|
1 // Copyright (c) 2008-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 // TVIEW2 |
|
15 // Tests integration of view architecture throughout the ViewSrv, Cone, Apparc, Uikon and RefUI layers. |
|
16 // Tests basic view switching and appUi embedding. Tests various exceptional view switch conditions |
|
17 // including OOM during activation, attempts to start missing apps, tests panics while idle, while |
|
18 // activating and while deactivating and very slow activations and deactivations. |
|
19 // Should be used with companion test app TVIEW1 - the target view for each test view switch is in this app |
|
20 // and using TVIEW1 means that the test view switches can be initiated from a different thread. |
|
21 // TVIEW2 can be used for stress testing the view arc by setting up queues of events while doing |
|
22 // the longer tests and killing random apps etc. |
|
23 // If TVIEW1 is running when TVIEW2 is started TVIEW1 will be set as the owning window group |
|
24 // |
|
25 // |
|
26 |
|
27 /** |
|
28 @file |
|
29 @internalComponent - Internal Symbian test code |
|
30 */ |
|
31 |
|
32 #include <e32math.h> |
|
33 #include <barsread.h> |
|
34 #include <gulalign.h> |
|
35 #include <txtrich.h> |
|
36 #include <apgtask.h> |
|
37 |
|
38 #include <techview/eiktxlbx.h> |
|
39 #include <techview/eiktxlbm.h> |
|
40 #include <techview/eiklabel.h> |
|
41 #include <techview/eikcmbut.h> |
|
42 #include <techview/eikbtpan.h> |
|
43 #include <techview/eikmenub.h> |
|
44 #include <techview/eikdialg.h> |
|
45 #include <eikdll.h> |
|
46 #include <eiksvdef.h> |
|
47 #include <techview/eikrted.h> |
|
48 #include <eikstart.h> |
|
49 |
|
50 #include <techview/eikwbtb.h> |
|
51 |
|
52 #include <techview/eikon.hrh> |
|
53 #include <techview/eikon.rsg> |
|
54 |
|
55 #include <tview2.rsg> |
|
56 |
|
57 #include "tview2.H" |
|
58 #include "tview2.HRH" |
|
59 #include "tvwuids.H" |
|
60 |
|
61 #define VIEW_ONE TVwsViewId(KUidViewAppTwo,KUidViewOne) |
|
62 #define VIEW_TWO TVwsViewId(KUidViewAppTwo,KUidViewTwo) |
|
63 #define APP_TEXT _L("TVIEW2") |
|
64 |
|
65 // |
|
66 // EXPORTed functions |
|
67 // |
|
68 |
|
69 |
|
70 LOCAL_C CApaApplication* NewApplication() |
|
71 { |
|
72 return new CTestApplication; |
|
73 } |
|
74 |
|
75 GLDEF_C TInt E32Main() |
|
76 { |
|
77 return EikStart::RunApplication(NewApplication); |
|
78 } |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 // |
|
84 // CTestApplication |
|
85 // |
|
86 |
|
87 TUid CTestApplication::AppDllUid() const |
|
88 { |
|
89 return KUidViewAppTwo; |
|
90 } |
|
91 |
|
92 CApaDocument* CTestApplication::CreateDocumentL() |
|
93 { |
|
94 return new (ELeave) CTestDocument(*this); |
|
95 } |
|
96 |
|
97 |
|
98 // |
|
99 // CTestDocument |
|
100 // |
|
101 |
|
102 CTestDocument::CTestDocument(CEikApplication& aApp) |
|
103 : CEikDocument(aApp) |
|
104 { |
|
105 } |
|
106 |
|
107 CEikAppUi* CTestDocument::CreateAppUiL() |
|
108 { |
|
109 return new(ELeave) CTestAppUi; |
|
110 } |
|
111 |
|
112 |
|
113 // |
|
114 // CTestSwitchDialog. |
|
115 // |
|
116 |
|
117 CTestSwitchDialog::~CTestSwitchDialog() |
|
118 { |
|
119 } |
|
120 |
|
121 CTestSwitchDialog::CTestSwitchDialog(CTestAppUi& aAppUi) : iAppUi(aAppUi) |
|
122 { |
|
123 } |
|
124 |
|
125 TBool CTestSwitchDialog::OkToExitL(TInt aButtonId) |
|
126 { |
|
127 if (aButtonId!=EEikBidOk) |
|
128 return EFalse; |
|
129 |
|
130 switch (ChoiceListCurrentItem(ESwitchDlg_ViewChoice)) |
|
131 { |
|
132 case 0: |
|
133 iAppUi.iViewToActivate.iViewUid=KUidViewOne; |
|
134 break; |
|
135 case 1: |
|
136 iAppUi.iViewToActivate.iViewUid=KUidViewTwo; |
|
137 break; |
|
138 default: |
|
139 break; |
|
140 } |
|
141 |
|
142 if (ChoiceListCurrentItem(ESwitchDlg_AppChoice)==0) |
|
143 { |
|
144 iAppUi.iViewToActivate.iAppUid=KUidViewAppOne; |
|
145 } |
|
146 else if (ChoiceListCurrentItem(ESwitchDlg_AppChoice)==1) |
|
147 { |
|
148 iAppUi.iViewToActivate.iAppUid=KUidViewAppTwo; |
|
149 } |
|
150 |
|
151 delete iAppUi.iCustomMsg; |
|
152 iAppUi.iCustomMsg=HBufC::NewL(STATIC_CAST(CEikEdwin*,Control(ESwitchDlg_CustomMsg))->TextLength()); |
|
153 TPtr des=iAppUi.iCustomMsg->Des(); |
|
154 GetEdwinText(des,ESwitchDlg_CustomMsg); |
|
155 return ETrue; |
|
156 } |
|
157 |
|
158 // |
|
159 // CTestRichTextDialog |
|
160 // |
|
161 |
|
162 class CTestRichTextDialog : public CEikDialog |
|
163 { |
|
164 public: |
|
165 CTestRichTextDialog(CRichText*& aRichText,CParaFormatLayer*& aRichParaFormatLayer,CCharFormatLayer*& aRichCharFormatLayer); |
|
166 private: // framework |
|
167 void PreLayoutDynInitL(); |
|
168 TBool OkToExitL(TInt aKeycode); |
|
169 private: |
|
170 CRichText*& iRichText; |
|
171 CParaFormatLayer*& iRichParaFormatLayer; |
|
172 CCharFormatLayer*& iRichCharFormatLayer; |
|
173 }; |
|
174 |
|
175 |
|
176 CTestRichTextDialog::CTestRichTextDialog(CRichText*& aRichText,CParaFormatLayer*& aRichParaFormatLayer, |
|
177 CCharFormatLayer*& aRichCharFormatLayer) |
|
178 : iRichText(aRichText),iRichParaFormatLayer(aRichParaFormatLayer),iRichCharFormatLayer(aRichCharFormatLayer) |
|
179 {} |
|
180 |
|
181 |
|
182 void CTestRichTextDialog::PreLayoutDynInitL() |
|
183 { |
|
184 CEikRichTextEditor* ed=(CEikRichTextEditor*)Control(ERtextedDlg_Editor); |
|
185 ed->SetDocumentContentL(*iRichText); |
|
186 } |
|
187 |
|
188 TBool CTestRichTextDialog::OkToExitL(TInt /*aKeycode*/) |
|
189 { |
|
190 delete iRichText; |
|
191 delete iRichParaFormatLayer; |
|
192 delete iRichCharFormatLayer; |
|
193 CEikRichTextEditor* edwin=STATIC_CAST(CEikRichTextEditor*,Control(ERtextedDlg_Editor)); |
|
194 edwin->SetDocumentOwnership(CEikEdwin::EDoesNotOwnText); |
|
195 iRichText=edwin->RichText(); |
|
196 iRichText->SetPictureFactory(iRichText->PictureFactory(),NULL); |
|
197 iRichParaFormatLayer=((CParaFormatLayer*)iRichText->GlobalParaFormatLayer()); |
|
198 iRichCharFormatLayer=((CCharFormatLayer*)iRichText->GlobalCharFormatLayer()); |
|
199 return(ETrue); |
|
200 } |
|
201 |
|
202 |
|
203 // |
|
204 // CTestAppUi |
|
205 // |
|
206 |
|
207 CTestAppUi::~CTestAppUi() |
|
208 { |
|
209 delete iCustomMsg; |
|
210 delete iRichText; |
|
211 delete iRichParaFormatLayer; |
|
212 delete iRichCharFormatLayer; |
|
213 delete iViewActivationObserver; |
|
214 delete iAutoTestTimer; |
|
215 delete iIdle; |
|
216 } |
|
217 |
|
218 const TInt KRandSeed=67890; |
|
219 |
|
220 CTestAppUi::CTestAppUi() |
|
221 : iRandSeed(KRandSeed) |
|
222 { |
|
223 TTime time; |
|
224 time.HomeTime(); |
|
225 iRandSeed=time.Int64(); |
|
226 } |
|
227 |
|
228 void CTestAppUi::ConstructL() |
|
229 { |
|
230 CTestVwAppUi::ConstructL(); |
|
231 iRichParaFormatLayer=CEikonEnv::NewDefaultParaFormatLayerL(); |
|
232 iRichCharFormatLayer=CEikonEnv::NewDefaultCharFormatLayerL(); |
|
233 iRichText=CRichText::NewL(iRichParaFormatLayer,iRichCharFormatLayer); |
|
234 CreateViewsL(); |
|
235 iViewActivationObserver=new(ELeave) CTestViewActivationObserver(*this); |
|
236 iViewActivationObserver->ConstructL(); |
|
237 iAutoTestTimer=CPeriodic::NewL(0); |
|
238 iIdle=CIdle::NewL(CActive::EPriorityIdle); |
|
239 |
|
240 // Set default owning window if available |
|
241 CEikonEnv* env=CEikonEnv::Static(); |
|
242 TApaTaskList taskList(env->WsSession()); |
|
243 TApaTask task=taskList.FindApp(KUidViewAppOne); |
|
244 if (task.Exists()) |
|
245 { |
|
246 env->RootWin().SetOwningWindowGroup(task.WgId()); |
|
247 } |
|
248 } |
|
249 |
|
250 void CTestAppUi::CreateViewsL() |
|
251 { |
|
252 if (iViewsCreated) |
|
253 { |
|
254 RDebug::Print(_L("Views already created")); |
|
255 return; |
|
256 } |
|
257 |
|
258 AddViewL(VIEW_ONE); |
|
259 AddViewL(VIEW_TWO); |
|
260 STATIC_CAST(CTestView*,View(VIEW_TWO))->InitializeAsDefaultL(); |
|
261 RDebug::Print(_L("All views created")); |
|
262 iViewsCreated=ETrue; |
|
263 } |
|
264 |
|
265 void CTestAppUi::AddViewL(const TVwsViewId& aViewId) |
|
266 { |
|
267 RDebug::Print(_L("Creating %x..."),aViewId.iViewUid.iUid); |
|
268 CTestView* view=new(ELeave) CTestView(aViewId,*this); |
|
269 CleanupStack::PushL(view); |
|
270 CTestVwAppUi::AddViewL(view); |
|
271 CleanupStack::Pop(); |
|
272 } |
|
273 |
|
274 void CTestAppUi::DisplaySwitchViewDialogL() |
|
275 { |
|
276 CEikDialog* dlg=new(ELeave) CTestSwitchDialog(*this); |
|
277 if (dlg->ExecuteLD(R_VW_VIEW_SWITCH_DIALOG)) |
|
278 { |
|
279 DoActivationL(); |
|
280 } |
|
281 } |
|
282 |
|
283 void CTestAppUi::HandleCommandL(TInt aCommand) |
|
284 { |
|
285 switch (aCommand) |
|
286 { |
|
287 case ESwitchView: |
|
288 DisplaySwitchViewDialogL(); |
|
289 break; |
|
290 case EDisplayRichText: |
|
291 DisplayRichTextDialogL(); |
|
292 break; |
|
293 case EEikCmdExit: |
|
294 Exit(); |
|
295 break; |
|
296 case EDisplayTaskList: |
|
297 CEikonEnv::Static()->DisplayTaskList(); |
|
298 break; |
|
299 case EActivationOOM: |
|
300 TestActivationOOML(); |
|
301 break; |
|
302 case ESuccesiveAllocFail: |
|
303 TestSuccesiveAllocFailL(); |
|
304 break; |
|
305 case EWaitingActivation: |
|
306 TestWaitingActivationL(); |
|
307 break; |
|
308 case EStartMissingApp: |
|
309 TestStartMissingAppL(); |
|
310 break; |
|
311 case EPanicedActivation: |
|
312 TestPanicedActivationL(); |
|
313 break; |
|
314 case EPanicApp: |
|
315 TestPanic(); |
|
316 break; |
|
317 case EPanicedDeactivation: |
|
318 TestPanicedDeactivationL(); |
|
319 break; |
|
320 case ESlowActivation: |
|
321 TestSlowActivationL(); |
|
322 break; |
|
323 case ESlowDeactivation: |
|
324 TestSlowDeactivationL(); |
|
325 break; |
|
326 default: |
|
327 if (ActiveView()) |
|
328 ActiveView()->HandleCommandL(aCommand); |
|
329 else |
|
330 RDebug::Print(_L("No active view")); |
|
331 break; |
|
332 } |
|
333 } |
|
334 |
|
335 void CTestAppUi::DisplayRichTextDialogL() |
|
336 { |
|
337 CEikDialog* dialog=new(ELeave) CTestRichTextDialog(iRichText,iRichParaFormatLayer,iRichCharFormatLayer); |
|
338 dialog->ExecuteLD(R_VW_RTEXTED_DIALOG); |
|
339 } |
|
340 |
|
341 void CTestAppUi::DoActivationL() |
|
342 { |
|
343 if (iCustomMsg->Length()) |
|
344 { |
|
345 ActivateViewL(iViewToActivate,KUidTestCustomMesssageId,*iCustomMsg); |
|
346 } |
|
347 else |
|
348 { |
|
349 TVwsViewId viewId; |
|
350 CCoeAppUi::GetActiveViewId(viewId); |
|
351 CCoeAppUi::ActivateViewL(iViewToActivate); |
|
352 CCoeAppUi::GetActiveViewId(viewId); |
|
353 } |
|
354 } |
|
355 |
|
356 void CTestAppUi::TestSuccesiveAllocFailL() |
|
357 { |
|
358 RDebug::Print(_L("TVIEW2 : Test Succesive Alloc Failure During Activation Until Success")); |
|
359 TInt error=KErrUnknown; |
|
360 for(TInt fail=1;error!=KErrNone;fail++) |
|
361 { |
|
362 RDebug::Print(_L("TVIEW2 : Next Failure Test")); |
|
363 __UHEAP_FAILNEXT(fail);// fail on succesive allocations |
|
364 __UHEAP_MARK; |
|
365 TRAP(error,CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne))); |
|
366 __UHEAP_MARKEND; // Check nothing has alloc'd due to fail |
|
367 } |
|
368 __UHEAP_SETFAIL(RHeap::ENone,0);// turn failure off |
|
369 } |
|
370 |
|
371 void CTestAppUi::TestActivationOOML() |
|
372 { |
|
373 RDebug::Print(_L("TVIEW2 : Test Activation OOM")); |
|
374 ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidActivationOOM,KNullDesC16); |
|
375 } |
|
376 |
|
377 void CTestAppUi::TestWaitingActivationL() |
|
378 { |
|
379 RDebug::Print(_L("TVIEW2 : Test Waiting Activation")); |
|
380 ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidStartScheduler,KNullDesC16); |
|
381 } |
|
382 |
|
383 void CTestAppUi::TestPanicedActivationL() |
|
384 { |
|
385 RDebug::Print(_L("TVIEW2 : Test Paniced Activation")); |
|
386 ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidActivationPanic,KNullDesC16); |
|
387 } |
|
388 |
|
389 void CTestAppUi::TestPanicedDeactivationL() |
|
390 { |
|
391 RDebug::Print(_L("TVIEW2 : Test Paniced Deactivation")); |
|
392 STATIC_CAST(CTestView*,View(VIEW_ONE))->iDeactivationPanic=ETrue; |
|
393 STATIC_CAST(CTestView*,View(VIEW_TWO))->iDeactivationPanic=ETrue; |
|
394 CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne)); |
|
395 } |
|
396 |
|
397 void CTestAppUi::TestSlowActivationL() |
|
398 { |
|
399 RDebug::Print(_L("TVIEW2 : Test Slow Activation")); |
|
400 ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidSlowActivation,KNullDesC16); |
|
401 } |
|
402 |
|
403 void CTestAppUi::TestSlowDeactivationL() |
|
404 { |
|
405 RDebug::Print(_L("TVIEW2 : Test Slow Deactivation")); |
|
406 STATIC_CAST(CTestView*,View(VIEW_ONE))->iSlowDeactivation=ETrue; |
|
407 STATIC_CAST(CTestView*,View(VIEW_TWO))->iSlowDeactivation=ETrue; |
|
408 CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne)); |
|
409 } |
|
410 |
|
411 const TInt KMinimumDelay=50000; |
|
412 |
|
413 void CTestAppUi::StartEnduranceTest() |
|
414 { |
|
415 if (iAutoTestTimer->IsActive()) |
|
416 iAutoTestTimer->Cancel(); |
|
417 |
|
418 // Start the auto test timer |
|
419 TTimeIntervalMicroSeconds32 delay(KMinimumDelay+KMinimumDelay*Math::Rand(iRandSeed)/KMaxTInt); |
|
420 iAutoTestTimer->Start(delay,delay,TCallBack(EnduranceTestCallBack,this)); |
|
421 } |
|
422 |
|
423 void CTestAppUi::DoNextEnduranceTestActivation() |
|
424 { |
|
425 if (iAutoTestTimer->IsActive()) |
|
426 iAutoTestTimer->Cancel(); |
|
427 |
|
428 // Find a new view to activate |
|
429 TUid viewUid = (Math::Rand(iRandSeed)<KMaxTInt/2) ? KUidViewOne : KUidViewTwo; |
|
430 TUid appUid = KNullUid; |
|
431 TInt rand=Math::Rand(iRandSeed); |
|
432 if (rand<=KMaxTInt/3) // 1 in 3 chance |
|
433 { |
|
434 appUid=KUidViewAppOne; |
|
435 } |
|
436 else if (rand/2<=KMaxTInt/3) |
|
437 { |
|
438 appUid=KUidViewAppTwo; |
|
439 } |
|
440 else |
|
441 { |
|
442 appUid=KUidViewAppThree; |
|
443 } |
|
444 |
|
445 // Decide whether any special condition should be used with activation. |
|
446 // This can mean the activation will be sluggish, a deactivation will be sluggish |
|
447 // or the activation will leave |
|
448 TUid messageUid=KNullUid; |
|
449 rand=Math::Rand(iRandSeed); |
|
450 if (rand<=KMaxTInt/10) // 1 in 10 chance |
|
451 { |
|
452 messageUid=KUidActivationOOM; |
|
453 } |
|
454 else if (rand/2<=KMaxTInt/10) |
|
455 { |
|
456 messageUid=KUidSluggishActivation; |
|
457 } |
|
458 else if (rand/3<=KMaxTInt/10) |
|
459 { |
|
460 STATIC_CAST(CTestView*,View(VIEW_ONE))->iSluggishDeactivation=ETrue; |
|
461 } |
|
462 |
|
463 // Start the timer again with a new time delay |
|
464 TTimeIntervalMicroSeconds32 delay(KMinimumDelay+KMinimumDelay*Math::Rand(iRandSeed)/KMaxTInt); |
|
465 iAutoTestTimer->Start(delay,delay,TCallBack(EnduranceTestCallBack,this)); |
|
466 TRAPD(err,ActivateViewL(TVwsViewId(appUid,viewUid),messageUid,KNullDesC)); |
|
467 __ASSERT_ALWAYS(!err,User::Panic(_L("ActivateViewL(TVwsViewId(appUid,viewUid),messageUid,KNullDesC)"),err)); |
|
468 |
|
469 } |
|
470 |
|
471 TInt CTestAppUi::EnduranceTestCallBack(TAny* aSelf) |
|
472 { // static |
|
473 REINTERPRET_CAST(CTestAppUi*,aSelf)->DoNextEnduranceTestActivation(); |
|
474 return 0; |
|
475 } |
|
476 |
|
477 void CTestAppUi::IdleExit() |
|
478 { |
|
479 if (!(iIdle->IsActive())) |
|
480 { |
|
481 RDebug::Print(_L("******************************** TVIEW2 : EXIT EXIT EXIT EXIT EXIT *************************")); |
|
482 iIdle->Start(TCallBack(IdleExitCallBack,this)); |
|
483 } |
|
484 } |
|
485 |
|
486 TBool CTestAppUi::IdleExitCallBack(TAny* aSelf) |
|
487 {//static |
|
488 REINTERPRET_CAST(CTestAppUi*,aSelf)->DoExit(); |
|
489 return 0; |
|
490 } |
|
491 |
|
492 void CTestAppUi::DoExit() |
|
493 { |
|
494 User::After(100000); // 0.1 sec |
|
495 Exit(); |
|
496 } |
|
497 // |
|
498 // This UID defined in Uikon. Not an app. |
|
499 // |
|
500 const TUid KUidPasswordMode={268435755}; |
|
501 |
|
502 void CTestAppUi::TestStartMissingAppL() |
|
503 { |
|
504 RDebug::Print(_L("TVIEW2 : Test Start Missing App")); |
|
505 CCoeAppUi::ActivateViewL(TVwsViewId(KUidPasswordMode,KUidViewOne)); |
|
506 } |
|
507 |
|
508 void CTestAppUi::TestPanic() |
|
509 { |
|
510 RDebug::Print(_L("TVIEW2 : Test Panic")); |
|
511 User::Panic(APP_TEXT,1); |
|
512 } |
|
513 |
|
514 CTestViewControl::~CTestViewControl() |
|
515 { |
|
516 } |
|
517 |
|
518 void CTestViewControl::ConstructL(const TVwsViewId& aViewId) |
|
519 { |
|
520 iViewId=aViewId; |
|
521 CreateWindowL(); |
|
522 Window().SetShadowDisabled(ETrue); |
|
523 Window().SetBackgroundColor(KRgbRed); |
|
524 ActivateL(); |
|
525 } |
|
526 |
|
527 const TInt KXStart = 50; |
|
528 const TInt KYStart = 50; |
|
529 |
|
530 void CTestViewControl::Draw(const TRect& /*aRect*/) const |
|
531 { |
|
532 CWindowGc& gc = SystemGc(); |
|
533 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
534 gc.SetBrushColor(KRgbDitheredLightGray); |
|
535 gc.DrawRect(Rect()); |
|
536 |
|
537 gc.UseFont(iEikonEnv->TitleFont()); |
|
538 |
|
539 TInt yPos = KYStart; |
|
540 TInt xPos = KXStart; |
|
541 |
|
542 gc.DrawText(APP_TEXT,TPoint(xPos,yPos)); |
|
543 |
|
544 yPos+=30; |
|
545 |
|
546 TBuf<256> viewNameBuf; |
|
547 viewNameBuf.Append(_L("View ")); |
|
548 TBuf<16> numBuf; |
|
549 numBuf.Num((TInt)iViewId.iViewUid.iUid); |
|
550 viewNameBuf.Append(numBuf); |
|
551 |
|
552 gc.DrawText(viewNameBuf,TPoint(xPos,yPos)); |
|
553 } |
|
554 |
|
555 |
|
556 // |
|
557 // CTestView |
|
558 // |
|
559 |
|
560 CTestView::~CTestView() |
|
561 { |
|
562 RemoveFromStack(iControl); |
|
563 delete iControl; |
|
564 } |
|
565 |
|
566 CTestView::CTestView(const TVwsViewId& aViewId,CTestAppUi& aAppUi) |
|
567 :CTestVwAppView(aViewId,aAppUi), iDeactivationPanic(EFalse), iSlowDeactivation(EFalse), iSluggishDeactivation(EFalse) |
|
568 { |
|
569 } |
|
570 |
|
571 void CTestView::ConstructL() |
|
572 { |
|
573 iControl=new(ELeave) CTestViewControl; |
|
574 iControl->ConstructL(ViewId()); |
|
575 iControl->SetRect(ClientRect()); |
|
576 AddToStackL(iControl); |
|
577 } |
|
578 |
|
579 void CTestView::InitializeAsDefaultL() |
|
580 { |
|
581 AppUi().SetDefaultViewL(*this); |
|
582 |
|
583 if (!iControl) |
|
584 ConstructL(); |
|
585 |
|
586 iControl->ActivateL(); |
|
587 iControl->DrawNow(); |
|
588 } |
|
589 |
|
590 LOCAL_C void CleanupDoActivate(TAny* aPtr) |
|
591 { |
|
592 ((CTestView*)aPtr)->UnrollDoActivate(); |
|
593 } |
|
594 |
|
595 void CTestView::UnrollDoActivate() |
|
596 { |
|
597 RemoveFromStack(iControl); |
|
598 delete iControl; |
|
599 iControl=NULL; |
|
600 } |
|
601 |
|
602 void CTestView::DoActivateL(const TVwsViewId& /*aPrevViewUid*/,TUid aCustomMessageId,const TDesC16& /*aCustomMessage*/) |
|
603 { |
|
604 CleanupStack::PushL(TCleanupItem(CleanupDoActivate,this)); |
|
605 |
|
606 if (!iControl) |
|
607 ConstructL(); |
|
608 |
|
609 if(aCustomMessageId==KUidStartScheduler) |
|
610 { |
|
611 STATIC_CAST(CTestAppUi&,AppUi()).DisplayRichTextDialogL(); |
|
612 } |
|
613 else if(aCustomMessageId==KUidActivationOOM) |
|
614 { |
|
615 User::Leave(KErrNoMemory); |
|
616 } |
|
617 else if(aCustomMessageId==KUidActivationPanic) |
|
618 { |
|
619 User::Panic(APP_TEXT,1); |
|
620 } |
|
621 else if(aCustomMessageId==KUidSlowActivation) |
|
622 { |
|
623 User::After(5000000); |
|
624 } |
|
625 else if(aCustomMessageId==KUidEndurance) |
|
626 { |
|
627 STATIC_CAST(CTestAppUi&,AppUi()).StartEnduranceTest(); |
|
628 } |
|
629 else if(aCustomMessageId==KUidSluggishActivation) |
|
630 { |
|
631 User::After(1000000); // 1.0 sec |
|
632 } |
|
633 else if(aCustomMessageId==KUidActivationExit) |
|
634 { |
|
635 STATIC_CAST(CTestAppUi&,AppUi()).IdleExit(); |
|
636 } |
|
637 else if(aCustomMessageId==KUidActivateAgain) |
|
638 { |
|
639 STATIC_CAST(CCoeAppUi&,AppUi()).ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewTwo)); |
|
640 } |
|
641 |
|
642 CleanupStack::Pop(); // TCleanupItem |
|
643 |
|
644 iControl->DrawableWindow()->SetOrdinalPosition(0); |
|
645 iActivated=ETrue; |
|
646 } |
|
647 |
|
648 void CTestView::DoDeactivate() |
|
649 { |
|
650 if (!iActivated) |
|
651 { |
|
652 RDebug::Print(_L("%x,%x deactivated when not active"),ViewId().iAppUid.iUid,ViewId().iViewUid.iUid); |
|
653 ASSERT(iActivated); |
|
654 } |
|
655 if (iDeactivationPanic) |
|
656 { |
|
657 RDebug::Print(_L("TVIEW2 : Deactivation Panic")); |
|
658 User::Panic(APP_TEXT,1); |
|
659 } |
|
660 else if (iSlowDeactivation) |
|
661 { |
|
662 RDebug::Print(_L("TVIEW2 : Slow Deactivation")); |
|
663 User::After(5000000); // 5 sec |
|
664 iSlowDeactivation=EFalse; |
|
665 } |
|
666 else if (iSluggishDeactivation) |
|
667 { |
|
668 RDebug::Print(_L("TVIEW2 : Sluggish Deactivation")); |
|
669 User::After(500000); // 0.5 sec |
|
670 iSluggishDeactivation=EFalse; |
|
671 } |
|
672 iActivated=EFalse; |
|
673 } |
|
674 |
|
675 void CTestView::HandleCommandL(TInt aCommand) |
|
676 { |
|
677 switch (aCommand) |
|
678 { |
|
679 case ETaskToAppAViewOne: |
|
680 ActivateViewL(TVwsViewId(KUidViewAppOne,KUidViewOne)); |
|
681 break; |
|
682 case ETaskToAppAViewTwo: |
|
683 ActivateViewL(TVwsViewId(KUidViewAppOne,KUidViewTwo)); |
|
684 break; |
|
685 case EDNLViewAppC: |
|
686 //ActivateViewL(TVwsViewId(KUidViewAppCApp,KUidViewAppCOne)); |
|
687 break; |
|
688 default: |
|
689 break; |
|
690 } |
|
691 } |
|
692 |
|
693 void CTestView::SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/) |
|
694 { |
|
695 } |
|
696 |
|
697 void CTestView::Reset() |
|
698 { |
|
699 delete iControl; |
|
700 iControl=NULL; |
|
701 } |
|
702 |
|
703 |
|
704 // |
|
705 // Class CTestViewDeactivationObserver |
|
706 // |
|
707 |
|
708 CTestViewActivationObserver::CTestViewActivationObserver(CCoeAppUi& aAppUi) |
|
709 : iAppUi(aAppUi), iActivationCount(0) |
|
710 {} |
|
711 |
|
712 void CTestViewActivationObserver::ConstructL() |
|
713 { |
|
714 iAppUi.NotifyNextActivation(*this); |
|
715 } |
|
716 |
|
717 const TInt KLargeInt=KMaxTInt/2; |
|
718 |
|
719 void CTestViewActivationObserver::HandleViewActivation(const TVwsViewId& /*aNewlyActivatedViewId*/,const TVwsViewId& /*aViewIdToBeDeactivated*/) |
|
720 { |
|
721 // reset count if it gets big |
|
722 if (iActivationCount>KLargeInt) |
|
723 { |
|
724 iActivationCount=0; |
|
725 } |
|
726 iActivationCount++; |
|
727 iAppUi.NotifyNextActivation(*this); |
|
728 } |