|
1 // Copyright (c) 2006-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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include <gdi.h> |
|
23 #include "tcrx.h" |
|
24 #include "wsredir.h" |
|
25 #include "wslisten.h" |
|
26 |
|
27 static TRedirectorInfo TheInfo; |
|
28 |
|
29 class CTwoWindow: public CBase |
|
30 { |
|
31 public: |
|
32 static CTwoWindow* NewL(); |
|
33 ~CTwoWindow(); |
|
34 private: |
|
35 void ConstructL(); |
|
36 private: |
|
37 RWsSession iWs; |
|
38 CWsScreenDevice* iScr; |
|
39 CWindowGc* iGc; |
|
40 RWindowGroup iGroup; |
|
41 RWindow iBg; |
|
42 RWindow iFg; |
|
43 }; |
|
44 |
|
45 CTwoWindow* CTwoWindow::NewL() |
|
46 { |
|
47 CTwoWindow* tw = new(ELeave) CTwoWindow; |
|
48 CleanupStack::PushL(tw); |
|
49 tw->ConstructL(); |
|
50 CleanupStack::Pop(tw); |
|
51 return tw; |
|
52 } |
|
53 |
|
54 CTwoWindow::~CTwoWindow() |
|
55 { |
|
56 iFg.Close(); |
|
57 iBg.Close(); |
|
58 iGroup.Close(); |
|
59 delete iGc; |
|
60 delete iScr; |
|
61 iWs.Close(); |
|
62 } |
|
63 |
|
64 void CTwoWindow::ConstructL() |
|
65 { |
|
66 User::LeaveIfError(iWs.Connect()); |
|
67 iScr = new(ELeave) CWsScreenDevice(iWs); |
|
68 User::LeaveIfError(iScr->Construct()); |
|
69 User::LeaveIfError(iScr->CreateContext(iGc)); |
|
70 iGroup = RWindowGroup(iWs); |
|
71 User::LeaveIfError(iGroup.Construct(0xc0de,ETrue)); |
|
72 |
|
73 iBg = RWindow(iWs); |
|
74 User::LeaveIfError(iBg.Construct(iGroup,0xc0debabe)); |
|
75 iBg.SetRequiredDisplayMode(EColor64K); |
|
76 iBg.Activate(); |
|
77 iWs.Flush(); |
|
78 |
|
79 iBg.BeginRedraw(); |
|
80 iGc->Activate(iBg); |
|
81 iGc->SetBrushColor(KRgbGreen); |
|
82 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
83 TRect rect(iScr->SizeInPixels()); |
|
84 iGc->DrawRect(rect); |
|
85 iGc->SetBrushColor(KRgbBlue); |
|
86 iGc->DrawEllipse(rect); |
|
87 iGc->Deactivate(); |
|
88 iBg.EndRedraw(); |
|
89 iWs.Flush(); |
|
90 |
|
91 iFg = RWindow(iWs); |
|
92 User::LeaveIfError(iFg.Construct(iGroup,0xc0decafe)); |
|
93 iFg.SetRequiredDisplayMode(EColor64K); |
|
94 iFg.SetTransparencyAlphaChannel(); |
|
95 iFg.SetBackgroundColor(TRgb(0xff,0x55,0x55,0x80)); |
|
96 iFg.Activate(); |
|
97 iWs.Flush(); |
|
98 } |
|
99 |
|
100 CClient* CClient::NewL() |
|
101 { |
|
102 CClient* self = new(ELeave) CClient; |
|
103 CleanupStack::PushL(self); |
|
104 self->ConstructL(); |
|
105 CleanupStack::Pop(self); |
|
106 |
|
107 return self; |
|
108 } |
|
109 |
|
110 CClient::CClient(): CActive(CActive::EPriorityStandard) |
|
111 { |
|
112 } |
|
113 |
|
114 void CClient::ConstructL() |
|
115 { |
|
116 CActiveScheduler::Add(this); |
|
117 User::LeaveIfError(iWs.Connect()); |
|
118 iScreen = new(ELeave) CWsScreenDevice(iWs); |
|
119 User::LeaveIfError(iScreen->Construct(0)); |
|
120 iGroup = RWindowGroup(iWs); |
|
121 User::LeaveIfError(iGroup.Construct(0xCAFE, ETrue)); |
|
122 iGc = new(ELeave) CWindowGc(iScreen); |
|
123 User::LeaveIfError(iGc->Construct()); |
|
124 iWin = new(ELeave) CWindow(this); |
|
125 iWin->ConstructL(NULL, EFalse); |
|
126 iRedraw = CRedrawHandler::NewL(this); |
|
127 |
|
128 iRedir = CWsRedir::NewL(); |
|
129 iListen = CWsListen::NewL(); |
|
130 |
|
131 MakeRequest(); |
|
132 } |
|
133 |
|
134 void CClient::HandleCommand(TInt aCmd) |
|
135 { |
|
136 switch (aCmd) |
|
137 { |
|
138 case 1: |
|
139 iRedir->Redirect(CWsRedir::EFrontBuffer, ETrue); |
|
140 break; |
|
141 |
|
142 case 2: |
|
143 iRedir->Redirect(CWsRedir::EBackBuffer, ETrue); |
|
144 break; |
|
145 |
|
146 case 3: |
|
147 iRedir->Redirect(CWsRedir::EFrontBuffer, EFalse); |
|
148 break; |
|
149 |
|
150 case 4: |
|
151 iRedir->Redirect(CWsRedir::EBackBuffer, EFalse); |
|
152 break; |
|
153 |
|
154 case 5: |
|
155 iListen->Enable(ETrue); |
|
156 break; |
|
157 |
|
158 case 6: |
|
159 iListen->Enable(EFalse); |
|
160 break; |
|
161 |
|
162 case 7: |
|
163 iRedir->QueryPlugin(TheInfo); |
|
164 break; |
|
165 |
|
166 case 8: |
|
167 iBlank.Close(); |
|
168 iBlank = RBlankWindow(iWs); |
|
169 iBlank.Construct(iGroup, 0xbeef); |
|
170 iBlank.SetRequiredDisplayMode(EColor64K); |
|
171 iBlank.SetColor(KRgbRed); |
|
172 iBlank.SetExtent(TPoint(20,20),TSize(100,100)); |
|
173 iBlank.Activate(); |
|
174 break; |
|
175 |
|
176 case 9: |
|
177 ClearTwoWindow(); |
|
178 DrawTwoWindow(); |
|
179 break; |
|
180 |
|
181 case 10: |
|
182 CActiveScheduler::Stop(); |
|
183 break; |
|
184 } |
|
185 } |
|
186 |
|
187 CClient::~CClient() |
|
188 { |
|
189 Deque(); |
|
190 ClearTwoWindow(); |
|
191 iBlank.Close(); |
|
192 |
|
193 delete iListen; |
|
194 delete iRedir; |
|
195 delete iWin; |
|
196 delete iRedraw; |
|
197 delete iGc; |
|
198 delete iScreen; |
|
199 |
|
200 iGroup.Close(); |
|
201 iWs.Close(); |
|
202 } |
|
203 |
|
204 void CClient::DrawTwoWindow() |
|
205 { |
|
206 TRAP_IGNORE(iTwo = CTwoWindow::NewL()); |
|
207 } |
|
208 |
|
209 void CClient::ClearTwoWindow() |
|
210 { |
|
211 delete iTwo; |
|
212 iTwo = NULL; |
|
213 } |
|
214 |
|
215 void CClient::RunL() |
|
216 { |
|
217 iWs.GetEvent(iEvent); |
|
218 if (iEvent.Type()==EEventKey) |
|
219 HandleCommand(iEvent.Key()->iCode-'0'); |
|
220 MakeRequest(); |
|
221 } |
|
222 |
|
223 void CClient::DoCancel() |
|
224 { |
|
225 iWs.EventReadyCancel(); |
|
226 } |
|
227 |
|
228 void CClient::MakeRequest() |
|
229 { |
|
230 iWs.EventReady(&iStatus); |
|
231 SetActive(); |
|
232 } |
|
233 |
|
234 CRedrawHandler* CRedrawHandler::NewL(CClient* aClient) |
|
235 { |
|
236 CRedrawHandler* self=new(ELeave) CRedrawHandler(aClient); |
|
237 CleanupStack::PushL(self); |
|
238 self->ConstructL(); |
|
239 CleanupStack::Pop(self); |
|
240 |
|
241 return self; |
|
242 } |
|
243 |
|
244 CRedrawHandler::CRedrawHandler(CClient* aClient) : CActive(CActive::EPriorityStandard), iClient(aClient) |
|
245 { |
|
246 } |
|
247 |
|
248 void CRedrawHandler::ConstructL() |
|
249 { |
|
250 CActiveScheduler::Add(this); |
|
251 MakeRequest(); |
|
252 } |
|
253 |
|
254 CRedrawHandler::~CRedrawHandler() |
|
255 { |
|
256 Cancel(); |
|
257 } |
|
258 |
|
259 void CRedrawHandler::RunL() |
|
260 { |
|
261 TWsRedrawEvent event; |
|
262 iClient->Ws().GetRedraw(event); |
|
263 CWindow* win = (CWindow*)event.Handle(); |
|
264 if (win) |
|
265 { |
|
266 TRect rect=event.Rect(); |
|
267 iClient->Gc().Activate(win->Window()); |
|
268 win->Window().BeginRedraw(rect); |
|
269 win->Draw(rect); |
|
270 win->Window().EndRedraw(); |
|
271 iClient->Gc().Deactivate(); |
|
272 } |
|
273 |
|
274 MakeRequest(); |
|
275 } |
|
276 |
|
277 void CRedrawHandler::MakeRequest() |
|
278 { |
|
279 iClient->Ws().RedrawReady(&iStatus); |
|
280 SetActive(); |
|
281 } |
|
282 |
|
283 void CRedrawHandler::DoCancel() |
|
284 { |
|
285 iClient->Ws().RedrawReadyCancel(); |
|
286 } |
|
287 |
|
288 CWindow::CWindow(CClient* aClient) : iClient(aClient) |
|
289 { |
|
290 } |
|
291 |
|
292 CWindow::~CWindow() |
|
293 { |
|
294 iWin.Close(); |
|
295 } |
|
296 |
|
297 void CWindow::ConstructL(CWindow* aParent, TBool aTransparentFlag) |
|
298 { |
|
299 iParent = aParent; |
|
300 iWin = RWindow(iClient->Ws()); |
|
301 RWindowTreeNode* node=iParent? &iParent->Window() : (RWindowTreeNode*)&iClient->Group(); |
|
302 User::LeaveIfError(iWin.Construct(*node, (TUint32)this)); |
|
303 iWin.SetRequiredDisplayMode(EColor64K); |
|
304 if (aTransparentFlag) |
|
305 { |
|
306 iWin.SetBackgroundColor(TRgb(0,0,0,0x80)); |
|
307 iWin.SetTransparencyAlphaChannel(); |
|
308 } |
|
309 iWin.SetExtent(TPoint(0,0),TSize(240,240)); |
|
310 iWin.Activate(); |
|
311 } |
|
312 |
|
313 void CWindow::Draw(const TRect& aRect) const |
|
314 { |
|
315 CWindowGc& gc = iClient->Gc(); |
|
316 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
317 gc.SetBrushColor(TRgb(0,0,0xff,0xff)); |
|
318 gc.DrawRect(TRect(aRect.iTl.iX,aRect.iTl.iY,aRect.iBr.iX,aRect.iBr.iY/2)); |
|
319 gc.SetBrushColor(TRgb(0,0,0xff,0x80)); |
|
320 gc.DrawRect(TRect(aRect.iTl.iX,aRect.iBr.iY/2,aRect.iBr.iX,aRect.iBr.iY)); |
|
321 DrawMenu(); |
|
322 |
|
323 gc.DrawWsGraphic(iClient->WsRedir()->Id(),TRect(aRect.iTl.iX,aRect.iBr.iY/2,aRect.iBr.iX,aRect.iBr.iY)); |
|
324 } |
|
325 |
|
326 _LIT(KMenu1, "1. Redirect screen"); |
|
327 _LIT(KMenu2, "2. Redirect flickerfree"); |
|
328 _LIT(KMenu3, "3. Restore screen"); |
|
329 _LIT(KMenu4, "4. Restore flickerfree"); |
|
330 _LIT(KMenu5, "5. Register event listener"); |
|
331 _LIT(KMenu6, "6. Unregister listener"); |
|
332 _LIT(KMenu7, "7. Test send receive msg"); |
|
333 _LIT(KMenu8, "8. Test blank window"); |
|
334 _LIT(KMenu9, "9. Test two window"); |
|
335 _LIT(KMenuA, "A. Exit"); |
|
336 |
|
337 const TBufC<32> TheMenu[] = |
|
338 { |
|
339 (const TDesC&)KMenu1, |
|
340 (const TDesC&)KMenu2, |
|
341 (const TDesC&)KMenu3, |
|
342 (const TDesC&)KMenu4, |
|
343 (const TDesC&)KMenu5, |
|
344 (const TDesC&)KMenu6, |
|
345 (const TDesC&)KMenu7, |
|
346 (const TDesC&)KMenu8, |
|
347 (const TDesC&)KMenu9, |
|
348 (const TDesC&)KMenuA |
|
349 }; |
|
350 |
|
351 _LIT(KTypeFace, "DejaVu Sans Condensed"); |
|
352 |
|
353 void CWindow::DrawMenu() const |
|
354 { |
|
355 CWsScreenDevice* scr = iClient->Screen(); |
|
356 CFont* font = NULL; |
|
357 TFontSpec fs(KTypeFace, 15); |
|
358 scr->GetNearestFontInPixels(font, fs); |
|
359 CWindowGc& gc = iClient->Gc(); |
|
360 gc.UseFont(font); |
|
361 TInt h = font->HeightInPixels(); |
|
362 gc.SetPenColor(KRgbYellow); |
|
363 TInt nMenu = sizeof(TheMenu)/sizeof(TheMenu[0]); |
|
364 for (TInt ii=0; ii<nMenu; ++ii) |
|
365 gc.DrawText(TheMenu[ii], TPoint(10,(ii+1)*h)); |
|
366 gc.DiscardFont(); |
|
367 scr->ReleaseFont(font); |
|
368 } |
|
369 |
|
370 void MainL() |
|
371 { |
|
372 CClient* client=CClient::NewL(); |
|
373 CActiveScheduler::Start(); |
|
374 |
|
375 delete client; |
|
376 } |
|
377 |
|
378 GLDEF_C TInt E32Main() |
|
379 { |
|
380 CTrapCleanup* trap=CTrapCleanup::New(); |
|
381 if (!trap) |
|
382 return KErrNoMemory; |
|
383 CActiveScheduler* scheduler = new(ELeave) CActiveScheduler; |
|
384 CActiveScheduler::Install(scheduler); |
|
385 |
|
386 __UHEAP_MARK; |
|
387 TRAPD(err, MainL()); |
|
388 __UHEAP_MARKEND; |
|
389 |
|
390 delete scheduler; |
|
391 delete trap; |
|
392 return err; |
|
393 } |