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


C# TextPointer.GetPointerContext方法代码示例

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


在下文中一共展示了TextPointer.GetPointerContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsPositionNextToWordBreak

        // Helper for GetPositionAtWordBoundary.
        // Returns true when passed TextPointer is next to a wordBreak in requested direction.
        private static bool IsPositionNextToWordBreak(TextPointer position, LogicalDirection wordBreakDirection)
        {
            bool isAtWordBoundary = false;

            // Skip over any formatting.
            if (position.GetPointerContext(wordBreakDirection) != TextPointerContext.Text)
            {
                position = position.GetInsertionPosition(wordBreakDirection);
            }

            if (position.GetPointerContext(wordBreakDirection) == TextPointerContext.Text)
            {
                LogicalDirection oppositeDirection = (wordBreakDirection == LogicalDirection.Forward) ?
                    LogicalDirection.Backward : LogicalDirection.Forward;

                char[] runBuffer = new char[1];
                char[] oppositeRunBuffer = new char[1];

                position.GetTextInRun(wordBreakDirection, runBuffer, /*startIndex*/0, /*count*/1);
                position.GetTextInRun(oppositeDirection, oppositeRunBuffer, /*startIndex*/0, /*count*/1);

                if (runBuffer[0] == ' ' && !(oppositeRunBuffer[0] == ' '))
                {
                    isAtWordBoundary = true;
                }
            }
            else
            {
                // If we're not adjacent to text then we always want to consider this position a "word break".
                // In practice, we're most likely next to an embedded object or a block boundary.
                isAtWordBoundary = true;
            }

            return isAtWordBoundary;
        }
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:37,代码来源:WordBreaker.cs

示例2: DoCore

        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        // Called by the undo manager.  Restores tree state to its condition
        // when the unit was created.  Assumes the tree state matches conditions
        // just after the unit was created.
        public override void DoCore()
        {
            TextPointer start;
            TextPointer end;
            TextElement element;

            VerifyTreeContentHashCode();

            start = new TextPointer(this.TextContainer, this.SymbolOffset, LogicalDirection.Forward);

            Invariant.Assert(start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart, "TextTree undo unit out of [....] with TextTree.");

            element = start.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward);

            if (_deep)
            {
                // Extract the element and its content.
                end = new TextPointer(this.TextContainer, element.TextElementNode, ElementEdge.AfterEnd);
                this.TextContainer.DeleteContentInternal(start, end);
            }
            else
            {
                // Just extract the element, not its content.
                this.TextContainer.ExtractElementInternal(element);
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:37,代码来源:TextTreeInsertElementUndoUnit.cs

示例3: GetTextPositionAtOffset

        TextPointer GetTextPositionAtOffset(TextPointer position, int characterCount)
        {
            while (position != null)
            {
                var context = position.GetPointerContext(LogicalDirection.Forward);
                if (context == TextPointerContext.Text)
                {
                    var count = position.GetTextRunLength(LogicalDirection.Forward);
                    if (characterCount <= count)
                    {
                        return position.GetPositionAtOffset(characterCount);
                    }

                    characterCount -= count;
                }
                else if (position.Parent is LineBreak)
                {
                    var count = 2;
                    if (characterCount <= count)
                    {
                        return position.GetPositionAtOffset(characterCount);
                    }

                    characterCount -= count;
                }
                
                var nextContextPosition = position.GetNextContextPosition(LogicalDirection.Forward);
                if (nextContextPosition == null)
                    return position;

                position = nextContextPosition;
            }

            return position;
        }
开发者ID:ElemarJR,项目名称:Jujubas,代码行数:35,代码来源:MainWindow.xaml.cs

示例4: DoCore

        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        // Called by the undo manager.  Restores tree state to its condition
        // when the unit was created.  Assumes the tree state matches conditions
        // just after the unit was created.
        public override void DoCore()
        {
            TextPointer position;

            VerifyTreeContentHashCode();

            position = new TextPointer(this.TextContainer, this.SymbolOffset, LogicalDirection.Forward);

            Invariant.Assert(position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart, "TextTree undo unit out of [....] with TextTree.");

            if (_propertyRecord.Value != DependencyProperty.UnsetValue)
            {
                this.TextContainer.SetValue(position, _propertyRecord.Property, _propertyRecord.Value);
            }
            else
            {
                position.Parent.ClearValue(_propertyRecord.Property);
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:30,代码来源:TextTreePropertyUndoUnit.cs

示例5: FindWordFromPosition

        private static TextRange FindWordFromPosition(TextPointer position, string word)
        {
            while (position != null)
            {
                if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
                {
                    string textRun = position.GetTextInRun(LogicalDirection.Forward);

                    // Find the starting index of any substring that matches "word".
                    int indexInRun = textRun.IndexOf(word);
                    if (indexInRun >= 0)
                    {
                        TextPointer start = position.GetPositionAtOffset(indexInRun);
                        TextPointer end = start.GetPositionAtOffset(word.Length);
                        return new TextRange(start, end);
                    }
                }

                position = position.GetNextContextPosition(LogicalDirection.Forward);
            }

            // position will be null if "word" is not found.
            return null;
        }
开发者ID:diegoRodriguezAguila,项目名称:SGAM.Elfec.Admin,代码行数:24,代码来源:RichTextBoxExtensions.cs

示例6: ValidateMergingPositions

        // Validates that the sibling element at this position belong to expected itemType (Inline, Block, ListItem)
        private static void ValidateMergingPositions(Type itemType, TextPointer start, TextPointer end)
        {
            if (start.CompareTo(end) < 0)
            {
                // Verify inner part
                TextPointerContext forwardFromStart = start.GetPointerContext(LogicalDirection.Forward);
                TextPointerContext backwardFromEnd = end.GetPointerContext(LogicalDirection.Backward);
                Invariant.Assert(forwardFromStart == TextPointerContext.ElementStart, "Expecting first opening tag of pasted fragment");
                Invariant.Assert(backwardFromEnd == TextPointerContext.ElementEnd, "Expecting last closing tag of pasted fragment");
                Invariant.Assert(itemType.IsAssignableFrom(start.GetAdjacentElement(LogicalDirection.Forward).GetType()), "The first pasted fragment item is expected to be a " + itemType.Name);
                Invariant.Assert(itemType.IsAssignableFrom(end.GetAdjacentElement(LogicalDirection.Backward).GetType()), "The last pasted fragment item is expected to be a " + itemType.Name);

                // Veryfy outer part
                TextPointerContext backwardFromStart = start.GetPointerContext(LogicalDirection.Backward);
                TextPointerContext forwardFromEnd = end.GetPointerContext(LogicalDirection.Forward);
                Invariant.Assert(backwardFromStart == TextPointerContext.ElementStart || backwardFromStart == TextPointerContext.ElementEnd || backwardFromStart == TextPointerContext.None, "Bad context preceding a pasted fragment");
                Invariant.Assert(!(backwardFromStart == TextPointerContext.ElementEnd) || itemType.IsAssignableFrom(start.GetAdjacentElement(LogicalDirection.Backward).GetType()), "An element preceding a pasted fragment is expected to be a " + itemType.Name);
                Invariant.Assert(forwardFromEnd == TextPointerContext.ElementStart || forwardFromEnd == TextPointerContext.ElementEnd || forwardFromEnd == TextPointerContext.None, "Bad context following a pasted fragment");
                Invariant.Assert(!(forwardFromEnd == TextPointerContext.ElementStart) || itemType.IsAssignableFrom(end.GetAdjacentElement(LogicalDirection.Forward).GetType()), "An element following a pasted fragment is expected to be a " + itemType.Name);
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:22,代码来源:TextRangeSerialization.cs

示例7: InsertInkAtPosition

        // Inserts an InkInteropObject at a specified position.
        private TextPointer InsertInkAtPosition(TextPointer insertionPosition, InkInteropObject inkobject, out UnsafeNativeMethods.TS_TEXTCHANGE change)
        {
            int symbolsAddedBefore = 0;
            int symbolsAddedAfter = 0;

            // Prepare an insertion position for InlineUIContainer.
            // As an optimization, shift outside of any formatting tags to avoid
            // splitting tags below.
            while (insertionPosition.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart &&
                TextSchema.IsFormattingType(insertionPosition.Parent.GetType()))
            {
                insertionPosition = insertionPosition.GetNextContextPosition(LogicalDirection.Backward);
            }
            while (insertionPosition.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd &&
                TextSchema.IsFormattingType(insertionPosition.Parent.GetType()))
            {
                insertionPosition = insertionPosition.GetNextContextPosition(LogicalDirection.Forward);
            }

            // If we need to, split the current parent TextElement and prepare
            // a suitable home for an InlineUIContainer.
            if (!TextSchema.IsValidParent(insertionPosition.Parent.GetType(), typeof(InlineUIContainer)))
            {
                insertionPosition = TextRangeEditTables.EnsureInsertionPosition(insertionPosition, out symbolsAddedBefore, out symbolsAddedAfter);
                Invariant.Assert(insertionPosition.Parent is Run, "position must be in Run scope");

                insertionPosition = TextRangeEdit.SplitElement(insertionPosition);
                // We need to remember how many symbols were added into addition
                // to the InlineUIContainer itself.
                // Account for the two element edges just added.
                symbolsAddedBefore += 1;
                symbolsAddedAfter += 1;
            }

            // Create an InlineUIContainer.
            InlineUIContainer inlineUIContainer = new InlineUIContainer(inkobject);

            change.start = ((ITextPointer)insertionPosition).Offset - symbolsAddedBefore;
            change.oldEnd = change.start;

            // Insert it into the insertionPosition.  This adds 3 symbols.
            insertionPosition.InsertTextElement(inlineUIContainer);

            change.newEnd = change.start + symbolsAddedBefore + inlineUIContainer.SymbolCount + symbolsAddedAfter;

            // Return a position after the inserted object.
            return inlineUIContainer.ElementEnd.GetInsertionPosition(LogicalDirection.Forward);
        }
开发者ID:mind0n,项目名称:hive,代码行数:49,代码来源:TextStore.cs

示例8: FindElementPosition

        //-------------------------------------------------------------------
        // IContentHost Helpers
        //-------------------------------------------------------------------

        /// <summary>
        /// Searches for an element in the _structuralCache.TextContainer. If the element is found, returns the
        /// position at which it is found. Otherwise returns null.
        /// </summary>
        /// <param name="e">
        /// Element to be found.
        /// </param>
        /// <param name="isLimitedToTextView">
        /// bool value indicating whether the search should only be limited to the text view of the page,
        /// in which case we search only text segments in the text view
        /// </param>
        private TextPointer FindElementPosition(IInputElement e, bool isLimitedToTextView)
        {
            // Parameter validation
            Debug.Assert(e != null);

            // Validate that this function is only called when a TextContainer exists as complex content
            Debug.Assert(_structuralCache.TextContainer is TextContainer);

            TextPointer elementPosition = null;

            // If e is a TextElement we can optimize by checking its TextContainer
            if (e is TextElement)
            {
                if ((e as TextElement).TextContainer == _structuralCache.TextContainer)
                {
                    // Element found
                    elementPosition = new TextPointer((e as TextElement).ElementStart);
                }
                // else: elementPosition stays null
            }
            else
            {
                // Else: search for e in the complex content
                if (!(_structuralCache.TextContainer.Start is TextPointer) ||
                    !(_structuralCache.TextContainer.End is TextPointer))
                {
                    // Invalid TextContainer, don't search
                    return null;
                }

                TextPointer searchPosition = new TextPointer(_structuralCache.TextContainer.Start as TextPointer);
                while (elementPosition == null && ((ITextPointer)searchPosition).CompareTo(_structuralCache.TextContainer.End) < 0)
                {
                    // Search each position in _structuralCache.TextContainer for the element
                    switch (searchPosition.GetPointerContext(LogicalDirection.Forward))
                    {
                        case TextPointerContext.EmbeddedElement:
                            DependencyObject embeddedObject = searchPosition.GetAdjacentElement(LogicalDirection.Forward);
                            if (embeddedObject is ContentElement || embeddedObject is UIElement)
                            {
                                if (embeddedObject == e as ContentElement || embeddedObject == e as UIElement)
                                {
                                    // Element found. Stop searching
                                    elementPosition = new TextPointer(searchPosition);
                                    break;
                                }
                            }
                            break;
                        default:
                            break;
                    }
                    searchPosition.MoveToNextContextPosition(LogicalDirection.Forward);
                }
            }

            // If the element was found, check if we are limited to text view
            if (elementPosition != null)
            {
                if (isLimitedToTextView)
                {
                    // At this point, we should create TextView if it doesn't exist
                    _textView = GetTextView();
                    Invariant.Assert(_textView != null);
                    // Check all segements in text view for position
                    for (int segmentIndex = 0; segmentIndex < ((ITextView)_textView).TextSegments.Count; segmentIndex++)
                    {
                        if (((ITextPointer)elementPosition).CompareTo(((ITextView)_textView).TextSegments[segmentIndex].Start) >= 0 &&
                            ((ITextPointer)elementPosition).CompareTo(((ITextView)_textView).TextSegments[segmentIndex].End) < 0)
                        {
                            // Element lies within a segment. Return position
                            return elementPosition;
                        }
                    }
                    // Element not found in all segments of TextView. Set position to null
                    elementPosition = null;
                }
            }
            return elementPosition;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:94,代码来源:FlowDocumentPage.cs

示例9: UpdateAccessKey

        /// <summary>
        /// UpdateAccessKey - Scans forward in the tree looking for the access key marker, replacing it with access key element. We only support one find.
        /// </summary>
        private void UpdateAccessKey()
        {
            TextPointer navigator = new TextPointer(TextContainer.Start);

            while (!_accessKeyLocated && navigator.CompareTo(TextContainer.End) < 0 )
            {
                TextPointerContext symbolType = navigator.GetPointerContext(LogicalDirection.Forward);
                switch (symbolType)
                {
                    case TextPointerContext.Text:
                        string text = navigator.GetTextInRun(LogicalDirection.Forward);
                        int index = FindAccessKeyMarker(text);
                        if(index != -1 && index < text.Length - 1)
                        {
                            string keyText = StringInfo.GetNextTextElement(text, index + 1);
                            TextPointer keyEnd = navigator.GetPositionAtOffset(index + 1 + keyText.Length);

                            _accessKey = new Run(keyText);
                            _accessKey.Style = AccessKeyStyle;

                            RegisterAccessKey();

                            HasCustomSerializationStorage.SetValue(_accessKey, true);
                            _accessKeyLocated = true;

                            UninitializeTextContainerListener();

                            TextContainer.BeginChange();
                            try
                            {
                                TextPointer underlineStart = new TextPointer(navigator, index);
                                TextRangeEdit.DeleteInlineContent(underlineStart, keyEnd);
                                _accessKey.RepositionWithContent(underlineStart);

                            }
                            finally
                            {
                                TextContainer.EndChange();
                                InitializeTextContainerListener();
                            }
                        }

                        break;
                }
                navigator.MoveToNextContextPosition(LogicalDirection.Forward);
            }

            // Convert double _ to single _
            navigator = new TextPointer(TextContainer.Start);
            string accessKeyMarker = AccessKeyMarker.ToString();
            string doubleAccessKeyMarker = accessKeyMarker + accessKeyMarker;
            while (navigator.CompareTo(TextContainer.End) < 0)
            {
                TextPointerContext symbolType = navigator.GetPointerContext(LogicalDirection.Forward);
                switch (symbolType)
                {
                    case TextPointerContext.Text:
                        string text = navigator.GetTextInRun(LogicalDirection.Forward);
                        string nexText = text.Replace(doubleAccessKeyMarker, accessKeyMarker);
                        if (text != nexText)
                        {
                            TextPointer keyStart = new TextPointer(navigator, 0);
                            TextPointer keyEnd = new TextPointer(navigator, text.Length);

                            UninitializeTextContainerListener();
                            TextContainer.BeginChange();
                            try
                            {
                                keyEnd.InsertTextInRun(nexText);
                                TextRangeEdit.DeleteInlineContent(keyStart, keyEnd);
                            }
                            finally
                            {
                                TextContainer.EndChange();
                                InitializeTextContainerListener();
                            }
                        }

                        break;
                }
                navigator.MoveToNextContextPosition(LogicalDirection.Forward);
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:86,代码来源:AccessText.cs

示例10: MergeLists

        /// <summary>
        /// Merges two naighboring lists ending and starting at position mergePosition
        /// </summary>
        /// <param name="mergePosition">
        /// Position at with two List elements are expected to appear next to each other
        /// </param>
        /// <returns>
        /// true if there were two mergeable List elements and merge happened.
        /// false if there is no pair of List elements at the mergePosition.
        /// </returns>
        internal static bool MergeLists(TextPointer mergePosition)
        {
            if (mergePosition.GetPointerContext(LogicalDirection.Backward) != TextPointerContext.ElementEnd ||
                mergePosition.GetPointerContext(LogicalDirection.Forward) != TextPointerContext.ElementStart)
            {
                return false;
            }

            List precedingList = mergePosition.GetAdjacentElement(LogicalDirection.Backward) as List;
            List followingList = mergePosition.GetAdjacentElement(LogicalDirection.Forward) as List;

            if (precedingList == null || followingList == null)
            {
                return false;
            }

            precedingList.Reposition(precedingList.ContentStart, followingList.ElementEnd);
            followingList.Reposition(null, null);

            // We need to set appropriate FlowDirection property on the new List and its paragraph children. 
            // We take the FlowDirection value from the preceding list.
            TextRangeEdit.SetParagraphProperty(precedingList.ElementStart, precedingList.ElementEnd,
                Paragraph.FlowDirectionProperty, precedingList.GetValue(Paragraph.FlowDirectionProperty));

            return true;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:36,代码来源:TextRangeEditLists.cs

示例11: CreateInsertionPositionInIncompleteContent

        // Helper for EnsureInsertionPosition. 
        // Generates minimally necessary content to ensure at least one insertion position.
        private static TextPointer CreateInsertionPositionInIncompleteContent(TextPointer position) 
        {
            // Go inside the scoped element to its possible lowest level
            while (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart)
            { 
                position = position.GetNextContextPosition(LogicalDirection.Forward);
            } 
            while (position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementEnd) 
            {
                position = position.GetNextContextPosition(LogicalDirection.Backward); 
            }

            DependencyObject parent = position.Parent;
            if (parent != null) 
            {
                if (parent is Table) 
                { 
                    // Creating implicit TableRowGroup
                    TableRowGroup tableRowGroup = new TableRowGroup(); 
                    tableRowGroup.Reposition(position, position);
                    position = tableRowGroup.ContentStart;
                    parent = position.Parent;
                } 

                if (parent is TableRowGroup) 
                { 
                    // Creating implicit TableRow
                    TableRow tableRow = new TableRow(); 
                    tableRow.Reposition(position, position);
                    position = tableRow.ContentStart;
                    parent = position.Parent;
                } 

                if (parent is TableRow) 
                { 
                    // Creating implicit TableCell
                    TableCell tableCell = new TableCell(); 
                    tableCell.Reposition(position, position);
                    position = tableCell.ContentStart;
                    parent = position.Parent;
                } 

                if (parent is List) 
                { 
                    // Creating implicit ListItem
                    ListItem listItem = new ListItem(); 
                    listItem.Reposition(position, position);
                    position = listItem.ContentStart;
                    parent = position.Parent;
                } 

                if (parent is LineBreak || parent is InlineUIContainer) 
                { 
                    position = ((Inline)parent).ElementStart;
                    parent = position.Parent; 
                }
            }

            if (parent == null) 
            {
                // 
 
                throw new InvalidOperationException(SR.Get(SRID.TextSchema_CannotInsertContentInThisPosition));
            } 

            TextPointer insertionPosition;
            if (TextSchema.IsValidChild(/*position:*/position, /*childType:*/typeof(Inline)))
            { 
                insertionPosition = CreateImplicitRun(position);
            } 
            else 
            {
                Invariant.Assert(TextSchema.IsValidChild(/*position:*/position, /*childType:*/typeof(Block)), "Expecting valid parent-child relationship"); 
                insertionPosition = CreateImplicitParagraph(position);
            }

            return insertionPosition; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:80,代码来源:TextRangeEditTables.cs

示例12: EnsureInsertionPosition

        // ....................................................................
        // 
        // Row editing 
        //
        // .................................................................... 

        #region Row Editing

        /// <summary> 
        /// Checks whether the given TextPointer is at row end position, where text insertion is impossible
        /// and returns a following position where text insertion or pasting is valid. 
        /// New paragraphs is creeated at the end of TextContainer if necessary. 
        /// </summary>
        internal static TextPointer EnsureInsertionPosition(TextPointer position) 
        {
            Invariant.Assert(position != null, "null check: position");

            // Normalize the pointer 
            position = position.GetInsertionPosition(position.LogicalDirection);
 
            if (!TextPointerBase.IsAtInsertionPosition(position)) 
            {
                // There is no insertion positions in the whole document at all. 
                // Generate minimally necessary content to ensure at least one insertion position.
                position = CreateInsertionPositionInIncompleteContent(position);
            }
            else 
            {
                // Check if position is at one of special structural boundary positions, where we can potentially have an 
                // insertion position and create one. 

                if (position.IsAtRowEnd) 
                {
                    // Find a next insertion position within the scope of the parent table.
                    Table currentTable = TextRangeEditTables.GetTableFromPosition(position);
                    position = GetAdjustedRowEndPosition(currentTable, position); 

                    if (position.CompareTo(currentTable.ElementEnd) == 0) 
                    { 
                        // The range is at the end of table which is the last block of text container OR
                        // next insertion position crossed table boundary. 
                        // In both cases, we want to insert a paragraph after table end and move our insertion position there.
                        position = CreateImplicitParagraph(currentTable.ElementEnd);
                    }
                } 
                Invariant.Assert(!position.IsAtRowEnd, "position is not expected to be at RowEnd anymore");
 
                // Note that this is not an else if, because our next insertion position (if it is within the same table), 
                // can fall into one of the following cases. We need to handle it.
                if (TextPointerBase.IsInBlockUIContainer(position)) 
                {
                    BlockUIContainer blockUIContainer = (BlockUIContainer)position.Parent;
                    bool insertBefore = position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart;
                    position = insertBefore 
                        ? CreateImplicitParagraph(blockUIContainer.ElementStart)
                        : CreateImplicitParagraph(blockUIContainer.ElementEnd); 
 
                    // Clean potentialy incomplete content
                    if (blockUIContainer.IsEmpty) 
                    {
                        blockUIContainer.RepositionWithContent(null);
                    }
                } 
                else if (TextPointerBase.IsBeforeFirstTable(position) || TextPointerBase.IsAtPotentialParagraphPosition(position))
                { 
                    position = CreateImplicitParagraph(position); 
                }
                else if (TextPointerBase.IsAtPotentialRunPosition(position)) 
                {
                    position = CreateImplicitRun(position);
                }
            } 

            Invariant.Assert(TextSchema.IsInTextContent(position), "position must be in text content now"); 
            return position; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:76,代码来源:TextRangeEditTables.cs

示例13: IdentifyTableElements

        /// <summary> 
        /// From two text positions finds out table elements involved
        /// into building potential table range.
        /// </summary>
        /// <param name="anchorPosition"> 
        /// Position where selection starts. The cell at this position (if any)
        /// must be included into a range unconditionally. 
        /// </param> 
        /// <param name="movingPosition">
        /// A position opposite to an anchorPosition. 
        /// </param>
        /// <param name="includeCellAtMovingPosition">
        /// <see ref="TextRangeEditTables.BuildTableRange"/>
        /// </param> 
        /// <param name="anchorCell">
        /// The cell at anchor position. Returns not null only if a range is not crossing table 
        /// boundary. Returns null if the range does not cross any TableCell boundary at all 
        /// or if cells crossed belong to a table whose boundary is crossed by a range.
        /// In other words, anchorCell and movingCell are either both nulls or both non-nulls. 
        /// </param>
        /// <param name="movingCell">
        /// The cell at the movingPosition.  Returns not null only if a range is not crossing table
        /// boundary. Returns null if the range does not cross any TableCell boundary at all 
        /// or if cells crossed belong to a table whose boundary is crossed by a range.
        /// In other words, anchorCell and movingCell are either both nulls or both non-nulls. 
        /// </param> 
        /// <param name="anchorRow"></param>
        /// <param name="movingRow"></param> 
        /// <param name="anchorRowGroup"></param>
        /// <param name="movingRowGroup"></param>
        /// <param name="anchorTable"></param>
        /// <param name="movingTable"></param> 
        /// <returns>
        /// True if at least one structural unit was found. 
        /// False if no structural units were crossed by either startPosition or endPosition 
        /// (up to their commin ancestor element).
        /// </returns> 
        private static bool IdentifyTableElements(
            TextPointer anchorPosition, TextPointer movingPosition,
            bool includeCellAtMovingPosition,
            out TableCell anchorCell, out TableCell movingCell, 
            out TableRow anchorRow, out TableRow movingRow,
            out TableRowGroup anchorRowGroup, out TableRowGroup movingRowGroup, 
            out Table anchorTable, out Table movingTable) 
        {
            // We need to normalize pointers to make sure that we do not stay above TableCell level 
            anchorPosition = anchorPosition.GetInsertionPosition(LogicalDirection.Forward);
            if (!TextPointerBase.IsAfterLastParagraph(movingPosition))
            {
                movingPosition = movingPosition.GetInsertionPosition(LogicalDirection.Backward); 
            }
 
            if (!FindTableElements( 
                anchorPosition, movingPosition,
                out anchorCell, out movingCell, 
                out anchorRow, out movingRow,
                out anchorRowGroup, out movingRowGroup,
                out anchorTable, out movingTable))
            { 
                //Invariant.Assert(
                //    anchorCell == null && movingCell == null && 
                //    anchorRow == null && movingRow == null && 
                //    anchorRowGroup == null && movingRowGroup == null &&
                //    anchorTable == null && movingTable == null); 
                return false;
            }

            if (anchorTable != null || movingTable != null) 
            {
                // We crossed table boundary, so need to clear anchor/movingCells 
                //Invariant.Assert(anchorTable == null || movingTable == null || anchorTable != movingTable); 

                anchorCell = null; 
                movingCell = null;
            }
            else
            { 
                // We did not cross table boundary. Make sure that anchor/movingCells set consistently
 
                if (anchorCell != null && movingCell != null) 
                {
                    // Both ends cross cell boundaries. 
                    // The cell at movingPosition may require a correction - excluding it from
                    // a range - if its column index is greater than the anchor's one
                    // and if the movingPosition is at the very beginning of the cell,
                    // and if includeCellAtMovingPosition is set to false. 
                    if (!includeCellAtMovingPosition &&
                        movingPosition.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart && 
                        movingCell.ColumnIndex > anchorCell.ColumnIndex + anchorCell.ColumnSpan - 1 && 
                        movingCell.Index > 0)
                    { 
                        // Moving cell is in forward direction relative to anchor and the position at its very beginning.
                        // This cell should not be included into selection. Take the previous one as the moving cell.
                        movingCell = movingCell.Row.Cells[movingCell.Index - 1];
                    } 
                }
                else if (anchorCell != null && movingCell == null && movingPosition.IsAtRowEnd) 
                { 
                    // Special case when movingPosition is after the very last cell in row
                    TableRow movingCellRow = movingPosition.Parent as TableRow; 
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:TextRangeEditTables.cs

示例14: MoveToFirstNonCharacterSymbol

 // move to the first non-character symbol, but not pass beyond the limit
 private static void MoveToFirstNonCharacterSymbol(
     TextPointer navigator,   // navigator to move
     TextPointer  stopHint     // don't move further if we already pass beyond this point
     )         
 {
     while (navigator.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text 
         && navigator.CompareTo(stopHint) < 0
         && navigator.MoveToNextContextPosition(LogicalDirection.Forward)) ;
 }
开发者ID:JianwenSun,项目名称:cc,代码行数:10,代码来源:TextEffectResolver.cs

示例15: MoveToFirstCharacterSymbol

 //---------------------------
 // Private static methods
 //---------------------------
 
 // move to the first character symbol
 private static void MoveToFirstCharacterSymbol(TextPointer navigator)
 {
     while (navigator.GetPointerContext(LogicalDirection.Forward) != TextPointerContext.Text
         && navigator.MoveToNextContextPosition(LogicalDirection.Forward)) ;
 }
开发者ID:JianwenSun,项目名称:cc,代码行数:10,代码来源:TextEffectResolver.cs


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