idlehomescreen/xmluirendering/dom/src/xndomproperty.cpp
changeset 0 f72a12da539e
child 2 08c6ee43b396
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2005,2006 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:  Represents a Css property.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "xndomproperty.h"
       
    22 #include    "xndompropertyvalue.h"
       
    23 #include    "xndomlist.h"
       
    24 #include    "xndomstringpool.h"
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 // -----------------------------------------------------------------------------
       
    28 // CXnDomProperty::CXnDomProperty
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CXnDomProperty::CXnDomProperty( CXnDomStringPool& aStringPool ):
       
    34     iStringPool( aStringPool )
       
    35     {
       
    36     }
       
    37 // -----------------------------------------------------------------------------
       
    38 // CXnDomProperty::CXnDomProperty
       
    39 // C++ default constructor can NOT contain any code, that
       
    40 // might leave.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CXnDomProperty::CXnDomProperty( 
       
    44     TInt16 aStringPoolIndex, 
       
    45     CXnDomStringPool& aStringPool ):
       
    46     iStringPool( aStringPool ),
       
    47     iNameRef( aStringPoolIndex )
       
    48     {
       
    49     }    
       
    50 // -----------------------------------------------------------------------------
       
    51 // CXnDomProperty::ConstructL
       
    52 // Symbian 2nd phase constructor can leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 void CXnDomProperty::ConstructL( const TDesC8& aName )
       
    56     {
       
    57     iNameRef = iStringPool.AddStringL( aName );
       
    58     iPropValList = CXnDomList::NewL( CXnDomList::EPropertyValueList, iStringPool );
       
    59     }
       
    60 // -----------------------------------------------------------------------------
       
    61 // CXnDomProperty::ConstructL
       
    62 // Symbian 2nd phase constructor can leave.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void CXnDomProperty::ConstructL()
       
    66     {
       
    67     iPropValList = CXnDomList::NewL( CXnDomList::EPropertyValueList, iStringPool );
       
    68     }
       
    69 // -----------------------------------------------------------------------------
       
    70 // CXnDomProperty::NewL
       
    71 // Two-phased constructor.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C CXnDomProperty* CXnDomProperty::NewL( 
       
    75     const TDesC8& aName,
       
    76     CXnDomStringPool& aStringPool )
       
    77     {
       
    78     CXnDomProperty* self = new( ELeave ) CXnDomProperty( aStringPool );
       
    79     
       
    80     CleanupStack::PushL( self );
       
    81     self->ConstructL( aName );
       
    82     CleanupStack::Pop( self );
       
    83 
       
    84     return self;
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CXnDomProperty::NewL
       
    89 // Two-phased stream constructor.
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CXnDomProperty* CXnDomProperty::NewL( 
       
    93     RReadStream& aStream, 
       
    94     CXnDomStringPool& aStringPool )
       
    95     {
       
    96     CXnDomProperty* self = 
       
    97         new( ELeave ) CXnDomProperty( aStringPool );
       
    98     
       
    99     CleanupStack::PushL( self );
       
   100     
       
   101     aStream >> *self;
       
   102     CleanupStack::Pop( self );
       
   103 
       
   104     return self;
       
   105     }
       
   106 // -----------------------------------------------------------------------------
       
   107 // CXnDomProperty::NewL
       
   108 // Two-phased constructor.
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 EXPORT_C CXnDomProperty* CXnDomProperty::NewL( 
       
   112     TInt16 aStringPoolIndex,
       
   113     CXnDomStringPool& aStringPool )
       
   114     {
       
   115     CXnDomProperty* self = 
       
   116         new (ELeave) CXnDomProperty( aStringPoolIndex, aStringPool );
       
   117     CleanupStack::PushL( self );
       
   118     self->ConstructL();
       
   119     CleanupStack::Pop( self );
       
   120     return self;
       
   121     }       
       
   122 // Destructor
       
   123 EXPORT_C CXnDomProperty::~CXnDomProperty()
       
   124     {
       
   125     delete iPropValList;
       
   126     }
       
   127 // -----------------------------------------------------------------------------
       
   128 // CXnDomProperty::CloneL
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C CXnDomProperty* CXnDomProperty::CloneL()
       
   132     {
       
   133     CXnDomProperty* clone = new (ELeave)CXnDomProperty( iStringPool );
       
   134     CleanupStack::PushL(clone);
       
   135     
       
   136     clone->iPropValList = CXnDomList::NewL( CXnDomList::EPropertyValueList, iStringPool );
       
   137     clone->iNameRef = iNameRef;
       
   138     
       
   139     TInt count( iPropValList->Length() );
       
   140     for (TInt i = 0; i < count; ++i)
       
   141         {
       
   142         CXnDomPropertyValue* val = static_cast<CXnDomPropertyValue*>( iPropValList->Item(i) );
       
   143         CXnDomPropertyValue* cloneVal = val->CloneL();
       
   144         CleanupStack::PushL( cloneVal );
       
   145         clone->iPropValList->AddItemL( cloneVal );
       
   146         CleanupStack::Pop( cloneVal );
       
   147         }
       
   148     clone->iInherited = iInherited;
       
   149     clone->iPseudoClass = iPseudoClass;    
       
   150     CleanupStack::Pop(clone);
       
   151     return clone;
       
   152     }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CXnDomProperty::CloneL
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 EXPORT_C CXnDomProperty* CXnDomProperty::CloneL( CXnDomStringPool& aStringPool )
       
   159     {
       
   160     const TDesC8& name = iStringPool.String( iNameRef );
       
   161     CXnDomProperty* clone = CXnDomProperty::NewL( name, aStringPool );
       
   162     CleanupStack::PushL(clone);
       
   163     
       
   164     TInt count( iPropValList->Length() );
       
   165     for (TInt i = 0; i < count; ++i)
       
   166         {
       
   167         CXnDomPropertyValue* val = static_cast<CXnDomPropertyValue*>( iPropValList->Item(i) );
       
   168         CXnDomPropertyValue* cloneVal = val->CloneL( aStringPool );
       
   169         CleanupStack::PushL( cloneVal );
       
   170         clone->iPropValList->AddItemL( cloneVal );
       
   171         CleanupStack::Pop( cloneVal );
       
   172         }
       
   173     clone->iInherited = iInherited;
       
   174     clone->iPseudoClass = iPseudoClass;    
       
   175     CleanupStack::Pop(clone);
       
   176     return clone;
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CXnDomProperty::Name
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 EXPORT_C const TDesC8& CXnDomProperty::Name()
       
   184     {
       
   185     return iStringPool.String( iNameRef );
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CXnDomProperty::PropertyValue
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 EXPORT_C CXnDomList& CXnDomProperty::PropertyValueList()
       
   193     {
       
   194     return *iPropValList;
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CXnDomProperty::IsValueSet
       
   199 // -----------------------------------------------------------------------------
       
   200 //    
       
   201 EXPORT_C TBool CXnDomProperty::IsValueSet()
       
   202     {
       
   203     return (iPropValList->Length() > 0);
       
   204     }                  
       
   205            
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CXnDomProperty::Inherited
       
   209 // -----------------------------------------------------------------------------
       
   210 //    
       
   211 EXPORT_C TBool CXnDomProperty::Inherited()
       
   212     {
       
   213     return iInherited;
       
   214     }
       
   215 // -----------------------------------------------------------------------------
       
   216 // CXnDomProperty::SetInherited
       
   217 // -----------------------------------------------------------------------------
       
   218 //    
       
   219 EXPORT_C void CXnDomProperty::SetInherited( TBool aInherited )
       
   220     {
       
   221     iInherited = aInherited;
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CXnDomProperty::StringPool
       
   226 // -----------------------------------------------------------------------------
       
   227 //        
       
   228 EXPORT_C CXnDomStringPool& CXnDomProperty::StringPool() const
       
   229     {
       
   230     return iStringPool;
       
   231     }                      
       
   232 // -----------------------------------------------------------------------------
       
   233 // CXnDomProperty::StringPoolIndex
       
   234 // -----------------------------------------------------------------------------
       
   235 //        
       
   236 EXPORT_C TInt16 CXnDomProperty::StringPoolIndex()const
       
   237     {
       
   238     return iNameRef;    
       
   239     }
       
   240 // -----------------------------------------------------------------------------
       
   241 // CXnDomProperty::PseudoClass
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 EXPORT_C CXnDomProperty::TPseudoClass CXnDomProperty::PseudoClass() const
       
   245     {
       
   246     return iPseudoClass;
       
   247     }
       
   248     
       
   249 // -----------------------------------------------------------------------------
       
   250 // CXnDomProperty::SetPseudoClass
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 EXPORT_C void CXnDomProperty::SetPseudoClass( TPseudoClass aPseudoClass )
       
   254     {
       
   255     iPseudoClass = aPseudoClass;
       
   256     }       
       
   257         
       
   258 // -----------------------------------------------------------------------------
       
   259 // CXnDomProperty::Size
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 TInt CXnDomProperty::Size() const
       
   263     {
       
   264     TInt size( 0 );
       
   265     
       
   266     size += sizeof(TInt16); //iNameRef
       
   267     size += iPropValList->Size();
       
   268     size += sizeof(TInt8);    //iInherited
       
   269     size += sizeof(TInt8);  //iPseudoClass
       
   270     
       
   271     return size;    
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CXnDomProperty::ExternalizeL
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CXnDomProperty::ExternalizeL( RWriteStream& aStream ) const
       
   279     {
       
   280     aStream.WriteInt16L( iNameRef );
       
   281     aStream << *iPropValList;
       
   282     aStream.WriteInt8L( iInherited );
       
   283     aStream.WriteInt8L( iPseudoClass );   
       
   284     }
       
   285 // -----------------------------------------------------------------------------
       
   286 // CXnDomProperty::InternalizeL
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 void CXnDomProperty::InternalizeL( RReadStream& aStream )
       
   290     {
       
   291     iNameRef = aStream.ReadInt16L() + iStringPool.Offset();
       
   292     iPropValList = CXnDomList::NewL( aStream, iStringPool );
       
   293     
       
   294     iInherited =  TBool( aStream.ReadInt8L() );
       
   295     iPseudoClass = TPseudoClass( aStream.ReadInt8L() );
       
   296     }
       
   297 
       
   298 //  End of File