diff --git a/lcl/interfaces/cocoa/cocoaprivate.pp b/lcl/interfaces/cocoa/cocoaprivate.pp index b1d69e5e7e..f98d0b296a 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pp +++ b/lcl/interfaces/cocoa/cocoaprivate.pp @@ -92,6 +92,8 @@ type { LCLViewExtension } LCLViewExtension = objccategory(NSView) + function lclInitWithCreateParams(const AParams: TCreateParams): id; message 'lclInitWithCreateParams:'; + function lclIsVisible: Boolean; message 'lclIsVisible'; reintroduce; procedure lclSetVisible(AVisible: Boolean); message 'lclSetVisible:'; reintroduce; function lclIsPainting: Boolean; message 'lclIsPainting'; @@ -402,8 +404,16 @@ type procedure resetCursorRects; override; end; +procedure SetViewDefaults(AView: NSView); + implementation +procedure SetViewDefaults(AView: NSView); +begin + if not Assigned(AView) then Exit; + AView.setAutoresizingMask(NSViewMinYMargin or NSViewMaxXMargin); +end; + { TCocoaScrollView } function TCocoaScrollView.acceptsFirstResponder: Boolean; @@ -1099,6 +1109,36 @@ begin SetEnabled(AEnabled); end; +function LCLViewExtension.lclInitWithCreateParams(const AParams: TCreateParams): id; +var + p: NSView; + ns: NSRect; +begin + p := nil; + setHidden(AParams.Style and WS_VISIBLE = 0); + if (AParams.WndParent <> 0) then + begin + if (NSObject(AParams.WndParent).isKindOfClass_(NSView)) then + p := NSView(AParams.WndParent) + else + if (NSObject(AParams.WndParent).isKindOfClass_(NSWindow)) then + p := NSWindow(AParams.WndParent).contentView; + end; + with AParams do + if Assigned(p) then + LCLToNSRect(Types.Bounds(X,Y,Width, Height), p.frame.size.height, ns) + else + LCLToNSRect(Types.Bounds(X,Y,Width, Height), ns); + + Result := initWithFrame(ns); + if not Assigned(Result) then + Exit; + + if Assigned(p) then + p.addSubview(Self); + SetViewDefaults(Self); +end; + function LCLViewExtension.lclIsVisible: Boolean; begin Result := not isHidden; diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index 0b2b9d9a25..8cefbf8770 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -14,13 +14,6 @@ uses CocoaPrivate, CocoaGDIObjects, CocoaCaret, CocoaUtils, LCLMessageGlue; type - - { LCLWSViewExtension } - - LCLWSViewExtension = objccategory(NSView) - function lclInitWithCreateParams(const AParams: TCreateParams): id; message 'lclInitWithCreateParams:'; - end; - { TLCLCommonCallback } TLCLCommonCallback = class(TObject, ICommonCallBack) @@ -117,7 +110,6 @@ const function AllocCustomControl(const AWinControl: TWinControl): TCocoaCustomControl; function EmbedInScrollView(AView: NSView): TCocoaScrollView; -procedure SetViewDefaults(AView: NSView); implementation @@ -150,12 +142,6 @@ begin SetViewDefaults(Result); end; -procedure SetViewDefaults(AView:NSView); -begin - if not Assigned(AView) then Exit; - AView.setAutoresizingMask(NSViewMinYMargin or NSViewMaxXMargin); -end; - { TLCLCustomControlCallback } function TLCLCustomControlCallback.MouseUpDownEvent(Event: NSEvent): Boolean; @@ -1030,37 +1016,5 @@ begin Result := TLCLIntfHandle(ctrl); end; -{ LCLWSViewExtension } - -function LCLWSViewExtension.lclInitWithCreateParams(const AParams: TCreateParams): id; -var - p: NSView; - ns: NSRect; -begin - p := nil; - setHidden(AParams.Style and WS_VISIBLE = 0); - if (AParams.WndParent <> 0) then - begin - if (NSObject(AParams.WndParent).isKindOfClass_(NSView)) then - p := NSView(AParams.WndParent) - else - if (NSObject(AParams.WndParent).isKindOfClass_(NSWindow)) then - p := NSWindow(AParams.WndParent).contentView; - end; - with AParams do - if Assigned(p) then - LCLToNSRect(Types.Bounds(X,Y,Width, Height), p.frame.size.height, ns) - else - LCLToNSRect(Types.Bounds(X,Y,Width, Height), ns); - - Result := initWithFrame(ns); - if not Assigned(Result) then - Exit; - - if Assigned(p) then - p.addSubview(Self); - SetViewDefaults(Self); -end; - end. diff --git a/lcl/interfaces/cocoa/cocoawsstdctrls.pp b/lcl/interfaces/cocoa/cocoawsstdctrls.pp index e521a4c309..fbc9663f8d 100644 --- a/lcl/interfaces/cocoa/cocoawsstdctrls.pp +++ b/lcl/interfaces/cocoa/cocoawsstdctrls.pp @@ -228,29 +228,29 @@ end; function AllocTextView(ATarget: TWinControl; const AParams: TCreateParams; fieldEditor: Boolean): NSTextView; begin - Result:=TCocoaTextView.alloc; - if Assigned(Result) then begin - TCocoaTextView(Result).callback:=TLCLCommonCallback.Create(Result, ATarget); - Result.initWithFrame(CreateParamsToNSRect(AParams)); + Result := TCocoaTextView.alloc.lclInitWithCreateParams(AParams); + if Assigned(Result) then + begin + TCocoaTextView(Result).callback := TLCLCommonCallback.Create(Result, ATarget); end; end; function AllocTextField(ATarget: TWinControl; const AParams: TCreateParams): TCocoaTextField; begin - Result:=TCocoaTextField(TCocoaTextField.alloc.lclInitWithCreateParams(AParams)); - if Assigned(Result) then begin - TCocoaTextField(Result).callback:=TLCLCommonCallback.Create(Result, ATarget); - Result.initWithFrame(CreateParamsToNSRect(AParams)); + Result := TCocoaTextField.alloc.lclInitWithCreateParams(AParams); + if Assigned(Result) then + begin + Result.callback := TLCLCommonCallback.Create(Result, ATarget); SetNSControlValue(Result, AParams.Caption); end; end; function AllocSecureTextField(ATarget: TWinControl; const AParams: TCreateParams): TCocoaSecureTextField; begin - Result:=TCocoaSecureTextField(TCocoaSecureTextField.alloc); - if Assigned(Result) then begin - TCocoaSecureTextField(Result).callback:=TLCLCommonCallback.Create(Result, ATarget); - Result.initWithFrame(CreateParamsToNSRect(AParams)); + Result := TCocoaSecureTextField.alloc.lclInitWithCreateParams(AParams); + if Assigned(Result) then + begin + TCocoaSecureTextField(Result).callback := TLCLCommonCallback.Create(Result, ATarget); SetNSText(Result.currentEditor, AParams.Caption); end; end;