mulwidgets/mulcoverflowwidget/inc/mulcoverflowcontrol.h
branchRCL_3
changeset 26 0e9bb658ef58
parent 0 e83bab7cf002
equal deleted inserted replaced
25:4ea6f81c838a 26:0e9bb658ef58
       
     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 Control header for CoverFlow Widgets.
       
    15  *
       
    16 */
       
    17 
       
    18 #ifndef MULCOVERFLOWCONTROL_H
       
    19 #define MULCOVERFLOWCONTROL_H
       
    20 
       
    21 // Alf Headers
       
    22 #include <alf/alfwidgetcontrol.h>
       
    23 
       
    24 // Osn Headers
       
    25 #include <touchfeedback.h>
       
    26 
       
    27 // Gesture Helper
       
    28 #include <gestureobserver.h>
       
    29 
       
    30 // Mul Headers
       
    31 #include <mul/imulvarianttype.h>
       
    32 #include <mul/imulwidget.h>
       
    33 #include "imulmodelobserver.h"
       
    34 
       
    35 //Gesture Helper namespace 
       
    36 namespace GestureHelper
       
    37     {
       
    38     class CGestureHelper;
       
    39     struct TRealPoint;
       
    40     }
       
    41 
       
    42 //Forward declarations
       
    43 class CAlfFlowLayout ;
       
    44 class CAlfImageVisual;
       
    45 
       
    46 namespace Alf
       
    47     {
       
    48 //Forward declarations
       
    49 class IAlfWidget;
       
    50 class IMulModelAccessor;
       
    51 class IMulSliderModel;
       
    52 class IMulSliderWidget;
       
    53 class MulBaseElement;
       
    54 class MulCoverFlowAo;
       
    55 class MulCoverFlowTemplate;
       
    56 
       
    57 struct TMulCoverFlowControlImpl;
       
    58 
       
    59 namespace mulcoverflowcontrol
       
    60     {
       
    61      static const IfId Ident=
       
    62         {
       
    63         0,"MulCoverFlowControl"
       
    64         };
       
    65     }
       
    66     
       
    67 class MulCoverFlowControl : public CAlfWidgetControl,
       
    68 							public IMulModelObserver,
       
    69 							public GestureHelper::MGestureObserver
       
    70     {
       
    71 
       
    72 public: //Constructor and destructor
       
    73 
       
    74     /**
       
    75      * C++ constructor.
       
    76      */
       
    77     MulCoverFlowControl( CAlfEnv& aEnv );
       
    78 
       
    79     /**
       
    80      * Destructor.
       
    81      */
       
    82     virtual ~MulCoverFlowControl();
       
    83     
       
    84 public: //From CAlfWidgetControl
       
    85 
       
    86     AlfEventStatus handleEvent( const TAlfEvent& aEvent );
       
    87         
       
    88     static inline const IfId& Type()
       
    89         {
       
    90         return mulcoverflowcontrol::Ident;    
       
    91         }
       
    92     
       
    93     IAlfInterfaceBase* makeInterface( const IfId& aType );
       
    94                 
       
    95     void VisualLayoutUpdated (CAlfVisual& aVisual);
       
    96         
       
    97 public:// From IMulModelObserver
       
    98     
       
    99 	void ModelStateChanged( TMulChangedState aState, IMulVariantType& aData );
       
   100     
       
   101 public:// From MGestureObserver
       
   102 
       
   103     /**
       
   104      * Handles gesture events and delegates the processing to the base element
       
   105      * 
       
   106      * @param aEvent Gesture event e.g . EGestureSwipeLeft/Right
       
   107      */
       
   108     void HandleGestureL( const GestureHelper::MGestureEvent& aEvent );
       
   109     
       
   110 
       
   111 public: //New Methods
       
   112 	
       
   113 	/**
       
   114 	 * Returns the total count that application has set to the model . 
       
   115 	 * The number of items that application has set to the model i,e the total 
       
   116 	 * number of items that the application may insert into the model may not
       
   117 	 * be equal to the total number of items given to the widget for presentation 
       
   118 	 * by the model . 
       
   119 	 * 
       
   120 	 * @returns The number of items that the application has set to the model .
       
   121 	 */
       
   122 	int TotalModelCount();
       
   123 	
       
   124     /**
       
   125      * Sets the highlight index to the given aIndex
       
   126      *
       
   127      * @param aIndex, Index to which the current focus visulisation to be moved.
       
   128      */		
       
   129 	void SetHighlightIndex( int aIndex ,bool aUpdateSlider = true);
       
   130 	
       
   131     /**
       
   132      * Return the Highlight Item Index maintained in control when update highlight to model is blocked
       
   133      *
       
   134      * @return, Current Highlight
       
   135      */
       
   136     int HighlightIndex();
       
   137     
       
   138     /**
       
   139      * Returns the current 2D coverflow template.
       
   140      *
       
   141      * @return, CoverflowTemplate
       
   142      */	
       
   143     MulCoverFlowTemplate*  Template2D();
       
   144         
       
   145     /**
       
   146      * Returns whether the coverflow is currently in fast scroll mode or not .
       
   147      *
       
   148      * @returns true if fast scroll mode is launched, else returns false
       
   149      */
       
   150     bool IsFastScrollMode();
       
   151     
       
   152     /**
       
   153      * Resets the show widget flag depending on the parameter passed. 
       
   154      * 
       
   155      * @param aNewResetValue The new value with which the flag needs to be reset.
       
   156      */
       
   157     void ResetShowWidgetFlag( bool aNewResetValue );
       
   158     
       
   159     
       
   160     /**
       
   161      * Returns the accessor to the current model of the widget.
       
   162      */
       
   163     IMulModelAccessor* ModelAccessor();
       
   164      
       
   165 	
       
   166 	/**
       
   167      * Recycles all the visuals added to the Icon Layout.
       
   168      * The function is called whenever there is an model change
       
   169      */
       
   170     void RecycleVisuals(); 
       
   171     
       
   172     /**
       
   173      * Creates the slider widget . The creation of slider widget depends on the xml . 
       
   174      * That is if the xml has a slider tag then only slider widget is created . 
       
   175      */
       
   176     IAlfWidget* CreateSliderWidget();
       
   177     
       
   178     /**
       
   179      * Returns the created slider widget . If the widget is  not created , then returns NULL.
       
   180      */
       
   181     IAlfWidget* GetSliderWidget();
       
   182 	
       
   183 	/**
       
   184 	 * Returns the slider model pointer . 
       
   185 	 *
       
   186 	 * @returns The slider model pointer if slider widget is created and exists, else returns NULL.
       
   187 	 */	
       
   188 	IMulSliderModel* GetSliderModel(); 
       
   189 	
       
   190     /**
       
   191      * Check whether we need hold events (Enhanced coverflow can be launched) and
       
   192      * set the state to gesture helper accordingly
       
   193      */	    
       
   194     void SetHoldingEnabled();
       
   195     
       
   196     /**
       
   197      * Enable/Disable double tap on Gesture helper based on the aValue specified.
       
   198      * 
       
   199      * @param aValue The value whether double tap should be enabled or not.
       
   200      */	
       
   201     void SetDoubleTapEnabled( bool aValue);
       
   202         
       
   203     /**
       
   204      * Handles the scrolling event and changes the focus accordingly.
       
   205      * 
       
   206      * @param aEvent the scrolling event to be handled
       
   207      */
       
   208     void HandleNavigationEvent( int aEvent );
       
   209     
       
   210 	/**
       
   211 	 * Transition time for highlight change in fast scroll
       
   212 	 *
       
   213 	 * @return, transition time to be used
       
   214 	 */	
       
   215 	int FastScrollTransitionTime();	 
       
   216 
       
   217 	/**
       
   218 	 * Update the item at relative index Of aVisualIndex with the data at aItemIndex
       
   219 	 *
       
   220 	 * @param aItemIndex, Absolute index
       
   221 	 * @param aVisualIndex, Relative index
       
   222 	 * @param aAnimationTime, text will be updated after the aAnimationTime.
       
   223 	 */
       
   224 	void UpdateCoverflowItem( int aItemIndex, int aVisualIndex, int aAnimationTime = 0);
       
   225 	
       
   226 	/**
       
   227 	 * Checks the current index is in visible window and returns its relative index in aRelativeIndex
       
   228 	 *
       
   229 	 * @param aIndex, 
       
   230 	 * @param aRelativeIndex,
       
   231 	 */	
       
   232 	bool IsIndexInVisibleWindow(const int aIndex,int& aRelativeIndex);
       
   233 	
       
   234 	/**
       
   235 	 *  
       
   236 	 *
       
   237 	 */	
       
   238 	int RelativeToAbsolute(const int aRelativeIndex);
       
   239 	
       
   240 	/**
       
   241 	 * update the item at the relative index. 
       
   242 	 * 
       
   243 	 * @param aVisualIndex, Relative index
       
   244 	 * @param aAnimationTime, text will be updated after the aAnimationTime.
       
   245 	 *
       
   246 	 */	
       
   247 	void UpdateItemAtIndex(const int aRelativeIndex, int aAnimationTime = 0);
       
   248 
       
   249 	/**
       
   250 	 *  
       
   251 	 *
       
   252 	 */
       
   253     void DoSetImage(IMulVariantType* aImageData,CAlfImageVisual* aImgVisual);
       
   254     
       
   255    /**
       
   256     * Checks the given file path is of SVG image or not
       
   257     *
       
   258     * @param aImagePath Path of the image file,which need to be checked for SVG file format. 
       
   259     */
       
   260     bool IsSVGImage(const TDesC& aImagePath);
       
   261     
       
   262     /**
       
   263      * Load Image visual with image provided from file path
       
   264      * 
       
   265      * @param aSvgFilePath path of Image
       
   266      * @param aImageVisual visual on with image to be loaded
       
   267      */
       
   268     void LoadImageFromSvg(const TDesC& aImagePath,CAlfImageVisual& aImageVisual );
       
   269     
       
   270 	/**
       
   271 	 *  
       
   272 	 *
       
   273 	 */    
       
   274     void StoreVisibleItemCount(int aVisibleItemCount);
       
   275     
       
   276 	/**
       
   277 	 *  
       
   278 	 *
       
   279 	 */
       
   280 	void SetDefaultImage(int aTextureId);
       
   281 	
       
   282 	/**
       
   283 	 *  
       
   284 	 *
       
   285 	 */
       
   286 	int WindowTop(int aHighlightIndex);
       
   287 
       
   288 	/**
       
   289 	 *  
       
   290 	 *
       
   291 	 */	
       
   292 	void UpdateBaseElement(MulBaseElement* aBaseElement);
       
   293 	
       
   294     /**
       
   295      * Slider handles the key events  .
       
   296      * Slider thumb positions itself to the gesture and key events of coverflow widget 
       
   297      *
       
   298      */
       
   299     void SetSliderTickPosition();
       
   300 	
       
   301 	/**
       
   302 	 *  
       
   303 	 *
       
   304 	 */	
       
   305     void ModelChanged( IMulModelAccessor* aAccessor);
       
   306 
       
   307 	/**
       
   308 	 * Determins the current resolution
       
   309 	 * 
       
   310 	 *
       
   311 	 */	
       
   312 	bool IsLandscape();
       
   313     
       
   314     /**
       
   315      * Destroys slider widget.
       
   316      */	
       
   317     void DestroySlider(); 
       
   318  
       
   319     /**
       
   320      * Return gesture helper.
       
   321      */ 
       
   322     GestureHelper::CGestureHelper* Gesturehelper();
       
   323     
       
   324 private:
       
   325     
       
   326     // Event handling related api.
       
   327     /**
       
   328      * Handles key event related manipulation. 
       
   329      * 
       
   330      * @param TAlfEvent
       
   331      * @returns The status of the handled event.
       
   332      */
       
   333     AlfEventStatus HandleKeyEvent( const TAlfEvent& aEvent );
       
   334     
       
   335     /**
       
   336      * Handles repeated key event. 
       
   337      * 
       
   338      * @param TAlfEvent 
       
   339      * @returns The status of the handled event.
       
   340      */
       
   341     AlfEventStatus HandleRepeatKeyEvent( const TAlfEvent& aEvent );  
       
   342 
       
   343     /**
       
   344      * Handle fast scrolling and speed variations with repeated key events. 
       
   345      * 
       
   346      * @param aDirection, Direction in which to change the highlight
       
   347      */    
       
   348     void HandleFastScrollWithKeyEvents(int aDirection);  
       
   349     
       
   350     /**
       
   351      * Handles custom event that control has raised to itself like bounce,bounce over etc. 
       
   352      * 
       
   353      * @returns The status of the handled event.
       
   354      */
       
   355     AlfEventStatus HandleCustomEvent( const TAlfEvent& aEvent );
       
   356     
       
   357     /**
       
   358      * Handles swipe events(only on pointer events from gesture helper)
       
   359      * 
       
   360      * @param aEvent - SwipeRight/SwipeLeft.
       
   361      */
       
   362     void HandleSwipe(int aEvent);
       
   363     
       
   364     /**
       
   365      * Performs the focus visualisation for the new focusedindex, and clears the old
       
   366      * index visulisation. Called for every navigation events and sethighlight api call.
       
   367      *
       
   368      * @param aIndex new Index to which the focus visualisation is to be set.    
       
   369      */        
       
   370     void DoSetFocusIndex( int aIndex, int aAnimationTime =0);
       
   371     
       
   372     /**
       
   373      * Sets the current highlighted item as the selected item . 
       
   374      * Sends the selection event to the application . 
       
   375      */
       
   376     void SetSelection(int aHighlight);
       
   377         
       
   378     /**
       
   379      * Creates a new template element with aTemplateName .
       
   380      * 
       
   381      * @param aTemplateName The name of thew new template element.
       
   382      */
       
   383     void CreateTemplateElement( mulwidget::TLogicalTemplate aTemplateName);
       
   384         
       
   385        
       
   386     /**
       
   387      * Sends the specified event to the base element .
       
   388      * 
       
   389      * @param aEvent Event to be sent to the base element.
       
   390      */
       
   391     void SendEventToBaseElement( const TAlfEvent& aEvent );
       
   392     
       
   393     /**
       
   394      * Handles if there is any change in the total count of model .
       
   395      * Updates the slider tick if the total count of model increases/decreases.
       
   396      *
       
   397      */
       
   398      
       
   399     void HandleModelCountChange();
       
   400             
       
   401     /**
       
   402      * Gets the absolute index of the specified visual, which has been tapped.
       
   403      * 
       
   404      * @param aHitVisual The visual which has been tapped or hit.
       
   405      */
       
   406     int GetHitVisualIndex( CAlfVisual* aHitVisual );
       
   407     
       
   408     /**
       
   409      * Handle enhanced stop.
       
   410      */ 
       
   411 	void HandleEnhancedStop();
       
   412    
       
   413     /**
       
   414      * Performs all the enhanced mode related checkings ..e.g whether the fast scroll flag
       
   415      * is set or not / whether the application is in landscape mode or not .
       
   416      *
       
   417      * @return Boolean value informing whether enhanced mode should be started or not .
       
   418      */
       
   419     bool EnhancedModeCondition();
       
   420     
       
   421     /**
       
   422      * Performs animations when enhanced mode is started .
       
   423      * The coverflow transits to enhanced mode from 2D normal mode .
       
   424      *
       
   425      * @param aEvent , gesture event
       
   426      */
       
   427     void EnhancedStarted( const GestureHelper::MGestureEvent& aEvent );
       
   428     
       
   429     /**
       
   430      * Returns the current Gesture Speed. 
       
   431      * 
       
   432      * @param aEvent Event from the gesture helper.
       
   433      * @returns The current gesture speed.
       
   434      */
       
   435     GestureHelper::TRealPoint GestureSpeed( const GestureHelper::MGestureEvent& aEvent );
       
   436     
       
   437     /**
       
   438      * Performs animations in enhanced mode.
       
   439      * Moves the layout along with the pointer event . The function calls the active object class
       
   440      * to move the layout with smooth animation .
       
   441      *
       
   442      * @param aEvent Gesture event .
       
   443      */
       
   444     void StartMoving( const GestureHelper::MGestureEvent& aEvent );
       
   445 
       
   446     /**
       
   447      * Handles all normal gesture events other than hold events
       
   448      * 
       
   449      * @param aEvent Gesture event e.g . EGestureSwipeLeft/Right
       
   450      */    
       
   451 	void HandleNormalGestureEvents(const GestureHelper::MGestureEvent& aEvent);
       
   452 
       
   453     /**
       
   454      * Handles hold gesture events.
       
   455      * 
       
   456      * @param aEvent Gesture event e.g . EGestureSwipeHoldLeft/Right
       
   457      */
       
   458 	void HandleHoldGestureEvents(const GestureHelper::MGestureEvent& aEvent);
       
   459 
       
   460     /**
       
   461      * Handles updating utems when the number of items in model are less than total visible items
       
   462      * 
       
   463      * @param aIndex, Index to update.
       
   464      */	
       
   465 	void HandleLessItemsUpdate(int aIndex);  
       
   466 
       
   467     /**
       
   468      * Sets a blank texture the visual at relative index.
       
   469      * 
       
   470      * @param aRelativeIndex, Index for which the blank texture should be set
       
   471      */	
       
   472 	void SetBlankTexture(int aRelativeIndex);	  
       
   473 
       
   474 
       
   475     /**
       
   476      * Converts the gesture distance into the form of direction (For right
       
   477      * its plus and left its minus)
       
   478      * 
       
   479      * @param aDistance, Gesture distance
       
   480      */
       
   481 	int ConvertDistanceToDirection( int aDistance );    	 
       
   482     /**
       
   483      * Sends Tactile feedback in case of touch down event.
       
   484      *
       
   485      * @param aEvent Gesture event.
       
   486      */	
       
   487 	void SendFeedbackOnTouchDown(const GestureHelper::MGestureEvent& aEvent); 
       
   488 	
       
   489     /**
       
   490      * Decides in which direction the strip should move during fast scroll and also decides the position of 
       
   491      * reference point for some special cases .
       
   492      *
       
   493      * @param aEvent Gesture event.
       
   494      */
       
   495 	void ReverseDirectionInFastScroll(const GestureHelper::MGestureEvent& aEvent); 
       
   496 	
       
   497 	/**
       
   498 	 * Change the reference point of reversing the direction until the reference point becomes the 
       
   499 	 * middle of the screen .
       
   500 	 *
       
   501 	 * @param aCurrPosition The current pointer position .
       
   502 	 * @param aDistanceTravelled The distance travelled by the gesture till now.
       
   503 	 */
       
   504 	void ChangeDirReferencePoint(int aCurrPosition, int aDistanceTravelled );
       
   505 	
       
   506 	/**
       
   507      * Handles the operations on the Single tap.
       
   508      *
       
   509      * @param aEvent Gesture event.
       
   510      */
       
   511 	void HandleSingleTap(const GestureHelper::MGestureEvent& aEvent); 
       
   512 
       
   513 	/**
       
   514      * 
       
   515      *
       
   516      * 
       
   517      */	
       
   518 	int TotalSwipeDistance( const GestureHelper::MGestureEvent& aEvent );	 
       
   519 
       
   520     	 
       
   521 private:
       
   522     
       
   523      auto_ptr<GestureHelper::CGestureHelper> mHelper; //owns it
       
   524     
       
   525      auto_ptr<TMulCoverFlowControlImpl> mData; // Owned
       
   526      
       
   527      auto_ptr<MulCoverFlowAo> mCoverFlowAo;   // owned
       
   528      
       
   529      MTouchFeedback* mFeedback; // tactile feedback, doesnt own it.
       
   530      
       
   531     IMulSliderWidget* mSliderWidget;  //    
       
   532     
       
   533     };
       
   534     
       
   535     } // namespace Alf
       
   536     
       
   537 #endif // MULCOVERFLOWCONTROL_H
       
   538 
       
   539 //End of file