stif/ConsoleUI/src/Consolemenus.cpp
changeset 15 ccab7f1f8266
parent 0 a03f92240627
child 21 f5d4820de50d
equal deleted inserted replaced
13:33016869e0dd 15:ccab7f1f8266
   216     
   216     
   217 -------------------------------------------------------------------------------
   217 -------------------------------------------------------------------------------
   218 */
   218 */
   219 void CMenu::TimerUpdate()
   219 void CMenu::TimerUpdate()
   220     {    
   220     {    
   221 
   221     iScrolledLine.Zero();
   222     RRefArray<TDesC> texts;
   222     RRefArray<TDesC> texts;
   223     User::LeaveIfError( ItemTexts( texts ) );
   223     User::LeaveIfError( ItemTexts( texts ) );
   224     
   224     
   225     TInt count = texts.Count();
   225     TInt count = texts.Count();
   226     // If list is empty, do not scroll.
   226     // If list is empty, do not scroll.
   242         }
   242         }
   243 
   243 
   244 
   244 
   245     // If menu item have not been changed after last timer, then
   245     // If menu item have not been changed after last timer, then
   246     // start scrolling  
   246     // start scrolling  
   247     const TDesC& name = texts[ iFirst + iPosOnScreen ]; 
   247     const TDesC& name = texts[ iFirst + iPosOnScreen ];
   248     if ( name.Length() > ( iSize.iWidth - KMenuOverhead ) )
   248     if ( name.Length() > ( iSize.iWidth - KMenuOverhead ) )
   249         {
   249         {
   250 
   250 
   251         TInt y = iConsole->WhereY();
   251         TInt y = iConsole->WhereY();
   252         TInt x = iConsole->WhereX();
   252         TInt x = iConsole->WhereX();
   253         TBuf<80> iTmp;              
   253         TBuf<80> iTmp;              
   254 
   254 
   255         iStart = iStart + iDirection;
   255         iStart = iStart + iDirection;
   256 
   256 
   257         // "Right end"
   257         // "Right end"
   258         if ( iStart + iSize.iWidth > name.Length() + KMenuOverhead )
   258         if ( iStart + iSize.iWidth > name.Length() + KMenuOverhead + 2)
   259             {
   259             {
   260             iStart--;
   260             iStart--;
   261             iDirection = -1;
   261             iDirection = -1;
   262             }
   262             }
   263         
   263         
   275 
   275 
   276         iTmp=_L(" *");
   276         iTmp=_L(" *");
   277         LimitedAppend( iTmp, name.Mid ( iStart ) );
   277         LimitedAppend( iTmp, name.Mid ( iStart ) );
   278             
   278             
   279         iConsole->SetPos( 0, iPosOnScreen+1);       
   279         iConsole->SetPos( 0, iPosOnScreen+1);       
   280         iConsole->Printf ( iTmp.Left( iSize.iWidth -2 )  );
   280         Print(iTmp);
       
   281         iScrolledLine.Copy(texts[iFirst + iPosOnScreen].Left(iScrolledLine.MaxLength())); 
   281 
   282 
   282         iConsole->SetPos(x,y);
   283         iConsole->SetPos(x,y);
   283         }
   284         }
   284     texts.Close();
   285     texts.Close();
   285 
   286 
   393         }
   394         }
   394     else
   395     else
   395         {
   396         {
   396         //removing "*" sign from the previous cursor position
   397         //removing "*" sign from the previous cursor position
   397         iConsole->SetPos(0, iPrevPosOnScreen + iMenuItemsListStartIndex);
   398         iConsole->SetPos(0, iPrevPosOnScreen + iMenuItemsListStartIndex);
   398         line.Append( _L("  ") );
   399         //line.Append( _L("  ") );
   399         iConsole->Printf(line);
   400         AppendBefore(iPrevPosOnScreen + iFirst, line);
       
   401         LimitedAppend(line, iScrolledLine);
       
   402         //iConsole->Printf(line);
       
   403         Print(line);
   400         iConsole->SetPos(0, iPosOnScreen + iMenuItemsListStartIndex);
   404         iConsole->SetPos(0, iPosOnScreen + iMenuItemsListStartIndex);
   401         line.Zero();
   405         line.Zero();
       
   406         iScrolledLine.Zero();
   402         
   407         
   403         //writing "*" sign before the currently selected line
   408         //writing "*" sign before the currently selected line
   404         line.Append( _L(" *") );
   409         line.Append( _L(" *") );
   405         iConsole->Printf(line);
   410         iConsole->Printf(line);
   406         iConsole->SetPos(0, iMenuItemsListEndIndex);
   411         iConsole->SetPos(0, iMenuItemsListEndIndex);
   407         iPreventClearScreen = EFalse;
   412         iPreventClearScreen = EFalse;
   408         }
   413         }
   409     }
   414     }
   410 
   415 
   411 
   416 /*
       
   417 -------------------------------------------------------------------------------
       
   418 
       
   419     Class: CMenu
       
   420 
       
   421     Method: SelectL
       
   422 
       
   423     Description: Common method to count all variables needed for printing
       
   424                  page of the screen.
       
   425 
       
   426     Parameters: TInt aDelta       :in:      where to move current position
       
   427                  Value > 0 stands for moving down the menu.
       
   428                  Value < 0 stands for moving up the menu.
       
   429 
       
   430     Return Values: 
       
   431 
       
   432     Errors/Exceptions: None
       
   433 
       
   434     Status: Draft
       
   435 
       
   436 -------------------------------------------------------------------------------
       
   437 */
       
   438 void CMenu::MovePosition(TInt aDelta)
       
   439     {
       
   440     if(iItemCount > 0 && aDelta != 0)
       
   441         {
       
   442         // Valid screen size
       
   443         TInt screenSize = iScreenSize + 1;
       
   444         TInt realPosition = iFirst + iPosOnScreen;
       
   445 
       
   446         // Number of all pages and items in the last page
       
   447         TInt rest = iItemCount % screenSize;
       
   448         TInt pages = (iItemCount / screenSize) + ((rest == 0) ? (0) : (1));
       
   449 
       
   450         // Current page
       
   451         TInt currPage = realPosition / screenSize;
       
   452         
       
   453         // New page
       
   454         TInt newRealPosition = realPosition + aDelta;
       
   455         while(newRealPosition < 0)
       
   456             newRealPosition += iItemCount;
       
   457         newRealPosition %= iItemCount;
       
   458         TInt newPage = newRealPosition / screenSize;
       
   459         
       
   460         // Change position
       
   461         iFirst = newPage * screenSize;
       
   462         iLast = iFirst + screenSize - 1;
       
   463         if(iLast >= iItemCount)
       
   464             iLast = iItemCount - 1;
       
   465         iPrevPosOnScreen = iPosOnScreen;
       
   466         iPosOnScreen = newRealPosition % screenSize;
       
   467         if(newPage == pages - 1 && iPosOnScreen >= rest)
       
   468             iPosOnScreen = rest - 1;
       
   469             
       
   470         // Prevent refreshing
       
   471         iPreventClearScreen = (currPage == newPage);
       
   472         }
       
   473     else
       
   474         iPreventClearScreen = ETrue;    
       
   475     }
       
   476     
   412 /*
   477 /*
   413 -------------------------------------------------------------------------------
   478 -------------------------------------------------------------------------------
   414 
   479 
   415     Class: CMenu
   480     Class: CMenu
   416 
   481 
   440 
   505 
   441     // Exit
   506     // Exit
   442     case EKeyEscape:
   507     case EKeyEscape:
   443         aContinue = EFalse;
   508         aContinue = EFalse;
   444         return this;
   509         return this;
       
   510 
   445     // SelectL item
   511     // SelectL item
   446     case EKeyEnter:
   512     case EKeyEnter:
   447     case EKeyRightArrow:
   513     case EKeyRightArrow:
   448         return iItems[iPosOnScreen];
   514         return iItems[iPosOnScreen];
   449 
   515 
   451     case EKeyLeftArrow:
   517     case EKeyLeftArrow:
   452         return iParent;
   518         return iParent;
   453 
   519 
   454     // Go down
   520     // Go down
   455     case EKeyDownArrow:
   521     case EKeyDownArrow:
   456         {
   522         MovePosition(1);
   457         if ( iFirst + iPosOnScreen == iItemCount - 1 )
       
   458             {
       
   459             // If end of the list, go to beginning
       
   460             iPosOnScreen = 0;
       
   461             iFirst = 0;
       
   462             iLast = iScreenSize;
       
   463             if ( iLast > iItemCount - 1 )
       
   464             	{
       
   465             	iLast = iItemCount - 1;
       
   466             	}
       
   467             }
       
   468         else 
       
   469             {
       
   470             if ( iPosOnScreen == iScreenSize )
       
   471                 {
       
   472                 iPosOnScreen = 0;
       
   473                 iFirst += iScreenSize + 1;
       
   474                 iLast += iScreenSize + 1;
       
   475                 }
       
   476             else
       
   477                 {
       
   478                 // Going down "in-screen", no need to update items
       
   479                 iPrevPosOnScreen = iPosOnScreen;
       
   480                 iPreventClearScreen = EFalse;
       
   481                 if (iItemCount > 0)
       
   482                     {
       
   483                     iPosOnScreen++;
       
   484                     iPreventClearScreen = ETrue;
       
   485                     }
       
   486                 }
       
   487             }
       
   488         break;
   523         break;
   489         }
       
   490         
   524         
   491     // Go Up
   525     // Go Up
   492     case EKeyUpArrow:
   526     case EKeyUpArrow:
   493         {                               
   527         MovePosition(-1);
   494         // The second condition is needed for the cursor not to go to "next" page (if it does not exist)
       
   495         if ( iFirst + iPosOnScreen == 0 )
       
   496             {
       
   497             // If in the beginning of the list
       
   498             if (iItemCount == iScreenSize + 1 || iItemCount == iScreenSize)
       
   499                 {
       
   500                 iPosOnScreen = iItemCount - 1;
       
   501                 }
       
   502             else
       
   503                 {
       
   504                 iFirst = (iItemCount / iScreenSize) * iScreenSize;
       
   505                 iLast = iItemCount - 1;
       
   506                 iPosOnScreen = iItemCount % iScreenSize - 1;
       
   507                 if (iItemCount > iScreenSize)
       
   508                     {
       
   509                     iFirst++;
       
   510                     iPosOnScreen--;
       
   511                     }
       
   512                 }
       
   513             }
       
   514         else if ( iPosOnScreen == 0 )
       
   515             {
       
   516             iPosOnScreen = iScreenSize;
       
   517             iLast -= iScreenSize + 1;
       
   518             iFirst -= iScreenSize + 1;
       
   519             }
       
   520         else
       
   521             {
       
   522             iPrevPosOnScreen = iPosOnScreen;
       
   523             iPosOnScreen--;
       
   524             iPreventClearScreen = ETrue;
       
   525             }
       
   526         
       
   527         break;
   528         break;
   528         }
       
   529 
   529 
   530     // Additional keys
   530     // Additional keys
   531     case EKeyHome:
   531     case EKeyHome:
   532     case '3':
   532     case '3':
   533         iPosOnScreen = 0;
   533         MovePosition(-iFirst - iPosOnScreen);
   534         iFirst = 0;
       
   535         iLast = iScreenSize;
       
   536 
       
   537         if ( iLast > iItemCount - 1 )
       
   538             {
       
   539             iLast = iItemCount - 1;
       
   540             }
       
   541         break;
   534         break;
   542 
   535 
   543     case EKeyEnd:
   536     case EKeyEnd:
   544     case '9':
   537     case '9':
   545         iLast = iItemCount - 1;
   538         MovePosition(iItemCount - 1 - iFirst - iPosOnScreen);
   546         iFirst = iLast - iScreenSize;
       
   547 
       
   548         if ( iFirst < 0 )
       
   549             {
       
   550             iFirst = 0;
       
   551             }
       
   552         iPosOnScreen = iLast - iFirst;        
       
   553         break;
   539         break;
   554 
   540 
   555     case EKeyPageUp:
   541     case EKeyPageUp:
   556     case '1':
   542     case '1':
   557 
   543         MovePosition((iFirst + iPosOnScreen - iScreenSize - 1 >= 0) ? (-iScreenSize - 1) : (-iFirst - iPosOnScreen));
   558         iFirst = iFirst - iScreenSize;
       
   559         iLast = iLast - iScreenSize;
       
   560 
       
   561         if ( iFirst < 0 )
       
   562             {
       
   563             iFirst = 0;
       
   564             iPosOnScreen = 0;           
       
   565             iLast = iScreenSize;
       
   566             if ( iLast > iItemCount - 1 )
       
   567                 {
       
   568                 iLast = iItemCount - 1;
       
   569                 }
       
   570             }
       
   571         break;
   544         break;
   572 
   545 
   573     case EKeyPageDown:
   546     case EKeyPageDown:
   574     case '7':
   547     case '7':
   575         iFirst = iFirst + iScreenSize;
   548         MovePosition((iFirst + iPosOnScreen + iScreenSize + 1 < iItemCount) ? (iScreenSize + 1) : (iItemCount - 1 - iFirst - iPosOnScreen));
   576         iLast = iLast + iScreenSize;
       
   577 
       
   578         // Going too far
       
   579         if ( iLast > iItemCount - 1 )
       
   580             {
       
   581             iLast = iItemCount - 1;
       
   582             iFirst = iLast - iScreenSize;
       
   583             if ( iFirst < 0 )
       
   584                 {
       
   585                 iFirst = 0;
       
   586                 }
       
   587             }
       
   588         iPosOnScreen = iLast - iFirst;
       
   589         break;
   549         break;
   590     default:  // Bypass the keypress
   550     default:  // Bypass the keypress
   591         break;
   551         break;
   592     }
   552     }
   593 
   553 
   679 -------------------------------------------------------------------------------
   639 -------------------------------------------------------------------------------
   680 */
   640 */
   681 void CMenu::Print( const TDesC& aPrint )
   641 void CMenu::Print( const TDesC& aPrint )
   682     {
   642     {
   683     
   643     
   684     iConsole->Printf ( aPrint.Left( iSize.iWidth - KMenuOverhead ) );
   644     iConsole->Write ( aPrint.Left( iSize.iWidth - KMenuOverhead ) );
   685     iConsole->Printf(_L("\n"));
   645     iConsole->Write(_L("\n"));
   686 
   646 
   687     }
   647     }
   688 
   648 
   689 /*
   649 /*
   690 -------------------------------------------------------------------------------
   650 -------------------------------------------------------------------------------
  1118                 error.iText.Append( *iTestModuleNames[iPosOnScreen] );
  1078                 error.iText.Append( *iTestModuleNames[iPosOnScreen] );
  1119                 error.iText.Append( _L(" error "));
  1079                 error.iText.Append( _L(" error "));
  1120                 error.iText.AppendNum( ret );
  1080                 error.iText.AppendNum( ret );
  1121                 iMain->Error( error );
  1081                 iMain->Error( error );
  1122                 }
  1082                 }
  1123             return iParent;
  1083         return iParent;
  1124             }
  1084             }
  1125         else
  1085         else
  1126             {
  1086             {
  1127             return this;
  1087             return this;
  1128             }
  1088             }
  4426 
  4386 
  4427         switch ( aSelection )
  4387         switch ( aSelection )
  4428             {
  4388             {
  4429             case EKeyEnter:
  4389             case EKeyEnter:
  4430             case EKeyRightArrow:
  4390             case EKeyRightArrow:
  4431             	{           
  4391                 {           
       
  4392                 if(iPosOnScreen < iFileList.Count())
       
  4393                     {
       
  4394                     const TDesC& aSetName = iFileList.operator [](iPosOnScreen)->Des();
  4432                 
  4395                 
  4433                 const TDesC& aSetName = iFileList.operator [](iPosOnScreen)->Des();
  4396                     ret = iMain->UIStore().LoadTestSet( iFileList.operator [](iPosOnScreen)->Des() );
  4434                 
  4397                     if (ret == KErrNone)
  4435                 ret = iMain->UIStore().LoadTestSet( iFileList.operator [](iPosOnScreen)->Des() );
  4398                         {
  4436                 if (ret == KErrNone)
  4399                         ((CTestSetMenu*)iParent)->SetCreated();
  4437                 	{
  4400                         ((CTestSetMenu*)iParent)->SetTestSetFileName(iFileList.operator [](iPosOnScreen)->Des());
  4438                 	((CTestSetMenu*)iParent)->SetCreated();
  4401                         }
  4439                 	((CTestSetMenu*)iParent)->SetTestSetFileName(iFileList.operator [](iPosOnScreen)->Des());
  4402                     return iParent;
  4440                 	}
  4403                     }
  4441                 return iParent;
  4404                 else
       
  4405                     {
       
  4406                     return this;
       
  4407                     }
  4442                 }
  4408                 }
  4443             default:
  4409             default:
  4444                 break;
  4410                 break;
  4445             }
  4411             }
  4446             
  4412