Further simplification.
[SDL.s60v3.git] / src / main / symbian / sdlexe.cpp
blob5ab5702410fd77eee3125eb32dcfa9de73999cf3
1 #include <aknapp.h>
2 #include <aknappui.h>
3 #include <eikdoc.h>
4 #include <sdlepocapi.h>
5 #include <bautils.h>
6 #include <eikstart.h>
7 #include <badesca.h>
8 #include <bautils.h>
9 #include <apgcli.h>
10 #include <eikedwin.h>
11 #include <eiklabel.h>
12 #include <aknglobalmsgquery.h>
13 #include <apgwgnam.h>
15 class CApaDocument;
17 class CExitWait : public CActive
19 public:
20 CExitWait(CAknAppUi& aWait);
21 ~CExitWait() { Cancel(); }
23 private:
24 void RunL() { if(iStatusPtr != NULL) iWait.Exit(); }
25 void DoCancel() { if(iStatusPtr != NULL) User::RequestComplete(iStatusPtr, KErrCancel); }
27 CAknAppUi& iWait;
28 TRequestStatus* iStatusPtr;
31 CExitWait::CExitWait(CAknAppUi& aWait) : CActive(CActive::EPriorityStandard), iWait(aWait)
33 CActiveScheduler::Add(this);
34 SetActive();
35 iStatusPtr = &iStatus;
38 ////////////////////////////////////////////////////////////////////////
40 class CSDLWin : public CCoeControl
42 public:
43 CSDLWin( const TRect& aRect );
44 RWindow& GetWindow() const { return Window(); }
46 private:
47 void Draw(const TRect& aRect) const;
50 CSDLWin::CSDLWin( const TRect& aRect )
52 CreateWindowL();
53 SetRect(aRect);
54 ActivateL();
58 void CSDLWin::Draw(const TRect& /*aRect*/) const
62 ////////////////////////////////////////////////////////////////////////////
64 class CSDLAppUi : public CAknAppUi
66 public:
67 ~CSDLAppUi();
69 private:
70 void ConstructL();
71 void HandleCommandL(int aCommand);
72 void HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination);
73 void HandleResourceChangeL(int aType);
75 void StartL();
76 static TBool StartL(void* aThis);
78 void HandleForegroundEventL(TBool aForeground);
80 CExitWait* iWait;
81 CSDLWin* iSDLWin;
82 CSDL* iSdl;
83 CIdle* iStarter;
86 CSDLAppUi::~CSDLAppUi()
88 if(iStarter)
89 iStarter->Cancel();
90 delete iStarter;
91 delete iWait;
92 delete iSdl;
93 delete iSDLWin;
96 void CSDLAppUi::ConstructL()
98 BaseConstructL(ENoAppResourceFile|EAknEnableSkin);
100 iSDLWin = new CSDLWin(ApplicationRect());
102 iSdl = CSDL::NewL();
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();
115 return EFalse;
118 void CSDLAppUi::StartL()
120 iWait = new CExitWait(*this);
121 iSdl->CallMainL(&iWait->iStatus);
124 void CSDLAppUi::HandleCommandL(int aCommand)
126 switch(aCommand)
128 case EAknSoftkeyBack:
129 case EAknSoftkeyExit:
130 case EAknCmdExit:
131 case EEikCmdExit:
132 if(iWait == NULL || !iWait->IsActive() || iSdl == NULL)
134 Exit();
136 else
138 TWsEvent event;
139 event.SetType(EEventSwitchOff), event.SetTimeNow();
140 iSdl->AppendWsEvent(event);
142 break;
144 default:
145 break;
149 void CSDLAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination)
151 if(aEvent.Type() == KAknUidValueEndKeyCloseEvent)
153 if(iWait != NULL && iWait->IsActive() && iSdl != NULL)
155 TWsEvent event;
156 event.SetType(EEventSwitchOff), event.SetTimeNow();
157 iSdl->AppendWsEvent(event);
158 return;
162 if(iSdl && iWait)
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());
174 iSdl->Resize();
178 void CSDLAppUi::HandleForegroundEventL(TBool aForeground)
180 CAknAppUi::HandleForegroundEventL(aForeground);
183 ////////////////////////////////////////////////////////////////////////////
185 class CSDLDocument : public CEikDocument
187 public:
188 CSDLDocument(CEikApplication& aApp) : CEikDocument(aApp) {}
190 private:
191 CEikAppUi* CreateAppUiL() { return new CSDLAppUi; }
194 ////////////////////////////////////////////////////////////////////////
196 class CSDLApplication : public CAknApplication
198 public:
199 CSDLApplication();
201 private:
202 CApaDocument* CreateDocumentL() { return new CSDLDocument(*this); }
203 TUid AppDllUid() const { return iUid; }
205 TUid iUid;
208 CSDLApplication::CSDLApplication()
210 RApaLsSession apa;
211 User::LeaveIfError(apa.Connect());
212 CleanupClosePushL(apa);
213 User::LeaveIfError(apa.GetAllApps());
214 TFileName name = RProcess().FileName();
215 TApaAppInfo info;
216 while(apa.GetNextApp(info) == KErrNone)
218 if(info.iFullName.CompareF(name) == 0)
220 iUid = info.iUid;
221 break;
224 CleanupStack::PopAndDestroy();
227 ////////////////////////////////////////////////////////////////////////
229 CApaApplication* NewApplication()
231 return new CSDLApplication();
234 int E32Main()
236 return EikStart::RunApplication(NewApplication);