uifw/AvKon/src/AknIconArray.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "AknIconArray.h"  // This class
       
    21 #include <barsread.h>       // TResourceReader
       
    22 #include <fbs.h>            // CFbsBitmap
       
    23 #include <gulicon.h>        // CGulIcon
       
    24 #include <coemain.h>        // CCoeEnv
       
    25 #include <bautils.h>
       
    26 #include "avkon.hrh"
       
    27 #include "AknPanic.h"
       
    28 
       
    29 #include <AknIconUtils.h>
       
    30 
       
    31 
       
    32 // LOCAL FUNCTION PROTOTYPES
       
    33 // ==================== LOCAL FUNCTIONS ====================
       
    34 
       
    35 
       
    36 // ================= MEMBER FUNCTIONS =======================
       
    37 
       
    38 EXPORT_C CAknIconArray::CAknIconArray(TInt aGranurality)
       
    39     : CArrayPtrFlat<CGulIcon>(aGranurality)
       
    40     {
       
    41     }
       
    42 
       
    43 EXPORT_C void CAknIconArray::ConstructFromResourceL(TInt aResId)
       
    44     {
       
    45     AppendFromResourceL(aResId);
       
    46     }
       
    47 
       
    48 EXPORT_C void CAknIconArray::ConstructFromResourceL(TResourceReader& aReader)
       
    49     {
       
    50     AppendFromResourceL(aReader);
       
    51     }
       
    52 
       
    53 EXPORT_C CAknIconArray::~CAknIconArray()
       
    54     {
       
    55     ResetAndDestroy();
       
    56     }
       
    57 
       
    58 EXPORT_C void CAknIconArray::AppendFromResourceL(TInt aResId)
       
    59     {
       
    60     TResourceReader reader;
       
    61     CCoeEnv::Static()->CreateResourceReaderLC(reader, aResId);
       
    62     AppendFromResourceL(reader);
       
    63     CleanupStack::PopAndDestroy();  // reader
       
    64     }
       
    65 
       
    66 EXPORT_C void CAknIconArray::AppendFromResourceL(TResourceReader& aReader)
       
    67     {
       
    68     TInt type = aReader.ReadInt16();
       
    69     switch (type)
       
    70 		{
       
    71 		case EAknIconArraySimple:
       
    72 		break; // go to the actual reader
       
    73 		case EAknIconArrayComplex:
       
    74 			{
       
    75 			TInt count_a = aReader.ReadInt16();
       
    76 			while(count_a-- > 0)
       
    77 				{
       
    78 				// recursive algorithm.	
       
    79 				AppendFromResourceL(aReader);
       
    80 				}
       
    81 			}
       
    82 			return;
       
    83 		default:
       
    84 		aReader.Rewind(2);
       
    85 
       
    86 		};
       
    87     
       
    88 
       
    89     // this reads AKN_ICON_ARRAY *except* the type field!
       
    90     HBufC* bmpName = GetBmpNameLC(aReader); 
       
    91 
       
    92     TInt count = aReader.ReadInt16();
       
    93     SetReserveL(Count() + count);
       
    94     while (count-- > 0)
       
    95         {
       
    96         TInt32 iconId = aReader.ReadInt32();
       
    97         TInt32 maskId = aReader.ReadInt32();
       
    98 
       
    99     	CFbsBitmap* bitmap;
       
   100         CFbsBitmap* mask;
       
   101 
       
   102         AknIconUtils::CreateIconLC( bitmap, mask, *bmpName, iconId, maskId );
       
   103 
       
   104         CGulIcon* icon = CGulIcon::NewL(bitmap, mask);
       
   105         CleanupStack::Pop(2);  // mask, bitmap
       
   106 
       
   107         // Following AppendL call cannot leave due to lack of memory because 
       
   108         // of SetReserveL above. This is why there is no need to push icon
       
   109         // on the cleanup stack.
       
   110         AppendL(icon);
       
   111         }
       
   112 
       
   113     CleanupStack::PopAndDestroy();  // bmpName
       
   114     }
       
   115 
       
   116 HBufC* CAknIconArray::GetBmpNameLC(TResourceReader& aReader)
       
   117     {
       
   118     HBufC* bmpName = aReader.ReadHBufCL();
       
   119     CleanupStack::PushL(bmpName);
       
   120 
       
   121     TBool drivePresent =
       
   122         (bmpName->Length() >= 3 &&
       
   123         (*bmpName)[1] == ':' &&
       
   124         (*bmpName)[2] == '\\' );
       
   125 
       
   126     RFs& fs = CCoeEnv::Static()->FsSession();
       
   127 
       
   128     TBool found = EFalse;
       
   129     if ( drivePresent )
       
   130         {
       
   131         found = BaflUtils::FileExists( fs, *bmpName );
       
   132         }
       
   133 
       
   134     // If drive letter is not specified, or not found in the specified drive,
       
   135     // FindByDir scans the drives in order E:, D:, C:, Z:
       
   136 
       
   137     if (!found)
       
   138         {
       
   139         TFindFile find( fs );
       
   140         if (find.FindByDir(*bmpName, KNullDesC) == KErrNone)
       
   141             {
       
   142             if (bmpName->Length() < find.File().Length())
       
   143                 {
       
   144                 bmpName = bmpName->ReAllocL(find.File().Length());
       
   145                 CleanupStack::Pop(); // old bmpName
       
   146                 CleanupStack::PushL( bmpName );
       
   147                 }
       
   148     
       
   149             *bmpName = find.File();
       
   150             }
       
   151         }
       
   152 
       
   153     return bmpName;
       
   154     }
       
   155 //  End of File  
       
   156