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); }
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); }
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 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); }
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)); }
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(); }
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); }
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); }
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); }
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))); }
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); }