2 * Copyright (c) 2003-2005 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Predective text input engine core interface.
37 #include "PtiLanguage.h"
38 #include "PtiUserDictionary.h"
40 // FORWARD DECLARATIONS
42 class MPtiEngineCompositionDataInterface;
43 class MPtiUserDictionaryEntry;
46 const TInt KDefaultCoresGran = 3;
49 * This is abstract base class of all PtiEngine core objects. A PtiEngine core object implements set of
50 * input modes and input related services for a set of languages. This class defines core side
60 * Initialized core object. This method is called by PtiEngine framework when core object
64 * @param aOwner Pointer to onwing PtiEngine framework instance.
65 * @param aTextBuffer A pointer to PtiEngine main text buffer.
66 * @param aLanguageList A language list to be filled with language bindings to this core
68 * @param aUseDefautUserDictionary A boolean value indicating whether default user dictionary shoulkd be used
69 * (in case this core object supports user dictionaries).
71 virtual void InitializeL(CPtiEngine* aOwner, TDes* aTextBuffer, CArrayPtrFlat<CPtiCoreLanguage>* aLanguageList, TBool aUseDefautUserDictionary) = 0;
74 * Removes languages associated to this core object from given language list. Languages
75 * not associated to this core abject are not touched.
78 * @param aLanguageList A language list to be cleaned.
80 virtual void DropLanguages(CArrayPtrFlat<CPtiCoreLanguage>* aLanguageList) = 0;
83 * Opens resources for given language and itinialized them.
86 * @param aLanguage Symbian OS language code a language to be initialized.
87 * @return KErrNone or a system wide error code.
89 virtual TInt OpenLanguageL(CPtiCoreLanguage *aLanguage) = 0;
92 * Closes currently activate language and frees resources associated to it.
95 * @return KErrNone of system wide error ocde.
97 virtual TInt CloseLanguageL() = 0;
100 * Returns the contents of text buffer.
103 * @return A constant pointer to text buffer.
105 virtual TPtrC GetCurrentWord() const = 0;
108 * Commits current word. Commiting means that user has added current
109 * word as part of text. Frequency information and other related attributes
110 * can then be updated.
113 * @return KErrNone or a system wide error code.
115 virtual TInt CommitCurrentWord() = 0;
118 * Returns a pointer core info structure. Core info struct contains useful
119 * information about core object and its features.
122 virtual MPtiCoreInfo* GetCoreInfo() = 0;
125 * Turns reoreding feature on or off. Reordering means that prediction engine
126 * maintains frequency information for used words and modifys the order of candidate list
127 * based on that information. This feature may not be supported by all prediction engines.
130 * @param aStatus New status for reorderinf feature.
131 * @return KErrNone or a system wide error code.
133 virtual TInt SetReordering(TBool aStatus) = 0;
136 * This is the single most important core API method, most of the text input functionality
137 * will be utilize this method. Call to this method indicates core object that a key was
138 * pressed and it should act accordingly and fill the output buffer.
141 * @param aKey Enum value for pressed key.
143 virtual void AppendKeyPress(TPtiKey aKey) = 0;
146 * Indicates core object that it should perform 'delete key press'-operation.
150 virtual void DeleteKeyPress() = 0;
153 * Call to this method notifys core object that input buffer was cleared.
157 virtual void ClearBuffer() = 0;
160 * Sets current input sequence. The end result of this operation must be same as
161 * if user had entered keys in input array as individual key presses.
164 * @param aInput An array containing sequence of key presses (type TPtiKey).
165 * @return KErrNone or a system wide error code.
167 virtual TInt SetCurrentInputSequence(TPtrC8 aInput) = 0;
170 * Converts given string from one character set to another. Possible conversion types
171 * are defined in PtiDefs.h
174 * @param aType Conversion type.
175 * @param aInput Pointer to input string to be converted.
176 * @param aInputLength Length of input buffer.
177 * @param aOutput pointer to output buffer.
178 * @return KErrNone or a system wide error code.
180 virtual TInt Convert(TPtiCharConversion aType,
186 * Re-defines keymappings for given key / input mode / case combination. Previous
187 * keymapping will be deleted and new mappings will be used instead.
190 * @param aMode Input mode for new key mapping.
191 * @param aKey A key to be replaced.
192 * @param aKeyMap New keymapping data for aKey.
193 * @param aCase Text case to be replaced.
194 * @return KErrNone or system wide error code.
196 virtual TInt SetExternalKeyMapL(TPtiEngineInputMode aMode,
199 TPtiTextCase aCase) = 0;
201 * Returns alternate spelling for given unicode characters. Possible conversion
202 * types are defined in header PtiDefs.h.
205 * @aInput A character to be converted.
206 * @aOutput Resulting alternate spelling will be stored here.
207 * @aType Spelling conversion type.
208 * @return KErrNone or system wide error code.
210 virtual TInt GetSpelling(TUint16 aInput, TDes& aOutput, TPtiSpelling aType) = 0;
213 * Cancels all on-going core obejct timner activity.
216 * @return KErrNone or system wide error code.
218 virtual TInt CancelTimerActivity() = 0;
221 * A generic command handling method for extending PtiEngine API without adding
222 * new base class methods. It is recommended to use this only in force major
223 * situations, where there is no other way.
226 * @param aCommand A Command id value. Platform wide command ids are defined in PtiDefs.h.
227 * @param aParams TAny pointer for passing any required parameters.
228 * @return An integer containing possible return value related to command.
230 virtual TInt HandleCommandL(TPtiEngineCommand aCommand, TAny* aParams) = 0;
233 // Predictive latin API
237 * Returns number of candidates for currently entered key sequence.
240 * @return Number of prediction candidates for currently entered key sequence.
242 virtual TInt NumberOfCandidates() = 0;
245 * Returns a list of candidate words for currently entered key sequence.
248 * @param aList A list to be filled with candidate words.
249 * @return Number of candidate works in aList.
251 virtual TInt GetCandidateListL(CDesCArray& aList) = 0;
254 * Returns next word candidate list. Next word candidates are words
255 * potentially related to currently selected candidate. Next word prediction
256 * feature must supported by the engine and turned on.
260 virtual TInt GetNextWordCandidateListL(CDesCArray& aList) = 0;
263 * Returns first word in list of candidate words for current input sequence.
266 * @param aResult A descriptor where resulting word will be stored.
267 * @return KErrnNone or system wide error code.
269 virtual TInt GetFirstCandidate(TDes& aResult) = 0;
272 * Returns next word in list of candidate words for current input sequence.
275 * @param aResult A descriptor where resulting word will be stored.
276 * @return KErrnNone or system wide error code.
278 virtual TInt GetNextCandidate(TDes& aResult) = 0;
281 * Returns previous word in list of candidate words for current input sequence.
284 * @param aResult A descriptor where resulting word will be stored.
285 * @return KErrnNone or system wide error code.
287 virtual TInt GetPreviousCandidate(TDes& aResult) = 0;
290 // User dictionary API
293 virtual TInt AddUserDictionaryEntry(MPtiUserDictionaryEntry& aEntry, CPtiUserDictionary* aDict) = 0;
294 virtual TInt RemoveUserDictionaryEntry(MPtiUserDictionaryEntry& aEntry, CPtiUserDictionary* aDict) = 0;
295 virtual TInt NumberOfEntriesInUserDictionary(CPtiUserDictionary* aDict) = 0;
296 virtual TInt GetUserDictionaryEntry(TInt aIndex, MPtiUserDictionaryEntry& aResult, CPtiUserDictionary* aDict) = 0;
297 virtual CPtiUserDictionary* CreateEmptyUserDictionaryL(TInt aMaxSize) = 0;
298 virtual TInt AttachUserDictionary(CPtiUserDictionary* aDict) = 0;
299 virtual TBool DetachUserDictionary(CPtiUserDictionary* aDict) = 0;
305 virtual TPtrC GetCandidatePage() = 0;
306 virtual TBool NextCandidatePage() = 0;
307 virtual TBool PreviousCandidatePage() = 0;
308 virtual TBool MoreCandidatePages() = 0;
309 virtual void SetCandidatePageLength(TInt aLength) = 0;
310 virtual TPtrC GetPhoneticSpelling(TInt aIndex) const = 0;
311 virtual TInt PhoneticSpellingCount() const = 0;
312 virtual TBool SelectPhoneticSpelling(TInt aIndex) = 0;
313 virtual TInt SelectedPhoneticSpelling() const = 0;
314 virtual TBool ToneMark(TText& aToneMark) const = 0;
315 virtual TBool IsToneMarkValidForSpelling() = 0;
316 virtual TBool SetPredictiveChineseChar(const TDesC& aChar) = 0;
317 virtual TBool SetToneMark(TInt aToneMark) = 0;
324 virtual TPtrC ReadingTextL() = 0;
325 virtual MPtiEngineCompositionDataInterface* CompositionData() = 0;
331 virtual HBufC* GetCandidatesByInputString(const TDesC& aInputString,
332 RPointerArray<HBufC>& aList,
333 const TBool aIsPredictive) = 0;
338 * This class is a base class implementation for MPtiCore. It contains empty base implemenations
339 * for core API methods and static methods for creating and listing PtiEngine core objects.
341 class CPtiCore : public CBase, public MPtiCore
344 // Plugin household methods
348 * Creates in instance of core object for given implemenation uid.
350 * @param aCoreUid An ecom implementation uid for core object to be created.
351 * @return Pointer to new core object instance.
353 IMPORT_C static CPtiCore* CreateCoreL(TUid aCoreUid);
356 * Lists all the available PtiEngine core onject implemenatations.
358 * @return Pointer to a list cantaining implementation uids for available core plugins.
360 IMPORT_C static CArrayFix<TInt>* ListCoresLC();
363 IMPORT_C ~CPtiCore();
369 IMPORT_C TInt SetCurrentInputSequence(TPtrC8 aInput);
370 IMPORT_C TInt Convert(TPtiCharConversion aType,
374 IMPORT_C TInt GetSpelling(TUint16 aInput,
377 IMPORT_C TInt SetExternalKeyMapL(TPtiEngineInputMode aMode,
381 IMPORT_C TInt CommitCurrentWord();
382 IMPORT_C TPtrC GetCurrentWord() const;
385 // Predictive latin API
388 IMPORT_C TInt NumberOfCandidates();
389 IMPORT_C TInt GetCandidateListL(CDesCArray& aList);
390 IMPORT_C TInt GetNextWordCandidateListL(CDesCArray& aList);
391 IMPORT_C TInt GetFirstCandidate(TDes& aResult);
392 IMPORT_C TInt GetNextCandidate(TDes& aResult);
393 IMPORT_C TInt GetPreviousCandidate(TDes& aResult);
396 // User dictionary API
399 IMPORT_C TInt AddUserDictionaryEntry(MPtiUserDictionaryEntry& aEntry, CPtiUserDictionary* aDict);
400 IMPORT_C TInt RemoveUserDictionaryEntry(MPtiUserDictionaryEntry& aEntry, CPtiUserDictionary* aDict);
401 IMPORT_C TInt NumberOfEntriesInUserDictionary(CPtiUserDictionary* aDict);
402 IMPORT_C TInt GetUserDictionaryEntry(TInt aIndex, MPtiUserDictionaryEntry& aResult, CPtiUserDictionary* aDict);
403 IMPORT_C CPtiUserDictionary* CreateEmptyUserDictionaryL(TInt aMaxSize);
404 IMPORT_C TInt AttachUserDictionary(CPtiUserDictionary* aDict);
405 IMPORT_C TBool DetachUserDictionary(CPtiUserDictionary* aDict);
411 IMPORT_C TPtrC GetCandidatePage();
412 IMPORT_C TBool NextCandidatePage();
413 IMPORT_C TBool PreviousCandidatePage();
414 IMPORT_C TBool MoreCandidatePages();
415 IMPORT_C void SetCandidatePageLength(TInt aLength);
416 IMPORT_C TPtrC GetPhoneticSpelling(TInt aIndex) const;
417 IMPORT_C TInt PhoneticSpellingCount() const;
418 IMPORT_C TBool SelectPhoneticSpelling(TInt aIndex);
419 IMPORT_C TInt SelectedPhoneticSpelling() const;
420 IMPORT_C TBool ToneMark(TText& aToneMark) const;
421 IMPORT_C TBool IsToneMarkValidForSpelling();
422 IMPORT_C TBool SetPredictiveChineseChar(const TDesC& aChar);
423 IMPORT_C TBool SetToneMark(TInt aToneMark);
429 IMPORT_C TPtrC ReadingTextL();
430 IMPORT_C MPtiEngineCompositionDataInterface* CompositionData();
436 IMPORT_C HBufC* GetCandidatesByInputString(const TDesC& aInputString,
437 RPointerArray<HBufC>& aList,
438 const TBool aIsPredictive);
441 inline void SetDestructorKeyId(TInt aDtorKeyId);
449 inline void CPtiCore::SetDestructorKeyId(TInt aDtorKeyId)
451 iDtorKeyId = aDtorKeyId;