os/graphics/windowing/windowserver/test/tman/TMPNTCUR.CPP
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) 1999-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
// Tests for various pointer cursors on different windows
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <hal.h>
sl@0
    20
#include "W32STD.H"
sl@0
    21
#include "../tlib/testbase.h"
sl@0
    22
#include "TMAN.H"
sl@0
    23
sl@0
    24
class CPointerCursorWindow : public CTWin
sl@0
    25
	{
sl@0
    26
public:
sl@0
    27
	~CPointerCursorWindow();
sl@0
    28
	void SetChild(CPointerCursorWindow* aChild);
sl@0
    29
	inline CPointerCursorWindow* Child() {return iChild;}
sl@0
    30
	inline void SetBitmap(CFbsBitmap* aBitmap,TBool aTop=ETrue) {iBitmap=aBitmap;iTop=aTop;}
sl@0
    31
	void SetPointerCursor(CTPointerCursor* aCursor);
sl@0
    32
	//Virtual function from CTBaseWin
sl@0
    33
	void SetUpL(TPoint aPos,TSize aSize,CTWinBase *aParent,CWindowGc &aGc);
sl@0
    34
	void Draw();
sl@0
    35
	void PointerL(const TPointerEvent &aPointer,const TTime &aTime);
sl@0
    36
private:
sl@0
    37
	CPointerCursorWindow* iChild;
sl@0
    38
	CFbsBitmap* iBitmap;
sl@0
    39
	TBool iTop;
sl@0
    40
	};
sl@0
    41
sl@0
    42
class CPointerCursorWindowGroup : public CTWindowGroup
sl@0
    43
	{
sl@0
    44
public:
sl@0
    45
	CPointerCursorWindowGroup(CTClient *aClient);
sl@0
    46
	void SetPointerCursor(CTPointerCursor* aCursor);
sl@0
    47
	void ConstructL();
sl@0
    48
	};
sl@0
    49
sl@0
    50
class CStatusWindow : public CTTitledWindow
sl@0
    51
	{
sl@0
    52
public:
sl@0
    53
	~CStatusWindow();
sl@0
    54
	void Construct(CTestBase* aTest);
sl@0
    55
	void DoDraw();
sl@0
    56
	//virtual functions from CTWinBase overridden by CTBaseWin
sl@0
    57
	void WinKeyL(const TKeyEvent &aKey,const TTime &aTime);
sl@0
    58
	//virtual functions from CTBaseWin
sl@0
    59
	void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
sl@0
    60
	void PointerL(const TPointerEvent &aPointer,const TTime &aTime);
sl@0
    61
	//virtual function from CTBaseWin overridden by CTTitledWindow
sl@0
    62
	void Draw();
sl@0
    63
private:
sl@0
    64
	void UpdateString1();
sl@0
    65
	void UpdateString2();
sl@0
    66
	void UpdateString3();
sl@0
    67
	void ChangeXyInputType();
sl@0
    68
	void ChangePointerCursorMode();
sl@0
    69
private:
sl@0
    70
	CTestBase* iTest;
sl@0
    71
	TBuf<16> iString1;
sl@0
    72
	TBuf<16> iString2;
sl@0
    73
	TBuf<16> iString3;
sl@0
    74
	TBuf<32> iString4;
sl@0
    75
	TRect iRect1;
sl@0
    76
	TRect iRect2;
sl@0
    77
	TRect iRect3;
sl@0
    78
	TRect iRect4;
sl@0
    79
	TXYInputType iXyInputType;
sl@0
    80
	TXYInputType iOriginalXyInputType;
sl@0
    81
	TPointerCursorMode iMode;
sl@0
    82
	TPointerCursorMode iOriginalMode;
sl@0
    83
	TBool iSimulatedPenDown;
sl@0
    84
	TBool iUpdateNeeded;
sl@0
    85
	TBool iExit;
sl@0
    86
	};
sl@0
    87
sl@0
    88
class CPointerCursorTest : public CTestBase
sl@0
    89
	{
sl@0
    90
	enum {eWindowGap=3,eChildWindowGap=2};
sl@0
    91
	enum {eNumPointerCursors=7};
sl@0
    92
public:
sl@0
    93
	CPointerCursorTest();
sl@0
    94
	~CPointerCursorTest();
sl@0
    95
	TestState DoTestL();
sl@0
    96
	void ConstructL();
sl@0
    97
private:
sl@0
    98
	CPointerCursorWindow *CreateWindowL(TInt aNum,TRect aLocation,CTWinBase *aGroup);
sl@0
    99
	void CreatePointerCursorsL();
sl@0
   100
	void CreateWindowsL(TSize aArea);
sl@0
   101
private:
sl@0
   102
	TSize iWinSize;
sl@0
   103
	TInt iState;
sl@0
   104
	CStatusWindow *iInfoWindow;
sl@0
   105
	CPointerCursorWindowGroup *iGroup1;
sl@0
   106
	CPointerCursorWindowGroup *iGroup2;
sl@0
   107
	CPointerCursorWindow *iWindows[6];
sl@0
   108
	CTPointerCursor *iCursors[eNumPointerCursors];
sl@0
   109
	CFbsBitmap *iBitmaps[eNumPointerCursors];
sl@0
   110
	};
sl@0
   111
sl@0
   112
sl@0
   113
/*CPointerCursorWindow*/
sl@0
   114
sl@0
   115
CPointerCursorWindow::~CPointerCursorWindow()
sl@0
   116
	{
sl@0
   117
	delete iChild;
sl@0
   118
	}
sl@0
   119
sl@0
   120
void CPointerCursorWindow::SetChild(CPointerCursorWindow* aChild)
sl@0
   121
	{
sl@0
   122
	iChild=aChild;
sl@0
   123
	iWin.SetShadowDisabled(ETrue);
sl@0
   124
	}
sl@0
   125
sl@0
   126
void CPointerCursorWindow::SetPointerCursor(CTPointerCursor* aCursor)
sl@0
   127
	{
sl@0
   128
	iWin.SetCustomPointerCursor(aCursor->PointerCursor());
sl@0
   129
	}
sl@0
   130
sl@0
   131
void CPointerCursorWindow::SetUpL(TPoint aPos,TSize aSize,CTWinBase *aParent,CWindowGc &aGc)
sl@0
   132
	{
sl@0
   133
	CTWin::SetUpL(aPos,aSize,aParent,aGc);
sl@0
   134
	iWin.SetShadowDisabled(ETrue);
sl@0
   135
	iWin.SetPointerGrab(EFalse);
sl@0
   136
	}
sl@0
   137
sl@0
   138
void CPointerCursorWindow::Draw()
sl@0
   139
	{
sl@0
   140
	iGc->Reset();
sl@0
   141
	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   142
	iGc->DrawRect(Size());
sl@0
   143
	if (iBitmap)
sl@0
   144
		{
sl@0
   145
		TPoint point(3,3);
sl@0
   146
		if (!iTop)
sl@0
   147
			point.iY=Size().iHeight-iBitmap->SizeInPixels().iHeight-3;
sl@0
   148
		iGc->BitBlt(point,iBitmap);
sl@0
   149
		}
sl@0
   150
	}
sl@0
   151
sl@0
   152
void CPointerCursorWindow::PointerL(const TPointerEvent&,const TTime&)
sl@0
   153
	{
sl@0
   154
	}
sl@0
   155
sl@0
   156
sl@0
   157
/*CPointerCursorWindowGroup*/
sl@0
   158
sl@0
   159
CPointerCursorWindowGroup::CPointerCursorWindowGroup(CTClient *aClient)
sl@0
   160
	:CTWindowGroup(aClient)
sl@0
   161
	{}
sl@0
   162
sl@0
   163
void CPointerCursorWindowGroup::ConstructL()
sl@0
   164
	{
sl@0
   165
	CTWindowGroup::ConstructL();
sl@0
   166
	iGroupWin.EnableReceiptOfFocus(EFalse);
sl@0
   167
	}
sl@0
   168
sl@0
   169
void CPointerCursorWindowGroup::SetPointerCursor(CTPointerCursor* aCursor)
sl@0
   170
	{
sl@0
   171
	iGroupWin.SetCustomPointerCursor(aCursor->PointerCursor());
sl@0
   172
	}
sl@0
   173
sl@0
   174
sl@0
   175
/*CStatusWindow*/
sl@0
   176
sl@0
   177
CStatusWindow::~CStatusWindow()
sl@0
   178
	{
sl@0
   179
	Client()->iWs.SetPointerCursorMode(iOriginalMode);
sl@0
   180
#if defined(__WINS__)
sl@0
   181
	Client()->iWs.SimulateXyInputType(iOriginalXyInputType);
sl@0
   182
#endif
sl@0
   183
	}
sl@0
   184
sl@0
   185
void CStatusWindow::Construct(CTestBase* aTest)
sl@0
   186
	{
sl@0
   187
	_LIT(Title,"StatusWindow");
sl@0
   188
	_LIT(String4,"Click here to finish");
sl@0
   189
	iTest=aTest;
sl@0
   190
	TWindowTitle title(Title);
sl@0
   191
	SetTitle(title);
sl@0
   192
	TInt yy=iTitleHeight+iFont->HeightInPixels()+7;
sl@0
   193
	iRect1.SetRect(3,iTitleHeight+5,iSize.iWidth-1,yy);
sl@0
   194
	TInt yy1=yy+iFont->HeightInPixels()+2;
sl@0
   195
	iRect2.SetRect(3,yy+3,iSize.iWidth-1,yy1);
sl@0
   196
	TInt yy2=yy1+iFont->HeightInPixels()+2;
sl@0
   197
	iRect3.SetRect(3,yy1+3,iSize.iWidth-1,yy2);
sl@0
   198
	iRect4.SetRect(3,yy2+3,iSize.iWidth-1,yy2+iFont->HeightInPixels()+2);
sl@0
   199
	TMachineInfoV1Buf machineInfo;
sl@0
   200
	UserHal::MachineInfo(machineInfo);
sl@0
   201
	iXyInputType=machineInfo().iXYInputType;
sl@0
   202
	iOriginalXyInputType=iXyInputType;
sl@0
   203
	iSimulatedPenDown=EFalse;
sl@0
   204
	//
sl@0
   205
	iString3.Copy(KNullDesC);
sl@0
   206
	if (iXyInputType==EXYInputDeltaMouse)
sl@0
   207
		{
sl@0
   208
		if (HAL::Get(HALData::EMouseState,iSimulatedPenDown)==KErrNone)
sl@0
   209
			UpdateString3();
sl@0
   210
		}
sl@0
   211
	UpdateString1();
sl@0
   212
	iMode=Client()->iWs.PointerCursorMode();
sl@0
   213
	iOriginalMode=iMode;
sl@0
   214
	UpdateString2();
sl@0
   215
	iUpdateNeeded=EFalse;
sl@0
   216
	iString4.Copy(String4);
sl@0
   217
	iExit=EFalse;
sl@0
   218
	}
sl@0
   219
sl@0
   220
void CStatusWindow::SetUpL(TPoint aPos,TSize aSize,CTWinBase *aParent,CWindowGc &aGc)
sl@0
   221
	{
sl@0
   222
	CTTitledWindow::SetUpL(aPos,aSize,aParent,aGc);
sl@0
   223
	}
sl@0
   224
sl@0
   225
void CStatusWindow::WinKeyL(const TKeyEvent &aKey,const TTime&)
sl@0
   226
	{
sl@0
   227
	switch(aKey.iCode)
sl@0
   228
		{
sl@0
   229
		case EKeyEscape:
sl@0
   230
			iTest->Request();
sl@0
   231
			break;
sl@0
   232
		case 'M':
sl@0
   233
		case 'm':
sl@0
   234
			if (iXyInputType==EXYInputDeltaMouse)
sl@0
   235
				{
sl@0
   236
				if (HAL::Set(HALData::EMouseState,!iSimulatedPenDown)==KErrNone)
sl@0
   237
					{
sl@0
   238
					iSimulatedPenDown=!iSimulatedPenDown;
sl@0
   239
					UpdateString3();
sl@0
   240
					DoDraw();
sl@0
   241
					}
sl@0
   242
				}
sl@0
   243
			break;
sl@0
   244
	#if defined(__WINS__)
sl@0
   245
		case 'I':
sl@0
   246
		case 'i':
sl@0
   247
		case '1':
sl@0
   248
			ChangeXyInputType();
sl@0
   249
			Client()->iWs.SimulateXyInputType(iXyInputType);
sl@0
   250
			break;
sl@0
   251
	#endif
sl@0
   252
		case 'C':
sl@0
   253
		case 'c':
sl@0
   254
		case '2':
sl@0
   255
			ChangePointerCursorMode();
sl@0
   256
			Client()->iWs.SetPointerCursorMode(iMode);
sl@0
   257
			break;
sl@0
   258
		default:;
sl@0
   259
		}
sl@0
   260
	}
sl@0
   261
sl@0
   262
void CStatusWindow::PointerL(const TPointerEvent &aPointer,const TTime &aTime)
sl@0
   263
	{
sl@0
   264
#if defined(__WINS__)
sl@0
   265
	if (iRect1.Contains(aPointer.iPosition))
sl@0
   266
		{
sl@0
   267
		if (aPointer.iType==TPointerEvent::EButton1Down)
sl@0
   268
			ChangeXyInputType();
sl@0
   269
		}
sl@0
   270
	else
sl@0
   271
#endif
sl@0
   272
        if (iRect2.Contains(aPointer.iPosition))
sl@0
   273
		{
sl@0
   274
		if (aPointer.iType==TPointerEvent::EButton1Down)
sl@0
   275
			ChangePointerCursorMode();
sl@0
   276
		}
sl@0
   277
	else if (iRect4.Contains(aPointer.iPosition))
sl@0
   278
		iExit=ETrue;
sl@0
   279
	else
sl@0
   280
		CTTitledWindow::PointerL(aPointer,aTime);
sl@0
   281
	if ((iUpdateNeeded || iExit) && aPointer.iType==TPointerEvent::EButton1Up)
sl@0
   282
		{
sl@0
   283
		if (iExit)
sl@0
   284
			iTest->Request();
sl@0
   285
		else
sl@0
   286
			{
sl@0
   287
			Client()->iWs.SetPointerCursorMode(iMode);
sl@0
   288
		#if defined(__WINS__)
sl@0
   289
			Client()->iWs.SimulateXyInputType(iXyInputType);
sl@0
   290
		#endif
sl@0
   291
			Client()->iWs.Flush();
sl@0
   292
			iUpdateNeeded=EFalse;
sl@0
   293
			}
sl@0
   294
		}
sl@0
   295
	}
sl@0
   296
sl@0
   297
void CStatusWindow::Draw()
sl@0
   298
	{
sl@0
   299
	CTTitledWindow::Draw();
sl@0
   300
	TInt ascent=iFont->AscentInPixels()+1;
sl@0
   301
	iGc->DrawText(iString1,iRect1,ascent,CGraphicsContext::ELeft);
sl@0
   302
	iGc->DrawText(iString2,iRect2,ascent,CGraphicsContext::ELeft);
sl@0
   303
	iGc->DrawText(iString3,iRect3,ascent,CGraphicsContext::ELeft);
sl@0
   304
	iGc->DrawText(iString4,iRect4,ascent,CGraphicsContext::ELeft);
sl@0
   305
	}
sl@0
   306
sl@0
   307
void CStatusWindow::DoDraw()
sl@0
   308
	{
sl@0
   309
	iGc->Activate(iWin);
sl@0
   310
	iGc->UseFont((CFont *)iFont);
sl@0
   311
	Draw();
sl@0
   312
	iGc->Deactivate();
sl@0
   313
	}
sl@0
   314
sl@0
   315
void CStatusWindow::UpdateString1()
sl@0
   316
	{
sl@0
   317
	_LIT(Text0,"No Pointer");
sl@0
   318
	_LIT(Text1,"Pen");
sl@0
   319
	_LIT(Text2,"Mouse");
sl@0
   320
	_LIT(Text3,"Relative Mouse");
sl@0
   321
	switch (iXyInputType)
sl@0
   322
		{
sl@0
   323
	case EXYInputNone:
sl@0
   324
		iString1.Copy(Text0);
sl@0
   325
		break;
sl@0
   326
	case EXYInputPointer:
sl@0
   327
		iString1.Copy(Text1);
sl@0
   328
		break;
sl@0
   329
	case EXYInputMouse:
sl@0
   330
		iString1.Copy(Text2);
sl@0
   331
		break;
sl@0
   332
	case EXYInputDeltaMouse:
sl@0
   333
		iString1.Copy(Text3);
sl@0
   334
		break;
sl@0
   335
		}
sl@0
   336
	}
sl@0
   337
sl@0
   338
void CStatusWindow::UpdateString2()
sl@0
   339
	{
sl@0
   340
	_LIT(Text0,"None");
sl@0
   341
	_LIT(Text1,"Fixed");
sl@0
   342
	_LIT(Text2,"Normal");
sl@0
   343
	_LIT(Text3,"Window");
sl@0
   344
	switch (iMode)
sl@0
   345
		{
sl@0
   346
	case EPointerCursorNone:
sl@0
   347
		iString2.Copy(Text0);
sl@0
   348
		break;
sl@0
   349
	case EPointerCursorFixed:
sl@0
   350
		iString2.Copy(Text1);
sl@0
   351
		break;
sl@0
   352
	case EPointerCursorNormal:
sl@0
   353
		iString2.Copy(Text2);
sl@0
   354
		break;
sl@0
   355
	case EPointerCursorWindow:
sl@0
   356
		iString2.Copy(Text3);
sl@0
   357
		break;
sl@0
   358
		}
sl@0
   359
	}
sl@0
   360
sl@0
   361
void CStatusWindow::UpdateString3()
sl@0
   362
	{
sl@0
   363
	if (iSimulatedPenDown)
sl@0
   364
		{
sl@0
   365
		_LIT(TextD,"Sim Pen Down");
sl@0
   366
		iString3.Copy(TextD);
sl@0
   367
		}
sl@0
   368
	else
sl@0
   369
		{
sl@0
   370
		_LIT(TextU,"Sim Pen Up");
sl@0
   371
		iString3.Copy(TextU);
sl@0
   372
		}
sl@0
   373
	}
sl@0
   374
sl@0
   375
void CStatusWindow::ChangeXyInputType()
sl@0
   376
	{
sl@0
   377
	if (iXyInputType==EXYInputMouse)
sl@0
   378
		iXyInputType=EXYInputPointer;
sl@0
   379
	else if (iXyInputType==EXYInputPointer)
sl@0
   380
		iXyInputType=EXYInputMouse;
sl@0
   381
	UpdateString1();
sl@0
   382
	DoDraw();
sl@0
   383
	iUpdateNeeded=ETrue;
sl@0
   384
	}
sl@0
   385
sl@0
   386
void CStatusWindow::ChangePointerCursorMode()
sl@0
   387
	{
sl@0
   388
	TInt mode=(iMode+1)%(EPointerCursorLastMode+1);
sl@0
   389
	iMode=STATIC_CAST(TPointerCursorMode,mode);
sl@0
   390
	UpdateString2();
sl@0
   391
	DoDraw();
sl@0
   392
	iUpdateNeeded=ETrue;
sl@0
   393
	}
sl@0
   394
sl@0
   395
sl@0
   396
/*Sprite Drawing Functions*/
sl@0
   397
sl@0
   398
#if defined(__WINS__)
sl@0
   399
	#define DRAW_COLOR 1
sl@0
   400
#else
sl@0
   401
	#define DRAW_COLOR 0
sl@0
   402
#endif
sl@0
   403
sl@0
   404
void DrawCross(CBitmapContext *aGc,TInt , const TSize &aSize, TBool aDoMask, TAny *aLineWidth)
sl@0
   405
	{
sl@0
   406
	TInt halfLineWidth=(*STATIC_CAST(TInt*,aLineWidth)+1)/2;
sl@0
   407
	TInt lineWidth=2*halfLineWidth+1;		//Must be odd
sl@0
   408
	aGc->SetBrushColor(TRgb::Gray4(aDoMask ? 0 : 3));
sl@0
   409
	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   410
	aGc->SetPenStyle(CGraphicsContext::ENullPen);
sl@0
   411
	aGc->DrawRect(TRect(aSize));
sl@0
   412
	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
sl@0
   413
	aGc->SetPenColor(TRgb::Gray4(aDoMask ? 3 : 0));
sl@0
   414
	aGc->SetPenSize(TSize(lineWidth,lineWidth));
sl@0
   415
	aGc->DrawLine(TPoint(halfLineWidth,halfLineWidth),TPoint(aSize.iWidth-lineWidth,aSize.iHeight-lineWidth));
sl@0
   416
	aGc->DrawLine(TPoint(halfLineWidth,aSize.iHeight-lineWidth),TPoint(aSize.iWidth-lineWidth,halfLineWidth));
sl@0
   417
	}
sl@0
   418
sl@0
   419
void DrawArrow(CBitmapContext *aGc,TInt , const TSize &aSize, TBool aDoMask, TAny *aLineWidth)
sl@0
   420
	{
sl@0
   421
	TInt lineWidth=*STATIC_CAST(TInt*,aLineWidth);
sl@0
   422
	TInt halfLineWidth=(lineWidth-1)/2;
sl@0
   423
	aGc->SetBrushColor(TRgb::Gray4(aDoMask ? 0 : 3));
sl@0
   424
	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   425
	aGc->SetPenStyle(CGraphicsContext::ENullPen);
sl@0
   426
	aGc->DrawRect(TRect(aSize));
sl@0
   427
	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
sl@0
   428
	aGc->SetPenColor(TRgb::Gray4(aDoMask ? 3 : 0));
sl@0
   429
	aGc->SetPenSize(TSize(1,1));
sl@0
   430
	aGc->DrawLine(TPoint(0,0),TPoint(lineWidth,0));
sl@0
   431
	aGc->DrawLine(TPoint(0,0),TPoint(0,lineWidth));
sl@0
   432
	aGc->SetPenSize(TSize(lineWidth,lineWidth));
sl@0
   433
	aGc->DrawLine(TPoint(halfLineWidth,halfLineWidth),TPoint(aSize.iWidth-halfLineWidth-1,aSize.iHeight-halfLineWidth-1));
sl@0
   434
	aGc->DrawLine(TPoint(halfLineWidth,halfLineWidth),TPoint(aSize.iWidth/2,halfLineWidth));
sl@0
   435
	aGc->DrawLine(TPoint(halfLineWidth,halfLineWidth),TPoint(halfLineWidth,aSize.iHeight/2));
sl@0
   436
	}
sl@0
   437
sl@0
   438
void DrawSquare(CBitmapContext *aGc,TInt , const TSize &aSize, TBool aDoMask, TAny *)
sl@0
   439
	{
sl@0
   440
	aGc->SetBrushColor(TRgb::Gray4(aDoMask ? 0 : 3));
sl@0
   441
	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   442
	aGc->SetPenStyle(CGraphicsContext::ENullPen);
sl@0
   443
	aGc->DrawRect(TRect(aSize));
sl@0
   444
	aGc->SetBrushColor(TRgb::Gray4(aDoMask ? 3 : DRAW_COLOR));
sl@0
   445
	aGc->DrawRect(TRect(1,1,aSize.iWidth-1,aSize.iHeight-1));
sl@0
   446
	}
sl@0
   447
sl@0
   448
void DrawCircle(CBitmapContext *aGc,TInt , const TSize &aSize, TBool aDoMask, TAny *)
sl@0
   449
	{
sl@0
   450
	aGc->SetBrushColor(TRgb::Gray4(aDoMask ? 0 : 3));
sl@0
   451
	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   452
	aGc->SetPenStyle(CGraphicsContext::ENullPen);
sl@0
   453
	aGc->DrawRect(TRect(aSize));
sl@0
   454
	aGc->SetBrushColor(TRgb::Gray4(aDoMask ? 3 : 1));
sl@0
   455
	aGc->DrawEllipse(TRect(1,1,aSize.iWidth-1,aSize.iHeight-1));
sl@0
   456
	}
sl@0
   457
sl@0
   458
void DrawTriangle(CBitmapContext *aGc,TInt , const TSize &aSize, TBool aDoMask, TAny *)
sl@0
   459
	{
sl@0
   460
	aGc->SetBrushColor(TRgb::Gray4(aDoMask ? 0 : 3));
sl@0
   461
	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   462
	aGc->SetPenStyle(CGraphicsContext::ENullPen);
sl@0
   463
	aGc->DrawRect(TRect(aSize));
sl@0
   464
	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
sl@0
   465
	aGc->SetPenColor(TRgb::Gray4(aDoMask ? 3 : DRAW_COLOR));
sl@0
   466
	aGc->SetPenSize(TSize(1,1));
sl@0
   467
	for(TInt y=0;y<aSize.iHeight;y++)
sl@0
   468
		{
sl@0
   469
		TInt xfact=aSize.iWidth*y/aSize.iHeight;
sl@0
   470
		aGc->DrawLine(TPoint(aSize.iWidth-xfact-1,y),TPoint(aSize.iWidth-1,y));
sl@0
   471
		}
sl@0
   472
	}
sl@0
   473
sl@0
   474
void DrawOpenSquare(CBitmapContext *aGc,TInt , const TSize &aSize, TBool aDoMask, TAny *aLineWidth)
sl@0
   475
	{
sl@0
   476
	TInt halfLineWidth=*STATIC_CAST(TInt*,aLineWidth)/2;
sl@0
   477
	TInt lineWidth=2*halfLineWidth+1;		//Must be odd
sl@0
   478
	aGc->SetBrushColor(TRgb::Gray4(aDoMask ? 0 : 3));
sl@0
   479
	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   480
	aGc->SetPenStyle(CGraphicsContext::ENullPen);
sl@0
   481
	aGc->DrawRect(TRect(aSize));
sl@0
   482
	aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
sl@0
   483
	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
sl@0
   484
	aGc->SetPenColor(TRgb::Gray4(aDoMask ? 3 : DRAW_COLOR));
sl@0
   485
	aGc->SetPenSize(TSize(lineWidth,lineWidth));
sl@0
   486
	TPoint botRig(aSize.iWidth-aSize.iWidth/4-1,aSize.iHeight-aSize.iHeight/4-1);
sl@0
   487
	aGc->DrawRect(TRect(aSize.iWidth/4,aSize.iHeight/4,botRig.iX+1,botRig.iY+1));
sl@0
   488
	aGc->DrawLine(TPoint(halfLineWidth,halfLineWidth),TPoint(aSize.iWidth/4-halfLineWidth,aSize.iHeight/4-halfLineWidth));
sl@0
   489
	aGc->DrawLine(TPoint(aSize.iWidth-1-halfLineWidth,halfLineWidth),TPoint(botRig.iX+halfLineWidth,aSize.iHeight/4-halfLineWidth));
sl@0
   490
	aGc->DrawLine(TPoint(aSize.iWidth-1-halfLineWidth,aSize.iHeight-1-halfLineWidth),TPoint(botRig.iX+halfLineWidth,botRig.iY+halfLineWidth));
sl@0
   491
	aGc->DrawLine(TPoint(halfLineWidth,aSize.iHeight-1-halfLineWidth),TPoint(aSize.iWidth/4-halfLineWidth,botRig.iY+halfLineWidth));
sl@0
   492
	}
sl@0
   493
sl@0
   494
void DrawOpenCircle(CBitmapContext *aGc,TInt , const TSize &aSize, TBool aDoMask, TAny *aLineWidth)
sl@0
   495
	{
sl@0
   496
	TInt halfLineWidth=*STATIC_CAST(TInt*,aLineWidth)/2;
sl@0
   497
	TInt lineWidth=2*halfLineWidth+1;		//Must be odd
sl@0
   498
	aGc->SetBrushColor(TRgb::Gray4(aDoMask ? 0 : 3));
sl@0
   499
	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   500
	aGc->SetPenStyle(CGraphicsContext::ENullPen);
sl@0
   501
	aGc->DrawRect(TRect(aSize));
sl@0
   502
	aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
sl@0
   503
	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
sl@0
   504
	aGc->SetPenColor(TRgb::Gray4(aDoMask ? 3 : DRAW_COLOR));
sl@0
   505
	aGc->SetPenSize(TSize(lineWidth,lineWidth));
sl@0
   506
	TPoint botRig(aSize.iWidth-aSize.iWidth/4-1,aSize.iHeight-aSize.iHeight/4-1);
sl@0
   507
	aGc->DrawEllipse(TRect(aSize.iWidth/4+1,aSize.iHeight/4+1,botRig.iX+1,botRig.iY+1));
sl@0
   508
	aGc->DrawLine(TPoint(aSize.iWidth/2,1+halfLineWidth),TPoint(aSize.iWidth/2,aSize.iHeight/4+1-halfLineWidth));
sl@0
   509
	aGc->DrawLine(TPoint(aSize.iWidth/2,aSize.iHeight-1-halfLineWidth),TPoint(aSize.iWidth/2,botRig.iY+halfLineWidth));
sl@0
   510
	aGc->DrawLine(TPoint(1+halfLineWidth,aSize.iWidth/2),TPoint(aSize.iWidth/4+1-halfLineWidth,aSize.iHeight/2));
sl@0
   511
	aGc->DrawLine(TPoint(aSize.iWidth-1-halfLineWidth,aSize.iHeight/2),TPoint(botRig.iX+halfLineWidth,aSize.iWidth/2));
sl@0
   512
	}
sl@0
   513
sl@0
   514
sl@0
   515
/*CPointerCursorTest*/
sl@0
   516
sl@0
   517
GLDEF_C CTestBase *CreatePointerCursorTest()
sl@0
   518
	{
sl@0
   519
	return(new(ELeave) CPointerCursorTest());
sl@0
   520
	}
sl@0
   521
sl@0
   522
CPointerCursorTest::CPointerCursorTest() : CTestBase(_L("PointerCursor"))
sl@0
   523
	{}
sl@0
   524
sl@0
   525
CPointerCursorTest::~CPointerCursorTest()
sl@0
   526
	{
sl@0
   527
	TInt ii;
sl@0
   528
	Client()->iGroup->SetCurrentWindow(NULL);
sl@0
   529
	delete iInfoWindow;
sl@0
   530
	for(ii=0;ii<6;++ii)
sl@0
   531
		{
sl@0
   532
		delete iWindows[ii];
sl@0
   533
		}
sl@0
   534
	for(ii=0;ii<eNumPointerCursors;++ii)
sl@0
   535
		{
sl@0
   536
		delete iCursors[ii];
sl@0
   537
		delete iBitmaps[ii];
sl@0
   538
		}
sl@0
   539
	delete iGroup1;
sl@0
   540
	delete iGroup2;
sl@0
   541
	}
sl@0
   542
sl@0
   543
void CPointerCursorTest::ConstructL()
sl@0
   544
	{
sl@0
   545
	TSize size=Client()->iScreen->SizeInPixels();
sl@0
   546
	TInt infoWidth=Min(210,5*size.iWidth/12);
sl@0
   547
	size.iWidth=Max(Min(415,size.iWidth-infoWidth),85);
sl@0
   548
	iInfoWindow=new(ELeave) CStatusWindow();
sl@0
   549
	iInfoWindow->SetUpL(TPoint(size.iWidth,50),TSize(infoWidth,180),Client()->iGroup,*Client()->iGc);
sl@0
   550
	Client()->iGroup->SetCurrentWindow(iInfoWindow);
sl@0
   551
	iInfoWindow->Construct(this);
sl@0
   552
	iGroup1=new(ELeave) CPointerCursorWindowGroup(Client());
sl@0
   553
	iGroup1->ConstructL();
sl@0
   554
	iGroup2=new(ELeave) CPointerCursorWindowGroup(Client());
sl@0
   555
	iGroup2->ConstructL();
sl@0
   556
	size.iWidth-=5;
sl@0
   557
	CreateWindowsL(size);
sl@0
   558
	CreatePointerCursorsL();
sl@0
   559
	iGroup1->SetPointerCursor(iCursors[0]);
sl@0
   560
	iWindows[1]->SetBitmap(iBitmaps[0],EFalse);
sl@0
   561
	iWindows[0]->SetPointerCursor(iCursors[1]);
sl@0
   562
	iWindows[0]->SetBitmap(iBitmaps[1]);
sl@0
   563
	iWindows[0]->Child()->SetPointerCursor(iCursors[2]);
sl@0
   564
	iWindows[0]->Child()->SetBitmap(iBitmaps[2]);
sl@0
   565
	iWindows[2]->SetPointerCursor(iCursors[3]);
sl@0
   566
	iWindows[2]->SetBitmap(iBitmaps[3]);
sl@0
   567
	iWindows[2]->Child()->Child()->SetPointerCursor(iCursors[4]);
sl@0
   568
	iWindows[2]->Child()->Child()->SetBitmap(iBitmaps[4]);
sl@0
   569
	iWindows[3]->Child()->SetPointerCursor(iCursors[5]);
sl@0
   570
	iWindows[3]->Child()->SetBitmap(iBitmaps[5]);
sl@0
   571
	iWindows[4]->SetPointerCursor(iCursors[6]);
sl@0
   572
	iWindows[4]->SetBitmap(iBitmaps[6]);
sl@0
   573
	}
sl@0
   574
sl@0
   575
void CPointerCursorTest::CreateWindowsL(TSize aArea)
sl@0
   576
	{
sl@0
   577
	//TSize screenSize=Client()->iScreen->SizeInPixels();
sl@0
   578
	TInt height=eWindowGap+(aArea.iHeight-5*eWindowGap)/4;
sl@0
   579
	TInt halfWidth=aArea.iWidth/2;
sl@0
   580
	TRect rect(5,eWindowGap,halfWidth,height);
sl@0
   581
	iWindows[0]=CreateWindowL(2,rect,iGroup1);
sl@0
   582
	rect.Move(halfWidth,0);
sl@0
   583
	iWindows[1]=CreateWindowL(2,rect,iGroup1);
sl@0
   584
	rect.Move(-halfWidth,height);
sl@0
   585
	rect.iBr.iX=aArea.iWidth;
sl@0
   586
	iWindows[2]=CreateWindowL(4,rect,iGroup2);
sl@0
   587
	rect.Move(0,height);
sl@0
   588
	rect.iBr.iX=aArea.iWidth-11;
sl@0
   589
	iWindows[3]=CreateWindowL(3,rect,iGroup2);
sl@0
   590
	rect.Move(0,height);
sl@0
   591
	rect.iBr.iX=halfWidth;
sl@0
   592
	iWindows[4]=CreateWindowL(2,rect,iGroup2);
sl@0
   593
	rect.Move(halfWidth,0);
sl@0
   594
	iWindows[5]=CreateWindowL(2,rect,iGroup2);
sl@0
   595
	}
sl@0
   596
sl@0
   597
CPointerCursorWindow* CPointerCursorTest::CreateWindowL(TInt aNum,TRect aLocation,CTWinBase *aGroup)
sl@0
   598
	{
sl@0
   599
	CPointerCursorWindow* firstWin=NULL;
sl@0
   600
	CPointerCursorWindow* parent=NULL;
sl@0
   601
	CPointerCursorWindow* win;
sl@0
   602
	TInt xInc=aLocation.Width()/aNum-eChildWindowGap;
sl@0
   603
	TInt ii;
sl@0
   604
	for (ii=aNum;ii>0;ii--)
sl@0
   605
		{
sl@0
   606
		win=new(ELeave) CPointerCursorWindow();
sl@0
   607
		CleanupStack::PushL(win);
sl@0
   608
		win->SetUpL(aLocation.iTl,aLocation.Size(),aGroup,*Client()->iGc);
sl@0
   609
		if (!parent)
sl@0
   610
			firstWin=win;
sl@0
   611
		else
sl@0
   612
			{
sl@0
   613
			parent->SetChild(win);
sl@0
   614
			CleanupStack::Pop();
sl@0
   615
			}
sl@0
   616
		aLocation.iBr=TPoint(-eChildWindowGap,-eChildWindowGap)+aLocation.Size();
sl@0
   617
		aLocation.iTl.iX=xInc;
sl@0
   618
		aLocation.iTl.iY=eChildWindowGap;
sl@0
   619
		aGroup=win;
sl@0
   620
		parent=win;
sl@0
   621
		}
sl@0
   622
	CleanupStack::Pop();
sl@0
   623
	return firstWin;
sl@0
   624
	}
sl@0
   625
sl@0
   626
void CPointerCursorTest::CreatePointerCursorsL()
sl@0
   627
	{
sl@0
   628
	const TSize size(32,32);
sl@0
   629
	TSpriteCreateParams params(size,TPoint(-16,-16),DrawSquare);
sl@0
   630
	TSpriteCreateParams paramarray[eNumPointerCursors];
sl@0
   631
	TInt lineWidth1=3;
sl@0
   632
	TInt lineWidth2=5;
sl@0
   633
	paramarray[2]=params;
sl@0
   634
	params.iDrawFunc=DrawCircle;
sl@0
   635
	paramarray[3]=params;
sl@0
   636
	params.iDrawFunc=DrawOpenSquare;
sl@0
   637
	params.iDrawFuncParam=&lineWidth1;
sl@0
   638
	paramarray[5]=params;
sl@0
   639
	params.iDrawFunc=DrawOpenCircle;
sl@0
   640
	paramarray[6]=params;
sl@0
   641
	params.iOffset=TPoint(0,0);
sl@0
   642
	params.iDrawFunc=DrawArrow;
sl@0
   643
	params.iDrawFuncParam=&lineWidth2;
sl@0
   644
	paramarray[1]=params;
sl@0
   645
	params.iOffset.iX=-31;
sl@0
   646
	params.iDrawFunc=DrawTriangle;
sl@0
   647
	paramarray[4]=params;
sl@0
   648
	params.iOffset=TPoint(-15,-15);
sl@0
   649
	params.iDrawFunc=DrawCross;
sl@0
   650
	paramarray[0]=params;
sl@0
   651
	CFbsBitmap *bitmap;
sl@0
   652
	TInt ii,jj;
sl@0
   653
	TDisplayMode mode=Client()->iWs.GetDefModeMaxNumColors(ii,jj);
sl@0
   654
	for (ii=0;ii<eNumPointerCursors;++ii)
sl@0
   655
		{
sl@0
   656
		bitmap=NULL;
sl@0
   657
		iBitmaps[ii]=new(ELeave) CFbsBitmap();
sl@0
   658
		User::LeaveIfError(iBitmaps[ii]->Create(size,mode));
sl@0
   659
		iCursors[ii]=new(ELeave) CTPointerCursor(Client()->iWs);
sl@0
   660
		iCursors[ii]->ConstructL(1,&paramarray[ii],0,iBitmaps[ii],bitmap);
sl@0
   661
		delete bitmap;
sl@0
   662
		}
sl@0
   663
	}
sl@0
   664
sl@0
   665
TestState CPointerCursorTest::DoTestL()
sl@0
   666
	{
sl@0
   667
	switch(iState)
sl@0
   668
		{
sl@0
   669
		case 0:
sl@0
   670
			LogSubTest(_L("Pointer Cursor"),1);
sl@0
   671
			TestL(ETrue);
sl@0
   672
			iState++;
sl@0
   673
			return(EContinue);
sl@0
   674
		default:
sl@0
   675
			return(EFinished);
sl@0
   676
		}
sl@0
   677
	}