fep/aknfep/src/AknFepUiInputStatePredictiveCandidateMiniQwertyChinesePhrase.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 15 Sep 2010 12:34:44 +0300
branchRCL_3
changeset 50 5a1685599b76
parent 0 eb1f2e154e89
child 56 8152b1f1763a
permissions -rw-r--r--
Revision: 201035 Kit: 201036

/*
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0""
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:            Implementation of Pinyin phrase predictive candidate MiniQwerty state
*
*/












// System includes
#include <PtiEngine.h>                      

// User includes
#include "AknFepUiInputStatePredictiveCandidateMiniQwertyChinesePhrase.h"
#include "AknFepUiCtrlContainerChinese.h"
#include "AknFepUIManagerStateInterface.h"  
#include "AknFepManagerUIInterface.h" 
#include "AknFepManager.h"      
#include "AknFepUICtrlCandidatePane.h"
#include "aknfepuictrleditpane.h"

// ---------------------------------------------------------------------------
// TAknFepInputStatePredictiveCandidateMiniQwertyChinesePhrase::
// TAknFepInputStatePredictiveCandidateMiniQwertyChinesePhrase
// (other items were commented in a header).
// ---------------------------------------------------------------------------
//
TAknFepInputStatePredictiveCandidateMiniQwertyChinesePhrase::
TAknFepInputStatePredictiveCandidateMiniQwertyChinesePhrase(
    MAknFepUIManagerStateInterface* aOwner,
    MAknFepUICtrlContainerChinese* aUIContainer)
    :TAknFepInputStatePredictiveInputQwertyChinesePhrase(aOwner, aUIContainer)
    {
    iState = EPredictiveCandidate;
    UIContainer()->CandidatePane()->ShowCandidateOrdinals(EFalse);
    }

// ---------------------------------------------------------------------------
// TAknFepInputStatePredictiveCandidateMiniQwertyChinesePhrase::HandleKeyL
// (other items were commented in a header).
// ---------------------------------------------------------------------------
//
TBool TAknFepInputStatePredictiveCandidateMiniQwertyChinesePhrase::HandleKeyL(
                                           TInt aKey, TKeyPressLength aLength)
    {
    TBool ret = ETrue;

    if(iOwner->IsValidChineseSymbol(aKey))
    	{
        iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
        ret = ETrue;
        }
    else if (iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagQwertyShiftMode) ||
        iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed)||
        iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagShiftKeyDepressed))
        {
        iOwner->FepMan()->TryCloseUiL();
        ret = EFalse;
        }
    else if ( CAknFepFnKeyManager::EFnKeyNext == iOwner->FepMan()->FnKeyState() ||
              CAknFepFnKeyManager::EFnKeyLock == iOwner->FepMan()->FnKeyState() ||
              CAknFepFnKeyManager::EFnKeyDown == iOwner->FepMan()->FnKeyState()) // for fn + a character
        {
    	iOwner->FepMan()->TryCloseUiL();
        ret = EFalse;
        }
   else if ( aKey ==EKeyLeftCtrl || aKey == EKeyRightCtrl)      
        {
        iOwner->FepMan()->TryCloseUiL();
        ret = EFalse;
        }
    else if (aKey == EStdKeyEnter)
        {
        iOwner->FepMan()->TryCloseUiL();
        ret = EFalse;
        }
    else if (aKey == EStdKeyBackspace) 
        {
    	iOwner->FepMan()->TryCloseUiL();
        }
    else if (aKey ==EKeyRightFunc)//fn key
    	{
    	iOwner->FepMan()->TryCloseUiL();
    	ret = EFalse;
    	}
    else if ( aKey ==EStdKeySpace)
    	{
    	if (ECangJie ==iOwner->FepMan()->InputMode())
    		{
    		TPtrC text = UIContainer()->CandidatePane()->CurrentPhraseCandidate();
	        if(text.Length())
	            {            
	            MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
	            fepMan->NewTextL(text);
	            fepMan->CommitInlineEditL();
	            iOwner->PtiEngine()->SetPredictiveChineseChar(text);
	            if (fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull))
	                {
	                fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
	                iOwner->FepMan()->TryCloseUiL();
	                }
	            else
	                {
	                iOwner->ChangeState(EPredictiveCandidate);
	                }
	            }
	        return ETrue;
    		}
    	else 
    		{
             iOwner->FepMan()->TryCloseUiL();
             ret = EFalse; 
    		}
    	}	    
   else if ( aKey == EStdKeyDevice0 || aKey == EStdKeyDevice3 ) // Add for SK1 and selection 
        {
        TBool state = ETrue;
        if ( UIContainer()->EditPaneWindow()->IsChangeState() && aLength == ELongKeyPress )
            {
            state = EFalse;
            }
        else
            {
            UIContainer()->EditPaneWindow()->SetChangeState( EFalse );
            }
        if ( state )
            {
            TPtrC text = UIContainer()->CandidatePane()->CurrentPhraseCandidate();
            if(text.Length())
                {            
                MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
                fepMan->NewTextL(text);
                fepMan->CommitInlineEditL();
                iOwner->PtiEngine()->SetPredictiveChineseChar(text);
                
                // For sogou core, the predictive is not endless, so when there
                // is no predictive candidates, we should call TryCloseUiL().
                TBool noCandidates = EFalse;
                
                if ( iPlugin.IsEnable() || iStrokePlugin.IsEnable())
                    {
                    // Get the predictive candidates.
                    CDesCArrayFlat* phraseCandidates = new(ELeave) CDesCArrayFlat(1);
                    CleanupStack::PushL ( phraseCandidates );
                    phraseCandidates->Reset();
                    iOwner->PtiEngine()->GetChinesePhraseCandidatesL( *phraseCandidates );
                    if ( phraseCandidates->Count() == 0 )
                        {
                        noCandidates = ETrue;
                        }
                    CleanupStack::PopAndDestroy( phraseCandidates );
                    }
                
                // If no candidates, call TryCloseUiL().
                if ( fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull) || noCandidates )
                    {
                    fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
                    iOwner->FepMan()->TryCloseUiL();
                    }
                else
                    {
                    iOwner->ChangeState(EPredictiveCandidate);
                    }           
                }
            }
        }
    else if(aKey == EStdKeyRightArrow )
        {
    	UIContainer()->CandidatePane()->SelectNext(); 
        }
    else if (aKey == EStdKeyLeftArrow)  
    	{
        UIContainer()->CandidatePane()->SelectPrev();
    	}    
    else if(iOwner->IsValidChineseInputKeyQwerty(aKey))
        {
        if ( aLength == ELongKeyPress )
            {
            return ETrue;
            }
        
        if(EPinyin ==iOwner->FepMan()->InputMode())
    		{
			CPtiEngine* ptiengine = iOwner->PtiEngine();
			// it is needed when we use phrase input engine, otherwise it seems not cleared
    		ptiengine->ClearCurrentWord(); 
			ptiengine->ResetToneMark();

			iOwner->ChangeState(EEntry);
			ret = EFalse; //passes to entry state to handle the key
    		}
    	else if(EZhuyin  ==iOwner->FepMan()->InputMode() || 
    	        ECangJie ==iOwner->FepMan()->InputMode() ||
    	        EStroke  ==iOwner->FepMan()->InputMode() )	
    		{
    	 	CPtiEngine* ptiengine = iOwner->PtiEngine();
			// it is needed when we use phrase input engine, otherwise it seems not cleared
        	ptiengine->ClearCurrentWord(); 
			ptiengine->ResetToneMark();

			iOwner->ChangeState(EEntry);
			ret = EFalse; //passes to entry state to handle the key
    		}

    	}
    else if(    aKey == EPtiKeyQwertyQ ||
    		    aKey == EPtiKeyQwertyW ||
    		    aKey == EPtiKeyQwertyO ||
    		    aKey == EPtiKeyQwertyP ||
    		    aKey == EPtiKeyQwertyA ||
    		    aKey == EPtiKeyQwertyS ||
    		    aKey == EPtiKeyQwertyL ||
    		    aKey == EPtiKeyQwertyZ ||
    		    aKey == EPtiKeyQwertyX ||
    		    aKey == EPtiKeyQwertyC ||
    		    aKey == EPtiKeyQwertyV ||
    		    aKey == EPtiKeyQwertyB ||
    		    aKey == EPtiKeyQwertyN ||
    		    aKey == EPtiKeyQwertyM )
    	{
    	 if(EStroke ==iOwner->FepMan()->InputMode())
    	 	{
    	 	iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
    		//iOwner->FepMan()->TryCloseUiL();
    	 	}	
    	}
    else
    {
    ret = TAknFepInputStateCandidateQwertyBaseChinesePhrase::HandleKeyL(aKey, aLength);
    }        		    
      
    return ret;
 }

// ---------------------------------------------------------------------------
// TAknFepInputStatePredictiveCandidateMiniQwertyChinesePhrase::HandleCommandL
// Handling Command
// ---------------------------------------------------------------------------
//
void TAknFepInputStatePredictiveCandidateMiniQwertyChinesePhrase::HandleCommandL(
    TInt aCommandId )
    {
    TBool state = ETrue;
    switch ( aCommandId )
        {
        // Handle the event frome command.
        case EAknSoftkeySelect:
            // case (TUint16)EAknSoftkeySelect: //the Selected in soft CBA
            if ( UIContainer()->EditPaneWindow()->IsChangeState( ) )
                {
                state = EFalse;
                }
            else
                {
                UIContainer()->EditPaneWindow()->SetChangeState( EFalse );
                }
            if ( state )
                {
                TPtrC text = UIContainer()->CandidatePane()->CurrentPhraseCandidate( );
                if ( text.Length( ) )
                    {
                    MAknFepManagerUIInterface* fepMan = iOwner->FepMan( );
                    fepMan->NewTextL( text );
                    fepMan->CommitInlineEditL( );
                    iOwner->PtiEngine()->SetPredictiveChineseChar( text );
                    if ( fepMan->IsFlagSet( CAknFepManager::EFlagEditorFull ) )
                        {
                        fepMan->ClearFlag( CAknFepManager::EFlagEditorFull );
                        iOwner->FepMan()->TryCloseUiL( );
                        }
                    else
                        {
                        iOwner->ChangeState( EPredictiveCandidate );
                        }
                    }
                }
            break;
        default:
            TAknFepInputStateChineseBase::HandleCommandL( aCommandId );
            break;
        }
    }
void TAknFepInputStatePredictiveCandidateMiniQwertyChinesePhrase::SubmitTextL( const TDesC& aText )
	{
	if( aText.Length())
	    {            
	    MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
	    CPtiEngine* engine = iOwner->PtiEngine();
	    fepMan->NewTextL(aText);
	    fepMan->CommitInlineEditL();
	    engine->SetPredictiveChineseChar(aText);
	                    
        // For sogou core, the predictive is not endless, so when there
        // is no predictive candidates, we should call TryCloseUiL().
        TBool noCandidates = EFalse;
        
        if ( iPlugin.IsEnable() || iStrokePlugin.IsEnable())
            {
            // Get the predictive candidates.
            CDesCArrayFlat* phraseCandidates = new(ELeave) CDesCArrayFlat(1);
            CleanupStack::PushL ( phraseCandidates );
            phraseCandidates->Reset();
            iOwner->PtiEngine()->GetChinesePhraseCandidatesL( *phraseCandidates );
            if ( phraseCandidates->Count() == 0 )
                {
                noCandidates = ETrue;
                }
            CleanupStack::PopAndDestroy( phraseCandidates );
            }
	    
	    if (fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull) || noCandidates )
	       {
	        fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
	        fepMan->TryCloseUiL();
	        }
	    else
	        {
	    if( iOwner )
	    	{
	        iOwner->ChangeState(EPredictiveCandidate);
	    	}
	        }           
	    }
	}

// End of file