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