mulwidgets/alfscrollbarwidget/src/alfscrollbarwidget.cpp
branchRCL_3
changeset 19 4ea6f81c838a
parent 17 514d98f21c43
child 20 0e9bb658ef58
equal deleted inserted replaced
17:514d98f21c43 19:4ea6f81c838a
     1 /*
       
     2 * Copyright (c) 2007, 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation for scrollbar widget.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // Alfred Client includes
       
    20 #include <alf/alfenv.h>
       
    21 
       
    22 // Widget Model includes
       
    23 #include "alf/alfelement.h"
       
    24 #include <alf/alfexception.h>
       
    25 
       
    26 // Widget Includes
       
    27 #include <alf/ialfscrollbardefaultbaseelement.h>
       
    28 #include <alf/alfscrollbarproductids.h>
       
    29 // Internal includes
       
    30 
       
    31 #include "alfscrollbardefaultbaseelement.h"
       
    32 #include "alfscrollbarwidget.h"
       
    33 #include "alfscrollbarmodel.h"
       
    34 #include "alfscrollbarcontrol.h"
       
    35 #include <alf/alfwidgetenvextension.h>
       
    36 using namespace alfscrollbarwidget;
       
    37 
       
    38 using Alf::CommonWidgetEvent;
       
    39 namespace Alf
       
    40     {
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 //  Creator Method.
       
    44 // ---------------------------------------------------------------------------
       
    45 //        
       
    46 AlfScrollBarWidget* AlfScrollBarWidget :: create(
       
    47     CAlfEnv& aEnv, 
       
    48     IAlfContainerWidget& aContainer,
       
    49     const char* aWidgetId, 
       
    50     DuiNode *aNode, 
       
    51     const char *aFilePath, 
       
    52     AlfCustomInitDataBase* aCustomData)
       
    53     {
       
    54     return (new( EMM ) AlfScrollBarWidget(aEnv, 
       
    55         aContainer, aWidgetId, aNode, aFilePath, aCustomData));
       
    56     }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 //  Destructor.
       
    61 // ---------------------------------------------------------------------------
       
    62 //        
       
    63 AlfScrollBarWidget::~AlfScrollBarWidget()
       
    64     {
       
    65     if(mScrollModel)
       
    66         {
       
    67         delete mScrollModel;
       
    68         }
       
    69     else 
       
    70         {
       
    71         
       
    72         }
       
    73     }
       
    74     
       
    75     
       
    76     
       
    77 // ---------------------------------------------------------------------------
       
    78 // From class IAlfWidget.
       
    79 // Getter for the parent container. The ownership not passed.
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 IAlfContainerWidget* AlfScrollBarWidget::parent() const
       
    83     {
       
    84     return mWidget->parent();
       
    85     }
       
    86     
       
    87     
       
    88 // From class MAlfInterfaceBase.
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // Getter for interfaces provided by the scrollbar widget.
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 IAlfInterfaceBase* AlfScrollBarWidget :: makeInterface(const IfId& aType)
       
    95     {
       
    96     UString param ( aType.mImplementationId );
       
    97 
       
    98     if (param == IAlfScrollBarWidget::type().mImplementationId)
       
    99         {
       
   100         return static_cast<IAlfScrollBarWidget*>(this);
       
   101         }
       
   102     else if (param == IAlfWidget::type().mImplementationId)
       
   103         {
       
   104         return static_cast<IAlfWidget*>(this);
       
   105         }
       
   106     else
       
   107         {
       
   108         //do nothing
       
   109         }
       
   110 
       
   111     return mWidget->makeInterface(aType);
       
   112     }
       
   113     
       
   114       
       
   115 // From class IAlfWidget.
       
   116     
       
   117 // ---------------------------------------------------------------------------
       
   118 // Getter for the control. The ownership is not passed.
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 CAlfWidgetControl* AlfScrollBarWidget :: control() const
       
   122     {
       
   123     return mWidget->control();
       
   124     }
       
   125     
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // Setter for the control. The control is owned by the Alfred environment.
       
   129 // ---------------------------------------------------------------------------
       
   130 //    
       
   131 void AlfScrollBarWidget :: setControl( 
       
   132     CAlfWidgetControl* aControl, bool /*aDeletePreviousControl*/ )
       
   133     {
       
   134     mScrollControl = aControl;
       
   135     mWidget->setControl(aControl);
       
   136     }
       
   137 
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // Getter for the model. The ownership is not passed.
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 IAlfModel* AlfScrollBarWidget :: model()
       
   144     {    
       
   145     return mScrollModel;
       
   146     }
       
   147     
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // Setter for the model. Ownership is passed and the old model is released.
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void AlfScrollBarWidget :: setModel( IAlfModel* aModel, bool /*aTakeOwnerShip*/)
       
   154     {
       
   155     IAlfElement* baseelement = control()->findElement ("BaseElement");
       
   156     if(baseelement)
       
   157     	{
       
   158     IAlfScrollBarBaseElementInternal* elementInternal = 
       
   159             static_cast<IAlfScrollBarBaseElementInternal*> (
       
   160     baseelement->makeInterface(
       
   161                     IAlfScrollBarBaseElementInternal::type()));
       
   162             
       
   163     if(aModel==NULL)
       
   164         {
       
   165         if(elementInternal)
       
   166         	{
       
   167         	elementInternal->destroyVisualization();
       
   168         	}
       
   169         delete mScrollModel;
       
   170         mScrollModel = NULL;
       
   171         }
       
   172     else
       
   173         {
       
   174         if(mScrollModel)
       
   175             {
       
   176             delete mScrollModel;
       
   177             mScrollModel = NULL;
       
   178             
       
   179             mScrollModel = static_cast<IAlfScrollBarModel*>( aModel->makeInterface(
       
   180                 IAlfScrollBarModel::type()));
       
   181             AlfScrollBarModel* scrollBarModel = (AlfScrollBarModel*)mScrollModel;
       
   182             // Store the widget pointer in model
       
   183             scrollBarModel->storeWidget(this);
       
   184             
       
   185             if(mScrollModel && elementInternal)
       
   186                 {
       
   187                 elementInternal->initializeScrollModel();
       
   188                 elementInternal->updateVisualization();
       
   189                 }
       
   190             }
       
   191         else
       
   192             {
       
   193             mScrollModel =static_cast<IAlfScrollBarModel*>( aModel->makeInterface(
       
   194                 IAlfScrollBarModel::type()));
       
   195             AlfScrollBarModel* scrollBarModel = (AlfScrollBarModel*)mScrollModel;
       
   196             scrollBarModel->storeWidget(this);
       
   197             
       
   198             if(mScrollModel && elementInternal)
       
   199                 {
       
   200                 elementInternal->createVisualization();
       
   201                 }
       
   202              }
       
   203 
       
   204         }
       
   205     	}
       
   206     }
       
   207     
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // Get the name of the widget instance.
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 const char* AlfScrollBarWidget :: widgetName() const
       
   214     {
       
   215     return mWidget->widgetName();
       
   216     } 
       
   217     
       
   218     
       
   219 // ---------------------------------------------------------------------------
       
   220 // Sets/Releases the Focus from child widget of container.
       
   221 // ---------------------------------------------------------------------------
       
   222 //
       
   223 void AlfScrollBarWidget :: setChildFocus(bool /*aFocus*/)
       
   224     {
       
   225     }
       
   226     
       
   227     
       
   228 //---------------------------------------------------------------------------
       
   229 // Creates the presentation for the widget from XML. Destroys any existing
       
   230 // presentation.
       
   231 //---------------------------------------------------------------------------
       
   232 //    
       
   233 void AlfScrollBarWidget :: setPresentation(const char* /*aFilePath*/)
       
   234     {
       
   235     } 
       
   236 
       
   237 
       
   238             
       
   239 // ---------------------------------------------------------------------------
       
   240 //  C++ default constructor.
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 AlfScrollBarWidget :: AlfScrollBarWidget(
       
   244     CAlfEnv& aEnv, IAlfContainerWidget& aContainer,
       
   245     const char* aWidgetId, DuiNode * /*aNode*/, 
       
   246     const char * /*aFilePath*/,
       
   247     AlfCustomInitDataBase* /*aCustomData*/)
       
   248     { 
       
   249     mScrollModel = NULL;
       
   250     mWidget.reset(new(EMM) AlfWidget(aWidgetId,aContainer,aEnv));
       
   251     // Default Imperative Construction
       
   252     constructDefault(aEnv);
       
   253 
       
   254     }
       
   255 
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 // Constructs default Visualization for widget.
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 void AlfScrollBarWidget :: constructDefault(CAlfEnv& aEnv)
       
   262     {
       
   263     const char* mBaseElementLoadId=KScrollBarDefaultBaseElement; 
       
   264     
       
   265     // Create Control
       
   266     CAlfWidgetControl* ctrl = constructDefaultControl(aEnv);
       
   267     setControl(ctrl);
       
   268     
       
   269     // Create Element
       
   270     IAlfWidgetFactory& widgetFactory = AlfWidgetEnvExtension::widgetFactory(control()->Env());
       
   271     
       
   272     widgetFactory.createElement<IAlfElement>(mBaseElementLoadId, 
       
   273 					         	             baseElementName(),
       
   274 					         	             *control());    
       
   275     }
       
   276     
       
   277 // ---------------------------------------------------------------------------
       
   278 //  Construct and returns Scrollbar Control.
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 CAlfWidgetControl *AlfScrollBarWidget :: constructDefaultControl(CAlfEnv& aEnv)
       
   282     {
       
   283     return(new(EMM) AlfScrollBarControl(aEnv) );
       
   284     }    
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 //  Enables tactile feedback based on the flag state
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 void AlfScrollBarWidget ::enableTactile(bool aFlag)
       
   291 	{
       
   292 	AlfScrollBarControl* scrollControl = (AlfScrollBarControl*)control();
       
   293 	scrollControl->EnableTactileFeedback(aFlag);
       
   294 	}
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 //  Getter for tactile feedback state
       
   298 // ---------------------------------------------------------------------------
       
   299 //               
       
   300 bool AlfScrollBarWidget ::IsTactileEnabled()
       
   301 	{
       
   302 	AlfScrollBarControl* scrollControl = (AlfScrollBarControl*)control();
       
   303 	return scrollControl->IsTactileFeedbackEnabled();
       
   304 	}  
       
   305     
       
   306     }//End of Alf
       
   307