|
1 /* |
|
2 * Copyright (c) 2002-2005 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: Rich text container |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CCARICHTEXTCONTAINER_H |
|
21 #define CCARICHTEXTCONTAINER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include "MCAMessageContainer.h" |
|
25 #include "mcalayoutchangeobserver.h" |
|
26 #include "MCASettings.h" |
|
27 #include <e32base.h> |
|
28 #include <e32std.h> |
|
29 #include <frmtlay.h> // TCursorSelection |
|
30 |
|
31 |
|
32 // FORWARD DECLARATIONS |
|
33 class CCAMessageWrapper; |
|
34 class CParaFormatLayer; |
|
35 class CCharFormatLayer; |
|
36 class CRichText; |
|
37 class MLayDoc; |
|
38 class MCATextView; |
|
39 class CCAMessageExtensionsHandler; |
|
40 class CGulIcon; |
|
41 class MCAMessageUtils; |
|
42 class MCAAppUi; |
|
43 class MCASettingsPC; |
|
44 class MCAMsgAddedToRichTxtCtrlObserver; |
|
45 |
|
46 // CLASS DECLARATION |
|
47 |
|
48 /** |
|
49 * Rich text container |
|
50 * |
|
51 * @lib chat.app |
|
52 * @since Series 60 3.0 |
|
53 */ |
|
54 class CCARichTextContainer : public CBase, |
|
55 public MCAMessageContainer, |
|
56 public MCALayoutChangeObserver |
|
57 { |
|
58 public: // enumerations |
|
59 enum THighlightMovement |
|
60 { |
|
61 ENext = 0, |
|
62 EPrevious |
|
63 }; |
|
64 |
|
65 public: // Constructors and destructor |
|
66 |
|
67 /** |
|
68 * Two-phased constructor. |
|
69 * @param aTextView Viewer of the text |
|
70 * @param aExtensionsHandler Message extensions handler |
|
71 * @param aFromMe "From me" icon. |
|
72 * @param aToMe "To me" icon. |
|
73 * @param aMap Graphics device map for converting pixels to twips |
|
74 * @param aScrollOver Should we scroll over the top and bottom, |
|
75 * i.e. disabling highlight when pressing up at top. |
|
76 * @param aAddMsgObserver - observer |
|
77 */ |
|
78 static CCARichTextContainer* NewL( MCAAppUi& aAppUi, |
|
79 MCASettingsPC& aSettingsPC, |
|
80 MCATextView& aTextView, |
|
81 CCAMessageExtensionsHandler& aExtensionsHandler, |
|
82 CGulIcon*& aFromMe, |
|
83 CGulIcon*& aToMe, |
|
84 CGulIcon*& aUnsupported, |
|
85 CGulIcon*& aCorrupted, |
|
86 MGraphicsDeviceMap& aMap, |
|
87 TBool aScrollOver = ETrue, |
|
88 MCAMsgAddedToRichTxtCtrlObserver* aAddMsgObserver = NULL ); |
|
89 |
|
90 /** |
|
91 * Destructor. |
|
92 */ |
|
93 virtual ~CCARichTextContainer(); |
|
94 |
|
95 public: // New functions |
|
96 |
|
97 /** |
|
98 * @return Selected message or NULL if nothing selected |
|
99 */ |
|
100 MCAConversationMessage* SelectedMessage(); |
|
101 |
|
102 /** |
|
103 * @return Buffer containing the currently selected text |
|
104 * (or empty buffer if nothing selected) |
|
105 */ |
|
106 HBufC* SelectedItemL(); |
|
107 |
|
108 /** |
|
109 * @return Type of selected item |
|
110 */ |
|
111 TInt SelectedItemType(); |
|
112 |
|
113 /** |
|
114 * @return Text layout interface for displaying the text |
|
115 */ |
|
116 MLayDoc* TextLayout(); |
|
117 |
|
118 /** |
|
119 * Moves current highlight selection |
|
120 * @return KErrNotFound If there are no items to highlight. |
|
121 * KErrNone otherwise. |
|
122 */ |
|
123 TInt MoveHighlightL( THighlightMovement aDirection ); |
|
124 |
|
125 /** |
|
126 * Set all highlighting off |
|
127 */ |
|
128 void DisableHighlightL(); |
|
129 |
|
130 /** |
|
131 * Sets item highlight on or off |
|
132 * @param aItemHighlight ETrue if the items inside messages |
|
133 * should be highlighted |
|
134 */ |
|
135 void SetItemHighlight( TBool aItemHighlight ); |
|
136 |
|
137 /** |
|
138 * @return ETrue if some item is highlighted |
|
139 */ |
|
140 TBool Highlighted(); |
|
141 |
|
142 /** |
|
143 * Highlights whole message or item at given position. |
|
144 * @param aPos Highlights the message or item which has |
|
145 * the craracter at aPos |
|
146 * @return KErrNone - if highlighted a new item |
|
147 * KErrAlreadyExists - if item is already highlighted |
|
148 * KErrNotFound - if can't find message or item at aPos |
|
149 */ |
|
150 TInt HighlightItemAtPosL( TInt aPos ); |
|
151 |
|
152 public: // From MCALayoutChangeObserver |
|
153 |
|
154 /** |
|
155 * From MCALayoutChangeObserver |
|
156 */ |
|
157 void LayoutChangedL( TInt aType ); |
|
158 |
|
159 public: // Functions from MCAMessageContainer |
|
160 |
|
161 /** |
|
162 * Check if chat container is deleted. |
|
163 * Use this to check if the messages still exists |
|
164 * @return ETrue: chat is deleted, |
|
165 * EFalse: chat is not deleted |
|
166 */ |
|
167 TBool IsDeleted() const; |
|
168 |
|
169 protected: // Functions from MCAMessageContainer |
|
170 |
|
171 /** |
|
172 * Add new message to container |
|
173 * @param aMessage Message |
|
174 */ |
|
175 void AddMessageL( MCAConversationMessage& aMessage ); |
|
176 |
|
177 /** |
|
178 * Inform about changed message |
|
179 * @param aIndex Index of changed message |
|
180 */ |
|
181 void MessageChangedL( TInt aIndex ); |
|
182 |
|
183 /** |
|
184 * Remove message from container |
|
185 * @param aIndex Index of message to be removed |
|
186 */ |
|
187 void RemoveMessage( TInt aIndex ); |
|
188 |
|
189 /** |
|
190 * Marks message container as deleted. |
|
191 */ |
|
192 void MarkDeleted(); |
|
193 |
|
194 /** |
|
195 * @see MCAMessageContainer |
|
196 */ |
|
197 void InsertMessageL( MCAConversationMessage& aMessage ); |
|
198 |
|
199 protected: // New functions |
|
200 |
|
201 /** |
|
202 * Updates all wrappers after (and including) aFirstIndex |
|
203 * Adds aChange to wrapper positions (in rich text) |
|
204 * @param aFirstIndex Index of first modified wrapper |
|
205 * @param aChange Removed or added number of characters in rich |
|
206 * text before wrapper at aFirstIndex |
|
207 */ |
|
208 void UpdateWrappers( TInt aFirstIndex, TInt aChange ); |
|
209 |
|
210 /** |
|
211 * @return Union of two selections |
|
212 */ |
|
213 TCursorSelection Union( const TCursorSelection& aSel1, |
|
214 const TCursorSelection& aSel2 ); |
|
215 |
|
216 /** |
|
217 * @return Currently highlighted selection, or last |
|
218 * message if highlighting is disabled |
|
219 */ |
|
220 TCursorSelection CurrentSelection() const; |
|
221 |
|
222 /** |
|
223 * Sets the background color of selected text |
|
224 */ |
|
225 void TextBackColorL( const TCursorSelection& aSel, const TRgb& aColor ); |
|
226 |
|
227 /** |
|
228 * Sets the color of selected text |
|
229 */ |
|
230 void TextColorL( const TCursorSelection& aSel, const TRgb& aColor ); |
|
231 |
|
232 /** |
|
233 * Sets the background color of selected paragraph |
|
234 */ |
|
235 void BackColorL( const TCursorSelection& aSel, const TRgb& aColor ); |
|
236 |
|
237 /** |
|
238 * Format the highlight item |
|
239 */ |
|
240 void HighLightItemL( const TCursorSelection& aSel ); |
|
241 |
|
242 /** |
|
243 * Sets the selection bold |
|
244 */ |
|
245 void BoldL( const TCursorSelection& aSel ); |
|
246 |
|
247 /** |
|
248 * Parses text for highlight items (phone numbers, urls) and places |
|
249 * the positions to messagewrapper. |
|
250 * @param aText Text to be parsed |
|
251 * @param aStartPos Start position of aText in rich text |
|
252 * @param aRelativePos Relative position of aText inside one message |
|
253 * @param aMessageWrapper Message wrapper where positions are stored |
|
254 */ |
|
255 void ParseTextL( const TDesC& aText, TInt aStartPos, TInt aRelativePos, |
|
256 CCAMessageWrapper& aMessageWrapper ); |
|
257 |
|
258 /** |
|
259 * Add UserIdentity of a message to rich text |
|
260 * @param aMessageWrapper Message wrapper |
|
261 * @return Selection for UserIdentity |
|
262 */ |
|
263 TCursorSelection AddUserIdentityL( CCAMessageWrapper& aMessageWrapper ); |
|
264 |
|
265 /** |
|
266 * Add nickname of a message to rich text |
|
267 * @param aMessageWrapper Message wrapper |
|
268 * @return Selection for nickname (for coloring) |
|
269 */ |
|
270 TCursorSelection AddNickL( CCAMessageWrapper& aMessageWrapper ); |
|
271 |
|
272 /** |
|
273 * Add timestamp of a message to rich text |
|
274 * @param aMessageWrapper Message wrapper |
|
275 * @return Selection of timestamp |
|
276 */ |
|
277 TCursorSelection AddTimeStampL( CCAMessageWrapper& aMessageWrapper ); |
|
278 |
|
279 /** |
|
280 * Add content of a message to rich text |
|
281 * @param aMsgStart Start position of this message in rich text |
|
282 * @param aMessageWrapper Message wrapper |
|
283 */ |
|
284 void AddContentL( TInt aMsgStart, CCAMessageWrapper& aMessageWrapper ); |
|
285 |
|
286 /** |
|
287 * Add thumbnail of a picture message to rich text |
|
288 * @param aPos Position in rich text |
|
289 * @param aMessageWrapper Message wrapper |
|
290 */ |
|
291 void AddThumbL( TInt aPos, CCAMessageWrapper& aMessageWrapper ); |
|
292 |
|
293 /** |
|
294 * Updates the color of messages according to current skin. |
|
295 * Only the theme colored part of messages are updated. |
|
296 * This method should be called when the skin is changed. |
|
297 * @return None |
|
298 */ |
|
299 void UpdateSkinnedTextColourL(); |
|
300 |
|
301 /** |
|
302 * Helper method to determine which part of the message really is |
|
303 * colored by the active skin. |
|
304 * @param aMessageWrapper Message to inspect |
|
305 * @param aUseDefaultColors Variation for default colours |
|
306 * @param aCustomDefinedColor Has user customized the message colour |
|
307 * @return Selection of the text which follows the skin color |
|
308 */ |
|
309 TCursorSelection SkinColoredSelection( |
|
310 CCAMessageWrapper& aMessageWrapper, |
|
311 TBool aUseDefaultColors, |
|
312 TBool aCustomDefinedColor ); |
|
313 |
|
314 /** |
|
315 * Helper method for replacing all paragraph delimiters |
|
316 * inside message content with line breaks, needed for |
|
317 * keeping text alignment consistent inside one message. |
|
318 * Used in AddContentL. |
|
319 * @since S60 v3.1 |
|
320 * @param aSource Source descriptor. |
|
321 * @param aTarget Target descriptor. Caller is responsible |
|
322 * to provide a large enough descriptor, |
|
323 * aTarget size must not be less than |
|
324 * size of aSource. |
|
325 */ |
|
326 void ReplaceParaDelimsWithLineBreaks( |
|
327 const TPtrC& aSource, |
|
328 TPtr& aTarget ) const; |
|
329 |
|
330 /** |
|
331 * Helper method to update selection inside rich text. |
|
332 * This will remove the highlight from previously selected item |
|
333 * and add highlight to newly selected item. |
|
334 * @since S60 v3.1 |
|
335 */ |
|
336 void UpdateSelectionL(); |
|
337 |
|
338 /** |
|
339 * Insert nickname of a message to rich text start. |
|
340 * @param aMessageWrapper Message wrapper. |
|
341 * @return Selection for nickname. |
|
342 */ |
|
343 TCursorSelection InsertNickL( CCAMessageWrapper& aMessageWrapper ); |
|
344 |
|
345 /** |
|
346 * Insert timestamp of a message to rich text. |
|
347 * @param aMessageWrapper Message wrapper. |
|
348 * @return Selection of timestamp. |
|
349 */ |
|
350 TCursorSelection InsertTimeStampL( CCAMessageWrapper& aMessageWrapper ); |
|
351 |
|
352 /** |
|
353 * Insert User Identity of a message to rich text. |
|
354 * @param aMessageWrapper Message wrapper. |
|
355 * @return Selection of User Identity. |
|
356 */ |
|
357 TCursorSelection InsertUserIdentityL( CCAMessageWrapper& aMessageWrapper ); |
|
358 |
|
359 /** |
|
360 * Insert content of a message to rich text. |
|
361 * @param aMessageWrapper Message wrapper. |
|
362 * @return Length of content added. |
|
363 */ |
|
364 TInt InsertContentL( CCAMessageWrapper& aMessageWrapper ); |
|
365 |
|
366 /** |
|
367 * Reads integer resource value from resources |
|
368 * @param aResourceId resource id which is read |
|
369 * @return value of wanted integer resource flag |
|
370 */ |
|
371 TInt IntResourceValueL( TInt aResourceId ); |
|
372 |
|
373 public: |
|
374 /** |
|
375 * @returns the total messages in the view |
|
376 */ |
|
377 TInt GetMessageCount(); |
|
378 |
|
379 /** |
|
380 * Changes the HighlightColor |
|
381 */ |
|
382 void ChangeHighlightColorL(); |
|
383 |
|
384 //when user navigate among tab. |
|
385 /** |
|
386 * unregisters the observer added to listen to |
|
387 * message added in rich text container |
|
388 * @Param - None |
|
389 * @return - None |
|
390 */ |
|
391 void UnRegisterRichTxtCtrlObserver(); |
|
392 |
|
393 private: |
|
394 |
|
395 /** |
|
396 * C++ default constructor. |
|
397 */ |
|
398 CCARichTextContainer( MCAAppUi& aAppUi, |
|
399 MCASettingsPC& aSettingsPC, |
|
400 MCATextView& aTextView, |
|
401 CCAMessageExtensionsHandler& aExtensionsHandler, |
|
402 CGulIcon*& aFromMe, |
|
403 CGulIcon*& aToMe, |
|
404 CGulIcon*& aUnsupported, |
|
405 CGulIcon*& aCorrupted, |
|
406 MGraphicsDeviceMap& aMap, |
|
407 TBool aScrollOver, |
|
408 MCAMsgAddedToRichTxtCtrlObserver* aAddMsgObserver ); |
|
409 |
|
410 /** |
|
411 * By default Symbian 2nd phase constructor is private. |
|
412 */ |
|
413 void ConstructL(); |
|
414 |
|
415 private: // enums |
|
416 |
|
417 enum THighlightState |
|
418 { |
|
419 ENoHighlight = 0, |
|
420 EItemSelected, |
|
421 EMessageTop, |
|
422 EMessageBottom |
|
423 }; |
|
424 |
|
425 private: // Data |
|
426 |
|
427 // doesn't own, interface to AppUi -class |
|
428 MCAAppUi& iAppUi; |
|
429 |
|
430 // doesn't own, interface to application settings |
|
431 MCASettingsPC& iSettings; |
|
432 |
|
433 // doesn't own, interface to text viewer |
|
434 MCATextView& iTextView; |
|
435 |
|
436 // Owns. Paragraph formatter |
|
437 CParaFormatLayer* iParaFormatLayer; |
|
438 |
|
439 // Owns. Character formatter |
|
440 CCharFormatLayer* iCharFormatLayer; |
|
441 |
|
442 // Owns. rich text document |
|
443 CRichText* iRichText; |
|
444 |
|
445 // Owns. message wrappers |
|
446 RPointerArray<CCAMessageWrapper> iMessages; |
|
447 |
|
448 // "From me" icon. Not owned. |
|
449 // Reference to a pointer because this can change |
|
450 CGulIcon*& iFromMe; |
|
451 |
|
452 // "To me" icon. Not owned. |
|
453 // Reference to a pointer because this can change |
|
454 CGulIcon*& iToMe; |
|
455 |
|
456 // "Unsupported" icon. Not owned. |
|
457 // Reference to a pointer because this can change |
|
458 CGulIcon*& iUnsupported; |
|
459 |
|
460 // "Corrupted" icon. Not owned. |
|
461 // Reference to a pointer because this can change |
|
462 CGulIcon*& iCorrupted; |
|
463 |
|
464 // item highlight |
|
465 TBool iItemHighlight; |
|
466 |
|
467 // selected message |
|
468 TInt iSelected; |
|
469 |
|
470 // selected item in message |
|
471 TInt iSelectedItem; |
|
472 |
|
473 // current highlight state |
|
474 THighlightState iHighlightState; |
|
475 |
|
476 // previous selection |
|
477 TCursorSelection iPrevious; |
|
478 |
|
479 // message extensions handler |
|
480 CCAMessageExtensionsHandler& iExtensionsHandler; |
|
481 |
|
482 // interface to graphics device for converting pixels to twips |
|
483 MGraphicsDeviceMap& iMap; |
|
484 |
|
485 // Should we scroll over the top and bottom, |
|
486 // i.e. disabling highlight when pressing up at top. |
|
487 TBool iScrollOver; |
|
488 |
|
489 // should whole message be colored |
|
490 TBool iColorWholeMessage; |
|
491 // alternative colors |
|
492 TBool iOwnMsgColorInUse; |
|
493 TRgb iOwnMsgColor; |
|
494 TBool iMsgColorInUse; |
|
495 TRgb iMsgColor; |
|
496 |
|
497 TRgb iDefaultMsgColor; |
|
498 |
|
499 // Show timestamp setting value |
|
500 TBool iShowTimeStamps; |
|
501 |
|
502 // icon in front of own messages |
|
503 TBool iOwnMsgIcon; |
|
504 // icon in front of other messages |
|
505 TBool iMsgIcon; |
|
506 |
|
507 TSize iThumbSize; |
|
508 |
|
509 // doesn't own |
|
510 const CFont* iPrimaryFont; |
|
511 const CFont* iSecondaryFont; |
|
512 |
|
513 // are messages deleted |
|
514 TBool iMessagesDeleted; |
|
515 |
|
516 // is RichTextContainer container recovering from OOM situation |
|
517 TBool iRecoveringFromOOM; |
|
518 |
|
519 //used to notify of message was added to the rich text control. |
|
520 MCAMsgAddedToRichTxtCtrlObserver* iAddMsgObserver; |
|
521 |
|
522 //Used only for recorded chats |
|
523 TInt iMsgAddedToContentProcessor; |
|
524 |
|
525 }; |
|
526 |
|
527 #endif // CCARICHTEXTCONTAINER_H |
|
528 |
|
529 // End of File |