textinput/peninputhwrtrui/src/truishortcutscontainer.cpp
changeset 0 eb1f2e154e89
child 7 6defe5d1bd39
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Implement of class CTruiShortcutsContainer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <barsread.h>
       
    20 #include <aknnavide.h>
       
    21 #include <akntabgrp.h>
       
    22 #include <eikspane.h>
       
    23 #include <aknViewAppUi.h>
       
    24 #include <aknlists.h>
       
    25 #include <AknIconArray.h>
       
    26 #include <eikclbd.h>
       
    27 #include <trui.rsg>
       
    28 #include <StringLoader.h>
       
    29 #include <trui_icons.mbg>
       
    30 #include <AknIconUtils.h>
       
    31 #include <gulicon.h> 
       
    32 #include <akntextsettingpage.h>
       
    33 #include <AknQueryDialog.h>  
       
    34 #include <AknPreviewPopUpController.h>
       
    35 #include <aknlayoutscalable_apps.cdl.h>
       
    36 #include <layoutmetadata.cdl.h>
       
    37 #include <akntoolbar.h>
       
    38 #include <aknbutton.h>
       
    39 #include <aknlayoutscalable_apps.cdl.h>
       
    40 #include <biditext.h>
       
    41 
       
    42 #include "truicontainerbase.h"
       
    43 #include "truishortcutscontainer.h"
       
    44 #include "truimainview.h"
       
    45 #include "truiengine.h"
       
    46 #include "truiappui.h"
       
    47 #include "truiengine.h"
       
    48 #include "truishortcuteditview.h"
       
    49 #include "trui.hrh"
       
    50 #include "truiapplication.h"
       
    51 #include "truihelp.h"
       
    52 #include "truihwrbox.h"
       
    53 #include "truishortcutedittextview.h"
       
    54 #include "truiinfomessageview.h"
       
    55 #include "truishortcutsview.h"
       
    56 
       
    57 _LIT( KTRUIICONSFILENAME, "\\resource\\apps\\trui_icons.mif" );
       
    58 
       
    59 // Initialized size for item array
       
    60 const TInt KItemArraySize = 1;
       
    61 
       
    62 // Initialized size for icon array
       
    63 const TInt KIconArraySize = 3;
       
    64 
       
    65 // listbox item format string
       
    66 _LIT( KListItemWithPicFormat, "1\t%S\t\t" );
       
    67 _LIT( KListItemFormat, "\t%S\t\t" );
       
    68     
       
    69 // Delay time of showing tooltip
       
    70 const TTimeIntervalMicroSeconds32 KTooltipShowDelay = 1000000;
       
    71 
       
    72 // Delay time of hiding tooltip
       
    73 const TTimeIntervalMicroSeconds32 KTooltipHideDelay = 3000000;
       
    74 
       
    75 // Rect of popup hwrbox
       
    76 const TRect KPopupHwrBoxRect = TRect( TPoint( 0, 0 ), TSize( 75, 75 ) );
       
    77 
       
    78 const TPoint KPopupHwrBoxPosLandscape = TPoint( 479, 360 );
       
    79 const TPoint KPopupHwrBoxPosPortrait = TPoint( 337, 500 );
       
    80 
       
    81 const TInt KPopupWindowVarity = 0;
       
    82 
       
    83 const TInt KParaDelimiterSize = 1;
       
    84 _LIT( KParaDelimiterFormat, "%c" );
       
    85     
       
    86 // ======== MEMBER FUNCTIONS ========
       
    87 
       
    88 CTruiShortcutsContainer::CTruiShortcutsContainer()
       
    89     {  
       
    90     }
       
    91     
       
    92 void CTruiShortcutsContainer::ConstructL( const TRect& aRect )
       
    93     {
       
    94     // Initialize control array
       
    95     InitComponentArrayL();
       
    96         
       
    97     // Set parent control or owning window
       
    98     CreateWindowL();   
       
    99     
       
   100     // Load shortcuts
       
   101     iEngine->UpdateShortcutListL();
       
   102     
       
   103     // Initialize controls
       
   104     InitializeControlsL();
       
   105     SetRect( aRect );
       
   106                 
       
   107     // Set default selected index
       
   108     iListBox->SetCurrentItemIndex( iEngine->CurrentSelectedIndex() );
       
   109                
       
   110     HandleListBoxFocusChangedL( CurrentItemIndex() );
       
   111     
       
   112     ActivateL();    
       
   113     }
       
   114     
       
   115 CTruiShortcutsContainer* CTruiShortcutsContainer::NewL( const TRect& aRect )
       
   116     {
       
   117     CTruiShortcutsContainer* self = CTruiShortcutsContainer::NewLC( aRect );
       
   118     CleanupStack::Pop( self );
       
   119     return self;
       
   120     }
       
   121     
       
   122 CTruiShortcutsContainer* CTruiShortcutsContainer::NewLC
       
   123                                                   ( const TRect& aRect )
       
   124     {
       
   125     CTruiShortcutsContainer* self = new (ELeave) CTruiShortcutsContainer();
       
   126     CleanupStack::PushL( self );
       
   127     self->ConstructL( aRect );
       
   128     return self;
       
   129     }
       
   130     
       
   131 CTruiShortcutsContainer::~CTruiShortcutsContainer()
       
   132     {    
       
   133     delete iPopupController;     
       
   134     delete iHwrBox;
       
   135     }
       
   136     
       
   137 // ---------------------------------------------------------------------------
       
   138 // Create controls to be displayed in this container.
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CTruiShortcutsContainer::InitializeControlsL()
       
   142     {
       
   143     // Create toolbar
       
   144     CAknToolbar* toolbar = iAppUi->View( KTruiShortcutsViewId )->Toolbar();
       
   145     // Get Clear button from toolbar    
       
   146     CAknButton* deleteButton = static_cast<CAknButton*>
       
   147                     ( toolbar->ControlOrNull( EShortcutsViewButtonIdDelete ) );
       
   148 
       
   149     // Create listbox
       
   150     CreateListBoxL();
       
   151     
       
   152     // Create preview popup window
       
   153     iPopupController = CreatePopupHwrBoxL();    
       
   154     }
       
   155             
       
   156 // ---------------------------------------------------------------------------
       
   157 // From class CCoeControl.
       
   158 // Responds to changes to the size and position of the contents of this control.
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CTruiShortcutsContainer::SizeChanged()
       
   162     {
       
   163     if ( iListBox )
       
   164         {
       
   165         iListBox->SetRect( Rect() );
       
   166         }    
       
   167     
       
   168     // caculate main pane
       
   169     TRect rect = Rect();    
       
   170     TAknWindowComponentLayout main_pane_layout = 
       
   171                             AknLayoutScalable_Apps::main_hwr_training_pane();
       
   172     TAknLayoutRect main_pane_layout_rect;
       
   173     main_pane_layout_rect.LayoutRect( rect, main_pane_layout );
       
   174     TRect main_pane_rect = main_pane_layout_rect.Rect();
       
   175     
       
   176     // Calculate popup_hwr_training_preview_window
       
   177     TAknWindowComponentLayout preview_popup_layout = 
       
   178                AknLayoutScalable_Apps::popup_hwr_training_preview_window
       
   179                                                      ( KPopupWindowVarity );
       
   180     TAknLayoutRect preview_popup_layout_rect;
       
   181     preview_popup_layout_rect.LayoutRect( main_pane_rect, preview_popup_layout );    
       
   182     
       
   183     iHwrBox->SetSize( preview_popup_layout_rect.Rect().Size() );
       
   184     
       
   185     TPoint itemPos = PopupWindowPosition( CurrentItemIndex() );
       
   186     iPopupController->SetPosition( itemPos );
       
   187     }       
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // From class CCoeControl.
       
   191 // This is called whenever the control gains or loses focus, 
       
   192 // ---------------------------------------------------------------------------
       
   193 // 
       
   194 void CTruiShortcutsContainer::FocusChanged( TDrawNow /*aDrawNow*/ )
       
   195     {
       
   196     if ( IsFocused() )
       
   197         {        
       
   198         if ( iDisplayPopupWindow )
       
   199             {            
       
   200             TRAPD( err, CheckAndPreviewShortcutModelL( CurrentItemIndex() ) );
       
   201             if ( err != KErrNone )
       
   202                 {
       
   203                 iDisplayPopupWindow = EFalse;
       
   204                 }
       
   205             }
       
   206         }
       
   207     else
       
   208         {        
       
   209         // Close pupup preview window
       
   210         iPopupController->HidePopUp();
       
   211         }
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // From class CCoeControl.
       
   216 // Handles pointer events.
       
   217 // ---------------------------------------------------------------------------
       
   218 //     
       
   219 void CTruiShortcutsContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   220     {
       
   221     iPenDownPoint = aPointerEvent.iPosition;
       
   222     CCoeControl::HandlePointerEventL( aPointerEvent );    
       
   223     }
       
   224     
       
   225 // ---------------------------------------------------------------------------
       
   226 // Popup the TextSettingPage and added the new shortcut to ListBox.
       
   227 // ---------------------------------------------------------------------------
       
   228 //     
       
   229 void CTruiShortcutsContainer::AddShortcutL()
       
   230     {    
       
   231     iEngine->NewShortcut( ETrue );
       
   232     iEngine->SetShortcut( KNullDesC );
       
   233     // Get always display setting from ini file
       
   234     TInt isNotDisplayWizard = 0;
       
   235     TRAPD( err, GetSettingFromIniFileL( KAlwaysDisplayWizardKey, isNotDisplayWizard ) );
       
   236     if ( err != KErrNone )
       
   237         {
       
   238         isNotDisplayWizard = 0;
       
   239         }
       
   240         
       
   241     if ( isNotDisplayWizard )
       
   242         {
       
   243         iEngine->SetDisplayWizard( EFalse );
       
   244         iAppUi->ActivateLocalViewL( KTruiShortcutEditTextViewId );
       
   245         }
       
   246     else
       
   247         {
       
   248         iEngine->SetDisplayWizard( ETrue );
       
   249         iAppUi->ActivateLocalViewL( KTruiInfoMessageViewId );
       
   250         }    
       
   251     }
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // Edit shortcut
       
   255 // ---------------------------------------------------------------------------
       
   256 // 
       
   257 void CTruiShortcutsContainer::EditShortcutL( TBool aOnlyEditText )
       
   258     {
       
   259     CDesCArray* shortcutlist = iEngine->ShortcutTextList();
       
   260     TInt posInEngine = iListBox->CurrentItemIndex() - 1;
       
   261     iEngine->SetShortcut( shortcutlist->MdcaPoint( posInEngine ) );
       
   262     iEngine->NewShortcut( EFalse );
       
   263     // Switch to shortcut edit view 
       
   264     if ( aOnlyEditText )
       
   265         {
       
   266         iAppUi->ActivateLocalViewL( KTruiShortcutEditTextViewId );
       
   267         }
       
   268     else
       
   269         {
       
   270         iAppUi->ActivateLocalViewL( KTruiShortcutEditViewId );
       
   271         }
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 // Check if reset introduction
       
   276 // ---------------------------------------------------------------------------
       
   277 // 
       
   278 TBool CTruiShortcutsContainer::IsResetIntroduction()
       
   279     {
       
   280     TInt value = 0;
       
   281     TRAPD( err, GetSettingFromIniFileL( KAlwaysDisplayWizardKey, value ) );
       
   282     if ( err != KErrNone )
       
   283         {
       
   284         value = 0;
       
   285         }
       
   286     return value ? ETrue: EFalse;
       
   287     }    
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // Reset introduction
       
   291 // ---------------------------------------------------------------------------
       
   292 // 
       
   293 void CTruiShortcutsContainer::ResetIntroductionL()
       
   294     {
       
   295     SaveSettingIntoIniFileL( KAlwaysDisplayWizardKey, 0 );
       
   296     iAppUi->ActivateLocalViewL( KTruiInfoMessageViewId );
       
   297     }
       
   298     
       
   299 // ---------------------------------------------------------------------------
       
   300 // From MEikListBoxObserver
       
   301 // Handle event from an listbox
       
   302 // ---------------------------------------------------------------------------
       
   303 //     
       
   304 void CTruiShortcutsContainer::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   305                                                   TListBoxEvent aEventType )
       
   306     {       
       
   307     switch( aEventType )
       
   308         {
       
   309         case EEventPenDownOnItem:
       
   310             {            
       
   311             iPopupController->HidePopUp();
       
   312             // Check index
       
   313             TInt index = CurrentItemIndex();
       
   314             iListBox->View()->XYPosToItemIndex( iPenDownPoint, index );
       
   315             // Popup preview window
       
   316             HandleListBoxFocusChangedL( index );
       
   317             }
       
   318             break;
       
   319         case EEventItemClicked:
       
   320             {
       
   321             break;
       
   322             }
       
   323         case EEventItemDoubleClicked:
       
   324             {            
       
   325             if ( CurrentItemIndex() > 0 )
       
   326                 {
       
   327                 if ( MarkCount() == 0 )
       
   328                     {
       
   329                     // Pop context menu
       
   330                     PopupContextMenuL( R_TRUI_SHORTCUTSVIEW_CONTEXT_MENUBAR );
       
   331                     }
       
   332                 }
       
   333             else
       
   334                {                
       
   335                // Tap on "New shortcut"
       
   336                AddShortcutL();
       
   337                }
       
   338             // Set the current index into engine
       
   339             // Update toolbar button's status
       
   340             break;
       
   341             }
       
   342         case EEventItemDraggingActioned:
       
   343             {            
       
   344             iPopupController->HidePopUp();            
       
   345             TInt index = CurrentItemIndex();
       
   346             iListBox->View()->XYPosToItemIndex( iPenDownPoint, index );
       
   347             // Popup preview window
       
   348             HandleListBoxFocusChangedL( index );
       
   349             break;
       
   350             }
       
   351         }
       
   352     }
       
   353 
       
   354 // ---------------------------------------------------------------------------
       
   355 // From class CCoeControl.
       
   356 // Handles key event.
       
   357 // ---------------------------------------------------------------------------
       
   358 //      
       
   359 TKeyResponse CTruiShortcutsContainer::OfferKeyEventL
       
   360                                       ( const TKeyEvent& aKeyEvent, 
       
   361                                         TEventCode aType )
       
   362     {
       
   363     if ( aType == EEventKey )
       
   364         {        
       
   365         switch ( aKeyEvent.iCode )
       
   366             {            
       
   367             case EKeyLeftArrow:
       
   368                 {                
       
   369                 CAknNavigationDecorator* naviDecorator = 
       
   370                                          iAppUi->GetNaviDecorator();
       
   371                 CAknTabGroup* tabGroup = static_cast<CAknTabGroup*>
       
   372                                         ( naviDecorator->DecoratedControl() );
       
   373                 return tabGroup->OfferKeyEventL( aKeyEvent, aType );   
       
   374                 }
       
   375             case EKeyRightArrow:
       
   376                 {                
       
   377                 return EKeyWasConsumed;
       
   378                 }
       
   379             case EKeyUpArrow:
       
   380             case EKeyDownArrow:
       
   381                 {
       
   382                 if ( iListBox )
       
   383                     {                    
       
   384                     iPopupController->HidePopUp();
       
   385                     TKeyResponse keyResponse = iListBox->OfferKeyEventL
       
   386                                                ( aKeyEvent, aType );
       
   387                     // Set the CBA button
       
   388                     if ( IsMarked( 0 ) )
       
   389                         {
       
   390                         iListBox->SetCurrentItemIndex( 0 );
       
   391                         AknSelectionService::HandleMarkableListProcessCommandL
       
   392                                              ( EAknCmdUnmark, iListBox );
       
   393                         iListBox->SetCurrentItemIndexAndDraw( iEngine->CurrentSelectedIndex() );
       
   394                         }                        
       
   395                     HandleListBoxFocusChangedL( CurrentItemIndex() );
       
   396                     return keyResponse;
       
   397                     }		   
       
   398 			    }		
       
   399 			case EKeyEnter:
       
   400 			case EKeyOK:
       
   401 			    {
       
   402                 if ( CurrentItemIndex() == 0 )
       
   403                     {
       
   404                     // Select "Create new shortcut" item
       
   405                     AddShortcutL();
       
   406                     }
       
   407                 else
       
   408                     {
       
   409                     if ( MarkCount() == 0 )
       
   410                         {
       
   411                         // Pop context menu
       
   412                         PopupContextMenuL( R_TRUI_SHORTCUTSVIEW_CONTEXT_MENUBAR );
       
   413                         }
       
   414                     }
       
   415                 return EKeyWasConsumed;                
       
   416                  }
       
   417             default:
       
   418                 break;			    
       
   419             }
       
   420        }    
       
   421     return EKeyWasNotConsumed;    
       
   422     }
       
   423 
       
   424 // ---------------------------------------------------------------------------
       
   425 // Gets the control's help context. Returns a NULL context by default.
       
   426 // ---------------------------------------------------------------------------
       
   427 //
       
   428 void CTruiShortcutsContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   429     {
       
   430     aContext.iMajor = KUidtruiApp;
       
   431     aContext.iContext = HWRT_HLP_SHORTCUTS;
       
   432     }
       
   433         
       
   434 // ---------------------------------------------------------------------------
       
   435 // Delete shortcut from ListBox
       
   436 // ---------------------------------------------------------------------------
       
   437 //     
       
   438 void CTruiShortcutsContainer::DeleteItemsL()
       
   439     {
       
   440     CTextListBoxModel* model = iListBox->Model();
       
   441     CDesCArray* itemArray = static_cast<CDesCArray*>( model->ItemTextArray() );
       
   442     if ( MarkCount() > 0 )
       
   443         {
       
   444         // Delete all marked items, ignoring the selected item.
       
   445         RArray<TInt> selectionIndexes;
       
   446         CleanupClosePushL( selectionIndexes );
       
   447         const CArrayFix<TInt>* indexArray = iListBox->SelectionIndexes();
       
   448         TInt indexArrayLen = indexArray->Count();
       
   449         
       
   450         // Copy the selection indexes array into RArray<TInt>
       
   451         for ( TInt i = 0; i < indexArrayLen; i++ )
       
   452             {
       
   453             selectionIndexes.Append( ( *indexArray )[i] );
       
   454             }
       
   455         selectionIndexes.Sort();
       
   456         // Delete all marked items    
       
   457         TInt selectionCount = selectionIndexes.Count();                    
       
   458         for ( TInt i = selectionCount - 1; i >= 0; i-- )
       
   459             {   
       
   460             // Delete item from Engine
       
   461             TInt itemArrayIndex = selectionIndexes[i];
       
   462             CDesCArray* shortcutList = iEngine->ShortcutTextList();
       
   463 
       
   464             if ( shortcutList )
       
   465                 {
       
   466                 iEngine->DeleteShortcut( (*shortcutList)[itemArrayIndex-1] );            
       
   467                 // Delete the currently selected item from array
       
   468                 itemArray->Delete( itemArrayIndex );
       
   469                 // Update ListBox
       
   470                 AknListBoxUtils::HandleItemRemovalAndPositionHighlightL( iListBox, 
       
   471                                                                         itemArrayIndex,
       
   472                                                                         ETrue);     
       
   473                 }        
       
   474             }
       
   475         CleanupStack::PopAndDestroy( &selectionIndexes ); // selectionIndexes           
       
   476         }
       
   477     else
       
   478         {
       
   479         // Delete the currently selected item.
       
   480         // Get the currently selected item
       
   481         TInt selectedIndex = CurrentItemIndex();
       
   482 
       
   483         // Delete item from Engine
       
   484         CDesCArray* shortcutList = iEngine->ShortcutTextList();
       
   485         if ( shortcutList )
       
   486             {
       
   487             iEngine->DeleteShortcut( (*shortcutList)[selectedIndex-1] );            
       
   488             // Delete the currently selected item from array
       
   489             itemArray->Delete( selectedIndex );
       
   490             // Update ListBox
       
   491             AknListBoxUtils::HandleItemRemovalAndPositionHighlightL( iListBox, 
       
   492                                                                     selectedIndex,
       
   493                                                                     ETrue);     
       
   494             }        
       
   495     }
       
   496     iListBox->DrawNow();                
       
   497     iEngine->UpdateShortcutListL();
       
   498     // Set the current CBA
       
   499     HandleListBoxFocusChangedL( CurrentItemIndex() );
       
   500     }
       
   501     
       
   502 // ---------------------------------------------------------------------------
       
   503 // Delete shortcut
       
   504 // ---------------------------------------------------------------------------
       
   505 //     
       
   506 void CTruiShortcutsContainer::DeleteShortcutL()
       
   507     {
       
   508     // Popup note dialog
       
   509     CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   510     HBufC* prompt = NULL;
       
   511     TInt count = MarkCount();
       
   512     if ( count )
       
   513         {
       
   514         prompt = StringLoader::LoadLC( R_QTN_HWRT_QUERY_DELETE_SEVERAL_SHORTCUTS, count );
       
   515         }
       
   516     else
       
   517         {
       
   518         prompt = StringLoader::LoadLC( R_QTN_HWRT_QUERY_DELETE_SHORTCUT );
       
   519         }
       
   520     
       
   521     if ( dlg->ExecuteLD( R_TRUI_QUERYDIALOG_DELETE_SHORTCUT, *prompt ) )
       
   522         {
       
   523         // press yes 
       
   524         // Delete item from Listbox, also delete from Engine in it.
       
   525         iPopupController->HidePopUp();
       
   526         DeleteItemsL();        
       
   527         }
       
   528     CleanupStack::PopAndDestroy( prompt ); // prompt
       
   529     }
       
   530 
       
   531 // ---------------------------------------------------------------------------
       
   532 // Handle event when listbox change to another focused item.
       
   533 // ---------------------------------------------------------------------------
       
   534 //     
       
   535 void CTruiShortcutsContainer::HandleListBoxFocusChangedL( TInt aIndex )
       
   536     {
       
   537     // Set the current index into engine
       
   538     iEngine->SetCurrentSelectedIndex( aIndex );
       
   539     // Update toolbar button's status
       
   540     UpdateToolbarButtonStatus( aIndex );
       
   541     // Draw current item // add this line
       
   542     iListBox->DrawItem( aIndex ); // add this line
       
   543     // Preview shortcut model if it has model.
       
   544     CheckAndPreviewShortcutModelL( aIndex );
       
   545     }
       
   546     
       
   547 // ---------------------------------------------------------------------------
       
   548 // Mark shortcut
       
   549 // ---------------------------------------------------------------------------
       
   550 //     
       
   551 void CTruiShortcutsContainer::MarkShortcutL()
       
   552     {
       
   553     // The first item mustn't be marked
       
   554     TInt currentIndex = CurrentItemIndex();
       
   555     if ( currentIndex != 0 )
       
   556         {
       
   557         AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdMark,
       
   558                                                                 iListBox );       
       
   559         }
       
   560         
       
   561     CAknToolbar* toolbar = iAppUi->View( KTruiShortcutsViewId )->Toolbar();
       
   562     if ( toolbar )
       
   563         {
       
   564         // Set edit text button's status
       
   565         CAknButton* editTextButton = static_cast<CAknButton*>
       
   566                     ( toolbar->ControlOrNull( EShortcutsViewButtonIdEditText ) );
       
   567         editTextButton->SetDimmed( ETrue );
       
   568         editTextButton->DrawNow();
       
   569         // Set edit model button's status
       
   570         CAknButton* editModelButton = static_cast<CAknButton*>
       
   571                     ( toolbar->ControlOrNull( EShortcutsViewButtonIdEditModel ) );
       
   572         editModelButton->SetDimmed( ETrue );
       
   573         editModelButton->DrawNow();
       
   574         }    
       
   575     }
       
   576     
       
   577 // ---------------------------------------------------------------------------
       
   578 // Unmark shortcut
       
   579 // ---------------------------------------------------------------------------
       
   580 //     
       
   581 void CTruiShortcutsContainer::UnmarkShortcutL()
       
   582     {
       
   583     // The first item mustn't be unmarked
       
   584     TInt currentIndex = CurrentItemIndex();
       
   585     if ( currentIndex != 0 )
       
   586         {
       
   587         AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdUnmark,
       
   588                                                                 iListBox );
       
   589         }
       
   590     if ( MarkCount() == 0 )
       
   591         {
       
   592         CAknToolbar* toolbar = iAppUi->View( KTruiShortcutsViewId )->Toolbar();
       
   593         if ( toolbar )
       
   594             {
       
   595             // Set edit text button's status
       
   596             CAknButton* editTextButton = static_cast<CAknButton*>
       
   597                         ( toolbar->ControlOrNull( EShortcutsViewButtonIdEditText ) );
       
   598             editTextButton->SetDimmed( EFalse );
       
   599             editTextButton->DrawNow();
       
   600             // Set edit model button's status
       
   601             CAknButton* editModelButton = static_cast<CAknButton*>
       
   602                         ( toolbar->ControlOrNull( EShortcutsViewButtonIdEditModel ) );
       
   603             editModelButton->SetDimmed( EFalse );
       
   604             editModelButton->DrawNow();
       
   605             }
       
   606         }
       
   607     }
       
   608     
       
   609 // ---------------------------------------------------------------------------
       
   610 // Return current selected item's index
       
   611 // ---------------------------------------------------------------------------
       
   612 //
       
   613 TInt CTruiShortcutsContainer::CurrentItemIndex()
       
   614     {       
       
   615     return iListBox->CurrentItemIndex();
       
   616     }
       
   617 
       
   618 // ---------------------------------------------------------------------------
       
   619 // Test if the currently selected index is marked
       
   620 // ---------------------------------------------------------------------------
       
   621 //    
       
   622 TBool CTruiShortcutsContainer::IsMarked( TInt aSelectedIndex )
       
   623     {
       
   624     const CArrayFix<TInt>* aIndexArray = iListBox->SelectionIndexes();    
       
   625     for ( TInt index = 0; index < aIndexArray->Count(); index++ )
       
   626         {
       
   627         if ( aSelectedIndex == ( *aIndexArray )[index] )
       
   628             {
       
   629             return ETrue;
       
   630             }
       
   631         }
       
   632     return EFalse;        
       
   633     }
       
   634 
       
   635 // ---------------------------------------------------------------------------
       
   636 // Return the count of being marked currently.
       
   637 // ---------------------------------------------------------------------------
       
   638 // 
       
   639 TInt CTruiShortcutsContainer::MarkCount()
       
   640     {
       
   641     const CArrayFix<TInt>* aIndexArray = iListBox->SelectionIndexes();
       
   642     return aIndexArray->Count();
       
   643     }
       
   644 
       
   645 // ---------------------------------------------------------------------------
       
   646 // Create preview popup controller to show popup hwrbox.
       
   647 // ---------------------------------------------------------------------------
       
   648 // 
       
   649 CAknPreviewPopUpController* CTruiShortcutsContainer::CreatePopupHwrBoxL()
       
   650     {   
       
   651     iHwrBox = CTruiHwrBox::NewL( this, NULL );   
       
   652     iHwrBox->SetHwrBoxFlag( CTruiHwrBox::ENoFrameHwrBox 
       
   653                             | CTruiHwrBox::EReadOnlyHwrBox );
       
   654     CAknPreviewPopUpController* popupController =
       
   655                       CAknPreviewPopUpController::NewL
       
   656                       ( *iHwrBox, CAknPreviewPopUpController::EPermanentMode );
       
   657     popupController->AddObserverL( *this );
       
   658     return popupController;
       
   659     }
       
   660 
       
   661 // ---------------------------------------------------------------------------
       
   662 // Show the text tooltip.
       
   663 // ---------------------------------------------------------------------------
       
   664 //
       
   665 void CTruiShortcutsContainer::PopupHwrBoxL( const TPoint& aPosition, 
       
   666                            const TTimeIntervalMicroSeconds32& aShowDelay,
       
   667                            const TTimeIntervalMicroSeconds32& aHideDelay )
       
   668     {    
       
   669     if ( iPopupController && iHwrBox )
       
   670         {
       
   671         iPopupController->SetPosition( aPosition );
       
   672         // Set hwrbox's rect to engine and set guiding line to hwrbox
       
   673         iHwrBox->SetDisplayBottomGuideLine( ETrue );
       
   674         if ( iEngine->CurrentLanguageScript() == EMainViewSubmenuHebrew )
       
   675             {
       
   676             iHwrBox->SetDisplayTopGuideLine( ETrue );
       
   677             }        
       
   678         iPopupController->SetPopUpShowDelay( aShowDelay );
       
   679         iPopupController->SetPopUpHideDelay( aHideDelay );
       
   680         iPopupController->ShowPopUp();
       
   681         }
       
   682     }   
       
   683     
       
   684 // ---------------------------------------------------------------------------
       
   685 // Preview shortcut model in popup hwrbox.
       
   686 // ---------------------------------------------------------------------------
       
   687 //
       
   688 void CTruiShortcutsContainer::PreviewShortcutModelL( const TDesC& aShortcutText,
       
   689                                                      TInt aIndex )
       
   690     {
       
   691     // Get shortcut model
       
   692     if ( iEngine->CheckShortcutModel( aShortcutText ) )
       
   693         {        
       
   694         TRAPD( err, iEngine->GetShortcutModelL( aShortcutText, 
       
   695                                                 iHwrBox->Model(), 
       
   696                                                 iShortcutUnicode ) );
       
   697         if ( err == KErrNone )
       
   698             { 
       
   699             // Popup hwrbox
       
   700             // Get position for popup window
       
   701             TPoint itemPos = PopupWindowPosition( aIndex );            
       
   702             PopupHwrBoxL( itemPos,
       
   703                           KTooltipShowDelay,
       
   704                           KTooltipHideDelay );
       
   705             }
       
   706         }    
       
   707     }
       
   708     
       
   709 // ---------------------------------------------------------------------------
       
   710 // Called by the preview popup when an appropriate event takes place.
       
   711 // ---------------------------------------------------------------------------
       
   712 //
       
   713 void CTruiShortcutsContainer::HandlePreviewPopUpEventL(
       
   714       CAknPreviewPopUpController* aController, TPreviewPopUpEvent aEvent )
       
   715     {
       
   716     if ( aController == iPopupController && aEvent == EPreviewPopUpShown )
       
   717         {
       
   718         TSize refSize = CTruiContainerBase::OriginSymbolSize();       
       
   719         iHwrBox->ShowTrails( iHwrBox->Model(), ETrue, refSize );        
       
   720         iDisplayPopupWindow = EFalse;
       
   721         }
       
   722     else
       
   723         {
       
   724         iHwrBox->ClearExistModel();
       
   725         iHwrBox->DrawNow();
       
   726         iDisplayPopupWindow = ETrue;
       
   727         }
       
   728     }
       
   729 
       
   730 // ---------------------------------------------------------------------------
       
   731 // Create list box to display all shortcut
       
   732 // ---------------------------------------------------------------------------
       
   733 // 
       
   734 void CTruiShortcutsContainer::CreateListBoxL()
       
   735     {
       
   736     // listbox instance
       
   737     iListBox = new (ELeave) CAknSingleGraphicStyleListBox;
       
   738     Components().AppendLC( iListBox );
       
   739     CleanupStack::Pop( iListBox ); // iListBox
       
   740     
       
   741     // Construct listbox
       
   742     iListBox->ConstructL( this, EAknListBoxMarkableList ); 
       
   743 
       
   744     // Set container control
       
   745     iListBox->SetContainerWindowL( *this );
       
   746     
       
   747     // Set observer
       
   748     iListBox->SetListBoxObserver( this );
       
   749 
       
   750     // Add scrollbars to listbox
       
   751     iListBox->CreateScrollBarFrameL(ETrue);
       
   752     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   753         CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto );    
       
   754 
       
   755     // Get shortcut list from engine
       
   756     CDesCArray* primalList = iEngine->ShortcutTextList();   
       
   757 
       
   758     LoadTextArrayL( primalList );
       
   759 
       
   760     // construct icon array with granularity 3
       
   761     CArrayPtr<CGulIcon>* iconList = new (ELeave) CAknIconArray( KIconArraySize );
       
   762     CleanupStack::PushL( iconList );
       
   763     CFbsBitmap* bitmap;
       
   764     CFbsBitmap* bitmapm;
       
   765 
       
   766     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   767     AknsUtils::CreateColorIconL( skin,
       
   768                                  KAknsIIDQgnIndiMarkedAdd,
       
   769                                  KAknsIIDQsnIconColors,
       
   770                                  EAknsCIQsnIconColorsCG16,
       
   771                                  bitmap,
       
   772                                  bitmapm,
       
   773                                  KTRUIICONSFILENAME,
       
   774                                  EMbmTrui_iconsQgn_indi_marked_add,
       
   775                                  EMbmTrui_iconsQgn_indi_marked_add_mask,
       
   776                                  KRgbBlack
       
   777                                  ); 
       
   778     CleanupStack::PushL( bitmap );
       
   779     CleanupStack::PushL( bitmapm );
       
   780     CGulIcon* iconMark = CGulIcon::NewL( bitmap, bitmapm ); // Ownership transfered
       
   781     CleanupStack::Pop( bitmapm );
       
   782     CleanupStack::Pop( bitmap );                                   
       
   783     CleanupStack::PushL( iconMark );
       
   784     iconList->AppendL( iconMark );
       
   785     CleanupStack::Pop( iconMark );
       
   786     
       
   787     AknsUtils::CreateIconL( skin,
       
   788                             KAknsIIDQgnPropHwrTrainingShortcut,
       
   789                             bitmap,
       
   790                             bitmapm,
       
   791                             KTRUIICONSFILENAME,
       
   792                             EMbmTrui_iconsQgn_prop_hwrtraining_shortcut_new,
       
   793                             EMbmTrui_iconsQgn_prop_hwrtraining_shortcut_new_mask
       
   794                             );
       
   795     CleanupStack::PushL( bitmap );
       
   796     CleanupStack::PushL( bitmapm );    
       
   797     CGulIcon* iconNew = CGulIcon::NewL( bitmap, bitmapm ); // Ownership transfered
       
   798     CleanupStack::Pop( bitmapm );
       
   799     CleanupStack::Pop( bitmap );
       
   800     CleanupStack::PushL( iconNew );
       
   801     iconList->AppendL( iconNew );
       
   802     CleanupStack::Pop( iconNew );
       
   803 
       
   804     iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconList );
       
   805     
       
   806     CleanupStack::Pop( iconList ); // iconList
       
   807 
       
   808     iListBox->SetFocus( ETrue );
       
   809     // update listbox
       
   810     iListBox->ActivateL();    
       
   811     }
       
   812 
       
   813 // ---------------------------------------------------------------------------
       
   814 // Setup text data for listbox
       
   815 // ---------------------------------------------------------------------------
       
   816 // 
       
   817 void CTruiShortcutsContainer::LoadTextArrayL( const CDesCArray* aTextArray )
       
   818     {  
       
   819     // Construct listbox item array.
       
   820     // The items in the list contain an option of create new shortcut
       
   821     // and the primal shortcuts from HWR engine
       
   822     CDesCArray* itemList = new (ELeave) CDesCArrayFlat( KItemArraySize ); 
       
   823     CleanupStack::PushL(itemList);
       
   824           
       
   825     TBuf<KShortcutMaxLength> item;    
       
   826     HBufC* newShortcutText = StringLoader::LoadL( R_TRUI_SHORTCUTVIEW_NEW_SHORTCUT );
       
   827     item.Format( KListItemWithPicFormat, newShortcutText );
       
   828     delete newShortcutText;
       
   829     newShortcutText = NULL;
       
   830     itemList->AppendL(item);
       
   831     
       
   832     // if at least one shortcut exists
       
   833      if ( aTextArray )
       
   834         {
       
   835         // Item from WHR engine
       
   836         for ( TInt i=0; i < aTextArray->Count(); i++ )
       
   837             {
       
   838             TBuf<KShortcutMaxLength> itemPrimal;
       
   839             itemPrimal = aTextArray->MdcaPoint(i);
       
   840             item.Format( KListItemFormat, &itemPrimal );
       
   841             TBuf<KParaDelimiterSize> paraDelimiter;
       
   842             paraDelimiter.Format( KParaDelimiterFormat, EKeyEnter );
       
   843             AknTextUtils::ReplaceCharacters( item, paraDelimiter, TChar( EKeySpace ) );          
       
   844             itemList->AppendL( item );
       
   845             }        
       
   846         } 
       
   847     // set items and ownership
       
   848     CleanupStack::Pop( itemList );
       
   849     iListBox->Model()->SetItemTextArray( itemList );
       
   850     iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
   851     iListBox->HandleItemAdditionL();    
       
   852     }
       
   853     
       
   854 // ---------------------------------------------------------------------------
       
   855 // Popup context menu.
       
   856 // ---------------------------------------------------------------------------
       
   857 // 
       
   858 void CTruiShortcutsContainer::PopupContextMenuL( TInt aResourceId )
       
   859     {    
       
   860     // Hide popup preview window
       
   861     iPopupController->HidePopUp();  
       
   862     // Popup context menu  
       
   863     CEikMenuBar* parentMenuBar = iAppUi->View( KTruiShortcutsViewId )->MenuBar();
       
   864     if ( parentMenuBar )
       
   865         {
       
   866         parentMenuBar->SetMenuTitleResourceId( aResourceId );
       
   867         parentMenuBar->SetMenuType( CEikMenuBar::EMenuContext );
       
   868         parentMenuBar->TryDisplayMenuBarL();
       
   869         parentMenuBar->SetMenuTitleResourceId( R_TRUI_SHORTCUTSVIEW_MENUBAR );
       
   870         parentMenuBar->SetMenuType( CEikMenuBar::EMenuOptions );
       
   871         }    
       
   872     }
       
   873 
       
   874 // ---------------------------------------------------------------------------
       
   875 // Get position relative to screen origin for popup window.
       
   876 // ---------------------------------------------------------------------------
       
   877 // 
       
   878 TPoint CTruiShortcutsContainer::PopupWindowPosition( TInt aIndex )
       
   879     {
       
   880     // Place popup window to left-bottom
       
   881     TPoint itemPos = iListBox->View()->ItemPos( aIndex ) 
       
   882                      + iListBox->PositionRelativeToScreen();
       
   883     TSize itemSize = iListBox->View()->ItemSize( aIndex );    
       
   884     itemPos.iY += itemSize.iHeight;
       
   885     
       
   886     // if direction is upforwards.
       
   887     if ( Rect().iBr.iY + iListBox->PositionRelativeToScreen().iY - 
       
   888          ( itemPos.iY + iPopupController->Size().iHeight ) < 0 )
       
   889         {
       
   890         itemPos.iY -= ( itemSize.iHeight + iPopupController->Size().iHeight );
       
   891         }
       
   892         
       
   893     if ( TBidiText::ScriptDirectionality( User::Language() )
       
   894          ==  TBidiText::ELeftToRight )
       
   895         { // None-arabic,hebrew, place popup window to right-bottom
       
   896         itemPos.iX += itemSize.iWidth;
       
   897         // Sub width of scroll bar
       
   898         TInt scrollbarWidth = 0;
       
   899         if ( iListBox->ScrollBarFrame() )
       
   900             {
       
   901             scrollbarWidth = iListBox->ScrollBarFrame()
       
   902                              ->ScrollBarBreadth( CEikScrollBar::EVertical );
       
   903             }
       
   904         itemPos.iX -= scrollbarWidth;
       
   905         }
       
   906     else
       
   907         {
       
   908         itemPos.iX += iPopupController->Size().iWidth;        
       
   909         }
       
   910     return itemPos;
       
   911     }
       
   912     
       
   913 // ---------------------------------------------------------------------------
       
   914 // Check if need to preview shortcut and perform previewing necessarily.
       
   915 // ---------------------------------------------------------------------------
       
   916 // 
       
   917 TBool CTruiShortcutsContainer::CheckAndPreviewShortcutModelL( TInt aIndex )
       
   918     {
       
   919     TBool ret = EFalse;
       
   920     if ( aIndex > 0 )
       
   921         {
       
   922         // Get selected shortcut text
       
   923         CDesCArray* shortcutlist = iEngine->ShortcutTextList();
       
   924         TInt posInEngine = aIndex - 1;
       
   925         // Popup hwr box to preview
       
   926         PreviewShortcutModelL( shortcutlist->MdcaPoint( posInEngine ), aIndex );
       
   927         ret = ETrue;
       
   928         }
       
   929     else
       
   930         {
       
   931         iPopupController->HidePopUp();
       
   932         ret = EFalse;
       
   933         }    
       
   934     return ret;
       
   935     }
       
   936     
       
   937 // ---------------------------------------------------------------------------
       
   938 // Update buttons' status in toolbar
       
   939 // ---------------------------------------------------------------------------
       
   940 // 
       
   941 void CTruiShortcutsContainer::UpdateToolbarButtonStatus( TInt aIndex )
       
   942     {
       
   943     CAknToolbar* toolbar = iAppUi->View( KTruiShortcutsViewId )->Toolbar();
       
   944     if ( toolbar )
       
   945         {
       
   946         // Set edit text button's status
       
   947         CAknButton* editTextButton = static_cast<CAknButton*>
       
   948                     ( toolbar->ControlOrNull( EShortcutsViewButtonIdEditText ) );
       
   949         if ( editTextButton )
       
   950             {
       
   951             if ( aIndex > 0 )
       
   952                 {
       
   953                 if ( MarkCount() > 0 )
       
   954                     {
       
   955                     editTextButton->SetDimmed( ETrue );
       
   956                     }
       
   957                 else
       
   958                     {
       
   959                     editTextButton->SetDimmed( EFalse );
       
   960                     }
       
   961                 }
       
   962             else
       
   963                 {
       
   964                 editTextButton->SetDimmed( ETrue );
       
   965                 }
       
   966             editTextButton->DrawNow();
       
   967             }
       
   968             
       
   969         // Set edit model button's status
       
   970         CAknButton* editModelButton = static_cast<CAknButton*>
       
   971                     ( toolbar->ControlOrNull( EShortcutsViewButtonIdEditModel ) );
       
   972         if ( editModelButton )
       
   973             {
       
   974             if( aIndex > 0 )
       
   975                 {
       
   976                 if ( MarkCount() > 0 )
       
   977                     {
       
   978                     editModelButton->SetDimmed( ETrue );
       
   979                     }
       
   980                 else
       
   981                     {
       
   982                     CDesCArray* shortcutlist = iEngine->ShortcutTextList();
       
   983                     TInt posInEngine = aIndex - 1;
       
   984                     if ( iEngine->CheckShortcutModel
       
   985                                  ( shortcutlist->MdcaPoint( posInEngine ) ) )
       
   986                         {
       
   987                         // Shortcut model exist and allow to edit model.
       
   988                         editModelButton->SetDimmed( EFalse );
       
   989                         }
       
   990                     }
       
   991                 }
       
   992             else
       
   993                 {
       
   994                 editModelButton->SetDimmed( ETrue );
       
   995                 }
       
   996             editModelButton->DrawNow();
       
   997             }
       
   998                     
       
   999         // Set delete button's status            
       
  1000         CAknButton* deleteButton = static_cast<CAknButton*>
       
  1001                     ( toolbar->ControlOrNull( EShortcutsViewButtonIdDelete ) );
       
  1002         if ( deleteButton )  
       
  1003             {
       
  1004             TBool isDimmed = aIndex > 0 ? EFalse : ETrue;
       
  1005             deleteButton->SetDimmed( isDimmed );
       
  1006             deleteButton->DrawNow(); 
       
  1007             }
       
  1008         }
       
  1009     }