windowing/windowserver/test/tman/TMPNTBUF.CPP
changeset 103 2717213c588a
parent 0 5d03bc08d59c
equal deleted inserted replaced
98:bf7481649c98 103:2717213c588a
       
     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 "W32STD.H"
       
    20 #include "../tlib/testbase.h"
       
    21 #include "TMAN.H"
       
    22 
       
    23 class CTPntBufTest;
       
    24 
       
    25 class CPntBufWindow : public CTBackedUpWin
       
    26 	{
       
    27 private:
       
    28 	enum {KPointerMoveBufferSize=32};
       
    29 public:
       
    30 	CPntBufWindow(CTPntBufTest *aTest);
       
    31 	~CPntBufWindow();
       
    32 	void SetUpLD(TPoint pos,TSize size,CTWinBase *parent);
       
    33 	void PointerBufferReady(const TTime &aTime);
       
    34 	void PointerL(const TPointerEvent &pointer,const TTime &aTime);
       
    35 	void SetUpState();
       
    36 	void NextTest();
       
    37 	void WinKeyL(const TKeyEvent &aKey,const TTime &aTime);
       
    38 	void ErrorL();
       
    39 private:
       
    40 	//Virtual functions from CTWinBase
       
    41 	void PointerEnter(const TTime&);
       
    42 	void PointerExit(const TTime&);
       
    43 private:
       
    44 	CTPntBufTest *iTest;
       
    45 	TBool iDragging;
       
    46 	TBool iErrorNest;
       
    47 	TBool iDisabled;
       
    48 	TBool iDiscard;
       
    49 	TInt iMode;
       
    50 	TBool iIgnorNextPoint;
       
    51 	};
       
    52 
       
    53 class CTPntBufTest : public CTestBase
       
    54 	{
       
    55 public:
       
    56 	CTPntBufTest();
       
    57 	~CTPntBufTest();
       
    58 	TestState DoTestL();
       
    59 	void FinishedTests();
       
    60 	void ConstructL();
       
    61 private:
       
    62 	CPntBufWindow *iWin;
       
    63 	TSize iWinSize;
       
    64 	TInt iState;
       
    65 	};
       
    66 
       
    67 GLDEF_C CTestBase *CreatePointerBufferTest()
       
    68 	{
       
    69 	return(new(ELeave) CTPntBufTest());
       
    70 	}
       
    71 
       
    72 CPntBufWindow::CPntBufWindow(CTPntBufTest *aTest) : CTBackedUpWin(EGray4), iTest(aTest)
       
    73 	{}
       
    74 
       
    75 CPntBufWindow::~CPntBufWindow()
       
    76 	{
       
    77 	delete iGc;
       
    78 	}
       
    79 
       
    80 void CPntBufWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent)
       
    81 	{
       
    82 	ConstructExtLD(*parent,pos,size);
       
    83 	User::LeaveIfError(iWin.AllocPointerMoveBuffer(KPointerMoveBufferSize,0));
       
    84 	iWin.SetPointerGrab(ETrue);
       
    85 	iWin.PointerFilter(EPointerFilterEnterExit,0);
       
    86 	Activate();
       
    87 	User::LeaveIfError(Client()->iScreen->CreateContext(iGc));
       
    88 	iGc->Activate(iWin);
       
    89 	SetUpState();
       
    90 	}
       
    91 
       
    92 void CPntBufWindow::PointerBufferReady(const TTime &)
       
    93 	{
       
    94 	if (iDiscard)
       
    95 		iWin.DiscardPointerMoveBuffer();
       
    96 	iGc->SetPenColor(iDragging ? TRgb::Gray4(0) : TRgb::Gray4(1));
       
    97 	iGc->SetPenSize(iDragging ? TSize(2,2) : TSize(1,1));
       
    98 	TPoint pnts[KPointerMoveBufferSize];
       
    99 	TPtr8 ptr((TUint8 *)&pnts,sizeof(pnts));
       
   100 	TInt numPnts=iWin.RetrievePointerMoveBuffer(ptr);
       
   101 	TInt index=0;
       
   102 	if (iIgnorNextPoint)
       
   103 		{
       
   104 		iGc->MoveTo(pnts[index]);
       
   105 		index=1;
       
   106 		iIgnorNextPoint=EFalse;
       
   107 		}
       
   108 	for(;index<numPnts;index++)
       
   109 		iGc->DrawLineTo(pnts[index]);
       
   110 	}
       
   111 
       
   112 void CPntBufWindow::ErrorL()
       
   113 	{
       
   114 	if (!iErrorNest)
       
   115 		{
       
   116 		iErrorNest=ETrue;
       
   117 		iTest->TestL(EFalse);
       
   118 		}
       
   119 	}
       
   120 
       
   121 void CPntBufWindow::PointerL(const TPointerEvent &pointer,const TTime &)
       
   122 	{
       
   123 	switch(pointer.iType)
       
   124 		{
       
   125 		case TPointerEvent::EButton1Down:
       
   126 			iDragging=ETrue;
       
   127 			iGc->MoveTo(pointer.iPosition);
       
   128 			if (iMode==2)
       
   129 				{
       
   130 				if (pointer.iModifiers&EModifierShift)
       
   131 					{
       
   132 					iDisabled=ETrue;
       
   133 					iWin.DisablePointerMoveBuffer();
       
   134 					}
       
   135 				else if (pointer.iModifiers&EModifierCtrl)
       
   136 					iDiscard=ETrue;
       
   137 				}
       
   138 			break;
       
   139 		case TPointerEvent::EButton1Up:
       
   140 			if (iDisabled)
       
   141 				{
       
   142 				iDisabled=EFalse;
       
   143 				iWin.EnablePointerMoveBuffer();
       
   144 				}
       
   145 			iDiscard=EFalse;
       
   146 			iGc->MoveTo(pointer.iPosition);
       
   147 			iDragging=EFalse;
       
   148 			break;
       
   149 		case TPointerEvent::EDrag:
       
   150 			if (iDragging && !iDisabled)
       
   151 				ErrorL();
       
   152 			break;
       
   153 		case TPointerEvent::EMove:
       
   154 			if (iDragging && !iDisabled)
       
   155 				ErrorL();
       
   156 			break;
       
   157 		default:;
       
   158 		}
       
   159 	}
       
   160 
       
   161 void CPntBufWindow::SetUpState()
       
   162 	{
       
   163 
       
   164 	iGc->Reset();
       
   165 	iGc->UseFont((CFont *)iFont);
       
   166 	iGc->Clear();
       
   167 	switch(iMode)
       
   168 		{
       
   169 		case 0:
       
   170 			iWin.PointerFilter(EPointerFilterMove,EPointerFilterMove);
       
   171 			iGc->DrawText(_L("Drag the pointer around the window and check"), TPoint(10,20));
       
   172 			iGc->DrawText(_L("a line is drawn following the pointer when"), TPoint(10,40));
       
   173 			iGc->DrawText(_L("dragging but not when moving"), TPoint(10,60));
       
   174 			iGc->DrawText(_L("Press <Space> when checked"), TPoint(10,90));
       
   175 			break;
       
   176 		case 1:
       
   177 			iWin.PointerFilter(EPointerFilterMove|EPointerFilterDrag,EPointerFilterDrag);
       
   178 			iGc->DrawText(_L("If pointer moves are supported move the pointer around the "), TPoint(10,20));
       
   179 			iGc->DrawText(_L("window and check a line is drawn following the pointer"), TPoint(10,40));
       
   180 			iGc->DrawText(_L("when it is up, and no lines are drawn when dragging"), TPoint(10,60));
       
   181 			iGc->DrawText(_L("Press <Esc> if moves not supported or <Space> when checked"), TPoint(10,90));
       
   182 			break;
       
   183 		case 2:
       
   184 			iWin.PointerFilter(EPointerFilterMove|EPointerFilterDrag,0);
       
   185 			iGc->DrawText(_L("Drag and move the pointer around the window and check a"), TPoint(10,20));
       
   186 			iGc->DrawText(_L("line is drawn following the pointer during both dragging and"), TPoint(10,40));
       
   187 			iGc->DrawText(_L("moving, also check drag with the shift or control key down doesn't draw"), TPoint(10,60));
       
   188 			iGc->DrawText(_L("Press <Space> when checked"), TPoint(10,90));
       
   189 			break;
       
   190 		}
       
   191 	}
       
   192 
       
   193 void CPntBufWindow::NextTest()
       
   194 	{
       
   195 	if (iMode++==2)
       
   196 		iTest->FinishedTests();
       
   197 	else
       
   198 		SetUpState();
       
   199 	}
       
   200 
       
   201 void CPntBufWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
       
   202 	{
       
   203 	switch(aKey.iCode)
       
   204 		{
       
   205 		case ' ':
       
   206 			NextTest();
       
   207 			break;
       
   208 		case EKeyEscape:
       
   209 			iTest->FinishedTests();
       
   210 			break;
       
   211 		case '0':
       
   212 			SetUpState();
       
   213 			break;
       
   214 		case '1':
       
   215 		case '2':
       
   216 		case '3':
       
   217 			{
       
   218 			TInt mode=aKey.iCode-'1';
       
   219 			if (mode!=iMode)
       
   220 				{
       
   221 				iMode=mode;
       
   222 				SetUpState();
       
   223 				}
       
   224 			}
       
   225 			break;
       
   226 		}
       
   227 	}
       
   228 
       
   229 void CPntBufWindow::PointerEnter(const TTime&)
       
   230 	{
       
   231 	if (iMode==0)
       
   232 		iDragging=ETrue;
       
   233 	else if (iMode==1)
       
   234 		iDragging=EFalse;
       
   235 	iIgnorNextPoint=ETrue;
       
   236 	}
       
   237 
       
   238 void CPntBufWindow::PointerExit(const TTime&)
       
   239 	{}
       
   240 
       
   241 
       
   242 /*CTPntBufTest*/
       
   243 
       
   244 CTPntBufTest::CTPntBufTest() : CTestBase(_L("Scale"))
       
   245 	{}
       
   246 
       
   247 CTPntBufTest::~CTPntBufTest()
       
   248 	{
       
   249 #if defined(__WINS__)
       
   250 	Client()->iWs.SimulateXyInputType(EXYInputPointer);
       
   251 #endif
       
   252 	CTWin::Delete(iWin);
       
   253 	}
       
   254 
       
   255 void CTPntBufTest::FinishedTests()
       
   256 	{
       
   257 	Request();
       
   258 	}
       
   259 
       
   260 void CTPntBufTest::ConstructL()
       
   261 	{
       
   262 	CPntBufWindow *win=new(ELeave) CPntBufWindow(this);
       
   263 	win->SetUpLD(TPoint(0,0),Client()->iScreen->SizeInPixels(),Client()->iGroup);
       
   264 	iWin=win;
       
   265 	Client()->iGroup->SetCurrentWindow(iWin);
       
   266 #if defined(__WINS__)
       
   267 	Client()->iWs.SimulateXyInputType(EXYInputMouse);
       
   268 #endif
       
   269 	}
       
   270 
       
   271 TestState CTPntBufTest::DoTestL()
       
   272 	{
       
   273 	switch(iState)
       
   274 		{
       
   275 		case 0:
       
   276 			LogSubTest(_L("Scale 1"),1);
       
   277 			iState++;
       
   278 			return(EContinue);
       
   279 		default:
       
   280 			return(EFinished);
       
   281 		}
       
   282 //	return(ENext);
       
   283 	}