uifw/EikStd/coctlsrc/aknresourceprovider.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2008-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:  Resource provider
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "aknresourceprovider.h"
       
    20 #include "aknresourceitem.h"
       
    21 
       
    22 
       
    23 // ======== MEMBER FUNCTIONS ========
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // Two-phased constructor.
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 CAknResourceProvider* CAknResourceProvider::NewL()
       
    30     {
       
    31     CAknResourceProvider* self = new ( ELeave ) CAknResourceProvider;
       
    32     return self;
       
    33     }
       
    34 
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // Destructor.
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CAknResourceProvider::~CAknResourceProvider()
       
    41     {
       
    42     iResourceArray.ResetAndDestroy();
       
    43     }
       
    44 
       
    45 
       
    46 // ----------------------------------------------------------------------------
       
    47 // Returns a resource item duplicate by the resource item id.
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 TInt CAknResourceProvider::GetResourceL( TUint aId,
       
    51                                         MAknResourceItem*& aResource )
       
    52     {
       
    53     for ( int i = 0; i < iResourceArray.Count(); i++ )
       
    54         {
       
    55         if ( iResourceArray[i]->Id() == aId )
       
    56             {
       
    57             aResource = iResourceArray[i]->DuplicateL();
       
    58             return aId;
       
    59             }
       
    60         }
       
    61     return KErrNotFound;
       
    62     }
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Handles resource changes, for example layout and skin changes.
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CAknResourceProvider::HandleResourceChange( TInt aType )
       
    70     {
       
    71     for ( int i = 0; i < iResourceArray.Count(); i++ )
       
    72         {
       
    73         if ( iResourceArray[i]->Invalidate( aType ) )
       
    74             {
       
    75             DeleteResourceByIndex( i );
       
    76             }
       
    77         }
       
    78     }
       
    79 
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // Adds the given resource item to the resource array. If there
       
    83 // exists a resource item with the same id in the array, it is first removed.
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CAknResourceProvider::SetResourceL( TUint aId, 
       
    87                                         const MAknResourceItem* aResource )
       
    88     {
       
    89     for ( int i = 0; i < iResourceArray.Count(); i++ )
       
    90         {
       
    91         if ( iResourceArray[i]->Id() == aId )
       
    92             {
       
    93             DeleteResourceByIndex( i );
       
    94             }
       
    95         }
       
    96     iResourceArray.AppendL( aResource );
       
    97     }
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // C++ default constructor can NOT contain any code that might leave.
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 CAknResourceProvider::CAknResourceProvider()
       
   105     {
       
   106     // No implementation required
       
   107     }
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // Deletes a resource item in the resource array by the specified index.
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CAknResourceProvider::DeleteResourceByIndex( TUint aIndex )
       
   115     {
       
   116     if ( aIndex < iResourceArray.Count() )
       
   117         {
       
   118         MAknResourceItem* removeItem = iResourceArray[aIndex];
       
   119         iResourceArray.Remove( aIndex );
       
   120         delete removeItem;
       
   121         }
       
   122     }