Exemplo n.º 1
0
        internal int GetPageNumber(ITextPointer textPointer)
        {
            FixedTextPointer fixedTextPointer = textPointer as FixedTextPointer;
            int pageNumber = int.MaxValue;

            if (fixedTextPointer != null)
            {
                if (fixedTextPointer.CompareTo(((ITextContainer)this).Start) == 0)
                {
                    pageNumber = 0;
                }
                else if (fixedTextPointer.CompareTo(((ITextContainer)this).End) == 0)
                {
                    pageNumber = this.FixedDocument.PageCount - 1;
                }
                else
                {
                    FlowNode flowNode;
                    int      flowOffset;

                    fixedTextPointer.FlowPosition.GetFlowNode(fixedTextPointer.LogicalDirection, out flowNode, out flowOffset);

                    FixedElement fixedElement = flowNode.Cookie as FixedElement;

                    if (flowNode.Type == FlowNodeType.Boundary)
                    {
                        if (flowNode.Fp > 0)
                        {
                            //Document end boundary node
                            pageNumber = this.FixedDocument.PageCount - 1;
                        }
                        else
                        {
                            //Document start boundary node
                            pageNumber = 0;
                        }
                    }
                    else if (flowNode.Type == FlowNodeType.Virtual || flowNode.Type == FlowNodeType.Noop)
                    {
                        pageNumber = (int)flowNode.Cookie;
                    }
                    else if (fixedElement != null)
                    {
                        pageNumber = (int)fixedElement.PageIndex;
                    }
                    else
                    {
                        FixedPosition fixPos;
                        bool          res = FixedTextBuilder.GetFixedPosition(fixedTextPointer.FlowPosition, fixedTextPointer.LogicalDirection, out fixPos);
                        Debug.Assert(res);
                        if (res)
                        {
                            pageNumber = fixPos.Page;
                        }
                    }
                }
            }

            return(pageNumber);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whenever TextView contains specified position.
        /// </summary>
        /// <param name="position">
        /// A position to test.
        /// </param>
        /// <returns>
        /// True if TextView contains specified text position.
        /// Otherwise returns false.
        /// </returns>
        /// <exception cref="System.InvalidOperationException">
        /// Throws InvalidOperationException if IsValid is false.
        /// If IsValid returns false, Validate method must be called before
        /// calling this method.
        /// </exception>
        internal override bool Contains(ITextPointer position)
        {
            FixedTextPointer tp = Container.VerifyPosition(position);

            return((tp.CompareTo(this.Start) > 0 && tp.CompareTo(this.End) < 0) ||
                   (tp.CompareTo(this.Start) == 0 && (tp.LogicalDirection == LogicalDirection.Forward || this.IsContainerStart)) ||
                   (tp.CompareTo(this.End) == 0 && (tp.LogicalDirection == LogicalDirection.Backward || this.IsContainerEnd))
                   );
        }
Exemplo n.º 3
0
        // Token: 0x06002EA0 RID: 11936 RVA: 0x000D2AD4 File Offset: 0x000D0CD4
        internal int GetPageNumber(ITextPointer textPointer)
        {
            FixedTextPointer fixedTextPointer = textPointer as FixedTextPointer;
            int result = int.MaxValue;

            if (fixedTextPointer != null)
            {
                if (fixedTextPointer.CompareTo(((ITextContainer)this).Start) == 0)
                {
                    result = 0;
                }
                else if (fixedTextPointer.CompareTo(((ITextContainer)this).End) == 0)
                {
                    result = this.FixedDocument.PageCount - 1;
                }
                else
                {
                    FlowNode flowNode;
                    int      num;
                    fixedTextPointer.FlowPosition.GetFlowNode(fixedTextPointer.LogicalDirection, out flowNode, out num);
                    FixedElement fixedElement = flowNode.Cookie as FixedElement;
                    if (flowNode.Type == FlowNodeType.Boundary)
                    {
                        if (flowNode.Fp > 0)
                        {
                            result = this.FixedDocument.PageCount - 1;
                        }
                        else
                        {
                            result = 0;
                        }
                    }
                    else if (flowNode.Type == FlowNodeType.Virtual || flowNode.Type == FlowNodeType.Noop)
                    {
                        result = (int)flowNode.Cookie;
                    }
                    else if (fixedElement != null)
                    {
                        result = fixedElement.PageIndex;
                    }
                    else
                    {
                        FixedPosition fixedPosition2;
                        bool          fixedPosition = this.FixedTextBuilder.GetFixedPosition(fixedTextPointer.FlowPosition, fixedTextPointer.LogicalDirection, out fixedPosition2);
                        if (fixedPosition)
                        {
                            result = fixedPosition2.Page;
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        // Get the highlights, in Glyphs granularity, that covers this range
        internal void GetMultiHighlights(FixedTextPointer start, FixedTextPointer end, Dictionary<FixedPage, ArrayList> highlights, FixedHighlightType t,
            Brush foregroundBrush, Brush backgroundBrush)
        {
            Debug.Assert(highlights != null);
            if (start.CompareTo(end) > 0)
            {
                // make sure start <= end
                FixedTextPointer temp = start;
                start = end;
                end = temp;
            }

            FixedSOMElement[] elements;
            //Start and end indices in selection for first and last FixedSOMElements respectively
            int startIndex = 0;
            int endIndex = 0;
            if (_GetFixedNodesForFlowRange(start, end, out elements, out startIndex, out endIndex))
            {
                for(int i=0; i<elements.Length; i++)
                {
                    FixedSOMElement elem = elements[i];
                    
                    FixedNode fn = elem.FixedNode;
                    // Get the FixedPage if possible
                    FixedPage page = this.FixedDocument.SyncGetPageWithCheck(fn.Page);
                    if (page == null)
                    {
                        continue;
                    }

                    DependencyObject o = page.GetElement(fn);
                    if (o == null)
                    {
                        continue;
                    }

                    int beginOffset = 0;
                    int endOffset;
                    UIElement e;
                    if (o is Image || o is Path)
                    {
                        e = (UIElement)o;
                        endOffset = 1;
                    }
                    else
                    {
                        Glyphs g = o as Glyphs;
                        if (g == null)
                        {
                            continue;
                        }
                        e = (UIElement)o;
                        beginOffset = elem.StartIndex;
                        endOffset = elem.EndIndex;
                    }

                    if (i == 0)
                    {
                        beginOffset = startIndex;
                    }

                    if (i == elements.Length - 1)
                    {
                        endOffset = endIndex;
                    }

                    ArrayList lfs;
                    if (highlights.ContainsKey(page))
                    {
                        lfs = highlights[page];
                    }
                    else
                    {
                        lfs = new ArrayList();
                        highlights.Add(page, lfs);
                    }

                    FixedSOMTextRun textRun = elem as FixedSOMTextRun;
                    if (textRun != null && textRun.IsReversed)
                    {
                        int oldBeginOffset = beginOffset;
                        beginOffset = elem.EndIndex - endOffset;
                        endOffset = elem.EndIndex - oldBeginOffset;
                    }

                    FixedHighlight fh = new FixedHighlight(e, beginOffset, endOffset, t, foregroundBrush, backgroundBrush);
                    lfs.Add(fh);
                }
            }
        }
Exemplo n.º 5
0
        // Token: 0x06002EA1 RID: 11937 RVA: 0x000D2BCC File Offset: 0x000D0DCC
        internal void GetMultiHighlights(FixedTextPointer start, FixedTextPointer end, Dictionary <FixedPage, ArrayList> highlights, FixedHighlightType t, Brush foregroundBrush, Brush backgroundBrush)
        {
            if (start.CompareTo(end) > 0)
            {
                FixedTextPointer fixedTextPointer = start;
                start = end;
                end   = fixedTextPointer;
            }
            int num  = 0;
            int num2 = 0;

            FixedSOMElement[] array;
            if (this._GetFixedNodesForFlowRange(start, end, out array, out num, out num2))
            {
                for (int i = 0; i < array.Length; i++)
                {
                    FixedSOMElement fixedSOMElement = array[i];
                    FixedNode       fixedNode       = fixedSOMElement.FixedNode;
                    FixedPage       fixedPage       = this.FixedDocument.SyncGetPageWithCheck(fixedNode.Page);
                    if (fixedPage != null)
                    {
                        DependencyObject element = fixedPage.GetElement(fixedNode);
                        if (element != null)
                        {
                            int       num3 = 0;
                            UIElement element2;
                            int       num4;
                            if (element is Image || element is Path)
                            {
                                element2 = (UIElement)element;
                                num4     = 1;
                            }
                            else
                            {
                                Glyphs glyphs = element as Glyphs;
                                if (glyphs == null)
                                {
                                    goto IL_144;
                                }
                                element2 = (UIElement)element;
                                num3     = fixedSOMElement.StartIndex;
                                num4     = fixedSOMElement.EndIndex;
                            }
                            if (i == 0)
                            {
                                num3 = num;
                            }
                            if (i == array.Length - 1)
                            {
                                num4 = num2;
                            }
                            ArrayList arrayList;
                            if (highlights.ContainsKey(fixedPage))
                            {
                                arrayList = highlights[fixedPage];
                            }
                            else
                            {
                                arrayList = new ArrayList();
                                highlights.Add(fixedPage, arrayList);
                            }
                            FixedSOMTextRun fixedSOMTextRun = fixedSOMElement as FixedSOMTextRun;
                            if (fixedSOMTextRun != null && fixedSOMTextRun.IsReversed)
                            {
                                int num5 = num3;
                                num3 = fixedSOMElement.EndIndex - num4;
                                num4 = fixedSOMElement.EndIndex - num5;
                            }
                            FixedHighlight value = new FixedHighlight(element2, num3, num4, t, foregroundBrush, backgroundBrush);
                            arrayList.Add(value);
                        }
                    }
                    IL_144 :;
                }
            }
        }
Exemplo n.º 6
0
        // Get the highlights, in Glyphs granularity, that covers this range
        internal void GetMultiHighlights(FixedTextPointer start, FixedTextPointer end, Dictionary <FixedPage, ArrayList> highlights, FixedHighlightType t,
                                         Brush foregroundBrush, Brush backgroundBrush)
        {
            Debug.Assert(highlights != null);
            if (start.CompareTo(end) > 0)
            {
                // make sure start <= end
                FixedTextPointer temp = start;
                start = end;
                end   = temp;
            }

            FixedSOMElement[] elements;
            //Start and end indices in selection for first and last FixedSOMElements respectively
            int startIndex = 0;
            int endIndex   = 0;

            if (_GetFixedNodesForFlowRange(start, end, out elements, out startIndex, out endIndex))
            {
                for (int i = 0; i < elements.Length; i++)
                {
                    FixedSOMElement elem = elements[i];

                    FixedNode fn = elem.FixedNode;
                    // Get the FixedPage if possible
                    FixedPage page = this.FixedDocument.SyncGetPageWithCheck(fn.Page);
                    if (page == null)
                    {
                        continue;
                    }

                    DependencyObject o = page.GetElement(fn);
                    if (o == null)
                    {
                        continue;
                    }

                    int       beginOffset = 0;
                    int       endOffset;
                    UIElement e;
                    if (o is Image || o is Path)
                    {
                        e         = (UIElement)o;
                        endOffset = 1;
                    }
                    else
                    {
                        Glyphs g = o as Glyphs;
                        if (g == null)
                        {
                            continue;
                        }
                        e           = (UIElement)o;
                        beginOffset = elem.StartIndex;
                        endOffset   = elem.EndIndex;
                    }

                    if (i == 0)
                    {
                        beginOffset = startIndex;
                    }

                    if (i == elements.Length - 1)
                    {
                        endOffset = endIndex;
                    }

                    ArrayList lfs;
                    if (highlights.ContainsKey(page))
                    {
                        lfs = highlights[page];
                    }
                    else
                    {
                        lfs = new ArrayList();
                        highlights.Add(page, lfs);
                    }

                    FixedSOMTextRun textRun = elem as FixedSOMTextRun;
                    if (textRun != null && textRun.IsReversed)
                    {
                        int oldBeginOffset = beginOffset;
                        beginOffset = elem.EndIndex - endOffset;
                        endOffset   = elem.EndIndex - oldBeginOffset;
                    }

                    FixedHighlight fh = new FixedHighlight(e, beginOffset, endOffset, t, foregroundBrush, backgroundBrush);
                    lfs.Add(fh);
                }
            }
        }