|
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 "listener.h" |
|
23 #include "wsgraphicdrawercontext.h" |
|
24 #include <graphics/wsscreendevice.h> |
|
25 #include <fbs.h> |
|
26 #include <bitdev.h> |
|
27 #include <bitstd.h> |
|
28 #ifdef __WINS__ |
|
29 #include "../debuglog/osbwin.h" |
|
30 #endif |
|
31 |
|
32 const TInt KDefaultScreen = 0; |
|
33 const TInt KListenDisable = 0; |
|
34 const TInt KListenEnable = 1; |
|
35 const TInt KCmdQuery = 2; |
|
36 |
|
37 const TUint8 KListenerInfoSig = 0xaa; |
|
38 |
|
39 NONSHARABLE_STRUCT(TListenerInfo) |
|
40 { |
|
41 TUint8 iSignature; |
|
42 TInt iNumRect; |
|
43 TRect iRect; |
|
44 TInt iWindowGroupId; |
|
45 }; |
|
46 |
|
47 const TInt KMaxColors = 14; |
|
48 const TInt KColorList[KMaxColors] = |
|
49 { |
|
50 0x555555, |
|
51 0x000080, |
|
52 0x008000, |
|
53 0x008080, |
|
54 0x800000, |
|
55 0x800080, |
|
56 0x808000, |
|
57 0x0000ff, |
|
58 0x00ff00, |
|
59 0x00ffff, |
|
60 0xff0000, |
|
61 0xff00ff, |
|
62 0xffff00, |
|
63 0xaaaaaa |
|
64 }; |
|
65 |
|
66 CWsEventListener* CWsEventListener::NewL() |
|
67 { |
|
68 return new(ELeave) CWsEventListener; |
|
69 } |
|
70 |
|
71 CWsEventListener::~CWsEventListener() |
|
72 { |
|
73 if (iEnabled) |
|
74 Env().UnregisterEventHandler(this); |
|
75 |
|
76 #ifdef __WINS__ |
|
77 if (!iDisableWin) |
|
78 delete iWin; |
|
79 #endif |
|
80 delete iGc; |
|
81 delete iDev; |
|
82 delete iBit; |
|
83 |
|
84 if (iDrawerContext) |
|
85 { |
|
86 iDrawerContext->Destroy(); |
|
87 iDrawerContext = NULL; |
|
88 } |
|
89 } |
|
90 |
|
91 void CWsEventListener::ConstructL(MWsGraphicDrawerEnvironment& aEnv, const TGraphicDrawerId& aId, MWsClient& aOwner, const TDesC8& aData) |
|
92 { |
|
93 BaseConstructL(aEnv, aId, aOwner); |
|
94 |
|
95 #ifdef __WINS__ |
|
96 if (aData.Length()>0) |
|
97 iDisableWin = aData[0]==1; |
|
98 #endif |
|
99 |
|
100 iScreen = aEnv.Screen(KDefaultScreen); |
|
101 MWsScreenConfig* screenConfig = iScreen->ObjectInterface<MWsScreenConfig>(); |
|
102 if (screenConfig) |
|
103 {// Non NGA |
|
104 iSize = screenConfig->SizeInPixels(); |
|
105 iDisplayMode = screenConfig->DisplayMode(); |
|
106 iDrawerContext = CWsGraphicDrawerNonNgaContext::NewL(); |
|
107 } |
|
108 else |
|
109 {// NGA |
|
110 MWsScreenDevice* screenDevice = iScreen->ObjectInterface<MWsScreenDevice>(); |
|
111 User::LeaveIfNull(screenDevice); |
|
112 iSize = screenDevice->SizeInPixels(); |
|
113 iDisplayMode = screenDevice->DisplayMode(); |
|
114 iDrawerContext = CWsGraphicDrawerNgaContext::NewL(); |
|
115 } |
|
116 |
|
117 iWindowGroupId = KErrNotFound; |
|
118 |
|
119 iBit = new(ELeave) CFbsBitmap; |
|
120 User::LeaveIfError(iBit->Create(iSize,iDisplayMode)); |
|
121 iDev = CFbsBitmapDevice::NewL(iBit); |
|
122 User::LeaveIfNull(iDev); |
|
123 User::LeaveIfError(iDev->CreateContext(iGc)); |
|
124 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
125 iGc->SetPenStyle(CGraphicsContext::ENullPen); |
|
126 |
|
127 #ifdef __WINS__ |
|
128 if (!iDisableWin) |
|
129 { |
|
130 _LIT(KListener, "EventListener"); |
|
131 iWin = CDebugOsbWin::NewL(KListener, iBit->SizeInPixels()); |
|
132 } |
|
133 #endif |
|
134 iReady = ETrue; |
|
135 } |
|
136 |
|
137 void CWsEventListener::HandleMessage(const TDesC8& aData) |
|
138 { |
|
139 // wserv already check data size, and won't invoke this handler if it's empty |
|
140 switch (aData[0]) |
|
141 { |
|
142 case KListenEnable: |
|
143 if (!iEnabled) |
|
144 { |
|
145 Env().RegisterEventHandler(this, this, TWservCrEvent::EScreenSizeModeChanged|TWservCrEvent::EWindowVisibilityChanged|TWservCrEvent::EWindowGroupChanged); |
|
146 iEnabled = ETrue; |
|
147 } |
|
148 break; |
|
149 |
|
150 case KListenDisable: |
|
151 if (iEnabled) |
|
152 { |
|
153 iEnabled = EFalse; |
|
154 Env().UnregisterEventHandler(this); |
|
155 } |
|
156 break; |
|
157 |
|
158 case KCmdQuery: |
|
159 SendInfo(); |
|
160 break; |
|
161 } |
|
162 } |
|
163 |
|
164 void CWsEventListener::DoHandleEvent(const TWservCrEvent& aEvent) |
|
165 { |
|
166 if (!iReady) |
|
167 return; |
|
168 |
|
169 switch (aEvent.Type()) |
|
170 { |
|
171 case TWservCrEvent::EScreenSizeModeChanged: |
|
172 OnScreenSizeModeChanged(aEvent.SizeMode()); |
|
173 break; |
|
174 |
|
175 case TWservCrEvent::EWindowVisibilityChanged: |
|
176 OnWindowVisibilityChanged(aEvent.VisibleRegion()); |
|
177 break; |
|
178 |
|
179 case TWservCrEvent::EWindowGroupChanged: |
|
180 OnWindowGroupChanged(aEvent.ScreenNumber(), aEvent.WindowGroupIdentifier()); |
|
181 break; |
|
182 } |
|
183 } |
|
184 |
|
185 void CWsEventListener::DoDraw(MWsGc& aGc, const TRect& aRect, const TDesC8& /*aData*/) const |
|
186 { |
|
187 iDrawerContext->DrawEllipse(aGc, aRect, TRgb(0,255,0,128)); |
|
188 } |
|
189 |
|
190 void CWsEventListener::OnScreenSizeModeChanged(TInt /*aMode*/) |
|
191 { |
|
192 iGc->SetBrushColor(KRgbWhite); |
|
193 iGc->Clear(); |
|
194 |
|
195 #ifdef __WINS__ |
|
196 if (!iDisableWin) |
|
197 { |
|
198 iBit->LockHeap(); |
|
199 iWin->Refresh(iBit->SizeInPixels(), iBit->DisplayMode(), iBit->DataAddress()); |
|
200 iBit->UnlockHeap(); |
|
201 } |
|
202 #endif |
|
203 } |
|
204 |
|
205 TRgb CWsEventListener::CurrentColor() |
|
206 { |
|
207 iColorIdx = (iColorIdx+1) % KMaxColors; |
|
208 return TRgb(KColorList[iColorIdx]); |
|
209 } |
|
210 |
|
211 void CWsEventListener::OnWindowVisibilityChanged(const RRegion* aRegion) |
|
212 { |
|
213 if (!aRegion) |
|
214 return; |
|
215 |
|
216 TInt n = aRegion->Count(); |
|
217 if (n==0) |
|
218 return; |
|
219 iGc->SetBrushColor(CurrentColor()); |
|
220 for (TInt i=0; i<n; ++i) |
|
221 { |
|
222 iGc->DrawRect((*aRegion)[i]); |
|
223 } |
|
224 |
|
225 iSaveNumRect = n; |
|
226 iSaveRect = (*aRegion)[0]; |
|
227 |
|
228 #ifdef __WINS__ |
|
229 if (!iDisableWin) |
|
230 { |
|
231 iBit->LockHeap(); |
|
232 iWin->Refresh(iBit->SizeInPixels(), iBit->DisplayMode(), iBit->DataAddress()); |
|
233 iBit->UnlockHeap(); |
|
234 } |
|
235 #endif |
|
236 } |
|
237 |
|
238 void CWsEventListener::OnWindowGroupChanged(TInt /*aScreenNumber*/, TInt aWindowGroupId) |
|
239 { |
|
240 iWindowGroupId = aWindowGroupId; |
|
241 } |
|
242 |
|
243 void CWsEventListener::SendInfo() |
|
244 { |
|
245 TPckgBuf<TListenerInfo> buf; |
|
246 buf().iSignature = KListenerInfoSig; |
|
247 buf().iNumRect = iSaveNumRect; |
|
248 buf().iRect = iSaveRect; |
|
249 buf().iWindowGroupId = iWindowGroupId; |
|
250 TInt err = SendMessage(buf); |
|
251 __ASSERT_ALWAYS(err>=KErrNone, User::Invariant()); |
|
252 iSaveNumRect = 0; |
|
253 iSaveRect = TRect(); |
|
254 } |
|
255 |
|
256 CWsEventNotifier* CWsEventNotifier::NewL() |
|
257 { |
|
258 return new(ELeave) CWsEventNotifier; |
|
259 } |
|
260 |
|
261 CWsEventNotifier::~CWsEventNotifier() |
|
262 { |
|
263 Env().UnregisterEventHandler(this); |
|
264 } |
|
265 |
|
266 void CWsEventNotifier::ConstructL(MWsGraphicDrawerEnvironment& aEnv, const TGraphicDrawerId& aId, MWsClient& aOwner, const TDesC8& /*aData*/) |
|
267 { |
|
268 BaseConstructL(aEnv, aId, aOwner); |
|
269 iEnv = &aEnv; |
|
270 iTestGraphicDrawerEnvironment = EFalse; |
|
271 iReady = ETrue; |
|
272 } |
|
273 |
|
274 void CWsEventNotifier::HandleMessage(const TDesC8& aData) |
|
275 { |
|
276 // wserv already checked data size, and won't invoke this handler if it's empty |
|
277 switch (aData[0]) |
|
278 { //Set how it will handle the first visibility event |
|
279 case KNotifyRemoveSelf: |
|
280 case KNotifyRemoveThenAddSelf: |
|
281 case KNotifyAddSelf: |
|
282 case KNotifyRemoveOther: |
|
283 case KNotifyRemoveThenAddOther: |
|
284 case KNotifyAddOther: |
|
285 case KNotifyRemoveSelfAndOther: |
|
286 case KNotifyDoNothing: |
|
287 Env().RegisterEventHandler(this, this, TWservCrEvent::EWindowVisibilityChanged); |
|
288 iHandleMethod = aData[0]; |
|
289 break; |
|
290 case KNotifyDisable: |
|
291 Env().UnregisterEventHandler(this); |
|
292 iHandleMethod = KNotifyDoNothing; |
|
293 break; |
|
294 default: |
|
295 break; |
|
296 } |
|
297 } |
|
298 |
|
299 void CWsEventNotifier::DoHandleEvent(const TWservCrEvent& /*aEvent*/) |
|
300 { |
|
301 if(!iTestGraphicDrawerEnvironment) |
|
302 { |
|
303 iTestGraphicDrawerEnvironment = ETrue; |
|
304 TestGraphicDrawerEnvironment(); |
|
305 } |
|
306 |
|
307 if (iHandleMethod == KNotifyRemoveSelf) |
|
308 { |
|
309 Env().UnregisterEventHandler(this); |
|
310 iHandleMethod = KNotifyDoNothing; |
|
311 } |
|
312 else if (iHandleMethod == KNotifyRemoveThenAddSelf) |
|
313 { |
|
314 Env().UnregisterEventHandler(this); |
|
315 Env().RegisterEventHandler(this, this, TWservCrEvent::EWindowVisibilityChanged); |
|
316 iHandleMethod = KNotifyDoNothing; |
|
317 } |
|
318 else if (iHandleMethod == KNotifyAddSelf) |
|
319 { |
|
320 Env().RegisterEventHandler(this, this, TWservCrEvent::EWindowVisibilityChanged); |
|
321 iHandleMethod = KNotifyDoNothing; |
|
322 } |
|
323 else if (iHandleMethod == KNotifyRemoveOther) |
|
324 { |
|
325 iAnotherPluginID.iId = 0x102754c5; //First method that needs the address of the other plugin |
|
326 iAnotherPluginID.iIsUid = ETrue; |
|
327 iAnotherPlugin = const_cast<CWsGraphicDrawer*>(Env().ResolveGraphic(iAnotherPluginID)); |
|
328 Env().UnregisterEventHandler(iAnotherPlugin); |
|
329 iHandleMethod = KNotifyDoNothing; |
|
330 } |
|
331 else if (iHandleMethod == KNotifyRemoveThenAddOther) |
|
332 { |
|
333 Env().UnregisterEventHandler(iAnotherPlugin); |
|
334 Env().RegisterEventHandler(iAnotherPlugin, this, TWservCrEvent::EWindowVisibilityChanged); |
|
335 iHandleMethod = KNotifyDoNothing; |
|
336 } |
|
337 else if (iHandleMethod == KNotifyAddOther) |
|
338 { |
|
339 Env().RegisterEventHandler(iAnotherPlugin, this, TWservCrEvent::EWindowVisibilityChanged); |
|
340 iHandleMethod = KNotifyDoNothing; |
|
341 } |
|
342 else if (iHandleMethod == KNotifyRemoveSelfAndOther) |
|
343 { |
|
344 Env().UnregisterEventHandler(this); |
|
345 Env().UnregisterEventHandler(iAnotherPlugin); |
|
346 iHandleMethod = KNotifyDoNothing; |
|
347 } |
|
348 } |
|
349 |
|
350 void CWsEventNotifier::DoDraw(MWsGc& /*aGc*/, const TRect& /*aRect*/, const TDesC8& /*aData*/) const |
|
351 { |
|
352 } |
|
353 |
|
354 void CWsEventNotifier::TestGraphicDrawerEnvironment() |
|
355 { |
|
356 const MWsGraphicDrawerEnvironment* aEnvConst = iEnv; |
|
357 TInt lowerbound = -1; |
|
358 //-tests Screen methods (const and non const) |
|
359 __ASSERT_ALWAYS(iEnv->Screen(lowerbound)==NULL, SendMessage(_L8("Error:iEnv->Screen(lowerbound) - expected: NULL, actual: !NULL (listener.cpp)"))); |
|
360 __ASSERT_ALWAYS(iEnv->Screen(iEnv->ScreenCount())==NULL, SendMessage(_L8("Error:iEnv->Screen(iEnv->ScreenCount()) - expected: NULL, actual: !NULL (listener.cpp)"))); |
|
361 __ASSERT_ALWAYS(aEnvConst->Screen(lowerbound)==NULL, SendMessage(_L8("Error:aEnvConst->Screen(lowerbound) - expected: NULL, actual: !NULL (listener.cpp)"))); |
|
362 __ASSERT_ALWAYS(aEnvConst->Screen(aEnvConst->ScreenCount())==NULL, SendMessage(_L8("Error:aEnvConst->ScreenCount()) - expected: NULL, actual: !NULL (listener.cpp)"))); |
|
363 //+test const screen method |
|
364 const MWsScreen* constScreen = aEnvConst->Screen(aEnvConst->ScreenCount()-1); |
|
365 __ASSERT_ALWAYS(constScreen!=NULL, SendMessage(_L8("Error:constScreen - expected: !NULL, actual: NULL (listener.cpp)"))); |
|
366 //+test resolveobjectinterface method |
|
367 MWsActiveSchedulerDebug* scheduler = iEnv->ObjectInterface<MWsActiveSchedulerDebug>(); |
|
368 __ASSERT_ALWAYS(scheduler!=NULL, SendMessage(_L8("Error:scheduler - expected: !NULL, actual: NULL (listener.cpp)"))); |
|
369 TUint32 eventMask = 0; |
|
370 //-tests for registereventhandler and unregistereventhandler |
|
371 __ASSERT_ALWAYS(iEnv->RegisterEventHandler(NULL,this, TWservCrEvent::EWindowClosing)==KErrArgument, SendMessage(_L8("Error:iEnv->RegisterEventHandler(NULL,this, TWservCrEvent::EWindowClosing) - expected: KErrArgument, actual: !KErrArgument (listener.cpp)"))); |
|
372 __ASSERT_ALWAYS(iEnv->RegisterEventHandler(this,NULL, TWservCrEvent::EWindowClosing)==KErrArgument, SendMessage(_L8("Error:iEnv->RegisterEventHandler(this,NULL, TWservCrEvent::EWindowClosing) - expected: KErrArgument, actual: !KErrArgument (listener.cpp)"))); |
|
373 __ASSERT_ALWAYS(iEnv->RegisterEventHandler(this,this, eventMask)==KErrArgument, SendMessage(_L8("Error:iEnv->RegisterEventHandler(this,this, eventMask) - expected: KErrArgument, actual: !KErrArgument (listener.cpp)"))); |
|
374 __ASSERT_ALWAYS(iEnv->UnregisterEventHandler(NULL)==KErrArgument, SendMessage(_L8("Error:iEnv->UnregisterEventHandler(NULL) - expected: KErrArgument, actual: !KErrArgument (listener.cpp)"))); |
|
375 //-tests for registerwseventhandler |
|
376 #ifdef SYMBIAN_GRAPHICS_GCE |
|
377 __ASSERT_ALWAYS(iEnv->RegisterWsEventHandler(this, eventMask)==KErrArgument, SendMessage(_L8("Error:iEnv->RegisterWsEventHandler(this, eventMask) - expected: KErrArgument, actual: !KErrArgument (listener.cpp)"))); |
|
378 __ASSERT_ALWAYS(iEnv->RegisterWsEventHandler(NULL, TWservCrEvent::EWindowClosing)==KErrArgument, SendMessage(_L8("Error:iEnv->RegisterWsEventHandler(NULL, TWservCrEvent::EWindowClosing) - expected: KErrArgument, actual: !KErrArgument (listener.cpp)"))); |
|
379 #endif //SYMBIAN_GRAPHICS_GCE |
|
380 } |