textinput/peninputhwrtrui/src/truihwrbox.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     1 /*
       
     2 * Copyright (c) 2009 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:  Implement of class CTruiHwrBox
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <centralrepository.h>
       
    21 #include <settingsinternalcrkeys.h>
       
    22 #include <aknlayoutscalable_apps.cdl.h>
       
    23 #include <layoutmetadata.cdl.h>
       
    24 #include <AknUtils.h>
       
    25 #include <AknsSkinInstance.h>
       
    26 #include <AknsDrawUtils.h>
       
    27 #include <aknlayoutscalable_avkon.cdl.h>
       
    28 #include <AknsBasicBackgroundControlContext.h>
       
    29 
       
    30 #include <AknsConstants.h>
       
    31 #include <trui_icons.mbg>
       
    32 
       
    33 #include "truihwrbox.h"
       
    34 #include "truihwrboxobserver.h"
       
    35 #include "truiappui.h"
       
    36 #include "truiappui.h"
       
    37 #include "truiengine.h"
       
    38 
       
    39 #ifdef __WINS__
       
    40 static const TInt KWritePeriod = 1500000;
       
    41 #else
       
    42 static const TInt KWritePeriod = 1000000;
       
    43 #endif
       
    44 
       
    45 #ifdef __WINS__
       
    46 static const TInt KDrawSpeed = 30000;
       
    47 #else
       
    48 static const TInt KDrawSpeed = 30000;
       
    49 #endif
       
    50 
       
    51 const TInt KFirstPoint = -1;
       
    52 const TSize KGuideLinePenSize = TSize( 1, 1 );
       
    53 const TSize KLinePenSize = TSize( 4, 4 );
       
    54 const TInt KFirstEventDelay = 0;
       
    55 
       
    56 _LIT( KTRUIICONSFILENAME, "\\resource\\apps\\trui_icons.mif" );
       
    57 
       
    58 const TInt KTopGuideLineIndex = 0;
       
    59 const TInt KBottomGuideLineIndex = 1;
       
    60 
       
    61 const TInt KGuideLineWidthRadio = 10;
       
    62 
       
    63 // ======== MEMBER FUNCTIONS ========
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Two-phased constructor.
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CTruiHwrBox* CTruiHwrBox::NewL( CCoeControl* aParent,
       
    70                                 MTruiHwrBoxObserver* aHwrBoxObserver,
       
    71                                 MAknsControlContext* aBgContext )
       
    72     {
       
    73     CTruiHwrBox* self = CTruiHwrBox::NewLC( aParent, aHwrBoxObserver,
       
    74                                             aBgContext );
       
    75     CleanupStack::Pop( self );
       
    76     return self;
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // Two-phased constructor.
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 CTruiHwrBox* CTruiHwrBox::NewLC( CCoeControl* aParent,
       
    84                                  MTruiHwrBoxObserver* aHwrBoxObserver,
       
    85                                  MAknsControlContext* aBgContex )
       
    86     {
       
    87     CTruiHwrBox* self = new ( ELeave ) CTruiHwrBox();
       
    88     CleanupStack::PushL( self );
       
    89     self->ConstructL( aParent, aHwrBoxObserver,
       
    90                       aBgContex );
       
    91     return self;
       
    92     }
       
    93         
       
    94 // -----------------------------------------------------------------------------
       
    95 // CTruiHwrBox::CTruiHwrBox()
       
    96 // C++ default constructor can NOT contain any code, that might leave.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 CTruiHwrBox::CTruiHwrBox()
       
   100     {
       
   101     // No implementation required
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CTruiHwrBox::ConstructL()
       
   106 // Symbian 2nd phase constructor can leave.
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CTruiHwrBox::ConstructL( CCoeControl* aParent,
       
   110                               MTruiHwrBoxObserver* aHwrBoxObserver,
       
   111                               MAknsControlContext* aBgContext )
       
   112     {
       
   113     if ( aParent ) 
       
   114         {
       
   115         SetContainerWindowL( *aParent );
       
   116         }
       
   117     else
       
   118         {
       
   119         CreateWindowL();
       
   120         }
       
   121         
       
   122     SetHwrBoxObserver( aHwrBoxObserver );
       
   123     
       
   124     // Create tooltip
       
   125     iTooltip = CAknInfoPopupNoteController::NewL();    
       
   126     iTooltip->SetTooltipModeL( ETrue );
       
   127     iTooltip->AddObserverL( *this );
       
   128     
       
   129     iBoxState = ENewModelStop;    
       
   130     iTimeToSave = CPeriodic::NewL( CActive::EPriorityHigh ); // neutral priority
       
   131     iTimeToDrawNext = CPeriodic::NewL( CActive::EPriorityStandard ); // neutral priority
       
   132     
       
   133     iPointArrayDraw.Reset();
       
   134     iPointArrayModel.Reset();
       
   135     
       
   136     LoadBorderBitmapsL();
       
   137     LoadShadowBitmapsL();
       
   138     LoadGuideLineBitmapsL();
       
   139     
       
   140     EnableDragEvents();    
       
   141     
       
   142     iBgContext = static_cast<CAknsBasicBackgroundControlContext*>( aBgContext );
       
   143     
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CTruiHwrBox::~CTruiHwrBox()
       
   148 // Destructor.
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 CTruiHwrBox::~CTruiHwrBox()
       
   152     {
       
   153     if ( iTooltip )
       
   154         {
       
   155         iTooltip->RemoveObserver( *this );
       
   156         }    
       
   157     HideInfoPopupNote();
       
   158     
       
   159     // Cancel and delete timer.
       
   160     if ( iTimeToSave )
       
   161         {
       
   162         iTimeToSave->Cancel();
       
   163         delete iTimeToSave;
       
   164         }
       
   165       
       
   166     if ( iTimeToDrawNext )
       
   167         {
       
   168         iTimeToDrawNext->Cancel();
       
   169         delete iTimeToDrawNext;
       
   170         }
       
   171     
       
   172     iPointArrayDraw.Close();
       
   173     iPointArrayModel.Close();
       
   174     delete iTooltip;
       
   175     
       
   176     iBorderBitmaps.ResetAndDestroy();
       
   177     iBorderBitmapMasks.ResetAndDestroy();
       
   178     iBorderLayout.Close();
       
   179     
       
   180     iShadowBitmaps.ResetAndDestroy();
       
   181     iShadowBitmapMasks.ResetAndDestroy();
       
   182     iShadowLayout.Close();
       
   183         
       
   184     iGuideLineBitmaps.ResetAndDestroy();
       
   185     iGuideLineBitmapMasks.ResetAndDestroy();
       
   186     iGuideLineLayout.Close();
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // Draws control to given area
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CTruiHwrBox::Draw( const TRect& /*aRect*/ ) const
       
   194     {
       
   195     // Get the standard graphics context 
       
   196     CWindowGc& gc = SystemGc();        
       
   197     
       
   198     // Set context
       
   199     PrepareContext( gc );
       
   200     
       
   201     // Gets the control's extent
       
   202     TRect rect = Rect();
       
   203     if ( iBgContext )
       
   204         {
       
   205         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   206         if ( !AknsDrawUtils::Background( skin, iBgContext, 
       
   207                                          gc, rect ) ) 
       
   208             {
       
   209             gc.Clear( rect );
       
   210             }
       
   211         }
       
   212         
       
   213     if ( iFlag & EFrameHwrBox == EFrameHwrBox )
       
   214         {
       
   215         // Draw border
       
   216         DrawBorders( gc );
       
   217         // Draw shawdow
       
   218         DrawShadows( gc ); 
       
   219         }
       
   220     
       
   221     // Get repository
       
   222     CRepository* repository = NULL;
       
   223     TRAPD( err, repository = CRepository::NewL( KCRUidPersonalizationSettings ) );
       
   224     if ( err == KErrNone )
       
   225         {
       
   226         TInt guideLine;
       
   227         repository->Get( KSettingsPenInputGuideLine, guideLine );
       
   228         delete repository;
       
   229         repository = NULL;
       
   230         // Draw guideline
       
   231         if ( guideLine )
       
   232             {
       
   233             // Draw guidelines            
       
   234             DrawGuideLines( gc );   
       
   235             }        
       
   236         }        
       
   237     // Draw work area  
       
   238     gc.SetPenSize( KLinePenSize );
       
   239     DrawTrails( gc );
       
   240     }
       
   241         
       
   242 TInt CTruiHwrBox::TimeToSaveL( TAny* aObject )
       
   243     {
       
   244     ( (CTruiHwrBox*)aObject )->SaveModelL(); // cast, and call non-static function
       
   245     return KErrNone;
       
   246     }
       
   247     
       
   248 TInt CTruiHwrBox::TimeToDrawNextL( TAny* aObject )
       
   249     {
       
   250     ( (CTruiHwrBox*)aObject )->DrawNextL(); // cast, and call non-static function
       
   251     return KErrNone;
       
   252     }
       
   253     
       
   254 // -----------------------------------------------------------------------------
       
   255 // CTruiHwrBox::TimedOut()
       
   256 // Timer control, called everytime the time times out.
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CTruiHwrBox::SaveModelL()
       
   260     {
       
   261     if ( iBoxState == ENewModelDraw )
       
   262         {
       
   263         // Restore all screen to invalid region.
       
   264         Window().Invalidate();
       
   265         //Cancel the timer
       
   266         iTimeToSave->Cancel();
       
   267         iBoxState = EExistModelStop;
       
   268         SetPointerCapture( EFalse );
       
   269         iPointArrayModel.Reset();
       
   270         for ( TInt i=0; i<iPointArrayDraw.Count(); i++ )
       
   271             {
       
   272             iPointArrayModel.Append( iPointArrayDraw[i] );
       
   273             }
       
   274         //can't save an empty model
       
   275         if ( iPointArrayModel.Count() > 0 )
       
   276             {                        
       
   277             if ( iHwrBoxObserver )
       
   278                 {
       
   279                 iHwrBoxObserver->SaveNewModelL();
       
   280                 }            
       
   281             }
       
   282         else
       
   283             {
       
   284             ClearExistModel();
       
   285             }
       
   286         iStartSave = EFalse;
       
   287         }
       
   288     }
       
   289     
       
   290 // -----------------------------------------------------------------------------
       
   291 // Compare the numbers of points of two arrays at first. if they are not same, 
       
   292 // add a new point from iPointArrayModel to iPointArrayDraw. then draw a new line
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 void CTruiHwrBox::DrawNextL()
       
   296     {
       
   297     // Check HwrBox state at first and then Check if model is drawn acompletely
       
   298     if ( iBoxState == EExistModelDraw &&
       
   299         iPointArrayModel.Count() > iPointArrayDraw.Count() )
       
   300         {
       
   301         // Add new point to iPointArrayDraw
       
   302         iPointArrayDraw.AppendL( iPointArrayModel[ iPointArrayDraw.Count() ] );
       
   303         // Update the screen
       
   304         DrawModel();
       
   305         }
       
   306     else
       
   307         {
       
   308         iBoxState = EExistModelStop;
       
   309         iTimeToDrawNext->Cancel();
       
   310         Window().Invalidate();
       
   311         }
       
   312     }
       
   313     
       
   314 // ---------------------------------------------------------------------------
       
   315 // Draw an existing model
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void CTruiHwrBox::PlayAnimation( TBool aIsScale, const TSize& aRefSize )
       
   319     {
       
   320     if ( ( iBoxState == EExistModelStop || iBoxState == EExistModelDraw ) 
       
   321         && iPointArrayModel.Count() )
       
   322         {
       
   323         // Check and scale model points         
       
   324         if ( aIsScale )
       
   325             {
       
   326             // Scale model points
       
   327             ScaleModel( aRefSize, Rect().Size(), iPointArrayModel );
       
   328             }
       
   329             
       
   330         //Cancel the timer at first
       
   331         iTimeToDrawNext->Cancel();
       
   332         
       
   333         //Clear the box
       
   334         iPointArrayDraw.Reset();
       
   335         if ( Parent() )
       
   336             {            
       
   337             Parent()->DrawNow();            
       
   338             }        
       
   339         
       
   340         //Set index of point need to be drawn to the beginning
       
   341         iLastAnimatedPoint = KFirstPoint;
       
   342         
       
   343         //Set animate timer
       
   344         iTimeToDrawNext->Start( KFirstEventDelay, KDrawSpeed, TCallBack( TimeToDrawNextL, this ) );
       
   345         
       
   346         //Change box state
       
   347         iBoxState = EExistModelDraw;
       
   348         }
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // Clear the existing model
       
   353 // ---------------------------------------------------------------------------
       
   354 //
       
   355 void CTruiHwrBox::ClearExistModel()
       
   356     {
       
   357     switch ( iBoxState )
       
   358         {
       
   359         case EExistModelDraw:
       
   360             {
       
   361             //animation is playing, cancel the timer before clear it
       
   362             iTimeToDrawNext->Cancel();
       
   363             break;
       
   364             }
       
   365         case ENewModelDraw:
       
   366             {
       
   367             //new model is inputting, cancel the timer before clear it
       
   368             iTimeToSave->Cancel();
       
   369             iStartSave = EFalse;
       
   370             break;
       
   371             }
       
   372         case EExistModelStop:
       
   373         case ENewModelStop:
       
   374         default:
       
   375             {
       
   376             }
       
   377         }
       
   378     iPointArrayModel.Reset();
       
   379     iPointArrayDraw.Reset();
       
   380     iBoxState = ENewModelStop;
       
   381     Window().Invalidate();
       
   382     }
       
   383         
       
   384 // ---------------------------------------------------------------------------
       
   385 // Handles an event from an observed control.
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 void CTruiHwrBox::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   389     {        
       
   390     if ( iFlag & EReadOnlyHwrBox )
       
   391         {
       
   392         // Readonly, don't handle pointer event.
       
   393         return;
       
   394         }
       
   395             
       
   396     CCoeControl::HandlePointerEventL( aPointerEvent );    
       
   397     if ( AknLayoutUtils::PenEnabled() )
       
   398         {
       
   399         switch( aPointerEvent.iType )
       
   400             {
       
   401             case TPointerEvent::EButton1Down:
       
   402                 {
       
   403                 Window().Invalidate();
       
   404                 if ( IsContained( aPointerEvent.iPosition ) )
       
   405                     {   
       
   406                     HideInfoPopupNote();                 
       
   407                     iPenInRect = ETrue;
       
   408                     if ( iBoxState == ENewModelStop )
       
   409                         {
       
   410                         //change box state
       
   411                         iBoxState = ENewModelDraw;
       
   412                         SetPointerCapture( ETrue );
       
   413                         //start from the point where button is down
       
   414                         iPointArrayDraw.Append( aPointerEvent.iPosition - Position() );
       
   415                         iLastAnimatedPoint = KFirstPoint;
       
   416                         DrawModel();
       
   417                         }
       
   418                     else if ( iBoxState == ENewModelDraw )
       
   419                         {
       
   420                         //cancel the iTimeToSave
       
   421                         iTimeToSave->Cancel();
       
   422                         iStartSave = EFalse;
       
   423                         //start from the point where button is down
       
   424                         iPointArrayDraw.Append( aPointerEvent.iPosition - Position() );
       
   425                         DrawModel();
       
   426                         }
       
   427                     else
       
   428                         {
       
   429                         if ( iHwrBoxObserver )
       
   430                             {
       
   431                             iHwrBoxObserver->HandleEventL( MTruiHwrBoxObserver::EModelExist );
       
   432                             }                        
       
   433                         }
       
   434                     }
       
   435                 else
       
   436                     {
       
   437                     iPenInRect = EFalse;
       
   438                     }
       
   439                 break;    
       
   440                 }
       
   441             case TPointerEvent::EButton1Up:    
       
   442                 {                
       
   443                 if ( iBoxState == ENewModelDraw )
       
   444                     {
       
   445                     iPointArrayDraw.Append( KTail ); 
       
   446                     if ( !iStartSave )
       
   447                         {
       
   448                         iStartSave = ETrue;
       
   449                         iTimeToSave->Start( KWritePeriod,
       
   450                                             KWritePeriod,
       
   451                                             TCallBack( TimeToSaveL, this ) );
       
   452                         }
       
   453                     }
       
   454                 break;
       
   455                 }
       
   456             case TPointerEvent::EDrag:
       
   457             case TPointerEvent::EMove:
       
   458                 {
       
   459                 if ( iBoxState == ENewModelDraw )
       
   460                     {                    
       
   461                     if ( IsContained( aPointerEvent.iPosition ) )
       
   462                         {
       
   463                         Window().Invalidate();
       
   464                         HideInfoPopupNote(); 
       
   465                         //Pen go into available rect again, start an new trace
       
   466                         if ( iPenInRect == EFalse )
       
   467                             {
       
   468                             iTimeToSave->Cancel();
       
   469                             iStartSave = EFalse;
       
   470                             }
       
   471                         iPointArrayDraw.Append( aPointerEvent.iPosition - Position() );
       
   472                         DrawModel();
       
   473                         iPenInRect = ETrue;
       
   474                         }
       
   475                     else
       
   476                         {
       
   477                         if ( iPenInRect )
       
   478                             {
       
   479                             iPointArrayDraw.Append( KTail );                           
       
   480                             if ( !iStartSave )
       
   481                                 {
       
   482                                 iStartSave = ETrue;
       
   483                                 iTimeToSave->Start( KWritePeriod,
       
   484                                                     KWritePeriod,
       
   485                                                     TCallBack( TimeToSaveL, 
       
   486                                                                this ) );
       
   487                                 }
       
   488                             iPenInRect = EFalse;
       
   489                             }
       
   490                         }
       
   491                     }
       
   492                 break;
       
   493                 }
       
   494             default:
       
   495                 break;
       
   496             }
       
   497         }
       
   498     }
       
   499 
       
   500 // ---------------------------------------------------------------------------
       
   501 // Handles an event from an observed control.
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 TKeyResponse CTruiHwrBox::OfferKeyEventL( const TKeyEvent& /*aKeyEvent*/,
       
   505                                                 TEventCode /*aType*/ )
       
   506     {
       
   507     return EKeyWasConsumed;
       
   508     }
       
   509     
       
   510 // --------------------------------------------------------------------------
       
   511 // CTruiHwrBox::SetHwrBoxObserver
       
   512 // --------------------------------------------------------------------------
       
   513 //
       
   514 void CTruiHwrBox::SetHwrBoxObserver( MTruiHwrBoxObserver* aHwrBoxObserver )
       
   515     {
       
   516     iHwrBoxObserver = aHwrBoxObserver;
       
   517     }
       
   518     
       
   519 // --------------------------------------------------------------------------
       
   520 // Get the HwrBox's model.
       
   521 // --------------------------------------------------------------------------
       
   522 //
       
   523 RArray<TPoint>& CTruiHwrBox::Model()
       
   524     {
       
   525     return iPointArrayModel;
       
   526     }
       
   527     
       
   528 // --------------------------------------------------------------------------
       
   529 // Draw character model
       
   530 // --------------------------------------------------------------------------
       
   531 //
       
   532 void CTruiHwrBox::DrawModel()
       
   533     {
       
   534     if ( IsActivated() && iPointArrayDraw.Count() &&
       
   535          iLastAnimatedPoint + 1 < iPointArrayDraw.Count() )
       
   536         {
       
   537         // Get system graphic content
       
   538         CWindowGc& gc = SystemGc();
       
   539         RWindow& window = Window();
       
   540         gc.Activate( window );  
       
   541         window.Invalidate( Rect() );
       
   542         window.BeginRedraw( Rect() );
       
   543         Draw( Rect() );
       
   544         window.EndRedraw();
       
   545         gc.Deactivate();        
       
   546         }
       
   547     }
       
   548     
       
   549 // ---------------------------------------------------------------------------
       
   550 // Responds to changes to the size and position of the contents of this control.
       
   551 // ---------------------------------------------------------------------------
       
   552 //
       
   553 void CTruiHwrBox::SizeChanged()
       
   554     {
       
   555     LoadBorderLayout( 0 );
       
   556     for ( TInt i = 0; i < iBorderLayout.Count()
       
   557                       && i < iBorderBitmaps.Count()
       
   558                       && i < iBorderBitmapMasks.Count(); i++ )
       
   559         {
       
   560         TSize size = iBorderLayout[i].Rect().Size();
       
   561 	    AknIconUtils::SetSize( iBorderBitmaps[i], size, EAspectRatioNotPreserved );
       
   562 	    AknIconUtils::SetSize( iBorderBitmapMasks[i], size, EAspectRatioNotPreserved );        
       
   563         }
       
   564     
       
   565     LoadShadowLayout( 0 );
       
   566     for ( TInt i = 0; i < iShadowLayout.Count()
       
   567                       && i < iShadowBitmaps.Count()
       
   568                       && i < iShadowBitmapMasks.Count(); i++ )
       
   569         {
       
   570         TSize size = iShadowLayout[i].Rect().Size();
       
   571 	    AknIconUtils::SetSize( iShadowBitmaps[i], size, EAspectRatioNotPreserved );
       
   572 	    AknIconUtils::SetSize( iShadowBitmapMasks[i], size, EAspectRatioNotPreserved );
       
   573         }
       
   574     
       
   575     LoadGuideLineLayout( 0 );    
       
   576     // Guide line position
       
   577     TInt margin = Size().iWidth / KGuideLineWidthRadio;
       
   578     
       
   579     iGuideLineBottomL.iX = Position().iX + margin;
       
   580     iGuideLineTopL.iX = Position().iX + margin;
       
   581     
       
   582     for ( TInt i = 0; i < iGuideLineLayout.Count()
       
   583                       && i < iGuideLineBitmaps.Count()
       
   584                       && i < iGuideLineBitmapMasks.Count(); i++ )
       
   585         {
       
   586         TSize size = iGuideLineLayout[i].Rect().Size();
       
   587         size.iWidth = Size().iWidth - margin * 2;
       
   588 	    AknIconUtils::SetSize( iGuideLineBitmaps[i], size, EAspectRatioNotPreserved );
       
   589 	    AknIconUtils::SetSize( iGuideLineBitmapMasks[i], size, EAspectRatioNotPreserved );
       
   590         }
       
   591     
       
   592     // Caculate hwr_training_write_pane_g7 for drawable rect
       
   593     TRect rect = Rect();
       
   594     TAknWindowComponentLayout drawable_rect_layout = 
       
   595                AknLayoutScalable_Apps::hwr_training_write_pane_g7( 0 );
       
   596     TAknLayoutRect drawable_rect_layout_rect;
       
   597     drawable_rect_layout_rect.LayoutRect( rect, drawable_rect_layout );
       
   598     iDrawabelRect = drawable_rect_layout_rect.Rect();
       
   599     iDrawabelRect.Shrink( KLinePenSize.iWidth ,
       
   600                       KLinePenSize.iHeight );
       
   601     iPenColor = drawable_rect_layout_rect.Color();    
       
   602 
       
   603     TInt guidinglinetop(0);
       
   604     TInt guidinglinebottom(0);
       
   605     CTruiEngine* engine = static_cast<CTruiAppUi*>( iEikonEnv->AppUi() )->HwrEngine();
       
   606     engine->GetGuidingLinePos( iDrawabelRect.Size(), guidinglinetop, guidinglinebottom );
       
   607     SetGuidingLine( guidinglinetop, guidinglinebottom );    
       
   608     }
       
   609 
       
   610 // ---------------------------------------------------------------------------
       
   611 // From class CCoeControl.
       
   612 // Handles a change to the control's resources.
       
   613 // ---------------------------------------------------------------------------
       
   614 //
       
   615 void CTruiHwrBox::HandleResourceChange( TInt aType )
       
   616     {
       
   617     CCoeControl::HandleResourceChange( aType );
       
   618     if ( aType == KEikMessageUnfadeWindows )
       
   619         {
       
   620         DrawDeferred();
       
   621         }
       
   622     if ( aType == KAknsMessageSkinChange )
       
   623         {
       
   624         TRAP_IGNORE(
       
   625             LoadBorderBitmapsL();
       
   626             LoadShadowBitmapsL();
       
   627             LoadGuideLineBitmapsL();        
       
   628             )
       
   629         SizeChanged();
       
   630         }    
       
   631     }
       
   632 
       
   633 // ---------------------------------------------------------------------------
       
   634 // From class CCoeControl.
       
   635 // Handle focus changed.
       
   636 // ---------------------------------------------------------------------------
       
   637 //
       
   638 void CTruiHwrBox::FocusChanged( TDrawNow /*aDrawNow*/ )
       
   639     {    
       
   640     if ( !IsFocused() && iBoxState == ENewModelDraw )    
       
   641         {
       
   642         iPointArrayDraw.Append( KTail );
       
   643         TRAP_IGNORE( SaveModelL() );
       
   644         }
       
   645     }
       
   646 
       
   647 // ---------------------------------------------------------------------------
       
   648 // When load model from outside, set box state
       
   649 // ---------------------------------------------------------------------------
       
   650 //
       
   651 void CTruiHwrBox::ModelIsReady( TBool aReady )
       
   652     {
       
   653     if ( aReady )
       
   654         {
       
   655         iBoxState = EExistModelStop;
       
   656         }
       
   657     else
       
   658         {
       
   659         iBoxState = ENewModelStop;
       
   660         }
       
   661     }
       
   662 
       
   663 TRect CTruiHwrBox::DrawableRect() const
       
   664     {
       
   665     return iDrawabelRect;
       
   666     }
       
   667 
       
   668 // ---------------------------------------------------------------------------
       
   669 // Set editing mode to readonly or writable
       
   670 // ---------------------------------------------------------------------------
       
   671 //
       
   672 void CTruiHwrBox::SetHwrBoxReadOnly( TBool aReadOnly )
       
   673     {
       
   674     TUint flag = aReadOnly ? EReadOnlyHwrBox : EWritableHwrBox;
       
   675     iFlag &= ( ~EReadOnlyHwrBox & ~EWritableHwrBox );
       
   676     iFlag |= flag;     
       
   677     }
       
   678     
       
   679 // ---------------------------------------------------------------------------
       
   680 // Get the Hwrbox's state
       
   681 // ---------------------------------------------------------------------------
       
   682 //
       
   683 TInt CTruiHwrBox::BoxState() const
       
   684     {
       
   685     return iBoxState;
       
   686     }
       
   687 
       
   688 // ---------------------------------------------------------------------------
       
   689 // Pause the playing of animation
       
   690 // ---------------------------------------------------------------------------
       
   691 //
       
   692 void CTruiHwrBox::PausePlaying()
       
   693     {
       
   694     if ( iBoxState == EExistModelDraw  )
       
   695         {
       
   696         iBoxState = EExistModelStop;
       
   697         iTimeToDrawNext->Cancel();
       
   698         Window().Invalidate();
       
   699         }
       
   700     }
       
   701     
       
   702 // ---------------------------------------------------------------------------
       
   703 // Resume the playing of animation
       
   704 // ---------------------------------------------------------------------------
       
   705 //
       
   706 void CTruiHwrBox::ResumePlaying()
       
   707     {
       
   708     // Check HwrBox state at first and then Check if model is drawn acompletely
       
   709     if ( iBoxState == EExistModelStop &&
       
   710         iPointArrayModel.Count() > iPointArrayDraw.Count() )
       
   711         {
       
   712         
       
   713         //Cancel the timer at first
       
   714         iTimeToDrawNext->Cancel();
       
   715 
       
   716         //Set animate timer
       
   717         iTimeToDrawNext->Start( KFirstEventDelay, KDrawSpeed, 
       
   718                                 TCallBack(TimeToDrawNextL, this) );
       
   719         
       
   720         //Change box state
       
   721         iBoxState = EExistModelDraw;
       
   722         }
       
   723     }
       
   724 
       
   725 // ---------------------------------------------------------------------------
       
   726 // Set Guiding Line
       
   727 // ---------------------------------------------------------------------------
       
   728 //
       
   729 TInt CTruiHwrBox::SetGuidingLine( TInt aTop, TInt aBottom )
       
   730     {
       
   731     TRect rect = DrawableRect();
       
   732     if ( Size().iHeight <= aBottom || aBottom <= 0
       
   733          || Size().iHeight <= aTop || aTop <= 0 )
       
   734         {
       
   735         return KErrArgument;
       
   736         }
       
   737             
       
   738     iGuideLineTopL.iY = rect.iTl.iY + aTop;
       
   739     iGuideLineBottomL.iY = rect.iTl.iY + aBottom;
       
   740     return KErrNone;
       
   741     }
       
   742     
       
   743 // ---------------------------------------------------------------------------
       
   744 // Check if the point is contained in drawing area
       
   745 // ---------------------------------------------------------------------------
       
   746 // 
       
   747 TBool CTruiHwrBox::IsContained( const TPoint& aPoint ) const
       
   748     {
       
   749     return DrawableRect().Contains( aPoint );
       
   750     }
       
   751    
       
   752 // ---------------------------------------------------------------------------
       
   753 // Adjust shortcut model's point to fit the popup hwr box. 
       
   754 // ---------------------------------------------------------------------------
       
   755 //    
       
   756 void CTruiHwrBox::ScaleModel( const TSize& aOriginSize, 
       
   757                               const TSize& aRealSize, 
       
   758                               RArray<TPoint>& aModel )
       
   759     {
       
   760     CTruiEngine* engine = static_cast<CTruiAppUi*>( iEikonEnv->AppUi() )->HwrEngine();
       
   761     TInt originTop;    
       
   762     TInt originBottom;
       
   763     engine->GetGuidingLinePos( aOriginSize, originTop, originBottom );
       
   764     TInt realTop;
       
   765     TInt realBottom;
       
   766     engine->GetGuidingLinePos( aRealSize, realTop, realBottom );
       
   767     for ( TInt i =0; i < aModel.Count(); i++ )
       
   768         {                
       
   769         if ( aModel[i] != KTail )
       
   770             {
       
   771             aModel[i].iX = aModel[i].iX * realBottom / originBottom;
       
   772             aModel[i].iY = aModel[i].iY * realBottom / originBottom;            
       
   773             }        
       
   774         }
       
   775     }
       
   776     
       
   777 // -----------------------------------------------------------------------------
       
   778 // Draws all points.
       
   779 // -----------------------------------------------------------------------------
       
   780 //
       
   781 void CTruiHwrBox::DrawTrails( CWindowGc& aGc ) const
       
   782     {
       
   783     // Draw model
       
   784     if ( iPointArrayDraw.Count() )
       
   785         {
       
   786         //Draw from the first point in the array
       
   787         TInt lastAnimatedPoint( 0 );
       
   788         TPoint relativePos;
       
   789         if ( OwnsWindow() )
       
   790             {
       
   791             relativePos = TPoint( 0, 0 );
       
   792             }
       
   793         else
       
   794             {
       
   795             relativePos = Position();
       
   796             }        
       
   797         aGc.Plot( iPointArrayDraw[lastAnimatedPoint] + relativePos );
       
   798                 
       
   799         // Check if there is point need to be drawn
       
   800         // Plus 1 to lastAnimatedPointIndex since zero implies the first point
       
   801         // in the iLastAnimatedPoint
       
   802         while ( lastAnimatedPoint + 1 < iPointArrayDraw.Count() )
       
   803             {
       
   804             //Check if this is a new arc and increase the index counter
       
   805             if ( iPointArrayDraw[lastAnimatedPoint++] != KTail )
       
   806                 {
       
   807                 //It is not a new arc, then check if this is the end of an arc
       
   808                 if ( iPointArrayDraw[lastAnimatedPoint] != KTail )
       
   809                     {
       
   810                     //It is not the end of an arc, so draw line
       
   811                     aGc.DrawLineTo( iPointArrayDraw[lastAnimatedPoint]
       
   812                                    + relativePos );
       
   813                     }
       
   814                 }
       
   815             else
       
   816                 {
       
   817                 //It is a new arc, so move the pen to the new point 
       
   818                 aGc.Plot( iPointArrayDraw[lastAnimatedPoint]
       
   819                          + relativePos );
       
   820                 }
       
   821             }
       
   822         }
       
   823     }   
       
   824 
       
   825 // --------------------------------------------------------------------------
       
   826 // Set context for this control.
       
   827 // --------------------------------------------------------------------------
       
   828 //
       
   829 void CTruiHwrBox::PrepareContext( CWindowGc& aGc ) const
       
   830     {
       
   831     TRgb color;
       
   832     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   833     // Set pen color to the color of test in main area
       
   834     TInt error = AknsUtils::GetCachedColor( skin,
       
   835                                             color,
       
   836                                             KAknsIIDQsnTextColors,
       
   837                                             EAknsCIQsnTextColorsCG6 );
       
   838     if ( !error )
       
   839         {
       
   840         aGc.SetPenColor( color );
       
   841         }
       
   842     }
       
   843     
       
   844 // --------------------------------------------------------------------------
       
   845 // Load bitmaps for border.
       
   846 // --------------------------------------------------------------------------
       
   847 //
       
   848 void CTruiHwrBox::LoadBorderBitmapsL()
       
   849     {
       
   850     iBorderBitmaps.ResetAndDestroy();
       
   851     iBorderBitmapMasks.ResetAndDestroy();
       
   852     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   853     CFbsBitmap* bitmapLeft;
       
   854     CFbsBitmap* bitmapLeftMask;
       
   855     AknsUtils::CreateColorIconL( skin,
       
   856                                  KAknsIIDQgnGrafFepBgColour,
       
   857                                  KAknsIIDQsnIconColors,
       
   858                                  EAknsCIQsnIconColorsCG14,
       
   859                                  bitmapLeft,
       
   860                                  bitmapLeftMask,
       
   861                                  KTRUIICONSFILENAME,
       
   862                                  EMbmTrui_iconsQgn_graf_fep_bg_colour,
       
   863                                  EMbmTrui_iconsQgn_graf_fep_bg_colour_mask,
       
   864                                  KRgbBlack
       
   865                                  );    
       
   866     iBorderBitmaps.Append( bitmapLeft );
       
   867     iBorderBitmapMasks.Append( bitmapLeftMask );
       
   868 
       
   869     CFbsBitmap* bitmapTop;
       
   870     CFbsBitmap* bitmapTopMask;
       
   871     AknsUtils::CreateColorIconL( skin,
       
   872                                  KAknsIIDQgnGrafFepBgColour,
       
   873                                  KAknsIIDQsnIconColors,
       
   874                                  EAknsCIQsnIconColorsCG14,
       
   875                                  bitmapTop,
       
   876                                  bitmapTopMask,
       
   877                                  KTRUIICONSFILENAME,
       
   878                                  EMbmTrui_iconsQgn_graf_fep_bg_colour,
       
   879                                  EMbmTrui_iconsQgn_graf_fep_bg_colour_mask,
       
   880                                  KRgbBlack
       
   881                                  );    
       
   882     iBorderBitmaps.Append( bitmapTop );
       
   883     iBorderBitmapMasks.Append( bitmapTopMask );
       
   884 
       
   885     CFbsBitmap* bitmapBottom;
       
   886     CFbsBitmap* bitmapBottomMask;
       
   887     AknsUtils::CreateColorIconL( skin,
       
   888                                  KAknsIIDQgnGrafFepBgColour,
       
   889                                  KAknsIIDQsnIconColors,
       
   890                                  EAknsCIQsnIconColorsCG14,
       
   891                                  bitmapBottom,
       
   892                                  bitmapBottomMask,
       
   893                                  KTRUIICONSFILENAME,
       
   894                                  EMbmTrui_iconsQgn_graf_fep_bg_colour,
       
   895                                  EMbmTrui_iconsQgn_graf_fep_bg_colour_mask,
       
   896                                  KRgbBlack
       
   897                                  );    
       
   898     iBorderBitmaps.Append( bitmapBottom );
       
   899     iBorderBitmapMasks.Append( bitmapBottomMask );
       
   900 
       
   901     CFbsBitmap* bitmapRight;
       
   902     CFbsBitmap* bitmapRightMask;
       
   903     AknsUtils::CreateColorIconL( skin,
       
   904                                  KAknsIIDQgnGrafFepBgColour,
       
   905                                  KAknsIIDQsnIconColors,
       
   906                                  EAknsCIQsnIconColorsCG14,
       
   907                                  bitmapRight,
       
   908                                  bitmapRightMask,
       
   909                                  KTRUIICONSFILENAME,
       
   910                                  EMbmTrui_iconsQgn_graf_fep_bg_colour,
       
   911                                  EMbmTrui_iconsQgn_graf_fep_bg_colour_mask,
       
   912                                  KRgbBlack
       
   913                                  );    
       
   914     iBorderBitmaps.Append( bitmapRight );
       
   915     iBorderBitmapMasks.Append( bitmapRightMask );
       
   916     }
       
   917 
       
   918 // --------------------------------------------------------------------------
       
   919 // Load bitmaps for shadows.
       
   920 // --------------------------------------------------------------------------
       
   921 //
       
   922 void CTruiHwrBox::LoadShadowBitmapsL()
       
   923     {
       
   924     iShadowBitmaps.ResetAndDestroy();
       
   925     iShadowBitmapMasks.ResetAndDestroy();    
       
   926     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   927     CFbsBitmap* bitmapTl;
       
   928     CFbsBitmap* bitmapTlMask;
       
   929     AknsUtils::CreateColorIconL( skin,
       
   930                                  KAknsIIDQgnGrafFepPopupShadowTl,
       
   931                                  KAknsIIDQsnIconColors,
       
   932                                  EAknsCIQsnIconColorsCG14,
       
   933                                  bitmapTl,
       
   934                                  bitmapTlMask,
       
   935                                  KTRUIICONSFILENAME,
       
   936                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_tl,
       
   937                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_tl_mask,
       
   938                                  KRgbBlack
       
   939                                  );    
       
   940     iShadowBitmaps.Append( bitmapTl );
       
   941     iShadowBitmapMasks.Append( bitmapTlMask );
       
   942 
       
   943     CFbsBitmap* bitmapT;
       
   944     CFbsBitmap* bitmapTMask;
       
   945     AknsUtils::CreateColorIconL( skin,
       
   946                                  KAknsIIDQgnGrafFepPopupShadowT,
       
   947                                  KAknsIIDQsnIconColors,
       
   948                                  EAknsCIQsnIconColorsCG14,
       
   949                                  bitmapT,
       
   950                                  bitmapTMask,
       
   951                                  KTRUIICONSFILENAME,
       
   952                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_t,
       
   953                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_t_mask,
       
   954                                  KRgbBlack
       
   955                                  );    
       
   956     iShadowBitmaps.Append( bitmapT );
       
   957     iShadowBitmapMasks.Append( bitmapTMask );
       
   958 
       
   959     CFbsBitmap* bitmapTr;
       
   960     CFbsBitmap* bitmapTrMask;
       
   961     AknsUtils::CreateColorIconL( skin,
       
   962                                  KAknsIIDQgnGrafFepPopupShadowTr,
       
   963                                  KAknsIIDQsnIconColors,
       
   964                                  EAknsCIQsnIconColorsCG14,
       
   965                                  bitmapTr,
       
   966                                  bitmapTrMask,
       
   967                                  KTRUIICONSFILENAME,
       
   968                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_tr,
       
   969                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_tr_mask,
       
   970                                  KRgbBlack
       
   971                                  );    
       
   972     iShadowBitmaps.Append( bitmapTr );
       
   973     iShadowBitmapMasks.Append( bitmapTrMask );
       
   974 
       
   975     CFbsBitmap* bitmapL;
       
   976     CFbsBitmap* bitmapLMask;
       
   977     AknsUtils::CreateColorIconL( skin,
       
   978                                  KAknsIIDQgnGrafFepPopupShadowL,
       
   979                                  KAknsIIDQsnIconColors,
       
   980                                  EAknsCIQsnIconColorsCG14,
       
   981                                  bitmapL,
       
   982                                  bitmapLMask,
       
   983                                  KTRUIICONSFILENAME,
       
   984                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_l,
       
   985                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_l_mask,
       
   986                                  KRgbBlack
       
   987                                  );    
       
   988     iShadowBitmaps.Append( bitmapL );
       
   989     iShadowBitmapMasks.Append( bitmapLMask );
       
   990 
       
   991     CFbsBitmap* bitmapBl;
       
   992     CFbsBitmap* bitmapBlMask;
       
   993     AknsUtils::CreateColorIconL( skin,
       
   994                                  KAknsIIDQgnGrafFepPopupShadowBl,
       
   995                                  KAknsIIDQsnIconColors,
       
   996                                  EAknsCIQsnIconColorsCG14,
       
   997                                  bitmapBl,
       
   998                                  bitmapBlMask,
       
   999                                  KTRUIICONSFILENAME,
       
  1000                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_bl,
       
  1001                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_bl_mask,
       
  1002                                  KRgbBlack
       
  1003                                  );    
       
  1004     iShadowBitmaps.Append( bitmapBl );
       
  1005     iShadowBitmapMasks.Append( bitmapBlMask );
       
  1006 
       
  1007     CFbsBitmap* bitmapR;
       
  1008     CFbsBitmap* bitmapRMask;
       
  1009     AknsUtils::CreateColorIconL( skin,
       
  1010                                  KAknsIIDQgnGrafFepPopupShadowR,
       
  1011                                  KAknsIIDQsnIconColors,
       
  1012                                  EAknsCIQsnIconColorsCG14,
       
  1013                                  bitmapR,
       
  1014                                  bitmapRMask,
       
  1015                                  KTRUIICONSFILENAME,
       
  1016                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_r,
       
  1017                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_r_mask,
       
  1018                                  KRgbBlack
       
  1019                                  );    
       
  1020     iShadowBitmaps.Append( bitmapR );
       
  1021     iShadowBitmapMasks.Append( bitmapRMask );
       
  1022 
       
  1023     CFbsBitmap* bitmapB;
       
  1024     CFbsBitmap* bitmapBMask;
       
  1025     AknsUtils::CreateColorIconL( skin,
       
  1026                                  KAknsIIDQgnGrafFepPopupShadowB,
       
  1027                                  KAknsIIDQsnIconColors,
       
  1028                                  EAknsCIQsnIconColorsCG14,
       
  1029                                  bitmapB,
       
  1030                                  bitmapBMask,
       
  1031                                  KTRUIICONSFILENAME,
       
  1032                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_b,
       
  1033                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_b_mask,
       
  1034                                  KRgbBlack
       
  1035                                  );    
       
  1036     iShadowBitmaps.Append( bitmapB );
       
  1037     iShadowBitmapMasks.Append( bitmapBMask );
       
  1038 
       
  1039     CFbsBitmap* bitmapBr;
       
  1040     CFbsBitmap* bitmapBrMask;
       
  1041     AknsUtils::CreateColorIconL( skin,
       
  1042                                  KAknsIIDQgnGrafFepPopupShadowBr,
       
  1043                                  KAknsIIDQsnIconColors,
       
  1044                                  EAknsCIQsnIconColorsCG14,
       
  1045                                  bitmapBr,
       
  1046                                  bitmapBrMask,
       
  1047                                  KTRUIICONSFILENAME,
       
  1048                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_br,
       
  1049                                  EMbmTrui_iconsQgn_graf_fep_popup_shadow_br_mask,
       
  1050                                  KRgbBlack
       
  1051                                  );    
       
  1052     iShadowBitmaps.Append( bitmapBr );
       
  1053     iShadowBitmapMasks.Append( bitmapBrMask );
       
  1054     }
       
  1055 
       
  1056 // --------------------------------------------------------------------------
       
  1057 // Load bitmaps for guidelines.
       
  1058 // --------------------------------------------------------------------------
       
  1059 //
       
  1060 void CTruiHwrBox::LoadGuideLineBitmapsL()
       
  1061     {
       
  1062     iGuideLineBitmaps.ResetAndDestroy();
       
  1063     iGuideLineBitmapMasks.ResetAndDestroy();    
       
  1064     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  1065     CFbsBitmap* bitmapTop;
       
  1066     CFbsBitmap* bitmapTopMask;
       
  1067     AknsUtils::CreateColorIconL( skin,
       
  1068                                  KAknsIIDQgnGrafFepBgColour,
       
  1069                                  KAknsIIDQsnIconColors,
       
  1070                                  EAknsCIQsnIconColorsCG14,
       
  1071                                  bitmapTop,
       
  1072                                  bitmapTopMask,
       
  1073                                  KTRUIICONSFILENAME,
       
  1074                                  EMbmTrui_iconsQgn_graf_fep_bg_colour,
       
  1075                                  EMbmTrui_iconsQgn_graf_fep_bg_colour_mask,
       
  1076                                  KRgbBlack
       
  1077                                  );    
       
  1078     iGuideLineBitmaps.Append( bitmapTop );
       
  1079     iGuideLineBitmapMasks.Append( bitmapTopMask );
       
  1080 
       
  1081     CFbsBitmap* bitmapBottom;
       
  1082     CFbsBitmap* bitmapBottomMask;
       
  1083     AknsUtils::CreateColorIconL( skin,
       
  1084                                  KAknsIIDQgnGrafFepBgColour,
       
  1085                                  KAknsIIDQsnIconColors,
       
  1086                                  EAknsCIQsnIconColorsCG14,
       
  1087                                  bitmapBottom,
       
  1088                                  bitmapBottomMask,
       
  1089                                  KTRUIICONSFILENAME,
       
  1090                                  EMbmTrui_iconsQgn_graf_fep_bg_colour,
       
  1091                                  EMbmTrui_iconsQgn_graf_fep_bg_colour_mask,
       
  1092                                  KRgbBlack
       
  1093                                  );    
       
  1094     iGuideLineBitmaps.Append( bitmapBottom );
       
  1095     iGuideLineBitmapMasks.Append( bitmapBottomMask );
       
  1096     }
       
  1097 
       
  1098 // --------------------------------------------------------------------------
       
  1099 // Load layouts for borders from LAF.
       
  1100 // --------------------------------------------------------------------------
       
  1101 //
       
  1102 void CTruiHwrBox::LoadBorderLayout( TInt aVarity )
       
  1103     {
       
  1104     TRect rect = Rect();
       
  1105     iBorderLayout.Reset();
       
  1106     // Caculate hwr_training_write_pane_g1
       
  1107     TAknWindowComponentLayout border_left_layout = 
       
  1108                AknLayoutScalable_Apps::hwr_training_write_pane_g1( aVarity );
       
  1109     TAknLayoutRect border_left_layout_rect;
       
  1110     border_left_layout_rect.LayoutRect( rect, border_left_layout );    
       
  1111     iBorderLayout.Append( border_left_layout_rect );
       
  1112 
       
  1113     TAknWindowComponentLayout border_top_layout = 
       
  1114                AknLayoutScalable_Apps::hwr_training_write_pane_g2( aVarity );
       
  1115     TAknLayoutRect border_top_layout_rect;
       
  1116     border_top_layout_rect.LayoutRect( rect, border_top_layout );    
       
  1117     iBorderLayout.Append( border_top_layout_rect );
       
  1118     
       
  1119     TAknWindowComponentLayout border_bottom_layout = 
       
  1120                AknLayoutScalable_Apps::hwr_training_write_pane_g3( aVarity );
       
  1121     TAknLayoutRect border_bottom_layout_rect;
       
  1122     border_bottom_layout_rect.LayoutRect( rect, border_bottom_layout );    
       
  1123     iBorderLayout.Append( border_bottom_layout_rect );
       
  1124 
       
  1125     TAknWindowComponentLayout border_right_layout = 
       
  1126                AknLayoutScalable_Apps::hwr_training_write_pane_g4( aVarity );
       
  1127     TAknLayoutRect border_right_layout_rect;
       
  1128     border_right_layout_rect.LayoutRect( rect, border_right_layout );    
       
  1129     iBorderLayout.Append( border_right_layout_rect );
       
  1130     }
       
  1131 
       
  1132 // --------------------------------------------------------------------------
       
  1133 // Load layouts for shadows from LAF.
       
  1134 // --------------------------------------------------------------------------
       
  1135 //
       
  1136 void CTruiHwrBox::LoadShadowLayout( TInt aVarity )
       
  1137     {
       
  1138     TRect rect = Rect();
       
  1139     iShadowLayout.Reset();
       
  1140     // Caculate bg_frame_shadow_pane
       
  1141     TAknWindowComponentLayout shadow_pane_layout = 
       
  1142                AknLayoutScalable_Apps::bg_frame_shadow_pane( aVarity );
       
  1143     TAknLayoutRect shadow_pane_layout_rect;
       
  1144     shadow_pane_layout_rect.LayoutRect( rect, shadow_pane_layout );
       
  1145     TRect shadowPaneRect = shadow_pane_layout_rect.Rect();
       
  1146     
       
  1147     // Caculate bg_frame_shadow_pane_g1
       
  1148     TAknWindowComponentLayout shadow_pane_tl_layout = 
       
  1149                AknLayoutScalable_Apps::bg_frame_shadow_pane_g1( aVarity );
       
  1150     TAknLayoutRect shadow_pane_tl_layout_rect;
       
  1151     shadow_pane_tl_layout_rect.LayoutRect( shadowPaneRect, shadow_pane_tl_layout );    
       
  1152     iShadowLayout.Append( shadow_pane_tl_layout_rect );
       
  1153 
       
  1154     // Caculate bg_frame_shadow_pane_g2
       
  1155     TAknWindowComponentLayout shadow_pane_t_layout = 
       
  1156                AknLayoutScalable_Apps::bg_frame_shadow_pane_g2( aVarity );
       
  1157     TAknLayoutRect shadow_pane_t_layout_rect;
       
  1158     shadow_pane_t_layout_rect.LayoutRect( shadowPaneRect, shadow_pane_t_layout );
       
  1159     iShadowLayout.Append( shadow_pane_t_layout_rect );
       
  1160 
       
  1161     // Caculate bg_frame_shadow_pane_g3
       
  1162     TAknWindowComponentLayout shadow_pane_tr_layout = 
       
  1163                AknLayoutScalable_Apps::bg_frame_shadow_pane_g3( aVarity );
       
  1164     TAknLayoutRect shadow_pane_tr_layout_rect;
       
  1165     shadow_pane_tr_layout_rect.LayoutRect( shadowPaneRect, shadow_pane_tr_layout );
       
  1166     iShadowLayout.Append( shadow_pane_tr_layout_rect );
       
  1167 
       
  1168     // Caculate bg_frame_shadow_pane_g4
       
  1169     TAknWindowComponentLayout shadow_pane_l_layout = 
       
  1170                AknLayoutScalable_Apps::bg_frame_shadow_pane_g4( aVarity );
       
  1171     TAknLayoutRect shadow_pane_l_layout_rect;
       
  1172     shadow_pane_l_layout_rect.LayoutRect( shadowPaneRect, shadow_pane_l_layout );
       
  1173     iShadowLayout.Append( shadow_pane_l_layout_rect );
       
  1174 
       
  1175     // Caculate bg_frame_shadow_pane_g5
       
  1176     TAknWindowComponentLayout shadow_pane_bl_layout = 
       
  1177                AknLayoutScalable_Apps::bg_frame_shadow_pane_g5( aVarity );
       
  1178     TAknLayoutRect shadow_pane_bl_layout_rect;
       
  1179     shadow_pane_bl_layout_rect.LayoutRect( shadowPaneRect, shadow_pane_bl_layout );
       
  1180     iShadowLayout.Append( shadow_pane_bl_layout_rect );
       
  1181 
       
  1182     // Caculate bg_frame_shadow_pane_g6
       
  1183     TAknWindowComponentLayout shadow_pane_r_layout = 
       
  1184                AknLayoutScalable_Apps::bg_frame_shadow_pane_g6( aVarity );
       
  1185     TAknLayoutRect shadow_pane_r_layout_rect;
       
  1186     shadow_pane_r_layout_rect.LayoutRect( shadowPaneRect, shadow_pane_r_layout );
       
  1187     iShadowLayout.Append( shadow_pane_r_layout_rect );
       
  1188 
       
  1189     // Caculate bg_frame_shadow_pane_g7
       
  1190     TAknWindowComponentLayout shadow_pane_b_layout = 
       
  1191                AknLayoutScalable_Apps::bg_frame_shadow_pane_g7( aVarity );
       
  1192     TAknLayoutRect shadow_pane_b_layout_rect;
       
  1193     shadow_pane_b_layout_rect.LayoutRect( shadowPaneRect, shadow_pane_b_layout );
       
  1194     iShadowLayout.Append( shadow_pane_b_layout_rect );
       
  1195 
       
  1196     // Caculate bg_frame_shadow_pane_g8
       
  1197     TAknWindowComponentLayout shadow_pane_br_layout = 
       
  1198                AknLayoutScalable_Apps::bg_frame_shadow_pane_g8( aVarity );
       
  1199     TAknLayoutRect shadow_pane_br_layout_rect;
       
  1200     shadow_pane_br_layout_rect.LayoutRect( shadowPaneRect, shadow_pane_br_layout );
       
  1201     iShadowLayout.Append( shadow_pane_br_layout_rect );
       
  1202     }
       
  1203 
       
  1204 // --------------------------------------------------------------------------
       
  1205 // Load layouts for guidelines from LAF.
       
  1206 // --------------------------------------------------------------------------
       
  1207 //
       
  1208 void CTruiHwrBox::LoadGuideLineLayout( TInt aVarity )
       
  1209     {
       
  1210     TRect rect = Rect();
       
  1211     iGuideLineLayout.Reset();
       
  1212     // Caculate hwr_training_write_pane_g5
       
  1213     TAknWindowComponentLayout top_guideline_layout = 
       
  1214                AknLayoutScalable_Apps::hwr_training_write_pane_g5( aVarity );
       
  1215     TAknLayoutRect top_guideline_layout_rect;
       
  1216     top_guideline_layout_rect.LayoutRect( rect, top_guideline_layout );
       
  1217     iGuideLineLayout.Append( top_guideline_layout_rect );
       
  1218 
       
  1219     // Caculate hwr_training_write_pane_g6
       
  1220     TAknWindowComponentLayout bottom_guideline_layout = 
       
  1221                AknLayoutScalable_Apps::hwr_training_write_pane_g6( aVarity );
       
  1222     TAknLayoutRect bottom_guideline_layout_rect;
       
  1223     bottom_guideline_layout_rect.LayoutRect( rect, bottom_guideline_layout );
       
  1224     iGuideLineLayout.Append( bottom_guideline_layout_rect );
       
  1225     }
       
  1226 
       
  1227 // --------------------------------------------------------------------------
       
  1228 // Draw borders.
       
  1229 // --------------------------------------------------------------------------
       
  1230 //
       
  1231 void CTruiHwrBox::DrawBorders( CWindowGc& aGc ) const
       
  1232     {
       
  1233     for ( TInt i = 0; i < iBorderLayout.Count(); i++ )
       
  1234         {
       
  1235         iBorderLayout[i].DrawImage( aGc, iBorderBitmaps[i], iBorderBitmapMasks[i] );        
       
  1236         }
       
  1237     }
       
  1238 
       
  1239 // --------------------------------------------------------------------------
       
  1240 // Draw shadows.
       
  1241 // --------------------------------------------------------------------------
       
  1242 //
       
  1243 void CTruiHwrBox::DrawShadows( CWindowGc& aGc ) const
       
  1244     {
       
  1245     for ( TInt i = 0; i < iShadowLayout.Count(); i++ )
       
  1246         {
       
  1247         iShadowLayout[i].DrawImage( aGc, iShadowBitmaps[i], iShadowBitmapMasks[i] );
       
  1248         }
       
  1249     }
       
  1250     
       
  1251 // --------------------------------------------------------------------------
       
  1252 // Draw guidelines.
       
  1253 // --------------------------------------------------------------------------
       
  1254 //
       
  1255 void CTruiHwrBox::DrawGuideLines( CWindowGc& aGc ) const
       
  1256     {
       
  1257     if ( iTopGuideLineDisplay && KTopGuideLineIndex < iGuideLineLayout.Count()
       
  1258                               && KTopGuideLineIndex < iGuideLineBitmaps.Count()
       
  1259                               && KTopGuideLineIndex < iGuideLineBitmapMasks.Count() )
       
  1260         {        
       
  1261         TSize pixSize = iGuideLineBitmaps[KTopGuideLineIndex]->SizeInPixels();
       
  1262         aGc.BitBltMasked( iGuideLineTopL, iGuideLineBitmaps[KTopGuideLineIndex], 
       
  1263                          TRect( TPoint( 0, 0 ), pixSize ), 
       
  1264                          iGuideLineBitmapMasks[KTopGuideLineIndex], EFalse );        
       
  1265         }
       
  1266         
       
  1267     if ( iBottomGuideLineDisplay && KBottomGuideLineIndex < iGuideLineLayout.Count()
       
  1268                               && KBottomGuideLineIndex < iGuideLineBitmaps.Count()
       
  1269                               && KBottomGuideLineIndex < iGuideLineBitmapMasks.Count() )
       
  1270         {
       
  1271         TSize pixSize = iGuideLineBitmaps[KBottomGuideLineIndex]->SizeInPixels();                
       
  1272         aGc.BitBltMasked( iGuideLineBottomL, iGuideLineBitmaps[KBottomGuideLineIndex], 
       
  1273                          TRect( TPoint( 0, 0 ), pixSize ), 
       
  1274                          iGuideLineBitmapMasks[KBottomGuideLineIndex], EFalse );
       
  1275         }
       
  1276     }  
       
  1277     
       
  1278 // -----------------------------------------------------------------------------
       
  1279 // Show trails.
       
  1280 // -----------------------------------------------------------------------------
       
  1281 //
       
  1282 void CTruiHwrBox::ShowTrails( const RArray<TPoint>& aPointArray, 
       
  1283                               TBool aIsScale,
       
  1284                               const TSize& aRefSize )
       
  1285     {    
       
  1286     // Set values fo iPointArrayDraw
       
  1287     if ( aPointArray.Count() > 0 )
       
  1288         {
       
  1289         iPointArrayDraw.Reset();
       
  1290         for ( TInt i = 0; i < aPointArray.Count(); i++ )
       
  1291             {
       
  1292             iPointArrayDraw.Append( aPointArray[i] );
       
  1293             }
       
  1294         }
       
  1295     
       
  1296     // Adjust the trails in terms of HwrBox size
       
  1297     if ( aIsScale )
       
  1298         {
       
  1299         // Scale model points
       
  1300         ScaleModel( aRefSize, iDrawabelRect.Size(), iPointArrayDraw );
       
  1301         }
       
  1302     DrawNow();
       
  1303     }
       
  1304     
       
  1305 // --------------------------------------------------------------------------
       
  1306 // CTruiHwrBox::ShowTooltipL
       
  1307 // --------------------------------------------------------------------------
       
  1308 //
       
  1309 void CTruiHwrBox::ShowTooltipL( const TDesC& aText, 
       
  1310                                 const TPoint& aPosition,
       
  1311                                 const TInt aBeforeTimeout,
       
  1312                                 const TInt aInViewTimeout )
       
  1313     {
       
  1314     if ( aText.Length() < 0 )
       
  1315         {
       
  1316         return;
       
  1317         }
       
  1318     iTooltip->SetTextL( aText );
       
  1319     iTooltip->SetTimeDelayBeforeShow( aBeforeTimeout );
       
  1320     iTooltip->SetTimePopupInView( aInViewTimeout );
       
  1321     iTooltip->SetPositionAndAlignment( aPosition, EHCenterVTop );
       
  1322 
       
  1323     iTooltip->ShowInfoPopupNote();        
       
  1324     }
       
  1325 
       
  1326 void CTruiHwrBox::SetTooltipPosition( const TPoint& aPosition )
       
  1327     {
       
  1328     if ( iTooltip )
       
  1329         {
       
  1330         iTooltip->SetPositionAndAlignment( aPosition, EHCenterVTop );
       
  1331         }
       
  1332     }
       
  1333 
       
  1334 // --------------------------------------------------------------------------
       
  1335 // Hide tooltip.
       
  1336 // --------------------------------------------------------------------------
       
  1337 //
       
  1338 void CTruiHwrBox::HideInfoPopupNote()
       
  1339     {
       
  1340     if ( iTooltip )
       
  1341         {
       
  1342         iTooltip->HideInfoPopupNote();
       
  1343         }    
       
  1344     }
       
  1345 
       
  1346 // --------------------------------------------------------------------------
       
  1347 // Handles events reported from info popup note.
       
  1348 // --------------------------------------------------------------------------
       
  1349 //
       
  1350 void CTruiHwrBox::HandleInfoPopupNoteEvent( CAknInfoPopupNoteController* aController,
       
  1351         TAknInfoPopupNoteEvent aEvent )
       
  1352     {
       
  1353     if ( aController == iTooltip && aEvent == EInfoPopupNoteHidden )
       
  1354         {        
       
  1355         DrawNow();        
       
  1356         }
       
  1357     }
       
  1358 
       
  1359 // -----------------------------------------------------------------------------
       
  1360 // Save the new inputting model by manual.
       
  1361 // -----------------------------------------------------------------------------
       
  1362 //
       
  1363 void CTruiHwrBox::SaveModelByManuallyL()
       
  1364     {
       
  1365     if ( iPointArrayDraw.Count() && !iStartSave )
       
  1366         {
       
  1367         // Has drawn
       
  1368         if ( iPointArrayDraw[iPointArrayDraw.Count() - 1] != KTail )
       
  1369             {
       
  1370             iPointArrayDraw.Append( KTail );            
       
  1371             }
       
  1372         SaveModelL();
       
  1373         }        
       
  1374     }