sl@0: // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: // Definition of classes related event handling
sl@0: // 
sl@0: //
sl@0: 
sl@0: 
sl@0: #ifndef __EVENT_H__
sl@0: #define __EVENT_H__
sl@0: 
sl@0: #include "EVQUEUE.H"
sl@0: #include <e32std.h>
sl@0: #include <e32base.h>
sl@0: #include <e32svr.h>
sl@0: #include <w32std.h>
sl@0: #include "w32cmd.h"
sl@0: #include <w32adll.h>
sl@0: #include <graphics/wsgraphicdrawer.h>
sl@0: 
sl@0: class CWsClient;
sl@0: class CWsWindowBase;
sl@0: class CWsWindowGroup;
sl@0: class MEventHandler;
sl@0: class CWsHotKey;
sl@0: class CWsCaptureLongKey;
sl@0: class CScreen;
sl@0: 
sl@0: struct TEventRequestItem
sl@0: 	{
sl@0: 	const CWsWindowBase *iWindow;
sl@0: 	TInt iParam;
sl@0: 	TEventControl iCircumstances;
sl@0: 	TSglQueLink iQue;
sl@0: 	};
sl@0: 
sl@0: class TEventRequestQueue
sl@0: 	{
sl@0: public:
sl@0: 	TEventRequestQueue();
sl@0: 	TEventRequestItem *FindInEventRequestQueueList(const CWsWindowBase &aWindow);
sl@0: 	void AddToEventRequestListL(const CWsWindowBase &aWindow, TInt aParam, TEventControl aCircumstances);
sl@0: 	void RemoveFromEventRequestListL(const CWsWindowBase &aWindow);
sl@0: 	inline TSglQue<TEventRequestItem> &Queue();
sl@0: private:
sl@0: 	TSglQue<TEventRequestItem> iQueue;
sl@0: 	};
sl@0: 
sl@0: class CRawEventReceiver : public CActive
sl@0: 	{
sl@0: public:
sl@0: 	CRawEventReceiver(TInt aPriority);
sl@0: 	~CRawEventReceiver();
sl@0: 	void ConstructL();
sl@0: protected:
sl@0: 	void Request();
sl@0: 	void DoCancel();
sl@0: 	void RunL();
sl@0: private:
sl@0: 	TRawEventBuf iEventBuf;
sl@0: 	};
sl@0: 
sl@0: class TRepeatKey
sl@0: 	{
sl@0: public:
sl@0: 	TKeyData iKey;
sl@0: 	TInt iScanCode;
sl@0: 	};
sl@0: 
sl@0: class CKeyboardRepeat : public CTimer
sl@0: 	{
sl@0: public:
sl@0: 	CKeyboardRepeat();
sl@0: 	static void NewL();
sl@0: 	static void Destroy();
sl@0: 	static void KeyDown();
sl@0: 	static void KeyUp(TInt aScanCode);
sl@0: 	static TBool StartRepeat(const TKeyData &aKey, TInt aScanCode, CWsWindowGroup *aRepeatFocus, CWsCaptureLongKey* longCapture);
sl@0: 	static void CancelRepeat(CWsWindowGroup *aRepeatFocus);
sl@0: 	static void CancelRepeat(CWsWindowGroup *aRepeatFocus,TUint aScanCode,TBool aLongCaptureFlag,TUint aModifiers=0);
sl@0: 	static void SetRepeatTime(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime);
sl@0: 	static void GetRepeatTime(TTimeIntervalMicroSeconds32 &aInitialTime, TTimeIntervalMicroSeconds32 &aTime);
sl@0: 	static inline TBool IsAreadyActive();
sl@0: private:
sl@0: 	enum TRepeatType
sl@0: 		{
sl@0: 		ERepeatNone,
sl@0: 		ERepeatNormal,
sl@0: 		ERepeatLong,
sl@0: 		ERepeatLongRepeated,
sl@0: 		};
sl@0: private:
sl@0: 	static void doCancelRepeat();
sl@0: 	void RunL();
sl@0: private:
sl@0: 	static CWsWindowGroup *iFocus;
sl@0: 	static CKeyboardRepeat *iThis; // Needed as CTimer derived parts can't be static
sl@0: 	static TTimeIntervalMicroSeconds32 iInitialTime;
sl@0: 	static TTimeIntervalMicroSeconds32 iTime;
sl@0: 	static TRepeatKey iCurrentRepeat;
sl@0: 	static TRepeatType iRepeating;
sl@0: 	static TRepeatKey iAlternateRepeat;
sl@0: 	static TBool iAlternateRepeatExists;
sl@0: 	static CWsCaptureLongKey* iLongCapture;
sl@0: 	static TInt iRepeatRollover;
sl@0: 	};
sl@0: 
sl@0: struct SNotificationHandler {CAnim* iAnim; TUint32 iNotifications;};
sl@0: struct TDrawerHandler
sl@0: 	{
sl@0: 	TDrawerHandler(CWsGraphicDrawer *aDrawer, TUint32 aEvents): iDrawer(aDrawer), iEvents(aEvents) {}
sl@0: 	CWsGraphicDrawer* iDrawer;
sl@0: 	TUint32 iEvents;
sl@0: 	};
sl@0: 
sl@0: // Andy - can we deprectate TDrawerHandler and just use this?  It seems to be more generic and there's no
sl@0: // good reason not to be.
sl@0: struct TWsEventHandler
sl@0: 	{
sl@0: 	TWsEventHandler(MWsEventHandler *aHandler, TUint32 aEvents): iHandler(aHandler), iEvents(aEvents) {}
sl@0: 	static TBool CompareHandler(const TWsEventHandler& lhs, const TWsEventHandler& rhs) { return lhs.iHandler == rhs.iHandler; }
sl@0: 	MWsEventHandler* iHandler;
sl@0: 	TUint32 iEvents;
sl@0: 	};
sl@0: 
sl@0: class TWindowServerEvent
sl@0: 	{
sl@0: 	#define EDefaultInitialRepeatTime TTimeIntervalMicroSeconds32(300000)
sl@0: 	#define EDefaultRepeatTime TTimeIntervalMicroSeconds32(100000)
sl@0: 
sl@0: 	typedef void (*TSendEventFunc)(TEventRequestItem *aQptr, TInt aParam1, TInt aParam2);
sl@0: public:
sl@0: 	enum {ENumHotKeys=21};
sl@0: 	enum {EOomEventSecondGap=150};	// Don't resend OOM messages unless at least 150 seconds has passed
sl@0: 	enum {ERemovedEventHandlerWhileProcessingRawEvents=0x02};
sl@0: public:
sl@0: 	static void InitStaticsL();
sl@0: 	static void DeleteStatics();
sl@0: 	static CWsHotKey* ClearHotKeysL(TInt aHotKey);
sl@0: 	static void ResetDefaultHotKeyL(TInt aHotKey);
sl@0: 	static void SetHotKeyL(const TWsClCmdSetHotKey &aHotKey);
sl@0: 	static void AddCaptureKeyL(const TCaptureKey &aCaptureKey);
sl@0: 	static void SetCaptureKey(TUint32 aHandle, const TCaptureKey &aCaptureKey);
sl@0: 	static void CancelCaptureKey(TUint32 aHandle);
sl@0: 	static void ClientDestroyed(CWsClient *aClient);
sl@0: 	static inline void AddToSwitchOnEventListL(const CWsWindowBase &aWindow, TEventControl aCircumstances);
sl@0: 	static inline void RemoveFromSwitchOnEventList(const CWsWindowBase &aWindow);
sl@0: 	static inline void AddToErrorMessageListL(const CWsWindowBase &aWindow, TEventControl aCircumstances);
sl@0: 	static inline void RemoveFromErrorMessageList(const CWsWindowBase &aWindow);
sl@0: 	static inline void AddToModifierChangedEventListL(const CWsWindowBase &aWindow, TInt aModifierMask, TEventControl aCircumstances);
sl@0: 	static inline void RemoveFromModifierChangedEventList(const CWsWindowBase &aWindow);
sl@0: 	static inline void AddToGroupChangeEventListL(const CWsWindowBase &aWindow);
sl@0: 	static inline void RemoveFromGroupChangeEventEventList(const CWsWindowBase &aWindow);
sl@0: 	static inline void AddToFocusChangeEventListL(const CWsWindowBase &aWindow);
sl@0: 	static inline void RemoveFromFocusChangeEventEventList(const CWsWindowBase &aWindow);
sl@0: 	static inline void AddToGroupListChangeEventListL(const CWsWindowBase &aWindow);
sl@0: 	static inline void RemoveFromGroupListChangeEventEventList(const CWsWindowBase &aWindow);
sl@0: 	static inline void AddToScreenDeviceChangeEventListL(const CWsWindowBase &aWindow);
sl@0: 	static inline void RemoveFromScreenDeviceChangeEventList(const CWsWindowBase &aWindow);
sl@0: 	static TInt GetModifierState();
sl@0: 	static inline TInt GetStoredModifierState();
sl@0: 	static void SetModifierState(TEventModifier aModifier,TModifierState aState);
sl@0: 	static void ProcessRawEvent(const TRawEvent& aRawEvent);
sl@0: 	static void ProcessKeyEvent(const TKeyEvent& aKeyEvent,TInt aRepeats);
sl@0: 	static TBool MousePress(const TRawEvent &aRawEvent, const CWsWindowGroup *aGroupWin);
sl@0: 	static void SendGroupChangedEvents();
sl@0: 	static void SendFocusChangedEvents();
sl@0: 	static void SendGroupListChangedEvents();
sl@0: 	static void SendVisibilityChangedEvents(CWsWindowBase* aWin, TUint aFlags);
sl@0: 	static void SendScreenDeviceChangedEvents(CScreen* aScreen);
sl@0: 	static void SendScreenDeviceChangedEvent(const CWsWindowBase *aWindow);
sl@0: 	static TBool ProcessErrorMessages(TWsErrorMessage::TErrorCategory aCategory, TInt aError);
sl@0: 	static void NotifyOom();
sl@0: 	static void QueueKeyPress(const TKeyData &aKey, TInt aScanCode, CWsWindowGroup *aRepeatFocus, TBool aCheckRepeat,TInt aRepeats);
sl@0: 	static void AddEventHandler(MEventHandler *aEventHandler);
sl@0: 	static void RemoveEventHandler(const MEventHandler *aEventHandler);
sl@0: 	static void PotentialEventHandlerL(TInt aNum);
sl@0: 	static TInt AddNotificationHandler(CAnim* aAnim, TUint32 aNotifications);
sl@0: 	static void RemoveNotificationHandler(CAnim* aAnim);
sl@0: 	static void PublishNotification(const TWsEvent& aWsEvent);
sl@0: 	static TInt RegisterDrawerHandler(CWsGraphicDrawer* aDrawer, TUint32 aEvents);
sl@0: 	static TInt UnregisterDrawerHandler(CWsGraphicDrawer* aDrawer);
sl@0: 	static TInt RegisterWsEventHandler(MWsEventHandler * aHandler, TUint32 aEvents);
sl@0: 	static TInt UnregisterWsEventHandler(MWsEventHandler * aHandler);
sl@0: 	static void NotifyDrawer(const TWservCrEvent& aEvent);
sl@0: 	static void NotifyScreenDrawingEvent(const TRegion* aRegion);
sl@0: 	static void NotifyScreenDrawingEvent(const TRect& aRect);
sl@0: private:
sl@0: 	static void ProcessEventQueue(TEventRequestQueue &aQueue, TSendEventFunc aFunc, TInt aParam1, TInt aParam2);
sl@0: 	static void DeleteHotKeys();
sl@0: 	static void QueueKeyEvent(CWsWindowGroup *aWin, TWsEvent &aEvent, TWservEventPriorities aPriority);
sl@0: 	static void QueueKeyUpDown(const TRawEvent &aRawEvent);
sl@0: 	static void ConstructDefaultHotKeyL(TInt aHotKey, const TWsWinCmdCaptureKey &aSystemKey);
sl@0: 	static void ProcessModifierChanges();
sl@0: 	static void LinkHotKey(CWsHotKey *aWsHotKey);
sl@0: 	static TBool DrawerCompareFunc(const TDrawerHandler& lhs, const TDrawerHandler& rhs);
sl@0: private:
sl@0: 	static CKeyTranslator *iKeyTranslator;
sl@0: 	static TEventRequestQueue iSwitchOnQueue;
sl@0: 	static TEventRequestQueue iErrorMessageQueue;
sl@0: 	static TEventRequestQueue iModifierChangedQueue;
sl@0: 	static TEventRequestQueue iGroupChangedQueue;
sl@0: 	static TEventRequestQueue iFocusChangedQueue;
sl@0: 	static TEventRequestQueue iGroupListChangedQueue;
sl@0: 	static TEventRequestQueue iScreenDeviceChangedQueue;
sl@0: 	static TTime iPrevOomMessageTime;
sl@0: 	static CCaptureKeys *iCaptureKeys;
sl@0: 	static CWsHotKey *iHotKeys;
sl@0: 	static TInt iModifierState;
sl@0: 	static CRawEventReceiver *iEventReceiver;
sl@0: 	static CArrayPtrFlat<MEventHandler> *iEventHandlers;
sl@0: 	static CArrayFixFlat<SNotificationHandler> *iNotificationHandlers;
sl@0: 	static TInt iPotentialEventHandlers;
sl@0: 	static RArray<TDrawerHandler>* iDrawerHandlers;
sl@0: 	static RArray<TWsEventHandler> iWsEventHandlers;
sl@0: 	static TUint32 iBinaryFlags;
sl@0: 	static TInt iEventHandlerCount;
sl@0: 	};
sl@0: 
sl@0: 
sl@0: //
sl@0: // inlines			//
sl@0: //
sl@0: 
sl@0: inline TBool CKeyboardRepeat::IsAreadyActive()
sl@0: 	{
sl@0: 	return iThis->IsActive();
sl@0: 	}
sl@0: 
sl@0: //
sl@0: inline void TWindowServerEvent::AddToSwitchOnEventListL(const CWsWindowBase &aWindow, TEventControl aCircumstances)
sl@0: 	{iSwitchOnQueue.AddToEventRequestListL(aWindow, 0, aCircumstances);}
sl@0: inline void TWindowServerEvent::AddToErrorMessageListL(const CWsWindowBase &aWindow, TEventControl aCircumstances)
sl@0: 	{iErrorMessageQueue.AddToEventRequestListL(aWindow, 0, aCircumstances);}
sl@0: inline void TWindowServerEvent::AddToModifierChangedEventListL(const CWsWindowBase &aWindow, TInt aModifierMask, TEventControl aCircumstances)
sl@0: 	{iModifierChangedQueue.AddToEventRequestListL(aWindow, aModifierMask, aCircumstances);}
sl@0: inline void TWindowServerEvent::AddToGroupChangeEventListL(const CWsWindowBase &aWindow)
sl@0: 	{iGroupChangedQueue.AddToEventRequestListL(aWindow, 0, EEventControlAlways);}
sl@0: inline void TWindowServerEvent::AddToFocusChangeEventListL(const CWsWindowBase &aWindow)
sl@0: 	{iFocusChangedQueue.AddToEventRequestListL(aWindow, 0, EEventControlAlways);}
sl@0: inline void TWindowServerEvent::AddToGroupListChangeEventListL(const CWsWindowBase &aWindow)
sl@0: 	{iGroupListChangedQueue.AddToEventRequestListL(aWindow, 0, EEventControlAlways);}
sl@0: inline void TWindowServerEvent::AddToScreenDeviceChangeEventListL(const CWsWindowBase &aWindow)
sl@0: 	{iScreenDeviceChangedQueue.AddToEventRequestListL(aWindow, 0, EEventControlAlways);}
sl@0: 
sl@0: inline void TWindowServerEvent::RemoveFromSwitchOnEventList(const CWsWindowBase &aWindow)
sl@0: 	{iSwitchOnQueue.RemoveFromEventRequestListL(aWindow);}
sl@0: inline void TWindowServerEvent::RemoveFromErrorMessageList(const CWsWindowBase &aWindow)
sl@0: 	{iErrorMessageQueue.RemoveFromEventRequestListL(aWindow);}
sl@0: inline void TWindowServerEvent::RemoveFromModifierChangedEventList(const CWsWindowBase &aWindow)
sl@0: 	{iModifierChangedQueue.RemoveFromEventRequestListL(aWindow);}
sl@0: inline void TWindowServerEvent::RemoveFromGroupChangeEventEventList(const CWsWindowBase &aWindow)
sl@0: 	{iGroupChangedQueue.RemoveFromEventRequestListL(aWindow);}
sl@0: inline void TWindowServerEvent::RemoveFromFocusChangeEventEventList(const CWsWindowBase &aWindow)
sl@0: 	{iFocusChangedQueue.RemoveFromEventRequestListL(aWindow);}
sl@0: inline void TWindowServerEvent::RemoveFromGroupListChangeEventEventList(const CWsWindowBase &aWindow)
sl@0: 	{iGroupListChangedQueue.RemoveFromEventRequestListL(aWindow);}
sl@0: inline void TWindowServerEvent::RemoveFromScreenDeviceChangeEventList(const CWsWindowBase &aWindow)
sl@0: 	{iScreenDeviceChangedQueue.RemoveFromEventRequestListL(aWindow);}
sl@0: inline TInt TWindowServerEvent::GetStoredModifierState()
sl@0: 	{return(iModifierState);}
sl@0: 
sl@0: #endif