windowing/windowserver/nga/SERVER/EVENT.H
changeset 0 5d03bc08d59c
child 18 57c618273d5c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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 "EVQUEUE.H"
       
    29 #include <w32adll.h>
       
    30 #include "Graphics/WSGRAPHICDRAWER.H"
       
    31 
       
    32 class CWsClient;
       
    33 class CWsWindowBase;
       
    34 class CWsWindowGroup;
       
    35 class MEventHandler;
       
    36 class CWsHotKey;
       
    37 class CWsCaptureLongKey;
       
    38 class CScreen;
       
    39 class DWsScreenDevice;
       
    40 
       
    41 const TInt KRetryInitialDelay = 100000; //0.01 second
       
    42 
       
    43 struct TEventRequestItem
       
    44 	{
       
    45 	const CWsWindowBase *iWindow;
       
    46 	TInt iParam;
       
    47 	TEventControl iCircumstances;
       
    48 	TSglQueLink iQue;
       
    49 	};
       
    50 
       
    51 class TEventRequestQueue
       
    52 	{
       
    53 public:
       
    54 	TEventRequestQueue();
       
    55 	TEventRequestItem *FindInEventRequestQueueList(const CWsWindowBase &aWindow);
       
    56 	void AddToEventRequestListL(const CWsWindowBase &aWindow, TInt aParam, TEventControl aCircumstances);
       
    57 	void RemoveFromEventRequestListL(const CWsWindowBase &aWindow);
       
    58 	inline TSglQue<TEventRequestItem> &Queue();
       
    59 private:
       
    60 	TSglQue<TEventRequestItem> iQueue;
       
    61 	};
       
    62 
       
    63 class CRawEventReceiver : public CActive
       
    64 	{
       
    65 public:
       
    66 	CRawEventReceiver(TInt aPriority);
       
    67 	~CRawEventReceiver();
       
    68 	void ConstructL();
       
    69 	inline TBool IsReadyToRun() const {return IsActive() && iStatus!=KRequestPending;}
       
    70 protected:
       
    71 	void Request();
       
    72 	void DoCancel();
       
    73 	void RunL();
       
    74 private:
       
    75 	TRawEventBuf iEventBuf;
       
    76 	};
       
    77 
       
    78 class TRepeatKey
       
    79 	{
       
    80 public:
       
    81 	TKeyData iKey;
       
    82 	TInt iScanCode;
       
    83 	};
       
    84 
       
    85 class CKeyboardRepeat : public CTimer
       
    86 	{
       
    87 public:
       
    88 	CKeyboardRepeat();
       
    89 	static void NewL();
       
    90 	static void Destroy();
       
    91 	static void KeyDown();
       
    92 	static void KeyUp(TInt aScanCode);
       
    93 	static TBool StartRepeat(const TKeyData &aKey, TInt aScanCode, CWsWindowGroup *aRepeatFocus, CWsCaptureLongKey* longCapture);
       
    94 	static void CancelRepeat(CWsWindowGroup *aRepeatFocus);
       
    95 	static void CancelRepeat(CWsWindowGroup *aRepeatFocus,TUint aScanCode,TBool aLongCaptureFlag,TUint aModifiers=0);
       
    96 	static void SetRepeatTime(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime);
       
    97 	static void GetRepeatTime(TTimeIntervalMicroSeconds32 &aInitialTime, TTimeIntervalMicroSeconds32 &aTime);
       
    98 	static inline TBool IsAreadyActive();
       
    99 private:
       
   100 	enum TRepeatType
       
   101 		{
       
   102 		ERepeatNone,
       
   103 		ERepeatNormal,
       
   104 		ERepeatLong,
       
   105 		ERepeatLongRepeated,
       
   106 		};
       
   107 private:
       
   108 	static void doCancelRepeat();
       
   109 	void RunL();
       
   110 private:
       
   111 	static CWsWindowGroup *iFocus;
       
   112 	static CKeyboardRepeat *iThis; // Needed as CTimer derived parts can't be static
       
   113 	static TTimeIntervalMicroSeconds32 iInitialTime;
       
   114 	static TTimeIntervalMicroSeconds32 iTime;
       
   115 	static TRepeatKey iCurrentRepeat;
       
   116 	static TRepeatType iRepeating;
       
   117 	static TRepeatKey iAlternateRepeat;
       
   118 	static TBool iAlternateRepeatExists;
       
   119 	static CWsCaptureLongKey* iLongCapture;
       
   120 	static TInt iRepeatRollover;
       
   121 	};
       
   122 
       
   123 struct SNotificationHandler {CAnim* iAnim; TUint32 iNotifications;};
       
   124 struct TDrawerHandler
       
   125 	{
       
   126 	TDrawerHandler(CWsGraphicDrawer *aDrawer, TUint32 aEvents): iDrawer(aDrawer), iEvents(aEvents) {}
       
   127 	CWsGraphicDrawer* iDrawer;
       
   128 	TUint32 iEvents;
       
   129 	};
       
   130 
       
   131 struct TWsEventHandler
       
   132 	{
       
   133 	TWsEventHandler(MWsEventHandler *aHandler, TUint32 aEvents): iHandler(aHandler), iEvents(aEvents) {}
       
   134 	static TBool CompareHandler(const TWsEventHandler& lhs, const TWsEventHandler& rhs) { return lhs.iHandler == rhs.iHandler; }
       
   135 	MWsEventHandler* iHandler;
       
   136 	TUint32 iEvents;
       
   137 	};
       
   138 
       
   139 class CEventQueueRetry : public CActive
       
   140 	{
       
   141 public:
       
   142 	static CEventQueueRetry* NewL();
       
   143 	~CEventQueueRetry();
       
   144 	void Init(CScreen *aOwner);
       
   145 	void Retry(TInt aDelay);
       
   146 	void CancelRetry();
       
   147 private:
       
   148 	CEventQueueRetry();
       
   149 	void ConstructL();
       
   150 	// From CActive:
       
   151 	void RunL();
       
   152 	void DoCancel();
       
   153 	
       
   154 private:
       
   155 	RTimer iTimer;
       
   156 	CScreen *iOwner;
       
   157 	TInt iRetrySpinner;
       
   158 	RPointerArray<CWsClient> iClientArray;
       
   159 	};
       
   160 
       
   161 class TWindowServerEvent
       
   162 	{
       
   163 	#define EDefaultInitialRepeatTime TTimeIntervalMicroSeconds32(300000)
       
   164 	#define EDefaultRepeatTime TTimeIntervalMicroSeconds32(100000)
       
   165 
       
   166 	typedef void (*TSendEventFunc)(TEventRequestItem *aQptr, TInt aParam1, TInt aParam2);
       
   167 public:
       
   168 	enum {ENumHotKeys=21};
       
   169 	enum {EOomEventSecondGap=150};	// Don't resend OOM messages unless at least 150 seconds has passed
       
   170 	enum {ERemovedEventHandlerWhileProcessingRawEvents=0x02};
       
   171 public:
       
   172 	static void InitStaticsL();
       
   173 	static void DeleteStatics();
       
   174 	static CWsHotKey* ClearHotKeysL(TInt aHotKey);
       
   175 	static void ResetDefaultHotKeyL(TInt aHotKey);
       
   176 	static void SetHotKeyL(const TWsClCmdSetHotKey &aHotKey);
       
   177 	static void AddCaptureKeyL(const TCaptureKey &aCaptureKey);
       
   178 	static void SetCaptureKey(TUint32 aHandle, const TCaptureKey &aCaptureKey);
       
   179 	static void CancelCaptureKey(TUint32 aHandle);
       
   180 	static void ClientDestroyed(CWsClient *aClient);
       
   181 	static inline void AddToSwitchOnEventListL(const CWsWindowBase &aWindow, TEventControl aCircumstances);
       
   182 	static inline void RemoveFromSwitchOnEventList(const CWsWindowBase &aWindow);
       
   183 	static inline void AddToErrorMessageListL(const CWsWindowBase &aWindow, TEventControl aCircumstances);
       
   184 	static inline void RemoveFromErrorMessageList(const CWsWindowBase &aWindow);
       
   185 	static inline void AddToModifierChangedEventListL(const CWsWindowBase &aWindow, TInt aModifierMask, TEventControl aCircumstances);
       
   186 	static inline void RemoveFromModifierChangedEventList(const CWsWindowBase &aWindow);
       
   187 	static inline void AddToGroupChangeEventListL(const CWsWindowBase &aWindow);
       
   188 	static inline void RemoveFromGroupChangeEventEventList(const CWsWindowBase &aWindow);
       
   189 	static inline void AddToFocusChangeEventListL(const CWsWindowBase &aWindow);
       
   190 	static inline void RemoveFromFocusChangeEventEventList(const CWsWindowBase &aWindow);
       
   191 	static inline void AddToGroupListChangeEventListL(const CWsWindowBase &aWindow);
       
   192 	static inline void RemoveFromGroupListChangeEventEventList(const CWsWindowBase &aWindow);
       
   193 	static inline void AddToScreenDeviceChangeEventListL(const CWsWindowBase &aWindow);
       
   194 	static inline void RemoveFromScreenDeviceChangeEventList(const CWsWindowBase &aWindow);
       
   195 	static TInt GetModifierState();
       
   196 	static inline TInt GetStoredModifierState();
       
   197 	static void SetModifierState(TEventModifier aModifier,TModifierState aState);
       
   198 	static void ProcessRawEvent(const TRawEvent& aRawEvent);
       
   199 	static void ProcessKeyEvent(const TKeyEvent& aKeyEvent,TInt aRepeats);
       
   200 	static TBool MousePress(const TRawEvent &aRawEvent, const CWsWindowGroup *aGroupWin);
       
   201 	static void SendGroupChangedEvents();
       
   202 	static void SendFocusChangedEvents();
       
   203 	static void SendGroupListChangedEvents();
       
   204 	static void SendVisibilityChangedEvents(CWsWindowBase* aWin, TUint aFlags);
       
   205 	static TBool SendDisplayChangedEvents(CWsClient *aWsClient, TInt aDisplayNumber, TInt aConfigurationChangeId, TInt aResolutionListChangeId);
       
   206 	static void SendScreenDeviceChangedEvents(CScreen* aScreen);
       
   207 	static void SendScreenDeviceChangedEvent(const CWsWindowBase *aWindow);
       
   208 	static TBool ProcessErrorMessages(TWsErrorMessage::TErrorCategory aCategory, TInt aError);
       
   209 	static void NotifyOom();
       
   210 	static void QueueKeyPress(const TKeyData& aKey, TInt aScanCode, CWsWindowGroup* aRepeatFocus, TBool aCheckRepeat,TInt aRepeats);
       
   211 	static void AddEventHandler(MEventHandler *aEventHandler, TBool aAdvancedPointersEnabled);
       
   212 	static void RemoveEventHandler(const MEventHandler *aEventHandler);
       
   213 	static void PotentialEventHandlerL(TInt aNum);
       
   214 	static TInt AddNotificationHandler(CAnim* aAnim, TUint32 aNotifications);
       
   215 	static void RemoveNotificationHandler(CAnim* aAnim);
       
   216 	static void PublishNotification(const TWsEvent& aWsEvent);
       
   217 	static TInt RegisterDrawerHandler(CWsGraphicDrawer* aDrawer, TUint32 aEvents);
       
   218 	static TInt UnregisterDrawerHandler(CWsGraphicDrawer* aDrawer);
       
   219 	static TInt RegisterWsEventHandler(MWsEventHandler * aHandler, TUint32 aEvents);
       
   220 	static TInt UnregisterWsEventHandler(MWsEventHandler * aHandler);
       
   221 	static void NotifyDrawer(const TWservCrEvent& aEvent);
       
   222 	static void NotifyScreenDrawingEvent(const TRegion* aRegion);
       
   223 	static void NotifyScreenDrawingEvent(const TRect& aRect);
       
   224 	static inline const CRawEventReceiver* EventReceiver() {return iEventReceiver;}
       
   225 private:
       
   226 	class TRawEventHandler
       
   227 		{
       
   228 		public:
       
   229 			inline TRawEventHandler(MEventHandler *aEventHandler, TBool aAdvancedPointersEnabled);
       
   230 		public:
       
   231 			MEventHandler *iEventHandler;
       
   232 			TBool iAdvancedPointersEnabled;
       
   233 		};
       
   234 	static void ProcessEventQueue(TEventRequestQueue &aQueue, TSendEventFunc aFunc, TInt aParam1, TInt aParam2);
       
   235 	static void DeleteHotKeys();
       
   236 	static void QueueKeyEvent(CWsWindowGroup *aWin, TWsEvent &aEvent, TWservEventPriorities aPriority);
       
   237 	static void QueueKeyUpDown(const TRawEvent &aRawEvent);
       
   238 	static void ConstructDefaultHotKeyL(TInt aHotKey, const TWsWinCmdCaptureKey &aSystemKey);
       
   239 	static void ProcessModifierChanges();
       
   240 	static void LinkHotKey(CWsHotKey *aWsHotKey);
       
   241 	static TBool DrawerCompareFunc(const TDrawerHandler& lhs, const TDrawerHandler& rhs);
       
   242 private:
       
   243 	static CKeyTranslator *iKeyTranslator;
       
   244 	static TEventRequestQueue iSwitchOnQueue;
       
   245 	static TEventRequestQueue iErrorMessageQueue;
       
   246 	static TEventRequestQueue iModifierChangedQueue;
       
   247 	static TEventRequestQueue iGroupChangedQueue;
       
   248 	static TEventRequestQueue iFocusChangedQueue;
       
   249 	static TEventRequestQueue iGroupListChangedQueue;
       
   250 	static TEventRequestQueue iScreenDeviceChangedQueue;
       
   251 	static TTime iPrevOomMessageTime;
       
   252 	static CCaptureKeys *iCaptureKeys;
       
   253 	static CWsHotKey *iHotKeys;
       
   254 	static TInt iModifierState;
       
   255 	static CRawEventReceiver *iEventReceiver;
       
   256 	static RArray<TRawEventHandler> iEventHandlers;
       
   257 	static CArrayFixFlat<SNotificationHandler> *iNotificationHandlers;
       
   258 	static TInt iPotentialEventHandlers;
       
   259 	static RArray<TDrawerHandler>* iDrawerHandlers;
       
   260 	static RArray<TWsEventHandler> iWsEventHandlers;
       
   261 	static TUint32 iBinaryFlags;
       
   262 	static TInt iEventHandlerCount;
       
   263 	};
       
   264 
       
   265 
       
   266 //
       
   267 // inlines			//
       
   268 //
       
   269 
       
   270 inline TBool CKeyboardRepeat::IsAreadyActive()
       
   271 	{
       
   272 	return iThis->IsActive();
       
   273 	}
       
   274 
       
   275 inline TWindowServerEvent::TRawEventHandler::TRawEventHandler(MEventHandler *aEventHandler, TBool aAdvancedPointersEnabled)
       
   276 : iEventHandler(aEventHandler), iAdvancedPointersEnabled(aAdvancedPointersEnabled)
       
   277 	{ }
       
   278 
       
   279 inline void TWindowServerEvent::AddToSwitchOnEventListL(const CWsWindowBase &aWindow, TEventControl aCircumstances)
       
   280 	{iSwitchOnQueue.AddToEventRequestListL(aWindow, 0, aCircumstances);}
       
   281 inline void TWindowServerEvent::AddToErrorMessageListL(const CWsWindowBase &aWindow, TEventControl aCircumstances)
       
   282 	{iErrorMessageQueue.AddToEventRequestListL(aWindow, 0, aCircumstances);}
       
   283 inline void TWindowServerEvent::AddToModifierChangedEventListL(const CWsWindowBase &aWindow, TInt aModifierMask, TEventControl aCircumstances)
       
   284 	{iModifierChangedQueue.AddToEventRequestListL(aWindow, aModifierMask, aCircumstances);}
       
   285 inline void TWindowServerEvent::AddToGroupChangeEventListL(const CWsWindowBase &aWindow)
       
   286 	{iGroupChangedQueue.AddToEventRequestListL(aWindow, 0, EEventControlAlways);}
       
   287 inline void TWindowServerEvent::AddToFocusChangeEventListL(const CWsWindowBase &aWindow)
       
   288 	{iFocusChangedQueue.AddToEventRequestListL(aWindow, 0, EEventControlAlways);}
       
   289 inline void TWindowServerEvent::AddToGroupListChangeEventListL(const CWsWindowBase &aWindow)
       
   290 	{iGroupListChangedQueue.AddToEventRequestListL(aWindow, 0, EEventControlAlways);}
       
   291 inline void TWindowServerEvent::AddToScreenDeviceChangeEventListL(const CWsWindowBase &aWindow)
       
   292 	{iScreenDeviceChangedQueue.AddToEventRequestListL(aWindow, 0, EEventControlAlways);}
       
   293 
       
   294 inline void TWindowServerEvent::RemoveFromSwitchOnEventList(const CWsWindowBase &aWindow)
       
   295 	{iSwitchOnQueue.RemoveFromEventRequestListL(aWindow);}
       
   296 inline void TWindowServerEvent::RemoveFromErrorMessageList(const CWsWindowBase &aWindow)
       
   297 	{iErrorMessageQueue.RemoveFromEventRequestListL(aWindow);}
       
   298 inline void TWindowServerEvent::RemoveFromModifierChangedEventList(const CWsWindowBase &aWindow)
       
   299 	{iModifierChangedQueue.RemoveFromEventRequestListL(aWindow);}
       
   300 inline void TWindowServerEvent::RemoveFromGroupChangeEventEventList(const CWsWindowBase &aWindow)
       
   301 	{iGroupChangedQueue.RemoveFromEventRequestListL(aWindow);}
       
   302 inline void TWindowServerEvent::RemoveFromFocusChangeEventEventList(const CWsWindowBase &aWindow)
       
   303 	{iFocusChangedQueue.RemoveFromEventRequestListL(aWindow);}
       
   304 inline void TWindowServerEvent::RemoveFromGroupListChangeEventEventList(const CWsWindowBase &aWindow)
       
   305 	{iGroupListChangedQueue.RemoveFromEventRequestListL(aWindow);}
       
   306 inline void TWindowServerEvent::RemoveFromScreenDeviceChangeEventList(const CWsWindowBase &aWindow)
       
   307 	{iScreenDeviceChangedQueue.RemoveFromEventRequestListL(aWindow);}
       
   308 inline TInt TWindowServerEvent::GetStoredModifierState()
       
   309 	{return(iModifierState);}
       
   310 
       
   311 #endif