htiui/HtiServicePlugins/HtiKeyEventServicePlugin/src/PointerEventHandler.cpp
changeset 38 aca9d8bb5fbc
parent 31 e7a04a6385be
child 39 a5449825eaf3
equal deleted inserted replaced
31:e7a04a6385be 38:aca9d8bb5fbc
     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:  Functional implementation of pointer event service
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "HtiKeyEventServicePlugin.h"
       
    20 #include "PointerEventHandler.h"
       
    21 
       
    22 
       
    23 #include <HtiDispatcherInterface.h>
       
    24 #include <HtiLogging.h>
       
    25 
       
    26 
       
    27 // CONSTANTS
       
    28 _LIT8( KErrorMissingCommand, "Command was not given - message was empty" );
       
    29 _LIT8( KErrorServiceNotReady, "Service is busy - possibly executing long running pointer events" );
       
    30 _LIT8( KErrorInvalidParameters, "Command parameters not valid" );
       
    31 _LIT8( KErrorUnrecognizedCommand, "Unrecognized command" );
       
    32 _LIT8( KErrorInternalFailure, "Internal pointer command failure" );
       
    33 _LIT8( KErrorGetHALData, "Can not get the HAL data" );
       
    34 
       
    35 const TInt KTapCmdLength = 10;
       
    36 const TInt KDragMultiCmdMinLength = 14;
       
    37 const TInt KSinglePointerCmdLength = 4;
       
    38 const TInt KAdvancedTapScreenCmdMinLength = 16;
       
    39 const TInt KPinchZoomCmdMinLength = 30;
       
    40 
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // CPointerEventHandler::NewL()
       
    44 // ----------------------------------------------------------------------------
       
    45 CPointerEventHandler* CPointerEventHandler::NewL()
       
    46     {
       
    47     HTI_LOG_FUNC_IN( "CPointerEventHandler::NewL" );
       
    48     CPointerEventHandler* self = new (ELeave) CPointerEventHandler();
       
    49     CleanupStack::PushL ( self );
       
    50     self->ConstructL();
       
    51     CleanupStack::Pop();
       
    52     HTI_LOG_FUNC_OUT( "CPointerEventHandler::Done" );
       
    53     return self;
       
    54     }
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // CPointerEventHandler::CPointerEventHandler()
       
    58 // ----------------------------------------------------------------------------
       
    59 CPointerEventHandler::CPointerEventHandler()
       
    60     : CActive( CActive::EPriorityStandard ), iReady( ETrue ), iCommand( 0 ), iMultiTouchHandler(NULL),
       
    61       iState( EPointerUp )
       
    62     {
       
    63     }
       
    64 
       
    65 // ----------------------------------------------------------------------------
       
    66 // CPointerEventHandler::~CPointerEventHandler()
       
    67 // ----------------------------------------------------------------------------
       
    68 CPointerEventHandler::~CPointerEventHandler()
       
    69     {
       
    70     HTI_LOG_TEXT( "CPointerEventHandler destroy" );
       
    71     Cancel();
       
    72     iTimer.Close();
       
    73     iWsSession.Close();
       
    74     if ( iCoords )
       
    75         {
       
    76         iCoords->Close();
       
    77         }
       
    78     delete iCoords;
       
    79     delete iMultiTouchHandler;
       
    80 	
       
    81 	iAdvancedPointers.ResetAndDestroy();
       
    82 	iDelayArray.ResetAndDestroy();  
       
    83 	iAdvPointerMoveArray.ResetAndDestroy(); 
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------------------------------
       
    87 // CPointerEventHandler::ConstructL()
       
    88 // ----------------------------------------------------------------------------
       
    89 void CPointerEventHandler::ConstructL()
       
    90     {
       
    91     HTI_LOG_TEXT( "CPointerEventHandler::ConstructL" );
       
    92     User::LeaveIfError( iWsSession.Connect() );
       
    93     User::LeaveIfError( iTimer.CreateLocal() );
       
    94     CActiveScheduler::Add( this );
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // void CPointerEventHandler::SetDispatcher()
       
    99 // ----------------------------------------------------------------------------
       
   100 void CPointerEventHandler::SetDispatcher( MHtiDispatcher* aDispatcher )
       
   101     {
       
   102     iDispatcher = aDispatcher;
       
   103     }
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // CPointerEventHandler::RunL()
       
   107 // ----------------------------------------------------------------------------
       
   108 void CPointerEventHandler::RunL()
       
   109     {
       
   110     HTI_LOG_FUNC_IN( "CPointerEventHandler::RunL" );
       
   111 
       
   112     if ( iCommand == ETapScreen || iCommand == EAdvancedTapScreen )
       
   113         {
       
   114         ChangePointerStateL();
       
   115         }
       
   116 
       
   117     else if ( iCommand == ETapAndDrag  && iState == EPointerDown )
       
   118         {
       
   119         PointerMove();
       
   120         PointerUp();
       
   121         SendOkMsgL();
       
   122         iReady = ETrue;
       
   123         }
       
   124 
       
   125     else if ( iCommand == ETapAndDragMultipoint )
       
   126         {
       
   127         if ( iState == EPointerUp )  // Starting a new line
       
   128             {
       
   129             PointerDown();
       
   130             iTapCount--;
       
   131             iTimer.After( iStatus, iEventDelay );
       
   132             SetActive();
       
   133             }
       
   134         else
       
   135             {
       
   136             MoveToNextPointL(); // Continuing current line
       
   137             }
       
   138         }
       
   139     
       
   140     else if ( iCommand == EPinchZoom )
       
   141         {
       
   142         PointerMove();
       
   143         if ( !AdvancedStartDelay())
       
   144             {
       
   145             PointerUp();
       
   146             SendOkMsgL();
       
   147             iAdvPointerMoveArray.ResetAndDestroy(); 
       
   148             iReady = ETrue;
       
   149             }
       
   150         }		
       
   151     
       
   152     else if ( iCommand == EMultiTouch )
       
   153         {
       
   154         SendOkMsgL();
       
   155         iMultiTouchHandler->Clear();
       
   156         iReady = ETrue;
       
   157         }		
       
   158     HTI_LOG_FUNC_OUT( "CPointerEventHandler::RunL" );
       
   159     }
       
   160 
       
   161 // ----------------------------------------------------------------------------
       
   162 // CPointerEventHandler::RunError()
       
   163 // ----------------------------------------------------------------------------
       
   164 TInt CPointerEventHandler::RunError( TInt aError )
       
   165     {
       
   166     HTI_LOG_FORMAT( "CPointerEventHandler::RunError %d", aError );
       
   167 
       
   168     TInt dispatchResult = KErrNone;
       
   169     TRAP( dispatchResult, SendErrorMessageL( aError, KErrorInternalFailure ) );
       
   170     if ( dispatchResult != KErrNone )
       
   171         {
       
   172         HTI_LOG_FORMAT( "CPointerEventHandler::RunError: Failed to send error report to framework: %d.", dispatchResult );
       
   173         }
       
   174     iReady = ETrue;
       
   175     return KErrNone;
       
   176     }
       
   177 
       
   178 // ----------------------------------------------------------------------------
       
   179 // CPointerEventHandler::DoCancel()
       
   180 // ----------------------------------------------------------------------------
       
   181 void CPointerEventHandler::DoCancel()
       
   182     {
       
   183     iTimer.Cancel();
       
   184     }
       
   185 
       
   186 // ----------------------------------------------------------------------------
       
   187 // CPointerEventHandler::ProcessMessageL()
       
   188 // ----------------------------------------------------------------------------
       
   189 void CPointerEventHandler::ProcessMessageL( const TDesC8& aMessage,
       
   190     THtiMessagePriority /*aPriority*/ )
       
   191     {
       
   192     HTI_LOG_FUNC_IN("CPointerEventHandler::ProcessMessageL");
       
   193     HTI_LOG_FORMAT("Msg len: %d.", aMessage.Length());
       
   194 
       
   195     if ( !iReady )
       
   196         {
       
   197         SendErrorMessageL( ENotReadyCommand, KErrorServiceNotReady );
       
   198         return;
       
   199         }
       
   200     if ( aMessage.Length() == 0 )
       
   201         {
       
   202         SendErrorMessageL( EMissingCommand, KErrorMissingCommand );
       
   203         return;
       
   204         }
       
   205 
       
   206     User::ResetInactivityTime();
       
   207     iCommand = aMessage.Ptr()[0];
       
   208     switch ( iCommand )
       
   209         {
       
   210         case ETapScreen:
       
   211             HandleTapScreenL( aMessage.Right( aMessage.Length() - 1 ) );
       
   212             break;
       
   213         case ETapAndDrag:
       
   214             HandleTapAndDragL( aMessage.Right( aMessage.Length() - 1 ) );
       
   215             break;
       
   216         case ETapAndDragMultipoint:
       
   217             HandleTapAndDragMultipointL(
       
   218                 aMessage.Right( aMessage.Length() - 1 ) );
       
   219             break;
       
   220         case EPressPointerDown:
       
   221         case ELiftPointerUp:
       
   222             HandlePointerDownOrUpL( aMessage.Right( aMessage.Length() - 1 ) );
       
   223             break;
       
   224 		case EAdvancedTapScreen:
       
   225 		    HandleAdvancedTapScreenL( aMessage.Right( aMessage.Length() - 1 ) );
       
   226             break;		
       
   227 		case EPinchZoom: 
       
   228 		    HandlePinchZoomL( aMessage.Right( aMessage.Length() - 1 ) );
       
   229             break;
       
   230 		case EMultiTouch:
       
   231 			HandleMultiTouchL(aMessage.Right( aMessage.Length() - 1 ));
       
   232 			break;
       
   233         default:
       
   234             SendErrorMessageL( EUnrecognizedCommand,
       
   235                 KErrorUnrecognizedCommand );
       
   236             break;
       
   237         }
       
   238 
       
   239     HTI_LOG_FUNC_OUT( "CPointerEventHandler::ProcessMessageL: Done" );
       
   240     }
       
   241 
       
   242 // ----------------------------------------------------------------------------
       
   243 // CPointerEventHandler::HandleTapScreenL()
       
   244 // Handles single or multiple taps to one point.
       
   245 // ----------------------------------------------------------------------------
       
   246 void CPointerEventHandler::HandleTapScreenL( const TDesC8& aData )
       
   247     {
       
   248     HTI_LOG_FUNC_IN( "CPointerEventHandler::HandleTapScreenL" );
       
   249 
       
   250     if ( aData.Length() != KTapCmdLength )
       
   251         {
       
   252         SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   253         return;
       
   254         }
       
   255 
       
   256     // Parse the parameters - correct length is already verified
       
   257     TInt offset = 0;
       
   258     iX = aData[offset] + ( aData[offset+1] << 8 );
       
   259     offset += 2;
       
   260     HTI_LOG_FORMAT( "X coord = %d", iX );
       
   261     iY = aData[offset] + ( aData[offset+1] << 8 );
       
   262     offset += 2;
       
   263     HTI_LOG_FORMAT( "Y coord = %d", iY );
       
   264     iEventDelay = ( aData[offset] + ( aData[offset+1] << 8 ) ) * 1000;
       
   265     offset += 2;
       
   266     HTI_LOG_FORMAT( "Time to hold down = %d", iEventDelay.Int() );
       
   267     iTapCount = aData[offset] + ( aData[offset+1] << 8 );
       
   268     offset += 2;
       
   269     HTI_LOG_FORMAT( "Tap count = %d", iTapCount );
       
   270     iActionDelay = ( aData[offset] + ( aData[offset+1] << 8 ) ) * 1000;
       
   271     HTI_LOG_FORMAT( "Pause between taps = %d", iActionDelay.Int() );
       
   272 
       
   273     // Start tapping
       
   274     iReady = EFalse;
       
   275     ChangePointerStateL();
       
   276 
       
   277     HTI_LOG_FUNC_OUT( "CPointerEventHandler::HandleTapScreenL" );
       
   278     }
       
   279 	
       
   280 
       
   281 
       
   282 // ----------------------------------------------------------------------------
       
   283 // CPointerEventHandler::HandleTapAndDragL()
       
   284 // Handles a single drag and drop with straight line.
       
   285 // ----------------------------------------------------------------------------
       
   286 void CPointerEventHandler::HandleTapAndDragL( const TDesC8& aData )
       
   287     {
       
   288     HTI_LOG_FUNC_IN( "CPointerEventHandler::HandleTapAndDragL" );
       
   289 
       
   290     if ( aData.Length() != KTapCmdLength )
       
   291         {
       
   292         SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   293         return;
       
   294         }
       
   295 
       
   296     TInt offset = 0;
       
   297     iX = aData[offset] + ( aData[offset+1] << 8 );
       
   298     offset += 2;
       
   299     HTI_LOG_FORMAT( "X coord down = %d", iX );
       
   300     iY = aData[offset] + ( aData[offset+1] << 8 );
       
   301     offset += 2;
       
   302     HTI_LOG_FORMAT( "Y coord down = %d", iY );
       
   303     TInt xUp = aData[offset] + ( aData[offset+1] << 8 );
       
   304     offset += 2;
       
   305     HTI_LOG_FORMAT( "X coord up = %d", xUp );
       
   306     TInt yUp = aData[offset] + ( aData[offset+1] << 8 );
       
   307     offset += 2;
       
   308     HTI_LOG_FORMAT( "Y coord up = %d", yUp );
       
   309     iEventDelay = ( aData[offset] + ( aData[offset+1] << 8 ) ) * 1000;
       
   310     HTI_LOG_FORMAT( "Drag time = %d", iEventDelay.Int() );
       
   311 
       
   312     iReady = EFalse;
       
   313     PointerDown();
       
   314     iX = xUp;
       
   315     iY = yUp;
       
   316     iTimer.After( iStatus, iEventDelay );
       
   317     SetActive();
       
   318 
       
   319     HTI_LOG_FUNC_OUT( "CPointerEventHandler::HandleTapAndDragL" );
       
   320     }
       
   321 
       
   322 // ----------------------------------------------------------------------------
       
   323 // CPointerEventHandler::HandleTapAndDragMultipointL()
       
   324 // Handles drawing one or more curvy lines.
       
   325 // ----------------------------------------------------------------------------
       
   326 void CPointerEventHandler::HandleTapAndDragMultipointL( const TDesC8& aData )
       
   327     {
       
   328     HTI_LOG_FUNC_IN( "CPointerEventHandler::HandleTapAndDragMultipointL" );
       
   329 
       
   330     TInt dataLength = aData.Length();
       
   331     if ( dataLength < KDragMultiCmdMinLength || dataLength % 2 != 0 )
       
   332         {
       
   333         SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   334         return;
       
   335         }
       
   336 
       
   337     TInt offset = 0;
       
   338     iEventDelay = ( aData[offset] + ( aData[offset+1] << 8 ) ) * 1000;
       
   339     offset += 2;
       
   340     HTI_LOG_FORMAT( "Time between events = %d", iEventDelay.Int() );
       
   341     iActionDelay = ( aData[offset] + ( aData[offset+1] << 8 ) ) * 1000;
       
   342     offset += 2;
       
   343     HTI_LOG_FORMAT( "Pause between lines = %d", iActionDelay.Int() );
       
   344 
       
   345     if ( iCoords == NULL )
       
   346         {
       
   347         iCoords = new ( ELeave ) RArray<TInt>();
       
   348         }
       
   349     iCoords->Reset();
       
   350 
       
   351     // Read integers from aData to the array, all integers are 2 bytes
       
   352     while ( offset < dataLength )
       
   353         {
       
   354         iCoords->AppendL( aData[offset] + ( aData[offset + 1] << 8 ) );
       
   355         offset += 2;
       
   356         }
       
   357 
       
   358     iReady = EFalse;
       
   359     iTapCount = ( *iCoords )[0];
       
   360     iCoords->Remove( 0 );
       
   361     iX = ( *iCoords )[0];
       
   362     iCoords->Remove( 0 );
       
   363     iY = ( *iCoords )[0];
       
   364     iCoords->Remove( 0 );
       
   365     HTI_LOG_FORMAT( "Point count for first line = %d", iTapCount );
       
   366     PointerDown();
       
   367     iTapCount--;
       
   368     iTimer.After( iStatus, iEventDelay );
       
   369     SetActive();
       
   370 
       
   371     HTI_LOG_FUNC_OUT( "CPointerEventHandler::HandleTapAndDragMultipointL" );
       
   372     }
       
   373 
       
   374 // ----------------------------------------------------------------------------
       
   375 // CPointerEventHandler::HandlePointerDownOrUpL()
       
   376 // Handles pushing pointer down in one point or lifting it up.
       
   377 // This is synchronous operation and sends OK message right after the event
       
   378 // is simulated.
       
   379 // ----------------------------------------------------------------------------
       
   380 void CPointerEventHandler::HandlePointerDownOrUpL( const TDesC8& aData )
       
   381     {
       
   382     HTI_LOG_FUNC_IN( "CPointerEventHandler::HandlePointerDownOrUpL" );
       
   383     if ( aData.Length() != KSinglePointerCmdLength )
       
   384         {
       
   385         SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   386         return;
       
   387         }
       
   388 
       
   389     // Parse the parameters - correct length is already verified
       
   390     TInt offset = 0;
       
   391     iX = aData[offset] + ( aData[offset+1] << 8 );
       
   392     offset += 2;
       
   393     HTI_LOG_FORMAT( "X coord = %d", iX );
       
   394     iY = aData[offset] + ( aData[offset+1] << 8 );
       
   395     offset += 2;
       
   396     HTI_LOG_FORMAT( "Y coord = %d", iY );
       
   397 
       
   398     if ( iCommand == EPressPointerDown )
       
   399         {
       
   400         PointerDown();
       
   401         }
       
   402     else
       
   403         {
       
   404         PointerUp();
       
   405         }
       
   406     SendOkMsgL();
       
   407     HTI_LOG_FUNC_OUT( "CPointerEventHandler::HandlePointerDownOrUpL" );
       
   408     }
       
   409 
       
   410 // ----------------------------------------------------------------------------
       
   411 // CPointerEventHandler::ChangePointerStateL()
       
   412 // Decides whether to do  "pointer down" or "pointer up" event next or if
       
   413 // operation is complete.
       
   414 // This function is used by ETapScreen command.
       
   415 // ----------------------------------------------------------------------------
       
   416 void CPointerEventHandler::ChangePointerStateL()
       
   417     {
       
   418     HTI_LOG_FUNC_IN( "CPointerEventHandler::ChangePointerStateL" );
       
   419     HTI_LOG_FORMAT( "Taps remaining = %d", iTapCount );
       
   420     if ( iTapCount < 1 )
       
   421         {
       
   422         SendOkMsgL();
       
   423         iReady = ETrue;
       
   424         return;
       
   425         }
       
   426 
       
   427     if ( iState == EPointerUp )
       
   428         {
       
   429         PointerDown();
       
   430         iTimer.After( iStatus, iEventDelay );
       
   431         SetActive();
       
   432         }
       
   433     else if ( iState == EPointerDown )
       
   434         {
       
   435         PointerUp();
       
   436         iTapCount--; // one tap done
       
   437         if ( iTapCount > 0 ) // do we continue tapping?
       
   438             {
       
   439             iTimer.After( iStatus, iActionDelay );
       
   440             SetActive();
       
   441             }
       
   442         else
       
   443             {
       
   444             SendOkMsgL();  // tapping done
       
   445             iReady = ETrue;
       
   446             }
       
   447         }
       
   448     HTI_LOG_FUNC_OUT( "CPointerEventHandler::ChangePointerStateL" );
       
   449     }
       
   450 	
       
   451 	// ----------------------------------------------------------------------------
       
   452 	
       
   453 // ----------------------------------------------------------------------------
       
   454 // CPointerEventHandler::HandleAdvancedTapScreenL()
       
   455 // ****cherry.
       
   456 // ----------------------------------------------------------------------------
       
   457 
       
   458 void CPointerEventHandler::HandleAdvancedTapScreenL( const TDesC8& aData )
       
   459     {
       
   460     
       
   461     HTI_LOG_FUNC_IN( "CPointerEventHandler::HandleAdvancedTapScreenL" );
       
   462 
       
   463     if ( aData.Length() < KAdvancedTapScreenCmdMinLength ) //KAdvancedTapScreenCmdMinLength needs to be defined
       
   464         {
       
   465         SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   466         return;
       
   467         }
       
   468 	TInt dataLength = aData.Length();
       
   469 	
       
   470     // Parse the parameters - correct length is already verified
       
   471 	TInt offset = 0;
       
   472 	
       
   473 	iEventDelay = ( aData[offset] + ( aData[offset+1] << 8 ) ) * 1000;
       
   474     offset += 2;
       
   475     HTI_LOG_FORMAT( "Time to hold down = %d", iEventDelay.Int() );
       
   476     iTapCount = aData[offset] + ( aData[offset+1] << 8 );
       
   477     offset += 2;
       
   478     HTI_LOG_FORMAT( "Tap count = %d", iTapCount );
       
   479     iActionDelay = ( aData[offset] + ( aData[offset+1] << 8 ) ) * 1000;
       
   480 	offset += 2;
       
   481     HTI_LOG_FORMAT( "Pause between taps = %d", iActionDelay.Int() );		
       
   482 	TInt pointerCount = aData[offset] + ( aData[offset+1] << 8 );
       
   483 	offset += 2;
       
   484 	HTI_LOG_FORMAT( "Pointer Count = %d", pointerCount );
       
   485 	
       
   486     iAdvancedPointers.ResetAndDestroy();
       
   487 
       
   488     // Read integers from aData to the array, all integers are 2 bytes
       
   489     for ( TInt i = 0; i < pointerCount; i++ )
       
   490         {
       
   491 		TAdvancedPointer* advancedPointer = new (ELeave) TAdvancedPointer;
       
   492 		
       
   493 		advancedPointer->PointerNum = aData[offset];
       
   494 		offset += 1;
       
   495 		HTI_LOG_FORMAT( "%d Pointer", advancedPointer->PointerNum );
       
   496 		
       
   497 		advancedPointer->X = aData[offset] + ( aData[offset+1] << 8 );
       
   498 		offset += 2;
       
   499 		HTI_LOG_FORMAT( "X coord down = %d", advancedPointer->X );
       
   500 		
       
   501 		advancedPointer->Y = aData[offset] + ( aData[offset+1] << 8 );
       
   502 		offset += 2;
       
   503 		HTI_LOG_FORMAT( "Y coord down = %d", advancedPointer->Y );
       
   504 
       
   505 		advancedPointer->Z = aData[offset] + ( aData[offset+1] << 8 );
       
   506 		offset += 2;
       
   507 		HTI_LOG_FORMAT( "Z coord down = %d", advancedPointer->Z );
       
   508 		
       
   509         iAdvancedPointers.AppendL( advancedPointer );
       
   510         }
       
   511 	
       
   512     // Start tapping
       
   513     iReady = EFalse;
       
   514     ChangePointerStateL();
       
   515 
       
   516     HTI_LOG_FUNC_OUT( "CPointerEventHandler::HandleAdvancedTapScreenL" );
       
   517     
       
   518     }
       
   519 	
       
   520 // ----------------------------------------------------------------------------
       
   521 // CPointerEventHandler::HandlePinchZoomL()
       
   522 // ****cherry
       
   523 // ----------------------------------------------------------------------------
       
   524 void CPointerEventHandler::HandlePinchZoomL( const TDesC8& aData )
       
   525     {
       
   526     HTI_LOG_FUNC_IN( "CPointerEventHandler::HandlePinchZoomL" );
       
   527 
       
   528     if ( aData.Length() < KPinchZoomCmdMinLength ) //KPinchZoomCmdMinLength needs to be defined
       
   529         {
       
   530         SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   531         return;
       
   532         }
       
   533 	TInt dataLength = aData.Length();
       
   534 	
       
   535     // Parse the parameters - correct length is already verified
       
   536 	TInt offset = 0;
       
   537 	
       
   538 	TTimeIntervalMicroSeconds32 eventDelay = ( aData[offset] + ( aData[offset+1] << 8 ) ) * 1000;
       
   539 	offset += 2;
       
   540     HTI_LOG_FORMAT( "Event time = %d", eventDelay.Int() );
       
   541     
       
   542     if (eventDelay.Int()<=0)
       
   543         {
       
   544         SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   545         return;        
       
   546         }
       
   547     
       
   548     TInt stepCount = aData[offset] + ( aData[offset+1] << 8 );
       
   549     offset += 2;
       
   550     HTI_LOG_FORMAT( "Step Count = %d", stepCount );
       
   551         
       
   552 	TInt pointerCount = aData[offset] + ( aData[offset+1] << 8 );
       
   553 	offset += 2;
       
   554 	HTI_LOG_FORMAT( "Pointer Count = %d", pointerCount );
       
   555 	
       
   556 	iAdvPointerMoveArray.ResetAndDestroy();	
       
   557 
       
   558     // Read integers from aData to the array, all integers are 2 bytes
       
   559     for ( TInt i = 0; i < pointerCount; i++ )
       
   560         {
       
   561         TInt pointNumber,X1, Y1, Z1,X2,Y2, Z2 ;
       
   562         
       
   563         // invalid pointer array 
       
   564         if ((dataLength-offset)<3*2*2+1)
       
   565             {
       
   566             SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   567             return;        
       
   568             }        
       
   569         // start point	
       
   570 		pointNumber = aData[offset];
       
   571 		offset += 1;
       
   572 		HTI_LOG_FORMAT( "%d Pointer Start", pointNumber );
       
   573 		
       
   574 		X1 = aData[offset] + ( aData[offset+1] << 8 );
       
   575 		offset += 2;
       
   576 		HTI_LOG_FORMAT( "X coord down = %d", X1 );
       
   577 		
       
   578 		Y1 = aData[offset] + ( aData[offset+1] << 8 );
       
   579 		offset += 2;
       
   580 		HTI_LOG_FORMAT( "Y coord down = %d", Y1 );
       
   581 
       
   582 		Z1 = aData[offset] + ( aData[offset+1] << 8 );
       
   583 		offset += 2;
       
   584 		HTI_LOG_FORMAT( "Z coord down = %d", Z1 );		
       
   585 
       
   586 		// end point     
       
   587 		X2 = aData[offset] + ( aData[offset+1] << 8 );
       
   588         offset += 2;
       
   589         HTI_LOG_FORMAT( "X coord down = %d", X2 );
       
   590         
       
   591         Y2 = aData[offset] + ( aData[offset+1] << 8 );
       
   592         offset += 2;
       
   593         HTI_LOG_FORMAT( "Y coord down = %d", Y2 );
       
   594 
       
   595         Z2 = aData[offset] + ( aData[offset+1] << 8 );
       
   596         offset += 2;
       
   597         HTI_LOG_FORMAT( "Z coord down = %d", Z2 );
       
   598         
       
   599         AdvanceAddMiddlePointL(pointNumber,X1, Y1, Z1,X2,Y2, Z2,stepCount );        
       
   600 
       
   601         }
       
   602     	
       
   603     AdvancedAddDelayArray(eventDelay,stepCount);
       
   604    
       
   605     iReady = EFalse;
       
   606     PointerDown();
       
   607 
       
   608     if (!AdvancedStartDelay())
       
   609         {
       
   610         SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   611         return;        
       
   612         }
       
   613 
       
   614     HTI_LOG_FUNC_OUT( "CPointerEventHandler::HandlePinchZoomL" );
       
   615     }	
       
   616 // ----------------------------------------------------------------------------
       
   617 // void CPointerEventHandler::HandleMultiTouchL()
       
   618 // ----------------------------------------------------------------------------
       
   619 void CPointerEventHandler::HandleMultiTouchL( const TDesC8& aData )
       
   620 	{
       
   621 	HTI_LOG_FUNC_IN( "CPointerEventHandler::HandleMultiTouchL" );	
       
   622 	
       
   623 	if (iMultiTouchHandler == NULL)
       
   624 		iMultiTouchHandler=CMultiTouchPointerEventHandler::NewL(*this);	
       
   625 	
       
   626     if ( !iMultiTouchHandler->HandleMultiTouchL ( aData ) )
       
   627     	{
       
   628 		iMultiTouchHandler->Clear();
       
   629 		SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   630     	}
       
   631     else
       
   632 		iReady = EFalse;
       
   633 	
       
   634 	HTI_LOG_FUNC_OUT( "CPointerEventHandler::HandleMultiTouchL" );
       
   635 	}
       
   636 // ----------------------------------------------------------------------------
       
   637 // void CPointerEventHandler::NotifyMultiTouchComplete()
       
   638 // ----------------------------------------------------------------------------
       
   639 void CPointerEventHandler::NotifyMultiTouchComplete()
       
   640     {
       
   641     HTI_LOG_FUNC_IN("CPointerEventHandler::NotifyMultiTouchComplete"); 
       
   642     
       
   643     // wait for 1000 microsecond then clear multi touch and send ok msg 
       
   644     TTimeIntervalMicroSeconds32 time(1000);
       
   645     iTimer.After( iStatus, time );
       
   646     SetActive();    
       
   647     
       
   648     HTI_LOG_FUNC_OUT("CPointerEventHandler::NotifyMultiTouchComplete");
       
   649     }
       
   650 // ----------------------------------------------------------------------------
       
   651 // CPointerEventHandler::AdvancedStartDelay()
       
   652 // ----------------------------------------------------------------------------
       
   653 TBool CPointerEventHandler::AdvancedStartDelay()
       
   654     {
       
   655     HTI_LOG_FUNC_IN( "CPointerEventHandler::AdvancedStartDelay" );
       
   656     TBool ret=EFalse;
       
   657     if (iDelayArray.Count()>0)
       
   658         {
       
   659         TTimeIntervalMicroSeconds32* time=iDelayArray[0];
       
   660         iDelayArray.Remove(0);
       
   661         ret=ETrue;
       
   662   
       
   663         iTimer.After( iStatus, *time );
       
   664         delete time;
       
   665         SetActive();
       
   666         }
       
   667     HTI_LOG_FUNC_OUT( "CPointerEventHandler::AdvancedStartDelay" );
       
   668     return ret;
       
   669     }
       
   670 
       
   671 // ----------------------------------------------------------------------------
       
   672 // CPointerEventHandler::AdvanceAddMiddlePointL()
       
   673 // ----------------------------------------------------------------------------
       
   674 void CPointerEventHandler::AdvanceAddMiddlePointL(TInt aPointNumber,TInt aX1,TInt aY1, TInt aZ1, 
       
   675         TInt aX2,TInt aY2, TInt aZ2 , TInt aStepCount )
       
   676     {
       
   677     HTI_LOG_FUNC_IN( "CPointerEventHandler::AdvanceAddMiddlePointL" );
       
   678     TInt dx=(aX2-aX1)/aStepCount;
       
   679     TInt dy=(aY2-aY1)/aStepCount;  
       
   680     
       
   681     for (TInt i=0;i<=aStepCount+1;i++)
       
   682         {
       
   683         TAdvancedPointer* point = new (ELeave) TAdvancedPointer;
       
   684         CleanupStack::PushL(point);
       
   685         iAdvPointerMoveArray.AppendL(point);
       
   686         CleanupStack::Pop();
       
   687         
       
   688         point->PointerNum=aPointNumber;
       
   689         if (i<aStepCount)
       
   690             {
       
   691             point->X=aX1+i*dx;
       
   692             point->Y=aY1+i*dy;
       
   693             point->Z=aZ1;
       
   694             }
       
   695         else
       
   696             {
       
   697             point->X=aX2;
       
   698             point->Y=aY2;
       
   699             point->Z=aZ2;
       
   700             }             
       
   701                   
       
   702         } 
       
   703     
       
   704     HTI_LOG_FUNC_OUT( "CPointerEventHandler::AdvanceAddMiddlePointL" );
       
   705     }
       
   706 
       
   707 // ----------------------------------------------------------------------------
       
   708 // CPointerEventHandler::AdvancedAddDelayArray()
       
   709 // ----------------------------------------------------------------------------
       
   710 void CPointerEventHandler::AdvancedAddDelayArray(TTimeIntervalMicroSeconds32 aDelay , TInt aStepCount )
       
   711     {
       
   712     HTI_LOG_FUNC_IN( "CPointerEventHandler::AdvancedAddDelayArray" );
       
   713     
       
   714     TInt interval=aDelay.Int()/aStepCount;
       
   715     iDelayArray.ResetAndDestroy();    
       
   716     
       
   717     for (TInt i=0;i<aStepCount;i++)
       
   718         {
       
   719         TTimeIntervalMicroSeconds32* time = new (ELeave) TTimeIntervalMicroSeconds32(interval);
       
   720         CleanupStack::PushL(time);
       
   721         iDelayArray.AppendL(time);
       
   722         CleanupStack::Pop(time);
       
   723         } 
       
   724     HTI_LOG_FUNC_OUT( "CPointerEventHandler::AdvancedAddDelayArray" );
       
   725     }
       
   726 
       
   727 // ----------------------------------------------------------------------------
       
   728 // CPointerEventHandler::MoveToNextPointL()
       
   729 // Takes the next point from the coordinate array and initiates pointer moving
       
   730 // to that point.
       
   731 // This function is used by ETapAndDragMultipoint command and called from
       
   732 // the RunL().
       
   733 // ----------------------------------------------------------------------------
       
   734 void CPointerEventHandler::MoveToNextPointL()
       
   735     {
       
   736     HTI_LOG_FUNC_IN( "CPointerEventHandler::MoveToNextPointL" );
       
   737     HTI_LOG_FORMAT( "Points remaining for this line = %d", iTapCount );
       
   738 
       
   739     if ( iTapCount == 0 ) // End of current line
       
   740         {
       
   741         PointerUp();
       
   742         if ( iCoords->Count() < 5 ) // point count & at least 2 points
       
   743             {
       
   744             // This was the last line, we are done
       
   745             SendOkMsgL();
       
   746             iReady = ETrue;
       
   747             }
       
   748         else
       
   749             {
       
   750             // New line starts: take the point count of this line and
       
   751             // first coordinates.
       
   752             iTapCount = ( *iCoords )[0];
       
   753             iCoords->Remove( 0 );
       
   754             iX = ( *iCoords )[0];
       
   755             iCoords->Remove( 0 );
       
   756             iY = ( *iCoords )[0];
       
   757             iCoords->Remove( 0 );
       
   758             HTI_LOG_FORMAT( "Point count for new line = %d", iTapCount );
       
   759             iTimer.After( iStatus, iActionDelay );
       
   760             SetActive();
       
   761             }
       
   762         }
       
   763 
       
   764     else  // Current line continues: take next point coords and move
       
   765         {
       
   766         iX = ( *iCoords )[0];
       
   767         iCoords->Remove( 0 );
       
   768         iY = ( *iCoords )[0];
       
   769         iCoords->Remove( 0 );
       
   770         PointerMove();
       
   771         iTapCount--;
       
   772         iTimer.After( iStatus, iEventDelay );
       
   773         SetActive();
       
   774         }
       
   775 
       
   776     HTI_LOG_FUNC_OUT( "CPointerEventHandler::MoveToNextPointL" );
       
   777     }
       
   778 
       
   779 // ----------------------------------------------------------------------------
       
   780 // CPointerEventHandler::PointerDown()
       
   781 // ----------------------------------------------------------------------------
       
   782 void CPointerEventHandler::PointerDown()
       
   783     {
       
   784     HTI_LOG_FUNC_IN( "CPointerEventHandler::PointerDown" );
       
   785     SimulatePointerEvent( TRawEvent::EButton1Down );
       
   786     iState = EPointerDown;
       
   787     HTI_LOG_FUNC_OUT( "CPointerEventHandler::PointerDown" );
       
   788     }
       
   789 
       
   790 // ----------------------------------------------------------------------------
       
   791 // CPointerEventHandler::PointerUp()
       
   792 // ----------------------------------------------------------------------------
       
   793 void CPointerEventHandler::PointerUp()
       
   794     {
       
   795     HTI_LOG_FUNC_IN( "CPointerEventHandler::PointerUp" );
       
   796     SimulatePointerEvent( TRawEvent::EButton1Up );
       
   797     iState = EPointerUp;
       
   798     HTI_LOG_FUNC_OUT( "CPointerEventHandler::PointerUp" );
       
   799     }
       
   800 
       
   801 // ----------------------------------------------------------------------------
       
   802 // CPointerEventHandler::PointerMove()
       
   803 // ----------------------------------------------------------------------------
       
   804 void CPointerEventHandler::PointerMove()
       
   805     {
       
   806     HTI_LOG_FUNC_IN( "CPointerEventHandler::PointerMove" );
       
   807     SimulatePointerEvent( TRawEvent::EPointerMove );
       
   808     iState = EPointerMoving;
       
   809     HTI_LOG_FUNC_OUT( "CPointerEventHandler::PointerMove" );
       
   810     }
       
   811 
       
   812 // ----------------------------------------------------------------------------
       
   813 // CPointerEventHandler::SimulatePointerEvent()
       
   814 // Sends the pointer event as a raw event.
       
   815 // ----------------------------------------------------------------------------
       
   816 void CPointerEventHandler::SimulatePointerEvent( TRawEvent::TType aType )
       
   817     {
       
   818     HTI_LOG_FUNC_IN( "CPointerEventHandler::SimulatePointerEvent" );
       
   819     
       
   820     TRawEvent rawEvent;
       
   821     
       
   822     if ( iCommand == EAdvancedTapScreen )
       
   823         {
       
   824         TInt i;
       
   825          for ( i = 0; i < iAdvancedPointers.Count(); i++ )
       
   826              {
       
   827              rawEvent.SetPointerNumber( iAdvancedPointers[i]->PointerNum ); 
       
   828              rawEvent.Set( aType, iAdvancedPointers[i]->X, iAdvancedPointers[i]->Y, iAdvancedPointers[i]->Z);    
       
   829              iWsSession.SimulateRawEvent( rawEvent );    
       
   830              }      
       
   831         }
       
   832     else if ( iCommand == EPinchZoom  )
       
   833         {
       
   834         TInt i,index,pointnum=-1;
       
   835         RPointerArray<TAdvancedPointer> array;
       
   836         for ( i = 0; i < iAdvPointerMoveArray.Count(); i++ )
       
   837             {
       
   838             TAdvancedPointer* point=iAdvPointerMoveArray[i];   
       
   839             if (point->PointerNum!=pointnum)
       
   840                 {
       
   841                 pointnum=point->PointerNum;                
       
   842                 rawEvent.SetPointerNumber( point->PointerNum ); 
       
   843                 rawEvent.Set( aType, point->X, point->Y, point->Z); 	
       
   844                 iWsSession.SimulateRawEvent( rawEvent );	
       
   845                 
       
   846                 HTI_LOG_FORMAT( "SimulateAdvanced event=%d ", aType );
       
   847                 HTI_LOG_FORMAT( "SimulateAdvanced PointerNum=%d", point->PointerNum );
       
   848                 HTI_LOG_FORMAT( "SimulateAdvanced X=%d ", point->X );
       
   849                 HTI_LOG_FORMAT( "SimulateAdvanced Y=%d ", point->Y );
       
   850                 HTI_LOG_FORMAT( "SimulateAdvanced Z=%d", point->Z );
       
   851                 
       
   852                 array.Append(point);
       
   853                 }
       
   854             }
       
   855         for (i=0;i<array.Count();i++)
       
   856             {
       
   857             index=iAdvPointerMoveArray.Find(array[i]);
       
   858             if (index!=KErrNotFound)
       
   859                 iAdvPointerMoveArray.Remove(index);
       
   860             }
       
   861         array.ResetAndDestroy();
       
   862         }
       
   863     else
       
   864         {	
       
   865         rawEvent.Set( aType, iX, iY );
       
   866         iWsSession.SimulateRawEvent( rawEvent );
       
   867         }
       
   868     
       
   869     iWsSession.Flush();
       
   870     HTI_LOG_FUNC_OUT( "CPointerEventHandler::SimulatePointerEvent" );
       
   871     }
       
   872 
       
   873 // ----------------------------------------------------------------------------
       
   874 // CPointerEventHandler::IsMultitouch()
       
   875 // ----------------------------------------------------------------------------
       
   876 TBool CPointerEventHandler::IsMultitouch()
       
   877     {
       
   878     HTI_LOG_FUNC_IN("CPointerEventHandler::IsMultitouch");
       
   879     TBool isMultitouch = EFalse;
       
   880     if ( iCommand == EAdvancedTapScreen || iCommand == EPinchZoom )
       
   881         {
       
   882         isMultitouch = ETrue;
       
   883         }
       
   884     HTI_LOG_FUNC_OUT("CPointerEventHandler::IsMultitouch");
       
   885     return isMultitouch;
       
   886     }    
       
   887     
       
   888 // ----------------------------------------------------------------------------
       
   889 // CPointerEventHandler::SendOkMsgL()
       
   890 // ----------------------------------------------------------------------------
       
   891 void CPointerEventHandler::SendOkMsgL()
       
   892     {
       
   893     HTI_LOG_FUNC_IN("CPointerEventHandler::SendOkMsgL");
       
   894 
       
   895     User::LeaveIfNull( iDispatcher );
       
   896     TBuf8<1> response;
       
   897     response.Append( EResultOk );
       
   898     HBufC8* respH8 = response.AllocL();
       
   899     User::LeaveIfError( iDispatcher->DispatchOutgoingMessage(
       
   900         respH8, KKeyEventServiceUid ) );
       
   901 
       
   902     HTI_LOG_FUNC_OUT("CPointerEventHandler::SendOkMsgL");
       
   903     }
       
   904 
       
   905 // ----------------------------------------------------------------------------
       
   906 // CPointerEventHandler::SendErrorMessageL()
       
   907 // ----------------------------------------------------------------------------
       
   908 void CPointerEventHandler::SendErrorMessageL(
       
   909         TInt aError, const TDesC8& aDescription )
       
   910     {
       
   911     HTI_LOG_FUNC_IN("CPointerEventHandler::SendErrorMessageL");
       
   912     User::LeaveIfNull( iDispatcher );
       
   913     User::LeaveIfError( iDispatcher->DispatchOutgoingErrorMessage(
       
   914         aError, aDescription, KKeyEventServiceUid ) );
       
   915     HTI_LOG_FUNC_OUT("CPointerEventHandler::SendErrorMessageL");
       
   916     }
       
   917 
       
   918 // End of file