|
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 CAknSingleColumnStyleSubtitleRow class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <AknUtils.h> |
|
20 #include <aknlayoutscalable_avkon.cdl.h> |
|
21 |
|
22 #include "akntree.h" |
|
23 #include "aknsinglecolumnstylesubtitlerow.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 CAknSingleColumnStyleSubtitleRow* CAknSingleColumnStyleSubtitleRow::NewLC( |
|
37 const TDesC& aText, TUint32 aFlags ) |
|
38 { |
|
39 CAknSingleColumnStyleSubtitleRow* self = |
|
40 new ( ELeave ) CAknSingleColumnStyleSubtitleRow( aFlags ); |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL( aText ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // Destructor. |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CAknSingleColumnStyleSubtitleRow::~CAknSingleColumnStyleSubtitleRow() |
|
52 { |
|
53 delete iText; |
|
54 } |
|
55 |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Returns the text set for the subtitle row. |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 const TDesC& CAknSingleColumnStyleSubtitleRow::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 CAknSingleColumnStyleSubtitleRow::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 subtitle row icon type. |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 TInt CAknSingleColumnStyleSubtitleRow::Icon( TIconType aType ) const |
|
92 { |
|
93 TInt iconId = KDefault; |
|
94 switch ( aType ) |
|
95 { |
|
96 case EExpandedIcon: |
|
97 iconId = iExpandedIcon; |
|
98 break; |
|
99 |
|
100 case ECollapsedIcon: |
|
101 iconId = iCollapsedIcon; |
|
102 break; |
|
103 |
|
104 case EOptIcon: |
|
105 iconId = iOptIcon; |
|
106 break; |
|
107 |
|
108 case EHighlightedExpandedIcon: |
|
109 iconId = iHighlightedExpandedIcon; |
|
110 break; |
|
111 |
|
112 case EHighlightedCollapsedIcon: |
|
113 iconId = iHighlightedCollapsedIcon; |
|
114 break; |
|
115 |
|
116 case EHighlightedOptIcon: |
|
117 iconId = iHighlightedOptIcon; |
|
118 break; |
|
119 |
|
120 default: |
|
121 break; |
|
122 } |
|
123 return iconId; |
|
124 } |
|
125 |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // Sets the icon ID for specified subtitle row icon type. |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void CAknSingleColumnStyleSubtitleRow::SetIcon( TIconType aType, |
|
132 TInt aIconId, TBool aDrawNow ) |
|
133 { |
|
134 switch( aType ) |
|
135 { |
|
136 case EExpandedIcon: |
|
137 iExpandedIcon = aIconId; |
|
138 break; |
|
139 |
|
140 case ECollapsedIcon: |
|
141 iCollapsedIcon = aIconId; |
|
142 break; |
|
143 |
|
144 case EOptIcon: |
|
145 iOptIcon = aIconId; |
|
146 break; |
|
147 |
|
148 case EHighlightedExpandedIcon: |
|
149 iHighlightedExpandedIcon = aIconId; |
|
150 break; |
|
151 |
|
152 case EHighlightedCollapsedIcon: |
|
153 iHighlightedCollapsedIcon = aIconId; |
|
154 break; |
|
155 |
|
156 case EHighlightedOptIcon: |
|
157 iHighlightedOptIcon = aIconId; |
|
158 break; |
|
159 |
|
160 default: |
|
161 __ASSERT_DEBUG( EFalse, User::Invariant() ); |
|
162 break; |
|
163 } |
|
164 |
|
165 if ( aDrawNow ) |
|
166 { |
|
167 __ASSERT_DEBUG( Root(), User::Invariant() ); |
|
168 Root()->ItemModified( this ); |
|
169 } |
|
170 } |
|
171 |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // Icon ID. |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 TInt CAknSingleColumnStyleSubtitleRow::IconId( TBool aFocused ) const |
|
178 { |
|
179 TInt iconId = KNone; |
|
180 if ( IsExpanded() ) |
|
181 { |
|
182 iconId = CAknTree::EOpenFolderIndication; |
|
183 if ( aFocused && iHighlightedExpandedIcon != KDefault ) |
|
184 { |
|
185 iconId = iHighlightedExpandedIcon; |
|
186 } |
|
187 else if ( iExpandedIcon != KDefault ) |
|
188 { |
|
189 iconId = iExpandedIcon; |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 iconId = CAknTree::EClosedFolderIndication; |
|
195 if ( aFocused && iHighlightedCollapsedIcon != KDefault ) |
|
196 { |
|
197 iconId = iHighlightedCollapsedIcon; |
|
198 } |
|
199 else if ( iCollapsedIcon != KDefault ) |
|
200 { |
|
201 iconId = iCollapsedIcon; |
|
202 } |
|
203 } |
|
204 return iconId; |
|
205 } |
|
206 |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // Optional icon ID. |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 TInt CAknSingleColumnStyleSubtitleRow::OptionalIconId( TBool aFocused ) const |
|
213 { |
|
214 // Default ID for optional icon. |
|
215 TInt iconId = KNone; |
|
216 |
|
217 // Determines ID for the optional icon based on focusing, item marking, |
|
218 // and set optional icon IDs. |
|
219 if ( IsMarked() ) |
|
220 { |
|
221 iconId = aFocused ? AknTreeListIconID::KHighlightedMarkedIndication : |
|
222 AknTreeListIconID::KMarkedIndication; |
|
223 } |
|
224 else if ( aFocused && iHighlightedOptIcon != KDefault ) |
|
225 { |
|
226 iconId = iHighlightedOptIcon; |
|
227 } |
|
228 else if ( iOptIcon != KDefault ) |
|
229 { |
|
230 iconId = iOptIcon; |
|
231 } |
|
232 |
|
233 return iconId; |
|
234 } |
|
235 |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // From class CAknTreeItem. |
|
239 // Returns the type of concrete item class. |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 TInt CAknSingleColumnStyleSubtitleRow::Type() const |
|
243 { |
|
244 return AknTreeList::KSingleColumnStyleSubtitleRow; |
|
245 } |
|
246 |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // From class CAknTreeItem. |
|
250 // Draws the subtitle row to the appointed graphics context. |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 void CAknSingleColumnStyleSubtitleRow::Draw( CWindowGc& aGc, |
|
254 const TRect& aItemRect, const TRect& /*aRect*/, TBool aFocused ) const |
|
255 { |
|
256 CAknTree* root = Root(); |
|
257 __ASSERT_DEBUG( root, User::Invariant() ); |
|
258 |
|
259 // Icon. |
|
260 TInt iconVariety = IsMarked() ? 3 : 2; |
|
261 TRect iconRect = RectFromLayout( aItemRect, AknLayoutScalable_Avkon:: |
|
262 list_single_2heading_msg_pane_g1( iconVariety ) ); |
|
263 |
|
264 TInt iconId = IconId( aFocused ); |
|
265 |
|
266 if ( iconId != AknTreeListIconID::KNone ) |
|
267 { |
|
268 root->DrawIcon( iconId, iconRect.Size(), aGc, iconRect.iTl, |
|
269 iconRect.Size() ); |
|
270 } |
|
271 |
|
272 // Non-empty folder indication icon. |
|
273 if ( !IsEmpty() ) |
|
274 { |
|
275 TInt indicatorId = IsExpanded() ? |
|
276 CAknTree::ECollapseFunctionIndication : |
|
277 CAknTree::EExpandFunctionIndication; |
|
278 |
|
279 root->DrawIcon( indicatorId, iconRect.Size(), aGc, iconRect.iTl, |
|
280 iconRect.Size() ); |
|
281 } |
|
282 |
|
283 // Optional icon ID. |
|
284 TInt optIconId = OptionalIconId( aFocused ); |
|
285 |
|
286 // Text. |
|
287 TAknLayoutText layoutText; |
|
288 TInt textVariety = ( optIconId == KNone ) ? 2 : 3; |
|
289 layoutText.LayoutText( aItemRect, AknLayoutScalable_Avkon:: |
|
290 list_single_2heading_msg_pane_t1( textVariety ).LayoutLine() ); |
|
291 |
|
292 root->DrawText( aGc, aItemRect, AknLayoutScalable_Avkon:: |
|
293 list_single_2heading_msg_pane_t1( textVariety ), *iText, NULL, |
|
294 this, aFocused, ETrue ); |
|
295 |
|
296 // Optional indication icon. |
|
297 TInt optIconVariety = 1; // Sorting group. Marked. |
|
298 TRect optIconRect = RectFromLayout( aItemRect, AknLayoutScalable_Avkon:: |
|
299 list_single_2heading_msg_pane_g2( optIconVariety ) ); |
|
300 if ( optIconId != KNone ) |
|
301 { |
|
302 root->DrawIcon( optIconId, optIconRect.Size(), aGc, |
|
303 optIconRect.iTl, optIconRect.Size() ); |
|
304 } |
|
305 } |
|
306 |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // From class CAknTreeItem. |
|
310 // Handles pointer events. |
|
311 // --------------------------------------------------------------------------- |
|
312 // |
|
313 void CAknSingleColumnStyleSubtitleRow::HandlePointerEventL( |
|
314 const TPointerEvent& /*aPointerEvent*/, const TRect& /*aItemRect*/ ) |
|
315 { |
|
316 } |
|
317 |
|
318 |
|
319 // --------------------------------------------------------------------------- |
|
320 // C++ constructor. |
|
321 // --------------------------------------------------------------------------- |
|
322 // |
|
323 CAknSingleColumnStyleSubtitleRow::CAknSingleColumnStyleSubtitleRow( |
|
324 TUint32 aFlags ) |
|
325 : CAknTreeNode( aFlags ), |
|
326 iExpandedIcon( KDefault ), |
|
327 iCollapsedIcon( KDefault ), |
|
328 iOptIcon( KDefault ), |
|
329 iHighlightedExpandedIcon( KDefault ), |
|
330 iHighlightedCollapsedIcon( KDefault ), |
|
331 iHighlightedOptIcon( KDefault ) |
|
332 { |
|
333 } |
|
334 |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // Second phase constructor. |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 void CAknSingleColumnStyleSubtitleRow::ConstructL( const TDesC& aText ) |
|
341 { |
|
342 iText = aText.AllocL(); |
|
343 } |
|
344 |
|
345 |
|
346 |