diff --git a/lcl/interfaces/cocoa/cocoascrollers.pas b/lcl/interfaces/cocoa/cocoascrollers.pas index b630c01d75..e302926b91 100644 --- a/lcl/interfaces/cocoa/cocoascrollers.pas +++ b/lcl/interfaces/cocoa/cocoascrollers.pas @@ -141,6 +141,9 @@ type end; + TCocoaManualScrollHost = objcclass(TCocoaScrollView) + end; + function isMouseEventInScrollBar(host: TCocoaManualScrollView; event: NSEvent): Boolean; // These settings are set by a user in "System Preferences" diff --git a/lcl/interfaces/cocoa/cocoawinapi.inc b/lcl/interfaces/cocoa/cocoawinapi.inc index c08529ba69..d340da10a9 100644 --- a/lcl/interfaces/cocoa/cocoawinapi.inc +++ b/lcl/interfaces/cocoa/cocoawinapi.inc @@ -1568,6 +1568,9 @@ begin Result := Assigned(obj); if not Result then Exit; + if obj.isKindOfClass(TCocoaManualScrollHost) then + obj := TCocoaManualScrollHost(obj).documentView; + if obj.isKindOfClass(NSScrollView) then begin sc := NSScrollView(obj); @@ -1602,6 +1605,9 @@ begin Result := Assigned(obj); if not Result then Exit; + if obj.isKindOfClass(TCocoaManualScrollHost) then + obj := TCocoaManualScrollHost(obj).documentView; + if obj.isKindOfClass(TCocoaScrollBar) then Result := CocoaScrollBarGetScrollInfo(TCocoaScrollBar(obj), ScrollInfo) else @@ -1792,11 +1798,19 @@ var f : NSSize; sz : NSSize; flg : NSUInteger; + hosted: Boolean; begin obj := NSObject(Handle); Result := 0; if not Assigned(obj) then Exit; + if obj.isKindOfClass(TCocoaManualScrollHost) then + begin + hosted := true; + obj := TCocoaManualScrollHost(obj).documentView; + end else + hosted := false; + if obj.isKindOfClass(TCocoaScrollView) then begin sc:=TCocoaScrollView(obj); @@ -1848,6 +1862,9 @@ begin else Result := 0; + if hosted then + NSView(obj).lclInvalidate; + end else if obj.isKindOfClass(TCocoaScrollBar) then begin Result := CocoaScrollBarSetScrollInfo(TCocoaScrollBar(obj), ScrollInfo); @@ -1866,6 +1883,9 @@ begin Result := Assigned(obj); if not Result then Exit; + if obj.isKindOfClass(TCocoaManualScrollHost) then + obj := TCocoaManualScrollHost(obj).documentView; + if obj.isKindOfClass(TCocoaScrollView) then begin Result := true; diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index dea2cc33bd..ed072e0357 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -147,12 +147,15 @@ type published class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; + class procedure SetBorderStyle(const AWinControl: TWinControl; + const ABorderStyle: TBorderStyle); override; end; // Utility WS functions. todo: it makes sense to put them into CocoaScollers function EmbedInScrollView(AView: NSView; AReleaseView: Boolean = true): TCocoaScrollView; function EmbedInManualScrollView(AView: NSView): TCocoaManualScrollView; +function EmbedInManualScrollHost(AView: TCocoaManualScrollView): TCocoaManualScrollHost; function HWNDToTargetObject(AFormHandle: HWND): TObject; @@ -275,6 +278,38 @@ begin TCocoaCustomControl(AView).auxMouseByParent := true; end; +function EmbedInManualScrollHost(AView: TCocoaManualScrollView + ): TCocoaManualScrollHost; +var + r: TRect; + p: NSView; +begin + if not Assigned(AView) then + Exit(nil); + r := AView.lclFrame; + p := AView.superview; + Result := TCocoaManualScrollHost.alloc.initWithFrame(NSNullRect); + if Assigned(p) then p.addSubView(Result); + Result.lclSetFrame(r); + {$ifdef BOOLFIX} + Result.setHidden_(Ord(AView.isHidden)); + {$else} + Result.setHidden(AView.isHidden); + {$endif} + Result.setDocumentView(AView); + Result.setDrawsBackground(false); // everything is covered anyway + Result.contentView.setAutoresizesSubviews(true); + AView.setAutoresizingMask(NSViewWidthSizable or NSViewHeightSizable); + + AView.release; + {$ifdef BOOLFIX} + AView.setHidden_(Ord(false)); + {$else} + AView.setHidden(false); + {$endif} + SetViewDefaults(Result); +end; + { TLCLCommonCallback } function TLCLCommonCallback.GetHasCaret: Boolean; @@ -1783,7 +1818,9 @@ class function TCocoaWSCustomControl.CreateHandle(const AWinControl: TWinControl var ctrl : TCocoaCustomControl; sl : TCocoaManualScrollView; + hs : TCocoaManualScrollHost; lcl : TLCLCommonCallback; + begin ctrl := TCocoaCustomControl(TCocoaCustomControl.alloc.lclInitWithCreateParams(AParams)); lcl := TLCLCommonCallback.Create(ctrl, AWinControl); @@ -1793,9 +1830,21 @@ begin sl := EmbedInManualScrollView(ctrl); sl.callback := ctrl.callback; - lcl.HandleFrame:=sl; - Result := TLCLIntfHandle(sl); + hs := EmbedInManualScrollHost(sl); + hs.callback := ctrl.callback; + lcl.HandleFrame:=hs; + + ScrollViewSetBorderStyle(hs, TCustomControl(AWinControl).BorderStyle ); + + Result := TLCLIntfHandle(hs); +end; + +class procedure TCocoaWSCustomControl.SetBorderStyle( + const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); +begin + if not Assigned(AWinControl) or not (AWinControl.HandleAllocated) then Exit; + ScrollViewSetBorderStyle( TCocoaManualScrollHost(AWinControl.Handle), ABorderStyle ); end; function HWNDToTargetObject(AFormHandle: HWND): TObject;