Avoid type redefinitions.
[SDL.s60v3.git] / src / main / symbian / sdlexe.cpp
blob384247590bf1862a5489bae2c3b3977ed0ba946f
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;
42 void HandlePointerEventL(const TPointerEvent& aPointerEvent);
45 CSDLWin::CSDLWin( const TRect& aRect )
47 CreateWindowL();
48 SetRect(aRect);
49 EnableDragEvents();
50 ActivateL();
51 Window().SetRequiredDisplayMode(EColor64K);
54 void CSDLWin::Draw(const TRect& /*aRect*/) const
58 void CSDLWin::HandlePointerEventL(const TPointerEvent& aPointerEvent)
60 CCoeControl::HandlePointerEventL(aPointerEvent);
62 TWsEvent event;
63 event.SetType(EEventPointer);
64 memcpy(event.Pointer(), &aPointerEvent, sizeof(TPointerEvent));
65 g_SDL->AppendWsEvent(event);
68 ////////////////////////////////////////////////////////////////////////////
70 class CSDLAppUi : public CAknAppUi
72 public:
73 ~CSDLAppUi();
75 private:
76 void ConstructL();
77 void HandleCommandL(int aCommand);
78 void HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination);
79 void HandleResourceChangeL(int aType);
81 void HandleForegroundEventL(TBool aForeground);
83 Ticker* iTicker;
84 CSDLWin* iSDLWin;
85 CSDL* iSdl;
88 CSDLAppUi::~CSDLAppUi()
90 delete iTicker;
91 delete iSdl;
92 delete iSDLWin;
95 void CSDLAppUi::ConstructL()
97 BaseConstructL(ENoAppResourceFile|EAknEnableSkin);
99 iSDLWin = new CSDLWin(ApplicationRect());
100 iSdl = new CSDL;
101 iTicker = new Ticker;
103 SetKeyBlockMode(ENoKeyBlock);
105 iSdl->SetContainerWindowL(iSDLWin->GetWindow(), iEikonEnv->WsSession(), *iEikonEnv->ScreenDevice());
106 iSdl->CallMainL();
107 Exit();
110 void CSDLAppUi::HandleCommandL(int aCommand)
112 switch(aCommand)
114 case EAknSoftkeyBack:
115 case EAknSoftkeyExit:
116 case EAknCmdExit:
117 case EEikCmdExit:
119 TWsEvent event;
120 event.SetType(EEventSwitchOff), event.SetTimeNow();
121 iSdl->AppendWsEvent(event);
122 break;
125 default:
126 break;
130 void CSDLAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination)
132 if(aEvent.Type() == KAknUidValueEndKeyCloseEvent)
134 TWsEvent event;
135 event.SetType(EEventSwitchOff), event.SetTimeNow();
136 iSdl->AppendWsEvent(event);
137 return;
139 else
141 iSdl->AppendWsEvent(aEvent);
144 CAknAppUi::HandleWsEventL(aEvent, aDestination);
147 void CSDLAppUi::HandleResourceChangeL(int aType)
149 CAknAppUi::HandleResourceChangeL(aType);
150 if(aType == KEikDynamicLayoutVariantSwitch)
152 iSDLWin->SetRect(ApplicationRect());
153 iSdl->SetContainerWindowL(iSDLWin->GetWindow(), iEikonEnv->WsSession(), *iEikonEnv->ScreenDevice());
154 iSdl->Resize();
158 void CSDLAppUi::HandleForegroundEventL(TBool aForeground)
160 CAknAppUi::HandleForegroundEventL(aForeground);
161 g_SDL->SetFocus(aForeground);
164 ////////////////////////////////////////////////////////////////////////////
166 class CSDLDocument : public CEikDocument
168 public:
169 CSDLDocument(CEikApplication& aApp) : CEikDocument(aApp) {}
171 private:
172 CEikAppUi* CreateAppUiL() { return new CSDLAppUi; }
175 ////////////////////////////////////////////////////////////////////////
177 class CSDLApplication : public CAknApplication
179 public:
180 CSDLApplication();
182 private:
183 CApaDocument* CreateDocumentL() { return new CSDLDocument(*this); }
184 TUid AppDllUid() const { return iUid; }
186 TUid iUid;
189 CSDLApplication::CSDLApplication()
191 RApaLsSession apa;
192 User::LeaveIfError(apa.Connect());
193 CleanupClosePushL(apa);
194 User::LeaveIfError(apa.GetAllApps());
195 TFileName name = RProcess().FileName();
196 TApaAppInfo info;
197 while(apa.GetNextApp(info) == KErrNone)
199 if(info.iFullName.CompareF(name) == 0)
201 iUid = info.iUid;
202 break;
205 CleanupStack::PopAndDestroy();
208 ////////////////////////////////////////////////////////////////////////
210 CApaApplication* NewApplication()
212 return new CSDLApplication();
215 int E32Main()
217 return EikStart::RunApplication(NewApplication);