windowing/windowserver/nga/SERVER/pointer.h
changeset 0 5d03bc08d59c
child 2 5e30ef2e26cb
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2006-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 // TWsPointer and associated classes definitions
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __POINTER_H__
       
    19 #define __POINTER_H__
       
    20 
       
    21 #include "server.h"
       
    22 #include "advancedpointereventhelper.h"
       
    23 
       
    24 class TWsPointer;
       
    25 class CWsPointerTimer : public CTimer
       
    26 	{
       
    27 public:
       
    28 	class MPointerTimerCallback
       
    29 		{
       
    30 	public:
       
    31 		virtual void RepeatTimerCompleted() =0;
       
    32 		};	
       
    33 	
       
    34 	static CWsPointerTimer* NewL(MPointerTimerCallback& aWsPointer);
       
    35 private:
       
    36 	CWsPointerTimer(MPointerTimerCallback& aPointerTimerCallback);
       
    37 	void ConstructL();
       
    38 	void RunL();
       
    39 private:
       
    40 	MPointerTimerCallback& iPointerTimerCallback;
       
    41 	};
       
    42 
       
    43 class TWsPointer : public CWsPointerTimer::MPointerTimerCallback
       
    44 	{
       
    45 	enum {EPointerUpdateGapInMicroSeconds=50000};
       
    46 	enum TPointerState
       
    47 		{
       
    48 		EPointerStateOutOfRange=0,
       
    49 		EPointerStateUp,
       
    50 		EPointerStateDown
       
    51 		};
       
    52 public:
       
    53 	static void InitStaticsL();
       
    54 	static void Stop();
       
    55 	static void DeleteStatics();
       
    56 	static inline TPointerCursorMode PointerCursorMode();
       
    57 	static inline void SetPointerCursorMode(TPointerCursorMode aMode);
       
    58 	static inline TPoint PointerCursorPos();
       
    59 	static void SetPointerCursorPos(TPoint aPos);
       
    60 	static void ReLogPointersCurrentWindows();
       
    61 	static void ReLogWindow(const CWsWindow* aWin);
       
    62 	static void WindowDisconnected(const CWsWindow* deletedWindow);
       
    63 	static TInt ClaimGrab(const CWsWindow* aWindow,const TWsWinCmdGrabControl& aGrabControl);	
       
    64 #if defined(__WINS__)
       
    65 	static TBool PreProcessDriverEvent(TRawEvent &aRawEvent,TBool aFromHardware=EFalse);
       
    66 #else
       
    67 	static TBool PreProcessDriverEvent(TRawEvent &aRawEvent);
       
    68 #endif
       
    69 	static TBool PreProcessClientEvent(TRawEvent &aRawEvent, TBool aAdvancedPointersEnabled);
       
    70 	static TBool IsPointerEventType(TRawEvent::TType aType);
       
    71 	static void ProcessWsEvent(TWsEvent& aEvent,const CWsWindowGroup* aForceInGroup,TBool aNatural);	
       
    72 	static void GetDoubleClickSettings(TTimeIntervalMicroSeconds32 &aTime, TInt &aDistance);
       
    73 	static void SetDoubleClick(const TTimeIntervalMicroSeconds32 &aTime, TInt aDistance);
       
    74 	static void UpdatePointerCursor();
       
    75 	static TInt RequestPointerRepeatEvent(CWsWindow* aWindow, const TWsWinCmdRequestPointerRepeatEvent& aRequest);
       
    76 	static TInt CancelPointerRepeatEventRequest(const TWsWinCmdCancelPointerRepeatEventRequest& aCancel);
       
    77 	void RepeatTimerCompleted(); // from CWsPointerTimer::MPointerTimerCallback	
       
    78 	static TEventQueueWalkRet PointerRepeatPurgeCheck(TWsEvent* aEvent, TUint8 aPointerNumber);
       
    79 	static inline void UnmatchedEventPurged(TPointerEvent::TType aPointerType, TWsEvent* aEventPurged);
       
    80 	static void TimerExpired();
       
    81 	static inline TBool XyInput();
       
    82 #if defined(__WINS__)
       
    83 	static void SetXyInputType(TXYInputType aXyInputType);
       
    84 #endif
       
    85 	static void UpdatePrimaryPointer(const TRawEvent& aRawEvent);
       
    86 	static inline void RollbackPrimaryPointer();
       
    87 	static TInt SetCloseProximityThresholds(TInt aEnterCloseProximityThreshold, TInt aExitCloseProximityThreshold);
       
    88 	static TInt GetEnterCloseProximityThreshold();
       
    89 	static TInt GetExitCloseProximityThreshold();
       
    90 	static TInt SetHighPressureThresholds(TInt aEnterHighPressureThreshold, TInt aExitHighPressureThreshold);
       
    91 	static TInt GetEnterHighPressureThreshold();
       
    92 	static TInt GetExitHighPressureThreshold();
       
    93 	static inline TInt PrimaryPointer();
       
    94 private:
       
    95 	/** Clears all fields to default values, state goes to EPointerStateOutOfRange */
       
    96 	void Clear();
       
    97 	void SendEnterExitEvent(TEventCode aType);
       
    98 	void SetCurrentWindow(const CWsWindow* aWin);
       
    99 	void ReLogCurrentWindow();
       
   100 	void ReLogCurrentWindow(TPoint &aPos, TPoint &aParentPos, const CWsWindowGroup* aForceInGroup);
       
   101 	void ProcessForegroundCheck();
       
   102 	CWsPointerCursor* CalculatePointerCursor();
       
   103 	void ProcessEvent(TWsEvent& aEvent,const CWsWindowGroup* aForceInGroup,TBool aNatural);	
       
   104 	void ProcessEvent(TWsEvent& aEvent, TBool aNatural);
       
   105 	void ProcessPointerEvent(TWsEvent& aEvent);
       
   106 	void ProcessOutOfRangeEvent(TWsEvent& aEvent,const CWsWindowGroup* aForceInGroup, TBool aNatural);
       
   107 	void UnmatchedEventPurged(TPointerEvent::TType aPointerType, TUint aHandle);
       
   108 	TBool CheckMatchingEventPurged(TPointerEvent::TType aType);
       
   109 	TBool QueuePointerEvent(const CWsWindow* aWindow, TWsEvent &event);
       
   110 	void ClaimGrab(const CWsWindow* aWindow, TBool aSendUpEvent);
       
   111 	void PointerCursorUpdateCheck();
       
   112 	void NotifyCClick(TAdvancedPointerEvent& aPointerEvent);
       
   113 	
       
   114 	static void RestrictPos(TPoint& aPos,TBool aWithinDrawableArea=ETrue);
       
   115 	void RequestRepeatEvent(CWsWindow* aWindow, const TWsWinCmdRequestPointerRepeatEvent& aRequest);
       
   116 	void CancelPointerRepeatEventRequest();
       
   117 	TBool PointerEventRepeatCheck(const TWsEvent* aEvent, TUint32 aHandle);
       
   118 	static void UpdatePointerCursorTo(CWsPointerCursor* aNewCursor);
       
   119 	static inline TBool MovesAvailable();
       
   120 	static inline TBool DeltaMouse();
       
   121 	static inline CWsWindow*& RepeatWindow(TUint8 aPointerNumber);
       
   122 	static inline TRect& RepeatRect(TUint8 aPointerNumber);
       
   123 	static inline CWsPointerTimer*& RepeatTimer(TUint8 aPointerNumber);
       
   124 	static inline TBool PointerNumberInRange(TUint8 aPointerNumber);
       
   125 	static void ShiftYCoordinate(TInt& aY);
       
   126 private:
       
   127 	/** Pointer number used to identify this pointer */
       
   128 	TUint iNumber;
       
   129 	
       
   130 	/** State of the pointer - Up, Down or OutOfRange */
       
   131 	TPointerState iState;
       
   132 	
       
   133 	/** 2D position of the pointer. Valid if iState != EPointerStateOutOfRange. */
       
   134 	TPoint iPos;
       
   135 	
       
   136 	/** Combined pressure and proximity values for the pointer */
       
   137 	TInt iPressureProximity;
       
   138 	
       
   139 	/** Where the pointer is 'Logged' taking into account position, grabbing and capturing */
       
   140 	const CWsWindow* iCurrentWindow;
       
   141 	
       
   142 	/** Window under pointer */
       
   143 	const CWsWindow* iActualWinPointerIsOver;
       
   144 	
       
   145 	/** Window that is grabbing this pointer's events (related to Drag events) */
       
   146 	const CWsWindow* iGrabWindow;
       
   147 	
       
   148 	TUint iLastUnmatchedDown1;
       
   149 	TUint iLastUnmatchedDown2;
       
   150 	TUint iLastUnmatchedDown3;
       
   151 	TUint iLastUnmatchedEnterHighPressure;
       
   152 	
       
   153 	/** Window which received last click, for double click detection */
       
   154 	const CWsWindow* iPrevClickWindow;
       
   155 	
       
   156 	/** Position of last click, for double click detection */
       
   157 	TPoint iPrevClickPos;
       
   158 	
       
   159 	/** Time of last click, for double click detection */ 
       
   160 	TTime iPrevClickTime;
       
   161 	
       
   162 	/** Which button has been clicked last time, for double click detection */ 
       
   163 	TPointerEvent::TType iPrevClickEventType;
       
   164 	
       
   165 	/** State upon which firing of EEnterCloseProximity and EExitCloseProximity
       
   166 	events is based. */
       
   167 	TBool iInCloseProximity;
       
   168 	
       
   169 	/** State upon which firing of EEnterHighPressure and EExitHighPressure
       
   170 	events is based. */
       
   171 	TBool iInHighPressure;
       
   172 	
       
   173 	/** Timer for pointer event repeating */
       
   174 	CWsPointerTimer* iRepeatTimer;
       
   175 	
       
   176 	CWsWindow* iRepeatWindow;
       
   177 	
       
   178 	TRect iRepeatRect;
       
   179 	
       
   180 	/** Pointing device's type */
       
   181 	static TXYInputType iXyInputType;
       
   182 
       
   183 	/** Maximum number of pointers handled at the same time. Always at least 1. */ 
       
   184 	static TInt iMaxPointers;
       
   185 	
       
   186 	/** Main array of TWsPointer objects, can keep up to iMaxPointers objects */
       
   187 	static RArray<TWsPointer> iPointers;
       
   188 	
       
   189 	/** Index of Primary Pointer in iPointers array. */
       
   190 	static TInt iPrimaryPointer;
       
   191 	
       
   192 	/** Previous primary pointer, before last run of UpdatePrimaryPointer(TRawEvent). */
       
   193 	static TInt iPreviousPrimaryPointer;
       
   194 	
       
   195 	static CWsRootWindow* iRootWindow;
       
   196 	
       
   197 	/** Global setting for all pointers */
       
   198 	static TTimeIntervalMicroSeconds32 iDoubleClickMaxInterval;
       
   199 
       
   200 	/** Global setting for all pointers */
       
   201 	static TInt iDoubleClickMaxDistance;
       
   202 	
       
   203 	static CWsPointerCursor* iCursorSprite;
       
   204 	
       
   205 	static TPointerCursorMode iPointerCursorMode;
       
   206 	
       
   207 	/** If pointer cursor update is required */
       
   208 	static TBool iUpdateRequired;
       
   209 	
       
   210 	/** Timer for pointer cursor updates */
       
   211 	static CPeriodic* iPeriodicTimer;
       
   212 	
       
   213 	/** For iPeriodicTimer */
       
   214 	static TBool iTimerQueued;
       
   215 	
       
   216 	static TBool iIs3DPointer;
       
   217 	
       
   218 	/** Threshold upon which firing of EEnterCloseProximity event is based */
       
   219 	static TInt iEnterCloseProximityThreshold;
       
   220 	
       
   221 	/** Threshold upon which firing of EExitCloseProximity event is based */
       
   222 	static TInt iExitCloseProximityThreshold;
       
   223 
       
   224 	/** Threshold upon which firing of EEnterHighPressure event is based */
       
   225 	static TInt iEnterHighPressureThreshold;
       
   226 
       
   227 	/** Threshold upon which firing of EExitHighPressure event is based */
       
   228 	static TInt iExitHighPressureThreshold;
       
   229 	
       
   230 	/** Used to offset the y pointer */
       
   231 	static TInt iYOffset;
       
   232 	};
       
   233 
       
   234 class CWsPointerBuffer : public CBase
       
   235 	{
       
   236 public:
       
   237 	~CWsPointerBuffer();
       
   238 	static void ConnectL(CWsClientWindow* aWindow, TInt aMaxPoints, TUint aFlags);
       
   239 	static void Disconnect(CWsClientWindow* aWindow);
       
   240 	static void PointerEvent(CWsClientWindow* aWindow,const TPoint &aPoint);
       
   241 	static void RetrievePointerMoveBuffer(CWsClientWindow* aWindow,TInt aMaxPoints);
       
   242 	static void DiscardPointerMoveBuffer(CWsClientWindow* aWindow);
       
   243 	static void DiscardPointerMoveBuffer(TUint aHandle);
       
   244 private:
       
   245 	static void AdjustMaxSizeL();
       
   246 	static void Reset();
       
   247 	static void SignalBufferReady();
       
   248 private:
       
   249 	CWsClientWindow* iWindow;
       
   250 	TInt iMaxPoints;
       
   251 	TInt iFlags;
       
   252 	TSglQueLink iQue;
       
   253 	static TBool iSignalled;
       
   254 	static CWsPointerBuffer* iCurrentBuffer;
       
   255 	static CCirBuf<TPoint>* iPointerBuffer;
       
   256 	static TSglQue<CWsPointerBuffer> iList;
       
   257 	};
       
   258 
       
   259 
       
   260 inline void TWsPointer::SetPointerCursorMode(TPointerCursorMode aMode)
       
   261 	{iPointerCursorMode=aMode;}
       
   262 	
       
   263 inline TPointerCursorMode TWsPointer::PointerCursorMode()
       
   264 	{return iPointerCursorMode;}
       
   265 	
       
   266 inline TPoint TWsPointer::PointerCursorPos()
       
   267 	{return iPointers[iPrimaryPointer].iPos;}
       
   268 
       
   269 inline void TWsPointer::UnmatchedEventPurged(TPointerEvent::TType aPointerType, TWsEvent* aEventPurged)
       
   270 	{iPointers[TAdvancedPointerEventHelper::PointerNumber(*aEventPurged)].UnmatchedEventPurged(aPointerType, aEventPurged->Handle());}
       
   271 
       
   272 inline TBool TWsPointer::XyInput()
       
   273 	{return iXyInputType!=EXYInputNone;}
       
   274 
       
   275 /*
       
   276 EXYInputNone => no pointer, no moves.
       
   277 EXYInputPointer && !iIs3DPointer => drags only, no moves (allows mouse to behave like pen for emulator)
       
   278 EXYInputPointer && iIs3DPointer => drags and moves
       
   279 EXYInputMouse => drags and moves  
       
   280 EXYInputDeltaMouse => drags and moves
       
   281 */
       
   282 inline TBool TWsPointer::MovesAvailable()
       
   283 	{return (iXyInputType!=EXYInputNone && ((iXyInputType!=EXYInputPointer)||iIs3DPointer));}
       
   284 
       
   285 inline TBool TWsPointer::DeltaMouse()
       
   286 	{return (iXyInputType==EXYInputDeltaMouse);}
       
   287 
       
   288 inline TInt TWsPointer::PrimaryPointer()
       
   289 	{return iPrimaryPointer;}
       
   290 
       
   291 /**
       
   292 Sets primary pointer to the one which was present before last run of UpdatePrimaryPointer() method.
       
   293 */
       
   294 inline void TWsPointer::RollbackPrimaryPointer()
       
   295 	{iPrimaryPointer = iPreviousPrimaryPointer;}
       
   296 
       
   297 inline CWsWindow*& TWsPointer::RepeatWindow(TUint8 aPointerNumber)
       
   298 	{return iPointers[aPointerNumber].iRepeatWindow;}
       
   299 
       
   300 inline TRect& TWsPointer::RepeatRect(TUint8 aPointerNumber)
       
   301 	{return iPointers[aPointerNumber].iRepeatRect;}
       
   302 
       
   303 inline CWsPointerTimer*& TWsPointer::RepeatTimer(TUint8 aPointerNumber)
       
   304 	{return iPointers[aPointerNumber].iRepeatTimer;}
       
   305 
       
   306 inline TBool TWsPointer::PointerNumberInRange(TUint8 aPointerNumber)
       
   307 	{return (aPointerNumber<iMaxPointers);}
       
   308 
       
   309 #endif