fep/aknfep/src/AknFepUiInputStatePredictiveInputJapanese.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     1 /*
       
     2 * Copyright (c) 2002-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:            Provides the
       
    15 *                TAknFepUiInputStatePredictiveInputJapanese methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 // INCLUDE FILES
       
    31 #include "AknFepUiInputStatePredictiveInputJapanese.h"
       
    32 #include "AknFepUIManagerStateInterface.h"  // MAknFepUIManagerStateInterface
       
    33 #include "AknFepManagerUIInterface.h"       // MAknFepManagerUIInterface
       
    34 #include "AknFepUICtrlContainerJapanese.h"  // MAknFepUICtrlContainerJapanese
       
    35 #include "AknFepUICtrlCandidatePaneInterface.h"
       
    36                                        // MAknFepUICtrlCandidatePaneInterface
       
    37 #include "AknFepGlobalEnums.h"
       
    38 #include "AknFepPanic.h"
       
    39 
       
    40 #include <PtiDefs.h>                    // keys
       
    41 #include <PtiEngine.h>
       
    42 #include <PtiCompositionDataIF.h>       // MPtiEngineCompositionDataInterface
       
    43 #include <aknfep.rsg>
       
    44 #include <avkon.rsg>
       
    45 
       
    46 // CONSTANTS
       
    47 const TText KAknFEPLineFeedSymbol = 0x21B2;
       
    48 const TText KAknFEPMirroredLineFeedSymbol = 0x21B3;
       
    49 
       
    50 /**
       
    51  *  TAknFepUiInputStatePredictiveInputJapanese class.
       
    52  *
       
    53  */
       
    54 //============================ MEMBER FUNCTIONS ==============================
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // TAknFepUiInputStatePredictiveInputJapanese::
       
    58 //                      TAknFepUiInputStatePredictiveInputJapanese
       
    59 // C++ default Constructor
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 TAknFepUiInputStatePredictiveInputJapanese::
       
    63     TAknFepUiInputStatePredictiveInputJapanese(
       
    64                                 MAknFepUIManagerStateInterface* aOwner,
       
    65                                 MAknFepUICtrlContainerJapanese* aUIContainer)
       
    66     :TAknFepUiInputStateJapanesePredictiveBase(aOwner, aUIContainer)
       
    67     {
       
    68     iState = EPredictiveInput;
       
    69     iCbaResourceID = R_AKNFEP_SOFTKEYS_CONVERT_OTHER_SELECT;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // TAknFepUiInputStatePredictiveInputJapanese::KeyTimerExpired
       
    74 // Call this function when Multitap timer of PtiEngine was time-out
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void TAknFepUiInputStatePredictiveInputJapanese::KeyTimerExpired()
       
    78     {
       
    79     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
    80     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
    81     const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
    82 
       
    83     TPtrC text = data->ConvertingString();
       
    84     TInt cursorpos = data->CursorPosition();
       
    85     if (text.Length() > 0)
       
    86         {
       
    87         if (text[0] == KAknFEPLineFeedSymbol
       
    88          || text[0] == KAknFEPMirroredLineFeedSymbol)
       
    89             {
       
    90             iOwner->ChangeState(EInitial);
       
    91             }
       
    92         else
       
    93             {
       
    94             // Set on cursor visibility in inline editing
       
    95             TRAPD(err, fepMan->SetInlineEditingCursorVisibilityL(ETrue));
       
    96             if (err == KErrNone)
       
    97                 {
       
    98                 TRAP(err, fepMan->UpdateInlineEditL(text, cursorpos));
       
    99                 }
       
   100             if (err != KErrNone)
       
   101                 {
       
   102                 TRAP_IGNORE(iOwner->FepMan()->SimulateKeyEventL(EKeyEscape, ETrue));
       
   103                 }
       
   104             }
       
   105         }
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // TAknFepUiInputStatePredictiveInputJapanese::InitializeStateL
       
   110 // Initialize State
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void TAknFepUiInputStatePredictiveInputJapanese::InitializeStateL()
       
   114     {
       
   115     iOwner->SetInlineEditUnderlineVisibility(ETrue);
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // TAknFepUiInputStatePredictiveInputJapanese::HandleCommandL
       
   120 // Handling Command
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void TAknFepUiInputStatePredictiveInputJapanese::
       
   124     HandleCommandL(TInt aCommandId)
       
   125     {
       
   126     switch (aCommandId)
       
   127         {
       
   128         case EAknFepSoftkeySelectCandidate:
       
   129             {
       
   130             iOwner->FepMan()->UpdateCbaL(NULL);
       
   131             CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   132             const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
   133             TPtrC textConv = data->ConvertingString();
       
   134             TPtrC textComp = data->CompletedString();
       
   135             if (textConv.Length() > 0 || textComp.Length() > 0)
       
   136                 {
       
   137                 iOwner->ChangeState(EMultiCompletion);
       
   138                 }
       
   139             else
       
   140                 {
       
   141                 iOwner->ChangeState(EInitial);
       
   142                 }
       
   143             }
       
   144             break;
       
   145         case EAknFepSoftkeyConvert:
       
   146             {
       
   147             // change state to conversion
       
   148             ChangeStateToConversionL();
       
   149             }
       
   150             break;
       
   151         case EAknFepSoftkeyOtherModes:
       
   152             {
       
   153             MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   154             CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   155             MAknFepUICtrlContainerJapanese* uicontainer = UIContainer();
       
   156             MAknFepUICtrlCandidatePaneInterface* predictivePane =
       
   157                 uicontainer->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   158                                            EJapanesePredictiveCandidatePane);
       
   159             // Closeing candidate pop-up list
       
   160             predictivePane->HideWindow();
       
   161             // Update of CBA
       
   162             iOwner->FepMan()->UpdateCbaL(NULL);
       
   163             // Delete Cursor
       
   164             fepMan->SetInlineEditingCursorVisibilityL(EFalse);
       
   165             // Change the status to Retroactive input
       
   166             iOwner->ChangeState(ECandidateRetroActive);
       
   167             }
       
   168             break;
       
   169         case EAknFepSoftkeyPredictiveOn:
       
   170             {
       
   171             CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   172             // normal operation
       
   173             if (UpdateInlineEditingCharacterL())
       
   174                 {
       
   175                 CDesCArrayFlat* candidateArray = iOwner->CandidateArray();
       
   176                 ptiEngine->GetCandidateListL(*candidateArray);
       
   177                 UpdateCandidateListL();
       
   178                 }
       
   179             }
       
   180             break;
       
   181         case EAknFepResourceChanged:
       
   182             {
       
   183             MAknFepUICtrlContainerJapanese* uicontainer = UIContainer();
       
   184             MAknFepUICtrlCandidatePaneInterface* predictivePane =
       
   185                 uicontainer->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   186                                            EJapanesePredictiveCandidatePane);
       
   187             TInt index = predictivePane->CurrentItemIndexOfCandidate();
       
   188             predictivePane->HideWindow();
       
   189             UpdateCandidateListL(index);
       
   190             }
       
   191             break;
       
   192         default:
       
   193             break;
       
   194         }
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // TAknFepUiInputStatePredictiveInputJapanese::HandleNumericShortKeyL
       
   199 // Handling numeric keypress event
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 TBool TAknFepUiInputStatePredictiveInputJapanese::
       
   203     HandleNumericShortKeyL(TInt aKey)
       
   204     {
       
   205     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   206     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   207     TBool cursornisibility = EFalse;
       
   208     TBool inputcontinue = ETrue;
       
   209 
       
   210     if (aKey == EStdKeySpace)
       
   211         {
       
   212         const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
   213         TPtrC text = data->ConvertingString();
       
   214         if (text.Length() > 0)
       
   215             {
       
   216             HandleCommandL(EAknFepSoftkeyConvert);
       
   217             inputcontinue = EFalse;
       
   218             }
       
   219         }
       
   220 
       
   221     if (inputcontinue)
       
   222         {
       
   223         if (aKey == EPtiKeyStar)
       
   224             {
       
   225             cursornisibility = ETrue;
       
   226             }
       
   227         // Setting Cursor visibility
       
   228         fepMan->SetInlineEditingCursorVisibilityL(cursornisibility);
       
   229 
       
   230         // To send a key to PtiEngine
       
   231         // Notice: AppendKeyPress() must be called after SetInlineEditingCursorVisibilityL().
       
   232         ptiEngine->AppendKeyPress((TPtiKey)aKey);
       
   233 
       
   234         // this process run if completion character (line feed or space) exist.
       
   235         const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
   236         TPtrC text = data->CompletedString();
       
   237         if (text.Length() > 0)
       
   238             {
       
   239             CloseUI();
       
   240             return ETrue;
       
   241             }
       
   242         // normal operation
       
   243         if (UpdateInlineEditingCharacterL())
       
   244             {
       
   245             // for Qwerty input, if including latin characters,
       
   246             // close candidate list.
       
   247             if (!iOwner->IsQwerty()
       
   248              || !IsFullWidthAlphaChar(data->ConvertingString()))
       
   249                 {
       
   250                 CDesCArrayFlat* candidateArray = iOwner->CandidateArray();
       
   251                 ptiEngine->GetCandidateListL(*candidateArray);
       
   252                 UpdateCandidateListL();
       
   253                 }
       
   254             }
       
   255         }
       
   256     return ETrue;
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // TAknFepUiInputStatePredictiveInputJapanese::HandleAuxKeyL
       
   261 // Handling auxiliary keypress events including OK and Backspace
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 TBool TAknFepUiInputStatePredictiveInputJapanese::HandleAuxKeyL(TInt aKey,
       
   265                                                                 TKeyPressLength /*aLength*/)
       
   266     {
       
   267     TBool ret = EFalse;
       
   268     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   269     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   270 
       
   271     switch(aKey)
       
   272         {
       
   273         case EKeyOK:
       
   274         case EStdKeyDevice3:        /* 0xA7 */
       
   275         case EStdKeyEnter:          /* 0x03 */
       
   276         case EStdKeyNkpEnter:       /* 0x88 */
       
   277             {
       
   278             iOwner->FepMan()->UpdateCbaL(NULL);
       
   279             iOwner->ChangeState(EMultiCompletion);
       
   280             ret = EFalse;
       
   281             }
       
   282             break;
       
   283         case EKeyBackspace:
       
   284         case EStdKeyBackspace:      /* 0x01 */
       
   285         case EStdKeyEscape:         /* 0x04 */
       
   286             {
       
   287             fepMan->SetInlineEditingCursorVisibilityL(ETrue);
       
   288             ptiEngine->DeleteKeyPress();
       
   289 
       
   290             if (UpdateInlineEditingCharacterL())
       
   291                 {
       
   292                 // get composition data.
       
   293                 const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
   294                 // for Qwerty input, if including latin characters,
       
   295                 // close candidate list.
       
   296                 if (!iOwner->IsQwerty()
       
   297                  || !IsFullWidthAlphaChar(data->ConvertingString()))
       
   298                     {
       
   299                     CDesCArrayFlat* candidateArray = iOwner->CandidateArray();
       
   300                     ptiEngine->GetCandidateListL(*candidateArray);
       
   301                     UpdateCandidateListL();
       
   302                     }
       
   303                 else
       
   304                     {
       
   305                     // Update of CBA
       
   306                     TInt newResource = R_AVKON_SOFTKEYS_EMPTY;
       
   307                     fepMan->UpdateCbaL(newResource);
       
   308                     }
       
   309                 }
       
   310             ret = ETrue;
       
   311             }
       
   312             break;
       
   313         default: // Panic
       
   314             {
       
   315             AknFepPanic(EAknFepPanicNotSupportKey);
       
   316             }
       
   317             break;
       
   318         }
       
   319 
       
   320     return ret;
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // TAknFepUiInputStateJapanesePredictiveBase::HandleNaviKeyL
       
   325 // Handling Navigate keypress event
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 TBool TAknFepUiInputStatePredictiveInputJapanese::
       
   329   HandleNaviKeyL(TInt aKey, TKeyPressLength aLength)
       
   330     {
       
   331     TBool ret = EFalse;
       
   332     switch(aKey)
       
   333         {
       
   334         case EKeyDownArrow:
       
   335         case EStdKeyDownArrow:      /* 0x11 */
       
   336         case EKeyUpArrow:
       
   337         case EStdKeyUpArrow:        /* 0x10 */
       
   338         case EKeyLeftArrow:
       
   339         case EStdKeyLeftArrow:      /* 0x0e */
       
   340             {
       
   341             CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   342             MAknFepUICtrlContainerJapanese* uicontainer = UIContainer();
       
   343             MAknFepUICtrlCandidatePaneInterface* predictivePane =
       
   344                 uicontainer->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   345                                            EJapanesePredictiveCandidatePane);
       
   346             if (predictivePane->CurrentItemIndexOfCandidate() == 0
       
   347              && ptiEngine->NumberOfCandidates() == 1)
       
   348                 {
       
   349                 // change state to entry
       
   350                 ChangeStateToEntryL();
       
   351                 // go through the key event.
       
   352                 return EFalse;
       
   353                 }
       
   354             }
       
   355             break;
       
   356         default:
       
   357             break;
       
   358         }
       
   359     if (!ret)
       
   360         {
       
   361         ret = TAknFepUiInputStateJapanesePredictiveBase::HandleNaviKeyL(aKey, aLength);
       
   362         }
       
   363     return ret;
       
   364     }
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // TAknFepUiInputStatePredictiveInputJapanese::IsFullWidthAlphaChar
       
   368 // Check full-width alphabet character
       
   369 // ---------------------------------------------------------------------------
       
   370 //
       
   371 TBool TAknFepUiInputStatePredictiveInputJapanese::IsFullWidthAlphaChar(TPtrC aPtr)
       
   372     {
       
   373     const TUint KFullAlphaLargeA = 0xFF21;
       
   374     const TUint KFullAlphaLargeZ = 0xFF3A;
       
   375     const TUint KFullAlphaSmallA = 0xFF41;
       
   376     const TUint KFullAlphaSmallZ = 0xFF5A;
       
   377 
       
   378     TBool isAlpha = EFalse;
       
   379     for (TInt i=aPtr.Length()-1; i >= 0 && !isAlpha; i--)
       
   380         {
       
   381         TUint ch = aPtr[i];
       
   382         isAlpha = (KFullAlphaLargeA <= ch && ch <= KFullAlphaLargeZ)
       
   383                  || (KFullAlphaSmallA <= ch && ch <= KFullAlphaSmallZ);
       
   384         }
       
   385     return isAlpha;
       
   386     }
       
   387 
       
   388 /**
       
   389  * TAknFepUiInputStatePredictiveInputJapanese::ChangeStateToConversionL();
       
   390  * Change state to conversion
       
   391  */
       
   392 void TAknFepUiInputStatePredictiveInputJapanese::ChangeStateToConversionL()
       
   393     {
       
   394     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   395     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   396     MAknFepUICtrlContainerJapanese* uicontainer = UIContainer();
       
   397     MAknFepUICtrlCandidatePaneInterface* predictivePane =
       
   398         uicontainer->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   399                                    EJapanesePredictiveCandidatePane);
       
   400     // Closeing candidate pop-up list
       
   401     predictivePane->HideWindow();
       
   402     // Update of CBA
       
   403     iOwner->FepMan()->UpdateCbaL(NULL);
       
   404     // Delete Cursor
       
   405     fepMan->SetInlineEditingCursorVisibilityL(EFalse);
       
   406 
       
   407     // Update of inline editing characters
       
   408     ptiEngine->HandleCommandL(EPtiCommandUserActionConvert);
       
   409     const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
   410     TPtrC text = data->CompletedString();
       
   411     TPtrC text2 = data->ConvertingString();
       
   412     if (text.Length() >0)
       
   413         {
       
   414         iOwner->ChangeState(EMultiCompletion);
       
   415         fepMan->CommitInlineEditL(text, text.Length());
       
   416         if (fepMan->EditorHasFreeSpace())
       
   417             {
       
   418             iOwner->ChangeState(ENextWord);
       
   419             }
       
   420         else
       
   421             {
       
   422             CloseUI();
       
   423             }
       
   424         }
       
   425     else if (text2.Length() > 0)
       
   426         {
       
   427         // Change to ConversionState
       
   428         iOwner->ChangeState(EConversion);
       
   429         fepMan->UpdateInlineEditL(text2, text2.Length());
       
   430         }
       
   431     }
       
   432 
       
   433 /**
       
   434  * TAknFepUiInputStatePredictiveInputJapanese::ChangeStateToEntryL();
       
   435  * Change state to Entry
       
   436  */
       
   437 void TAknFepUiInputStatePredictiveInputJapanese::ChangeStateToEntryL()
       
   438     {
       
   439     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   440     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   441     MAknFepUICtrlContainerJapanese* uicontainer = UIContainer();
       
   442     MAknFepUICtrlCandidatePaneInterface* predictivePane =
       
   443         uicontainer->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   444                                    EJapanesePredictiveCandidatePane);
       
   445     // Closeing candidate pop-up list
       
   446     predictivePane->HideWindow();
       
   447     // Update of CBA
       
   448     iOwner->FepMan()->UpdateCbaL(NULL);
       
   449     // Delete Cursor
       
   450     fepMan->SetInlineEditingCursorVisibilityL(EFalse);
       
   451 
       
   452     // Change to EntryState
       
   453     iOwner->ChangeState(EEntry);
       
   454     }
       
   455 
       
   456 // ---------------------------------------------------------------------------
       
   457 // TAknFepUiInputStatePredictiveInputJapanese::CloseUI
       
   458 // Closing UI
       
   459 // ---------------------------------------------------------------------------
       
   460 //
       
   461 void TAknFepUiInputStatePredictiveInputJapanese::CloseUI()
       
   462     {
       
   463     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   464     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   465     MAknFepUICtrlContainerJapanese* uicontainer = UIContainer();
       
   466     MAknFepUICtrlCandidatePaneInterface* predictivePane =
       
   467         uicontainer->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   468                                    EJapanesePredictiveCandidatePane);
       
   469 
       
   470     const MPtiEngineCompositionDataInterface* currentdata = ptiEngine->CompositionData();
       
   471     if (currentdata->ConvertingString().Length() >0)
       
   472         {
       
   473         TInt index = predictivePane->CurrentItemIndexOfCandidate();
       
   474         if (index > -1)
       
   475             {
       
   476             TRAP_IGNORE( ptiEngine->HandleCommandL(EPtiCommandUserActionCompleteCandidate, &index));
       
   477             }
       
   478         else
       
   479             {
       
   480             TRAP_IGNORE( ptiEngine->HandleCommandL(EPtiCommandUserActionComplete));
       
   481             }
       
   482         }
       
   483     const MPtiEngineCompositionDataInterface* commitdata = ptiEngine->CompositionData();
       
   484     TPtrC text = commitdata->CompletedString();
       
   485     if (text.Length() >0)
       
   486         {
       
   487         iOwner->ChangeState(EMultiCompletion);
       
   488         TRAP_IGNORE( fepMan->CommitInlineEditL(text, text.Length()));
       
   489         }
       
   490 
       
   491     ptiEngine->ClearCurrentWord();
       
   492     // Closing candidate pop-up list
       
   493     predictivePane->HideWindow();
       
   494     iOwner->ChangeState(EInitial);
       
   495     }
       
   496 
       
   497 // End of file