|
1 /* |
|
2 * Copyright (c) 2002-2008 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: Defines a public static utility class AknsUtils. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "AknsCppPreface.h" |
|
21 |
|
22 #include <eikenv.h> |
|
23 #include <coecntrl.h> |
|
24 #include <gulicon.h> |
|
25 |
|
26 #include <AknsUtils.h> |
|
27 |
|
28 #include "AknsAppSkinInstance.h" |
|
29 #include "AknsContainerDataContext.h" |
|
30 #include "AknsAppUiParameters.h" |
|
31 #include "AknsScalabilityUtils.h" |
|
32 |
|
33 #include "AknsDebug.h" |
|
34 |
|
35 _LIT(KAknsUtilsTrue, "true"); |
|
36 _LIT(KAknsUtilsFalse, "false"); |
|
37 |
|
38 |
|
39 AKNS_UNDEFINED_METHOD(AknsUtils::AknsUtils) |
|
40 |
|
41 // ============================ MEMBER FUNCTIONS =============================== |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // AknsUtils::InitSkinSupportL |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 AKNS_EXPORTED_METHOD(AknsUtils::InitSkinSupportL) |
|
48 EXPORT_C void AknsUtils::InitSkinSupportL() |
|
49 { |
|
50 AKNS_TRACE_INFO("AknsUtils::InitSkinSupportL"); |
|
51 |
|
52 if( !SkinInstance() ) |
|
53 { |
|
54 CAknsAppSkinInstance::CreateSingletonL(); |
|
55 } |
|
56 |
|
57 __ASSERT_DEBUG(SkinInstance(),AKNS_DEBUG_PANIC(EAknsDPanicNotInitialized)); |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // AknsUtils::CreateDataContextForContainerL |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 AKNS_EXPORTED_METHOD(AknsUtils::CreateDataContextForContainerL) |
|
65 EXPORT_C MAknsDataContext* AknsUtils::CreateDataContextForContainerL() |
|
66 { |
|
67 return CAknsContainerDataContext::NewL(); |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // AknsUtils::CreateBitmapItemDefL |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 AKNS_EXPORTED_METHOD(AknsUtils::CreateBitmapItemDefL) |
|
75 EXPORT_C CAknsItemDef* AknsUtils::CreateBitmapItemDefL( |
|
76 const TAknsItemID& aID, const TDesC& aFilename, |
|
77 const TInt aIndex ) |
|
78 { |
|
79 return CAknsBitmapItemDef::NewL( aID, aFilename, aIndex ); |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // AknsUtils::CreateMaskedBitmapItemDefL |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 AKNS_EXPORTED_METHOD(AknsUtils::CreateMaskedBitmapItemDefL) |
|
87 EXPORT_C CAknsItemDef* AknsUtils::CreateMaskedBitmapItemDefL( |
|
88 const TAknsItemID& aID, const TDesC& aFilename, |
|
89 const TInt aIndex, const TInt aMaskIndex ) |
|
90 { |
|
91 return CAknsMaskedBitmapItemDef::NewL( aID, aFilename, aIndex, |
|
92 aMaskIndex ); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // AknsUtils::SkinInstance |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 AKNS_EXPORTED_METHOD(AknsUtils::SkinInstance) |
|
100 EXPORT_C MAknsSkinInstance* AknsUtils::SkinInstance() |
|
101 { |
|
102 CAknsAppSkinInstance* skin = static_cast<CAknsAppSkinInstance*> |
|
103 (CCoeEnv::Static( KAknsSkinInstanceTls )); |
|
104 return skin; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // AknsUtils::DataContext |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 AKNS_EXPORTED_METHOD(AknsUtils::DataContext) |
|
112 EXPORT_C MAknsDataContext* AknsUtils::DataContext( MObjectProvider* aMop ) |
|
113 { |
|
114 MAknsSkinInstance* skin = SkinInstance(); |
|
115 if( !skin ) |
|
116 { |
|
117 return NULL; |
|
118 } |
|
119 |
|
120 MAknsDataContext* dc = NULL; |
|
121 if( aMop ) |
|
122 { |
|
123 aMop->MopGetObject( dc ); |
|
124 } |
|
125 |
|
126 if( !dc ) |
|
127 { |
|
128 dc = skin->RootDataContext(); |
|
129 } |
|
130 |
|
131 return dc; |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // AknsUtils::CreateIconL |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 EXPORT_C void AknsUtils::CreateIconL( |
|
139 MAknsSkinInstance* aInstance, const TAknsItemID& aID, |
|
140 CFbsBitmap*& aBitmap, CFbsBitmap*& aMask, |
|
141 const TDesC& aFilename, |
|
142 const TInt aFileBitmapId, const TInt aFileMaskId ) |
|
143 { |
|
144 CreateIconLC( aInstance, aID, aBitmap, aMask, |
|
145 aFilename, aFileBitmapId, aFileMaskId ); |
|
146 CleanupStack::Pop(2); // aBitmap, aMask |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // AknsUtils::CreateIconLC |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 EXPORT_C void AknsUtils::CreateIconLC( |
|
154 MAknsSkinInstance* aInstance, const TAknsItemID& aID, |
|
155 CFbsBitmap*& aBitmap, CFbsBitmap*& aMask, |
|
156 const TDesC& aFilename, |
|
157 const TInt aFileBitmapId, const TInt aFileMaskId ) |
|
158 { |
|
159 CFbsBitmap* bitmap = NULL; |
|
160 CFbsBitmap* mask = NULL; |
|
161 TBool fallback = EFalse; |
|
162 if( aInstance ) |
|
163 { |
|
164 CAknsMaskedBitmapItemData* bmpData = |
|
165 static_cast<CAknsMaskedBitmapItemData*>( |
|
166 aInstance->CreateUncachedItemDataL( aID, EAknsITMaskedBitmap ) ); |
|
167 CleanupStack::PushL( bmpData ); |
|
168 if( bmpData && bmpData->Bitmap() && bmpData->Mask() ) |
|
169 { |
|
170 // Detach bitmaps |
|
171 bitmap = bmpData->Bitmap(); |
|
172 bmpData->SetBitmap( NULL ); |
|
173 mask = bmpData->Mask(); |
|
174 bmpData->SetMask( NULL ); |
|
175 } |
|
176 CleanupStack::PopAndDestroy( bmpData ); |
|
177 } |
|
178 |
|
179 if( bitmap ) // Mask is also loaded |
|
180 { |
|
181 CleanupStack::PushL( mask ); |
|
182 CleanupStack::PushL( bitmap ); |
|
183 } |
|
184 else |
|
185 { |
|
186 if( !aFilename.Length() ) |
|
187 { |
|
188 User::Leave( KErrNotFound ); |
|
189 } |
|
190 |
|
191 // Fallback |
|
192 AknIconUtils::CreateIconLC( bitmap, mask, |
|
193 aFilename, aFileBitmapId, aFileMaskId ); |
|
194 fallback = ETrue; |
|
195 } |
|
196 |
|
197 if( (bitmap && mask) || fallback) |
|
198 { |
|
199 // Ownership transferred |
|
200 aBitmap = bitmap; |
|
201 aMask = mask; |
|
202 } |
|
203 else |
|
204 { |
|
205 User::Leave( KErrUnknown ); |
|
206 } |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // AknsUtils::CreateIconL |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 EXPORT_C void AknsUtils::CreateIconL( |
|
214 MAknsSkinInstance* aInstance, const TAknsItemID& aID, |
|
215 CFbsBitmap*& aBitmap, |
|
216 const TDesC& aFilename, |
|
217 const TInt aFileBitmapId ) |
|
218 { |
|
219 CreateIconLC( aInstance, aID, aBitmap, |
|
220 aFilename, aFileBitmapId ); |
|
221 CleanupStack::Pop( aBitmap ); |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // AknsUtils::CreateIconLC |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 EXPORT_C void AknsUtils::CreateIconLC( |
|
229 MAknsSkinInstance* aInstance, const TAknsItemID& aID, |
|
230 CFbsBitmap*& aBitmap, |
|
231 const TDesC& aFilename, |
|
232 const TInt aFileBitmapId ) |
|
233 { |
|
234 CFbsBitmap* bitmap = NULL; |
|
235 |
|
236 if( aInstance ) |
|
237 { |
|
238 CAknsBitmapItemData* bmpData = |
|
239 static_cast<CAknsBitmapItemData*>( |
|
240 aInstance->CreateUncachedItemDataL( aID, EAknsITBitmap ) ); |
|
241 CleanupStack::PushL( bmpData ); |
|
242 if( bmpData && bmpData->Bitmap() ) |
|
243 { |
|
244 // Detach bitmap |
|
245 bitmap = bmpData->Bitmap(); |
|
246 bmpData->SetBitmap( NULL ); |
|
247 } |
|
248 CleanupStack::PopAndDestroy( bmpData ); |
|
249 } |
|
250 |
|
251 if( bitmap ) |
|
252 { |
|
253 CleanupStack::PushL( bitmap ); |
|
254 } |
|
255 else |
|
256 { |
|
257 if( !aFilename.Length() ) |
|
258 { |
|
259 User::Leave( KErrNotFound ); |
|
260 } |
|
261 |
|
262 // Fallback |
|
263 bitmap = AknIconUtils::CreateIconL( |
|
264 aFilename, aFileBitmapId ); |
|
265 |
|
266 CleanupStack::PushL( bitmap ); // bitmap |
|
267 } |
|
268 |
|
269 if( bitmap ) |
|
270 { |
|
271 // Ownership transferred |
|
272 aBitmap = bitmap; |
|
273 } |
|
274 else |
|
275 { |
|
276 User::Leave( KErrUnknown ); |
|
277 } |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // AknsUtils::CreateMaskedBitmapL |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 EXPORT_C CApaMaskedBitmap* AknsUtils::CreateMaskedBitmapL( |
|
285 MAknsSkinInstance* aInstance, const TAknsItemID& aID, |
|
286 const TDesC& aFilename, |
|
287 const TInt aFileIndex, const TInt aFileMaskIndex ) |
|
288 { |
|
289 AKNS_TRACE_OBSOLETE("AknsUtils::CreateMaskedBitmapL (5 param)"); |
|
290 |
|
291 CFbsBitmap* bitmap = NULL; |
|
292 CFbsBitmap* mask = NULL; |
|
293 |
|
294 CreateIconLC( aInstance, aID, bitmap, mask, |
|
295 aFilename, aFileIndex, aFileMaskIndex ); |
|
296 |
|
297 // Bitmap and mask always exist here |
|
298 CApaMaskedBitmap* maskedBitmap = CApaMaskedBitmap::NewLC(); |
|
299 // Note that these calls leave with SVG-originating icons |
|
300 User::LeaveIfError( maskedBitmap->Duplicate( bitmap->Handle() ) ); |
|
301 User::LeaveIfError( maskedBitmap->Mask()->Duplicate( mask->Handle() ) ); |
|
302 CleanupStack::Pop( maskedBitmap ); |
|
303 |
|
304 CleanupStack::PopAndDestroy( 2 ); // bitmap, mask |
|
305 |
|
306 return maskedBitmap; |
|
307 } |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // AknsUtils::CreateGulIconL |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 EXPORT_C CGulIcon* AknsUtils::CreateGulIconL( |
|
314 MAknsSkinInstance* aInstance, const TAknsItemID& aID, |
|
315 const TDesC& aFilename, |
|
316 const TInt aFileIndex, const TInt aFileMaskIndex ) |
|
317 { |
|
318 CFbsBitmap* bitmap = NULL; |
|
319 CFbsBitmap* mask = NULL; |
|
320 |
|
321 CreateIconLC( aInstance, aID, bitmap, mask, |
|
322 aFilename, aFileIndex, aFileMaskIndex ); |
|
323 |
|
324 CGulIcon* icon = CGulIcon::NewL( bitmap, mask ); |
|
325 |
|
326 CleanupStack::Pop( 2 ); // bitmap, mask |
|
327 |
|
328 return icon; |
|
329 } |
|
330 |
|
331 // ----------------------------------------------------------------------------- |
|
332 // AknsUtils::CreateColorIconL |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 AKNS_EXPORTED_METHOD(AknsUtils::CreateColorIconL) |
|
336 EXPORT_C void AknsUtils::CreateColorIconL( |
|
337 MAknsSkinInstance* aInstance, const TAknsItemID& aID, |
|
338 const TAknsItemID& aColorID, const TInt aColorIndex, |
|
339 CFbsBitmap*& aBitmap, CFbsBitmap*& aMask, |
|
340 const TDesC& aFilename, |
|
341 const TInt aFileBitmapId, const TInt aFileMaskId, |
|
342 const TRgb aDefaultColor ) |
|
343 { |
|
344 CreateColorIconLC( aInstance, aID, aColorID, aColorIndex, |
|
345 aBitmap, aMask, aFilename, aFileBitmapId, aFileMaskId, aDefaultColor ); |
|
346 CleanupStack::Pop(2); // aBitmap, aMask |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // AknsUtils::CreateColorIconLC |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 AKNS_EXPORTED_METHOD(AknsUtils::CreateColorIconLC) |
|
354 EXPORT_C void AknsUtils::CreateColorIconLC( |
|
355 MAknsSkinInstance* aInstance, const TAknsItemID& aID, |
|
356 const TAknsItemID& aColorID, const TInt aColorIndex, |
|
357 CFbsBitmap*& aBitmap, CFbsBitmap*& aMask, |
|
358 const TDesC& aFilename, |
|
359 const TInt aFileBitmapId, const TInt aFileMaskId, |
|
360 const TRgb aDefaultColor ) |
|
361 { |
|
362 CreateColorIconLC( |
|
363 aInstance, aID, aColorID, aColorIndex, aBitmap, aMask, |
|
364 aFilename, aFileBitmapId, aFileMaskId, aDefaultColor, |
|
365 TSize(-1,-1), EAspectRatioPreserved ); |
|
366 } |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // AknsUtils::CreateColorIconL |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 AKNS_EXPORTED_METHOD(AknsUtils::CreateColorIconL) |
|
373 EXPORT_C void AknsUtils::CreateColorIconL( |
|
374 MAknsSkinInstance* aInstance, const TAknsItemID& aID, |
|
375 const TAknsItemID& aColorID, const TInt aColorIndex, |
|
376 CFbsBitmap*& aBitmap, CFbsBitmap*& aMask, |
|
377 const TDesC& aFilename, |
|
378 const TInt aFileBitmapId, const TInt aFileMaskId, |
|
379 const TRgb aDefaultColor, |
|
380 const TSize& aSize, const TScaleMode aScaleMode ) |
|
381 { |
|
382 CreateColorIconLC( aInstance, aID, aColorID, aColorIndex, |
|
383 aBitmap, aMask, aFilename, aFileBitmapId, aFileMaskId, aDefaultColor, |
|
384 aSize, aScaleMode ); |
|
385 CleanupStack::Pop(2); // aBitmap, aMask |
|
386 } |
|
387 |
|
388 // ----------------------------------------------------------------------------- |
|
389 // AknsUtils::CreateColorIconLC |
|
390 // ----------------------------------------------------------------------------- |
|
391 // |
|
392 AKNS_EXPORTED_METHOD(AknsUtils::CreateColorIconLC) |
|
393 EXPORT_C void AknsUtils::CreateColorIconLC( |
|
394 MAknsSkinInstance* aInstance, const TAknsItemID& aID, |
|
395 const TAknsItemID& aColorID, const TInt aColorIndex, |
|
396 CFbsBitmap*& aBitmap, CFbsBitmap*& aMask, |
|
397 const TDesC& aFilename, |
|
398 const TInt aFileBitmapId, const TInt aFileMaskId, |
|
399 const TRgb aDefaultColor, |
|
400 const TSize& aSize, const TScaleMode aScaleMode ) |
|
401 { |
|
402 CFbsBitmap* bitmap = NULL; |
|
403 CFbsBitmap* mask = NULL; |
|
404 |
|
405 CreateIconLC( aInstance, aID, bitmap, mask, |
|
406 aFilename, aFileBitmapId, aFileMaskId ); // (2) |
|
407 |
|
408 TRgb color = aDefaultColor; |
|
409 // Return value intentionally ignored |
|
410 GetCachedColor( aInstance, color, aColorID, aColorIndex ); |
|
411 |
|
412 if( AknIconUtils::IsMifIcon( bitmap ) ) |
|
413 { |
|
414 AknIconUtils::SetIconColor( bitmap, color ); |
|
415 aBitmap = bitmap; |
|
416 aMask = mask; |
|
417 } |
|
418 else // Create Own Icon |
|
419 { |
|
420 CFbsBitmap* colorBitmap = new (ELeave) CFbsBitmap(); |
|
421 CleanupStack::PushL( colorBitmap ); // (3) |
|
422 |
|
423 TSize size = mask->SizeInPixels(); |
|
424 User::LeaveIfError( |
|
425 colorBitmap->Create( size, |
|
426 CEikonEnv::Static()->ScreenDevice()->DisplayMode() ) ); |
|
427 |
|
428 CFbsBitmapDevice* colorBmpDev = CFbsBitmapDevice::NewL( colorBitmap ); |
|
429 CleanupStack::PushL( colorBmpDev ); // (4) |
|
430 User::LeaveIfError( colorBmpDev->Resize( size ) ); |
|
431 |
|
432 CFbsBitGc* colorBmpGc = CFbsBitGc::NewL(); |
|
433 CleanupStack::PushL( colorBmpGc ); // (5) |
|
434 colorBmpGc->Activate( colorBmpDev ); |
|
435 |
|
436 colorBmpGc->SetBrushColor( color ); |
|
437 colorBmpGc->SetPenStyle( CGraphicsContext::ENullPen ); |
|
438 colorBmpGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
439 colorBmpGc->DrawRect( TRect( TPoint(0,0), size ) ); |
|
440 |
|
441 CleanupStack::PopAndDestroy( 2 ); // colorBmpGc, colorBmpDev (3) |
|
442 CleanupStack::Pop( 3 ); // colorBmp, bitmap, mask (0) |
|
443 delete bitmap; // We don't know the order, must destroy manually |
|
444 |
|
445 aBitmap = colorBitmap; |
|
446 aMask = mask; |
|
447 |
|
448 // These are both safe |
|
449 CleanupStack::PushL( aBitmap ); // (1) |
|
450 CleanupStack::PushL( aMask ); // (2) |
|
451 } |
|
452 |
|
453 if( aSize.iWidth>=0 ) |
|
454 { |
|
455 // Set the size |
|
456 User::LeaveIfError( |
|
457 AknIconUtils::SetSize( aBitmap, aSize, aScaleMode ) ); |
|
458 } |
|
459 } |
|
460 |
|
461 // ----------------------------------------------------------------------------- |
|
462 // AknsUtils::CreateBitmapL |
|
463 // ----------------------------------------------------------------------------- |
|
464 // |
|
465 AKNS_EXPORTED_METHOD(AknsUtils::CreateBitmapL) |
|
466 EXPORT_C CFbsBitmap* AknsUtils::CreateBitmapL( |
|
467 MAknsSkinInstance* aInstance, const TAknsItemID& aID ) |
|
468 { |
|
469 CFbsBitmap* bitmap = NULL; |
|
470 CreateIconL( aInstance, aID, bitmap, KNullDesC, -1 ); |
|
471 |
|
472 return bitmap; |
|
473 } |
|
474 |
|
475 // ----------------------------------------------------------------------------- |
|
476 // AknsUtils::CreateMaskedBitmapL |
|
477 // ----------------------------------------------------------------------------- |
|
478 // |
|
479 AKNS_EXPORTED_METHOD(AknsUtils::CreateMaskedBitmapL) |
|
480 EXPORT_C CApaMaskedBitmap* AknsUtils::CreateMaskedBitmapL( |
|
481 MAknsSkinInstance* aInstance, const TAknsItemID& aID ) |
|
482 { |
|
483 AKNS_TRACE_OBSOLETE("AknsUtils::CreateMaskedBitmapL (2 param)"); |
|
484 return CreateMaskedBitmapL( aInstance, aID, KNullDesC, -1, -1 ); |
|
485 } |
|
486 |
|
487 // ----------------------------------------------------------------------------- |
|
488 // AknsUtils::CreateGulIconL |
|
489 // ----------------------------------------------------------------------------- |
|
490 // |
|
491 AKNS_EXPORTED_METHOD(AknsUtils::CreateGulIconL) |
|
492 EXPORT_C CGulIcon* AknsUtils::CreateGulIconL( |
|
493 MAknsSkinInstance* aInstance, const TAknsItemID& aID, |
|
494 const TBool aRequireMask ) |
|
495 { |
|
496 if( !aInstance ) |
|
497 { |
|
498 User::Leave(KErrNotSupported); |
|
499 } |
|
500 |
|
501 // Forward-query type |
|
502 TBool needsDelete = EFalse; |
|
503 CAknsItemDef* def = |
|
504 static_cast<CAknsAppSkinInstance*>(aInstance)->LookupDef( |
|
505 needsDelete, aID, EAknsITMaskedBitmap ); |
|
506 TBool maskedAvailable = def ? ETrue : EFalse; |
|
507 if( needsDelete ) delete def; |
|
508 |
|
509 if( maskedAvailable ) |
|
510 { |
|
511 return CreateGulIconL( aInstance, aID, KNullDesC, -1, -1 ); |
|
512 } |
|
513 else if( !aRequireMask ) |
|
514 { |
|
515 CFbsBitmap* bitmap = NULL; |
|
516 CreateIconLC( aInstance, aID, bitmap, KNullDesC, -1 ); |
|
517 CGulIcon* icon = CGulIcon::NewL( bitmap ); |
|
518 CleanupStack::Pop( bitmap ); |
|
519 return icon; |
|
520 } |
|
521 else |
|
522 { |
|
523 User::Leave( KErrNotFound ); |
|
524 } |
|
525 |
|
526 return NULL; // Never reached |
|
527 } |
|
528 |
|
529 // ----------------------------------------------------------------------------- |
|
530 // AknsUtils::GetCachedBitmap |
|
531 // ----------------------------------------------------------------------------- |
|
532 // |
|
533 AKNS_EXPORTED_METHOD(AknsUtils::GetCachedBitmap) |
|
534 EXPORT_C CFbsBitmap* AknsUtils::GetCachedBitmap( |
|
535 MAknsSkinInstance* aInstance, const TAknsItemID& aID ) |
|
536 { |
|
537 if( !aInstance ) |
|
538 { |
|
539 return NULL; |
|
540 } |
|
541 |
|
542 CAknsItemData* resData = aInstance->GetCachedItemData( aID, EAknsITBitmap ); |
|
543 if( !resData ) |
|
544 { |
|
545 return NULL; |
|
546 } |
|
547 |
|
548 return static_cast<CAknsBitmapItemData*>(resData)->Bitmap(); |
|
549 } |
|
550 |
|
551 // ----------------------------------------------------------------------------- |
|
552 // AknsUtils::GetCachedMaskedBitmap |
|
553 // ----------------------------------------------------------------------------- |
|
554 // |
|
555 AKNS_EXPORTED_METHOD(AknsUtils::GetCachedMaskedBitmap) |
|
556 EXPORT_C void AknsUtils::GetCachedMaskedBitmap( |
|
557 MAknsSkinInstance* aInstance, const TAknsItemID& aID, |
|
558 CFbsBitmap*& aBitmap, CFbsBitmap*& aMask ) |
|
559 { |
|
560 aBitmap = NULL; |
|
561 aMask = NULL; |
|
562 |
|
563 if( !aInstance ) |
|
564 { |
|
565 return; |
|
566 } |
|
567 |
|
568 CAknsItemData* resData = aInstance->GetCachedItemData( aID, EAknsITBitmap ); |
|
569 if( !resData ) |
|
570 { |
|
571 return; |
|
572 } |
|
573 |
|
574 // If found, guaranteed to be at least EAknsITBitmap |
|
575 aBitmap = static_cast<CAknsBitmapItemData*>( resData )->Bitmap(); |
|
576 |
|
577 // Assign mask only, if EAknsITMaskedBitmap |
|
578 if( IsDerivedType( EAknsITMaskedBitmap, resData->Type() ) ) |
|
579 { |
|
580 aMask = static_cast<CAknsMaskedBitmapItemData*>( resData )->Mask(); |
|
581 } |
|
582 } |
|
583 |
|
584 // ----------------------------------------------------------------------------- |
|
585 // AknsUtils::GetCachedColor |
|
586 // ----------------------------------------------------------------------------- |
|
587 // |
|
588 AKNS_EXPORTED_METHOD(AknsUtils::GetCachedColor) |
|
589 EXPORT_C TInt AknsUtils::GetCachedColor( |
|
590 MAknsSkinInstance* aInstance, TRgb& aRgb, const TAknsItemID& aID, |
|
591 const TInt aIndex ) |
|
592 { |
|
593 if( !aInstance ) |
|
594 { |
|
595 return KErrNotSupported; |
|
596 } |
|
597 |
|
598 // Check backward compatibility first |
|
599 if( AknsScalabilityUtils::GetBackwardCompatibilityColor( |
|
600 aInstance, aRgb, aID, aIndex ) ) |
|
601 { |
|
602 // Found and assigned |
|
603 return KErrNone; |
|
604 } |
|
605 |
|
606 CAknsColorTableItemData* colorData = static_cast<CAknsColorTableItemData*>( |
|
607 aInstance->GetCachedItemData( aID, EAknsITColorTable ) ); |
|
608 if( !colorData) |
|
609 { |
|
610 return KErrNotFound; |
|
611 } |
|
612 |
|
613 TRAPD( err, colorData->GetColorL( aIndex, aRgb ) ); |
|
614 return err; |
|
615 } |
|
616 |
|
617 // ----------------------------------------------------------------------------- |
|
618 // AknsUtils::BooleanPropertyL |
|
619 // ----------------------------------------------------------------------------- |
|
620 // |
|
621 AKNS_EXPORTED_METHOD(AknsUtils::BooleanPropertyL) |
|
622 EXPORT_C TBool AknsUtils::BooleanPropertyL( MAknsSkinInstance* aInstance, |
|
623 const TAknsItemID& aID ) |
|
624 { |
|
625 if( !aInstance ) User::Leave( KErrNotSupported ); |
|
626 |
|
627 CAknsStringItemData* data = static_cast<CAknsStringItemData*>( |
|
628 aInstance->GetCachedItemData( aID, EAknsITString ) ); |
|
629 if( !data ) User::Leave( KErrNotFound ); |
|
630 |
|
631 if( !data->String().CompareF( KAknsUtilsTrue ) ) return ETrue; |
|
632 if( !data->String().CompareF( KAknsUtilsFalse ) ) return EFalse; |
|
633 |
|
634 User::Leave( KErrArgument ); |
|
635 return EFalse; // Never reached |
|
636 } |
|
637 |
|
638 // ----------------------------------------------------------------------------- |
|
639 // AknsUtils::IsDerivedType |
|
640 // ----------------------------------------------------------------------------- |
|
641 // |
|
642 TBool AknsUtils::IsDerivedType( const TAknsItemType aBaseType, |
|
643 const TAknsItemType aDerivedType ) |
|
644 { |
|
645 if( aBaseType == aDerivedType ) |
|
646 { |
|
647 return ETrue; |
|
648 } |
|
649 |
|
650 switch( aBaseType ) |
|
651 { |
|
652 case EAknsITUnknown: |
|
653 { |
|
654 return ETrue; |
|
655 } |
|
656 |
|
657 case EAknsITImage: |
|
658 { |
|
659 if( (aDerivedType==EAknsITBitmap) || |
|
660 (aDerivedType==EAknsITMaskedBitmap) || |
|
661 (aDerivedType==EAknsITColorTable) || |
|
662 (aDerivedType==EAknsITImageTable) || |
|
663 (aDerivedType==EAknsITBmpAnim ) ) |
|
664 { |
|
665 return ETrue; |
|
666 } |
|
667 |
|
668 return EFalse; |
|
669 } |
|
670 |
|
671 case EAknsITBitmap: |
|
672 { |
|
673 if( aDerivedType == EAknsITMaskedBitmap ) |
|
674 { |
|
675 return ETrue; |
|
676 } |
|
677 |
|
678 return EFalse; |
|
679 } |
|
680 |
|
681 case EAknsITImageTable: |
|
682 { |
|
683 if( aDerivedType == EAknsITBmpAnim ) |
|
684 { |
|
685 return ETrue; |
|
686 } |
|
687 |
|
688 return EFalse; |
|
689 } |
|
690 |
|
691 default: |
|
692 break; |
|
693 } //lint !e788 Other values return EFalse |
|
694 |
|
695 return EFalse; |
|
696 } |
|
697 |
|
698 // ----------------------------------------------------------------------------- |
|
699 // AknsUtils::SetAvkonSkinEnabledL |
|
700 // ----------------------------------------------------------------------------- |
|
701 // |
|
702 AKNS_EXPORTED_METHOD(AknsUtils::SetAvkonSkinEnabledL) |
|
703 EXPORT_C void AknsUtils::SetAvkonSkinEnabledL( const TBool aEnabled ) |
|
704 { |
|
705 CAknsAppUiParameters* aup = static_cast<CAknsAppUiParameters*> |
|
706 (CCoeEnv::Static( KAknsAppUiParametersTls )); |
|
707 |
|
708 if( !aup ) |
|
709 { |
|
710 CAknsAppUiParameters::CreateSingletonL(); |
|
711 aup = static_cast<CAknsAppUiParameters*> |
|
712 (CCoeEnv::Static( KAknsAppUiParametersTls )); |
|
713 } |
|
714 |
|
715 __ASSERT_DEBUG(aup,AKNS_DEBUG_PANIC(EAknsDPanicNotInitialized)); |
|
716 |
|
717 aup->SetAvkonSkinEnabled( aEnabled ); |
|
718 } |
|
719 |
|
720 // ----------------------------------------------------------------------------- |
|
721 // AknsUtils::AvkonSkinEnabled |
|
722 // ----------------------------------------------------------------------------- |
|
723 // |
|
724 AKNS_EXPORTED_METHOD(AknsUtils::AvkonSkinEnabled) |
|
725 EXPORT_C TBool AknsUtils::AvkonSkinEnabled() |
|
726 { |
|
727 CAknsAppUiParameters* aup = static_cast<CAknsAppUiParameters*> |
|
728 (CCoeEnv::Static( KAknsAppUiParametersTls )); |
|
729 |
|
730 if( aup ) |
|
731 { |
|
732 return aup->AvkonSkinEnabled(); |
|
733 } |
|
734 |
|
735 return EFalse; |
|
736 } |
|
737 |
|
738 // ----------------------------------------------------------------------------- |
|
739 // AknsUtils::SetAvkonHighlightAnimationEnabledL |
|
740 // ----------------------------------------------------------------------------- |
|
741 // |
|
742 AKNS_EXPORTED_METHOD(AknsUtils::SetAvkonHighlightAnimationEnabledL) |
|
743 EXPORT_C void AknsUtils::SetAvkonHighlightAnimationEnabledL( const TBool aEnabled ) |
|
744 { |
|
745 CAknsAppUiParameters* aup = static_cast<CAknsAppUiParameters*> |
|
746 (CCoeEnv::Static( KAknsAppUiParametersTls )); |
|
747 |
|
748 if( !aup ) |
|
749 { |
|
750 CAknsAppUiParameters::CreateSingletonL(); |
|
751 aup = static_cast<CAknsAppUiParameters*> |
|
752 (CCoeEnv::Static( KAknsAppUiParametersTls )); |
|
753 } |
|
754 |
|
755 __ASSERT_DEBUG(aup,AKNS_DEBUG_PANIC(EAknsDPanicNotInitialized)); |
|
756 |
|
757 aup->SetAvkonHighlightAnimationEnabled( aEnabled ); |
|
758 } |
|
759 |
|
760 // ----------------------------------------------------------------------------- |
|
761 // AknsUtils::AvkonHighlightAnimationEnabled |
|
762 // ----------------------------------------------------------------------------- |
|
763 // |
|
764 AKNS_EXPORTED_METHOD(AknsUtils::AvkonHighlightAnimationEnabled) |
|
765 EXPORT_C TBool AknsUtils::AvkonHighlightAnimationEnabled() |
|
766 { |
|
767 // Step 1: Check if product variant has disabled animations |
|
768 CAknsAppSkinInstance* skin = static_cast<CAknsAppSkinInstance*> |
|
769 (CCoeEnv::Static( KAknsSkinInstanceTls )); |
|
770 if( skin ) |
|
771 { |
|
772 if( !skin->VariantHighlightAnimationEnabled() ) |
|
773 { |
|
774 // Product variant has disabled highlight animation |
|
775 return EFalse; |
|
776 } |
|
777 } |
|
778 else |
|
779 { |
|
780 // No skin instance -> no skin -> animations can hardly be supported |
|
781 return EFalse; |
|
782 } |
|
783 |
|
784 // Step 2: Product allows animations, check application specific status |
|
785 CAknsAppUiParameters* aup = static_cast<CAknsAppUiParameters*> |
|
786 (CCoeEnv::Static( KAknsAppUiParametersTls )); |
|
787 |
|
788 if( aup ) |
|
789 { |
|
790 return aup->AvkonHighlightAnimationEnabled(); |
|
791 } |
|
792 |
|
793 return ETrue; // By default, highlight animations are enabled |
|
794 } |
|
795 |
|
796 // ----------------------------------------------------------------------------- |
|
797 // AknsUtils::RegisterControlPosition |
|
798 // ----------------------------------------------------------------------------- |
|
799 // |
|
800 AKNS_EXPORTED_METHOD(AknsUtils::RegisterControlPosition) |
|
801 EXPORT_C void AknsUtils::RegisterControlPosition( const CCoeControl* aControl ) |
|
802 { |
|
803 if( aControl && aControl->DrawableWindow() ) |
|
804 { |
|
805 RegisterControlPosition( aControl, aControl->PositionRelativeToScreen() ); |
|
806 } |
|
807 } |
|
808 |
|
809 // ----------------------------------------------------------------------------- |
|
810 // AknsUtils::RegisterControlPosition |
|
811 // ----------------------------------------------------------------------------- |
|
812 // |
|
813 EXPORT_C void AknsUtils::RegisterControlPosition( const CCoeControl* aControl, |
|
814 const TPoint& aPoint ) |
|
815 { |
|
816 CAknsAppSkinInstance* skin = static_cast<CAknsAppSkinInstance*> |
|
817 (CCoeEnv::Static( KAknsSkinInstanceTls )); |
|
818 |
|
819 if( (!skin) || (!aControl) || (!aControl->DrawableWindow()) ) |
|
820 { |
|
821 return; |
|
822 } |
|
823 |
|
824 TAknsControlPositionEntry entry; |
|
825 TInt index; |
|
826 |
|
827 entry.iKey = reinterpret_cast<TUint>(aControl); |
|
828 if( skin->iControlPositionList.FindInUnsignedKeyOrder( |
|
829 entry, index ) == KErrNone ) |
|
830 { |
|
831 skin->iControlPositionList[index].iScreenPos = aPoint; |
|
832 } |
|
833 else |
|
834 { |
|
835 entry.iScreenPos = aPoint; |
|
836 skin->iControlPositionList.InsertInUnsignedKeyOrder( entry ); |
|
837 } |
|
838 } |
|
839 |
|
840 // ----------------------------------------------------------------------------- |
|
841 // AknsUtils::DeregisterControlPosition |
|
842 // ----------------------------------------------------------------------------- |
|
843 // |
|
844 AKNS_EXPORTED_METHOD(AknsUtils::DeregisterControlPosition) |
|
845 EXPORT_C void AknsUtils::DeregisterControlPosition( const CCoeControl* aControl ) |
|
846 { |
|
847 CAknsAppSkinInstance* skin = static_cast<CAknsAppSkinInstance*> |
|
848 (CCoeEnv::Static( KAknsSkinInstanceTls )); |
|
849 |
|
850 if( !skin ) |
|
851 { |
|
852 return; |
|
853 } |
|
854 |
|
855 TAknsControlPositionEntry entry; |
|
856 TInt index; |
|
857 |
|
858 entry.iKey = reinterpret_cast<TUint>(aControl); |
|
859 if( skin->iControlPositionList.FindInUnsignedKeyOrder( |
|
860 entry, index ) == KErrNone ) |
|
861 { |
|
862 skin->iControlPositionList.Remove( index ); |
|
863 } |
|
864 } |
|
865 |
|
866 // ----------------------------------------------------------------------------- |
|
867 // AknsUtils::GetControlPosition |
|
868 // ----------------------------------------------------------------------------- |
|
869 // |
|
870 EXPORT_C TInt AknsUtils::GetControlPosition( const CCoeControl* aControl, |
|
871 TPoint& aScreenPos ) |
|
872 { |
|
873 CAknsAppSkinInstance* skin = static_cast<CAknsAppSkinInstance*> |
|
874 (CCoeEnv::Static( KAknsSkinInstanceTls )); |
|
875 |
|
876 if( !skin ) |
|
877 { |
|
878 return KErrNotFound; |
|
879 } |
|
880 |
|
881 TAknsControlPositionEntry entry; |
|
882 TInt index; |
|
883 |
|
884 entry.iKey = reinterpret_cast<TUint>(aControl); |
|
885 if( skin->iControlPositionList.FindInUnsignedKeyOrder( |
|
886 entry, index ) == KErrNone ) |
|
887 { |
|
888 aScreenPos = skin->iControlPositionList[index].iScreenPos; |
|
889 return KErrNone; |
|
890 } |
|
891 |
|
892 return KErrNotFound; |
|
893 } |
|
894 |
|
895 // ----------------------------------------------------------------------------- |
|
896 // AknsUtils::Reserved |
|
897 // ----------------------------------------------------------------------------- |
|
898 // |
|
899 AKNS_EXPORTED_METHOD(AknsUtils::Reserved) |
|
900 EXPORT_C TInt AknsUtils::Reserved() |
|
901 { |
|
902 return 0; |
|
903 } |
|
904 |
|
905 // End of File |