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();
69 TSdlClass() : iExeFlags(0) {}
70 void SetMain(const TMainFunc
& aFunc
, int aExeFlags
);
71 const TMainFunc
& Main() const { return iFunc
; }
72 int AppFlags() const { return iExeFlags
; }
73 void AppFlags(int aFlags
) { iExeFlags
|= aFlags
; }
80 void TSdlClass::SetMain(const TMainFunc
& aFunc
, int aExeFlags
)
83 iExeFlags
= aExeFlags
;
88 ////////////////////////////////////////////////////////////////
90 class CExitWait
: public CActive
93 CExitWait(CAknAppUi
& aWait
);
94 ~CExitWait() { Cancel(); }
97 void RunL() { if(iStatusPtr
!= NULL
) iWait
.Exit(); }
98 void DoCancel() { if(iStatusPtr
!= NULL
) User::RequestComplete(iStatusPtr
, KErrCancel
); }
101 TRequestStatus
* iStatusPtr
;
104 CExitWait::CExitWait(CAknAppUi
& aWait
) : CActive(CActive::EPriorityStandard
), iWait(aWait
)
106 CActiveScheduler::Add(this);
108 iStatusPtr
= &iStatus
;
111 ////////////////////////////////////////////////////////////////////////
113 class CSDLWin
: public CCoeControl
116 CSDLWin( const TRect
& aRect
);
117 RWindow
& GetWindow() const { return Window(); }
118 void SetDraw(bool draw
) { m_draw
= draw
; }
121 void Draw(const TRect
& aRect
) const;
126 CSDLWin::CSDLWin( const TRect
& aRect
)
135 void CSDLWin::Draw(const TRect
& /*aRect*/) const
139 CWindowGc
& gc
= SystemGc();
140 gc
.SetPenStyle(CGraphicsContext::ESolidPen
);
141 gc
.SetPenColor(KRgbGray
);
142 gc
.SetBrushStyle(CGraphicsContext::ESolidBrush
);
143 gc
.SetBrushColor(0x000000);
148 ////////////////////////////////////////////////////////////////////////////
150 class CSDLAppUi
: public CAknAppUi
157 void HandleCommandL(int aCommand
);
158 void HandleWsEventL(const TWsEvent
& aEvent
, CCoeControl
* aDestination
);
159 void HandleResourceChangeL(int aType
);
162 static TBool
StartL(TAny
* aThis
);
164 TBool
ParamEditorL(TDes
& aCheat
);
166 TBool
ProcessCommandParametersL(CApaCommandLine
&aCommandLine
);
168 void HandleForegroundEventL(TBool aForeground
);
174 CDesC8Array
* iParams
;
178 ////////////////////////////////////////////////////////////////////////////
180 class CSDLDocument
: public CEikDocument
183 CSDLDocument(CEikApplication
& aApp
) : CEikDocument(aApp
) {}
186 CEikAppUi
* CreateAppUiL() { return new CSDLAppUi
; }
189 ////////////////////////////////////////////////////////////////////////////
191 class CSDLApplication
: public CAknApplication
197 CApaDocument
* CreateDocumentL() { return new CSDLDocument(*this); }
198 TUid
AppDllUid() const { return iUid
; }
203 ////////////////////////////////////////////////////////////////////////////////////////
205 CSDLApplication::CSDLApplication()
208 User::LeaveIfError(apa
.Connect());
209 CleanupClosePushL(apa
);
210 User::LeaveIfError(apa
.GetAllApps());
211 TFileName name
= RProcess().FileName();
213 while(apa
.GetNextApp(info
) == KErrNone
)
215 if(info
.iFullName
.CompareF(name
) == 0)
221 CleanupStack::PopAndDestroy();
224 /////////////////////////////////////////////////////////////////////////
226 CSDLAppUi::~CSDLAppUi()
237 void CSDLAppUi::ConstructL()
239 BaseConstructL(ENoAppResourceFile
|EAknEnableSkin
);
244 fs
.PrivatePath(name
);
246 name
.Append( _L("sdlexe.rsc") );
247 name
.Insert( 0, _L("C:") );
248 iResOffset
= iCoeEnv
->AddResourceFileL(name
);
250 iSDLWin
= new CSDLWin(ApplicationRect());
254 SetKeyBlockMode(ENoKeyBlock
);
256 iSdl
->SetContainerWindowL(iSDLWin
->GetWindow(), iEikonEnv
->WsSession(), *iEikonEnv
->ScreenDevice());
258 iStarter
= CIdle::NewL(CActive::EPriorityLow
);
259 iStarter
->Start(TCallBack(StartL
, this));
262 TBool
CSDLAppUi::StartL(TAny
* aThis
)
264 static_cast<CSDLAppUi
*>(aThis
)->StartL();
268 TBool
CSDLAppUi::ProcessCommandParametersL(CApaCommandLine
&aCommandLine
)
270 const TPtrC8 cmdLine
= aCommandLine
.TailEnd();
271 iParams
= new CDesC8ArrayFlat(8);
272 MakeCCmdLineL(cmdLine
, *iParams
);
276 TBool
CSDLAppUi::ParamEditorL(TDes
& aCheat
)
278 CAknTextQueryDialog
* query
= CAknTextQueryDialog::NewL(aCheat
);
279 CleanupStack::PushL(query
);
280 query
->SetPromptL(_L("Enter parameters"));
282 return query
->ExecuteLD(R_PARAMEDITOR
);
285 void CSDLAppUi::StartL()
287 if(gSDLClass
.AppFlags() & SDLEnv::EParamQuery
)
289 iSDLWin
->SetDraw(true);
293 int err
= file
.Open(iEikonEnv
->FsSession(), _L("sdl_param.txt"),EFileRead
);
298 MakeCCmdLineL(cmd
, *iParams
);
300 if(err
!= KErrNone
|| gSDLClass
.AppFlags() & (SDLEnv::EParamQueryDialog
^ SDLEnv::EParamQuery
))
303 if(ParamEditorL(buffer
))
306 MakeCCmdLineL(cmd
, *iParams
);
310 iSDLWin
->SetDraw(false);
312 iCoeEnv
->DeleteResourceFile(iResOffset
);
314 iWait
= new CExitWait(*this);
315 iSdl
->CallMainL(gSDLClass
.Main(), &iWait
->iStatus
, iParams
);
318 void CSDLAppUi::HandleCommandL(int aCommand
)
322 case EAknSoftkeyBack
:
323 case EAknSoftkeyExit
:
326 if(iWait
== NULL
|| !iWait
->IsActive() || iSdl
== NULL
)
333 event
.SetType(EEventSwitchOff
), event
.SetTimeNow();
334 iSdl
->AppendWsEvent(event
);
343 void CSDLAppUi::HandleWsEventL(const TWsEvent
& aEvent
, CCoeControl
* aDestination
)
345 if(aEvent
.Type() == KAknUidValueEndKeyCloseEvent
)
347 if(iWait
!= NULL
&& iWait
->IsActive() && iSdl
!= NULL
)
350 event
.SetType(EEventSwitchOff
), event
.SetTimeNow();
351 iSdl
->AppendWsEvent(event
);
357 iSdl
->AppendWsEvent(aEvent
);
358 CAknAppUi::HandleWsEventL(aEvent
, aDestination
);
361 void CSDLAppUi::HandleResourceChangeL(int aType
)
363 CAknAppUi::HandleResourceChangeL(aType
);
364 if(aType
== KEikDynamicLayoutVariantSwitch
)
366 iSDLWin
->SetRect(ApplicationRect());
367 iSdl
->SetContainerWindowL(iSDLWin
->GetWindow(), iEikonEnv
->WsSession(), *iEikonEnv
->ScreenDevice());
372 void CSDLAppUi::HandleForegroundEventL(TBool aForeground
)
374 CAknAppUi::HandleForegroundEventL(aForeground
);
377 ////////////////////////////////////////////////////////////////////////
379 CApaApplication
* NewApplication()
381 return new CSDLApplication();
384 int SDLEnv::SetMain(const TMainFunc
& aFunc
, int aSdlExeFlags
)
386 gSDLClass
.SetMain(aFunc
, aSdlExeFlags
);
387 return EikStart::RunApplication(NewApplication
);