diff options
Diffstat (limited to 'apps/plugins/sdl/src/main/symbian')
-rw-r--r-- | apps/plugins/sdl/src/main/symbian/EKA1/SDL_main.cpp | 152 | ||||
-rw-r--r-- | apps/plugins/sdl/src/main/symbian/EKA2/SDL_main.cpp | 1035 | ||||
-rw-r--r-- | apps/plugins/sdl/src/main/symbian/EKA2/sdlexe.cpp | 809 | ||||
-rw-r--r-- | apps/plugins/sdl/src/main/symbian/EKA2/sdllib.cpp | 12 | ||||
-rw-r--r-- | apps/plugins/sdl/src/main/symbian/EKA2/vectorbuffer.cpp | 62 | ||||
-rw-r--r-- | apps/plugins/sdl/src/main/symbian/EKA2/vectorbuffer.h | 240 |
6 files changed, 2310 insertions, 0 deletions
diff --git a/apps/plugins/sdl/src/main/symbian/EKA1/SDL_main.cpp b/apps/plugins/sdl/src/main/symbian/EKA1/SDL_main.cpp new file mode 100644 index 0000000000..683db874ff --- /dev/null +++ b/apps/plugins/sdl/src/main/symbian/EKA1/SDL_main.cpp | |||
@@ -0,0 +1,152 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Library General Public | ||
16 | License along with this library; if not, write to the Free | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@devolution.com | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | SDL_main.cpp | ||
25 | The Epoc executable startup functions | ||
26 | |||
27 | Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi) | ||
28 | */ | ||
29 | |||
30 | #include <e32std.h> | ||
31 | #include <e32def.h> | ||
32 | #include <e32svr.h> | ||
33 | #include <e32base.h> | ||
34 | #include <estlib.h> | ||
35 | #include <stdlib.h> | ||
36 | #include <stdio.h> | ||
37 | #include <w32std.h> | ||
38 | #include <apgtask.h> | ||
39 | |||
40 | #include "SDL_error.h" | ||
41 | |||
42 | #if defined(__WINS__) | ||
43 | #include <estw32.h> | ||
44 | IMPORT_C void RegisterWsExe(const TDesC &aName); | ||
45 | #endif | ||
46 | |||
47 | /* The prototype for the application's main() function */ | ||
48 | #define main SDL_main | ||
49 | extern "C" int main (int argc, char *argv[], char *envp[]); | ||
50 | extern "C" void exit (int ret); | ||
51 | |||
52 | |||
53 | /* Epoc main function */ | ||
54 | |||
55 | #ifdef __WINS__ | ||
56 | |||
57 | |||
58 | void GetCmdLine(int& aArgc, char**& aArgv) | ||
59 | { | ||
60 | RChunk chunk; | ||
61 | |||
62 | if(chunk.OpenGlobal(RThread().Name(), ETrue) != KErrNone) | ||
63 | return; | ||
64 | |||
65 | TUint* ptr = (TUint*) chunk.Base(); | ||
66 | if(ptr != NULL) | ||
67 | { | ||
68 | aArgc = (int) *(ptr); // count | ||
69 | aArgv = (char**) *(ptr + 1); | ||
70 | } | ||
71 | chunk.Close(); | ||
72 | } | ||
73 | |||
74 | #endif | ||
75 | |||
76 | |||
77 | TInt E32Main() | ||
78 | { | ||
79 | /* Get the clean-up stack */ | ||
80 | CTrapCleanup* cleanup = CTrapCleanup::New(); | ||
81 | |||
82 | /* Arrange for multi-threaded operation */ | ||
83 | SpawnPosixServerThread(); | ||
84 | |||
85 | /* Get args and environment */ | ||
86 | int argc=0; | ||
87 | char** argv=0; | ||
88 | char** envp=0; | ||
89 | |||
90 | #ifndef __WINS__ | ||
91 | __crt0(argc,argv,envp); | ||
92 | #else | ||
93 | GetCmdLine(argc, argv); | ||
94 | #endif | ||
95 | /* Start the application! */ | ||
96 | |||
97 | /* Create stdlib */ | ||
98 | _REENT; | ||
99 | |||
100 | /* Set process and thread priority and name */ | ||
101 | |||
102 | RThread currentThread; | ||
103 | RProcess thisProcess; | ||
104 | TParse exeName; | ||
105 | exeName.Set(thisProcess.FileName(), NULL, NULL); | ||
106 | currentThread.Rename(exeName.Name()); | ||
107 | currentThread.SetProcessPriority(EPriorityLow); | ||
108 | currentThread.SetPriority(EPriorityMuchLess); | ||
109 | |||
110 | /* Call stdlib main */ | ||
111 | int ret = main(argc, argv, envp); /* !! process exits here if there is "exit()" in main! */ | ||
112 | |||
113 | /* Call exit */ | ||
114 | //exit(ret); /* !! process exits here! */ | ||
115 | //Markus: I do not understand above | ||
116 | //I commented it at let this function | ||
117 | //to return ret value - was it purpose | ||
118 | //that cleanup below is not called at all - why? | ||
119 | |||
120 | /* Free resources and return */ | ||
121 | |||
122 | _cleanup(); //this is normally called at exit, I call it here, Markus | ||
123 | |||
124 | CloseSTDLIB(); | ||
125 | delete cleanup; | ||
126 | #ifdef __WINS__ | ||
127 | // User::Panic(_L("exit"), ret); | ||
128 | // RThread().Kill(ret); //Markus get rid of this thread | ||
129 | // RThread().RaiseException(EExcKill); | ||
130 | #endif | ||
131 | return ret;//Markus, or exit(ret); ?? | ||
132 | //return(KErrNone); | ||
133 | } | ||
134 | |||
135 | |||
136 | #ifdef __WINS__ | ||
137 | EXPORT_C TInt WinsMain() | ||
138 | { | ||
139 | return E32Main(); | ||
140 | // return WinsMain(0, 0, 0); | ||
141 | } | ||
142 | #endif | ||
143 | |||
144 | /* Epoc dll entry point */ | ||
145 | #if defined(__WINS__) | ||
146 | GLDEF_C TInt E32Dll(TDllReason) | ||
147 | { | ||
148 | return(KErrNone); | ||
149 | } | ||
150 | #endif | ||
151 | |||
152 | |||
diff --git a/apps/plugins/sdl/src/main/symbian/EKA2/SDL_main.cpp b/apps/plugins/sdl/src/main/symbian/EKA2/SDL_main.cpp new file mode 100644 index 0000000000..3dc69d4aad --- /dev/null +++ b/apps/plugins/sdl/src/main/symbian/EKA2/SDL_main.cpp | |||
@@ -0,0 +1,1035 @@ | |||
1 | /* | ||
2 | SDL_Main.cpp | ||
3 | Symbian OS services for SDL | ||
4 | |||
5 | Markus Mertama | ||
6 | */ | ||
7 | |||
8 | |||
9 | #include "epoc_sdl.h" | ||
10 | |||
11 | #include"sdlepocapi.h" | ||
12 | #include <e32base.h> | ||
13 | #include <estlib.h> | ||
14 | #include <stdio.h> | ||
15 | #include <badesca.h> | ||
16 | |||
17 | #include "vectorbuffer.h" | ||
18 | #include <w32std.h> | ||
19 | #include <aknappui.h> | ||
20 | #include <aknapp.h> | ||
21 | #include "SDL_epocevents_c.h" | ||
22 | #include "SDL_keysym.h" | ||
23 | #include "dsa.h" | ||
24 | |||
25 | |||
26 | #ifdef SYMBIANC | ||
27 | #include <reent.h> | ||
28 | #endif | ||
29 | |||
30 | //Markus Mertama | ||
31 | |||
32 | |||
33 | extern SDLKey* KeyMap(); | ||
34 | extern void ResetKeyMap(); | ||
35 | |||
36 | class CCurrentAppUi; | ||
37 | |||
38 | //const TUid KSDLUid = { 0xF01F3D69 }; | ||
39 | |||
40 | NONSHARABLE_CLASS(EnvUtils) | ||
41 | { | ||
42 | public: | ||
43 | static void DisableKeyBlocking(); | ||
44 | static TBool Rendezvous(RThread& aThread, TRequestStatus& aStatus); | ||
45 | }; | ||
46 | |||
47 | TInt Panic(TInt aErr, TInt aLine) | ||
48 | { | ||
49 | TBuf<64> b; | ||
50 | b.Format(_L("Main at %d"), aLine); | ||
51 | User::Panic(b, aErr); | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | |||
56 | NONSHARABLE_CLASS(CCurrentAppUi) : public CAknAppUi | ||
57 | { | ||
58 | public: | ||
59 | static CCurrentAppUi* Cast(CEikAppUi* aUi); | ||
60 | void DisableKeyBlocking(); | ||
61 | }; | ||
62 | |||
63 | |||
64 | CCurrentAppUi* CCurrentAppUi::Cast(CEikAppUi* aUi) | ||
65 | { | ||
66 | return static_cast<CCurrentAppUi*>(aUi); | ||
67 | } | ||
68 | |||
69 | void CCurrentAppUi::DisableKeyBlocking() | ||
70 | { | ||
71 | SetKeyBlockMode(ENoKeyBlock); | ||
72 | } | ||
73 | |||
74 | |||
75 | class CEventQueue : public CBase, public MEventQueue | ||
76 | { | ||
77 | public: | ||
78 | static CEventQueue* NewL(); | ||
79 | ~CEventQueue(); | ||
80 | public: | ||
81 | TInt Append(const TWsEvent& aEvent); | ||
82 | const TWsEvent& Shift(); | ||
83 | void Lock(); | ||
84 | void Unlock(); | ||
85 | TBool HasData(); | ||
86 | private: | ||
87 | TVector<TWsEvent, 64> iVector; | ||
88 | RCriticalSection iCS; | ||
89 | }; | ||
90 | |||
91 | CEventQueue* CEventQueue::NewL() | ||
92 | { | ||
93 | CEventQueue* q = new (ELeave) CEventQueue(); | ||
94 | CleanupStack::PushL(q); | ||
95 | User::LeaveIfError(q->iCS.CreateLocal()); | ||
96 | CleanupStack::Pop(); | ||
97 | return q; | ||
98 | } | ||
99 | |||
100 | CEventQueue::~CEventQueue() | ||
101 | { | ||
102 | iCS.Close(); | ||
103 | } | ||
104 | |||
105 | TInt CEventQueue::Append(const TWsEvent& aEvent) | ||
106 | { | ||
107 | iCS.Wait(); | ||
108 | const TInt err = iVector.Append(aEvent); | ||
109 | iCS.Signal(); | ||
110 | return err; | ||
111 | } | ||
112 | |||
113 | |||
114 | TBool CEventQueue::HasData() | ||
115 | { | ||
116 | return iVector.Size() > 0; | ||
117 | } | ||
118 | |||
119 | |||
120 | void CEventQueue::Lock() | ||
121 | { | ||
122 | iCS.Wait(); | ||
123 | } | ||
124 | |||
125 | void CEventQueue::Unlock() | ||
126 | { | ||
127 | iCS.Signal(); | ||
128 | } | ||
129 | |||
130 | const TWsEvent& CEventQueue::Shift() | ||
131 | { | ||
132 | const TWsEvent& event = iVector.Shift(); | ||
133 | return event; | ||
134 | } | ||
135 | |||
136 | |||
137 | TSdlCleanupItem::TSdlCleanupItem(TSdlCleanupOperation aOperation, TAny* aItem) : | ||
138 | iOperation(aOperation), iItem(aItem), iThread(RThread().Id()) | ||
139 | { | ||
140 | } | ||
141 | |||
142 | class CEikonEnv; | ||
143 | class CSdlAppServ; | ||
144 | |||
145 | |||
146 | NONSHARABLE_CLASS(EpocSdlEnvData) | ||
147 | { | ||
148 | public: | ||
149 | void Free(); | ||
150 | CEventQueue* iEventQueue; | ||
151 | TMainFunc iMain; | ||
152 | TInt iEpocEnvFlags; | ||
153 | int iArgc; | ||
154 | char** iArgv; | ||
155 | CDsa* iDsa; | ||
156 | CSdlAppServ* iAppSrv; | ||
157 | TThreadId iId; | ||
158 | CArrayFix<TSdlCleanupItem>* iCleanupItems; | ||
159 | CEikAppUi* iAppUi; | ||
160 | CSDL* iSdl; | ||
161 | }; | ||
162 | |||
163 | |||
164 | EpocSdlEnvData* gEpocEnv; | ||
165 | |||
166 | #define MAINFUNC(x) EXPORT_C TMainFunc::TMainFunc(mainfunc##x aFunc){Mem::FillZ(iMainFunc, sizeof(iMainFunc)); iMainFunc[x - 1] = (void*) aFunc;} | ||
167 | |||
168 | MAINFUNC(1) | ||
169 | MAINFUNC(2) | ||
170 | MAINFUNC(3) | ||
171 | MAINFUNC(4) | ||
172 | MAINFUNC(5) | ||
173 | MAINFUNC(6) | ||
174 | |||
175 | EXPORT_C TMainFunc::TMainFunc() | ||
176 | { | ||
177 | Mem::FillZ(iMainFunc, sizeof(iMainFunc)); | ||
178 | } | ||
179 | |||
180 | |||
181 | const void* TMainFunc::operator[](TInt aIndex) const | ||
182 | { | ||
183 | return iMainFunc[aIndex]; | ||
184 | } | ||
185 | |||
186 | |||
187 | NONSHARABLE_CLASS(CSdlAppServ) : public CActive | ||
188 | { | ||
189 | public: | ||
190 | enum | ||
191 | { | ||
192 | EAppSrvNoop = CDsa::ELastDsaRequest, | ||
193 | EAppSrvWindowWidth, | ||
194 | EAppSrvWindowHeight, | ||
195 | EAppSrvWindowDisplayMode, | ||
196 | EAppSrvWindowPointerCursorMode, | ||
197 | EAppSrvDsaStatus, | ||
198 | EAppSrvStopThread, | ||
199 | EAppSrvWaitDsa | ||
200 | }; | ||
201 | CSdlAppServ(); | ||
202 | void ConstructL(); | ||
203 | ~CSdlAppServ(); | ||
204 | TInt Request(TInt aService); | ||
205 | TInt RequestValue(TInt aService); | ||
206 | void Init(); | ||
207 | void PanicMain(TInt aReason); | ||
208 | void PanicMain(const TDesC& aInfo, TInt aReason); | ||
209 | void SetObserver(MSDLObserver* aObserver); | ||
210 | TInt ObserverEvent(TInt aEvent, TInt aParam); | ||
211 | void SetParam(TInt aParam); | ||
212 | void HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread); | ||
213 | MSDLObserver* Observer(); | ||
214 | private: | ||
215 | void RunL(); | ||
216 | void DoCancel(); | ||
217 | private: | ||
218 | const TThreadId iMainId; | ||
219 | RThread iAppThread; | ||
220 | TInt iService; | ||
221 | TInt iReturnValue; | ||
222 | RSemaphore iSema; | ||
223 | MSDLObserver* iObserver; | ||
224 | TRequestStatus* iStatusPtr; | ||
225 | }; | ||
226 | |||
227 | CSdlAppServ::CSdlAppServ() : CActive(CActive::EPriorityHigh), iMainId(RThread().Id()) | ||
228 | { | ||
229 | } | ||
230 | |||
231 | |||
232 | |||
233 | MSDLObserver* CSdlAppServ::Observer() | ||
234 | { | ||
235 | return iObserver; | ||
236 | } | ||
237 | |||
238 | |||
239 | void CSdlAppServ::SetObserver(MSDLObserver* aObserver) | ||
240 | { | ||
241 | iObserver = aObserver; | ||
242 | } | ||
243 | |||
244 | TInt CSdlAppServ::ObserverEvent(TInt aEvent, TInt aParam) | ||
245 | { | ||
246 | if(iObserver != NULL) | ||
247 | { | ||
248 | if(RThread().Id() == gEpocEnv->iId) | ||
249 | { | ||
250 | return iObserver->SdlThreadEvent(aEvent, aParam); | ||
251 | } | ||
252 | else if(RThread().Id() == iMainId) | ||
253 | { | ||
254 | return iObserver->SdlEvent(aEvent, aParam); | ||
255 | } | ||
256 | PANIC(KErrNotSupported); | ||
257 | } | ||
258 | return 0; | ||
259 | } | ||
260 | |||
261 | void CSdlAppServ::PanicMain(TInt aReason) | ||
262 | { | ||
263 | iAppThread.Panic(RThread().Name(), aReason); | ||
264 | } | ||
265 | |||
266 | void CSdlAppServ::PanicMain(const TDesC& aInfo, TInt aReason) | ||
267 | { | ||
268 | iAppThread.Panic(aInfo, aReason); | ||
269 | } | ||
270 | |||
271 | void CSdlAppServ::ConstructL() | ||
272 | { | ||
273 | CActiveScheduler::Add(this); | ||
274 | User::LeaveIfError(iSema.CreateLocal(1)); | ||
275 | iStatus = KRequestPending; | ||
276 | iStatusPtr = &iStatus; | ||
277 | SetActive(); | ||
278 | } | ||
279 | |||
280 | CSdlAppServ::~CSdlAppServ() | ||
281 | { | ||
282 | Cancel(); | ||
283 | if(iSema.Handle() != NULL) | ||
284 | iSema.Signal(); | ||
285 | iSema.Close(); | ||
286 | iAppThread.Close(); | ||
287 | } | ||
288 | |||
289 | TInt CSdlAppServ::Request(TInt aService) | ||
290 | { | ||
291 | if(RThread().Id() != iAppThread.Id()) | ||
292 | { | ||
293 | iSema.Wait(); | ||
294 | iService = aService; | ||
295 | iAppThread.RequestComplete(iStatusPtr, KErrNone); | ||
296 | return KErrNone; | ||
297 | } | ||
298 | return KErrBadHandle; | ||
299 | } | ||
300 | |||
301 | TInt CSdlAppServ::RequestValue(TInt aService) | ||
302 | { | ||
303 | Request(aService); | ||
304 | Request(EAppSrvNoop); | ||
305 | return iReturnValue; | ||
306 | } | ||
307 | |||
308 | void CSdlAppServ::Init() | ||
309 | { | ||
310 | PANIC_IF_ERROR(iAppThread.Open(iMainId)); | ||
311 | } | ||
312 | |||
313 | void CSdlAppServ::SetParam(TInt aParam) | ||
314 | { | ||
315 | iReturnValue = aParam; | ||
316 | } | ||
317 | |||
318 | void CSdlAppServ::HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread) | ||
319 | { | ||
320 | if(iObserver != NULL && aMainThread) | ||
321 | { | ||
322 | switch(aService) | ||
323 | { | ||
324 | case MSDLObserver::EEventScreenSizeChanged: | ||
325 | if(aReturnValue == MSDLObserver::EScreenSizeChangedDefaultPalette) | ||
326 | EpocSdlEnv::LockPalette(EFalse); | ||
327 | break; | ||
328 | } | ||
329 | } | ||
330 | if(!aMainThread && aService == MSDLObserver::EEventSuspend) | ||
331 | { | ||
332 | if(iObserver == NULL || | ||
333 | (gEpocEnv->iDsa->Stopped() && aReturnValue != MSDLObserver::ESuspendNoSuspend)) | ||
334 | { | ||
335 | EpocSdlEnv::Suspend(); | ||
336 | } | ||
337 | } | ||
338 | } | ||
339 | |||
340 | void CSdlAppServ::RunL() | ||
341 | { | ||
342 | if(iStatus == KErrNone) | ||
343 | { | ||
344 | switch(iService) | ||
345 | { | ||
346 | case CSdlAppServ::EAppSrvWaitDsa: | ||
347 | EpocSdlEnv::SetWaitDsa(); | ||
348 | iReturnValue = EpocSdlEnv::IsDsaAvailable(); | ||
349 | // } | ||
350 | // gEpocEnv->iDsa->Stop(); | ||
351 | // gEpocEnv->iDsa->RestartL(); | ||
352 | break; | ||
353 | case CSdlAppServ::EAppSrvStopThread: | ||
354 | gEpocEnv->iDsa->SetSuspend(); | ||
355 | break; | ||
356 | case EpocSdlEnv::EDisableKeyBlocking: | ||
357 | EnvUtils::DisableKeyBlocking(); | ||
358 | break; | ||
359 | |||
360 | case EAppSrvWindowPointerCursorMode: | ||
361 | iReturnValue = gEpocEnv->iDsa != NULL ? | ||
362 | gEpocEnv->iDsa->Session().PointerCursorMode() : KErrNotReady; | ||
363 | break; | ||
364 | case EAppSrvDsaStatus: | ||
365 | gEpocEnv->iDsa->Stop(); | ||
366 | iReturnValue = KErrNone; | ||
367 | break; | ||
368 | case CDsa::ERequestUpdate: | ||
369 | gEpocEnv->iDsa->UnlockHWSurfaceRequestComplete(); | ||
370 | break; | ||
371 | case EAppSrvNoop: | ||
372 | break; | ||
373 | case MSDLObserver::EEventResume: | ||
374 | case MSDLObserver::EEventSuspend: | ||
375 | case MSDLObserver::EEventScreenSizeChanged: | ||
376 | case MSDLObserver::EEventWindowReserved: | ||
377 | case MSDLObserver::EEventKeyMapInit: | ||
378 | case MSDLObserver::EEventWindowNotAvailable: | ||
379 | case MSDLObserver::EEventMainExit: | ||
380 | iReturnValue = ObserverEvent(iService, iReturnValue); | ||
381 | HandleObserverValue(iService, iReturnValue, ETrue); | ||
382 | break; | ||
383 | default: | ||
384 | PANIC(KErrNotSupported); | ||
385 | } | ||
386 | iStatus = KRequestPending; | ||
387 | iStatusPtr = &iStatus; | ||
388 | SetActive(); | ||
389 | } | ||
390 | iSema.Signal(); | ||
391 | } | ||
392 | |||
393 | void CSdlAppServ::DoCancel() | ||
394 | { | ||
395 | iSema.Wait(); | ||
396 | TRequestStatus* s = &iStatus; | ||
397 | iAppThread.RequestComplete(s, KErrCancel); | ||
398 | } | ||
399 | |||
400 | |||
401 | |||
402 | MEventQueue& EpocSdlEnv::EventQueue() | ||
403 | { | ||
404 | __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); | ||
405 | return *gEpocEnv->iEventQueue; | ||
406 | } | ||
407 | |||
408 | |||
409 | TBool EpocSdlEnv::Flags(TInt aFlag) | ||
410 | { | ||
411 | const TInt flag = gEpocEnv->iEpocEnvFlags & aFlag; | ||
412 | return flag == aFlag; | ||
413 | } | ||
414 | |||
415 | TInt EpocSdlEnv::Argc() | ||
416 | { | ||
417 | __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); | ||
418 | return gEpocEnv->iArgc; | ||
419 | } | ||
420 | |||
421 | |||
422 | char** EpocSdlEnv::Argv() | ||
423 | { | ||
424 | __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); | ||
425 | return gEpocEnv->iArgv; | ||
426 | } | ||
427 | |||
428 | |||
429 | TBool EpocSdlEnv::IsDsaAvailable() | ||
430 | { | ||
431 | __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); | ||
432 | return gEpocEnv->iDsa != NULL && gEpocEnv->iDsa->IsDsaAvailable(); | ||
433 | } | ||
434 | |||
435 | |||
436 | void EpocSdlEnv::WaitDsaAvailable() | ||
437 | { | ||
438 | EpocSdlEnv::ObserverEvent(MSDLObserver::EEventWindowNotAvailable, 0); | ||
439 | gEpocEnv->iAppSrv->Request(CSdlAppServ::EAppSrvStopThread); | ||
440 | if(EpocSdlEnv::Flags(CSDL::EEnableFocusStop)) | ||
441 | { | ||
442 | EpocSdlEnv::ObserverEvent(MSDLObserver::EEventSuspend, 0); | ||
443 | } | ||
444 | } | ||
445 | |||
446 | void EpocSdlEnv::Suspend() | ||
447 | { | ||
448 | if(gEpocEnv->iDsa->Stopped() || EpocSdlEnv::Flags(CSDL::EEnableFocusStop)) | ||
449 | { | ||
450 | // gEpocEnv->iDsa->ReleaseStop(); | ||
451 | gEpocEnv->iDsa->SetSuspend(); | ||
452 | RThread().Suspend(); | ||
453 | EpocSdlEnv::ObserverEvent(MSDLObserver::EEventResume, 0); | ||
454 | } | ||
455 | } | ||
456 | |||
457 | void EpocSdlEnv::SetWaitDsa() | ||
458 | { | ||
459 | if(!IsDsaAvailable()) | ||
460 | { | ||
461 | RThread th; | ||
462 | th.Open(gEpocEnv->iId); | ||
463 | th.Suspend(); | ||
464 | th.Close(); | ||
465 | gEpocEnv->iDsa->SetSuspend(); | ||
466 | } | ||
467 | } | ||
468 | |||
469 | void EpocSdlEnv::Resume() | ||
470 | { | ||
471 | gEpocEnv->iDsa->Resume(); | ||
472 | RThread th; | ||
473 | th.Open(gEpocEnv->iId); | ||
474 | th.Resume(); | ||
475 | th.Close(); | ||
476 | |||
477 | const TInt value = gEpocEnv->iAppSrv->ObserverEvent(MSDLObserver::EEventResume, 0); | ||
478 | gEpocEnv->iAppSrv->HandleObserverValue(MSDLObserver::EEventResume, value, ETrue); | ||
479 | } | ||
480 | |||
481 | |||
482 | TInt EpocSdlEnv::AllocSwSurface(const TSize& aSize, TDisplayMode aMode) | ||
483 | { | ||
484 | return gEpocEnv->iDsa->AllocSurface(EFalse, aSize, aMode); | ||
485 | } | ||
486 | |||
487 | TInt EpocSdlEnv::AllocHwSurface(const TSize& aSize, TDisplayMode aMode) | ||
488 | { | ||
489 | return gEpocEnv->iDsa->AllocSurface(ETrue, aSize, aMode); | ||
490 | } | ||
491 | |||
492 | |||
493 | void EpocSdlEnv::UnlockHwSurface() | ||
494 | { | ||
495 | gEpocEnv->iDsa->UnlockHwSurface(); | ||
496 | } | ||
497 | |||
498 | TUint8* EpocSdlEnv::LockHwSurface() | ||
499 | { | ||
500 | return gEpocEnv->iDsa->LockHwSurface(); | ||
501 | } | ||
502 | |||
503 | |||
504 | void EpocSdlEnv::UpdateSwSurface() | ||
505 | { | ||
506 | gEpocEnv->iDsa->UpdateSwSurface(); | ||
507 | } | ||
508 | |||
509 | TBool EpocSdlEnv::AddUpdateRect(TUint8* aAddress, const TRect& aUpdateRect, const TRect& aRect) | ||
510 | { | ||
511 | return gEpocEnv->iDsa->AddUpdateRect(aAddress, aUpdateRect, aRect); | ||
512 | } | ||
513 | |||
514 | void EpocSdlEnv::Request(TInt aService) | ||
515 | { | ||
516 | __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); | ||
517 | gEpocEnv->iAppSrv->Request(aService); | ||
518 | } | ||
519 | |||
520 | |||
521 | TSize EpocSdlEnv::WindowSize(const TSize& aRequestedSize) | ||
522 | { | ||
523 | __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); | ||
524 | if(EpocSdlEnv::Flags(CSDL::EAllowImageResize) && gEpocEnv->iDsa->WindowSize() != aRequestedSize) | ||
525 | { | ||
526 | TRAP_IGNORE(gEpocEnv->iDsa->CreateZoomerL(aRequestedSize)); | ||
527 | } | ||
528 | return gEpocEnv->iDsa->WindowSize(); | ||
529 | } | ||
530 | |||
531 | TSize EpocSdlEnv::WindowSize() | ||
532 | { | ||
533 | __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); | ||
534 | return gEpocEnv->iDsa->WindowSize(); | ||
535 | } | ||
536 | |||
537 | TDisplayMode EpocSdlEnv::DisplayMode() | ||
538 | { | ||
539 | return gEpocEnv->iDsa->DisplayMode(); | ||
540 | } | ||
541 | |||
542 | TPointerCursorMode EpocSdlEnv::PointerMode() | ||
543 | { | ||
544 | return static_cast<TPointerCursorMode> | ||
545 | (gEpocEnv->iAppSrv->RequestValue(CSdlAppServ::EAppSrvWindowPointerCursorMode)); | ||
546 | } | ||
547 | |||
548 | TInt EpocSdlEnv::SetPalette(TInt aFirstcolor, TInt aColorCount, TUint32* aPalette) | ||
549 | { | ||
550 | return gEpocEnv->iDsa->SetPalette(aFirstcolor, aColorCount, aPalette); | ||
551 | } | ||
552 | |||
553 | void EpocSdlEnv::PanicMain(TInt aErr) | ||
554 | { | ||
555 | gEpocEnv->iAppSrv->PanicMain(aErr); | ||
556 | } | ||
557 | |||
558 | |||
559 | TInt EpocSdlEnv::AppendCleanupItem(const TSdlCleanupItem& aItem) | ||
560 | { | ||
561 | TRAPD(err, gEpocEnv->iCleanupItems->AppendL(aItem)); | ||
562 | return err; | ||
563 | } | ||
564 | |||
565 | void EpocSdlEnv::RemoveCleanupItem(TAny* aItem) | ||
566 | { | ||
567 | for(TInt i = 0; i < gEpocEnv->iCleanupItems->Count(); i++) | ||
568 | { | ||
569 | if(gEpocEnv->iCleanupItems->At(i).iItem == aItem) | ||
570 | gEpocEnv->iCleanupItems->Delete(i); | ||
571 | } | ||
572 | } | ||
573 | |||
574 | void EpocSdlEnv::CleanupItems() | ||
575 | { | ||
576 | const TThreadId id = RThread().Id(); | ||
577 | TInt last = gEpocEnv->iCleanupItems->Count() - 1; | ||
578 | TInt i; | ||
579 | for(i = last; i >= 0 ; i--) | ||
580 | { | ||
581 | TSdlCleanupItem& item = gEpocEnv->iCleanupItems->At(i); | ||
582 | if(item.iThread == id) | ||
583 | { | ||
584 | item.iThread = TThreadId(0); | ||
585 | item.iOperation(item.iItem); | ||
586 | } | ||
587 | } | ||
588 | last = gEpocEnv->iCleanupItems->Count() - 1; | ||
589 | for(i = last; i >= 0 ; i--) | ||
590 | { | ||
591 | TSdlCleanupItem& item = gEpocEnv->iCleanupItems->At(i); | ||
592 | if(item.iThread == TThreadId(0)) | ||
593 | { | ||
594 | gEpocEnv->iCleanupItems->Delete(i); | ||
595 | } | ||
596 | } | ||
597 | } | ||
598 | |||
599 | void EpocSdlEnv::FreeSurface() | ||
600 | { | ||
601 | Request(CSdlAppServ::EAppSrvDsaStatus); | ||
602 | gEpocEnv->iDsa->Free(); | ||
603 | } | ||
604 | |||
605 | void EpocSdlEnv::LockPalette(TBool aLock) | ||
606 | { | ||
607 | gEpocEnv->iDsa->LockPalette(aLock); | ||
608 | } | ||
609 | |||
610 | void EpocSdlEnv::ObserverEvent(TInt aService, TInt aParam) | ||
611 | { | ||
612 | const TBool sdlThread = RThread().Id() == gEpocEnv->iId; | ||
613 | const TInt valuea = gEpocEnv->iAppSrv->ObserverEvent(aService, aParam); | ||
614 | gEpocEnv->iAppSrv->HandleObserverValue(aService, valuea, !sdlThread); | ||
615 | if(sdlThread) | ||
616 | { | ||
617 | gEpocEnv->iAppSrv->SetParam(aParam); | ||
618 | const TInt valuet = gEpocEnv->iAppSrv->RequestValue(aService); | ||
619 | gEpocEnv->iAppSrv->HandleObserverValue(aService, valuet, EFalse); | ||
620 | } | ||
621 | } | ||
622 | |||
623 | |||
624 | TPoint EpocSdlEnv::WindowCoordinates(const TPoint& aPoint) | ||
625 | { | ||
626 | return gEpocEnv->iDsa->WindowCoordinates(aPoint); | ||
627 | } | ||
628 | |||
629 | void EpocSdlEnv::PanicMain(const TDesC& aInfo, TInt aErr) | ||
630 | { | ||
631 | gEpocEnv->iAppSrv->PanicMain(aInfo, aErr); | ||
632 | } | ||
633 | //Dsa is a low priority ao, it has to wait if its pending event, but ws | ||
634 | //event has been prioritized before it | ||
635 | //this is not called from app thread! | ||
636 | void EpocSdlEnv::WaitDeviceChange() | ||
637 | { | ||
638 | LockPalette(ETrue); | ||
639 | gEpocEnv->iAppSrv->RequestValue(CSdlAppServ::EAppSrvWaitDsa); | ||
640 | const TSize sz = WindowSize(); | ||
641 | const TInt param = reinterpret_cast<TInt>(&sz); | ||
642 | ObserverEvent(MSDLObserver::EEventScreenSizeChanged, param); | ||
643 | |||
644 | // RThread().Suspend(); | ||
645 | } | ||
646 | |||
647 | LOCAL_C TBool CheckSdl() | ||
648 | { | ||
649 | TInt isExit = ETrue; | ||
650 | RThread sdl; | ||
651 | if(sdl.Open(gEpocEnv->iId) == KErrNone) | ||
652 | { | ||
653 | if(sdl.ExitType() == EExitPending) | ||
654 | { | ||
655 | isExit = EFalse; | ||
656 | } | ||
657 | sdl.Close(); | ||
658 | } | ||
659 | return isExit; | ||
660 | } | ||
661 | |||
662 | void EpocSdlEnvData::Free() | ||
663 | { | ||
664 | if(RThread().Id() == gEpocEnv->iId) | ||
665 | { | ||
666 | iDsa->Free(); | ||
667 | return; | ||
668 | } | ||
669 | |||
670 | __ASSERT_ALWAYS(iArgv == NULL || CheckSdl(), PANIC(KErrNotReady)); | ||
671 | |||
672 | for(TInt i = 0; i < iArgc; i++) | ||
673 | User::Free( iArgv[i] ); | ||
674 | |||
675 | User::Free(iArgv); | ||
676 | |||
677 | |||
678 | delete iEventQueue; | ||
679 | |||
680 | if(iDsa != NULL) | ||
681 | iDsa->Free(); | ||
682 | |||
683 | delete iDsa; | ||
684 | delete iAppSrv; | ||
685 | } | ||
686 | |||
687 | _LIT(KSDLMain, "SDLMain"); | ||
688 | |||
689 | LOCAL_C int MainL() | ||
690 | { | ||
691 | gEpocEnv->iCleanupItems = new (ELeave) CArrayFixFlat<TSdlCleanupItem>(8); | ||
692 | |||
693 | char** envp=0; | ||
694 | /* !! process exits here if there is "exit()" in main! */ | ||
695 | int ret = 0; | ||
696 | for(TInt i = 0; i < 6; i++) | ||
697 | { | ||
698 | void* f = (void*) gEpocEnv->iMain[i]; | ||
699 | if(f != NULL) | ||
700 | { | ||
701 | switch(i) | ||
702 | { | ||
703 | case 0: | ||
704 | ret = ((mainfunc1)f)(); | ||
705 | return ret; | ||
706 | case 3: | ||
707 | ((mainfunc1)f)(); | ||
708 | return ret; | ||
709 | case 1: | ||
710 | ret = ((mainfunc2)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv()); | ||
711 | return ret; | ||
712 | case 4: | ||
713 | ((mainfunc2)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv()); | ||
714 | return ret; | ||
715 | case 2: | ||
716 | ret = ((mainfunc3)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv(), envp); | ||
717 | return ret; | ||
718 | case 5: | ||
719 | ((mainfunc3)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv(), envp); | ||
720 | return ret; | ||
721 | } | ||
722 | } | ||
723 | } | ||
724 | PANIC(KErrNotFound); | ||
725 | return 0; | ||
726 | } | ||
727 | |||
728 | LOCAL_C TInt DoMain(TAny* /*aParam*/) | ||
729 | { | ||
730 | |||
731 | |||
732 | CTrapCleanup* cleanup = CTrapCleanup::New(); | ||
733 | |||
734 | TBool fbsconnected = EFalse; | ||
735 | if(RFbsSession::GetSession() == NULL) | ||
736 | { | ||
737 | PANIC_IF_ERROR(RFbsSession::Connect()); | ||
738 | fbsconnected = ETrue; | ||
739 | } | ||
740 | |||
741 | gEpocEnv->iAppSrv->Init(); | ||
742 | |||
743 | #ifdef SYMBIANC | ||
744 | // Create stdlib | ||
745 | _REENT; | ||
746 | #endif | ||
747 | |||
748 | // Call stdlib main | ||
749 | int ret = 0; | ||
750 | |||
751 | //completes waiting rendesvous | ||
752 | RThread::Rendezvous(KErrNone); | ||
753 | |||
754 | TRAPD(err, err = MainL()); | ||
755 | |||
756 | EpocSdlEnv::ObserverEvent(MSDLObserver::EEventMainExit, err); | ||
757 | |||
758 | // Free resources and return | ||
759 | |||
760 | EpocSdlEnv::CleanupItems(); | ||
761 | |||
762 | gEpocEnv->iCleanupItems->Reset(); | ||
763 | delete gEpocEnv->iCleanupItems; | ||
764 | gEpocEnv->iCleanupItems = NULL; | ||
765 | |||
766 | gEpocEnv->Free(); //free up in thread resources | ||
767 | |||
768 | #ifdef SYMBIANC | ||
769 | _cleanup(); //this is normally called at exit, I call it here | ||
770 | #endif | ||
771 | |||
772 | if(fbsconnected) | ||
773 | RFbsSession::Disconnect(); | ||
774 | |||
775 | #ifdef SYMBIANC | ||
776 | CloseSTDLIB(); | ||
777 | #endif | ||
778 | |||
779 | // delete as; | ||
780 | delete cleanup; | ||
781 | |||
782 | return err == KErrNone ? ret : err;; | ||
783 | } | ||
784 | |||
785 | |||
786 | |||
787 | EXPORT_C CSDL::~CSDL() | ||
788 | { | ||
789 | gEpocEnv->Free(); | ||
790 | User::Free(gEpocEnv); | ||
791 | gEpocEnv->iSdl = NULL; | ||
792 | } | ||
793 | |||
794 | EXPORT_C CSDL* CSDL::NewL(TInt aFlags) | ||
795 | { | ||
796 | __ASSERT_ALWAYS(gEpocEnv == NULL, PANIC(KErrAlreadyExists)); | ||
797 | gEpocEnv = (EpocSdlEnvData*) User::AllocL(sizeof(EpocSdlEnvData)); | ||
798 | Mem::FillZ(gEpocEnv, sizeof(EpocSdlEnvData)); | ||
799 | |||
800 | gEpocEnv->iEpocEnvFlags = aFlags; | ||
801 | gEpocEnv->iEventQueue = CEventQueue::NewL(); | ||
802 | |||
803 | gEpocEnv->iAppSrv = new (ELeave) CSdlAppServ(); | ||
804 | gEpocEnv->iAppSrv->ConstructL(); | ||
805 | |||
806 | CSDL* sdl = new (ELeave) CSDL(); | ||
807 | |||
808 | gEpocEnv->iSdl = sdl; | ||
809 | |||
810 | return sdl; | ||
811 | } | ||
812 | |||
813 | /* | ||
814 | EXPORT_C void CSDL::ReInitL(TFlags aFlags) | ||
815 | { | ||
816 | const TFlags prevFlags = gEpocEnv->iEpocEnvFlags; | ||
817 | gEpocEnv->iEpocEnvFlags = aFlags; | ||
818 | TInt err = KErrNone; | ||
819 | if(((prevFlags & EDrawModeDSB) != (aFlags & EDrawModeDSB)) && gEpocEnv->iDsa) | ||
820 | { | ||
821 | delete gEpocEnv->iDsa; | ||
822 | gEpocEnv->iDsa = NULL; | ||
823 | gEpocEnv->iDsa = CDsa::RecreateL(EpocSdlEnv::Flags(CSDL::EDrawModeDSB)); | ||
824 | } | ||
825 | } | ||
826 | */ | ||
827 | |||
828 | |||
829 | EXPORT_C void CSDL::SetContainerWindowL(RWindow& aWindow, RWsSession& aSession, CWsScreenDevice& aDevice) | ||
830 | { | ||
831 | if(gEpocEnv->iDsa == NULL) | ||
832 | gEpocEnv->iDsa = CDsa::CreateL(aSession); | ||
833 | gEpocEnv->iDsa->ConstructL(aWindow, aDevice); | ||
834 | } | ||
835 | |||
836 | |||
837 | EXPORT_C TThreadId CSDL::CallMainL(const TMainFunc& aFunc, TRequestStatus* const aStatus, const CDesC8Array* const aArg, TInt aFlags, TInt aStackSize) | ||
838 | { | ||
839 | ASSERT(gEpocEnv != NULL); | ||
840 | gEpocEnv->iMain = aFunc; | ||
841 | const TBool args = aArg != NULL; | ||
842 | |||
843 | gEpocEnv->iArgc = aArg->Count() + 1; | ||
844 | gEpocEnv->iArgv = (char**) User::AllocL(sizeof(char*) * (gEpocEnv->iArgc + 1)); | ||
845 | |||
846 | TInt k = 0; | ||
847 | const TFileName processName = RProcess().FileName(); | ||
848 | const TInt len = processName.Length(); | ||
849 | gEpocEnv->iArgv[k] = (char*) User::AllocL(len + 1); | ||
850 | Mem::Copy(gEpocEnv->iArgv[k], processName.Ptr(), len); | ||
851 | gEpocEnv->iArgv[k][len] = 0; | ||
852 | |||
853 | for(TInt i = 0; args && (i < aArg->Count()); i++) | ||
854 | { | ||
855 | k++; | ||
856 | const TInt len = aArg->MdcaPoint(i).Length(); | ||
857 | gEpocEnv->iArgv[k] = (char*) User::AllocL(len + 1); | ||
858 | Mem::Copy(gEpocEnv->iArgv[k], aArg->MdcaPoint(i).Ptr(), len); | ||
859 | gEpocEnv->iArgv[k][len] = 0; | ||
860 | } | ||
861 | |||
862 | gEpocEnv->iArgv[gEpocEnv->iArgc] = NULL; | ||
863 | |||
864 | RThread thread; | ||
865 | User::LeaveIfError(thread.Create(KSDLMain, DoMain, aStackSize, NULL, NULL)); | ||
866 | |||
867 | if(aStatus != NULL) | ||
868 | { | ||
869 | thread.Logon(*aStatus); | ||
870 | } | ||
871 | |||
872 | gEpocEnv->iId = thread.Id(); | ||
873 | thread.SetPriority(EPriorityLess); | ||
874 | if((aFlags & CSDL::ERequestResume) == 0) | ||
875 | { | ||
876 | thread.Resume(); | ||
877 | } | ||
878 | thread.Close(); | ||
879 | return gEpocEnv->iId; | ||
880 | } | ||
881 | |||
882 | EXPORT_C TInt CSDL::AppendWsEvent(const TWsEvent& aEvent) | ||
883 | { | ||
884 | return EpocSdlEnv::EventQueue().Append(aEvent); | ||
885 | } | ||
886 | |||
887 | EXPORT_C void CSDL::SDLPanic(const TDesC& aInfo, TInt aErr) | ||
888 | { | ||
889 | EpocSdlEnv::PanicMain(aInfo, aErr); | ||
890 | } | ||
891 | |||
892 | EXPORT_C TInt CSDL::GetSDLCode(TInt aScanCode) | ||
893 | { | ||
894 | if(aScanCode < 0) | ||
895 | return MAX_SCANCODE; | ||
896 | if(aScanCode >= MAX_SCANCODE) | ||
897 | return -1; | ||
898 | return KeyMap()[aScanCode]; | ||
899 | } | ||
900 | |||
901 | EXPORT_C TInt CSDL::SDLCodesCount() const | ||
902 | { | ||
903 | return MAX_SCANCODE; | ||
904 | } | ||
905 | |||
906 | EXPORT_C void CSDL::ResetSDLCodes() | ||
907 | { | ||
908 | ResetKeyMap(); | ||
909 | } | ||
910 | |||
911 | EXPORT_C void CSDL::SetOrientation(TOrientationMode aMode) | ||
912 | { | ||
913 | gEpocEnv->iDsa->SetOrientation(aMode); | ||
914 | } | ||
915 | |||
916 | EXPORT_C TInt CSDL::SetSDLCode(TInt aScanCode, TInt aSDLCode) | ||
917 | { | ||
918 | const TInt current = GetSDLCode(aScanCode); | ||
919 | if(aScanCode >= 0 && aScanCode < MAX_SCANCODE) | ||
920 | KeyMap()[aScanCode] = static_cast<SDLKey>(aSDLCode); | ||
921 | return current; | ||
922 | } | ||
923 | |||
924 | |||
925 | EXPORT_C MSDLObserver* CSDL::Observer() | ||
926 | { | ||
927 | return gEpocEnv->iAppSrv->Observer(); | ||
928 | } | ||
929 | |||
930 | EXPORT_C void CSDL::SetObserver(MSDLObserver* aObserver) | ||
931 | { | ||
932 | gEpocEnv->iAppSrv->SetObserver(aObserver); | ||
933 | } | ||
934 | |||
935 | EXPORT_C void CSDL::Resume() | ||
936 | { | ||
937 | EpocSdlEnv::Resume(); | ||
938 | } | ||
939 | |||
940 | EXPORT_C void CSDL::Suspend() | ||
941 | { | ||
942 | gEpocEnv->iDsa->DoStop(); | ||
943 | } | ||
944 | |||
945 | EXPORT_C CSDL::CSDL() | ||
946 | { | ||
947 | } | ||
948 | |||
949 | EXPORT_C void CSDL::DisableKeyBlocking(CAknAppUi& aAppUi) const | ||
950 | { | ||
951 | gEpocEnv->iAppUi = &aAppUi; | ||
952 | EnvUtils::DisableKeyBlocking(); | ||
953 | } | ||
954 | |||
955 | EXPORT_C TInt CSDL::SetBlitter(MBlitter* aBlitter) | ||
956 | { | ||
957 | if(gEpocEnv && gEpocEnv->iDsa) | ||
958 | { | ||
959 | gEpocEnv->iDsa->SetBlitter(aBlitter); | ||
960 | return KErrNone; | ||
961 | } | ||
962 | return KErrNotReady; | ||
963 | } | ||
964 | |||
965 | |||
966 | EXPORT_C TInt CSDL::AppendOverlay(MOverlay& aOverlay, TInt aPriority) | ||
967 | { | ||
968 | if(gEpocEnv && gEpocEnv->iDsa) | ||
969 | { | ||
970 | return gEpocEnv->iDsa->AppendOverlay(aOverlay, aPriority); | ||
971 | } | ||
972 | return KErrNotReady; | ||
973 | } | ||
974 | |||
975 | EXPORT_C TInt CSDL::RemoveOverlay(MOverlay& aOverlay) | ||
976 | { | ||
977 | if(gEpocEnv && gEpocEnv->iDsa) | ||
978 | { | ||
979 | return gEpocEnv->iDsa->RemoveOverlay(aOverlay); | ||
980 | } | ||
981 | return KErrNotReady; | ||
982 | } | ||
983 | |||
984 | EXPORT_C TInt CSDL::RedrawRequest() | ||
985 | { | ||
986 | if(gEpocEnv && gEpocEnv->iDsa) | ||
987 | { | ||
988 | return gEpocEnv->iDsa->RedrawRequest(); | ||
989 | } | ||
990 | return KErrNotReady; | ||
991 | } | ||
992 | |||
993 | /* | ||
994 | EXPORT_C CSDL* CSDL::Current() | ||
995 | { | ||
996 | return gEpocEnv != NULL ? gEpocEnv->iSdl : NULL; | ||
997 | } | ||
998 | |||
999 | |||
1000 | EXPORT_C TInt CSDL::SetVolume(TInt aVolume) | ||
1001 | { | ||
1002 | return EpocSdlEnv::SetVolume(aVolume); | ||
1003 | } | ||
1004 | |||
1005 | EXPORT_C TInt CSDL::Volume() const | ||
1006 | { | ||
1007 | return EpocSdlEnv::Volume(); | ||
1008 | } | ||
1009 | |||
1010 | EXPORT_C TInt CSDL::MaxVolume() const | ||
1011 | { | ||
1012 | return EpocSdlEnv::MaxVolume(); | ||
1013 | } | ||
1014 | */ | ||
1015 | |||
1016 | void EnvUtils::DisableKeyBlocking() | ||
1017 | { | ||
1018 | if(gEpocEnv->iAppUi != NULL) | ||
1019 | return CCurrentAppUi::Cast(gEpocEnv->iAppUi)->DisableKeyBlocking(); | ||
1020 | } | ||
1021 | |||
1022 | TBool EnvUtils::Rendezvous(RThread& aThread, TRequestStatus& aStatus) | ||
1023 | { | ||
1024 | if(gEpocEnv->iId != TThreadId(0) && | ||
1025 | aThread.Open(gEpocEnv->iId) && | ||
1026 | aThread.ExitType() == EExitPending) | ||
1027 | { | ||
1028 | aThread.Rendezvous(aStatus); | ||
1029 | return ETrue; | ||
1030 | } | ||
1031 | return EFalse; | ||
1032 | } | ||
1033 | |||
1034 | |||
1035 | |||
diff --git a/apps/plugins/sdl/src/main/symbian/EKA2/sdlexe.cpp b/apps/plugins/sdl/src/main/symbian/EKA2/sdlexe.cpp new file mode 100644 index 0000000000..bb160c4090 --- /dev/null +++ b/apps/plugins/sdl/src/main/symbian/EKA2/sdlexe.cpp | |||
@@ -0,0 +1,809 @@ | |||
1 | // INCLUDES | ||
2 | #include <aknapp.h> | ||
3 | #include <aknappui.h> | ||
4 | #include <eikdoc.h> | ||
5 | #include <sdlepocapi.h> | ||
6 | #include <bautils.h> | ||
7 | #include <eikstart.h> | ||
8 | #include <badesca.h> | ||
9 | #include <bautils.h> | ||
10 | #include <apgcli.h> | ||
11 | #include <sdlmain.h> | ||
12 | #include <eikedwin.h> | ||
13 | #include <eiklabel.h> | ||
14 | #include <sdlexe.rsg> | ||
15 | #include <aknglobalmsgquery.h> | ||
16 | #include <apgwgnam.h> | ||
17 | |||
18 | |||
19 | |||
20 | // FORWARD DECLARATIONS | ||
21 | class CApaDocument; | ||
22 | |||
23 | |||
24 | //const TUid KSDLUID = { 0xF01F605E }; | ||
25 | |||
26 | LOCAL_C void MakeCCmdLineL(const TDesC8& aParam, CDesC8Array& aArray) | ||
27 | { | ||
28 | |||
29 | const TChar dq('\"'); | ||
30 | |||
31 | TLex8 lex(aParam); | ||
32 | TBool in = EFalse; | ||
33 | |||
34 | lex.SkipSpaceAndMark(); | ||
35 | |||
36 | while(!lex.Eos()) | ||
37 | { | ||
38 | TPtrC8 ptr; | ||
39 | if(in) | ||
40 | { | ||
41 | const TPtrC8 rem = lex.RemainderFromMark(); | ||
42 | const TInt pos = rem.Locate(dq); | ||
43 | if(pos > 0) | ||
44 | { | ||
45 | lex.Inc(pos); | ||
46 | ptr.Set(lex.MarkedToken()); | ||
47 | lex.SkipAndMark(1); | ||
48 | } | ||
49 | else | ||
50 | { | ||
51 | ptr.Set(rem); | ||
52 | } | ||
53 | in = EFalse; | ||
54 | } | ||
55 | else | ||
56 | { | ||
57 | ptr.Set(lex.NextToken()); | ||
58 | const TInt pos = ptr.Locate(dq); | ||
59 | if(pos == 0) | ||
60 | { | ||
61 | lex.UnGetToMark(); | ||
62 | lex.SkipAndMark(1); | ||
63 | in = ETrue; | ||
64 | continue; // back to in brace | ||
65 | } | ||
66 | else | ||
67 | lex.SkipSpaceAndMark(); | ||
68 | } | ||
69 | |||
70 | aArray.AppendL(ptr); | ||
71 | |||
72 | } | ||
73 | } | ||
74 | |||
75 | NONSHARABLE_CLASS(TVirtualCursor) : public MOverlay | ||
76 | { | ||
77 | public: | ||
78 | TVirtualCursor(); | ||
79 | void Set(const TRect& aRect, CFbsBitmap* aBmp, CFbsBitmap* aAlpha); | ||
80 | void Move(TInt aX, TInt aY); | ||
81 | void MakeEvent(TWsEvent& aEvent, const TPoint& aBasePos) const; | ||
82 | void Toggle(); | ||
83 | TBool IsOn() const; | ||
84 | private: | ||
85 | void Draw(CBitmapContext& aGc, const TRect& aTargetRect, const TSize& aSize); | ||
86 | private: | ||
87 | TRect iRect; | ||
88 | TPoint iInc; | ||
89 | TPoint iPos; | ||
90 | TBool iIsOn; | ||
91 | CFbsBitmap* iCBmp; | ||
92 | CFbsBitmap* iAlpha; | ||
93 | }; | ||
94 | |||
95 | |||
96 | TVirtualCursor::TVirtualCursor() : iInc(0, 0), iIsOn(EFalse), iCBmp(NULL) | ||
97 | { | ||
98 | } | ||
99 | |||
100 | const TInt KMaxMove = 10; | ||
101 | |||
102 | void TVirtualCursor::Move(TInt aX, TInt aY) | ||
103 | { | ||
104 | if(aX > 0 && iInc.iX > 0) | ||
105 | ++iInc.iX; | ||
106 | else if(aX < 0 && iInc.iX < 0) | ||
107 | --iInc.iX; | ||
108 | else | ||
109 | iInc.iX = aX; | ||
110 | |||
111 | if(aY > 0 && iInc.iY > 0) | ||
112 | ++iInc.iY; | ||
113 | else if(aY < 0 && iInc.iY < 0) | ||
114 | --iInc.iY; | ||
115 | else | ||
116 | iInc.iY = aY; | ||
117 | |||
118 | iInc.iX = Min(KMaxMove, iInc.iX); | ||
119 | |||
120 | iInc.iX = Max(-KMaxMove, iInc.iX); | ||
121 | |||
122 | iInc.iY = Min(KMaxMove, iInc.iY); | ||
123 | |||
124 | iInc.iY =Max(-KMaxMove, iInc.iY); | ||
125 | |||
126 | const TPoint pos = iPos + iInc; | ||
127 | if(iRect.Contains(pos)) | ||
128 | { | ||
129 | iPos = pos; | ||
130 | } | ||
131 | else | ||
132 | { | ||
133 | iInc = TPoint(0, 0); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | |||
138 | void TVirtualCursor::Toggle() | ||
139 | { | ||
140 | iIsOn = !iIsOn; | ||
141 | } | ||
142 | |||
143 | |||
144 | TBool TVirtualCursor::IsOn() const | ||
145 | { | ||
146 | return iIsOn; | ||
147 | } | ||
148 | |||
149 | void TVirtualCursor::Set(const TRect& aRect, CFbsBitmap* aBmp, CFbsBitmap* aAlpha) | ||
150 | { | ||
151 | iRect = aRect; | ||
152 | iCBmp = aBmp; | ||
153 | iAlpha = aAlpha; | ||
154 | } | ||
155 | |||
156 | |||
157 | void TVirtualCursor::MakeEvent(TWsEvent& aEvent, const TPoint& aBasePos) const | ||
158 | { | ||
159 | aEvent.SetType(EEventPointer), | ||
160 | aEvent.SetTimeNow(); | ||
161 | TPointerEvent& pointer = *aEvent.Pointer(); | ||
162 | pointer.iType = TPointerEvent::EButton1Down; | ||
163 | pointer.iPosition = iPos; | ||
164 | pointer.iParentPosition = aBasePos; | ||
165 | } | ||
166 | |||
167 | |||
168 | void TVirtualCursor::Draw(CBitmapContext& aGc, const TRect& /*aTargetRect*/, const TSize& /*aSize*/) | ||
169 | { | ||
170 | if(iIsOn && iCBmp != NULL) | ||
171 | { | ||
172 | const TRect rect(TPoint(0, 0), iCBmp->SizeInPixels()); | ||
173 | aGc.AlphaBlendBitmaps(iPos, iCBmp, rect, iAlpha, TPoint(0, 0)); | ||
174 | } | ||
175 | |||
176 | } | ||
177 | |||
178 | NONSHARABLE_CLASS(TSdlClass) | ||
179 | { | ||
180 | public: | ||
181 | TSdlClass(); | ||
182 | void SetMain(const TMainFunc& aFunc, TInt aFlags, MSDLMainObs* aObs, TInt aExeFlags); | ||
183 | TInt SdlFlags() const; | ||
184 | const TMainFunc& Main() const; | ||
185 | void SendEvent(TInt aEvent, TInt aParam, CSDL* aSDL); | ||
186 | TInt AppFlags() const; | ||
187 | void AppFlags(TInt aFlags); | ||
188 | private: | ||
189 | TMainFunc iFunc; | ||
190 | TInt iSdlFlags; | ||
191 | TInt iExeFlags; | ||
192 | MSDLMainObs* iObs; | ||
193 | }; | ||
194 | |||
195 | |||
196 | void TSdlClass::AppFlags(TInt aFlags) | ||
197 | { | ||
198 | iExeFlags |= aFlags; | ||
199 | } | ||
200 | |||
201 | void TSdlClass::SendEvent(TInt aEvent, TInt aParam, CSDL* aSDL) | ||
202 | { | ||
203 | if(iObs != NULL) | ||
204 | iObs->SDLMainEvent(aEvent, aParam, aSDL); | ||
205 | } | ||
206 | |||
207 | TInt TSdlClass::AppFlags() const | ||
208 | { | ||
209 | return iExeFlags; | ||
210 | } | ||
211 | |||
212 | void TSdlClass::SetMain(const TMainFunc& aFunc, TInt aFlags, MSDLMainObs* aObs, TInt aExeFlags) | ||
213 | { | ||
214 | iFunc = aFunc; | ||
215 | iSdlFlags = aFlags; | ||
216 | iExeFlags = aExeFlags; | ||
217 | iObs = aObs; | ||
218 | } | ||
219 | |||
220 | const TMainFunc& TSdlClass::Main() const | ||
221 | { | ||
222 | return iFunc; | ||
223 | } | ||
224 | |||
225 | |||
226 | TInt TSdlClass::SdlFlags() const | ||
227 | { | ||
228 | return iSdlFlags; | ||
229 | } | ||
230 | |||
231 | |||
232 | |||
233 | TSdlClass::TSdlClass() | ||
234 | { | ||
235 | Mem::FillZ(this, sizeof(this)); | ||
236 | } | ||
237 | |||
238 | TSdlClass gSDLClass; | ||
239 | |||
240 | |||
241 | //////////////////////////////////////////////////////////////// | ||
242 | |||
243 | NONSHARABLE_CLASS(CSDLApplication) : public CAknApplication | ||
244 | { | ||
245 | public: | ||
246 | CSDLApplication(); | ||
247 | private: | ||
248 | CApaDocument* CreateDocumentL(); | ||
249 | TFileName ResourceFileName() const; | ||
250 | TUid AppDllUid() const; | ||
251 | void FindMeL(); | ||
252 | TUid iUid; | ||
253 | }; | ||
254 | |||
255 | NONSHARABLE_CLASS(CSDLDocument) : public CEikDocument | ||
256 | { | ||
257 | public: | ||
258 | CSDLDocument(CEikApplication& aApp); | ||
259 | private: | ||
260 | CEikAppUi* CreateAppUiL(); | ||
261 | |||
262 | }; | ||
263 | |||
264 | //////////////////////////////////////////////////////////////////// | ||
265 | |||
266 | |||
267 | NONSHARABLE_CLASS(MExitWait) | ||
268 | { | ||
269 | public: | ||
270 | virtual void DoExit(TInt aErr) = 0; | ||
271 | }; | ||
272 | |||
273 | ///////////////////////////////////////////////////////////////////////// | ||
274 | |||
275 | NONSHARABLE_CLASS(CExitWait) : public CActive | ||
276 | { | ||
277 | public: | ||
278 | CExitWait(MExitWait& aWait); | ||
279 | ~CExitWait(); | ||
280 | private: | ||
281 | void RunL(); | ||
282 | void DoCancel(); | ||
283 | private: | ||
284 | MExitWait& iWait; | ||
285 | TRequestStatus* iStatusPtr; | ||
286 | }; | ||
287 | |||
288 | //////////////////////////////////////////////////////////////////////// | ||
289 | |||
290 | |||
291 | NONSHARABLE_CLASS(CSDLWin) : public CCoeControl | ||
292 | { | ||
293 | public: | ||
294 | void ConstructL(const TRect& aRect); | ||
295 | RWindow& GetWindow() const; | ||
296 | void SetNoDraw(); | ||
297 | private: | ||
298 | void Draw(const TRect& aRect) const; | ||
299 | private: | ||
300 | TBool iNoDraw; | ||
301 | }; | ||
302 | |||
303 | |||
304 | //////////////////////////////////////////////////////////////////////////// | ||
305 | |||
306 | NONSHARABLE_CLASS(CSDLAppUi) : public CAknAppUi, public MExitWait, MSDLObserver | ||
307 | { | ||
308 | public: | ||
309 | ~CSDLAppUi(); | ||
310 | private: // New functions | ||
311 | void ConstructL(); | ||
312 | void HandleCommandL(TInt aCommand); | ||
313 | void HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination); | ||
314 | void HandleResourceChangeL(TInt aType); | ||
315 | |||
316 | void DoExit(TInt aErr); | ||
317 | |||
318 | TInt SdlEvent(TInt aEvent, TInt aParam); | ||
319 | TInt SdlThreadEvent(TInt aEvent, TInt aParam); | ||
320 | |||
321 | void StartL(); | ||
322 | static TBool StartL(TAny* aThis); | ||
323 | |||
324 | TBool ParamEditorL(TDes& aCheat); | ||
325 | |||
326 | TBool ProcessCommandParametersL(CApaCommandLine &aCommandLine); | ||
327 | |||
328 | void PrepareToExit(); | ||
329 | void HandleConsoleWindowL(); | ||
330 | void HandleConsoleWindow(); | ||
331 | void HandleForegroundEventL(TBool aForeground); | ||
332 | |||
333 | static TBool IdleRequestL(TAny* aThis); | ||
334 | |||
335 | TBool HandleKeyL(const TWsEvent& aEvent); | ||
336 | |||
337 | |||
338 | private: | ||
339 | CExitWait* iWait; | ||
340 | CSDLWin* iSDLWin; | ||
341 | CSDL* iSdl; | ||
342 | CIdle* iStarter; | ||
343 | TBool iExitRequest; | ||
344 | CDesC8Array* iParams; | ||
345 | TInt iResOffset; | ||
346 | CIdle* iIdle; | ||
347 | TInt iStdOut; | ||
348 | TVirtualCursor iCursor; | ||
349 | CFbsBitmap* iCBmp; | ||
350 | CFbsBitmap* iAlpha; | ||
351 | // TTime iLastPress; | ||
352 | // CSDL::TOrientationMode iOrientation; | ||
353 | }; | ||
354 | |||
355 | ////////////////////////////////////////////////////////////////////////////////////////7 | ||
356 | |||
357 | CApaDocument* CSDLApplication::CreateDocumentL() | ||
358 | { | ||
359 | return new (ELeave) CSDLDocument(*this); | ||
360 | } | ||
361 | |||
362 | TUid CSDLApplication::AppDllUid() const | ||
363 | { | ||
364 | return iUid; | ||
365 | } | ||
366 | |||
367 | |||
368 | CSDLApplication::CSDLApplication() | ||
369 | { | ||
370 | TRAPD(err, FindMeL()); | ||
371 | ASSERT(err == KErrNone); | ||
372 | } | ||
373 | |||
374 | void CSDLApplication::FindMeL() | ||
375 | { | ||
376 | RApaLsSession apa; | ||
377 | User::LeaveIfError(apa.Connect()); | ||
378 | CleanupClosePushL(apa); | ||
379 | User::LeaveIfError(apa.GetAllApps()); | ||
380 | TFileName name = RProcess().FileName(); | ||
381 | TApaAppInfo info; | ||
382 | while(apa.GetNextApp(info) == KErrNone) | ||
383 | { | ||
384 | if(info.iFullName.CompareF(name) == 0) | ||
385 | { | ||
386 | iUid = info.iUid; | ||
387 | break; | ||
388 | } | ||
389 | } | ||
390 | CleanupStack::PopAndDestroy(); | ||
391 | } | ||
392 | |||
393 | TFileName CSDLApplication::ResourceFileName() const | ||
394 | { | ||
395 | return KNullDesC(); | ||
396 | } | ||
397 | |||
398 | /////////////////////////////////////////////////////////////////////////////////////////// | ||
399 | |||
400 | CExitWait::CExitWait(MExitWait& aWait) : CActive(CActive::EPriorityStandard), iWait(aWait) | ||
401 | { | ||
402 | CActiveScheduler::Add(this); | ||
403 | SetActive(); | ||
404 | iStatusPtr = &iStatus; | ||
405 | } | ||
406 | |||
407 | CExitWait::~CExitWait() | ||
408 | { | ||
409 | Cancel(); | ||
410 | } | ||
411 | |||
412 | void CExitWait::RunL() | ||
413 | { | ||
414 | if(iStatusPtr != NULL ) | ||
415 | iWait.DoExit(iStatus.Int()); | ||
416 | } | ||
417 | |||
418 | void CExitWait::DoCancel() | ||
419 | { | ||
420 | if(iStatusPtr != NULL ) | ||
421 | User::RequestComplete(iStatusPtr , KErrCancel); | ||
422 | } | ||
423 | |||
424 | |||
425 | ////////////////////////////////////////////////////////////////////////////////////////////// | ||
426 | |||
427 | CSDLDocument::CSDLDocument(CEikApplication& aApp) : CEikDocument(aApp) | ||
428 | {} | ||
429 | |||
430 | CEikAppUi* CSDLDocument::CreateAppUiL() | ||
431 | { | ||
432 | return new (ELeave) CSDLAppUi; | ||
433 | } | ||
434 | |||
435 | /////////////////////////////////////////////////////////////////////////// | ||
436 | |||
437 | void CSDLWin:: ConstructL(const TRect& aRect) | ||
438 | { | ||
439 | CreateWindowL(); | ||
440 | SetRect(aRect); | ||
441 | ActivateL(); | ||
442 | } | ||
443 | |||
444 | |||
445 | RWindow& CSDLWin::GetWindow() const | ||
446 | { | ||
447 | return Window(); | ||
448 | } | ||
449 | |||
450 | |||
451 | void CSDLWin::Draw(const TRect& /*aRect*/) const | ||
452 | { | ||
453 | if(!iNoDraw) | ||
454 | { | ||
455 | CWindowGc& gc = SystemGc(); | ||
456 | gc.SetPenStyle(CGraphicsContext::ESolidPen); | ||
457 | gc.SetPenColor(KRgbGray); | ||
458 | gc.SetBrushStyle(CGraphicsContext::ESolidBrush); | ||
459 | gc.SetBrushColor(0xaaaaaa); | ||
460 | gc.DrawRect(Rect()); | ||
461 | } | ||
462 | } | ||
463 | |||
464 | void CSDLWin::SetNoDraw() | ||
465 | { | ||
466 | iNoDraw = ETrue; | ||
467 | } | ||
468 | |||
469 | ///////////////////////////////////////////////////////////////////////// | ||
470 | |||
471 | CSDLAppUi::~CSDLAppUi() | ||
472 | { | ||
473 | if(iIdle) | ||
474 | iIdle->Cancel(); | ||
475 | delete iIdle; | ||
476 | if(iStarter != NULL) | ||
477 | iStarter->Cancel(); | ||
478 | delete iStarter; | ||
479 | delete iWait; | ||
480 | delete iSdl; | ||
481 | delete iSDLWin; | ||
482 | delete iParams; | ||
483 | delete iCBmp; | ||
484 | delete iAlpha; | ||
485 | } | ||
486 | |||
487 | |||
488 | void CSDLAppUi::ConstructL() | ||
489 | { | ||
490 | BaseConstructL(ENoAppResourceFile | ENoScreenFurniture); | ||
491 | |||
492 | |||
493 | RLibrary lib; | ||
494 | User::LeaveIfError(lib.Load(_L("sdlexe.dll"))); | ||
495 | TFileName name = lib.FileName(); | ||
496 | lib.Close(); | ||
497 | name.Replace(3, name.Length() - 3, _L("resource\\apps\\sdlexe.rsc")); | ||
498 | BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(), name); | ||
499 | iResOffset = iCoeEnv->AddResourceFileL(name); | ||
500 | |||
501 | name.Replace(name.Length() - 3, 3, _L("mbm")); | ||
502 | |||
503 | TEntry e; | ||
504 | const TInt err = iEikonEnv->FsSession().Entry(name, e); | ||
505 | |||
506 | iCBmp = iEikonEnv->CreateBitmapL(name, 0); | ||
507 | iAlpha = iEikonEnv->CreateBitmapL(name, 1); | ||
508 | |||
509 | iIdle = CIdle::NewL(CActive::EPriorityIdle); | ||
510 | |||
511 | iSDLWin = new (ELeave) CSDLWin; | ||
512 | iSDLWin->ConstructL(ApplicationRect()); | ||
513 | |||
514 | iSdl = CSDL::NewL(gSDLClass.SdlFlags()); | ||
515 | |||
516 | gSDLClass.SendEvent(MSDLMainObs::ESDLCreated, 0, iSdl); | ||
517 | |||
518 | iSdl->SetObserver(this); | ||
519 | iSdl->DisableKeyBlocking(*this); | ||
520 | iSdl->SetContainerWindowL( | ||
521 | iSDLWin->GetWindow(), | ||
522 | iEikonEnv->WsSession(), | ||
523 | *iEikonEnv->ScreenDevice()); | ||
524 | iSdl->AppendOverlay(iCursor, 0); | ||
525 | |||
526 | iCursor.Set(TRect(TPoint(0, 0), iSDLWin->Size()), iCBmp, iAlpha); | ||
527 | |||
528 | iStarter = CIdle::NewL(CActive::EPriorityLow); | ||
529 | iStarter->Start(TCallBack(StartL, this)); | ||
530 | |||
531 | |||
532 | } | ||
533 | |||
534 | |||
535 | |||
536 | TBool CSDLAppUi::StartL(TAny* aThis) | ||
537 | { | ||
538 | static_cast<CSDLAppUi*>(aThis)->StartL(); | ||
539 | return EFalse; | ||
540 | } | ||
541 | |||
542 | |||
543 | void CSDLAppUi::PrepareToExit() | ||
544 | { | ||
545 | CAknAppUiBase::PrepareToExit(); //aknappu::PrepareToExit crashes | ||
546 | iCoeEnv->DeleteResourceFile(iResOffset); | ||
547 | } | ||
548 | |||
549 | TBool CSDLAppUi::ProcessCommandParametersL(CApaCommandLine &aCommandLine) | ||
550 | { | ||
551 | const TPtrC8 cmdLine = aCommandLine.TailEnd(); | ||
552 | iParams = new (ELeave) CDesC8ArrayFlat(8); | ||
553 | MakeCCmdLineL(cmdLine, *iParams); | ||
554 | return EFalse; | ||
555 | } | ||
556 | |||
557 | |||
558 | TBool CSDLAppUi::ParamEditorL(TDes& aCheat) | ||
559 | { | ||
560 | CAknTextQueryDialog* query = CAknTextQueryDialog::NewL(aCheat); | ||
561 | CleanupStack::PushL(query); | ||
562 | query->SetPromptL(_L("Enter parameters")); | ||
563 | CleanupStack::Pop(); | ||
564 | return query->ExecuteLD(R_PARAMEDITOR); | ||
565 | } | ||
566 | |||
567 | void CSDLAppUi::StartL() | ||
568 | { | ||
569 | if(gSDLClass.AppFlags() & SDLEnv::EParamQuery) | ||
570 | { | ||
571 | TBuf8<256> cmd; | ||
572 | RFile file; | ||
573 | TInt err = file.Open(iEikonEnv->FsSession(), _L("sdl_param.txt"),EFileRead); | ||
574 | if(err == KErrNone) | ||
575 | { | ||
576 | file.Read(cmd); | ||
577 | file.Close(); | ||
578 | MakeCCmdLineL(cmd, *iParams); | ||
579 | } | ||
580 | if(err != KErrNone || gSDLClass.AppFlags() & (SDLEnv::EParamQueryDialog ^ SDLEnv::EParamQuery)) | ||
581 | { | ||
582 | TBuf<256> buffer; | ||
583 | if(ParamEditorL(buffer)) | ||
584 | { | ||
585 | cmd.Copy(buffer); | ||
586 | MakeCCmdLineL(cmd, *iParams); | ||
587 | } | ||
588 | } | ||
589 | } | ||
590 | iWait = new (ELeave) CExitWait(*this); | ||
591 | iSdl->CallMainL(gSDLClass.Main(), &iWait->iStatus, iParams, CSDL::ENoParamFlags, 0xA000); | ||
592 | } | ||
593 | |||
594 | void CSDLAppUi::HandleCommandL(TInt aCommand) | ||
595 | { | ||
596 | switch(aCommand) | ||
597 | { | ||
598 | case EAknSoftkeyBack: | ||
599 | case EAknSoftkeyExit: | ||
600 | case EAknCmdExit: | ||
601 | case EEikCmdExit: | ||
602 | gSDLClass.AppFlags(SDLEnv::EAllowConsoleView); | ||
603 | if(iWait == NULL || !iWait->IsActive() || iSdl == NULL) | ||
604 | { | ||
605 | Exit(); | ||
606 | } | ||
607 | else if(!iExitRequest) | ||
608 | { | ||
609 | iExitRequest = ETrue; //trick how SDL can be closed! | ||
610 | iSdl->Suspend(); | ||
611 | } | ||
612 | break; | ||
613 | } | ||
614 | } | ||
615 | |||
616 | |||
617 | |||
618 | TBool CSDLAppUi::HandleKeyL(const TWsEvent& aEvent) | ||
619 | { | ||
620 | const TInt type = aEvent.Type(); | ||
621 | if(!(type == EEventKey || type == EEventKeyUp || type == EEventKeyDown)) | ||
622 | { | ||
623 | return ETrue; | ||
624 | } | ||
625 | const TKeyEvent& key = *aEvent.Key(); | ||
626 | if((key.iScanCode == EStdKeyYes) && (gSDLClass.AppFlags() & SDLEnv::EVirtualMouse)) | ||
627 | { | ||
628 | if(type == EEventKeyUp) | ||
629 | { | ||
630 | iCursor.Toggle(); | ||
631 | iSdl->RedrawRequest(); | ||
632 | } | ||
633 | return EFalse; | ||
634 | } | ||
635 | if(iCursor.IsOn()) | ||
636 | { | ||
637 | switch(key.iScanCode) | ||
638 | { | ||
639 | case EStdKeyUpArrow: | ||
640 | iCursor.Move(0, -1); | ||
641 | break; | ||
642 | case EStdKeyDownArrow: | ||
643 | iCursor.Move(0, 1); | ||
644 | break; | ||
645 | case EStdKeyLeftArrow: | ||
646 | iCursor.Move(-1, 0); | ||
647 | break; | ||
648 | case EStdKeyRightArrow: | ||
649 | iCursor.Move(1, 0); | ||
650 | break; | ||
651 | case EStdKeyDevice3: | ||
652 | if(type == EEventKeyUp) | ||
653 | { | ||
654 | TWsEvent event; | ||
655 | iCursor.MakeEvent(event, iSDLWin->Position()); | ||
656 | iSdl->AppendWsEvent(event); | ||
657 | } | ||
658 | return EFalse; | ||
659 | default: | ||
660 | return ETrue; | ||
661 | } | ||
662 | iSdl->RedrawRequest(); | ||
663 | return EFalse; | ||
664 | } | ||
665 | return ETrue; | ||
666 | } | ||
667 | |||
668 | void CSDLAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination) | ||
669 | { | ||
670 | if(iSdl && iWait && HandleKeyL(aEvent)) | ||
671 | iSdl->AppendWsEvent(aEvent); | ||
672 | CAknAppUi::HandleWsEventL(aEvent, aDestination); | ||
673 | } | ||
674 | |||
675 | void CSDLAppUi::HandleResourceChangeL(TInt aType) | ||
676 | { | ||
677 | CAknAppUi::HandleResourceChangeL(aType); | ||
678 | if(aType == KEikDynamicLayoutVariantSwitch) | ||
679 | { | ||
680 | iSDLWin->SetRect(ApplicationRect()); | ||
681 | iSdl->SetContainerWindowL( | ||
682 | iSDLWin->GetWindow(), | ||
683 | iEikonEnv->WsSession(), | ||
684 | *iEikonEnv->ScreenDevice()); | ||
685 | } | ||
686 | } | ||
687 | |||
688 | |||
689 | void CSDLAppUi::DoExit(TInt/*Err*/) | ||
690 | { | ||
691 | iExitRequest = ETrue; | ||
692 | Exit(); | ||
693 | } | ||
694 | |||
695 | |||
696 | TInt CSDLAppUi::SdlThreadEvent(TInt aEvent, TInt /*aParam*/) | ||
697 | { | ||
698 | switch(aEvent) | ||
699 | { | ||
700 | case MSDLObserver::EEventResume: | ||
701 | break; | ||
702 | case MSDLObserver::EEventSuspend: | ||
703 | if(iExitRequest) | ||
704 | return MSDLObserver::ESuspendNoSuspend; | ||
705 | break; | ||
706 | case MSDLObserver::EEventWindowReserved: | ||
707 | break; | ||
708 | case MSDLObserver::EEventWindowNotAvailable: | ||
709 | break; | ||
710 | case MSDLObserver::EEventScreenSizeChanged: | ||
711 | break; | ||
712 | } | ||
713 | return MSDLObserver::EParameterNone; | ||
714 | } | ||
715 | |||
716 | TInt CSDLAppUi::SdlEvent(TInt aEvent, TInt /*aParam*/) | ||
717 | { | ||
718 | switch(aEvent) | ||
719 | { | ||
720 | case MSDLObserver::EEventResume: | ||
721 | break; | ||
722 | case MSDLObserver::EEventSuspend: | ||
723 | if(iExitRequest) | ||
724 | return MSDLObserver::ESuspendNoSuspend; | ||
725 | break; | ||
726 | case MSDLObserver::EEventWindowReserved: | ||
727 | break; | ||
728 | case MSDLObserver::EEventWindowNotAvailable: | ||
729 | { | ||
730 | TRAP_IGNORE(HandleConsoleWindowL()); | ||
731 | } | ||
732 | break; | ||
733 | case MSDLObserver::EEventScreenSizeChanged: | ||
734 | break; | ||
735 | case MSDLObserver::EEventKeyMapInit: | ||
736 | break; | ||
737 | case MSDLObserver::EEventMainExit: | ||
738 | if(iStdOut != 0) | ||
739 | { | ||
740 | gSDLClass.AppFlags(SDLEnv::EAllowConsoleView); | ||
741 | iEikonEnv->WsSession().SetWindowGroupOrdinalPosition(iStdOut, 0); | ||
742 | } | ||
743 | break; | ||
744 | } | ||
745 | return MSDLObserver::EParameterNone; | ||
746 | } | ||
747 | |||
748 | void CSDLAppUi::HandleForegroundEventL(TBool aForeground) | ||
749 | { | ||
750 | CAknAppUi::HandleForegroundEventL(aForeground); | ||
751 | if(!aForeground) | ||
752 | HandleConsoleWindow(); | ||
753 | } | ||
754 | |||
755 | void CSDLAppUi::HandleConsoleWindow() | ||
756 | { | ||
757 | if(!iIdle->IsActive()) | ||
758 | iIdle->Start(TCallBack(IdleRequestL, this)); | ||
759 | } | ||
760 | |||
761 | TBool CSDLAppUi::IdleRequestL(TAny* aThis) | ||
762 | { | ||
763 | static_cast<CSDLAppUi*>(aThis)->HandleConsoleWindowL(); | ||
764 | return EFalse; | ||
765 | } | ||
766 | |||
767 | void CSDLAppUi::HandleConsoleWindowL() | ||
768 | { | ||
769 | if(gSDLClass.AppFlags() & SDLEnv::EAllowConsoleView) | ||
770 | { | ||
771 | return; | ||
772 | } | ||
773 | RWsSession& ses = iEikonEnv->WsSession(); | ||
774 | const TInt focus = ses.GetFocusWindowGroup(); | ||
775 | CApaWindowGroupName* name = CApaWindowGroupName::NewLC(ses, focus); | ||
776 | const TPtrC caption = name->Caption(); | ||
777 | if(0 == caption.CompareF(_L("STDOUT"))) | ||
778 | { | ||
779 | iStdOut = focus; | ||
780 | ses.SetWindowGroupOrdinalPosition(iEikonEnv->RootWin().Identifier(), 0); | ||
781 | } | ||
782 | CleanupStack::PopAndDestroy(); //name | ||
783 | } | ||
784 | |||
785 | |||
786 | //////////////////////////////////////////////////////////////////////// | ||
787 | |||
788 | |||
789 | CApaApplication* NewApplication() | ||
790 | { | ||
791 | return new CSDLApplication(); | ||
792 | } | ||
793 | |||
794 | |||
795 | EXPORT_C TInt SDLEnv::SetMain(const TMainFunc& aFunc, TInt aSdlFlags, MSDLMainObs* aObs, TInt aSdlExeFlags) | ||
796 | { | ||
797 | gSDLClass.SetMain(aFunc, aSdlFlags, aObs, aSdlExeFlags); | ||
798 | return EikStart::RunApplication(NewApplication); | ||
799 | } | ||
800 | |||
801 | ////////////////////////////////////////////////////////////////////// | ||
802 | |||
803 | TInt SDLUiPrint(const TDesC8& /*aInfo*/) | ||
804 | { | ||
805 | return KErrNotFound; | ||
806 | } | ||
807 | |||
808 | |||
809 | |||
diff --git a/apps/plugins/sdl/src/main/symbian/EKA2/sdllib.cpp b/apps/plugins/sdl/src/main/symbian/EKA2/sdllib.cpp new file mode 100644 index 0000000000..7c09996ec7 --- /dev/null +++ b/apps/plugins/sdl/src/main/symbian/EKA2/sdllib.cpp | |||
@@ -0,0 +1,12 @@ | |||
1 | #include<eikstart.h> | ||
2 | #include<sdlmain.h> | ||
3 | #include<sdlepocapi.h> | ||
4 | |||
5 | |||
6 | GLREF_C TInt E32Main() | ||
7 | { | ||
8 | return SDLEnv::SetMain(SDL_main, CSDL::EEnableFocusStop | CSDL::EAllowImageResize, | ||
9 | NULL, SDLEnv::EParamQuery | SDLEnv::EVirtualMouse); | ||
10 | } | ||
11 | |||
12 | \ No newline at end of file | ||
diff --git a/apps/plugins/sdl/src/main/symbian/EKA2/vectorbuffer.cpp b/apps/plugins/sdl/src/main/symbian/EKA2/vectorbuffer.cpp new file mode 100644 index 0000000000..72c3b3e5c0 --- /dev/null +++ b/apps/plugins/sdl/src/main/symbian/EKA2/vectorbuffer.cpp | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | vectorbuffer.cpp | ||
3 | yet another circle buffer | ||
4 | |||
5 | Markus Mertama | ||
6 | */ | ||
7 | |||
8 | #include"vectorbuffer.h" | ||
9 | |||
10 | |||
11 | |||
12 | void VectorPanic(TInt aErr, TInt aLine) | ||
13 | { | ||
14 | TBuf<64> b; | ||
15 | b.Format(_L("vector buffer at % d "), aLine); | ||
16 | User::Panic(b, aErr); | ||
17 | } | ||
18 | |||
19 | void TNodeBuffer::TNode::Terminator(TNodeBuffer::TNode* aNode) | ||
20 | { | ||
21 | Mem::Copy(iSucc, &aNode, sizeof(TNode*)); | ||
22 | } | ||
23 | |||
24 | TInt TNodeBuffer::TNode::Size() const | ||
25 | { | ||
26 | return reinterpret_cast<const TUint8*>(iSucc) - Ptr(); | ||
27 | } | ||
28 | |||
29 | const TUint8* TNodeBuffer::TNode::Ptr() const | ||
30 | { | ||
31 | return reinterpret_cast<const TUint8*>(this) + sizeof(TNode); | ||
32 | } | ||
33 | |||
34 | TNodeBuffer::TNode* TNodeBuffer::TNode::Empty(TUint8* aBuffer) | ||
35 | { | ||
36 | TNode* node = reinterpret_cast<TNode*>(aBuffer); | ||
37 | node->iSucc = node + 1; | ||
38 | return node; | ||
39 | } | ||
40 | |||
41 | TNodeBuffer::TNode* TNodeBuffer::TNode::New(TNode* aPred, const TDesC8& aData) | ||
42 | { | ||
43 | TNode* node = aPred->Size() == 0 ? aPred : aPred->iSucc; | ||
44 | |||
45 | |||
46 | TUint8* start = reinterpret_cast<TUint8*>(node) + sizeof(TNode); | ||
47 | node->iSucc = reinterpret_cast<TNode*>(start + aData.Size()); | ||
48 | node->iSucc->iSucc = NULL; //terminator | ||
49 | |||
50 | __ASSERT_DEBUG(node->Size() == aData.Size(), VECPANIC(KErrCorrupt)); | ||
51 | |||
52 | Mem::Copy(start, aData.Ptr(), aData.Size()); | ||
53 | return node; | ||
54 | } | ||
55 | |||
56 | |||
57 | |||
58 | |||
59 | |||
60 | |||
61 | |||
62 | \ No newline at end of file | ||
diff --git a/apps/plugins/sdl/src/main/symbian/EKA2/vectorbuffer.h b/apps/plugins/sdl/src/main/symbian/EKA2/vectorbuffer.h new file mode 100644 index 0000000000..3d8be58d6a --- /dev/null +++ b/apps/plugins/sdl/src/main/symbian/EKA2/vectorbuffer.h | |||
@@ -0,0 +1,240 @@ | |||
1 | /* | ||
2 | vectorbuffer.cpp | ||
3 | yet another circle buffer | ||
4 | |||
5 | Markus Mertama | ||
6 | */ | ||
7 | |||
8 | #ifndef __VECTORBUFFER_H__ | ||
9 | #define __VECTORBUFFER_H__ | ||
10 | |||
11 | #include<e32std.h> | ||
12 | #define VLOG(x) | ||
13 | #define VECPANIC(x) VectorPanic(x, __LINE__) | ||
14 | void VectorPanic(TInt, TInt); | ||
15 | |||
16 | |||
17 | //int DEBUG_INT; | ||
18 | |||
19 | NONSHARABLE_CLASS(TNodeBuffer) | ||
20 | { | ||
21 | public: | ||
22 | protected: | ||
23 | NONSHARABLE_CLASS(TNode) | ||
24 | { | ||
25 | public: | ||
26 | static TNode* Empty(TUint8* iBuffer); | ||
27 | static TNode* New(TNode* aPrev, const TDesC8& aData); | ||
28 | const TUint8* Ptr() const; | ||
29 | TInt Size() const; | ||
30 | inline TNode* Succ(); | ||
31 | static void SetSucc(TNode*& aNode); | ||
32 | void Terminator(TNode* aNode); | ||
33 | private: | ||
34 | TNode* iSucc; | ||
35 | }; | ||
36 | }; | ||
37 | |||
38 | inline TNodeBuffer::TNode* TNodeBuffer::TNode::Succ() | ||
39 | { | ||
40 | return iSucc; | ||
41 | } | ||
42 | |||
43 | template <TInt C> | ||
44 | NONSHARABLE_CLASS(TVectorBuffer) : public TNodeBuffer | ||
45 | { | ||
46 | public: | ||
47 | TVectorBuffer(); | ||
48 | TInt Append(const TDesC8& aData); | ||
49 | // TInt AppendOverwrite(const TDesC8& aData); | ||
50 | TPtrC8 Shift(); | ||
51 | TPtrC8 operator[](TInt aIndex) const; | ||
52 | TInt Size() const; | ||
53 | private: | ||
54 | TInt GetRoom(TInt aSize) const; | ||
55 | TInt Unreserved() const; | ||
56 | private: | ||
57 | TNode* iTop; | ||
58 | TNode* iBottom; | ||
59 | TInt iSize; | ||
60 | TUint8 iBuffer[C]; | ||
61 | }; | ||
62 | |||
63 | template <TInt C> | ||
64 | TVectorBuffer<C>::TVectorBuffer() : iSize(0) | ||
65 | { | ||
66 | Mem::FillZ(iBuffer, C); | ||
67 | iTop = TNode::Empty(iBuffer); //these points to buffer | ||
68 | iBottom = TNode::Empty(iBuffer); | ||
69 | } | ||
70 | |||
71 | template<TInt C > | ||
72 | TInt TVectorBuffer<C>::Unreserved() const | ||
73 | { | ||
74 | __ASSERT_DEBUG(iBottom < iBottom->Succ(), VECPANIC(KErrCorrupt)); | ||
75 | const TInt bytesbetween = | ||
76 | reinterpret_cast<const TUint8*>(iBottom->Succ()) - | ||
77 | reinterpret_cast<const TUint8*>(iTop); | ||
78 | const TInt topsize = sizeof(TNode); | ||
79 | if(bytesbetween > 0) //bytesbetween is room between bottom and top | ||
80 | { //therefore free room is subracted from free space | ||
81 | |||
82 | const TInt room = C - bytesbetween - topsize; | ||
83 | return room; | ||
84 | } | ||
85 | if(bytesbetween == 0) | ||
86 | { | ||
87 | |||
88 | if(Size() > 0) | ||
89 | return 0; | ||
90 | else | ||
91 | return C - topsize; | ||
92 | } | ||
93 | const TInt room = -bytesbetween - topsize; //free is space between pointers | ||
94 | return room; | ||
95 | } | ||
96 | |||
97 | template <TInt C> | ||
98 | TInt TVectorBuffer<C>::GetRoom(TInt aSize) const | ||
99 | { | ||
100 | const TInt bytesnew = sizeof(TNode) + aSize; | ||
101 | const TInt room = Unreserved() - bytesnew; | ||
102 | return room; | ||
103 | } | ||
104 | |||
105 | template <TInt C> | ||
106 | TInt TVectorBuffer<C>::Append(const TDesC8& aData) //ei ole ok! | ||
107 | { | ||
108 | const TInt len = aData.Length(); | ||
109 | if(GetRoom(len) < 0) | ||
110 | { | ||
111 | return KErrOverflow; | ||
112 | } | ||
113 | if(iBottom->Succ()->Ptr() - iBuffer > (C - (len + TInt(sizeof(TNode))))) | ||
114 | { | ||
115 | VLOG("rc"); | ||
116 | // RDebug::Print(_L("vector: append")); | ||
117 | TNode* p = TNode::Empty(iBuffer); | ||
118 | iBottom->Terminator(p); | ||
119 | iBottom = p; | ||
120 | return Append(aData); | ||
121 | // Append(); | ||
122 | // iBottom = TNode::New(p, aData); //just append something into end | ||
123 | } | ||
124 | |||
125 | //DEBUG_INT++; | ||
126 | |||
127 | iBottom = TNode::New(iBottom, aData); | ||
128 | |||
129 | iSize += len; | ||
130 | return KErrNone; | ||
131 | } | ||
132 | |||
133 | /* | ||
134 | template <TInt C> | ||
135 | TInt TVectorBuffer<C>::AppendOverwrite(const TDesC8& aData) //ei ole ok! | ||
136 | { | ||
137 | while(Append(aData) == KErrOverflow) | ||
138 | { | ||
139 | if(iTop->Succ() == NULL) | ||
140 | { | ||
141 | return KErrUnderflow; | ||
142 | } | ||
143 | //Shift(); //data is lost | ||
144 | } | ||
145 | return KErrNone; | ||
146 | } | ||
147 | */ | ||
148 | template <TInt C> | ||
149 | TPtrC8 TVectorBuffer<C>::Shift() | ||
150 | { | ||
151 | __ASSERT_ALWAYS(iTop->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom | ||
152 | TNode* node = iTop; | ||
153 | iTop = iTop->Succ(); | ||
154 | if(iTop > node) | ||
155 | { | ||
156 | // DEBUG_INT--; | ||
157 | iSize -= node->Size(); | ||
158 | return TPtrC8(node->Ptr(), node->Size()); | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | // RDebug::Print(_L("vector: shift")); | ||
163 | return Shift(); //this happens when buffer is terminated, and data lies in next | ||
164 | } | ||
165 | } | ||
166 | |||
167 | template <TInt C> | ||
168 | TInt TVectorBuffer<C>::Size() const | ||
169 | { | ||
170 | return iSize; | ||
171 | } | ||
172 | |||
173 | template <TInt C> | ||
174 | TPtrC8 TVectorBuffer<C>::operator[](TInt aIndex) const | ||
175 | { | ||
176 | TInt index = 0; | ||
177 | TNode* t = iTop->Size() > 0 ? iTop : iTop->Succ(); //eliminate terminator | ||
178 | while(index < aIndex) | ||
179 | { | ||
180 | TNode* nt = t->Succ(); | ||
181 | if(nt < t) | ||
182 | { | ||
183 | nt = nt->Succ(); | ||
184 | } | ||
185 | t = nt; | ||
186 | if(t->Size() > 0) | ||
187 | index++; | ||
188 | __ASSERT_ALWAYS(t->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom | ||
189 | } | ||
190 | return t->Ptr(); | ||
191 | } | ||
192 | |||
193 | |||
194 | template <class T, TInt C> | ||
195 | NONSHARABLE_CLASS(TVector) : public TVectorBuffer<C * sizeof(T)> | ||
196 | { | ||
197 | public: | ||
198 | TVector(); | ||
199 | TInt Append(const T& aData); | ||
200 | const T& Shift(); | ||
201 | TInt Size() const; | ||
202 | const T& operator[](TInt aIndex) const; | ||
203 | }; | ||
204 | |||
205 | template <class T, TInt C> | ||
206 | TVector<T, C>::TVector() : TVectorBuffer<C * sizeof(T)>() | ||
207 | { | ||
208 | } | ||
209 | |||
210 | template <class T, TInt C> | ||
211 | TInt TVector<T, C>::Append(const T& aData) | ||
212 | { | ||
213 | const TPckgC<T> data(aData); | ||
214 | return TVectorBuffer<C * sizeof(T)>::Append(data); | ||
215 | } | ||
216 | |||
217 | template <class T, TInt C> | ||
218 | const T& TVector<T, C>::Shift() | ||
219 | { | ||
220 | const TPtrC8 ptr = TVectorBuffer<C * sizeof(T)>::Shift(); | ||
221 | return *(reinterpret_cast<const T*>(ptr.Ptr())); | ||
222 | } | ||
223 | |||
224 | |||
225 | template <class T, TInt C> | ||
226 | TInt TVector<T, C>::Size() const | ||
227 | { | ||
228 | return TVectorBuffer<C * sizeof(T)>::Size() / sizeof(T); | ||
229 | } | ||
230 | |||
231 | template <class T, TInt C> | ||
232 | const T& TVector<T, C>::operator[](TInt aIndex) const | ||
233 | { | ||
234 | const TPtrC8 ptr = TVectorBuffer<C * sizeof(T)>::operator[](aIndex); | ||
235 | return *(reinterpret_cast<const T*>(ptr.Ptr())); | ||
236 | } | ||
237 | |||
238 | #endif | ||
239 | |||
240 | |||