Exemplo n.º 1
0
 protected override bool OnLeaveNotifyEvent(Gdk.EventCrossing evnt)
 {
     // While showing a window, if the cursor is in the area of the new window, sometimes we get several Enter/Leave events
     // in sequence, until the window is fully visible. To avoid hiding the window too early, we schedule here a tooltip
     // hide, which will be canceled if we get a new Enter event.
     GtkUtil.ScheduleHideTooltip(tree);
     return(base.OnLeaveNotifyEvent(evnt));
 }
Exemplo n.º 2
0
        internal void ShowPopup(Xwt.Widget widget, Xwt.Rectangle caret, PopupPosition position)
        {
            xwtParent            = widget;
            this.currentCaret    = new Gdk.Rectangle((int)caret.X, (int)caret.Y, (int)caret.Width, (int)caret.Height);
            Theme.TargetPosition = position;
            var pos = GtkUtil.GetSceenBounds(widget);

            targetWindowOrigin = new Point((int)pos.X, (int)pos.Y);
            RepositionWindow();
        }
Exemplo n.º 3
0
        public void ShowPopup(Widget widget, Rectangle targetRectangle, PopupPosition position)
        {
            target         = widget;
            targetRect     = targetRectangle;
            targetPosition = position;
            TransientFor   = widget.ParentWindow;
            var pos = GtkUtil.GetSceenBounds(widget);

            targetWindowOrigin = new Point(pos.X, pos.Y);
            ShowPopupInternal();
        }
Exemplo n.º 4
0
 Gdk.Rectangle GetScreenCoordinates(Gdk.Rectangle caret)
 {
     if (parent != null)
     {
         return(GtkUtil.ToScreenCoordinates(parent, parent.GdkWindow, caret));
     }
     if (xwtParent != null)
     {
         return(GtkUtil.ToScreenCoordinates(xwtParent, caret.ToXwtRectangle()));
     }
     return(Gdk.Rectangle.Zero);
 }
Exemplo n.º 5
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            base.OnExposeEvent(evnt);

            Gdk.Rectangle expose     = Allocation;
            Gdk.Color     save       = Gdk.Color.Zero;
            bool          hasFgColor = false;
            int           x          = 1;

            // Make sure that the row has not been removed inbetween.
            // If the model is a TreeStore, it can do the validation for us, otherwise we need to validate the path.
            if ((treeStore != null && treeStore.IterIsValid(iter) == false) || !tree.Model.GetIter(out iter, path))
            {
                GtkUtil.HideTooltip(tree);
                return(true);
            }
            col.CellSetCellData(tree.Model, iter, false, false);

            foreach (CellRenderer cr in col.CellRenderers)
            {
                if (!cr.Visible)
                {
                    continue;
                }

                if (cr is CellRendererText)
                {
                    hasFgColor = ((CellRendererText)cr).GetCellForegroundSet();
                    save       = ((CellRendererText)cr).ForegroundGdk;
                    ((CellRendererText)cr).ForegroundGdk = Style.Foreground(State);
                }

                int sp, wi, he, xo, yo;
                col.CellGetPosition(cr, out sp, out wi);
                Gdk.Rectangle bgrect = new Gdk.Rectangle(x, expose.Y, wi, expose.Height - 2);
                cr.GetSize(tree, ref bgrect, out xo, out yo, out wi, out he);
                int           leftMargin = (int)((bgrect.Width - wi) * cr.Xalign);
                int           topMargin  = (int)((bgrect.Height - he) * cr.Yalign);
                Gdk.Rectangle cellrect   = new Gdk.Rectangle(bgrect.X + leftMargin, bgrect.Y + topMargin + 1, wi, he);
                cr.Render(this.GdkWindow, this, bgrect, cellrect, expose, CellRendererState.Focused);
                x += bgrect.Width + col.Spacing + 1;

                if (cr is CellRendererText)
                {
                    ((CellRendererText)cr).ForegroundGdk = save;
                    ((CellRendererText)cr).SetCellForegroundSet(hasFgColor);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        private void ShowPopup(AppKit.NSView widget, Rectangle targetRectangle, PopupPosition position)
        {
            target         = widget;
            targetRect     = targetRectangle;
            targetPosition = position;
            try {
                TransientFor = Toolkit.Load(Xwt.ToolkitType.XamMac)?.WrapWindow(widget.Window);
            } catch {
                if (MessageDialog.RootWindow != null)
                {
                    TransientFor = MessageDialog.RootWindow;
                }
            }
            var pos = GtkUtil.GetSceenBounds(widget);

            targetWindowOrigin = new Point(pos.X, pos.Y);
            ShowPopupInternal();
        }
Exemplo n.º 7
0
        protected Rectangle GetScreenCoordinates(Rectangle targetRect)
        {
            // TODO: Fix cross toolkit coords
            var gtkTarget = target as Gtk.Widget;

            if (gtkTarget != null)
            {
                return(GtkUtil.ToScreenCoordinates(gtkTarget, gtkTarget.GdkWindow, targetRect.ToGdkRectangle()).ToXwtRectangle());
            }
                        #if MAC
            var nsTarget = target as AppKit.NSView;
            if (nsTarget != null)
            {
                var lo = nsTarget.ConvertPointToView(new CoreGraphics.CGPoint((nfloat)targetRect.X, (nfloat)targetRect.Y), null);
                lo = nsTarget.Window.ConvertRectToScreen(new CoreGraphics.CGRect(lo, CoreGraphics.CGSize.Empty)).Location;
                var r = new CoreGraphics.CGRect(lo.X, lo.Y, 0, nsTarget.IsFlipped ? 0 : nsTarget.Frame.Height);

                var desktopBounds = new Rectangle();
                foreach (var s in AppKit.NSScreen.Screens)
                {
                    var sr = s.Frame;
                    desktopBounds = desktopBounds.Union(new Rectangle(sr.X, sr.Y, sr.Width, sr.Height));
                }

                r.Y = (nfloat)desktopBounds.Height - r.Y - r.Height;
                if (desktopBounds.Y < 0)
                {
                    r.Y += (nfloat)desktopBounds.Y;
                }
                return(new Rectangle(r.X, r.Y, r.Width, r.Height));
            }
                        #endif
            var xwtTarget = target as Widget;
            if (xwtTarget != null)
            {
                return(GtkUtil.ToScreenCoordinates(xwtTarget, targetRect).ToXwtRectangle());
            }

            return(Rectangle.Zero);
        }
        public void AnimatedResize()
        {
            if (!GtkUtil.ScreenSupportsARGB())
            {
                QueueResize();
                return;
            }

            disableSizeCheck = true;
            Gtk.Requisition sizeReq = Gtk.Requisition.Zero;
            // use OnSizeRequested instead of SizeRequest to bypass internal GTK caching
            OnSizeRequested(ref sizeReq);
            disableSizeCheck = false;

            Gdk.Size size = new Gdk.Size(sizeReq.Width, sizeReq.Height);

            // ensure that our apint area is big enough for our padding
            if (paintSize.Width <= 15 || paintSize.Height <= 15)
            {
                paintSize = size;
            }

            targetSize = size;
            Gdk.Size start = paintSize;
            Func <double, Gdk.Size> transform = x => new Gdk.Size((int)(start.Width + (size.Width - start.Width) * x),
                                                                  (int)(start.Height + (size.Height - start.Height) * x));

            this.Animate("Resize",
                         transform,
                         s => paintSize = s,
                         length: 150,
                         easing: Easing.SinInOut,
                         finished: (x, aborted) => { if (!aborted)
                                                     {
                                                         MaybeReanimate();
                                                     }
                         });
            QueueResize();
        }
        public virtual void RepositionWindow(Gdk.Rectangle?newCaret = null)
        {
            if (parent == null)
            {
                return;
            }

            int x, y;

            if (newCaret.HasValue)              //Update caret if parameter is given
            {
                currentCaret = newCaret.Value;
            }
            Gdk.Rectangle caret  = currentCaret;
            Gdk.Window    window = targetWindow;
            if (targetWindow == null)
            {
                return;
            }
            PopupPosition position = Theme.TargetPosition;

            this.position = Theme.TargetPosition;
            UpdatePadding();

            window.GetOrigin(out x, out y);
            var alloc = parent.Allocation;

            if (eventProvided)
            {
                caret.X     = x;
                caret.Y     = y;
                caret.Width = caret.Height = 1;
            }
            else
            {
                if (caret.Equals(Gdk.Rectangle.Zero))
                {
                    caret = new Gdk.Rectangle(0, 0, alloc.Width, alloc.Height);
                }
                caret = GtkUtil.ToScreenCoordinates(parent, parent.GdkWindow, caret);
            }

            Gtk.Requisition request = SizeRequest();
            var             screen  = parent.Screen;

            Gdk.Rectangle geometry = GtkWorkarounds.GetUsableMonitorGeometry(screen, screen.GetMonitorAtPoint(caret.X, caret.Y));

            // Add some spacing between the screen border and the popover window
            geometry.Inflate(-5, -5);

            // Flip the orientation if the window doesn't fit the screen.

            int intPos = (int)position;

            switch ((PopupPosition)(intPos & 0x0f))
            {
            case PopupPosition.Top:
                if (caret.Bottom + request.Height > geometry.Bottom)
                {
                    intPos = (intPos & 0xf0) | (int)PopupPosition.Bottom;
                }
                break;

            case PopupPosition.Bottom:
                if (caret.Top - request.Height < geometry.X)
                {
                    intPos = (intPos & 0xf0) | (int)PopupPosition.Top;
                }
                break;

            case PopupPosition.Right:
                if (caret.X - request.Width < geometry.X)
                {
                    intPos = (intPos & 0xf0) | (int)PopupPosition.Left;
                }
                break;

            case PopupPosition.Left:
                if (caret.Right + request.Width > geometry.Right)
                {
                    intPos = (intPos & 0xf0) | (int)PopupPosition.Right;
                }
                break;
            }

            position = (PopupPosition)intPos;
            UpdatePadding();

            // Calculate base coordinate

            switch ((PopupPosition)((int)position & 0x0f))
            {
            case PopupPosition.Top:
                y = caret.Bottom;
                break;

            case PopupPosition.Bottom:
                y = caret.Y - request.Height; break;

            case PopupPosition.Right:
                x = caret.X - request.Width; break;

            case PopupPosition.Left:
                x = caret.Right; break;
            }
            int offset;

            if ((position & PopupPosition.Top) != 0 || (position & PopupPosition.Bottom) != 0)
            {
                if (((int)position & 0x10) != 0)
                {
                    x = caret.X - MinArrowSpacing - Theme.ArrowWidth / 2;
                }
                else if (((int)position & 0x20) != 0)
                {
                    x = caret.Right - request.Width + MinArrowSpacing + Theme.ArrowWidth / 2;
                }
                else
                {
                    x = caret.X + (caret.Width - request.Width) / 2;
                }

                if (x < geometry.Left)
                {
                    x = geometry.Left;
                }
                else if (x + request.Width > geometry.Right)
                {
                    x = geometry.Right - request.Width;
                }

                offset = caret.X + caret.Width / 2 - x;
                if (offset - Theme.ArrowWidth / 2 < MinArrowSpacing)
                {
                    offset = MinArrowSpacing + Theme.ArrowWidth / 2;
                }
                if (offset > request.Width - MinArrowSpacing - Theme.ArrowWidth / 2)
                {
                    offset = request.Width - MinArrowSpacing - Theme.ArrowWidth / 2;
                }
            }
            else
            {
                if (((int)position & 0x10) != 0)
                {
                    y = caret.Y - MinArrowSpacing - Theme.ArrowWidth / 2;
                }
                else if (((int)position & 0x20) != 0)
                {
                    y = caret.Bottom - request.Height + MinArrowSpacing + Theme.ArrowWidth / 2;
                }
                else
                {
                    y = caret.Y + (caret.Height - request.Height) / 2;
                }

                if (y < geometry.Top)
                {
                    y = geometry.Top;
                }
                else if (y + request.Height > geometry.Bottom)
                {
                    y = geometry.Bottom - request.Height;
                }
                if (MaximumYTopBound > 0)
                {
                    y = Math.Max(MaximumYTopBound, y);
                }

                offset = caret.Y + caret.Height / 2 - y;
                if (offset - Theme.ArrowWidth / 2 < MinArrowSpacing)
                {
                    offset = MinArrowSpacing + Theme.ArrowWidth / 2;
                }
                if (offset > request.Height - MinArrowSpacing - Theme.ArrowWidth / 2)
                {
                    offset = request.Height - MinArrowSpacing - Theme.ArrowWidth / 2;
                }
            }
            Theme.ArrowOffset = offset;
            this.position     = position;
            UpdatePadding();

            Move(x, y);
            Show();
            if (!ShowWindowShadow)
            {
                DesktopService.RemoveWindowShadow(this);
            }
        }
Exemplo n.º 10
0
 protected override bool OnEnterNotifyEvent(Gdk.EventCrossing evnt)
 {
     GtkUtil.UnscheduleHideTooltip(tree);
     return(base.OnEnterNotifyEvent(evnt));
 }
Exemplo n.º 11
0
 protected override bool OnLeaveNotifyEvent(Gdk.EventCrossing evnt)
 {
     MouseIsOver = false;
     GtkUtil.HideTooltip(tree);
     return(base.OnLeaveNotifyEvent(evnt));
 }