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