// Token: 0x06007BCF RID: 31695 RVA: 0x0022C850 File Offset: 0x0022AA50
        public override IList <DependencyObject> GetSelectedNodes(object selection)
        {
            IList <TextSegment>      list  = this.CheckSelection(selection);
            IList <DependencyObject> list2 = new List <DependencyObject>();

            foreach (TextSegment textSegment in list)
            {
                int          minValue = int.MinValue;
                ITextPointer pointer  = textSegment.Start.CreatePointer(LogicalDirection.Forward);
                TextSelectionHelper.GetPointerPage(pointer, out minValue);
                Point pointForPointer = TextSelectionHelper.GetPointForPointer(pointer);
                if (minValue == -2147483648)
                {
                    throw new ArgumentException(SR.Get("SelectionDoesNotResolveToAPage", new object[]
                    {
                        "start"
                    }), "selection");
                }
                int          minValue2 = int.MinValue;
                ITextPointer pointer2  = textSegment.End.CreatePointer(LogicalDirection.Backward);
                TextSelectionHelper.GetPointerPage(pointer2, out minValue2);
                Point pointForPointer2 = TextSelectionHelper.GetPointForPointer(pointer2);
                if (minValue2 == -2147483648)
                {
                    throw new ArgumentException(SR.Get("SelectionDoesNotResolveToAPage", new object[]
                    {
                        "end"
                    }), "selection");
                }
                int num  = list2.Count;
                int num2 = minValue2 - minValue;
                int i    = 0;
                if (list2.Count > 0 && ((FixedTextSelectionProcessor.FixedPageProxy)list2[list2.Count - 1]).Page == minValue)
                {
                    num--;
                    i++;
                }
                while (i <= num2)
                {
                    list2.Add(new FixedTextSelectionProcessor.FixedPageProxy(textSegment.Start.TextContainer.Parent, minValue + i));
                    i++;
                }
                if (num2 == 0)
                {
                    ((FixedTextSelectionProcessor.FixedPageProxy)list2[num]).Segments.Add(new FixedTextSelectionProcessor.PointSegment(pointForPointer, pointForPointer2));
                }
                else
                {
                    ((FixedTextSelectionProcessor.FixedPageProxy)list2[num]).Segments.Add(new FixedTextSelectionProcessor.PointSegment(pointForPointer, FixedTextSelectionProcessor.PointSegment.NotAPoint));
                    ((FixedTextSelectionProcessor.FixedPageProxy)list2[num + num2]).Segments.Add(new FixedTextSelectionProcessor.PointSegment(FixedTextSelectionProcessor.PointSegment.NotAPoint, pointForPointer2));
                }
            }
            return(list2);
        }
コード例 #2
0
        /// <summary>
        ///  Generates FixedPageProxy objects for each page, spaned by the selection
        /// </summary>
        /// <param name="selection">the selection to examine. Must implement ITextRange</param>
        /// <returns>a list of FixedPageProxy objects, corresponding to each page spanned by the selection; never returns
        /// null</returns>
        /// <exception cref="ArgumentNullException">selection is null</exception>
        /// <exception cref="ArgumentException">selection is of wrong type</exception>
        /// <exception cref="ArgumentException">selection start or end point can not be resolved to a page</exception>
        public override IList <DependencyObject> GetSelectedNodes(Object selection)
        {
            IList <TextSegment> textSegments = CheckSelection(selection);

            IList <DependencyObject> pageEl = new List <DependencyObject>();

            Point start;
            Point end;

            foreach (TextSegment segment in textSegments)
            {
                int          startPage    = int.MinValue;
                ITextPointer startPointer = segment.Start.CreatePointer(LogicalDirection.Forward);
                TextSelectionHelper.GetPointerPage(startPointer, out startPage);
                start = TextSelectionHelper.GetPointForPointer(startPointer);
                if (startPage == int.MinValue)
                {
                    throw new ArgumentException(SR.Get(SRID.SelectionDoesNotResolveToAPage, "start"), "selection");
                }

                int          endPage    = int.MinValue;
                ITextPointer endPointer = segment.End.CreatePointer(LogicalDirection.Backward);
                TextSelectionHelper.GetPointerPage(endPointer, out endPage);
                end = TextSelectionHelper.GetPointForPointer(endPointer);
                if (endPage == int.MinValue)
                {
                    throw new ArgumentException(SR.Get(SRID.SelectionDoesNotResolveToAPage, "end"), "selection");
                }

                int firstPage  = pageEl.Count;
                int numOfPages = endPage - startPage;

                Debug.Assert(numOfPages >= 0, "start page number is bigger than the end page number");

                // If the first page of this segment already has an FPP, then use that one for an additional segment
                int i = 0;

                if (pageEl.Count > 0 && ((FixedPageProxy)pageEl[pageEl.Count - 1]).Page == startPage)
                {
                    firstPage--; // use the existing one from the list as the first
                    i++;         // make 1 fewer FPPs
                }

                for (; i <= numOfPages; i++)
                {
                    pageEl.Add(new FixedPageProxy(segment.Start.TextContainer.Parent, startPage + i));
                }

                // If entire segment is on one page set both start/end on that page
                if (numOfPages == 0)
                {
                    ((FixedPageProxy)pageEl[firstPage]).Segments.Add(new PointSegment(start, end));
                }
                else
                {
                    // otherwise set start on the first page and end on the last page
                    ((FixedPageProxy)pageEl[firstPage]).Segments.Add(new PointSegment(start, PointSegment.NotAPoint));
                    ((FixedPageProxy)pageEl[firstPage + numOfPages]).Segments.Add(new PointSegment(PointSegment.NotAPoint, end));
                }
            }

            return(pageEl);
        }