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