textinput/peninputcommonctrlsjp/src/peninputhiraganakanji.cpp
changeset 0 eb1f2e154e89
child 7 6defe5d1bd39
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     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             iInputContextField->StartInlineL();
       
   584             }
       
   585         UpdateContextFieldL();
       
   586         }
       
   587     }
       
   588 
       
   589 // ---------------------------------------------------------
       
   590 // Cancel timers for key repeat
       
   591 // ---------------------------------------------------------
       
   592 //
       
   593 EXPORT_C void CPeninputHiraganaKanji::CancelRepeat()
       
   594     {
       
   595     if (iRepeat)
       
   596         {
       
   597         if (iLongPressTimer)
       
   598             {
       
   599             iLongPressTimer->Cancel();
       
   600             }
       
   601         if (iRepeatTimer)
       
   602             {
       
   603             iRepeatTimer->Cancel();
       
   604             }
       
   605         iPendingEvent = 0;
       
   606         iRepeat = 0;
       
   607         }
       
   608     iCandidateWnd->CancelScrollBarRepeat();
       
   609     iPredictiveWnd->CancelRepeat();
       
   610     }
       
   611 
       
   612 // ---------------------------------------------------------
       
   613 // Start timers for clear key repeat
       
   614 // ---------------------------------------------------------
       
   615 //
       
   616 EXPORT_C void CPeninputHiraganaKanji::RepeatClearKeyStart()
       
   617     {
       
   618     if (!iRepeat)
       
   619         {
       
   620         iPendingEvent = EPeninputLayoutEventBack;
       
   621         iRepeat = 1;
       
   622         iLongPressTimer->SetTimer(KLongPressInterval);
       
   623         }
       
   624     }
       
   625 
       
   626 // ---------------------------------------------------------
       
   627 // Time out event handler of both long press timer & repeat timer
       
   628 // ---------------------------------------------------------
       
   629 //
       
   630 void CPeninputHiraganaKanji::HandleTimerOut(const CAknFepTimer* aTimer)
       
   631     {
       
   632     if (aTimer == iLongPressTimer)
       
   633         {
       
   634         iRepeatTimer->SetTimer(KRepeatInterval);
       
   635         }
       
   636     else
       
   637         {
       
   638         if (aTimer == iRepeatTimer)
       
   639             {
       
   640             if (iPendingEvent)
       
   641                 {
       
   642                 if (EPeninputLayoutEventBack == iPendingEvent)
       
   643                     {
       
   644                     iUiLayout->HandleControlEvent(EPeninputLayoutEventBack, reinterpret_cast<CFepUiBaseCtrl*>(this), KNullDesC);
       
   645                     }
       
   646                 else   // up/down/left/right arrow
       
   647                     {
       
   648                     TRAP_IGNORE(HandleControlEventJpL(iPendingEvent, KNullDesC));
       
   649                     }
       
   650                 iRepeatTimer->SetTimer(KRepeatInterval);
       
   651                 }
       
   652             }
       
   653         }
       
   654     }
       
   655 
       
   656 // ---------------------------------------------------------
       
   657 // C++ Constructor
       
   658 // ---------------------------------------------------------
       
   659 CPeninputHiraganaKanji::CPeninputHiraganaKanji(CPtiEngine* aPtiEngine
       
   660                                                                    , CFepUiLayout* aUiLayout
       
   661                                                                    , CFepInputContextFieldJp* aInputContextField
       
   662                                                                    , CPeninputJapaneseCandidateWnd* aCandidateWnd
       
   663                                                                    , CPeninputJapanesePredictiveWnd* aPredictiveWnd)
       
   664     : iPtiEngine(aPtiEngine),
       
   665       iUiLayout(aUiLayout),
       
   666       iInputContextField(aInputContextField),
       
   667       iStatus(EStatusInitial),
       
   668       iCandidateWnd(aCandidateWnd),
       
   669       iPredictiveWnd(aPredictiveWnd)
       
   670     {
       
   671     }
       
   672 
       
   673 // ---------------------------------------------------------
       
   674 // 2nd Constructor
       
   675 // ---------------------------------------------------------
       
   676 void CPeninputHiraganaKanji::ConstructL()
       
   677     {
       
   678     iCandidateArray = new(ELeave) CDesCArrayFlat(1);
       
   679     iCandidateWnd->SetIcf(iInputContextField);
       
   680     iLongPressTimer = CAknFepTimer::NewL(this);
       
   681     iRepeatTimer = CAknFepTimer::NewL(this);
       
   682     }
       
   683 
       
   684 // ---------------------------------------------------------
       
   685 // Insert a key
       
   686 // ---------------------------------------------------------
       
   687 void CPeninputHiraganaKanji::HandleInsertL(const TDesC& aEventData)
       
   688     {
       
   689     TUint16* unicode = (TUint16*)aEventData.Ptr();
       
   690     TUint ch;
       
   691     for (TInt i = 0; i < aEventData.Length(); i++)
       
   692         {
       
   693         ch = *(unicode + i);
       
   694         iPtiEngine->HandleCommandL(EPtiCommandAppendCharacter, &ch);
       
   695         }
       
   696     UpdateContextFieldL();
       
   697     }
       
   698 
       
   699 // ---------------------------------------------------------
       
   700 // Cancel From UiLayout   not used
       
   701 // ---------------------------------------------------------
       
   702 void CPeninputHiraganaKanji::ClearTextL()
       
   703     {
       
   704     iPtiEngine->ClearCurrentWord();
       
   705     CancelL();
       
   706     UpdateContextFieldL();
       
   707     }
       
   708 
       
   709 // ---------------------------------------------------------
       
   710 // complete
       
   711 // ---------------------------------------------------------
       
   712 void CPeninputHiraganaKanji::CompleteL()
       
   713     {
       
   714     iPtiEngine->HandleCommandL(EPtiCommandUserActionComplete);
       
   715     CompleteSubL();
       
   716     }
       
   717 
       
   718 // ---------------------------------------------------------
       
   719 // complete all
       
   720 // ---------------------------------------------------------
       
   721 void CPeninputHiraganaKanji::CompleteAllL()
       
   722     {
       
   723     iPtiEngine->HandleCommandL(EPtiCommandUserActionAllComplete);
       
   724     if (EStatusCompleteAllfromUiLayout == iStatus)
       
   725         {
       
   726         iPredictiveWnd->HidePopup();
       
   727         iCandidateArray->Reset();
       
   728         iCandidateWnd->HidePopup();
       
   729         }
       
   730     CompleteSubL();
       
   731     }
       
   732 
       
   733 // ---------------------------------------------------------
       
   734 // CompleteSubL
       
   735 // ---------------------------------------------------------
       
   736 void CPeninputHiraganaKanji::CompleteSubL()
       
   737     {
       
   738     const MPtiEngineCompositionDataInterface* data = iPtiEngine->CompositionData();
       
   739     if (!data)
       
   740         {
       
   741         return;
       
   742         }
       
   743     TPtrC completedString = data->CompletedString();
       
   744     TPtrC convertingString = data->ConvertingString();
       
   745     TInt sviStatus = iStatus;
       
   746     if (completedString.Length() > 0)
       
   747         {
       
   748         if (EStatusCompleteAllfromUiLayout != iStatus)
       
   749             {
       
   750             iStatus = (convertingString.Length())? EStatusComplete : EStatusCompleteAll;
       
   751             }
       
   752         if (EStatusPredictiveTransitoryInputWithNoChar != sviStatus)
       
   753             {
       
   754             if (EStatusComplete == iStatus)
       
   755                 {
       
   756                 iInputContextField->CommitInlineL();
       
   757                 }
       
   758             else
       
   759                 {
       
   760                 iInputContextField->CompleteInlineL();
       
   761                 }
       
   762             }
       
   763         iUiLayout->SignalOwner(ESignalKeyEvent,completedString);
       
   764         if (EStatusCompleteAllfromUiLayout == iStatus)
       
   765             {
       
   766             iUiLayout->HandleControlEvent(EEventWaitforEditorTextComing, reinterpret_cast<CFepUiBaseCtrl*>(this), KNullDesC);
       
   767             }
       
   768         }
       
   769     else
       
   770         {
       
   771         if (EStatusPredictiveTransitoryInputWithNoChar == iStatus
       
   772               || EStatusCompleteAllfromUiLayout == iStatus)
       
   773             {
       
   774             if (iStatus == EStatusCompleteAllfromUiLayout)  // exceptional case
       
   775                 {
       
   776                 iInputContextField->CancelInlineL();
       
   777                 }
       
   778             iStatus = EStatusInitial;
       
   779             }
       
   780         UpdateContextFieldL();  // not leave
       
   781         }
       
   782     }
       
   783 
       
   784 // ---------------------------------------------------------
       
   785 // Handle back key
       
   786 // iStatus
       
   787 //     EStatusTransitoryInput:
       
   788 //     EStatusPredictiveTransitoryInput:
       
   789 // ---------------------------------------------------------
       
   790 void CPeninputHiraganaKanji::HandleBackL()
       
   791     {
       
   792     const MPtiEngineCompositionDataInterface* data = iPtiEngine->CompositionData();
       
   793     if (!data)
       
   794         {
       
   795         return;
       
   796         }
       
   797     TPtrC text = data->ConvertingString();
       
   798     if (!text.Length())  // not take place
       
   799         {
       
   800         return;
       
   801         }
       
   802     iPtiEngine->DeleteKeyPress();
       
   803     const MPtiEngineCompositionDataInterface* dataAfter = iPtiEngine->CompositionData();
       
   804     if (!dataAfter)
       
   805         {
       
   806         return;
       
   807         }
       
   808     TPtrC textAfter = dataAfter->ConvertingString();
       
   809     if (!textAfter.Length())
       
   810         {
       
   811         CancelL();
       
   812         }
       
   813     UpdateContextFieldL();
       
   814     }
       
   815 
       
   816 // ---------------------------------------------------------
       
   817 // Update context field : ConvertingString
       
   818 // ---------------------------------------------------------
       
   819 //
       
   820 void CPeninputHiraganaKanji::UpdateContextFieldL()
       
   821     {
       
   822     const MPtiEngineCompositionDataInterface* data = iPtiEngine->CompositionData();
       
   823     if (!data)
       
   824         {
       
   825         return;
       
   826         }
       
   827     TPtrC text = data->ConvertingString();
       
   828     if (EStatusPredictiveTransitoryInputWithNoChar == iStatus)
       
   829         {
       
   830         iPtiEngine->ClearCurrentWord();
       
   831         iInputContextField->SetCursorVisible( ETrue );
       
   832         // update popup window
       
   833         UpdateCandidateListL();
       
   834         return;
       
   835         }
       
   836     if (EStatusPredictiveTransitoryInput == iStatus || EStatusTransitoryInput == iStatus)
       
   837         {
       
   838         if (text.Length() > 0)
       
   839             {
       
   840             iInputContextField->UpdateInlineL(text, -1);
       
   841             TInt pos = data->CursorPosition();
       
   842             if(0 <= pos)
       
   843                 {
       
   844                 iInputContextField->SetCursorPosition(pos);
       
   845                 }
       
   846             iInputContextField->SetCursorVisible( ETrue );
       
   847             // update popup window
       
   848             UpdateCandidateListL();
       
   849             return;
       
   850             }
       
   851         }
       
   852     if (EStatusConversion == iStatus || EStatusCandidate == iStatus || EStatusChangeDivision == iStatus)
       
   853         {
       
   854         if (text.Length() > 0 && data->NumberOfPhrase() > 0)
       
   855             {
       
   856             TPtrC8 clauseChar = data->LengthOfPhrase();
       
   857             // update inline on ContextField
       
   858             if ( EStatusChangeDivision == iStatus )
       
   859                 {
       
   860                 iInputContextField->UpdateInlineL(text, clauseChar[0], CFepInputContextFieldJp::ETransitoryInputAreaSwitching);
       
   861                 }
       
   862             else
       
   863                 {
       
   864                 iInputContextField->UpdateInlineL(text, clauseChar[0]);
       
   865                 }
       
   866             iInputContextField->SetCursorVisible(EFalse);
       
   867             UpdateCandidateListL();
       
   868             return;
       
   869             }
       
   870         }
       
   871     if (EStatusInitial != iStatus)    // can take place : at EEventVirtualKeyUp(data length == 0)
       
   872         {
       
   873         CancelL();
       
   874         }
       
   875     iPtiEngine->ClearCurrentWord();
       
   876     iInputContextField->SetCursorVisible( ETrue );
       
   877     iUiLayout->HandleControlEvent(EEventHiraganaKanjiWithTransitoryChars2Standbyjp, reinterpret_cast<CFepUiBaseCtrl*>(this), KNullDesC);
       
   878     UpdateCandidateListL();
       
   879     }
       
   880 
       
   881 // ---------------------------------------------------------
       
   882 // Update Predictive Popup
       
   883 // ---------------------------------------------------------
       
   884 void CPeninputHiraganaKanji::UpdateCandidateListL()
       
   885     {
       
   886     if (EStatusPredictiveTransitoryInput == iStatus || EStatusPredictiveTransitoryInputWithNoChar == iStatus || EStatusCandidate == iStatus)
       
   887         {
       
   888         TInt index = 0;
       
   889         iCandidateArray->Reset();
       
   890         iPtiEngine->GetCandidateListL(*iCandidateArray);
       
   891         if (EStatusCandidate == iStatus)
       
   892             {
       
   893             iPtiEngine->HandleCommandL(EPtiCommandUserActionGetCurrentIndexOfCandidates, &index);
       
   894             if (index >= iCandidateArray->Count())    // not take place
       
   895                 {
       
   896                 index = 0;
       
   897                 }
       
   898             iPredictiveWnd->HidePopup();
       
   899             iCandidateWnd->ShowPopupL(iCandidateArray, index);
       
   900             // capture of candidate control removed. Trensitory Input Exists, then the capture flag should be on.
       
   901             //signal the owner that pointer needs be captured
       
   902                 {
       
   903                 TBool capture = ETrue;
       
   904                 TPtrC data;
       
   905                 data.Set((const TUint16 *)&capture,sizeof(TBool)/sizeof(TUint16));
       
   906                 iUiLayout->LayoutOwner()->SignalOwner(ESignalCapturePointer,data);
       
   907                 }
       
   908             }
       
   909         else
       
   910             {
       
   911             iCandidateWnd->HidePopup();
       
   912             iPredictiveWnd->ShowPopupL(iCandidateArray, index);
       
   913             }
       
   914         }
       
   915     else
       
   916         {
       
   917         iPredictiveWnd->HidePopup();
       
   918         iCandidateWnd->HidePopup();
       
   919         }
       
   920     }
       
   921 
       
   922 // ---------------------------------------------------------
       
   923 // Cancel Transitory Input
       
   924 // ---------------------------------------------------------
       
   925 void CPeninputHiraganaKanji::CancelL()
       
   926     {
       
   927     iStatus = EStatusInitial;
       
   928     iInputContextField->CancelInlineL();
       
   929     }
       
   930 
       
   931 // End Of File