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 void ConstructL(const TRect
& aRect
);
174 RWindow
& GetWindow() const;
177 void Draw(const TRect
& aRect
) const;
180 ////////////////////////////////////////////////////////////////////////////
182 NONSHARABLE_CLASS(CSDLAppUi
) : public CAknAppUi
189 void HandleCommandL(int aCommand
);
190 void HandleWsEventL(const TWsEvent
& aEvent
, CCoeControl
* aDestination
);
191 void HandleResourceChangeL(int aType
);
194 static TBool
StartL(TAny
* aThis
);
196 TBool
ParamEditorL(TDes
& aCheat
);
198 TBool
ProcessCommandParametersL(CApaCommandLine
&aCommandLine
);
200 void HandleForegroundEventL(TBool aForeground
);
206 CDesC8Array
* iParams
;
210 ////////////////////////////////////////////////////////////////////////////////////////
212 CApaDocument
* CSDLApplication::CreateDocumentL()
214 return new (ELeave
) CSDLDocument(*this);
217 TUid
CSDLApplication::AppDllUid() const
222 CSDLApplication::CSDLApplication()
224 TRAPD(err
, FindMeL());
225 ASSERT(err
== KErrNone
);
228 void CSDLApplication::FindMeL()
231 User::LeaveIfError(apa
.Connect());
232 CleanupClosePushL(apa
);
233 User::LeaveIfError(apa
.GetAllApps());
234 TFileName name
= RProcess().FileName();
236 while(apa
.GetNextApp(info
) == KErrNone
)
238 if(info
.iFullName
.CompareF(name
) == 0)
244 CleanupStack::PopAndDestroy();
247 TFileName
CSDLApplication::ResourceFileName() const
252 ///////////////////////////////////////////////////////////////////////////////////////////
254 CExitWait::CExitWait(CAknAppUi
& aWait
) : CActive(CActive::EPriorityStandard
), iWait(aWait
)
256 CActiveScheduler::Add(this);
258 iStatusPtr
= &iStatus
;
261 CExitWait::~CExitWait()
266 void CExitWait::RunL()
268 if(iStatusPtr
!= NULL
)
272 void CExitWait::DoCancel()
274 if(iStatusPtr
!= NULL
)
275 User::RequestComplete(iStatusPtr
, KErrCancel
);
278 //////////////////////////////////////////////////////////////////////////////////////////////
280 CSDLDocument::CSDLDocument(CEikApplication
& aApp
) : CEikDocument(aApp
)
283 CEikAppUi
* CSDLDocument::CreateAppUiL()
285 return new (ELeave
) CSDLAppUi
;
288 ///////////////////////////////////////////////////////////////////////////
290 void CSDLWin::ConstructL(const TRect
& aRect
)
297 RWindow
& CSDLWin::GetWindow() const
302 void CSDLWin::Draw(const TRect
& /*aRect*/) const
304 CWindowGc
& gc
= SystemGc();
305 gc
.SetPenStyle(CGraphicsContext::ESolidPen
);
306 gc
.SetPenColor(KRgbGray
);
307 gc
.SetBrushStyle(CGraphicsContext::ESolidBrush
);
308 gc
.SetBrushColor(0x000000);
312 /////////////////////////////////////////////////////////////////////////
314 CSDLAppUi::~CSDLAppUi()
325 void CSDLAppUi::ConstructL()
327 BaseConstructL(ENoAppResourceFile
| ENoScreenFurniture
);
332 fs
.PrivatePath(name
);
334 name
.Append( _L("sdlexe.rsc") );
335 name
.Insert( 0, _L("C:") );
336 iResOffset
= iCoeEnv
->AddResourceFileL(name
);
338 iSDLWin
= new (ELeave
) CSDLWin
;
339 iSDLWin
->ConstructL(ApplicationRect());
341 iSdl
= CSDL::NewL(gSDLClass
.SdlFlags());
343 gSDLClass
.SendEvent(MSDLMainObs::ESDLCreated
, 0, iSdl
);
345 iSdl
->DisableKeyBlocking(*this);
346 iSdl
->SetContainerWindowL(
347 iSDLWin
->GetWindow(),
348 iEikonEnv
->WsSession(),
349 *iEikonEnv
->ScreenDevice());
351 iStarter
= CIdle::NewL(CActive::EPriorityLow
);
352 iStarter
->Start(TCallBack(StartL
, this));
355 TBool
CSDLAppUi::StartL(TAny
* aThis
)
357 static_cast<CSDLAppUi
*>(aThis
)->StartL();
361 TBool
CSDLAppUi::ProcessCommandParametersL(CApaCommandLine
&aCommandLine
)
363 const TPtrC8 cmdLine
= aCommandLine
.TailEnd();
364 iParams
= new (ELeave
) CDesC8ArrayFlat(8);
365 MakeCCmdLineL(cmdLine
, *iParams
);
369 TBool
CSDLAppUi::ParamEditorL(TDes
& aCheat
)
371 CAknTextQueryDialog
* query
= CAknTextQueryDialog::NewL(aCheat
);
372 CleanupStack::PushL(query
);
373 query
->SetPromptL(_L("Enter parameters"));
375 return query
->ExecuteLD(R_PARAMEDITOR
);
378 void CSDLAppUi::StartL()
380 if(gSDLClass
.AppFlags() & SDLEnv::EParamQuery
)
384 int err
= file
.Open(iEikonEnv
->FsSession(), _L("sdl_param.txt"),EFileRead
);
389 MakeCCmdLineL(cmd
, *iParams
);
391 if(err
!= KErrNone
|| gSDLClass
.AppFlags() & (SDLEnv::EParamQueryDialog
^ SDLEnv::EParamQuery
))
394 if(ParamEditorL(buffer
))
397 MakeCCmdLineL(cmd
, *iParams
);
401 iCoeEnv
->DeleteResourceFile(iResOffset
);
403 iWait
= new (ELeave
) CExitWait(*this);
404 iSdl
->CallMainL(gSDLClass
.Main(), &iWait
->iStatus
, iParams
, CSDL::ENoParamFlags
, 0xA000);
407 void CSDLAppUi::HandleCommandL(int aCommand
)
411 case EAknSoftkeyBack
:
412 case EAknSoftkeyExit
:
415 if(iWait
== NULL
|| !iWait
->IsActive() || iSdl
== NULL
)
422 event
.SetType(EEventSwitchOff
), event
.SetTimeNow();
423 iSdl
->AppendWsEvent(event
);
432 void CSDLAppUi::HandleWsEventL(const TWsEvent
& aEvent
, CCoeControl
* aDestination
)
434 if(aEvent
.Type() == KAknUidValueEndKeyCloseEvent
)
436 if(iWait
!= NULL
&& iWait
->IsActive() && iSdl
!= NULL
)
439 event
.SetType(EEventSwitchOff
), event
.SetTimeNow();
440 iSdl
->AppendWsEvent(event
);
446 iSdl
->AppendWsEvent(aEvent
);
447 CAknAppUi::HandleWsEventL(aEvent
, aDestination
);
450 void CSDLAppUi::HandleResourceChangeL(int aType
)
452 CAknAppUi::HandleResourceChangeL(aType
);
453 if(aType
== KEikDynamicLayoutVariantSwitch
)
455 iSDLWin
->SetRect(ApplicationRect());
456 iSdl
->SetContainerWindowL(
457 iSDLWin
->GetWindow(),
458 iEikonEnv
->WsSession(),
459 *iEikonEnv
->ScreenDevice());
463 void CSDLAppUi::HandleForegroundEventL(TBool aForeground
)
465 CAknAppUi::HandleForegroundEventL(aForeground
);
468 ////////////////////////////////////////////////////////////////////////
470 CApaApplication
* NewApplication()
472 return new CSDLApplication();
475 EXPORT_C
int SDLEnv::SetMain(const TMainFunc
& aFunc
, int aSdlFlags
, MSDLMainObs
* aObs
, int aSdlExeFlags
)
477 gSDLClass
.SetMain(aFunc
, aSdlFlags
, aObs
, aSdlExeFlags
);
478 return EikStart::RunApplication(NewApplication
);