public void NativeWindowFrameHasCorrectScreenBounds()
        {
            var nativeWindow = new Gtk.Window("Foo");

            nativeWindow.Resize(450, 320);
            nativeWindow.Move(13, 50);
            nativeWindow.ShowAll();

            WaitForEvents();

            var window = Toolkit.CurrentEngine.WrapWindow(nativeWindow);
            var bounds = window.ScreenBounds;

            Assert.AreEqual(450, bounds.Width);
            Assert.AreEqual(320, bounds.Height);
            Assert.AreEqual(13, bounds.X);
            Assert.AreEqual(50, bounds.Y);

            nativeWindow.Move(30, 100);
            WaitForEvents();
            bounds = window.ScreenBounds;
            Assert.AreEqual(30, bounds.X);
            Assert.AreEqual(100, bounds.Y);
            Assert.AreEqual(450, bounds.Width);
            Assert.AreEqual(320, bounds.Height);

            nativeWindow.Resize(100, 100);
            WaitForEvents();
            bounds = window.ScreenBounds;
            Assert.AreEqual(30, bounds.X);
            Assert.AreEqual(100, bounds.Y);
            Assert.AreEqual(100, bounds.Width);
            Assert.AreEqual(100, bounds.Height);
        }
예제 #2
0
		public void NativeWindowFrameHasCorrectScreenBounds ()
		{
			var nativeWindow = new Gtk.Window ("Foo");
			nativeWindow.Resize (450, 320);
			nativeWindow.Move (13, 50);
			nativeWindow.ShowAll ();

			WaitForEvents ();

			var window = Toolkit.CurrentEngine.WrapWindow (nativeWindow);
			var bounds = window.ScreenBounds;
			Assert.AreEqual (450, bounds.Width);
			Assert.AreEqual (320, bounds.Height);
			Assert.AreEqual (13, bounds.X);
			Assert.AreEqual (50, bounds.Y);

			nativeWindow.Move (30, 100);
			WaitForEvents ();
			bounds = window.ScreenBounds;
			Assert.AreEqual (30, bounds.X);
			Assert.AreEqual (100, bounds.Y);
			Assert.AreEqual (450, bounds.Width);
			Assert.AreEqual (320, bounds.Height);

			nativeWindow.Resize (100, 100);
			WaitForEvents ();
			bounds = window.ScreenBounds;
			Assert.AreEqual (30, bounds.X);
			Assert.AreEqual (100, bounds.Y);
			Assert.AreEqual (100, bounds.Width);
			Assert.AreEqual (100, bounds.Height);
		}
예제 #3
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());
            }
        }
예제 #4
0
        public void TestReparenting_ShouldDrawALineInForm()
        {
            Gtk.Application.Init();

            Form testForm = new Form();
            testForm.Show();
            Application.DoEvents();

            var containerWindow = new Gtk.Window(Gtk.WindowType.Popup);
            containerWindow.ShowNow();
            containerWindow.Move(-5000, -5000);

            while (Gtk.Application.EventsPending()) {
                Gtk.Application.RunIteration(false);
            }

            var gdkWrapperOfForm = Gdk.Window.ForeignNewForDisplay(Gdk.Display.Default, (uint)testForm.Handle);
            containerWindow.GdkWindow.Reparent(gdkWrapperOfForm, 0, 0);

            Gdk.GC color = containerWindow.Style.DarkGC (Gtk.StateType.Normal);
            containerWindow.GdkWindow.DrawLine(color, 0, 0, 100, 100);

            while (Gtk.Application.EventsPending()) {
                Gtk.Application.RunIteration(false);
            }

            Application.DoEvents();
        }
        private static void RestoreWindowState(Gtk.Window window)
        {
            var position      = Properties.Settings.Default.WindowPosition;
            var positionValid = false;

            foreach (var desktopWorkArea in Gdk.Global.DesktopWorkareas)
            {
                positionValid = desktopWorkArea.Contains(position);
                if (positionValid)
                {
                    break;
                }
            }
            if (!positionValid)
            {
                var desktop = Gdk.Global.CurrentDesktop;
                var currentDesktopWorkArea = Gdk.Global.DesktopWorkareas[desktop];
                position.X = currentDesktopWorkArea.Left + 40;
                position.Y = currentDesktopWorkArea.Top + 40;
            }
            var size  = Properties.Settings.Default.WindowSize;
            var state = Properties.Settings.Default.WindowState;

            window.Move(position.X, position.Y);
            window.Resize(size.Width, size.Height);
            if (state.HasFlag(Gdk.WindowState.Maximized))
            {
                window.Maximize();
            }
            if (state.HasFlag(Gdk.WindowState.Fullscreen))
            {
                window.Fullscreen();
            }
        }
예제 #6
0
        public void TestReparenting_ShouldDrawALineInForm()
        {
            Gtk.Application.Init();

            Form testForm = new Form();

            testForm.Show();
            Application.DoEvents();

            var containerWindow = new Gtk.Window(Gtk.WindowType.Popup);

            containerWindow.ShowNow();
            containerWindow.Move(-5000, -5000);

            while (Gtk.Application.EventsPending())
            {
                Gtk.Application.RunIteration(false);
            }

            var gdkWrapperOfForm = Gdk.Window.ForeignNewForDisplay(Gdk.Display.Default, (uint)testForm.Handle);

            containerWindow.GdkWindow.Reparent(gdkWrapperOfForm, 0, 0);

            Gdk.GC color = containerWindow.Style.DarkGC(Gtk.StateType.Normal);
            containerWindow.GdkWindow.DrawLine(color, 0, 0, 100, 100);

            while (Gtk.Application.EventsPending())
            {
                Gtk.Application.RunIteration(false);
            }

            Application.DoEvents();
        }
예제 #7
0
        public virtual Gtk.Window ShowTooltipWindow(TextEditor editor, int offset, Gdk.ModifierType modifierState, int mouseX, int mouseY, TooltipItem item)
        {
            Gtk.Window tipWindow = CreateTooltipWindow(editor, offset, modifierState, item);
            if (tipWindow == null)
            {
                return(null);
            }

            int ox = 0, oy = 0;

            if (editor.GdkWindow != null)
            {
                editor.GdkWindow.GetOrigin(out ox, out oy);
            }

            int    w;
            double xalign;

            GetRequiredPosition(editor, tipWindow, out w, out xalign);
            w += 10;

            int x = mouseX + ox + editor.Allocation.X;
            int y = mouseY + oy + editor.Allocation.Y;

            Gdk.Rectangle geometry = editor.Screen.GetUsableMonitorGeometry(editor.Screen.GetMonitorAtPoint(x, y));

            x -= (int)((double)w * xalign);
            y += 10;

            if (x + w >= geometry.X + geometry.Width)
            {
                x = geometry.X + geometry.Width - w;
            }
            if (x < geometry.Left)
            {
                x = geometry.Left;
            }

            int h = tipWindow.SizeRequest().Height;

            if (y + h >= geometry.Y + geometry.Height)
            {
                y = geometry.Y + geometry.Height - h;
            }
            if (y < geometry.Top)
            {
                y = geometry.Top;
            }

            tipWindow.Move(x, y);

            tipWindow.ShowAll();

            return(tipWindow);
        }
예제 #8
0
        // Drag function for automatic sources, called from DragBegin
        static void Drag(Gtk.Widget source, Gdk.DragContext ctx, WidgetDropCallback dropCallback, Gtk.Widget dragWidget)
        {
            if (ctx == null)
            {
                return;
            }

            Gtk.Window      dragWin;
            Gtk.Requisition req;

            ShowFaults();
            DND.dragWidget   = dragWidget;
            DND.dropCallback = dropCallback;

            dragWin = new Gtk.Window(Gtk.WindowType.Popup);
            dragWin.Add(dragWidget);

            req = dragWidget.SizeRequest();
            if (req.Width < 20 && req.Height < 20)
            {
                dragWin.SetSizeRequest(20, 20);
            }
            else if (req.Width < 20)
            {
                dragWin.SetSizeRequest(20, -1);
            }
            else if (req.Height < 20)
            {
                dragWin.SetSizeRequest(-1, 20);
            }

            req = dragWin.SizeRequest();
            if (ctx.SourceWindow != null)
            {
                int px, py, rx, ry;
                Gdk.ModifierType pmask;
                ctx.SourceWindow.GetPointer(out px, out py, out pmask);
                ctx.SourceWindow.GetRootOrigin(out rx, out ry);

                dragWin.Move(rx + px, ry + py);
                dragWin.Show();

                dragHotX = req.Width / 2;
                dragHotY = -3;

                Gtk.Drag.SetIconWidget(ctx, dragWin, dragHotX, dragHotY);
            }

            if (source != null)
            {
                source.DragDataGet += DragDataGet;
                source.DragEnd     += DragEnded;
            }
        }
예제 #9
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);
        }
예제 #10
0
        internal static void ShowAndPositionTooltip(MonoTextEditor editor, Gtk.Window tipWindow, int mouseX, int mouseY, int width, double xalign)
        {
            int ox = 0, oy = 0;

            if (editor.GdkWindow != null)
            {
                editor.GdkWindow.GetOrigin(out ox, out oy);
            }

            width += 10;

            int x = mouseX + ox + editor.Allocation.X;
            int y = mouseY + oy + editor.Allocation.Y;

            Gdk.Rectangle geometry = editor.Screen.GetUsableMonitorGeometry(editor.Screen.GetMonitorAtPoint(x, y));

            x -= (int)((double)width * xalign);
            y += 10;

            if (x + width >= geometry.X + geometry.Width)
            {
                x = geometry.X + geometry.Width - width;
            }
            if (x < geometry.Left)
            {
                x = geometry.Left;
            }

            int h = tipWindow.SizeRequest().Height;

            if (y + h >= geometry.Y + geometry.Height)
            {
                y = geometry.Y + geometry.Height - h;
            }
            if (y < geometry.Top)
            {
                y = geometry.Top;
            }

            tipWindow.Move(x, y);

            tipWindow.ShowAll();
        }
예제 #11
0
        public void Restore()
        {
            if ((options & WindowPersistOptions.Size) != 0)
            {
                int width  = WidthSchema.Get();
                int height = HeightSchema.Get();

                if (width != 0 && height != 0)
                {
                    window.Resize(width, height);
                }
            }

            if ((options & WindowPersistOptions.Position) != 0)
            {
                int x = XPosSchema.Get();
                int y = YPosSchema.Get();

                if (x == 0 && y == 0)
                {
                    window.SetPosition(Gtk.WindowPosition.Center);
                }
                else
                {
                    window.Move(x, y);
                }
            }

            if ((options & WindowPersistOptions.Size) != 0)
            {
                if (MaximizedSchema.Get())
                {
                    window.Maximize();
                }
                else
                {
                    window.Unmaximize();
                }
            }
        }
예제 #12
0
        void ShowTip(int x, int y, string text)
        {
            if (GdkWindow == null)
            {
                return;
            }
            if (tipWindow == null)
            {
                tipWindow = new TipWindow();
                Gtk.Label lab = new Gtk.Label(text);
                lab.Xalign = 0;
                lab.Xpad   = 3;
                lab.Ypad   = 3;
                tipWindow.Add(lab);
            }
            ((Gtk.Label)tipWindow.Child).Text = text;
            int w = tipWindow.Child.SizeRequest().Width;
            int ox, oy;

            GdkWindow.GetOrigin(out ox, out oy);
            tipWindow.Move(ox + x - (w / 2) + (iconSize / 2), oy + y);
            tipWindow.ShowAll();
        }
예제 #13
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);
        }
예제 #14
0
        internal void SetFloatMode(Gdk.Rectangle rect)
        {
            if (floatingWindow == null)
            {
                ResetMode();
                SetRegionStyle(frame.GetRegionStyleForItem(this));

                floatingWindow = new DockFloatingWindow((Gtk.Window)frame.Toplevel, GetWindowTitle());
                Ide.IdeApp.CommandService.RegisterTopWindow(floatingWindow);

                Gtk.VBox box = new Gtk.VBox();
                box.Show();
                box.PackStart(TitleTab, false, false, 0);
                box.PackStart(Widget, true, true, 0);
                floatingWindow.Add(box);
                floatingWindow.DeleteEvent += delegate(object o, Gtk.DeleteEventArgs a) {
                    if (behavior == DockItemBehavior.CantClose)
                    {
                        Status = DockItemStatus.Dockable;
                    }
                    else
                    {
                        Visible = false;
                    }
                    a.RetVal = true;
                };
            }
            floatingWindow.Move(rect.X, rect.Y);
            floatingWindow.Resize(rect.Width, rect.Height);
            floatingWindow.Show();
            if (titleTab != null)
            {
                titleTab.UpdateBehavior();
            }
            Widget.Show();
        }
예제 #15
0
파일: DND.cs 프로젝트: mono/stetic
        // Drag function for automatic sources, called from DragBegin
        static void Drag(Gtk.Widget source, Gdk.DragContext ctx, WidgetDropCallback dropCallback, Gtk.Widget dragWidget)
        {
            if (ctx == null)
                return;

            Gtk.Window dragWin;
            Gtk.Requisition req;

            ShowFaults ();
            DND.dragWidget = dragWidget;
            DND.dropCallback = dropCallback;

            dragWin = new Gtk.Window (Gtk.WindowType.Popup);
            dragWin.Add (dragWidget);

            req = dragWidget.SizeRequest ();
            if (req.Width < 20 && req.Height < 20)
                dragWin.SetSizeRequest (20, 20);
            else if (req.Width < 20)
                dragWin.SetSizeRequest (20, -1);
            else if (req.Height < 20)
                dragWin.SetSizeRequest (-1, 20);

            req = dragWin.SizeRequest ();

            int px, py, rx, ry;
            Gdk.ModifierType pmask;
            ctx.SourceWindow.GetPointer (out px, out py, out pmask);
            ctx.SourceWindow.GetRootOrigin (out rx, out ry);

            dragWin.Move (rx + px, ry + py);
            dragWin.Show ();

            dragHotX = req.Width / 2;
            dragHotY = -3;

            Gtk.Drag.SetIconWidget (ctx, dragWin, dragHotX, dragHotY);

            if (source != null) {
                source.DragDataGet += DragDataGet;
                source.DragEnd += DragEnded;
            }
        }
예제 #16
0
 internal virtual void PlaceWindow(Gtk.Window window, int x, int y, int width, int height)
 {
     window.Move(x, y);
     window.Resize(width, height);
 }
예제 #17
0
        /// <summary>Writes PDF for specified auto-doc commands.</summary>
        /// <param name="section">The writer to write to.</param>
        /// <param name="tags">The autodoc tags.</param>
        /// <param name="workingDirectory">The working directory.</param>
        private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags, string workingDirectory)
        {
            int figureNumber = 0;

            foreach (AutoDocumentation.ITag tag in tags)
            {
                if (tag is AutoDocumentation.Heading)
                {
                    AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading;
                    if (heading.headingLevel > 0 && heading.headingLevel <= 6)
                    {
                        //if (heading.headingLevel == 1)
                        //    section.AddPageBreak();

                        Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel);
                        if (heading.headingLevel == 1)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level1;
                        }
                        else if (heading.headingLevel == 2)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level2;
                        }
                        else if (heading.headingLevel == 3)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level3;
                        }
                        else if (heading.headingLevel == 4)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level4;
                        }
                        else if (heading.headingLevel == 5)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level5;
                        }
                        else if (heading.headingLevel == 6)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level6;
                        }
                    }
                }
                else if (tag is AutoDocumentation.Paragraph)
                {
                    AutoDocumentation.Paragraph paragraph = tag as AutoDocumentation.Paragraph;
                    if (paragraph.text.Contains("![Alt Text]"))
                    {
                        figureNumber++;
                    }
                    paragraph.text = paragraph.text.Replace("[FigureNumber]", figureNumber.ToString());
                    AddFormattedParagraphToSection(section, paragraph);
                }
                else if (tag is AutoDocumentation.GraphAndTable)
                {
                    CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory);
                }
                else if (tag is GraphPage)
                {
                    CreateGraphPage(section, tag as GraphPage, workingDirectory);
                }
                else if (tag is AutoDocumentation.NewPage)
                {
                    section.AddPageBreak();
                }
                else if (tag is AutoDocumentation.Table)
                {
                    CreateTable(section, tag as AutoDocumentation.Table, workingDirectory);
                }
                else if (tag is Graph)
                {
                    GraphPresenter graphPresenter = new GraphPresenter();
                    ExplorerPresenter.ApsimXFile.Links.Resolve(graphPresenter);
                    GraphView graphView = new GraphView();
                    graphView.BackColor = OxyPlot.OxyColors.White;
                    graphView.FontSize  = 12;
                    graphView.Width     = 500;
                    graphView.Height    = 500;
                    graphPresenter.Attach(tag, graphView, ExplorerPresenter);
                    string PNGFileName = graphPresenter.ExportToPDF(workingDirectory);
                    section.AddImage(PNGFileName);
                    string caption = (tag as Graph).Caption;
                    if (caption != null)
                    {
                        section.AddParagraph(caption);
                    }
                    graphPresenter.Detach();
                    graphView.MainWidget.Destroy();
                }
                else if (tag is Map && (tag as Map).GetCoordinates().Count > 0)
                {
                    MapPresenter mapPresenter = new MapPresenter();
                    MapView      mapView      = new MapView(null);
                    mapPresenter.Attach(tag, mapView, ExplorerPresenter);
                    string PNGFileName = mapPresenter.ExportToPDF(workingDirectory);
                    if (!String.IsNullOrEmpty(PNGFileName))
                    {
                        section.AddImage(PNGFileName);
                    }
                    mapPresenter.Detach();
                    mapView.MainWidget.Destroy();
                }
                else if (tag is AutoDocumentation.Image)
                {
                    AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image;
                    if (imageTag.image.Width > 700)
                    {
                        imageTag.image = ImageUtilities.ResizeImage(imageTag.image, 700, 500);
                    }
                    string PNGFileName = Path.Combine(workingDirectory, imageTag.name);
                    imageTag.image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png);
                    section.AddImage(PNGFileName);
                    figureNumber++;
                }
                else if (tag is DirectedGraph)
                {
                    DirectedGraphPresenter presenter = new DirectedGraphPresenter();
                    ExplorerPresenter.ApsimXFile.Links.Resolve(presenter);
                    DirectedGraphView view = new DirectedGraphView();
                    presenter.Attach(new DirectedGraphContainer(tag as DirectedGraph), view, ExplorerPresenter);

                    Gtk.Window popupWin = new Gtk.Window(Gtk.WindowType.Popup);
                    popupWin.SetSizeRequest(800, 800);
                    // Move the window offscreen; the user doesn't need to see it.
                    // This works with IE, but not with WebKit
                    // Not yet tested on OSX
                    if (ProcessUtilities.CurrentOS.IsWindows)
                    {
                        popupWin.Move(-10000, -10000);
                    }
                    popupWin.Add(view.MainWidget);
                    popupWin.ShowAll();
                    while (Gtk.Application.EventsPending())
                    {
                        Gtk.Application.RunIteration();
                    }

                    string PNGFileName = presenter.ExportToPNG(workingDirectory);
                    section.AddImage(PNGFileName);
                    presenter.Detach();
                    view.MainWidget.Destroy();
                }
            }
        }