mulwidgets/alfscrollbarwidget/src/alfscrollbarwidgetfactoryplugin.cpp
branchRCL_3
changeset 19 4ea6f81c838a
parent 17 514d98f21c43
child 20 0e9bb658ef58
equal deleted inserted replaced
17:514d98f21c43 19:4ea6f81c838a
     1 /*
       
     2 * Copyright (c) 2009 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:  Plugin factory implementation for scrollbar widget.
       
    15 *
       
    16 */
       
    17 
       
    18 // WidgetModel Includes
       
    19 #include "alf/alfwidget.h"
       
    20 #include <alf/ialfwidget.h>
       
    21 
       
    22 // Symbian Includes
       
    23 #include <ecom/ecom.h>
       
    24 
       
    25 // OpenC Includes
       
    26 #include <libc/string.h>
       
    27 
       
    28 // Widget Includes
       
    29 #include <alf/ialfscrollbarwidget.h>
       
    30 #include <alf/alfscrollbarproductids.h>
       
    31 
       
    32 //Internal includes
       
    33 #include "alfscrollbarwidgetfactoryplugin.h"
       
    34 #include "alfscrollbarwidget.h"
       
    35 #include "alfscrollbarmodel.h"
       
    36 #include "alfscrollbardefaultbaseelement.h"
       
    37 
       
    38 using namespace osncore;
       
    39 
       
    40 namespace Alf
       
    41     {
       
    42 const TInt KScrollBarWidgetFactoryPluginUid = {0x20010106};
       
    43 const int KProductCount = 3;
       
    44 
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // Two-phased Symbian constructor.
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 AlfScrollBarWidgetFactoryPlugin* AlfScrollBarWidgetFactoryPlugin::NewL()
       
    51     {
       
    52     return new (EMM) AlfScrollBarWidgetFactoryPlugin;
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // Destructor.
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 AlfScrollBarWidgetFactoryPlugin::~AlfScrollBarWidgetFactoryPlugin()
       
    61     {
       
    62 
       
    63     }
       
    64     
       
    65     
       
    66 // ---------------------------------------------------------------------------
       
    67 // Creates either a scrollbar widget or a scrollbar model.
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 IAlfInterfaceBase* AlfScrollBarWidgetFactoryPlugin::createProduct(
       
    71     const char* aProduct,
       
    72     void* aInitData)
       
    73     {
       
    74     IAlfInterfaceBase* ret (0);
       
    75     if (aProduct == NULL)
       
    76         {
       
    77         // do nothing
       
    78         }
       
    79     else if (!strcmp(aProduct, KScrollBarWidget))
       
    80         {
       
    81         AlfWidgetInitData* initData = (AlfWidgetInitData*)aInitData;
       
    82        
       
    83         if (initData == 0)
       
    84             {
       
    85             // Throw exception if init data is null
       
    86             ALF_THROW(
       
    87                 AlfException, 
       
    88                 ECommonError, 
       
    89                 "Scrollbar widget initialization data was NULL.");
       
    90             }
       
    91         else
       
    92             {
       
    93             // Do Nothing
       
    94             }
       
    95         
       
    96         if (initData->mWidgetId == 0)
       
    97             {
       
    98             // Assert that widget id in the initialization data is correct.
       
    99             ALF_THROW(
       
   100                 AlfException, 
       
   101                 ECommonError, 
       
   102                 "Widget ID was NULL.");
       
   103             }
       
   104         else
       
   105             {
       
   106             // Do Nothing
       
   107             }
       
   108         
       
   109         if (initData->mEnv == 0)
       
   110             {
       
   111             // Assert that the UI Accelerator Toolkit Environment 
       
   112             // in the initialization data is correct.
       
   113             ALF_THROW(
       
   114                 AlfException, 
       
   115                 ECommonError, 
       
   116                 "Environment instance was NULL.");
       
   117             }
       
   118         else
       
   119             {
       
   120             // Do Nothing
       
   121             }
       
   122         
       
   123         if (initData->mContainerWidget == 0)
       
   124             {
       
   125             // Assert that container widget pointer in the 
       
   126             // initialization data is correct.
       
   127             ALF_THROW(
       
   128                 AlfException, 
       
   129                 ECommonError, 
       
   130                 "Container widget instance was NULL.");
       
   131             }
       
   132         else
       
   133             {
       
   134             // Do Nothing
       
   135             }
       
   136         
       
   137         auto_ptr<AlfScrollBarWidget> widget(AlfScrollBarWidget::create(
       
   138             *initData->mEnv, 
       
   139             *initData->mContainerWidget,
       
   140             initData->mWidgetId,
       
   141             initData->mNode, 
       
   142             initData->mFilePath, 
       
   143             initData->mCustomData));
       
   144             
       
   145         ret = widget->makeInterface (IAlfScrollBarWidget::type());
       
   146         widget.release();
       
   147         }
       
   148     else if (!strcmp(aProduct, KScrollBarModel))
       
   149         {
       
   150         auto_ptr<AlfScrollBarModel> model(new(EMM) AlfScrollBarModel(NULL));
       
   151         ret = model->makeInterface (IAlfScrollBarModel::type());
       
   152         model.release();
       
   153         }
       
   154     else if (!strcmp(aProduct, KScrollBarDefaultBaseElement))
       
   155         {
       
   156         AlfElementInitData* initData = (AlfElementInitData*) aInitData;
       
   157         // TBD: Need to change the exceptions to scrollbar specific exceptions. 
       
   158         // Throw exception if init data is null
       
   159         if (initData == 0)
       
   160             {
       
   161             ALF_THROW(
       
   162                 AlfException, 
       
   163                 ECommonError, 
       
   164                 "Scrollbar widget initialization data was NULL.");
       
   165             }
       
   166         else
       
   167             {
       
   168             // Do Nothing
       
   169             }
       
   170         
       
   171         if (initData->mElementId == 0)
       
   172             {
       
   173             // Assert that element id in the initialization data is correct.
       
   174             ALF_THROW(
       
   175                 AlfException, 
       
   176                 ECommonError, 
       
   177                 "Element ID was NULL.");
       
   178             }
       
   179         else
       
   180             {
       
   181             // Do Nothing
       
   182             }
       
   183         
       
   184         if (initData->mControl == 0)
       
   185             {
       
   186             // Assert that the widget control is correct.
       
   187             ALF_THROW(
       
   188                 AlfException, 
       
   189                 ECommonError, 
       
   190                 "Environment instance was NULL.");
       
   191             }
       
   192         else
       
   193             {
       
   194             // Do Nothing
       
   195             }
       
   196             
       
   197         auto_ptr<AlfScrollBarDefaultBaseElement> element(
       
   198             new(EMM) AlfScrollBarDefaultBaseElement(
       
   199                 (CAlfWidgetControl&)(*initData->mControl),
       
   200                 initData->mElementId,
       
   201                 initData->mNode,initData->mCustomData));
       
   202                 
       
   203         ret = element->makeInterface(IAlfScrollBarDefaultBaseElement::type());
       
   204         element.release();
       
   205         }      
       
   206     else
       
   207         {
       
   208         // Do Nothing
       
   209         }
       
   210 
       
   211     return ret;
       
   212     }
       
   213     
       
   214     
       
   215 // ---------------------------------------------------------------------------
       
   216 // From IAlfInterfaceBase.
       
   217 // Creates interface based on the given type.
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 IAlfInterfaceBase* AlfScrollBarWidgetFactoryPlugin::makeInterface(
       
   221     const IfId& /*aType*/)
       
   222     {
       
   223     return NULL;
       
   224     }
       
   225     
       
   226     
       
   227 // ---------------------------------------------------------------------------
       
   228 // Returns the amount of products this factory can produce.
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 int AlfScrollBarWidgetFactoryPlugin::productCount() const
       
   232     {
       
   233     return KProductCount;
       
   234     }
       
   235     
       
   236     
       
   237 // ---------------------------------------------------------------------------
       
   238 // Returns product information.
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 const char* AlfScrollBarWidgetFactoryPlugin::productInfo (int aIndex) const
       
   242     {
       
   243     switch (aIndex)
       
   244         {
       
   245     case 0:
       
   246         {
       
   247         return KScrollBarWidget;
       
   248         }    
       
   249 
       
   250     case 1:
       
   251         {
       
   252         return KScrollBarModel;
       
   253         }
       
   254 
       
   255     case 2:
       
   256         {
       
   257         return KScrollBarDefaultBaseElement;
       
   258         }
       
   259     
       
   260 
       
   261     default:
       
   262         break;
       
   263 
       
   264         }
       
   265 
       
   266     return 0;
       
   267     }
       
   268 
       
   269     }// NameSpace 
       
   270 
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // OTHER EXPORTED FUNCTIONS.
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 
       
   277 using namespace Alf;
       
   278 const TImplementationProxy ImplementationTable[] =
       
   279     {
       
   280 #ifdef __EABI__
       
   281     IMPLEMENTATION_PROXY_ENTRY (
       
   282         KScrollBarWidgetFactoryPluginUid, 
       
   283         AlfScrollBarWidgetFactoryPlugin::NewL)
       
   284 #else
       
   285         {
       
   286         {KScrollBarWidgetFactoryPluginUid}, 
       
   287         AlfScrollBarWidgetFactoryPlugin::NewL}
       
   288 #endif
       
   289     };
       
   290 
       
   291 OSN_EXPORT const TImplementationProxy* ImplementationGroupProxy(
       
   292     TInt& aTableCount)
       
   293     {
       
   294     aTableCount = sizeof (ImplementationTable) / sizeof (TImplementationProxy);
       
   295 
       
   296     return ImplementationTable;
       
   297     }
       
   298 
       
   299