mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-07-09 12:05:57 +02:00
customdrawn-cocoa: Updates to use the new unified form handle
git-svn-id: trunk@33912 -
This commit is contained in:
parent
a736fd742e
commit
bfdacf99d4
@ -18,9 +18,16 @@ uses
|
|||||||
Forms, Controls, LCLMessageGlue, WSControls, LCLType, LCLProc, GraphType;
|
Forms, Controls, LCLMessageGlue, WSControls, LCLType, LCLProc, GraphType;
|
||||||
|
|
||||||
type
|
type
|
||||||
{ TCocoaWindow }
|
TCocoaForm = objcclass;
|
||||||
|
|
||||||
TCocoaWindow = objcclass(NSWindow, NSWindowDelegateProtocol)
|
TCocoaWindow = class(TCDForm)
|
||||||
|
public
|
||||||
|
CocoaForm: TCocoaForm;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaForm }
|
||||||
|
|
||||||
|
TCocoaForm = objcclass(NSWindow, NSWindowDelegateProtocol)
|
||||||
protected
|
protected
|
||||||
function windowShouldClose(sender : id): LongBool; message 'windowShouldClose:';
|
function windowShouldClose(sender : id): LongBool; message 'windowShouldClose:';
|
||||||
procedure windowWillClose(notification: NSNotification); message 'windowWillClose:';
|
procedure windowWillClose(notification: NSNotification); message 'windowWillClose:';
|
||||||
@ -28,9 +35,7 @@ type
|
|||||||
procedure windowDidResignKey(notification: NSNotification); message 'windowDidResignKey:';
|
procedure windowDidResignKey(notification: NSNotification); message 'windowDidResignKey:';
|
||||||
procedure windowDidResize(notification: NSNotification); message 'windowDidResize:';
|
procedure windowDidResize(notification: NSNotification); message 'windowDidResize:';
|
||||||
public
|
public
|
||||||
LCLForm: TCustomForm;
|
WindowHandle: TCocoaWindow;
|
||||||
Children: TFPList; // TCDWinControl
|
|
||||||
LastMouseDownControl: TWinControl; // Stores the control which should receive the next MouseUp
|
|
||||||
function acceptsFirstResponder: Boolean; override;
|
function acceptsFirstResponder: Boolean; override;
|
||||||
procedure mouseUp(event: NSEvent); override;
|
procedure mouseUp(event: NSEvent); override;
|
||||||
procedure mouseDown(event: NSEvent); override;
|
procedure mouseDown(event: NSEvent); override;
|
||||||
@ -61,10 +66,8 @@ type
|
|||||||
|
|
||||||
TCocoaCustomControl = objcclass(NSControl)
|
TCocoaCustomControl = objcclass(NSControl)
|
||||||
//callback : TCommonCallback;
|
//callback : TCommonCallback;
|
||||||
Image: TLazIntfImage;
|
WindowHandle: TCocoaWindow;
|
||||||
Canvas: TLazCanvas;
|
|
||||||
Context : TCocoaContext;
|
Context : TCocoaContext;
|
||||||
LCLForm: TCustomForm;
|
|
||||||
procedure drawRect(dirtyRect: NSRect); override;
|
procedure drawRect(dirtyRect: NSRect); override;
|
||||||
procedure Draw(ControlContext: NSGraphicsContext; const Abounds, dirty:NSRect); message 'draw:Context:bounds:';
|
procedure Draw(ControlContext: NSGraphicsContext; const Abounds, dirty:NSRect); message 'draw:Context:bounds:';
|
||||||
public
|
public
|
||||||
@ -175,9 +178,9 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaWindow }
|
{ TCocoaForm }
|
||||||
|
|
||||||
function TCocoaWindow.windowShouldClose(sender: id): LongBool;
|
function TCocoaForm.windowShouldClose(sender: id): LongBool;
|
||||||
var
|
var
|
||||||
canClose : Boolean;
|
canClose : Boolean;
|
||||||
begin
|
begin
|
||||||
@ -186,32 +189,32 @@ begin
|
|||||||
Result:=canClose;
|
Result:=canClose;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.windowWillClose(notification: NSNotification);
|
procedure TCocoaForm.windowWillClose(notification: NSNotification);
|
||||||
begin
|
begin
|
||||||
LCLSendCloseUpMsg(LCLForm);
|
LCLSendCloseUpMsg(WindowHandle.LCLForm);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.windowDidBecomeKey(notification: NSNotification);
|
procedure TCocoaForm.windowDidBecomeKey(notification: NSNotification);
|
||||||
begin
|
begin
|
||||||
CallbackActivate;
|
CallbackActivate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.windowDidResignKey(notification: NSNotification);
|
procedure TCocoaForm.windowDidResignKey(notification: NSNotification);
|
||||||
begin
|
begin
|
||||||
CallbackDeactivate;
|
CallbackDeactivate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.windowDidResize(notification: NSNotification);
|
procedure TCocoaForm.windowDidResize(notification: NSNotification);
|
||||||
begin
|
begin
|
||||||
CallbackResize;
|
CallbackResize;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaWindow.acceptsFirstResponder: Boolean;
|
function TCocoaForm.acceptsFirstResponder: Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.mouseUp(event: NSEvent);
|
procedure TCocoaForm.mouseUp(event: NSEvent);
|
||||||
var
|
var
|
||||||
mp : NSPoint;
|
mp : NSPoint;
|
||||||
begin
|
begin
|
||||||
@ -221,7 +224,7 @@ begin
|
|||||||
inherited mouseUp(event);
|
inherited mouseUp(event);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.mouseDown(event: NSEvent);
|
procedure TCocoaForm.mouseDown(event: NSEvent);
|
||||||
var
|
var
|
||||||
mp : NSPoint;
|
mp : NSPoint;
|
||||||
begin
|
begin
|
||||||
@ -231,7 +234,7 @@ begin
|
|||||||
inherited mouseDown(event);
|
inherited mouseDown(event);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.mouseDragged(event: NSEvent);
|
procedure TCocoaForm.mouseDragged(event: NSEvent);
|
||||||
var
|
var
|
||||||
mp : NSPoint;
|
mp : NSPoint;
|
||||||
begin
|
begin
|
||||||
@ -241,7 +244,7 @@ begin
|
|||||||
inherited mouseMoved(event);
|
inherited mouseMoved(event);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.mouseMoved(event: NSEvent);
|
procedure TCocoaForm.mouseMoved(event: NSEvent);
|
||||||
var
|
var
|
||||||
mp : NSPoint;
|
mp : NSPoint;
|
||||||
begin
|
begin
|
||||||
@ -251,32 +254,32 @@ begin
|
|||||||
inherited mouseMoved(event);
|
inherited mouseMoved(event);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.mouseEntered(event: NSEvent);
|
procedure TCocoaForm.mouseEntered(event: NSEvent);
|
||||||
begin
|
begin
|
||||||
inherited mouseEntered(event);
|
inherited mouseEntered(event);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.mouseExited(event: NSEvent);
|
procedure TCocoaForm.mouseExited(event: NSEvent);
|
||||||
begin
|
begin
|
||||||
inherited mouseExited(event);
|
inherited mouseExited(event);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaWindow.lclIsVisible:Boolean;
|
function TCocoaForm.lclIsVisible:Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=isVisible;
|
Result:=isVisible;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.lclInvalidateRect(const r:TRect);
|
procedure TCocoaForm.lclInvalidateRect(const r:TRect);
|
||||||
begin
|
begin
|
||||||
contentView.lclInvalidateRect(r);
|
contentView.lclInvalidateRect(r);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.lclInvalidate;
|
procedure TCocoaForm.lclInvalidate;
|
||||||
begin
|
begin
|
||||||
contentView.lclInvalidate;
|
contentView.lclInvalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.lclLocalToScreen(var X,Y:Integer);
|
procedure TCocoaForm.lclLocalToScreen(var X,Y:Integer);
|
||||||
var
|
var
|
||||||
f : NSRect;
|
f : NSRect;
|
||||||
begin
|
begin
|
||||||
@ -287,14 +290,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaWindow.lclFrame:TRect;
|
function TCocoaForm.lclFrame:TRect;
|
||||||
begin
|
begin
|
||||||
if Assigned(screen)
|
if Assigned(screen)
|
||||||
then NSToLCLRect(frame, screen.frame.size.height, Result)
|
then NSToLCLRect(frame, screen.frame.size.height, Result)
|
||||||
else NSToLCLRect(frame, Result);
|
else NSToLCLRect(frame, Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.lclSetFrame(const r:TRect);
|
procedure TCocoaForm.lclSetFrame(const r:TRect);
|
||||||
var
|
var
|
||||||
ns : NSREct;
|
ns : NSREct;
|
||||||
begin
|
begin
|
||||||
@ -304,7 +307,7 @@ begin
|
|||||||
setFrame_display(ns, isVisible);
|
setFrame_display(ns, isVisible);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaWindow.lclClientFrame:TRect;
|
function TCocoaForm.lclClientFrame:TRect;
|
||||||
var
|
var
|
||||||
wr : NSRect;
|
wr : NSRect;
|
||||||
b : CGGeometry.CGRect;
|
b : CGGeometry.CGRect;
|
||||||
@ -317,68 +320,69 @@ begin
|
|||||||
Result.Bottom:=Round(Result.Top+b.size.height);
|
Result.Bottom:=Round(Result.Top+b.size.height);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.CallbackActivate;
|
procedure TCocoaForm.CallbackActivate;
|
||||||
begin
|
begin
|
||||||
LCLSendActivateMsg(LCLForm, True, false);
|
LCLSendActivateMsg(WindowHandle.LCLForm, True, false);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.CallbackDeactivate;
|
procedure TCocoaForm.CallbackDeactivate;
|
||||||
begin
|
begin
|
||||||
LCLSendDeactivateStartMsg(LCLForm);
|
LCLSendDeactivateStartMsg(WindowHandle.LCLForm);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.CallbackCloseQuery(var CanClose: Boolean);
|
procedure TCocoaForm.CallbackCloseQuery(var CanClose: Boolean);
|
||||||
begin
|
begin
|
||||||
// Message results : 0 - do nothing, 1 - destroy window
|
// Message results : 0 - do nothing, 1 - destroy window
|
||||||
CanClose:=LCLSendCloseQueryMsg(LCLForm)>0;
|
CanClose:=LCLSendCloseQueryMsg(WindowHandle.LCLForm)>0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.CallbackResize;
|
procedure TCocoaForm.CallbackResize;
|
||||||
var
|
var
|
||||||
sz : NSSize;
|
sz : NSSize;
|
||||||
r : TRect;
|
r : TRect;
|
||||||
begin
|
begin
|
||||||
sz := frame.size;
|
sz := frame.size;
|
||||||
TCDWSCustomForm.GetClientBounds(TWinControl(LCLForm), r);
|
TCDWSCustomForm.GetClientBounds(TWinControl(WindowHandle.LCLForm), r);
|
||||||
if Assigned(LCLForm) then
|
if Assigned(WindowHandle.LCLForm) then
|
||||||
LCLSendSizeMsg(LCLForm, Round(sz.width), Round(sz.height), SIZENORMAL);
|
LCLSendSizeMsg(WindowHandle.LCLForm, Round(sz.width), Round(sz.height), SIZENORMAL);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.CallbackMouseUp(x, y: Integer);
|
procedure TCocoaForm.CallbackMouseUp(x, y: Integer);
|
||||||
var
|
var
|
||||||
lTarget: TWinControl;
|
lTarget: TWinControl;
|
||||||
lEventPos: TPoint;
|
lEventPos: TPoint;
|
||||||
begin
|
begin
|
||||||
lTarget := LastMouseDownControl;
|
lTarget := WindowHandle.LastMouseDownControl;
|
||||||
if lTarget = nil then lTarget := FindControlWhichReceivedEvent(LCLForm, Children, x, y);
|
if lTarget = nil then lTarget := FindControlWhichReceivedEvent(
|
||||||
|
WindowHandle.LCLForm, WindowHandle.Children, x, y);
|
||||||
lEventPos := FormPosToControlPos(lTarget, x, y);
|
lEventPos := FormPosToControlPos(lTarget, x, y);
|
||||||
LCLSendMouseUpMsg(lTarget, lEventPos.x, lEventPos.y, mbLeft, []);
|
LCLSendMouseUpMsg(lTarget, lEventPos.x, lEventPos.y, mbLeft, []);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.CallbackMouseDown(x, y: Integer);
|
procedure TCocoaForm.CallbackMouseDown(x, y: Integer);
|
||||||
var
|
var
|
||||||
lTarget: TWinControl;
|
lTarget: TWinControl;
|
||||||
lEventPos: TPoint;
|
lEventPos: TPoint;
|
||||||
begin
|
begin
|
||||||
lTarget := FindControlWhichReceivedEvent(LCLForm, Children, x, y);
|
lTarget := FindControlWhichReceivedEvent(WindowHandle.LCLForm, WindowHandle.Children, x, y);
|
||||||
LastMouseDownControl := lTarget;
|
WindowHandle.LastMouseDownControl := lTarget;
|
||||||
lEventPos := FormPosToControlPos(lTarget, x, y);
|
lEventPos := FormPosToControlPos(lTarget, x, y);
|
||||||
LCLSendMouseDownMsg(lTarget, lEventPos.x, lEventPos.y, mbLeft, []);
|
LCLSendMouseDownMsg(lTarget, lEventPos.x, lEventPos.y, mbLeft, []);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.CallbackMouseClick(clickCount: Integer);
|
procedure TCocoaForm.CallbackMouseClick(clickCount: Integer);
|
||||||
begin
|
begin
|
||||||
LCLSendClickedMsg(LCLForm);
|
LCLSendClickedMsg(WindowHandle.LCLForm);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.CallbackMouseMove(x, y: Integer);
|
procedure TCocoaForm.CallbackMouseMove(x, y: Integer);
|
||||||
var
|
var
|
||||||
lTarget: TWinControl;
|
lTarget: TWinControl;
|
||||||
lEventPos: TPoint;
|
lEventPos: TPoint;
|
||||||
begin
|
begin
|
||||||
lTarget := FindControlWhichReceivedEvent(LCLForm, Children, x, y);
|
lTarget := FindControlWhichReceivedEvent(WindowHandle.LCLForm, WindowHandle.Children, x, y);
|
||||||
lEventPos := FormPosToControlPos(lTarget, x, y);
|
lEventPos := FormPosToControlPos(lTarget, x, y);
|
||||||
LCLSendMouseMoveMsg(LCLForm, lEventPos.x, lEventPos.y, []);
|
LCLSendMouseMoveMsg(WindowHandle.LCLForm, lEventPos.x, lEventPos.y, []);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaCustomControl }
|
{ TCocoaCustomControl }
|
||||||
@ -409,27 +413,27 @@ begin
|
|||||||
// Prepare the non-native image and canvas
|
// Prepare the non-native image and canvas
|
||||||
FillChar(struct, SizeOf(TPaintStruct), 0);
|
FillChar(struct, SizeOf(TPaintStruct), 0);
|
||||||
|
|
||||||
UpdateControlLazImageAndCanvas(Image,
|
UpdateControlLazImageAndCanvas(WindowHandle.Image,
|
||||||
Canvas, lWidth, lHeight, clfRGB24UpsideDown);
|
WindowHandle.Canvas, lWidth, lHeight, clfRGB24UpsideDown);
|
||||||
DrawFormBackground(Image, Canvas);
|
DrawFormBackground(WindowHandle.Image, WindowHandle.Canvas);
|
||||||
|
|
||||||
struct.hdc := HDC(Canvas);
|
struct.hdc := HDC(WindowHandle.Canvas);
|
||||||
|
|
||||||
// Send the paint message to the LCL
|
// Send the paint message to the LCL
|
||||||
{$IFDEF VerboseCDWinAPI}
|
{$IFDEF VerboseCDWinAPI}
|
||||||
DebugLn(Format('[TLCLCommonCallback.Draw] OnPaint event started context: %x', [struct.hdc]));
|
DebugLn(Format('[TLCLCommonCallback.Draw] OnPaint event started context: %x', [struct.hdc]));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
LCLSendPaintMsg(LCLForm, struct.hdc, @struct);
|
LCLSendPaintMsg(WindowHandle.LCLForm, struct.hdc, @struct);
|
||||||
{$IFDEF VerboseCDWinAPI}
|
{$IFDEF VerboseCDWinAPI}
|
||||||
DebugLn('[TLCLCommonCallback.Draw] OnPaint event ended');
|
DebugLn('[TLCLCommonCallback.Draw] OnPaint event ended');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
// Now render all child wincontrols
|
// Now render all child wincontrols
|
||||||
RenderChildWinControls(Image, Canvas,
|
RenderChildWinControls(WindowHandle.Image, WindowHandle.Canvas,
|
||||||
TCDWSCustomForm.BackendGetCDWinControlList(LCLForm));
|
GetCDWinControlList(WindowHandle.LCLForm));
|
||||||
|
|
||||||
// Now render it into the control
|
// Now render it into the control
|
||||||
Image.GetRawImage(lRawImage);
|
WindowHandle.Image.GetRawImage(lRawImage);
|
||||||
Cocoa_RawImage_CreateBitmaps(lRawImage, lBitmap, lMask, True);
|
Cocoa_RawImage_CreateBitmaps(lRawImage, lBitmap, lMask, True);
|
||||||
Context.DrawBitmap(0, 0, TCocoaBitmap(lBitmap));
|
Context.DrawBitmap(0, 0, TCocoaBitmap(lBitmap));
|
||||||
end;
|
end;
|
||||||
|
@ -449,10 +449,12 @@ end;*)
|
|||||||
|
|
||||||
function TCDWidgetSet.BackendGetClientBounds(handle : HWND; var ARect : TRect) : Boolean;
|
function TCDWidgetSet.BackendGetClientBounds(handle : HWND; var ARect : TRect) : Boolean;
|
||||||
begin
|
begin
|
||||||
if Handle<>0 then begin
|
if Handle<>0 then
|
||||||
|
begin
|
||||||
Result:=True;
|
Result:=True;
|
||||||
ARect:= TCocoaWindow(handle).lclClientFrame;
|
ARect:= TCocoaWindow(handle).CocoaForm.lclClientFrame;
|
||||||
end else
|
end
|
||||||
|
else
|
||||||
Result:=False;
|
Result:=False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -505,10 +507,12 @@ end;*)
|
|||||||
|
|
||||||
function TCDWidgetSet.GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean;
|
function TCDWidgetSet.GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean;
|
||||||
begin
|
begin
|
||||||
if Handle<>0 then begin
|
if Handle<>0 then
|
||||||
|
begin
|
||||||
Result:=True;
|
Result:=True;
|
||||||
//TCocoaWindow(handle).lclRelativePos(Left, Top);
|
//TCocoaWindow(handle).lclRelativePos(Left, Top);
|
||||||
end else
|
end
|
||||||
|
else
|
||||||
Result:=False;
|
Result:=False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -527,12 +531,15 @@ end;*)
|
|||||||
|
|
||||||
function TCDWidgetSet.BackendInvalidateRect(aHandle : HWND; Rect : pRect; bErase : Boolean): Boolean;
|
function TCDWidgetSet.BackendInvalidateRect(aHandle : HWND; Rect : pRect; bErase : Boolean): Boolean;
|
||||||
begin
|
begin
|
||||||
if aHandle<>0 then begin
|
if aHandle<>0 then
|
||||||
|
begin
|
||||||
Result:=True;
|
Result:=True;
|
||||||
if Assigned(Rect)
|
if Assigned(Rect) then
|
||||||
then TCocoaWindow(aHandle).lclInvalidateRect(Rect^)
|
TCocoaWindow(aHandle).CocoaForm.lclInvalidateRect(Rect^)
|
||||||
else TCocoaWindow(aHandle).lclInvalidate;
|
else
|
||||||
end else
|
TCocoaWindow(aHandle).CocoaForm.lclInvalidate;
|
||||||
|
end
|
||||||
|
else
|
||||||
Result:=False;
|
Result:=False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -2,24 +2,6 @@
|
|||||||
|
|
||||||
{ TCDWSCustomForm }
|
{ TCDWSCustomForm }
|
||||||
|
|
||||||
class procedure TCDWSCustomForm.BackendAddCDWinControlToForm(const AForm: TCustomForm; ACDWinControl: TCDWinControl);
|
|
||||||
var
|
|
||||||
lwin: TCocoaWindow;
|
|
||||||
begin
|
|
||||||
lwin := TCocoaWindow(AForm.Handle);
|
|
||||||
if lwin.Children = nil then lwin.Children := TFPList.Create;
|
|
||||||
lwin.Children.Add(ACDWinControl);
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TCDWSCustomForm.BackendGetCDWinControlList(const AForm: TCustomForm): TFPList;
|
|
||||||
var
|
|
||||||
lwin: TCocoaWindow;
|
|
||||||
begin
|
|
||||||
lwin := TCocoaWindow(AForm.Handle);
|
|
||||||
if lwin.Children = nil then lwin.Children := TFPList.Create;
|
|
||||||
Result := lwin.Children;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: TCDWSCustomForm.CreateHandle
|
Method: TCDWSCustomForm.CreateHandle
|
||||||
Params: AWinControl - LCL control
|
Params: AWinControl - LCL control
|
||||||
@ -32,23 +14,26 @@ end;
|
|||||||
class function TCDWSCustomForm.CreateHandle(const AWinControl: TWinControl;
|
class function TCDWSCustomForm.CreateHandle(const AWinControl: TWinControl;
|
||||||
const AParams: TCreateParams): TLCLIntfHandle;
|
const AParams: TCreateParams): TLCLIntfHandle;
|
||||||
var
|
var
|
||||||
win : TCocoaWindow;
|
win : TCocoaForm;
|
||||||
|
winhandle: TCocoaWindow;
|
||||||
cnt : TCocoaCustomControl;
|
cnt : TCocoaCustomControl;
|
||||||
ns : NSString;
|
ns : NSString;
|
||||||
const
|
const
|
||||||
WinMask = NSTitledWindowMask or NSClosableWindowMask or NSMiniaturizableWindowMask or NSResizableWindowMask;
|
WinMask = NSTitledWindowMask or NSClosableWindowMask or NSMiniaturizableWindowMask or NSResizableWindowMask;
|
||||||
begin
|
begin
|
||||||
win := TCocoaWindow(TCocoaWindow.alloc);
|
win := TCocoaForm(TCocoaForm.alloc);
|
||||||
|
|
||||||
if not Assigned(win) then begin
|
if not Assigned(win) then
|
||||||
|
begin
|
||||||
Result:=0;
|
Result:=0;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
win:=TCocoaWindow(win.initWithContentRect_styleMask_backing_defer(CreateParamsToNSRect(AParams), WinMask, NSBackingStoreBuffered, False));
|
winhandle := TCocoaWindow.Create;
|
||||||
//TCocoaWindow(win).callback:=TLCLCommonCallback.Create(win, AWinControl);
|
winhandle.LCLForm := TCustomForm(AWinControl);
|
||||||
//TCocoaWindow(win).wincallback:=TLCLWindowCallback.Create(win, AWinControl);
|
|
||||||
TCocoaWindow(win).LCLForm := TCustomForm(AWinControl);
|
win:=TCocoaForm(win.initWithContentRect_styleMask_backing_defer(CreateParamsToNSRect(AParams), WinMask, NSBackingStoreBuffered, False));
|
||||||
|
win.WindowHandle := winhandle;
|
||||||
win.setDelegate(win);
|
win.setDelegate(win);
|
||||||
ns:=NSStringUtf8(AWinControl.Caption);
|
ns:=NSStringUtf8(AWinControl.Caption);
|
||||||
win.setTitle(ns);
|
win.setTitle(ns);
|
||||||
@ -56,10 +41,11 @@ begin
|
|||||||
win.setAcceptsMouseMovedEvents(True);
|
win.setAcceptsMouseMovedEvents(True);
|
||||||
|
|
||||||
cnt:=TCocoaCustomControl.alloc.init;
|
cnt:=TCocoaCustomControl.alloc.init;
|
||||||
cnt.LCLForm := TCustomForm(AWinControl);
|
cnt.WindowHandle := winhandle;
|
||||||
win.setContentView(cnt);
|
win.setContentView(cnt);
|
||||||
|
|
||||||
Result := TLCLIntfHandle(win);
|
winhandle.CocoaForm := win;
|
||||||
|
Result := TLCLIntfHandle(winhandle);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TCDWSCustomForm.DestroyHandle(const AWinControl: TWinControl);
|
class procedure TCDWSCustomForm.DestroyHandle(const AWinControl: TWinControl);
|
||||||
@ -72,7 +58,7 @@ begin
|
|||||||
if AWinControl.Handle=0 then Exit;
|
if AWinControl.Handle=0 then Exit;
|
||||||
{todo: setFrame_display(, true)? }
|
{todo: setFrame_display(, true)? }
|
||||||
//sf:=NSScreen.mainScreen.frame;
|
//sf:=NSScreen.mainScreen.frame;
|
||||||
TCocoaWindow(AWinControl.Handle).lclSetFrame(Bounds(ALeft, ATop, AWidth, AHeight));
|
TCocoaWindow(AWinControl.Handle).CocoaForm.lclSetFrame(Bounds(ALeft, ATop, AWidth, AHeight));
|
||||||
|
|
||||||
//LCLToCocoaRect( GetNSRect(ALeft,ATop,AWidth,AHeight), sf, wf);
|
//LCLToCocoaRect( GetNSRect(ALeft,ATop,AWidth,AHeight), sf, wf);
|
||||||
//NSWindow(AWinControl.Handle).setFrame_display(wf, false);
|
//NSWindow(AWinControl.Handle).setFrame_display(wf, false);
|
||||||
@ -104,15 +90,15 @@ end;
|
|||||||
|
|
||||||
class procedure TCDWSCustomForm.ShowHide(const AWinControl: TWinControl);
|
class procedure TCDWSCustomForm.ShowHide(const AWinControl: TWinControl);
|
||||||
var
|
var
|
||||||
win : NSWindow;
|
win: TCocoaWindow;
|
||||||
begin
|
begin
|
||||||
win:=NSWindow(AWinControl.Handle);
|
win := TCocoaWindow(AWinControl.Handle);
|
||||||
if not Assigned(win) then Exit;
|
if not Assigned(win) then Exit;
|
||||||
|
|
||||||
if AWinControl.Visible then
|
if AWinControl.Visible then
|
||||||
win.orderFrontRegardless
|
win.CocoaForm.orderFrontRegardless
|
||||||
else
|
else
|
||||||
win.orderOut(nil);
|
win.CocoaForm.orderOut(nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCDWSCustomForm.GetText(const AWinControl: TWinControl; var AText: String): Boolean;
|
class function TCDWSCustomForm.GetText(const AWinControl: TWinControl; var AText: String): Boolean;
|
||||||
@ -122,7 +108,7 @@ begin
|
|||||||
win:=TCocoaWindow(AWinControl.Handle);
|
win:=TCocoaWindow(AWinControl.Handle);
|
||||||
Result:=Assigned(win);
|
Result:=Assigned(win);
|
||||||
if not Result then Exit;
|
if not Result then Exit;
|
||||||
AText:=NSStringToString(win.title);
|
AText:=NSStringToString(win.CocoaForm.title);
|
||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -133,7 +119,7 @@ begin
|
|||||||
win:=TCocoaWindow(AWinControl.Handle);
|
win:=TCocoaWindow(AWinControl.Handle);
|
||||||
Result:=Assigned(win);
|
Result:=Assigned(win);
|
||||||
if not Result then Exit;
|
if not Result then Exit;
|
||||||
ALength:=win.title.length;
|
ALength:=win.CocoaForm.title.length;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TCDWSCustomForm.SetText(const AWinControl: TWinControl; const AText: String);
|
class procedure TCDWSCustomForm.SetText(const AWinControl: TWinControl; const AText: String);
|
||||||
@ -144,7 +130,7 @@ begin
|
|||||||
win:=TCocoaWindow(AWinControl.Handle);
|
win:=TCocoaWindow(AWinControl.Handle);
|
||||||
if not Assigned(win) then Exit;
|
if not Assigned(win) then Exit;
|
||||||
ns:=NSStringUtf8(AText);
|
ns:=NSStringUtf8(AText);
|
||||||
win.setTitle(ns);
|
win.CocoaForm.setTitle(ns);
|
||||||
ns.release;
|
ns.release;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -152,7 +138,7 @@ class function TCDWSCustomForm.GetClientBounds(const AWinControl: TWinControl; v
|
|||||||
begin
|
begin
|
||||||
Result:=AWinControl.Handle<>0;
|
Result:=AWinControl.Handle<>0;
|
||||||
if not Result then Exit;
|
if not Result then Exit;
|
||||||
ARect:= TCocoaWindow(AWinControl.Handle).lclClientFrame;
|
ARect:= TCocoaWindow(AWinControl.Handle).CocoaForm.lclClientFrame;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCDWSCustomForm.GetClientRect(const AWinControl: TWinControl; var ARect: TRect): Boolean;
|
class function TCDWSCustomForm.GetClientRect(const AWinControl: TWinControl; var ARect: TRect): Boolean;
|
||||||
@ -161,9 +147,9 @@ var
|
|||||||
begin
|
begin
|
||||||
Result:=AWinControl.Handle<>0;
|
Result:=AWinControl.Handle<>0;
|
||||||
if not Result then Exit;
|
if not Result then Exit;
|
||||||
ARect:= TCocoaWindow(AWinControl.Handle).lclClientFrame;
|
ARect:= TCocoaWindow(AWinControl.Handle).CocoaForm.lclClientFrame;
|
||||||
x:=0;y:=0;
|
x:=0;y:=0;
|
||||||
TCocoaWindow(AWinControl.Handle).lclLocalToScreen(x,y);
|
TCocoaWindow(AWinControl.Handle).CocoaForm.lclLocalToScreen(x,y);
|
||||||
MoveRect(ARect, x,y);
|
MoveRect(ARect, x,y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user