taskswitcher/taskswitcherui/taskswitcherapp/inc/tsfastswaparea.h
changeset 4 4d54b72983ae
child 5 c743ef5928ba
equal deleted inserted replaced
3:fb3763350a08 4:4d54b72983ae
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Taskswitcher Fast Swap area UI
       
    15  *
       
    16 */
       
    17 
       
    18 #ifndef TSFASTSWAPAREA_H
       
    19 #define TSFASTSWAPAREA_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <eikmobs.h>
       
    23 #include "tsdevicestate.h"
       
    24 #include "tsfswclientobserver.h"
       
    25 #include "tsfastswapgrid.h"
       
    26 #include "tseventcontrolerobserver.h"
       
    27 
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class CTsFswClient;
       
    31 class CTsFswEntry;
       
    32 class CAknStylusPopUpMenu;
       
    33 class CAknQueryDialog;
       
    34 class CTsEventControler;
       
    35 class MTsDataChangeObserver;
       
    36 
       
    37 /**
       
    38  * Taskswitcher Fast Swap area UI.
       
    39  */
       
    40 class CTsFastSwapArea: public CCoeControl,
       
    41                                public MEikMenuObserver,
       
    42                                public MTsFswObserver,
       
    43                                public MEikListBoxObserver,
       
    44                                public MTsFastSwapGridObserver,
       
    45                                private MTsEventControlerObserver,
       
    46                                public MTsDeviceStateObserver,
       
    47                                public MTsFastSwapTimerObserver
       
    48     {
       
    49 public:
       
    50     /**
       
    51      * Two-phase constructor.
       
    52      * 
       
    53      * @param aRect Area where fast swap info & list should draw itself.
       
    54      * @param aParent Parent CoeControl. 
       
    55      */
       
    56     static CTsFastSwapArea* NewL( const TRect& aRect,
       
    57             CCoeControl& aParent, CTsDeviceState& aDeviceState,
       
    58             CTsEventControler& aEventHandler);
       
    59 
       
    60     /**
       
    61      * @copydoc NewL
       
    62      */
       
    63     static CTsFastSwapArea* NewLC( const TRect& aRect,
       
    64             CCoeControl& aParent, CTsDeviceState& aDeviceState,
       
    65             CTsEventControler& aEventHandler);
       
    66 
       
    67     /**
       
    68      * Destructor.
       
    69      */
       
    70     ~CTsFastSwapArea();
       
    71 
       
    72     /**
       
    73      * Called from appview when coming to foreground.
       
    74      */
       
    75     void HandleSwitchToForegroundEvent();
       
    76     
       
    77     /**
       
    78      * Called from appview when going to background.
       
    79      */
       
    80     void HandleSwitchToBackgroundEvent();
       
    81 
       
    82     /**
       
    83      * Called after construction to set up additional properties,
       
    84      * like the control observer.
       
    85      */
       
    86     void Setup( MCoeControlObserver& aControlObserver );
       
    87 
       
    88     /**
       
    89      * Saves the index of the currently selected (highlighted) item.
       
    90      */
       
    91     void SaveSelectedIndex();
       
    92     
       
    93     /**
       
    94      * Restores the selection (highlight) position.
       
    95      */
       
    96     void RestoreSelectedIndex();
       
    97 
       
    98     // Functions to perform activate, close, close others operations.
       
    99     // They are public so same functionality can be implemented in the
       
   100     // Options menu (appui) for example.
       
   101     
       
   102     /**
       
   103      * Index of highlighted item or KErrNotFound.
       
   104      */
       
   105     TInt SelectedIndex() const;
       
   106     
       
   107     /**
       
   108      * Brings the app corresponding to the item at given index into foreground.
       
   109      */
       
   110     void SwitchToApp( TInt aIndex );
       
   111     
       
   112     /**
       
   113      * Sends close msg to given app.
       
   114      * @param   aIndex      index
       
   115      * @param   aSuppressRendering  content is not refreshed if ETrue
       
   116      */
       
   117     void TryCloseAppL( TInt aIndex, TBool aSuppressRendering = EFalse );
       
   118     
       
   119     /**
       
   120      * Sends close msg to given app if user confirms the query.
       
   121      */
       
   122     void TryCloseAppWithQueryL( TInt aIndex );
       
   123     
       
   124     /**
       
   125      * Tries to Close all applications that cn be closed
       
   126      */
       
   127     void TryCloseAllL();
       
   128     
       
   129     /**
       
   130      * True if it is allowed to ask the given app to close.
       
   131      * @param   aIndex  index
       
   132      */
       
   133     TBool CanClose( TInt aIndex ) const;
       
   134     
       
   135     /**
       
   136      * @param  aSelectedItem  item for which pop up is shown
       
   137      * 
       
   138      * @return ETrue, when number of closable apps is >= 2 or there is at least
       
   139      *                one closable item and non closable item is selected.
       
   140      * @return EFalse, when number of closable apps is < 2.
       
   141      */
       
   142     TBool CanCloseAll( TInt aSelectedItem ) const;
       
   143 
       
   144     /**
       
   145      * Returns the number of items in the list.
       
   146      */
       
   147     TInt Count() const;
       
   148 
       
   149     /**
       
   150      * Returns the underlying Ganes control pointer.
       
   151      */
       
   152     CCoeControl* GetChildControl() { return iGrid; }
       
   153 
       
   154     /**
       
   155      * Sets the data-changed observer.
       
   156      */
       
   157     void SetDataChangeObserver( MTsDataChangeObserver* aDcObserver );
       
   158 
       
   159     /*
       
   160      * Handling short/long app key.
       
   161      */
       
   162     void HandleAppKey(TInt aType);
       
   163 
       
   164 private:
       
   165 
       
   166     /**
       
   167      * @copydoc NewL
       
   168      */
       
   169     void ConstructL( const TRect& aRect );
       
   170 
       
   171     /**
       
   172      * C++ constructor.
       
   173      */
       
   174     CTsFastSwapArea(CCoeControl& aParent,
       
   175             CTsDeviceState& aDeviceState,
       
   176             CTsEventControler& aEventHandler);
       
   177     
       
   178     // From MEikListBoxObserver
       
   179     void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType);
       
   180     
       
   181 public:
       
   182     /**
       
   183      * Implements drag gesture handling
       
   184      * @see MTsEventControlerObserver
       
   185      */
       
   186     void MoveOffset(const TPoint&);
       
   187 
       
   188     /**
       
   189      * Implements tap gesture handling
       
   190      * @see MTsEventControlerObserver
       
   191      */
       
   192     void TapL(const TPoint&);
       
   193 
       
   194     /**
       
   195      * Implements long tap gesture handling
       
   196      * @see MTsEventControlerObserver
       
   197      */
       
   198     void LongTapL(const TPoint&);
       
   199 
       
   200     /**
       
   201      * Implements drag gesture handling
       
   202      * @see MTsEventControlerObserver
       
   203      */
       
   204     void Drag(const AknTouchGestureFw::MAknTouchGestureFwDragEvent& aEvent);
       
   205     
       
   206     /**
       
   207      * Implements animation stop handling
       
   208      * @see MTsEventControlerObserver
       
   209      */
       
   210     void Stop();
       
   211     
       
   212     /**
       
   213      * Implements view position getter. Returns point in the middle of the
       
   214      * grid view window.
       
   215      * 
       
   216      * @see MTsEventControlerObserver
       
   217      */
       
   218     TPoint ViewPos()const;
       
   219     
       
   220 public:    
       
   221     // from CCoeControl    
       
   222     TInt CountComponentControls() const;
       
   223     CCoeControl* ComponentControl(TInt aIndex) const;
       
   224     void FocusChanged( TDrawNow aDrawNow );
       
   225     void SizeChanged();
       
   226     void Draw( const TRect& aRect ) const;
       
   227     TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType );
       
   228     void HandlePointerEventL( const TPointerEvent& aPointerEvent );
       
   229     
       
   230 private:
       
   231     // From MTsFswObserver     
       
   232     void HandleFswContentChanged();
       
   233     
       
   234     // From MEikMenuObserver
       
   235     void ProcessCommandL( TInt aCommandId );
       
   236 	void SetEmphasis( CCoeControl*, TBool ) { }
       
   237 	
       
   238 	// From MTsFastSwapGridObserver
       
   239 	void HandleCloseEventL(TInt aItemIdx);
       
   240 	
       
   241 	// From MTsDeviceStateObserver
       
   242 	void HandleDeviceStateChanged( TChangeType aChangeType );
       
   243 
       
   244     // From MTsFastSwapTimerObserver
       
   245     void TimerCompletedL( CTsFastSwapTimer* aSource );
       
   246 	
       
   247 // new functions    
       
   248 
       
   249     /**
       
   250      * Makes a copy of the given bitmap.
       
   251      * Also scaled to the given size, but maintains aspect ratio,
       
   252      * so the size of the returned bitmap may be less then aSize.
       
   253      */
       
   254     CFbsBitmap* CopyBitmapL( TInt aFbsHandle, TSize aSize );
       
   255 
       
   256     /**
       
   257      * Called from HandleFswContentChanged.
       
   258      */    
       
   259     void HandleFswContentChangedL();
       
   260     
       
   261     /**
       
   262      * Shows the content from iArray on the screen.
       
   263      */
       
   264     void RenderContentL();
       
   265     
       
   266     /**
       
   267      * Creates the ganes grid control.
       
   268      */
       
   269     void ReCreateGridL();
       
   270     
       
   271     /**
       
   272      * Returns rectangles for fast swap area controls
       
   273      */
       
   274     void GetFastSwapAreaRects( RArray<TAknLayoutRect>& aRects );
       
   275 
       
   276     /**
       
   277      * Creates a stylus popup instance (iPopup) if not yet done.
       
   278      */
       
   279     void PreCreatePopupL();
       
   280 
       
   281     /**
       
   282      * Shows the stylus popup menu if not yet visible.
       
   283      * @param   aIndex  index of item in the grid
       
   284      * @param   aPoint  position for the popup
       
   285      */
       
   286     TBool ShowPopupL( TInt aIndex, const TPoint& aPoint );
       
   287     
       
   288     /**
       
   289      * Shows the app close confirmation query.
       
   290      * @param   aIndex  index of item in the grid
       
   291      * @return ETrue if accepted EFalse if canceled
       
   292      */
       
   293     TBool ConfirmCloseL( TInt aIndex );
       
   294 
       
   295     /**
       
   296      * Sends the data-changed notification.
       
   297      */   
       
   298     void NotifyChange();
       
   299 
       
   300     /**
       
   301      * Chage application order.
       
   302      * move Homescreen to first left position.
       
   303      */   
       
   304     void SwapApplicationOrder( RPointerArray<CTsFswEntry>& aArray );
       
   305     
       
   306     /**
       
   307      * Retrieves and returns size for image graphics.
       
   308      */
       
   309     TSize PreferredImageSize();
       
   310     
       
   311     /**
       
   312      * Retrieves number of items in grid
       
   313      */
       
   314     TInt GridItemCount();
       
   315     
       
   316     /**
       
   317      * Calculates the correct size if aspect ratio needs to be preserved.
       
   318      */
       
   319     TSize CalculateSizePreserveRatio(const TSize& aTargetAreaSize,
       
   320             const TSize& aSourceSize);
       
   321     
       
   322     /**
       
   323      * Selects next item in grid
       
   324      */
       
   325     void SelectNextItem();
       
   326     
       
   327     /**
       
   328      * Highlight current grid'd item and redraw
       
   329      */
       
   330     void ShowHighlight();
       
   331     
       
   332     /**
       
   333      * Centralise most centered item so it was most exposed on the view.
       
   334      * Centered element is being selected by grid.
       
   335      * Animation to the centered element is made after aRedrawDelay time.
       
   336      * 
       
   337      * @param aRedrawDelay - animation delay.
       
   338      */
       
   339     void CenterItem( TInt aRedrawDelay);
       
   340     
       
   341     /**
       
   342      * Returns full grid view size.
       
   343      */
       
   344     TSize GridWorldSize();
       
   345     
       
   346     /**
       
   347      * Updates grid, called for manual grid scroll update
       
   348      * 
       
   349      * @param  aForceRedraw    if set to ETrue - redraw will be forced
       
   350      * @param  aAnimate        set to ETrue to enable animation
       
   351      */
       
   352     void UpdateGrid( TBool aForceRedraw = EFalse,
       
   353                      TBool aAnimate = ETrue );
       
   354     
       
   355     /**
       
   356      * Returns grid view size
       
   357      */
       
   358     TSize ViewSize();
       
   359     
       
   360     /**
       
   361      * Returns the position of the given item inside grid world rect.
       
   362      * Returns point in the middle of the view rectangle.
       
   363      * 
       
   364      * @param  aItemIdx  index of the item for which calculation will be done
       
   365      */
       
   366     TPoint ItemViewPosition( TInt aItemIdx );
       
   367     
       
   368     /**
       
   369      * Returns index of the shown item, based on the logical
       
   370      * position of the grids view. Item that is closest to the
       
   371      * middle of screen is returned.
       
   372      * 
       
   373      * @param  aViewPos  grids view position. This must be point in
       
   374      *                   the middle of the view rectangle
       
   375      * @return  index of the item
       
   376      */
       
   377     TInt ViewToVisibleItem( const TPoint aViewPos );
       
   378     
       
   379     /**
       
   380      * Launches increasing pop-up feedback.
       
   381      */
       
   382     void LaunchPopupFeedback();
       
   383 
       
   384 private: // Data
       
   385     
       
   386     // parent control
       
   387     CCoeControl& iParent;
       
   388     
       
   389     // device state
       
   390     // not own 
       
   391     CTsDeviceState& iDeviceState;
       
   392 
       
   393     // grid, own
       
   394     CTsFastSwapGrid* iGrid;
       
   395         
       
   396     // fsw client, own
       
   397     CTsFswClient* iFSClient;
       
   398     // fsw content, ptrs owned
       
   399     RPointerArray<CTsFswEntry> iArray;
       
   400     
       
   401     // index of selected (highlighted) item in the grid
       
   402     // when the fsw was last focused
       
   403     TInt iSavedSelectedIndex;
       
   404     
       
   405     // fsw popup (activate, close, etc.), own
       
   406     CAknStylusPopUpMenu* iPopup;
       
   407     // the aIndex argument of ShowPopupL is stored here
       
   408     TInt iAppIndexForPopup;
       
   409 
       
   410     // query shown when pressing Clear key in fsw, own
       
   411     CAknQueryDialog* iConfirmCloseQuery;
       
   412 
       
   413     // Timestamp of the last application close operation
       
   414     TTime iTimeOfLastClose;
       
   415     
       
   416     // Observer ptr, may be NULL, not owned
       
   417     MTsDataChangeObserver* iDcObserver;
       
   418     
       
   419     //Input events handler
       
   420     CTsEventControler& iEvtHandler;
       
   421     
       
   422     TInt iMaxItemsOnScreen;
       
   423     TInt iPreviousNoOfItems;
       
   424     
       
   425     // Tap event
       
   426     TPointerEvent iTapEvent;
       
   427     CTsFastSwapTimer* iHighlightTimer;
       
   428     
       
   429     // Grid scrolling
       
   430     TInt iGridItemWidth;
       
   431     TInt iGridItemGap;
       
   432     
       
   433     CTsFastSwapTimer* iRedrawTimer; // owned
       
   434     
       
   435     CTsFastSwapTimer* iUpdateGridTimer;//owned
       
   436     
       
   437     // Key event handling
       
   438     TBool iConsumeEvent;
       
   439     TBool iKeyEvent;
       
   440     };
       
   441 
       
   442 #endif // TSFASTSWAPAREA_H