本文整理汇总了C#中ITextPointer.GetNextContextPosition方法的典型用法代码示例。如果您正苦于以下问题:C# ITextPointer.GetNextContextPosition方法的具体用法?C# ITextPointer.GetNextContextPosition怎么用?C# ITextPointer.GetNextContextPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextPointer
的用法示例。
在下文中一共展示了ITextPointer.GetNextContextPosition方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveSelectionByMouse
//......................................................
//
// Selection Building With Mouse
//
//......................................................
// Moves the selection to the mouse cursor position.
// If the cursor is facing a UIElement, select the UIElement.
// Sets new selection anchor to a given cursorPosition.
private void MoveSelectionByMouse(ITextPointer cursorPosition, Point cursorMousePoint)
{
ITextSelection thisSelection = (ITextSelection)this;
if (this.TextView == null)
{
return;
}
Invariant.Assert(this.TextView.IsValid); // We just checked RenderScope. We'll use TextView below
ITextPointer movingPosition = null;
if (cursorPosition.GetPointerContext(cursorPosition.LogicalDirection) == TextPointerContext.EmbeddedElement)
{
Rect objectEdgeRect = this.TextView.GetRectangleFromTextPosition(cursorPosition);
// Check for embedded object.
// If the click happend inside of it we need to select it as a whole, when content is not read-only.
if (!_textEditor.IsReadOnly && ShouldSelectEmbeddedObject(cursorPosition, cursorMousePoint, objectEdgeRect))
{
movingPosition = cursorPosition.GetNextContextPosition(cursorPosition.LogicalDirection);
}
}
// Move selection to this position
if (movingPosition == null)
{
thisSelection.SetCaretToPosition(cursorPosition, cursorPosition.LogicalDirection, /*allowStopAtLineEnd:*/true, /*allowStopNearSpace:*/false);
}
else
{
thisSelection.Select(cursorPosition, movingPosition);
}
}
示例2: WriteXamlTextSegment
// -------------------------------------------------------------
//
// Private Methods
//
// -------------------------------------------------------------
#region Private Methods
// .............................................................
//
// Serialization
//
// .............................................................
/// <summary>
/// This function serializes text segment formed by rangeStart and rangeEnd to valid xml using xmlWriter.
/// </summary>
/// <SecurityNote>
/// To mask the security exception from XamlWriter.Save in partial trust case,
/// this function checks if the current call stack has the all clipboard permission.
/// </SecurityNote>
private static void WriteXamlTextSegment(XmlWriter xmlWriter, ITextPointer rangeStart, ITextPointer rangeEnd, XamlTypeMapper xamlTypeMapper, ref int elementLevel, WpfPayload wpfPayload, bool ignoreWriteHyperlinkEnd, List<int> ignoreList, bool preserveTextElements)
{
// Special case for pure text selection - we need a Run wrapper for it.
if (elementLevel == EmptyDocumentDepth && typeof(Run).IsAssignableFrom(rangeStart.ParentType))
{
elementLevel++;
xmlWriter.WriteStartElement(typeof(Run).Name);
}
// Create text navigator for reading the range's content
ITextPointer textReader = rangeStart.CreatePointer();
// Exclude last opening tag from serialization - we don't need to create extra element
// is cases when we have whole paragraphs/cells selected.
// NOTE: We do this slightly differently than in TextRangeEdit.AdjustRangeEnd, where we use normalization for adjusted position.
// In this case normalized position does not work, because we need to keep information about crossed paragraph boundary.
while (rangeEnd.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
{
rangeEnd = rangeEnd.GetNextContextPosition(LogicalDirection.Backward);
}
// Write the range internal contents
while (textReader.CompareTo(rangeEnd) < 0)
{
TextPointerContext runType = textReader.GetPointerContext(LogicalDirection.Forward);
switch (runType)
{
case TextPointerContext.ElementStart:
TextElement nextElement = (TextElement)textReader.GetAdjacentElement(LogicalDirection.Forward);
if (nextElement is Hyperlink)
{
// Don't write Hyperlink start element if Hyperlink is invalid
// in case of having a UiElement except Image or stated the range end
// position before the end position of the Hyperlink.
if (IsHyperlinkInvalid(textReader, rangeEnd))
{
ignoreWriteHyperlinkEnd = true;
textReader.MoveToNextContextPosition(LogicalDirection.Forward);
continue;
}
}
else if (nextElement != null)
{
//
TextElementEditingBehaviorAttribute att = (TextElementEditingBehaviorAttribute)Attribute.GetCustomAttribute(nextElement.GetType(), typeof(TextElementEditingBehaviorAttribute));
if (att != null && !att.IsTypographicOnly)
{
if (IsPartialNonTypographic(textReader, rangeEnd))
{
// Add pointer to ignore list
ITextPointer ptr = textReader.CreatePointer();
ptr.MoveToElementEdge(ElementEdge.BeforeEnd);
ignoreList.Add(ptr.Offset);
textReader.MoveToNextContextPosition(LogicalDirection.Forward);
continue;
}
}
}
elementLevel++;
textReader.MoveToNextContextPosition(LogicalDirection.Forward);
WriteStartXamlElement(/*range:*/null, textReader, xmlWriter, xamlTypeMapper, /*reduceElement:*/wpfPayload == null, preserveTextElements);
break;
case TextPointerContext.ElementEnd:
// Don't write Hyperlink end element if Hyperlink include the invalid
// in case of having a UiElement except Image or stated the range end
// before the end position of the Hyperlink or Hyperlink opening tag is
// skipped from WriteOpeningTags by selecting of the partial of Hyperlink.
if (ignoreWriteHyperlinkEnd && (textReader.GetAdjacentElement(LogicalDirection.Forward) is Hyperlink))
{
// Reset the flag to keep walk up the next Hyperlink tag
//.........这里部分代码省略.........
示例3: IsAtParagraphOrBlockUIContainerStart
// Returns true if pointer is at the start of a paragraph.
internal static bool IsAtParagraphOrBlockUIContainerStart(ITextPointer pointer)
{
// Is pointer at a potential paragraph position?
if (IsAtPotentialParagraphPosition(pointer))
{
return true;
}
// Can you find a <Paragraph> start tag looking backwards?
// Loop to skip multiple formatting opening tags, never crossing parent element boundary.
while (pointer.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
{
if (TextSchema.IsParagraphOrBlockUIContainer(pointer.ParentType))
{
return true;
}
pointer = pointer.GetNextContextPosition(LogicalDirection.Backward);
}
return false;
}
示例4: RestrictWithinBlock
private static ITextPointer RestrictWithinBlock(ITextPointer position, ITextPointer limit, LogicalDirection direction)
{
Invariant.Assert(!(direction == LogicalDirection.Backward) || position.CompareTo(limit) >= 0, "for backward direction position must be >= than limit");
Invariant.Assert(!(direction == LogicalDirection.Forward) || position.CompareTo(limit) <= 0, "for forward direcion position must be <= than linit");
while (direction == LogicalDirection.Backward ? position.CompareTo(limit) > 0 : position.CompareTo(limit) < 0)
{
TextPointerContext context = position.GetPointerContext(direction);
if (context == TextPointerContext.ElementStart || context == TextPointerContext.ElementEnd)
{
Type elementType = position.GetElementType(direction);
if (!typeof(Inline).IsAssignableFrom(elementType))
{
limit = position;
break;
}
}
else if (context == TextPointerContext.EmbeddedElement)
{
limit = position;
break;
}
position = position.GetNextContextPosition(direction);
}
// Return normalized position - in the direction towards a center position.
return limit.GetInsertionPosition(direction == LogicalDirection.Backward ? LogicalDirection.Forward : LogicalDirection.Backward);
}
示例5: IsNextToRichBreak
// Returns true if the position is adjacent to a LineBreak or Paragraph element,
// ignoring any intermediate formatting elements.
//
// If lineBreakType is null, any line break element is considered valid.
private static bool IsNextToRichBreak(ITextPointer thisPosition, LogicalDirection direction, Type lineBreakType)
{
Invariant.Assert(lineBreakType == null || lineBreakType == typeof(LineBreak) || lineBreakType == typeof(Paragraph));
bool result = false;
while (true)
{
Type neighbor = thisPosition.GetElementType(direction);
if (lineBreakType == null)
{
if (typeof(LineBreak).IsAssignableFrom(neighbor) ||
typeof(Paragraph).IsAssignableFrom(neighbor))
{
result = true;
break;
}
}
else if (lineBreakType.IsAssignableFrom(neighbor))
{
result = true;
break;
}
if (!TextSchema.IsFormattingType(neighbor))
break;
thisPosition = thisPosition.GetNextContextPosition(direction);
}
return result;
}
示例6: GetContentPosition
// Returns a position ajacent to the supplied position, skipping any
// intermediate Inlines.
// This is useful for sliding inside the context of adjacent Hyperlinks,
// Spans, etc.
private static ITextPointer GetContentPosition(ITextPointer position)
{
while (position.GetAdjacentElement(LogicalDirection.Forward) is Inline)
{
position = position.GetNextContextPosition(LogicalDirection.Forward);
}
return position;
}
示例7: IsAtListItemStart
// Tests if the position is at the beginning of some list item -
// to allow Backspace to delete the bullet.
private static bool IsAtListItemStart(ITextPointer position)
{
// Check for empty ListItem case
if (typeof(ListItem).IsAssignableFrom(position.ParentType) &&
position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart &&
position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd)
{
return true;
}
while (position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
{
Type parentType = position.ParentType;
if (TextSchema.IsBlock(parentType))
{
if (TextSchema.IsParagraphOrBlockUIContainer(parentType))
{
position = position.GetNextContextPosition(LogicalDirection.Backward);
if (position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart &&
typeof(ListItem).IsAssignableFrom(position.ParentType))
{
return true;
}
}
return false;
}
position = position.GetNextContextPosition(LogicalDirection.Backward);
}
return false;
}