Stingray® Foundation : Chapter 9 Print Package : Print Preview
Print Preview
The print preview feature provides a way for users to view a printed document on the screen before it is actually sent to a printer. The print preview window allows the user to page up and down through the output to see every page. The output shown in the print preview window should be identical to the output generated by the printer.
The print preview feature is implemented with the help of the Model-View-Controller (MVC) package. The implementation treats print preview as an MVC component that can be mixed into or aggregated with any type of window. Using MVC to implement print preview also makes it easy to swap in and out different types of viewports and controllers in order to modify or enhance the appearance and behavior of the print preview window. It also makes it possible to use wrapper classes for decorating the print preview viewport with scroll bars or ruler guides. Most of the print preview functionality is implemented in the following three classes: CPrtPreviewModel, CPrtPreviewViewport, and CPrtPreviewController.
Using the print preview MVC classes is just like using any other MVC component. The viewport is either aggregated into a window or mixed into a window class. Paint messages are delegated to the viewport’s Draw() method in order to render the data in the model. The model, viewport and controller are connected together and cooperate to provide a service.
Once the CPrtPreviewModel, CPrtPreviewViewport and CPrtPreviewController have been created and connected together, a printable object and document must be supplied to the model. The CPrtPreviewModel class implements a Start() method, which takes an IPrintable and CPrintDoc as parameters. The Start() method stores pointers to the IPrintable and CPrintDoc objects in the model, creates and initializes a printer DC, and calls UpdateAllObservers(). The call to UpdateAllObservers() informs the viewports to render the model. The class CPrtPreviewModel also keeps track of the current page and the number of pages to display in the viewports.