Exemple #1
0
        bool ShowFixesMenu(Gtk.Widget parent, Gdk.Rectangle evt, FixMenuDescriptor entrySet)
        {
                        #if MAC
            parent.GrabFocus();
            int x, y;
            x = (int)evt.X;
            y = (int)evt.Y;

            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      = 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
            return(true);
        }
        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 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);
        }