idlehomescreen/xmluicontroller/src/csspropertymap.cpp
changeset 0 f72a12da539e
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  DOM property map
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "xnproperty.h"
       
    20 #include "xndomproperty.h"
       
    21 #include "xndompropertyvalue.h"
       
    22 #include "xndomlist.h"
       
    23 
       
    24 #include "csspropertymap.h"
       
    25 #include "aixmluiutils.h"
       
    26 
       
    27 using namespace AiXmlUiController;
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 CCssPropertyMap::CCssPropertyMap()
       
    32     {
       
    33     }
       
    34 
       
    35 CCssPropertyMap* CCssPropertyMap::NewL()
       
    36     {
       
    37     CCssPropertyMap* self = new( ELeave ) CCssPropertyMap;
       
    38     return self;
       
    39     }
       
    40 
       
    41 CCssPropertyMap::~CCssPropertyMap()
       
    42     {
       
    43     Reset();
       
    44     iElementMap.Close();
       
    45     }
       
    46 
       
    47 
       
    48 void CCssPropertyMap::StorePropertyValueL( const TDesC8& aElementId,
       
    49                                            CXnProperty& aProperty )
       
    50     {
       
    51     RDomPropertyValueMap* propertyMap = iElementMap.Find( aElementId );
       
    52     
       
    53     if ( !propertyMap )
       
    54         {
       
    55         // Create new entry
       
    56         propertyMap = new( ELeave ) RDomPropertyValueMap;
       
    57         
       
    58         CleanupStack::PushL( propertyMap );
       
    59         
       
    60         iElementMap.InsertL( aElementId.AllocLC(), propertyMap );
       
    61         
       
    62         CleanupStack::Pop( 2, propertyMap );
       
    63         }
       
    64         
       
    65     // Clone property value
       
    66     CXnDomProperty* property = aProperty.Property();
       
    67     CXnDomPropertyValue* value = static_cast< CXnDomPropertyValue* >(
       
    68                                             property->PropertyValueList().First() );
       
    69     LeaveIfNull( value, KErrArgument );
       
    70     
       
    71     value = value->CloneL();
       
    72     CleanupStack::PushL( value );
       
    73     
       
    74     // Store value
       
    75     propertyMap->InsertL( property->Name().AllocLC(), value );
       
    76     
       
    77     CleanupStack::Pop( 2, value );
       
    78     
       
    79     }
       
    80     
       
    81 CXnDomPropertyValue* CCssPropertyMap::FindPropertyValue( const TDesC8& aElementId,
       
    82                                                          const TDesC8& aName )
       
    83     {
       
    84     RDomPropertyValueMap* propertyMap = iElementMap.Find( aElementId );
       
    85     
       
    86     if ( !propertyMap )
       
    87         {
       
    88         return NULL;
       
    89         }
       
    90         
       
    91     return propertyMap->Find( aName );
       
    92     }
       
    93 
       
    94 void CCssPropertyMap::Reset()
       
    95     {
       
    96     TPtrHashMapIter< TDesC8, RDomPropertyValueMap > mapIter( iElementMap );
       
    97     mapIter.Reset();
       
    98     
       
    99     while ( mapIter.NextKey() )
       
   100         {
       
   101         // Reset map for current key
       
   102         RDomPropertyValueMap* map = const_cast< RDomPropertyValueMap* >( 
       
   103                                                     mapIter.CurrentValue() );
       
   104         map->ResetAndDestroy();
       
   105         
       
   106         // Delete current key and map
       
   107         delete mapIter.CurrentKey();
       
   108         delete map;
       
   109         
       
   110         // Remove map (pointer) for current key
       
   111         mapIter.RemoveCurrent();
       
   112         }
       
   113     
       
   114     }