Esempio n. 1
0
        /// <summary>
        /// Returns the ContentPosition for the given page.
        /// </summary>
        /// <param name="page">Document page.</param>
        /// <returns>Returns the ContentPosition for the given page.</returns>
        /// <exception cref="ArgumentException">
        /// Throws ArgumentException if the page is not valid.
        /// </exception>
        public override ContentPosition GetPagePosition(DocumentPage page)
        {
            FlowDocumentPage flowDocumentPage;
            ITextView        textView;
            ITextPointer     position;
            Point            point, newPoint;
            MatrixTransform  transform;

            // Ensure usage from just one Dispatcher object.
            // FlowDocumentPaginator runs its own layout, hence there is a need
            // to protect it from random access from other threads.
            _dispatcherObject.VerifyAccess();

            // ContentPosition cannot be null.
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }
            // DocumentPage must be of appropriate type.
            flowDocumentPage = page as FlowDocumentPage;
            if (flowDocumentPage == null || flowDocumentPage.IsDisposed)
            {
                return(ContentPosition.Missing);
            }

            // DocumentPage.Visual for printing scenarions needs to be always returned
            // in LeftToRight FlowDirection. Hence, if the document is RightToLeft,
            // mirroring transform need to be applied to the content of DocumentPage.Visual.
            point = new Point(0, 0);
            if (_document.FlowDirection == FlowDirection.RightToLeft)
            {
                transform = new MatrixTransform(-1.0, 0.0, 0.0, 1.0, flowDocumentPage.Size.Width, 0.0);
                transform.TryTransform(point, out newPoint);
                point = newPoint;
            }

            // Get TextView for DocumentPage. Position of the page is calculated through hittesting
            // the top-left of the page. If position cannot be found, the start position of
            // the first range for TextView is treated as ContentPosition for the page.
            textView = (ITextView)((IServiceProvider)flowDocumentPage).GetService(typeof(ITextView));
            Invariant.Assert(textView != null, "Cannot access ITextView for FlowDocumentPage.");

            //Invariant.Assert(textView.TextSegments.Count > 0, "Page cannot be empty.");
            // It is not necessarily WPF's fault if there are no TextSegments.
            // We have seen examples where PTS aborts the formatting because the content
            // exceeds its capacity.  Rather than crashing in this case, limp along
            // as if the position couldn't be determined.
            if (textView.TextSegments.Count == 0)
            {
                return(ContentPosition.Missing);
            }

            position = textView.GetTextPositionFromPoint(point, true);
            if (position == null)
            {
                position = textView.TextSegments[0].Start;
            }
            return((position is TextPointer) ? (ContentPosition)position : ContentPosition.Missing);
        }
Esempio n. 2
0
        public void TryTransform()
        {
            var point     = new Point(1, 2);
            var transform = new MatrixTransform(MatrixTest.GetIncrementalMatrix(-5, 2));
            var result    = transform.TryTransform(point, out var outPoint);

            result.Should().BeTrue();
            outPoint.X.Should().Be(-4);
            outPoint.Y.Should().Be(4);
        }
Esempio n. 3
0
        // Token: 0x06007013 RID: 28691 RVA: 0x002032D4 File Offset: 0x002014D4
        public override ContentPosition GetPagePosition(DocumentPage page)
        {
            this._dispatcherObject.VerifyAccess();
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }
            FlowDocumentPage flowDocumentPage = page as FlowDocumentPage;

            if (flowDocumentPage == null || flowDocumentPage.IsDisposed)
            {
                return(ContentPosition.Missing);
            }
            Point point = new Point(0.0, 0.0);

            if (this._document.FlowDirection == FlowDirection.RightToLeft)
            {
                MatrixTransform matrixTransform = new MatrixTransform(-1.0, 0.0, 0.0, 1.0, flowDocumentPage.Size.Width, 0.0);
                Point           point2;
                matrixTransform.TryTransform(point, out point2);
                point = point2;
            }
            ITextView textView = (ITextView)((IServiceProvider)flowDocumentPage).GetService(typeof(ITextView));

            Invariant.Assert(textView != null, "Cannot access ITextView for FlowDocumentPage.");
            if (textView.TextSegments.Count == 0)
            {
                return(ContentPosition.Missing);
            }
            ITextPointer textPointer = textView.GetTextPositionFromPoint(point, true);

            if (textPointer == null)
            {
                textPointer = textView.TextSegments[0].Start;
            }
            if (!(textPointer is TextPointer))
            {
                return(ContentPosition.Missing);
            }
            return((ContentPosition)textPointer);
        }
        private void DrawDataProvider(CellDrawingContext dc)
        {
            if (DataProviders.Count == 0)
            {
                return;
            }
            DataProviders.ForEach(x =>
            {
                if (x.Trigger.TryGetTarget(out var trigger) && trigger != null)
                {
                    trigger.Visibility = System.Windows.Visibility.Collapsed;
                }
            });
            DataProviders.ForEach(x =>
            {
                if (x.Selector.TryGetTarget(out var selector) && selector != null)
                {
                    selector.IsOpen = false;
                }
            });
            if (sheet.SelectionRange.IsEmpty || dc.DrawMode != DrawMode.View)
            {
                return;
            }

            var g = dc.Graphics as WPFGraphics;
            var scaledSelectionRect = GetScaledAndClippedRangeRect(this,
                                                                   sheet.SelectionRange.StartPos, sheet.SelectionRange.StartPos, 0);

            Cell cell = sheet.GetCell(sheet.SelectionRange.StartPos);

            if (cell == null || cell.DataProvider == null)
            {
                return;
            }

            if (g.TransformStack.Count != 0)
            {
                MatrixTransform mt = g.TransformStack.Peek();
                if (mt.TryTransform(new System.Windows.Point(cell.Right, cell.Top), out var righttop))
                {
                    if (righttop.X < this.Left || righttop.Y < this.Top)
                    {
                        if (cell.DataProvider.Trigger.TryGetTarget(out var tigger))
                        {
                            tigger.Visibility = System.Windows.Visibility.Collapsed;

                            tigger.Height = cell.Height;
                        }
                        return;
                    }
                    else
                    {
                        mt.TryTransform(new System.Windows.Point(cell.Left, cell.Bottom), out var leftbottom);
                        if (cell.DataProvider.Trigger.TryGetTarget(out var tigger) && tigger != null)
                        {
                            tigger.Height     = cell.Height;
                            tigger.Visibility = System.Windows.Visibility.Collapsed;
                            var position = (tigger.Parent as Canvas).PointToScreen(leftbottom);
                            tigger.Margin     = new System.Windows.Thickness(righttop.X, righttop.Y, 0, 0);
                            tigger.Visibility = System.Windows.Visibility.Visible;
                            Rectangle rectangle = new Rectangle(position.X, position.Y, righttop.X - leftbottom.X, righttop.Y - leftbottom.Y);
                            cell.DataProvider.Update(rectangle, cell);
                        }
                    }
                }
            }
            else
            {
                if (cell.DataProvider.Trigger.TryGetTarget(out var tigger))
                {
                    tigger.Margin     = new System.Windows.Thickness(this.Left + scaledSelectionRect.Right, this.Top + scaledSelectionRect.Top, 0, 0);
                    tigger.Visibility = System.Windows.Visibility.Visible;
                }
            }
        }