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 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); }
public static void ShowContextMenu(Gtk.Widget parent, int x, int y, NSMenu menu, bool selectFirstItem = false) { if (parent == null) { throw new ArgumentNullException("parent"); } if (menu == null) { throw new ArgumentNullException("menu"); } parent.GrabFocus(); Gtk.Application.Invoke((o, args) => { // 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 nsview = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView(parent); var toplevel = parent.Toplevel as Gtk.Window; var nswindow = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow(toplevel); int titleBarOffset; if (toplevel.TypeHint == Gdk.WindowTypeHint.Toolbar && toplevel.Type == Gtk.WindowType.Toplevel && toplevel.Decorated == false) { // Undecorated toplevel toolbars are used for auto-hide pad windows. Don't add a titlebar offset for them. titleBarOffset = 0; } else if (MonoDevelop.Ide.DesktopService.GetIsFullscreen(toplevel)) { titleBarOffset = 0; } else { titleBarOffset = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight() + 12; } parent.TranslateCoordinates(parent.Toplevel, x, y, out x, out y); if (selectFirstItem) { var pt = new CoreGraphics.CGPoint(x, y); lastOpenPositon = pt; menu.PopUpMenu(menu.ItemAt(0), pt, nsview); } else { var pt = new CoreGraphics.CGPoint(x, nswindow.Frame.Height - y - titleBarOffset); lastOpenPositon = pt; var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown, pt, 0, 0, nswindow.WindowNumber, null, 0, 0, 0); NSMenu.PopUpContextMenu(menu, tmp_event, nsview); } }); }
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); }
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); }
/// <summary> /// Render a GTK widget to an AppKit NSImage /// </summary> public static NSImage RenderGtkWidget(Gtk.Widget widget) { var nativeView = GetNSView(widget); widget.TranslateCoordinates(widget.Toplevel, widget.Allocation.X, widget.Allocation.Y, out int transX, out int transY); var rect = new CoreGraphics.CGRect(transX, transY, widget.Allocation.Width, widget.Allocation.Height); var imageRep = nativeView.BitmapImageRepForCachingDisplayInRect(rect); nativeView.CacheDisplay(rect, imageRep); var image = new NSImage(rect.Size); image.AddRepresentation(imageRep); return(image); }
public override bool ShowContextMenu(CommandManager commandManager, Gtk.Widget widget, double x, double y, CommandEntrySet entrySet) { 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); }
protected void GetCoordsInWindow(Gtk.Widget widget, out int x, out int y) { widget.TranslateCoordinates(widget.Toplevel, 0, 0, out x, out y); }