public abstract void Update(Graphics graphics, LayoutUpdateReason reason);
        public override void Update(Graphics graphics, LayoutUpdateReason reason)
        {
            //do not recalculate pages when it's just a zoom change
            if (reason == LayoutUpdateReason.ZoomChanged)
                return;

            if (graphics == null)
                throw new ArgumentException("graphics");

            //Set the scaling, pageSize, margins, pageseparator by reserse scaling; so that when we actually scale
            //at the time of drawing things will be correctly calculated
            Size margin = WorkflowTheme.CurrentTheme.AmbientTheme.Margin;
            Size paperSize = GetPaperSize(graphics);
            Margins margins = GetAdjustedMargins(graphics);
            Size rootDesignerSize = (this.parentView.RootDesigner != null) ? this.parentView.RootDesigner.Size : Size.Empty;
            if (!rootDesignerSize.IsEmpty)
            {
                Size selectionSize = WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize;
                rootDesignerSize.Width += 3 * selectionSize.Width;
                rootDesignerSize.Height += 3 * selectionSize.Height;
            }

            //STEP1 : Calculate the scaling factor
            if (this.printDocument.PageSetupData.AdjustToScaleFactor)
            {
                this.scaling = ((float)this.printDocument.PageSetupData.ScaleFactor / 100.0f);
            }
            else
            {
                Size printableArea = new Size(paperSize.Width - (margins.Left + margins.Right), paperSize.Height - (margins.Top + margins.Bottom));
                printableArea.Width = Math.Max(printableArea.Width, 1);
                printableArea.Height = Math.Max(printableArea.Height, 1);

                PointF scaleFactor = new PointF(
                ((float)this.printDocument.PageSetupData.PagesWide * (float)printableArea.Width / (float)rootDesignerSize.Width),
                ((float)this.printDocument.PageSetupData.PagesTall * (float)printableArea.Height / (float)rootDesignerSize.Height));

                //Take the minimum scaling as we do not want to unevenly scale the bitmap
                this.scaling = Math.Min(scaleFactor.X, scaleFactor.Y);
                //leave just 3 digital points (also, that will remove potential problems with ceiling e.g. when the number of pages would be 3.00000000001 we'll get 4)
                this.scaling = (float)(Math.Floor((double)this.scaling * 1000.0d) / 1000.0d);
            }

            //STEP2 : Calculate the pagesize
            this.pageSize = paperSize;
            this.pageSize.Width = Convert.ToInt32(Math.Ceiling(((float)this.pageSize.Width) / this.scaling));
            this.pageSize.Height = Convert.ToInt32(Math.Ceiling(((float)this.pageSize.Height) / this.scaling));

            //STEP3 : Calculate the page separator
            IDesignerOptionService designerOptionService = this.serviceProvider.GetService(typeof(IDesignerOptionService)) as IDesignerOptionService;
            if (designerOptionService != null)
            {
                object separator = designerOptionService.GetOptionValue("WinOEDesigner", "PageSeparator");
                PageSeparator = (separator != null) ? (Size)separator : PrintPreviewLayout.DefaultPageSeparator;
            }
            PageSeparator = new Size(Convert.ToInt32(Math.Ceiling(((float)PageSeparator.Width) / this.scaling)), Convert.ToInt32(Math.Ceiling(((float)PageSeparator.Height) / this.scaling)));

            //STEP4: Calculate the margins after reverse scaling the margins, so that when we set the normal scalezoom we have correct margins
            PageMargins = margins;
            PageMargins.Left = Convert.ToInt32((float)PageMargins.Left / this.scaling);
            PageMargins.Right = Convert.ToInt32((float)PageMargins.Right / this.scaling);
            PageMargins.Top = Convert.ToInt32((float)PageMargins.Top / this.scaling);
            PageMargins.Bottom = Convert.ToInt32((float)PageMargins.Bottom / this.scaling);

            //STEP5: Calculate the header and footer margins
            this.headerFooterMargins.Top = Convert.ToInt32((float)this.printDocument.PageSetupData.HeaderMargin / this.scaling);
            this.headerFooterMargins.Bottom = Convert.ToInt32((float)this.printDocument.PageSetupData.FooterMargin / this.scaling);
            this.previewTime = DateTime.Now;

            //STEP6: Calculate the the row columns
            Size viewablePageSize = new Size(this.pageSize.Width - (PageMargins.Left + PageMargins.Right), this.pageSize.Height - (PageMargins.Top + PageMargins.Bottom));
            viewablePageSize.Width = Math.Max(viewablePageSize.Width, 1);
            viewablePageSize.Height = Math.Max(viewablePageSize.Height, 1);

            //We check for greater than 1 here as the division might introduce rounding factor
            //Columns
            this.rowColumns.Width = rootDesignerSize.Width / viewablePageSize.Width;
            this.rowColumns.Width += ((rootDesignerSize.Width % viewablePageSize.Width) > 1) ? 1 : 0;
            this.rowColumns.Width = Math.Max(1, this.rowColumns.Width);

            //Rows
            this.rowColumns.Height = rootDesignerSize.Height / viewablePageSize.Height;
            this.rowColumns.Height += ((rootDesignerSize.Height % viewablePageSize.Height) > 1) ? 1 : 0;
            this.rowColumns.Height = Math.Max(1, this.rowColumns.Height);

            //STEP7: Calculate the pagelayoutdata
            this.pageLayoutInfo.Clear();

            //Create the layout data
            for (int row = 0; row < this.rowColumns.Height; row++)
            {
                for (int column = 0; column < this.rowColumns.Width; column++)
                {
                    Point pageLocation = Point.Empty;
                    pageLocation.X = (column * this.pageSize.Width) + ((column + 1) * PageSeparator.Width);
                    pageLocation.Y = (row * this.pageSize.Height) + ((row + 1) * PageSeparator.Height);

                    Point viewablePageLocation = Point.Empty;
                    viewablePageLocation.X = pageLocation.X + PageMargins.Left;
                    viewablePageLocation.Y = pageLocation.Y + PageMargins.Top;

                    Rectangle logicalBounds = new Rectangle(column * viewablePageSize.Width, row * viewablePageSize.Height, viewablePageSize.Width, viewablePageSize.Height);
                    Rectangle pageBounds = new Rectangle(pageLocation, this.pageSize);
                    Rectangle viewablePageBounds = new Rectangle(viewablePageLocation, viewablePageSize);
                    this.pageLayoutInfo.Add(new PageLayoutData(logicalBounds, pageBounds, viewablePageBounds, new Point(column, row)));
                }
            }
        }
 public abstract void Update(Graphics graphics, LayoutUpdateReason reason);
 public override void Update(Graphics graphics, LayoutUpdateReason reason)
 {
     //We dont do anything as our layout is simple
 }
 public override void Update(Graphics graphics, LayoutUpdateReason reason)
 {
     //We dont do anything as our layout is simple
 }