|
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: Model class for Control Button component. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "emailtrace.h" |
|
21 #include <AknsUtils.h> |
|
22 //<cmail> SF |
|
23 #include <alf/alflayout.h> |
|
24 //</cmail> |
|
25 #include "fscontrolbuttonmodel.h" |
|
26 #include "fsgenericpanic.h" |
|
27 #include "fslayoutmanager.h" |
|
28 #include "fscontrolbar.h" |
|
29 |
|
30 const TInt KDefaultLabelHPadding1 = 4; |
|
31 const TInt KDefaultLabelHPadding2 = 4; |
|
32 const TInt KDefaultLabelVPadding1 = 2; |
|
33 const TInt KDefaultLabelVPadding2 = 0; |
|
34 |
|
35 // Number of layout defined button postions on controlbar. |
|
36 const TInt KMaxButtonLayoutItems = 4; |
|
37 |
|
38 |
|
39 // ======== MEMBER FUNCTIONS ======== |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // Constructor. |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CFsControlButtonModel::CFsControlButtonModel( |
|
46 TInt aId, |
|
47 TFsControlButtonType aType, |
|
48 const TRect& aStartPoint, |
|
49 CAlfLayout& aParentLayout ) : |
|
50 iType( aType ), |
|
51 iId( aId ), |
|
52 iFocused( EFalse ), |
|
53 iLabelHPadding1( KDefaultLabelHPadding1 ), |
|
54 iLabelHPadding2( KDefaultLabelHPadding2 ), |
|
55 iLabelVPadding1( KDefaultLabelVPadding1 ), |
|
56 iLabelVPadding2( KDefaultLabelVPadding2 ), |
|
57 iStartPoint( aStartPoint.iTl ), |
|
58 iDimmed( EFalse ), |
|
59 iSizeChanged( EFalse ), |
|
60 iAutoPosition( ETrue ), |
|
61 iPosChanged( EFalse ), |
|
62 iSize( aStartPoint.Size() ), |
|
63 iAutoSizeMode( MFsControlButtonInterface::EFsLayout ), |
|
64 iParentLayout( aParentLayout ), |
|
65 iLayoutPos( 0 ), |
|
66 iUseLayoutData( ETrue ) |
|
67 { |
|
68 FUNC_LOG; |
|
69 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), iColorFocused, |
|
70 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG2 ); |
|
71 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), iColorNormal, |
|
72 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG7 ); |
|
73 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), iColorDimmed, |
|
74 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG61 ); |
|
75 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), iColorBackground, |
|
76 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG21 ); |
|
77 } |
|
78 |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // Second phase constructor. |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 void CFsControlButtonModel::ConstructL() |
|
85 { |
|
86 FUNC_LOG; |
|
87 } |
|
88 |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // Two-phased constructor. |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 CFsControlButtonModel* CFsControlButtonModel::NewL( |
|
95 TInt aId, |
|
96 TFsControlButtonType aType, |
|
97 const TRect& aRect, |
|
98 CAlfLayout& aParentLayout ) |
|
99 { |
|
100 FUNC_LOG; |
|
101 CFsControlButtonModel* self( |
|
102 new( ELeave )CFsControlButtonModel( |
|
103 aId, aType, aRect, aParentLayout ) ); |
|
104 CleanupStack::PushL( self ); |
|
105 self->ConstructL(); |
|
106 CleanupStack::Pop( self ); |
|
107 return self; |
|
108 } |
|
109 |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // Destructor. |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 CFsControlButtonModel::~CFsControlButtonModel() |
|
116 { |
|
117 FUNC_LOG; |
|
118 delete iFirstTextLine; |
|
119 delete iSecondTextLine; |
|
120 } |
|
121 |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // Sets id of the button. |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 void CFsControlButtonModel::SetId( TInt aId ) |
|
128 { |
|
129 FUNC_LOG; |
|
130 iId = aId; |
|
131 } |
|
132 |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // Retrieves button's id. |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 TInt CFsControlButtonModel::Id() |
|
139 { |
|
140 FUNC_LOG; |
|
141 return iId; |
|
142 } |
|
143 |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // Sets type of the button. |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void CFsControlButtonModel::SetType( TFsControlButtonType aType ) |
|
150 { |
|
151 FUNC_LOG; |
|
152 iType = aType; |
|
153 } |
|
154 |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // Retrieves button's type. |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 TFsControlButtonType CFsControlButtonModel::Type() |
|
161 { |
|
162 FUNC_LOG; |
|
163 return iType; |
|
164 } |
|
165 |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // Stores text for first line. Allocates or realocates memory |
|
169 // for specified text. |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CFsControlButtonModel::SetTextL( |
|
173 const TDesC& aLabel, |
|
174 MFsControlButtonInterface::TFsButtonContent aContent ) |
|
175 { |
|
176 FUNC_LOG; |
|
177 switch ( aContent ) |
|
178 { |
|
179 case MFsControlButtonInterface::EFsButtonFirstLine: |
|
180 delete iFirstTextLine; |
|
181 iFirstTextLine = NULL; |
|
182 iFirstTextLine = aLabel.AllocL(); |
|
183 break; |
|
184 |
|
185 case MFsControlButtonInterface::EFsButtonSecondLine: |
|
186 delete iSecondTextLine; |
|
187 iSecondTextLine = NULL; |
|
188 iSecondTextLine = aLabel.AllocL(); |
|
189 break; |
|
190 |
|
191 default: |
|
192 FsGenericPanic( EFsControlButtonIncorrectButtonType ); |
|
193 User::Leave( KErrNotSupported ); |
|
194 break; |
|
195 } |
|
196 } |
|
197 |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // Change the color of defined target. |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 void CFsControlButtonModel::SetTextColor( |
|
204 const TRgb& aColor, |
|
205 TFsButtonStateType aType ) |
|
206 { |
|
207 FUNC_LOG; |
|
208 switch ( aType ) |
|
209 { |
|
210 case EButtonNormal: |
|
211 iColorNormal = aColor; |
|
212 break; |
|
213 case EButtonFocused: |
|
214 iColorFocused = aColor; |
|
215 break; |
|
216 case EButtonDimmed: |
|
217 iColorDimmed = aColor; |
|
218 break; |
|
219 case EButtonBackground: |
|
220 iColorBackground = aColor; |
|
221 break; |
|
222 default: |
|
223 break; |
|
224 } |
|
225 } |
|
226 |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // Retrieves the requested target color. |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 const TRgb& CFsControlButtonModel::TextColor( TFsButtonStateType aType ) const |
|
233 { |
|
234 FUNC_LOG; |
|
235 const TRgb* retVal( NULL ); |
|
236 switch ( aType ) |
|
237 { |
|
238 case EButtonNormal: |
|
239 retVal = &iColorNormal; |
|
240 break; |
|
241 case EButtonBackground: |
|
242 retVal = &iColorBackground; |
|
243 break; |
|
244 case EButtonFocused: |
|
245 retVal = &iColorFocused; |
|
246 break; |
|
247 case EButtonDimmed: |
|
248 retVal = &iColorDimmed; |
|
249 break; |
|
250 default: |
|
251 break; |
|
252 } |
|
253 return *retVal; |
|
254 } |
|
255 |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // Retrieves first line of button's text. |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 TPtrC CFsControlButtonModel::Text( |
|
262 MFsControlButtonInterface::TFsButtonContent aContent ) |
|
263 { |
|
264 FUNC_LOG; |
|
265 TPtrC retVal; |
|
266 |
|
267 switch ( aContent ) |
|
268 { |
|
269 case MFsControlButtonInterface::EFsButtonFirstLine: |
|
270 if( !ContainsElement( ECBElemLabelFirstLine ) ) |
|
271 { |
|
272 FsGenericPanic( EFsControlButtonIncorrectButtonType ); |
|
273 } |
|
274 else |
|
275 { |
|
276 retVal.Set( iFirstTextLine->Des() ); |
|
277 } |
|
278 break; |
|
279 |
|
280 case MFsControlButtonInterface::EFsButtonSecondLine: |
|
281 if( !ContainsElement( ECBElemLabelSndLine ) ) |
|
282 { |
|
283 FsGenericPanic( EFsControlButtonIncorrectButtonType ); |
|
284 } |
|
285 else |
|
286 { |
|
287 retVal.Set( iSecondTextLine->Des() ); |
|
288 } |
|
289 break; |
|
290 |
|
291 default: |
|
292 FsGenericPanic( EFsControlButtonIncorrectButtonType ); |
|
293 break; |
|
294 } |
|
295 |
|
296 return retVal; |
|
297 } |
|
298 |
|
299 |
|
300 // --------------------------------------------------------------------------- |
|
301 // Retireves horizontal padding for text in button. |
|
302 // --------------------------------------------------------------------------- |
|
303 // |
|
304 TInt CFsControlButtonModel::LabelHPadding( |
|
305 TFsControlButtonType aType ) const |
|
306 { |
|
307 FUNC_LOG; |
|
308 TInt retVal( 0 ); |
|
309 switch ( aType ) |
|
310 { |
|
311 case ECBTypeOneLineLabelOnly: |
|
312 case ECBTypeOneLineLabelIconA: |
|
313 case ECBTypeOneLineLabelIconB: |
|
314 case ECBTypeOneLineLabelTwoIcons: |
|
315 retVal = iLabelHPadding1; |
|
316 break; |
|
317 |
|
318 case ECBTypeTwoLinesLabelOnly: |
|
319 case ECBTypeTwoLinesLabelIconA: |
|
320 case ECBTypeTwoLinesLabelIconB: |
|
321 case ECBTypeTwoLinesLabelTwoIcons: |
|
322 retVal = iLabelHPadding2; |
|
323 break; |
|
324 |
|
325 default: |
|
326 break; |
|
327 } |
|
328 return retVal; |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------------------------- |
|
332 // Retireves vertical padding for text in button. |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 TInt CFsControlButtonModel::LabelVPadding( |
|
336 TFsControlButtonType aType ) const |
|
337 { |
|
338 FUNC_LOG; |
|
339 TInt retVal( 0 ); |
|
340 switch ( aType ) |
|
341 { |
|
342 case ECBTypeOneLineLabelOnly: |
|
343 case ECBTypeOneLineLabelIconA: |
|
344 case ECBTypeOneLineLabelIconB: |
|
345 case ECBTypeOneLineLabelTwoIcons: |
|
346 retVal = iLabelVPadding1; |
|
347 break; |
|
348 |
|
349 case ECBTypeTwoLinesLabelOnly: |
|
350 case ECBTypeTwoLinesLabelIconA: |
|
351 case ECBTypeTwoLinesLabelIconB: |
|
352 case ECBTypeTwoLinesLabelTwoIcons: |
|
353 retVal = iLabelVPadding2; |
|
354 break; |
|
355 |
|
356 default: |
|
357 break; |
|
358 } |
|
359 return retVal; |
|
360 } |
|
361 |
|
362 |
|
363 // --------------------------------------------------------------------------- |
|
364 // Sets width of the button. |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 void CFsControlButtonModel::SetWidth( TInt aWidth ) |
|
368 { |
|
369 FUNC_LOG; |
|
370 TInt width( iSize.iWidth ); |
|
371 |
|
372 if ( iSize.iWidth != aWidth ) |
|
373 { |
|
374 iSizeChanged = ETrue; |
|
375 } |
|
376 iSize.iWidth = aWidth; |
|
377 |
|
378 if ( MFsControlButtonInterface::EFsLayout != AutoSizeMode() |
|
379 && CFsLayoutManager::IsMirrored() ) |
|
380 { |
|
381 TPoint pos( TopLeftPoint() ); |
|
382 pos.iX = pos.iX - Size().iWidth + width; |
|
383 SetPos( pos, EFalse ); |
|
384 } |
|
385 } |
|
386 |
|
387 |
|
388 // --------------------------------------------------------------------------- |
|
389 // Set size for the button. |
|
390 // --------------------------------------------------------------------------- |
|
391 // |
|
392 void CFsControlButtonModel::SetSize( TSize aSize ) |
|
393 { |
|
394 FUNC_LOG; |
|
395 if ( iSize != aSize ) |
|
396 { |
|
397 iSizeChanged = ETrue; |
|
398 } |
|
399 iSize = aSize; |
|
400 } |
|
401 |
|
402 |
|
403 // --------------------------------------------------------------------------- |
|
404 // Retrieves the size of the button. |
|
405 // --------------------------------------------------------------------------- |
|
406 // |
|
407 const TSize& CFsControlButtonModel::Size() const |
|
408 { |
|
409 FUNC_LOG; |
|
410 return iSize; |
|
411 } |
|
412 |
|
413 |
|
414 // --------------------------------------------------------------------------- |
|
415 // Set auto size mode for button. |
|
416 // Defines how the buttons size is changed. |
|
417 // --------------------------------------------------------------------------- |
|
418 // |
|
419 void CFsControlButtonModel::SetAutoSizeMode( |
|
420 MFsControlButtonInterface::TFsAutoSizeMode aAutoSizeMode ) |
|
421 { |
|
422 FUNC_LOG; |
|
423 if ( iAutoSizeMode != aAutoSizeMode ) |
|
424 { |
|
425 iSizeChanged = ETrue; |
|
426 iAutoSizeMode = aAutoSizeMode; |
|
427 |
|
428 // Update manual position |
|
429 iManualSetPos = TopLeftPoint(); |
|
430 if ( CFsLayoutManager::IsMirrored() ) |
|
431 { |
|
432 iManualSetPos.iX = iParentLayout.Size().Target().iX |
|
433 - iManualSetPos.iX - Size().iWidth; |
|
434 } |
|
435 } |
|
436 } |
|
437 |
|
438 |
|
439 // --------------------------------------------------------------------------- |
|
440 // Resolve the current mode. |
|
441 // --------------------------------------------------------------------------- |
|
442 // |
|
443 MFsControlButtonInterface::TFsAutoSizeMode |
|
444 CFsControlButtonModel::AutoSizeMode() |
|
445 { |
|
446 return iAutoSizeMode; |
|
447 } |
|
448 |
|
449 |
|
450 // --------------------------------------------------------------------------- |
|
451 // Sets focus to control button. |
|
452 // --------------------------------------------------------------------------- |
|
453 // |
|
454 void CFsControlButtonModel::SetFocus( TBool aState ) |
|
455 { |
|
456 FUNC_LOG; |
|
457 iFocused = aState; |
|
458 } |
|
459 |
|
460 |
|
461 // --------------------------------------------------------------------------- |
|
462 // Checks if button has focus. |
|
463 // --------------------------------------------------------------------------- |
|
464 // |
|
465 TBool CFsControlButtonModel::IsFocused() |
|
466 { |
|
467 FUNC_LOG; |
|
468 return iFocused; |
|
469 } |
|
470 |
|
471 |
|
472 // --------------------------------------------------------------------------- |
|
473 // Sets dimmed state of control button. |
|
474 // --------------------------------------------------------------------------- |
|
475 // |
|
476 void CFsControlButtonModel::SetDimmed( TBool aDimmed ) |
|
477 { |
|
478 FUNC_LOG; |
|
479 iDimmed = aDimmed; |
|
480 } |
|
481 |
|
482 |
|
483 // --------------------------------------------------------------------------- |
|
484 // Checks if button is dimmed (read only). |
|
485 // --------------------------------------------------------------------------- |
|
486 // |
|
487 TBool CFsControlButtonModel::IsDimmed() |
|
488 { |
|
489 FUNC_LOG; |
|
490 return iDimmed; |
|
491 } |
|
492 |
|
493 |
|
494 // --------------------------------------------------------------------------- |
|
495 // Sets icon in the button. |
|
496 // --------------------------------------------------------------------------- |
|
497 // |
|
498 void CFsControlButtonModel::SetIconL( |
|
499 CAlfTexture& aIcon, |
|
500 TFsControlButtonElem aElemType ) |
|
501 { |
|
502 FUNC_LOG; |
|
503 if( !ContainsElement( aElemType ) ) |
|
504 { |
|
505 FsGenericPanic( EFsControlButtonIncorrectButtonType ); |
|
506 User::Leave( KErrNotSupported ); |
|
507 } |
|
508 |
|
509 if ( aElemType == ECBElemIconA ) |
|
510 { |
|
511 iIconA = &aIcon; |
|
512 } |
|
513 else |
|
514 { |
|
515 iIconB = &aIcon; |
|
516 } |
|
517 } |
|
518 |
|
519 |
|
520 // --------------------------------------------------------------------------- |
|
521 // Retrieves specified icon image. |
|
522 // --------------------------------------------------------------------------- |
|
523 // |
|
524 CAlfTexture* CFsControlButtonModel::Icon( TFsControlButtonElem aElemType ) |
|
525 { |
|
526 FUNC_LOG; |
|
527 CAlfTexture* result( NULL ); |
|
528 |
|
529 if( !ContainsElement( aElemType ) ) |
|
530 { |
|
531 FsGenericPanic( EFsControlButtonIncorrectButtonType ); |
|
532 } |
|
533 else if ( aElemType == ECBElemIconA ) |
|
534 { |
|
535 result = iIconA; |
|
536 } |
|
537 else |
|
538 { |
|
539 result = iIconB; |
|
540 } |
|
541 |
|
542 return result; |
|
543 } |
|
544 |
|
545 // <cmail> Platform layout changes |
|
546 // --------------------------------------------------------------------------- |
|
547 // Sets position of the button. |
|
548 // --------------------------------------------------------------------------- |
|
549 // |
|
550 void CFsControlButtonModel::SetPos( const TPoint& aTlPoint, TBool aClearFlag ) |
|
551 { |
|
552 FUNC_LOG; |
|
553 if ( iStartPoint != aTlPoint ) |
|
554 { |
|
555 iPosChanged = ETrue; |
|
556 } |
|
557 iStartPoint = aTlPoint; |
|
558 if ( aClearFlag ) |
|
559 { |
|
560 iAutoPosition = EFalse; |
|
561 iManualSetPos = aTlPoint; |
|
562 } |
|
563 } |
|
564 // <cmail> Platform layout changes |
|
565 |
|
566 |
|
567 // --------------------------------------------------------------------------- |
|
568 // Retrieves top left point of the button. |
|
569 // --------------------------------------------------------------------------- |
|
570 // |
|
571 TPoint CFsControlButtonModel::TopLeftPoint() |
|
572 { |
|
573 FUNC_LOG; |
|
574 return iStartPoint; |
|
575 } |
|
576 |
|
577 |
|
578 // --------------------------------------------------------------------------- |
|
579 // Checks if current set button type contains specified icon type. |
|
580 // --------------------------------------------------------------------------- |
|
581 // |
|
582 TBool CFsControlButtonModel::ContainsElement( TFsControlButtonElem aWhich ) |
|
583 { |
|
584 FUNC_LOG; |
|
585 TBool result( EFalse ); |
|
586 |
|
587 switch ( aWhich ) |
|
588 { |
|
589 case ECBElemIconA: |
|
590 { |
|
591 if ( iType == ECBTypeIconOnly |
|
592 || iType == ECBTypeOneLineLabelIconA |
|
593 || iType == ECBTypeOneLineLabelTwoIcons |
|
594 || iType == ECBTypeTwoLinesLabelIconA |
|
595 || iType == ECBTypeOneLineLabelTwoIcons |
|
596 || iType == ECBTypeTwoLinesLabelTwoIcons ) |
|
597 { |
|
598 result = ETrue; |
|
599 } |
|
600 break; |
|
601 } |
|
602 |
|
603 case ECBElemIconB: |
|
604 { |
|
605 if ( iType == ECBTypeOneLineLabelIconB |
|
606 || iType == ECBTypeOneLineLabelTwoIcons |
|
607 || iType == ECBTypeTwoLinesLabelIconB |
|
608 || iType == ECBTypeTwoLinesLabelTwoIcons ) |
|
609 { |
|
610 result = ETrue; |
|
611 } |
|
612 break; |
|
613 } |
|
614 |
|
615 case ECBElemLabelFirstLine: |
|
616 { |
|
617 if ( iType != ECBTypeIconOnly ) |
|
618 { |
|
619 result = ETrue; |
|
620 } |
|
621 break; |
|
622 } |
|
623 |
|
624 case ECBElemLabelSndLine: |
|
625 { |
|
626 if ( iType == ECBTypeTwoLinesLabelOnly |
|
627 || iType == ECBTypeTwoLinesLabelIconA |
|
628 || iType == ECBTypeTwoLinesLabelIconB |
|
629 || iType == ECBTypeTwoLinesLabelTwoIcons ) |
|
630 { |
|
631 result = ETrue; |
|
632 } |
|
633 break; |
|
634 } |
|
635 |
|
636 default: |
|
637 { |
|
638 FsGenericPanic( EFsControlButtonIncorrectButtonElement ); |
|
639 break; |
|
640 } |
|
641 } |
|
642 |
|
643 return result; |
|
644 } |
|
645 |
|
646 |
|
647 // --------------------------------------------------------------------------- |
|
648 // Checks if size of button was changed. |
|
649 // --------------------------------------------------------------------------- |
|
650 // |
|
651 TBool CFsControlButtonModel::ButtonSizeChanged() |
|
652 { |
|
653 FUNC_LOG; |
|
654 TBool result( iSizeChanged ); |
|
655 iSizeChanged = EFalse; |
|
656 return result; |
|
657 } |
|
658 |
|
659 |
|
660 // --------------------------------------------------------------------------- |
|
661 // Checks if position of button was changed. |
|
662 // --------------------------------------------------------------------------- |
|
663 // |
|
664 TBool CFsControlButtonModel::ButtonPosChanged() |
|
665 { |
|
666 FUNC_LOG; |
|
667 TBool result( iPosChanged ); |
|
668 iPosChanged = EFalse; |
|
669 return result; |
|
670 } |
|
671 |
|
672 |
|
673 // --------------------------------------------------------------------------- |
|
674 // Checks if button should be automatically positioned. |
|
675 // --------------------------------------------------------------------------- |
|
676 // |
|
677 TBool CFsControlButtonModel::AutoPosition() |
|
678 { |
|
679 FUNC_LOG; |
|
680 return iAutoPosition; |
|
681 } |
|
682 |
|
683 |
|
684 // --------------------------------------------------------------------------- |
|
685 // Resolve the button's size from layout. |
|
686 // --------------------------------------------------------------------------- |
|
687 // |
|
688 TSize CFsControlButtonModel::GetLayoutSize() |
|
689 { |
|
690 FUNC_LOG; |
|
691 TRect parentRect( TPoint( 0, 0 ), iParentLayout.Size().Target() ); |
|
692 return GetLayoutSize( parentRect ); |
|
693 } |
|
694 |
|
695 |
|
696 // --------------------------------------------------------------------------- |
|
697 // Resolve the button's size from layout. |
|
698 // --------------------------------------------------------------------------- |
|
699 // |
|
700 TSize CFsControlButtonModel::GetLayoutSize( TRect& aParentRect ) |
|
701 { |
|
702 FUNC_LOG; |
|
703 CFsLayoutManager::TFsLayoutMetrics layoutItem( |
|
704 CFsLayoutManager::EFsLmMainSpFsCtrlbarPaneG1 ); |
|
705 switch ( Type() ) |
|
706 { |
|
707 case ECBTypeIconOnly: |
|
708 if ( 4 == iLayoutPos && iUseLayoutData ) |
|
709 { |
|
710 layoutItem = CFsLayoutManager::EFsLmMainSpFsCtrlbarPaneG2; |
|
711 } |
|
712 else |
|
713 { |
|
714 layoutItem = CFsLayoutManager::EFsLmMainSpFsCtrlbarPaneG1; |
|
715 } |
|
716 break; |
|
717 case ECBTypeOneLineLabelOnly: |
|
718 case ECBTypeOneLineLabelIconA: |
|
719 case ECBTypeOneLineLabelIconB: |
|
720 case ECBTypeOneLineLabelTwoIcons: |
|
721 case ECBTypeTwoLinesLabelOnly: |
|
722 case ECBTypeTwoLinesLabelIconA: |
|
723 case ECBTypeTwoLinesLabelIconB: |
|
724 case ECBTypeTwoLinesLabelTwoIcons: |
|
725 if ( 3 == iLayoutPos && iUseLayoutData ) |
|
726 { |
|
727 layoutItem = |
|
728 CFsLayoutManager::EFsLmMainSpFsCtrlbarButtonPaneCp01; |
|
729 } |
|
730 else |
|
731 { |
|
732 layoutItem = |
|
733 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPane; |
|
734 } |
|
735 break; |
|
736 default: |
|
737 break; |
|
738 } |
|
739 |
|
740 TSize layoutSize( 0, 0 ); |
|
741 |
|
742 CFsLayoutManager::LayoutMetricsSize( aParentRect, |
|
743 layoutItem, layoutSize, |
|
744 0 ); |
|
745 |
|
746 return layoutSize; |
|
747 } |
|
748 |
|
749 |
|
750 // --------------------------------------------------------------------------- |
|
751 // Get the layout position on controlbar. |
|
752 // --------------------------------------------------------------------------- |
|
753 // |
|
754 TInt CFsControlButtonModel::GetLayoutPos() |
|
755 { |
|
756 FUNC_LOG; |
|
757 return iLayoutPos; |
|
758 } |
|
759 |
|
760 |
|
761 // --------------------------------------------------------------------------- |
|
762 // Set the layout position index on controlbar. |
|
763 // --------------------------------------------------------------------------- |
|
764 // |
|
765 void CFsControlButtonModel::SetParentIndex( TInt aLayoutPos ) |
|
766 { |
|
767 FUNC_LOG; |
|
768 if ( 0 >= aLayoutPos || KMaxButtonLayoutItems < aLayoutPos ) |
|
769 { |
|
770 iUseLayoutData = EFalse; |
|
771 } |
|
772 else |
|
773 { |
|
774 SetSize( GetLayoutSize() ); |
|
775 TPoint buttonPos( CFsControlBar::GetLayoutRect( aLayoutPos ).iTl ); |
|
776 SetPos( buttonPos, EFalse ); |
|
777 // Auto position flag needs to be reseted every time. |
|
778 iAutoPosition = ETrue; |
|
779 iUseLayoutData = ETrue; |
|
780 } |
|
781 iLayoutPos = aLayoutPos; |
|
782 } |
|
783 |
|
784 |
|
785 // --------------------------------------------------------------------------- |
|
786 // Resolve if layout data is used to define the size of the button. |
|
787 // --------------------------------------------------------------------------- |
|
788 // |
|
789 TBool CFsControlButtonModel::IsLayoutSize() |
|
790 { |
|
791 FUNC_LOG; |
|
792 return iUseLayoutData; |
|
793 } |
|
794 |
|
795 |
|
796 // --------------------------------------------------------------------------- |
|
797 // Refresh button's position. |
|
798 // --------------------------------------------------------------------------- |
|
799 // |
|
800 void CFsControlButtonModel::RefreshButtonPosition( const TSize& aParentSize ) |
|
801 { |
|
802 FUNC_LOG; |
|
803 TPoint point; |
|
804 |
|
805 if ( iUseLayoutData && AutoPosition() |
|
806 && MFsControlButtonInterface::EFsLayout == AutoSizeMode() ) |
|
807 { |
|
808 TRect layoutRect( CFsControlBar::GetLayoutRect( GetLayoutPos() ) ); |
|
809 |
|
810 SetSize( layoutRect.Size() ); |
|
811 point = layoutRect.iTl; |
|
812 } |
|
813 else |
|
814 { |
|
815 TRect parentRect( TPoint( 0, 0 ), aParentSize ); |
|
816 if ( CFsLayoutManager::IsMirrored() ) |
|
817 { |
|
818 point.iX = parentRect.Width() - iManualSetPos.iX - iSize.iWidth; |
|
819 point.iY = iStartPoint.iY; |
|
820 } |
|
821 else |
|
822 { |
|
823 point = iManualSetPos; |
|
824 } |
|
825 } |
|
826 |
|
827 SetPos( point, EFalse ); |
|
828 } |
|
829 |