fep/aknfep/src/AknFepUiInputStateEntryJapaneseMultitap.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:           
       
    15 *       Provides the TAknFepUiInputStateEntryJapaneseMultitap methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 // INCLUDE FILES
       
    31 #include "AknFepUiInputStateEntryJapaneseMultitap.h"
       
    32 #include "AknFepUIManagerStateInterface.h"   // MAknFepUIManagerStateInterface
       
    33 #include "AknFepManagerUIInterface.h"        // MAknFepManagerUIInterface
       
    34 #include "AknFepGlobalEnums.h"
       
    35 #include "AknFepManager.h"
       
    36 #include "AknFepUICtrlCandidatePaneInterface.h" // MAknFepUICtrlCandidatePaneInterface
       
    37 
       
    38 #include <PtiDefs.h>                    // keys
       
    39 #include <PtiEngine.h>
       
    40 #include <PtiCompositionDataIF.h>       // MPtiEngineCompositionDataInterface
       
    41 
       
    42 // CONSTANTS
       
    43 const TText KAknFEPLineFeedSymbol = 0x21B2;
       
    44 const TText KAknFEPMirroredLineFeedSymbol = 0x21B3;
       
    45 
       
    46 /**
       
    47  *  TAknFepUiInputStateEntryJapaneseMultitap class.
       
    48  *
       
    49  */
       
    50 
       
    51 //============================ MEMBER FUNCTIONS ==============================
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // TAknFepUiInputStateEntryJapaneseMultitap::
       
    55 //                                  TAknFepUiInputStateEntryJapaneseMultitap
       
    56 // C++ default Constructor
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 TAknFepUiInputStateEntryJapaneseMultitap::
       
    60     TAknFepUiInputStateEntryJapaneseMultitap(
       
    61                                 MAknFepUIManagerStateInterface* aOwner,
       
    62                                 MAknFepUICtrlContainerJapanese* aUIContainer)
       
    63     :TAknFepUiInputStateJapaneseBase(aOwner, aUIContainer)
       
    64     {
       
    65     iState = EEntry;
       
    66     }
       
    67 
       
    68 /**
       
    69  * MPtiObserver interface.
       
    70  */
       
    71 //============================ MEMBER FUNCTIONS ==============================
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // TAknFepUiInputStateEntryJapaneseMultitap::KeyTimerExpired
       
    75 // Call this function when Multitap timer of PtiEngine was time-out
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void TAknFepUiInputStateEntryJapaneseMultitap::KeyTimerExpired()
       
    79     {
       
    80     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
    81     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
    82     const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
    83     TPtrC text = data->CompletedString();
       
    84 
       
    85     if (text.Length() > 0)
       
    86         {
       
    87         iOwner->ChangeState(EMultiCompletion);
       
    88         fepMan->ClearFlag(CAknFepManager::EFlagInsideMultitapInlineEditingTransaction);
       
    89         TRAP_IGNORE(fepMan->CommitInlineEditL());
       
    90         iOwner->ChangeState(EInitial);
       
    91         }
       
    92     else
       
    93         {
       
    94         TPtrC text2 = data->ConvertingString();
       
    95         TInt cursorpos = data->CursorPosition();
       
    96         if (text2.Length() > 0)
       
    97             {
       
    98             if (text2[0] == KAknFEPLineFeedSymbol
       
    99              || text2[0] == KAknFEPMirroredLineFeedSymbol)
       
   100                 {
       
   101                 iOwner->ChangeState(EInitial);
       
   102                 }
       
   103             else
       
   104                 {
       
   105                 // Set on cursor visibility in inline editing
       
   106                 TRAPD(err, fepMan->SetInlineEditingCursorVisibilityL(ETrue));
       
   107                 if (err == KErrNone)
       
   108                     {
       
   109                     TRAP(err, fepMan->UpdateInlineEditL(text2, cursorpos));
       
   110                     }
       
   111                 if (err != KErrNone)
       
   112                     {
       
   113                     TRAP_IGNORE(iOwner->FepMan()->SimulateKeyEventL(EKeyEscape, ETrue));
       
   114                     }
       
   115                 }
       
   116             }
       
   117         }
       
   118     }
       
   119 
       
   120 /**
       
   121  *  TAknFepUiInputStateEntryJapaneseMultitap class.
       
   122  *
       
   123  */
       
   124 //============================ MEMBER FUNCTIONS ==============================
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // TAknFepUiInputStateEntryJapaneseMultitap::InitializeStateL
       
   128 // Initialize State
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void TAknFepUiInputStateEntryJapaneseMultitap::InitializeStateL()
       
   132     {
       
   133     iOwner->SetInlineEditUnderlineVisibility(EFalse);
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // TAknFepUiInputStateEntryJapaneseMultitap::HandleNumericShortKeyL
       
   138 // HHandling short keypress events of the numeric and the star.
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 TBool TAknFepUiInputStateEntryJapaneseMultitap::HandleNumericShortKeyL(TInt aKey)
       
   142     {
       
   143     TBool cursorVisibility = EFalse;
       
   144     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   145     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   146     TBool ret = EFalse;
       
   147     if (aKey == EPtiKeyStar)
       
   148         {
       
   149         cursorVisibility = ETrue;
       
   150         }
       
   151     fepMan->SetInlineEditingCursorVisibilityL(cursorVisibility);
       
   152     ptiEngine->AppendKeyPress((TPtiKey)aKey);
       
   153     ret = UpdateInlineEditingCharacterL();
       
   154     return ret;
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // TAknFepUiInputStateEntryJapaneseMultitap::HandleNumericLongKeyL
       
   159 // Handling Numeric long keypress event
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 TBool TAknFepUiInputStateEntryJapaneseMultitap::HandleNumericLongKeyL(TInt /*aKey*/)
       
   163     {
       
   164     iOwner->ChangeState(EMultiCompletion);
       
   165     return EFalse;
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // TAknFepUiInputStateEntryJapaneseMultitap::HandleNaviKeyL
       
   170 // Handling navigate keypress event
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 TBool TAknFepUiInputStateEntryJapaneseMultitap::HandleNaviKeyL(TInt /*aKey*/,
       
   174                                                                TKeyPressLength /*aLength*/)
       
   175     {
       
   176     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   177     TBool ret = EFalse;
       
   178 
       
   179     ptiEngine->HandleCommandL(EPtiCommandUserActionComplete);
       
   180     ret = UpdateInlineEditingCharacterL();
       
   181 
       
   182     return ret;
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // TAknFepUiInputStateEntryJapaneseMultitap::HandleAuxKeyL
       
   187 // Handling auxiliary keypress events including OK and Backspace
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 TBool TAknFepUiInputStateEntryJapaneseMultitap::HandleAuxKeyL(TInt aKey,
       
   191                                                               TKeyPressLength /*aLength*/)
       
   192     {
       
   193     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   194     TBool ret = EFalse;
       
   195 
       
   196     switch(aKey)
       
   197         {
       
   198         case EKeyBackspace:
       
   199         case EStdKeyBackspace:      /* 0x01 */
       
   200             {
       
   201             MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   202             fepMan->SetInlineEditingCursorVisibilityL(ETrue);
       
   203             ptiEngine->DeleteKeyPress();
       
   204             ret = UpdateInlineEditingCharacterL();
       
   205             }
       
   206             break;
       
   207         case EKeyOK:
       
   208         case EStdKeyDevice3:        /* 0xA7 */
       
   209         case EStdKeyEnter:          /* 0x03 */
       
   210         case EStdKeyNkpEnter:       /* 0x88 */
       
   211             {
       
   212             iOwner->ChangeState(EMultiCompletion);
       
   213             }
       
   214             break;
       
   215         default:
       
   216             break;
       
   217         }
       
   218 
       
   219 
       
   220     return ret;
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // TAknFepUiInputStateEntryJapaneseMultitap::UpdateInlineEditingCharacterL
       
   225 // Update inline editing string
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 TBool TAknFepUiInputStateEntryJapaneseMultitap::UpdateInlineEditingCharacterL()
       
   229     {
       
   230     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   231     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   232     TBool ret = EFalse;
       
   233 
       
   234     if (!CommitInlineEditingCharacterL())
       
   235         {
       
   236         const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
   237         TPtrC text = data->ConvertingString();
       
   238         TInt cursorpos = data->CursorPosition();
       
   239         if (text.Length() > 0)
       
   240             {
       
   241             if (State() == EConversion
       
   242              || State() == ECandidate
       
   243              || State() == ECandidateRetroActive
       
   244              || State() == EPredictiveInput)
       
   245             	{
       
   246 	            if (data->NumberOfPhrase() > 0)
       
   247 	                {
       
   248 	                TPtrC8 clauseChar = data->LengthOfPhrase();
       
   249 	                cursorpos = clauseChar[0];
       
   250 	                }
       
   251             	}
       
   252             fepMan->UpdateInlineEditL(text, cursorpos);
       
   253             }
       
   254         else
       
   255             {
       
   256             __ASSERT_DEBUG(text.Length() == 0,
       
   257                 RDebug::Print(
       
   258                    _L("In TAknFepUiInputStateEntryJapaneseMultitap::UpdateInlineEditingCharacterL,\nINVALID DATA: ConvertingString. Roll back to initial State!")));
       
   259             ptiEngine->ClearCurrentWord();
       
   260             fepMan->CancelInlineEdit();
       
   261             iOwner->ChangeState(EInitial);
       
   262             }
       
   263         ret = ETrue;
       
   264         }
       
   265 
       
   266     return ret;
       
   267     }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // TAknFepUiInputStateEntryJapaneseMultitap::CommitInlineEditingCharacterL
       
   271 // Commit inline editing string
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 TBool TAknFepUiInputStateEntryJapaneseMultitap::CommitInlineEditingCharacterL()
       
   275     {
       
   276     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   277     TBool ret = EFalse;
       
   278     const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
   279     TPtrC text = data->CompletedString();
       
   280     if (text.Length() > 0)
       
   281         {
       
   282         iOwner->ChangeState(EMultiCompletion);
       
   283         ret = ETrue;
       
   284         }
       
   285     return ret;
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // TAknFepUiInputStatePredictiveInputJapanese::HandleCommandL
       
   290 // Handling Command
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void TAknFepUiInputStateEntryJapaneseMultitap::
       
   294     HandleCommandL(TInt aCommandId)
       
   295     {
       
   296     if(aCommandId == EAknFepSoftkeyCommit)
       
   297         {
       
   298         CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   299         const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
   300         TPtrC textConv = data->ConvertingString();
       
   301         TPtrC textComp = data->CompletedString();
       
   302         MAknFepUICtrlCandidatePaneInterface* candidatePane =
       
   303             UIContainer()->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   304                                          EJapaneseCandidatePane);
       
   305         TInt curr = candidatePane->CurrentItemIndexOfCandidate();
       
   306         if (curr > -1)
       
   307             {
       
   308             TInt old = 0;
       
   309             ptiEngine->HandleCommandL(EPtiCommandUserActionGetCurrentIndexOfCandidates, &old);
       
   310             while(curr > old)
       
   311                 {
       
   312                 ++old;
       
   313                 ptiEngine->HandleCommandL(EPtiCommandUserActionConvert);
       
   314                 }
       
   315             while(curr < old)
       
   316                 {
       
   317                 --old;
       
   318                 ptiEngine->HandleCommandL(EPtiCommandUserActionPrevious);
       
   319                 }
       
   320             }
       
   321         candidatePane->HideWindow();
       
   322         if (textConv.Length() > 0 || textComp.Length() > 0)
       
   323             {
       
   324             iOwner->ChangeState(EMultiCompletion);
       
   325             }
       
   326         else
       
   327             {
       
   328             iOwner->ChangeState(EInitial);
       
   329             }
       
   330         }
       
   331     }
       
   332 
       
   333 // End of file