public static void ShowContextMenu(NSView parent, int x, int y, NSMenu menu, bool selectFirstItem = false) { if (parent == null) { throw new ArgumentNullException("parent"); } if (menu == null) { throw new ArgumentNullException("menu"); } var pt = parent.ConvertPointToView(new CoreGraphics.CGPoint(x, y), null); if (selectFirstItem) { menu.PopUpMenu(menu.ItemAt(0), pt, parent); } else { var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown, pt, 0, 0, parent.Window.WindowNumber, null, 0, 0, 0); NSMenu.PopUpContextMenu(menu, tmp_event, parent); } }
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); } }); }
partial void ShowLicenses(NSObject sender) { var button = (NSButton)sender; licensesMenu.PopUpMenu( null, new CoreGraphics.CGPoint(0, button.Frame.Height), button); }
public override NSMenu MenuForEvent(NSEvent theEvent) { if (Identifier == "Individuals") { return(base.MenuForEvent(theEvent)); } var emptyMenu = new NSMenu(); emptyMenu.PopUpMenu(null, new CGPoint(0, 0), this); return(emptyMenu); }
public static void ShowContextMenu(NSView parent, int x, int y, NSMenu menu, bool selectFirstItem = false) { if (parent == null) { throw new ArgumentNullException("parent"); } if (menu == null) { throw new ArgumentNullException("menu"); } var pt = parent.ConvertPointToView(new CoreGraphics.CGPoint(x, y), null); if (selectFirstItem) { menu.PopUpMenu(menu.ItemAt(0), pt, parent); } else { var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown, pt, 0, 0, parent.Window.WindowNumber, null, 0, 0, 0); // the following lines are here to dianose & fix VSTS 1026106 - we were getting // a SigSegv from here and it is likely caused by NSEvent being null, however // it's worth leaving Debug checks in just to be on the safe side if (tmp_event == null) { // since this is often called outside of a try/catch loop, we'll just // log an error and not throw the exception LoggingService.LogInternalError(new ArgumentNullException(nameof(tmp_event))); return; } System.Diagnostics.Debug.Assert(parent != null, "Parent was modified (set to null) during execution."); System.Diagnostics.Debug.Assert(menu != null, "Menu was modified (set to null) during execution."); NSMenu.PopUpContextMenu(menu, tmp_event, parent); } }
public override void RightMouseDown(NSEvent theEvent) { base.RightMouseDown(theEvent); var row = GetRowByMouseEventArgs(theEvent); if (row > -1) { var selectedRowIndexes = SelectedRows.AsEnumerable().ToList(); if (!selectedRowIndexes.Contains((nuint)row)) { var extendSelection = UiStateHelper.CommandKeyDown; SelectRow(row, extendSelection); selectedRowIndexes = SelectedRows.AsEnumerable().ToList(); } var menuItems = new List <NSMenuItem>(); var arguments = new ContextMenuArguments(menuItems, selectedRowIndexes); PrepareContextMenu?.Invoke(this, arguments); if (menuItems.Any()) { var menu = new NSMenu { AutoEnablesItems = false }; menu.Delegate = new DeferredInitializerDelegate(arguments.Initializers); foreach (var item in menuItems) { menu.AddItem(item); } var locationInView = this.ConvertPointToView(theEvent.LocationInWindow, null); locationInView.X -= 26; menu.PopUpMenu(null, locationInView, this); } } }
public PathSelectorView (CGRect frameRect) : base (frameRect) { PathComponentCells = new [] { new NSPathComponentCell { Image = ImageService.GetIcon ("project").ToNSImage (), Title = ConfigurationPlaceholder, Enabled = false, TextColor = NSColor.FromRgba (0.34f, 0.34f, 0.34f, 1), }, new NSPathComponentCell { Image = ImageService.GetIcon ("device").ToNSImage (), Title = RuntimePlaceholder, Enabled = false, TextColor = NSColor.FromRgba (0.34f, 0.34f, 0.34f, 1), } }; BackgroundColor = NSColor.Clear; FocusRingType = NSFocusRingType.None; Activated += (sender, e) => { var item = ClickedPathComponentCell; if (item == null) return; var componentRect = ((NSPathCell)Cell).GetRect (item, Frame, this); int idx = -1; int i = 0; var menu = new NSMenu { AutoEnablesItems = false, ShowsStateColumn = false, Font = NSFont.MenuFontOfSize (12), }; if (object.ReferenceEquals (ClickedPathComponentCell, PathComponentCells [ConfigurationIdx])) { foreach (var configuration in ConfigurationModel) { if (idx == -1 && configuration.OriginalId == ActiveConfiguration.OriginalId) idx = i; var _configuration = configuration; menu.AddItem (new NSMenuItem (configuration.DisplayString, (o2, e2) => { ActiveConfiguration = configurationModel.First (c => c.OriginalId == _configuration.OriginalId); if (ConfigurationChanged != null) ConfigurationChanged (o2, e2); UpdatePathText (ConfigurationIdx, _configuration.DisplayString); }) { Enabled = true, IndentationLevel = 1, }); ++i; } } else if (object.ReferenceEquals (ClickedPathComponentCell, PathComponentCells [RuntimeIdx])) { foreach (var runtime in RuntimeModel) { if (idx == -1 && runtime.DisplayString == ActiveRuntime.DisplayString) idx = i; if (runtime.HasParent) continue; if (runtime.IsSeparator) menu.AddItem (NSMenuItem.SeparatorItem); else CreateMenuItem (menu, runtime); ++i; } } else throw new NotSupportedException (); if (menu.Count > 1) { var offs = new CGPoint (componentRect.Left + 3, componentRect.Top + 3); if (Window.Screen.BackingScaleFactor == 2) offs.Y += 0.5f; // fine tune menu position on retinas menu.PopUpMenu (null, offs, this); } }; }
public PathSelectorView(CGRect frameRect) : base(frameRect) { PathComponentCells = new [] { new NSPathComponentCell { Image = ImageService.GetIcon("project").ToNSImage(), Title = ConfigurationPlaceholder, Enabled = false, TextColor = NSColor.FromRgba(0.34f, 0.34f, 0.34f, 1), }, new NSPathComponentCell { Image = ImageService.GetIcon("device").ToNSImage(), Title = RuntimePlaceholder, Enabled = false, TextColor = NSColor.FromRgba(0.34f, 0.34f, 0.34f, 1), } }; BackgroundColor = NSColor.Clear; FocusRingType = NSFocusRingType.None; Activated += (sender, e) => { var item = ClickedPathComponentCell; if (item == null) { return; } var componentRect = ((NSPathCell)Cell).GetRect(item, Frame, this); int idx = -1; int i = 0; var menu = new NSMenu { AutoEnablesItems = false, ShowsStateColumn = false, Font = NSFont.MenuFontOfSize(12), }; if (object.ReferenceEquals(ClickedPathComponentCell, PathComponentCells [ConfigurationIdx])) { foreach (var configuration in ConfigurationModel) { if (idx == -1 && configuration.OriginalId == ActiveConfiguration.OriginalId) { idx = i; } var _configuration = configuration; menu.AddItem(new NSMenuItem(configuration.DisplayString, (o2, e2) => { ActiveConfiguration = configurationModel.First(c => c.OriginalId == _configuration.OriginalId); if (ConfigurationChanged != null) { ConfigurationChanged(o2, e2); } UpdatePathText(ConfigurationIdx, _configuration.DisplayString); }) { Enabled = true, IndentationLevel = 1, }); ++i; } } else if (object.ReferenceEquals(ClickedPathComponentCell, PathComponentCells [RuntimeIdx])) { foreach (var runtime in RuntimeModel) { if (idx == -1 && runtime.DisplayString == ActiveRuntime.DisplayString) { idx = i; } if (runtime.HasParent) { continue; } if (runtime.IsSeparator) { menu.AddItem(NSMenuItem.SeparatorItem); } else { CreateMenuItem(menu, runtime); } ++i; } } else { throw new NotSupportedException(); } if (menu.Count > 1) { var offs = new CGPoint(componentRect.Left + 3, componentRect.Top + 3); if (Window.Screen.BackingScaleFactor == 2) { offs.Y += 0.5f; // fine tune menu position on retinas } menu.PopUpMenu(null, offs, this); } }; }
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 (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 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; } if (selectFirstItem) { var pt = new CoreGraphics.CGPoint (x, y); menu.PopUpMenu (menu.ItemAt (0), pt, nsview); } else { var pt = new CoreGraphics.CGPoint (x, nswindow.Frame.Height - y - titleBarOffset); var tmp_event = NSEvent.MouseEvent (NSEventType.LeftMouseDown, pt, 0, 0, nswindow.WindowNumber, null, 0, 0, 0); NSMenu.PopUpContextMenu (menu, tmp_event, nsview); } }); }
public override void MouseDown(NSEvent theEvent) { if (!Enabled) { return; } var locationInView = ConvertPointFromView(theEvent.LocationInWindow, null); var cellIdx = IndexOfCellAtX(locationInView.X); if (cellIdx == -1) { return; } var item = PathComponentCells [cellIdx]; if (item == null || !item.Enabled) { return; } var componentRect = ((NSPathCell)Cell).GetRect(item, Frame, this); int i = 0; NSMenuItem selectedItem = null; var menu = new NSMenu { AutoEnablesItems = false, ShowsStateColumn = false, Font = NSFont.MenuFontOfSize(12), }; if (cellIdx == ConfigurationIdx) { if (ActiveConfiguration == null) { return; } foreach (var configuration in ConfigurationModel) { var _configuration = configuration; var menuitem = new NSMenuItem(configuration.DisplayString, (o2, e2) => { ActiveConfiguration = configurationModel.First(c => c.OriginalId == _configuration.OriginalId); }) { Enabled = true, IndentationLevel = 1, }; menu.AddItem(menuitem); if (selectedItem == null && configuration.OriginalId == ActiveConfiguration.OriginalId) { selectedItem = menuitem; } } } else if (cellIdx == RuntimeIdx) { if (ActiveRuntime == null) { return; } using (var activeMutableModel = ActiveRuntime.GetMutableModel()) { foreach (var runtime in RuntimeModel) { if (runtime.HasParent) { continue; } NSMenuItem menuitem = null; if (runtime.IsSeparator) { menu.AddItem(NSMenuItem.SeparatorItem); } else { menuitem = CreateMenuItem(menu, runtime); } using (var mutableModel = runtime.GetMutableModel()) { if (selectedItem == null && menuitem != null && mutableModel.DisplayString == activeMutableModel.DisplayString) { selectedItem = menuitem; } } ++i; } } } else { throw new NotSupportedException(); } if (menu.Count > 1) { var offs = new CGPoint(componentRect.Left + 3, componentRect.Top + 3); if (Window?.Screen?.BackingScaleFactor == 2) { offs.Y += 0.5f; // fine tune menu position on retinas } menu.PopUpMenu(selectedItem, offs, this); } }
void PopupMenuForCell(NSPathComponentCell item) { var componentRect = ((NSPathCell)Cell).GetRect(item, Frame, this); int i = 0; NSMenuItem selectedItem = null; var menu = new NSMenu { AutoEnablesItems = false, ShowsStateColumn = true, Font = NSFont.MenuFontOfSize(12), }; if (item.Identifier == RunConfigurationIdentifier) { if (ActiveRunConfiguration == null) { return; } foreach (var configuration in RunConfigurationModel) { var _configuration = configuration; var menuitem = new NSMenuItem(configuration.DisplayString, (o2, e2) => { ActiveRunConfiguration = runConfigurationModel.First(c => c.OriginalId == _configuration.OriginalId); }) { Enabled = true, IndentationLevel = 1, }; menu.AddItem(menuitem); if (selectedItem == null && configuration.OriginalId == ActiveRunConfiguration.OriginalId) { selectedItem = menuitem; } } } else if (item.Identifier == ConfigurationIdentifier) { if (ActiveConfiguration == null) { return; } foreach (var configuration in ConfigurationModel) { var _configuration = configuration; var menuitem = new NSMenuItem(configuration.DisplayString, (o2, e2) => { ActiveConfiguration = configurationModel.First(c => c.OriginalId == _configuration.OriginalId); }) { Enabled = true, IndentationLevel = 1, }; menu.AddItem(menuitem); if (selectedItem == null && configuration.OriginalId == ActiveConfiguration.OriginalId) { selectedItem = menuitem; } } } else if (item.Identifier == RuntimeIdentifier) { if (ActiveRuntime == null) { return; } using (var activeMutableModel = ActiveRuntime.GetMutableModel()) { foreach (var runtime in RuntimeModel) { NSMenuItem menuitem = null; if (runtime.IsSeparator) { menu.AddItem(NSMenuItem.SeparatorItem); } else { menuitem = CreateMenuItem(menu, runtime); } using (var mutableModel = runtime.GetMutableModel()) { if (selectedItem == null && menuitem != null && mutableModel.DisplayString == activeMutableModel.DisplayString) { selectedItem = menuitem; } } ++i; } } } else { throw new NotSupportedException(); } LastSelectedCell = IndexFromIdentifier(item.Identifier); if (menu.Count > 1) { var offs = new CGPoint(componentRect.Left + 3, componentRect.Top + 3); if (Window?.Screen?.BackingScaleFactor == 2) { offs.Y += 0.5f; // fine tune menu position on retinas } menu.PopUpMenu(selectedItem, offs, this); } }
public override void MouseDown (NSEvent theEvent) { if (!Enabled) return; var locationInView = ConvertPointFromView (theEvent.LocationInWindow, null); var cellIdx = IndexOfCellAtX (locationInView.X); if (cellIdx == -1) { return; } var item = Cells [cellIdx]; if (item == null || !item.Enabled) return; var componentRect = ((NSPathCell)Cell).GetRect (item, Frame, this); int i = 0; NSMenuItem selectedItem = null; var menu = new NSMenu { AutoEnablesItems = false, ShowsStateColumn = false, Font = NSFont.MenuFontOfSize (12), }; if (cellIdx == RunConfigurationIdx) { if (ActiveRunConfiguration == null) return; foreach (var configuration in RunConfigurationModel) { var _configuration = configuration; var menuitem = new NSMenuItem (configuration.DisplayString, (o2, e2) => { ActiveRunConfiguration = runConfigurationModel.First (c => c.OriginalId == _configuration.OriginalId); }) { Enabled = true, IndentationLevel = 1, }; menu.AddItem (menuitem); if (selectedItem == null && configuration.OriginalId == ActiveRunConfiguration.OriginalId) selectedItem = menuitem; } } else if (cellIdx == ConfigurationIdx) { if (ActiveConfiguration == null) return; foreach (var configuration in ConfigurationModel) { var _configuration = configuration; var menuitem = new NSMenuItem (configuration.DisplayString, (o2, e2) => { ActiveConfiguration = configurationModel.First (c => c.OriginalId == _configuration.OriginalId); }) { Enabled = true, IndentationLevel = 1, }; menu.AddItem (menuitem); if (selectedItem == null && configuration.OriginalId == ActiveConfiguration.OriginalId) selectedItem = menuitem; } } else if (cellIdx == RuntimeIdx) { if (ActiveRuntime == null) return; using (var activeMutableModel = ActiveRuntime.GetMutableModel ()) { foreach (var runtime in RuntimeModel) { if (runtime.HasParent) continue; NSMenuItem menuitem = null; if (runtime.IsSeparator) menu.AddItem (NSMenuItem.SeparatorItem); else menuitem = CreateMenuItem (menu, runtime); using (var mutableModel = runtime.GetMutableModel ()) { if (selectedItem == null && menuitem != null && mutableModel.DisplayString == activeMutableModel.DisplayString) selectedItem = menuitem; } ++i; } } } else throw new NotSupportedException (); if (menu.Count > 1) { var offs = new CGPoint (componentRect.Left + 3, componentRect.Top + 3); if (Window?.Screen?.BackingScaleFactor == 2) offs.Y += 0.5f; // fine tune menu position on retinas menu.PopUpMenu (selectedItem, offs, this); } }