|
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: Implementation for single style tree ordering. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "aknsinglestyletreeordering.h" |
|
20 #include "aknsinglestyletreenode.h" |
|
21 #include "aknsinglestyletreeleaf.h" |
|
22 |
|
23 |
|
24 // ======== MEMBER FUNCTIONS ======== |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // Two-phased constructor. |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CAknSingleStyleTreeOrdering* CAknSingleStyleTreeOrdering::NewL( |
|
31 TOrderingType aType ) |
|
32 { |
|
33 CAknSingleStyleTreeOrdering* self = CAknSingleStyleTreeOrdering::NewLC( |
|
34 aType ); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // Two phased constructor. |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CAknSingleStyleTreeOrdering* CAknSingleStyleTreeOrdering::NewLC( |
|
45 TOrderingType aType ) |
|
46 { |
|
47 CAknSingleStyleTreeOrdering* self = |
|
48 new ( ELeave ) CAknSingleStyleTreeOrdering( aType ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // Destructor. |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CAknSingleStyleTreeOrdering::~CAknSingleStyleTreeOrdering() |
|
60 { |
|
61 } |
|
62 |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // From class CAknTreeOrdering. |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 TInt CAknSingleStyleTreeOrdering::Compare( const CAknTreeItem& aFirst, |
|
69 const CAknTreeItem& aSecond ) |
|
70 { |
|
71 TInt comparisonValue = NULL; |
|
72 if ( aFirst.IsLeaf() && aSecond.IsLeaf() ) |
|
73 { |
|
74 const TDesC& first = |
|
75 static_cast<const CAknSingleStyleTreeLeaf&>( aFirst ).Text(); |
|
76 |
|
77 const TDesC& second = |
|
78 static_cast<const CAknSingleStyleTreeLeaf&>( aSecond ).Text(); |
|
79 |
|
80 comparisonValue = first.CompareC( second ); |
|
81 } |
|
82 else if ( aFirst.IsLeaf() && aSecond.IsNode() ) |
|
83 { |
|
84 comparisonValue = 1; |
|
85 } |
|
86 else if ( aFirst.IsNode() && aSecond.IsLeaf() ) |
|
87 { |
|
88 comparisonValue = -1; |
|
89 } |
|
90 else // Both items are nodes |
|
91 { |
|
92 __ASSERT_DEBUG( aFirst.IsNode(), User::Invariant() ); |
|
93 __ASSERT_DEBUG( aSecond.IsNode(), User::Invariant() ); |
|
94 |
|
95 const TDesC& first = |
|
96 static_cast<const CAknSingleStyleTreeNode&>( aFirst ).Text(); |
|
97 |
|
98 const TDesC& second = |
|
99 static_cast<const CAknSingleStyleTreeNode&>( aSecond ).Text(); |
|
100 |
|
101 comparisonValue = first.CompareC( second ); |
|
102 } |
|
103 |
|
104 if ( iType == EDescending ) |
|
105 { |
|
106 comparisonValue *= -1; |
|
107 } |
|
108 |
|
109 return comparisonValue; |
|
110 } |
|
111 |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // Default C++ constructor. |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 CAknSingleStyleTreeOrdering::CAknSingleStyleTreeOrdering( TOrderingType aType ) |
|
118 : iType( aType ) |
|
119 { |
|
120 } |
|
121 |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // Second phase constructor. |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 void CAknSingleStyleTreeOrdering::ConstructL() |
|
128 { |
|
129 } |
|
130 |
|
131 |