mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 20:09:10 +02:00
Cocoa: TCocoaWSPopupMenu.Popup() refactored
This commit is contained in:
parent
275776771b
commit
7f7a01a35b
@ -950,44 +950,28 @@ end;
|
|||||||
class procedure TCocoaWSPopupMenu.Popup(const APopupMenu: TPopupMenu; const X,
|
class procedure TCocoaWSPopupMenu.Popup(const APopupMenu: TPopupMenu; const X,
|
||||||
Y: Integer);
|
Y: Integer);
|
||||||
var
|
var
|
||||||
menu : TCocoaMenu;
|
menu: TCocoaMenu;
|
||||||
view : NSView;
|
point: TPoint;
|
||||||
w : NSWindow;
|
screen: NSScreen;
|
||||||
px, py: Integer;
|
mouseY: CGFloat;
|
||||||
menuY: Integer;
|
menuY: CGFloat;
|
||||||
begin
|
begin
|
||||||
if (not Assigned(APopupMenu)) or (APopupMenu.Handle=0) then
|
if (not Assigned(APopupMenu)) or (APopupMenu.Handle=0) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
px := x;
|
|
||||||
py := y;
|
|
||||||
menu := TCocoaMenu(APopupMenu.Handle);
|
menu := TCocoaMenu(APopupMenu.Handle);
|
||||||
view := nil;
|
point:= TPoint.Create( x, y );
|
||||||
w :=NSApp.keyWindow;
|
screen:= getScreenFromHMonitor( CocoaWidgetSet.MonitorFromPoint(point, MONITOR_DEFAULTTONULL) );
|
||||||
// in macOS it's possible to "rightclick" without focusing a window
|
|
||||||
// so let's try to find the window
|
|
||||||
if not Assigned(w) then
|
|
||||||
w := GetCocoaWindowAtPos( NSMakePoint(px, Round(NSGlobalScreenHeight) - py) );
|
|
||||||
|
|
||||||
if Assigned(w) then
|
mouseY:= NSGlobalScreenHeight - y;
|
||||||
begin
|
if Assigned(screen) then begin
|
||||||
view := w.contentView;
|
menuY:= screen.visibleFrame.origin.y + menu.size.height + 1;
|
||||||
if Assigned(view) then
|
menuY:= max( mouseY, MenuY );
|
||||||
begin
|
end else begin
|
||||||
// LCL Screen coordinate
|
menuY:= mouseY;
|
||||||
menuY := Round(NSGlobalScreenHeight - w.screen.visibleFrame.origin.y - menu.size.height) - 1;
|
|
||||||
py := min(py, menuY);
|
|
||||||
view.lclScreenToLocal(px, py);
|
|
||||||
// have to flip again, because popUpMenuPositioningItem expects point
|
|
||||||
// to be in View coordinates and it does respect Flipped flag
|
|
||||||
if not view.isFlipped then
|
|
||||||
py := Round(view.frame.size.height) - py;
|
|
||||||
end;
|
end;
|
||||||
end
|
|
||||||
else
|
|
||||||
py := Round(NSGlobalScreenHeight) - py;
|
|
||||||
|
|
||||||
menu.popUpMenuPositioningItem_atLocation_inView(nil, NSMakePoint(px, py), view);
|
menu.popUpMenuPositioningItem_atLocation_inView(nil, NSMakePoint(x,menuY), nil);
|
||||||
APopupMenu.Close; // notify LCL popup menu
|
APopupMenu.Close; // notify LCL popup menu
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user