cocoa: bug #38711. The themes enabled for Cocoa teHeader drawing is now imlpemented to make sure virtual tree view draws headers nicely

git-svn-id: trunk@64937 -
This commit is contained in:
dmitry 2021-04-07 05:01:00 +00:00
parent 3624a43153
commit e1deb6db08

View File

@ -32,6 +32,7 @@ type
protected protected
callback : NSObject; callback : NSObject;
BtnCell : NSButtonCell; BtnCell : NSButtonCell;
hdrCell : NSTableHeaderCell;
function SetButtonCellType(btn: NSButtonCell; Details: TThemedElementDetails): Boolean; function SetButtonCellType(btn: NSButtonCell; Details: TThemedElementDetails): Boolean;
procedure SetButtonCellToDetails(btn: NSButtonCell; Details: TThemedElementDetails); procedure SetButtonCellToDetails(btn: NSButtonCell; Details: TThemedElementDetails);
@ -48,8 +49,9 @@ type
function GetDrawState(Details: TThemedElementDetails): ThemeDrawState; function GetDrawState(Details: TThemedElementDetails): ThemeDrawState;
function DrawButtonElement(DC: TCocoaContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect; function DrawButtonElement(DC: TCocoaContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;
(* function DrawComboBoxElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect; (* function DrawComboBoxElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;
function DrawHeaderElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect; *)
function DrawRebarElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;*) function DrawHeaderElement(DC: TCocoaContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;
(* function DrawRebarElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;*)
function DrawToolBarElement(DC: TCocoaContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect; function DrawToolBarElement(DC: TCocoaContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;
function DrawTreeviewElement(DC: TCocoaContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect; function DrawTreeviewElement(DC: TCocoaContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;
(* function DrawWindowElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect; (* function DrawWindowElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;
@ -246,35 +248,39 @@ begin
end; end;
end; end;
(*{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCarbonThemeServices.DrawHeaderElement Method: TCocoaThemeServices.DrawHeaderElement
Params: DC - Carbon device context Params: DC - Carbon device context
Details - Details for themed element Details - Details for themed element
R - Bounding rectangle R - Bounding rectangle
ClipRect - Clipping rectangle ClipRect - Clipping rectangle
Returns: ClientRect Returns: ClientRect
Draws a header (THeaderControl same as ListView header) element with native Carbon look Draws a header (THeaderControl same as ListView header) element with native macOS look
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCarbonThemeServices.DrawHeaderElement(DC: TCarbonDeviceContext; function TCocoaThemeServices.DrawHeaderElement(DC: TCocoaContext;
Details: TThemedElementDetails; R: TRect; ClipRect: PRect): TRect; Details: TThemedElementDetails; R: TRect; ClipRect: PRect): TRect;
var var
ButtonDrawInfo: HIThemeButtonDrawInfo; cur : NSGraphicsContext;
PaintRect: HIRect; nsr : NSRect;
begin begin
ButtonDrawInfo.version := 0; if (HdrCell=nil) then
ButtonDrawInfo.State := GetDrawState(Details); begin
ButtonDrawInfo.kind := kThemeBevelButtonSmall;//kThemeListHeaderButton; hdrCell := NSTableHeaderCell.alloc.initTextCell(NSSTR(''));
ButtonDrawInfo.adornment := kThemeAdornmentNone; end;
CellDrawStart(DC, R, cur, nsr);
PaintRect := RectToCGRect(R); // this draws a header background
hdrCell.setDrawsBackground(true);
hdrCell.drawInteriorWithFrame_inView(nsr,nil);
hdrCell.highlight_withFrame_inView(true, nsr, nil);
OSError( // this draws a nice cell separator
HIThemeDrawButton(PaintRect, ButtonDrawInfo, DC.CGContext, hdrCell.setDrawsBackground(false);
kHIThemeOrientationNormal, @PaintRect), CellDrawFrame(hdrCell, nsr);
Self, 'DrawButtonElement', 'HIThemeDrawButton');
Result := CGRectToRect(PaintRect); CellDrawEnd(DC, cur);
Result := R;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -287,6 +293,7 @@ end;
Draws a rebar element (splitter) with native Carbon look Draws a rebar element (splitter) with native Carbon look
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
(*
function TCarbonThemeServices.DrawRebarElement(DC: TCarbonDeviceContext; function TCarbonThemeServices.DrawRebarElement(DC: TCarbonDeviceContext;
Details: TThemedElementDetails; R: TRect; ClipRect: PRect): TRect; Details: TThemedElementDetails; R: TRect; ClipRect: PRect): TRect;
var var
@ -549,6 +556,7 @@ destructor TCocoaThemeServices.Destroy;
begin begin
NSNotificationCenter(NSNotificationCenter.defaultCenter).removeObserver(callback); NSNotificationCenter(NSNotificationCenter.defaultCenter).removeObserver(callback);
callback.release; callback.release;
if (HdrCell<>nil) then hdrCell.Release;
inherited Destroy; inherited Destroy;
end; end;
@ -704,8 +712,8 @@ begin
case Details.Element of case Details.Element of
//teComboBox: DrawComboBoxElement(Context, Details, R, ClipRect); //teComboBox: DrawComboBoxElement(Context, Details, R, ClipRect);
teButton: DrawButtonElement(Context, Details, R, ClipRect); teButton: DrawButtonElement(Context, Details, R, ClipRect);
{teHeader: DrawHeaderElement(Context, Details, R, ClipRect); teHeader: DrawHeaderElement(Context, Details, R, ClipRect);
teRebar: DrawRebarElement(Context, Details, R, ClipRect);} {teRebar: DrawRebarElement(Context, Details, R, ClipRect);}
teToolBar: DrawToolBarElement(Context, Details, R, ClipRect); teToolBar: DrawToolBarElement(Context, Details, R, ClipRect);
teTreeview: DrawTreeviewElement(Context, Details, R, ClipRect); teTreeview: DrawTreeviewElement(Context, Details, R, ClipRect);
// teWindow: DrawWindowElement(Context, Details, R, ClipRect); // teWindow: DrawWindowElement(Context, Details, R, ClipRect);