|
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: Splits layout chain by visual |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "glxlayoutsplitter.h" |
|
22 |
|
23 #include <alf/alfvisual.h> |
|
24 #include <mglxvisuallist.h> |
|
25 #include <glxpanic.h> // Panic codes |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // Constructor |
|
29 // ----------------------------------------------------------------------------- |
|
30 EXPORT_C TGlxLayoutSplitter::TGlxLayoutSplitter() |
|
31 : iDefaultLayout( NULL ), |
|
32 iVisualList( NULL ) |
|
33 { |
|
34 __DEBUG_ONLY( _iName = _L("TGlxLayoutSplitter") ); |
|
35 } |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // Destructor |
|
39 // ----------------------------------------------------------------------------- |
|
40 EXPORT_C TGlxLayoutSplitter::~TGlxLayoutSplitter() |
|
41 { |
|
42 Reset(); |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // Tells the splitter what is the visual list object |
|
47 // ----------------------------------------------------------------------------- |
|
48 EXPORT_C void TGlxLayoutSplitter::SetVisualListL( |
|
49 MGlxVisualList* aVisualList ) |
|
50 { |
|
51 __ASSERT_DEBUG( |
|
52 aVisualList, Panic( EGlxPanicNullVisualList ) ); |
|
53 iVisualList = aVisualList; |
|
54 iVisualList->AddObserverL( this ); |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // SetLayoutL |
|
59 // ----------------------------------------------------------------------------- |
|
60 EXPORT_C void TGlxLayoutSplitter::SetLayoutL( |
|
61 MGlxLayout* aLayout, const CAlfVisual* aVisual ) |
|
62 { |
|
63 // Call SetVisualListL first |
|
64 __ASSERT_DEBUG( iVisualList, Panic( EGlxPanicNullVisualList ) ); |
|
65 // to replace EGlxPanicNullCHuiVisual |
|
66 //__ASSERT_DEBUG( aVisual && aLayout, Panic( EGlxPanicNullCAlfVisual ) ); |
|
67 // search if there already is a layout for this visual |
|
68 __DEBUG_ONLY( TLayout temp;temp.iVisual = aVisual; ); |
|
69 __ASSERT_DEBUG( |
|
70 iLayouts.Find( temp, TLayout::Match ) == KErrNotFound, |
|
71 Panic( EGlxPanicAlreadyAdded ) ); |
|
72 |
|
73 // create layout struct |
|
74 TLayout newLayoutStruct; |
|
75 newLayoutStruct.iLayout = aLayout; |
|
76 newLayoutStruct.iVisual = aVisual; |
|
77 // append to the array |
|
78 iLayouts.AppendL( newLayoutStruct ); |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // Removes an existing layout |
|
83 // ----------------------------------------------------------------------------- |
|
84 EXPORT_C void TGlxLayoutSplitter::RemoveLayout( |
|
85 const CAlfVisual* aVisual ) |
|
86 { |
|
87 TInt index = LayoutIndex( aVisual ); |
|
88 if( index != KErrNotFound ) |
|
89 { |
|
90 iLayouts.Remove( index ); |
|
91 } |
|
92 // NOTE! it is ok to try to remove a layout from visual when there was none |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // Sets layout to be used when for visuals which don't have a specific layout |
|
97 // ----------------------------------------------------------------------------- |
|
98 EXPORT_C void TGlxLayoutSplitter::SetDefaultLayout( |
|
99 MGlxLayout* aLayout ) |
|
100 { |
|
101 iDefaultLayout = aLayout; |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // Reset |
|
106 // Remove all layouts and remove association with visual list. |
|
107 // ----------------------------------------------------------------------------- |
|
108 EXPORT_C void TGlxLayoutSplitter::Reset() |
|
109 { |
|
110 // Remove all layouts |
|
111 iLayouts.Close(); |
|
112 |
|
113 if( iVisualList ) |
|
114 { |
|
115 iVisualList->RemoveObserver( this ); |
|
116 iVisualList = NULL; |
|
117 } |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // DoSetLayoutValues |
|
122 // ----------------------------------------------------------------------------- |
|
123 void TGlxLayoutSplitter::DoSetLayoutValues( |
|
124 TGlxLayoutInfo& aInfo ) |
|
125 { |
|
126 // Call SetVisualListL to avoid this assert |
|
127 __ASSERT_DEBUG( iVisualList, Panic( EGlxPanicNullVisualList ) ); |
|
128 |
|
129 // Does a layout exist for the visual |
|
130 // If yes, use the specific layout. If not, use default layout. |
|
131 MGlxLayout* layout = Layout( &aInfo.Visual() ); |
|
132 // if layout was found |
|
133 if( layout ) |
|
134 { |
|
135 // return its value |
|
136 return layout->SetLayoutValues( aInfo ); |
|
137 } |
|
138 // otherwise return the default layout value |
|
139 else if( iDefaultLayout ) |
|
140 { |
|
141 return iDefaultLayout->SetLayoutValues( aInfo ); |
|
142 } |
|
143 // nothing to do, no layout for the visual nor default |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // HandleVisualAddedL |
|
148 // ----------------------------------------------------------------------------- |
|
149 void TGlxLayoutSplitter::HandleVisualAddedL( |
|
150 CAlfVisual* /*aVisual*/, TInt /*aIndex*/, MGlxVisualList* /*aList*/) |
|
151 { |
|
152 // Do nothing |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // HandleVisualRemoved |
|
157 // Remove the layout associated with the visual, if any. |
|
158 // ----------------------------------------------------------------------------- |
|
159 void TGlxLayoutSplitter::HandleVisualRemoved( |
|
160 const CAlfVisual* aVisual, MGlxVisualList* /*aList*/ ) |
|
161 { |
|
162 // Try to find a layout struct with the provided visual, and remove |
|
163 // it if found |
|
164 TInt index = LayoutIndex( aVisual ); |
|
165 if( index != KErrNotFound ) |
|
166 { |
|
167 iLayouts.Remove( index ); |
|
168 } |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // HandleFocusChangedL |
|
173 // ----------------------------------------------------------------------------- |
|
174 void TGlxLayoutSplitter::HandleFocusChangedL( |
|
175 TInt /*aFocusIndex*/, |
|
176 TReal32 /*aItemsPerSecond*/, |
|
177 MGlxVisualList* /*aList*/, |
|
178 NGlxListDefs::TFocusChangeType /*aType*/ ) |
|
179 { |
|
180 // Do nothing |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // HandleSizeChanged |
|
185 // ----------------------------------------------------------------------------- |
|
186 void TGlxLayoutSplitter::HandleSizeChanged( |
|
187 const TSize& /*aSize*/, MGlxVisualList* /*aList*/ ) |
|
188 { |
|
189 // Do nothing |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // Returns the layout associated with the aInIndex, or NULL if not found |
|
194 // ----------------------------------------------------------------------------- |
|
195 MGlxLayout* TGlxLayoutSplitter::Layout( |
|
196 const CAlfVisual* aVisual ) const |
|
197 { |
|
198 // Find the layout that is intended for this visual |
|
199 TInt index = LayoutIndex( aVisual ); |
|
200 if( index != KErrNotFound ) |
|
201 { |
|
202 return iLayouts[ index ].iLayout; |
|
203 } |
|
204 return NULL; |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // Returns layout struct index or KErrNotFound |
|
209 // ----------------------------------------------------------------------------- |
|
210 TInt TGlxLayoutSplitter::LayoutIndex( |
|
211 const CAlfVisual* aVisual ) const |
|
212 { |
|
213 // search if there already is a layout for this visual |
|
214 TLayout temp; |
|
215 temp.iVisual = aVisual; |
|
216 return iLayouts.Find( temp, TLayout::Match ); |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // TGlxLayoutSplitter::Match |
|
221 // ----------------------------------------------------------------------------- |
|
222 TBool TGlxLayoutSplitter::TLayout::Match( |
|
223 const TLayout& aLhs, const TLayout& aRhs ) |
|
224 { |
|
225 // return true if the visuals are same |
|
226 return aLhs.iVisual == aRhs.iVisual; |
|
227 } |
|
228 |