diff --git a/lcl/interfaces/cocoa/cocoaprivate.pp b/lcl/interfaces/cocoa/cocoaprivate.pp index 38b9091aae..ce76f8a526 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pp +++ b/lcl/interfaces/cocoa/cocoaprivate.pp @@ -57,6 +57,7 @@ type procedure boundsDidChange; // misc events procedure Draw(ctx: NSGraphicsContext; const bounds, dirty: NSRect); + procedure DrawBackground(ctx: NSGraphicsContext; const bounds, dirty: NSRect); function ResetCursorRects: Boolean; procedure BecomeFirstResponder; procedure ResignFirstResponder; @@ -1991,20 +1992,12 @@ begin end; procedure TCocoaCustomControl.drawRect(dirtyRect: NSRect); -var - lTarget: TWinControl; begin inherited drawRect(dirtyRect); + // Implement Color property if Assigned(callback) then - begin - lTarget := TWinControl(callback.GetTarget()); - if (lTarget.Color <> clDefault) and (lTarget.Color <> clBtnFace) then - begin - ColorToNSColor(ColorToRGB(lTarget.Color)).set_(); - NSRectFill(dirtyRect); - end; - end; + callback.DrawBackground(NSGraphicsContext.currentContext, bounds, dirtyRect); if CheckMainThread and Assigned(callback) then callback.Draw(NSGraphicsContext.currentContext, bounds, dirtyRect); diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index d49f00ba8b..9b4d1246ca 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -67,6 +67,7 @@ type function DeliverMessage(var Msg): LRESULT; virtual; overload; function DeliverMessage(Msg: Cardinal; WParam: WParam; LParam: LParam): LResult; virtual; overload; procedure Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); virtual; + procedure DrawBackground(ctx: NSGraphicsContext; const bounds, dirtyRect: NSRect); virtual; function ResetCursorRects: Boolean; virtual; property HasCaret: Boolean read GetHasCaret write SetHasCaret; @@ -1058,6 +1059,19 @@ begin end; end; +procedure TLCLCommonCallback.DrawBackground(ctx: NSGraphicsContext; const bounds, dirtyRect: NSRect); +var + lTarget: TWinControl; +begin + // Implement Color property + lTarget := TWinControl(GetTarget()); + if (lTarget.Color <> clDefault) and (lTarget.Color <> clBtnFace) then + begin + ColorToNSColor(ColorToRGB(lTarget.Color)).set_(); + NSRectFill(dirtyRect); + end; +end; + function TLCLCommonCallback.ResetCursorRects: Boolean; var ACursor: TCursor; diff --git a/lcl/interfaces/cocoa/cocoawsstdctrls.pp b/lcl/interfaces/cocoa/cocoawsstdctrls.pp index d3c6ef0630..35fff8bb6e 100644 --- a/lcl/interfaces/cocoa/cocoawsstdctrls.pp +++ b/lcl/interfaces/cocoa/cocoawsstdctrls.pp @@ -1068,6 +1068,8 @@ class function TCocoaWSCustomGroupBox.CreateHandle(const AWinControl: TWinContro var box: TCocoaGroupBox; cap: NSString; + lGroupBoxContents: TCocoaCustomControl; + ns: NSRect; begin box := NSView(TCocoaGroupBox.alloc).lclInitWithCreateParams(AParams); if Assigned(box) then @@ -1076,6 +1078,13 @@ begin cap := NSStringUTF8(AParams.Caption); box.setTitle(cap); cap.release; + + // set a content view in order to be able to customize drawing for labels/color + ns := GetNSRect(AParams.X, AParams.Y, AParams.Width, AParams.Height); + lGroupBoxContents := TCocoaCustomControl(TCocoaCustomControl.alloc.initWithFrame(ns)); + lGroupBoxContents.callback := TLCLCustomControlCallback.Create(lGroupBoxContents, AWinControl); + lGroupBoxContents.autorelease; + box.setContentView(lGroupBoxContents); end; Result := TLCLIntfHandle(box); end;