private void FindToken(ITextBlock textBlock)
        {
            if (this.editedBlock == null)
            {
                return;
            }
            if ((this.editedBlock as RadElement).Parent == null)
            {
                this.editedBlock = textBlock;
            }
            string text  = textBlock.Text;
            bool   flag1 = textBlock is TokenizedTextBlockElement || TextBoxWrapPanel.IsCarriageReturn(text) || TextBoxWrapPanel.IsLineFeed(text);
            bool   flag2 = text.EndsWith(this.delimiter.ToString());

            if (flag1 || flag2)
            {
                if (flag2 && this.editedBlock.Index <= textBlock.Index)
                {
                    this.tokenFound = true;
                }
                else
                {
                    this.editedTokenEnd  = (ITextBlock)null;
                    this.editedTokenText = new StringBuilder();
                    return;
                }
            }
            this.editedTokenEnd = textBlock;
            this.editedTokenText.Append(textBlock.Text);
        }
Ejemplo n.º 2
0
 protected virtual void ReplaceTextRange(
     ITextBlock targetBlock,
     int startCharPosition,
     int endCharPosition,
     string text)
 {
     if (startCharPosition == endCharPosition && string.IsNullOrEmpty(text))
     {
         return;
     }
     if (targetBlock == null)
     {
         this.InsertTextBlocks(0, text, TextBoxWrapPanel.TextBlockElementType);
     }
     else
     {
         bool flag  = string.IsNullOrEmpty(targetBlock.Text) || TextBoxWrapPanel.IsSpecialText(targetBlock.Text);
         int  index = targetBlock.Index;
         if (flag)
         {
             this.ReplaceSpecialTextBlock(targetBlock, startCharPosition, endCharPosition, text);
         }
         else
         {
             this.ReplaceTextBlock(targetBlock, startCharPosition, endCharPosition, text);
         }
         if (!string.IsNullOrEmpty(targetBlock.Text) || !this.Children.Contains(targetBlock as RadElement))
         {
             return;
         }
         this.Children.Remove(targetBlock as RadElement);
     }
 }
Ejemplo n.º 3
0
 protected virtual void ReplaceTextBlock(
     ITextBlock targetBlock,
     int startCharPosition,
     int endCharPosition,
     string text)
 {
     if (string.IsNullOrEmpty(text) && startCharPosition == 0 && endCharPosition == targetBlock.Length)
     {
         this.Children.Remove(targetBlock as RadElement);
     }
     else
     {
         string str   = targetBlock.Text.Substring(0, startCharPosition);
         string text1 = targetBlock.Text.Substring(endCharPosition);
         targetBlock.Text = str;
         if (TextBoxWrapPanel.IsSpecialText(text))
         {
             int num = this.InsertTextBlocks(string.IsNullOrEmpty(str) ? targetBlock.Index : targetBlock.Index + 1, text, TextBoxWrapPanel.TextBlockElementType);
             if (string.IsNullOrEmpty(str))
             {
                 targetBlock.Index = num + 1;
             }
             if (!string.IsNullOrEmpty(str) && !string.IsNullOrEmpty(text1))
             {
                 this.InsertTextBlocks(num + 1, text1, TextBoxWrapPanel.TextBlockElementType);
                 return;
             }
         }
         else
         {
             targetBlock.Text += text;
         }
         targetBlock.Text += text1;
     }
 }
        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);
        }
Ejemplo n.º 5
0
        public virtual TextPosition GetPositionFromPoint(PointF point)
        {
            LineInfoCollection lines     = this.textBoxElement.ViewElement.Lines;
            LineInfo           firstLine = lines.FirstLine;
            LineInfo           lastLine  = lines.LastLine;

            if (firstLine == null || lastLine == null)
            {
                return((TextPosition)null);
            }
            LineInfo line = (double)point.Y > (double)firstLine.ControlBoundingRectangle.Top ? ((double)point.Y < (double)lastLine.ControlBoundingRectangle.Bottom ? lines.BinarySearchByYCoordinate(point.Y) : lastLine) : firstLine;

            if (line == null)
            {
                return((TextPosition)null);
            }
            TextPosition positionFromLine = this.GetTextPositionFromLine(line, point.X);
            ITextBlock   textBlock        = positionFromLine.TextBlock;

            if (TextBoxWrapPanel.IsLineFeed(textBlock.Text) || TextBoxWrapPanel.IsCarriageReturn(textBlock.Text))
            {
                positionFromLine.CharPosition = 0;
            }
            return(positionFromLine);
        }
Ejemplo n.º 6
0
 public static bool IsSpecialText(string text)
 {
     if (!TextBoxWrapPanel.IsWhitespace(text) && !TextBoxWrapPanel.IsTab(text) && (!TextBoxWrapPanel.IsLineFeed(text) && !TextBoxWrapPanel.IsCarriageReturn(text)) && !(text == Environment.NewLine))
     {
         return(TextBoxWrapPanel.ContainsNewLine(text));
     }
     return(true);
 }
Ejemplo n.º 7
0
 public static bool IsTabOrWhitespace(string text)
 {
     if (!TextBoxWrapPanel.IsTab(text))
     {
         return(TextBoxWrapPanel.IsWhitespace(text));
     }
     return(true);
 }
        protected virtual int RemoveEditableBlockRange(
            ITextBlock tailBlock,
            int startCharPosition,
            out string text)
        {
            StringBuilder stringBuilder = new StringBuilder();
            int           index         = tailBlock.Index;
            string        str           = this.delimiter.ToString();

            while (index >= 0)
            {
                ITextBlock child = this.Children[index] as ITextBlock;
                if (child == tailBlock && startCharPosition == 0)
                {
                    --index;
                }
                else
                {
                    string text1 = child.Text;
                    if (child is TokenizedTextBlockElement || TextBoxWrapPanel.IsLineFeed(text1))
                    {
                        ++index;
                        break;
                    }
                    if (!TextBoxWrapPanel.IsCarriageReturn(text1))
                    {
                        bool flag = true;
                        if (child == tailBlock)
                        {
                            child.Text = text1.Substring(startCharPosition);
                            text1      = text1.Substring(0, startCharPosition);
                            flag       = string.IsNullOrEmpty(child.Text);
                        }
                        else if (text1.EndsWith(str))
                        {
                            ++index;
                            break;
                        }
                        if (flag)
                        {
                            this.Children.RemoveAt(index);
                        }
                        stringBuilder.Insert(0, text1);
                        --index;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (index < 0)
            {
                index = 0;
            }
            text = stringBuilder.ToString();
            return(index);
        }
Ejemplo n.º 9
0
        public static TextPosition GetFirstPosition(TextBoxWrapPanel layoutPanel)
        {
            LineInfo firstLine = layoutPanel.Lines.FirstLine;

            if (firstLine == null)
            {
                return((TextPosition)null);
            }
            return(new TextPosition(firstLine, firstLine.StartBlock, 0));
        }
Ejemplo n.º 10
0
        protected virtual bool AreSplittedBlock(ITextBlock firstBlock, ITextBlock secondBlock)
        {
            if (firstBlock == secondBlock || firstBlock == null || secondBlock == null)
            {
                return(false);
            }
            string text1 = firstBlock.Text;
            string text2 = secondBlock.Text;

            return(!TextBoxWrapPanel.IsLineFeed(text1) && !TextBoxWrapPanel.IsLineFeed(text2) && (!TextBoxWrapPanel.IsCarriageReturn(text1) && !TextBoxWrapPanel.IsCarriageReturn(text2)) && (!TextBoxWrapPanel.IsTabOrWhitespace(text1) && !TextBoxWrapPanel.IsTabOrWhitespace(text2)));
        }
Ejemplo n.º 11
0
 protected virtual string GetBlockText(ITextBlock block, int start, int length)
 {
     if (length < 0)
     {
         return(block.Text.Substring(start));
     }
     if (TextBoxWrapPanel.IsLineFeed(block.Text))
     {
         return(block.Text);
     }
     return(block.Text.Substring(start, length));
 }
Ejemplo n.º 12
0
        public static TextPosition GetLastPosition(TextBoxWrapPanel layoutPanel)
        {
            LineInfo lastLine = layoutPanel.Lines.LastLine;

            if (lastLine == null)
            {
                return((TextPosition)null);
            }
            ITextBlock endBlock = lastLine.EndBlock;

            return(new TextPosition(lastLine, endBlock, endBlock.Length));
        }
Ejemplo n.º 13
0
 public static Size MeasureText(string text, Font font)
 {
     using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
     {
         graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
         Size size = TextRenderer.MeasureText((IDeviceContext)graphics, text, font, Size.Empty, TextFormatFlags.NoClipping | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.NoPadding);
         if (TextBoxWrapPanel.IsTab(text))
         {
             size.Width = RadGdiGraphics.GetTextMetric(font).aveCharWidth * 4;
         }
         return(size);
     }
 }
Ejemplo n.º 14
0
        protected override SizeF MeasureOverride(SizeF availableSize)
        {
            Padding clientOffset   = this.GetClientOffset(true);
            SizeF   availableSize1 = new SizeF(availableSize.Width - (float)clientOffset.Horizontal, availableSize.Height - (float)clientOffset.Vertical);

            if (this.Children.Count == 0)
            {
                this.Children.Add(this.CreateBlock(string.Empty, TextBoxWrapPanel.TextBlockElementType) as RadElement);
            }
            SizeF  desiredSize = SizeF.Empty;
            double width       = (double)availableSize1.Width;
            int    num         = -1;
            int    offset      = 0;

            for (int blockIndex = 0; blockIndex < this.Children.Count; ++blockIndex)
            {
                ITextBlock child = this.Children[blockIndex] as ITextBlock;
                child.Index = blockIndex;
                this.MergeAndMeasureBlock(child, availableSize1);
                bool flag = TextBoxWrapPanel.IsLineFeed(child.Text);
                if (flag && num >= 0)
                {
                    ++offset;
                }
                LineInfo line = num == -1 || flag && this.multiline ? this.CreateNewLine(child, ref desiredSize, ref num) : this.GetLineInfo(num);
                if (this.multiline && this.wordWrap)
                {
                    if (!this.MeasureWrap(availableSize1, blockIndex, ref desiredSize, ref num, ref offset))
                    {
                        line = this.GetLineInfo(num);
                    }
                    else
                    {
                        continue;
                    }
                }
                this.AddBlockDesiredSize(child.DesiredSize, line);
                line.EndBlock = child;
                child.Offset  = offset;
                offset       += child.Length;
            }
            this.AddLineDesiredSize(this.GetLineInfo(num), ref desiredSize);
            this.RemoveUnnecessaryLines(num);
            desiredSize.Width  += (float)clientOffset.Horizontal;
            desiredSize.Height += (float)clientOffset.Vertical;
            desiredSize         = this.ClampDesiredSize(desiredSize, availableSize);
            return(desiredSize);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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));
        }
Ejemplo n.º 17
0
        private void ClampSelection()
        {
            ITextBoxNavigator navigator     = this.textBoxElement.Navigator;
            TextPosition      startPosition = navigator.SelectionStart;
            TextPosition      endPosition   = navigator.SelectionEnd;

            if (startPosition == (TextPosition)null || endPosition == (TextPosition)null)
            {
                return;
            }
            bool flag = false;

            TextPosition.Swap(ref startPosition, ref endPosition);
            if (TextBoxWrapPanel.IsLineFeed(startPosition.TextBlock.Text))
            {
                startPosition = navigator.GetNextPosition(startPosition);
                startPosition.CharPosition = 0;
                flag = true;
            }
            if (TextBoxWrapPanel.IsCarriageReturn(endPosition.TextBlock.Text))
            {
                endPosition = navigator.GetPreviousPosition(endPosition);
                endPosition.CharPosition = endPosition.TextBlock.Length;
                flag = true;
            }
            if (!flag)
            {
                return;
            }
            if (navigator.SelectionStart > navigator.SelectionEnd)
            {
                TextPosition textPosition = startPosition;
                startPosition = endPosition;
                endPosition   = textPosition;
            }
            navigator.SuspendNotifications();
            navigator.Select(startPosition, endPosition);
            navigator.ResumeNotifications();
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
        protected virtual SizeF ArrangeWithLeftAlignment(SizeF finalSize)
        {
            RectangleF clientRectangle = this.GetClientRectangle(finalSize);
            float      x = clientRectangle.X;
            float      y = clientRectangle.Y;

            foreach (LineInfo line in (ReadOnlyCollection <LineInfo>) this.lines)
            {
                ITextBlock startBlock = line.StartBlock;
                ITextBlock endBlock   = line.EndBlock;
                int        index      = startBlock.Index;
                if (TextBoxWrapPanel.IsWhitespace(startBlock.Text) && !TextBoxWrapPanel.IsTab(startBlock.Text) && this.lines.IndexOf(line) > 0)
                {
                    ++index;
                }
                for (; index <= endBlock.Index; ++index)
                {
                    RadElement child     = this.Children[index];
                    ITextBlock textBlock = child as ITextBlock;
                    child.InvalidateArrange();
                    PointF location       = new PointF(x, y);
                    SizeF  desiredSize    = textBlock.DesiredSize;
                    float  baselineOffset = this.GetBaselineOffset(line, textBlock);
                    location.Y += (float)Math.Ceiling((double)baselineOffset);
                    textBlock.Arrange(new RectangleF(location, desiredSize));
                    if (textBlock == endBlock)
                    {
                        float width = (float)(endBlock.ControlBoundingRectangle.Right - startBlock.ControlBoundingRectangle.X);
                        line.Size = new SizeF(width, line.Size.Height);
                    }
                    x += desiredSize.Width;
                }
                x  = clientRectangle.X;
                y += line.Size.Height + (float)this.lineSpacing;
            }
            return(finalSize);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        protected virtual ITextBlock RemoveBlockRange(
            ITextBlock startBlock,
            int startCharPosition,
            ITextBlock endBlock,
            int endCharPosition,
            ref int position)
        {
            int index1 = startBlock.Index;

            if (startCharPosition > 0 || TextBoxWrapPanel.IsLineFeed(startBlock.Text))
            {
                if (startCharPosition > 0 && startCharPosition != startBlock.Length)
                {
                    string str = startBlock.Text.Substring(0, startCharPosition);
                    startBlock.Text = str;
                }
                ++index1;
            }
            int index2 = endBlock.Index;

            if (endCharPosition >= 0)
            {
                if (endCharPosition != endBlock.Length)
                {
                    --index2;
                }
                if (endCharPosition < endBlock.Text.Length)
                {
                    string str = endBlock.Text.Substring(endCharPosition);
                    endBlock.Text = str;
                }
            }
            for (int index3 = index2 - index1 + 1; index3 > 0 && this.Children.Count > index1; --index3)
            {
                this.Children.RemoveAt(index1);
            }
            ITextBlock textBlock = (ITextBlock)null;

            if (index1 == 0 && this.Children.Count > 0)
            {
                textBlock       = this.Children[0] as ITextBlock;
                textBlock.Index = 0;
                position        = 0;
            }
            else if (index1 - 1 >= 0 && this.Children.Count > 0)
            {
                int index3 = index1 - 1;
                textBlock       = this.Children[index3] as ITextBlock;
                textBlock.Index = index3;
                position        = textBlock.Length;
            }
            else if (index1 + 1 < this.Children.Count)
            {
                textBlock = this.Children[index1 + 1] as ITextBlock;
                position  = 0;
            }
            else
            {
                position = -1;
            }
            return(textBlock);
        }
Ejemplo n.º 22
0
        public override TextPosition GetPreviousPosition(TextPosition position)
        {
            TextPosition previousPosition = base.GetPreviousPosition(position);
            ITextBlock   textBlock        = previousPosition.TextBlock;

            if (textBlock is TokenizedTextBlockElement && !this.IsValidCharPosition(previousPosition.CharPosition, textBlock.Length))
            {
                int charPosition = previousPosition.CharPosition;
                int num          = previousPosition.Line != position.Line ? textBlock.Length : (position.CharPosition != 1 || !TextBoxWrapPanel.IsCarriageReturn(position.TextBlock.Text) ? 0 : textBlock.Length);
                previousPosition.CharPosition = num;
            }
            return(previousPosition);
        }