fep/aknfep/src/AknFepUiInputStateCandidateRetroActive.cpp
changeset 36 a7632c26d895
parent 35 0f326f2e628e
child 42 b3eaa440ab06
equal deleted inserted replaced
35:0f326f2e628e 36:a7632c26d895
     1 /*
       
     2 * Copyright (c) 2002-2006 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:            Provides the TAknFepUiInputStateCandidateRetroActive methods.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 // INCLUDE FILES
       
    30 
       
    31 
       
    32 #include "AknFepUiInputStateCandidateRetroActive.h"
       
    33 #include "AknFepUIManagerStateInterface.h"   // MAknFepUIManagerStateInterface
       
    34 #include "AknFepManagerUIInterface.h"        // MAknFepManagerUIInterface
       
    35 #include "AknFepUICtrlContainerJapanese.h"   // MAknFepUICtrlContainerJapanese
       
    36 #include "AknFepUICtrlCandidatePaneInterface.h"
       
    37                                         // MAknFepUICtrlCandidatePaneInterface
       
    38 #include "AknFepGlobalEnums.h"
       
    39 #include "AknFepPanic.h"
       
    40 
       
    41 #include <PtiDefs.h>                    // keys
       
    42 #include <PtiEngine.h>
       
    43 #include <PtiCompositionDataIF.h>       // MPtiEngineCompositionDataInterfac
       
    44 #include <avkon.rsg>
       
    45 #include <aknfep.rsg>
       
    46 
       
    47 
       
    48 // CONSTANTS
       
    49 
       
    50 /**
       
    51  *  TAknFepUiInputStateCandidateRetroActive class.
       
    52  *
       
    53  */
       
    54 //============================ MEMBER FUNCTIONS ==============================
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // TAknFepUiInputStateCandidateRetroActive::
       
    58 //                                  TAknFepUiInputStateCandidateRetroActive
       
    59 // C++ default Constructor
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 TAknFepUiInputStateCandidateRetroActive::TAknFepUiInputStateCandidateRetroActive(
       
    63                                     MAknFepUIManagerStateInterface* aOwner,
       
    64                                     MAknFepUICtrlContainerJapanese* aUIContainer)
       
    65 
       
    66     :TAknFepUiInputStateEntryJapaneseMultitap(aOwner, aUIContainer)
       
    67     {
       
    68     iState = ECandidateRetroActive;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // TAknFepUiInputStateInitialJapaneseBase::InitializeStateL
       
    73 // Initialize State
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void TAknFepUiInputStateCandidateRetroActive::InitializeStateL()
       
    77     {
       
    78     iOwner->SetInlineEditUnderlineVisibility(ETrue);
       
    79 
       
    80     ShowListL(EAknFepSoftkeyRetroActiveHalf);
       
    81     iData = EAknFepSoftkeyRetroActiveHalf;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // TAknFepUiInputStateCandidateRetroActive::CloseUI
       
    86 // Closing UI
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void TAknFepUiInputStateCandidateRetroActive::CloseUI()
       
    90     {
       
    91     // commit the current item
       
    92     TRAP_IGNORE(DoCommitItemL());
       
    93     // Move the status to EInitial.
       
    94     iOwner->PtiEngine()->ClearCurrentWord();
       
    95     iOwner->ChangeState(EInitial);
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // TAknFepUiInputStateCandidateRetroActive::HandleNumericKeyL
       
   100 // Handling short keypress events of the numeric and the star
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 TBool TAknFepUiInputStateCandidateRetroActive::HandleNumericShortKeyL(TInt /*aKey*/)
       
   104     {
       
   105     // This state doesn't handle numeric key.
       
   106     // commit the current item
       
   107     DoCommitItemL();
       
   108     // Move the status to EInitial.
       
   109     iOwner->PtiEngine()->ClearCurrentWord();
       
   110     iOwner->ChangeState(EInitial);
       
   111     // Return EFalse, because of going through the event
       
   112     return EFalse;
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // TAknFepUiInputStateCandidateRetroActive::HandleNaviKeyL
       
   117 // Handling Navigate keypress event
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 TBool TAknFepUiInputStateCandidateRetroActive::HandleNaviKeyL(TInt aKey,
       
   121                                                                 TKeyPressLength /*aLength*/)
       
   122     {
       
   123     TBool ret = EFalse;
       
   124     MAknFepUICtrlCandidatePaneInterface* candidatePane =
       
   125         UIContainer()->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   126                                      EJapaneseCandidatePane);
       
   127     TAknFepUICtrlScroll direction = EScrollNone;
       
   128 
       
   129     switch(aKey)
       
   130         {
       
   131         case EKeyDownArrow:
       
   132         case EKeyUpArrow:
       
   133         case EStdKeyDownArrow:      /* 0x11 */
       
   134         case EStdKeyUpArrow:        /* 0x10 */
       
   135         case EStdKeySpace:
       
   136             { // The highlight of candidate is moved up/down
       
   137             direction = EScrollDown;
       
   138             if (aKey == EKeyUpArrow || aKey == EStdKeyUpArrow)
       
   139                 {
       
   140                 direction = EScrollUp;
       
   141                 }
       
   142 
       
   143             candidatePane->MoveItem(direction);
       
   144             ret = ETrue;
       
   145             }
       
   146             break;
       
   147         case EKeyLeftArrow:
       
   148         case EKeyRightArrow:
       
   149         case EStdKeyLeftArrow:      /* 0x0e */
       
   150         case EStdKeyRightArrow:     /* 0x0f */
       
   151             ret = ETrue;
       
   152             break;
       
   153         default:
       
   154             break;
       
   155         }
       
   156 
       
   157     return ret;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // TAknFepUiInputStateCandidateRetroActive::HandleAuxKeyL
       
   162 // Handling auxiliary keypress events including OK and Backspace
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 TBool TAknFepUiInputStateCandidateRetroActive::HandleAuxKeyL(TInt aKey,
       
   166                                                                TKeyPressLength /*aLength*/)
       
   167     {
       
   168     TBool ret = EFalse;
       
   169     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   170     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   171     MAknFepUICtrlCandidatePaneInterface* candidatePane =
       
   172         UIContainer()->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   173                                      EJapaneseCandidatePane);
       
   174     TInt currentIdex = candidatePane->CurrentItemIndexOfCandidate();
       
   175     candidatePane->HideWindow();
       
   176     switch(aKey)
       
   177         {
       
   178         case EKeyOK:
       
   179         case EStdKeyDevice3:        /* 0xA7 */
       
   180         case EStdKeyEnter:          /* 0x03 */
       
   181         case EStdKeyNkpEnter:       /* 0x88 */
       
   182             {
       
   183             DoSelectItemL();
       
   184             ret = ETrue;
       
   185             }
       
   186             break;
       
   187         case EKeyBackspace:
       
   188         case EStdKeyBackspace:      /* 0x01 */
       
   189         case EStdKeyEscape:         /* 0x04 */
       
   190             {
       
   191             fepMan->SetInlineEditingCursorVisibilityL(ETrue);
       
   192             ptiEngine->HandleCommandL(EPtiCommandUserActionCancel);
       
   193             iOwner->SetInlineEditUnderlineVisibility(ETrue);
       
   194 
       
   195             if(iOwner->IsPredictive())
       
   196                 {
       
   197                 iOwner->ChangeState(EPredictiveInput);
       
   198                 ShowPredictiveListL();
       
   199                 }
       
   200             else
       
   201                 {
       
   202                 UpdateInlineEditingCharacterL();
       
   203                 iOwner->ChangeState(EEntry);
       
   204                 }
       
   205             ret = ETrue;
       
   206             }
       
   207             break;
       
   208       default: // Panic
       
   209             {
       
   210             AknFepPanic(EAknFepPanicNotSupportKey);
       
   211             }
       
   212             break;
       
   213         }
       
   214     return ret;
       
   215     }
       
   216 
       
   217 void TAknFepUiInputStateCandidateRetroActive::HandleCommandL(TInt aCommandId)
       
   218     {
       
   219     // Close current popup window
       
   220     MAknFepUICtrlCandidatePaneInterface*
       
   221         candidatePane = UIContainer()->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   222                                                      EJapaneseCandidatePane);
       
   223     switch (aCommandId)
       
   224         {
       
   225         case EAknFepSoftkeyCommit:
       
   226             candidatePane->HideWindow();
       
   227             DoSelectItemL();
       
   228             break;
       
   229         case EAknFepSoftkeyRetroActiveHalf:
       
   230         case EAknFepSoftkeyRetroActiveFull:
       
   231             {
       
   232             candidatePane->HideWindow();
       
   233             // Change from half to full or from full to half
       
   234             ShowListL(aCommandId);
       
   235             iData = aCommandId;
       
   236             }
       
   237             break;
       
   238         case EAknFepResourceChanged:
       
   239             {
       
   240             TInt currentIdex = candidatePane->CurrentItemIndexOfCandidate();
       
   241             candidatePane->HideWindow();
       
   242             // Change from half to full or from full to half
       
   243             ShowListL(iData, currentIdex);
       
   244             break;
       
   245             }
       
   246         default:
       
   247             // Go through the event to base class.
       
   248             TAknFepUiInputStateEntryJapaneseMultitap::HandleCommandL(aCommandId);
       
   249             break;
       
   250         }
       
   251     }
       
   252 
       
   253 void TAknFepUiInputStateCandidateRetroActive::ShowListL(TInt aCommandId, TInt aIndex /*=0*/)
       
   254     {
       
   255     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   256     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   257     CDesCArrayFlat* candidateArray = iOwner->CandidateArray();
       
   258     MAknFepUICtrlCandidatePaneInterface*
       
   259         candidatePane = UIContainer()->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   260                                                      EJapaneseCandidatePane);
       
   261     const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
   262     // Check ComposirionData
       
   263     __ASSERT_DEBUG( data->CompletedString().Length() < 0,
       
   264         RDebug::Print(
       
   265            _L("In TAknFepUiInputStateCandidateRetroActive::TAknFepUiInputStateCandidateRetroActive INVALID DATA: ConvertingString!")));
       
   266 
       
   267     // Get coordinate of input area
       
   268     TPoint  leftSideOfBaseLine;
       
   269     TInt    height;
       
   270     TInt    ascent;
       
   271     TInt    documentOffset = data->CursorPosition();
       
   272     fepMan->GetScreenCoordinatesL(leftSideOfBaseLine, height, ascent, documentOffset);
       
   273 
       
   274     // Decide either half or full
       
   275     TPtiEngineCommand command = EPtiCommandUserActionRetroActiveCandidateHalf;
       
   276     TInt resId = R_AKNFEP_SOFTKEYS_RETROACTIVE_FULL_WIDTH;
       
   277     if (aCommandId == EAknFepSoftkeyRetroActiveFull)
       
   278         {
       
   279         command = EPtiCommandUserActionRetroActiveCandidateFull;
       
   280         resId = R_AKNFEP_SOFTKEYS_RETROACTIVE_HALF_WIDTH;
       
   281         }
       
   282 
       
   283     // Get the showing candidates
       
   284     ptiEngine->HandleCommandL(command, (TAny*)candidateArray);
       
   285     if (candidateArray->Count() > 0)
       
   286         {
       
   287         // Show the retroactive popup
       
   288         candidatePane->SetWindowPosition(leftSideOfBaseLine, height, ascent);
       
   289         candidatePane->ShowCandidateListL(candidateArray, aIndex, resId);
       
   290         }
       
   291     else
       
   292         {
       
   293         // return to Entry state
       
   294         iOwner->ChangeState(EEntry);
       
   295         }
       
   296     }
       
   297 
       
   298 void TAknFepUiInputStateCandidateRetroActive::ShowPredictiveListL()
       
   299     {
       
   300     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   301     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   302     // normal operation
       
   303     if (UpdateInlineEditingCharacterL())
       
   304         {
       
   305         // Get the candidate array object
       
   306         CDesCArrayFlat* candidateArray = iOwner->CandidateArray();
       
   307         // Set the candidates to array on PtiEngine
       
   308         ptiEngine->GetCandidateListL(*candidateArray);
       
   309 
       
   310         MAknFepUICtrlCandidatePaneInterface* predictivePane =
       
   311             UIContainer()->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   312                                        EJapanesePredictiveCandidatePane);
       
   313         const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
   314         // Get coordinate of input area
       
   315         TPoint  leftSideOfBaseLine;
       
   316         TInt    height;
       
   317         TInt    ascent;
       
   318         TInt    documentOffset = data->CursorPosition() > 0 ? data->CursorPosition() : 0;
       
   319 
       
   320         fepMan->GetScreenCoordinatesL(leftSideOfBaseLine,
       
   321                                       height,
       
   322                                       ascent,
       
   323                                       documentOffset);
       
   324         // show candidate pop-up list
       
   325         predictivePane->SetWindowPosition(leftSideOfBaseLine, height, ascent);
       
   326         predictivePane->ShowCandidateListL(candidateArray, 0, iCbaResourceID);
       
   327         }
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // TAknFepUiInputStateCandidateRetroActive::DoSelectItemL
       
   332 // Select a current item, and commit it.
       
   333 // ---------------------------------------------------------------------------
       
   334 //
       
   335 void TAknFepUiInputStateCandidateRetroActive::DoSelectItemL()
       
   336     {
       
   337     // commit the current item
       
   338     DoCommitItemL();
       
   339     if (iOwner->FepMan()->EditorHasFreeSpace()
       
   340      && iOwner->IsPredictive())
       
   341         {
       
   342         iOwner->ChangeState(ENextWord);
       
   343         }
       
   344     else
       
   345         {
       
   346         iOwner->PtiEngine()->ClearCurrentWord();
       
   347         iOwner->ChangeState(EInitial);
       
   348         }
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // TAknFepUiInputStateCandidateRetroActive::DoCommitItemL
       
   353 // Commit a current item
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 void TAknFepUiInputStateCandidateRetroActive::DoCommitItemL()
       
   357     {
       
   358     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   359     CPtiEngine* ptiEngine = iOwner->PtiEngine();
       
   360     MAknFepUICtrlCandidatePaneInterface* candidatePane =
       
   361         UIContainer()->CandidatePane(MAknFepUICtrlContainerJapanese::
       
   362                                      EJapaneseCandidatePane);
       
   363     TInt currentIdex = candidatePane->CurrentItemIndexOfCandidate();
       
   364     candidatePane->HideWindow();
       
   365 
       
   366     iOwner->ChangeState(EMultiCompletion);
       
   367     CDesCArrayFlat* candidateArray = iOwner->CandidateArray();
       
   368     TPtrC ptr((*candidateArray)[currentIdex]);
       
   369     ptiEngine->HandleCommandL(EPtiCommandUserActionRetroActiveCommit, &ptr);
       
   370     const MPtiEngineCompositionDataInterface* data = ptiEngine->CompositionData();
       
   371     TPtrC text = data->CompletedString();
       
   372     if (text.Length() > 0)
       
   373         {
       
   374         fepMan->CommitInlineEditL(text, text.Length());
       
   375         }
       
   376     }
       
   377 
       
   378 // End of file