64
|
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(
|
|
280 |
TInt aButtonId, TBool aLandscape )
|
|
281 |
{
|
|
282 |
FUNC_LOG;
|
|
283 |
TInt index( KErrNotFound );
|
|
284 |
CFsControlButton* currentBtn( ButtonById( aButtonId ) );
|
|
285 |
|
|
286 |
// Find current button's id.
|
|
287 |
TInt buttonId( 0 );
|
|
288 |
while ( iButtons.Count() > buttonId )
|
|
289 |
{
|
|
290 |
if ( iButtons[buttonId] == currentBtn )
|
|
291 |
{
|
|
292 |
break;
|
|
293 |
}
|
|
294 |
buttonId++;
|
|
295 |
}
|
|
296 |
|
|
297 |
// Find the next button on right.
|
|
298 |
TAlfRealPoint curPosTarget( currentBtn->Visualiser()->Pos().Target() );
|
|
299 |
TInt curPos( curPosTarget.iX );
|
|
300 |
if( aLandscape )
|
|
301 |
{
|
|
302 |
curPos = curPosTarget.iY;
|
|
303 |
}
|
|
304 |
|
|
305 |
TBool candidate( EFalse );
|
|
306 |
TInt next( 0 );
|
|
307 |
for ( TInt i( 0 ); iButtons.Count() > i; i++ )
|
|
308 |
{
|
|
309 |
if ( i == buttonId
|
|
310 |
|| !iButtons[i]->IsVisible()
|
|
311 |
|| iButtons[i]->IsDimmed() )
|
|
312 |
{
|
|
313 |
continue;
|
|
314 |
}
|
|
315 |
TAlfRealPoint btnPosTarget( iButtons[i]->Visualiser()->Pos().Target() );
|
|
316 |
TInt btnPos( btnPosTarget.iX );
|
|
317 |
if( aLandscape )
|
|
318 |
{
|
|
319 |
btnPos = btnPosTarget.iY;
|
|
320 |
}
|
|
321 |
if ( btnPos >= curPos )
|
|
322 |
{
|
|
323 |
if ( btnPos == curPos )
|
|
324 |
{
|
|
325 |
if ( i < buttonId )
|
|
326 |
{
|
|
327 |
continue;
|
|
328 |
}
|
|
329 |
}
|
|
330 |
if ( !candidate )
|
|
331 |
{
|
|
332 |
// This is the first proper candidate.
|
|
333 |
index = i;
|
|
334 |
next = btnPos;
|
|
335 |
candidate = ETrue;
|
|
336 |
}
|
|
337 |
else if ( btnPos <= next )
|
|
338 |
{
|
|
339 |
// This button is closer than previously found button.
|
|
340 |
index = i;
|
|
341 |
next = btnPos;
|
|
342 |
if ( btnPos == curPos )
|
|
343 |
{
|
|
344 |
break;
|
|
345 |
}
|
|
346 |
}
|
|
347 |
}
|
|
348 |
}
|
|
349 |
return ButtonByIndex( index );
|
|
350 |
}
|
|
351 |
|
|
352 |
|
|
353 |
// ---------------------------------------------------------------------------
|
|
354 |
// Retrieves previous focusable button.
|
|
355 |
// ---------------------------------------------------------------------------
|
|
356 |
//
|
|
357 |
CFsControlButton* CFsControlBarModel::PrevButton(
|
|
358 |
TInt aButtonId, TBool aLandscape )
|
|
359 |
{
|
|
360 |
FUNC_LOG;
|
|
361 |
TInt index( KErrNotFound );
|
|
362 |
CFsControlButton* currentBtn( ButtonById( aButtonId ) );
|
|
363 |
|
|
364 |
// Find current button's id.
|
|
365 |
TInt buttonId( 0 );
|
|
366 |
while ( iButtons.Count() > buttonId )
|
|
367 |
{
|
|
368 |
if ( iButtons[buttonId] == currentBtn )
|
|
369 |
{
|
|
370 |
break;
|
|
371 |
}
|
|
372 |
buttonId++;
|
|
373 |
}
|
|
374 |
|
|
375 |
// Find the next button on left or up.
|
|
376 |
TAlfRealPoint curPosTaget( currentBtn->Visualiser()->Pos().Target() );
|
|
377 |
|
|
378 |
TInt curPos( curPosTaget.iX );
|
|
379 |
if( aLandscape )
|
|
380 |
{
|
|
381 |
curPos = curPosTaget.iY;
|
|
382 |
}
|
|
383 |
TBool candidate( EFalse );
|
|
384 |
TInt next( 0 );
|
|
385 |
for ( TInt i( iButtons.Count() - 1 ); 0 <= i; i-- )
|
|
386 |
{
|
|
387 |
if ( ( i == buttonId ) ||
|
|
388 |
( !iButtons[i]->IsVisible() ) ||
|
|
389 |
( iButtons[i]->IsDimmed() ) )
|
|
390 |
{
|
|
391 |
continue;
|
|
392 |
}
|
|
393 |
TAlfRealPoint btnPosTarget( iButtons[i]->Visualiser()->Pos().Target() );
|
|
394 |
TInt btnPos( btnPosTarget.iX );
|
|
395 |
if( aLandscape )
|
|
396 |
{
|
|
397 |
btnPos = btnPosTarget.iY;
|
|
398 |
}
|
|
399 |
if ( btnPos <= curPos )
|
|
400 |
{
|
|
401 |
if ( btnPos == curPos )
|
|
402 |
{
|
|
403 |
if ( i > buttonId )
|
|
404 |
{
|
|
405 |
continue;
|
|
406 |
}
|
|
407 |
}
|
|
408 |
if ( !candidate )
|
|
409 |
{
|
|
410 |
// This is the first proper candidate.
|
|
411 |
index = i;
|
|
412 |
next = btnPos;
|
|
413 |
candidate = ETrue;
|
|
414 |
}
|
|
415 |
else if ( btnPos >= next )
|
|
416 |
{
|
|
417 |
// This button is closer than previously found button.
|
|
418 |
index = i;
|
|
419 |
next = btnPos;
|
|
420 |
if ( btnPos == curPos )
|
|
421 |
{
|
|
422 |
break;
|
|
423 |
}
|
|
424 |
}
|
|
425 |
}
|
|
426 |
}
|
|
427 |
|
|
428 |
return ButtonByIndex( index );
|
|
429 |
}
|
|
430 |
|
|
431 |
|
|
432 |
// ---------------------------------------------------------------------------
|
|
433 |
// Sets focus for control bar.
|
|
434 |
// ---------------------------------------------------------------------------
|
|
435 |
//
|
|
436 |
void CFsControlBarModel::SetFocus( TBool aState )
|
|
437 |
{
|
|
438 |
FUNC_LOG;
|
|
439 |
iFocused = aState;
|
|
440 |
}
|
|
441 |
|
|
442 |
|
|
443 |
// ---------------------------------------------------------------------------
|
|
444 |
// Retrieves focus state of control bar.
|
|
445 |
// ---------------------------------------------------------------------------
|
|
446 |
//
|
|
447 |
TBool CFsControlBarModel::IsFocused() const
|
|
448 |
{
|
|
449 |
FUNC_LOG;
|
|
450 |
return iFocused;
|
|
451 |
}
|
|
452 |
|
|
453 |
|
|
454 |
// ---------------------------------------------------------------------------
|
|
455 |
// Generates free id value for new button.
|
|
456 |
// ---------------------------------------------------------------------------
|
|
457 |
//
|
|
458 |
TInt CFsControlBarModel::GenerateButtonId()
|
|
459 |
{
|
|
460 |
FUNC_LOG;
|
|
461 |
TInt result( 0 );
|
|
462 |
|
|
463 |
for ( TInt i( 0 ); Count() > i; i++ )
|
|
464 |
{
|
|
465 |
if ( result == ButtonByIndex( i )->Id() )
|
|
466 |
{
|
|
467 |
++result;
|
|
468 |
}
|
|
469 |
}
|
|
470 |
|
|
471 |
return result;
|
|
472 |
}
|
|
473 |
|
|
474 |
|
|
475 |
// ---------------------------------------------------------------------------
|
|
476 |
// Retrieves default bar background color.
|
|
477 |
// ---------------------------------------------------------------------------
|
|
478 |
//
|
|
479 |
const TRgb& CFsControlBarModel::BarBgColor() const
|
|
480 |
{
|
|
481 |
FUNC_LOG;
|
|
482 |
return iBgColor;
|
|
483 |
}
|
|
484 |
|
|
485 |
|
|
486 |
// ---------------------------------------------------------------------------
|
|
487 |
// Gets transition time for moving selector.
|
|
488 |
// ---------------------------------------------------------------------------
|
|
489 |
//
|
|
490 |
TInt CFsControlBarModel::SelectorTransitionTime() const
|
|
491 |
{
|
|
492 |
FUNC_LOG;
|
|
493 |
return iSelectorTransitionTime;
|
|
494 |
}
|
|
495 |
|
|
496 |
|
|
497 |
// ---------------------------------------------------------------------------
|
|
498 |
// Sets transition time for moving selector.
|
|
499 |
// ---------------------------------------------------------------------------
|
|
500 |
//
|
|
501 |
void CFsControlBarModel::SetSelectorTransitionTime( TInt aTransitionTime )
|
|
502 |
{
|
|
503 |
FUNC_LOG;
|
|
504 |
iSelectorTransitionTime = aTransitionTime;
|
|
505 |
}
|
|
506 |
|
|
507 |
|
|
508 |
// ---------------------------------------------------------------------------
|
|
509 |
// Refresh the buttons' positions.
|
|
510 |
// ---------------------------------------------------------------------------
|
|
511 |
//
|
|
512 |
void CFsControlBarModel::UpdateButtonsPositions()
|
|
513 |
{
|
|
514 |
FUNC_LOG;
|
|
515 |
TSize parentSize( Size() );
|
|
516 |
|
|
517 |
for ( TInt i( 0 ); iButtons.Count() > i; i++ )
|
|
518 |
{
|
|
519 |
iButtons[i]->RefreshButtonPosition( parentSize );
|
|
520 |
}
|
|
521 |
}
|
|
522 |
|
|
523 |
// ---------------------------------------------------------------------------
|
|
524 |
// Set new position and size
|
|
525 |
// ---------------------------------------------------------------------------
|
|
526 |
//
|
|
527 |
void CFsControlBarModel::SetRect( const TRect& aRect )
|
|
528 |
{
|
|
529 |
iSize = aRect.Size();
|
|
530 |
iWidthUseDefault = EFalse;
|
|
531 |
iHeightUseDefault = EFalse;
|
|
532 |
iTl = aRect.iTl;
|
|
533 |
}
|
|
534 |
|
|
535 |
// ---------------------------------------------------------------------------
|
|
536 |
// Get top-left position of the bar
|
|
537 |
// ---------------------------------------------------------------------------
|
|
538 |
//
|
|
539 |
TPoint CFsControlBarModel::Pos() const
|
|
540 |
{
|
|
541 |
return iTl;
|
|
542 |
}
|
|
543 |
|
|
544 |
// ---------------------------------------------------------------------------
|
|
545 |
// Sets width in pixels of controlbar and refreshes control.
|
|
546 |
// ---------------------------------------------------------------------------
|
|
547 |
//
|
|
548 |
void CFsControlBarModel::SetWidth( TInt aWidth )
|
|
549 |
{
|
|
550 |
FUNC_LOG;
|
|
551 |
iSize.iWidth = aWidth;
|
|
552 |
iWidthUseDefault = EFalse;
|
|
553 |
}
|
|
554 |
|
|
555 |
|
|
556 |
// ---------------------------------------------------------------------------
|
|
557 |
// Sets height in pixels of controlbar and refreshes control.
|
|
558 |
// ---------------------------------------------------------------------------
|
|
559 |
//
|
|
560 |
void CFsControlBarModel::SetHeight( TInt aHeight )
|
|
561 |
{
|
|
562 |
FUNC_LOG;
|
|
563 |
iSize.iHeight = aHeight;
|
|
564 |
iHeightUseDefault = EFalse;
|
|
565 |
}
|
|
566 |
|
|
567 |
|
|
568 |
// ---------------------------------------------------------------------------
|
|
569 |
// Retrieves controlbar's size in pixels.
|
|
570 |
// ---------------------------------------------------------------------------
|
|
571 |
//
|
|
572 |
TSize CFsControlBarModel::Size() const
|
|
573 |
{
|
|
574 |
FUNC_LOG;
|
|
575 |
TRect layoutRect;
|
|
576 |
|
|
577 |
if ( iWidthUseDefault || iHeightUseDefault )
|
|
578 |
{
|
|
579 |
TRect parentRect;
|
|
580 |
AknLayoutUtils::LayoutMetricsRect(
|
|
581 |
AknLayoutUtils::EScreen, parentRect );
|
|
582 |
|
|
583 |
CFsLayoutManager::LayoutMetricsRect( parentRect,
|
|
584 |
CFsLayoutManager::EFsLmMainSpFsCtrlbarPane, layoutRect );
|
|
585 |
}
|
|
586 |
|
|
587 |
return TSize(
|
|
588 |
iWidthUseDefault ? layoutRect.Width() : iSize.iWidth,
|
|
589 |
iHeightUseDefault ? layoutRect.Height() : iSize.iHeight );
|
|
590 |
}
|
|
591 |
|