tsrc/consoleplayer/common/testappbase.cpp
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  * Source file containing common test app functionality.
       
    16  * 
       
    17  */
       
    18 
       
    19 #include <f32file.h>
       
    20 #include <remconcoreapitarget.h>
       
    21 #include <remconinterfaceselector.h>
       
    22 
       
    23 #include "testappbase.h"
       
    24 
       
    25 const TInt KLeftSoftKeyCode  = EKeyDevice0;
       
    26 const TInt KRightSoftKeyCode = EKeyDevice1;
       
    27 
       
    28 const TInt KHelpWindowBorderPixels = 20;
       
    29 const TInt KHelpWindowSpaceBetweenColumns = 25;
       
    30 const TInt KHelpWindowSpaceBetweenRows = 2;
       
    31 
       
    32 struct TKeyListEntry
       
    33     {
       
    34     TInt         keyCode;
       
    35     const TText* keyName;
       
    36     };
       
    37 
       
    38 const TKeyListEntry KSupportedKeys[KSupportedKeysCount] =
       
    39         {
       
    40             {EKeyEnter,      STR("Enter")},      
       
    41             {EKeyUpArrow,    STR("Up")},
       
    42             {EKeyDownArrow,  STR("Down")}, 
       
    43             {EKeyLeftArrow,  STR("Left")},
       
    44             {EKeyRightArrow, STR("Right")},
       
    45             {'0',            STR("0")},
       
    46             {'1',            STR("1")},  
       
    47             {'2',            STR("2")}, 
       
    48             {'3',            STR("3")},
       
    49             {'4',            STR("4")},
       
    50             {'5',            STR("5")},
       
    51             {'6',            STR("6")},
       
    52             {'7',            STR("7")},
       
    53             {'8',            STR("8")},
       
    54             {'9',            STR("9")},
       
    55             {'*',            STR("*")},
       
    56             {'#',            STR("#")}
       
    57         };
       
    58         
       
    59 static TPtrC KeyName( TInt aIndex )
       
    60     {
       
    61     return TPtrC(KSupportedKeys[aIndex].keyName);
       
    62     }
       
    63 
       
    64 // Portable app implementation
       
    65 
       
    66 CTestAppBase::CTestAppBase( TInt aFontSize ) : 
       
    67     CActive( EPriorityStandard ),
       
    68     iFontSize( aFontSize ),
       
    69     iHelpSemitransparentBackgroundActive( true )
       
    70     {    
       
    71     CActiveScheduler::Add(this);
       
    72     }
       
    73 
       
    74 CTestAppBase::~CTestAppBase()
       
    75     {
       
    76     delete iInterfaceSelector;
       
    77     delete iHelpWindow;
       
    78     delete iSelectionWindow;
       
    79     delete iGc;
       
    80     delete iWindowGroup;
       
    81     delete iScreenDevice;
       
    82     delete iTypefaceStore;
       
    83     iWs.Close();
       
    84     iFs.Close();
       
    85     iFileHistory.ResetAndDestroy();
       
    86     }
       
    87 
       
    88 void CTestAppBase::BaseConstructL( const TOperationsPage* aKeyMap, TInt aPageCount )
       
    89     {
       
    90     iKeyMap = aKeyMap;
       
    91     iPageCount = aPageCount;
       
    92     
       
    93     User::LeaveIfError( iFs.Connect() );        
       
    94     
       
    95     User::LeaveIfError( iWs.Connect() );    
       
    96 
       
    97     iScreenDevice = new(ELeave) CWsScreenDevice( iWs );
       
    98     User::LeaveIfError( iScreenDevice->Construct() );
       
    99     iDisplaySize = iScreenDevice->SizeInPixels();
       
   100     
       
   101     User::LeaveIfError( iScreenDevice->CreateContext(iGc) );
       
   102 
       
   103     iWindowGroup = new(ELeave) RWindowGroup( iWs );
       
   104     User::LeaveIfError( iWindowGroup->Construct( KNullWsHandle ) );
       
   105 
       
   106     iSelectionWindow = new(ELeave) RWindow( iWs );
       
   107     User::LeaveIfError( iSelectionWindow->Construct( *iWindowGroup, KNullWsHandle ) );    
       
   108     iSelectionWindow->SetVisible(false);
       
   109     iSelectionWindow->Activate();    
       
   110             
       
   111     // Load the font to be used for all text operations.
       
   112     TFontSpec fontSpec;
       
   113     fontSpec.iHeight = iFontSize;
       
   114     iTypefaceStore = CFbsTypefaceStore::NewL(NULL);
       
   115     
       
   116     User::LeaveIfError( iTypefaceStore->GetNearestFontToDesignHeightInPixels(iFont, fontSpec) );
       
   117 
       
   118     CalculateHelpWindowSize();
       
   119 
       
   120     iHelpWindowTopRight = TPoint(iDisplaySize.iWidth/2 - iHelpWindowSize.iWidth/2, 
       
   121                                  iDisplaySize.iHeight/2 - iHelpWindowSize.iHeight/2);
       
   122 
       
   123     iHelpWindow = new(ELeave) RWindow( iWs );
       
   124     User::LeaveIfError( iHelpWindow->Construct( *iWindowGroup, KNullWsHandle ) );
       
   125     iHelpWindow->SetExtent( iHelpWindowTopRight, iHelpWindowSize );
       
   126     iHelpWindow->SetTransparencyAlphaChannel();
       
   127     iHelpWindow->SetBackgroundColor(KRgbTransparent);
       
   128     iHelpWindow->SetVisible(false);
       
   129     iHelpWindow->Activate();
       
   130     iHelpWindow->PointerFilter(EPointerFilterDrag, 0);
       
   131 
       
   132     // Initialize soft key indices
       
   133     for( TInt i = 0; i < aPageCount; i++ )
       
   134         {
       
   135         iSoftkeyIndices[i] = iKeyMap[i].defaultSoftkeyIndex;
       
   136         }
       
   137     
       
   138     // Only need to draw the help text when the options page is changed.  Window is displayed later by
       
   139     // toggling the visibility of the window.
       
   140     DrawHelpText();
       
   141     
       
   142     // THE FOLLOWING CODE IS COMMENTED OUT BECAUSE IT CAUSES A CRASH IN NCP BUILDS.
       
   143     // THIS CAN BE ENABLED IN DFS BUILDS, TO ALLOW FOR TWO BUTTON OPERATION USING THE VOLUME KEYS.
       
   144     //
       
   145     // Since some phone have no keyboard or soft keys, treat the volume keys like the soft keys.
       
   146     // SetupVolumeKeysL();    
       
   147     }
       
   148 
       
   149 void CTestAppBase::SetupVolumeKeysL()
       
   150     {
       
   151     iInterfaceSelector = CRemConInterfaceSelector::NewL();
       
   152     iCoreTarget = CRemConCoreApiTarget::NewL(*iInterfaceSelector, *this);
       
   153     iInterfaceSelector->OpenTargetL();
       
   154     }
       
   155 
       
   156 void CTestAppBase::StartMonitoringWindowEvents()
       
   157     {
       
   158     // Request notification for windows server events, to detect key presses.    
       
   159     SetActive();
       
   160     iWs.EventReady( &iStatus );
       
   161     }
       
   162 
       
   163 TInt CTestAppBase::CurrentPageNumber()
       
   164     {
       
   165     return iCurrentPage+1;
       
   166     }
       
   167 
       
   168 TPtrC CTestAppBase::CurrentPageName()
       
   169     {
       
   170     return TPtrC(iKeyMap[iCurrentPage].pageName);
       
   171     }
       
   172 
       
   173 TPtrC CTestAppBase::CurrentSoftkeyName()
       
   174     {
       
   175     return TPtrC(iKeyMap[iCurrentPage].mapping[iSoftkeyIndices[iCurrentPage]].text);    
       
   176     }
       
   177     
       
   178 TPtrC CTestAppBase::KeyMapText( TInt aIndex, TInt aPage )
       
   179     {
       
   180     return TPtrC(iKeyMap[aPage].mapping[aIndex].text);
       
   181     }
       
   182 
       
   183 TInt CTestAppBase::KeyMapOperation(TInt aIndex, TInt aPage )
       
   184     {
       
   185     return iKeyMap[aPage].mapping[aIndex].operation;
       
   186     }
       
   187 
       
   188 void CTestAppBase::IncrementKeymapIndex( TInt& aIndex, TInt aPage )
       
   189     {
       
   190     aIndex = (aIndex + 1) % KSupportedKeysCount;
       
   191     while( iKeyMap[aPage].mapping[aIndex].operation == KOperation_None )
       
   192         {
       
   193         aIndex = (aIndex + 1) % KSupportedKeysCount;
       
   194         }
       
   195     }
       
   196 
       
   197 void CTestAppBase::DecrementKeymapIndex( TInt& aIndex, TInt aPage )
       
   198     {
       
   199     aIndex = (aIndex + KSupportedKeysCount - 1) % KSupportedKeysCount;
       
   200     while( iKeyMap[aPage].mapping[aIndex].operation == KOperation_None )
       
   201         {
       
   202         aIndex = (aIndex + KSupportedKeysCount - 1) % KSupportedKeysCount;
       
   203         }
       
   204     }
       
   205 
       
   206 void CTestAppBase::CalculateHelpWindowSize()
       
   207     {
       
   208     iHelpWindowColumn1Width = 0;
       
   209     iHelpWindowColumn2Width = 0;
       
   210     
       
   211     // Find the widest strings for each column to determine the width of the window.
       
   212     for( TInt index = 0; index < KSupportedKeysCount; index++ )
       
   213         {
       
   214         TInt width = iFont->TextWidthInPixels(KeyName(index));
       
   215         if( width > iHelpWindowColumn1Width )
       
   216             {
       
   217             iHelpWindowColumn1Width = width;
       
   218             }
       
   219         
       
   220         for( TInt index2 = 0; index2 < iPageCount; index2++ )
       
   221             {
       
   222             width = iFont->TextWidthInPixels(KeyMapText(index,index2));
       
   223             if( width > iHelpWindowColumn2Width )
       
   224                 {
       
   225                 iHelpWindowColumn2Width = width;
       
   226                 }                    
       
   227             }
       
   228         }    
       
   229     
       
   230     iHelpWindowSize.iWidth = 2*KHelpWindowBorderPixels + iHelpWindowColumn1Width + 
       
   231                              KHelpWindowSpaceBetweenColumns + iHelpWindowColumn2Width;
       
   232     
       
   233     iHelpWindowSize.iHeight = 2*KHelpWindowBorderPixels + iFontSize*KSupportedKeysCount + 
       
   234                               KHelpWindowSpaceBetweenRows*(KSupportedKeysCount-1);
       
   235     }
       
   236 
       
   237 void CTestAppBase::StartReceivingPointerEvents()
       
   238     {
       
   239     iRoutePointerEventsToApp = true;
       
   240     }
       
   241 
       
   242 void CTestAppBase::StopReceivingPointerEvents()
       
   243     {
       
   244     iRoutePointerEventsToApp = false;
       
   245     }
       
   246 
       
   247 //virtual void HandlePointerEvent( const TPointerEvent& aEvent ) {}
       
   248 
       
   249 CTestAppBase::TTestAppPointerEvent CTestAppBase::CharacterizePointerEvent( const TAdvancedPointerEvent& event )
       
   250     {
       
   251     TTestAppPointerEvent returnValue = EPointerEvent_None;
       
   252     
       
   253     RDebug::Printf( "POINTER EVENT:" );        
       
   254     RDebug::Printf( "iType=%i", event.iType );
       
   255     RDebug::Printf( "iModifiers=%x", event.iModifiers );
       
   256     RDebug::Printf( "iPosition=%i,%i", event.iPosition.iX, event.iPosition.iY );
       
   257     RDebug::Printf( "iParentPosition=%i,%i", event.iParentPosition.iX, event.iParentPosition.iY );
       
   258     RDebug::Printf( "PointerNumber=%i", event.PointerNumber() );
       
   259     RDebug::Printf( "Proximity=%i", event.Proximity() );
       
   260     RDebug::Printf( "Pressure=%i", event.Pressure() );
       
   261     RDebug::Printf( "ProximityAndPressure=%i", event.ProximityAndPressure() );
       
   262     RDebug::Printf( "Position3D=%i,%i,%i", event.Position3D().iX, event.Position3D().iY, event.Position3D().iZ );
       
   263     RDebug::Printf( "Pressure3D=%i,%i,%i", event.Pressure3D().iX, event.Pressure3D().iY, event.Pressure3D().iZ );
       
   264     RDebug::Printf( "PositionAndPressure3D=%i,%i,%i", event.PositionAndPressure3D().iX, event.PositionAndPressure3D().iY, event.PositionAndPressure3D().iZ );
       
   265     
       
   266     switch( event.iType )
       
   267         {
       
   268         case TPointerEvent::EButton1Down:
       
   269             {
       
   270             iPointerDownPosition = event.iPosition;            
       
   271             break;
       
   272             }
       
   273         case TPointerEvent::EButton1Up:
       
   274             {
       
   275             TInt xDelta = event.iPosition.iX - iPointerDownPosition.iX; 
       
   276             TInt yDelta = event.iPosition.iY - iPointerDownPosition.iY;
       
   277             
       
   278             TInt xMagnitude = xDelta;
       
   279             if( xMagnitude < 0 )
       
   280                 {
       
   281                 xMagnitude = -xMagnitude;
       
   282                 }
       
   283             
       
   284             TInt yMagnitude = yDelta;
       
   285             if( yMagnitude < 0 )
       
   286                 {
       
   287                 yMagnitude = -yMagnitude;
       
   288                 }
       
   289 
       
   290             const TInt KTapThreshold = 30;
       
   291             
       
   292             if( yMagnitude > xMagnitude )
       
   293                 {
       
   294                 if( yMagnitude < KTapThreshold )
       
   295                     {
       
   296                     RDebug::Printf( "POINTER EVENT ENTER x=%i y=%i", xDelta, yDelta );                            
       
   297                     returnValue = EPointerEvent_Select;
       
   298                     }
       
   299                 else if( yDelta < 0 )
       
   300                     {
       
   301                     RDebug::Printf( "POINTER EVENT UP x=%i y=%i", xDelta, yDelta );        
       
   302                     returnValue = EPointerEvent_Up;
       
   303                     }
       
   304                 else
       
   305                     {
       
   306                     RDebug::Printf( "POINTER EVENT DOWN x=%i y=%i", xDelta, yDelta );                            
       
   307                     returnValue = EPointerEvent_Down;
       
   308                     }                
       
   309                 }
       
   310             else
       
   311                 {
       
   312                 if( xMagnitude < KTapThreshold )
       
   313                     {
       
   314                     RDebug::Printf( "POINTER EVENT ENTER x=%i y=%i", xDelta, yDelta );                            
       
   315                     returnValue = EPointerEvent_Select;
       
   316                     }
       
   317                 else if( xDelta < 0 )
       
   318                     {
       
   319                     RDebug::Printf( "POINTER EVENT LEFT x=%i y=%i", xDelta, yDelta );        
       
   320                     returnValue = EPointerEvent_Left;
       
   321                     }
       
   322                 else
       
   323                     {
       
   324                     RDebug::Printf( "POINTER EVENT RIGHT x=%i y=%i", xDelta, yDelta );                            
       
   325                     returnValue = EPointerEvent_Right;
       
   326                     }                                
       
   327                 }
       
   328             break;
       
   329             }
       
   330         }
       
   331     
       
   332     return returnValue;
       
   333     }
       
   334 
       
   335 void CTestAppBase::RunL()
       
   336     {
       
   337     if( iWait.IsStarted() )
       
   338         {
       
   339         // This is an event during synchronous list selection.  Stop the nested scheduler.
       
   340         iWait.AsyncStop();
       
   341         return;
       
   342         }    
       
   343     
       
   344     TWsEvent event;
       
   345     iWs.GetEvent(event);
       
   346 
       
   347     TInt operationIndex = -1;
       
   348     
       
   349     TInt keyCode = 0;
       
   350     bool processKeyCode = false;
       
   351     
       
   352     TInt operation = KOperation_None; 
       
   353     
       
   354     // Other potentially useful events are EEventKeyUp and EEventKeyDown.
       
   355     
       
   356     if( event.Type() == EEventKey )
       
   357         {
       
   358         keyCode = event.Key()->iCode;
       
   359                    
       
   360         RDebug::Printf( "key event keyCode=%x/%c scanCode=%x/%c", keyCode, keyCode, event.Key()->iScanCode, event.Key()->iScanCode );
       
   361         
       
   362         // Allow subclasses a chance to consume the key event directly.  If that happens, then
       
   363         // do not handle the key as normal.
       
   364         if( !ConsumeKeyEvent( keyCode ) )
       
   365             {
       
   366             processKeyCode = true;        
       
   367             }
       
   368         }
       
   369     else if( event.Type() == EEventPointer )
       
   370         {
       
   371         TAdvancedPointerEvent* p = event.Pointer();
       
   372 
       
   373         if( iRoutePointerEventsToApp  )
       
   374             {
       
   375             HandlePointerEvent( *p );
       
   376             }
       
   377         else
       
   378             {        
       
   379             TTestAppPointerEvent pointerEvent = CharacterizePointerEvent( *p );
       
   380 
       
   381             switch( pointerEvent )
       
   382                 {
       
   383                 case EPointerEvent_None:
       
   384                     // Do nothing.
       
   385                     break;
       
   386                 case EPointerEvent_Up:
       
   387                     operation = KOperation_PreviousOption;
       
   388                     break;
       
   389                 case EPointerEvent_Down:
       
   390                     operation = KOperation_NextOption;
       
   391                     break;
       
   392                 case EPointerEvent_Left:
       
   393                     operation = KOperation_PreviousOptionPage;
       
   394                     break;
       
   395                 case EPointerEvent_Right:
       
   396                     operation = KOperation_NextOptionPage;
       
   397                     break;
       
   398                 case EPointerEvent_Select:
       
   399                     operation = KOperation_ExecuteOption;
       
   400                     break;
       
   401                 }
       
   402             }
       
   403         }
       
   404     else
       
   405         {
       
   406         RDebug::Printf( "other event, type=%i", event.Type() );    
       
   407         }
       
   408         
       
   409     if( processKeyCode )
       
   410         {
       
   411         // If one of the softkeys were pressed then take the appropriate action.
       
   412         // This is to support a two button touch device with no numeric keypad.
       
   413         // Support 'A' and 'B' also, for the NCP emulator where a keyboard  is
       
   414         // not displayed.
       
   415         switch( keyCode )
       
   416             {
       
   417             case KLeftSoftKeyCode:
       
   418             case 'a':
       
   419             case 'A':
       
   420                 {
       
   421                 operation = KOperation_NextOption;
       
   422                 break;
       
   423                 } 
       
   424             case KRightSoftKeyCode:
       
   425             case 'b':
       
   426             case 'B':
       
   427                 {
       
   428                 // Execute softkey function.
       
   429                 operation = KOperation_ExecuteOption;
       
   430                 break;
       
   431                 }
       
   432             default:
       
   433                 {
       
   434                 // Search for keycode in keymap.  If not found then the key was not a valid
       
   435                 // key, so ignore.                
       
   436                 TInt index = 0;
       
   437                 while( (index < KSupportedKeysCount) && (operationIndex == -1))
       
   438                     {
       
   439                     if( KSupportedKeys[index].keyCode == keyCode )
       
   440                         {                
       
   441                         // Found!
       
   442                         operationIndex = index;
       
   443                         }
       
   444                     else
       
   445                         {
       
   446                         index++;
       
   447                         }
       
   448                     }
       
   449                 break;
       
   450                 }                
       
   451             }        
       
   452         }
       
   453     
       
   454     if( operation == KOperation_ExecuteOption )
       
   455         {
       
   456         operationIndex = iSoftkeyIndices[iCurrentPage];
       
   457         }
       
   458     
       
   459     if( operationIndex >= 0 )
       
   460         {
       
   461         operation = KeyMapOperation(operationIndex, iCurrentPage);    
       
   462         }
       
   463     
       
   464     if( operation != KOperation_None )
       
   465         {
       
   466         // Valid operation.
       
   467 
       
   468         switch( operation )
       
   469             {
       
   470             case KOperation_Exit:
       
   471                 {                
       
   472                 CActiveScheduler::Stop();
       
   473                 break;
       
   474                 }
       
   475             case KOperation_PreviousOption:
       
   476                 {
       
   477                 // Change softkey function.
       
   478                 DecrementKeymapIndex( iSoftkeyIndices[iCurrentPage], iCurrentPage );
       
   479                 
       
   480                 // Redraw help text, since a new function should now be underlined.
       
   481                 DrawHelpText();
       
   482                 
       
   483                 // Notify subclass that softkey function has been updated.
       
   484                 SoftkeyFunctionUpdated();
       
   485                 break;
       
   486                 }
       
   487             case KOperation_NextOption:
       
   488                 {
       
   489                 // Change softkey function.
       
   490                 IncrementKeymapIndex( iSoftkeyIndices[iCurrentPage], iCurrentPage );
       
   491                 
       
   492                 // Redraw help text, since a new function should now be underlined.
       
   493                 DrawHelpText();
       
   494                 
       
   495                 // Notify subclass that softkey function has been updated.
       
   496                 SoftkeyFunctionUpdated();
       
   497                 break;
       
   498                 }
       
   499             case KOperation_PreviousOptionPage:
       
   500                 {
       
   501                 iCurrentPage = (iCurrentPage + iPageCount - 1) % iPageCount;
       
   502                 DrawHelpText();
       
   503                 SoftkeyFunctionUpdated();                
       
   504                 break;
       
   505                 }
       
   506             case KOperation_NextOptionPage:
       
   507                 {
       
   508                 iCurrentPage = (iCurrentPage + 1) % iPageCount;
       
   509                 DrawHelpText();
       
   510                 SoftkeyFunctionUpdated();                
       
   511                 break;
       
   512                 }
       
   513             case KOperation_ToggleHelpVisibility:    
       
   514                 {
       
   515                 // Toggle help text on/off.
       
   516                 iHelpActive = !iHelpActive;
       
   517                 iHelpWindow->SetVisible(iHelpActive);
       
   518                 break;
       
   519                 }
       
   520             case KOperation_ToggleHelpTransparency:
       
   521                 {
       
   522                 iHelpSemitransparentBackgroundActive = !iHelpSemitransparentBackgroundActive;
       
   523                 if( iHelpSemitransparentBackgroundActive )
       
   524                     {
       
   525                     // Turn on help if it is currently off.
       
   526                     iHelpActive = true;
       
   527                     iHelpWindow->SetVisible(true);
       
   528                     }
       
   529                 DrawHelpText();
       
   530                 break;            
       
   531                 }
       
   532             default:
       
   533                 {
       
   534                 // Pass operation to subclass.
       
   535                 TPtrC operatioName( KeyMapText(operationIndex, iCurrentPage) );
       
   536                 ExecuteOperation( operation, operatioName );                        
       
   537                 break;
       
   538                 }
       
   539             }    
       
   540         }        
       
   541     
       
   542     SetActive();
       
   543     iWs.EventReady( &iStatus );
       
   544     }            
       
   545 
       
   546 void CTestAppBase::DoCancel()
       
   547     {
       
   548     iWs.EventReadyCancel();
       
   549     }
       
   550 
       
   551 // TODO: ALLOW SUBCLASS TO SPECIFY COLOR SELECTIONS
       
   552 
       
   553 TInt CTestAppBase::SelectFromListL( TPoint aTopLeft,
       
   554                                     TSize aSize,
       
   555                                     const TDesC& aHeaderText, 
       
   556                                     RPointerArray<TDesC>& aSelectionList, 
       
   557                                     TInt aInitialSelectionIndex )
       
   558     {
       
   559     iSelectionWindow->SetExtent( aTopLeft, aSize );
       
   560     iSelectionWindow->SetVisible( true );
       
   561 
       
   562     const TInt KRowIncrement = iFontSize + 2;
       
   563     
       
   564     TInt entriesPerPage = aSize.iHeight / KRowIncrement - 4;
       
   565     
       
   566     TInt returnValue = -2;
       
   567     TInt startIndex = 0;
       
   568     TInt selected = aInitialSelectionIndex;     
       
   569     
       
   570     while( returnValue == -2 )
       
   571         {
       
   572         iGc->Activate(*iSelectionWindow);
       
   573     
       
   574         iSelectionWindow->Invalidate();
       
   575         iSelectionWindow->BeginRedraw();
       
   576     
       
   577         iGc->Reset();
       
   578         
       
   579         iGc->UseFont(iFont);                
       
   580         iGc->SetBrushColor(KRgbDarkBlue);
       
   581         
       
   582         iGc->Clear();
       
   583 
       
   584         // KRgbWhite seems to be having problems (0xffffff) in some emulators,
       
   585         // but 0xfefefe is working, so use that instead of white.        
       
   586         iGc->SetPenColor(0xfefefe);
       
   587 
       
   588         const TInt KHeaderColumn = 5;
       
   589         const TInt KEntryColumn = 15;
       
   590         
       
   591         TInt row = KRowIncrement;
       
   592 
       
   593         iGc->SetUnderlineStyle(EUnderlineOff);
       
   594 
       
   595         iGc->DrawText( aHeaderText, TPoint(KHeaderColumn, row) );
       
   596         row += (KRowIncrement + 5);
       
   597         
       
   598         TBool again = true;
       
   599         TInt backIndex = -1;
       
   600         TInt forwardIndex = -1;
       
   601         TInt offset = 0;
       
   602                     
       
   603         while( again )
       
   604             {
       
   605             if( selected == offset )
       
   606                 {
       
   607                 iGc->SetUnderlineStyle(EUnderlineOn);
       
   608                 }
       
   609             else
       
   610                 {
       
   611                 iGc->SetUnderlineStyle(EUnderlineOff);            
       
   612                 }
       
   613         
       
   614             if( (offset < entriesPerPage) && (startIndex+offset < aSelectionList.Count()) )
       
   615                 {
       
   616                 iGc->DrawText( *aSelectionList[startIndex+offset], TPoint(KEntryColumn, row) );
       
   617                 row += KRowIncrement;
       
   618 
       
   619                 offset++;
       
   620                 }
       
   621             else
       
   622                 {
       
   623                 again = false;
       
   624                 if( startIndex + offset < aSelectionList.Count() )
       
   625                     {
       
   626                     iGc->DrawText( _L("<page down>"), TPoint(KEntryColumn, row) );
       
   627                     row += KRowIncrement;
       
   628                     
       
   629                     forwardIndex = offset;
       
   630                     offset++;
       
   631                     }
       
   632                 if( startIndex > 0 )
       
   633                     {
       
   634                     if( selected == offset )
       
   635                         {
       
   636                         iGc->SetUnderlineStyle(EUnderlineOn);
       
   637                         }
       
   638                     else
       
   639                         {
       
   640                         iGc->SetUnderlineStyle(EUnderlineOff);            
       
   641                         }
       
   642                 
       
   643                     iGc->DrawText( _L("<page up>"), TPoint(KEntryColumn, row) );
       
   644                     row += KRowIncrement;
       
   645 
       
   646                     backIndex = offset;
       
   647                     offset++;
       
   648                     }
       
   649                 }
       
   650             }
       
   651         
       
   652         iSelectionWindow->EndRedraw();
       
   653        
       
   654         iGc->Deactivate();
       
   655 
       
   656         TInt keyCode = WaitForAnyKey();        
       
   657         
       
   658         switch( keyCode )
       
   659             {
       
   660             case EKeyUpArrow:
       
   661                 if( selected == 0 )
       
   662                     {
       
   663                     selected = offset-1;
       
   664                     }
       
   665                 else
       
   666                     {
       
   667                     selected -= 1;
       
   668                     }
       
   669                 break;
       
   670                 
       
   671             case EKeyDownArrow:
       
   672             case KLeftSoftKeyCode:                        
       
   673             case 'a':
       
   674             case 'A':
       
   675                 selected += 1;
       
   676                 if( selected == offset )
       
   677                     {
       
   678                     selected = 0;
       
   679                     }
       
   680                 break;
       
   681 
       
   682             case EKeyLeftArrow:
       
   683                 if( backIndex >= 0 )
       
   684                     {
       
   685                     startIndex -= entriesPerPage;
       
   686                     selected = 0;                        
       
   687                     }
       
   688                 else
       
   689                     {
       
   690                     returnValue = -1;
       
   691                     again = false;
       
   692                     }
       
   693                 break;
       
   694                 
       
   695             case EKeyRightArrow:
       
   696                 if( forwardIndex >= 0 )
       
   697                     {
       
   698                     startIndex += entriesPerPage;
       
   699                     selected = 0;                    
       
   700                     }
       
   701                 break;
       
   702 
       
   703             case EKeyEnter:
       
   704             case KRightSoftKeyCode:                        
       
   705             case 'b':
       
   706             case 'B':
       
   707                 if( selected == forwardIndex )
       
   708                     {
       
   709                     startIndex += entriesPerPage;
       
   710                     selected = 0;                    
       
   711                     }
       
   712                 else if( selected == backIndex )
       
   713                     {
       
   714                     startIndex -= entriesPerPage;
       
   715                     selected = 0;
       
   716                     }
       
   717                 else
       
   718                     {
       
   719                     returnValue = startIndex+selected;
       
   720                     }
       
   721                 break;
       
   722             }
       
   723         }
       
   724 
       
   725     iSelectionWindow->SetVisible( false );
       
   726     
       
   727     return returnValue;        
       
   728     }
       
   729 
       
   730 TInt CTestAppBase::SelectFromListL( TPoint aTopLeft,
       
   731                                     TSize aSize,
       
   732                                     const TDesC& aHeaderText, 
       
   733                                     RPointerArray<HBufC>& aSelectionList, 
       
   734                                     TInt aInitialSelectionIndex )
       
   735     {
       
   736     RPointerArray<TDesC> aSelectionList2;
       
   737     
       
   738     for( TInt index = 0; index < aSelectionList.Count(); index++ )
       
   739         {
       
   740         aSelectionList2.Append( aSelectionList[index]);
       
   741         }
       
   742     
       
   743     TInt returnValue = SelectFromListL( aTopLeft, aSize, aHeaderText, aSelectionList2, aInitialSelectionIndex );
       
   744     
       
   745     aSelectionList2.Close();
       
   746     
       
   747     return returnValue;
       
   748     }
       
   749 
       
   750 void CTestAppBase::BuildDriveListL( RPointerArray<HBufC>& aDrives )
       
   751     {
       
   752     TDriveList driveList;
       
   753     TInt err = iFs.DriveList( driveList );
       
   754     
       
   755     for( TInt index = 0; index < driveList.Length(); index++ )
       
   756         {
       
   757         if( driveList[index] != 0 )
       
   758             {
       
   759             HBufC* drive = HBufC::NewL( 2 );
       
   760             drive->Des().Format( _L("%c:"), 'A' + index);
       
   761             aDrives.Append( drive );
       
   762             }
       
   763         }
       
   764     }
       
   765 
       
   766 bool CTestAppBase::SelectDriveL( TPoint aTopLeft,
       
   767                                  TSize aWindowSize,
       
   768                                  const TDesC& aHeaderText, 
       
   769                                  TDes& aDrive )
       
   770     {
       
   771     RPointerArray<HBufC> drives;
       
   772     BuildDriveListL( drives );
       
   773     
       
   774     TInt index = SelectFromListL( aTopLeft, aWindowSize, aHeaderText, drives );
       
   775     
       
   776     bool returnValue = false;
       
   777     
       
   778     if( index >= 0 )
       
   779         {
       
   780         returnValue = true;
       
   781         aDrive.Copy( *(drives[index]) );
       
   782         aDrive.Append( _L("\\") );
       
   783         }
       
   784     
       
   785     drives.ResetAndDestroy();
       
   786     
       
   787     return returnValue;
       
   788     }
       
   789 
       
   790 bool CTestAppBase::SelectFileL( TPoint aTopLeft,
       
   791                                 TSize aWindowSize,
       
   792                                 const TDesC& aHeaderText, 
       
   793                                 const TDesC& aDrive, 
       
   794                                 TDes& aFullFilename )
       
   795     {
       
   796     TFileName directory;
       
   797     
       
   798     DoSelectFileL( aTopLeft, aWindowSize, aHeaderText, aDrive, 0, directory, aFullFilename );
       
   799     
       
   800     aFullFilename.Insert( 0, directory );
       
   801     
       
   802     return aFullFilename.Length() > 0;
       
   803     }
       
   804 
       
   805 bool CTestAppBase::SelectFileWithHistoryL( TPoint aTopLeft,
       
   806                                            TSize aSize,
       
   807                                            TDes& aFullFilename,
       
   808                                            const TDesC& aHistoryFilename,
       
   809                                            TInt aMaxHistoryEntries,
       
   810                                            const TDesC& aPrompt )
       
   811     {
       
   812     RPointerArray<HBufC> drives;
       
   813     BuildDriveListL( drives );
       
   814         
       
   815     RPointerArray<TDesC> selections;
       
   816 
       
   817     for( TInt index = 0; index < drives.Count(); index++ )
       
   818         {
       
   819         selections.Append( drives[index]);
       
   820         }
       
   821     TInt drivesBaseIndex = 0;
       
   822         
       
   823     // Add file history to the end of the drive list.  Newest files are last, so add in reverse order.
       
   824     // For convenience, add the last history entry at the top, before the drive list.
       
   825     ReadFileHistory( aHistoryFilename );
       
   826     if( iFileHistory.Count() > 0 )
       
   827         {
       
   828         selections.Insert( iFileHistory[iFileHistory.Count()-1], 0 );        
       
   829         drivesBaseIndex++;
       
   830         }
       
   831     for(TInt index = iFileHistory.Count()-2; index >= 0; index-- )
       
   832         {        
       
   833         selections.Append( iFileHistory[index]);
       
   834         }
       
   835 
       
   836     bool done = false;
       
   837     bool selected = true;
       
   838     
       
   839     while( !done )
       
   840         {
       
   841         TInt index = SelectFromListL( aTopLeft, aSize, aPrompt, selections );
       
   842 
       
   843         if( index < 0 )
       
   844             {
       
   845             selected = false;
       
   846             done = true;
       
   847             }        
       
   848         else if( (index >= drivesBaseIndex) && (index - drivesBaseIndex < drives.Count()) )
       
   849             {
       
   850             TBuf<10> drive;
       
   851             drive.Copy( *(selections[index]) );
       
   852             drive.Append( _L("\\") );
       
   853             
       
   854             done = SelectFileL( aTopLeft, aSize, aPrompt, drive, aFullFilename );        
       
   855             }
       
   856         else
       
   857             {    
       
   858             // Remove the selected file from the history, so that it will pop up to the top of the list
       
   859             // as the most recently selected file.
       
   860             TInt historyIndex;
       
   861             if( index == 0 )
       
   862                 {
       
   863                 historyIndex = iFileHistory.Count() - 1;
       
   864                 }
       
   865             else
       
   866                 {
       
   867                 historyIndex = iFileHistory.Count() - index + drives.Count() - 1;
       
   868                 }
       
   869             aFullFilename.Copy( *(selections[index]) );
       
   870             delete iFileHistory[historyIndex];
       
   871             iFileHistory.Remove( historyIndex );            
       
   872 
       
   873             done = true;
       
   874             }
       
   875         }
       
   876     
       
   877     if( selected )
       
   878         {
       
   879         AddToFileHistory( aFullFilename, aHistoryFilename, aMaxHistoryEntries );        
       
   880         }
       
   881     
       
   882     selections.Reset();
       
   883     drives.ResetAndDestroy();
       
   884     
       
   885     return selected;
       
   886     }
       
   887 
       
   888 bool CTestAppBase::SelectIntegerL( TPoint aTopLeft,
       
   889                                    TSize aSize,
       
   890                                    const TDesC& aHeaderText,
       
   891                                    TInt aMin,
       
   892                                    TInt aMax,
       
   893                                    TInt& aSelection )
       
   894     {
       
   895     // currently no way to exit out of this selection
       
   896     
       
   897     iSelectionWindow->SetExtent( aTopLeft, aSize );
       
   898     iSelectionWindow->SetVisible( true );
       
   899 
       
   900     bool done = false;
       
   901     
       
   902     while( !done )
       
   903         {
       
   904         iGc->Activate(*iSelectionWindow);
       
   905     
       
   906         iSelectionWindow->Invalidate();
       
   907         iSelectionWindow->BeginRedraw();
       
   908     
       
   909         iGc->Reset();
       
   910         
       
   911         iGc->UseFont(iFont);                
       
   912         iGc->SetBrushColor(KRgbDarkBlue);
       
   913         
       
   914         iGc->Clear();
       
   915 
       
   916         // KRgbWhite seems to be having problems (0xffffff) in some emulators,
       
   917         // but 0xfefefe is working, so use that instead of white.        
       
   918         iGc->SetPenColor(0xfefefe);
       
   919 
       
   920         TBuf<120> buffer;
       
   921         buffer.Copy( aHeaderText );        
       
   922         buffer.AppendFormat( _L(" %i"), aSelection );
       
   923         
       
   924         iGc->DrawText( buffer, TPoint(5, iFontSize+2) );
       
   925 
       
   926         iSelectionWindow->EndRedraw();
       
   927        
       
   928         iGc->Deactivate();
       
   929 
       
   930         TInt keyCode = WaitForAnyKey();
       
   931         
       
   932         switch( keyCode )
       
   933             {
       
   934             case EKeyUpArrow:
       
   935                 aSelection -= 10;
       
   936                 break;
       
   937                 
       
   938             case EKeyDownArrow:
       
   939             case KLeftSoftKeyCode:                        
       
   940             case 'a':
       
   941             case 'A':
       
   942                 aSelection += 10;
       
   943                 break;
       
   944 
       
   945             case EKeyLeftArrow:
       
   946                 aSelection--;
       
   947                 break;
       
   948                 
       
   949             case EKeyRightArrow:
       
   950                 aSelection++;
       
   951                 break;
       
   952 
       
   953             case EKeyEnter:
       
   954             case KRightSoftKeyCode:                        
       
   955             case 'b':
       
   956             case 'B':
       
   957                 done = true;
       
   958                 break;
       
   959             }
       
   960         
       
   961         if( aSelection > aMax )
       
   962             {
       
   963             aSelection = aMin;
       
   964             }
       
   965         else if( aSelection < aMin )
       
   966             {
       
   967             aSelection = aMax;
       
   968             }        
       
   969         }
       
   970 
       
   971     iSelectionWindow->SetVisible( false );
       
   972     
       
   973     return true;
       
   974     }
       
   975 
       
   976 TInt CTestAppBase::WaitForAnyKey()
       
   977     {
       
   978     TInt returnValue = 0;
       
   979     
       
   980     bool done = false;
       
   981     
       
   982     while( !done )
       
   983         {        
       
   984         // Have to use this tricky nested active scheduler technique to allow the active object
       
   985         // used to remap volume keys to run.
       
   986         SetActive();
       
   987         iWs.EventReady( &iStatus );
       
   988         iWait.Start();
       
   989     
       
   990         TWsEvent event;
       
   991         iWs.GetEvent(event);
       
   992     
       
   993         // Other potentially useful events are EEventKeyUp and EEventKeyDown.
       
   994         
       
   995         if( event.Type() == EEventKey )
       
   996             {
       
   997             done = true;
       
   998             returnValue = event.Key()->iCode;
       
   999             }
       
  1000         else if( event.Type() == EEventPointer )
       
  1001             {
       
  1002             TAdvancedPointerEvent* p = event.Pointer();
       
  1003 
       
  1004             TTestAppPointerEvent pointerEvent = CharacterizePointerEvent( *p );
       
  1005 
       
  1006             switch( pointerEvent )
       
  1007                 {
       
  1008                 case EPointerEvent_None:
       
  1009                     // Do nothing.
       
  1010                     break;
       
  1011                 case EPointerEvent_Up:
       
  1012                     returnValue = EKeyUpArrow;
       
  1013                     done = true;
       
  1014                     break;
       
  1015                 case EPointerEvent_Down:
       
  1016                     returnValue = EKeyDownArrow;
       
  1017                     done = true;
       
  1018                     break;
       
  1019                 case EPointerEvent_Left:
       
  1020                     returnValue = EKeyLeftArrow;
       
  1021                     done = true;
       
  1022                     break;
       
  1023                 case EPointerEvent_Right:
       
  1024                     returnValue = EKeyRightArrow;
       
  1025                     done = true;
       
  1026                     break;
       
  1027                 case EPointerEvent_Select:
       
  1028                     returnValue = EKeyEnter;
       
  1029                     done = true;
       
  1030                     break;
       
  1031                 }
       
  1032             }        
       
  1033         }
       
  1034     
       
  1035     return returnValue;
       
  1036     }
       
  1037 
       
  1038 TInt CTestAppBase::ReadFile( const TDesC& aFilename, RPointerArray<HBufC>& aContents )
       
  1039     {
       
  1040     RFile inputFile;
       
  1041     TInt err = inputFile.Open(iFs, aFilename, EFileShareReadersOnly | EFileStream | EFileRead );
       
  1042     
       
  1043     if( err == KErrNone )
       
  1044         {
       
  1045         TInt fileSize;
       
  1046         inputFile.Size( fileSize );
       
  1047         
       
  1048         RBuf8 contents;
       
  1049         contents.Create( fileSize );
       
  1050 
       
  1051         inputFile.Read( contents, fileSize );
       
  1052 
       
  1053         inputFile.Close();
       
  1054 
       
  1055         TPtrC8 remaining( contents );
       
  1056         
       
  1057         while( remaining.Length() > 0 )
       
  1058             {
       
  1059             // Removing leading CR/LFs, if any.
       
  1060             while( remaining.Length() > 0 && (remaining[0] == '\n' || remaining[0] == '\r') )
       
  1061                 {
       
  1062                 remaining.Set(remaining.Right(remaining.Length()-1));            
       
  1063                 }
       
  1064 
       
  1065             if( remaining.Length() == 0 )
       
  1066                 {
       
  1067                 break;
       
  1068                 }
       
  1069 
       
  1070             // Find next CR/LF, or end of string.
       
  1071             TInt separatorIndex = 1;
       
  1072             while( (separatorIndex < remaining.Length()) && 
       
  1073                    (remaining[separatorIndex] != '\n') &&
       
  1074                    (remaining[separatorIndex] != '\r'))
       
  1075                 {
       
  1076                 separatorIndex++;
       
  1077                 }
       
  1078                         
       
  1079             HBufC* line = HBufC::NewL( separatorIndex );
       
  1080             TPtrC8 line8 = remaining.Left( separatorIndex );
       
  1081             line->Des().Copy( line8 );
       
  1082         
       
  1083             aContents.Append( line );
       
  1084 
       
  1085             TInt remainingLength = remaining.Length() - separatorIndex;            
       
  1086 
       
  1087             remaining.Set(remaining.Right(remainingLength));            
       
  1088             }        
       
  1089         
       
  1090         contents.Close();
       
  1091         }
       
  1092     
       
  1093     return err;
       
  1094     }
       
  1095 
       
  1096 void CTestAppBase::ReadFileHistory( const TDesC& aHistoryFilename )
       
  1097     {
       
  1098     iFileHistory.ResetAndDestroy();
       
  1099     
       
  1100     ReadFile( aHistoryFilename, iFileHistory );
       
  1101     }
       
  1102 
       
  1103 void CTestAppBase::AddToFileHistory( const TDesC& aFilename, const TDesC& aHistoryFilename, TInt aMaxHistoryEntries )
       
  1104     {
       
  1105     HBufC* filename = HBufC::NewL( aFilename.Length() );
       
  1106     filename->Des().Copy( aFilename );
       
  1107     iFileHistory.Append( filename );
       
  1108 
       
  1109     while( iFileHistory.Count() > aMaxHistoryEntries )
       
  1110         {
       
  1111         delete iFileHistory[0];
       
  1112         iFileHistory.Remove( 0 );
       
  1113         }    
       
  1114     
       
  1115     RFile historyFile;
       
  1116     TInt err = historyFile.Create(iFs, aHistoryFilename, EFileStream | EFileWrite );    
       
  1117     if( err == KErrAlreadyExists )
       
  1118         {
       
  1119         err = historyFile.Open(iFs, aHistoryFilename, EFileStream | EFileWrite );
       
  1120         historyFile.SetSize(0);
       
  1121         }
       
  1122     
       
  1123     if( err == KErrNone )
       
  1124         {
       
  1125         for( TInt index = 0; index < iFileHistory.Count(); index++ )
       
  1126             {
       
  1127             TBuf8<KMaxFileName> filename8;
       
  1128             filename8.Copy( iFileHistory[index]->Des() );
       
  1129             historyFile.Write( filename8 );
       
  1130             historyFile.Write( _L8("\n") );
       
  1131             }
       
  1132         }
       
  1133     
       
  1134     historyFile.Close();    
       
  1135     }
       
  1136 
       
  1137 void CTestAppBase::DoSelectFileL( TPoint aTopRight,
       
  1138                                   TSize aWindowSize,
       
  1139                                   const TDesC& aHeaderText, 
       
  1140                                   const TFileName& aDirectory, 
       
  1141                                   TInt aDirectoryLevel, 
       
  1142                                   TDes& aSelectedDirectory, 
       
  1143                                   TDes& aSelectedFilename )     
       
  1144     {
       
  1145     RPointerArray<TDesC> fileNames;
       
  1146     
       
  1147     ReadDirectoryEntriesL( aDirectory, fileNames );
       
  1148 
       
  1149     TInt initialSelectionIndex = 0;
       
  1150     
       
  1151     _LIT( KUp, ".." );        
       
  1152     if( aDirectoryLevel > 0 )
       
  1153         {
       
  1154         TFileName* newEntry = new(ELeave) TFileName;
       
  1155         newEntry->Copy( KUp );            
       
  1156         fileNames.Insert( newEntry, 0 );
       
  1157         initialSelectionIndex++;
       
  1158         }
       
  1159     
       
  1160     bool done = false;    
       
  1161     
       
  1162     while( !done && (aSelectedFilename.Length() == 0) )
       
  1163         {
       
  1164         TInt index = SelectFromListL( aTopRight, aWindowSize, aHeaderText, fileNames, initialSelectionIndex );
       
  1165 
       
  1166         if( index < 0 || index >= fileNames.Count() )
       
  1167             {
       
  1168             done = true;
       
  1169             }
       
  1170         else if( fileNames[index]->Compare(KUp) == 0 )
       
  1171             {
       
  1172             // Go up one directory.  Return to caller without setting aFilename
       
  1173             break;
       
  1174             }
       
  1175         else if( (*fileNames[index])[fileNames[index]->Length()-1] == '\\' )
       
  1176             {
       
  1177             // Directory selected.
       
  1178             TFileName directory;
       
  1179             directory.Copy( aDirectory );
       
  1180             directory.Append( *fileNames[index] );
       
  1181             DoSelectFileL( aTopRight, aWindowSize, aHeaderText, directory, aDirectoryLevel+1, aSelectedDirectory, aSelectedFilename );
       
  1182             }
       
  1183         else
       
  1184             {
       
  1185             // File selected.                            
       
  1186             aSelectedDirectory.Copy( aDirectory );
       
  1187             aSelectedFilename.Copy( *fileNames[index] );
       
  1188             done = true;
       
  1189             }
       
  1190         
       
  1191         }
       
  1192 
       
  1193     fileNames.ResetAndDestroy();
       
  1194     }
       
  1195 
       
  1196 void CTestAppBase::ReadDirectoryEntriesL( const TFileName& aDirectoryName, RPointerArray<TDesC>& aFileNames )
       
  1197     {
       
  1198     aFileNames.ResetAndDestroy();
       
  1199     
       
  1200     RDir dir;
       
  1201     User::LeaveIfError( dir.Open( iFs, aDirectoryName, KEntryAttNormal|KEntryAttDir) );
       
  1202     
       
  1203     TEntryArray entries;
       
  1204     TInt err = KErrNone;
       
  1205     TInt directoryCount = 0;
       
  1206     while( err == KErrNone )
       
  1207         {
       
  1208         err = dir.Read( entries );
       
  1209                 
       
  1210         for( TInt index = 0; index < entries.Count(); index++ )
       
  1211             {
       
  1212             // It was observed that not all devices sorted the list by default, so do an
       
  1213             // insertion sort here.            
       
  1214             TFileName* newEntry = new(ELeave) TFileName;
       
  1215             newEntry->Copy( entries[index].iName );
       
  1216             
       
  1217             // Put the directories first in the list.
       
  1218             if( entries[index].IsDir())
       
  1219                 {
       
  1220                 newEntry->Append( _L("\\") );
       
  1221                 
       
  1222                 TInt insertionIndex = 0;
       
  1223                 while( insertionIndex < directoryCount && newEntry->CompareF(*aFileNames[insertionIndex]) > 0 )
       
  1224                     {
       
  1225                     insertionIndex++;
       
  1226                     }
       
  1227                 aFileNames.Insert( newEntry, insertionIndex );
       
  1228                 
       
  1229                 directoryCount++;
       
  1230                 }
       
  1231             else
       
  1232                 {
       
  1233                 TInt insertionIndex = directoryCount;
       
  1234                 while( insertionIndex < aFileNames.Count() && newEntry->CompareF(*aFileNames[insertionIndex]) > 0 )
       
  1235                     {
       
  1236                     insertionIndex++;
       
  1237                     }
       
  1238                 aFileNames.Insert( newEntry, insertionIndex );
       
  1239                 }
       
  1240             }        
       
  1241         }      
       
  1242     
       
  1243     dir.Close();
       
  1244     }
       
  1245 
       
  1246 void CTestAppBase::DrawHelpText()
       
  1247     {
       
  1248     iGc->Activate(*iHelpWindow);
       
  1249 
       
  1250     iHelpWindow->Invalidate();
       
  1251     iHelpWindow->BeginRedraw();
       
  1252 
       
  1253     iGc->Reset();
       
  1254     
       
  1255     iGc->UseFont(iFont);                
       
  1256     iGc->SetBrushColor(KRgbTransparent);
       
  1257     
       
  1258     iGc->Clear();
       
  1259 
       
  1260     if( iHelpSemitransparentBackgroundActive )
       
  1261         {
       
  1262         iGc->SetPenColor(KRgbTransparent);
       
  1263         iGc->SetBrushStyle(CWindowGc::ESolidBrush);
       
  1264         iGc->SetBrushColor( TRgb(0x7f7f7faf) );
       
  1265         iGc->DrawRect( TRect(iHelpWindowSize) );
       
  1266         }
       
  1267 
       
  1268     // KRgbWhite seems to be having problems (0xffffff) in some emulators,
       
  1269     // but 0xfefefe is working, so use that instead of white.        
       
  1270     iGc->SetPenColor(0xfefefe);
       
  1271 
       
  1272     const TInt KColumn1 = KHelpWindowBorderPixels;
       
  1273     const TInt KColumn2 = KColumn1 + iHelpWindowColumn1Width + KHelpWindowSpaceBetweenColumns;
       
  1274     const TInt KRowIncrement = iFontSize + KHelpWindowSpaceBetweenRows;
       
  1275     
       
  1276     TInt row = iFontSize + KHelpWindowBorderPixels;
       
  1277 
       
  1278     for( TInt index = 0; index < KSupportedKeysCount; index++ )
       
  1279         {
       
  1280         iGc->SetUnderlineStyle(EUnderlineOff);        
       
  1281     
       
  1282         TPtrC text = KeyMapText( index, iCurrentPage ); 
       
  1283 
       
  1284         iGc->DrawText( KeyName(index), TPoint(KColumn1, row) );
       
  1285 
       
  1286         if( index == iSoftkeyIndices[iCurrentPage] )
       
  1287             {
       
  1288             iGc->SetUnderlineStyle(EUnderlineOn);
       
  1289             }
       
  1290         else
       
  1291             {
       
  1292             iGc->SetUnderlineStyle(EUnderlineOff);        
       
  1293             }
       
  1294 
       
  1295         iGc->DrawText( text, TPoint(KColumn2, row) );
       
  1296         
       
  1297         row += KRowIncrement;
       
  1298         }
       
  1299 
       
  1300     iHelpWindow->EndRedraw();
       
  1301    
       
  1302     iGc->Deactivate();
       
  1303     }
       
  1304 
       
  1305 void CTestAppBase::MrccatoCommand( TRemConCoreApiOperationId aOperationId,
       
  1306                                    TRemConCoreApiButtonAction /*aButtonAct*/ )
       
  1307     {
       
  1308     // Treat volume up like the right soft key, and volume down like the left soft key.
       
  1309     TKeyEvent keyEvent;
       
  1310     keyEvent.iCode = 0;
       
  1311     keyEvent.iScanCode = 0;
       
  1312     keyEvent.iModifiers = 0;
       
  1313     keyEvent.iRepeats = 0;
       
  1314     
       
  1315     switch (aOperationId)
       
  1316         {
       
  1317         case ERemConCoreApiVolumeUp:
       
  1318             keyEvent.iCode = KRightSoftKeyCode;
       
  1319             iWs.SimulateKeyEvent(keyEvent);
       
  1320             iWs.Flush();
       
  1321             break;
       
  1322         case ERemConCoreApiVolumeDown:
       
  1323             keyEvent.iCode = KLeftSoftKeyCode;
       
  1324             iWs.SimulateKeyEvent(keyEvent);
       
  1325             iWs.Flush();
       
  1326             break;
       
  1327         default:
       
  1328             break;
       
  1329         }
       
  1330     }