83
|
1 |
/*
|
|
2 |
* Copyright (c) 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:
|
|
15 |
* CWmImageConverter implementation
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include <fbs.h>
|
|
20 |
#include <eikdef.h>
|
|
21 |
#include <eikenv.h>
|
|
22 |
#include <bautils.h>
|
|
23 |
#include <imageconversion.h>
|
|
24 |
#include <bitmaptransforms.h>
|
|
25 |
#include <AknIconUtils.h>
|
|
26 |
#include <AknsSkinInstance.h>
|
|
27 |
#include <AknsUtils.h>
|
|
28 |
#include <avkon.mbg>
|
|
29 |
#include <apgcli.h>
|
|
30 |
#include <SVGEngineInterfaceImpl.h>
|
|
31 |
#include <widgetregistryconstants.h> // KWidgetUidLowerBound, KWidgetUidUpperBound
|
|
32 |
|
|
33 |
#include "wmimageconverter.h"
|
|
34 |
|
|
35 |
_LIT( KSkin, "skin" );
|
|
36 |
_LIT( KMif, "mif" );
|
|
37 |
_LIT( KUid, "uid" );
|
|
38 |
_LIT( KColon, ":" );
|
|
39 |
_LIT( KSvgExt, ".svg" );
|
|
40 |
_LIT( KHexPrefix, "0x" );
|
|
41 |
const TUint KLeftParenthesis = '(';
|
|
42 |
|
|
43 |
// ---------------------------------------------------------
|
|
44 |
// CWmImageConverter::NewL
|
|
45 |
// ---------------------------------------------------------
|
|
46 |
//
|
|
47 |
CWmImageConverter* CWmImageConverter::NewL()
|
|
48 |
{
|
|
49 |
CWmImageConverter* self =
|
|
50 |
new(ELeave) CWmImageConverter();
|
|
51 |
CleanupStack::PushL( self );
|
|
52 |
self->ConstructL();
|
|
53 |
CleanupStack::Pop(self);
|
|
54 |
return self;
|
|
55 |
}
|
|
56 |
|
|
57 |
// ---------------------------------------------------------
|
|
58 |
// CWmImageConverter::CWmImageConverter
|
|
59 |
// ---------------------------------------------------------
|
|
60 |
//
|
|
61 |
CWmImageConverter::CWmImageConverter()
|
|
62 |
{
|
|
63 |
iBitmap = NULL;
|
|
64 |
iMask = NULL;
|
|
65 |
}
|
|
66 |
|
|
67 |
// ---------------------------------------------------------
|
|
68 |
// CWmImageConverter::ConstructL
|
|
69 |
// ---------------------------------------------------------
|
|
70 |
//
|
|
71 |
void CWmImageConverter::ConstructL()
|
|
72 |
{
|
|
73 |
User::LeaveIfError( iFs.Connect() );
|
|
74 |
iFs.ShareProtected();
|
|
75 |
}
|
|
76 |
|
|
77 |
// ---------------------------------------------------------
|
|
78 |
// CWmImageConverter::~CWmImageConverter
|
|
79 |
// ---------------------------------------------------------
|
|
80 |
//
|
|
81 |
CWmImageConverter::~CWmImageConverter()
|
|
82 |
{
|
|
83 |
iFs.Close();
|
|
84 |
if ( iBitmap )
|
|
85 |
{
|
|
86 |
delete iBitmap;
|
|
87 |
iBitmap = NULL;
|
|
88 |
}
|
|
89 |
if ( iMask )
|
|
90 |
{
|
|
91 |
delete iMask;
|
|
92 |
iMask = NULL;
|
|
93 |
}
|
|
94 |
}
|
|
95 |
|
|
96 |
// ---------------------------------------------------------
|
|
97 |
// CWmImageConverter::HandleIconString
|
|
98 |
// ---------------------------------------------------------
|
|
99 |
//
|
|
100 |
TInt CWmImageConverter::HandleIconString(
|
|
101 |
const TSize& aIconSize,
|
|
102 |
const TDesC& aIconStr,
|
|
103 |
CFbsBitmap*& aBitmap,
|
|
104 |
CFbsBitmap*& aMask )
|
|
105 |
{
|
|
106 |
delete aBitmap; aBitmap = NULL;
|
|
107 |
delete aMask; aMask = NULL;
|
|
108 |
|
|
109 |
TInt err( KErrNone );
|
|
110 |
TRAP( err, HandleIconStringL( aIconSize, aIconStr ); );
|
|
111 |
if ( err == KErrNone && iBitmap && iMask )
|
|
112 |
{
|
|
113 |
// ownership transferred
|
|
114 |
aBitmap = iBitmap;
|
|
115 |
iBitmap = NULL;
|
|
116 |
aMask = iMask;
|
|
117 |
iMask = NULL;
|
|
118 |
}
|
|
119 |
else
|
|
120 |
{
|
|
121 |
if ( iBitmap )
|
|
122 |
{
|
|
123 |
delete iBitmap;
|
|
124 |
iBitmap = NULL;
|
|
125 |
}
|
|
126 |
if ( iMask )
|
|
127 |
{
|
|
128 |
delete iMask;
|
|
129 |
iMask = NULL;
|
|
130 |
}
|
|
131 |
}
|
|
132 |
|
|
133 |
return err;
|
|
134 |
}
|
|
135 |
|
|
136 |
// ---------------------------------------------------------
|
|
137 |
// CWmImageConverter::HandleIconStringL
|
|
138 |
// ---------------------------------------------------------
|
|
139 |
//
|
|
140 |
void CWmImageConverter::HandleIconStringL(
|
|
141 |
const TSize& aIconSize,
|
|
142 |
const TDesC& aIconStr )
|
|
143 |
{
|
|
144 |
if ( aIconStr.Length() )
|
|
145 |
{
|
|
146 |
TAknsItemID skinItemId;
|
|
147 |
skinItemId.iMajor = 0;
|
|
148 |
skinItemId.iMinor = 0;
|
|
149 |
TInt bitmapId( KErrNotFound );
|
|
150 |
TInt maskId( KErrNotFound );
|
|
151 |
TUid appUid;
|
|
152 |
iFilename = KNullDesC;
|
|
153 |
iSize = aIconSize;
|
|
154 |
|
|
155 |
if ( ResolveSkinIdAndMifId(
|
|
156 |
aIconStr, skinItemId, bitmapId, maskId, iFilename ) )
|
|
157 |
{
|
|
158 |
CreateSkinOrMifIconL(
|
|
159 |
skinItemId, bitmapId, maskId, iFilename );
|
|
160 |
}
|
|
161 |
else if ( ResolveUid( aIconStr, appUid ) )
|
|
162 |
{
|
|
163 |
CreateIconFromUidL( appUid );
|
|
164 |
}
|
|
165 |
else if ( EndsWith( aIconStr, KSvgExt ) )
|
|
166 |
{
|
|
167 |
// filename_with_full_path.svg
|
|
168 |
CreateIconFromSvgL( aIconStr );
|
|
169 |
}
|
|
170 |
else if ( BaflUtils::FileExists( iFs, aIconStr ) )
|
|
171 |
{
|
|
172 |
// filename_with_full_path.png/jpg
|
|
173 |
CreateIconFromOtherL( aIconStr );
|
|
174 |
}
|
|
175 |
else
|
|
176 |
{
|
|
177 |
User::Leave( KErrArgument );
|
|
178 |
}
|
|
179 |
}
|
|
180 |
else
|
|
181 |
{
|
|
182 |
User::Leave( KErrArgument );
|
|
183 |
}
|
|
184 |
}
|
|
185 |
|
|
186 |
// ---------------------------------------------------------
|
|
187 |
// CWmImageConverter::CreateIconFromUidL
|
|
188 |
// ---------------------------------------------------------
|
|
189 |
//
|
|
190 |
void CWmImageConverter::CreateIconFromUidL( const TUid& aUid )
|
|
191 |
{
|
|
192 |
CFbsBitmap* bitmap = NULL;
|
|
193 |
CFbsBitmap* mask = NULL;
|
|
194 |
|
|
195 |
if ( aUid.iUid >= KWidgetUidLowerBound &&
|
|
196 |
aUid.iUid < KWidgetUidUpperBound )
|
|
197 |
{
|
|
198 |
RApaLsSession lsSession;
|
|
199 |
User::LeaveIfError( lsSession.Connect() );
|
|
200 |
CleanupClosePushL( lsSession );
|
|
201 |
|
|
202 |
const TInt KAppSizeArraySize = 3;
|
|
203 |
CArrayFixFlat<TSize>* sizeArray = new (ELeave)
|
|
204 |
CArrayFixFlat<TSize>( KAppSizeArraySize );
|
|
205 |
CleanupStack::PushL( sizeArray );
|
|
206 |
|
|
207 |
User::LeaveIfError( lsSession.GetAppIconSizes( aUid, *sizeArray ) );
|
|
208 |
|
|
209 |
// there should be atleast one size available
|
|
210 |
if ( sizeArray->Count() == 0 ){ User::Leave( KErrNotReady ); };
|
|
211 |
|
|
212 |
TSize size(0,0);
|
|
213 |
for( TInt i=0; i < sizeArray->Count(); i++ )
|
|
214 |
{
|
|
215 |
TSize s = (*sizeArray)[i];
|
|
216 |
if ( size.iWidth < s.iWidth || size.iHeight < s.iHeight )
|
|
217 |
{ size = s; }
|
|
218 |
if ( size == iSize ) { break; }
|
|
219 |
}
|
|
220 |
|
|
221 |
CApaMaskedBitmap* maskedBmp = CApaMaskedBitmap::NewLC();
|
|
222 |
User::LeaveIfError( lsSession.GetAppIcon( aUid, size, *maskedBmp ) );
|
|
223 |
|
|
224 |
// handle bitmap
|
|
225 |
iBitmap = new ( ELeave ) CFbsBitmap;
|
|
226 |
CopyBitmapL( *iBitmap, *maskedBmp );
|
|
227 |
|
|
228 |
// handle mask
|
|
229 |
if ( maskedBmp->Mask() )
|
|
230 |
{
|
|
231 |
iMask = new ( ELeave ) CFbsBitmap;
|
|
232 |
CopyBitmapL( *iMask, *maskedBmp->Mask() );
|
|
233 |
}
|
|
234 |
|
|
235 |
// cleanup
|
|
236 |
CleanupStack::PopAndDestroy( maskedBmp );
|
|
237 |
CleanupStack::PopAndDestroy( sizeArray );
|
|
238 |
CleanupStack::PopAndDestroy( &lsSession );
|
|
239 |
}
|
|
240 |
else if ( aUid.iUid != KNullUid.iUid )
|
|
241 |
{
|
|
242 |
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
|
|
243 |
TInt err( KErrNone );
|
|
244 |
TRAP( err,
|
|
245 |
{
|
|
246 |
AknsUtils::CreateAppIconLC( skin, aUid,
|
|
247 |
EAknsAppIconTypeContext, bitmap, mask );
|
|
248 |
CleanupStack::Pop( 2 ); // for trap
|
|
249 |
}
|
|
250 |
);
|
|
251 |
|
|
252 |
if( KErrNone != err )
|
|
253 |
{
|
|
254 |
// If icon is not created, try to create default application icon
|
|
255 |
AknsUtils::CreateIconLC( skin,
|
|
256 |
KAknsIIDQgnMenuUnknownLst, bitmap, mask,
|
|
257 |
AknIconUtils::AvkonIconFileName(),
|
|
258 |
EMbmAvkonQgn_menu_unknown_lst,
|
|
259 |
EMbmAvkonQgn_menu_unknown_lst_mask );
|
|
260 |
CleanupStack::Pop( 2 ); // for trap
|
|
261 |
}
|
|
262 |
|
|
263 |
iBitmap = bitmap;
|
|
264 |
iMask = mask;
|
|
265 |
err = AknIconUtils::SetSize( iBitmap , iSize, EAspectRatioPreserved );
|
|
266 |
if ( KErrNone == err )
|
|
267 |
{
|
|
268 |
err = AknIconUtils::SetSize( iMask , iSize, EAspectRatioPreserved );
|
|
269 |
}
|
|
270 |
}
|
|
271 |
else
|
|
272 |
{
|
|
273 |
User::Leave( KErrArgument );
|
|
274 |
}
|
|
275 |
}
|
|
276 |
|
|
277 |
// ---------------------------------------------------------
|
|
278 |
// CWmImageConverter::CreateIconFromSvgL
|
|
279 |
// ---------------------------------------------------------
|
|
280 |
//
|
|
281 |
void CWmImageConverter::CreateIconFromSvgL( const TDesC& aFileName )
|
|
282 |
{
|
|
283 |
if ( iBitmap )
|
|
284 |
{
|
|
285 |
delete iBitmap;
|
|
286 |
iBitmap = NULL;
|
|
287 |
}
|
|
288 |
if ( iMask )
|
|
289 |
{
|
|
290 |
delete iMask;
|
|
291 |
iMask = NULL;
|
|
292 |
}
|
|
293 |
|
|
294 |
TDisplayMode mode = CEikonEnv::Static()->ScreenDevice()->DisplayMode();
|
|
295 |
if ( mode >= ERgb ) // currently svg engine doesn't render correctly
|
|
296 |
{ mode = EColor16M; } // in this or above mode ( ou1cimx1#229434 )
|
|
297 |
TFontSpec fontspec;
|
|
298 |
|
|
299 |
CFbsBitmap* frameBuffer = new ( ELeave ) CFbsBitmap;
|
|
300 |
CleanupStack::PushL( frameBuffer );
|
|
301 |
frameBuffer->Create( iSize, mode );
|
|
302 |
|
|
303 |
CSvgEngineInterfaceImpl* svgEngine = CSvgEngineInterfaceImpl::NewL(
|
|
304 |
frameBuffer, NULL, fontspec );
|
|
305 |
CleanupStack::PushL( svgEngine );
|
|
306 |
|
|
307 |
svgEngine->SetDRMMode( EFalse );
|
|
308 |
|
|
309 |
TInt domHandle;
|
|
310 |
CheckSvgErrorL( svgEngine->PrepareDom( aFileName, domHandle ) );
|
|
311 |
|
|
312 |
CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
|
|
313 |
CleanupStack::PushL( bitmap );
|
|
314 |
User::LeaveIfError( bitmap->Create( iSize, mode ) );
|
|
315 |
|
|
316 |
CFbsBitmap* mask = new(ELeave) CFbsBitmap;
|
|
317 |
CleanupStack::PushL( mask );
|
|
318 |
User::LeaveIfError( mask->Create( iSize, EGray256 ) );
|
|
319 |
|
|
320 |
CheckSvgErrorL( svgEngine->UseDom( domHandle, bitmap, mask ) );
|
|
321 |
|
|
322 |
MSvgError* err;
|
|
323 |
svgEngine->Start( err );
|
|
324 |
CheckSvgErrorL( err );
|
|
325 |
|
|
326 |
CheckSvgErrorL( svgEngine->UseDom( domHandle, NULL, NULL ) );
|
|
327 |
CheckSvgErrorL( svgEngine->DeleteDom( domHandle ) );
|
|
328 |
|
|
329 |
CleanupStack::Pop( mask );
|
|
330 |
CleanupStack::Pop( bitmap );
|
|
331 |
CleanupStack::PopAndDestroy( svgEngine );
|
|
332 |
CleanupStack::PopAndDestroy( frameBuffer );
|
|
333 |
|
|
334 |
iBitmap = bitmap;
|
|
335 |
iMask = mask;
|
|
336 |
}
|
|
337 |
|
|
338 |
// ---------------------------------------------------------
|
|
339 |
// CWmImageConverter::CreateIconFromOtherL
|
|
340 |
// ---------------------------------------------------------
|
|
341 |
//
|
|
342 |
void CWmImageConverter::CreateIconFromOtherL( const TDesC& aFileName )
|
|
343 |
{
|
|
344 |
if (iBitmap) {delete iBitmap; iBitmap = NULL;}
|
|
345 |
if (iMask) {delete iMask; iMask = NULL;}
|
|
346 |
|
|
347 |
iFilename.Copy( aFileName );
|
|
348 |
|
|
349 |
// create the decoder
|
|
350 |
CImageDecoder* imageDecoder = CImageDecoder::FileNewL(
|
|
351 |
iFs, iFilename, CImageDecoder::EOptionAlwaysThread );
|
|
352 |
CleanupStack::PushL( imageDecoder );
|
|
353 |
|
|
354 |
TSize size = imageDecoder->FrameInfo().iOverallSizeInPixels;
|
|
355 |
|
|
356 |
// create the destination bitmap
|
|
357 |
iBitmap = new (ELeave) CFbsBitmap();
|
|
358 |
User::LeaveIfError( iBitmap->Create(
|
|
359 |
size, imageDecoder->FrameInfo().iFrameDisplayMode ) );
|
|
360 |
|
|
361 |
iMask = new (ELeave) CFbsBitmap();
|
|
362 |
User::LeaveIfError( iMask->Create( size, EGray256 ) );
|
|
363 |
|
|
364 |
// start conversion to bitmap
|
|
365 |
TRequestStatus status;
|
|
366 |
imageDecoder->Convert( &status, *iBitmap, *iMask );
|
|
367 |
User::WaitForRequest( status );
|
|
368 |
if( status.Int() == KErrUnderflow )
|
|
369 |
{
|
|
370 |
imageDecoder->ContinueConvert( &status );
|
|
371 |
User::WaitForRequest( status );
|
|
372 |
}
|
|
373 |
User::LeaveIfError( status.Int() );
|
|
374 |
CleanupStack::PopAndDestroy( imageDecoder );
|
|
375 |
}
|
|
376 |
|
|
377 |
// ---------------------------------------------------------------------------
|
|
378 |
// CWmImageConverter::CreateSkinOrMifIconL
|
|
379 |
// ---------------------------------------------------------------------------
|
|
380 |
//
|
|
381 |
void CWmImageConverter::CreateSkinOrMifIconL(
|
|
382 |
const TAknsItemID& aItemId, TInt aBitmapId,
|
|
383 |
TInt aMaskId, const TDesC& aFileName )
|
|
384 |
{
|
|
385 |
iFilename = aFileName;
|
|
386 |
CFbsBitmap* bitmap = NULL;
|
|
387 |
CFbsBitmap* mask = NULL;
|
|
388 |
|
|
389 |
// Load from skin
|
|
390 |
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
|
|
391 |
if ( skin && aItemId.iMajor != 0 && aItemId.iMinor != 0 )
|
|
392 |
{
|
|
393 |
TInt err( KErrNone );
|
|
394 |
CAknsMaskedBitmapItemData* itemData = NULL;
|
|
395 |
TRAP( err, itemData =
|
|
396 |
static_cast<CAknsMaskedBitmapItemData*>(
|
|
397 |
skin->CreateUncachedItemDataL( aItemId, EAknsITMaskedBitmap ) ); );
|
|
398 |
if( itemData && KErrNone == err )
|
|
399 |
{
|
|
400 |
CleanupStack::PushL( itemData );
|
|
401 |
// Detach bitmaps
|
|
402 |
bitmap = itemData->Bitmap();
|
|
403 |
itemData->SetBitmap( NULL );
|
|
404 |
mask = itemData->Mask();
|
|
405 |
itemData->SetMask( NULL );
|
|
406 |
CleanupStack::PopAndDestroy( itemData );
|
|
407 |
}
|
|
408 |
else
|
|
409 |
{
|
|
410 |
// look in imagetable
|
|
411 |
CAknsImageTableItemData* iconData = NULL;
|
|
412 |
TRAP( err, iconData = static_cast<CAknsImageTableItemData*>(
|
|
413 |
skin->CreateUncachedItemDataL( aItemId, EAknsITImageTable ) ); );
|
|
414 |
if( iconData && KErrNone == err )
|
|
415 |
{
|
|
416 |
CleanupStack::PushL( iconData );
|
|
417 |
if( iconData->NumberOfImages() )
|
|
418 |
{
|
|
419 |
TAknsItemID iconIId;
|
|
420 |
iconIId.Set( iconData->ImageIID(0) );
|
|
421 |
TRAP( err, AknsUtils::CreateIconL(
|
|
422 |
skin, iconIId, bitmap, mask, KNullDesC, -1, -1 ); );
|
|
423 |
}
|
|
424 |
CleanupStack::PopAndDestroy( iconData );
|
|
425 |
}
|
|
426 |
}
|
|
427 |
|
|
428 |
if ( KErrNone == err && bitmap )
|
|
429 |
{
|
|
430 |
TInt err = AknIconUtils::SetSize(
|
|
431 |
bitmap,
|
|
432 |
iSize,
|
|
433 |
EAspectRatioPreserved );
|
|
434 |
if ( KErrNone == err )
|
|
435 |
{
|
|
436 |
if ( mask )
|
|
437 |
{
|
|
438 |
err = AknIconUtils::SetSize(
|
|
439 |
mask,
|
|
440 |
iSize,
|
|
441 |
EAspectRatioPreserved );
|
|
442 |
}
|
|
443 |
iBitmap = bitmap;
|
|
444 |
iMask = mask;
|
|
445 |
return;
|
|
446 |
}
|
|
447 |
else
|
|
448 |
{
|
|
449 |
if ( bitmap ) { delete bitmap; bitmap = NULL; }
|
|
450 |
if ( mask ){ delete mask; mask = NULL; }
|
|
451 |
}
|
|
452 |
}
|
|
453 |
}
|
|
454 |
|
|
455 |
if( aBitmapId != KErrNotFound && !bitmap &&
|
|
456 |
aFileName.Length() && BaflUtils::FileExists( iFs, aFileName ) )
|
|
457 |
{
|
|
458 |
if ( aMaskId != KErrNotFound )
|
|
459 |
{
|
|
460 |
// Create icon from Mif filename , bitmap id and mask id
|
|
461 |
AknIconUtils::CreateIconL(
|
|
462 |
bitmap, mask, *this, aBitmapId, aMaskId );
|
|
463 |
}
|
|
464 |
else
|
|
465 |
{
|
|
466 |
bitmap = AknIconUtils::CreateIconL( *this, aBitmapId );
|
|
467 |
}
|
|
468 |
}
|
|
469 |
else
|
|
470 |
{
|
|
471 |
User::Leave( KErrArgument );
|
|
472 |
}
|
|
473 |
|
|
474 |
iBitmap = bitmap;
|
|
475 |
iMask = mask;
|
|
476 |
|
|
477 |
TInt err = AknIconUtils::SetSize( iBitmap , iSize, EAspectRatioPreserved );
|
|
478 |
if ( KErrNone == err && iMask )
|
|
479 |
{
|
|
480 |
err = AknIconUtils::SetSize( iMask , iSize, EAspectRatioPreserved );
|
|
481 |
}
|
|
482 |
}
|
|
483 |
|
|
484 |
// ---------------------------------------------------------
|
|
485 |
// CWmImageConverter::CheckSvgErrorL
|
|
486 |
// ---------------------------------------------------------
|
|
487 |
//
|
|
488 |
void CWmImageConverter::CheckSvgErrorL( MSvgError* aError )
|
|
489 |
{
|
|
490 |
if ( aError )
|
|
491 |
{
|
|
492 |
User::LeaveIfError( aError->SystemErrorCode() );
|
|
493 |
}
|
|
494 |
}
|
|
495 |
|
|
496 |
// ---------------------------------------------------------
|
|
497 |
// CWmImageConverter::EndsWith
|
|
498 |
// ---------------------------------------------------------
|
|
499 |
//
|
|
500 |
TBool CWmImageConverter::EndsWith( const TDesC& aString,
|
|
501 |
const TDesC& aPattern )
|
|
502 |
{
|
|
503 |
return ( aString.Right( aPattern.Length() ) == aPattern );
|
|
504 |
}
|
|
505 |
|
|
506 |
// ---------------------------------------------------------------------------
|
|
507 |
// CWmImageConverter::ResolveUid
|
|
508 |
// ---------------------------------------------------------------------------
|
|
509 |
//
|
|
510 |
TBool CWmImageConverter::ResolveUid(
|
|
511 |
const TDesC& aPath, TUid& aUid )
|
|
512 |
{
|
|
513 |
// Syntax: uid(0x12345678)
|
|
514 |
TInt error = KErrNotFound;
|
|
515 |
TInt pos = aPath.FindF( KUid );
|
|
516 |
if( pos == 0 )
|
|
517 |
{
|
|
518 |
// Skip uid token
|
|
519 |
pos += KUid().Length();
|
|
520 |
|
|
521 |
// Initialize lexer
|
|
522 |
TLex lex( aPath.Mid( pos ) );
|
|
523 |
lex.SkipSpaceAndMark();
|
|
524 |
|
|
525 |
// Check left parenthesis
|
|
526 |
if ( lex.Get() == KLeftParenthesis )
|
|
527 |
{
|
|
528 |
error = ParseNextUint( lex, (TUint&)aUid.iUid );
|
|
529 |
}
|
|
530 |
}
|
|
531 |
|
|
532 |
return (error == KErrNone );
|
|
533 |
}
|
|
534 |
|
|
535 |
// ---------------------------------------------------------------------------
|
|
536 |
// CWmImageConverter::ResolveSkinId
|
|
537 |
// ---------------------------------------------------------------------------
|
|
538 |
//
|
|
539 |
TBool CWmImageConverter::ResolveSkinId(
|
|
540 |
const TDesC& aPath, TAknsItemID& aItemId )
|
|
541 |
{
|
|
542 |
// Syntax: skin(major minor)
|
|
543 |
TInt error = KErrNotFound;
|
|
544 |
TInt pos = aPath.FindF( KSkin );
|
|
545 |
if( pos == 0 )
|
|
546 |
{
|
|
547 |
// Skip skin token
|
|
548 |
pos += KSkin().Length();
|
|
549 |
|
|
550 |
// Initialize lexer
|
|
551 |
TLex lex( aPath.Mid( pos ) );
|
|
552 |
lex.SkipSpaceAndMark();
|
|
553 |
|
|
554 |
// Check left parenthesis
|
|
555 |
if ( lex.Get() == KLeftParenthesis )
|
|
556 |
{
|
|
557 |
TUint majorId = 0;
|
|
558 |
TUint minorId = 0;
|
|
559 |
error = ParseNextUint( lex, majorId );
|
|
560 |
error |= ParseNextUint( lex, minorId );
|
|
561 |
aItemId.Set( majorId, minorId );
|
|
562 |
}
|
|
563 |
}
|
|
564 |
|
|
565 |
return (error == KErrNone );
|
|
566 |
}
|
|
567 |
|
|
568 |
// ---------------------------------------------------------------------------
|
|
569 |
// CWmImageConverter::ResolveMifId
|
|
570 |
// ---------------------------------------------------------------------------
|
|
571 |
//
|
|
572 |
TBool CWmImageConverter::ResolveMifId(
|
|
573 |
const TDesC& aPath, TInt& aBitmapId,
|
|
574 |
TInt& aMaskId, TDes& aFileName )
|
|
575 |
{
|
|
576 |
// Syntax: mif(filename bimapId maskId)
|
|
577 |
TInt error = KErrNotFound;
|
|
578 |
TInt pos = aPath.FindF( KMif );
|
|
579 |
if( pos == 0 )
|
|
580 |
{
|
|
581 |
// Skip mif token
|
|
582 |
pos += KMif().Length();
|
|
583 |
// Initialize lexer
|
|
584 |
TLex lex( aPath.Mid( pos ) );
|
|
585 |
lex.SkipSpaceAndMark();
|
|
586 |
|
|
587 |
// Check left parenthesis
|
|
588 |
if ( lex.Get() == KLeftParenthesis )
|
|
589 |
{
|
|
590 |
lex.SkipSpaceAndMark();
|
|
591 |
lex.SkipCharacters();
|
|
592 |
// Resolve MifFile name
|
|
593 |
aFileName.Copy(lex.MarkedToken());
|
|
594 |
if( aFileName.Length()!= 0)
|
|
595 |
{
|
|
596 |
TUint bitmap, mask;
|
|
597 |
error = ParseNextUint( lex, bitmap );
|
|
598 |
ParseNextUint( lex, mask ); // mask is not mandatory
|
|
599 |
aBitmapId = bitmap;
|
|
600 |
aMaskId = mask;
|
|
601 |
}
|
|
602 |
}
|
|
603 |
}
|
|
604 |
return ( error == KErrNone );
|
|
605 |
}
|
|
606 |
|
|
607 |
// ---------------------------------------------------------------------------
|
|
608 |
// CWmImageConverter::ResolveSkinIdAndMifId
|
|
609 |
// ---------------------------------------------------------------------------
|
|
610 |
//
|
|
611 |
TBool CWmImageConverter::ResolveSkinIdAndMifId(
|
|
612 |
const TDesC& aPath, TAknsItemID& aItemId,
|
|
613 |
TInt& aBitmapId, TInt& aMaskId, TDes& aFileName )
|
|
614 |
{
|
|
615 |
// Syntax: skin(major minor):mif(filename bimapId maskId)
|
|
616 |
TBool result = ResolveSkinId( aPath, aItemId );
|
|
617 |
if ( result )
|
|
618 |
{
|
|
619 |
TInt pos = aPath.FindF( KColon );
|
|
620 |
if ( pos != KErrNotFound )
|
|
621 |
{
|
|
622 |
TPtrC ptr = aPath.Mid( pos+1 );
|
|
623 |
result = ResolveMifId( ptr, aBitmapId, aMaskId, aFileName );
|
|
624 |
}
|
|
625 |
}
|
|
626 |
else
|
|
627 |
{
|
|
628 |
result = ResolveMifId( aPath, aBitmapId, aMaskId, aFileName );
|
|
629 |
}
|
|
630 |
return result;
|
|
631 |
}
|
|
632 |
|
|
633 |
// ---------------------------------------------------------------------------
|
|
634 |
// CWmImageConverter::ParseNextUint()
|
|
635 |
// ---------------------------------------------------------------------------
|
|
636 |
//
|
|
637 |
TInt CWmImageConverter::ParseNextUint( TLex& aLex, TUint& aValue )
|
|
638 |
{
|
|
639 |
TInt error = KErrNone;
|
|
640 |
aLex.SkipSpaceAndMark();
|
|
641 |
aLex.SkipCharacters();
|
|
642 |
|
|
643 |
TPtrC mtoken = aLex.MarkedToken();
|
|
644 |
TInt pos = mtoken.FindF( KHexPrefix );
|
|
645 |
if ( pos == 0 )
|
|
646 |
{
|
|
647 |
TLex innerLex( mtoken.Mid( KHexPrefix().Length() ) );
|
|
648 |
error = innerLex.Val( aValue, EHex );
|
|
649 |
}
|
|
650 |
else
|
|
651 |
{
|
|
652 |
TLex innerLex( mtoken );
|
|
653 |
error = innerLex.Val( aValue, EDecimal );
|
|
654 |
}
|
|
655 |
|
|
656 |
return error;
|
|
657 |
}
|
|
658 |
|
|
659 |
// ---------------------------------------------------------------------------
|
|
660 |
// CWmImageConverter::RetrieveIconFileHandleL
|
|
661 |
// ---------------------------------------------------------------------------
|
|
662 |
//
|
|
663 |
void CWmImageConverter::RetrieveIconFileHandleL(
|
|
664 |
RFile& aFile, const TIconFileType /*aType*/ )
|
|
665 |
{
|
|
666 |
TInt err = aFile.Open( iFs, iFilename,
|
|
667 |
EFileRead | EFileShareReadersOnly );
|
|
668 |
if ( KErrNone != err )
|
|
669 |
{
|
|
670 |
User::Leave( err );
|
|
671 |
}
|
|
672 |
}
|
|
673 |
|
|
674 |
// ---------------------------------------------------------------------------
|
|
675 |
// CWmImageConverter::CopyBitmapL
|
|
676 |
// ---------------------------------------------------------------------------
|
|
677 |
//
|
|
678 |
void CWmImageConverter::CopyBitmapL(
|
|
679 |
CFbsBitmap& aTrgBitmap,
|
|
680 |
CFbsBitmap& aSrcBitmap )
|
|
681 |
{
|
|
682 |
TSize size( aSrcBitmap.SizeInPixels() );
|
|
683 |
TDisplayMode displayMode( aSrcBitmap.DisplayMode() );
|
|
684 |
User::LeaveIfError( aTrgBitmap.Create( size, displayMode ) );
|
|
685 |
|
|
686 |
HBufC8* scanLine = HBufC8::NewL( aSrcBitmap.ScanLineLength(
|
|
687 |
size.iWidth, displayMode ) );
|
|
688 |
TPtr8 scanPtr( scanLine->Des() );
|
|
689 |
TPoint pp;
|
|
690 |
for( pp.iY = 0; pp.iY < size.iHeight; ++pp.iY )
|
|
691 |
{
|
|
692 |
aSrcBitmap.GetScanLine( scanPtr, pp, size.iWidth, displayMode );
|
|
693 |
aTrgBitmap.SetScanLine( scanPtr, pp.iY );
|
|
694 |
}
|
|
695 |
delete scanLine;
|
|
696 |
}
|
|
697 |
|
|
698 |
// ---------------------------------------------------------------------------
|
|
699 |
// CWmImageConverter::Finished
|
|
700 |
// ---------------------------------------------------------------------------
|
|
701 |
//
|
|
702 |
void CWmImageConverter::Finished()
|
|
703 |
{
|
|
704 |
// finishes using the icon file. No actions needed here.
|
|
705 |
}
|
|
706 |
|
|
707 |
// ---------------------------------------------------------------------------
|
|
708 |
// CWmImageConverter::UpdateImageSize
|
|
709 |
// ---------------------------------------------------------------------------
|
|
710 |
//
|
|
711 |
void CWmImageConverter::UpdateImageSize(
|
|
712 |
const TSize& aSize,
|
|
713 |
const TDesC& aIconStr,
|
|
714 |
CFbsBitmap& aBitmap,
|
|
715 |
CFbsBitmap& aMask )
|
|
716 |
{
|
|
717 |
if ( aIconStr.Length() && iSize != aSize )
|
|
718 |
{
|
|
719 |
TAknsItemID skinItemId;
|
|
720 |
skinItemId.iMajor = 0;
|
|
721 |
skinItemId.iMinor = 0;
|
|
722 |
TInt bitmapId( KErrNotFound );
|
|
723 |
TInt maskId( KErrNotFound );
|
|
724 |
TUid appUid;
|
|
725 |
iFilename = KNullDesC;
|
|
726 |
iSize = aSize;
|
|
727 |
|
|
728 |
if ( ResolveSkinIdAndMifId(
|
|
729 |
aIconStr, skinItemId, bitmapId, maskId, iFilename ) )
|
|
730 |
{
|
|
731 |
AknIconUtils::SetSize( &aBitmap, iSize );
|
|
732 |
AknIconUtils::SetSize( &aMask, iSize );
|
|
733 |
}
|
|
734 |
else if ( ResolveUid( aIconStr, appUid ) )
|
|
735 |
{
|
|
736 |
if ( appUid.iUid >= KWidgetUidLowerBound &&
|
|
737 |
appUid.iUid < KWidgetUidUpperBound )
|
|
738 |
{
|
|
739 |
//WRT. No resize needed here
|
|
740 |
return;
|
|
741 |
}
|
|
742 |
else if ( appUid.iUid != KNullUid.iUid )
|
|
743 |
{
|
|
744 |
AknIconUtils::SetSize( &aBitmap, iSize );
|
|
745 |
AknIconUtils::SetSize( &aMask, iSize );
|
|
746 |
}
|
|
747 |
}
|
|
748 |
}
|
|
749 |
}
|
|
750 |
|
|
751 |
// End of file
|
|
752 |
|