コード例 #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
        bool FocusWidget(Gtk.Widget widget)
        {
            if (widget.HasFocus)
            {
                return(true);
            }
            if (widget.CanFocus)
            {
                widget.GrabFocus();
                return(true);
            }
            var container = widget as Gtk.Container;

            if (container != null)
            {
                var chain = container.FocusChain;
                System.Collections.IEnumerable children = chain.Length > 0 ? chain : container.AllChildren;
                foreach (Gtk.Widget child in children)
                {
                    if (FocusWidget(child))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #3
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);
                }
            });
        }
コード例 #4
0
 void SetFocus(Gtk.Widget w)
 {
     if (w.Parent != null)
     {
         SetFocus(w.Parent);
     }
     w.GrabFocus();
     w.IsFocus  = true;
     w.HasFocus = true;
 }
コード例 #5
0
ファイル: ActionMenuItem.cs プロジェクト: orf53975/stetic
        void AttachChildren(Gtk.Table table, uint row, uint col)
        {
            if (icon != null)
            {
                table.Attach(icon, col, col + 1, row, row + 1);
                Gtk.Table.TableChild tc = (Gtk.Table.TableChild)table [icon];
                if (!editing)
                {
                    tc.YPadding = itemSpacing;
                }
            }
            if (label != null)
            {
                table.Attach(label, col + 1, col + 2, row, row + 1);
                Gtk.Table.TableChild tc = (Gtk.Table.TableChild)table [label];
                if (!editing)
                {
                    tc.YPadding = itemSpacing;
                }
                label.GrabFocus();
            }
            if (accel != null)
            {
                table.Attach(accel, col + 2, col + 3, row, row + 1);
            }

            if (minWidth > 0 && label != null)
            {
                if (label.SizeRequest().Width < minWidth)
                {
                    label.WidthRequest = minWidth;
                }
            }

            bool sens = editing || node.Action == null || node.Action.GtkAction.Sensitive;

            if (icon != null)
            {
                icon.Sensitive = sens;
            }
            if (label != null)
            {
                label.Sensitive = sens;
            }
            if (accel != null)
            {
                accel.Sensitive = sens;
            }
        }
コード例 #6
0
        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);
            });
        }
コード例 #7
0
        public bool GrabFocus()
        {
            if (!widget.CanFocus)
            {
                return(false);
            }

            widget.GrabFocus();

            var toplevel_window = widget.Toplevel as Gtk.Window;

            if (toplevel_window != null)
            {
                toplevel_window.Present();
            }

            return(true);
        }
コード例 #8
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);
            });
        }