textinput/peninputgenericitut/src/peninputitutchnuistatestrokezhuyincomposition.cpp
changeset 0 eb1f2e154e89
child 10 6defe5d1bd39
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2002-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:  drop-down list control
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <peninputinputcontextfield.h>
       
    20 #include <PtiEngine.h>
       
    21 #include <peninputdropdownlist.h>
       
    22 #include <peninputcmdparam.h>
       
    23 #include <peninputgeneralitutnew.rsg>
       
    24 #include <peninputitutconfig_chinese.rsg>
       
    25 #include <AknFepGlobalEnums.h>
       
    26 
       
    27 #include "peninputitutchnuistatestrokezhuyincomposition.h"
       
    28 #include "peninputgenericitutuimgrbase.h"
       
    29 #include "peninputgenericitutdatamgr.h"
       
    30 #include "peninputgenericitutlayoutcontext.h"
       
    31 #include "peninputgenericitutconverter.h"
       
    32 
       
    33 CChnItutUiStateStrokeZhuyinComposition* CChnItutUiStateStrokeZhuyinComposition::NewL(
       
    34     CGenericItutUiMgrBase* aOwner)
       
    35     {
       
    36     CChnItutUiStateStrokeZhuyinComposition* self = 
       
    37         new (ELeave) CChnItutUiStateStrokeZhuyinComposition(aOwner);
       
    38     CleanupStack::PushL(self);
       
    39     self->ConstructL(); 
       
    40     CleanupStack::Pop(self);
       
    41     return self;
       
    42     }
       
    43 
       
    44 CChnItutUiStateStrokeZhuyinComposition::~CChnItutUiStateStrokeZhuyinComposition()
       
    45     {
       
    46     }
       
    47 
       
    48 CChnItutUiStateStrokeZhuyinComposition::CChnItutUiStateStrokeZhuyinComposition(
       
    49     CGenericItutUiMgrBase* aOwner):CGenericItutUiStateBase(aOwner)
       
    50     {
       
    51     }
       
    52 
       
    53 void CChnItutUiStateStrokeZhuyinComposition::OnEntryL()
       
    54     {
       
    55     TInt immode = iOwner->DataMgr()->InputMode();
       
    56 
       
    57     if (immode == EStroke)
       
    58         {
       
    59         TInt resID;
       
    60         if (iOwner->DataMgr()->InputLanguage() == ELangPrcChinese)
       
    61             {
       
    62             resID = R_FINGER_INPUT_KEYPAD_STROKE_COMPOSITION_PRC;
       
    63             }
       
    64         else
       
    65             {
       
    66             resID = R_FINGER_INPUT_KEYPAD_STROKE_COMPOSITION_TRA;
       
    67             }        
       
    68         iOwner->DataMgr()->NotifyChangeControlLayout(
       
    69             MItutPropertySubscriber::EItutPropertyKeypadResourceId, 
       
    70             resID);
       
    71         }
       
    72     else if (immode == EZhuyin)
       
    73         {
       
    74         iOwner->DataMgr()->NotifyChangeControlLayout(
       
    75             MItutPropertySubscriber::EItutPropertyKeypadResourceId, 
       
    76             R_FINGER_INPUT_KEYPAD_ZHUYIN_COMPOSITION);
       
    77         }
       
    78 
       
    79     // update resource id of keypad, candidate drop list
       
    80     iOwner->DataMgr()->NotifyChangeControlLayout(
       
    81         MItutPropertySubscriber::EItutPropertyCandidateListResourceId,
       
    82         R_AKN_FEP_NORMAL_CAND_DROP_DOWN_LIST);
       
    83 
       
    84     // show spell
       
    85     CFepInputContextField* spellctrl = 
       
    86         static_cast<CFepInputContextField*>(iOwner->LayoutContext()->Control(ECtrlIdSpellICF));
       
    87     TFepInputContextFieldData spelldata;
       
    88     spelldata.iCmd = EPeninputICFInitial;
       
    89     spelldata.iStartPos = 0;
       
    90     spelldata.iLength = 0;
       
    91     spelldata.iText.Set( KNullDesC );
       
    92     spelldata.iCurSel = TCursorSelection(0, 0);
       
    93     spelldata.iCursorVisibility = ETrue;
       
    94     spelldata.iCursorSelVisible = ETrue;
       
    95     spellctrl->SetTextL(spelldata);
       
    96     spellctrl->Hide(EFalse);
       
    97 
       
    98     // show candidate drop list
       
    99     CFepCtrlDropdownList* candlist = 
       
   100         static_cast<CFepCtrlDropdownList*>(iOwner->LayoutContext()->Control(ECtrlIdStdCandsList));
       
   101     candlist->Hide(EFalse);
       
   102     
       
   103     //hide navi button
       
   104     iOwner->LayoutContext()->ShowArrowBtn(0);
       
   105     
       
   106     //hide indicator 
       
   107     iOwner->LayoutContext()->Control(ECtrlIdIndicator)->Hide(ETrue);
       
   108     }
       
   109 
       
   110 void CChnItutUiStateStrokeZhuyinComposition::OnExit()
       
   111     {
       
   112     // hide dropdownlist & reset its status
       
   113     CFepCtrlDropdownList* candlist = 
       
   114         static_cast<CFepCtrlDropdownList*>(iOwner->LayoutContext()->Control(ECtrlIdStdCandsList));
       
   115     candlist->ResetAndClear(CFepCtrlDropdownList::EListExpandable);
       
   116     iOwner->DataMgr()->ClearChnCandidates(EItutCandidates);
       
   117     candlist->Hide(ETrue);
       
   118 
       
   119     CFepInputContextField* spellctrl = 
       
   120         static_cast<CFepInputContextField*>(iOwner->LayoutContext()->Control(ECtrlIdSpellICF));
       
   121 
       
   122     spellctrl->Hide(ETrue);
       
   123 
       
   124     //show navi button
       
   125     iOwner->LayoutContext()->ShowArrowBtn(EBtnArrowLeft | EBtnArrowRight
       
   126              | EBtnArrowUp| EBtnArrowDown);
       
   127     
       
   128     //show indicator 
       
   129     iOwner->LayoutContext()->Control(ECtrlIdIndicator)->Hide(EFalse);
       
   130 
       
   131     iOwner->DataMgr()->PtiEngine()->ClearCurrentWord();
       
   132     }
       
   133 
       
   134 TBool CChnItutUiStateStrokeZhuyinComposition::HandleKeyL(TInt /*aCmd*/, TInt aKey)
       
   135     {
       
   136     TInt immode = iOwner->DataMgr()->InputMode();
       
   137     
       
   138     if (immode != EStroke && immode != EZhuyin)
       
   139         {
       
   140         return EFalse;
       
   141         }
       
   142 
       
   143     if (!(aKey == EKeyBackspace || 
       
   144          (aKey >= EPtiKey0 && aKey <= EPtiKey9) ||
       
   145          (aKey == EPtiKeyStar)))
       
   146         {
       
   147         return EFalse;
       
   148         }
       
   149     
       
   150     if (aKey == EKeyBackspace)
       
   151         {
       
   152         if (!iOwner->DataMgr()->PtiEngine()->DeleteKeyPress().Length())
       
   153             {
       
   154             iOwner->SetCurrentStateL(CGenericItutUiMgrBase::EStateStandby);
       
   155             
       
   156             iOwner->SetClrConsume(ETrue);
       
   157             
       
   158             return ETrue;
       
   159             }
       
   160         } 
       
   161     else if (aKey == EPtiKeyStar)
       
   162         {
       
   163         if (immode == EStroke)
       
   164             {
       
   165             //iOwner->DataMgr()->PtiEngine()->ClearCurrentWord();
       
   166             //iOwner->SetCurrentStateL(CGenericItutUiMgrBase::EStateStandby);
       
   167             
       
   168             return ETrue;
       
   169             }
       
   170         else
       
   171             {
       
   172             // input mode is zhuyin
       
   173             // input tonemark
       
   174             if (!iOwner->DataMgr()->PtiEngine()->IncrementToneMark(ETrue))
       
   175                 {
       
   176                 // tonemark did not set correctly, everything unchanged
       
   177                 return ETrue;
       
   178                 }
       
   179             }
       
   180         }
       
   181     else
       
   182         {
       
   183         if (immode == EZhuyin ||
       
   184            (immode == EStroke && aKey >= EPtiKey0 && aKey <= EPtiKey6))
       
   185             {
       
   186             // append keypress
       
   187             iOwner->DataMgr()->PtiEngine()->AppendKeyPress(TPtiKey(aKey));
       
   188             } 
       
   189         else if (immode == EStroke && aKey >= EPtiKey7 && aKey <= EPtiKey9)
       
   190             {
       
   191             // just ignore	
       
   192             return ETrue;
       
   193             }
       
   194         }
       
   195 
       
   196     // display 1st spell, ptiengine's phonetic spelling start index is 1, not 0
       
   197     iOwner->DataMgr()->PtiEngine()->SelectPhoneticSpelling(1);
       
   198 
       
   199     CFepInputContextField* spellctrl = 
       
   200         static_cast<CFepInputContextField*>(iOwner->LayoutContext()->Control(ECtrlIdSpellICF));
       
   201     TPtrC spelltext = iOwner->DataMgr()->PtiEngine()->GetPhoneticSpelling(1);
       
   202 
       
   203     TFepInputContextFieldData spelldata;
       
   204 
       
   205     spelldata.iCmd = EPeninputICFInitial;
       
   206     spelldata.iStartPos = 0;
       
   207     spelldata.iLength = spelltext.Length();
       
   208     spelldata.iMidPos = -1;
       
   209     spelldata.iText.Set(spelltext);
       
   210 
       
   211     spelldata.iCurSel = TCursorSelection(spelltext.Length(), spelltext.Length());
       
   212     spelldata.iCursorVisibility = EFalse;
       
   213     spelldata.iCursorSelVisible = EFalse;
       
   214 
       
   215     spellctrl->SetTextL(spelldata);
       
   216 
       
   217     // get candidates of 1st spell 
       
   218     TPtrC cands = iOwner->DataMgr()->PtiEngine()->CandidatePage();
       
   219 
       
   220     iOwner->DataMgr()->ClearChnCandidates(EItutCandidates);
       
   221     RPointerArray<HBufC>& candslist = 
       
   222         TItutDataConverter::AnyToRptrArray(iOwner->DataMgr()->RequestData(EChnCandidates));
       
   223     TItutDataConverter::ConvertChnPhraseCandidateL(cands, candslist);
       
   224 
       
   225     CFepCtrlDropdownList* canddroplist = 
       
   226         static_cast<CFepCtrlDropdownList*>(iOwner->LayoutContext()->Control(ECtrlIdStdCandsList));
       
   227     canddroplist->SetCandidatesL(candslist, CFepCtrlDropdownList::EListExpandableWithBubble);
       
   228 
       
   229     return ETrue;
       
   230     }
       
   231 
       
   232 CGenericItutUiMgrBase::TUiState CChnItutUiStateStrokeZhuyinComposition::StateType()
       
   233     {
       
   234     return CGenericItutUiMgrBase::EStateComposition;
       
   235     }
       
   236     
       
   237 TBool CChnItutUiStateStrokeZhuyinComposition::HandleCtrlEventL(TInt aEventType, 
       
   238                                                                CFepUiBaseCtrl* aCtrl, 
       
   239                                                                const TDesC& aEventData)
       
   240     {
       
   241     switch (aEventType)
       
   242         {
       
   243         case EItutCmdCandidateSelected:
       
   244             {
       
   245             if (aCtrl->ControlId() == ECtrlIdStdCandsList)
       
   246                 {
       
   247                 iOwner->SetCurrentStateL(CGenericItutUiMgrBase::EStatePredict);
       
   248                 return iOwner->CurrentState()->HandleCtrlEventL(aEventType,
       
   249                                                                 aCtrl,
       
   250                                                                 aEventData);
       
   251                 }
       
   252             }
       
   253             break;
       
   254         case EItutCmdGetNextCandidatePage:
       
   255             {
       
   256             if (aCtrl->ControlId() == ECtrlIdStdCandsList)
       
   257                 {
       
   258                 RPointerArray<HBufC>& candslist = TItutDataConverter::AnyToRptrArray(
       
   259                     iOwner->DataMgr()->RequestData(EChnCandidates));
       
   260 
       
   261                 // original candidate count before fetch new candidate
       
   262                 TInt candscnt = candslist.Count();
       
   263                 if (iOwner->DataMgr()->GetNextPageCandidateL(candslist) == KErrNone)
       
   264                     {
       
   265                     static_cast<CFepCtrlDropdownList*>(aCtrl)->AddCandidatesL(candslist);    
       
   266                     }
       
   267 
       
   268                 return ETrue;
       
   269                 }
       
   270             }
       
   271             break;
       
   272         case EItutCmdCandidateExisted:
       
   273             {
       
   274             if (aCtrl->ControlId() == ECtrlIdStdCandsList)
       
   275                 {
       
   276                 static_cast<CFepCtrlDropdownList*>(aCtrl)->SetFlagCandidateExist(
       
   277                     iOwner->DataMgr()->NextPageCandidateExist());
       
   278                 return ETrue;
       
   279                 }
       
   280             }
       
   281             break;
       
   282         // consume star key at zhuyin composition state
       
   283         case EEventRawKeyDownEvent:
       
   284             {
       
   285             const TKeyEvent *key = reinterpret_cast<const TKeyEvent*>(aEventData.Ptr());
       
   286             
       
   287             if (key->iScanCode == EStdKeyNkpAsterisk && iOwner->DataMgr()->InputMode() == EZhuyin)
       
   288                 {
       
   289                 HandleKeyL(ECmdPenInputFingerKeyPress, EPtiKeyStar);
       
   290                 return ETrue;
       
   291                 }
       
   292             }
       
   293             break;
       
   294         case EEventRawKeyUpEvent:
       
   295             {
       
   296             const TKeyEvent *key = reinterpret_cast<const TKeyEvent*>(aEventData.Ptr());
       
   297             
       
   298             if (key->iScanCode == EStdKeyNkpAsterisk && iOwner->DataMgr()->InputMode() == EZhuyin)
       
   299                 {
       
   300                 return ETrue;
       
   301                 }
       
   302             }
       
   303             break;
       
   304         default:
       
   305             break;
       
   306         }
       
   307 
       
   308     return EFalse;    
       
   309     }
       
   310 
       
   311 // End Of File