Exemplo n.º 1
0
        /// <summary>
        ///     Searches the logical tree for a node matching the values of
        ///     locatorPart.  A match must be a chunk which produces the same
        ///     fingerprint as in the locator part.
        /// </summary>
        /// <param name="locatorPart">locator part to be matched, must be of the type
        /// handled by this processor</param>
        /// <param name="startNode">logical tree node to start search at</param>
        /// <param name="continueResolving">return flag indicating whether the search
        /// should continue (presumably because the search was not exhaustive). This
        /// processor will return false if the startNode is a FixedPage
        /// with a different page number than the locator part's page number.
        /// Otherwise the return value will be true.
        /// inside the FixedPage(like TextSelection) </param>
        /// <returns>returns a node that matches the locator part; null if no such
        /// node is found</returns>
        /// <exception cref="ArgumentNullException">locatorPart or startNode are
        /// null</exception>
        /// <exception cref="ArgumentException">locatorPart is of the incorrect
        /// type</exception>
        public override DependencyObject ResolveLocatorPart(ContentLocatorPart locatorPart, DependencyObject startNode, out bool continueResolving)
        {
            if (locatorPart == null)
            {
                throw new ArgumentNullException("locatorPart");
            }

            if (startNode == null)
            {
                throw new ArgumentNullException("startNode");
            }

            if (PageNumberElementName != locatorPart.PartType)
            {
                throw new ArgumentException(SR.Get(SRID.IncorrectLocatorPartType, locatorPart.PartType.Namespace + ":" + locatorPart.PartType.Name), "locatorPart");
            }

            // Initial value
            continueResolving = true;

            int    pageNumber       = 0;
            string pageNumberString = locatorPart.NameValuePairs[ValueAttributeName];

            if (pageNumberString != null)
            {
                pageNumber = Int32.Parse(pageNumberString, NumberFormatInfo.InvariantInfo);
            }
            else
            {
                throw new ArgumentException(SR.Get(SRID.IncorrectLocatorPartType, locatorPart.PartType.Namespace + ":" + locatorPart.PartType.Name), "locatorPart");
            }


            // Get the actual FixedPage for the page number specified in the LocatorPart.  We need
            // the actual FixedPage cause its what exists in the visual tree and what we'll use to
            // anchor the annotations to.
            FixedDocumentPage        page     = null;
            IDocumentPaginatorSource document = null;
            DocumentPageView         dpv      = null;

            if (_useLogicalTree)
            {
                document = startNode as FixedDocument;
                if (document != null)
                {
                    page = document.DocumentPaginator.GetPage(pageNumber) as FixedDocumentPage;
                }
                else
                {
                    document = startNode as FixedDocumentSequence;
                    if (document != null)
                    {
                        FixedDocumentSequenceDocumentPage sequencePage = document.DocumentPaginator.GetPage(pageNumber) as FixedDocumentSequenceDocumentPage;
                        if (sequencePage != null)
                        {
                            page = sequencePage.ChildDocumentPage as FixedDocumentPage;
                        }
                    }
                }
            }
            else
            {
                dpv = startNode as DocumentPageView;
                if (dpv != null)
                {
                    page = dpv.DocumentPage as FixedDocumentPage;
                    if (page == null)
                    {
                        FixedDocumentSequenceDocumentPage sequencePage = dpv.DocumentPage as FixedDocumentSequenceDocumentPage;
                        if (sequencePage != null)
                        {
                            page = sequencePage.ChildDocumentPage as FixedDocumentPage;
                        }
                    }

                    // If this was the wrong fixed page we want to stop searching this subtree
                    if (page != null && dpv.PageNumber != pageNumber)
                    {
                        continueResolving = false;
                        page = null;
                    }
                }
            }

            if (page != null)
            {
                return(page.FixedPage);
            }

            return(null);
        }
Exemplo n.º 2
0
        // Token: 0x06007BC8 RID: 31688 RVA: 0x0022C61C File Offset: 0x0022A81C
        public override DependencyObject ResolveLocatorPart(ContentLocatorPart locatorPart, DependencyObject startNode, out bool continueResolving)
        {
            if (locatorPart == null)
            {
                throw new ArgumentNullException("locatorPart");
            }
            if (startNode == null)
            {
                throw new ArgumentNullException("startNode");
            }
            if (FixedPageProcessor.PageNumberElementName != locatorPart.PartType)
            {
                throw new ArgumentException(SR.Get("IncorrectLocatorPartType", new object[]
                {
                    locatorPart.PartType.Namespace + ":" + locatorPart.PartType.Name
                }), "locatorPart");
            }
            continueResolving = true;
            string text = locatorPart.NameValuePairs[FixedPageProcessor.ValueAttributeName];

            if (text == null)
            {
                throw new ArgumentException(SR.Get("IncorrectLocatorPartType", new object[]
                {
                    locatorPart.PartType.Namespace + ":" + locatorPart.PartType.Name
                }), "locatorPart");
            }
            int num = int.Parse(text, NumberFormatInfo.InvariantInfo);
            FixedDocumentPage fixedDocumentPage = null;

            if (this._useLogicalTree)
            {
                IDocumentPaginatorSource documentPaginatorSource = startNode as FixedDocument;
                if (documentPaginatorSource != null)
                {
                    fixedDocumentPage = (documentPaginatorSource.DocumentPaginator.GetPage(num) as FixedDocumentPage);
                }
                else
                {
                    documentPaginatorSource = (startNode as FixedDocumentSequence);
                    if (documentPaginatorSource != null)
                    {
                        FixedDocumentSequenceDocumentPage fixedDocumentSequenceDocumentPage = documentPaginatorSource.DocumentPaginator.GetPage(num) as FixedDocumentSequenceDocumentPage;
                        if (fixedDocumentSequenceDocumentPage != null)
                        {
                            fixedDocumentPage = (fixedDocumentSequenceDocumentPage.ChildDocumentPage as FixedDocumentPage);
                        }
                    }
                }
            }
            else
            {
                DocumentPageView documentPageView = startNode as DocumentPageView;
                if (documentPageView != null)
                {
                    fixedDocumentPage = (documentPageView.DocumentPage as FixedDocumentPage);
                    if (fixedDocumentPage == null)
                    {
                        FixedDocumentSequenceDocumentPage fixedDocumentSequenceDocumentPage2 = documentPageView.DocumentPage as FixedDocumentSequenceDocumentPage;
                        if (fixedDocumentSequenceDocumentPage2 != null)
                        {
                            fixedDocumentPage = (fixedDocumentSequenceDocumentPage2.ChildDocumentPage as FixedDocumentPage);
                        }
                    }
                    if (fixedDocumentPage != null && documentPageView.PageNumber != num)
                    {
                        continueResolving = false;
                        fixedDocumentPage = null;
                    }
                }
            }
            if (fixedDocumentPage != null)
            {
                return(fixedDocumentPage.FixedPage);
            }
            return(null);
        }