当前位置: 首页>>代码示例>>C#>>正文


C# TextPointer.GetSymbolOffset方法代码示例

本文整理汇总了C#中System.Windows.Documents.TextPointer.GetSymbolOffset方法的典型用法代码示例。如果您正苦于以下问题:C# TextPointer.GetSymbolOffset方法的具体用法?C# TextPointer.GetSymbolOffset怎么用?C# TextPointer.GetSymbolOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Documents.TextPointer的用法示例。


在下文中一共展示了TextPointer.GetSymbolOffset方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:26,代码来源:TextTreeDeleteContentUndoUnit.cs

示例2: Dump

 // Dumps a TextPointer or TextNavigator, including symbol offset.
 internal static void Dump(TextPointer position)
 {
     Debug.WriteLine("Offset: " + position.GetSymbolOffset() + " " + position.ToString());
 }
开发者ID:mind0n,项目名称:hive,代码行数:5,代码来源:TextTreeDumper.cs

示例3: DeleteContentFromSiblingTree

        // Removes nodes from a sibling tree.  containingNode must scope start/end.
        // Returns the combined symbol count of all the removed nodes. 
        private int DeleteContentFromSiblingTree(SplayTreeNode containingNode, TextPointer startPosition, TextPointer endPosition, bool newFirstIMEVisibleNode, out int charCount) 
        {
            SplayTreeNode leftSubTree; 
            SplayTreeNode middleSubTree;
            SplayTreeNode rightSubTree;
            SplayTreeNode rootNode;
            TextTreeNode previousNode; 
            ElementEdge previousEdge;
            TextTreeNode nextNode; 
            ElementEdge nextEdge; 
            int symbolCount;
            int symbolOffset; 

            // Early out in the no-op case. CutContent can't handle an empty content span.
            if (startPosition.CompareTo(endPosition) == 0)
            { 
                if (newFirstIMEVisibleNode)
                { 
                    UpdateContainerSymbolCount(containingNode, /* symbolCount */ 0, /* charCount */ -1); 
                }
                charCount = 0; 
                return 0;
            }

            // Get the symbol offset now before the CutContent call invalidates startPosition. 
            symbolOffset = startPosition.GetSymbolOffset();
 
            // Do the cut.  middleSubTree is what we want to remove. 
            symbolCount = CutContent(startPosition, endPosition, out charCount, out leftSubTree, out middleSubTree, out rightSubTree);
 
            // We need to remember the original previous/next node for the span
            // we're about to drop, so any orphaned positions can find their way
            // back.
            if (middleSubTree != null) 
            {
                if (leftSubTree != null) 
                { 
                    previousNode = (TextTreeNode)leftSubTree.GetMaxSibling();
                    previousEdge = ElementEdge.AfterEnd; 
                }
                else
                {
                    previousNode = (TextTreeNode)containingNode; 
                    previousEdge = ElementEdge.AfterStart;
                } 
                if (rightSubTree != null) 
                {
                    nextNode = (TextTreeNode)rightSubTree.GetMinSibling(); 
                    nextEdge = ElementEdge.BeforeStart;
                }
                else
                { 
                    nextNode = (TextTreeNode)containingNode;
                    nextEdge = ElementEdge.BeforeEnd; 
                } 

                // Increment previous/nextNode reference counts. This may involve 
                // splitting a text node, so we use refs.
                AdjustRefCountsForContentDelete(ref previousNode, previousEdge, ref nextNode, nextEdge, (TextTreeNode)middleSubTree);

                // Make sure left/rightSubTree stay local roots, we might 
                // have inserted new elements in the AdjustRefCountsForContentDelete call.
                if (leftSubTree != null) 
                { 
                    leftSubTree.Splay();
                } 
                if (rightSubTree != null)
                {
                    rightSubTree.Splay();
                } 
                // Similarly, middleSubtree might not be a local root any more,
                // so splay it too. 
                middleSubTree.Splay(); 

                // Note TextContainer now has no references to middleSubTree, if there are 
                // no orphaned positions this allocation won't be kept around.
                Invariant.Assert(middleSubTree.ParentNode == null, "Assigning fixup node to parented child!");
                middleSubTree.ParentNode = new TextTreeFixupNode(previousNode, previousEdge, nextNode, nextEdge);
            } 

            // Put left/right sub trees back into the TextContainer. 
            rootNode = TextTreeNode.Join(leftSubTree, rightSubTree); 
            containingNode.ContainedNode = rootNode;
            if (rootNode != null) 
            {
                rootNode.ParentNode = containingNode;
            }
 
            if (symbolCount > 0)
            { 
                int nextNodeCharDelta = 0; 
                if (newFirstIMEVisibleNode)
                { 
                    // The following node is the new first ime visible sibling.
                    // It just moved, and loses an edge character.
                    nextNodeCharDelta = -1;
                } 

//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:TextContainer.cs

示例4: IsAtCaretUnitBoundary

        // Wrapper for this.TextView.IsAtCaretUnitBoundary, adds a cache. 
        internal bool IsAtCaretUnitBoundary(TextPointer position)
        { 
            position.DebugAssertGeneration();
            Invariant.Assert(position.HasValidLayout);

            if (_rootNode.CaretUnitBoundaryCacheOffset != position.GetSymbolOffset()) 
            {
                _rootNode.CaretUnitBoundaryCacheOffset = position.GetSymbolOffset(); 
                _rootNode.CaretUnitBoundaryCache = _textview.IsAtCaretUnitBoundary(position); 

                if (!_rootNode.CaretUnitBoundaryCache && position.LogicalDirection == LogicalDirection.Backward) 
                {
                    // In MIL Text and TextView worlds, a position at trailing edge of a newline (with backward gravity)
                    // is not an allowed caret stop.
                    // However, in TextPointer world we must allow such a position to be a valid insertion position, 
                    // since it breaks textrange normalization for empty ranges.
                    // Hence, we need to check for TextView.IsAtCaretUnitBoundary in reverse direction here. 
 
                    TextPointer positionForwardGravity = position.GetPositionAtOffset(0, LogicalDirection.Forward);
                    _rootNode.CaretUnitBoundaryCache = _textview.IsAtCaretUnitBoundary(positionForwardGravity); 
                }
            }

            return _rootNode.CaretUnitBoundaryCache; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:26,代码来源:TextContainer.cs

示例5: GetOffsetToPosition

        /// <summary>
        /// Returns the distance between this TextPointer and another.
        /// </summary>
        /// <param name="position">
        /// TextPointer to compare.
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// Throws an ArgumentException if the TextPointer position is not
        /// positioned within the same document as this TextPointer.
        /// </exception>
        /// <returns>
        /// <para>The return value will be negative if the TextPointer position
        /// preceeds this TextPointer, zero if the two TextPointers
        /// are equally positioned, or positive if position follows this
        /// TextPointer.</para>
        /// </returns>
        /// <remarks>
        /// <para>The distance is represented as a number of "symbols"
        /// between these two pointers.</para>
        /// <para>Each opening and each closing tag of any TextElement
        /// is considered as one symbol. So an empty TextElement contributes
        /// two symbols - one for each of tags.</para>
        /// <para>UIElement placed within InlineUIContainer or BlockUIContainer
        /// represented as one symbol - independently of how complex
        /// is its content. Even if the UIElement contains or is a
        /// text container it is treated as atomic entity - single symbol.
        /// This may be confusing especially if you do not pay
        /// muchy attention to a difference between the <see cref="TextElement"/>
        /// the <see cref="UIElement"/> class.</para>
        /// <para>Each 16-bit unicode character inside a <see cref="Run"/> element
        /// is considered as one symbol.</para>
        /// <para>For instance, for the following xaml:
        /// &lt;Run&gt;abc&lt;/Run&gt;&lt;InlineUIContainer&gt;&lt;Button&gt;OK&lt;/Button&gt;&lt;/InlineUIContainer&gt;
        /// the offset from itw content start to content end will be 8 -
        /// one for each of: (1) Run start, (2) "a", (3) "b", (4) "c", (5) Run end, (6) InlineUIContainer start,
        /// (7) whole Button element, (8) InlineUIContainer end. Note that <c>Button</c>
        /// element considered as one symbol even though it is represented
        /// by two tags and two characters.</para>
        /// </remarks>
        /// <example>
        /// <para>In this example we show how to use TextPointer offsets for
        /// persisting positional information. Assuming that the content of
        /// a RichTextBox is not changed between calls of
        /// GetPersistedSelection and RestoreSelectionFromPersistedRange
        /// methods, the selection will be restored to its original state.</para>
        /// <code>
        ///     struct PersistedTextRange { int Start; int End; }
        ///
        ///     PersistedTextRange GetPersistedSelection(RichTextBox richTextBox)
        ///     {
        ///         PersistedTextRange persistedSelection;
        ///
        ///         TextPointer contentStart = richTextBox.Document.ContentStart;
        ///         persistedSelection.Start = contentStart.GetOffsetToPosition(richTextBox.Selection.Start);
        ///         persistedSelection.End = contentStart.GetOffsetToPosition(richTextBox.Selection.End);
        ///
        ///         return persistedSelection;
        ///     }
        ///
        ///     RestoreSelectionFromPersistedRange(RichTextBox richTextBox, PersistedTextRange persistedRange)
        ///     {
        ///         TextPointer contentStart = richTextBox.Document.ContentStart;
        ///
        ///         richTextBox.Selection.Select(
        ///             contentStart.GetPositionAtOffset(persistedRange.Start),
        ///             contentStart.GetPositionAtOffset(persistedRange.End));
        ///     }
        ///
        /// </code>
        /// </example>
        public int GetOffsetToPosition(TextPointer position)
        {
            _tree.EmptyDeadPositionList();

            ValidationHelper.VerifyPosition(_tree, position);

            SyncToTreeGeneration();
            position.SyncToTreeGeneration();

            return (position.GetSymbolOffset() - GetSymbolOffset());
        }
开发者ID:mind0n,项目名称:hive,代码行数:81,代码来源:TextPointer.cs

示例6: CompareTo

        /// <summary>
        /// Compares positions of this TextPointer with another TextPointer.
        /// </summary>
        /// <param name="position">
        /// The TextPointer to compare with.
        /// </param>
        /// <returns>
        /// Less than zero: this TextPointer preceeds position.
        /// Zero: this TextPointer is at the same location as position.
        /// Greater than zero: this TextPointer follows position.
        /// </returns>
        /// <exception cref="System.ArgumentException">
        /// Throws ArgumentException if position does not belong to the same
        /// text container as this TextPointer (you can use <see cref="TextPointer.IsInSameDocument"/>
        /// method to detect whether comparison is possible).
        /// </exception>
        public int CompareTo(TextPointer position)
        {
            int offsetThis;
            int offsetPosition;
            int result;

            _tree.EmptyDeadPositionList();

            ValidationHelper.VerifyPosition(_tree, position);

            SyncToTreeGeneration();
            position.SyncToTreeGeneration();

            offsetThis = GetSymbolOffset();
            offsetPosition = position.GetSymbolOffset();

            if (offsetThis < offsetPosition)
            {
                result = -1;
            }
            else if (offsetThis > offsetPosition)
            {
                result = +1;
            }
            else
            {
                result = 0;
            }

            return result;
        }
开发者ID:mind0n,项目名称:hive,代码行数:47,代码来源:TextPointer.cs

示例7: InitializeOffset

        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // Called by the TextPointer ctor.  Initializes this instance.
        private void InitializeOffset(TextPointer position, int distance, LogicalDirection direction)
        {
            SplayTreeNode node;
            ElementEdge edge;
            int offset;
            bool isCaretUnitBoundaryCacheValid;

            // We MUST [....] to the current tree, otherwise we could addref
            // an orphaned node, resulting in a future unmatched release...
            // Ref counts on orphaned nodes are only considered at the time
            // of removal, not afterwards.
            position.SyncToTreeGeneration();

            if (distance != 0)
            {
                offset = position.GetSymbolOffset() + distance;
                if (offset < 1 || offset > position.TextContainer.InternalSymbolCount - 1)
                {
                    throw new ArgumentException(SR.Get(SRID.BadDistance));
                }

                position.TextContainer.GetNodeAndEdgeAtOffset(offset, out node, out edge);

                isCaretUnitBoundaryCacheValid = false;
            }
            else
            {
                node = position.Node;
                edge = position.Edge;
                isCaretUnitBoundaryCacheValid = position.IsCaretUnitBoundaryCacheValid;
            }

            Initialize(position.TextContainer, (TextTreeNode)node, edge, direction, position.TextContainer.PositionGeneration,
                position.CaretUnitBoundaryCache, isCaretUnitBoundaryCacheValid, position._layoutGeneration);
        }
开发者ID:mind0n,项目名称:hive,代码行数:44,代码来源:TextPointer.cs


注:本文中的System.Windows.Documents.TextPointer.GetSymbolOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。