os/graphics/windowing/windowserver/test/tman/MULTICON.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) 1995-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 multiple connections to the window server
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <e32svr.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
const TInt EMaxSubState=3;
sl@0
    25
sl@0
    26
class CMcWindowBase;
sl@0
    27
class TMultiConTest;
sl@0
    28
sl@0
    29
class CMcConnectionBase : public CTClient
sl@0
    30
	{
sl@0
    31
public:
sl@0
    32
	CMcConnectionBase(TMultiConTest *aTest);
sl@0
    33
	~CMcConnectionBase();
sl@0
    34
	virtual void ConstructL();
sl@0
    35
	void SubStateChanged();
sl@0
    36
protected:
sl@0
    37
	TMultiConTest *iTest;
sl@0
    38
	CMcWindowBase *iWin;
sl@0
    39
	CWindowGc *iGc;
sl@0
    40
	};
sl@0
    41
sl@0
    42
class CMcConnection : public CMcConnectionBase	// Sets AutoForeground off
sl@0
    43
	{
sl@0
    44
public:
sl@0
    45
	CMcConnection(TMultiConTest *aTest);
sl@0
    46
	void ConstructL();
sl@0
    47
	};
sl@0
    48
sl@0
    49
class CMcWindowGroupAf : public CTWindowGroup
sl@0
    50
	{
sl@0
    51
public:
sl@0
    52
	CMcWindowGroupAf(CTClient *aClient);
sl@0
    53
	void KeyL(const TKeyEvent &aKey, const TTime &aTime);
sl@0
    54
	};
sl@0
    55
sl@0
    56
class CMcConnectionAf : public CMcConnectionBase	// Sets AutoForeground on
sl@0
    57
	{
sl@0
    58
public:
sl@0
    59
	CMcConnectionAf(TMultiConTest *aTest);
sl@0
    60
	void ConstructL();
sl@0
    61
	void KeyL(const TKeyEvent &aKey);
sl@0
    62
	};
sl@0
    63
sl@0
    64
class CMcConnectionDef : public CMcConnectionBase	// Leaves AutoForeground as the default value
sl@0
    65
	{
sl@0
    66
public:
sl@0
    67
	CMcConnectionDef(TMultiConTest *aTest);
sl@0
    68
	void ConstructL();
sl@0
    69
	};
sl@0
    70
sl@0
    71
class CMcWindowBase : public CTWin
sl@0
    72
	{
sl@0
    73
public:
sl@0
    74
	CMcWindowBase(TMultiConTest *aTest);
sl@0
    75
	void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
sl@0
    76
	virtual void Draw()=0;
sl@0
    77
	virtual void PointerL(const TPointerEvent &pointer,const TTime &)=0;
sl@0
    78
protected:
sl@0
    79
	TMultiConTest *iTest;
sl@0
    80
	TRgb iBack;
sl@0
    81
	};
sl@0
    82
sl@0
    83
class CMcWindow : public CMcWindowBase
sl@0
    84
	{
sl@0
    85
public:
sl@0
    86
	CMcWindow(TMultiConTest *aTest);
sl@0
    87
	virtual void Draw();
sl@0
    88
	virtual void PointerL(const TPointerEvent &pointer,const TTime &);
sl@0
    89
	};
sl@0
    90
sl@0
    91
class CMcWindowAf : public CMcWindowBase
sl@0
    92
	{
sl@0
    93
public:
sl@0
    94
	CMcWindowAf(TMultiConTest *aTest);
sl@0
    95
	virtual void Draw();
sl@0
    96
	virtual void PointerL(const TPointerEvent &pointer,const TTime &);
sl@0
    97
	void ConstructL();
sl@0
    98
	};
sl@0
    99
sl@0
   100
class CMcWindowDef : public CMcWindowBase
sl@0
   101
	{
sl@0
   102
public:
sl@0
   103
	CMcWindowDef(TMultiConTest *aTest);
sl@0
   104
	virtual void Draw();
sl@0
   105
	virtual void PointerL(const TPointerEvent &pointer,const TTime &);
sl@0
   106
	};
sl@0
   107
sl@0
   108
class TMultiConTest : public CTestBase
sl@0
   109
	{
sl@0
   110
public:
sl@0
   111
	TMultiConTest();
sl@0
   112
	~TMultiConTest();
sl@0
   113
	TestState DoTestL();
sl@0
   114
	void ConstructL();
sl@0
   115
	void EndAutoForegroundTest();
sl@0
   116
	TInt SubState() const;
sl@0
   117
	void IncSubState();
sl@0
   118
private:
sl@0
   119
	CMcConnectionAf *iConn1;
sl@0
   120
	CMcConnection *iConn2;
sl@0
   121
	CMcConnectionDef *iConn3;
sl@0
   122
	TSize iWinSize;
sl@0
   123
	TInt iState;
sl@0
   124
	TInt iSubState;
sl@0
   125
	};
sl@0
   126
sl@0
   127
GLDEF_C CTestBase *CreateMultiConTest()
sl@0
   128
	{
sl@0
   129
	return(new(ELeave) TMultiConTest());
sl@0
   130
	}
sl@0
   131
sl@0
   132
TMultiConTest::TMultiConTest() : CTestBase(_L("MultiCon"))
sl@0
   133
	{}
sl@0
   134
sl@0
   135
TMultiConTest::~TMultiConTest()
sl@0
   136
	{
sl@0
   137
	delete iConn1;
sl@0
   138
	delete iConn2;
sl@0
   139
	delete iConn3;
sl@0
   140
	}
sl@0
   141
sl@0
   142
void TMultiConTest::EndAutoForegroundTest()
sl@0
   143
	{
sl@0
   144
	iConn1->iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
sl@0
   145
	iConn2->iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
sl@0
   146
	iConn3->iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
sl@0
   147
	Request();
sl@0
   148
	}
sl@0
   149
sl@0
   150
void TMultiConTest::ConstructL()
sl@0
   151
	{
sl@0
   152
	iConn3=new(ELeave) CMcConnectionDef(this);
sl@0
   153
	iConn3->ConstructL();
sl@0
   154
	iConn2=new(ELeave) CMcConnection(this);
sl@0
   155
	iConn2->ConstructL();
sl@0
   156
	iConn1=new(ELeave) CMcConnectionAf(this);
sl@0
   157
	iConn1->ConstructL();
sl@0
   158
	}
sl@0
   159
sl@0
   160
//
sl@0
   161
// CMcConnection
sl@0
   162
sl@0
   163
CMcConnectionBase::CMcConnectionBase(TMultiConTest *aTest) : iTest(aTest)
sl@0
   164
	{
sl@0
   165
	}
sl@0
   166
sl@0
   167
CMcConnectionBase::~CMcConnectionBase()
sl@0
   168
	{
sl@0
   169
	CTWin::Delete(iWin);
sl@0
   170
	delete iGc;
sl@0
   171
	}
sl@0
   172
sl@0
   173
void CMcConnectionBase::SubStateChanged()
sl@0
   174
	{
sl@0
   175
	iWin->Invalidate();
sl@0
   176
	iWs.Flush();
sl@0
   177
	}
sl@0
   178
sl@0
   179
void CMcConnectionBase::ConstructL()
sl@0
   180
	{
sl@0
   181
	CTClient::ConstructL();
sl@0
   182
	User::LeaveIfError(iScreen->CreateContext(iGc));
sl@0
   183
	}
sl@0
   184
sl@0
   185
CMcConnection::CMcConnection(TMultiConTest *aTest) : CMcConnectionBase(aTest)
sl@0
   186
	{
sl@0
   187
	}
sl@0
   188
sl@0
   189
void CMcConnection::ConstructL()
sl@0
   190
	{
sl@0
   191
	CMcConnectionBase::ConstructL();
sl@0
   192
	iGroup=new(ELeave) CTWindowGroup(this);
sl@0
   193
	iGroup->ConstructL();
sl@0
   194
	TSize screenSize=iGroup->Size();
sl@0
   195
	TInt winWidth=screenSize.iWidth/3;
sl@0
   196
	TInt winHeight=screenSize.iHeight/2-10;
sl@0
   197
	iGroup->GroupWin()->AutoForeground(EFalse);
sl@0
   198
	CMcWindow *win=new(ELeave) CMcWindow(iTest);
sl@0
   199
	win->SetUpL(TPoint(5,5),TSize(winWidth,winHeight),iGroup,*iGc);
sl@0
   200
	iWin=win;
sl@0
   201
	iWs.Flush();
sl@0
   202
	}
sl@0
   203
sl@0
   204
CMcConnectionAf::CMcConnectionAf(TMultiConTest *aTest) : CMcConnectionBase(aTest)
sl@0
   205
	{
sl@0
   206
	}
sl@0
   207
sl@0
   208
void CMcConnectionAf::ConstructL()
sl@0
   209
	{
sl@0
   210
	CMcConnectionBase::ConstructL();
sl@0
   211
	iGroup=new(ELeave) CMcWindowGroupAf(this);
sl@0
   212
	iGroup->ConstructL();
sl@0
   213
	TSize screenSize=iGroup->Size();
sl@0
   214
	TInt winWidth=screenSize.iWidth/3;
sl@0
   215
	TInt winHeight=screenSize.iHeight/2-10;
sl@0
   216
	iGroup->GroupWin()->AutoForeground(ETrue);
sl@0
   217
	CMcWindowAf *win=new(ELeave) CMcWindowAf(iTest);
sl@0
   218
	win->SetUpL(TPoint(winWidth,5),TSize(winWidth,winHeight),iGroup,*iGc);
sl@0
   219
	iWin=win;
sl@0
   220
	iWs.Flush();
sl@0
   221
	}
sl@0
   222
sl@0
   223
void CMcConnectionAf::KeyL(const TKeyEvent &aKey)
sl@0
   224
	{
sl@0
   225
	switch(aKey.iCode)
sl@0
   226
		{
sl@0
   227
		case ' ':
sl@0
   228
			if (iTest->SubState()==0)
sl@0
   229
				{
sl@0
   230
				iTest->TestL(iGroup->GroupWin()->OrdinalPosition()==0);
sl@0
   231
				iTest->IncSubState();
sl@0
   232
				}
sl@0
   233
			break;
sl@0
   234
		case EKeyEscape:
sl@0
   235
			iTest->EndAutoForegroundTest();
sl@0
   236
			break;
sl@0
   237
		}
sl@0
   238
	}
sl@0
   239
sl@0
   240
CMcConnectionDef::CMcConnectionDef(TMultiConTest *aTest) : CMcConnectionBase(aTest)
sl@0
   241
	{
sl@0
   242
	}
sl@0
   243
sl@0
   244
void CMcConnectionDef::ConstructL()
sl@0
   245
	{
sl@0
   246
	CMcConnectionBase::ConstructL();
sl@0
   247
	iGroup=new(ELeave) CTWindowGroup(this);
sl@0
   248
	iGroup->ConstructL();
sl@0
   249
	iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
sl@0
   250
	TSize screenSize=iGroup->Size();
sl@0
   251
	TInt winWidth=screenSize.iWidth/3-10;
sl@0
   252
	TInt winHeight=(screenSize.iHeight/2)-10;
sl@0
   253
	CMcWindowDef *win=new(ELeave) CMcWindowDef(iTest);
sl@0
   254
	win->SetUpL(TPoint(5+winWidth/2,screenSize.iHeight/2),TSize(winWidth,winHeight),iGroup,*iGc);
sl@0
   255
	iWin=win;
sl@0
   256
	iWs.Flush();
sl@0
   257
	}
sl@0
   258
sl@0
   259
//
sl@0
   260
// CMcWindow, base class //
sl@0
   261
//
sl@0
   262
sl@0
   263
CMcWindowBase::CMcWindowBase(TMultiConTest *aTest) : CTWin(), iTest(aTest)
sl@0
   264
	{
sl@0
   265
	}
sl@0
   266
sl@0
   267
void CMcWindowBase::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
sl@0
   268
	{
sl@0
   269
	ConstructExtLD(*parent,pos,size);
sl@0
   270
	iWin.SetBackgroundColor(iBack);
sl@0
   271
	Activate();
sl@0
   272
	AssignGC(aGc);
sl@0
   273
	}
sl@0
   274
sl@0
   275
//
sl@0
   276
// CMcWindow, window used to test multiple connections //
sl@0
   277
//
sl@0
   278
sl@0
   279
CMcWindow::CMcWindow(TMultiConTest *aTest) : CMcWindowBase(aTest)
sl@0
   280
	{
sl@0
   281
	iBack=TRgb::Gray256(221);
sl@0
   282
	}
sl@0
   283
sl@0
   284
void CMcWindow::PointerL(const TPointerEvent &pointer,const TTime &)
sl@0
   285
	{
sl@0
   286
	if (pointer.iType==TPointerEvent::EButton1Down)
sl@0
   287
		{
sl@0
   288
		switch(iTest->SubState())
sl@0
   289
			{
sl@0
   290
			case 1:
sl@0
   291
				iTest->TestL(Client()->iGroup->GroupWin()->OrdinalPosition()==1);
sl@0
   292
				iTest->IncSubState();
sl@0
   293
				break;
sl@0
   294
			}
sl@0
   295
		}
sl@0
   296
	}
sl@0
   297
sl@0
   298
void CMcWindow::Draw()
sl@0
   299
	{
sl@0
   300
	iGc->Clear();
sl@0
   301
	TBuf<0x40> buf;
sl@0
   302
	switch(iTest->SubState())
sl@0
   303
		{
sl@0
   304
		case 1:
sl@0
   305
			buf.Copy(_L("Click on me"));
sl@0
   306
			break;
sl@0
   307
		case 0:
sl@0
   308
		case 2:
sl@0
   309
		case 3:
sl@0
   310
			buf.Copy(_L(""));
sl@0
   311
			break;
sl@0
   312
		default:
sl@0
   313
			buf.Copy(_L("ERROR"));
sl@0
   314
		}
sl@0
   315
	iGc->DrawText(buf, TPoint(10,20));
sl@0
   316
	}
sl@0
   317
sl@0
   318
//
sl@0
   319
// CMcWindowAf, Auto foreground version of CMcWindow //
sl@0
   320
//
sl@0
   321
sl@0
   322
CMcWindowAf::CMcWindowAf(TMultiConTest *aTest) : CMcWindowBase(aTest)
sl@0
   323
	{
sl@0
   324
	iBack=TRgb::Gray256(150);
sl@0
   325
	}
sl@0
   326
sl@0
   327
void CMcWindowAf::PointerL(const TPointerEvent &pointer,const TTime &)
sl@0
   328
	{
sl@0
   329
	if (pointer.iType==TPointerEvent::EButton1Down)
sl@0
   330
		{
sl@0
   331
		switch(iTest->SubState())
sl@0
   332
			{
sl@0
   333
			case 2:
sl@0
   334
				iTest->TestL(Client()->iGroup->GroupWin()->OrdinalPosition()==0);
sl@0
   335
				iTest->IncSubState();
sl@0
   336
				break;
sl@0
   337
			}
sl@0
   338
		}
sl@0
   339
	}
sl@0
   340
sl@0
   341
void CMcWindowAf::Draw()
sl@0
   342
	{
sl@0
   343
	iGc->Clear();
sl@0
   344
	TBuf<0x40> buf;
sl@0
   345
	switch(iTest->SubState())
sl@0
   346
		{
sl@0
   347
		case 1:
sl@0
   348
		case 3:
sl@0
   349
			break;
sl@0
   350
		case 0:
sl@0
   351
			buf.Copy(_L("Press <Space>"));
sl@0
   352
			break;
sl@0
   353
		case 2:
sl@0
   354
			buf.Copy(_L("Click on me"));
sl@0
   355
			break;
sl@0
   356
		default:
sl@0
   357
			buf.Copy(_L("ERROR"));
sl@0
   358
		}
sl@0
   359
	iGc->DrawText(buf, TPoint(10,20));
sl@0
   360
	}
sl@0
   361
sl@0
   362
//
sl@0
   363
sl@0
   364
CMcWindowGroupAf::CMcWindowGroupAf(CTClient *aClient) : CTWindowGroup(aClient)
sl@0
   365
	{}
sl@0
   366
sl@0
   367
void CMcWindowGroupAf::KeyL(const TKeyEvent &aKey, const TTime &)
sl@0
   368
	{
sl@0
   369
	((CMcConnectionAf *)iClient)->KeyL(aKey);
sl@0
   370
	}
sl@0
   371
sl@0
   372
//
sl@0
   373
// CMcWindowDef, Default auto foreground version of CMcWindow //
sl@0
   374
//
sl@0
   375
sl@0
   376
CMcWindowDef::CMcWindowDef(TMultiConTest *aTest) : CMcWindowBase(aTest)
sl@0
   377
	{
sl@0
   378
	iBack=TRgb::Gray256(236);
sl@0
   379
	}
sl@0
   380
sl@0
   381
void CMcWindowDef::PointerL(const TPointerEvent &pointer,const TTime &)
sl@0
   382
	{
sl@0
   383
	if (pointer.iType==TPointerEvent::EButton1Down)
sl@0
   384
		{
sl@0
   385
		switch(iTest->SubState())
sl@0
   386
			{
sl@0
   387
			case 3:
sl@0
   388
				iTest->TestL(Client()->iGroup->GroupWin()->OrdinalPosition()==0);
sl@0
   389
				iTest->IncSubState();
sl@0
   390
				break;
sl@0
   391
			}
sl@0
   392
		}
sl@0
   393
	}
sl@0
   394
sl@0
   395
void CMcWindowDef::Draw()
sl@0
   396
	{
sl@0
   397
	iGc->Clear();
sl@0
   398
	TBuf<0x40> buf;
sl@0
   399
	switch(iTest->SubState())
sl@0
   400
		{
sl@0
   401
		case 0:
sl@0
   402
		case 1:
sl@0
   403
		case 2:
sl@0
   404
			break;
sl@0
   405
		case 3:
sl@0
   406
			buf.Copy(_L("Click on me"));
sl@0
   407
			break;
sl@0
   408
		default:
sl@0
   409
			buf.Copy(_L("ERROR"));
sl@0
   410
		}
sl@0
   411
	iGc->DrawText(buf, TPoint(10,20));
sl@0
   412
	}
sl@0
   413
sl@0
   414
//
sl@0
   415
sl@0
   416
TInt TMultiConTest::SubState() const
sl@0
   417
	{
sl@0
   418
	return(iSubState);
sl@0
   419
	}
sl@0
   420
sl@0
   421
void TMultiConTest::IncSubState()
sl@0
   422
	{
sl@0
   423
	if (iSubState==EMaxSubState)
sl@0
   424
		EndAutoForegroundTest();
sl@0
   425
	else
sl@0
   426
		{
sl@0
   427
		iSubState++;
sl@0
   428
		iConn1->SubStateChanged();
sl@0
   429
		iConn2->SubStateChanged();
sl@0
   430
		iConn3->SubStateChanged();
sl@0
   431
		}
sl@0
   432
	}
sl@0
   433
sl@0
   434
TestState TMultiConTest::DoTestL()
sl@0
   435
	{
sl@0
   436
	switch(iState)
sl@0
   437
		{
sl@0
   438
		case 0:
sl@0
   439
			LogSubTest(_L("MultiCon 1"),1);
sl@0
   440
			iState++;
sl@0
   441
			return(EContinue);
sl@0
   442
		default:
sl@0
   443
			return(EFinished);
sl@0
   444
		}
sl@0
   445
//	return(ENext);
sl@0
   446
 	}