|
1 // Copyright (c) 1998-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 // Screen mode changing tests |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include "W32STD.H" |
|
20 #include "../tlib/testbase.h" |
|
21 #include "TMAN.H" |
|
22 |
|
23 class CScreenModeTest; |
|
24 |
|
25 class CScreenModeWindow : public CTWin |
|
26 { |
|
27 public: |
|
28 CScreenModeWindow(); |
|
29 void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc); |
|
30 void WinKeyL(const TKeyEvent &aKey,const TTime &aTime); |
|
31 void Draw(); |
|
32 void ScreenDeviceChanged(); |
|
33 private: |
|
34 TInt iSubState; |
|
35 }; |
|
36 |
|
37 class CScreenModeGroup : public CTWindowGroup |
|
38 { |
|
39 public: |
|
40 ~CScreenModeGroup(); |
|
41 CScreenModeGroup(CTClient *aClient); |
|
42 void ConstructL(); |
|
43 void ScreenDeviceChanged(); |
|
44 private: |
|
45 CScreenModeWindow *iWindow; |
|
46 }; |
|
47 |
|
48 class CScreenModeTest : public CTestBase |
|
49 { |
|
50 public: |
|
51 CScreenModeTest(); |
|
52 ~CScreenModeTest(); |
|
53 TestState DoTestL(); |
|
54 void ConstructL(); |
|
55 private: |
|
56 CScreenModeGroup *iScreenModeGroup; |
|
57 TSize iWinSize; |
|
58 TInt iState; |
|
59 }; |
|
60 |
|
61 GLDEF_C CTestBase *CreateScreenModeTest() |
|
62 { |
|
63 return(new(ELeave) CScreenModeTest()); |
|
64 } |
|
65 |
|
66 // |
|
67 // CScreenModeWindow |
|
68 // |
|
69 |
|
70 CScreenModeWindow::CScreenModeWindow() : CTWin() |
|
71 {} |
|
72 |
|
73 void CScreenModeWindow::WinKeyL(const TKeyEvent &aKey,const TTime &) |
|
74 { |
|
75 if (aKey.iCode==EKeyEscape || aKey.iCode==EKeyEnter) |
|
76 { |
|
77 if (iSubState==0) |
|
78 { |
|
79 iSubState=1; |
|
80 ScreenDeviceChanged(); |
|
81 Invalidate(); |
|
82 } |
|
83 else |
|
84 CActiveScheduler::Stop(); |
|
85 } |
|
86 } |
|
87 |
|
88 void CScreenModeWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc) |
|
89 { |
|
90 ConstructExtLD(*parent,pos,size); |
|
91 Activate(); |
|
92 AssignGC(aGc); |
|
93 } |
|
94 |
|
95 void CScreenModeWindow::Draw() |
|
96 { |
|
97 iGc->Clear(); |
|
98 TSize winSize(Win()->Size()); |
|
99 iGc->DrawRect(winSize); |
|
100 iGc->DrawLine(TPoint(0,0),TPoint(winSize.iWidth,winSize.iHeight)); |
|
101 iGc->DrawLine(TPoint(0,winSize.iHeight),TPoint(winSize.iWidth,0)); |
|
102 TInt xpos=winSize.iWidth/2-100; |
|
103 iGc->DrawText(iSubState==0?_L("Twips not adjusted,"): |
|
104 _L("Twips adjusted,"),TPoint(xpos,20)); |
|
105 iGc->DrawText(_L("Cycle through all screen modes,"),TPoint(xpos,40)); |
|
106 iGc->DrawText(_L("Check the window is resized and rotated correctly,"),TPoint(xpos,60)); |
|
107 iGc->DrawText(_L("Then press <Enter> when finished"),TPoint(xpos,80)); |
|
108 // |
|
109 TSize twips=Client()->iScreen->SizeInTwips(); |
|
110 TSize pixels=Client()->iScreen->SizeInPixels(); |
|
111 // Horizontal line |
|
112 TInt inches=twips.iWidth/KTwipsPerInch-1; |
|
113 TInt lineLen=Client()->iScreen->HorizontalTwipsToPixels(inches*KTwipsPerInch); |
|
114 TPoint linePos=TPoint((pixels.iWidth-lineLen)/2,pixels.iHeight/2); |
|
115 iGc->DrawLine(linePos,linePos+TPoint(lineLen,0)); |
|
116 TBuf<0x20> buf; |
|
117 buf.Format(TRefByValue<const TDesC>(_L("Width %d\"")),inches); |
|
118 iGc->DrawText(buf,TPoint((pixels.iWidth-iFont->TextWidthInPixels(buf))/2,linePos.iY-iFont->HeightInPixels()+iFont->AscentInPixels()-2)); |
|
119 TInt index; |
|
120 for(index=0;index<=inches;index++) |
|
121 { |
|
122 TInt dx=Client()->iScreen->HorizontalTwipsToPixels(index*KTwipsPerInch); |
|
123 TInt dy=Client()->iScreen->VerticalTwipsToPixels(KTwipsPerInch/(index==0 || index==inches ? 8 : 16)); |
|
124 iGc->DrawLine(linePos+TPoint(dx,1), linePos+TPoint(dx,dy)); |
|
125 } |
|
126 // Vertical line |
|
127 inches=twips.iHeight/KTwipsPerInch; |
|
128 lineLen=Client()->iScreen->VerticalTwipsToPixels(inches*KTwipsPerInch); |
|
129 linePos.iY=(pixels.iHeight-lineLen)/2; |
|
130 iGc->DrawLine(linePos,linePos+TPoint(0,lineLen)); |
|
131 buf.Format(TRefByValue<const TDesC>(_L("Height %d\"")),inches); |
|
132 iGc->DrawText(buf,TPoint(linePos.iX+10, pixels.iHeight/4)); |
|
133 for(index=0;index<=inches;index++) |
|
134 { |
|
135 TInt dx=Client()->iScreen->HorizontalTwipsToPixels(KTwipsPerInch/(index==0 || index==inches ? 8 : 16)); |
|
136 TInt dy=Client()->iScreen->VerticalTwipsToPixels(index*KTwipsPerInch); |
|
137 iGc->DrawLine(linePos+TPoint(1,dy), linePos+TPoint(dx,dy)); |
|
138 } |
|
139 |
|
140 } |
|
141 |
|
142 void CScreenModeWindow::ScreenDeviceChanged() |
|
143 { |
|
144 if (iSubState==0) |
|
145 { |
|
146 TPixelsAndRotation sizeAndRotation; |
|
147 Client()->iScreen->GetDefaultScreenSizeAndRotation(sizeAndRotation); |
|
148 Client()->iScreen->SetScreenSizeAndRotation(sizeAndRotation); |
|
149 } |
|
150 else |
|
151 { |
|
152 TPixelsTwipsAndRotation sizeAndRotation; |
|
153 Client()->iScreen->GetDefaultScreenSizeAndRotation(sizeAndRotation); |
|
154 Client()->iScreen->SetScreenSizeAndRotation(sizeAndRotation); |
|
155 } |
|
156 SetSize(Client()->iScreen->SizeInPixels()); |
|
157 } |
|
158 |
|
159 // |
|
160 // CScreenModeGroup |
|
161 // |
|
162 |
|
163 CScreenModeGroup::~CScreenModeGroup() |
|
164 { |
|
165 GroupWin()->EnableReceiptOfFocus(EFalse); |
|
166 ClearCurrentWindow(); |
|
167 Client()->iGroup->SetCurrentWindow(NULL); |
|
168 CTWin::Delete(iWindow); |
|
169 } |
|
170 |
|
171 CScreenModeGroup::CScreenModeGroup(CTClient *aClient) : CTWindowGroup(aClient) |
|
172 {} |
|
173 |
|
174 void CScreenModeGroup::ConstructL() |
|
175 { |
|
176 CTWindowGroup::ConstructL(); |
|
177 iWindow=new(ELeave) CScreenModeWindow; |
|
178 iWindow->SetUpLD(TPoint(0,0),Client()->iScreen->SizeInPixels(),this,*Client()->iGc); |
|
179 SetCurrentWindow(iWindow); |
|
180 GroupWin()->EnableScreenChangeEvents(); |
|
181 GroupWin()->SetOrdinalPosition(0); |
|
182 } |
|
183 |
|
184 void CScreenModeGroup::ScreenDeviceChanged() |
|
185 { |
|
186 iWindow->ScreenDeviceChanged(); |
|
187 } |
|
188 |
|
189 // |
|
190 // CScreenModeTest |
|
191 // |
|
192 |
|
193 CScreenModeTest::CScreenModeTest() : CTestBase(_L("Screen mode")) |
|
194 {} |
|
195 |
|
196 CScreenModeTest::~CScreenModeTest() |
|
197 { |
|
198 Client()->iGroup->GroupWin()->EnableScreenChangeEvents(); |
|
199 Client()->iScreen->SetScreenMode(0); |
|
200 delete iScreenModeGroup; |
|
201 } |
|
202 |
|
203 void CScreenModeTest::ConstructL() |
|
204 { |
|
205 Client()->iGroup->GroupWin()->SetOrdinalPosition(0); |
|
206 Client()->iGroup->GroupWin()->DisableScreenChangeEvents(); |
|
207 // |
|
208 iScreenModeGroup=new(ELeave) CScreenModeGroup(Client()); |
|
209 iScreenModeGroup->ConstructL(); |
|
210 } |
|
211 |
|
212 TestState CScreenModeTest::DoTestL() |
|
213 { |
|
214 switch(iState) |
|
215 { |
|
216 case 0: |
|
217 LogSubTest(_L("Screen mode 1"),1); |
|
218 CActiveScheduler::Start(); |
|
219 iState++; |
|
220 break; |
|
221 default: |
|
222 return(EFinished); |
|
223 } |
|
224 return(ENext); |
|
225 } |
|
226 |