textinput/peninputhwrtrui/inc/truihwrbox.h
changeset 27 694fa80c203c
parent 24 fc42a86c98e3
child 35 0f326f2e628e
equal deleted inserted replaced
24:fc42a86c98e3 27:694fa80c203c
     1 /*
       
     2 * Copyright (c) 2007 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:  hand writing box - control in Training UI application 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_TRAININGUIHWRBOX_H
       
    20 #define C_TRAININGUIHWRBOX_H
       
    21 
       
    22 // includes 
       
    23 #include <coecntrl.h>
       
    24 #include <AknInfoPopupNoteController.h> // Tooltip
       
    25 
       
    26 // forward declarations  
       
    27 class MTruiHwrBoxObserver;
       
    28 class CAknInfoPopupNoteController;
       
    29 class CAknsBasicBackgroundControlContext;
       
    30 
       
    31 const TPoint KTail( 0xFFFF,0 );
       
    32 
       
    33 // Class declaration
       
    34 /**
       
    35  *  CTruiHwrBox
       
    36  *  CTruiHwrBox is new component, which allows input and output a character
       
    37  *  model by strokes
       
    38  *  @lib avkon.lib
       
    39  */ 
       
    40 class CTruiHwrBox : public CCoeControl, public MAknInfoPopupNoteObserver
       
    41     {   
       
    42 public:
       
    43 
       
    44     /* Flags for hwrbox state. HwrBox must be one and only one state */   
       
    45     enum TBoxState
       
    46         {
       
    47         /* Already has model but doesn't play the animation */
       
    48         EExistModelStop = 0,
       
    49         /* Already has model and play the animation */
       
    50         EExistModelDraw,
       
    51         /* Ready to input an new character model */
       
    52         ENewModelStop,
       
    53         /* Use is inputting an new character model */
       
    54         ENewModelDraw,
       
    55         }; 
       
    56         
       
    57     enum THwrBoxFlag
       
    58         {
       
    59         ENoFrameHwrBox = 0x00000000,
       
    60         EFrameHwrBox = 0x00000001,
       
    61         EReadOnlyHwrBox = 0x00000002,
       
    62         EWritableHwrBox = 0x00000004
       
    63         };
       
    64         
       
    65 public: 
       
    66 
       
    67     /**
       
    68      * Two-phased constructor.
       
    69      * @param aParent the parent control for choice list
       
    70      * @param aRect the extent of the control
       
    71      * @return Pointer to CTruiHwrBox's instance
       
    72      */
       
    73     static CTruiHwrBox* NewL( CCoeControl* aParent, 
       
    74                               MTruiHwrBoxObserver* aHwrBoxObserver = NULL,
       
    75                               MAknsControlContext* aBgContext = NULL );
       
    76 
       
    77     /**
       
    78      * Two-phased constructor.
       
    79      * @param aParent the parent control for choice list
       
    80      * @param aRect the extent of the control
       
    81      * @return Pointer to CTruiHwrBox's instance
       
    82      */
       
    83     static CTruiHwrBox* NewLC( CCoeControl* aParent,
       
    84                                MTruiHwrBoxObserver* aHwrBoxObserver = NULL,
       
    85                                MAknsControlContext* aBgContext = NULL );
       
    86     
       
    87     /**
       
    88      * Destructor
       
    89      */
       
    90     ~CTruiHwrBox(); 
       
    91     
       
    92     /**
       
    93      * Periodic Callback function
       
    94      * To save the model
       
    95      *
       
    96      * @param aObject: Transfer the pointer to CTruiHwrBox into this function
       
    97      * @return system-wide err code
       
    98      */
       
    99     static TInt TimeToSaveL( TAny* aObject );
       
   100     
       
   101     /**
       
   102      * Save the new inputting model
       
   103      */
       
   104     void SaveModelL();
       
   105 
       
   106     /**
       
   107      * Save the new inputting model by manual.
       
   108      */
       
   109     void SaveModelByManuallyL();
       
   110     
       
   111     /**
       
   112      * Periodic Callback function
       
   113      * To draw the next piont in the animation
       
   114      *
       
   115      * @param aObject: Transfer the pointer to CTruiHwrBox into this function
       
   116      * @return system-wide err code
       
   117      */
       
   118     static TInt TimeToDrawNextL( TAny* aObject );
       
   119     
       
   120     /**
       
   121      * Draw the next piont in the animation
       
   122      */
       
   123     void DrawNextL();
       
   124     
       
   125     /**
       
   126      * Begin to draw the existing model
       
   127      *
       
   128      * @param aIsScale ETrue scale points to the fitable size before playing.
       
   129      * @param aRefSize The size as the reference coordination for scaling.
       
   130      */
       
   131     void PlayAnimation( TBool aIsScale = EFalse, const TSize& aRefSize = TSize( 1, 1 ) );
       
   132     
       
   133     /**
       
   134      * clear the existing model
       
   135      */
       
   136     void ClearExistModel();
       
   137     
       
   138     /**
       
   139      * Set HwrBox observer
       
   140      * @param aHwrBoxObserver the observer
       
   141      */
       
   142     void SetHwrBoxObserver( MTruiHwrBoxObserver* aHwrBoxObserver );
       
   143     
       
   144     /**
       
   145      * Get the Hwrbox's model
       
   146      *
       
   147      * @return Reference to iPointArrayModel
       
   148      */
       
   149     RArray<TPoint>& Model();
       
   150     
       
   151     /**
       
   152      * Get the Hwrbox's state
       
   153      *
       
   154      * @return Current HWR box's state
       
   155      */
       
   156     TInt BoxState() const;
       
   157     
       
   158     /**
       
   159      * Pause the playing of animation
       
   160      */
       
   161     void PausePlaying();
       
   162     
       
   163     /**
       
   164      * Resume the playing of animation
       
   165      */
       
   166     void ResumePlaying();
       
   167     
       
   168     /**
       
   169      * Set guiding line
       
   170      *
       
   171      * @param aTop The vertical coordinate of top guiding line
       
   172      * @param aBottom The vertical coordinate of bottom guiding line
       
   173      * @return system-wide err code
       
   174      */
       
   175     TInt SetGuidingLine( TInt aTop, TInt aBottom );
       
   176     
       
   177     /**
       
   178      * Show trails statically
       
   179      *
       
   180      * @param aPointArray The points that will be shown in HwrBox
       
   181      */
       
   182     void ShowTrails( const RArray<TPoint>& aPointArray, 
       
   183                      TBool aIsScale = EFalse,
       
   184                      const TSize& aRefSize = TSize( 1, 1 ) );
       
   185     
       
   186     /**
       
   187      * Show tooltip
       
   188      *
       
   189      * @param aText The tooltip tex.
       
   190      * @param aPosition The tooltip's location.
       
   191      * @param aBeforeTimeout The time internal that will popup tooltip
       
   192      * @param aInViewTimeout The time internal that will hide tooltip
       
   193      */
       
   194     void ShowTooltipL( const TDesC& aText,
       
   195                        const TPoint& aPosition, 
       
   196                        const TInt aBeforeTimeout,
       
   197                        const TInt aInViewTimeout );
       
   198     
       
   199     /**
       
   200      * Set the position for tooltip
       
   201      *     
       
   202      * @param aPosition The tooltip's location.
       
   203      */
       
   204     void SetTooltipPosition( const TPoint& aPosition );
       
   205     
       
   206     /**
       
   207      * Hide tooltip
       
   208      *
       
   209      */
       
   210     void HideInfoPopupNote();
       
   211 // From CCoeControl 
       
   212     
       
   213     /**
       
   214      * From CCoeControl. Handles key events.
       
   215      * @param aKeyEvent the key event    
       
   216      * @param aType The type of key event
       
   217      * @return Indicates whether or not the keyevent was used by this control   
       
   218      */
       
   219     TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType );    
       
   220     
       
   221     /**
       
   222      * From CCoeControl. Draws control to given area
       
   223      * @param aRect The rectangle that should be drawn by the control. 
       
   224      */
       
   225     void Draw( const TRect& aRect ) const;
       
   226        
       
   227     /**
       
   228      * Draw character model
       
   229      */
       
   230     void DrawModel();
       
   231     
       
   232     /**
       
   233      * Set box state from outside
       
   234      *
       
   235      * @param aReady ture means model is loaded
       
   236      *               false means no model is loaded
       
   237      */
       
   238     void ModelIsReady( TBool aReady = ETrue );
       
   239     
       
   240     TRect DrawableRect() const;
       
   241     
       
   242     inline void SetHwrBoxFlag( TUint aFlag )
       
   243         {
       
   244         iFlag = aFlag;
       
   245         };
       
   246         
       
   247     /**
       
   248      * Set flag to indicate if draw bottom guideline
       
   249      *
       
   250      * @param aBottomGuideLineDisplay ETrue means draw bottom guideline
       
   251      */
       
   252     inline void SetDisplayBottomGuideLine( TBool aBottomGuideLineDisplay )
       
   253         {
       
   254         iBottomGuideLineDisplay = aBottomGuideLineDisplay;
       
   255         };
       
   256 
       
   257     /**
       
   258      * Set flag to indicate if draw top guideline
       
   259      *
       
   260      * @param aTopGuideLineDisplay ETrue means draw bottom guideline
       
   261      */
       
   262     inline void SetDisplayTopGuideLine( TBool aTopGuideLineDisplay )
       
   263         {
       
   264         iTopGuideLineDisplay = aTopGuideLineDisplay;
       
   265         };
       
   266         
       
   267     /**
       
   268      * Set editing mode to readonly or writable
       
   269      *
       
   270      * @param aReadOnly ETrue means hwrbox is readonly
       
   271      *                  EFalse means hwrbox is loaded
       
   272      */
       
   273     void SetHwrBoxReadOnly( TBool aReadOnly );
       
   274 
       
   275 // from CCoeControl
       
   276     
       
   277     /**
       
   278      * From CCoeControl. Handles pointer events
       
   279      * @param aPointerEvent the pointer event be be handled.
       
   280      */
       
   281     void HandlePointerEventL( const TPointerEvent& aPointerEvent );    
       
   282     
       
   283 protected: 
       
   284 
       
   285 
       
   286     /**
       
   287      * From CoeControl.
       
   288      * Responds to changes to the size and position of the contents of this control.
       
   289      */
       
   290     void SizeChanged();
       
   291     
       
   292     /**
       
   293      * Handles a change to the control's resources.
       
   294      *
       
   295      * @param aType A message UID value.
       
   296      */
       
   297     void HandleResourceChange( TInt aType );
       
   298     
       
   299     /**
       
   300      * Handle focus changed
       
   301      *
       
   302      */
       
   303     void FocusChanged( TDrawNow aDrawNow ); 
       
   304 
       
   305 private:
       
   306 
       
   307     /**
       
   308      * C++ Default Constructor 
       
   309      */
       
   310     CTruiHwrBox(); 
       
   311 
       
   312     /**
       
   313      * 2nd phase constructor
       
   314      * @param aParent the parent control for choice list
       
   315      * @param aRect the extent of the control
       
   316      */
       
   317     void ConstructL( CCoeControl* aParent,
       
   318                      MTruiHwrBoxObserver* aHwrBoxObserver = NULL,
       
   319                      MAknsControlContext* aBgContext = NULL );
       
   320     
       
   321     /**
       
   322      * Check if the point is contained in drawing area
       
   323      *
       
   324      * @param aPoint The point which to be checked
       
   325      * @return ETrue: The point is in drawing area
       
   326      *         EFalse: The point isn't in drawing area
       
   327      */
       
   328     TBool IsContained( const TPoint& aPoint ) const;
       
   329     
       
   330     /**
       
   331     * Adjust shortcut model's point to fit the popup hwr box. 
       
   332     * @param aOriginSize Origin size of which input character model.
       
   333     * @param aRealSize Real popup hwr box's size.
       
   334     * @param aModel The model to be adjuested.
       
   335     */    
       
   336     void ScaleModel( const TSize& aOriginSize, 
       
   337                      const TSize& aRealSize, 
       
   338                      RArray<TPoint>& aModel );
       
   339        
       
   340     /**
       
   341      * Draws all points.     
       
   342      */
       
   343     void DrawTrails( CWindowGc& aGc ) const;
       
   344     
       
   345     /**
       
   346      * Set context for this control.
       
   347      *
       
   348      * @param aGc Handle for CWindowGc
       
   349      */
       
   350     void PrepareContext( CWindowGc& aGc ) const;
       
   351     
       
   352     /**
       
   353      * Load bitmaps for border.
       
   354      *
       
   355      */
       
   356     void LoadBorderBitmapsL();
       
   357     
       
   358     /**
       
   359      * Load bitmaps for shadows.
       
   360      *
       
   361      */
       
   362     void LoadShadowBitmapsL();
       
   363 
       
   364     /**
       
   365      * Load bitmaps for guidelines.
       
   366      *
       
   367      */
       
   368     void LoadGuideLineBitmapsL();
       
   369     
       
   370     /**
       
   371      * Load layouts for borders from LAF.
       
   372      *
       
   373      * @param aVarity Varity for LAF
       
   374      */
       
   375     void LoadBorderLayout( TInt aVarity );
       
   376 
       
   377     /**
       
   378      * Load layouts for shadows from LAF.
       
   379      *
       
   380      * @param aVarity Varity for LAF
       
   381      */
       
   382     void LoadShadowLayout( TInt aVarity );
       
   383     
       
   384     /**
       
   385      * Load layouts for guidelines from LAF.
       
   386      *
       
   387      * @param aVarity Varity for LAF
       
   388      */
       
   389     void LoadGuideLineLayout( TInt aVarity );
       
   390 
       
   391     /**
       
   392      * Draw borders.
       
   393      *
       
   394      */
       
   395     void DrawBorders( CWindowGc& aGc ) const;
       
   396     
       
   397     /**
       
   398      * Draw shadows.
       
   399      *
       
   400      */
       
   401     void DrawShadows( CWindowGc& aGc ) const;
       
   402 
       
   403     /**
       
   404      * Draw guideliens.
       
   405      *
       
   406      */    
       
   407     void DrawGuideLines( CWindowGc& aGc ) const;    
       
   408     
       
   409 // From MAknInfoPopupNoteObserver
       
   410     /**
       
   411     * Handles events reported from info popup note.
       
   412     * @param aController The controller that controls the note, from
       
   413     *   where the event originates.
       
   414     * @param aEvent The event.
       
   415     */
       
   416     void HandleInfoPopupNoteEvent( CAknInfoPopupNoteController* aController,
       
   417             TAknInfoPopupNoteEvent aEvent );
       
   418     
       
   419 private: // data
       
   420 
       
   421     /**
       
   422      * When this timer time out, the inputting of new character is over.
       
   423      * Own.
       
   424      */
       
   425     CPeriodic* iTimeToSave;
       
   426     
       
   427     /**
       
   428      * To control drawing speed
       
   429      * Own.
       
   430      */
       
   431     CPeriodic* iTimeToDrawNext;
       
   432 
       
   433     /**
       
   434      * Contain the points need to be drawn on screen
       
   435      * Own
       
   436      */
       
   437     RArray<TPoint> iPointArrayDraw;
       
   438 
       
   439     /**
       
   440      * Contain the character model points
       
   441      * Own
       
   442      */
       
   443     RArray<TPoint> iPointArrayModel;
       
   444     
       
   445     /**
       
   446      * Current control state 
       
   447      */
       
   448     TBoxState iBoxState;
       
   449     
       
   450     /**
       
   451      * Observe user's input
       
   452      * Not own
       
   453      */
       
   454     MTruiHwrBoxObserver* iHwrBoxObserver;
       
   455     
       
   456     /**
       
   457      * Use this attribute to count the last animated point
       
   458      * zero implies the first point
       
   459      */
       
   460     TInt iLastAnimatedPoint;
       
   461     
       
   462     /**
       
   463      * Guideline top left point
       
   464      */
       
   465     TPoint iGuideLineTopL;
       
   466     
       
   467     /**
       
   468      * Guideline top right point
       
   469      */
       
   470     TPoint iGuideLineTopR;
       
   471     
       
   472     /**
       
   473      * Guideline bottom left point
       
   474      */
       
   475     TPoint iGuideLineBottomL;
       
   476     
       
   477     /**
       
   478      * Guideline bottom right point
       
   479      */
       
   480     TPoint iGuideLineBottomR;
       
   481     
       
   482     /**
       
   483      * Indicate pen position
       
   484      */
       
   485     TBool iPenInRect;   
       
   486           
       
   487     /**
       
   488      * Flag of training box.
       
   489      */
       
   490     TUint iFlag;
       
   491     
       
   492     /**
       
   493      * Component used to show tooltip
       
   494      * Own.
       
   495      */
       
   496     CAknInfoPopupNoteController* iTooltip;
       
   497     
       
   498     /**
       
   499      * Check if draw bottom guideline.
       
   500      */
       
   501     TBool iBottomGuideLineDisplay;
       
   502     
       
   503     /**
       
   504      * Check if draw bottom guideline.     
       
   505      */    
       
   506     TBool iTopGuideLineDisplay;
       
   507         
       
   508     /**
       
   509      * Pointer array to store pointers to bitmaps of borders
       
   510      * 
       
   511      * Own
       
   512      */    
       
   513     RPointerArray<CFbsBitmap> iBorderBitmaps;
       
   514 
       
   515     /**
       
   516      * Pointer array to store pointers to mask bitmaps of borders
       
   517      * 
       
   518      * Own
       
   519      */
       
   520     RPointerArray<CFbsBitmap> iBorderBitmapMasks;
       
   521 
       
   522     /**
       
   523      * Array to store pointers to TAknLayoutRect for borders
       
   524      * 
       
   525      * Own
       
   526      */
       
   527     RArray<TAknLayoutRect> iBorderLayout;
       
   528 
       
   529 
       
   530     /**
       
   531      * Pointer array to store pointers to bitmaps of shadows
       
   532      * 
       
   533      * Own
       
   534      */    
       
   535     RPointerArray<CFbsBitmap> iShadowBitmaps;
       
   536 
       
   537     /**
       
   538      * Pointer array to store pointers to mask bitmaps of shadows
       
   539      * 
       
   540      * Own
       
   541      */
       
   542     RPointerArray<CFbsBitmap> iShadowBitmapMasks;
       
   543 
       
   544     /**
       
   545      * Array to store pointers to TAknLayoutRect for shadows
       
   546      * 
       
   547      * Own
       
   548      */
       
   549     RArray<TAknLayoutRect> iShadowLayout;
       
   550     
       
   551     /**
       
   552      * Pointer array to store pointers to bitmaps of guideline
       
   553      * 
       
   554      * Own
       
   555      */    
       
   556     RPointerArray<CFbsBitmap> iGuideLineBitmaps;
       
   557 
       
   558     /**
       
   559      * Pointer array to store pointers to mask bitmaps of guideline
       
   560      * 
       
   561      * Own
       
   562      */
       
   563     RPointerArray<CFbsBitmap> iGuideLineBitmapMasks;
       
   564 
       
   565     /**
       
   566      * Array to store pointers to TAknLayoutRect for guidelines
       
   567      * 
       
   568      * Own
       
   569      */
       
   570     RArray<TAknLayoutRect> iGuideLineLayout;
       
   571     
       
   572     /**
       
   573      * Rect of drawable for trails;
       
   574      * 
       
   575      */
       
   576     TRect iDrawabelRect;
       
   577     
       
   578     /**
       
   579      * Color of pen;
       
   580      * 
       
   581      */
       
   582     TRgb iPenColor;
       
   583     
       
   584     
       
   585     CAknsBasicBackgroundControlContext* iBgContext;
       
   586     
       
   587     TBool iStartSave;
       
   588     };    
       
   589 
       
   590 #endif // TRAININGUIHWRBOX_H
       
   591 
       
   592 // end of file
       
   593