mulwidgets/alfscrollbarwidget/src/alfscrollbarcontrol.cpp
branchRCL_3
changeset 26 0e9bb658ef58
equal deleted inserted replaced
25:4ea6f81c838a 26:0e9bb658ef58
       
     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:  Control Implementation with utilities for scrollbar widget.
       
    15 *
       
    16 */
       
    17 
       
    18 // Toolkit includes
       
    19 #include <alf/alfenv.h>
       
    20 #include <alf/alfroster.h>
       
    21 #include <alf/alfdisplay.h>
       
    22 
       
    23 // Widget model includes
       
    24 #include <alf/alfwidgetevents.h>
       
    25 #include <alf/alfcontrolgroup.h>
       
    26 
       
    27 // Widget includes
       
    28 #include <alf/ialfscrollbardefaultbaseelement.h>
       
    29 #include "ialfscrollbarbaseelementinternal.h"
       
    30 
       
    31 // Internal includes
       
    32 #include "alfscrollbarcontrol.h"
       
    33 #include "alfscrollbarwidget.h"
       
    34 
       
    35 
       
    36 // namespaces
       
    37 using namespace osncore;
       
    38 using namespace alfscrollbarwidget;
       
    39 
       
    40 namespace Alf
       
    41     {
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 //  Constructor.
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 AlfScrollBarControl::AlfScrollBarControl(CAlfEnv& aEnv) : 
       
    48     CAlfWidgetControl(aEnv)
       
    49     {
       
    50     mLayoutHeight = -1; //this means that the first draw is yet to happen.
       
    51     mLayoutWidth = -1;  //this means that the first draw is yet to happen.
       
    52     disableState(IAlfWidgetControl::Focusable);
       
    53     mTactilefdbInstance = NULL;
       
    54     mDragTactileFeedbackStarted = false;
       
    55     mEnableTactile = false; // Next statement will make it true
       
    56     EnableTactileFeedback(true);
       
    57     }
       
    58    
       
    59 // ---------------------------------------------------------------------------
       
    60 // Destructor.
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 AlfScrollBarControl::~AlfScrollBarControl()
       
    64     {
       
    65     }
       
    66    
       
    67 // ---------------------------------------------------------------------------
       
    68 // 
       
    69 // enableTactileFeedback
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void AlfScrollBarControl::EnableTactileFeedback(bool aEnabled)
       
    73     {
       
    74         if (!mTactilefdbInstance)
       
    75             {
       
    76              mEnableTactile = aEnabled;
       
    77              mTactilefdbInstance = MTouchFeedback::Instance();
       
    78             }
       
    79     }
       
    80 
       
    81 //-----------------------------------------------------------------------------
       
    82 //
       
    83 //  TouchTactileEffectOnTouch
       
    84 //-----------------------------------------------------------------------------
       
    85 
       
    86 void AlfScrollBarControl::TactileEffectOnTouchandHold()
       
    87     {
       
    88     if (mTactilefdbInstance)
       
    89         {
       
    90          mTactilefdbInstance->InstantFeedback(ETouchFeedbackSlider);
       
    91         }
       
    92     }
       
    93 
       
    94 //-------------------------------------------------------------------------------
       
    95 //
       
    96 //
       
    97 //--------------------------------------------------------------------------------     
       
    98             
       
    99 void AlfScrollBarControl::TactileEffectOnDrag(TAlfEvent& aEvent)
       
   100 {            
       
   101  if (mTactilefdbInstance)
       
   102   {
       
   103     CCoeControl* ccoecntrl = static_cast<CCoeControl*>(Display()->ObjectProvider());
       
   104     TInt intensity = 50;
       
   105     TTimeIntervalMicroSeconds32 timespan = 400000;
       
   106     mTactilefdbInstance->StartFeedback(ccoecntrl,ETouchContinuousSlider,&aEvent.PointerEvent(),intensity,timespan);
       
   107     mDragTactileFeedbackStarted = true;
       
   108   }
       
   109 }
       
   110 
       
   111 //-------------------------------------------------------------------------------
       
   112 //
       
   113 //   TouchTactileEffectOnRelease
       
   114 //--------------------------------------------------------------------------------
       
   115 //    
       
   116 void AlfScrollBarControl::TactileEffectOnRelease()    
       
   117 {
       
   118 	if (mTactilefdbInstance)
       
   119 	{
       
   120 	if ( mDragTactileFeedbackStarted )
       
   121 	    {
       
   122 	    	// Touch Release on Thumb after drag
       
   123         CCoeControl* ccoecntrl = static_cast<CCoeControl*>(Display()->ObjectProvider());
       
   124 	    mTactilefdbInstance->StopFeedback(ccoecntrl);
       
   125 	    mDragTactileFeedbackStarted = false;
       
   126 	    }
       
   127 	else
       
   128 	    {
       
   129 	    // Touch Release on thumb	
       
   130 	    mTactilefdbInstance->InstantFeedback(ETouchFeedbackSlider);
       
   131 	    }
       
   132 	}
       
   133 }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 // getTactileFeedbackState
       
   138 // 
       
   139 // ---------------------------------------------------------------------------
       
   140 bool AlfScrollBarControl::IsTactileFeedbackEnabled()
       
   141     {
       
   142     return mEnableTactile;
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // From Base class CAlfControl
       
   147 // Notifies the owner that the layout of a visual has been recalculated.
       
   148 // Called only when the EAlfVisualFlagLayoutUpdateNotification flag has
       
   149 // been set for the visual.
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 void AlfScrollBarControl::VisualLayoutUpdated(CAlfVisual& aVisual)
       
   153     {
       
   154     if((mLayoutWidth == -1 && roundFloatToInt(
       
   155         aVisual.Size().ValueNow().iX) == 0) ||
       
   156         (mLayoutHeight == -1 && roundFloatToInt(
       
   157             aVisual.Size().ValueNow().iY) == 0))
       
   158         {
       
   159         return; /*No size assigned yet*/
       
   160         }
       
   161     else
       
   162         {
       
   163         //do nothing
       
   164         }   
       
   165 
       
   166     if(mLayoutWidth == roundFloatToInt(aVisual.Size().ValueNow().iX)  && 
       
   167         mLayoutHeight == roundFloatToInt(aVisual.Size().ValueNow().iY))
       
   168         {
       
   169         //return; /* No change in layout size */
       
   170         }
       
   171         else
       
   172         {
       
   173         //do nothing
       
   174         }
       
   175 
       
   176     mLayoutWidth = roundFloatToInt(aVisual.Size().ValueNow().iX);
       
   177     mLayoutHeight = roundFloatToInt(aVisual.Size().ValueNow().iY);
       
   178     IAlfElement* baseelement = findElement ("BaseElement");
       
   179     IAlfScrollBarBaseElementInternal* elementInternal = NULL;
       
   180     if(baseelement)
       
   181 	    {
       
   182 	    elementInternal = 
       
   183 	      static_cast<IAlfScrollBarBaseElementInternal*> (
       
   184 	      baseelement->makeInterface(IAlfScrollBarBaseElementInternal::type()));	
       
   185 	    }
       
   186 	else
       
   187 		{
       
   188 		// do nothing	
       
   189 		}
       
   190     
       
   191     if(elementInternal)
       
   192         {
       
   193         elementInternal->baseLayoutSizeChanged();
       
   194         }
       
   195     else
       
   196         {
       
   197         //do nothing
       
   198         }
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // Returns top level layout.
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 CAlfLayout* AlfScrollBarControl::ContainerLayout(
       
   206     const CAlfControl* /*aConnected*/) const
       
   207     {
       
   208     //Return the root layout of the control
       
   209     return(static_cast<CAlfLayout*> (&Visual(0)));
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // From base class CAlfWidgetControl
       
   214 // Handle Alfred events.
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 AlfEventStatus AlfScrollBarControl::handleEvent( const TAlfEvent& aEvent )
       
   218     {
       
   219     IAlfElement *base = findElement("BaseElement");
       
   220         
       
   221     if(aEvent.IsCustomEvent())
       
   222         {
       
   223         if(aEvent.CustomParameter() == EEventMissedPointerUp) 
       
   224             {
       
   225             if(base)
       
   226             	{
       
   227             	IAlfWidgetEventHandler* element = 
       
   228 	                    static_cast<IAlfWidgetEventHandler*> (
       
   229 	                        base->makeInterface(IAlfWidgetEventHandler::type()));
       
   230 	            if(element)
       
   231 		            {
       
   232 		            	element->offerEvent(*this,aEvent);
       
   233 		            }
       
   234 	            
       
   235             	}
       
   236             }
       
   237         }
       
   238     else if(aEvent.IsPointerEvent())
       
   239         {
       
   240         // if the type of base element is scrollbardefaultbaseelement, then
       
   241         // convert the event to custom event
       
   242         if(base)
       
   243         	{
       
   244          
       
   245 	        if(base->makeInterface(
       
   246 	            IAlfScrollBarDefaultBaseElement::type()) != NULL)
       
   247 	            {
       
   248 	            TAlfEvent customevent(EEventScrollBarClicked,(TInt )&aEvent);
       
   249 	            return CAlfWidgetControl::processEvent(customevent);	            
       
   250 	            }
       
   251 	        else // other elements (like AlfElement) dont understand custom events
       
   252 	            { // Let them handle the original event in their own way
       
   253 	            return CAlfWidgetControl::handleEvent(aEvent);	                       
       
   254 		        }
       
   255             }
       
   256         }     
       
   257     //ScrollBar should not handle any key event
       
   258     else
       
   259         { 
       
   260         return EEventNotHandled;
       
   261         }
       
   262     
       
   263     return EEventNotHandled;
       
   264     }
       
   265 
       
   266     }//End of namespace Alf
       
   267 //End of File