示例#1
0
        public void TestResultsWindowIsBelowMainWindow()
        {
            Gtk.Window main    = new Gtk.Window("Test Main Window");
            Gtk.Window results = new Gtk.Window("Test Results Window");

            main.Resize(200, 100);
            results.Resize(200, 100);

            Gdk.Rectangle resultsOffset = new Gdk.Rectangle(0, 10, 0, 0);

            var positioner = new PositionWindow(main, results);

            positioner.UpdatePosition(10, Pane.First, resultsOffset);

            // Drain the event loop
            while (Gtk.Global.EventsPending)
            {
                Gtk.Main.Iteration();
            }

            int main_x, main_y;
            int results_x, results_y;

            main.GetPosition(out main_x, out main_y);
            results.GetPosition(out results_x, out results_y);
            Assert.Greater(results_y, main_y + 100);
        }
示例#2
0
        private void SolveWindowPosition(Gtk.Window parent)
        {
            int          x, y, cw, ch, pw, ph, px, py;
            PositionMode wp = (ShellObject as Window).PositionMode;

            //if center parent and parent is null, center screen instead
            if (parent == null && wp == PositionMode.CenterParent)
            {
                wp = PositionMode.CenterScreen;
            }


            switch (wp)
            {
            case PositionMode.Manual:
                //HACK: we have to move the window to the position it already is for some stupid gtk-reason
                //an GetPosition doesnt work (in windows at least)
                int wx, wy, w, h, d;
                window.GdkWindow.GetGeometry(out wx, out wy, out w, out h, out d);
                Margin m = GetDecorationSize();
                window.Move(wx - m.Left, wy - m.Top);
                return;     //done already

            case PositionMode.CenterParent:
                parent.GetSize(out pw, out ph);
                parent.GetPosition(out px, out py);
                window.GetSize(out cw, out ch);
                var c = window.WindowPosition;
                x = px + pw / 2 - cw / 2;
                y = py + ph / 2 - ch / 2;
                window.Move(x, y);
                break;

            case PositionMode.CenterScreen:
                Gdk.Screen scr = window.Screen;     // ?? Gdk.Screen.Default
                window.GetSize(out cw, out ch);
                x = scr.Width / 2 - cw / 2;
                y = scr.Height / 2 - ch / 2;
                window.Move(x, y);
                break;

            case PositionMode.MouseCursor:
                Gdk.Screen scr2 = window.Screen;
                scr2.Display.GetPointer(out x, out y);
                window.Move(x, y);
                break;

            default:
                throw new Exception("GtkSharp driver does not know how to position screen at " + wp.ToString());
            }
        }
示例#3
0
        /// <summary>Centers a window relative to its parent.</summary>
        static void CenterWindow(Window childControl, Window parentControl)
        {
            Gtk.Window child  = childControl;
            Gtk.Window parent = parentControl;
            child.Child.Show();
            int w, h, winw, winh, x, y, winx, winy;

            child.GetSize(out w, out h);
            parent.GetSize(out winw, out winh);
            parent.GetPosition(out winx, out winy);
            x = Math.Max(0, (winw - w) / 2) + winx;
            y = Math.Max(0, (winh - h) / 2) + winy;
            child.Move(x, y);
        }
示例#4
0
        public void Save()
        {
            if (window == null || !window.Visible || !window.IsMapped || window.GdkWindow == null)
            {
                return;
            }

            maximized = (window.GdkWindow.State & Gdk.WindowState.Maximized) != 0;
            window.GetPosition(out x, out y);
            window.GetSize(out width, out height);

            if (timer_id == 0)
            {
                timer_id = GLib.Timeout.Add(250, OnTimeout);
            }
            else
            {
                pending_changes = true;
            }
        }
示例#5
0
        /// <summary>Centers a window relative to its parent.</summary>
        static void CenterWindow(Window childControl, Window parentControl)
        {
            // TODO: support cross-toolkit centering
            if (!(parentControl.nativeWidget is Gtk.Window))
            {
                // FIXME: center on screen if no Gtk parent given for a Gtk dialog
                if (childControl.nativeWidget is Gtk.Window gtkChild)
                {
                    gtkChild.WindowPosition = Gtk.WindowPosition.Center;
                }
                return;
            }
            Gtk.Window child  = childControl;
            Gtk.Window parent = parentControl;
            child.Child.Show();
            int w, h, winw, winh, x, y, winx, winy;

            child.GetSize(out w, out h);
            parent.GetSize(out winw, out winh);
            parent.GetPosition(out winx, out winy);
            x = Math.Max(0, (winw - w) / 2) + winx;
            y = Math.Max(0, (winh - h) / 2) + winy;
            child.Move(x, y);
        }