os/graphics/windowing/windowserver/test/tman/TMPNTBUF.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tman/TMPNTBUF.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,283 @@
     1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Test Pointer move/drag buffer
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include "W32STD.H"
    1.23 +#include "../tlib/testbase.h"
    1.24 +#include "TMAN.H"
    1.25 +
    1.26 +class CTPntBufTest;
    1.27 +
    1.28 +class CPntBufWindow : public CTBackedUpWin
    1.29 +	{
    1.30 +private:
    1.31 +	enum {KPointerMoveBufferSize=32};
    1.32 +public:
    1.33 +	CPntBufWindow(CTPntBufTest *aTest);
    1.34 +	~CPntBufWindow();
    1.35 +	void SetUpLD(TPoint pos,TSize size,CTWinBase *parent);
    1.36 +	void PointerBufferReady(const TTime &aTime);
    1.37 +	void PointerL(const TPointerEvent &pointer,const TTime &aTime);
    1.38 +	void SetUpState();
    1.39 +	void NextTest();
    1.40 +	void WinKeyL(const TKeyEvent &aKey,const TTime &aTime);
    1.41 +	void ErrorL();
    1.42 +private:
    1.43 +	//Virtual functions from CTWinBase
    1.44 +	void PointerEnter(const TTime&);
    1.45 +	void PointerExit(const TTime&);
    1.46 +private:
    1.47 +	CTPntBufTest *iTest;
    1.48 +	TBool iDragging;
    1.49 +	TBool iErrorNest;
    1.50 +	TBool iDisabled;
    1.51 +	TBool iDiscard;
    1.52 +	TInt iMode;
    1.53 +	TBool iIgnorNextPoint;
    1.54 +	};
    1.55 +
    1.56 +class CTPntBufTest : public CTestBase
    1.57 +	{
    1.58 +public:
    1.59 +	CTPntBufTest();
    1.60 +	~CTPntBufTest();
    1.61 +	TestState DoTestL();
    1.62 +	void FinishedTests();
    1.63 +	void ConstructL();
    1.64 +private:
    1.65 +	CPntBufWindow *iWin;
    1.66 +	TSize iWinSize;
    1.67 +	TInt iState;
    1.68 +	};
    1.69 +
    1.70 +GLDEF_C CTestBase *CreatePointerBufferTest()
    1.71 +	{
    1.72 +	return(new(ELeave) CTPntBufTest());
    1.73 +	}
    1.74 +
    1.75 +CPntBufWindow::CPntBufWindow(CTPntBufTest *aTest) : CTBackedUpWin(EGray4), iTest(aTest)
    1.76 +	{}
    1.77 +
    1.78 +CPntBufWindow::~CPntBufWindow()
    1.79 +	{
    1.80 +	delete iGc;
    1.81 +	}
    1.82 +
    1.83 +void CPntBufWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent)
    1.84 +	{
    1.85 +	ConstructExtLD(*parent,pos,size);
    1.86 +	User::LeaveIfError(iWin.AllocPointerMoveBuffer(KPointerMoveBufferSize,0));
    1.87 +	iWin.SetPointerGrab(ETrue);
    1.88 +	iWin.PointerFilter(EPointerFilterEnterExit,0);
    1.89 +	Activate();
    1.90 +	User::LeaveIfError(Client()->iScreen->CreateContext(iGc));
    1.91 +	iGc->Activate(iWin);
    1.92 +	SetUpState();
    1.93 +	}
    1.94 +
    1.95 +void CPntBufWindow::PointerBufferReady(const TTime &)
    1.96 +	{
    1.97 +	if (iDiscard)
    1.98 +		iWin.DiscardPointerMoveBuffer();
    1.99 +	iGc->SetPenColor(iDragging ? TRgb::Gray4(0) : TRgb::Gray4(1));
   1.100 +	iGc->SetPenSize(iDragging ? TSize(2,2) : TSize(1,1));
   1.101 +	TPoint pnts[KPointerMoveBufferSize];
   1.102 +	TPtr8 ptr((TUint8 *)&pnts,sizeof(pnts));
   1.103 +	TInt numPnts=iWin.RetrievePointerMoveBuffer(ptr);
   1.104 +	TInt index=0;
   1.105 +	if (iIgnorNextPoint)
   1.106 +		{
   1.107 +		iGc->MoveTo(pnts[index]);
   1.108 +		index=1;
   1.109 +		iIgnorNextPoint=EFalse;
   1.110 +		}
   1.111 +	for(;index<numPnts;index++)
   1.112 +		iGc->DrawLineTo(pnts[index]);
   1.113 +	}
   1.114 +
   1.115 +void CPntBufWindow::ErrorL()
   1.116 +	{
   1.117 +	if (!iErrorNest)
   1.118 +		{
   1.119 +		iErrorNest=ETrue;
   1.120 +		iTest->TestL(EFalse);
   1.121 +		}
   1.122 +	}
   1.123 +
   1.124 +void CPntBufWindow::PointerL(const TPointerEvent &pointer,const TTime &)
   1.125 +	{
   1.126 +	switch(pointer.iType)
   1.127 +		{
   1.128 +		case TPointerEvent::EButton1Down:
   1.129 +			iDragging=ETrue;
   1.130 +			iGc->MoveTo(pointer.iPosition);
   1.131 +			if (iMode==2)
   1.132 +				{
   1.133 +				if (pointer.iModifiers&EModifierShift)
   1.134 +					{
   1.135 +					iDisabled=ETrue;
   1.136 +					iWin.DisablePointerMoveBuffer();
   1.137 +					}
   1.138 +				else if (pointer.iModifiers&EModifierCtrl)
   1.139 +					iDiscard=ETrue;
   1.140 +				}
   1.141 +			break;
   1.142 +		case TPointerEvent::EButton1Up:
   1.143 +			if (iDisabled)
   1.144 +				{
   1.145 +				iDisabled=EFalse;
   1.146 +				iWin.EnablePointerMoveBuffer();
   1.147 +				}
   1.148 +			iDiscard=EFalse;
   1.149 +			iGc->MoveTo(pointer.iPosition);
   1.150 +			iDragging=EFalse;
   1.151 +			break;
   1.152 +		case TPointerEvent::EDrag:
   1.153 +			if (iDragging && !iDisabled)
   1.154 +				ErrorL();
   1.155 +			break;
   1.156 +		case TPointerEvent::EMove:
   1.157 +			if (iDragging && !iDisabled)
   1.158 +				ErrorL();
   1.159 +			break;
   1.160 +		default:;
   1.161 +		}
   1.162 +	}
   1.163 +
   1.164 +void CPntBufWindow::SetUpState()
   1.165 +	{
   1.166 +
   1.167 +	iGc->Reset();
   1.168 +	iGc->UseFont((CFont *)iFont);
   1.169 +	iGc->Clear();
   1.170 +	switch(iMode)
   1.171 +		{
   1.172 +		case 0:
   1.173 +			iWin.PointerFilter(EPointerFilterMove,EPointerFilterMove);
   1.174 +			iGc->DrawText(_L("Drag the pointer around the window and check"), TPoint(10,20));
   1.175 +			iGc->DrawText(_L("a line is drawn following the pointer when"), TPoint(10,40));
   1.176 +			iGc->DrawText(_L("dragging but not when moving"), TPoint(10,60));
   1.177 +			iGc->DrawText(_L("Press <Space> when checked"), TPoint(10,90));
   1.178 +			break;
   1.179 +		case 1:
   1.180 +			iWin.PointerFilter(EPointerFilterMove|EPointerFilterDrag,EPointerFilterDrag);
   1.181 +			iGc->DrawText(_L("If pointer moves are supported move the pointer around the "), TPoint(10,20));
   1.182 +			iGc->DrawText(_L("window and check a line is drawn following the pointer"), TPoint(10,40));
   1.183 +			iGc->DrawText(_L("when it is up, and no lines are drawn when dragging"), TPoint(10,60));
   1.184 +			iGc->DrawText(_L("Press <Esc> if moves not supported or <Space> when checked"), TPoint(10,90));
   1.185 +			break;
   1.186 +		case 2:
   1.187 +			iWin.PointerFilter(EPointerFilterMove|EPointerFilterDrag,0);
   1.188 +			iGc->DrawText(_L("Drag and move the pointer around the window and check a"), TPoint(10,20));
   1.189 +			iGc->DrawText(_L("line is drawn following the pointer during both dragging and"), TPoint(10,40));
   1.190 +			iGc->DrawText(_L("moving, also check drag with the shift or control key down doesn't draw"), TPoint(10,60));
   1.191 +			iGc->DrawText(_L("Press <Space> when checked"), TPoint(10,90));
   1.192 +			break;
   1.193 +		}
   1.194 +	}
   1.195 +
   1.196 +void CPntBufWindow::NextTest()
   1.197 +	{
   1.198 +	if (iMode++==2)
   1.199 +		iTest->FinishedTests();
   1.200 +	else
   1.201 +		SetUpState();
   1.202 +	}
   1.203 +
   1.204 +void CPntBufWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
   1.205 +	{
   1.206 +	switch(aKey.iCode)
   1.207 +		{
   1.208 +		case ' ':
   1.209 +			NextTest();
   1.210 +			break;
   1.211 +		case EKeyEscape:
   1.212 +			iTest->FinishedTests();
   1.213 +			break;
   1.214 +		case '0':
   1.215 +			SetUpState();
   1.216 +			break;
   1.217 +		case '1':
   1.218 +		case '2':
   1.219 +		case '3':
   1.220 +			{
   1.221 +			TInt mode=aKey.iCode-'1';
   1.222 +			if (mode!=iMode)
   1.223 +				{
   1.224 +				iMode=mode;
   1.225 +				SetUpState();
   1.226 +				}
   1.227 +			}
   1.228 +			break;
   1.229 +		}
   1.230 +	}
   1.231 +
   1.232 +void CPntBufWindow::PointerEnter(const TTime&)
   1.233 +	{
   1.234 +	if (iMode==0)
   1.235 +		iDragging=ETrue;
   1.236 +	else if (iMode==1)
   1.237 +		iDragging=EFalse;
   1.238 +	iIgnorNextPoint=ETrue;
   1.239 +	}
   1.240 +
   1.241 +void CPntBufWindow::PointerExit(const TTime&)
   1.242 +	{}
   1.243 +
   1.244 +
   1.245 +/*CTPntBufTest*/
   1.246 +
   1.247 +CTPntBufTest::CTPntBufTest() : CTestBase(_L("Scale"))
   1.248 +	{}
   1.249 +
   1.250 +CTPntBufTest::~CTPntBufTest()
   1.251 +	{
   1.252 +#if defined(__WINS__)
   1.253 +	Client()->iWs.SimulateXyInputType(EXYInputPointer);
   1.254 +#endif
   1.255 +	CTWin::Delete(iWin);
   1.256 +	}
   1.257 +
   1.258 +void CTPntBufTest::FinishedTests()
   1.259 +	{
   1.260 +	Request();
   1.261 +	}
   1.262 +
   1.263 +void CTPntBufTest::ConstructL()
   1.264 +	{
   1.265 +	CPntBufWindow *win=new(ELeave) CPntBufWindow(this);
   1.266 +	win->SetUpLD(TPoint(0,0),Client()->iScreen->SizeInPixels(),Client()->iGroup);
   1.267 +	iWin=win;
   1.268 +	Client()->iGroup->SetCurrentWindow(iWin);
   1.269 +#if defined(__WINS__)
   1.270 +	Client()->iWs.SimulateXyInputType(EXYInputMouse);
   1.271 +#endif
   1.272 +	}
   1.273 +
   1.274 +TestState CTPntBufTest::DoTestL()
   1.275 +	{
   1.276 +	switch(iState)
   1.277 +		{
   1.278 +		case 0:
   1.279 +			LogSubTest(_L("Scale 1"),1);
   1.280 +			iState++;
   1.281 +			return(EContinue);
   1.282 +		default:
   1.283 +			return(EFinished);
   1.284 +		}
   1.285 +//	return(ENext);
   1.286 +	}