sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Test Pointer move/drag buffer sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "W32STD.H" sl@0: #include "../tlib/testbase.h" sl@0: #include "TMAN.H" sl@0: sl@0: class CTPntBufTest; sl@0: sl@0: class CPntBufWindow : public CTBackedUpWin sl@0: { sl@0: private: sl@0: enum {KPointerMoveBufferSize=32}; sl@0: public: sl@0: CPntBufWindow(CTPntBufTest *aTest); sl@0: ~CPntBufWindow(); sl@0: void SetUpLD(TPoint pos,TSize size,CTWinBase *parent); sl@0: void PointerBufferReady(const TTime &aTime); sl@0: void PointerL(const TPointerEvent &pointer,const TTime &aTime); sl@0: void SetUpState(); sl@0: void NextTest(); sl@0: void WinKeyL(const TKeyEvent &aKey,const TTime &aTime); sl@0: void ErrorL(); sl@0: private: sl@0: //Virtual functions from CTWinBase sl@0: void PointerEnter(const TTime&); sl@0: void PointerExit(const TTime&); sl@0: private: sl@0: CTPntBufTest *iTest; sl@0: TBool iDragging; sl@0: TBool iErrorNest; sl@0: TBool iDisabled; sl@0: TBool iDiscard; sl@0: TInt iMode; sl@0: TBool iIgnorNextPoint; sl@0: }; sl@0: sl@0: class CTPntBufTest : public CTestBase sl@0: { sl@0: public: sl@0: CTPntBufTest(); sl@0: ~CTPntBufTest(); sl@0: TestState DoTestL(); sl@0: void FinishedTests(); sl@0: void ConstructL(); sl@0: private: sl@0: CPntBufWindow *iWin; sl@0: TSize iWinSize; sl@0: TInt iState; sl@0: }; sl@0: sl@0: GLDEF_C CTestBase *CreatePointerBufferTest() sl@0: { sl@0: return(new(ELeave) CTPntBufTest()); sl@0: } sl@0: sl@0: CPntBufWindow::CPntBufWindow(CTPntBufTest *aTest) : CTBackedUpWin(EGray4), iTest(aTest) sl@0: {} sl@0: sl@0: CPntBufWindow::~CPntBufWindow() sl@0: { sl@0: delete iGc; sl@0: } sl@0: sl@0: void CPntBufWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent) sl@0: { sl@0: ConstructExtLD(*parent,pos,size); sl@0: User::LeaveIfError(iWin.AllocPointerMoveBuffer(KPointerMoveBufferSize,0)); sl@0: iWin.SetPointerGrab(ETrue); sl@0: iWin.PointerFilter(EPointerFilterEnterExit,0); sl@0: Activate(); sl@0: User::LeaveIfError(Client()->iScreen->CreateContext(iGc)); sl@0: iGc->Activate(iWin); sl@0: SetUpState(); sl@0: } sl@0: sl@0: void CPntBufWindow::PointerBufferReady(const TTime &) sl@0: { sl@0: if (iDiscard) sl@0: iWin.DiscardPointerMoveBuffer(); sl@0: iGc->SetPenColor(iDragging ? TRgb::Gray4(0) : TRgb::Gray4(1)); sl@0: iGc->SetPenSize(iDragging ? TSize(2,2) : TSize(1,1)); sl@0: TPoint pnts[KPointerMoveBufferSize]; sl@0: TPtr8 ptr((TUint8 *)&pnts,sizeof(pnts)); sl@0: TInt numPnts=iWin.RetrievePointerMoveBuffer(ptr); sl@0: TInt index=0; sl@0: if (iIgnorNextPoint) sl@0: { sl@0: iGc->MoveTo(pnts[index]); sl@0: index=1; sl@0: iIgnorNextPoint=EFalse; sl@0: } sl@0: for(;indexDrawLineTo(pnts[index]); sl@0: } sl@0: sl@0: void CPntBufWindow::ErrorL() sl@0: { sl@0: if (!iErrorNest) sl@0: { sl@0: iErrorNest=ETrue; sl@0: iTest->TestL(EFalse); sl@0: } sl@0: } sl@0: sl@0: void CPntBufWindow::PointerL(const TPointerEvent &pointer,const TTime &) sl@0: { sl@0: switch(pointer.iType) sl@0: { sl@0: case TPointerEvent::EButton1Down: sl@0: iDragging=ETrue; sl@0: iGc->MoveTo(pointer.iPosition); sl@0: if (iMode==2) sl@0: { sl@0: if (pointer.iModifiers&EModifierShift) sl@0: { sl@0: iDisabled=ETrue; sl@0: iWin.DisablePointerMoveBuffer(); sl@0: } sl@0: else if (pointer.iModifiers&EModifierCtrl) sl@0: iDiscard=ETrue; sl@0: } sl@0: break; sl@0: case TPointerEvent::EButton1Up: sl@0: if (iDisabled) sl@0: { sl@0: iDisabled=EFalse; sl@0: iWin.EnablePointerMoveBuffer(); sl@0: } sl@0: iDiscard=EFalse; sl@0: iGc->MoveTo(pointer.iPosition); sl@0: iDragging=EFalse; sl@0: break; sl@0: case TPointerEvent::EDrag: sl@0: if (iDragging && !iDisabled) sl@0: ErrorL(); sl@0: break; sl@0: case TPointerEvent::EMove: sl@0: if (iDragging && !iDisabled) sl@0: ErrorL(); sl@0: break; sl@0: default:; sl@0: } sl@0: } sl@0: sl@0: void CPntBufWindow::SetUpState() sl@0: { sl@0: sl@0: iGc->Reset(); sl@0: iGc->UseFont((CFont *)iFont); sl@0: iGc->Clear(); sl@0: switch(iMode) sl@0: { sl@0: case 0: sl@0: iWin.PointerFilter(EPointerFilterMove,EPointerFilterMove); sl@0: iGc->DrawText(_L("Drag the pointer around the window and check"), TPoint(10,20)); sl@0: iGc->DrawText(_L("a line is drawn following the pointer when"), TPoint(10,40)); sl@0: iGc->DrawText(_L("dragging but not when moving"), TPoint(10,60)); sl@0: iGc->DrawText(_L("Press when checked"), TPoint(10,90)); sl@0: break; sl@0: case 1: sl@0: iWin.PointerFilter(EPointerFilterMove|EPointerFilterDrag,EPointerFilterDrag); sl@0: iGc->DrawText(_L("If pointer moves are supported move the pointer around the "), TPoint(10,20)); sl@0: iGc->DrawText(_L("window and check a line is drawn following the pointer"), TPoint(10,40)); sl@0: iGc->DrawText(_L("when it is up, and no lines are drawn when dragging"), TPoint(10,60)); sl@0: iGc->DrawText(_L("Press if moves not supported or when checked"), TPoint(10,90)); sl@0: break; sl@0: case 2: sl@0: iWin.PointerFilter(EPointerFilterMove|EPointerFilterDrag,0); sl@0: iGc->DrawText(_L("Drag and move the pointer around the window and check a"), TPoint(10,20)); sl@0: iGc->DrawText(_L("line is drawn following the pointer during both dragging and"), TPoint(10,40)); sl@0: iGc->DrawText(_L("moving, also check drag with the shift or control key down doesn't draw"), TPoint(10,60)); sl@0: iGc->DrawText(_L("Press when checked"), TPoint(10,90)); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CPntBufWindow::NextTest() sl@0: { sl@0: if (iMode++==2) sl@0: iTest->FinishedTests(); sl@0: else sl@0: SetUpState(); sl@0: } sl@0: sl@0: void CPntBufWindow::WinKeyL(const TKeyEvent &aKey,const TTime &) sl@0: { sl@0: switch(aKey.iCode) sl@0: { sl@0: case ' ': sl@0: NextTest(); sl@0: break; sl@0: case EKeyEscape: sl@0: iTest->FinishedTests(); sl@0: break; sl@0: case '0': sl@0: SetUpState(); sl@0: break; sl@0: case '1': sl@0: case '2': sl@0: case '3': sl@0: { sl@0: TInt mode=aKey.iCode-'1'; sl@0: if (mode!=iMode) sl@0: { sl@0: iMode=mode; sl@0: SetUpState(); sl@0: } sl@0: } sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CPntBufWindow::PointerEnter(const TTime&) sl@0: { sl@0: if (iMode==0) sl@0: iDragging=ETrue; sl@0: else if (iMode==1) sl@0: iDragging=EFalse; sl@0: iIgnorNextPoint=ETrue; sl@0: } sl@0: sl@0: void CPntBufWindow::PointerExit(const TTime&) sl@0: {} sl@0: sl@0: sl@0: /*CTPntBufTest*/ sl@0: sl@0: CTPntBufTest::CTPntBufTest() : CTestBase(_L("Scale")) sl@0: {} sl@0: sl@0: CTPntBufTest::~CTPntBufTest() sl@0: { sl@0: #if defined(__WINS__) sl@0: Client()->iWs.SimulateXyInputType(EXYInputPointer); sl@0: #endif sl@0: CTWin::Delete(iWin); sl@0: } sl@0: sl@0: void CTPntBufTest::FinishedTests() sl@0: { sl@0: Request(); sl@0: } sl@0: sl@0: void CTPntBufTest::ConstructL() sl@0: { sl@0: CPntBufWindow *win=new(ELeave) CPntBufWindow(this); sl@0: win->SetUpLD(TPoint(0,0),Client()->iScreen->SizeInPixels(),Client()->iGroup); sl@0: iWin=win; sl@0: Client()->iGroup->SetCurrentWindow(iWin); sl@0: #if defined(__WINS__) sl@0: Client()->iWs.SimulateXyInputType(EXYInputMouse); sl@0: #endif sl@0: } sl@0: sl@0: TestState CTPntBufTest::DoTestL() sl@0: { sl@0: switch(iState) sl@0: { sl@0: case 0: sl@0: LogSubTest(_L("Scale 1"),1); sl@0: iState++; sl@0: return(EContinue); sl@0: default: sl@0: return(EFinished); sl@0: } sl@0: // return(ENext); sl@0: }