|
1 /* |
|
2 * Copyright (c) 2007 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: message editor |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <StringLoader.h> |
|
21 #include <AknUtils.h> |
|
22 #include <AknsUtils.h> |
|
23 #include <AknsSkinInstance.h> |
|
24 #include <FreestyleEmailUi.rsg> |
|
25 #include <touchfeedback.h> |
|
26 |
|
27 #include "FreestyleEmailUiLayoutData.h" |
|
28 #include "FreestyleEmailUiAppui.h" |
|
29 #include "FreestyleEmailUiTextureManager.h" |
|
30 #include "FreestyleEmailUiLayoutHandler.h" |
|
31 #include "ncsattachmentfield.h" |
|
32 #include "ncsutility.h" |
|
33 #include "ncsheadercontainer.h" |
|
34 #include "FSEmail.pan" |
|
35 |
|
36 |
|
37 CNcsAttachmentField* CNcsAttachmentField::NewL( |
|
38 TInt aLabelTextId, |
|
39 MNcsFieldSizeObserver* aSizeObserver, |
|
40 CNcsHeaderContainer* aParentControl ) |
|
41 { |
|
42 FUNC_LOG; |
|
43 CNcsAttachmentField* self = |
|
44 new ( ELeave ) CNcsAttachmentField( aLabelTextId, aSizeObserver, aParentControl ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CNcsAttachmentField::~CNcsAttachmentField() |
|
52 { |
|
53 FUNC_LOG; |
|
54 iAttachmentLabels.ResetAndDestroy(); |
|
55 |
|
56 delete iAttachmentNames; |
|
57 delete iAttachmentSizes; |
|
58 |
|
59 delete iAttachmentBitmap; |
|
60 delete iAttachmentMask; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CNcsAttachmentField::CNcsAttachmentField() |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CNcsAttachmentField::CNcsAttachmentField( TInt aLabelTextId, |
|
68 MNcsFieldSizeObserver* aSizeObserver, |
|
69 CNcsHeaderContainer* aParentControl ): |
|
70 MNcsControl( aSizeObserver ), |
|
71 iParentControl( aParentControl ), |
|
72 iLabelTextId ( aLabelTextId ), |
|
73 iFocusedLabelIndex( KNoAttachmentLabelFocused ) |
|
74 { |
|
75 FUNC_LOG; |
|
76 } |
|
77 |
|
78 void CNcsAttachmentField::ConstructL() |
|
79 { |
|
80 FUNC_LOG; |
|
81 CreateIconsL(); |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CNcsAttachmentField::LineCount() |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 TInt CNcsAttachmentField::LineCount() const |
|
89 { |
|
90 FUNC_LOG; |
|
91 return 0; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CNcsAttachmentField::ScrollableLines() |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 TInt CNcsAttachmentField::ScrollableLines() const |
|
99 { |
|
100 FUNC_LOG; |
|
101 return 0; |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CNcsAttachmentField::GetNumChars() |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 TInt CNcsAttachmentField::GetNumChars() const |
|
109 { |
|
110 FUNC_LOG; |
|
111 return 0; |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CNcsAttachmentField::CursorLineNumber() |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 TInt CNcsAttachmentField::CursorLineNumber() const |
|
119 { |
|
120 FUNC_LOG; |
|
121 return 0; |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CNcsAttachmentField::CursorPosition() |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 TInt CNcsAttachmentField::CursorPosition() const |
|
129 { |
|
130 FUNC_LOG; |
|
131 return 0; |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CNcsAttachmentField::Reposition() |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CNcsAttachmentField::Reposition(TPoint& aPt, TInt /*aWidth*/ ) |
|
139 { |
|
140 FUNC_LOG; |
|
141 SetPosition( aPt ); |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CNcsAttachmentField::GetLabelText() |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 const TDesC& CNcsAttachmentField::GetLabelText() const |
|
149 { |
|
150 FUNC_LOG; |
|
151 return KNullDesC; |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // CNcsAttachmentField::LayoutLineCount |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 TInt CNcsAttachmentField::LayoutLineCount() const |
|
159 { |
|
160 FUNC_LOG; |
|
161 return ( IsVisible() ? iAttachmentLabelCount : 0 ); |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CNcsAttachmentField::Draw() |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CNcsAttachmentField::Draw( const TRect& /*aRect*/ ) const |
|
169 { |
|
170 FUNC_LOG; |
|
171 CWindowGc& gc = SystemGc(); |
|
172 |
|
173 // Draw text box |
|
174 if ( IsFocused() ) |
|
175 { |
|
176 TBool highlighedFound( EFalse ); |
|
177 for ( TInt i( 0 ); !highlighedFound && i<iAttachmentLabelCount; ++i ) |
|
178 { |
|
179 if ( iAttachmentLabels[i]->IsFocused() ) |
|
180 { |
|
181 highlighedFound = ETrue; |
|
182 // highlight for label when focused |
|
183 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
184 TRgb imageColor; |
|
185 if( KErrNone != AknsUtils::GetCachedColor( |
|
186 skin, imageColor, |
|
187 KAknsIIDFsHighlightColors, |
|
188 EAknsCIFsHighlightColorsCG4 ) && |
|
189 KErrNone != AknsUtils::GetCachedColor( |
|
190 skin, imageColor, |
|
191 KAknsIIDQsnHighlightColors, |
|
192 EAknsCIQsnHighlightColorsCG2 ) ) |
|
193 { |
|
194 imageColor = KRgbBlue; |
|
195 } |
|
196 |
|
197 gc.SetPenStyle( CGraphicsContext::ENullPen ); |
|
198 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
199 gc.SetBrushColor( imageColor ); |
|
200 |
|
201 TRect highlightRect( |
|
202 iAttachmentLabels[i]->TextHitAreaRect() ); |
|
203 highlightRect.Grow( 0, 1 ); |
|
204 gc.DrawRect( highlightRect ); |
|
205 } |
|
206 } |
|
207 } |
|
208 |
|
209 // Draw icons |
|
210 gc.SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
211 gc.BitBltMasked( iAttachmentIconPos, iAttachmentBitmap, |
|
212 iAttachmentBitmap->SizeInPixels(), |
|
213 iAttachmentMask, ETrue ); |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // CNcsAttachmentField::SizeChanged() |
|
218 // ----------------------------------------------------------------------------- |
|
219 // |
|
220 void CNcsAttachmentField::SizeChanged() |
|
221 { |
|
222 FUNC_LOG; |
|
223 LayoutControls(); |
|
224 UpdateFontSize(); |
|
225 UpdateColors(); |
|
226 // The attachment texts needs to be updated when label size changes because it |
|
227 // may now get truncated differently. |
|
228 TRAP_IGNORE( UpdateAttachmentTextsL() ); |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CNcsAttachmentField::PositionChanged() |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CNcsAttachmentField::PositionChanged() |
|
236 { |
|
237 FUNC_LOG; |
|
238 LayoutControls(); |
|
239 UpdateColors(); |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CNcsAttachmentField::MinimumHeight() |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 TInt CNcsAttachmentField::MinimumHeight() const |
|
247 { |
|
248 FUNC_LOG; |
|
249 return 0; |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CNcsAttachmentField::SetMaxLabelLength() |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 void CNcsAttachmentField::SetMaxLabelLength( TInt aMaxLength ) |
|
257 { |
|
258 FUNC_LOG; |
|
259 iMaximumLabelLength = aMaxLength; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CNcsAttachmentField::GetMinLabelLength() |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 TInt CNcsAttachmentField::GetMinLabelLength() const |
|
267 { |
|
268 FUNC_LOG; |
|
269 return 0; |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CNcsAttachmentField::SetContainerWindowL() |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 void CNcsAttachmentField::SetContainerWindowL( const CCoeControl& aContainer ) |
|
277 { |
|
278 FUNC_LOG; |
|
279 CCoeControl::SetContainerWindowL( aContainer ); |
|
280 |
|
281 UpdateComponentArrayL(); |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CNcsAttachmentField::UpdateComponentArrayL() |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 void CNcsAttachmentField::UpdateComponentArrayL() |
|
289 { |
|
290 FUNC_LOG; |
|
291 InitComponentArrayL(); |
|
292 CCoeControlArray& controls = Components(); |
|
293 TInt controlsCount( controls.Count() ); |
|
294 controls.SetControlsOwnedExternally( ETrue ); |
|
295 |
|
296 // Create the new component array items if needed |
|
297 if ( iAttachmentLabelCount > controlsCount ) |
|
298 { |
|
299 // append controls for new attachment labels after the existing ones |
|
300 for ( TInt i( controlsCount ); i<iAttachmentLabelCount; ++i ) |
|
301 { |
|
302 controls.AppendLC( iAttachmentLabels[i] ); |
|
303 CleanupStack::Pop( iAttachmentLabels[i] ); |
|
304 |
|
305 UpdateFontSize( iAttachmentLabels[i] ); |
|
306 |
|
307 // Align according to mirrored layout variation |
|
308 iAttachmentLabels[i]->SetAlignment( AknLayoutUtils::LayoutMirrored() ? |
|
309 EHRightVCenter : EHLeftVCenter ); |
|
310 } |
|
311 } |
|
312 // Remove unnecessary component array items from the end |
|
313 else if ( iAttachmentLabelCount < controlsCount ) |
|
314 { |
|
315 for ( TInt i( controlsCount-1 ); i>=iAttachmentLabelCount ; --i ) |
|
316 { |
|
317 controls.Remove( iAttachmentLabels[i] ); |
|
318 } |
|
319 } |
|
320 } |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // CNcsAttachmentField::SetTextsLD() |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 void CNcsAttachmentField::SetTextsLD( |
|
327 CDesCArray* aAttachmentNames, CDesCArray* aAttachmentSizes ) |
|
328 { |
|
329 FUNC_LOG; |
|
330 delete iAttachmentNames; |
|
331 iAttachmentNames = NULL; |
|
332 iAttachmentNames = aAttachmentNames; |
|
333 delete iAttachmentSizes; |
|
334 iAttachmentSizes = NULL; |
|
335 iAttachmentSizes = aAttachmentSizes; |
|
336 |
|
337 if ( iAttachmentNames ) |
|
338 { |
|
339 __ASSERT_DEBUG( iAttachmentNames && |
|
340 iAttachmentSizes && |
|
341 iAttachmentNames->Count() == iAttachmentSizes->Count(), |
|
342 Panic( ENcsBasicUi ) ); |
|
343 |
|
344 TInt attachmentLabelCountBeforeUpdate( iAttachmentLabelCount ); |
|
345 |
|
346 UpdateAttachmentTextsL(); |
|
347 |
|
348 // set the focused attachment label |
|
349 if ( iAttachmentLabelCount == 0 ) |
|
350 { |
|
351 // No attachments |
|
352 iFocusedLabelIndex = KNoAttachmentLabelFocused; |
|
353 } |
|
354 else if ( iFocusedLabelIndex >= iAttachmentLabelCount || |
|
355 attachmentLabelCountBeforeUpdate < iAttachmentLabelCount ) |
|
356 { |
|
357 // Set the focused index to last, we get here either if the last |
|
358 // attachment label in list was removed or a new one was added. |
|
359 // In either case focused should be the new last attachment label. |
|
360 iFocusedLabelIndex = iAttachmentLabelCount-1; |
|
361 } |
|
362 // In any other case, don't re-set the focused label index |
|
363 } |
|
364 else // no attachments |
|
365 { |
|
366 iAttachmentLabelCount = 0; |
|
367 iFocusedLabelIndex = KNoAttachmentLabelFocused; |
|
368 } |
|
369 |
|
370 UpdateComponentArrayL(); |
|
371 LayoutControls(); |
|
372 iSizeObserver->UpdateFieldSizeL(); |
|
373 } |
|
374 |
|
375 // ----------------------------------------------------------------------------- |
|
376 // CNcsAttachmentField::FocusedAttachmentLabelIndex() |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 TInt CNcsAttachmentField::FocusedAttachmentLabelIndex() |
|
380 { |
|
381 FUNC_LOG; |
|
382 return iFocusedLabelIndex; |
|
383 } |
|
384 |
|
385 // ----------------------------------------------------------------------------- |
|
386 // CNcsAttachmentField::UpdateAttachmentTextsL() |
|
387 // ----------------------------------------------------------------------------- |
|
388 // |
|
389 void CNcsAttachmentField::UpdateAttachmentTextsL() |
|
390 { |
|
391 FUNC_LOG; |
|
392 // create new array of labels. |
|
393 iAttachmentLabelCount = 0; |
|
394 TInt count = iAttachmentNames->MdcaCount(); |
|
395 TInt existingLabelCount = iAttachmentLabels.Count(); |
|
396 TInt i( 0 ); |
|
397 |
|
398 // First, set the new texts using existing attachment labels objects |
|
399 for ( ; i<count; ++i ) |
|
400 { |
|
401 if ( i==existingLabelCount ) |
|
402 { |
|
403 // no more re-usable label objects in their array.. break this |
|
404 // loop and continue with the next one (that creates new labels) |
|
405 break; |
|
406 } |
|
407 UpdateSingleAttachmentLabelTextL( iAttachmentLabels[i], i ); |
|
408 ++iAttachmentLabelCount; |
|
409 } |
|
410 |
|
411 // Create new attachment labels if needed |
|
412 if ( i<count ) |
|
413 { |
|
414 // stringloader used to get the initial (dummy) attachment text.. |
|
415 HBufC* textBuf = StringLoader::LoadLC( iLabelTextId ); |
|
416 |
|
417 for ( ; i<count; ++i ) |
|
418 { |
|
419 // create and initialize (fonts & colors) new label |
|
420 CNcsLabel* label = new ( ELeave ) CNcsLabel( *this, NULL ); |
|
421 CleanupStack::PushL( label ); |
|
422 label->SetTextL( *textBuf ); |
|
423 UpdateFontSize( label ); |
|
424 UpdateColors( label ); |
|
425 UpdateSingleAttachmentLabelTextL( label, i ); |
|
426 |
|
427 // append then new label to attachment label array |
|
428 iAttachmentLabels.AppendL( label ); |
|
429 CleanupStack::Pop( label ); |
|
430 ++iAttachmentLabelCount; |
|
431 } |
|
432 CleanupStack::PopAndDestroy( textBuf ); |
|
433 } |
|
434 } |
|
435 |
|
436 |
|
437 // ----------------------------------------------------------------------------- |
|
438 // CNcsAttachmentField::ResizeIcons() |
|
439 // ----------------------------------------------------------------------------- |
|
440 // |
|
441 void CNcsAttachmentField::ResizeIcons() |
|
442 { |
|
443 FUNC_LOG; |
|
444 const TSize frontIconSize( NcsUtility::HeaderDetailIconRect( |
|
445 Rect(), 1, NcsUtility::EIconFront ).Size() ); |
|
446 if ( frontIconSize != iAttachmentBitmap->SizeInPixels() ) |
|
447 { |
|
448 AknIconUtils::SetSize( iAttachmentBitmap, frontIconSize, |
|
449 EAspectRatioPreservedAndUnusedSpaceRemoved ); |
|
450 AknIconUtils::SetSize( iAttachmentMask, frontIconSize, |
|
451 EAspectRatioPreservedAndUnusedSpaceRemoved ); |
|
452 } |
|
453 } |
|
454 |
|
455 // ----------------------------------------------------------------------------- |
|
456 // CNcsAttachmentField::FocusChanged() |
|
457 // ----------------------------------------------------------------------------- |
|
458 // |
|
459 void CNcsAttachmentField::FocusChanged( TDrawNow aDrawNow ) |
|
460 { |
|
461 FUNC_LOG; |
|
462 if ( IsFocused() ) |
|
463 { |
|
464 for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i ) |
|
465 { |
|
466 iAttachmentLabels[i]->SetFocus( i==iFocusedLabelIndex ); |
|
467 } |
|
468 // make sure that control is visible on screen |
|
469 if ( Rect().iTl.iY < 0 ) |
|
470 { |
|
471 TPoint pt = TPoint( 0, 0 ); |
|
472 Reposition( pt,Rect().Width() ); |
|
473 iSizeObserver->UpdateFieldPosition( this ); |
|
474 } |
|
475 else |
|
476 { |
|
477 TPoint pos = PositionRelativeToScreen(); |
|
478 pos.iY += Size().iHeight; |
|
479 CWsScreenDevice* screenDev = ControlEnv()->ScreenDevice(); |
|
480 TPixelsAndRotation pix; |
|
481 screenDev->GetDefaultScreenSizeAndRotation( pix ); |
|
482 const TInt h = pix.iPixelSize.iHeight; |
|
483 if ( pos.iY >= h - h / 3 ) |
|
484 { |
|
485 TPoint pt = TPoint( 0, h / 3 ); |
|
486 Reposition( pt,Rect().Width() ); |
|
487 iSizeObserver->UpdateFieldPosition( this ); |
|
488 } |
|
489 } |
|
490 |
|
491 if ( iParentControl ) |
|
492 { |
|
493 TRAP_IGNORE( iParentControl->SetMskL() ); |
|
494 } |
|
495 } |
|
496 else |
|
497 { |
|
498 for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i ) |
|
499 { |
|
500 iAttachmentLabels[i]->SetFocus( EFalse ); |
|
501 } |
|
502 } |
|
503 |
|
504 UpdateColors(); |
|
505 |
|
506 if ( aDrawNow ) |
|
507 { |
|
508 DrawNow(); |
|
509 } |
|
510 else |
|
511 { |
|
512 DrawDeferred(); |
|
513 } |
|
514 } |
|
515 |
|
516 // ----------------------------------------------------------------------------- |
|
517 // CNcsAttachmentField::UpdateColors() |
|
518 // ----------------------------------------------------------------------------- |
|
519 // |
|
520 void CNcsAttachmentField::UpdateColors() |
|
521 { |
|
522 FUNC_LOG; |
|
523 for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i ) |
|
524 { |
|
525 UpdateColors( iAttachmentLabels[i] ); |
|
526 // currently all attachments are underlined |
|
527 iAttachmentLabels[i]->SetUnderlining( ETrue ); |
|
528 } |
|
529 |
|
530 CFreestyleEmailUiAppUi* appUi = |
|
531 static_cast<CFreestyleEmailUiAppUi*>( ControlEnv()->AppUi() ); |
|
532 iBorderColor = appUi->LayoutHandler()->ComposerFieldBorderColor(); |
|
533 iBgColor = appUi->LayoutHandler()->ComposerFieldBackgroundColor(); |
|
534 } |
|
535 |
|
536 // ----------------------------------------------------------------------------- |
|
537 // CNcsAttachmentField::UpdateColors() |
|
538 // ----------------------------------------------------------------------------- |
|
539 // |
|
540 void CNcsAttachmentField::UpdateColors( CNcsLabel* aLabel ) |
|
541 { |
|
542 FUNC_LOG; |
|
543 if ( aLabel ) |
|
544 { |
|
545 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
546 TRgb labelTextColor = KRgbBlack; |
|
547 TRgb labelEmphasisColor = KRgbBlack; |
|
548 TRgb labelHighlightFullEmphasisColor = KRgbBlack; |
|
549 |
|
550 AknsUtils::GetCachedColor( |
|
551 skin, |
|
552 labelTextColor, |
|
553 KAknsIIDQsnTextColors, |
|
554 aLabel->IsFocused() ? |
|
555 EAknsCIQsnTextColorsCG24 : EAknsCIQsnTextColorsCG6 ); |
|
556 AknsUtils::GetCachedColor( |
|
557 skin, |
|
558 labelEmphasisColor, |
|
559 KAknsIIDQsnHighlightColors, |
|
560 EAknsCIQsnHighlightColorsCG3 ); |
|
561 AknsUtils::GetCachedColor( |
|
562 skin, |
|
563 labelHighlightFullEmphasisColor, |
|
564 KAknsIIDQsnHighlightColors, |
|
565 EAknsCIQsnHighlightColorsCG2 ); |
|
566 |
|
567 TRAP_IGNORE( aLabel->OverrideColorL( |
|
568 EColorLabelText, labelTextColor ) ); |
|
569 TRAP_IGNORE( aLabel->OverrideColorL( |
|
570 EColorLabelTextEmphasis, labelEmphasisColor ) ); |
|
571 TRAP_IGNORE( aLabel->OverrideColorL( |
|
572 EColorLabelHighlightFullEmphasis, |
|
573 labelHighlightFullEmphasisColor ) ); |
|
574 } |
|
575 } |
|
576 |
|
577 // ----------------------------------------------------------------------------- |
|
578 // CNcsAttachmentField::UpdateFontSize() |
|
579 // ----------------------------------------------------------------------------- |
|
580 // |
|
581 void CNcsAttachmentField::UpdateFontSize() |
|
582 { |
|
583 FUNC_LOG; |
|
584 if ( iAttachmentLabelCount ) |
|
585 { |
|
586 // same font used for all labels, so just get the first one's |
|
587 iEditorFont = NcsUtility::GetLayoutFont( |
|
588 iAttachmentLabels[0]->Rect(), NcsUtility::ENcsHeaderDetailFont ); |
|
589 } |
|
590 for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i ) |
|
591 { |
|
592 iAttachmentLabels[i]->SetFont( iEditorFont ); |
|
593 } |
|
594 } |
|
595 |
|
596 // ----------------------------------------------------------------------------- |
|
597 // CNcsAttachmentField::UpdateFontSize() |
|
598 // ----------------------------------------------------------------------------- |
|
599 // |
|
600 void CNcsAttachmentField::UpdateFontSize( CNcsLabel* aLabel ) |
|
601 { |
|
602 FUNC_LOG; |
|
603 iEditorFont = NcsUtility::GetLayoutFont( |
|
604 aLabel->Rect(), NcsUtility::ENcsHeaderDetailFont ); |
|
605 aLabel->SetFont( iEditorFont ); |
|
606 } |
|
607 |
|
608 // ----------------------------------------------------------------------------- |
|
609 // CNcsAttachmentField::LayoutControls() |
|
610 // ----------------------------------------------------------------------------- |
|
611 // |
|
612 void CNcsAttachmentField::LayoutControls() |
|
613 { |
|
614 FUNC_LOG; |
|
615 const TRect rect( Rect() ); |
|
616 for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i ) |
|
617 { |
|
618 NcsUtility::LayoutDetailLabel( iAttachmentLabels[i], rect, i ); |
|
619 if ( i == 0 ) |
|
620 { |
|
621 // icons need to be updated for first round only |
|
622 UpdateIconPositions( rect ); |
|
623 } |
|
624 } |
|
625 } |
|
626 |
|
627 // ----------------------------------------------------------------------------- |
|
628 // CNcsAttachmentField::UpdateIconPositions() |
|
629 // ----------------------------------------------------------------------------- |
|
630 // |
|
631 void CNcsAttachmentField::UpdateIconPositions( const TRect& aRect ) |
|
632 { |
|
633 FUNC_LOG; |
|
634 iAttachmentIconPos = NcsUtility::HeaderDetailIconRect( |
|
635 aRect, 1, NcsUtility::EIconFront ).iTl; |
|
636 } |
|
637 |
|
638 // ----------------------------------------------------------------------------- |
|
639 // CNcsAttachmentField::HandleResourceChange() |
|
640 // ----------------------------------------------------------------------------- |
|
641 // |
|
642 void CNcsAttachmentField::HandleResourceChange( TInt aType ) |
|
643 { |
|
644 FUNC_LOG; |
|
645 CCoeControl::HandleResourceChange( aType ); |
|
646 if ( aType == KAknsMessageSkinChange || |
|
647 aType == KEikMessageColorSchemeChange ) |
|
648 { |
|
649 UpdateFontSize(); |
|
650 UpdateColors(); |
|
651 CreateIcons(); |
|
652 DrawDeferred(); |
|
653 } |
|
654 } |
|
655 |
|
656 // ----------------------------------------------------------------------------- |
|
657 // CNcsAttachmentField::HandlePointerEventL() |
|
658 // ----------------------------------------------------------------------------- |
|
659 // |
|
660 void CNcsAttachmentField::HandlePointerEventL( |
|
661 const TPointerEvent& aPointerEvent ) |
|
662 { |
|
663 FUNC_LOG; |
|
664 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
665 |
|
666 if ( aPointerEvent.iType == TPointerEvent::EButton1Down && |
|
667 Rect().Contains( aPointerEvent.iPosition ) ) |
|
668 { |
|
669 TBool focusedAttachmentLabelIndexChanged( EFalse ); |
|
670 TInt i( 0 ); |
|
671 for ( ; i<iAttachmentLabelCount; ++i ) |
|
672 { |
|
673 if ( iAttachmentLabels[i]->TextHitAreaRect().Contains( |
|
674 aPointerEvent.iPosition ) ) |
|
675 { |
|
676 // tactile feedback |
|
677 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
678 if ( feedback ) |
|
679 { |
|
680 feedback->InstantFeedback( this, ETouchFeedbackBasic ); |
|
681 } |
|
682 |
|
683 if ( iFocusedLabelIndex != i ) |
|
684 { |
|
685 focusedAttachmentLabelIndexChanged = ETrue; |
|
686 iFocusedLabelIndex = i; |
|
687 } |
|
688 break; |
|
689 } |
|
690 } |
|
691 |
|
692 if ( i == iAttachmentLabelCount ) |
|
693 { |
|
694 // Pointer event happened outside any of the labels. |
|
695 // Invalidate focused label index.. this will cause the next |
|
696 // for loop to set all label focuses to EFalse. |
|
697 iFocusedLabelIndex = KNoAttachmentLabelFocused; |
|
698 focusedAttachmentLabelIndexChanged = ETrue; |
|
699 } |
|
700 |
|
701 if ( focusedAttachmentLabelIndexChanged ) |
|
702 { |
|
703 // only redraw if focused attachment label changed |
|
704 for ( TInt i( 0 ); i<iAttachmentLabelCount; ++i ) |
|
705 { |
|
706 iAttachmentLabels[i]->SetFocus( i==iFocusedLabelIndex ); |
|
707 } |
|
708 UpdateColors(); |
|
709 DrawDeferred(); |
|
710 } |
|
711 } |
|
712 } |
|
713 |
|
714 // ----------------------------------------------------------------------------- |
|
715 // CNcsAttachmentField::CreateIcons() |
|
716 // ----------------------------------------------------------------------------- |
|
717 // |
|
718 TInt CNcsAttachmentField::CreateIcons() |
|
719 { |
|
720 FUNC_LOG; |
|
721 TRAPD( error, CreateIconsL() ); |
|
722 return error; |
|
723 } |
|
724 |
|
725 // ----------------------------------------------------------------------------- |
|
726 // CNcsAttachmentField::CreateIconsL() |
|
727 // ----------------------------------------------------------------------------- |
|
728 // |
|
729 void CNcsAttachmentField::CreateIconsL() |
|
730 { |
|
731 FUNC_LOG; |
|
732 CFreestyleEmailUiAppUi* fsAppUi = |
|
733 static_cast<CFreestyleEmailUiAppUi*>( ControlEnv()->AppUi() ); |
|
734 delete iAttachmentBitmap; |
|
735 iAttachmentBitmap = NULL; |
|
736 delete iAttachmentMask; |
|
737 iAttachmentMask = NULL; |
|
738 fsAppUi->FsTextureManager()->ProvideBitmapL( |
|
739 EAttachmentIcon, iAttachmentBitmap, iAttachmentMask ); |
|
740 ResizeIcons(); |
|
741 } |
|
742 |
|
743 // ----------------------------------------------------------------------------- |
|
744 // CNcsAttachmentField::UpdateSingleAttachmentLabelTextL() |
|
745 // ----------------------------------------------------------------------------- |
|
746 // |
|
747 void CNcsAttachmentField::UpdateSingleAttachmentLabelTextL( |
|
748 CNcsLabel* aLabel, TInt aIndex ) |
|
749 { |
|
750 FUNC_LOG; |
|
751 // create decorated size text including the preceeding space character |
|
752 HBufC* decoratedSize = StringLoader::LoadLC( |
|
753 R_FSE_VIEWER_ATTACHMENTS_LIST_SIZE, |
|
754 iAttachmentSizes->MdcaPoint( aIndex ) ); |
|
755 HBufC* decoratedSizeWithSpace = HBufC::NewL( |
|
756 decoratedSize->Length() + |
|
757 KSpace().Length() + |
|
758 KBidiRleStartChar().Length() + |
|
759 KBidiPdfChar().Length() ); |
|
760 decoratedSizeWithSpace->Des().Append( KSpace ); |
|
761 if ( AknLayoutUtils::LayoutMirrored() ) |
|
762 { |
|
763 // Put size part into embedded right-to-left block to ensure |
|
764 // correct rendering even when name part is written from |
|
765 // left-to-right. |
|
766 decoratedSizeWithSpace->Des().Append( KBidiRleStartChar ); |
|
767 decoratedSizeWithSpace->Des().Append( *decoratedSize ); |
|
768 decoratedSizeWithSpace->Des().Append( KBidiPdfChar ); |
|
769 } |
|
770 else |
|
771 { |
|
772 decoratedSizeWithSpace->Des().Append( *decoratedSize ); |
|
773 } |
|
774 CleanupStack::PopAndDestroy( decoratedSize ); |
|
775 CleanupStack::PushL( decoratedSizeWithSpace ); |
|
776 |
|
777 // clip attachment name to fit the field so that size information has |
|
778 // enough space too. |
|
779 const CFont& font = *aLabel->Font(); |
|
780 |
|
781 TInt labelWidth = aLabel->Size().iWidth; |
|
782 TInt sizeTextInPixels = |
|
783 font.TextWidthInPixels( *decoratedSizeWithSpace ); |
|
784 TInt pixelsLeftForAttachmentName = labelWidth - sizeTextInPixels; |
|
785 |
|
786 HBufC* attachmentText = NULL; // will contain the complete text |
|
787 // safe check if the size information is too wide for some reason. |
|
788 if ( pixelsLeftForAttachmentName < 0 ) |
|
789 { |
|
790 attachmentText = HBufC::NewLC( |
|
791 iAttachmentNames->MdcaPoint( aIndex ).Length() |
|
792 + decoratedSizeWithSpace->Length() ); |
|
793 attachmentText->Des().Append( iAttachmentNames->MdcaPoint( aIndex ) ); |
|
794 attachmentText->Des().Append( *decoratedSizeWithSpace ); |
|
795 TPtr attachmentTextBufferModDes = attachmentText->Des(); |
|
796 AknTextUtils::ClipToFit( attachmentTextBufferModDes, |
|
797 font, labelWidth ); |
|
798 } |
|
799 else |
|
800 { // normal case |
|
801 HBufC* attacmentNameBuffer = |
|
802 iAttachmentNames->MdcaPoint( aIndex ).AllocLC(); |
|
803 TPtr attachmentNameBufferModDes = attacmentNameBuffer->Des(); |
|
804 AknTextUtils::ClipToFit( attachmentNameBufferModDes, |
|
805 font, pixelsLeftForAttachmentName ); |
|
806 |
|
807 attachmentText = HBufC::NewL( |
|
808 attacmentNameBuffer->Length() |
|
809 + decoratedSizeWithSpace->Length() ); |
|
810 attachmentText->Des().Append( *attacmentNameBuffer ); |
|
811 attachmentText->Des().Append( *decoratedSizeWithSpace ); |
|
812 CleanupStack::PopAndDestroy( attacmentNameBuffer ); |
|
813 CleanupStack::PushL( attachmentText ); |
|
814 } |
|
815 aLabel->SetTextL( *attachmentText ); |
|
816 CleanupStack::PopAndDestroy( attachmentText ); |
|
817 CleanupStack::PopAndDestroy( decoratedSizeWithSpace ); |
|
818 } |
|
819 |