示例#1
0
        protected virtual TextPosition NavigateToLine(
            KeyEventArgs keys,
            TextPosition position)
        {
            Keys keyCode = keys.KeyCode;
            TextBoxViewElement            viewElement = this.textBoxElement.ViewElement;
            ReadOnlyCollection <LineInfo> lines       = (ReadOnlyCollection <LineInfo>)viewElement.Lines;
            LineInfo line = position.Line;
            int      num  = lines.IndexOf(line);

            if (keyCode == Keys.Up && num > 0)
            {
                line = lines[num - 1];
            }
            else if (keyCode == Keys.Down && num < lines.Count - 1)
            {
                line = lines[num + 1];
            }
            if (position.Line == line)
            {
                return(position);
            }
            float x = viewElement.GetLocation(position).X + viewElement.ScrollOffset.Width;

            return(this.GetTextPositionFromLine(line, x));
        }
        protected virtual RectangleF GetRectangle(LineInfo currentLine)
        {
            TextBoxViewElement viewElement       = this.textBoxElement.ViewElement;
            RectangleF         boundingRectangle = currentLine.ControlBoundingRectangle;
            PointF             absolute1         = viewElement.PointToAbsolute(boundingRectangle.Location);
            ITextBlock         textBlock         = currentLine.StartBlock;
            ITextBlock         endBlock          = currentLine.EndBlock;

            while (TextBoxWrapPanel.IsWhitespace(textBlock.Text))
            {
                ITextBlock nextBlock = this.TextBoxElement.ViewElement.GetNextBlock(textBlock.Index);
                if (nextBlock != null)
                {
                    textBlock   = nextBlock;
                    absolute1.Y = viewElement.PointToAbsolute((PointF)textBlock.ControlBoundingRectangle.Location).Y;
                }
                else
                {
                    break;
                }
            }
            PointF location  = (PointF)textBlock.ControlBoundingRectangle.Location;
            PointF absolute2 = viewElement.PointToAbsolute(location);
            PointF pointF    = new PointF((float)endBlock.ControlBoundingRectangle.Right, (float)endBlock.ControlBoundingRectangle.Y);

            pointF                     = viewElement.PointToAbsolute(pointF);
            absolute1.X                = absolute2.X;
            boundingRectangle.Width    = pointF.X - boundingRectangle.X;
            boundingRectangle.Location = absolute1;
            return(boundingRectangle);
        }
        public virtual void Invalidate(
            TextPosition selectionStart,
            TextPosition selectionEnd,
            bool repaint)
        {
            this.selectionPolygons = (RectangleF[])null;
            TextBoxViewElement viewElement = this.textBoxElement.ViewElement;

            if (object.Equals((object)selectionStart, (object)selectionEnd) || selectionEnd == (TextPosition)null)
            {
                viewElement.Invalidate();
            }
            else
            {
                TextPosition.Swap(ref selectionStart, ref selectionEnd);
                LineInfo line1 = selectionStart.Line;
                LineInfo line2 = selectionEnd.Line;
                ReadOnlyCollection <LineInfo> lines = (ReadOnlyCollection <LineInfo>)viewElement.Lines;
                int index       = lines.IndexOf(line1);
                int lineSpacing = viewElement.LineSpacing;
                List <RectangleF> rectangleFList = new List <RectangleF>();
                for (; index < lines.Count; ++index)
                {
                    LineInfo   currentLine = lines[index];
                    RectangleF rectangle   = this.GetRectangle(currentLine);
                    if (currentLine == line1)
                    {
                        PointF location = viewElement.GetLocation(selectionStart);
                        rectangle.Width += rectangle.X - location.X;
                        rectangle.X      = location.X;
                    }
                    if (currentLine == line2)
                    {
                        PointF location = viewElement.GetLocation(selectionEnd);
                        rectangle.Width = location.X - rectangle.X;
                    }
                    if (currentLine != line1)
                    {
                        rectangle.Y      -= (float)lineSpacing;
                        rectangle.Height += (float)lineSpacing;
                    }
                    rectangleFList.Add(rectangle);
                    if (currentLine == line2)
                    {
                        break;
                    }
                }
                this.selectionPolygons = rectangleFList.ToArray();
                if (!repaint)
                {
                    return;
                }
                viewElement.Invalidate();
            }
        }
示例#4
0
        public TextBoxNavigator(RadTextBoxControlElement textBoxElement)
        {
            this.textBoxElement = textBoxElement;
            this.selectionStart = (TextPosition)null;
            this.selectionEnd   = (TextPosition)null;
            TextBoxViewElement viewElement = this.textBoxElement.ViewElement;

            viewElement.VScroller.ScrollerUpdated += new EventHandler(this.OnScrollerUpdated);
            viewElement.HScroller.ScrollerUpdated += new EventHandler(this.OnScrollerUpdated);
            viewElement.TextChanged += new EventHandler(this.OnViewElementTextChanged);
            this.textBoxElement.RadPropertyChanged += new RadPropertyChangedEventHandler(this.OnTextBoxElementRadPropertyChanged);
        }
        protected virtual void OnRemoveButtonClick()
        {
            TextBoxViewElement parent = this.Parent as TextBoxViewElement;

            if (parent == null)
            {
                return;
            }
            parent.BeginEditUpdate();
            parent.Children.Remove((RadElement)this);
            parent.UpdateLayout();
            parent.EndEditUpdate(true, string.Empty, this.offset, TextBoxChangeAction.TextEdit);
        }
示例#6
0
        protected virtual void Dispose(bool disposing)
        {
            TextBoxViewElement viewElement = this.textBoxElement.ViewElement;

            if (viewElement.VScroller != null)
            {
                viewElement.VScroller.ScrollerUpdated -= new EventHandler(this.OnScrollerUpdated);
            }
            if (viewElement.HScroller != null)
            {
                viewElement.HScroller.ScrollerUpdated -= new EventHandler(this.OnScrollerUpdated);
            }
            viewElement.TextChanged -= new EventHandler(this.OnViewElementTextChanged);
            this.textBoxElement.RadPropertyChanged -= new RadPropertyChangedEventHandler(this.OnTextBoxElementRadPropertyChanged);
        }
示例#7
0
        protected virtual TextPosition GetEditablePosition(TextPosition position, bool next)
        {
            if (position == (TextPosition)null)
            {
                return((TextPosition)null);
            }
            TextBoxViewElement viewElement = this.TextBoxElement.ViewElement;
            ITextBlock         textBlock1  = position.TextBlock;

            if (textBlock1 is TokenizedTextBlockElement)
            {
                if (position.CharPosition == 0 && textBlock1.Index > 0)
                {
                    textBlock1 = viewElement.Children[textBlock1.Index - 1] as ITextBlock;
                }
                else if (position.CharPosition == textBlock1.Length && textBlock1.Index < viewElement.Children.Count - 1)
                {
                    textBlock1 = viewElement.Children[textBlock1.Index + 1] as ITextBlock;
                }
            }
            ITextBlock textBlock2 = textBlock1;
            ITextBlock child;

            for (; textBlock1 is TextBlockElement; textBlock1 = child)
            {
                textBlock2 = textBlock1;
                int index = next ? textBlock1.Index + 1 : textBlock1.Index - 1;
                if (index >= 0 && index < viewElement.Children.Count)
                {
                    child = viewElement.Children[index] as ITextBlock;
                    if (TextBoxWrapPanel.IsLineFeed(child.Text) || TextBoxWrapPanel.IsCarriageReturn(child.Text))
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            if (textBlock2 is TextBlockElement)
            {
                return(new TextPosition(viewElement.Lines.BinarySearchByBlockIndex(textBlock2.Index), textBlock2, next ? textBlock2.Length : 0));
            }
            return(position);
        }
示例#8
0
        private void OnScrollTimerTick(object sender, EventArgs e)
        {
            TextBoxViewElement viewElement       = this.textBoxElement.ViewElement;
            Rectangle          boundingRectangle = viewElement.ControlBoundingRectangle;
            Point point = viewElement.ElementTree == null ? Point.Empty : viewElement.ElementTree.Control.PointToClient(Control.MousePosition);

            if (viewElement.ElementTree == null || boundingRectangle.Contains(point))
            {
                this.scrollTimer.Stop();
            }
            else
            {
                if (this.textBoxElement.Multiline)
                {
                    int num = 0;
                    if (point.Y > boundingRectangle.Bottom)
                    {
                        num = point.Y - boundingRectangle.Bottom;
                    }
                    else if (point.Y < boundingRectangle.Y)
                    {
                        num = point.Y - boundingRectangle.Y;
                    }
                    if (num != 0)
                    {
                        viewElement.VScroller.Value += num;
                        point.Y -= num;
                    }
                }
                int num1 = 0;
                if (point.X < boundingRectangle.X)
                {
                    num1 = point.X - boundingRectangle.X;
                }
                else if (point.X > boundingRectangle.Right)
                {
                    num1 = point.X - boundingRectangle.Right;
                }
                if (num1 != 0)
                {
                    viewElement.HScroller.Value += num1;
                    point.X -= num1;
                }
                this.ProcessMouseSelection(point);
            }
        }
示例#9
0
        private TextPosition GetWordEndPosition(
            LineInfo currentLine,
            ITextBlock currentBlock)
        {
            TextBoxViewElement viewElement = this.textBoxElement.ViewElement;
            bool       flag1 = TextBoxWrapPanel.IsTabOrWhitespace(currentBlock.Text);
            bool       flag2 = false;
            ITextBlock child;

            for (; currentBlock.Index < viewElement.Children.Count - 1; currentBlock = child)
            {
                child = viewElement.Children[currentBlock.Index + 1] as ITextBlock;
                bool flag3 = TextBoxWrapPanel.IsTabOrWhitespace(child.Text);
                bool flag4 = TextBoxWrapPanel.IsCarriageReturn(child.Text);
                bool flag5 = TextBoxWrapPanel.IsLineFeed(child.Text);
                if (!flag4 && !flag5)
                {
                    if (flag1)
                    {
                        if (!flag3)
                        {
                            break;
                        }
                    }
                    else if (!flag2 || flag3)
                    {
                        if (!flag2)
                        {
                            flag2 = flag3;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            currentLine = viewElement.Lines.BinarySearchByBlockIndex(currentBlock.Index);
            return(new TextPosition(currentLine, currentBlock, currentBlock.Length));
        }
示例#10
0
        public virtual void SetCaretPosition()
        {
            if (this.selectionStart == (TextPosition)null)
            {
                return;
            }
            TextBoxControlCaret caret         = this.textBoxElement.Caret;
            TextPosition        caretPosition = this.CaretPosition;
            TextBoxViewElement  viewElement   = this.textBoxElement.ViewElement;
            PointF location     = viewElement.GetLocation(caretPosition);
            SizeF  scrollOffset = viewElement.ScrollOffset;

            location.X  += scrollOffset.Width;
            location.Y  += scrollOffset.Height;
            caret.Height = (int)caretPosition.Line.Size.Height;
            Point point = this.textBoxElement.PointFromControl(Point.Truncate(location));

            caret.Position = point;
        }
示例#11
0
        public virtual TextPosition GetPositionFromOffset(int offset)
        {
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }
            if (offset > this.textBoxElement.TextLength)
            {
                offset = this.textBoxElement.TextLength;
            }
            TextBoxViewElement viewElement = this.textBoxElement.ViewElement;
            LineInfo           line        = viewElement.Lines.BinarySearchByOffset(offset);

            if (line == null)
            {
                return((TextPosition)null);
            }
            ITextBlock textBlock    = viewElement.BinarySearchTextBlockByOffset(line, offset);
            int        charPosition = offset - textBlock.Offset;

            return(new TextPosition(line, textBlock, charPosition));
        }
示例#12
0
        protected virtual TextPosition GetNextPositionCore(TextPosition position)
        {
            TextBoxViewElement viewElement = this.textBoxElement.ViewElement;
            TextPosition       position1   = position;
            LineInfo           line        = position.Line;
            ITextBlock         textBlock   = position.TextBlock;
            int  charPosition1             = position.CharPosition + 1;
            int  index = textBlock.Index + 1;
            int  num   = textBlock.Offset + textBlock.Length + 1;
            bool flag  = false;

            if (charPosition1 <= textBlock.Length)
            {
                position1 = new TextPosition(line, textBlock, charPosition1);
                flag      = TextBoxWrapPanel.IsCarriageReturn(textBlock.Text);
            }
            else if (num <= viewElement.TextLength)
            {
                ITextBlock child = viewElement.Children[index] as ITextBlock;
                int        charPosition2;
                if (index > line.EndBlock.Index)
                {
                    line          = viewElement.Lines.BinarySearchByBlockIndex(index);
                    charPosition2 = 0;
                }
                else
                {
                    charPosition2 = child.Length > 0 ? 1 : 0;
                    flag          = TextBoxWrapPanel.IsCarriageReturn(child.Text) || TextBoxWrapPanel.IsLineFeed(child.Text);
                }
                position1 = new TextPosition(line, child, charPosition2);
            }
            if (!object.Equals((object)position1, (object)position) && flag)
            {
                position1 = this.GetNextPositionCore(position1);
            }
            return(position1);
        }
示例#13
0
        private string GetText()
        {
            int num = this.text != null ? this.text.Length : 0;

            if (num > 0)
            {
                TextBoxViewElement parent = this.Parent as TextBoxViewElement;
                if (parent != null && !parent.Multiline)
                {
                    char ch1 = Application.RenderWithVisualStyles ? '●' : '*';
                    char ch2 = parent.UseSystemPasswordChar ? ch1 : parent.PasswordChar;
                    if (ch2 != char.MinValue)
                    {
                        StringBuilder stringBuilder = new StringBuilder();
                        for (; num > 0; --num)
                        {
                            stringBuilder.Append(ch2);
                        }
                        return(stringBuilder.ToString());
                    }
                }
            }
            return(this.text);
        }
示例#14
0
        protected virtual TextPosition GetPreviousPositionCore(TextPosition position)
        {
            TextPosition position1     = position;
            LineInfo     line          = position.Line;
            int          charPosition1 = position.CharPosition - 1;
            ITextBlock   textBlock     = position.TextBlock;
            int          num           = textBlock.Offset - 1;
            bool         flag          = false;

            if (charPosition1 >= 0)
            {
                position1 = new TextPosition(line, textBlock, charPosition1);
                flag      = TextBoxWrapPanel.IsCarriageReturn(textBlock.Text);
            }
            else if (num >= 0)
            {
                TextBoxViewElement viewElement = this.textBoxElement.ViewElement;
                int        index         = textBlock.Index - 1;
                ITextBlock child         = viewElement.Children[index] as ITextBlock;
                int        charPosition2 = child.Length > 0 ? child.Length - 1 : 0;
                if (index < line.StartBlock.Index)
                {
                    line = viewElement.Lines.BinarySearchByBlockIndex(index);
                }
                else
                {
                    flag = TextBoxWrapPanel.IsLineFeed(child.Text) || TextBoxWrapPanel.IsCarriageReturn(child.Text);
                }
                position1 = new TextPosition(line, child, charPosition2);
            }
            if (!object.Equals((object)position1, (object)position) && flag)
            {
                position1 = this.GetPreviousPositionCore(position1);
            }
            return(position1);
        }