voiceui/voiceuivoicerecognition/src/vuicnbestlistdialog.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2004-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:  Implementation of CNBestListDialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <featmgr.h>
       
    21 
       
    22 #include <aknPopup.h>
       
    23 #include <data_caging_path_literals.hrh>
       
    24 
       
    25 #include <AknIconArray.h>
       
    26 
       
    27 #include <AknMediatorFacade.h>
       
    28 
       
    29 #include <secondarydisplay/vuisecondarydisplayapi.h>
       
    30 #include <SecondaryDisplay/AknSecondaryDisplayDefs.h>
       
    31 
       
    32 #include <vuivoicerecognition.rsg>
       
    33 #include <vuivoicerecogdefs.h>
       
    34 
       
    35 #include "vuivoicerecognition.hrh"
       
    36 
       
    37 #include "vuiclistquerydialog.h"
       
    38 #include "vuicnbestlistdialog.h"
       
    39 
       
    40 #include "vuimkeycallback.h"
       
    41 
       
    42 #include "vuivoiceicondefs.h"
       
    43 
       
    44 #include "rubydebug.h"
       
    45 
       
    46 // ================= MEMBER FUNCTIONS =======================
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CNBestListDialog::CNBestListDialog
       
    50 // C++ default constructor can NOT contain any code, that
       
    51 // might leave.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CNBestListDialog::CNBestListDialog() 
       
    55  : iCurrentIndex( 0 ), iTagCount( 0 ),
       
    56    iCba( R_SOFTKEYS_SELECT_QUIT__SELECT )
       
    57     {
       
    58     }
       
    59 
       
    60 
       
    61 // Destructor
       
    62 CNBestListDialog::~CNBestListDialog()
       
    63     {
       
    64     RUBY_DEBUG0( "CNBestListDialog::~CNBestListDialog START" );
       
    65      
       
    66     RegisterForKeyCallback( NULL );
       
    67     
       
    68     delete iDialog;
       
    69     iDialog = NULL;
       
    70     
       
    71     iEikonEnv->EikAppUi()->RemoveFromStack( this );
       
    72         
       
    73     RUBY_DEBUG0( "CNBestListDialog::~CNBestListDialog EXIT" );          
       
    74     }
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CNBestListDialog::ConstructL
       
    79 // Symbian 2nd phase constructor can leave.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CNBestListDialog::ConstructL()
       
    83     {
       
    84     RUBY_DEBUG_BLOCK( "CNBestListDialog::ConstructL" );
       
    85       
       
    86     iEikonEnv->EikAppUi()->AddToStackL( this, ECoeStackPriorityAlert );
       
    87     }
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // CNBestListDialog::NewL
       
    92 // Two-phased constructor.
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 CNBestListDialog* CNBestListDialog::NewL()                                                           
       
    96     {
       
    97     CNBestListDialog* self = new (ELeave) CNBestListDialog();
       
    98     CleanupStack::PushL(self);
       
    99     self->ConstructL();
       
   100     CleanupStack::Pop( self );
       
   101     return self;
       
   102     }
       
   103     
       
   104 // -----------------------------------------------------------------------------
       
   105 // CNBestListDialog::RegisterForKeyCallback
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CNBestListDialog::RegisterForKeyCallback( MKeyCallback* aKeyCallback )
       
   109     {
       
   110     iKeyCallback = aKeyCallback;
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------
       
   114 // TKeyResponse CNBestListDialog::OfferKeyEventL
       
   115 // ---------------------------------------------------------
       
   116 //
       
   117 TKeyResponse CNBestListDialog::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode /*aType*/ )
       
   118     {
       
   119     RUBY_DEBUG_BLOCK( "CNBestListDialog::OfferKeyEventL" );
       
   120 
       
   121     TKeyResponse keyStatus = EKeyWasNotConsumed;
       
   122 
       
   123     TInt event = ConvertKeyEventL( aKeyEvent );
       
   124     
       
   125     // Check if event should be ignored
       
   126     if ( iDialog && iDialog->IsMenuVisible() )
       
   127         {
       
   128         switch( event )
       
   129             {
       
   130             case EVoiceTagSoftKeyQuit:
       
   131                 {
       
   132                 break;
       
   133                 }
       
   134             
       
   135             default:
       
   136                 {
       
   137                 event = ENoKeypress;
       
   138                 break;
       
   139                 }
       
   140             }
       
   141         }
       
   142 
       
   143     if ( event != ENoKeypress )
       
   144         {
       
   145         switch( event )
       
   146             {
       
   147             case ESelectKeypress:
       
   148             case EDirectSelectKeypress:
       
   149                 {                   
       
   150                 keyStatus = EKeyWasConsumed;
       
   151                 break;
       
   152                 }
       
   153             
       
   154             case EUpKeypress:
       
   155                 {
       
   156                 --iCurrentIndex;
       
   157                 if ( iCurrentIndex <= -1 )
       
   158                     {
       
   159                     iCurrentIndex = iTagCount - 1;    
       
   160                     }
       
   161                 break;
       
   162                 }
       
   163                         
       
   164             case EDownKeypress:
       
   165                 {
       
   166                 ++iCurrentIndex;
       
   167                 if ( iCurrentIndex >= iTagCount )
       
   168                     {
       
   169                     iCurrentIndex = 0;
       
   170                     }
       
   171                 break;
       
   172                 }
       
   173                
       
   174             case EVoiceTagSoftKeyQuit:
       
   175                 {
       
   176                 iEikonEnv->EikAppUi()->RemoveFromStack( this );
       
   177                 break;
       
   178                 }
       
   179                                         
       
   180             default:
       
   181                 break;            
       
   182             }
       
   183          
       
   184          if ( iKeyCallback )
       
   185              {
       
   186              iKeyCallback->HandleKeypressL( event );
       
   187              }
       
   188          }
       
   189          
       
   190     return keyStatus;
       
   191     }
       
   192     
       
   193 // ---------------------------------------------------------
       
   194 // CNBestListDialog::ProcessCommandL
       
   195 // ---------------------------------------------------------
       
   196 //      
       
   197 void CNBestListDialog::ProcessCommandL( TInt aCommandId )
       
   198     {
       
   199     RUBY_DEBUG_BLOCK( "CNBestListDialog::ProcessCommandL" );
       
   200     
       
   201     TInt event = KErrNone;
       
   202     
       
   203     if ( aCommandId == EVoiceTagSoftKeySelect )
       
   204         {
       
   205         event = ESelectKeypress;
       
   206         }
       
   207     else if ( aCommandId == EVoiceTagSoftKeyOpen )
       
   208         {
       
   209         event = EOpenKeypress;
       
   210         }
       
   211     else if ( aCommandId == EVoiceTagSoftKeyQuit )
       
   212         {
       
   213         event = EVoiceTagSoftKeyQuit;
       
   214         }
       
   215     else if ( aCommandId == EAknSoftkeyOptions )
       
   216         {
       
   217         event = EOptionsKeypress;
       
   218         }
       
   219     else if ( aCommandId == EDragKeypress )
       
   220         {
       
   221         event = EDragKeypress;
       
   222         
       
   223         // Don't forward keypress if current index hasn't changed
       
   224         if ( iCurrentIndex == iDialog->ListBox()->CurrentItemIndex() )
       
   225             {
       
   226             return;
       
   227             }
       
   228 
       
   229         iCurrentIndex = iDialog->ListBox()->CurrentItemIndex();
       
   230         }
       
   231     else if ( aCommandId == EScrollKeypress )
       
   232         {
       
   233         event = EScrollKeypress;
       
   234         }
       
   235                     
       
   236     iKeyCallback->HandleKeypressL( event );
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CNBestListDialog::MediatorCommandL
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 TAknDialogMediatorObserverCommand CNBestListDialog::MediatorCommandL( TUid /*aDomain*/, 
       
   244                                                                       TUid aCategory, 
       
   245                                                                       TInt aCommandId, 
       
   246                                                                       const TDesC8& aData )
       
   247     { 
       
   248     RUBY_DEBUG_BLOCK( "CNBestListDialog::MediatorCommandL" );
       
   249     
       
   250     TAknDialogMediatorObserverCommand retValue = EHandleAsNormal;
       
   251     
       
   252     if ( aCategory == SecondaryDisplay::KCatVoiceUi && 
       
   253          aCommandId == SecondaryDisplay::ECmdShowNBestListQuery )
       
   254         {
       
   255         if ( aData.Length() == sizeof( SAknDialogFeedback ) ) 
       
   256             {
       
   257             const SAknDialogFeedback& params = 
       
   258                 reinterpret_cast<const SAknDialogFeedback&>( *( aData.Ptr() ) );
       
   259             
       
   260             if ( params.iKey.iCode == EKeyCBA1 )
       
   261                 {
       
   262                 // LSK should select current selection
       
   263                 iKeyCallback->HandleKeypressL( ESelectKeypress );
       
   264                 
       
   265                 retValue = EDoNothingWithThisCommand;
       
   266                 }
       
   267             }
       
   268         else
       
   269             {
       
   270             SAknIntegerUpdate* params = (SAknIntegerUpdate*) &aData;
       
   271         
       
   272             if ( params->iCmd == EAknListQueryUpdateSelection )
       
   273                 {
       
   274                 iCurrentIndex = params->iId;
       
   275                 iDialog->ListControl()->Listbox()->SetCurrentItemIndexAndDraw( iCurrentIndex );
       
   276 
       
   277                 // Just send EUpKeypress or EDownKeypress event to notify that selection
       
   278                 // has changed
       
   279                 iKeyCallback->HandleKeypressL( EDownKeypress );
       
   280                 }
       
   281             }
       
   282         }
       
   283     return retValue; 
       
   284     } 
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 // CNBestListDialog::NotifyMediatorExit
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 void CNBestListDialog::NotifyMediatorExit() 
       
   291     { 
       
   292     RUBY_DEBUG0( "CNBestListDialog::NotifyMediatorExit" );
       
   293     // Do nothing
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CNBestListDialog::CreateNBestListPopupLC
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 void CNBestListDialog::CreateNBestListPopupLC( CDesC16ArrayFlat* aItems,
       
   301                                                const TDesC& aHeader )
       
   302     {
       
   303     RUBY_DEBUG0( "CNBestListDialog::ShowNBestListPopupLC START" );
       
   304        
       
   305     iDialog = CListQueryDialog::NewL( &iCurrentIndex, &iDialog, this, R_NBEST_OPTIONS_MENU );
       
   306     iDialog->PrepareLC( R_NBEST_POPUP_LIST );
       
   307     
       
   308     if ( aHeader != KNullDesC )
       
   309         {
       
   310         iDialog->QueryHeading()->SetTextL( aHeader );
       
   311         }
       
   312 
       
   313     iDialog->SetOwnershipType( ELbmOwnsItemArray );
       
   314     iDialog->SetItemTextArray( aItems );
       
   315     
       
   316     iDialog->ListControl()->Listbox()->ItemDrawer()->FormattedCellData()->EnableMarqueeL( ETrue );
       
   317         
       
   318     iTagCount = aItems->Count();
       
   319     
       
   320     CreateAndSetSecondaryDisplayDataL( aItems );
       
   321         
       
   322     // Create icon array
       
   323     CArrayPtr<CGulIcon>* icons = CreateIconArrayL();    
       
   324     iDialog->SetIconArrayL( icons );
       
   325     
       
   326     RUBY_DEBUG0( "CNBestListDialog::ShowNBestListPopupLC EXIT" );
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // CNBestListDialog::ShowNBestListPopupL
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 TInt CNBestListDialog::ShowNBestListPopupL()
       
   334     {
       
   335     RUBY_DEBUG0( "CNBestListDialog::ShowNBestListPopupL START" );
       
   336 
       
   337     // Show N-Best List
       
   338     TInt returnValue = iDialog->RunLD();
       
   339     
       
   340     // Touch selection returns EAknSoftkeyOk
       
   341     if ( returnValue == EAknSoftkeyOk )
       
   342         {
       
   343         returnValue = EVoiceTagSoftKeySelect;
       
   344         }
       
   345             
       
   346     RUBY_DEBUG0( "CNBestListDialog::ShowNBestListPopupL EXIT" );
       
   347 
       
   348     return returnValue;
       
   349     }
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 // CNBestListDialog::SetSoftkeys
       
   353 // -----------------------------------------------------------------------------
       
   354 //    
       
   355 void CNBestListDialog::SetSoftkeysL( TInt aResourceId )
       
   356     {
       
   357     RUBY_DEBUG_BLOCK( "CNBestListDialog::SetSoftkeysL" );
       
   358     
       
   359     iCba = aResourceId;
       
   360     
       
   361     // Set softkey labels
       
   362     CEikButtonGroupContainer* cba = &iDialog->ButtonGroupContainer();
       
   363     cba->SetCommandSetL( aResourceId );
       
   364     cba->DrawDeferred();
       
   365     }
       
   366     
       
   367 // -----------------------------------------------------------------------------
       
   368 // CNBestListDialog::SetCommandsHidden
       
   369 // -----------------------------------------------------------------------------
       
   370 //    
       
   371 void CNBestListDialog::SetCommandsHidden( TBool aHidden )
       
   372     {
       
   373     RUBY_DEBUG_BLOCK( "CNBestListDialog::SetCommandsHidden" );
       
   374     
       
   375     iDialog->SetCommandVisibility( aHidden );
       
   376     }
       
   377     
       
   378 // -----------------------------------------------------------------------------
       
   379 // CNBestListDialog::ConvertKeyEventL
       
   380 // -----------------------------------------------------------------------------
       
   381 // 
       
   382 TInt CNBestListDialog::ConvertKeyEventL( const TKeyEvent& aKeyEvent )
       
   383     {
       
   384     TInt event = ENoKeypress;
       
   385     
       
   386     switch( aKeyEvent.iCode )
       
   387         {
       
   388         case EKeyNo:
       
   389         case EKeyEscape:
       
   390             {
       
   391             event = EVoiceTagSoftKeyQuit;
       
   392             break;
       
   393             }
       
   394 
       
   395         case EKeyDevice3:
       
   396             {
       
   397             event = ESelectKeypress;
       
   398             break;
       
   399             }
       
   400             
       
   401         case EKeyYes:
       
   402             {
       
   403             event = EDirectSelectKeypress;
       
   404             break;
       
   405             }
       
   406 
       
   407         case EKeyUpArrow:
       
   408             {
       
   409             event = EUpKeypress;
       
   410             break;
       
   411             }
       
   412                         
       
   413         case EKeyDownArrow:
       
   414             {
       
   415             event = EDownKeypress;
       
   416             break;
       
   417             }
       
   418                                         
       
   419         default:
       
   420             {
       
   421             event = ENoKeypress;
       
   422             break;            
       
   423             }
       
   424         }
       
   425             
       
   426     return event;
       
   427     }
       
   428     
       
   429 // ---------------------------------------------------------
       
   430 // CNBestListDialog::CreateIconArrayL
       
   431 // Creates new icon array
       
   432 // ---------------------------------------------------------
       
   433 //
       
   434 CArrayPtr<CGulIcon>* CNBestListDialog::CreateIconArrayL()
       
   435     {
       
   436     RUBY_DEBUG_BLOCK( "CNBestListDialog::CreateIconArrayL" );
       
   437     
       
   438     CAknIconArray* icons = new ( ELeave ) CAknIconArray( KSindNumberOfIcons );
       
   439     CleanupStack::PushL( icons );
       
   440 
       
   441     // 0. Phone
       
   442     // 1. Home
       
   443     // 2. Work
       
   444     // 3. Mobile
       
   445     // 4. Fax
       
   446     // 5. Pager
       
   447     // 6. Blank
       
   448     // 7. Profile
       
   449     // 8. Application or function
       
   450     // 9. Video call icon
       
   451     //10. VoIP icon
       
   452     
       
   453     for ( int i = 0; i < KSindNumberOfIcons; ++i )
       
   454         {
       
   455         AppendIconToArrayL( icons, *KIconId[ i ], KBitmapId[ i ], KMaskId[ i ] );
       
   456         }
       
   457         
       
   458     CleanupStack::Pop( icons );
       
   459     return icons;
       
   460     }
       
   461 
       
   462 
       
   463 // ---------------------------------------------------------
       
   464 // CNBestListDialog::AppendIconToArrayL
       
   465 // ---------------------------------------------------------
       
   466 //
       
   467 void CNBestListDialog::AppendIconToArrayL( CAknIconArray* aArray,
       
   468                                            const TAknsItemID& aID,
       
   469                                            TInt aBitmapId,
       
   470                                            TInt aMaskId )
       
   471     {
       
   472     RUBY_DEBUG_BLOCK( "CNBestListDialog::AppendIconToArrayL" );
       
   473 
       
   474     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   475 
       
   476     CFbsBitmap* bitmap = NULL;
       
   477     CFbsBitmap* mask = NULL;
       
   478     TBuf<KMaxFileName> fileName = AknIconUtils::AvkonIconFileName();
       
   479     
       
   480     if ( aID == *KIconId[ EIconProfile ] || aID == *KIconId[ EIconApplication ] )
       
   481         {
       
   482         TParse* fp = new ( ELeave ) TParse();
       
   483         CleanupStack::PushL( fp );
       
   484         User::LeaveIfError( fp->Set( KDirAndFile, &KDC_BITMAP_DIR, NULL ) );
       
   485 
       
   486         fileName = fp->FullName();
       
   487         CleanupStack::PopAndDestroy( fp );
       
   488         }
       
   489 
       
   490     AknsUtils::CreateIconL( skin, aID, bitmap, mask, fileName,
       
   491                             aBitmapId, aMaskId );
       
   492     CleanupStack::PushL( bitmap );
       
   493     CleanupStack::PushL( mask );
       
   494 
       
   495     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   496     icon->SetBitmapsOwnedExternally( EFalse );
       
   497 
       
   498     // icon now owns the bitmaps, no need to keep on cleanup stack.
       
   499     CleanupStack::Pop( mask );
       
   500     CleanupStack::Pop( bitmap );
       
   501     bitmap = NULL;
       
   502     mask = NULL;
       
   503 
       
   504     CleanupStack::PushL( icon );
       
   505     aArray->AppendL( icon );
       
   506 
       
   507     // aArray now owns the icon, no need to delete.
       
   508     CleanupStack::Pop( icon );
       
   509     }
       
   510 
       
   511 // ---------------------------------------------------------
       
   512 // CNBestListDialog::CreateAndSetSecondaryDisplayDataL
       
   513 // ---------------------------------------------------------
       
   514 //    
       
   515 void CNBestListDialog::CreateAndSetSecondaryDisplayDataL( CDesC16ArrayFlat* aItems )
       
   516     {
       
   517     RUBY_DEBUG_BLOCK( "CNBestListDialog::CreateAndSetSecondaryDisplayDataL" );
       
   518 
       
   519     if ( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) )
       
   520         {        
       
   521         // Create dummy id list (needed for list query automation)
       
   522         CArrayFixFlat<TInt>* array = new ( ELeave ) CArrayFixFlat<TInt>( 1 );
       
   523         CleanupStack::PushL( array );
       
   524         for( TInt i = 0; i < iTagCount; ++i )
       
   525             {
       
   526             array->AppendL( i );
       
   527             }
       
   528 
       
   529         // Publish to secondary display
       
   530         iDialog->PublishDialogL( SecondaryDisplay::ECmdShowNBestListQuery,
       
   531                                  SecondaryDisplay::KCatVoiceUi,
       
   532                                  array );
       
   533                                  
       
   534         iDialog->SetMediatorObserver( this );
       
   535         
       
   536         CleanupStack::Pop( array ); // Dialog takes ownership of array
       
   537 
       
   538         // Generate n-best data for secondary display
       
   539         CAknMediatorFacade* covercl = AknMediatorFacade( iDialog );
       
   540         if( covercl )
       
   541             {
       
   542             // Current index
       
   543             covercl->BufStream().WriteInt32L( iCurrentIndex );
       
   544 
       
   545             // Item count and items
       
   546             covercl->BufStream().WriteInt32L( iTagCount );
       
   547             for( TInt i = 0; i < iTagCount; ++i )
       
   548                 {
       
   549                 TPtrC16 item = aItems->MdcaPoint( i );
       
   550                 covercl->BufStream().WriteInt32L( item.Length() );
       
   551                 covercl->BufStream().WriteL( item, item.Length() );
       
   552                 }
       
   553 
       
   554             covercl->BufStream().CommitL(); // no more data to send so commit buf
       
   555             }
       
   556         }
       
   557     }
       
   558 
       
   559 // ---------------------------------------------------------
       
   560 // CNBestListDialog::HandleShortKeypressL
       
   561 // ---------------------------------------------------------
       
   562 //
       
   563 TBool CNBestListDialog::HandleShortKeypressL( CDesC16ArrayFlat* aItems )
       
   564     {        
       
   565     RUBY_DEBUG_BLOCK( "CNBestListDialog::HandleShortKeypressL" );
       
   566 
       
   567     TBool returnValue = ETrue;
       
   568 
       
   569     if ( aItems )
       
   570         {
       
   571         iDialog->SetItemTextArray( aItems );        
       
   572         iDialog->ListControl()->Listbox()->SetCurrentItemIndexAndDraw( iCurrentIndex );
       
   573         
       
   574         CreateAndSetSecondaryDisplayDataL( aItems );
       
   575         }
       
   576     else
       
   577         {
       
   578         ++iCurrentIndex;
       
   579         if ( iCurrentIndex == iTagCount )
       
   580             {    
       
   581             returnValue = EFalse;
       
   582             }
       
   583 
       
   584         if ( returnValue ) 
       
   585             {
       
   586             // Move focus to the current item
       
   587             TKeyEvent keyEvent;
       
   588             keyEvent.iRepeats = 0;
       
   589             keyEvent.iCode = EKeyDownArrow;
       
   590         
       
   591             iDialog->OfferKeyEventL( keyEvent, EEventKey );
       
   592             }
       
   593         }
       
   594     
       
   595     return returnValue;                
       
   596     }
       
   597     
       
   598 // ---------------------------------------------------------------------------
       
   599 // CNBestListDialog::SelectedIndex
       
   600 // ---------------------------------------------------------------------------
       
   601 //    
       
   602 TInt CNBestListDialog::SelectedIndex()
       
   603     {
       
   604     RUBY_DEBUG1( "CNBestListDialog::SelectedIndex - index = %d", iCurrentIndex );
       
   605     
       
   606     TInt index = iCurrentIndex;
       
   607     
       
   608     if ( index < 0 )
       
   609         {
       
   610         index = 0;
       
   611         }
       
   612     
       
   613     return index;
       
   614     }
       
   615     
       
   616 //  End of File