Force hardware pixel format to 565.
[SDL.s60v3.git] / src / main / symbian / sdlexe.cpp
blob131434aad3976b25b503a08f9df76443138a4d12
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 Ticker : public CActive
19 public:
20 Ticker() : CActive(CActive::EPriorityIdle)
22 CActiveScheduler::Add(this);
23 SetActive();
25 ~Ticker() { Cancel(); }
27 private:
28 void RunL() {}
29 void DoCancel() {}
32 ////////////////////////////////////////////////////////////////////////
34 class CSDLWin : public CCoeControl
36 public:
37 CSDLWin( const TRect& aRect );
38 RWindow& GetWindow() const { return Window(); }
40 private:
41 void Draw(const TRect& aRect) const;
44 CSDLWin::CSDLWin( const TRect& aRect )
46 CreateWindowL();
47 SetRect(aRect);
48 ActivateL();
49 Window().SetRequiredDisplayMode(EColor64K);
52 void CSDLWin::Draw(const TRect& /*aRect*/) const
56 ////////////////////////////////////////////////////////////////////////////
58 class CSDLAppUi : public CAknAppUi
60 public:
61 ~CSDLAppUi();
63 private:
64 void ConstructL();
65 void HandleCommandL(int aCommand);
66 void HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination);
67 void HandleResourceChangeL(int aType);
69 void HandleForegroundEventL(TBool aForeground);
71 Ticker* iTicker;
72 CSDLWin* iSDLWin;
73 CSDL* iSdl;
76 CSDLAppUi::~CSDLAppUi()
78 delete iTicker;
79 delete iSdl;
80 delete iSDLWin;
83 void CSDLAppUi::ConstructL()
85 BaseConstructL(ENoAppResourceFile|EAknEnableSkin);
87 iSDLWin = new CSDLWin(ApplicationRect());
88 iSdl = new CSDL;
89 iTicker = new Ticker;
91 SetKeyBlockMode(ENoKeyBlock);
93 iSdl->SetContainerWindowL(iSDLWin->GetWindow(), iEikonEnv->WsSession(), *iEikonEnv->ScreenDevice());
94 iSdl->CallMainL();
95 Exit();
98 void CSDLAppUi::HandleCommandL(int aCommand)
100 switch(aCommand)
102 case EAknSoftkeyBack:
103 case EAknSoftkeyExit:
104 case EAknCmdExit:
105 case EEikCmdExit:
107 TWsEvent event;
108 event.SetType(EEventSwitchOff), event.SetTimeNow();
109 iSdl->AppendWsEvent(event);
110 break;
113 default:
114 break;
118 void CSDLAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination)
120 if(aEvent.Type() == KAknUidValueEndKeyCloseEvent)
122 TWsEvent event;
123 event.SetType(EEventSwitchOff), event.SetTimeNow();
124 iSdl->AppendWsEvent(event);
125 return;
127 else
129 iSdl->AppendWsEvent(aEvent);
132 CAknAppUi::HandleWsEventL(aEvent, aDestination);
135 void CSDLAppUi::HandleResourceChangeL(int aType)
137 CAknAppUi::HandleResourceChangeL(aType);
138 if(aType == KEikDynamicLayoutVariantSwitch)
140 iSDLWin->SetRect(ApplicationRect());
141 iSdl->SetContainerWindowL(iSDLWin->GetWindow(), iEikonEnv->WsSession(), *iEikonEnv->ScreenDevice());
142 iSdl->Resize();
146 void CSDLAppUi::HandleForegroundEventL(TBool aForeground)
148 CAknAppUi::HandleForegroundEventL(aForeground);
149 g_SDL->SetFocus(aForeground);
152 ////////////////////////////////////////////////////////////////////////////
154 class CSDLDocument : public CEikDocument
156 public:
157 CSDLDocument(CEikApplication& aApp) : CEikDocument(aApp) {}
159 private:
160 CEikAppUi* CreateAppUiL() { return new CSDLAppUi; }
163 ////////////////////////////////////////////////////////////////////////
165 class CSDLApplication : public CAknApplication
167 public:
168 CSDLApplication();
170 private:
171 CApaDocument* CreateDocumentL() { return new CSDLDocument(*this); }
172 TUid AppDllUid() const { return iUid; }
174 TUid iUid;
177 CSDLApplication::CSDLApplication()
179 RApaLsSession apa;
180 User::LeaveIfError(apa.Connect());
181 CleanupClosePushL(apa);
182 User::LeaveIfError(apa.GetAllApps());
183 TFileName name = RProcess().FileName();
184 TApaAppInfo info;
185 while(apa.GetNextApp(info) == KErrNone)
187 if(info.iFullName.CompareF(name) == 0)
189 iUid = info.iUid;
190 break;
193 CleanupStack::PopAndDestroy();
196 ////////////////////////////////////////////////////////////////////////
198 CApaApplication* NewApplication()
200 return new CSDLApplication();
203 int E32Main()
205 return EikStart::RunApplication(NewApplication);