Ejemplo n.º 1
0
        public double[] GetBoundingRectangles()
#endif
        {
            LineToIndexTable layoutLineCollection = this.textbox.LayoutLineCollection;
            TextPoint        topLeft     = layoutLineCollection.GetTextPointFromIndex(this.start);
            TextPoint        bottomRight = this.textbox.LayoutLineCollection.GetTextPointFromIndex(IsNewLine(this.end) ? this.end - 1 : this.end);


#if METRO || WINDOWS_UWP
            float dpi;
            Util.GetDpi(out dpi, out dpi);
            double scale          = dpi / 96;
            Point  topLeftPos     = this.textbox.GetPostionFromTextPoint(topLeft);
            Point  bottomRightPos = this.textbox.GetPostionFromTextPoint(bottomRight);
            topLeftPos     = Util.GetPointInWindow(topLeftPos.Scale(scale), textbox);
            bottomRightPos = Util.GetPointInWindow(bottomRightPos.Scale(scale), textbox);
#endif
#if WPF
            Point topLeftPos     = this.textbox.GetPostionFromTextPoint(topLeft);
            Point bottomRightPos = this.textbox.GetPostionFromTextPoint(bottomRight);
            topLeftPos     = this.textbox.PointToScreen(topLeftPos);
            bottomRightPos = this.textbox.PointToScreen(bottomRightPos);
#endif

            double width = bottomRightPos.X - topLeftPos.X;
            if (width == 0)
            {
                width = 1;
            }
            Rectangle rect = new Rectangle(topLeftPos.X, topLeftPos.Y,
                                           width,
                                           bottomRightPos.Y - topLeftPos.Y + layoutLineCollection.GetLineHeight(bottomRight));

#if METRO || WINDOWS_UWP
            rectangles = new double[4] {
                rect.X,
                rect.Y,
                rect.Width,
                rect.Height
            };
#endif
#if WPF
            return(new double[4] {
                rect.X,
                rect.Y,
                rect.Width,
                rect.Height
            });
#endif
        }
Ejemplo n.º 2
0
        public int MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count)
        {
            if (count == 0)
            {
                return(0);
            }

            int              moved = 0;
            TextPoint        caret = TextPoint.Null, newCaret = TextPoint.Null;
            Controller       ctrl       = textbox.Controller;
            LineToIndexTable layoutLine = textbox.LayoutLineCollection;

            if (endpoint == TextPatternRangeEndpoint.Start)
            {
                caret = layoutLine.GetTextPointFromIndex(this.start);
            }
            else if (endpoint == TextPatternRangeEndpoint.End)
            {
                caret = layoutLine.GetTextPointFromIndex(this.end);
            }

            switch (unit)
            {
            case TextUnit.Character:
                newCaret = ctrl.GetNextCaret(caret, count, MoveFlow.Character, out moved);
                break;

            case TextUnit.Format:
            case TextUnit.Word:
                newCaret = ctrl.GetNextCaret(caret, count, MoveFlow.Word, out moved);
                break;

            case TextUnit.Line:
                newCaret = ctrl.GetNextCaret(caret, count, MoveFlow.Line, out moved);
                break;

            case TextUnit.Paragraph:
                newCaret = ctrl.GetNextCaret(caret, count, MoveFlow.Paragraph, out moved);
                break;

            case TextUnit.Page:
            case TextUnit.Document:
                this.start = 0;
                this.end   = this.textbox.Document.Length - 1;
                moved      = 1;
                break;
            }

            if (endpoint == TextPatternRangeEndpoint.Start)
            {
                this.start = layoutLine.GetIndexFromTextPoint(newCaret);
                if (this.start > this.end)
                {
                    this.end = this.start;
                }
            }
            else if (endpoint == TextPatternRangeEndpoint.End)
            {
                this.end = layoutLine.GetIndexFromTextPoint(newCaret);
                if (this.end < this.start)
                {
                    this.start = this.end;
                }
            }
            return(moved);
        }