|
1 /* |
|
2 * Copyright (c) 2008 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: Data class to hold view data info |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <babitflags.h> |
|
20 |
|
21 // User includes |
|
22 #include "xncomposer.h" |
|
23 #include "xnodtparser.h" |
|
24 #include "xnviewmanager.h" |
|
25 #include "xnviewdata.h" |
|
26 #include "xncontroladapter.h" |
|
27 #include "xndomnode.h" |
|
28 #include "xnnode.h" |
|
29 #include "xnoomsyshandler.h" |
|
30 |
|
31 // Constants |
|
32 _LIT8( KStateConfirmed, "Confirmed" ); |
|
33 _LIT8( KStateError, "Error" ); |
|
34 _LIT8( KLockingStatusLocked, "locked" ); |
|
35 |
|
36 // ============================ LOCAL FUNCTIONS ================================ |
|
37 |
|
38 // ============================ MEMBER FUNCTIONS =============================== |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CXnViewData::NewL() |
|
41 // Two-phased constructor. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CXnViewData* CXnViewData::NewL( CXnPluginData& aParent ) |
|
45 { |
|
46 CXnViewData* self = CXnViewData::NewLC( aParent ); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CXnViewData::NewLC() |
|
53 // Two-phased constructor. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CXnViewData* CXnViewData::NewLC( CXnPluginData& aParent ) |
|
57 { |
|
58 CXnViewData* self = new ( ELeave ) CXnViewData( aParent ); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CXnViewData::CXnViewData() |
|
66 // C++ default constructor |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CXnViewData::CXnViewData( CXnPluginData& aParent ) |
|
70 : CXnPluginData( aParent ) |
|
71 { |
|
72 // By default view data is removable |
|
73 iFlags.Set( EIsRemovable ); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CXnViewData::~CXnViewData() |
|
78 // C++ default destructor. |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CXnViewData::~CXnViewData() |
|
82 { |
|
83 Destroy(); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CXnViewData::ConstructL() |
|
88 // 2nd phase constructor |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void CXnViewData::ConstructL() |
|
92 { |
|
93 CXnPluginData::ConstructL(); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CXnViewData::SetActiveL() |
|
98 // |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 void CXnViewData::SetActiveL( TBool aActive ) |
|
102 { |
|
103 TBool active( Active() ); |
|
104 |
|
105 if ( active == aActive || !Occupied() ) |
|
106 { |
|
107 return; |
|
108 } |
|
109 |
|
110 if ( aActive ) |
|
111 { |
|
112 iFlags.Clear( EIsInitial ); |
|
113 |
|
114 iFlags.Set( EIsActive ); |
|
115 |
|
116 LoadDataPluginsL(); |
|
117 } |
|
118 else |
|
119 { |
|
120 DestroyDataPluginsL(); |
|
121 |
|
122 iFlags.Clear( EIsActive ); |
|
123 } |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CXnViewData::LoadL() |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 void CXnViewData::LoadL() |
|
132 { |
|
133 if ( Occupied() || PluginState().CompareF( KStateError ) == 0 ) |
|
134 { |
|
135 return; |
|
136 } |
|
137 |
|
138 if ( !CXnOomSysHandler::HeapAvailable( VIEW_MIN_MEM ) ) |
|
139 { |
|
140 ViewManager().OomSysHandler().HandlePotentialOomL(); |
|
141 return; |
|
142 } |
|
143 |
|
144 TRAPD( error, |
|
145 |
|
146 if( iManager.Composer().ComposeViewL( *this ) == KErrNone ) |
|
147 { |
|
148 iManager.Parser().LoadViewL( *this ); |
|
149 } |
|
150 ); |
|
151 |
|
152 if ( error || !Occupied() ) |
|
153 { |
|
154 if( error == KErrNoMemory ) |
|
155 { |
|
156 ViewManager().OomSysHandler().HandlePotentialOomL(); |
|
157 } |
|
158 |
|
159 // Set error state |
|
160 iFlags.Clear( EIsInitial ); |
|
161 |
|
162 SetPluginStateL( KStateError ); |
|
163 } |
|
164 else |
|
165 { |
|
166 // Must confirm here, as widgets loading may fail, which |
|
167 // then results his view to be doomed unnceccesarily |
|
168 SetPluginStateL( KStateConfirmed ); |
|
169 |
|
170 // Load view initial widgets |
|
171 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
172 { |
|
173 if ( iPluginsData[i]->PluginId() != KNullDesC8 ) |
|
174 { |
|
175 iPluginsData[i]->LoadL(); |
|
176 } |
|
177 } |
|
178 |
|
179 if ( Active() ) |
|
180 { |
|
181 LoadDataPluginsL(); |
|
182 } |
|
183 } |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CXnViewData::Destroy() |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 void CXnViewData::Destroy() |
|
192 { |
|
193 if ( Occupied() ) |
|
194 { |
|
195 TRAP_IGNORE( DestroyDataPluginsL() ); |
|
196 |
|
197 iManager.Parser().DestroyView( *this ); |
|
198 } |
|
199 |
|
200 Flush(); |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CXnViewData::Plugin() |
|
205 // Finds plugin or view data based on node |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 CXnPluginData& CXnViewData::Plugin( CXnNode* aNode ) |
|
209 { |
|
210 if ( aNode->ViewNodeImpl() ) |
|
211 { |
|
212 // Reached view, return self |
|
213 if ( Node()->LayoutNode() == aNode ) |
|
214 { |
|
215 return *this; |
|
216 } |
|
217 } |
|
218 |
|
219 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
220 { |
|
221 if ( iPluginsData[i]->Owner()->LayoutNode() == aNode ) |
|
222 { |
|
223 return *iPluginsData[i]; |
|
224 } |
|
225 } |
|
226 |
|
227 // Not found, try parent |
|
228 CXnNode* parent( aNode->Parent() ); |
|
229 |
|
230 return Plugin( parent ); |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CXnViewData::Plugin() |
|
235 // Finds plugin or view data based on namespace |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 CXnPluginData* CXnViewData::Plugin( const TDesC8& aNamespace ) |
|
239 { |
|
240 if ( aNamespace == KNullDesC8 ) |
|
241 { |
|
242 // No namespace, return self for global access |
|
243 return this; |
|
244 } |
|
245 |
|
246 CXnDomNode* view( Node() ); |
|
247 |
|
248 if ( view && view->LayoutNode()->Namespace() == aNamespace ) |
|
249 { |
|
250 return this; |
|
251 } |
|
252 |
|
253 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
254 { |
|
255 CXnDomNode* widget( iPluginsData[i]->Node() ); |
|
256 |
|
257 if ( widget && widget->LayoutNode()->Namespace() == aNamespace ) |
|
258 { |
|
259 return iPluginsData[i]; |
|
260 } |
|
261 } |
|
262 |
|
263 return NULL; |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CXnViewData::ViewNode() |
|
268 // Returns this view data's view node |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 CXnNode* CXnViewData::ViewNode() const |
|
272 { |
|
273 return iNode->LayoutNode(); |
|
274 } |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // CXnViewData::ResourcesL() |
|
278 // Gets this view data's resources |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CXnViewData::ResourcesL( CArrayPtrSeg< CXnResource >& aList ) const |
|
282 { |
|
283 // Get my resources |
|
284 CXnPluginData::ResourcesL( aList ); |
|
285 |
|
286 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
287 { |
|
288 // And resources which my plugin holds |
|
289 iPluginsData[i]->ResourcesL( aList ); |
|
290 } |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CXnViewData::ControlsL() |
|
295 // Gets this view data's controls |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 void CXnViewData::ControlsL( RPointerArray< CXnControlAdapter >& aList ) const |
|
299 { |
|
300 // Get my controls |
|
301 CXnPluginData::ControlsL( aList ); |
|
302 |
|
303 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
304 { |
|
305 // And controls which my plugin holds |
|
306 iPluginsData[i]->ControlsL( aList ); |
|
307 } |
|
308 } |
|
309 |
|
310 // ----------------------------------------------------------------------------- |
|
311 // CXnViewData::PluginNodesL() |
|
312 // Gets this view data's appearance nodes |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 void CXnViewData::AppearanceNodesL( RPointerArray< CXnNode >& aList ) const |
|
316 { |
|
317 // Get my appearance nodes |
|
318 CXnPluginData::AppearanceNodesL( aList ); |
|
319 |
|
320 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
321 { |
|
322 // And appearance nodes which my plugin holds |
|
323 iPluginsData[i]->AppearanceNodesL( aList ); |
|
324 } |
|
325 } |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CXnViewData::InitialFocusNodesL() |
|
329 // Gets this view data's initial focus nodes |
|
330 // ----------------------------------------------------------------------------- |
|
331 // |
|
332 void CXnViewData::InitialFocusNodesL( RPointerArray< CXnNode >& aList ) const |
|
333 { |
|
334 // Offer widgets initial focus nodes by default first |
|
335 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
336 { |
|
337 // And appearance nodes which my plugin holds |
|
338 iPluginsData[i]->InitialFocusNodesL( aList ); |
|
339 } |
|
340 |
|
341 // Get my initial focus nodes |
|
342 CXnPluginData::InitialFocusNodesL( aList ); |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CXnViewData::ContentSourceNodesL() |
|
347 // Gets this view data's content source nodes |
|
348 // ----------------------------------------------------------------------------- |
|
349 // |
|
350 void CXnViewData::ContentSourceNodesL( RPointerArray< CXnNode >& aList ) const |
|
351 { |
|
352 // Get my data provider nodes |
|
353 CXnPluginData::ContentSourceNodesL( aList ); |
|
354 |
|
355 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
356 { |
|
357 // And appearance nodes which my plugin holds |
|
358 iPluginsData[i]->ContentSourceNodesL( aList ); |
|
359 } |
|
360 } |
|
361 |
|
362 // ----------------------------------------------------------------------------- |
|
363 // CXnViewData::PluginNodesL() |
|
364 // Gets this view data's plugin nodes |
|
365 // ----------------------------------------------------------------------------- |
|
366 // |
|
367 void CXnViewData::PluginNodesL( RPointerArray< CXnNode >& aList ) const |
|
368 { |
|
369 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
370 { |
|
371 // And controls which my plugin holds |
|
372 aList.AppendL( iPluginsData[i]->Owner()->LayoutNode() ); |
|
373 } |
|
374 } |
|
375 |
|
376 // ----------------------------------------------------------------------------- |
|
377 // CXnViewData::LoadDataPluginsL |
|
378 // Loads data plugins associated to the plugin |
|
379 // ----------------------------------------------------------------------------- |
|
380 // |
|
381 void CXnViewData::LoadDataPluginsL() |
|
382 { |
|
383 if( Occupied() && Active() ) |
|
384 { |
|
385 // Load own plugins first, and after that data plugins for widgets |
|
386 CXnPluginData::LoadDataPluginsL(); |
|
387 } |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CXnPluginData::DataPluginsLoadCompletedL |
|
392 // Indicates that all data plugins are loaded |
|
393 // ----------------------------------------------------------------------------- |
|
394 // |
|
395 void CXnViewData::DataPluginsLoadCompletedL( TInt aStatus ) |
|
396 { |
|
397 if ( aStatus == KErrNone ) |
|
398 { |
|
399 for( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
400 { |
|
401 iPluginsData[i]->LoadDataPluginsL(); |
|
402 } |
|
403 } |
|
404 |
|
405 CXnPluginData::DataPluginsLoadCompletedL( aStatus ); |
|
406 } |
|
407 |
|
408 // ----------------------------------------------------------------------------- |
|
409 // CXnViewData::DestroyDataPluginsL |
|
410 // Remove data plugins associated to the plugin |
|
411 // ----------------------------------------------------------------------------- |
|
412 // |
|
413 void CXnViewData::DestroyDataPluginsL() |
|
414 { |
|
415 CXnPluginData::DestroyDataPluginsL(); |
|
416 |
|
417 for( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
418 { |
|
419 iPluginsData[i]->DestroyDataPluginsL(); |
|
420 } |
|
421 } |
|
422 |
|
423 // ----------------------------------------------------------------------------- |
|
424 // CXnPluginData::DataPluginsLoaded() |
|
425 // ----------------------------------------------------------------------------- |
|
426 // |
|
427 TBool CXnViewData::DataPluginsLoaded() const |
|
428 { |
|
429 TBool loaded( CXnPluginData::DataPluginsLoaded() ); |
|
430 |
|
431 for( TInt i = 0; loaded && i < iPluginsData.Count(); i++ ) |
|
432 { |
|
433 CXnPluginData* plugin( iPluginsData[i] ); |
|
434 |
|
435 if( plugin->Occupied() ) |
|
436 { |
|
437 loaded = plugin->DataPluginsLoaded(); |
|
438 } |
|
439 } |
|
440 |
|
441 return loaded; |
|
442 } |
|
443 |
|
444 // ----------------------------------------------------------------------------- |
|
445 // Sets view's locking_status attribute ("locked"/"none") |
|
446 // ----------------------------------------------------------------------------- |
|
447 // |
|
448 void CXnViewData::SetLockingStatus( const TDesC8& aLockingStatusString ) |
|
449 { |
|
450 if( ( aLockingStatusString != KNullDesC8 ) && |
|
451 ( aLockingStatusString.Match( KLockingStatusLocked ) == 0 ) ) |
|
452 { |
|
453 iFlags.Clear( EIsRemovable ); |
|
454 } |
|
455 else |
|
456 { |
|
457 iFlags.Set( EIsRemovable ); |
|
458 } |
|
459 } |
|
460 // End of file |