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 CExitWait
: public CActive
132 CExitWait(CAknAppUi
& aWait
);
140 TRequestStatus
* iStatusPtr
;
143 ////////////////////////////////////////////////////////////////////////
145 class CSDLWin
: public CCoeControl
148 CSDLWin( const TRect
& aRect
);
149 RWindow
& GetWindow() const { return Window(); }
150 void SetDraw(bool draw
) { m_draw
= draw
; }
153 void Draw(const TRect
& aRect
) const;
158 CSDLWin::CSDLWin( const TRect
& aRect
)
167 void CSDLWin::Draw(const TRect
& /*aRect*/) const
171 CWindowGc
& gc
= SystemGc();
172 gc
.SetPenStyle(CGraphicsContext::ESolidPen
);
173 gc
.SetPenColor(KRgbGray
);
174 gc
.SetBrushStyle(CGraphicsContext::ESolidBrush
);
175 gc
.SetBrushColor(0x000000);
180 ////////////////////////////////////////////////////////////////////////////
182 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 class CSDLDocument
: public CEikDocument
215 CSDLDocument(CEikApplication
& aApp
) : CEikDocument(aApp
) {}
218 CEikAppUi
* CreateAppUiL() { return new CSDLAppUi
; }
221 ////////////////////////////////////////////////////////////////////////////
223 class CSDLApplication
: public CAknApplication
229 CApaDocument
* CreateDocumentL() { return new CSDLDocument(*this); }
230 TUid
AppDllUid() const { return iUid
; }
235 ////////////////////////////////////////////////////////////////////////////////////////
237 CSDLApplication::CSDLApplication()
240 User::LeaveIfError(apa
.Connect());
241 CleanupClosePushL(apa
);
242 User::LeaveIfError(apa
.GetAllApps());
243 TFileName name
= RProcess().FileName();
245 while(apa
.GetNextApp(info
) == KErrNone
)
247 if(info
.iFullName
.CompareF(name
) == 0)
253 CleanupStack::PopAndDestroy();
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 CSDLAppUi::~CSDLAppUi()
295 void CSDLAppUi::ConstructL()
297 BaseConstructL(ENoAppResourceFile
|EAknEnableSkin
);
302 fs
.PrivatePath(name
);
304 name
.Append( _L("sdlexe.rsc") );
305 name
.Insert( 0, _L("C:") );
306 iResOffset
= iCoeEnv
->AddResourceFileL(name
);
308 iSDLWin
= new CSDLWin(ApplicationRect());
310 iSdl
= CSDL::NewL(gSDLClass
.SdlFlags());
312 gSDLClass
.SendEvent(MSDLMainObs::ESDLCreated
, 0, iSdl
);
314 SetKeyBlockMode(ENoKeyBlock
);
316 iSdl
->SetContainerWindowL(iSDLWin
->GetWindow(), iEikonEnv
->WsSession(), *iEikonEnv
->ScreenDevice());
318 iStarter
= CIdle::NewL(CActive::EPriorityLow
);
319 iStarter
->Start(TCallBack(StartL
, this));
322 TBool
CSDLAppUi::StartL(TAny
* aThis
)
324 static_cast<CSDLAppUi
*>(aThis
)->StartL();
328 TBool
CSDLAppUi::ProcessCommandParametersL(CApaCommandLine
&aCommandLine
)
330 const TPtrC8 cmdLine
= aCommandLine
.TailEnd();
331 iParams
= new CDesC8ArrayFlat(8);
332 MakeCCmdLineL(cmdLine
, *iParams
);
336 TBool
CSDLAppUi::ParamEditorL(TDes
& aCheat
)
338 CAknTextQueryDialog
* query
= CAknTextQueryDialog::NewL(aCheat
);
339 CleanupStack::PushL(query
);
340 query
->SetPromptL(_L("Enter parameters"));
342 return query
->ExecuteLD(R_PARAMEDITOR
);
345 void CSDLAppUi::StartL()
347 if(gSDLClass
.AppFlags() & SDLEnv::EParamQuery
)
349 iSDLWin
->SetDraw(true);
353 int err
= file
.Open(iEikonEnv
->FsSession(), _L("sdl_param.txt"),EFileRead
);
358 MakeCCmdLineL(cmd
, *iParams
);
360 if(err
!= KErrNone
|| gSDLClass
.AppFlags() & (SDLEnv::EParamQueryDialog
^ SDLEnv::EParamQuery
))
363 if(ParamEditorL(buffer
))
366 MakeCCmdLineL(cmd
, *iParams
);
370 iSDLWin
->SetDraw(false);
372 iCoeEnv
->DeleteResourceFile(iResOffset
);
374 iWait
= new CExitWait(*this);
375 iSdl
->CallMainL(gSDLClass
.Main(), &iWait
->iStatus
, iParams
, 0xA000);
378 void CSDLAppUi::HandleCommandL(int aCommand
)
382 case EAknSoftkeyBack
:
383 case EAknSoftkeyExit
:
386 if(iWait
== NULL
|| !iWait
->IsActive() || iSdl
== NULL
)
393 event
.SetType(EEventSwitchOff
), event
.SetTimeNow();
394 iSdl
->AppendWsEvent(event
);
403 void CSDLAppUi::HandleWsEventL(const TWsEvent
& aEvent
, CCoeControl
* aDestination
)
405 if(aEvent
.Type() == KAknUidValueEndKeyCloseEvent
)
407 if(iWait
!= NULL
&& iWait
->IsActive() && iSdl
!= NULL
)
410 event
.SetType(EEventSwitchOff
), event
.SetTimeNow();
411 iSdl
->AppendWsEvent(event
);
417 iSdl
->AppendWsEvent(aEvent
);
418 CAknAppUi::HandleWsEventL(aEvent
, aDestination
);
421 void CSDLAppUi::HandleResourceChangeL(int aType
)
423 CAknAppUi::HandleResourceChangeL(aType
);
424 if(aType
== KEikDynamicLayoutVariantSwitch
)
426 iSDLWin
->SetRect(ApplicationRect());
427 iSdl
->SetContainerWindowL(iSDLWin
->GetWindow(), iEikonEnv
->WsSession(), *iEikonEnv
->ScreenDevice());
432 void CSDLAppUi::HandleForegroundEventL(TBool aForeground
)
434 CAknAppUi::HandleForegroundEventL(aForeground
);
437 ////////////////////////////////////////////////////////////////////////
439 CApaApplication
* NewApplication()
441 return new CSDLApplication();
444 int SDLEnv::SetMain(const TMainFunc
& aFunc
, int aSdlFlags
, MSDLMainObs
* aObs
, int aSdlExeFlags
)
446 gSDLClass
.SetMain(aFunc
, aSdlFlags
, aObs
, aSdlExeFlags
);
447 return EikStart::RunApplication(NewApplication
);