sl@0: // Copyright (c) 2006-2010 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: // TWsPointer and associated classes definitions sl@0: // sl@0: // sl@0: sl@0: #ifndef __POINTER_H__ sl@0: #define __POINTER_H__ sl@0: sl@0: #include "server.h" sl@0: #include "advancedpointereventhelper.h" sl@0: sl@0: class TWsPointer; sl@0: class CWsPointerTimer : public CTimer sl@0: { sl@0: public: sl@0: class MPointerTimerCallback sl@0: { sl@0: public: sl@0: virtual void RepeatTimerCompleted() =0; sl@0: }; sl@0: sl@0: static CWsPointerTimer* NewL(MPointerTimerCallback& aWsPointer); sl@0: private: sl@0: CWsPointerTimer(MPointerTimerCallback& aPointerTimerCallback); sl@0: void ConstructL(); sl@0: void RunL(); sl@0: private: sl@0: MPointerTimerCallback& iPointerTimerCallback; sl@0: }; sl@0: sl@0: class TWsPointer : public CWsPointerTimer::MPointerTimerCallback sl@0: { sl@0: friend class TWindowServerEvent; sl@0: enum {EPointerUpdateGapInMicroSeconds=50000}; sl@0: enum TPointerState sl@0: { sl@0: EPointerStateOutOfRange=0, sl@0: EPointerStateUp, sl@0: EPointerStateDown sl@0: }; sl@0: public: sl@0: static void InitStaticsL(); sl@0: static void Stop(); sl@0: static void DeleteStatics(); sl@0: static inline TPointerCursorMode PointerCursorMode(); sl@0: static inline void SetPointerCursorMode(TPointerCursorMode aMode); sl@0: static inline TPoint PointerCursorPos(); sl@0: static void SetPointerCursorPos(TPoint aPos); sl@0: static void ReLogPointersCurrentWindows(); sl@0: static void ReLogWindow(const CWsWindow* aWin); sl@0: static void WindowDisconnected(const CWsWindow* deletedWindow); sl@0: static TInt ClaimGrab(const CWsWindow* aWindow,const TWsWinCmdGrabControl& aGrabControl); sl@0: #if defined(__WINS__) sl@0: static TBool PreProcessDriverEvent(TRawEvent &aRawEvent,TBool aFromHardware=EFalse); sl@0: #else sl@0: static TBool PreProcessDriverEvent(TRawEvent &aRawEvent); sl@0: #endif sl@0: static void TranslateCoordsOnRotation(TPoint& aPoint); sl@0: static TBool PreProcessClientEvent(TRawEvent &aRawEvent, TBool aAdvancedPointersEnabled); sl@0: static TBool IsPointerEventType(TRawEvent::TType aType); sl@0: static void ProcessWsEvent(TWsEvent& aEvent,const CWsWindowGroup* aForceInGroup,TBool aNatural); sl@0: static void GetDoubleClickSettings(TTimeIntervalMicroSeconds32 &aTime, TInt &aDistance); sl@0: static void SetDoubleClick(const TTimeIntervalMicroSeconds32 &aTime, TInt aDistance); sl@0: static void UpdatePointerCursor(); sl@0: static TInt RequestPointerRepeatEvent(CWsWindow* aWindow, const TWsWinCmdRequestPointerRepeatEvent& aRequest); sl@0: static TInt CancelPointerRepeatEventRequest(const TWsWinCmdCancelPointerRepeatEventRequest& aCancel); sl@0: void RepeatTimerCompleted(); // from CWsPointerTimer::MPointerTimerCallback sl@0: static TEventQueueWalkRet PointerRepeatPurgeCheck(TWsEvent* aEvent, TUint8 aPointerNumber); sl@0: static inline void UnmatchedEventPurged(TPointerEvent::TType aPointerType, TWsEvent* aEventPurged); sl@0: static void TimerExpired(); sl@0: static inline TBool XyInput(); sl@0: #if defined(__WINS__) sl@0: static void SetXyInputType(TXYInputType aXyInputType); sl@0: #endif sl@0: static void UpdatePrimaryPointer(const TRawEvent& aRawEvent); sl@0: static inline void RollbackPrimaryPointer(); sl@0: static TInt SetCloseProximityThresholds(TInt aEnterCloseProximityThreshold, TInt aExitCloseProximityThreshold); sl@0: static TInt GetEnterCloseProximityThreshold(); sl@0: static TInt GetExitCloseProximityThreshold(); sl@0: static TInt SetHighPressureThresholds(TInt aEnterHighPressureThreshold, TInt aExitHighPressureThreshold); sl@0: static TInt GetEnterHighPressureThreshold(); sl@0: static TInt GetExitHighPressureThreshold(); sl@0: static inline TInt PrimaryPointer(); sl@0: private: sl@0: /** Clears all fields to default values, state goes to EPointerStateOutOfRange */ sl@0: void Clear(); sl@0: void SendEnterExitEvent(TEventCode aType); sl@0: void SetCurrentWindow(const CWsWindow* aWin); sl@0: void ReLogCurrentWindow(); sl@0: void ReLogCurrentWindow(TPoint &aPos, TPoint &aParentPos, const CWsWindowGroup* aForceInGroup); sl@0: void ProcessForegroundCheck(); sl@0: CWsPointerCursor* CalculatePointerCursor(); sl@0: void ProcessEvent(TWsEvent& aEvent,const CWsWindowGroup* aForceInGroup,TBool aNatural); sl@0: void ProcessEvent(TWsEvent& aEvent, TBool aNatural); sl@0: void ProcessPointerEvent(TWsEvent& aEvent); sl@0: void ProcessOutOfRangeEvent(TWsEvent& aEvent,const CWsWindowGroup* aForceInGroup, TBool aNatural); sl@0: void UnmatchedEventPurged(TPointerEvent::TType aPointerType, TUint aHandle); sl@0: TBool CheckMatchingEventPurged(TPointerEvent::TType aType); sl@0: TBool QueuePointerEvent(const CWsWindow* aWindow, TWsEvent &event); sl@0: void ClaimGrab(const CWsWindow* aWindow, TBool aSendUpEvent); sl@0: void PointerCursorUpdateCheck(); sl@0: void NotifyCClick(TAdvancedPointerEvent& aPointerEvent); sl@0: sl@0: static void RestrictPos(TPoint& aPos,TBool aWithinDrawableArea=ETrue); sl@0: void RequestRepeatEvent(CWsWindow* aWindow, const TWsWinCmdRequestPointerRepeatEvent& aRequest); sl@0: void CancelPointerRepeatEventRequest(); sl@0: TBool PointerEventRepeatCheck(const TWsEvent* aEvent, TUint32 aHandle); sl@0: static void UpdatePointerCursorTo(CWsPointerCursor* aNewCursor); sl@0: static inline TBool MovesAvailable(); sl@0: static inline TBool DeltaMouse(); sl@0: static inline CWsWindow*& RepeatWindow(TUint8 aPointerNumber); sl@0: static inline TRect& RepeatRect(TUint8 aPointerNumber); sl@0: static inline CWsPointerTimer*& RepeatTimer(TUint8 aPointerNumber); sl@0: static inline TBool PointerNumberInRange(TUint8 aPointerNumber); sl@0: static void ShiftYCoordinate(TInt& aY); sl@0: private: sl@0: /** Pointer number used to identify this pointer */ sl@0: TUint iNumber; sl@0: sl@0: /** State of the pointer - Up, Down or OutOfRange */ sl@0: TPointerState iState; sl@0: sl@0: /** 2D position of the pointer. Valid if iState != EPointerStateOutOfRange. */ sl@0: TPoint iPos; sl@0: sl@0: /** Combined pressure and proximity values for the pointer */ sl@0: TInt iPressureProximity; sl@0: sl@0: /** Where the pointer is 'Logged' taking into account position, grabbing and capturing */ sl@0: const CWsWindow* iCurrentWindow; sl@0: sl@0: /** Window under pointer */ sl@0: const CWsWindow* iActualWinPointerIsOver; sl@0: sl@0: /** Window that is grabbing this pointer's events (related to Drag events) */ sl@0: const CWsWindow* iGrabWindow; sl@0: sl@0: TUint iLastUnmatchedDown1; sl@0: TUint iLastUnmatchedDown2; sl@0: TUint iLastUnmatchedDown3; sl@0: TUint iLastUnmatchedEnterHighPressure; sl@0: sl@0: /** Window which received last click, for double click detection */ sl@0: const CWsWindow* iPrevClickWindow; sl@0: sl@0: /** Position of last click, for double click detection */ sl@0: TPoint iPrevClickPos; sl@0: sl@0: /** Time of last click, for double click detection */ sl@0: TTime iPrevClickTime; sl@0: sl@0: /** Which button has been clicked last time, for double click detection */ sl@0: TPointerEvent::TType iPrevClickEventType; sl@0: sl@0: /** State upon which firing of EEnterCloseProximity and EExitCloseProximity sl@0: events is based. */ sl@0: TBool iInCloseProximity; sl@0: sl@0: /** State upon which firing of EEnterHighPressure and EExitHighPressure sl@0: events is based. */ sl@0: TBool iInHighPressure; sl@0: sl@0: /** Timer for pointer event repeating */ sl@0: CWsPointerTimer* iRepeatTimer; sl@0: sl@0: CWsWindow* iRepeatWindow; sl@0: sl@0: TRect iRepeatRect; sl@0: sl@0: /** Pointing device's type */ sl@0: static TXYInputType iXyInputType; sl@0: sl@0: /** Maximum number of pointers handled at the same time. Always at least 1. */ sl@0: static TInt iMaxPointers; sl@0: sl@0: /** Main array of TWsPointer objects, can keep up to iMaxPointers objects */ sl@0: static RArray iPointers; sl@0: sl@0: /** Index of Primary Pointer in iPointers array. */ sl@0: static TInt iPrimaryPointer; sl@0: sl@0: /** Previous primary pointer, before last run of UpdatePrimaryPointer(TRawEvent). */ sl@0: static TInt iPreviousPrimaryPointer; sl@0: sl@0: static CWsRootWindow* iRootWindow; sl@0: sl@0: /** Global setting for all pointers */ sl@0: static TTimeIntervalMicroSeconds32 iDoubleClickMaxInterval; sl@0: sl@0: /** Global setting for all pointers */ sl@0: static TInt iDoubleClickMaxDistance; sl@0: sl@0: static CWsPointerCursor* iCursorSprite; sl@0: sl@0: static TPointerCursorMode iPointerCursorMode; sl@0: sl@0: /** If pointer cursor update is required */ sl@0: static TBool iUpdateRequired; sl@0: sl@0: /** Timer for pointer cursor updates */ sl@0: static CPeriodic* iPeriodicTimer; sl@0: sl@0: /** For iPeriodicTimer */ sl@0: static TBool iTimerQueued; sl@0: sl@0: static TBool iIs3DPointer; sl@0: sl@0: /** Threshold upon which firing of EEnterCloseProximity event is based */ sl@0: static TInt iEnterCloseProximityThreshold; sl@0: sl@0: /** Threshold upon which firing of EExitCloseProximity event is based */ sl@0: static TInt iExitCloseProximityThreshold; sl@0: sl@0: /** Threshold upon which firing of EEnterHighPressure event is based */ sl@0: static TInt iEnterHighPressureThreshold; sl@0: sl@0: /** Threshold upon which firing of EExitHighPressure event is based */ sl@0: static TInt iExitHighPressureThreshold; sl@0: sl@0: /** Used to offset the y pointer */ sl@0: static TInt iYOffset; sl@0: sl@0: #if defined(__WINS__) sl@0: /** Tell whether to rotate pointer coords in _WINS_ builds */ sl@0: static TBool iEmulatorRotatePointerCoords; sl@0: #endif sl@0: }; sl@0: sl@0: class CWsPointerBuffer : public CBase sl@0: { sl@0: public: sl@0: ~CWsPointerBuffer(); sl@0: static void ConnectL(CWsClientWindow* aWindow, TInt aMaxPoints, TUint aFlags); sl@0: static void Disconnect(CWsClientWindow* aWindow); sl@0: static void PointerEvent(CWsClientWindow* aWindow,const TPoint &aPoint); sl@0: static void RetrievePointerMoveBuffer(CWsClientWindow* aWindow,TInt aMaxPoints); sl@0: static void DiscardPointerMoveBuffer(CWsClientWindow* aWindow); sl@0: static void DiscardPointerMoveBuffer(TUint aHandle); sl@0: private: sl@0: static void AdjustMaxSizeL(); sl@0: static void Reset(); sl@0: static void SignalBufferReady(); sl@0: private: sl@0: CWsClientWindow* iWindow; sl@0: TInt iMaxPoints; sl@0: TInt iFlags; sl@0: TSglQueLink iQue; sl@0: static TBool iSignalled; sl@0: static CWsPointerBuffer* iCurrentBuffer; sl@0: static CCirBuf* iPointerBuffer; sl@0: static TSglQue iList; sl@0: }; sl@0: sl@0: sl@0: inline void TWsPointer::SetPointerCursorMode(TPointerCursorMode aMode) sl@0: {iPointerCursorMode=aMode;} sl@0: sl@0: inline TPointerCursorMode TWsPointer::PointerCursorMode() sl@0: {return iPointerCursorMode;} sl@0: sl@0: inline TPoint TWsPointer::PointerCursorPos() sl@0: {return iPointers[iPrimaryPointer].iPos;} sl@0: sl@0: inline void TWsPointer::UnmatchedEventPurged(TPointerEvent::TType aPointerType, TWsEvent* aEventPurged) sl@0: {iPointers[TAdvancedPointerEventHelper::PointerNumber(*aEventPurged)].UnmatchedEventPurged(aPointerType, aEventPurged->Handle());} sl@0: sl@0: inline TBool TWsPointer::XyInput() sl@0: {return iXyInputType!=EXYInputNone;} sl@0: sl@0: /* sl@0: EXYInputNone => no pointer, no moves. sl@0: EXYInputPointer && !iIs3DPointer => drags only, no moves (allows mouse to behave like pen for emulator) sl@0: EXYInputPointer && iIs3DPointer => drags and moves sl@0: EXYInputMouse => drags and moves sl@0: EXYInputDeltaMouse => drags and moves sl@0: */ sl@0: inline TBool TWsPointer::MovesAvailable() sl@0: {return (iXyInputType!=EXYInputNone && ((iXyInputType!=EXYInputPointer)||iIs3DPointer));} sl@0: sl@0: inline TBool TWsPointer::DeltaMouse() sl@0: {return (iXyInputType==EXYInputDeltaMouse);} sl@0: sl@0: inline TInt TWsPointer::PrimaryPointer() sl@0: {return iPrimaryPointer;} sl@0: sl@0: /** sl@0: Sets primary pointer to the one which was present before last run of UpdatePrimaryPointer() method. sl@0: */ sl@0: inline void TWsPointer::RollbackPrimaryPointer() sl@0: {iPrimaryPointer = iPreviousPrimaryPointer;} sl@0: sl@0: inline CWsWindow*& TWsPointer::RepeatWindow(TUint8 aPointerNumber) sl@0: {return iPointers[aPointerNumber].iRepeatWindow;} sl@0: sl@0: inline TRect& TWsPointer::RepeatRect(TUint8 aPointerNumber) sl@0: {return iPointers[aPointerNumber].iRepeatRect;} sl@0: sl@0: inline CWsPointerTimer*& TWsPointer::RepeatTimer(TUint8 aPointerNumber) sl@0: {return iPointers[aPointerNumber].iRepeatTimer;} sl@0: sl@0: inline TBool TWsPointer::PointerNumberInRange(TUint8 aPointerNumber) sl@0: {return (aPointerNumber