widgetmodel/alfwidgetmodel/src/alfcommonvisualattributesetter.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:  attributesetter for common visual attributes
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "alf/alfattribute.h"
       
    20 #include "alf/alfcommonvisualattributesetter.h"
       
    21 #include "alf/alfattributevaluetype.h"
       
    22 #include <alf/alfvisual.h>
       
    23 #include <alf/alfattributeexception.h>
       
    24 #include <alf/alfdataexception.h>
       
    25 #include <alf/alfvisualexception.h>
       
    26 #include "alf/alfattributecontainer.h"
       
    27 #include <libc/string.h>
       
    28 #include <osn/ustring.h>
       
    29 #include "alf/attrproperty.h"
       
    30 #include <alf/alfenv.h>
       
    31 
       
    32 using namespace osncore;
       
    33 
       
    34 using namespace duiuimodel::commonattributes;
       
    35 using namespace duiuimodel::commonattributevalues;
       
    36 using namespace duiuimodel::commonvisualattributes;
       
    37 using namespace duiuimodel::layoutattributes;
       
    38 using namespace duiuimodel::rect;
       
    39 using namespace duiuimodel::padding;
       
    40 using namespace duiuimodel::tactileattributes;
       
    41 
       
    42 namespace Alf
       
    43     {
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // gets the data from map pointed by attribute's field name.
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 IAlfVariantType* getData(const AlfAttribute& aAttr, IAlfMap* aData)
       
    50     {
       
    51     IAlfVariantType* data = 0;
       
    52     const char* dataField = aAttr.getDataField();
       
    53     if (dataField)
       
    54         {
       
    55         data = aData->item(UString(dataField));
       
    56         }
       
    57     return data;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // gets the time from attribute safely.
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 int getTime(const AlfAttribute& aAttr, bool aImmediate = false)
       
    65     {
       
    66     int time = 0;
       
    67     if (!aImmediate)
       
    68         {
       
    69         time = aAttr.getTime();
       
    70         }
       
    71 
       
    72     return time;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // sets source values from aAttr to aPoint.
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 void setSourceValue(TAlfTimedValue& aValue, const AlfAttribute& aAttr)
       
    80     {
       
    81     if (aAttr.getSourceValueCount() > 0)
       
    82         {
       
    83         aValue.SetValueNow(aAttr.getSourceValue()->realValue());
       
    84         }
       
    85     }
       
    86 // ---------------------------------------------------------------------------
       
    87 // sets source values to aPoint.
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void SetSourceValues(TAlfTimedPoint& aPoint, const AlfAttribute& aAttrX,
       
    91                      const AlfAttribute& aAttrY)
       
    92     {
       
    93     if (aAttrX.getSourceValueCount() > 0)
       
    94         {
       
    95         aPoint.iX.SetValueNow(aAttrX.getSourceValue()->realValue());
       
    96         }
       
    97     if (aAttrY.getSourceValueCount() > 0)
       
    98         {
       
    99         aPoint.iY.SetValueNow(aAttrY.getSourceValue()->realValue());
       
   100         }
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // sets source values to aRect.
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void SetSourceRect(TAlfRealRect& aRect, const AlfAttribute& aAttrTopX,
       
   108                    const AlfAttribute& aAttrTopY,
       
   109                    const AlfAttribute& aAttrBottomRightX,
       
   110                    const AlfAttribute& aAttrBottomRightY)
       
   111     {
       
   112     if (aAttrTopX.getSourceValueCount() > 0)
       
   113         {
       
   114         aRect.iTl.iX = aAttrTopX.getSourceValue()->realValue();
       
   115         }
       
   116     if (aAttrTopY.getSourceValueCount() > 0)
       
   117         {
       
   118         aRect.iTl.iY = aAttrTopY.getSourceValue()->realValue();
       
   119         }
       
   120     if (aAttrBottomRightX.getSourceValueCount() > 0)
       
   121         {
       
   122         aRect.iBr.iX = aAttrBottomRightX.getSourceValue()->realValue();
       
   123         }
       
   124     if (aAttrBottomRightY.getSourceValueCount() > 0)
       
   125         {
       
   126         aRect.iBr.iY = aAttrBottomRightY.getSourceValue()->realValue();
       
   127         }
       
   128     }
       
   129 
       
   130 // ======== MEMBER FUNCTIONS ========
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // Constructor.
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 OSN_EXPORT AlfCommonVisualAttributeSetter::AlfCommonVisualAttributeSetter()
       
   137     {
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // Destructor.
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 OSN_EXPORT AlfCommonVisualAttributeSetter::~AlfCommonVisualAttributeSetter()
       
   145     {
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // creates one command.
       
   150 // deprecated
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 OSN_EXPORT TAlfCommand* AlfCommonVisualAttributeSetter::createCommand(
       
   154     CAlfVisual& /*aVisual*/, AlfAttributeContainer* /*aContainer*/,
       
   155     IAlfMap* /*aData*/, int /*aTransitionTime*/, CAlfVisual* /*aRefVisual*/ )
       
   156     {
       
   157     return 0;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // creates and sends one or more commands.
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 OSN_EXPORT void AlfCommonVisualAttributeSetter::createAndSendCommands(
       
   165     CAlfVisual& aVisual,
       
   166     AlfAttributeContainer* aContainer,
       
   167     CAlfVisual* aRefVisual )
       
   168     {
       
   169     unsigned int attrCount = aContainer->attributeCount();
       
   170 
       
   171     for ( int i = 0; i < attrCount; ++i )
       
   172         {
       
   173         AlfAttribute& attr = aContainer->getAttribute(i);
       
   174         sendCommandsForAttribute(aVisual, *aContainer, attr, aRefVisual);
       
   175         }
       
   176 
       
   177     // Call the base class implementation also.
       
   178     // It goes through the same loop again and checks if there are attributes
       
   179     // that it handles.
       
   180     AlfCommonAttributeSetter::createAndSendCommands(
       
   181         aVisual,
       
   182         aContainer,
       
   183         aRefVisual );
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // Sets an value of a static attribute to target visual immediately
       
   188 // without a transition.
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void AlfCommonVisualAttributeSetter::handleStaticAttribute(
       
   192     CAlfVisual &aVisual, AlfAttribute& aAttr,
       
   193     AlfAttributeContainer& aContainer)
       
   194     {
       
   195     const char* attrName = aAttr.name();
       
   196     if ( !strcmp(attrName, KParentVisual))
       
   197         {
       
   198         }
       
   199     else if (!strcmp(attrName, KMaxHeight)||!strcmp(attrName, KMaxWidth))
       
   200         {
       
   201         setMaxSize(aVisual,aContainer,NULL);
       
   202         }
       
   203     else if (!strcmp(attrName, KMinHeight)||!strcmp(attrName, KMinWidth))
       
   204         {
       
   205         setMinSize(aVisual,aContainer,NULL);
       
   206         }
       
   207     else if (!strcmp(attrName, KPaddingTop)||!strcmp(attrName, KPaddingBottom)
       
   208              ||!strcmp(attrName, KPaddingLeft)||!strcmp(attrName, KPaddingRight))
       
   209         {
       
   210         setPadding(aVisual,aContainer,NULL);
       
   211 
       
   212         }
       
   213     else if (!strcmp(attrName, KSetFlags))
       
   214         {
       
   215         int val = aAttr.intValue();
       
   216         aVisual.SetFlags(val);
       
   217         }
       
   218     else if (!strcmp(attrName, KClearFlags))
       
   219         {
       
   220         int val = aAttr.intValue();
       
   221         aVisual.ClearFlags(val);
       
   222         }
       
   223     else if (!strcmp(attrName, KEventInput) || !strcmp(attrName, KFeedbackType))
       
   224         {
       
   225         setTactileFeedback(aVisual,aContainer,NULL);
       
   226         }
       
   227     // turnangle and secondaryalpha are implemented by derived attributesetters
       
   228     else
       
   229         {
       
   230         //check, if dynamic attribute, if so, set attributes immediately.
       
   231         if (!doHandleDynamicAttribute(aVisual, aAttr, aContainer, true))
       
   232             {
       
   233             //not handled here, try base class.
       
   234             AlfCommonAttributeSetter::handleStaticAttribute(aVisual,
       
   235                     aAttr, aContainer);
       
   236             }
       
   237         }
       
   238     }
       
   239 
       
   240 void AlfCommonVisualAttributeSetter::setTactileFeedback(CAlfVisual &aVisual,AlfAttributeContainer& aContainer,IAlfMap* /*aData*/)
       
   241     {
       
   242     TRAPD( error, aVisual.SetTactileFeedbackL(
       
   243         aContainer.getAttributeByName( KEventInput ).intValue(),
       
   244         aContainer.getAttributeByName( KFeedbackType ).intValue() ) );
       
   245 
       
   246 	if(error != KErrNone)
       
   247 	    {
       
   248 		ALF_THROW(AlfVisualException,EInvalidAttribute,"AlfCommonVisualAttributeSetter")
       
   249 	    }
       
   250 	try
       
   251     	{
       
   252         aContainer.getAttributeByName( duiuimodel::tactileattributes::KEventInput ).setDirty( false );
       
   253         aContainer.getAttributeByName( duiuimodel::tactileattributes::KFeedbackType ).setDirty( false );
       
   254     	}
       
   255     	
       
   256     catch( AlfDataException& exception )
       
   257 	    {
       
   258 		//exception needed here?
       
   259 	    }
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // Sets an dynamic attribute value in the target visual
       
   264 // using transitions defined in attributes
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 void AlfCommonVisualAttributeSetter::handleDynamicAttribute(
       
   268     CAlfVisual& aVisual, AlfAttribute& aAttr,
       
   269     AlfAttributeContainer& aContainer)
       
   270     {
       
   271     if (!doHandleDynamicAttribute(aVisual, aAttr, aContainer))
       
   272         {
       
   273         //not handled here, try base class.
       
   274         AlfCommonAttributeSetter::handleDynamicAttribute(aVisual, aAttr,
       
   275                 aContainer);
       
   276         }
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // Sets an value for static attribute in the target visual immediately
       
   281 // without a transition using data in map.
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 void AlfCommonVisualAttributeSetter::handleStaticDataAttribute(
       
   285     CAlfVisual &aVisual, AlfAttribute& aAttr,
       
   286     AlfAttributeContainer& aContainer, IAlfMap* aData)
       
   287     {
       
   288 
       
   289     if (aData)
       
   290         {
       
   291         const char* attrName = aAttr.name();
       
   292 
       
   293         if (!strcmp(attrName, KMaxHeight))
       
   294             {
       
   295             // If maxheight exists, maxwidth must exists also.
       
   296             const IAlfVariantType* maxHeight = getData(aAttr, aData);
       
   297             const IAlfVariantType* maxWidth = getData(
       
   298                                                   aContainer.getAttributeByName(KMaxWidth), aData);
       
   299 
       
   300             if (maxHeight && maxHeight->type() == IAlfVariantType::EReal &&
       
   301                     maxWidth && maxWidth->type() == IAlfVariantType::EReal)
       
   302                 {
       
   303                 TAlfRealSize size( maxWidth->real(), maxHeight->real() );
       
   304                 aVisual.SetMaxSize(size);
       
   305                 }
       
   306             }
       
   307         else if (!strcmp(attrName, KMinHeight))
       
   308             {
       
   309             //If minheight exists, minwidth must exists also.
       
   310             const IAlfVariantType* minHeight = getData(aAttr, aData);
       
   311             const IAlfVariantType* minWidth = getData(
       
   312                                                   aContainer.getAttributeByName(KMinWidth), aData);
       
   313 
       
   314             if (minHeight && minHeight->type() == IAlfVariantType::EReal &&
       
   315                     minWidth && minWidth->type() == IAlfVariantType::EReal)
       
   316                 {
       
   317                 TAlfRealSize size( minWidth->real(), minHeight->real() );
       
   318                 aVisual.SetMinSize(size);
       
   319                 }
       
   320             }
       
   321         else if (!strcmp(attrName, KPaddingTop))
       
   322             {
       
   323             const IAlfVariantType* top = getData(aAttr, aData);
       
   324             const IAlfVariantType* right = getData(
       
   325                                                aContainer.getAttributeByName(KPaddingRight), aData);
       
   326             const IAlfVariantType* bottom = getData(
       
   327                                                 aContainer.getAttributeByName(KPaddingBottom), aData);
       
   328             const IAlfVariantType* left = getData(
       
   329                                               aContainer.getAttributeByName(KPaddingLeft), aData);
       
   330 
       
   331             if (top && top->type() == IAlfVariantType::EReal &&
       
   332                     right && right->type() == IAlfVariantType::EReal &&
       
   333                     bottom && bottom->type() == IAlfVariantType::EReal &&
       
   334                     left && left->type() == IAlfVariantType::EReal)
       
   335                 {
       
   336                 float l = left->real();
       
   337                 float r = right->real();
       
   338                 float t = top->real();
       
   339                 float b = bottom->real();
       
   340                 TAlfBoxMetric metric(l, r, t, b);
       
   341                 aVisual.SetPadding(metric);
       
   342                 }
       
   343             }
       
   344         else if (!strcmp(attrName, KSetFlags))
       
   345             {
       
   346             const IAlfVariantType* flag = getData(aAttr, aData);
       
   347             if (flag && flag->type() == IAlfVariantType::EInt)
       
   348                 {
       
   349                 int flagValue  = flag->integer();
       
   350                 aVisual.SetFlags(flagValue);
       
   351                 }
       
   352             }
       
   353         else if (!strcmp(attrName, KClearFlags))
       
   354             {
       
   355             const IAlfVariantType* flag = getData(aAttr, aData);
       
   356             if (flag && flag->type() == IAlfVariantType::EInt)
       
   357                 {
       
   358                 int flagValue  = flag->integer();
       
   359                 aVisual.ClearFlags(flagValue);
       
   360                 }
       
   361             }
       
   362         // turnangle and secondaryalpha are implemented by derived attributesetters
       
   363         else if (strcmp(attrName, KMaxWidth) &&         //these are already
       
   364                  strcmp(attrName, KMinWidth) &&         //handled above
       
   365                  strcmp(attrName, KPaddingRight) &&
       
   366                  strcmp(attrName, KPaddingBottom) &&
       
   367                  strcmp(attrName, KPaddingLeft))
       
   368             {
       
   369             //check, if dynamic attribute, if so, set attributes immediately.
       
   370             //If not, the function will call baseclass SetAttributeValue.
       
   371             if (!doHandleDynamicDataAttribute(aVisual, aAttr,
       
   372                                               aContainer, aData, true))
       
   373                 {
       
   374                 //not handled here, try base class.
       
   375                 AlfCommonAttributeSetter::handleStaticDataAttribute(
       
   376                     aVisual, aAttr, aContainer, aData);
       
   377                 }
       
   378             }
       
   379         }
       
   380     }
       
   381 
       
   382 // ---------------------------------------------------------------------------
       
   383 // From AlfCommonAttributeSetter
       
   384 //
       
   385 // Sets a value for dynamic data attribute value in the target visual
       
   386 // using transitions and data in map.
       
   387 // ---------------------------------------------------------------------------
       
   388 //
       
   389 void AlfCommonVisualAttributeSetter::handleDynamicDataAttribute(
       
   390     CAlfVisual& aVisual, AlfAttribute& aAttr,
       
   391     AlfAttributeContainer& aContainer, IAlfMap* aData)
       
   392     {
       
   393     if (!doHandleDynamicDataAttribute(aVisual, aAttr, aContainer, aData))
       
   394         {
       
   395         //not handled here, try base class.
       
   396         AlfCommonAttributeSetter::handleDynamicDataAttribute(aVisual, aAttr,
       
   397                 aContainer, aData);
       
   398         }
       
   399     }
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // Sets an dynamic attribute value in the target visual
       
   403 // using transitions defined in attributes
       
   404 // Handles only attributes, belonging to this attributesetter, not bases.
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 bool AlfCommonVisualAttributeSetter::doHandleDynamicAttribute(
       
   408     CAlfVisual& aVisual, AlfAttribute& aAttr,
       
   409     AlfAttributeContainer& aContainer, bool aImmediate)
       
   410     {
       
   411     const char* attrName = aAttr.name();
       
   412     bool handled = true;
       
   413 
       
   414     if ( !strcmp( attrName, KOpacity ) )
       
   415         {
       
   416         TAlfTimedValue v;
       
   417         setSourceValue(v, aAttr);
       
   418 
       
   419         float targetValue(aAttr.realValue());
       
   420         int time = getTime(aAttr, aImmediate);
       
   421         v.SetTarget(targetValue, time);
       
   422         v.SetStyle(aAttr.getInterpolationStyle());
       
   423         aVisual.SetOpacity(v);
       
   424         }
       
   425 
       
   426     else if (!strcmp( attrName, KPositionX)||!strcmp( attrName, KPositionY)) ////also handles: KPositionY
       
   427         {
       
   428         setPos(aVisual,aContainer,NULL,aImmediate);
       
   429         }
       
   430 
       
   431     else if (!strcmp( attrName, KWidth)||!strcmp( attrName, KHeight)) //also handles: KHeight
       
   432         {
       
   433         setSize(aVisual,aContainer,NULL,aImmediate);
       
   434         }
       
   435     else if (!strcmp(attrName, KTopLeftX)||!strcmp(attrName, KTopLeftY)
       
   436              ||!strcmp(attrName, KBottomRightX)||!strcmp(attrName, KBottomRightY))
       
   437         {
       
   438         setRect(aVisual,aContainer,NULL,aImmediate);
       
   439         }
       
   440     else
       
   441         {
       
   442         handled = false;
       
   443         }
       
   444 
       
   445     return handled;
       
   446     }
       
   447 
       
   448 // ---------------------------------------------------------------------------
       
   449 // Sets an value for dynamic attribute value in the target visual
       
   450 // using transitions and data in map.
       
   451 // ---------------------------------------------------------------------------
       
   452 //
       
   453 bool AlfCommonVisualAttributeSetter::doHandleDynamicDataAttribute(
       
   454     CAlfVisual& aVisual, AlfAttribute& aAttr,
       
   455     AlfAttributeContainer& aContainer, IAlfMap* aData, bool aImmediate )
       
   456     {
       
   457     bool handled = true;
       
   458     if (aData)
       
   459         {
       
   460         const char* attrName = aAttr.name();
       
   461 
       
   462         if ( !strcmp( attrName, KOpacity ) )
       
   463             {
       
   464             const IAlfVariantType* data = getData(aAttr, aData);
       
   465             if (data && data->type() == IAlfVariantType::EReal)
       
   466                 {
       
   467                 TAlfTimedValue v;
       
   468                 setSourceValue(v, aAttr);
       
   469 
       
   470                 float targetValue(data->real());
       
   471                 int time = getTime(aAttr, aImmediate);
       
   472                 v.SetTarget(targetValue, time);
       
   473                 v.SetStyle(aAttr.getInterpolationStyle());
       
   474                 aVisual.SetOpacity(v);
       
   475                 }
       
   476             }
       
   477         else if (!strcmp( attrName, KPositionX)) //also handles: KPositionY
       
   478             {
       
   479             //If positionx exists, positiony must exists also
       
   480             const AlfAttribute& attrX = aAttr;
       
   481             const AlfAttribute& attrY = aContainer.getAttributeByName(KPositionY);
       
   482 
       
   483             const IAlfVariantType* posX = getData(attrX, aData);
       
   484             const IAlfVariantType* posY = getData(attrY, aData);
       
   485 
       
   486             if (posX && posX->type() == IAlfVariantType::EReal &&
       
   487                     posY && posY->type() == IAlfVariantType::EReal)
       
   488                 {
       
   489                 TAlfTimedPoint pos;
       
   490                 SetSourceValues(pos, attrX, attrY);
       
   491 
       
   492                 pos.iX.SetStyle(attrX.getInterpolationStyle());
       
   493                 pos.iX.SetTarget(posX->real(), getTime(attrX, aImmediate));
       
   494                 pos.iY.SetStyle(attrY.getInterpolationStyle());
       
   495                 pos.iY.SetTarget(posY->real(), getTime(attrY, aImmediate));
       
   496                 aVisual.SetPos(pos);
       
   497                 }
       
   498             }
       
   499         else if (!strcmp( attrName, KWidth)) //also handles: KHeight
       
   500             {
       
   501             const AlfAttribute& attrWidth = aAttr;
       
   502             const AlfAttribute& attrHeight =
       
   503                 aContainer.getAttributeByName(KHeight);
       
   504 
       
   505             const IAlfVariantType* width = getData(attrWidth, aData);
       
   506             const IAlfVariantType* height = getData(attrHeight, aData);
       
   507 
       
   508             if (width && width->type() == IAlfVariantType::EReal &&
       
   509                     height && height->type() == IAlfVariantType::EReal)
       
   510                 {
       
   511                 TAlfTimedPoint size;
       
   512                 SetSourceValues(size, attrWidth, attrHeight);
       
   513 
       
   514                 size.iX.SetStyle(attrWidth.getInterpolationStyle());
       
   515                 size.iX.SetTarget(width->real(),
       
   516                                   getTime(attrWidth, aImmediate));
       
   517                 size.iY.SetStyle(attrHeight.getInterpolationStyle());
       
   518                 size.iY.SetTarget(height->real(),
       
   519                                   getTime(attrHeight, aImmediate));
       
   520 
       
   521                 aVisual.SetSize(size);
       
   522                 }
       
   523             }
       
   524         else if (!strcmp(attrName, KTopLeftX))
       
   525             {
       
   526             //If topleftx exists, topy, bottomx and bottomy must exists also
       
   527             const AlfAttribute& attrTopX = aAttr;
       
   528             const AlfAttribute& attrTopY =
       
   529                 aContainer.getAttributeByName(KTopLeftY);
       
   530             const AlfAttribute& attrBottomRightX =
       
   531                 aContainer.getAttributeByName(KBottomRightX);
       
   532             const AlfAttribute& attrBottomRightY =
       
   533                 aContainer.getAttributeByName(KBottomRightY);
       
   534 
       
   535             const IAlfVariantType* topX = getData(attrTopX, aData);
       
   536             const IAlfVariantType* topY = getData(attrTopY, aData);
       
   537             const IAlfVariantType* bottomX = getData(attrBottomRightX, aData);
       
   538             const IAlfVariantType* bottomY = getData(attrBottomRightY, aData);
       
   539 
       
   540             if (topX && topX->type() == IAlfVariantType::EReal &&
       
   541                     topY && topY->type() == IAlfVariantType::EReal &&
       
   542                     bottomX && bottomX->type() == IAlfVariantType::EReal &&
       
   543                     bottomY && bottomY->type() == IAlfVariantType::EReal)
       
   544                 {
       
   545                 const TAlfRealPoint sTopLeft(aVisual.Pos().ValueNow());
       
   546                 TAlfRealPoint size(aVisual.Size().ValueNow());
       
   547                 TAlfRealRect sRect(sTopLeft, TAlfRealPoint(
       
   548                                        sTopLeft.iX + size.iX, sTopLeft.iY + size.iY));
       
   549 
       
   550                 SetSourceRect(sRect, attrTopX, attrTopY, attrBottomRightX,
       
   551                               attrBottomRightY);
       
   552 
       
   553                 aVisual.SetRect(sRect, 0);
       
   554 
       
   555                 TAlfRealPoint topLeft(topX->real(), topY->real());
       
   556                 TAlfRealPoint bottomRight(bottomX->real(), bottomY->real());
       
   557                 TAlfRealRect realRect(topLeft, bottomRight);
       
   558                 aVisual.SetRect(realRect, getTime(aAttr, aImmediate));
       
   559                 }
       
   560             }
       
   561         else if (strcmp(attrName, KPositionY) &&      //these are already
       
   562                  strcmp(attrName, KHeight) &&         //handled above
       
   563                  strcmp(attrName, KTopLeftY) &&
       
   564                  strcmp(attrName, KBottomRightX) &&
       
   565                  strcmp(attrName, KBottomRightY))
       
   566             {
       
   567             handled = false;
       
   568             }
       
   569         }
       
   570 
       
   571     return handled;
       
   572     }
       
   573 
       
   574 // ---------------------------------------------------------------------------
       
   575 // Creates and returns one command
       
   576 // ---------------------------------------------------------------------------
       
   577 //
       
   578 void AlfCommonVisualAttributeSetter::sendCommandsForAttribute(
       
   579     CAlfVisual& aVisual, AlfAttributeContainer& aContainer,
       
   580     AlfAttribute& aAttr, CAlfVisual* aRefVisual)
       
   581     {
       
   582     const char* attrName = aAttr.name();
       
   583 
       
   584     if ( !strcmp( attrName, KOpacity ) )
       
   585         {
       
   586         float value(aAttr.realValue());
       
   587 
       
   588         if (aRefVisual)
       
   589             {
       
   590             // Add the opacity of the reference visual to the value
       
   591             // of the opacity provided in the attribute 
       
   592             value += aRefVisual->Opacity().ValueNow(); 
       
   593             }
       
   594 
       
   595         int time = getTime(aAttr);
       
   596 
       
   597         //setting interpolation style
       
   598         TAlfInterpolationStyle style = aAttr.getInterpolationStyle();
       
   599         TAlfTimedValue v;
       
   600         v.SetStyle(style);
       
   601         aVisual.SetOpacity(v);
       
   602 
       
   603         //create command
       
   604         TAlfValueCommand cmd(&aVisual, EAlfValueCommandVisualSetOpacity,
       
   605                              EAlfOpSet, value, time);
       
   606 
       
   607         //send with delay.
       
   608         CAlfEnv::Static()->Send(cmd, aAttr.getDelay());
       
   609         }
       
   610 
       
   611     else if (!strcmp( attrName, KPositionX)) ////also handles: KPositionY
       
   612         {
       
   613         // Must contain both KPositionX and KPositionY
       
   614         const AlfAttribute& posXattrib = aAttr;
       
   615         const AlfAttribute& posYattrib =
       
   616             aContainer.getAttributeByName(KPositionY);
       
   617 
       
   618         TAlfRealPoint value(posXattrib.realValue(),
       
   619                             posYattrib.realValue());
       
   620 
       
   621         if ( aRefVisual )
       
   622             {
       
   623             value += aRefVisual->Pos().ValueNow(); // Add the reference point
       
   624             }
       
   625 
       
   626         int time = getTime(aAttr);
       
   627 
       
   628         //create command
       
   629         TAlfPointCommand cmd(&aVisual, EAlfPointCommandVisualSetPos,
       
   630                              value, time);
       
   631 
       
   632         //send with delay.
       
   633         CAlfEnv::Static()->Send(cmd, aAttr.getDelay());
       
   634         }
       
   635 
       
   636     else if (!strcmp( attrName, KWidth)) //also handles: KHeight
       
   637         {
       
   638         // Must contain both KWidth and KHeight
       
   639         const AlfAttribute& widthAttrib = aAttr;
       
   640         const AlfAttribute& heightAttrib =
       
   641             aContainer.getAttributeByName(KHeight);
       
   642 
       
   643         TAlfRealPoint value(widthAttrib.realValue(),
       
   644                             heightAttrib.realValue());
       
   645 
       
   646         if (aRefVisual)
       
   647             {
       
   648             value += aRefVisual->Size().ValueNow(); // Add the reference point
       
   649             }
       
   650         int time = getTime(aAttr);
       
   651 
       
   652         //create command
       
   653         TAlfPointCommand cmd(&aVisual,
       
   654                              EAlfPointCommandVisualSetSize, value, time);
       
   655 
       
   656         //send with delay.
       
   657         CAlfEnv::Static()->Send(cmd, aAttr.getDelay());
       
   658         }
       
   659     else if (!strcmp(attrName, KTopLeftX))
       
   660         {
       
   661         //If topleftx exists, topy, bottomx and bottomy must exists also
       
   662         float topX = aAttr.realValue();
       
   663         const AlfAttribute& attrTopY =
       
   664             aContainer.getAttributeByName(KTopLeftY);
       
   665         const AlfAttribute& attrBottomX =
       
   666             aContainer.getAttributeByName(KBottomRightX);
       
   667         const AlfAttribute& attrBottomY =
       
   668             aContainer.getAttributeByName(KBottomRightY);
       
   669         TAlfRealPoint topLeft(topX, attrTopY.realValue());
       
   670         TAlfRealPoint size(attrBottomX.realValue() - topLeft.iX,
       
   671                            attrBottomY.realValue() - topLeft.iY);
       
   672         if (aRefVisual)
       
   673             {
       
   674             // Add the reference point
       
   675             topLeft += aRefVisual->Pos().ValueNow();
       
   676             size += aRefVisual->Size().ValueNow();
       
   677             }
       
   678 
       
   679         int posTime = getTime(aAttr);
       
   680         int sizeTime = getTime(attrBottomX);
       
   681 
       
   682         //create position command
       
   683         TAlfPointCommand posCmd(&aVisual, EAlfPointCommandVisualSetPos,
       
   684                                 topLeft, posTime);
       
   685         TAlfPointCommand sizeCmd(&aVisual, EAlfPointCommandVisualSetPos,
       
   686                                  size, sizeTime);
       
   687 
       
   688         //send with delay.
       
   689         CAlfEnv::Static()->Send(posCmd, aAttr.getDelay());
       
   690         CAlfEnv::Static()->Send(sizeCmd, attrBottomX.getDelay());
       
   691         }
       
   692     }
       
   693 
       
   694     
       
   695 void AlfCommonVisualAttributeSetter::setPadding(CAlfVisual &aVisual,AlfAttributeContainer& aContainer,IAlfMap* /*aData*/)
       
   696     {
       
   697     //If padding-top exists, right, bottom and left must exists also
       
   698 
       
   699     AlfAttribute& attrTop =
       
   700         aContainer.getAttributeByName(KPaddingTop);
       
   701     AlfAttribute& attrRight =
       
   702         aContainer.getAttributeByName(KPaddingRight);
       
   703     AlfAttribute& attrBottom =
       
   704         aContainer.getAttributeByName(KPaddingBottom);
       
   705     AlfAttribute& attrLeft =
       
   706         aContainer.getAttributeByName(KPaddingLeft);
       
   707 
       
   708     TAlfBoxMetric metric(
       
   709         TAlfMetric(attrLeft.realValue(), attrLeft.unit()),
       
   710         TAlfMetric(attrRight.realValue(), attrRight.unit()),
       
   711         TAlfMetric(attrTop.realValue(), attrTop.unit()),
       
   712         TAlfMetric(attrBottom.realValue(), attrBottom.unit()));
       
   713 
       
   714     aVisual.SetPadding(metric);
       
   715 
       
   716     attrTop.setDirty(false);
       
   717     attrRight.setDirty(false);
       
   718     attrBottom.setDirty(false);
       
   719     attrLeft.setDirty(false);
       
   720 
       
   721     }
       
   722 
       
   723 void AlfCommonVisualAttributeSetter::setMinSize(CAlfVisual &aVisual,AlfAttributeContainer& aContainer,IAlfMap* /*aData*/)
       
   724     {
       
   725     //If minheight exists, minwidth must exists also.
       
   726     AlfAttribute& attrHt =
       
   727         aContainer.getAttributeByName(KMinHeight);
       
   728     AlfAttribute& attrWidth =
       
   729         aContainer.getAttributeByName(KMinWidth);
       
   730     float height = attrHt.realValue();
       
   731     float width = attrWidth.realValue();
       
   732     TAlfRealSize size( width, height );
       
   733 
       
   734     aVisual.SetMinSize(size);
       
   735 
       
   736     attrHt.setDirty(false);
       
   737     attrWidth.setDirty(false);
       
   738     }
       
   739 
       
   740 void AlfCommonVisualAttributeSetter::setMaxSize(CAlfVisual &aVisual,AlfAttributeContainer& aContainer,IAlfMap* /*aData*/)
       
   741     {
       
   742     AlfAttribute& attrHt =
       
   743         aContainer.getAttributeByName(KMaxHeight);
       
   744     AlfAttribute& attrWidth =
       
   745         aContainer.getAttributeByName(KMaxWidth);
       
   746     float height = attrHt.realValue();
       
   747     float width = attrWidth.realValue();
       
   748     TAlfRealSize size( width, height );
       
   749 
       
   750     aVisual.SetMaxSize(size);
       
   751 
       
   752 
       
   753     attrHt.setDirty(false);
       
   754     attrWidth.setDirty(false);
       
   755 
       
   756 
       
   757     }
       
   758 
       
   759 void AlfCommonVisualAttributeSetter::setSize(CAlfVisual &aVisual,AlfAttributeContainer& aContainer,IAlfMap* /*aData*/,bool aImmediate)
       
   760     {
       
   761     // Must contain both KWidth and KHeight
       
   762     AlfAttribute& attrWidth =
       
   763         aContainer.getAttributeByName(KWidth);;
       
   764     AlfAttribute& attrHeight =
       
   765         aContainer.getAttributeByName(KHeight);
       
   766 
       
   767     TAlfTimedPoint size(aVisual.Size());
       
   768     SetSourceValues(size, attrWidth, attrHeight);
       
   769 
       
   770     size.iX.SetStyle(attrWidth.getInterpolationStyle());
       
   771     size.iX.SetTarget(attrWidth.realValue(),
       
   772                       getTime(attrWidth, aImmediate));
       
   773     size.iY.SetStyle(attrHeight.getInterpolationStyle());
       
   774     size.iY.SetTarget(attrHeight.realValue(),
       
   775                       getTime(attrHeight, aImmediate));
       
   776 
       
   777 
       
   778     aVisual.SetSize(size);
       
   779 
       
   780 
       
   781     attrWidth.setDirty(false);
       
   782     attrHeight.setDirty(false);
       
   783     }
       
   784 
       
   785 void AlfCommonVisualAttributeSetter::setPos(CAlfVisual &aVisual,AlfAttributeContainer& aContainer,IAlfMap* /*aData*/,bool aImmediate)
       
   786     {
       
   787     // Must contain both KPositionX and KPositionY
       
   788     AlfAttribute& attrX = aContainer.getAttributeByName(KPositionX);
       
   789     AlfAttribute& attrY = aContainer.getAttributeByName(KPositionY);
       
   790 
       
   791     TAlfTimedPoint pos(aVisual.Pos());
       
   792     SetSourceValues(pos, attrX, attrY);
       
   793 
       
   794     pos.iX.SetStyle(attrX.getInterpolationStyle());
       
   795     pos.iX.SetTarget(attrX.realValue(), getTime(attrX, aImmediate));
       
   796     pos.iY.SetStyle(attrY.getInterpolationStyle());
       
   797     pos.iY.SetTarget(attrY.realValue(), getTime(attrY, aImmediate));
       
   798 
       
   799     aVisual.SetPos(pos);
       
   800 
       
   801 
       
   802     attrX.setDirty(false);
       
   803     attrY.setDirty(false);
       
   804     }
       
   805 
       
   806 void AlfCommonVisualAttributeSetter::setRect(CAlfVisual &aVisual,AlfAttributeContainer& aContainer,IAlfMap* /*aData*/,bool aImmediate)
       
   807     {
       
   808     //If topleftx exists, topy, bottomx and bottomy must exists also
       
   809     AlfAttribute& attrTopX =
       
   810         aContainer.getAttributeByName(KTopLeftX);
       
   811     AlfAttribute& attrTopY =
       
   812         aContainer.getAttributeByName(KTopLeftY);
       
   813     AlfAttribute& attrBottomRightX =
       
   814         aContainer.getAttributeByName(KBottomRightX);
       
   815     AlfAttribute& attrBottomRightY =
       
   816         aContainer.getAttributeByName(KBottomRightY);
       
   817 
       
   818     const TAlfRealPoint sTopLeft(aVisual.Pos().ValueNow());
       
   819     TAlfRealPoint size(aVisual.Size().ValueNow());
       
   820     TAlfRealRect sRect(sTopLeft, TAlfRealPoint(sTopLeft.iX + size.iX,
       
   821                        sTopLeft.iY + size.iY));
       
   822 
       
   823     SetSourceRect(sRect, attrTopX, attrTopY, attrBottomRightX,
       
   824                   attrBottomRightY);
       
   825 
       
   826     aVisual.SetRect(sRect, 0);
       
   827 
       
   828     TAlfRealPoint tTopLeft(attrTopX.realValue(), attrTopY.realValue());
       
   829     TAlfRealPoint tBottomRight(attrBottomRightX.realValue(),
       
   830                                attrBottomRightY.realValue());
       
   831     TAlfRealRect tRealRect(tTopLeft, tBottomRight);
       
   832 
       
   833     int time = getTime(attrTopX, aImmediate);
       
   834     aVisual.SetRect(tRealRect, time);
       
   835 
       
   836 
       
   837     attrTopX.setDirty(false);
       
   838     attrTopY.setDirty(false);
       
   839     attrBottomRightX.setDirty(false);
       
   840     attrBottomRightY.setDirty(false);
       
   841 
       
   842     }
       
   843 } // Alf