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