web_plat/stmgesturefw_api/inc/stmgestureinterface.h
changeset 28 d39add9822e2
equal deleted inserted replaced
27:6297cdf66332 28:d39add9822e2
       
     1 /*
       
     2 * Copyright (c) 2008 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 the License "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:   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __STMGESTUREINTERFACE_H__
       
    20 #define __STMGESTUREINTERFACE_H__
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <rt_gestureif.h>
       
    24 #include <rt_gesturelistener.h>
       
    25 #include <rt_uievent.h>
       
    26 #include <stmgesturelistener.h>
       
    27 
       
    28 // FORWARD DECLARATION
       
    29 namespace stmGesture
       
    30 {
       
    31     class CGestureFramework;
       
    32     class MGestureRecogniserIf;
       
    33 }
       
    34 
       
    35 class CStmGestureContext;
       
    36 class MStmGestureListener;
       
    37 
       
    38 typedef stmGesture::MGestureIf MStmGesture;
       
    39 typedef stmGesture::TGestureUid TStmGestureUid;
       
    40 typedef stmGesture::MGestureListener MStmGestureEngineListener;
       
    41 typedef stmGesture::MGestureRecogniserIf MStmGestureRecogniser;
       
    42 typedef stmGesture::TGestureSettings TStmGestureSettings;
       
    43 typedef stmGesture::TGestureAreaSettings TStmGestureAreaSettings;
       
    44 typedef stmGesture::TGestureArea TStmGestureArea;
       
    45 
       
    46 ///==================================================================
       
    47 
       
    48 /**
       
    49  * Interface class for defining gesture settings parameters
       
    50  */
       
    51 class MStmGestureParameters
       
    52     {
       
    53 public:
       
    54     virtual TStmGestureArea* Area(TStmGestureAreaSettings aArea) = 0;
       
    55     virtual TInt Param(TStmGestureSettings aParam) const = 0;
       
    56     virtual TUint8 Enabled(TStmGestureUid aGesture) const = 0;
       
    57     };
       
    58 
       
    59 ///==================================================================
       
    60 
       
    61 /**
       
    62  * Class definition for gesture settings parameters
       
    63  */
       
    64 NONSHARABLE_CLASS( CStmGestureParameters ): public CBase, public MStmGestureParameters
       
    65     {
       
    66 public:
       
    67     /*!
       
    68      * Constructors
       
    69      */
       
    70     IMPORT_C CStmGestureParameters();
       
    71     IMPORT_C CStmGestureParameters(const CStmGestureParameters& aParams);
       
    72 
       
    73 public: //getter methods
       
    74 
       
    75     /*!
       
    76      * To get the area settings
       
    77      */
       
    78     TStmGestureArea* Area(TStmGestureAreaSettings aArea) { return &iAreaSettings[aArea]; }
       
    79 
       
    80     /*!
       
    81      * To get Gesture params
       
    82      */
       
    83     TInt Param(TStmGestureSettings aParam) const { return iParam[aParam];  }
       
    84 
       
    85     /*!
       
    86      * Gesture enabled or not
       
    87      */
       
    88     TUint8 Enabled(TStmGestureUid aGesture) const { return iEnabled[aGesture] != 0; }
       
    89 
       
    90 public: // setter methods
       
    91 
       
    92     /*!
       
    93      * To set the parameters
       
    94      */
       
    95     void SetParam(TStmGestureSettings aParam, TInt aValue) { iParam[aParam] = aValue; }
       
    96 
       
    97     /*!
       
    98      * To enable or disble the gestures
       
    99      */
       
   100     void SetEnabled(TStmGestureUid aGesture, TUint8 aParam) { iEnabled[aGesture] = aParam; }
       
   101 
       
   102     /*!
       
   103      * Gesture settings
       
   104      */
       
   105     TInt& operator[](TStmGestureSettings aParam) { return iParam[aParam]; }
       
   106 
       
   107 private:
       
   108     TInt iParam[stmGesture::EGestureSettingsCount];
       
   109     TStmGestureArea iAreaSettings[stmGesture::EGestureAreaSettingsCount];
       
   110     TInt iModified;
       
   111     TUint8 iEnabled[stmGesture::EStmGestureUid_Count];
       
   112     };
       
   113 
       
   114 ///==================================================================
       
   115 
       
   116 /**
       
   117  * CStmGestureEngine Class Declaration
       
   118  */
       
   119 NONSHARABLE_CLASS( CStmGestureEngine ): public CBase
       
   120     {
       
   121 public:
       
   122 
       
   123     /*!
       
   124      * Gesture Engine Creation
       
   125      */
       
   126     IMPORT_C static CStmGestureEngine* NewL();
       
   127     ~CStmGestureEngine();
       
   128 
       
   129 public:
       
   130 
       
   131     /*!
       
   132      * To Create a context in gesture engine
       
   133      */
       
   134     IMPORT_C CStmGestureContext* CreateContextL(TInt aId);
       
   135 
       
   136     /*!
       
   137      * To get the context
       
   138      */
       
   139     IMPORT_C CStmGestureContext* Context(TInt aId);
       
   140 
       
   141     /*!
       
   142      * Application use HandlePointerEventL API to pass the raw hardware events to the gesture library
       
   143      */
       
   144     IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent, void* target);
       
   145 
       
   146 private:
       
   147 
       
   148     /*!
       
   149      * default constructor
       
   150      */
       
   151     CStmGestureEngine();
       
   152 
       
   153     /*!
       
   154      * Two-phase constructor
       
   155      */
       
   156     void ConstructL();
       
   157 
       
   158 private: // used by friend class CStmGestureContext
       
   159 
       
   160     void EnableContextL(CStmGestureContext& aCtxt);
       
   161     void DisableContextL(CStmGestureContext& aCtxt);
       
   162 
       
   163     template<class T>
       
   164     void InitRecognizerL( T*& aGesture, CStmGestureContext& aContext, TBool aNewCOntext);
       
   165 
       
   166     void SetupRecognizersL(CStmGestureContext& aCtxt, TBool aNewContext);
       
   167 
       
   168 private:
       
   169     friend class CStmGestureContext;
       
   170     stmGesture::CGestureFramework* iGf;
       
   171     // Registered/owned contexts
       
   172     RPointerArray<CStmGestureContext> iContexts;
       
   173     // Active set of contexts; latest added defines parameters
       
   174     RPointerArray<CStmGestureContext> iCtxtStack;
       
   175     // Global/default parameters
       
   176     CStmGestureParameters* iConfig;
       
   177     TBool iDtorPhase;
       
   178     };
       
   179 
       
   180 ///==================================================================
       
   181 
       
   182 //Forward declaration
       
   183 class CGestureEventSender;
       
   184 
       
   185 /**
       
   186  * Gesture context represents a certain configuration of gesture parameters
       
   187  * (including what gestures are enabled) and gesture listeners.
       
   188  * Context can be created beforehand and reused later.
       
   189  * The assumed use of a context is to have rough correspondence between
       
   190  * UI view and enabled gestures.
       
   191  *
       
   192  * @note Gesture contexts are created by an instance of CStmGestureEngine.
       
   193  */
       
   194 
       
   195 class CStmGestureContext: public CBase, public MStmGestureEngineListener
       
   196     {
       
   197 public:
       
   198     /*!
       
   199      * Constructor
       
   200      */
       
   201     CStmGestureContext(CStmGestureEngine& aEngine);
       
   202 
       
   203     ~CStmGestureContext();
       
   204 
       
   205 public: /// Gesture listeners
       
   206 
       
   207     /*!
       
   208      * Add listener to the gesture processing context.
       
   209      * @param aListener Listener object
       
   210      * @param aPos Position of inserted listener which determines order in which it receives gesture events (0 == first, before existing)
       
   211      */
       
   212     IMPORT_C void AddListenerL(MStmGestureListener* aListener, TInt aPos = 0);
       
   213 
       
   214     /*!
       
   215      * Remove listener from the gesture processing context.
       
   216      * @param aListener Listener object
       
   217      */
       
   218     IMPORT_C TInt RemoveListener(MStmGestureListener* aListener);
       
   219 
       
   220     /*!
       
   221      * To get the list of listeners
       
   222      */
       
   223     const RPointerArray<MStmGestureListener>& Listeners() const { return iListeners; }
       
   224 
       
   225 public: /// Context activation
       
   226     
       
   227     /*!
       
   228      * To set the context configuration in Gesture Engine.
       
   229      */
       
   230     IMPORT_C void SetContext(CCoeControl* aControl);
       
   231    
       
   232     /*!
       
   233      * Initialize context configuration on the Gesture Engine.
       
   234      */
       
   235     IMPORT_C void ActivateL();
       
   236     
       
   237     /*!
       
   238      * deactivate context configuration on the Gesture Engine.
       
   239      */
       
   240     IMPORT_C void Deactivate();
       
   241 
       
   242     /*!
       
   243      * gesture configuration
       
   244      */
       
   245     CStmGestureParameters& Config() { return *iConfig; }
       
   246     
       
   247     /*!
       
   248      * Enable Logging
       
   249      */
       
   250     void SetLogging(TInt aEnabled) { iLogging = aEnabled; }
       
   251     
       
   252     /*!
       
   253      * Context control
       
   254      */
       
   255     CCoeControl* ContextControl() { return iOwnerControl; }
       
   256     
       
   257     /*!
       
   258      * is gesture context is active ?
       
   259      */   
       
   260     TBool IsActive() { return iActivated; }
       
   261      
       
   262     /*!
       
   263      * Context id
       
   264      */      
       
   265     TInt Id() const { return iCtxtId; }
       
   266     
       
   267 public: // from MStmGestureEngineListener
       
   268 
       
   269     void gestureEnter(MStmGesture& aGesture);
       
   270     void gestureExit(TStmGestureUid aGestureUid);
       
   271     CCoeControl* getOwner();
       
   272 
       
   273 private:
       
   274     friend class CStmGestureEngine;
       
   275 
       
   276     void ConstructL();
       
   277     void DispatchGestureEventL(TStmGestureUid aUid, MStmGesture* aGesture);
       
   278     void SuspendRecognizer(TStmGestureUid aUid);
       
   279     void EnableRecognizersL();
       
   280     void EnableRecognizerL(TStmGestureUid aUid);
       
   281 
       
   282 private:
       
   283     CStmGestureEngine& iEngine;
       
   284     // Application-specific ID for finding context
       
   285     TInt iCtxtId;
       
   286     TBool iActivated;
       
   287     CStmGestureParameters* iConfig;
       
   288     CCoeControl* iOwnerControl;
       
   289     //TBool iPinchUsed;
       
   290     RPointerArray<MStmGestureListener> iListeners;
       
   291     // for simplicity of addressing recognizers, we'll use fixed array
       
   292     // with UID-based index (range 0..N is assumed for UIDs)
       
   293     // @note Tap recognizer actually produces Tap and DoubleTap gesture,
       
   294     //       so should be handled carefully -- only Tap position is set
       
   295     MStmGestureRecogniser* iRecognizers[stmGesture::EStmGestureUid_Count];
       
   296     TBool iLogging;
       
   297     CGestureEventSender* iEventSender;
       
   298     };
       
   299 
       
   300 #endif