widgetmodel/alfwidgetmodel/src/alfelement.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:  The basic implementation for presentation elements.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "alf/alfelement.h"
       
    20 #include <alf/alfwidgetcontrol.h>
       
    21 #include <alf/alfvarianttype.h>
       
    22 #include "alf/ialfvisualtemplate.h"
       
    23 #include "alf/alfreferencetovisual.h"
       
    24 //#include "alf/alfperf.h"
       
    25 #include <alf/alfexceptions.h>
       
    26 
       
    27 #include "alfelementattributeownerimpl.h"
       
    28 
       
    29 namespace Alf
       
    30     {
       
    31 
       
    32 class  AlfVisualData
       
    33     {
       
    34 public:
       
    35     AlfVisualData( CAlfVisual* aVisualTree, uint aDataID ) :
       
    36             mVisualTree( aVisualTree ), mDataID( aDataID )
       
    37         {
       
    38         }
       
    39     CAlfVisual *mVisualTree;
       
    40     uint mDataID;
       
    41     ~AlfVisualData()
       
    42         {
       
    43 
       
    44         }
       
    45 
       
    46     };
       
    47 
       
    48 class AlfElementImpl
       
    49     {
       
    50 public:
       
    51     AlfElementImpl()
       
    52         {
       
    53         mControl = 0;
       
    54         mVisualTemplate = 0;
       
    55         mParentElement = 0;
       
    56  	    mParentLayout = 0;
       
    57         }
       
    58     ~AlfElementImpl()
       
    59         {
       
    60         if (mVisualTemplate)
       
    61             {
       
    62             delete mVisualTemplate;
       
    63             mVisualTemplate = 0;
       
    64             }
       
    65         if (mParentLayout)
       
    66             {
       
    67             delete mParentLayout;
       
    68             mParentLayout = 0;
       
    69             }
       
    70 
       
    71         mVisualTreeArray.clear();
       
    72         }
       
    73     /**
       
    74      * The control. Not own.
       
    75      */
       
    76     CAlfWidgetControl* mControl;
       
    77 
       
    78     /**
       
    79      * The element name.
       
    80      */
       
    81     UString mName;
       
    82 
       
    83     /**
       
    84      * The visual template for creating visual trees. Own.
       
    85      */
       
    86     IAlfVisualTemplate* mVisualTemplate;
       
    87 
       
    88     /*
       
    89      * Parent element. NULL for root elements. Not own.
       
    90      */
       
    91     IAlfElement *mParentElement;
       
    92 
       
    93     /*
       
    94      * Array of created visual trees with the associated data IDs.
       
    95      */
       
    96     AlfPtrVector<AlfVisualData>mVisualTreeArray; //RArray<TAlfVisualData> mVisualTreeArray;
       
    97 
       
    98     /*
       
    99      * Reference to the default parent layout. Own.
       
   100      */
       
   101     AlfReferenceToVisual *mParentLayout;
       
   102     
       
   103     /*
       
   104      * IAlfAttributeOwner implementation. Own.
       
   105      */
       
   106     auto_ptr<AlfElementAttributeOwnerImpl> mAttributeOwnerImpl;
       
   107     };
       
   108 
       
   109 // ======== MEMBER FUNCTIONS ========
       
   110 
       
   111 OSN_EXPORT AlfElement::AlfElement()
       
   112     {
       
   113     }
       
   114 
       
   115 OSN_EXPORT void AlfElement::construct( CAlfWidgetControl& aControl, const char* aName )
       
   116     {
       
   117     mData.reset(new (EMM) AlfElementImpl());
       
   118 
       
   119     mData->mControl = &aControl;
       
   120     mData->mName = UString(aName);
       
   121     mData->mParentLayout=NULL;
       
   122     mData->mParentElement=NULL;
       
   123     mData->mVisualTemplate=NULL;
       
   124     mData->mVisualTreeArray.setAutoDelete(true);
       
   125     mData->mAttributeOwnerImpl.reset(new (EMM) AlfElementAttributeOwnerImpl(*this, 
       
   126         *mData->mControl));
       
   127     aControl.addElement(this);
       
   128     }
       
   129 
       
   130 
       
   131 OSN_EXPORT AlfElement::AlfElement(CAlfWidgetControl& aControl, const char* aName)
       
   132     {
       
   133     construct( aControl, aName );
       
   134 
       
   135     }
       
   136 
       
   137 OSN_EXPORT AlfElement::~AlfElement()
       
   138     {
       
   139     }
       
   140 
       
   141 OSN_EXPORT const char* AlfElement::name() const
       
   142     {
       
   143     return mData->mName.getUtf8();
       
   144     }
       
   145 
       
   146 OSN_EXPORT void AlfElement::createChildVisualTree(
       
   147     IAlfElement* aElement, IAlfVariantType& aChildData,
       
   148     IAlfBranch& aData, int aIndex, uint aDataID )
       
   149     {
       
   150     // Pass directly to the child element CreateVisualTree, no need
       
   151     // to do anything else. Derived classes may need additional steps here.
       
   152 //    ALF_PERF_START( perfdata, "AlfElement-createVisualTree-createChildVisualTree")
       
   153     aElement->createVisualTree( aChildData, aData, aIndex, aDataID,
       
   154                                 aElement->defaultParentLayout( aDataID ),
       
   155                                 aIndex );
       
   156 //    ALF_PERF_STOP( perfdata, "AlfElement-createVisualTree-createChildVisualTree")
       
   157     }
       
   158 
       
   159 OSN_EXPORT CAlfVisual* AlfElement::createVisualTree(
       
   160     IAlfVariantType& aData, IAlfBranch& aParentData, int aIndex,
       
   161     uint aParentDataID, CAlfLayout* aParentLayout, int aLayoutIndex )
       
   162     {
       
   163     if ( aIndex >= 0 && aIndex <= aParentData.childrenCount() )
       
   164         {
       
   165         // Update data IDs of all visual trees after the new visual tree
       
   166         // Start from the aIndex, and increase all indices by one
       
   167         updateDataIDs( aParentData, aIndex, 1, aParentDataID, aParentDataID );
       
   168 
       
   169         // Create the new visual tree
       
   170         uint dataID = control().elementDataId( *this, aIndex, aParentDataID );
       
   171         return createVisualTree( aData, dataID, aParentLayout, aLayoutIndex );
       
   172         }
       
   173     ALF_THROW(AlfElementException,EInvalidElement,"AlfElement")
       
   174     }
       
   175 
       
   176 OSN_EXPORT CAlfVisual* AlfElement::createVisualTree(
       
   177     IAlfVariantType& aData, uint aDataID, CAlfLayout* aParentLayout, int aLayoutIndex )
       
   178     {
       
   179     CAlfVisual *retVisual = NULL;
       
   180     IAlfMap* currentData = NULL;
       
   181     IAlfBranch* branch = NULL;
       
   182     if ( aData.type()== IAlfVariantType::EMap )
       
   183         {
       
   184         currentData = aData.map();
       
   185         }
       
   186     else if (aData.type()== IAlfVariantType::EBranch)
       
   187         {
       
   188         branch = aData.branch();
       
   189         currentData = aData.branch()->data();
       
   190         }
       
   191 
       
   192     if ( currentData && mData->mVisualTemplate )
       
   193         {
       
   194         //Find the visual tree with data id
       
   195         int index = findFromArray( aDataID );
       
   196         if ( index < 0 )
       
   197             {
       
   198             // Create a new visual tree
       
   199             try
       
   200                 {
       
   201                 retVisual = mData->mVisualTemplate->createVisualTree(*mData->mControl,
       
   202                             currentData, aParentLayout, aLayoutIndex);
       
   203                 }
       
   204             catch (...)
       
   205                 {
       
   206                 ALF_THROW(AlfVisualException,ECanNotCreateVisual,"AlfElement")
       
   207                 }
       
   208             // Append the visual into the array
       
   209             mData->mVisualTreeArray.resize(mData->mVisualTreeArray.count()+1);
       
   210             mData->mVisualTreeArray.insert(mData->mVisualTreeArray.count(),(new (EMM) AlfVisualData(retVisual, aDataID)));
       
   211             }
       
   212         else
       
   213             {
       
   214             ALF_THROW(AlfVisualException,EInvalidElement,"AlfElement")
       
   215             }
       
   216         }
       
   217 
       
   218     if ( branch )
       
   219         {
       
   220         // Pass to children
       
   221         int count = branch->childrenCount();
       
   222         for ( int i = 0; i < count; ++i )
       
   223             {
       
   224             IAlfElement* element = mData->mControl->findElement(
       
   225                                        branch->childName( i ).getUtf8() );
       
   226             if ( element )
       
   227                 {
       
   228                 createChildVisualTree(
       
   229                     element, *branch->childData( i ), *branch, i, aDataID );
       
   230                 }
       
   231             }
       
   232         }
       
   233 
       
   234     return retVisual;
       
   235     }
       
   236 
       
   237 OSN_EXPORT void AlfElement::removeChildVisualTree(
       
   238     IAlfElement* aElement, IAlfBranch& aData, int aIndex, uint aDataID )
       
   239     {
       
   240     // Pass directly to the child element RemoveVisualTree, no need
       
   241     // to do anything else. Derived classes may need additional steps here.
       
   242     aElement->removeVisualTree( aData, aIndex, aDataID );
       
   243     }
       
   244 
       
   245 OSN_EXPORT void AlfElement::removeVisualTree( IAlfBranch& aParentData,
       
   246         int aIndex, uint aParentDataID )
       
   247     {
       
   248     if ( aIndex < aParentData.childrenCount() )
       
   249         {
       
   250         IAlfVariantType* data = aParentData.childData( aIndex );
       
   251         uint dataID = control().elementDataId( *this, aIndex, aParentDataID );
       
   252 
       
   253         removeVisualTree( *data, dataID );
       
   254 
       
   255         // Update data IDs of all visual trees after the removed visual tree
       
   256         // Start from the aIndex + 1, and decrease all indices by one
       
   257         updateDataIDs( aParentData, aIndex + 1, -1, aParentDataID, aParentDataID );
       
   258         }
       
   259     else
       
   260         ALF_THROW(AlfVisualException,EInvalidElement,"AlfElement")
       
   261         }
       
   262 
       
   263 OSN_EXPORT void AlfElement::removeVisualTree( IAlfVariantType& aData, uint aDataID )
       
   264     {
       
   265     if ( aData.type() == IAlfVariantType::EBranch )
       
   266         {
       
   267         // Pass to children
       
   268         IAlfBranch* branch = aData.branch();
       
   269         int count = branch->childrenCount();
       
   270         for ( int i = 0; i < count; ++i )
       
   271             {
       
   272             IAlfElement* element = mData->mControl->findElement( branch->childName( i ).getUtf8() );
       
   273             if ( element )
       
   274                 {
       
   275                 removeChildVisualTree( element, *branch, i, aDataID );
       
   276                 }
       
   277             }
       
   278         }
       
   279 
       
   280     // Remove visual tree from this element
       
   281     int index = findFromArray( aDataID );
       
   282     if (index >= 0)
       
   283         {
       
   284         CAlfVisual* visual = mData->mVisualTreeArray[index]->mVisualTree;
       
   285         visual->RemoveAndDestroyAllD();
       
   286         mData->mVisualTreeArray.remove( index );
       
   287         }
       
   288     else
       
   289         {
       
   290         ALF_THROW(AlfVisualException,EInvalidElement,"AlfElement")
       
   291         }
       
   292     }
       
   293 
       
   294 OSN_EXPORT void AlfElement::updateVisualTree(
       
   295     IAlfVariantType& aNewData, IAlfVariantType& aOldData, uint aDataID )
       
   296     {
       
   297     IAlfMap* currentNewData = NULL;
       
   298     IAlfMap* currentOldData = NULL;
       
   299     IAlfBranch* branch = NULL;
       
   300     IAlfBranch* oldBranch = NULL;
       
   301 
       
   302     if ( aNewData.type()== IAlfVariantType::EMap )
       
   303         {
       
   304         currentNewData = aNewData.map();
       
   305         }
       
   306     else if (aNewData.type()== IAlfVariantType::EBranch)
       
   307         {
       
   308         branch = aNewData.branch();
       
   309         currentNewData = branch->data();
       
   310         }
       
   311 
       
   312     if (&aOldData)
       
   313         {
       
   314         if (aOldData.type()== IAlfVariantType::EMap)
       
   315             {
       
   316             currentOldData = aOldData.map();
       
   317             }
       
   318         else if (aOldData.type()== IAlfVariantType::EBranch)
       
   319             {
       
   320             oldBranch = aOldData.branch();
       
   321             currentOldData = aOldData.branch()->data();
       
   322             }
       
   323         }
       
   324 
       
   325     if ( currentNewData && mData->mVisualTemplate )
       
   326         {
       
   327         //Find the visual tree with data id
       
   328         int index = findFromArray( aDataID );
       
   329         if (index >= 0)
       
   330             {
       
   331             // Update the contents of the visual tree
       
   332             CAlfVisual* visual = mData->mVisualTreeArray[index]->mVisualTree;
       
   333             //ALF_PERF_START( perfdata, "AlfElement-updateVisualTree-VTUpdateVisualTree")
       
   334             mData->mVisualTreeArray[index]->mVisualTree =
       
   335                 mData->mVisualTemplate->updateVisualTree(
       
   336                     currentNewData, currentOldData, *visual );
       
   337             //ALF_PERF_STOP( perfdata, "AlfElement-UpdateVisualTree-VTUpdateVisualTree")
       
   338             }
       
   339         }
       
   340 
       
   341     if ( branch )
       
   342         {
       
   343         // Pass to children
       
   344         int count = branch->childrenCount();
       
   345         for ( int i = 0; i < count; ++i )
       
   346             {
       
   347             IAlfElement* element = mData->mControl->findElement( branch->childName( i ).getUtf8() );
       
   348             if ( element )
       
   349                 {
       
   350                 IAlfVariantType* oldData = NULL;
       
   351                 if (oldBranch)
       
   352                     {
       
   353                     oldData = oldBranch->childData( i );
       
   354                     }
       
   355 
       
   356                 element->updateVisualTree( *branch->childData( i ), *oldData,
       
   357                                            mData->mControl->elementDataId( *element, i, aDataID ) );
       
   358                 }
       
   359             }
       
   360         }
       
   361     }
       
   362 
       
   363 OSN_EXPORT void AlfElement::addVisualTree(CAlfVisual* aVisualTree, uint aDataID)
       
   364     {
       
   365     int index = findFromArray( aDataID );
       
   366     if ( index >= 0 || aVisualTree == NULL )
       
   367         {
       
   368         ALF_THROW(AlfVisualException,EInvalidElement,"AlfElement")
       
   369         }
       
   370     // Append the visual with the assiciated data id into the array
       
   371 
       
   372     mData->mVisualTreeArray.resize(mData->mVisualTreeArray.count()+1);
       
   373     mData->mVisualTreeArray.insert(mData->mVisualTreeArray.count(),(new (EMM) AlfVisualData(aVisualTree, aDataID)));
       
   374     }
       
   375 
       
   376 OSN_EXPORT void AlfElement::replaceVisualTree( IAlfVariantType& aData, uint aDataID, uint aOldDataID )
       
   377     {
       
   378     IAlfVariantType* oldData = control().elementData(*this, aOldDataID );
       
   379 
       
   380     int index = findFromArray( aOldDataID );
       
   381     if ( index < 0 )
       
   382         {
       
   383         ALF_THROW(AlfVisualException,EInvalidElement,"AlfElement")
       
   384         }
       
   385     mData->mVisualTreeArray[index]->mDataID = aDataID;
       
   386 
       
   387     // Update the contents of the visual tree with the new data
       
   388     updateVisualTree( aData, *oldData, aDataID );
       
   389     }
       
   390 
       
   391 OSN_EXPORT void AlfElement::updateDataIDs(
       
   392     IAlfBranch& aParentBranch, int aStartIndex,
       
   393     int aOffset, uint /*aOldParentDataId*/, uint aParentDataID )
       
   394     {
       
   395 
       
   396     for ( int i = 0; i < mData->mVisualTreeArray.count(); ++i )
       
   397         {
       
   398         uint oldDataID = mData->mVisualTreeArray[i]->mDataID;
       
   399         uint index = control().dataIdToIndex( *this, oldDataID );
       
   400         uint newDataID = control().elementDataId(
       
   401                              *this, index + aOffset, aParentDataID );
       
   402         if ( index >= aStartIndex && oldDataID != newDataID )
       
   403             {
       
   404             // Update the data ID
       
   405             mData->mVisualTreeArray[i]->mDataID = newDataID;
       
   406             // The old data ID was used to calculate the child element data IDs
       
   407             // We need to update the visual trees in child elements
       
   408             IAlfVariantType* data = aParentBranch.childData( index );
       
   409             if ( data != NULL )
       
   410                 {
       
   411                 if ( data->type() == IAlfVariantType::EBranch )
       
   412                     {
       
   413                     IAlfBranch* branch = data->branch();
       
   414                     for ( int j = 0; j < branch->childrenCount(); ++j )
       
   415                         {
       
   416                         IAlfElement* childElement =
       
   417                             mData->mControl->findElement( branch->childName( j ).getUtf8() );
       
   418                         if ( childElement )
       
   419                             {
       
   420                             childElement->updateDataIDs(
       
   421                                 *branch, 0, 0, oldDataID, newDataID );
       
   422                             }
       
   423                         }
       
   424                     }
       
   425                 }
       
   426             }
       
   427         }
       
   428     }
       
   429 
       
   430 OSN_EXPORT CAlfLayout* AlfElement::defaultParentLayout(uint aParentDataID)
       
   431     {
       
   432     if (mData->mParentLayout)
       
   433         {
       
   434         CAlfVisual* visual=NULL;
       
   435         try
       
   436             {
       
   437             visual = mData->mParentLayout->resolve(*mData->mControl, aParentDataID);
       
   438             }
       
   439         catch (...)
       
   440             {
       
   441             ALF_THROW(AlfVisualException,EInvalidVisual,"AlfElement")
       
   442             }
       
   443         return (CAlfLayout *)visual;
       
   444         }
       
   445     return NULL;
       
   446     }
       
   447 
       
   448 OSN_EXPORT void AlfElement::setDefaultParentLayout(AlfReferenceToVisual* aReference)
       
   449     {
       
   450     if (mData->mParentLayout)
       
   451         {
       
   452         delete mData->mParentLayout;
       
   453         mData->mParentLayout = 0;
       
   454         }
       
   455     mData->mParentLayout = aReference;
       
   456     }
       
   457 
       
   458 OSN_EXPORT void AlfElement::setVisualTemplate(IAlfVisualTemplate& aTemplate) throw()
       
   459     {
       
   460     // Remove the visual template from its previous owner
       
   461     if(aTemplate.owner())
       
   462         {
       
   463         aTemplate.owner()->removeVisualTemplate();
       
   464         }
       
   465     
       
   466     // Set the visual template to this element
       
   467     mData->mVisualTemplate = &aTemplate;
       
   468     mData->mVisualTemplate->setOwner(this);
       
   469     }
       
   470 
       
   471 OSN_EXPORT IAlfVisualTemplate* AlfElement::getVisualTemplate() const throw()
       
   472     {
       
   473     return mData->mVisualTemplate;
       
   474     }
       
   475 
       
   476 OSN_EXPORT void AlfElement::destroyVisualTemplate() throw()
       
   477     {
       
   478     if (mData->mVisualTemplate)
       
   479         {
       
   480         delete mData->mVisualTemplate;
       
   481         mData->mVisualTemplate = 0;
       
   482         }    
       
   483     }
       
   484 
       
   485 OSN_EXPORT IAlfVisualTemplate* AlfElement::removeVisualTemplate() throw()
       
   486     {
       
   487     IAlfVisualTemplate* ret = mData->mVisualTemplate;
       
   488     
       
   489     // Set owner to NULL in removed visual template
       
   490     if(mData->mVisualTemplate)
       
   491         {
       
   492         mData->mVisualTemplate->setOwner(0);
       
   493         }    
       
   494     mData->mVisualTemplate = 0;
       
   495 
       
   496     return ret;
       
   497     }
       
   498 
       
   499 OSN_EXPORT CAlfVisual* AlfElement::findVisual(const char* aName, uint aDataID)
       
   500     {
       
   501     int index = findFromArray( aDataID );
       
   502     if ( index < 0 )
       
   503         {
       
   504         return NULL;
       
   505         }
       
   506     return mData->mVisualTreeArray[index]->mVisualTree->FindTag(TPtrC8((unsigned char*)aName));//Alf dependency
       
   507     }
       
   508 
       
   509 OSN_EXPORT CAlfVisual* AlfElement::findVisual(uint aDataID)
       
   510     {
       
   511     int index = findFromArray( aDataID );
       
   512     if ( index < 0 )
       
   513         {
       
   514         return NULL;
       
   515         }
       
   516     return mData->mVisualTreeArray[index]->mVisualTree;
       
   517     }
       
   518 
       
   519 OSN_EXPORT uint AlfElement::dataID( const CAlfVisual& aVisual ) const
       
   520     {
       
   521     for ( int i = 0; i < mData->mVisualTreeArray.count(); ++i )
       
   522         {
       
   523         if ( mData->mVisualTreeArray[i]->mVisualTree == &aVisual )
       
   524             {
       
   525             return mData->mVisualTreeArray[i]->mDataID;
       
   526             }
       
   527         }
       
   528     return 0;
       
   529     }
       
   530 
       
   531 int AlfElement::findFromArray( uint aDataID ) const
       
   532     {
       
   533     for ( int i = 0; i < mData->mVisualTreeArray.count(); ++i )
       
   534         {
       
   535         if ( mData->mVisualTreeArray[i]->mDataID == aDataID )
       
   536             {
       
   537             return i;
       
   538             }
       
   539         }
       
   540     return -1;
       
   541     }
       
   542 
       
   543 OSN_EXPORT const IAlfElement* AlfElement::parentElement() const
       
   544     {
       
   545     return mData->mParentElement;
       
   546     }
       
   547 
       
   548 OSN_EXPORT void AlfElement::setParentElement(IAlfElement& aParent)
       
   549     {
       
   550     mData->mParentElement = &aParent;
       
   551     }
       
   552 
       
   553 OSN_EXPORT  CAlfWidgetControl& AlfElement::control()
       
   554     {
       
   555     return *mData->mControl;
       
   556     }
       
   557 
       
   558 OSN_EXPORT  void AlfElement::removeAndDestroyVisuals( int aTimeMilliseconds )
       
   559     {
       
   560     //remove child elements
       
   561     for (int i = 0; i<control().numElements(); i++)
       
   562         {
       
   563         IAlfElement& element = control().element(i);
       
   564         if (element.parentElement() == this)
       
   565             {
       
   566             element.removeAndDestroyVisuals(aTimeMilliseconds);
       
   567             }
       
   568         }
       
   569     
       
   570     //remove visual trees and elements, that are linked 
       
   571     //to this element with parentlayout.
       
   572     for (int i = 0 ; i < mData->mVisualTreeArray.count(); i++)
       
   573         {
       
   574         AlfVisualData* vData = mData->mVisualTreeArray[i];
       
   575         CAlfVisual* visual = vData->mVisualTree;
       
   576         if(visual)
       
   577             {
       
   578             CAlfLayout* layout = dynamic_cast<CAlfLayout*>(visual);
       
   579             if (layout)
       
   580                 {
       
   581                 for (int j = 0; j<control().numElements(); j++)
       
   582                     {
       
   583                     IAlfElement& element = control().element(j);
       
   584                     CAlfLayout* parent = element.defaultParentLayout(vData->mDataID);
       
   585                     if (parent && contains(*parent))
       
   586                         {
       
   587                         element.removeAndDestroyVisuals(aTimeMilliseconds);
       
   588                         }
       
   589                     }
       
   590                 }
       
   591             visual->RemoveAndDestroyAllD();
       
   592             vData->mVisualTree = NULL;
       
   593             }
       
   594         }
       
   595         
       
   596     mData->mVisualTreeArray.clear();
       
   597     }
       
   598 
       
   599 
       
   600 //From IAlfElement
       
   601 OSN_EXPORT bool AlfElement::contains(CAlfVisual& aVisual) const
       
   602     {
       
   603     CAlfVisual* visual = &aVisual;
       
   604     //traverse back to the root parent
       
   605     while (visual)
       
   606         {
       
   607         for (int i = 0 ; i < mData->mVisualTreeArray.count(); i++)
       
   608             {
       
   609             if (visual == mData->mVisualTreeArray[i]->mVisualTree)//is this visual parent of passed visual?
       
   610                 return true;
       
   611             }
       
   612         visual = visual->Layout();
       
   613         }
       
   614     return false; //referred visual is not part of this element.
       
   615     }
       
   616 
       
   617 // ---------------------------------------------------------------------------
       
   618 // From class IAlfInterfaceBase.
       
   619 // Getter for interfaces provided by the element.
       
   620 // ---------------------------------------------------------------------------
       
   621 //
       
   622 OSN_EXPORT IAlfInterfaceBase* AlfElement::makeInterface( const IfId& aType )
       
   623     {
       
   624     UString param(aType.mImplementationId);
       
   625     if (param == IAlfElement::type().mImplementationId)
       
   626         {
       
   627         return static_cast<IAlfElement*>(this);
       
   628         }
       
   629     else if (param == IAlfAttributeOwner::type().mImplementationId)
       
   630         {
       
   631     	return static_cast<IAlfAttributeOwner*>(mData->mAttributeOwnerImpl.get());
       
   632         }
       
   633     return NULL;
       
   634     }
       
   635     
       
   636     } // Alf