114
|
1 |
/*
|
|
2 |
* Copyright (c) 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: The API supports requesting raw bitmaps
|
|
15 |
* Version : %version: ou1s60ui#12 % << Don't touch! Updated by Synergy at check-out.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
|
|
22 |
#include <e32base.h>
|
|
23 |
#include <AknsUtils.h>
|
|
24 |
#include <mcsmenu.h>
|
|
25 |
#include <mcsmenuitem.h>
|
|
26 |
#include <mcsmenuutils.h>
|
|
27 |
#include <satdomainpskeys.h>
|
|
28 |
#include <e32property.h>
|
|
29 |
#include <apgcli.h>
|
|
30 |
#include <AknInternalIconUtils.h>
|
|
31 |
|
|
32 |
#include "mcssathandler.h"
|
|
33 |
|
|
34 |
//#include "mcsextendedmenuitem.h"
|
|
35 |
#include "mcsmenuiconutility.h"
|
|
36 |
#include <mcsdef.h>
|
|
37 |
|
|
38 |
// Constants
|
|
39 |
_LIT( KMifIconPath, "\\resource\\apps\\" );
|
|
40 |
const TUint32 KMifIconPathLenght = 18;
|
|
41 |
const TInt KJavaIconWidth = 88; // Java icon default width
|
|
42 |
const TInt KJavaIconHeight = 88; // Java icon default height
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
// ================= LOCAL FUNCTIONS ========================
|
|
47 |
|
|
48 |
|
|
49 |
// -----------------------------------------------------------------------------
|
|
50 |
// CreateMbmIconLC2 - Creates bitmap
|
|
51 |
// -----------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
LOCAL_C TBool CreateMbmIconLC2(CFbsBitmap*& aBitmap, CFbsBitmap*& aMask, const TDesC& aAppUid )
|
|
54 |
{
|
|
55 |
TBool ret = EFalse;
|
|
56 |
TSize size( KJavaIconWidth, KJavaIconHeight );
|
|
57 |
|
|
58 |
aBitmap = NULL;
|
|
59 |
aMask = NULL;
|
|
60 |
|
|
61 |
RApaLsSession lsSession;
|
|
62 |
User::LeaveIfError( lsSession.Connect() );
|
|
63 |
CleanupClosePushL( lsSession ); // lsSession (1)
|
|
64 |
|
|
65 |
TUint appUidUint;
|
|
66 |
|
|
67 |
// Gets app TUid from aAppUid descryptor
|
|
68 |
User::LeaveIfError( MenuUtils::GetTUint( aAppUid, appUidUint ) );
|
|
69 |
TUid appUid( TUid::Uid( appUidUint) );
|
|
70 |
|
|
71 |
// Tries to find icon with default size.
|
|
72 |
CApaMaskedBitmap* apaBmp = CApaMaskedBitmap::NewLC();
|
|
73 |
TInt apaErr = lsSession.GetAppIcon( appUid, size, *apaBmp );
|
|
74 |
if ( apaErr == KErrNotFound )
|
|
75 |
{
|
|
76 |
// Icon not found.
|
|
77 |
// AppArc tries to find equal to or smaller than the specified size.
|
|
78 |
// Get all icon sizes and search for next bigger icon size.
|
|
79 |
CArrayFixFlat<TSize>* sizes = new(ELeave) CArrayFixFlat<TSize>( 5 );
|
|
80 |
apaErr = lsSession.GetAppIconSizes(appUid, *sizes);
|
|
81 |
if ( !apaErr )
|
|
82 |
{
|
|
83 |
if ( sizes->Count() )
|
|
84 |
{
|
|
85 |
// There are other icon sizes
|
|
86 |
TInt idx = -1;
|
|
87 |
TInt square( size.iWidth * size.iHeight );
|
|
88 |
for ( TInt i = 0; i < sizes->Count(); i++ )
|
|
89 |
{
|
|
90 |
if ( ( sizes->At( i ).iWidth * sizes->At( i ).iHeight ) > square )
|
|
91 |
{
|
|
92 |
idx = i;
|
|
93 |
break;
|
|
94 |
}
|
|
95 |
}
|
|
96 |
|
|
97 |
if ( idx >= 0 )
|
|
98 |
{
|
|
99 |
// Next bigger icon.
|
|
100 |
size = sizes->At( idx );
|
|
101 |
}
|
|
102 |
else
|
|
103 |
{
|
|
104 |
// Just get the first available.
|
|
105 |
size = sizes->At( 0 );
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
// Gets icon with new size.
|
|
110 |
apaErr = lsSession.GetAppIcon( appUid, size, *apaBmp );
|
|
111 |
}
|
|
112 |
|
|
113 |
// Reset and destroy.
|
|
114 |
sizes->Reset();
|
|
115 |
delete sizes;
|
|
116 |
sizes = NULL;
|
|
117 |
}
|
|
118 |
|
|
119 |
// Some builds requires brackets
|
|
120 |
// logical correction was also made
|
|
121 |
if ( ( apaErr != KErrNone ) &&
|
|
122 |
( apaErr != KErrNotFound ) &&
|
|
123 |
( apaErr != KErrNotSupported ) )
|
|
124 |
{
|
|
125 |
// System wide error.
|
|
126 |
User::LeaveIfError( apaErr );
|
|
127 |
}
|
|
128 |
|
|
129 |
if( !apaErr &&
|
|
130 |
apaBmp &&
|
|
131 |
apaBmp->Mask() &&
|
|
132 |
apaBmp->Handle() &&
|
|
133 |
apaBmp->Mask()->Handle())
|
|
134 |
{
|
|
135 |
// AIF-based icon
|
|
136 |
CFbsBitmap* iconOwnedBitmap = new (ELeave) CFbsBitmap();
|
|
137 |
CleanupStack::PushL( iconOwnedBitmap ); // iob (3)
|
|
138 |
CFbsBitmap* iconOwnedMask = new (ELeave) CFbsBitmap();
|
|
139 |
CleanupStack::PushL( iconOwnedMask ); // iom (4)
|
|
140 |
User::LeaveIfError(
|
|
141 |
iconOwnedBitmap->Duplicate( apaBmp->Handle() ) );
|
|
142 |
User::LeaveIfError(
|
|
143 |
iconOwnedMask->Duplicate( apaBmp->Mask()->Handle() ) );
|
|
144 |
|
|
145 |
CAknIcon* tmpIcon = CAknIcon::NewL();
|
|
146 |
|
|
147 |
// Ownership is transferred
|
|
148 |
tmpIcon->SetBitmap( iconOwnedBitmap );
|
|
149 |
tmpIcon->SetMask( iconOwnedMask );
|
|
150 |
// Ownership of tmpIcon is transferred
|
|
151 |
CAknIcon* appIcon = AknIconUtils::CreateIconL( tmpIcon );
|
|
152 |
CleanupStack::Pop( 2 ); // iom, iob (2)
|
|
153 |
|
|
154 |
aBitmap = appIcon->Bitmap();
|
|
155 |
aMask = appIcon->Mask();
|
|
156 |
AknInternalIconUtils::SetAppIcon(aBitmap);
|
|
157 |
|
|
158 |
// Detach and delete
|
|
159 |
appIcon->SetBitmap( NULL );
|
|
160 |
appIcon->SetMask( NULL );
|
|
161 |
delete appIcon;
|
|
162 |
|
|
163 |
ret = ETrue;
|
|
164 |
}
|
|
165 |
|
|
166 |
CleanupStack::PopAndDestroy( 2 ); // lsSession, apaBmp (0)
|
|
167 |
|
|
168 |
// These are both safe
|
|
169 |
if ( aBitmap )
|
|
170 |
{
|
|
171 |
CleanupStack::PushL( aBitmap ); // (1)
|
|
172 |
CleanupStack::PushL( aMask ); // (2)
|
|
173 |
}
|
|
174 |
|
|
175 |
return ret;
|
|
176 |
}
|
|
177 |
|
|
178 |
|
|
179 |
// ---------------------------------------------------------
|
|
180 |
// ParseIconFilePathL
|
|
181 |
// ---------------------------------------------------------
|
|
182 |
//
|
|
183 |
|
|
184 |
LOCAL_C void ParseIconFilePathL( const TDesC& aIconFilePath, RBuf& aIconFilePathBuf )
|
|
185 |
{
|
|
186 |
TParsePtrC fileParsePtrC(aIconFilePath);
|
|
187 |
if( !fileParsePtrC.PathPresent())
|
|
188 |
{
|
|
189 |
aIconFilePathBuf.CreateL(KMifIconPathLenght + aIconFilePath.Length());
|
|
190 |
aIconFilePathBuf.Append(KMifIconPath);
|
|
191 |
}
|
|
192 |
else
|
|
193 |
{
|
|
194 |
aIconFilePathBuf.CreateL(aIconFilePath.Length());
|
|
195 |
}
|
|
196 |
aIconFilePathBuf.Append(aIconFilePath);
|
|
197 |
}
|
|
198 |
|
|
199 |
// ---------------------------------------------------------
|
|
200 |
// LoadSkinL
|
|
201 |
// ---------------------------------------------------------
|
|
202 |
//
|
|
203 |
LOCAL_C CAknIcon* LoadSkinL( TUint majorId, TUint minorId )
|
|
204 |
{
|
|
205 |
CAknIcon* icon = NULL;
|
|
206 |
CFbsBitmap* bitmap( 0 );
|
|
207 |
CFbsBitmap* mask( 0 );
|
|
208 |
|
|
209 |
TAknsItemID skinId;
|
|
210 |
skinId.Set( majorId, minorId );
|
|
211 |
|
|
212 |
AknsUtils::CreateIconLC(
|
|
213 |
AknsUtils::SkinInstance(),
|
|
214 |
skinId,
|
|
215 |
bitmap,
|
|
216 |
mask,
|
|
217 |
KNullDesC,
|
|
218 |
KErrNotFound,
|
|
219 |
KErrNotFound );
|
|
220 |
|
|
221 |
icon = CAknIcon::NewL();
|
|
222 |
icon->SetBitmap( bitmap );
|
|
223 |
icon->SetMask( mask );
|
|
224 |
|
|
225 |
// bitmap and icon, AknsUtils::CreateIconLC doesn't specify the order
|
|
226 |
CleanupStack::Pop( 2 );
|
|
227 |
|
|
228 |
return icon;
|
|
229 |
}
|
|
230 |
|
|
231 |
// ---------------------------------------------------------
|
|
232 |
// LoadSkinL
|
|
233 |
// ---------------------------------------------------------
|
|
234 |
//
|
|
235 |
LOCAL_C CAknIcon* LoadAppSkinL( TUid& aAppUid )
|
|
236 |
{
|
|
237 |
CAknIcon* icon = NULL;
|
|
238 |
CFbsBitmap* bitmap( 0 );
|
|
239 |
CFbsBitmap* mask( 0 );
|
|
240 |
|
|
241 |
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
|
|
242 |
|
|
243 |
TRAPD( err,
|
|
244 |
{
|
|
245 |
AknsUtils::CreateAppIconLC( skin, aAppUid, EAknsAppIconTypeList, bitmap, mask );
|
|
246 |
CleanupStack::Pop(2); //for trap
|
|
247 |
}
|
|
248 |
);
|
|
249 |
if( err == KErrNone )
|
|
250 |
{
|
|
251 |
icon = CAknIcon::NewL();
|
|
252 |
icon->SetBitmap( bitmap );
|
|
253 |
icon->SetMask( mask );
|
|
254 |
}
|
|
255 |
return icon;
|
|
256 |
}
|
|
257 |
|
|
258 |
// ---------------------------------------------------------
|
|
259 |
// GetSkinL
|
|
260 |
// ---------------------------------------------------------
|
|
261 |
//
|
|
262 |
LOCAL_C CAknIcon* GetSkinL( CMenuItem& aItem )
|
|
263 |
{
|
|
264 |
CAknIcon* icon = NULL;
|
|
265 |
TUint majorId( 0 );
|
|
266 |
TUint minorId( 0 );
|
|
267 |
TPtrC idString( KNullDesC );
|
|
268 |
TBool attrExists;
|
|
269 |
|
|
270 |
idString.Set( aItem.GetAttributeL( KMenuAttrIconSkinMajorId, attrExists ) );
|
|
271 |
if ( attrExists && idString.Length() )
|
|
272 |
{
|
|
273 |
User::LeaveIfError( MenuUtils::GetTUint( idString, majorId ) );
|
|
274 |
}
|
|
275 |
else
|
|
276 |
{
|
|
277 |
return NULL;
|
|
278 |
}
|
|
279 |
|
|
280 |
idString.Set( aItem.GetAttributeL( KMenuAttrIconSkinMinorId, attrExists ) );
|
|
281 |
if ( attrExists && idString.Length() )
|
|
282 |
{
|
|
283 |
User::LeaveIfError( MenuUtils::GetTUint( idString, minorId ) );
|
|
284 |
}
|
|
285 |
else
|
|
286 |
{
|
|
287 |
return NULL;
|
|
288 |
}
|
|
289 |
|
|
290 |
icon = LoadSkinL( majorId, minorId );
|
|
291 |
|
|
292 |
return icon;
|
|
293 |
}
|
|
294 |
|
|
295 |
// ---------------------------------------------------------
|
|
296 |
// GetIconL
|
|
297 |
// ---------------------------------------------------------
|
|
298 |
//
|
|
299 |
LOCAL_C CAknIcon* GetIconL( CMenuItem& aItem )
|
|
300 |
{
|
|
301 |
CAknIcon* icon = NULL;
|
|
302 |
TUint iconId( 0 );
|
|
303 |
TUint maskId( 0 );
|
|
304 |
TPtrC attrStr( KNullDesC );
|
|
305 |
TBool attrExists;
|
|
306 |
|
|
307 |
TPtrC iconFilePath( aItem.GetAttributeL( KMenuAttrIconFile, attrExists ) );
|
|
308 |
|
|
309 |
if ( !attrExists )
|
|
310 |
{
|
|
311 |
return NULL;
|
|
312 |
}
|
|
313 |
|
|
314 |
attrStr.Set( aItem.GetAttributeL( KMenuAttrIconId, attrExists ) );
|
|
315 |
if ( attrExists )
|
|
316 |
{
|
|
317 |
User::LeaveIfError( MenuUtils::GetTUint( attrStr, iconId ) );
|
|
318 |
}
|
|
319 |
else
|
|
320 |
{
|
|
321 |
return NULL;
|
|
322 |
}
|
|
323 |
|
|
324 |
attrStr.Set( aItem.GetAttributeL( KMenuAttrMaskId, attrExists ) );
|
|
325 |
if ( attrExists )
|
|
326 |
{
|
|
327 |
User::LeaveIfError( MenuUtils::GetTUint( attrStr, maskId ) );
|
|
328 |
}
|
|
329 |
else
|
|
330 |
{
|
|
331 |
return NULL;
|
|
332 |
}
|
|
333 |
|
|
334 |
CFbsBitmap* bitmap( 0 );
|
|
335 |
CFbsBitmap* mask( 0 );
|
|
336 |
|
|
337 |
RBuf pathBuf;
|
|
338 |
pathBuf.CleanupClosePushL();
|
|
339 |
ParseIconFilePathL(iconFilePath, pathBuf);
|
|
340 |
|
|
341 |
AknIconUtils::CreateIconLC( bitmap, mask, pathBuf, iconId, maskId );
|
|
342 |
icon = CAknIcon::NewL();
|
|
343 |
icon->SetBitmap( bitmap );
|
|
344 |
icon->SetMask( mask );
|
|
345 |
CleanupStack::Pop( 2 );
|
|
346 |
|
|
347 |
CleanupStack::PopAndDestroy( &pathBuf );
|
|
348 |
|
|
349 |
return icon;
|
|
350 |
}
|
|
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
355 |
// ---------------------------------------------------------
|
|
356 |
// GetDefaultSkinL
|
|
357 |
// ---------------------------------------------------------
|
|
358 |
//
|
|
359 |
LOCAL_C CAknIcon* GetDefaultSkinL( CMenuItem& aItem )
|
|
360 |
{
|
|
361 |
CAknIcon* icon = NULL;
|
|
362 |
|
|
363 |
if ( KErrNone == aItem.Type().Compare( KMenuTypeApp ) )
|
|
364 |
{
|
|
365 |
TBool attrExists( EFalse );
|
|
366 |
TPtrC appUidDes( aItem.GetAttributeL( KMenuAttrUid, attrExists ) );
|
|
367 |
if( appUidDes == KMenuSatUiUid )
|
|
368 |
{
|
|
369 |
CMcsSatHandler* satHandler = CMcsSatHandler::NewL();
|
|
370 |
CleanupStack::PushL( satHandler );
|
|
371 |
icon = satHandler->LoadIconL();
|
|
372 |
CleanupStack::PopAndDestroy( satHandler );
|
|
373 |
}
|
|
374 |
if( !icon )
|
|
375 |
{
|
|
376 |
if( aItem.GetAttributeL( KMenuAttrNative, attrExists ) == KMenuFalse )
|
|
377 |
{
|
|
378 |
CFbsBitmap* bitmap( 0 );
|
|
379 |
CFbsBitmap* mask( 0 );
|
|
380 |
//for native
|
|
381 |
if( CreateMbmIconLC2( bitmap, mask, appUidDes ) )
|
|
382 |
{
|
|
383 |
icon = CAknIcon::NewL();
|
|
384 |
icon->SetBitmap( bitmap );
|
|
385 |
icon->SetMask( mask );
|
|
386 |
CleanupStack::Pop( 2 );
|
|
387 |
}
|
|
388 |
}
|
|
389 |
if( !icon )
|
|
390 |
{
|
|
391 |
TUint appUid;
|
|
392 |
TUid uid;
|
|
393 |
TInt err = MenuUtils::GetTUint( appUidDes, appUid );
|
|
394 |
if ( !err )
|
|
395 |
{
|
|
396 |
uid = TUid::Uid( appUid );
|
|
397 |
icon = LoadAppSkinL( uid );
|
|
398 |
}
|
|
399 |
}
|
|
400 |
if( !icon )
|
|
401 |
{
|
|
402 |
icon = LoadSkinL(
|
|
403 |
KAknsIIDQgnMenuUnknownLst.iMajor,
|
|
404 |
KAknsIIDQgnMenuUnknownLst.iMinor );
|
|
405 |
}
|
|
406 |
}
|
|
407 |
}
|
|
408 |
else if ( KErrNone == aItem.Type().Compare( KMenuTypeFolder ) )
|
|
409 |
{
|
|
410 |
TUint childrenCount;
|
|
411 |
TBool attrExists( EFalse );
|
|
412 |
TInt err = MenuUtils::GetTUint(
|
|
413 |
aItem.GetAttributeL( KChildrenCount, attrExists ), childrenCount );
|
|
414 |
|
|
415 |
if( childrenCount > 0 )
|
|
416 |
{
|
|
417 |
icon = LoadSkinL(
|
|
418 |
KAknsIIDQgnPropFolderAppsMedium.iMajor,
|
|
419 |
KAknsIIDQgnPropFolderAppsMedium.iMinor );
|
|
420 |
}
|
|
421 |
else
|
|
422 |
{
|
|
423 |
icon = LoadSkinL(
|
|
424 |
KAknsIIDQgnMenuFolderEmpty.iMajor,
|
|
425 |
KAknsIIDQgnMenuFolderEmpty.iMinor );
|
|
426 |
|
|
427 |
}
|
|
428 |
|
|
429 |
}
|
|
430 |
|
|
431 |
return icon;
|
|
432 |
}
|
|
433 |
|
|
434 |
// ================= MEMBER FUNCTIONS =======================
|
|
435 |
|
|
436 |
|
|
437 |
// ---------------------------------------------------------
|
|
438 |
// MenuIconUtility::GetItemIconL
|
|
439 |
// ---------------------------------------------------------
|
|
440 |
//
|
|
441 |
EXPORT_C CAknIcon* MenuIconUtility::GetItemIconL( CMenuItem& aItem )
|
|
442 |
{
|
|
443 |
CAknIcon* icon = NULL;
|
|
444 |
// Try to get the skin of the item
|
|
445 |
TRAP_IGNORE(icon = GetSkinL( aItem ));
|
|
446 |
if ( icon )
|
|
447 |
{
|
|
448 |
return icon;
|
|
449 |
}
|
|
450 |
|
|
451 |
// Try to get the icon of the item (skin failed)
|
|
452 |
TRAP_IGNORE(icon = GetIconL( aItem ));
|
|
453 |
if ( icon )
|
|
454 |
{
|
|
455 |
return icon;
|
|
456 |
}
|
|
457 |
|
|
458 |
// Return a default (skin and icon failed)
|
|
459 |
icon = GetDefaultSkinL( aItem );
|
|
460 |
|
|
461 |
return icon;
|
|
462 |
}
|
|
463 |
|