skins/AknSkins/srvsrc/AknsSrvChunkMaintainer.cpp
changeset 0 05e9090e2422
child 79 a1b3ef187795
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2003-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:  Chunk maintainer.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "AknsSrvChunkMaintainer.h"
       
    22 
       
    23 #include <AknsSrvClient.h>
       
    24 #include "AknsSrvUtils.h"
       
    25 #include <AknsConstants.h>
       
    26 #include "AknsSrvDescriptorFileLayout.h"
       
    27 #include "AknsSrvBitmapStore.h"
       
    28 #include <fbs.h>
       
    29 #include <bautils.h>
       
    30 #include "AknsSrvVariant.hrh"
       
    31 #include <versioninfo.h>
       
    32 
       
    33 #include <AknsSkinUID.h>
       
    34 
       
    35 #include "AknsDebug.h"
       
    36 
       
    37 
       
    38 // CONSTANTS
       
    39 static const TInt KAknsSrvMinMorphingInterval = 60; // in seconds
       
    40 static const TInt KAknsSrvSkipMajor = -3;
       
    41 static const TInt KAknsSrvSkipMinor = -3;
       
    42 static const TInt KAknsSrvRewriteMajor = -4;
       
    43 static const TInt KAknsSrvRewriteBase = -256;
       
    44 
       
    45 static const TInt KAknsSrvMaxChunkReaders = 127;
       
    46 
       
    47 static const TInt KAknsSrvTextColorGroupCount = 63;
       
    48 
       
    49 // All of the following constants _MUST_ be divisible by 4
       
    50 // This value seems to be most efficient when comparing memory consumption:
       
    51 static const TInt KAknsSrvSharedChunkInitialSize = 160*1024;
       
    52 static const TInt KAknsSrvSharedChunkMaxSize = 384*1024;
       
    53 // This value seems to be most efficient when comparing memory consumption:
       
    54 static const TInt KAknsSrvSharedChunkGranularity = 4*1024;
       
    55 static const TInt KAknsSrvSharedChunkHeaderAreaSize = 16*4;
       
    56 
       
    57 static const TInt KAknsSrvMaxHashList = 128;
       
    58 static const TInt KAknsSrvMaxHashSize = 1024;
       
    59 
       
    60 static const TInt32 KAknsSrvIdleWallpaperFilenameID = 0xc0def00d;
       
    61 
       
    62 static const TInt KAknsSrvMaxScalableGfxItems =
       
    63     KAknsSrvSharedChunkGranularity / sizeof(TAknsSrvScalableItemDef);
       
    64 
       
    65 _LIT(KAknsSrvScalableRomBmpLocation,":\\resource\\skins\\");
       
    66 _LIT(KAknsSrvPathEndSeparator, "\\");
       
    67 
       
    68 // ============================= LOCAL FUNCTIONS ===============================
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // TAknsSrvCMPostOp::LinearOrder
       
    72 //
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 TInt TAknsSrvCMPostOp::LinearOrder(
       
    76     const TAknsSrvCMPostOp& aFirst,
       
    77     const TAknsSrvCMPostOp& aSecond )
       
    78     {
       
    79     return TAknsItemID::LinearOrder( aFirst.iIID, aSecond.iIID );
       
    80     }
       
    81 
       
    82 // ============================ MEMBER FUNCTIONS ===============================
       
    83 
       
    84  CAknsSrvMorphingTimer* CAknsSrvMorphingTimer::NewL(MAknsSrvMorphingListener* aListener, TInt aInterval)
       
    85     {
       
    86     CAknsSrvMorphingTimer* self = new (ELeave)CAknsSrvMorphingTimer(aListener, aInterval);
       
    87     CleanupStack::PushL(self);
       
    88     self->ConstructL();
       
    89     CleanupStack::Pop( self );
       
    90     return self;
       
    91     }
       
    92 
       
    93 void CAknsSrvMorphingTimer::RunL()
       
    94     {
       
    95     iListener->MorhphingEventTimeout();
       
    96     IssueRequest();
       
    97     }
       
    98 
       
    99 void CAknsSrvMorphingTimer::DoCancel()
       
   100     {
       
   101     iTimer.Cancel();
       
   102     }
       
   103 
       
   104 void CAknsSrvMorphingTimer::IssueRequest()
       
   105     {
       
   106     if ( !IsActive() )
       
   107         {
       
   108         TTime now;
       
   109         now.HomeTime();
       
   110         now+=TTimeIntervalSeconds(iInterval);
       
   111         iTimer.At(iStatus, now);
       
   112         SetActive();
       
   113         }
       
   114     }
       
   115 
       
   116 CAknsSrvMorphingTimer::~CAknsSrvMorphingTimer()
       
   117     {
       
   118     Cancel();
       
   119     iTimer.Close();
       
   120     }
       
   121 
       
   122 void CAknsSrvMorphingTimer::ConstructL()
       
   123     {
       
   124     User::LeaveIfError(iTimer.CreateLocal());
       
   125     }
       
   126 
       
   127 CAknsSrvMorphingTimer::CAknsSrvMorphingTimer(MAknsSrvMorphingListener* aListener,TInt aInterval) :
       
   128         CActive(CActive::EPriorityStandard),
       
   129         iListener(aListener),
       
   130         iInterval(aInterval)
       
   131     {
       
   132     CActiveScheduler::Add(this);
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // Destructor
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 CAknsSrvChunkMaintainer::~CAknsSrvChunkMaintainer()
       
   140     {
       
   141     // We should never reach here, but just in case...
       
   142     delete iMorphingTimer;
       
   143     iSharedChunk.Close();
       
   144     iWaitSema.Close();
       
   145     iRenderMutex.Close();
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // Constructor
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 CAknsSrvChunkMaintainer::CAknsSrvChunkMaintainer(CAknsSrvBitmapStore* aBitmapStore)
       
   153     {
       
   154     // Size sanity checks
       
   155     __ASSERT_DEBUG(
       
   156         KAknsSrvSharedChunkInitialSize <= KAknsSrvSharedChunkMaxSize,
       
   157         User::Panic(KAknSkinSrvPanicCategory, EAknsSrvInvalidBuildConf ) );
       
   158 
       
   159     TInt err = iSharedChunk.CreateGlobal(KAKNSSRVSHAREDMEMORYCHUNKNAME,
       
   160         KAknsSrvSharedChunkInitialSize, KAknsSrvSharedChunkMaxSize );
       
   161 
       
   162     if (!err)
       
   163         {
       
   164         err = iWaitSema.CreateGlobal(KAKNSSRVWAITSEMAPHORENAME,
       
   165             KAknsSrvMaxChunkReaders);
       
   166         iInternalSemaCount = 0;
       
   167         }
       
   168 
       
   169     if( !err )
       
   170         {
       
   171         err = iRenderMutex.CreateGlobal(KAKNSSRVRENDERMUTEXNAME);
       
   172         }
       
   173 
       
   174     if (err)
       
   175         {
       
   176         AKNS_TRACE_ERROR("CAknsSrvChunkMaintainer::Constructor CANNOT CREATE SHARED CHUNK!");
       
   177         User::Panic(KAknSkinSrvPanicCategory, EAknsSrvCannotCreateSharedChunk);
       
   178         }
       
   179 
       
   180     VersionInfo::TPlatformVersion platformVersion;
       
   181     TRAP( err,VersionInfo::GetVersion( platformVersion ) );
       
   182     if ( !err )
       
   183         {
       
   184         iPlatformMajor = platformVersion.iMajorVersion;
       
   185         iPlatformMinor = platformVersion.iMinorVersion;
       
   186         }
       
   187     else 
       
   188         {
       
   189         iPlatformMajor = 0;
       
   190         iPlatformMinor = 0;
       
   191         }
       
   192     
       
   193     iCurrentFilenameID = 0;
       
   194     iBitmapStore = aBitmapStore;
       
   195     iMergeS60Skin = EFalse;
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CAknsSrvChunkMaintainer::MergeSkinDefinitionsL
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CAknsSrvChunkMaintainer::MergeSkinDefinitionsL( const TPtrC& aFilename,
       
   203     const TAknsItemDefClass aClass, const TBool aClearChunk,
       
   204     const TAknsSrvExclusionQuery& aExclQuery,
       
   205     const TBool aAhOverride,
       
   206     const TAknsPkgID& aPID )
       
   207     {
       
   208     // Do not merge other than bitmap classes
       
   209     if( aClass != EAknsItemDefClassBitmaps ) return;
       
   210 
       
   211     // Block read access to the shared chunk while writing new values
       
   212     BeginWrite();
       
   213     iMorphingMinInterval = -1;
       
   214     if (iMorphingTimer)
       
   215         {
       
   216         delete iMorphingTimer;
       
   217         iMorphingTimer = NULL;
       
   218         }
       
   219     
       
   220     if ( aPID == KAknsPIDS60DefaultSkin )
       
   221         {
       
   222         iMergeS60Skin = ETrue;
       
   223         }
       
   224     TRAPD( mergeErr, MergeSkinDefinitionsUnprotectedL( aFilename,
       
   225         aClearChunk, aExclQuery, aAhOverride, aPID) );
       
   226     
       
   227     iMergeS60Skin = EFalse;
       
   228     // And allow read access again...
       
   229     EndWrite();
       
   230 
       
   231     User::LeaveIfError( mergeErr );
       
   232     }
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CAknsSrvChunkMaintainer::SetWallpaper
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 void CAknsSrvChunkMaintainer::SetWallpaper( const TAknsItemID& aIID,
       
   239     const TDesC& aFilename, TInt /*aIndex*/ )
       
   240     {
       
   241     BeginWrite();
       
   242 
       
   243     TAknsSrvDef wallpaperDef;
       
   244     wallpaperDef.iID.iMajor = EAknsMajorSkin;
       
   245     wallpaperDef.iID.iMinor = EAknsMinorWallpaper;
       
   246 
       
   247     TInt32 filenameid;
       
   248     if( aIID == KAknsIIDWallpaper )
       
   249         {
       
   250         if (aFilename.Length() > 0)
       
   251             {
       
   252             filenameid = KAknsSrvIdleWallpaperFilenameID;
       
   253             }
       
   254         else
       
   255             {
       
   256             TInt index = FindDefIndex( wallpaperDef.iID );
       
   257             TAknsSrvDef* trgDef = NULL;
       
   258             if (index >= 0)
       
   259                 {
       
   260                 trgDef = (TAknsSrvDef*)( GetAreaBasePtr(EAknsSrvItemDefArea)
       
   261                     + index*sizeof(TAknsSrvDef) );
       
   262                 trgDef->iID.iMajor = KAknsSrvSkipMajor;
       
   263                 trgDef->iID.iMinor = KAknsSrvSkipMinor;
       
   264                 }
       
   265             EndWrite();
       
   266             return;
       
   267             }
       
   268         }
       
   269     else
       
   270         {
       
   271         EndWrite();
       
   272         return;
       
   273         }
       
   274     UpdateFilename( filenameid, (TUint8*)aFilename.Ptr(),
       
   275         (TUint16)(aFilename.Length()), KNullDesC());
       
   276 
       
   277     wallpaperDef.iType = EAknsITEffectQueue;
       
   278 
       
   279     TAknsSrvEffectQueueDef applyGfxEffectQueue;
       
   280     applyGfxEffectQueue.iEffectQueueSize = sizeof(TAknsSrvEffectQueueDef)
       
   281         + 2*sizeof(TAknsSrvEffectDef) + 3*sizeof(TAknsSrvEffectParameterDef)
       
   282         + 11*sizeof(TInt32);
       
   283     applyGfxEffectQueue.iInputLayerIndex =0;
       
   284     applyGfxEffectQueue.iInputLayerMode = 2; //RGB
       
   285     applyGfxEffectQueue.iOutputLayerIndex = 2;
       
   286     applyGfxEffectQueue.iOutputLayerMode = 2; //RGB
       
   287     applyGfxEffectQueue.iEffectCount = 2;
       
   288     applyGfxEffectQueue.iRefMajor = 0;
       
   289     applyGfxEffectQueue.iRefMinor = 0;
       
   290 
       
   291     TAknsSrvEffectDef applyGfxEffectDef;
       
   292     applyGfxEffectDef.iEffectUid.iUid = 0x101F8748;
       
   293     applyGfxEffectDef.iInputLayerAIndex = 0;
       
   294     applyGfxEffectDef.iInputLayerAMode = 1;
       
   295     applyGfxEffectDef.iInputLayerBIndex = 0;
       
   296     applyGfxEffectDef.iInputLayerBMode = 1;
       
   297     applyGfxEffectDef.iOutputLayerIndex = 1;
       
   298     applyGfxEffectDef.iOutputLayerMode = 8; //  1/RGBA
       
   299     applyGfxEffectDef.iEffectParameterCount = 2;
       
   300     applyGfxEffectDef.iEffectSize = sizeof(TAknsSrvEffectDef)
       
   301         + 2*sizeof(TAknsSrvEffectParameterDef)+4*sizeof(TInt32)+2*sizeof(TInt32);
       
   302 
       
   303     TAknsSrvEffectParameterDef applyGfxParams;
       
   304     applyGfxParams.iParameterLength =
       
   305         sizeof(TAknsSrvEffectParameterDef)+4*sizeof(TInt32);
       
   306     applyGfxParams.iParameterType = 2; // graphics file
       
   307 
       
   308     TAknsSrvEffectParameterDef applyGfxParams2;
       
   309     applyGfxParams2.iParameterLength =
       
   310         sizeof(TAknsSrvEffectParameterDef)+2*sizeof(TInt32);
       
   311     applyGfxParams2.iParameterType = 0; // int
       
   312 
       
   313 
       
   314 
       
   315     TAknsSrvEffectDef alphaBlendEffectDef;
       
   316     alphaBlendEffectDef.iEffectUid.iUid = 0x10204add;
       
   317     alphaBlendEffectDef.iInputLayerAIndex = 0;
       
   318     alphaBlendEffectDef.iInputLayerAMode = 8; // RGBA
       
   319     alphaBlendEffectDef.iInputLayerBIndex = 1;
       
   320     alphaBlendEffectDef.iInputLayerBMode = 8; // RGBA
       
   321     alphaBlendEffectDef.iOutputLayerIndex = 2;
       
   322     alphaBlendEffectDef.iOutputLayerMode = 2; // RGB
       
   323     alphaBlendEffectDef.iEffectParameterCount = 1;
       
   324     alphaBlendEffectDef.iEffectSize = sizeof(TAknsSrvEffectDef)
       
   325         + sizeof(TAknsSrvEffectParameterDef)+2*sizeof(TInt32);
       
   326 
       
   327 
       
   328     TAknsSrvEffectParameterDef alphaBlendParams;
       
   329     alphaBlendParams.iParameterLength =
       
   330         sizeof(TAknsSrvEffectParameterDef)+2*sizeof(TInt32);
       
   331     alphaBlendParams.iParameterType = 0; // int
       
   332 
       
   333 
       
   334     TInt32 bitmapIndex = 0;
       
   335     TInt32 maskindex = 0;
       
   336     TInt32 filenameOffset = GetFilenameOffsetByID(filenameid);// offset replaces the id
       
   337 
       
   338     TUint8* eqblock = NULL;
       
   339     TRAPD( err,
       
   340         eqblock = new (ELeave) TUint8[
       
   341             sizeof(TAknsSrvEffectQueueDef) + 2*sizeof(TAknsSrvEffectDef)
       
   342             + 3*sizeof(TAknsSrvEffectParameterDef) + 2*sizeof(TInt32) + 4*sizeof(TInt32) + 2*sizeof(TInt32) ] );
       
   343     if ( err != KErrNone )
       
   344         {
       
   345         EndWrite();
       
   346         delete [] eqblock;
       
   347         return;
       
   348         }
       
   349     TUint8 *ptr = eqblock;
       
   350 
       
   351     Mem::Copy(ptr,&applyGfxEffectQueue, sizeof(TAknsSrvEffectQueueDef));
       
   352     ptr+=sizeof(TAknsSrvEffectQueueDef);
       
   353     Mem::Copy(ptr,&applyGfxEffectDef, sizeof(TAknsSrvEffectDef));
       
   354     ptr+=sizeof(TAknsSrvEffectDef);
       
   355     Mem::Copy(ptr, &applyGfxParams, sizeof(TAknsSrvEffectParameterDef));
       
   356     ptr+=sizeof(TAknsSrvEffectParameterDef);
       
   357     // applygfx params...
       
   358     *((TUint16*)(ptr)) = 1;
       
   359     ptr+=2; // sizeof TUint16
       
   360     *((TUint16*)(ptr)) = 'f';
       
   361     ptr+=2; // sizeof TUint16
       
   362     *((TUint32*)(ptr)) = bitmapIndex;
       
   363     ptr+=4;
       
   364     *((TUint32*)(ptr)) = maskindex;
       
   365     ptr+=4;
       
   366     *((TUint32*)(ptr)) = filenameOffset;
       
   367     ptr+=4;
       
   368     // generic image
       
   369     Mem::Copy(ptr, &applyGfxParams2, sizeof(TAknsSrvEffectParameterDef));
       
   370     ptr+=sizeof(TAknsSrvEffectParameterDef);
       
   371     *((TUint16*)(ptr)) = 1;
       
   372     ptr+=2; // sizeof TUint16
       
   373     *((TUint16*)(ptr)) = 'g';
       
   374     ptr+=2;
       
   375     *((TUint32*)(ptr)) = 1;
       
   376     ptr+=4;
       
   377 
       
   378 
       
   379     //alphablend
       
   380     Mem::Copy(ptr, &alphaBlendEffectDef, sizeof(TAknsSrvEffectDef));
       
   381     ptr+=sizeof(TAknsSrvEffectDef);
       
   382     Mem::Copy(ptr, &alphaBlendParams,sizeof(TAknsSrvEffectParameterDef));
       
   383     ptr+=sizeof(TAknsSrvEffectParameterDef);
       
   384 
       
   385     *((TUint16*)(ptr)) = 1;
       
   386     ptr+=2;
       
   387     *((TUint16*)(ptr)) = 'm';
       
   388     ptr+=2;
       
   389     *((TUint32*)(ptr)) = 1;
       
   390     ptr+=4;
       
   391 
       
   392     TAknsSrvEffectQueueDef* eqDef = (TAknsSrvEffectQueueDef*)eqblock;
       
   393 
       
   394     UpdateDef( &wallpaperDef, eqDef,     applyGfxEffectQueue.iEffectQueueSize, -1 );
       
   395     delete [] eqblock;
       
   396     EndWrite();
       
   397     }
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CAknsSrvChunkMaintainer::BeginWrite
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 void CAknsSrvChunkMaintainer::BeginWrite()
       
   404     {
       
   405     iInternalSemaCount++;
       
   406     if( iInternalSemaCount > 1 )
       
   407         {
       
   408         // Chunk already locked
       
   409         return;
       
   410         }
       
   411 #if defined(_DEBUG)
       
   412     if( iInternalSemaCount < 1 )
       
   413         {
       
   414         AKNS_TRACE_ERROR("CAknsSrvChunkMaintainer::BeginWrite Internal error, internal counter underflow!");
       
   415         AKNS_DEBUG_PANIC(EAknsDPanicBadState);
       
   416         }
       
   417 #endif
       
   418     // Wait if there is a read in progress...
       
   419     for (TInt count = 0;count < KAknsSrvMaxChunkReaders;count++)
       
   420         {
       
   421         iWaitSema.Wait();
       
   422         }
       
   423     }
       
   424 
       
   425 // -----------------------------------------------------------------------------
       
   426 // CAknsSrvChunkMaintainer::EndWrite
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 void CAknsSrvChunkMaintainer::EndWrite()
       
   430     {
       
   431     iInternalSemaCount--;
       
   432     if( iInternalSemaCount > 0 )
       
   433         {
       
   434         // Chunk must be left locked
       
   435         return;
       
   436         }
       
   437     iWaitSema.Signal(KAknsSrvMaxChunkReaders);
       
   438 
       
   439 #if defined(_DEBUG)
       
   440     if( iInternalSemaCount < 0 )
       
   441         {
       
   442         AKNS_TRACE_ERROR("CAknsSrvChunkMaintainer::EndWrite Internal error, internal counter underflow!");
       
   443         AKNS_DEBUG_PANIC(EAknsDPanicBadState);
       
   444         }
       
   445 #endif
       
   446 
       
   447     AKNS_TRACE_INFO("------------------------------------------------------------------");
       
   448     AKNS_TRACE_INFO1("AknSkinSrv: Total SharedChunk size at EndWrite operation %d bytes", iSharedChunk.Size());
       
   449     AKNS_TRACE_INFO1("AknSkinSrv: Total ItemDefArea size at EndWrite operation %d bytes", GetAreaAllocatedSize(EAknsSrvItemDefArea));
       
   450     AKNS_TRACE_INFO1("AknSkinSrv: Total DataArea size at EndWrite operation %d bytes", GetAreaAllocatedSize(EAknsSrvDataArea));
       
   451     AKNS_TRACE_INFO1("AknSkinSrv: Total FilenameArea size after EndWrite operation %d bytes", GetAreaAllocatedSize(EAknsSrvFilenameArea));
       
   452     AKNS_TRACE_INFO1("AknSkinSrv: Total ScalableGfxArea(STATIC) size after EndWrite operation %d bytes", GetAreaAllocatedSize(EAknsSrvScalableGfxArea));
       
   453     AKNS_TRACE_INFO1("AknSkinSrv: Total unused space in ItemDefArea %d bytes", (GetAreaAllocatedSize(EAknsSrvItemDefArea)-GetAreaCurrentSize(EAknsSrvItemDefArea)));
       
   454     AKNS_TRACE_INFO1("AknSkinSrv: Total unused space in DataArea %d bytes", (GetAreaAllocatedSize(EAknsSrvDataArea)-GetAreaCurrentSize(EAknsSrvDataArea)));
       
   455     AKNS_TRACE_INFO1("AknSkinSrv: Total unused space in FilenameArea %d bytes", (GetAreaAllocatedSize(EAknsSrvFilenameArea)-GetAreaCurrentSize(EAknsSrvFilenameArea)));
       
   456     AKNS_TRACE_INFO1("AknSkinSrv: Total unused space in ScalableGfxArea %d bytes", (GetAreaAllocatedSize(EAknsSrvScalableGfxArea)-GetAreaCurrentSize(EAknsSrvScalableGfxArea)));
       
   457     AKNS_TRACE_INFO("------------------------------------------------------------------");
       
   458     }
       
   459 
       
   460 // -----------------------------------------------------------------------------
       
   461 // CAknsSrvChunkMaintainer::ResetLevel
       
   462 // -----------------------------------------------------------------------------
       
   463 //
       
   464 void CAknsSrvChunkMaintainer::ResetLevel()
       
   465     {
       
   466     iMergingLevel = 0;
       
   467     }
       
   468 
       
   469 // -----------------------------------------------------------------------------
       
   470 // CAknsSrvChunkMaintainer::NextLevel
       
   471 // -----------------------------------------------------------------------------
       
   472 //
       
   473 void CAknsSrvChunkMaintainer::NextLevel()
       
   474     {
       
   475     iMergingLevel++;
       
   476     }
       
   477 
       
   478 // -----------------------------------------------------------------------------
       
   479 // CAknsSrvChunkMaintainer::CheckAndModifyIID
       
   480 // -----------------------------------------------------------------------------
       
   481 //
       
   482 void CAknsSrvChunkMaintainer::CheckAndModifyIID( TAknsItemID& aIID,
       
   483     const TAknsSrvExclusionQuery& aExclQuery )
       
   484     {
       
   485     if( aIID.iMajor == KAknsSrvRewriteMajor )
       
   486         {
       
   487         aIID.iMajor = KAknsSrvRewriteBase - iMergingLevel;
       
   488         }
       
   489 
       
   490     aExclQuery.MapIID( aIID );
       
   491     }
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CAknsSrvChunkMaintainer::ProcessChunksL
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 TInt CAknsSrvChunkMaintainer::ProcessChunksL( CAknsSrvFileBuffer& aFile,
       
   498     TUint32 aFileOffset, TUint32 aChunkCount, const TDesC& aFilename,
       
   499     const TAknsSrvExclusionQuery& aExclQuery, const TBool aMirrored )
       
   500     {
       
   501     AKNS_TRACE_INFO1("CAknsSrvChunkMaintainer::ProcessChunksL Starting count=%i", aChunkCount );
       
   502 
       
   503     TInt offset = aFileOffset;
       
   504 #if defined(AKNS_TRACING_ENABLED_ERROR)
       
   505     TUint16 prevChunktype = 65535;
       
   506 #endif
       
   507     TUint16 chunktype = 65535;
       
   508     for (TUint32 count = 0; count < aChunkCount; count++)
       
   509         {
       
   510         AKNS_TRACE_INFO2("CAknsSrvChunkMaintainer::ProcessChunksL Step %i/%i", count, aChunkCount );
       
   511 
       
   512 #if defined(AKNS_TRACING_ENABLED_ERROR)
       
   513         prevChunktype = chunktype;
       
   514 #endif
       
   515 
       
   516         if( AknsSrvUtils::GetUInt8L( aFile, offset ) == 0xf5 )
       
   517             {
       
   518             AKNS_TRACE_ERROR1("CAknsSrvChunkMaintainer::ProcessChunksL Suspicious EOC at BOC, prev=%i", prevChunktype);
       
   519             }
       
   520 
       
   521         TInt32 chunksize = AknsSrvUtils::GetInt32L(
       
   522             aFile, offset+EAknsSrvDFOCommonLength );
       
   523         chunktype = AknsSrvUtils::GetUInt16L(
       
   524             aFile, offset+EAknsSrvDFOCommonType );
       
   525 
       
   526         AKNS_TRACE_INFO2("CAknsSrvChunkMaintainer::ProcessChunksL This chunk size=%i type=%i", chunksize, chunktype );
       
   527 
       
   528         if (chunktype == EAknsSkinDescFilename) // filename chunk
       
   529             {
       
   530             offset+=HandleFilenameChunkL(aFile, offset, aFilename);
       
   531             }
       
   532         else if (chunktype == EAknsSkinDescInformation) // information chunk
       
   533             {
       
   534             offset+=HandleInformationChunkL(aFile, offset, aFilename);
       
   535             }
       
   536         else if (chunktype == EAknsSkinDescSkinDescClass) // class chunk
       
   537             {
       
   538             offset+=HandleClassChunkL(aFile, offset, aExclQuery);
       
   539             }
       
   540         else if (chunktype == EAknsSkinDescSkinDescImgLangOverride) // language override chunk
       
   541             {
       
   542             offset+=HandleLangOverrideChunkL(aFile, offset);
       
   543             }
       
   544         else if (chunktype == EAknsSkinDescWallpaper) // wallpaper chunk
       
   545             {
       
   546             offset+=HandleWallpaperChunkL(aFile, offset);
       
   547             }
       
   548         // release restriction chunk (2.6)
       
   549         else if( chunktype == EAknsSkinDescRelease26 )
       
   550             {
       
   551             offset+=Handle26RelRestrictionChunkL(
       
   552                 aFile, offset, aFilename, aExclQuery, aMirrored);
       
   553             }
       
   554         // release restriction chunk (generic)
       
   555         else if( chunktype == EAknsSkinDescReleaseGeneric )
       
   556             {
       
   557             offset+=HandleGenericRelRestrictionChunkL(
       
   558                 aFile, offset, aFilename, aExclQuery, aMirrored);
       
   559             }
       
   560         else if (chunktype == EAknsSkinDescLanguage) // language restriction chunk
       
   561             {
       
   562             offset+=HandleLangRestrictionChunkL(aFile, offset, aFilename, aExclQuery, aMirrored);
       
   563             }
       
   564         else
       
   565             {
       
   566             // chunk not supported/not used, proceed....
       
   567             AKNS_TRACE_ERROR3("CAknsSrvChunkMaintainer::ProcessChunksL Unsupported chunk, type=%i prev=%i count=%i", chunktype, prevChunktype, count);
       
   568             offset+=chunksize;
       
   569             }
       
   570         if( AknsSrvUtils::GetUInt8L(aFile,offset-1) != 0xf5 )
       
   571             {
       
   572             AKNS_TRACE_ERROR2("CAknsSrvChunkMaintainer::ProcessChunksL No EOC, type=%i count=%i!", chunktype, count);
       
   573             }
       
   574         }
       
   575     return offset;
       
   576     }
       
   577 
       
   578 
       
   579 // -----------------------------------------------------------------------------
       
   580 // CAknsSrvChunkMaintainer::HandleInformationChunkL
       
   581 // -----------------------------------------------------------------------------
       
   582 //
       
   583 TInt CAknsSrvChunkMaintainer::HandleInformationChunkL(CAknsSrvFileBuffer& aFile, TUint32 aFileOffset, const TDesC& /*aFilename*/)
       
   584     {
       
   585     TUint32 size = AknsSrvUtils::GetInt32L(aFile, EAknsSrvDFOCommonLength+aFileOffset);
       
   586     TUint32 version = AknsSrvUtils::GetInt32L(aFile, EAknsSrvDFOInformationCompilerVer+aFileOffset);
       
   587     TUint32 authorlen = 2*(AknsSrvUtils::GetInt16L(aFile, EAknsSrvDFOInformationAuthorLen+aFileOffset));
       
   588     TUint32 copyrightlen = 2*(AknsSrvUtils::GetInt16L(aFile, EAknsSrvDFOInformationAuthorStr+authorlen+aFileOffset));
       
   589      TUint16 verMajor = (version >> 16);
       
   590 #if defined(_DEBUG)
       
   591     TUint16 verMinor = (version &0xffff);
       
   592 #endif
       
   593     TUint8 platMajor= AknsSrvUtils::GetUInt8L(aFile, EAknsSrvDFOInformationAuthorStr+2+copyrightlen+authorlen+aFileOffset);
       
   594     TUint8 platMinor= AknsSrvUtils::GetUInt8L(aFile, EAknsSrvDFOInformationAuthorStr+2+1+copyrightlen+authorlen+aFileOffset);
       
   595 #if defined(_DEBUG)
       
   596     RDebug::Print(_L("Skin compiler information:"));
       
   597     RDebug::Print(_L("    SCVer: %d.%d"), verMajor, verMinor);
       
   598     RDebug::Print(_L("    Platf: %d.%d"), platMajor, platMinor);
       
   599     RDebug::Print(_L("    Compl: %d.%d.%d"), platMajor, platMinor,verMinor);
       
   600 #endif
       
   601     if (verMajor < 2 && platMajor < 3)
       
   602         {
       
   603         User::Leave(KErrCorrupt);
       
   604         }
       
   605     return size;
       
   606     }
       
   607 
       
   608 
       
   609 
       
   610 // -----------------------------------------------------------------------------
       
   611 // CAknsSrvChunkMaintainer::HandleFilenameChunkL
       
   612 // -----------------------------------------------------------------------------
       
   613 //
       
   614 TInt CAknsSrvChunkMaintainer::HandleFilenameChunkL(CAknsSrvFileBuffer& aFile, TUint32 aFileOffset, const TDesC& aFilename)
       
   615     {
       
   616     TUint32 size = AknsSrvUtils::GetInt32L(aFile, EAknsSrvDFOCommonLength+aFileOffset);
       
   617     TUint8* filenamechunk = AknsSrvUtils::ReadSkinDescL(aFile, aFileOffset, size);
       
   618     TInt32 filenameid = *((TInt32*)(filenamechunk+EAknsSrvDFOFilenameFilenameID))+iCurrentFilenameID;
       
   619     TUint16 filenamelen = *((TUint16*)(filenamechunk+EAknsSrvDFOFilenameLen));
       
   620     if (iBitmapPath)
       
   621         {
       
   622         UpdateFilename( filenameid, filenamechunk+EAknsSrvDFOFilenameFilename, filenamelen, *iBitmapPath );
       
   623         }
       
   624     else
       
   625         {
       
   626         UpdateFilename( filenameid, filenamechunk+EAknsSrvDFOFilenameFilename, filenamelen, aFilename );
       
   627         }
       
   628 
       
   629     iFilenameCount++;
       
   630     delete [] filenamechunk;
       
   631     return size;
       
   632     }
       
   633 
       
   634 // -----------------------------------------------------------------------------
       
   635 // CAknsSrvChunkMaintainer::HandleClassChunkL
       
   636 // -----------------------------------------------------------------------------
       
   637 //
       
   638 TInt CAknsSrvChunkMaintainer::HandleClassChunkL(
       
   639     CAknsSrvFileBuffer& aFile, TUint32 aFileOffset,
       
   640     const TAknsSrvExclusionQuery& aExclQuery )
       
   641     {
       
   642     TUint32 size = AknsSrvUtils::GetInt32L(
       
   643         aFile, aFileOffset+EAknsSrvDFOCommonLength);
       
   644     DoMergeSkinDefinitionsL(
       
   645         aFile, aFileOffset, EAknsItemDefClassBitmaps, aExclQuery, EFalse);
       
   646     return size;
       
   647     }
       
   648 
       
   649 // -----------------------------------------------------------------------------
       
   650 // CAknsSrvChunkMaintainer::HandleLangOverrideChunkL
       
   651 // -----------------------------------------------------------------------------
       
   652 //
       
   653 TInt CAknsSrvChunkMaintainer::HandleLangOverrideChunkL(CAknsSrvFileBuffer& aFile, TUint32 aFileOffset)
       
   654     {
       
   655     TUint32 size = AknsSrvUtils::GetInt32L(aFile, EAknsSrvDFOCommonLength+aFileOffset);
       
   656     return size;
       
   657     }
       
   658 
       
   659 // -----------------------------------------------------------------------------
       
   660 // CAknsSrvChunkMaintainer::HandleWallpaperChunkL
       
   661 // -----------------------------------------------------------------------------
       
   662 //
       
   663 TInt CAknsSrvChunkMaintainer::HandleWallpaperChunkL(CAknsSrvFileBuffer& aFile, TUint32 aFileOffset)
       
   664     {
       
   665     TUint32 size = AknsSrvUtils::GetInt32L(aFile, EAknsSrvDFOCommonLength+aFileOffset);
       
   666     TUint8 wallpapertype = AknsSrvUtils::GetUInt8L(aFile, EAknsSrvDFOWallpaperWallpaperType+aFileOffset);
       
   667     TUint16 filenamelen = AknsSrvUtils::GetUInt16L(aFile,EAknsSrvDFOWallpaperFilenameLen+aFileOffset);
       
   668     TUint8 fileindex = AknsSrvUtils::GetUInt8L(aFile,aFileOffset+EAknsSrvDFOWallpaperFilename+filenamelen*2);
       
   669     TAknsItemID iid;
       
   670 
       
   671     if (wallpapertype == 0x00)
       
   672         {
       
   673         iid = KAknsIIDWallpaper;
       
   674         }
       
   675     else
       
   676         {
       
   677         // ignore all other values....
       
   678         return size;
       
   679         }
       
   680 
       
   681     HBufC16* filename = HBufC16::NewL(KAknsSrvMaxFileNameLen);
       
   682     CleanupStack::PushL(filename);
       
   683 
       
   684     TUint8* filenameptr = AknsSrvUtils::ReadSkinDescL( aFile, EAknsSrvDFOWallpaperFilename+aFileOffset, filenamelen*2);
       
   685     CleanupStack::PushL(filenameptr);
       
   686 
       
   687     TPtr16 ptr = filename->Des();
       
   688     ptr.SetLength(filenamelen);
       
   689     Mem::Copy((TUint16*)ptr.Ptr(), filenameptr, filenamelen*2);
       
   690 
       
   691 
       
   692     CleanupStack::PopAndDestroy( filenameptr );
       
   693 
       
   694     SetWallpaper(iid, *filename, fileindex);
       
   695     CleanupStack::PopAndDestroy( filename );
       
   696     return size;
       
   697     }
       
   698 
       
   699 // -----------------------------------------------------------------------------
       
   700 // CAknsSrvChunkMaintainer::Handle26RelRestrictionChunkL
       
   701 // -----------------------------------------------------------------------------
       
   702 //
       
   703 TInt CAknsSrvChunkMaintainer::Handle26RelRestrictionChunkL(
       
   704     CAknsSrvFileBuffer& aFile, TUint32 aFileOffset, const TDesC& aFilename,
       
   705     const TAknsSrvExclusionQuery& aExclQuery, const TBool aMirrored )
       
   706     {
       
   707     TUint32 size = AknsSrvUtils::GetInt32L( aFile,
       
   708         aFileOffset+EAknsSrvDFORelease26Length);
       
   709     TInt32 numberofchunks = AknsSrvUtils::GetInt32L( aFile,
       
   710         aFileOffset+EAknsSrvDFORelease26ChunksN );
       
   711 
       
   712     // Process always (we are guaranteed to be at lease 2.8>2.6)
       
   713     ProcessChunksL( aFile, aFileOffset+EAknsSrvDFORelease26Content,
       
   714         numberofchunks, aFilename, aExclQuery, aMirrored);
       
   715 
       
   716     return size;
       
   717     }
       
   718 
       
   719 // -----------------------------------------------------------------------------
       
   720 // CAknsSrvChunkMaintainer::HandleGenericRelRestrictionChunkL
       
   721 // -----------------------------------------------------------------------------
       
   722 //
       
   723 TInt CAknsSrvChunkMaintainer::HandleGenericRelRestrictionChunkL(
       
   724     CAknsSrvFileBuffer& aFile, TUint32 aFileOffset, const TDesC& aFilename,
       
   725     const TAknsSrvExclusionQuery& aExclQuery, const TBool aMirrored )
       
   726     {
       
   727     TUint32 size = AknsSrvUtils::GetInt32L( aFile,
       
   728         aFileOffset+EAknsSrvDFOReleaseGenericLength);
       
   729     TInt32 numberofchunks = AknsSrvUtils::GetInt32L( aFile,
       
   730         aFileOffset+EAknsSrvDFOReleaseGenericChunksN );
       
   731     TInt platformMajor = AknsSrvUtils::GetUInt8L( aFile,
       
   732         aFileOffset+EAknsSrvDFOReleaseGenericPlatformMajor );
       
   733     TInt platformMinor = AknsSrvUtils::GetUInt8L( aFile,
       
   734         aFileOffset+EAknsSrvDFOReleaseGenericPlatformMinor );
       
   735 
       
   736     // Process the chunk only if restriction is met
       
   737     if( (platformMajor<iPlatformMajor) ||
       
   738         ((platformMajor==iPlatformMajor)&&
       
   739         (platformMinor<=iPlatformMinor)) )
       
   740         {
       
   741         ProcessChunksL( aFile, aFileOffset+EAknsSrvDFOReleaseGenericContent,
       
   742             numberofchunks, aFilename, aExclQuery, aMirrored);
       
   743         }
       
   744 
       
   745     return size;
       
   746     }
       
   747 
       
   748 // -----------------------------------------------------------------------------
       
   749 // CAknsSrvChunkMaintainer::HandleLangRestrictionChunkL
       
   750 // -----------------------------------------------------------------------------
       
   751 //
       
   752 TInt CAknsSrvChunkMaintainer::HandleLangRestrictionChunkL(
       
   753     CAknsSrvFileBuffer& aFile, TUint32 aFileOffset, const TDesC& aFilename,
       
   754     const TAknsSrvExclusionQuery& aExclQuery, const TBool aMirrored )
       
   755     {
       
   756     TUint32 size = AknsSrvUtils::GetInt32L( aFile,
       
   757         EAknsSrvDFOCommonLength+aFileOffset);
       
   758     TUint16 generalRestr = AknsSrvUtils::GetInt16L( aFile,
       
   759         EAknsSrvDFOLanguageGenRestr+aFileOffset);
       
   760     TUint16 langRestr =  AknsSrvUtils::GetInt16L( aFile,
       
   761         EAknsSrvDFOLanguageLangRestr+aFileOffset);
       
   762     TInt32 numberofchunks = AknsSrvUtils::GetInt32L( aFile,
       
   763         EAknsSrvDFOLanguageLanguageN+aFileOffset);
       
   764     if( (generalRestr == 0) ||
       
   765         (generalRestr == 1 && !aMirrored) ||
       
   766         (generalRestr == 2 && aMirrored) )
       
   767         {
       
   768         if ((langRestr == 0) ||
       
   769            (langRestr && langRestr == User::Language()))
       
   770             {
       
   771             // Set the restriction parameters before processing
       
   772             // the chunks inside it
       
   773             TAknsSrvExclusionQuery* query = const_cast<TAknsSrvExclusionQuery*>(&aExclQuery);
       
   774             query->SetParameters(
       
   775                 (User::Language()==ELangArabic)?ETrue:EFalse,
       
   776                 (User::Language()==ELangHebrew)?ETrue:EFalse );
       
   777             ProcessChunksL( aFile, aFileOffset+EAknsSrvDFOLanguageContent,
       
   778                 numberofchunks, aFilename, aExclQuery, aMirrored );
       
   779             // Disable exclusions after processing language restriction chunks
       
   780             query->SetParameters(EFalse,EFalse);
       
   781             }
       
   782         }
       
   783     return size;
       
   784     }
       
   785 
       
   786 // -----------------------------------------------------------------------------
       
   787 // CAknsSrvChunkMaintainer::EnqueuePostOperationL
       
   788 // -----------------------------------------------------------------------------
       
   789 //
       
   790 void CAknsSrvChunkMaintainer::EnqueuePostOperationL(
       
   791     const TAknsSrvCMPostOpType aType, const TAknsItemID aIID )
       
   792     {
       
   793     AKNS_TRACE_INFO2("CAknsSrvChunkMaintainer::EnqPO Adding PO for %x %x", aIID.iMajor, aIID.iMinor );
       
   794 
       
   795     TAknsSrvCMPostOp op;
       
   796     op.iType = aType;
       
   797     op.iIID = aIID;
       
   798     User::LeaveIfError( iPostOpArray.InsertInOrderAllowRepeats(
       
   799         op, TAknsSrvCMPostOp::LinearOrder ) );
       
   800     }
       
   801 
       
   802 // -----------------------------------------------------------------------------
       
   803 // CAknsSrvChunkMaintainer::ExecutePostOperations
       
   804 //
       
   805 // -----------------------------------------------------------------------------
       
   806 //
       
   807 void CAknsSrvChunkMaintainer::ExecutePostOperations()
       
   808     {
       
   809     TAknsSrvDef* itemtable = (TAknsSrvDef*)GetAreaBasePtr(EAknsSrvItemDefArea);
       
   810     TInt defcount = GetAreaCurrentSize(EAknsSrvItemDefArea) / sizeof(TAknsSrvDef);
       
   811 
       
   812     for( TInt index = 0; index<defcount; index++ )
       
   813         {
       
   814         TAknsSrvCMPostOp key;
       
   815         key.iIID = itemtable[index].iID;
       
   816         TInt opIndex = KErrNotFound;
       
   817         while( (opIndex=iPostOpArray.FindInOrder(
       
   818             key, TAknsSrvCMPostOp::LinearOrder ))!=KErrNotFound )
       
   819             {
       
   820             TAknsSrvCMPostOp op;
       
   821             op = iPostOpArray[ opIndex ];
       
   822             iPostOpArray.Remove( opIndex );
       
   823 
       
   824             AKNS_TRACE_INFO2("CAknsSrvChunkMaintainer::ExePO Executing PO for %x %x", op.iIID.iMajor, op.iIID.iMinor );
       
   825             if( itemtable[index].iDef.iPtrType == EAknsSrvMPPtrAbsoluteROM )
       
   826                 {
       
   827                 // Not modifiable
       
   828                 AKNS_TRACE_INFO("CAknsSrvChunkMaintainer::ExePO SKIPPED, ROM def");
       
   829                 continue;
       
   830                 }
       
   831 
       
   832             switch( op.iType )
       
   833                 {
       
   834                 case EAknsSrvCMPOTTileX:
       
   835                 case EAknsSrvCMPOTTileY:
       
   836                 case EAknsSrvCMPOTTileToStretch:
       
   837                     PostOpTile( op, &itemtable[index] );
       
   838                     break;
       
   839                 default:
       
   840                     AKNS_TRACE_INFO("CAknsSrvChunkMaintainer::ExePO SKIPPED, unsupported type");
       
   841                     break;
       
   842                 }
       
   843             }
       
   844         }
       
   845     }
       
   846 
       
   847 // -----------------------------------------------------------------------------
       
   848 // CAknsSrvChunkMaintainer::PostOpTile
       
   849 // -----------------------------------------------------------------------------
       
   850 //
       
   851 void CAknsSrvChunkMaintainer::PostOpTile( TAknsSrvCMPostOp& op,
       
   852     TAknsSrvDef* itemDef )
       
   853     {
       
   854     // Read attributes
       
   855     TInt imageAttributes = 0;
       
   856     if( itemDef->iType == EAknsITBitmap )
       
   857         {
       
   858         TAknsSrvBitmapDef* bmpDef =
       
   859             static_cast<TAknsSrvBitmapDef*>(const_cast<TAny*>(
       
   860             itemDef->iDef.Address(GetAreaBasePtr(EAknsSrvDataArea))));
       
   861         imageAttributes = bmpDef->iImageAttributes;
       
   862         }
       
   863     else if( itemDef->iType == EAknsITMaskedBitmap )
       
   864         {
       
   865         TAknsSrvMaskedBitmapDef* bmpDef =
       
   866             static_cast<TAknsSrvMaskedBitmapDef*>(const_cast<TAny*>(
       
   867             itemDef->iDef.Address(GetAreaBasePtr(EAknsSrvDataArea))));
       
   868         imageAttributes = bmpDef->iImageAttributes;
       
   869         }
       
   870     else
       
   871         {
       
   872         // Never reached, but play for sure
       
   873         AKNS_TRACE_INFO("CAknsSrvChunkMaintainer::POT Unsupported def type.");
       
   874         return;
       
   875         }
       
   876 
       
   877     // Modify
       
   878     if( !(imageAttributes&EAknsImageAttributeNBC) &&
       
   879         (imageAttributes&EAknsImageAttributeTile) )
       
   880         {
       
   881         if( op.iType==EAknsSrvCMPOTTileX )
       
   882             {
       
   883             imageAttributes ^= EAknsImageAttributeTile;
       
   884             imageAttributes |= EAknsImageAttributeTileX;
       
   885             imageAttributes |= EAknsImageAttributeNBC;
       
   886             }
       
   887         else if( op.iType==EAknsSrvCMPOTTileY )
       
   888             {
       
   889             imageAttributes ^= EAknsImageAttributeTile;
       
   890             imageAttributes |= EAknsImageAttributeTileY;
       
   891             imageAttributes |= EAknsImageAttributeNBC;
       
   892             }
       
   893         else if( op.iType==EAknsSrvCMPOTTileToStretch )
       
   894             {
       
   895             imageAttributes ^= EAknsImageAttributeTile;
       
   896             imageAttributes |= EAknsImageAttributeStretch;
       
   897             imageAttributes |= EAknsImageAttributeNBC;
       
   898             }
       
   899         }
       
   900 
       
   901     // Write attributes
       
   902     if( itemDef->iType == EAknsITBitmap )
       
   903         {
       
   904         TAknsSrvBitmapDef* bmpDef =
       
   905             static_cast<TAknsSrvBitmapDef*>(const_cast<TAny*>(
       
   906             itemDef->iDef.Address(GetAreaBasePtr(EAknsSrvDataArea))));
       
   907         bmpDef->iImageAttributes = imageAttributes;
       
   908         }
       
   909     else if( itemDef->iType == EAknsITMaskedBitmap )
       
   910         {
       
   911         TAknsSrvMaskedBitmapDef* bmpDef =
       
   912             static_cast<TAknsSrvMaskedBitmapDef*>(const_cast<TAny*>(
       
   913             itemDef->iDef.Address(GetAreaBasePtr(EAknsSrvDataArea))));
       
   914         bmpDef->iImageAttributes = imageAttributes;
       
   915         }
       
   916     }
       
   917 
       
   918 // -----------------------------------------------------------------------------
       
   919 // CAknsSrvChunkMaintainer::MergeSkinDefinitionsUnprotectedL
       
   920 // -----------------------------------------------------------------------------
       
   921 //
       
   922 void CAknsSrvChunkMaintainer::MergeSkinDefinitionsUnprotectedL(
       
   923     const TDesC& aFilename, const TBool aClearChunk,
       
   924     const TAknsSrvExclusionQuery& aExclQuery, TBool aAhOverride,
       
   925     const TAknsPkgID& aPID )
       
   926     {
       
   927     iFilenameCount = 0;
       
   928 
       
   929     if (aClearChunk)
       
   930         {
       
   931         InitializeChunk();
       
   932         }
       
   933 
       
   934     RFs fs;
       
   935     User::LeaveIfError(fs.Connect());
       
   936     CleanupClosePushL(fs);
       
   937 
       
   938     // Check if image files exist in resource\skins\<skinuid>
       
   939 
       
   940     delete iBitmapPath;
       
   941     TInt pathsize = KAknsSrvScalableRomBmpLocation().Length()+8+2; //2 for the driveletter and end separator
       
   942     if (!aPID.IsUid())
       
   943         {
       
   944         pathsize+=8;
       
   945         }
       
   946     iBitmapPath = HBufC16::NewL(pathsize);
       
   947     iBitmapPath->Des().Append(aFilename[0]);
       
   948     iBitmapPath->Des().Append(KAknsSrvScalableRomBmpLocation);
       
   949     iBitmapPath->Des().AppendNumFixedWidthUC( aPID.iNumber, EHex, 8 );
       
   950 
       
   951     if( !aPID.IsUid() )
       
   952         {
       
   953         iBitmapPath->Des().AppendNumFixedWidthUC( aPID.iTimestamp, EHex, 8 );
       
   954         }
       
   955 
       
   956     iBitmapPath->Des().Append(KAknsSrvPathEndSeparator);
       
   957     TBool exists = BaflUtils::FolderExists(fs, *iBitmapPath);
       
   958     if (!exists)
       
   959         {
       
   960         delete iBitmapPath;
       
   961         iBitmapPath = NULL;
       
   962         }
       
   963 
       
   964     TChar driveLetter = aFilename[0];
       
   965     TInt driveNumber;
       
   966     User::LeaveIfError(fs.CharToDrive(driveLetter, driveNumber));
       
   967     User::LeaveIfError(fs.ShareProtected());
       
   968 
       
   969     TInt err = fs.CreatePrivatePath(driveNumber);
       
   970     if (err!=KErrNone && err!=KErrAlreadyExists)
       
   971         User::Leave(err);
       
   972 
       
   973     User::LeaveIfError(fs.SetSessionToPrivate(driveNumber));
       
   974     RFile file;
       
   975     User::LeaveIfError(file.Open(fs,aFilename, EFileRead | EFileShareReadersOnly));
       
   976     CleanupClosePushL(file);
       
   977     CAknsSrvFileBuffer* fileBuf = CAknsSrvFileBuffer::NewL( file );
       
   978     CleanupStack::PushL( fileBuf );
       
   979 
       
   980     TUint masterChunkSize = AknsSrvUtils::GetInt32L(
       
   981         *fileBuf, EAknsSrvDFOCommonLength );
       
   982     TUint masterChunkType = AknsSrvUtils::GetUInt16L(
       
   983         *fileBuf, EAknsSrvDFOCommonType );
       
   984     TInt32 numberofchunks = AknsSrvUtils::GetInt32L(
       
   985         *fileBuf, EAknsSrvDFOSkinChunksN );
       
   986 
       
   987     if( masterChunkType != EAknsSkinDescSkinDesc )
       
   988         {
       
   989         AKNS_TRACE_ERROR("CAknsSrvChunkMaintainer::MSDUL CORRUPTED FILE (bad master type)!");
       
   990         User::Leave( KErrCorrupt );
       
   991         }
       
   992 
       
   993     ProcessChunksL(*fileBuf, EAknsSrvDFOSkinContent , numberofchunks, aFilename, aExclQuery, aAhOverride );
       
   994 
       
   995     if( AknsSrvUtils::GetUInt8L(*fileBuf,masterChunkSize-1) != 0xf5 )
       
   996         {
       
   997         AKNS_TRACE_ERROR("CAknsSrvChunkMaintainer::MSDUL CORRUPTED FILE (no master eoc)!");
       
   998         User::Leave( KErrCorrupt );
       
   999         }
       
  1000     CleanupStack::PopAndDestroy(2);
       
  1001     iCurrentFilenameID += iFilenameCount;
       
  1002     CleanupStack::PopAndDestroy(); //fileBuf
       
  1003 
       
  1004     // Add generic post operations
       
  1005     EnqueuePostOperationL( EAknsSrvCMPOTTileToStretch,
       
  1006         KAknsIIDQsnFrPopupCenterMenu );
       
  1007     EnqueuePostOperationL( EAknsSrvCMPOTTileToStretch,
       
  1008         KAknsIIDQsnFrPopupCenterSubmenu );
       
  1009     EnqueuePostOperationL( EAknsSrvCMPOTTileToStretch,
       
  1010         KAknsIIDQsnFrPopupCenterNote );
       
  1011     EnqueuePostOperationL( EAknsSrvCMPOTTileToStretch,
       
  1012         KAknsIIDQsnFrPopupCenterQuery );
       
  1013     EnqueuePostOperationL( EAknsSrvCMPOTTileToStretch,
       
  1014         KAknsIIDQsnFrPopupCenterFind );
       
  1015     EnqueuePostOperationL( EAknsSrvCMPOTTileToStretch,
       
  1016         KAknsIIDQsnFrPopupCenterSnote );
       
  1017     EnqueuePostOperationL( EAknsSrvCMPOTTileToStretch,
       
  1018         KAknsIIDQsnFrPopupCenterFswap );
       
  1019 
       
  1020     // Execute any pending post operations
       
  1021     ExecutePostOperations();
       
  1022     }
       
  1023 
       
  1024 // -----------------------------------------------------------------------------
       
  1025 // CAknsSrvChunkMaintainer::DoMergeSkinDefinitionsL
       
  1026 // -----------------------------------------------------------------------------
       
  1027 //
       
  1028 void CAknsSrvChunkMaintainer::DoMergeSkinDefinitionsL(
       
  1029     CAknsSrvFileBuffer& file, const TUint aOffset,
       
  1030     const TAknsItemDefClass aClass, const TAknsSrvExclusionQuery& aExclQuery,
       
  1031     const TBool aAhOverride )
       
  1032     {
       
  1033     TInt fileoffset = aOffset;
       
  1034     TInt32 chunklen = AknsSrvUtils::GetInt32L( file,
       
  1035         fileoffset+EAknsSrvDFOCommonLength );
       
  1036     TInt16 chunktype = AknsSrvUtils::GetUInt16L( file,
       
  1037         fileoffset+EAknsSrvDFOCommonType );
       
  1038     TInt32 chunkcount = AknsSrvUtils::GetInt32L( file,
       
  1039         fileoffset+EAknsSrvDFOClassChunksN );
       
  1040     fileoffset += EAknsSrvDFOClassContent;
       
  1041 
       
  1042     for (TInt count = 0;count < chunkcount;count++)
       
  1043         {
       
  1044         if( AknsSrvUtils::GetUInt8L( file, fileoffset ) == 0xf5 )
       
  1045             {
       
  1046             AKNS_TRACE_ERROR1("CAknsSrvChunkMaintainer::DMSDL Suspicious EOC at BOC, prev=%i", chunktype);
       
  1047             }
       
  1048 
       
  1049         chunklen = AknsSrvUtils::GetInt32L( file,
       
  1050             fileoffset+EAknsSrvDFOCommonLength );
       
  1051         chunktype = AknsSrvUtils::GetUInt16L( file,
       
  1052             fileoffset+EAknsSrvDFOCommonType );
       
  1053 
       
  1054         switch(chunktype)
       
  1055             {
       
  1056 
       
  1057             case EAknsSkinDescSkinDescBmpItemDef:
       
  1058                 DoMergeBitmapDefinitionL( file, fileoffset, aClass, aExclQuery, aAhOverride );
       
  1059                 break;
       
  1060 
       
  1061             case EAknsSkinDescSkinDescColorTblItemDef:
       
  1062                 DoMergeColorTableDefinitionL( file, fileoffset, aClass, aExclQuery, aAhOverride );
       
  1063                 break;
       
  1064 
       
  1065             case EAknsSkinDescSkinDescImgTblItemDef:
       
  1066                 DoMergeImageTableDefinitionL( file, fileoffset, aClass, aExclQuery, aAhOverride );
       
  1067                 break;
       
  1068 
       
  1069             case EAknsSkinDescSkinDescImgBmpAnim:
       
  1070                 DoMergeBmpAnimDefinitionL( file, fileoffset, aClass, aExclQuery, aAhOverride );
       
  1071                 break;
       
  1072 
       
  1073             case EAknsSkinDescSkinDescStringItemDef:
       
  1074                 DoMergeStringDefinitionL( file, fileoffset, aClass, aExclQuery, aAhOverride );
       
  1075                 break;
       
  1076 
       
  1077             case EAknsSkinDescEffectQueue:
       
  1078                 DoMergeEffectQueueL(file, fileoffset, aClass, aExclQuery, aAhOverride);
       
  1079                 break;
       
  1080 
       
  1081             case EAknsSkinDescAnimation:
       
  1082                 DoMergeAnimationL( file, fileoffset, aClass, aExclQuery, aAhOverride );
       
  1083                 break;
       
  1084 
       
  1085             default:
       
  1086                 AKNS_TRACE_ERROR1("CAknsSrvChunkMaintainer::DMSL SKIPPED CHUNK %i", chunktype );
       
  1087                 break;
       
  1088 
       
  1089             }
       
  1090 
       
  1091         fileoffset+=chunklen;
       
  1092         if( AknsSrvUtils::GetUInt8L( file, fileoffset-1 ) != 0xf5 )
       
  1093             {
       
  1094             AKNS_TRACE_ERROR("CAknsSrvChunkMaintainer::DMSDL CORRUPTED FILE!");
       
  1095             User::Leave( KErrCorrupt );
       
  1096             }
       
  1097         }
       
  1098     }
       
  1099 
       
  1100 // -----------------------------------------------------------------------------
       
  1101 // CAknsSrvChunkMaintainer::StoreScalableGraphicsL
       
  1102 // -----------------------------------------------------------------------------
       
  1103 //
       
  1104 void CAknsSrvChunkMaintainer::StoreScalableGraphicsL( const TAknsItemID& aIID,
       
  1105     const TInt aType, const TSize& aLayoutSize, TInt aBmpHandle, TInt aMskHandle, TBool aIsMorphing )
       
  1106     {
       
  1107     CFbsBitmap* bitmap = NULL;
       
  1108     CFbsBitmap* mask = NULL;
       
  1109 
       
  1110     bitmap = new (ELeave) CFbsBitmap;
       
  1111     CleanupStack::PushL(bitmap);
       
  1112     User::LeaveIfError( bitmap->Duplicate(aBmpHandle) );
       
  1113     if (aMskHandle)
       
  1114         {
       
  1115         mask = new (ELeave) CFbsBitmap;
       
  1116         CleanupStack::PushL(mask);
       
  1117         User::LeaveIfError( mask->Duplicate(aMskHandle) );
       
  1118         CleanupStack::Pop( mask );
       
  1119         }
       
  1120     CleanupStack::Pop(bitmap);
       
  1121     iBitmapStore->StoreBitmap( bitmap );
       
  1122     if (mask)
       
  1123         {
       
  1124         iBitmapStore->StoreBitmap( mask );
       
  1125         }
       
  1126 
       
  1127     TAknsSrvScalableItemDef def;
       
  1128     def.iID = aIID;
       
  1129     def.iLayoutType = aType;
       
  1130     def.iLayoutSize = aLayoutSize;
       
  1131     def.iBitmapHandle = bitmap->Handle();
       
  1132     if (aMskHandle)
       
  1133         {
       
  1134         def.iMaskHandle = mask->Handle();
       
  1135         }
       
  1136     else
       
  1137         {
       
  1138         def.iMaskHandle = 0;
       
  1139         }
       
  1140     TTime currenttime;
       
  1141     currenttime.HomeTime();
       
  1142     def.isMorphing = aIsMorphing;
       
  1143     def.iTimeStamp = currenttime;
       
  1144 
       
  1145     BeginWrite();
       
  1146 
       
  1147     TAknsSrvScalableItemDef* table = (TAknsSrvScalableItemDef*)GetAreaBasePtr(EAknsSrvScalableGfxArea);
       
  1148     TInt defcount = GetAreaCurrentSize(EAknsSrvScalableGfxArea) / sizeof(TAknsSrvScalableItemDef);
       
  1149     TInt bodycount = 0;
       
  1150     for (bodycount = 0; bodycount < defcount; bodycount++)
       
  1151         {
       
  1152         if (table[bodycount].iID == aIID &&
       
  1153             table[bodycount].iLayoutType == aType &&
       
  1154             table[bodycount].iLayoutSize == aLayoutSize)
       
  1155             {
       
  1156             iBitmapStore->RemoveStoredBitmap(table[bodycount].iBitmapHandle);
       
  1157             iBitmapStore->RemoveStoredBitmap(table[bodycount].iMaskHandle);
       
  1158             // Replace existing item, no count increase
       
  1159             Mem::Copy((TUint8*)(&table[bodycount]), &def, sizeof(TAknsSrvScalableItemDef));
       
  1160             EndWrite();
       
  1161             return;
       
  1162             }
       
  1163         }
       
  1164     if( defcount >= KAknsSrvMaxScalableGfxItems )
       
  1165         {
       
  1166         TTime oldeststamp = table[0].iTimeStamp;
       
  1167         TUint32 oldestindex = 0;
       
  1168         for (bodycount = 0; bodycount < defcount; bodycount++)
       
  1169             {
       
  1170             if (table[bodycount].iTimeStamp < oldeststamp)
       
  1171                 {
       
  1172                 oldestindex = bodycount;
       
  1173                 oldeststamp = table[bodycount].iTimeStamp;
       
  1174                 }
       
  1175             }
       
  1176         iBitmapStore->RemoveStoredBitmap(table[oldestindex].iBitmapHandle);
       
  1177         iBitmapStore->RemoveStoredBitmap(table[oldestindex].iMaskHandle);
       
  1178         // Replace existing item, no count increase
       
  1179         Mem::Copy((TUint8*)(&table[oldestindex]), &def, sizeof(TAknsSrvScalableItemDef));
       
  1180         }
       
  1181     else
       
  1182         {
       
  1183         TInt8* target = GetAreaBasePtr(EAknsSrvScalableGfxArea) + GetAreaCurrentSize(EAknsSrvScalableGfxArea);
       
  1184         SetAreaCurrentSize(EAknsSrvScalableGfxArea,GetAreaCurrentSize(EAknsSrvScalableGfxArea)+sizeof(TAknsSrvScalableItemDef));
       
  1185         Mem::Copy(target, &def, sizeof(TAknsSrvScalableItemDef));
       
  1186         }
       
  1187 
       
  1188     EndWrite();
       
  1189     }
       
  1190 
       
  1191 // -----------------------------------------------------------------------------
       
  1192 // CAknsSrvChunkMaintainer::ClearScalableGraphics
       
  1193 // -----------------------------------------------------------------------------
       
  1194 //
       
  1195 void CAknsSrvChunkMaintainer::ClearScalableGraphics(TAknsSrcScreenMode aMode)
       
  1196     {
       
  1197     BeginWrite();
       
  1198     if (aMode == EAknsSrvScrModeLandscape || aMode == EAknsSrvScrModePortrait)
       
  1199         {
       
  1200         TAknsSrvScalableItemDef* table = (TAknsSrvScalableItemDef*)GetAreaBasePtr(EAknsSrvScalableGfxArea);
       
  1201         TInt defcount = GetAreaCurrentSize(EAknsSrvScalableGfxArea) / sizeof(TAknsSrvScalableItemDef);
       
  1202         TInt bodycount = 0;
       
  1203         for (bodycount = 0; bodycount < defcount; bodycount++)
       
  1204             {
       
  1205             TTime currentTime;
       
  1206             currentTime.HomeTime();
       
  1207             TTimeIntervalMinutes minutes;
       
  1208             currentTime.MinutesFrom(table[bodycount].iTimeStamp, minutes);
       
  1209             TBool layoutNotInUse = EFalse;
       
  1210             if (aMode == EAknsSrvScrModeLandscape)
       
  1211                 {
       
  1212                 if (table[bodycount].iLayoutSize.iWidth < table[bodycount].iLayoutSize.iHeight)
       
  1213                     {
       
  1214                     // dump portrait bitmaps...
       
  1215                     layoutNotInUse = ETrue;
       
  1216                     }
       
  1217                 }
       
  1218             else if (aMode == EAknsSrvScrModePortrait)
       
  1219                 {
       
  1220                 if (table[bodycount].iLayoutSize.iWidth > table[bodycount].iLayoutSize.iHeight)
       
  1221                     {
       
  1222                     // dump landscape bitmaps...
       
  1223                     layoutNotInUse = ETrue;
       
  1224                     }
       
  1225                 }
       
  1226             // dump bitmap if the layout is different than current, or the item has been in the cache more than 5
       
  1227             // minutes
       
  1228             if (layoutNotInUse ||
       
  1229                 minutes.Int() >= 5)
       
  1230                 {
       
  1231 #if defined(_DEBUG)
       
  1232                 RDebug::Print(_L("CAknsSrvChunkMaintainer: Dumped bitmap, timediff: %d, mode:%d, layouttype %d"), minutes.Int(), aMode,table[bodycount].iLayoutType );
       
  1233 #endif
       
  1234                 iBitmapStore->RemoveStoredBitmap(table[bodycount].iBitmapHandle);
       
  1235                 iBitmapStore->RemoveStoredBitmap(table[bodycount].iMaskHandle);
       
  1236                 // clear item from the chunk &
       
  1237                 // move the rest of the chunk upwards
       
  1238                 TInt8* target = (TInt8*)(&(table[bodycount]));
       
  1239                 TInt8* source = (TInt8*)(&(table[bodycount+1]));
       
  1240                 TUint32 size = sizeof(TAknsSrvScalableItemDef)*(defcount-(bodycount+1));
       
  1241                 if (size > 0)
       
  1242                 {
       
  1243                     Mem::Copy(target, source, size);
       
  1244                 }
       
  1245                 SetAreaCurrentSize(EAknsSrvScalableGfxArea,GetAreaCurrentSize(EAknsSrvScalableGfxArea)-sizeof(TAknsSrvScalableItemDef));
       
  1246                 defcount--;
       
  1247                 bodycount--;
       
  1248                 continue;
       
  1249                 }
       
  1250             }
       
  1251         }
       
  1252     else
       
  1253         {
       
  1254         SetAreaCurrentSize( EAknsSrvScalableGfxArea, 0 );
       
  1255         iBitmapStore->DestroyBitmaps();
       
  1256         }
       
  1257     EndWrite();
       
  1258     }
       
  1259 
       
  1260 // -----------------------------------------------------------------------------
       
  1261 // CAknsSrvChunkMaintainer::ClearMorphedGraphics
       
  1262 // -----------------------------------------------------------------------------
       
  1263 //
       
  1264 void CAknsSrvChunkMaintainer::ClearMorphedGraphics()
       
  1265     {
       
  1266     BeginWrite();
       
  1267     TAknsSrvScalableItemDef* table = (TAknsSrvScalableItemDef*)GetAreaBasePtr(EAknsSrvScalableGfxArea);
       
  1268     TInt defcount = GetAreaCurrentSize(EAknsSrvScalableGfxArea) / sizeof(TAknsSrvScalableItemDef);
       
  1269     TInt bodycount = 0;
       
  1270     for (bodycount = 0; bodycount < defcount; bodycount++)
       
  1271         {
       
  1272         if (table[bodycount].isMorphing)
       
  1273             {
       
  1274             iBitmapStore->RemoveStoredBitmap(table[bodycount].iBitmapHandle);
       
  1275             iBitmapStore->RemoveStoredBitmap(table[bodycount].iMaskHandle);
       
  1276             // clear item from the chunk &
       
  1277             // move the rest of the chunk upwards
       
  1278             TInt8* target = (TInt8*)(&(table[bodycount]));
       
  1279             TInt8* source = (TInt8*)(&(table[bodycount+1]));
       
  1280             TUint32 size = sizeof(TAknsSrvScalableItemDef)*(defcount-(bodycount+1));
       
  1281             if (size > 0)
       
  1282             {
       
  1283                 Mem::Copy(target, source, size);
       
  1284             }
       
  1285             SetAreaCurrentSize(
       
  1286                 EAknsSrvScalableGfxArea,
       
  1287                 GetAreaCurrentSize(EAknsSrvScalableGfxArea)-sizeof(TAknsSrvScalableItemDef));
       
  1288             defcount--;
       
  1289             bodycount--;
       
  1290             continue;
       
  1291             }
       
  1292         }
       
  1293     EndWrite();
       
  1294     }
       
  1295 
       
  1296 void CAknsSrvChunkMaintainer::RemoveSingleScalableItem(const TAknsItemID& aIID )
       
  1297     {
       
  1298     BeginWrite();
       
  1299     TAknsSrvScalableItemDef* table = (TAknsSrvScalableItemDef*)GetAreaBasePtr(EAknsSrvScalableGfxArea);
       
  1300     TInt defcount = GetAreaCurrentSize(EAknsSrvScalableGfxArea) / sizeof(TAknsSrvScalableItemDef);
       
  1301     TInt bodycount = 0;
       
  1302     for (bodycount = 0; bodycount < defcount; bodycount++)
       
  1303         {
       
  1304         if (table[bodycount].iID == aIID )
       
  1305             {
       
  1306             iBitmapStore->RemoveStoredBitmap(table[bodycount].iBitmapHandle);
       
  1307             iBitmapStore->RemoveStoredBitmap(table[bodycount].iMaskHandle);
       
  1308             // clear item from the chunk &
       
  1309             // move the rest of the chunk upwards
       
  1310             TInt8* target = (TInt8*)(&(table[bodycount]));
       
  1311             TInt8* source = (TInt8*)(&(table[bodycount+1]));
       
  1312             TUint32 size = sizeof(TAknsSrvScalableItemDef)*(defcount-(bodycount+1));
       
  1313             if (size > 0)
       
  1314             {
       
  1315                 Mem::Copy(target, source, size);
       
  1316             }
       
  1317             SetAreaCurrentSize(
       
  1318                 EAknsSrvScalableGfxArea,
       
  1319                 GetAreaCurrentSize(EAknsSrvScalableGfxArea)-sizeof(TAknsSrvScalableItemDef));
       
  1320             defcount--;
       
  1321             bodycount--;
       
  1322             continue;
       
  1323             }
       
  1324         }
       
  1325     EndWrite();
       
  1326     }
       
  1327 
       
  1328 
       
  1329 // -----------------------------------------------------------------------------
       
  1330 // CAknsSrvChunkMaintainer::CreateMorphingTimerL
       
  1331 // -----------------------------------------------------------------------------
       
  1332 //
       
  1333 void CAknsSrvChunkMaintainer::CreateMorphingTimerL(MAknsSrvMorphingListener* aListener)
       
  1334     {
       
  1335     if (iMorphingMinInterval > 0)
       
  1336         {
       
  1337         if (iMorphingMinInterval < KAknsSrvMinMorphingInterval)
       
  1338             {
       
  1339             iMorphingMinInterval = KAknsSrvMinMorphingInterval;
       
  1340             }
       
  1341         iMorphingTimer = CAknsSrvMorphingTimer::NewL(aListener, iMorphingMinInterval);
       
  1342         AKNS_TRACE_INFO("CAknsSrvChunkMaintainer::Created timer for morphing items");
       
  1343         iMorphingTimer->IssueRequest();
       
  1344         AKNS_TRACE_INFO("CAknsSrvChunkMaintainer::Activated morphing timer timer");
       
  1345         }
       
  1346     }
       
  1347 
       
  1348 // -----------------------------------------------------------------------------
       
  1349 // CAknsSrvChunkMaintainer::UpdateMorphingTime
       
  1350 // -----------------------------------------------------------------------------
       
  1351 //
       
  1352 void CAknsSrvChunkMaintainer::UpdateMorphingTime()
       
  1353     {
       
  1354     TTime now;
       
  1355     now.HomeTime();
       
  1356 
       
  1357     TAknsSrvDef itemDef;
       
  1358 
       
  1359     // Perform any ID mappings
       
  1360     itemDef.iID.Set( EAknsMajorProperty, EAknsMinorPropertyMorphingTime );
       
  1361 
       
  1362     // Initialize item def type
       
  1363     itemDef.iType = EAknsITString;
       
  1364     TAknsSrvStringDef stringDef;
       
  1365 
       
  1366     // TText16 and TPtrC16 must be used here, since the data is copied
       
  1367     // verbatim from the skin file
       
  1368     TUint32 timestamp[2];
       
  1369     timestamp[0] = I64HIGH(now.Int64());
       
  1370     timestamp[1] = I64LOW(now.Int64());
       
  1371     TText16* oldData = 0;
       
  1372     TInt oldDataSize = 0;
       
  1373 
       
  1374     TAknsSrvDef* itemtable = (TAknsSrvDef*)(GetAreaBasePtr(EAknsSrvItemDefArea));
       
  1375     TInt oldIndex = FindDefIndex( itemDef.iID );
       
  1376     if( (oldIndex>0) && (itemtable[oldIndex].iDef.iPtrType ==
       
  1377         EAknsSrvMPPtrBaseRelativeRAM) )
       
  1378         {
       
  1379         TAknsSrvStringDef* oldDef = (TAknsSrvStringDef*)
       
  1380             itemtable[oldIndex].iDef.Address( GetAreaBasePtr(EAknsSrvDataArea));
       
  1381         if( oldDef->iString.iPtrType ==
       
  1382             EAknsSrvMPPtrBaseRelativeRAM )
       
  1383             {
       
  1384             // We already have string data in the chunk
       
  1385             // Const cast is safe (always in RAM)
       
  1386             oldData = const_cast<TText16*>(
       
  1387                 oldDef->iString.Address( GetAreaBasePtr(EAknsSrvDataArea)));
       
  1388             // Size is the length of string
       
  1389             oldDataSize = 8;
       
  1390             }
       
  1391         }
       
  1392 
       
  1393     stringDef.iString.iPtrType = EAknsSrvMPPtrBaseRelativeRAM;
       
  1394     stringDef.iString.iAddressOrOffset =
       
  1395         reinterpret_cast< TText16* >(
       
  1396         UpdateData( &timestamp, 8,
       
  1397         oldData, oldDataSize ) );
       
  1398 
       
  1399     // Const cast is safe (always in RAM)
       
  1400     TText* stringBuf = const_cast< TText16* >(
       
  1401         stringDef.iString.Address( GetAreaBasePtr(EAknsSrvDataArea)));
       
  1402 
       
  1403     UpdateDef( &itemDef, &stringDef, sizeof(stringDef), sizeof(stringDef) );
       
  1404     }
       
  1405 
       
  1406 // -----------------------------------------------------------------------------
       
  1407 // CAknsSrvChunkMaintainer::DoMergeBitmapDefinitionL
       
  1408 // -----------------------------------------------------------------------------
       
  1409 //
       
  1410 void CAknsSrvChunkMaintainer::DoMergeBitmapDefinitionL(
       
  1411     CAknsSrvFileBuffer& aFile, const TUint aOffset,
       
  1412     const TAknsItemDefClass aClass,
       
  1413     const TAknsSrvExclusionQuery& aExclQuery, const TBool /*aAhOverride*/)
       
  1414     {
       
  1415     // Only bitmap and application icon classes are effective
       
  1416     if( (aClass != EAknsItemDefClassBitmaps) &&
       
  1417         (aClass != EAknsItemDefClassAppIcons) )
       
  1418         {
       
  1419         return;
       
  1420         }
       
  1421 
       
  1422     TAknsSrvDef itemDef;
       
  1423 
       
  1424     TInt32 major = AknsSrvUtils::GetInt32L( aFile,
       
  1425         aOffset+EAknsSrvDFOBitmapMajor );
       
  1426     TInt32 minor = AknsSrvUtils::GetInt32L( aFile,
       
  1427         aOffset+EAknsSrvDFOBitmapMinor );
       
  1428     TInt32 filenameid = AknsSrvUtils::GetInt32L( aFile,
       
  1429         aOffset+EAknsSrvDFOBitmapFilenameID) + iCurrentFilenameID;
       
  1430     TInt32 bmpIndex = AknsSrvUtils::GetInt32L( aFile,
       
  1431         aOffset+EAknsSrvDFOBitmapBitmapIndex );
       
  1432     TInt32 maskBmpIndex = AknsSrvUtils::GetInt32L( aFile,
       
  1433         aOffset+EAknsSrvDFOBitmapMaskIndex );
       
  1434 
       
  1435     itemDef.iID.Set(major, minor);
       
  1436 
       
  1437     // Exclude e.g. question mark in A&H override skin
       
  1438     if( aExclQuery.IsExcluded( itemDef.iID ) )
       
  1439         {
       
  1440         return;
       
  1441         }
       
  1442 
       
  1443     CheckAndModifyIID( itemDef.iID, aExclQuery );
       
  1444 
       
  1445     if( maskBmpIndex == -1 )
       
  1446         {
       
  1447         itemDef.iType = EAknsITBitmap;
       
  1448 
       
  1449         // aFilename and MBM index
       
  1450         TAknsSrvBitmapDef bmpDef;
       
  1451         bmpDef.iFilename.iPtrType = EAknsSrvMPPtrBaseRelativeRAM;
       
  1452         bmpDef.iFilename.iAddressOrOffset = reinterpret_cast<
       
  1453             const TUint16*>(
       
  1454             GetFilenameOffsetByID( filenameid ) );
       
  1455         bmpDef.iIndex = bmpIndex;
       
  1456 
       
  1457         // Image attributes
       
  1458         ReadAttributeChunkL( aFile, aOffset+EAknsSrvDFOBitmapAttributes,
       
  1459             bmpDef.iImageAttributes, bmpDef.iImageAlignment,
       
  1460             bmpDef.iImageCoordX, bmpDef.iImageCoordY,
       
  1461             bmpDef.iImageSizeW, bmpDef.iImageSizeH );
       
  1462 
       
  1463         UpdateDef( &itemDef, &bmpDef, sizeof(bmpDef), sizeof(bmpDef) );
       
  1464         }
       
  1465     else
       
  1466         {
       
  1467         itemDef.iType = EAknsITMaskedBitmap;
       
  1468 
       
  1469         // aFilename and MBM index
       
  1470         TAknsSrvMaskedBitmapDef bmpDef;
       
  1471         bmpDef.iFilename.iPtrType = EAknsSrvMPPtrBaseRelativeRAM;
       
  1472         bmpDef.iFilename.iAddressOrOffset = reinterpret_cast<
       
  1473             const TUint16*>(
       
  1474             GetFilenameOffsetByID( filenameid ) );
       
  1475         bmpDef.iIndex = bmpIndex;
       
  1476         bmpDef.iMaskIndex = maskBmpIndex;
       
  1477 
       
  1478         // Image attributes
       
  1479         ReadAttributeChunkL( aFile, aOffset+EAknsSrvDFOBitmapAttributes,
       
  1480             bmpDef.iImageAttributes, bmpDef.iImageAlignment,
       
  1481             bmpDef.iImageCoordX, bmpDef.iImageCoordY,
       
  1482             bmpDef.iImageSizeW, bmpDef.iImageSizeH );
       
  1483 
       
  1484         UpdateDef( &itemDef, &bmpDef, sizeof(bmpDef), sizeof(bmpDef) );
       
  1485         }
       
  1486     }
       
  1487 
       
  1488 // -----------------------------------------------------------------------------
       
  1489 // Local method - PostProcessColorTable.
       
  1490 // -----------------------------------------------------------------------------
       
  1491 //
       
  1492 void PostProcessColorTable(const TAknsItemID aID, TAknsColorTableEntry* aDef,
       
  1493         TInt aOldColorCount, TInt aNewColorCount)
       
  1494     {
       
  1495     if (aOldColorCount > aNewColorCount )
       
  1496         {
       
  1497         if ( aNewColorCount < KAknsSrvTextColorGroupCount &&
       
  1498              aID == KAknsIIDQsnTextColors)
       
  1499             {
       
  1500             // patch MSK colors
       
  1501             aDef[EAknsCIQsnTextColorsCG56].iIndex = aDef[EAknsCIQsnTextColorsCG13].iIndex;
       
  1502             aDef[EAknsCIQsnTextColorsCG56].iRgb = aDef[EAknsCIQsnTextColorsCG13].iRgb;
       
  1503 
       
  1504             aDef[EAknsCIQsnTextColorsCG57].iIndex = aDef[EAknsCIQsnTextColorsCG15].iIndex;
       
  1505             aDef[EAknsCIQsnTextColorsCG57].iRgb = aDef[EAknsCIQsnTextColorsCG15].iRgb;
       
  1506 
       
  1507             aDef[EAknsCIQsnTextColorsCG58].iIndex = aDef[EAknsCIQsnTextColorsCG17].iIndex;
       
  1508             aDef[EAknsCIQsnTextColorsCG58].iRgb = aDef[EAknsCIQsnTextColorsCG17].iRgb;
       
  1509             }
       
  1510         }
       
  1511     }
       
  1512 
       
  1513 // -----------------------------------------------------------------------------
       
  1514 // CAknsSrvChunkMaintainer::DoMergeColorTableDefinitionL
       
  1515 // -----------------------------------------------------------------------------
       
  1516 //
       
  1517 void CAknsSrvChunkMaintainer::DoMergeColorTableDefinitionL(
       
  1518     CAknsSrvFileBuffer& aFile, const TUint aOffset,
       
  1519     const TAknsItemDefClass aClass, const TAknsSrvExclusionQuery& aExclQuery,
       
  1520     const TBool /*aAhOverride*/ )
       
  1521     {
       
  1522     // Only bitmap class is effective
       
  1523     if (aClass != EAknsItemDefClassBitmaps )
       
  1524         {
       
  1525         return;
       
  1526         }
       
  1527 
       
  1528     TAknsSrvDef itemDef;
       
  1529 
       
  1530     TInt32 major = AknsSrvUtils::GetInt32L( aFile,
       
  1531         aOffset+EAknsSrvDFOColorTableMajor );
       
  1532     TInt32 minor = AknsSrvUtils::GetInt32L( aFile,
       
  1533         aOffset+EAknsSrvDFOColorTableMinor );
       
  1534     TInt colorCount = (AknsSrvUtils::GetUInt16L( aFile,
       
  1535         aOffset+EAknsSrvDFOColorTableColorsN))&0xff;
       
  1536 
       
  1537     itemDef.iID.Set( major, minor );
       
  1538     CheckAndModifyIID( itemDef.iID, aExclQuery );
       
  1539 
       
  1540     itemDef.iType = EAknsITColorTable;
       
  1541 
       
  1542     TAknsSrvColorTableDef colorTableDef;
       
  1543     colorTableDef.iNumberOfColors = colorCount;
       
  1544 
       
  1545     // Image attributes
       
  1546     TInt attributeBaseOffset =
       
  1547         aOffset+EAknsSrvDFOColorTableColorIndex0+
       
  1548         colorCount*EAknsSrvDFOColorTableColorSize;
       
  1549     ReadAttributeChunkL( aFile, attributeBaseOffset,
       
  1550         colorTableDef.iImageAttributes, colorTableDef.iImageAlignment,
       
  1551         colorTableDef.iImageCoordX, colorTableDef.iImageCoordY,
       
  1552         colorTableDef.iImageSizeW, colorTableDef.iImageSizeH );
       
  1553 
       
  1554     TAny* oldData = 0;
       
  1555     TInt oldDataSize = 0;
       
  1556 
       
  1557     TAknsSrvDef* itemtable = (TAknsSrvDef*)(GetAreaBasePtr(EAknsSrvItemDefArea));
       
  1558     TInt oldIndex = FindDefIndex( itemDef.iID );
       
  1559     if( (oldIndex>0) && (itemtable[oldIndex].iDef.iPtrType ==
       
  1560         EAknsSrvMPPtrBaseRelativeRAM) )
       
  1561         {
       
  1562         TAknsSrvColorTableDef* oldDef = (TAknsSrvColorTableDef*)
       
  1563             itemtable[oldIndex].iDef.Address( GetAreaBasePtr(EAknsSrvDataArea) );
       
  1564         if( oldDef->iColors.iPtrType ==
       
  1565             EAknsSrvMPPtrBaseRelativeRAM )
       
  1566             {
       
  1567             // We already have color table data in the chunk
       
  1568             oldData = const_cast<TAknsColorTableEntry*>(
       
  1569                 oldDef->iColors.Address( GetAreaBasePtr(EAknsSrvDataArea)));
       
  1570             oldDataSize = oldDef->iNumberOfColors *
       
  1571                 sizeof(TAknsColorTableEntry);
       
  1572             if (oldDef->iNumberOfColors > colorTableDef.iNumberOfColors)
       
  1573                 {
       
  1574                 // keep the entrycount as same as in the old table,
       
  1575                 // if the new table has less colors that the old one
       
  1576                 // ie. inherit the colors from the default skin
       
  1577                 colorTableDef.iNumberOfColors = oldDef->iNumberOfColors;
       
  1578                 }
       
  1579             }
       
  1580         }
       
  1581 
       
  1582     colorTableDef.iColors.iPtrType = EAknsSrvMPPtrBaseRelativeRAM;
       
  1583     colorTableDef.iColors.iAddressOrOffset =
       
  1584         reinterpret_cast< TAknsColorTableEntry* >(
       
  1585         UpdateData( NULL, colorCount*sizeof(TAknsColorTableEntry),
       
  1586         oldData, oldDataSize ) );
       
  1587 
       
  1588     TAknsColorTableEntry* colorEntries =
       
  1589         const_cast< TAknsColorTableEntry* >(
       
  1590         colorTableDef.iColors.Address( GetAreaBasePtr(EAknsSrvDataArea)));
       
  1591 
       
  1592     for( TInt i=0; i<colorCount; i++ )
       
  1593         {
       
  1594         TInt16 index = AknsSrvUtils::GetUInt16L( aFile,
       
  1595             aOffset+EAknsSrvDFOColorTableColorIndex0 +
       
  1596             (i*EAknsSrvDFOColorTableColorSize) );
       
  1597         TInt32 rgb = AknsSrvUtils::GetInt32L( aFile,
       
  1598             aOffset+EAknsSrvDFOColorTableColorRgb0 +
       
  1599             (i*EAknsSrvDFOColorTableColorSize) );
       
  1600 
       
  1601         colorEntries[i].iIndex = index;
       
  1602         colorEntries[i].iRgb = rgb;
       
  1603         }
       
  1604     PostProcessColorTable(itemDef.iID,colorEntries,colorTableDef.iNumberOfColors, colorCount);
       
  1605     UpdateDef( &itemDef, &colorTableDef, sizeof(colorTableDef), sizeof(colorTableDef) );
       
  1606     }
       
  1607 
       
  1608 // -----------------------------------------------------------------------------
       
  1609 // CAknsSrvChunkMaintainer::DoMergeImageTableDefinitionL
       
  1610 // -----------------------------------------------------------------------------
       
  1611 //
       
  1612 void CAknsSrvChunkMaintainer::DoMergeImageTableDefinitionL(
       
  1613     CAknsSrvFileBuffer& aFile, const TUint aOffset,
       
  1614     const TAknsItemDefClass aClass,
       
  1615     const TAknsSrvExclusionQuery& aExclQuery, const TBool /*aAhOverride*/ )
       
  1616     {
       
  1617     // Only bitmap and application icon classes are effective
       
  1618     if( (aClass != EAknsItemDefClassBitmaps) &&
       
  1619         (aClass != EAknsItemDefClassAppIcons) )
       
  1620         {
       
  1621         return;
       
  1622         }
       
  1623 
       
  1624     TAknsSrvDef itemDef;
       
  1625 
       
  1626     TInt32 major = AknsSrvUtils::GetInt32L( aFile,
       
  1627         aOffset+EAknsSrvDFOImageTableMajor );
       
  1628     TInt32 minor = AknsSrvUtils::GetInt32L( aFile,
       
  1629         aOffset+EAknsSrvDFOImageTableMinor );
       
  1630     TInt imageCount = (AknsSrvUtils::GetUInt16L( aFile,
       
  1631         aOffset+EAknsSrvDFOImageTableImagesN))&0xff;
       
  1632 
       
  1633     itemDef.iID.Set( major, minor );
       
  1634     CheckAndModifyIID( itemDef.iID, aExclQuery );
       
  1635 
       
  1636     // Exclude e.g. ROP icon
       
  1637     if( aExclQuery.IsExcluded( itemDef.iID ) )
       
  1638         {
       
  1639         return;
       
  1640         }
       
  1641 
       
  1642     itemDef.iType = EAknsITImageTable;
       
  1643 
       
  1644     TAknsSrvImageTableDef imageTableDef;
       
  1645     imageTableDef.iNumberOfImages = imageCount;
       
  1646 
       
  1647     // Image attributes
       
  1648     TInt attributeBaseOffset =
       
  1649         aOffset+EAknsSrvDFOImageTableImageMajor0+
       
  1650         imageCount*EAknsSrvDFOImageTableImageSize;
       
  1651     ReadAttributeChunkL( aFile, attributeBaseOffset,
       
  1652         imageTableDef.iImageAttributes, imageTableDef.iImageAlignment,
       
  1653         imageTableDef.iImageCoordX, imageTableDef.iImageCoordY,
       
  1654         imageTableDef.iImageSizeW, imageTableDef.iImageSizeH );
       
  1655 
       
  1656     TAny* oldData = 0;
       
  1657     TInt oldDataSize = 0;
       
  1658 
       
  1659     TAknsSrvDef* itemtable = (TAknsSrvDef*)(GetAreaBasePtr(EAknsSrvItemDefArea));
       
  1660     TInt oldIndex = FindDefIndex( itemDef.iID );
       
  1661     if( (oldIndex>0) && (itemtable[oldIndex].iDef.iPtrType ==
       
  1662         EAknsSrvMPPtrBaseRelativeRAM) )
       
  1663         {
       
  1664         TAknsSrvImageTableDef* oldDef = (TAknsSrvImageTableDef*)
       
  1665             itemtable[oldIndex].iDef.Address( GetAreaBasePtr(EAknsSrvDataArea));
       
  1666         if( oldDef->iImages.iPtrType ==
       
  1667             EAknsSrvMPPtrBaseRelativeRAM )
       
  1668             {
       
  1669             // We already have image table data in the chunk
       
  1670             oldData = const_cast<TAknsItemID*>(
       
  1671                 oldDef->iImages.Address( GetAreaBasePtr(EAknsSrvDataArea)));
       
  1672             oldDataSize = oldDef->iNumberOfImages *
       
  1673                 sizeof(TAknsItemID);
       
  1674             }
       
  1675         }
       
  1676 
       
  1677     imageTableDef.iImages.iPtrType = EAknsSrvMPPtrBaseRelativeRAM;
       
  1678     imageTableDef.iImages.iAddressOrOffset =
       
  1679         reinterpret_cast< TAknsItemID* >(
       
  1680         UpdateData( NULL, imageCount*sizeof(TAknsItemID),
       
  1681         oldData, oldDataSize ) );
       
  1682 
       
  1683     TAknsItemID* imageEntries =
       
  1684         const_cast< TAknsItemID* >(
       
  1685         imageTableDef.iImages.Address( GetAreaBasePtr(EAknsSrvDataArea)));
       
  1686 
       
  1687     for( TInt i=0; i<imageCount; i++ )
       
  1688         {
       
  1689         TInt32 imgMajor = AknsSrvUtils::GetInt32L( aFile,
       
  1690             aOffset+EAknsSrvDFOImageTableImageMajor0 +
       
  1691             (i*EAknsSrvDFOImageTableImageSize) );
       
  1692         TInt32 imgMinor = AknsSrvUtils::GetInt32L( aFile,
       
  1693             aOffset+EAknsSrvDFOImageTableImageMinor0 +
       
  1694             (i*EAknsSrvDFOImageTableImageSize) );
       
  1695 
       
  1696         imageEntries[i].iMajor = imgMajor;
       
  1697         imageEntries[i].iMinor = imgMinor;
       
  1698         CheckAndModifyIID( imageEntries[i], aExclQuery );
       
  1699         }
       
  1700 
       
  1701     if( imageCount == 9 ) // Frame
       
  1702         {
       
  1703         EnqueuePostOperationL( EAknsSrvCMPOTTileToStretch, imageEntries[4] );
       
  1704         EnqueuePostOperationL( EAknsSrvCMPOTTileToStretch, imageEntries[5] );
       
  1705         EnqueuePostOperationL( EAknsSrvCMPOTTileToStretch, imageEntries[6] );
       
  1706         EnqueuePostOperationL( EAknsSrvCMPOTTileToStretch, imageEntries[7] );
       
  1707         EnqueuePostOperationL( EAknsSrvCMPOTTileToStretch, imageEntries[8] );
       
  1708         }
       
  1709 
       
  1710     UpdateDef( &itemDef, &imageTableDef,
       
  1711         sizeof(imageTableDef), sizeof(imageTableDef) );
       
  1712     }
       
  1713 
       
  1714 // -----------------------------------------------------------------------------
       
  1715 // CAknsSrvChunkMaintainer::DoMergeBmpAnimDefinitionL
       
  1716 // -----------------------------------------------------------------------------
       
  1717 //
       
  1718 void CAknsSrvChunkMaintainer::DoMergeBmpAnimDefinitionL(
       
  1719     CAknsSrvFileBuffer& aFile, const TUint aOffset,
       
  1720     const TAknsItemDefClass aClass,
       
  1721     const TAknsSrvExclusionQuery& aExclQuery, const TBool /*aAhOverride*/ )
       
  1722     {
       
  1723     // Only bitmap class are effective
       
  1724     if( aClass != EAknsItemDefClassBitmaps )
       
  1725         {
       
  1726         return;
       
  1727         }
       
  1728 
       
  1729     TAknsSrvDef itemDef;
       
  1730 
       
  1731     TInt32 major = AknsSrvUtils::GetInt32L( aFile,
       
  1732         aOffset+EAknsSrvDFOBmpAnimMajor );
       
  1733     TInt32 minor = AknsSrvUtils::GetInt32L( aFile,
       
  1734         aOffset+EAknsSrvDFOBmpAnimMinor );
       
  1735     TInt frameCount = (AknsSrvUtils::GetUInt16L( aFile,
       
  1736         aOffset+EAknsSrvDFOBmpAnimFramesN))&0xff;
       
  1737     TInt16 interval = AknsSrvUtils::GetInt16L( aFile,
       
  1738         aOffset+EAknsSrvDFOBmpAnimInterval );
       
  1739     TInt16 playMode = static_cast< TInt16 >(
       
  1740         AknsSrvUtils::GetUInt8L( aFile,
       
  1741         aOffset+EAknsSrvDFOBmpAnimPlayMode) );
       
  1742     TBool flash = EFalse;
       
  1743     if( ((AknsSrvUtils::GetUInt16L( aFile,
       
  1744         aOffset+EAknsSrvDFOBmpAnimPlayMode))&0xff) != 0 )
       
  1745         {
       
  1746         flash = ETrue;
       
  1747         }
       
  1748 
       
  1749     itemDef.iID.Set( major, minor );
       
  1750 
       
  1751     // Exclude e.g. question mark in A&H override skin
       
  1752     if( aExclQuery.IsExcluded( itemDef.iID ) )
       
  1753         {
       
  1754         return;
       
  1755         }
       
  1756 
       
  1757     CheckAndModifyIID( itemDef.iID, aExclQuery );
       
  1758 
       
  1759     itemDef.iType = EAknsITBmpAnim;
       
  1760 
       
  1761     TAknsSrvBmpAnimDef bmpAnimDef;
       
  1762     bmpAnimDef.iNumberOfImages = frameCount;
       
  1763     bmpAnimDef.iFrameInterval = interval;
       
  1764     bmpAnimDef.iPlayMode = playMode;
       
  1765     bmpAnimDef.iFlash = flash;
       
  1766     bmpAnimDef.iLastFrameBackground = EFalse;
       
  1767 
       
  1768     // Image attributes
       
  1769     TInt attributeBaseOffset =
       
  1770         aOffset+EAknsSrvDFOBmpAnimFrameMajor0+
       
  1771         frameCount*EAknsSrvDFOBmpAnimFrameSize;
       
  1772     ReadAttributeChunkL( aFile, attributeBaseOffset,
       
  1773         bmpAnimDef.iImageAttributes, bmpAnimDef.iImageAlignment,
       
  1774         bmpAnimDef.iImageCoordX, bmpAnimDef.iImageCoordY,
       
  1775         bmpAnimDef.iImageSizeW, bmpAnimDef.iImageSizeH );
       
  1776 
       
  1777     TAny* oldImageData = 0;
       
  1778     TInt oldImageDataSize = 0;
       
  1779     TAny* oldFrameData = 0;
       
  1780     TInt oldFrameDataSize = 0;
       
  1781 
       
  1782     TAknsSrvDef* itemtable = (TAknsSrvDef*)(GetAreaBasePtr(EAknsSrvItemDefArea));
       
  1783     TInt oldIndex = FindDefIndex( itemDef.iID );
       
  1784     if( (oldIndex>0) && (itemtable[oldIndex].iDef.iPtrType ==
       
  1785         EAknsSrvMPPtrBaseRelativeRAM) )
       
  1786         {
       
  1787         TAknsSrvBmpAnimDef* oldDef = (TAknsSrvBmpAnimDef*)
       
  1788             itemtable[oldIndex].iDef.Address(GetAreaBasePtr(EAknsSrvDataArea));
       
  1789         if( oldDef->iImages.iPtrType ==
       
  1790             EAknsSrvMPPtrBaseRelativeRAM )
       
  1791             {
       
  1792             // We already have image table data in the chunk
       
  1793             oldImageData = const_cast<TAknsItemID*>(
       
  1794                 oldDef->iImages.Address(GetAreaBasePtr(EAknsSrvDataArea)));
       
  1795             oldImageDataSize = oldDef->iNumberOfImages *
       
  1796                 sizeof(TAknsItemID);
       
  1797             }
       
  1798         if( oldDef->iFrameInfos.iPtrType ==
       
  1799             EAknsSrvMPPtrBaseRelativeRAM )
       
  1800             {
       
  1801             // We already have frame infos in the chunk
       
  1802             oldFrameData = const_cast<TAknsBmpAnimFrameInfo*>(
       
  1803                 oldDef->iFrameInfos.Address( GetAreaBasePtr(EAknsSrvDataArea)));
       
  1804             oldFrameDataSize = oldDef->iNumberOfImages *
       
  1805                 sizeof(TAknsBmpAnimFrameInfo);
       
  1806             }
       
  1807         }
       
  1808 
       
  1809     bmpAnimDef.iImages.iPtrType = EAknsSrvMPPtrBaseRelativeRAM;
       
  1810     bmpAnimDef.iImages.iAddressOrOffset =
       
  1811         reinterpret_cast< TAknsItemID* >(
       
  1812         UpdateData( NULL, frameCount*sizeof(TAknsItemID),
       
  1813         oldImageData, oldImageDataSize ) );
       
  1814     bmpAnimDef.iFrameInfos.iPtrType = EAknsSrvMPPtrBaseRelativeRAM;
       
  1815     bmpAnimDef.iFrameInfos.iAddressOrOffset =
       
  1816         reinterpret_cast< TAknsBmpAnimFrameInfo* >(
       
  1817         UpdateData( NULL, frameCount*sizeof(TAknsBmpAnimFrameInfo),
       
  1818         oldFrameData, oldFrameDataSize ) );
       
  1819 
       
  1820     TAknsItemID* imageEntries =
       
  1821         const_cast< TAknsItemID* >(
       
  1822         bmpAnimDef.iImages.Address( GetAreaBasePtr(EAknsSrvDataArea)));
       
  1823     TAknsBmpAnimFrameInfo* frameEntries =
       
  1824         const_cast< TAknsBmpAnimFrameInfo* >(
       
  1825         bmpAnimDef.iFrameInfos.Address( GetAreaBasePtr(EAknsSrvDataArea)));
       
  1826 
       
  1827     for( TInt i=0; i<frameCount; i++ )
       
  1828         {
       
  1829         TInt32 imgMajor = AknsSrvUtils::GetInt32L( aFile,
       
  1830             aOffset+EAknsSrvDFOBmpAnimFrameMajor0 +
       
  1831             (i*EAknsSrvDFOBmpAnimFrameSize) );
       
  1832         TInt32 imgMinor = AknsSrvUtils::GetInt32L( aFile,
       
  1833             aOffset+EAknsSrvDFOBmpAnimFrameMinor0 +
       
  1834             (i*EAknsSrvDFOBmpAnimFrameSize) );
       
  1835 
       
  1836         imageEntries[i].iMajor = imgMajor;
       
  1837         imageEntries[i].iMinor = imgMinor;
       
  1838         CheckAndModifyIID( imageEntries[i], aExclQuery );
       
  1839 
       
  1840         TInt16 frameTime = AknsSrvUtils::GetInt16L( aFile,
       
  1841             aOffset+EAknsSrvDFOBmpAnimFrameTime0 +
       
  1842             (i*EAknsSrvDFOBmpAnimFrameSize) );
       
  1843         TInt16 framePosX = AknsSrvUtils::GetInt16L( aFile,
       
  1844             aOffset+EAknsSrvDFOBmpAnimFramePosX0 +
       
  1845             (i*EAknsSrvDFOBmpAnimFrameSize) );
       
  1846         TInt16 framePosY = AknsSrvUtils::GetInt16L( aFile,
       
  1847             aOffset+EAknsSrvDFOBmpAnimFramePosY0 +
       
  1848             (i*EAknsSrvDFOBmpAnimFrameSize) );
       
  1849 
       
  1850         frameEntries[i].iTime = frameTime;
       
  1851         frameEntries[i].iPosX = framePosX;
       
  1852         frameEntries[i].iPosY = framePosY;
       
  1853         }
       
  1854 
       
  1855     UpdateDef( &itemDef, &bmpAnimDef, sizeof(bmpAnimDef), sizeof(bmpAnimDef) );
       
  1856     }
       
  1857 
       
  1858 // -----------------------------------------------------------------------------
       
  1859 // CAknsSrvChunkMaintainer::DoMergeStringDefinitionL
       
  1860 // -----------------------------------------------------------------------------
       
  1861 //
       
  1862 void CAknsSrvChunkMaintainer::DoMergeStringDefinitionL(
       
  1863     CAknsSrvFileBuffer& aFile, const TUint aOffset,
       
  1864     const TAknsItemDefClass aClass,
       
  1865     const TAknsSrvExclusionQuery& aExclQuery, const TBool /*aAhOverride*/ )
       
  1866     {
       
  1867     // Only bitmap and application icon classes are effective
       
  1868     if( (aClass != EAknsItemDefClassBitmaps) &&
       
  1869         (aClass != EAknsItemDefClassAppIcons) )
       
  1870         {
       
  1871         return;
       
  1872         }
       
  1873 
       
  1874     TAknsSrvDef itemDef;
       
  1875 
       
  1876     // First fetch the scalar values
       
  1877     TInt32 major = AknsSrvUtils::GetInt32L( aFile,
       
  1878         aOffset+EAknsSrvDFOStringMajor );
       
  1879     TInt32 minor = AknsSrvUtils::GetInt32L( aFile,
       
  1880         aOffset+EAknsSrvDFOStringMinor );
       
  1881     TInt stringLen = AknsSrvUtils::GetUInt16L( aFile,
       
  1882         aOffset+EAknsSrvDFOStringStringLen );
       
  1883 
       
  1884     // Perform any ID mappings
       
  1885     itemDef.iID.Set( major, minor );
       
  1886     CheckAndModifyIID( itemDef.iID, aExclQuery );
       
  1887 
       
  1888     // Exclude e.g. ROP icon
       
  1889     if( aExclQuery.IsExcluded( itemDef.iID ) )
       
  1890         {
       
  1891         return;
       
  1892         }
       
  1893 
       
  1894     // Initialize item def type
       
  1895     itemDef.iType = EAknsITString;
       
  1896     TAknsSrvStringDef stringDef;
       
  1897 
       
  1898     // TText16 and TPtrC16 must be used here, since the data is copied
       
  1899     // verbatim from the skin file
       
  1900     TText16* oldData = 0;
       
  1901     TInt oldDataSize = 0;
       
  1902 
       
  1903     // Find old item, if any
       
  1904     TAknsSrvDef* itemtable = (TAknsSrvDef*)(GetAreaBasePtr(EAknsSrvItemDefArea));
       
  1905     TInt oldIndex = FindDefIndex( itemDef.iID );
       
  1906     if( (oldIndex>0) && (itemtable[oldIndex].iDef.iPtrType ==
       
  1907         EAknsSrvMPPtrBaseRelativeRAM) )
       
  1908         {
       
  1909         TAknsSrvStringDef* oldDef = (TAknsSrvStringDef*)
       
  1910             itemtable[oldIndex].iDef.Address( GetAreaBasePtr(EAknsSrvDataArea));
       
  1911         if( oldDef->iString.iPtrType ==
       
  1912             EAknsSrvMPPtrBaseRelativeRAM )
       
  1913             {
       
  1914             // We already have string data in the chunk
       
  1915             // Const cast is safe (always in RAM)
       
  1916             oldData = const_cast<TText16*>(
       
  1917                 oldDef->iString.Address( GetAreaBasePtr(EAknsSrvDataArea)));
       
  1918             // Size is the length of string + zero terminator
       
  1919             oldDataSize = TPtrC16( oldData ).Size() + 2;
       
  1920             }
       
  1921         }
       
  1922 
       
  1923     stringDef.iString.iPtrType = EAknsSrvMPPtrBaseRelativeRAM;
       
  1924     stringDef.iString.iAddressOrOffset =
       
  1925         reinterpret_cast< TText16* >(
       
  1926         UpdateData( NULL, (stringLen+1)*2,
       
  1927         oldData, oldDataSize ) );
       
  1928 
       
  1929     // Const cast is safe (always in RAM)
       
  1930     TText* stringBuf = const_cast< TText16* >(
       
  1931         stringDef.iString.Address( GetAreaBasePtr(EAknsSrvDataArea)));
       
  1932 
       
  1933     for( TInt i=0; i<stringLen; i++ )
       
  1934         {
       
  1935         stringBuf[i] = AknsSrvUtils::GetInt16L( aFile,
       
  1936             aOffset+EAknsSrvDFOStringString+2*i );
       
  1937         }
       
  1938     // Append zero terminator
       
  1939     stringBuf[stringLen] = 0;
       
  1940 
       
  1941     UpdateDef( &itemDef, &stringDef, sizeof(stringDef), sizeof(stringDef) );
       
  1942     }
       
  1943 
       
  1944 // -----------------------------------------------------------------------------
       
  1945 // CAknsSrvChunkMaintainer::ReadAttributeChunkL
       
  1946 // -----------------------------------------------------------------------------
       
  1947 //
       
  1948 void CAknsSrvChunkMaintainer::ReadAttributeChunkL( CAknsSrvFileBuffer& aFile,
       
  1949     const TUint aOffset, TInt& aAttributes, TInt& aAlignment,
       
  1950     TInt& aCoordX, TInt& aCoordY, TInt& aSizeW, TInt& aSizeH )
       
  1951     {
       
  1952     TUint16 version = AknsSrvUtils::GetUInt16L( aFile,
       
  1953         aOffset + EAknsSrvDFOCommonVersion );
       
  1954 
       
  1955     TUint16 alignAttr = AknsSrvUtils::GetUInt16L( aFile,
       
  1956         aOffset + EAknsSrvDFOAttributesAttributeFlags );
       
  1957     TInt16 imageCoordX = AknsSrvUtils::GetUInt16L( aFile,
       
  1958         aOffset + EAknsSrvDFOAttributesCoordX );
       
  1959     TInt16 imageCoordY = AknsSrvUtils::GetUInt16L( aFile,
       
  1960         aOffset + EAknsSrvDFOAttributesCoordY );
       
  1961     TInt16 imageSizeW = AknsSrvUtils::GetUInt16L( aFile,
       
  1962         aOffset + EAknsSrvDFOAttributesSizeW );
       
  1963     TInt16 imageSizeH = AknsSrvUtils::GetUInt16L( aFile,
       
  1964         aOffset + EAknsSrvDFOAttributesSizeH );
       
  1965 
       
  1966     aAttributes = alignAttr&0xff;
       
  1967     aAlignment = (alignAttr&0xff00)>>8;
       
  1968     aCoordX = imageCoordX;
       
  1969     aCoordY = imageCoordY;
       
  1970     aSizeW = imageSizeW;
       
  1971     aSizeH = imageSizeH;
       
  1972 
       
  1973     if( version >= 2 )
       
  1974         {
       
  1975         TInt extAttr = AknsSrvUtils::GetUInt16L( aFile,
       
  1976             aOffset + EAknsSrvDFOAttributesExtAttributeFlags );
       
  1977         extAttr = extAttr << 8;
       
  1978         aAttributes |= extAttr;
       
  1979         }
       
  1980     }
       
  1981 
       
  1982 // -----------------------------------------------------------------------------
       
  1983 // CAknsSrvChunkMaintainer::FindDefIndex
       
  1984 // -----------------------------------------------------------------------------
       
  1985 //
       
  1986 TInt CAknsSrvChunkMaintainer::FindDefIndex( const TAknsItemID& aIID )
       
  1987     {
       
  1988     if ( iMergeS60Skin )
       
  1989         {
       
  1990         return -1;
       
  1991         }
       
  1992     TAknsSrvHashTable* hashtable = (TAknsSrvHashTable*)GetAreaBasePtr(EAknsSrvItemDefHash);
       
  1993     TAknsSrvDef* itemtable = (TAknsSrvDef*)GetAreaBasePtr(EAknsSrvItemDefArea);
       
  1994     TInt defcount = GetAreaCurrentSize(EAknsSrvItemDefArea) / sizeof(TAknsSrvDef);
       
  1995   
       
  1996     TUint hashindex = (TUint)(aIID.iMajor + aIID.iMinor) % KAknsSrvMaxHashList;
       
  1997     if ( hashtable[hashindex].iHead >= 0 )
       
  1998         {
       
  1999         TInt def = hashtable[hashindex].iHead;
       
  2000         while ( def >= 0)
       
  2001             {
       
  2002             if (TAknsItemID::LinearOrder( aIID, itemtable[def].iID) == 0 )
       
  2003                 {
       
  2004                 return def;
       
  2005                 }
       
  2006             def = itemtable[def].iHashNext;
       
  2007             }
       
  2008         }
       
  2009 
       
  2010     return -1;
       
  2011     }
       
  2012 
       
  2013 // -----------------------------------------------------------------------------
       
  2014 // CAknsSrvChunkMaintainer::UpdateDef
       
  2015 // -----------------------------------------------------------------------------
       
  2016 //
       
  2017 void CAknsSrvChunkMaintainer::UpdateDef( const TAknsSrvDef* aDef,
       
  2018     const TAny* aData, const TInt aDataSize, const TInt aOldDataSize )
       
  2019     {
       
  2020     TAny* oldData = NULL;
       
  2021     TInt oldDataSize = 0;
       
  2022     TAknsSrvDef* trgDef = NULL;
       
  2023 
       
  2024     TInt index = FindDefIndex( aDef->iID );
       
  2025 
       
  2026     if( index >= 0 )
       
  2027         {
       
  2028         trgDef = (TAknsSrvDef*)( GetAreaBasePtr(EAknsSrvItemDefArea) + index*sizeof(TAknsSrvDef) );
       
  2029 
       
  2030         if( (trgDef->iType == aDef->iType) &&
       
  2031             (trgDef->iDef.iPtrType == EAknsSrvMPPtrBaseRelativeRAM ) )
       
  2032             {
       
  2033             oldData = const_cast<TAny*>(
       
  2034                 trgDef->iDef.Address( GetAreaBasePtr(EAknsSrvDataArea) ) );
       
  2035             if (aOldDataSize == -1)
       
  2036                 {
       
  2037                 // if a olddatasize -1 was passed to this function the first value
       
  2038                 // in the data is the size of the data (in bytes)
       
  2039                 TInt size  = *(reinterpret_cast<TInt*>(oldData));
       
  2040                 oldDataSize = size;
       
  2041                 }
       
  2042             else
       
  2043                 {
       
  2044                 oldDataSize = aOldDataSize;
       
  2045                 }
       
  2046             }
       
  2047         TInt next = trgDef->iHashNext;
       
  2048         Mem::Copy( trgDef, aDef, sizeof(TAknsSrvDef) );
       
  2049         trgDef->iHashNext = next;
       
  2050         }
       
  2051     else
       
  2052         {
       
  2053         trgDef = (TAknsSrvDef*)( GetAreaBasePtr(EAknsSrvItemDefArea)
       
  2054             + GetAreaCurrentSize(EAknsSrvItemDefArea));
       
  2055         SetAreaCurrentSize(EAknsSrvItemDefArea,
       
  2056             GetAreaCurrentSize(EAknsSrvItemDefArea)+sizeof(TAknsSrvDef));
       
  2057         Mem::Copy( trgDef, aDef, sizeof(TAknsSrvDef) );
       
  2058         UpdateDefHash( trgDef );
       
  2059         }
       
  2060 
       
  2061     trgDef->iDef.iPtrType = EAknsSrvMPPtrBaseRelativeRAM;
       
  2062     trgDef->iDef.iAddressOrOffset = reinterpret_cast<TAny*>(
       
  2063         UpdateData( aData, aDataSize, oldData, oldDataSize ) );
       
  2064     }
       
  2065 
       
  2066 void CAknsSrvChunkMaintainer::UpdateDefHash( TAknsSrvDef* aDef )
       
  2067     {
       
  2068     //Calculate the hash number
       
  2069     TUint num = (TUint)( aDef->iID.iMajor + aDef->iID.iMinor ) % 128;
       
  2070     TAknsSrvHashTable* hashtable = (TAknsSrvHashTable*)GetAreaBasePtr(EAknsSrvItemDefHash);
       
  2071     TInt defcount = GetAreaCurrentSize(EAknsSrvItemDefArea) / sizeof(TAknsSrvDef);
       
  2072 
       
  2073     aDef->iHashNext = (hashtable[num].iHead >= 0) ? hashtable[num].iHead: -1;
       
  2074     hashtable[num].iHead = defcount-1; 
       
  2075     }
       
  2076 // -----------------------------------------------------------------------------
       
  2077 // CAknsSrvChunkMaintainer::UpdateData
       
  2078 // -----------------------------------------------------------------------------
       
  2079 //
       
  2080 TInt CAknsSrvChunkMaintainer::UpdateData( const TAny* aData,
       
  2081     const TInt aDataSize, TAny* aOldData, const TInt aOldDataSize )
       
  2082     {
       
  2083     TInt offset = 0;
       
  2084 
       
  2085     if( aOldData && (aOldDataSize>=aDataSize) )
       
  2086         {
       
  2087         // New data fits in place of the old data
       
  2088         if( aData )
       
  2089             {
       
  2090             Mem::Copy( aOldData, aData, aDataSize );
       
  2091             }
       
  2092         offset = (TInt)aOldData - (TInt)GetAreaBasePtr(EAknsSrvDataArea);
       
  2093         }
       
  2094     else
       
  2095         {
       
  2096         offset = GetAreaCurrentSize(EAknsSrvDataArea);
       
  2097         SetAreaCurrentSize(EAknsSrvDataArea, offset+aDataSize);
       
  2098         if( aData )
       
  2099             {
       
  2100             Mem::Copy( GetAreaBasePtr(EAknsSrvDataArea) + offset, aData,
       
  2101                 aDataSize );
       
  2102             }
       
  2103         }
       
  2104     return offset;
       
  2105     }
       
  2106 
       
  2107 // -----------------------------------------------------------------------------
       
  2108 // CAknsSrvChunkMaintainer::GetFilenameOffsetByID
       
  2109 // -----------------------------------------------------------------------------
       
  2110 //
       
  2111 TInt CAknsSrvChunkMaintainer::GetFilenameOffsetByID( TInt32 aID )
       
  2112     {
       
  2113     TInt32* chunkptr = (TInt32*)(GetAreaBasePtr(EAknsSrvFilenameArea));
       
  2114     TInt count = GetAreaCurrentSize(EAknsSrvFilenameArea)
       
  2115         / KAknsSrvMaxFileNameLen;
       
  2116     TInt index = 0;
       
  2117     for (index = 0; index < count; index++)
       
  2118         {
       
  2119         if (chunkptr[0] == aID)
       
  2120             {
       
  2121             break;
       
  2122             }
       
  2123         chunkptr+=KAknsSrvMaxFileNameLen/4;
       
  2124         }
       
  2125     return index*KAknsSrvMaxFileNameLen+4;
       
  2126     }
       
  2127 
       
  2128 // -----------------------------------------------------------------------------
       
  2129 // CAknsSrvChunkMaintainer::UpdateFilename
       
  2130 // -----------------------------------------------------------------------------
       
  2131 //
       
  2132 void CAknsSrvChunkMaintainer::UpdateFilename(
       
  2133     TInt32 aFilenameID, TUint8* aFilenamePtr, TUint16 aFilenameLen,
       
  2134     const TDesC& aBaseFilename )
       
  2135     {
       
  2136     TInt pathindex = aBaseFilename.LocateReverse(TChar('\\'))+1;
       
  2137     TInt filenamecount = GetAreaCurrentSize(EAknsSrvFilenameArea)
       
  2138         / KAknsSrvMaxFileNameLen;
       
  2139     TInt* chunkptr = (TInt*)GetAreaBasePtr(EAknsSrvFilenameArea);
       
  2140     TInt index = 0;
       
  2141     TBool found = EFalse;
       
  2142     // Check if the filename is already inserted and update it
       
  2143     for (index = 0; index < filenamecount; index++)
       
  2144         {
       
  2145         if (chunkptr[0] == aFilenameID)
       
  2146             {
       
  2147             found = ETrue;
       
  2148             break;
       
  2149             }
       
  2150         chunkptr+=KAknsSrvMaxFileNameLen/4;
       
  2151         }
       
  2152 
       
  2153     if (!found)
       
  2154         {
       
  2155         SetAreaCurrentSize( EAknsSrvFilenameArea,
       
  2156             GetAreaCurrentSize(EAknsSrvFilenameArea)+KAknsSrvMaxFileNameLen);
       
  2157         }
       
  2158 
       
  2159     TUint8* filenameptr = (TUint8*)chunkptr;
       
  2160     Mem::FillZ(filenameptr, KAknsSrvMaxFileNameLen);
       
  2161     chunkptr[0] = aFilenameID;
       
  2162 
       
  2163     filenameptr+=4;
       
  2164     Mem::Copy(filenameptr, aBaseFilename.Ptr(), pathindex*2);
       
  2165     Mem::Copy(filenameptr+pathindex*2,
       
  2166         aFilenamePtr,
       
  2167         aFilenameLen*2);
       
  2168     Mem::FillZ(filenameptr+pathindex*2+aFilenameLen*2, 2);
       
  2169     }
       
  2170 
       
  2171 // -----------------------------------------------------------------------------
       
  2172 // CAknsSrvChunkMaintainer::GetAreaBasePtr
       
  2173 // -----------------------------------------------------------------------------
       
  2174 //
       
  2175 TInt8* CAknsSrvChunkMaintainer::GetAreaBasePtr( TAknsSrvBaseAreaName aAreaname )
       
  2176     {
       
  2177     TInt* chunkbase = (TInt*)(iSharedChunk.Base());
       
  2178     TInt offset = 0;
       
  2179     switch (aAreaname)
       
  2180         {
       
  2181         case EAknsSrvItemDefArea:
       
  2182             offset = chunkbase[EAknsSrvItemDefAreaBaseOffset];
       
  2183             return ((TInt8*)(chunkbase))+offset;
       
  2184         case EAknsSrvDataArea:
       
  2185             offset = chunkbase[EAknsSrvDataAreaBaseOffset];
       
  2186             return ((TInt8*)(chunkbase))+offset;
       
  2187         case EAknsSrvFilenameArea:
       
  2188             offset = chunkbase[EAknsSrvFilenameAreaBaseOffset];
       
  2189             return ((TInt8*)(chunkbase))+offset;
       
  2190         case EAknsSrvScalableGfxArea:
       
  2191             offset = chunkbase[EAknsSrvScalableGfxAreaBaseOffset];
       
  2192             return ((TInt8*)(chunkbase))+offset;
       
  2193         case EAknsSrvItemDefHash:
       
  2194             offset = chunkbase[EAknsSrvItemDefHashBaseOffset];
       
  2195             return ((TInt8*)(chunkbase))+offset;
       
  2196         default:
       
  2197             return 0;
       
  2198         }
       
  2199     }
       
  2200 
       
  2201 // -----------------------------------------------------------------------------
       
  2202 // CAknsSrvChunkMaintainer::GetAreaAllocatedSize
       
  2203 // -----------------------------------------------------------------------------
       
  2204 //
       
  2205 TInt CAknsSrvChunkMaintainer::GetAreaAllocatedSize(
       
  2206     TAknsSrvBaseAreaName aAreaname )
       
  2207     {
       
  2208     TInt* chunkbase = (TInt*)(iSharedChunk.Base());
       
  2209     TInt size = 0;
       
  2210     switch (aAreaname)
       
  2211         {
       
  2212         case EAknsSrvItemDefArea:
       
  2213             size = chunkbase[EAknsSrvItemDefAreaAllocatedSizeOffset];
       
  2214             return size;
       
  2215         case EAknsSrvDataArea:
       
  2216             size = chunkbase[EAknsSrvDataAreaAllocatedSizeOffset];
       
  2217             return size;
       
  2218         case EAknsSrvFilenameArea:
       
  2219             size = chunkbase[EAknsSrvFilenameAreaAllocatedSizeOffset];
       
  2220             return size;
       
  2221         case EAknsSrvScalableGfxArea:
       
  2222             size = chunkbase[EAknsSrvScalableGfxAreaAllocatedSizeOffset];
       
  2223             return size;
       
  2224         case EAknsSrvItemDefHash:
       
  2225             size = chunkbase[EAknsSrvItemDefHashAllocatedSizeOffset];
       
  2226             return size;
       
  2227         default:
       
  2228             return 0;
       
  2229         }
       
  2230     }
       
  2231 
       
  2232 // -----------------------------------------------------------------------------
       
  2233 // CAknsSrvChunkMaintainer::GetAreaCurrentSize
       
  2234 // -----------------------------------------------------------------------------
       
  2235 //
       
  2236 TInt CAknsSrvChunkMaintainer::GetAreaCurrentSize(
       
  2237     TAknsSrvBaseAreaName aAreaname )
       
  2238     {
       
  2239     TInt* chunkbase = (TInt*)(iSharedChunk.Base());
       
  2240     TInt count = 0;
       
  2241     switch (aAreaname)
       
  2242         {
       
  2243         case EAknsSrvItemDefArea:
       
  2244             count = chunkbase[EAknsSrvItemDefAreaCurrentSizeOffset];
       
  2245             return count;
       
  2246         case EAknsSrvDataArea:
       
  2247             count = chunkbase[EAknsSrvDataAreaCurrentSizeOffset];
       
  2248             return count;
       
  2249         case EAknsSrvFilenameArea:
       
  2250             count = chunkbase[EAknsSrvFilenameAreaCurrentSizeOffset];
       
  2251             return count;
       
  2252         case EAknsSrvScalableGfxArea:
       
  2253             count = chunkbase[EAknsSrvScalableGfxAreaCurrentSizeOffset];
       
  2254             return count;
       
  2255         default:
       
  2256             return 0;
       
  2257         }
       
  2258     }
       
  2259 
       
  2260 // -----------------------------------------------------------------------------
       
  2261 // CAknsSrvChunkMaintainer::AdjustAreaAllocatedSize
       
  2262 // -----------------------------------------------------------------------------
       
  2263 //
       
  2264 void CAknsSrvChunkMaintainer::AdjustAreaAllocatedSize(
       
  2265     TAknsSrvBaseAreaName aAreaname, TInt aNewSize )
       
  2266     {
       
  2267     TInt* chunkbase = (TInt*)(iSharedChunk.Base());
       
  2268 
       
  2269     TInt areaallocatedsize = GetAreaAllocatedSize(aAreaname);
       
  2270     TInt totalallocatedareasize = GetAreaAllocatedSize(EAknsSrvItemDefArea)
       
  2271         + GetAreaAllocatedSize(EAknsSrvDataArea)
       
  2272         + GetAreaAllocatedSize(EAknsSrvFilenameArea)
       
  2273         + GetAreaAllocatedSize(EAknsSrvScalableGfxArea)
       
  2274         + GetAreaAllocatedSize(EAknsSrvItemDefHash)
       
  2275         + KAknsSrvSharedChunkHeaderAreaSize;
       
  2276 
       
  2277     if (areaallocatedsize <= aNewSize)
       
  2278         {
       
  2279         TInt chunksize = iSharedChunk.Size();
       
  2280         if ( totalallocatedareasize
       
  2281             > KAknsSrvSharedChunkMaxSize - KAknsSrvSharedChunkGranularity  )
       
  2282             {
       
  2283             // Tough luck, we cannot adjust the chunk size past
       
  2284             // KAknsSrvSharedChunkMaxSize, just cross our fingers and
       
  2285             // hope that everything fits in the chunk...
       
  2286             return;
       
  2287             }
       
  2288         if ( (totalallocatedareasize+KAknsSrvSharedChunkGranularity)
       
  2289             >= chunksize )
       
  2290             {
       
  2291             TInt err = iSharedChunk.Adjust( chunksize +
       
  2292                 KAknsSrvSharedChunkGranularity );
       
  2293             if (err)
       
  2294                 {
       
  2295                 AKNS_TRACE_ERROR("CAknsSrvChunkMaintainer::AdjustAreaAllocatedSize CANNOT ADJUST!");
       
  2296                 User::Panic(KAknSkinSrvPanicCategory, EAknsSrvCannotAdjustChunk );
       
  2297                 }
       
  2298             }
       
  2299 
       
  2300         TInt len = 0;
       
  2301         TInt8* source = 0;
       
  2302         TInt8* target = 0;
       
  2303 
       
  2304         switch (aAreaname)
       
  2305             {
       
  2306             case EAknsSrvItemDefArea:
       
  2307                 chunkbase[EAknsSrvItemDefAreaAllocatedSizeOffset] =
       
  2308                     chunkbase[EAknsSrvItemDefAreaAllocatedSizeOffset]
       
  2309                     + KAknsSrvSharedChunkGranularity;
       
  2310                 // move dataarea, filenamearea and scalablegfxarea
       
  2311                 // KAknsSrvSharedChunkGranularity bytes down...
       
  2312                 source = GetAreaBasePtr(EAknsSrvDataArea);
       
  2313                 target = source+KAknsSrvSharedChunkGranularity;
       
  2314                 len = GetAreaAllocatedSize(EAknsSrvDataArea)
       
  2315                     + GetAreaAllocatedSize(EAknsSrvFilenameArea)
       
  2316                     + GetAreaAllocatedSize(EAknsSrvScalableGfxArea);
       
  2317                 Mem::Move(target, source, len);
       
  2318                 chunkbase[EAknsSrvDataAreaBaseOffset] =
       
  2319                     chunkbase[EAknsSrvDataAreaBaseOffset]
       
  2320                     + KAknsSrvSharedChunkGranularity;
       
  2321                 chunkbase[EAknsSrvFilenameAreaBaseOffset] =
       
  2322                     chunkbase[EAknsSrvFilenameAreaBaseOffset]
       
  2323                     + KAknsSrvSharedChunkGranularity;
       
  2324                 chunkbase[EAknsSrvScalableGfxAreaBaseOffset] =
       
  2325                     chunkbase[EAknsSrvScalableGfxAreaBaseOffset]
       
  2326                     + KAknsSrvSharedChunkGranularity;
       
  2327                 break;
       
  2328             case EAknsSrvDataArea:
       
  2329                 chunkbase[EAknsSrvDataAreaAllocatedSizeOffset] =
       
  2330                     chunkbase[EAknsSrvDataAreaAllocatedSizeOffset]
       
  2331                     + KAknsSrvSharedChunkGranularity;
       
  2332                 // move filenamearea and scalablegfxarea
       
  2333                 // KAknsSrvSharedChunkGranularity bytes down
       
  2334                 source = GetAreaBasePtr(EAknsSrvFilenameArea);
       
  2335                 target = source+KAknsSrvSharedChunkGranularity;
       
  2336                 len = GetAreaAllocatedSize(EAknsSrvFilenameArea)
       
  2337                     + GetAreaAllocatedSize(EAknsSrvScalableGfxArea);
       
  2338                 Mem::Move(target, source, len);
       
  2339                 chunkbase[EAknsSrvFilenameAreaBaseOffset] =
       
  2340                     chunkbase[EAknsSrvFilenameAreaBaseOffset]
       
  2341                     + KAknsSrvSharedChunkGranularity;
       
  2342                 chunkbase[EAknsSrvScalableGfxAreaBaseOffset] =
       
  2343                     chunkbase[EAknsSrvScalableGfxAreaBaseOffset]
       
  2344                     + KAknsSrvSharedChunkGranularity;
       
  2345                 break;
       
  2346             case EAknsSrvFilenameArea:
       
  2347                 chunkbase[EAknsSrvFilenameAreaAllocatedSizeOffset] =
       
  2348                     chunkbase[EAknsSrvFilenameAreaAllocatedSizeOffset]
       
  2349                     + KAknsSrvSharedChunkGranularity;
       
  2350                 // move scalablegfxarea KAknsSrvSharedChunkGranularity bytes down
       
  2351                 source = GetAreaBasePtr(EAknsSrvScalableGfxArea);
       
  2352                 target = source+KAknsSrvSharedChunkGranularity;
       
  2353                 len = GetAreaAllocatedSize(EAknsSrvScalableGfxArea);
       
  2354                 Mem::Move(target,source,len);
       
  2355                 chunkbase[EAknsSrvScalableGfxAreaBaseOffset] =
       
  2356                     chunkbase[EAknsSrvScalableGfxAreaBaseOffset]
       
  2357                     + KAknsSrvSharedChunkGranularity;
       
  2358                 break;
       
  2359             case EAknsSrvScalableGfxArea:
       
  2360                 // the size of this area is static, no need to adjust it
       
  2361                 break;
       
  2362             default:
       
  2363                 break;
       
  2364             }
       
  2365         }
       
  2366     }
       
  2367 
       
  2368 // -----------------------------------------------------------------------------
       
  2369 // CAknsSrvChunkMaintainer::SetAreaCurrentSize
       
  2370 // -----------------------------------------------------------------------------
       
  2371 //
       
  2372 void CAknsSrvChunkMaintainer::SetAreaCurrentSize(
       
  2373     TAknsSrvBaseAreaName aAreaname, TInt aNewSize )
       
  2374     {
       
  2375     TUint misalign = aNewSize&3;
       
  2376     TUint newValue = aNewSize;
       
  2377     if( misalign )
       
  2378         {
       
  2379         newValue += (4-misalign);
       
  2380         }
       
  2381 
       
  2382     __ASSERT_DEBUG( newValue%4==0,
       
  2383         User::Panic( KAknSkinSrvPanicCategory, EAknsSrvBadAlignment ) );
       
  2384 
       
  2385     AdjustAreaAllocatedSize( aAreaname, newValue );
       
  2386     TInt* chunkbase = (TInt*)(iSharedChunk.Base());
       
  2387     switch (aAreaname)
       
  2388         {
       
  2389         case EAknsSrvItemDefArea:
       
  2390             chunkbase[EAknsSrvItemDefAreaCurrentSizeOffset] = newValue;
       
  2391             break;
       
  2392         case EAknsSrvDataArea:
       
  2393             chunkbase[EAknsSrvDataAreaCurrentSizeOffset] = newValue;
       
  2394             break;
       
  2395         case EAknsSrvFilenameArea:
       
  2396             chunkbase[EAknsSrvFilenameAreaCurrentSizeOffset] = newValue;
       
  2397             break;
       
  2398         case EAknsSrvScalableGfxArea:
       
  2399             chunkbase[EAknsSrvScalableGfxAreaCurrentSizeOffset] = newValue;
       
  2400             break;
       
  2401         default:
       
  2402             break;
       
  2403         }
       
  2404     }
       
  2405 
       
  2406 // -----------------------------------------------------------------------------
       
  2407 // CAknsSrvChunkMaintainer::InitializeChunk
       
  2408 // -----------------------------------------------------------------------------
       
  2409 //
       
  2410 void CAknsSrvChunkMaintainer::InitializeChunk()
       
  2411     {
       
  2412     iCurrentFilenameID = 0;
       
  2413     Mem::FillZ(iSharedChunk.Base(), iSharedChunk.Size());
       
  2414     TInt* chunkbase = (TInt*)iSharedChunk.Base();
       
  2415     
       
  2416     chunkbase[EAknsSrvItemDefHashBaseOffset] =
       
  2417         KAknsSrvSharedChunkHeaderAreaSize;
       
  2418     chunkbase[EAknsSrvItemDefHashAllocatedSizeOffset] =
       
  2419         KAknsSrvMaxHashSize-KAknsSrvSharedChunkHeaderAreaSize;
       
  2420     chunkbase[EAknsSrvItemDefHashCurrentSizeOffset] = 0;
       
  2421 
       
  2422     Mem::Fill( GetAreaBasePtr(EAknsSrvItemDefHash), 
       
  2423             (KAknsSrvMaxHashSize-KAknsSrvSharedChunkHeaderAreaSize), 0xFF );
       
  2424     
       
  2425     chunkbase[EAknsSrvItemDefAreaBaseOffset] =
       
  2426         KAknsSrvMaxHashSize;
       
  2427     chunkbase[EAknsSrvItemDefAreaAllocatedSizeOffset] =
       
  2428         12*KAknsSrvSharedChunkGranularity - KAknsSrvMaxHashSize; //48k -1k 
       
  2429     chunkbase[EAknsSrvItemDefAreaCurrentSizeOffset] = 0;
       
  2430     
       
  2431     chunkbase[EAknsSrvDataAreaBaseOffset] = 12*KAknsSrvSharedChunkGranularity;
       
  2432     chunkbase[EAknsSrvDataAreaAllocatedSizeOffset] =
       
  2433         20*KAknsSrvSharedChunkGranularity; //80k
       
  2434     chunkbase[EAknsSrvDataAreaCurrentSizeOffset] = 0;
       
  2435     
       
  2436     chunkbase[EAknsSrvFilenameAreaBaseOffset] =
       
  2437         32*KAknsSrvSharedChunkGranularity;
       
  2438     chunkbase[EAknsSrvFilenameAreaAllocatedSizeOffset] =
       
  2439         KAknsSrvSharedChunkGranularity;
       
  2440     chunkbase[EAknsSrvFilenameAreaCurrentSizeOffset] = 0;
       
  2441     
       
  2442     chunkbase[EAknsSrvScalableGfxAreaBaseOffset] =
       
  2443         33*KAknsSrvSharedChunkGranularity;
       
  2444     chunkbase[EAknsSrvScalableGfxAreaAllocatedSizeOffset] =
       
  2445         KAknsSrvSharedChunkGranularity;
       
  2446     chunkbase[EAknsSrvScalableGfxAreaCurrentSizeOffset] = 0;
       
  2447 
       
  2448     TInt committed = iSharedChunk.Size();
       
  2449     if (committed > KAknsSrvSharedChunkInitialSize)
       
  2450         {
       
  2451 #if defined(_DEBUG)
       
  2452         TInt err =
       
  2453 #endif
       
  2454             iSharedChunk.Adjust( KAknsSrvSharedChunkInitialSize );
       
  2455 #if defined(_DEBUG)
       
  2456         AKNS_TRACE_ERROR("AknSkinSrv could not reduce shared memory chunk size");
       
  2457 #endif
       
  2458         }
       
  2459     }
       
  2460 
       
  2461 // -----------------------------------------------------------------------------
       
  2462 // CAknsSrvChunkMaintainer::AlignToFour
       
  2463 // -----------------------------------------------------------------------------
       
  2464 //
       
  2465 TInt CAknsSrvChunkMaintainer::AlignToFour(const TInt aValue)
       
  2466     {
       
  2467     TInt misalign = aValue&3;
       
  2468     TInt newValue = aValue;
       
  2469     if( misalign )
       
  2470         {
       
  2471         newValue += (4-misalign);
       
  2472         }
       
  2473 
       
  2474     __ASSERT_DEBUG( newValue%4==0,
       
  2475         User::Panic( KAknSkinSrvPanicCategory, EAknsSrvBadAlignment ) );
       
  2476     return newValue;
       
  2477     }
       
  2478 
       
  2479 // End of file