htiui/HtiServicePlugins/HtiKeyEventServicePlugin/src/PointerEventHandler.cpp
branchRCL_3
changeset 3 2703485a934c
parent 0 d6fe6244b863
child 6 69ec17276f52
equal deleted inserted replaced
0:d6fe6244b863 3:2703485a934c
    13 *
    13 *
    14 * Description:  Functional implementation of pointer event service
    14 * Description:  Functional implementation of pointer event service
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
       
    19 // INCLUDE FILES
    18 // INCLUDE FILES
    20 #include "HtiKeyEventServiceplugin.h"
    19 #include "HtiKeyEventServicePlugin.h"
    21 #include "PointerEventHandler.h"
    20 #include "PointerEventHandler.h"
    22 
    21 
    23 #include <HtiDispatcherInterface.h>
    22 #include <HtiDispatcherInterface.h>
    24 #include <HTILogging.h>
    23 #include <HtiLogging.h>
    25 
    24 
    26 
    25 
    27 // CONSTANTS
    26 // CONSTANTS
    28 _LIT8( KErrorMissingCommand, "Command was not given - message was empty" );
    27 _LIT8( KErrorMissingCommand, "Command was not given - message was empty" );
    29 _LIT8( KErrorServiceNotReady, "Service is busy - possibly executing long running pointer events" );
    28 _LIT8( KErrorServiceNotReady, "Service is busy - possibly executing long running pointer events" );
    30 _LIT8( KErrorInvalidParameters, "Command parameters not valid" );
    29 _LIT8( KErrorInvalidParameters, "Command parameters not valid" );
    31 _LIT8( KErrorUnrecognizedCommand, "Unrecognized command" );
    30 _LIT8( KErrorUnrecognizedCommand, "Unrecognized command" );
    32 _LIT8( KErrorInternalFailure, "Internal pointer command failure" );
    31 _LIT8( KErrorInternalFailure, "Internal pointer command failure" );
       
    32 _LIT8( KErrorGetHALData, "Can not get the HAL data" );
    33 
    33 
    34 const TInt KTapCmdLength = 10;
    34 const TInt KTapCmdLength = 10;
    35 const TInt KDragMultiCmdMinLength = 14;
    35 const TInt KDragMultiCmdMinLength = 14;
    36 const TInt KSinglePointerCmdLength = 4;
    36 const TInt KSinglePointerCmdLength = 4;
       
    37 const TInt KAdvancedTapScreenCmdMinLength = 16;
       
    38 const TInt KPinchZoomCmdMinLength = 30;
       
    39 
    37 
    40 
    38 // ----------------------------------------------------------------------------
    41 // ----------------------------------------------------------------------------
    39 // CPointerEventHandler::NewL()
    42 // CPointerEventHandler::NewL()
    40 // ----------------------------------------------------------------------------
    43 // ----------------------------------------------------------------------------
    41 CPointerEventHandler* CPointerEventHandler::NewL()
    44 CPointerEventHandler* CPointerEventHandler::NewL()
    70     if ( iCoords )
    73     if ( iCoords )
    71         {
    74         {
    72         iCoords->Close();
    75         iCoords->Close();
    73         }
    76         }
    74     delete iCoords;
    77     delete iCoords;
       
    78 	
       
    79 	iAdvancedPointers.ResetAndDestroy();
       
    80 	iDelayArray.ResetAndDestroy();  
       
    81 	iAdvPointerMoveArray.ResetAndDestroy(); 
    75     }
    82     }
    76 
    83 
    77 // ----------------------------------------------------------------------------
    84 // ----------------------------------------------------------------------------
    78 // CPointerEventHandler::ConstructL()
    85 // CPointerEventHandler::ConstructL()
    79 // ----------------------------------------------------------------------------
    86 // ----------------------------------------------------------------------------
    98 // ----------------------------------------------------------------------------
   105 // ----------------------------------------------------------------------------
    99 void CPointerEventHandler::RunL()
   106 void CPointerEventHandler::RunL()
   100     {
   107     {
   101     HTI_LOG_FUNC_IN( "CPointerEventHandler::RunL" );
   108     HTI_LOG_FUNC_IN( "CPointerEventHandler::RunL" );
   102 
   109 
   103     if ( iCommand == ETapScreen )
   110     if ( iCommand == ETapScreen || iCommand == EAdvancedTapScreen )
   104         {
   111         {
   105         ChangePointerStateL();
   112         ChangePointerStateL();
   106         }
   113         }
   107 
   114 
   108     else if ( iCommand == ETapAndDrag && iState == EPointerDown )
   115     else if ( iCommand == ETapAndDrag  && iState == EPointerDown )
   109         {
   116         {
   110         PointerMove();
   117         PointerMove();
   111         PointerUp();
   118         PointerUp();
   112         SendOkMsgL();
   119         SendOkMsgL();
   113         iReady = ETrue;
   120         iReady = ETrue;
   125         else
   132         else
   126             {
   133             {
   127             MoveToNextPointL(); // Continuing current line
   134             MoveToNextPointL(); // Continuing current line
   128             }
   135             }
   129         }
   136         }
   130 
   137     else if ( iCommand == EPinchZoom )
       
   138         {
       
   139         PointerMove();
       
   140         if ( !AdvancedStartDelay())
       
   141             {
       
   142             PointerUp();
       
   143             SendOkMsgL();
       
   144             iReady = ETrue;
       
   145             }
       
   146         }		
   131     HTI_LOG_FUNC_OUT( "CPointerEventHandler::RunL" );
   147     HTI_LOG_FUNC_OUT( "CPointerEventHandler::RunL" );
   132     }
   148     }
   133 
   149 
   134 // ----------------------------------------------------------------------------
   150 // ----------------------------------------------------------------------------
   135 // CPointerEventHandler::RunError()
   151 // CPointerEventHandler::RunError()
   192             break;
   208             break;
   193         case EPressPointerDown:
   209         case EPressPointerDown:
   194         case ELiftPointerUp:
   210         case ELiftPointerUp:
   195             HandlePointerDownOrUpL( aMessage.Right( aMessage.Length() - 1 ) );
   211             HandlePointerDownOrUpL( aMessage.Right( aMessage.Length() - 1 ) );
   196             break;
   212             break;
       
   213 		case EAdvancedTapScreen:
       
   214 		    HandleAdvancedTapScreenL( aMessage.Right( aMessage.Length() - 1 ) );
       
   215             break;		
       
   216 		case EPinchZoom: 
       
   217 		    HandlePinchZoomL( aMessage.Right( aMessage.Length() - 1 ) );
       
   218             break;
       
   219 		
   197         default:
   220         default:
   198             SendErrorMessageL( EUnrecognizedCommand,
   221             SendErrorMessageL( EUnrecognizedCommand,
   199                 KErrorUnrecognizedCommand );
   222                 KErrorUnrecognizedCommand );
   200             break;
   223             break;
   201         }
   224         }
   238     iReady = EFalse;
   261     iReady = EFalse;
   239     ChangePointerStateL();
   262     ChangePointerStateL();
   240 
   263 
   241     HTI_LOG_FUNC_OUT( "CPointerEventHandler::HandleTapScreenL" );
   264     HTI_LOG_FUNC_OUT( "CPointerEventHandler::HandleTapScreenL" );
   242     }
   265     }
       
   266 	
       
   267 
   243 
   268 
   244 // ----------------------------------------------------------------------------
   269 // ----------------------------------------------------------------------------
   245 // CPointerEventHandler::HandleTapAndDragL()
   270 // CPointerEventHandler::HandleTapAndDragL()
   246 // Handles a single drag and drop with straight line.
   271 // Handles a single drag and drop with straight line.
   247 // ----------------------------------------------------------------------------
   272 // ----------------------------------------------------------------------------
   407             iReady = ETrue;
   432             iReady = ETrue;
   408             }
   433             }
   409         }
   434         }
   410     HTI_LOG_FUNC_OUT( "CPointerEventHandler::ChangePointerStateL" );
   435     HTI_LOG_FUNC_OUT( "CPointerEventHandler::ChangePointerStateL" );
   411     }
   436     }
       
   437 	
       
   438 	// ----------------------------------------------------------------------------
       
   439 	
       
   440 // ----------------------------------------------------------------------------
       
   441 // CPointerEventHandler::HandleAdvancedTapScreenL()
       
   442 // ****cherry.
       
   443 // ----------------------------------------------------------------------------
       
   444 
       
   445 void CPointerEventHandler::HandleAdvancedTapScreenL( const TDesC8& aData )
       
   446     {
       
   447     
       
   448     HTI_LOG_FUNC_IN( "CPointerEventHandler::HandleAdvancedTapScreenL" );
       
   449 
       
   450     if ( aData.Length() < KAdvancedTapScreenCmdMinLength ) //KAdvancedTapScreenCmdMinLength needs to be defined
       
   451         {
       
   452         SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   453         return;
       
   454         }
       
   455 	TInt dataLength = aData.Length();
       
   456 	
       
   457     // Parse the parameters - correct length is already verified
       
   458 	TInt offset = 0;
       
   459 	
       
   460 	iEventDelay = ( aData[offset] + ( aData[offset+1] << 8 ) ) * 1000;
       
   461     offset += 2;
       
   462     HTI_LOG_FORMAT( "Time to hold down = %d", iEventDelay.Int() );
       
   463     iTapCount = aData[offset] + ( aData[offset+1] << 8 );
       
   464     offset += 2;
       
   465     HTI_LOG_FORMAT( "Tap count = %d", iTapCount );
       
   466     iActionDelay = ( aData[offset] + ( aData[offset+1] << 8 ) ) * 1000;
       
   467 	offset += 2;
       
   468     HTI_LOG_FORMAT( "Pause between taps = %d", iActionDelay.Int() );		
       
   469 	TInt pointerCount = aData[offset] + ( aData[offset+1] << 8 );
       
   470 	offset += 2;
       
   471 	HTI_LOG_FORMAT( "Pointer Count = %d", pointerCount );
       
   472 	
       
   473     iAdvancedPointers.ResetAndDestroy();
       
   474 
       
   475     // Read integers from aData to the array, all integers are 2 bytes
       
   476     for ( TInt i = 0; i < pointerCount; i++ )
       
   477         {
       
   478 		TAdvancedPointer* advancedPointer = new (ELeave) TAdvancedPointer;
       
   479 		
       
   480 		advancedPointer->PointerNum = aData[offset];
       
   481 		offset += 1;
       
   482 		HTI_LOG_FORMAT( "%d Pointer", advancedPointer->PointerNum );
       
   483 		
       
   484 		advancedPointer->X = aData[offset] + ( aData[offset+1] << 8 );
       
   485 		offset += 2;
       
   486 		HTI_LOG_FORMAT( "X coord down = %d", advancedPointer->X );
       
   487 		
       
   488 		advancedPointer->Y = aData[offset] + ( aData[offset+1] << 8 );
       
   489 		offset += 2;
       
   490 		HTI_LOG_FORMAT( "Y coord down = %d", advancedPointer->Y );
       
   491 
       
   492 		advancedPointer->Z = aData[offset] + ( aData[offset+1] << 8 );
       
   493 		offset += 2;
       
   494 		HTI_LOG_FORMAT( "Z coord down = %d", advancedPointer->Z );
       
   495 		
       
   496         iAdvancedPointers.AppendL( advancedPointer );
       
   497         }
       
   498 	
       
   499     // Start tapping
       
   500     iReady = EFalse;
       
   501     ChangePointerStateL();
       
   502 
       
   503     HTI_LOG_FUNC_OUT( "CPointerEventHandler::HandleAdvancedTapScreenL" );
       
   504     
       
   505     }
       
   506 	
       
   507 // ----------------------------------------------------------------------------
       
   508 // CPointerEventHandler::HandlePinchZoomL()
       
   509 // ****cherry
       
   510 // ----------------------------------------------------------------------------
       
   511 void CPointerEventHandler::HandlePinchZoomL( const TDesC8& aData )
       
   512     {
       
   513     HTI_LOG_FUNC_IN( "CPointerEventHandler::HandlePinchZoomL" );
       
   514 
       
   515     if ( aData.Length() < KPinchZoomCmdMinLength ) //KPinchZoomCmdMinLength needs to be defined
       
   516         {
       
   517         SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   518         return;
       
   519         }
       
   520 	TInt dataLength = aData.Length();
       
   521 	
       
   522     // Parse the parameters - correct length is already verified
       
   523 	TInt offset = 0;
       
   524 	
       
   525 	TTimeIntervalMicroSeconds32 eventDelay = ( aData[offset] + ( aData[offset+1] << 8 ) ) * 1000;
       
   526 	offset += 2;
       
   527     HTI_LOG_FORMAT( "Event time = %d", eventDelay.Int() );
       
   528 	
       
   529     TInt stepCount = aData[offset] + ( aData[offset+1] << 8 );
       
   530     offset += 2;
       
   531     HTI_LOG_FORMAT( "Step Count = %d", stepCount );
       
   532         
       
   533 	TInt pointerCount = aData[offset] + ( aData[offset+1] << 8 );
       
   534 	offset += 2;
       
   535 	HTI_LOG_FORMAT( "Pointer Count = %d", pointerCount );
       
   536 	
       
   537 	iAdvPointerMoveArray.ResetAndDestroy();	
       
   538 
       
   539     // Read integers from aData to the array, all integers are 2 bytes
       
   540     for ( TInt i = 0; i < pointerCount; i++ )
       
   541         {
       
   542         TInt pointNumber,X1, Y1, Z1,X2,Y2, Z2 ;
       
   543         
       
   544         // start point	
       
   545 		pointNumber = aData[offset];
       
   546 		offset += 1;
       
   547 		HTI_LOG_FORMAT( "%d Pointer Start", pointNumber );
       
   548 		
       
   549 		X1 = aData[offset] + ( aData[offset+1] << 8 );
       
   550 		offset += 2;
       
   551 		HTI_LOG_FORMAT( "X coord down = %d", X1 );
       
   552 		
       
   553 		Y1 = aData[offset] + ( aData[offset+1] << 8 );
       
   554 		offset += 2;
       
   555 		HTI_LOG_FORMAT( "Y coord down = %d", Y1 );
       
   556 
       
   557 		Z1 = aData[offset] + ( aData[offset+1] << 8 );
       
   558 		offset += 2;
       
   559 		HTI_LOG_FORMAT( "Z coord down = %d", Z1 );		
       
   560 
       
   561 		// end point     
       
   562 		X2 = aData[offset] + ( aData[offset+1] << 8 );
       
   563         offset += 2;
       
   564         HTI_LOG_FORMAT( "X coord down = %d", X2 );
       
   565         
       
   566         Y2 = aData[offset] + ( aData[offset+1] << 8 );
       
   567         offset += 2;
       
   568         HTI_LOG_FORMAT( "Y coord down = %d", Y2 );
       
   569 
       
   570         Z2 = aData[offset] + ( aData[offset+1] << 8 );
       
   571         offset += 2;
       
   572         HTI_LOG_FORMAT( "Z coord down = %d", Z2 );
       
   573         
       
   574         AdvanceAddMiddlePointL(pointNumber,X1, Y1, Z1,X2,Y2, Z2,stepCount );        
       
   575 
       
   576         }
       
   577     	
       
   578     AdvancedAddDelayArray(eventDelay,stepCount);
       
   579    
       
   580     iReady = EFalse;
       
   581     PointerDown();
       
   582 
       
   583     if (!AdvancedStartDelay())
       
   584         {
       
   585         SendErrorMessageL( EInvalidParameters, KErrorInvalidParameters );
       
   586         return;        
       
   587         }
       
   588 
       
   589     HTI_LOG_FUNC_OUT( "CPointerEventHandler::HandlePinchZoomL" );
       
   590     }	
       
   591 
       
   592 // ----------------------------------------------------------------------------
       
   593 // CPointerEventHandler::AdvancedStartDelay()
       
   594 // ----------------------------------------------------------------------------
       
   595 TBool CPointerEventHandler::AdvancedStartDelay()
       
   596     {
       
   597     HTI_LOG_FUNC_IN( "CPointerEventHandler::AdvancedStartDelay" );
       
   598     TBool ret=EFalse;
       
   599     if (iDelayArray.Count()>0)
       
   600         {
       
   601         TTimeIntervalMicroSeconds32* time=iDelayArray[0];
       
   602         iDelayArray.Remove(0);
       
   603         ret=ETrue;
       
   604   
       
   605         iTimer.After( iStatus, *time );
       
   606         delete time;
       
   607         SetActive();
       
   608         }
       
   609     HTI_LOG_FUNC_OUT( "CPointerEventHandler::AdvancedStartDelay" );
       
   610     return ret;
       
   611     }
       
   612 
       
   613 // ----------------------------------------------------------------------------
       
   614 // CPointerEventHandler::AdvanceAddMiddlePointL()
       
   615 // ----------------------------------------------------------------------------
       
   616 void CPointerEventHandler::AdvanceAddMiddlePointL(TInt aPointNumber,TInt aX1,TInt aY1, TInt aZ1, 
       
   617         TInt aX2,TInt aY2, TInt aZ2 , TInt aStepCount )
       
   618     {
       
   619     HTI_LOG_FUNC_IN( "CPointerEventHandler::AdvanceAddMiddlePointL" );
       
   620     TInt dx=(aX2-aX1)/aStepCount;
       
   621     TInt dy=(aY2-aY1)/aStepCount;  
       
   622     
       
   623     for (TInt i=0;i<=aStepCount+1;i++)
       
   624         {
       
   625         TAdvancedPointer* point = new (ELeave) TAdvancedPointer;
       
   626         CleanupStack::PushL(point);
       
   627         iAdvPointerMoveArray.AppendL(point);
       
   628         CleanupStack::Pop();
       
   629         
       
   630         point->PointerNum=aPointNumber;
       
   631         if (i<aStepCount)
       
   632             {
       
   633             point->X=aX1+i*dx;
       
   634             point->Y=aY1+i*dy;
       
   635             point->Z=aZ1;
       
   636             }
       
   637         else
       
   638             {
       
   639             point->X=aX2;
       
   640             point->Y=aY2;
       
   641             point->Z=aZ2;
       
   642             }             
       
   643                   
       
   644         } 
       
   645     
       
   646     HTI_LOG_FUNC_OUT( "CPointerEventHandler::AdvanceAddMiddlePointL" );
       
   647     }
       
   648 
       
   649 // ----------------------------------------------------------------------------
       
   650 // CPointerEventHandler::AdvancedAddDelayArray()
       
   651 // ----------------------------------------------------------------------------
       
   652 void CPointerEventHandler::AdvancedAddDelayArray(TTimeIntervalMicroSeconds32 aDelay , TInt aStepCount )
       
   653     {
       
   654     HTI_LOG_FUNC_IN( "CPointerEventHandler::AdvancedAddDelayArray" );
       
   655     
       
   656     TInt interval=aDelay.Int()/aStepCount;
       
   657     iDelayArray.ResetAndDestroy();    
       
   658     
       
   659     for (TInt i=0;i<aStepCount;i++)
       
   660         {
       
   661         TTimeIntervalMicroSeconds32* time = new (ELeave) TTimeIntervalMicroSeconds32(interval);
       
   662         CleanupStack::PushL(time);
       
   663         iDelayArray.AppendL(time);
       
   664         CleanupStack::Pop(time);
       
   665         } 
       
   666     HTI_LOG_FUNC_OUT( "CPointerEventHandler::AdvancedAddDelayArray" );
       
   667     }
   412 
   668 
   413 // ----------------------------------------------------------------------------
   669 // ----------------------------------------------------------------------------
   414 // CPointerEventHandler::MoveToNextPointL()
   670 // CPointerEventHandler::MoveToNextPointL()
   415 // Takes the next point from the coordinate array and initiates pointer moving
   671 // Takes the next point from the coordinate array and initiates pointer moving
   416 // to that point.
   672 // to that point.
   500 // Sends the pointer event as a raw event.
   756 // Sends the pointer event as a raw event.
   501 // ----------------------------------------------------------------------------
   757 // ----------------------------------------------------------------------------
   502 void CPointerEventHandler::SimulatePointerEvent( TRawEvent::TType aType )
   758 void CPointerEventHandler::SimulatePointerEvent( TRawEvent::TType aType )
   503     {
   759     {
   504     HTI_LOG_FUNC_IN( "CPointerEventHandler::SimulatePointerEvent" );
   760     HTI_LOG_FUNC_IN( "CPointerEventHandler::SimulatePointerEvent" );
       
   761     
   505     TRawEvent rawEvent;
   762     TRawEvent rawEvent;
   506     rawEvent.Set( aType, iX, iY );
   763     
   507     iWsSession.SimulateRawEvent( rawEvent );
   764     if ( iCommand == EAdvancedTapScreen )
       
   765         {
       
   766         TInt i;
       
   767          for ( i = 0; i < iAdvancedPointers.Count(); i++ )
       
   768              {
       
   769              rawEvent.SetPointerNumber( iAdvancedPointers[i]->PointerNum ); 
       
   770              rawEvent.Set( aType, iAdvancedPointers[i]->X, iAdvancedPointers[i]->Y, iAdvancedPointers[i]->Z);    
       
   771              iWsSession.SimulateRawEvent( rawEvent );    
       
   772              }      
       
   773         }
       
   774     else if ( iCommand == EPinchZoom  )
       
   775         {
       
   776         TInt i,index,pointnum=-1;
       
   777         RPointerArray<TAdvancedPointer> array;
       
   778         for ( i = 0; i < iAdvPointerMoveArray.Count(); i++ )
       
   779             {
       
   780             TAdvancedPointer* point=iAdvPointerMoveArray[i];   
       
   781             if (point->PointerNum!=pointnum)
       
   782                 {
       
   783                 pointnum=point->PointerNum;                
       
   784                 rawEvent.SetPointerNumber( point->PointerNum ); 
       
   785                 rawEvent.Set( aType, point->X, point->Y, point->Z); 	
       
   786                 iWsSession.SimulateRawEvent( rawEvent );	
       
   787                 
       
   788                 HTI_LOG_FORMAT( "SimulateAdvanced event=%d ", aType );
       
   789                 HTI_LOG_FORMAT( "SimulateAdvanced PointerNum=%d", point->PointerNum );
       
   790                 HTI_LOG_FORMAT( "SimulateAdvanced X=%d ", point->X );
       
   791                 HTI_LOG_FORMAT( "SimulateAdvanced Y=%d ", point->Y );
       
   792                 HTI_LOG_FORMAT( "SimulateAdvanced Z=%d", point->Z );
       
   793                 
       
   794                 array.Append(point);
       
   795                 }
       
   796             }
       
   797         for (i=0;i<array.Count();i++)
       
   798             {
       
   799             index=iAdvPointerMoveArray.Find(array[i]);
       
   800             if (index!=KErrNotFound)
       
   801                 iAdvPointerMoveArray.Remove(index);
       
   802             }
       
   803         array.ResetAndDestroy();
       
   804         }
       
   805     else
       
   806         {	
       
   807         rawEvent.Set( aType, iX, iY );
       
   808         iWsSession.SimulateRawEvent( rawEvent );
       
   809         }
       
   810     
   508     iWsSession.Flush();
   811     iWsSession.Flush();
   509     HTI_LOG_FUNC_OUT( "CPointerEventHandler::SimulatePointerEvent" );
   812     HTI_LOG_FUNC_OUT( "CPointerEventHandler::SimulatePointerEvent" );
   510     }
   813     }
   511 
   814 
       
   815 // ----------------------------------------------------------------------------
       
   816 // CPointerEventHandler::IsMultitouch()
       
   817 // ----------------------------------------------------------------------------
       
   818 TBool CPointerEventHandler::IsMultitouch()
       
   819     {
       
   820     HTI_LOG_FUNC_IN("CPointerEventHandler::IsMultitouch");
       
   821     TBool isMultitouch = EFalse;
       
   822     if ( iCommand == EAdvancedTapScreen || iCommand == EPinchZoom )
       
   823         {
       
   824         isMultitouch = ETrue;
       
   825         }
       
   826     HTI_LOG_FUNC_OUT("CPointerEventHandler::IsMultitouch");
       
   827     return isMultitouch;
       
   828     }    
       
   829     
   512 // ----------------------------------------------------------------------------
   830 // ----------------------------------------------------------------------------
   513 // CPointerEventHandler::SendOkMsgL()
   831 // CPointerEventHandler::SendOkMsgL()
   514 // ----------------------------------------------------------------------------
   832 // ----------------------------------------------------------------------------
   515 void CPointerEventHandler::SendOkMsgL()
   833 void CPointerEventHandler::SendOkMsgL()
   516     {
   834     {