taskswitcher/taskswitcherui/taskswitcherapp/inc/tsfastswapgrid.h
changeset 4 4d54b72983ae
child 5 c743ef5928ba
equal deleted inserted replaced
3:fb3763350a08 4:4d54b72983ae
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Taskswitcher Fast Swap area UI
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef TSFASTSWAPGRID_H_
       
    20 #define TSFASTSWAPGRID_H_
       
    21 
       
    22 #include <AknGrid.h>
       
    23 #include <aknconsts.h>
       
    24 #include "tsdevicestate.h"
       
    25 
       
    26 class CAknsFrameBackgroundControlContext;
       
    27 class CTsFastSwapTimer;
       
    28 
       
    29 /**
       
    30  * Observer for handling fast swap grid events
       
    31  */
       
    32 class MTsFastSwapGridObserver
       
    33     {
       
    34 public:
       
    35     /**
       
    36      * Called when close icon is tapped on the grid item.
       
    37      * 
       
    38      * @param  aItemIdx  index of the the item for which close icon
       
    39      *                   has been tapped
       
    40      */
       
    41     virtual void HandleCloseEventL( TInt aItemIdx ) = 0;
       
    42     };
       
    43 
       
    44 
       
    45 class MTsFastSwapTimerObserver
       
    46     {
       
    47 public:
       
    48     /**
       
    49      * Called when timer is completed
       
    50      */
       
    51     virtual void TimerCompletedL( CTsFastSwapTimer* aSource ) = 0;
       
    52     };
       
    53 
       
    54 
       
    55 /**
       
    56  * Avkon grid implementing custom item drawer
       
    57  */
       
    58 class CTsFastSwapGrid: 
       
    59     public CAknGrid,
       
    60     public MTsDeviceStateObserver
       
    61     {
       
    62 public: // enums
       
    63     enum TFastSwapGridBehaviour
       
    64         {
       
    65         // Highlight always visible
       
    66         EHybrid,
       
    67         
       
    68         // Touch only highlight handling
       
    69         ETouchOnly
       
    70         };
       
    71     
       
    72 public: // Constructor and destructor
       
    73     CTsFastSwapGrid();
       
    74     ~CTsFastSwapGrid();
       
    75     void ConstructL( const CCoeControl* aParent );
       
    76     
       
    77 public: // From CCoeControl
       
    78     void HandlePointerEventL( const TPointerEvent &aPointerEvent );
       
    79     TTypeUid::Ptr MopSupplyObject( TTypeUid aId );
       
    80     void HandleResourceChange( TInt aType );
       
    81     void SizeChanged();
       
    82     
       
    83 public: //From MTsDeviceStateObserver
       
    84     /**
       
    85      * Called when a change, to which the observer is registered,
       
    86      * has happened.
       
    87      */
       
    88     virtual void HandleDeviceStateChanged( TChangeType aChangeType );
       
    89     
       
    90 public: // New functions
       
    91 
       
    92     /**
       
    93      * Sets fast swap grid observer
       
    94      */
       
    95     void SetFastSwapGridObserver( MTsFastSwapGridObserver* aObserver  );
       
    96 
       
    97     /**
       
    98      * Set indexes of items which can be closed.
       
    99      * Copies item index array.
       
   100      */
       
   101     void SetCloseItemsL( RArray<TInt>& aItemIndex );
       
   102 
       
   103     /**
       
   104      * Checks if the item of given index is closable
       
   105      */
       
   106     TBool CanCloseItem( TInt aItemIndex );
       
   107 
       
   108     /**
       
   109      * Checks if the given item's close icon has been tapped.
       
   110      */
       
   111     TBool IsItemCloseHit( TInt aItemIndex );
       
   112 
       
   113     /**
       
   114      * Resets index of the item that has been close icon hit
       
   115      */
       
   116     void ResetCloseHit();
       
   117     
       
   118     /**
       
   119      * Sets grid behaviour
       
   120      * 
       
   121      * @param  aBehaviour  behaviour to be set
       
   122      */
       
   123     void SetGridBehaviour( TFastSwapGridBehaviour aBehaviour );
       
   124     
       
   125     /**
       
   126      * Getter for grid behaviour
       
   127      * 
       
   128      * @return  girds behaviour
       
   129      */
       
   130     TFastSwapGridBehaviour GridBehaviour();
       
   131     
       
   132     /**
       
   133      * Shows highlight. In touch only behaviour highlight
       
   134      * will be shown only for ammount of time.
       
   135      */
       
   136     void ShowHighlight();
       
   137     
       
   138     /**
       
   139      * Hides highlight.
       
   140      */
       
   141     void HideHighlight();
       
   142     
       
   143     /**
       
   144      * Checks if the highlight is currently visible.
       
   145      * 
       
   146      * @return  ETrue  if highlight is visible
       
   147      *          EFalse if highlight is not visible
       
   148      */
       
   149     TBool IsHighlightVisible();
       
   150     
       
   151     /**
       
   152      * Sets visible view, items outside of view will not be drawn
       
   153      */
       
   154     void SetVisibleViewRect( const TRect aRect );
       
   155     
       
   156     /**
       
   157      * Returns visible view. Items outside of visible rectangle are not drawn.
       
   158      */
       
   159     TRect VisibleViewRect();
       
   160     
       
   161     /**
       
   162      * Launch tactile ETouchFeedbackSensitive feedback.
       
   163      */
       
   164     void LaunchTactileFeedback();
       
   165     
       
   166     /**
       
   167      * Set tactile feedback support.
       
   168      * 
       
   169      * @param aSupport new support value 
       
   170      */
       
   171     void SetTactileFeedbackSupport(TBool aSupport);
       
   172     
       
   173     /**
       
   174      * Remove item from iFullyVisibleItems and iPartialVisibleItems arrays 
       
   175      * 
       
   176      * @param   aItem  idem index 
       
   177      * @return  ETrue  if item was removed
       
   178      *          EFalse if item was not found
       
   179      */
       
   180     TBool RemoveFromVisibleItems(TInt aItem) const;
       
   181 
       
   182     /**
       
   183      * Add item to iFullyVisibleItems array 
       
   184      * 
       
   185      * @param   aItem  idem index 
       
   186      * @return  ETrue  if item was added
       
   187      *          EFalse if item was not added because it was there before
       
   188      */
       
   189     TBool AddToFullyVisibleItems(TInt aItem) const;
       
   190 
       
   191     /**
       
   192      * Remove item from iPartialVisibleItems array 
       
   193      * 
       
   194      * @param   aItem  idem index 
       
   195      * @return  ETrue  if item was removed
       
   196      *          EFalse if item was not removed because it was not found
       
   197      */
       
   198     TBool MoveToPartialVisibleItems(TInt aItem) const;
       
   199 
       
   200 private: // From CAknGrid
       
   201     virtual void CreateItemDrawerL();
       
   202 
       
   203 private: // New functions
       
   204     
       
   205     /**
       
   206      * Loads close icon bitmap and mask
       
   207      */
       
   208     void LoadCloseIcon();
       
   209     
       
   210     /**
       
   211      * Redraws grid and parent controls
       
   212      */
       
   213     void Redraw();
       
   214     
       
   215 private: // Data
       
   216     
       
   217     // Grid's parent
       
   218     const CCoeControl* iParent;
       
   219     
       
   220     // Background context for grid
       
   221     CAknsFrameBackgroundControlContext* iBgContext;
       
   222     
       
   223     // Close icon handling
       
   224     RArray<TInt> iCloseItems;
       
   225     TInt iCloseIconHitIdx;
       
   226     MTsFastSwapGridObserver* iFastSwapGridObserver;
       
   227 
       
   228     // Highlight handling
       
   229     TFastSwapGridBehaviour iBehaviour;
       
   230     TBool iHighlightVisible;
       
   231     
       
   232     // Visible view rectangle (horizontal scrolling support)
       
   233     TRect iVisibleViewRect;
       
   234     
       
   235     TBool iTactileFeedbackSupport;
       
   236     
       
   237     mutable RArray<TInt> iFullyVisibleItems;
       
   238     mutable RArray<TInt> iPartialVisibleItems;
       
   239     };
       
   240 
       
   241 
       
   242 
       
   243 /**
       
   244  * Custom item drawer for drawing grid items
       
   245  */
       
   246 class CTsGridItemDrawer: public CFormattedCellListBoxItemDrawer
       
   247     {
       
   248 
       
   249 public: // Constructor and destructor
       
   250     CTsGridItemDrawer( CTsFastSwapGrid* aGrid,
       
   251                                CFormattedCellListBoxData* aData );
       
   252     ~CTsGridItemDrawer();
       
   253 
       
   254 public: // New functions
       
   255 
       
   256     /**
       
   257      * Sets close icon drawn for items that can be closed.
       
   258      * Ownership transferred.
       
   259      */
       
   260     void SetCloseIcon( CFbsBitmap* aBmp, CFbsBitmap* aMask );
       
   261 
       
   262     /**
       
   263      * Initializes close icon rectangles.
       
   264      * 
       
   265      * @param  aButtonRect  rectangle for the button, coordinates must be relative to the grid item
       
   266      * @param  aIconRect    rectangle for the icon, coordinates must be relative to the grid item
       
   267      */
       
   268     void SetCloseIconRect( const TRect& aButtonRect, const TRect& aIconRect );
       
   269     
       
   270     /**
       
   271      * Returns current close icon coordinates for the given item rectangle
       
   272      * 
       
   273      * @param  aItemRect  rectangle of the item for which close button coordinates
       
   274      *                    are to be returned
       
   275      */
       
   276     TRect GetCloseButtonRect( const TRect& aItemRect ) const;
       
   277     
       
   278     /**
       
   279      * Sets screen offset for the item drawer to not draw items on the
       
   280      * grid edges
       
   281      */
       
   282     void SetEdgeOffset( TInt aLeftOffset, TInt aRightOffset );
       
   283     
       
   284     /**
       
   285      * Enables/Disables item drawer background redrawing
       
   286      * 
       
   287      * @param  aEnable  if set to ETrue, background will be redrawn by item drawer
       
   288      *                  if set to EFalse, background will not be redrawn
       
   289      */
       
   290     void SetRedrawBackground( TBool aEnable );
       
   291 
       
   292 private: // From CFormattedCellListBoxItemDrawer
       
   293     void DrawActualItem( TInt aItemIndex, const TRect& aActualItemRect,
       
   294                          TBool aItemIsCurrent, TBool aViewIsEmphasized,
       
   295                          TBool aViewIsDimmed, TBool aItemIsSelected ) const;
       
   296 private: // New functions
       
   297     /**
       
   298      * Checks if the item rectangle is visible in the view.
       
   299      * 
       
   300      * @param   aItemRect  rectangle of the item to be checked 
       
   301      * @return  ETrue      if rectangle is fully or partially visible
       
   302      *          EFalse     if rectangle is not visible
       
   303      */
       
   304     TBool IsItemRectVisible( const TRect& aItemRect ) const;
       
   305     
       
   306     /**
       
   307      * Checks if the aRectContained rectancle is contained by aRectContainig 
       
   308      * 
       
   309      * @param   aRectContained  rectangle that is suppose to be contained 
       
   310      * @param   aRectContainig  rectangle that is suppose to be containing 
       
   311      * @return  ETrue      if rectangle is fully contained 
       
   312      *          EFalse     if rectangle is not fully contained
       
   313      */
       
   314     TBool IsRectContained(const TRect& aRectContained,
       
   315             const TRect& aRectContainig) const;
       
   316 
       
   317     /**
       
   318      * Calculates current inner button rectangle for close icon
       
   319      */
       
   320     TRect CalculateInnerButtonRect( const TRect& aOuterRect ) const; 
       
   321     
       
   322 private: // Data
       
   323     // Not owned
       
   324     CTsFastSwapGrid* iGrid;
       
   325     // Owned
       
   326     CFbsBitmap* iCloseIcon;
       
   327     CFbsBitmap* iCloseIconMask;
       
   328     
       
   329     TRect iScreenRect;
       
   330     TInt iLeftOffset;
       
   331     TInt iRightOffset;
       
   332     
       
   333     // Layout data
       
   334     TRect iCloseIconRect;
       
   335     TRect iCloseButtonRect;
       
   336 	
       
   337     TBool iRedrawBackground;
       
   338     };
       
   339 
       
   340 
       
   341 
       
   342 /**
       
   343  * Timer class for handling highlight bevaiour
       
   344  */
       
   345 class CTsFastSwapTimer : public CTimer
       
   346     {
       
   347 public:
       
   348     // Constructor
       
   349     CTsFastSwapTimer( MTsFastSwapTimerObserver& aObserver );
       
   350     // Destructor
       
   351     ~CTsFastSwapTimer();
       
   352     // 2nd phase constructor
       
   353     void ConstructL();
       
   354     
       
   355 private: // From CTimer
       
   356     void RunL();
       
   357     
       
   358 private: // Data
       
   359     MTsFastSwapTimerObserver* iObserver; // not own
       
   360     };
       
   361 
       
   362 #endif /* TSFASTSWAPGRID_H_ */