mulwidgets/alfscrollbarwidget/src/alfscrollbardefaultbaseelement.cpp
changeset 0 e83bab7cf002
equal deleted inserted replaced
-1:000000000000 0:e83bab7cf002
       
     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 implementation for presentation elements.
       
    15 *
       
    16 */
       
    17 
       
    18 //Toolkit Includes
       
    19 #include <alf/alfimagevisual.h>
       
    20 #include <alf/alfevent.h>
       
    21 #include <alf/alfenv.h>
       
    22 #include <AknUtils.h>
       
    23 //AknLayout2 includes
       
    24 #include <aknlayoutscalable_uiaccel.cdl.h>
       
    25 
       
    26 // Alfred Client includes
       
    27 #include <alf/alfroster.h>
       
    28 #include <alf/alfdisplay.h>
       
    29 
       
    30 //Widget Model Includes
       
    31 #include <alf/alflayout.h>
       
    32 #include "alf/alfelement.h"
       
    33 #include <alf/alfwidgeteventhandler.h>
       
    34 #include <alf/alfwidgetenvextension.h>
       
    35 #include <alf/ialfmodel.h>
       
    36 
       
    37 //scrollbar widget includes
       
    38 #include <alf/alfscrollevents.h>
       
    39 #include "alfscrollbardefaultbaseelement.h"
       
    40 #include "alfscrollbarwidget.h"
       
    41 #include "alfscrollbarcontrol.h"
       
    42 #include "alfscrollbarmodel.h"
       
    43 #include "alfscrollbarlongtaptimer.h"
       
    44 
       
    45 #include <math.h>
       
    46 
       
    47 enum 
       
    48     {
       
    49     EReleased,
       
    50     ETrackPressed,
       
    51     EThumbPressed
       
    52     };    
       
    53 
       
    54 // EPSILON is an small constant used to compare two real values
       
    55 const float KEpsilon  = 0.000001;
       
    56 
       
    57 namespace Alf
       
    58     {
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 //  A function to compare two real values. The difference less than aEpsilon
       
    62 //  is assumed negligible.
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 inline int realCompare(float aReal1, float aReal2, float aEpsilon)
       
    66     {
       
    67     if (Abs(aReal1-aReal2) < aEpsilon)
       
    68         {
       
    69         return 0;
       
    70         }
       
    71     else if ((aReal1-aReal2) > 0)
       
    72         {
       
    73         return 1;
       
    74         }
       
    75     else
       
    76         {
       
    77         return -1;
       
    78         }
       
    79     };  
       
    80     
       
    81 struct ScrollBarBaseElementData
       
    82     {
       
    83     TOperation mOperation;              // Thumb Drag
       
    84     CAlfVisual* mVisual;                // Hit visual
       
    85     TPoint mDragPoint;                  // Current pointer value
       
    86     TPoint mLongTapPos;                 // Long Tap Point
       
    87     int mDragStartStep;                 // Value of view start position when drag starts
       
    88     int mCurrentState;                  // track or thumb clicked state indicator
       
    89     bool mLongTapStarted;               // Long Tap Timer started ( true if started) 
       
    90    
       
    91     int mViewLength;                    // For avoiding thumb length calculation 
       
    92                                         // everytime when model data changes
       
    93                                         // Stores current viewLength
       
    94     
       
    95     int mTotalLength;                   // For avoiding thumb length calculation 
       
    96                                         // everytime when model data changes
       
    97                                         // Stores current spanLength
       
    98     
       
    99     float mWidgetOpacity;               // default value =1.0.
       
   100     float mThumbOpacity;                // default value =1.0. thumb will eventually have
       
   101                                         // opacity=iWidgetOpacity*iThumbOpacity.
       
   102     
       
   103     int mThumbAnimationTime;            // thumb animation time in milliseconds.
       
   104     float mThumbLength;                 // Length of scrollbar thumb
       
   105     float mThumbMinLength;              // Minimum Length of thumb
       
   106     float mThumbMaxLength;              // Maximum Length of thumb
       
   107     float mStepSize;                    // Step Size
       
   108     bool mThumbSizeChanged;             // flag to indicate whether thumbSize is Changed.
       
   109     int mExtendedTouch;                 // extended area width.
       
   110     AlfScrollBarModel* mScrollbarModel; // Pointer to scrollbar model
       
   111    
       
   112     CAlfLayout* mRootLayout ;           // Layouts and visuals
       
   113     CAlfLayout* mTrackLayout ;
       
   114     CAlfLayout* mExtendedTrackLayout;
       
   115     CAlfLayout* mThumbLayout ;
       
   116     CAlfLayout* mExtendedThumbLayout;
       
   117     
       
   118     CAlfImageVisual* mTrackTopImage ;
       
   119     CAlfImageVisual* mTrackMiddleImage ;
       
   120     CAlfImageVisual* mTrackEndImage ;
       
   121     
       
   122     CAlfImageVisual* mThumbTopImage ;
       
   123     CAlfImageVisual* mThumbMiddleImage ;
       
   124     CAlfImageVisual* mThumbEndImage ;
       
   125     };//End of struct ScrollBarBaseElementData
       
   126         
       
   127 struct ScrollbarThumbLCTData
       
   128     {
       
   129     TInt left;      //used to specify left value
       
   130     TInt top;       //used to specify top value
       
   131     TInt right;     //used to specify right value
       
   132     TInt bottom;    //used to specify bottom value
       
   133     TInt height;    //used to specify height value
       
   134     TInt width;     //used to specify width value
       
   135     };
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 //  C++ default constructor.
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 AlfScrollBarDefaultBaseElement::AlfScrollBarDefaultBaseElement(
       
   142                                     CAlfWidgetControl& aControl,
       
   143                                     const char* aName, 
       
   144                                     DuiNode* /*mNode*/,
       
   145                                     AlfCustomInitDataBase* /*aCustomData*/)
       
   146     : mData(NULL)
       
   147     {
       
   148     try
       
   149         {
       
   150         // Base class (AlfElement) construct
       
   151         construct(aControl, aName);   
       
   152           
       
   153         mLongTapTimer.reset( 
       
   154             new (EMM) AlfScrollBarLongTapTimer(this));
       
   155         
       
   156         mIsLongTapObserverSet=EFalse;
       
   157         //For Imperative construct
       
   158         createDefaultBaseElement();
       
   159         }
       
   160     catch(AlfException& e)
       
   161         {
       
   162         aControl.removeElement(*this);
       
   163         throw;
       
   164         }
       
   165     // AlfScrollBarDefaultBaseElement is an event handler too so it 
       
   166     // should be added to the control
       
   167     aControl.addEventHandler(this);
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 //  Destructor
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 AlfScrollBarDefaultBaseElement::~AlfScrollBarDefaultBaseElement()
       
   175     {
       
   176     
       
   177     if(mData)
       
   178         {
       
   179         delete mData;
       
   180         }
       
   181     else
       
   182         {
       
   183         
       
   184         }
       
   185     if(mLCTData)
       
   186         {
       
   187         delete mLCTData;
       
   188         }
       
   189     else
       
   190         {
       
   191         
       
   192         }
       
   193     }//End of Destructor
       
   194 
       
   195 //--------------------------------------------------------------------------
       
   196 // APIs from the IAlfScrollBarDefaultBaseElement for controlling the 
       
   197 // visualization of the scrollbar
       
   198 //--------------------------------------------------------------------------
       
   199 
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // Sets the thumb animation time.
       
   203 // @aTime     : Time in miliseconds
       
   204 // @exception : for aTime less then O.0 miliseconds
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void AlfScrollBarDefaultBaseElement::setThumbAnimationTime ( int aTime )
       
   208     {
       
   209     // Sanity check
       
   210     if (aTime < 0)
       
   211     	{
       
   212     	ALF_THROW(AlfException, EInvalidArgument, "AnimationTime is invalid");
       
   213     	}
       
   214     else
       
   215     	{
       
   216     	// do nothing
       
   217     	}	
       
   218     
       
   219     if(mData->mThumbAnimationTime != aTime)
       
   220     	{
       
   221     	mData->mThumbAnimationTime = aTime;
       
   222     	}
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // From class IAlfScrollBarWdget.
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 int AlfScrollBarDefaultBaseElement::getThumbAnimationTime() const
       
   230     {
       
   231     return mData->mThumbAnimationTime;
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // Sets opacity value for the Thumb.
       
   236 // Thumb opacity is relative to the track.
       
   237 // @param     : aOpacity float value between 0.0 to 1.0
       
   238 // @exception : value of aOpacity more than 1.0 and less than 0.0
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void AlfScrollBarDefaultBaseElement::setThumbOpacity (float aOpacity)
       
   242     {
       
   243     // Sanity check
       
   244    if (realCompare(aOpacity, 0.0, KEpsilon) < 0
       
   245        || realCompare(aOpacity, 1.0, KEpsilon) > 0)
       
   246        {
       
   247        ALF_THROW(AlfException, EInvalidArgument, "Opacity is invalid");
       
   248        }
       
   249    else
       
   250        {
       
   251        // do nothing
       
   252        }
       
   253     // if there is a change, update the visualization
       
   254     if (aOpacity != mData->mThumbOpacity)
       
   255         {
       
   256         mData->mThumbOpacity = aOpacity;
       
   257         const TAlfTimedValue opacity(mData->mThumbOpacity * mData->mWidgetOpacity);
       
   258         if(mData->mThumbLayout)
       
   259             {
       
   260             mData->mThumbLayout->SetOpacity(opacity);
       
   261             control().Visual(0).UpdateChildrenLayout();
       
   262             }
       
   263         }
       
   264     }//End of setThumbOpacity
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // Returns Thumb opacity is relative to the track.
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 float AlfScrollBarDefaultBaseElement::getThumbOpacity() const
       
   271     {
       
   272     return mData->mThumbOpacity;
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // Sets opacity value for the widget.
       
   277 // 
       
   278 // @param     : aOpacity float value between 0.0 to 1.0
       
   279 // @exception : value of aOpacity more than 1.0 and less than 0.0
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 void AlfScrollBarDefaultBaseElement::setOpacity (float aOpacity)
       
   283     {
       
   284     // Sanity check
       
   285    if (realCompare(aOpacity, 0.0, KEpsilon) < 0
       
   286        || realCompare(aOpacity, 1.0, KEpsilon) > 0)
       
   287        {
       
   288        ALF_THROW(AlfException, EInvalidArgument, "Opacity is invalid");
       
   289        }
       
   290    else
       
   291        {
       
   292        // do nothing
       
   293        }
       
   294     // if there is a change, update the visualization
       
   295     if (aOpacity != mData->mWidgetOpacity)
       
   296         {
       
   297         mData->mWidgetOpacity = aOpacity;
       
   298         const TAlfTimedValue opacity(mData->mWidgetOpacity);
       
   299         if(mData->mTrackLayout)
       
   300             {
       
   301             mData->mRootLayout->SetOpacity(opacity);
       
   302             control().Visual(0).UpdateChildrenLayout();
       
   303             }
       
   304         }
       
   305     }//End of setThumbOpacity
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // Returns Widget opacity is relative to the track.
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 float AlfScrollBarDefaultBaseElement::getOpacity() const
       
   312     {
       
   313     return mData->mWidgetOpacity;
       
   314     }
       
   315 
       
   316 //--------------------------------------------------------------------------
       
   317 // APIs from the IAlfScrollBarBaseElement 
       
   318 //--------------------------------------------------------------------------
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // Gets called when the parent layout is relayouted.
       
   322 // resets all the anchor points and updates the visualization
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 void AlfScrollBarDefaultBaseElement::baseLayoutSizeChanged()
       
   326     {
       
   327     initializeLayout();    
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // processPointerEvent generates custom events 
       
   332 // according the focus visual .
       
   333 // ---------------------------------------------------------------------------
       
   334 //
       
   335 bool AlfScrollBarDefaultBaseElement::processPointerEvent(TAlfEvent * aPntrEvent)
       
   336     {
       
   337     // retrieve pointer event (NULL check not required here)
       
   338     // Get the hit visual
       
   339     CAlfVisual *focusvisual =aPntrEvent->Visual();
       
   340     
       
   341     if ( aPntrEvent->IsPointerEvent()  )
       
   342         {
       
   343         if (aPntrEvent->PointerEvent().iType == TPointerEvent::EButton1Down)
       
   344             {
       
   345             bool ret = handlePointerDownEvent(aPntrEvent);	
       
   346             return ret;
       
   347             }
       
   348         else if (aPntrEvent->PointerEvent().iType == TPointerEvent::EDrag)
       
   349             {
       
   350             if(!mData->mOperation) 
       
   351                 {
       
   352                 // Drag during tap and hold on track 
       
   353                 if(mIsLongTapObserverSet)
       
   354                     {
       
   355                     mData->mLongTapPos=aPntrEvent->PointerEvent().iParentPosition;
       
   356                     }
       
   357                 else
       
   358                     {
       
   359                     //Do Nothing.
       
   360                     }    
       
   361                 }
       
   362             else
       
   363                 {
       
   364                 // Drag on thumb
       
   365                 if(mIsLongTapObserverSet &&
       
   366                    mData->mVisual && (isScrollbarThumbVisual(focusvisual)) )
       
   367                     {
       
   368                     mData->mLongTapPos= aPntrEvent->PointerEvent().iParentPosition ;
       
   369                     }
       
   370                 else
       
   371                     {
       
   372                     // Do nothing
       
   373                     }
       
   374                 int dist = aPntrEvent->PointerEvent().iParentPosition.iY - mData->mDragPoint.iY;
       
   375                 int steps = ceil(dist / mData->mStepSize) + mData->mDragStartStep;
       
   376                                                 
       
   377                 // checking steps to avoid negative value, incase of max scrollbar length
       
   378                 if(  steps >  mData->mScrollbarModel->getTotalLength() -  mData->mScrollbarModel->getViewLength()) 
       
   379                      {
       
   380                      steps =  mData->mScrollbarModel->getTotalLength() -  mData->mScrollbarModel->getViewLength(); 
       
   381                      }   
       
   382                else if(steps <  0 )   
       
   383                      {
       
   384                      steps =  0;
       
   385                      } 
       
   386                 if(steps !=  mData->mScrollbarModel->getViewStartPosition())
       
   387                     {
       
   388                     // send tactile sensitive event
       
   389                     //control().processEvent(TAlfEvent(EEventScrollBarDrag));
       
   390                     TAlfEvent customevent(EEventDragVertical,(TInt )steps);
       
   391                     control().processEvent(customevent);
       
   392                     }
       
   393                 // Tactile Feedback for Thumb drag
       
   394                 AlfScrollBarControl& slbrcntrl = static_cast<AlfScrollBarControl&>(control());
       
   395                 slbrcntrl.TactileEffectOnDrag(*aPntrEvent);
       
   396                 }    
       
   397             }
       
   398         
       
   399         else if(aPntrEvent->PointerUp()  )
       
   400             {
       
   401             mData->mLongTapStarted = false;
       
   402             handlePointerUpEvent();
       
   403             }
       
   404         else
       
   405             {
       
   406             //Do Nothing.
       
   407             }
       
   408     }
       
   409     
       
   410     return true;
       
   411     }//End of processPointerEvent
       
   412 
       
   413 void AlfScrollBarDefaultBaseElement::createVisualization()
       
   414     {
       
   415     initializeScrollModel();
       
   416     CAlfWidgetControl  *ctrl = &control();
       
   417     
       
   418     // Create Root Layout
       
   419     mData->mRootLayout = CAlfLayout::AddNewL(*((CAlfControl*)ctrl),NULL);
       
   420     mData->mRootLayout->SetFlag(EAlfVisualFlagLayoutUpdateNotification);
       
   421     mData->mRootLayout->SetFlag( EAlfVisualFlagAutomaticLocaleMirroringEnabled );	
       
   422                        
       
   423     // Create Track Layout
       
   424     mData->mTrackLayout = CAlfLayout::AddNewL(*((CAlfControl*)ctrl),mData->mRootLayout);
       
   425     mData->mTrackLayout->SetFlag( EAlfVisualFlagAutomaticLocaleMirroringEnabled );
       
   426     mData->mExtendedTrackLayout = CAlfLayout::AddNewL(*((CAlfControl*)ctrl),mData->mTrackLayout);
       
   427     
       
   428     if(mData->mTrackLayout)
       
   429         {
       
   430         mData->mTrackTopImage = CAlfImageVisual::AddNewL(
       
   431             *((CAlfControl*)ctrl),mData->mTrackLayout);
       
   432         mData->mTrackMiddleImage = CAlfImageVisual::AddNewL(
       
   433             *((CAlfControl*)ctrl),mData->mTrackLayout);
       
   434         mData->mTrackEndImage = CAlfImageVisual::AddNewL(
       
   435             *((CAlfControl*)ctrl),mData->mTrackLayout);
       
   436             
       
   437         if(mData->mTrackTopImage && 
       
   438            mData->mTrackMiddleImage && 
       
   439            mData->mTrackEndImage)
       
   440             {
       
   441             setTrackImage();
       
   442             }
       
   443          
       
   444         // Create Thumb Visuals    
       
   445         mData->mThumbLayout = CAlfLayout::AddNewL(*((CAlfControl*)ctrl),
       
   446                                                         mData->mRootLayout);
       
   447         mData->mThumbLayout->SetFlag( EAlfVisualFlagAutomaticLocaleMirroringEnabled );
       
   448         mData->mExtendedThumbLayout = CAlfLayout::AddNewL(*((CAlfControl*)ctrl),
       
   449                                                         mData->mThumbLayout);
       
   450        
       
   451         if(mData->mThumbLayout)
       
   452             {
       
   453             mData->mThumbTopImage = CAlfImageVisual::AddNewL(
       
   454                 *((CAlfControl*)ctrl),mData->mThumbLayout);
       
   455             mData->mThumbMiddleImage = CAlfImageVisual::AddNewL(
       
   456                 *((CAlfControl*)ctrl),mData->mThumbLayout);
       
   457             mData->mThumbEndImage = CAlfImageVisual::AddNewL(
       
   458                 *((CAlfControl*)ctrl),mData->mThumbLayout);
       
   459                
       
   460             if(mData->mThumbTopImage && 
       
   461                mData->mThumbMiddleImage && 
       
   462                mData->mThumbEndImage)
       
   463                 {
       
   464                 setThumbImage();
       
   465                 }
       
   466             }
       
   467         }
       
   468     }
       
   469 
       
   470 void AlfScrollBarDefaultBaseElement::updateVisualization()
       
   471     {
       
   472     calculateStepSizeAndThumbLength();
       
   473     if(mData->mViewLength !=  mData->mScrollbarModel->getViewLength() || mData->mTotalLength !=  mData->mScrollbarModel->getTotalLength())
       
   474         {
       
   475         mData->mViewLength =  mData->mScrollbarModel->getViewLength();
       
   476         mData->mTotalLength =  mData->mScrollbarModel->getTotalLength();
       
   477         initializeThumbLayout();
       
   478         }
       
   479     TAlfRealPoint thumbPos;
       
   480     thumbPos.iX = mData->mThumbLayout->Pos().iX.ValueNow();        	
       
   481     thumbPos.iY = ceil(mData->mStepSize *  mData->mScrollbarModel->getViewStartPosition());
       
   482     mData->mThumbLayout->SetPos(thumbPos,mData->mThumbAnimationTime);
       
   483     }
       
   484 
       
   485 void AlfScrollBarDefaultBaseElement::destroyVisualization()
       
   486     {
       
   487     mData->mRootLayout->RemoveAndDestroyAllD();
       
   488     delete mData;
       
   489     delete mLCTData;
       
   490     createDefaultBaseElement();
       
   491     }
       
   492 
       
   493 // ---------------------------------------------------------------------------
       
   494 // From class MAlfInterfaceBase.
       
   495 // Getter for interfaces provided by the scrollbar widget.
       
   496 // ---------------------------------------------------------------------------
       
   497 //
       
   498 IAlfInterfaceBase* AlfScrollBarDefaultBaseElement::makeInterface(
       
   499                         const IfId& aType)
       
   500     {
       
   501     UString param (aType.mImplementationId);
       
   502     if (param == 
       
   503         IAlfScrollBarDefaultBaseElement::type().mImplementationId)
       
   504         {
       
   505         return static_cast<IAlfScrollBarDefaultBaseElement*>(this);
       
   506         }
       
   507     else if (param == IAlfWidgetEventHandler::type().mImplementationId)
       
   508         {
       
   509         return static_cast<IAlfWidgetEventHandler*>(this);
       
   510         }
       
   511 
       
   512     else if (param == 
       
   513         IAlfScrollBarBaseElementInternal::type().mImplementationId)
       
   514         {
       
   515         return static_cast<IAlfScrollBarBaseElementInternal*>(this);
       
   516         } 
       
   517     else
       
   518         {
       
   519         //do nothing
       
   520         }
       
   521     return AlfElement::makeInterface(aType);
       
   522     }
       
   523 
       
   524 // ---------------------------------------------------------------------------
       
   525 //  handles the pointerDown event
       
   526 // 
       
   527 // ---------------------------------------------------------------------------
       
   528 //
       
   529 bool AlfScrollBarDefaultBaseElement::handlePointerDownEvent(TAlfEvent * aPntrEvent)
       
   530     {
       
   531     CAlfVisual * focusvisual = aPntrEvent->Visual();
       
   532     AlfEventStatus result = EEventNotHandled;
       
   533     
       
   534     if (focusvisual)
       
   535         {
       
   536         mData->mVisual = focusvisual;
       
   537         
       
   538         // Register with the Roster to receive drag Event    
       
   539         control().Display()->Roster().SetPointerEventObservers( 
       
   540            EAlfPointerEventReportDrag ,control());
       
   541         
       
   542         if(!mData->mOperation)
       
   543                 {
       
   544                 mIsLongTapObserverSet = ETrue;
       
   545                 mData->mLongTapPos = aPntrEvent->PointerEvent().iParentPosition;
       
   546                 mData->mLongTapStarted = true;
       
   547                 control().processEvent(TAlfEvent(EEventScrollBarTouchDown));
       
   548                 mLongTapTimer->Start();
       
   549                 }
       
   550            
       
   551         // Pointer down on track   
       
   552         if (isScrollbarTrackVisual(focusvisual))
       
   553                 {
       
   554                 mData->mLongTapStarted = true;
       
   555                 return trackVisualHit(focusvisual);
       
   556                 }
       
   557         
       
   558         // Pointer down on thumb
       
   559         else if (isScrollbarThumbVisual(focusvisual))
       
   560                 {
       
   561                 if(!mData->mOperation)
       
   562                     {
       
   563                     initializeThumbDragData( aPntrEvent->PointerEvent().iParentPosition); 
       
   564                     AlfScrollBarControl& slbrcntrl = static_cast<AlfScrollBarControl&>(control());
       
   565                     slbrcntrl.TactileEffectOnTouchandHold();
       
   566                     }
       
   567                 result = EEventHandled;
       
   568                 }
       
   569         }
       
   570     return result;
       
   571     }
       
   572 
       
   573 // ---------------------------------------------------------------------------
       
   574 //  Sends drag Up or Down event, according to the hit position
       
   575 //  on track
       
   576 // ---------------------------------------------------------------------------
       
   577 //
       
   578 AlfEventStatus AlfScrollBarDefaultBaseElement::trackVisualHit(CAlfVisual * /*aHitVisual*/)
       
   579     {
       
   580     //Get Co-Ordinates of the click event
       
   581     //Find the thumb Anchor Layout.
       
   582     TAlfTimedPoint thumbVisPos = mData->mThumbLayout->Pos();
       
   583     TAlfTimedPoint thumbVisSize =mData->mThumbLayout->Size();
       
   584     TAlfRealRect rct= mData->mTrackLayout->DisplayRect() ;
       
   585     //Check if click was above/below of thumb
       
   586     if (mData->mLongTapPos.iY - rct.iTl.iY < thumbVisPos.iY.ValueNow())
       
   587         {
       
   588         if(mData->mLongTapStarted)
       
   589             {
       
   590             //control().processEvent(TAlfEvent(EEventScrollBarDrag));
       
   591             control().processEvent(TAlfEvent (EEventScrollPageUp));
       
   592             }
       
   593         }
       
   594     else if (mData->mLongTapPos.iY - rct.iTl.iY > (thumbVisPos.iY.ValueNow() + 
       
   595         thumbVisSize.iY.ValueNow()) )
       
   596         {
       
   597         if(mData->mLongTapStarted)
       
   598             {
       
   599             //control().processEvent(TAlfEvent(EEventScrollBarDrag));
       
   600             control().processEvent(TAlfEvent(EEventScrollPageDown));
       
   601             }
       
   602         }
       
   603     else 
       
   604         {
       
   605         if(mIsLongTapObserverSet)
       
   606             {
       
   607             // Stop the long tap timer
       
   608             mLongTapTimer->Stop();
       
   609             mData->mLongTapStarted = false; 
       
   610             //mIsLongTapObserverSet = EFalse;    
       
   611             }
       
   612         else
       
   613             {
       
   614             //Do Nothing.
       
   615             }                            
       
   616             }
       
   617     return EEventHandled;
       
   618     }  
       
   619 
       
   620 // ---------------------------------------------------------------------------
       
   621 //  handles the pointerUp event
       
   622 // 
       
   623 // ---------------------------------------------------------------------------
       
   624 //
       
   625 void AlfScrollBarDefaultBaseElement::handlePointerUpEvent()
       
   626     {
       
   627     // if thumb or track is clicked, change the graphics
       
   628     if(mData->mCurrentState == ETrackPressed || mData->mCurrentState == EThumbPressed)
       
   629         {
       
   630         mData->mCurrentState = EReleased;
       
   631         changeGraphics();
       
   632         }
       
   633     
       
   634     if(mData->mOperation)
       
   635         {
       
   636         //Somehow missed the Up event 
       
   637         stopDrag(NULL,0);
       
   638         AlfScrollBarControl& slbrcntrl = static_cast<AlfScrollBarControl&>(control());
       
   639         slbrcntrl.TactileEffectOnRelease();
       
   640         }
       
   641     if(mIsLongTapObserverSet)
       
   642         {
       
   643         // Stop the long tap timer
       
   644         mLongTapTimer->Stop();
       
   645         
       
   646         // Un-register with the roster for long tap events 
       
   647         control().Display()->Roster().SetPointerEventObservers(0,
       
   648             control());
       
   649         mIsLongTapObserverSet = EFalse;    
       
   650         }
       
   651     }
       
   652 
       
   653 AlfEventStatus AlfScrollBarDefaultBaseElement::handleLongTapEvent()
       
   654     {
       
   655     AlfEventStatus ret= EEventNotHandled;
       
   656     
       
   657     if (isScrollbarTrackVisual(mData->mVisual))
       
   658         {
       
   659         mData->mLongTapStarted = true;
       
   660         ret = trackVisualHit(mData->mVisual);
       
   661         // Long tap Tactile feedback 
       
   662         AlfScrollBarControl& slbrcntrl = static_cast<AlfScrollBarControl&>(control());
       
   663         slbrcntrl.TactileEffectOnTouchandHold();
       
   664         }
       
   665     return ret;
       
   666     }
       
   667 
       
   668 //--------------------------------------------------------------------------
       
   669 //Overriden Apis from IAlfWidgetEventHandlers
       
   670 //--------------------------------------------------------------------------
       
   671 //
       
   672 
       
   673 // ---------------------------------------------------------------------------
       
   674 // From class IAlfWidgetEventHandler.
       
   675 // ---------------------------------------------------------------------------
       
   676 //
       
   677 bool AlfScrollBarDefaultBaseElement::accept(
       
   678         CAlfWidgetControl& /*aControl*/,
       
   679         const TAlfEvent& aEvent ) const
       
   680     {
       
   681     // Scrollbar baseElement handles only EEventScrollBarClicked 
       
   682     // and EEventScrollBarClicked cusbtom events
       
   683     // EEventScrollBarClicked event come from scrollbar control and  
       
   684     // EEventScrollBarModelChanged event comes from scrollable widget
       
   685     if (aEvent.CustomParameter() == EEventScrollBarClicked ||
       
   686         aEvent.CustomParameter() == EEventScrollBarModelChanged)
       
   687         {
       
   688         return true;
       
   689         }
       
   690     return false;
       
   691     }
       
   692 
       
   693 IAlfWidgetEventHandler::AlfEventHandlerType AlfScrollBarDefaultBaseElement::eventHandlerType()
       
   694     {
       
   695     return IAlfWidgetEventHandler::EPresentationEventHandler;
       
   696     }
       
   697 
       
   698 IAlfWidgetEventHandler::AlfEventHandlerExecutionPhase AlfScrollBarDefaultBaseElement::eventExecutionPhase()
       
   699     {
       
   700     return IAlfWidgetEventHandler::ETunnellingPhaseEventHandler;
       
   701     }
       
   702 
       
   703 AlfEventStatus AlfScrollBarDefaultBaseElement::offerEvent(
       
   704             CAlfWidgetControl& /*aControl*/,
       
   705             const TAlfEvent& aEvent )
       
   706     {
       
   707     AlfEventStatus ret= EEventNotHandled;
       
   708     // Dont do event handling incase widget & thumb opacity is zero
       
   709     if(mData->mWidgetOpacity && mData->mThumbOpacity )
       
   710         {
       
   711         if (aEvent.IsCustomEvent())
       
   712         {
       
   713         switch(aEvent.CustomParameter())
       
   714             {
       
   715             // The event is coming from scrollbale widget
       
   716             case EEventScrollBarModelChanged:
       
   717                 {
       
   718                 if( mData->mScrollbarModel)
       
   719                     {
       
   720                     ScrollModelChangedEventData* scrollEventData = 
       
   721                     (ScrollModelChangedEventData*)aEvent.CustomEventData();  
       
   722                     
       
   723                         // Change the model which intern will update visualization 
       
   724                          mData->mScrollbarModel->changeData(
       
   725                                         scrollEventData->mSpan,
       
   726                                         scrollEventData->mViewLength,
       
   727                                         scrollEventData->mViewStartPos);
       
   728                         ret=EEventHandled;
       
   729                     }
       
   730             }
       
   731             break;
       
   732             
       
   733             case EEventMissedPointerUp:
       
   734                 {
       
   735                 mData->mLongTapStarted = false;
       
   736                 ret=EEventHandled;
       
   737                 handlePointerUpEvent();
       
   738                 }
       
   739             break;
       
   740             
       
   741             case EEventScrollBarClicked:
       
   742                 {
       
   743                 ret = handleScrollBarClickedEvent(aEvent);
       
   744                 }
       
   745             break;
       
   746             
       
   747             default:
       
   748             break;
       
   749             }
       
   750         }
       
   751     }
       
   752     return ret;
       
   753     }
       
   754 
       
   755  AlfEventStatus AlfScrollBarDefaultBaseElement::handleScrollBarClickedEvent(
       
   756             const TAlfEvent& aEvent )
       
   757      {
       
   758      AlfEventStatus ret= EEventNotHandled;
       
   759      TAlfEvent * pntrEvent=(TAlfEvent *)aEvent.CustomEventData();
       
   760      if(pntrEvent)
       
   761          {
       
   762          // Get the hit visual
       
   763          CAlfVisual *focusvisual = pntrEvent->Visual();
       
   764          if(focusvisual && 
       
   765                  pntrEvent->PointerEvent().iType == TPointerEvent::EButton1Down)
       
   766                     {
       
   767                     // check if the click is made on thumb
       
   768                     if (isScrollbarThumbVisual(focusvisual))
       
   769                         {
       
   770                         mData->mCurrentState = EThumbPressed;
       
   771                         // Change the graphics to pressed one
       
   772                         changeGraphics();
       
   773                         }
       
   774                     else if (isScrollbarTrackVisual(focusvisual))
       
   775                         {     
       
   776                         mData->mCurrentState  = ETrackPressed;
       
   777                         // Change the graphics to pressed one
       
   778                         changeGraphics();
       
   779                         }
       
   780                     }
       
   781          // Blocking event processing in case of maxthumblength,
       
   782          // case 1 : revert back the graphics change incase of maxscrollbar length
       
   783          if(pntrEvent->PointerUp() &&  mData->mScrollbarModel->getViewLength() >=  mData->mScrollbarModel->getTotalLength())
       
   784              {
       
   785              handlePointerUpEvent();
       
   786              }
       
   787          // case 2 : process the event in all other case except max length
       
   788          else if( mData->mScrollbarModel->getViewLength() !=  mData->mScrollbarModel->getTotalLength())
       
   789              {
       
   790              processPointerEvent(pntrEvent);
       
   791              }
       
   792          // case2 : do nothing incase of maxscrollbar length
       
   793          else
       
   794              {
       
   795              // do nothing
       
   796              }
       
   797              ret = EEventHandled;
       
   798          }
       
   799      else
       
   800          {
       
   801          ret = EEventNotHandled;
       
   802          }
       
   803     
       
   804      return ret;
       
   805     }
       
   806 
       
   807 void AlfScrollBarDefaultBaseElement::setActiveStates(
       
   808     unsigned int /*aStates*/)
       
   809     {
       
   810     //do nothing
       
   811     }
       
   812 
       
   813 // ---------------------------------------------------------------------------
       
   814 // From class IAlfScrollBarBaseElementInternal.
       
   815 // ---------------------------------------------------------------------------
       
   816 //
       
   817 
       
   818 // ---------------------------------------------------------------------------
       
   819 // initializes scrollbar layout 
       
   820 // ---------------------------------------------------------------------------
       
   821 //
       
   822 void AlfScrollBarDefaultBaseElement::initializeLayout()
       
   823     {
       
   824     setThumbMinMaxLength();
       
   825     calculateStepSizeAndThumbLength();
       
   826     initializeTrackLayout();
       
   827     initializeThumbLayout();
       
   828     }
       
   829 
       
   830 // ---------------------------------------------------------------------------
       
   831 // initializes scrollbar Track layout 
       
   832 // ---------------------------------------------------------------------------
       
   833 //
       
   834 void AlfScrollBarDefaultBaseElement::initializeTrackLayout()
       
   835     {
       
   836     
       
   837     TAknWindowLineLayout ExtendedTrackLayoutHandle = 
       
   838                 AknLayoutScalable_UiAccel::
       
   839                 aid_size_touch_aascroll_bar(0).LayoutLine();
       
   840     // negative offset for the extended active area layout.
       
   841     // Width values based on LCT data for extended touch
       
   842     mData->mExtendedTouch = - (ExtendedTrackLayoutHandle.iW -  
       
   843                     mData->mRootLayout->Size().iX.ValueNow());                  
       
   844                     
       
   845     // Create Track Visuals
       
   846     if(mData->mTrackLayout)
       
   847         {
       
   848         TAknWindowLineLayout TrackLayoutHandle = 
       
   849             AknLayoutScalable_UiAccel:: hc_scroll_bg_pane(0).LayoutLine();
       
   850         
       
   851         // Root layout rect, parent rect for track and thumb layout
       
   852         TRect rootLayoutRect(0,
       
   853                              0,
       
   854                              mData->mRootLayout->Size().iX.ValueNow(),
       
   855                              mData->mRootLayout->Size().iY.ValueNow());
       
   856         
       
   857         TAknLayoutRect TracklayoutRect;
       
   858         TracklayoutRect.LayoutRect(rootLayoutRect, TrackLayoutHandle);
       
   859         mData->mTrackLayout->SetRect(TracklayoutRect.Rect(),0.0);
       
   860         
       
   861         // set position and size for extended track layout
       
   862         setPositionAndSize(mData->mExtendedTrackLayout,
       
   863                 mData->mExtendedTouch,0 ,
       
   864                 mData->mExtendedTouch,
       
   865                 mData->mTrackLayout->Size().iY.ValueNow());
       
   866         
       
   867         if(mData->mTrackTopImage && 
       
   868            mData->mTrackMiddleImage && 
       
   869            mData->mTrackEndImage)
       
   870             {
       
   871             // parent rect for track images
       
   872             TRect Trackrect(0,
       
   873                             0,
       
   874                             mData->mTrackLayout->Size().iX.ValueNow(),
       
   875                             mData->mTrackLayout->Size().iY.ValueNow());
       
   876             
       
   877             TAknWindowLineLayout TrackTopHandle = 
       
   878                 AknLayoutScalable_UiAccel::hc_scroll_bg_pane_g1(0).LayoutLine();
       
   879             setLCTData(Trackrect,TrackTopHandle,mData->mTrackTopImage);
       
   880            
       
   881             TAknWindowLineLayout TrackMiddleHandle = 
       
   882                 AknLayoutScalable_UiAccel::hc_scroll_bg_pane_g2(0).LayoutLine();
       
   883             setLCTData(Trackrect,TrackMiddleHandle,mData->mTrackMiddleImage);
       
   884             
       
   885             TAknWindowLineLayout TrackEndHandle = 
       
   886                 AknLayoutScalable_UiAccel::hc_scroll_bg_pane_g3(0).LayoutLine();
       
   887             setLCTData(Trackrect,TrackEndHandle,mData->mTrackEndImage);
       
   888            }
       
   889          }
       
   890     }
       
   891 
       
   892 // ---------------------------------------------------------------------------
       
   893 // initializes scrollbar Thumb layout 
       
   894 // ---------------------------------------------------------------------------
       
   895 //
       
   896 void AlfScrollBarDefaultBaseElement::initializeThumbLayout()
       
   897     {
       
   898     // Create Track Visuals
       
   899     if(mData->mTrackLayout)
       
   900         {
       
   901         if(mData->mThumbLayout)
       
   902             {
       
   903             // Get thumb WindowLine Layout
       
   904             TAknWindowLineLayout ThumbLayoutHandle = 
       
   905                     AknLayoutScalable_UiAccel::hc_scroll_handle_pane(0).LayoutLine();
       
   906             
       
   907             // Root layout rect, parent rect for track and thumb layout
       
   908             TRect rootLayoutRect(0,
       
   909                                  0,
       
   910                                  mData->mRootLayout->Size().iX.ValueNow(),
       
   911                                  mData->mRootLayout->Size().iY.ValueNow());
       
   912             
       
   913            TAknLayoutRect ThumblayoutRect;
       
   914            ThumblayoutRect.LayoutRect(rootLayoutRect, ThumbLayoutHandle);
       
   915            
       
   916            // set thumb height and thumb start position from model
       
   917            mLCTData->height = mData->mThumbLength;
       
   918                                	   
       
   919            mLCTData->top = 
       
   920                       ceil(mData->mStepSize *  mData->mScrollbarModel->getViewStartPosition());     
       
   921                       
       
   922            setPositionAndSize(mData->mThumbLayout,
       
   923                          ThumblayoutRect.Rect().iTl.iX,
       
   924                          mLCTData->top,
       
   925                          ThumblayoutRect.Rect().Size().iWidth,
       
   926                          mLCTData->height);
       
   927            // Setting position and size for extended thumb layout
       
   928            setPositionAndSize(mData->mExtendedThumbLayout ,
       
   929                          mData->mExtendedTouch ,
       
   930                          0,
       
   931                          mData->mExtendedTouch,
       
   932                          mLCTData->height);
       
   933             
       
   934             if(mData->mThumbTopImage && 
       
   935                mData->mThumbMiddleImage && 
       
   936                mData->mThumbEndImage)
       
   937                 {
       
   938                // parent rect for thumb images
       
   939                TRect ThumbRect(0,
       
   940                                0,
       
   941                                mData->mThumbLayout->Size().iX.ValueNow(),
       
   942                                mData->mThumbLayout->Size().iY.ValueNow());
       
   943                 
       
   944                TAknWindowLineLayout ThumbTopHandle = 
       
   945                     AknLayoutScalable_UiAccel::hc_scroll_handle_pane_g1(0).LayoutLine();
       
   946                setLCTData(ThumbRect,ThumbTopHandle,mData->mThumbTopImage);
       
   947                
       
   948                TAknWindowLineLayout ThumbMiddleHandle = 
       
   949                     AknLayoutScalable_UiAccel::hc_scroll_handle_pane_g2(0).LayoutLine();
       
   950                setLCTData(ThumbRect,ThumbMiddleHandle,mData->mThumbMiddleImage);
       
   951                
       
   952                TAknWindowLineLayout ThumbEndHandle = 
       
   953                     AknLayoutScalable_UiAccel::hc_scroll_handle_pane_g3(0).LayoutLine();
       
   954                setLCTData(ThumbRect,ThumbEndHandle,mData->mThumbEndImage);
       
   955                 }
       
   956             }
       
   957         }
       
   958     }
       
   959 
       
   960 // ---------------------------------------------------------------------------
       
   961 // sets LCT Data (position and size) for the visual 
       
   962 // ---------------------------------------------------------------------------
       
   963 //
       
   964 void AlfScrollBarDefaultBaseElement::setLCTData(const TRect& aRect ,
       
   965                                                 TAknWindowLineLayout& aWindowLineLayout,
       
   966                                                 CAlfVisual * aVisual)
       
   967     {
       
   968     TAknLayoutRect layoutRect;
       
   969     layoutRect.LayoutRect(aRect, aWindowLineLayout);
       
   970          
       
   971     setPositionAndSize(aVisual,layoutRect.Rect().iTl.iX,layoutRect.Rect().iTl.iY,
       
   972                       layoutRect.Rect().Size().iWidth,layoutRect.Rect().Size().iHeight);
       
   973     }
       
   974 
       
   975 // ---------------------------------------------------------------------------
       
   976 // sets position and size for the visual 
       
   977 // ---------------------------------------------------------------------------
       
   978 //
       
   979 void AlfScrollBarDefaultBaseElement::setPositionAndSize(CAlfVisual * aVisual,
       
   980                                                       int aXVal,int aYVal, 
       
   981                                                       int aWidth,int aHeight)
       
   982     {
       
   983     TAlfRealPoint trackTopPnt(aXVal,aYVal);
       
   984     TAlfRealSize trackTopSize(aWidth,aHeight);
       
   985     aVisual->SetPos(trackTopPnt,0);
       
   986     aVisual->SetSize(trackTopSize,0);
       
   987     }
       
   988 
       
   989 // ---------------------------------------------------------------------------
       
   990 // initializes scrollbar model pointer for further reference 
       
   991 // ---------------------------------------------------------------------------
       
   992 //
       
   993 void AlfScrollBarDefaultBaseElement::initializeScrollModel()
       
   994     {
       
   995     // Store the ScrollBar Model Pointer;
       
   996     IAlfWidgetFactory& widgetFactory =AlfWidgetEnvExtension::widgetFactory(control().Env());
       
   997     AlfScrollBarWidget* wdgt = static_cast<AlfScrollBarWidget*>(widgetFactory.findWidget(control().widget()->widgetName()));
       
   998     //Get model pointer
       
   999     IAlfScrollBarModel* model = static_cast<IAlfScrollBarModel*>(wdgt->model());
       
  1000     mData->mScrollbarModel = static_cast<AlfScrollBarModel*>(model);
       
  1001     }
       
  1002 
       
  1003 
       
  1004 // ---------------------------------------------------------------------------
       
  1005 // Set images for the track 
       
  1006 // ---------------------------------------------------------------------------
       
  1007 //
       
  1008 void AlfScrollBarDefaultBaseElement::setTrackImage()
       
  1009     {
       
  1010     TInt flags = EAlfTextureFlagSkinContent;
       
  1011     flags |= EAlfTextureFlagAutoSize;
       
  1012    
       
  1013     // Create skin Image
       
  1014     TAlfImage trackTopImage(KAknsIIDQsnCpScrollBgTop,TSize(0,0), 
       
  1015                             EAspectRatioNotPreserved,NULL, 
       
  1016                             -1,-1,0.f,0.f,1.f,1.f,
       
  1017                             (TAlfTextureFlags)flags);
       
  1018     TAlfImage trackMiddleImage(KAknsIIDQsnCpScrollBgMiddle, TSize(0,0), 
       
  1019                                EAspectRatioNotPreserved, NULL, 
       
  1020                                -1, -1, 0.f, 0.f, 1.f, 1.f, 
       
  1021                                (TAlfTextureFlags)flags);
       
  1022     TAlfImage trackEndImage(KAknsIIDQsnCpScrollBgBottom, TSize(0,0), 
       
  1023                             EAspectRatioNotPreserved, NULL, 
       
  1024                             -1, -1, 0.f, 0.f, 1.f, 1.f, 
       
  1025                             (TAlfTextureFlags)flags);
       
  1026     TAlfImage trackTopPressedImage(KAknsIIDQsnCpScrollBgTopPressed,TSize(0,0), 
       
  1027                                 EAspectRatioNotPreserved,NULL, 
       
  1028                                 -1,-1,0.f,0.f,1.f,1.f,
       
  1029                                 (TAlfTextureFlags)flags);
       
  1030     TAlfImage trackMiddlePressedImage(KAknsIIDQsnCpScrollBgMiddlePressed, TSize(0,0), 
       
  1031                                EAspectRatioNotPreserved, NULL, 
       
  1032                                -1, -1, 0.f, 0.f, 1.f, 1.f, 
       
  1033                                (TAlfTextureFlags)flags);
       
  1034     TAlfImage trackEndPressedImage(KAknsIIDQsnCpScrollBgBottomPressed, TSize(0,0), 
       
  1035                             EAspectRatioNotPreserved, NULL, 
       
  1036                             -1, -1, 0.f, 0.f, 1.f, 1.f, 
       
  1037                             (TAlfTextureFlags)flags);
       
  1038     
       
  1039     // Set Image on visuals
       
  1040     mData->mTrackTopImage->SetImage(trackTopImage);
       
  1041     mData->mTrackMiddleImage->SetImage(trackMiddleImage);                        
       
  1042     mData->mTrackEndImage->SetImage(trackEndImage);
       
  1043     mData->mTrackTopImage->SetSecondaryImage(trackTopPressedImage);
       
  1044     mData->mTrackMiddleImage->SetSecondaryImage(trackMiddlePressedImage);                        
       
  1045     mData->mTrackEndImage->SetSecondaryImage(trackEndPressedImage);
       
  1046     }//End of setImage
       
  1047 
       
  1048 // ---------------------------------------------------------------------------
       
  1049 // Set images for the thumb 
       
  1050 // ---------------------------------------------------------------------------
       
  1051 //
       
  1052 void AlfScrollBarDefaultBaseElement::setThumbImage()
       
  1053     {
       
  1054     TInt flags = EAlfTextureFlagSkinContent;
       
  1055        flags |= EAlfTextureFlagAutoSize;
       
  1056    
       
  1057 	  TAlfImage thumbTopImage(KAknsIIDQsnCpScrollHandleTop,TSize(0,0), 
       
  1058 							   EAspectRatioNotPreserved,NULL, 
       
  1059 							   -1,-1,0.f,0.f,1.f,1.f,
       
  1060 							   (TAlfTextureFlags)flags);
       
  1061 	  TAlfImage thumbMiddleImage(KAknsIIDQsnCpScrollHandleMiddle, TSize(0,0), 
       
  1062                               EAspectRatioNotPreserved, NULL, 
       
  1063                               -1, -1, 0.f, 0.f, 1.f, 1.f, 
       
  1064                               (TAlfTextureFlags)flags);
       
  1065 	  TAlfImage thumbEndImage(KAknsIIDQsnCpScrollHandleBottom, TSize(0,0), 
       
  1066 	                           EAspectRatioNotPreserved, NULL, 
       
  1067 	                           -1, -1, 0.f, 0.f, 1.f, 1.f, 
       
  1068 	                           (TAlfTextureFlags)flags);
       
  1069 	  TAlfImage thumbTopPressedImage(KAknsIIDQsnCpScrollHandleTopPressed,TSize(0,0), 
       
  1070 	                           EAspectRatioNotPreserved,NULL, 
       
  1071 	                           -1,-1,0.f,0.f,1.f,1.f,
       
  1072 	                           (TAlfTextureFlags)flags);
       
  1073       TAlfImage thumbMiddlePressedImage(KAknsIIDQsnCpScrollHandleMiddlePressed, TSize(0,0), 
       
  1074                               EAspectRatioNotPreserved, NULL, 
       
  1075                               -1, -1, 0.f, 0.f, 1.f, 1.f, 
       
  1076                               (TAlfTextureFlags)flags);
       
  1077       TAlfImage thumbEndPressedImage(KAknsIIDQsnCpScrollHandleBottomPressed, TSize(0,0), 
       
  1078                               EAspectRatioNotPreserved, NULL, 
       
  1079                               -1, -1, 0.f, 0.f, 1.f, 1.f, 
       
  1080                               (TAlfTextureFlags)flags);
       
  1081 
       
  1082        mData->mThumbTopImage->SetImage(thumbTopImage);
       
  1083        mData->mThumbMiddleImage->SetImage(thumbMiddleImage);                        
       
  1084        mData->mThumbEndImage->SetImage(thumbEndImage);
       
  1085        mData->mThumbTopImage->SetSecondaryImage(thumbTopPressedImage);
       
  1086        mData->mThumbMiddleImage->SetSecondaryImage(thumbMiddlePressedImage);                        
       
  1087        mData->mThumbEndImage->SetSecondaryImage(thumbEndPressedImage);
       
  1088  
       
  1089     }//End of setImage
       
  1090 // ---------------------------------------------------------------------------
       
  1091 // change images for the track 
       
  1092 // ---------------------------------------------------------------------------
       
  1093 //
       
  1094 void AlfScrollBarDefaultBaseElement::changeTrackImage(bool aPressed)
       
  1095     {
       
  1096     if(aPressed)
       
  1097     	{
       
  1098     	TAlfTimedValue alpha(1.0, 0.0);
       
  1099     	mData->mTrackTopImage->SetSecondaryAlpha(alpha);
       
  1100 	    mData->mTrackMiddleImage->SetSecondaryAlpha(alpha);                        
       
  1101 	    mData->mTrackEndImage->SetSecondaryAlpha(alpha);
       
  1102 	    }
       
  1103     else
       
  1104     	{
       
  1105     	TAlfTimedValue alpha(0.0, 0.0);
       
  1106     	mData->mTrackTopImage->SetSecondaryAlpha(alpha);
       
  1107 	    mData->mTrackMiddleImage->SetSecondaryAlpha(alpha);                        
       
  1108 	    mData->mTrackEndImage->SetSecondaryAlpha(alpha);
       
  1109     	
       
  1110     	}
       
  1111     }
       
  1112 // ---------------------------------------------------------------------------
       
  1113 // change images for the thumb 
       
  1114 // ---------------------------------------------------------------------------
       
  1115 //
       
  1116 void AlfScrollBarDefaultBaseElement::changeThumbImage(bool aPressed)
       
  1117     {
       
  1118     if(aPressed)
       
  1119     	{
       
  1120     	TAlfTimedValue alpha(1.0,0.0);
       
  1121     	mData->mThumbTopImage->SetSecondaryAlpha(alpha);
       
  1122 	    mData->mThumbMiddleImage->SetSecondaryAlpha(alpha);                        
       
  1123 	    mData->mThumbEndImage->SetSecondaryAlpha(alpha);
       
  1124 	    }
       
  1125     else
       
  1126     	{
       
  1127     	TAlfTimedValue alpha(0.0,0.0);
       
  1128     	mData->mThumbTopImage->SetSecondaryAlpha(alpha);
       
  1129 	    mData->mThumbMiddleImage->SetSecondaryAlpha(alpha);                        
       
  1130 	    mData->mThumbEndImage->SetSecondaryAlpha(alpha);
       
  1131     	}
       
  1132     }
       
  1133 // ---------------------------------------------------------------------------
       
  1134 // calculates Step size and Thumb length 
       
  1135 // ---------------------------------------------------------------------------
       
  1136 //
       
  1137 void  AlfScrollBarDefaultBaseElement::calculateStepSizeAndThumbLength()
       
  1138     {
       
  1139     int totalLength =  mData->mScrollbarModel->getTotalLength();
       
  1140     int viewLength =  mData->mScrollbarModel->getViewLength();
       
  1141     int viewStartPos =  mData->mScrollbarModel->getViewStartPosition();
       
  1142     
       
  1143     TAlfTimedPoint size = mData->mRootLayout->Size();
       
  1144     mData->mThumbLength = ((float)viewLength / 
       
  1145                                 (float)totalLength) * size.iY.ValueNow();
       
  1146     
       
  1147     if(mData->mThumbMinLength != 0)
       
  1148         {
       
  1149         if(mData->mThumbLength<mData->mThumbMinLength)
       
  1150             {
       
  1151             mData->mThumbLength = mData->mThumbMinLength;
       
  1152             }
       
  1153         else if(mData->mThumbLength>mData->mThumbMaxLength)
       
  1154             {
       
  1155             mData->mThumbLength = mData->mThumbMaxLength;
       
  1156             }
       
  1157         else
       
  1158             {
       
  1159             
       
  1160             }
       
  1161         }
       
  1162     else
       
  1163         {
       
  1164         
       
  1165         }
       
  1166         
       
  1167     if(totalLength != viewLength)
       
  1168 	    {    
       
  1169 	    mData->mStepSize = (size.iY.ValueNow() - mData->mThumbLength) / 
       
  1170 	                        (totalLength - viewLength);                       
       
  1171 	    }
       
  1172     else
       
  1173 	    {
       
  1174 	    mData->mStepSize = 0.0;	
       
  1175 	    }
       
  1176     }
       
  1177 // ---------------------------------------------------------------------------
       
  1178 // set maximum and minimum thumblength value from LCT data 
       
  1179 // ---------------------------------------------------------------------------
       
  1180 //
       
  1181 void AlfScrollBarDefaultBaseElement::setThumbMinMaxLength()
       
  1182     {
       
  1183     TAknWindowLineLayout ThumbMinLengthHandle = 
       
  1184                 AknLayoutScalable_UiAccel::
       
  1185                 aid_size_min_handle_cp002(0).LayoutLine();
       
  1186 
       
  1187     TAknWindowLineLayout ThumbMaxLengthHandle = 
       
  1188                 AknLayoutScalable_UiAccel::
       
  1189                     aid_hc_size_max_handle(0).LayoutLine();
       
  1190     
       
  1191     // Since LCT data corresponding to this is very small (20), 
       
  1192     // we are hardcoding the value as 30,this has to be removed 
       
  1193     // once if we get the correct LCT data
       
  1194     // mData->mThumbMinLength = 30;
       
  1195     mData->mThumbMinLength = ThumbMinLengthHandle.iH;
       
  1196     mData->mThumbMaxLength = mData->mRootLayout->Size().iY.ValueNow() -
       
  1197                              ThumbMaxLengthHandle.ib;
       
  1198     }
       
  1199 
       
  1200 // ---------------------------------------------------------------------------
       
  1201 // createDefaultBaseElement, initializes class member variables 
       
  1202 // ---------------------------------------------------------------------------
       
  1203 //
       
  1204 void AlfScrollBarDefaultBaseElement::createDefaultBaseElement()
       
  1205     {
       
  1206     
       
  1207     mData = new (EMM) ScrollBarBaseElementData();
       
  1208     mData->mOperation = ENop;
       
  1209     mData->mVisual = NULL;
       
  1210     mData->mDragPoint = TPoint(0,0);
       
  1211     mData->mLongTapPos = TPoint(0,0);
       
  1212     mData->mDragStartStep = 0;
       
  1213     mData->mViewLength = 0;
       
  1214     mData->mThumbLength = 0;
       
  1215     mData->mThumbMinLength = 0;
       
  1216     mData->mThumbMaxLength = 0;
       
  1217     mData->mStepSize = 0;
       
  1218     mData->mThumbSizeChanged = false;
       
  1219     mData->mWidgetOpacity = 1.0;
       
  1220     mData->mThumbOpacity = 1.0;
       
  1221     mData->mLongTapStarted = false;
       
  1222     mData->mCurrentState = EReleased;
       
  1223     mData->mTrackLayout = NULL;
       
  1224     mData->mTrackTopImage = NULL ;
       
  1225     mData->mTrackMiddleImage = NULL ;
       
  1226     mData->mTrackEndImage = NULL ;
       
  1227     mData->mThumbLayout = NULL ;
       
  1228     mData->mThumbTopImage = NULL ;
       
  1229     mData->mThumbMiddleImage = NULL ;
       
  1230     mData->mThumbEndImage = NULL ;
       
  1231     mData->mExtendedTouch = 0;
       
  1232     mData->mScrollbarModel = NULL;
       
  1233     mData->mThumbAnimationTime = 0;
       
  1234     
       
  1235     mLCTData = new ( EMM ) ScrollbarThumbLCTData();
       
  1236     mLCTData->left=0;
       
  1237     mLCTData->top=0;
       
  1238     mLCTData->right=0;
       
  1239     mLCTData->bottom=0;
       
  1240     mLCTData->height=0;
       
  1241     mLCTData->width=0;
       
  1242     
       
  1243     }//End of createDefaultBaseElement
       
  1244 
       
  1245 // ---------------------------------------------------------------------------
       
  1246 // initializeThumbDragData
       
  1247 //  
       
  1248 // ---------------------------------------------------------------------------
       
  1249 //    
       
  1250 bool AlfScrollBarDefaultBaseElement::initializeThumbDragData( const TPoint& aPointerPos )
       
  1251     {
       
  1252     if(mData->mVisual )
       
  1253         {
       
  1254         mData->mOperation = EMoveItem;
       
  1255         mData->mDragPoint = aPointerPos;
       
  1256         mData->mDragStartStep = mData->mScrollbarModel->getViewStartPosition();
       
  1257         }
       
  1258     else
       
  1259         {
       
  1260         // Do Nothing
       
  1261         }   
       
  1262     return ETrue;  
       
  1263     }
       
  1264 
       
  1265 
       
  1266 // ---------------------------------------------------------------------------
       
  1267 // stopDrag
       
  1268 // Stop Dragging 
       
  1269 // ---------------------------------------------------------------------------
       
  1270 //
       
  1271 bool AlfScrollBarDefaultBaseElement::stopDrag( CAlfVisual* /*aHitVisual*/, 
       
  1272                                                TInt /*aAnimTime*/)
       
  1273     {
       
  1274     TRAPD(err,
       
  1275           control().Display()->Roster().SetPointerEventObservers(
       
  1276           0, 
       
  1277           control()));
       
  1278     
       
  1279     if(err == KErrNone)
       
  1280         {
       
  1281         if(mData->mVisual)
       
  1282             {
       
  1283             mData->mVisual = NULL;
       
  1284             }
       
  1285         mData->mOperation = ENop;
       
  1286         return true;
       
  1287         }
       
  1288     return false;
       
  1289     }
       
  1290 
       
  1291 // ---------------------------------------------------------------------------
       
  1292 // changeGraphics
       
  1293 // change the skin image graphics based on the pressedState
       
  1294 // ---------------------------------------------------------------------------
       
  1295 //
       
  1296 void AlfScrollBarDefaultBaseElement::changeGraphics()
       
  1297     {
       
  1298     if(mData->mCurrentState == EReleased)    // Normal graphics
       
  1299         {
       
  1300         changeTrackImage(false);
       
  1301         changeThumbImage(false);
       
  1302         }
       
  1303     else if(mData->mCurrentState == EThumbPressed || mData->mCurrentState == ETrackPressed)  // Pressed graphics
       
  1304         {
       
  1305         if(mData->mCurrentState == EThumbPressed)
       
  1306             {
       
  1307             // set the index for pressed graphics (thumb and track)
       
  1308             changeTrackImage(true);
       
  1309             changeThumbImage(true);
       
  1310             }
       
  1311         else if (mData->mCurrentState == ETrackPressed)
       
  1312             {
       
  1313             // set the index for pressed graphics (track)
       
  1314             changeTrackImage(true);
       
  1315             }
       
  1316         }
       
  1317     }
       
  1318 
       
  1319 // ---------------------------------------------------------------------------
       
  1320 // isScrollbarTrackVisual
       
  1321 // checks whether the visual is scrollbar track visual or not
       
  1322 // ---------------------------------------------------------------------------
       
  1323 // 
       
  1324 bool AlfScrollBarDefaultBaseElement::isScrollbarTrackVisual(CAlfVisual *aVisual)
       
  1325     {
       
  1326     if(aVisual == mData->mExtendedTrackLayout ||
       
  1327        aVisual == mData->mTrackTopImage ||
       
  1328        aVisual == mData->mTrackMiddleImage ||
       
  1329        aVisual == mData->mTrackEndImage)
       
  1330         {
       
  1331         return true;
       
  1332         }
       
  1333      return false;   
       
  1334     }  
       
  1335 
       
  1336 // ---------------------------------------------------------------------------
       
  1337 // isScrollbarThumbVisual
       
  1338 // checks whether the visual is scrollbar thumb visual or not
       
  1339 // ---------------------------------------------------------------------------
       
  1340 // 
       
  1341 bool AlfScrollBarDefaultBaseElement::isScrollbarThumbVisual(CAlfVisual *aVisual)
       
  1342     {
       
  1343     if(aVisual == mData->mExtendedThumbLayout ||
       
  1344        aVisual == mData->mThumbTopImage ||
       
  1345        aVisual == mData->mThumbMiddleImage ||
       
  1346        aVisual == mData->mThumbEndImage)
       
  1347         {
       
  1348         return true;
       
  1349         }
       
  1350      return false;   
       
  1351     }  
       
  1352 
       
  1353     }//namespace Alf
       
  1354     
       
  1355 //End Of File