printingsupport/printinguisupport/inc/PRNPREV.H
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #if !defined (__PRNPREV_H__)
       
    17 #define __PRNPREV_H__
       
    18 
       
    19 #if !defined(__E32STD_H__)
       
    20 #include  <e32std.h>
       
    21 #endif
       
    22 #if !defined(__E32BASE_H__)
       
    23 #include  <e32base.h>
       
    24 #endif
       
    25 #if !defined(__PRNSETUP_H__)
       
    26 #include <prnsetup.h>
       
    27 #endif
       
    28 
       
    29 // classes defined:
       
    30 class TPrintPreviewFormat;
       
    31 class TPreviewPanel;
       
    32 class CPrintPreviewImage;
       
    33 //
       
    34 
       
    35 // forward references:
       
    36 class RWsSession;
       
    37 class RWindow;
       
    38 class CPrintPreviewDevice;
       
    39 //
       
    40 
       
    41 
       
    42 class TPrintPreviewFormat
       
    43 /** Print preview format information.
       
    44 
       
    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. 
       
    47 
       
    48 Preview information includes:
       
    49 
       
    50 - panel settings: multiple pages can be previewed at once; the display area 
       
    51 for each page is termed a panel.
       
    52 
       
    53 - label settings: each panel can have an associated label, which specifies the 
       
    54 corresponding document page number 
       
    55 
       
    56 @publishedAll 
       
    57 @released */
       
    58 	{
       
    59 public:
       
    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;
       
    74 	};
       
    75 
       
    76 
       
    77 class CPrintPreviewImage : public CBase, private MPrintProcessObserver, private MPageRegionPrinter
       
    78 /** Print preview image.
       
    79 
       
    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 
       
    83 the preview image.
       
    84 
       
    85 The class provides a callback to the application code that draws the preview 
       
    86 pages. 
       
    87 
       
    88 @publishedAll 
       
    89 @released */
       
    90 	{
       
    91 public:
       
    92 	/** Margin display state flags. */
       
    93 	enum TMarginState {
       
    94 		/** Show margins in print preview image. */
       
    95 		EShowMargins,
       
    96 		/** Hide margins in print preview image. */
       
    97 		EHideMargins
       
    98 		};
       
    99 public:
       
   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)
       
   109 	//
       
   110 private:
       
   111 	class TPreviewPanel;
       
   112 	class TRange
       
   113 		{
       
   114 	public:
       
   115 		TInt iFrom;
       
   116 		TInt iTo;
       
   117 		};
       
   118 private:
       
   119 	CPrintPreviewImage(CPrintSetup& aPrintSetup,MPageRegionPrinter& aBodyPrinter,RWsSession& aWsSession,
       
   120 						RWindow& aWindow,const TSize& aMaxWindowSize,const TPrintPreviewFormat& aStaticFormat);
       
   121 	void ConstructL();
       
   122 	void CalculateHeaderFooterRects(TRect& aHeaderRectInPixels,TRect& aFooterRectInPixels);
       
   123 	TInt SetPanelArrayL(const TInt aFirstPage,const TInt aNumPagesToView); 
       
   124 	void SetLabelWidth();
       
   125 	void ScrollPanels();
       
   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);
       
   139 private:
       
   140 	CPrintPreviewDevice* iDevice;
       
   141 	CPrintSetup* iPrintSetup;
       
   142 	MPageRegionPrinter* iAppBodyPrinter;
       
   143 	MPrintProcessObserver* iObserver; // may be null
       
   144 	RWsSession* iWsSession;
       
   145 	RWindow* iWindow;
       
   146 	CFont* iLabelFont;
       
   147 	CArrayFix<TPreviewPanel>* iPanelArray;
       
   148 	//
       
   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
       
   155 	TSize iLabelSize;
       
   156 	TSize iActualGutter; // gap from the edge of the panel to either screen edge or adjacent panel
       
   157 	TInt iNumPagesInDoc; 
       
   158 	TInt iNumBands;
       
   159 	TSize iRndError; // rounding error from calculation of iActualGutter
       
   160 	TRange iDrawRange; // the pages that actually require drawing - ie have not been scrolled 
       
   161 	};
       
   162 
       
   163 
       
   164 /** Internalises the margin state from a read stream.
       
   165 
       
   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. 
       
   168 
       
   169 @publishedAll 
       
   170 @released */
       
   171 IMPORT_C void InternalizeL(CPrintPreviewImage::TMarginState& aThing,RReadStream& aStream);
       
   172 
       
   173 inline RWriteStream& operator<<(RWriteStream& aStream,const CPrintPreviewImage::TMarginState& aThing) 
       
   174 /**
       
   175 @publishedAll 
       
   176 @released 
       
   177 */
       
   178 	{aStream.WriteUint8L(aThing);return aStream;}
       
   179 
       
   180 inline RReadStream& operator>>(RReadStream& aStream,CPrintPreviewImage::TMarginState& aThing) 
       
   181 /**
       
   182 @publishedAll 
       
   183 @released 
       
   184 */
       
   185 	{InternalizeL(aThing,aStream);return aStream;}
       
   186 
       
   187 //
       
   188 // inlines
       
   189 //
       
   190 
       
   191 // move to private source...
       
   192 
       
   193 inline TBool CPrintPreviewImage::IsFirstPanel(TInt aPageNum) 
       
   194 	{ return aPageNum==iPrintParams.iFirstPage; }
       
   195 
       
   196 inline TBool CPrintPreviewImage::IsLastPanel(TInt aPageNum) 
       
   197 	{ return aPageNum==iPrintParams.iLastPage; }
       
   198 
       
   199 
       
   200 #endif