|
1 /* |
|
2 * Copyright (c) 2007-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: Meeting request attachments field |
|
15 * |
|
16 */ |
|
17 #include "emailtrace.h" |
|
18 #include "cesmrviewerattachmentsfield.h" |
|
19 |
|
20 //<cmail> |
|
21 #include "mesmrcalentry.h" |
|
22 #include "cesmrcontactmenuattachmenthandler.h" |
|
23 //</cmail> |
|
24 #include <esmrgui.rsg> |
|
25 #include <StringLoader.h> |
|
26 //<cmail> |
|
27 #include "esmricalvieweropcodes.hrh" |
|
28 #include "CFSMailMessage.h" |
|
29 //</cmail> |
|
30 |
|
31 #include "cesmrrichtextviewer.h" |
|
32 #include "cesmrrichtextlink.h" |
|
33 #include "mesmrlistobserver.h" |
|
34 #include "mesmrmeetingrequestentry.h" |
|
35 #include "tesmrinputparams.h" |
|
36 #include "cesmrattachment.h" |
|
37 #include "cesmrattachmentinfo.h" |
|
38 #include "cesmrcontactmenuhandler.h" |
|
39 #include "cmrimage.h" |
|
40 #include "nmrlayoutmanager.h" |
|
41 |
|
42 |
|
43 // Unnamed namespace for local definitions |
|
44 namespace { // codescanner::namespace |
|
45 |
|
46 //<cmail> |
|
47 // MR does not contain attachments |
|
48 const TInt KNoAttachments( 0 ); |
|
49 // MR contains one attachment |
|
50 const TInt KOneAttachment( 1 ); |
|
51 //</cmail> |
|
52 |
|
53 const TInt KOneKiloByte( 1024 ); |
|
54 |
|
55 }//namespace |
|
56 |
|
57 // ======== MEMBER FUNCTIONS ======== |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CESMRViewerAttachmentsField::CESMRViewerAttachmentsField |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CESMRViewerAttachmentsField::CESMRViewerAttachmentsField() |
|
64 : iFocused(EFalse) |
|
65 { |
|
66 FUNC_LOG; |
|
67 SetFieldId( EESMRFieldAttachments ); |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CESMRViewerAttachmentsField::~CESMRViewerAttachmentsField |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CESMRViewerAttachmentsField::~CESMRViewerAttachmentsField() |
|
75 { |
|
76 FUNC_LOG; |
|
77 delete iFieldIcon; |
|
78 delete iRichTextViewer; |
|
79 delete iAttachmentText; |
|
80 |
|
81 iESMRStatic.Close(); |
|
82 |
|
83 delete iAttachmentInfo; |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // CESMRViewerAttachmentsField::NewL |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 CESMRViewerAttachmentsField* CESMRViewerAttachmentsField::NewL() |
|
91 { |
|
92 FUNC_LOG; |
|
93 CESMRViewerAttachmentsField* self = new( ELeave )CESMRViewerAttachmentsField; |
|
94 CleanupStack::PushL( self ); |
|
95 self->ConstructL(); |
|
96 CleanupStack::Pop( self ); |
|
97 return self; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CESMRViewerAttachmentsField::ConstructL() |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 void CESMRViewerAttachmentsField::ConstructL() |
|
105 { |
|
106 FUNC_LOG; |
|
107 SetFocusType( EESMRNoFocus ); |
|
108 |
|
109 iFieldIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapMailAttachment ); |
|
110 iFieldIcon->SetParent( this ); |
|
111 |
|
112 iRichTextViewer = CESMRRichTextViewer::NewL( this ); |
|
113 iRichTextViewer->SetEdwinSizeObserver( this ); |
|
114 iRichTextViewer->SetLinkObserver( this ); |
|
115 iRichTextViewer->SetParent( this ); |
|
116 |
|
117 iRichTextViewer->SetActionMenuStatus( ETrue ); |
|
118 iESMRStatic.ConnectL(); |
|
119 iCntMenuHdlr = &iESMRStatic.ContactMenuHandlerL(); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CESMRViewerAttachmentsField::MinimumSize |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 TSize CESMRViewerAttachmentsField::MinimumSize() |
|
127 { |
|
128 // Let's calculate the required rect of the iRichTextViewer. |
|
129 // We will not use directly the iRichTextViewer height, because it might |
|
130 // not exist, or the height of the viewer might still be incorrect |
|
131 TRect richTextViewerRect = RichTextViewerRect(); |
|
132 |
|
133 // We will use as minimum size the parents width |
|
134 // but the calculated iRichTextViewers height |
|
135 return TSize( Parent()->Size().iWidth, richTextViewerRect.Height() ); |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // CESMRViewerAttachmentsField::InitializeL |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 void CESMRViewerAttachmentsField::InitializeL() |
|
143 { |
|
144 FUNC_LOG; |
|
145 // Setting Font for the rich text viewer |
|
146 TAknLayoutText text = NMRLayoutManager::GetLayoutText( |
|
147 Rect(), |
|
148 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
149 |
|
150 iRichTextViewer->SetFontL( text.Font(), iLayout ); |
|
151 |
|
152 // This is called so theme changes will apply when changing theme "on the fly" |
|
153 if ( IsFocused() ) |
|
154 { |
|
155 iRichTextViewer->FocusChanged( EDrawNow ); |
|
156 } |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // CESMRViewerAttachmentsField::InternalizeL() |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 void CESMRViewerAttachmentsField::InternalizeL( MESMRCalEntry& aEntry ) |
|
164 { |
|
165 FUNC_LOG; |
|
166 MESMRMeetingRequestEntry* mrEntry = NULL; |
|
167 if ( aEntry.Type() != MESMRCalEntry::EESMRCalEntryMeetingRequest ) |
|
168 { |
|
169 // This is not meeting request entry so attachment field should be removed from ui |
|
170 iObserver->RemoveControl( FieldId() ); |
|
171 return; |
|
172 } |
|
173 else |
|
174 { |
|
175 mrEntry = static_cast<MESMRMeetingRequestEntry*>( &aEntry ); |
|
176 |
|
177 TESMRInputParams startupParams; |
|
178 if ( mrEntry && mrEntry->StartupParameters(startupParams) ) |
|
179 { |
|
180 // Startup parameters exist --> Let's check if there are attachments |
|
181 |
|
182 if ( startupParams.iAttachmentInfo ) |
|
183 { |
|
184 iMailMessage = startupParams.iMailMessage; |
|
185 |
|
186 UpdateAttachmentInfoL(); |
|
187 |
|
188 iCntMenuHdlr->SetCommandObserver( this ); |
|
189 |
|
190 iAttachmentCount = 0; |
|
191 |
|
192 if ( iAttachmentInfo ) |
|
193 { |
|
194 iAttachmentCount = iAttachmentInfo->AttachmentCount(); |
|
195 } |
|
196 |
|
197 if ( iAttachmentCount > KOneAttachment ) |
|
198 { |
|
199 // There are more than one attachments |
|
200 TInt attachmentsSizeSum(0); |
|
201 for (TInt i(0); i < iAttachmentCount; ++i ) |
|
202 { |
|
203 const CESMRAttachment& attachment( |
|
204 iAttachmentInfo->AttachmentL( i ) ); |
|
205 |
|
206 TInt attachmentSize( attachment.AttachmentSizeInBytes() ); |
|
207 attachmentsSizeSum += attachmentSize; |
|
208 } |
|
209 if ( attachmentsSizeSum >= KOneKiloByte ) |
|
210 { |
|
211 CArrayFixFlat<TInt>* ints = |
|
212 new ( ELeave ) CArrayFixFlat<TInt>( 1 ); |
|
213 |
|
214 CleanupStack::PushL(ints); |
|
215 ints->AppendL( iAttachmentCount ); |
|
216 ints->AppendL( attachmentsSizeSum / KOneKiloByte ); |
|
217 |
|
218 iAttachmentText = StringLoader::LoadL( |
|
219 R_QTN_FSE_VIEWER_HEADER_ATTACHMENTS_TOTAL, |
|
220 *ints ); |
|
221 |
|
222 CleanupStack::PopAndDestroy(ints); |
|
223 } |
|
224 else |
|
225 { |
|
226 iAttachmentText = StringLoader::LoadL( |
|
227 R_QTN_FSE_VIEWER_HEADER_ATTACHMENTS_LESS_THAN_KB, |
|
228 iAttachmentCount); |
|
229 } |
|
230 } |
|
231 else if ( iAttachmentCount > 0 ) |
|
232 { |
|
233 // There is one attachment |
|
234 const CESMRAttachment& attachment( |
|
235 iAttachmentInfo->AttachmentL( 0 ) ); |
|
236 TPtrC attachmentName( attachment.AttachmentName() ); |
|
237 |
|
238 TInt attachmentSize( attachment.AttachmentSizeInBytes() ); |
|
239 |
|
240 if ( attachmentSize >= KOneKiloByte ) |
|
241 { |
|
242 // "%0U %1N kB" |
|
243 |
|
244 CDesCArrayFlat* attachmentStrings = |
|
245 new(ELeave)CDesCArrayFlat( 1 ); |
|
246 CleanupStack::PushL( attachmentStrings ); |
|
247 //First string |
|
248 attachmentStrings->AppendL( attachmentName ); |
|
249 |
|
250 CArrayFixFlat<TInt>* integers = |
|
251 new (ELeave) CArrayFixFlat<TInt>(1); |
|
252 CleanupStack::PushL( integers ); |
|
253 integers->AppendL( attachmentSize / KOneKiloByte ); |
|
254 |
|
255 iAttachmentText = StringLoader::LoadL( |
|
256 R_QTN_FSE_VIEWER_HEADER_ATTACHMENT, |
|
257 *attachmentStrings, |
|
258 *integers ); |
|
259 |
|
260 // Pop and delete strings array |
|
261 CleanupStack::PopAndDestroy( integers ); |
|
262 CleanupStack::PopAndDestroy( attachmentStrings ); |
|
263 } |
|
264 else |
|
265 { |
|
266 iAttachmentText = StringLoader::LoadL( |
|
267 R_QTN_FSE_VIEWER_HEADER_ATTACHMENT_LESS_THAN_KB, |
|
268 attachmentName); |
|
269 } |
|
270 } |
|
271 |
|
272 if ( iAttachmentText ) |
|
273 { |
|
274 iRichTextViewer->SetTextL( iAttachmentText, EFalse ); |
|
275 // After setting the text, the viewer line count is known |
|
276 iLineCount = iRichTextViewer->LineCount(); |
|
277 |
|
278 CESMRRichTextLink* link = CESMRRichTextLink::NewL ( |
|
279 0, iAttachmentText->Length ( ), |
|
280 iAttachmentText->Des(), |
|
281 CESMRRichTextLink::ETypeAttachment, |
|
282 CESMRRichTextLink::ETriggerKeyRight ); |
|
283 |
|
284 CleanupStack::PushL( link ); |
|
285 iRichTextViewer->AddLinkL( link ); |
|
286 CleanupStack::Pop( link ); |
|
287 } |
|
288 } |
|
289 } |
|
290 } |
|
291 |
|
292 if ( KNoAttachments == iAttachmentCount ) |
|
293 { |
|
294 iObserver->RemoveControl( FieldId() ); |
|
295 } |
|
296 |
|
297 iDisableRedraw = ETrue; |
|
298 } |
|
299 |
|
300 // ----------------------------------------------------------------------------- |
|
301 // CESMRViewerAttachmentsField::HandleRichTextLinkSelection |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 TBool CESMRViewerAttachmentsField::HandleRichTextLinkSelection( |
|
305 const CESMRRichTextLink* /*aLink*/ ) |
|
306 { |
|
307 FUNC_LOG; |
|
308 |
|
309 // <cmail> |
|
310 TRAP_IGNORE( iCntMenuHdlr->ShowActionMenuL() ); |
|
311 // </cmail> |
|
312 |
|
313 return ETrue; |
|
314 } |
|
315 |
|
316 // --------------------------------------------------------------------------- |
|
317 // CESMRViewerAttachmentsField::OfferKeyEventL() |
|
318 // --------------------------------------------------------------------------- |
|
319 // |
|
320 TKeyResponse CESMRViewerAttachmentsField::OfferKeyEventL( |
|
321 const TKeyEvent& aEvent, |
|
322 TEventCode aType ) |
|
323 { |
|
324 FUNC_LOG; |
|
325 TKeyResponse response( EKeyWasNotConsumed ); |
|
326 |
|
327 if ( ( aType == EEventKey || aType == EEventKeyUp ) && |
|
328 aEvent.iScanCode == EStdKeyDevice3 ) |
|
329 { |
|
330 // Selection key was pressed --> Trigger open attachment view command |
|
331 NotifyEventL( EESMRCmdMskOpenEmailAttachment ); |
|
332 |
|
333 response = EKeyWasConsumed; |
|
334 } |
|
335 else |
|
336 { |
|
337 response = iRichTextViewer->OfferKeyEventL ( aEvent, aType ); |
|
338 } |
|
339 |
|
340 return response; |
|
341 } |
|
342 |
|
343 // --------------------------------------------------------------------------- |
|
344 // CESMRViewerAttachmentsField::HandleEdwinSizeEventL() |
|
345 // --------------------------------------------------------------------------- |
|
346 // |
|
347 TBool CESMRViewerAttachmentsField::HandleEdwinSizeEventL( |
|
348 CEikEdwin* aEdwin, |
|
349 TEdwinSizeEvent /*aType*/, |
|
350 TSize aSize ) |
|
351 { |
|
352 FUNC_LOG; |
|
353 TBool reDraw( EFalse ); |
|
354 |
|
355 // Let's save the required size for the iRichTextViewer |
|
356 iSize = aSize; |
|
357 |
|
358 if ( iObserver && aEdwin == iRichTextViewer ) |
|
359 { |
|
360 iObserver->ControlSizeChanged( this ); |
|
361 reDraw = ETrue; |
|
362 } |
|
363 return reDraw; |
|
364 } |
|
365 |
|
366 // --------------------------------------------------------------------------- |
|
367 // CESMRViewerAttachmentsField::ListObserverSet |
|
368 // --------------------------------------------------------------------------- |
|
369 // |
|
370 void CESMRViewerAttachmentsField::ListObserverSet() |
|
371 { |
|
372 FUNC_LOG; |
|
373 iRichTextViewer->SetListObserver( iObserver ); |
|
374 } |
|
375 |
|
376 // --------------------------------------------------------------------------- |
|
377 // CESMRViewerAttachmentsField::SetOutlineFocusL |
|
378 // --------------------------------------------------------------------------- |
|
379 // |
|
380 void CESMRViewerAttachmentsField::SetOutlineFocusL( TBool aFocus ) |
|
381 { |
|
382 FUNC_LOG; |
|
383 CESMRField::SetOutlineFocusL( aFocus ); |
|
384 |
|
385 if ( iRichTextViewer ) |
|
386 { |
|
387 iRichTextViewer->SetFocus( aFocus ); |
|
388 } |
|
389 else |
|
390 { |
|
391 //need to tell action menu that focus has changed |
|
392 iRichTextViewer->ResetActionMenuL(); |
|
393 } |
|
394 if ( aFocus && aFocus != iFocused ) |
|
395 { |
|
396 // <cmail> |
|
397 UpdateAttachmentInfoL(); |
|
398 |
|
399 if( iAttachmentInfo->AttachmentCount() > KOneAttachment ) |
|
400 { |
|
401 ChangeMiddleSoftKeyL( EESMRCmdOpenAttachmentView, |
|
402 R_QTN_MSK_VIEWLIST ); |
|
403 } |
|
404 else |
|
405 { |
|
406 // There is one attachment |
|
407 const CESMRAttachment& attachment( |
|
408 iAttachmentInfo->AttachmentL( 0 ) ); |
|
409 |
|
410 if( attachment.AttachmenState() == CESMRAttachment::EAttachmentStateDownloaded ) |
|
411 { |
|
412 ChangeMiddleSoftKeyL( EESMRCmdOpenAttachment, |
|
413 R_QTN_MSK_OPEN ); |
|
414 } |
|
415 else |
|
416 { |
|
417 ChangeMiddleSoftKeyL( EESMRCmdDownloadAttachment, |
|
418 R_QTN_MSK_DOWNLOAD ); |
|
419 } |
|
420 } |
|
421 // </cmail> |
|
422 } |
|
423 iFocused = aFocus; |
|
424 } |
|
425 |
|
426 // <cmail> |
|
427 // --------------------------------------------------------------------------- |
|
428 // CESMRViewerAttachmentsField::MessagePartPointerArrayCleanup |
|
429 // --------------------------------------------------------------------------- |
|
430 // |
|
431 void CESMRViewerAttachmentsField::MessagePartPointerArrayCleanup( TAny* aArray ) |
|
432 { |
|
433 FUNC_LOG; |
|
434 RPointerArray<CFSMailMessagePart>* messagePartArray = |
|
435 static_cast<RPointerArray<CFSMailMessagePart>*>( aArray ); |
|
436 |
|
437 messagePartArray->ResetAndDestroy(); |
|
438 messagePartArray->Close(); |
|
439 } |
|
440 |
|
441 // --------------------------------------------------------------------------- |
|
442 // CESMRViewerAttachmentsField::UpdateAttachmentInfoL |
|
443 // --------------------------------------------------------------------------- |
|
444 // |
|
445 void CESMRViewerAttachmentsField::UpdateAttachmentInfoL() |
|
446 { |
|
447 if ( iMailMessage->IsFlagSet( EFSMsgFlag_Attachments ) ) |
|
448 { |
|
449 RPointerArray<CFSMailMessagePart> attachmentParts; |
|
450 CleanupStack::PushL( |
|
451 TCleanupItem( |
|
452 MessagePartPointerArrayCleanup, |
|
453 &attachmentParts) ); |
|
454 |
|
455 iMailMessage->AttachmentListL( attachmentParts ); |
|
456 |
|
457 // find calendar part from the list |
|
458 CFSMailMessagePart* calendarPart = |
|
459 iMailMessage->FindBodyPartL( KFSMailContentTypeTextCalendar ); |
|
460 CleanupStack::PushL( calendarPart ); |
|
461 |
|
462 if ( calendarPart ) |
|
463 { |
|
464 // remove calendar body part from attachment list |
|
465 for ( TInt ii = attachmentParts.Count() - 1; ii >= 0; --ii ) |
|
466 { |
|
467 if ( attachmentParts[ii]->GetPartId() == calendarPart->GetPartId() ) |
|
468 { |
|
469 delete attachmentParts[ii]; |
|
470 attachmentParts.Remove(ii); |
|
471 break; |
|
472 } |
|
473 } |
|
474 } |
|
475 CleanupStack::PopAndDestroy( calendarPart ); |
|
476 |
|
477 iAttachmentCount = attachmentParts.Count(); |
|
478 if ( iAttachmentCount > 0 ) |
|
479 { |
|
480 delete iAttachmentInfo; |
|
481 iAttachmentInfo = NULL; |
|
482 |
|
483 CESMRAttachmentInfo* attachmentInfo = CESMRAttachmentInfo::NewL(); |
|
484 CleanupStack::PushL( attachmentInfo ); |
|
485 |
|
486 for( TInt i(0); i < iAttachmentCount; ++i ) |
|
487 { |
|
488 CESMRAttachment::TESMRAttachmentState state( |
|
489 CESMRAttachment::EAttachmentStateDownloaded ); |
|
490 |
|
491 if ( EFSFull != attachmentParts[i]->FetchLoadState() ) |
|
492 { |
|
493 state = CESMRAttachment::EAttachmentStateNotDownloaded; |
|
494 } |
|
495 |
|
496 TInt contentSize( attachmentParts[i]->ContentSize() ); |
|
497 TPtrC attachmentName( attachmentParts[i]->AttachmentNameL() ); |
|
498 if ( contentSize > 0 && attachmentName.Length() ) |
|
499 { |
|
500 attachmentInfo->AddAttachmentInfoL( |
|
501 attachmentName, |
|
502 contentSize, |
|
503 state ); |
|
504 } |
|
505 } |
|
506 |
|
507 if ( attachmentInfo->AttachmentCount() ) |
|
508 { |
|
509 iAttachmentInfo = attachmentInfo; |
|
510 CleanupStack::Pop( attachmentInfo ); |
|
511 } |
|
512 else |
|
513 { |
|
514 CleanupStack::PopAndDestroy( attachmentInfo ); |
|
515 } |
|
516 |
|
517 attachmentInfo = NULL; |
|
518 } |
|
519 CleanupStack::PopAndDestroy(); // attachmentparts |
|
520 |
|
521 // relay attachment info to contact menu so we can display |
|
522 // options based on attachment state |
|
523 if ( iAttachmentInfo ) |
|
524 { |
|
525 iCntMenuHdlr->SetAttachmentInfoL( iAttachmentInfo ); |
|
526 } |
|
527 } |
|
528 } |
|
529 |
|
530 // --------------------------------------------------------------------------- |
|
531 // CESMRViewerAttachmentsField::ExecuteGenericCommandL |
|
532 // --------------------------------------------------------------------------- |
|
533 // |
|
534 void CESMRViewerAttachmentsField::ExecuteGenericCommandL( TInt aCommand ) |
|
535 { |
|
536 FUNC_LOG; |
|
537 |
|
538 switch ( aCommand ) |
|
539 { |
|
540 case EESMRCmdOpenAttachment:// Fall through |
|
541 case EESMRCmdOpenAttachmentView:// Fall through |
|
542 case EESMRCmdDownloadAttachment: // Fall through |
|
543 { |
|
544 NotifyEventL( aCommand ); |
|
545 |
|
546 break; |
|
547 } |
|
548 case EESMRCmdClipboardCopy: |
|
549 { |
|
550 iRichTextViewer->CopyCurrentLinkValueToClipBoardL(); |
|
551 break; |
|
552 } |
|
553 default: |
|
554 { |
|
555 break; |
|
556 } |
|
557 } |
|
558 } |
|
559 |
|
560 // ----------------------------------------------------------------------------- |
|
561 // CESMRRichTextViewer::ProcessCommandL |
|
562 // ----------------------------------------------------------------------------- |
|
563 // |
|
564 void CESMRViewerAttachmentsField::ProcessCommandL( TInt aCommandId ) |
|
565 { |
|
566 FUNC_LOG; |
|
567 |
|
568 NotifyEventL( aCommandId ); |
|
569 } |
|
570 |
|
571 |
|
572 // --------------------------------------------------------------------------- |
|
573 // CESMRViewerAttachmentsField::CountComponentControls |
|
574 // --------------------------------------------------------------------------- |
|
575 // |
|
576 TInt CESMRViewerAttachmentsField::CountComponentControls() const |
|
577 { |
|
578 TInt count( 0 ); |
|
579 if ( iFieldIcon ) |
|
580 { |
|
581 ++count; |
|
582 } |
|
583 |
|
584 if ( iRichTextViewer ) |
|
585 { |
|
586 ++count; |
|
587 } |
|
588 return count; |
|
589 } |
|
590 |
|
591 // --------------------------------------------------------------------------- |
|
592 // CESMRViewerAttachmentsField::ComponentControl |
|
593 // --------------------------------------------------------------------------- |
|
594 // |
|
595 CCoeControl* CESMRViewerAttachmentsField::ComponentControl( |
|
596 TInt aIndex ) const |
|
597 { |
|
598 switch ( aIndex ) |
|
599 { |
|
600 case 0: |
|
601 return iFieldIcon; |
|
602 case 1: |
|
603 return iRichTextViewer; |
|
604 default: |
|
605 return NULL; |
|
606 } |
|
607 } |
|
608 |
|
609 // --------------------------------------------------------------------------- |
|
610 // CESMRViewerAttachmentsField::SizeChanged |
|
611 // --------------------------------------------------------------------------- |
|
612 // |
|
613 void CESMRViewerAttachmentsField::SizeChanged( ) |
|
614 { |
|
615 TRect rect = Rect(); |
|
616 |
|
617 // LAYOUTING FIELD ICON |
|
618 if( iFieldIcon ) |
|
619 { |
|
620 TAknWindowComponentLayout iconLayout = |
|
621 NMRLayoutManager::GetWindowComponentLayout( |
|
622 NMRLayoutManager::EMRLayoutTextEditorIcon ); |
|
623 AknLayoutUtils::LayoutImage( iFieldIcon, rect, iconLayout ); |
|
624 } |
|
625 |
|
626 // LAYOUTING FIELD BACKGROUND |
|
627 TAknLayoutRect bgLayoutRect = |
|
628 NMRLayoutManager::GetLayoutRect( |
|
629 rect, NMRLayoutManager::EMRLayoutTextEditorBg ); |
|
630 TRect bgRect( bgLayoutRect.Rect() ); |
|
631 // Move focus rect so that it's relative to field's position |
|
632 bgRect.Move( -Position() ); |
|
633 SetFocusRect( bgRect ); |
|
634 |
|
635 |
|
636 // LAYOUTING FIELD TEXT VIEWER |
|
637 if( iRichTextViewer ) |
|
638 { |
|
639 iRichTextViewer->SetRect( RichTextViewerRect() ); |
|
640 } |
|
641 } |
|
642 |
|
643 // --------------------------------------------------------------------------- |
|
644 // CESMRViewerAttachmentsField::SetContainerWindowL |
|
645 // --------------------------------------------------------------------------- |
|
646 // |
|
647 void CESMRViewerAttachmentsField::SetContainerWindowL( |
|
648 const CCoeControl& aContainer ) |
|
649 { |
|
650 CCoeControl::SetContainerWindowL( aContainer ); |
|
651 iRichTextViewer->SetContainerWindowL( aContainer ); |
|
652 } |
|
653 |
|
654 // --------------------------------------------------------------------------- |
|
655 // CESMRViewerAttachmentsField::RichTextViewerRect |
|
656 // --------------------------------------------------------------------------- |
|
657 // |
|
658 TRect CESMRViewerAttachmentsField::RichTextViewerRect() |
|
659 { |
|
660 TRect rect = Rect(); |
|
661 |
|
662 TAknTextComponentLayout edwinLayout = NMRLayoutManager::GetTextComponentLayout( |
|
663 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
664 |
|
665 // Text layout rect for one line viewer |
|
666 TAknLayoutText textLayout; |
|
667 textLayout.LayoutText( rect, edwinLayout ); |
|
668 TRect textLayoutRect = textLayout.TextRect(); |
|
669 |
|
670 TRect viewerRect = textLayoutRect; |
|
671 |
|
672 // If iRichTextViewer has lines and iSize has been set, |
|
673 // we will use iSize.iHeight as the viewers height |
|
674 if( iLineCount > 0 && iSize.iHeight > 0 ) |
|
675 { |
|
676 viewerRect.SetHeight( iSize.iHeight ); |
|
677 } |
|
678 // Otherwise we will use one row height as the height of the |
|
679 // iRichTextViewer |
|
680 else |
|
681 { |
|
682 TAknLayoutRect rowLayoutRect = |
|
683 NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ); |
|
684 viewerRect.SetHeight( rowLayoutRect.Rect().Height() ); |
|
685 } |
|
686 |
|
687 return viewerRect; |
|
688 } |
|
689 |
|
690 //EOF |