fep/aknfep/src/aknfepuiinputstateentrypinyinphrasecreation.cpp
changeset 0 eb1f2e154e89
child 3 f5a1e66df979
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     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 TAknFepInputStateEntryPinyinPhraseCreation methods.
       
    16  *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include <PtiEngine.h>                          //CPtiEngine
       
    31 #include <PtiUserDicEntry.h>
       
    32 
       
    33 #include <PtiDefs.h>                            //keys
       
    34 #include <avkon.rsg>
       
    35 #include <AknFep.rsg>
       
    36 #include <aknnotewrappers.h>
       
    37 
       
    38 #include "AknFepPanic.h"
       
    39 #include "aknfepuiinputstateentrypinyinphrasecreation.h"
       
    40 #include "AknFepUIManagerStateInterface.h"      //MAknFepUIManagerStateInterface
       
    41 #include "AknFepManagerUIInterface.h"           //MAknFepManagerUIInterface
       
    42 #include "AknFepUiCtrlContainerChinese.h"
       
    43 #include "AknFepUICtrlInputPane.h"
       
    44 #include "AknFepUICtrlCandidatePane.h"
       
    45 #include "AknFepUICtrlPinyinPopup.h"    //Pinyin phrase
       
    46 #include "aknfepuictrleditpane.h"           //pinyin phrase creation
       
    47 #include "AknFepManager.h"
       
    48 
       
    49 const TInt KMaxPhraseCreationCount = 7;
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // C++ construct.
       
    53 // ---------------------------------------------------------
       
    54 //
       
    55 TAknFepInputStateEntryPinyinPhraseCreation::TAknFepInputStateEntryPinyinPhraseCreation(
       
    56     MAknFepUIManagerStateInterface* aOwner,
       
    57     MAknFepUICtrlContainerChinese* aUIContainer ) :
       
    58     TAknFepInputStatePinyinPhraseCreationBase( aOwner, aUIContainer)
       
    59     {
       
    60     iState = EKeySequenceEdit;
       
    61 
       
    62     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
    63     uiContainer->FocusCandidatePane( EFalse );
       
    64     uiContainer->CandidatePane()->ShowCandidateOrdinals( EFalse );
       
    65     uiContainer->SetLayout( MAknFepUICtrlContainerChinese::ELayoutPhraseCreation );
       
    66     uiContainer->CandidatePane()->SelectFirstPhrase();
       
    67     uiContainer->ShowVerticalScrollArrows( ETrue );
       
    68     uiContainer->ShowHorizontalScrollArrows( EFalse );
       
    69     uiContainer->InputPane()->SetOverrideFontId( 0 );
       
    70     uiContainer->PinyinPopupWindow()->SetPhraseCreationEditingState( EFalse );
       
    71     // in the case that we are coming back to the input pane from the candidate pane, 
       
    72     // we need to ensure that the current selection is selected correctly
       
    73     if ( uiContainer->PinyinPopupWindow()->GetFromEditToSpellingFlag() )
       
    74         {
       
    75         uiContainer->PinyinPopupWindow()->SetFromEditToSpellingFlag();
       
    76         TInt validCount = uiContainer-> 
       
    77             PinyinPopupWindow()->InEffectKeystrokeArray()->Count();
       
    78         uiContainer->EditPaneWindow()->SetCursorIndexOfKeystroke( validCount );
       
    79         ShowInfo();        
       
    80         uiContainer->PinyinPopupWindow()->SetNoneHighlighted();
       
    81         uiContainer->EditPaneWindow()->ActiveCursor();
       
    82         uiContainer->EditPaneWindow()->EnableCursor();
       
    83         }
       
    84     else
       
    85         {
       
    86         ImplicityShowInfo( ETrue );    
       
    87         }
       
    88     // however we also need to clear the deliberate selection, in case we are not
       
    89     // coming back to the input pane from the candidate pane
       
    90     ChangeCba();
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------
       
    94 // HandleKeyL
       
    95 // ---------------------------------------------------------
       
    96 // 
       
    97 TBool TAknFepInputStateEntryPinyinPhraseCreation::HandleKeyL( TInt aKey,
       
    98     TKeyPressLength aLength )
       
    99     {
       
   100     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   101     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   102     CDesCArrayFlat* inEffectKeystrokeArray = popup->InEffectKeystrokeArray();
       
   103     CDesCArrayFlat* showKeystrokeArray = popup->ShowKeystrokeArray();
       
   104    
       
   105     switch( aKey )
       
   106         {
       
   107         case EKeyBackspace:
       
   108             {
       
   109             TBool state = ETrue;
       
   110             if ( popup->IsChangeStatet() && aLength == ELongKeyPress )
       
   111                 {
       
   112                 state = EFalse;
       
   113                 }
       
   114             else
       
   115                 {
       
   116                 popup->SetChangeState( EFalse );
       
   117                 }
       
   118             if ( state )
       
   119                 {
       
   120                 HandleKeyBackspace( aLength );
       
   121                 }
       
   122             break;
       
   123             }
       
   124         case EKeyRightArrow:
       
   125             if ( !IsMoveCursor() )
       
   126                 {
       
   127                 iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   128                 }
       
   129             else
       
   130                 {
       
   131                 MoveCursorToRight();
       
   132                 }
       
   133             break;
       
   134         case EKeyLeftArrow:
       
   135             if ( !IsMoveCursor() )
       
   136                 {
       
   137                 iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   138                 }
       
   139             else
       
   140                 {
       
   141                 MoveCursorToLeft();
       
   142                 }
       
   143             break;
       
   144         case EKeyOK:
       
   145         case EKeyCBA1:
       
   146             if ( !( popup->IsChangeStatet() && aLength == ELongKeyPress ) )
       
   147                 {
       
   148                 popup->SetChangeState( EFalse );
       
   149                 HandleKeyOKAndKeyCBA1L();
       
   150                 }
       
   151            break;
       
   152         case EKeyCBA2:
       
   153             iOwner->FepMan()->TryCloseUiL();
       
   154             break;
       
   155         case EKeyDownArrow:
       
   156             if ( ( 0 == showKeystrokeArray->Count() ) ||
       
   157                 ( 0 == inEffectKeystrokeArray->Count() ) )
       
   158                 {
       
   159                 iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   160                 }
       
   161             else
       
   162                 {
       
   163                 popup->SetChangeState( ETrue );
       
   164                 popup->SetFromEditToSpellingFlag( ETrue );
       
   165                 iOwner->ChangeState( ESpellingSelection );
       
   166                 }
       
   167             break;
       
   168         case EKeyUpArrow:
       
   169             iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   170             break;
       
   171         default:
       
   172             if ( EShortKeyPress == aLength )
       
   173                 {
       
   174                 HandleOthersKey( aKey );
       
   175                 }
       
   176             else
       
   177                 {
       
   178                 iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   179                 }
       
   180             break;
       
   181         }
       
   182     
       
   183     return ETrue;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------
       
   187 // Init the show info
       
   188 // ---------------------------------------------------------
       
   189 //
       
   190 void TAknFepInputStateEntryPinyinPhraseCreation::ImplicityShowInfo( 
       
   191                                                    TBool aGetScreenCoordinates )
       
   192     {
       
   193     TRAP_IGNORE( ImplicityShowInfoL( aGetScreenCoordinates ) );
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------
       
   197 // Init the show info
       
   198 // ---------------------------------------------------------
       
   199 //
       
   200 void TAknFepInputStateEntryPinyinPhraseCreation::ImplicityShowInfoL( 
       
   201                                                    TBool aGetScreenCoordinates )
       
   202     {
       
   203     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   204     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   205     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   206     TInt showKeystrokeCount = popup->ShowKeystrokeArray()->Count();
       
   207     TInt chineseCount = popup->ChooseChineseCharacterArray()->Count();
       
   208     // get cursor position
       
   209     TPoint baseLine = TPoint( 0, 0 );
       
   210     TInt height = 0;
       
   211     TInt ascent = 0;
       
   212     TBool validChange = EFalse;
       
   213     TBool isSpellingValid = EFalse;
       
   214     if ( aGetScreenCoordinates )
       
   215         {
       
   216         iOwner->FepMan()->GetScreenCoordinatesL(baseLine,height,ascent);
       
   217         uiContainer->SetContainerPosition( baseLine, height );
       
   218         }
       
   219     if ( popup->GetPhraseCreationEditingState() )
       
   220         {
       
   221         isSpellingValid = GetValidKeystroke();
       
   222         }    
       
   223     else if ( popup->GetPhraseCreationState() )
       
   224         {
       
   225         isSpellingValid = GetValidKeystroke();
       
   226         if ( 0 == chineseCount )
       
   227             {
       
   228             editPane->SetCursorIndexOfKeystroke( showKeystrokeCount );
       
   229             }
       
   230         else
       
   231             {
       
   232             editPane->SetCursorIndexOfKeystroke( 0 );
       
   233             }
       
   234         
       
   235         }
       
   236     
       
   237     if ( !isSpellingValid )
       
   238         {
       
   239         UIContainer()->SetControlInVisible( EFalse );
       
   240         }
       
   241     
       
   242     validChange = popup->GetValidKeystrokeChange();
       
   243     
       
   244     ShowInfo();
       
   245     SetWarningColor();
       
   246     editPane->ActiveCursor();
       
   247     if ( ( popup->GetPhraseCreationState() ) || 
       
   248         ( popup->GetPhraseCreationEditingState() ) )
       
   249         {
       
   250         if ( validChange || 
       
   251             ( 0 != popup->CurrentPageStartIndex() ) )
       
   252             {
       
   253             popup->SetPhraseCreationEditingState( EFalse );
       
   254             popup->SetPhraseCreationState( EFalse );
       
   255             RefreshUI();
       
   256             }
       
   257         else
       
   258             {
       
   259             if ( 0 != popup->CurrentSelection() )
       
   260                 {
       
   261                 RefreshCandidate();
       
   262                 }
       
   263             }
       
   264         }
       
   265     else
       
   266         {
       
   267         if ( validChange )
       
   268             {
       
   269             RefreshUI( popup->CurrentSelection() );
       
   270             }
       
   271         }
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------
       
   275 // EKeyBackspace
       
   276 // ---------------------------------------------------------
       
   277 //
       
   278 void TAknFepInputStateEntryPinyinPhraseCreation::HandleKeyBackspace( TKeyPressLength aLength )
       
   279     {
       
   280     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   281     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   282     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   283 
       
   284     TInt validKeystrokeCount = popup->InEffectKeystrokeArray()->Count();
       
   285     TInt chineseCount = popup->ChooseChineseCharacterArray()->Count();
       
   286     TInt cursorOfkeystrokeIndex = editPane->GetCursorIndexOfKeystroke();
       
   287     
       
   288     if ( 0 == cursorOfkeystrokeIndex )
       
   289         {
       
   290         if ( !TryCloseUI( aLength ) )
       
   291             {
       
   292             if ( ( 0 == chineseCount ) && ( 0 != validKeystrokeCount ) )
       
   293                 {
       
   294                 iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   295                 }
       
   296             else
       
   297                 {
       
   298                 if ( ChineseRevertKeystroke() )
       
   299                     {
       
   300                     ClearDeliberateSelection();
       
   301                     popup->SetPhraseCreationEditingState( ETrue );
       
   302                     ImplicityShowInfo();
       
   303                     ChangeCba();
       
   304                     }
       
   305                 else
       
   306                     {
       
   307                     iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   308                     }               
       
   309                 }
       
   310             }        
       
   311         }
       
   312     else
       
   313         {
       
   314         if ( 1 == cursorOfkeystrokeIndex )
       
   315             {
       
   316             editPane->Reset();
       
   317             editPane->SetCursorIndexOfKeystroke( 1 );
       
   318             }
       
   319         //delete the current keystroke
       
   320         if ( DeleteCurrentKeystroke() )
       
   321             {
       
   322             if ( !TryCloseUI( aLength ) )
       
   323                 {
       
   324                 ClearDeliberateSelection();
       
   325                 popup->SetPhraseCreationEditingState( ETrue );
       
   326                 ImplicityShowInfo();
       
   327                 ChangeCba();
       
   328                 }
       
   329             }
       
   330         else
       
   331             {
       
   332             iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   333             }            
       
   334         }  
       
   335     }
       
   336 
       
   337 // ---------------------------------------------------------
       
   338 // EKeyOK And EKeyCBA1L.
       
   339 // ---------------------------------------------------------
       
   340 //
       
   341 void TAknFepInputStateEntryPinyinPhraseCreation::HandleKeyOKAndKeyCBA1L()
       
   342     {
       
   343     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   344     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   345 
       
   346     TInt validKeystrokeCount = popup->InEffectKeystrokeArray()->Count();
       
   347     TInt keystrokeCount = popup->ShowKeystrokeArray()->Count();
       
   348     CDesCArrayFlat* chinese = popup->ChooseChineseCharacterArray();
       
   349     TBuf<KMaxPhraseCreationCount> phraseCreated;
       
   350     
       
   351     if ( ( chinese->Count() >= 2 ) && ( 0 == keystrokeCount ) )
       
   352         {
       
   353         //commit the chinese character.
       
   354         MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   355         for (TInt i = 0; i < chinese->Count(); ++i )
       
   356             {
       
   357             phraseCreated.Append( chinese->MdcaPoint( i ) );
       
   358             }
       
   359         AddPhraseToDB( phraseCreated );
       
   360         fepMan->PinyinPhraseCreation( EFalse );
       
   361         fepMan->NewTextL( phraseCreated );
       
   362         fepMan->CommitInlineEditL();
       
   363         iOwner->FepMan()->TryCloseUiL(); //no more keys, close the UI.
       
   364         }
       
   365     else if ( 0 != validKeystrokeCount )
       
   366         {
       
   367         popup->SetChangeState( ETrue );
       
   368         popup->SetFromEditToSpellingFlag( ETrue );
       
   369         iOwner->ChangeState( ESpellingSelection );
       
   370         }
       
   371     else
       
   372         {
       
   373         iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   374         }
       
   375     }
       
   376 
       
   377 // ---------------------------------------------------------
       
   378 // others key input.
       
   379 // ---------------------------------------------------------
       
   380 //
       
   381 void TAknFepInputStateEntryPinyinPhraseCreation::HandleOthersKey( TInt aKey )
       
   382     {
       
   383     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   384     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   385     iOwner->FepMan()->SetCcpuFlag( CAknFepManager::ECcpuStateIgnoreStarUp );
       
   386     if ( iOwner->IsValidChineseInputKey( aKey ) )
       
   387         {
       
   388         if ( AddKeystroke( aKey ) )
       
   389             {
       
   390             ClearDeliberateSelection();
       
   391             popup->SetPhraseCreationEditingState( ETrue );
       
   392             ImplicityShowInfo();
       
   393             ChangeCba();
       
   394             }
       
   395         else
       
   396             {
       
   397             iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   398             }
       
   399         }
       
   400     else if ( aKey == EPtiKeyStar ) // we increment the tone mark.
       
   401         {
       
   402         if ( AddToneMark() )
       
   403             {
       
   404             ClearDeliberateSelection();
       
   405             popup->SetPhraseCreationEditingState( ETrue );
       
   406             ImplicityShowInfo();
       
   407             ChangeCba();
       
   408             }
       
   409         else
       
   410             {
       
   411             iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   412             }            
       
   413         }
       
   414     else
       
   415         {
       
   416         iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   417         }
       
   418     }
       
   419 
       
   420 // ---------------------------------------------------------
       
   421 // move cursor to left.
       
   422 // ---------------------------------------------------------
       
   423 //
       
   424 TBool TAknFepInputStateEntryPinyinPhraseCreation::IsMoveCursor()
       
   425     {
       
   426     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   427     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   428     TInt keystrokeCount = popup->ShowKeystrokeArray()->Count();
       
   429     TInt chineseCount = popup->ChooseChineseCharacterArray()->Count();
       
   430     if ( ( 0 == keystrokeCount ) || ( KMaxPhraseCreationCount == chineseCount ) )
       
   431         {
       
   432         return EFalse;
       
   433         }
       
   434     return ETrue;
       
   435     }
       
   436 
       
   437 // ---------------------------------------------------------
       
   438 // move cursor to left.
       
   439 // ---------------------------------------------------------
       
   440 //
       
   441 void TAknFepInputStateEntryPinyinPhraseCreation::MoveCursorToLeft()
       
   442     {
       
   443     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   444     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   445     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   446     TInt keystrokeCount = popup->ShowKeystrokeArray()->Count();
       
   447     TInt indexOfKeystroke = editPane->GetCursorIndexOfKeystroke();
       
   448 
       
   449     if ( 0 == indexOfKeystroke )
       
   450         {
       
   451         editPane->SetCursorIndexOfKeystroke( keystrokeCount );
       
   452         // for fix bug when press left, spelling pane will flash
       
   453         // ImplicityShowInfo();
       
   454         ShowInfo();
       
   455         SetWarningColor();
       
   456         }
       
   457     else if ( 1 == indexOfKeystroke )
       
   458         {
       
   459         editPane->SetCursorIndexOfKeystroke( 0 );
       
   460         // for fix bug when press left, spelling pane will flash
       
   461         // ImplicityShowInfo();
       
   462         ShowInfo();
       
   463         SetWarningColor();
       
   464         }
       
   465     else
       
   466         {
       
   467         editPane->SetCursorIndexOfKeystroke( indexOfKeystroke - 1 );
       
   468         editPane->MoveCursorLeft();
       
   469         }
       
   470     }
       
   471 
       
   472 
       
   473 // ---------------------------------------------------------
       
   474 // move cursor to left.
       
   475 // ---------------------------------------------------------
       
   476 //
       
   477 void TAknFepInputStateEntryPinyinPhraseCreation::MoveCursorToRight()
       
   478     {
       
   479     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   480     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   481     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   482     TInt keystrokeCount = popup->ShowKeystrokeArray()->Count();
       
   483     TInt indexOfKeystroke = editPane->GetCursorIndexOfKeystroke();
       
   484 
       
   485     if ( indexOfKeystroke == keystrokeCount )
       
   486         {
       
   487         editPane->SetCursorIndexOfKeystroke( 0 );
       
   488         // for fix bug when press right, spelling pane will flash
       
   489         // ImplicityShowInfo();
       
   490         ShowInfo();
       
   491         SetWarningColor();
       
   492         }
       
   493     else
       
   494         {
       
   495         editPane->SetCursorIndexOfKeystroke( indexOfKeystroke + 1 );
       
   496         editPane->MoveCursorRight();
       
   497         }
       
   498     }
       
   499 
       
   500 // ---------------------------------------------------------
       
   501 // Initialize State.
       
   502 // ---------------------------------------------------------
       
   503 //
       
   504 void TAknFepInputStateEntryPinyinPhraseCreation::InitializeState()
       
   505     {
       
   506     ChangeCba();
       
   507     }
       
   508 
       
   509 // ---------------------------------------------------------
       
   510 // Add phrase to DB.
       
   511 // ---------------------------------------------------------
       
   512 //
       
   513 TBool TAknFepInputStateEntryPinyinPhraseCreation::AddPhraseToDB(
       
   514     const TDesC& aPhraseAdd )
       
   515     {
       
   516     TInt retCode;
       
   517     TPtiUserDictionaryEntry addUdbEntry(aPhraseAdd);
       
   518     //Add the phrase to the DB by PTI Engine
       
   519     retCode = iOwner->PtiEngine()->AddUserDictionaryEntry( addUdbEntry );
       
   520     if ( KErrNone != retCode )
       
   521         {
       
   522         return EFalse;
       
   523         }
       
   524 
       
   525     return ETrue;
       
   526     }
       
   527 
       
   528 // ---------------------------------------------------------
       
   529 // Try to close UI.
       
   530 // ---------------------------------------------------------
       
   531 //
       
   532 TBool TAknFepInputStateEntryPinyinPhraseCreation::TryCloseUI( TKeyPressLength aLength )
       
   533     {
       
   534     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   535     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   536     TInt keystrokeCount = popup->ShowKeystrokeArray()->Count();
       
   537     TInt chineseCount = popup->ChooseChineseCharacterArray()->Count();
       
   538     
       
   539     if ( ( 0 == chineseCount ) && ( 0 == keystrokeCount ) )
       
   540         {
       
   541         TRAP_IGNORE( iOwner->FepMan()->TryCloseUiL() ); //no more keys, close the UI.
       
   542         if ( aLength == ELongKeyPress )
       
   543             {
       
   544             iOwner->FepMan()->SetLongClearAfterCloseUI( ETrue );
       
   545             }
       
   546         return ETrue;
       
   547         }
       
   548     
       
   549     return EFalse;
       
   550     }
       
   551 
       
   552 // End of file