textinput/peninputvkbcn/ctrlinc/peninputvkbcompositionfield.h
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  CAknFepVkbCompositionField
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CAKNFEPVKBCOMPOSITIONFIELD_H
       
    20 #define C_CAKNFEPVKBCOMPOSITIONFIELD_H
       
    21 
       
    22 #include <peninputlayouteditareabase.h>
       
    23 
       
    24 class MAknFepVkbDataProvider;
       
    25 class CAknFepVkbPinyinAnalyser;
       
    26 
       
    27 // property of Cpi engine, Private protocol since hard to modify ptiengine.h
       
    28 const TInt KCpiMaxInputPhraseLen = 6;
       
    29 /**
       
    30  *  Composition Element Type.
       
    31  *
       
    32  *  @lib peninputvkbcn.lib
       
    33  *  @since S60 v3.2 
       
    34  */
       
    35 enum TCompositionElementType
       
    36     {
       
    37     EElementTypeCompositionChar = 0x0001, //normal char
       
    38     EElementTypeAutoSeparator = 0x0002,   //auto separator
       
    39     EElementTypeManualSeparator = 0x0004,  //manual separator
       
    40     EElementTypeSeparator = EElementTypeAutoSeparator | EElementTypeManualSeparator,
       
    41     EElementTypeTonemark = 0x0008,        //tomark
       
    42     EElementTypeAuxilian = EElementTypeSeparator | EElementTypeTonemark,
       
    43     EElementTypeConvertedChar = 0x0010    //converted char from engine
       
    44     };
       
    45         
       
    46 class CAknFepVkbCompositionField;
       
    47 
       
    48 /**
       
    49  *  CCompositionElement.
       
    50  *
       
    51  *  @lib peninputvkbcn.lib
       
    52  *  @since S60 v3.2 
       
    53  */
       
    54 class CCompositionElement: public CBase
       
    55     {
       
    56 public:
       
    57 
       
    58     /**
       
    59      * Symbian constructor.
       
    60      *
       
    61      * @since S60 v3.2
       
    62      * @param aKey Input key
       
    63      * @return Pointer to created CCompositionElement object
       
    64      */
       
    65     static CCompositionElement* NewLC(const TDesC& aKey);    
       
    66 
       
    67     /**
       
    68      * destructor
       
    69      *
       
    70      * @since S60 v3.2
       
    71      * @return None
       
    72      */
       
    73     virtual ~CCompositionElement();
       
    74     
       
    75     /**
       
    76      * Get the length of original input
       
    77      *
       
    78      * @since S60 v3.2
       
    79      * @return The length of original input
       
    80      */
       
    81     virtual TInt OriginalCount() const;
       
    82     
       
    83     /**
       
    84      * Undo convert
       
    85      *
       
    86      * @since S60 v3.2
       
    87      * @param aField The owner of unconverted components
       
    88      * @param aStartPos The insert position
       
    89      * @return Inserted elements count
       
    90      */
       
    91     virtual TInt UndoConvertL(CAknFepVkbCompositionField* aField, TInt aStartPos);
       
    92 
       
    93     /**
       
    94      * Get the key
       
    95      *
       
    96      * @since S60 v3.2
       
    97      * @return The key
       
    98      */
       
    99     inline const TDesC* Key() const;
       
   100 
       
   101     /**
       
   102      * Compare function
       
   103      *
       
   104      * @since S60 v3.2
       
   105      * @return ETrue if the key value is equal to aKeyValue,
       
   106      *         EFalse otherwise
       
   107      */
       
   108     inline TBool operator == (TUint aKeyValue) const;
       
   109     
       
   110     /**
       
   111      * Determine the type of element
       
   112      *
       
   113      * @since S60 v3.2
       
   114      * @param aType The type of element to judge
       
   115      * @return ETrue if it is, otherwise EFalse
       
   116      */
       
   117     inline TBool IsTypeOf(TCompositionElementType aType) const;
       
   118 
       
   119     /**
       
   120      * Is this element is a separator?
       
   121      *
       
   122      * @since S60 v3.2
       
   123      * @return ETrue if element is a separator; otherwise EFalse
       
   124      */
       
   125     inline TBool IsSeparator() const;
       
   126     
       
   127     /**
       
   128      * Is this element is an atuo separator?
       
   129      *
       
   130      * @since S60 v3.2
       
   131      * @return ETrue if element is an auto separator; otherwise EFalse
       
   132      */
       
   133     inline TBool IsAutoSeparator() const;
       
   134     
       
   135     /**
       
   136      * Is this element is a manul separator?
       
   137      *
       
   138      * @since S60 v3.2
       
   139      * @return ETrue if element is a manul separator; otherwise EFalse
       
   140      */
       
   141     inline TBool IsManualSeparator() const;
       
   142     
       
   143 
       
   144     /**
       
   145      * Is this element is a tone mark?
       
   146      *
       
   147      * @since S60 v3.2
       
   148      * @return ETrue if element is a tone mark; otherwise EFalse
       
   149      */
       
   150     inline TBool IsTonemark() const;
       
   151     
       
   152     /**
       
   153      * Is this element is a auxilian(separator or tone mark)
       
   154      *
       
   155      * @since S60 v3.2
       
   156      * @return ETrue if element is a manul separator; otherwise EFalse
       
   157      */
       
   158     inline TBool IsAuxilian() const;
       
   159     
       
   160     /**
       
   161      * Is this element is visible?
       
   162      *
       
   163      * @since S60 v3.2
       
   164      * @return ETrue if element is visible; otherwise EFalse
       
   165      */
       
   166     inline TBool IsVisible();
       
   167     
       
   168     /**
       
   169      * Show/hide the element
       
   170      *
       
   171      * @since S60 v3.2
       
   172      * @param aHide Hide flag,
       
   173      * @return None
       
   174      */
       
   175     inline void Hide(TBool aHide);
       
   176     
       
   177     /**
       
   178      * Get the CCompositionElement pointer of original input
       
   179      *
       
   180      * @since S60 v3.2
       
   181      * @return The length of original input
       
   182      */
       
   183     virtual const CCompositionElement* OriginalContent( TInt aIndex ) const;
       
   184     
       
   185     
       
   186 protected:
       
   187 
       
   188     /**
       
   189      * C++ constructor
       
   190      *
       
   191      * @since S60 v3.2
       
   192      * @return None
       
   193      */            
       
   194     CCompositionElement(TInt aKeyType);
       
   195     
       
   196     /**
       
   197      * 2nd constructor
       
   198      *
       
   199      * @since S60 v3.2
       
   200      * @param aKey Input key
       
   201      * @return None
       
   202      */            
       
   203     void BaseConstructL(const TDesC& aKey);
       
   204     
       
   205 private:  //data
       
   206 
       
   207     /**
       
   208      * The key type
       
   209      */
       
   210     const TInt iKeyType;
       
   211     /**
       
   212      * The key (Own)
       
   213      * The iKey->Length() must be > 0 
       
   214      */
       
   215     HBufC* iKey;
       
   216    
       
   217     TBool iHide; 
       
   218     };
       
   219     
       
   220 /**
       
   221  *  CCompositionConvertedElement.
       
   222  *
       
   223  *  @lib peninputvkbcn.lib
       
   224  *  @since S60 v3.2 
       
   225  */
       
   226 class CCompositionConvertedElement: public CCompositionElement
       
   227     {
       
   228 public:
       
   229 
       
   230     /**
       
   231      * Symbian constructor.
       
   232      *
       
   233      * @since S60 v3.2
       
   234      * @param aKey Input key
       
   235      * @return Pointer to created CCompositionElement object
       
   236      */
       
   237     static CCompositionConvertedElement* NewLC(const TDesC& aKey);    
       
   238 
       
   239     /**
       
   240      * destructor
       
   241      *
       
   242      * @since S60 v3.2
       
   243      * @return None
       
   244      */
       
   245     virtual ~CCompositionConvertedElement();
       
   246 
       
   247     /**
       
   248      * Append a element to this converted element
       
   249      *
       
   250      * @since S60 v3.2
       
   251      * @param aElement The element to append
       
   252      * @return None
       
   253      */
       
   254     void AppendOriginal(const CCompositionElement* aElement);
       
   255 
       
   256 // from CCompositionElement
       
   257     
       
   258     /**
       
   259      * From CCompositionElement
       
   260      * Undo convert
       
   261      *
       
   262      * @since S60 v3.2
       
   263      * @param aField The owner of unconverted components
       
   264      * @param aStartPos The insert position
       
   265      * @return Inserted elements count
       
   266      */
       
   267     TInt UndoConvertL(CAknFepVkbCompositionField* aField, TInt aStartPos);
       
   268     
       
   269     /**
       
   270      * From CCompositionElement
       
   271      * Get the length of original input
       
   272      *
       
   273      * @since S60 v3.2
       
   274      * @return The length of original input
       
   275      */
       
   276     TInt OriginalCount() const;
       
   277     
       
   278     /**
       
   279      * From CCompositionElement
       
   280      * Get the CCompositionElement pointer of original input
       
   281      *
       
   282      * @since S60 v3.2
       
   283      * @return The length of original input
       
   284      */
       
   285     virtual const CCompositionElement* OriginalContent( TInt aIndex ) const;
       
   286 
       
   287 private:
       
   288     
       
   289     /**
       
   290      * C++ constructor
       
   291      *
       
   292      * @since S60 v3.2
       
   293      * @return None
       
   294      */            
       
   295     CCompositionConvertedElement();
       
   296     
       
   297     /**
       
   298      * 2nd constructor
       
   299      *
       
   300      * @since S60 v3.2
       
   301      * @param aKey Input key
       
   302      * @return None
       
   303      */            
       
   304     void ConstructL(const TDesC& aKey);
       
   305 
       
   306 private:  //data
       
   307     
       
   308     /**
       
   309      * Original elements before converted
       
   310      */
       
   311     RPointerArray<CCompositionElement> iOriginalElements;
       
   312     
       
   313     };
       
   314     
       
   315 /**
       
   316  *  CAknFepVkbCompositionField.
       
   317  *
       
   318  *  @lib peninputvkbcn.lib
       
   319  *  @since S60 v3.2 
       
   320  */
       
   321 class CAknFepVkbCompositionField: public CFepLayoutEditAreaBase
       
   322     {
       
   323 
       
   324 public:
       
   325     
       
   326     friend class CCompositionConvertedElement;
       
   327     
       
   328     /**
       
   329      * Symbian constructor.
       
   330      *
       
   331      * @since S60 v3.2
       
   332      * @param aMaxLength Length limitation, 0 means no limitation
       
   333      * @param aRect  The control rect
       
   334      * @param aUiLayout The layout
       
   335      * @param aControlId The control id.
       
   336      * @return Pointer to created CAknFepVkbCompositionField object
       
   337      */
       
   338     static CAknFepVkbCompositionField* NewL(TInt aMaxLength,
       
   339                                             TRect aRect,
       
   340                                             CFepUiLayout* aUiLayout,
       
   341                                             TInt aControlId,
       
   342                                             MAknFepVkbDataProvider* aDataProvider);    
       
   343 
       
   344     /**
       
   345      * destructor
       
   346      *
       
   347      * @since S60 v3.2
       
   348      * @return None
       
   349      */
       
   350     virtual ~CAknFepVkbCompositionField();
       
   351 
       
   352     /**
       
   353      * HandleControlEvent
       
   354      *
       
   355      * @since S60 v3.2
       
   356      * @param aEventType The event type
       
   357      * @param aCtrl  The sender
       
   358      * @param aEventData The event data.
       
   359      * @return None
       
   360      */
       
   361     void HandleControlEvent(TInt aEventType, CFepUiBaseCtrl* aCtrl, const TDesC& aEventData);
       
   362     
       
   363     /**
       
   364      * Get the length of current string in composition field
       
   365      *
       
   366      * @since S60 v3.2
       
   367      * @return The length of current string in composition field
       
   368      */
       
   369     TInt Length() const ;  
       
   370     
       
   371     /**
       
   372      * Set warning color
       
   373      *
       
   374      * @since S60 v3.2
       
   375      * @param aColor The color.
       
   376      * @return None
       
   377      */
       
   378     void SetWarningColor(const TRgb& aColor);
       
   379         
       
   380     /**
       
   381      * Set normal color
       
   382      *
       
   383      * @since S60 v3.2
       
   384      * @param aColor The color.
       
   385      * @return None
       
   386      */
       
   387     void SetNormalColor(const TRgb& aColor); 
       
   388     
       
   389     /**
       
   390      * Is there need to create new word
       
   391      *
       
   392      * @since S60 v3.2
       
   393      * @return ETrue if there is need to create new word, otherwise EFalse
       
   394      */
       
   395     TBool NeedCreateWord();
       
   396     
       
   397      /**
       
   398      * Return the spell for new created words.
       
   399      *
       
   400      * @since S60 v3.2
       
   401      * @return The buffer for the gernated spell.
       
   402      */ 
       
   403     TPtrC GetCreatedWordSpell();
       
   404     
       
   405      /**
       
   406      * Return whether the inputted spell is invalid
       
   407      *
       
   408      * @since S60 v3.2
       
   409      * @return Return whether the inputted spell is invalid.
       
   410      */ 
       
   411     TBool IsValidSpell();
       
   412 
       
   413 	void ConstructFromResourceL();
       
   414 	
       
   415 	void SizeChanged(TRect aRect);	
       
   416 private:
       
   417 
       
   418     /**
       
   419      * C++ constructor
       
   420      *
       
   421      * @since S60 v3.2
       
   422      * @param aMaxLength Length limitation, 0 means no limitation
       
   423      * @param aRect  The control rect
       
   424      * @param aUiLayout The layout
       
   425      * @param aControlId The control id.
       
   426      * @return None
       
   427      */            
       
   428     CAknFepVkbCompositionField(TInt aMaxLength,
       
   429                               TRect aRect,
       
   430                               CFepUiLayout* aUiLayout,
       
   431                               TInt aControlId,
       
   432                               MAknFepVkbDataProvider* aDataProvider);
       
   433 
       
   434     /**
       
   435      * Second phase constructor
       
   436      *
       
   437      * @since S60 v3.2
       
   438      * @return None
       
   439      */
       
   440     void ConstructL();
       
   441 
       
   442     /**
       
   443      * Insert a key
       
   444      *
       
   445      * @since S60 v3.2
       
   446      * @param aKey The key to insert.
       
   447      * @return None
       
   448      */
       
   449     void HandleInsertL(const TDesC& aKey);
       
   450 
       
   451     /**
       
   452      * Generate first segment to analysis
       
   453      *
       
   454      * @since S60 v3.2
       
   455      * @return None
       
   456      */
       
   457     void GetFirstSegmentL();
       
   458 
       
   459     /**
       
   460      * Insert an element
       
   461      *
       
   462      * @since S60 v3.2
       
   463      * @param aElement The element to insert.
       
   464      * @return None
       
   465      */
       
   466     void InsertElementL(const CCompositionElement* aElement);
       
   467 
       
   468     /**
       
   469      * clear text
       
   470      *
       
   471      * @since S60 v3.2
       
   472      * @return None
       
   473      */
       
   474     void ClearTextL();
       
   475     
       
   476     /**
       
   477      * Handle back key
       
   478      *
       
   479      * @since S60 v3.2
       
   480      * @return None
       
   481      */
       
   482     void HandleBackL();
       
   483     
       
   484     /**
       
   485      * Submit all text
       
   486      *
       
   487      * @since S60 v3.2
       
   488      * @return None
       
   489      */
       
   490     void HandleFlushL();
       
   491 
       
   492     /**
       
   493      * Handle Analysis Response
       
   494      *
       
   495      * @since S60 v3.2
       
   496      * @param aCompText Analysis result text.
       
   497      * @return None
       
   498      */
       
   499     void HandleAnalysisResponseL(const TDesC& aCompText);
       
   500 
       
   501     /**
       
   502      * Handle converted result
       
   503      *
       
   504      * @since S60 v3.2
       
   505      * @param aConvertedText Converted result text.
       
   506      * @return None
       
   507      */
       
   508     void HandleConvertedResultL(const TDesC& aConvertedText);
       
   509 
       
   510     /**
       
   511      * Elements operation: remove
       
   512      *
       
   513      * @since S60 v3.2
       
   514      * @param aStartPos Start position.
       
   515      * @param aLength Length.
       
   516      * @return None
       
   517      */
       
   518     void Remove(TInt aStartPos, TInt aLength, TBool aDestroy = ETrue);
       
   519     /**
       
   520      * Elements operation: insert
       
   521      *
       
   522      * @since S60 v3.2
       
   523      * @param aPos Insert position.
       
   524      * @param aElement The element.
       
   525      * @return None
       
   526      */
       
   527     void InsertL(TInt aPos, const CCompositionElement* aElement);
       
   528     
       
   529     /**
       
   530      * Elements operation: clear
       
   531      *
       
   532      * @since S60 v3.2
       
   533      * @return None
       
   534      */
       
   535     void Clear();
       
   536     
       
   537     /**
       
   538      * Submit the keys in elements and the cursor to editbase
       
   539      *
       
   540      * @since S60 v3.2
       
   541      * @param aPos Insert position.
       
   542      * @return None
       
   543      */
       
   544     void UpdateTextL();
       
   545 
       
   546     /**
       
   547      * Determine whether elment is allowed to insert
       
   548      *
       
   549      * @since S60 v3.2
       
   550      * @param aElement Element to insert
       
   551      * @return ETrue for allowed otherwise EFalse;
       
   552      */
       
   553     TBool IsAllowedInsert(const CCompositionElement* aElement);
       
   554 
       
   555     /**
       
   556      * Send Analysis Request
       
   557      *
       
   558      * @since S60 v3.2
       
   559      * @param aRequest The request
       
   560      * @return None;
       
   561      */
       
   562     void SendAnalysisRequestL();
       
   563     
       
   564     /**
       
   565      * To test whether the all input keys are converted
       
   566      * to chinese characters
       
   567      *
       
   568      * @since S60 v3.2
       
   569      * @return ETrue if finished, EFalse otherwise.
       
   570      */
       
   571     TBool IsFinishComposition();
       
   572     
       
   573     /**
       
   574      * To test whether current pos element should be replaced by input one
       
   575      *
       
   576      * @since S60 v3.2
       
   577      * @param aElement The input element
       
   578      * @param aPos The pos of element to test
       
   579      * @return ETrue if current element should be replaced, EFalse otherwise.
       
   580      */
       
   581     TBool IsReplacePosition(const CCompositionElement* aElement, TInt aPos);
       
   582     
       
   583     /**
       
   584      * To test whether the one before current pos element should be replaced 
       
   585      * by input one
       
   586      *
       
   587      * @since S60 v3.2
       
   588      * @param aElement The input element
       
   589      * @return ETrue if current element should be replaced, EFalse otherwise.
       
   590      */
       
   591     TBool IsReplaceFront(const CCompositionElement* aElement);
       
   592     
       
   593     /**
       
   594      * To test whether current pos element should be replaced by input one
       
   595      *
       
   596      * @since S60 v3.2
       
   597      * @param aElement The input element
       
   598      * @return ETrue if current element should be replaced, EFalse otherwise.
       
   599      */
       
   600     TBool IsReplaceBack(const CCompositionElement* aElement);
       
   601     
       
   602     /**
       
   603      * Redo the format after deletion.
       
   604      *
       
   605      * @since S60 v3.2
       
   606      * @return None.
       
   607      */
       
   608     void ReFomatAfterDelete();
       
   609     
       
   610     /**
       
   611      * Get display cursor positon by internal cursor position
       
   612      *
       
   613      * @since S60 v3.2
       
   614      * @param aInternalPos The internal position
       
   615      * @return The display cursor position.
       
   616      */
       
   617     TInt InternalPosToDisplayPos(TInt aInternalPos);
       
   618     
       
   619     /**
       
   620      * Get internal cursor positon by display cursor position
       
   621      *
       
   622      * @since S60 v3.2
       
   623      * @param aInternalPos The internal position
       
   624      * @return The display cursor position.
       
   625      */
       
   626     TInt DisplayPosToInternaPos(TInt aDisplayPos);
       
   627     
       
   628     /**
       
   629      * Remove the selected text
       
   630      *
       
   631      * @since S60 v3.2
       
   632      * @return None
       
   633      */
       
   634     void RemoveSelection();
       
   635     
       
   636 // from CFepLayoutEditAreaBase
       
   637 
       
   638     /**
       
   639      * From CFepLayoutEditAreaBase
       
   640      * Adjust the cursor when pointer down or move
       
   641      *
       
   642      * @since S60 v3.2
       
   643      * @return None
       
   644      */
       
   645     void AdjustSelectedCompositionText(TInt& aPositionOfInsertionPointInBuffer);
       
   646 
       
   647     /**
       
   648      * From CFepLayoutEditAreaBase
       
   649      * Update editbase content when scrolling
       
   650      *
       
   651      * @since S60 v3.2
       
   652      * @param aCursorPos The cursor position
       
   653      * @param aAnchorPos The anchor position
       
   654      * @return None.     
       
   655      */                  
       
   656     void UpdateContent(const TCursorSelection& aCursorSel);
       
   657     
       
   658 private:  //data
       
   659 
       
   660     /**
       
   661      * Length limitation
       
   662      */
       
   663     TInt iMaxLength;
       
   664     
       
   665     /**
       
   666      * segment to analysis (Own)
       
   667      */
       
   668     HBufC* iFirstSegment;
       
   669     
       
   670     /**
       
   671      * first segment start position in buffer 
       
   672      */
       
   673     TInt iFirstSegmentOffset;
       
   674 
       
   675     /**
       
   676      * first segment length in buffer 
       
   677      * iFirstSegmentLength may not equal to iFirstSegment.Length
       
   678      * Because all automatical separators are removed in iFirstSegment
       
   679      */
       
   680     TInt iFirstSegmentLength;
       
   681     
       
   682     /**
       
   683      * Warning color 
       
   684      */
       
   685     TRgb iWarningColor;
       
   686     
       
   687     /**
       
   688      * Normal color 
       
   689      */
       
   690     TRgb iNormalColor;
       
   691     
       
   692     /**
       
   693      * Elements
       
   694      */
       
   695     RPointerArray<CCompositionElement> iElements;
       
   696     
       
   697     /**
       
   698      * Current cursor position of 
       
   699      * internal data
       
   700      */
       
   701     TInt iCurrentPos;
       
   702     /**
       
   703      * composition text start with manul separator
       
   704      */
       
   705     //TInt iSavedCursorPos;
       
   706     
       
   707     /**
       
   708      * Flag of is there need to create new word
       
   709      */
       
   710     TBool iNeedCreateWord;
       
   711     
       
   712     /**
       
   713      * The count of converted element
       
   714      */
       
   715     TInt iConvertedElement;
       
   716     
       
   717     /**
       
   718      * The count of converted element
       
   719      */
       
   720     TBuf<KCpiMaxInputPhraseLen * 8 + 1> iCreateWordSpellBuffer;
       
   721     
       
   722     /**
       
   723      * The analyser handle for spell decomposition
       
   724      */
       
   725     CAknFepVkbPinyinAnalyser* iPinyinAnalyser;
       
   726     CAknFepVkbPinyinAnalyser* iZhuyinAnalyser;
       
   727     
       
   728     /**
       
   729      * The data provider
       
   730      * Not own
       
   731      */
       
   732     MAknFepVkbDataProvider* iDataProvider;
       
   733     
       
   734     /**
       
   735      * Specify wether the spell is valid.
       
   736      */
       
   737     TInt iIsValidSpells;
       
   738 
       
   739     };
       
   740 
       
   741 #include "peninputvkbcompositionfield.inl"    
       
   742 
       
   743 #endif //C_CAKNFEPVKBCOMPOSITIONFIELD_H
       
   744 
       
   745 //  End Of File