Exemplo n.º 1
0
        // Token: 0x06007C3C RID: 31804 RVA: 0x0022EF74 File Offset: 0x0022D174
        internal static ITextView GetDocumentPageTextView(ITextPointer pointer)
        {
            DependencyObject parent = pointer.TextContainer.Parent;

            if (parent != null)
            {
                FlowDocumentScrollViewer flowDocumentScrollViewer = PathNode.GetParent(parent) as FlowDocumentScrollViewer;
                if (flowDocumentScrollViewer != null)
                {
                    IServiceProvider serviceProvider = flowDocumentScrollViewer.ScrollViewer.Content as IServiceProvider;
                    Invariant.Assert(serviceProvider != null, "FlowDocumentScrollViewer should be an IServiceProvider.");
                    return(serviceProvider.GetService(typeof(ITextView)) as ITextView);
                }
            }
            int num;
            IDocumentPaginatorSource pointerPage = TextSelectionHelper.GetPointerPage(pointer, out num);

            if (pointerPage != null && num >= 0)
            {
                DocumentPage     page             = pointerPage.DocumentPaginator.GetPage(num);
                IServiceProvider serviceProvider2 = page as IServiceProvider;
                if (serviceProvider2 != null)
                {
                    return(serviceProvider2.GetService(typeof(ITextView)) as ITextView);
                }
            }
            return(null);
        }
        // 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);
        }
Exemplo n.º 3
0
        // Token: 0x06007C3D RID: 31805 RVA: 0x0022F01C File Offset: 0x0022D21C
        internal static List <ITextView> GetDocumentPageTextViews(TextSegment segment)
        {
            ITextPointer     textPointer  = segment.Start.CreatePointer(LogicalDirection.Forward);
            ITextPointer     textPointer2 = segment.End.CreatePointer(LogicalDirection.Backward);
            DependencyObject parent       = textPointer.TextContainer.Parent;

            if (parent != null)
            {
                FlowDocumentScrollViewer flowDocumentScrollViewer = PathNode.GetParent(parent) as FlowDocumentScrollViewer;
                if (flowDocumentScrollViewer != null)
                {
                    IServiceProvider serviceProvider = flowDocumentScrollViewer.ScrollViewer.Content as IServiceProvider;
                    Invariant.Assert(serviceProvider != null, "FlowDocumentScrollViewer should be an IServiceProvider.");
                    return(new List <ITextView>(1)
                    {
                        serviceProvider.GetService(typeof(ITextView)) as ITextView
                    });
                }
            }
            int num;
            IDocumentPaginatorSource pointerPage = TextSelectionHelper.GetPointerPage(textPointer, out num);
            DynamicDocumentPaginator dynamicDocumentPaginator = pointerPage.DocumentPaginator as DynamicDocumentPaginator;
            int num2 = (dynamicDocumentPaginator != null) ? dynamicDocumentPaginator.GetPageNumber((ContentPosition)textPointer2) : -1;
            List <ITextView> result;

            if (num == -1 || num2 == -1)
            {
                result = new List <ITextView>(0);
            }
            else if (num == num2)
            {
                result = TextSelectionHelper.ProcessSinglePage(pointerPage, num);
            }
            else
            {
                result = TextSelectionHelper.ProcessMultiplePages(pointerPage, num, num2);
            }
            return(result);
        }
Exemplo n.º 4
0
        // Token: 0x06007C35 RID: 31797 RVA: 0x0022EBE4 File Offset: 0x0022CDE4
        public static UIElement GetParent(ITextPointer pointer)
        {
            if (pointer == null)
            {
                throw new ArgumentNullException("pointer");
            }
            DependencyObject         parent  = pointer.TextContainer.Parent;
            DependencyObject         parent2 = PathNode.GetParent(parent);
            FlowDocumentScrollViewer flowDocumentScrollViewer = parent2 as FlowDocumentScrollViewer;

            if (flowDocumentScrollViewer != null)
            {
                return((UIElement)flowDocumentScrollViewer.ScrollViewer.Content);
            }
            DocumentViewerBase documentViewerBase = parent2 as DocumentViewerBase;

            if (documentViewerBase != null)
            {
                int num;
                IDocumentPaginatorSource pointerPage = TextSelectionHelper.GetPointerPage(pointer.CreatePointer(LogicalDirection.Forward), out num);
                if (num >= 0)
                {
                    foreach (DocumentPageView documentPageView in documentViewerBase.PageViews)
                    {
                        if (documentPageView.PageNumber == num)
                        {
                            int childrenCount = VisualTreeHelper.GetChildrenCount(documentPageView);
                            Invariant.Assert(childrenCount == 1);
                            return(VisualTreeHelper.GetChild(documentPageView, 0) as DocumentPageHost);
                        }
                    }
                    return(null);
                }
            }
            return(parent2 as UIElement);
        }
Exemplo n.º 5
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);
        }