Cocoa: Fix the issue introduced @8bdb42c

for example, the Header cannot be displayed normally in VirtualTrees
This commit is contained in:
rich2014 2024-06-08 23:48:11 +08:00
parent f90017e4f6
commit 1b9571bfcd

View File

@ -36,9 +36,9 @@ type
function SetButtonCellType(btn: NSButtonCell; Details: TThemedElementDetails): Boolean;
procedure SetButtonCellToDetails(btn: NSButtonCell; Details: TThemedElementDetails);
procedure CellDrawStart(dst: TCocoaContext; const r: Trect; out dstRect: NSRect);
procedure CellDrawStart(dst: TCocoaContext; const r: Trect; out cur: NSGraphicsContext; out dstRect: NSRect);
procedure CellDrawFrame(cell: NSCell; const dst: NSRect);
procedure CellDrawEnd(dst: TCocoaContext);
procedure CellDrawEnd(dst: TCocoaContext; cur: NSGraphicsContext);
function InitThemes: Boolean; override;
function UseThemes: Boolean; override;
@ -197,6 +197,7 @@ var
lState: TCDControlState = [];
lDrawer: TCDDrawer;
lPt: TPoint;
cur : NSGraphicsContext;
nsr : NSRect;
b : NSButtonCell;
begin
@ -206,9 +207,9 @@ begin
if SetButtonCellType(b, Details) then
begin
SetButtonCellToDetails(b, Details);
CellDrawStart(DC, R, nsr);
CellDrawStart(DC, R, cur, nsr);
CellDrawFrame(b, nsr);
CellDrawEnd(DC);
CellDrawEnd(DC, cur);
Exit;
end;
finally
@ -260,13 +261,14 @@ end;
function TCocoaThemeServices.DrawHeaderElement(DC: TCocoaContext;
Details: TThemedElementDetails; R: TRect; ClipRect: PRect): TRect;
var
cur : NSGraphicsContext;
nsr : NSRect;
begin
if (HdrCell=nil) then
begin
hdrCell := NSTableHeaderCell.alloc.initTextCell(NSSTR_EMPTY);
end;
CellDrawStart(DC, R, nsr);
CellDrawStart(DC, R, cur, nsr);
// this draws a header background
hdrCell.setDrawsBackground(true);
@ -277,7 +279,7 @@ begin
hdrCell.setDrawsBackground(false);
CellDrawFrame(hdrCell, nsr);
CellDrawEnd(DC);
CellDrawEnd(DC, cur);
Result := R;
end;
@ -344,6 +346,7 @@ var
lCDToolbarItem: TCDToolBarItem;
lCDToolbar: TCDToolBarStateEx;
lDrawer: TCDDrawer;
cur : NSGraphicsContext;
nsr : NSRect;
begin
if Details.Part = TP_BUTTON then
@ -351,9 +354,9 @@ begin
//BtnCell.setBezeled(true);
SetButtonCellType(BtnCell, Details);
SetButtonCellToDetails(BtnCell, Details);
CellDrawStart(DC, R, nsr);
CellDrawStart(DC, R, cur, nsr);
CellDrawFrame(btnCell, nsr);
CellDrawEnd(DC);
CellDrawEnd(DC, cur);
Result := R;
end
else
@ -938,17 +941,16 @@ begin
btn.setIntValue(0);
end;
procedure TCocoaThemeServices.CellDrawStart(dst: TCocoaContext; const r: Trect; out dstRect: NSRect);
var
acc : TCocoaContextAccess absolute dst;
procedure TCocoaThemeServices.CellDrawStart(dst: TCocoaContext; const r: Trect; out cur: NSGraphicsContext; out dstRect: NSRect);
begin
NSGraphicsContext.classSaveGraphicsState;
NSGraphicsContext.setCurrentContext(acc.ctx);
CGContextSaveGState(dst.ctx.CGContext);
cur := NSGraphicsContext.currentContext;
NSGraphicsContext.setCurrentContext(dst.ctx);
if NOT acc.ctx.isFlipped then begin
CGContextTranslateCTM(acc.ctx.CGContext, 0, acc.Size.cy);
CGContextScaleCTM(acc.ctx.CGContext, 1, -1);
LCLToNSRect(R, acc.size.cy, dstRect);
if NOT dst.ctx.isFlipped then begin
CGContextTranslateCTM(dst.ctx.CGContext, 0, dst.Size.cy);
CGContextScaleCTM(dst.ctx.CGContext, 1, -1);
LCLToNSRect(R, dst.size.cy, dstRect);
end else begin
dstRect:= RectTONSRect(R);
end;
@ -959,9 +961,10 @@ begin
cell.drawWithFrame_inView(dst, nil);
end;
procedure TCocoaThemeServices.CellDrawEnd(dst: TCocoaContext);
procedure TCocoaThemeServices.CellDrawEnd(dst: TCocoaContext; cur: NSGraphicsContext);
begin
NSGraphicsContext.classRestoreGraphicsState;
NSGraphicsContext.setCurrentContext(cur);
CGContextRestoreGState(dst.ctx.lclCGContext);
end;
{ TCocoaThemeCallback }