4 #include <sdlepocapi.h>
12 #include <aknglobalmsgquery.h>
17 class CExitWait
: public CActive
20 CExitWait(CAknAppUi
& aWait
);
21 ~CExitWait() { Cancel(); }
24 void RunL() { if(iStatusPtr
!= NULL
) iWait
.Exit(); }
25 void DoCancel() { if(iStatusPtr
!= NULL
) User::RequestComplete(iStatusPtr
, KErrCancel
); }
28 TRequestStatus
* iStatusPtr
;
31 CExitWait::CExitWait(CAknAppUi
& aWait
) : CActive(CActive::EPriorityStandard
), iWait(aWait
)
33 CActiveScheduler::Add(this);
35 iStatusPtr
= &iStatus
;
38 ////////////////////////////////////////////////////////////////////////
40 class CSDLWin
: public CCoeControl
43 CSDLWin( const TRect
& aRect
);
44 RWindow
& GetWindow() const { return Window(); }
47 void Draw(const TRect
& aRect
) const;
50 CSDLWin::CSDLWin( const TRect
& aRect
)
58 void CSDLWin::Draw(const TRect
& /*aRect*/) const
62 ////////////////////////////////////////////////////////////////////////////
64 class CSDLAppUi
: public CAknAppUi
71 void HandleCommandL(int aCommand
);
72 void HandleWsEventL(const TWsEvent
& aEvent
, CCoeControl
* aDestination
);
73 void HandleResourceChangeL(int aType
);
76 static TBool
StartL(void* aThis
);
78 void HandleForegroundEventL(TBool aForeground
);
86 CSDLAppUi::~CSDLAppUi()
96 void CSDLAppUi::ConstructL()
98 BaseConstructL(ENoAppResourceFile
|EAknEnableSkin
);
100 iSDLWin
= new CSDLWin(ApplicationRect());
104 SetKeyBlockMode(ENoKeyBlock
);
106 iSdl
->SetContainerWindowL(iSDLWin
->GetWindow(), iEikonEnv
->WsSession(), *iEikonEnv
->ScreenDevice());
108 iStarter
= CIdle::NewL(CActive::EPriorityLow
);
109 iStarter
->Start(TCallBack(StartL
, this));
112 TBool
CSDLAppUi::StartL(void* aThis
)
114 static_cast<CSDLAppUi
*>(aThis
)->StartL();
118 void CSDLAppUi::StartL()
120 iWait
= new CExitWait(*this);
121 iSdl
->CallMainL(&iWait
->iStatus
);
124 void CSDLAppUi::HandleCommandL(int aCommand
)
128 case EAknSoftkeyBack
:
129 case EAknSoftkeyExit
:
132 if(iWait
== NULL
|| !iWait
->IsActive() || iSdl
== NULL
)
139 event
.SetType(EEventSwitchOff
), event
.SetTimeNow();
140 iSdl
->AppendWsEvent(event
);
149 void CSDLAppUi::HandleWsEventL(const TWsEvent
& aEvent
, CCoeControl
* aDestination
)
151 if(aEvent
.Type() == KAknUidValueEndKeyCloseEvent
)
153 if(iWait
!= NULL
&& iWait
->IsActive() && iSdl
!= NULL
)
156 event
.SetType(EEventSwitchOff
), event
.SetTimeNow();
157 iSdl
->AppendWsEvent(event
);
163 iSdl
->AppendWsEvent(aEvent
);
164 CAknAppUi::HandleWsEventL(aEvent
, aDestination
);
167 void CSDLAppUi::HandleResourceChangeL(int aType
)
169 CAknAppUi::HandleResourceChangeL(aType
);
170 if(aType
== KEikDynamicLayoutVariantSwitch
)
172 iSDLWin
->SetRect(ApplicationRect());
173 iSdl
->SetContainerWindowL(iSDLWin
->GetWindow(), iEikonEnv
->WsSession(), *iEikonEnv
->ScreenDevice());
178 void CSDLAppUi::HandleForegroundEventL(TBool aForeground
)
180 CAknAppUi::HandleForegroundEventL(aForeground
);
183 ////////////////////////////////////////////////////////////////////////////
185 class CSDLDocument
: public CEikDocument
188 CSDLDocument(CEikApplication
& aApp
) : CEikDocument(aApp
) {}
191 CEikAppUi
* CreateAppUiL() { return new CSDLAppUi
; }
194 ////////////////////////////////////////////////////////////////////////
196 class CSDLApplication
: public CAknApplication
202 CApaDocument
* CreateDocumentL() { return new CSDLDocument(*this); }
203 TUid
AppDllUid() const { return iUid
; }
208 CSDLApplication::CSDLApplication()
211 User::LeaveIfError(apa
.Connect());
212 CleanupClosePushL(apa
);
213 User::LeaveIfError(apa
.GetAllApps());
214 TFileName name
= RProcess().FileName();
216 while(apa
.GetNextApp(info
) == KErrNone
)
218 if(info
.iFullName
.CompareF(name
) == 0)
224 CleanupStack::PopAndDestroy();
227 ////////////////////////////////////////////////////////////////////////
229 CApaApplication
* NewApplication()
231 return new CSDLApplication();
236 return EikStart::RunApplication(NewApplication
);