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