public Gdk.Rectangle GetCoordinates(Gtk.Widget w) { int px, py; if (!w.TranslateCoordinates (this, 0, 0, out px, out py)) return new Gdk.Rectangle (0,0,0,0); Gdk.Rectangle rect = w.Allocation; rect.X = px - Allocation.X; rect.Y = py - Allocation.Y; return rect; }
void PlaceSelectionBoxInternal (Gtk.Widget widget) { int px, py; if (!widget.TranslateCoordinates (this, 0, 0, out px, out py)) return; Gdk.Rectangle rect = widget.Allocation; rect.X = px; rect.Y = py; selectionBox.Reposition (rect); }
public override bool ShowContextMenu (CommandManager commandManager, Gtk.Widget widget, double x, double y, CommandEntrySet entrySet, object initialCommandTarget = null) { Gtk.Application.Invoke (delegate { // Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime); var menu = new MDMenu (commandManager, entrySet, CommandSource.ContextMenu, initialCommandTarget); var nsview = MacInterop.GtkQuartz.GetView (widget); var toplevel = widget.Toplevel as Gtk.Window; int trans_x, trans_y; widget.TranslateCoordinates (toplevel, (int)x, (int)y, out trans_x, out trans_y); // Window coordinates in gtk are the same for cocoa, with the exception of the Y coordinate, that has to be flipped. var pt = new PointF ((float)trans_x, (float)trans_y); int w,h; toplevel.GetSize (out w, out h); pt.Y = h - pt.Y; var tmp_event = NSEvent.MouseEvent (NSEventType.LeftMouseDown, pt, 0, 0, MacInterop.GtkQuartz.GetWindow (toplevel).WindowNumber, null, 0, 0, 0); NSMenu.PopUpContextMenu (menu, tmp_event, nsview); }); return true; }
public void Show (Gtk.Widget parent, int x, int y, Action closeHandler, bool selectFirstItem = false) { #if MAC if (Platform.IsMac) { int tx, ty; // x, y are in gtk coordinates, so they need to be translated for Cocoa. parent.TranslateCoordinates (parent.Toplevel, x, y, out tx, out ty); ContextMenuExtensionsMac.ShowContextMenu (parent, tx, ty, this, closeHandler, selectFirstItem); return; } #endif ContextMenuExtensionsGtk.ShowContextMenu (parent, x, y, this, closeHandler, selectFirstItem); }
public static void ShowContextMenu (Gtk.Widget parent, Gdk.EventButton evt, NSMenu menu) { int x, y; parent.TranslateCoordinates (parent.Toplevel, (int)evt.X, (int)evt.Y, out x, out y); ShowContextMenu (parent, x, y, menu); }
bool ShowFixesMenu (Gtk.Widget parent, Gdk.Rectangle evt, FixMenuDescriptor entrySet) { if (parent == null || parent.GdkWindow == null) return true; try { #if MAC parent.GrabFocus (); int x, y; x = (int)evt.X; y = (int)evt.Y; // Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime); var menu = CreateNSMenu (entrySet); menu.Delegate = new ClosingMenuDelegate (document.Editor); var nsview = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView (parent); var toplevel = parent.Toplevel as Gtk.Window; int trans_x, trans_y; parent.TranslateCoordinates (toplevel, (int)x, (int)y, out trans_x, out trans_y); // Window coordinates in gtk are the same for cocoa, with the exception of the Y coordinate, that has to be flipped. var pt = new CoreGraphics.CGPoint ((float)trans_x, (float)trans_y); int w,h; toplevel.GetSize (out w, out h); pt.Y = h - pt.Y; var tmp_event = AppKit.NSEvent.MouseEvent (AppKit.NSEventType.LeftMouseDown, pt, 0, 0, MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow (toplevel).WindowNumber, null, 0, 0, 0); AppKit.NSMenu.PopUpContextMenu (menu, tmp_event, nsview); #else var menu = CreateGtkMenu (entrySet); menu.Events |= Gdk.EventMask.AllEventsMask; menu.SelectFirst (true); menu.Hidden += delegate { document.Editor.SuppressTooltips = false; }; menu.ShowAll (); menu.SelectFirst (true); menu.MotionNotifyEvent += (o, args) => { if (args.Event.Window == Editor.Parent.TextArea.GdkWindow) { StartMenuCloseTimer (); } else { CancelMenuCloseTimer (); } }; GtkWorkarounds.ShowContextMenu (menu, parent, null, evt); #endif } catch (Exception ex) { LoggingService.LogError ("Error while context menu popup.", ex); } return true; }
public override bool ShowContextMenu (CommandManager commandManager, Gtk.Widget widget, double x, double y, CommandEntrySet entrySet) { Gtk.Application.Invoke (delegate { var menu = new MDMenu (commandManager, entrySet); var nsview = MacInterop.GtkQuartz.GetView (widget); var toplevel = widget.Toplevel as Gtk.Window; int trans_x, trans_y; widget.TranslateCoordinates (toplevel, (int)x, (int)y, out trans_x, out trans_y); var pt = nsview.ConvertPointFromBase (new PointF ((float)trans_x, (float)trans_y)); var tmp_event = NSEvent.MouseEvent (NSEventType.LeftMouseDown, pt, 0, 0, MacInterop.GtkQuartz.GetWindow (toplevel).WindowNumber, null, 0, 0, 0); NSMenu.PopUpContextMenu (menu, tmp_event, nsview); }); return true; }