windowing/windowserver/tman/TMPNTKEY.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1996-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 Pointer move/drag buffer
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <hal.h>
       
    20 #include "W32STD.H"
       
    21 #include "../tlib/testbase.h"
       
    22 #include "TMAN.H"
       
    23 
       
    24 const TInt ENumPntKeyTests=6;
       
    25 const TUint EModifierMask=EModifierCtrl|EModifierShift|EModifierFunc;
       
    26 
       
    27 class CTPntKeyTest;
       
    28 
       
    29 class CTPntKeyWindow : public CTWin
       
    30 	{
       
    31 private:
       
    32 	enum {KPointerMoveBufferSize=32};
       
    33 public:
       
    34 	CTPntKeyWindow(CTPntKeyTest *aTest);
       
    35 	~CTPntKeyWindow();
       
    36 	void SetUpLD(TPoint pos,TSize size,CTWinBase *parent);
       
    37 	void PointerL(const TPointerEvent &pointer,const TTime &aTime);
       
    38 	void KeyUpL(const TKeyEvent &aKey,const TTime &);
       
    39 	void KeyDownL(const TKeyEvent &aKey,const TTime &);
       
    40 	void WinKeyL(const TKeyEvent &aKey,const TTime &);
       
    41 	void SwitchOn(const TTime &aTime);
       
    42 	void SetState(TInt iState);
       
    43 	void NextKey();
       
    44 	void Test(TInt aCheck);
       
    45 	void Error();
       
    46 	void DrawButton(const TRect &aRect, const TDesC &aText);
       
    47 	void Draw();
       
    48 private:
       
    49 	CTPntKeyTest *iTest;
       
    50 	TInt iKeyCount;
       
    51 	TRect iKey1;
       
    52 	TRect iKey2;
       
    53 	TRect iKey3;
       
    54 	static TInt iTestScanCodes[ENumPntKeyTests];
       
    55 	static TUint iTestCodes[ENumPntKeyTests];
       
    56 	static TUint iTestModifiers[ENumPntKeyTests];
       
    57 	};
       
    58 
       
    59 class CTPntKeyTest : public CTestBase
       
    60 	{
       
    61 public:
       
    62 	CTPntKeyTest();
       
    63 	~CTPntKeyTest();
       
    64 	TestState DoTestL();
       
    65 	void FinishedTests();
       
    66 	void ConstructL();
       
    67 	void Failed();
       
    68 	inline TBool NoDigitiser() const {return iNoDigitiser;}
       
    69 private:
       
    70 	CTPntKeyWindow *iWin;
       
    71 	TSize iWinSize;
       
    72 	TInt iState;
       
    73 	TBool iFailed;
       
    74 	TBool iOldPointerState;
       
    75 	TBool iNoDigitiser;
       
    76 	};
       
    77 
       
    78 TInt CTPntKeyWindow::iTestScanCodes[ENumPntKeyTests]={'A','B',0,'C',EStdKeyEnter,'Y'};
       
    79 TUint CTPntKeyWindow::iTestCodes[ENumPntKeyTests]={'a','B',0,'c',EKeyEnter,'y'};
       
    80 TUint CTPntKeyWindow::iTestModifiers[ENumPntKeyTests]={0,EModifierShift,0,0,0,0};
       
    81 
       
    82 GLDEF_C CTestBase *CreatePointerKeyTest()
       
    83 	{
       
    84 	return(new(ELeave) CTPntKeyTest());
       
    85 	}
       
    86 
       
    87 CTPntKeyWindow::CTPntKeyWindow(CTPntKeyTest *aTest) : iTest(aTest)
       
    88 	{}
       
    89 
       
    90 CTPntKeyWindow::~CTPntKeyWindow()
       
    91 	{
       
    92 	}
       
    93 
       
    94 void CTPntKeyWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent)
       
    95 	{
       
    96 	ConstructExtLD(*parent,pos,size);
       
    97 	iWin.SetPointerGrab(ETrue);
       
    98 	iKey1=TRect(size.iWidth*1/16,size.iHeight/2,size.iWidth*5/16,size.iHeight);
       
    99 	iKey2=TRect(size.iWidth*6/16,size.iHeight/2,size.iWidth*10/16,size.iHeight);
       
   100 	iKey3=TRect(size.iWidth*11/16,size.iHeight/2,size.iWidth*15/16,size.iHeight);
       
   101 	iWin.AddKeyRect(iKey1,'A',EFalse);
       
   102 	iWin.AddKeyRect(iKey2,'B',EFalse);
       
   103 	AssignGC(*Client()->iGc);
       
   104 	BaseWin()->EnableOnEvents();
       
   105 	Activate();
       
   106 	}
       
   107 
       
   108 void CTPntKeyWindow::Error()
       
   109 	{
       
   110 	iTest->Failed();
       
   111 	}
       
   112 
       
   113 void CTPntKeyWindow::SetState(TInt iState)
       
   114 	{
       
   115 	iKeyCount=iState-1;
       
   116 	NextKey();
       
   117 	iTest->Client()->Flush();
       
   118 	}
       
   119 
       
   120 void CTPntKeyWindow::NextKey()
       
   121 	{
       
   122 	if (++iKeyCount==ENumPntKeyTests || iKeyCount>4)
       
   123 		iTest->FinishedTests();
       
   124 	else
       
   125 		{
       
   126 		if (iKeyCount==2)
       
   127 			iWin.RemoveAllKeyRects();
       
   128 		else if (iKeyCount==3)
       
   129 			iWin.AddKeyRect(iKey3,'C',EFalse);
       
   130 		else if (iKeyCount==4)
       
   131 			{
       
   132 	#if !defined(__WINS__)
       
   133 			if (iTest->NoDigitiser())
       
   134 				iTest->FinishedTests();
       
   135 	#endif
       
   136 			iWin.RemoveAllKeyRects();
       
   137 			iWin.AddKeyRect(TRect(Client()->iScreen->SizeInPixels()),'Z',EFalse);
       
   138 			}
       
   139 		else if (iKeyCount==5)
       
   140 			{
       
   141 			iWin.RemoveAllKeyRects();
       
   142 			Client()->iWs.Flush();
       
   143 			User::After(500000);	// Wait half a second
       
   144 			iWin.AddKeyRect(TRect(Client()->iScreen->SizeInPixels()),'Y',ETrue);
       
   145 			}
       
   146 		Invalidate();
       
   147 		}
       
   148 	}
       
   149 
       
   150 void CTPntKeyWindow::Test(TInt aCheck)
       
   151 	{
       
   152 	if (!aCheck)
       
   153 		Error();
       
   154 	}
       
   155 
       
   156 void CTPntKeyWindow::KeyUpL(const TKeyEvent &aKey,const TTime&)
       
   157 	{
       
   158 	if (aKey.iScanCode==iTestScanCodes[iKeyCount])
       
   159 		NextKey();
       
   160 	}
       
   161 
       
   162 void CTPntKeyWindow::KeyDownL(const TKeyEvent &aKey,const TTime &)
       
   163 	{
       
   164 	if (aKey.iScanCode!=EStdKeyLeftFunc && aKey.iScanCode!=EStdKeyRightFunc && 
       
   165 		 aKey.iScanCode!=EStdKeyLeftAlt && aKey.iScanCode!=EStdKeyRightAlt &&
       
   166 		 aKey.iScanCode!=EStdKeyLeftCtrl && aKey.iScanCode!=EStdKeyRightCtrl &&
       
   167 		 aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift && 
       
   168 		 aKey.iScanCode!=EStdKeyOff &&
       
   169 		 aKey.iScanCode!=EStdKeyEscape)
       
   170 		Test(aKey.iScanCode==iTestScanCodes[iKeyCount]);
       
   171 	}
       
   172 
       
   173 void CTPntKeyWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
       
   174 	{
       
   175 	if (aKey.iCode==EKeyEscape)
       
   176 		iTest->FinishedTests();
       
   177 	else
       
   178 		{
       
   179 		Test(aKey.iScanCode==iTestScanCodes[iKeyCount]);
       
   180 		Test(aKey.iCode==iTestCodes[iKeyCount]);
       
   181 		Test((aKey.iModifiers&EModifierMask)==(iTestModifiers[iKeyCount]&EModifierMask));
       
   182 		}
       
   183 	}
       
   184 
       
   185 void CTPntKeyWindow::SwitchOn(const TTime &)
       
   186 	{
       
   187 	if (iKeyCount==4)
       
   188 		NextKey();
       
   189 	else if (iKeyCount!=5)
       
   190 		Error();
       
   191 	}
       
   192 
       
   193 void CTPntKeyWindow::PointerL(const TPointerEvent &aPointer,const TTime &)
       
   194 	{
       
   195 	if (aPointer.iType==TPointerEvent::EButton1Down)
       
   196 		{
       
   197 		if (iKeyCount!=2)
       
   198 			Error();
       
   199 		else
       
   200 			NextKey();
       
   201 		}
       
   202 	}
       
   203 
       
   204 void CTPntKeyWindow::DrawButton(const TRect &aRect, const TDesC &aText)
       
   205 	{
       
   206 	iGc->DrawRect(aRect);
       
   207 	iGc->DrawText(aText, TPoint((aRect.iBr.iX+aRect.iTl.iX)/2,(aRect.iBr.iY+aRect.iTl.iY)/2));
       
   208 	}
       
   209 
       
   210 void CTPntKeyWindow::Draw()
       
   211 	{
       
   212 	iGc->SetBrushColor(TRgb::Gray4(0));
       
   213 	iGc->SetPenColor(TRgb::Gray4(3));
       
   214 	iGc->Clear();
       
   215 	DrawButton(iKey1,_L("A"));
       
   216 	DrawButton(iKey2,_L("B"));
       
   217 	DrawButton(iKey3,_L("C"));
       
   218 	switch(iKeyCount)
       
   219 		{
       
   220 		case 0:
       
   221 			iGc->DrawText(_L("Click on 'A'"), TPoint(10,20));
       
   222 			break;
       
   223 		case 1:
       
   224 			iGc->DrawText(_L("Shift-Click on 'B'"), TPoint(10,20));
       
   225 			break;
       
   226 		case 2:
       
   227 			iGc->DrawText(_L("Click anywhere in this window"), TPoint(10,20));
       
   228 			break;
       
   229 		case 3:
       
   230 			iGc->DrawText(_L("Click on 'C'"), TPoint(10,20));
       
   231 			break;
       
   232 		case 4:
       
   233 #if defined(__WINS__)	// Can't emulate touching dig when switched off under WINS
       
   234 			iGc->DrawText(_L("Switch off and on (or press Enter)"), TPoint(10,20));
       
   235 #else
       
   236 			iGc->DrawText(_L("1st Switch off, then touch the screen to switch on"), TPoint(10,20));
       
   237 #endif
       
   238 			break;
       
   239 		case 5:
       
   240 #if defined(__WINS__)	// Can't emulate touching dig when switched off under WINS
       
   241 			iGc->DrawText(_L("Touch anywhere in the window"), TPoint(10,20));
       
   242 #else
       
   243 			iGc->DrawText(_L("2nd Switch off and touch the screen to switch on"), TPoint(10,20));
       
   244 #endif
       
   245 			break;
       
   246 		}
       
   247 	}
       
   248 
       
   249 CTPntKeyTest::CTPntKeyTest() : CTestBase(_L("Pointer Key Test"))
       
   250 	{}
       
   251 
       
   252 CTPntKeyTest::~CTPntKeyTest()
       
   253 	{
       
   254 	HAL::Set(HALData::EPenDisplayOn,iOldPointerState);
       
   255 	CTWin::Delete(iWin);
       
   256 	Client()->ResetFocus();
       
   257 	}
       
   258 
       
   259 void CTPntKeyTest::Failed()
       
   260 	{
       
   261 	if (!iFailed)
       
   262 		{
       
   263 		iFailed=ETrue;
       
   264 		FinishedTests();
       
   265 		}
       
   266 	}
       
   267 
       
   268 void CTPntKeyTest::FinishedTests()
       
   269 	{
       
   270 	Request();
       
   271 	}
       
   272 
       
   273 void CTPntKeyTest::ConstructL()
       
   274 	{
       
   275 	CTPntKeyWindow *win=new(ELeave) CTPntKeyWindow(this);
       
   276 	win->SetUpLD(TPoint(20,20),Client()->iScreen->SizeInPixels()-TSize(40,40),Client()->iGroup);
       
   277 	iWin=win;
       
   278 	Client()->iGroup->SetCurrentWindow(iWin);
       
   279 	iNoDigitiser=EFalse;
       
   280 	TInt err=HAL::Get(HALData::EPenDisplayOn,iOldPointerState);
       
   281 	if (err==KErrNotSupported)
       
   282 		iNoDigitiser=ETrue;
       
   283 	else if (err==KErrNone)
       
   284 		err=HAL::Set(HALData::EPenDisplayOn,ETrue);
       
   285 	if (err==KErrNotSupported)
       
   286 		iNoDigitiser=(!iOldPointerState);
       
   287 	else
       
   288 		TestL(err==KErrNone);
       
   289 	}
       
   290 
       
   291 TestState CTPntKeyTest::DoTestL()
       
   292 	{
       
   293 	TestL(!iFailed);
       
   294 	switch(iState)
       
   295 		{
       
   296 		case 0:
       
   297 			LogSubTest(_L("Key set 1"),1);
       
   298 			iWin->SetState(4);
       
   299 			iState++;
       
   300 			return(EContinue);
       
   301 		default:
       
   302 			return(EFinished);
       
   303 		}
       
   304 //	return(ENext);
       
   305 	}