1 crichbio.h |
1 /* |
|
2 * Copyright (c) 2002 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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * A UI control used by Smart Messaging Viewers. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef _CRICHBIO_H_ |
|
22 #define _CRICHBIO_H_ |
|
23 |
|
24 // INCLUDES |
|
25 |
|
26 #include <coecntrl.h> // CCoeControl |
|
27 #include <badesca.h> // CDesC16ArrayFlat |
|
28 #include <txtfrmat.h> // TCharFormat |
|
29 #include <MsgEditor.hrh> // TMsgCursorLocation |
|
30 |
|
31 // DATA TYPES |
|
32 |
|
33 /** |
|
34 * This enumeration defines the types of CRichBio |
|
35 * No longer used meaningfully but defined for BC |
|
36 * |
|
37 */ |
|
38 enum TRichBioMode |
|
39 { |
|
40 ERichBioModeEditorBase, |
|
41 ERichBioModeStandard |
|
42 }; |
|
43 |
|
44 // FORWARD DECLARATIONS |
|
45 |
|
46 class CEikRichTextEditor; |
|
47 class CMsgExpandableControlEditor; |
|
48 |
|
49 /** |
|
50 * A UI control used by Smart Messaging Viewers. |
|
51 * This control owns an editor, which is capable of viewing rich text content. |
|
52 * NOTE! This is only intended for use with the Smart Message Viewers. |
|
53 */ |
|
54 class CRichBio : public CCoeControl |
|
55 { |
|
56 public: // construction |
|
57 |
|
58 /** |
|
59 * Two-phased constructor. Constructs the complete object. |
|
60 * The parent control has to have a container window at this stage. |
|
61 * The type (TRichBioMode) is legacy code and has no effect on the |
|
62 * construction or use of the object. Either ERichBioModeEditorBase |
|
63 * or ERichBioModeStandard can be used with the same effect |
|
64 * @param aParent The parent control. |
|
65 * @param aMode Either ERichBioModeEditorBase or ERichBioModeStandard |
|
66 * @return a pointer to the created object. |
|
67 */ |
|
68 IMPORT_C static CRichBio* NewL( const CCoeControl* aParent, |
|
69 TRichBioMode aMode ); |
|
70 |
|
71 /** |
|
72 * Constructor. |
|
73 * ConstructL must be called after the container window is get. |
|
74 * The type (TRichBioMode) is legacy code and has no effect on the |
|
75 * construction or use of the object. Either ERichBioModeEditorBase |
|
76 * or ERichBioModeStandard can be used with the same effect |
|
77 * @param aMode Either ERichBioModeEditorBase or ERichBioModeStandard |
|
78 */ |
|
79 IMPORT_C CRichBio( TRichBioMode aMode ); |
|
80 |
|
81 /** |
|
82 * Second phase constructor. |
|
83 * The parent control has to have a container window at this stage. |
|
84 * @param aParent The parent control, which has container window. |
|
85 */ |
|
86 IMPORT_C void ConstructL( const CCoeControl* aParent ); |
|
87 |
|
88 public: // destruction |
|
89 |
|
90 /** |
|
91 * Destructor |
|
92 */ |
|
93 ~CRichBio(); |
|
94 |
|
95 public: // own methods |
|
96 |
|
97 /** |
|
98 * Adds a label and value pair. |
|
99 * The client does not need to check the length of the strings. This function will |
|
100 * wrap strings that are too long. |
|
101 * @param aLabel text to displayed in label text format. |
|
102 * @param aValue text to displayed in text format. |
|
103 */ |
|
104 IMPORT_C void AddItemL(const TDesC& aLabel, const TDesC& aValue); |
|
105 |
|
106 /** |
|
107 * This is needed for scrolling with Editor Base. |
|
108 * @return TRect Returns the rectangle of the "current" line. |
|
109 */ |
|
110 IMPORT_C TRect CurrentLineRect(); |
|
111 |
|
112 /** |
|
113 * For accessing the richtext editor. |
|
114 * Must not be called before ConstructL has been called. |
|
115 * @return Reference to the CEikRichTextEditor |
|
116 * @exception Panics if the iEditor is NULL. |
|
117 */ |
|
118 IMPORT_C CEikRichTextEditor& Editor(); |
|
119 |
|
120 /** |
|
121 * Is the editor base mode on. |
|
122 * @return ETrue if it is in Editor Base mode. |
|
123 */ |
|
124 IMPORT_C TBool IsEditorBaseMode() const; |
|
125 |
|
126 /** |
|
127 * Empties the data contents. |
|
128 */ |
|
129 IMPORT_C void Reset(); |
|
130 |
|
131 /** |
|
132 * Returns the preferred size of the control. |
|
133 * @param aSize Control may set its preferred size |
|
134 */ |
|
135 IMPORT_C void SetAndGetSizeL( TSize& aSize ); |
|
136 |
|
137 /** |
|
138 * Returns the rich text virtual length. |
|
139 * @return text length in rich text. |
|
140 */ |
|
141 IMPORT_C TInt VirtualHeight(); |
|
142 |
|
143 /** |
|
144 * Returns the current cursor position. |
|
145 * Even in the viewer mode control contains a hidden cursor. |
|
146 * This method return its position. |
|
147 * @return a position of the hidden cursor relative to the virtual length. |
|
148 */ |
|
149 IMPORT_C TInt VirtualVisibleTop(); |
|
150 |
|
151 /** |
|
152 * Find out if the cursor is at a certain position. |
|
153 * @param aLocation indicates either that the cursor is at the topmost |
|
154 * position of the control or at the bottom most position. |
|
155 * @return ETrue if the cursor is at the specified position, EFalse otherwise. |
|
156 */ |
|
157 IMPORT_C TBool IsCursorLocation(TMsgCursorLocation aLocation) const; |
|
158 |
|
159 /** |
|
160 * Performs the internal scrolling of control if needed. |
|
161 * @since 3.2 |
|
162 * |
|
163 * @param aPixelsToScroll Amount of pixels to scroll. |
|
164 * @param aDirection Scrolling direction. |
|
165 * @return Amount of pixels the where scrolled. Zero value means the component cannot |
|
166 * be scrolled to that direction anymore |
|
167 */ |
|
168 |
|
169 IMPORT_C TInt ScrollL( TInt aPixelsToScroll, TMsgScrollDirection aDirection ); |
|
170 |
|
171 /** |
|
172 * Prepares control for viewing. |
|
173 * @since 3.2 |
|
174 * @param aEvent The event type |
|
175 * @param aParam Event related parameters |
|
176 */ |
|
177 IMPORT_C void NotifyViewEvent( TMsgViewEvent aEvent, TInt aParam ); |
|
178 |
|
179 public: // from CCoeControl |
|
180 |
|
181 TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType); |
|
182 |
|
183 private: // Helper methods. |
|
184 |
|
185 /** |
|
186 * Applies the format of label text to viewer. |
|
187 * @param aFormat Character format to be applied. |
|
188 * @param aMask Character format mask |
|
189 */ |
|
190 void ApplyLabelFormat(TCharFormat& aFormat, TCharFormatMask& aMask); |
|
191 |
|
192 /** |
|
193 * Applies the format of value text to viewer. |
|
194 * @param aFormat Character format to be applied. |
|
195 * @param aMask Character format mask |
|
196 */ |
|
197 void ApplyValueFormat(TCharFormat& aFormat, TCharFormatMask& aMask); |
|
198 |
|
199 /** |
|
200 * Applies the format of value and label text to viewer. |
|
201 * @param aFormat Character format to be applied. |
|
202 * @param aMask Character format mask |
|
203 * @aIsLabel Determines is the text label or value. |
|
204 */ |
|
205 void ApplyFormat(TCharFormat& aFormat, TCharFormatMask& aMask, TBool aIsLabel); |
|
206 |
|
207 /** |
|
208 * Appends text to RichText viewer. |
|
209 * @param aLabel Label text |
|
210 * @param aValue value text |
|
211 */ |
|
212 void AddItemToRichTextL(const TDesC& aLabel, const TDesC& aValue); |
|
213 |
|
214 /** |
|
215 * Add text to viewer, checks and removes linefeeds and carriage returns |
|
216 * @param aText text to be added |
|
217 * @param aFormat Character format |
|
218 * @param aMask Character format mask |
|
219 */ |
|
220 void AppendTextL( const TDesC& aText, |
|
221 const TCharFormat& aFormat, |
|
222 const TCharFormatMask& aMask ); |
|
223 |
|
224 /** |
|
225 * Checks either cache exists or not. |
|
226 * @return TBool exists cache or not |
|
227 */ |
|
228 TBool CacheExists(); |
|
229 |
|
230 /** |
|
231 * Adds items to richtext from cache. |
|
232 */ |
|
233 void LoadFromCacheL(); |
|
234 |
|
235 /** |
|
236 * Adds item to cache |
|
237 * @param aLabel label text |
|
238 * @param aValue value text |
|
239 */ |
|
240 void CacheItemL(const TDesC& aLabel, const TDesC& aValue); |
|
241 |
|
242 /** |
|
243 * panic wrapper |
|
244 * @param aCode panic code. |
|
245 */ |
|
246 static void Panic( TInt aPanic ); |
|
247 |
|
248 |
|
249 |
|
250 private: |
|
251 |
|
252 /** |
|
253 * Default constructor prohibited |
|
254 */ |
|
255 CRichBio(); |
|
256 |
|
257 /** |
|
258 * Copy constructor hidden away. |
|
259 */ |
|
260 CRichBio(const CRichBio& aSource); |
|
261 |
|
262 /** |
|
263 * Assignment operator hidden away. |
|
264 */ |
|
265 const CRichBio& operator=(const CRichBio& aSource); |
|
266 |
|
267 private: // from CCoeControl |
|
268 |
|
269 void Draw(const TRect& aRect) const; |
|
270 |
|
271 TInt CountComponentControls() const; |
|
272 |
|
273 CCoeControl* ComponentControl(TInt aIndex) const; |
|
274 |
|
275 void SizeChanged(); |
|
276 |
|
277 private: |
|
278 |
|
279 /// Introduce inner class. |
|
280 class CEdwinSizeObserver; |
|
281 |
|
282 /// Declare inner class friend. |
|
283 friend class CEdwinSizeObserver; |
|
284 |
|
285 /// Pointer to the editor size observer. |
|
286 CEdwinSizeObserver* iEdwinSizeObserver; |
|
287 |
|
288 /// Editor control |
|
289 CMsgExpandableControlEditor* iEditor; |
|
290 |
|
291 /// preserved for binary compatibility |
|
292 TInt iVirtualHeight; |
|
293 |
|
294 // startup cache for data |
|
295 CDesC16ArrayFlat* iLabelCache; |
|
296 |
|
297 // startup cache for data |
|
298 CDesC16ArrayFlat* iValueCache; |
|
299 |
|
300 // Editor Base mode on or off. |
|
301 const TRichBioMode iMode; |
|
302 |
|
303 /// is first item |
|
304 TBool iIsFirstItem; |
|
305 |
|
306 private: |
|
307 friend class T_RichBioTestSuite; |
|
308 }; |
|
309 |
|
310 #endif //_CRICHBIO_H_ |
|
311 |
|
312 // end of file |