|
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: State Machine implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef STATEMACHINE_H |
|
19 #define STATEMACHINE_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 #include <aknwseventobserver.h> |
|
24 |
|
25 #include <rt_uievent.h> |
|
26 #include "timerinterface.h" |
|
27 #include "statemachine_v2.h" |
|
28 |
|
29 class CCoeEnv; |
|
30 |
|
31 namespace stmUiEventEngine |
|
32 { |
|
33 |
|
34 class CCallbackTimer; |
|
35 class CStateEngine; |
|
36 class THwEvent; |
|
37 class CStateEngineConfiguration; |
|
38 |
|
39 |
|
40 int Distance(int dx, int dy); |
|
41 |
|
42 inline int Distance(const TPoint& aP1, const TPoint& aP2) |
|
43 { |
|
44 return Distance(aP1.iX - aP2.iX, aP1.iY - aP2.iY); |
|
45 } |
|
46 |
|
47 // CLASS DECLARATION |
|
48 /** |
|
49 * CStateMachine |
|
50 * |
|
51 */ |
|
52 NONSHARABLE_CLASS( CStateMachine ): public CBase, |
|
53 public MTimerInterface, |
|
54 public MAknWsEventObserver, |
|
55 public MStateMachine |
|
56 { |
|
57 public: |
|
58 /** |
|
59 * The MStateMachine interface methods |
|
60 */ |
|
61 virtual TRect getTouchArea(TInt aPointerNumber) ; |
|
62 virtual void setTouchTimeArea(long fingersize_mm) ; |
|
63 virtual void setTouchArea(long fingersize_mm) ; |
|
64 virtual TAreaShape getTouchAreaShape() ; |
|
65 virtual void setTouchAreaShape(const TAreaShape shape) ; |
|
66 virtual unsigned int getTouchTimeout() ; |
|
67 virtual void setTouchTimeout(unsigned int) ; |
|
68 virtual TRect getHoldArea(TInt aPointerNumber) ; |
|
69 virtual void setHoldArea(long fingersize_mm) ; |
|
70 virtual TAreaShape getHoldAreaShape() ; |
|
71 virtual void setHoldAreaShape(const TAreaShape shape) ; |
|
72 virtual unsigned int getHoldTimeout(); |
|
73 virtual void setHoldTimeout(unsigned int a); |
|
74 virtual unsigned int getTouchSuppressTimeout() ; |
|
75 virtual void setTouchSuppressTimeout(unsigned int a) ; |
|
76 virtual unsigned int getMoveSuppressTimeout() ; |
|
77 virtual void setMoveSuppressTimeout(unsigned int a) ; |
|
78 virtual bool addUiEventObserver(MUiEventObserver* observer) ; |
|
79 virtual bool removeUiEventObserver(MUiEventObserver* observer) ; |
|
80 virtual bool wasLastMessageFiltered(TInt aPointerNumber) ; |
|
81 virtual void enableCapacitiveUp(bool enable) ; |
|
82 virtual void enableLogging(bool aEnable) ; |
|
83 virtual void enableYadjustment(bool aEnable) ; |
|
84 virtual int getNumberOfPointers() ; |
|
85 |
|
86 /** |
|
87 * MAknWsEventObserver methods |
|
88 */ |
|
89 virtual void HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination) ; |
|
90 |
|
91 /* other methods */ |
|
92 /** |
|
93 * Pointer event handling in case the messaging should be handled that way, note that the target CCoeControl needs to be givem |
|
94 */ |
|
95 void HandlePointerEventL(const TPointerEvent& aPointerEvent, void* target) ; |
|
96 /** |
|
97 * Simple toggle changes from handling the messages using ...WsEventL or ...PointerEventL |
|
98 */ |
|
99 void EnableWsEventMonitoring(bool aEnable) ; |
|
100 /** |
|
101 * Method to handle the TPointerEvent |
|
102 */ |
|
103 bool HandleStateEvent(const TPointerEvent& aPointerEvent, void* aTarget, const TTime& aTime) ; |
|
104 /*! |
|
105 * Setting the Y adjustment useful in capacitive touch |
|
106 * Note that there are problems with the adjustment if done at this level, |
|
107 * the most proper place would be the window server. |
|
108 */ |
|
109 |
|
110 /** |
|
111 * MTimerInterface methods, these are internal and do not need to be exported |
|
112 */ |
|
113 virtual void startTouchTimer(TInt aDelay, TInt aPointerNumber) ; |
|
114 virtual void cancelTouchTimer(TInt aPointerNumber) ; |
|
115 virtual void startHoldTimer(TInt aDelay, TInt aPointerNumber) ; |
|
116 virtual void cancelHoldTimer(TInt aPointerNumber) ; |
|
117 virtual void startSuppressTimer(TInt aDelay, TInt aPointerNumber) ; |
|
118 virtual void cancelSuppressTimer(TInt aPointerNumber) ; |
|
119 |
|
120 public: |
|
121 ~CStateMachine(); |
|
122 static CStateMachine* NewL(); |
|
123 static CStateMachine* NewLC(); |
|
124 |
|
125 private: |
|
126 CStateMachine(); |
|
127 void ConstructL(); |
|
128 |
|
129 inline static TInt PointerIndex(const TPointerEvent& aPointerEvent); |
|
130 |
|
131 /** |
|
132 * Convert pointer event into our own event format (including timestamp) |
|
133 */ |
|
134 void CreateHwEvent(THwEvent& aEvent, |
|
135 const TPointerEvent& aPointerEvent, |
|
136 void* aTarget, |
|
137 const TTime& aTime) ; |
|
138 |
|
139 void CreateTimerEvent(THwEvent& aEvent, TStateMachineEvent aEventCode) ; |
|
140 |
|
141 /** |
|
142 * the actual state machines implementing the transitions etc. |
|
143 */ |
|
144 CStateEngine* m_impl[KMaxNumberOfPointers] ; |
|
145 /* |
|
146 * The configuration for state machines |
|
147 */ |
|
148 CStateEngineConfiguration* m_config ; |
|
149 /*! |
|
150 * convert window coordinates to screen coordinates. |
|
151 */ |
|
152 TPoint screenCoordinates(const TPoint& aPos, void* aGestureTarget) ; |
|
153 |
|
154 CCoeEnv* m_coeEnv; |
|
155 |
|
156 bool m_WasMessageFiltered ; |
|
157 bool m_wseventmonitoringenabled ; |
|
158 bool m_loggingenabled ; |
|
159 bool m_capacitiveup ; |
|
160 |
|
161 int m_3mminpixels ; |
|
162 bool m_adjustYposition ; |
|
163 // Use same naming scheme with the timers, and variables and methods |
|
164 // using macro expansion tricks (with multitouch support starts to look quite ugly): |
|
165 #define DECLARE_TIMER(x) \ |
|
166 void start##x##Timer(TInt aPointerNumber) ;\ |
|
167 CCallbackTimer* m_##x##Timer[KMaxNumberOfPointers] ;\ |
|
168 void handle##x##Timer(TInt aPointerNumber) ;\ |
|
169 void cancel##x##Timer(TInt aPointerNumber) |
|
170 |
|
171 DECLARE_TIMER(touch) ; |
|
172 DECLARE_TIMER(hold) ; |
|
173 DECLARE_TIMER(suppress) ; |
|
174 |
|
175 }; |
|
176 } // namespace |
|
177 #endif // STATEMACHINE_H |