// Token: 0x06006F9C RID: 28572 RVA: 0x0020154C File Offset: 0x001FF74C
        internal static void DisconnectPageVisual(Visual pageVisual)
        {
            Visual visual = VisualTreeHelper.GetParent(pageVisual) as Visual;

            if (visual != null)
            {
                ContainerVisual containerVisual = visual as ContainerVisual;
                if (containerVisual == null)
                {
                    throw new ArgumentException(SR.Get("DocumentPageView_ParentNotDocumentPageHost"), "pageVisual");
                }
                DocumentPageHost documentPageHost = VisualTreeHelper.GetParent(containerVisual) as DocumentPageHost;
                if (documentPageHost == null)
                {
                    throw new ArgumentException(SR.Get("DocumentPageView_ParentNotDocumentPageHost"), "pageVisual");
                }
                documentPageHost.PageVisual = null;
            }
        }
Beispiel #2
0
        //-------------------------------------------------------------------
        //
        //  Internal Methods
        //
        //-------------------------------------------------------------------

        #region Internal Methods

        internal static void DisconnectPageVisual(Visual pageVisual)
        {
            // There might be a case where a visual associated with a page was
            // inserted to a visual tree before. It got removed later, but GC did not
            // destroy its parent yet. To workaround this case always check for the parent
            // of page visual and disconnect it, when necessary.
            Visual currentParent = VisualTreeHelper.GetParent(pageVisual) as Visual;

            if (currentParent != null)
            {
                ContainerVisual pageVisualHost = currentParent as ContainerVisual;
                if (pageVisualHost == null)
                {
                    throw new ArgumentException(SR.Get(SRID.DocumentPageView_ParentNotDocumentPageHost), "pageVisual");
                }
                DocumentPageHost docPageHost = VisualTreeHelper.GetParent(pageVisualHost) as DocumentPageHost;
                if (docPageHost == null)
                {
                    throw new ArgumentException(SR.Get(SRID.DocumentPageView_ParentNotDocumentPageHost), "pageVisual");
                }
                docPageHost.PageVisual = null;
            }
        }
        /// <summary>
        /// Content arrangement.
        /// </summary>
        /// <param name="finalSize">The final size that element should use to arrange itself and its children.</param>
        protected override sealed Size ArrangeOverride(Size finalSize)
        {
            Transform pageTransform;
            ScaleTransform pageScaleTransform;
            Visual pageVisual;
            Size pageSize, pageZoom;
            
            CheckDisposed();

            if (_pageVisualClone == null)
            {
                if (_pageHost == null)
                {
                    _pageHost = new DocumentPageHost();
                    this.AddVisualChild(_pageHost);
                }
                Invariant.Assert(_pageHost != null);

                pageVisual = (_documentPage == null) ? null : _documentPage.Visual;
                if (pageVisual == null)
                {
                    // Remove existing visiual children.
                    _pageHost.PageVisual = null;

                    // Reset offset and transform on the page host before Arrange
                    _pageHost.CachedOffset = new Point();
                    _pageHost.RenderTransform = null;

                    // Size for the page host needs to be set to finalSize
                    _pageHost.Arrange(new Rect(_pageHost.CachedOffset, finalSize));
                }
                else
                {
                    // Add visual representing the page contents. For performance reasons
                    // first check if it is already insered there.
                    if (_pageHost.PageVisual != pageVisual)
                    {
                        // There might be a case where a visual associated with a page was 
                        // inserted to a visual tree before. It got removed later, but GC did not
                        // destroy its parent yet. To workaround this case always check for the parent
                        // of page visual and disconnect it, when necessary.
                        DocumentPageHost.DisconnectPageVisual(pageVisual);

                        _pageHost.PageVisual = pageVisual;
                    }
                
                    // Compute transform to be applied to the page visual. First take into account
                    // mirroring transform, if necessary. Apply also scaling transform.
                    pageSize = _documentPage.Size;
                    pageTransform = Transform.Identity;

                    // DocumentPage.Visual is always LeftToRight, so if the current
                    // FlowDirection is RightToLeft, need to unmirror the child visual.
                    if (FlowDirection == FlowDirection.RightToLeft)
                    {
                        pageTransform = new MatrixTransform(-1.0, 0.0, 0.0, 1.0, pageSize.Width, 0.0);
                    }

                    // Apply zooming
                    if (!DoubleUtil.IsOne(_pageZoom))
                    {
                        pageScaleTransform = new ScaleTransform(_pageZoom, _pageZoom);
                        if (pageTransform == Transform.Identity)
                        {
                            pageTransform = pageScaleTransform;
                        }
                        else
                        {
                            pageTransform = new MatrixTransform(pageTransform.Value * pageScaleTransform.Value);
                        }
                        pageSize = new Size(pageSize.Width * _pageZoom, pageSize.Height * _pageZoom);
                    }

                    // Apply stretch properties
                    pageZoom = Viewbox.ComputeScaleFactor(finalSize, pageSize, this.Stretch, this.StretchDirection);
                    if (!DoubleUtil.IsOne(pageZoom.Width) || !DoubleUtil.IsOne(pageZoom.Height))
                    {
                        pageScaleTransform = new ScaleTransform(pageZoom.Width, pageZoom.Height);
                        if (pageTransform == Transform.Identity)
                        {
                            pageTransform = pageScaleTransform;
                        }
                        else
                        {
                            pageTransform = new MatrixTransform(pageTransform.Value * pageScaleTransform.Value);
                        }
                        pageSize = new Size(pageSize.Width * pageZoom.Width, pageSize.Height * pageZoom.Height);
                    }

                    // Set offset and transform on the page host before Arrange
                    _pageHost.CachedOffset = new Point((finalSize.Width - pageSize.Width) / 2, (finalSize.Height - pageSize.Height) / 2);
                    _pageHost.RenderTransform = pageTransform;

                    // Arrange pagehost to original size of the page.
                    _pageHost.Arrange(new Rect(_pageHost.CachedOffset, _documentPage.Size));

                }

                // Fire [....] notification if new page was connected.
                if (_newPageConnected)
                {
                    OnPageConnected();
                }
                
                // Transform for the page has been changed, need to notify TextView about the changes.
                OnTransformChangedAsync();
            }
            else
            {
                if (_pageHost.PageVisual != _pageVisualClone)
                {
                    // Remove existing visiual children.
                    _pageHost.PageVisual = _pageVisualClone;
                    // Size for the page host needs to be set to finalSize

                    // Use previous offset and transform
                    _pageHost.Arrange(new Rect(_pageHost.CachedOffset, finalSize));
                }
            }

            return base.ArrangeOverride(finalSize);
        }