Exemplo n.º 1
0
        // Token: 0x06007245 RID: 29253 RVA: 0x0020AA54 File Offset: 0x00208C54
        internal static List <AutomationPeer> GetAutomationPeersFromRange(ITextPointer start, ITextPointer end, ITextPointer ownerContentStart)
        {
            List <AutomationPeer> list = new List <AutomationPeer>();

            start = start.CreatePointer();
            while (start.CompareTo(end) < 0)
            {
                bool flag = false;
                if (start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart)
                {
                    object adjacentElement = start.GetAdjacentElement(LogicalDirection.Forward);
                    if (adjacentElement is ContentElement)
                    {
                        AutomationPeer automationPeer = ContentElementAutomationPeer.CreatePeerForElement((ContentElement)adjacentElement);
                        if (automationPeer != null)
                        {
                            if (ownerContentStart == null || TextContainerHelper.IsImmediateAutomationChild(start, ownerContentStart))
                            {
                                list.Add(automationPeer);
                            }
                            start.MoveToNextContextPosition(LogicalDirection.Forward);
                            start.MoveToElementEdge(ElementEdge.AfterEnd);
                            flag = true;
                        }
                    }
                }
                else if (start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.EmbeddedElement)
                {
                    object adjacentElement = start.GetAdjacentElement(LogicalDirection.Forward);
                    if (adjacentElement is UIElement)
                    {
                        if (ownerContentStart == null || TextContainerHelper.IsImmediateAutomationChild(start, ownerContentStart))
                        {
                            AutomationPeer automationPeer = UIElementAutomationPeer.CreatePeerForElement((UIElement)adjacentElement);
                            if (automationPeer != null)
                            {
                                list.Add(automationPeer);
                            }
                            else
                            {
                                TextContainerHelper.iterate((Visual)adjacentElement, list);
                            }
                        }
                    }
                    else if (adjacentElement is ContentElement)
                    {
                        AutomationPeer automationPeer = ContentElementAutomationPeer.CreatePeerForElement((ContentElement)adjacentElement);
                        if (automationPeer != null && (ownerContentStart == null || TextContainerHelper.IsImmediateAutomationChild(start, ownerContentStart)))
                        {
                            list.Add(automationPeer);
                        }
                    }
                }
                if (!flag && !start.MoveToNextContextPosition(LogicalDirection.Forward))
                {
                    break;
                }
            }
            return(list);
        }
Exemplo n.º 2
0
        // Token: 0x06007247 RID: 29255 RVA: 0x0020ABF0 File Offset: 0x00208DF0
        internal static AutomationPeer GetEnclosingAutomationPeer(ITextPointer start, ITextPointer end, out ITextPointer elementStart, out ITextPointer elementEnd)
        {
            List <object>       list        = new List <object>();
            List <ITextPointer> list2       = new List <ITextPointer>();
            ITextPointer        textPointer = start.CreatePointer();

            while (typeof(TextElement).IsAssignableFrom(textPointer.ParentType))
            {
                textPointer.MoveToElementEdge(ElementEdge.BeforeStart);
                object obj = textPointer.GetAdjacentElement(LogicalDirection.Forward);
                if (obj != null)
                {
                    list.Insert(0, obj);
                    list2.Insert(0, textPointer.CreatePointer(LogicalDirection.Forward));
                }
            }
            List <object>       list3 = new List <object>();
            List <ITextPointer> list4 = new List <ITextPointer>();

            textPointer = end.CreatePointer();
            while (typeof(TextElement).IsAssignableFrom(textPointer.ParentType))
            {
                textPointer.MoveToElementEdge(ElementEdge.AfterEnd);
                object obj = textPointer.GetAdjacentElement(LogicalDirection.Backward);
                if (obj != null)
                {
                    list3.Insert(0, obj);
                    list4.Insert(0, textPointer.CreatePointer(LogicalDirection.Backward));
                }
            }
            AutomationPeer automationPeer = null;
            ITextPointer   textPointer2;

            elementEnd   = (textPointer2 = null);
            elementStart = textPointer2;
            for (int i = Math.Min(list.Count, list3.Count); i > 0; i--)
            {
                if (list[i - 1] == list3[i - 1])
                {
                    object obj = list[i - 1];
                    if (obj is UIElement)
                    {
                        automationPeer = UIElementAutomationPeer.CreatePeerForElement((UIElement)obj);
                    }
                    else if (obj is ContentElement)
                    {
                        automationPeer = ContentElementAutomationPeer.CreatePeerForElement((ContentElement)obj);
                    }
                    if (automationPeer != null)
                    {
                        elementStart = list2[i - 1];
                        elementEnd   = list4[i - 1];
                        break;
                    }
                }
            }
            return(automationPeer);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Is AutometionPeer represented by 'elementStart' is immediate child of AutomationPeer
        /// represented by 'ownerContentStart'.
        /// </summary>
        internal static bool IsImmediateAutomationChild(ITextPointer elementStart, ITextPointer ownerContentStart)
        {
            Invariant.Assert(elementStart.CompareTo(ownerContentStart) >= 0);
            bool immediateChild = true;
            // Walk element tree up looking for AutomationPeers.
            ITextPointer position = elementStart.CreatePointer();

            while (typeof(TextElement).IsAssignableFrom(position.ParentType))
            {
                position.MoveToElementEdge(ElementEdge.BeforeStart);
                if (position.CompareTo(ownerContentStart) <= 0)
                {
                    break;
                }
                AutomationPeer peer    = null;
                object         element = position.GetAdjacentElement(LogicalDirection.Forward);
                if (element is UIElement)
                {
                    peer = UIElementAutomationPeer.CreatePeerForElement((UIElement)element);
                }
                else if (element is ContentElement)
                {
                    peer = ContentElementAutomationPeer.CreatePeerForElement((ContentElement)element);
                }
                if (peer != null)
                {
                    immediateChild = false;
                    break;
                }
            }
            return(immediateChild);
        }
Exemplo n.º 4
0
        // Token: 0x06007246 RID: 29254 RVA: 0x0020AB60 File Offset: 0x00208D60
        internal static bool IsImmediateAutomationChild(ITextPointer elementStart, ITextPointer ownerContentStart)
        {
            Invariant.Assert(elementStart.CompareTo(ownerContentStart) >= 0);
            bool         result      = true;
            ITextPointer textPointer = elementStart.CreatePointer();

            while (typeof(TextElement).IsAssignableFrom(textPointer.ParentType))
            {
                textPointer.MoveToElementEdge(ElementEdge.BeforeStart);
                if (textPointer.CompareTo(ownerContentStart) <= 0)
                {
                    break;
                }
                AutomationPeer automationPeer  = null;
                object         adjacentElement = textPointer.GetAdjacentElement(LogicalDirection.Forward);
                if (adjacentElement is UIElement)
                {
                    automationPeer = UIElementAutomationPeer.CreatePeerForElement((UIElement)adjacentElement);
                }
                else if (adjacentElement is ContentElement)
                {
                    automationPeer = ContentElementAutomationPeer.CreatePeerForElement((ContentElement)adjacentElement);
                }
                if (automationPeer != null)
                {
                    result = false;
                    break;
                }
            }
            return(result);
        }
        // Token: 0x06003889 RID: 14473 RVA: 0x000FDB54 File Offset: 0x000FBD54
        private static UIElement GetUIElementWhenMouseOver(TextEditor This, Point mouseMovePoint)
        {
            ITextPointer textPositionFromPoint = This.TextView.GetTextPositionFromPoint(mouseMovePoint, false);

            if (textPositionFromPoint == null)
            {
                return(null);
            }
            if (textPositionFromPoint.GetPointerContext(textPositionFromPoint.LogicalDirection) != TextPointerContext.EmbeddedElement)
            {
                return(null);
            }
            ITextPointer     textPointer = textPositionFromPoint.GetNextContextPosition(textPositionFromPoint.LogicalDirection);
            LogicalDirection gravity     = (textPositionFromPoint.LogicalDirection == LogicalDirection.Forward) ? LogicalDirection.Backward : LogicalDirection.Forward;

            textPointer = textPointer.CreatePointer(0, gravity);
            Rect rectangleFromTextPosition  = This.TextView.GetRectangleFromTextPosition(textPositionFromPoint);
            Rect rectangleFromTextPosition2 = This.TextView.GetRectangleFromTextPosition(textPointer);
            Rect rect = rectangleFromTextPosition;

            rect.Union(rectangleFromTextPosition2);
            if (!rect.Contains(mouseMovePoint))
            {
                return(null);
            }
            return(textPositionFromPoint.GetAdjacentElement(textPositionFromPoint.LogicalDirection) as UIElement);
        }
Exemplo n.º 6
0
 // Token: 0x0600384C RID: 14412 RVA: 0x000FB73C File Offset: 0x000F993C
 private static ITextPointer GetContentPosition(ITextPointer position)
 {
     while (position.GetAdjacentElement(LogicalDirection.Forward) is Inline)
     {
         position = position.GetNextContextPosition(LogicalDirection.Forward);
     }
     return(position);
 }
Exemplo n.º 7
0
        // Return a UIElement when mouseMovePoint is within the ui element's bounding Rect. Null otherwise.
        private static UIElement GetUIElementWhenMouseOver(TextEditor This, Point mouseMovePoint)
        {
            ITextPointer mouseMovePosition = This.TextView.GetTextPositionFromPoint(mouseMovePoint, /*snapToText:*/ false);

            if (mouseMovePosition == null)
            {
                return(null);
            }

            if (!(mouseMovePosition.GetPointerContext(mouseMovePosition.LogicalDirection) == TextPointerContext.EmbeddedElement))
            {
                return(null);
            }

            // Find out if mouseMovePoint is within the bounding Rect of UIElement, we need to do this check explicitly
            // because even when snapToText is false, textview returns a first/last position on a line when point is in
            // an area before/after line start/end. This is by-design behavior for textview.

            // Need to get Rect from TextView, since Rect returned by TextPointer.GetCharacterRect()
            // is transformed to UiScope coordinates and we want RenderScope coordinates here.

            ITextPointer     otherEdgePosition  = mouseMovePosition.GetNextContextPosition(mouseMovePosition.LogicalDirection);
            LogicalDirection otherEdgeDirection = (mouseMovePosition.LogicalDirection == LogicalDirection.Forward) ?
                                                  LogicalDirection.Backward : LogicalDirection.Forward;

            // Normalize with correct gravity
            otherEdgePosition = otherEdgePosition.CreatePointer(0, otherEdgeDirection);

            Rect uiElementFirstEdgeRect  = This.TextView.GetRectangleFromTextPosition(mouseMovePosition);
            Rect uiElementSecondEdgeRect = This.TextView.GetRectangleFromTextPosition(otherEdgePosition);

            Rect boundingRect = uiElementFirstEdgeRect;

            boundingRect.Union(uiElementSecondEdgeRect);
            if (!boundingRect.Contains(mouseMovePoint))
            {
                return(null);
            }

            return(mouseMovePosition.GetAdjacentElement(mouseMovePosition.LogicalDirection) as UIElement);
        }
Exemplo n.º 8
0
        // Normalizes a range:
        //
        // -The start position is advanced over all element edges not visible
        //  to the IMEs.
        // -Start and end positions are moved to insertion positions.
        private void GetNormalizedRange(int startCharOffset, int endCharOffset, out ITextPointer start, out ITextPointer end)
        {
            start = CreatePointerAtCharOffset(startCharOffset, LogicalDirection.Forward);
            end = (startCharOffset == endCharOffset) ? start : CreatePointerAtCharOffset(endCharOffset, LogicalDirection.Backward);

            // Skip over hidden element edges.
            while (start.CompareTo(end) < 0)
            {
                TextPointerContext forwardContext = start.GetPointerContext(LogicalDirection.Forward);

                if (forwardContext == TextPointerContext.ElementStart)
                {
                    TextElement element = start.GetAdjacentElement(LogicalDirection.Forward) as TextElement;

                    if (element == null)
                        break;
                    if (element.IMELeftEdgeCharCount != 0)
                        break;
                }
                else if (forwardContext != TextPointerContext.ElementEnd)
                {
                    break;
                }

                start.MoveToNextContextPosition(LogicalDirection.Forward);
            }

            // Move to insertion positions.
            // If the positions are already adjacent to text, we must respect
            // the IME's decision in regards to exact placement.
            // MoveToInsertionPosition will skip over surrogates and combining
            // marks, but the IME needs fine-grained control over these positions.

            if (start.CompareTo(end) == 0)
            {
                start = start.GetFormatNormalizedPosition(LogicalDirection.Backward);
                end = start;
            }
            else
            {
                start = start.GetFormatNormalizedPosition(LogicalDirection.Backward);
                end = end.GetFormatNormalizedPosition(LogicalDirection.Backward);
            }
        }
Exemplo n.º 9
0
        // GetText handler for Blocks and TableCell to add '\n' or TS_CHAR_REGION.
        private static bool WalkRegionBoundary(ITextPointer navigator, ITextPointer limit, char[] text, int cchReq, ref int charsCopied, UnsafeNativeMethods.TS_RUNINFO[] runInfo, int cRunInfoReq, ref int cRunInfoRcv)
        {
            bool hitLimit;

            Invariant.Assert(navigator.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart || navigator.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd);
            Invariant.Assert(limit == null || navigator.CompareTo(limit) <= 0);

            // If the caller passed in a non-null limit, we don't do anything and just return true.
            // we've passed it.
            if (limit != null)
            {
                if (navigator.CompareTo(limit) >= 0)
                {
                    return true;
                }
            }

            hitLimit = false;

            if (cchReq > 0)
            {
                // Add one TS_CHAR_REGION (TableCell) or '\n' (everything else) char.
                char ch = (navigator.GetAdjacentElement(LogicalDirection.Forward) is TableCell) ? UnsafeNativeMethods.TS_CHAR_REGION : '\n';
                text[charsCopied] = ch;
                navigator.MoveByOffset(1);
                charsCopied += 1;
                hitLimit = (text.Length == charsCopied) || (limit != null && navigator.CompareTo(limit) == 0);
            }
            else
            {
                // Caller doesn't want text, just run info.
                // Advance the navigator.
                // Add one TS_CHAR_REGION char.
                navigator.MoveByOffset(1);
            }

            if (cRunInfoReq > 0)
            {
                // Be sure to merge this text run with the previous run, if they are both text runs.
                // (A good robustness fix would be to make cicero handle this, if we ever get the chance.)
                if (cRunInfoRcv > 0 && runInfo[cRunInfoRcv - 1].type == UnsafeNativeMethods.TsRunType.TS_RT_PLAIN)
                {
                    runInfo[cRunInfoRcv - 1].count += 1;
                }
                else
                {
                    runInfo[cRunInfoRcv].count = 1;
                    runInfo[cRunInfoRcv].type = UnsafeNativeMethods.TsRunType.TS_RT_PLAIN;
                    cRunInfoRcv++;
                }
            }

            return hitLimit;
        }
        // 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;
        }
Exemplo n.º 11
0
 // Part of plain text converter: called from GetTextInternal when processing ElementStart for AccessKey elements 
 // Uses s stack of list items indices and updates it for following list items.
 private static void PlainConvertAccessKey(StringBuilder textBuffer, ITextPointer navigator)
 {
     // Creating an "_" prefix for AccessKey character (represented as a Run with special serialization attribution) 
     object element = navigator.GetAdjacentElement(LogicalDirection.Forward);
     if (AccessText.HasCustomSerialization(element)) 
     { 
         textBuffer.Append(AccessText.AccessKeyMarker);
     } 
 }
Exemplo n.º 12
0
        // Part of plain text converter: called from GetTextInternal when processing ElementStart for ListItem elements
        // Uses s stack of list items indices and updates it for following list items.
        private static void PlainConvertListItemStart(StringBuilder textBuffer, ITextPointer navigator, ref Stack<int> listItemCounter) 
        {
            if (navigator is TextPointer) // can do somethinng useful only in concrete TextContainer - not in an abstract one 
            { 
                List list = (List)((TextPointer)navigator).Parent;
                ListItem listItem = (ListItem)navigator.GetAdjacentElement(LogicalDirection.Forward); 

                // Initialize list context
                if (listItemCounter == null)
                { 
                    listItemCounter = new Stack<int>(1);
                } 
                if (listItemCounter.Count == 0) 
                {
                    // List is taken from its middle position. Need to identify starting item number 
                    listItemCounter.Push(((IList)listItem.SiblingListItems).IndexOf(listItem));
                }

                // Get list item number 
                Invariant.Assert(listItemCounter.Count > 0, "expectinng listItemCounter.Count > 0");
                int listItemIndex = listItemCounter.Pop(); 
                int indexBase = list != null ? list.StartIndex : 0; 
                TextMarkerStyle markerStyle = list != null ? list.MarkerStyle : TextMarkerStyle.Disc;
 
                WriteListMarker(textBuffer, markerStyle, listItemIndex + indexBase);

                // Advance
                listItemIndex++; 
                listItemCounter.Push(listItemIndex);
            } 
        } 
        internal object BuildObjectTree()
        {
            IAddChild root;

            switch (_type)
            {
            case ElementType.Table:
                root = new Table();
                break;

            case ElementType.TableRowGroup:
                root = new TableRowGroup();
                break;

            case ElementType.TableRow:
                root = new TableRow();
                break;

            case ElementType.TableCell:
                root = new TableCell();
                break;

            case ElementType.Paragraph:
                root = new Paragraph();
                break;

            case ElementType.Hyperlink:
                Hyperlink link = new Hyperlink();
                link.NavigateUri      = GetValue(NavigateUriProperty) as Uri;
                link.RequestNavigate += new RequestNavigateEventHandler(ClickHyperlink);
                AutomationProperties.SetHelpText(link, (String)this.GetValue(HelpTextProperty));
                AutomationProperties.SetName(link, (String)this.GetValue(NameProperty));
                root = link;
                break;

            default:
                Debug.Assert(false);
                root = null;
                break;
            }

            ITextPointer pos = ((ITextPointer)_start).CreatePointer();

            while (pos.CompareTo((ITextPointer)_end) < 0)
            {
                TextPointerContext tpc = pos.GetPointerContext(LogicalDirection.Forward);
                if (tpc == TextPointerContext.Text)
                {
                    root.AddText(pos.GetTextInRun(LogicalDirection.Forward));
                }
                else if (tpc == TextPointerContext.EmbeddedElement)
                {
                    root.AddChild(pos.GetAdjacentElement(LogicalDirection.Forward));
                }
                else if (tpc == TextPointerContext.ElementStart)
                {
                    object obj = pos.GetAdjacentElement(LogicalDirection.Forward);
                    if (obj != null)
                    {
                        root.AddChild(obj);
                        pos.MoveToNextContextPosition(LogicalDirection.Forward);
                        pos.MoveToElementEdge(ElementEdge.BeforeEnd);
                    }
                }

                pos.MoveToNextContextPosition(LogicalDirection.Forward);
            }
            return(root);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Retrieves the range of a child object.
        /// </summary>
        /// <param name="childElementProvider">The child element.  A provider should check that the
        /// passed element is a child of the text container, and should throw an
        /// InvalidOperationException if it is not.</param>
        /// <returns>A range that spans the child element.</returns>
        ITextRangeProvider ITextProvider.RangeFromChild(IRawElementProviderSimple childElementProvider)
        {
            if (childElementProvider == null)
            {
                throw new ArgumentNullException("childElementProvider");
            }

            // Retrieve DependencyObject from AutomationElement
            DependencyObject childElement;

            if (_textPeer is TextAutomationPeer)
            {
                childElement = ((TextAutomationPeer)_textPeer).ElementFromProvider(childElementProvider);
            }
            else
            {
                childElement = ((ContentTextAutomationPeer)_textPeer).ElementFromProvider(childElementProvider);
            }

            TextRangeAdaptor range = null;

            if (childElement != null)
            {
                ITextPointer rangeStart = null;
                ITextPointer rangeEnd   = null;

                // Retrieve start and end positions for given element.
                // If element is TextElement, retrieve its Element Start and End positions.
                // If element is UIElement hosted by UIContainer (Inlien of Block),
                // retrieve content Start and End positions of the container.
                // Otherwise scan ITextContainer to find a range for given element.
                if (childElement is TextElement)
                {
                    rangeStart = ((TextElement)childElement).ElementStart;
                    rangeEnd   = ((TextElement)childElement).ElementEnd;
                }
                else
                {
                    DependencyObject parent = LogicalTreeHelper.GetParent(childElement);
                    if (parent is InlineUIContainer || parent is BlockUIContainer)
                    {
                        rangeStart = ((TextElement)parent).ContentStart;
                        rangeEnd   = ((TextElement)parent).ContentEnd;
                    }
                    else
                    {
                        ITextPointer position = _textContainer.Start.CreatePointer();
                        while (position.CompareTo(_textContainer.End) < 0)
                        {
                            TextPointerContext context = position.GetPointerContext(LogicalDirection.Forward);
                            if (context == TextPointerContext.ElementStart)
                            {
                                if (childElement == position.GetAdjacentElement(LogicalDirection.Forward))
                                {
                                    rangeStart = position.CreatePointer(LogicalDirection.Forward);
                                    position.MoveToElementEdge(ElementEdge.AfterEnd);
                                    rangeEnd = position.CreatePointer(LogicalDirection.Backward);
                                    break;
                                }
                            }
                            else if (context == TextPointerContext.EmbeddedElement)
                            {
                                if (childElement == position.GetAdjacentElement(LogicalDirection.Forward))
                                {
                                    rangeStart = position.CreatePointer(LogicalDirection.Forward);
                                    position.MoveToNextContextPosition(LogicalDirection.Forward);
                                    rangeEnd = position.CreatePointer(LogicalDirection.Backward);
                                    break;
                                }
                            }
                            position.MoveToNextContextPosition(LogicalDirection.Forward);
                        }
                    }
                }
                // Create range
                if (rangeStart != null && rangeEnd != null)
                {
                    range = new TextRangeAdaptor(this, rangeStart, rangeEnd, _textPeer);
                }
            }
            if (range == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.TextProvider_InvalidChildElement));
            }
            return(range);
        }
Exemplo n.º 15
0
        /// <summary>
        /// This helper method is used by TextRangeAdaptor to bring the range into view
        /// through multiple nested scroll providers.
        /// </summary>
        internal void ScrollIntoView(ITextPointer start, ITextPointer end, bool alignToTop)
        {
            // Calculate the bounding rectangle for the range
            Rect rangeBounds = Rect.Empty;

            Rect[] lineBounds = GetBoundingRectangles(start, end, false, false);
            foreach (Rect rect in lineBounds)
            {
                rangeBounds.Union(rect);
            }

            ITextView textView = GetUpdatedTextView();

            if (textView != null && !rangeBounds.IsEmpty)
            {
                // Find out the visible portion of the range.
                Rect visibleRect        = GetVisibleRectangle(textView);
                Rect rangeVisibleBounds = Rect.Intersect(rangeBounds, visibleRect);
                if (rangeVisibleBounds == rangeBounds)
                {
                    // The range is already in the view. It's probably not aligned as requested,
                    // but who cares since it's entirely visible anyway.
                    return;
                }

                // Ensure the visibility of the range.
                // BringIntoView will do most of the magic except the very first scroll
                // in order to satisfy the requested alignment.
                UIElement renderScope = textView.RenderScope;
                Visual    visual      = renderScope;
                while (visual != null)
                {
                    IScrollInfo isi = visual as IScrollInfo;
                    if (isi != null)
                    {
                        // Transform the bounding rectangle into the IScrollInfo coordinates.
                        if (visual != renderScope)
                        {
                            GeneralTransform childToParent = renderScope.TransformToAncestor(visual);
                            rangeBounds = childToParent.TransformBounds(rangeBounds);
                        }

                        if (isi.CanHorizontallyScroll)
                        {
                            isi.SetHorizontalOffset(alignToTop ? rangeBounds.Left : (rangeBounds.Right - isi.ViewportWidth));
                        }
                        if (isi.CanVerticallyScroll)
                        {
                            isi.SetVerticalOffset(alignToTop ? rangeBounds.Top : (rangeBounds.Bottom - isi.ViewportHeight));
                        }
                        break;
                    }
                    visual = VisualTreeHelper.GetParent(visual) as Visual;
                }

                FrameworkElement fe = renderScope as FrameworkElement;
                if (fe != null)
                {
                    fe.BringIntoView(rangeVisibleBounds);
                }
            }
            else
            {
                // If failed to retrive range bounds, try to Bring into view closes element.
                ITextPointer pointer = alignToTop ? start.CreatePointer() : end.CreatePointer();
                pointer.MoveToElementEdge(alignToTop ? ElementEdge.AfterStart : ElementEdge.AfterEnd);
                FrameworkContentElement element = pointer.GetAdjacentElement(LogicalDirection.Backward) as FrameworkContentElement;
                if (element != null)
                {
                    element.BringIntoView();
                }
            }
        }
Exemplo n.º 16
0
        //-------------------------------------------------------------------
        //
        //  Internal Methods
        //
        //-------------------------------------------------------------------

        #region Internal Methods

        /// <summary>
        /// Retrieves a collection of AutomationPeers that fall within the range.
        /// Children that overlap with the range but are not entirely enclosed by
        /// it will also be included in the collection.
        /// </summary>
        internal static List <AutomationPeer> GetAutomationPeersFromRange(ITextPointer start, ITextPointer end, ITextPointer ownerContentStart)
        {
            bool                  positionMoved;
            AutomationPeer        peer = null;
            object                element;
            List <AutomationPeer> peers = new List <AutomationPeer>();

            start = start.CreatePointer();

            while (start.CompareTo(end) < 0)
            {
                // Indicate that 'start' position is not moved yet.
                positionMoved = false;

                if (start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart)
                {
                    // Get adjacent element and try to retrive AutomationPeer for it.
                    element = start.GetAdjacentElement(LogicalDirection.Forward);
                    if (element is ContentElement)
                    {
                        peer = ContentElementAutomationPeer.CreatePeerForElement((ContentElement)element);
                        // If AutomationPeer has been retrieved, add it to the collection.
                        // And skip entire element.
                        if (peer != null)
                        {
                            if (ownerContentStart == null || IsImmediateAutomationChild(start, ownerContentStart))
                            {
                                peers.Add(peer);
                            }
                            start.MoveToNextContextPosition(LogicalDirection.Forward);
                            start.MoveToElementEdge(ElementEdge.AfterEnd);
                            positionMoved = true;
                        }
                    }
                }
                else if (start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.EmbeddedElement)
                {
                    // Get adjacent element and try to retrive AutomationPeer for it.
                    element = start.GetAdjacentElement(LogicalDirection.Forward);
                    if (element is UIElement)
                    {
                        if (ownerContentStart == null || IsImmediateAutomationChild(start, ownerContentStart))
                        {
                            peer = UIElementAutomationPeer.CreatePeerForElement((UIElement)element);
                            // If AutomationPeer has been retrieved, add it to the collection.
                            if (peer != null)
                            {
                                peers.Add(peer);
                            }
                            else
                            {
                                iterate((Visual)element, peers);
                            }
                        }
                    }
                    else if (element is ContentElement)
                    {
                        peer = ContentElementAutomationPeer.CreatePeerForElement((ContentElement)element);
                        // If AutomationPeer has been retrieved, add it to the collection.
                        if (peer != null)
                        {
                            if (ownerContentStart == null || IsImmediateAutomationChild(start, ownerContentStart))
                            {
                                peers.Add(peer);
                            }
                        }
                    }
                }
                // Move to the next content position, if position has not been moved already.
                if (!positionMoved)
                {
                    if (!start.MoveToNextContextPosition(LogicalDirection.Forward))
                    {
                        break;
                    }
                }
            }

            return(peers);
        }
Exemplo n.º 17
0
        // Token: 0x060065C7 RID: 26055 RVA: 0x001C84A0 File Offset: 0x001C66A0
        internal void ScrollIntoView(ITextPointer start, ITextPointer end, bool alignToTop)
        {
            Rect rect = Rect.Empty;

            Rect[] boundingRectangles = this.GetBoundingRectangles(start, end, false, false);
            foreach (Rect rect2 in boundingRectangles)
            {
                rect.Union(rect2);
            }
            ITextView updatedTextView = this.GetUpdatedTextView();

            if (updatedTextView != null && !rect.IsEmpty)
            {
                Rect visibleRectangle = this.GetVisibleRectangle(updatedTextView);
                Rect rect3            = Rect.Intersect(rect, visibleRectangle);
                if (rect3 == rect)
                {
                    return;
                }
                UIElement renderScope = updatedTextView.RenderScope;
                Visual    visual      = renderScope;
                while (visual != null)
                {
                    IScrollInfo scrollInfo = visual as IScrollInfo;
                    if (scrollInfo != null)
                    {
                        if (visual != renderScope)
                        {
                            GeneralTransform generalTransform = renderScope.TransformToAncestor(visual);
                            rect = generalTransform.TransformBounds(rect);
                        }
                        if (scrollInfo.CanHorizontallyScroll)
                        {
                            scrollInfo.SetHorizontalOffset(alignToTop ? rect.Left : (rect.Right - scrollInfo.ViewportWidth));
                        }
                        if (scrollInfo.CanVerticallyScroll)
                        {
                            scrollInfo.SetVerticalOffset(alignToTop ? rect.Top : (rect.Bottom - scrollInfo.ViewportHeight));
                            break;
                        }
                        break;
                    }
                    else
                    {
                        visual = (VisualTreeHelper.GetParent(visual) as Visual);
                    }
                }
                FrameworkElement frameworkElement = renderScope as FrameworkElement;
                if (frameworkElement != null)
                {
                    frameworkElement.BringIntoView(rect3);
                    return;
                }
            }
            else
            {
                ITextPointer textPointer = alignToTop ? start.CreatePointer() : end.CreatePointer();
                textPointer.MoveToElementEdge(alignToTop ? ElementEdge.AfterStart : ElementEdge.AfterEnd);
                FrameworkContentElement frameworkContentElement = textPointer.GetAdjacentElement(LogicalDirection.Backward) as FrameworkContentElement;
                if (frameworkContentElement != null)
                {
                    frameworkContentElement.BringIntoView();
                }
            }
        }
Exemplo n.º 18
0
        // Token: 0x060065D1 RID: 26065 RVA: 0x001C8918 File Offset: 0x001C6B18
        ITextRangeProvider ITextProvider.RangeFromChild(IRawElementProviderSimple childElementProvider)
        {
            if (childElementProvider == null)
            {
                throw new ArgumentNullException("childElementProvider");
            }
            DependencyObject dependencyObject;

            if (this._textPeer is TextAutomationPeer)
            {
                dependencyObject = ((TextAutomationPeer)this._textPeer).ElementFromProvider(childElementProvider);
            }
            else
            {
                dependencyObject = ((ContentTextAutomationPeer)this._textPeer).ElementFromProvider(childElementProvider);
            }
            TextRangeAdaptor textRangeAdaptor = null;

            if (dependencyObject != null)
            {
                ITextPointer textPointer  = null;
                ITextPointer textPointer2 = null;
                if (dependencyObject is TextElement)
                {
                    textPointer  = ((TextElement)dependencyObject).ElementStart;
                    textPointer2 = ((TextElement)dependencyObject).ElementEnd;
                }
                else
                {
                    DependencyObject parent = LogicalTreeHelper.GetParent(dependencyObject);
                    if (parent is InlineUIContainer || parent is BlockUIContainer)
                    {
                        textPointer  = ((TextElement)parent).ContentStart;
                        textPointer2 = ((TextElement)parent).ContentEnd;
                    }
                    else
                    {
                        ITextPointer textPointer3 = this._textContainer.Start.CreatePointer();
                        while (textPointer3.CompareTo(this._textContainer.End) < 0)
                        {
                            TextPointerContext pointerContext = textPointer3.GetPointerContext(LogicalDirection.Forward);
                            if (pointerContext == TextPointerContext.ElementStart)
                            {
                                if (dependencyObject == textPointer3.GetAdjacentElement(LogicalDirection.Forward))
                                {
                                    textPointer = textPointer3.CreatePointer(LogicalDirection.Forward);
                                    textPointer3.MoveToElementEdge(ElementEdge.AfterEnd);
                                    textPointer2 = textPointer3.CreatePointer(LogicalDirection.Backward);
                                    break;
                                }
                            }
                            else if (pointerContext == TextPointerContext.EmbeddedElement && dependencyObject == textPointer3.GetAdjacentElement(LogicalDirection.Forward))
                            {
                                textPointer = textPointer3.CreatePointer(LogicalDirection.Forward);
                                textPointer3.MoveToNextContextPosition(LogicalDirection.Forward);
                                textPointer2 = textPointer3.CreatePointer(LogicalDirection.Backward);
                                break;
                            }
                            textPointer3.MoveToNextContextPosition(LogicalDirection.Forward);
                        }
                    }
                }
                if (textPointer != null && textPointer2 != null)
                {
                    textRangeAdaptor = new TextRangeAdaptor(this, textPointer, textPointer2, this._textPeer);
                }
            }
            if (textRangeAdaptor == null)
            {
                throw new InvalidOperationException(SR.Get("TextProvider_InvalidChildElement"));
            }
            return(textRangeAdaptor);
        }
Exemplo n.º 19
0
        //-------------------------------------------------------------------
        // 
        //  Internal Methods 
        //
        //------------------------------------------------------------------- 

        #region Internal Methods

        /// <summary> 
        /// Retrieves a collection of AutomationPeers that fall within the range.
        /// Children that overlap with the range but are not entirely enclosed by 
        /// it will also be included in the collection. 
        /// </summary>
        internal static List<AutomationPeer> GetAutomationPeersFromRange(ITextPointer start, ITextPointer end, ITextPointer ownerContentStart) 
        {
            bool positionMoved;
            AutomationPeer peer = null;
            object element; 
            List<AutomationPeer> peers = new List<AutomationPeer>();
            start = start.CreatePointer(); 
 
            while (start.CompareTo(end) < 0)
            { 
                // Indicate that 'start' position is not moved yet.
                positionMoved = false;

                if (start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart) 
                {
                    // Get adjacent element and try to retrive AutomationPeer for it. 
                    element = start.GetAdjacentElement(LogicalDirection.Forward); 
                    if (element is ContentElement)
                    { 
                        peer = ContentElementAutomationPeer.CreatePeerForElement((ContentElement)element);
                        // If AutomationPeer has been retrieved, add it to the collection.
                        // And skip entire element.
                        if (peer != null) 
                        {
                            if (ownerContentStart == null || IsImmediateAutomationChild(start, ownerContentStart)) 
                            { 
                                peers.Add(peer);
                            } 
                            start.MoveToNextContextPosition(LogicalDirection.Forward);
                            start.MoveToElementEdge(ElementEdge.AfterEnd);
                            positionMoved = true;
                        } 
                    }
                } 
                else if (start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.EmbeddedElement) 
                {
                    // Get adjacent element and try to retrive AutomationPeer for it. 
                    element = start.GetAdjacentElement(LogicalDirection.Forward);
                    if (element is UIElement)
                    {
                        if (ownerContentStart == null || IsImmediateAutomationChild(start, ownerContentStart)) 
                        {
                            peer = UIElementAutomationPeer.CreatePeerForElement((UIElement)element); 
                            // If AutomationPeer has been retrieved, add it to the collection. 
                            if (peer != null)
                            { 
                                peers.Add(peer);
                            }
                            else
                            { 
                                iterate((Visual)element, peers);
                            } 
                        } 
                    }
                    else if (element is ContentElement) 
                    {
                        peer = ContentElementAutomationPeer.CreatePeerForElement((ContentElement)element);
                        // If AutomationPeer has been retrieved, add it to the collection.
                        if (peer != null) 
                        {
                            if (ownerContentStart == null || IsImmediateAutomationChild(start, ownerContentStart)) 
                            { 
                                peers.Add(peer);
                            } 
                        }
                    }
                }
                // Move to the next content position, if position has not been moved already. 
                if (!positionMoved)
                { 
                    if (!start.MoveToNextContextPosition(LogicalDirection.Forward)) 
                    {
                        break; 
                    }
                }
            }
 
            return peers;
        } 
        /// <summary>
        /// Return true if Hyperlink range is invalid.
        /// Hyperlink is invalid if it include a UiElement except Image or the range end position
        /// is stated before the end position of hyperlink.
        /// This must be called before Hyperlink start element position.
        /// </summary>        
        private static bool IsHyperlinkInvalid(ITextPointer textReader, ITextPointer rangeEnd)
        {
            // TextRead must be on the position before the element start position of Hyperlink
            Invariant.Assert(textReader.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart);
            Invariant.Assert(typeof(Hyperlink).IsAssignableFrom(textReader.GetElementType(LogicalDirection.Forward)));

            bool hyperlinkInvalid = false;

            // Get the forward adjacent element and cast Hyperlink hardly since it must be Hyperlink
            Hyperlink hyperlink = (Hyperlink)textReader.GetAdjacentElement(LogicalDirection.Forward);

            ITextPointer hyperlinkNavigation = textReader.CreatePointer();
            ITextPointer hyperlinkEnd = textReader.CreatePointer();

            hyperlinkEnd.MoveToNextContextPosition(LogicalDirection.Forward);

            // Find the hyperlink end position
            hyperlinkEnd.MoveToElementEdge(ElementEdge.AfterEnd);

            // Hyperlink end position is stated after the range end position.
            if (hyperlinkEnd.CompareTo(rangeEnd) > 0)
            {
                hyperlinkInvalid = true;
            }
            else
            {
                // Check whether the hyperlink having a UiElement except Image until hyperlink end position
                while (hyperlinkNavigation.CompareTo(hyperlinkEnd) < 0)
                {
                    InlineUIContainer inlineUIContainer = hyperlinkNavigation.GetAdjacentElement(LogicalDirection.Forward) as InlineUIContainer;
                    if (inlineUIContainer != null && !(inlineUIContainer.Child is Image))
                    {
                        hyperlinkInvalid = true;
                        break;
                    }

                    hyperlinkNavigation.MoveToNextContextPosition(LogicalDirection.Forward);
                }
            }

            return hyperlinkInvalid;
        }
Exemplo n.º 21
0
        // Part of plain text converter: called from GetTextInternal when processing ElementStart for List elements.
        // Initializes a stack of list item counters and pushes a new zero for the opened list level.
        private static void PlainConvertListStart(ITextPointer navigator, ref Stack<int> listItemCounter)
        { 
            List list = (List)navigator.GetAdjacentElement(LogicalDirection.Forward);
 
            // Initialize list context 
            if (listItemCounter == null)
            { 
                listItemCounter = new Stack<int>(1);
            }
            listItemCounter.Push(0);
        } 
        /// <summary>
        /// Writes an opening tag of an element together with all attributes
        /// representing Avalon properties.
        /// </summary>
        /// <param name="range">
        /// Parameter used for top-level Table element - to decide what columns to output.
        /// For all other elements it's ignored.
        /// </param>
        /// <param name="textReader">
        /// TextPointer positioned in the scope of element whose
        /// start tag is going to be written.
        /// </param>
        /// <param name="xmlWriter">
        /// XmlWriter to output element opening tag.
        /// </param>
        /// <param name="xamlTypeMapper"></param>
        /// <param name="reduceElement">
        /// True value of this parameter indicates that
        /// serialization goes into XamlPackage, so all elements
        /// can be preserved as is; otherwise some of them must be
        /// reduced into simpler representations (such as InlineUIContainer -> Run
        /// and BlockUIContainer -> Paragraph).
        /// </param>
        /// <param name="preserveTextElements">
        /// If TRUE, TextElements are serialized as-is.  If FALSE, they're upcast
        /// to their base types.
        /// </param>
        private static void WriteStartXamlElement(ITextRange range, ITextPointer textReader, XmlWriter xmlWriter, XamlTypeMapper xamlTypeMapper, bool reduceElement, bool preserveTextElements)
        {
            Type elementType = textReader.ParentType;

            Type elementTypeStandardized = TextSchema.GetStandardElementType(elementType, reduceElement);

            // Get rid f UIContainers when their child is not an image
            if (elementTypeStandardized == typeof(InlineUIContainer) || elementTypeStandardized == typeof(BlockUIContainer))
            {
                Invariant.Assert(!reduceElement);

                InlineUIContainer inlineUIContainer = textReader.GetAdjacentElement(LogicalDirection.Backward) as InlineUIContainer;
                BlockUIContainer blockUIContainer = textReader.GetAdjacentElement(LogicalDirection.Backward) as BlockUIContainer;

                if ((inlineUIContainer == null || !(inlineUIContainer.Child is Image)) &&
                    (blockUIContainer == null || !(blockUIContainer.Child is Image)))
                {
                    // Even when we serialize for DataFormats.XamlPackage we strip out UIElement
                    // different from Images. 
                    // Note that this condition is consistent with the one in WriteEmbeddedObject -
                    // so that when we reduce the element type fromm UIContainer to Run/Paragraph
                    // we also output just a space instead of the embedded object conntained in it.
                    elementTypeStandardized = TextSchema.GetStandardElementType(elementType, /*reduceElement:*/true);
                }
            }
            else if (preserveTextElements)
            {
                elementTypeStandardized = elementType;
            }

            bool customTextElement = preserveTextElements && !TextSchema.IsKnownType(elementType);
            if (customTextElement)
            {
                // If the element is not from PresentationFramework, we'll need to serialize a namespace
                // 
                int index = elementTypeStandardized.Module.Name.LastIndexOf('.');
                string assembly = (index == -1 ? elementTypeStandardized.Module.Name : elementTypeStandardized.Module.Name.Substring(0, index));
                string nameSpace = "clr-namespace:" + elementTypeStandardized.Namespace + ";" + "assembly=" + assembly;
                string prefix = elementTypeStandardized.Namespace;
                xmlWriter.WriteStartElement(prefix, elementTypeStandardized.Name, nameSpace);
            }
            else
            {
                xmlWriter.WriteStartElement(elementTypeStandardized.Name);
            }

            // Write properties
            DependencyObject complexProperties = new DependencyObject();
            WriteInheritableProperties(elementTypeStandardized, textReader, xmlWriter, /*onlyAffected:*/true, complexProperties);
            WriteNoninheritableProperties(elementTypeStandardized, textReader, xmlWriter, /*onlyAffected:*/true, complexProperties);
            if (customTextElement)
            {
                WriteLocallySetProperties(elementTypeStandardized, textReader, xmlWriter, complexProperties);
            }
            WriteComplexProperties(xmlWriter, complexProperties, elementTypeStandardized);

            // Special case for Table element serialization
            if (elementTypeStandardized == typeof(Table) && textReader is TextPointer)
            {
                // Write the columns text.
                WriteTableColumnsInformation(range, (Table)((TextPointer)textReader).Parent, xmlWriter, xamlTypeMapper);
            }
        }
        // Token: 0x06002D1F RID: 11551 RVA: 0x000CBAC0 File Offset: 0x000C9CC0
        internal object BuildObjectTree()
        {
            FixedElement.ElementType type = this._type;
            IAddChild addChild;

            if (type != FixedElement.ElementType.Paragraph)
            {
                switch (type)
                {
                case FixedElement.ElementType.Table:
                    addChild = new Table();
                    goto IL_C7;

                case FixedElement.ElementType.TableRowGroup:
                    addChild = new TableRowGroup();
                    goto IL_C7;

                case FixedElement.ElementType.TableRow:
                    addChild = new TableRow();
                    goto IL_C7;

                case FixedElement.ElementType.TableCell:
                    addChild = new TableCell();
                    goto IL_C7;

                case FixedElement.ElementType.Hyperlink:
                {
                    Hyperlink hyperlink = new Hyperlink();
                    hyperlink.NavigateUri      = (base.GetValue(FixedElement.NavigateUriProperty) as Uri);
                    hyperlink.RequestNavigate += this.ClickHyperlink;
                    AutomationProperties.SetHelpText(hyperlink, (string)base.GetValue(FixedElement.HelpTextProperty));
                    AutomationProperties.SetName(hyperlink, (string)base.GetValue(FixedElement.NameProperty));
                    addChild = hyperlink;
                    goto IL_C7;
                }
                }
                addChild = null;
            }
            else
            {
                addChild = new Paragraph();
            }
IL_C7:
            ITextPointer textPointer = ((ITextPointer)this._start).CreatePointer();

            while (textPointer.CompareTo(this._end) < 0)
            {
                TextPointerContext pointerContext = textPointer.GetPointerContext(LogicalDirection.Forward);
                if (pointerContext == TextPointerContext.Text)
                {
                    addChild.AddText(textPointer.GetTextInRun(LogicalDirection.Forward));
                }
                else if (pointerContext == TextPointerContext.EmbeddedElement)
                {
                    addChild.AddChild(textPointer.GetAdjacentElement(LogicalDirection.Forward));
                }
                else if (pointerContext == TextPointerContext.ElementStart)
                {
                    object adjacentElement = textPointer.GetAdjacentElement(LogicalDirection.Forward);
                    if (adjacentElement != null)
                    {
                        addChild.AddChild(adjacentElement);
                        textPointer.MoveToNextContextPosition(LogicalDirection.Forward);
                        textPointer.MoveToElementEdge(ElementEdge.BeforeEnd);
                    }
                }
                textPointer.MoveToNextContextPosition(LogicalDirection.Forward);
            }
            return(addChild);
        }