os/graphics/windowing/windowserver/test/TClick/CLICK.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2001-2009 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
// Test Key Click Plug-In DLL
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include "W32CLICK.H"
sl@0
    20
#include "CLICK.H"
sl@0
    21
#include <graphics/pointereventdata.h>
sl@0
    22
#if defined(__WINS__)
sl@0
    23
	#include <emulator.h>
sl@0
    24
	#include "LOGWIN.H"
sl@0
    25
#endif
sl@0
    26
sl@0
    27
#define bufSize 64
sl@0
    28
sl@0
    29
GLREF_D struct TSharedMemory GSharedMemory;
sl@0
    30
sl@0
    31
class MClickMaker
sl@0
    32
	{
sl@0
    33
public:
sl@0
    34
	virtual void KeyEvent(TEventCode aType,const TKeyEvent& aEvent)=0;
sl@0
    35
	virtual void PointerEvent(const TPointerEvent& aEvent)=0;
sl@0
    36
	virtual void OtherEvent(TInt aType,TAny* aParam)=0;
sl@0
    37
	};
sl@0
    38
sl@0
    39
struct TGpWinInfo
sl@0
    40
	{
sl@0
    41
	TBool iInUse;
sl@0
    42
	TInt iServerValue;
sl@0
    43
	TInt iNumGroups;
sl@0
    44
	};
sl@0
    45
sl@0
    46
struct TGpWinIdData
sl@0
    47
	{
sl@0
    48
	TInt iId;
sl@0
    49
	TInt iClient;
sl@0
    50
	};
sl@0
    51
sl@0
    52
NONSHARABLE_CLASS(TLogClicks) : public MClickMaker
sl@0
    53
	{
sl@0
    54
public:
sl@0
    55
	void StartLoggingL();
sl@0
    56
	inline TBool IsLogging() {return iLogging;}
sl@0
    57
	//Pure virtual functions from MClickMaker
sl@0
    58
	void KeyEvent(TEventCode aType,const TKeyEvent& aEvent);
sl@0
    59
	void PointerEvent(const TPointerEvent& aEvent);
sl@0
    60
    void OtherEvent(TInt aType,TAny* aParam=NULL);
sl@0
    61
private:
sl@0
    62
	TBool iLogging;
sl@0
    63
	};
sl@0
    64
sl@0
    65
NONSHARABLE_CLASS(CEventClicks) : public CBase, public MClickMaker
sl@0
    66
	{
sl@0
    67
	enum {
sl@0
    68
		EEventBufferSize=32,
sl@0
    69
		EMaxGroupWinClients=6,
sl@0
    70
		EMaxGroupWinIdData=12
sl@0
    71
		};
sl@0
    72
public:
sl@0
    73
	void ConstructL();
sl@0
    74
	TInt Add(TWsEvent* aEvent);
sl@0
    75
	inline TInt Failed() {return iFailed;}
sl@0
    76
	inline TInt Events() {return iEventsTested;}
sl@0
    77
	void Reset();
sl@0
    78
	void ExtendedPointerEvent(const TPointerEventData& aPointerEvent);
sl@0
    79
	void ExpectNewWindowGroup(TInt aClient);
sl@0
    80
	void NewWindowGroup(const TGroupWindowOpenData& aGpWinOpen);
sl@0
    81
	void CheckGpWinId(TInt aId);
sl@0
    82
	void ExpectCloseWindowGroup(TInt aId);
sl@0
    83
	void CloseWindowGroup(TInt aId);
sl@0
    84
	void ExpectCloseWindow(TWindowCloseData& aCloseWin);
sl@0
    85
	void CloseWindow(TWindowCloseData& aCloseWin);
sl@0
    86
	void PointerEventInfo(TPointerEventInfo& aPointerEventInfo);	
sl@0
    87
	//Pure virtual functions from MClickMaker
sl@0
    88
	void KeyEvent(TEventCode aType,const TKeyEvent& aEvent);
sl@0
    89
	void PointerEvent(const TPointerEvent& aEvent);
sl@0
    90
	void OtherEvent(TInt aType,TAny* aParam=NULL);
sl@0
    91
private:
sl@0
    92
	TBool GetEvent(TWsEvent& aEvent);
sl@0
    93
	void Fail();
sl@0
    94
	void AddGroupWindowId(TInt aClient,TInt aGpWinId);
sl@0
    95
	void RemoveGroupWindowId(TInt aGpWinId);
sl@0
    96
private:
sl@0
    97
	CCirBuf<TWsEvent> iEventBuffer;
sl@0
    98
	TInt iFailed;
sl@0
    99
	TInt iEventsTested;
sl@0
   100
	TInt iFailedAt;
sl@0
   101
	TGpWinInfo iGroupWins[EMaxGroupWinClients];
sl@0
   102
	TGpWinIdData iGroupWinIds[EMaxGroupWinIdData];
sl@0
   103
	TInt iExpectedEvent;
sl@0
   104
	TInt iExpectedEventData;
sl@0
   105
	TInt iExpectedHandle;
sl@0
   106
	TPointerEventInfo iExpectedPointerEventInfo;
sl@0
   107
	TInt iLastNewGpWinId;
sl@0
   108
	TAdvancedPointerEvent iLastPointerEvent;
sl@0
   109
	TBool iExpectingExtendedPointer;
sl@0
   110
	};
sl@0
   111
sl@0
   112
NONSHARABLE_CLASS(CMyClickMaker) : public CClickMaker
sl@0
   113
	{
sl@0
   114
public:
sl@0
   115
	~CMyClickMaker();
sl@0
   116
	void ConstructL();
sl@0
   117
	//Virtual function from CClickMaker
sl@0
   118
	void KeyEvent(TEventCode aType,const TKeyEvent& aEvent);
sl@0
   119
	void PointerEvent(const TPointerEvent& aEvent);
sl@0
   120
	void OtherEvent(TInt aType,TAny* aParam);
sl@0
   121
	TInt CommandReplyL(TInt aOpcode, TAny *aArgs);
sl@0
   122
private:
sl@0
   123
	void LogToWindowL();
sl@0
   124
private:
sl@0
   125
	TClickOutputModes iMode;
sl@0
   126
	MClickMaker* iCurrentClick;
sl@0
   127
	TLogClicks iLogClicks;
sl@0
   128
	CEventClicks* iEventClicks;
sl@0
   129
	};
sl@0
   130
sl@0
   131
sl@0
   132
/*TLogClicks*/
sl@0
   133
sl@0
   134
void TLogClicks::StartLoggingL()
sl@0
   135
	{
sl@0
   136
#if defined(__WINS__)
sl@0
   137
	if (!IsLogging())
sl@0
   138
		{
sl@0
   139
		CreateLogWinThreadL();
sl@0
   140
		iLogging=ETrue;
sl@0
   141
		}
sl@0
   142
#else
sl@0
   143
	User::Leave(KErrNotSupported);
sl@0
   144
#endif
sl@0
   145
	}
sl@0
   146
sl@0
   147
void TLogClicks::KeyEvent(TEventCode aType,const TKeyEvent& aEvent)
sl@0
   148
	{
sl@0
   149
	_LIT(KKeyDown,		"KEY DOWN   ");
sl@0
   150
	_LIT(KKeyUp,		"KEY UP     ");
sl@0
   151
	_LIT(KKeyEvent,		"KEY EVENT  ");
sl@0
   152
	_LIT(KKeyRepeat,	"KEY REPEAT ");
sl@0
   153
	_LIT(KKeyUnknown,	"KEY Unknown");
sl@0
   154
	_LIT(KKeyDataFormatChar,"'%c',");
sl@0
   155
	_LIT(KKeyDataFormatCode," Code=%u,");
sl@0
   156
	_LIT(KKeyDataFormatScan," Scan=%d,");
sl@0
   157
	_LIT(KKeyDataFormatModRep," Mod=0x%x, Rep=%d");
sl@0
   158
	TBuf<bufSize> bufPlusZero;
sl@0
   159
	switch (aType)
sl@0
   160
		{
sl@0
   161
	case EEventKey:
sl@0
   162
		bufPlusZero.Copy(KKeyEvent);
sl@0
   163
		break;
sl@0
   164
	case EEventKeyUp:
sl@0
   165
		bufPlusZero.Copy(KKeyUp);
sl@0
   166
		break;
sl@0
   167
	case EEventKeyDown:
sl@0
   168
		bufPlusZero.Copy(KKeyDown);
sl@0
   169
		break;
sl@0
   170
	case EEventKeyRepeat:
sl@0
   171
		bufPlusZero.Copy(KKeyRepeat);
sl@0
   172
		break;
sl@0
   173
	default:
sl@0
   174
		bufPlusZero.Copy(KKeyUnknown);
sl@0
   175
		break;
sl@0
   176
		}
sl@0
   177
	bufPlusZero.AppendFormat(KKeyDataFormatCode,aEvent.iCode);
sl@0
   178
	if (aEvent.iCode!=0)
sl@0
   179
		bufPlusZero.AppendFormat(KKeyDataFormatChar,aEvent.iCode);
sl@0
   180
	bufPlusZero.AppendFormat(KKeyDataFormatScan,aEvent.iScanCode);
sl@0
   181
	if (aEvent.iScanCode!=0)
sl@0
   182
		bufPlusZero.AppendFormat(KKeyDataFormatChar,aEvent.iScanCode);
sl@0
   183
	bufPlusZero.AppendFormat(KKeyDataFormatModRep,aEvent.iModifiers,aEvent.iRepeats);
sl@0
   184
	bufPlusZero.ZeroTerminate();
sl@0
   185
#if defined(__WINS__)
sl@0
   186
	Emulator::Escape();
sl@0
   187
	SendMessage(GSharedMemory.iHwnd, WM_USER+EAppendText, (bufPlusZero.Length()+1)*sizeof(TText), (TInt32)(bufPlusZero.Ptr()));
sl@0
   188
	Emulator::Reenter();
sl@0
   189
#endif
sl@0
   190
	}
sl@0
   191
sl@0
   192
void TLogClicks::PointerEvent(const TPointerEvent& aEvent)
sl@0
   193
	{
sl@0
   194
	_LIT(KButtonDown,	"POINTER DOWN ");
sl@0
   195
	_LIT(KButtonUp,		"POINTER UP   ");
sl@0
   196
	_LIT(KButton2Down,	"BUTTON 2 DOWN");
sl@0
   197
	_LIT(KButton2Up,	"BUTTON 2 UP  ");
sl@0
   198
	_LIT(KButton3Down,	"BUTTON 3 DOWN");
sl@0
   199
	_LIT(KButton3Up,	"BUTTON 3 UP  ");
sl@0
   200
	_LIT(KButtonDrag,	"POINTER DRAG ");
sl@0
   201
	_LIT(KButtonMove,	"POINTER MOVE ");
sl@0
   202
	_LIT(KButtonRepeat,	"BUTTON REPEAT");
sl@0
   203
	_LIT(KSwitchOn,		"POINTER ON   ");
sl@0
   204
	_LIT(KUnknown,		"PTR Unknown  ");
sl@0
   205
	//_LIT(KPtrDataFormat," Pos=(%d,%d), ScrPos=(%d,%d), Modifiers=%x");
sl@0
   206
	_LIT(KPtrDataFormat," Pos=(%d,%d), ScrPos=(%d,%d), Mod=%x");
sl@0
   207
	TBuf<bufSize> bufPlusZero;
sl@0
   208
	switch (aEvent.iType)
sl@0
   209
		{
sl@0
   210
	case TPointerEvent::EButton1Down:
sl@0
   211
		bufPlusZero.Copy(KButtonDown);
sl@0
   212
		break;
sl@0
   213
	case TPointerEvent::EButton1Up:
sl@0
   214
		bufPlusZero.Copy(KButtonUp);
sl@0
   215
		break;
sl@0
   216
	case TPointerEvent::EButton2Down:
sl@0
   217
		bufPlusZero.Copy(KButton2Down);
sl@0
   218
		break;
sl@0
   219
	case TPointerEvent::EButton2Up:
sl@0
   220
		bufPlusZero.Copy(KButton2Up);
sl@0
   221
		break;
sl@0
   222
	case TPointerEvent::EButton3Down:
sl@0
   223
		bufPlusZero.Copy(KButton3Down);
sl@0
   224
		break;
sl@0
   225
	case TPointerEvent::EButton3Up:
sl@0
   226
		bufPlusZero.Copy(KButton3Up);
sl@0
   227
		break;
sl@0
   228
	case TPointerEvent::EDrag:
sl@0
   229
		bufPlusZero.Copy(KButtonDrag);
sl@0
   230
		break;
sl@0
   231
	case TPointerEvent::EMove:
sl@0
   232
		bufPlusZero.Copy(KButtonMove);
sl@0
   233
		break;
sl@0
   234
	case TPointerEvent::EButtonRepeat:
sl@0
   235
		bufPlusZero.Copy(KButtonRepeat);
sl@0
   236
		break;
sl@0
   237
	case TPointerEvent::ESwitchOn:
sl@0
   238
		bufPlusZero.Copy(KSwitchOn);
sl@0
   239
		break;
sl@0
   240
	default:
sl@0
   241
		bufPlusZero.Copy(KUnknown);
sl@0
   242
		break;
sl@0
   243
		}
sl@0
   244
	bufPlusZero.AppendFormat(KPtrDataFormat,aEvent.iPosition.iX,aEvent.iPosition.iY
sl@0
   245
																,aEvent.iParentPosition.iX,aEvent.iParentPosition.iY,aEvent.iModifiers);
sl@0
   246
	bufPlusZero.ZeroTerminate();
sl@0
   247
#if defined(__WINS__)
sl@0
   248
	Emulator::Escape();
sl@0
   249
	SendMessage(GSharedMemory.iHwnd, WM_USER+EAppendText, (bufPlusZero.Length()+1)*sizeof(TText), (TInt32)(bufPlusZero.Ptr()));
sl@0
   250
	Emulator::Reenter();
sl@0
   251
#endif
sl@0
   252
	}
sl@0
   253
sl@0
   254
void TLogClicks::OtherEvent(TInt aType,TAny* aParam)
sl@0
   255
	{
sl@0
   256
	_LIT(KPointer,"POINTER EVENT Ver=%d, ScrPos=(%d,%d), WinClientHandle=0x%x, WinOrigin=%d, WinGpId=%d");
sl@0
   257
	_LIT(KScreenDeviceChanged,"SCREEN DEVICE CHANGED EVENT, Mode=%d");
sl@0
   258
	_LIT(KGroupWindowOpen,"GROUP WINDOW OPEN EVENT WinGpId=%d, Client=%d, NumWinGps=%d");
sl@0
   259
	_LIT(KGroupWindowClose,"GROUP WINDOW CLOSE EVENT WinGpId=%d");
sl@0
   260
	_LIT(KWindowClose,"WINDOW CLOSE EVENT Client=%d, WinGpId=%d");
sl@0
   261
	_LIT(KEventUnknown,	"EVENT Unknown");
sl@0
   262
	TBuf<bufSize> bufPlusZero;
sl@0
   263
	switch (aType)
sl@0
   264
		{
sl@0
   265
	case EEventPointer:
sl@0
   266
		{
sl@0
   267
		TPointerEventData& data=*static_cast<TPointerEventData*>(aParam);
sl@0
   268
		bufPlusZero.Format(KPointer,data.iVersion,data.iCurrentPos.iX,data.iCurrentPos.iY,data.iClientHandle
sl@0
   269
										,data.iWindowOrigin.iX,data.iWindowOrigin.iY,data.iWindowGroupId);
sl@0
   270
		}
sl@0
   271
		break;
sl@0
   272
	case EEventScreenDeviceChanged:
sl@0
   273
		{
sl@0
   274
		TClickMakerData& data=*static_cast<TClickMakerData*>(aParam);
sl@0
   275
		bufPlusZero.Format(KScreenDeviceChanged,data.screenDeviceMode);
sl@0
   276
		}
sl@0
   277
		break;
sl@0
   278
	case EEventGroupWindowOpen:
sl@0
   279
		{
sl@0
   280
		TGroupWindowOpenData& data=*static_cast<TGroupWindowOpenData*>(aParam);
sl@0
   281
		bufPlusZero.Format(KGroupWindowOpen,data.iIdentifier,data.iClient,data.iNumClientWindowGroups);
sl@0
   282
		}
sl@0
   283
		break;
sl@0
   284
	case EEventGroupWindowClose:
sl@0
   285
		bufPlusZero.Format(KGroupWindowClose,reinterpret_cast<TInt&>(aParam));
sl@0
   286
		break;
sl@0
   287
	case EEventWindowClose:
sl@0
   288
		{
sl@0
   289
		TWindowCloseData& data=*static_cast<TWindowCloseData*>(aParam);
sl@0
   290
		bufPlusZero.Format(KWindowClose,data.iClientHandle,data.iWindowGroupId);
sl@0
   291
		}
sl@0
   292
		break;
sl@0
   293
	default:
sl@0
   294
		bufPlusZero.Copy(KEventUnknown);
sl@0
   295
		break;
sl@0
   296
		}
sl@0
   297
	bufPlusZero.ZeroTerminate();
sl@0
   298
#if defined(__WINS__)
sl@0
   299
	Emulator::Escape();
sl@0
   300
	SendMessage(GSharedMemory.iHwnd, WM_USER+EAppendText, (bufPlusZero.Length()+1)*sizeof(TText), (TInt32)(bufPlusZero.Ptr()));
sl@0
   301
	Emulator::Reenter();
sl@0
   302
#endif
sl@0
   303
	}
sl@0
   304
sl@0
   305
/*CEventClicks*/
sl@0
   306
sl@0
   307
void CEventClicks::ConstructL()
sl@0
   308
	{
sl@0
   309
	iEventBuffer.SetLengthL(EEventBufferSize);
sl@0
   310
	}
sl@0
   311
sl@0
   312
TInt CEventClicks::Add(TWsEvent* aEvent)
sl@0
   313
	{
sl@0
   314
	return (iEventBuffer.Add(aEvent) ? KErrNone:KErrOverflow);
sl@0
   315
	}
sl@0
   316
sl@0
   317
void CEventClicks::Reset()
sl@0
   318
	{
sl@0
   319
	iFailed=EFalse;
sl@0
   320
	iEventsTested=0;
sl@0
   321
	iExpectedEvent=0;
sl@0
   322
	iLastNewGpWinId=0;
sl@0
   323
	}
sl@0
   324
sl@0
   325
void CEventClicks::ExtendedPointerEvent(const TPointerEventData& aPointerEvent)
sl@0
   326
	{
sl@0
   327
	if (!iExpectingExtendedPointer)
sl@0
   328
		{
sl@0
   329
		Fail();
sl@0
   330
		return;
sl@0
   331
		}
sl@0
   332
	iExpectingExtendedPointer=EFalse;
sl@0
   333
	TBool match=ETrue;
sl@0
   334
	if (0!=aPointerEvent.iVersion)
sl@0
   335
		match=EFalse;
sl@0
   336
	if (iLastPointerEvent.iType!=aPointerEvent.iPointerEvent.iType)
sl@0
   337
		match=EFalse;
sl@0
   338
	if (iLastPointerEvent.iModifiers!=aPointerEvent.iPointerEvent.iModifiers)
sl@0
   339
		match=EFalse;
sl@0
   340
	if (iLastPointerEvent.iPosition!=aPointerEvent.iPointerEvent.iPosition)
sl@0
   341
		match=EFalse;
sl@0
   342
	if (iLastPointerEvent.iParentPosition!=aPointerEvent.iCurrentPos)
sl@0
   343
		match=EFalse;
sl@0
   344
	if (TPointerEventData::EUnspecified!=aPointerEvent.iSource)
sl@0
   345
		match=EFalse;
sl@0
   346
	if (iExpectedPointerEventInfo.iClientHandle && iExpectedPointerEventInfo.iWinGpId>0)
sl@0
   347
		{
sl@0
   348
		if (iLastPointerEvent.iParentPosition-iExpectedPointerEventInfo.iParentOrigin
sl@0
   349
										!=aPointerEvent.iPointerEvent.iParentPosition)
sl@0
   350
			match=EFalse;
sl@0
   351
		if (iExpectedPointerEventInfo.iParentOrigin+iExpectedPointerEventInfo.iWinOrigin
sl@0
   352
															!=aPointerEvent.iWindowOrigin)
sl@0
   353
			match=EFalse;
sl@0
   354
		if (iExpectedPointerEventInfo.iClientHandle!=aPointerEvent.iClientHandle)
sl@0
   355
			match=EFalse;
sl@0
   356
		if (iExpectedPointerEventInfo.iWinGpId!=aPointerEvent.iWindowGroupId)
sl@0
   357
			match=EFalse;
sl@0
   358
		}
sl@0
   359
	if (!match)
sl@0
   360
		Fail();
sl@0
   361
	}
sl@0
   362
sl@0
   363
void CEventClicks::ExpectNewWindowGroup(TInt aClient)
sl@0
   364
	{
sl@0
   365
	if (iExpectedEvent>0)
sl@0
   366
		Fail();
sl@0
   367
	iExpectedEvent=EEventGroupWindowOpen;
sl@0
   368
	iExpectedEventData=aClient;
sl@0
   369
	}
sl@0
   370
sl@0
   371
void CEventClicks::NewWindowGroup(const TGroupWindowOpenData& aGpWinOpen)
sl@0
   372
	{
sl@0
   373
	iLastNewGpWinId=aGpWinOpen.iIdentifier;
sl@0
   374
	if (iExpectedEvent!=EEventGroupWindowOpen)
sl@0
   375
		{
sl@0
   376
		Fail();
sl@0
   377
		return;
sl@0
   378
		}
sl@0
   379
	iExpectedEvent=0;
sl@0
   380
	if (iExpectedEventData>=EMaxGroupWinClients)
sl@0
   381
		return;
sl@0
   382
	AddGroupWindowId(iExpectedEventData,iLastNewGpWinId);
sl@0
   383
	TGpWinInfo& gpWinInfo=iGroupWins[iExpectedEventData];
sl@0
   384
	if (gpWinInfo.iInUse)
sl@0
   385
		{
sl@0
   386
		if (aGpWinOpen.iClient!=gpWinInfo.iServerValue)
sl@0
   387
			Fail();
sl@0
   388
		else 
sl@0
   389
			{
sl@0
   390
			if (aGpWinOpen.iNumClientWindowGroups!=gpWinInfo.iNumGroups)
sl@0
   391
				Fail();
sl@0
   392
			++gpWinInfo.iNumGroups;
sl@0
   393
			}
sl@0
   394
		}
sl@0
   395
	else
sl@0
   396
		{
sl@0
   397
		gpWinInfo.iInUse=ETrue;
sl@0
   398
		gpWinInfo.iServerValue=aGpWinOpen.iClient;
sl@0
   399
		gpWinInfo.iNumGroups=aGpWinOpen.iNumClientWindowGroups+1;
sl@0
   400
		}
sl@0
   401
	}
sl@0
   402
sl@0
   403
void CEventClicks::CheckGpWinId(TInt aId)
sl@0
   404
	{
sl@0
   405
	if (iLastNewGpWinId!=aId)
sl@0
   406
		Fail();
sl@0
   407
	}
sl@0
   408
sl@0
   409
void CEventClicks::ExpectCloseWindowGroup(TInt aId)
sl@0
   410
	{
sl@0
   411
	if (iExpectedEvent>0)
sl@0
   412
		Fail();
sl@0
   413
	iExpectedEvent=EEventGroupWindowClose;
sl@0
   414
	iExpectedEventData=aId;
sl@0
   415
	}
sl@0
   416
sl@0
   417
void CEventClicks::CloseWindowGroup(TInt aId)
sl@0
   418
	{
sl@0
   419
	if (iExpectedEvent!=EEventGroupWindowClose || iExpectedEventData!=aId)
sl@0
   420
		Fail();
sl@0
   421
	if (iExpectedEvent==EEventGroupWindowClose)
sl@0
   422
		iExpectedEvent=0;
sl@0
   423
	RemoveGroupWindowId(aId);
sl@0
   424
	}
sl@0
   425
sl@0
   426
void CEventClicks::ExpectCloseWindow(TWindowCloseData& aCloseWin)
sl@0
   427
	{
sl@0
   428
	if (iExpectedEvent>0)
sl@0
   429
		Fail();
sl@0
   430
	iExpectedEvent=EEventWindowClose;
sl@0
   431
	iExpectedEventData=aCloseWin.iWindowGroupId;
sl@0
   432
	iExpectedHandle=aCloseWin.iClientHandle;
sl@0
   433
	}
sl@0
   434
sl@0
   435
void CEventClicks::CloseWindow(TWindowCloseData& aCloseWin)
sl@0
   436
	{
sl@0
   437
	if (iExpectedEvent!=EEventWindowClose || iExpectedEventData!=aCloseWin.iWindowGroupId || iExpectedHandle!=aCloseWin.iClientHandle)
sl@0
   438
		Fail();
sl@0
   439
	if (iExpectedEvent==EEventWindowClose)
sl@0
   440
		iExpectedEvent=0;
sl@0
   441
	}
sl@0
   442
sl@0
   443
void CEventClicks::PointerEventInfo(TPointerEventInfo& aPointerEventInfo)
sl@0
   444
	{
sl@0
   445
	iExpectedPointerEventInfo=aPointerEventInfo;
sl@0
   446
	}
sl@0
   447
sl@0
   448
TBool CEventClicks::GetEvent(TWsEvent& aEvent)
sl@0
   449
	{
sl@0
   450
	++iEventsTested;
sl@0
   451
	if (iEventBuffer.Remove(&aEvent)<1)
sl@0
   452
		{
sl@0
   453
		Fail();
sl@0
   454
		return ETrue;
sl@0
   455
		}
sl@0
   456
	return EFalse;
sl@0
   457
	}
sl@0
   458
sl@0
   459
void CEventClicks::Fail()
sl@0
   460
	{
sl@0
   461
	if (!iFailed)
sl@0
   462
		{
sl@0
   463
		iFailed=iEventsTested;
sl@0
   464
		}
sl@0
   465
	}
sl@0
   466
sl@0
   467
void CEventClicks::AddGroupWindowId(TInt aClient,TInt aGpWinId)
sl@0
   468
	{
sl@0
   469
	TInt ii=0;
sl@0
   470
	while (ii<EMaxGroupWinIdData && iGroupWinIds[ii].iId>0)
sl@0
   471
		++ii;
sl@0
   472
	if (ii<EMaxGroupWinIdData)
sl@0
   473
		{
sl@0
   474
		iGroupWinIds[ii].iId=aGpWinId;
sl@0
   475
		iGroupWinIds[ii].iClient=aClient;
sl@0
   476
		}
sl@0
   477
	}
sl@0
   478
sl@0
   479
void CEventClicks::RemoveGroupWindowId(TInt aGpWinId)
sl@0
   480
	{
sl@0
   481
	TInt ii=0;
sl@0
   482
	while (ii<EMaxGroupWinIdData && iGroupWinIds[ii].iId!=aGpWinId)
sl@0
   483
		++ii;
sl@0
   484
	if (ii<EMaxGroupWinIdData)
sl@0
   485
		{
sl@0
   486
		--iGroupWins[iGroupWinIds[ii].iClient].iNumGroups;
sl@0
   487
		iGroupWinIds[ii].iId=0;
sl@0
   488
		}
sl@0
   489
	}
sl@0
   490
sl@0
   491
#define MODIFIER_FLAGS_TO_IGNOR EModifierNumLock
sl@0
   492
#pragma warning(disable : 4245)		//'initializing' : conversion from 'int' to 'unsigned int', signed/unsigned mismatch
sl@0
   493
void CEventClicks::KeyEvent(TEventCode aType,const TKeyEvent& aEvent)
sl@0
   494
	{
sl@0
   495
	TBool pass;
sl@0
   496
	TEventCode eType=aType;
sl@0
   497
	switch (aType)
sl@0
   498
		{
sl@0
   499
	case EEventKey:
sl@0
   500
		pass=(aEvent.iRepeats==0);
sl@0
   501
		break;
sl@0
   502
	case EEventKeyUp:
sl@0
   503
	case EEventKeyDown:
sl@0
   504
		pass=(aEvent.iCode==0) && (aEvent.iRepeats==0);
sl@0
   505
		break;
sl@0
   506
	case EEventKeyRepeat:
sl@0
   507
		pass=(aEvent.iRepeats>0);
sl@0
   508
		eType=EEventKey;
sl@0
   509
		break;
sl@0
   510
	default:
sl@0
   511
		pass=EFalse;
sl@0
   512
		}
sl@0
   513
	if (!pass)
sl@0
   514
		{
sl@0
   515
		Fail();
sl@0
   516
		return;
sl@0
   517
		}
sl@0
   518
	TWsEvent eEvent;
sl@0
   519
	if (GetEvent(eEvent))
sl@0
   520
		return;
sl@0
   521
	if (eEvent.Type()!=eType)
sl@0
   522
		{
sl@0
   523
		Fail();
sl@0
   524
		return;
sl@0
   525
		}
sl@0
   526
	TKeyEvent keyEvent=*eEvent.Key();
sl@0
   527
	TUint mask=~(EModifierAutorepeatable|MODIFIER_FLAGS_TO_IGNOR);
sl@0
   528
	if (keyEvent.iCode!=aEvent.iCode || (keyEvent.iModifiers&mask)!=(aEvent.iModifiers&mask) || keyEvent.iScanCode!=aEvent.iScanCode
sl@0
   529
																						|| (keyEvent.iRepeats==0)!=(aEvent.iRepeats==0))
sl@0
   530
		{
sl@0
   531
		Fail();
sl@0
   532
		return;
sl@0
   533
		}
sl@0
   534
	}
sl@0
   535
sl@0
   536
void CEventClicks::PointerEvent(const TPointerEvent& aEvent)
sl@0
   537
	{
sl@0
   538
	// Click events are now all advanced events so in order to test the modifier bits
sl@0
   539
	// appropriately we need to copy them as TAdvancedPointerEvent not TPointerEvent
sl@0
   540
	if(!aEvent.IsAdvancedPointerEvent())
sl@0
   541
		{
sl@0
   542
		Fail();
sl@0
   543
		return;
sl@0
   544
		}
sl@0
   545
	iLastPointerEvent=*aEvent.AdvancedPointerEvent();
sl@0
   546
		
sl@0
   547
	if (iExpectingExtendedPointer)
sl@0
   548
		Fail();
sl@0
   549
	else
sl@0
   550
		iExpectingExtendedPointer=ETrue;
sl@0
   551
	TWsEvent eEvent;
sl@0
   552
	if (GetEvent(eEvent))
sl@0
   553
		return;
sl@0
   554
	TAdvancedPointerEvent pEvent=*eEvent.Pointer();
sl@0
   555
	TUint mask=~(MODIFIER_FLAGS_TO_IGNOR);
sl@0
   556
	if (pEvent.iType!=aEvent.iType || (pEvent.iModifiers&mask)!=(aEvent.iModifiers&mask)
sl@0
   557
												|| pEvent.iPosition!=aEvent.iPosition || pEvent.iParentPosition!=aEvent.iParentPosition)
sl@0
   558
		{
sl@0
   559
		Fail();
sl@0
   560
		return;
sl@0
   561
		}
sl@0
   562
	}
sl@0
   563
sl@0
   564
void CEventClicks::OtherEvent(TInt aType,TAny* aParam)
sl@0
   565
	{
sl@0
   566
	TBool pass=ETrue;
sl@0
   567
	if (aType!=EEventPointer)
sl@0
   568
		++iEventsTested;
sl@0
   569
	switch (aType)
sl@0
   570
		{
sl@0
   571
	case EEventPointer:
sl@0
   572
		ExtendedPointerEvent(*static_cast<TPointerEventData*>(aParam));
sl@0
   573
		break;
sl@0
   574
	case EEventScreenDeviceChanged:
sl@0
   575
		break;
sl@0
   576
	case EEventGroupWindowOpen:
sl@0
   577
		NewWindowGroup(*static_cast<TGroupWindowOpenData*>(aParam));
sl@0
   578
		break;
sl@0
   579
	case EEventGroupWindowClose:
sl@0
   580
		CloseWindowGroup(reinterpret_cast<TInt>(aParam));
sl@0
   581
		break;
sl@0
   582
	case EEventWindowClose:
sl@0
   583
		CloseWindow(*static_cast<TWindowCloseData*>(aParam));
sl@0
   584
		break;
sl@0
   585
	default:
sl@0
   586
		pass=EFalse;
sl@0
   587
		}
sl@0
   588
	if (!pass)
sl@0
   589
		Fail();
sl@0
   590
	//GetEvent() is not call here because CWsGroupWindow::EnableScreenChangeEvents() could not be 
sl@0
   591
	//been called.This mean that no EEventScreenDeviceChanged will be put in the client queue.
sl@0
   592
	//Instead this event will be always passed to the click plugin if this is present.
sl@0
   593
	}
sl@0
   594
#pragma warning(default : 4245)
sl@0
   595
sl@0
   596
sl@0
   597
/*CMyClickMaker*/
sl@0
   598
sl@0
   599
CMyClickMaker::~CMyClickMaker()
sl@0
   600
	{
sl@0
   601
	delete iEventClicks;
sl@0
   602
	}
sl@0
   603
sl@0
   604
void CMyClickMaker::ConstructL()
sl@0
   605
	{
sl@0
   606
	iMode=EClickNone;
sl@0
   607
	iEventClicks=new(ELeave) CEventClicks();
sl@0
   608
	iEventClicks->ConstructL();
sl@0
   609
	}
sl@0
   610
sl@0
   611
void CMyClickMaker::KeyEvent(TEventCode aType,const TKeyEvent& aEvent)
sl@0
   612
	{
sl@0
   613
	if (iCurrentClick)
sl@0
   614
		iCurrentClick->KeyEvent(aType,aEvent);
sl@0
   615
	}
sl@0
   616
sl@0
   617
void CMyClickMaker::PointerEvent(const TPointerEvent& aEvent)
sl@0
   618
	{
sl@0
   619
	if (iCurrentClick)
sl@0
   620
		iCurrentClick->PointerEvent(aEvent);
sl@0
   621
	}
sl@0
   622
sl@0
   623
void CMyClickMaker::OtherEvent(TInt aType,TAny* aParam)
sl@0
   624
	{
sl@0
   625
	if (iCurrentClick)
sl@0
   626
		iCurrentClick->OtherEvent(aType,aParam);
sl@0
   627
	}
sl@0
   628
sl@0
   629
TInt CMyClickMaker::CommandReplyL(TInt aOpcode,TAny* aArgs)
sl@0
   630
	{
sl@0
   631
	switch (aOpcode)
sl@0
   632
		{
sl@0
   633
	case EClickCommandToggleOutput:
sl@0
   634
		switch (iMode)
sl@0
   635
			{
sl@0
   636
		case EClickNone:
sl@0
   637
			LogToWindowL();
sl@0
   638
			break;
sl@0
   639
		case EClickCheck:
sl@0
   640
		case EClickToWindow:
sl@0
   641
			iMode=EClickNone;
sl@0
   642
			iCurrentClick=NULL;
sl@0
   643
			break;
sl@0
   644
			}
sl@0
   645
		break;
sl@0
   646
	case EClickCommandSetOutput:
sl@0
   647
		iMode=*STATIC_CAST(TClickOutputModes*,aArgs);
sl@0
   648
		switch (iMode)
sl@0
   649
			{
sl@0
   650
		case EClickNone:
sl@0
   651
			iCurrentClick=NULL;
sl@0
   652
			break;
sl@0
   653
		case EClickCheck:
sl@0
   654
			iCurrentClick=iEventClicks;
sl@0
   655
			iEventClicks->Reset();
sl@0
   656
			break;
sl@0
   657
		case EClickToWindow:
sl@0
   658
			LogToWindowL();
sl@0
   659
			break;
sl@0
   660
			}
sl@0
   661
		break;
sl@0
   662
	case EClickEventAdd:
sl@0
   663
		return iEventClicks->Add(STATIC_CAST(TWsEvent*,aArgs));
sl@0
   664
	case EClickFailed:
sl@0
   665
		return iEventClicks->Failed();
sl@0
   666
	case EClickEvents:
sl@0
   667
		return iEventClicks->Events();
sl@0
   668
	case EClickReset:
sl@0
   669
		iEventClicks->Reset();
sl@0
   670
		break;
sl@0
   671
	case EClickCreateGroupWin:
sl@0
   672
		iEventClicks->ExpectNewWindowGroup(*static_cast<TInt*>(aArgs));
sl@0
   673
		break;
sl@0
   674
	case EClickCheckGpWinId:
sl@0
   675
		iEventClicks->CheckGpWinId(*static_cast<TInt*>(aArgs));
sl@0
   676
		break;
sl@0
   677
	case EClickCloseGroupWin:
sl@0
   678
		iEventClicks->ExpectCloseWindowGroup(*static_cast<TInt*>(aArgs));
sl@0
   679
		break;
sl@0
   680
	case EClickCloseWin:
sl@0
   681
		iEventClicks->ExpectCloseWindow(*static_cast<TWindowCloseData*>(aArgs));
sl@0
   682
		break;
sl@0
   683
	case EClickPointerEvent:
sl@0
   684
		iEventClicks->PointerEventInfo(*static_cast<TPointerEventInfo*>(aArgs));
sl@0
   685
		break;
sl@0
   686
	default:;
sl@0
   687
		}
sl@0
   688
	return KErrNone;
sl@0
   689
	}
sl@0
   690
sl@0
   691
void CMyClickMaker::LogToWindowL()
sl@0
   692
	{
sl@0
   693
	iMode=EClickNone;
sl@0
   694
	iCurrentClick=NULL;
sl@0
   695
	iLogClicks.StartLoggingL();
sl@0
   696
	iMode=EClickToWindow;
sl@0
   697
	iCurrentClick=&iLogClicks;
sl@0
   698
	}
sl@0
   699
sl@0
   700
sl@0
   701
EXPORT_C CClickMaker* CreateClickMakerL()
sl@0
   702
	{
sl@0
   703
	CMyClickMaker* plugIn=new(ELeave) CMyClickMaker;
sl@0
   704
	CleanupStack::PushL(plugIn);
sl@0
   705
	plugIn->ConstructL();
sl@0
   706
	CleanupStack::Pop(plugIn);
sl@0
   707
	return plugIn;
sl@0
   708
	}