|
1 /* |
|
2 * Copyright (c) 2008-2009 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: Layout mapping index to distance from focus |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "glxfollowfocuslayout.h" |
|
22 |
|
23 #include <mglxvisuallist.h> // MGlxVisualList |
|
24 #include "glxpanic.h" // Panic codes |
|
25 #include <mglxanimation.h> |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // Constructor |
|
29 // ----------------------------------------------------------------------------- |
|
30 EXPORT_C TGlxFollowFocusLayout::TGlxFollowFocusLayout() |
|
31 : iVisualList( NULL ) |
|
32 { |
|
33 } |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // Destructor |
|
37 // ----------------------------------------------------------------------------- |
|
38 EXPORT_C TGlxFollowFocusLayout::~TGlxFollowFocusLayout() |
|
39 { |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // SetVisualListL |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 EXPORT_C void TGlxFollowFocusLayout::SetVisualListL( |
|
47 MGlxVisualList* aVisualList ) |
|
48 { |
|
49 __ASSERT_DEBUG( aVisualList, Panic( EGlxPanicNullVisualList ) ); |
|
50 |
|
51 iVisualList = aVisualList; |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // DoSetLayoutValues |
|
56 // ----------------------------------------------------------------------------- |
|
57 void TGlxFollowFocusLayout::DoSetLayoutValues( TGlxLayoutInfo& aInfo ) |
|
58 { |
|
59 __ASSERT_DEBUG( iVisualList, Panic( EGlxPanicNullVisualList ) ); |
|
60 |
|
61 // change the mappedindex to be relative to focus but wrapped around |
|
62 // so if the list items are |
|
63 // 0, 1, 2, 3, 4, 5, 6 |
|
64 // -2,-1, 0, 1, 2, 3,-3 == focus in 2 |
|
65 // -3,-2,-1, 0, 1, 2, 3 == focus in 3 |
|
66 // 1, 2, 3,-3,-2,-1, 0 == focus in 6 |
|
67 // 0, 1, 2, 3,-3,-2,-1 == focus in 0 |
|
68 |
|
69 // calculate the current index - focus |
|
70 TInt index = aInfo.Index() - iVisualList->FocusIndex(); |
|
71 |
|
72 // get item count |
|
73 TInt itemCount = iVisualList->ItemCount(); |
|
74 TInt maxDist = itemCount / 2; |
|
75 |
|
76 // if index is smaller than smallest possible |
|
77 if ( index < -maxDist ) |
|
78 { |
|
79 // wrap around |
|
80 index += itemCount; |
|
81 } |
|
82 // if index is larger than biggest possible |
|
83 else if ( index >= maxDist ) |
|
84 { |
|
85 // wrap around |
|
86 index -= itemCount; |
|
87 } |
|
88 // assign the mapped index |
|
89 aInfo.iMappedIndex = index; |
|
90 } |