fep/aknfep/src/aknfepinputstatespellingpinyinphrasecreation.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     1 /*
       
     2 * Copyright (c) 2004 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:           
       
    15 *       Provides the CAknFepUIInputStatePinyinPhrase methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 #include <PtiEngine.h>                          //CPtiEngine
       
    30 #include <PtiDefs.h>                            //keys
       
    31 #include <avkon.rsg>
       
    32 #include <aknfep.rsg>
       
    33 #include <aknnotewrappers.h>
       
    34 
       
    35 #include "AknFepPanic.h"
       
    36 #include "aknfepinputstatespellingpinyinphrasecreation.h"
       
    37 #include "AknFepUIManagerStateInterface.h"      //MAknFepUIManagerStateInterface
       
    38 #include "AknFepManagerUIInterface.h"           //MAknFepManagerUIInterface
       
    39 #include "AknFepUiCtrlContainerChinese.h"
       
    40 #include "AknFepUICtrlInputPane.h"
       
    41 #include "AknFepUICtrlCandidatePane.h"
       
    42 #include "AknFepUICtrlPinyinPopup.h"		//Pinyin phrase
       
    43 #include "aknfepuictrleditpane.h"           //pinyin phrase creation
       
    44 #include "AknFepManager.h"
       
    45 
       
    46 const TUint16 KDelimiter =0x0027;
       
    47 const TInt KMaxPhraseCreationCount = 7;
       
    48 const TInt KMaxSpellingLength = 10;
       
    49 
       
    50 // ---------------------------------------------------------
       
    51 // C++ construct.
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 TAknFepInputStateSpellingPinyinPhraseCreation::TAknFepInputStateSpellingPinyinPhraseCreation(
       
    55                                 MAknFepUIManagerStateInterface* aOwner,
       
    56                                 MAknFepUICtrlContainerChinese* aUIContainer)
       
    57     :TAknFepInputStatePinyinPhraseCreationBase( aOwner, aUIContainer )
       
    58     {
       
    59     iState = ESpellingSelection;
       
    60 
       
    61     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
    62     uiContainer->FocusCandidatePane(EFalse);
       
    63     uiContainer->CandidatePane()->ShowCandidateOrdinals(EFalse);
       
    64     uiContainer->SetLayout(MAknFepUICtrlContainerChinese::ELayoutPhraseCreation);
       
    65     uiContainer->CandidatePane()->SelectFirstPhrase(); 
       
    66     uiContainer->ShowVerticalScrollArrows(ETrue);
       
    67     uiContainer->ShowHorizontalScrollArrows(EFalse);
       
    68     uiContainer->InputPane()->SetOverrideFontId(0);
       
    69     uiContainer->SetFepMan( iOwner->FepMan() );
       
    70     uiContainer->EditPaneWindow()->DeactiveCursor();
       
    71     
       
    72     // in the case that we are coming back to the input pane from the candidate pane, 
       
    73     // we need to ensure that the current selection is selected correctly
       
    74     if ( uiContainer->PinyinPopupWindow()->GetFromEditToSpellingFlag() )
       
    75         {
       
    76         TInt validCount = uiContainer-> 
       
    77             PinyinPopupWindow()->InEffectKeystrokeArray()->Count();
       
    78         TInt chineseCount = uiContainer-> 
       
    79             PinyinPopupWindow()->ChooseChineseCharacterArray()->Count();
       
    80         TInt index = 0;
       
    81         if ( !uiContainer->PinyinPopupWindow()->GetPhraseCreationEditingState() )
       
    82             {
       
    83             index = uiContainer->PinyinPopupWindow()->CurrentSelection();
       
    84             }        
       
    85         uiContainer->EditPaneWindow()->SetCursorIndexOfKeystroke( validCount );
       
    86         ShowInfo();
       
    87         uiContainer->EditPaneWindow()->
       
    88             SetUnderline( chineseCount, chineseCount + validCount - 1 );
       
    89         uiContainer->InputPane()->SetText( uiContainer->
       
    90             PinyinPopupWindow()->PhoneticSpellingArray()->MdcaPoint( index ) );
       
    91         uiContainer->PinyinPopupWindow()->SetFromEditToSpellingFlag();
       
    92         uiContainer->PinyinPopupWindow()->SplitPhraseSpellingIntoPages();
       
    93         uiContainer->PinyinPopupWindow()->SetDisplayPage( index );
       
    94         uiContainer->PinyinPopupWindow()->SetPhraseItemTexts();
       
    95         uiContainer->PinyinPopupWindow()->PopupSizeChanged(); // phrase input
       
    96         uiContainer->PinyinPopupWindow()->Enable( ETrue );
       
    97         }
       
    98     else
       
    99         {
       
   100         ImplicityShowInfo( ETrue );
       
   101         }
       
   102     
       
   103     ChangeCba();
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------
       
   107 // HandleKeyL
       
   108 // ---------------------------------------------------------
       
   109 //
       
   110 TBool TAknFepInputStateSpellingPinyinPhraseCreation::HandleKeyL(
       
   111                                  TInt aKey, 
       
   112                                  TKeyPressLength aLength )
       
   113     {
       
   114     switch( aKey )
       
   115         {
       
   116         case EKeyBackspace:
       
   117         case EKeyUpArrow:
       
   118             HandleKeyBackspaceOrKeyUpArrow( aLength );
       
   119             break;
       
   120         case EKeyRightArrow:
       
   121             HandleKeyRightArrow();
       
   122             break;
       
   123         case EKeyLeftArrow:
       
   124             HandleKeyLeftArrow();
       
   125             break;
       
   126         case EKeyOK:
       
   127         case EKeyDownArrow:
       
   128         case EKeyCBA1:    
       
   129              HandleKeyOKOrKeyDownArrowOrKeyCBA1( aLength );
       
   130             break;
       
   131         case EKeyCBA2:
       
   132             iOwner->FepMan()->TryCloseUiL();
       
   133             break;
       
   134         default:
       
   135             iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   136             break;
       
   137         }
       
   138         return ETrue;
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------
       
   142 // Initialize state
       
   143 // ---------------------------------------------------------
       
   144 //
       
   145 void TAknFepInputStateSpellingPinyinPhraseCreation::InitializeStateL(void)
       
   146     {
       
   147     iOwner->FepMan()->UpdateCbaL(R_AKNFEP_SOFTKEYS_PHRASE_CREATION_SELECT_CANCEL_SELECT);
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------
       
   151 // Implicity the show info
       
   152 // ---------------------------------------------------------
       
   153 //
       
   154 void TAknFepInputStateSpellingPinyinPhraseCreation::ImplicityShowInfo( 
       
   155                                                  TBool aGetScreenCoordinates )
       
   156     {
       
   157     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   158     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   159     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   160     CDesCArrayFlat* validKeystroke = popup->InEffectKeystrokeArray();
       
   161     TInt chineseCount = popup->ChooseChineseCharacterArray()->Count();
       
   162     TInt selection(0);
       
   163     // get cursor position
       
   164     TPoint baseLine = TPoint(0,0);
       
   165     TInt height = 0;
       
   166     TInt ascent = 0;
       
   167     if ( aGetScreenCoordinates )
       
   168         {
       
   169         TRAPD(ret,iOwner->FepMan()->GetScreenCoordinatesL(baseLine,height,ascent));
       
   170         if (ret == KErrNone)
       
   171             {
       
   172             uiContainer->SetContainerPosition(baseLine, height);    
       
   173             }
       
   174         }
       
   175     if ( popup->GetPhraseCreationState() )
       
   176         {
       
   177         GetValidKeystroke();
       
   178         editPane->SetCursorIndexOfKeystroke( validKeystroke->Count() );
       
   179         }
       
   180     else
       
   181         {
       
   182         editPane->SetCursorIndexOfKeystroke( validKeystroke->Count() );
       
   183         }
       
   184     
       
   185     ShowInfo();
       
   186     editPane->SetUnderline( chineseCount, chineseCount + 
       
   187         validKeystroke->Count() - 1 );
       
   188     if ( popup->GetPhraseCreationState() )
       
   189         {
       
   190         ClearDeliberateSelection();        
       
   191         }
       
   192     else
       
   193         {
       
   194         selection = popup->CurrentSelection();
       
   195         }
       
   196     RefreshUI( selection );
       
   197     if ( popup->GetPhraseCreationState() )
       
   198         {
       
   199         popup->SetPhraseCreationState( EFalse );
       
   200         }
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------
       
   204 // Refresh the show info
       
   205 // ---------------------------------------------------------
       
   206 //
       
   207 void TAknFepInputStateSpellingPinyinPhraseCreation::RefreshShowInfo()
       
   208     {
       
   209     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   210     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   211     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   212     MAknFepUICtrlInputPane* inputPane = uiContainer->InputPane();
       
   213     CDesCArrayFlat* validKeystroke = popup->InEffectKeystrokeArray();
       
   214     CDesCArrayFlat* spelling = popup->PhoneticSpellingArray();
       
   215     CDesCArrayFlat* candidateArray = 
       
   216         uiContainer->CandidatePane()->CandidateArray();
       
   217     TInt selection = popup->CurrentSelection();
       
   218     TInt chineseCount = popup->ChooseChineseCharacterArray()->Count();
       
   219     TPtr deliberateSelection = iOwner->GetLatestDeliberateSelection();
       
   220     
       
   221     editPane->SetCursorIndexOfKeystroke( validKeystroke->Count() );
       
   222     ShowInfo();
       
   223     editPane->SetUnderline( chineseCount, chineseCount + 
       
   224         validKeystroke->Count() - 1 );
       
   225     inputPane->SetText( spelling->MdcaPoint( selection ) );
       
   226     deliberateSelection = spelling->MdcaPoint( selection );
       
   227     
       
   228     popup->SplitPhraseSpellingIntoPages();
       
   229     popup->SetDisplayPage(selection);
       
   230     popup->SetPhraseItemTexts();
       
   231     popup->PopupSizeChanged();
       
   232     popup->Enable( validKeystroke->Count() );
       
   233     GetCandidate( selection );
       
   234     uiContainer->CandidatePane()->SplitPhraseCandidatesIntoPages();
       
   235     uiContainer->CandidatePane()->SetCandidateBuffer();
       
   236     uiContainer->Enable( ETrue );
       
   237     uiContainer->ShowHorizontalScrollArrows( EFalse );
       
   238     uiContainer->ShowVerticalScrollArrows( ETrue );
       
   239     UpdateIndicator();
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------
       
   243 // KeyBackspace Or KeyUpArrow
       
   244 // ---------------------------------------------------------
       
   245 //
       
   246 void TAknFepInputStateSpellingPinyinPhraseCreation::HandleKeyBackspaceOrKeyUpArrow( 
       
   247     TKeyPressLength aLength )
       
   248     {
       
   249     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   250     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   251     
       
   252     TBool state = ETrue;
       
   253     if ( popup->IsChangeStatet() && aLength == ELongKeyPress )
       
   254         {
       
   255         state = EFalse;
       
   256         }
       
   257     else
       
   258         {
       
   259         popup->SetChangeState( EFalse );
       
   260         }
       
   261     if ( state )
       
   262         {
       
   263         popup->SetChangeState( ETrue );
       
   264         //change state to EKeySequenceEdit
       
   265         popup->SetFromEditToSpellingFlag( ETrue );
       
   266         iOwner->ChangeState( EKeySequenceEdit );
       
   267         }
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------
       
   271 // KeyOK Or KeyDownArrow Or KeyCBA1
       
   272 // ---------------------------------------------------------
       
   273 //
       
   274 void TAknFepInputStateSpellingPinyinPhraseCreation::HandleKeyOKOrKeyDownArrowOrKeyCBA1( 
       
   275     TKeyPressLength aLength )
       
   276     {
       
   277     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   278     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   279     TBool state = ETrue;
       
   280     if ( popup->IsChangeStatet() && aLength == ELongKeyPress )
       
   281         {
       
   282         state = EFalse;
       
   283         }
       
   284     else
       
   285         {
       
   286         popup->SetChangeState( EFalse );
       
   287         }
       
   288 
       
   289     TBool changeState = ( popup->ChooseChineseCharacterArray()->Count() != 
       
   290         KMaxPhraseCreationCount ) && ( popup->KeystrokeArray()->Count() != 0 );
       
   291     
       
   292     if ( changeState && state )
       
   293         {
       
   294         if(popup->IsEnabled())
       
   295             {
       
   296             popup->Enable(EFalse);
       
   297             }
       
   298         popup->SetChangeState( ETrue );
       
   299         iOwner->ChangeState(ECandidateSelection);     
       
   300         }
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------
       
   304 // KeyRightArrow
       
   305 // ---------------------------------------------------------
       
   306 //
       
   307 void TAknFepInputStateSpellingPinyinPhraseCreation::HandleKeyRightArrow()
       
   308     {
       
   309     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   310     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   311     TBuf<KMaxSpellingLength> spelling;
       
   312     popup->SetPhraseCreationState( EFalse );
       
   313     if( popup->SelectNextPhrase() )
       
   314         {
       
   315         if ( RefreshValidKeystroke() )
       
   316             {
       
   317             RefreshShowInfo();
       
   318             }
       
   319         else
       
   320             {
       
   321             iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   322             }
       
   323         }
       
   324     else
       
   325         {
       
   326         iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   327         }
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------
       
   331 // KeyRightArrow
       
   332 // ---------------------------------------------------------
       
   333 //
       
   334 void TAknFepInputStateSpellingPinyinPhraseCreation::HandleKeyLeftArrow()
       
   335     {
       
   336     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   337     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   338 
       
   339     if( popup->SelectPrevPhrase() )
       
   340         {
       
   341         if ( RefreshValidKeystroke() )
       
   342             {
       
   343             RefreshShowInfo();
       
   344             }
       
   345         else
       
   346             {
       
   347             iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   348             }
       
   349         }
       
   350     else
       
   351         {
       
   352         iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   353         }
       
   354     }
       
   355 
       
   356 // ---------------------------------------------------------
       
   357 // Refresh Valid Keystroke.
       
   358 // ---------------------------------------------------------
       
   359 //
       
   360 TBool TAknFepInputStateSpellingPinyinPhraseCreation::RefreshValidKeystroke()
       
   361     {
       
   362     TRAPD( ret, RefreshValidKeystrokeL() );
       
   363     if ( KErrNone != ret )
       
   364         {
       
   365         return EFalse;
       
   366         }
       
   367     return ETrue;
       
   368     }
       
   369 
       
   370 // ---------------------------------------------------------
       
   371 // Refresh Valid Keystroke.
       
   372 // ---------------------------------------------------------
       
   373 //
       
   374 void TAknFepInputStateSpellingPinyinPhraseCreation::RefreshValidKeystrokeL()
       
   375     {
       
   376     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   377     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   378     CDesCArrayFlat* validKeystroke = popup->InEffectKeystrokeArray();
       
   379     CDesCArrayFlat* keystroke = popup->ShowKeystrokeArray();
       
   380     CDesCArrayFlat* spelling = popup->PhoneticSpellingArray();    
       
   381     TInt selection = popup->CurrentSelection();
       
   382     validKeystroke->Reset();
       
   383     TInt spellLength = spelling->MdcaPoint( selection ).Length();
       
   384     
       
   385     for ( TInt i = 0; ( i < spellLength ) && ( spellLength <= 
       
   386         keystroke->Count() ); ++i )
       
   387         {
       
   388         validKeystroke->AppendL( keystroke->MdcaPoint( i ) );
       
   389         }
       
   390     
       
   391     if ( spellLength < keystroke->Count() )
       
   392         {
       
   393         if ( KDelimiter == keystroke->MdcaPoint( spellLength )[0] )
       
   394             {
       
   395             validKeystroke->AppendL( keystroke->MdcaPoint( spellLength ) );
       
   396             }
       
   397         }
       
   398     
       
   399     validKeystroke->Compress();
       
   400     }
       
   401 
       
   402 // End of file