Cocoa: new utils for Multi Display applied

This commit is contained in:
rich2014 2023-10-28 19:26:56 +08:00
parent 27fd42670e
commit e3a53a2a42
5 changed files with 19 additions and 26 deletions

View File

@ -1144,7 +1144,7 @@ begin
params.isFirstCall:= not hasMarkedText(); params.isFirstCall:= not hasMarkedText();
rect:= imeHandler.IMEGetTextBound( params ); rect:= imeHandler.IMEGetTextBound( params );
LCLToNSRect( rect, NSGlobalScreenHeight, Result ); LCLToNSRect( rect, NSGlobalScreenBottom, Result );
end; end;
procedure TCocoaFullControlEdit.unmarkText; procedure TCocoaFullControlEdit.unmarkText;

View File

@ -1074,7 +1074,7 @@ begin
contentView := TCocoaWindowContent(Handle); contentView := TCocoaWindowContent(Handle);
if (not contentView.isembedded) and Assigned(contentView.window) then if (not contentView.isembedded) and Assigned(contentView.window) then
NSToLCLRect(contentView.window.frame, NSGlobalScreenHeight, ARect) ARect := ScreenRectFromNSToLCL( contentView.window.frame )
else else
ARect := contentView.lclFrame; ARect := contentView.lclFrame;
Result := 1; Result := 1;
@ -1138,19 +1138,13 @@ end;
function TCocoaWidgetSet.GetCursorPos(var lpPoint: TPoint ): Boolean; function TCocoaWidgetSet.GetCursorPos(var lpPoint: TPoint ): Boolean;
begin begin
with NSEvent.mouseLocation do lpPoint:= ScreenPointFromNSToLCL( NSEvent.mouseLocation );
begin
lpPoint.x := Round(x);
// cocoa returns cursor with inverted y coordinate
lpPoint.y := Round(NSGlobalScreenHeight-y);
end;
//debugln('GetCursorPos='+DbgS(lpPoint)); //debugln('GetCursorPos='+DbgS(lpPoint));
Result := True; Result := True;
end; end;
function TCocoaWidgetSet.GetMonitorInfo(hMonitor: HMONITOR; lpmi: PMonitorInfo): Boolean; function TCocoaWidgetSet.GetMonitorInfo(hMonitor: HMONITOR; lpmi: PMonitorInfo): Boolean;
var var
globalScreenHeight: CGFloat;
ScreenID: NSScreen; ScreenID: NSScreen;
begin begin
Result := (lpmi <> nil) and (lpmi^.cbSize >= SizeOf(TMonitorInfo)); Result := (lpmi <> nil) and (lpmi^.cbSize >= SizeOf(TMonitorInfo));
@ -1159,9 +1153,8 @@ begin
Result := Assigned(ScreenID); Result := Assigned(ScreenID);
if not Result then Exit; if not Result then Exit;
globalScreenHeight := NSGlobalScreenHeight; lpmi^.rcMonitor:= ScreenRectFromNSToLCL( ScreenID.frame );
NSToLCLRect(ScreenID.frame, globalScreenHeight, lpmi^.rcMonitor); lpmi^.rcWork:= ScreenRectFromNSToLCL( ScreenID.visibleFrame );
NSToLCLRect(ScreenID.visibleFrame, globalScreenHeight, lpmi^.rcWork);
// according to the documentation the primary (0,0 coord screen) // according to the documentation the primary (0,0 coord screen)
// is always and index 0 // is always and index 0
if HMonitorToIndex(hMonitor) = 0 then if HMonitorToIndex(hMonitor) = 0 then
@ -1477,7 +1470,7 @@ begin
Exit; Exit;
p.x:=Point.X; p.x:=Point.X;
p.y:=NSGlobalScreenHeight-Point.Y; p.y:=NSGlobalScreenBottom-Point.Y;
window := GetCocoaWindowAtPos(p); window := GetCocoaWindowAtPos(p);
if Assigned(window) then if Assigned(window) then
Result:= HWND(window.contentView); Result:= HWND(window.contentView);
@ -1876,7 +1869,7 @@ var
i: Integer; i: Integer;
begin begin
Result:= 0; Result:= 0;
point:= LCLToNSPoint( ptScreenCoords, NSGlobalScreenHeight ); point:= ScreenPointFromLCLToNS( ptScreenCoords );
if point.y>=1 then // NSPointInRect is (upper,left) inside if point.y>=1 then // NSPointInRect is (upper,left) inside
point.y:= point.y-1; // (lower,right) outside point.y:= point.y-1; // (lower,right) outside

View File

@ -446,7 +446,7 @@ begin
if not isembedded then if not isembedded then
begin begin
//Window bounds should return "client rect" in screen coordinates //Window bounds should return "client rect" in screen coordinates
NSToLCLRect(window.frame, NSGlobalScreenHeight, wfrm); wfrm := ScreenRectFromNSToLCL(window.frame);
Types.OffsetRect(Result, -Result.Left+wfrm.Left, -Result.Top+wfrm.Top); Types.OffsetRect(Result, -Result.Left+wfrm.Left, -Result.Top+wfrm.Top);
end; end;
end; end;
@ -1250,7 +1250,7 @@ var
begin begin
f := frame; f := frame;
inc(X, Round(f.origin.x)); inc(X, Round(f.origin.x));
inc(Y, Round(NSGlobalScreenHeight - NSMaxY(f))); inc(Y, Round(NSGlobalScreenBottom - NSMaxY(f)));
end; end;
procedure LCLWindowExtension.lclScreenToLocal(var X, Y: Integer); procedure LCLWindowExtension.lclScreenToLocal(var X, Y: Integer);
@ -1259,15 +1259,15 @@ var
begin begin
f := frame; f := frame;
dec(X, Round(f.origin.x)); dec(X, Round(f.origin.x));
dec(Y, Round(NSGlobalScreenHeight - NSMaxY(f))); dec(Y, Round(NSGlobalScreenBottom - NSMaxY(f)));
end; end;
function LCLWindowExtension.lclFrame: TRect; function LCLWindowExtension.lclFrame: TRect;
begin begin
if Assigned(contentView) then if Assigned(contentView) then
Result:=contentView.lclFrame Result:= contentView.lclFrame
else else
NSToLCLRect(frame, NSGlobalScreenHeight, Result); Result:= ScreenRectFromNSToLCL( frame );
end; end;
function LCLWindowExtension.lclGetTopBarHeight:integer; function LCLWindowExtension.lclGetTopBarHeight:integer;
@ -1288,12 +1288,12 @@ var
ns : NSRect; ns : NSRect;
h : integer; h : integer;
begin begin
LCLToNSRect(r, NSGlobalScreenHeight, ns); ns:= ScreenRectFromLCLToNS( r );
// add topbar height // add topbar height
h:=lclGetTopBarHeight; h:= lclGetTopBarHeight;
ns.size.height:=ns.size.height+h; ns.size.height:= ns.size.height + h;
ns.origin.y:=ns.origin.y-h; ns.origin.y:= ns.origin.y - h;
{$ifdef BOOLFIX} {$ifdef BOOLFIX}
setFrame_display_(ns, Ord(isVisible)); setFrame_display_(ns, Ord(isVisible));
{$else} {$else}

View File

@ -536,8 +536,8 @@ begin
if lWindow <> nil then if lWindow <> nil then
begin begin
f := lWindow.frame; f := lWindow.frame;
Point.x := Point.x+f.origin.x; Point.x := Point.x + f.origin.x;
Point.y := lWindow.screen.frame.size.height- f.origin.y - Point.y; Point.y := NSGlobalScreenBottom - ( Point.y + f.origin.y );
end; end;
end; end;

View File

@ -963,7 +963,7 @@ begin
point:= TPoint.Create( x, y ); point:= TPoint.Create( x, y );
screen:= getScreenFromHMonitor( CocoaWidgetSet.MonitorFromPoint(point, MONITOR_DEFAULTTONULL) ); screen:= getScreenFromHMonitor( CocoaWidgetSet.MonitorFromPoint(point, MONITOR_DEFAULTTONULL) );
mouseY:= NSGlobalScreenHeight - y; mouseY:= NSGlobalScreenBottom - y;
if Assigned(screen) then begin if Assigned(screen) then begin
menuY:= screen.visibleFrame.origin.y + menu.size.height + 1; menuY:= screen.visibleFrame.origin.y + menu.size.height + 1;
menuY:= max( mouseY, MenuY ); menuY:= max( mouseY, MenuY );