|
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 Bar component. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "emailtrace.h" |
|
21 #include <AknUtils.h> |
|
22 |
|
23 #include "fscontrolbarmodel.h" |
|
24 #include "fscontrolbutton.h" |
|
25 #include "fsgenericpanic.h" |
|
26 #include "fscontrolbuttonvisualiser.h" |
|
27 #include "fslayoutmanager.h" |
|
28 |
|
29 const TUint KDefaultSelectorSpeed = 1000; |
|
30 |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // Constructor. |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 CFsControlBarModel::CFsControlBarModel() : |
|
39 iSelectorTransitionTime( KDefaultSelectorSpeed ), |
|
40 iWidthUseDefault( ETrue ), |
|
41 iHeightUseDefault( ETrue ) |
|
42 { |
|
43 FUNC_LOG; |
|
44 } |
|
45 |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // Second phase constructor. |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 void CFsControlBarModel::ConstructL() |
|
52 { |
|
53 FUNC_LOG; |
|
54 } |
|
55 |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Two-phased constructor. |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CFsControlBarModel* CFsControlBarModel::NewL() |
|
62 { |
|
63 FUNC_LOG; |
|
64 CFsControlBarModel* self = CFsControlBarModel::NewLC(); |
|
65 CleanupStack::Pop( self ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Two-phased constructor. |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CFsControlBarModel* CFsControlBarModel::NewLC() |
|
75 { |
|
76 FUNC_LOG; |
|
77 CFsControlBarModel* self = new (ELeave) CFsControlBarModel; |
|
78 CleanupStack::PushL( self ); |
|
79 self->ConstructL(); |
|
80 return self; |
|
81 } |
|
82 |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // Destructor. |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 CFsControlBarModel::~CFsControlBarModel() |
|
89 { |
|
90 FUNC_LOG; |
|
91 // <cmail> Touch |
|
92 // Buttons are now alf controls and owned by alf environment, not deleted here |
|
93 /*for( TInt i = 0; i < Count(); i++ ) |
|
94 { |
|
95 delete iButtons[i]; |
|
96 }*/ |
|
97 // </cmail> |
|
98 |
|
99 iButtons.Reset(); |
|
100 } |
|
101 |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // Adds button object to collection. |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 void CFsControlBarModel::AddButtonL( CFsControlButton& aButton ) |
|
108 { |
|
109 FUNC_LOG; |
|
110 iButtons.AppendL( &aButton ); |
|
111 } |
|
112 |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // Retrieves button from collection with specified index. |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 CFsControlButton* CFsControlBarModel::ButtonByIndex( TInt aIndex ) |
|
119 { |
|
120 FUNC_LOG; |
|
121 CFsControlButton* result( NULL ); |
|
122 |
|
123 if ( aIndex >= 0 && aIndex < Count() ) |
|
124 { |
|
125 result = iButtons[ aIndex ]; |
|
126 } |
|
127 |
|
128 return result; |
|
129 } |
|
130 |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // Retrieves button from collection with specified id. |
|
134 // Panics if id is incorrect. |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 CFsControlButton* CFsControlBarModel::ButtonById( TInt aId ) |
|
138 { |
|
139 FUNC_LOG; |
|
140 CFsControlButton* button( NULL ); |
|
141 CFsControlButton* result( NULL ); |
|
142 TInt i( 0 ); |
|
143 |
|
144 if ( ECBFirstFocusableButton == aId ) |
|
145 { |
|
146 while ( Count() > i && !result ) |
|
147 { |
|
148 button = ButtonByIndex( i ); |
|
149 if ( button->IsVisible() && !button->IsDimmed() ) |
|
150 { |
|
151 result = button; |
|
152 } |
|
153 ++i; |
|
154 } |
|
155 } |
|
156 else |
|
157 { |
|
158 while ( Count() > i && !result ) |
|
159 { |
|
160 button = ButtonByIndex( i ); |
|
161 if( button->Id() == aId ) |
|
162 { |
|
163 result = button; |
|
164 } |
|
165 ++i; |
|
166 } |
|
167 |
|
168 // panic only when specified id passed by component user is searched |
|
169 if ( !result ) |
|
170 { |
|
171 FsGenericPanic( EFsControlButtonIncorrectButtonId ); |
|
172 } |
|
173 } |
|
174 |
|
175 return result; |
|
176 } |
|
177 |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // Retrieves number of buttons in collection. |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 TInt CFsControlBarModel::Count() const |
|
184 { |
|
185 FUNC_LOG; |
|
186 return iButtons.Count(); |
|
187 } |
|
188 |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // Removes button from collection using index. |
|
192 // Used function ButtonByIndex panics - see ButtonByIndex. |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 void CFsControlBarModel::RemoveButtonByIndex( TInt aIndex ) |
|
196 { |
|
197 FUNC_LOG; |
|
198 delete ButtonByIndex( aIndex ); |
|
199 iButtons.Remove( aIndex ); |
|
200 } |
|
201 |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // Removes button from collection using id. |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 TInt CFsControlBarModel::RemoveButtonById( TInt aId ) |
|
208 { |
|
209 FUNC_LOG; |
|
210 TInt retVal( KErrNotFound ); |
|
211 for ( TInt i( 0 ); Count() > i; i++ ) |
|
212 { |
|
213 if( ButtonByIndex( i )->Id() == aId ) |
|
214 { |
|
215 RemoveButtonByIndex( i ); |
|
216 retVal = KErrNone; |
|
217 break; |
|
218 } |
|
219 } |
|
220 |
|
221 if ( retVal ) |
|
222 { |
|
223 FsGenericPanic( EFsControlButtonIncorrectButtonId ); |
|
224 } |
|
225 |
|
226 return retVal; |
|
227 } |
|
228 |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // Checks if button with specified id exists in collection. |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 TBool CFsControlBarModel::ExistsButtonWithId( TInt aId ) |
|
235 { |
|
236 FUNC_LOG; |
|
237 TBool result( EFalse ); |
|
238 |
|
239 for( TInt i( 0 ); iButtons.Count() > i; i++ ) |
|
240 { |
|
241 if( iButtons[i]->Id() == aId ) |
|
242 { |
|
243 result = ETrue; |
|
244 break; |
|
245 } |
|
246 } |
|
247 |
|
248 return result; |
|
249 } |
|
250 |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // Retrieves index of button with specified id. |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 TInt CFsControlBarModel::IndexById( TInt aButtonId ) |
|
257 { |
|
258 FUNC_LOG; |
|
259 TInt result( -1 ); |
|
260 TInt i( 0 ); |
|
261 |
|
262 while ( -1 == result && Count() > i ) |
|
263 { |
|
264 if( ButtonByIndex( i )->Id() == aButtonId ) |
|
265 { |
|
266 result = i; |
|
267 } |
|
268 i++; |
|
269 } |
|
270 |
|
271 return result; |
|
272 } |
|
273 |
|
274 |
|
275 // --------------------------------------------------------------------------- |
|
276 // Retrieves next focusable button. |
|
277 // --------------------------------------------------------------------------- |
|
278 // |
|
279 CFsControlButton* CFsControlBarModel::NextButton( TInt aButtonId ) |
|
280 { |
|
281 FUNC_LOG; |
|
282 TInt index( -1 ); |
|
283 CFsControlButton* currentBtn( ButtonById( aButtonId ) ); |
|
284 |
|
285 // Find current button's id. |
|
286 TInt buttonId( 0 ); |
|
287 while ( iButtons.Count() > buttonId ) |
|
288 { |
|
289 if ( iButtons[buttonId] == currentBtn ) |
|
290 { |
|
291 break; |
|
292 } |
|
293 buttonId++; |
|
294 } |
|
295 |
|
296 // Find the next button on right. |
|
297 TInt curPos( currentBtn->Visualiser()->Pos().Target().iX ); |
|
298 TBool candidate( EFalse ); |
|
299 TInt next( 0 ); |
|
300 for ( TInt i( 0 ); iButtons.Count() > i; i++ ) |
|
301 { |
|
302 if ( i == buttonId |
|
303 || !iButtons[i]->IsVisible() |
|
304 || iButtons[i]->IsDimmed() ) |
|
305 { |
|
306 continue; |
|
307 } |
|
308 TInt btnPos( iButtons[i]->Visualiser()->Pos().Target().iX ); |
|
309 if ( btnPos >= curPos ) |
|
310 { |
|
311 if ( btnPos == curPos ) |
|
312 { |
|
313 if ( i < buttonId ) |
|
314 { |
|
315 continue; |
|
316 } |
|
317 } |
|
318 if ( !candidate ) |
|
319 { |
|
320 // This is the first proper candidate. |
|
321 index = i; |
|
322 next = btnPos; |
|
323 candidate = ETrue; |
|
324 } |
|
325 else if ( btnPos <= next ) |
|
326 { |
|
327 // This button is closer than previously found button. |
|
328 index = i; |
|
329 next = btnPos; |
|
330 if ( btnPos == curPos ) |
|
331 { |
|
332 break; |
|
333 } |
|
334 } |
|
335 } |
|
336 } |
|
337 return ButtonByIndex( index ); |
|
338 } |
|
339 |
|
340 |
|
341 // --------------------------------------------------------------------------- |
|
342 // Retrieves previous focusable button. |
|
343 // --------------------------------------------------------------------------- |
|
344 // |
|
345 CFsControlButton* CFsControlBarModel::PrevButton( TInt aButtonId ) |
|
346 { |
|
347 FUNC_LOG; |
|
348 TInt index( -1 ); |
|
349 CFsControlButton* currentBtn( ButtonById( aButtonId ) ); |
|
350 |
|
351 // Find current button's id. |
|
352 TInt buttonId( 0 ); |
|
353 while ( iButtons.Count() > buttonId ) |
|
354 { |
|
355 if ( iButtons[buttonId] == currentBtn ) |
|
356 { |
|
357 break; |
|
358 } |
|
359 buttonId++; |
|
360 } |
|
361 |
|
362 // Find the next button on left. |
|
363 TInt curPos( currentBtn->Visualiser()->Pos().Target().iX ); |
|
364 TBool candidate( EFalse ); |
|
365 TInt next( 0 ); |
|
366 for ( TInt i( iButtons.Count() - 1 ); 0 <= i; i-- ) |
|
367 { |
|
368 if ( i == buttonId |
|
369 || !iButtons[i]->IsVisible() |
|
370 || iButtons[i]->IsDimmed() ) |
|
371 { |
|
372 continue; |
|
373 } |
|
374 TInt btnPos( iButtons[i]->Visualiser()->Pos().Target().iX ); |
|
375 if ( btnPos <= curPos ) |
|
376 { |
|
377 if ( btnPos == curPos ) |
|
378 { |
|
379 if ( i > buttonId ) |
|
380 { |
|
381 continue; |
|
382 } |
|
383 } |
|
384 if ( !candidate ) |
|
385 { |
|
386 // This is the first proper candidate. |
|
387 index = i; |
|
388 next = btnPos; |
|
389 candidate = ETrue; |
|
390 } |
|
391 else if ( btnPos >= next ) |
|
392 { |
|
393 // This button is closer than previously found button. |
|
394 index = i; |
|
395 next = btnPos; |
|
396 if ( btnPos == curPos ) |
|
397 { |
|
398 break; |
|
399 } |
|
400 } |
|
401 } |
|
402 } |
|
403 |
|
404 return ButtonByIndex( index ); |
|
405 } |
|
406 |
|
407 |
|
408 // --------------------------------------------------------------------------- |
|
409 // Sets focus for control bar. |
|
410 // --------------------------------------------------------------------------- |
|
411 // |
|
412 void CFsControlBarModel::SetFocus( TBool aState ) |
|
413 { |
|
414 FUNC_LOG; |
|
415 iFocused = aState; |
|
416 } |
|
417 |
|
418 |
|
419 // --------------------------------------------------------------------------- |
|
420 // Retrieves focus state of control bar. |
|
421 // --------------------------------------------------------------------------- |
|
422 // |
|
423 TBool CFsControlBarModel::IsFocused() const |
|
424 { |
|
425 FUNC_LOG; |
|
426 return iFocused; |
|
427 } |
|
428 |
|
429 |
|
430 // --------------------------------------------------------------------------- |
|
431 // Generates free id value for new button. |
|
432 // --------------------------------------------------------------------------- |
|
433 // |
|
434 TInt CFsControlBarModel::GenerateButtonId() |
|
435 { |
|
436 FUNC_LOG; |
|
437 TInt result( 0 ); |
|
438 |
|
439 for ( TInt i( 0 ); Count() > i; i++ ) |
|
440 { |
|
441 if ( result == ButtonByIndex( i )->Id() ) |
|
442 { |
|
443 ++result; |
|
444 } |
|
445 } |
|
446 |
|
447 return result; |
|
448 } |
|
449 |
|
450 |
|
451 // --------------------------------------------------------------------------- |
|
452 // Retrieves default bar background color. |
|
453 // --------------------------------------------------------------------------- |
|
454 // |
|
455 const TRgb& CFsControlBarModel::BarBgColor() const |
|
456 { |
|
457 FUNC_LOG; |
|
458 return iBgColor; |
|
459 } |
|
460 |
|
461 |
|
462 // --------------------------------------------------------------------------- |
|
463 // Gets transition time for moving selector. |
|
464 // --------------------------------------------------------------------------- |
|
465 // |
|
466 TInt CFsControlBarModel::SelectorTransitionTime() const |
|
467 { |
|
468 FUNC_LOG; |
|
469 return iSelectorTransitionTime; |
|
470 } |
|
471 |
|
472 |
|
473 // --------------------------------------------------------------------------- |
|
474 // Sets transition time for moving selector. |
|
475 // --------------------------------------------------------------------------- |
|
476 // |
|
477 void CFsControlBarModel::SetSelectorTransitionTime( TInt aTransitionTime ) |
|
478 { |
|
479 FUNC_LOG; |
|
480 iSelectorTransitionTime = aTransitionTime; |
|
481 } |
|
482 |
|
483 |
|
484 // --------------------------------------------------------------------------- |
|
485 // Refresh the buttons' positions. |
|
486 // --------------------------------------------------------------------------- |
|
487 // |
|
488 void CFsControlBarModel::UpdateButtonsPositions() |
|
489 { |
|
490 FUNC_LOG; |
|
491 TSize parentSize( Size() ); |
|
492 |
|
493 for ( TInt i( 0 ); iButtons.Count() > i; i++ ) |
|
494 { |
|
495 iButtons[i]->RefreshButtonPosition( parentSize ); |
|
496 } |
|
497 } |
|
498 |
|
499 |
|
500 // --------------------------------------------------------------------------- |
|
501 // Sets width in pixels of controlbar and refreshes control. |
|
502 // --------------------------------------------------------------------------- |
|
503 // |
|
504 void CFsControlBarModel::SetWidth( TInt aWidth ) |
|
505 { |
|
506 FUNC_LOG; |
|
507 iSize.iWidth = aWidth; |
|
508 iWidthUseDefault = EFalse; |
|
509 } |
|
510 |
|
511 |
|
512 // --------------------------------------------------------------------------- |
|
513 // Sets height in pixels of controlbar and refreshes control. |
|
514 // --------------------------------------------------------------------------- |
|
515 // |
|
516 void CFsControlBarModel::SetHeight( TInt aHeight ) |
|
517 { |
|
518 FUNC_LOG; |
|
519 iSize.iHeight = aHeight; |
|
520 iHeightUseDefault = EFalse; |
|
521 } |
|
522 |
|
523 |
|
524 // --------------------------------------------------------------------------- |
|
525 // Retrieves controlbar's size in pixels. |
|
526 // --------------------------------------------------------------------------- |
|
527 // |
|
528 TSize CFsControlBarModel::Size() const |
|
529 { |
|
530 FUNC_LOG; |
|
531 TRect layoutRect; |
|
532 |
|
533 if ( iWidthUseDefault || iHeightUseDefault ) |
|
534 { |
|
535 TRect parentRect; |
|
536 AknLayoutUtils::LayoutMetricsRect( |
|
537 AknLayoutUtils::EScreen, parentRect ); |
|
538 |
|
539 CFsLayoutManager::LayoutMetricsRect( parentRect, |
|
540 CFsLayoutManager::EFsLmMainSpFsCtrlbarPane, layoutRect ); |
|
541 } |
|
542 |
|
543 return TSize( |
|
544 iWidthUseDefault ? layoutRect.Width() : iSize.iWidth, |
|
545 iHeightUseDefault ? layoutRect.Height() : iSize.iHeight ); |
|
546 } |
|
547 |