aboutsummaryrefslogtreecommitdiffstats
path: root/distrib/sdl-1.2.15/src/main/symbian/EKA2/sdlexe.cpp
blob: bb160c409028107de2f405b86e53fc16d5b71473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
//  INCLUDES
#include <aknapp.h>
#include <aknappui.h>
#include <eikdoc.h>
#include <sdlepocapi.h>
#include <bautils.h>
#include <eikstart.h>
#include <badesca.h>
#include <bautils.h>
#include <apgcli.h>
#include <sdlmain.h>
#include <eikedwin.h>
#include <eiklabel.h>
#include <sdlexe.rsg>
#include <aknglobalmsgquery.h>
#include <apgwgnam.h> 



//  FORWARD DECLARATIONS
class CApaDocument;


//const TUid KSDLUID = { 0xF01F605E };

LOCAL_C void MakeCCmdLineL(const TDesC8& aParam, CDesC8Array& aArray)
    { 
    
    const TChar dq('\"');

    TLex8 lex(aParam);
    TBool in = EFalse;

    lex.SkipSpaceAndMark();

    while(!lex.Eos())
        {
        TPtrC8 ptr;
        if(in)
            {
            const TPtrC8 rem = lex.RemainderFromMark();
            const TInt pos = rem.Locate(dq);
            if(pos > 0)
                {
                lex.Inc(pos);
                ptr.Set(lex.MarkedToken());
                lex.SkipAndMark(1);
                }
            else
                {
                ptr.Set(rem);
                }
            in = EFalse;
            }
        else
            {
            ptr.Set(lex.NextToken());
            const TInt pos = ptr.Locate(dq);
            if(pos == 0)
                {
                lex.UnGetToMark();
                lex.SkipAndMark(1);
                in = ETrue;
                continue; // back to in brace
                }
            else
                lex.SkipSpaceAndMark();
            }
        
        aArray.AppendL(ptr);

        }
    }  
    
NONSHARABLE_CLASS(TVirtualCursor) : public MOverlay
	{
	public:
		TVirtualCursor();
		void Set(const TRect& aRect, CFbsBitmap* aBmp, CFbsBitmap* aAlpha);
		void Move(TInt aX, TInt aY);
		void MakeEvent(TWsEvent& aEvent, const TPoint& aBasePos) const;
		void Toggle();
		TBool IsOn() const;
	private:
    	void Draw(CBitmapContext& aGc, const TRect& aTargetRect, const TSize& aSize);
	private:
		TRect iRect;
		TPoint iInc;
		TPoint iPos;
		TBool iIsOn;
		CFbsBitmap* iCBmp;
		CFbsBitmap* iAlpha;
	};
	
	
TVirtualCursor::TVirtualCursor() :  iInc(0, 0), iIsOn(EFalse), iCBmp(NULL)
	{	
	}
	
const TInt KMaxMove = 10;	

void TVirtualCursor::Move(TInt aX, TInt aY)
	{
	if(aX > 0 && iInc.iX > 0)
			++iInc.iX;
	else if(aX < 0 && iInc.iX < 0)
			--iInc.iX;
	else
		iInc.iX = aX;

	if(aY > 0 && iInc.iY > 0)
			++iInc.iY;
	else if(aY < 0 && iInc.iY < 0)
			--iInc.iY;
	else
			iInc.iY = aY;
	
	iInc.iX = Min(KMaxMove, iInc.iX); 
	
	iInc.iX = Max(-KMaxMove, iInc.iX);
	
	iInc.iY = Min(KMaxMove, iInc.iY);
	
	iInc.iY =Max(-KMaxMove, iInc.iY);
	
	const TPoint pos = iPos + iInc;
	if(iRect.Contains(pos))
		{
		iPos = pos;
		}
	else
		{
		iInc = TPoint(0, 0);	
		}
	}
	
	
void TVirtualCursor::Toggle()
	{
	iIsOn = !iIsOn;
	}
	
	
TBool TVirtualCursor::IsOn() const
	{
	return iIsOn;
	}
	
void TVirtualCursor::Set(const TRect& aRect, CFbsBitmap* aBmp, CFbsBitmap* aAlpha)
	{
	iRect = aRect;
	iCBmp = aBmp;
	iAlpha = aAlpha;
	}
	
		
void TVirtualCursor::MakeEvent(TWsEvent& aEvent, const TPoint& aBasePos) const
	{
 	aEvent.SetType(EEventPointer),
	aEvent.SetTimeNow();
	TPointerEvent& pointer = *aEvent.Pointer();	
	pointer.iType = TPointerEvent::EButton1Down;
	pointer.iPosition = iPos;
	pointer.iParentPosition = aBasePos;
	}
	
	
void TVirtualCursor::Draw(CBitmapContext& aGc, const TRect& /*aTargetRect*/, const TSize& /*aSize*/)
	{
	if(iIsOn && iCBmp != NULL)
		{
		const TRect rect(TPoint(0, 0), iCBmp->SizeInPixels());
		aGc.AlphaBlendBitmaps(iPos, iCBmp, rect, iAlpha, TPoint(0, 0));
		}
	
	}	

NONSHARABLE_CLASS(TSdlClass)
	{
	public:
		TSdlClass();
		void SetMain(const TMainFunc& aFunc, TInt aFlags, MSDLMainObs* aObs, TInt aExeFlags);
		TInt SdlFlags() const;
		const TMainFunc& Main() const;
		void SendEvent(TInt aEvent, TInt aParam, CSDL* aSDL);
		TInt AppFlags() const; 
		void AppFlags(TInt aFlags); 
	private:
		TMainFunc iFunc;
		TInt iSdlFlags;
		TInt iExeFlags;
		MSDLMainObs* iObs;
	};
	
	
void TSdlClass::AppFlags(TInt aFlags)
	{
	iExeFlags |= aFlags;
	}
	
void TSdlClass::SendEvent(TInt aEvent, TInt aParam, CSDL* aSDL)
	{
	if(iObs != NULL)
		iObs->SDLMainEvent(aEvent, aParam, aSDL);
	}
	
TInt TSdlClass::AppFlags() const
	{
	return iExeFlags;
	}
	
void TSdlClass::SetMain(const TMainFunc& aFunc, TInt aFlags, MSDLMainObs* aObs, TInt aExeFlags)
	{	
	iFunc = aFunc;
	iSdlFlags = aFlags;
	iExeFlags = aExeFlags;
	iObs = aObs;
	}
	
const TMainFunc& TSdlClass::Main() const
	{
	return iFunc;
	}
	
 
 TInt TSdlClass::SdlFlags() const
 	{
 	return iSdlFlags;
 	}
 	

 	
TSdlClass::TSdlClass()
	{
	Mem::FillZ(this, sizeof(this));
	}
 
TSdlClass gSDLClass;    
    
	     
////////////////////////////////////////////////////////////////    

NONSHARABLE_CLASS(CSDLApplication) : public CAknApplication
    {
    public:
    	CSDLApplication();
    private:
        CApaDocument* CreateDocumentL(); 
        TFileName ResourceFileName() const;
        TUid AppDllUid() const; 
      		void FindMeL();
     		TUid iUid;
    };
    
NONSHARABLE_CLASS(CSDLDocument)  : public CEikDocument
    {
    public:
        CSDLDocument(CEikApplication& aApp);
     private:
     	CEikAppUi* CreateAppUiL();
     
     };
     
 ////////////////////////////////////////////////////////////////////
 
     
NONSHARABLE_CLASS(MExitWait)
 	{
 	public:
 		virtual void DoExit(TInt aErr) = 0;
 	};   
 
///////////////////////////////////////////////////////////////////////// 
 	
NONSHARABLE_CLASS(CExitWait) : public CActive
 	{
 	public:
 		CExitWait(MExitWait& aWait);
 		~CExitWait();
 	private:
 		void RunL();
 		void DoCancel();
 	private:
 		MExitWait& iWait;
 		TRequestStatus* iStatusPtr;
 	};
 	
//////////////////////////////////////////////////////////////////////// 

 	
NONSHARABLE_CLASS(CSDLWin) : public CCoeControl
	{
	public:
		void ConstructL(const TRect& aRect);
		RWindow& GetWindow() const;
		void SetNoDraw();
	private:
		void Draw(const TRect& aRect) const;
	private:
		TBool iNoDraw;
	}; 	
	

////////////////////////////////////////////////////////////////////////////	
     
NONSHARABLE_CLASS(CSDLAppUi) : public CAknAppUi, public MExitWait, MSDLObserver
	{
	public:
		~CSDLAppUi();
   	private: // New functions
 		void ConstructL(); 
   	void HandleCommandL(TInt aCommand);
 		void HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination);
 		void HandleResourceChangeL(TInt aType);
        
   		void DoExit(TInt aErr);
   	
   		TInt SdlEvent(TInt aEvent, TInt aParam);
    	TInt SdlThreadEvent(TInt aEvent, TInt aParam);
    
    	void StartL();
    	static TBool StartL(TAny* aThis);
    	
    	TBool ParamEditorL(TDes& aCheat);
    	
    	TBool ProcessCommandParametersL(CApaCommandLine &aCommandLine);
    	
    	void PrepareToExit();
    	void HandleConsoleWindowL();
    	void HandleConsoleWindow();
    	void HandleForegroundEventL(TBool aForeground);
    	
    	static TBool IdleRequestL(TAny* aThis);
    	
    	TBool HandleKeyL(const TWsEvent& aEvent);
    
    	
	private:
		CExitWait* iWait;
		CSDLWin* iSDLWin;
		CSDL* iSdl;
		CIdle* iStarter;
		TBool iExitRequest;
		CDesC8Array* iParams;
		TInt iResOffset;
		CIdle* iIdle;
		TInt iStdOut;
		TVirtualCursor iCursor;
		CFbsBitmap*	iCBmp;
		CFbsBitmap*	iAlpha;
	//	TTime iLastPress;
	//	CSDL::TOrientationMode iOrientation;
	};
	
////////////////////////////////////////////////////////////////////////////////////////7

CApaDocument* CSDLApplication::CreateDocumentL()
	{
	return new (ELeave) CSDLDocument(*this);
	}
	
TUid CSDLApplication::AppDllUid() const
	{
	return iUid;
	}
	
	
CSDLApplication::CSDLApplication()
	{
	TRAPD(err, FindMeL());
	ASSERT(err == KErrNone);
	}	
	
void CSDLApplication::FindMeL()
	{
	RApaLsSession apa;
	User::LeaveIfError(apa.Connect());
	CleanupClosePushL(apa);
	User::LeaveIfError(apa.GetAllApps());
	TFileName name = RProcess().FileName();
	TApaAppInfo info;
	while(apa.GetNextApp(info) == KErrNone)
		{
		if(info.iFullName.CompareF(name) == 0)
			{
			iUid = info.iUid;
			break;
			}
		}
	CleanupStack::PopAndDestroy();
	}
	
TFileName CSDLApplication::ResourceFileName() const
	{
	return KNullDesC();
	}
	
///////////////////////////////////////////////////////////////////////////////////////////

CExitWait::CExitWait(MExitWait& aWait) : CActive(CActive::EPriorityStandard), iWait(aWait)
	{
	CActiveScheduler::Add(this);
	SetActive();
	iStatusPtr = &iStatus;
	}
	
CExitWait::~CExitWait()
	{
	Cancel();
	}
 
void CExitWait::RunL()
	{
	if(iStatusPtr != NULL )
		iWait.DoExit(iStatus.Int());
	}
	
void CExitWait::DoCancel()
	{
	if(iStatusPtr != NULL )
		User::RequestComplete(iStatusPtr , KErrCancel);
	}
	

//////////////////////////////////////////////////////////////////////////////////////////////

CSDLDocument::CSDLDocument(CEikApplication& aApp) : CEikDocument(aApp)
	{}
    
CEikAppUi* CSDLDocument::CreateAppUiL()
	{
	return new (ELeave) CSDLAppUi;
	}
	
///////////////////////////////////////////////////////////////////////////	
	
void CSDLWin:: ConstructL(const TRect& aRect)	
	{
	CreateWindowL();
	SetRect(aRect);
	ActivateL();
	}
	
	
RWindow& CSDLWin::GetWindow() const
	{
	return Window();
	}
	

void CSDLWin::Draw(const TRect& /*aRect*/) const
	{
	if(!iNoDraw)
		{
		CWindowGc& gc = SystemGc();
		gc.SetPenStyle(CGraphicsContext::ESolidPen);
		gc.SetPenColor(KRgbGray);
		gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
		gc.SetBrushColor(0xaaaaaa);
		gc.DrawRect(Rect());
		}
	}	
	
void CSDLWin::SetNoDraw()
	{
	iNoDraw = ETrue;
	}

/////////////////////////////////////////////////////////////////////////			
	
CSDLAppUi::~CSDLAppUi()
	{
	if(iIdle)
		iIdle->Cancel();
	delete iIdle;
	if(iStarter != NULL)
		iStarter->Cancel();
	delete iStarter;
	delete iWait;
	delete iSdl;
	delete iSDLWin;
	delete iParams;
	delete iCBmp;
	delete iAlpha;
	}
	
		
void CSDLAppUi::ConstructL()
 	{
 	BaseConstructL(ENoAppResourceFile | ENoScreenFurniture);
 	
 	
 	RLibrary lib;
 	User::LeaveIfError(lib.Load(_L("sdlexe.dll")));
 	TFileName name = lib.FileName();
 	lib.Close();
 	name.Replace(3, name.Length() - 3, _L("resource\\apps\\sdlexe.rsc"));
 	BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(), name);
 	iResOffset = iCoeEnv->AddResourceFileL(name);
 	
 	name.Replace(name.Length() - 3, 3, _L("mbm"));
	
	TEntry e;
	const TInt err = iEikonEnv->FsSession().Entry(name, e);
	
	iCBmp = iEikonEnv->CreateBitmapL(name, 0);
	iAlpha = iEikonEnv->CreateBitmapL(name, 1);	
 	
 	iIdle = CIdle::NewL(CActive::EPriorityIdle);
 	
 	iSDLWin = new (ELeave) CSDLWin;
 	iSDLWin->ConstructL(ApplicationRect());
 	
 	iSdl = CSDL::NewL(gSDLClass.SdlFlags());
 	
 	gSDLClass.SendEvent(MSDLMainObs::ESDLCreated, 0, iSdl);
 	
 	iSdl->SetObserver(this);
 	iSdl->DisableKeyBlocking(*this);
 	iSdl->SetContainerWindowL(
 					iSDLWin->GetWindow(), 
        			iEikonEnv->WsSession(),
        			*iEikonEnv->ScreenDevice());
    iSdl->AppendOverlay(iCursor, 0);
    
    iCursor.Set(TRect(TPoint(0, 0), iSDLWin->Size()), iCBmp, iAlpha);
        			
    iStarter = CIdle::NewL(CActive::EPriorityLow);   
    iStarter->Start(TCallBack(StartL, this));
    
    
 	}
 	


TBool CSDLAppUi::StartL(TAny* aThis)
	{
	static_cast<CSDLAppUi*>(aThis)->StartL();
	return EFalse;
	}
	
	
void CSDLAppUi::PrepareToExit()
	{
	CAknAppUiBase::PrepareToExit(); //aknappu::PrepareToExit crashes
	iCoeEnv->DeleteResourceFile(iResOffset);
	}
	
TBool CSDLAppUi::ProcessCommandParametersL(CApaCommandLine &aCommandLine)
	{
	const TPtrC8 cmdLine = aCommandLine.TailEnd();
	iParams = new (ELeave) CDesC8ArrayFlat(8);
	MakeCCmdLineL(cmdLine, *iParams);
	return EFalse;
	}
 	
 
 TBool CSDLAppUi::ParamEditorL(TDes& aCheat)
	{
	CAknTextQueryDialog* query = CAknTextQueryDialog::NewL(aCheat);
	CleanupStack::PushL(query);
	query->SetPromptL(_L("Enter parameters"));
	CleanupStack::Pop();
	return query->ExecuteLD(R_PARAMEDITOR);
	}
 	
 void CSDLAppUi::StartL()	
 	{ 		
 	if(gSDLClass.AppFlags() & SDLEnv::EParamQuery)
 		{
 		TBuf8<256> cmd;
 		RFile file;
 		TInt err = file.Open(iEikonEnv->FsSession(), _L("sdl_param.txt"),EFileRead);
 		if(err == KErrNone)
 			{
 			file.Read(cmd);
 			file.Close();	
 			MakeCCmdLineL(cmd, *iParams);
 			}
 		if(err != KErrNone || gSDLClass.AppFlags() & (SDLEnv::EParamQueryDialog ^ SDLEnv::EParamQuery))
 			{
 			TBuf<256> buffer;
 			if(ParamEditorL(buffer))
 				{
 				cmd.Copy(buffer);
 				MakeCCmdLineL(cmd, *iParams);
 				}	
 			}
 		}
 	iWait = new (ELeave) CExitWait(*this);
 	iSdl->CallMainL(gSDLClass.Main(), &iWait->iStatus, iParams, CSDL::ENoParamFlags, 0xA000);
 	}
 	
void CSDLAppUi::HandleCommandL(TInt aCommand)
	{
	switch(aCommand)
		{
		case EAknSoftkeyBack:
 		case EAknSoftkeyExit:
		case EAknCmdExit:
		case EEikCmdExit:
			gSDLClass.AppFlags(SDLEnv::EAllowConsoleView); 
		    if(iWait == NULL || !iWait->IsActive() || iSdl == NULL)
		    	{
		    	Exit();
		    	}	
			  else if(!iExitRequest)
			  	{
			  	iExitRequest = ETrue; //trick how SDL can be closed!
			  	iSdl->Suspend();
			  	} 
			break;
		}
	}
	

	
TBool CSDLAppUi::HandleKeyL(const TWsEvent& aEvent)
	{
	const TInt type = aEvent.Type();
	if(!(type == EEventKey || type == EEventKeyUp || type == EEventKeyDown))
 			{
 			return ETrue;
 			}
 	const TKeyEvent& key = *aEvent.Key();
	if((key.iScanCode == EStdKeyYes) && (gSDLClass.AppFlags() & SDLEnv::EVirtualMouse))
 		{
 		if(type == EEventKeyUp)
 			{
 			iCursor.Toggle();
 			iSdl->RedrawRequest();	
 			}
 		return EFalse;
		}
	if(iCursor.IsOn())
		{
		switch(key.iScanCode)
			{
			case EStdKeyUpArrow:
				iCursor.Move(0, -1);
				break;
			case EStdKeyDownArrow:
				iCursor.Move(0, 1);
				break;
			case EStdKeyLeftArrow:
				iCursor.Move(-1, 0);
				break;
			case EStdKeyRightArrow:
				iCursor.Move(1, 0);
				break; 
			case EStdKeyDevice3:
				if(type == EEventKeyUp)
					{
					TWsEvent event;
					iCursor.MakeEvent(event, iSDLWin->Position());
					iSdl->AppendWsEvent(event);
					}
				return EFalse;
			default:
				return ETrue;
			}
		iSdl->RedrawRequest();	
		return EFalse;
		}
	return ETrue;
	}
 		
 void CSDLAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination)
 	{
 	if(iSdl && iWait && HandleKeyL(aEvent))
 		iSdl->AppendWsEvent(aEvent);
 	CAknAppUi::HandleWsEventL(aEvent, aDestination);
 	}
 	
 void CSDLAppUi::HandleResourceChangeL(TInt aType)
 	{
    CAknAppUi::HandleResourceChangeL(aType);
    if(aType == KEikDynamicLayoutVariantSwitch)
        {  	
        iSDLWin->SetRect(ApplicationRect());
      	iSdl->SetContainerWindowL(
      				iSDLWin->GetWindow(),
        			iEikonEnv->WsSession(),
        			*iEikonEnv->ScreenDevice());
        }
 	}
 	
 	
void CSDLAppUi::DoExit(TInt/*Err*/)
   	{
   	iExitRequest = ETrue;
   	Exit();
   	}

    
 TInt CSDLAppUi::SdlThreadEvent(TInt aEvent, TInt /*aParam*/)    
	{
	switch(aEvent)
		{
		case MSDLObserver::EEventResume:
			break;
		case MSDLObserver::EEventSuspend:
			if(iExitRequest)
				return MSDLObserver::ESuspendNoSuspend;
			break;
		case MSDLObserver::EEventWindowReserved:
			break;
		case MSDLObserver::EEventWindowNotAvailable:
			break;
		case MSDLObserver::EEventScreenSizeChanged:
            break;
		}
	return MSDLObserver::EParameterNone;	
	}
	    
TInt CSDLAppUi::SdlEvent(TInt aEvent, TInt /*aParam*/)    
	{
	switch(aEvent)
		{
		case MSDLObserver::EEventResume:
			break;
		case MSDLObserver::EEventSuspend:
			if(iExitRequest)
				return MSDLObserver::ESuspendNoSuspend;
			break;
		case MSDLObserver::EEventWindowReserved:
			break;
		case MSDLObserver::EEventWindowNotAvailable:
			{
			TRAP_IGNORE(HandleConsoleWindowL());
			}
			break;
		case MSDLObserver::EEventScreenSizeChanged:
     		break;
		case MSDLObserver::EEventKeyMapInit:
			break;
		case MSDLObserver::EEventMainExit:
			if(iStdOut != 0)
				{
				gSDLClass.AppFlags(SDLEnv::EAllowConsoleView); 
				iEikonEnv->WsSession().SetWindowGroupOrdinalPosition(iStdOut, 0);
				}
			break;
		}
	return MSDLObserver::EParameterNone;
	}
	
void CSDLAppUi::HandleForegroundEventL(TBool aForeground)
	{
	CAknAppUi::HandleForegroundEventL(aForeground);	
	if(!aForeground)
		HandleConsoleWindow();
	}
	
void CSDLAppUi::HandleConsoleWindow()
	{
	if(!iIdle->IsActive())
		iIdle->Start(TCallBack(IdleRequestL, this));
	}
	
TBool CSDLAppUi::IdleRequestL(TAny* aThis)
	{
	static_cast<CSDLAppUi*>(aThis)->HandleConsoleWindowL();
	return EFalse;
	}

void CSDLAppUi::HandleConsoleWindowL()
	{
	if(gSDLClass.AppFlags() & SDLEnv::EAllowConsoleView)
		{
		return;
		}
	RWsSession& ses = iEikonEnv->WsSession();
	const TInt focus = ses.GetFocusWindowGroup();
	CApaWindowGroupName* name = CApaWindowGroupName::NewLC(ses, focus);
	const TPtrC caption = name->Caption();
	if(0 == caption.CompareF(_L("STDOUT")))
		{
		iStdOut = focus;
		ses.SetWindowGroupOrdinalPosition(iEikonEnv->RootWin().Identifier(), 0);
		}
	CleanupStack::PopAndDestroy(); //name
	}
	
	
////////////////////////////////////////////////////////////////////////


CApaApplication* NewApplication()
    {
    return new CSDLApplication();
    }

	
EXPORT_C TInt SDLEnv::SetMain(const TMainFunc& aFunc, TInt aSdlFlags, MSDLMainObs* aObs, TInt aSdlExeFlags)
	{
	gSDLClass.SetMain(aFunc, aSdlFlags, aObs, aSdlExeFlags);
  	return EikStart::RunApplication(NewApplication);
	}	
	
//////////////////////////////////////////////////////////////////////

TInt SDLUiPrint(const TDesC8& /*aInfo*/)
    {
    return KErrNotFound;
    }