|
1 /* |
|
2 * Copyright (c) 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: MR attahcment field implementation |
|
15 * |
|
16 */ |
|
17 #include "cmrattachmentsfield.h" |
|
18 |
|
19 #include "mesmrlistobserver.h" |
|
20 #include "mesmrmeetingrequestentry.h" |
|
21 #include "cmrlabel.h" |
|
22 #include "nmrlayoutmanager.h" |
|
23 #include "nmrbitmapmanager.h" |
|
24 #include "cmrimage.h" |
|
25 #include "cesmrrichtextviewer.h" |
|
26 #include "cesmreditor.h" |
|
27 #include "cesmrrichtextlink.h" |
|
28 #include "cmrattachmentcommandhandler.h" |
|
29 |
|
30 #include <aknsbasicbackgroundcontrolcontext.h> |
|
31 #include <calentry.h> |
|
32 #include <calattachment.h> |
|
33 #include <stringloader.h> |
|
34 #include <esmrgui.rsg> |
|
35 #include <gulicon.h> |
|
36 #include <ct/rcpointerarray.h> |
|
37 #include <aknbiditextutils.h> |
|
38 |
|
39 // DEBUG |
|
40 #include "emailtrace.h" |
|
41 |
|
42 |
|
43 // unnamed namespace for local definitions |
|
44 namespace { // codescanner::namespace |
|
45 //CONSTANTS |
|
46 |
|
47 // TODO: Read default text from resource |
|
48 _LIT( KAddAttachment, "Add attachment" ); |
|
49 _LIT( KNewLine, "\f" ); |
|
50 |
|
51 const TInt KOneKiloByte( 1024 ); |
|
52 const TInt KOneMegaByte( 1048576 ); // (1024^2 or 2^20): |
|
53 const TInt KMargin = 5; |
|
54 |
|
55 /** |
|
56 * Checks that command is valid attachment viewer command. |
|
57 * @param aCommmand Command ID |
|
58 */ |
|
59 TBool IsValidAttachmentEditorCommand( TInt aCommand ) |
|
60 { |
|
61 TBool ret( EFalse ); |
|
62 |
|
63 switch( aCommand ) |
|
64 { |
|
65 case EESMREditorOpenAttachment: |
|
66 case EESMREditorRemoveAttachment: |
|
67 case EESMREditorRemoveAllAttachments: |
|
68 case EESMREditorAddAttachment: |
|
69 ret = ETrue; |
|
70 break; |
|
71 |
|
72 default: |
|
73 ret = EFalse; |
|
74 break; |
|
75 } |
|
76 |
|
77 return ret; |
|
78 } |
|
79 |
|
80 }//namespace |
|
81 |
|
82 // ======== MEMBER FUNCTIONS ======== |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CMRAttachmentsField::CMRAttachmentsField |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 CMRAttachmentsField::CMRAttachmentsField() |
|
89 { |
|
90 FUNC_LOG; |
|
91 SetFocusType( EESMRHighlightFocus ); |
|
92 SetFieldId( EESMRFieldAttachments ); |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CMRAttachmentsField::~CMRAttachmentsField |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 CMRAttachmentsField::~CMRAttachmentsField( ) |
|
100 { |
|
101 FUNC_LOG; |
|
102 delete iBgCtrlContext; |
|
103 delete iFieldIcon; |
|
104 delete iTitle; |
|
105 delete iAttCommandHandler; |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // CMRAttachmentsField::NewL |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 CMRAttachmentsField* CMRAttachmentsField::NewL() |
|
113 { |
|
114 FUNC_LOG; |
|
115 CMRAttachmentsField* self = new( ELeave )CMRAttachmentsField(); |
|
116 CleanupStack::PushL ( self ); |
|
117 self->ConstructL(); |
|
118 CleanupStack::Pop ( self ); |
|
119 return self; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CMRAttachmentsField::ConstructL |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CMRAttachmentsField::ConstructL() |
|
127 { |
|
128 FUNC_LOG; |
|
129 |
|
130 SetComponentsToInheritVisibility( ETrue ); |
|
131 |
|
132 iFieldIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapAttachment ); |
|
133 iFieldIcon->SetParent( this ); |
|
134 |
|
135 iTitle = CMRLabel::NewL(); |
|
136 iTitle->SetParent( this ); |
|
137 |
|
138 iRichTextViewer = CESMRRichTextViewer::NewL( this ); |
|
139 CESMRField::ConstructL( iRichTextViewer ); // ownership transferred |
|
140 iRichTextViewer->SetEdwinSizeObserver ( this ); |
|
141 iRichTextViewer->SetLinkObserver (this ); |
|
142 iRichTextViewer->SetParent( this ); |
|
143 |
|
144 // TODO: read from resource |
|
145 iTitle->SetTextL( KAddAttachment ); |
|
146 |
|
147 // Draw bg instead of using skin bg |
|
148 TRect tempRect( 0, 0, 0, 0 ); |
|
149 NMRBitmapManager::TMRBitmapStruct bitmapStruct; |
|
150 bitmapStruct = NMRBitmapManager::GetBitmapStruct( |
|
151 NMRBitmapManager::EMRBitmapInputCenter ); |
|
152 |
|
153 iBgCtrlContext = CAknsBasicBackgroundControlContext::NewL( |
|
154 bitmapStruct.iItemId, |
|
155 tempRect, |
|
156 EFalse ); |
|
157 |
|
158 iRichTextViewer->SetSkinBackgroundControlContextL( iBgCtrlContext ); |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // CMRAttachmentsField::MinimumSize |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 TSize CMRAttachmentsField::MinimumSize() |
|
166 { |
|
167 TRect parentRect( Parent()->Rect() ); |
|
168 |
|
169 TRect richTextRect = |
|
170 NMRLayoutManager::GetFieldLayoutRect( parentRect, 1 ).Rect(); |
|
171 |
|
172 TRect textRect( NMRLayoutManager::GetLayoutText( |
|
173 richTextRect, |
|
174 NMRLayoutManager::EMRTextLayoutTextEditor ).TextRect() ); |
|
175 |
|
176 // Adjust field size so that there's room for expandable editor. |
|
177 richTextRect.Resize( 0, iRichTextSize.iHeight - textRect.Height() ); |
|
178 |
|
179 // Add title area to the required size |
|
180 TSize titleSize( CESMRField::MinimumSize() ); |
|
181 |
|
182 TSize completeFieldSize( titleSize ); |
|
183 if( iAttachmentCount ) |
|
184 { |
|
185 completeFieldSize.iHeight += richTextRect.Height(); |
|
186 } |
|
187 |
|
188 return completeFieldSize; |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // CMRAttachmentsField::InitializeL |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 void CMRAttachmentsField::InitializeL() |
|
196 { |
|
197 FUNC_LOG; |
|
198 TAknLayoutText layoutText = |
|
199 NMRLayoutManager::GetLayoutText( Rect(), |
|
200 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
201 iRichTextViewer->SetFontL( layoutText.Font() ); |
|
202 if( iAttachmentCount > 1 ) |
|
203 { |
|
204 iRichTextViewer->SetLineSpacingL( LineSpacing() ); |
|
205 } |
|
206 iRichTextViewer->ApplyLayoutChangesL(); |
|
207 |
|
208 //wake up current contact menu selection by calling this |
|
209 iRichTextViewer->FocusChanged( ENoDrawNow ); |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CMRAttachmentsField::InternalizeL |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 void CMRAttachmentsField::InternalizeL( MESMRCalEntry& aEntry ) |
|
217 { |
|
218 FUNC_LOG; |
|
219 iEntry = &aEntry; |
|
220 |
|
221 if ( aEntry.SupportsCapabilityL( MESMRCalEntry::EMRCapabilityAttachments ) ) |
|
222 { |
|
223 UpdateAttachmentsListL(); |
|
224 |
|
225 //wake up current contact menu selection by calling this |
|
226 iRichTextViewer->FocusChanged( ENoDrawNow ); |
|
227 |
|
228 iDisableRedraw = ETrue; |
|
229 } |
|
230 else |
|
231 { |
|
232 // Field does not support attachments --> Remove field from UI. |
|
233 iObserver->HideControl( EESMRFieldAttachments ); |
|
234 } |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // CMRAttachmentsField::ExternalizeL |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 void CMRAttachmentsField::ExternalizeL( MESMRCalEntry& /*aEntry*/ ) |
|
242 { |
|
243 FUNC_LOG; |
|
244 // No implementation |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // CMRAttachmentsField::CountComponentControls |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 TInt CMRAttachmentsField::CountComponentControls( ) const |
|
252 { |
|
253 FUNC_LOG; |
|
254 TInt count( 0 ); |
|
255 if ( iFieldIcon ) |
|
256 { |
|
257 ++count; |
|
258 } |
|
259 |
|
260 if ( iRichTextViewer ) |
|
261 { |
|
262 ++count; |
|
263 } |
|
264 if ( iTitle ) |
|
265 { |
|
266 ++count; |
|
267 } |
|
268 |
|
269 return count; |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // CMRAttachmentsField::ComponentControl |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 CCoeControl* CMRAttachmentsField::ComponentControl( TInt aInd ) const |
|
277 { |
|
278 FUNC_LOG; |
|
279 switch ( aInd ) |
|
280 { |
|
281 case 0: |
|
282 return iRichTextViewer; |
|
283 case 1: |
|
284 return iFieldIcon; |
|
285 case 2: |
|
286 return iTitle; |
|
287 default: |
|
288 return NULL; |
|
289 } |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------------------------- |
|
293 // CMRAttachmentsField::SizeChanged |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 void CMRAttachmentsField::SizeChanged( ) |
|
297 { |
|
298 FUNC_LOG; |
|
299 TRect rect( Rect() ); |
|
300 |
|
301 TAknLayoutRect firstRowLayoutRect( |
|
302 NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ) ); |
|
303 TRect firstRowRect( firstRowLayoutRect.Rect() ); |
|
304 |
|
305 TRect secondRowRect( firstRowRect ); |
|
306 secondRowRect.Move( 0, firstRowRect.Height() ); |
|
307 |
|
308 // Layout field button |
|
309 if( iFieldIcon ) |
|
310 { |
|
311 TAknWindowComponentLayout iconLayout( |
|
312 NMRLayoutManager::GetWindowComponentLayout( |
|
313 NMRLayoutManager::EMRLayoutTextEditorIcon ) ); |
|
314 AknLayoutUtils::LayoutControl( |
|
315 iFieldIcon, firstRowRect, iconLayout ); |
|
316 } |
|
317 |
|
318 // Layout field title |
|
319 if( iTitle ) |
|
320 { |
|
321 TAknLayoutText labelLayout( |
|
322 NMRLayoutManager::GetLayoutText( |
|
323 firstRowRect, |
|
324 NMRLayoutManager::EMRTextLayoutTextEditor ) ); |
|
325 |
|
326 iTitle->SetRect( labelLayout.TextRect() ); |
|
327 |
|
328 // Setting font also for the label. Failures are ignored. |
|
329 TRAP_IGNORE( iTitle->SetFont( labelLayout.Font() ) ); |
|
330 } |
|
331 |
|
332 TRect edwinRect( 0, 0, 0, 0 ); |
|
333 |
|
334 // Layout field editor |
|
335 if( iRichTextViewer ) |
|
336 { |
|
337 TAknLayoutText layoutText = NMRLayoutManager::GetLayoutText( |
|
338 secondRowRect, |
|
339 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
340 |
|
341 edwinRect = layoutText.TextRect(); |
|
342 |
|
343 // Resize height according to actual height required by edwin. |
|
344 edwinRect.Resize( 0, iRichTextSize.iHeight - edwinRect.Height() ); |
|
345 |
|
346 iRichTextViewer->SetRect( edwinRect ); |
|
347 |
|
348 // Try setting font. Failures are ignored. |
|
349 TRAP_IGNORE( |
|
350 iRichTextViewer->SetFontL( layoutText.Font() ); |
|
351 if( iAttachmentCount > 1 ) |
|
352 { |
|
353 iRichTextViewer->SetLineSpacingL( LineSpacing() ); |
|
354 } |
|
355 iRichTextViewer->ApplyLayoutChangesL(); |
|
356 ); |
|
357 } |
|
358 |
|
359 // Layouting focus |
|
360 TRect bgRect( 0, 0, 0, 0 ); |
|
361 // No attachments -> Focus to the title |
|
362 if( iAttachmentCount == 0 ) |
|
363 { |
|
364 TAknLayoutRect bgLayoutRect = |
|
365 NMRLayoutManager::GetLayoutRect( |
|
366 firstRowRect, NMRLayoutManager::EMRLayoutTextEditorBg ); |
|
367 bgRect = bgLayoutRect.Rect(); |
|
368 } |
|
369 // One attachment -> Focus to the attachment according to layout data |
|
370 if( iAttachmentCount == 1 ) |
|
371 { |
|
372 TAknLayoutRect bgLayoutRect = |
|
373 NMRLayoutManager::GetLayoutRect( |
|
374 secondRowRect, NMRLayoutManager::EMRLayoutTextEditorBg ); |
|
375 bgRect = bgLayoutRect.Rect(); |
|
376 } |
|
377 // More than one attachements -> Focus calculated manually |
|
378 if( iAttachmentCount > 1 ) |
|
379 { |
|
380 bgRect.SetRect( |
|
381 TPoint( edwinRect.iTl.iX, |
|
382 edwinRect.iTl.iY - FocusMargin() ), |
|
383 TPoint( edwinRect.iBr.iX, |
|
384 edwinRect.iBr.iY + FocusMargin() ) ); |
|
385 } |
|
386 |
|
387 // Move focus rect so that it's relative to field's position. |
|
388 bgRect.Move( -Position() ); |
|
389 SetFocusRect( bgRect ); |
|
390 } |
|
391 |
|
392 // --------------------------------------------------------------------------- |
|
393 // CMRAttachmentsField::OfferKeyEventL |
|
394 // --------------------------------------------------------------------------- |
|
395 // |
|
396 TKeyResponse CMRAttachmentsField::OfferKeyEventL( |
|
397 const TKeyEvent& aEvent, |
|
398 TEventCode aType ) |
|
399 { |
|
400 FUNC_LOG; |
|
401 TKeyResponse response( EKeyWasNotConsumed ); |
|
402 |
|
403 if( iAttachmentCount == 0 ) |
|
404 { |
|
405 response = iTitle->OfferKeyEventL( aEvent, aType ); |
|
406 } |
|
407 |
|
408 if( iAttachmentCount > 0 ) |
|
409 { |
|
410 response = iRichTextViewer->OfferKeyEventL( aEvent, aType ); |
|
411 } |
|
412 |
|
413 if ( aType == EEventKey && |
|
414 ( aEvent.iScanCode != EStdKeyUpArrow && |
|
415 aEvent.iScanCode != EStdKeyDownArrow )) |
|
416 { |
|
417 iTitle->DrawDeferred(); // ?? |
|
418 } |
|
419 return response; |
|
420 } |
|
421 |
|
422 // --------------------------------------------------------------------------- |
|
423 // CMRAttachmentsField::SetContainerWindowL() |
|
424 // --------------------------------------------------------------------------- |
|
425 // |
|
426 void CMRAttachmentsField::SetContainerWindowL( const CCoeControl& aControl ) |
|
427 { |
|
428 FUNC_LOG; |
|
429 CESMRField::SetContainerWindowL( aControl ); |
|
430 iRichTextViewer->SetContainerWindowL( aControl ); |
|
431 iRichTextViewer->SetParent( this ); |
|
432 iTitle->SetContainerWindowL( aControl ); |
|
433 iTitle->SetParent( this ); |
|
434 iFieldIcon->SetContainerWindowL( aControl ); |
|
435 iFieldIcon->SetParent( this ); |
|
436 |
|
437 iButtonGroupContainer = CEikButtonGroupContainer::Current(); |
|
438 } |
|
439 |
|
440 // --------------------------------------------------------------------------- |
|
441 // CMRAttachmentsField::HandleEdwinSizeEventL |
|
442 // --------------------------------------------------------------------------- |
|
443 // |
|
444 TBool CMRAttachmentsField::HandleEdwinSizeEventL( CEikEdwin* aEdwin, |
|
445 TEdwinSizeEvent /*aType*/, TSize aSize ) |
|
446 { |
|
447 FUNC_LOG; |
|
448 TBool reDraw( EFalse ); |
|
449 |
|
450 if( iRichTextSize.iHeight != aSize.iHeight && iAttachmentCount > 0 ) |
|
451 { |
|
452 // Let's save the required size of the rich text viewer |
|
453 iRichTextSize = aSize; |
|
454 |
|
455 if ( iObserver && aEdwin == iRichTextViewer ) |
|
456 { |
|
457 iObserver->ControlSizeChanged( this ); |
|
458 reDraw = ETrue; |
|
459 } |
|
460 } |
|
461 |
|
462 return reDraw; |
|
463 } |
|
464 |
|
465 // --------------------------------------------------------------------------- |
|
466 // CMRAttachmentsField::ListObserverSet |
|
467 // --------------------------------------------------------------------------- |
|
468 // |
|
469 void CMRAttachmentsField::ListObserverSet() |
|
470 { |
|
471 FUNC_LOG; |
|
472 iRichTextViewer->SetListObserver( iObserver ); |
|
473 } |
|
474 |
|
475 // --------------------------------------------------------------------------- |
|
476 // CMRAttachmentsField::ExecuteGenericCommandL |
|
477 // --------------------------------------------------------------------------- |
|
478 // |
|
479 TBool CMRAttachmentsField::ExecuteGenericCommandL( TInt aCommand ) |
|
480 { |
|
481 FUNC_LOG; |
|
482 // TODO: Changes from other fields have to be implemented here |
|
483 TBool handled( EFalse ); |
|
484 |
|
485 // From cesmrattachmentfield |
|
486 if( aCommand == EAknCmdOpen ) |
|
487 { |
|
488 handled = ETrue; |
|
489 HandleTactileFeedbackL(); |
|
490 } |
|
491 else if ( aCommand == EESMREditorAddAttachment ) |
|
492 { |
|
493 handled = AddAttachmentL(); |
|
494 if( handled ) |
|
495 { |
|
496 HandleTactileFeedbackL(); |
|
497 } |
|
498 } |
|
499 |
|
500 else if ( IsValidAttachmentEditorCommand(aCommand) && |
|
501 iAttCommandHandler ) |
|
502 { |
|
503 const CESMRRichTextLink* currentLink = iRichTextViewer->GetSelectedLink(); |
|
504 |
|
505 ASSERT( currentLink ); |
|
506 |
|
507 iAttCommandHandler->HandleAttachmentCommandL( |
|
508 aCommand, |
|
509 *currentLink ); |
|
510 |
|
511 HandleTactileFeedbackL(); |
|
512 |
|
513 handled = ETrue; |
|
514 |
|
515 if( aCommand == EESMREditorRemoveAttachment || |
|
516 aCommand == EESMREditorRemoveAllAttachments ) |
|
517 { |
|
518 // Attachment list needs to be updated after removing |
|
519 // attachment(s) |
|
520 UpdateAttachmentsListL(); |
|
521 |
|
522 //wake up current contact menu selection by calling this |
|
523 iRichTextViewer->FocusChanged( ENoDrawNow ); |
|
524 |
|
525 if( iAttachmentCount == 0 ) |
|
526 { |
|
527 // If no attachments are present anymore, let's hide the |
|
528 // whole rich text viewer. |
|
529 iRichTextViewer->MakeVisible( EFalse ); |
|
530 |
|
531 // Because rich text part is removed from the UI, |
|
532 // we need to inform the parent, to re-size the |
|
533 // field container and re-initialize the physics |
|
534 // world size |
|
535 iObserver->ControlSizeChanged( this ); |
|
536 } |
|
537 } |
|
538 } |
|
539 |
|
540 return handled; |
|
541 } |
|
542 |
|
543 // --------------------------------------------------------------------------- |
|
544 // CMRAttachmentsField::SetOutlineFocusL |
|
545 // --------------------------------------------------------------------------- |
|
546 // |
|
547 void CMRAttachmentsField::SetOutlineFocusL( TBool aFocus ) |
|
548 { |
|
549 FUNC_LOG; |
|
550 CESMRField::SetOutlineFocusL( aFocus ); |
|
551 |
|
552 if ( aFocus ) |
|
553 { |
|
554 if ( iAttachmentCount ) |
|
555 { |
|
556 ChangeMiddleSoftKeyL( |
|
557 EAknSoftkeyContextOptions, |
|
558 R_QTN_MSK_OPEN ); |
|
559 } |
|
560 else |
|
561 { |
|
562 ChangeMiddleSoftKeyL( |
|
563 EESMREditorAddAttachment, |
|
564 R_QTN_MSK_ADD ); |
|
565 |
|
566 } |
|
567 } |
|
568 } |
|
569 |
|
570 // ----------------------------------------------------------------------------- |
|
571 // CMRAttachmentsField::HandleRichTextLinkSelection |
|
572 // ----------------------------------------------------------------------------- |
|
573 // |
|
574 TBool CMRAttachmentsField::HandleRichTextLinkSelection( |
|
575 const CESMRRichTextLink* aLink ) |
|
576 { |
|
577 FUNC_LOG; |
|
578 TBool ret( EFalse ); |
|
579 |
|
580 // Open context menu in editor and viewer modes with link selection |
|
581 if ( aLink->Type() == CESMRRichTextLink::ETypeAttachment ) |
|
582 { |
|
583 TRAP_IGNORE( NotifyEventL( EMRLaunchAttachmentContextMenu )); |
|
584 ret = ETrue; |
|
585 } |
|
586 |
|
587 return ret; |
|
588 } |
|
589 |
|
590 // ----------------------------------------------------------------------------- |
|
591 // CMRAttachmentsField::UpdateAttachmentsListL |
|
592 // ----------------------------------------------------------------------------- |
|
593 // |
|
594 void CMRAttachmentsField::UpdateAttachmentsListL() |
|
595 { |
|
596 FUNC_LOG; |
|
597 |
|
598 RBuf buffer; // codescanner::resourcenotoncleanupstack |
|
599 buffer.CleanupClosePushL(); |
|
600 |
|
601 RCPointerArray<CESMRRichTextLink> attachmentLinks; |
|
602 CleanupClosePushL( attachmentLinks ); |
|
603 |
|
604 iAttachmentCount = iEntry->Entry().AttachmentCountL(); |
|
605 |
|
606 TAknLayoutText layoutText = NMRLayoutManager::GetLayoutText( |
|
607 Rect(), |
|
608 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
609 |
|
610 attachmentLinks.ReserveL( iAttachmentCount ); |
|
611 for ( TInt i = 0; i < iAttachmentCount; ++i ) |
|
612 { |
|
613 CCalAttachment* att = iEntry->Entry().AttachmentL( i ); // Ownership not gained |
|
614 |
|
615 // Reducing space required by file size information from |
|
616 // max line width, so that file name can be trimmed to correct |
|
617 // length |
|
618 TInt maxLineWidth = MinimumSize().iWidth; |
|
619 const CFont* font = layoutText.Font(); |
|
620 |
|
621 HBufC* attachmentSize = AttachmentNameAndSizeL( KNullDesC(), *att ); |
|
622 TInt attachmentSizeLength = attachmentSize->Length(); |
|
623 maxLineWidth -= font->TextWidthInPixels( *attachmentSize ); |
|
624 delete attachmentSize; |
|
625 attachmentSize = NULL; |
|
626 |
|
627 // TODO: correct icon zise to correct one. Ask from UI specifier. |
|
628 TSize iconSize( 20, 20); |
|
629 maxLineWidth -= iconSize.iWidth; |
|
630 |
|
631 // Trimming file name to fit to one line |
|
632 TPtrC text = att->Label(); |
|
633 HBufC* clippedTextHBufC = ClipTextLC( text, *font, maxLineWidth ); |
|
634 TPtr clippedText = clippedTextHBufC->Des(); |
|
635 clippedText.Trim(); |
|
636 |
|
637 if ( clippedText.Length() > 0 ) |
|
638 { |
|
639 // Creating rich text link |
|
640 CESMRRichTextLink* link = CESMRRichTextLink::NewL( |
|
641 buffer.Length(), |
|
642 clippedText.Length() + attachmentSizeLength, |
|
643 text, |
|
644 CESMRRichTextLink::ETypeAttachment, |
|
645 CESMRRichTextLink::ETriggerKeyRight ); |
|
646 CleanupStack::PushL( link ); |
|
647 attachmentLinks.AppendL( link ); |
|
648 CleanupStack::Pop( link ); |
|
649 |
|
650 HBufC* buf = AttachmentNameAndSizeL( clippedText, *att ); |
|
651 CleanupStack::PushL( buf ); |
|
652 |
|
653 // Append attachment name and size with line feed to buffer |
|
654 buffer.ReAllocL( buffer.Length() + |
|
655 clippedText.Length() + |
|
656 buf->Length() + |
|
657 KNewLine().Length() ); |
|
658 |
|
659 buffer.Append( buf->Des() ); |
|
660 buffer.Append( KNewLine ); |
|
661 |
|
662 CleanupStack::PopAndDestroy( buf ); |
|
663 } |
|
664 |
|
665 CleanupStack::PopAndDestroy( clippedTextHBufC ); |
|
666 } |
|
667 |
|
668 // Remove unnecessary new line from the end of buffer. |
|
669 if ( buffer.Length() >= KNewLine().Length() ) |
|
670 { |
|
671 buffer.SetLength( buffer.Length() - KNewLine().Length() ); |
|
672 } |
|
673 |
|
674 // Adding all rich text links to the rich text viewer |
|
675 if ( buffer.Length() > 0 ) |
|
676 { |
|
677 iRichTextViewer->SetTextL( &buffer ); |
|
678 iRichTextViewer->SetFontL( layoutText.Font() ); |
|
679 if( iAttachmentCount > 1 ) |
|
680 { |
|
681 iRichTextViewer->SetLineSpacingL( LineSpacing() ); |
|
682 } |
|
683 iRichTextViewer->ApplyLayoutChangesL(); |
|
684 iRichTextViewer->SetMargins( KMargin ); // What's this? |
|
685 iRichTextViewer->HandleTextChangedL(); |
|
686 |
|
687 while ( attachmentLinks.Count() > 0 ) |
|
688 { |
|
689 CESMRRichTextLink* link = attachmentLinks[0]; |
|
690 CleanupStack::PushL( link ); |
|
691 attachmentLinks.Remove( 0 ); |
|
692 iRichTextViewer->AddLinkL( link ); |
|
693 CleanupStack::Pop( link ); |
|
694 } |
|
695 } |
|
696 |
|
697 CleanupStack::PopAndDestroy( &attachmentLinks ); |
|
698 CleanupStack::PopAndDestroy( &buffer ); |
|
699 |
|
700 if ( iAttachmentCount ) |
|
701 { |
|
702 iRichTextViewer->MakeVisible( ETrue ); |
|
703 |
|
704 iObserver->ControlSizeChanged( this ); |
|
705 |
|
706 ChangeMiddleSoftKeyL( |
|
707 EAknSoftkeyContextOptions, |
|
708 R_QTN_MSK_OPEN ); |
|
709 |
|
710 delete iAttCommandHandler; |
|
711 iAttCommandHandler = NULL; |
|
712 |
|
713 iAttCommandHandler = |
|
714 CMRAttachmentCommandHandler::NewL( |
|
715 iEntry->Entry(), |
|
716 *iEventQueue ); |
|
717 } |
|
718 } |
|
719 |
|
720 // ----------------------------------------------------------------------------- |
|
721 // CMRAttachmentsField::ClipTextLC |
|
722 // ----------------------------------------------------------------------------- |
|
723 // |
|
724 HBufC* CMRAttachmentsField::ClipTextLC( |
|
725 const TDesC& aText, const CFont& aFont, TInt aWidth ) |
|
726 { |
|
727 FUNC_LOG; |
|
728 HBufC* text = HBufC::NewLC( aText.Length() + KAknBidiExtraSpacePerLine ); |
|
729 TPtr textPtr = text->Des(); |
|
730 AknBidiTextUtils::ConvertToVisualAndClip( |
|
731 aText, textPtr, aFont, aWidth, aWidth ); |
|
732 return text; |
|
733 } |
|
734 |
|
735 // --------------------------------------------------------------------------- |
|
736 // CMRAttachmentsField::AttachmentOperationCompleted |
|
737 // --------------------------------------------------------------------------- |
|
738 // |
|
739 void CMRAttachmentsField::AttachmentOperationCompleted( |
|
740 MDesC16Array& /*aArray*/ ) |
|
741 { |
|
742 TRAPD( error, UpdateAttachmentsListL() ); |
|
743 if( error != KErrNone ) |
|
744 { |
|
745 // Error occured, could not update the field |
|
746 iCoeEnv->HandleError( error ); |
|
747 } |
|
748 |
|
749 delete iAttachmentUi; |
|
750 iAttachmentUi = NULL; |
|
751 } |
|
752 |
|
753 // --------------------------------------------------------------------------- |
|
754 // CMRAttachmentsField::AttachmentNameAndSizeL |
|
755 // --------------------------------------------------------------------------- |
|
756 // |
|
757 HBufC* CMRAttachmentsField::AttachmentNameAndSizeL( |
|
758 const TDesC& aDes, |
|
759 const CCalAttachment& aAttachment ) |
|
760 { |
|
761 HBufC* stringholder; |
|
762 |
|
763 CDesCArrayFlat* attachmentStrings = |
|
764 new(ELeave)CDesCArrayFlat( 1 ); |
|
765 CleanupStack::PushL( attachmentStrings ); |
|
766 |
|
767 CArrayFixFlat<TInt>* integers = |
|
768 new (ELeave) CArrayFixFlat<TInt>(1); |
|
769 CleanupStack::PushL( integers ); |
|
770 |
|
771 TInt attachmentSize = aAttachment.FileAttachment()->Size(); |
|
772 |
|
773 if ( attachmentSize >= KOneMegaByte ) |
|
774 { |
|
775 attachmentStrings->AppendL( aDes ); |
|
776 |
|
777 integers->AppendL( attachmentSize / KOneMegaByte ); |
|
778 |
|
779 stringholder = StringLoader::LoadLC( |
|
780 R_MEET_REQ_ATTACHMENT_FILE_MEGABYTE, |
|
781 *attachmentStrings, |
|
782 *integers ); |
|
783 } |
|
784 else if (( attachmentSize < KOneKiloByte ) && (attachmentSize != 0)) |
|
785 { |
|
786 attachmentStrings->AppendL( aDes ); |
|
787 |
|
788 stringholder = StringLoader::LoadLC( |
|
789 R_MEET_REQ_ATTACHMENT_FILE_LESS_THAN_KILOBYTE, |
|
790 *attachmentStrings); |
|
791 } |
|
792 else |
|
793 { |
|
794 attachmentStrings->AppendL( aDes ); |
|
795 |
|
796 integers->AppendL( attachmentSize / KOneKiloByte ); |
|
797 |
|
798 stringholder = StringLoader::LoadLC( |
|
799 R_MEET_REQ_ATTACHMENT_FILE_KILOBYTE, |
|
800 *attachmentStrings, |
|
801 *integers ); |
|
802 } |
|
803 |
|
804 CleanupStack::Pop( stringholder ); |
|
805 CleanupStack::PopAndDestroy( integers ); |
|
806 CleanupStack::PopAndDestroy( attachmentStrings ); |
|
807 |
|
808 return stringholder; |
|
809 } |
|
810 |
|
811 // --------------------------------------------------------------------------- |
|
812 // CMRAttachmentsField::AddAttachmentL |
|
813 // --------------------------------------------------------------------------- |
|
814 // |
|
815 TBool CMRAttachmentsField::AddAttachmentL() |
|
816 { |
|
817 TBool ret( EFalse ); |
|
818 |
|
819 if( iEntry ) |
|
820 { |
|
821 if ( !iAttachmentUi ) |
|
822 { |
|
823 iAttachmentUi = CMRAttachmentUi::NewL(); |
|
824 } |
|
825 |
|
826 iAttachmentUi->SetObserver( *this ); |
|
827 TInt error( iAttachmentUi->LaunchFetchUi( *iEntry ) ); |
|
828 ret = ETrue; |
|
829 if( error != KErrNone ) |
|
830 { |
|
831 iCoeEnv->HandleError( error ); |
|
832 ret = EFalse; |
|
833 } |
|
834 } |
|
835 |
|
836 return ret; |
|
837 } |
|
838 |
|
839 // --------------------------------------------------------------------------- |
|
840 // CMRAttachmentsField::HandleSingletapEventL |
|
841 // --------------------------------------------------------------------------- |
|
842 // |
|
843 TBool CMRAttachmentsField::HandleSingletapEventL( const TPoint& aPosition ) |
|
844 { |
|
845 FUNC_LOG; |
|
846 TBool ret( EFalse ); |
|
847 |
|
848 // When there are no attachments, the whole field area |
|
849 // will execute single tap the action |
|
850 if( iAttachmentCount == 0 ) |
|
851 { |
|
852 if( Rect().Contains( aPosition ) ) |
|
853 { |
|
854 ret = AddAttachmentL(); |
|
855 if( ret ) |
|
856 { |
|
857 HandleTactileFeedbackL(); |
|
858 } |
|
859 } |
|
860 } |
|
861 // Otherwise only the title and the fieldIcon will |
|
862 // execute the single tap action |
|
863 else |
|
864 { |
|
865 if( iTitle->Rect().Contains( aPosition ) || |
|
866 iFieldIcon->Rect().Contains( aPosition ) ) |
|
867 { |
|
868 ret = AddAttachmentL(); |
|
869 if( ret ) |
|
870 { |
|
871 HandleTactileFeedbackL(); |
|
872 } |
|
873 } |
|
874 } |
|
875 |
|
876 return ret; |
|
877 } |
|
878 |
|
879 // --------------------------------------------------------------------------- |
|
880 // CMRAttachmentsField::HandleLongtapEventL |
|
881 // --------------------------------------------------------------------------- |
|
882 // |
|
883 void CMRAttachmentsField::HandleLongtapEventL( const TPoint& aPosition ) |
|
884 { |
|
885 // When there are no attachments, the whole field area |
|
886 // will execute long tap the action |
|
887 if( iAttachmentCount == 0 ) |
|
888 { |
|
889 if( Rect().Contains( aPosition ) ) |
|
890 { |
|
891 if( AddAttachmentL() ) |
|
892 { |
|
893 HandleTactileFeedbackL(); |
|
894 } |
|
895 } |
|
896 } |
|
897 else |
|
898 { |
|
899 if ( iRichTextViewer->Rect().Contains( aPosition ) ) |
|
900 { |
|
901 if( iRichTextViewer->LinkSelectedL() ) |
|
902 { |
|
903 HandleTactileFeedbackL(); |
|
904 } |
|
905 } |
|
906 |
|
907 if( iTitle->Rect().Contains( aPosition ) || |
|
908 iFieldIcon->Rect().Contains( aPosition ) ) |
|
909 { |
|
910 if( AddAttachmentL() ) |
|
911 { |
|
912 HandleTactileFeedbackL(); |
|
913 } |
|
914 } |
|
915 } |
|
916 } |
|
917 |
|
918 // --------------------------------------------------------------------------- |
|
919 // CMRAttachmentsField::HandleRawPointerEventL |
|
920 // --------------------------------------------------------------------------- |
|
921 // |
|
922 TBool CMRAttachmentsField::HandleRawPointerEventL( |
|
923 const TPointerEvent& aPointerEvent ) |
|
924 { |
|
925 FUNC_LOG; |
|
926 TBool ret( EFalse ); |
|
927 |
|
928 if( iAttachmentCount > 0 && |
|
929 aPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
930 { |
|
931 if( iRichTextViewer->Rect().Contains( aPointerEvent.iPosition ) ) |
|
932 { |
|
933 iRichTextViewer->HandlePointerEventL( aPointerEvent ); |
|
934 ret = ETrue; |
|
935 } |
|
936 } |
|
937 |
|
938 return ret; |
|
939 } |
|
940 |
|
941 // --------------------------------------------------------------------------- |
|
942 // CMRAttachmentsField::DynInitMenuPaneL |
|
943 // --------------------------------------------------------------------------- |
|
944 // |
|
945 void CMRAttachmentsField::DynInitMenuPaneL( |
|
946 TInt aResourceId, |
|
947 CEikMenuPane* aMenuPane ) |
|
948 { |
|
949 FUNC_LOG; |
|
950 |
|
951 if ( R_MR_EDITOR_ATTACHMENT_MENU == aResourceId ) |
|
952 { |
|
953 if ( !iAttachmentCount ) |
|
954 { |
|
955 aMenuPane->SetItemDimmed( |
|
956 EESMREditorOpenAttachment, |
|
957 ETrue ); |
|
958 |
|
959 aMenuPane->SetItemDimmed( |
|
960 EESMREditorRemoveAttachment, |
|
961 ETrue ); |
|
962 |
|
963 aMenuPane->SetItemDimmed( |
|
964 EESMREditorRemoveAllAttachments, |
|
965 ETrue ); |
|
966 } |
|
967 else if ( iAttachmentCount == 1 ) |
|
968 { |
|
969 aMenuPane->SetItemDimmed( |
|
970 EESMREditorRemoveAllAttachments, |
|
971 ETrue ); |
|
972 |
|
973 } |
|
974 } |
|
975 } |
|
976 |
|
977 // --------------------------------------------------------------------------- |
|
978 // CMRAttachmentsField::LineSpacing |
|
979 // --------------------------------------------------------------------------- |
|
980 // |
|
981 TInt CMRAttachmentsField::LineSpacing() |
|
982 { |
|
983 FUNC_LOG; |
|
984 // Calculates the line spacing based on default one line layout data |
|
985 TInt lineSpacing( 0 ); |
|
986 |
|
987 TRect rect( Rect() ); |
|
988 |
|
989 TAknLayoutRect rowLayoutRect = |
|
990 NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ); |
|
991 TRect rowRect = rowLayoutRect.Rect(); |
|
992 |
|
993 TAknLayoutText labelLayout = |
|
994 NMRLayoutManager::GetLayoutText( |
|
995 rect, NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
996 |
|
997 TRect defaultTextRect = labelLayout.TextRect(); |
|
998 |
|
999 TInt difference = rowRect.Height() - defaultTextRect.Height(); |
|
1000 |
|
1001 lineSpacing = difference * 2; |
|
1002 |
|
1003 return lineSpacing; |
|
1004 } |
|
1005 |
|
1006 // --------------------------------------------------------------------------- |
|
1007 // CMRAttachmentsField::FocusMargin |
|
1008 // --------------------------------------------------------------------------- |
|
1009 // |
|
1010 TInt CMRAttachmentsField::FocusMargin() |
|
1011 { |
|
1012 FUNC_LOG; |
|
1013 // Calculates focus margin based on default one line layout data |
|
1014 TInt focusMagin( 0 ); |
|
1015 |
|
1016 TRect rect( Rect() ); |
|
1017 |
|
1018 TAknLayoutRect rowLayoutRect = |
|
1019 NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ); |
|
1020 TRect rowRect = rowLayoutRect.Rect(); |
|
1021 |
|
1022 TAknLayoutText labelLayout = |
|
1023 NMRLayoutManager::GetLayoutText( |
|
1024 rect, NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
1025 |
|
1026 TRect defaultTextRect = labelLayout.TextRect(); |
|
1027 |
|
1028 TAknLayoutRect bgLayoutRect = |
|
1029 NMRLayoutManager::GetLayoutRect( |
|
1030 rect, NMRLayoutManager::EMRLayoutTextEditorBg ); |
|
1031 TRect defaultBgRect( bgLayoutRect.Rect() ); |
|
1032 |
|
1033 TInt difference = defaultBgRect.Height() - defaultTextRect.Height(); |
|
1034 |
|
1035 focusMagin = TReal( difference / 2 ); |
|
1036 |
|
1037 return focusMagin; |
|
1038 } |
|
1039 |
|
1040 //EOF |