mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-07-23 16:46:11 +02:00
cocoa: start work on sizing/positioning
git-svn-id: trunk@34128 -
This commit is contained in:
parent
9c38c40343
commit
61a5e41099
@ -86,10 +86,15 @@ type
|
|||||||
{ ICommonCallback }
|
{ ICommonCallback }
|
||||||
|
|
||||||
ICommonCallback = interface
|
ICommonCallback = interface
|
||||||
|
// mouse events
|
||||||
procedure MouseDown(x,y: Integer);
|
procedure MouseDown(x,y: Integer);
|
||||||
procedure MouseUp(x,y: Integer);
|
procedure MouseUp(x,y: Integer);
|
||||||
procedure MouseClick(ClickCount: Integer);
|
procedure MouseClick(ClickCount: Integer);
|
||||||
procedure MouseMove(x,y: Integer);
|
procedure MouseMove(x,y: Integer);
|
||||||
|
// size,pos events
|
||||||
|
procedure frameDidChange;
|
||||||
|
procedure boundsDidChange;
|
||||||
|
// misc events
|
||||||
procedure Draw(ctx: NSGraphicsContext; const bounds, dirty: NSRect);
|
procedure Draw(ctx: NSGraphicsContext; const bounds, dirty: NSRect);
|
||||||
function ResetCursorRects: Boolean;
|
function ResetCursorRects: Boolean;
|
||||||
end;
|
end;
|
||||||
@ -129,6 +134,8 @@ type
|
|||||||
TCocoaButton = objcclass(NSButton)
|
TCocoaButton = objcclass(NSButton)
|
||||||
protected
|
protected
|
||||||
procedure actionButtonClick(sender: NSObject); message 'actionButtonClick:';
|
procedure actionButtonClick(sender: NSObject); message 'actionButtonClick:';
|
||||||
|
procedure boundsDidChange(sender: NSNotification); message 'boundsDidChange:';
|
||||||
|
procedure frameDidChange(sender: NSNotification); message 'frameDidChange:';
|
||||||
public
|
public
|
||||||
callback: IButtonCallback;
|
callback: IButtonCallback;
|
||||||
function initWithFrame(frameRect: NSRect): id; override;
|
function initWithFrame(frameRect: NSRect): id; override;
|
||||||
@ -316,6 +323,16 @@ begin
|
|||||||
callback.ButtonClick;
|
callback.ButtonClick;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaButton.boundsDidChange(sender: NSNotification);
|
||||||
|
begin
|
||||||
|
callback.boundsDidChange;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaButton.frameDidChange(sender: NSNotification);
|
||||||
|
begin
|
||||||
|
callback.frameDidChange;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCocoaButton.initWithFrame(frameRect: NSRect): id;
|
function TCocoaButton.initWithFrame(frameRect: NSRect): id;
|
||||||
begin
|
begin
|
||||||
Result := inherited initWithFrame(frameRect);
|
Result := inherited initWithFrame(frameRect);
|
||||||
@ -323,6 +340,10 @@ begin
|
|||||||
begin
|
begin
|
||||||
setTarget(Self);
|
setTarget(Self);
|
||||||
setAction(objcselector('actionButtonClick:'));
|
setAction(objcselector('actionButtonClick:'));
|
||||||
|
NSNotificationCenter.defaultCenter.addObserver_selector_name_object(Self, objcselector('boundsDidChange:'), NSViewBoundsDidChangeNotification, Result);
|
||||||
|
NSNotificationCenter.defaultCenter.addObserver_selector_name_object(Self, objcselector('frameDidChange:'), NSViewFrameDidChangeNotification, Result);
|
||||||
|
Result.setPostsBoundsChangedNotifications(True);
|
||||||
|
Result.setPostsFrameChangedNotifications(True);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ uses
|
|||||||
MacOSAll, CocoaAll,
|
MacOSAll, CocoaAll,
|
||||||
Classes, Controls, SysUtils,
|
Classes, Controls, SysUtils,
|
||||||
//
|
//
|
||||||
WSControls, LCLType, LCLProc, Forms,
|
WSControls, LCLType, LMessages, LCLProc, Forms,
|
||||||
CocoaPrivate, CocoaGDIObjects, CocoaUtils, LCLMessageGlue;
|
CocoaPrivate, CocoaGDIObjects, CocoaUtils, LCLMessageGlue;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -26,14 +26,16 @@ type
|
|||||||
TLCLCommonCallback = class(TObject, ICommonCallBack)
|
TLCLCommonCallback = class(TObject, ICommonCallBack)
|
||||||
public
|
public
|
||||||
Owner: NSObject;
|
Owner: NSObject;
|
||||||
Target : TControl;
|
Target : TWinControl;
|
||||||
Context : TCocoaContext;
|
Context : TCocoaContext;
|
||||||
constructor Create(AOwner: NSObject; ATarget: TControl); virtual;
|
constructor Create(AOwner: NSObject; ATarget: TWinControl); virtual;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure MouseDown(x,y: Integer); virtual;
|
procedure MouseDown(x,y: Integer); virtual;
|
||||||
procedure MouseUp(x,y: Integer); virtual;
|
procedure MouseUp(x,y: Integer); virtual;
|
||||||
procedure MouseClick(clickCount: Integer); virtual;
|
procedure MouseClick(clickCount: Integer); virtual;
|
||||||
procedure MouseMove(x,y: Integer); virtual;
|
procedure MouseMove(x,y: Integer); virtual;
|
||||||
|
procedure frameDidChange; virtual;
|
||||||
|
procedure boundsDidChange; virtual;
|
||||||
procedure Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); virtual;
|
procedure Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); virtual;
|
||||||
function ResetCursorRects: Boolean; virtual;
|
function ResetCursorRects: Boolean; virtual;
|
||||||
end;
|
end;
|
||||||
@ -111,7 +113,7 @@ end;
|
|||||||
|
|
||||||
{ TLCLCommonCallback }
|
{ TLCLCommonCallback }
|
||||||
|
|
||||||
constructor TLCLCommonCallback.Create(AOwner: NSObject; ATarget: TControl);
|
constructor TLCLCommonCallback.Create(AOwner: NSObject; ATarget: TWinControl);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
Owner := AOwner;
|
Owner := AOwner;
|
||||||
@ -144,6 +146,70 @@ begin
|
|||||||
LCLSendMouseMoveMsg(Target, x,y, []);
|
LCLSendMouseMoveMsg(Target, x,y, []);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLCLCommonCallback.frameDidChange;
|
||||||
|
begin
|
||||||
|
boundsDidChange;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLCLCommonCallback.boundsDidChange;
|
||||||
|
var
|
||||||
|
NewBounds, OldBounds: TRect;
|
||||||
|
PosMsg: TLMWindowPosChanged;
|
||||||
|
Resized, Moved: Boolean;
|
||||||
|
begin
|
||||||
|
NewBounds := Owner.lclFrame;
|
||||||
|
OldBounds := Target.BoundsRect;
|
||||||
|
|
||||||
|
Resized :=
|
||||||
|
(OldBounds.Right - OldBounds.Left <> NewBounds.Right - NewBounds.Left) or
|
||||||
|
(OldBounds.Bottom - OldBounds.Top <> NewBounds.Bottom - NewBounds.Top);
|
||||||
|
Moved :=
|
||||||
|
(OldBounds.Left <> NewBounds.Left) or
|
||||||
|
(OldBounds.Top <> NewBounds.Top);
|
||||||
|
|
||||||
|
// send window pos changed
|
||||||
|
if Resized or Moved then
|
||||||
|
begin
|
||||||
|
PosMsg.Msg := LM_WINDOWPOSCHANGED;
|
||||||
|
PosMsg.Result := 0;
|
||||||
|
New(PosMsg.WindowPos);
|
||||||
|
try
|
||||||
|
with PosMsg.WindowPos^ do
|
||||||
|
begin
|
||||||
|
hWndInsertAfter := 0;
|
||||||
|
x := NewBounds.Left;
|
||||||
|
y := NewBounds.Right;
|
||||||
|
cx := NewBounds.Right - NewBounds.Left;
|
||||||
|
cy := NewBounds.Bottom - NewBounds.Top;
|
||||||
|
flags := 0;
|
||||||
|
end;
|
||||||
|
DeliverMessage(Target, PosMsg);
|
||||||
|
finally
|
||||||
|
Dispose(PosMsg.WindowPos);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// update client rect
|
||||||
|
if Resized or Target.ClientRectNeedsInterfaceUpdate then
|
||||||
|
begin
|
||||||
|
Target.InvalidateClientRectCache(False);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// then send a LM_SIZE message
|
||||||
|
if Resized then
|
||||||
|
begin
|
||||||
|
LCLSendSizeMsg(Target, NewBounds.Right - NewBounds.Left,
|
||||||
|
NewBounds.Bottom - NewBounds.Top, Size_SourceIsInterface);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// then send a LM_MOVE message
|
||||||
|
if Moved then
|
||||||
|
begin
|
||||||
|
LCLSendMoveMsg(Target, NewBounds.Left,
|
||||||
|
NewBounds.Top, Move_SourceIsInterface);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TLCLCommonCallback.Draw(ControlContext: NSGraphicsContext;
|
procedure TLCLCommonCallback.Draw(ControlContext: NSGraphicsContext;
|
||||||
const bounds, dirty:NSRect);
|
const bounds, dirty:NSRect);
|
||||||
var
|
var
|
||||||
|
Loading…
Reference in New Issue
Block a user