From 22bb78575c001c16b220ddf0e9d44f7b84842177 Mon Sep 17 00:00:00 2001 From: dmitry Date: Mon, 29 Apr 2019 02:21:24 +0000 Subject: [PATCH] cocoa: drawing themed non-flat speed buttons git-svn-id: trunk@61078 - --- lcl/interfaces/cocoa/cocoathemes.pas | 84 ++++++++++++++++++---------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoathemes.pas b/lcl/interfaces/cocoa/cocoathemes.pas index c9b60c2361..40b038e565 100644 --- a/lcl/interfaces/cocoa/cocoathemes.pas +++ b/lcl/interfaces/cocoa/cocoathemes.pas @@ -30,9 +30,8 @@ type TCocoaThemeServices = class(TThemeServices) private protected - BezelToolBar : NSBezelStyle; BtnCell : NSButtonCell; - procedure SetButtonCellType(btn: NSButtonCell; Details: TThemedElementDetails); + function SetButtonCellType(btn: NSButtonCell; Details: TThemedElementDetails): Boolean; procedure SetButtonCellToDetails(btn: NSButtonCell; Details: TThemedElementDetails); procedure CellDrawStart(dst: TCocoaContext; const r: Trect; out cur: NSGraphicsContext; out dstRect: NSRect); @@ -56,6 +55,8 @@ type *) function GetCellForDetails(Details: TThemedElementDetails): NSCell; public + BezelToolBar : NSBezelStyle; + BezelButton : NSBezelStyle; constructor Create; procedure DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect; ClipRect: PRect); override; (* @@ -280,33 +281,25 @@ var lState: TCDControlState = []; lDrawer: TCDDrawer; lPt: TPoint; - cl : NSCell; - acc : TCocoaContextAccess; - dr : NSRect; - cur : NSGraphicsContext; + nsr : NSRect; + b : NSButtonCell; begin - cl := GetCellForDetails(Details); - if Assigned(cl) then - begin - acc := TCocoaContextAccess(DC); - - cur := NSGraphicsContext.currentContext; - NSGraphicsContext.setCurrentContext( acc.ctx ); - - acc.SetCGFillping(acc.CGContext, 0, -acc.Size.cy); - try - LCLToNSRect( R, acc.size.cy, dr); - cl.drawWithFrame_inView (dr, nil ); - finally - acc.SetCGFillping(acc.CGContext, 0, -acc.Size.cy); - NSGraphicsContext.setCurrentContext( cur ); + b := NSButtonCell.alloc.initTextCell(NSString.string_); + try + // ideally, all uttons are drawn via Cocoa + if SetButtonCellType(b, Details) then + begin + SetButtonCellToDetails(b, Details); + CellDrawStart(DC, R, cur, nsr); + CellDrawFrame(b, nsr); + CellDrawEnd(DC, cur); + Exit; end; - - Exit; + finally + b.release; end; - lCDButton := TCDButtonStateEx.Create; lCanvas := TCanvas.Create; try @@ -629,7 +622,8 @@ constructor TCocoaThemeServices.Create; begin inherited Create; BtnCell := NSButtonCell.alloc.initTextCell(NSSTR('')); - BezelToolBar := NSSmallSquareBezelStyle; + BezelToolBar := NSSmallSquareBezelStyle; // can be resized at any size + BezelButton := NSSmallSquareBezelStyle; end; (*function TCarbonThemeServices.DrawWindowElement(DC: TCarbonDeviceContext; @@ -943,14 +937,46 @@ begin end; *) -procedure TCocoaThemeServices.SetButtonCellType(btn: NSButtonCell; Details: TThemedElementDetails); +function TCocoaThemeServices.SetButtonCellType(btn: NSButtonCell; Details: TThemedElementDetails): Boolean; +var + BtnType : NSButtonType; + BezelStyle : NSBezelStyle; + useBezel : Boolean; begin + Result := true; + BtnType := NSMomentaryPushButton; + BezelStyle := NSRoundedBezelStyle; + useBezel := false; if Details.Element = teToolBar then begin - btn.setButtonType(NSOnOffButton); - btn.setBezelStyle(BezelToolBar); - btn.setBezeled(true); + BtnType := NSOnOffButton; + BezelStyle := BezelToolBar; + useBezel := true; + end else if Details.Element = teButton then + begin + useBezel := false; + case Details.Part of + BP_CHECKBOX: BtnType := NSSwitchButton; + BP_RADIOBUTTON: BtnType := NSRadioButton; + BP_PUSHBUTTON: + begin + BtnType := NSPushOnPushOffButton; + BezelStyle := BezelButton; + useBezel := true; + end; + else + Result := false; + end; + end else + Result := false; + + if Result then + begin + btn.setButtonType(BtnType); + btn.setBezelStyle(BezelStyle); + btn.setBezeled(useBezel); end; + end; procedure TCocoaThemeServices.SetButtonCellToDetails(btn: NSButtonCell; Details: TThemedElementDetails);