Exemple #1
0
        // Token: 0x06007C33 RID: 31795 RVA: 0x0022EB24 File Offset: 0x0022CD24
        public static IList <DependencyObject> GetSelectedNodes(object selection)
        {
            if (selection == null)
            {
                throw new ArgumentNullException("selection");
            }
            ITextPointer        textPointer = null;
            ITextPointer        position    = null;
            IList <TextSegment> list;

            TextSelectionHelper.CheckSelection(selection, out textPointer, out position, out list);
            IList <DependencyObject> list2 = new List <DependencyObject>();

            if (textPointer.CompareTo(position) == 0)
            {
                list2.Add(((TextPointer)textPointer).Parent);
                return(list2);
            }
            TextPointer textPointer2 = (TextPointer)textPointer.CreatePointer();

            while (((ITextPointer)textPointer2).CompareTo(position) < 0)
            {
                DependencyObject parent = textPointer2.Parent;
                if (!list2.Contains(parent))
                {
                    list2.Add(parent);
                }
                textPointer2.MoveToNextContextPosition(LogicalDirection.Forward);
            }
            return(list2);
        }
Exemple #2
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);
        }
Exemple #3
0
        // Token: 0x06007C39 RID: 31801 RVA: 0x0022EDE4 File Offset: 0x0022CFE4
        public static Rect GetAnchorRectangle(ITextPointer pointer)
        {
            if (pointer == null)
            {
                throw new ArgumentNullException("pointer");
            }
            bool      flag = false;
            ITextView documentPageTextView = TextSelectionHelper.GetDocumentPageTextView(pointer);

            if (pointer.CompareTo(pointer.TextContainer.End) == 0)
            {
                Point point = new Point(double.MaxValue, double.MaxValue);
                pointer = documentPageTextView.GetTextPositionFromPoint(point, true);
                flag    = true;
            }
            if (documentPageTextView != null && documentPageTextView.IsValid && TextDocumentView.Contains(pointer, documentPageTextView.TextSegments))
            {
                Rect rectangleFromTextPosition = documentPageTextView.GetRectangleFromTextPosition(pointer);
                if (flag && rectangleFromTextPosition != Rect.Empty)
                {
                    rectangleFromTextPosition.X += rectangleFromTextPosition.Height / 2.0;
                }
                return(rectangleFromTextPosition);
            }
            return(Rect.Empty);
        }
        // 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);
        }
Exemple #5
0
        // Token: 0x06007C34 RID: 31796 RVA: 0x0022EBB0 File Offset: 0x0022CDB0
        public static UIElement GetParent(object selection)
        {
            if (selection == null)
            {
                throw new ArgumentNullException("selection");
            }
            ITextPointer        pointer     = null;
            ITextPointer        textPointer = null;
            IList <TextSegment> list;

            TextSelectionHelper.CheckSelection(selection, out pointer, out textPointer, out list);
            return(TextSelectionHelper.GetParent(pointer));
        }
Exemple #6
0
        // Token: 0x06007C38 RID: 31800 RVA: 0x0022ED78 File Offset: 0x0022CF78
        public static Point GetPointForPointer(ITextPointer pointer)
        {
            if (pointer == null)
            {
                throw new ArgumentNullException("pointer");
            }
            Rect anchorRectangle = TextSelectionHelper.GetAnchorRectangle(pointer);

            if (anchorRectangle != Rect.Empty)
            {
                return(new Point(anchorRectangle.Left, anchorRectangle.Top + anchorRectangle.Height / 2.0));
            }
            return(new Point(0.0, 0.0));
        }
Exemple #7
0
        // Token: 0x06007C36 RID: 31798 RVA: 0x0022ECC8 File Offset: 0x0022CEC8
        public static Point GetAnchorPoint(object selection)
        {
            if (selection == null)
            {
                throw new ArgumentNullException("selection");
            }
            TextAnchor textAnchor = selection as TextAnchor;

            if (textAnchor == null)
            {
                throw new ArgumentException(SR.Get("WrongSelectionType"), "selection");
            }
            return(TextSelectionHelper.GetAnchorPointForPointer(textAnchor.Start.CreatePointer(LogicalDirection.Forward)));
        }
        // Token: 0x06007C45 RID: 31813 RVA: 0x0022F240 File Offset: 0x0022D440
        public override IList <ContentLocatorPart> GenerateLocatorParts(object selection, DependencyObject startNode)
        {
            if (startNode == null)
            {
                throw new ArgumentNullException("startNode");
            }
            if (selection == null)
            {
                throw new ArgumentNullException("selection");
            }
            IList <TextSegment> list = null;
            ITextPointer        textPointer;
            ITextPointer        position;

            TextSelectionHelper.CheckSelection(selection, out textPointer, out position, out list);
            if (!(textPointer is TextPointer))
            {
                throw new ArgumentException(SR.Get("WrongSelectionType"), "selection");
            }
            ITextPointer textPointer2;
            ITextPointer textPointer3;

            if (!this.GetNodesStartAndEnd(startNode, out textPointer2, out textPointer3))
            {
                return(null);
            }
            if (textPointer2.CompareTo(position) > 0)
            {
                throw new ArgumentException(SR.Get("InvalidStartNodeForTextSelection"), "startNode");
            }
            if (textPointer3.CompareTo(textPointer) < 0)
            {
                throw new ArgumentException(SR.Get("InvalidStartNodeForTextSelection"), "startNode");
            }
            ContentLocatorPart contentLocatorPart = new ContentLocatorPart(TextSelectionProcessor.CharacterRangeElementName);
            int num  = 0;
            int num2 = 0;

            for (int i = 0; i < list.Count; i++)
            {
                this.GetTextSegmentValues(list[i], textPointer2, textPointer3, out num, out num2);
                contentLocatorPart.NameValuePairs.Add("Segment" + i.ToString(NumberFormatInfo.InvariantInfo), num.ToString(NumberFormatInfo.InvariantInfo) + TextSelectionProcessor.Separator[0].ToString() + num2.ToString(NumberFormatInfo.InvariantInfo));
            }
            contentLocatorPart.NameValuePairs.Add("Count", list.Count.ToString(NumberFormatInfo.InvariantInfo));
            return(new List <ContentLocatorPart>(1)
            {
                contentLocatorPart
            });
        }
Exemple #9
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);
        }
Exemple #10
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);
        }
 /// <summary>
 /// Gets the anchor point for the selection. This is the Point that corresponds
 /// to the start position of the selection
 /// </summary>
 /// <param name="selection">the selection to examine. Must implement ITextRange</param>
 /// <returns>the anchor point of the selection; can be (double.NaN, double.NaN) if the
 /// selection start point is not contained in a document viewer</returns>
 /// <exception cref="ArgumentNullException">selection is null</exception>
 /// <exception cref="ArgumentException">selection is of wrong type</exception>
 public override Point GetAnchorPoint(Object selection)
 {
     CheckAnchor(selection);
     return(TextSelectionHelper.GetAnchorPoint(selection));
 }
 /// <summary>
 /// Gets the parent element of this selection. The parent element is the
 /// FixedPage that contains selection.Start TextPointer.
 /// </summary>
 /// <param name="selection">the selection to examine. Must implement ITextRange</param>
 /// <returns>the parent element of the selection; can be null</returns>
 /// <exception cref="ArgumentNullException">selection is null</exception>
 /// <exception cref="ArgumentException">selection is of wrong type</exception>
 public override UIElement GetParent(Object selection)
 {
     CheckAnchor(selection);
     return(TextSelectionHelper.GetParent(selection));
 }
 /// <summary>
 ///     Gets the tree elements spanned by the selection.
 /// </summary>
 /// <param name="selection">the selection to examine</param>
 /// <returns>a list of elements spanned by the selection; never returns
 /// null</returns>
 /// <exception cref="ArgumentNullException">selection is null</exception>
 /// <exception cref="ArgumentException">selection is of wrong type</exception>
 public override IList <DependencyObject> GetSelectedNodes(Object selection)
 {
     return(TextSelectionHelper.GetSelectedNodes(selection));
 }
        GenerateLocatorParts(Object selection, DependencyObject startNode)
        {
            if (startNode == null)
            {
                throw new ArgumentNullException("startNode");
            }

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

            ITextPointer        start;
            ITextPointer        end;
            IList <TextSegment> textSegments = null;

            TextSelectionHelper.CheckSelection(selection, out start, out end, out textSegments);
            if (!(start is TextPointer))
            {
                throw new ArgumentException(SR.Get(SRID.WrongSelectionType), "selection");
            }

            ITextPointer elementStart;
            ITextPointer elementEnd;

            // If we can't get the start/end of the node then we can't generate a locator part
            if (!GetNodesStartAndEnd(startNode, out elementStart, out elementEnd))
            {
                return(null);
            }

            if (elementStart.CompareTo(end) > 0)
            {
                throw new ArgumentException(SR.Get(SRID.InvalidStartNodeForTextSelection), "startNode");
            }

            if (elementEnd.CompareTo(start) < 0)
            {
                throw new ArgumentException(SR.Get(SRID.InvalidStartNodeForTextSelection), "startNode");
            }

            ContentLocatorPart part = new ContentLocatorPart(CharacterRangeElementName);

            int startOffset = 0;
            int endOffset   = 0;

            for (int i = 0; i < textSegments.Count; i++)
            {
                GetTextSegmentValues(textSegments[i], elementStart, elementEnd, out startOffset, out endOffset);

                part.NameValuePairs.Add(SegmentAttribute + i.ToString(NumberFormatInfo.InvariantInfo), startOffset.ToString(NumberFormatInfo.InvariantInfo) + TextSelectionProcessor.Separator[0] + endOffset.ToString(NumberFormatInfo.InvariantInfo));
            }

            part.NameValuePairs.Add(CountAttribute, textSegments.Count.ToString(NumberFormatInfo.InvariantInfo));

            List <ContentLocatorPart> res = new List <ContentLocatorPart>(1);

            res.Add(part);

            return(res);
        }
 // Token: 0x06007C43 RID: 31811 RVA: 0x0022F22D File Offset: 0x0022D42D
 public override UIElement GetParent(object selection)
 {
     return(TextSelectionHelper.GetParent(selection));
 }
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        /// Merges the two anchors into one, if possible. It does not require
        /// the anchors to be connected. All this method does is to create a
        /// TextAnchor that spans the two anchors.
        /// </summary>
        /// <param name="anchor1">anchor to merge. Must be a TextAnchor. </param>
        /// <param name="anchor2">other anchor to merge. Must be a TextAnchor. </param>
        /// <param name="newAnchor">new anchor that contains the data from both
        /// anchor1 and anchor2</param>
        /// <returns>true if the anchors were merged, false otherwise
        /// </returns>
        public override bool MergeSelections(Object anchor1, Object anchor2, out Object newAnchor)
        {
            return(TextSelectionHelper.MergeSelections(anchor1, anchor2, out newAnchor));
        }
        /// <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);
        }
 // Token: 0x06007C44 RID: 31812 RVA: 0x0022F235 File Offset: 0x0022D435
 public override Point GetAnchorPoint(object selection)
 {
     return(TextSelectionHelper.GetAnchorPoint(selection));
 }