textinput/peninputsplititut/src/peninputsplititutchnuistatepinyincomposition.cpp
changeset 0 eb1f2e154e89
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 <peninputdropdownlist.h>
       
    20 #include <PtiEngine.h>
       
    21 #include <peninputsplititutnew.rsg>
       
    22 #include <peninputsplititutconfig_chinese.rsg>
       
    23 
       
    24 #include "peninputsplititutchnuistatepinyincomposition.h"
       
    25 #include "peninputsplititutuimgrbase.h"
       
    26 #include "peninputsplititutdatamgr.h"
       
    27 #include "peninputsplititutlayoutcontext.h"
       
    28 #include "peninputsplititutconverter.h"
       
    29 
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS =============================
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CChnSplitItutUiStatePinyinComposition::NewL
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CChnSplitItutUiStatePinyinComposition* CChnSplitItutUiStatePinyinComposition::NewL(
       
    38     CSplitItutUiMgrBase* aOwner)
       
    39     {
       
    40     CChnSplitItutUiStatePinyinComposition* self = 
       
    41         new (ELeave) CChnSplitItutUiStatePinyinComposition(aOwner);
       
    42     CleanupStack::PushL(self);
       
    43     self->ConstructL(); 
       
    44     CleanupStack::Pop(self);
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CChnSplitItutUiStatePinyinComposition::~CChnSplitItutUiStatePinyinComposition
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CChnSplitItutUiStatePinyinComposition::~CChnSplitItutUiStatePinyinComposition()
       
    53     {
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CChnSplitItutUiStatePinyinComposition::CChnSplitItutUiStatePinyinComposition
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CChnSplitItutUiStatePinyinComposition::CChnSplitItutUiStatePinyinComposition(
       
    61     CSplitItutUiMgrBase* aOwner):CSplitItutUiStateBase(aOwner)
       
    62     {
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CChnSplitItutUiStatePinyinComposition::OnEntryL
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CChnSplitItutUiStatePinyinComposition::OnEntryL()
       
    70     {
       
    71     // update resource id of keypad, candidate drop list
       
    72     iOwner->DataMgr()->NotifyChangeControlLayout(
       
    73         MItutPropertySubscriber::EItutPropertyKeypadResourceId, 
       
    74         R_FINGER_INPUT_KEYPAD_PINYIN_COMPOSITION);
       
    75     iOwner->DataMgr()->NotifyChangeControlLayout(
       
    76         MItutPropertySubscriber::EItutPropertyCandidateListResourceId,
       
    77         R_AKN_FEP_PINYIN_CAND_DROP_DOWN_LIST);
       
    78 
       
    79     // show spell drop list
       
    80     CFepCtrlDropdownList* spelllist = static_cast<CFepCtrlDropdownList*>(
       
    81         iOwner->LayoutContext()->Control(ECtrlIdSpellCandsList));
       
    82     spelllist->Hide(EFalse);
       
    83 
       
    84     // show candidate drop list
       
    85     CFepCtrlDropdownList* candlist = static_cast<CFepCtrlDropdownList*>(
       
    86         iOwner->LayoutContext()->Control(ECtrlIdStdCandsList));
       
    87     candlist->Hide(EFalse);
       
    88     
       
    89     //hide navi button
       
    90     iOwner->LayoutContext()->ShowArrowBtn(0);  
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CChnSplitItutUiStatePinyinComposition::OnExit
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void CChnSplitItutUiStatePinyinComposition::OnExit()
       
    98     {
       
    99     /*
       
   100     // hide dropdownlist & reset its status
       
   101     CFepCtrlDropdownList* spelllist = static_cast<CFepCtrlDropdownList*>(
       
   102         iOwner->LayoutContext()->Control(ECtrlIdSpellCandsList));
       
   103     spelllist->ResetAndClear(CFepCtrlDropdownList::EListExpandableRollWithIcon);
       
   104     iSpellCands.ResetAndDestroy();
       
   105     iSpellCands.Close();
       
   106     spelllist->Hide(ETrue);
       
   107 
       
   108     CFepCtrlDropdownList* candlist = static_cast<CFepCtrlDropdownList*>(
       
   109         iOwner->LayoutContext()->Control(ECtrlIdStdCandsList));
       
   110     candlist->ResetAndClear(CFepCtrlDropdownList::EListExpandable);
       
   111     iOwner->DataMgr()->ClearChnCandidates(EItutCandidates);
       
   112     candlist->Hide(ETrue);
       
   113 
       
   114     iOwner->DataMgr()->PtiEngine()->ClearCurrentWord();
       
   115     
       
   116     //show navi button
       
   117     iOwner->LayoutContext()->ShowArrowBtn(EBtnArrowLeft | EBtnArrowRight
       
   118              | EBtnArrowUp| EBtnArrowDown);
       
   119     
       
   120     //show indicator 
       
   121     iOwner->LayoutContext()->Control(ECtrlIdIndicator)->Hide(EFalse);
       
   122 
       
   123     iOwner->DataMgr()->PtiEngine()->ClearCurrentWord();
       
   124     */
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CChnSplitItutUiStatePinyinComposition::HandleKeyL
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 TBool CChnSplitItutUiStatePinyinComposition::HandleKeyL(TInt /*aCmd*/, TInt /*aKey*/)
       
   132     {
       
   133     /*
       
   134     if (!(aKey == EKeyBackspace || 
       
   135         (aKey >= EPtiKey0 && aKey <= EPtiKey9) || 
       
   136         (aKey == EPtiKeyStar)))
       
   137         {
       
   138         return EFalse;
       
   139         }
       
   140 
       
   141     if (aKey >= EPtiKey0 && aKey <= EPtiKey9)
       
   142         {
       
   143         // append keypress 
       
   144         iOwner->DataMgr()->PtiEngine()->AppendKeyPress(TPtiKey(aKey));
       
   145         }
       
   146     else if (aKey == EKeyBackspace)
       
   147         {
       
   148         if (!iOwner->DataMgr()->PtiEngine()->DeleteKeyPress().Length())
       
   149             {
       
   150             iOwner->SetCurrentStateL(CSplitItutUiMgrBase::EStateStandby);
       
   151             
       
   152             iOwner->SetClrConsume(ETrue);
       
   153 
       
   154             return ETrue;
       
   155             }
       
   156         }
       
   157     else{
       
   158          // input tonemark
       
   159         if (!iOwner->DataMgr()->PtiEngine()->IncrementToneMark(ETrue))
       
   160             {
       
   161             // tonemark did not set correctly, everything unchanged
       
   162             return ETrue;
       
   163             }
       
   164         }
       
   165 
       
   166     // get all spelling
       
   167     TInt spellcnt = iOwner->DataMgr()->PtiEngine()->PhoneticSpellingCount();
       
   168 
       
   169     iSpellCands.ResetAndDestroy();
       
   170     iSpellCands.Close();
       
   171 
       
   172     // note: ptiengine's phonetic spelling start index is 1, not 0
       
   173     for (TInt i = 1; i < (spellcnt + 1); i++)
       
   174         {
       
   175         HBufC* spellbuf = (iOwner->DataMgr()->PtiEngine()->GetPhoneticSpelling(i)).AllocL();
       
   176 
       
   177         CleanupStack::PushL(spellbuf);
       
   178         iSpellCands.Append(spellbuf);
       
   179         CleanupStack::Pop(spellbuf);
       
   180         }
       
   181 
       
   182     TInt nearestIdx = 0;
       
   183 
       
   184     
       
   185     if (iLastSelSpell)
       
   186         {
       
   187         nearestIdx = GetNearestSpell(iLastSelSpell->Length());
       
   188 
       
   189         delete iLastSelSpell;
       
   190         iLastSelSpell = NULL;
       
   191         }
       
   192 
       
   193     iLastSelSpell = (iOwner->DataMgr()->PtiEngine()->GetPhoneticSpelling(nearestIdx + 1)).AllocL();
       
   194     
       
   195 
       
   196     // set spell, set highlight of spelling candidate list
       
   197     CFepCtrlDropdownList* spelldroplist = static_cast<CFepCtrlDropdownList*>(
       
   198         iOwner->LayoutContext()->Control(ECtrlIdSpellCandsList));
       
   199     spelldroplist->SetCandidatesL(iSpellCands, CFepCtrlDropdownList::EListExpandableRollWithIconWithBubble);
       
   200     spelldroplist->SetHighlightCell(nearestIdx);
       
   201 
       
   202     // get candidates of nearest spell
       
   203     iOwner->DataMgr()->PtiEngine()->SelectPhoneticSpelling(nearestIdx + 1);
       
   204     TPtrC cands = iOwner->DataMgr()->PtiEngine()->CandidatePage();
       
   205 
       
   206     iOwner->DataMgr()->ClearChnCandidates(EItutCandidates);
       
   207     RPointerArray<HBufC>& candslist = 
       
   208         TItutDataConverter::AnyToRptrArray(iOwner->DataMgr()->RequestData(EChnCandidates));
       
   209     TItutDataConverter::ConvertChnPhraseCandidateL(cands, candslist);
       
   210 
       
   211     // set candidate
       
   212     CFepCtrlDropdownList* canddroplist = 
       
   213         static_cast<CFepCtrlDropdownList*>(iOwner->LayoutContext()->Control(ECtrlIdStdCandsList));
       
   214     canddroplist->SetCandidatesL(candslist, CFepCtrlDropdownList::EListExpandableWithBubble);
       
   215     */
       
   216     return ETrue;
       
   217     }
       
   218 
       
   219 /*
       
   220 TInt CChnItutUiStatePinyinComposition::GetNearestSpell(TInt aValidLastSpellLen)
       
   221     {
       
   222     if (aValidLastSpellLen <= 0)
       
   223         {
       
   224         return 0;
       
   225         }
       
   226     
       
   227     for (TInt i = 0; i < iSpellCands.Count(); i++)
       
   228         {
       
   229         if ((iSpellCands[i]->Left(aValidLastSpellLen)).Compare(iLastSelSpell->Left(aValidLastSpellLen)) == 0)
       
   230             {
       
   231             return i;
       
   232             }
       
   233         }
       
   234     
       
   235     return GetNearestSpell(aValidLastSpellLen-1);
       
   236     }
       
   237 */    
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CChnSplitItutUiStatePinyinComposition::HandleCtrlEventL
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 TBool CChnSplitItutUiStatePinyinComposition::HandleCtrlEventL(
       
   244     TInt /*aEventType*/, CFepUiBaseCtrl* /*aCtrl*/, const TDesC& /*aEventData*/)
       
   245     {
       
   246     /*
       
   247     switch (aEventType)
       
   248         {
       
   249         case EItutCmdCandidateSelected:
       
   250             {
       
   251             // press cell on spelling list
       
   252             if (aCtrl->ControlId() == ECtrlIdSpellCandsList &&
       
   253                 aEventData.Length() > 0)
       
   254                 {
       
   255                 TInt selCandIdx = aEventData[aEventData.Length() - 1];
       
   256 
       
   257                 // note for ptiengine, spelling index start from 1, not 0
       
   258                 iOwner->DataMgr()->PtiEngine()->SelectPhoneticSpelling(selCandIdx + 1);
       
   259                 
       
   260                 CFepCtrlDropdownList* spelldroplist = static_cast<CFepCtrlDropdownList*>(aCtrl);
       
   261                 spelldroplist->SetHighlightCell(selCandIdx);
       
   262 
       
   263                                  
       
   264                 delete iLastSelSpell;
       
   265                 iLastSelSpell = NULL;
       
   266                 iLastSelSpell = (iOwner->DataMgr()->PtiEngine()->GetPhoneticSpelling(selCandIdx + 1)).AllocL();
       
   267                 
       
   268 
       
   269                 TPtrC cands = iOwner->DataMgr()->PtiEngine()->CandidatePage();
       
   270 
       
   271                 iOwner->DataMgr()->ClearChnCandidates(EItutCandidates);
       
   272                 RPointerArray<HBufC>& candslist = TItutDataConverter::AnyToRptrArray(
       
   273                     iOwner->DataMgr()->RequestData(EChnCandidates));
       
   274                 TItutDataConverter::ConvertChnPhraseCandidateL(cands, candslist);
       
   275 
       
   276                 CFepCtrlDropdownList* canddroplist = static_cast<CFepCtrlDropdownList*>(
       
   277                     iOwner->LayoutContext()->Control(ECtrlIdStdCandsList));
       
   278                 canddroplist->SetCandidatesL(candslist, CFepCtrlDropdownList::EListExpandableWithBubble);
       
   279 
       
   280                 return ETrue;
       
   281                 }
       
   282             else if (aCtrl->ControlId() == ECtrlIdStdCandsList)
       
   283                 {
       
   284                 iOwner->SetCurrentStateL(CSplitItutUiMgrBase::EStatePredict);
       
   285                 return iOwner->CurrentState()->HandleCtrlEventL(aEventType, aCtrl, aEventData);
       
   286                 }
       
   287             }
       
   288             break;
       
   289         case EItutCmdGetNextCandidatePage:
       
   290             {
       
   291             if (aCtrl->ControlId() == ECtrlIdStdCandsList)
       
   292                 {
       
   293                 RPointerArray<HBufC>& candslist = TItutDataConverter::AnyToRptrArray(
       
   294                     iOwner->DataMgr()->RequestData(EChnCandidates));
       
   295 
       
   296                 // original candidate count before fetch new candidate
       
   297                 TInt candscnt = candslist.Count();
       
   298                 if (iOwner->DataMgr()->GetNextPageCandidateL(candslist) == KErrNone)
       
   299                     {
       
   300                     static_cast<CFepCtrlDropdownList*>(aCtrl)->AddCandidatesL(candslist);    
       
   301                     }
       
   302 
       
   303                 return ETrue;
       
   304                 }
       
   305             }
       
   306             break;
       
   307         case EItutCmdCandidateExisted:
       
   308             {
       
   309             if (aCtrl->ControlId() == ECtrlIdStdCandsList)
       
   310                 {
       
   311                 static_cast<CFepCtrlDropdownList*>(
       
   312                     aCtrl)->SetFlagCandidateExist(iOwner->DataMgr()->NextPageCandidateExist());
       
   313                 return ETrue;
       
   314                 }
       
   315             }
       
   316             break;
       
   317         // consume star key at pinyin composition state
       
   318         case EEventRawKeyDownEvent:
       
   319             {
       
   320             const TKeyEvent *key = reinterpret_cast<const TKeyEvent*>(aEventData.Ptr());
       
   321             
       
   322             if (key->iScanCode == EStdKeyNkpAsterisk)
       
   323                 {
       
   324                 HandleKeyL(ECmdPenInputFingerKeyPress, EPtiKeyStar);
       
   325                 return ETrue;
       
   326                 }
       
   327             }
       
   328             break;
       
   329         case EEventRawKeyUpEvent:
       
   330             {
       
   331             const TKeyEvent *key = reinterpret_cast<const TKeyEvent*>(aEventData.Ptr());
       
   332             
       
   333             if (key->iScanCode == EStdKeyNkpAsterisk)
       
   334                 {
       
   335                 return ETrue;
       
   336                 }
       
   337             }
       
   338             break;
       
   339         default:
       
   340             break;
       
   341         }
       
   342     */
       
   343     return EFalse;
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // CChnSplitItutUiStatePinyinComposition::StateType
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 CSplitItutUiMgrBase::TUiState CChnSplitItutUiStatePinyinComposition::StateType()
       
   351     {
       
   352     return CSplitItutUiMgrBase::EStateComposition;
       
   353     }
       
   354 
       
   355 // End Of File