diff --git a/lcl/interfaces/cocoa/cocoabuttons.pas b/lcl/interfaces/cocoa/cocoabuttons.pas index 6cfc1586b3..d884e66e43 100644 --- a/lcl/interfaces/cocoa/cocoabuttons.pas +++ b/lcl/interfaces/cocoa/cocoabuttons.pas @@ -31,6 +31,16 @@ uses // LCL ,Graphics; +const + // these heights were received from Xcode interface builder, + // where the height cannot be changed for a button control the actual size + // of the button (the difference between top pixel and bottom pixel, + // is less than frame size also + + PUSHBTN_REG_HEIGHT = 20; + PUSHBTN_SMALL_HEIGHT = 17; + PUSHBTN_MINI_HEIGHT = 14; + type diff --git a/lcl/interfaces/cocoa/cocoaprivate.pas b/lcl/interfaces/cocoa/cocoaprivate.pas index 4973c2bbc2..e2012c17ad 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pas +++ b/lcl/interfaces/cocoa/cocoaprivate.pas @@ -267,6 +267,7 @@ type procedure lclClearCallback; override; procedure resetCursorRects; override; function lclGetFrameToLayoutDelta: TRect; override; + procedure lclSetFrame(const r: TRect); override; // mouse function acceptsFirstMouse(event: NSEvent): Boolean; override; procedure mouseDown(event: NSEvent); override; @@ -339,7 +340,7 @@ procedure SetViewDefaults(AView: NSView); function CheckMainThread: Boolean; function GetNSViewSuperViewHeight(view: NSView): CGFloat; -procedure SetNSControlSize(ctrl: NSControl; newHeight, miniHeight, smallHeight: Integer; AutoChangeFont: Boolean); +procedure SetNSControlSize(ctrl: NSView; newHeight, miniHeight, smallHeight: Integer; AutoChangeFont: Boolean); // these constants are missing from CocoaAll for some reason const @@ -1204,6 +1205,12 @@ begin end; end; +procedure TCocoaProgressIndicator.lclSetFrame(const r: TRect); +begin + SetNSControlSize(self, r.Bottom - r.Top, 0, PROGRESS_SMALL_HEIGHT, true); + inherited lclSetFrame(r); +end; + function TCocoaProgressIndicator.acceptsFirstMouse(event: NSEvent): Boolean; begin Result:=true; @@ -1509,7 +1516,15 @@ begin self.setNeedsDisplay; end; -procedure SetNSControlSize(ctrl: NSControl; newHeight, miniHeight, smallHeight: Integer; AutoChangeFont: Boolean); +type + NSViewControlSizeExt = objccategory external (NSView) + function controlSize: Integer; message 'controlSize'; + procedure setControlSize(ASize: Integer); message 'setControlSize:'; + function cell: id; message 'cell'; + procedure setFont(afont: NSFont); message 'setFont:'; + end; + +procedure SetNSControlSize(ctrl: NSView; newHeight, miniHeight, smallHeight: Integer; AutoChangeFont: Boolean); var sz : NSControlSize; begin @@ -1520,14 +1535,15 @@ begin else sz:=NSRegularControlSize; - //todo: "cell" property (function) has been deprecated since 10.10 - // instead NSControl itself has controlSize method - if NSCell(ctrl.cell).controlSize<>sz then + if ctrl.respondsToSelector(ObjCSelector('setControlSize:')) then + ctrl.setControlSize(sz) + else if ctrl.respondsToSelector(ObjCSelector('cell')) then begin - NSCell(ctrl.cell).setControlSize(sz); - if AutoChangeFont then - ctrl.setFont(NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(sz))); + if NSCell(ctrl.cell).controlSize<>sz then + NSCell(ctrl.cell).setControlSize(sz); end; + if AutoChangeFont and (ctrl.respondsToSelector(ObjCSelector('setFont:'))) then + ctrl.setFont(NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(sz))); end; diff --git a/lcl/interfaces/cocoa/cocoawsstdctrls.pas b/lcl/interfaces/cocoa/cocoawsstdctrls.pas index 24e50c1663..6f1015eebb 100644 --- a/lcl/interfaces/cocoa/cocoawsstdctrls.pas +++ b/lcl/interfaces/cocoa/cocoawsstdctrls.pas @@ -592,13 +592,9 @@ var btn: TCocoaButton; begin btn := AllocButton(AWinControl, TLCLButtonCallback, AParams, NSRoundedBezelStyle, NSMomentaryPushInButton); - // btn.regularHeight = 32 - btn.smallHeight := 28; - btn.miniHeight := 16; + btn.smallHeight := PUSHBTN_SMALL_HEIGHT; + btn.miniHeight := PUSHBTN_MINI_HEIGHT; btn.adjustFontToControlSize:=true; - // these heights were received from Xcode builder, where the height cannot be changed for a button control - // the actual size of the button (the difference between top pixel and bottom pixel, is less than frame size - // also, the "mini" button seems to be wider, than Result := TLCLIntfHandle(btn); end;