fep/aknfep/src/AknFepUiInputStateEntryQwertyZhuyinPhrase.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     1 /*
       
     2 * Copyright (c) 2005 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 CAknFepUIInputStateQwertyZhuyinPhrase methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include "AknFepUiInputStateEntryQwertyZhuyinPhrase.h"
       
    31 #include "AknFepUIManagerStateInterface.h"
       
    32 
       
    33 #include "AknFepUICtrlInputPane.h"
       
    34 #include "AknFepUICtrlCandidatePane.h"
       
    35 #include "AknFepManagerUIInterface.h"       //MAknFepManagerUIInterface
       
    36 #include "AknFepManager.h"                  //FepMan flag
       
    37 
       
    38 #include <PtiEngine.h>
       
    39 #include <e32keys.h>
       
    40 #include <PtiDefs.h>                //keys
       
    41 
       
    42 const TInt KInputPaneLength = 32;
       
    43 _LIT(KSep, "'");
       
    44 _LIT(KReplace, "");
       
    45  
       
    46 
       
    47 TAknFepInputStateEntryQwertyZhuyinPhrase::TAknFepInputStateEntryQwertyZhuyinPhrase(
       
    48                                 MAknFepUIManagerStateInterface* aOwner,
       
    49                                 MAknFepUICtrlContainerChinese* aUIContainer)
       
    50     :TAknFepInputStateEntryQwertyBaseChinesePhrase(aOwner, aUIContainer)
       
    51     {
       
    52     UIContainer()->CandidatePane()->ShowCandidateOrdinals(EFalse);
       
    53     iOwner->PtiEngine()->SetInputMode(EPtiEngineZhuyinPhraseQwerty);
       
    54     iOwner->PtiEngine()->SetCase(EPtiCaseLower);
       
    55     }
       
    56 
       
    57 TBool TAknFepInputStateEntryQwertyZhuyinPhrase::HandleKeyL(TInt aKey, TKeyPressLength aLength)
       
    58     {
       
    59     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    60     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
    61     MAknFepUICtrlInputPane* inputPane = uiContainer->InputPane();
       
    62     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
    63     TBool ret = ETrue;
       
    64 
       
    65     if (iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagShiftKeyDepressed) ||
       
    66         iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed))
       
    67         {
       
    68         return ret;
       
    69         }
       
    70     
       
    71     if((aKey == EPtiKey3 || 
       
    72         aKey == EPtiKey4 || 
       
    73         aKey == EPtiKey6 || 
       
    74         aKey == EPtiKey7 ||
       
    75         aKey == EStdKeySpace) && 
       
    76         (aLength == EShortKeyPress))        
       
    77         {
       
    78         if(ptiengine->SetToneMark(aKey))
       
    79             {
       
    80             inputPane->SetFlag(MAknFepUICtrlInputPane::EPhoneticChanged);
       
    81             
       
    82             TBool multiplePages = !(uiContainer->CandidatePane()->IsLastPage() &&
       
    83                                     uiContainer->CandidatePane()->IsFirstPage());
       
    84             TInt bufLength = ptiengine->CandidatePage().Length();
       
    85             TBool showHorizontalScrollArrows = multiplePages || bufLength>1;
       
    86             
       
    87             UIContainer()->ShowHorizontalScrollArrows(showHorizontalScrollArrows);
       
    88             UIContainer()->ShowVerticalScrollArrows(multiplePages);
       
    89             SetInputPaneToneMark();
       
    90             RefreshUI();
       
    91             }
       
    92         }
       
    93     else if(aKey == EStdKeyBackspace)
       
    94         {
       
    95 		if (iOwner->PtiEngine()->DeleteKeyPress().Length())
       
    96             {
       
    97             uiContainer->ShowVerticalScrollArrows(!(uiContainer->CandidatePane()->IsLastPage() &&
       
    98                                                     uiContainer->CandidatePane()->IsFirstPage()));
       
    99             inputPane->SetFlag(MAknFepUICtrlInputPane::EPhoneticChanged);
       
   100             SetInputPaneToneMark();
       
   101             RefreshUI();
       
   102             }
       
   103         else
       
   104             {
       
   105             iOwner->FepMan()->TryCloseUiL();
       
   106             if (aLength == ELongKeyPress)
       
   107                 {
       
   108                 iOwner->FepMan()->SetLongClearAfterCloseUI(ETrue);
       
   109                 }
       
   110             }
       
   111         }
       
   112     else if((aLength == EShortKeyPress) && iOwner->IsValidChineseInputKeyQwerty(aKey))
       
   113         {
       
   114         ptiengine->AppendKeyPress((TPtiKey)aKey);
       
   115         inputPane->SetFlag(MAknFepUICtrlInputPane::EPhoneticChanged);
       
   116         uiContainer->ShowVerticalScrollArrows(!(uiContainer->CandidatePane()->IsLastPage() &&
       
   117                                                 uiContainer->CandidatePane()->IsFirstPage()));
       
   118         SetInputPaneToneMark();
       
   119         RefreshUI();
       
   120         }
       
   121     else if (aKey == EStdKeyLeftArrow )  
       
   122         {
       
   123         if (candidatePane->SelectedIndex() == 0 && 
       
   124             candidatePane->IsFirstPage())
       
   125             {
       
   126             return ETrue;    
       
   127             }
       
   128         else
       
   129             {
       
   130             iOwner->ChangeState(ECandidate);
       
   131             return EFalse;
       
   132             }
       
   133         }
       
   134     else if (aKey == EStdKeyRightArrow)
       
   135         {
       
   136         if (candidatePane->IsLastPage() && 
       
   137            (candidatePane->SelectedIndex() == candidatePane->VisibleCandidateCount() - 1))
       
   138             {
       
   139             return ETrue;    
       
   140             }
       
   141         else
       
   142             {
       
   143             iOwner->ChangeState(ECandidate);
       
   144             return EFalse;
       
   145             }
       
   146         }
       
   147     else if(aKey == EStdKeyDevice3)
       
   148         {
       
   149         TInt index = MapKeyToIndex(aKey);
       
   150 
       
   151         candidatePane->SelectIndex(index);
       
   152         TPtrC text = candidatePane->CurrentPhraseCandidate();
       
   153         if(text.Length())
       
   154             {            
       
   155             MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   156             fepMan->NewTextL(text);
       
   157             fepMan->CommitInlineEditL();
       
   158             iOwner->PtiEngine()->SetPredictiveChineseChar(text);
       
   159             iOwner->ChangeState(EPredictiveCandidate);
       
   160             }
       
   161         else
       
   162             {
       
   163             // No candidates available. Back to Entry state.
       
   164             iOwner->ChangeState(EEntry);
       
   165             }
       
   166         }
       
   167    else if (aKey == EStdKeyEnter)
       
   168         {
       
   169         TBuf<KInputPaneLength> currentText;
       
   170         inputPane->GetText(currentText);
       
   171         
       
   172         while(currentText.Find(KSep)> 0)
       
   173             {
       
   174             currentText.Replace(currentText.Find(KSep), 1,KReplace);
       
   175             }
       
   176         
       
   177         
       
   178         if(currentText.Length())
       
   179             {            
       
   180             MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   181             fepMan->NewTextL(currentText);
       
   182             fepMan->CommitInlineEditL();
       
   183             if (fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull))
       
   184                 {
       
   185                 fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
       
   186                 iOwner->FepMan()->TryCloseUiL();
       
   187                 }
       
   188             else
       
   189                 {
       
   190                 iOwner->FepMan()->TryCloseUiL();                
       
   191                 }
       
   192             }
       
   193         }
       
   194     else
       
   195         {
       
   196         ret = TAknFepInputStateEntryQwertyBaseChinesePhrase::HandleKeyL(aKey, aLength);
       
   197         }
       
   198     return ret;
       
   199     }
       
   200     
       
   201 void TAknFepInputStateEntryQwertyZhuyinPhrase::KeyTimerExpired()
       
   202     {
       
   203     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   204     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   205     MAknFepUICtrlInputPane* inputPane = uiContainer->InputPane();
       
   206     
       
   207     // set container's position
       
   208     TPoint baseLine = TPoint(0,0);
       
   209     TInt height = 0;
       
   210     TInt ascent = 0;
       
   211     TRAPD(ret,iOwner->FepMan()->GetScreenCoordinatesL(baseLine,height,ascent));
       
   212     if (ret == KErrNone)
       
   213         {
       
   214         uiContainer->SetContainerPosition(baseLine, height);    
       
   215         }
       
   216  
       
   217     TPtrC ptr = ptiengine->GetPhoneticSpelling(1);
       
   218     TBuf<KInputPaneLength> currentText;
       
   219     inputPane->GetText(currentText);
       
   220     if (ptr.Length() < currentText.Length())
       
   221         {
       
   222         iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   223         }
       
   224     inputPane->SetText(ptr);
       
   225     }
       
   226 
       
   227 // End of file