textinput/peninputcommonctrlsjp/src/peninputhiraganakanji.cpp
branchRCL_3
changeset 21 ecbabf52600f
equal deleted inserted replaced
20:ebd48d2de13c 21:ecbabf52600f
       
     1 /*
       
     2 * Copyright (c) 2009 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:  peninputkanakanji implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <PtiEngine.h>
       
    20 #include <peninputlayout.h>
       
    21 #include <PtiCompositionDataIF.h>
       
    22 #include <aknlayoutscalable_avkon.cdl.h>
       
    23 #include <peninputcommonlayoutglobalenum.h>  // EPeninputLayoutEventEnter
       
    24 #include <aknfeppeninputenums.h>    //command from fep or IME to plugin. for vkb/hwr
       
    25 
       
    26 #include "peninputeventjp.h"
       
    27 #include "peninputhiraganakanji.h"
       
    28 #include "peninputcontextfieldjp.h"
       
    29 #include "peninputjapanesecandidatewnd.h"
       
    30 #include "peninputjapanesepredictivewnd.h"
       
    31 
       
    32 // CONSTANTS
       
    33 const TUint16 KLittleCharCode = 0x5c0f; // little
       
    34 
       
    35 //default value for long press timer
       
    36 const TInt KLongPressInterval = 600000;
       
    37 //default value for repeat timer
       
    38 const TInt KRepeatInterval = 100000;
       
    39 
       
    40 // ---------------------------------------------------------
       
    41 // Constructor
       
    42 // ---------------------------------------------------------
       
    43 EXPORT_C CPeninputHiraganaKanji* CPeninputHiraganaKanji::NewL(CPtiEngine* aPtiEngine
       
    44                                                              , CFepUiLayout* aUiLayout
       
    45                                                              , CFepInputContextFieldJp* aInputContextField
       
    46                                                              , CPeninputJapaneseCandidateWnd* aCandidateWnd
       
    47                                                              , CPeninputJapanesePredictiveWnd* aPredictiveWnd)
       
    48     {
       
    49     if (aPtiEngine == NULL
       
    50          || aUiLayout == NULL
       
    51          || aInputContextField == NULL
       
    52          || aCandidateWnd == NULL
       
    53          || aPredictiveWnd == NULL
       
    54          )
       
    55         {
       
    56         User::Leave(KErrArgument);
       
    57         }
       
    58 
       
    59     CPeninputHiraganaKanji* self = new (ELeave) CPeninputHiraganaKanji(aPtiEngine
       
    60                                                                                , aUiLayout
       
    61                                                                                , aInputContextField
       
    62                                                                                , aCandidateWnd
       
    63                                                                                , aPredictiveWnd);
       
    64 
       
    65     CleanupStack::PushL(self);
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop(self);
       
    68 
       
    69     return self;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // Destructor
       
    74 // ---------------------------------------------------------
       
    75 EXPORT_C CPeninputHiraganaKanji::~CPeninputHiraganaKanji()
       
    76     {
       
    77     delete iCandidateArray;
       
    78     delete iChar;
       
    79     CancelRepeat();
       
    80     delete iLongPressTimer;
       
    81     delete iRepeatTimer;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // Handle events in
       
    86 // ---------------------------------------------------------
       
    87 EXPORT_C void CPeninputHiraganaKanji::HandleControlEventJpL(TInt aEventType, const TDesC& aEventData)
       
    88     {
       
    89     if(EStatusComplete == iStatus || EStatusCompleteAll == iStatus
       
    90           || EStatusCompleteAllfromUiLayout == iStatus) // wait for SetEditorTextL from Editor
       
    91         {
       
    92         return ;
       
    93         }
       
    94     switch (aEventType)
       
    95         {
       
    96         case EEventVirtualKeyUp:
       
    97             if (!aEventData.Length())
       
    98                 {
       
    99                 UpdateContextFieldL();
       
   100                 }
       
   101             else
       
   102                 {
       
   103                 TUint16* unicode = (TUint16*) aEventData.Ptr();
       
   104                 if (EStatusInitial == iStatus)
       
   105                     {
       
   106                     if (KLittleCharCode != *unicode)
       
   107                         {
       
   108                         iInputContextField->StartInlineL();
       
   109                         iStatus = (!iPredictiveWnd->Hiden())? EStatusPredictiveTransitoryInput : EStatusTransitoryInput;
       
   110                         }
       
   111                     }
       
   112                 else if (EStatusPredictiveTransitoryInputWithNoChar == iStatus)
       
   113                     {
       
   114                     if (KLittleCharCode != *unicode)
       
   115                         {
       
   116                         iInputContextField->StartInlineL();
       
   117                         iStatus = EStatusPredictiveTransitoryInput;
       
   118                         }
       
   119                     }
       
   120                 if (EStatusPredictiveTransitoryInput == iStatus || EStatusTransitoryInput == iStatus)
       
   121                     {
       
   122                     // different from editor
       
   123                     iStatus = (!iPredictiveWnd->Hiden())? EStatusPredictiveTransitoryInput : EStatusTransitoryInput;
       
   124                     HandleInsertL(aEventData);
       
   125                     }
       
   126                 else if (EStatusConversion == iStatus
       
   127                        || EStatusCandidate == iStatus  // not take place
       
   128                        || EStatusChangeDivision == iStatus)
       
   129                     {
       
   130                     delete iChar;
       
   131                     iChar = NULL;
       
   132                     iChar = aEventData.AllocL();
       
   133                     CompleteAllL();
       
   134                     }
       
   135                 }
       
   136             break;
       
   137         case EEventCompleteAllHiraganaKanji:    // CompleteALL:from UiLayout
       
   138             if (EStatusInitial != iStatus)
       
   139                 {
       
   140                 if (EStatusPredictiveTransitoryInputWithNoChar == iStatus)
       
   141                     {
       
   142                     iStatus = EStatusInitial;
       
   143                     UpdateContextFieldL();  // not leave
       
   144                     }
       
   145                 else
       
   146                     {
       
   147                     iStatus = EStatusCompleteAllfromUiLayout;
       
   148                     CompleteAllL();
       
   149                     }
       
   150                 }
       
   151             break;
       
   152         case EEventCompleteIfConvertingHiraganaKanji:    // Complete:from Hwr UiLayout
       
   153             if (EStatusConversion == iStatus
       
   154                || EStatusCandidate == iStatus  // not take place
       
   155                || EStatusChangeDivision == iStatus)
       
   156                 {
       
   157                 iStatus = EStatusCompleteAllfromUiLayout;
       
   158                 CompleteAllL();
       
   159                 }
       
   160             break;
       
   161         case EPeninputLayoutEventSelectItem:  // select from prediction/convert candidates by pointer
       
   162         case EPeninputLayoutEventEnter:
       
   163             if (EStatusPredictiveTransitoryInput == iStatus || EStatusPredictiveTransitoryInputWithNoChar == iStatus)
       
   164                 {
       
   165                 TInt curr = iPredictiveWnd->CurrentItemIndexOfCandidate();
       
   166                 if (curr >= 0)
       
   167                     {
       
   168                     iPtiEngine->HandleCommandL(EPtiCommandUserActionCompleteCandidate, &curr);
       
   169                     CompleteSubL();  // not leave
       
   170                     }
       
   171                 break;
       
   172                 }
       
   173             if (EStatusCandidate == iStatus)
       
   174                 {
       
   175                 TInt curr = iCandidateWnd->CurrentItemIndex();
       
   176                 TInt old = 0;
       
   177                 iPtiEngine->HandleCommandL(EPtiCommandUserActionGetCurrentIndexOfCandidates, &old);
       
   178                 while(curr > old)
       
   179                     {
       
   180                     ++old;
       
   181                     iPtiEngine->HandleCommandL(EPtiCommandUserActionConvert);
       
   182                     }
       
   183                 while(curr < old)
       
   184                     {
       
   185                     --old;
       
   186                     iPtiEngine->HandleCommandL(EPtiCommandUserActionPrevious);
       
   187                     }
       
   188                 }
       
   189             if (EStatusInitial != iStatus)
       
   190                 {
       
   191                 CompleteL();
       
   192                 }
       
   193             break;
       
   194         case EPeninputLayoutEventBack:
       
   195             {
       
   196             switch(iStatus)
       
   197                 {
       
   198                 case EStatusPredictiveTransitoryInputWithNoChar:
       
   199                     {
       
   200                     iStatus = EStatusInitial;
       
   201                     UpdateContextFieldL();  // not leave
       
   202                     }
       
   203                     break;
       
   204                 case EStatusTransitoryInput:
       
   205                 case EStatusPredictiveTransitoryInput:
       
   206                     {
       
   207                     // different from editor
       
   208                     iStatus = (!iPredictiveWnd->Hiden())? EStatusPredictiveTransitoryInput : EStatusTransitoryInput;
       
   209                     HandleBackL();
       
   210                     }
       
   211                     break;
       
   212                 case EStatusCandidate:
       
   213                     {
       
   214                     iStatus = EStatusConversion;
       
   215                     UpdateContextFieldL();
       
   216                     }
       
   217                     break;
       
   218                 case EStatusConversion:
       
   219                 case EStatusChangeDivision:
       
   220                     {
       
   221                     iPtiEngine->HandleCommandL(EPtiCommandUserActionCancel);
       
   222                     iStatus = EStatusTransitoryInput;
       
   223                     UpdateContextFieldL();
       
   224                     }
       
   225                     break;
       
   226                 default:
       
   227                     break;
       
   228                 }
       
   229             }
       
   230             break;
       
   231         case EEventStdKeyUpArrow:
       
   232         case EEventStdKeyDownArrow:
       
   233         case EPeninputLayoutEventSpace:
       
   234             if (EStatusInitial != iStatus)
       
   235                 {
       
   236                 if ((EStatusPredictiveTransitoryInput == iStatus || EStatusPredictiveTransitoryInputWithNoChar == iStatus)
       
   237                           && EPeninputLayoutEventSpace != aEventType)
       
   238                     {
       
   239                     iPredictiveWnd->MoveTo((EEventStdKeyUpArrow != aEventType)?
       
   240                                         CPeninputJapanesePredictiveWnd::EScrollDown : CPeninputJapanesePredictiveWnd::EScrollUp);
       
   241                     }
       
   242                 else if (EStatusPredictiveTransitoryInputWithNoChar == iStatus && EPeninputLayoutEventSpace == aEventType)
       
   243                     {  // only by space button on vkb peninput
       
   244                     iStatus = EStatusInitial;
       
   245                     UpdateContextFieldL();
       
   246                     iUiLayout->SignalOwner(ESignalKeyEvent,aEventData);
       
   247                     }
       
   248                 else
       
   249                     {
       
   250                     iPtiEngine->HandleCommandL(
       
   251                                  (EEventStdKeyUpArrow != aEventType)? EPtiCommandUserActionConvert : EPtiCommandUserActionPrevious);
       
   252                     if (EStatusCandidate == iStatus)   // not take place
       
   253                         {
       
   254                         iCandidateWnd->MoveToL((EEventStdKeyUpArrow != aEventType)?
       
   255                                                 CPeninputJapaneseCandidateWnd::EScrollDown : CPeninputJapaneseCandidateWnd::EScrollUp);
       
   256                         }
       
   257                     else
       
   258                         {
       
   259                         iStatus = (EStatusConversion == iStatus)? EStatusCandidate : EStatusConversion;
       
   260                         }
       
   261                     UpdateContextFieldL();
       
   262                     }
       
   263                 }
       
   264             break;
       
   265         case EPeninputLayoutEventTab:
       
   266             if (EStatusPredictiveTransitoryInputWithNoChar == iStatus)
       
   267                 {
       
   268                 iStatus = EStatusCompleteAll;   // wait for SetEditorTextL()
       
   269                 iUiLayout->SignalOwner(ESignalKeyEvent,aEventData);
       
   270                 }
       
   271             break;
       
   272         case EEventCancelHiraganaKanji:    // Cancel:from UiLayout   not used
       
   273             ClearTextL();
       
   274             break;
       
   275         case EEventStdKeyLeftArrow:
       
   276         case EEventStdKeyRightArrow:
       
   277             if (EStatusTransitoryInput == iStatus)
       
   278                 {
       
   279                 TInt pos = -1;
       
   280                 iPtiEngine->HandleCommandL(
       
   281                              (EEventStdKeyLeftArrow == aEventType)? EPtiCommandUserActionLeft : EPtiCommandUserActionRight);
       
   282                 const MPtiEngineCompositionDataInterface* data = iPtiEngine->CompositionData();
       
   283                 if (data)
       
   284                     {
       
   285                     pos = data->CursorPosition();
       
   286                     }
       
   287                 if(0 <= pos)
       
   288                     {
       
   289                     iInputContextField->SetCursorPosition(pos);
       
   290                     }
       
   291                 }
       
   292             else if (EStatusPredictiveTransitoryInput == iStatus || EStatusPredictiveTransitoryInputWithNoChar == iStatus)
       
   293                 {
       
   294                 iPredictiveWnd->MoveTo((EEventStdKeyLeftArrow != aEventType)?
       
   295                                             CPeninputJapanesePredictiveWnd::EScrollRight : CPeninputJapanesePredictiveWnd::EScrollLeft);
       
   296                 }
       
   297             else if (EStatusConversion == iStatus || EStatusCandidate == iStatus)
       
   298                 {
       
   299                 iStatus = EStatusChangeDivision;
       
   300                 }
       
   301             if (EStatusChangeDivision == iStatus)
       
   302                 {
       
   303                 iPtiEngine->HandleCommandL(
       
   304                              (EEventStdKeyLeftArrow == aEventType)? EPtiCommandUserActionShorten : EPtiCommandUserActionLengthen);
       
   305                 UpdateContextFieldL();
       
   306                 }
       
   307             break;
       
   308         case EEventIcfPointerUp:  // from ContextField
       
   309             if (EStatusConversion == iStatus || EStatusCandidate == iStatus)
       
   310                 {
       
   311                 iPtiEngine->HandleCommandL(EPtiCommandUserActionShorten);
       
   312                 iPtiEngine->HandleCommandL(EPtiCommandUserActionLengthen);
       
   313                 iStatus = EStatusChangeDivision;
       
   314                 UpdateContextFieldL();
       
   315                 }
       
   316             else if (EStatusTransitoryInput == iStatus
       
   317                    || EStatusPredictiveTransitoryInput == iStatus
       
   318                    || EStatusPredictiveTransitoryInputWithNoChar == iStatus  // not take place
       
   319                    || EStatusChangeDivision == iStatus)
       
   320                 {
       
   321                 TInt pos = -1;
       
   322                 TInt cursorPosition = *((TInt*)aEventData.Ptr());
       
   323                 const MPtiEngineCompositionDataInterface* data = iPtiEngine->CompositionData();
       
   324                 if (data)
       
   325                     {
       
   326                     pos = data->CursorPosition();
       
   327                     if (EStatusChangeDivision == iStatus)
       
   328                         {
       
   329                         if (data->NumberOfPhrase() > 0)
       
   330                             {
       
   331                             TPtrC8 clauseChar = data->LengthOfPhrase();
       
   332                             pos = clauseChar[0];
       
   333                             }
       
   334                         }
       
   335                     }
       
   336                 if(0 <= pos)
       
   337                     {
       
   338                     TInt posDiff = cursorPosition - pos;
       
   339                     if(posDiff)
       
   340                         {
       
   341                         TPtiEngineCommand cmd;
       
   342                         if (EStatusChangeDivision == iStatus)
       
   343                             {
       
   344                             cmd = (posDiff < 0)? EPtiCommandUserActionShorten : EPtiCommandUserActionLengthen;
       
   345                             }
       
   346                         else
       
   347                             {
       
   348                             cmd = (posDiff < 0)? EPtiCommandUserActionLeft : EPtiCommandUserActionRight;
       
   349                             }
       
   350                         if (posDiff < 0)
       
   351                             {
       
   352                             posDiff = -posDiff;
       
   353                             }
       
   354                          while(posDiff > 0)
       
   355                             {
       
   356                             -- posDiff;
       
   357                             iPtiEngine->HandleCommandL(cmd);
       
   358                             }
       
   359                         }
       
   360                     if (EStatusChangeDivision == iStatus)
       
   361                         {
       
   362                         iPtiEngine->HandleCommandL(EPtiCommandUserActionConvert);
       
   363                         iStatus = EStatusConversion;
       
   364                         UpdateContextFieldL();
       
   365                         }
       
   366                     }
       
   367                 }
       
   368             break;
       
   369 		case EEventIcfCompleteAll:  // from ContextField
       
   370             {
       
   371             CompleteL();
       
   372             }
       
   373             break;
       
   374         case EEventICFSelectionChanged:  // from ContextField (when whithout transitory input)
       
   375             {
       
   376             }
       
   377             break;
       
   378         case EEventSetAppCursorSelection:  // from ContextField
       
   379             { // clear prediction pane
       
   380             if (EStatusPredictiveTransitoryInputWithNoChar == iStatus)
       
   381                 {
       
   382                 iStatus = EStatusInitial;
       
   383                 UpdateContextFieldL();
       
   384                 }
       
   385             }
       
   386             break;
       
   387         default:
       
   388             break;
       
   389         }
       
   390     }
       
   391 
       
   392 // -----------------------------------------------------------------------------
       
   393 // CPeninputHiraganaKanji::HandleKeyEvent
       
   394 // without implementation
       
   395 // (other items were commented in a header).
       
   396 // -----------------------------------------------------------------------------
       
   397 EXPORT_C TBool CPeninputHiraganaKanji::HandleKeyEvent(const TRawEvent& aData)
       
   398     {
       
   399     TBool ret = EFalse;
       
   400     iPendingEvent = 0;
       
   401     if(EStatusComplete == iStatus || EStatusCompleteAll == iStatus
       
   402           || EStatusCompleteAllfromUiLayout == iStatus) // wait for SetEditorTextL from Editor
       
   403         {
       
   404         return ETrue;
       
   405         }
       
   406     const MPtiEngineCompositionDataInterface* data = iPtiEngine->CompositionData();
       
   407     if (!data)
       
   408         {
       
   409         return ret;
       
   410         }
       
   411     TPtrC text = data->ConvertingString();
       
   412     if (text.Length() > 0 || EStatusPredictiveTransitoryInputWithNoChar == iStatus)
       
   413         {
       
   414         TInt key = (aData.ScanCode() & 0x000000FF);
       
   415         TInt evetType = EPeninputLayoutEventEnter;
       
   416         TInt repeat = 0;
       
   417         switch(key)
       
   418             {
       
   419             case EKeyUpArrow:
       
   420             case EStdKeyUpArrow:        /* 0x10 */
       
   421                 {
       
   422                 evetType = EEventStdKeyUpArrow;
       
   423                 ret = ETrue;
       
   424                 repeat = 1;
       
   425                 }
       
   426                 break;
       
   427             case EKeyDownArrow:
       
   428             case EStdKeyDownArrow:
       
   429                 {
       
   430                 evetType = EEventStdKeyDownArrow;
       
   431                 ret = ETrue;
       
   432                 repeat = 1;
       
   433                 }
       
   434                 break;
       
   435             case EKeyLeftArrow:
       
   436             case EStdKeyLeftArrow:      /* 0x0e */
       
   437                 {
       
   438                 evetType = EEventStdKeyLeftArrow;
       
   439                 ret = ETrue;
       
   440                 repeat = 1;
       
   441                 }
       
   442                 break;
       
   443             case EKeyRightArrow:
       
   444             case EStdKeyRightArrow:     /* 0x0f */
       
   445                 {
       
   446                 evetType = EEventStdKeyRightArrow;
       
   447                 ret = ETrue;
       
   448                 repeat = 1;
       
   449                 }
       
   450                 break;
       
   451             case EKeyOK:
       
   452             case EStdKeyDevice3:        /* 0xA7 */
       
   453             case EStdKeyEnter:          /* 0x03 */
       
   454             case EStdKeyNkpEnter:       /* 0x88 */
       
   455                 {
       
   456                 evetType = EPeninputLayoutEventEnter;
       
   457                 ret = ETrue;
       
   458                 }
       
   459                 break;
       
   460             case EKeyBackspace:
       
   461             case EStdKeyBackspace:      /* 0x01 */
       
   462                 {
       
   463                 evetType = EPeninputLayoutEventBack;
       
   464                 ret = ETrue;
       
   465                 repeat = 1;
       
   466                 }
       
   467                 break;
       
   468             case EStdKeyEscape:         /* 0x04 */
       
   469                 {
       
   470                 evetType = EPeninputLayoutEventBack;
       
   471                 ret = ETrue;
       
   472                 }
       
   473                 break;
       
   474             case EStdKeyTab:         /* 0x02 */
       
   475                 {
       
   476                 evetType = EPeninputLayoutEventTab;
       
   477                 ret = ETrue;
       
   478                 }
       
   479                 break;
       
   480             case EStdKeySpace:         /* 0x05 */
       
   481                 {
       
   482                 if (EStatusPredictiveTransitoryInputWithNoChar == iStatus)
       
   483                     {
       
   484                     iStatus = EStatusInitial;
       
   485                     TRAP_IGNORE(UpdateContextFieldL());  // not Leave
       
   486                     }
       
   487                 else
       
   488                     {
       
   489                     evetType = EPeninputLayoutEventSpace;
       
   490                     ret = ETrue;
       
   491                     }
       
   492                 }
       
   493                 break;
       
   494             default:
       
   495                 break;
       
   496             }
       
   497         if(ret && TRawEvent::EKeyDown == aData.Type())
       
   498             {
       
   499             iPendingEvent = evetType;
       
   500             iRepeat = repeat;
       
   501             }
       
   502         if(TRawEvent::EKeyUp == aData.Type())
       
   503             {
       
   504             CancelRepeat();
       
   505             }
       
   506         }
       
   507     return ret;
       
   508     }
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // CPeninputHiraganaKanji::HandlePendingEventL
       
   512 // (other items were commented in a header).
       
   513 // -----------------------------------------------------------------------------
       
   514 EXPORT_C TBool CPeninputHiraganaKanji::HandlePendingEventL()
       
   515     {
       
   516     if (iPendingEvent)
       
   517         {
       
   518         if (EPeninputLayoutEventBack == iPendingEvent)
       
   519             {
       
   520             iUiLayout->HandleControlEvent(EPeninputLayoutEventBack, reinterpret_cast<CFepUiBaseCtrl*>(this), KNullDesC);
       
   521             }
       
   522         else  // up/down/left/right arrow
       
   523             {
       
   524             HandleControlEventJpL(iPendingEvent, KNullDesC);
       
   525             }
       
   526         if (iRepeat)
       
   527             {
       
   528             iLongPressTimer->SetTimer(KLongPressInterval);
       
   529             }
       
   530         else
       
   531             {
       
   532             iPendingEvent = 0;
       
   533             }
       
   534         return ETrue;
       
   535         }
       
   536     return EFalse;
       
   537     }
       
   538 
       
   539 // ---------------------------------------------------------------------------
       
   540 // CPeninputHiraganaKanji::SetEditorTextL
       
   541 // (other items were commented in a header).
       
   542 // ---------------------------------------------------------------------------
       
   543 EXPORT_C void CPeninputHiraganaKanji::SetEditorTextL(const TFepInputContextFieldData& aData)
       
   544     {
       
   545     if(EStatusComplete == iStatus || EStatusCompleteAll == iStatus || EStatusCompleteAllfromUiLayout == iStatus)
       
   546         {
       
   547         iCandidateArray->Reset();
       
   548         iCandidateWnd->HidePopup();
       
   549         }
       
   550     if(iInputContextField)
       
   551         {
       
   552         iInputContextField->SetTextL(aData);
       
   553         }
       
   554     if(EStatusComplete == iStatus || EStatusCompleteAll == iStatus || EStatusCompleteAllfromUiLayout == iStatus)
       
   555         {
       
   556         if (EStatusCompleteAllfromUiLayout == iStatus)
       
   557             {
       
   558             iStatus = EStatusInitial;
       
   559             }
       
   560         else if (EStatusCompleteAll == iStatus)
       
   561             {
       
   562             if (!iPredictiveWnd->Hiden())
       
   563                 {
       
   564                 iStatus = EStatusPredictiveTransitoryInputWithNoChar;
       
   565                 iUiLayout->HandleControlEvent(EEventHiraganaKanjiWithoutTransitoryChars, reinterpret_cast<CFepUiBaseCtrl*>(this), KNullDesC);
       
   566                 }
       
   567             else
       
   568                 {
       
   569                 iStatus = EStatusInitial;
       
   570                 }
       
   571             if (iChar)   // next input exists
       
   572                 {
       
   573                 UpdateContextFieldL();
       
   574                 iUiLayout->HandleControlEvent(EEventVirtualKeyUp, reinterpret_cast<CFepUiBaseCtrl*>(this), *iChar);
       
   575                 delete iChar;
       
   576                 iChar = NULL;
       
   577                 return;
       
   578                 }
       
   579             }
       
   580         else
       
   581             {
       
   582             iStatus = EStatusConversion;
       
   583             
       
   584             if( iInputContextField != NULL )
       
   585                 {
       
   586                 iInputContextField->StartInlineL();
       
   587                 }
       
   588             }
       
   589         UpdateContextFieldL();
       
   590         }
       
   591     }
       
   592 
       
   593 // ---------------------------------------------------------
       
   594 // Cancel timers for key repeat
       
   595 // ---------------------------------------------------------
       
   596 //
       
   597 EXPORT_C void CPeninputHiraganaKanji::CancelRepeat()
       
   598     {
       
   599     if (iRepeat)
       
   600         {
       
   601         if (iLongPressTimer)
       
   602             {
       
   603             iLongPressTimer->Cancel();
       
   604             }
       
   605         if (iRepeatTimer)
       
   606             {
       
   607             iRepeatTimer->Cancel();
       
   608             }
       
   609         iPendingEvent = 0;
       
   610         iRepeat = 0;
       
   611         }
       
   612     iCandidateWnd->CancelScrollBarRepeat();
       
   613     iPredictiveWnd->CancelRepeat();
       
   614     }
       
   615 
       
   616 // ---------------------------------------------------------
       
   617 // Start timers for clear key repeat
       
   618 // ---------------------------------------------------------
       
   619 //
       
   620 EXPORT_C void CPeninputHiraganaKanji::RepeatClearKeyStart()
       
   621     {
       
   622     if (!iRepeat)
       
   623         {
       
   624         iPendingEvent = EPeninputLayoutEventBack;
       
   625         iRepeat = 1;
       
   626         iLongPressTimer->SetTimer(KLongPressInterval);
       
   627         }
       
   628     }
       
   629 
       
   630 // ---------------------------------------------------------
       
   631 // Time out event handler of both long press timer & repeat timer
       
   632 // ---------------------------------------------------------
       
   633 //
       
   634 void CPeninputHiraganaKanji::HandleTimerOut(const CAknFepTimer* aTimer)
       
   635     {
       
   636     if (aTimer == iLongPressTimer)
       
   637         {
       
   638         iRepeatTimer->SetTimer(KRepeatInterval);
       
   639         }
       
   640     else
       
   641         {
       
   642         if (aTimer == iRepeatTimer)
       
   643             {
       
   644             if (iPendingEvent)
       
   645                 {
       
   646                 if (EPeninputLayoutEventBack == iPendingEvent)
       
   647                     {
       
   648                     iUiLayout->HandleControlEvent(EPeninputLayoutEventBack, reinterpret_cast<CFepUiBaseCtrl*>(this), KNullDesC);
       
   649                     }
       
   650                 else   // up/down/left/right arrow
       
   651                     {
       
   652                     TRAP_IGNORE(HandleControlEventJpL(iPendingEvent, KNullDesC));
       
   653                     }
       
   654                 iRepeatTimer->SetTimer(KRepeatInterval);
       
   655                 }
       
   656             }
       
   657         }
       
   658     }
       
   659 
       
   660 // ---------------------------------------------------------
       
   661 // C++ Constructor
       
   662 // ---------------------------------------------------------
       
   663 CPeninputHiraganaKanji::CPeninputHiraganaKanji(CPtiEngine* aPtiEngine
       
   664                                                                    , CFepUiLayout* aUiLayout
       
   665                                                                    , CFepInputContextFieldJp* aInputContextField
       
   666                                                                    , CPeninputJapaneseCandidateWnd* aCandidateWnd
       
   667                                                                    , CPeninputJapanesePredictiveWnd* aPredictiveWnd)
       
   668     : iPtiEngine(aPtiEngine),
       
   669       iUiLayout(aUiLayout),
       
   670       iInputContextField(aInputContextField),
       
   671       iStatus(EStatusInitial),
       
   672       iCandidateWnd(aCandidateWnd),
       
   673       iPredictiveWnd(aPredictiveWnd)
       
   674     {
       
   675     }
       
   676 
       
   677 // ---------------------------------------------------------
       
   678 // 2nd Constructor
       
   679 // ---------------------------------------------------------
       
   680 void CPeninputHiraganaKanji::ConstructL()
       
   681     {
       
   682     iCandidateArray = new(ELeave) CDesCArrayFlat(1);
       
   683     iCandidateWnd->SetIcf(iInputContextField);
       
   684     iLongPressTimer = CAknFepTimer::NewL(this);
       
   685     iRepeatTimer = CAknFepTimer::NewL(this);
       
   686     }
       
   687 
       
   688 // ---------------------------------------------------------
       
   689 // Insert a key
       
   690 // ---------------------------------------------------------
       
   691 void CPeninputHiraganaKanji::HandleInsertL(const TDesC& aEventData)
       
   692     {
       
   693     TUint16* unicode = (TUint16*)aEventData.Ptr();
       
   694     TUint ch;
       
   695     for (TInt i = 0; i < aEventData.Length(); i++)
       
   696         {
       
   697         ch = *(unicode + i);
       
   698         iPtiEngine->HandleCommandL(EPtiCommandAppendCharacter, &ch);
       
   699         }
       
   700     UpdateContextFieldL();
       
   701     }
       
   702 
       
   703 // ---------------------------------------------------------
       
   704 // Cancel From UiLayout   not used
       
   705 // ---------------------------------------------------------
       
   706 void CPeninputHiraganaKanji::ClearTextL()
       
   707     {
       
   708     iPtiEngine->ClearCurrentWord();
       
   709     CancelL();
       
   710     UpdateContextFieldL();
       
   711     }
       
   712 
       
   713 // ---------------------------------------------------------
       
   714 // complete
       
   715 // ---------------------------------------------------------
       
   716 void CPeninputHiraganaKanji::CompleteL()
       
   717     {
       
   718     iPtiEngine->HandleCommandL(EPtiCommandUserActionComplete);
       
   719     CompleteSubL();
       
   720     }
       
   721 
       
   722 // ---------------------------------------------------------
       
   723 // complete all
       
   724 // ---------------------------------------------------------
       
   725 void CPeninputHiraganaKanji::CompleteAllL()
       
   726     {
       
   727     iPtiEngine->HandleCommandL(EPtiCommandUserActionAllComplete);
       
   728     if (EStatusCompleteAllfromUiLayout == iStatus)
       
   729         {
       
   730         iPredictiveWnd->HidePopup();
       
   731         iCandidateArray->Reset();
       
   732         iCandidateWnd->HidePopup();
       
   733         }
       
   734     CompleteSubL();
       
   735     }
       
   736 
       
   737 // ---------------------------------------------------------
       
   738 // CompleteSubL
       
   739 // ---------------------------------------------------------
       
   740 void CPeninputHiraganaKanji::CompleteSubL()
       
   741     {
       
   742     const MPtiEngineCompositionDataInterface* data = iPtiEngine->CompositionData();
       
   743     if (!data)
       
   744         {
       
   745         return;
       
   746         }
       
   747     TPtrC completedString = data->CompletedString();
       
   748     TPtrC convertingString = data->ConvertingString();
       
   749     TInt sviStatus = iStatus;
       
   750     if (completedString.Length() > 0)
       
   751         {
       
   752         if (EStatusCompleteAllfromUiLayout != iStatus)
       
   753             {
       
   754             iStatus = (convertingString.Length())? EStatusComplete : EStatusCompleteAll;
       
   755             }
       
   756         if (EStatusPredictiveTransitoryInputWithNoChar != sviStatus)
       
   757             {
       
   758             if (EStatusComplete == iStatus)
       
   759                 {
       
   760                 iInputContextField->CommitInlineL();
       
   761                 }
       
   762             else
       
   763                 {
       
   764                 iInputContextField->CompleteInlineL();
       
   765                 }
       
   766             }
       
   767         iUiLayout->SignalOwner(ESignalKeyEvent,completedString);
       
   768         if (EStatusCompleteAllfromUiLayout == iStatus)
       
   769             {
       
   770             iUiLayout->HandleControlEvent(EEventWaitforEditorTextComing, reinterpret_cast<CFepUiBaseCtrl*>(this), KNullDesC);
       
   771             }
       
   772         }
       
   773     else
       
   774         {
       
   775         if (EStatusPredictiveTransitoryInputWithNoChar == iStatus
       
   776               || EStatusCompleteAllfromUiLayout == iStatus)
       
   777             {
       
   778             if (iStatus == EStatusCompleteAllfromUiLayout)  // exceptional case
       
   779                 {
       
   780                 iInputContextField->CancelInlineL();
       
   781                 }
       
   782             iStatus = EStatusInitial;
       
   783             }
       
   784         UpdateContextFieldL();  // not leave
       
   785         }
       
   786     }
       
   787 
       
   788 // ---------------------------------------------------------
       
   789 // Handle back key
       
   790 // iStatus
       
   791 //     EStatusTransitoryInput:
       
   792 //     EStatusPredictiveTransitoryInput:
       
   793 // ---------------------------------------------------------
       
   794 void CPeninputHiraganaKanji::HandleBackL()
       
   795     {
       
   796     const MPtiEngineCompositionDataInterface* data = iPtiEngine->CompositionData();
       
   797     if (!data)
       
   798         {
       
   799         return;
       
   800         }
       
   801     TPtrC text = data->ConvertingString();
       
   802     if (!text.Length())  // not take place
       
   803         {
       
   804         return;
       
   805         }
       
   806     iPtiEngine->DeleteKeyPress();
       
   807     const MPtiEngineCompositionDataInterface* dataAfter = iPtiEngine->CompositionData();
       
   808     if (!dataAfter)
       
   809         {
       
   810         return;
       
   811         }
       
   812     TPtrC textAfter = dataAfter->ConvertingString();
       
   813     if (!textAfter.Length())
       
   814         {
       
   815         CancelL();
       
   816         }
       
   817     UpdateContextFieldL();
       
   818     }
       
   819 
       
   820 // ---------------------------------------------------------
       
   821 // Update context field : ConvertingString
       
   822 // ---------------------------------------------------------
       
   823 //
       
   824 void CPeninputHiraganaKanji::UpdateContextFieldL()
       
   825     {
       
   826     const MPtiEngineCompositionDataInterface* data = iPtiEngine->CompositionData();
       
   827     if (!data)
       
   828         {
       
   829         return;
       
   830         }
       
   831     TPtrC text = data->ConvertingString();
       
   832     if (EStatusPredictiveTransitoryInputWithNoChar == iStatus)
       
   833         {
       
   834         iPtiEngine->ClearCurrentWord();
       
   835         iInputContextField->SetCursorVisible( ETrue );
       
   836         // update popup window
       
   837         UpdateCandidateListL();
       
   838         return;
       
   839         }
       
   840     if (EStatusPredictiveTransitoryInput == iStatus || EStatusTransitoryInput == iStatus)
       
   841         {
       
   842         if (text.Length() > 0)
       
   843             {
       
   844             iInputContextField->UpdateInlineL(text, -1);
       
   845             TInt pos = data->CursorPosition();
       
   846             if(0 <= pos)
       
   847                 {
       
   848                 iInputContextField->SetCursorPosition(pos);
       
   849                 }
       
   850             iInputContextField->SetCursorVisible( ETrue );
       
   851             // update popup window
       
   852             UpdateCandidateListL();
       
   853             return;
       
   854             }
       
   855         }
       
   856     if (EStatusConversion == iStatus || EStatusCandidate == iStatus || EStatusChangeDivision == iStatus)
       
   857         {
       
   858         if (text.Length() > 0 && data->NumberOfPhrase() > 0)
       
   859             {
       
   860             TPtrC8 clauseChar = data->LengthOfPhrase();
       
   861             // update inline on ContextField
       
   862             if ( EStatusChangeDivision == iStatus )
       
   863                 {
       
   864                 iInputContextField->UpdateInlineL(text, clauseChar[0], CFepInputContextFieldJp::ETransitoryInputAreaSwitching);
       
   865                 }
       
   866             else
       
   867                 {
       
   868                 iInputContextField->UpdateInlineL(text, clauseChar[0]);
       
   869                 }
       
   870             iInputContextField->SetCursorVisible(EFalse);
       
   871             UpdateCandidateListL();
       
   872             return;
       
   873             }
       
   874         }
       
   875     if (EStatusInitial != iStatus)    // can take place : at EEventVirtualKeyUp(data length == 0)
       
   876         {
       
   877         CancelL();
       
   878         }
       
   879     iPtiEngine->ClearCurrentWord();
       
   880     iInputContextField->SetCursorVisible( ETrue );
       
   881     iUiLayout->HandleControlEvent(EEventHiraganaKanjiWithTransitoryChars2Standbyjp, reinterpret_cast<CFepUiBaseCtrl*>(this), KNullDesC);
       
   882     UpdateCandidateListL();
       
   883     }
       
   884 
       
   885 // ---------------------------------------------------------
       
   886 // Update Predictive Popup
       
   887 // ---------------------------------------------------------
       
   888 void CPeninputHiraganaKanji::UpdateCandidateListL()
       
   889     {
       
   890     if (EStatusPredictiveTransitoryInput == iStatus || EStatusPredictiveTransitoryInputWithNoChar == iStatus || EStatusCandidate == iStatus)
       
   891         {
       
   892         TInt index = 0;
       
   893         iCandidateArray->Reset();
       
   894         iPtiEngine->GetCandidateListL(*iCandidateArray);
       
   895         if (EStatusCandidate == iStatus)
       
   896             {
       
   897             iPtiEngine->HandleCommandL(EPtiCommandUserActionGetCurrentIndexOfCandidates, &index);
       
   898             if (index >= iCandidateArray->Count())    // not take place
       
   899                 {
       
   900                 index = 0;
       
   901                 }
       
   902             iPredictiveWnd->HidePopup();
       
   903             iCandidateWnd->ShowPopupL(iCandidateArray, index);
       
   904             // capture of candidate control removed. Trensitory Input Exists, then the capture flag should be on.
       
   905             //signal the owner that pointer needs be captured
       
   906                 {
       
   907                 TBool capture = ETrue;
       
   908                 TPtrC data;
       
   909                 data.Set((const TUint16 *)&capture,sizeof(TBool)/sizeof(TUint16));
       
   910                 iUiLayout->LayoutOwner()->SignalOwner(ESignalCapturePointer,data);
       
   911                 }
       
   912             }
       
   913         else
       
   914             {
       
   915             iCandidateWnd->HidePopup();
       
   916             iPredictiveWnd->ShowPopupL(iCandidateArray, index);
       
   917             }
       
   918         }
       
   919     else
       
   920         {
       
   921         iPredictiveWnd->HidePopup();
       
   922         iCandidateWnd->HidePopup();
       
   923         }
       
   924     }
       
   925 
       
   926 // ---------------------------------------------------------
       
   927 // Cancel Transitory Input
       
   928 // ---------------------------------------------------------
       
   929 void CPeninputHiraganaKanji::CancelL()
       
   930     {
       
   931     iStatus = EStatusInitial;
       
   932     iInputContextField->CancelInlineL();
       
   933     }
       
   934 
       
   935 // End Of File