widgetmodel/alfwidgetmodel/src/alfviewportlayoutattributesetter.cpp
branchRCL_3
changeset 26 0e9bb658ef58
parent 0 e83bab7cf002
equal deleted inserted replaced
25:4ea6f81c838a 26:0e9bb658ef58
       
     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 ViewPortLayout.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //includes
       
    21 
       
    22 //widget model includes
       
    23 #include "alf/alfattributecontainer.h"
       
    24 #include "alf/alfattribute.h"
       
    25 #include "alf/alfviewportlayoutattributesetter.h"
       
    26 #include <alf/alfvisualexception.h>
       
    27 #include <alf/alfdataexception.h>
       
    28 #include <alf/alfattributeexception.h>
       
    29 
       
    30 //osn includes
       
    31 #include <osn/ustring.h>
       
    32 
       
    33 //alf includes
       
    34 #include <alf/alfvisual.h>
       
    35 #include <alf/alfviewportlayout.h>
       
    36 
       
    37 //dui includes
       
    38 #include "alf/attrproperty.h"
       
    39 
       
    40 //other includes
       
    41 #include <libc/string.h>
       
    42 
       
    43 
       
    44 
       
    45 //namespaces
       
    46 using namespace osncore;
       
    47 using namespace duiuimodel::layoutattributes::viewport;
       
    48 
       
    49 namespace Alf
       
    50     {
       
    51 
       
    52 // ======== MEMBER FUNCTIONS ========
       
    53 
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // Constructor.
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 OSN_EXPORT AlfViewportLayoutAttributeSetter::AlfViewportLayoutAttributeSetter()
       
    60     {
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // Destructor.
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 OSN_EXPORT AlfViewportLayoutAttributeSetter::
       
    68     ~AlfViewportLayoutAttributeSetter()
       
    69     {
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 IAlfVariantType* AlfViewportLayoutAttributeSetter::getData(
       
    76     AlfAttribute& aAttr, IAlfMap* aData)
       
    77     {
       
    78     IAlfVariantType* data = 0;
       
    79     const char* dataField = aAttr.getDataField();
       
    80     if (dataField)
       
    81         {
       
    82         data = aData->item(UString(dataField));
       
    83         }
       
    84     return data;
       
    85     }
       
    86 
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 int AlfViewportLayoutAttributeSetter::getTime(
       
    92     const AlfAttribute& aAttr, bool aImmediate)
       
    93     {
       
    94     int time = 0;
       
    95     if (!aImmediate)
       
    96         {
       
    97         time = aAttr.getTime();
       
    98         }
       
    99     return time;
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 OSN_EXPORT void AlfViewportLayoutAttributeSetter::setAttributeValue(
       
   106     CAlfVisual &aVisual, AlfAttributeContainer* aContainer, IAlfMap* aData)
       
   107     {
       
   108     CAlfViewportLayout* viewportLayout = 
       
   109         dynamic_cast<CAlfViewportLayout*>(&aVisual);
       
   110     if (!viewportLayout)
       
   111         {
       
   112         ALF_THROW (AlfVisualException, EInvalidVisual, "AlfViewportLayoutAttributeSetter")
       
   113         }     
       
   114     AlfCommonLayoutAttributeSetter::setAttributeValue(aVisual,
       
   115                                         aContainer, aData);
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 OSN_EXPORT TAlfCommand* AlfViewportLayoutAttributeSetter::createCommand(
       
   122     CAlfVisual& /*aVisual*/, AlfAttributeContainer* /*aContainer*/,
       
   123     IAlfMap* /*aData*/, int /*aTransitionTime*/, CAlfVisual* /*aRefVisual*/)
       
   124     {
       
   125     TAlfCommand* cmd = 0;
       
   126     return cmd;
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 OSN_EXPORT void AlfViewportLayoutAttributeSetter::createAndSendCommands(
       
   133     CAlfVisual& aVisual,
       
   134     AlfAttributeContainer* aContainer,
       
   135     CAlfVisual* aRefVisual )
       
   136     {
       
   137     // Call the base class implementation.
       
   138     // It goes through its loop and checks if there are attributes that it
       
   139     // handles.
       
   140     AlfCommonLayoutAttributeSetter::createAndSendCommands(aVisual,
       
   141                                         aContainer,aRefVisual);
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void AlfViewportLayoutAttributeSetter::handleDynamicDataAttribute(
       
   148     CAlfVisual& aVisual, AlfAttribute& aAttr,
       
   149     AlfAttributeContainer& aContainer, IAlfMap* aData)
       
   150     {
       
   151     if (!doHandleDynamicDataAttribute(aVisual, aAttr, aContainer, aData))
       
   152         {
       
   153         AlfCommonLayoutAttributeSetter::handleDynamicDataAttribute(aVisual,
       
   154                                             aAttr, aContainer, aData);
       
   155         }
       
   156     }
       
   157 // ---------------------------------------------------------------------------
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 bool AlfViewportLayoutAttributeSetter::doHandleDynamicDataAttribute(
       
   161     CAlfVisual& aVisual, AlfAttribute& aAttr,
       
   162     AlfAttributeContainer& aContainer, IAlfMap* aData, bool aImmediate)
       
   163     {
       
   164     CAlfViewportLayout* viewportLayout = 
       
   165         dynamic_cast<CAlfViewportLayout*>(&aVisual);
       
   166     if (!viewportLayout)
       
   167         {
       
   168         ALF_THROW (AlfVisualException, EInvalidVisual, "AlfViewportLayoutAttributeSetter")
       
   169         }
       
   170     bool handled = true;
       
   171     if (!aData)
       
   172         {
       
   173         ALF_THROW (AlfDataException, EInvalidVariantDataType, "AlfViewportLayoutAttributeSetter" )
       
   174         }
       
   175     else
       
   176         {
       
   177         const char* attrName = aAttr.name();
       
   178         if (!strcmp( attrName, KVirtualHeight)) //also handles: KVirtualWidth
       
   179             {
       
   180             // item for both virtual height and virtual width should be there.
       
   181             const IAlfVariantType* virtualHeight = getData(aAttr, aData);
       
   182             const IAlfVariantType* virtualWidth = 
       
   183                 getData(aContainer.getAttributeByName(KVirtualWidth), aData);
       
   184 
       
   185             if (virtualHeight && 
       
   186                 virtualHeight->type() == IAlfVariantType::EReal &&
       
   187                 virtualWidth && virtualWidth->type() == IAlfVariantType::EReal)
       
   188                 {
       
   189                 viewportLayout->SetVirtualSize(
       
   190                     TAlfRealSize(virtualWidth->real(),virtualHeight->real()),
       
   191                     getTime(aAttr, aImmediate));
       
   192                 }
       
   193             else
       
   194                 {
       
   195                 ALF_THROW(AlfDataException, EInvalidVariantDataType, "AlfViewportLayoutAttributeSetter")
       
   196                 }
       
   197 
       
   198             }
       
   199         else if (!strcmp( attrName, KVirtualWidth))
       
   200             {
       
   201             // both virtual height and virtual width should be there
       
   202             // if attribute for virtual height exists,don't do anything as this
       
   203             // will be taken care while looking for attribute for virtual 
       
   204             // height, else throw exception
       
   205             try
       
   206                 {
       
   207                 AlfAttribute& attrWidth = 
       
   208                     aContainer.getAttributeByName (KVirtualHeight );
       
   209                 }
       
   210 
       
   211             catch (...)
       
   212                 {
       
   213                 ALF_THROW(AlfDataException, EIncompleteAttributeValues, "AlfViewportLayoutAttributeSetter")
       
   214                 }
       
   215             }
       
   216         //also handles: KViewportWidth    
       
   217         else if (!strcmp( attrName, KViewportHeight)) 
       
   218             {
       
   219             // item for both viewport window height and viewport window width
       
   220             // should be there.
       
   221             const IAlfVariantType* viewportHeight = getData(aAttr, aData);
       
   222             const IAlfVariantType* viewportWidth = 
       
   223                 getData(aContainer.getAttributeByName(KViewportWidth), aData);
       
   224 
       
   225             if (viewportHeight &&
       
   226                 viewportHeight->type() == IAlfVariantType::EReal &&
       
   227                 viewportWidth && 
       
   228                 viewportWidth->type() == IAlfVariantType::EReal)
       
   229                 {
       
   230                 viewportLayout->SetViewportSize(
       
   231                     TAlfRealSize(viewportWidth->real(),viewportHeight->real()),
       
   232                     getTime(aAttr, aImmediate));
       
   233                 }
       
   234             else
       
   235                 {
       
   236                 ALF_THROW(AlfDataException, EInvalidVariantDataType, "AlfViewportLayoutAttributeSetter")
       
   237                 }    
       
   238             }
       
   239         else if (!strcmp( attrName, KViewportWidth))
       
   240             {
       
   241             // both viewport height and viewport width should be there
       
   242             // if attribute for viewport height exists,don't do anything as
       
   243             // this will be taken care while looking for attribute for 
       
   244             // virtual height, else throw exception
       
   245             try
       
   246                 {
       
   247                 AlfAttribute& attrWidth = 
       
   248                     aContainer.getAttributeByName (KViewportHeight );
       
   249                 }
       
   250 
       
   251             catch (...)
       
   252                 {
       
   253                 ALF_THROW(AlfDataException, EIncompleteAttributeValues, "AlfViewportLayoutAttributeSetter")
       
   254                 }
       
   255             }
       
   256         //also handles: KViewportPositionY    
       
   257         else if (!strcmp( attrName, KViewportPositionX)) 
       
   258             {
       
   259             // item for both viewport window X-position and Y-position 
       
   260             // should be there.
       
   261             const IAlfVariantType* viewportPosX = getData(aAttr, aData);
       
   262             const IAlfVariantType* viewportPosY = 
       
   263                    getData(aContainer.getAttributeByName(KViewportPositionY),
       
   264                            aData);
       
   265 
       
   266             if (viewportPosX &&
       
   267                 viewportPosX->type() == IAlfVariantType::EReal &&
       
   268                 viewportPosY && viewportPosY->type() == IAlfVariantType::EReal)
       
   269                 {
       
   270                 viewportLayout->SetViewportPos(
       
   271                     TAlfRealPoint(viewportPosX->real(),viewportPosY->real()),
       
   272                     getTime(aAttr, aImmediate));
       
   273                 }
       
   274             else
       
   275                 {
       
   276                 ALF_THROW(AlfDataException, EInvalidVariantDataType, "AlfViewportLayoutAttributeSetter")
       
   277                 }    
       
   278             }
       
   279         else if (!strcmp( attrName, KViewportPositionY))
       
   280             {
       
   281             // both viewport window X-position and Y-position should be there
       
   282             // if attribute for viewport window X-position exists,don't do 
       
   283             // anything as this will be taken care while looking for attribute
       
   284             // for viewport window X-position, else throw exception
       
   285             try
       
   286                 {
       
   287                 AlfAttribute& attrWidth = 
       
   288                     aContainer.getAttributeByName (KViewportPositionX );
       
   289                 }
       
   290 
       
   291             catch (...)
       
   292                 {
       
   293                 ALF_THROW(AlfDataException, EIncompleteAttributeValues, "AlfViewportLayoutAttributeSetter")
       
   294                 }
       
   295             }
       
   296         else
       
   297             {
       
   298             handled = false;
       
   299             }
       
   300         }
       
   301     return handled;
       
   302     }
       
   303 
       
   304 void AlfViewportLayoutAttributeSetter::handleStaticDataAttribute(
       
   305     CAlfVisual &aVisual, AlfAttribute& aAttr, 
       
   306     AlfAttributeContainer& aContainer, IAlfMap* aData)
       
   307     {
       
   308     // viewport layout does not have any static attribute of its own
       
   309     // check, if dynamic attribute(but set by user as static), if so,
       
   310     // set attributes immediately.
       
   311     if (!doHandleDynamicDataAttribute(aVisual, aAttr,aContainer, aData, true))
       
   312         {
       
   313         AlfCommonLayoutAttributeSetter::handleStaticDataAttribute(
       
   314             aVisual, aAttr, aContainer, aData);
       
   315         }
       
   316     }
       
   317 
       
   318 void AlfViewportLayoutAttributeSetter::handleDynamicAttribute(
       
   319     CAlfVisual &aVisual, AlfAttribute& aAttr, 
       
   320     AlfAttributeContainer& aContainer)
       
   321     {
       
   322     if (!doHandleDynamicAttribute(aVisual, aAttr, aContainer))
       
   323         {
       
   324         AlfCommonLayoutAttributeSetter::handleDynamicAttribute(
       
   325             aVisual, aAttr, aContainer);
       
   326         }
       
   327     }
       
   328 
       
   329 bool AlfViewportLayoutAttributeSetter::doHandleDynamicAttribute(
       
   330     CAlfVisual &aVisual, AlfAttribute& aAttr,
       
   331     AlfAttributeContainer& aContainer, bool aImmediate)
       
   332     {
       
   333     CAlfViewportLayout* viewportLayout = 
       
   334         dynamic_cast<CAlfViewportLayout*>(&aVisual);
       
   335     if (!viewportLayout)
       
   336         {
       
   337         ALF_THROW (AlfVisualException, EInvalidVisual, "AlfViewportLayoutAttributeSetter")
       
   338         }
       
   339 
       
   340     bool handled = true;
       
   341     const char* attrName = aAttr.name();
       
   342     if (!strcmp(attrName, KVirtualHeight)||!strcmp(attrName, KVirtualWidth))
       
   343         {
       
   344         // both virtual height and virtual width should be there.
       
   345         AlfAttribute& attrWidth = 
       
   346             aContainer.getAttributeByName (KVirtualWidth );
       
   347         AlfAttribute& attrHt = aContainer.getAttributeByName (KVirtualHeight );
       
   348         if(attrWidth.type() == AlfAttributeValueType::EFloat &&
       
   349                attrHt.type() == AlfAttributeValueType::EFloat )
       
   350             {
       
   351             float height = attrHt.realValue();
       
   352             float width = attrWidth.realValue();
       
   353             viewportLayout->SetVirtualSize(
       
   354                 TAlfRealSize(width,height),getTime(attrHt, aImmediate));
       
   355             attrHt.setDirty(false);
       
   356             attrWidth.setDirty(false);
       
   357             }
       
   358         else
       
   359             {
       
   360             ALF_THROW ( AlfAttributeException, EInvalidAttributeValue, "AlfViewportLayoutAttributeSetter");
       
   361             }
       
   362         }
       
   363     else if (!strcmp(attrName, KViewportHeight)||
       
   364              !strcmp(attrName, KViewportWidth))
       
   365         {
       
   366         // both viewport window height and width should be there.
       
   367         AlfAttribute& attrWidth = 
       
   368             aContainer.getAttributeByName (KViewportWidth );
       
   369         AlfAttribute& attrHt = 
       
   370             aContainer.getAttributeByName (KViewportHeight );
       
   371         if(attrWidth.type() == AlfAttributeValueType::EFloat &&
       
   372                attrHt.type() == AlfAttributeValueType::EFloat )
       
   373             {
       
   374             float height = attrHt.realValue();
       
   375             float width = attrWidth.realValue();
       
   376             viewportLayout->SetViewportSize(
       
   377                 TAlfRealSize(width,height),getTime(attrHt, aImmediate));
       
   378             attrHt.setDirty(false);
       
   379             attrWidth.setDirty(false);
       
   380             }
       
   381         else
       
   382             {
       
   383             ALF_THROW ( AlfAttributeException, EInvalidAttributeValue, "AlfViewportLayoutAttributeSetter");
       
   384             }
       
   385         }
       
   386     else if (!strcmp(attrName, KViewportPositionX)||
       
   387              !strcmp(attrName, KViewportPositionY))
       
   388         {
       
   389         // both viewport window X-position and Y-position should be there.
       
   390         AlfAttribute& attrWidth = 
       
   391             aContainer.getAttributeByName (KViewportPositionY );
       
   392         AlfAttribute& attrHt = 
       
   393             aContainer.getAttributeByName (KViewportPositionX );
       
   394         if(attrWidth.type() == AlfAttributeValueType::EFloat &&
       
   395                attrHt.type() == AlfAttributeValueType::EFloat )
       
   396             {
       
   397             float xPosition = attrHt.realValue();
       
   398             float yPosition = attrWidth.realValue();
       
   399             viewportLayout->SetViewportPos(
       
   400                TAlfRealPoint(xPosition,yPosition),getTime(attrHt, aImmediate));
       
   401             attrHt.setDirty(false);
       
   402             attrWidth.setDirty(false);
       
   403             }
       
   404         else
       
   405             {
       
   406             ALF_THROW ( AlfAttributeException, EInvalidAttributeValue, "AlfViewportLayoutAttributeSetter");
       
   407             }
       
   408         }
       
   409     else
       
   410         {
       
   411         handled = false;
       
   412         }
       
   413 
       
   414     return handled;
       
   415     }
       
   416 
       
   417 void AlfViewportLayoutAttributeSetter::handleStaticAttribute(
       
   418     CAlfVisual& aVisual, AlfAttribute& aAttr,
       
   419     AlfAttributeContainer& aContainer)
       
   420     {
       
   421     // viewport layout does not have any static attribute of its own
       
   422     // check, if dynamic attribute(but set as static by the user),
       
   423     // if so, set attributes immediately.
       
   424     if (!doHandleDynamicAttribute(aVisual, aAttr, aContainer, true))
       
   425         {
       
   426         AlfCommonLayoutAttributeSetter::handleStaticAttribute(aVisual, aAttr, 
       
   427                                             aContainer);
       
   428         }
       
   429     }
       
   430     
       
   431     } // Alf
       
   432