mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-15 07:40:04 +02:00
cocoa: initial support for controls painting
git-svn-id: trunk@27243 -
This commit is contained in:
parent
32dbf71e3a
commit
d92436b1e6
@ -43,6 +43,7 @@ type
|
||||
procedure MouseUp(x,y: Integer); virtual; abstract;
|
||||
procedure MouseClick(ClickCount: Integer); virtual; abstract;
|
||||
procedure MouseMove(x,y: Integer); virtual; abstract;
|
||||
procedure Draw(ctx: NSGraphicsContext; r: NSRect); virtual; abstract;
|
||||
end;
|
||||
|
||||
{ TWindowCallback }
|
||||
@ -58,13 +59,6 @@ type
|
||||
procedure Resize; virtual; abstract;
|
||||
end;
|
||||
|
||||
{ TCocoaWindowContentView }
|
||||
|
||||
TCocoaWindowContentView = objcclass(NSView)
|
||||
public
|
||||
procedure drawRect(r: NSRect); override;
|
||||
end;
|
||||
|
||||
{todo: consider using common protocol for all TCocoa* derived objcclasses }
|
||||
{TCocoaTopLeftRect = objcprotocol
|
||||
procedure getTopLeftFrame(var r: TRect); message 'getTopLeftFrame:';
|
||||
@ -106,6 +100,8 @@ type
|
||||
function acceptsFirstResponder: Boolean; override;
|
||||
end;
|
||||
|
||||
{ TCocoaWindow }
|
||||
|
||||
TCocoaWindow = objcclass(NSWindow)
|
||||
protected
|
||||
function windowShouldClose(sender : id): LongBool; message 'windowShouldClose:';
|
||||
@ -125,20 +121,15 @@ type
|
||||
procedure mouseMoved(event: NSEvent); override;
|
||||
end;
|
||||
|
||||
{ TCocoaCustomControl }
|
||||
|
||||
TCocoaCustomControl = objcclass(NSControl)
|
||||
callback : TCommonCallback;
|
||||
procedure drawRect(dirtyRect: NSRect); override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TCocoaWindowContentView }
|
||||
|
||||
procedure TCocoaWindowContentView.drawRect(r: NSRect);
|
||||
begin
|
||||
//LCLSendPaintMsg();
|
||||
inherited drawRect(r);
|
||||
end;
|
||||
|
||||
{ TCocoaButton }
|
||||
|
||||
procedure TCocoaButton.actionButtonClick(sender: NSObject);
|
||||
@ -320,5 +311,13 @@ begin
|
||||
Owner:=AOwner;
|
||||
end;
|
||||
|
||||
{ TCocoaCustomControl }
|
||||
|
||||
procedure TCocoaCustomControl.drawRect(dirtyRect:NSRect);
|
||||
begin
|
||||
inherited drawRect(dirtyRect);
|
||||
callback.Draw(NSGraphicsContext.currentContext, dirtyRect);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -9,6 +9,16 @@ uses
|
||||
MacOSAll, CocoaAll,
|
||||
Types, LCLType;
|
||||
|
||||
type
|
||||
|
||||
{ TCocoaContext }
|
||||
|
||||
TCocoaContext = class(TObject)
|
||||
public
|
||||
ctx : NSGraphicsContext;
|
||||
end;
|
||||
|
||||
|
||||
function GetNSPoint(x,y: single): NSPoint; inline;
|
||||
|
||||
function GetNSRect(x, y, width, height: Integer): NSRect; inline;
|
||||
|
@ -19,11 +19,14 @@ type
|
||||
TLCLCommonCallback = class(TCommonCallback)
|
||||
public
|
||||
Target : TControl;
|
||||
Context : TCocoaContext;
|
||||
constructor Create(AOwner: NSObject; ATarget: TControl);
|
||||
destructor Destroy; override;
|
||||
procedure MouseDown(x,y: Integer); override;
|
||||
procedure MouseUp(x,y: Integer); override;
|
||||
procedure MouseClick(clickCount: Integer); override;
|
||||
procedure MouseMove(x,y: Integer); override;
|
||||
procedure Draw(ControlContext: NSGraphicsContext; dirty: NSRect); override;
|
||||
end;
|
||||
|
||||
{ TCocoaWSWinControl }
|
||||
@ -79,6 +82,13 @@ constructor TLCLCommonCallback.Create(AOwner: NSObject; ATarget: TControl);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
Target:=ATarget;
|
||||
Context:=TCocoaContext.Create;
|
||||
end;
|
||||
|
||||
destructor TLCLCommonCallback.Destroy;
|
||||
begin
|
||||
Context.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TLCLCommonCallback.MouseDown(x, y: Integer);
|
||||
@ -101,6 +111,15 @@ begin
|
||||
LCLSendMouseMoveMsg(Target, x,y, []);
|
||||
end;
|
||||
|
||||
procedure TLCLCommonCallback.Draw(ControlContext: NSGraphicsContext; dirty:NSRect);
|
||||
var
|
||||
struct : TPaintStruct;
|
||||
begin
|
||||
FillChar(struct, SizeOf(TPaintStruct), 0);
|
||||
struct.hdc := HDC(Context);
|
||||
LCLSendPaintMsg(Target, HDC(Context), @struct);
|
||||
end;
|
||||
|
||||
{ TCocoaWSWinControl }
|
||||
|
||||
class function TCocoaWSWinControl.CreateHandle(const AWinControl: TWinControl;
|
||||
|
@ -202,6 +202,7 @@ class function TCocoaWSCustomForm.CreateHandle(const AWinControl: TWinControl;
|
||||
const AParams: TCreateParams): TLCLIntfHandle;
|
||||
var
|
||||
win : TCocoaWindow;
|
||||
cnt : TCocoaCustomControl;
|
||||
const
|
||||
WinMask = NSTitledWindowMask or NSClosableWindowMask or NSMiniaturizableWindowMask or NSResizableWindowMask;
|
||||
begin
|
||||
@ -219,6 +220,10 @@ begin
|
||||
win.setTitle(NSStringUtf8(AWinControl.Caption));
|
||||
win.setAcceptsMouseMovedEvents(True);
|
||||
|
||||
cnt:=TCocoaCustomControl.alloc.init;
|
||||
cnt.callback:=TCocoaWindow(win).callback;
|
||||
win.setContentView(cnt);
|
||||
|
||||
Result := TLCLIntfHandle(win);
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user