示例#1
0
        public static Gdk.Point ToWindowCoordinates(Gtk.Widget widget, Gdk.Window w, int x, int y)
        {
            int ox, oy;

            w.GetOrigin(out ox, out oy);
            ox += widget.Allocation.X;
            oy += widget.Allocation.Y;
            return(new Gdk.Point(x - ox, y - oy));
        }
示例#2
0
        public void GetPosition(out int x, out int y, Atk.CoordType coordType)
        {
            Gdk.Window window = null;

            if (!widget.IsDrawable)
            {
                x = y = int.MinValue;
                return;
            }

            if (widget.Parent != null)
            {
                x      = widget.Allocation.X;
                y      = widget.Allocation.Y;
                window = widget.ParentWindow;
            }
            else
            {
                x      = 0;
                y      = 0;
                window = widget.GdkWindow;
            }

            int x_window, y_window;

            window.GetOrigin(out x_window, out y_window);
            x += x_window;
            y += y_window;

            if (coordType == Atk.CoordType.Window)
            {
                window = widget.GdkWindow.Toplevel;
                int x_toplevel, y_toplevel;
                window.GetOrigin(out x_toplevel, out y_toplevel);

                x -= x_toplevel;
                y -= y_toplevel;
            }
        }
示例#3
0
        public static Gdk.Point ToScreenCoordinates(Gtk.Widget widget, Gdk.Window w, int x, int y)
        {
            int ox, oy;

            w.GetOrigin(out ox, out oy);
            //Bug 31032 - this is workaround bug in GTK on Windows OS which has widget.Allocation.X/Y
            //relative to widget.GdkWindow.Toplevel instead to widget.GdkWindow which is GdkWindow decicated
            //to TreeView so widget.Allocation.X/Y should always be 0,0(which is true on Mac)
            //hence skipping adding Allocation.X/Y since they should always be 0,0 anyway
            if (!(widget is TreeView))
            {
                ox += widget.Allocation.X;
                oy += widget.Allocation.Y;
            }
            return(new Gdk.Point(ox + x, oy + y));
        }
示例#4
0
        private void Move()
        {
            Gdk.Window treewindow = d_treeview.GdkWindow;

            Realize();

            int treeX;
            int treeY;
            int treeWidth;
            int treeHeight;

            treewindow.GetOrigin(out treeX, out treeY);
            treewindow.GetSize(out treeWidth, out treeHeight);

            int x = treeX + treeWidth - Allocation.Width - 6;
            int y = treeY + treeHeight - Allocation.Height - 6;

            Move(x, y);
        }
示例#5
0
        /// <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(Gtk.Menu menu, Gtk.Widget parent, Gdk.EventButton evt, Gdk.Rectangle caret)
        {
            Gtk.MenuPositionFunc posFunc = null;

            if (parent != null)
            {
                menu.AttachToWidget(parent, null);
                posFunc = delegate(Gtk.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;
                    }
                    Gtk.Requisition request  = m.SizeRequest();
                    var             screen   = parent.Screen;
                    Gdk.Rectangle   geometry = GetUsableMonitorGeometry(screen, 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.Right)
                    {
                        if (flip_left)
                        {
                            x -= request.Width;
                        }
                        else
                        {
                            x = geometry.Right - request.Width;
                        }

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

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

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

                    pushIn = false;
                };
            }

            uint time;
            uint button;

            if (evt == null)
            {
                time   = Gtk.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);
        }
示例#6
0
        /// <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(Gtk.Menu menu, Gtk.Widget parent, Gdk.EventButton evt, Gdk.Rectangle caret)
        {
            Gtk.MenuPositionFunc posFunc = null;

            // NOTE: we don't gtk_menu_attach_to_widget to the parent because it seems to cause issues.
            // The expanders in other treeviews in MD stop working when we detach it, and detaching is necessary
            // to prevent memory leaks.
            // Attaching means menu moves when parent is moved and is destroyed when parent is destroyed. Neither is
            // particularly important for us.
            // See https://bugzilla.xamarin.com/show_bug.cgi?id=4388
            if (parent != null)
            {
                posFunc = delegate(Gtk.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;
                    }
                    Gtk.Requisition request  = m.SizeRequest();
                    var             screen   = parent.Screen;
                    Gdk.Rectangle   geometry = GetUsableMonitorGeometry(screen, 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   = Gtk.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);
        }