widgetmodel/alfwidgetmodel/src/alfvisualtemplate.cpp
branchRCL_3
changeset 26 0e9bb658ef58
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:  Visual template class for alfred widget model.
       
    15 *      This class creates and updates visual tree.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 //INCLUDES
       
    23 #include <algorithm>
       
    24 #include <assert.h>
       
    25 #include <alf/alfcontrol.h>
       
    26 #include <alf/alfbrush.h>
       
    27 #include <alf/alfvisualfactory.h>
       
    28 #include <alf/alfbrusharray.h>
       
    29 #include <utf.h>
       
    30 #include <alf/alfimagevisual.h>
       
    31 #include <alf/alftexture.h>
       
    32 #include <alf/alfenv.h>
       
    33 #include <alf/alfexceptions.h>
       
    34 //#include "alf/alfperf.h"
       
    35 #include <osn/osnnew.h>
       
    36 #include <alf/ialfelement.h>
       
    37 #include "alf/alfvisualtemplate.h"
       
    38 #include "alf/alfvarianttype.h"
       
    39 #include "alf/ialfattributesetter.h"
       
    40 #include "alf/alfattributecontainer.h"
       
    41 #include "alf/alfattribute.h"
       
    42 
       
    43 // The number of attribute setters is usually between 1 and 5
       
    44 static const int KAttributeArrayGranularity = 4;
       
    45 static const int KContainerArrayGranularity = 4;
       
    46 
       
    47 namespace Alf
       
    48     {
       
    49 
       
    50 struct DeleteTemplate
       
    51 {
       
    52     void operator()(const IAlfVisualTemplate* aTemplate) const
       
    53         {
       
    54         delete aTemplate;
       
    55         }
       
    56 };
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // Helper function to iterate through a visual template hierarchy and
       
    60 // investigate whether a given visual template exists in it.
       
    61 // -----------------------------------------------------------------------------
       
    62 bool existsInHierarchy(IAlfVisualTemplate& aRoot, const IAlfVisualTemplate& aTemplate)
       
    63     {
       
    64     // Check the template against the root node.
       
    65     if(&aTemplate == &aRoot)
       
    66         {
       
    67         return true;
       
    68         }
       
    69     
       
    70     // Iterate through all the root's children
       
    71     for(int i = 0; i < aRoot.numChildTemplates(); ++i)
       
    72         {
       
    73         if(existsInHierarchy(aRoot.childTemplate(i), aTemplate))
       
    74             {
       
    75             return true;
       
    76             }
       
    77         }
       
    78         
       
    79     return false;        
       
    80     }    
       
    81     
       
    82 // ============================ MEMBER FUNCTIONS ===============================
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // Description : Constructor
       
    86 // ---------------------------------------------------------------------------
       
    87 OSN_EXPORT AlfVisualTemplate* AlfVisualTemplate::create()
       
    88     {
       
    89     return new( EMM ) AlfVisualTemplate;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // Description : Constructor
       
    94 // ---------------------------------------------------------------------------
       
    95 OSN_EXPORT AlfVisualTemplate* AlfVisualTemplate::create(TAlfVisualType aType)
       
    96     {
       
    97     return new( EMM ) AlfVisualTemplate( aType );
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // Description : Constructor
       
   102 // ---------------------------------------------------------------------------
       
   103 OSN_EXPORT AlfVisualTemplate* AlfVisualTemplate::create(TAlfLayoutType aType)
       
   104     {
       
   105     return new( EMM ) AlfVisualTemplate( aType );
       
   106     }
       
   107 
       
   108 // ============================ MEMBER FUNCTIONS ===============================
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // Description : Constructor
       
   112 // ---------------------------------------------------------------------------
       
   113 OSN_EXPORT AlfVisualTemplate::AlfVisualTemplate():
       
   114     mVisualType(EAlfVisualTypeVisual),
       
   115     mAttributeArray(KAttributeArrayGranularity),
       
   116     mContainerArray(KContainerArrayGranularity),
       
   117     mSelectOneChild(false),
       
   118     mOwner(0),
       
   119     mParent(0)
       
   120     {
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // Description : Constructor
       
   125 // ---------------------------------------------------------------------------
       
   126 OSN_EXPORT AlfVisualTemplate::AlfVisualTemplate(TAlfVisualType aType):
       
   127     mVisualType(aType),
       
   128     mAttributeArray(KAttributeArrayGranularity),
       
   129     mContainerArray(KContainerArrayGranularity),
       
   130     mSelectOneChild(false),
       
   131     mOwner(0),
       
   132     mParent(0)
       
   133     {
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // Description : Constructor
       
   138 // ---------------------------------------------------------------------------
       
   139 OSN_EXPORT AlfVisualTemplate::AlfVisualTemplate(TAlfLayoutType aType):
       
   140     mVisualType(-1 - aType),
       
   141     mAttributeArray(KAttributeArrayGranularity),
       
   142     mContainerArray(KContainerArrayGranularity),
       
   143     mSelectOneChild(false),
       
   144     mOwner(0),
       
   145     mParent(0)
       
   146     {
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // Description : Destructor
       
   151 // ---------------------------------------------------------------------------
       
   152 OSN_EXPORT AlfVisualTemplate::~AlfVisualTemplate()
       
   153     {
       
   154     mBrushArray.clear();
       
   155     mAttributeArray.clear();
       
   156     mContainerArray.clear();
       
   157     
       
   158     // Remove this visual template from it's parent or owner
       
   159     if(parent())
       
   160         {
       
   161         parent()->removeChildTemplate(*this);
       
   162         }
       
   163     if(owner())
       
   164         {
       
   165         owner()->removeVisualTemplate();
       
   166         }
       
   167     
       
   168     // Destroy child visual templates in two passes, since destructor of a child
       
   169     // visual template could affect the content of the this visual template's child vector.
       
   170     vector<IAlfVisualTemplate*> children(mChildren);
       
   171     mChildren.clear();
       
   172     for_each(children.begin(), children.end(), DeleteTemplate());
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // Description : Set the owner element.
       
   177 // ---------------------------------------------------------------------------
       
   178 OSN_EXPORT void AlfVisualTemplate::setOwner(IAlfElement* aOwner) throw()
       
   179     {
       
   180 	if(aOwner != mOwner)
       
   181 	    {
       
   182 	    // Remove this visual template from it's parent. Parent and owner are
       
   183 	    // mutually exclusive properties on a visual template.
       
   184 	    if(aOwner && (parent() != 0))
       
   185 	        {
       
   186 	        parent()->removeChildTemplate(*this);
       
   187 	        }
       
   188 	    
       
   189 	    // Set the owner of this visual template.
       
   190 		mOwner = aOwner;
       
   191 	    }
       
   192     }
       
   193 
       
   194 OSN_EXPORT IAlfElement* AlfVisualTemplate::owner() const throw()
       
   195     {
       
   196 	return mOwner;
       
   197     }
       
   198     
       
   199 // ---------------------------------------------------------------------------
       
   200 // Description : Set the name of the visual, i.e., the tag.
       
   201 // ---------------------------------------------------------------------------
       
   202 OSN_EXPORT void AlfVisualTemplate::setName(const char* aName)
       
   203     {
       
   204     mVisualName = UString(aName);
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // Description : Get the name of the visual, i.e., the tag.
       
   209 // ---------------------------------------------------------------------------
       
   210 OSN_EXPORT const char* AlfVisualTemplate::name() const throw()
       
   211     {
       
   212     return mVisualName.getUtf8();
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // Description : Add a child visual template.
       
   217 // ---------------------------------------------------------------------------
       
   218 OSN_EXPORT void AlfVisualTemplate::addChildTemplate(IAlfVisualTemplate& aChild)
       
   219     {    
       
   220     insertChildTemplate(aChild, mChildren.size());
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // Description : Inserts a child visual template at given index
       
   225 // ---------------------------------------------------------------------------
       
   226 OSN_EXPORT void AlfVisualTemplate::insertChildTemplate(IAlfVisualTemplate& aChild, int aIndex)
       
   227 	{
       
   228 	if(!(aIndex >=0 && aIndex <= mChildren.size()))
       
   229 	    ALF_THROW(AlfException, EInvalidArrayIndex, "AlfVisualTemplate::insertChildTemplate() - Index out of bounds.");
       
   230 	     	
       
   231     // Verify that the given argument is valid
       
   232     if(existsInHierarchy(*this, aChild))
       
   233         {
       
   234         ALF_THROW(AlfException, EInvalidHierarchy, "AlfVisualTemplate::insertChildTemplate() - Adding a child visual template that is already in the hierarchy.");
       
   235         }
       
   236     if(existsInHierarchy(aChild, *this))
       
   237         {
       
   238         ALF_THROW(AlfException, EInvalidHierarchy, "AlfVisualTemplate::insertChildTemplate() - Attempt to create a recursive visual template tree.");
       
   239         }
       
   240     if(layoutType() < 0)
       
   241         {
       
   242         ALF_THROW(AlfException, EInvalidHierarchy, "AlfVisualTemplate::insertChildTemplate() - Attempt to add a child visual into a non-layout visual template.");
       
   243         }     	
       
   244      	
       
   245     // Insert child visual template to the array
       
   246 	mChildren.insert(mChildren.begin() + aIndex, &aChild);
       
   247 	
       
   248     // Remove child from previous hierarchy and add it under this visual template.
       
   249     if(aChild.parent())
       
   250         {
       
   251         // Visual template cannot have a parent and owner at the same time.
       
   252         assert(aChild.owner() == 0);
       
   253         aChild.parent()->removeChildTemplate(aChild);        
       
   254         }
       
   255     if(aChild.owner())
       
   256         {
       
   257         // Visual template cannot have a parent and owner at the same time.
       
   258         assert(aChild.parent() == 0);
       
   259         aChild.owner()->removeVisualTemplate();
       
   260         }
       
   261     
       
   262     // Set a new parent for this visual template.
       
   263     aChild.setParent(this);	
       
   264 	}
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // Description : Destroyes a child visual template at given index
       
   268 // ---------------------------------------------------------------------------
       
   269 OSN_EXPORT void AlfVisualTemplate::destroyChildTemplate(int aIndex) throw()
       
   270 	{
       
   271 	// Remove and destroy a child template by the given index
       
   272 	if(aIndex >=0 && aIndex < mChildren.size())
       
   273 		{
       
   274 		IAlfVisualTemplate* child = mChildren[aIndex];				
       
   275 		removeChildTemplate(*child);
       
   276 		delete child;
       
   277 		}				
       
   278 	}
       
   279 	
       
   280 // ---------------------------------------------------------------------------
       
   281 // Description : Destroyes a child visual template.with the given name
       
   282 // ---------------------------------------------------------------------------
       
   283 OSN_EXPORT void AlfVisualTemplate::destroyChildTemplate(const char* aName) throw()
       
   284 	{
       
   285 	// Search through the children for the given name.
       
   286 	for(int i = 0; i < mChildren.size() ;i++)
       
   287     	{
       
   288 		if(!strcmp(mChildren[i]->name(), aName))
       
   289     		{
       
   290     		// Remove and destroy the found child visual template
       
   291     		IAlfVisualTemplate* child = mChildren[i];
       
   292     		removeChildTemplate(*child);
       
   293     		delete child;
       
   294     		}
       
   295     	}
       
   296 	}
       
   297 	
       
   298 // ---------------------------------------------------------------------------
       
   299 // Description : Get the number of child visual templates.
       
   300 // ---------------------------------------------------------------------------
       
   301 OSN_EXPORT int AlfVisualTemplate::numChildTemplates() const throw()
       
   302     {
       
   303     return mChildren.size();
       
   304     }
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // Description : Get a child visual template.
       
   308 // ---------------------------------------------------------------------------
       
   309 OSN_EXPORT IAlfVisualTemplate& AlfVisualTemplate::childTemplate(int aIndex) const
       
   310     {
       
   311     if((aIndex < 0) || (aIndex >= numChildTemplates()))
       
   312         {
       
   313         ALF_THROW(AlfException, EInvalidArrayIndex, "AlfVisualTemplate::childTemplate() - Index out of bounds.");
       
   314         }
       
   315     return *mChildren[aIndex];
       
   316     }
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // Description : Add a new visual attribute setter. The ownership is not passed.
       
   320 // -----------------------------------------------------------------------------
       
   321 OSN_EXPORT void AlfVisualTemplate::addAttributeSetter(
       
   322     IAlfAttributeSetter* aSetter, AlfAttributeContainer* aContainer )
       
   323     {
       
   324     mAttributeArray.resize(mAttributeArray.count()+1);
       
   325     mContainerArray.resize(mContainerArray.count()+1);
       
   326 
       
   327     mAttributeArray.insert(mAttributeArray.count(),aSetter);
       
   328     mContainerArray.insert(mContainerArray.count(),aContainer);
       
   329     }
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // Description : Get the number of visual attribute setters.
       
   333 // -----------------------------------------------------------------------------
       
   334 OSN_EXPORT int AlfVisualTemplate::numAttributeSetters() const throw()
       
   335     {
       
   336     return mAttributeArray.count();
       
   337     }
       
   338 
       
   339 // -----------------------------------------------------------------------------
       
   340 // Description : Get a visual attribute setter.
       
   341 // -----------------------------------------------------------------------------
       
   342 OSN_EXPORT IAlfAttributeSetter& AlfVisualTemplate::attributeSetter(int aIndex) const
       
   343     {
       
   344     if((aIndex < 0) || (aIndex >= mAttributeArray.count()))
       
   345         {
       
   346         ALF_THROW(AlfException, EInvalidArrayIndex, "AlfVisualTemplate::attributeSetter() - Index out of bounds.");
       
   347         }    
       
   348     return *mAttributeArray[aIndex];
       
   349     }
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 // Description :
       
   353 // -----------------------------------------------------------------------------
       
   354 OSN_EXPORT AlfAttributeContainer& AlfVisualTemplate::attributeContainer(int aIndex) const
       
   355     {
       
   356     if((aIndex < 0) || (aIndex >= mContainerArray.count()))
       
   357         {
       
   358         ALF_THROW(AlfException, EInvalidArrayIndex, "AlfVisualTemplate::attributeContainer() - Index out of bounds.");
       
   359         }        
       
   360     return *mContainerArray[aIndex];
       
   361     }
       
   362 
       
   363 // -----------------------------------------------------------------------------
       
   364 // Description : Update an existing visual tree with new values
       
   365 // -----------------------------------------------------------------------------
       
   366 OSN_EXPORT CAlfVisual* AlfVisualTemplate::updateVisualTree(IAlfMap* aData, IAlfMap* aOldData, CAlfVisual& aVisual)
       
   367     {
       
   368 
       
   369     CAlfVisual* retVisual = &aVisual;
       
   370     // Update the attributes.
       
   371     for (int i = 0; i < mAttributeArray.count(); ++i)
       
   372         {
       
   373         try
       
   374             {
       
   375             //ALF_PERF_START( perfdata, "AlfVisualTemplate-updateVisualTree-SetAttributeValue")
       
   376             mAttributeArray[i]->setAttributeValue(aVisual, mContainerArray[i], aData);
       
   377             //ALF_PERF_STOP( perfdata, "AlfVisualTemplate-updateVisualTree-setAttributeValue")
       
   378             }
       
   379         catch (...)
       
   380             {
       
   381             ALF_THROW(AlfAttributeException,EInvalidAttributeValue,"AlfVisualTemplate")
       
   382             }
       
   383         }
       
   384     // Pass to children
       
   385     if (mChildren.size())
       
   386         {
       
   387         int ind = selectedChildInd( aData );
       
   388         if (ind >= 0 && ind < mChildren.size())
       
   389             {
       
   390             CAlfLayout *layout = (CAlfLayout *)&aVisual;
       
   391             int indOld = selectedChildInd( aOldData );
       
   392             if ( ind == indOld )
       
   393                 {
       
   394                 mChildren[ind]->updateVisualTree( aData, aOldData, *layout );
       
   395                 }
       
   396             else
       
   397                 {
       
   398                 CAlfControl& c(aVisual.Owner());
       
   399 
       
   400                 //new visual tree is created. Replaces the current (now old) layout,
       
   401                 //which is removed from its parent and destroyed.
       
   402                 //new layout is returned from the function.
       
   403                 CAlfLayout* parentLayout = layout->Layout();
       
   404                 TInt ind = parentLayout->FindVisual(layout);
       
   405                 parentLayout->Remove(layout);
       
   406                 layout->RemoveAndDestroyAllD();
       
   407                 CAlfLayout* newLayout = (CAlfLayout *) createVisualTree(c, aData, parentLayout, ind);
       
   408                 retVisual = newLayout;
       
   409                 }
       
   410             }
       
   411         else
       
   412             {
       
   413             CAlfLayout *layout = (CAlfLayout *)&aVisual;
       
   414             for (int i = 0; i < mChildren.size(); ++i)
       
   415                 {
       
   416                 mChildren[i]->updateVisualTree(aData, aOldData, layout->Visual(i));
       
   417                 }
       
   418             }
       
   419         }
       
   420     return retVisual;
       
   421     }
       
   422     
       
   423 // -----------------------------------------------------------------------------
       
   424 // Description : create a new visual tree and initialize the visuals
       
   425 // -----------------------------------------------------------------------------
       
   426 OSN_EXPORT CAlfVisual* AlfVisualTemplate::createVisualTree(CAlfControl& aControl,
       
   427         IAlfMap* aData, CAlfLayout* aParentLayout, int aLayoutIndex)
       
   428     {
       
   429     // create the visual
       
   430     CAlfVisual *result = NULL;
       
   431     CAlfLayout *layout = NULL;
       
   432     if (!mSelectOneChild)
       
   433         {
       
   434         if (mVisualType < 0)
       
   435             {
       
   436             //ALF_PERF_START( perfdata, "AlfVisualTemplate-createVisualTree-NewLayout")
       
   437             // create layout
       
   438             result = layout = AlfVisualFactory::NewLayoutL(
       
   439                                   (TAlfLayoutType)(-1 - mVisualType), aParentLayout, aControl, aControl.Env());
       
   440             //ALF_PERF_STOP( perfdata, "AlfVisualTemplate-createVisualTree-NewLayout")
       
   441             if (!result)
       
   442                 {
       
   443                 ALF_THROW(AlfVisualException,ECanNotCreateVisual,"AlfVisualTemplate")
       
   444                 }
       
   445             }
       
   446         else
       
   447             {
       
   448             // create visual
       
   449             //ALF_PERF_START( perfdata, "AlfVisualTemplate-createVisualTree-NewVisual")
       
   450             result = AlfVisualFactory::NewVisualL(
       
   451                          (TAlfVisualType)mVisualType, aParentLayout, aControl, aControl.Env());
       
   452             //ALF_PERF_STOP( perfdata, "AlfVisualTemplate-createVisualTree-NewVisual")
       
   453             if (!result)
       
   454                 {
       
   455                 ALF_THROW(AlfVisualException,ECanNotCreateVisual,"AlfVisualTemplate")
       
   456                 }
       
   457 
       
   458             //Add the brushes to the visual
       
   459             result->EnableBrushesL(true);
       
   460             for (int i=0; i < mBrushArray.count(); i++)
       
   461                 {
       
   462                 result->Brushes()->AppendL(mBrushArray[i], EAlfDoesNotHaveOwnership);
       
   463                 }
       
   464             }
       
   465         if (aParentLayout &&
       
   466                 aLayoutIndex >= 0 && aLayoutIndex <= aParentLayout->Count())
       
   467             {
       
   468             //when aConstructedWithParentInformation- parameter is ETrue,
       
   469             //no message sent to server
       
   470             aParentLayout->Append(result, ETrue);
       
   471 
       
   472             //reorder, if needed.
       
   473             if (aLayoutIndex != aParentLayout->Count() - 1)
       
   474                 {
       
   475                 aParentLayout->Reorder(*result, aLayoutIndex);
       
   476                 }
       
   477             }
       
   478         aControl.Append(result);
       
   479 
       
   480         if (mVisualName.isNull())
       
   481             mVisualName = UString("");
       
   482         result->SetTagL(TPtrC8((unsigned char*)mVisualName.getUtf8()));
       
   483         
       
   484         // Set the attributes
       
   485         for (int i = 0; i < mAttributeArray.count(); ++i)
       
   486             {
       
   487             try
       
   488                 {
       
   489                 //ALF_PERF_START( perfdata, "AlfVisualTemplate-createVisualTree-setAttributeValue")
       
   490                 // set dirtines of all attribute in createvisualtree
       
   491                 for(int j = 0; j < mContainerArray[i]->attributeCount() ;j++ )
       
   492                     {
       
   493                     mContainerArray[i]->getAttribute(j).setDirty(true);
       
   494                     }
       
   495                 mAttributeArray[i]->setAttributeValue(*result, mContainerArray[i], aData);
       
   496                 //ALF_PERF_STOP( perfdata, "AlfVisualTemplate-createVisualTree-setAttributeValue")
       
   497                 }
       
   498             catch (...)
       
   499                 {
       
   500                 ALF_THROW(AlfAttributeException,EInvalidAttributeValue,"AlfVisualTemplate")
       
   501                 }
       
   502             }        
       
   503         }
       
   504     
       
   505     // Pass to children
       
   506     int ind = selectedChildInd( aData );
       
   507     if (ind >= 0 && ind < mChildren.size())
       
   508         {
       
   509         result = mChildren[ind]->createVisualTree(aControl, aData, aParentLayout, aLayoutIndex);
       
   510         }
       
   511     else if (!mSelectOneChild)
       
   512         {
       
   513         for (int i = 0; i < mChildren.size(); ++i)
       
   514             {
       
   515             mChildren[i]->createVisualTree(aControl, aData, layout, i);
       
   516             }
       
   517         }
       
   518     return result;
       
   519     }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // reads and returns selected ind from data, if set. If not set returns -1.
       
   523 // -----------------------------------------------------------------------------
       
   524 int AlfVisualTemplate::selectedChildInd( IAlfMap* aData )
       
   525     {
       
   526     int ind = -1;
       
   527     if (aData && mSelectOneChild)
       
   528         {
       
   529         IAlfVariantType* data = aData->item(mChildIndFieldName);
       
   530 
       
   531         //field value contains index to child array.
       
   532         //if field contains no data and template has only one
       
   533         // child, assume it's the child wanted.
       
   534         bool valueIsEmpty = false;
       
   535         if (!data)
       
   536             {
       
   537             valueIsEmpty = true;
       
   538             }
       
   539         else
       
   540             {
       
   541             switch ( data->type() )
       
   542                 {
       
   543                 case IAlfVariantType::EInt:
       
   544                     ind = data->integer();
       
   545                     break;
       
   546                 default:
       
   547                     break;
       
   548                 }
       
   549             }
       
   550         if ( valueIsEmpty && mChildren.size() == 1 )
       
   551             {
       
   552             ind = 0;
       
   553             }
       
   554         }
       
   555     return ind;
       
   556     }
       
   557 
       
   558 // -----------------------------------------------------------------------------
       
   559 // Description : Removes a visual template from the child array without
       
   560 // destroying the child template object.
       
   561 // -----------------------------------------------------------------------------
       
   562 void AlfVisualTemplate::removeChildTemplate(IAlfVisualTemplate& aChild) throw()
       
   563     {
       
   564     std::vector<IAlfVisualTemplate*>::iterator it = find(mChildren.begin(), mChildren.end(), &aChild);
       
   565     if(it != mChildren.end())
       
   566         {
       
   567         mChildren.erase(it);
       
   568         aChild.setParent(0);
       
   569         }
       
   570     }
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 // Description : Returns the parent visual template object
       
   574 // -----------------------------------------------------------------------------
       
   575 OSN_EXPORT IAlfVisualTemplate* AlfVisualTemplate::parent() const throw()
       
   576     {
       
   577     return mParent;
       
   578     }
       
   579     
       
   580 // -----------------------------------------------------------------------------
       
   581 // Description : Set the visual type
       
   582 // -----------------------------------------------------------------------------
       
   583 OSN_EXPORT void AlfVisualTemplate::setParent(IAlfVisualTemplate* aParent) throw()
       
   584     {
       
   585     mParent = aParent;
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // Description : Set the visual type
       
   590 // -----------------------------------------------------------------------------
       
   591 OSN_EXPORT void AlfVisualTemplate::setVisualType(TAlfVisualType aType)
       
   592     {
       
   593     mVisualType = aType;
       
   594     }
       
   595 
       
   596 // -----------------------------------------------------------------------------
       
   597 // Description : Get the visual type
       
   598 // -----------------------------------------------------------------------------
       
   599 OSN_EXPORT int AlfVisualTemplate::visualType() const throw()
       
   600     {
       
   601     return mVisualType;
       
   602     }
       
   603 // -----------------------------------------------------------------------------
       
   604 // Description : Set the layout type
       
   605 // -----------------------------------------------------------------------------
       
   606 OSN_EXPORT void AlfVisualTemplate::setLayoutType(TAlfLayoutType aType)
       
   607     {
       
   608     mVisualType = -1 - aType;
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // Description : Get the layout type
       
   613 // -----------------------------------------------------------------------------
       
   614 OSN_EXPORT int AlfVisualTemplate::layoutType() const throw()
       
   615     {
       
   616     return -1 - mVisualType;
       
   617     }
       
   618 
       
   619 // -----------------------------------------------------------------------------
       
   620 // Description : Adds brush to the brush array.
       
   621 // -----------------------------------------------------------------------------
       
   622 OSN_EXPORT void AlfVisualTemplate::addBrush(CAlfBrush& aBrush)
       
   623     {
       
   624     mBrushArray.resize(mBrushArray.count()+1);
       
   625     mBrushArray.insert(mBrushArray.count(),&aBrush);
       
   626     }
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // Description : Get the munber of brushes
       
   630 // -----------------------------------------------------------------------------
       
   631 OSN_EXPORT int AlfVisualTemplate::numBrushes() const
       
   632     {
       
   633     return mBrushArray.count();
       
   634     }
       
   635 
       
   636 // -----------------------------------------------------------------------------
       
   637 // Description : Get a Brush
       
   638 // -----------------------------------------------------------------------------
       
   639 OSN_EXPORT CAlfBrush& AlfVisualTemplate::brush(int aIndex) const
       
   640     {
       
   641     return *mBrushArray[aIndex];
       
   642     }
       
   643 
       
   644 
       
   645 // -----------------------------------------------------------------------------
       
   646 // Description : puts the class in to selected child mode.
       
   647 // -----------------------------------------------------------------------------
       
   648 OSN_EXPORT void AlfVisualTemplate::setSelectChildMode(bool aSelectChild,
       
   649         const UString& aChildIndFieldName )
       
   650     {
       
   651     mSelectOneChild = aSelectChild;
       
   652     mChildIndFieldName = aChildIndFieldName;
       
   653     }
       
   654 
       
   655 
       
   656 // ---------------------------------------------------------------------------
       
   657 // From class IAlfInterfaceBase.
       
   658 // Getter for interfaces provided by the visual template.
       
   659 // ---------------------------------------------------------------------------
       
   660 //
       
   661 OSN_EXPORT IAlfInterfaceBase* AlfVisualTemplate::makeInterface( const IfId& aType )
       
   662     {
       
   663     UString param(aType.mImplementationId);
       
   664     if (param == IAlfVisualTemplate::type().mImplementationId)
       
   665         {
       
   666         return static_cast<IAlfVisualTemplate*>(this);
       
   667         }
       
   668     return NULL;
       
   669     }
       
   670 
       
   671     } //Alf