4 #include <sdlepocapi.h>
14 #include <aknglobalmsgquery.h>
19 LOCAL_C
void MakeCCmdLineL(const TDesC8
& aParam
, CDesC8Array
& aArray
)
26 lex
.SkipSpaceAndMark();
33 const TPtrC8 rem
= lex
.RemainderFromMark();
34 const int pos
= rem
.Locate(dq
);
38 ptr
.Set(lex
.MarkedToken());
49 ptr
.Set(lex
.NextToken());
50 const int pos
= ptr
.Locate(dq
);
56 continue; // back to in brace
59 lex
.SkipSpaceAndMark();
66 NONSHARABLE_CLASS(TSdlClass
)
70 void SetMain(const TMainFunc
& aFunc
, int aFlags
, MSDLMainObs
* aObs
, int aExeFlags
);
72 const TMainFunc
& Main() const;
73 void SendEvent(int aEvent
, int aParam
, CSDL
* aSDL
);
75 void AppFlags(int aFlags
);
85 void TSdlClass::AppFlags(int aFlags
)
90 void TSdlClass::SendEvent(int aEvent
, int aParam
, CSDL
* aSDL
)
93 iObs
->SDLMainEvent(aEvent
, aParam
, aSDL
);
96 int TSdlClass::AppFlags() const
101 void TSdlClass::SetMain(const TMainFunc
& aFunc
, int aFlags
, MSDLMainObs
* aObs
, int aExeFlags
)
105 iExeFlags
= aExeFlags
;
109 const TMainFunc
& TSdlClass::Main() const
115 int TSdlClass::SdlFlags() const
120 TSdlClass::TSdlClass()
122 Mem::FillZ(this, sizeof(this));
127 ////////////////////////////////////////////////////////////////
129 NONSHARABLE_CLASS(CSDLApplication
) : public CAknApplication
135 CApaDocument
* CreateDocumentL();
136 TFileName
ResourceFileName() const;
137 TUid
AppDllUid() const;
143 NONSHARABLE_CLASS(CSDLDocument
) : public CEikDocument
146 CSDLDocument(CEikApplication
& aApp
);
149 CEikAppUi
* CreateAppUiL();
152 ////////////////////////////////////////////////////////////////////
154 NONSHARABLE_CLASS(CExitWait
) : public CActive
157 CExitWait(CAknAppUi
& aWait
);
165 TRequestStatus
* iStatusPtr
;
168 ////////////////////////////////////////////////////////////////////////
170 NONSHARABLE_CLASS(CSDLWin
) : public CCoeControl
173 CSDLWin() : m_draw(false) {}
174 void ConstructL(const TRect
& aRect
);
175 RWindow
& GetWindow() const;
176 void SetDraw(bool draw
) { m_draw
= draw
; }
179 void Draw(const TRect
& aRect
) const;
184 ////////////////////////////////////////////////////////////////////////////
186 NONSHARABLE_CLASS(CSDLAppUi
) : public CAknAppUi
193 void HandleCommandL(int aCommand
);
194 void HandleWsEventL(const TWsEvent
& aEvent
, CCoeControl
* aDestination
);
195 void HandleResourceChangeL(int aType
);
198 static TBool
StartL(TAny
* aThis
);
200 TBool
ParamEditorL(TDes
& aCheat
);
202 TBool
ProcessCommandParametersL(CApaCommandLine
&aCommandLine
);
204 void HandleForegroundEventL(TBool aForeground
);
210 CDesC8Array
* iParams
;
214 ////////////////////////////////////////////////////////////////////////////////////////
216 CApaDocument
* CSDLApplication::CreateDocumentL()
218 return new (ELeave
) CSDLDocument(*this);
221 TUid
CSDLApplication::AppDllUid() const
226 CSDLApplication::CSDLApplication()
228 TRAPD(err
, FindMeL());
229 ASSERT(err
== KErrNone
);
232 void CSDLApplication::FindMeL()
235 User::LeaveIfError(apa
.Connect());
236 CleanupClosePushL(apa
);
237 User::LeaveIfError(apa
.GetAllApps());
238 TFileName name
= RProcess().FileName();
240 while(apa
.GetNextApp(info
) == KErrNone
)
242 if(info
.iFullName
.CompareF(name
) == 0)
248 CleanupStack::PopAndDestroy();
251 TFileName
CSDLApplication::ResourceFileName() const
256 ///////////////////////////////////////////////////////////////////////////////////////////
258 CExitWait::CExitWait(CAknAppUi
& aWait
) : CActive(CActive::EPriorityStandard
), iWait(aWait
)
260 CActiveScheduler::Add(this);
262 iStatusPtr
= &iStatus
;
265 CExitWait::~CExitWait()
270 void CExitWait::RunL()
272 if(iStatusPtr
!= NULL
)
276 void CExitWait::DoCancel()
278 if(iStatusPtr
!= NULL
)
279 User::RequestComplete(iStatusPtr
, KErrCancel
);
282 //////////////////////////////////////////////////////////////////////////////////////////////
284 CSDLDocument::CSDLDocument(CEikApplication
& aApp
) : CEikDocument(aApp
)
287 CEikAppUi
* CSDLDocument::CreateAppUiL()
289 return new (ELeave
) CSDLAppUi
;
292 ///////////////////////////////////////////////////////////////////////////
294 void CSDLWin::ConstructL(const TRect
& aRect
)
301 RWindow
& CSDLWin::GetWindow() const
306 void CSDLWin::Draw(const TRect
& /*aRect*/) const
310 CWindowGc
& gc
= SystemGc();
311 gc
.SetPenStyle(CGraphicsContext::ESolidPen
);
312 gc
.SetPenColor(KRgbGray
);
313 gc
.SetBrushStyle(CGraphicsContext::ESolidBrush
);
314 gc
.SetBrushColor(0x000000);
319 /////////////////////////////////////////////////////////////////////////
321 CSDLAppUi::~CSDLAppUi()
332 void CSDLAppUi::ConstructL()
334 BaseConstructL(ENoAppResourceFile
| ENoScreenFurniture
);
339 fs
.PrivatePath(name
);
341 name
.Append( _L("sdlexe.rsc") );
342 name
.Insert( 0, _L("C:") );
343 iResOffset
= iCoeEnv
->AddResourceFileL(name
);
345 iSDLWin
= new (ELeave
) CSDLWin
;
346 iSDLWin
->ConstructL(ApplicationRect());
348 iSdl
= CSDL::NewL(gSDLClass
.SdlFlags());
350 gSDLClass
.SendEvent(MSDLMainObs::ESDLCreated
, 0, iSdl
);
352 SetKeyBlockMode(ENoKeyBlock
);
354 iSdl
->SetContainerWindowL(iSDLWin
->GetWindow(), iEikonEnv
->WsSession(), *iEikonEnv
->ScreenDevice());
356 iStarter
= CIdle::NewL(CActive::EPriorityLow
);
357 iStarter
->Start(TCallBack(StartL
, this));
360 TBool
CSDLAppUi::StartL(TAny
* aThis
)
362 static_cast<CSDLAppUi
*>(aThis
)->StartL();
366 TBool
CSDLAppUi::ProcessCommandParametersL(CApaCommandLine
&aCommandLine
)
368 const TPtrC8 cmdLine
= aCommandLine
.TailEnd();
369 iParams
= new (ELeave
) CDesC8ArrayFlat(8);
370 MakeCCmdLineL(cmdLine
, *iParams
);
374 TBool
CSDLAppUi::ParamEditorL(TDes
& aCheat
)
376 CAknTextQueryDialog
* query
= CAknTextQueryDialog::NewL(aCheat
);
377 CleanupStack::PushL(query
);
378 query
->SetPromptL(_L("Enter parameters"));
380 return query
->ExecuteLD(R_PARAMEDITOR
);
383 void CSDLAppUi::StartL()
385 if(gSDLClass
.AppFlags() & SDLEnv::EParamQuery
)
387 iSDLWin
->SetDraw(true);
391 int err
= file
.Open(iEikonEnv
->FsSession(), _L("sdl_param.txt"),EFileRead
);
396 MakeCCmdLineL(cmd
, *iParams
);
398 if(err
!= KErrNone
|| gSDLClass
.AppFlags() & (SDLEnv::EParamQueryDialog
^ SDLEnv::EParamQuery
))
401 if(ParamEditorL(buffer
))
404 MakeCCmdLineL(cmd
, *iParams
);
408 iSDLWin
->SetDraw(false);
410 iCoeEnv
->DeleteResourceFile(iResOffset
);
412 iWait
= new (ELeave
) CExitWait(*this);
413 iSdl
->CallMainL(gSDLClass
.Main(), &iWait
->iStatus
, iParams
, 0xA000);
416 void CSDLAppUi::HandleCommandL(int aCommand
)
420 case EAknSoftkeyBack
:
421 case EAknSoftkeyExit
:
424 if(iWait
== NULL
|| !iWait
->IsActive() || iSdl
== NULL
)
431 event
.SetType(EEventSwitchOff
), event
.SetTimeNow();
432 iSdl
->AppendWsEvent(event
);
441 void CSDLAppUi::HandleWsEventL(const TWsEvent
& aEvent
, CCoeControl
* aDestination
)
443 if(aEvent
.Type() == KAknUidValueEndKeyCloseEvent
)
445 if(iWait
!= NULL
&& iWait
->IsActive() && iSdl
!= NULL
)
448 event
.SetType(EEventSwitchOff
), event
.SetTimeNow();
449 iSdl
->AppendWsEvent(event
);
455 iSdl
->AppendWsEvent(aEvent
);
456 CAknAppUi::HandleWsEventL(aEvent
, aDestination
);
459 void CSDLAppUi::HandleResourceChangeL(int aType
)
461 CAknAppUi::HandleResourceChangeL(aType
);
462 if(aType
== KEikDynamicLayoutVariantSwitch
)
464 iSDLWin
->SetRect(ApplicationRect());
465 iSdl
->SetContainerWindowL(iSDLWin
->GetWindow(), iEikonEnv
->WsSession(), *iEikonEnv
->ScreenDevice());
470 void CSDLAppUi::HandleForegroundEventL(TBool aForeground
)
472 CAknAppUi::HandleForegroundEventL(aForeground
);
475 ////////////////////////////////////////////////////////////////////////
477 CApaApplication
* NewApplication()
479 return new CSDLApplication();
482 EXPORT_C
int SDLEnv::SetMain(const TMainFunc
& aFunc
, int aSdlFlags
, MSDLMainObs
* aObs
, int aSdlExeFlags
)
484 gSDLClass
.SetMain(aFunc
, aSdlFlags
, aObs
, aSdlExeFlags
);
485 return EikStart::RunApplication(NewApplication
);