fep/aknfep/src/AknFepUiInputStatePredictiveCandidatePhrase.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     1 /*
       
     2 * Copyright (c) 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 TAknFepInputStatePredictiveCandidatePhrase methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include "AknFepUiInputStatePredictiveCandidatePhrase.h"
       
    31 #include "AknFepUICtrlCandidatePane.h"
       
    32 #include "AknFepUiCtrlContainerChinese.h"
       
    33 #include "AknFepUIManagerStateInterface.h"  //MAknFepUIManagerStateInterface
       
    34 #include "AknFepManagerUIInterface.h"       //MAknFepManagerUIInterface
       
    35 
       
    36 #include <PtiEngine.h>                      //CPtiEngine
       
    37 
       
    38 TAknFepInputStatePredictiveCandidatePhrase::TAknFepInputStatePredictiveCandidatePhrase(
       
    39                                 MAknFepUIManagerStateInterface* aOwner,
       
    40                                 MAknFepUICtrlContainerChinese* aUIContainer)
       
    41     :TAknFepInputStateCandidateBasePhrase(aOwner, aUIContainer)
       
    42     {
       
    43     iState = EPredictiveCandidate;
       
    44     
       
    45     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
    46 
       
    47     // set container window position to follow cursor
       
    48     TPoint baseLine = TPoint(0,0);
       
    49     TInt height = 0;
       
    50     TInt ascent = 0;
       
    51     TRAPD(ret,iOwner->FepMan()->GetScreenCoordinatesL(baseLine,height,ascent));
       
    52     if (ret == KErrNone)
       
    53         {
       
    54         uiContainer->SetContainerPosition(baseLine, height);    
       
    55         }
       
    56     uiContainer->FocusCandidatePane(ETrue);
       
    57 
       
    58     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    59     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
    60     // for some reason needs to feed back to ptiengine current Chinese phrase just before get the prediction
       
    61     TPtrC text = candidatePane->CurrentPhraseCandidate();
       
    62     candidatePane->SelectFirstPhrase(); 
       
    63     ptiengine->SetPredictiveChineseChar(text);
       
    64     
       
    65     TRAPD(ignore,ptiengine->GetChinesePhraseCandidatesL(*(candidatePane->CandidateArray())));
       
    66     if (ignore == KErrNone)
       
    67         {
       
    68         candidatePane->SplitPhraseCandidatesIntoPages(); 
       
    69         uiContainer->SetLayout(MAknFepUICtrlContainerChinese::ELayoutCandidate);
       
    70         candidatePane->SetCandidateBuffer();
       
    71 
       
    72         TBool multiplePages = !(uiContainer->CandidatePane()->IsLastPage() &&
       
    73                                 uiContainer->CandidatePane()->IsFirstPage());
       
    74         TInt bufLength = iOwner->PtiEngine()->CandidatePage().Length();
       
    75         TBool showHorizontalScrollArrows = multiplePages || bufLength>1;
       
    76 
       
    77         uiContainer->ShowHorizontalScrollArrows(showHorizontalScrollArrows); 
       
    78         uiContainer->ShowVerticalScrollArrows(multiplePages);
       
    79         candidatePane->ShowCandidateOrdinals(EFalse);
       
    80         }
       
    81     }
       
    82 
       
    83 TBool TAknFepInputStatePredictiveCandidatePhrase::HandleKeyL(TInt aKey, TKeyPressLength aLength)
       
    84     {
       
    85     TBool ret = ETrue;
       
    86 
       
    87     if(aLength == ELongKeyPress) 
       
    88         {
       
    89         return ret;
       
    90         }
       
    91     if(iOwner->IsValidChineseInputKey(aKey))
       
    92         {
       
    93         CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    94         // needs to clear current word for current engine, otherwise buffer is not cleared
       
    95         ptiengine->ClearCurrentWord(); 
       
    96         ptiengine->ResetToneMark();
       
    97 
       
    98         iOwner->ChangeState(EEntry);
       
    99         ret = EFalse; //passes to entry state to handle the key
       
   100         }
       
   101     if(!HandleVerticalNavigation(aKey))
       
   102         {
       
   103         if (aKey == EKeyLeftArrow || aKey == EKeyRightArrow || aKey == EKeyOK)
       
   104             {
       
   105             iOwner->ChangeState(EPredictiveInput);
       
   106             ret = EFalse; //passes to predictive input state to handle the key
       
   107             }
       
   108         else if(aKey == EKeyBackspace)
       
   109             {
       
   110             iOwner->FepMan()->TryCloseUiL();
       
   111             }
       
   112         else if (aKey == EPtiKeyStar)
       
   113             {
       
   114             ret = TAknFepInputStateCandidateBasePhrase::HandleKeyL(aKey, aLength);
       
   115             }   
       
   116         }
       
   117     return ret;
       
   118     }
       
   119 
       
   120 // End of file