本文整理汇总了C#中System.Windows.Documents.TextPointer.GetScopingNode方法的典型用法代码示例。如果您正苦于以下问题:C# TextPointer.GetScopingNode方法的具体用法?C# TextPointer.GetScopingNode怎么用?C# TextPointer.GetScopingNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextPointer
的用法示例。
在下文中一共展示了TextPointer.GetScopingNode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TextTreeDeleteContentUndoUnit
//------------------------------------------------------
//
// Constructors
//
//------------------------------------------------------
#region Constructors
// Creates a new instance.
// start/end span the content to copy into the new undo unit -- they
// should always share the same scoping TextElement.
internal TextTreeDeleteContentUndoUnit(TextContainer tree, TextPointer start, TextPointer end) : base(tree, start.GetSymbolOffset())
{
TextTreeNode node;
TextTreeNode haltNode;
start.DebugAssertGeneration();
end.DebugAssertGeneration();
Invariant.Assert(start.GetScopingNode() == end.GetScopingNode(), "start/end have different scope!");
node = start.GetAdjacentNode(LogicalDirection.Forward);
haltNode = end.GetAdjacentNode(LogicalDirection.Forward);
// Walk the content, copying runs as we go.
_content = CopyContent(node, haltNode);
}
示例2: Reposition
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
#region Public Methods
/// <summary>
/// Extracts this TextElement from its current position, if any, and
/// inserts it at a specified location.
/// </summary>
/// <param name="start">
/// New start position.
/// </param>
/// <param name="end">
/// New end position.
/// </param>
/// <exception cref="System.ArgumentException">
/// Throws an ArgumentException if start and end are not
/// positioned within the same document, or if start is positioned
/// after end, or if start == null but end != null.
/// </exception>
/// <remarks>
/// This method extracts the TextElement from its current position,
/// leaving behind any contained content, before inserting the TextElement
/// at a new location.
///
/// If start is null, end must also be null, and the TextElement will
/// not be inserted into a new document.
/// </remarks>
internal void Reposition(TextPointer start, TextPointer end)
{
TextContainer tree;
if (start != null)
{
ValidationHelper.VerifyPositionPair(start, end);
}
else if (end != null)
{
throw new ArgumentException(SR.Get(SRID.TextElement_UnmatchedEndPointer));
}
if (start != null)
{
// start/end must be equally scoped. But we want to discount
// this TextElement when considering scoping -- it will be
// extracted before the final insert.
SplayTreeNode startNode = start.GetScopingNode();
// Suppress presharp 6506: Parameter 'end' to this public method must be validated.
// We already validated it indirectly above, when calling ValidationHelper.VerifyPositionPair.
#pragma warning suppress 6506
SplayTreeNode endNode = end.GetScopingNode();
if (startNode == _textElementNode)
{
startNode = _textElementNode.GetContainingNode();
}
if (endNode == _textElementNode)
{
endNode = _textElementNode.GetContainingNode();
}
if (startNode != endNode)
{
throw new ArgumentException(SR.Get(SRID.InDifferentScope, "start", "end"));
}
}
if (this.IsInTree)
{
tree = EnsureTextContainer();
if (start == null)
{
//
// Case 0: Extract this element from its tree.
//
tree.BeginChange();
try
{
tree.ExtractElementInternal(this);
}
finally
{
tree.EndChange();
}
}
else
{
// Presharp doesn't understand that by design TextPointer.TextContainer can never be null.
#pragma warning suppress 6506
if (tree == start.TextContainer)
{
//
// Case 1: extract and insert this TextElement within the same tree.
//
//.........这里部分代码省略.........
示例3: CutContent
// Splits a sibling tree into three sub trees -- a tree with content before startPosition,
// a tree with content between startPosition/endPosition, and a tree with content following endPosition.
// Any of the subtrees may be null on exit, if they contain no content (eg, if
// startPosition == endPosition, middleSubTree will be null on exit, and so forth).
//
// All returned roots have null ParentNode pointers -- the caller MUST
// reparent all of them, even if deleting content, to ensure orphaned
// TextPositions can find their way back to the original tree.
//
// Returns the symbol count of middleSubTree -- all the content between startPosition and endPosition.
private int CutContent(TextPointer startPosition, TextPointer endPosition, out int charCount, out SplayTreeNode leftSubTree, out SplayTreeNode middleSubTree, out SplayTreeNode rightSubTree)
{
SplayTreeNode childNode;
int symbolCount;
Invariant.Assert(startPosition.GetScopingNode() == endPosition.GetScopingNode(), "startPosition/endPosition not in same sibling tree!");
Invariant.Assert(startPosition.CompareTo(endPosition) != 0, "CutContent doesn't expect empty span!");
// Get the root of all nodes to the left of the split.
switch (startPosition.Edge)
{
case ElementEdge.BeforeStart:
leftSubTree = startPosition.Node.GetPreviousNode();
break;
case ElementEdge.AfterStart:
leftSubTree = null;
break;
case ElementEdge.BeforeEnd:
default:
Invariant.Assert(false, "Unexpected edge!"); // Should have gone to simple insert case.
leftSubTree = null;
break;
case ElementEdge.AfterEnd:
leftSubTree = startPosition.Node;
break;
}
// Get the root of all nodes to the right of the split.
switch (endPosition.Edge)
{
case ElementEdge.BeforeStart:
rightSubTree = endPosition.Node;
break;
case ElementEdge.AfterStart:
default:
Invariant.Assert(false, "Unexpected edge! (2)"); // Should have gone to simple insert case.
rightSubTree = null;
break;
case ElementEdge.BeforeEnd:
rightSubTree = null;
break;
case ElementEdge.AfterEnd:
rightSubTree = endPosition.Node.GetNextNode();
break;
}
// Get the root of all nodes covered by startPosition/endPosition.
if (rightSubTree == null)
{
if (leftSubTree == null)
{
middleSubTree = startPosition.GetScopingNode().ContainedNode;
}
else
{
middleSubTree = leftSubTree.GetNextNode();
}
}
else
{
middleSubTree = rightSubTree.GetPreviousNode();
if (middleSubTree == leftSubTree)
{
middleSubTree = null;
}
}
// Split the tree into three sub trees matching the roots we've found.
if (leftSubTree != null)
{
leftSubTree.Split();
Invariant.Assert(leftSubTree.Role == SplayTreeNodeRole.LocalRoot);
leftSubTree.ParentNode.ContainedNode = null;
leftSubTree.ParentNode = null;
}
symbolCount = 0;
charCount = 0;
if (middleSubTree != null)
{
if (rightSubTree != null)
{
//.........这里部分代码省略.........
示例4: CutTopLevelLogicalNodes
// Does a deep extract of all top-level TextElements between two positions.
// Returns the combined symbol count of all extracted elements.
// Each extracted element (and its children) are moved into a private tree.
// This insures that outside references to the TextElement can still use
// the TextElements freely, inserting or removing content, etc.
//
// Also calls AddLogicalChild on any top-level UIElements encountered.
private int CutTopLevelLogicalNodes(TextTreeNode containingNode, TextPointer startPosition, TextPointer endPosition, out int charCount)
{
SplayTreeNode node;
SplayTreeNode nextNode;
SplayTreeNode stopNode;
TextTreeTextElementNode elementNode;
TextTreeObjectNode uiElementNode;
char[] elementText;
int symbolCount;
TextContainer tree;
TextPointer newTreeStart;
DependencyObject logicalParent;
object currentLogicalChild;
Invariant.Assert(startPosition.GetScopingNode() == endPosition.GetScopingNode(), "startPosition/endPosition not in same sibling tree!");
node = startPosition.GetAdjacentSiblingNode(LogicalDirection.Forward);
stopNode = endPosition.GetAdjacentSiblingNode(LogicalDirection.Forward);
symbolCount = 0;
charCount = 0;
logicalParent = containingNode.GetLogicalTreeNode();
while (node != stopNode)
{
currentLogicalChild = null;
// Get the next node now, before we extract any TextElementNodes.
nextNode = node.GetNextNode();
elementNode = node as TextTreeTextElementNode;
if (elementNode != null)
{
// Grab the IMECharCount before we modify the node.
// This value depends on the node's current context.
int imeCharCountInOriginalContainer = elementNode.IMECharCount;
// Cut and record the matching symbols.
elementText = TextTreeText.CutText(_rootNode.RootTextBlock, elementNode.GetSymbolOffset(this.Generation), elementNode.SymbolCount);
// Rip the element out of its sibling tree.
// textElementNode.TextElement's TextElementNode will be updated
// with a deep copy of all contained nodes. We need a deep copy
// to ensure the new element/tree has no TextPointer references.
ExtractElementFromSiblingTree(containingNode, elementNode, true /* deep */);
// Assert that the TextElement now points to a new TextElementNode, not the original one.
Invariant.Assert(elementNode.TextElement.TextElementNode != elementNode);
// We want to start referring to the copied node, update elementNode.
elementNode = elementNode.TextElement.TextElementNode;
UpdateContainerSymbolCount(containingNode, -elementNode.SymbolCount, -imeCharCountInOriginalContainer);
NextGeneration(true /* deletedContent */);
// Stick it in a private tree so it's safe for the outside world to play with.
tree = new TextContainer(null, false /* plainTextOnly */);
newTreeStart = tree.Start;
tree.InsertElementToSiblingTree(newTreeStart, newTreeStart, elementNode);
Invariant.Assert(elementText.Length == elementNode.SymbolCount);
tree.UpdateContainerSymbolCount(elementNode.GetContainingNode(), elementNode.SymbolCount, elementNode.IMECharCount);
tree.DemandCreateText();
TextTreeText.InsertText(tree.RootTextBlock, 1 /* symbolOffset */, elementText);
tree.NextGeneration(false /* deletedContent */);
currentLogicalChild = elementNode.TextElement;
// Keep a running total of how many symbols we've removed.
symbolCount += elementNode.SymbolCount;
charCount += imeCharCountInOriginalContainer;
}
else
{
uiElementNode = node as TextTreeObjectNode;
if (uiElementNode != null)
{
currentLogicalChild = uiElementNode.EmbeddedElement;
}
}
// Remove the child from the logical tree
LogicalTreeHelper.RemoveLogicalChild(logicalParent, currentLogicalChild);
node = nextNode;
}
if (symbolCount > 0)
{
startPosition.SyncToTreeGeneration();
endPosition.SyncToTreeGeneration();
}
return symbolCount;
//.........这里部分代码省略.........
示例5: InsertElementToSiblingTreeComplex
// Inserts an element node into a sibling tree. The node is expected to cover existing content.
// Returns the symbol count of all contained nodes the elementNode covers.
private int InsertElementToSiblingTreeComplex(TextPointer startPosition, TextPointer endPosition, TextTreeTextElementNode elementNode,
out int childCharCount)
{
SplayTreeNode containingNode;
SplayTreeNode leftSubTree;
SplayTreeNode middleSubTree;
SplayTreeNode rightSubTree;
int childSymbolCount;
containingNode = startPosition.GetScopingNode();
// Rip out all the nodes the new element node is going to contain.
childSymbolCount = CutContent(startPosition, endPosition, out childCharCount, out leftSubTree, out middleSubTree, out rightSubTree);
// Join left/right trees under elementNode.
TextTreeNode.Join(elementNode, leftSubTree, rightSubTree);
// Reparent middle tree under elementNode.
elementNode.ContainedNode = middleSubTree;
middleSubTree.ParentNode = elementNode;
// Reparent the whole thing under the original container.
containingNode.ContainedNode = elementNode;
elementNode.ParentNode = containingNode;
return childSymbolCount;
}
示例6: DeleteContentInternal
// DeleteContent worker. Removes content from the tree.
internal void DeleteContentInternal(TextPointer startPosition, TextPointer endPosition)
{
TextTreeNode containingNode;
int symbolCount;
int charCount;
TextTreeUndoUnit undoUnit;
TextPointer deletePosition;
startPosition.SyncToTreeGeneration();
endPosition.SyncToTreeGeneration();
if (startPosition.CompareTo(endPosition) == 0)
return;
BeforeAddChange();
undoUnit = TextTreeUndo.CreateDeleteContentUndoUnit(this, startPosition, endPosition);
containingNode = startPosition.GetScopingNode();
// Invalidate any TextElementCollection that depends on the parent.
// Make sure we do that before raising any public events.
TextElementCollectionHelper.MarkDirty(containingNode.GetLogicalTreeNode());
int nextIMEVisibleNodeCharDelta = 0;
TextTreeTextElementNode nextIMEVisibleNode = GetNextIMEVisibleNode(startPosition, endPosition);
if (nextIMEVisibleNode != null)
{
// The node following the delete just became the first sibling.
// This might affect its ime char count.
nextIMEVisibleNodeCharDelta = -nextIMEVisibleNode.IMELeftEdgeCharCount;
nextIMEVisibleNode.IMECharCount += nextIMEVisibleNodeCharDelta;
}
// First cut: remove all top-level TextElements and their chilren.
// We need to put each TextElement in its own tree, so that any outside
// references can still play with the TextElements safely.
symbolCount = CutTopLevelLogicalNodes(containingNode, startPosition, endPosition, out charCount);
// Cut what's left.
int remainingCharCount;
symbolCount += DeleteContentFromSiblingTree(containingNode, startPosition, endPosition, nextIMEVisibleNodeCharDelta != 0, out remainingCharCount);
charCount += remainingCharCount;
Invariant.Assert(symbolCount > 0);
if (undoUnit != null)
{
undoUnit.SetTreeHashCode();
}
// Public tree event.
deletePosition = new TextPointer(startPosition, LogicalDirection.Forward);
AddChange(deletePosition, symbolCount, charCount, PrecursorTextChangeType.ContentRemoved);
if (nextIMEVisibleNodeCharDelta != 0)
{
RaiseEventForNewFirstIMEVisibleNode(nextIMEVisibleNode);
}
}