os/graphics/windowing/windowserver/test/tman/TMSCRMOD.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/TMSCRMOD.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,226 @@
     1.4 +// Copyright (c) 1998-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 +// Screen mode changing tests
    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 CScreenModeTest;
    1.27 +
    1.28 +class CScreenModeWindow : public CTWin
    1.29 +	{
    1.30 +public:
    1.31 +	CScreenModeWindow();
    1.32 +	void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
    1.33 +	void WinKeyL(const TKeyEvent &aKey,const TTime &aTime);
    1.34 +	void Draw();
    1.35 +	void ScreenDeviceChanged();
    1.36 +private:
    1.37 +	TInt iSubState;
    1.38 +	};
    1.39 +
    1.40 +class CScreenModeGroup : public CTWindowGroup
    1.41 +	{
    1.42 +public:
    1.43 +	~CScreenModeGroup();
    1.44 +	CScreenModeGroup(CTClient *aClient);
    1.45 +	void ConstructL();
    1.46 +	void ScreenDeviceChanged();
    1.47 +private:
    1.48 +	CScreenModeWindow *iWindow;
    1.49 +	};
    1.50 +
    1.51 +class CScreenModeTest : public CTestBase
    1.52 +	{
    1.53 +public:
    1.54 +	CScreenModeTest();
    1.55 +	~CScreenModeTest();
    1.56 +	TestState DoTestL();
    1.57 +	void ConstructL();
    1.58 +private:
    1.59 +	CScreenModeGroup *iScreenModeGroup;
    1.60 +	TSize iWinSize;
    1.61 +	TInt iState;
    1.62 +	};
    1.63 +
    1.64 +GLDEF_C CTestBase *CreateScreenModeTest()
    1.65 +	{
    1.66 +	return(new(ELeave) CScreenModeTest());
    1.67 +	}
    1.68 +
    1.69 +//
    1.70 +// CScreenModeWindow
    1.71 +//
    1.72 +
    1.73 +CScreenModeWindow::CScreenModeWindow() : CTWin()
    1.74 +	{}
    1.75 +
    1.76 +void CScreenModeWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
    1.77 +	{
    1.78 +	if (aKey.iCode==EKeyEscape || aKey.iCode==EKeyEnter)
    1.79 +		{
    1.80 +		if (iSubState==0)
    1.81 +			{
    1.82 +			iSubState=1;
    1.83 +			ScreenDeviceChanged();
    1.84 +			Invalidate();
    1.85 +			}
    1.86 +		else
    1.87 +			CActiveScheduler::Stop();
    1.88 +		}
    1.89 +	}
    1.90 +
    1.91 +void CScreenModeWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
    1.92 +	{
    1.93 +	ConstructExtLD(*parent,pos,size);
    1.94 +	Activate();
    1.95 +	AssignGC(aGc);
    1.96 +	}
    1.97 +
    1.98 +void CScreenModeWindow::Draw()
    1.99 +	{
   1.100 +	iGc->Clear();
   1.101 +	TSize winSize(Win()->Size());
   1.102 +	iGc->DrawRect(winSize);
   1.103 +	iGc->DrawLine(TPoint(0,0),TPoint(winSize.iWidth,winSize.iHeight));
   1.104 +	iGc->DrawLine(TPoint(0,winSize.iHeight),TPoint(winSize.iWidth,0));
   1.105 +	TInt xpos=winSize.iWidth/2-100;
   1.106 +	iGc->DrawText(iSubState==0?_L("Twips not adjusted,"):
   1.107 +								_L("Twips adjusted,"),TPoint(xpos,20));
   1.108 +	iGc->DrawText(_L("Cycle through all screen modes,"),TPoint(xpos,40));
   1.109 +	iGc->DrawText(_L("Check the window is resized and rotated correctly,"),TPoint(xpos,60));
   1.110 +	iGc->DrawText(_L("Then press <Enter> when finished"),TPoint(xpos,80));
   1.111 +//
   1.112 +	TSize twips=Client()->iScreen->SizeInTwips();
   1.113 +	TSize pixels=Client()->iScreen->SizeInPixels();
   1.114 +// Horizontal line
   1.115 +	TInt inches=twips.iWidth/KTwipsPerInch-1;
   1.116 +	TInt lineLen=Client()->iScreen->HorizontalTwipsToPixels(inches*KTwipsPerInch);
   1.117 +	TPoint linePos=TPoint((pixels.iWidth-lineLen)/2,pixels.iHeight/2);
   1.118 +	iGc->DrawLine(linePos,linePos+TPoint(lineLen,0));
   1.119 +	TBuf<0x20> buf;
   1.120 +	buf.Format(TRefByValue<const TDesC>(_L("Width %d\"")),inches);
   1.121 +	iGc->DrawText(buf,TPoint((pixels.iWidth-iFont->TextWidthInPixels(buf))/2,linePos.iY-iFont->HeightInPixels()+iFont->AscentInPixels()-2));
   1.122 +	TInt index;
   1.123 +	for(index=0;index<=inches;index++)
   1.124 +		{
   1.125 +		TInt dx=Client()->iScreen->HorizontalTwipsToPixels(index*KTwipsPerInch);
   1.126 +		TInt dy=Client()->iScreen->VerticalTwipsToPixels(KTwipsPerInch/(index==0 || index==inches ? 8 : 16));
   1.127 +		iGc->DrawLine(linePos+TPoint(dx,1), linePos+TPoint(dx,dy));
   1.128 +		}
   1.129 +// Vertical line
   1.130 +	inches=twips.iHeight/KTwipsPerInch;
   1.131 +	lineLen=Client()->iScreen->VerticalTwipsToPixels(inches*KTwipsPerInch);
   1.132 +	linePos.iY=(pixels.iHeight-lineLen)/2;
   1.133 +	iGc->DrawLine(linePos,linePos+TPoint(0,lineLen));
   1.134 +	buf.Format(TRefByValue<const TDesC>(_L("Height %d\"")),inches);
   1.135 +	iGc->DrawText(buf,TPoint(linePos.iX+10, pixels.iHeight/4));
   1.136 +	for(index=0;index<=inches;index++)
   1.137 +		{
   1.138 +		TInt dx=Client()->iScreen->HorizontalTwipsToPixels(KTwipsPerInch/(index==0 || index==inches ? 8 : 16));
   1.139 +		TInt dy=Client()->iScreen->VerticalTwipsToPixels(index*KTwipsPerInch);
   1.140 +		iGc->DrawLine(linePos+TPoint(1,dy), linePos+TPoint(dx,dy));
   1.141 +		}
   1.142 +
   1.143 +	}
   1.144 +
   1.145 +void CScreenModeWindow::ScreenDeviceChanged()
   1.146 +	{
   1.147 +	if (iSubState==0)
   1.148 +		{
   1.149 +		TPixelsAndRotation sizeAndRotation;
   1.150 +		Client()->iScreen->GetDefaultScreenSizeAndRotation(sizeAndRotation);
   1.151 +		Client()->iScreen->SetScreenSizeAndRotation(sizeAndRotation);
   1.152 +		}
   1.153 +	else
   1.154 +		{
   1.155 +		TPixelsTwipsAndRotation sizeAndRotation;
   1.156 +		Client()->iScreen->GetDefaultScreenSizeAndRotation(sizeAndRotation);
   1.157 +		Client()->iScreen->SetScreenSizeAndRotation(sizeAndRotation);
   1.158 +		}
   1.159 +	SetSize(Client()->iScreen->SizeInPixels());
   1.160 +	}
   1.161 +
   1.162 +//
   1.163 +// CScreenModeGroup
   1.164 +//
   1.165 +
   1.166 +CScreenModeGroup::~CScreenModeGroup()
   1.167 +	{
   1.168 +	GroupWin()->EnableReceiptOfFocus(EFalse);
   1.169 +	ClearCurrentWindow();
   1.170 +	Client()->iGroup->SetCurrentWindow(NULL);
   1.171 +	CTWin::Delete(iWindow);
   1.172 +	}
   1.173 +
   1.174 +CScreenModeGroup::CScreenModeGroup(CTClient *aClient) : CTWindowGroup(aClient)
   1.175 +	{}
   1.176 +
   1.177 +void CScreenModeGroup::ConstructL()
   1.178 +	{
   1.179 +	CTWindowGroup::ConstructL();
   1.180 +	iWindow=new(ELeave) CScreenModeWindow;
   1.181 +	iWindow->SetUpLD(TPoint(0,0),Client()->iScreen->SizeInPixels(),this,*Client()->iGc);
   1.182 +	SetCurrentWindow(iWindow);
   1.183 +	GroupWin()->EnableScreenChangeEvents();
   1.184 +	GroupWin()->SetOrdinalPosition(0);
   1.185 +	}
   1.186 +
   1.187 +void CScreenModeGroup::ScreenDeviceChanged()
   1.188 +	{
   1.189 +	iWindow->ScreenDeviceChanged();
   1.190 +	}
   1.191 +
   1.192 +//
   1.193 +// CScreenModeTest
   1.194 +//
   1.195 +
   1.196 +CScreenModeTest::CScreenModeTest() : CTestBase(_L("Screen mode"))
   1.197 +	{}
   1.198 +
   1.199 +CScreenModeTest::~CScreenModeTest()
   1.200 +	{
   1.201 +	Client()->iGroup->GroupWin()->EnableScreenChangeEvents();
   1.202 +	Client()->iScreen->SetScreenMode(0);
   1.203 +	delete iScreenModeGroup;
   1.204 +	}
   1.205 +
   1.206 +void CScreenModeTest::ConstructL()
   1.207 +	{
   1.208 +	Client()->iGroup->GroupWin()->SetOrdinalPosition(0);
   1.209 +	Client()->iGroup->GroupWin()->DisableScreenChangeEvents();
   1.210 +//
   1.211 +	iScreenModeGroup=new(ELeave) CScreenModeGroup(Client());
   1.212 +	iScreenModeGroup->ConstructL();
   1.213 +	}
   1.214 +
   1.215 +TestState CScreenModeTest::DoTestL()
   1.216 +	{
   1.217 +	switch(iState)
   1.218 +		{
   1.219 +		case 0:
   1.220 +			LogSubTest(_L("Screen mode 1"),1);
   1.221 + 			CActiveScheduler::Start();
   1.222 +			iState++;
   1.223 +			break;
   1.224 +		default:
   1.225 +			return(EFinished);
   1.226 +		}
   1.227 +	return(ENext);
   1.228 +	}
   1.229 +