fep/aknfep/src/AknFepUiInputStatePredictiveInputQwertyPinyin.cpp
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     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 TAknFepInputStatePredictiveInputQwerty methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include "AknFepUiInputStatePredictiveInputQwertyPinyin.h"
       
    31 #include "AknFepUICtrlCandidatePane.h"
       
    32 #include "AknFepUiCtrlContainerChinese.h"
       
    33 #include "AknFepUIManagerStateInterface.h"  //MAknFepUIManagerStateInterface
       
    34 #include "AknFepManagerUIInterface.h"       //MAknFepManagerUIInterface
       
    35 #include "AknFepManager.h"                  //FepMan flag
       
    36 
       
    37 #include <PtiEngine.h>                      //CPtiEngine
       
    38 
       
    39 TAknFepInputStatePredictiveInputQwertyPinyin::TAknFepInputStatePredictiveInputQwertyPinyin(
       
    40                                 MAknFepUIManagerStateInterface* aOwner,
       
    41                                 MAknFepUICtrlContainerChinese* aUIContainer)
       
    42     :TAknFepInputStateCandidateQwertyChineseBase(aOwner, aUIContainer)
       
    43     {
       
    44     iState = EPredictiveInput;
       
    45     
       
    46     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
    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     uiContainer->SetLayout(MAknFepUICtrlContainerChinese::ELayoutCandidate);
       
    58 
       
    59     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    60     ptiengine->SetCandidatePageLength(MAknFepUICtrlContainerChinese::ELayoutInput);
       
    61 
       
    62     // for some reason needs to feed back to ptiengine current Chinese char just before get the prediction
       
    63     TPtrC text = uiContainer->CandidatePane()->CurrentCandidate();
       
    64     uiContainer->CandidatePane()->SelectFirst(); 
       
    65     ptiengine->SetPredictiveChineseChar(text);
       
    66     uiContainer->CandidatePane()->SetCandidateBuffer(ptiengine->CandidatePage());
       
    67 
       
    68     TBool multiplePages = ptiengine->MoreCandidatePages();
       
    69     TInt bufLength = ptiengine->CandidatePage().Length();
       
    70     TBool showHorizontalScrollArrows = multiplePages || bufLength>1;
       
    71     
       
    72     uiContainer->ShowVerticalScrollArrows(multiplePages);
       
    73     uiContainer->ShowHorizontalScrollArrows(showHorizontalScrollArrows);
       
    74     uiContainer->CandidatePane()->ShowCandidateOrdinals(ETrue);
       
    75     UpdateIndicator();
       
    76     }
       
    77 
       
    78 TBool TAknFepInputStatePredictiveInputQwertyPinyin::HandleKeyL(TInt aKey, TKeyPressLength aLength)
       
    79     {
       
    80     TBool ret = ETrue;
       
    81     if (iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagQwertyShiftMode) ||
       
    82         iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed))
       
    83         {
       
    84         iOwner->FepMan()->TryCloseUiL();
       
    85         ret = EFalse;
       
    86         }
       
    87     else if (IsValidEntryKey(aKey))
       
    88         {
       
    89         iOwner->FepMan()->TryCloseUiL();
       
    90         ret = EFalse;
       
    91         }
       
    92     else if(aKey == EStdKeyBackspace)
       
    93         {
       
    94         iOwner->FepMan()->TryCloseUiL();
       
    95         }
       
    96     else if(aKey == EStdKeyLeftFunc && aLength == EShortKeyPress)
       
    97         {
       
    98         MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
    99         if (fepMan->IsAbleToLaunchSCT())
       
   100             {
       
   101             fepMan->LaunchSpecialCharacterTableL();
       
   102             }
       
   103         }
       
   104     else if(iOwner->IsValidChineseInputKeyQwerty(aKey))
       
   105         {
       
   106         if (IsValidPinyinKey(aKey))
       
   107             {
       
   108             CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   109             // it is needed when we use phrase input engine, otherwise it seems not cleared
       
   110             ptiengine->ClearCurrentWord(); 
       
   111             ptiengine->ResetToneMark();
       
   112 
       
   113             iOwner->ChangeState(EEntry);
       
   114             ret = EFalse; //passes to entry state to handle the key
       
   115             }
       
   116         }
       
   117     else 
       
   118         {
       
   119         ret = TAknFepInputStateCandidateQwertyChineseBase::HandleKeyL(aKey, aLength);
       
   120         }
       
   121     return ret;
       
   122     }
       
   123 
       
   124 TBool  TAknFepInputStatePredictiveInputQwertyPinyin::IsValidPinyinKey(TInt aKey)
       
   125     {
       
   126     TBool response = ETrue;
       
   127 
       
   128     if (aKey == EPtiKeyQwertyU || aKey == EPtiKeyQwertyV ||
       
   129         aKey == EPtiKeyQwertyI )
       
   130         {
       
   131         iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   132         response = EFalse;
       
   133         }
       
   134 
       
   135     return response;
       
   136     }
       
   137     
       
   138 TBool  TAknFepInputStatePredictiveInputQwertyPinyin::IsValidEntryKey(TInt aKey)
       
   139     {
       
   140     TBool response = ETrue;
       
   141 
       
   142     if ((aKey >= EPtiKeyQwertyA && aKey <= EPtiKeyQwertyZ) ||
       
   143         (aKey >= EStdKeyLeftArrow && aKey <= EStdKeyDownArrow) ||
       
   144         (aKey >= EPtiKeyQwerty0 && aKey <= EPtiKeyQwerty9) ||
       
   145          aKey == EStdKeyBackspace || aKey == EStdKeyLeftFunc ||
       
   146          aKey == EStdKeyDevice1)
       
   147         {
       
   148         response = EFalse;
       
   149         }
       
   150 
       
   151     return response;
       
   152     }    
       
   153 
       
   154 // End of file