|
1 /* |
|
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __FRMPAGE_H__ |
|
20 #define __FRMPAGE_H__ |
|
21 |
|
22 #include <e32std.h> |
|
23 #include <e32base.h> |
|
24 #include <gdi.h> |
|
25 |
|
26 class MLayDoc; |
|
27 class CTextLayout; |
|
28 class CParaFormat; |
|
29 |
|
30 // |
|
31 // The following two classes are for internal use only |
|
32 // |
|
33 |
|
34 /** |
|
35 @internalComponent |
|
36 */ |
|
37 struct TPageLine |
|
38 { |
|
39 TInt iDocPos; |
|
40 TInt iLineHeight; |
|
41 TBool iKeepWithNext; |
|
42 TBool iStartNewPage; |
|
43 }; |
|
44 |
|
45 /** |
|
46 @internalComponent |
|
47 */ |
|
48 class TLinePaginator |
|
49 { |
|
50 public: |
|
51 TLinePaginator(); |
|
52 TBool AppendLineL(TPageLine aLine); |
|
53 void FlushL(TInt aEndDocPos); |
|
54 void SetPageHeight(TInt aPageHeight); |
|
55 void SetArray(CArrayFix<TInt>* aCharsPerPage); |
|
56 void Reset(); |
|
57 private: |
|
58 void ResetArray(); |
|
59 void InsertPageBreakL(); |
|
60 void SetPotentialBreakPoint(TInt aDocPos); |
|
61 void CheckTallLineL(TPageLine& aLine); |
|
62 private: |
|
63 CArrayFix<TInt>* iPageList; // This is created and destroyed by the application running the paginator. |
|
64 TInt iDocPos; |
|
65 TBool iKeepWithPrev; |
|
66 TInt iPageHeight; |
|
67 TInt iHeightRem; |
|
68 TBool iBreakOnPage; |
|
69 TInt iPrevPageBreak; |
|
70 TInt iHeightLines; |
|
71 TBool iFirstLine; // Used to prevent page break being inserted at top of document. |
|
72 }; |
|
73 |
|
74 /** |
|
75 An abstract class which must be mixed with application calling the active object. |
|
76 It specifies the protocol for a pagination observer. A |
|
77 pagination observer may be used when paginating a document in the background |
|
78 (using CTextPaginator::PaginateCompleteDocumentL()). It notifies the client |
|
79 on page completion, document completion, and on errors. |
|
80 |
|
81 The observer is set up using the function CTextPaginator::SetObserver(). |
|
82 @publishedAll |
|
83 @released |
|
84 */ |
|
85 class MPaginateObserver |
|
86 { |
|
87 public: |
|
88 |
|
89 /** Notifies the client on completion of document pagination. */ |
|
90 virtual void NotifyCompletion()=0; |
|
91 |
|
92 /** Notifies the client when a leave is trapped or when the pagination is cancelled. |
|
93 Implements error handling. |
|
94 @param anErrorCode Error code - indicates the type of error. */ |
|
95 virtual void NotifyError(TInt anErrorCode)=0; |
|
96 |
|
97 /** Called by the paginator when each page has been completed. |
|
98 @param aCurrentPageNum The number of the page. */ |
|
99 virtual void NotifyPageCompletion(TInt aCurrentPageNum)=0; |
|
100 }; |
|
101 |
|
102 |
|
103 |
|
104 /** |
|
105 Paginates a document. |
|
106 |
|
107 Sets the page dimensions, the printer device and the source document to paginate. |
|
108 Uses a page list, which is an array of characters-per-page values. |
|
109 |
|
110 There are two ways of paginating a document; either in the background using |
|
111 an active object or by incrementally adding text to the document and repeatedly |
|
112 notifying the CTextPaginator object to paginate the added text. If an active |
|
113 object is used, the client may be notified on completion of pages, on trapped |
|
114 leaves and on completion of the pagination by an optional pagination observer. |
|
115 @publishedAll |
|
116 @released |
|
117 */ |
|
118 class CTextPaginator : public CActive |
|
119 { |
|
120 public: |
|
121 // 2 phase ctor: automatically adds self to active scheduler |
|
122 IMPORT_C static CTextPaginator* NewL(CPrinterDevice* aPrinterDevice,CArrayFix<TInt>* aCharsPerPage,TInt aPriority); |
|
123 IMPORT_C ~CTextPaginator(); |
|
124 IMPORT_C void SetDocumentL(MLayDoc* aLayDoc); // Must call before anything else |
|
125 IMPORT_C void SetPrinterDevice(CPrinterDevice* aPrinterDevice); |
|
126 IMPORT_C void SetPageSpecInTwips(const TPageSpec& aPageSpec); // Physical size of page. |
|
127 IMPORT_C void SetPageMarginsInTwips(const TMargins& aPageMargins); // Default are all zero. |
|
128 IMPORT_C void SetTextMarginWidthsInTwips(TInt aLabelMarginWidth,TInt aGutterMarginWidth); // label margins (if any) |
|
129 // Called to initiate paginating a document using active object |
|
130 IMPORT_C void SetObserver(MPaginateObserver* aObserver); |
|
131 IMPORT_C void PaginateCompleteDocumentL(); |
|
132 // Called to paginate incrementally, without active object |
|
133 IMPORT_C TInt AppendTextL(TInt& aCumulativeDocPos); // returns number of page breaks so far |
|
134 IMPORT_C TInt PaginationCompletedL(); // called at end of incremental pagination - returns total number of page breaks |
|
135 private: |
|
136 enum TPaginateMode |
|
137 { |
|
138 EFPaginateCompleteDocument, |
|
139 EFPaginateIncrementally |
|
140 }; |
|
141 enum |
|
142 { |
|
143 EPageLineArrayGranularity=10, |
|
144 EPageListArrayGranularity=5 |
|
145 }; |
|
146 enum |
|
147 { |
|
148 EFMaximumNumberLinesInBlock=20 |
|
149 }; |
|
150 private: |
|
151 CTextPaginator(TInt aPriority); |
|
152 void RunL(); // Active scheduler is friend - can access |
|
153 void DoCancel(); // Called by CActive::Cancel() |
|
154 void ConstructL(CPrinterDevice* aPrinterDevice,CArrayFix<TInt>* aCharsPerPage); |
|
155 void SetLayoutDimensions(); |
|
156 void SetOrReplaceDocumentL(MLayDoc* aLayDoc); |
|
157 TRect TextRectInTwips() const; |
|
158 TSize TextSizeInPixels() const; |
|
159 void TrapPaginateParagraphL(); |
|
160 void PaginateParagraphL(); |
|
161 void PageCompleted(); |
|
162 void Reque(); |
|
163 void ResetPaginator(); |
|
164 void CopyTempPageListL(); // Copies temporary page list to real one. |
|
165 void LeaveL(TInt aErr); |
|
166 private: |
|
167 MLayDoc* iLayDoc; |
|
168 MPaginateObserver* iObserver; |
|
169 CPrinterDevice* iPrinterDevice; |
|
170 TLinePaginator iPaginator; |
|
171 CTextLayout* iLayout; |
|
172 CArrayFix<TInt>* iPageList; |
|
173 CArrayFixFlat<TInt>* iTempPageList; |
|
174 CArrayFixFlat<TPageLine>* iPageLineArray; |
|
175 TSize iPageSizeInTwips; |
|
176 TMargins iPageMarginsInTwips; |
|
177 TInt iGutterMarginWidthInTwips; // Gap between labels and text proper - in twips |
|
178 TInt iLabelMarginWidthInTwips; |
|
179 TInt iDocPos; // Within the laydoc |
|
180 TBool iPageBreakChar; |
|
181 TPaginateMode iMode; |
|
182 }; |
|
183 |
|
184 #endif |
|
185 |