|
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Definition of classes related event handling |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #ifndef __EVENT_H__ |
|
20 #define __EVENT_H__ |
|
21 |
|
22 #include "EVQUEUE.H" |
|
23 #include <e32std.h> |
|
24 #include <e32base.h> |
|
25 #include <e32svr.h> |
|
26 #include <w32std.h> |
|
27 #include "w32cmd.h" |
|
28 #include <w32adll.h> |
|
29 #include <graphics/wsgraphicdrawer.h> |
|
30 |
|
31 class CWsClient; |
|
32 class CWsWindowBase; |
|
33 class CWsWindowGroup; |
|
34 class MEventHandler; |
|
35 class CWsHotKey; |
|
36 class CWsCaptureLongKey; |
|
37 class CScreen; |
|
38 |
|
39 struct TEventRequestItem |
|
40 { |
|
41 const CWsWindowBase *iWindow; |
|
42 TInt iParam; |
|
43 TEventControl iCircumstances; |
|
44 TSglQueLink iQue; |
|
45 }; |
|
46 |
|
47 class TEventRequestQueue |
|
48 { |
|
49 public: |
|
50 TEventRequestQueue(); |
|
51 TEventRequestItem *FindInEventRequestQueueList(const CWsWindowBase &aWindow); |
|
52 void AddToEventRequestListL(const CWsWindowBase &aWindow, TInt aParam, TEventControl aCircumstances); |
|
53 void RemoveFromEventRequestListL(const CWsWindowBase &aWindow); |
|
54 inline TSglQue<TEventRequestItem> &Queue(); |
|
55 private: |
|
56 TSglQue<TEventRequestItem> iQueue; |
|
57 }; |
|
58 |
|
59 class CRawEventReceiver : public CActive |
|
60 { |
|
61 public: |
|
62 CRawEventReceiver(TInt aPriority); |
|
63 ~CRawEventReceiver(); |
|
64 void ConstructL(); |
|
65 protected: |
|
66 void Request(); |
|
67 void DoCancel(); |
|
68 void RunL(); |
|
69 private: |
|
70 TRawEventBuf iEventBuf; |
|
71 }; |
|
72 |
|
73 class TRepeatKey |
|
74 { |
|
75 public: |
|
76 TKeyData iKey; |
|
77 TInt iScanCode; |
|
78 }; |
|
79 |
|
80 class CKeyboardRepeat : public CTimer |
|
81 { |
|
82 public: |
|
83 CKeyboardRepeat(); |
|
84 static void NewL(); |
|
85 static void Destroy(); |
|
86 static void KeyDown(); |
|
87 static void KeyUp(TInt aScanCode); |
|
88 static TBool StartRepeat(const TKeyData &aKey, TInt aScanCode, CWsWindowGroup *aRepeatFocus, CWsCaptureLongKey* longCapture); |
|
89 static void CancelRepeat(CWsWindowGroup *aRepeatFocus); |
|
90 static void CancelRepeat(CWsWindowGroup *aRepeatFocus,TUint aScanCode,TBool aLongCaptureFlag,TUint aModifiers=0); |
|
91 static void SetRepeatTime(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime); |
|
92 static void GetRepeatTime(TTimeIntervalMicroSeconds32 &aInitialTime, TTimeIntervalMicroSeconds32 &aTime); |
|
93 static inline TBool IsAreadyActive(); |
|
94 private: |
|
95 enum TRepeatType |
|
96 { |
|
97 ERepeatNone, |
|
98 ERepeatNormal, |
|
99 ERepeatLong, |
|
100 ERepeatLongRepeated, |
|
101 }; |
|
102 private: |
|
103 static void doCancelRepeat(); |
|
104 void RunL(); |
|
105 private: |
|
106 static CWsWindowGroup *iFocus; |
|
107 static CKeyboardRepeat *iThis; // Needed as CTimer derived parts can't be static |
|
108 static TTimeIntervalMicroSeconds32 iInitialTime; |
|
109 static TTimeIntervalMicroSeconds32 iTime; |
|
110 static TRepeatKey iCurrentRepeat; |
|
111 static TRepeatType iRepeating; |
|
112 static TRepeatKey iAlternateRepeat; |
|
113 static TBool iAlternateRepeatExists; |
|
114 static CWsCaptureLongKey* iLongCapture; |
|
115 static TInt iRepeatRollover; |
|
116 }; |
|
117 |
|
118 struct SNotificationHandler {CAnim* iAnim; TUint32 iNotifications;}; |
|
119 struct TDrawerHandler |
|
120 { |
|
121 TDrawerHandler(CWsGraphicDrawer *aDrawer, TUint32 aEvents): iDrawer(aDrawer), iEvents(aEvents) {} |
|
122 CWsGraphicDrawer* iDrawer; |
|
123 TUint32 iEvents; |
|
124 }; |
|
125 |
|
126 // Andy - can we deprectate TDrawerHandler and just use this? It seems to be more generic and there's no |
|
127 // good reason not to be. |
|
128 struct TWsEventHandler |
|
129 { |
|
130 TWsEventHandler(MWsEventHandler *aHandler, TUint32 aEvents): iHandler(aHandler), iEvents(aEvents) {} |
|
131 static TBool CompareHandler(const TWsEventHandler& lhs, const TWsEventHandler& rhs) { return lhs.iHandler == rhs.iHandler; } |
|
132 MWsEventHandler* iHandler; |
|
133 TUint32 iEvents; |
|
134 }; |
|
135 |
|
136 class TWindowServerEvent |
|
137 { |
|
138 #define EDefaultInitialRepeatTime TTimeIntervalMicroSeconds32(300000) |
|
139 #define EDefaultRepeatTime TTimeIntervalMicroSeconds32(100000) |
|
140 |
|
141 typedef void (*TSendEventFunc)(TEventRequestItem *aQptr, TInt aParam1, TInt aParam2); |
|
142 public: |
|
143 enum {ENumHotKeys=21}; |
|
144 enum {EOomEventSecondGap=150}; // Don't resend OOM messages unless at least 150 seconds has passed |
|
145 enum {ERemovedEventHandlerWhileProcessingRawEvents=0x02}; |
|
146 public: |
|
147 static void InitStaticsL(); |
|
148 static void DeleteStatics(); |
|
149 static CWsHotKey* ClearHotKeysL(TInt aHotKey); |
|
150 static void ResetDefaultHotKeyL(TInt aHotKey); |
|
151 static void SetHotKeyL(const TWsClCmdSetHotKey &aHotKey); |
|
152 static void AddCaptureKeyL(const TCaptureKey &aCaptureKey); |
|
153 static void SetCaptureKey(TUint32 aHandle, const TCaptureKey &aCaptureKey); |
|
154 static void CancelCaptureKey(TUint32 aHandle); |
|
155 static void ClientDestroyed(CWsClient *aClient); |
|
156 static inline void AddToSwitchOnEventListL(const CWsWindowBase &aWindow, TEventControl aCircumstances); |
|
157 static inline void RemoveFromSwitchOnEventList(const CWsWindowBase &aWindow); |
|
158 static inline void AddToErrorMessageListL(const CWsWindowBase &aWindow, TEventControl aCircumstances); |
|
159 static inline void RemoveFromErrorMessageList(const CWsWindowBase &aWindow); |
|
160 static inline void AddToModifierChangedEventListL(const CWsWindowBase &aWindow, TInt aModifierMask, TEventControl aCircumstances); |
|
161 static inline void RemoveFromModifierChangedEventList(const CWsWindowBase &aWindow); |
|
162 static inline void AddToGroupChangeEventListL(const CWsWindowBase &aWindow); |
|
163 static inline void RemoveFromGroupChangeEventEventList(const CWsWindowBase &aWindow); |
|
164 static inline void AddToFocusChangeEventListL(const CWsWindowBase &aWindow); |
|
165 static inline void RemoveFromFocusChangeEventEventList(const CWsWindowBase &aWindow); |
|
166 static inline void AddToGroupListChangeEventListL(const CWsWindowBase &aWindow); |
|
167 static inline void RemoveFromGroupListChangeEventEventList(const CWsWindowBase &aWindow); |
|
168 static inline void AddToScreenDeviceChangeEventListL(const CWsWindowBase &aWindow); |
|
169 static inline void RemoveFromScreenDeviceChangeEventList(const CWsWindowBase &aWindow); |
|
170 static TInt GetModifierState(); |
|
171 static inline TInt GetStoredModifierState(); |
|
172 static void SetModifierState(TEventModifier aModifier,TModifierState aState); |
|
173 static void ProcessRawEvent(const TRawEvent& aRawEvent); |
|
174 static void ProcessKeyEvent(const TKeyEvent& aKeyEvent,TInt aRepeats); |
|
175 static TBool MousePress(const TRawEvent &aRawEvent, const CWsWindowGroup *aGroupWin); |
|
176 static void SendGroupChangedEvents(); |
|
177 static void SendFocusChangedEvents(); |
|
178 static void SendGroupListChangedEvents(); |
|
179 static void SendVisibilityChangedEvents(CWsWindowBase* aWin, TUint aFlags); |
|
180 static void SendScreenDeviceChangedEvents(CScreen* aScreen); |
|
181 static void SendScreenDeviceChangedEvent(const CWsWindowBase *aWindow); |
|
182 static TBool ProcessErrorMessages(TWsErrorMessage::TErrorCategory aCategory, TInt aError); |
|
183 static void NotifyOom(); |
|
184 static void QueueKeyPress(const TKeyData &aKey, TInt aScanCode, CWsWindowGroup *aRepeatFocus, TBool aCheckRepeat,TInt aRepeats); |
|
185 static void AddEventHandler(MEventHandler *aEventHandler); |
|
186 static void RemoveEventHandler(const MEventHandler *aEventHandler); |
|
187 static void PotentialEventHandlerL(TInt aNum); |
|
188 static TInt AddNotificationHandler(CAnim* aAnim, TUint32 aNotifications); |
|
189 static void RemoveNotificationHandler(CAnim* aAnim); |
|
190 static void PublishNotification(const TWsEvent& aWsEvent); |
|
191 static TInt RegisterDrawerHandler(CWsGraphicDrawer* aDrawer, TUint32 aEvents); |
|
192 static TInt UnregisterDrawerHandler(CWsGraphicDrawer* aDrawer); |
|
193 static TInt RegisterWsEventHandler(MWsEventHandler * aHandler, TUint32 aEvents); |
|
194 static TInt UnregisterWsEventHandler(MWsEventHandler * aHandler); |
|
195 static void NotifyDrawer(const TWservCrEvent& aEvent); |
|
196 static void NotifyScreenDrawingEvent(const TRegion* aRegion); |
|
197 static void NotifyScreenDrawingEvent(const TRect& aRect); |
|
198 private: |
|
199 static void ProcessEventQueue(TEventRequestQueue &aQueue, TSendEventFunc aFunc, TInt aParam1, TInt aParam2); |
|
200 static void DeleteHotKeys(); |
|
201 static void QueueKeyEvent(CWsWindowGroup *aWin, TWsEvent &aEvent, TWservEventPriorities aPriority); |
|
202 static void QueueKeyUpDown(const TRawEvent &aRawEvent); |
|
203 static void ConstructDefaultHotKeyL(TInt aHotKey, const TWsWinCmdCaptureKey &aSystemKey); |
|
204 static void ProcessModifierChanges(); |
|
205 static void LinkHotKey(CWsHotKey *aWsHotKey); |
|
206 static TBool DrawerCompareFunc(const TDrawerHandler& lhs, const TDrawerHandler& rhs); |
|
207 private: |
|
208 static CKeyTranslator *iKeyTranslator; |
|
209 static TEventRequestQueue iSwitchOnQueue; |
|
210 static TEventRequestQueue iErrorMessageQueue; |
|
211 static TEventRequestQueue iModifierChangedQueue; |
|
212 static TEventRequestQueue iGroupChangedQueue; |
|
213 static TEventRequestQueue iFocusChangedQueue; |
|
214 static TEventRequestQueue iGroupListChangedQueue; |
|
215 static TEventRequestQueue iScreenDeviceChangedQueue; |
|
216 static TTime iPrevOomMessageTime; |
|
217 static CCaptureKeys *iCaptureKeys; |
|
218 static CWsHotKey *iHotKeys; |
|
219 static TInt iModifierState; |
|
220 static CRawEventReceiver *iEventReceiver; |
|
221 static CArrayPtrFlat<MEventHandler> *iEventHandlers; |
|
222 static CArrayFixFlat<SNotificationHandler> *iNotificationHandlers; |
|
223 static TInt iPotentialEventHandlers; |
|
224 static RArray<TDrawerHandler>* iDrawerHandlers; |
|
225 static RArray<TWsEventHandler> iWsEventHandlers; |
|
226 static TUint32 iBinaryFlags; |
|
227 static TInt iEventHandlerCount; |
|
228 }; |
|
229 |
|
230 |
|
231 // |
|
232 // inlines // |
|
233 // |
|
234 |
|
235 inline TBool CKeyboardRepeat::IsAreadyActive() |
|
236 { |
|
237 return iThis->IsActive(); |
|
238 } |
|
239 |
|
240 // |
|
241 inline void TWindowServerEvent::AddToSwitchOnEventListL(const CWsWindowBase &aWindow, TEventControl aCircumstances) |
|
242 {iSwitchOnQueue.AddToEventRequestListL(aWindow, 0, aCircumstances);} |
|
243 inline void TWindowServerEvent::AddToErrorMessageListL(const CWsWindowBase &aWindow, TEventControl aCircumstances) |
|
244 {iErrorMessageQueue.AddToEventRequestListL(aWindow, 0, aCircumstances);} |
|
245 inline void TWindowServerEvent::AddToModifierChangedEventListL(const CWsWindowBase &aWindow, TInt aModifierMask, TEventControl aCircumstances) |
|
246 {iModifierChangedQueue.AddToEventRequestListL(aWindow, aModifierMask, aCircumstances);} |
|
247 inline void TWindowServerEvent::AddToGroupChangeEventListL(const CWsWindowBase &aWindow) |
|
248 {iGroupChangedQueue.AddToEventRequestListL(aWindow, 0, EEventControlAlways);} |
|
249 inline void TWindowServerEvent::AddToFocusChangeEventListL(const CWsWindowBase &aWindow) |
|
250 {iFocusChangedQueue.AddToEventRequestListL(aWindow, 0, EEventControlAlways);} |
|
251 inline void TWindowServerEvent::AddToGroupListChangeEventListL(const CWsWindowBase &aWindow) |
|
252 {iGroupListChangedQueue.AddToEventRequestListL(aWindow, 0, EEventControlAlways);} |
|
253 inline void TWindowServerEvent::AddToScreenDeviceChangeEventListL(const CWsWindowBase &aWindow) |
|
254 {iScreenDeviceChangedQueue.AddToEventRequestListL(aWindow, 0, EEventControlAlways);} |
|
255 |
|
256 inline void TWindowServerEvent::RemoveFromSwitchOnEventList(const CWsWindowBase &aWindow) |
|
257 {iSwitchOnQueue.RemoveFromEventRequestListL(aWindow);} |
|
258 inline void TWindowServerEvent::RemoveFromErrorMessageList(const CWsWindowBase &aWindow) |
|
259 {iErrorMessageQueue.RemoveFromEventRequestListL(aWindow);} |
|
260 inline void TWindowServerEvent::RemoveFromModifierChangedEventList(const CWsWindowBase &aWindow) |
|
261 {iModifierChangedQueue.RemoveFromEventRequestListL(aWindow);} |
|
262 inline void TWindowServerEvent::RemoveFromGroupChangeEventEventList(const CWsWindowBase &aWindow) |
|
263 {iGroupChangedQueue.RemoveFromEventRequestListL(aWindow);} |
|
264 inline void TWindowServerEvent::RemoveFromFocusChangeEventEventList(const CWsWindowBase &aWindow) |
|
265 {iFocusChangedQueue.RemoveFromEventRequestListL(aWindow);} |
|
266 inline void TWindowServerEvent::RemoveFromGroupListChangeEventEventList(const CWsWindowBase &aWindow) |
|
267 {iGroupListChangedQueue.RemoveFromEventRequestListL(aWindow);} |
|
268 inline void TWindowServerEvent::RemoveFromScreenDeviceChangeEventList(const CWsWindowBase &aWindow) |
|
269 {iScreenDeviceChangedQueue.RemoveFromEventRequestListL(aWindow);} |
|
270 inline TInt TWindowServerEvent::GetStoredModifierState() |
|
271 {return(iModifierState);} |
|
272 |
|
273 #endif |