widgetmodel/alfwidgetmodel/src/alfelementattributeownerimpl.cpp
branchRCL_3
changeset 25 4ea6f81c838a
parent 23 514d98f21c43
child 26 0e9bb658ef58
equal deleted inserted replaced
23:514d98f21c43 25:4ea6f81c838a
     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:  Implementation of the IAlfAttributeOwner interface 
       
    15 *                for AlfElement.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <alf/alfexceptions.h>
       
    21 #include "alf/alfattribute.h"
       
    22 #include "alf/alfattributecontainer.h"
       
    23 #include "alf/ialfvisualtemplate.h"
       
    24 #include <alf/alfwidgetcontrol.h>
       
    25 #include "alf/ialfattributesetter.h"
       
    26 #include "alf/alfcommonvisualattributesetter.h"
       
    27 #include "alf/alfelement.h"
       
    28 #include <osn/ustring.h>
       
    29 #include "alf/attrproperty.h"
       
    30 #include <alf/alfwidgetcommand.h>
       
    31 
       
    32 
       
    33 #include "alfelementattributeownerimpl.h"
       
    34 
       
    35 using namespace duiuimodel;
       
    36 
       
    37 namespace Alf
       
    38     {
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Constructor.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 AlfElementAttributeOwnerImpl::AlfElementAttributeOwnerImpl(
       
    45     AlfElement& aElement, CAlfWidgetControl& aControl) :
       
    46     mElement(aElement), mControl(aControl)
       
    47     {
       
    48     mAttributeList.setAutoDelete(true);    
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // Destructor.
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 AlfElementAttributeOwnerImpl::~AlfElementAttributeOwnerImpl()
       
    56     {
       
    57     mAttributeList.clear();
       
    58     }
       
    59     
       
    60 // ---------------------------------------------------------------------------
       
    61 // From class IAlfInterfaceBase.
       
    62 // Getter for interfaces provided by the element.
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 IAlfInterfaceBase* AlfElementAttributeOwnerImpl::makeInterface(
       
    66     const IfId& aType)
       
    67     {
       
    68     UString param(aType.mImplementationId);
       
    69     if (param == IAlfAttributeOwner::type().mImplementationId)
       
    70         {
       
    71     	return static_cast<IAlfAttributeOwner*>(this);
       
    72         }
       
    73     return 0;
       
    74     }    
       
    75         
       
    76 // ---------------------------------------------------------------------------
       
    77 // Get the number of available attributes.
       
    78 // From class IAlfAttributeOwner.
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 int AlfElementAttributeOwnerImpl::attributeCount() const
       
    82     {
       
    83     return mAttributeList.count();
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // Gets the attribute with the given name.
       
    88 // From class IAlfAttributeOwner.
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 const AlfAttribute* AlfElementAttributeOwnerImpl::getAttribute(
       
    92     const UString& aAttribName) const
       
    93     {
       
    94     AlfAttribute* attribute = 0;
       
    95  	for (int i = 0; i < mAttributeList.count(); i++)
       
    96  	    {
       
    97  		if (!strcmp(aAttribName.getUtf8(), mAttributeList[i]->name()))
       
    98  		    {
       
    99  			attribute = mAttributeList[i];
       
   100  			break;
       
   101  		    }
       
   102  	    }
       
   103     return attribute;
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Set a value of an attribute.
       
   108 // From class IAlfAttributeOwner.
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 bool AlfElementAttributeOwnerImpl::setAttribute(const AlfAttribute& aAttribute)
       
   112     {
       
   113     // The attribute must have at least one value set.
       
   114     if (!aAttribute.getTargetValueCount())
       
   115         {
       
   116         ALF_THROW(
       
   117             AlfAttributeException, EInvalidAttribute, "AlfElementAttributeOwnerImpl")
       
   118         }
       
   119     
       
   120     if (!canHandleAttribute(aAttribute.name()))
       
   121         {
       
   122         return false;
       
   123         }
       
   124     
       
   125     // Check whether the attribute exists already.
       
   126     int i = 0;
       
   127     for (i = 0; i < mAttributeList.count() ; i++)
       
   128  	    {
       
   129  		if (!strcmp(aAttribute.name(), mAttributeList[i]->name()))
       
   130  		    {
       
   131  		    // Attribute exists already, modify the contents.
       
   132  			*mAttributeList[i] = aAttribute;
       
   133  			handleAttribute(*mAttributeList[i]);
       
   134  			return true;
       
   135  		    }
       
   136         }
       
   137 
       
   138     // Attribute with the given name does not exist,
       
   139     // clone the given attribute and insert it in the list.
       
   140     mAttributeList.resize(mAttributeList.count() + 1);
       
   141     // Insert cannot fail because already resized.
       
   142     mAttributeList.insert(mAttributeList.count(),
       
   143         const_cast<AlfAttribute&>(aAttribute).clone());
       
   144     
       
   145     handleAttribute(*mAttributeList[i]);
       
   146     return true;
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // Set a value of an attribute.
       
   151 // From class IAlfAttributeOwner.
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 bool AlfElementAttributeOwnerImpl::setAttribute(
       
   155     const UString& aAttribName, AlfAttributeValueType* aValue)
       
   156     {
       
   157     if (!aValue)
       
   158         {
       
   159         ALF_THROW(
       
   160             AlfAttributeException, EInvalidAttribute, "AlfElementAttributeOwnerImpl")
       
   161         }
       
   162     
       
   163     // Create a new attribute.
       
   164     auto_ptr<AlfAttribute> attribute(
       
   165         new (EMM) AlfAttribute(aAttribName.getUtf8(), AlfAttribute::EStatic));
       
   166     attribute->addTargetValue(aValue);
       
   167  
       
   168     return setAttribute(*attribute.get());
       
   169     }      
       
   170 // ---------------------------------------------------------------------------
       
   171 // Set a value of an attribute.
       
   172 // From class IAlfAttributeOwner.
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 bool AlfElementAttributeOwnerImpl::setAttribute( const UString& aTargetId , 
       
   176 												 AlfAttribute& aAttribute ) 
       
   177 	{
       
   178   	bool ret(false);
       
   179   
       
   180 	// The attribute must have at least one value set.
       
   181 	if (!aAttribute.getTargetValueCount())
       
   182 		{
       
   183 		ALF_THROW(
       
   184 		    AlfAttributeException, EInvalidAttribute, "AlfElementAttributeOwnerImpl")
       
   185 		}
       
   186 
       
   187 	//check targetId
       
   188 	if (!aTargetId.isEmpty() 
       
   189 	 && !aTargetId.compare(mElement.name()) )
       
   190 		{
       
   191 		ret = setAttribute(aAttribute);
       
   192 		}
       
   193 
       
   194   	return ret;
       
   195   	}
       
   196 
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // Set a value of an attribute.
       
   200 // From class IAlfAttributeOwner.
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 bool AlfElementAttributeOwnerImpl::setAttribute( const UString& aTargetId, 
       
   204 												 const UString& aAttribName,
       
   205  												 AlfAttributeValueType* aValue )
       
   206 	{
       
   207 	bool ret(false);
       
   208 	
       
   209 	if (!aValue)
       
   210 		{
       
   211 		ALF_THROW(
       
   212 		    AlfAttributeException, EInvalidAttribute, "AlfElementAttributeOwnerImpl")
       
   213 		}
       
   214 	
       
   215 	if (!aTargetId.isEmpty())
       
   216 		{
       
   217 		 // Create a new static attribute.
       
   218 	    auto_ptr<AlfAttribute> attribute(
       
   219 	        new (EMM) AlfAttribute(aAttribName.getUtf8(), AlfAttribute::EStatic));
       
   220 	    attribute->addTargetValue(aValue);
       
   221 	 
       
   222 	    ret = setAttribute(*attribute.get());
       
   223 	
       
   224 		}
       
   225 			
       
   226 	return ret;
       
   227 		
       
   228 	} 
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // Gets the attribute with the given name.
       
   232 // From class IAlfAttributeOwner.
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 const AlfAttribute* AlfElementAttributeOwnerImpl::getAttribute( const UString& aTargetId ,
       
   236 															    const UString& aAttribName ) const
       
   237 	{
       
   238 	const AlfAttribute* attr(0);
       
   239 
       
   240 	//check targetId
       
   241 	if (!aTargetId.isEmpty() 
       
   242 	     && !aTargetId.compare(mElement.name()))
       
   243 		{
       
   244 		attr = getAttribute(aAttribName); 
       
   245 		}
       
   246 		
       
   247 	return attr;
       
   248 	}
       
   249 	
       
   250 // ---------------------------------------------------------------------------
       
   251 // Sets the attributes from container
       
   252 // From class IAlfAttributeOwner.
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 bool AlfElementAttributeOwnerImpl::setAttributeContainer( AlfAttributeContainer& aAttributeContainer )
       
   256 	{
       
   257 
       
   258     const int attributeCount = aAttributeContainer.attributeCount();
       
   259 	int numAttributesHandled = 0;
       
   260 	
       
   261     for (int i = 0; i < attributeCount ; i++)
       
   262         {
       
   263         AlfAttribute& attribute = aAttributeContainer.getAttribute(i);
       
   264         if (!strcmp(attribute.name(), duiuimodel::tactileattributes::KEventInput))
       
   265             {
       
   266             
       
   267             // Look for feedback type attribute.
       
   268             try
       
   269               {
       
   270               AlfAttribute& feedBackType = 
       
   271               aAttributeContainer.getAttributeByName(duiuimodel::tactileattributes::KFeedbackType);
       
   272               handleTactileAttribute(attribute,feedBackType);
       
   273               numAttributesHandled += 2;
       
   274               }
       
   275             catch(AlfDataException& exception)
       
   276               {
       
   277               // attribute not found,so return false
       
   278               return false;
       
   279               }
       
   280             }
       
   281          
       
   282         else if(setAttribute(attribute))
       
   283             {
       
   284             numAttributesHandled++;
       
   285             }
       
   286 	    }
       
   287 
       
   288 
       
   289 	return (numAttributesHandled == attributeCount);
       
   290 	}
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // Handles the Tactile Attribute.
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void AlfElementAttributeOwnerImpl::handleTactileAttribute(
       
   297     AlfAttribute& aAttributeEvent,AlfAttribute& aAttributeFeedback)
       
   298     {
       
   299 	    IAlfVisualTemplate* visualTemplate = mElement.getVisualTemplate();
       
   300 		
       
   301 	    // Find the root layout 
       
   302 	    CAlfVisual* main = mElement.findVisual(0);//needs to be changed because in some cases id may be
       
   303 	    										  // set by the user	
       
   304 	    
       
   305 	    if(visualTemplate )
       
   306 	        {
       
   307 			AlfAttribute* attrEvent = NULL;
       
   308 			AlfAttribute* attrFeedback = NULL;
       
   309 
       
   310 	        int setterCount = visualTemplate->numAttributeSetters();
       
   311 	        bool found(false);
       
   312 	        for (int j = 0; j < setterCount ; j++)
       
   313 	            {
       
   314 	            AlfAttributeContainer& container = visualTemplate->attributeContainer(j);
       
   315 	            try
       
   316 	                {
       
   317 	                //find the attribute in each container until it is found
       
   318 	                attrEvent = &(container.getAttributeByName(duiuimodel::tactileattributes::KEventInput));
       
   319 	                attrFeedback = &(container.getAttributeByName(duiuimodel::tactileattributes::KFeedbackType));
       
   320 	                }
       
   321 	            catch(AlfDataException& exception)
       
   322 	                {
       
   323 	                // attribute not found,so continue
       
   324 	                continue;
       
   325 	                }
       
   326 	            //attribute found in one of the existing containers of the visual template, update it
       
   327 	            *attrEvent = aAttributeEvent;
       
   328 	            *attrFeedback = aAttributeFeedback;
       
   329 	            found = true;
       
   330 	            IAlfAttributeSetter& setter  = visualTemplate->attributeSetter(j);
       
   331 	            if(main)
       
   332 	            	setter.setAttributeValue(*main,&container,0);
       
   333 	            break;                                            
       
   334 	            }
       
   335 	        // attribute not found in any of the containers, so create one attribute container and one 
       
   336 	        // attribute setter and add both to the visual template        
       
   337 	        if (!found)
       
   338 	            {
       
   339 	            auto_ptr<AlfAttributeContainer> container( 
       
   340 	                new (EMM) AlfAttributeContainer());
       
   341 	            
       
   342 	            auto_ptr<AlfCommonVisualAttributeSetter> setter(
       
   343 	                new (EMM) AlfCommonVisualAttributeSetter());
       
   344 	                
       
   345 	            AlfAttribute* attribe =aAttributeEvent.clone();
       
   346 	            AlfAttribute* attribf =aAttributeFeedback.clone();
       
   347 
       
   348 	            container.get()->addAttribute(attribe);
       
   349 	            container.get()->addAttribute(attribf);
       
   350 	            if(main)
       
   351 	            setter.get()->setAttributeValue(*main, container.get(), 0);
       
   352 	            
       
   353 	            visualTemplate->addAttributeSetter(setter.release(), 
       
   354 	                container.release());
       
   355 	            }
       
   356 	        }
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------------------------
       
   360 // Sets the attributes from container using targetId
       
   361 // From class IAlfAttributeOwner.
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 bool AlfElementAttributeOwnerImpl::setAttributeContainer( const UString& aTargetId , 
       
   365                                AlfAttributeContainer& aAttributeContainer )
       
   366 	{
       
   367 
       
   368 
       
   369     const int attributeCount = aAttributeContainer.attributeCount();
       
   370 	int numAttributesHandled = 0;
       
   371 	
       
   372     for (int i = 0; i < attributeCount ; i++)
       
   373         {
       
   374         AlfAttribute& attribute = aAttributeContainer.getAttribute(i);
       
   375         if (!strcmp(attribute.name(), duiuimodel::tactileattributes::KEventInput))
       
   376         {
       
   377                 // Look for feedback type attribute.
       
   378         
       
   379         // Look for feedback type attribute.
       
   380         try
       
   381           {
       
   382           AlfAttribute& feedBackType = 
       
   383           aAttributeContainer.getAttributeByName(duiuimodel::tactileattributes::KFeedbackType);
       
   384           handleTactileAttribute(attribute,feedBackType);
       
   385           numAttributesHandled += 2;
       
   386           }
       
   387         catch(AlfDataException& exception)
       
   388           {
       
   389           // attribute not found,so return false
       
   390           return false;
       
   391           }
       
   392         }
       
   393        else if(setAttribute(aTargetId,attribute))
       
   394         {
       
   395         	numAttributesHandled++;
       
   396         }
       
   397 	    }
       
   398 
       
   399 	return (numAttributesHandled == attributeCount);
       
   400 		
       
   401 	}
       
   402     
       
   403 // ---------------------------------------------------------------------------
       
   404 // Handles the attribute, sets proper values.
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 void AlfElementAttributeOwnerImpl::handleAttribute(AlfAttribute& aAttribute)
       
   408     {
       
   409     const char* attrName = aAttribute.name();
       
   410     
       
   411     if (!strcmp(attrName, commonvisualattributes::KOpacity)) 
       
   412         {
       
   413         handleOpacityAttribute(aAttribute);
       
   414         }
       
   415     else if(!strcmp(attrName, layoutattributes::KPositionX) || 
       
   416             !strcmp(attrName, layoutattributes::KPositionY))
       
   417         {
       
   418         handlePositionAttribute(aAttribute);
       
   419         }
       
   420     else if(!strcmp(attrName, layoutattributes::KWidth) || 
       
   421             !strcmp(attrName, layoutattributes::KHeight))
       
   422         {
       
   423         handleSizeAttribute(aAttribute);
       
   424         }
       
   425     else if(!strcmp(attrName, layoutattributes::KMaxWidth) || 
       
   426             !strcmp(attrName, layoutattributes::KMaxHeight))
       
   427         {
       
   428         handleMaxSizeAttribute(aAttribute);
       
   429         }
       
   430     else if(!strcmp(attrName, layoutattributes::KMinWidth) || 
       
   431             !strcmp(attrName, layoutattributes::KMinHeight))
       
   432         {
       
   433         handleMinSizeAttribute(aAttribute);
       
   434         }        
       
   435     }
       
   436     
       
   437 // ---------------------------------------------------------------------------
       
   438 // Can attribute be handled with this widget.
       
   439 // ---------------------------------------------------------------------------
       
   440 //
       
   441 bool AlfElementAttributeOwnerImpl::canHandleAttribute(
       
   442     const char* aAttributeName)
       
   443     {
       
   444     bool canHandle(false);
       
   445     if (!strcmp(aAttributeName, commonvisualattributes::KOpacity) ||
       
   446         !strcmp(aAttributeName, layoutattributes::KPositionX) ||
       
   447         !strcmp(aAttributeName, layoutattributes::KPositionY) ||
       
   448         !strcmp(aAttributeName, layoutattributes::KWidth) ||
       
   449         !strcmp(aAttributeName, layoutattributes::KHeight) ||  
       
   450         !strcmp(aAttributeName, layoutattributes::KMaxWidth) ||
       
   451         !strcmp(aAttributeName, layoutattributes::KMaxHeight) ||  
       
   452         !strcmp(aAttributeName, layoutattributes::KMinWidth) ||
       
   453         !strcmp(aAttributeName, layoutattributes::KMinHeight))  
       
   454         {
       
   455         canHandle = true;
       
   456         }
       
   457     return canHandle;        
       
   458     }
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // Handles the Opacity Attribute.
       
   462 // ---------------------------------------------------------------------------
       
   463 //
       
   464 void AlfElementAttributeOwnerImpl::handleOpacityAttribute(
       
   465     AlfAttribute& aAttribute)
       
   466     {
       
   467     const char* attrName = aAttribute.name();
       
   468     
       
   469     IAlfVisualTemplate* visualTemplate = mElement.getVisualTemplate();
       
   470     
       
   471     // Find the root layout 
       
   472     CAlfVisual* main = mElement.findVisual(0);
       
   473     
       
   474     if(visualTemplate && main)
       
   475         {
       
   476         int setterCount = visualTemplate->numAttributeSetters();
       
   477         bool found(false);
       
   478         for (int j = 0; j < setterCount && main; j++)
       
   479             {
       
   480             AlfAttributeContainer& container = visualTemplate->attributeContainer(j);
       
   481             AlfAttribute* attr = NULL;
       
   482             try
       
   483                 {
       
   484                 //find the attribute in each container until it is found
       
   485                 attr = &(container.getAttributeByName(attrName));
       
   486                 }
       
   487             catch(AlfDataException& exception)
       
   488                 {
       
   489                 // attribute not found,so continue
       
   490                 continue;
       
   491                 }
       
   492             //attribute found in one of the existing containers of the visual template, update it
       
   493             *attr = aAttribute;
       
   494             found = true;
       
   495             IAlfAttributeSetter& setter  = visualTemplate->attributeSetter(j);
       
   496             setter.setAttributeValue(*main,&container,0);
       
   497             break;                                            
       
   498             }
       
   499         // attribute not found in any of the containers, so create one attribute container and one 
       
   500         // attribute setter and add both to the visual template        
       
   501         if (!found)
       
   502             {
       
   503             auto_ptr<AlfAttributeContainer> container( 
       
   504                 new (EMM) AlfAttributeContainer());
       
   505             auto_ptr<AlfCommonVisualAttributeSetter> setter(
       
   506                 new (EMM) AlfCommonVisualAttributeSetter());
       
   507             AlfAttribute* attribute =aAttribute.clone();
       
   508             container.get()->addAttribute(attribute);
       
   509            
       
   510             setter.get()->setAttributeValue(*main, container.get(), 0);
       
   511             visualTemplate->addAttributeSetter(setter.release(), 
       
   512                 container.release());
       
   513             }
       
   514         }
       
   515     }
       
   516 
       
   517 // ---------------------------------------------------------------------------
       
   518 // Handles the Position Attribute
       
   519 // ---------------------------------------------------------------------------
       
   520 //    
       
   521 void AlfElementAttributeOwnerImpl::handlePositionAttribute(AlfAttribute& aAttribute)
       
   522     {
       
   523     const char* attrName = aAttribute.name();
       
   524     const char* attrPair = layoutattributes::KPositionX;
       
   525     bool isPositionXAttr = false;
       
   526     if(!strcmp(attrName, layoutattributes::KPositionX))
       
   527         {
       
   528         attrPair = layoutattributes::KPositionY;
       
   529         isPositionXAttr = true;
       
   530         }
       
   531     if (handleAttributePairs(aAttribute, attrPair))
       
   532         {
       
   533         CAlfVisual* main = mElement.findVisual(0);
       
   534         if (main)
       
   535             {
       
   536             bool needsRelayouting = false;
       
   537             TAlfRealPoint pos(main->Pos().Target());
       
   538             
       
   539             //for optimizing relayouting, which is expensive. Check, whether we need to do it.
       
   540             if (isPositionXAttr)
       
   541                 {
       
   542                 //check against visual x position
       
   543                 needsRelayouting = (pos.iX != aAttribute.realValue());
       
   544                 }
       
   545             else
       
   546                 {
       
   547                 needsRelayouting = (pos.iY != aAttribute.realValue());
       
   548                 }
       
   549                 
       
   550             if (needsRelayouting)
       
   551                 {
       
   552                 main->UpdateChildrenLayout();
       
   553                 mControl.updateParentLayout();
       
   554                 }
       
   555             }
       
   556         }
       
   557     }
       
   558 
       
   559 // ---------------------------------------------------------------------------
       
   560 // Handles the Size Attribute.
       
   561 // ---------------------------------------------------------------------------
       
   562 //
       
   563 void AlfElementAttributeOwnerImpl::handleSizeAttribute(AlfAttribute& aAttribute)
       
   564     {
       
   565     const char* attrName = aAttribute.name();
       
   566     const char* attrPair = layoutattributes::KWidth;
       
   567     bool isWidthAttr = false;
       
   568     
       
   569     if(!strcmp(attrName, layoutattributes::KWidth))
       
   570         {
       
   571         attrPair = layoutattributes::KHeight;
       
   572         isWidthAttr = true;
       
   573         }
       
   574     if (handleAttributePairs(aAttribute, attrPair))
       
   575         {
       
   576         CAlfVisual* main = mElement.findVisual(0);
       
   577         if (main)
       
   578             {
       
   579             bool needsRelayouting = false;
       
   580             TAlfRealPoint size(main->Size().Target());
       
   581             
       
   582             //for optimizing relayouting, which is expensive. Check, whether we need to do it.
       
   583             if (isWidthAttr)
       
   584                 {
       
   585                 needsRelayouting = (size.iX != aAttribute.realValue());
       
   586                 }
       
   587             else
       
   588                 {
       
   589                 needsRelayouting = (size.iY != aAttribute.realValue());
       
   590                 }
       
   591                 
       
   592             if (needsRelayouting)
       
   593                 {
       
   594                 main->UpdateChildrenLayout();
       
   595                 mControl.updateParentLayout();
       
   596                 }
       
   597             }
       
   598         }
       
   599     }
       
   600 
       
   601 // ---------------------------------------------------------------------------
       
   602 // Handles the Max Size Attribute.
       
   603 // ---------------------------------------------------------------------------
       
   604 //
       
   605 void AlfElementAttributeOwnerImpl::handleMaxSizeAttribute(AlfAttribute& aAttribute)
       
   606     {
       
   607     const char* attrName = aAttribute.name();
       
   608     const char* attrPair = layoutattributes::KMaxWidth;
       
   609     if(!strcmp(attrName, layoutattributes::KMaxWidth))
       
   610         {
       
   611         attrPair = layoutattributes::KMaxHeight;
       
   612         }
       
   613     handleAttributePairs(aAttribute, attrPair);
       
   614     } 
       
   615 
       
   616 // ---------------------------------------------------------------------------
       
   617 // Handles the Min Size Attribute.
       
   618 // ---------------------------------------------------------------------------
       
   619 //    
       
   620 void AlfElementAttributeOwnerImpl::handleMinSizeAttribute(AlfAttribute& aAttribute)
       
   621     {
       
   622     const char* attrName = aAttribute.name();
       
   623     const char* attrPair = layoutattributes::KMinWidth;
       
   624     if(!strcmp(attrName, layoutattributes::KMinWidth))
       
   625         {
       
   626         attrPair = layoutattributes::KMinHeight;
       
   627         }
       
   628     handleAttributePairs(aAttribute, attrPair);
       
   629     }
       
   630     
       
   631 // ---------------------------------------------------------------------------
       
   632 // Handles setting of paired attributes: widget & height, xpos & ypos etc.
       
   633 // ---------------------------------------------------------------------------
       
   634 //    
       
   635 bool AlfElementAttributeOwnerImpl::handleAttributePairs(AlfAttribute& aAttribute, 
       
   636     const char* aAttributeNamePair)
       
   637     {
       
   638     const char* attrName = aAttribute.name();
       
   639     bool changed(false);
       
   640     IAlfVisualTemplate* visualTemplate = mElement.getVisualTemplate();
       
   641        
       
   642     // Find the root layout
       
   643     CAlfVisual* main = mElement.findVisual(0);
       
   644     if(visualTemplate && main)
       
   645         {
       
   646         int setterCount = visualTemplate->numAttributeSetters();
       
   647         bool found(false);
       
   648         
       
   649         //find the attribute in all the existing containers
       
   650         for (int j = 0; j < setterCount; j++)
       
   651             {
       
   652             AlfAttributeContainer& container = visualTemplate->attributeContainer(j);
       
   653             AlfAttribute* attri = NULL;
       
   654             try
       
   655                 {
       
   656                 attri = &(container.getAttributeByName(attrName));
       
   657                 }
       
   658             catch(AlfDataException& exception)
       
   659                 {
       
   660                 // attribute not found in the container
       
   661                 // continue to find in other containers
       
   662                 continue;
       
   663                 }
       
   664             // attribute found, update it
       
   665             *attri = aAttribute;
       
   666             found = true;
       
   667             
       
   668             //check, that attribute pair exists.
       
   669             try
       
   670                 {
       
   671                 AlfAttribute& attr = 
       
   672                     container.getAttributeByName(aAttributeNamePair);
       
   673                 }
       
   674             catch(AlfDataException& exception)
       
   675                 {
       
   676                 //attribute pair not found in the same container, so break
       
   677                 break;
       
   678                 }
       
   679                 
       
   680             // attribute pair found, so call setAttributeValue()
       
   681             IAlfAttributeSetter& setter = visualTemplate->attributeSetter(j);                                
       
   682             setter.setAttributeValue(*main, &container, 0);
       
   683             changed = true;
       
   684             break;
       
   685             }
       
   686             
       
   687         // the attribute not found in any of the existing containers    
       
   688         if(!found)
       
   689             {
       
   690             bool foundAttrPair(false);
       
   691             
       
   692             // again try to find the attribute pair
       
   693             // this is for the situation where the attribute already exists
       
   694             for (int j = 0; j < setterCount; j++)
       
   695                 {
       
   696                 AlfAttributeContainer& container = visualTemplate->attributeContainer(j);
       
   697                   
       
   698                 try
       
   699                     {
       
   700                     AlfAttribute& attr = 
       
   701                         container.getAttributeByName(aAttributeNamePair);
       
   702                     }
       
   703                 catch(AlfDataException& exception)
       
   704                     {
       
   705                     // attribute not found,so continue
       
   706                     continue;
       
   707                     }
       
   708                 // attribute pair found, so add the attribute to the same container
       
   709                 // and call setAttributeValue()   
       
   710                 AlfAttribute* attribute = aAttribute.clone();
       
   711                 container.addAttribute(attribute);
       
   712                 IAlfAttributeSetter& setter = visualTemplate->attributeSetter(j);                                
       
   713                 setter.setAttributeValue(*main, &container, 0);
       
   714                 changed = true;
       
   715                 foundAttrPair = true;
       
   716                 break;
       
   717                 }
       
   718                 
       
   719             // counter-part also does not exist, so create a new container and a attribute setter, add 
       
   720             // the attribute to the container, and the container and attribute setter to the visual template
       
   721             if(!foundAttrPair)
       
   722                 {
       
   723                 auto_ptr<AlfAttributeContainer> container(
       
   724                     new (EMM) AlfAttributeContainer());
       
   725                 auto_ptr<AlfCommonVisualAttributeSetter> setter(
       
   726                     new (EMM) AlfCommonVisualAttributeSetter());
       
   727                 AlfAttribute* attribute = aAttribute.clone();
       
   728                 container.get()->addAttribute(attribute);
       
   729                 visualTemplate->addAttributeSetter(setter.get(), 
       
   730                     container.get());
       
   731                 container.release();
       
   732                 setter.release();                
       
   733                 }
       
   734             }
       
   735         }
       
   736         return changed;
       
   737     }     
       
   738     
       
   739     } // namespace Alf