|
1 /* |
|
2 * Copyright (c) 2006, 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: Implementation for CAknSingleStyleTreeList class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "aknsinglestyletreelist.h" |
|
20 #include "aknsinglestyletreenode.h" |
|
21 #include "aknsinglestyletreeleaf.h" |
|
22 #include "aknsinglestyletreeordering.h" |
|
23 #include "akntree.h" |
|
24 #include "aknhlistlib.h" |
|
25 #include "akntreelistinternalconstants.h" |
|
26 #include "akntreelistview.h" |
|
27 |
|
28 #include <AknTasHook.h> // for testability hooks |
|
29 /** Set of flags that cannot be set for single style hierarchical list. */ |
|
30 const TInt KRestrictedListFlags = KAknTreeListMarkable; |
|
31 |
|
32 |
|
33 // ======== MEMBER FUNCTIONS ======== |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // Two-phased constructor. |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 EXPORT_C CAknSingleStyleTreeList* CAknSingleStyleTreeList::NewL() |
|
40 { |
|
41 CAknSingleStyleTreeList* self = CAknSingleStyleTreeList::NewLC(); |
|
42 CleanupStack::Pop( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // Two-phased constructor. |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 EXPORT_C CAknSingleStyleTreeList* CAknSingleStyleTreeList::NewLC() |
|
52 { |
|
53 CAknSingleStyleTreeList* self = new( ELeave ) CAknSingleStyleTreeList; |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL(); |
|
56 AKNTASHOOK_ADDL( self, "CAknSingleStyleTreeList" ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // Two-phased constructor. |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C CAknSingleStyleTreeList* CAknSingleStyleTreeList::NewL( |
|
66 const CCoeControl& aContainer ) |
|
67 { |
|
68 CAknSingleStyleTreeList* self |
|
69 = CAknSingleStyleTreeList::NewLC( aContainer ); |
|
70 CleanupStack::Pop( self ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // Two-phased constructor. |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 EXPORT_C CAknSingleStyleTreeList* CAknSingleStyleTreeList::NewLC( |
|
80 const CCoeControl& aContainer ) |
|
81 { |
|
82 CAknSingleStyleTreeList* self = new ( ELeave ) CAknSingleStyleTreeList; |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL( aContainer ); |
|
85 AKNTASHOOK_ADDL( self, "CAknSingleStyleTreeList" ); |
|
86 return self; |
|
87 } |
|
88 |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // Destructor. |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 CAknSingleStyleTreeList::~CAknSingleStyleTreeList() |
|
95 { |
|
96 AKNTASHOOK_REMOVE(); |
|
97 } |
|
98 |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // Construct and add new leaf to the tree. |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 EXPORT_C TAknTreeItemID CAknSingleStyleTreeList::AddLeafL( |
|
105 TAknTreeItemID aParent, const TDesC& aText, TUint32 aFlags, |
|
106 TBool aDrawNow ) |
|
107 { |
|
108 TUint32 flags = NULL; |
|
109 if ( aFlags & EPersistent ) |
|
110 { |
|
111 flags |= CAknSingleStyleTreeLeaf::EPersistent; |
|
112 } |
|
113 if ( aFlags & EMarked ) |
|
114 { |
|
115 flags |= CAknSingleStyleTreeLeaf::EMarked; |
|
116 } |
|
117 |
|
118 CAknSingleStyleTreeLeaf* leaf = |
|
119 CAknSingleStyleTreeLeaf::NewLC( aText, flags ); |
|
120 TAknTreeItemID id = Tree().AddItemL( leaf, aParent, aDrawNow ); |
|
121 CleanupStack::Pop( leaf ); |
|
122 return id; |
|
123 } |
|
124 |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // Construct and add new node to the tree. |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 EXPORT_C TAknTreeItemID CAknSingleStyleTreeList::AddNodeL( |
|
131 TAknTreeItemID aParent, const TDesC& aText, TUint32 aFlags, |
|
132 TBool aDrawNow ) |
|
133 { |
|
134 TUint32 flags = NULL; |
|
135 if ( aFlags & EPersistent ) |
|
136 { |
|
137 flags |= CAknSingleStyleTreeNode::EPersistent; |
|
138 } |
|
139 if ( aFlags & EMarked ) |
|
140 { |
|
141 flags |= CAknSingleStyleTreeNode::EMarked; |
|
142 } |
|
143 if ( aFlags & EExpanded ) |
|
144 { |
|
145 flags |= CAknSingleStyleTreeNode::EExpanded; |
|
146 } |
|
147 if ( aFlags & ENonEmpty ) |
|
148 { |
|
149 flags |= CAknSingleStyleTreeNode::ENonEmpty; |
|
150 } |
|
151 |
|
152 CAknSingleStyleTreeNode* node = |
|
153 CAknSingleStyleTreeNode::NewLC( aText, flags ); |
|
154 TAknTreeItemID id = Tree().AddItemL( node, aParent, aDrawNow ); |
|
155 CleanupStack::Pop( node ); |
|
156 return id; |
|
157 } |
|
158 |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // Sorts the list. |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 EXPORT_C void CAknSingleStyleTreeList::SortL( TOrdering aOrdering, |
|
165 TBool aDrawNow ) |
|
166 { |
|
167 CAknSingleStyleTreeOrdering::TOrderingType type = |
|
168 CAknSingleStyleTreeOrdering::EAscending; |
|
169 if ( aOrdering == EDescendingAlphabeticalOrdering ) |
|
170 { |
|
171 type = CAknSingleStyleTreeOrdering::EDescending; |
|
172 } |
|
173 |
|
174 CAknSingleStyleTreeOrdering* ordering = |
|
175 CAknSingleStyleTreeOrdering::NewL( type ); |
|
176 Tree().SetOrdering( ordering, aDrawNow ); |
|
177 } |
|
178 |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // Sets the given text for specified tree item. |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 EXPORT_C void CAknSingleStyleTreeList::SetTextL( TAknTreeItemID aItem, |
|
185 const TDesC& aText, TBool aDrawNow ) |
|
186 { |
|
187 CAknTreeItem* item = Tree().Item( aItem ); |
|
188 if ( item->Type() == AknTreeList::KSingleStyleTreeLeaf ) |
|
189 { |
|
190 static_cast<CAknSingleStyleTreeLeaf*>( item )->SetTextL( aText, |
|
191 aDrawNow ); |
|
192 } |
|
193 else if ( item->Type() == AknTreeList::KSingleStyleTreeNode ) |
|
194 { |
|
195 static_cast<CAknSingleStyleTreeNode*>( item )->SetTextL( aText, |
|
196 aDrawNow ); |
|
197 } |
|
198 else |
|
199 { |
|
200 Panic( EAknHListPanicInvalidItemType ); |
|
201 } |
|
202 } |
|
203 |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // Return text for the specified tree item. |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 EXPORT_C const TDesC& CAknSingleStyleTreeList::Text( TAknTreeItemID aItem ) const |
|
210 { |
|
211 CAknTreeItem* item = Tree().Item( aItem ); |
|
212 if ( item->Type() == AknTreeList::KSingleStyleTreeLeaf ) |
|
213 { |
|
214 __ASSERT_DEBUG( item->IsLeaf(), User::Invariant() ); |
|
215 return static_cast<CAknSingleStyleTreeLeaf*>( item )->Text(); |
|
216 } |
|
217 else if ( item->Type() == AknTreeList::KSingleStyleTreeNode ) |
|
218 { |
|
219 __ASSERT_DEBUG( item->IsNode(), User::Invariant() ); |
|
220 return static_cast<CAknSingleStyleTreeNode*>( item )->Text(); |
|
221 } |
|
222 else |
|
223 { |
|
224 return KNullDesC; |
|
225 } |
|
226 } |
|
227 |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // Set icon for specified item. |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 EXPORT_C void CAknSingleStyleTreeList::SetIcon( const TAknTreeItemID aItem, |
|
234 const TIconType aType, const TInt aIconId, const TBool aDrawNow ) |
|
235 { |
|
236 CAknTreeItem* item = Tree().Item( aItem ); |
|
237 if ( item->Type() == AknTreeList::KSingleStyleTreeLeaf ) |
|
238 { |
|
239 CAknSingleStyleTreeLeaf::TIconType type; |
|
240 switch ( aType ) |
|
241 { |
|
242 case ELeaf: |
|
243 type = CAknSingleStyleTreeLeaf::EIcon; |
|
244 break; |
|
245 |
|
246 case EHighlightedLeaf: |
|
247 type = CAknSingleStyleTreeLeaf::EHighlightedIcon; |
|
248 break; |
|
249 |
|
250 case EOptionalIcon1: |
|
251 type = CAknSingleStyleTreeLeaf::EOptIcon1; |
|
252 break; |
|
253 |
|
254 case EHighlightedOptionalIcon1: |
|
255 type = CAknSingleStyleTreeLeaf::EHighlightedOptIcon1; |
|
256 break; |
|
257 |
|
258 case EOptionalIcon2: |
|
259 type = CAknSingleStyleTreeLeaf::EOptIcon2; |
|
260 break; |
|
261 |
|
262 case EHighlightedOptionalIcon2: |
|
263 type = CAknSingleStyleTreeLeaf::EHighlightedOptIcon2; |
|
264 break; |
|
265 |
|
266 default: |
|
267 // Invalid icon type for tree leaf. |
|
268 Panic( EAknHListPanicInvalidItemType ); |
|
269 return; |
|
270 } |
|
271 static_cast<CAknSingleStyleTreeLeaf*>( item )->SetIcon( type, |
|
272 aIconId, aDrawNow ); |
|
273 } |
|
274 |
|
275 else if ( item->Type() == AknTreeList::KSingleStyleTreeNode ) |
|
276 { |
|
277 __ASSERT_DEBUG( item->IsNode(), User::Invariant() ); |
|
278 CAknSingleStyleTreeNode::TIconType type; |
|
279 switch ( aType ) |
|
280 { |
|
281 case EExpandedNode: |
|
282 type = CAknSingleStyleTreeNode::EExpandedIcon; |
|
283 break; |
|
284 |
|
285 case EHighlightedExpandedNode: |
|
286 type = CAknSingleStyleTreeNode::EHighlightedExpandedIcon; |
|
287 break; |
|
288 |
|
289 case ECollapsedNode: |
|
290 type = CAknSingleStyleTreeNode::ECollapsedIcon; |
|
291 break; |
|
292 |
|
293 case EHighlightedCollapsedNode: |
|
294 type = CAknSingleStyleTreeNode::EHighlightedCollapsedIcon; |
|
295 break; |
|
296 |
|
297 case EOptionalIcon1: |
|
298 type = CAknSingleStyleTreeNode::EOptIcon1; |
|
299 break; |
|
300 |
|
301 case EHighlightedOptionalIcon1: |
|
302 type = CAknSingleStyleTreeNode::EHighlightedOptIcon1; |
|
303 break; |
|
304 |
|
305 case EOptionalIcon2: |
|
306 type = CAknSingleStyleTreeNode::EOptIcon2; |
|
307 break; |
|
308 |
|
309 case EHighlightedOptionalIcon2: |
|
310 type = CAknSingleStyleTreeNode::EHighlightedOptIcon2; |
|
311 break; |
|
312 |
|
313 default: |
|
314 // Invalid icon type for tree node. |
|
315 Panic( EAknHListPanicInvalidItemType ); |
|
316 return; |
|
317 } |
|
318 static_cast<CAknSingleStyleTreeNode*>( item )->SetIcon( type, |
|
319 aIconId, aDrawNow ); |
|
320 } |
|
321 |
|
322 else |
|
323 { |
|
324 // Invalid item type. |
|
325 Panic( EAknHListPanicInvalidItemType ); |
|
326 } |
|
327 } |
|
328 |
|
329 |
|
330 // --------------------------------------------------------------------------- |
|
331 // Returns the icon ID set for the specified tree item. |
|
332 // --------------------------------------------------------------------------- |
|
333 // |
|
334 EXPORT_C TInt CAknSingleStyleTreeList::Icon( TAknTreeItemID aItem, |
|
335 TIconType aType ) const |
|
336 { |
|
337 CAknTreeItem* item = Tree().Item( aItem ); |
|
338 if ( item->Type() == AknTreeList::KSingleStyleTreeLeaf ) |
|
339 { |
|
340 CAknSingleStyleTreeLeaf::TIconType type; |
|
341 switch ( aType ) |
|
342 { |
|
343 case ELeaf: |
|
344 type = CAknSingleStyleTreeLeaf::EIcon; |
|
345 break; |
|
346 |
|
347 case EHighlightedLeaf: |
|
348 type = CAknSingleStyleTreeLeaf::EHighlightedIcon; |
|
349 break; |
|
350 |
|
351 case EOptionalIcon1: |
|
352 type = CAknSingleStyleTreeLeaf::EOptIcon1; |
|
353 break; |
|
354 |
|
355 case EHighlightedOptionalIcon1: |
|
356 type = CAknSingleStyleTreeLeaf::EHighlightedOptIcon1; |
|
357 break; |
|
358 |
|
359 case EOptionalIcon2: |
|
360 type = CAknSingleStyleTreeLeaf::EOptIcon2; |
|
361 break; |
|
362 |
|
363 case EHighlightedOptionalIcon2: |
|
364 type = CAknSingleStyleTreeLeaf::EHighlightedOptIcon2; |
|
365 break; |
|
366 |
|
367 default: |
|
368 // Invalid icon type for tree leaf. |
|
369 return KErrNotFound; |
|
370 } |
|
371 return static_cast<CAknSingleStyleTreeLeaf*>( item )->Icon( type ); |
|
372 } |
|
373 |
|
374 else if ( item->Type() == AknTreeList::KSingleStyleTreeNode ) |
|
375 { |
|
376 __ASSERT_DEBUG( item->IsNode(), User::Invariant() ); |
|
377 CAknSingleStyleTreeNode::TIconType type; |
|
378 switch ( aType ) |
|
379 { |
|
380 case EExpandedNode: |
|
381 type = CAknSingleStyleTreeNode::EExpandedIcon; |
|
382 break; |
|
383 |
|
384 case EHighlightedExpandedNode: |
|
385 type = CAknSingleStyleTreeNode::EHighlightedExpandedIcon; |
|
386 break; |
|
387 |
|
388 case ECollapsedNode: |
|
389 type = CAknSingleStyleTreeNode::ECollapsedIcon; |
|
390 break; |
|
391 |
|
392 case EHighlightedCollapsedNode: |
|
393 type = CAknSingleStyleTreeNode::EHighlightedCollapsedIcon; |
|
394 break; |
|
395 |
|
396 case EOptionalIcon1: |
|
397 type = CAknSingleStyleTreeNode::EOptIcon1; |
|
398 break; |
|
399 |
|
400 case EHighlightedOptionalIcon1: |
|
401 type = CAknSingleStyleTreeNode::EHighlightedOptIcon1; |
|
402 break; |
|
403 |
|
404 case EOptionalIcon2: |
|
405 type = CAknSingleStyleTreeNode::EOptIcon2; |
|
406 break; |
|
407 |
|
408 case EHighlightedOptionalIcon2: |
|
409 type = CAknSingleStyleTreeNode::EHighlightedOptIcon2; |
|
410 break; |
|
411 |
|
412 default: |
|
413 // Invalid icon type for tree node. |
|
414 return KErrNotFound; |
|
415 } |
|
416 return static_cast<CAknSingleStyleTreeNode*>( item )->Icon( type ); |
|
417 } |
|
418 |
|
419 else |
|
420 { |
|
421 return KErrNotFound; |
|
422 } |
|
423 } |
|
424 |
|
425 |
|
426 // --------------------------------------------------------------------------- |
|
427 // From class CAknTreeList. |
|
428 // Sets flags for the list. |
|
429 // --------------------------------------------------------------------------- |
|
430 // |
|
431 void CAknSingleStyleTreeList::SetFlags( TUint32 aFlags ) |
|
432 { |
|
433 aFlags &= ~KRestrictedListFlags; |
|
434 CAknTreeList::SetFlags( aFlags ); |
|
435 } |
|
436 |
|
437 |
|
438 // --------------------------------------------------------------------------- |
|
439 // Default C++ constructor. |
|
440 // --------------------------------------------------------------------------- |
|
441 // |
|
442 CAknSingleStyleTreeList::CAknSingleStyleTreeList() |
|
443 { |
|
444 } |
|
445 |
|
446 |
|
447 // --------------------------------------------------------------------------- |
|
448 // Second phase constructor. |
|
449 // --------------------------------------------------------------------------- |
|
450 // |
|
451 void CAknSingleStyleTreeList::ConstructL() |
|
452 { |
|
453 BaseConstructL(); |
|
454 } |
|
455 |
|
456 |
|
457 // --------------------------------------------------------------------------- |
|
458 // Second phase constructor. |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 void CAknSingleStyleTreeList::ConstructL( const CCoeControl& aContainer ) |
|
462 { |
|
463 BaseConstructL( aContainer ); |
|
464 } |
|
465 |