akntouchgesturefw/src/akntouchgesturefwsimulation.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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:  Touch gesture fw simulation class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "akntouchgesturefwimpl.h"
       
    20 #include "akntouchgesturefwsimulation.h"
       
    21 
       
    22 using namespace AknTouchGestureFw;
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // Sets the pointer number of an advanced pointer event.
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 void TAdvancedPointerEventHelper::SetPointerNumberToEvent(
       
    31     TAdvancedPointerEvent* aEvent,
       
    32     TInt aPointerNumber )
       
    33     {
       
    34     // Just to hack to set the pointer number: these members may not be
       
    35     // supported in the future...
       
    36     aEvent->iModifiers |= EModifierAdvancedPointerEvent;
       
    37     aEvent->iData.multiPos3D.iPointerNumber = aPointerNumber;
       
    38     }
       
    39 
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CAknTouchGestureFwSimulation::~CAknTouchGestureFwSimulation
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CAknTouchGestureFwSimulation::~CAknTouchGestureFwSimulation()
       
    46     {
       
    47     iDataArray.Reset();
       
    48     iDataArray.Close();
       
    49     }
       
    50 
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CAknTouchGestureFwSimulation::InitSimulationL
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 void CAknTouchGestureFwSimulation::InitSimulationL(
       
    57         CAknTouchGestureFw* aGestureFw,
       
    58         CAknTouchGestureFwImpl* aGestureEngine )
       
    59     {
       
    60     CAknTouchGestureFwSimulation* instance =
       
    61         static_cast< CAknTouchGestureFwSimulation* >(
       
    62                 CCoeEnv::Static( KAknTouchGestureFwSimulation ) );
       
    63     if ( !instance )
       
    64         {
       
    65         instance =
       
    66             new ( ELeave ) CAknTouchGestureFwSimulation();
       
    67         }
       
    68     // Check if already in array
       
    69     TBool gestureFwFound( EFalse );
       
    70     for ( TInt i = 0; i < instance->iDataArray.Count(); i++ )
       
    71         {
       
    72         if ( instance->iDataArray[ i ].iGestureFw == aGestureFw )
       
    73             {
       
    74             gestureFwFound = ETrue;
       
    75             break;
       
    76             }
       
    77         }
       
    78     // Add only if fw was not found from array
       
    79     if ( !gestureFwFound )
       
    80         {
       
    81         TAknTouchGestureFwSimulationData newData;
       
    82         newData.iGestureFw = aGestureFw;
       
    83         newData.iGestureEngine = aGestureEngine;
       
    84         instance->iDataArray.AppendL( newData );
       
    85         }
       
    86     }
       
    87 
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CAknTouchGestureFwSimulation::EndSimulation
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CAknTouchGestureFwSimulation::EndSimulation(
       
    94         CAknTouchGestureFw* aGestureFw )
       
    95     {
       
    96     CAknTouchGestureFwSimulation* instance =
       
    97         static_cast< CAknTouchGestureFwSimulation* >(
       
    98                 CCoeEnv::Static( KAknTouchGestureFwSimulation ) );
       
    99     if ( !instance )
       
   100         {
       
   101         return;
       
   102         }
       
   103     for ( TInt i = 0; i < instance->iDataArray.Count(); i++ )
       
   104         {
       
   105         if ( instance->iDataArray[ i ].iGestureFw == aGestureFw )
       
   106             {
       
   107             instance->iDataArray.Remove( i );
       
   108             break;
       
   109             }
       
   110         }
       
   111     }
       
   112 
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // Simulates a single pointer event.
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CAknTouchGestureFwSimulation::SimulateL( CAknTouchGestureFw* aGestureFw,
       
   119                                               TPointerEvent& aEvent,
       
   120                                               TInt aPointerNumber,
       
   121                                               TTime aTimeStamp )
       
   122     {
       
   123     CAknTouchGestureFwImpl* engine( NULL );
       
   124     for ( TInt i = 0; i < iDataArray.Count(); i++ )
       
   125         {
       
   126         if ( iDataArray[ i ].iGestureFw == aGestureFw )
       
   127             {
       
   128             engine = iDataArray[ i ].iGestureEngine;
       
   129             break;
       
   130             }
       
   131         }
       
   132     if ( engine )
       
   133         {
       
   134         TAdvancedPointerEvent* ctrlEvent =
       
   135             static_cast<TAdvancedPointerEvent*>( &aEvent );
       
   136         TAdvancedPointerEventHelper::SetPointerNumberToEvent(
       
   137                 ctrlEvent, aPointerNumber );
       
   138         
       
   139         TPointerEventData pointerData( 
       
   140                 *ctrlEvent, aPointerNumber, aTimeStamp, ETrue, ETrue );
       
   141         engine->HandleSimulatedPointerEventL( pointerData );
       
   142         }
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // Default C++ constructor.
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 CAknTouchGestureFwSimulation::CAknTouchGestureFwSimulation()
       
   151     : CCoeStatic( KAknTouchGestureFwSimulation )
       
   152     {
       
   153     }
       
   154 
       
   155 // End of File