textinput/ptienginev2/inc/PtiEngineImpl.h
changeset 0 eb1f2e154e89
child 8 4eb1ae11334f
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2003-2008 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:   Predective text input engine implementation class header
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef _PTI_ENGINE_IMPL_H
       
    21 #define _PTI_ENGINE_IMPL_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <badesca.h> 
       
    26 #include "PtiDefs.h"
       
    27 #include "PtiObserver.h"
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class CPtiCore;
       
    31 class MPtiLanguage;
       
    32 class CPtiCoreLanguage;
       
    33 class CPtiUserDictionary;
       
    34 class MPtiUserDictionary;
       
    35 class MPtiEngineCompositionDataInterface;
       
    36 class MPtiUserDictionaryEntry;
       
    37 class CPtiEngine;
       
    38 class CPtiMappings;
       
    39 class MPtiHwrRecognizer;
       
    40 class CHwrRecognizer;
       
    41 class CPtiHwrRecognizer;
       
    42 class MPtiKeyMappings;
       
    43 const TInt KPtiMaxKeymappingsLength = 32;
       
    44 /**
       
    45 * CPtiEngineImpl class.
       
    46 * Implementation class for main PtiEngine API. See file PtiEngine.h for actual documentation.
       
    47 */
       
    48 NONSHARABLE_CLASS(CPtiEngineImpl) : public CBase
       
    49 	{
       
    50 	public:
       
    51 	    /**
       
    52 		* Two phase constructor.
       
    53 		*
       
    54 		* @param  aUseDefaultUserDictionary
       
    55 		* @return 
       
    56 		*/
       
    57 		static CPtiEngineImpl* NewL(CPtiEngine* aFrontEnd);		
       
    58 
       
    59 		/**
       
    60 		* Destructor.
       
    61 		*/
       
    62 		~CPtiEngineImpl();
       
    63 
       
    64         // The PtiEngine API.
       
    65         // See the description of corresponding method in PtiEngine.h
       
    66 		TInt ActivateLanguageL(TInt aEpocLanguageID, TPtiEngineInputMode aMode);
       
    67 		void CloseCurrentLanguageL();
       
    68 		IMPORT_C MPtiCoreInfo* CoreInfo(TPtiEngineInputMode aMode) const;
       
    69 		inline MPtiLanguage* CurrentLanguage();
       
    70 		MPtiLanguage* GetLanguage(TInt aCode) const;
       
    71 		TInt NumberOfCandidates();
       
    72 		TPtrC AppendKeyPress(TPtiKey aKey);
       
    73 		TPtrC DeleteKeyPress();
       
    74 		TInt AddCoreL(const TUid aCoreUid, TBool aUseDefaultUserDictionary);
       
    75 		TInt GetCandidateListL(CDesCArray& aList);
       
    76 		TInt GetNextWordCandidateListL(CDesCArray& aList);
       
    77 		TPtrC FirstCandidate();		
       
    78 		TPtrC NextCandidate();
       
    79 		TPtrC PreviousCandidate();
       
    80 		TInt SetInputMode(TPtiEngineInputMode aMode);
       
    81 		inline TPtiEngineInputMode InputMode() const;
       
    82 		TInt SetReordering(TBool aStatus);
       
    83 		TInt SetCurrentWord(TPtrC aWord);
       
    84 		inline TPtrC CurrentWord();
       
    85 		void ClearCurrentWord();
       
    86 		inline void SetCase(TPtiTextCase aCase);
       
    87 		inline TPtiTextCase Case() const;	
       
    88 		void GetAvailableLanguagesL(CArrayFix<TInt>* aResult);
       
    89 		void GetAvailableLanguagesL(RArray<TInt>& aResult);
       
    90 		inline TInt NumberOfLanguages() const;
       
    91 		TInt CreateUserDictionaryL(TDesC& aFileName, CDesCArrayFlat* aWords,
       
    92 		                           TPtiEngineInputMode aMode); 
       
    93 		MPtiUserDictionary* AttachUserDictionaryL(TDesC& aFileName);	
       
    94 		MPtiUserDictionary* AttachDefaultUserDictionaryL(TUid aCoreUid, TInt aSymbolClass);		
       
    95 		TInt DetachUserDictionary(TDesC& aFileName);
       
    96 		TInt DetachUserDictionary(TInt aId);
       
    97 		void GetLocalizedLanguageNameL(TInt aLangCode, TDes& aResult);
       
    98 		TInt CommitCurrentWord();
       
    99 		TInt CharConversion(TPtiCharConversion aType,
       
   100 		               TAny* aInput,
       
   101 		  			   TInt aInputLength,
       
   102 					   TAny* aOutput);
       
   103 		TUint32 AvailableCharConversions() const;
       
   104 		TInt SetExternalKeyMapL(TPtiEngineInputMode aMode,
       
   105 		                        TPtiKey aKey,
       
   106 						  	    TDesC& aKeyMap,
       
   107 								TPtiTextCase aCase);
       
   108 		inline TPtiKey LastEnteredKey() const;
       
   109 		inline TPtrC8 CurrentInputSequence() const;
       
   110 		TInt GetSpelling(TUint16 aInput, TDes& aOutput, TPtiSpelling aType);
       
   111 		TInt CancelTimerActivity();
       
   112 		TPtiKey CharacterToKey(TUint16 aChar);
       
   113 		TInt AddUserDictionaryEntry(MPtiUserDictionaryEntry& aEntry);
       
   114 		TInt AddUserDictionaryEntry(MPtiUserDictionaryEntry& aEntry, TInt aId);
       
   115 		TInt RemoveEntryFromUserDictionary(MPtiUserDictionaryEntry& aEntry);
       
   116 		TInt RemoveEntryFromUserDictionary(MPtiUserDictionaryEntry& aEntry, TInt aId);
       
   117 		TInt NumberOfEntriesInUserDictionary();
       
   118 		TInt GetUserDictionaryEntry(TInt aIndex, MPtiUserDictionaryEntry& aResult);
       
   119 		MPtiUserDictionary* DefaultUserDictionary(TPtiEngineInputMode aMode);
       
   120 		inline void SetObserver(MPtiObserver* aObserver);
       
   121 		inline MPtiObserver* Observer();
       
   122 		TInt HandleCommandL(TPtiEngineCommand aCommand, TAny* aParams);
       
   123 		TPtrC CandidatePage();
       
   124 		TBool NextCandidatePage();
       
   125 		TBool PreviousCandidatePage();
       
   126 		TBool MoreCandidatePages();
       
   127 		void SetCandidatePageLength(TInt aLength);
       
   128 	    TPtrC GetPhoneticSpelling(TInt aIndex) const; 
       
   129 		TInt PhoneticSpellingCount() const;	
       
   130 	    TBool SelectPhoneticSpelling(TInt aIndex);
       
   131 	    TInt SelectedPhoneticSpelling() const; 
       
   132 		void EnableToneMarks(TBool aValue);
       
   133 		void ResetToneMark();
       
   134 		TBool ToneMark(TText& aToneMark) const;
       
   135 		TBool IsToneMarkValidForSpelling() const;
       
   136 		TBool IncrementToneMark(TBool aOverrideInvalid);
       
   137 		TBool SetPredictiveChineseChar(const TDesC& aChar);
       
   138 		MPtiEngineCompositionDataInterface* CompositionData();
       
   139 		TPtrC ReadingTextL();
       
   140 		void GetModeNameIndexL(TPtiChineseVariant aVariant, RArray<TInt>& aResult);
       
   141 		TInt GetPhoneticSpellingsL(CDesCArray& aList);
       
   142 		TInt GetChinesePhraseCandidatesL(CDesCArray& aList);
       
   143 		TBool SetToneMark(TInt aToneMark);	
       
   144 		void CreateDefaultUserDictionaryFileL(TUid aCoreUid, TInt aSymbolClass);					
       
   145 		void WriteSecondaryDataFileL(TUid aCoreUid, TInt aIndexNumber, HBufC8* aData);		
       
   146 		HBufC8* ReadSecondaryDataFileL(TUid aCoreUid, TInt aIndexNumber);			
       
   147 		void MappingDataForKey(TPtiKey aKey, TDes& aResult, TPtiTextCase aCase);		
       
   148 		void GetNumericModeKeysForQwertyL(TInt aLanguage, RArray<TPtiNumericKeyBinding>& aResult);                        								
       
   149     IMPORT_C HBufC* GetCandidatesByInputString(const TDesC& aInputString, 
       
   150                                                 RPointerArray<HBufC>& aList, 
       
   151                                                 const TBool aIsPredictive);		
       
   152 		void InitializeL(TBool aUseDefaultUserDictionary);
       
   153         MPtiHwrRecognizer* GetHwrRecognizerL(TLanguage aLanguage);
       
   154         MPtiHwrRecognizer* GetHwrRecognizerL(TInt aImpId);		   
       
   155         RArray<TUid>& ListHwrRecognizerL(TLanguage aLanguage);
       
   156         void GetHwrAvailableLanguagesL(RArray<TInt>& aResult);
       
   157 
       
   158  	    const RArray<TPtiNumericKeyBinding>& ExtendedNumericModeKeysForQwertyL(TInt aLanguage);
       
   159         TInt SetAutoSubstitution(TBool aStatus); 
       
   160         TInt AddAutoSubstitutionEntry(const TDesC& aShortcut, const TDesC& aSubstituition);     
       
   161         TInt DeleteAutoSubstitutionEntry(const TDesC& aShortcut);     
       
   162         TInt NumberOfAutoSubstitutionEntries() const;     
       
   163         TInt GetAutoSubstitutionEntry(TInt aIndex, TDes& aShortcut,
       
   164                                       TDes& aSubstitution);                                           
       
   165         TPtiKeyboardType KeyboardType() const;     
       
   166         TInt SetKeyboardType(TPtiKeyboardType aType);   
       
   167         void KeyboardTypesSupportedByLanguageL(TInt aLanguage,
       
   168                                                RArray<TPtiKeyboardType>& aResult);                       
       
   169         void GetNumericModeKeysForQwertyL(TInt aLanguage,
       
   170  	                                      RArray<TPtiNumericKeyBinding>& aResult,
       
   171  	                                   TPtiKeyboardType aKeyboardType);                                                                             
       
   172         const RArray<TPtiNumericKeyBinding>& ExtendedNumericModeKeysForQwertyL(TInt aLanguage,                                                                            TPtiKeyboardType aKeyboardType);
       
   173         TInt SetNumberCandidateStatus(TBool aStatus);                                                                               
       
   174   	    TBool IsValidKey(TPtiKey aKey) const;
       
   175   	    TInt SetMaxLengthForAutoCompletedCandidates(TInt aMaxLenght); 
       
   176         void MarkAutoCapitalized(); 
       
   177         inline TPtrC8 CaseSequence();   
       
   178         TInt AddPhrase(const TDesC& aNewPhrase);                	                                                                                                
       
   179 #ifdef FF_DUAL_LANGUAGE_SUPPORT
       
   180         TInt SetSecondaryInputL(TInt aEpocLanguageID);
       
   181         MPtiKeyMappings* GetCombinedKeyMappings(TPtiKeyboardType aKeyboardType);
       
   182 #endif //FF_DUAL_LANGUAGE_SUPPORT
       
   183                                         
       
   184 	private:
       
   185 		enum
       
   186 			{
       
   187 			KPtiMaxWordSize = 255
       
   188 			};
       
   189 						
       
   190 	private:
       
   191 		CPtiEngineImpl();
       
   192 		void ConstructL(CPtiEngine* aFrontEnd);
       
   193 		CArrayFixFlat<TPtiLangName>* CreateLanguageNamesListLC();
       
   194 		void FindLanguageName(CArrayFixFlat<TPtiLangName>*aList, TDes& aResult, TInt aLangCode);
       
   195 		void RefreshLanguageNamesL();
       
   196 		inline TBool IsCoreForInputMode(TPtiEngineInputMode aMode) const;
       
   197 		inline TBool IsCore() const;
       
   198 		inline CPtiCore* Core() const;
       
   199 		inline CPtiCore* CoreForInputMode(TPtiEngineInputMode aMode) const;		
       
   200 		void DetachUserDictionaries();
       
   201 		CPtiCore* FindCoreByUid(TInt32 aUid);
       
   202 		void ConvertToKeySequence(TPtrC aIn, TDes8& aOut);
       
   203 		inline void ClearBuffers();
       
   204 		void Capitalize(TDes& aTextBuffer);
       
   205 		void MakeCaseSequence(TPtrC aWord);
       
   206 		void LoadCoresInDefaultDirL(TBool aUseDefaultUserDictionary);
       
   207 		CPtiUserDictionary* DefaultUserDictForCore(CPtiCore* aCore);
       
   208 		TInt ReadUidFromUserDictionaryFileL(const TDesC& aFileName);
       
   209 		CPtiCoreLanguage* CreateNumericLanguageL(CPtiCore* aCore);
       
   210 		inline TBool IsChinese() const;
       
   211 		TInt CountToneMarks(TPtrC aSpelling) const;
       
   212 		inline TBool SupportsUserDictionaries(CPtiCore* aCore);
       
   213 		inline TBool IsToneMarkOrSeparator(TInt aChar) const;
       
   214 		inline TBool IsModeChineseQwerty(TPtiEngineInputMode aMode) const;
       
   215 		TPtrC RedirectKeyForChineseQwerty(TPtiKey aKey, TBool& aRedirected);
       
   216 		void CreateUserDictName(TDes& aResult, TUid aCoreUid, TInt aSymbolClass);	
       
   217 		void CreateSecondaryDataFileName(TDes& aResult, TUid aCoreUid, TInt aIndex);				
       
   218         TBool MapNumericChar(CPtiMappings* aMaps, TPtiNumericKeyBinding& aBinding,
       
   219                              TPtiKey aKey, TPtiTextCase aCase, TBool aUseExtendedSet,
       
   220                              TPtiEngineInputMode aMode);	
       
   221    		inline TBool AllowCapitalize(TUint16 aChar) const;
       
   222 		void NumericModeKeysForQwertyL(TInt aLanguage,
       
   223                                        RArray<TPtiNumericKeyBinding>& aResult,
       
   224                                        TBool aUseExtendedSet,
       
   225                                        TPtiKeyboardType aKeyboardtype = EPtiKeyboardNone);	
       
   226         TPtiKeyboardType ActiveKeyboardTypeL();
       
   227         TPtiKeyboardType FindFirstAvailableQwertyKeyboardType(TInt aLang) const;                                              	
       
   228         TPtiTextCase CaseForMappedCharacter(TChar aCharacter);
       
   229         void RemoveTrailingPunctuations();
       
   230         void RemoveTrailingPunctuations12Key();
       
   231 #ifdef FF_DUAL_LANGUAGE_SUPPORT
       
   232         void  SearchKeySequenceInSecLang(TPtrC aIn, TDes8& aOut);
       
   233 #endif // FF_DUAL_LANGUAGE_SUPPORT        
       
   234 	private:	
       
   235 	    /*
       
   236 	    * Pointer to PtiEngine front end.
       
   237 	    */
       
   238 		CPtiEngine*              iFrontEnd;
       
   239 		
       
   240 		/*
       
   241 		* Primary text buffer.
       
   242 		*/
       
   243 		TBuf<KPtiMaxWordSize>    iTextBuffer;
       
   244 		
       
   245 		TBuf<KPtiMaxKeymappingsLength>    iPunctuationCharacters;
       
   246 		
       
   247 		/*
       
   248 		* Input sequence buffer. Holds scan codes for
       
   249 		* each key press for current word.
       
   250 		*/
       
   251 		TBuf8<KPtiMaxWordSize>   iInputSequence;
       
   252 		
       
   253 		/*
       
   254 		* Case buffer. Holds the shift status for each key press.
       
   255 		*/
       
   256 		TBuf8<KPtiMaxWordSize>   iCaseBuffer;
       
   257 		
       
   258 		/*
       
   259 		* Current input mode.
       
   260 		*/
       
   261 		TPtiEngineInputMode      iInputMode;	
       
   262 		
       
   263 		/*
       
   264 		* Pointer to currently active language.
       
   265 		*/	
       
   266 		CPtiCoreLanguage*        iCurrentLanguage;
       
   267 		
       
   268 		/*
       
   269 		* Current text case.
       
   270 		*/
       
   271 		TPtiTextCase             iCase;
       
   272 		
       
   273 		/*
       
   274 		* The language list. 
       
   275 		*/
       
   276 		CArrayPtrFlat<CPtiCoreLanguage>* iLanguages;
       
   277 		
       
   278 		/*
       
   279 		* Candidate buffer.
       
   280 		*/
       
   281 		TBuf<KPtiMaxWordSize>    iCandidateBuffer;
       
   282 		
       
   283 		/*
       
   284 		* Core object array.
       
   285 		*/ 
       
   286 		CArrayPtrFlat<CPtiCore>* iCores;
       
   287 
       
   288         /*
       
   289         * User dictionary array.
       
   290         */
       
   291 		RPointerArray<CPtiUserDictionary> iUserDictionaries;		
       
   292 		
       
   293 		/*
       
   294 		* Pointer to registered PtiEngine observer.
       
   295 		*/
       
   296 		MPtiObserver*            iObserver;
       
   297 			
       
   298 		/* 
       
   299 		* Language for current extended numeric mode set.
       
   300 		*/	
       
   301 		TInt                     iExtendedNumricSetLang;
       
   302 		
       
   303 		/*
       
   304 		* Extended numeric mode characters. 
       
   305 		*/
       
   306 		RArray<TPtiNumericKeyBinding> iExtendedNumricSet;
       
   307 
       
   308         /**
       
   309         * The array used to store hwr implementation uid list
       
   310         */      
       
   311         RArray<TUid> iImpIdList; 
       
   312 		
       
   313         /**
       
   314         * The pointer points current active hwr implementation
       
   315         */
       
   316         CPtiHwrRecognizer* iCurrentHwrImpl;                
       
   317 #ifdef FF_DUAL_LANGUAGE_SUPPORT
       
   318         /*
       
   319         * Pointer to currently active language.
       
   320         */  
       
   321         CPtiCoreLanguage*        iSecondaryLanguage;
       
   322         
       
   323         /**
       
   324         * The pointer used to store current combined keymapping class
       
   325         */
       
   326         MPtiKeyMappings* iCombinedKeyMappings;
       
   327 #endif //FF_DUAL_LANGUAGE_SUPPORT
       
   328 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   329         /*
       
   330         * Pointer to currently active language.
       
   331         */        
       
   332         TBuf16<4>     iZhuyinSymbols;
       
   333         /*
       
   334         * current key inputted.
       
   335         */ 
       
   336         TPtiKey       iKeyMuliTap;
       
   337         /*
       
   338         * index in zhuyin symbol array for mini qwerty zhuyin multi-tap .
       
   339         */ 
       
   340         TInt8         iIndex;
       
   341 #endif //RD_INTELLIGENT_TEXT_INPUT
       
   342 
       
   343         /*
       
   344          * When cursor position in editor crossed max length in editor then set this flag
       
   345         */
       
   346         TBool iMaxEditorLengthCrossed;
       
   347         /*
       
   348          * Keeps count of the punctuation keys entered simultaneously
       
   349          */
       
   350         TInt iPunctuationsEntered;
       
   351         
       
   352         /*
       
   353          * Keeps track of the location of start of punct symbol
       
   354          */
       
   355         TInt iPunctuationLocation;
       
   356 	};
       
   357 
       
   358 #include "PtiEngine.inl"
       
   359 
       
   360 #endif  _PTI_ENGINE_H
       
   361 
       
   362 // End of file