textinput/peninputhwrtrui/src/truishortcuteditcontainer.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     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 CTruiShortcutEditContainer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <eikedwin.h>
       
    20 #include <aknbutton.h>
       
    21 #include <eiklabel.h>
       
    22 #include <barsread.h>
       
    23 #include <aknnavide.h>
       
    24 #include <aknnotewrappers.h> 
       
    25 #include <trui.rsg>
       
    26 #include <AknsBasicBackgroundControlContext.h>
       
    27 #include <AknsDrawUtils.h>
       
    28 #include <aknlayoutscalable_apps.cdl.h>
       
    29 #include <avkon.rsg>
       
    30 #include <layoutmetadata.cdl.h>
       
    31 #include <akntoolbar.h>
       
    32 #include <aknSctDialog.h>
       
    33 
       
    34 #include "truicontainerbase.h"
       
    35 #include "truishortcuteditcontainer.h"
       
    36 #include "truihwrbox.h"
       
    37 #include "truiengine.h"
       
    38 #include "truiappui.h"
       
    39 #include "truishortcutsview.h"
       
    40 #include "truiapplication.h"
       
    41 #include "truiappradiobutton.h"
       
    42 #include "truishortcutsview.h"
       
    43 #include "truiapplication.h"
       
    44 #include "truishortcutedittextview.h"
       
    45 #include "trui.hrh"
       
    46 #include "truishortcuteditview.h"
       
    47 
       
    48 const TInt KSimilarMsgLength = 160;
       
    49 
       
    50 // The maximum number of lines for tips
       
    51 const TInt KIndicatorBufSize = 2;
       
    52 
       
    53 // The index of each item in radio button groups
       
    54 const TInt KOwnIndex = 0;
       
    55 const TInt KPresetIndex = 1;
       
    56 
       
    57 // Layout for portrait
       
    58 const TPoint KLabelTipPosPortrait = TPoint( 0, 0 );
       
    59 const TSize KLabelTipSizePortrait = TSize( 360, 60 );
       
    60 const TPoint KRadioPosPortrait = TPoint( 5, 73 );
       
    61 const TSize KRadioSizePortrait = TSize( 196, 99 );
       
    62 const TPoint KLeftBtnPosPotrait = TPoint( 115, 160 );
       
    63 const TPoint KIndicatorPosPotrait = TPoint( 165, 160 );
       
    64 const TPoint KRightBtnPosPotrait = TPoint( 215, 160 );
       
    65 const TPoint KHwrBoxPosPortrait = TPoint( 90, 215 );
       
    66 
       
    67 const TSize KButtonSize = TSize( 50, 50 );
       
    68 
       
    69 // Layout for landscape
       
    70 const TPoint KRadioPosLandscape = TPoint( 5, 18 );
       
    71 const TPoint KLabelTipPosLandscape = TPoint( 5, 120 );
       
    72 const TSize KLabelTipSizeLandscape = TSize( 250, 120 );
       
    73 
       
    74 const TPoint KLeftBtnPos = TPoint( 300, 15 );
       
    75 
       
    76 const TPoint KRightBtnPos = TPoint( 400, 15 );
       
    77 const TPoint KIndicatorPosLandscape = TPoint( 350, 15 );
       
    78 const TSize KHwrBoxSizeLandscape = TSize( 200, 200 );
       
    79 const TPoint KHwrBoxPosLandscape = TPoint( 275, 80 );
       
    80 
       
    81 const TInt KTooltipPopupTimeOut = 0;
       
    82 const TInt KTooltipStayTimeOut = 3000;
       
    83 
       
    84 const TInt KSctBufferSize = 32;
       
    85 const TInt KHwrTooltipY = 20;
       
    86 
       
    87 _LIT( KActiveCharFormat, "%c" );
       
    88 
       
    89 // Varity of landscape for common components
       
    90 const TInt KVarityLandscape = 3;
       
    91 
       
    92 // Varity of portrait for common components
       
    93 const TInt KVarityPortrait = 2;
       
    94 
       
    95 const TInt KVarityListPane = 1;
       
    96 
       
    97 // ======== MEMBER FUNCTIONS ========
       
    98 
       
    99 CTruiShortcutEditContainer::CTruiShortcutEditContainer()
       
   100     {  
       
   101     iActiveCharPos = KErrNotFound;
       
   102     }
       
   103     
       
   104 void CTruiShortcutEditContainer::ConstructL( const TRect& aRect )
       
   105     {    
       
   106     // Initialize control array
       
   107     InitComponentArrayL();
       
   108         
       
   109     // Set parent control or owning window
       
   110     CreateWindowL();
       
   111 
       
   112     iBackGround = CAknsBasicBackgroundControlContext::NewL
       
   113                   ( KAknsIIDQsnBgAreaMain, Rect(), EFalse);
       
   114     
       
   115     // Initialize controls
       
   116     InitializeControlsL();       
       
   117     
       
   118 #ifdef TRAININGUI_FOR_PRESET
       
   119     // Get all presets from Engine
       
   120     HBufC* presetHBuf = iEikonEnv->AllocReadResourceLC( R_TRUI_PRESET_SYMBOLS );
       
   121     for ( TInt i = 0; i < presetHBuf->Length(); i++ )
       
   122         {
       
   123         iPresets.Append( ( *presetHBuf )[i] );
       
   124         }
       
   125     CleanupStack::PopAndDestroy( presetHBuf );        
       
   126 #endif
       
   127       
       
   128     // Load setting data
       
   129     CTruiShortcutEditView* view = static_cast<CTruiShortcutEditView*>
       
   130                            ( iAppUi->View( KTruiShortcutEditViewId ) );
       
   131     
       
   132     if ( view->PreviousViewId() == TVwsViewId( KUidtruiApp, KTruiShortcutsViewId ) )
       
   133         {
       
   134         // Edit old shortcut
       
   135         iEngine->GetShortcutModelL( iEngine->Shortcut(), 
       
   136                                     iHwrBox->Model(), 
       
   137                                     iUnicode );
       
   138         // Backup shortcut model
       
   139         BackupShortcutModel( iHwrBox->Model(), iUnicode );
       
   140         // Load the current active char whether is own or preset.
       
   141         iShortcutType = iUnicode ? KPresetIndex : KOwnIndex;
       
   142         iIsEmptyHwrBox = iUnicode ? ETrue : EFalse;
       
   143 #ifdef TRAININGUI_FOR_PRESET
       
   144         if ( iUnicode )
       
   145             {
       
   146             // Edit preset shortcut
       
   147             iActiveCharPos = iPresets.Find( iUnicode );
       
   148             }
       
   149         else
       
   150             {
       
   151             // Edit own shortcut, get the first available preset shortcut
       
   152             if ( FindFirstAvailableCharL( 0, iPresets.Count() - 1, 1, iUnicode ) )
       
   153                 {
       
   154                 iActiveCharPos = iPresets.Find( iUnicode );
       
   155                 }
       
   156             else
       
   157                 {        
       
   158                 iActiveCharPos = KErrNotFound;
       
   159                 }            
       
   160             }
       
   161 #endif
       
   162         }
       
   163     else
       
   164         {
       
   165         // Create new shortcut        
       
   166         // Load the current active char whether is own or preset.
       
   167         iShortcutType = KOwnIndex;
       
   168         iIsEmptyHwrBox = ETrue;
       
   169 #ifdef TRAININGUI_FOR_PRESET
       
   170         if ( FindFirstAvailableCharL( 0, iPresets.Count() - 1, 1, iUnicode ) )
       
   171             {
       
   172             iActiveCharPos = iPresets.Find( iUnicode );
       
   173             }
       
   174         else
       
   175             {        
       
   176             iActiveCharPos = KErrNotFound;
       
   177             }
       
   178 #endif
       
   179         }
       
   180 
       
   181     // Set radio button
       
   182     iRadioButtonContainer->HandlePointerRadioButtonL( iShortcutType, 
       
   183                                                       EEventRequestFocus );
       
   184     SetRect( aRect );
       
   185     
       
   186     ActivateL();
       
   187     }
       
   188     
       
   189 CTruiShortcutEditContainer* CTruiShortcutEditContainer::NewL( const TRect& aRect )
       
   190     {
       
   191     CTruiShortcutEditContainer* self = CTruiShortcutEditContainer::NewLC( aRect );
       
   192     CleanupStack::Pop( self );
       
   193     return self;
       
   194     }
       
   195     
       
   196 CTruiShortcutEditContainer* CTruiShortcutEditContainer::NewLC( const TRect& aRect )
       
   197     {
       
   198     CTruiShortcutEditContainer* self = new (ELeave) CTruiShortcutEditContainer();
       
   199     CleanupStack::PushL( self );
       
   200     self->ConstructL( aRect );
       
   201     return self;
       
   202     }
       
   203     
       
   204 CTruiShortcutEditContainer::~CTruiShortcutEditContainer()
       
   205     {
       
   206     delete iBackGround;
       
   207     delete iLabeltext;
       
   208     delete iWrappedLabelText;
       
   209     iModelBak.Close();
       
   210     iPresets.Close();
       
   211     iLineWidthArray.Close();
       
   212     }
       
   213     
       
   214 // ---------------------------------------------------------------------------
       
   215 // Create controls to be displayed in this container.
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CTruiShortcutEditContainer::InitializeControlsL()
       
   219     {
       
   220     // Create fixed toolbar
       
   221     CAknToolbar* toolbar = iAppUi->View( KTruiShortcutEditViewId )->Toolbar();
       
   222     // Get Clear button from toolbar    
       
   223     CAknButton* clearButton = static_cast<CAknButton*>
       
   224                     ( toolbar->ControlOrNull( EShortcutEditViewDelete ) );
       
   225 
       
   226     CreateRadioButtonL();         
       
   227 
       
   228     CcnstructButtonL();
       
   229     
       
   230     CreateLabelL();
       
   231     
       
   232     CreateHwrBoxL();
       
   233     }
       
   234     
       
   235 // ---------------------------------------------------------------------------
       
   236 // From class CCoeControl.
       
   237 // Responds to changes to the size and position of the contents of this control.
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CTruiShortcutEditContainer::SizeChanged()
       
   241     {
       
   242     TInt varity = Layout_Meta_Data::IsLandscapeOrientation() ? KVarityLandscape
       
   243                                                              : KVarityPortrait;
       
   244     DoSizeChanged( varity );
       
   245     // Set hwrbox's rect to engine and set guiding line to hwrbox
       
   246     iHwrBox->SetDisplayBottomGuideLine( ETrue );
       
   247     TBool isDisplayTopGuideLine = ( iEngine->CurrentLanguageScript() 
       
   248                              == EMainViewSubmenuHebrew ) ? ETrue : EFalse;
       
   249     
       
   250     iHwrBox->SetDisplayTopGuideLine( isDisplayTopGuideLine );
       
   251         
       
   252     if ( varity == KVarityLandscape )
       
   253         {
       
   254         DoLayoutLandscape();
       
   255         }
       
   256     else if ( varity == KVarityPortrait )  
       
   257         {
       
   258         DoLayoutPortait();
       
   259         }
       
   260     if ( iBackGround )
       
   261         {
       
   262         iBackGround->SetRect( Rect() );
       
   263         }    
       
   264     }
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // Layout under landscape condition.
       
   268 // ---------------------------------------------------------------------------
       
   269 //    
       
   270 void CTruiShortcutEditContainer::DoLayoutLandscape()
       
   271     {    
       
   272 #ifdef TRAININGUI_FOR_PRESET  
       
   273     iRadioButtonContainer->SetRect( TRect( KRadioPosLandscape, 
       
   274                                            KRadioSizePortrait ) );
       
   275     iLeftBtn->SetRect( TRect( KLeftBtnPos, KButtonSize ) );
       
   276     iRightBtn->SetRect( TRect( KRightBtnPos, KButtonSize ) );
       
   277     iIndicator->SetRect( TRect( KIndicatorPosLandscape, KButtonSize ) );
       
   278 #endif
       
   279     }
       
   280     
       
   281 // ---------------------------------------------------------------------------
       
   282 // Layout under portait condition.
       
   283 // ---------------------------------------------------------------------------
       
   284 //    
       
   285 void CTruiShortcutEditContainer::DoLayoutPortait()
       
   286     {
       
   287 #ifdef TRAININGUI_FOR_PRESET
       
   288     iRadioButtonContainer->SetRect( TRect( KRadioPosPortrait, 
       
   289                                            KRadioSizePortrait ) );    
       
   290     iLeftBtn->SetRect( TRect( KLeftBtnPosPotrait, KButtonSize ) );
       
   291     iRightBtn->SetRect( TRect( KRightBtnPosPotrait, KButtonSize ) );
       
   292     iIndicator->SetRect( TRect( KIndicatorPosPotrait, KButtonSize ) );
       
   293 #endif
       
   294     }    
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // Save own shortcut.
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 void CTruiShortcutEditContainer::SaveOwnShortcutL( const TDesC& aShortcut, 
       
   301                                                    RArray<TPoint>& aModel,
       
   302                                                    TDes& aErrMsg )
       
   303     {
       
   304     // Ensure the shortcut doesn't exist.
       
   305     if ( iEngine->CheckShortcutModel( aShortcut ) )
       
   306         {
       
   307         iEngine->DeleteShortcut( aShortcut );
       
   308         }
       
   309     if ( aModel.Count() )
       
   310         {
       
   311         iEngine->SaveShortcutL( aShortcut, aModel, aErrMsg );
       
   312         }
       
   313     }    
       
   314     
       
   315 // ---------------------------------------------------------------------------
       
   316 // Save preset shortcut.
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 void CTruiShortcutEditContainer::SavePresetShortcutL( const TDesC& aShortcut, 
       
   320                                                       TUint aUnicode )
       
   321     {
       
   322     // Ensure the shortcut doesn't exist.
       
   323     if ( iEngine->CheckShortcutModel( aShortcut ) )
       
   324         {
       
   325         iEngine->DeleteShortcut( aShortcut );
       
   326         }
       
   327     // Check if aUnicode is in use.
       
   328     RArray<TPoint> presetModel;
       
   329     CleanupClosePushL( presetModel );
       
   330     TBuf<KSimilarMsgLength> msg;
       
   331     iEngine->GetPresetSymbolByUnicodeL( aUnicode, presetModel, msg );
       
   332     if ( msg.Length() > 0 )
       
   333         {
       
   334         // In use, being assigned to some shortcut.
       
   335         User::Leave( KErrInUse );
       
   336         }
       
   337     CleanupStack::PopAndDestroy( &presetModel );
       
   338     iEngine->SavePresetShortcutL( aUnicode, aShortcut );
       
   339     }
       
   340 
       
   341 // ---------------------------------------------------------------------------
       
   342 // Backup shortcut model. It is probably to be restored when press Back to exit.
       
   343 // ---------------------------------------------------------------------------
       
   344 //
       
   345 void CTruiShortcutEditContainer::BackupShortcutModel
       
   346                                  ( const RArray<TPoint>& aOriginalModel,
       
   347                                    TUint aOriginalUnicode )
       
   348     {
       
   349     iUnicodeBak = aOriginalUnicode;
       
   350     if ( !iUnicodeBak )
       
   351         {
       
   352         // If old shortcut is own, it is necessary to store trails.
       
   353         // If it is preset, backup is unecessary
       
   354         for ( TInt i = 0; i < aOriginalModel.Count(); i++ )
       
   355             {
       
   356             iModelBak.Append( aOriginalModel[i] );
       
   357             }        
       
   358         }    
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // Set active char.
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 void CTruiShortcutEditContainer::SetActiveCharL( TUint aUnicode )
       
   366     {
       
   367     // Set active indicator
       
   368     TBuf<KIndicatorBufSize> preset;
       
   369 
       
   370     // Preset symbol
       
   371     preset.Format( KActiveCharFormat, aUnicode );
       
   372     iIndicator->SetTextL( preset );        
       
   373     iIndicator->DrawNow();    
       
   374     // Clear hwrbox and stop playing animation    
       
   375     iHwrBox->ClearExistModel();
       
   376     // Get model
       
   377     TBuf<KSimilarMsgLength> similarMsg;
       
   378     iEngine->GetPresetSymbolByUnicodeL( aUnicode, iHwrBox->Model(),
       
   379                                         similarMsg );
       
   380     // Play animation in HwrBox 
       
   381     iHwrBox->ModelIsReady( ETrue );
       
   382     if ( iShortcutType == KPresetIndex )
       
   383         {
       
   384         // As for preset, need to scale trails size firstly
       
   385         iHwrBox->PlayAnimation( ETrue, CTruiContainerBase::OriginSymbolSize() );
       
   386         }
       
   387     else
       
   388         {
       
   389         iHwrBox->PlayAnimation();
       
   390         }    
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // Find the first available preset symbol.
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 TBool CTruiShortcutEditContainer::FindFirstAvailableCharL( TInt aStartPos, 
       
   398                                                            TInt aEndPos,
       
   399                                                            TInt aDirection, 
       
   400                                                            TUint& aUnicode )
       
   401     {
       
   402     while ( aStartPos != aEndPos && aStartPos < iPresets.Count() )
       
   403         {
       
   404         if ( !CheckPresetSymbolInUseL( iPresets[aStartPos] ) )
       
   405             {            
       
   406             aUnicode = iPresets[aStartPos];
       
   407             return ETrue;
       
   408             }
       
   409         else
       
   410             {
       
   411             // In use
       
   412             if ( iUnicodeBak == iPresets[aStartPos] )
       
   413                 {
       
   414                 // But the preset symbol is the old preset 
       
   415                 // which users are editting, 
       
   416                 // Still display the symbol in indicator                
       
   417                 aUnicode = iPresets[aStartPos];
       
   418                 return ETrue;
       
   419                 }
       
   420             }
       
   421         if ( aDirection )
       
   422             {
       
   423             // Go right           
       
   424             aStartPos = ( ++aStartPos + iPresets.Count() ) % iPresets.Count();
       
   425             }
       
   426         else
       
   427             {
       
   428             // Go left
       
   429             aStartPos = ( --aStartPos + iPresets.Count() ) % iPresets.Count();
       
   430             }                    
       
   431         }
       
   432     if ( aEndPos < iPresets.Count() && !CheckPresetSymbolInUseL( iPresets[aEndPos] ) )
       
   433         {
       
   434         aUnicode = iPresets[aEndPos];
       
   435         return ETrue;
       
   436         }      
       
   437     return EFalse;           
       
   438     }
       
   439     
       
   440 // ---------------------------------------------------------------------------
       
   441 // Return if the preset is in use.
       
   442 // ---------------------------------------------------------------------------
       
   443 //
       
   444 TBool CTruiShortcutEditContainer::CheckPresetSymbolInUseL( TUint aUnicode )
       
   445     {
       
   446     // Check if iUnicode is in use
       
   447     RArray<TPoint> presetModels;
       
   448     CleanupClosePushL( presetModels );
       
   449     TBuf<KSimilarMsgLength> similarMsg;      
       
   450     iEngine->GetPresetSymbolByUnicodeL( aUnicode,
       
   451                                         presetModels,
       
   452                                         similarMsg );
       
   453     CleanupStack::PopAndDestroy( &presetModels );
       
   454     if ( similarMsg.Length() )
       
   455         {
       
   456         return ETrue;
       
   457         }
       
   458     return EFalse;
       
   459     }
       
   460 
       
   461 // ---------------------------------------------------------------------------
       
   462 // Do something to response to size changed.
       
   463 // ---------------------------------------------------------------------------
       
   464 // 
       
   465 void CTruiShortcutEditContainer::DoSizeChanged( TInt aVarity )
       
   466     {
       
   467     TRect rect = Rect();
       
   468     
       
   469     TAknWindowComponentLayout main_pane_layout = 
       
   470                             AknLayoutScalable_Apps::main_hwr_training_pane();
       
   471     TAknLayoutRect main_pane_layout_rect;
       
   472     main_pane_layout_rect.LayoutRect( rect, main_pane_layout );
       
   473     TRect main_pane_rect = main_pane_layout_rect.Rect();
       
   474         
       
   475     // hwr_training_write_pane
       
   476     TAknWindowComponentLayout write_pane_layout = 
       
   477                AknLayoutScalable_Apps::hwr_training_write_pane( aVarity );
       
   478     TAknLayoutRect write_pane_layout_rect;
       
   479     write_pane_layout_rect.LayoutRect( main_pane_rect, write_pane_layout );
       
   480     iHwrBox->SetRect( write_pane_layout_rect.Rect() );
       
   481     
       
   482     TPoint hwrPos = iHwrBox->PositionRelativeToScreen();
       
   483     iHwrBox->SetTooltipPosition( hwrPos + TPoint( iHwrBox->Size().iWidth, KHwrTooltipY ) );
       
   484 
       
   485     // hwr_training_instruct_pane
       
   486     TAknWindowComponentLayout instruct_pane_layout = 
       
   487                AknLayoutScalable_Apps::hwr_training_instruct_pane( aVarity );
       
   488     TAknLayoutRect instruct_pane_layout_rect;
       
   489     instruct_pane_layout_rect.LayoutRect( main_pane_rect, instruct_pane_layout );    
       
   490     // count of text rows
       
   491     TInt count = AknLayoutScalable_Apps::
       
   492                  list_single_hwr_training_instruct_pane_ParamLimits( KVarityListPane )
       
   493                  .LastRow() + 1;
       
   494 
       
   495     // array contains all text rows in help screen
       
   496     RArray<TAknTextComponentLayout> textLayoutArray;
       
   497     iLineWidthArray.Reset();
       
   498     for( TInt i = 0; i < count; i++ )
       
   499         {
       
   500         // pane area for each row
       
   501         TAknWindowComponentLayout each_row_layout =  
       
   502             AknLayoutScalable_Apps::list_single_hwr_training_instruct_pane
       
   503             ( KVarityListPane, 0, i );
       
   504         TAknLayoutRect each_row_layout_rect;
       
   505         each_row_layout_rect.LayoutRect( instruct_pane_layout_rect.Rect(), 
       
   506                                          each_row_layout );
       
   507         iLineWidthArray.Append( each_row_layout_rect.Rect().Width() );
       
   508         // smaller pane for text itself
       
   509         TAknTextComponentLayout each_row_text_layout =  
       
   510             AknLayoutScalable_Apps::list_single_hwr_training_instruct_pane_t1();
       
   511     
       
   512         // composition of two latter componets
       
   513         TAknTextComponentLayout textCompCompositionWiz = 
       
   514             TAknWindowComponentLayout::ComposeText(
       
   515                 each_row_layout, each_row_text_layout );
       
   516  
       
   517         TRAPD(error, textLayoutArray.AppendL( textCompCompositionWiz ) );
       
   518         // if error in append function, then just exit the loop      
       
   519         if ( error != KErrNone )
       
   520             {
       
   521             break;
       
   522             }
       
   523         }       
       
   524     iMultilineLayout = TAknTextComponentLayout::Multiline( textLayoutArray ); 
       
   525     if ( iLabeltext && iWrappedLabelText )
       
   526         {
       
   527         // Be ready to show label
       
   528         TAknLayoutText multilineTextLayout;
       
   529         multilineTextLayout.LayoutText( instruct_pane_layout_rect.Rect(), iMultilineLayout );    
       
   530         const CFont* font = AknLayoutUtils::FontFromId( iMultilineLayout.FontId() );
       
   531         TRAPD( err, WrapLabelTextL( font, *iLabeltext, iLineWidthArray, iWrappedLabelText ) );
       
   532         if ( err == KErrNone )
       
   533             {
       
   534             TRAP_IGNORE( iLabelTip->SetTextL( *iWrappedLabelText ) );
       
   535             }
       
   536         else
       
   537             {
       
   538             TRAP_IGNORE( iLabelTip->SetTextL( *iLabeltext ) );
       
   539             }        
       
   540         AknLayoutUtils::LayoutLabel( iLabelTip, 
       
   541                                      instruct_pane_layout_rect.Rect(), 
       
   542                                      iMultilineLayout );
       
   543         }
       
   544     textLayoutArray.Close();
       
   545 
       
   546     TRgb labelColor = KRgbBlack;
       
   547     TInt error = GetCachedLabelTextColor( labelColor );
       
   548     if ( error == KErrNone )
       
   549         {
       
   550         TRAP_IGNORE( iLabelTip->OverrideColorL( EColorLabelText, labelColor ) );
       
   551         TRAP_IGNORE( iIndicator->OverrideColorL( EColorLabelText, labelColor ) );
       
   552         }
       
   553     }
       
   554         
       
   555 // ---------------------------------------------------------------------------
       
   556 // Create radio button.
       
   557 // ---------------------------------------------------------------------------
       
   558 //    
       
   559 void CTruiShortcutEditContainer::CreateRadioButtonL()
       
   560     {
       
   561     iRadioButtonContainer = CTruiRadioButton::NewL( this,
       
   562                                              CTruiRadioButton::ERadioButton,
       
   563                                              this );
       
   564     Components().AppendLC( iRadioButtonContainer );
       
   565     CleanupStack::Pop( iRadioButtonContainer );
       
   566     
       
   567     HBufC* radioTextOwn = iEikonEnv->AllocReadResourceLC
       
   568                              ( R_TRUI_SHORTCUTEDITMODELVIEW_RADIOBUTTON_OWN );
       
   569     iRadioButtonContainer->AddItem( radioTextOwn, CTruiRadioButton::ENonSelected );
       
   570     CleanupStack::Pop( radioTextOwn ); // transfered ownership
       
   571     HBufC* radioTextPreset = iEikonEnv->AllocReadResourceLC
       
   572                              ( R_TRUI_SHORTCUTEDITMODELVIEW_RADIOBUTTON_PRESET );
       
   573     iRadioButtonContainer->AddItem( radioTextPreset, CTruiRadioButton::ENonSelected );
       
   574     CleanupStack::Pop( radioTextPreset ); // transfered ownership
       
   575     iRadioButtonContainer->HandleItemAdditionL();
       
   576     }
       
   577    
       
   578 // ---------------------------------------------------------------------------
       
   579 // Create HWR box to write and play model
       
   580 // ---------------------------------------------------------------------------
       
   581 //    
       
   582 void CTruiShortcutEditContainer::CreateHwrBoxL()
       
   583     {
       
   584     CTruiHwrBox* hwrBox = CTruiHwrBox::NewL( this, this, iBackGround );    
       
   585     hwrBox->SetHwrBoxFlag( CTruiHwrBox::EFrameHwrBox );
       
   586     Components().AppendLC( hwrBox );
       
   587     hwrBox->ActivateL();    
       
   588     CleanupStack::Pop( hwrBox );
       
   589     iHwrBox = hwrBox;
       
   590     }
       
   591 
       
   592 // ---------------------------------------------------------------------------
       
   593 // Create buttons.
       
   594 // ---------------------------------------------------------------------------
       
   595 //    
       
   596 void CTruiShortcutEditContainer::CcnstructButtonL()
       
   597     {
       
   598     // Left button for last character
       
   599     CAknButton* preButton = CreateButtonL( R_MAINVIEW_BUTTON_LEFT,
       
   600                                            this,
       
   601                                            this );
       
   602     Components().AppendLC( preButton );
       
   603     CleanupStack::Pop( preButton );    
       
   604     iLeftBtn = preButton;
       
   605 
       
   606     // Right button for next character
       
   607     CAknButton* nextButton = CreateButtonL( R_MAINVIEW_BUTTON_RIGHT,
       
   608                                            this,
       
   609                                            this );
       
   610     Components().AppendLC( nextButton );
       
   611     CleanupStack::Pop( nextButton );    
       
   612     iRightBtn = nextButton;    
       
   613     }
       
   614 
       
   615 // ---------------------------------------------------------------------------
       
   616 // Create buttons.
       
   617 // ---------------------------------------------------------------------------
       
   618 //    
       
   619 void CTruiShortcutEditContainer::CreateLabelL()
       
   620     {
       
   621     //Create label tip
       
   622     CEikLabel* tipLabel = new (ELeave) CEikLabel();
       
   623     CleanupStack::PushL( tipLabel );    
       
   624     tipLabel->SetContainerWindowL( *this );
       
   625     tipLabel->SetTextL( KNullDesC );
       
   626     tipLabel->ActivateL();
       
   627     CleanupStack::Pop( tipLabel );
       
   628     Components().AppendLC( tipLabel );
       
   629     CleanupStack::Pop( tipLabel );
       
   630     iLabelTip = tipLabel;    
       
   631 
       
   632     // Create active character indicator
       
   633     CEikLabel* aknLabel = new (ELeave) CEikLabel();
       
   634     CleanupStack::PushL( aknLabel );
       
   635     aknLabel->SetContainerWindowL( *this );
       
   636     aknLabel->SetObserver( this );
       
   637     aknLabel->SetAlignment( 
       
   638          TGulAlignmentValue ( EEikLabelAlignHCenter|EEikLabelAlignVCenter ) );
       
   639     aknLabel->SetTextL( KNullDesC );
       
   640     aknLabel->ActivateL();
       
   641     CleanupStack::Pop( aknLabel );
       
   642     Components().AppendLC( aknLabel );    
       
   643     CleanupStack::Pop( aknLabel );     
       
   644     iIndicator = aknLabel;
       
   645     iIndicator->SetObserver( this );    
       
   646     }
       
   647     
       
   648 // ---------------------------------------------------------------------------
       
   649 // Draw.
       
   650 // ---------------------------------------------------------------------------
       
   651 //    
       
   652 void CTruiShortcutEditContainer::Draw( const TRect& /*aRect*/ ) const
       
   653     {
       
   654     // Get the standard graphics context
       
   655     CWindowGc& gc = SystemGc();
       
   656     // Gets the control's extent
       
   657     TRect rect( Rect());
       
   658     // Clears the screen
       
   659     gc.Clear( rect );
       
   660 
       
   661     MAknsSkinInstance* skin = AknsUtils::SkinInstance();  
       
   662     if ( AknsDrawUtils::HasBitmapBackground( skin, iBackGround ) ) 
       
   663         {
       
   664         AknsDrawUtils::Background( skin, iBackGround, gc, rect );
       
   665         }   
       
   666     }
       
   667 
       
   668 // ---------------------------------------------------------------------------
       
   669 // Switch to shortcuts view.
       
   670 // ---------------------------------------------------------------------------
       
   671 //  
       
   672 void CTruiShortcutEditContainer::SwitchToShortcutViewL()
       
   673     {    
       
   674     // Update shortcut list
       
   675     iEngine->UpdateShortcutListL();
       
   676     // Find the current shortcut's index in shortcut list
       
   677     CDesCArray* shortcutList = iEngine->ShortcutTextList();
       
   678     TInt index = DefaultSelectedIndex( shortcutList, iEngine->Shortcut() );
       
   679     if ( index == KErrNotFound )
       
   680         {
       
   681         TInt oldIndex = iEngine->CurrentSelectedIndex();
       
   682         if ( shortcutList )
       
   683             {
       
   684             index = ( oldIndex > shortcutList->Count() ) 
       
   685                                ? shortcutList->Count() : oldIndex;
       
   686             }
       
   687         else
       
   688             {
       
   689             index = 0;
       
   690             }
       
   691         }
       
   692        
       
   693     // Set current index in Engine
       
   694     iEngine->SetCurrentSelectedIndex( index );
       
   695 
       
   696     // Close tooltip
       
   697     iHwrBox->HideInfoPopupNote();
       
   698 
       
   699     iAppUi->ActivateLocalViewL( KTruiShortcutsViewId );
       
   700     // Show NaviDecorator
       
   701     iAppUi->ShowNaviPaneL();
       
   702     }
       
   703 
       
   704 // ---------------------------------------------------------------------------
       
   705 // Go back to previous view
       
   706 // ---------------------------------------------------------------------------
       
   707 //  
       
   708 void CTruiShortcutEditContainer::BackToPreviousViewL()
       
   709     {
       
   710     if ( iIsRestored )
       
   711         {
       
   712         // Check if restore the old shortcut
       
   713         if ( iUnicodeBak )
       
   714             {
       
   715             // Old shortcut is preset, restore it.
       
   716             SavePresetShortcutL( iEngine->Shortcut(), iUnicodeBak );
       
   717             }
       
   718         else
       
   719             {
       
   720             // Old shortcut is own, restore it.
       
   721             // Or create new shortcut
       
   722             TBuf<KSimilarMsgLength> similarMsg;
       
   723             SaveOwnShortcutL( iEngine->Shortcut(), iModelBak, similarMsg );
       
   724             }        
       
   725         }  
       
   726         
       
   727     // Close tooltip
       
   728     iHwrBox->HideInfoPopupNote();
       
   729     
       
   730     // Show NaviDecorator      
       
   731     CTruiShortcutEditView* view = static_cast<CTruiShortcutEditView*>
       
   732                            ( iAppUi->View( KTruiShortcutEditViewId ) );
       
   733     iAppUi->ActivateLocalViewL( view->PreviousViewId().iViewUid );
       
   734     
       
   735     if ( view->PreviousViewId() == TVwsViewId( KUidtruiApp, KTruiShortcutsViewId ) )
       
   736         {
       
   737         iAppUi->ShowNaviPaneL();        
       
   738         }    
       
   739     }
       
   740     
       
   741 // ---------------------------------------------------------------------------
       
   742 // Handles an event from an observed control.
       
   743 // ---------------------------------------------------------------------------
       
   744 //     
       
   745 void CTruiShortcutEditContainer::HandleControlEventL( CCoeControl* aControl,
       
   746                                                       TCoeEvent aEventType )
       
   747     {
       
   748     if ( aControl == iLeftBtn && aEventType == EEventStateChanged )
       
   749         {        
       
   750         if ( iActiveCharPos != KErrNotFound )
       
   751             {
       
   752             // Edit an old preset
       
   753             // Find first available preset, otherwise, show error note all in use
       
   754             // Create a new preset shortcut but at least one is available
       
   755             // Find first available preset, otherwise, nothing to do
       
   756             TInt startPos = ( iActiveCharPos - 1 + iPresets.Count() ) 
       
   757                             % iPresets.Count();
       
   758             TInt endPos = ( iActiveCharPos + 1 + iPresets.Count() ) 
       
   759                             % iPresets.Count();       
       
   760             if ( FindFirstAvailableCharL( startPos, endPos, 0, iUnicode ) )
       
   761                 {
       
   762                 iActiveCharPos = iPresets.Find( iUnicode );
       
   763                 SetActiveCharL( iUnicode ); 
       
   764                 }
       
   765             else if ( !iEngine->NewShortcut() )
       
   766                 {
       
   767                 // if Create a new preset shortcut but at least one is available
       
   768                 // nothing to do
       
   769                 // show error note : all in use
       
   770                 PopupTooltipL( R_TRUI_SHORTCUTEDITVIEW_ERROR_NOTE_ALL_IN_USE );
       
   771                 }
       
   772             }
       
   773         else
       
   774             {
       
   775             // Create a new preset, but all in use
       
   776             // Show error note
       
   777             PopupTooltipL( R_TRUI_SHORTCUTEDITVIEW_ERROR_NOTE_ALL_IN_USE );
       
   778             }
       
   779         }
       
   780     else if ( aControl == iRightBtn && aEventType == EEventStateChanged )
       
   781         {
       
   782         if ( iActiveCharPos != KErrNotFound )
       
   783             {
       
   784             // Edit an old preset
       
   785             // Find first available preset, otherwise, show error note all in use
       
   786             // Create a new preset shortcut but at least one is available
       
   787             // Find first available preset, otherwise, nothing to do
       
   788             TInt startPos = ( iActiveCharPos + 1 + iPresets.Count() ) 
       
   789                             % iPresets.Count();
       
   790             TInt endPos = ( iActiveCharPos - 1 + iPresets.Count() ) 
       
   791                             % iPresets.Count();       
       
   792             if ( FindFirstAvailableCharL( startPos, endPos, 1, iUnicode ) )
       
   793                 {
       
   794                 iActiveCharPos = iPresets.Find( iUnicode );
       
   795                 SetActiveCharL( iUnicode ); 
       
   796                 }
       
   797             else if ( !iEngine->NewShortcut() )
       
   798                 {
       
   799                 // show error note : all in use
       
   800                 PopupTooltipL( R_TRUI_SHORTCUTEDITVIEW_ERROR_NOTE_ALL_IN_USE );
       
   801                 }
       
   802             }
       
   803         else
       
   804             {
       
   805             // Create a new preset, but all in use
       
   806             // Show error note
       
   807             PopupTooltipL( R_TRUI_SHORTCUTEDITVIEW_ERROR_NOTE_ALL_IN_USE );
       
   808             }
       
   809         }
       
   810     else if ( iShortcutType == KPresetIndex && aControl == iIndicator 
       
   811               && aEventType == EEventRequestFocus )
       
   812         {
       
   813         PreviewShortcutModel();
       
   814         }
       
   815     }
       
   816 
       
   817 // ---------------------------------------------------------------------------
       
   818 // From class MTruiHWRBoxObserver.
       
   819 // Handle the save model event
       
   820 // ---------------------------------------------------------------------------
       
   821 //
       
   822 void CTruiShortcutEditContainer::SaveNewModelL()
       
   823     {
       
   824     // Carry out saving new model
       
   825     if ( iShortcutType == KOwnIndex )
       
   826         {
       
   827         iIsRestored = ETrue;
       
   828         
       
   829         // If shortcut is own, it will save new model
       
   830         TBuf<KSimilarMsgLength> similarMsg;
       
   831         TRAPD( err, SaveOwnShortcutL( iEngine->Shortcut(), 
       
   832                                       iHwrBox->Model(), 
       
   833                                       similarMsg ) );
       
   834         switch ( err )
       
   835             {
       
   836             case KErrNone:
       
   837                 {
       
   838                 iIsEmptyHwrBox = EFalse;
       
   839                 CAknToolbar* toolbar = iAppUi->View( KTruiShortcutEditViewId )
       
   840                                              ->Toolbar();
       
   841                 CAknButton* clearBtn = static_cast<CAknButton*>
       
   842                           ( toolbar->ControlOrNull( EShortcutEditViewDelete ) );
       
   843                 clearBtn->SetDimmed( EFalse );
       
   844                 clearBtn->DrawNow(); 
       
   845                 CAknButton* previewBtn = static_cast<CAknButton*>
       
   846                           ( toolbar->ControlOrNull( EShortcutEditViewPreviewModel ) );
       
   847                 previewBtn->SetDimmed( EFalse );
       
   848                 previewBtn->DrawNow(); 
       
   849 
       
   850                 TPoint hwrPos = iHwrBox->PositionRelativeToScreen();
       
   851                 HBufC* tooltipText = 
       
   852                         iEikonEnv->AllocReadResourceLC( R_TRUI_TOOLTIP_SAVED );
       
   853                 iHwrBox->ShowTooltipL( *tooltipText, 
       
   854                                   hwrPos + TPoint( iHwrBox->Size().iWidth, KHwrTooltipY ),
       
   855                                        KTooltipPopupTimeOut, 
       
   856                                        KTooltipStayTimeOut );
       
   857                 CleanupStack::PopAndDestroy( tooltipText );
       
   858                 break;
       
   859                 }
       
   860             case KErrAlreadyExists:
       
   861                 {
       
   862                 //Clear invalid model
       
   863                 ClearCurrentModelL();
       
   864                 
       
   865                 //Popup err message
       
   866                 PopupTooltipL( R_TRUI_SHORTCUTEDITVIEW_ERROR_NOTE_IN_USE );
       
   867                 break;
       
   868                 }
       
   869                 
       
   870             }
       
   871         }       
       
   872     }
       
   873 
       
   874 // ---------------------------------------------------------------------------
       
   875 // From class MTruiHWRBoxObserver.
       
   876 // Handle the message event from the HWRBox
       
   877 // ---------------------------------------------------------------------------
       
   878 //
       
   879 void CTruiShortcutEditContainer::HandleEventL( TMessageType aMessage )
       
   880     {
       
   881     if ( aMessage == EModelExist )
       
   882         {
       
   883         PopupTooltipL( R_TRUI_NOTE_CLEAR_BOX );
       
   884         }
       
   885     }
       
   886 
       
   887 // ---------------------------------------------------------------------------
       
   888 // From class MTruiHWRBoxObserver.
       
   889 // Notify that which radio button is selected.
       
   890 // ---------------------------------------------------------------------------
       
   891 //
       
   892 void CTruiShortcutEditContainer::SelectChangedL( TInt aIndex )
       
   893     {
       
   894     // Change the text below radio buttons
       
   895     TInt tipResource = aIndex ? R_TRUI_SHORTCUTEDITVIEW_PRESET_SYMBOL
       
   896                               : R_TRUI_SHORTCUTEDITVIEW_OWN_SYMBOL;    
       
   897     delete iLabeltext;
       
   898     iLabeltext = NULL;
       
   899     iLabeltext = iEikonEnv->AllocReadResourceL( tipResource );
       
   900     delete iWrappedLabelText;
       
   901     iWrappedLabelText = NULL;
       
   902     // count of text rows
       
   903     TInt lines = AknLayoutScalable_Apps::
       
   904                  list_single_hwr_training_instruct_pane_ParamLimits( KVarityListPane )
       
   905                  .LastRow() + 1;         
       
   906     iWrappedLabelText = HBufC::NewL( iLabeltext->Length() + lines
       
   907                                      + KExtraSize );
       
   908     // Be ready to show label
       
   909     const CFont* font = AknLayoutUtils::FontFromId( iMultilineLayout.FontId() );
       
   910     TRAPD( err, WrapLabelTextL( font, *iLabeltext, iLineWidthArray, iWrappedLabelText ) );
       
   911     if ( err == KErrNone )
       
   912         {
       
   913         iLabelTip->SetTextL( *iWrappedLabelText );
       
   914         }
       
   915     else
       
   916         {
       
   917         iLabelTip->SetTextL( *iLabeltext );
       
   918         }
       
   919     // Get Clear button from toolbar
       
   920     CAknToolbar* toolbar = iAppUi->View( KTruiShortcutEditViewId )->Toolbar();
       
   921     CAknButton* clearBtn = static_cast<CAknButton*>
       
   922                 ( toolbar->ControlOrNull( EShortcutEditViewDelete ) );
       
   923     CAknButton* gridBtn = static_cast<CAknButton*>
       
   924                 ( toolbar->ControlOrNull( EShortcutEditViewGrid ) );
       
   925     // Dim left and right buttons when selecting "own symbol"
       
   926     TBool btnDimmed = aIndex ? EFalse : ETrue;
       
   927     iLeftBtn->SetDimmed( btnDimmed );
       
   928     iLeftBtn->DrawNow();
       
   929     iRightBtn->SetDimmed( btnDimmed );
       
   930     iRightBtn->DrawNow();
       
   931 
       
   932     // Set grid button status
       
   933     gridBtn->SetDimmed( btnDimmed );
       
   934     gridBtn->DrawNow();
       
   935 
       
   936     // Set active indicator
       
   937     TBuf<KIndicatorBufSize> preset;
       
   938     if ( aIndex && iUnicode )
       
   939         {
       
   940         // Preset symbol
       
   941         preset.Format( KActiveCharFormat, iUnicode );
       
   942         }
       
   943     else
       
   944         {
       
   945         // Own
       
   946         preset.Copy( KNullDesC );
       
   947         }
       
   948     iIndicator->SetTextL( preset );        
       
   949     iIndicator->DrawNow();    
       
   950 
       
   951     // Update current shortcut type
       
   952     iShortcutType = aIndex;   
       
   953 
       
   954     // Clear hwrbox and stop playing animation    
       
   955     iHwrBox->ClearExistModel();
       
   956     
       
   957     if ( iShortcutType == KPresetIndex )
       
   958         {
       
   959         // If preset shortcut, get trail points.
       
   960         TBuf<KSimilarMsgLength> similarMsg;
       
   961         iEngine->GetPresetSymbolByUnicodeL( iUnicode, 
       
   962                                             iHwrBox->Model(), similarMsg );
       
   963         iHwrBox->ModelIsReady( ETrue );
       
   964         iHwrBox->PlayAnimation( ETrue, CTruiContainerBase::OriginSymbolSize() );
       
   965         }
       
   966     else if ( !iIsEmptyHwrBox )
       
   967         {
       
   968         // If own shortcut, get trail points
       
   969         TUint unicode = 0;
       
   970         iEngine->GetShortcutModelL( iEngine->Shortcut(), iHwrBox->Model(),
       
   971                                     unicode );
       
   972         iHwrBox->ModelIsReady( ETrue );
       
   973         iHwrBox->PlayAnimation();
       
   974         }
       
   975 
       
   976     // Set hwrbox model
       
   977     if ( iShortcutType == KPresetIndex )
       
   978         {        
       
   979         iHwrBox->SetHwrBoxReadOnly( ETrue );        
       
   980         }
       
   981     else
       
   982         {
       
   983         iHwrBox->SetHwrBoxReadOnly( EFalse );
       
   984         }
       
   985     
       
   986     // Set clear button's status
       
   987     clearBtn->SetDimmed( !( iHwrBox->Model().Count() ) | aIndex );
       
   988     clearBtn->DrawNow();
       
   989 
       
   990     // Set preview button status
       
   991     CAknButton* previewBtn = static_cast<CAknButton*>
       
   992               ( toolbar->ControlOrNull( EShortcutEditViewPreviewModel ) );
       
   993 
       
   994     previewBtn->SetDimmed( !( iHwrBox->Model().Count() | aIndex ) );
       
   995     previewBtn->DrawNow();
       
   996     }
       
   997     
       
   998 // ---------------------------------------------------------------------------
       
   999 // Preview shortcut model
       
  1000 // ---------------------------------------------------------------------------
       
  1001 //
       
  1002 void CTruiShortcutEditContainer::PreviewShortcutModel()
       
  1003     {
       
  1004     //even hwrbox know if current character has existing model.
       
  1005     //ask for engine to confirm this
       
  1006     iHwrBox->PlayAnimation(); 
       
  1007     }
       
  1008 
       
  1009 // ---------------------------------------------------------------------------
       
  1010 // Check if model exist
       
  1011 // ---------------------------------------------------------------------------
       
  1012 //
       
  1013 TBool CTruiShortcutEditContainer::HasShortcutModel()
       
  1014     {    
       
  1015     return EFalse;
       
  1016     }
       
  1017     
       
  1018 // ---------------------------------------------------------------------------
       
  1019 // Prepare to exit
       
  1020 // ---------------------------------------------------------------------------
       
  1021 //
       
  1022 TBool CTruiShortcutEditContainer::PrepareToExitL()
       
  1023     {
       
  1024     iHwrBox->HideInfoPopupNote();
       
  1025     //If previous char's model is not saved, save it before exit.
       
  1026     if ( iHwrBox->BoxState() == CTruiHwrBox::ENewModelDraw )
       
  1027         {
       
  1028         //Call save function from hwrbox,
       
  1029         //in order to stop periodics in the hwrbox
       
  1030         iHwrBox->SaveModelByManuallyL();
       
  1031         }
       
  1032         
       
  1033     //After saving model, if shortcut model is empty,
       
  1034     //notice user that shortcut will be delete.
       
  1035     if ( iHwrBox->Model().Count() == 0 )
       
  1036         {
       
  1037         // Not assign model to shortcut
       
  1038         CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
  1039         if ( dlg->ExecuteLD( R_TRUI_QUERYDIALOG_SHORTCUT_NOT_ASSIGNED ) )
       
  1040             {
       
  1041             // yes/ok pressed
       
  1042             iEngine->DeleteShortcut( iEngine->Shortcut() );
       
  1043             return ETrue;
       
  1044             }
       
  1045         else
       
  1046             {
       
  1047             return EFalse;
       
  1048             }
       
  1049         }
       
  1050     else
       
  1051         {
       
  1052         if ( iShortcutType == KPresetIndex )
       
  1053             {
       
  1054             // Save preset
       
  1055             // No need to save own preset again, because it has been saved before.
       
  1056             TRAPD( err, SavePresetShortcutL( iEngine->Shortcut(), iUnicode ) );
       
  1057             if ( err == KErrInUse )
       
  1058                 {
       
  1059                 // Pop information note
       
  1060                 HBufC* errMsg = iEikonEnv->AllocReadResourceLC
       
  1061                               ( R_TRUI_SHORTCUTEDITVIEW_ERROR_NOTE_IN_USE );
       
  1062                 CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote 
       
  1063                                                                     ( ETrue );
       
  1064                 note->ExecuteLD( *errMsg );                
       
  1065                 CleanupStack::PopAndDestroy( errMsg );
       
  1066                 return EFalse;
       
  1067                 }                
       
  1068             }
       
  1069         }
       
  1070     return ETrue;
       
  1071     }
       
  1072 
       
  1073 // ---------------------------------------------------------------------------
       
  1074 // Clear current model
       
  1075 // ---------------------------------------------------------------------------
       
  1076 //
       
  1077 void CTruiShortcutEditContainer::ClearCurrentModelL()
       
  1078     {
       
  1079     // Get Clear button from toolbar
       
  1080     CAknToolbar* toolbar = iAppUi->View( KTruiShortcutEditViewId )->Toolbar();    
       
  1081     CAknButton* clearBtn = static_cast<CAknButton*>
       
  1082                 ( toolbar->ControlOrNull( EShortcutEditViewDelete ) );    
       
  1083     clearBtn->SetDimmed( ETrue );
       
  1084     clearBtn->DrawNow();
       
  1085     
       
  1086     // Set preview button status
       
  1087     CAknButton* previewBtn = static_cast<CAknButton*>
       
  1088               ( toolbar->ControlOrNull( EShortcutEditViewPreviewModel ) );
       
  1089 
       
  1090     previewBtn->SetDimmed( ETrue );
       
  1091     previewBtn->DrawNow();
       
  1092 
       
  1093     iHwrBox->ClearExistModel();
       
  1094     HBufC* tipText = iEikonEnv->AllocReadResourceLC( R_TRUI_TOOLTIP_DELETED );
       
  1095     TPoint hwrPos = iHwrBox->PositionRelativeToScreen();
       
  1096     iHwrBox->ShowTooltipL( *tipText, 
       
  1097                            hwrPos + TPoint( iHwrBox->Size().iWidth, KHwrTooltipY ),
       
  1098                            KTooltipPopupTimeOut, KTooltipStayTimeOut );
       
  1099     CleanupStack::PopAndDestroy( tipText ); 
       
  1100     iIsEmptyHwrBox = ETrue;
       
  1101     }
       
  1102     
       
  1103 // ---------------------------------------------------------------------------
       
  1104 // Popup tooltip
       
  1105 // ---------------------------------------------------------------------------
       
  1106 //    
       
  1107 void CTruiShortcutEditContainer::PopupTooltipL( TInt aResourceID )
       
  1108     {
       
  1109     HBufC* tooltiptext =iEikonEnv->AllocReadResourceLC( aResourceID );
       
  1110     CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
       
  1111     note->ExecuteLD( *tooltiptext );
       
  1112     CleanupStack::PopAndDestroy( tooltiptext );
       
  1113     }
       
  1114 
       
  1115 // ---------------------------------------------------------------------------
       
  1116 // This is called whenever the control gains or loses focus, 
       
  1117 // ---------------------------------------------------------------------------
       
  1118 // 
       
  1119 void CTruiShortcutEditContainer::FocusChanged( TDrawNow /*aDrawNow*/ )
       
  1120     {
       
  1121     if ( IsFocused() )
       
  1122         {
       
  1123         if ( iHwrBox->BoxState() == CTruiHwrBox::EExistModelStop )
       
  1124             {
       
  1125             iHwrBox->ResumePlaying();
       
  1126             }
       
  1127         }
       
  1128     else
       
  1129         {
       
  1130         if ( iHwrBox->BoxState() == CTruiHwrBox::EExistModelDraw )
       
  1131             {
       
  1132             iHwrBox->PausePlaying();
       
  1133             }
       
  1134         }
       
  1135     iHwrBox->SetFocus( IsFocused() );
       
  1136     }
       
  1137 
       
  1138 // ---------------------------------------------------------------------------
       
  1139 // Return the currently selected index, which will be set in Shortcuts view.
       
  1140 // ---------------------------------------------------------------------------
       
  1141 //
       
  1142 TInt CTruiShortcutEditContainer::DefaultSelectedIndex( const CDesCArray* aItemList,
       
  1143                                                        const TDesC& aText )
       
  1144     {    
       
  1145     if ( aItemList )
       
  1146         {
       
  1147         for ( TInt i = 0; i < aItemList->Count(); i++ )
       
  1148             {        
       
  1149             if ( (*aItemList)[i].Compare( aText ) == 0 )
       
  1150                 {
       
  1151                 return i + 1;
       
  1152                 }
       
  1153             }
       
  1154         }
       
  1155     return KErrNotFound;
       
  1156     }
       
  1157 
       
  1158 // ---------------------------------------------------------------------------
       
  1159 // Popup SCT dialog.
       
  1160 // ---------------------------------------------------------------------------
       
  1161 //
       
  1162 void CTruiShortcutEditContainer::PopupSctDialogL()
       
  1163     {
       
  1164     TBuf<KSctBufferSize> selectedStr;
       
  1165     CAknCharMapDialog* sct = new (ELeave) CAknCharMapDialog( EAknSCTLowerCase, 
       
  1166                                            selectedStr, 
       
  1167                                            R_TRUI_SCT_CHARSET_PRESET );    
       
  1168     TInt keyboardMode = CurrentKeyBoardModeL(); 
       
  1169     if ( keyboardMode )
       
  1170         {
       
  1171         // QWERTY: Lock numeric keys.
       
  1172         sct->LockNumericKeys( ETrue );
       
  1173         }
       
  1174     else
       
  1175         {
       
  1176         // ITU-T: Unlock numeric keys.
       
  1177         sct->LockNumericKeys( EFalse );
       
  1178         }
       
  1179     sct->DisableRecentCharsRow();
       
  1180     if ( sct->ExecuteLD( R_TRUI_SCT_DIALOG ) )
       
  1181         {        
       
  1182         TInt selectedUnicode = selectedStr.Length() ? selectedStr[0] : NULL;
       
  1183         TBool isInUse = CheckPresetSymbolInUseL( selectedUnicode );
       
  1184         if ( isInUse && selectedUnicode != iUnicodeBak )
       
  1185             {
       
  1186             // Preset is in use
       
  1187             //Popup err message
       
  1188             PopupTooltipL( R_TRUI_SHORTCUTEDITVIEW_ERROR_NOTE_IN_USE );
       
  1189             return;
       
  1190             }
       
  1191         else
       
  1192             {
       
  1193             TInt activePos = iPresets.Find( selectedUnicode );
       
  1194             
       
  1195             // Set active char pos
       
  1196             iActiveCharPos = ( activePos != KErrNotFound ) ? activePos : 0;
       
  1197             iUnicode = iPresets[iActiveCharPos];
       
  1198             SetActiveCharL( selectedUnicode );            
       
  1199             }        
       
  1200         }
       
  1201     }
       
  1202 
       
  1203 // ---------------------------------------------------------------------------
       
  1204 // From class CCoeControl.
       
  1205 // Handles a change to the control's resources.
       
  1206 // ---------------------------------------------------------------------------
       
  1207 //
       
  1208 void CTruiShortcutEditContainer::HandleResourceChange( TInt aType )
       
  1209     {
       
  1210     CTruiContainerBase::HandleResourceChange( aType );
       
  1211     if ( aType == KEikDynamicLayoutVariantSwitch && iHwrBox )
       
  1212         {
       
  1213         if ( iHwrBox->BoxState() == CTruiHwrBox::ENewModelDraw )
       
  1214             {
       
  1215             TRAP_IGNORE( iHwrBox->SaveModelByManuallyL() );
       
  1216             }        
       
  1217         }    
       
  1218 
       
  1219     if ( aType == KAknsMessageSkinChange )
       
  1220         {
       
  1221         TRgb labelColor = KRgbBlack;
       
  1222         TInt error = GetCachedLabelTextColor( labelColor );
       
  1223         if ( error == KErrNone )
       
  1224             {
       
  1225             TRAPD( errLable, iLabelTip->OverrideColorL( EColorLabelText, 
       
  1226                                                         labelColor ) );
       
  1227             if ( errLable != KErrNone )
       
  1228                 {
       
  1229                 return;
       
  1230                 }
       
  1231             TRAP_IGNORE( iIndicator->OverrideColorL( EColorLabelText, 
       
  1232                                                      labelColor ) );
       
  1233             }        
       
  1234         }         
       
  1235     }