예제 #1
0
        public static void ShowContextMenu(Gtk.Widget parent, int x, int y, NSMenu menu)
        {
            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);
                var titleBarHeight = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight();
                var pt             = new CoreGraphics.CGPoint(x, nswindow.Frame.Height - y - titleBarHeight - 12);

                var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown,
                                                   pt,
                                                   0, 0,
                                                   nswindow.WindowNumber,
                                                   null, 0, 0, 0);

                NSMenu.PopUpContextMenu(menu, tmp_event, nsview);
            });
        }
예제 #2
0
        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);
        }
예제 #3
0
        public static NSEvent TransformLocationOfEvent(NSView view, NSEvent nsEvent)
        {
            if (!IsMouseEvent(nsEvent.Type))
            {
                return(nsEvent);
            }

            var newLocation = view.ConvertPointFromView(nsEvent.LocationInWindow, null);

            if (IsMouseEnterExitEvent(nsEvent.Type))
            {
                return(CreateMouseEnterExitEvent(nsEvent, newLocation));
            }

            return(NSEvent.MouseEvent(
                       nsEvent.Type,
                       newLocation,
                       nsEvent.ModifierFlags,
                       nsEvent.Timestamp,
                       nsEvent.WindowNumber,
                       null,
                       nsEvent.EventNumber,
                       nsEvent.ClickCount,
                       nsEvent.Pressure));
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        private void PopUpContextMenu()
        {
            if (this.popUpContextMenu == null)
            {
                this.popUpContextMenu = new NSMenu();

                if (this.viewModel.TargetPlatform.SupportsCustomExpressions)
                {
                    var mi = new NSMenuItem(Properties.Resources.CustomExpressionEllipsis)
                    {
                        AttributedTitle = new Foundation.NSAttributedString(
                            Properties.Resources.CustomExpressionEllipsis,
                            new CoreText.CTStringAttributes {
                            Font = new CoreText.CTFont(PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1),
                        })
                    };

                    mi.Activated += OnCustomExpression;

                    this.popUpContextMenu.AddItem(mi);
                    this.popUpContextMenu.AddItem(NSMenuItem.SeparatorItem);
                }

                if (this.viewModel.SupportsResources)
                {
                    this.popUpContextMenu.AddItem(NSMenuItem.SeparatorItem);

                    var mi2 = new NSMenuItem(Properties.Resources.ResourceEllipsis)
                    {
                        AttributedTitle = new Foundation.NSAttributedString(
                            Properties.Resources.ResourceEllipsis,
                            new CoreText.CTStringAttributes {
                            Font = new CoreText.CTFont(PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1),
                        })
                    };

                    mi2.Activated += OnResourceRequested;
                    this.popUpContextMenu.AddItem(mi2);
                }

                this.popUpContextMenu.AddItem(NSMenuItem.SeparatorItem);

                // TODO If we add more menu items consider making the Label/Command a dictionary that we can iterate over to populate everything.
                this.popUpContextMenu.AddItem(new CommandMenuItem(Properties.Resources.Reset, viewModel.ClearValueCommand)
                {
                    AttributedTitle = new Foundation.NSAttributedString(
                        Properties.Resources.Reset,
                        new CoreText.CTStringAttributes {
                        Font = new CoreText.CTFont(PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1),
                    })
                });
            }

            var menuOrigin = this.Superview.ConvertPointToView(new CGPoint(Frame.Location.X - 1, Frame.Location.Y + Frame.Size.Height + 4), null);

            var popupMenuEvent = NSEvent.MouseEvent(NSEventType.LeftMouseDown, menuOrigin, (NSEventModifierMask)0x100, 0, this.Window.WindowNumber, this.Window.GraphicsContext, 0, 1, 1);

            NSMenu.PopUpContextMenu(popUpContextMenu, popupMenuEvent, this);
        }
예제 #6
0
        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);
                }
            });
        }
예제 #7
0
        public static NSEvent RetargetMouseEvent(this NSEvent e, NSView target, NSMouseFlags props)
        {
            var p          = target.Window.ConvertScreenToBase(e.Window.ConvertBaseToScreen(e.LocationInWindow));
            var clickCount = props.HasFlag(NSMouseFlags.ClickCount) ? e.ClickCount : 0;
            var pressure   = props.HasFlag(NSMouseFlags.Pressure) ? e.Pressure : 0;

            return(e.Type == NSEventType.ScrollWheel
                                ? e // Creating ScrollWheel fails, we need to use CGEvent() or derive custom event from NSEvent
                                : NSEvent.MouseEvent(e.Type, p, e.ModifierFlags, e.Timestamp, target.Window.WindowNumber, null, 0, clickCount, pressure));
        }
        public static void ShowContextMenu(Gtk.Widget parent, Gdk.EventButton evt, NSMenu menu)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }

            parent.GrabFocus();
            int x, y;

            if (evt != null)
            {
                x = (int)evt.X;
                y = (int)evt.Y;
            }
            else
            {
                Gdk.ModifierType mod;
                parent.GdkWindow.GetPointer(out x, out y, out mod);

                var titleBarHeight = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight();
                y -= titleBarHeight;
            }

            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 screenPoint = NSEvent.CurrentMouseLocation;
                var screenRect  = new CoreGraphics.CGRect(screenPoint.X, screenPoint.Y, 0, 0);
                var nswindow    = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow(toplevel);
                var rect        = nswindow.ConvertRectFromScreen(screenRect);
                var pt          = rect.Location;

                var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown,
                                                   pt,
                                                   0, 0,
                                                   nswindow.WindowNumber,
                                                   null, 0, 0, 0);

                NSMenu.PopUpContextMenu(menu, tmp_event, nsview);
            });
        }
예제 #9
0
        public static NSEvent RetargetMouseEvent(this NSEvent e, CGPoint locationOnScreen, NSMouseFlags props)
        {
            var wnum   = NSWindow.WindowNumberAtPoint(locationOnScreen, 0);
            var target = NSApplication.SharedApplication.WindowWithWindowNumber(wnum);

            if (target != null)
            {
                var location   = target.ConvertScreenToBase(locationOnScreen);
                var clickCount = props.HasFlag(NSMouseFlags.ClickCount) ? e.ClickCount : 0;
                var pressure   = props.HasFlag(NSMouseFlags.Pressure) ? e.Pressure : 0;
                return(e.Type == NSEventType.ScrollWheel
                                        ? e // Creating ScrollWheel fails, we need to use CGEvent() or derive custom event from NSEvent
                                        : NSEvent.MouseEvent(e.Type, location, e.ModifierFlags, e.Timestamp, target.WindowNumber, null, 0, clickCount, pressure));
            }
            return(e);
        }
예제 #10
0
        public void Show(Control relativeTo)
        {
            NSEvent nsevent = NSApplication.SharedApplication.CurrentEvent;

            if (nsevent == null)
            {
                var location = NSEvent.CurrentMouseLocation;
                location = NSApplication.SharedApplication.KeyWindow.ConvertScreenToBase(location);

                var time         = DateTime.Now.ToOADate();
                var windowNumber = NSApplication.SharedApplication.KeyWindow.WindowNumber;

                nsevent = NSEvent.MouseEvent(NSEventType.RightMouseDown, location, 0, time, windowNumber, null, 0, 0, 0.1f);
            }
            var view = relativeTo != null ? relativeTo.ControlObject as NSView : null;

            NSMenu.PopUpContextMenu(Control, nsevent, view);
        }
예제 #11
0
        public static void ShowContextMenu(Gtk.Widget parent, int x, int y, NSMenu menu)
        {
            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
                {
                    titleBarOffset = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight() + 12;
                }

                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);
            });
        }
예제 #12
0
        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);
            }
        }
예제 #13
0
        public void Show(Control relativeTo, PointF?location)
        {
            var view = relativeTo?.GetContainerView();

            if (location != null || view == null)
            {
                CGPoint cglocation;
                if (view != null && location != null)
                {
                    cglocation = location.Value.ToNS();
                    if (!view.IsFlipped)
                    {
                        cglocation.Y = view.Frame.Height - cglocation.Y;
                    }
                }
                else
                {
                    cglocation = (location ?? Mouse.Position).ToNS();
                    var origin = NSScreen.Screens[0].Frame.Bottom;
                    cglocation.Y = origin - cglocation.Y;
                }

                Control.PopUpMenu(null, cglocation, view);
            }
            else
            {
                NSEvent nsevent = NSApplication.SharedApplication.CurrentEvent;
                if (nsevent == null)
                {
                    var keyWindow     = NSApplication.SharedApplication.KeyWindow;
                    var mouseLocation = NSEvent.CurrentMouseLocation;
                    mouseLocation = keyWindow.ConvertScreenToBase(mouseLocation);

                    var time         = DateTime.Now.ToOADate();
                    var windowNumber = keyWindow.WindowNumber;

                    nsevent = NSEvent.MouseEvent(NSEventType.RightMouseDown, mouseLocation, 0, time, windowNumber, null, 0, 0, 0.1f);
                }

                NSMenu.PopUpContextMenu(Control, nsevent, view);
            }
        }
        public void Show(Control control, Point pos)
        {
            if (control == null)
            {
                throw new ArgumentException();
            }

            src_control = control;

            OnPopup(EventArgs.Empty);
            //m_view.RemoveAllItems();
            //m_view.InsertItem("beep",null,"",0);
            var point = control.m_view.ConvertPointToBase(pos);

            NSMenu.PopUpContextMenu(m_view, NSEvent.MouseEvent(NSEventType.LeftMouseUp, point, NSEventModifierMask.ShiftKeyMask, 0, NSApplication.SharedApplication.MainWindow.WindowNumber, new NSGraphicsContext(), 0, 1, 1f), control, NSFont.MenuBarFontOfSize(12));
            //m_view.PopUpMenu(new NSMenuItem("test",""),pos,control);


            OnCollapse(EventArgs.Empty);
        }
예제 #15
0
        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);
        }
예제 #16
0
        public async Task <DragDropEffects> DoDragDrop(IDataObject data, DragDropEffects allowedEffects)
        {
            // We need the TopLevelImpl + a mouse location so we just wait for the next event.
            var mouseEv = await _inputManager.PreProcess.OfType <RawMouseEventArgs>().FirstAsync();

            var view = ((mouseEv.Root as TopLevel)?.PlatformImpl as TopLevelImpl)?.View;

            if (view == null)
            {
                return(DragDropEffects.None);
            }

            // Prepare the source event:
            var pt = view.TranslateLocalPoint(mouseEv.Position).ToMonoMacPoint();
            var ev = NSEvent.MouseEvent(NSEventType.LeftMouseDown, pt, 0, 0, 0, null, 0, 0, 0);

            _allowedEffects = allowedEffects;
            var items = data.GetDataFormats().SelectMany(fmt => CreateDraggingItems(fmt, data.Get(fmt))).ToArray();

            view.BeginDraggingSession(items, ev, this);

            return(await _result);
        }
예제 #17
0
        public static NSEvent RetargetMouseEvent(this NSEvent e, NSView target)
        {
            var p = target.Window.ConvertScreenToBase(e.Window.ConvertBaseToScreen(e.LocationInWindow));

            return(NSEvent.MouseEvent(e.Type, p, e.ModifierFlags, e.Timestamp, target.Window.WindowNumber, null, 0, e.ClickCount, e.Pressure));
        }
        public void CustomMouseUp(string message)
        {
            //Console.WriteLine ("message:{0}", message);
            var domRange = ContentWebView.SelectedDomRange;

            if (domRange == null)
            {
                return;
            }

            string selectText = domRange.Text;

            if (selectText == null || selectText.Length <= 0)
            {
                return;
            }

            var    aobject = JsonConvert.DeserializeObject <Dictionary <string, object> > (message);
            var    values  = aobject.Values;
            nfloat x       = Int32.Parse(values.ElementAt(0).ToString());
            nfloat y       = View.Frame.Height + 50 - Int32.Parse(values.ElementAt(1).ToString());


            CGPoint location = new CGPoint(x, y);

            menuLocation = new CGPoint(x, y);

            location = View.ConvertPointToView(location, null);

            bool islegal = Utility.IsValidDictionary();

            //islegal = false;
            ContentMenu.ItemAt(2).Hidden = !islegal;

            bool isHighlight = false;

            ContentMenu.ItemAt(4).Hidden = isHighlight;
            ContentMenu.ItemAt(5).Hidden = !isHighlight;
            ContentMenu.ItemAt(6).Hidden = !isHighlight;

            bool isNote = false;

            ContentMenu.ItemAt(7).Hidden = isNote;
            ContentMenu.ItemAt(8).Hidden = !isNote;
            ContentMenu.ItemAt(9).Hidden = !isNote;

            NSWindow window = NSApplication.SharedApplication.KeyWindow;

            if (window == null)
            {
                window = NSApplication.SharedApplication.MainWindow;
            }
            nint windowNumber = 1;

            if (window != null)
            {
                windowNumber = window.WindowNumber;
            }
            else
            {
                return;
            }
            NSEvent fakeMouseEvent =
                NSEvent.MouseEvent(NSEventType.LeftMouseUp,
                                   location,
                                   (NSEventModifierMask)NSEventMask.LeftMouseUp,
                                   0,
                                   windowNumber,
                                   window.GraphicsContext, 0, 1, 1);

            NSMenu.PopUpContextMenu(ContentMenu, fakeMouseEvent, View);
        }
예제 #19
0
        private void PopupMenuAtLocation(NSObject sender)
        {
            var     button   = (NSButton)sender;
            CGPoint location = new CGPoint();

            location.X = button.Frame.GetMinX();
            location.Y = button.Frame.GetMidY();

            location = button.Superview.ConvertPointToView(location, null);

            NSWindow window       = Utility.GetMainWindowConroller().Window;
            nint     windowNumber = window.WindowNumber;

            if (TagMenu == null)
            {
                TagMenu = new NSMenu();
            }
            else
            {
                TagMenu.RemoveAllItems();
            }

            NSMenuItem menuItem = new NSMenuItem("All Tags");

            menuItem.Image  = Utility.ImageWithFilePath("/Images/Annotation/[email protected]");
            menuItem.Action = new ObjCRuntime.Selector("TagFilterMenuItemClick:");
            menuItem.Target = this;
            menuItem.Tag    = 0;
            TagMenu.InsertItem(menuItem, 0);

            menuItem        = new NSMenuItem("No Tag");
            menuItem.Image  = CreateImageWithColor(string.Empty);
            menuItem.Action = new ObjCRuntime.Selector("TagFilterMenuItemClick:");
            menuItem.Target = this;
            menuItem.Tag    = 1;
            TagMenu.InsertItem(menuItem, 1);

            TagMenu.AddItem(NSMenuItem.SeparatorItem);

            for (int i = 3; i < this.TagList.Count; i++)
            {
                menuItem        = new NSMenuItem(this.TagList[i].Title);
                menuItem.Image  = CreateImageWithColor(this.TagList[i].Color);
                menuItem.Action = new ObjCRuntime.Selector("TagFilterMenuItemClick:");
                menuItem.Target = this;
                menuItem.Tag    = i;
                menuItem.State  = NSCellStateValue.Off;
                TagMenu.InsertItem(menuItem, i);
            }

            var menuItems = TagMenu.ItemArray();

            for (int i = 0; i < this.TagList.Count; i++)
            {
                menuItems[i].State = this.TagList[i].CheckState;
            }

            NSEvent fakeMouseEvent =
                NSEvent.MouseEvent(NSEventType.LeftMouseUp,
                                   location,
                                   (NSEventModifierMask)NSEventMask.LeftMouseUp,
                                   0,
                                   windowNumber,
                                   window.GraphicsContext, 0, 1, 1);

            NSMenu.PopUpContextMenu(TagMenu, fakeMouseEvent, (NSView)sender);
        }