|
1 /* |
|
2 * Copyright (c) 2007-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: Implementation for CAknSingleColumnStyleSimpleDataRow class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <AknUtils.h> |
|
20 #include <aknlayoutscalable_avkon.cdl.h> |
|
21 |
|
22 #include "akntree.h" |
|
23 #include "aknsinglecolumnstylesimpledatarow.h" |
|
24 #include "akntreelistinternalconstants.h" |
|
25 |
|
26 using AknTreeListIconID::KDefault; |
|
27 using AknTreeListIconID::KNone; |
|
28 |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // Two-phased constructor. |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CAknSingleColumnStyleSimpleDataRow* CAknSingleColumnStyleSimpleDataRow::NewLC( |
|
37 const TDesC& aText, TUint32 aFlags ) |
|
38 { |
|
39 CAknSingleColumnStyleSimpleDataRow* self = |
|
40 new ( ELeave ) CAknSingleColumnStyleSimpleDataRow( aFlags ); |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL( aText ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // Destructor. |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CAknSingleColumnStyleSimpleDataRow::~CAknSingleColumnStyleSimpleDataRow() |
|
52 { |
|
53 delete iText; |
|
54 } |
|
55 |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Returns the text set for the simple data row. |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 const TDesC& CAknSingleColumnStyleSimpleDataRow::Text() const |
|
62 { |
|
63 return iText ? *iText : KNullDesC(); |
|
64 } |
|
65 |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // Allocates new heap based descriptor for the text, and if the allocation |
|
69 // succeeds, deletes the old descriptor and replaces it with the new. |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 void CAknSingleColumnStyleSimpleDataRow::SetTextL( const TDesC& aText, |
|
73 TBool aDrawNow ) |
|
74 { |
|
75 HBufC* tmp = aText.AllocL(); |
|
76 delete iText; |
|
77 iText = tmp; |
|
78 |
|
79 if ( aDrawNow ) |
|
80 { |
|
81 __ASSERT_DEBUG( Root(), User::Invariant() ); |
|
82 Root()->ItemModified( this ); |
|
83 } |
|
84 } |
|
85 |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // Returns the icon ID set for the specified simple data row icon type. |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 TInt CAknSingleColumnStyleSimpleDataRow::Icon( TIconType aType ) const |
|
92 { |
|
93 TInt iconId = KDefault; |
|
94 switch ( aType ) |
|
95 { |
|
96 case EIcon: |
|
97 iconId = iIcon; |
|
98 break; |
|
99 |
|
100 case EOptIcon: |
|
101 iconId = iOptIcon; |
|
102 break; |
|
103 |
|
104 case EHighlightedIcon: |
|
105 iconId = iHighlightedIcon; |
|
106 break; |
|
107 |
|
108 case EHighlightedOptIcon: |
|
109 iconId = iHighlightedOptIcon; |
|
110 break; |
|
111 |
|
112 default: |
|
113 break; |
|
114 } |
|
115 return iconId; |
|
116 } |
|
117 |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // Sets the icon ID for specified simple row icon type. |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 void CAknSingleColumnStyleSimpleDataRow::SetIcon( TIconType aType, |
|
124 TInt aIconId, TBool aDrawNow ) |
|
125 { |
|
126 switch( aType ) |
|
127 { |
|
128 case EIcon: |
|
129 iIcon = aIconId; |
|
130 break; |
|
131 |
|
132 case EOptIcon: |
|
133 iOptIcon = aIconId; |
|
134 break; |
|
135 |
|
136 case EHighlightedIcon: |
|
137 iHighlightedIcon = aIconId; |
|
138 break; |
|
139 |
|
140 case EHighlightedOptIcon: |
|
141 iHighlightedOptIcon = aIconId; |
|
142 break; |
|
143 |
|
144 default: |
|
145 __ASSERT_DEBUG( EFalse, User::Invariant() ); |
|
146 break; |
|
147 } |
|
148 |
|
149 if ( aDrawNow ) |
|
150 { |
|
151 __ASSERT_DEBUG( Root(), User::Invariant() ); |
|
152 Root()->ItemModified( this ); |
|
153 } |
|
154 } |
|
155 |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // Icon ID. |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 TInt CAknSingleColumnStyleSimpleDataRow::IconId( TBool aFocused ) const |
|
162 { |
|
163 // Default ID for icon. |
|
164 TInt iconId = KNone; |
|
165 |
|
166 // Determines ID for the icon based on focusing and set IDs. |
|
167 if ( aFocused && iHighlightedIcon != KDefault ) |
|
168 { |
|
169 iconId = iHighlightedIcon; |
|
170 } |
|
171 else if ( iIcon != KDefault ) |
|
172 { |
|
173 iconId = iIcon; |
|
174 } |
|
175 |
|
176 return iconId; |
|
177 } |
|
178 |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // Optional icon ID. |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 TInt CAknSingleColumnStyleSimpleDataRow::OptionalIconId( TBool aFocused ) const |
|
185 { |
|
186 // Default ID for optional icon. |
|
187 TInt iconId = KNone; |
|
188 |
|
189 // Determines ID for the optional icon based on focusing, item marking, |
|
190 // and set optional icon IDs. |
|
191 if ( IsMarked() ) |
|
192 { |
|
193 iconId = aFocused ? AknTreeListIconID::KHighlightedMarkedIndication : |
|
194 AknTreeListIconID::KMarkedIndication; |
|
195 } |
|
196 else if ( aFocused && iHighlightedOptIcon != KDefault ) |
|
197 { |
|
198 iconId = iHighlightedOptIcon; |
|
199 } |
|
200 else if ( iOptIcon != KDefault ) |
|
201 { |
|
202 iconId = iOptIcon; |
|
203 } |
|
204 |
|
205 return iconId; |
|
206 } |
|
207 |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // From class CAknTreeItem. |
|
211 // Returns the type of concrete item class. |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 TInt CAknSingleColumnStyleSimpleDataRow::Type() const |
|
215 { |
|
216 return AknTreeList::KSingleColumnStyleSimpleDataRow; |
|
217 } |
|
218 |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // From class CAknTreeItem. |
|
222 // Draws the simple data row to the appointed graphics context. |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 void CAknSingleColumnStyleSimpleDataRow::Draw( CWindowGc& aGc, |
|
226 const TRect& aItemRect, const TRect& /*aRect*/, TBool aFocused ) const |
|
227 { |
|
228 CAknTree* root = Root(); |
|
229 __ASSERT_DEBUG( root, User::Invariant() ); |
|
230 |
|
231 // Icon. |
|
232 TInt iconVariety = IsMarked() ? 1 : 0; |
|
233 TRect iconRect = RectFromLayout( aItemRect, AknLayoutScalable_Avkon:: |
|
234 list_single_2heading_msg_pane_g1( iconVariety ) ); |
|
235 |
|
236 TInt iconId = IconId( aFocused ); |
|
237 if ( iIcon != AknTreeListIconID::KNone ) |
|
238 { |
|
239 root->DrawIcon( iconId, iconRect.Size(), aGc, iconRect.iTl, |
|
240 iconRect.Size() ); |
|
241 } |
|
242 |
|
243 // Optional icon ID. |
|
244 TInt optIconId = OptionalIconId( aFocused ); |
|
245 |
|
246 // Text. |
|
247 TAknLayoutText layoutText; |
|
248 TInt textVariety = ( optIconId == KNone ) ? 0 : 1; |
|
249 layoutText.LayoutText( aItemRect, AknLayoutScalable_Avkon:: |
|
250 list_single_2heading_msg_pane_t1( textVariety ).LayoutLine() ); |
|
251 root->DrawText( aGc, aItemRect, AknLayoutScalable_Avkon:: |
|
252 list_single_2heading_msg_pane_t1( textVariety ), *iText, NULL, |
|
253 this, aFocused, ETrue ); |
|
254 |
|
255 // Optional indication icon. |
|
256 TInt optIconVariety = 0; // Marked folder. |
|
257 TRect optIconRect = RectFromLayout( aItemRect, AknLayoutScalable_Avkon:: |
|
258 list_single_2heading_msg_pane_g2( optIconVariety ) ); |
|
259 if ( optIconId != KNone ) |
|
260 { |
|
261 root->DrawIcon( optIconId, optIconRect.Size(), aGc, |
|
262 optIconRect.iTl, optIconRect.Size() ); |
|
263 } |
|
264 } |
|
265 |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // From class CAknTreeItem. |
|
269 // Handles pointer events. |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 void CAknSingleColumnStyleSimpleDataRow::HandlePointerEventL( |
|
273 const TPointerEvent& /*aPointerEvent*/, const TRect& /*aItemRect*/ ) |
|
274 { |
|
275 } |
|
276 |
|
277 |
|
278 // --------------------------------------------------------------------------- |
|
279 // C++ constructor. |
|
280 // --------------------------------------------------------------------------- |
|
281 // |
|
282 CAknSingleColumnStyleSimpleDataRow::CAknSingleColumnStyleSimpleDataRow( |
|
283 TUint32 aFlags ) |
|
284 : CAknTreeLeaf( aFlags ), |
|
285 iIcon( KDefault ), |
|
286 iOptIcon( KDefault ), |
|
287 iHighlightedIcon( KDefault ), |
|
288 iHighlightedOptIcon( KDefault ) |
|
289 { |
|
290 } |
|
291 |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // Second phase constructor. |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 void CAknSingleColumnStyleSimpleDataRow::ConstructL( const TDesC& aText ) |
|
298 { |
|
299 iText = aText.AllocL(); |
|
300 } |
|
301 |
|
302 |