widgetmodel/alfwidgetmodel/src/alfimagevisualattributesetter.cpp
changeset 17 3eca7e70b1b8
parent 3 4526337fb576
equal deleted inserted replaced
3:4526337fb576 17:3eca7e70b1b8
     1 /*
       
     2 * Copyright (c) 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:   Implements attributesetters for image.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "alf/alfattribute.h"
       
    20 #include "alf/alfimagevisualattributesetter.h"
       
    21 #include "alf/alfattributevaluetype.h"
       
    22 #include <alf/alfvisual.h>
       
    23 #include <alf/alfattributeexception.h>
       
    24 #include <alf/alfvisualexception.h>
       
    25 #include "alf/alfattributecontainer.h"
       
    26 #include <libc/string.h>
       
    27 
       
    28 #include <uiacceltk/HuiRealPoint.h>
       
    29 
       
    30 #include <alf/alfimagevisual.h>
       
    31 #include <alf/alftexture.h>
       
    32 #include <utf.h>
       
    33 #include <alf/alfenv.h>
       
    34 #include <alf/alfdataexception.h>
       
    35 #include <alf/alfdisplay.h>
       
    36 #include <alf/alfutil.h>
       
    37 
       
    38 #include <alf/alfbrusharray.h>
       
    39 #include <alf/alfframebrush.h>
       
    40 
       
    41 
       
    42 #include <alf/alfeventhandler.h>
       
    43 #include <alf/alfevent.h>
       
    44 #include <osn/alfptrvector.h>
       
    45 #include <alf/alfresourcepool.h>
       
    46 #include <alf/alfmetric.h>
       
    47 #include <alf/alfwidgetenvextension.h>
       
    48 
       
    49 #include <osn/osnnew.h>
       
    50 #include <osn/ustring.h>
       
    51 #include <alf/attrproperty.h>
       
    52 
       
    53 using namespace osncore;
       
    54 
       
    55 using namespace duiuimodel::imagevisualattributes;
       
    56 using namespace duiuimodel::commonvisualattributes;
       
    57 using namespace duiuimodel::layoutattributes;
       
    58 
       
    59 namespace Alf
       
    60 {
       
    61 
       
    62 class AlfImageVisualAttributeSetterImpl
       
    63     {
       
    64 public:
       
    65     AlfImageVisualAttributeSetterImpl();
       
    66     ~AlfImageVisualAttributeSetterImpl();
       
    67 public:
       
    68     //Keep track of loaded texture for imagevisuals.
       
    69     //Texture manager doesn't unload the texture from memory untill Env is deleted.
       
    70     //Hence need to unload them once attribute setter is deleted.
       
    71     AlfPtrVector<CAlfTexture> mLoadedTextures;
       
    72     //Env needed to access TextureManager while unloading textures.
       
    73     CAlfEnv* mEnv;
       
    74 
       
    75     // Utility functions. Keep them static so whole class can become static in future
       
    76     TAlfImage createImageFromImagePath( const CAlfImageVisual& aImageVisual, const TPtrC8& aPath );
       
    77     TAlfImage createNonPoolImageFromSkinLogicalID(CAlfEnv& aEnv, const Utf8* aResourceRef, AlfAttributeContainer& aContainer);    
       
    78     };
       
    79 
       
    80 AlfImageVisualAttributeSetterImpl::AlfImageVisualAttributeSetterImpl()
       
    81     {
       
    82     //Do not delete textures here as they may be in use by the visuals that have not been deleted.
       
    83     mEnv = CAlfEnv::Static();
       
    84     mLoadedTextures.setAutoDelete(false);
       
    85     }
       
    86 
       
    87 AlfImageVisualAttributeSetterImpl::~AlfImageVisualAttributeSetterImpl()
       
    88     {
       
    89     //Unload all loaded textures created by this attributesetter to free up the memory.
       
    90     for (int i =0;i<mLoadedTextures.count();i++)
       
    91         {
       
    92         CAlfTexture* texture = mLoadedTextures[i];
       
    93         mEnv->TextureManager().UnloadTexture(texture->Id());
       
    94         }
       
    95     mLoadedTextures.clear();
       
    96 
       
    97     }
       
    98 
       
    99 // ======== MEMBER FUNCTIONS ========
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // Constructor.
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 OSN_EXPORT AlfImageVisualAttributeSetter::AlfImageVisualAttributeSetter()
       
   106     {
       
   107     mImpl.reset(new (EMM) AlfImageVisualAttributeSetterImpl());
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // Destructor.
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 OSN_EXPORT AlfImageVisualAttributeSetter::~AlfImageVisualAttributeSetter()
       
   115     {
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // Sets Attribute Value. Delegates based on attribute Category.
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 OSN_EXPORT void AlfImageVisualAttributeSetter::setAttributeValue (
       
   123     CAlfVisual &aVisual,
       
   124     AlfAttributeContainer* aContainer,
       
   125     IAlfMap* aData )
       
   126     {
       
   127     CAlfImageVisual* imageVisual = dynamic_cast<CAlfImageVisual*>(&aVisual);
       
   128     if (!imageVisual)
       
   129         {
       
   130         ALF_THROW ( AlfVisualException, EInvalidVisual, "AlfImageVisualAttributeSetter")
       
   131         }
       
   132 
       
   133     AlfCommonVisualAttributeSetter::setAttributeValue(aVisual,
       
   134             aContainer, aData);
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void AlfImageVisualAttributeSetter::handleDynamicDataAttribute(
       
   141     CAlfVisual& aVisual, AlfAttribute& aAttr,
       
   142     AlfAttributeContainer& aContainer, IAlfMap* aData)
       
   143     {
       
   144     AlfCommonVisualAttributeSetter::handleDynamicDataAttribute( aVisual, aAttr,
       
   145             aContainer, aData);
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void AlfImageVisualAttributeSetter::handleStaticDataAttribute(
       
   152     CAlfVisual &aVisual, AlfAttribute& aAttr,
       
   153     AlfAttributeContainer& aContainer, IAlfMap* aData)
       
   154     {
       
   155     if (!aData) ALF_THROW ( AlfDataException, EInvalidVariantDataType, "CAlfTextVisualAttributeSetter" )
       
   156 
       
   157         const char* dataField = aAttr.getDataField();
       
   158     if (!dataField) ALF_THROW ( AlfDataException, EInvalidAttribute, "CAlfTextVisualAttributeSetter" )
       
   159 
       
   160         IAlfVariantType* data = aData->item ( UString(dataField));
       
   161 
       
   162     const char* attrName = aAttr.name();
       
   163 
       
   164     if (data)
       
   165         {
       
   166         CAlfImageVisual* imageVisual = dynamic_cast<CAlfImageVisual*>(&aVisual);
       
   167         if(!imageVisual)
       
   168             {
       
   169             ALF_THROW ( AlfDataException, EInvalidVariantDataType, "CAlfTextVisualAttributeSetter" )
       
   170             }
       
   171 
       
   172         if (!strcmp(attrName,KImageScaleMode))
       
   173             {
       
   174             if (data->type() == IAlfVariantType::EInt)
       
   175                 {
       
   176                 int val = data->integer();
       
   177                 imageVisual->SetScaleMode(CAlfImageVisual::TScaleMode(val));
       
   178                 }
       
   179             }
       
   180         else if (!strcmp(attrName,KImageColorMode))
       
   181             {
       
   182             if (data->type() == IAlfVariantType::EInt)
       
   183                 {
       
   184                 int val = data->integer();
       
   185                 imageVisual->SetColorMode(CAlfImageVisual::TColorMode(val));
       
   186                 }
       
   187             }
       
   188         else if (!strcmp(attrName,KDropShadow))
       
   189             {
       
   190 
       
   191             // needs to have discussion about how to store unit in the data
       
   192 
       
   193             }
       
   194             
       
   195         else if (!strcmp(attrName, KImagePath))
       
   196             {
       
   197             if (data->type() == IAlfVariantType::EString)
       
   198                 {
       
   199                 TPtrC8 src;
       
   200                 src.Set((TUint8*)data->string().getUtf8());
       
   201                 HandleImagePathAttribute( src, imageVisual, true );
       
   202                 }
       
   203             }
       
   204 
       
   205         else if (!strcmp(attrName,KImageResourceRef))
       
   206             {
       
   207             if (data->type() == IAlfVariantType::EString)
       
   208                 {
       
   209                 TAlfImage image;
       
   210                 try
       
   211                     {
       
   212                 	image = AlfWidgetEnvExtension::resourcePool(aVisual.Env()).getImageResource(data->string().getUtf8());	
       
   213                     }
       
   214                 catch(invalid_argument &)
       
   215                     {
       
   216                   	ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfImageVisualAttributeSetter:: Image does not exist");
       
   217                     }
       
   218                 
       
   219                 if(image.HasTexture())
       
   220                     {
       
   221                     imageVisual->SetImage(image);
       
   222                     }
       
   223                 else
       
   224                     {
       
   225                     ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfImageVisualAttributeSetter:: Image does not exist");
       
   226                     }
       
   227                 }
       
   228             }
       
   229 
       
   230         else if (!strcmp(attrName,KSecondaryImagePath))
       
   231             {
       
   232             if (data->type() == IAlfVariantType::EString)
       
   233                 {
       
   234                 TPtrC8 src;
       
   235                 src.Set((TUint8*)data->string().getUtf8());
       
   236             
       
   237                 HandleImagePathAttribute( src, imageVisual, false );
       
   238                 }
       
   239             }
       
   240 
       
   241         else if (!strcmp(attrName,KSecondaryImageResourceRef))
       
   242             {
       
   243             if (data->type() == IAlfVariantType::EString)
       
   244                 {
       
   245                 TAlfImage image;
       
   246                 try
       
   247                     {
       
   248                 	image = AlfWidgetEnvExtension::resourcePool(aVisual.Env()).getImageResource(data->string().getUtf8());	
       
   249                     }
       
   250                 catch(invalid_argument &)
       
   251                     {
       
   252                   	ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfImageVisualAttributeSetter:: Image does not exist");
       
   253                     }
       
   254                 if(image.HasTexture())
       
   255                     {
       
   256                     imageVisual->SetSecondaryImage(image);
       
   257                     }
       
   258                 else
       
   259                     {
       
   260                     ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfImageVisualAttributeSetter:: Image does not exist");
       
   261                     }
       
   262                 }
       
   263             }
       
   264 
       
   265         else if (!strcmp(attrName,KSkinImagePath))
       
   266             {
       
   267             if (data->type() == IAlfVariantType::EString)
       
   268                 {
       
   269                 TAlfImage image;
       
   270                 try
       
   271                     {
       
   272                 	image = AlfWidgetEnvExtension::resourcePool(aVisual.Env()).getImageResource(data->string().getUtf8());	
       
   273                     }
       
   274                 catch(invalid_argument &)
       
   275                     {
       
   276                     // This image is not present in currently active Theme, 
       
   277                     // hence Resource Pool throws an exception
       
   278                     // which can be ignored and we will try to load it for first time.
       
   279                   	}
       
   280                 if(!image.HasTexture())
       
   281                     {
       
   282                     image = mImpl->createNonPoolImageFromSkinLogicalID( imageVisual->Env(), data->string().getUtf8(), aContainer);
       
   283                     }                	
       
   284                 imageVisual->SetImage(image);
       
   285                 }
       
   286 
       
   287             }
       
   288         else if (!strcmp(attrName,KAnimatedSkinImage))
       
   289             {  
       
   290             
       
   291             // Retrieve animation skin id
       
   292             
       
   293     		auto_ptr< HBufC> skinAnimId;
       
   294     		if (data->type() == IAlfVariantType::EString)
       
   295     			{    		
       
   296     			TPtrC8 src( (TUint8*) data->string().getUtf8() );    		
       
   297     			TRAPD(err,skinAnimId.reset(CnvUtfConverter::ConvertToUnicodeFromUtf8L(src)));
       
   298     		    	
       
   299     			if(err != KErrNone)
       
   300     				{
       
   301     				ALF_THROW ( AlfDataException, err, "AlfImageVisualAttributeSetter") 
       
   302     				}  			 
       
   303     	   
       
   304     	    	// loading the texture from animation id.            
       
   305        	    	TAlfImage skinAnimImage(imageVisual->Env().TextureManager().
       
   306        	   			           LoadAnimatedTextureL(*(skinAnimId.get()),
       
   307        	   						                    imageVisual->Env().PrimaryDisplay().VisibleArea().Size(),
       
   308        	   					 	                    EAlfTextureFlagDefault,
       
   309        	   					 	                    KAlfAutoGeneratedTextureId));
       
   310        	   
       
   311        	    	// setting the texture to imagevisual only if it exists.
       
   312        	    	if(skinAnimImage.HasTexture())
       
   313        	   			{
       
   314        	   			imageVisual->SetImage(skinAnimImage);
       
   315        	   			}
       
   316     			}
       
   317        	   			
       
   318             }
       
   319         else if (!strcmp(attrName,KSecondarySkinImagePath))
       
   320             {
       
   321             if (data->type() == IAlfVariantType::EString)
       
   322                 {
       
   323                 TAlfImage image;
       
   324                 try
       
   325                     {
       
   326                 	image = AlfWidgetEnvExtension::resourcePool(aVisual.Env()).getImageResource(data->string().getUtf8());	
       
   327                     }
       
   328                 catch(invalid_argument &)
       
   329                     {
       
   330                     // This image is not present in currently active Theme, 
       
   331                     // hence Resource Pool throws an exception
       
   332                     // which can be ignored and we will try to load it for first time.
       
   333                     }
       
   334                 if(!image.HasTexture())
       
   335                     {
       
   336                     image = mImpl->createNonPoolImageFromSkinLogicalID( imageVisual->Env(), data->string().getUtf8(), aContainer);
       
   337                     }                	
       
   338                 imageVisual->SetSecondaryImage(image);
       
   339                 }
       
   340             }
       
   341         else if(!strcmp(attrName,KSkinFrameImage))
       
   342             {
       
   343  		
       
   344     		if (data->type() == IAlfVariantType::EString)
       
   345                 {   		
       
   346     				
       
   347     			setFrameImage(aVisual,data->string().getUtf8(), aContainer,aData);    				
       
   348                 }    			
       
   349             }
       
   350         else if (!strcmp(attrName,KStretchMode))
       
   351             {
       
   352             if (data->type() == IAlfVariantType::EInt)
       
   353                 {
       
   354                 int val = data->integer();
       
   355                 imageVisual->SetStretchMode(CAlfGc::TStretchMode(val));
       
   356                 }
       
   357             }
       
   358         else if (!strcmp(attrName,KColor))
       
   359             {
       
   360             if (data->type() == IAlfVariantType::EContainer )
       
   361                 {
       
   362                 IAlfContainer* dataContainer = data->container();
       
   363 
       
   364                 if ( 4 != dataContainer -> count() ) ALF_THROW ( AlfDataException, EIncompleteAttributeValues, "AlfImageVisualAttributeSetter")
       
   365 
       
   366                     IAlfVariantType* red = dataContainer->item ( 0 ); //red
       
   367 
       
   368                 IAlfVariantType* green = dataContainer->item ( 1 ); //green
       
   369 
       
   370                 IAlfVariantType* blue = dataContainer->item ( 2 ); //blue
       
   371 
       
   372                 IAlfVariantType* alpha = dataContainer->item ( 3 ); //alpha
       
   373 
       
   374                 if ( red && IAlfVariantType::EInt == red->type() && green && IAlfVariantType::EInt == green->type() && blue && IAlfVariantType::EInt == blue->type() && alpha && IAlfVariantType::EInt == alpha->type() )
       
   375                     {
       
   376                     TRgb color ( red->integer(), green->integer(), blue->integer(), alpha->integer() );
       
   377                     imageVisual->SetColor ( color );
       
   378                     }
       
   379                 else
       
   380                     {
       
   381                     ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfImageVisualAttributeSetter" )
       
   382                     }
       
   383                 }
       
   384 
       
   385             }
       
   386         else
       
   387             {
       
   388             AlfCommonVisualAttributeSetter::handleStaticDataAttribute(aVisual, aAttr, aContainer, aData);
       
   389             }
       
   390         }
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 void AlfImageVisualAttributeSetter::handleDynamicAttribute(CAlfVisual &aVisual, AlfAttribute& aAttr, AlfAttributeContainer& aContainer)
       
   397     {
       
   398     CAlfImageVisual* imageVisual = dynamic_cast<CAlfImageVisual*>(&aVisual);
       
   399     if(!imageVisual)
       
   400         {
       
   401         return;
       
   402         }
       
   403 
       
   404     const char* attrName = aAttr.name();
       
   405 
       
   406     //KScale
       
   407     if (!strcmp(attrName,KScale))
       
   408         {
       
   409         TAlfTimedValue tVal((TReal32)aAttr.getSourceValue()->realValue());
       
   410         tVal.SetTarget((TReal32)aAttr.getTargetValue()->realValue(), (TInt)aAttr.getTime());
       
   411         tVal.SetStyle( aAttr.getInterpolationStyle() );
       
   412         tVal.SetMappingFunctionIdentifier( aAttr.getMappingFunctionId());
       
   413         imageVisual->SetScale( tVal );
       
   414         }
       
   415     // KSecondaryAlpha
       
   416     else if (!strcmp(attrName, KSecondaryAlpha))
       
   417         {
       
   418         TAlfTimedValue tVal((TReal32)aAttr.getSourceValue()->realValue());
       
   419         tVal.SetTarget((TReal32)aAttr.getTargetValue()->realValue(), (TInt)aAttr.getTime());
       
   420         tVal.SetStyle( aAttr.getInterpolationStyle() );
       
   421         tVal.SetMappingFunctionIdentifier( aAttr.getMappingFunctionId() );
       
   422         imageVisual->SetSecondaryAlpha( tVal );
       
   423         }
       
   424     //KTurnAngle
       
   425     else if (!strcmp(attrName, KTurnAngle))
       
   426         {
       
   427         TAlfTimedValue tVal((TReal32)aAttr.getSourceValue()->realValue());
       
   428         tVal.SetTarget((TReal32)aAttr.getTargetValue()->realValue(), (TInt)aAttr.getTime());
       
   429         tVal.SetStyle( aAttr.getInterpolationStyle() );
       
   430         tVal.SetMappingFunctionIdentifier( aAttr.getMappingFunctionId() );
       
   431         imageVisual->SetTurnAngle( tVal );
       
   432         }
       
   433     else if (!strcmp(attrName,KOffsetX)||!strcmp(attrName,KOffsetY))
       
   434         {
       
   435         AlfAttribute& attrX = aContainer.getAttributeByName( KOffsetX );
       
   436         AlfAttribute& attrY = aContainer.getAttributeByName( KOffsetY );
       
   437 
       
   438         TAlfTimedPoint timedpoint((TReal32)attrX.getSourceValue()->realValue(),
       
   439                                   (TReal32)attrY.getSourceValue()->realValue());
       
   440 
       
   441         timedpoint.iX.SetTarget((TReal32)attrX.getTargetValue()->realValue(), (TInt)attrX.getTime());
       
   442         timedpoint.iY.SetTarget((TReal32)attrY.getTargetValue()->realValue(), (TInt)attrY.getTime());
       
   443 
       
   444         timedpoint.iX.SetStyle(attrX.getInterpolationStyle());
       
   445         timedpoint.iY.SetStyle(attrY.getInterpolationStyle() );
       
   446 
       
   447         timedpoint.iX.SetMappingFunctionIdentifier(attrX.getMappingFunctionId());
       
   448         timedpoint.iY.SetMappingFunctionIdentifier(attrY.getMappingFunctionId());
       
   449 
       
   450         imageVisual->SetOffset(timedpoint);
       
   451         attrX.setDirty(false);
       
   452         attrY.setDirty(false);
       
   453 
       
   454         }
       
   455     else
       
   456         {
       
   457         AlfCommonVisualAttributeSetter::handleDynamicAttribute(
       
   458             aVisual, aAttr, aContainer);
       
   459         }
       
   460     }
       
   461 
       
   462 // ---------------------------------------------------------------------------
       
   463 // ---------------------------------------------------------------------------
       
   464 //
       
   465 void AlfImageVisualAttributeSetter::handleStaticAttribute(CAlfVisual& aVisual, AlfAttribute& aAttr, AlfAttributeContainer& aContainer)
       
   466     {
       
   467     CAlfImageVisual* imageVisual = dynamic_cast<CAlfImageVisual*>(&aVisual);
       
   468     if(!imageVisual)
       
   469         {
       
   470         return;
       
   471         }
       
   472 
       
   473     const char* attrName = aAttr.name();
       
   474 
       
   475     // imagevisual attributes
       
   476     if (!strcmp(attrName,KImageScaleMode))
       
   477         {
       
   478         int val = aAttr.intValue();
       
   479         imageVisual->SetScaleMode(CAlfImageVisual::TScaleMode(val));
       
   480         }
       
   481     else if (!strcmp(attrName,KImageColorMode))
       
   482         {
       
   483         int val = aAttr.intValue();
       
   484         imageVisual->SetColorMode( CAlfImageVisual::TColorMode(val));
       
   485         }
       
   486     else if (!strcmp(attrName,KDropShadow))
       
   487         {
       
   488         int count = aAttr.getTargetValueCount();
       
   489 
       
   490         //user has added one value to the attribute,so this value will be used for both x and y directions.
       
   491         if (1==count)
       
   492             {
       
   493             AlfAttributeValueType* attrType = aAttr.getTargetValue(0);
       
   494             imageVisual->SetDropShadow( TAlfMetric(attrType->unit(),attrType->realValue()) );
       
   495             }
       
   496         //user has not added two values to the attribute,so the first and second values
       
   497         // will be used for x and y directions respectively.
       
   498         else if (2==count)
       
   499             {
       
   500             const AlfAttributeValueType* attrType1 = aAttr.getTargetValue(0);
       
   501             const AlfAttributeValueType* attrType2 = aAttr.getTargetValue(1);
       
   502             imageVisual->SetDropShadow(TAlfXYMetric(TAlfMetric(attrType1->unit(),attrType1->realValue()),TAlfMetric(attrType2->unit(),attrType2->realValue())));
       
   503             }
       
   504         else
       
   505             {
       
   506             ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfImageVisualAttributeSetter")
       
   507             }
       
   508 
       
   509         }
       
   510     else if (!strcmp(attrName,KImagePath))
       
   511         {
       
   512         TPtrC8 src((TUint8*)aAttr.stringValue().getUtf8());
       
   513         HandleImagePathAttribute( src, imageVisual, true );
       
   514         }
       
   515     else if (!strcmp(attrName,KImageResourceRef))
       
   516         {
       
   517 
       
   518     	TAlfImage image;
       
   519 	    try
       
   520 	        {
       
   521     		image = AlfWidgetEnvExtension::resourcePool(aVisual.Env()).getImageResource(aAttr.stringValue().getUtf8());
       
   522 	        }
       
   523 	    catch(invalid_argument &)
       
   524 	        {
       
   525 	        ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfImageVisualAttributeSetter:: Image does not exist");
       
   526 	        }
       
   527        	if(image.HasTexture())
       
   528        		imageVisual->SetImage(image);
       
   529     	else
       
   530     		{
       
   531         	ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfImageVisualAttributeSetter:: Image does not exist");
       
   532         	}
       
   533     
       
   534         }
       
   535     else if (!strcmp(attrName,KSecondaryImagePath))
       
   536         {
       
   537         TPtrC8 src((TUint8*)aAttr.stringValue().getUtf8());
       
   538         HandleImagePathAttribute( src, imageVisual, false );        
       
   539         }
       
   540     else if (!strcmp(attrName,KSecondaryImageResourceRef))
       
   541         {
       
   542 
       
   543     	TAlfImage image;
       
   544         try
       
   545             {
       
   546     		image = AlfWidgetEnvExtension::resourcePool(aVisual.Env()).getImageResource(aAttr.stringValue().getUtf8());
       
   547             }
       
   548         catch(invalid_argument &)
       
   549             {
       
   550              ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfImageVisualAttributeSetter:: Image does not exist");
       
   551             }
       
   552        	if(image.HasTexture())
       
   553        		imageVisual->SetSecondaryImage(image);
       
   554     	else
       
   555     		{
       
   556         	ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfImageVisualAttributeSetter:: Image does not exist");
       
   557         	}
       
   558     
       
   559         }
       
   560     else if (!strcmp(attrName,KSkinImagePath))
       
   561         {
       
   562         TAlfImage image;
       
   563         try
       
   564             {
       
   565         	image = AlfWidgetEnvExtension::resourcePool(aVisual.Env()).getImageResource(aAttr.stringValue().getUtf8());
       
   566             }
       
   567         catch(invalid_argument &)
       
   568             {
       
   569             // This image is not present in currently active Theme, 
       
   570             // hence Resource Pool throws an exception
       
   571             // which can be ignored and we will try to load it for first time.
       
   572 	        }
       
   573         if(!image.HasTexture())
       
   574             {
       
   575             image = mImpl->createNonPoolImageFromSkinLogicalID( 
       
   576                 imageVisual->Env() ,aAttr.stringValue().getUtf8(), aContainer);
       
   577             }
       
   578         imageVisual->SetImage(image);
       
   579         }
       
   580     else if (!strcmp(attrName,KAnimatedSkinImage))
       
   581         {
       
   582         
       
   583         // Retrieve animation skin id        
       
   584     	auto_ptr< HBufC> skinAnimId;
       
   585     	TPtrC8 src( (TUint8*) aAttr.stringValue().getUtf8() );    		
       
   586     	TRAPD(err,skinAnimId.reset(CnvUtfConverter::ConvertToUnicodeFromUtf8L(src)));
       
   587     		    	
       
   588     	if(err != KErrNone)
       
   589     		{
       
   590     		ALF_THROW ( AlfDataException, err, "AlfImageVisualAttributeSetter") 
       
   591     		}  			 
       
   592     	   
       
   593     	// loading the texture from animation id.        
       
   594        	TAlfImage skinAnimImage(imageVisual->Env().TextureManager().
       
   595        	   			           LoadAnimatedTextureL(*(skinAnimId.get()),
       
   596        	   						                    imageVisual->Env().PrimaryDisplay().VisibleArea().Size(),
       
   597        	   					 	                    EAlfTextureFlagDefault,
       
   598        	   					 	                    KAlfAutoGeneratedTextureId));
       
   599        	   
       
   600        	// setting the texture to imagevisual only if it exists.
       
   601        	if(skinAnimImage.HasTexture())
       
   602        		{
       
   603        		imageVisual->SetImage(skinAnimImage);
       
   604        		}
       
   605        		
       
   606         }
       
   607     else if (!strcmp(attrName,KSecondarySkinImagePath))
       
   608         {
       
   609         TAlfImage	image; 
       
   610         try
       
   611             {
       
   612         	image = AlfWidgetEnvExtension::resourcePool(aVisual.Env()).getImageResource(aAttr.stringValue().getUtf8());
       
   613             }
       
   614         catch(invalid_argument &)
       
   615             {
       
   616             // This image is not present in currently active Theme, 
       
   617             // hence Resource Pool throws an exception
       
   618             // which can be ignored and we will try to load it for first time.
       
   619 	        }
       
   620         if(!image.HasTexture())
       
   621             {
       
   622             image = mImpl->createNonPoolImageFromSkinLogicalID( imageVisual->Env(), aAttr.stringValue().getUtf8(), aContainer);
       
   623             }
       
   624         imageVisual->SetSecondaryImage(image);
       
   625         }
       
   626     else if(!strcmp(attrName,KSkinFrameImage))
       
   627         {	
       
   628 		setFrameImage(aVisual, aAttr.stringValue().getUtf8(), aContainer);		
       
   629         }
       
   630     else if (!strcmp(attrName,KStretchMode))
       
   631         {
       
   632         int val = aAttr.intValue();
       
   633         imageVisual->SetStretchMode(CAlfGc::TStretchMode(val));
       
   634         }
       
   635     else if (!strcmp(attrName, KSecondaryAlpha))
       
   636         {
       
   637         TAlfTimedValue tVal((TReal32)aAttr.getSourceValue()->realValue());
       
   638         tVal.SetTarget((TReal32)aAttr.getTargetValue()->realValue(), (TInt)aAttr.getTime());
       
   639         tVal.SetStyle( aAttr.getInterpolationStyle() );
       
   640         tVal.SetMappingFunctionIdentifier( aAttr.getMappingFunctionId());
       
   641         imageVisual->SetSecondaryAlpha( tVal );
       
   642         }
       
   643     else if (!strcmp(attrName, KTurnAngle))
       
   644         {
       
   645         TAlfTimedValue tVal((TReal32)aAttr.getSourceValue()->realValue());
       
   646         tVal.SetTarget((TReal32)aAttr.getTargetValue()->realValue(), (TInt)aAttr.getTime());
       
   647         tVal.SetStyle( aAttr.getInterpolationStyle() );
       
   648         tVal.SetMappingFunctionIdentifier( aAttr.getMappingFunctionId() );
       
   649         imageVisual->SetTurnAngle( tVal );
       
   650         }
       
   651     else if (!strcmp(attrName, KColor))
       
   652         {
       
   653         if ( 4 == aAttr.getTargetValueCount() && AlfAttributeValueType::EInt == aAttr.type(0) && AlfAttributeValueType::EInt == aAttr.type(1) && AlfAttributeValueType::EInt == aAttr.type(2) && AlfAttributeValueType::EInt == aAttr.type(3))
       
   654             {
       
   655             TRgb color ( aAttr.intValue(0), aAttr.intValue(1), aAttr.intValue(2), aAttr.intValue(3) );
       
   656             imageVisual->SetColor ( color );
       
   657             }
       
   658         else
       
   659             {
       
   660             ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfImageVisualAttributeSetter")
       
   661             }
       
   662         }
       
   663     else
       
   664         {
       
   665         AlfCommonVisualAttributeSetter::handleStaticAttribute(aVisual, aAttr, aContainer);
       
   666         }
       
   667     }
       
   668 
       
   669 
       
   670 
       
   671 // ---------------------------------------------------------------------------
       
   672 // Helper method to set the frame image to the image visual.
       
   673 // ---------------------------------------------------------------------------
       
   674 //
       
   675 void AlfImageVisualAttributeSetter::setFrameImage(CAlfVisual& /*aVisual*/, const Utf8* /*aSkinFrameID*/,
       
   676 							const AlfAttributeContainer& /*aContainer*/,IAlfMap* /*aData*/)
       
   677 	{	
       
   678         	
       
   679   }
       
   680 
       
   681 // ---------------------------------------------------------------------------
       
   682 // This method gets the value of the attribute based on whether the attribute is static
       
   683 // or staticData. 
       
   684 // Currently handled only for static or staticdata.
       
   685 // ---------------------------------------------------------------------------
       
   686    
       
   687 int AlfImageVisualAttributeSetter::getValueFromAttribute(const AlfAttribute& aAttr,IAlfMap* aData) const
       
   688 	{	
       
   689 	int attrValue=0;
       
   690 	
       
   691 	// Check whether attribute is from Static type.
       
   692 	
       
   693 	if(AlfAttribute::EStatic==aAttr.category())
       
   694 		{
       
   695 		attrValue=aAttr.intValue();
       
   696 		}
       
   697 	else
       
   698 		{		
       
   699 		
       
   700 		// static data case.		
       
   701 	    try
       
   702 	    	{
       
   703 	    	 if(aData)
       
   704 	    	 	{	    	 	
       
   705 	    	 
       
   706 	    	 	const char* dataValue = aAttr.getDataField();
       
   707              	IAlfVariantType* dataVariant = aData->item ( UString(dataValue) );
       
   708 
       
   709              	if (dataVariant && dataVariant->type() == IAlfVariantType::EInt )
       
   710                 	{                
       
   711                 	
       
   712                 	attrValue=dataVariant->integer();
       
   713                 		    		  
       
   714 	    			}
       
   715 	    	 	}
       
   716 	    	}
       
   717 	    catch(AlfDataException& e)
       
   718 	    	{	    		    	
       
   719 	   	    // Error in getting the value.
       
   720 	   	    // default is already set to 0,dont do anything here.			
       
   721 	    	}
       
   722 		}
       
   723 		
       
   724 	return attrValue;
       
   725 	
       
   726 	}
       
   727 
       
   728 // ---------------------------------------------------------------------------
       
   729 // ---------------------------------------------------------------------------
       
   730 //
       
   731 OSN_EXPORT TAlfCommand* AlfImageVisualAttributeSetter::createCommand(
       
   732     CAlfVisual& /*aVisual*/, AlfAttributeContainer* /*aContainer*/,
       
   733     IAlfMap* /*aData*/, int /*aTransitionTime*/, CAlfVisual* /*aRefVisual*/)
       
   734     {
       
   735     TAlfCommand* cmd = 0;
       
   736     return cmd;
       
   737     }
       
   738 
       
   739 // ---------------------------------------------------------------------------
       
   740 // ---------------------------------------------------------------------------
       
   741 //
       
   742 OSN_EXPORT void AlfImageVisualAttributeSetter::createAndSendCommands(
       
   743     CAlfVisual& aVisual,
       
   744     AlfAttributeContainer* aContainer,
       
   745     CAlfVisual* aRefVisual )
       
   746     {
       
   747 
       
   748     // Call the base class implementation.It goes through its loop and checks if there are attributes
       
   749     // that it handles.
       
   750     AlfCommonVisualAttributeSetter::createAndSendCommands(
       
   751         aVisual,
       
   752         aContainer,
       
   753         aRefVisual );
       
   754     }
       
   755 
       
   756 // ---------------------------------------------------------------------------
       
   757 // ---------------------------------------------------------------------------
       
   758 //
       
   759 void AlfImageVisualAttributeSetter::HandleImagePathAttribute(
       
   760     const TPtrC8& aStringValue,
       
   761     CAlfImageVisual* aImageVisual,
       
   762     bool aPrimary )
       
   763     {
       
   764     TAlfImage image = mImpl->createImageFromImagePath( *aImageVisual, aStringValue); 
       
   765     if ( aPrimary )
       
   766         {                
       
   767         aImageVisual->SetImage(image);
       
   768         }
       
   769     else
       
   770         {
       
   771         aImageVisual->SetSecondaryImage(image);                
       
   772         }      
       
   773     }
       
   774 
       
   775 //----------------------------------------------------------------------------
       
   776 //----------------------------------------------------------------------------    
       
   777 TAlfImage AlfImageVisualAttributeSetterImpl::createNonPoolImageFromSkinLogicalID(CAlfEnv& /*aEnv*/,  const Utf8* /*aLogicalId*/, AlfAttributeContainer& /*aContainer*/)
       
   778     {
       
   779     
       
   780     // Depricated
       
   781     return TAlfImage();   
       
   782    
       
   783     }
       
   784 
       
   785 TAlfImage AlfImageVisualAttributeSetterImpl::createImageFromImagePath( const CAlfImageVisual& aImageVisual, const TPtrC8& aPath )
       
   786     {
       
   787     TAlfImage image; // return value
       
   788 
       
   789     auto_ptr<HBufC> textureId;
       
   790     TRAPD(err,textureId.reset(CnvUtfConverter::ConvertToUnicodeFromUtf8L(aPath)));
       
   791     if ( err != KErrNone )
       
   792         {
       
   793         ALF_THROW ( AlfDataException, err, "AlfImageVisualAttributeSetter")
       
   794         }
       
   795 
       
   796     // check if the texture is already loaded
       
   797     CAlfTextureManager& textureMgr = aImageVisual.Env().TextureManager();
       
   798     const TInt existingTextureId = textureMgr.TextureId(*(textureId.get()));
       
   799     if (existingTextureId != KErrNotFound)
       
   800     	{
       
   801             const CAlfTexture* texture = textureMgr.Texture( existingTextureId );
       
   802             image = TAlfImage(*texture);            
       
   803        	}
       
   804     else
       
   805         {
       
   806         CAlfTexture* mutableTexture = 0;
       
   807         TRAP(err, mutableTexture = &(textureMgr.LoadTextureL(*(textureId.get()), EAlfTextureFlagDefault, KAlfAutoGeneratedTextureId)));
       
   808         if ( err != KErrNone )
       
   809             {
       
   810             ALF_THROW ( AlfDataException, err, "AlfImageVisualAttributeSetter")
       
   811             }    
       
   812         mutableTexture->EnableRefCounting(ETrue);
       
   813         image = TAlfImage(*mutableTexture);
       
   814         mLoadedTextures.resize(mLoadedTextures.count()+1);
       
   815         mLoadedTextures.insert(mLoadedTextures.count(),mutableTexture);       
       
   816         }	
       
   817     
       
   818     return image;
       
   819     }
       
   820 	
       
   821 }// Alf