Beispiel #1
0
        public static Xwt.Point ConvertToScreenCoordinates(Widget widget, Xwt.Point point)
        {
            var parentWindow = widget.ParentWindow;

            if (parentWindow == null)
            {
                var win = widget as Gtk.Window;
                if (win != null)
                {
                    parentWindow = win.GdkWindow;
                }
                else
                {
                    return(Point.Zero);
                }
            }
            int x, y;

            parentWindow.GetOrigin(out x, out y);
            var a = widget.Allocation;

            x += a.X;
            y += a.Y;

            return(new Xwt.Point(x + point.X, y + point.Y));
        }
Beispiel #2
0
 public override void Update()
 {
     base.Update();
     if (useOnScroll && backend.AutoScroll)
     {
         var point = backend.AutoScrollPosition;
         _scrollPosition = new Xwt.Point(-point.X, -point.Y);
     }
 }
Beispiel #3
0
        private bool useOnScroll = true; // false: works on mono.windows, but not on linux
        public virtual void OnScroll(ScrollEventArgs se)
        {
            if (useOnScroll && backend.AutoScroll)
            {
                if (se.OldValue != se.NewValue)
                {
                    scrollChanged = true;

                    if (OS.Mono)
                    {
                        // mono does not deliver ScrollOrientation
                        var deltaX = 0d;
                        var deltaY = 0d;

                        var point = backend.AutoScrollPosition;
                        deltaX = _scrollPosition.X + point.X;
                        deltaY = _scrollPosition.Y + point.Y;

                        //update and set new scrollPosition
                        _scrollPosition = new Xwt.Point(-point.X, -point.Y);

                        if (deltaX != 0 || deltaY != 0)
                        {
                            // OnScroll works different on mono
                            // Mono first calls OnPaint, then OnScroll
                            // everything is drawn with wrong offset
                            // so we have to invalidate the device again
                            // this is a workaroud; we have two OnPaint then!
                            // think about a whole Viewport for Mono.Linux
#if TraceInvalidate
                            System.Console.Out.WriteLine("OnScroll  x={0} y={1}", deltaX, deltaY);
#endif
                            UpdateCamera();

                            backend.Invalidate();
                        }
                    }
                    else
                    {
                        if (se.ScrollOrientation == ScrollOrientation.HorizontalScroll)
                        {
                            _scrollPosition.X = se.NewValue;
                        }
                        else
                        {
                            _scrollPosition.Y = se.NewValue;
                        }
                    }

#if TraceInvalidate
                    System.Console.Out.WriteLine("OnScroll scrollChanged");
#endif
                }
            }
        }
Beispiel #4
0
        void OnMouseMove(object sender, Gtk.MotionNotifyEventArgs e)
        {
            if (_popup.IsVisible)
            {
                Point mousePt = new Point(e.Event.X, e.Event.Y); //TODO: Check if we have to move to screen cordinate system

                if (this.ShouldClearToolTipOnMouseMove(mousePt))
                {
                    _manager.RemoveAgent(this);
                }
            }
        }
Beispiel #5
0
        internal bool ShouldClearToolTipOnMouseMove(Point mousePt)
        {
            _textView.VisualElement.GetPointer(out int x, out int y);
            var topLeft     = _textView.VisualElement.GetScreenCoordinates(new Gdk.Point(0, 0));
            var bottomRight = _textView.VisualElement.GetScreenCoordinates(new Gdk.Point(_textView.VisualElement.WidthRequest, _textView.VisualElement.HeightRequest));

            //TODO: Test if this is correct
            if (!new Rect(topLeft.ToXwtPoint(), bottomRight.ToXwtPoint()).Contains(x, y))
            {
                return(true);
            }

            return(this.InnerShouldClearToolTipOnMouseMove(mousePt));
        }
Beispiel #6
0
        public void Show(Widget reference)
        {
            Gdk.Window    parentWindow = reference.ParentWindow;
            Xwt.Rectangle rectangle1   = new Xwt.Rectangle(this.ConvertToScreenCoordinates(reference, new Xwt.Point(0.0, 0.0)), new Xwt.Size((double)reference.Allocation.Width, (double)reference.Allocation.Height));
            Xwt.Rectangle rectangle2   = new Xwt.Rectangle(Xwt.Point.Zero, rectangle1.Size);
            rectangle2 = rectangle2.Offset(rectangle1.Location);
            Xwt.Point position = rectangle2.Location;
            this.ShowAll();
            int width;
            int height;

            this.GetSize(out width, out height);
            this.Move((int)(position.X + this.margin.Left), (int)(position.Y + this.margin.Top));
            this.SizeAllocated += (SizeAllocatedHandler)((o, args) => this.Move((int)position.X, (int)position.Y));
        }
Beispiel #7
0
        public Xwt.Point ConvertToScreenCoordinates(Widget widget, Xwt.Point widgetCoordinates)
        {
            if (widget.ParentWindow == null)
            {
                return(new Xwt.Point(0.0, 0.0));
            }
            int x;
            int y;

            widget.ParentWindow.GetOrigin(out x, out y);
            Gdk.Rectangle allocation = widget.Allocation;
            int           num1       = x + allocation.X;
            int           num2       = y + allocation.Y;

            return(new Xwt.Point((double)num1 + widgetCoordinates.X, (double)num2 + widgetCoordinates.Y));
        }
Beispiel #8
0
        internal bool InnerShouldClearToolTipOnMouseMove(Point mousePt)
        {
            if ((mousePt.X >= 0.0) && (mousePt.X < _textView.ViewportWidth) &&
                (mousePt.Y >= 0.0) && (mousePt.Y < _textView.ViewportHeight))
            {
                ITextViewLine line = _textView.TextViewLines.GetTextViewLineContainingYCoordinate(mousePt.Y + _textView.ViewportTop);
                if (line != null)
                {
                    SnapshotSpan span = _visualSpan.GetSpan(_textView.TextSnapshot);
                    if (span.IntersectsWith(line.ExtentIncludingLineBreak))
                    {
                        double x = mousePt.X + _textView.ViewportLeft;

                        //The mouse could be over text in the line ... see if it is over the tip
                        //This code essentially duplicates the logic in WpfTextView with respect
                        //to determining the logical position of the hover event.
                        int?position = line.GetBufferPositionFromXCoordinate(x, true);
                        if ((!position.HasValue) && (line.LineBreakLength == 0) && line.IsLastTextViewLineForSnapshotLine)
                        {
                            //For purposes of clearing tips, pretend the last line in the buffer
                            //actually is padded by the EndOfLineWidth (even though it is not).
                            if ((line.TextRight <= x) && (x < line.TextRight + line.EndOfLineWidth))
                            {
                                //position is at the end of the buffer. Return true if the span
                                //doesn't extend to the end of the buffer.
                                return(span.End < _textView.TextSnapshot.Length);
                            }
                        }

                        if (position.HasValue)
                        {
                            //A span that ends at the end of the buffer contains a position at the end of the buffer.
                            return(!span.Contains(position.Value));
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #9
0
            public override void DisplayAt(Point point)
            {
                //The horizontal and verical offsets are specified in terms of device pixels
                //so convert logical pixel position in point to device pixels.
                //_popup.HorizontalOffset = point.X * WpfHelper.DeviceScaleX;
                //_popup.VerticalOffset = point.Y * WpfHelper.DeviceScaleY;
                _popup.Location = point;

                if (base.Content != _popupContentContainer.Content)
                {
                    if (base.Content.Parent == null)
                    {
                        _popupContentContainer.Content = base.Content;
                        _popup.Show();
                    }
                    else
                    {
                        //The intended content still has a parent. Clear out the old content and hope things are better next time around.
                        _popupContentContainer.Content = null;
                    }
                }
            }
Beispiel #10
0
        public Geometry PositionAndDisplay(Geometry reservedSpace)
        {
            //This method should only be called from the popup manager (which should never call it when the containing
            //view is hidden or in the middle of a layout).

            //This method does not support virtual whitespace positioning.  An attempt to support it by using caret position was introduced, but
            //regressed the behavior that popup should stay in place as the caret moves.  If in the future we need to support virtual whitespace,
            //consider using virtual span instead.

            //Update the visual span to the current snapshot.
            SnapshotSpan visualSpan = _visualSpan.GetSpan(_textView.TextSnapshot);

            // If the style indicates that we should dismiss when the mouse leaves the span of the text, then we should make an
            // initial check to make sure the mouse starts-off in the span.  If not, we should fail to position.
            if ((_style & (PopupStyles.DismissOnMouseLeaveText | PopupStyles.DismissOnMouseLeaveTextOrContent)) != 0)
            {
                _textView.VisualElement.GetPointer(out int x, out int y);
                if (this.ShouldClearToolTipOnMouseMove(new Point(x, y)))
                {
                    return(null);
                }
            }

            Rect?spanRectangle = null;

            if (visualSpan.Length > 0)
            {
                double left   = double.MaxValue;
                double top    = double.MaxValue;
                double right  = double.MinValue;
                double bottom = double.MinValue;

                var bounds = _textView.TextViewLines.GetNormalizedTextBounds(visualSpan);
                foreach (var bound in bounds)
                {
                    left   = Math.Min(left, bound.Left);
                    top    = Math.Min(top, bound.TextTop);
                    right  = Math.Max(right, bound.Right);
                    bottom = Math.Max(bottom, bound.TextBottom);
                }

                // If the start of the span lies within the view, use that instead of the left-bound of the span as a whole.
                // This will cause popups to be left-aligned with the start of their span, if at all possible.
                var startLine = _textView.TextViewLines.GetTextViewLineContainingBufferPosition(visualSpan.Start);
                if (startLine != null)
                {
                    var startPointBounds = startLine.GetExtendedCharacterBounds(visualSpan.Start);
                    if ((startPointBounds.Left < right) && (startPointBounds.Left >= _textView.ViewportLeft) && (startPointBounds.Left < _textView.ViewportRight))
                    {
                        left = startPointBounds.Left;
                    }
                }

                //Special case handling for when the end of the span is at the start of a line.
                ITextViewLine line = _textView.TextViewLines.GetTextViewLineContainingBufferPosition(visualSpan.End);
                if ((line != null) && (line.Start == visualSpan.End))
                {
                    bottom = Math.Max(bottom, line.TextBottom);
                }

                if (left < right)
                {
                    spanRectangle = new Rect(left, top, right - left, bottom - top);
                }
            }
            else
            {
                //visualSpan is zero length so the default MarkerGeometry will be null. Create a custom marker geometry based on the location.
                ITextViewLine line = _textView.TextViewLines.GetTextViewLineContainingBufferPosition(visualSpan.Start);
                if (line != null)
                {
                    TextBounds bounds = line.GetCharacterBounds(visualSpan.Start);
                    spanRectangle = new Rect(bounds.Left, bounds.TextTop, 0.0, bounds.TextHeight);
                }
            }

            if (spanRectangle.HasValue)
            {
                //Get the portion of the span geometry that is inside the view.
                Rect viewRect = new Rect(_textView.ViewportLeft, _textView.ViewportTop, _textView.ViewportWidth, _textView.ViewportHeight);

                Rect spanRect = spanRectangle.Value;
                spanRect = spanRect.Intersect(viewRect);

                if (spanRect != default(Rect))
                {
                    // Determine two different rectangles for the span.  One is the span in its raw form.  The other is a "guess" at
                    // what the already-reserved space around the span will be.  We have a very-prevalent space reservation agent (the
                    // current line agent) that reserves the current line plus a 3-pixel buffer below the line.  We'll optimistically
                    // guess that this agent might be in-play and attempt to avoid it.
                    Rect spanRectWithBuffer = new Rect(spanRect.Left, spanRect.Top, spanRect.Right - spanRect.Left, spanRect.Bottom - spanRect.Top + BelowTheLineBufferHint);

                    //Some of the text associated with the popup is visible, show the popup.
                    Rect spanRectInScreenCoordinates = new Rect(this.GetScreenPointFromTextXY(spanRect.Left, spanRect.Top),
                                                                this.GetScreenPointFromTextXY(spanRect.Right, spanRect.Bottom));
                    Rect spanRectWithBufferInScreenCoordinates = new Rect(this.GetScreenPointFromTextXY(spanRectWithBuffer.Left, spanRectWithBuffer.Top),
                                                                          this.GetScreenPointFromTextXY(spanRectWithBuffer.Right, spanRectWithBuffer.Bottom));
                    Rect screenRect = Xwt.Desktop.GetScreenAtLocation(spanRectInScreenCoordinates.TopLeft).Bounds;//TODO: Check if we should use VisualBounds

                    Size desiredSize = _popup.Size;
                    //The popup size specified in deivice pixels. Convert these to logical
                    //pixels for purposes of calculating the actual size of the popup.
                    //TODO desiredSize = new Size (desiredSize.Width / WpfHelper.DeviceScaleX, desiredSize.Height / WpfHelper.DeviceScaleY);
                    desiredSize = new Size(desiredSize.Width, desiredSize.Height);

                    PopupStyles alternateStyle = _style ^ PopupStyles.PreferLeftOrTopPosition;

                    var   tr      = reservedSpace.Bounds;
                    Point topLeft = new Point(Math.Min(spanRectInScreenCoordinates.Left, tr.Left),
                                              Math.Min(spanRectInScreenCoordinates.Top, tr.Top));
                    Point bottomRight = new Point(Math.Max(spanRectInScreenCoordinates.Right, tr.Right),
                                                  Math.Max(spanRectInScreenCoordinates.Bottom, tr.Bottom));
                    var reservedRect = new Rect(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y);

                    //There are 6 possible locations for the popup.  The order of preference is determined by the presence of the
                    //'PositionClosest' PopupStyle.
                    //
                    //  Without 'PositionClosest':
                    //  1 .. On the desired side of the span.
                    //  2 .. On the desired side of the span with a bit of buffer.
                    //  3 .. on the desired side of the reserved rectangle.
                    //  4 .. On the alternate side of the span.
                    //  5 .. On the alternate side of the span with a bit of buffer.
                    //  6 .. on the alternate side of the reserved rectangle.
                    //
                    //  With 'PositionClosest':
                    //  1 .. On the desired side of the span.
                    //  2 .. On the desired side of the span with a bit of buffer.
                    //  3 .. On the alternate side of the span.
                    //  4 .. On the alternate side of the span with a bit of buffer.
                    //  5 .. on the desired side of the reserved rectangle.
                    //  6 .. on the alternate side of the reserved rectangle.
                    //
                    //Try each location till we get a winner.
                    //  A location is a winner if it is disjoint from the original reserved rect and
                    //  the edges of the screen.

                    Tuple <PopupStyles, Rect>[] positionChoices;
                    if (reservedRect != default(Rect))
                    {
                        if ((_style & PopupStyles.PositionClosest) == 0)
                        {
                            positionChoices = new Tuple <PopupStyles, Rect>[]
                            {
                                new Tuple <PopupStyles, Rect>(_style, spanRectInScreenCoordinates),
                                new Tuple <PopupStyles, Rect>(_style, spanRectWithBufferInScreenCoordinates),
                                new Tuple <PopupStyles, Rect>(_style, reservedRect),
                                new Tuple <PopupStyles, Rect>(alternateStyle, spanRectInScreenCoordinates),
                                new Tuple <PopupStyles, Rect>(alternateStyle, spanRectWithBufferInScreenCoordinates),
                                new Tuple <PopupStyles, Rect>(alternateStyle, reservedRect),
                            };
                        }
                        else
                        {
                            positionChoices = new Tuple <PopupStyles, Rect>[]
                            {
                                new Tuple <PopupStyles, Rect>(_style, spanRectInScreenCoordinates),
                                new Tuple <PopupStyles, Rect>(_style, spanRectWithBufferInScreenCoordinates),
                                new Tuple <PopupStyles, Rect>(alternateStyle, spanRectInScreenCoordinates),
                                new Tuple <PopupStyles, Rect>(alternateStyle, spanRectWithBufferInScreenCoordinates),
                                new Tuple <PopupStyles, Rect>(_style, reservedRect),
                                new Tuple <PopupStyles, Rect>(alternateStyle, reservedRect),
                            };
                        }
                    }
                    else
                    {
                        positionChoices = new Tuple <PopupStyles, Rect>[]
                        {
                            new Tuple <PopupStyles, Rect>(_style, spanRectInScreenCoordinates),
                            new Tuple <PopupStyles, Rect>(_style, spanRectWithBufferInScreenCoordinates),
                            new Tuple <PopupStyles, Rect>(alternateStyle, spanRectInScreenCoordinates),
                            new Tuple <PopupStyles, Rect>(alternateStyle, spanRectWithBufferInScreenCoordinates),
                        };
                    }

                    Rect location = default;
                    foreach (var choice in positionChoices)
                    {
                        Rect locationToTry = GetLocation(choice.Item1, desiredSize, spanRectInScreenCoordinates, choice.Item2, screenRect);
                        if (DisjointWithPadding(reservedSpace, locationToTry) && ContainsWithPadding(screenRect, locationToTry))
                        {
                            location = locationToTry;
                            _style   = choice.Item1;
                            break;
                        }
                    }

                    // If we couldn't locate a place to live, tell the manager we want to go away.
                    if (location == default)
                    {
                        return(null);
                    }

                    if (!_popup.IsVisible)
                    {
                        this.RegisterForEvents();
                    }

                    _popup.DisplayAt(location.TopLeft);

                    GeometryGroup requestedSpace = new GeometryGroup();
                    requestedSpace.Children.Add(new RectangleGeometry(FromXwtRect(spanRectInScreenCoordinates)));
                    requestedSpace.Children.Add(new RectangleGeometry(FromXwtRect(location)));

                    return(requestedSpace);
                }
            }

            //The text associated with the popup visualSpan is not visible: tell the manager we want to go away.
            return(null);
        }
Beispiel #11
0
 public abstract void DisplayAt(Point point);
Beispiel #12
0
 protected override void OnMouseMoved(MouseMovedEventArgs args)
 {
     var scaledPos = new Xwt.Point(args.X, args.Y);
     GradientButton B = Buttons.FirstOrDefault(X => CheckIfIn(scaledPos, X));
     if (B != null && B != Layout.PrimaryButton && !this.AnimationIsRunning(""))
         Layout.MakePrimary(B);
 }
Beispiel #13
0
 public MaskEntry(Xwt.Point position, MaskEntryType type, int pointerSize)
 {
     this.position = position;
     this.type = type;
     this.pointerSize = pointerSize;
 }