fep/aknfep/src/AknFepUiInputStateEntryZhuyinPhrase.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     1 /*
       
     2 * Copyright (c) 2004 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 CAknFepUIInputStateZhuyinPhrase methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include "AknFepUiInputStateEntryZhuyinPhrase.h"
       
    31 #include "AknFepUIManagerStateInterface.h"
       
    32 #include <PtiEngine.h>
       
    33 
       
    34 #include <e32keys.h>
       
    35 #include <PtiDefs.h>                //keys
       
    36 #include <aknnotewrappers.h>
       
    37 #include "AknFepUICtrlInputPane.h"
       
    38 #include "AknFepUICtrlCandidatePane.h"
       
    39 #include "AknFepManager.h"
       
    40 #include "aknfepuictrleditpane.h"
       
    41 #include "AknFepUICtrlPinyinPopup.h"
       
    42 #include "aknfepzhuyinconvertion.h"
       
    43 #include "aknfepzhuyinkeyhandlerinterface.h"
       
    44 #include "AknFepZhuyinAnalyserDb.h"
       
    45 #include "AknFepZhuyinAnalyser.h"
       
    46 #include <PtiUserDicEntry.h>
       
    47 
       
    48 const TInt KMaxPhraseCount = 50;
       
    49 const TInt KInputPaneLength = 32;
       
    50 const TUint16 KSegment = 0x0020;
       
    51 
       
    52 const TInt KMaxBufLen = 100;
       
    53 const TInt KInputPhraseMaxLength = 7;
       
    54 _LIT( KMaxPhraseNote,"\x8BCD\x7EC4\x6700\x957F\x4E3A\x4E03\x5B57" );
       
    55 
       
    56 TAknFepInputStateEntryZhuyinPhrase::TAknFepInputStateEntryZhuyinPhrase(
       
    57                                 MAknFepUIManagerStateInterface* aOwner,
       
    58                                 MAknFepUICtrlContainerChinese* aUIContainer)
       
    59     :TAknFepInputStateZhuyinPhraseCreationBase(aOwner, aUIContainer)
       
    60     {
       
    61     iState = EEntry;
       
    62     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
    63     uiContainer->SetLayout(MAknFepUICtrlContainerChinese::ELayoutKeystroke);
       
    64     uiContainer->CandidatePane()->SelectFirstPhrase(); 
       
    65     uiContainer->InputPane()->SetOverrideFontId(0);
       
    66 
       
    67     if (iOwner->PtiEngine()->InputMode() != EPtiEngineZhuyinByPhrase)
       
    68         {
       
    69         iOwner->PtiEngine()->SetInputMode(EPtiEngineZhuyinByPhrase);
       
    70         }
       
    71     iOwner->PtiEngine()->SetCandidatePageLength(KMaxPhraseCount);
       
    72     iOwner->FepMan()->EntryPhrase(ETrue);
       
    73     uiContainer->SetFepMan(iOwner->FepMan());
       
    74     uiContainer->EditPaneWindow()->DeactiveCursor();
       
    75     UpdateEEPContent();
       
    76     RefreshUI();
       
    77     UpdateIndicator();
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // TAknFepInputStateEntryZhuyinPhrase::HandleCommandL
       
    82 // Handling Command
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void TAknFepInputStateEntryZhuyinPhrase::HandleCommandL( TInt aCommandId )
       
    86     {
       
    87     switch ( aCommandId )
       
    88         {
       
    89         // Handle the event frome command.
       
    90         case EAknSoftkeyCancel:
       
    91             //  case (TUint16)EAknSoftkeyCancel: //the Cancle in soft CBA
       
    92             TAknFepInputStateChineseBase::HandleCommandL( aCommandId );
       
    93             break;
       
    94         case EAknSoftkeySelect:
       
    95             //case (TUint16)EAknSoftkeySelect: //the Selected in soft CBA
       
    96             HandleCommitL();
       
    97             break;
       
    98         default:
       
    99             TAknFepInputStateZhuyinPhraseCreationBase::HandleCommandL(
       
   100                 aCommandId );
       
   101             break;
       
   102         }
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // TAknFepInputStateEntryZhuyinPhrase::HandleCommit 
       
   107 // Handle CBA1,ok and select candidate phrase key press.
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void TAknFepInputStateEntryZhuyinPhrase::HandleCommitL()
       
   111     {
       
   112     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   113     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   114     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
   115     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   116     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   117 
       
   118     CDesCArrayFlat* zhuyinSymbols =
       
   119         uiContainer->PinyinPopupWindow()->ZhuyinSymbols();
       
   120     CDesCArrayFlat* chineseDisped =
       
   121         uiContainer->PinyinPopupWindow()->ChineseCharsDisped();
       
   122     CDesCArrayFlat
       
   123         * zhuyinSymbolsForChinese =
       
   124             uiContainer->PinyinPopupWindow()->ZhuyinSymbolsForChineseCharsDisped();
       
   125     CDesCArrayFlat* candidateList =
       
   126         uiContainer->CandidatePane()->CandidateArray();
       
   127     MZhuyinKeyHandler* zhuyinKeyHandler = iOwner->ZhuyinKeyHandler();
       
   128 
       
   129     TPtrC text = candidatePane->CurrentPhraseCandidate();
       
   130     if ( text.Length() == 0 )
       
   131         {
       
   132         return;
       
   133         }
       
   134     TBuf<KMaxBufLen> pinyinshown =
       
   135         UIContainer()->PinyinPopupWindow()->GetEEPContent();
       
   136     TInt count = TZhuyinSymbolsMethods::GetChineseCount( pinyinshown );
       
   137     if ( count > text.Length() )
       
   138         {
       
   139         fepMan->PhraseCreation( ETrue );
       
   140         }
       
   141     if ( fepMan->IsPhraseCreation() )
       
   142         {
       
   143         TBuf<KMaxBufLen> buf;
       
   144         buf.Copy( text );
       
   145         TBool commit = TZhuyinSymbolsMethods::AppendChineseChar( buf,
       
   146             fepMan->ZhuyinAnalyser(), zhuyinSymbols, chineseDisped,
       
   147             zhuyinSymbolsForChinese );
       
   148         TBool changeState = UpdateEEPContent();
       
   149         if ( commit )
       
   150             {
       
   151             TBuf<KMaxBufLen> commitbuf;
       
   152             TZhuyinSymbolsMethods::Convert2Des( chineseDisped, commitbuf );
       
   153             fepMan->NewTextL( commitbuf );
       
   154             fepMan->CommitInlineEditL();
       
   155             AddPhraseToDB( commitbuf );
       
   156             if ( chineseDisped->Count() < KInputPhraseMaxLength
       
   157                 || zhuyinSymbols->Count() == 0 )
       
   158                 {
       
   159                 iOwner->FepMan()->TryCloseUiL();
       
   160                 }
       
   161             else
       
   162                 {
       
   163                 CAknWarningNote* errnote = new (ELeave) CAknWarningNote();
       
   164                 errnote->SetTone( CAknNoteDialog::EWarningTone );
       
   165                 errnote->ExecuteLD( KMaxPhraseNote );
       
   166                 fepMan->TryCloseUiL();
       
   167                 }
       
   168             popup->ResetStrokeArray();
       
   169             }
       
   170         else
       
   171             {
       
   172             editPane->SetCursorIndexOfKeystroke( 0 );
       
   173             if ( changeState )
       
   174                 {
       
   175                 for (TInt i = 0; i < candidateList->Count(); i++ )
       
   176                     {
       
   177                     if ( TZhuyinSymbolsMethods::IsZhuyinSymbol(
       
   178                         candidateList->MdcaPoint( i ) ) )
       
   179                         {
       
   180                         candidateList->Delete( i, 1 );
       
   181                         break;
       
   182                         }
       
   183                     }
       
   184                 if ( candidateList->Count() > 0 )
       
   185                     {
       
   186                     popup->SetChangeState( ETrue );
       
   187                     iOwner->ChangeState( EEntry );
       
   188                     }
       
   189                 else
       
   190                     {
       
   191                     popup->SetChangeState( ETrue );
       
   192                     iOwner->ChangeState( EZhuyinSequenceEdit );
       
   193                     }
       
   194                 }
       
   195             else
       
   196                 {
       
   197                 popup->SetChangeState( ETrue );
       
   198                 iOwner->ChangeState( EZhuyinSequenceEdit );
       
   199                 }
       
   200             }
       
   201         }
       
   202     else
       
   203         {
       
   204         TBuf<KMaxBufLen> textbuf;
       
   205         for (TInt i = 0; i < chineseDisped->Count(); i++ )
       
   206             {
       
   207             textbuf.Append( chineseDisped->MdcaPoint( i ) );
       
   208             }
       
   209         textbuf.Append( text );
       
   210         fepMan->NewTextL( textbuf );
       
   211         fepMan->CommitInlineEditL();
       
   212         AddPhraseToDB( textbuf );
       
   213         popup->ResetStrokeArray();
       
   214         if ( text.Length() <= KInputPhraseMaxLength
       
   215             && !fepMan->IsPhraseCreation() )
       
   216             {
       
   217             if ( fepMan->IsFlagSet( CAknFepManager::EFlagEditorFull ) )
       
   218                 {
       
   219                 fepMan->ClearFlag( CAknFepManager::EFlagEditorFull );
       
   220                 iOwner->FepMan()->TryCloseUiL();
       
   221                 }
       
   222             else
       
   223                 {
       
   224                 iOwner->ChangeState( EPredictiveCandidate );
       
   225                 }
       
   226             }
       
   227         else
       
   228             {
       
   229             fepMan->TryCloseUiL();
       
   230             }
       
   231         }
       
   232     }
       
   233 
       
   234 void TAknFepInputStateEntryZhuyinPhrase::AddPhraseToDB( TDes& aPhrase )
       
   235     {
       
   236     TPtiUserDictionaryEntry addUdbEntry( aPhrase );
       
   237     //Add the phrase to the DB by PTI Engine
       
   238     iOwner->PtiEngine()->AddUserDictionaryEntry( addUdbEntry );
       
   239     }
       
   240 
       
   241 TBool TAknFepInputStateEntryZhuyinPhrase::HandleKeyL(TInt aKey, TKeyPressLength aLength)
       
   242     {
       
   243     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   244     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
   245     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   246     MZhuyinKeyHandler* zhuyinKeyHandler = iOwner->ZhuyinKeyHandler();
       
   247     
       
   248     CDesCArrayFlat* zhuyinSymbols = uiContainer->PinyinPopupWindow()->ZhuyinSymbols();
       
   249     CDesCArrayFlat* chineseDisped = uiContainer->PinyinPopupWindow()->ChineseCharsDisped();
       
   250 
       
   251     iOwner->FepMan()->SetCcpuFlag(CAknFepManager::ECcpuStateIgnoreStarUp);            
       
   252     
       
   253     if((aKey == EPtiKeyStar) && (aLength == EShortKeyPress))
       
   254         {
       
   255         AddToneMarkL();
       
   256         if ( !UpdateEEPContent( ) )
       
   257             {
       
   258             RefreshUI();
       
   259             ChangeCbaL();
       
   260             popup->SetChangeState( ETrue );
       
   261             iOwner->ZhuyinKeyHandler()->SetState(1);
       
   262             iOwner->ChangeState(EZhuyinSequenceEdit);
       
   263             return ETrue;
       
   264             }
       
   265         RefreshUI();
       
   266         ChangeCbaL();
       
   267         return ETrue;
       
   268         }
       
   269     else if (aKey == EKeyLeftArrow )
       
   270         {
       
   271         iOwner->ChangeState(ECandidate);
       
   272         return EFalse;
       
   273         }
       
   274     else if (aKey == EKeyRightArrow)
       
   275         {
       
   276         iOwner->ChangeState(ECandidate);
       
   277         return EFalse;
       
   278         }
       
   279     else 
       
   280         {
       
   281         if(aKey == EKeyBackspace)
       
   282             {
       
   283             if ( aLength == ELongKeyPress
       
   284                 && zhuyinKeyHandler->GetStatusChgFlag() == MZhuyinKeyHandler::EFromCandidateToEntry )
       
   285                 {
       
   286                 return ETrue;
       
   287                 }
       
   288             else
       
   289                 {
       
   290                 zhuyinKeyHandler->SetStatusChgFlag(MZhuyinKeyHandler::EInit);
       
   291                 }
       
   292             
       
   293             DeleteZhuyinSymbolOrChinese();
       
   294             
       
   295             if ( !UpdateEEPContent( ) )
       
   296                 {
       
   297                 RefreshUI();
       
   298                 popup->SetChangeState( ETrue );
       
   299                 iOwner->ZhuyinKeyHandler()->SetState(1);
       
   300                 ChangeCbaL();
       
   301                 iOwner->ChangeState(EZhuyinSequenceEdit);
       
   302                 if ( zhuyinSymbols->Count() == 0
       
   303                     && chineseDisped->Count() == 0 )
       
   304                     {
       
   305                     iOwner->FepMan()->TryCloseUiL();
       
   306                     if (aLength == ELongKeyPress)
       
   307                         {
       
   308                         iOwner->FepMan()->SetLongClearAfterCloseUI(ETrue);
       
   309                         }
       
   310                     }
       
   311                 if ( 0 == chineseDisped->Count() )
       
   312                     {
       
   313                     iOwner->FepMan()->PhraseCreation( EFalse );
       
   314                     }
       
   315                 return ETrue;
       
   316                 }
       
   317             ChangeCbaL();
       
   318             RefreshUI();
       
   319             if ( zhuyinSymbols->Count() == 0
       
   320                 && chineseDisped->Count() == 0 )
       
   321                 {
       
   322                 iOwner->FepMan()->TryCloseUiL();
       
   323                 if (aLength == ELongKeyPress)
       
   324                     {
       
   325                     iOwner->FepMan()->SetLongClearAfterCloseUI(ETrue);
       
   326                     }
       
   327                 }
       
   328             if ( 0 == chineseDisped->Count() )
       
   329                 {
       
   330                 iOwner->FepMan()->PhraseCreation( EFalse );
       
   331                 }
       
   332             }
       
   333         else if((aLength == EShortKeyPress) && iOwner->IsValidChineseInputKey(aKey))
       
   334             {
       
   335             if ( AddKeystrokeL( aKey ) )
       
   336                 {
       
   337                 if ( !UpdateEEPContent( ) )
       
   338                     {
       
   339                     RefreshUI();
       
   340                     popup->SetChangeState( ETrue );
       
   341                     iOwner->ZhuyinKeyHandler()->SetState(1);
       
   342                     iOwner->ChangeState(EZhuyinSequenceEdit);
       
   343                     return ETrue;
       
   344                     }
       
   345                 RefreshUI();
       
   346                 ChangeCbaL();
       
   347                 }
       
   348             else
       
   349                 {
       
   350                 iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   351                 }
       
   352             return ETrue;
       
   353             }
       
   354         else if(aKey == EKeyDownArrow)
       
   355             {
       
   356             if ( aLength == ELongKeyPress
       
   357                 && zhuyinKeyHandler->GetStatusChgFlag() == MZhuyinKeyHandler::EFromSpellingEditingToEntry )
       
   358                 {
       
   359                 return ETrue;
       
   360                 }
       
   361             else if (!candidatePane->IsLastPage())
       
   362                {
       
   363                zhuyinKeyHandler->SetStatusChgFlag(MZhuyinKeyHandler::EInit);
       
   364                if ( candidatePane->NeedGetNewCandidatePage() )
       
   365                    {
       
   366                    if ( !iOwner->PtiEngine()->NextCandidatePage( ) )
       
   367                        {
       
   368                        if ( candidatePane->IsLastPage() )
       
   369                            {
       
   370                            iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   371                            return ETrue;
       
   372                            }
       
   373                        }
       
   374                    else
       
   375                        {
       
   376                        CDesCArrayFlat* phraseCandidates = candidatePane->CandidateArray();
       
   377                        RPointerArray<HBufC> list;
       
   378                        GetNewCandidatesL( iOwner->PtiEngine()->CandidatePage( ), list );
       
   379                        for (TInt i = 0; i < list.Count( ); ++i )
       
   380                            {
       
   381                            phraseCandidates->AppendL( *(list[i]) );
       
   382                            }
       
   383                        list.ResetAndDestroy();
       
   384                        }
       
   385                    }           
       
   386                candidatePane->NextCandidatePage();
       
   387                RefreshUI();
       
   388                }
       
   389             }
       
   390         else if(aKey == EKeyUpArrow)
       
   391             {
       
   392             if(!candidatePane->IsFirstPage())
       
   393                 {
       
   394                 candidatePane->PreviousCandidatePage();
       
   395                 RefreshUI();
       
   396                 }
       
   397             else
       
   398                 {
       
   399                 iOwner->ZhuyinKeyHandler()->SetState(0);
       
   400                 popup->SetState( EFalse );
       
   401                 iOwner->ChangeState(EZhuyinSequenceEdit);
       
   402                 return EFalse;
       
   403                 }
       
   404             }   
       
   405         else if ( (aKey == EKeyOK || aKey == EKeyCBA1 || aKey == EKeyRightArrow || aKey == EKeyLeftArrow)
       
   406             && aLength == EShortKeyPress )
       
   407             {
       
   408             iOwner->ChangeState(ECandidate);
       
   409             return EFalse;
       
   410             }
       
   411         return ETrue;
       
   412         }
       
   413     }
       
   414 
       
   415 void TAknFepInputStateEntryZhuyinPhrase::KeyTimerExpired()
       
   416     {
       
   417     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   418     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   419     MAknFepUICtrlInputPane* inputPane = uiContainer->InputPane();
       
   420     
       
   421     // set container's position
       
   422     TPoint baseLine = TPoint(0,0);
       
   423     TInt height = 0;
       
   424     TInt ascent = 0;
       
   425     TRAPD(ret,iOwner->FepMan()->GetScreenCoordinatesL(baseLine,height,ascent));
       
   426     if (ret == KErrNone)
       
   427         {
       
   428         uiContainer->SetContainerPosition(baseLine, height);    
       
   429         }
       
   430 
       
   431     TPtrC ptr = ptiengine->GetPhoneticSpelling(1);
       
   432     inputPane->SetText(ptr);
       
   433     TBuf<KInputPaneLength> currentText;
       
   434     inputPane->GetText(currentText);
       
   435     if (ptr.Length() < currentText.Length())
       
   436         {
       
   437         iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   438         }
       
   439     UpdateIndicator();
       
   440     }
       
   441 
       
   442 void TAknFepInputStateEntryZhuyinPhrase::GetNewCandidatesL(const TDesC& aSource, 
       
   443                                                     RPointerArray<HBufC>& aList)
       
   444     {
       
   445     TInt start = 0;
       
   446     TInt length = 0;
       
   447 
       
   448     for (TInt ii = 0; ii < aSource.Length(); ii++)
       
   449         {
       
   450         if (aSource[ii] == KSegment)
       
   451             {
       
   452             TPtrC segment(aSource.Ptr() + start, length);
       
   453             aList.AppendL(segment.AllocL());
       
   454             start += (length + 1);
       
   455             length = 0;
       
   456             }
       
   457         else
       
   458             {
       
   459             length++;
       
   460             }
       
   461         }
       
   462 
       
   463     if (length)
       
   464         {
       
   465         TPtrC segm(aSource.Ptr() + start, length);
       
   466         aList.AppendL(segm.AllocL());
       
   467         }
       
   468     }
       
   469 
       
   470 // End of file