1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #if !defined (__PRNPREV_H__)
19 #if !defined(__E32STD_H__)
22 #if !defined(__E32BASE_H__)
25 #if !defined(__PRNSETUP_H__)
30 class TPrintPreviewFormat;
32 class CPrintPreviewImage;
35 // forward references:
38 class CPrintPreviewDevice;
42 class TPrintPreviewFormat
43 /** Print preview format information.
45 The print preview format information is accessed via its public data members.
46 Typically there is a system wide TPrintPreviewFormat supplied by the GUI framework.
48 Preview information includes:
50 - panel settings: multiple pages can be previewed at once; the display area
51 for each page is termed a panel.
53 - label settings: each panel can have an associated label, which specifies the
54 corresponding document page number
60 /** The minimum panel gutter size, in pixels. */
61 TSize iMinPanelGutterInPixels;
62 /** The width of the panel shadow, in pixels. */
63 TInt iPanelShadowWidthInPixels;
64 /** The colour of the panel shadow. */
65 TRgb iPanelShadowColor;
66 /** The panel margin colour. */
67 TRgb iPanelMarginColor;
68 /** The color of both the paper and the window background. */
69 TRgb iPreviewBackgroundColor;
70 /** X pixel offset of the label text from the panel edge. */
71 TInt iLabelOffsetInPixels;
72 /** Font specification for the label text. */
73 TFontSpec iLabelFontSpecInPixels;
77 class CPrintPreviewImage : public CBase, private MPrintProcessObserver, private MPageRegionPrinter
78 /** Print preview image.
80 This class provides a standard print preview image. An object of this type
81 should be owned by a control, which is in turn owned by the print preview
82 dialog. The control's window provides the region into which this object draws
85 The class provides a callback to the application code that draws the preview
92 /** Margin display state flags. */
94 /** Show margins in print preview image. */
96 /** Hide margins in print preview image. */
100 IMPORT_C static CPrintPreviewImage* NewL(CPrintSetup& aPrintSetup,MPageRegionPrinter& aBodyPrinter,
101 RWsSession& aWsSession,RWindow& aWindow,const TSize& aMaxWindowSize,
102 const TPrintPreviewFormat& aStaticFormat);
103 IMPORT_C virtual ~CPrintPreviewImage();
104 IMPORT_C void SetMargins(TMarginState aState); // whether or not to show margins
105 IMPORT_C void SetObserver(MPrintProcessObserver& aObserver);
106 IMPORT_C void SetNumBands(TInt aNum);
107 IMPORT_C void FormatL(TInt aNumPagesInDoc,TInt aFirstPageToDisplay,TInt aNumPagesToView); // call when scrolling or changing num pages to view
108 IMPORT_C void DrawL(const TPoint& aOrigin,const TRect& aInvalidRegion); // aOrigin is the point in the window I will treat as the origin (ie offset)
119 CPrintPreviewImage(CPrintSetup& aPrintSetup,MPageRegionPrinter& aBodyPrinter,RWsSession& aWsSession,
120 RWindow& aWindow,const TSize& aMaxWindowSize,const TPrintPreviewFormat& aStaticFormat);
122 void CalculateHeaderFooterRects(TRect& aHeaderRectInPixels,TRect& aFooterRectInPixels);
123 TInt SetPanelArrayL(const TInt aFirstPage,const TInt aNumPagesToView);
124 void SetLabelWidth();
126 void DrawBorder(CGraphicsContext* aGc); // and shadow
127 void DrawMargins(CGraphicsContext* aGc); // including header/footer lines
128 void DrawLabel(CGraphicsContext* aGc,TInt aPageNo);
129 void DrawToGutter(CGraphicsContext* aGc,TInt aPageNo); // blanks all the gutter areas associated to a particular panel
130 void DrawExtremities(CGraphicsContext* aGc); // blanks very left and right of the window
131 inline TBool IsFirstPanel(TInt aPageNum);
132 inline TBool IsLastPanel(TInt aPageNum);
133 // from MPrintProcessObserver
134 virtual void NotifyPrintStarted(TPrintParameters aPrintParams);
135 virtual void NotifyBandPrinted(TInt aPercentageOfPagePrinted, TInt aCurrentPageNum, TInt aCurrentCopyNum);
136 virtual void NotifyPrintEnded(TInt anErrorCode);
137 // from MPageRegionPrinter
138 virtual void PrintBandL(CGraphicsDevice* aDevice,TInt aPageNo,const TBandAttributes& aBand);
140 CPrintPreviewDevice* iDevice;
141 CPrintSetup* iPrintSetup;
142 MPageRegionPrinter* iAppBodyPrinter;
143 MPrintProcessObserver* iObserver; // may be null
144 RWsSession* iWsSession;
147 CArrayFix<TPreviewPanel>* iPanelArray;
149 TPrintPreviewFormat iFormat;
150 TPrintParameters iPrintParams; // current preview range
151 TMarginState iMarginState; // whether the margins are on or not
152 TSize iPanelSizeInPixels;
153 TSize iWinSize; // size of the window (for layout purposes)
154 TPoint iOrigin; // origin in the window to use for drawing
156 TSize iActualGutter; // gap from the edge of the panel to either screen edge or adjacent panel
159 TSize iRndError; // rounding error from calculation of iActualGutter
160 TRange iDrawRange; // the pages that actually require drawing - ie have not been scrolled
164 /** Internalises the margin state from a read stream.
166 @param aThing The margin state to be internalised - on or off.
167 @param aStream The read stream from which the margin state is to be internalised.
171 IMPORT_C void InternalizeL(CPrintPreviewImage::TMarginState& aThing,RReadStream& aStream);
173 inline RWriteStream& operator<<(RWriteStream& aStream,const CPrintPreviewImage::TMarginState& aThing)
178 {aStream.WriteUint8L(aThing);return aStream;}
180 inline RReadStream& operator>>(RReadStream& aStream,CPrintPreviewImage::TMarginState& aThing)
185 {InternalizeL(aThing,aStream);return aStream;}
191 // move to private source...
193 inline TBool CPrintPreviewImage::IsFirstPanel(TInt aPageNum)
194 { return aPageNum==iPrintParams.iFirstPage; }
196 inline TBool CPrintPreviewImage::IsLastPanel(TInt aPageNum)
197 { return aPageNum==iPrintParams.iLastPage; }