tsrc/consoleplayer/common/testappbase.h
changeset 35 b0f0be18af85
equal deleted inserted replaced
32:106971a9964d 35:b0f0be18af85
       
     1 /*
       
     2  * Copyright (c) 2010 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:
       
    15  * Header specifying the common test functionality.
       
    16  * 
       
    17  */
       
    18 
       
    19 #ifndef __TEST_APP_BASE_H__
       
    20 #define __TEST_APP_BASE_H__
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <w32std.h>
       
    24 #include <remconcoreapitargetobserver.h>  // for volume key handling
       
    25 
       
    26 class CRemConCoreApiTarget;
       
    27 class CRemConInterfaceSelector;
       
    28 
       
    29 #define STR(a) (TText*)L##a
       
    30 
       
    31 // 17 keys are supported.  The keys are in this order:
       
    32 //    Enter, Up, Down, Left, Right, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, *, #
       
    33 const TInt KSupportedKeysCount = 17;
       
    34 
       
    35 struct TOperationEntry
       
    36     {
       
    37     const TText* text;
       
    38     TInt         operation;
       
    39     };
       
    40 
       
    41 struct TOperationsPage
       
    42     {
       
    43     const TText*    pageName;    
       
    44     TInt            defaultSoftkeyIndex;
       
    45     TOperationEntry mapping[KSupportedKeysCount];
       
    46     };
       
    47 
       
    48 // Predefined standard operations
       
    49 const TInt KOperation_None = 0;
       
    50 const TInt KOperation_Exit = 1;
       
    51 const TInt KOperation_PreviousOptionPage = 2;
       
    52 const TInt KOperation_NextOptionPage = 3;
       
    53 const TInt KOperation_NextOption = 4;
       
    54 const TInt KOperation_PreviousOption = 5;
       
    55 const TInt KOperation_ExecuteOption = 6;
       
    56 const TInt KOperation_ToggleHelpVisibility = 7;
       
    57 const TInt KOperation_ToggleHelpTransparency = 8;
       
    58 const TInt KOperation_FirstCustomIndex = 10;  // app-specific operations can start here
       
    59 
       
    60 const TUint32 KNullWsHandle = 0xFFFFFFFF;
       
    61 
       
    62 class ITestAppPrompts
       
    63     {
       
    64 public:
       
    65     
       
    66     // Presents a selection list to the user and returns the index of the selected entry.
       
    67     // Synchronous call.
       
    68     // returns -1 if the selection was backed out without making a selection
       
    69     virtual TInt SelectFromListL( TPoint aTopLeft,
       
    70                                   TSize aSize,
       
    71                                   const TDesC& aHeaderText, 
       
    72                                   RPointerArray<TDesC>& aSelectionList, 
       
    73                                   TInt aInitialSelectionIndex = 0 ) = 0;
       
    74 
       
    75     // overload with HBufC instead of TDesC
       
    76     virtual TInt SelectFromListL( TPoint aTopLeft,
       
    77                                   TSize aSize,
       
    78                                   const TDesC& aHeaderText, 
       
    79                                   RPointerArray<HBufC>& aSelectionList, 
       
    80                                   TInt aInitialSelectionIndex = 0 ) = 0;
       
    81 
       
    82     // Synchronous call.
       
    83     // returns false if the selection was backed out without making a selection
       
    84     virtual bool SelectDriveL( TPoint aTopLeft,
       
    85                                TSize aSize,
       
    86                                const TDesC& aHeaderText, 
       
    87                                TDes& aDrive ) = 0;
       
    88     
       
    89     // Synchronous call.
       
    90     // returns false if the selection was backed out without making a selection
       
    91     virtual bool SelectFileL( TPoint aTopLeft,
       
    92                               TSize aSize,
       
    93                               const TDesC& aHeaderText, 
       
    94                               const TDesC& aDrive, 
       
    95                               TDes& aFullFilename ) = 0;
       
    96 
       
    97     // Synchronous call.
       
    98     // returns false if the selection was backed out without making a selection
       
    99     virtual bool SelectFileWithHistoryL( TPoint aTopLeft,
       
   100                                          TSize aSize,
       
   101                                          TDes& aFullFilename,
       
   102                                          const TDesC& aHistoryFilename,
       
   103                                          TInt aMaxHistoryEntries,
       
   104                                          const TDesC& aPrompt = _L("Select drive or recent file:") ) = 0;    
       
   105     
       
   106     // Synchronous call.
       
   107     // returns false if the selection was backed out without making a selection
       
   108     virtual bool SelectIntegerL( TPoint aTopLeft,
       
   109                                  TSize aSize,
       
   110                                  const TDesC& aHeaderText,
       
   111                                  TInt aMin,
       
   112                                  TInt aMax,
       
   113                                  TInt& aSelection ) = 0;  // set aSelection to default value
       
   114     
       
   115     // Synchronous call.  Returns the scan code of the pressed key.
       
   116     virtual TInt WaitForAnyKey() = 0;    
       
   117     
       
   118     virtual TSize DisplaySize() = 0;
       
   119     };
       
   120 
       
   121 class CTestAppBase : public CActive,
       
   122                      protected ITestAppPrompts,
       
   123                      private MRemConCoreApiTargetObserver
       
   124     {
       
   125 public:
       
   126     
       
   127     CTestAppBase( TInt aFontSize );
       
   128     
       
   129     ~CTestAppBase();
       
   130     
       
   131     // inherited from CActive
       
   132     void RunL();
       
   133     void DoCancel();
       
   134 
       
   135 protected:
       
   136     
       
   137     enum TTestAppPointerEvent
       
   138         {
       
   139         EPointerEvent_None,
       
   140         EPointerEvent_Up,
       
   141         EPointerEvent_Down,
       
   142         EPointerEvent_Left,
       
   143         EPointerEvent_Right,
       
   144         EPointerEvent_Select
       
   145         };
       
   146     
       
   147     virtual void ExecuteOperation( TInt aOperation, const TDesC& aOperationText ) = 0;
       
   148 
       
   149     // Subclasses can override this function to take action when the current softkey function has been changed.
       
   150     virtual void SoftkeyFunctionUpdated() {};
       
   151     
       
   152     // Subclasses can override this function to override the default key event handling.
       
   153     virtual bool ConsumeKeyEvent( TInt /*aKeyCode*/ ) { return false; };
       
   154     
       
   155     void BaseConstructL( const TOperationsPage* aKeyMap, TInt aPageCount );
       
   156     
       
   157     void SetupVolumeKeysL();
       
   158 
       
   159     void StartMonitoringWindowEvents();
       
   160 
       
   161     TInt CurrentPageNumber();
       
   162     
       
   163     TPtrC CurrentPageName();
       
   164     
       
   165     TPtrC CurrentSoftkeyName();    
       
   166     
       
   167     // Each line in the file will be an entry in the aContents array
       
   168     TInt ReadFile( const TDesC& aFilename, RPointerArray<HBufC>& aContents );    
       
   169     
       
   170     void BuildDriveListL( RPointerArray<HBufC>& aDrives );
       
   171         
       
   172     void StartReceivingPointerEvents();
       
   173     void StopReceivingPointerEvents();
       
   174 
       
   175     TTestAppPointerEvent CharacterizePointerEvent( const TAdvancedPointerEvent& event );    
       
   176         
       
   177     virtual void HandlePointerEvent( const TAdvancedPointerEvent& /*aEvent*/ ) {}
       
   178     
       
   179     // inherited from ITestAppPrompts
       
   180     TInt SelectFromListL( TPoint aTopLeft,
       
   181                           TSize aSize,
       
   182                           const TDesC& aHeaderText, 
       
   183                           RPointerArray<TDesC>& aSelectionList, 
       
   184                           TInt aInitialSelectionIndex = 0 );
       
   185     TInt SelectFromListL( TPoint aTopLeft,
       
   186                           TSize aSize,
       
   187                           const TDesC& aHeaderText, 
       
   188                           RPointerArray<HBufC>& aSelectionList, 
       
   189                           TInt aInitialSelectionIndex = 0 );
       
   190     bool SelectDriveL( TPoint aTopLeft,
       
   191                        TSize aSize,
       
   192                        const TDesC& aHeaderText, 
       
   193                        TDes& aDrive );
       
   194     bool SelectFileL( TPoint aTopLeft,
       
   195                       TSize aSize,
       
   196                       const TDesC& aHeaderText, 
       
   197                       const TDesC& aDrive, 
       
   198                       TDes& aFullFilename );
       
   199     bool SelectFileWithHistoryL( TPoint aTopLeft,
       
   200                                  TSize aSize,
       
   201                                  TDes& aFullFilename,
       
   202                                  const TDesC& aHistoryFilename,
       
   203                                  TInt aMaxHistoryEntries,
       
   204                                  const TDesC& aPrompt = _L("Select drive or recent file:") );    
       
   205     bool SelectIntegerL( TPoint aTopLeft,
       
   206                          TSize aSize,
       
   207                          const TDesC& aHeaderText,
       
   208                          TInt aMin,
       
   209                          TInt aMax,
       
   210                          TInt& aSelection );  // set aSelection to default value
       
   211     TInt WaitForAnyKey();    
       
   212     TSize DisplaySize() {return iDisplaySize;}
       
   213     
       
   214     const TInt            iFontSize;
       
   215     
       
   216     RFs                   iFs;
       
   217     RWsSession            iWs;
       
   218     CWsScreenDevice*      iScreenDevice; 
       
   219     RWindowGroup*         iWindowGroup;
       
   220     CWindowGc*            iGc;
       
   221     CFont*                iFont;
       
   222     CFbsTypefaceStore*    iTypefaceStore;
       
   223     TSize                 iDisplaySize;
       
   224     RWindow*              iSelectionWindow;    
       
   225     RWindow*              iHelpWindow;
       
   226 
       
   227 private:
       
   228     
       
   229     // inherited from MRemConCoreApiTargetObserver
       
   230     void MrccatoCommand(TRemConCoreApiOperationId aOperationId,
       
   231                         TRemConCoreApiButtonAction aButtonAct);
       
   232 
       
   233     TInt KeyMapOperation(TInt aIndex, TInt aPage );
       
   234     
       
   235     TPtrC KeyMapText( TInt aIndex, TInt aPage );
       
   236 
       
   237     void IncrementKeymapIndex( TInt& aIndex, TInt aPage );
       
   238     
       
   239     void DecrementKeymapIndex( TInt& aIndex, TInt aPage );
       
   240     
       
   241     void CalculateHelpWindowSize();
       
   242 
       
   243     void DrawHelpText();
       
   244     
       
   245     void DoSelectFileL( TPoint aTopRight,
       
   246                         TSize aWindowSize,
       
   247                         const TDesC& aHeaderText, 
       
   248                         const TFileName& aDirectory, 
       
   249                         TInt aDirectoryLevel, 
       
   250                         TDes& aSelectedDirectory, 
       
   251                         TDes& aSelectedFilename );     
       
   252     
       
   253     void ReadDirectoryEntriesL( const TFileName& aDirectoryName, RPointerArray<TDesC>& aFileNames );
       
   254     
       
   255     void ReadFileHistory( const TDesC& aHistoryFilename );
       
   256     
       
   257     void AddToFileHistory( const TDesC& aFilename, const TDesC& aHistoryFilename, TInt aMaxHistoryEntries );
       
   258 
       
   259     const TOperationsPage* iKeyMap;
       
   260     TInt                   iPageCount;
       
   261     TInt                   iCurrentPage;
       
   262     TInt                   iSoftkeyIndices[30];
       
   263     RPointerArray<HBufC>   iFileHistory;
       
   264     
       
   265     CActiveSchedulerWait  iWait;
       
   266     
       
   267     TPoint                iHelpWindowTopRight;
       
   268     TSize                 iHelpWindowSize;
       
   269     TInt                  iHelpWindowColumn1Width;
       
   270     TInt                  iHelpWindowColumn2Width;
       
   271     bool                  iHelpActive;
       
   272     bool                  iHelpSemitransparentBackgroundActive;    
       
   273     
       
   274     bool                  iRoutePointerEventsToApp;
       
   275     TPoint                iPointerDownPosition;
       
   276     
       
   277     // For volume key support
       
   278     CRemConCoreApiTarget*     iCoreTarget;
       
   279     CRemConInterfaceSelector* iInterfaceSelector;    
       
   280     };
       
   281 
       
   282 #endif