當前位置: 首頁>>代碼示例>>C#>>正文


C# Menu.Detach方法代碼示例

本文整理匯總了C#中Gtk.Menu.Detach方法的典型用法代碼示例。如果您正苦於以下問題:C# Menu.Detach方法的具體用法?C# Menu.Detach怎麽用?C# Menu.Detach使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Gtk.Menu的用法示例。


在下文中一共展示了Menu.Detach方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ShowContextMenu

        /// <summary>Shows a context menu.</summary>
        /// <param name='menu'>The menu.</param>
        /// <param name='parent'>The parent widget.</param>
        /// <param name='evt'>The mouse event. May be null if triggered by keyboard.</param>
        /// <param name='caret'>The caret/selection position within the parent, if the EventButton is null.</param>
        public static void ShowContextMenu(Menu menu, Widget parent, Gdk.EventButton evt, Gdk.Rectangle caret)
        {
            MenuPositionFunc posFunc = null;

            if (parent != null) {
                menu.AttachToWidget (parent, null);
                menu.Hidden += (sender, e) => {
                    if (menu.AttachWidget != null)
                        menu.Detach ();
                };
                posFunc = delegate (Menu m, out int x, out int y, out bool pushIn) {
                    Gdk.Window window = evt != null? evt.Window : parent.GdkWindow;
                    window.GetOrigin (out x, out y);
                    var alloc = parent.Allocation;
                    if (evt != null) {
                        x += (int) evt.X;
                        y += (int) evt.Y;
                    } else if (caret.X >= alloc.X && caret.Y >= alloc.Y) {
                        x += caret.X;
                        y += caret.Y + caret.Height;
                    } else {
                        x += alloc.X;
                        y += alloc.Y;
                    }
                    Requisition request = m.SizeRequest ();
                    var screen = parent.Screen;
                    Gdk.Rectangle geometry = screen.GetMonitorGeometry(screen.GetMonitorAtPoint (x, y));

                    //whether to push or flip menus that would extend offscreen
                    //FIXME: this is the correct behaviour for mac, check other platforms
                    bool flip_left = true;
                    bool flip_up   = false;

                    if (x + request.Width > geometry.X + geometry.Width) {
                        if (flip_left) {
                            x -= request.Width;
                        } else {
                            x = geometry.X + geometry.Width - request.Width;
                        }

                        if (x < geometry.Left)
                            x = geometry.Left;
                    }

                    if (y + request.Height > geometry.Y + geometry.Height) {
                        if (flip_up) {
                            y -= request.Height;
                        } else {
                            y = geometry.Y + geometry.Height - request.Height;
                        }

                        if (y < geometry.Top)
                            y = geometry.Top;
                    }

                    pushIn = false;
                };
            }

            uint time;
            uint button;

            if (evt == null) {
                time = Global.CurrentEventTime;
                button = 0;
            } else {
                time = evt.Time;
                button = evt.Button;
            }

            //HACK: work around GTK menu issues on mac when passing button to menu.Popup
            //some menus appear and immediately hide, and submenus don't activate
            //            if (Platform.IsMac) {
            //                button = 0;
            //            }

            menu.Popup (null, null, posFunc, button, time);
        }
開發者ID:28427328,項目名稱:SQCharts,代碼行數:83,代碼來源:GtkWorkarounds.cs


注:本文中的Gtk.Menu.Detach方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。