diff --git a/lcl/interfaces/cocoa/cocoaprivate.pp b/lcl/interfaces/cocoa/cocoaprivate.pp index 0a9dc6de8a..b1d69e5e7e 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pp +++ b/lcl/interfaces/cocoa/cocoaprivate.pp @@ -70,6 +70,7 @@ type function lclIsEnabled: Boolean; message 'lclIsEnabled'; procedure lclSetEnabled(AEnabled: Boolean); message 'lclSetEnabled:'; function lclIsVisible: Boolean; message 'lclIsVisible'; + procedure lclSetVisible(AVisible: Boolean); message 'lclSetVisible:'; function lclWindowState: Integer; message 'lclWindowState'; procedure lclInvalidateRect(const r: TRect); message 'lclInvalidateRect:'; @@ -92,6 +93,7 @@ type LCLViewExtension = objccategory(NSView) function lclIsVisible: Boolean; message 'lclIsVisible'; reintroduce; + procedure lclSetVisible(AVisible: Boolean); message 'lclSetVisible:'; reintroduce; function lclIsPainting: Boolean; message 'lclIsPainting'; procedure lclInvalidateRect(const r: TRect); message 'lclInvalidateRect:'; reintroduce; procedure lclInvalidate; message 'lclInvalidate'; reintroduce; @@ -120,6 +122,7 @@ type LCLWindowExtension = objccategory(NSWindow) function lclIsVisible: Boolean; message 'lclIsVisible'; reintroduce; + procedure lclSetVisible(AVisible: Boolean); message 'lclSetVisible:'; reintroduce; function lclIsEnabled: Boolean; message 'lclIsEnabled'; reintroduce; procedure lclSetEnabled(AEnabled: Boolean); message 'lclSetEnabled:'; reintroduce; @@ -978,6 +981,10 @@ begin Result := False; end; +procedure LCLObjectExtension.lclSetVisible(AVisible: Boolean); +begin +end; + function LCLObjectExtension.lclWindowState: Integer; begin Result := SIZENORMAL; @@ -1092,11 +1099,16 @@ begin SetEnabled(AEnabled); end; -function LCLViewExtension.lclIsVisible:Boolean; +function LCLViewExtension.lclIsVisible: Boolean; begin Result := not isHidden; end; +procedure LCLViewExtension.lclSetVisible(AVisible: Boolean); +begin + setHidden(not AVisible); +end; + function LCLViewExtension.lclIsPainting: Boolean; begin Result := Assigned(lclGetCallback) and Assigned(lclGetCallback.GetContext); @@ -1205,11 +1217,19 @@ end; { LCLWindowExtension } -function LCLWindowExtension.lclIsVisible:Boolean; +function LCLWindowExtension.lclIsVisible: Boolean; begin Result := isVisible; end; +procedure LCLWindowExtension.lclSetVisible(AVisible: Boolean); +begin + if AVisible then + orderFrontRegardless + else + orderOut(nil); +end; + function LCLWindowExtension.lclIsEnabled: Boolean; begin Result := contentView.lclIsEnabled; diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index b2ed070c40..0b2b9d9a25 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -82,6 +82,7 @@ type class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); override; class procedure SetCursor(const AWinControl: TWinControl; const ACursor: HCursor); override; class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override; + class procedure ShowHide(const AWinControl: TWinControl); override; end; @@ -910,9 +911,9 @@ end; class function TCocoaWSWinControl.GetClientBounds(const AWincontrol: TWinControl; var ARect: TRect): Boolean; begin - Result:=(AWinControl.Handle<>0); - if not Result then Exit; - ARect:=NSObject(AWinControl.Handle).lclClientFrame; + Result := AWinControl.HandleAllocated; + if Result then + ARect := NSObject(AWinControl.Handle).lclClientFrame; end; class function TCocoaWSWinControl.GetClientRect(const AWincontrol: TWinControl; var ARect: TRect): Boolean; @@ -929,7 +930,7 @@ var Obj: NSObject; Size: NSSize; begin - if (AWinControl.Handle <> 0) then + if AWinControl.HandleAllocated then begin Obj := NSObject(AWinControl.Handle); { @@ -946,7 +947,7 @@ end; class procedure TCocoaWSWinControl.SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); begin - if (AWinControl.Handle<>0) then + if AWinControl.HandleAllocated then NSObject(AWinControl.Handle).lclSetFrame(Bounds(ALeft, ATop, AWidth, AHeight)); end; @@ -1011,6 +1012,12 @@ begin end; end; +class procedure TCocoaWSWinControl.ShowHide(const AWinControl: TWinControl); +begin + if AWinControl.HandleAllocated then + NSObject(AWinControl.Handle).lclSetVisible(AWinControl.HandleObjectShouldBeVisible); +end; + { TCocoaWSCustomControl } class function TCocoaWSCustomControl.CreateHandle(const AWinControl: TWinControl; @@ -1025,27 +1032,33 @@ end; { LCLWSViewExtension } -function LCLWSViewExtension.lclInitWithCreateParams(const AParams:TCreateParams): id; +function LCLWSViewExtension.lclInitWithCreateParams(const AParams: TCreateParams): id; var p: NSView; ns: NSRect; begin - p:=nil; - if (AParams.WndParent<>0) then 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; + 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); + 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; + Result := initWithFrame(ns); + if not Assigned(Result) then + Exit; - if Assigned(p) then p.addSubview(Self); + if Assigned(p) then + p.addSubview(Self); SetViewDefaults(Self); end; diff --git a/lcl/interfaces/cocoa/cocoawsforms.pp b/lcl/interfaces/cocoa/cocoawsforms.pp index d165fc633b..862013d22d 100644 --- a/lcl/interfaces/cocoa/cocoawsforms.pp +++ b/lcl/interfaces/cocoa/cocoawsforms.pp @@ -91,8 +91,6 @@ type published class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; - class procedure ShowHide(const AWinControl: TWinControl); override; //TODO: rename to SetVisible(control, visible) - class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override; class function GetTextLen(const AWinControl: TWinControl; var ALength: Integer): Boolean; override; class procedure SetText(const AWinControl: TWinControl; const AText: String); override; @@ -223,16 +221,6 @@ begin Result := TLCLIntfHandle(win); end; -class procedure TCocoaWSCustomForm.ShowHide(const AWinControl: TWinControl); -begin - if not AWinControl.HandleAllocated then - Exit; - if AWinControl.HandleObjectShouldBeVisible then - NSWindow(AWinControl.Handle).orderFrontRegardless - else - NSWindow(AWinControl.Handle).orderOut(nil); -end; - class function TCocoaWSCustomForm.GetText(const AWinControl: TWinControl; var AText: String): Boolean; begin Result := AWinControl.HandleAllocated; diff --git a/lcl/interfaces/cocoa/cocoawsstdctrls.pp b/lcl/interfaces/cocoa/cocoawsstdctrls.pp index 9f6f9647b2..4b1c6a1fb5 100644 --- a/lcl/interfaces/cocoa/cocoawsstdctrls.pp +++ b/lcl/interfaces/cocoa/cocoawsstdctrls.pp @@ -158,7 +158,7 @@ type TCocoaWSButton = class(TWSButton) published - class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; + class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; class procedure SetDefault(const AButton: TCustomButton; ADefault: Boolean); override; end; @@ -221,7 +221,8 @@ begin cap := NSStringUTF8(AParams.Caption); Result.setTitle(cap); cap.release; - if btnBezel<>0 then Result.setBezelStyle(btnBezel); + if btnBezel <> 0 then + Result.setBezelStyle(btnBezel); Result.setButtonType(btnType); end; end;