fep/aknfep/src/AknFepUiInputStateEntryQwertyPinyin.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 CAknFepUIInputStateEntryQwertyPinyin methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include "AknFepUIManagerStateInterface.h"  //MAknFepUIManagerStateInterface
       
    31 #include "AknFepUiCtrlContainerChinese.h"
       
    32 #include "AknFepManagerUIInterface.h"       //MAknFepManagerUIInterface
       
    33 #include "AknFepUICtrlCandidatePane.h"
       
    34 #include "AknFepUICtrlInputPane.h"
       
    35 #include "AknFepUiInputStateEntryQwertyPinyin.h"
       
    36 #include "AknFepManager.h"                  //FepMan flag
       
    37 
       
    38 #include <PtiEngine.h>      //CPtiEngine
       
    39 #include <e32keys.h>        //keys  
       
    40 #include <avkon.rsg>
       
    41 
       
    42 const TText KPinyinTone4Valid = 0x02D9;
       
    43 const TText KPinyinTone4Invalid = 0x0020;
       
    44 const TInt KMaxCandidateCountFromCore = 6;
       
    45 
       
    46 TAknFepInputStateEntryQwertyPinyin::TAknFepInputStateEntryQwertyPinyin(
       
    47                                MAknFepUIManagerStateInterface* aOwner,
       
    48                                MAknFepUICtrlContainerChinese* aUIContainer)
       
    49     :TAknFepInputStateEntryQwertyBase(aOwner,aUIContainer)                           
       
    50     {
       
    51     UIContainer()->CandidatePane()->ShowCandidateOrdinals(ETrue);
       
    52     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    53     ptiengine->SetInputMode(EPtiEnginePinyinQwerty);
       
    54     ptiengine->SetCase(EPtiCaseLower);
       
    55     ptiengine->SetCandidatePageLength(MAknFepUICtrlContainerChinese::ELayoutInput);
       
    56     UpdateIndicator();
       
    57     }
       
    58 
       
    59 TBool TAknFepInputStateEntryQwertyPinyin::HandleKeyL(TInt aKey, TKeyPressLength aLength)
       
    60     {
       
    61     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    62     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();    
       
    63     TBool ret = ETrue;
       
    64 
       
    65     if((aKey == EStdKeyLeftFunc) && (aLength == EShortKeyPress))
       
    66         {
       
    67         if(ptiengine->IncrementToneMark(ETrue))
       
    68             {
       
    69             RefreshUI();
       
    70             }
       
    71         }
       
    72     else if(aKey == EStdKeyBackspace)
       
    73         {
       
    74 		if (iOwner->PtiEngine()->DeleteKeyPress().Length())
       
    75             {
       
    76             RefreshUI();
       
    77             }
       
    78         else
       
    79             {
       
    80             iOwner->FepMan()->TryCloseUiL();
       
    81             if (aLength == ELongKeyPress)
       
    82                 {
       
    83                 iOwner->FepMan()->SetLongClearAfterCloseUI(ETrue);
       
    84                 }
       
    85             }
       
    86         }        
       
    87     else if((aLength == EShortKeyPress) && iOwner->IsValidChineseInputKeyQwerty(aKey))
       
    88         {
       
    89         TInt stringBeforeLength(0);
       
    90         TInt stringAfterLength(0);
       
    91         
       
    92         stringBeforeLength = ptiengine->GetPhoneticSpelling(1).Length();
       
    93         stringAfterLength = ptiengine->AppendKeyPress((TPtiKey)aKey).Length();
       
    94         
       
    95         if (stringBeforeLength != stringAfterLength)
       
    96             {
       
    97             if (ptiengine->GetPhoneticSpelling(1).Length() == 1)
       
    98             {
       
    99             iOwner->FepMan()->UpdateCbaL(R_AVKON_SOFTKEYS_EMPTY);
       
   100             }            
       
   101             RefreshUI();
       
   102             }
       
   103 	    else
       
   104 	        {
       
   105 	        iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   106 	        }            
       
   107         
       
   108         if (ptiengine->GetPhoneticSpelling(1).Length() == 0)
       
   109             {
       
   110             iOwner->FepMan()->UpdateCbaL(NULL);
       
   111             }
       
   112         }        
       
   113     else if(aKey == EStdKeyDevice1)
       
   114         {
       
   115         iOwner->FepMan()->TryCloseUiL();
       
   116         }
       
   117     else if(!( HandleVerticalNavigation(aKey) || HandleHorizontalNavigation(aKey) ))
       
   118         {
       
   119         // it may be one of the 'valid' numbers..
       
   120         TInt index = MapKeyToIndex(aKey);
       
   121         MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
       
   122 
       
   123         if(candidatePane->SelectIndex(index) || aKey == EStdKeyDevice3 || aKey == EStdKeyEnter)
       
   124             {
       
   125             TPtrC text = candidatePane->CurrentCandidate();
       
   126             if(text.Length())
       
   127                 {            
       
   128                 MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   129                 iOwner->FepMan()->NewCharacterL(text);
       
   130                 iOwner->FepMan()->CommitInlineEditL();
       
   131                 if (iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagEditorFull))
       
   132                     {
       
   133                     iOwner->FepMan()->ClearFlag(CAknFepManager::EFlagEditorFull);
       
   134                     iOwner->FepMan()->TryCloseUiL();
       
   135                     }
       
   136                 else
       
   137                     {
       
   138                     iOwner->ChangeState(EPredictiveInput);
       
   139                     }
       
   140                 }
       
   141             else
       
   142                 {
       
   143                 // No candidates available. Back to Entry state.
       
   144                 iOwner->ChangeState(EEntry);
       
   145                 }
       
   146             }
       
   147         }
       
   148     return ret;
       
   149     }
       
   150 
       
   151 void TAknFepInputStateEntryQwertyPinyin::RefreshUI()
       
   152     {
       
   153     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   154     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   155     MAknFepUICtrlInputPane* inputPane = uiContainer->InputPane();
       
   156     
       
   157     SetInputPaneToneMark();    
       
   158 
       
   159     TPtrC ptr = ptiengine->GetPhoneticSpelling(1);
       
   160     TBool multiplePages = ptiengine->MoreCandidatePages();
       
   161     TInt bufLength = ptiengine->CandidatePage().Length();
       
   162     TBool showHorizontalScrollArrows = multiplePages || bufLength>1;
       
   163             
       
   164     UIContainer()->ShowHorizontalScrollArrows(showHorizontalScrollArrows); 
       
   165     UIContainer()->ShowVerticalScrollArrows(multiplePages);
       
   166     
       
   167     // set container's position
       
   168     TPoint baseLine = TPoint(0,0);
       
   169     TInt height = 0;
       
   170     TInt ascent = 0;
       
   171     TRAPD(ret,iOwner->FepMan()->GetScreenCoordinatesL(baseLine,height,ascent));
       
   172     if (ret == KErrNone)
       
   173         {
       
   174         uiContainer->SetContainerPosition(baseLine, height);    
       
   175         }
       
   176   
       
   177     TText toneMark;
       
   178     TBool toneMarkEntered = ptiengine->ToneMark(toneMark);
       
   179     TBuf<1> validToneMarkBuf;
       
   180     if(toneMarkEntered)
       
   181         {
       
   182         // override specific invalid tonemark character only, the others are the same character 
       
   183         // when both valid and invalid
       
   184         if(toneMark == KPinyinTone4Invalid)
       
   185             toneMark = KPinyinTone4Valid;
       
   186         validToneMarkBuf.Append(toneMark);
       
   187         }
       
   188 
       
   189     ptiengine->EnableToneMarks(ETrue);
       
   190  
       
   191     if (ptr.Length() > 0)
       
   192         {
       
   193         TPtrC candidates = ptiengine->CandidatePage();
       
   194         uiContainer->CandidatePane()->SetCandidateBuffer(candidates);
       
   195         uiContainer->Enable(ETrue);
       
   196         uiContainer->CandidatePane()->SelectFirst();
       
   197         
       
   198         inputPane->SetText(ptr);
       
   199         inputPane->SetToneMark(validToneMarkBuf);  
       
   200      
       
   201         UpdateIndicator();
       
   202         }
       
   203     }
       
   204     
       
   205 TBool TAknFepInputStateEntryQwertyPinyin::HandleHorizontalNavigation(TInt aKey)
       
   206     {
       
   207     MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
       
   208     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   209     TBool response = EFalse;
       
   210 
       
   211     // Do navigation...
       
   212     if (aKey == EStdKeyLeftArrow)
       
   213         {
       
   214         if (candidatePane->SelectedIndex() == 0 && 
       
   215             ptiengine->NumberOfCandidates() == 0)
       
   216             {
       
   217             return ETrue;
       
   218             }
       
   219         
       
   220         if(!candidatePane->SelectPrev())
       
   221             {
       
   222             ptiengine->PreviousCandidatePage();
       
   223             candidatePane->SetCandidateBuffer(ptiengine->CandidatePage());
       
   224             candidatePane->SelectLast();
       
   225             }
       
   226         UpdateIndicator();            
       
   227         response = ETrue;
       
   228         }
       
   229     else if (aKey == EStdKeyRightArrow)
       
   230         {
       
   231         TInt bufLength = iOwner->PtiEngine()->CandidatePage().Length();
       
   232         
       
   233         if (bufLength != KMaxCandidateCountFromCore &&
       
   234             candidatePane->SelectedIndex() == (bufLength -1))
       
   235             {
       
   236 			return ETrue;
       
   237             }
       
   238         
       
   239         if(!candidatePane->SelectNext())
       
   240             {
       
   241             ptiengine->NextCandidatePage();
       
   242             candidatePane->SetCandidateBuffer(ptiengine->CandidatePage());
       
   243             candidatePane->SelectFirst();
       
   244             }
       
   245         UpdateIndicator();    
       
   246         response = ETrue;
       
   247         }
       
   248     return response;
       
   249     }
       
   250 
       
   251 TBool TAknFepInputStateEntryQwertyPinyin::HandleVerticalNavigation(TInt aKey)
       
   252     {
       
   253     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   254 
       
   255     if (aKey == EStdKeyDownArrow || aKey == EStdKeySpace)
       
   256         {
       
   257         if (iOwner->PtiEngine()->CandidatePage().Length() != 
       
   258             KMaxCandidateCountFromCore)
       
   259             {
       
   260             return ETrue;
       
   261             }
       
   262         ptiengine->NextCandidatePage();
       
   263         }
       
   264     else if (aKey == EStdKeyUpArrow)
       
   265         {
       
   266         if (ptiengine->NumberOfCandidates() == 0)
       
   267             {								 
       
   268             return ETrue;
       
   269             }
       
   270         ptiengine->PreviousCandidatePage();
       
   271         }
       
   272     else
       
   273         {
       
   274         return EFalse;
       
   275         }
       
   276 
       
   277     MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
       
   278     candidatePane->SelectFirst();
       
   279     candidatePane->SetCandidateBuffer(ptiengine->CandidatePage());
       
   280     UpdateIndicator();
       
   281     return ETrue;
       
   282     }
       
   283  
       
   284  void TAknFepInputStateEntryQwertyPinyin::UpdateIndicator()
       
   285     {
       
   286     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   287     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();        
       
   288     TInt bufLength = iOwner->PtiEngine()->CandidatePage().Length();
       
   289     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
   290         
       
   291     if (ptiengine->NumberOfCandidates() == 0)
       
   292         {
       
   293         uiContainer->CandidatePane()->ShowUpScrollArrows(EFalse);    
       
   294         }
       
   295     else
       
   296         {
       
   297         uiContainer->CandidatePane()->ShowUpScrollArrows(ETrue);    
       
   298         }
       
   299     
       
   300     uiContainer->CandidatePane()->ShowDownScrollArrows
       
   301         (bufLength == KMaxCandidateCountFromCore ? ETrue : EFalse);
       
   302         
       
   303     if (candidatePane->SelectedIndex() == 0 && 
       
   304         ptiengine->NumberOfCandidates() == 0)
       
   305         {
       
   306         uiContainer->CandidatePane()->ShowLeftScrollArrows(EFalse);
       
   307         }
       
   308     else
       
   309         {
       
   310         uiContainer->CandidatePane()->ShowLeftScrollArrows(ETrue);
       
   311         }
       
   312         
       
   313     if (bufLength != KMaxCandidateCountFromCore &&
       
   314         candidatePane->SelectedIndex() == (bufLength -1))
       
   315         {
       
   316         uiContainer->CandidatePane()->ShowRightScrollArrows(EFalse);        
       
   317         }
       
   318     else
       
   319         {
       
   320         uiContainer->CandidatePane()->ShowRightScrollArrows(ETrue);
       
   321         }
       
   322     }
       
   323     
       
   324 // ---------------------------------------------------------------------------
       
   325 // TAknFepInputStateEntryQwertyPinyin::HandleCommandL
       
   326 // Handling Command
       
   327 // ---------------------------------------------------------------------------
       
   328 //
       
   329  void TAknFepInputStateEntryQwertyPinyin::HandleCommandL( TInt aCommandId )
       
   330     {
       
   331     TAknFepInputStateChineseBase::HandleCommandL( aCommandId );
       
   332     }
       
   333 // End of file