cocoa: cleanup and reorganizing some code

git-svn-id: trunk@34609 -
This commit is contained in:
paul 2012-01-06 03:31:14 +00:00
parent dff245bd1a
commit 6ffa774f3f
3 changed files with 52 additions and 58 deletions

View File

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

View File

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

View File

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