fep/aknfep/src/aknfepinputstatecandidatepinyinphrasecreation.cpp
changeset 36 a7632c26d895
parent 35 0f326f2e628e
child 42 b3eaa440ab06
equal deleted inserted replaced
35:0f326f2e628e 36:a7632c26d895
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:           
       
    15 *       Provides the aknfepinputstatecandidatepinyinphrasecreation definition.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 // System includes
       
    31 #include <PtiEngine.h>   
       
    32 #include <avkon.rsg>
       
    33 #include <aknfep.rsg>
       
    34 //#include <aknquerydialog.h> //CAknQueryDialog  
       
    35 
       
    36 // User includes
       
    37 #include "aknfepinputstatecandidatepinyinphrasecreation.h"
       
    38 #include "AknFepUiCtrlContainerChinese.h"
       
    39 #include "AknFepUICtrlCandidatePane.h"
       
    40 #include "AknFepUICtrlPinyinPopup.h"        //Pinyin phrase
       
    41 #include "aknfepuictrleditpane.h"           //pinyin phrase creation
       
    42 #include "AknFepUIManagerStateInterface.h"  
       
    43 #include "AknFepManager.h"     
       
    44 
       
    45 // Constant definition
       
    46 const TInt KMinCnadidateCount = 1;
       
    47 const TInt KMaxSpellingLength = 10;
       
    48 const TInt KMaxPhraseCreationCount = 7;
       
    49 
       
    50 //add  the max phrase is seven
       
    51 _LIT( KMaxPhraseNote,"\x8BCD\x7EC4\x6700\x957F\x4E3A\x4E03\x5B57" );
       
    52 
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // AknFepUiInputStateCandidatePinyinAndStrokePhrase::
       
    56 // TAknFepUiInputStateCandidatePinyinAndStrokePhrase
       
    57 // (other items were commented in a header).
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 TAknFepInputStateCandidatePinyinPhraseCreation::
       
    61     TAknFepInputStateCandidatePinyinPhraseCreation(
       
    62         MAknFepUIManagerStateInterface* aOwner,
       
    63         MAknFepUICtrlContainerChinese* aUIContainer) :
       
    64         TAknFepInputStatePinyinPhraseCreationBase( aOwner, aUIContainer)
       
    65     {
       
    66     iState = ECandidateSelection;
       
    67     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
    68     
       
    69     TBool multiplePages = !(uiContainer->CandidatePane()->IsLastPage() &&
       
    70                             uiContainer->CandidatePane()->IsFirstPage());
       
    71     TInt bufLength = iOwner->PtiEngine()->CandidatePage().Length();
       
    72     TBool showHorizontalScrollArrows = multiplePages || bufLength > KMinCnadidateCount;
       
    73 
       
    74     uiContainer->ShowHorizontalScrollArrows(showHorizontalScrollArrows); 
       
    75     uiContainer->ShowVerticalScrollArrows(ETrue);
       
    76     uiContainer->FocusCandidatePane(ETrue);
       
    77     uiContainer->CandidatePane()->ShowCandidateOrdinals(ETrue);
       
    78     uiContainer->CandidatePane()->SelectFirstPhrase();
       
    79     uiContainer->SetFepMan( iOwner->FepMan() );
       
    80     
       
    81     UpdateIndicator();
       
    82     ChangeCba();
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // TAknFepInputStateCandidatePinyinPhraseCreation::HandleKeyL
       
    87 // (other items were commented in a header).
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 TBool TAknFepInputStateCandidatePinyinPhraseCreation::HandleKeyL(TInt aKey,
       
    91                                                                  TKeyPressLength aLength)
       
    92     {
       
    93     switch( aKey )
       
    94         {
       
    95         case EKeyBackspace:
       
    96             KeyBackspace();
       
    97             break;
       
    98         case EKeyCBA2:
       
    99             iOwner->FepMan()->TryCloseUiL();
       
   100             break;
       
   101         default:
       
   102             HandleKeyUpDownLeftRightArrowOrKeyCBA1OKL( aKey, aLength );
       
   103             break;
       
   104         }
       
   105     return ETrue;
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------
       
   109 // Update indicator.
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 void TAknFepInputStateCandidatePinyinPhraseCreation::UpdateIndicator()
       
   113     {
       
   114     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();        
       
   115     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
   116         
       
   117     if (candidatePane->IsFirstPage())
       
   118         {
       
   119         uiContainer->CandidatePane()->ShowUpScrollArrows(EFalse);    
       
   120         }
       
   121     else
       
   122         {
       
   123         uiContainer->CandidatePane()->ShowUpScrollArrows(ETrue);    
       
   124         }
       
   125     if ( candidatePane->IsLastPage() )
       
   126        {
       
   127        uiContainer->CandidatePane()->ShowDownScrollArrows(EFalse);
       
   128        }
       
   129     else
       
   130        {
       
   131        uiContainer->CandidatePane()->ShowDownScrollArrows(ETrue);      
       
   132        }
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------
       
   136 // Handle horizontal navigation.
       
   137 // ---------------------------------------------------------
       
   138 //
       
   139 TBool TAknFepInputStateCandidatePinyinPhraseCreation::HandleHorizontalNavigation(TInt aKey)
       
   140     {
       
   141     MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
       
   142     TBool response = EFalse;
       
   143 
       
   144     // Do navigation...
       
   145     if (aKey == EKeyLeftArrow)
       
   146         {
       
   147         if( !candidatePane->SelectPrev() )
       
   148             {
       
   149             candidatePane->SetCandidateBuffer();
       
   150             candidatePane->SelectLastPhrase();
       
   151             }
       
   152         response = ETrue;
       
   153         }
       
   154     else if (aKey == EKeyRightArrow)
       
   155         {                  
       
   156         if( !candidatePane->SelectNext() )
       
   157             {
       
   158             candidatePane->SetCandidateBuffer();
       
   159             candidatePane->SelectFirstPhrase();
       
   160             }
       
   161         response = ETrue;
       
   162         }
       
   163         
       
   164     if (response)
       
   165         {
       
   166         UpdateIndicator();
       
   167         }   
       
   168              
       
   169     return response;
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------
       
   173 // Handle vertical navigation.
       
   174 // ---------------------------------------------------------
       
   175 //
       
   176 TBool TAknFepInputStateCandidatePinyinPhraseCreation::HandleVerticalNavigation(TInt aKey)
       
   177     {
       
   178     MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
       
   179 
       
   180     if (aKey == EKeyDownArrow)
       
   181         {
       
   182         if (candidatePane->IsLastPage())
       
   183             {
       
   184             return ETrue;
       
   185             }                
       
   186         candidatePane->NextCandidatePage();
       
   187         }
       
   188     else if (aKey == EKeyUpArrow)
       
   189         {
       
   190         if (candidatePane->IsFirstPage() )
       
   191             {
       
   192             return ETrue;   
       
   193             }       
       
   194         candidatePane->PreviousCandidatePage();
       
   195         }
       
   196     else
       
   197         {
       
   198         return EFalse;
       
   199         }
       
   200     candidatePane->SetCandidateBuffer();
       
   201     candidatePane->SelectFirstPhrase();
       
   202     UpdateIndicator(); 
       
   203 
       
   204     return ETrue;
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------
       
   208 // Commit inline to the EEP ctrl.
       
   209 // ---------------------------------------------------------
       
   210 //
       
   211 TBool TAknFepInputStateCandidatePinyinPhraseCreation::CommitInlineEEPL( const TDesC& aText )
       
   212     {
       
   213     MAknFepUICtrlPinyinPopup* popup = UIContainer()->PinyinPopupWindow();
       
   214     CDesCArrayFlat* keystrokeArray = popup->ShowKeystrokeArray();
       
   215     CDesCArrayFlat* validKeystroke = popup->InEffectKeystrokeArray();
       
   216     CDesCArrayFlat* chooseChineseCharacterArray = 
       
   217         popup->ChooseChineseCharacterArray();
       
   218     CDesCArrayFlat* chooseChineseCharacterArrayKeystroke = 
       
   219         popup->ChooseChineseCharacterArrayKeystroke();
       
   220     TInt keyCount = validKeystroke->Count();
       
   221     
       
   222     TBuf<KMaxSpellingLength> keystroke;
       
   223     
       
   224     popup->SetPhraseCreationState( ETrue );
       
   225     
       
   226     for ( TInt i = 0; i < keyCount; i++ )
       
   227         {
       
   228         keystroke.Append( keystrokeArray->MdcaPoint( 0 ) );
       
   229         keystrokeArray->Delete( 0 );
       
   230         }
       
   231     
       
   232     chooseChineseCharacterArray->AppendL( aText );
       
   233     chooseChineseCharacterArrayKeystroke->AppendL( keystroke );
       
   234     validKeystroke->Reset();
       
   235     
       
   236     if ( chooseChineseCharacterArray->Count() >= KMaxPhraseCreationCount )
       
   237         {
       
   238         keystrokeArray->Reset();
       
   239         CDesCArrayFlat* phraseCandidates = 
       
   240             UIContainer()->CandidatePane()->CandidateArray();
       
   241         phraseCandidates->Reset();
       
   242         phraseCandidates->AppendL( KMaxPhraseNote );
       
   243         RefreshUI( 0 );
       
   244         return EFalse;
       
   245         }  
       
   246     return keystrokeArray->Count();
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------
       
   250 // KeyBackspace.
       
   251 // ---------------------------------------------------------
       
   252 //
       
   253 void TAknFepInputStateCandidatePinyinPhraseCreation::KeyBackspace()
       
   254     {
       
   255     MAknFepUICtrlPinyinPopup* popup = UIContainer()->PinyinPopupWindow();
       
   256     // there is  "ChangeCba()" before 
       
   257     popup->SetChangeState( ETrue );
       
   258     iOwner->ChangeState(ESpellingSelection);
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------
       
   262 // Key Up,Down,Left,RightArrow Or Key CBA1,OK.
       
   263 // ---------------------------------------------------------
       
   264 //
       
   265 void TAknFepInputStateCandidatePinyinPhraseCreation::HandleKeyUpDownLeftRightArrowOrKeyCBA1OKL( 
       
   266                                      TInt aKey, 
       
   267                                      TKeyPressLength aLength )
       
   268     {
       
   269     MAknFepUICtrlPinyinPopup* popup = UIContainer()->PinyinPopupWindow();
       
   270     MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
       
   271     TInt index = MapKeyToIndex(aKey);
       
   272            
       
   273     if ( aKey == EKeyUpArrow &&
       
   274         iOwner->FepMan()->InputMode() == EPinyin &&
       
   275         candidatePane->IsFirstPage())
       
   276         {
       
   277         popup->SetChangeState( ETrue );
       
   278         iOwner->ChangeState(ESpellingSelection);
       
   279         return;
       
   280         }
       
   281     TBool state = ETrue;
       
   282     if ( popup->IsChangeStatet() && aLength == ELongKeyPress )
       
   283         {
       
   284         state = EFalse;
       
   285         }
       
   286     else
       
   287         {
       
   288         popup->SetChangeState( EFalse );
       
   289         }
       
   290     
       
   291     if ( state )
       
   292        {
       
   293        if ( !(HandleVerticalNavigation( aKey )
       
   294            || HandleHorizontalNavigation( aKey ) ) )
       
   295          {
       
   296               // it may be one of the 'valid' numbers..
       
   297            if ( candidatePane->SelectIndex( index, EFalse ) || aKey == EKeyOK
       
   298                || aKey == EKeyCBA1 )
       
   299               {
       
   300                ChangeStateOrNotL(); 
       
   301               }
       
   302            ChangeCba();
       
   303           }
       
   304        }
       
   305     }
       
   306    
       
   307 // ---------------------------------------------------------
       
   308 // change the state or not 
       
   309 // ---------------------------------------------------------
       
   310 //
       
   311 void TAknFepInputStateCandidatePinyinPhraseCreation::ChangeStateOrNotL()
       
   312 	{
       
   313 	 MAknFepUICtrlPinyinPopup* popup = UIContainer()->PinyinPopupWindow();
       
   314 	 MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
       
   315     TPtrC text = candidatePane->CurrentPhraseCandidate();
       
   316     if ( text.Length() )
       
   317         {
       
   318         CDesCArrayFlat* chooseChineseCharacterArray =
       
   319             popup->ChooseChineseCharacterArray();
       
   320         //here need Commit text to EEP and change 
       
   321         //state to EEP entry state if keystroke is empty
       
   322         //else keep spelling state 
       
   323         if ( chooseChineseCharacterArray->Count() < KMaxPhraseCreationCount )
       
   324             {
       
   325             if ( !CommitInlineEEPL( text ) )
       
   326                 {
       
   327                 popup->SetChangeState( ETrue );
       
   328                 iOwner->ChangeState( EKeySequenceEdit );
       
   329                 TBool visible =
       
   330                     ( chooseChineseCharacterArray->Count() == KMaxPhraseCreationCount );
       
   331                 UIContainer()->SetControlInVisible( visible );
       
   332                 }
       
   333             else
       
   334                 {
       
   335                 if ( !popup->IsEnabled() )
       
   336                     {
       
   337                     popup->Enable( ETrue );
       
   338                     }
       
   339                 if ( !GetValidKeystroke() )
       
   340                     {
       
   341                     UIContainer()->SetControlInVisible( EFalse );
       
   342                     popup->SetChangeState( ETrue );
       
   343                     iOwner->ChangeState( EKeySequenceEdit );
       
   344                     }
       
   345                 else
       
   346                     {
       
   347                     popup->SetChangeState( ETrue );
       
   348                     iOwner->ChangeState( ESpellingSelection );
       
   349                     }
       
   350                 }
       
   351             }
       
   352         else
       
   353             {
       
   354             popup->SetChangeState( ETrue );
       
   355             iOwner->ChangeState( EKeySequenceEdit );
       
   356             }
       
   357         }
       
   358     else
       
   359         {
       
   360         // No candidates available. Back to Entry state.
       
   361         popup->SetChangeState( ETrue );
       
   362         iOwner->ChangeState( EKeySequenceEdit );
       
   363         }
       
   364     }
       
   365 
       
   366 
       
   367 // End of file