|
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 CAknTreeListIcon class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <AknsUtils.h> |
|
20 #include <AknIconUtils.h> |
|
21 |
|
22 #include "akntreelisticon.h" |
|
23 |
|
24 // Flag definitions. |
|
25 enum TAknTreeListIconFlags |
|
26 { |
|
27 EFlagColored, // Icon is color skinned. |
|
28 EFlagReloadable, // Parameters for reloading the icon are stored in class. |
|
29 EFlagBitmapsOwnedExternally |
|
30 }; |
|
31 |
|
32 |
|
33 // ======== MEMBER FUNCTIONS ======== |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // Two-phased constructor. |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CAknTreeListIcon* CAknTreeListIcon::NewLC( TInt aIconId, const TAknsItemID& aId, |
|
40 const TDesC& aFilename, TInt aBitmapId, TInt aMaskId, |
|
41 TScaleMode aScaleMode ) |
|
42 { |
|
43 CAknTreeListIcon* self = new ( ELeave ) CAknTreeListIcon( aIconId, aId, |
|
44 aBitmapId, aMaskId, aScaleMode ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL( aFilename ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // Two-phased constructor. |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CAknTreeListIcon* CAknTreeListIcon::NewLC( TInt aIconId, CFbsBitmap* aIcon, |
|
56 CFbsBitmap* aMask, TBool aTransferOwnership, TScaleMode aScaleMode ) |
|
57 { |
|
58 CAknTreeListIcon* self = new ( ELeave ) CAknTreeListIcon( aIconId, |
|
59 aIcon, aMask, aTransferOwnership, aScaleMode ); |
|
60 CleanupStack::PushL( self ); |
|
61 return self; |
|
62 } |
|
63 |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // Two-phased constructor. |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CAknTreeListIcon* CAknTreeListIcon::NewLC( TInt aIconId, const TAknsItemID& aId, |
|
70 const TAknsItemID& aColorId, TInt aColorIndex, const TDesC& aFilename, |
|
71 TInt aBitmapId, TInt aMaskId, TRgb aDefaultColor, TScaleMode aScaleMode ) |
|
72 { |
|
73 CAknTreeListIcon* self = new ( ELeave ) CAknTreeListIcon( aIconId, aId, |
|
74 aColorId, aColorIndex, aBitmapId, aMaskId, aDefaultColor, aScaleMode ); |
|
75 CleanupStack::PushL( self ); |
|
76 self->ConstructL( aFilename ); |
|
77 return self; |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // Destructor. |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 CAknTreeListIcon::~CAknTreeListIcon() |
|
86 { |
|
87 delete iFilename; |
|
88 |
|
89 if ( iFlags.IsClear( EFlagBitmapsOwnedExternally ) ) |
|
90 { |
|
91 delete iBitmap; |
|
92 delete iMask; |
|
93 } |
|
94 |
|
95 iBitmap = NULL; |
|
96 iMask = NULL; |
|
97 } |
|
98 |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // Compares given two tree list icons. |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 TInt CAknTreeListIcon::Compare( const CAknTreeListIcon& aFirst, |
|
105 const CAknTreeListIcon& aSecond ) |
|
106 { |
|
107 TInt id = aFirst.Id(); |
|
108 return CompareId( &id, aSecond ); |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // Compares icon ID with the one in given tree list icons. |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 TInt CAknTreeListIcon::CompareId( const TInt* aIconId, |
|
117 const CAknTreeListIcon& aIcon ) |
|
118 { |
|
119 TInt value = NULL; |
|
120 TInt id1 = *aIconId; |
|
121 TInt id2 = aIcon.Id(); |
|
122 |
|
123 if ( id1 < id2 ) |
|
124 { |
|
125 value = -1; |
|
126 } |
|
127 else if ( id1 > id2 ) |
|
128 { |
|
129 value = 1; |
|
130 } |
|
131 |
|
132 return value; |
|
133 } |
|
134 |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // Reconstructs the bitmap and mask for the icon. |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 void CAknTreeListIcon::ReconstructL() |
|
141 { |
|
142 if ( iFlags.IsSet( EFlagReloadable ) ) |
|
143 { |
|
144 CFbsBitmap* bitmap = NULL; |
|
145 CFbsBitmap* mask = NULL; |
|
146 |
|
147 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
148 if ( iFlags.IsSet( EFlagColored ) ) |
|
149 { |
|
150 AknsUtils::CreateColorIconL( skin, iId, iColorId, iColorIndex, |
|
151 bitmap, mask, *iFilename, iBitmapId, iMaskId, iDefaultColor, |
|
152 iSize, iScaleMode ); |
|
153 } |
|
154 else |
|
155 { |
|
156 AknsUtils::CreateIconL( skin, iId, bitmap, mask, *iFilename, |
|
157 iBitmapId, iMaskId ); |
|
158 AknIconUtils::SetSize( bitmap, iSize, iScaleMode ); |
|
159 } |
|
160 |
|
161 delete iBitmap; |
|
162 iBitmap = bitmap; |
|
163 |
|
164 delete iMask; |
|
165 iMask = mask; |
|
166 } |
|
167 } |
|
168 |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // Returns the ID assigned for the tree list icon. |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 TInt CAknTreeListIcon::Id() const |
|
175 { |
|
176 return iIconId; |
|
177 } |
|
178 |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // Returns the icon's skin item ID. |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 const TAknsItemID& CAknTreeListIcon::SkinItemID() const |
|
185 { |
|
186 return iId; |
|
187 } |
|
188 |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // Returns pointer to the bitmap. |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 CFbsBitmap* CAknTreeListIcon::Bitmap() |
|
195 { |
|
196 return iBitmap; |
|
197 } |
|
198 |
|
199 |
|
200 // --------------------------------------------------------------------------- |
|
201 // Returns pointer to the mask. |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 CFbsBitmap* CAknTreeListIcon::Mask() |
|
205 { |
|
206 return iMask; |
|
207 } |
|
208 |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // Returns the icon's size. |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 TSize CAknTreeListIcon::Size() const |
|
215 { |
|
216 return iSize; |
|
217 } |
|
218 |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // Returns the icon's scale mode. |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 TScaleMode CAknTreeListIcon::ScaleMode() const |
|
225 { |
|
226 return iScaleMode; |
|
227 } |
|
228 |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // Sets new icon size and scale mode. |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 TInt CAknTreeListIcon::SetSize( const TSize& aSize ) |
|
235 { |
|
236 TInt error = KErrNone; |
|
237 if ( iSize != aSize ) |
|
238 { |
|
239 iSize = aSize; |
|
240 error = AknIconUtils::SetSize( iBitmap, iSize, iScaleMode ); |
|
241 } |
|
242 return error; |
|
243 } |
|
244 |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // C++ constructor. |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 CAknTreeListIcon::CAknTreeListIcon( TInt aIconId, const TAknsItemID& aId, |
|
251 TInt aBitmapId, TInt aMaskId, TScaleMode aScaleMode ) |
|
252 : iIconId( aIconId ), |
|
253 iId( aId ), |
|
254 iBitmapId( aBitmapId ), |
|
255 iMaskId( aMaskId ), |
|
256 iScaleMode( aScaleMode ) |
|
257 { |
|
258 iFlags.Set( EFlagReloadable ); |
|
259 } |
|
260 |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // C++ constructor. |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 CAknTreeListIcon::CAknTreeListIcon( TInt aIconId, CFbsBitmap* aIcon, |
|
267 CFbsBitmap* aMask, TBool aTransferOwnership, TScaleMode aScaleMode ) |
|
268 : iIconId( aIconId ), |
|
269 iId( KAknsIIDNone ), |
|
270 iBitmap( aIcon ), |
|
271 iMask( aMask ), |
|
272 iScaleMode( aScaleMode ) |
|
273 { |
|
274 iFlags.Assign( EFlagBitmapsOwnedExternally, !aTransferOwnership ); |
|
275 } |
|
276 |
|
277 |
|
278 // --------------------------------------------------------------------------- |
|
279 // C++ constructor. |
|
280 // --------------------------------------------------------------------------- |
|
281 // |
|
282 CAknTreeListIcon::CAknTreeListIcon( TInt aIconId, const TAknsItemID& aId, |
|
283 const TAknsItemID& aColorId, TInt aColorIndex, TInt aBitmapId, |
|
284 TInt aMaskId, TRgb aDefaultColor, TScaleMode aScaleMode ) |
|
285 : iIconId( aIconId ), |
|
286 iId( aId ), |
|
287 iColorId( aColorId ), |
|
288 iColorIndex( aColorIndex ), |
|
289 iBitmapId( aBitmapId ), |
|
290 iMaskId( aMaskId ), |
|
291 iDefaultColor( aDefaultColor ), |
|
292 iScaleMode( aScaleMode ) |
|
293 { |
|
294 iFlags.Set( EFlagReloadable ); |
|
295 iFlags.Set( EFlagColored ); |
|
296 } |
|
297 |
|
298 |
|
299 // --------------------------------------------------------------------------- |
|
300 // Second phase constructor. |
|
301 // --------------------------------------------------------------------------- |
|
302 // |
|
303 void CAknTreeListIcon::ConstructL( const TDesC& aFilename ) |
|
304 { |
|
305 iFilename = aFilename.AllocL(); |
|
306 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
307 if ( iFlags.IsSet( EFlagColored ) ) |
|
308 { |
|
309 AknsUtils::CreateColorIconL( skin, iId, iColorId, iColorIndex, |
|
310 iBitmap, iMask, *iFilename, iBitmapId, iMaskId, iDefaultColor ); |
|
311 } |
|
312 else |
|
313 { |
|
314 AknsUtils::CreateIconL( skin, iId, iBitmap, iMask, *iFilename, |
|
315 iBitmapId, iMaskId ); |
|
316 } |
|
317 } |
|
318 |