Esempio n. 1
0
        private void UpdateVisiblePage(SinglePageInfo visiblePage)
        {
            if (visiblePage == null)
            {
                return;
            }

            this.CurrentSinglePageInfo = visiblePage;
            Point scrollOffset = new Point(this.Owner.HorizontalScrollOffset, this.Owner.VerticalScrollOffset);;

            List <int> remove = new List <int>();

            foreach (int pageNo in this.VisiblePresenters.Keys)
            {
                if (visiblePage.FixedPage.PageNo != pageNo)
                {
                    remove.Add(pageNo);
                }
            }

            FixedPagePresenter presenter;

            foreach (int pageNo in remove)
            {
                this.ReleasePagePresenter(pageNo);
            }

            SinglePageInfo pageInfo = visiblePage;

            presenter = this.GetPagePresenter(pageInfo);

            if (pageInfo.Transformations != null)
            {
                presenter.RenderTransform = (Transform)pageInfo.Transformations;
            }

            Point topLeft;

            if (visiblePage.IntersectsWithViewport)
            {
                double y = Math.Min(scrollOffset.Y, visiblePage.BottomPositionInView - viewportSize.Height);
                y = Math.Max(y, visiblePage.TopPositionInView);

                topLeft = new Point(scrollOffset.X, y);
            }
            else
            {
                topLeft = new Point(visiblePage.PositionInView.Left, visiblePage.PositionInView.Top);
            }

            Rect viewport = new Rect(topLeft, this.viewportSize);
            Rect viewportIntersectionRect = pageInfo.GetViewportIntersectionRect(viewport);

            presenter.UpdateLayers(new UILayerUpdateContext(viewportIntersectionRect)
            {
                ShouldShowSelectionMarkers = this.ShouldShowSelectionMarkers
            });

            this.UpdateCanvas(presenter, pageInfo, scrollOffset, viewport);
        }
Esempio n. 2
0
        private void UpdateCanvas(FixedPagePresenter presenter, SinglePageInfo pageInfo, Point scrollOffset, Rect viewport)
        {
            Canvas.SetLeft(presenter, pageInfo.PositionInView.X - scrollOffset.X);

            double offset = pageInfo.PositionInView.Y - scrollOffset.Y;

            if (offset > pageInfo.VerticalOffset || (offset > 0 && offset < pageInfo.VerticalOffset))
            {
                Canvas.SetTop(presenter, pageInfo.VerticalOffset);
                return;
            }
            else if (offset < 0)
            {
                double totalheight   = pageInfo.BottomPositionInView - pageInfo.TopPositionInView;
                double heightOutside = -offset;
                double heightInside  = totalheight - heightOutside;
                if (heightInside < viewport.Height)
                {
                    Canvas.SetTop(presenter, viewport.Height - totalheight);
                    return;
                }
            }

            Canvas.SetTop(presenter, offset);
        }
Esempio n. 3
0
 protected override void ReleaseDocumentResourcesOverride()
 {
     this.CurrentSinglePageInfo    = null;
     this.visiblePage              = null;
     this.lastVerticalScrollOffset = 0;
     this.lastViewportHeight       = 0;
     this.scaleFactorChanged       = false;
 }
        public SinglePageInfo GetPageInView(Rect viewport, double verticalScrollDirection, SinglePageInfo currentPageInfo, bool retrieveCurrentPageInfo)
        {
            if (retrieveCurrentPageInfo && currentPageInfo != null)
            {
                this.visiblePage = this.pageLayoutInfos.Where(info => info.FixedPage.PageNo == currentPageInfo.FixedPage.PageNo).FirstOrDefault();

                return this.visiblePage;
            }

            return this.GetPageInView(viewport, verticalScrollDirection, currentPageInfo);
        }
Esempio n. 5
0
        public SinglePageInfo GetPageInView(Rect viewport, double verticalScrollDirection, SinglePageInfo currentPageInfo, bool retrieveCurrentPageInfo)
        {
            if (retrieveCurrentPageInfo && currentPageInfo != null)
            {
                this.visiblePage = this.pageLayoutInfos.Where(info => info.FixedPage.PageNo == currentPageInfo.FixedPage.PageNo).FirstOrDefault();

                return(this.visiblePage);
            }

            return(this.GetPageInView(viewport, verticalScrollDirection, currentPageInfo));
        }
Esempio n. 6
0
        protected override Size ArrangeOverride(Size arrangeBounds)
        {
            this.UpdateScrollBars(arrangeBounds);

            this.ViewportSize = arrangeBounds;

            double verticalScrollDirection = this.Owner.VerticalScrollOffset - lastVerticalScrollOffset;
            bool   viewportResized         = (this.ViewportSize.Height - lastViewportHeight) != 0;
            bool   useCurrentPageInfo      = this.scaleFactorChanged || viewportResized;

            Point scrollOffset = new Point(this.Owner.HorizontalScrollOffset, this.Owner.VerticalScrollOffset);

            this.visiblePage = this.pagesLayoutManager.GetPageInView(
                new Rect(scrollOffset, arrangeBounds),
                verticalScrollDirection,
                this.visiblePage,
                useCurrentPageInfo);


            if (useCurrentPageInfo)
            {
                this.scaleFactorChanged = false;
                if (this.visiblePage != null)
                {
                    if (this.visiblePage.IntersectsWithViewport)
                    {
                        if (this.visiblePage.BottomPositionInView + this.visiblePage.VerticalOffset < this.Owner.VerticalScrollOffset + ViewportSize.Height)
                        {
                            this.Owner.ScrollToVerticalOffset(this.visiblePage.BottomPositionInView + this.visiblePage.VerticalOffset - this.ViewportSize.Height);
                        }
                        else if (this.visiblePage.TopPositionInView - this.visiblePage.VerticalOffset > this.Owner.VerticalScrollOffset)
                        {
                            this.Owner.ScrollToVerticalOffset(this.visiblePage.TopPositionInView - this.visiblePage.VerticalOffset);
                        }
                    }
                    else
                    {
                        this.Owner.ScrollToVerticalOffset(this.visiblePage.TopPositionInView - this.visiblePage.VerticalOffset);
                    }
                }
            }

            this.lastViewportHeight       = ViewportSize.Height;
            this.lastVerticalScrollOffset = this.Owner.VerticalScrollOffset;

            this.VisiblePages = this.visiblePage == null?Enumerable.Empty <FixedPageLayoutInfo>() : new FixedPageLayoutInfo[]
            {
                this.visiblePage
            };
            this.UpdateVisiblePage(this.visiblePage);

            return(base.ArrangeOverride(arrangeBounds));
        }
Esempio n. 7
0
        public override void UpdateLayout(Size viewportSize)
        {
            RotationAngle rotationAngle = this.Presenter.Owner.RotationAngle;

            this.pageLayoutInfos.Clear();
            if (this.Document == null)
            {
                this.ContentSize = new Size(0, 0);
                return;
            }

            double height = 0;
            double width  = 0;

            foreach (RadFixedPage page in this.Document.Pages)
            {
                Size pageSize            = this.GetScaledPageSize(page);
                Size rotatedPageSize     = this.RotateSize(pageSize, rotationAngle);
                Size pageSizeWithMargins = new Size(rotatedPageSize.Width + (2 * this.PageMargins.Width), rotatedPageSize.Height + (2 * this.PageMargins.Height));

                if (pageSizeWithMargins.Width > width)
                {
                    width = pageSizeWithMargins.Width;
                }

                double horizontalOffset = ((viewportSize.Width - rotatedPageSize.Width) / 2) - this.PageMargins.Width;
                double verticalOffset   = ((viewportSize.Height - rotatedPageSize.Height) / 2) - this.PageMargins.Height;

                horizontalOffset = Math.Max(0, horizontalOffset);
                verticalOffset   = Math.Max(0, verticalOffset);

                double newHeight = height + pageSizeWithMargins.Height + 2 * verticalOffset;

                Rect positionInView = new Rect(this.PageMargins.Width + horizontalOffset, height + this.PageMargins.Height + verticalOffset, rotatedPageSize.Width, rotatedPageSize.Height);

                TransformGroup transformations = this.CreateTransformations(pageSize, rotationAngle);

                FixedPageLayoutInfo layoutInfo = new FixedPageLayoutInfo(page, positionInView, transformations);

                SinglePageInfo singlePageInfo = new SinglePageInfo(verticalOffset + this.PageMargins.Height, newHeight,
                                                                   rotatedPageSize.Width > viewportSize.Width,
                                                                   rotatedPageSize.Height > viewportSize.Height,
                                                                   layoutInfo.FixedPage, layoutInfo.PositionInView,
                                                                   layoutInfo.Transformations);

                this.pageLayoutInfos.Add(singlePageInfo);

                height = newHeight;
            }

            this.ContentSize = new Size(width, height);
        }
        public override void UpdateLayout(Size viewportSize)
        {
            RotationAngle rotationAngle = this.Presenter.Owner.RotationAngle;

            this.pageLayoutInfos.Clear();
            if (this.Document == null)
            {
                this.ContentSize = new Size(0, 0);
                return;
            }

            double height = 0;
            double width = 0;
            foreach (RadFixedPage page in this.Document.Pages)
            {
                Size pageSize = this.GetScaledPageSize(page);
                Size rotatedPageSize = this.RotateSize(pageSize, rotationAngle);
                Size pageSizeWithMargins = new Size(rotatedPageSize.Width + (2 * this.PageMargins.Width), rotatedPageSize.Height + (2 * this.PageMargins.Height));

                if (pageSizeWithMargins.Width > width)
                {
                    width = pageSizeWithMargins.Width;
                }

                double horizontalOffset = ((viewportSize.Width - rotatedPageSize.Width) / 2) - this.PageMargins.Width;
                double verticalOffset = ((viewportSize.Height - rotatedPageSize.Height) / 2) - this.PageMargins.Height;

                horizontalOffset = Math.Max(0, horizontalOffset);
                verticalOffset = Math.Max(0, verticalOffset);

                double newHeight = height + pageSizeWithMargins.Height + 2 * verticalOffset;

                Rect positionInView = new Rect(this.PageMargins.Width + horizontalOffset, height + this.PageMargins.Height + verticalOffset, rotatedPageSize.Width, rotatedPageSize.Height);

                TransformGroup transformations = this.CreateTransformations(pageSize, rotationAngle);

                FixedPageLayoutInfo layoutInfo = new FixedPageLayoutInfo(page, positionInView, transformations);

                SinglePageInfo singlePageInfo = new SinglePageInfo(verticalOffset + this.PageMargins.Height, newHeight,
                    rotatedPageSize.Width > viewportSize.Width,
                    rotatedPageSize.Height > viewportSize.Height,
                    layoutInfo.FixedPage, layoutInfo.PositionInView,
                    layoutInfo.Transformations);

                this.pageLayoutInfos.Add(singlePageInfo);

                height = newHeight;
            }

            this.ContentSize = new Size(width, height);
        }
Esempio n. 9
0
        public bool GetLocationFromViewPoint(Point viewPoint, Size viewport, out RadFixedPage page, out Point location)
        {
            location = new Point();
            page     = null;
            if (this.ContentSize.Width == 0 || this.ContentSize.Height == 0 || this.pageLayoutInfos == null || this.pageLayoutInfos.Count == 0)
            {
                return(false);
            }

            SinglePageInfo pageInfo = this.visiblePage;

            if (pageInfo == null || !pageInfo.FixedPage.HasContent)
            {
                return(false);
            }

            page = pageInfo.FixedPage;

            double verticalScrollOffset = this.Presenter.Owner.VerticalScrollOffset;

            if (pageInfo.IntersectsWithViewportVertically)
            {
                if (verticalScrollOffset < pageInfo.PositionInView.Y)
                {
                    viewPoint.Y += pageInfo.PositionInView.Y - verticalScrollOffset;
                }
                else if (verticalScrollOffset + viewport.Height > pageInfo.BottomPositionInView)
                {
                    viewPoint.Y -= verticalScrollOffset + viewport.Height - pageInfo.BottomPositionInView;
                }
            }
            else
            {
                if (verticalScrollOffset + pageInfo.VerticalOffset > pageInfo.PositionInView.Y)
                {
                    viewPoint.Y -= verticalScrollOffset + pageInfo.VerticalOffset - pageInfo.PositionInView.Y;
                }
                else if (verticalScrollOffset + pageInfo.VerticalOffset < pageInfo.PositionInView.Y)
                {
                    viewPoint.Y += pageInfo.PositionInView.Y - (verticalScrollOffset + pageInfo.VerticalOffset);
                }
            }

            location = new Point(viewPoint.X - pageInfo.PositionInView.X, viewPoint.Y - pageInfo.PositionInView.Y);
            if (pageInfo.InverseTransformations != null)
            {
                location = pageInfo.InverseTransformations.Transform(location);
            }

            return(true);
        }
Esempio n. 10
0
        private SinglePageInfo GetPageInView(Rect viewport, double verticalScrollDirection, SinglePageInfo currentPageInfo)
        {
            //In case the scroll direction changes between two pages.
            if (currentPageInfo != null)
            {
                foreach (var info in this.pageLayoutInfos)
                {
                    if (Intersects(viewport, info.PositionInView) && info.FixedPage.PageNo == currentPageInfo.FixedPage.PageNo)
                    {
                        this.visiblePage = info;
                        return(this.visiblePage);
                    }
                }
            }

            return(this.GetPageInView(viewport, verticalScrollDirection));
        }
Esempio n. 11
0
        private SinglePageInfo GetPageInView(Rect viewport, double verticalScrollDirection)
        {
            List <SinglePageInfo> infos = new List <SinglePageInfo>(this.pageLayoutInfos);

            if (verticalScrollDirection < 0)
            {
                infos.Reverse();
            }

            foreach (var info in infos)
            {
                if (Intersects(viewport, info.PositionInView))
                {
                    this.visiblePage = info;
                    return(this.visiblePage);
                }
            }

            return(this.visiblePage);
        }
        private SinglePageInfo GetPageInView(Rect viewport, double verticalScrollDirection, SinglePageInfo currentPageInfo)
        {
            //In case the scroll direction changes between two pages.
            if (currentPageInfo != null)
            {
                foreach (var info in this.pageLayoutInfos)
                {
                    if (Intersects(viewport, info.PositionInView) && info.FixedPage.PageNo == currentPageInfo.FixedPage.PageNo)
                    {
                        this.visiblePage = info;
                        return this.visiblePage;
                    }
                }
            }

            return this.GetPageInView(viewport, verticalScrollDirection);
        }
        private void UpdateVisiblePage(SinglePageInfo visiblePage)
        {
            if (visiblePage == null)
            {
                return;
            }

            this.CurrentSinglePageInfo = visiblePage;
            Point scrollOffset = new Point(this.Owner.HorizontalScrollOffset, this.Owner.VerticalScrollOffset);;

            List<int> remove = new List<int>();
            foreach (int pageNo in this.VisiblePresenters.Keys)
            {
                if (visiblePage.FixedPage.PageNo != pageNo)
                {
                    remove.Add(pageNo);
                }
            }

            FixedPagePresenter presenter;
            foreach (int pageNo in remove)
            {
                this.ReleasePagePresenter(pageNo);
            }

            SinglePageInfo pageInfo = visiblePage;

            presenter = this.GetPagePresenter(pageInfo);

            if (pageInfo.Transformations != null)
            {
                presenter.RenderTransform = (Transform)pageInfo.Transformations;
            }

            Point topLeft;

            if (visiblePage.IntersectsWithViewport)
            {
                double y = Math.Min(scrollOffset.Y, visiblePage.BottomPositionInView - ViewportSize.Height);
                y = Math.Max(y, visiblePage.TopPositionInView); 

                topLeft = new Point(scrollOffset.X, y);
            }
            else
            {
                topLeft = new Point(visiblePage.PositionInView.Left, visiblePage.PositionInView.Top);
            }

            Rect viewport = new Rect(topLeft, this.ViewportSize);
            Rect viewportIntersectionRect = pageInfo.GetViewportIntersectionRect(viewport);
            presenter.UpdateLayers(new UILayerUpdateContext(viewportIntersectionRect)
            {
                ShouldShowSelectionMarkers = this.ShouldShowSelectionMarkers
            });

            this.UpdateCanvas(presenter, pageInfo, scrollOffset, viewport);
        }
        protected override Size ArrangeOverride(Size arrangeBounds)
        {
            this.UpdateScrollBars(arrangeBounds);

            this.ViewportSize = arrangeBounds;

            double verticalScrollDirection = this.Owner.VerticalScrollOffset - lastVerticalScrollOffset; 
            bool viewportResized = (this.ViewportSize.Height - lastViewportHeight) != 0;
            bool useCurrentPageInfo = this.scaleFactorChanged || viewportResized;

            Point scrollOffset = new Point(this.Owner.HorizontalScrollOffset, this.Owner.VerticalScrollOffset);
            this.visiblePage = this.pagesLayoutManager.GetPageInView(
                new Rect(scrollOffset, arrangeBounds),
                verticalScrollDirection,
                this.visiblePage,
                useCurrentPageInfo);


            if (useCurrentPageInfo)
            {
                this.scaleFactorChanged = false;
                if (this.visiblePage != null)
                { 
                    if (this.visiblePage.IntersectsWithViewport)
                    {
                        if (this.visiblePage.BottomPositionInView + this.visiblePage.VerticalOffset < this.Owner.VerticalScrollOffset + ViewportSize.Height) 
                        {
                            this.Owner.ScrollToVerticalOffset(this.visiblePage.BottomPositionInView + this.visiblePage.VerticalOffset - this.ViewportSize.Height);
                        }
                        else if (this.visiblePage.TopPositionInView - this.visiblePage.VerticalOffset > this.Owner.VerticalScrollOffset) 
                        {
                            this.Owner.ScrollToVerticalOffset(this.visiblePage.TopPositionInView - this.visiblePage.VerticalOffset);
                        }
                    }
                    else
                    {
                        this.Owner.ScrollToVerticalOffset(this.visiblePage.TopPositionInView - this.visiblePage.VerticalOffset);
                    }
                }
            } 

            this.lastViewportHeight = ViewportSize.Height;
            this.lastVerticalScrollOffset = this.Owner.VerticalScrollOffset;
             
            this.UpdateVisiblePage(this.visiblePage);

            return base.ArrangeOverride(arrangeBounds);
        }
 public override void Release()
 {
     this.visiblePage = null;
 }
 protected override void ReleaseDocumentResourcesOverride()
 {
     this.CurrentSinglePageInfo = null;
     this.visiblePage = null;
     this.lastVerticalScrollOffset = 0;
     this.lastViewportHeight = 0;
     this.scaleFactorChanged = false;
 }
        private SinglePageInfo GetPageInView(Rect viewport, double verticalScrollDirection)
        {
            List<SinglePageInfo> infos = new List<SinglePageInfo>(this.pageLayoutInfos);

            if (verticalScrollDirection < 0)
            {
                infos.Reverse();
            }

            foreach (var info in infos)
            {
                if (Intersects(viewport, info.PositionInView))
                {
                    this.visiblePage = info;
                    return this.visiblePage;
                }
            }

            return this.visiblePage;
        }
        private void UpdateCanvas(FixedPagePresenter presenter, SinglePageInfo pageInfo, Point scrollOffset, Rect viewport)
        { 
            Canvas.SetLeft(presenter, pageInfo.PositionInView.X - scrollOffset.X);

            double offset = pageInfo.PositionInView.Y - scrollOffset.Y;
            if (offset > pageInfo.VerticalOffset || (offset > 0 && offset < pageInfo.VerticalOffset))
            {
                Canvas.SetTop(presenter, pageInfo.VerticalOffset);
                return;
            }
            else if (offset < 0)
            {
                double totalheight = pageInfo.BottomPositionInView - pageInfo.TopPositionInView;
                double heightOutside = -offset;
                double heightInside = totalheight - heightOutside;
                if (heightInside < viewport.Height)
                {
                    Canvas.SetTop(presenter, viewport.Height - totalheight);
                    return;
                }
            }

            Canvas.SetTop(presenter, offset);
        } 
Esempio n. 19
0
 public override void Release()
 {
     this.visiblePage = null;
 }