4 #include <sdlepocapi.h>
14 #include <aknglobalmsgquery.h>
19 static 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();
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 class CSDLApplication
: public CAknApplication
135 CApaDocument
* CreateDocumentL() { return new (ELeave
) CSDLDocument(*this); }
136 TUid
AppDllUid() const { return iUid
; }
141 class CSDLDocument
: public CEikDocument
144 CSDLDocument(CEikApplication
& aApp
);
147 CEikAppUi
* CreateAppUiL();
150 ////////////////////////////////////////////////////////////////////
152 class CExitWait
: public CActive
155 CExitWait(CAknAppUi
& aWait
);
163 TRequestStatus
* iStatusPtr
;
166 ////////////////////////////////////////////////////////////////////////
168 class CSDLWin
: public CCoeControl
171 CSDLWin() : m_draw(false) {}
172 void ConstructL(const TRect
& aRect
);
173 RWindow
& GetWindow() const;
174 void SetDraw(bool draw
) { m_draw
= draw
; }
177 void Draw(const TRect
& aRect
) const;
182 ////////////////////////////////////////////////////////////////////////////
184 class CSDLAppUi
: public CAknAppUi
191 void HandleCommandL(int aCommand
);
192 void HandleWsEventL(const TWsEvent
& aEvent
, CCoeControl
* aDestination
);
193 void HandleResourceChangeL(int aType
);
196 static TBool
StartL(TAny
* aThis
);
198 TBool
ParamEditorL(TDes
& aCheat
);
200 TBool
ProcessCommandParametersL(CApaCommandLine
&aCommandLine
);
202 void HandleForegroundEventL(TBool aForeground
);
208 CDesC8Array
* iParams
;
212 ////////////////////////////////////////////////////////////////////////////////////////
214 CSDLApplication::CSDLApplication()
217 User::LeaveIfError(apa
.Connect());
218 CleanupClosePushL(apa
);
219 User::LeaveIfError(apa
.GetAllApps());
220 TFileName name
= RProcess().FileName();
222 while(apa
.GetNextApp(info
) == KErrNone
)
224 if(info
.iFullName
.CompareF(name
) == 0)
230 CleanupStack::PopAndDestroy();
233 ///////////////////////////////////////////////////////////////////////////////////////////
235 CExitWait::CExitWait(CAknAppUi
& aWait
) : CActive(CActive::EPriorityStandard
), iWait(aWait
)
237 CActiveScheduler::Add(this);
239 iStatusPtr
= &iStatus
;
242 CExitWait::~CExitWait()
247 void CExitWait::RunL()
249 if(iStatusPtr
!= NULL
)
253 void CExitWait::DoCancel()
255 if(iStatusPtr
!= NULL
)
256 User::RequestComplete(iStatusPtr
, KErrCancel
);
259 //////////////////////////////////////////////////////////////////////////////////////////////
261 CSDLDocument::CSDLDocument(CEikApplication
& aApp
) : CEikDocument(aApp
)
264 CEikAppUi
* CSDLDocument::CreateAppUiL()
266 return new (ELeave
) CSDLAppUi
;
269 ///////////////////////////////////////////////////////////////////////////
271 void CSDLWin::ConstructL(const TRect
& aRect
)
278 RWindow
& CSDLWin::GetWindow() const
283 void CSDLWin::Draw(const TRect
& /*aRect*/) const
287 CWindowGc
& gc
= SystemGc();
288 gc
.SetPenStyle(CGraphicsContext::ESolidPen
);
289 gc
.SetPenColor(KRgbGray
);
290 gc
.SetBrushStyle(CGraphicsContext::ESolidBrush
);
291 gc
.SetBrushColor(0x000000);
296 /////////////////////////////////////////////////////////////////////////
298 CSDLAppUi::~CSDLAppUi()
309 void CSDLAppUi::ConstructL()
311 BaseConstructL(ENoAppResourceFile
|EAknEnableSkin
);
316 fs
.PrivatePath(name
);
318 name
.Append( _L("sdlexe.rsc") );
319 name
.Insert( 0, _L("C:") );
320 iResOffset
= iCoeEnv
->AddResourceFileL(name
);
322 iSDLWin
= new (ELeave
) CSDLWin
;
323 iSDLWin
->ConstructL(ApplicationRect());
325 iSdl
= CSDL::NewL(gSDLClass
.SdlFlags());
327 gSDLClass
.SendEvent(MSDLMainObs::ESDLCreated
, 0, iSdl
);
329 SetKeyBlockMode(ENoKeyBlock
);
331 iSdl
->SetContainerWindowL(iSDLWin
->GetWindow(), iEikonEnv
->WsSession(), *iEikonEnv
->ScreenDevice());
333 iStarter
= CIdle::NewL(CActive::EPriorityLow
);
334 iStarter
->Start(TCallBack(StartL
, this));
337 TBool
CSDLAppUi::StartL(TAny
* aThis
)
339 static_cast<CSDLAppUi
*>(aThis
)->StartL();
343 TBool
CSDLAppUi::ProcessCommandParametersL(CApaCommandLine
&aCommandLine
)
345 const TPtrC8 cmdLine
= aCommandLine
.TailEnd();
346 iParams
= new (ELeave
) CDesC8ArrayFlat(8);
347 MakeCCmdLineL(cmdLine
, *iParams
);
351 TBool
CSDLAppUi::ParamEditorL(TDes
& aCheat
)
353 CAknTextQueryDialog
* query
= CAknTextQueryDialog::NewL(aCheat
);
354 CleanupStack::PushL(query
);
355 query
->SetPromptL(_L("Enter parameters"));
357 return query
->ExecuteLD(R_PARAMEDITOR
);
360 void CSDLAppUi::StartL()
362 if(gSDLClass
.AppFlags() & SDLEnv::EParamQuery
)
364 iSDLWin
->SetDraw(true);
368 int err
= file
.Open(iEikonEnv
->FsSession(), _L("sdl_param.txt"),EFileRead
);
373 MakeCCmdLineL(cmd
, *iParams
);
375 if(err
!= KErrNone
|| gSDLClass
.AppFlags() & (SDLEnv::EParamQueryDialog
^ SDLEnv::EParamQuery
))
378 if(ParamEditorL(buffer
))
381 MakeCCmdLineL(cmd
, *iParams
);
385 iSDLWin
->SetDraw(false);
387 iCoeEnv
->DeleteResourceFile(iResOffset
);
389 iWait
= new (ELeave
) CExitWait(*this);
390 iSdl
->CallMainL(gSDLClass
.Main(), &iWait
->iStatus
, iParams
, 0xA000);
393 void CSDLAppUi::HandleCommandL(int aCommand
)
397 case EAknSoftkeyBack
:
398 case EAknSoftkeyExit
:
401 if(iWait
== NULL
|| !iWait
->IsActive() || iSdl
== NULL
)
408 event
.SetType(EEventSwitchOff
), event
.SetTimeNow();
409 iSdl
->AppendWsEvent(event
);
418 void CSDLAppUi::HandleWsEventL(const TWsEvent
& aEvent
, CCoeControl
* aDestination
)
420 if(aEvent
.Type() == KAknUidValueEndKeyCloseEvent
)
422 if(iWait
!= NULL
&& iWait
->IsActive() && iSdl
!= NULL
)
425 event
.SetType(EEventSwitchOff
), event
.SetTimeNow();
426 iSdl
->AppendWsEvent(event
);
432 iSdl
->AppendWsEvent(aEvent
);
433 CAknAppUi::HandleWsEventL(aEvent
, aDestination
);
436 void CSDLAppUi::HandleResourceChangeL(int aType
)
438 CAknAppUi::HandleResourceChangeL(aType
);
439 if(aType
== KEikDynamicLayoutVariantSwitch
)
441 iSDLWin
->SetRect(ApplicationRect());
442 iSdl
->SetContainerWindowL(iSDLWin
->GetWindow(), iEikonEnv
->WsSession(), *iEikonEnv
->ScreenDevice());
447 void CSDLAppUi::HandleForegroundEventL(TBool aForeground
)
449 CAknAppUi::HandleForegroundEventL(aForeground
);
452 ////////////////////////////////////////////////////////////////////////
454 CApaApplication
* NewApplication()
456 return new CSDLApplication();
459 int SDLEnv::SetMain(const TMainFunc
& aFunc
, int aSdlFlags
, MSDLMainObs
* aObs
, int aSdlExeFlags
)
461 gSDLClass
.SetMain(aFunc
, aSdlFlags
, aObs
, aSdlExeFlags
);
462 return EikStart::RunApplication(NewApplication
);