Example #1
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);
     }
 }
        public void DrawTextBlock(ITextBlock textBlock)
        {
            Brush?brush = textBlock.Foreground.ToWpfBrush();

            if (brush == null)
            {
                return;
            }

            var typeface = new Typeface(textBlock.FontFamily.ToWpfFontFamily(),
                                        textBlock.FontStyle.ToWpfFontStyle(),
                                        textBlock.FontWeight.ToWpfFontWeight(),
                                        textBlock.FontStretch.ToWpfFontStretch());

            // Create the initial formatted text string.
            FormattedText formattedText = new FormattedText(
                textBlock.Text,
                CultureInfo.GetCultureInfo("en-us"),  // TODO: Set this appropriately
                textBlock.FlowDirection.ToWpfFlowDirection(),
                typeface,
                textBlock.FontSize, // TODO: Set this appropriately
                brush,
                1.0);               // TODO: Set this appropriately

            _drawingContext !.DrawText(formattedText, new System.Windows.Point(0, 0));
        }
Example #3
0
        protected ITextBlock NotifyCreateTextBlock(ITextBlock block, string text)
        {
            CreateTextBlockEventArgs e = new CreateTextBlockEventArgs(text, block);

            this.OnCreateTextBlock(e);
            return(e.TextBlock);
        }
        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);
        }
Example #5
0
        public string GetTextRange(TextPosition startPosition, TextPosition endPosition)
        {
            if (startPosition == (TextPosition)null)
            {
                throw new ArgumentNullException(nameof(startPosition));
            }
            if (endPosition == (TextPosition)null)
            {
                throw new ArgumentNullException(nameof(endPosition));
            }
            TextPosition.Swap(ref startPosition, ref endPosition);
            StringBuilder stringBuilder = new StringBuilder();
            ITextBlock    textBlock1    = startPosition.TextBlock;
            ITextBlock    textBlock2    = endPosition.TextBlock;

            if (object.Equals((object)textBlock1, (object)textBlock2))
            {
                return(this.GetBlockText(textBlock1, startPosition.CharPosition, endPosition.CharPosition - startPosition.CharPosition));
            }
            stringBuilder.Append(this.GetBlockText(textBlock1, startPosition.CharPosition, textBlock1.Length - startPosition.CharPosition));
            for (int index = textBlock1.Index + 1; index < textBlock2.Index && index < this.Children.Count; ++index)
            {
                ITextBlock child = this.Children[index] as ITextBlock;
                if (child != null)
                {
                    stringBuilder.Append(this.GetBlockText(child, 0, child.Length));
                }
            }
            stringBuilder.Append(this.GetBlockText(textBlock2, 0, endPosition.CharPosition));
            return(stringBuilder.ToString());
        }
Example #6
0
        protected virtual bool SplitBlock(
            LineInfo currentLine,
            SizeF availableSize,
            ref ITextBlock textBlock,
            ref int offset)
        {
            string text1 = textBlock.Text;
            int    num   = TextBoxControlMeasurer.BinarySearchWrapIndex(text1, this.Font, availableSize.Width);

            switch (num)
            {
            case -1:
            case 0:
                return(false);

            default:
                if (num != text1.Length)
                {
                    string str   = text1.Substring(0, num);
                    string text2 = text1.Substring(num);
                    textBlock.Text   = str;
                    textBlock.Offset = offset;
                    offset          += textBlock.Length;
                    int index1 = textBlock.Index;
                    this.MeasureTextBlock(textBlock, availableSize);
                    currentLine.EndBlock = textBlock;
                    this.AddBlockDesiredSize(textBlock.DesiredSize, currentLine);
                    int index2 = index1 + 1;
                    textBlock = this.CreateBlock(text2, TextBoxWrapPanel.TextBlockElementType);
                    this.Children.Insert(index2, textBlock as RadElement);
                    return(true);
                }
                goto case -1;
            }
        }
Example #7
0
        public static string GetTextBlock(this ITextBlock block, Cursor from, Cursor to)
        {
            var fromOffs = block.GetOffset(from);
            var toOffs   = block.GetOffset(to);

            return(block.GetTextBlock(fromOffs, toOffs - fromOffs));
        }
Example #8
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);
        }
Example #9
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);
        }
Example #11
0
        protected virtual TextPosition NavigateAtLine(
            KeyEventArgs keys,
            TextPosition position)
        {
            Keys         keyCode   = keys.KeyCode;
            LineInfo     line      = position.Line;
            TextPosition position1 = position;

            switch (keyCode)
            {
            case Keys.End:
                ITextBlock endBlock = line.EndBlock;
                position1 = new TextPosition(line, endBlock, endBlock.Length);
                break;

            case Keys.Home:
                position1 = new TextPosition(line, line.StartBlock, 0);
                break;

            case Keys.Left:
                position1 = this.GetPreviousPosition(position1);
                break;

            case Keys.Right:
                position1 = this.GetNextPosition(position1);
                break;
            }
            return(position1);
        }
 protected override bool AreSplittedBlock(ITextBlock firstBlock, ITextBlock secondBlock)
 {
     if (firstBlock is TokenizedTextBlockElement || secondBlock is TokenizedTextBlockElement || firstBlock is TextBlockElement && secondBlock is TextBlockElement && firstBlock.Text.EndsWith(this.delimiter.ToString()))
     {
         return(false);
     }
     return(base.AreSplittedBlock(firstBlock, secondBlock));
 }
Example #13
0
        public Size MeasureTextBlock(ITextBlock textBlock)
        {
#if LATER
            FormattedText?formattedText = ToFormattedText(textBlock);
            return(new Size(formattedText.Width, formattedText.Height));
#endif
            return(Size.Default);
        }
        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);
        }
 protected override void MergeAndMeasureBlock(ITextBlock textBlock, SizeF availableSize)
 {
     base.MergeAndMeasureBlock(textBlock, availableSize);
     if (this.tokenFound)
     {
         return;
     }
     this.FindToken(textBlock);
 }
Example #16
0
        public virtual bool ScrollToCaret()
        {
            TextBoxControlCaret caret      = this.TextBoxElement.Caret;
            RadScrollBarElement hscrollBar = this.textBoxElement.HScrollBar;
            RadScrollBarElement vscrollBar = this.textBoxElement.VScrollBar;

            if (caret == null || this.CaretPosition == (TextPosition)null)
            {
                vscrollBar.Value = vscrollBar.Minimum;
                hscrollBar.Value = hscrollBar.Minimum;
                return(false);
            }
            RectangleF boundingRectangle = (RectangleF)caret.ControlBoundingRectangle;
            RectangleF viewportBounds    = (RectangleF)this.TextBoxElement.ViewElement.ViewportBounds;
            float      num1         = 0.0f;
            float      num2         = 0.0f;
            LineInfo   line         = this.CaretPosition.Line;
            ITextBlock textBlock    = this.CaretPosition.TextBlock;
            int        charPosition = this.CaretPosition.CharPosition;

            if (textBlock == line.StartBlock && charPosition == 0)
            {
                num1 = (float)(hscrollBar.Minimum - hscrollBar.Value);
            }
            else if ((double)boundingRectangle.X > (double)viewportBounds.Right || (double)boundingRectangle.X < (double)viewportBounds.Left)
            {
                num1 = boundingRectangle.X - viewportBounds.X - viewportBounds.Width / 2f;
            }
            this.SetScrollBarValue(hscrollBar, hscrollBar.Value + (int)num1);
            if (this.textBoxElement.Multiline)
            {
                if (line == this.textBoxElement.ViewElement.Lines.FirstLine)
                {
                    num2 = (float)(vscrollBar.Minimum - vscrollBar.Value);
                }
                else if (line == this.textBoxElement.ViewElement.Lines.LastLine)
                {
                    int num3 = this.textBoxElement.ViewElement.VScroller.MaxValue - 1;
                    if (num3 != 0)
                    {
                        num2 = (float)(num3 - vscrollBar.Value + 1);
                    }
                }
                else if ((double)boundingRectangle.Top < (double)viewportBounds.Top)
                {
                    num2 = boundingRectangle.Top - viewportBounds.Top;
                }
                else if ((double)boundingRectangle.Bottom > (double)viewportBounds.Bottom)
                {
                    num2 = boundingRectangle.Bottom - viewportBounds.Bottom;
                }
                this.SetScrollBarValue(vscrollBar, vscrollBar.Value + (int)num2);
            }
            return(true);
        }
        public int Compare(LineInfo line, LineInfo nullLine)
        {
            ITextBlock startBlock = line.StartBlock;
            ITextBlock endBlock   = line.EndBlock;

            if (startBlock.Index <= this.blockIndex && this.blockIndex <= endBlock.Index)
            {
                return(0);
            }
            return(this.blockIndex < startBlock.Index ? 1 : -1);
        }
Example #18
0
        public int Compare(LineInfo line, LineInfo nullLine)
        {
            ITextBlock startBlock = line.StartBlock;
            ITextBlock endBlock   = line.EndBlock;

            if (startBlock.Offset <= this.offset && this.offset <= endBlock.Offset + endBlock.Length)
            {
                return(0);
            }
            return(this.offset < startBlock.Offset ? 1 : -1);
        }
Example #19
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)));
        }
Example #20
0
        protected virtual void Detach(ITextBlock textBlock)
        {
            TokenizedTextBlockElement textBlockElement = textBlock as TokenizedTextBlockElement;

            if (textBlockElement == null)
            {
                return;
            }
            textBlockElement.ContentElement.TextChanging += new TextChangingEventHandler(this.OnContentElementTextChanging);
            textBlockElement.Item.PropertyChanged        -= new PropertyChangedEventHandler(this.OnTokenItemPropertyChanged);
        }
Example #21
0
        public override TextPosition GetNextPosition(TextPosition position)
        {
            TextPosition nextPosition = base.GetNextPosition(position);
            ITextBlock   textBlock    = nextPosition.TextBlock;

            if (textBlock is TokenizedTextBlockElement && !this.IsValidCharPosition(nextPosition.CharPosition, textBlock.Length))
            {
                nextPosition.CharPosition = nextPosition.Line == position.Line ? textBlock.Length : 0;
            }
            return(nextPosition);
        }
Example #22
0
        public int Compare(object x, object nullObject)
        {
            ITextBlock textBlock = x as ITextBlock;
            int        offset    = textBlock.Offset;
            int        num       = offset + textBlock.Length;

            if (offset <= this.offset && this.offset <= num)
            {
                return(0);
            }
            return(this.offset < offset ? 1 : -1);
        }
 protected ITextBlock GetTextBlockAtPoint(Point location)
 {
     for (RadElement radElement = this.TextBox.ElementTree.GetElementAtPoint(location, (Predicate <RadElement>)null); radElement != null; radElement = radElement.Parent)
     {
         ITextBlock textBlock = radElement as ITextBlock;
         if (textBlock != null)
         {
             return(textBlock);
         }
     }
     return((ITextBlock)null);
 }
Example #24
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));
 }
        public virtual RectangleF GetRectangleFromCharacterIndex(int index, bool trailEdge)
        {
            ITextBlock textBlock         = (ITextBlock)this;
            RectangleF boundingRectangle = (RectangleF)this.ControlBoundingRectangle;

            if (index == textBlock.Length)
            {
                boundingRectangle.X     = boundingRectangle.Right;
                boundingRectangle.Width = 0.0f;
            }
            return(boundingRectangle);
        }
 protected override bool SplitBlock(
     LineInfo currentLine,
     SizeF availableSize,
     ref ITextBlock textBlock,
     ref int offset)
 {
     if (textBlock is TokenizedTextBlockElement)
     {
         return(false);
     }
     return(base.SplitBlock(currentLine, availableSize, ref textBlock, ref offset));
 }
Example #27
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));
        }
Example #28
0
        protected virtual RadTokenizedTextItem OnRemoveBlock(ITextBlock textBlock)
        {
            TokenizedTextBlockElement textBlockElement  = textBlock as TokenizedTextBlockElement;
            RadTokenizedTextItem      tokenizedTextItem = (RadTokenizedTextItem)null;

            if (textBlockElement != null)
            {
                tokenizedTextItem = textBlockElement.Item;
                this.Items.Remove(tokenizedTextItem);
            }
            this.Detach(textBlock);
            return(tokenizedTextItem);
        }
 protected override void MeasureTextBlockOverride(ITextBlock textBlock, SizeF availableSize)
 {
     if (textBlock is TokenizedTextBlockElement)
     {
         textBlock.Measure(new SizeF(AutoCompleteBoxViewElement.InfinitySize.Width, this.MinLineHeight));
     }
     else
     {
         RadElement radElement = textBlock as RadElement;
         radElement.MaxSize = radElement.MinSize = new Size(0, (int)Math.Round((double)this.MinLineHeight, MidpointRounding.AwayFromZero));
         base.MeasureTextBlockOverride(textBlock, availableSize);
     }
 }
Example #30
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);
        }