|
1 /* |
|
2 * Copyright (c) 2006 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: Component manager implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_VTUICOMPONENTMANAGER_H |
|
20 #define C_VTUICOMPONENTMANAGER_H |
|
21 |
|
22 #include <coeaui.h> |
|
23 |
|
24 #include "mvtuicomponentmanager.h" |
|
25 #include "mvtuicomponent.h" |
|
26 #include "tvtuicomponentstate.h" |
|
27 |
|
28 /** |
|
29 * CVtUiComponentManager |
|
30 * |
|
31 * Component manager implementation. |
|
32 * |
|
33 * @since S60 v3.2 |
|
34 */ |
|
35 NONSHARABLE_CLASS( CVtUiComponentManager ) |
|
36 : public CBase, public MVtUiComponentManager |
|
37 { |
|
38 |
|
39 public: // public methods |
|
40 |
|
41 /** |
|
42 * Static constructor. |
|
43 * |
|
44 * @return Newly created instance of CVtUiComponentManager class. |
|
45 */ |
|
46 static CVtUiComponentManager* NewL(); |
|
47 |
|
48 /** |
|
49 * Destructor. |
|
50 */ |
|
51 ~CVtUiComponentManager(); |
|
52 |
|
53 /** |
|
54 * Called when a Ws event is delivered. |
|
55 * |
|
56 * @param aEvent Window server event. |
|
57 * @param aDestination Event destination control. |
|
58 */ |
|
59 void HandleWsEventL( const TWsEvent& aEvent, CCoeControl *aDestination ); |
|
60 |
|
61 /** |
|
62 * Called when a resource change is informed. |
|
63 * |
|
64 * @param aType Type of change. |
|
65 */ |
|
66 void HandleResourceChangeL( TInt aType ); |
|
67 |
|
68 /** |
|
69 * Called when a keyevent needs handling. |
|
70 * |
|
71 * @param aKeyEvent Key event structure. |
|
72 * @param aCode Event code. |
|
73 */ |
|
74 TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType); |
|
75 |
|
76 /** |
|
77 * Called when a layout change is informed. |
|
78 * |
|
79 */ |
|
80 void HandleLayoutChangeL(); |
|
81 |
|
82 public: // from MVtUiComponentManager |
|
83 |
|
84 /** |
|
85 * @see MVtUiComponentManager::ChangeWsEventRegistration |
|
86 */ |
|
87 TInt ChangeWsEventRegistration( MVtUiWindowServerEventObserver& aObserver, |
|
88 TAction aAction ); |
|
89 |
|
90 /** |
|
91 * @see MVtUiComponentManager::ChangeResourceChangeRegistration |
|
92 */ |
|
93 TInt ChangeResourceChangeRegistration( |
|
94 MVtUiResourceChangeObserver& aObserver, |
|
95 TAction aAction ); |
|
96 |
|
97 /** |
|
98 * @see MVtUiComponentManager::ChangeKeyEventRegistration |
|
99 */ |
|
100 TInt ChangeKeyEventRegistration( MVtUiKeyEventObserver& aComponent, |
|
101 TAction aAction ); |
|
102 |
|
103 /** |
|
104 * @see MVtUiComponentManager::ChangeLayoutChangeRegistration |
|
105 */ |
|
106 TInt ChangeLayoutChangeRegistration( MVtUiLayoutChangeObserver& aComponent, |
|
107 TAction aAction ); |
|
108 |
|
109 /** |
|
110 * @see MVtUiComponentManager::ChangeComponentRegistration |
|
111 */ |
|
112 TInt ChangeComponentRegistration( TVtUiComponentState& aComponentState, |
|
113 TAction aAction ); |
|
114 |
|
115 /** |
|
116 * @see MVtUiComponentManager::RequestActivation |
|
117 */ |
|
118 void RequestActivationL( MVtUiComponent::TComponentId aId ); |
|
119 |
|
120 /** |
|
121 * @see MVtUiComponentManager::DeActivateComponentL |
|
122 */ |
|
123 void DeActivateComponentL( MVtUiComponent::TComponentId aId ); |
|
124 |
|
125 private: // private classes |
|
126 |
|
127 /** |
|
128 * TStateListItem |
|
129 * |
|
130 * Contains one component's state in state list. |
|
131 */ |
|
132 class TStateListItem |
|
133 { |
|
134 |
|
135 public: // public type definitions |
|
136 |
|
137 /** |
|
138 * Compare by key type definition. |
|
139 */ |
|
140 typedef TInt (*TKeyCmpFunc) |
|
141 ( const MVtUiComponent::TComponentId*, const TStateListItem& ); |
|
142 |
|
143 public: // public methods |
|
144 |
|
145 /** |
|
146 * Constructor |
|
147 * |
|
148 * @param aState Constant reference to component state. |
|
149 */ |
|
150 TStateListItem( const TVtUiComponentState& aState ); |
|
151 |
|
152 /** |
|
153 * Returns component id. |
|
154 * |
|
155 * @return Component's id. |
|
156 */ |
|
157 MVtUiComponent::TComponentId ComponentId() const; |
|
158 |
|
159 /** |
|
160 * Returns component's state. |
|
161 * |
|
162 * @return Component's state. |
|
163 */ |
|
164 TVtUiComponentState::TState State() const; |
|
165 |
|
166 /** |
|
167 * Sets component's state. |
|
168 * |
|
169 * @param aState Component's new state. |
|
170 */ |
|
171 void SetState( TVtUiComponentState::TState aState ); |
|
172 |
|
173 /** |
|
174 * Returns const reference to block list. |
|
175 * |
|
176 * @return Constant reference to block list. |
|
177 */ |
|
178 const TVtUiBlockList& BlockList() const; |
|
179 |
|
180 /** |
|
181 * Sets this object as root. |
|
182 */ |
|
183 void SetRoot(); |
|
184 |
|
185 /** |
|
186 * Returns ETrue if this object is root. |
|
187 * |
|
188 * @return ETrue if this item is root, EFalse otherwise. |
|
189 */ |
|
190 TBool IsRoot() const; |
|
191 |
|
192 /** |
|
193 * Sets this object as visited. |
|
194 */ |
|
195 void SetVisited(); |
|
196 |
|
197 /** |
|
198 * Returns ETrue if this object is visited. |
|
199 * |
|
200 * @return ETrue if this item has been visited, EFalse otherwise. |
|
201 */ |
|
202 TBool IsVisited() const; |
|
203 |
|
204 public: // static public methods |
|
205 |
|
206 /** |
|
207 * Returns TLinearOrder for RArray operations. Ordered by component id. |
|
208 * |
|
209 * @return TLinearOrder insntace for RArray operations. Ordering will |
|
210 * be done based on component Id. |
|
211 */ |
|
212 static TLinearOrder< TStateListItem > LinearOrder(); |
|
213 |
|
214 /** |
|
215 * Returns key order function for RArray operations. |
|
216 * |
|
217 * @return Key compare method pointer for RArray operations. |
|
218 */ |
|
219 static TKeyCmpFunc KeyOrder(); |
|
220 |
|
221 /** |
|
222 * Returns TLinearOrder for RArray operations. Ordered by component |
|
223 * state. |
|
224 * |
|
225 * @return TLinearOrder instance for RArray operations. Ordering will |
|
226 * be done based on component state. |
|
227 */ |
|
228 static TLinearOrder< TStateListItem > StateOrder(); |
|
229 |
|
230 private: // static private methods |
|
231 |
|
232 /** |
|
233 * StateListItem compare method. |
|
234 */ |
|
235 static TInt ItemCmpFunc( const TStateListItem& aItem1, |
|
236 const TStateListItem& aItem2 ); |
|
237 |
|
238 /** |
|
239 * StateListItem vs key compare method. |
|
240 */ |
|
241 static TInt KeyCmpFunc( const MVtUiComponent::TComponentId* aKey, |
|
242 const TStateListItem& aItem ); |
|
243 |
|
244 /** |
|
245 * StateListItem by state compare method. |
|
246 */ |
|
247 static TInt StateCmpFunc( const TStateListItem& aItem1, |
|
248 const TStateListItem& aItem2 ); |
|
249 |
|
250 private: // data |
|
251 |
|
252 // Component's ID |
|
253 MVtUiComponent::TComponentId iComponentId; |
|
254 |
|
255 // Component's state |
|
256 TVtUiComponentState::TState iState; |
|
257 |
|
258 // Block mask (IDs which will be blocked by this component) |
|
259 TVtUiBlockListBitField iBlockList; |
|
260 |
|
261 // ETrue if this component is the root compoent, EFalse otherwise |
|
262 TBool iIsRoot; |
|
263 |
|
264 // ETrue if this component has been already visited (i.e. evaluated) |
|
265 TBool iIsVisited; |
|
266 |
|
267 }; |
|
268 |
|
269 /** |
|
270 * TStateList |
|
271 * |
|
272 * Contains list of component states. This list can be modified and when all |
|
273 * modifications are ready, the whole list can be commited at once. |
|
274 * |
|
275 */ |
|
276 class TStateList |
|
277 { |
|
278 |
|
279 public: // public methods |
|
280 |
|
281 /** |
|
282 * Constructor. |
|
283 */ |
|
284 TStateList(); |
|
285 |
|
286 /** |
|
287 * Destructor. |
|
288 */ |
|
289 ~TStateList(); |
|
290 |
|
291 /** |
|
292 * Add new item to state list. |
|
293 * |
|
294 * @param aItem Reference to item to be added to the list. |
|
295 */ |
|
296 void AddItemL( TStateListItem& aItem ); |
|
297 |
|
298 /** |
|
299 * Returns number of items in state list. |
|
300 * |
|
301 * @return Number of items on list. |
|
302 */ |
|
303 TInt ItemCount() const; |
|
304 |
|
305 /** |
|
306 * Find state list item by component id. |
|
307 * |
|
308 * @param aComponentId Id of component that will be searched. |
|
309 * @return Index of the component or KErrNotFound if component with |
|
310 * given Id could not be found. |
|
311 */ |
|
312 TInt FindItem( MVtUiComponent::TComponentId aComponentId ) const; |
|
313 |
|
314 /** |
|
315 * Returns reference to state list item at given index. |
|
316 * |
|
317 * @param aIndex Index of the item to be fetched. |
|
318 * @return Reference to item at given index. |
|
319 */ |
|
320 TStateListItem& At( TInt aIndex ); |
|
321 |
|
322 /** |
|
323 * Returns const reference to state list item at given index. |
|
324 * |
|
325 * @param aIndex Index of the item to be fetched. |
|
326 * @return Constant reference to item at given index. |
|
327 */ |
|
328 const TStateListItem& At( TInt aIndex ) const; |
|
329 |
|
330 /** |
|
331 * Sorts list using given linear order. |
|
332 * |
|
333 * @param aOrder TLinearObject that will be used in sorting. |
|
334 */ |
|
335 void Sort( |
|
336 TLinearOrder< CVtUiComponentManager::TStateListItem > aOrder ); |
|
337 |
|
338 private: // data |
|
339 |
|
340 // List items |
|
341 RArray< TStateListItem > iItems; |
|
342 |
|
343 }; |
|
344 |
|
345 private: // enumerations |
|
346 |
|
347 /** |
|
348 * Activation actions |
|
349 */ |
|
350 enum TActivationAction |
|
351 { |
|
352 /** Hide component */ |
|
353 EHide, |
|
354 /** Show component */ |
|
355 EShow |
|
356 }; |
|
357 |
|
358 private: |
|
359 |
|
360 /** |
|
361 * Constructor |
|
362 */ |
|
363 CVtUiComponentManager(); |
|
364 |
|
365 /** |
|
366 * 2nd constructor, may leave |
|
367 */ |
|
368 void ConstructL(); |
|
369 |
|
370 /** |
|
371 * Adds or removes component from given array. |
|
372 */ |
|
373 template < class T > |
|
374 TInt AddOrRemoveComponent( RPointerArray< T >& aArray, T* aComponent, |
|
375 TAction aAction ); |
|
376 |
|
377 /** |
|
378 * Returns linear order object for array operations. |
|
379 */ |
|
380 static TLinearOrder< MVtUiComponent > ComponentOrder(); |
|
381 |
|
382 /** |
|
383 * Returns linear order object for array operations. |
|
384 */ |
|
385 static TLinearOrder< TVtUiComponentState > ComponentStateOrder(); |
|
386 |
|
387 /** |
|
388 * Starts activation process. |
|
389 */ |
|
390 void DoActivationL( TVtUiComponentState& aComponentState, |
|
391 TVtUiComponentState::TState aNewState ); |
|
392 |
|
393 /** |
|
394 * Starts deactivation process. |
|
395 */ |
|
396 void DoDeactivationL( TVtUiComponentState& aComponentState, |
|
397 TVtUiComponentState::TState aNewState ); |
|
398 |
|
399 /** |
|
400 * Calculates activation. |
|
401 */ |
|
402 void CalculateActivationL( const TVtUiBlockList& aBlockList, |
|
403 const TVtUiBlockList& aExclList, TStateList& aStateList, |
|
404 TActivationAction aAction ); |
|
405 |
|
406 /** |
|
407 * Commits activation calculation results. |
|
408 */ |
|
409 void CommitStateListL( TStateList& aList ); |
|
410 |
|
411 /** |
|
412 * Constructs component state list before the calculations. |
|
413 */ |
|
414 void ConstructStateListL( TStateList& aList ); |
|
415 |
|
416 private: // data |
|
417 |
|
418 // Window server event listeners |
|
419 RPointerArray< MVtUiWindowServerEventObserver > iWsEventObservers; |
|
420 |
|
421 // Resource change event listeners |
|
422 RPointerArray< MVtUiResourceChangeObserver > iResourceChangeObservers; |
|
423 |
|
424 // Key event listeners |
|
425 RPointerArray< MVtUiKeyEventObserver > iKeyEventObservers; |
|
426 |
|
427 // Layout change listeners |
|
428 RPointerArray< MVtUiLayoutChangeObserver > iLayoutChangeObservers; |
|
429 |
|
430 // Registered components |
|
431 RPointerArray< TVtUiComponentState > iComponents; |
|
432 |
|
433 }; |
|
434 |
|
435 #endif // C_VTUICOMPONENTMANAGER_H |