mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-10 10:59:30 +02:00
cocoa:
* changed bounds setting/getting mechanism using objccategory. * removed bounds setting/getting functions from CocoaUtils * implemented DC origin changing getting functions * fix CriticalSection compilation problem (related bug #17341) * added stubs for Scroll-related winapi function git-svn-id: trunk@27273 -
This commit is contained in:
parent
78e3076672
commit
3cd980b72a
@ -125,7 +125,8 @@ type
|
||||
procedure Rectangle(X1, Y1, X2, Y2: Integer; FillRect: Boolean; UseBrush: TCocoaBrush);
|
||||
procedure Ellipse(X1, Y1, X2, Y2: Integer);
|
||||
procedure TextOut(X,Y: Integer; UTF8Chars: PChar; Count: Integer; CharsDelta: PInteger);
|
||||
procedure MoveOrigin(X,Y: Integer);
|
||||
procedure SetOrigin(X,Y: Integer);
|
||||
procedure GetOrigin(var X,Y: Integer);
|
||||
function CGContext: CGContextRef; virtual;
|
||||
property Brush: TCocoaBrush read fBrush write SetBrush;
|
||||
property Pen: TCocoaPen read fPen write SetPen;
|
||||
@ -375,7 +376,7 @@ begin
|
||||
CGContextScaleCTM(cg, 1, -1);
|
||||
end;
|
||||
|
||||
procedure TCocoaContext.MoveOrigin(X,Y:Integer);
|
||||
procedure TCocoaContext.SetOrigin(X,Y:Integer);
|
||||
var
|
||||
cg : CGContextRef;
|
||||
begin
|
||||
@ -384,6 +385,18 @@ begin
|
||||
if Assigned(cg) then CGContextTranslateCTM(cg, X, Y);
|
||||
end;
|
||||
|
||||
procedure TCocoaContext.GetOrigin(var X,Y: Integer);
|
||||
var
|
||||
cg : CGContextRef;
|
||||
t : CGAffineTransform;
|
||||
begin
|
||||
cg:=CGContext;
|
||||
if not Assigned(cg) then Exit;
|
||||
t:=CGContextGetCTM(cg);
|
||||
X := Round(t.tx);
|
||||
Y := ContextSize.cy - Round(t.ty);
|
||||
end;
|
||||
|
||||
|
||||
{ TCocoaRegion }
|
||||
|
||||
|
@ -32,6 +32,49 @@ uses
|
||||
MacOSAll, CocoaAll, CocoaUtils;
|
||||
|
||||
type
|
||||
{ LCLObjectExtension }
|
||||
|
||||
LCLObjectExtension = objccategory(NSObject)
|
||||
function lclIsEnabled: Boolean; message 'lclIsEnabled';
|
||||
procedure lclSetEnabled(AEnabled: Boolean); message 'lclSetEnabled:';
|
||||
function lclIsVisible: Boolean; message 'lclIsVisible';
|
||||
|
||||
procedure lclInvalidateRect(const r: TRect); message 'lclInvalidateRect:';
|
||||
procedure lclInvalidate; message 'lclInvalidate';
|
||||
procedure lclRelativePos(var Left, Top: Integer); message 'lclRelativePos::';
|
||||
procedure lclLocalToScreen(var X,Y: Integer); message 'lclLocalToScreen::';
|
||||
function lclParent: id; message 'lclParent';
|
||||
function lclFrame: TRect; message 'lclFrame';
|
||||
procedure lclSetFrame(const r: TRect); message 'lclSetFrame:';
|
||||
function lclClientFrame: TRect; message 'lclClientFrame';
|
||||
end;
|
||||
|
||||
{ LCLControlExtension }
|
||||
|
||||
LCLControlExtension = objccategory(NSControl)
|
||||
function lclIsEnabled: Boolean; message 'lclIsEnabled';
|
||||
procedure lclSetEnabled(AEnabled: Boolean); message 'lclSetEnabled:';
|
||||
function lclIsVisible: Boolean; message 'lclIsVisible';
|
||||
procedure lclInvalidateRect(const r: TRect); message 'lclInvalidateRect:';
|
||||
procedure lclInvalidate; message 'lclInvalidate';
|
||||
procedure lclLocalToScreen(var X,Y: Integer); message 'lclLocalToScreen::';
|
||||
function lclParent: id; message 'lclParent';
|
||||
function lclFrame: TRect; message 'lclFrame';
|
||||
procedure lclSetFrame(const r: TRect); message 'lclSetFrame:';
|
||||
function lclClientFrame: TRect; message 'lclClientFrame';
|
||||
end;
|
||||
|
||||
{ LCLWindowExtension }
|
||||
|
||||
LCLWindowExtension = objccategory(NSWindow)
|
||||
function lclIsVisible: Boolean; message 'lclIsVisible';
|
||||
procedure lclInvalidateRect(const r: TRect); message 'lclInvalidateRect:';
|
||||
procedure lclInvalidate; message 'lclInvalidate';
|
||||
procedure lclLocalToScreen(var X,Y: Integer); message 'lclLocalToScreen::';
|
||||
function lclFrame: TRect; message 'lclFrame';
|
||||
procedure lclSetFrame(const r: TRect); message 'lclSetFrame:';
|
||||
function lclClientFrame: TRect; message 'lclClientFrame';
|
||||
end;
|
||||
|
||||
{ TCommonCallback }
|
||||
|
||||
@ -319,5 +362,199 @@ begin
|
||||
callback.Draw(NSGraphicsContext.currentContext, bounds, dirtyRect);
|
||||
end;
|
||||
|
||||
{ LCLObjectExtension }
|
||||
|
||||
function LCLObjectExtension.lclIsEnabled:Boolean;
|
||||
begin
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
procedure LCLObjectExtension.lclSetEnabled(AEnabled:Boolean);
|
||||
begin
|
||||
end;
|
||||
|
||||
function LCLObjectExtension.lclIsVisible:Boolean;
|
||||
begin
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
procedure LCLObjectExtension.lclInvalidateRect(const r:TRect);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
procedure LCLObjectExtension.lclInvalidate;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
procedure LCLObjectExtension.lclRelativePos(var Left,Top:Integer);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
procedure LCLObjectExtension.lclLocalToScreen(var X,Y:Integer);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
function LCLObjectExtension.lclParent:id;
|
||||
begin
|
||||
Result:=nil;
|
||||
end;
|
||||
|
||||
function LCLObjectExtension.lclFrame:TRect;
|
||||
begin
|
||||
FillChar(Result, sizeof(Result), 0);
|
||||
end;
|
||||
|
||||
procedure LCLObjectExtension.lclSetFrame(const r:TRect);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
function LCLObjectExtension.lclClientFrame:TRect;
|
||||
begin
|
||||
FillChar(Result, sizeof(Result), 0);
|
||||
end;
|
||||
|
||||
{ LCLControlExtension }
|
||||
|
||||
function RectToViewCoord(view: NSView; const r: TRect): NSRect;
|
||||
var
|
||||
b: NSRect;
|
||||
begin
|
||||
if not Assigned(view) then Exit;
|
||||
b:=view.bounds;
|
||||
Result.origin.x:=r.Left;
|
||||
Result.origin.y:=b.size.height-r.Top;
|
||||
Result.size.width:=r.Right-r.Left;
|
||||
Result.size.height:=r.Bottom-r.Top;
|
||||
end;
|
||||
|
||||
function LCLControlExtension.lclIsEnabled:Boolean;
|
||||
begin
|
||||
Result:=IsEnabled;
|
||||
end;
|
||||
|
||||
procedure LCLControlExtension.lclSetEnabled(AEnabled:Boolean);
|
||||
begin
|
||||
SetEnabled(AEnabled);
|
||||
end;
|
||||
|
||||
function LCLControlExtension.lclIsVisible:Boolean;
|
||||
begin
|
||||
Result:=not isHidden;
|
||||
end;
|
||||
|
||||
procedure LCLControlExtension.lclInvalidateRect(const r:TRect);
|
||||
begin
|
||||
setNeedsDisplayInRect(RectToViewCoord(Self, r));
|
||||
end;
|
||||
|
||||
procedure LCLControlExtension.lclInvalidate;
|
||||
begin
|
||||
setNeedsDisplay;
|
||||
end;
|
||||
|
||||
procedure LCLControlExtension.lclLocalToScreen(var X,Y:Integer);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
function LCLControlExtension.lclParent:id;
|
||||
begin
|
||||
Result:=superView;
|
||||
end;
|
||||
|
||||
function LCLControlExtension.lclFrame: TRect;
|
||||
var
|
||||
v : NSView;
|
||||
begin
|
||||
v:=superview;
|
||||
if Assigned(v)
|
||||
then NSToLCLRect(frame, v.frame.size.height, Result)
|
||||
else NSToLCLRect(frame, Result);
|
||||
end;
|
||||
|
||||
procedure LCLControlExtension.lclSetFrame(const r:TRect);
|
||||
var
|
||||
ns : NSRect;
|
||||
begin
|
||||
if Assigned(superview)
|
||||
then LCLToNSRect(r, superview.frame.size.height, ns)
|
||||
else LCLToNSRect(r, ns);
|
||||
setFrame(ns);
|
||||
end;
|
||||
|
||||
function LCLControlExtension.lclClientFrame:TRect;
|
||||
var
|
||||
r: NSRect;
|
||||
begin
|
||||
r:=bounds;
|
||||
Result.Left:=0;
|
||||
Result.Top:=0;
|
||||
Result.Right:=Round(r.size.width);
|
||||
Result.Bottom:=Round(r.size.height);
|
||||
end;
|
||||
|
||||
{ LCLWindowExtension }
|
||||
|
||||
function LCLWindowExtension.lclIsVisible:Boolean;
|
||||
begin
|
||||
Result:=isVisible;
|
||||
end;
|
||||
|
||||
procedure LCLWindowExtension.lclInvalidateRect(const r:TRect);
|
||||
begin
|
||||
contentView.lclInvalidateRect(r);
|
||||
end;
|
||||
|
||||
procedure LCLWindowExtension.lclInvalidate;
|
||||
begin
|
||||
contentView.lclInvalidate;
|
||||
end;
|
||||
|
||||
procedure LCLWindowExtension.lclLocalToScreen(var X,Y:Integer);
|
||||
var
|
||||
f : NSRect;
|
||||
begin
|
||||
if Assigned(screen) then begin
|
||||
f:=frame;
|
||||
x:=Round(f.origin.x+x);
|
||||
y:=Round(screen.frame.size.height-f.size.height-f.origin.y);
|
||||
end;
|
||||
end;
|
||||
|
||||
function LCLWindowExtension.lclFrame:TRect;
|
||||
begin
|
||||
if Assigned(screen)
|
||||
then NSToLCLRect(frame, screen.frame.size.height, Result)
|
||||
else NSToLCLRect(frame, Result);
|
||||
end;
|
||||
|
||||
procedure LCLWindowExtension.lclSetFrame(const r:TRect);
|
||||
var
|
||||
ns : NSREct;
|
||||
begin
|
||||
if Assigned(screen)
|
||||
then LCLToNSRect(r, screen.frame.size.height, ns)
|
||||
else LCLToNSRect(r, ns);
|
||||
setFrame_display(ns, isVisible);
|
||||
end;
|
||||
|
||||
function LCLWindowExtension.lclClientFrame:TRect;
|
||||
var
|
||||
wr : NSRect;
|
||||
b : NSRect;
|
||||
begin
|
||||
wr:=frame;
|
||||
b:=contentView.frame;
|
||||
Result.Left:=Round(b.origin.x);
|
||||
Result.Top:=Round(wr.size.height-b.origin.y);
|
||||
Result.Right:=Round(b.origin.x+b.size.width);
|
||||
Result.Bottom:=Round(Result.Top+b.size.height);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -16,7 +16,13 @@ function CGRectToRect(const c: CGRect): TRect;
|
||||
|
||||
function GetNSRect(x, y, width, height: Integer): NSRect; inline;
|
||||
function RectToNSRect(const r: TRect): NSRect;
|
||||
procedure NSRectToRect(const ns: NSRect; var r: TRect);
|
||||
|
||||
procedure NSToLCLRect(const ns: NSRect; var lcl: TRect); overload;
|
||||
procedure NSToLCLRect(const ns: NSRect; ParentHeight: Single; var lcl: TRect); overload;
|
||||
|
||||
procedure LCLToNSRect(const lcl: TRect; var ns: NSRect); overload;
|
||||
procedure LCLToNSRect(const lcl: TRect; ParentHeight: Single; var ns: NSRect); overload;
|
||||
|
||||
function CreateParamsToNSRect(const params: TCreateParams): NSRect;
|
||||
|
||||
function NSStringUtf8(s: PChar): NSString;
|
||||
@ -27,22 +33,12 @@ function GetNSObjectView(obj: NSObject): NSView;
|
||||
procedure AddViewToNSObject(ctrl: NSView; obj: NSObject);
|
||||
procedure AddViewToNSObject(ctrl: NSView; obj: NSObject; X,Y: integer);
|
||||
|
||||
procedure SetViewFramePos(view: NSView; X,Y: Single; invalidateView: Boolean=false);
|
||||
procedure SetViewFrame(view: NSView; X,Y,W,H: Single; invalidateView: Boolean=false);
|
||||
procedure GetViewFrame(view: NSView; var FrameRect: TRect);
|
||||
|
||||
procedure SetNSText(text: NSText; const s: String); inline;
|
||||
function GetNSText(text: NSText): string; inline;
|
||||
|
||||
procedure SetNSControlValue(c: NSControl; const S: String); inline;
|
||||
function GetNSControlValue(c: NSControl): String; inline;
|
||||
|
||||
procedure LCLToCocoaRect(const lcl, parent: NSRect; var cocoa: NSRect); inline;
|
||||
procedure CocoaToLCLRect(const cocoa, parent: NSRect; var lcl: NSRect); inline;
|
||||
|
||||
function GetNSWindowFrame(win: NSWindow; var lcl: TRect): Boolean; inline;
|
||||
function GetNSViewFrame(view: NSView; var lcl: TRect): boolean; inline;
|
||||
|
||||
implementation
|
||||
|
||||
const
|
||||
@ -80,48 +76,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{X,Y - coordinates relative to Left-Top (LCL-style)}
|
||||
procedure SetViewFramePos(view: NSView; X,Y: Single; invalidateView: Boolean);
|
||||
var
|
||||
f : NSRect;
|
||||
begin
|
||||
f:=view.frame;
|
||||
SetViewFrame(view,x,y,f.size.width, f.size.height, invalidateView);
|
||||
end;
|
||||
|
||||
{X,Y - coordinates relative to Left-Top (LCL-style)}
|
||||
{W,H - width and height of the NSView}
|
||||
procedure SetViewFrame(view: NSView; X,Y,W,H: single; invalidateView: Boolean=false); overload;
|
||||
var
|
||||
parent : NSView;
|
||||
pb, b : NSRect;
|
||||
begin
|
||||
parent:=view.superView;
|
||||
if not Assigned(parent) then Exit;
|
||||
pb:=parent.bounds;
|
||||
b:=view.frame;
|
||||
b.origin.x:=X;
|
||||
b.origin.y:=pb.size.height-y-h;
|
||||
b.size.width:=w;
|
||||
b.size.height:=h;
|
||||
view.setFrame(b);
|
||||
if invalidateView then view.setNeedsDisplay_(true);
|
||||
end;
|
||||
|
||||
procedure GetViewFrame(view: NSView; var FrameRect: TRect);
|
||||
var
|
||||
parent : NSView;
|
||||
pb, f : NSRect;
|
||||
begin
|
||||
f:=view.frame;
|
||||
parent:=view.superView;
|
||||
if Assigned(parent) then begin
|
||||
pb:=parent.bounds;
|
||||
f.origin.y:=pb.size.height-f.origin.y-f.size.height;
|
||||
end;
|
||||
NSRectToRect(f, FrameRect);
|
||||
end;
|
||||
|
||||
function GetNSObjectView(obj: NSObject): NSView;
|
||||
begin
|
||||
Result:=nil;
|
||||
@ -142,7 +96,7 @@ end;
|
||||
procedure AddViewToNSObject(ctrl: NSView; obj: NSObject; X,Y: integer);
|
||||
begin
|
||||
AddViewToNSObject(ctrl, obj);
|
||||
SetViewFramePos(ctrl, x,y);
|
||||
//SetViewFramePos(ctrl, x,y);
|
||||
end;
|
||||
|
||||
function GetNSPoint(x, y: single): NSPoint;
|
||||
@ -182,14 +136,39 @@ begin
|
||||
Result:=GetNSRect(r.Left,r.Top,r.Right-r.Left,r.Bottom-r.Top);
|
||||
end;
|
||||
|
||||
procedure NSRectToRect(const ns: NSRect; var r: TRect);
|
||||
procedure NSToLCLRect(const ns: NSRect; var lcl: TRect);
|
||||
begin
|
||||
r.Left:=round(ns.origin.x);
|
||||
r.Top:=round(ns.origin.y);
|
||||
r.Right:=round(ns.origin.x+ns.size.width);
|
||||
r.Bottom:=round(ns.origin.y+ns.size.height);
|
||||
lcl.Left:=round(ns.origin.x);
|
||||
lcl.Top:=round(ns.origin.y);
|
||||
lcl.Right:=round(ns.origin.x+ns.size.width);
|
||||
lcl.Bottom:=round(ns.origin.y+ns.size.height);
|
||||
end;
|
||||
|
||||
procedure NSToLCLRect(const ns: NSRect; ParentHeight: Single; var lcl: TRect);
|
||||
begin
|
||||
lcl.Left:=Round(ns.origin.x);
|
||||
lcl.Top:=Round(ParentHeight-ns.size.height-ns.origin.y);
|
||||
lcl.Right:=Round(ns.origin.x+ns.size.width);
|
||||
lcl.Bottom:=Round(lcl.Top+ns.size.height);
|
||||
end;
|
||||
|
||||
procedure LCLToNSRect(const lcl: TRect; var ns: NSRect); overload;
|
||||
begin
|
||||
ns.origin.x:=lcl.Left;
|
||||
ns.origin.y:=lcl.Top;
|
||||
ns.size.width:=lcl.Right-lcl.Left;
|
||||
ns.size.height:=lcl.Bottom-lcl.Top;
|
||||
end;
|
||||
|
||||
procedure LCLToNSRect(const lcl: TRect; ParentHeight: Single; var ns: NSRect); overload;
|
||||
begin
|
||||
ns.origin.x:=lcl.left;
|
||||
ns.origin.y:=ParentHeight-(lcl.bottom-lcl.Top)-lcl.Top;
|
||||
ns.size.width:=lcl.Right-lcl.Left;
|
||||
ns.size.height:=lcl.Bottom-lcl.Top;
|
||||
end;
|
||||
|
||||
|
||||
function CreateParamsToNSRect(const params: TCreateParams): NSRect;
|
||||
begin
|
||||
with params do Result:=GetNSRect(X,Y,Width,Height);
|
||||
@ -247,46 +226,7 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
procedure LCLToCocoaRect(const lcl, parent: NSRect; var cocoa: NSRect);
|
||||
begin
|
||||
cocoa.origin.x:=lcl.origin.x;
|
||||
cocoa.origin.y:=parent.size.height - lcl.size.height - lcl.origin.y;
|
||||
cocoa.size:=lcl.size;
|
||||
end;
|
||||
|
||||
procedure CocoaToLCLRect(const cocoa, parent: NSRect; var lcl: NSRect);
|
||||
begin
|
||||
lcl.origin.x:=cocoa.origin.x;
|
||||
lcl.origin.y:=parent.size.height-cocoa.size.height-cocoa.origin.y;
|
||||
lcl.size:=cocoa.size;
|
||||
end;
|
||||
|
||||
function GetNSWindowFrame(win: NSWindow; var lcl: TRect): Boolean;
|
||||
var
|
||||
f : NSRect;
|
||||
begin
|
||||
if Assigned(win.screen) then begin
|
||||
CocoaToLCLRect( win.frame, win.screen.frame, f);
|
||||
NSRectToRect(f, lcl);
|
||||
end else
|
||||
NSRectToRect(win.frame, lcl);
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function GetNSViewFrame(view: NSView; var lcl: TRect): boolean; inline;
|
||||
var
|
||||
f : NSRect;
|
||||
begin
|
||||
if Assigned(view.superview) then begin
|
||||
CocoaToLCLRect( view.frame, view.superview.frame, f);
|
||||
NSRectToRect(f, lcl);
|
||||
end else
|
||||
NSRectToRect(view.frame, lcl);
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
|
||||
end.
|
||||
|
||||
|
@ -45,6 +45,8 @@ begin
|
||||
Result:=(Round(b*$FF) shl 16) or (Round(g*$FF) shl 8) or Round(r*$FF);
|
||||
end;
|
||||
|
||||
{--------------------------------- WINDOWS ------------------------------------}
|
||||
|
||||
function TCocoaWidgetSet.ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;
|
||||
begin
|
||||
{$ifdef VerboseCocoaWinAPI}
|
||||
@ -72,17 +74,149 @@ end;
|
||||
Retrieves the screen bounding rectangle of the specified window
|
||||
------------------------------------------------------------------------------}
|
||||
function TCocoaWidgetSet.GetWindowRect(Handle: hwnd; var ARect: TRect): Integer;
|
||||
var
|
||||
dx, dy: Integer;
|
||||
begin
|
||||
Result:=0;
|
||||
if Handle=0 then Exit;
|
||||
|
||||
if NSObject(Handle).isKindOfClass_(NSWindow) then
|
||||
GetNSWindowFrame(NSWindow(Handle), ARect)
|
||||
else
|
||||
{todo: GetNSViewFrame(NSView(Handle), ARect)};
|
||||
if Handle<>0 then begin
|
||||
ARect:=NSObject(Handle).lclFrame;
|
||||
if not NSObject(Handle).isKindOfClass_(NSWindow) then begin
|
||||
dx:=0; dy:=0;
|
||||
NSObject(Handle).lclLocalToScreen(dx, dx);
|
||||
MoveRect(ARect, dx, dy);
|
||||
end;
|
||||
Result:=1;
|
||||
end else
|
||||
Result:=0;
|
||||
end;
|
||||
|
||||
{--------------------------------- DRAWING ------------------------------------}
|
||||
function TCocoaWidgetSet.IsWindowEnabled(Handle: HWND): boolean;
|
||||
begin
|
||||
if Handle<>0
|
||||
then Result:=NSObject(Handle).lclIsEnabled
|
||||
else Result:=False;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.EnableWindow(hWnd: HWND; bEnable: Boolean): Boolean;
|
||||
begin
|
||||
if hWnd<>0
|
||||
then NSObject(hWnd).lclSetEnabled(bEnable)
|
||||
else Result:=False;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.IsWindowVisible(Handle: HWND): boolean;
|
||||
begin
|
||||
if Handle<>0
|
||||
then Result:=NSObject(Handle).lclIsVisible
|
||||
else Result:=False;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.GetClientBounds(handle : HWND; var ARect : TRect) : Boolean;
|
||||
begin
|
||||
if Handle<>0 then begin
|
||||
Result:=True;
|
||||
ARect:=NSObject(handle).lclClientFrame;
|
||||
end else
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.GetClientRect(handle : HWND; var ARect : TRect) : Boolean;
|
||||
var
|
||||
dx, dy: Integer;
|
||||
begin
|
||||
if Handle<>0 then begin
|
||||
Result:=True;
|
||||
ARect:=NSObject(handle).lclClientFrame;
|
||||
dx:=0; dy:=0;
|
||||
NSObject(Handle).lclLocalToScreen(dx, dy);
|
||||
MoveRect(ARect, dx, dy);
|
||||
end else
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.GetParent(Handle : HWND): HWND;
|
||||
begin
|
||||
if Handle<>0 then
|
||||
Result:=HWND(NSObject(Handle).lclParent)
|
||||
else
|
||||
Result:=0;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean;
|
||||
begin
|
||||
if Handle<>0 then begin
|
||||
Result:=True;
|
||||
NSObject(handle).lclRelativePos(Left, Top);
|
||||
end else
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean;
|
||||
var
|
||||
r : TRect;
|
||||
begin
|
||||
if Handle<>0 then begin
|
||||
Result:=True;
|
||||
r:=NSObject(Handle).lclFrame;
|
||||
Width:=R.Right-R.Left;
|
||||
Height:=R.Bottom-R.Top;
|
||||
end else
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.InvalidateRect(aHandle : HWND; Rect : pRect; bErase : Boolean): Boolean;
|
||||
begin
|
||||
if aHandle<>0 then begin
|
||||
Result:=True;
|
||||
if Assigned(Rect)
|
||||
then NSObject(aHandle).lclInvalidateRect(Rect^)
|
||||
else NSObject(aHandle).lclInvalidate;
|
||||
end else
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.UpdateWindow(Handle: HWND): Boolean;
|
||||
begin
|
||||
Result:=InvalidateRect(Handle, nil, false);
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.GetProp(Handle : hwnd; Str : PChar): Pointer;
|
||||
begin
|
||||
Result:=nil;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.SetProp(Handle: hwnd; Str : PChar; Data : Pointer) : Boolean;
|
||||
begin
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
{----------------------------- WINDOWS SCROLLING ------------------------------}
|
||||
|
||||
function TCocoaWidgetSet.GetScrollBarSize(Handle: HWND; BarKind: Integer): integer;
|
||||
begin
|
||||
Result:=0;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.GetScrollbarVisible(Handle: HWND; SBStyle: Integer): boolean;
|
||||
begin
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.GetScrollInfo(Handle: HWND; BarFlag: Integer; Var ScrollInfo: TScrollInfo): Boolean;
|
||||
begin
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.SetScrollInfo(Handle : HWND; SBStyle : Integer; ScrollInfo: TScrollInfo; bRedraw : Boolean): Integer;
|
||||
begin
|
||||
Result:=0;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.ShowScrollBar(Handle: HWND; wBar: Integer; bShow: Boolean): Boolean;
|
||||
begin
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
{----------------------------------- DRAWING ----------------------------------}
|
||||
|
||||
|
||||
type
|
||||
@ -277,10 +411,16 @@ begin
|
||||
CritSection:=0;
|
||||
end;
|
||||
|
||||
type
|
||||
//workaround for CocoaInt bug
|
||||
NSLockExtension = objccategory(NSRecursiveLock)
|
||||
procedure lock; message 'lock';
|
||||
procedure unlock; message 'unlock';
|
||||
end; external;
|
||||
|
||||
procedure TCocoaWidgetSet.EnterCriticalSection(var CritSection: TCriticalSection);
|
||||
begin
|
||||
if CritSection=0 then Exit;
|
||||
// if it doesn't compile, please follow bug #17341
|
||||
NSRecursiveLock(CritSection).lock;
|
||||
end;
|
||||
|
||||
@ -395,10 +535,23 @@ begin
|
||||
{$IFDEF VerboseWinAPI}
|
||||
DebugLn('TCarbonWidgetSet.MoveWindowOrgEx DC: ' + DbgS(DC) + ' ' + DbgS(DX) + ', ' + DbgS(DY));
|
||||
{$ENDIF}
|
||||
ctx.MoveOrigin(dX, dY);
|
||||
ctx.SetOrigin(dX, dY);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.GetWindowOrgEx(dc : hdc; P : PPoint): Integer;
|
||||
var
|
||||
ctx : TCocoaContext;
|
||||
begin
|
||||
ctx:=CheckDC(dc);
|
||||
if not Assigned(ctx) or not Assigned(P) then
|
||||
Result:=0
|
||||
else begin
|
||||
ctx.GetOrigin(p^.X, p^.Y);
|
||||
Result:=1;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------- FONT AND TEXT --------------------------------}
|
||||
|
||||
function TCocoaWidgetSet.CreateFontIndirect(const LogFont: TLogFont): HFONT;
|
||||
@ -448,6 +601,18 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.GetTextColor(DC: HDC) : TColorRef;
|
||||
var
|
||||
ctx : TCocoaContext;
|
||||
begin
|
||||
ctx:=CheckDC(DC);
|
||||
if not Assigned(ctx) then begin
|
||||
Result:=0;
|
||||
Exit;
|
||||
end;
|
||||
with ctx do Result:=RGBToColorFloat(TR, TG, TB);
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.TextOut(DC: HDC; X,Y : Integer; Str : Pchar; Count: Integer) : Boolean;
|
||||
begin
|
||||
Result:=ExtTextOut(DC, X, Y, 0, nil, Str, Count, nil);
|
||||
|
@ -72,9 +72,9 @@ function DrawEdge(DC: HDC; var Rect: TRect; edge: Cardinal; grfFlags: Cardinal):
|
||||
function DrawText(DC: HDC; Str: PChar; Count: Integer; var ARect: TRect; Flags: Cardinal): Integer; override;}
|
||||
|
||||
function Ellipse(DC: HDC; x1, y1, x2, y2: Integer): Boolean; override;
|
||||
{function EnableScrollBar(Wnd: HWND; wSBflags, wArrows: Cardinal): Boolean; override;
|
||||
{function EnableScrollBar(Wnd: HWND; wSBflags, wArrows: Cardinal): Boolean; override;}
|
||||
function EnableWindow(hWnd: HWND; bEnable: Boolean): Boolean; override;
|
||||
function EndPaint(Handle: hwnd; var PS: TPaintStruct): Integer; override;}
|
||||
{function EndPaint(Handle: hwnd; var PS: TPaintStruct): Integer; override;}
|
||||
procedure EnterCriticalSection(var CritSection: TCriticalSection); override;
|
||||
function EnumFontFamiliesEx(DC: HDC; lpLogFont: PLogFont; Callback: FontEnumExProc; Lparam: LParam; Flags: dword): longint; override;
|
||||
{function ExcludeClipRect(dc: hdc; Left, Top, Right, Bottom : Integer) : Integer; override;
|
||||
@ -91,10 +91,10 @@ function GetActiveWindow : HWND; override;
|
||||
function GetBitmapBits(Bitmap: HBITMAP; Count: Longint; Bits: Pointer): Longint; override;
|
||||
function GetCapture: HWND; override;
|
||||
function GetCaretPos(var lpPoint: TPoint): Boolean; override;
|
||||
function GetCaretRespondToFocus(handle: HWND; var ShowHideOnFocus: boolean): Boolean; override;
|
||||
function GetCaretRespondToFocus(handle: HWND; var ShowHideOnFocus: boolean): Boolean; override;}
|
||||
function GetClientBounds(handle : HWND; var ARect : TRect) : Boolean; override;
|
||||
function GetClientRect(handle : HWND; var ARect : TRect) : Boolean; override;
|
||||
function GetClipBox(DC : hDC; lpRect : PRect) : Longint; override;
|
||||
{function GetClipBox(DC : hDC; lpRect : PRect) : Longint; override;
|
||||
function GetClipRGN(DC: hDC; RGN: hRGN): Longint; override;
|
||||
function GetCursorPos(var lpPoint: TPoint ): Boolean; override;}
|
||||
function GetDC(hWnd: HWND): HDC; override;
|
||||
@ -104,35 +104,35 @@ function GetDeviceSize(DC: HDC; var P: TPoint): Boolean; Override;
|
||||
function GetDIBits(DC: HDC; Bitmap: HBitmap; StartScan, NumScans: UINT; Bits: Pointer; var BitInfo: BitmapInfo; Usage: UINT): Integer; Override;
|
||||
function GetFocus: HWND; override;
|
||||
function GetKeyState(nVirtKey: Integer): Smallint; override;
|
||||
function GetObject(GDIObj: HGDIOBJ; BufSize: Integer; Buf: Pointer): Integer; override;
|
||||
function GetObject(GDIObj: HGDIOBJ; BufSize: Integer; Buf: Pointer): Integer; override;}
|
||||
function GetParent(Handle : HWND): HWND; override;
|
||||
function GetProp(Handle : hwnd; Str : PChar): Pointer; override;
|
||||
function GetRgnBox(RGN : HRGN; lpRect : PRect) : Longint; override;
|
||||
function GetROP2(DC: HDC): Integer; override;
|
||||
{function GetRgnBox(RGN : HRGN; lpRect : PRect) : Longint; override;
|
||||
function GetROP2(DC: HDC): Integer; override;}
|
||||
function GetScrollBarSize(Handle: HWND; BarKind: Integer): integer; override;
|
||||
function GetScrollbarVisible(Handle: HWND; SBStyle: Integer): boolean; override;
|
||||
function GetScrollInfo(Handle: HWND; BarFlag: Integer; Var ScrollInfo: TScrollInfo): Boolean; override;
|
||||
function GetStockObject(Value: Integer): THandle; override;
|
||||
{function GetStockObject(Value: Integer): THandle; override;
|
||||
function GetSysColor(nIndex: Integer): DWORD; override;
|
||||
function GetSystemMetrics(nIndex: Integer): Integer; override;
|
||||
function GetSystemMetrics(nIndex: Integer): Integer; override;}
|
||||
function GetTextColor(DC: HDC) : TColorRef; Override;
|
||||
function GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean; override;
|
||||
{function GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean; override;
|
||||
function GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean; override;
|
||||
function GetWindowLong(Handle : hwnd; int: Integer): PtrInt; override;
|
||||
function GetWindowOrgEx(dc : hdc; P : PPoint): Integer; override;}
|
||||
function GetWindowLong(Handle : hwnd; int: Integer): PtrInt; override;}
|
||||
function GetWindowOrgEx(dc : hdc; P : PPoint): Integer; override;
|
||||
function GetWindowRect(Handle: hwnd; var ARect: TRect): Integer; override;
|
||||
{function GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean; override;
|
||||
function GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean; override;
|
||||
function GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean; override;
|
||||
function GradientFill(DC: HDC; Vertices: PTriVertex; NumVertices : Longint;
|
||||
{function GradientFill(DC: HDC; Vertices: PTriVertex; NumVertices : Longint;
|
||||
Meshes: Pointer; NumMeshes : Longint; Mode : Longint): Boolean; override;
|
||||
|
||||
function HideCaret(hWnd: HWND): Boolean; override;
|
||||
function HideCaret(hWnd: HWND): Boolean; override;}
|
||||
|
||||
function InvalidateRect(aHandle : HWND; Rect : pRect; bErase : Boolean) : Boolean; override;}
|
||||
function InvalidateRect(aHandle : HWND; Rect : pRect; bErase : Boolean) : Boolean; override;
|
||||
procedure InitializeCriticalSection(var CritSection: TCriticalSection); override;
|
||||
{function IntersectClipRect(dc: hdc; Left, Top, Right, Bottom: Integer): Integer; override;
|
||||
{function IntersectClipRect(dc: hdc; Left, Top, Right, Bottom: Integer): Integer; override;}
|
||||
function IsWindowEnabled(Handle: HWND): boolean; override;
|
||||
function IsWindowVisible(Handle: HWND): boolean; override;}
|
||||
function IsWindowVisible(Handle: HWND): boolean; override;
|
||||
|
||||
procedure LeaveCriticalSection(var CritSection: TCriticalSection); override;
|
||||
function LineTo(DC: HDC; X, Y: Integer): Boolean; override;
|
||||
@ -169,13 +169,13 @@ function SetCaretRespondToFocus(handle: HWND; ShowHideOnFocus: boolean): Boolean
|
||||
function SetCursor(ACursor: HCURSOR): HCURSOR; override;
|
||||
function SetCursorPos(X, Y: Integer): Boolean; override;
|
||||
function SetFocus(hWnd: HWND): HWND; override;
|
||||
function SetForegroundWindow(HWnd: HWND): boolean; override;
|
||||
function SetForegroundWindow(HWnd: HWND): boolean; override;}
|
||||
function SetProp(Handle: hwnd; Str : PChar; Data : Pointer) : Boolean; override;
|
||||
function SetScrollInfo(Handle : HWND; SBStyle : Integer; ScrollInfo: TScrollInfo; bRedraw : Boolean): Integer; override;}
|
||||
function SetScrollInfo(Handle : HWND; SBStyle : Integer; ScrollInfo: TScrollInfo; bRedraw : Boolean): Integer; override;
|
||||
function SetTextColor(DC: HDC; Color: TColorRef): TColorRef; override;
|
||||
{function SetWindowOrgEx(DC : HDC; NewX, NewY : Integer; OldPoint: PPoint) : Boolean; override;
|
||||
function ShowCaret(hWnd: HWND): Boolean; override;
|
||||
function ShowScrollBar(Handle: HWND; wBar: Integer; bShow: Boolean): Boolean; override;}
|
||||
function ShowCaret(hWnd: HWND): Boolean; override;}
|
||||
function ShowScrollBar(Handle: HWND; wBar: Integer; bShow: Boolean): Boolean; override;
|
||||
function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean; override;
|
||||
{function StretchBlt(DestDC: HDC; X, Y, Width, Height: Integer;
|
||||
SrcDC: HDC; XSrc, YSrc, SrcWidth, SrcHeight: Integer; ROp: Cardinal): Boolean; override;
|
||||
@ -185,8 +185,8 @@ function StretchMaskBlt(DestDC: HDC; X, Y, Width, Height: Integer;
|
||||
function SystemParametersInfo(uiAction: DWord; uiParam: DWord; pvParam: Pointer; fWinIni: DWord): LongBool; override;}
|
||||
|
||||
function TextOut(DC: HDC; X,Y : Integer; Str : Pchar; Count: Integer) : Boolean; override;
|
||||
{function UpdateWindow(Handle: HWND): Boolean; override;
|
||||
function WindowFromPoint(Point: TPoint): HWND; override;}
|
||||
function UpdateWindow(Handle: HWND): Boolean; override;
|
||||
{function WindowFromPoint(Point: TPoint): HWND; override;}
|
||||
|
||||
//##apiwiz##eps## // Do not remove, no wizard declaration after this line
|
||||
|
||||
|
@ -121,7 +121,6 @@ begin
|
||||
if Context.InitDraw(Round(bounds.size.width), Round(bounds.size.height)) then begin
|
||||
FillChar(struct, SizeOf(TPaintStruct), 0);
|
||||
struct.hdc := HDC(Context);
|
||||
writeln('target = ', Integer(Target),' ', Target.ClassName);
|
||||
LCLSendPaintMsg(Target, HDC(Context), @struct);
|
||||
end;
|
||||
end;
|
||||
@ -181,21 +180,21 @@ class function TCocoaWSWinControl.GetClientBounds(const AWincontrol: TWinControl
|
||||
begin
|
||||
Result:=(AWinControl.Handle<>0);
|
||||
if not Result then Exit;
|
||||
GetViewFrame(NSView(AWinControl.Handle), ARect);
|
||||
ARect:=NSObject(AWinControl.Handle).lclClientFrame;
|
||||
end;
|
||||
|
||||
class function TCocoaWSWinControl.GetClientRect(const AWincontrol: TWinControl; var ARect: TRect): Boolean;
|
||||
begin
|
||||
Result:=(AWinControl.Handle<>0);
|
||||
if not Result then Exit;
|
||||
NSRectToRect(NSView(AWinControl.Handle).bounds, ARect);
|
||||
ARect:=NSObject(AWinControl.Handle).lclClientFrame;
|
||||
end;
|
||||
|
||||
class procedure TCocoaWSWinControl.SetBounds(const AWinControl: TWinControl;
|
||||
const ALeft, ATop, AWidth, AHeight: Integer);
|
||||
begin
|
||||
if (AWinControl.Handle=0) then Exit;
|
||||
SetViewFrame(NSView(AWinControl.Handle), ALeft, ATop, AWidth, AHeight);
|
||||
if (AWinControl.Handle<>0) then
|
||||
NSObject(AWinControl.Handle).lclSetFrame(Bounds(ALeft, ATop, AWidth, AHeight));
|
||||
end;
|
||||
|
||||
{ TCocoaWSCustomControl }
|
||||
|
@ -274,32 +274,31 @@ class function TCocoaWSCustomForm.GetClientBounds(const AWinControl: TWinControl
|
||||
begin
|
||||
Result:=AWinControl.Handle<>0;
|
||||
if not Result then Exit;
|
||||
|
||||
Result:=GetNSWindowFrame(NSWindow(AWinControl.Handle), ARect);
|
||||
ARect:=NSObject(AWinControl.Handle).lclClientFrame;
|
||||
end;
|
||||
|
||||
class function TCocoaWSCustomForm.GetClientRect(const AWinControl: TWinControl;
|
||||
var ARect: TRect): Boolean;
|
||||
class function TCocoaWSCustomForm.GetClientRect(const AWinControl: TWinControl; var ARect: TRect): Boolean;
|
||||
var
|
||||
x,y : Integer;
|
||||
begin
|
||||
Result:=AWinControl.Handle<>0;
|
||||
if not Result then Exit;
|
||||
|
||||
{todo:}
|
||||
GetViewFrame( NSWindow(AWinControl.Handle).contentView, ARect );
|
||||
ARect:=NSObject(AWinControl.Handle).lclClientFrame;
|
||||
x:=0;y:=0;
|
||||
NSObject(AWinControl.Handle).lclLocalToScreen(x,y);
|
||||
MoveRect(ARect, x,y);
|
||||
end;
|
||||
|
||||
class procedure TCocoaWSCustomForm.SetBounds(const AWinControl: TWinControl;
|
||||
const ALeft, ATop, AWidth, AHeight: Integer);
|
||||
var
|
||||
sf, wf : NSRect;
|
||||
begin
|
||||
if AWinControl.Handle=0 then Exit;
|
||||
{todo: setFrame_display(, true)? }
|
||||
sf:=NSScreen.mainScreen.frame;
|
||||
//sf:=NSScreen.mainScreen.frame;
|
||||
NSObject(AWinControl.Handle).lclSetFrame(Bounds(ALeft, ATop, AWidth, AHeight));
|
||||
|
||||
LCLToCocoaRect( GetNSRect(ALeft,ATop,AWidth,AHeight), sf, wf);
|
||||
|
||||
NSWindow(AWinControl.Handle).setFrame_display(wf, false);
|
||||
//LCLToCocoaRect( GetNSRect(ALeft,ATop,AWidth,AHeight), sf, wf);
|
||||
//NSWindow(AWinControl.Handle).setFrame_display(wf, false);
|
||||
//NSWindow(AWinControl.Handle).setFrame_display( GetNSRect(ALeft,ATop, AWidth, AHeight), false);
|
||||
//NSWindow(AWinControl.Handle).setFrameTopLeftPoint( GetNSPoint(ALeft, ATop));
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user