|
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: Visualiser class for Control Button component. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 #include <alf/alfcontrol.h> |
|
20 #include <alf/alfdecklayout.h> |
|
21 #include <alf/alfimagevisual.h> |
|
22 #include <alf/alfgridlayout.h> |
|
23 #include <alf/alfenv.h> |
|
24 #include <alf/alftextstylemanager.h> |
|
25 #include <alf/alftextvisual.h> |
|
26 #include <alf/alfanchorlayout.h> |
|
27 #include <alf/alfgradientbrush.h> |
|
28 #include <alf/alfframebrush.h> |
|
29 #include <alf/alfimagebrush.h> |
|
30 #include <alf/alfshadowborderbrush.h> |
|
31 #include <alf/alfbrusharray.h> |
|
32 #include <alf/alftextstyle.h> |
|
33 #include <AknsConstants.h> |
|
34 #include <AknUtils.h> |
|
35 #include <touchlogicalfeedback.h> |
|
36 #include <layoutmetadata.cdl.h> |
|
37 |
|
38 #include "fscontrolbuttonvisualiser.h" |
|
39 #include "fscontrolbuttonmodel.h" |
|
40 #include "fsgenericpanic.h" |
|
41 #include "fstextstylemanager.h" |
|
42 #include "fslayoutmanager.h" |
|
43 #include "fscontrolbar.h" |
|
44 |
|
45 const TInt KFsDefaultFontStyle = EAlfTextStyleNormal; |
|
46 const TInt KDefaultShadowBorderWidth( 8 ); |
|
47 const TReal KShadowBorderOpacity( 0.08 ); |
|
48 const TInt KButtonBorderSize( 8 ); |
|
49 |
|
50 |
|
51 // ======== MEMBER FUNCTIONS ======== |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Constructor. |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 EXPORT_C CFsControlButtonVisualiser::CFsControlButtonVisualiser( |
|
58 CAlfControl& aParent, |
|
59 CAlfDeckLayout& aParentLayout, |
|
60 CFsTextStyleManager* aTextStyleManager ) : |
|
61 iParent( &aParent ), |
|
62 iParentLayout( &aParentLayout ), |
|
63 iUpdateIconsAlign( EFalse ), |
|
64 iFirstDraw( ETrue ), |
|
65 iVisible( EFalse ), |
|
66 iTextStyleManager( aTextStyleManager ) |
|
67 { |
|
68 FUNC_LOG; |
|
69 } |
|
70 |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // Constructor. |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 EXPORT_C CFsControlButtonVisualiser::CFsControlButtonVisualiser() : |
|
77 iUpdateIconsAlign( EFalse ), |
|
78 iFirstDraw( ETrue ), |
|
79 iVisible( EFalse ), |
|
80 iTextStyleManager( NULL ) |
|
81 { |
|
82 FUNC_LOG; |
|
83 } |
|
84 |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // Second phase constructor. |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 EXPORT_C void CFsControlButtonVisualiser::ConstructL() |
|
91 { |
|
92 FUNC_LOG; |
|
93 if ( iParent ) |
|
94 { |
|
95 // Visual for background content |
|
96 iButtonLayout = CAlfLayout::AddNewL( *iParent ); |
|
97 iButtonLayout->SetTactileFeedbackL( ETouchEventStylusDown, ETouchFeedbackBasic ); |
|
98 iButtonLayout->EnableBrushesL(); |
|
99 |
|
100 iButtonContentLayout = CAlfLayout::AddNewL( *iParent ); |
|
101 |
|
102 // Request callback after image is loaded to refresh it's size and |
|
103 // position. |
|
104 iParent->Env().TextureManager().AddLoadObserverL( this ); |
|
105 |
|
106 iParentLayout->SetFlag( EAlfVisualFlagLayoutUpdateNotification ); |
|
107 iButtonLayout->SetFlags( EAlfVisualFlagManualSize | EAlfVisualFlagManualPosition ); |
|
108 iButtonContentLayout->SetFlags( EAlfVisualFlagManualSize | EAlfVisualFlagManualPosition ); |
|
109 |
|
110 } |
|
111 } |
|
112 |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // Two-phased constructor. |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 CFsControlButtonVisualiser* CFsControlButtonVisualiser::NewL( |
|
119 CAlfControl& aParent, |
|
120 CAlfDeckLayout& aParentLayout, |
|
121 CFsTextStyleManager* aTextStyleManager ) |
|
122 { |
|
123 FUNC_LOG; |
|
124 CFsControlButtonVisualiser* self = |
|
125 new(ELeave)CFsControlButtonVisualiser( |
|
126 aParent, aParentLayout, aTextStyleManager ); |
|
127 |
|
128 CleanupStack::PushL( self ); |
|
129 self->ConstructL(); |
|
130 CleanupStack::Pop( self ); |
|
131 return self; |
|
132 } |
|
133 |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // Destructor. |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 EXPORT_C CFsControlButtonVisualiser::~CFsControlButtonVisualiser() |
|
140 { |
|
141 FUNC_LOG; |
|
142 ClearBackgroundImage(); |
|
143 |
|
144 // removing from parent |
|
145 if ( iButtonLayout ) |
|
146 { |
|
147 // If clase is only needed by debug version only. |
|
148 if ( KErrNotFound != iParentLayout->FindVisual( iButtonLayout ) ) |
|
149 { |
|
150 iParentLayout->Remove( iButtonLayout ); |
|
151 } |
|
152 iParent->Remove( iButtonLayout ); |
|
153 iParent->Env().TextureManager().RemoveLoadObserver( this ); |
|
154 delete iButtonLayout; |
|
155 } |
|
156 |
|
157 delete iBgColorBrush; |
|
158 delete iShadowBorderBrush; |
|
159 delete iTextFontSpec; |
|
160 } |
|
161 |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // From class CFsControlButtonVisualiserBase. |
|
165 // Initializes visualiser with model. |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 EXPORT_C void CFsControlButtonVisualiser::InitializeL( |
|
169 CFsControlButtonModel& aButtonModel ) |
|
170 { |
|
171 FUNC_LOG; |
|
172 iButtonModel = &aButtonModel; |
|
173 |
|
174 // Add background color brush. This cannot be done in ConstructL as the |
|
175 // button model isn't set before. |
|
176 if ( !iBgColorBrush ) |
|
177 { |
|
178 iBgColorBrush = CAlfGradientBrush::NewL( iParent->Env() ); |
|
179 if( iShowShadow ) |
|
180 { |
|
181 iBgColorBrush->SetOpacity( KShadowBorderOpacity ); |
|
182 iBgColorBrush->SetColor(KRgbBlack); |
|
183 } |
|
184 else |
|
185 { |
|
186 iBgColorBrush->SetOpacity( 0 ); |
|
187 } |
|
188 |
|
189 iBgColorBrush->SetLayer( EAlfBrushLayerBackground ); |
|
190 iButtonLayout->Brushes()->AppendL( iBgColorBrush, |
|
191 EAlfDoesNotHaveOwnership ); |
|
192 } |
|
193 |
|
194 iUseDefaultBackground = ETrue; |
|
195 |
|
196 // Add a shadow border brush to outline the buttons with a shadowed border. |
|
197 if ( iShowShadow && !iShadowBorderBrush ) |
|
198 { |
|
199 iShadowBorderBrush = CAlfShadowBorderBrush::NewL( |
|
200 iParent->Env(), TAlfMetric( KDefaultShadowBorderWidth ) ); |
|
201 iShadowBorderBrush->SetOpacity( KShadowBorderOpacity ); |
|
202 iShadowBorderBrush->SetLayer( EAlfBrushLayerBackground ); |
|
203 iButtonLayout->Brushes()->AppendL( iShadowBorderBrush, |
|
204 EAlfDoesNotHaveOwnership ); |
|
205 } |
|
206 |
|
207 UpdateVisualThemeL(); |
|
208 |
|
209 // create needed visuals |
|
210 CreateButtonVisualsL(); |
|
211 |
|
212 UpdateBarLayout(); |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // CFsControlButtonVisualiser::UpdateVisualThemeL |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 void CFsControlButtonVisualiser::UpdateVisualThemeL() |
|
220 { |
|
221 if( iUseDefaultBackground ) |
|
222 { |
|
223 ClearBackgroundImage(); |
|
224 iDefaultBgBrush = CAlfFrameBrush::NewL( iParent->Env(), KAknsIIDQsnFrButtonTb ); |
|
225 iBgBrush = iDefaultBgBrush; |
|
226 iButtonLayout->Brushes()->AppendL( iBgBrush, EAlfDoesNotHaveOwnership ); |
|
227 UpdateBarLayout(); |
|
228 } |
|
229 else if ( iBgColorBrush ) |
|
230 { |
|
231 SetBackgroundColor( iButtonModel->TextColor( |
|
232 CFsControlButtonModel::EButtonBackground ) ); |
|
233 } |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------------------------- |
|
237 // From class CFsControlButtonVisualiserBase. |
|
238 // Refreshes button's content. |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 EXPORT_C void CFsControlButtonVisualiser::Refresh() |
|
242 { |
|
243 FUNC_LOG; |
|
244 // draw only if enabled and ready for drawing |
|
245 if ( !IsVisible() ) |
|
246 { |
|
247 return; |
|
248 } |
|
249 |
|
250 TBool buttonSizeChanged( iButtonModel->ButtonSizeChanged() ); |
|
251 |
|
252 if ( buttonSizeChanged || |
|
253 iButtonModel->AutoSizeMode() |
|
254 == MFsControlButtonInterface::EFsFitToContent || |
|
255 iButtonModel->AutoSizeMode() |
|
256 == MFsControlButtonInterface::EFsFitToParent ) |
|
257 { |
|
258 TSize buttonSize( iButtonModel->Size() ); |
|
259 UpdateButtonSize(); |
|
260 buttonSizeChanged |= buttonSize != iButtonModel->Size(); |
|
261 } |
|
262 |
|
263 if ( buttonSizeChanged ) |
|
264 { |
|
265 UpdateBarLayout(); |
|
266 return; |
|
267 } |
|
268 |
|
269 if ( iButtonModel->ButtonPosChanged() ) |
|
270 { |
|
271 UpdateButtonPos(); |
|
272 if ( !buttonSizeChanged ) |
|
273 { |
|
274 UpdateBarLayout(); |
|
275 return; |
|
276 } |
|
277 } |
|
278 |
|
279 // recalculate icons alignement if needed |
|
280 if ( iUpdateIconsAlign || iFirstDraw ) |
|
281 { |
|
282 if ( iButtonModel->ContainsElement( ECBElemIconA ) ) |
|
283 { |
|
284 SetImageAlign( iIconA, iAIconHAlign, iAIconVAlign ); |
|
285 } |
|
286 |
|
287 if ( iButtonModel->ContainsElement( ECBElemIconB ) ) |
|
288 { |
|
289 SetImageAlign( iIconB, iBIconHAlign, iBIconVAlign ); |
|
290 } |
|
291 |
|
292 iUpdateIconsAlign = EFalse; |
|
293 iFirstDraw = EFalse; |
|
294 } |
|
295 |
|
296 // if dimmed |
|
297 if ( iButtonModel->IsDimmed() ) |
|
298 { |
|
299 PrepareDrawDimmed(); |
|
300 } |
|
301 // if focused |
|
302 else if( iButtonModel->IsFocused() && iDrawFocus ) |
|
303 { |
|
304 PrepareDrawFocused(); |
|
305 } |
|
306 // normal - no focus, enabled |
|
307 else |
|
308 { |
|
309 PrepareDrawNormal(); |
|
310 } |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // From class CFsControlButtonVisualiserBase. |
|
315 // Refreshes button's content, sets topleft point of button in specified |
|
316 // place. |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 EXPORT_C void CFsControlButtonVisualiser::Refresh( TPoint aStartAt ) |
|
320 { |
|
321 FUNC_LOG; |
|
322 if ( iButtonModel->AutoPosition() ) |
|
323 { |
|
324 TAlfRealPoint pos( aStartAt ); |
|
325 if ( CFsLayoutManager::IsMirrored() ) |
|
326 { |
|
327 TInt width( iParentLayout->Size().Target().iX ); |
|
328 pos.iX = width - aStartAt.iX - iButtonLayout->Size().Target().iX; |
|
329 } |
|
330 |
|
331 // Set new position for background visual and it's content. |
|
332 iButtonLayout->SetPos( pos ); |
|
333 iButtonContentLayout->SetPos( pos ); |
|
334 } |
|
335 |
|
336 Refresh(); |
|
337 } |
|
338 |
|
339 |
|
340 // --------------------------------------------------------------------------- |
|
341 // From class CFsControlButtonVisualiserBase. |
|
342 // Retrieves end X coordinate of the button. |
|
343 // --------------------------------------------------------------------------- |
|
344 // |
|
345 TInt CFsControlButtonVisualiser::GetBottomRight() const |
|
346 { |
|
347 FUNC_LOG; |
|
348 return |
|
349 iButtonModel->TopLeftPoint().iX + iButtonLayout->Size().iX.Target(); |
|
350 } |
|
351 |
|
352 |
|
353 // --------------------------------------------------------------------------- |
|
354 // From class CFsControlButtonVisualiserBase. |
|
355 // Retrieves position of the button. |
|
356 // --------------------------------------------------------------------------- |
|
357 // |
|
358 const TAlfTimedPoint CFsControlButtonVisualiser::Pos() const |
|
359 { |
|
360 FUNC_LOG; |
|
361 return iButtonLayout->Pos(); |
|
362 } |
|
363 |
|
364 |
|
365 // --------------------------------------------------------------------------- |
|
366 // From class CFsControlButtonVisualiserBase. |
|
367 // Retrieves size of the button. |
|
368 // --------------------------------------------------------------------------- |
|
369 // |
|
370 const TAlfTimedPoint CFsControlButtonVisualiser::Size() const |
|
371 { |
|
372 FUNC_LOG; |
|
373 return iButtonLayout->Size(); |
|
374 } |
|
375 |
|
376 |
|
377 // --------------------------------------------------------------------------- |
|
378 // From class CFsControlButtonVisualiserBase. |
|
379 // Sets background image of the button. |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 EXPORT_C void CFsControlButtonVisualiser::SetBackgroundImageL( |
|
383 CAlfImageBrush* aImage ) |
|
384 { |
|
385 FUNC_LOG; |
|
386 // Release the old background image. |
|
387 ClearBackgroundImage(); |
|
388 |
|
389 // As the ownership of the new brush is gained the pointer can't be lost. |
|
390 CleanupStack::PushL( aImage ); |
|
391 iButtonLayout->Brushes()->InsertL( 0, aImage, EAlfDoesNotHaveOwnership ); |
|
392 CleanupStack::Pop( aImage ); |
|
393 |
|
394 iUseDefaultBackground = EFalse; |
|
395 iBgBrush = aImage; |
|
396 } |
|
397 |
|
398 |
|
399 // --------------------------------------------------------------------------- |
|
400 // Sets background color for button. |
|
401 // --------------------------------------------------------------------------- |
|
402 // |
|
403 EXPORT_C void CFsControlButtonVisualiser::SetBackgroundColor( |
|
404 const TRgb& aColor ) |
|
405 { |
|
406 FUNC_LOG; |
|
407 iBgColorBrush->SetColor( aColor ); |
|
408 iBgColorBrush->SetOpacity( 1 ); |
|
409 } |
|
410 |
|
411 |
|
412 // --------------------------------------------------------------------------- |
|
413 // Clears button's background color. Button is transparent. |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 EXPORT_C void CFsControlButtonVisualiser::ClearBackgroundColor() |
|
417 { |
|
418 FUNC_LOG; |
|
419 if( iBgColorBrush ) |
|
420 { |
|
421 iBgColorBrush->SetOpacity( 0 ); |
|
422 } |
|
423 } |
|
424 |
|
425 |
|
426 // --------------------------------------------------------------------------- |
|
427 // From class CFsControlButtonVisualiserBase. |
|
428 // Clears background image of the button. |
|
429 // --------------------------------------------------------------------------- |
|
430 // |
|
431 EXPORT_C void CFsControlButtonVisualiser::ClearBackgroundImage() |
|
432 { |
|
433 FUNC_LOG; |
|
434 if ( iBgBrush ) |
|
435 { |
|
436 for ( TInt i( iButtonLayout->Brushes()->Count() - 1 ); 0 <= i; i-- ) |
|
437 { |
|
438 if ( &iButtonLayout->Brushes()->At( i ) == iBgBrush ) |
|
439 { |
|
440 iButtonLayout->Brushes()->Remove( i ); |
|
441 break; |
|
442 } |
|
443 } |
|
444 delete iBgBrush; |
|
445 iBgBrush = NULL; |
|
446 iDefaultBgBrush = NULL; |
|
447 } |
|
448 } |
|
449 |
|
450 |
|
451 // --------------------------------------------------------------------------- |
|
452 // From class CFsControlButtonVisualiserBase. |
|
453 // Sets alignement of element of the button. |
|
454 // --------------------------------------------------------------------------- |
|
455 // |
|
456 EXPORT_C void CFsControlButtonVisualiser::SetElemAlignL( |
|
457 TFsControlButtonElem aButtonElem, |
|
458 TAlfAlignHorizontal aHAlign, |
|
459 TAlfAlignVertical aVAlign ) |
|
460 { |
|
461 FUNC_LOG; |
|
462 TFsControlButtonType buttonType( iButtonModel->Type() ); |
|
463 |
|
464 // check if button contains this element. |
|
465 if ( !iButtonModel->ContainsElement( aButtonElem ) ) |
|
466 { |
|
467 FsGenericPanic( EFsControlButtonIncorrectButtonElement ); |
|
468 User::Leave( KErrNotSupported ); |
|
469 } |
|
470 |
|
471 switch ( aButtonElem ) |
|
472 { |
|
473 case ECBElemIconA: |
|
474 { |
|
475 iAIconHAlign = aHAlign; |
|
476 iAIconVAlign = aVAlign; |
|
477 SetImageAlign( iIconA, aHAlign, aVAlign ); |
|
478 break; |
|
479 } |
|
480 |
|
481 case ECBElemIconB: |
|
482 { |
|
483 iBIconHAlign = aHAlign; |
|
484 iBIconVAlign = aVAlign; |
|
485 SetImageAlign( iIconB, aHAlign, aVAlign ); |
|
486 break; |
|
487 } |
|
488 |
|
489 case ECBElemLabelFirstLine: |
|
490 { |
|
491 SetTextAlign( iLabelFirstLine, aHAlign, aVAlign ); |
|
492 break; |
|
493 } |
|
494 |
|
495 case ECBElemLabelSndLine: |
|
496 { |
|
497 SetTextAlign( iLabelSecondLine, aHAlign, aVAlign ); |
|
498 break; |
|
499 } |
|
500 |
|
501 default: |
|
502 { |
|
503 // no other elements available |
|
504 FsGenericPanic( EFsControlButtonIncorrectButtonElement ); |
|
505 break; |
|
506 } |
|
507 } |
|
508 } |
|
509 |
|
510 |
|
511 // --------------------------------------------------------------------------- |
|
512 // Update elemets after texture loading is completed. |
|
513 // --------------------------------------------------------------------------- |
|
514 // |
|
515 EXPORT_C void CFsControlButtonVisualiser::TextureLoadingCompleted( |
|
516 CAlfTexture& aTexture, |
|
517 TInt /*aTextureId*/, |
|
518 TInt aErrorCode ) |
|
519 { |
|
520 FUNC_LOG; |
|
521 if ( aErrorCode ) |
|
522 { |
|
523 return; |
|
524 } |
|
525 |
|
526 // <cmail> Safety check added. Check why it is needed here. |
|
527 if ( iIconA && |
|
528 iIconA->Image().HasTexture() && |
|
529 &iIconA->Image().Texture() == &aTexture ) |
|
530 { |
|
531 TRAP_IGNORE( UpdateElementL( ECBElemIconA ) ); |
|
532 } |
|
533 if ( iIconB && |
|
534 iIconB->Image().HasTexture() && |
|
535 &iIconB->Image().Texture() == &aTexture ) |
|
536 { |
|
537 TRAP_IGNORE( UpdateElementL( ECBElemIconB ) ); |
|
538 } |
|
539 // </cmail> |
|
540 } |
|
541 |
|
542 // --------------------------------------------------------------------------- |
|
543 // |
|
544 // --------------------------------------------------------------------------- |
|
545 // |
|
546 void CFsControlButtonVisualiser::MakeFocusVisible( TBool aShow ) |
|
547 { |
|
548 FUNC_LOG; |
|
549 if( aShow ) |
|
550 { |
|
551 iDrawFocus = ETrue; |
|
552 PrepareDrawFocused(); |
|
553 } |
|
554 else |
|
555 { |
|
556 iDrawFocus = EFalse; |
|
557 PrepareDrawNormal(); |
|
558 } |
|
559 } |
|
560 |
|
561 // --------------------------------------------------------------------------- |
|
562 // Updates element content from the model. |
|
563 // --------------------------------------------------------------------------- |
|
564 // |
|
565 EXPORT_C void CFsControlButtonVisualiser::UpdateElementL( |
|
566 TFsControlButtonElem aButtonElem ) |
|
567 { |
|
568 FUNC_LOG; |
|
569 // check if button contains this element. |
|
570 if ( !iButtonModel->ContainsElement( aButtonElem ) ) |
|
571 { |
|
572 FsGenericPanic( EFsControlButtonIncorrectButtonElement ); |
|
573 User::Leave( KErrNotSupported ); |
|
574 } |
|
575 |
|
576 switch ( aButtonElem ) |
|
577 { |
|
578 case ECBElemIconA: |
|
579 { |
|
580 iIconA->SetImage( |
|
581 TAlfImage( *iButtonModel->Icon( ECBElemIconA ) ) ); |
|
582 // <cmail> Platform layout change |
|
583 //iIconA->SetSize( iIconA->Image().Texture().Size() ); |
|
584 // </cmail> Platform layout change |
|
585 break; |
|
586 } |
|
587 |
|
588 case ECBElemIconB: |
|
589 { |
|
590 iIconB->SetImage( |
|
591 TAlfImage( *iButtonModel->Icon( ECBElemIconB ) ) ); |
|
592 // <cmail> Platform layout change |
|
593 //iIconB->SetSize( iIconB->Image().Texture().Size() ); |
|
594 // </cmail> Platform layout change |
|
595 break; |
|
596 } |
|
597 |
|
598 case ECBElemLabelFirstLine: |
|
599 { |
|
600 TRAP_IGNORE( iLabelFirstLine->SetTextL( iButtonModel->Text( |
|
601 MFsControlButtonInterface::EFsButtonFirstLine ) ) ); |
|
602 break; |
|
603 } |
|
604 |
|
605 case ECBElemLabelSndLine: |
|
606 { |
|
607 TRAP_IGNORE( iLabelSecondLine->SetTextL( iButtonModel->Text( |
|
608 MFsControlButtonInterface::EFsButtonSecondLine ) ) ); |
|
609 break; |
|
610 } |
|
611 |
|
612 default: |
|
613 { |
|
614 // no other elements available |
|
615 FsGenericPanic( EFsControlButtonIncorrectButtonElement ); |
|
616 break; |
|
617 } |
|
618 } |
|
619 |
|
620 UpdateButtonSize(); |
|
621 UpdateBarLayout(); |
|
622 } |
|
623 |
|
624 |
|
625 // --------------------------------------------------------------------------- |
|
626 // Retrieves width of the button. |
|
627 // --------------------------------------------------------------------------- |
|
628 // |
|
629 TInt CFsControlButtonVisualiser::Width() const |
|
630 { |
|
631 FUNC_LOG; |
|
632 return iButtonModel->Size().iWidth; |
|
633 } |
|
634 |
|
635 |
|
636 // --------------------------------------------------------------------------- |
|
637 // Updates size of button. |
|
638 // --------------------------------------------------------------------------- |
|
639 // |
|
640 EXPORT_C void CFsControlButtonVisualiser::UpdateButtonSize() |
|
641 { |
|
642 FUNC_LOG; |
|
643 TBool textClipping( ETrue ); |
|
644 CAlfTextVisual::TLineWrap textWrapping( |
|
645 CAlfTextVisual::ELineWrapTruncate ); |
|
646 |
|
647 const TPoint oldSize( iButtonContentLayout->Size().Target() ); |
|
648 |
|
649 switch( iButtonModel->AutoSizeMode() ) |
|
650 { |
|
651 case MFsControlButtonInterface::EFsLayout: |
|
652 { |
|
653 if ( iButtonModel->IsLayoutSize() ) |
|
654 { |
|
655 iButtonModel->SetSize( iButtonModel->GetLayoutSize() ); |
|
656 } |
|
657 break; |
|
658 } |
|
659 |
|
660 case MFsControlButtonInterface::EFsFitToContent: |
|
661 { |
|
662 iButtonModel->SetWidth( CalculateButtonSize() ); |
|
663 textWrapping = CAlfTextVisual::ELineWrapManual; |
|
664 textClipping = EFalse; |
|
665 break; |
|
666 } |
|
667 |
|
668 case MFsControlButtonInterface::EFsFitToParent: |
|
669 { |
|
670 iButtonModel->SetWidth( iParentLayout->Size().Target().iX ); |
|
671 break; |
|
672 } |
|
673 |
|
674 case MFsControlButtonInterface::EFsManual: |
|
675 default: |
|
676 { |
|
677 break; |
|
678 } |
|
679 } |
|
680 |
|
681 // New size for the button background. |
|
682 iButtonLayout->SetSize( iButtonModel->Size() ); |
|
683 // Same size for the content |
|
684 iButtonContentLayout->SetSize( iButtonModel->Size() ); |
|
685 |
|
686 if( iDefaultBgBrush ) |
|
687 { |
|
688 TSize size = iButtonModel->Size(); |
|
689 TRect fullRect = TRect( size ); |
|
690 TRect innerRect = fullRect; |
|
691 innerRect.Shrink( KButtonBorderSize,KButtonBorderSize ); |
|
692 TRAP_IGNORE( |
|
693 iDefaultBgBrush->SetFrameRectsL( innerRect, fullRect ); ); |
|
694 } |
|
695 |
|
696 if ( iLabelFirstLine ) |
|
697 { |
|
698 iLabelFirstLine->SetWrapping( textWrapping ); |
|
699 iLabelFirstLine->SetClipping( textClipping ); |
|
700 } |
|
701 |
|
702 if ( iLabelSecondLine ) |
|
703 { |
|
704 iLabelSecondLine->SetWrapping( textWrapping ); |
|
705 iLabelSecondLine->SetClipping( textClipping ); |
|
706 } |
|
707 |
|
708 iButtonLayout->UpdateChildrenLayout(); |
|
709 |
|
710 TRAP_IGNORE( UpdateElementsSizeL( iButtonModel->Type() ) ); |
|
711 |
|
712 iButtonContentLayout->UpdateChildrenLayout(); |
|
713 |
|
714 // update text styles if needed (at least one text line) |
|
715 const TPoint newSize( iButtonContentLayout->Size().Target() ); |
|
716 if ( newSize != oldSize ) |
|
717 { |
|
718 iUpdateIconsAlign = ETrue; |
|
719 if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) ) |
|
720 { |
|
721 UpdateTextStyles(); |
|
722 } |
|
723 UpdateBarLayout(); |
|
724 } |
|
725 } |
|
726 |
|
727 |
|
728 // --------------------------------------------------------------------------- |
|
729 // Retrieves the background layout of the button. |
|
730 // --------------------------------------------------------------------------- |
|
731 // |
|
732 CAlfLayout* CFsControlButtonVisualiser::Layout() |
|
733 { |
|
734 FUNC_LOG; |
|
735 return iButtonLayout; |
|
736 } |
|
737 |
|
738 |
|
739 // --------------------------------------------------------------------------- |
|
740 // Retrieves the content layout of the button. |
|
741 // --------------------------------------------------------------------------- |
|
742 // |
|
743 CAlfLayout* CFsControlButtonVisualiser::ContentLayout() |
|
744 { |
|
745 FUNC_LOG; |
|
746 return iButtonContentLayout; |
|
747 } |
|
748 |
|
749 |
|
750 // --------------------------------------------------------------------------- |
|
751 // Enables (makes visible) button. |
|
752 // --------------------------------------------------------------------------- |
|
753 // |
|
754 EXPORT_C void CFsControlButtonVisualiser::ShowL() |
|
755 { |
|
756 FUNC_LOG; |
|
757 UpdateButtonSize(); |
|
758 UpdateButtonPos(); |
|
759 |
|
760 if ( KErrNotFound == iParentLayout->FindVisual( iButtonLayout ) ) |
|
761 { |
|
762 User::LeaveIfError( iParentLayout->Append( iButtonLayout ) ); |
|
763 } |
|
764 if ( KErrNotFound == iParentLayout->FindVisual( iButtonContentLayout ) ) |
|
765 { |
|
766 TInt error( iParentLayout->Append( iButtonContentLayout ) ); |
|
767 if ( error ) |
|
768 { |
|
769 if ( KErrNotFound != iParentLayout->FindVisual( iButtonLayout ) ) |
|
770 { |
|
771 iParentLayout->Remove( iButtonLayout ); |
|
772 } |
|
773 User::Leave( error ); |
|
774 } |
|
775 } |
|
776 iVisible = ETrue; |
|
777 } |
|
778 |
|
779 |
|
780 // --------------------------------------------------------------------------- |
|
781 // Disables (hides) button. |
|
782 // --------------------------------------------------------------------------- |
|
783 // |
|
784 EXPORT_C void CFsControlButtonVisualiser::Hide() |
|
785 { |
|
786 FUNC_LOG; |
|
787 if ( !iVisible && iButtonModel->IsFocused() ) |
|
788 { |
|
789 FsGenericPanic( EFsControlButtonCannotDisableFocusedControl ); |
|
790 } |
|
791 |
|
792 TBool refresh( EFalse ); |
|
793 |
|
794 if ( KErrNotFound != iParentLayout->FindVisual( iButtonLayout ) ) |
|
795 { |
|
796 iParentLayout->Remove( iButtonLayout ); |
|
797 refresh = ETrue; |
|
798 } |
|
799 |
|
800 if ( KErrNotFound != iParentLayout->FindVisual( iButtonContentLayout ) ) |
|
801 { |
|
802 iParentLayout->Remove( iButtonContentLayout ); |
|
803 refresh = ETrue; |
|
804 } |
|
805 |
|
806 iVisible = EFalse; |
|
807 if ( refresh ) |
|
808 { |
|
809 UpdateBarLayout(); |
|
810 } |
|
811 } |
|
812 |
|
813 |
|
814 // --------------------------------------------------------------------------- |
|
815 // Checks if button is visible or hidden. |
|
816 // --------------------------------------------------------------------------- |
|
817 // |
|
818 TBool CFsControlButtonVisualiser::IsVisible() const |
|
819 { |
|
820 FUNC_LOG; |
|
821 return iVisible; |
|
822 } |
|
823 |
|
824 |
|
825 // --------------------------------------------------------------------------- |
|
826 // Changes color of text when button focused. |
|
827 // --------------------------------------------------------------------------- |
|
828 // |
|
829 EXPORT_C void CFsControlButtonVisualiser::PrepareDrawFocused() |
|
830 { |
|
831 FUNC_LOG; |
|
832 if ( iLabelFirstLine ) |
|
833 { |
|
834 TCharFormat charFormat; |
|
835 TInt styleId( KFsDefaultFontStyle ); |
|
836 |
|
837 if ( iTextStyleManager ) |
|
838 { |
|
839 ResolveCharFormat( charFormat, iLabelFirstLine ); |
|
840 charFormat.iFontPresentation.iUnderline = EUnderlineOff; |
|
841 // Use modified style if possible, otherwise use the default |
|
842 // style. |
|
843 TRAPD( leaveErr, |
|
844 styleId = iTextStyleManager->GetStyleIDL( charFormat ) ); |
|
845 if ( KErrNone == leaveErr ) |
|
846 { |
|
847 iLabelFirstLine->SetTextStyle( styleId ); |
|
848 } |
|
849 } |
|
850 iLabelFirstLine->SetColor( iButtonModel->TextColor( |
|
851 CFsControlButtonModel::EButtonFocused ) ); |
|
852 } |
|
853 |
|
854 if ( iLabelSecondLine ) |
|
855 { |
|
856 TCharFormat charFormat; |
|
857 TInt styleId( KFsDefaultFontStyle ); |
|
858 |
|
859 if ( iTextStyleManager ) |
|
860 { |
|
861 ResolveCharFormat( charFormat, iLabelSecondLine ); |
|
862 charFormat.iFontPresentation.iUnderline = EUnderlineOff; |
|
863 TRAPD( leaveErr, |
|
864 styleId = iTextStyleManager->GetStyleIDL( charFormat ) ); |
|
865 // Use modified style if possible, otherwise use the default |
|
866 // style. |
|
867 if ( KErrNone == leaveErr ) |
|
868 { |
|
869 iLabelSecondLine->SetTextStyle( styleId ); |
|
870 } |
|
871 } |
|
872 iLabelSecondLine->SetColor( iButtonModel->TextColor( |
|
873 CFsControlButtonModel::EButtonFocused ) ); |
|
874 } |
|
875 } |
|
876 |
|
877 |
|
878 // --------------------------------------------------------------------------- |
|
879 // Changes color of text when button's state is normal. |
|
880 // --------------------------------------------------------------------------- |
|
881 // |
|
882 EXPORT_C void CFsControlButtonVisualiser::PrepareDrawNormal() |
|
883 { |
|
884 FUNC_LOG; |
|
885 TCharFormat charFormat; |
|
886 |
|
887 if ( iLabelFirstLine ) |
|
888 { |
|
889 TCharFormat charFormat; |
|
890 TInt styleId( KFsDefaultFontStyle ); |
|
891 |
|
892 if ( iTextStyleManager ) |
|
893 { |
|
894 ResolveCharFormat( charFormat, iLabelFirstLine ); |
|
895 charFormat.iFontPresentation.iUnderline = EUnderlineOff; |
|
896 TRAPD( leaveErr, |
|
897 styleId = iTextStyleManager->GetStyleIDL( charFormat ) ); |
|
898 // Use modified style if possible, otherwise use the default |
|
899 // style. |
|
900 if ( KErrNone == leaveErr ) |
|
901 { |
|
902 iLabelFirstLine->SetTextStyle( styleId ); |
|
903 } |
|
904 } |
|
905 iLabelFirstLine->SetColor( iButtonModel->TextColor( |
|
906 CFsControlButtonModel::EButtonNormal ) ); |
|
907 } |
|
908 |
|
909 if ( iLabelSecondLine ) |
|
910 { |
|
911 TCharFormat charFormat; |
|
912 TInt styleId( KFsDefaultFontStyle ); |
|
913 |
|
914 if ( iTextStyleManager ) |
|
915 { |
|
916 ResolveCharFormat( charFormat, iLabelSecondLine ); |
|
917 charFormat.iFontPresentation.iUnderline = EUnderlineOff; |
|
918 TRAPD( leaveErr, |
|
919 styleId = iTextStyleManager->GetStyleIDL( charFormat ) ); |
|
920 // Use modified style if possible, otherwise use the default |
|
921 // style. |
|
922 if ( KErrNone == leaveErr ) |
|
923 { |
|
924 iLabelSecondLine->SetTextStyle( styleId ); |
|
925 } |
|
926 } |
|
927 iLabelSecondLine->SetColor( iButtonModel->TextColor( |
|
928 CFsControlButtonModel::EButtonNormal ) ); |
|
929 } |
|
930 |
|
931 if ( iIconA ) |
|
932 { |
|
933 iIconA->SetColorMode( CAlfImageVisual::EColorModulate ); |
|
934 } |
|
935 |
|
936 if ( iIconB ) |
|
937 { |
|
938 iIconB->SetColorMode( CAlfImageVisual::EColorModulate ); |
|
939 } |
|
940 } |
|
941 |
|
942 |
|
943 // --------------------------------------------------------------------------- |
|
944 // Changes color of text when button's state is dimmed. |
|
945 // --------------------------------------------------------------------------- |
|
946 // |
|
947 EXPORT_C void CFsControlButtonVisualiser::PrepareDrawDimmed() |
|
948 { |
|
949 FUNC_LOG; |
|
950 TCharFormat charFormat; |
|
951 |
|
952 if ( iLabelFirstLine ) |
|
953 { |
|
954 TCharFormat charFormat; |
|
955 TInt styleId( KFsDefaultFontStyle ); |
|
956 |
|
957 if ( iTextStyleManager ) |
|
958 { |
|
959 ResolveCharFormat( charFormat, iLabelFirstLine ); |
|
960 charFormat.iFontPresentation.iUnderline = EUnderlineOn; |
|
961 TRAPD( leaveErr, |
|
962 styleId = iTextStyleManager->GetStyleIDL( charFormat ) ); |
|
963 // Use modified style if possible, otherwise use the default |
|
964 // style. |
|
965 if ( KErrNone == leaveErr ) |
|
966 { |
|
967 iLabelFirstLine->SetTextStyle( styleId ); |
|
968 } |
|
969 } |
|
970 iLabelFirstLine->SetColor( iButtonModel->TextColor( |
|
971 CFsControlButtonModel::EButtonDimmed ) ); |
|
972 } |
|
973 |
|
974 if ( iLabelSecondLine ) |
|
975 { |
|
976 TCharFormat charFormat; |
|
977 TInt styleId( KFsDefaultFontStyle ); |
|
978 |
|
979 if ( iTextStyleManager ) |
|
980 { |
|
981 ResolveCharFormat( charFormat, iLabelSecondLine ); |
|
982 charFormat.iFontPresentation.iUnderline = EUnderlineOn; |
|
983 TRAPD( leaveErr, |
|
984 styleId = iTextStyleManager->GetStyleIDL( charFormat ) ); |
|
985 // Use modified style if possible, otherwise use the default |
|
986 // style. |
|
987 if ( KErrNone == leaveErr ) |
|
988 { |
|
989 iLabelSecondLine->SetTextStyle( styleId ); |
|
990 } |
|
991 } |
|
992 iLabelSecondLine->SetColor( iButtonModel->TextColor( |
|
993 CFsControlButtonModel::EButtonDimmed ) ); |
|
994 } |
|
995 |
|
996 if ( iIconA ) |
|
997 { |
|
998 iIconA->SetColorMode( CAlfImageVisual::EColorDimmed ); |
|
999 } |
|
1000 |
|
1001 if ( iIconB ) |
|
1002 { |
|
1003 iIconB->SetColorMode( CAlfImageVisual::EColorDimmed ); |
|
1004 } |
|
1005 } |
|
1006 |
|
1007 |
|
1008 // --------------------------------------------------------------------------- |
|
1009 // Creates needed number of rows for layout for specified button type. |
|
1010 // --------------------------------------------------------------------------- |
|
1011 // |
|
1012 EXPORT_C void CFsControlButtonVisualiser::CreateButtonVisualsL() |
|
1013 { |
|
1014 FUNC_LOG; |
|
1015 // create icon A visuals |
|
1016 if ( iButtonModel->ContainsElement( ECBElemIconA ) ) |
|
1017 { |
|
1018 iIconAContainer = |
|
1019 CAlfLayout::AddNewL( *iParent, iButtonContentLayout ); |
|
1020 iIconA = CAlfImageVisual::AddNewL( *iParent, iIconAContainer ); |
|
1021 iIconA->SetScaleMode( CAlfImageVisual::EScaleFitInside ); |
|
1022 iIconAContainer->SetClipping( ETrue ); |
|
1023 } |
|
1024 |
|
1025 // create visual for first line of text |
|
1026 if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) ) |
|
1027 { |
|
1028 iLabelFirstLine = |
|
1029 CAlfTextVisual::AddNewL( *iParent, iButtonContentLayout ); |
|
1030 iLabelFirstLine->SetAlign( EAlfAlignHLeft, EAlfAlignVCenter ); |
|
1031 iLabelFirstLine->SetPadding( |
|
1032 TPoint( iButtonModel->LabelHPadding( iButtonModel->Type() ), |
|
1033 iButtonModel->LabelVPadding( iButtonModel->Type() ) ) ); |
|
1034 } |
|
1035 |
|
1036 // create visual for second line of text |
|
1037 if ( iButtonModel->ContainsElement( ECBElemLabelSndLine ) ) |
|
1038 { |
|
1039 iLabelSecondLine = |
|
1040 CAlfTextVisual::AddNewL( *iParent, iButtonContentLayout ); |
|
1041 iLabelSecondLine->SetAlign( EAlfAlignHLeft, EAlfAlignVCenter ); |
|
1042 iLabelSecondLine->SetPadding( |
|
1043 TPoint( iButtonModel->LabelHPadding( iButtonModel->Type() ), |
|
1044 iButtonModel->LabelVPadding( iButtonModel->Type() ) ) ); |
|
1045 } |
|
1046 |
|
1047 // create icon B visuals |
|
1048 if ( iButtonModel->ContainsElement( ECBElemIconB ) ) |
|
1049 { |
|
1050 iIconBContainer = |
|
1051 CAlfLayout::AddNewL( *iParent, iButtonContentLayout ); |
|
1052 iIconB = CAlfImageVisual::AddNewL( *iParent, iIconBContainer ); |
|
1053 iIconB->SetScaleMode( CAlfImageVisual::EScaleNormal ); |
|
1054 iIconBContainer->SetClipping( ETrue ); |
|
1055 } |
|
1056 |
|
1057 // update text styles if needed (at least one text line) |
|
1058 if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) ) |
|
1059 { |
|
1060 UpdateTextStyles(); |
|
1061 } |
|
1062 } |
|
1063 |
|
1064 |
|
1065 // --------------------------------------------------------------------------- |
|
1066 // Calculates button size according to content. |
|
1067 // --------------------------------------------------------------------------- |
|
1068 // |
|
1069 EXPORT_C TInt CFsControlButtonVisualiser::CalculateButtonSize() |
|
1070 { |
|
1071 FUNC_LOG; |
|
1072 |
|
1073 if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) ) |
|
1074 { |
|
1075 // to get correct value from ExpandRectWithContent method |
|
1076 iLabelFirstLine->SetClipping( EFalse ); |
|
1077 |
|
1078 iLabelFirstLine->SetWrapping( CAlfTextVisual::ELineWrapManual ); |
|
1079 |
|
1080 // Update the text visual to get correct rect size. |
|
1081 TSize size( iLabelFirstLine->TextExtents() ); |
|
1082 TAlfRealRect padding( iLabelFirstLine->PaddingInPixels() ); |
|
1083 TRect textRect( 0, 0, |
|
1084 padding.iTl.iX + padding.iBr.iX + size.iWidth, |
|
1085 padding.iTl.iY + padding.iBr.iY + size.iHeight ); |
|
1086 |
|
1087 if ( iButtonModel->ContainsElement( ECBElemLabelSndLine ) ) |
|
1088 { |
|
1089 // to get correct value from ExpandRectWithContent method |
|
1090 iLabelSecondLine->SetClipping( EFalse ); |
|
1091 |
|
1092 iLabelSecondLine->SetWrapping( CAlfTextVisual::ELineWrapManual ); |
|
1093 |
|
1094 // Update the text visual to get correct rect size. |
|
1095 TSize size2( iLabelFirstLine->TextExtents() ); |
|
1096 TAlfRealRect padding( iLabelSecondLine->PaddingInPixels() ); |
|
1097 |
|
1098 TRect secondLineRect( 0, 0, |
|
1099 padding.iTl.iX + padding.iBr.iX + size2.iWidth, |
|
1100 padding.iTl.iY + padding.iBr.iY + size2.iHeight ); |
|
1101 |
|
1102 if ( secondLineRect.Width() > textRect.Width() ) |
|
1103 { |
|
1104 //text size |
|
1105 textRect = secondLineRect; |
|
1106 } |
|
1107 } |
|
1108 |
|
1109 // Calculate the difference compared to layout defined object. |
|
1110 TBool supportedType( ETrue ); |
|
1111 TRect parentRect = CFsControlBar::GetLayoutRect( 2 ); |
|
1112 CFsLayoutManager::TFsText text; |
|
1113 switch ( iButtonModel->Type() ) |
|
1114 { |
|
1115 case ECBTypeOneLineLabelIconB: |
|
1116 CFsLayoutManager::LayoutMetricsText( parentRect, |
|
1117 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 1 ); |
|
1118 break; |
|
1119 case ECBTypeOneLineLabelOnly: |
|
1120 CFsLayoutManager::LayoutMetricsText( parentRect, |
|
1121 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 0 ); |
|
1122 break; |
|
1123 case ECBTypeOneLineLabelIconA: |
|
1124 CFsLayoutManager::LayoutMetricsText( parentRect, |
|
1125 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 2 ); |
|
1126 break; |
|
1127 case ECBTypeOneLineLabelTwoIcons: |
|
1128 CFsLayoutManager::LayoutMetricsText( parentRect, |
|
1129 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 3 ); |
|
1130 break; |
|
1131 //case ECBTypeIconOnly: // no text item |
|
1132 case ECBTypeTwoLinesLabelOnly: |
|
1133 case ECBTypeTwoLinesLabelIconA: |
|
1134 case ECBTypeTwoLinesLabelIconB: |
|
1135 case ECBTypeTwoLinesLabelTwoIcons: |
|
1136 default: |
|
1137 supportedType = EFalse; |
|
1138 break; |
|
1139 } |
|
1140 |
|
1141 if ( supportedType ) |
|
1142 { |
|
1143 const TInt newWidth( |
|
1144 parentRect.Width() + textRect.Width() - text.iTextRect.Width() |
|
1145 ); |
|
1146 return newWidth; |
|
1147 } |
|
1148 } |
|
1149 |
|
1150 if ( iButtonModel->ContainsElement( ECBElemIconA ) ) |
|
1151 { |
|
1152 return iIconAContainer->Size().Target().iX; |
|
1153 } |
|
1154 |
|
1155 if ( iButtonModel->ContainsElement( ECBElemIconB ) ) |
|
1156 { |
|
1157 return iIconBContainer->Size().Target().iX; |
|
1158 } |
|
1159 |
|
1160 return iButtonContentLayout->Size().Target().iX; |
|
1161 } |
|
1162 |
|
1163 |
|
1164 // --------------------------------------------------------------------------- |
|
1165 // Updates position of button. |
|
1166 // --------------------------------------------------------------------------- |
|
1167 // |
|
1168 void CFsControlButtonVisualiser::UpdateButtonPos() |
|
1169 { |
|
1170 FUNC_LOG; |
|
1171 // Set position for button background and for the content. |
|
1172 iButtonLayout->SetPos( iButtonModel->TopLeftPoint() ); |
|
1173 iButtonContentLayout->SetPos( iButtonModel->TopLeftPoint() ); |
|
1174 } |
|
1175 |
|
1176 |
|
1177 // --------------------------------------------------------------------------- |
|
1178 // Updates size of columns in grid layouter for button's elements. |
|
1179 // --------------------------------------------------------------------------- |
|
1180 // |
|
1181 EXPORT_C void CFsControlButtonVisualiser::UpdateElementsSizeL( |
|
1182 TFsControlButtonType aButtonType ) |
|
1183 { |
|
1184 FUNC_LOG; |
|
1185 TRect parentRect( TPoint( 0, 0 ), iButtonModel->Size() ); |
|
1186 TRect layoutRect( 0, 0, 0, 0 ); |
|
1187 TRect iconA; |
|
1188 TRect iconB; |
|
1189 TRect text1; |
|
1190 TRect text2; |
|
1191 CFsLayoutManager::TFsText text; |
|
1192 switch ( aButtonType ) |
|
1193 { |
|
1194 case ECBTypeIconOnly: |
|
1195 iconA = iButtonModel->GetLayoutSize( parentRect ); |
|
1196 // Need to move the rect as icon doesn't have a separate button |
|
1197 // parent. It's position is related to controlbar's rect. |
|
1198 iconA.Move( -iconA.iTl.iX, -iconA.iTl.iY ); |
|
1199 break; |
|
1200 case ECBTypeOneLineLabelOnly: |
|
1201 CFsLayoutManager::LayoutMetricsText( parentRect, |
|
1202 CFsLayoutManager::ECmailDdmenuBtn01PaneT1, text, 1 ); |
|
1203 text1 = text.iTextRect; |
|
1204 break; |
|
1205 case ECBTypeOneLineLabelIconA: |
|
1206 if ( Layout_Meta_Data::IsLandscapeOrientation() ) |
|
1207 { |
|
1208 CFsLayoutManager::LayoutMetricsRect( parentRect, |
|
1209 CFsLayoutManager::ECmailDdmenuBtn02PaneG2, |
|
1210 iconA, 0 ); |
|
1211 CFsLayoutManager::LayoutMetricsText( parentRect, |
|
1212 CFsLayoutManager::ECmailDdmenuBtn02PaneT2, |
|
1213 text, 0 ); |
|
1214 } |
|
1215 else |
|
1216 { |
|
1217 CFsLayoutManager::LayoutMetricsRect( parentRect, |
|
1218 CFsLayoutManager::ECmailDdmenuBtn01PaneG1, |
|
1219 iconA, 1 ); |
|
1220 CFsLayoutManager::LayoutMetricsText( parentRect, |
|
1221 CFsLayoutManager::ECmailDdmenuBtn01PaneT1, |
|
1222 text, 0 ); |
|
1223 } |
|
1224 text1 = text.iTextRect; |
|
1225 break; |
|
1226 case ECBTypeOneLineLabelIconB: |
|
1227 CFsLayoutManager::LayoutMetricsText( parentRect, |
|
1228 CFsLayoutManager::ECmailDdmenuBtn01PaneT1, text, 1 ); |
|
1229 text1 = text.iTextRect; |
|
1230 CFsLayoutManager::LayoutMetricsRect( parentRect, |
|
1231 CFsLayoutManager::ECmailDdmenuBtn01PaneG2, |
|
1232 iconB, 2 ); |
|
1233 break; |
|
1234 case ECBTypeOneLineLabelTwoIcons: |
|
1235 CFsLayoutManager::LayoutMetricsRect( parentRect, |
|
1236 CFsLayoutManager::ECmailDdmenuBtn01PaneG1, |
|
1237 iconA, 1 ); |
|
1238 CFsLayoutManager::LayoutMetricsText( parentRect, |
|
1239 CFsLayoutManager::ECmailDdmenuBtn01PaneT1, text, 0 ); |
|
1240 text1 = text.iTextRect; |
|
1241 CFsLayoutManager::LayoutMetricsRect( parentRect, |
|
1242 CFsLayoutManager::ECmailDdmenuBtn01PaneG2, |
|
1243 iconB, 1 ); |
|
1244 break; |
|
1245 default: |
|
1246 break; |
|
1247 } |
|
1248 |
|
1249 // Buttons have different sizes so adapt the used rectangle dynamically |
|
1250 TSize buttonSize = iButtonModel->Size(); |
|
1251 buttonSize -= TPoint( KButtonBorderSize, KButtonBorderSize ); // shrink frame border size |
|
1252 |
|
1253 // If there is no text in the button, center the icon to the button |
|
1254 if( !iLabelFirstLine || iLabelFirstLine->Text().Length() == 0 ) |
|
1255 { |
|
1256 TRect oldIconRect = iconA; |
|
1257 iconA.SetRect( TPoint(( buttonSize.iWidth - oldIconRect.Width())/2, |
|
1258 oldIconRect.iTl.iY), |
|
1259 oldIconRect.Size() ); |
|
1260 } |
|
1261 if ( iButtonModel->ContainsElement( ECBElemIconA ) ) |
|
1262 { |
|
1263 const TSize& size( iconA.Size() ); |
|
1264 iIconAContainer->SetSize( size ); |
|
1265 iIconAContainer->SetPos( iconA.iTl ); |
|
1266 iIconA->SetSize( TAlfRealSize( size ) ); |
|
1267 } |
|
1268 if ( iButtonModel->ContainsElement( ECBElemIconB ) ) |
|
1269 { |
|
1270 const TSize& size( iconB.Size() ); |
|
1271 iIconBContainer->SetSize( iconB.Size() ); |
|
1272 iIconBContainer->SetPos( iconB.iTl ); |
|
1273 iIconB->SetSize( TAlfRealSize( size ) ); |
|
1274 } |
|
1275 if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) ) |
|
1276 { |
|
1277 if ( iLabelFirstLine ) |
|
1278 { |
|
1279 iLabelFirstLine->SetSize( text1.Size() ); |
|
1280 iLabelFirstLine->SetPos( text1.iTl ); |
|
1281 if ( Layout_Meta_Data::IsLandscapeOrientation() ) |
|
1282 { |
|
1283 iLabelFirstLine->SetAlign( EAlfAlignHCenter, EAlfAlignVCenter ); |
|
1284 } |
|
1285 else |
|
1286 { |
|
1287 iLabelFirstLine->SetAlign( EAlfAlignHLocale, EAlfAlignVCenter ); |
|
1288 } |
|
1289 } |
|
1290 } |
|
1291 if ( iButtonModel->ContainsElement( ECBElemLabelSndLine ) ) |
|
1292 { |
|
1293 iLabelSecondLine->SetSize( text2.Size() ); |
|
1294 iLabelSecondLine->SetPos( text2.iTl ); |
|
1295 } |
|
1296 // </cmail> Platform layout changes |
|
1297 } |
|
1298 |
|
1299 |
|
1300 // --------------------------------------------------------------------------- |
|
1301 // Sets text styles for specified button type. |
|
1302 // --------------------------------------------------------------------------- |
|
1303 // |
|
1304 EXPORT_C void CFsControlButtonVisualiser::UpdateTextStyles() |
|
1305 { |
|
1306 FUNC_LOG; |
|
1307 TInt style( KFsDefaultFontStyle ); |
|
1308 TBool sizeChanged( EFalse ); |
|
1309 |
|
1310 TCharFormat charFormat; |
|
1311 ResolveCharFormat( charFormat, iLabelFirstLine ); |
|
1312 |
|
1313 if ( !iTextHeightSet ) |
|
1314 { |
|
1315 TRect parentRect( |
|
1316 TPoint( 0, 0 ), iButtonContentLayout->Size().Target() ); |
|
1317 CFsLayoutManager::TFsText text; |
|
1318 CFsLayoutManager::LayoutMetricsText( parentRect, |
|
1319 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 1 ); |
|
1320 |
|
1321 charFormat.iFontSpec = text.iFont->FontSpecInTwips(); |
|
1322 } |
|
1323 else |
|
1324 { |
|
1325 CWsScreenDevice* screenDev( CCoeEnv::Static()->ScreenDevice() ); |
|
1326 |
|
1327 // Modify the height of the font. |
|
1328 TInt twips( screenDev->VerticalPixelsToTwips( iTextHeight ) ); |
|
1329 if ( 0 < iTextHeight && twips != charFormat.iFontSpec.iHeight ) |
|
1330 { |
|
1331 charFormat.iFontSpec.iHeight = twips; |
|
1332 sizeChanged = ETrue; |
|
1333 } |
|
1334 } |
|
1335 |
|
1336 if ( iTextStyleManager ) |
|
1337 { |
|
1338 // Use default style in case of a leave. |
|
1339 TRAP_IGNORE( style = iTextStyleManager->GetStyleIDL( charFormat ) ); |
|
1340 } |
|
1341 |
|
1342 if ( iLabelFirstLine ) |
|
1343 { |
|
1344 iLabelFirstLine->SetTextStyle( style ); |
|
1345 } |
|
1346 |
|
1347 if ( iLabelSecondLine ) |
|
1348 { |
|
1349 iLabelSecondLine->SetTextStyle( style ); |
|
1350 } |
|
1351 |
|
1352 if ( sizeChanged ) |
|
1353 { |
|
1354 UpdateButtonSize(); |
|
1355 } |
|
1356 } |
|
1357 |
|
1358 |
|
1359 // --------------------------------------------------------------------------- |
|
1360 // Sets alignement of specified image of the button. |
|
1361 // --------------------------------------------------------------------------- |
|
1362 // |
|
1363 EXPORT_C void CFsControlButtonVisualiser::SetImageAlign( |
|
1364 CAlfImageVisual* aImage, |
|
1365 TAlfAlignHorizontal aHAlign, |
|
1366 TAlfAlignVertical aVAlign ) |
|
1367 { |
|
1368 FUNC_LOG; |
|
1369 TInt iconWidth( aImage->Size().Target().iX ); |
|
1370 TInt iconHeight( aImage->Size().Target().iY ); |
|
1371 |
|
1372 TAlfTimedPoint startPoint( 0, 0 ); |
|
1373 TInt layoutWidth; |
|
1374 TInt layoutHeight; |
|
1375 |
|
1376 if ( aImage == iIconB ) |
|
1377 { |
|
1378 layoutWidth = iIconBContainer->Size().Target().iX; |
|
1379 layoutHeight = iIconBContainer->Size().Target().iY; |
|
1380 } |
|
1381 else if ( aImage == iIconA ) |
|
1382 { |
|
1383 layoutWidth = iIconAContainer->Size().Target().iX; |
|
1384 layoutHeight = iIconAContainer->Size().Target().iY; |
|
1385 } |
|
1386 else |
|
1387 { |
|
1388 return; |
|
1389 } |
|
1390 |
|
1391 switch ( aHAlign ) |
|
1392 { |
|
1393 case EAlfAlignHLeft: |
|
1394 { |
|
1395 startPoint.iX = 0; |
|
1396 break; |
|
1397 } |
|
1398 |
|
1399 case EAlfAlignHCenter: |
|
1400 { |
|
1401 startPoint.iX = layoutWidth / 2 - iconWidth / 2; |
|
1402 break; |
|
1403 } |
|
1404 |
|
1405 case EAlfAlignHRight: |
|
1406 { |
|
1407 startPoint.iX = layoutWidth - iconWidth; |
|
1408 break; |
|
1409 } |
|
1410 |
|
1411 default: |
|
1412 { |
|
1413 FsGenericPanic( EFsControlButtonEnumValueNotSupported ); |
|
1414 break; |
|
1415 } |
|
1416 } |
|
1417 |
|
1418 switch ( aVAlign ) |
|
1419 { |
|
1420 case EAlfAlignVTop: |
|
1421 { |
|
1422 startPoint.iY = 0; |
|
1423 break; |
|
1424 } |
|
1425 |
|
1426 case EAlfAlignVCenter: |
|
1427 { |
|
1428 startPoint.iY = layoutHeight / 2 - iconHeight / 2; |
|
1429 break; |
|
1430 } |
|
1431 |
|
1432 case EAlfAlignVBottom: |
|
1433 { |
|
1434 startPoint.iY = layoutHeight - iconHeight; |
|
1435 break; |
|
1436 } |
|
1437 |
|
1438 default: |
|
1439 { |
|
1440 FsGenericPanic( EFsControlButtonEnumValueNotSupported ); |
|
1441 break; |
|
1442 } |
|
1443 } |
|
1444 |
|
1445 aImage->SetPos( startPoint ); |
|
1446 } |
|
1447 |
|
1448 |
|
1449 // --------------------------------------------------------------------------- |
|
1450 // Sets alignment of specified text of the button. |
|
1451 // --------------------------------------------------------------------------- |
|
1452 // |
|
1453 EXPORT_C void CFsControlButtonVisualiser::SetTextAlign( |
|
1454 CAlfTextVisual* aText, |
|
1455 TAlfAlignHorizontal aHAlign, |
|
1456 TAlfAlignVertical aVAlign ) |
|
1457 { |
|
1458 FUNC_LOG; |
|
1459 aText->SetAlign( aHAlign, aVAlign ); |
|
1460 } |
|
1461 |
|
1462 |
|
1463 // --------------------------------------------------------------------------- |
|
1464 // Set new height for the button text. |
|
1465 // --------------------------------------------------------------------------- |
|
1466 // |
|
1467 EXPORT_C void CFsControlButtonVisualiser::SetTextHeight( |
|
1468 const TInt aTextHeight ) |
|
1469 { |
|
1470 FUNC_LOG; |
|
1471 iTextHeight = aTextHeight; |
|
1472 // Use default text height if the value is zero or negative. |
|
1473 iTextHeightSet = ( 0 < iTextHeight ); |
|
1474 |
|
1475 // Update text styles if needed (at least one text line) |
|
1476 if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) ) |
|
1477 { |
|
1478 UpdateTextStyles(); |
|
1479 UpdateButtonSize(); |
|
1480 } |
|
1481 } |
|
1482 |
|
1483 |
|
1484 // --------------------------------------------------------------------------- |
|
1485 // Change the current font. |
|
1486 // --------------------------------------------------------------------------- |
|
1487 // |
|
1488 EXPORT_C void CFsControlButtonVisualiser::SetTextFontL( |
|
1489 const TFontSpec& aFontSpec ) |
|
1490 { |
|
1491 FUNC_LOG; |
|
1492 if ( !iButtonModel->ContainsElement( ECBElemLabelFirstLine ) ) |
|
1493 { |
|
1494 User::Leave( KErrNotSupported ); |
|
1495 } |
|
1496 |
|
1497 if ( !iTextFontSpec ) |
|
1498 { |
|
1499 iTextFontSpec = new( ELeave )TFontSpec(); |
|
1500 } |
|
1501 |
|
1502 *iTextFontSpec = aFontSpec; |
|
1503 |
|
1504 // Update text styles. |
|
1505 Refresh(); |
|
1506 } |
|
1507 |
|
1508 |
|
1509 // --------------------------------------------------------------------------- |
|
1510 // Sets parent layout. |
|
1511 // --------------------------------------------------------------------------- |
|
1512 // |
|
1513 void CFsControlButtonVisualiser::SetParentLayoutL( |
|
1514 CAlfDeckLayout* aParentLayout ) |
|
1515 { |
|
1516 FUNC_LOG; |
|
1517 iParentLayout = aParentLayout; |
|
1518 |
|
1519 if ( iButtonLayout |
|
1520 && KErrNotFound == iParentLayout->FindVisual( iButtonLayout ) ) |
|
1521 { |
|
1522 User::LeaveIfError( iParentLayout->Append( iButtonLayout ) ); |
|
1523 } |
|
1524 if ( iButtonContentLayout |
|
1525 && KErrNotFound == iParentLayout->FindVisual( iButtonContentLayout ) ) |
|
1526 { |
|
1527 User::LeaveIfError( iParentLayout->Append( iButtonContentLayout ) ); |
|
1528 } |
|
1529 } |
|
1530 |
|
1531 |
|
1532 // --------------------------------------------------------------------------- |
|
1533 // Sets parent control. |
|
1534 // --------------------------------------------------------------------------- |
|
1535 // |
|
1536 void CFsControlButtonVisualiser::SetParentControlL( |
|
1537 CAlfControl* aParentControl ) |
|
1538 { |
|
1539 FUNC_LOG; |
|
1540 // There could be an existing observer available on previously used |
|
1541 // visualiser. |
|
1542 if ( iParent ) |
|
1543 { |
|
1544 iParent->Env().TextureManager().RemoveLoadObserver( this ); |
|
1545 } |
|
1546 |
|
1547 iParent = aParentControl; |
|
1548 ConstructL(); |
|
1549 } |
|
1550 |
|
1551 |
|
1552 // --------------------------------------------------------------------------- |
|
1553 // Set text style manager object. |
|
1554 // --------------------------------------------------------------------------- |
|
1555 // |
|
1556 void CFsControlButtonVisualiser::SetTextStyleManager( |
|
1557 CFsTextStyleManager* aTextStyleManager ) |
|
1558 { |
|
1559 FUNC_LOG; |
|
1560 iTextStyleManager = aTextStyleManager; |
|
1561 } |
|
1562 |
|
1563 |
|
1564 // --------------------------------------------------------------------------- |
|
1565 // Updates bar layout. |
|
1566 // --------------------------------------------------------------------------- |
|
1567 // |
|
1568 void CFsControlButtonVisualiser::UpdateBarLayout() |
|
1569 { |
|
1570 FUNC_LOG; |
|
1571 if ( iParentLayout ) |
|
1572 { |
|
1573 // This flag is cleared when the layout is updated. |
|
1574 iParentLayout->UpdateChildrenLayout(); |
|
1575 } |
|
1576 } |
|
1577 |
|
1578 |
|
1579 // --------------------------------------------------------------------------- |
|
1580 // Resolve the character format from current text visual. |
|
1581 // --------------------------------------------------------------------------- |
|
1582 // |
|
1583 void CFsControlButtonVisualiser::ResolveCharFormat( |
|
1584 TCharFormat& aCharFormat, |
|
1585 CAlfTextVisual* aTextVisual ) |
|
1586 { |
|
1587 FUNC_LOG; |
|
1588 // Get the current text style by text style id. |
|
1589 CAlfTextStyle* textStyle( |
|
1590 aTextVisual->Env().TextStyleManager().TextStyle( |
|
1591 aTextVisual->Style() ) ); |
|
1592 |
|
1593 // Copy the used format. |
|
1594 |
|
1595 if ( iTextFontSpec ) |
|
1596 { |
|
1597 aCharFormat.iFontSpec = *iTextFontSpec; |
|
1598 } |
|
1599 else |
|
1600 { |
|
1601 TRect parentRect( |
|
1602 TPoint( 0, 0 ), iButtonContentLayout->Size().Target() ); |
|
1603 CFsLayoutManager::TFsText text; |
|
1604 |
|
1605 // Specify button's type to get related font. |
|
1606 TInt variety( 0 ); |
|
1607 switch ( iButtonModel->Type() ) |
|
1608 { |
|
1609 case ECBTypeOneLineLabelOnly: |
|
1610 variety = 0; |
|
1611 break; |
|
1612 case ECBTypeOneLineLabelIconB: |
|
1613 variety = 1; |
|
1614 break; |
|
1615 case ECBTypeOneLineLabelIconA: |
|
1616 variety = 2; |
|
1617 break; |
|
1618 case ECBTypeOneLineLabelTwoIcons: |
|
1619 variety = 3; |
|
1620 break; |
|
1621 default: |
|
1622 break; |
|
1623 } |
|
1624 CFsLayoutManager::LayoutMetricsText( parentRect, |
|
1625 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, variety ); |
|
1626 |
|
1627 aCharFormat.iFontSpec = text.iFont->FontSpecInTwips(); |
|
1628 //alf migration - Might need iFontStyle to be set. |
|
1629 } |
|
1630 aCharFormat.iFontPresentation.iStrikethrough = |
|
1631 textStyle->IsStrikeThrough() ? EStrikethroughOn : EStrikethroughOff; |
|
1632 aCharFormat.iFontPresentation.iUnderline = |
|
1633 textStyle->IsUnderline() ? EUnderlineOn : EUnderlineOff; |
|
1634 } |