widgetmodel/alfwidgetmodel/src/alflctanchorlayoutattributesetter.cpp
changeset 0 e83bab7cf002
equal deleted inserted replaced
-1:000000000000 0:e83bab7cf002
       
     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 lct anchor layout.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //includes
       
    20 
       
    21 //widget model includes
       
    22 #include "alf/alfattributecontainer.h"
       
    23 #include "alf/alfattributevaluetype.h"
       
    24 #include "alf/alfattribute.h"
       
    25 #include "alf/alflctanchorlayoutattributesetter.h"
       
    26 #include <alf/alfvisualexception.h>
       
    27 #include <alf/alfdataexception.h>
       
    28 
       
    29 //osn includes
       
    30 #include <osn/ustring.h>
       
    31 
       
    32 //alf includes
       
    33 #include <alf/alfenv.h>
       
    34 #include <alf/alfdisplay.h>
       
    35 #include <alf/alflctanchorlayout.h>
       
    36 
       
    37 //dui includes
       
    38 #include "alf/attrproperty.h"
       
    39 #include <alf/alftimedvalue.h>
       
    40 //other includes
       
    41 #include <libc/string.h>
       
    42 #ifdef RD_ALF_IN_PLATFORM
       
    43 #include <aknlayout2hierarchy.h>
       
    44 #endif
       
    45 
       
    46 #include "AlfLctAttributeSetterUtils.h"
       
    47 
       
    48 using osncore::UString;
       
    49 
       
    50 using namespace duiuimodel::layoutattributes::grid;
       
    51 
       
    52 using namespace duiuimodel::lctvisualattributes;
       
    53 
       
    54 using namespace duiuimodel::anchorlayoutinput;
       
    55 
       
    56 namespace Alf
       
    57     {
       
    58 
       
    59 //variable inside ifdef to prevent compiler warning.
       
    60 #ifdef ALF_DEBUG_EXCEPTIONS
       
    61 static const char* const ClassName = "AlfLCTAnchorLayoutAttributeSetter";
       
    62 #endif
       
    63 
       
    64 // ======== MEMBER FUNCTIONS ========
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // Constructor.
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 OSN_EXPORT AlfLCTAnchorLayoutAttributeSetter::AlfLCTAnchorLayoutAttributeSetter()
       
    71     {
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Destructor.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 OSN_EXPORT AlfLCTAnchorLayoutAttributeSetter::~AlfLCTAnchorLayoutAttributeSetter()
       
    79     {
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Sets Attribute Value. Delegates based on attribute Category.
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 OSN_EXPORT void AlfLCTAnchorLayoutAttributeSetter::setAttributeValue(
       
    87     CAlfVisual &aVisual,
       
    88     AlfAttributeContainer* aContainer,
       
    89     IAlfMap* aData )
       
    90     {
       
    91     CAlfLCTAnchorLayout* anchorlayout =
       
    92         dynamic_cast<CAlfLCTAnchorLayout*>(&aVisual);
       
    93 
       
    94     if ( !anchorlayout )
       
    95         {
       
    96         ALF_THROW(AlfVisualException, EInvalidVisual, ClassName)
       
    97         }
       
    98 
       
    99     AlfAnchorLayoutAttributeSetter::setAttributeValue(
       
   100         aVisual, aContainer, aData);
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // Deprecated
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 OSN_EXPORT TAlfCommand* AlfLCTAnchorLayoutAttributeSetter::createCommand(
       
   108     CAlfVisual& /*aVisual*/,
       
   109     AlfAttributeContainer* /*aContainer*/, IAlfMap* /*aData*/,
       
   110      int /*aTransitionTime*/, CAlfVisual* /*aRefVisual*/ )
       
   111     {
       
   112     //deprecated
       
   113     TAlfCommand* cmd = 0;
       
   114     return cmd;
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // Sends a command to Env
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 OSN_EXPORT void AlfLCTAnchorLayoutAttributeSetter::createAndSendCommands(
       
   122     CAlfVisual& aVisual,
       
   123     AlfAttributeContainer* aContainer,
       
   124     CAlfVisual* aRefVisual )
       
   125     {
       
   126     AlfAnchorLayoutAttributeSetter::createAndSendCommands(
       
   127         aVisual, aContainer, aRefVisual);
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // Sets dynamic attributes to visual
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 void AlfLCTAnchorLayoutAttributeSetter::handleDynamicAttribute(
       
   135     CAlfVisual& aVisual,
       
   136     AlfAttribute& aAttr, 
       
   137     AlfAttributeContainer& aContainer)
       
   138     {
       
   139     const char* attrName = aAttr.name();
       
   140 
       
   141 #ifdef RD_ALF_IN_PLATFORM
       
   142     if ( !strcmp ( attrName, KLCT ) )
       
   143         {
       
   144         TAknLayoutHierarchyComponentHandle componentHandle =
       
   145             AlfLctAttributeSetterUtils::getCommonLctAttributes(&aContainer);
       
   146 
       
   147         int width(0);
       
   148         int height(0);
       
   149         if (AlfLctAttributeSetterUtils::itemSize(componentHandle, 
       
   150             width, height))
       
   151             {
       
   152             TInt displayWidth = 
       
   153                 aVisual.Env().PrimaryDisplay().VisibleArea().Width();
       
   154             if (width > displayWidth)
       
   155                 {
       
   156                 width = displayWidth;
       
   157                 }
       
   158                 
       
   159             TAlfTimedPoint size(width, height);
       
   160             aVisual.SetSize(size);
       
   161             }
       
   162         }
       
   163     else
       
   164 #endif
       
   165     if (strcmp(attrName,KRows) && 
       
   166         strcmp(attrName,KColumns) && 
       
   167         strcmp(attrName,KChildOrdinal))
       
   168         {
       
   169         AlfAnchorLayoutAttributeSetter::handleDynamicAttribute(
       
   170             aVisual, aAttr, aContainer);
       
   171         }
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // Sets static attributes to visual
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 void AlfLCTAnchorLayoutAttributeSetter::handleStaticAttribute(
       
   179     CAlfVisual &aVisual,
       
   180     AlfAttribute& aAttr, 
       
   181     AlfAttributeContainer& aContainer)
       
   182     {
       
   183     CAlfLCTAnchorLayout* anchorlayout = 
       
   184         dynamic_cast<CAlfLCTAnchorLayout*>(&aVisual);
       
   185         
       
   186     const char* attrName = aAttr.name();
       
   187     
       
   188 #ifdef RD_ALF_IN_PLATFORM
       
   189     if ( !strcmp ( attrName, KLCT ) )
       
   190         {
       
   191         TAknLayoutHierarchyComponentHandle componentHandle =
       
   192             AlfLctAttributeSetterUtils::getCommonLctAttributes(&aContainer);
       
   193 
       
   194         int width(0);
       
   195         int height(0);
       
   196         if (AlfLctAttributeSetterUtils::itemSize(componentHandle, 
       
   197             width, height))
       
   198             {
       
   199             // Some cases returns wrong width, so check that width is reasonable
       
   200             TInt displayWidth = 
       
   201                 aVisual.Env().PrimaryDisplay().VisibleArea().Width();
       
   202             if (width > displayWidth)
       
   203                 {
       
   204                 width = displayWidth;
       
   205                 }
       
   206             TAlfTimedPoint size(width, height);
       
   207             aVisual.SetSize(size);
       
   208             }
       
   209         }
       
   210     else if ( !strcmp(attrName, KRows)||
       
   211             !strcmp (attrName,KColumns) || !strcmp(attrName,KChildOrdinal) )
       
   212         {
       
   213         TAknLayoutHierarchyComponentHandle componentHandle =
       
   214             AlfLctAttributeSetterUtils::getCommonLctAttributes(&aContainer);
       
   215         AlfAttribute& attrRows = aContainer.getAttributeByName(KRows);
       
   216         AlfAttribute& attrCols = aContainer.getAttributeByName(KColumns);
       
   217         AlfAttribute& attrOrdinal = 
       
   218             aContainer.getAttributeByName(KChildOrdinal);
       
   219         componentHandle.SetColumn(attrCols.realValue());
       
   220         componentHandle.SetRow(attrRows.realValue());
       
   221         TAlfTimedPoint timedpoint(attrCols.getSourceValue()->realValue(),
       
   222                                   attrRows.getSourceValue()->realValue());
       
   223 
       
   224         //since static, effect will be immediate
       
   225         timedpoint.iX.SetTarget(attrCols.getTargetValue()->realValue(), 0);
       
   226         timedpoint.iY.SetTarget(attrRows.getTargetValue()->realValue(), 0);
       
   227 
       
   228         timedpoint.iX.SetStyle(attrCols.getInterpolationStyle());
       
   229         timedpoint.iY.SetStyle(attrRows.getInterpolationStyle());
       
   230 
       
   231         //TO ADD: Mapping Function Identifiers
       
   232         anchorlayout->SetAnchors(attrOrdinal.intValue(), 
       
   233             componentHandle, timedpoint);
       
   234         attrRows.setDirty(false);
       
   235         attrCols.setDirty(false);
       
   236         attrOrdinal.setDirty(false);
       
   237         }
       
   238     else
       
   239 #endif
       
   240         {
       
   241         AlfAnchorLayoutAttributeSetter::handleStaticAttribute(aVisual, aAttr,
       
   242                 aContainer);
       
   243         }
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // Sets dynamic attributes to visual from data
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 void AlfLCTAnchorLayoutAttributeSetter::handleDynamicDataAttribute(
       
   251     CAlfVisual &aVisual,
       
   252     AlfAttribute& aAttr, 
       
   253     AlfAttributeContainer& aContainer, 
       
   254     IAlfMap* aData )
       
   255     {
       
   256     AlfAnchorLayoutAttributeSetter::handleDynamicDataAttribute(aVisual, aAttr,
       
   257             aContainer, aData);
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // Sets static attributes to visual  from data
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 void AlfLCTAnchorLayoutAttributeSetter::handleStaticDataAttribute(
       
   265     CAlfVisual &aVisual,
       
   266     AlfAttribute& aAttr, 
       
   267     AlfAttributeContainer& aContainer, 
       
   268     IAlfMap* aData )
       
   269     {
       
   270     AlfAnchorLayoutAttributeSetter::handleStaticDataAttribute(aVisual, aAttr,
       
   271             aContainer, aData);
       
   272     }
       
   273 
       
   274     } // namespace Alf
       
   275 
       
   276 // End of file
       
   277 
       
   278 
       
   279 
       
   280 
       
   281