|
1 // Copyright (c) 1996-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 // Test pointer event handling |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <hal.h> |
|
20 #include "W32STD.H" |
|
21 #include "../tlib/testbase.h" |
|
22 #include "TMAN.H" |
|
23 |
|
24 class CTPointerTest; |
|
25 class CGrabWindow; |
|
26 |
|
27 class CPointerWindow : public CTWin |
|
28 { |
|
29 enum {KRepeatMargin=200000}; // 0.2 Seconds |
|
30 enum {KRepeatCount=4}; |
|
31 enum {KRepeatIntervalIncrements=100000}; |
|
32 enum {KRepeatRectXExtra=50}; |
|
33 enum {KRepeatRectYExtra=50}; |
|
34 enum {KStateWaitingForTest1,KStateFailed,KStateTesting1, |
|
35 KStateWaitingForTest2,KStateTesting2, |
|
36 KStateWaitingForTest3,KStateTesting3, |
|
37 KStateWaitingForTest4,KStateTesting4, |
|
38 KStateWaitingForTest5,KStateTesting5, |
|
39 KStateWaitingForTest6,KStateTesting6, |
|
40 KStateWaitingForTest8,KStateTesting8, |
|
41 KStateWaitingForTest7,KStateTesting7, |
|
42 KStateFinished}; |
|
43 public: |
|
44 CPointerWindow(CTPointerTest *aTest); |
|
45 void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc); |
|
46 void Draw(); |
|
47 void StartNextRepeatTest(); |
|
48 void QueueNextRepeat(); |
|
49 void PointerL(const TPointerEvent &aPointer,const TTime&); |
|
50 void WinKeyL(const TKeyEvent &aKey,const TTime &aTime); |
|
51 private: |
|
52 void SwitchOn(const TTime &); |
|
53 void ResetTest(TInt aState); |
|
54 void SetState(TInt aState); |
|
55 void FinishedTests(); |
|
56 void TestFailed(); |
|
57 private: |
|
58 CTPointerTest *iTest; |
|
59 TInt iRepeatCount; |
|
60 TInt iState; |
|
61 TTimeIntervalMicroSeconds32 iInterval; |
|
62 TTime iPrevTime; |
|
63 TRect iRepeatRect; |
|
64 }; |
|
65 |
|
66 class CGrabWindow2 : public CTWin |
|
67 { |
|
68 public: |
|
69 CGrabWindow2(CGrabWindow *aWindow); |
|
70 void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc); |
|
71 private: |
|
72 void Draw(); |
|
73 void PointerL(const TPointerEvent &aPointer,const TTime&); |
|
74 private: |
|
75 CGrabWindow *iGrabWindow; |
|
76 }; |
|
77 |
|
78 class CGrabWindow : public CTWin |
|
79 { |
|
80 enum {KGrabStateWaitingForDown,KGrabStateWaitingForDragOut,KGrabStateWaitingForUp,KGrabStateFinished, |
|
81 KGrabStateWaitingForDown2,KGrabStateWaitingForUp2a,KGrabStateWaitingForDrag2,KGrabStateWaitingForUp2b, |
|
82 KGrabStateWaitingForDown3,KGrabStateWaitingForUp3a,KGrabStateWaitingForUp3b, |
|
83 KGrabStateWaitingForDown4,KGrabStateWaitingForUp4, |
|
84 KGrabStateWaitingForDown5,KGrabStateWaitingForUp5,KGrabStateWaitingForDrag5, |
|
85 KStateFailed}; |
|
86 public: |
|
87 CGrabWindow(CTPointerTest *aTest); |
|
88 void Pointer2(const TPointerEvent &aPointer); |
|
89 void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc); |
|
90 void WinKeyL(const TKeyEvent &aKey,const TTime &aTime); |
|
91 private: |
|
92 void Draw(); |
|
93 void SetState(TInt aState); |
|
94 void ResetTest(); |
|
95 void PointerL(const TPointerEvent &aPointer,const TTime&); |
|
96 void TestFailed(); |
|
97 void FinishedTests(); |
|
98 private: |
|
99 TInt iState; |
|
100 CTPointerTest *iTest; |
|
101 }; |
|
102 |
|
103 class CTPointerTest : public CTestBase |
|
104 { |
|
105 public: |
|
106 CTPointerTest(); |
|
107 ~CTPointerTest(); |
|
108 TBool TestFailed(); |
|
109 TestState DoTestL(); |
|
110 void StartGrabTestL(); |
|
111 void ConstructL(); |
|
112 CGrabWindow2 *GrabWin2() const; |
|
113 inline TBool Digitiser() const {return !iNoDigitiser;} |
|
114 private: |
|
115 TInt doTestFailedL(); |
|
116 private: |
|
117 CPointerWindow *iRepeatWin; |
|
118 CGrabWindow *iGrabWin; |
|
119 CGrabWindow2 *iGrabWin2; |
|
120 TSize iWinSize; |
|
121 TInt iState; |
|
122 TBool iOldPointerState; |
|
123 TBool iNoDigitiser; |
|
124 }; |
|
125 |
|
126 GLDEF_C CTestBase *CreatePointerTest() |
|
127 { |
|
128 return(new(ELeave) CTPointerTest()); |
|
129 } |
|
130 |
|
131 CPointerWindow::CPointerWindow(CTPointerTest *aTest) : CTWin(), iTest(aTest) |
|
132 {} |
|
133 |
|
134 void CPointerWindow::SetState(TInt aState) |
|
135 { |
|
136 iState=aState; |
|
137 iWin.Invalidate(); |
|
138 switch(aState) |
|
139 { |
|
140 case KStateWaitingForTest1: |
|
141 case KStateWaitingForTest2: |
|
142 case KStateWaitingForTest3: |
|
143 case KStateWaitingForTest4: |
|
144 case KStateWaitingForTest5: |
|
145 case KStateWaitingForTest6: |
|
146 case KStateWaitingForTest8: |
|
147 case KStateWaitingForTest7: |
|
148 iRepeatRect=TRect(); |
|
149 break; |
|
150 case KStateTesting8: |
|
151 iWin.Close(); |
|
152 Client()->iWs.Flush(); |
|
153 User::After(500000); |
|
154 FinishedTests(); |
|
155 break; |
|
156 } |
|
157 } |
|
158 |
|
159 void CPointerWindow::ResetTest(TInt aState) |
|
160 { |
|
161 TInt newState=KStateFinished; |
|
162 switch(aState) |
|
163 { |
|
164 case KStateTesting1: |
|
165 newState=KStateWaitingForTest1; |
|
166 break; |
|
167 case KStateTesting2: |
|
168 newState=KStateWaitingForTest2; |
|
169 break; |
|
170 case KStateTesting3: |
|
171 newState=KStateWaitingForTest3; |
|
172 break; |
|
173 case KStateTesting4: |
|
174 newState=KStateWaitingForTest4; |
|
175 break; |
|
176 case KStateTesting5: |
|
177 newState=KStateWaitingForTest5; |
|
178 break; |
|
179 case KStateTesting6: |
|
180 newState=KStateWaitingForTest6; |
|
181 break; |
|
182 case KStateTesting8: |
|
183 newState=KStateWaitingForTest8; |
|
184 break; |
|
185 case KStateTesting7: |
|
186 newState=KStateWaitingForTest7; |
|
187 break; |
|
188 } |
|
189 SetState(newState); |
|
190 } |
|
191 |
|
192 void CPointerWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc) |
|
193 { |
|
194 ConstructExtLD(*parent,pos,size); |
|
195 Activate(); |
|
196 AssignGC(aGc); |
|
197 //SetState(KStateWaitingForTest1); |
|
198 SetState(KStateWaitingForTest7); //Only unconverted test |
|
199 BaseWin()->EnableOnEvents(); |
|
200 } |
|
201 |
|
202 void CPointerWindow::Draw() |
|
203 { |
|
204 iGc->Clear(); |
|
205 iGc->DrawRect(Size()); |
|
206 iGc->DrawRect(iRepeatRect); |
|
207 TBuf<0x80> buf; |
|
208 TBuf<0x80> buf2; |
|
209 switch(iState) |
|
210 { |
|
211 case KStateWaitingForTest1: |
|
212 buf.Format(_L("Click anywhere in the window and hold the pointer steady")); |
|
213 break; |
|
214 case KStateTesting1: |
|
215 buf.Format(_L("Hold pointer inside the box")); |
|
216 break; |
|
217 case KStateWaitingForTest2: |
|
218 buf.Format(_L("Release the pointer then click in the window and hold the pointer steady")); |
|
219 break; |
|
220 case KStateTesting2: |
|
221 buf.Format(_L("Drag the pointer outside the box")); |
|
222 break; |
|
223 case KStateWaitingForTest3: |
|
224 buf.Format(_L("Release the pointer then click in the window and hold the pointer steady")); |
|
225 break; |
|
226 case KStateTesting3: |
|
227 buf.Format(_L("Release the pointer")); |
|
228 break; |
|
229 case KStateWaitingForTest4: |
|
230 buf.Format(_L("Click anywhere in the window and move the pointer slightly")); |
|
231 break; |
|
232 case KStateTesting4: |
|
233 buf.Format(_L("Release the pointer")); |
|
234 break; |
|
235 case KStateWaitingForTest5: |
|
236 buf.Format(_L("Click anywhere in the window and move the pointer slightly")); |
|
237 break; |
|
238 case KStateTesting5: |
|
239 buf.Format(_L("Release the pointer")); |
|
240 break; |
|
241 case KStateWaitingForTest6: |
|
242 buf.Format(_L("Click anywhere in the window")); |
|
243 break; |
|
244 case KStateTesting6: |
|
245 buf.Format(_L("Move the pointer")); |
|
246 break; |
|
247 case KStateWaitingForTest8: |
|
248 buf.Format(_L("Click anywhere in the window, and keep the pointer pressed")); |
|
249 break; |
|
250 case KStateTesting8: |
|
251 buf.Format(_L("")); |
|
252 break; |
|
253 case KStateWaitingForTest7: |
|
254 buf.Format(_L("Switch off and touch the center of the screen")); |
|
255 break; |
|
256 case KStateTesting7: |
|
257 buf.Format(_L("")); |
|
258 break; |
|
259 } |
|
260 switch(iState) |
|
261 { |
|
262 case KStateTesting1: |
|
263 buf2.Format(TRefByValue<const TDesC>(_L("Repeat (%d/%d), interval=%d.%d")),iRepeatCount,KRepeatCount,iInterval.Int()/1000000,(iInterval.Int()%1000000)/100000); |
|
264 break; |
|
265 case KStateTesting2: |
|
266 case KStateTesting3: |
|
267 buf2.Format(TRefByValue<const TDesC>(_L("Repeat (%d), interval=%d.%d")),iRepeatCount,iInterval.Int()/1000000,(iInterval.Int()%1000000)/100000); |
|
268 break; |
|
269 } |
|
270 iGc->DrawText(buf,TPoint(10,20)); |
|
271 iGc->DrawText(buf2,TPoint(10,40)); |
|
272 } |
|
273 |
|
274 void CPointerWindow::FinishedTests() |
|
275 { |
|
276 iState=KStateFinished; |
|
277 iTest->Request(); |
|
278 } |
|
279 |
|
280 void CPointerWindow::StartNextRepeatTest() |
|
281 { |
|
282 iInterval=0; |
|
283 iRepeatCount=0; |
|
284 if (iState==KStateWaitingForTest4) |
|
285 User::After(TTimeIntervalMicroSeconds32(1000000)); |
|
286 else if (iState==KStateWaitingForTest5) |
|
287 User::After(TTimeIntervalMicroSeconds32(1000000)); |
|
288 QueueNextRepeat(); |
|
289 switch(iState) |
|
290 { |
|
291 case KStateWaitingForTest1: |
|
292 SetState(KStateTesting1); |
|
293 break; |
|
294 case KStateWaitingForTest2: |
|
295 SetState(KStateTesting2); |
|
296 break; |
|
297 case KStateWaitingForTest3: |
|
298 SetState(KStateTesting3); |
|
299 break; |
|
300 case KStateWaitingForTest4: |
|
301 SetState(KStateTesting4); |
|
302 break; |
|
303 case KStateWaitingForTest5: |
|
304 SetState(KStateTesting5); |
|
305 break; |
|
306 case KStateWaitingForTest6: |
|
307 SetState(KStateTesting6); |
|
308 break; |
|
309 case KStateWaitingForTest8: |
|
310 SetState(KStateTesting8); |
|
311 break; |
|
312 case KStateWaitingForTest7: |
|
313 SetState(KStateTesting7); |
|
314 break; |
|
315 } |
|
316 } |
|
317 |
|
318 void CPointerWindow::QueueNextRepeat() |
|
319 { |
|
320 iInterval=iInterval.Int()+KRepeatIntervalIncrements; |
|
321 iWin.RequestPointerRepeatEvent(TTimeIntervalMicroSeconds32(iInterval),TRect(iRepeatRect)); |
|
322 iPrevTime.HomeTime(); |
|
323 iWin.Invalidate(); |
|
324 } |
|
325 |
|
326 void CPointerWindow::PointerL(const TPointerEvent &aPointer,const TTime &aTime) |
|
327 { |
|
328 if (aPointer.iType==TPointerEvent::EButtonRepeat) |
|
329 { |
|
330 if (iState!=KStateTesting1 && iState!=KStateTesting2 && iState!=KStateTesting3 && iState!=KStateTesting4) |
|
331 TestFailed(); |
|
332 else |
|
333 { |
|
334 TTimeIntervalMicroSeconds32 interval(I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64())); |
|
335 if (interval.Int()<(iInterval.Int()-KRepeatMargin) || interval.Int()>(iInterval.Int()+KRepeatMargin)) |
|
336 TestFailed(); |
|
337 else |
|
338 { |
|
339 if (!iRepeatRect.Contains(aPointer.iPosition) || |
|
340 aPointer.iParentPosition!=(aPointer.iPosition+iWin.InquireOffset(*Parent()->WinTreeNode()))) |
|
341 TestFailed(); |
|
342 else |
|
343 { |
|
344 iRepeatCount++; |
|
345 if (iState==KStateTesting1 && iRepeatCount==KRepeatCount) |
|
346 { |
|
347 QueueNextRepeat(); |
|
348 Client()->iWs.Flush(); |
|
349 User::After(TTimeIntervalMicroSeconds32(iRepeatCount*KRepeatIntervalIncrements)); |
|
350 iWin.CancelPointerRepeatEventRequest(); |
|
351 SetState(KStateWaitingForTest2); |
|
352 } |
|
353 else |
|
354 QueueNextRepeat(); |
|
355 } |
|
356 } |
|
357 } |
|
358 } |
|
359 else switch(iState) |
|
360 { |
|
361 case KStateWaitingForTest1: |
|
362 case KStateWaitingForTest2: |
|
363 case KStateWaitingForTest3: |
|
364 case KStateWaitingForTest4: |
|
365 case KStateWaitingForTest8: |
|
366 if (aPointer.iType==TPointerEvent::EButton1Down) |
|
367 { |
|
368 iRepeatRect.iTl=aPointer.iPosition-TPoint(KRepeatRectXExtra,KRepeatRectYExtra); |
|
369 iRepeatRect.iBr=aPointer.iPosition+TPoint(KRepeatRectXExtra,KRepeatRectYExtra); |
|
370 StartNextRepeatTest(); |
|
371 } |
|
372 break; |
|
373 case KStateWaitingForTest5: |
|
374 if (aPointer.iType==TPointerEvent::EButton1Down) |
|
375 { |
|
376 iRepeatRect.iTl=aPointer.iPosition; |
|
377 iRepeatRect.iBr=aPointer.iPosition+TPoint(1,1); |
|
378 StartNextRepeatTest(); |
|
379 } |
|
380 break; |
|
381 case KStateWaitingForTest6: |
|
382 if (aPointer.iType==TPointerEvent::EButton1Down) |
|
383 { |
|
384 iRepeatRect.iTl=aPointer.iPosition+TPoint(KRepeatRectXExtra,KRepeatRectYExtra); |
|
385 iRepeatRect.iBr=aPointer.iPosition+TPoint(2*KRepeatRectXExtra,2*KRepeatRectYExtra); |
|
386 StartNextRepeatTest(); |
|
387 } |
|
388 break; |
|
389 case KStateTesting1: |
|
390 TestFailed(); |
|
391 break; |
|
392 case KStateTesting2: |
|
393 if (aPointer.iType==TPointerEvent::EDrag) |
|
394 SetState(KStateWaitingForTest3); |
|
395 else |
|
396 TestFailed(); |
|
397 break; |
|
398 case KStateTesting3: |
|
399 if (aPointer.iType==TPointerEvent::EButton1Up) |
|
400 SetState(KStateWaitingForTest4); |
|
401 else |
|
402 TestFailed(); |
|
403 break; |
|
404 case KStateTesting4: |
|
405 if (aPointer.iType==TPointerEvent::EButton1Up) |
|
406 SetState(KStateWaitingForTest5); |
|
407 else |
|
408 TestFailed(); |
|
409 break; |
|
410 case KStateTesting5: |
|
411 if (aPointer.iType==TPointerEvent::EButton1Up) |
|
412 SetState(KStateWaitingForTest6); |
|
413 else if (aPointer.iType!=TPointerEvent::EDrag) |
|
414 TestFailed(); |
|
415 break; |
|
416 case KStateTesting6: |
|
417 if (aPointer.iType==TPointerEvent::EDrag) |
|
418 { |
|
419 #if !defined(__WINS__) // Can't emulate touching dig when switched off under WINS |
|
420 if (iTest->Digitiser()) |
|
421 SetState(KStateWaitingForTest7); |
|
422 else |
|
423 #endif |
|
424 SetState(KStateWaitingForTest8); |
|
425 } |
|
426 else |
|
427 TestFailed(); |
|
428 break; |
|
429 case KStateWaitingForTest7: |
|
430 if (aPointer.iType==TPointerEvent::EButton1Down || aPointer.iType==TPointerEvent::ESwitchOn) |
|
431 TestFailed(); |
|
432 break; |
|
433 case KStateTesting7: |
|
434 if (aPointer.iType!=TPointerEvent::ESwitchOn) |
|
435 TestFailed(); |
|
436 else |
|
437 SetState(KStateTesting8); //Jump straight to end as this is only unconverted test. |
|
438 //SetState(KStateWaitingForTest8); |
|
439 break; |
|
440 case KStateTesting8: |
|
441 break; |
|
442 } |
|
443 } |
|
444 |
|
445 void CPointerWindow::TestFailed() |
|
446 { |
|
447 if (iState!=KStateFailed) |
|
448 { |
|
449 TInt oldState=iState; |
|
450 iState=KStateFailed; |
|
451 if (iTest->TestFailed()) |
|
452 ResetTest(oldState); |
|
453 } |
|
454 } |
|
455 |
|
456 void CPointerWindow::WinKeyL(const TKeyEvent &aKey,const TTime &) |
|
457 { |
|
458 if (aKey.iCode==EKeyEscape) |
|
459 FinishedTests(); // Simply skip this test if the Escape key is pressed |
|
460 } |
|
461 |
|
462 void CPointerWindow::SwitchOn(const TTime &) |
|
463 { |
|
464 if (iState==KStateWaitingForTest7) |
|
465 SetState(KStateTesting7); |
|
466 else |
|
467 TestFailed(); |
|
468 } |
|
469 |
|
470 // |
|
471 // CGrabWindow // |
|
472 // |
|
473 |
|
474 CGrabWindow::CGrabWindow(CTPointerTest *aTest) : iTest(aTest) |
|
475 { |
|
476 } |
|
477 |
|
478 void CGrabWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc) |
|
479 { |
|
480 ConstructExtLD(*parent,pos,size); |
|
481 Activate(); |
|
482 AssignGC(aGc); |
|
483 SetState(KGrabStateWaitingForDown); |
|
484 } |
|
485 |
|
486 void CGrabWindow::Draw() |
|
487 { |
|
488 iGc->Clear(); |
|
489 iGc->DrawRect(Size()); |
|
490 TBuf<0x80> buf; |
|
491 switch(iState) |
|
492 { |
|
493 case KGrabStateWaitingForDown: |
|
494 case KGrabStateWaitingForDown2: |
|
495 case KGrabStateWaitingForDown5: |
|
496 buf.Copy(_L("Press the pointer inside the window")); |
|
497 break; |
|
498 case KGrabStateWaitingForDown3: |
|
499 case KGrabStateWaitingForUp3a: |
|
500 buf.Copy(_L("Press and release the pointer inside the window")); |
|
501 break; |
|
502 case KGrabStateWaitingForDragOut: |
|
503 buf.Copy(_L("Drag the pointer outside into the outside window")); |
|
504 break; |
|
505 case KGrabStateWaitingForDrag2: |
|
506 buf.Copy(_L("Drag the pointer outside outside both windows")); |
|
507 break; |
|
508 case KGrabStateWaitingForUp: |
|
509 case KGrabStateWaitingForUp2b: |
|
510 case KGrabStateWaitingForUp5: |
|
511 buf.Copy(_L("Release the pointer")); |
|
512 break; |
|
513 case KGrabStateWaitingForDown4: |
|
514 buf.Copy(_L("Press then release the pointer")); |
|
515 break; |
|
516 default:; |
|
517 } |
|
518 iGc->DrawText(buf,TPoint(10,20)); |
|
519 } |
|
520 |
|
521 void CGrabWindow::PointerL(const TPointerEvent &aPointer,const TTime&) |
|
522 { |
|
523 switch(iState) |
|
524 { |
|
525 case KGrabStateWaitingForDown: |
|
526 if (aPointer.iType==TPointerEvent::EButton1Down) |
|
527 SetState(KGrabStateWaitingForDragOut); |
|
528 break; |
|
529 case KGrabStateWaitingForDragOut: |
|
530 if (aPointer.iType!=TPointerEvent::EDrag) |
|
531 TestFailed(); |
|
532 else |
|
533 { |
|
534 if (!TRect(Size()).Contains(aPointer.iPosition)) |
|
535 SetState(KGrabStateWaitingForUp); |
|
536 } |
|
537 break; |
|
538 case KGrabStateWaitingForUp: |
|
539 if (aPointer.iType==TPointerEvent::EDrag) |
|
540 break; |
|
541 if (aPointer.iType==TPointerEvent::EButton1Up) |
|
542 SetState(KGrabStateWaitingForDown2); |
|
543 else |
|
544 TestFailed(); |
|
545 break; |
|
546 case KGrabStateWaitingForDown2: |
|
547 if (aPointer.iType!=TPointerEvent::EButton1Down) |
|
548 TestFailed(); |
|
549 else |
|
550 { |
|
551 iTest->GrabWin2()->BaseWin()->ClaimPointerGrab(); |
|
552 iTest->GrabWin2()->BaseWin()->ClaimPointerGrab(); // Call twice to check it's harmless |
|
553 SetState(KGrabStateWaitingForUp2a); |
|
554 } |
|
555 break; |
|
556 case KGrabStateWaitingForUp2a: |
|
557 SetState(KGrabStateWaitingForDrag2); |
|
558 break; |
|
559 case KGrabStateWaitingForDrag2: |
|
560 break; |
|
561 case KGrabStateWaitingForUp2b: |
|
562 TestFailed(); |
|
563 break; |
|
564 case KGrabStateWaitingForDown3: |
|
565 if (aPointer.iType!=TPointerEvent::EButton1Down) |
|
566 TestFailed(); |
|
567 else |
|
568 SetState(KGrabStateWaitingForUp3a); |
|
569 break; |
|
570 case KGrabStateWaitingForUp3a: |
|
571 if (aPointer.iType==TPointerEvent::EButton1Up) |
|
572 { |
|
573 iTest->GrabWin2()->BaseWin()->ClaimPointerGrab(); |
|
574 SetState(KGrabStateWaitingForUp3b); |
|
575 } |
|
576 break; |
|
577 case KGrabStateWaitingForUp3b: |
|
578 TestFailed(); |
|
579 break; |
|
580 case KGrabStateWaitingForDown5: |
|
581 if (aPointer.iType!=TPointerEvent::EButton1Down) |
|
582 TestFailed(); |
|
583 else |
|
584 { |
|
585 iTest->GrabWin2()->BaseWin()->ClaimPointerGrab(EFalse); |
|
586 SetState(KGrabStateWaitingForDrag5); |
|
587 } |
|
588 break; |
|
589 case KGrabStateWaitingForDrag5: |
|
590 if (aPointer.iType==TPointerEvent::EButton1Up) |
|
591 TestFailed(); |
|
592 break; |
|
593 case KGrabStateWaitingForUp5: |
|
594 TestFailed(); |
|
595 break; |
|
596 case KGrabStateWaitingForDown4: |
|
597 SetState(KGrabStateWaitingForUp4); |
|
598 iWin.Close(); // Close the window with the grab captured in it |
|
599 break; |
|
600 case KGrabStateFinished: |
|
601 break; |
|
602 } |
|
603 } |
|
604 |
|
605 void CGrabWindow::ResetTest() |
|
606 { |
|
607 SetState(KGrabStateWaitingForDown); |
|
608 } |
|
609 |
|
610 void CGrabWindow::Pointer2(const TPointerEvent &aPointer) |
|
611 { |
|
612 switch(iState) |
|
613 { |
|
614 case KGrabStateWaitingForDrag2: |
|
615 { |
|
616 if (aPointer.iType==TPointerEvent::EDrag) |
|
617 { |
|
618 SetState(KGrabStateWaitingForUp2b); |
|
619 } |
|
620 else |
|
621 { |
|
622 if (iTest->TestFailed()) |
|
623 ResetTest(); |
|
624 } |
|
625 break; |
|
626 } |
|
627 case KGrabStateWaitingForUp2b: |
|
628 if (aPointer.iType==TPointerEvent::EDrag) // Harmless |
|
629 break; |
|
630 if (aPointer.iType==TPointerEvent::EButton1Up) |
|
631 SetState(KGrabStateWaitingForDown3); |
|
632 else |
|
633 TestFailed(); |
|
634 break; |
|
635 case KGrabStateWaitingForUp3b: |
|
636 if (aPointer.iType==TPointerEvent::EButton1Up) |
|
637 SetState(KGrabStateWaitingForDown5); |
|
638 else |
|
639 TestFailed(); |
|
640 break; |
|
641 case KGrabStateWaitingForUp4: |
|
642 FinishedTests(); |
|
643 break; |
|
644 case KGrabStateWaitingForDrag5: |
|
645 { |
|
646 if (aPointer.iType==TPointerEvent::EDrag) |
|
647 SetState(KGrabStateWaitingForUp5); |
|
648 else if (iTest->TestFailed()) |
|
649 ResetTest(); |
|
650 break; |
|
651 } |
|
652 case KGrabStateWaitingForUp5: |
|
653 if (aPointer.iType==TPointerEvent::EDrag) // Harmless |
|
654 break; |
|
655 if (aPointer.iType==TPointerEvent::EButton1Up) |
|
656 SetState(KGrabStateWaitingForDown4); |
|
657 else |
|
658 TestFailed(); |
|
659 break; |
|
660 default:; |
|
661 } |
|
662 } |
|
663 |
|
664 void CGrabWindow::SetState(TInt aState) |
|
665 { |
|
666 iState=aState; |
|
667 iWin.Invalidate(); |
|
668 } |
|
669 |
|
670 void CGrabWindow::TestFailed() |
|
671 { |
|
672 if (iState!=KStateFailed) |
|
673 { |
|
674 iState=KStateFailed; |
|
675 if (iTest->TestFailed()) |
|
676 ResetTest(); |
|
677 } |
|
678 } |
|
679 |
|
680 void CGrabWindow::FinishedTests() |
|
681 { |
|
682 iState=KGrabStateFinished; |
|
683 iTest->Request(); |
|
684 } |
|
685 |
|
686 void CGrabWindow::WinKeyL(const TKeyEvent &aKey,const TTime &) |
|
687 { |
|
688 if (aKey.iCode==EKeyEscape) |
|
689 FinishedTests(); // Simply skip this test if the Escape key is pressed |
|
690 } |
|
691 |
|
692 // |
|
693 // CGrabWindow2, used as part of grab tests // |
|
694 // |
|
695 |
|
696 CGrabWindow2::CGrabWindow2(CGrabWindow *aWindow) : iGrabWindow(aWindow) |
|
697 { |
|
698 } |
|
699 |
|
700 void CGrabWindow2::Draw() |
|
701 { |
|
702 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
703 iGc->SetBrushColor(TRgb::Gray4(2)); |
|
704 iGc->DrawRect(Size()); |
|
705 } |
|
706 |
|
707 void CGrabWindow2::PointerL(const TPointerEvent &aPointer,const TTime&) |
|
708 { |
|
709 iGrabWindow->Pointer2(aPointer); |
|
710 } |
|
711 |
|
712 // |
|
713 // CTPointTest // |
|
714 // |
|
715 |
|
716 CTPointerTest::CTPointerTest() : CTestBase(_L("CTPointerTest")) |
|
717 {} |
|
718 |
|
719 CTPointerTest::~CTPointerTest() |
|
720 { |
|
721 HAL::Set(HALData::EPenDisplayOn,iOldPointerState); |
|
722 delete iRepeatWin; |
|
723 delete iGrabWin; |
|
724 delete iGrabWin2; |
|
725 Client()->ResetFocus(); |
|
726 } |
|
727 |
|
728 void CTPointerTest::ConstructL() |
|
729 { |
|
730 iRepeatWin=new(ELeave) CPointerWindow(this); |
|
731 TSize screenSize(Client()->iScreen->SizeInPixels()); |
|
732 iRepeatWin->SetUpLD(TPoint(screenSize.iWidth/8,screenSize.iHeight/8),TSize(screenSize.iWidth*3/4,screenSize.iHeight*3/4),Client()->iGroup,*Client()->iGc); |
|
733 Client()->iGroup->SetCurrentWindow(iRepeatWin); |
|
734 iNoDigitiser=EFalse; |
|
735 TInt err=HAL::Get(HALData::EPenDisplayOn,iOldPointerState); |
|
736 if (err==KErrNotSupported) |
|
737 iNoDigitiser=ETrue; |
|
738 else if (err==KErrNone) |
|
739 err=HAL::Set(HALData::EPenDisplayOn,ETrue); |
|
740 if (err==KErrNotSupported) |
|
741 iNoDigitiser=(!iOldPointerState); |
|
742 else |
|
743 TestL(err==KErrNone); |
|
744 } |
|
745 |
|
746 TBool CTPointerTest::TestFailed() |
|
747 { |
|
748 TInt ret=1; |
|
749 TRAP_IGNORE(ret=doTestFailedL()); |
|
750 switch(ret) |
|
751 { |
|
752 case 0: |
|
753 return(ETrue); // Re-try test |
|
754 case 1: |
|
755 Request(); |
|
756 break; |
|
757 } |
|
758 return(EFalse); |
|
759 } |
|
760 |
|
761 TInt CTPointerTest::doTestFailedL() |
|
762 { |
|
763 CTDialog *dialog=new(ELeave) CTDialog(); |
|
764 dialog->SetTitle(_L("Pointer repeat test failed")); |
|
765 dialog->SetNumButtons(2); |
|
766 dialog->SetButtonText(0,_L("Retest")); |
|
767 dialog->SetButtonText(1,_L("Fail")); |
|
768 dialog->ConstructLD(*Client()->iGroup,*Client()->iGc); |
|
769 return dialog->Display(); |
|
770 } |
|
771 |
|
772 CGrabWindow2 *CTPointerTest::GrabWin2() const |
|
773 { |
|
774 return(iGrabWin2); |
|
775 } |
|
776 |
|
777 void CTPointerTest::StartGrabTestL() |
|
778 { |
|
779 iGrabWin=new(ELeave) CGrabWindow(this); |
|
780 iGrabWin2=new(ELeave) CGrabWindow2(iGrabWin); |
|
781 // |
|
782 TSize screenSize(Client()->iScreen->SizeInPixels()); |
|
783 iGrabWin2->SetUpL(TPoint(screenSize.iWidth/8,screenSize.iHeight/8),TSize(screenSize.iWidth*3/4,screenSize.iHeight*3/4),Client()->iGroup,*Client()->iGc); |
|
784 Client()->iGroup->SetCurrentWindow(iGrabWin2); |
|
785 // |
|
786 iGrabWin->SetUpLD(TPoint(screenSize.iWidth/4,screenSize.iHeight/4),TSize(screenSize.iWidth/2,screenSize.iHeight/2),Client()->iGroup,*Client()->iGc); |
|
787 Client()->iGroup->SetCurrentWindow(iGrabWin); |
|
788 // |
|
789 } |
|
790 |
|
791 #pragma warning( disable : 4065 ) //switch statement contains 'default' but no 'case' labels |
|
792 TestState CTPointerTest::DoTestL() |
|
793 { |
|
794 switch(iState) |
|
795 { |
|
796 #if !defined(__WINS__) //Only unconverted test is MARM only |
|
797 case 0: |
|
798 LogSubTest(_L("Repeat tests"),1); |
|
799 iState++; |
|
800 return(EContinue); |
|
801 #endif |
|
802 |
|
803 default: |
|
804 return(EFinished); |
|
805 } |
|
806 } |
|
807 #pragma warning( default : 4065 ) |
|
808 |