sl@0: // Copyright (c) 1995-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 multiple connections to the window server sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "W32STD.H" sl@0: #include "../tlib/testbase.h" sl@0: #include "TMAN.H" sl@0: sl@0: const TInt EMaxSubState=3; sl@0: sl@0: class CMcWindowBase; sl@0: class TMultiConTest; sl@0: sl@0: class CMcConnectionBase : public CTClient sl@0: { sl@0: public: sl@0: CMcConnectionBase(TMultiConTest *aTest); sl@0: ~CMcConnectionBase(); sl@0: virtual void ConstructL(); sl@0: void SubStateChanged(); sl@0: protected: sl@0: TMultiConTest *iTest; sl@0: CMcWindowBase *iWin; sl@0: CWindowGc *iGc; sl@0: }; sl@0: sl@0: class CMcConnection : public CMcConnectionBase // Sets AutoForeground off sl@0: { sl@0: public: sl@0: CMcConnection(TMultiConTest *aTest); sl@0: void ConstructL(); sl@0: }; sl@0: sl@0: class CMcWindowGroupAf : public CTWindowGroup sl@0: { sl@0: public: sl@0: CMcWindowGroupAf(CTClient *aClient); sl@0: void KeyL(const TKeyEvent &aKey, const TTime &aTime); sl@0: }; sl@0: sl@0: class CMcConnectionAf : public CMcConnectionBase // Sets AutoForeground on sl@0: { sl@0: public: sl@0: CMcConnectionAf(TMultiConTest *aTest); sl@0: void ConstructL(); sl@0: void KeyL(const TKeyEvent &aKey); sl@0: }; sl@0: sl@0: class CMcConnectionDef : public CMcConnectionBase // Leaves AutoForeground as the default value sl@0: { sl@0: public: sl@0: CMcConnectionDef(TMultiConTest *aTest); sl@0: void ConstructL(); sl@0: }; sl@0: sl@0: class CMcWindowBase : public CTWin sl@0: { sl@0: public: sl@0: CMcWindowBase(TMultiConTest *aTest); sl@0: void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc); sl@0: virtual void Draw()=0; sl@0: virtual void PointerL(const TPointerEvent &pointer,const TTime &)=0; sl@0: protected: sl@0: TMultiConTest *iTest; sl@0: TRgb iBack; sl@0: }; sl@0: sl@0: class CMcWindow : public CMcWindowBase sl@0: { sl@0: public: sl@0: CMcWindow(TMultiConTest *aTest); sl@0: virtual void Draw(); sl@0: virtual void PointerL(const TPointerEvent &pointer,const TTime &); sl@0: }; sl@0: sl@0: class CMcWindowAf : public CMcWindowBase sl@0: { sl@0: public: sl@0: CMcWindowAf(TMultiConTest *aTest); sl@0: virtual void Draw(); sl@0: virtual void PointerL(const TPointerEvent &pointer,const TTime &); sl@0: void ConstructL(); sl@0: }; sl@0: sl@0: class CMcWindowDef : public CMcWindowBase sl@0: { sl@0: public: sl@0: CMcWindowDef(TMultiConTest *aTest); sl@0: virtual void Draw(); sl@0: virtual void PointerL(const TPointerEvent &pointer,const TTime &); sl@0: }; sl@0: sl@0: class TMultiConTest : public CTestBase sl@0: { sl@0: public: sl@0: TMultiConTest(); sl@0: ~TMultiConTest(); sl@0: TestState DoTestL(); sl@0: void ConstructL(); sl@0: void EndAutoForegroundTest(); sl@0: TInt SubState() const; sl@0: void IncSubState(); sl@0: private: sl@0: CMcConnectionAf *iConn1; sl@0: CMcConnection *iConn2; sl@0: CMcConnectionDef *iConn3; sl@0: TSize iWinSize; sl@0: TInt iState; sl@0: TInt iSubState; sl@0: }; sl@0: sl@0: GLDEF_C CTestBase *CreateMultiConTest() sl@0: { sl@0: return(new(ELeave) TMultiConTest()); sl@0: } sl@0: sl@0: TMultiConTest::TMultiConTest() : CTestBase(_L("MultiCon")) sl@0: {} sl@0: sl@0: TMultiConTest::~TMultiConTest() sl@0: { sl@0: delete iConn1; sl@0: delete iConn2; sl@0: delete iConn3; sl@0: } sl@0: sl@0: void TMultiConTest::EndAutoForegroundTest() sl@0: { sl@0: iConn1->iGroup->GroupWin()->EnableReceiptOfFocus(EFalse); sl@0: iConn2->iGroup->GroupWin()->EnableReceiptOfFocus(EFalse); sl@0: iConn3->iGroup->GroupWin()->EnableReceiptOfFocus(EFalse); sl@0: Request(); sl@0: } sl@0: sl@0: void TMultiConTest::ConstructL() sl@0: { sl@0: iConn3=new(ELeave) CMcConnectionDef(this); sl@0: iConn3->ConstructL(); sl@0: iConn2=new(ELeave) CMcConnection(this); sl@0: iConn2->ConstructL(); sl@0: iConn1=new(ELeave) CMcConnectionAf(this); sl@0: iConn1->ConstructL(); sl@0: } sl@0: sl@0: // sl@0: // CMcConnection sl@0: sl@0: CMcConnectionBase::CMcConnectionBase(TMultiConTest *aTest) : iTest(aTest) sl@0: { sl@0: } sl@0: sl@0: CMcConnectionBase::~CMcConnectionBase() sl@0: { sl@0: CTWin::Delete(iWin); sl@0: delete iGc; sl@0: } sl@0: sl@0: void CMcConnectionBase::SubStateChanged() sl@0: { sl@0: iWin->Invalidate(); sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: void CMcConnectionBase::ConstructL() sl@0: { sl@0: CTClient::ConstructL(); sl@0: User::LeaveIfError(iScreen->CreateContext(iGc)); sl@0: } sl@0: sl@0: CMcConnection::CMcConnection(TMultiConTest *aTest) : CMcConnectionBase(aTest) sl@0: { sl@0: } sl@0: sl@0: void CMcConnection::ConstructL() sl@0: { sl@0: CMcConnectionBase::ConstructL(); sl@0: iGroup=new(ELeave) CTWindowGroup(this); sl@0: iGroup->ConstructL(); sl@0: TSize screenSize=iGroup->Size(); sl@0: TInt winWidth=screenSize.iWidth/3; sl@0: TInt winHeight=screenSize.iHeight/2-10; sl@0: iGroup->GroupWin()->AutoForeground(EFalse); sl@0: CMcWindow *win=new(ELeave) CMcWindow(iTest); sl@0: win->SetUpL(TPoint(5,5),TSize(winWidth,winHeight),iGroup,*iGc); sl@0: iWin=win; sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: CMcConnectionAf::CMcConnectionAf(TMultiConTest *aTest) : CMcConnectionBase(aTest) sl@0: { sl@0: } sl@0: sl@0: void CMcConnectionAf::ConstructL() sl@0: { sl@0: CMcConnectionBase::ConstructL(); sl@0: iGroup=new(ELeave) CMcWindowGroupAf(this); sl@0: iGroup->ConstructL(); sl@0: TSize screenSize=iGroup->Size(); sl@0: TInt winWidth=screenSize.iWidth/3; sl@0: TInt winHeight=screenSize.iHeight/2-10; sl@0: iGroup->GroupWin()->AutoForeground(ETrue); sl@0: CMcWindowAf *win=new(ELeave) CMcWindowAf(iTest); sl@0: win->SetUpL(TPoint(winWidth,5),TSize(winWidth,winHeight),iGroup,*iGc); sl@0: iWin=win; sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: void CMcConnectionAf::KeyL(const TKeyEvent &aKey) sl@0: { sl@0: switch(aKey.iCode) sl@0: { sl@0: case ' ': sl@0: if (iTest->SubState()==0) sl@0: { sl@0: iTest->TestL(iGroup->GroupWin()->OrdinalPosition()==0); sl@0: iTest->IncSubState(); sl@0: } sl@0: break; sl@0: case EKeyEscape: sl@0: iTest->EndAutoForegroundTest(); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: CMcConnectionDef::CMcConnectionDef(TMultiConTest *aTest) : CMcConnectionBase(aTest) sl@0: { sl@0: } sl@0: sl@0: void CMcConnectionDef::ConstructL() sl@0: { sl@0: CMcConnectionBase::ConstructL(); sl@0: iGroup=new(ELeave) CTWindowGroup(this); sl@0: iGroup->ConstructL(); sl@0: iGroup->GroupWin()->EnableReceiptOfFocus(EFalse); sl@0: TSize screenSize=iGroup->Size(); sl@0: TInt winWidth=screenSize.iWidth/3-10; sl@0: TInt winHeight=(screenSize.iHeight/2)-10; sl@0: CMcWindowDef *win=new(ELeave) CMcWindowDef(iTest); sl@0: win->SetUpL(TPoint(5+winWidth/2,screenSize.iHeight/2),TSize(winWidth,winHeight),iGroup,*iGc); sl@0: iWin=win; sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: // sl@0: // CMcWindow, base class // sl@0: // sl@0: sl@0: CMcWindowBase::CMcWindowBase(TMultiConTest *aTest) : CTWin(), iTest(aTest) sl@0: { sl@0: } sl@0: sl@0: void CMcWindowBase::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc) sl@0: { sl@0: ConstructExtLD(*parent,pos,size); sl@0: iWin.SetBackgroundColor(iBack); sl@0: Activate(); sl@0: AssignGC(aGc); sl@0: } sl@0: sl@0: // sl@0: // CMcWindow, window used to test multiple connections // sl@0: // sl@0: sl@0: CMcWindow::CMcWindow(TMultiConTest *aTest) : CMcWindowBase(aTest) sl@0: { sl@0: iBack=TRgb::Gray256(221); sl@0: } sl@0: sl@0: void CMcWindow::PointerL(const TPointerEvent &pointer,const TTime &) sl@0: { sl@0: if (pointer.iType==TPointerEvent::EButton1Down) sl@0: { sl@0: switch(iTest->SubState()) sl@0: { sl@0: case 1: sl@0: iTest->TestL(Client()->iGroup->GroupWin()->OrdinalPosition()==1); sl@0: iTest->IncSubState(); sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CMcWindow::Draw() sl@0: { sl@0: iGc->Clear(); sl@0: TBuf<0x40> buf; sl@0: switch(iTest->SubState()) sl@0: { sl@0: case 1: sl@0: buf.Copy(_L("Click on me")); sl@0: break; sl@0: case 0: sl@0: case 2: sl@0: case 3: sl@0: buf.Copy(_L("")); sl@0: break; sl@0: default: sl@0: buf.Copy(_L("ERROR")); sl@0: } sl@0: iGc->DrawText(buf, TPoint(10,20)); sl@0: } sl@0: sl@0: // sl@0: // CMcWindowAf, Auto foreground version of CMcWindow // sl@0: // sl@0: sl@0: CMcWindowAf::CMcWindowAf(TMultiConTest *aTest) : CMcWindowBase(aTest) sl@0: { sl@0: iBack=TRgb::Gray256(150); sl@0: } sl@0: sl@0: void CMcWindowAf::PointerL(const TPointerEvent &pointer,const TTime &) sl@0: { sl@0: if (pointer.iType==TPointerEvent::EButton1Down) sl@0: { sl@0: switch(iTest->SubState()) sl@0: { sl@0: case 2: sl@0: iTest->TestL(Client()->iGroup->GroupWin()->OrdinalPosition()==0); sl@0: iTest->IncSubState(); sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CMcWindowAf::Draw() sl@0: { sl@0: iGc->Clear(); sl@0: TBuf<0x40> buf; sl@0: switch(iTest->SubState()) sl@0: { sl@0: case 1: sl@0: case 3: sl@0: break; sl@0: case 0: sl@0: buf.Copy(_L("Press ")); sl@0: break; sl@0: case 2: sl@0: buf.Copy(_L("Click on me")); sl@0: break; sl@0: default: sl@0: buf.Copy(_L("ERROR")); sl@0: } sl@0: iGc->DrawText(buf, TPoint(10,20)); sl@0: } sl@0: sl@0: // sl@0: sl@0: CMcWindowGroupAf::CMcWindowGroupAf(CTClient *aClient) : CTWindowGroup(aClient) sl@0: {} sl@0: sl@0: void CMcWindowGroupAf::KeyL(const TKeyEvent &aKey, const TTime &) sl@0: { sl@0: ((CMcConnectionAf *)iClient)->KeyL(aKey); sl@0: } sl@0: sl@0: // sl@0: // CMcWindowDef, Default auto foreground version of CMcWindow // sl@0: // sl@0: sl@0: CMcWindowDef::CMcWindowDef(TMultiConTest *aTest) : CMcWindowBase(aTest) sl@0: { sl@0: iBack=TRgb::Gray256(236); sl@0: } sl@0: sl@0: void CMcWindowDef::PointerL(const TPointerEvent &pointer,const TTime &) sl@0: { sl@0: if (pointer.iType==TPointerEvent::EButton1Down) sl@0: { sl@0: switch(iTest->SubState()) sl@0: { sl@0: case 3: sl@0: iTest->TestL(Client()->iGroup->GroupWin()->OrdinalPosition()==0); sl@0: iTest->IncSubState(); sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CMcWindowDef::Draw() sl@0: { sl@0: iGc->Clear(); sl@0: TBuf<0x40> buf; sl@0: switch(iTest->SubState()) sl@0: { sl@0: case 0: sl@0: case 1: sl@0: case 2: sl@0: break; sl@0: case 3: sl@0: buf.Copy(_L("Click on me")); sl@0: break; sl@0: default: sl@0: buf.Copy(_L("ERROR")); sl@0: } sl@0: iGc->DrawText(buf, TPoint(10,20)); sl@0: } sl@0: sl@0: // sl@0: sl@0: TInt TMultiConTest::SubState() const sl@0: { sl@0: return(iSubState); sl@0: } sl@0: sl@0: void TMultiConTest::IncSubState() sl@0: { sl@0: if (iSubState==EMaxSubState) sl@0: EndAutoForegroundTest(); sl@0: else sl@0: { sl@0: iSubState++; sl@0: iConn1->SubStateChanged(); sl@0: iConn2->SubStateChanged(); sl@0: iConn3->SubStateChanged(); sl@0: } sl@0: } sl@0: sl@0: TestState TMultiConTest::DoTestL() sl@0: { sl@0: switch(iState) sl@0: { sl@0: case 0: sl@0: LogSubTest(_L("MultiCon 1"),1); sl@0: iState++; sl@0: return(EContinue); sl@0: default: sl@0: return(EFinished); sl@0: } sl@0: // return(ENext); sl@0: }