mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-20 02:20:58 +01:00
cocoa: updating lclRelativePos function, based on the patch by David Jenkins. bug #36049
git-svn-id: trunk@62434 -
This commit is contained in:
parent
c620145935
commit
62146e35bf
@ -127,6 +127,10 @@ type
|
|||||||
procedure lclInvalidateRect(const r: TRect); message 'lclInvalidateRect:';
|
procedure lclInvalidateRect(const r: TRect); message 'lclInvalidateRect:';
|
||||||
procedure lclInvalidate; message 'lclInvalidate';
|
procedure lclInvalidate; message 'lclInvalidate';
|
||||||
procedure lclUpdate; message 'lclUpdate';
|
procedure lclUpdate; message 'lclUpdate';
|
||||||
|
|
||||||
|
// Returns the position of the view or window, in the immediate
|
||||||
|
// parent (view or screen), relative to its client coordinates system
|
||||||
|
// Left and Top are always returned in LCL coordinate system.
|
||||||
procedure lclRelativePos(var Left, Top: Integer); message 'lclRelativePos::';
|
procedure lclRelativePos(var Left, Top: Integer); message 'lclRelativePos::';
|
||||||
procedure lclLocalToScreen(var X, Y: Integer); message 'lclLocalToScreen::';
|
procedure lclLocalToScreen(var X, Y: Integer); message 'lclLocalToScreen::';
|
||||||
procedure lclScreenToLocal(var X, Y: Integer); message 'lclScreenToLocal::';
|
procedure lclScreenToLocal(var X, Y: Integer); message 'lclScreenToLocal::';
|
||||||
@ -1024,8 +1028,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure LCLViewExtension.lclRelativePos(var Left, Top: Integer);
|
procedure LCLViewExtension.lclRelativePos(var Left, Top: Integer);
|
||||||
|
var
|
||||||
|
sv : NSView;
|
||||||
|
fr : NSRect;
|
||||||
begin
|
begin
|
||||||
Left := Round(frame.origin.x);
|
Left := Round(frame.origin.x);
|
||||||
|
sv := superview;
|
||||||
|
if Assigned(sv) and (not sv.isFlipped) then
|
||||||
|
begin
|
||||||
|
fr := frame;
|
||||||
|
Top := Round(sv.frame.size.height - fr.origin.y - fr.size.height);
|
||||||
|
end
|
||||||
|
else
|
||||||
Top := Round(frame.origin.y);
|
Top := Round(frame.origin.y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1035,18 +1049,22 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
// 1. convert to window base
|
// 1. convert to window base
|
||||||
|
// Convert from View-lcl to View-cocoa
|
||||||
P.x := X;
|
P.x := X;
|
||||||
if isFlipped then
|
if isFlipped then
|
||||||
p.y := Y
|
p.y := Y
|
||||||
else
|
else
|
||||||
P.y := frame.size.height-y; // convert to Cocoa system
|
P.y := frame.size.height-y; // convert to Cocoa system
|
||||||
|
|
||||||
|
// Convert from View-cocoa to Window-cocoa
|
||||||
P := convertPoint_ToView(P, nil);
|
P := convertPoint_ToView(P, nil);
|
||||||
|
|
||||||
|
// Convert from Window-cocoa to Window-lcl
|
||||||
X := Round(P.X);
|
X := Round(P.X);
|
||||||
Y := Round(window.frame.size.height-P.Y); // convert to LCL system
|
Y := Round(window.frame.size.height-P.Y); // convert to LCL system
|
||||||
|
|
||||||
// 2. convert window to screen
|
// 2. convert window to screen
|
||||||
|
// Use window function to convert fomr Window-lcl to Screen-lcl
|
||||||
window.lclLocalToScreen(X, Y);
|
window.lclLocalToScreen(X, Y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1055,13 +1073,17 @@ var
|
|||||||
P: NSPoint;
|
P: NSPoint;
|
||||||
begin
|
begin
|
||||||
// 1. convert from screen to window
|
// 1. convert from screen to window
|
||||||
|
// use window function to onvert from Screen-lcl to Window-lcl
|
||||||
window.lclScreenToLocal(X, Y);
|
window.lclScreenToLocal(X, Y);
|
||||||
|
// Convert from Window-lcl to Window-cocoa
|
||||||
P.x := X;
|
P.x := X;
|
||||||
P.y := Round(window.frame.size.height-Y); // convert to Cocoa system
|
P.y := Round(window.frame.size.height-Y); // convert to Cocoa system
|
||||||
|
|
||||||
// 2. convert from window to local
|
// 2. convert from window to local
|
||||||
|
// Convert from Window-cocoa to View-cocoa
|
||||||
P := convertPoint_FromView(P, nil);
|
P := convertPoint_FromView(P, nil);
|
||||||
|
|
||||||
|
// Convert from View-cocoa to View-lcl
|
||||||
X := Round(P.x);
|
X := Round(P.x);
|
||||||
if isFlipped then
|
if isFlipped then
|
||||||
Y := Round(p.y)
|
Y := Round(p.y)
|
||||||
@ -1079,7 +1101,7 @@ var
|
|||||||
v: NSView;
|
v: NSView;
|
||||||
begin
|
begin
|
||||||
v := superview;
|
v := superview;
|
||||||
if Assigned(v) then
|
if Assigned(v) and not v.isFlipped then
|
||||||
NSToLCLRect(frame, v.frame.size.height, Result)
|
NSToLCLRect(frame, v.frame.size.height, Result)
|
||||||
else
|
else
|
||||||
Result := NSRectToRect(frame);
|
Result := NSRectToRect(frame);
|
||||||
|
|||||||
@ -1318,12 +1318,7 @@ function TCocoaWidgetSet.GetWindowRelativePosition(Handle: hwnd; var Left, Top:
|
|||||||
begin
|
begin
|
||||||
Result := Handle <> 0;
|
Result := Handle <> 0;
|
||||||
if Result then
|
if Result then
|
||||||
begin
|
NSObject(handle).lclRelativePos(Left, Top);
|
||||||
if TCocoaWindowContent(handle).isembedded then
|
|
||||||
TCocoaWindowContent(handle).lclRelativePos(Left, Top)
|
|
||||||
else
|
|
||||||
TCocoaWindowContent(handle).window.lclRelativePos(Left, Top);
|
|
||||||
end
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaWidgetSet.GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean;
|
function TCocoaWidgetSet.GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean;
|
||||||
|
|||||||
@ -221,6 +221,7 @@ type
|
|||||||
function lclOwnWindow: NSWindow; message 'lclOwnWindow';
|
function lclOwnWindow: NSWindow; message 'lclOwnWindow';
|
||||||
procedure lclSetFrame(const r: TRect); override;
|
procedure lclSetFrame(const r: TRect); override;
|
||||||
function lclFrame: TRect; override;
|
function lclFrame: TRect; override;
|
||||||
|
procedure lclRelativePos(var Left, Top: Integer); override;
|
||||||
procedure viewDidMoveToSuperview; override;
|
procedure viewDidMoveToSuperview; override;
|
||||||
procedure viewDidMoveToWindow; override;
|
procedure viewDidMoveToWindow; override;
|
||||||
procedure viewWillMoveToWindow(newWindow: CocoaAll.NSWindow); override;
|
procedure viewWillMoveToWindow(newWindow: CocoaAll.NSWindow); override;
|
||||||
@ -452,6 +453,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaWindowContent.lclRelativePos(var Left, Top: Integer);
|
||||||
|
begin
|
||||||
|
if isembedded then
|
||||||
|
inherited lclRelativePos(Left, Top)
|
||||||
|
else
|
||||||
|
window.lclRelativePos(Left, Top);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindowContent.viewDidMoveToSuperview;
|
procedure TCocoaWindowContent.viewDidMoveToSuperview;
|
||||||
begin
|
begin
|
||||||
inherited viewDidMoveToSuperview;
|
inherited viewDidMoveToSuperview;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user