cocoa: formatting, cleanup, correctly initialize controls with initial visible state using WS_VISIBLE flag, implement ShowHide for controls and forms

git-svn-id: trunk@34600 -
This commit is contained in:
paul 2012-01-05 17:23:51 +00:00
parent 74c7b051a3
commit c403c02f92
4 changed files with 55 additions and 33 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;