widgetmodel/alfwidgetfactory/src/alfwidgetfactory.cpp
changeset 0 e83bab7cf002
equal deleted inserted replaced
-1:000000000000 0:e83bab7cf002
       
     1 /*
       
     2 * Copyright (c) 2007-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:  Widget factory implementation file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //STL includes
       
    20 #include <string.h>
       
    21 
       
    22 //ALF Client includes
       
    23 #include <alf/alfenv.h>
       
    24 #include <alf/alfdisplay.h>
       
    25 
       
    26 //OSN core includes
       
    27 #include <osn/ustring.h>
       
    28 #include <osn/alfptrvector.h>
       
    29 
       
    30 //Widget Utils includes
       
    31 #include <alf/alfexceptions.h>
       
    32 
       
    33 //Widget factory includes
       
    34 #include <alf/ialffactoryplugin.h>
       
    35 
       
    36 //Widget Model includes
       
    37 #include <alf/ialfwidget.h>
       
    38 #include <alf/ialfmodel.h>
       
    39 #include <alf/ialfwidgetcontrol.h>
       
    40 #include <alf/ialfelement.h>
       
    41 #include "alf/ialfvisualtemplate.h"
       
    42 #include <alf/ialfwidgeteventhandler.h>
       
    43 #include <alf/ialflayoutmanager.h>
       
    44 
       
    45 //View Widget includes
       
    46 #include <alf/ialfviewwidget.h>
       
    47 
       
    48 //Local Includes
       
    49 #include "alfwidgetfactory.h"
       
    50 
       
    51 using namespace osncore;
       
    52 
       
    53 namespace Alf
       
    54     {
       
    55 
       
    56 static const char* const KViewWidgetProductId = "viewwidget";
       
    57         
       
    58     
       
    59 static IAlfViewWidget* createDefaultViewWidget(
       
    60     const char* aInstanceId,
       
    61     int aControlGroupID,
       
    62     DuiNode* aNode,
       
    63     CAlfDisplay& aDisplay,
       
    64     CAlfEnv& aEnv,
       
    65     IAlfFactoryPlugin& aFactoryPlugin,
       
    66     const char* aFilePath,
       
    67     AlfCustomInitDataBase* aCustomData)
       
    68     {
       
    69     IAlfViewWidget* ret = 0;
       
    70     
       
    71     // Create construction parameter structure.
       
    72     AlfViewWidgetInitData init;
       
    73     
       
    74     // Zero out the data in the construction structure.
       
    75     memset(&init, 0, sizeof(AlfViewWidgetInitData));
       
    76     
       
    77     // Set the construction parameters.
       
    78     init.mEnv = &aEnv;
       
    79     init.mDisplay = &aDisplay;    
       
    80     init.mWidgetId = aInstanceId;
       
    81     init.mControlGroupId = aControlGroupID;
       
    82     init.mNode = aNode;
       
    83     init.mFilePath = aFilePath;
       
    84     init.mCustomData = aCustomData;
       
    85     
       
    86     // Create a temporary factory product and typecast it to the correct 
       
    87     // interface.
       
    88     IAlfInterfaceBase* tmp = aFactoryPlugin.createProduct(
       
    89         KViewWidgetProductId, &init);
       
    90     if(tmp)
       
    91         {
       
    92         // Object created. Attempt to typecast to correct interface.        	
       
    93         ret = IAlfInterfaceBase::makeInterface<IAlfViewWidget>(tmp);
       
    94         if(!ret)
       
    95             {
       
    96             // Interface not found. Delete the temporary product.	
       
    97             delete tmp;            	
       
    98             }	
       
    99         }
       
   100 
       
   101     return ret;
       
   102     }
       
   103 
       
   104 static IAlfWidget* createDefaultWidget(
       
   105     const char*     aLoadId,
       
   106     const char*     aInstanceId,
       
   107     IAlfContainerWidget& aContainerWidget,
       
   108     DuiNode*       aNode,
       
   109     CAlfEnv&        aEnv,
       
   110     IAlfFactoryPlugin&      aFactoryPlugin,
       
   111     const char* aFilePath,
       
   112     AlfCustomInitDataBase* aCustomData)
       
   113     {
       
   114     IAlfWidget* ret = 0;
       
   115     
       
   116     // Create construction parameter structure.
       
   117     AlfWidgetInitData init;
       
   118 
       
   119     // Zero out the data in the construction structure.
       
   120     memset(&init, 0, sizeof(AlfWidgetInitData));
       
   121     
       
   122     // Set the construction parameters.    
       
   123     init.mEnv = &aEnv;
       
   124     init.mContainerWidget = &aContainerWidget;
       
   125     init.mWidgetId = const_cast<char*>(aInstanceId);
       
   126     init.mNode = aNode;  
       
   127     init.mFilePath = aFilePath;  
       
   128     init.mCustomData = aCustomData;
       
   129 
       
   130     // Create a temporary factory product and typecast it to the correct 
       
   131     // interface.
       
   132     IAlfInterfaceBase* tmp = aFactoryPlugin.createProduct(aLoadId,&init);
       
   133     if(tmp)
       
   134         {
       
   135         // Object created. Attempt to typecast to correct interface.        	
       
   136         ret = IAlfInterfaceBase::makeInterface<IAlfWidget>(tmp);
       
   137         if(!ret)
       
   138             {
       
   139             // Interface not found. Delete the temporary product.	
       
   140             delete tmp;            	
       
   141             }	
       
   142         }
       
   143 
       
   144     return ret;       
       
   145     }
       
   146 
       
   147 static IAlfModel* createDefaultModel(
       
   148     const char* aLoadId,
       
   149     IAlfFactoryPlugin& aFactoryPlugin,
       
   150     AlfCustomInitDataBase* aCustomData)
       
   151     {
       
   152     IAlfModel* ret = 0;
       
   153 
       
   154     // Create construction parameter structure.
       
   155     AlfModelInitData init;
       
   156 
       
   157     // Zero out the data in the construction structure.
       
   158     memset(&init, 0, sizeof(AlfModelInitData));
       
   159 
       
   160     // Set the construction parameters.        
       
   161     init.mCustomData = aCustomData;
       
   162 
       
   163     // Create a temporary factory product and typecast it to the correct 
       
   164     // interface.
       
   165     IAlfInterfaceBase* tmp = aFactoryPlugin.createProduct(aLoadId,&init);
       
   166     if(tmp)
       
   167         {
       
   168         // Object created. Attempt to typecast to correct interface.
       
   169         ret = IAlfInterfaceBase::makeInterface<IAlfModel>(tmp);
       
   170         if(!ret)
       
   171             {
       
   172             // Interface not found. Delete the temporary product.	
       
   173             delete tmp;            	
       
   174             }	
       
   175         }
       
   176    
       
   177     return ret;           
       
   178     }
       
   179 
       
   180 static IAlfWidgetControl* createDefaultControl(
       
   181     const char* aLoadId,
       
   182     CAlfDisplay& aDisplay,
       
   183     IAlfFactoryPlugin& aFactoryPlugin,
       
   184     AlfCustomInitDataBase* aCustomData)
       
   185     {
       
   186     IAlfWidgetControl* ret(0);
       
   187 
       
   188     // Create construction parameter structure.
       
   189     AlfWidgetControlInitData init;
       
   190 
       
   191     // Zero out the data in the construction structure.
       
   192     memset(&init, 0, sizeof(AlfWidgetControlInitData));
       
   193 
       
   194     // Set the construction parameters.        
       
   195     init.mDisplay = &aDisplay;    
       
   196     init.mCustomData = aCustomData;
       
   197  
       
   198     // Create a temporary factory product and typecast it to the correct 
       
   199     // interface.
       
   200     IAlfInterfaceBase* tmp = aFactoryPlugin.createProduct(aLoadId,&init);
       
   201     if(tmp)
       
   202         {
       
   203         // Object created. Attempt to typecast to correct interface.
       
   204         ret = IAlfInterfaceBase::makeInterface<IAlfWidgetControl>(tmp);
       
   205         if(!ret)
       
   206             {
       
   207             // Interface not found. Delete the temporary product.	
       
   208             delete tmp;            	
       
   209             }	
       
   210         }
       
   211    
       
   212     return ret;       
       
   213     }
       
   214 
       
   215 static IAlfElement* createDefaultElement(
       
   216     const char* aLoadId, 
       
   217     const char* aInstanceId, 
       
   218     DuiNode* aNode,
       
   219     IAlfWidgetControl& aControl,
       
   220     IAlfFactoryPlugin& aFactoryPlugin,
       
   221     AlfCustomInitDataBase* aCustomData)
       
   222     {
       
   223     IAlfElement* ret(0);
       
   224     
       
   225     // Create construction parameter structure.
       
   226     AlfElementInitData init;
       
   227 
       
   228     // Zero out the data in the construction structure.
       
   229     memset(&init, 0, sizeof(AlfElementInitData));
       
   230 
       
   231     // Set the construction parameters.        
       
   232     init.mControl= &aControl;
       
   233     init.mElementId = const_cast<char*>(aInstanceId);
       
   234     init.mNode= aNode;
       
   235     init.mCustomData = aCustomData; 
       
   236  
       
   237     // Create a temporary factory product and typecast it to the correct 
       
   238     // interface.
       
   239     IAlfInterfaceBase* tmp = aFactoryPlugin.createProduct(aLoadId,&init);
       
   240     if(tmp)
       
   241         {
       
   242         // Object created. Attempt to typecast to correct interface.
       
   243         ret = IAlfInterfaceBase::makeInterface<IAlfElement>(tmp);
       
   244         if(!ret)
       
   245             {
       
   246             // Interface not found. Delete the temporary product.	
       
   247             delete tmp;            	
       
   248             }	
       
   249         }
       
   250 
       
   251     return ret;       
       
   252     }   
       
   253 
       
   254 static IAlfVisualTemplate* createDefaultVisualTemplate(
       
   255     const char* aLoadId, 
       
   256     const char* aInstanceId,
       
   257     DuiNode* aNode,
       
   258     IAlfFactoryPlugin& aFactoryPlugin,
       
   259     AlfCustomInitDataBase* aCustomData)
       
   260     {
       
   261     IAlfVisualTemplate* ret(0);
       
   262         
       
   263     // Create construction parameter structure.
       
   264     AlfVisualTemplateInitData init;
       
   265 
       
   266     // Zero out the data in the construction structure.
       
   267     memset(&init, 0, sizeof(AlfVisualTemplateInitData));
       
   268 
       
   269     // Set the construction parameters.        
       
   270     init.mVisualTemplateId = const_cast<char*>(aInstanceId);
       
   271     init.mNode= aNode;
       
   272     init.mCustomData = aCustomData;
       
   273 
       
   274     // Create a temporary factory product and typecast it to the correct 
       
   275     // interface.
       
   276     IAlfInterfaceBase* tmp = aFactoryPlugin.createProduct(aLoadId,&init);
       
   277     if(tmp)
       
   278         {
       
   279         // Object created. Attempt to typecast to correct interface.
       
   280         ret = IAlfInterfaceBase::makeInterface<IAlfVisualTemplate>(tmp);
       
   281         if(!ret)
       
   282             {
       
   283             // Interface not found. Delete the temporary product.	
       
   284             delete tmp;            	
       
   285             }	
       
   286         }
       
   287         
       
   288     return ret;       
       
   289     }
       
   290        
       
   291 static IAlfWidgetEventHandler* createDefaultEventHandler(
       
   292     const char* aLoadId,
       
   293     const char* aInstanceId,
       
   294     DuiNode* aNode,
       
   295     IAlfFactoryPlugin& aFactoryPlugin,
       
   296     AlfCustomInitDataBase* aCustomData)
       
   297     {
       
   298     IAlfWidgetEventHandler* ret(0);
       
   299         
       
   300     // Create construction parameter structure.
       
   301     AlfWidgetEventHandlerInitData init;
       
   302 
       
   303     // Zero out the data in the construction structure.
       
   304     memset(&init, 0, sizeof(AlfWidgetEventHandlerInitData));
       
   305 
       
   306     // Set the construction parameters.        
       
   307     init.mWidgetEventHandlerId = const_cast<char*>(aInstanceId);
       
   308     init.mNode= aNode;
       
   309     init.mCustomData = aCustomData;
       
   310     
       
   311     // Create a temporary factory product and typecast it to the correct 
       
   312     // interface.
       
   313     IAlfInterfaceBase* tmp = aFactoryPlugin.createProduct(aLoadId,&init);
       
   314     if(tmp)
       
   315         {
       
   316         // Object created. Attempt to typecast to correct interface.
       
   317         ret = IAlfInterfaceBase::makeInterface<IAlfWidgetEventHandler>(tmp);
       
   318         if(!ret)
       
   319             {
       
   320             // Interface not found. Delete the temporary product.	
       
   321             delete tmp;            	
       
   322             }	
       
   323         }
       
   324 
       
   325     return ret;       
       
   326     }
       
   327     
       
   328 static IAlfLayoutManager* createDefaultLayoutManager(
       
   329     const char* aLoadId,
       
   330     const char* aInstanceId,
       
   331     DuiNode* aNode,
       
   332     IAlfFactoryPlugin& aFactoryPlugin,
       
   333     AlfCustomInitDataBase* aCustomData)
       
   334     {
       
   335     IAlfLayoutManager* ret(0);
       
   336 
       
   337     // Create construction parameter structure.
       
   338     AlfLayoutManagerInitData init;
       
   339 
       
   340     // Zero out the data in the construction structure.
       
   341     memset(&init, 0, sizeof(AlfLayoutManagerInitData));
       
   342 
       
   343     // Set the construction parameters.        
       
   344     init.mLayoutManagerId = const_cast<char*>(aInstanceId);
       
   345     init.mNode= aNode;
       
   346     init.mCustomData = aCustomData;
       
   347 
       
   348     // Create a temporary factory product and typecast it to the correct 
       
   349     // interface.
       
   350     IAlfInterfaceBase* tmp = aFactoryPlugin.createProduct(aLoadId, &init);
       
   351     if(tmp)
       
   352         {
       
   353         // Object created. Attempt to typecast to correct interface.
       
   354         ret = IAlfInterfaceBase::makeInterface<IAlfLayoutManager>(tmp);
       
   355         if(!ret)
       
   356             {
       
   357             // Interface not found. Delete the temporary product.	
       
   358             delete tmp;            	
       
   359             }	
       
   360         }
       
   361 
       
   362     return ret;       
       
   363     }
       
   364 
       
   365 static IAlfViewWidget* createRegisteredViewWidget(
       
   366     const char* aInstanceId,
       
   367     int aControlGroupID,
       
   368     DuiNode* aNode,
       
   369     CAlfEnv& aEnv,
       
   370     CAlfDisplay& aDisplay,
       
   371     AlfPtrVector<IAlfFactoryPlugin>& aFactoryList,
       
   372     const char* aFilePath,    
       
   373     AlfCustomInitDataBase* aCustomData)
       
   374     {
       
   375     IAlfViewWidget* ret(0);
       
   376     IAlfInterfaceBase* tmp(0);
       
   377 
       
   378     // Create construction parameter structure.    
       
   379     AlfViewWidgetInitData init;
       
   380 
       
   381     // Zero out the data in the construction structure.
       
   382     memset(&init, 0, sizeof(AlfViewWidgetInitData));
       
   383 
       
   384     // Set the construction parameters.        
       
   385     init.mEnv = &aEnv;
       
   386     init.mDisplay = &aDisplay;    
       
   387     init.mWidgetId = aInstanceId;
       
   388     init.mControlGroupId = aControlGroupID;
       
   389     init.mNode = aNode;
       
   390     init.mFilePath = aFilePath;    
       
   391     init.mCustomData = aCustomData;
       
   392     
       
   393     // Run through registered factories.     
       
   394     for(int i=0;i<aFactoryList.count()&&!ret;i++)
       
   395         {
       
   396         // Create a temporary factory product and typecast it to the correct 
       
   397         // interface.
       
   398         tmp = aFactoryList.at(i)->createProduct(KViewWidgetProductId,&init);   
       
   399         if(tmp)
       
   400             {
       
   401             // Object created. Attempt to typecast to correct interface.
       
   402             ret = IAlfInterfaceBase::makeInterface<IAlfViewWidget>(tmp);
       
   403             if(!ret)
       
   404                 {
       
   405                 // Interface not found. Delete the temporary product.	
       
   406                 delete tmp;    
       
   407                 tmp=0;        	
       
   408                 }	
       
   409             }
       
   410         }
       
   411         
       
   412     return ret;     
       
   413     }
       
   414         
       
   415 static IAlfWidget* createRegisteredWidget(
       
   416     const char* aLoadId,
       
   417     const char* aInstanceId,
       
   418     IAlfContainerWidget& aContainerWidget,
       
   419     DuiNode*   aNode,
       
   420     CAlfEnv&    aEnv,
       
   421     AlfPtrVector<IAlfFactoryPlugin>& aFactoryList,
       
   422     const char* aFilePath,
       
   423     AlfCustomInitDataBase* aCustomData)
       
   424     {
       
   425     IAlfWidget* ret(0);
       
   426     IAlfInterfaceBase* tmp(0);
       
   427 
       
   428     // Create construction parameter structure.        
       
   429     AlfWidgetInitData init;
       
   430 
       
   431     // Zero out the data in the construction structure.
       
   432     memset(&init, 0, sizeof(AlfWidgetInitData));
       
   433 
       
   434     // Set the construction parameters.        
       
   435     init.mEnv = &aEnv;
       
   436     init.mContainerWidget = &aContainerWidget;
       
   437     init.mWidgetId = const_cast<char*>(aInstanceId);
       
   438     init.mNode = aNode;    
       
   439     init.mFilePath= aFilePath;
       
   440     init.mCustomData = aCustomData;
       
   441         
       
   442     // Run through registered factories.     
       
   443     for(int i=0;i<aFactoryList.count()&&!ret;i++)
       
   444         {
       
   445         // Create a temporary factory product and typecast it to the correct 
       
   446         // interface.
       
   447         tmp = aFactoryList.at(i)->createProduct(aLoadId,&init);   
       
   448         if(tmp)
       
   449             {
       
   450             // Object created. Attempt to typecast to correct interface.
       
   451             ret = IAlfInterfaceBase::makeInterface<IAlfWidget>(tmp);
       
   452             if(!ret)
       
   453                 {
       
   454                 // Interface not found. Delete the temporary product.	
       
   455                 delete tmp;    
       
   456                 tmp=0;        	
       
   457                 }	
       
   458             }
       
   459         }
       
   460 
       
   461     return ret;       
       
   462     }
       
   463 
       
   464 static IAlfModel* createRegisteredModel(
       
   465     const char* aLoadId,
       
   466     AlfPtrVector<IAlfFactoryPlugin>& aFactoryList,
       
   467     AlfCustomInitDataBase* aCustomData)
       
   468     {
       
   469     IAlfModel* ret(0);
       
   470     IAlfInterfaceBase* tmp(0);
       
   471 
       
   472     // Create construction parameter structure.
       
   473     AlfModelInitData init;
       
   474 
       
   475     // Zero out the data in the construction structure.
       
   476     memset(&init, 0, sizeof(AlfModelInitData));
       
   477 
       
   478     // Set the construction parameters.        
       
   479     init.mCustomData = aCustomData;
       
   480         
       
   481     // Run through registered factories.     
       
   482     for(int i=0;i<aFactoryList.count()&&!ret;i++)
       
   483         {
       
   484         // Create a temporary factory product and typecast it to the correct 
       
   485         // interface.
       
   486         tmp = aFactoryList.at(i)->createProduct(aLoadId,&init);   
       
   487         if(tmp)
       
   488             {
       
   489             // Object created. Attempt to typecast to correct interface.
       
   490             ret = IAlfInterfaceBase::makeInterface<IAlfModel>(tmp);
       
   491             if(!ret)
       
   492                 {
       
   493                 // Interface not found. Delete the temporary product.	
       
   494                 delete tmp;    
       
   495                 tmp=0;        	
       
   496                 }	
       
   497             }
       
   498         }
       
   499 
       
   500     return ret;     
       
   501     }
       
   502    
       
   503 static IAlfWidgetControl* createRegisteredControl(
       
   504     const char* aLoadId,
       
   505     CAlfDisplay& aDisplay,
       
   506     AlfPtrVector<IAlfFactoryPlugin>& aFactoryList,
       
   507     AlfCustomInitDataBase* aCustomData)
       
   508     {
       
   509     IAlfWidgetControl* ret(0);
       
   510     IAlfInterfaceBase* tmp(0);
       
   511 
       
   512 
       
   513     // Create construction parameter structure.
       
   514     AlfWidgetControlInitData init;
       
   515 
       
   516     // Zero out the data in the construction structure.
       
   517     memset(&init, 0, sizeof(AlfWidgetControlInitData));
       
   518 
       
   519     // Set the construction parameters.        
       
   520     init.mDisplay = &aDisplay;    
       
   521     init.mCustomData = aCustomData;
       
   522  
       
   523     // Run through registered factories.     
       
   524     for(int i=0;i<aFactoryList.count()&&!ret;i++)
       
   525         {
       
   526         // Create a temporary factory product and typecast it to the correct 
       
   527         // interface.
       
   528         tmp = aFactoryList.at(i)->createProduct(aLoadId,&init);   
       
   529         if(tmp)
       
   530             {
       
   531             // Object created. Attempt to typecast to correct interface.
       
   532             ret = IAlfInterfaceBase::makeInterface<IAlfWidgetControl>(tmp);
       
   533             if(!ret)
       
   534                 {
       
   535                 // Interface not found. Delete the temporary product.	
       
   536                 delete tmp;    
       
   537                 tmp=0;        	
       
   538                 }	
       
   539             }
       
   540         }
       
   541     
       
   542     return ret;       
       
   543     }
       
   544     
       
   545 static IAlfElement* createRegisteredElement(
       
   546     const char* aLoadId, 
       
   547     const char* aInstanceId,
       
   548     DuiNode*   aNode, 
       
   549     IAlfWidgetControl& aControl,
       
   550     AlfPtrVector<IAlfFactoryPlugin>& aFactoryList,
       
   551     AlfCustomInitDataBase* aCustomData)
       
   552     {
       
   553     IAlfElement* ret(0);
       
   554     IAlfInterfaceBase* tmp(0);
       
   555     
       
   556     // Create construction parameter structure.
       
   557     AlfElementInitData init;
       
   558 
       
   559     // Zero out the data in the construction structure.
       
   560     memset(&init, 0, sizeof(AlfElementInitData));
       
   561 
       
   562     // Set the construction parameters.        
       
   563     init.mControl= &aControl;
       
   564     init.mElementId = const_cast<char*>(aInstanceId);
       
   565     init.mNode= aNode;
       
   566     init.mCustomData = aCustomData; 
       
   567  
       
   568     // Run through registered factories.     
       
   569     for(int i=0;i<aFactoryList.count()&&!ret;i++)
       
   570         {
       
   571         // Create a temporary factory product and typecast it to the correct 
       
   572         // interface.
       
   573         tmp = aFactoryList.at(i)->createProduct(aLoadId,&init);   
       
   574         if(tmp)
       
   575             {
       
   576             // Object created. Attempt to typecast to correct interface.
       
   577             ret = IAlfInterfaceBase::makeInterface<IAlfElement>(tmp);
       
   578             if(!ret)
       
   579                 {
       
   580                 // Interface not found. Delete the temporary product.	
       
   581                 delete tmp;    
       
   582                 tmp=0;        	
       
   583                 }	
       
   584             }
       
   585         }
       
   586 
       
   587     return ret;       
       
   588     }
       
   589     
       
   590 static IAlfVisualTemplate* createRegisteredVisualTemplate(
       
   591     const char* aLoadId, 
       
   592     const char* aInstanceId,
       
   593     DuiNode* aNode,
       
   594     AlfPtrVector<IAlfFactoryPlugin>& aFactoryList,
       
   595     AlfCustomInitDataBase* aCustomData)
       
   596     {
       
   597     IAlfVisualTemplate* ret(0);
       
   598     IAlfInterfaceBase* tmp(0);
       
   599 
       
   600     // Create construction parameter structure.
       
   601     AlfVisualTemplateInitData init;
       
   602 
       
   603     // Zero out the data in the construction structure.
       
   604     memset(&init, 0, sizeof(AlfVisualTemplateInitData));
       
   605 
       
   606     // Set the construction parameters.        
       
   607     init.mVisualTemplateId = const_cast<char*>(aInstanceId);
       
   608     init.mNode= aNode;
       
   609     init.mCustomData = aCustomData;
       
   610  
       
   611     // Run through registered factories.     
       
   612     for(int i=0;i<aFactoryList.count()&&!ret;i++)
       
   613         {
       
   614         // Create a temporary factory product and typecast it to the correct 
       
   615         // interface.
       
   616         tmp = aFactoryList.at(i)->createProduct(aLoadId,&init);   
       
   617         if(tmp)
       
   618             {
       
   619             // Object created. Attempt to typecast to correct interface.
       
   620             ret = IAlfInterfaceBase::makeInterface<IAlfVisualTemplate>(tmp);
       
   621             if(!ret)
       
   622                 {
       
   623                 // Interface not found. Delete the temporary product.	
       
   624                 delete tmp;    
       
   625                 tmp=0;        	
       
   626                 }	
       
   627             }
       
   628         }
       
   629 
       
   630     return ret;  
       
   631     }
       
   632 
       
   633 static IAlfWidgetEventHandler* createRegisteredEventHandler(
       
   634     const char* aLoadId,
       
   635     const char* aInstanceId,
       
   636     DuiNode*   aNode,
       
   637     AlfPtrVector<IAlfFactoryPlugin>& aFactoryList,
       
   638     AlfCustomInitDataBase* aCustomData)
       
   639     {
       
   640     IAlfWidgetEventHandler* ret(0);
       
   641     IAlfInterfaceBase* tmp(0);
       
   642 
       
   643     // Create construction parameter structure.
       
   644     AlfWidgetEventHandlerInitData init;
       
   645 
       
   646     // Zero out the data in the construction structure.
       
   647     memset(&init, 0, sizeof(AlfWidgetEventHandlerInitData));
       
   648 
       
   649     // Set the construction parameters.        
       
   650     init.mWidgetEventHandlerId = const_cast<char*>(aInstanceId);
       
   651     init.mNode= aNode;
       
   652     init.mCustomData = aCustomData;
       
   653 
       
   654     // Run through registered factories.     
       
   655     for(int i=0;i<aFactoryList.count()&&!ret;i++)
       
   656         {
       
   657         // Create a temporary factory product and typecast it to the correct 
       
   658         // interface.
       
   659         tmp = aFactoryList.at(i)->createProduct(aLoadId,&init);   
       
   660         if(tmp)
       
   661             {
       
   662             // Object created. Attempt to typecast to correct interface.
       
   663             ret = IAlfInterfaceBase::makeInterface<IAlfWidgetEventHandler>(
       
   664                                                                       tmp);
       
   665             if(!ret)
       
   666                 {
       
   667                 // Interface not found. Delete the temporary product.	
       
   668                 delete tmp;    
       
   669                 tmp=0;        	
       
   670                 }	
       
   671             }
       
   672         }
       
   673 
       
   674     return ret;       
       
   675     }
       
   676     
       
   677 static IAlfLayoutManager* createRegisteredLayoutManager(
       
   678     const char* aLoadId,
       
   679     const char* aInstanceId,    
       
   680     DuiNode* aNode,
       
   681     AlfPtrVector<IAlfFactoryPlugin>& aFactoryList,
       
   682     AlfCustomInitDataBase* aCustomData)
       
   683     {
       
   684     IAlfLayoutManager* ret(0);
       
   685     IAlfInterfaceBase* tmp(0);
       
   686 
       
   687     // Create construction parameter structure.
       
   688     AlfLayoutManagerInitData init;
       
   689 
       
   690     // Zero out the data in the construction structure.
       
   691     memset(&init, 0, sizeof(AlfLayoutManagerInitData));
       
   692 
       
   693     // Set the construction parameters.        
       
   694     init.mLayoutManagerId = const_cast<char*>(aInstanceId);
       
   695     init.mNode= aNode;
       
   696     init.mCustomData = aCustomData;
       
   697 
       
   698     // Run through registered factories.     
       
   699     for(int i=0;i<aFactoryList.count()&&!ret;i++)
       
   700         {
       
   701         // Create a temporary factory product and typecast it to the correct 
       
   702         // interface.
       
   703         tmp = aFactoryList.at(i)->createProduct(aLoadId,&init);   
       
   704         if(tmp)
       
   705             {
       
   706             // Object created. Attempt to typecast to correct interface.
       
   707             ret = IAlfInterfaceBase::makeInterface<IAlfLayoutManager>(tmp);
       
   708             if(!ret)
       
   709                 {
       
   710                 // Interface not found. Delete the temporary product.	
       
   711                 delete tmp;    
       
   712                 tmp=0;        	
       
   713                 }	
       
   714             }
       
   715         }
       
   716 
       
   717     return ret;
       
   718     }    
       
   719                 
       
   720 
       
   721 AlfWidgetFactory::AlfWidgetFactory(CAlfEnv& aAlfEnv):
       
   722     mAlfEnv(aAlfEnv)
       
   723     {
       
   724     mWidgetList.setAutoDelete(true);
       
   725     }
       
   726 
       
   727 AlfWidgetFactory::~AlfWidgetFactory()
       
   728     {
       
   729     mWidgetList.clear();
       
   730     mRegisteredFactoryList.clear();
       
   731     }
       
   732 
       
   733 IAlfViewWidget* AlfWidgetFactory::createViewWidget(
       
   734     const char* aInstanceId, 
       
   735     int aControlGroupID, 
       
   736     DuiNode* aNode, 
       
   737     CAlfDisplay* aDisplay, 
       
   738     const char* aFilePath, 
       
   739     AlfCustomInitDataBase* aCustomData)
       
   740     {
       
   741     IAlfViewWidget* ret(0);
       
   742     auto_ptr<IAlfViewWidget> autoptr = auto_ptr<IAlfViewWidget>(0);
       
   743 
       
   744     IAlfFactoryPlugin* factoryPlugin = mFactoryPluginLoader.loadFactoryPlugin(
       
   745                                                         KViewWidgetProductId);    
       
   746     
       
   747     CAlfDisplay* display = aDisplay;
       
   748 
       
   749     //Check there is already a widget with the same instance ID.
       
   750     if(findWidget(aInstanceId))
       
   751         {
       
   752     	  ALF_THROW(AlfWidgetException,EInvalidWidgetInstanceId,
       
   753     	      "Instance ID same as an existing widget.")
       
   754         }
       
   755             
       
   756     //Both node and presentation declaration file handle cannot have 
       
   757     //non-null value at the same time.
       
   758     if(aNode && aFilePath)
       
   759         {
       
   760     	  ALF_THROW(AlfWidgetException,EInvalidArgument,
       
   761     	      "Both node & presentation declaration file handle cannot have non-null values at the same time")
       
   762         }
       
   763         
       
   764     if(!display)
       
   765         {
       
   766         if(mAlfEnv.DisplayCount() == 0)
       
   767             {
       
   768             // No display objects defined in the environment. 
       
   769             // Throw an exception.
       
   770             ALF_THROW(AlfException, EDisplayNotFound, 
       
   771             "No display found from environment.Unable to associate a display with the view widget.");
       
   772             }
       
   773         display = &mAlfEnv.PrimaryDisplay();    
       
   774         }    
       
   775     
       
   776     // Try default factory first    
       
   777     if(factoryPlugin)
       
   778         {
       
   779         autoptr.reset(createDefaultViewWidget(
       
   780                           aInstanceId,aControlGroupID,aNode,*display, 
       
   781                           mAlfEnv,*factoryPlugin,aFilePath,aCustomData));
       
   782         }
       
   783 
       
   784     // Then try registered factories
       
   785     if(!autoptr.get())
       
   786         {        
       
   787         autoptr.reset(createRegisteredViewWidget(
       
   788                           aInstanceId,aControlGroupID,aNode, 
       
   789                           mAlfEnv,*display,mRegisteredFactoryList, 
       
   790                           aFilePath,aCustomData));
       
   791         }
       
   792         
       
   793     if(autoptr.get() != 0)
       
   794         {
       
   795         // If trap occurs throw exception. Created widget will be automatically
       
   796         // destroyed since it is in auto pointer.
       
   797         TRAPD(err, appendWidget(
       
   798               IAlfInterfaceBase::makeInterface<IAlfWidget>(autoptr.get())));
       
   799         if(err != KErrNone)
       
   800             {
       
   801             ALF_THROW(AlfException, err, 
       
   802                 "Appending created widget to environment failed.");
       
   803             }
       
   804             
       
   805         // After succesfull call to AppendWidgetL we can release the autoptr.
       
   806         ret = autoptr.release();
       
   807         }
       
   808         
       
   809     return ret;
       
   810     }
       
   811 
       
   812 IAlfWidget* AlfWidgetFactory::createWidget(
       
   813     const char* aLoadId,
       
   814     const char* aInstanceId,
       
   815     IAlfContainerWidget& aContainerWidget,
       
   816     DuiNode* aNode,
       
   817     const char* aFilePath,
       
   818     AlfCustomInitDataBase* aCustomData)
       
   819     {
       
   820     IAlfWidget* ret(0);
       
   821     IAlfFactoryPlugin* pluginFactory = mFactoryPluginLoader.loadFactoryPlugin(
       
   822                                                                      aLoadId); 
       
   823 
       
   824     //Check there is already a widget with the same instance ID.
       
   825     if(findWidget(aInstanceId))
       
   826         {
       
   827     	  ALF_THROW(AlfWidgetException,EInvalidWidgetInstanceId,
       
   828     	      "Instance ID same as an existing widget.")
       
   829         }
       
   830         
       
   831     //Both node and presentation declaration file handle cannot have 
       
   832     //non-null value at the same time.
       
   833     if(aNode && aFilePath)
       
   834         {
       
   835     	  ALF_THROW(AlfWidgetException,EInvalidArgument,
       
   836     	      "Both node & presentation declaration file handle cannot have non-null values at the same time")
       
   837         }
       
   838     
       
   839     // Try first default factory    
       
   840     if(pluginFactory)
       
   841         {
       
   842         ret = createDefaultWidget(
       
   843                   aLoadId,aInstanceId,aContainerWidget,aNode,
       
   844                   mAlfEnv,*pluginFactory,aFilePath,aCustomData);    
       
   845         }
       
   846 
       
   847     // Then try registered factories
       
   848     if(!ret)
       
   849         {
       
   850         ret = createRegisteredWidget(
       
   851                   aLoadId,aInstanceId,aContainerWidget,aNode,mAlfEnv,
       
   852                   mRegisteredFactoryList,aFilePath,aCustomData);        
       
   853         }
       
   854         
       
   855     if(ret)
       
   856         {
       
   857         TRAPD(err, appendWidget(ret));
       
   858         if(err != KErrNone)
       
   859             {
       
   860             delete ret;	
       
   861             ALF_THROW(AlfException, err, 
       
   862                 "Appending created widget to environment failed.");
       
   863             }
       
   864         }
       
   865 
       
   866     return ret;
       
   867     }
       
   868 
       
   869 int AlfWidgetFactory::destroyWidget(IAlfWidget* aWidget)
       
   870     {
       
   871     int ret = -1;
       
   872     int widgetCount = mWidgetList.count();
       
   873     for ( int i = 0; i < widgetCount; ++i ) 
       
   874         {        
       
   875         if ( mWidgetList[i] == aWidget )
       
   876             {            
       
   877             // remove and destroy the widget
       
   878             mWidgetList.remove( i );
       
   879             ret = 0;
       
   880             break; ;
       
   881             }
       
   882         }    
       
   883     return ret;
       
   884     }
       
   885     
       
   886 int AlfWidgetFactory::appendWidget(IAlfWidget* aWidget)
       
   887     {
       
   888     int ret = 0;
       
   889     int widgetCount = mWidgetList.count();
       
   890     for ( int i = 0; i < widgetCount; ++i ) 
       
   891         {        
       
   892         if ( mWidgetList[i] == aWidget )
       
   893             {
       
   894             ret = -1;
       
   895             break; ;
       
   896             }
       
   897         }
       
   898     if(ret != -1 ) 
       
   899 	    {
       
   900 	    mWidgetList.resize( mWidgetList.count()+1);
       
   901     	mWidgetList.insert( mWidgetList.count(), aWidget );	
       
   902 	    }
       
   903 	return ret;
       
   904     }
       
   905     
       
   906 IAlfWidget* AlfWidgetFactory::findWidget(const char* aWidgetName) const
       
   907     {
       
   908     IAlfWidget* ret(NULL);
       
   909     int widgetCount = mWidgetList.count();
       
   910     for(int i=0; i<widgetCount && !ret; i++)
       
   911         {
       
   912         const char* widgetName = mWidgetList[i]->widgetName();
       
   913         if(!strcmp(widgetName,aWidgetName))
       
   914             {
       
   915             ret = mWidgetList[i];    
       
   916             }
       
   917         }
       
   918     return ret;
       
   919     }
       
   920 
       
   921 IAlfModel* AlfWidgetFactory::createModel(
       
   922     const char* aLoadId,
       
   923     AlfCustomInitDataBase* aCustomData)
       
   924     {
       
   925     IAlfModel* ret(0);
       
   926     IAlfFactoryPlugin* pluginFactory = mFactoryPluginLoader.loadFactoryPlugin(
       
   927                                                                      aLoadId);
       
   928 
       
   929     // Try first default factory
       
   930     if(pluginFactory)
       
   931         {
       
   932         ret = createDefaultModel(aLoadId,*pluginFactory, aCustomData);    
       
   933         }
       
   934 
       
   935     // Then try registered factories        
       
   936     if(!ret)
       
   937         {
       
   938         ret = createRegisteredModel(
       
   939                   aLoadId,mRegisteredFactoryList,aCustomData);        
       
   940         }
       
   941     
       
   942     return ret;
       
   943     }
       
   944     
       
   945 IAlfWidgetControl* AlfWidgetFactory::createControl(
       
   946     const char* aLoadId,
       
   947     const char* aInstanceId,
       
   948     CAlfDisplay* aDisplay,
       
   949     AlfCustomInitDataBase* aCustomData)
       
   950     {
       
   951     IAlfWidgetControl* ret(0);    	
       
   952     IAlfFactoryPlugin* pluginFactory = mFactoryPluginLoader.loadFactoryPlugin(
       
   953                                                                      aLoadId);
       
   954     //Compiler warning removal. Left here for future use cases.
       
   955     (void)aInstanceId; 
       
   956     
       
   957     CAlfDisplay* display = aDisplay;
       
   958     
       
   959     if(!display)
       
   960         {
       
   961         display = &mAlfEnv.PrimaryDisplay();    
       
   962         }
       
   963   
       
   964     // Try first default factory
       
   965     if(pluginFactory)
       
   966     	{
       
   967     	 ret = createDefaultControl(aLoadId,*display,*pluginFactory,aCustomData);
       
   968     	}
       
   969 
       
   970     // Then try registered factories         
       
   971     if(!ret)
       
   972         {
       
   973         ret = createRegisteredControl(
       
   974                   aLoadId,*display,mRegisteredFactoryList,aCustomData);        
       
   975         }
       
   976 
       
   977     return ret;     
       
   978     }
       
   979 
       
   980 IAlfElement* AlfWidgetFactory::createElement(
       
   981     const char* aLoadId,
       
   982     const char* aInstanceId, 
       
   983     IAlfWidgetControl& aControl,
       
   984     DuiNode* aNode,
       
   985     AlfCustomInitDataBase* aCustomData)
       
   986     {
       
   987     IAlfElement* ret(0);
       
   988     IAlfFactoryPlugin* pluginFactory = mFactoryPluginLoader.loadFactoryPlugin(
       
   989                                                                      aLoadId);
       
   990 
       
   991     // Try first default factory
       
   992     if (pluginFactory)
       
   993         {
       
   994         ret = createDefaultElement(
       
   995                   aLoadId,aInstanceId,aNode,aControl,
       
   996                   *pluginFactory,aCustomData);
       
   997         }
       
   998 
       
   999     // Then try registered factories                 
       
  1000     if(!ret)
       
  1001         {
       
  1002         ret = createRegisteredElement(
       
  1003                   aLoadId,aInstanceId,aNode,aControl,
       
  1004                   mRegisteredFactoryList,aCustomData);        
       
  1005         }
       
  1006 
       
  1007     return ret;    
       
  1008     }
       
  1009    
       
  1010 IAlfVisualTemplate* AlfWidgetFactory::createVisualTemplate(
       
  1011     const char* aLoadId,
       
  1012     const char* aInstanceId,
       
  1013     DuiNode* aNode,
       
  1014     AlfCustomInitDataBase* aCustomData )
       
  1015     {
       
  1016      
       
  1017     IAlfVisualTemplate* ret(0);
       
  1018     IAlfFactoryPlugin* pluginFactory = mFactoryPluginLoader.loadFactoryPlugin(
       
  1019                                                                      aLoadId);
       
  1020 
       
  1021     // Try first default factory                                                                 
       
  1022     if (pluginFactory)
       
  1023         {
       
  1024         ret = createDefaultVisualTemplate(
       
  1025                   aLoadId,aInstanceId,aNode,*pluginFactory,aCustomData);
       
  1026         }
       
  1027         
       
  1028     // Then try registered factories          
       
  1029     if(!ret)
       
  1030         {
       
  1031         ret = createRegisteredVisualTemplate(
       
  1032                   aLoadId,aInstanceId,aNode,
       
  1033                   mRegisteredFactoryList,aCustomData);        
       
  1034         }
       
  1035         
       
  1036     return ret;         
       
  1037     }
       
  1038     
       
  1039 IAlfWidgetEventHandler* AlfWidgetFactory::createEventHandler(
       
  1040     const char* aLoadId,
       
  1041     const char* aInstanceId,
       
  1042     DuiNode* aNode,
       
  1043     AlfCustomInitDataBase* aCustomData )
       
  1044     {
       
  1045     IAlfWidgetEventHandler* ret(0);
       
  1046     IAlfFactoryPlugin* pluginFactory = mFactoryPluginLoader.loadFactoryPlugin(
       
  1047                                                                      aLoadId);
       
  1048 
       
  1049     // Try first default factory
       
  1050     if (pluginFactory)
       
  1051         {
       
  1052         ret = createDefaultEventHandler(
       
  1053                   aLoadId,aInstanceId,aNode,*pluginFactory,aCustomData);
       
  1054         }
       
  1055 
       
  1056     // Then try registered factories        
       
  1057     if(!ret)
       
  1058         {
       
  1059         ret = createRegisteredEventHandler(
       
  1060                   aLoadId,aInstanceId,aNode,
       
  1061                   mRegisteredFactoryList,aCustomData);        
       
  1062         }
       
  1063         
       
  1064     return ret;    
       
  1065     }
       
  1066     
       
  1067 IAlfLayoutManager* AlfWidgetFactory::createLayoutManager(
       
  1068     const char* aLoadId, 
       
  1069     const char* aInstanceId, 
       
  1070     DuiNode* aNode, 
       
  1071     AlfCustomInitDataBase* aCustomData)
       
  1072     {
       
  1073     IAlfLayoutManager* ret(0);
       
  1074     IAlfFactoryPlugin* pluginFactory = mFactoryPluginLoader.loadFactoryPlugin(
       
  1075                                                                      aLoadId);
       
  1076 
       
  1077     // Try first default factory
       
  1078     if (pluginFactory)
       
  1079         {
       
  1080         ret = createDefaultLayoutManager(
       
  1081                   aLoadId,aInstanceId,aNode,*pluginFactory,aCustomData);
       
  1082         }
       
  1083     
       
  1084     // Then try registered factories         
       
  1085     if(!ret)
       
  1086         {
       
  1087         ret = createRegisteredLayoutManager(
       
  1088                   aLoadId,aInstanceId,aNode,
       
  1089                   mRegisteredFactoryList,aCustomData);
       
  1090         }
       
  1091         
       
  1092     return ret;
       
  1093     }
       
  1094 
       
  1095 void AlfWidgetFactory::registerCustomWidgetFactory(
       
  1096     IAlfFactoryPlugin* aFactory)
       
  1097     {
       
  1098     mRegisteredFactoryList.resize(mRegisteredFactoryList.count()+1);
       
  1099     mRegisteredFactoryList.insert(mRegisteredFactoryList.count(),aFactory);
       
  1100     }
       
  1101     
       
  1102 IAlfInterfaceBase* AlfWidgetFactory::makeInterface(const IfId& aType)
       
  1103     {
       
  1104     if ( !strcmp(aType.mImplementationId, 
       
  1105                  IAlfWidgetFactory::type().mImplementationId) )
       
  1106         {
       
  1107         return static_cast<IAlfWidgetFactory*>(this);
       
  1108         }
       
  1109     
       
  1110     return 0;
       
  1111     }
       
  1112     } // namespace Alf    
       
  1113 
       
  1114 // End of File