sl@0: // Copyright (c) 1998-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: // Screen mode changing tests 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 CScreenModeTest; sl@0: sl@0: class CScreenModeWindow : public CTWin sl@0: { sl@0: public: sl@0: CScreenModeWindow(); sl@0: void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc); sl@0: void WinKeyL(const TKeyEvent &aKey,const TTime &aTime); sl@0: void Draw(); sl@0: void ScreenDeviceChanged(); sl@0: private: sl@0: TInt iSubState; sl@0: }; sl@0: sl@0: class CScreenModeGroup : public CTWindowGroup sl@0: { sl@0: public: sl@0: ~CScreenModeGroup(); sl@0: CScreenModeGroup(CTClient *aClient); sl@0: void ConstructL(); sl@0: void ScreenDeviceChanged(); sl@0: private: sl@0: CScreenModeWindow *iWindow; sl@0: }; sl@0: sl@0: class CScreenModeTest : public CTestBase sl@0: { sl@0: public: sl@0: CScreenModeTest(); sl@0: ~CScreenModeTest(); sl@0: TestState DoTestL(); sl@0: void ConstructL(); sl@0: private: sl@0: CScreenModeGroup *iScreenModeGroup; sl@0: TSize iWinSize; sl@0: TInt iState; sl@0: }; sl@0: sl@0: GLDEF_C CTestBase *CreateScreenModeTest() sl@0: { sl@0: return(new(ELeave) CScreenModeTest()); sl@0: } sl@0: sl@0: // sl@0: // CScreenModeWindow sl@0: // sl@0: sl@0: CScreenModeWindow::CScreenModeWindow() : CTWin() sl@0: {} sl@0: sl@0: void CScreenModeWindow::WinKeyL(const TKeyEvent &aKey,const TTime &) sl@0: { sl@0: if (aKey.iCode==EKeyEscape || aKey.iCode==EKeyEnter) sl@0: { sl@0: if (iSubState==0) sl@0: { sl@0: iSubState=1; sl@0: ScreenDeviceChanged(); sl@0: Invalidate(); sl@0: } sl@0: else sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: } sl@0: sl@0: void CScreenModeWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc) sl@0: { sl@0: ConstructExtLD(*parent,pos,size); sl@0: Activate(); sl@0: AssignGC(aGc); sl@0: } sl@0: sl@0: void CScreenModeWindow::Draw() sl@0: { sl@0: iGc->Clear(); sl@0: TSize winSize(Win()->Size()); sl@0: iGc->DrawRect(winSize); sl@0: iGc->DrawLine(TPoint(0,0),TPoint(winSize.iWidth,winSize.iHeight)); sl@0: iGc->DrawLine(TPoint(0,winSize.iHeight),TPoint(winSize.iWidth,0)); sl@0: TInt xpos=winSize.iWidth/2-100; sl@0: iGc->DrawText(iSubState==0?_L("Twips not adjusted,"): sl@0: _L("Twips adjusted,"),TPoint(xpos,20)); sl@0: iGc->DrawText(_L("Cycle through all screen modes,"),TPoint(xpos,40)); sl@0: iGc->DrawText(_L("Check the window is resized and rotated correctly,"),TPoint(xpos,60)); sl@0: iGc->DrawText(_L("Then press when finished"),TPoint(xpos,80)); sl@0: // sl@0: TSize twips=Client()->iScreen->SizeInTwips(); sl@0: TSize pixels=Client()->iScreen->SizeInPixels(); sl@0: // Horizontal line sl@0: TInt inches=twips.iWidth/KTwipsPerInch-1; sl@0: TInt lineLen=Client()->iScreen->HorizontalTwipsToPixels(inches*KTwipsPerInch); sl@0: TPoint linePos=TPoint((pixels.iWidth-lineLen)/2,pixels.iHeight/2); sl@0: iGc->DrawLine(linePos,linePos+TPoint(lineLen,0)); sl@0: TBuf<0x20> buf; sl@0: buf.Format(TRefByValue(_L("Width %d\"")),inches); sl@0: iGc->DrawText(buf,TPoint((pixels.iWidth-iFont->TextWidthInPixels(buf))/2,linePos.iY-iFont->HeightInPixels()+iFont->AscentInPixels()-2)); sl@0: TInt index; sl@0: for(index=0;index<=inches;index++) sl@0: { sl@0: TInt dx=Client()->iScreen->HorizontalTwipsToPixels(index*KTwipsPerInch); sl@0: TInt dy=Client()->iScreen->VerticalTwipsToPixels(KTwipsPerInch/(index==0 || index==inches ? 8 : 16)); sl@0: iGc->DrawLine(linePos+TPoint(dx,1), linePos+TPoint(dx,dy)); sl@0: } sl@0: // Vertical line sl@0: inches=twips.iHeight/KTwipsPerInch; sl@0: lineLen=Client()->iScreen->VerticalTwipsToPixels(inches*KTwipsPerInch); sl@0: linePos.iY=(pixels.iHeight-lineLen)/2; sl@0: iGc->DrawLine(linePos,linePos+TPoint(0,lineLen)); sl@0: buf.Format(TRefByValue(_L("Height %d\"")),inches); sl@0: iGc->DrawText(buf,TPoint(linePos.iX+10, pixels.iHeight/4)); sl@0: for(index=0;index<=inches;index++) sl@0: { sl@0: TInt dx=Client()->iScreen->HorizontalTwipsToPixels(KTwipsPerInch/(index==0 || index==inches ? 8 : 16)); sl@0: TInt dy=Client()->iScreen->VerticalTwipsToPixels(index*KTwipsPerInch); sl@0: iGc->DrawLine(linePos+TPoint(1,dy), linePos+TPoint(dx,dy)); sl@0: } sl@0: sl@0: } sl@0: sl@0: void CScreenModeWindow::ScreenDeviceChanged() sl@0: { sl@0: if (iSubState==0) sl@0: { sl@0: TPixelsAndRotation sizeAndRotation; sl@0: Client()->iScreen->GetDefaultScreenSizeAndRotation(sizeAndRotation); sl@0: Client()->iScreen->SetScreenSizeAndRotation(sizeAndRotation); sl@0: } sl@0: else sl@0: { sl@0: TPixelsTwipsAndRotation sizeAndRotation; sl@0: Client()->iScreen->GetDefaultScreenSizeAndRotation(sizeAndRotation); sl@0: Client()->iScreen->SetScreenSizeAndRotation(sizeAndRotation); sl@0: } sl@0: SetSize(Client()->iScreen->SizeInPixels()); sl@0: } sl@0: sl@0: // sl@0: // CScreenModeGroup sl@0: // sl@0: sl@0: CScreenModeGroup::~CScreenModeGroup() sl@0: { sl@0: GroupWin()->EnableReceiptOfFocus(EFalse); sl@0: ClearCurrentWindow(); sl@0: Client()->iGroup->SetCurrentWindow(NULL); sl@0: CTWin::Delete(iWindow); sl@0: } sl@0: sl@0: CScreenModeGroup::CScreenModeGroup(CTClient *aClient) : CTWindowGroup(aClient) sl@0: {} sl@0: sl@0: void CScreenModeGroup::ConstructL() sl@0: { sl@0: CTWindowGroup::ConstructL(); sl@0: iWindow=new(ELeave) CScreenModeWindow; sl@0: iWindow->SetUpLD(TPoint(0,0),Client()->iScreen->SizeInPixels(),this,*Client()->iGc); sl@0: SetCurrentWindow(iWindow); sl@0: GroupWin()->EnableScreenChangeEvents(); sl@0: GroupWin()->SetOrdinalPosition(0); sl@0: } sl@0: sl@0: void CScreenModeGroup::ScreenDeviceChanged() sl@0: { sl@0: iWindow->ScreenDeviceChanged(); sl@0: } sl@0: sl@0: // sl@0: // CScreenModeTest sl@0: // sl@0: sl@0: CScreenModeTest::CScreenModeTest() : CTestBase(_L("Screen mode")) sl@0: {} sl@0: sl@0: CScreenModeTest::~CScreenModeTest() sl@0: { sl@0: Client()->iGroup->GroupWin()->EnableScreenChangeEvents(); sl@0: Client()->iScreen->SetScreenMode(0); sl@0: delete iScreenModeGroup; sl@0: } sl@0: sl@0: void CScreenModeTest::ConstructL() sl@0: { sl@0: Client()->iGroup->GroupWin()->SetOrdinalPosition(0); sl@0: Client()->iGroup->GroupWin()->DisableScreenChangeEvents(); sl@0: // sl@0: iScreenModeGroup=new(ELeave) CScreenModeGroup(Client()); sl@0: iScreenModeGroup->ConstructL(); sl@0: } sl@0: sl@0: TestState CScreenModeTest::DoTestL() sl@0: { sl@0: switch(iState) sl@0: { sl@0: case 0: sl@0: LogSubTest(_L("Screen mode 1"),1); sl@0: CActiveScheduler::Start(); sl@0: iState++; sl@0: break; sl@0: default: sl@0: return(EFinished); sl@0: } sl@0: return(ENext); sl@0: } sl@0: