fep/aknfep/src/AknFepInputStateInitialChineseGenericHalfQwerty.cpp
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2002 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 AknFepUiInputStateInitialChineseGenericHalfQwerty methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 #include "AknFepUiInputStateInitialChineseGenericHalfQwerty.h"
       
    30 #include "AknFepUIManagerStateInterface.h"
       
    31 #include "AknFepManagerUIInterface.h"
       
    32 #include "AknFepManager.h"         //FepMan flag
       
    33 
       
    34 #include <PtiEngine.h>
       
    35 #include <AknFepFnKeyManager.h>
       
    36 
       
    37 const TInt KFnMappedCharacters = 5;
       
    38 _LIT(KEmotionSmile, "\x003A\x0029");//:)
       
    39 _LIT(KEmotionLaugh, "\x003A\x0050");//:P
       
    40 _LIT(KEmotionSad, "\x003A\x0028");//:(
       
    41 _LIT(KSpace," "); 
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // TAknFepInputStateInitialChineseGenericHalfQwerty::TAknFepInputStateInitialChineseGenericHalfQwerty
       
    45 // the construt funtion 
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 TAknFepInputStateInitialChineseGenericHalfQwerty
       
    49 ::TAknFepInputStateInitialChineseGenericHalfQwerty(MAknFepUIManagerStateInterface* aOwner, TInt /*aMode*/)
       
    50     :TAknFepInputStateHalfQwerty(aOwner)
       
    51     {
       
    52     iState = EInitial;
       
    53     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    54     TPtiTextCase caseMode = ptiengine->Case();
       
    55     ptiengine->ClearCurrentWord();
       
    56     ptiengine->SetInputMode(EPtiEngineHalfQwerty);
       
    57     ptiengine->SetCase(caseMode);
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // TAknFepInputStateInitialChineseGenericHalfQwerty::HandleKeyL
       
    62 // handle key event
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 TBool TAknFepInputStateInitialChineseGenericHalfQwerty::HandleKeyL(TInt aKey, TKeyPressLength aLength)
       
    66     {
       
    67     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    68     TBool ret = EFalse;
       
    69     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
    70     CAknFepFnKeyManager::TFnKeyState fnKeyState = fepMan->FnKeyState();
       
    71     if ( !fepMan->EditorHasFreeSpace() && fnKeyState )
       
    72         {
       
    73         return EFalse;
       
    74         }
       
    75     
       
    76     if ( aKey == EPtiKeyQwerty0 )
       
    77     	{
       
    78     	aKey = EPtiKeyQwertySpace;
       
    79     	}
       
    80     
       
    81     if (iData && (iData != aKey) && aKey != EStdKeyBackspace )
       
    82         {
       
    83         ptiengine->CancelTimerActivity();           
       
    84         ptiengine->ClearCurrentWord();        
       
    85         fepMan->ClearFlag( CAknFepManager::EFlagInsideMultitapInlineEditingTransaction );
       
    86         iData = 0;
       
    87         if ( fnKeyState == CAknFepFnKeyManager::EFnKeyNext )
       
    88             {
       
    89             fepMan->SetFnKeyState( CAknFepFnKeyManager::EFnKeyNone );
       
    90             fnKeyState = CAknFepFnKeyManager::EFnKeyNone;
       
    91             }
       
    92         }
       
    93     
       
    94     if( aKey == EStdKeyLeftFunc && !fnKeyState) //chr key
       
    95         {
       
    96         fepMan->LaunchSelectModeMenuL();
       
    97         }
       
    98     else if ( HandleEmotionKeyL( aKey, aLength ) )
       
    99         {
       
   100         return ETrue;
       
   101         }
       
   102     else if ( fnKeyState == CAknFepFnKeyManager::EFnKeyNone && (aKey
       
   103         == EPtiKeyQwertyLeftShift || aKey == EStdKeyF21 ) )
       
   104         {
       
   105         return EFalse;
       
   106         }
       
   107     else if ( aKey == EStdKeyLeftArrow || aKey == EStdKeyRightArrow || aKey
       
   108         == EStdKeyUpArrow || aKey == EStdKeyDownArrow || aKey
       
   109         == EStdKeyBackspace )
       
   110         {
       
   111         if ( fepMan->IsFlagSet( CAknFepManager::EFlagShiftKeyDepressed )
       
   112             && fnKeyState )
       
   113             {
       
   114             return ETrue;
       
   115             }
       
   116         else
       
   117             {
       
   118             if ( fnKeyState == CAknFepFnKeyManager::EFnKeyNext )
       
   119                 {
       
   120                 fepMan->SetFnKeyState( CAknFepFnKeyManager::EFnKeyNone );
       
   121                 }
       
   122             return EFalse;
       
   123             }
       
   124         }
       
   125     else if ( aKey == EStdKeyDevice0 || aKey == EStdKeyDevice1 || 
       
   126         aKey == EStdKeyDevice2 )
       
   127         {
       
   128         return EFalse;
       
   129         }
       
   130     else if ( aLength == EShortKeyPress
       
   131         && fepMan->IsFlagSet( CAknFepManager::EFlagShiftKeyDepressed )
       
   132         && aKey != EStdKeyLeftShift )
       
   133         {
       
   134         return ETrue;
       
   135         }
       
   136     else if ( ( IsCharacter( aKey ) && aLength == EShortKeyPress )
       
   137         && !fepMan->IsFlagSet( CAknFepManager::EFlagQwertyChrKeyDepressed )
       
   138         && !fepMan->IsFlagSet( CAknFepManager::EFlagQwertyShiftMode )
       
   139         && !fnKeyState )
       
   140         {
       
   141         ptiengine->ClearCurrentWord();
       
   142         ptiengine->ResetToneMark();
       
   143         if ( iOwner->IsValidChineseInputKeyQwerty( aKey ) )
       
   144             {
       
   145             if(iOwner->ChangeState(EEntry) == EEntry)
       
   146                 {
       
   147                 iOwner->FepMan()->SendUIActivatedNotification();
       
   148                 }
       
   149             }
       
   150         else if( aLength == EShortKeyPress )
       
   151             {
       
   152             iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   153             return ETrue;
       
   154             }
       
   155         }
       
   156     else if ( fepMan->IsFlagSet( CAknFepManager::EFlagQwertyShiftMode )
       
   157         && fepMan->IsFlagSet( CAknFepManager::EFlagQwertyChrKeyDepressed ) )
       
   158         {
       
   159         ret = ETrue;
       
   160         }
       
   161     else if ( aKey == EPtiKeyQwertyApostrophe && aLength == ELongKeyPress )
       
   162         {
       
   163         ret = ETrue; 
       
   164         }
       
   165     else if (IsSCTKey(aKey))
       
   166         {
       
   167         HandleKeyByShiftOrCharPressedL(aKey,aLength);
       
   168         if (fepMan->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed))
       
   169             {
       
   170             fepMan->ClearFlag(CAknFepManager::EFlagNoActionDuringChrKeyPress);        
       
   171             }
       
   172         ret = ETrue;
       
   173         }
       
   174     else if( aKey == EStdKeySpace )
       
   175         {
       
   176         if ( aLength == EShortKeyPress)
       
   177             {
       
   178             fepMan->StartInlineEditL();
       
   179             fepMan->UpdateInlineEditL( KSpace, 0 );
       
   180             fepMan->CommitInlineEditL();
       
   181             if (fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull))
       
   182                 {
       
   183                 fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
       
   184                 }
       
   185             }
       
   186         else
       
   187             {
       
   188             TPtrC text;
       
   189             TBuf<KFnMappedCharacters> allFnMappedCharacters;
       
   190             ptiengine->MappingDataForKey( (TPtiKey)aKey,
       
   191                 allFnMappedCharacters, EPtiCaseFnLower );
       
   192             text.Set( allFnMappedCharacters );
       
   193             if ( text.Length() > 0 )
       
   194                 {
       
   195                 TBuf<1> chr;
       
   196                 chr.Append( text[0] );
       
   197                 fepMan->RemovePreviousCharacterL();
       
   198                 fepMan->NewCharacterL( chr );
       
   199                 fepMan->CommitInlineEditL();
       
   200                 if (fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull))
       
   201                     {
       
   202                     fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
       
   203                     }
       
   204                 ptiengine->ClearCurrentWord();
       
   205                 iData = 0;
       
   206                 }
       
   207             }
       
   208         ret = ETrue;
       
   209         }
       
   210     else
       
   211         {
       
   212         ret = TAknFepInputStateHalfQwerty::HandleKeyL( aKey, aLength );
       
   213         if ( fnKeyState == CAknFepFnKeyManager::EFnKeyNext && !IsMultitapkey( aKey ) )
       
   214             {
       
   215             fepMan->SetFnKeyState( CAknFepFnKeyManager::EFnKeyNone );
       
   216             }
       
   217         if (fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull))
       
   218             {
       
   219             fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
       
   220             }
       
   221         }
       
   222     return ret;
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // TAknFepInputStateInitialChineseGenericHalfQwerty::IsSCTKey
       
   227 // to check whether the key is sct key 
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 TBool TAknFepInputStateInitialChineseGenericHalfQwerty::IsSCTKey(TInt aKey)
       
   231     {
       
   232     TBool response = EFalse;
       
   233     switch (iOwner->FepMan()->InputMode())
       
   234         {
       
   235         case EPinyin:
       
   236             break;
       
   237         case EStroke:
       
   238         case EZhuyin:
       
   239             if (aKey == EPtiKeyQwertyQ ||aKey == EPtiKeyQwertyA ||aKey
       
   240                     == EPtiKeyQwertyZ ||aKey == EPtiKeyQwertyO ||aKey
       
   241                     == EPtiKeyQwertyL)
       
   242                 {
       
   243                 response = ETrue;
       
   244                 }
       
   245             break;
       
   246         case EStrokeFind:
       
   247         case EZhuyinFind:
       
   248             if (aKey >= EPtiKeyQwertyA && aKey <= EPtiKeyQwertyZ)
       
   249                 {
       
   250                 response = ETrue;
       
   251                 }
       
   252             break;
       
   253         }
       
   254     if ( (/*aKey == EStdKeyFullStop || */aKey == EStdKeySpace )
       
   255         && iOwner->FepMan()->FnKeyState() )
       
   256         {
       
   257         response = ETrue;
       
   258         }
       
   259     return response;
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // TAknFepInputStateInitialChineseGenericHalfQwerty::IsCharacter
       
   264 // to check whether the key stroke is a character key or not 
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 TBool TAknFepInputStateInitialChineseGenericHalfQwerty::IsCharacter(TInt aKey)
       
   268     {
       
   269     TBool response = EFalse;
       
   270     switch (iOwner->FepMan()->InputMode())
       
   271         {
       
   272         case EPinyin:
       
   273             if (( aKey >= EPtiKeyQwertyA && aKey <= EPtiKeyQwertyZ ) ||
       
   274             	( aKey >= EPtiKeyQwerty0 && aKey <= EPtiKeyQwerty9 ) )
       
   275                 {
       
   276                 response = ETrue;
       
   277                 }
       
   278             break;
       
   279         case EStroke:
       
   280         case EStrokeFind:
       
   281             if ((aKey == EPtiKeyQwertyE ||aKey == EPtiKeyQwertyT ||aKey
       
   282                     == EPtiKeyQwertyU ||aKey == EPtiKeyQwertyD ||aKey
       
   283                     == EPtiKeyQwertyG ||aKey == EPtiKeyQwertyJ ) || 
       
   284                (aKey >= EPtiKeyQwerty0 && aKey <= EPtiKeyQwerty6))
       
   285                 {
       
   286                 response = ETrue;
       
   287                 }
       
   288             break;
       
   289         case EZhuyin:
       
   290             if ( (aKey == EPtiKeyQwertyE ||aKey == EPtiKeyQwertyT ||aKey
       
   291                     == EPtiKeyQwertyU ||aKey == EPtiKeyQwertyD ||aKey
       
   292                     == EPtiKeyQwertyG ||aKey == EPtiKeyQwertyJ ||aKey
       
   293                     == EPtiKeyQwertyC ||aKey == EPtiKeyQwertyB ||aKey
       
   294                     == EPtiKeyQwertyM ||aKey == EPtiKeyQwertySpace ) ||
       
   295                 (aKey >= EPtiKeyQwerty0 && aKey <= EPtiKeyQwerty9))
       
   296                 {
       
   297                 response = ETrue;
       
   298                 }
       
   299             break;
       
   300         }
       
   301     return response;
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // TAknFepInputStateInitialChineseGenericHalfQwerty::HandleKeyByShiftOrCharPressedL
       
   306 // Handle the shift key envent 
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 TBool TAknFepInputStateInitialChineseGenericHalfQwerty::HandleKeyByShiftOrCharPressedL(
       
   310     TInt aKey, TKeyPressLength aLength)
       
   311     {
       
   312     TBool ret = EFalse;
       
   313     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   314     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   315     fepMan->ClearFlag(CAknFepManager::EFlagNoActionDuringShiftKeyPress);
       
   316     TPtiTextCase caseMode = EPtiCaseLower;
       
   317     TBool setfnstate = EFalse;
       
   318     if (fepMan->IsOnlyNumericPermitted())
       
   319         {
       
   320         return ret;
       
   321         }
       
   322     TPtiTextCase shiftedCase = caseMode;
       
   323     if (fepMan->IsFlagSet(CAknFepManager::EFlagQwertyShiftMode)) 
       
   324         {
       
   325         shiftedCase = EPtiCaseUpper;
       
   326         } 
       
   327     if (fepMan->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed) )
       
   328         {
       
   329         shiftedCase = EPtiCaseChrLower;
       
   330         }
       
   331     if ( fepMan->FnKeyState() )
       
   332         {
       
   333         shiftedCase = EPtiCaseFnLower;
       
   334         }
       
   335     if ( aKey == EPtiKeyQwertyQ ||aKey == EPtiKeyQwertyA ||aKey
       
   336         == EPtiKeyQwertyZ ||aKey == EPtiKeyQwertyO ||aKey == EPtiKeyQwertyL )
       
   337         {
       
   338         shiftedCase = EPtiCaseFnLower;
       
   339         setfnstate = ETrue;
       
   340         }
       
   341     ptiengine->SetCase(shiftedCase);
       
   342     TPtrC text;
       
   343     text.Set(ptiengine->AppendKeyPress((TPtiKey)aKey));
       
   344     if (text.Length())
       
   345         {
       
   346         if ( aLength == ELongKeyPress && !iOwner->FepMan()->FnKeyState() )
       
   347             {
       
   348             fepMan->RemovePreviousCharacterL();
       
   349             }
       
   350         TBuf<1> chr;            
       
   351         for (TInt jj = 0; jj < text.Length(); jj++)
       
   352             {
       
   353             chr.Zero();
       
   354             chr.Append( text[jj] );
       
   355             fepMan->NewCharacterL( chr );
       
   356             fepMan->CommitInlineEditL();
       
   357             if (fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull))
       
   358                 {
       
   359                 fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
       
   360                 }
       
   361             ptiengine->ClearCurrentWord();
       
   362             }
       
   363         ret = ETrue;
       
   364         }
       
   365     if(setfnstate && fepMan->FnKeyState() == CAknFepFnKeyManager::EFnKeyNext )
       
   366         {
       
   367         ptiengine->SetCase(EPtiCaseLower); 
       
   368         }    
       
   369     
       
   370     CAknFepFnKeyManager::TFnKeyState fnKeyState  = fepMan->FnKeyState();    
       
   371     if(fnKeyState == CAknFepFnKeyManager::EFnKeyNext)
       
   372         fepMan->SetFnKeyState(CAknFepFnKeyManager::EFnKeyNone);
       
   373     return ret;
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // TAknFepInputStateInitialChineseGenericHalfQwerty::HandleEmotionKeyL
       
   378 // Handle the emotion key envent 
       
   379 // ---------------------------------------------------------------------------
       
   380 //
       
   381 TBool TAknFepInputStateInitialChineseGenericHalfQwerty::HandleEmotionKeyL( TInt aKey, TKeyPressLength aLength )
       
   382     {
       
   383     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   384     TBool ret = EFalse;
       
   385     TPtrC emotion;
       
   386     if ( ( aKey != EPtiKeyQwerty7 &&
       
   387          aKey != EPtiKeyQwerty8 &&
       
   388          aKey != EPtiKeyQwerty9 ) ||
       
   389          fepMan->FnKeyState())
       
   390         {
       
   391         return EFalse;
       
   392         }
       
   393     if ( EStroke == fepMan->InputMode() || EStrokeFind == fepMan->InputMode() )
       
   394         {
       
   395         if ( fepMan->IsFlagSet( CAknFepManager::EFlagEditorFull ) )
       
   396             {
       
   397             fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
       
   398             return ETrue;
       
   399             }
       
   400         else
       
   401             {
       
   402             switch ( aKey )
       
   403                 {
       
   404                 case EPtiKeyQwerty7:
       
   405                     emotion.Set( KEmotionSmile );
       
   406                     ret = ETrue;
       
   407                     break;
       
   408                 case EPtiKeyQwerty8:
       
   409                     emotion.Set( KEmotionLaugh );
       
   410                     ret = ETrue;
       
   411                     break;
       
   412                 case EPtiKeyQwerty9:
       
   413                     emotion.Set( KEmotionSad );
       
   414                     ret = ETrue;
       
   415                     break;
       
   416                 default:
       
   417                     break;
       
   418                 }
       
   419             }
       
   420         }
       
   421     if ( ret )
       
   422         {
       
   423         if ( aLength == EShortKeyPress)
       
   424             {
       
   425             fepMan->NewTextL(emotion);
       
   426             fepMan->CommitInlineEditL();
       
   427             if (fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull))
       
   428                 {
       
   429                 fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
       
   430                 }
       
   431             }
       
   432         else
       
   433             {
       
   434             for( TInt i=0; i<emotion.Length(); i++ )
       
   435                 {
       
   436                 fepMan->RemovePreviousCharacterL();
       
   437                 }
       
   438             fepMan->SetFnKeyState( CAknFepFnKeyManager::EFnKeyNext );
       
   439             fepMan->PtiEngine()->SetCase( EPtiCaseFnLower );
       
   440             return EFalse;
       
   441             }
       
   442         }
       
   443     return ret;
       
   444     }
       
   445 
       
   446 TBool TAknFepInputStateInitialChineseGenericHalfQwerty::IsMultitapkey( TInt aKey )
       
   447     {
       
   448     TBool ret = EFalse;
       
   449     if ( aKey == EStdKeyLeftFunc || aKey == EPtiKeyQwertyLeftShift ||
       
   450         aKey == EStdKeyFullStop )
       
   451         {
       
   452         ret = ETrue;
       
   453         }
       
   454     return ret;
       
   455     }
       
   456 //end of the file