idlehomescreen/xmluirendering/uiengine/src/xnproperty.cpp
changeset 0 f72a12da539e
child 2 08c6ee43b396
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Xuikon property source
       
    15 *
       
    16 */
       
    17 
       
    18 //  INCLUDE FILES
       
    19 #include "xnproperty.h"
       
    20 #include "xndomproperty.h"
       
    21 #include "xndompropertyvalue.h"
       
    22 #include "xndomlist.h"
       
    23 #include "xndomstringpool.h"
       
    24 #include <utf.h>
       
    25 #include <gdi.h>
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CXnProperty::NewL
       
    31 // Two-phased constructor.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 EXPORT_C CXnProperty* CXnProperty::NewL( CXnDomProperty* aProperty )
       
    35     {
       
    36     CXnProperty* self = new ( ELeave ) CXnProperty;
       
    37 
       
    38     CleanupStack::PushL( self );
       
    39 
       
    40     self->ConstructL( aProperty );
       
    41 
       
    42     CleanupStack::Pop( self );
       
    43 
       
    44     return self;
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CXnProperty::NewL
       
    49 // Two-phased constructor.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 EXPORT_C CXnProperty* CXnProperty::NewL( const TDesC8& aName,
       
    53     CXnDomPropertyValue* aPropertyValue, CXnDomStringPool& aStringPool )
       
    54     {
       
    55     CXnProperty* self = new ( ELeave ) CXnProperty;
       
    56 
       
    57     CleanupStack::PushL( self );
       
    58 
       
    59     self->ConstructL( aName, aPropertyValue, aStringPool );
       
    60 
       
    61     CleanupStack::Pop( self );
       
    62 
       
    63     return self;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CXnProperty::NewL
       
    68 // Two-phased constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CXnProperty* CXnProperty::NewL( const TDesC8& aPropertyName,
       
    72     const TDesC8& aPropertyValue,
       
    73     CXnDomPropertyValue::TPrimitiveValueType aValueType,
       
    74     CXnDomStringPool& aStringPool )
       
    75     {
       
    76     CXnProperty* self = new ( ELeave ) CXnProperty;
       
    77     CleanupStack::PushL( self );
       
    78 
       
    79     self->ConstructL( aPropertyName, aPropertyValue, aValueType, aStringPool );
       
    80 
       
    81     CleanupStack::Pop( self );
       
    82 
       
    83     return self;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CXnProperty::NewL
       
    88 // Two-phased constructor.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 EXPORT_C CXnProperty* CXnProperty::NewL( const TDesC8& aPropertyName,
       
    92     TReal aPropertyValue,
       
    93     CXnDomPropertyValue::TPrimitiveValueType aValueType,
       
    94     CXnDomStringPool& aStringPool )
       
    95     {
       
    96     CXnProperty* self = new ( ELeave ) CXnProperty;
       
    97     CleanupStack::PushL( self );
       
    98 
       
    99     self->ConstructL( aPropertyName, aPropertyValue, aValueType, aStringPool );
       
   100 
       
   101     CleanupStack::Pop( self );
       
   102 
       
   103     return self;
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CXnProperty::NewSharedL
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 CXnProperty* CXnProperty::NewSharedL( CXnDomProperty* aProperty )
       
   111     {
       
   112     CXnProperty* self = new ( ELeave ) CXnProperty;
       
   113 
       
   114     CleanupStack::PushL( self );
       
   115 
       
   116     self->ConstructSharedL( aProperty );
       
   117 
       
   118     CleanupStack::Pop( self );
       
   119 
       
   120     return self;
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CXnProperty::~CXnProperty
       
   125 // Destructor
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 CXnProperty::~CXnProperty()
       
   129     {
       
   130     if ( iIsDomPropertyOwned )
       
   131         {
       
   132         delete iProperty;
       
   133         }
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CXnProperty::CXnProperty
       
   138 // C++ default constructor can NOT contain any code, that
       
   139 // might leave.
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 CXnProperty::CXnProperty()
       
   143     {
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CXnProperty::ConstructL
       
   148 // Symbian 2nd phase constructor can leave.
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void CXnProperty::ConstructL( CXnDomProperty* aProperty )
       
   152     {
       
   153     iProperty = aProperty;
       
   154     iIsDomPropertyOwned = ETrue;
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CXnProperty::ConstructL
       
   159 // Symbian 2nd phase constructor can leave.
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CXnProperty::ConstructL( const TDesC8& aName,
       
   163     CXnDomPropertyValue* aPropertyValue, CXnDomStringPool& aStringPool )
       
   164     {
       
   165     iProperty = CXnDomProperty::NewL( aName, aStringPool );
       
   166     iIsDomPropertyOwned = ETrue;
       
   167 
       
   168     CXnDomList& propertyValueList = iProperty->PropertyValueList();
       
   169     propertyValueList.AddItemL( aPropertyValue );
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CXnProperty::ConstructL
       
   174 // Symbian 2nd phase constructor can leave.
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CXnProperty::ConstructL( const TDesC8& aPropertyName,
       
   178     const TDesC8& aPropertyValue,
       
   179     CXnDomPropertyValue::TPrimitiveValueType aValueType,
       
   180     CXnDomStringPool& aStringPool )
       
   181     {
       
   182     iProperty = CXnDomProperty::NewL( aPropertyName, aStringPool );
       
   183     iIsDomPropertyOwned = ETrue;
       
   184 
       
   185     CXnDomPropertyValue* newValue = CXnDomPropertyValue::NewL( aStringPool );
       
   186     CleanupStack::PushL( newValue );
       
   187 
       
   188     newValue->SetStringValueL( aValueType, aPropertyValue );
       
   189 
       
   190     CXnDomList& propertyValueList( iProperty->PropertyValueList() );
       
   191 
       
   192     propertyValueList.AddItemL( newValue );
       
   193 
       
   194     CleanupStack::Pop( newValue );
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CXnProperty::ConstructL
       
   199 // Symbian 2nd phase constructor can leave.
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CXnProperty::ConstructL( const TDesC8& aPropertyName,
       
   203     TReal aPropertyValue,
       
   204     CXnDomPropertyValue::TPrimitiveValueType aValueType,
       
   205     CXnDomStringPool& aStringPool )
       
   206     {
       
   207     iProperty = CXnDomProperty::NewL( aPropertyName, aStringPool );
       
   208     iIsDomPropertyOwned = ETrue;
       
   209 
       
   210     CXnDomPropertyValue* newValue = CXnDomPropertyValue::NewL( aStringPool );
       
   211     CleanupStack::PushL( newValue );
       
   212 
       
   213     newValue->SetFloatValueL( aValueType, aPropertyValue );
       
   214 
       
   215     CXnDomList& propertyValueList( iProperty->PropertyValueList() );
       
   216 
       
   217     propertyValueList.AddItemL( newValue );
       
   218 
       
   219     CleanupStack::Pop( newValue );
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CXnProperty::ConstructSharedL
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 void CXnProperty::ConstructSharedL( CXnDomProperty* aProperty )
       
   227     {
       
   228     iProperty = aProperty;
       
   229     iIsDomPropertyOwned = EFalse;
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CXnProperty::EqualsL
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 EXPORT_C TBool CXnProperty::EqualsL( CXnProperty& aProperty ) const
       
   237     {
       
   238     TBool equals( EFalse );
       
   239 
       
   240     if ( aProperty.Property()->PseudoClass() != iProperty->PseudoClass() )
       
   241         {
       
   242         return equals;
       
   243         }
       
   244 
       
   245     if ( aProperty.Property()->Name() != iProperty->Name() )
       
   246         {
       
   247         return equals;
       
   248         }
       
   249 
       
   250     CXnDomPropertyValue* value1 = static_cast< CXnDomPropertyValue* >(
       
   251         iProperty->PropertyValueList().Item( 0 ) );
       
   252     CXnDomPropertyValue::TPrimitiveValueType primitiveValueType1 =
       
   253         value1->PrimitiveValueType();
       
   254 
       
   255     CXnDomPropertyValue* value2 = static_cast< CXnDomPropertyValue* >(
       
   256         aProperty.Property()->PropertyValueList().Item( 0 ) );
       
   257     CXnDomPropertyValue::TPrimitiveValueType primitiveValueType2 =
       
   258         value2->PrimitiveValueType();
       
   259 
       
   260     switch ( primitiveValueType1 )
       
   261         {
       
   262         case CXnDomPropertyValue::ENumber:
       
   263         case CXnDomPropertyValue::EPercentage:
       
   264         case CXnDomPropertyValue::EEms:
       
   265         case CXnDomPropertyValue::EExs:
       
   266         case CXnDomPropertyValue::EPx:
       
   267         case CXnDomPropertyValue::ECm:
       
   268         case CXnDomPropertyValue::EMm:
       
   269         case CXnDomPropertyValue::EIn:
       
   270         case CXnDomPropertyValue::EPt:
       
   271         case CXnDomPropertyValue::EPc:
       
   272         case CXnDomPropertyValue::EDeg:
       
   273         case CXnDomPropertyValue::ERad:
       
   274         case CXnDomPropertyValue::EGrad:
       
   275         case CXnDomPropertyValue::EMs:
       
   276         case CXnDomPropertyValue::ES:
       
   277         case CXnDomPropertyValue::EHz:
       
   278         case CXnDomPropertyValue::EKHz:
       
   279         case CXnDomPropertyValue::EUnitValue:
       
   280             if ( primitiveValueType1 == primitiveValueType2 )
       
   281                 {
       
   282                 equals = ( value1->FloatValueL() == value2->FloatValueL() );
       
   283                 }
       
   284             break;
       
   285         case CXnDomPropertyValue::EString:
       
   286         case CXnDomPropertyValue::EIdent:
       
   287         case CXnDomPropertyValue::EUri:
       
   288         case CXnDomPropertyValue::EAttr:
       
   289         case CXnDomPropertyValue::EUnknown:
       
   290             if ( primitiveValueType2 == CXnDomPropertyValue::EString ||
       
   291                  primitiveValueType2 == CXnDomPropertyValue::EIdent ||
       
   292                  primitiveValueType2 == CXnDomPropertyValue::EUri ||
       
   293                  primitiveValueType2 == CXnDomPropertyValue::EAttr ||
       
   294                  primitiveValueType2 == CXnDomPropertyValue::EUnknown )
       
   295                 {
       
   296                 equals = ( value1->StringValueL() == value2->StringValueL() );
       
   297                 }
       
   298             break;
       
   299         case CXnDomPropertyValue::ERgbColor:
       
   300         case CXnDomPropertyValue::ERgbaColor:
       
   301             if ( primitiveValueType1 == primitiveValueType2 )
       
   302                 {
       
   303                 TRgb rgb1( value1->RgbColorValueL() );
       
   304                 TRgb rgb2( value2->RgbColorValueL() );
       
   305 
       
   306                 equals = ( rgb1 == rgb2 );
       
   307                 }
       
   308             break;
       
   309         default:
       
   310             break;
       
   311         }
       
   312 
       
   313     return equals;
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CXnProperty::Property
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 EXPORT_C CXnDomProperty* CXnProperty::Property()
       
   321     {
       
   322     return iProperty;
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // CXnProperty::StringValueL
       
   327 // -----------------------------------------------------------------------------
       
   328 //
       
   329 EXPORT_C HBufC* CXnProperty::StringValueL()
       
   330     {
       
   331     CXnDomPropertyValue* value = static_cast< CXnDomPropertyValue* >(
       
   332         iProperty->PropertyValueList().Item( 0 ) );
       
   333     const TDesC8& name = StringValue();
       
   334     HBufC* utfName = HBufC::NewL( name.Length() );
       
   335     TPtr16 ptr = utfName->Des();
       
   336     CnvUtfConverter::ConvertToUnicodeFromUtf8( ptr, name );
       
   337     return utfName;
       
   338     }
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // CXnProperty::StringValue
       
   342 // -----------------------------------------------------------------------------
       
   343 //
       
   344 EXPORT_C const TDesC8& CXnProperty::StringValue()
       
   345     {
       
   346     CXnDomPropertyValue* value = static_cast< CXnDomPropertyValue* >(
       
   347         iProperty->PropertyValueList().Item( 0 ) );
       
   348     return value->StringValue();
       
   349     }
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 // CXnProperty::FloatValueL
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 EXPORT_C TReal CXnProperty::FloatValueL()
       
   356     {
       
   357     CXnDomPropertyValue* value = static_cast< CXnDomPropertyValue* >(
       
   358         iProperty->PropertyValueList().Item( 0 ) );
       
   359     return value->FloatValueL();
       
   360     }
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // CXnProperty::CloneL
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 EXPORT_C CXnProperty* CXnProperty::CloneL()
       
   367     {
       
   368     CXnDomProperty* property = iProperty->CloneL();
       
   369     CleanupStack::PushL( property );
       
   370     CXnProperty* returnValue = CXnProperty::NewL( property );
       
   371     CleanupStack::Pop( property );
       
   372     return returnValue;
       
   373     }