diff options
author | Franklin Wei <git@fwei.tk> | 2017-01-21 15:18:31 -0500 |
---|---|---|
committer | Franklin Wei <git@fwei.tk> | 2017-12-23 21:01:26 -0500 |
commit | a855d6202536ff28e5aae4f22a0f31d8f5b325d0 (patch) | |
tree | 8c75f224dd64ed360505afa8843d016b0d75000b /apps/plugins/sdl/src/main | |
parent | 01c6dcf6c7b9bb1ad2fa0450f99bacc5f3d3e04b (diff) | |
download | rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.tar.gz rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.zip |
Port of Duke Nukem 3D
This ports Fabien Sanglard's Chocolate Duke to run on a version of SDL
for Rockbox.
Change-Id: I8f2c4c78af19de10c1633ed7bb7a997b43256dd9
Diffstat (limited to 'apps/plugins/sdl/src/main')
26 files changed, 4096 insertions, 0 deletions
diff --git a/apps/plugins/sdl/src/main/beos/SDL_BeApp.cc b/apps/plugins/sdl/src/main/beos/SDL_BeApp.cc new file mode 100644 index 0000000000..8b793779ac --- /dev/null +++ b/apps/plugins/sdl/src/main/beos/SDL_BeApp.cc | |||
@@ -0,0 +1,111 @@ | |||
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 Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 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 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* Handle the BeApp specific portions of the application */ | ||
25 | |||
26 | #include <AppKit.h> | ||
27 | #include <storage/Path.h> | ||
28 | #include <storage/Entry.h> | ||
29 | #include <unistd.h> | ||
30 | |||
31 | #include "SDL_BeApp.h" | ||
32 | #include "SDL_thread.h" | ||
33 | #include "SDL_timer.h" | ||
34 | #include "SDL_error.h" | ||
35 | |||
36 | /* Flag to tell whether or not the Be application is active or not */ | ||
37 | int SDL_BeAppActive = 0; | ||
38 | static SDL_Thread *SDL_AppThread = NULL; | ||
39 | |||
40 | static int StartBeApp(void *unused) | ||
41 | { | ||
42 | if(!be_app) { | ||
43 | BApplication *App; | ||
44 | |||
45 | App = new BApplication("application/x-SDL-executable"); | ||
46 | |||
47 | App->Run(); | ||
48 | delete App; | ||
49 | } | ||
50 | return(0); | ||
51 | } | ||
52 | |||
53 | /* Initialize the Be Application, if it's not already started */ | ||
54 | int SDL_InitBeApp(void) | ||
55 | { | ||
56 | /* Create the BApplication that handles appserver interaction */ | ||
57 | if ( SDL_BeAppActive <= 0 ) { | ||
58 | SDL_AppThread = SDL_CreateThread(StartBeApp, NULL); | ||
59 | if ( SDL_AppThread == NULL ) { | ||
60 | SDL_SetError("Couldn't create BApplication thread"); | ||
61 | return(-1); | ||
62 | } | ||
63 | |||
64 | /* Change working to directory to that of executable */ | ||
65 | app_info info; | ||
66 | if (B_OK == be_app->GetAppInfo(&info)) { | ||
67 | entry_ref ref = info.ref; | ||
68 | BEntry entry; | ||
69 | if (B_OK == entry.SetTo(&ref)) { | ||
70 | BPath path; | ||
71 | if (B_OK == path.SetTo(&entry)) { | ||
72 | if (B_OK == path.GetParent(&path)) { | ||
73 | chdir(path.Path()); | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | |||
79 | do { | ||
80 | SDL_Delay(10); | ||
81 | } while ( (be_app == NULL) || be_app->IsLaunching() ); | ||
82 | |||
83 | /* Mark the application active */ | ||
84 | SDL_BeAppActive = 0; | ||
85 | } | ||
86 | |||
87 | /* Increment the application reference count */ | ||
88 | ++SDL_BeAppActive; | ||
89 | |||
90 | /* The app is running, and we're ready to go */ | ||
91 | return(0); | ||
92 | } | ||
93 | |||
94 | /* Quit the Be Application, if there's nothing left to do */ | ||
95 | void SDL_QuitBeApp(void) | ||
96 | { | ||
97 | /* Decrement the application reference count */ | ||
98 | --SDL_BeAppActive; | ||
99 | |||
100 | /* If the reference count reached zero, clean up the app */ | ||
101 | if ( SDL_BeAppActive == 0 ) { | ||
102 | if ( SDL_AppThread != NULL ) { | ||
103 | if ( be_app != NULL ) { /* Not tested */ | ||
104 | be_app->PostMessage(B_QUIT_REQUESTED); | ||
105 | } | ||
106 | SDL_WaitThread(SDL_AppThread, NULL); | ||
107 | SDL_AppThread = NULL; | ||
108 | } | ||
109 | /* be_app should now be NULL since be_app has quit */ | ||
110 | } | ||
111 | } | ||
diff --git a/apps/plugins/sdl/src/main/beos/SDL_BeApp.h b/apps/plugins/sdl/src/main/beos/SDL_BeApp.h new file mode 100644 index 0000000000..9f88212438 --- /dev/null +++ b/apps/plugins/sdl/src/main/beos/SDL_BeApp.h | |||
@@ -0,0 +1,33 @@ | |||
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 Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 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 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* Handle the BeApp specific portions of the application */ | ||
25 | |||
26 | /* Initialize the Be Application, if it's not already started */ | ||
27 | extern int SDL_InitBeApp(void); | ||
28 | |||
29 | /* Quit the Be Application, if there's nothing left to do */ | ||
30 | extern void SDL_QuitBeApp(void); | ||
31 | |||
32 | /* Flag to tell whether the app is active or not */ | ||
33 | extern int SDL_BeAppActive; | ||
diff --git a/apps/plugins/sdl/src/main/dummy/SDL_dummy_main.c b/apps/plugins/sdl/src/main/dummy/SDL_dummy_main.c new file mode 100644 index 0000000000..da47d06a87 --- /dev/null +++ b/apps/plugins/sdl/src/main/dummy/SDL_dummy_main.c | |||
@@ -0,0 +1,13 @@ | |||
1 | |||
2 | /* Include the SDL main definition header */ | ||
3 | #include "SDL_main.h" | ||
4 | |||
5 | #ifdef main | ||
6 | #undef main | ||
7 | int main(int argc, char *argv[]) | ||
8 | { | ||
9 | return(SDL_main(argc, argv)); | ||
10 | } | ||
11 | #else | ||
12 | /* Nothing to do on this platform */ | ||
13 | #endif | ||
diff --git a/apps/plugins/sdl/src/main/macos/SDL.r b/apps/plugins/sdl/src/main/macos/SDL.r new file mode 100644 index 0000000000..438f6872ef --- /dev/null +++ b/apps/plugins/sdl/src/main/macos/SDL.r | |||
@@ -0,0 +1 @@ | |||
data 'DLOG' (1000) { $"0072 0040 00EA 01B3 0001 0100 0000 0000 0000 03E8 0C43 6F6D 6D61 6E64 204C 696E" /* .r.@..............Command Lin */ $"6500 280A" /* e.( */ }; data 'DLOG' (1001) { $"0072 0040 00DB 01AC 0001 0100 0000 0000 0000 03E9 0C45 7272 6F72 2057 696E 646F" /* .r.@..............Error Windo */ $"7700 280A" /* w.( */ }; data 'DLOG' (1002) { $"00B8 00BE 0147 01D8 0005 0100 0000 0000 0000 03EA 1643 6F6E 6669 726D 2044 6973" /* ...G.............Confirm Dis */ $"706C 6179 2043 6861 6E67 6510 280A" /* play Change.( */ }; data 'DITL' (1000) { $"0005 0000 0000 0052 0113 0066 0158 0402 4F4B 0000 0000 0052 00C2 0066 0107 0406" /* .......R...f.X..OK.....R..f.... */ $"4361 6E63 656C 0000 0000 000F 0084 001F 0155 1000 0000 0000 0054 0019 0066 007D" /* Cancel..........U.......T...f.} */ $"050E 4F75 7470 7574 2074 6F20 6669 6C65 0000 0000 000F 0018 001F 007F 080D 436F" /* ..Output to file..............Co */ $"6D6D 616E 6420 4C69 6E65 3A00 0000 0000 0030 0018 0040 0158 0702 0080" /* mmand Line:......0...@.X... */ }; data 'DITL' (1001) { $"0001 0000 0000 0046 0120 005A 015A 0402 4F4B 0000 0000 0010 000A 0038 0160 0800" /* .......F. .Z.Z..OK........8.`.. */ }; data 'DITL' (1002) { $"0002 0000 0000 006F 001E 0083 0058 0406 4361 6E63 656C 0000 0000 006E 00C0 0082" /* .......o....X..Cancel.....n.. */ $"00FA 0402 4F4B 0000 0000 000E 000F 005F 010C 88B3 5468 6520 7365 7474 696E 6720" /* ...OK........._..The setting */ $"666F 7220 796F 7572 206D 6F6E 6974 6F72 2068 6173 2062 6565 6E20 6368 616E 6765" /* for your monitor has been change */ $"642C 2061 6E64 2069 7420 6D61 7920 6E6F 7420 6265 2064 6973 706C 6179 6564 2063" /* d, and it may not be displayed c */ $"6F72 7265 6374 6C79 2E20 546F 2063 6F6E 6669 726D 2074 6865 2064 6973 706C 6179" /* orrectly. To confirm the display */ $"2069 7320 636F 7272 6563 742C 2063 6C69 636B 204F 4B2E 2054 6F20 7265 7475 726E" /* is correct, click OK. To return */ $"2074 6F20 7468 6520 6F72 6967 696E 616C 2073 6574 7469 6E67 2C20 636C 6963 6B20" /* to the original setting, click */ $"4361 6E63 656C 2E00" /* Cancel.. */ }; data 'MENU' (128, preload) { $"0080 0000 0000 0000 0000 FFFF FFFB 0114 0C41 626F 7574 2053 444C 2E2E 2E00 0000" /* ............About SDL...... */ $"0001 2D00 0000 0000" /* ..-..... */ }; data 'MENU' (129) { $"0081 0000 0000 0000 0000 FFFF FFFF 0C56 6964 656F 2044 7269 7665 7219 4472 6177" /* ..........Video Driver.Draw */ $"5370 726F 636B 6574 2028 4675 6C6C 7363 7265 656E 2900 0000 001E 546F 6F6C 426F" /* Sprocket (Fullscreen).....ToolBo */ $"7820 2028 4675 6C6C 7363 7265 656E 2F57 696E 646F 7765 6429 0000 0000 00" /* x (Fullscreen/Windowed)..... */ }; data 'CNTL' (128) { $"0000 0000 0010 0140 0000 0100 0064 0081 03F0 0000 0000 0D56 6964 656F 2044 7269" /* .......@.....d.......Video Dri */ $"7665 723A" /* ver: */ }; data 'TMPL' (128, "CLne") { $"0C43 6F6D 6D61 6E64 204C 696E 6550 5354 520C 5669 6465 6F20 4472 6976 6572 5053" /* .Command LinePSTR.Video DriverPS */ $"5452 0C53 6176 6520 546F 2046 696C 6542 4F4F 4C" /* TR.Save To FileBOOL */ }; \ No newline at end of file | |||
diff --git a/apps/plugins/sdl/src/main/macos/SDL.shlib.r b/apps/plugins/sdl/src/main/macos/SDL.shlib.r new file mode 100644 index 0000000000..313c79485a --- /dev/null +++ b/apps/plugins/sdl/src/main/macos/SDL.shlib.r | |||
@@ -0,0 +1 @@ | |||
#ifndef __TYPES_R__ #include "Types.r" #endif #ifndef __BALLOONS_R__ #include "Balloons.r" #endif #define VERSION_MAJOR 1 #define VERSION_MINOR 2 #define REVISION 13 #define STATE release /* development | alpha | beta | release */ #define RELEASE_NO 0 /* number after letter, or zero for release */ #define COUNTRY verUS #define VERSION_STRING "1.2.13" #define NAME "SDL" #define SHORT_DESCRIPTION "Simple DirectMedia Layer by Sam Lantinga" #define LONG_DESCRIPTION "A cross-platform multimedia library.\n\nhttp://www.libsdl.org" resource 'vers' (1) { VERSION_MAJOR, (VERSION_MINOR << 4) | REVISION, STATE, RELEASE_NO, COUNTRY, VERSION_STRING, VERSION_STRING }; resource 'vers' (2) { VERSION_MAJOR, (VERSION_MINOR << 4) | REVISION, STATE, RELEASE_NO, COUNTRY, VERSION_STRING, SHORT_DESCRIPTION }; /* Extension Manager info */ data 'CCI' (128) { NAME "\n\n" LONG_DESCRIPTION }; /* Finder help balloon */ resource 'hfdr' (kHMHelpID) { HelpMgrVersion, hmDefaultOptions, 0, 0, { HMStringItem { NAME "\n\n" LONG_DESCRIPTION } } }; \ No newline at end of file | |||
diff --git a/apps/plugins/sdl/src/main/macos/SDL_main.c b/apps/plugins/sdl/src/main/macos/SDL_main.c new file mode 100644 index 0000000000..ff1ffdca0d --- /dev/null +++ b/apps/plugins/sdl/src/main/macos/SDL_main.c | |||
@@ -0,0 +1,610 @@ | |||
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 Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 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 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | |||
23 | /* This file takes care of command line argument parsing, and stdio redirection | ||
24 | in the MacOS environment. (stdio/stderr is *not* directed for Mach-O builds) | ||
25 | */ | ||
26 | |||
27 | #if defined(__APPLE__) && defined(__MACH__) | ||
28 | #include <Carbon/Carbon.h> | ||
29 | #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) | ||
30 | #include <Carbon.h> | ||
31 | #else | ||
32 | #include <Dialogs.h> | ||
33 | #include <Fonts.h> | ||
34 | #include <Events.h> | ||
35 | #include <Resources.h> | ||
36 | #include <Folders.h> | ||
37 | #endif | ||
38 | |||
39 | /* Include the SDL main definition header */ | ||
40 | #include "SDL.h" | ||
41 | #include "SDL_main.h" | ||
42 | #ifdef main | ||
43 | #undef main | ||
44 | #endif | ||
45 | |||
46 | #if !(defined(__APPLE__) && defined(__MACH__)) | ||
47 | /* The standard output files */ | ||
48 | #define STDOUT_FILE "stdout.txt" | ||
49 | #define STDERR_FILE "stderr.txt" | ||
50 | #endif | ||
51 | |||
52 | #if !defined(__MWERKS__) && !TARGET_API_MAC_CARBON | ||
53 | /* In MPW, the qd global has been removed from the libraries */ | ||
54 | QDGlobals qd; | ||
55 | #endif | ||
56 | |||
57 | /* Structure for keeping prefs in 1 variable */ | ||
58 | typedef struct { | ||
59 | Str255 command_line; | ||
60 | Str255 video_driver_name; | ||
61 | Boolean output_to_file; | ||
62 | } PrefsRecord; | ||
63 | |||
64 | /* See if the command key is held down at startup */ | ||
65 | static Boolean CommandKeyIsDown(void) | ||
66 | { | ||
67 | KeyMap theKeyMap; | ||
68 | |||
69 | GetKeys(theKeyMap); | ||
70 | |||
71 | if (((unsigned char *) theKeyMap)[6] & 0x80) { | ||
72 | return(true); | ||
73 | } | ||
74 | return(false); | ||
75 | } | ||
76 | |||
77 | #if !(defined(__APPLE__) && defined(__MACH__)) | ||
78 | |||
79 | /* Parse a command line buffer into arguments */ | ||
80 | static int ParseCommandLine(char *cmdline, char **argv) | ||
81 | { | ||
82 | char *bufp; | ||
83 | int argc; | ||
84 | |||
85 | argc = 0; | ||
86 | for ( bufp = cmdline; *bufp; ) { | ||
87 | /* Skip leading whitespace */ | ||
88 | while ( SDL_isspace(*bufp) ) { | ||
89 | ++bufp; | ||
90 | } | ||
91 | /* Skip over argument */ | ||
92 | if ( *bufp == '"' ) { | ||
93 | ++bufp; | ||
94 | if ( *bufp ) { | ||
95 | if ( argv ) { | ||
96 | argv[argc] = bufp; | ||
97 | } | ||
98 | ++argc; | ||
99 | } | ||
100 | /* Skip over word */ | ||
101 | while ( *bufp && (*bufp != '"') ) { | ||
102 | ++bufp; | ||
103 | } | ||
104 | } else { | ||
105 | if ( *bufp ) { | ||
106 | if ( argv ) { | ||
107 | argv[argc] = bufp; | ||
108 | } | ||
109 | ++argc; | ||
110 | } | ||
111 | /* Skip over word */ | ||
112 | while ( *bufp && ! SDL_isspace(*bufp) ) { | ||
113 | ++bufp; | ||
114 | } | ||
115 | } | ||
116 | if ( *bufp ) { | ||
117 | if ( argv ) { | ||
118 | *bufp = '\0'; | ||
119 | } | ||
120 | ++bufp; | ||
121 | } | ||
122 | } | ||
123 | if ( argv ) { | ||
124 | argv[argc] = NULL; | ||
125 | } | ||
126 | return(argc); | ||
127 | } | ||
128 | |||
129 | /* Remove the output files if there was no output written */ | ||
130 | static void cleanup_output(void) | ||
131 | { | ||
132 | FILE *file; | ||
133 | int empty; | ||
134 | |||
135 | /* Flush the output in case anything is queued */ | ||
136 | fclose(stdout); | ||
137 | fclose(stderr); | ||
138 | |||
139 | /* See if the files have any output in them */ | ||
140 | file = fopen(STDOUT_FILE, "rb"); | ||
141 | if ( file ) { | ||
142 | empty = (fgetc(file) == EOF) ? 1 : 0; | ||
143 | fclose(file); | ||
144 | if ( empty ) { | ||
145 | remove(STDOUT_FILE); | ||
146 | } | ||
147 | } | ||
148 | file = fopen(STDERR_FILE, "rb"); | ||
149 | if ( file ) { | ||
150 | empty = (fgetc(file) == EOF) ? 1 : 0; | ||
151 | fclose(file); | ||
152 | if ( empty ) { | ||
153 | remove(STDERR_FILE); | ||
154 | } | ||
155 | } | ||
156 | } | ||
157 | |||
158 | #endif //!(defined(__APPLE__) && defined(__MACH__)) | ||
159 | |||
160 | static int getCurrentAppName (StrFileName name) { | ||
161 | |||
162 | ProcessSerialNumber process; | ||
163 | ProcessInfoRec process_info; | ||
164 | FSSpec process_fsp; | ||
165 | |||
166 | process.highLongOfPSN = 0; | ||
167 | process.lowLongOfPSN = kCurrentProcess; | ||
168 | process_info.processInfoLength = sizeof (process_info); | ||
169 | process_info.processName = NULL; | ||
170 | process_info.processAppSpec = &process_fsp; | ||
171 | |||
172 | if ( noErr != GetProcessInformation (&process, &process_info) ) | ||
173 | return 0; | ||
174 | |||
175 | SDL_memcpy(name, process_fsp.name, process_fsp.name[0] + 1); | ||
176 | return 1; | ||
177 | } | ||
178 | |||
179 | static int getPrefsFile (FSSpec *prefs_fsp, int create) { | ||
180 | |||
181 | /* The prefs file name is the application name, possibly truncated, */ | ||
182 | /* plus " Preferences */ | ||
183 | |||
184 | #define SUFFIX " Preferences" | ||
185 | #define MAX_NAME 19 /* 31 - strlen (SUFFIX) */ | ||
186 | |||
187 | short volume_ref_number; | ||
188 | long directory_id; | ||
189 | StrFileName prefs_name; | ||
190 | StrFileName app_name; | ||
191 | |||
192 | /* Get Preferences folder - works with Multiple Users */ | ||
193 | if ( noErr != FindFolder ( kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, | ||
194 | &volume_ref_number, &directory_id) ) | ||
195 | exit (-1); | ||
196 | |||
197 | if ( ! getCurrentAppName (app_name) ) | ||
198 | exit (-1); | ||
199 | |||
200 | /* Truncate if name is too long */ | ||
201 | if (app_name[0] > MAX_NAME ) | ||
202 | app_name[0] = MAX_NAME; | ||
203 | |||
204 | SDL_memcpy(prefs_name + 1, app_name + 1, app_name[0]); | ||
205 | SDL_memcpy(prefs_name + app_name[0] + 1, SUFFIX, strlen (SUFFIX)); | ||
206 | prefs_name[0] = app_name[0] + strlen (SUFFIX); | ||
207 | |||
208 | /* Make the file spec for prefs file */ | ||
209 | if ( noErr != FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp) ) { | ||
210 | if ( !create ) | ||
211 | return 0; | ||
212 | else { | ||
213 | /* Create the prefs file */ | ||
214 | SDL_memcpy(prefs_fsp->name, prefs_name, prefs_name[0] + 1); | ||
215 | prefs_fsp->parID = directory_id; | ||
216 | prefs_fsp->vRefNum = volume_ref_number; | ||
217 | |||
218 | FSpCreateResFile (prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph | ||
219 | |||
220 | if ( noErr != ResError () ) | ||
221 | return 0; | ||
222 | } | ||
223 | } | ||
224 | return 1; | ||
225 | } | ||
226 | |||
227 | static int readPrefsResource (PrefsRecord *prefs) { | ||
228 | |||
229 | Handle prefs_handle; | ||
230 | |||
231 | prefs_handle = Get1Resource( 'CLne', 128 ); | ||
232 | |||
233 | if (prefs_handle != NULL) { | ||
234 | int offset = 0; | ||
235 | // int j = 0; | ||
236 | |||
237 | HLock(prefs_handle); | ||
238 | |||
239 | /* Get command line string */ | ||
240 | SDL_memcpy(prefs->command_line, *prefs_handle, (*prefs_handle)[0]+1); | ||
241 | |||
242 | /* Get video driver name */ | ||
243 | offset += (*prefs_handle)[0] + 1; | ||
244 | SDL_memcpy(prefs->video_driver_name, *prefs_handle + offset, (*prefs_handle)[offset] + 1); | ||
245 | |||
246 | /* Get save-to-file option (1 or 0) */ | ||
247 | offset += (*prefs_handle)[offset] + 1; | ||
248 | prefs->output_to_file = (*prefs_handle)[offset]; | ||
249 | |||
250 | ReleaseResource( prefs_handle ); | ||
251 | |||
252 | return ResError() == noErr; | ||
253 | } | ||
254 | |||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | static int writePrefsResource (PrefsRecord *prefs, short resource_file) { | ||
259 | |||
260 | Handle prefs_handle; | ||
261 | |||
262 | UseResFile (resource_file); | ||
263 | |||
264 | prefs_handle = Get1Resource ( 'CLne', 128 ); | ||
265 | if (prefs_handle != NULL) | ||
266 | RemoveResource (prefs_handle); | ||
267 | |||
268 | prefs_handle = NewHandle ( prefs->command_line[0] + prefs->video_driver_name[0] + 4 ); | ||
269 | if (prefs_handle != NULL) { | ||
270 | |||
271 | int offset; | ||
272 | |||
273 | HLock (prefs_handle); | ||
274 | |||
275 | /* Command line text */ | ||
276 | offset = 0; | ||
277 | SDL_memcpy(*prefs_handle, prefs->command_line, prefs->command_line[0] + 1); | ||
278 | |||
279 | /* Video driver name */ | ||
280 | offset += prefs->command_line[0] + 1; | ||
281 | SDL_memcpy(*prefs_handle + offset, prefs->video_driver_name, prefs->video_driver_name[0] + 1); | ||
282 | |||
283 | /* Output-to-file option */ | ||
284 | offset += prefs->video_driver_name[0] + 1; | ||
285 | *( *((char**)prefs_handle) + offset) = (char)prefs->output_to_file; | ||
286 | *( *((char**)prefs_handle) + offset + 1) = 0; | ||
287 | |||
288 | AddResource (prefs_handle, 'CLne', 128, "\pCommand Line"); | ||
289 | WriteResource (prefs_handle); | ||
290 | UpdateResFile (resource_file); | ||
291 | DisposeHandle (prefs_handle); | ||
292 | |||
293 | return ResError() == noErr; | ||
294 | } | ||
295 | |||
296 | return 0; | ||
297 | } | ||
298 | |||
299 | static int readPreferences (PrefsRecord *prefs) { | ||
300 | |||
301 | int no_error = 1; | ||
302 | FSSpec prefs_fsp; | ||
303 | |||
304 | /* Check for prefs file first */ | ||
305 | if ( getPrefsFile (&prefs_fsp, 0) ) { | ||
306 | |||
307 | short prefs_resource; | ||
308 | |||
309 | prefs_resource = FSpOpenResFile (&prefs_fsp, fsRdPerm); | ||
310 | if ( prefs_resource == -1 ) /* this shouldn't happen, but... */ | ||
311 | return 0; | ||
312 | |||
313 | UseResFile (prefs_resource); | ||
314 | no_error = readPrefsResource (prefs); | ||
315 | CloseResFile (prefs_resource); | ||
316 | } | ||
317 | |||
318 | /* Fall back to application's resource fork (reading only, so this is safe) */ | ||
319 | else { | ||
320 | |||
321 | no_error = readPrefsResource (prefs); | ||
322 | } | ||
323 | |||
324 | return no_error; | ||
325 | } | ||
326 | |||
327 | static int writePreferences (PrefsRecord *prefs) { | ||
328 | |||
329 | int no_error = 1; | ||
330 | FSSpec prefs_fsp; | ||
331 | |||
332 | /* Get prefs file, create if it doesn't exist */ | ||
333 | if ( getPrefsFile (&prefs_fsp, 1) ) { | ||
334 | |||
335 | short prefs_resource; | ||
336 | |||
337 | prefs_resource = FSpOpenResFile (&prefs_fsp, fsRdWrPerm); | ||
338 | if (prefs_resource == -1) | ||
339 | return 0; | ||
340 | no_error = writePrefsResource (prefs, prefs_resource); | ||
341 | CloseResFile (prefs_resource); | ||
342 | } | ||
343 | |||
344 | return no_error; | ||
345 | } | ||
346 | |||
347 | /* This is where execution begins */ | ||
348 | int main(int argc, char *argv[]) | ||
349 | { | ||
350 | |||
351 | #if !(defined(__APPLE__) && defined(__MACH__)) | ||
352 | #pragma unused(argc, argv) | ||
353 | #endif | ||
354 | |||
355 | #define DEFAULT_ARGS "\p" /* pascal string for default args */ | ||
356 | #define DEFAULT_VIDEO_DRIVER "\ptoolbox" /* pascal string for default video driver name */ | ||
357 | #define DEFAULT_OUTPUT_TO_FILE 1 /* 1 == output to file, 0 == no output */ | ||
358 | |||
359 | #define VIDEO_ID_DRAWSPROCKET 1 /* these correspond to popup menu choices */ | ||
360 | #define VIDEO_ID_TOOLBOX 2 | ||
361 | |||
362 | PrefsRecord prefs = { DEFAULT_ARGS, DEFAULT_VIDEO_DRIVER, DEFAULT_OUTPUT_TO_FILE }; | ||
363 | |||
364 | #if !(defined(__APPLE__) && defined(__MACH__)) | ||
365 | int nargs; | ||
366 | char **args; | ||
367 | char *commandLine; | ||
368 | |||
369 | StrFileName appNameText; | ||
370 | #endif | ||
371 | int videodriver = VIDEO_ID_TOOLBOX; | ||
372 | int settingsChanged = 0; | ||
373 | |||
374 | long i; | ||
375 | |||
376 | /* Kyle's SDL command-line dialog code ... */ | ||
377 | #if !TARGET_API_MAC_CARBON | ||
378 | InitGraf (&qd.thePort); | ||
379 | InitFonts (); | ||
380 | InitWindows (); | ||
381 | InitMenus (); | ||
382 | InitDialogs (nil); | ||
383 | #endif | ||
384 | InitCursor (); | ||
385 | FlushEvents(everyEvent,0); | ||
386 | #if !TARGET_API_MAC_CARBON | ||
387 | MaxApplZone (); | ||
388 | #endif | ||
389 | MoreMasters (); | ||
390 | MoreMasters (); | ||
391 | #if 0 | ||
392 | /* Intialize SDL, and put up a dialog if we fail */ | ||
393 | if ( SDL_Init (0) < 0 ) { | ||
394 | |||
395 | #define kErr_OK 1 | ||
396 | #define kErr_Text 2 | ||
397 | |||
398 | DialogPtr errorDialog; | ||
399 | short dummyType; | ||
400 | Rect dummyRect; | ||
401 | Handle dummyHandle; | ||
402 | short itemHit; | ||
403 | |||
404 | errorDialog = GetNewDialog (1001, nil, (WindowPtr)-1); | ||
405 | if (errorDialog == NULL) | ||
406 | return -1; | ||
407 | DrawDialog (errorDialog); | ||
408 | |||
409 | GetDialogItem (errorDialog, kErr_Text, &dummyType, &dummyHandle, &dummyRect); | ||
410 | SetDialogItemText (dummyHandle, "\pError Initializing SDL"); | ||
411 | |||
412 | #if TARGET_API_MAC_CARBON | ||
413 | SetPort (GetDialogPort(errorDialog)); | ||
414 | #else | ||
415 | SetPort (errorDialog); | ||
416 | #endif | ||
417 | do { | ||
418 | ModalDialog (nil, &itemHit); | ||
419 | } while (itemHit != kErr_OK); | ||
420 | |||
421 | DisposeDialog (errorDialog); | ||
422 | exit (-1); | ||
423 | } | ||
424 | atexit(cleanup_output); | ||
425 | atexit(SDL_Quit); | ||
426 | #endif | ||
427 | |||
428 | /* Set up SDL's QuickDraw environment */ | ||
429 | #if !TARGET_API_MAC_CARBON | ||
430 | SDL_InitQuickDraw(&qd); | ||
431 | #endif | ||
432 | |||
433 | if ( readPreferences (&prefs) ) { | ||
434 | |||
435 | if (SDL_memcmp(prefs.video_driver_name+1, "DSp", 3) == 0) | ||
436 | videodriver = 1; | ||
437 | else if (SDL_memcmp(prefs.video_driver_name+1, "toolbox", 7) == 0) | ||
438 | videodriver = 2; | ||
439 | } | ||
440 | |||
441 | if ( CommandKeyIsDown() ) { | ||
442 | |||
443 | #define kCL_OK 1 | ||
444 | #define kCL_Cancel 2 | ||
445 | #define kCL_Text 3 | ||
446 | #define kCL_File 4 | ||
447 | #define kCL_Video 6 | ||
448 | |||
449 | DialogPtr commandDialog; | ||
450 | short dummyType; | ||
451 | Rect dummyRect; | ||
452 | Handle dummyHandle; | ||
453 | short itemHit; | ||
454 | #if TARGET_API_MAC_CARBON | ||
455 | ControlRef control; | ||
456 | #endif | ||
457 | |||
458 | /* Assume that they will change settings, rather than do exhaustive check */ | ||
459 | settingsChanged = 1; | ||
460 | |||
461 | /* Create dialog and display it */ | ||
462 | commandDialog = GetNewDialog (1000, nil, (WindowPtr)-1); | ||
463 | #if TARGET_API_MAC_CARBON | ||
464 | SetPort ( GetDialogPort(commandDialog) ); | ||
465 | #else | ||
466 | SetPort (commandDialog); | ||
467 | #endif | ||
468 | |||
469 | /* Setup controls */ | ||
470 | #if TARGET_API_MAC_CARBON | ||
471 | GetDialogItemAsControl(commandDialog, kCL_File, &control); | ||
472 | SetControlValue (control, prefs.output_to_file); | ||
473 | #else | ||
474 | GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ | ||
475 | SetControlValue ((ControlHandle)dummyHandle, prefs.output_to_file ); | ||
476 | #endif | ||
477 | |||
478 | GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); | ||
479 | SetDialogItemText (dummyHandle, prefs.command_line); | ||
480 | |||
481 | #if TARGET_API_MAC_CARBON | ||
482 | GetDialogItemAsControl(commandDialog, kCL_Video, &control); | ||
483 | SetControlValue (control, videodriver); | ||
484 | #else | ||
485 | GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); | ||
486 | SetControlValue ((ControlRef)dummyHandle, videodriver); | ||
487 | #endif | ||
488 | |||
489 | SetDialogDefaultItem (commandDialog, kCL_OK); | ||
490 | SetDialogCancelItem (commandDialog, kCL_Cancel); | ||
491 | |||
492 | do { | ||
493 | |||
494 | ModalDialog(nil, &itemHit); /* wait for user response */ | ||
495 | |||
496 | /* Toggle command-line output checkbox */ | ||
497 | if ( itemHit == kCL_File ) { | ||
498 | #if TARGET_API_MAC_CARBON | ||
499 | GetDialogItemAsControl(commandDialog, kCL_File, &control); | ||
500 | SetControlValue (control, !GetControlValue(control)); | ||
501 | #else | ||
502 | GetDialogItem(commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ | ||
503 | SetControlValue((ControlHandle)dummyHandle, !GetControlValue((ControlHandle)dummyHandle) ); | ||
504 | #endif | ||
505 | } | ||
506 | |||
507 | } while (itemHit != kCL_OK && itemHit != kCL_Cancel); | ||
508 | |||
509 | /* Get control values, even if they did not change */ | ||
510 | GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); /* MJS */ | ||
511 | GetDialogItemText (dummyHandle, prefs.command_line); | ||
512 | |||
513 | #if TARGET_API_MAC_CARBON | ||
514 | GetDialogItemAsControl(commandDialog, kCL_File, &control); | ||
515 | prefs.output_to_file = GetControlValue(control); | ||
516 | #else | ||
517 | GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ | ||
518 | prefs.output_to_file = GetControlValue ((ControlHandle)dummyHandle); | ||
519 | #endif | ||
520 | |||
521 | #if TARGET_API_MAC_CARBON | ||
522 | GetDialogItemAsControl(commandDialog, kCL_Video, &control); | ||
523 | videodriver = GetControlValue(control); | ||
524 | #else | ||
525 | GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); | ||
526 | videodriver = GetControlValue ((ControlRef)dummyHandle); | ||
527 | #endif | ||
528 | |||
529 | DisposeDialog (commandDialog); | ||
530 | |||
531 | if (itemHit == kCL_Cancel ) { | ||
532 | exit (0); | ||
533 | } | ||
534 | } | ||
535 | |||
536 | /* Set pseudo-environment variables for video driver, update prefs */ | ||
537 | switch ( videodriver ) { | ||
538 | case VIDEO_ID_DRAWSPROCKET: | ||
539 | SDL_putenv("SDL_VIDEODRIVER=DSp"); | ||
540 | SDL_memcpy(prefs.video_driver_name, "\pDSp", 4); | ||
541 | break; | ||
542 | case VIDEO_ID_TOOLBOX: | ||
543 | SDL_putenv("SDL_VIDEODRIVER=toolbox"); | ||
544 | SDL_memcpy(prefs.video_driver_name, "\ptoolbox", 8); | ||
545 | break; | ||
546 | } | ||
547 | |||
548 | #if !(defined(__APPLE__) && defined(__MACH__)) | ||
549 | /* Redirect standard I/O to files */ | ||
550 | if ( prefs.output_to_file ) { | ||
551 | freopen (STDOUT_FILE, "w", stdout); | ||
552 | freopen (STDERR_FILE, "w", stderr); | ||
553 | } else { | ||
554 | fclose (stdout); | ||
555 | fclose (stderr); | ||
556 | } | ||
557 | #endif | ||
558 | |||
559 | if (settingsChanged) { | ||
560 | /* Save the prefs, even if they might not have changed (but probably did) */ | ||
561 | if ( ! writePreferences (&prefs) ) | ||
562 | fprintf (stderr, "WARNING: Could not save preferences!\n"); | ||
563 | } | ||
564 | |||
565 | #if !(defined(__APPLE__) && defined(__MACH__)) | ||
566 | appNameText[0] = 0; | ||
567 | getCurrentAppName (appNameText); /* check for error here ? */ | ||
568 | |||
569 | commandLine = (char*) malloc (appNameText[0] + prefs.command_line[0] + 2); | ||
570 | if ( commandLine == NULL ) { | ||
571 | exit(-1); | ||
572 | } | ||
573 | |||
574 | /* Rather than rewrite ParseCommandLine method, let's replace */ | ||
575 | /* any spaces in application name with underscores, */ | ||
576 | /* so that the app name is only 1 argument */ | ||
577 | for (i = 1; i < 1+appNameText[0]; i++) | ||
578 | if ( appNameText[i] == ' ' ) appNameText[i] = '_'; | ||
579 | |||
580 | /* Copy app name & full command text to command-line C-string */ | ||
581 | SDL_memcpy(commandLine, appNameText + 1, appNameText[0]); | ||
582 | commandLine[appNameText[0]] = ' '; | ||
583 | SDL_memcpy(commandLine + appNameText[0] + 1, prefs.command_line + 1, prefs.command_line[0]); | ||
584 | commandLine[ appNameText[0] + 1 + prefs.command_line[0] ] = '\0'; | ||
585 | |||
586 | /* Parse C-string into argv and argc */ | ||
587 | nargs = ParseCommandLine (commandLine, NULL); | ||
588 | args = (char **)malloc((nargs+1)*(sizeof *args)); | ||
589 | if ( args == NULL ) { | ||
590 | exit(-1); | ||
591 | } | ||
592 | ParseCommandLine (commandLine, args); | ||
593 | |||
594 | /* Run the main application code */ | ||
595 | SDL_main(nargs, args); | ||
596 | free (args); | ||
597 | free (commandLine); | ||
598 | |||
599 | /* Remove useless stdout.txt and stderr.txt */ | ||
600 | cleanup_output (); | ||
601 | #else // defined(__APPLE__) && defined(__MACH__) | ||
602 | SDL_main(argc, argv); | ||
603 | #endif | ||
604 | |||
605 | /* Exit cleanly, calling atexit() functions */ | ||
606 | exit (0); | ||
607 | |||
608 | /* Never reached, but keeps the compiler quiet */ | ||
609 | return (0); | ||
610 | } | ||
diff --git a/apps/plugins/sdl/src/main/macos/SIZE.r b/apps/plugins/sdl/src/main/macos/SIZE.r new file mode 100644 index 0000000000..940f37fc7f --- /dev/null +++ b/apps/plugins/sdl/src/main/macos/SIZE.r | |||
@@ -0,0 +1 @@ | |||
#include "Processes.r" resource 'SIZE' (-1) { reserved, acceptSuspendResumeEvents, reserved, canBackground, doesActivateOnFGSwitch, backgroundAndForeground, getFrontClicks, ignoreAppDiedEvents, is32BitCompatible, isHighLevelEventAware, onlyLocalHLEvents, notStationeryAware, useTextEditServices, reserved, reserved, reserved, 5242880, // 5 megs minimum 5242880 // 5 megs maximum }; \ No newline at end of file | |||
diff --git a/apps/plugins/sdl/src/main/macos/exports/Makefile b/apps/plugins/sdl/src/main/macos/exports/Makefile new file mode 100644 index 0000000000..5f37ae0760 --- /dev/null +++ b/apps/plugins/sdl/src/main/macos/exports/Makefile | |||
@@ -0,0 +1,39 @@ | |||
1 | |||
2 | EXPORTS = SDL.x | ||
3 | HEADERS = \ | ||
4 | ../../../../include/SDL.h \ | ||
5 | ../../../../include/SDL_active.h \ | ||
6 | ../../../../include/SDL_audio.h \ | ||
7 | ../../../../include/SDL_byteorder.h \ | ||
8 | ../../../../include/SDL_cdrom.h \ | ||
9 | ../../../../include/SDL_copying.h \ | ||
10 | ../../../../include/SDL_cpuinfo.h \ | ||
11 | ../../../../include/SDL_endian.h \ | ||
12 | ../../../../include/SDL_error.h \ | ||
13 | ../../../../include/SDL_events.h \ | ||
14 | ../../../../include/SDL_getenv.h \ | ||
15 | ../../../../include/SDL_joystick.h \ | ||
16 | ../../../../include/SDL_keyboard.h \ | ||
17 | ../../../../include/SDL_keysym.h \ | ||
18 | ../../../../include/SDL_loadso.h \ | ||
19 | ../../../../include/SDL_mouse.h \ | ||
20 | ../../../../include/SDL_mutex.h \ | ||
21 | ../../../../include/SDL_name.h \ | ||
22 | ../../../../include/SDL_platform.h \ | ||
23 | ../../../../include/SDL_quit.h \ | ||
24 | ../../../../include/SDL_rwops.h \ | ||
25 | ../../../../include/SDL_syswm.h \ | ||
26 | ../../../../include/SDL_thread.h \ | ||
27 | ../../../../include/SDL_timer.h \ | ||
28 | ../../../../include/SDL_types.h \ | ||
29 | ../../../../include/SDL_version.h \ | ||
30 | ../../../../include/SDL_video.h | ||
31 | |||
32 | |||
33 | all: $(EXPORTS) | ||
34 | |||
35 | $(EXPORTS): Makefile gendef.pl $(HEADERS) | ||
36 | perl gendef.pl $(HEADERS) >$@ || rm $@ | ||
37 | |||
38 | clean: | ||
39 | rm -f $(EXPORTS) | ||
diff --git a/apps/plugins/sdl/src/main/macos/exports/SDL.x b/apps/plugins/sdl/src/main/macos/exports/SDL.x new file mode 100644 index 0000000000..4830c43e93 --- /dev/null +++ b/apps/plugins/sdl/src/main/macos/exports/SDL.x | |||
@@ -0,0 +1 @@ | |||
SDL_Init SDL_InitSubSystem SDL_QuitSubSystem SDL_WasInit SDL_Quit SDL_GetAppState SDL_AudioInit SDL_AudioQuit SDL_AudioDriverName SDL_OpenAudio SDL_GetAudioStatus SDL_PauseAudio SDL_LoadWAV_RW SDL_FreeWAV SDL_BuildAudioCVT SDL_ConvertAudio SDL_MixAudio SDL_LockAudio SDL_UnlockAudio SDL_CloseAudio SDL_CDNumDrives SDL_CDName SDL_CDOpen SDL_CDStatus SDL_CDPlayTracks SDL_CDPlay SDL_CDPause SDL_CDResume SDL_CDStop SDL_CDEject SDL_CDClose SDL_HasRDTSC SDL_HasMMX SDL_HasMMXExt SDL_Has3DNow SDL_Has3DNowExt SDL_HasSSE SDL_HasSSE2 SDL_HasAltiVec SDL_SetError SDL_GetError SDL_ClearError SDL_Error SDL_PumpEvents SDL_PeepEvents SDL_PollEvent SDL_WaitEvent SDL_PushEvent SDL_SetEventFilter SDL_GetEventFilter SDL_EventState SDL_NumJoysticks SDL_JoystickName SDL_JoystickOpen SDL_JoystickOpened SDL_JoystickIndex SDL_JoystickNumAxes SDL_JoystickNumBalls SDL_JoystickNumHats SDL_JoystickNumButtons SDL_JoystickUpdate SDL_JoystickEventState SDL_JoystickGetAxis SDL_JoystickGetHat SDL_JoystickGetBall SDL_JoystickGetButton SDL_JoystickClose SDL_EnableUNICODE SDL_EnableKeyRepeat SDL_GetKeyRepeat SDL_GetKeyState SDL_GetModState SDL_SetModState SDL_GetKeyName SDL_LoadObject SDL_LoadFunction SDL_UnloadObject SDL_GetMouseState SDL_GetRelativeMouseState SDL_WarpMouse SDL_CreateCursor SDL_SetCursor SDL_GetCursor SDL_FreeCursor SDL_ShowCursor SDL_CreateMutex SDL_mutexP SDL_mutexV SDL_DestroyMutex SDL_CreateSemaphore SDL_DestroySemaphore SDL_SemWait SDL_SemTryWait SDL_SemWaitTimeout SDL_SemPost SDL_SemValue SDL_CreateCond SDL_DestroyCond SDL_CondSignal SDL_CondBroadcast SDL_CondWait SDL_CondWaitTimeout SDL_RWFromFile SDL_RWFromFP SDL_RWFromMem SDL_RWFromConstMem SDL_AllocRW SDL_FreeRW SDL_ReadLE16 SDL_ReadBE16 SDL_ReadLE32 SDL_ReadBE32 SDL_ReadLE64 SDL_ReadBE64 SDL_WriteLE16 SDL_WriteBE16 SDL_WriteLE32 SDL_WriteBE32 SDL_WriteLE64 SDL_WriteBE64 SDL_GetWMInfo SDL_CreateThread SDL_CreateThread SDL_ThreadID SDL_GetThreadID SDL_WaitThread SDL_KillThread SDL_GetTicks SDL_Delay SDL_SetTimer SDL_AddTimer SDL_RemoveTimer SDL_Linked_Version SDL_VideoInit SDL_VideoQuit SDL_VideoDriverName SDL_GetVideoSurface SDL_GetVideoInfo SDL_VideoModeOK SDL_ListModes SDL_SetVideoMode SDL_UpdateRects SDL_UpdateRect SDL_Flip SDL_SetGamma SDL_SetGammaRamp SDL_GetGammaRamp SDL_SetColors SDL_SetPalette SDL_MapRGB SDL_MapRGBA SDL_GetRGB SDL_GetRGBA SDL_CreateRGBSurface SDL_CreateRGBSurfaceFrom SDL_FreeSurface SDL_LockSurface SDL_UnlockSurface SDL_LoadBMP_RW SDL_SaveBMP_RW SDL_SetColorKey SDL_SetAlpha SDL_SetClipRect SDL_GetClipRect SDL_ConvertSurface SDL_UpperBlit SDL_LowerBlit SDL_FillRect SDL_DisplayFormat SDL_DisplayFormatAlpha SDL_CreateYUVOverlay SDL_LockYUVOverlay SDL_UnlockYUVOverlay SDL_DisplayYUVOverlay SDL_FreeYUVOverlay SDL_GL_LoadLibrary SDL_GL_GetProcAddress SDL_GL_SetAttribute SDL_GL_GetAttribute SDL_GL_SwapBuffers SDL_GL_UpdateRects SDL_GL_Lock SDL_GL_Unlock SDL_WM_SetCaption SDL_WM_GetCaption SDL_WM_SetIcon SDL_WM_IconifyWindow SDL_WM_ToggleFullScreen SDL_WM_GrabInput SDL_SoftStretch SDL_putenv SDL_getenv SDL_qsort SDL_revcpy SDL_strlcpy SDL_strlcat SDL_strdup SDL_strrev SDL_strupr SDL_strlwr SDL_ltoa SDL_ultoa SDL_strcasecmp SDL_strncasecmp SDL_snprintf SDL_vsnprintf SDL_iconv SDL_iconv_string SDL_InitQuickDraw \ No newline at end of file | |||
diff --git a/apps/plugins/sdl/src/main/macos/exports/gendef.pl b/apps/plugins/sdl/src/main/macos/exports/gendef.pl new file mode 100644 index 0000000000..9cffca92aa --- /dev/null +++ b/apps/plugins/sdl/src/main/macos/exports/gendef.pl | |||
@@ -0,0 +1,43 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # Program to take a set of header files and generate DLL export definitions | ||
4 | |||
5 | # Special exports to ignore for this platform | ||
6 | |||
7 | while ( ($file = shift(@ARGV)) ) { | ||
8 | if ( ! defined(open(FILE, $file)) ) { | ||
9 | warn "Couldn't open $file: $!\n"; | ||
10 | next; | ||
11 | } | ||
12 | $printed_header = 0; | ||
13 | $file =~ s,.*/,,; | ||
14 | while (<FILE>) { | ||
15 | if ( / DECLSPEC.* SDLCALL ([^\s\(]+)/ ) { | ||
16 | if ( not $exclude{$1} ) { | ||
17 | print "\t$1\r"; | ||
18 | } | ||
19 | } | ||
20 | } | ||
21 | close(FILE); | ||
22 | } | ||
23 | |||
24 | # Special exports to include for this platform | ||
25 | print "\tSDL_putenv\r"; | ||
26 | print "\tSDL_getenv\r"; | ||
27 | print "\tSDL_qsort\r"; | ||
28 | print "\tSDL_revcpy\r"; | ||
29 | print "\tSDL_strlcpy\r"; | ||
30 | print "\tSDL_strlcat\r"; | ||
31 | print "\tSDL_strdup\r"; | ||
32 | print "\tSDL_strrev\r"; | ||
33 | print "\tSDL_strupr\r"; | ||
34 | print "\tSDL_strlwr\r"; | ||
35 | print "\tSDL_ltoa\r"; | ||
36 | print "\tSDL_ultoa\r"; | ||
37 | print "\tSDL_strcasecmp\r"; | ||
38 | print "\tSDL_strncasecmp\r"; | ||
39 | print "\tSDL_snprintf\r"; | ||
40 | print "\tSDL_vsnprintf\r"; | ||
41 | print "\tSDL_iconv\r"; | ||
42 | print "\tSDL_iconv_string\r"; | ||
43 | print "\tSDL_InitQuickDraw\r"; | ||
diff --git a/apps/plugins/sdl/src/main/macosx/Info.plist.in b/apps/plugins/sdl/src/main/macosx/Info.plist.in new file mode 100644 index 0000000000..b3d69abac9 --- /dev/null +++ b/apps/plugins/sdl/src/main/macosx/Info.plist.in | |||
@@ -0,0 +1,24 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> | ||
3 | <plist version="0.9"> | ||
4 | <dict> | ||
5 | <key>CFBundleDevelopmentRegion</key> | ||
6 | <string>English</string> | ||
7 | <key>CFBundleExecutable</key> | ||
8 | <string>@EXECUTABLE_NAME@</string> | ||
9 | <key>CFBundleInfoDictionaryVersion</key> | ||
10 | <string>6.0</string> | ||
11 | <key>CFBundleName</key> | ||
12 | <string>@PACKAGE@</string> | ||
13 | <key>CFBundlePackageType</key> | ||
14 | <string>APPL</string> | ||
15 | <key>CFBundleShortVersionString</key> | ||
16 | <string>@VERSION@</string> | ||
17 | <key>CFBundleSignature</key> | ||
18 | <string>????</string> | ||
19 | <key>NSMainNibFile</key> | ||
20 | <string>SDLMain.nib</string> | ||
21 | <key>NSPrincipalClass</key> | ||
22 | <string>NSApplication</string> | ||
23 | </dict> | ||
24 | </plist> | ||
diff --git a/apps/plugins/sdl/src/main/macosx/SDLMain.h b/apps/plugins/sdl/src/main/macosx/SDLMain.h new file mode 100644 index 0000000000..c56d90cbe8 --- /dev/null +++ b/apps/plugins/sdl/src/main/macosx/SDLMain.h | |||
@@ -0,0 +1,16 @@ | |||
1 | /* SDLMain.m - main entry point for our Cocoa-ized SDL app | ||
2 | Initial Version: Darrell Walisser <dwaliss1@purdue.edu> | ||
3 | Non-NIB-Code & other changes: Max Horn <max@quendi.de> | ||
4 | |||
5 | Feel free to customize this file to suit your needs | ||
6 | */ | ||
7 | |||
8 | #ifndef _SDLMain_h_ | ||
9 | #define _SDLMain_h_ | ||
10 | |||
11 | #import <Cocoa/Cocoa.h> | ||
12 | |||
13 | @interface SDLMain : NSObject | ||
14 | @end | ||
15 | |||
16 | #endif /* _SDLMain_h_ */ | ||
diff --git a/apps/plugins/sdl/src/main/macosx/SDLMain.m b/apps/plugins/sdl/src/main/macosx/SDLMain.m new file mode 100644 index 0000000000..2434f81aa9 --- /dev/null +++ b/apps/plugins/sdl/src/main/macosx/SDLMain.m | |||
@@ -0,0 +1,381 @@ | |||
1 | /* SDLMain.m - main entry point for our Cocoa-ized SDL app | ||
2 | Initial Version: Darrell Walisser <dwaliss1@purdue.edu> | ||
3 | Non-NIB-Code & other changes: Max Horn <max@quendi.de> | ||
4 | |||
5 | Feel free to customize this file to suit your needs | ||
6 | */ | ||
7 | |||
8 | #include "SDL.h" | ||
9 | #include "SDLMain.h" | ||
10 | #include <sys/param.h> /* for MAXPATHLEN */ | ||
11 | #include <unistd.h> | ||
12 | |||
13 | /* For some reaon, Apple removed setAppleMenu from the headers in 10.4, | ||
14 | but the method still is there and works. To avoid warnings, we declare | ||
15 | it ourselves here. */ | ||
16 | @interface NSApplication(SDL_Missing_Methods) | ||
17 | - (void)setAppleMenu:(NSMenu *)menu; | ||
18 | @end | ||
19 | |||
20 | /* Use this flag to determine whether we use SDLMain.nib or not */ | ||
21 | #define SDL_USE_NIB_FILE 0 | ||
22 | |||
23 | /* Use this flag to determine whether we use CPS (docking) or not */ | ||
24 | #define SDL_USE_CPS 1 | ||
25 | #ifdef SDL_USE_CPS | ||
26 | /* Portions of CPS.h */ | ||
27 | typedef struct CPSProcessSerNum | ||
28 | { | ||
29 | UInt32 lo; | ||
30 | UInt32 hi; | ||
31 | } CPSProcessSerNum; | ||
32 | |||
33 | extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn); | ||
34 | extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); | ||
35 | extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn); | ||
36 | |||
37 | #endif /* SDL_USE_CPS */ | ||
38 | |||
39 | static int gArgc; | ||
40 | static char **gArgv; | ||
41 | static BOOL gFinderLaunch; | ||
42 | static BOOL gCalledAppMainline = FALSE; | ||
43 | |||
44 | static NSString *getApplicationName(void) | ||
45 | { | ||
46 | const NSDictionary *dict; | ||
47 | NSString *appName = 0; | ||
48 | |||
49 | /* Determine the application name */ | ||
50 | dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); | ||
51 | if (dict) | ||
52 | appName = [dict objectForKey: @"CFBundleName"]; | ||
53 | |||
54 | if (![appName length]) | ||
55 | appName = [[NSProcessInfo processInfo] processName]; | ||
56 | |||
57 | return appName; | ||
58 | } | ||
59 | |||
60 | #if SDL_USE_NIB_FILE | ||
61 | /* A helper category for NSString */ | ||
62 | @interface NSString (ReplaceSubString) | ||
63 | - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; | ||
64 | @end | ||
65 | #endif | ||
66 | |||
67 | @interface NSApplication (SDLApplication) | ||
68 | @end | ||
69 | |||
70 | @implementation NSApplication (SDLApplication) | ||
71 | /* Invoked from the Quit menu item */ | ||
72 | - (void)terminate:(id)sender | ||
73 | { | ||
74 | /* Post a SDL_QUIT event */ | ||
75 | SDL_Event event; | ||
76 | event.type = SDL_QUIT; | ||
77 | SDL_PushEvent(&event); | ||
78 | } | ||
79 | @end | ||
80 | |||
81 | /* The main class of the application, the application's delegate */ | ||
82 | @implementation SDLMain | ||
83 | |||
84 | /* Set the working directory to the .app's parent directory */ | ||
85 | - (void) setupWorkingDirectory:(BOOL)shouldChdir | ||
86 | { | ||
87 | if (shouldChdir) | ||
88 | { | ||
89 | char parentdir[MAXPATHLEN]; | ||
90 | CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); | ||
91 | CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); | ||
92 | if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) { | ||
93 | chdir(parentdir); /* chdir to the binary app's parent */ | ||
94 | } | ||
95 | CFRelease(url); | ||
96 | CFRelease(url2); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | #if SDL_USE_NIB_FILE | ||
101 | |||
102 | /* Fix menu to contain the real app name instead of "SDL App" */ | ||
103 | - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName | ||
104 | { | ||
105 | NSRange aRange; | ||
106 | NSEnumerator *enumerator; | ||
107 | NSMenuItem *menuItem; | ||
108 | |||
109 | aRange = [[aMenu title] rangeOfString:@"SDL App"]; | ||
110 | if (aRange.length != 0) | ||
111 | [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]]; | ||
112 | |||
113 | enumerator = [[aMenu itemArray] objectEnumerator]; | ||
114 | while ((menuItem = [enumerator nextObject])) | ||
115 | { | ||
116 | aRange = [[menuItem title] rangeOfString:@"SDL App"]; | ||
117 | if (aRange.length != 0) | ||
118 | [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]]; | ||
119 | if ([menuItem hasSubmenu]) | ||
120 | [self fixMenu:[menuItem submenu] withAppName:appName]; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | #else | ||
125 | |||
126 | static void setApplicationMenu(void) | ||
127 | { | ||
128 | /* warning: this code is very odd */ | ||
129 | NSMenu *appleMenu; | ||
130 | NSMenuItem *menuItem; | ||
131 | NSString *title; | ||
132 | NSString *appName; | ||
133 | |||
134 | appName = getApplicationName(); | ||
135 | appleMenu = [[NSMenu alloc] initWithTitle:@""]; | ||
136 | |||
137 | /* Add menu items */ | ||
138 | title = [@"About " stringByAppendingString:appName]; | ||
139 | [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; | ||
140 | |||
141 | [appleMenu addItem:[NSMenuItem separatorItem]]; | ||
142 | |||
143 | title = [@"Hide " stringByAppendingString:appName]; | ||
144 | [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; | ||
145 | |||
146 | menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; | ||
147 | [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; | ||
148 | |||
149 | [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; | ||
150 | |||
151 | [appleMenu addItem:[NSMenuItem separatorItem]]; | ||
152 | |||
153 | title = [@"Quit " stringByAppendingString:appName]; | ||
154 | [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; | ||
155 | |||
156 | |||
157 | /* Put menu into the menubar */ | ||
158 | menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; | ||
159 | [menuItem setSubmenu:appleMenu]; | ||
160 | [[NSApp mainMenu] addItem:menuItem]; | ||
161 | |||
162 | /* Tell the application object that this is now the application menu */ | ||
163 | [NSApp setAppleMenu:appleMenu]; | ||
164 | |||
165 | /* Finally give up our references to the objects */ | ||
166 | [appleMenu release]; | ||
167 | [menuItem release]; | ||
168 | } | ||
169 | |||
170 | /* Create a window menu */ | ||
171 | static void setupWindowMenu(void) | ||
172 | { | ||
173 | NSMenu *windowMenu; | ||
174 | NSMenuItem *windowMenuItem; | ||
175 | NSMenuItem *menuItem; | ||
176 | |||
177 | windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; | ||
178 | |||
179 | /* "Minimize" item */ | ||
180 | menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; | ||
181 | [windowMenu addItem:menuItem]; | ||
182 | [menuItem release]; | ||
183 | |||
184 | /* Put menu into the menubar */ | ||
185 | windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; | ||
186 | [windowMenuItem setSubmenu:windowMenu]; | ||
187 | [[NSApp mainMenu] addItem:windowMenuItem]; | ||
188 | |||
189 | /* Tell the application object that this is now the window menu */ | ||
190 | [NSApp setWindowsMenu:windowMenu]; | ||
191 | |||
192 | /* Finally give up our references to the objects */ | ||
193 | [windowMenu release]; | ||
194 | [windowMenuItem release]; | ||
195 | } | ||
196 | |||
197 | /* Replacement for NSApplicationMain */ | ||
198 | static void CustomApplicationMain (int argc, char **argv) | ||
199 | { | ||
200 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||
201 | SDLMain *sdlMain; | ||
202 | |||
203 | /* Ensure the application object is initialised */ | ||
204 | [NSApplication sharedApplication]; | ||
205 | |||
206 | #ifdef SDL_USE_CPS | ||
207 | { | ||
208 | CPSProcessSerNum PSN; | ||
209 | /* Tell the dock about us */ | ||
210 | if (!CPSGetCurrentProcess(&PSN)) | ||
211 | if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103)) | ||
212 | if (!CPSSetFrontProcess(&PSN)) | ||
213 | [NSApplication sharedApplication]; | ||
214 | } | ||
215 | #endif /* SDL_USE_CPS */ | ||
216 | |||
217 | /* Set up the menubar */ | ||
218 | [NSApp setMainMenu:[[NSMenu alloc] init]]; | ||
219 | setApplicationMenu(); | ||
220 | setupWindowMenu(); | ||
221 | |||
222 | /* Create SDLMain and make it the app delegate */ | ||
223 | sdlMain = [[SDLMain alloc] init]; | ||
224 | [NSApp setDelegate:sdlMain]; | ||
225 | |||
226 | /* Start the main event loop */ | ||
227 | [NSApp run]; | ||
228 | |||
229 | [sdlMain release]; | ||
230 | [pool release]; | ||
231 | } | ||
232 | |||
233 | #endif | ||
234 | |||
235 | |||
236 | /* | ||
237 | * Catch document open requests...this lets us notice files when the app | ||
238 | * was launched by double-clicking a document, or when a document was | ||
239 | * dragged/dropped on the app's icon. You need to have a | ||
240 | * CFBundleDocumentsType section in your Info.plist to get this message, | ||
241 | * apparently. | ||
242 | * | ||
243 | * Files are added to gArgv, so to the app, they'll look like command line | ||
244 | * arguments. Previously, apps launched from the finder had nothing but | ||
245 | * an argv[0]. | ||
246 | * | ||
247 | * This message may be received multiple times to open several docs on launch. | ||
248 | * | ||
249 | * This message is ignored once the app's mainline has been called. | ||
250 | */ | ||
251 | - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename | ||
252 | { | ||
253 | const char *temparg; | ||
254 | size_t arglen; | ||
255 | char *arg; | ||
256 | char **newargv; | ||
257 | |||
258 | if (!gFinderLaunch) /* MacOS is passing command line args. */ | ||
259 | return FALSE; | ||
260 | |||
261 | if (gCalledAppMainline) /* app has started, ignore this document. */ | ||
262 | return FALSE; | ||
263 | |||
264 | temparg = [filename UTF8String]; | ||
265 | arglen = SDL_strlen(temparg) + 1; | ||
266 | arg = (char *) SDL_malloc(arglen); | ||
267 | if (arg == NULL) | ||
268 | return FALSE; | ||
269 | |||
270 | newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2)); | ||
271 | if (newargv == NULL) | ||
272 | { | ||
273 | SDL_free(arg); | ||
274 | return FALSE; | ||
275 | } | ||
276 | gArgv = newargv; | ||
277 | |||
278 | SDL_strlcpy(arg, temparg, arglen); | ||
279 | gArgv[gArgc++] = arg; | ||
280 | gArgv[gArgc] = NULL; | ||
281 | return TRUE; | ||
282 | } | ||
283 | |||
284 | |||
285 | /* Called when the internal event loop has just started running */ | ||
286 | - (void) applicationDidFinishLaunching: (NSNotification *) note | ||
287 | { | ||
288 | int status; | ||
289 | |||
290 | /* Set the working directory to the .app's parent directory */ | ||
291 | [self setupWorkingDirectory:gFinderLaunch]; | ||
292 | |||
293 | #if SDL_USE_NIB_FILE | ||
294 | /* Set the main menu to contain the real app name instead of "SDL App" */ | ||
295 | [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()]; | ||
296 | #endif | ||
297 | |||
298 | /* Hand off to main application code */ | ||
299 | gCalledAppMainline = TRUE; | ||
300 | status = SDL_main (gArgc, gArgv); | ||
301 | |||
302 | /* We're done, thank you for playing */ | ||
303 | exit(status); | ||
304 | } | ||
305 | @end | ||
306 | |||
307 | |||
308 | @implementation NSString (ReplaceSubString) | ||
309 | |||
310 | - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString | ||
311 | { | ||
312 | unsigned int bufferSize; | ||
313 | unsigned int selfLen = [self length]; | ||
314 | unsigned int aStringLen = [aString length]; | ||
315 | unichar *buffer; | ||
316 | NSRange localRange; | ||
317 | NSString *result; | ||
318 | |||
319 | bufferSize = selfLen + aStringLen - aRange.length; | ||
320 | buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar)); | ||
321 | |||
322 | /* Get first part into buffer */ | ||
323 | localRange.location = 0; | ||
324 | localRange.length = aRange.location; | ||
325 | [self getCharacters:buffer range:localRange]; | ||
326 | |||
327 | /* Get middle part into buffer */ | ||
328 | localRange.location = 0; | ||
329 | localRange.length = aStringLen; | ||
330 | [aString getCharacters:(buffer+aRange.location) range:localRange]; | ||
331 | |||
332 | /* Get last part into buffer */ | ||
333 | localRange.location = aRange.location + aRange.length; | ||
334 | localRange.length = selfLen - localRange.location; | ||
335 | [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange]; | ||
336 | |||
337 | /* Build output string */ | ||
338 | result = [NSString stringWithCharacters:buffer length:bufferSize]; | ||
339 | |||
340 | NSDeallocateMemoryPages(buffer, bufferSize); | ||
341 | |||
342 | return result; | ||
343 | } | ||
344 | |||
345 | @end | ||
346 | |||
347 | |||
348 | |||
349 | #ifdef main | ||
350 | # undef main | ||
351 | #endif | ||
352 | |||
353 | |||
354 | /* Main entry point to executable - should *not* be SDL_main! */ | ||
355 | int main (int argc, char **argv) | ||
356 | { | ||
357 | /* Copy the arguments into a global variable */ | ||
358 | /* This is passed if we are launched by double-clicking */ | ||
359 | if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { | ||
360 | gArgv = (char **) SDL_malloc(sizeof (char *) * 2); | ||
361 | gArgv[0] = argv[0]; | ||
362 | gArgv[1] = NULL; | ||
363 | gArgc = 1; | ||
364 | gFinderLaunch = YES; | ||
365 | } else { | ||
366 | int i; | ||
367 | gArgc = argc; | ||
368 | gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1)); | ||
369 | for (i = 0; i <= argc; i++) | ||
370 | gArgv[i] = argv[i]; | ||
371 | gFinderLaunch = NO; | ||
372 | } | ||
373 | |||
374 | #if SDL_USE_NIB_FILE | ||
375 | NSApplicationMain (argc, argv); | ||
376 | #else | ||
377 | CustomApplicationMain (argc, argv); | ||
378 | #endif | ||
379 | return 0; | ||
380 | } | ||
381 | |||
diff --git a/apps/plugins/sdl/src/main/macosx/SDLMain.nib/classes.nib b/apps/plugins/sdl/src/main/macosx/SDLMain.nib/classes.nib new file mode 100644 index 0000000000..f8f4e9a4b9 --- /dev/null +++ b/apps/plugins/sdl/src/main/macosx/SDLMain.nib/classes.nib | |||
@@ -0,0 +1,12 @@ | |||
1 | { | ||
2 | IBClasses = ( | ||
3 | {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, | ||
4 | { | ||
5 | ACTIONS = {makeFullscreen = id; quit = id; }; | ||
6 | CLASS = SDLMain; | ||
7 | LANGUAGE = ObjC; | ||
8 | SUPERCLASS = NSObject; | ||
9 | } | ||
10 | ); | ||
11 | IBVersion = 1; | ||
12 | } | ||
diff --git a/apps/plugins/sdl/src/main/macosx/SDLMain.nib/info.nib b/apps/plugins/sdl/src/main/macosx/SDLMain.nib/info.nib new file mode 100644 index 0000000000..2211cf9d75 --- /dev/null +++ b/apps/plugins/sdl/src/main/macosx/SDLMain.nib/info.nib | |||
@@ -0,0 +1,12 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> | ||
3 | <plist version="0.9"> | ||
4 | <dict> | ||
5 | <key>IBDocumentLocation</key> | ||
6 | <string>49 97 356 240 0 0 987 746 </string> | ||
7 | <key>IBMainMenuLocation</key> | ||
8 | <string>20 515 195 44 0 46 800 532 </string> | ||
9 | <key>IBUserGuides</key> | ||
10 | <dict/> | ||
11 | </dict> | ||
12 | </plist> | ||
diff --git a/apps/plugins/sdl/src/main/macosx/SDLMain.nib/objects.nib b/apps/plugins/sdl/src/main/macosx/SDLMain.nib/objects.nib new file mode 100644 index 0000000000..9f697b0ee7 --- /dev/null +++ b/apps/plugins/sdl/src/main/macosx/SDLMain.nib/objects.nib | |||
Binary files differ | |||
diff --git a/apps/plugins/sdl/src/main/macosx/info.nib b/apps/plugins/sdl/src/main/macosx/info.nib new file mode 100644 index 0000000000..d13726f807 --- /dev/null +++ b/apps/plugins/sdl/src/main/macosx/info.nib | |||
@@ -0,0 +1 @@ | |||
// This is just a stub file to force automake to create the install directory | |||
diff --git a/apps/plugins/sdl/src/main/qtopia/SDL_qtopia_main.cc b/apps/plugins/sdl/src/main/qtopia/SDL_qtopia_main.cc new file mode 100644 index 0000000000..46fd518ff0 --- /dev/null +++ b/apps/plugins/sdl/src/main/qtopia/SDL_qtopia_main.cc | |||
@@ -0,0 +1,47 @@ | |||
1 | |||
2 | /* Include the SDL main definition header */ | ||
3 | #include "SDL_main.h" | ||
4 | #include <stdlib.h> | ||
5 | #include <unistd.h> | ||
6 | #ifdef main | ||
7 | #undef main | ||
8 | #endif | ||
9 | #ifdef QWS | ||
10 | #include <qpe/qpeapplication.h> | ||
11 | #include <qapplication.h> | ||
12 | #include <qpe/qpeapplication.h> | ||
13 | #include <stdlib.h> | ||
14 | |||
15 | // Workaround for OPIE to remove taskbar icon. Also fixes | ||
16 | // some issues in Qtopia where there are left-over qcop files in /tmp/. | ||
17 | // I'm guessing this will also clean up the taskbar in the Sharp version | ||
18 | // of Qtopia. | ||
19 | static inline void cleanupQCop() { | ||
20 | QString appname(qApp->argv()[0]); | ||
21 | int slash = appname.findRev("/"); | ||
22 | if(slash != -1) { appname = appname.mid(slash+1); } | ||
23 | QString cmd = QPEApplication::qpeDir() + "bin/qcop QPE/System 'closing(QString)' '"+appname+"'"; | ||
24 | system(cmd.latin1()); | ||
25 | cmd = "/tmp/qcop-msg-"+appname; | ||
26 | unlink(cmd.latin1()); | ||
27 | } | ||
28 | |||
29 | static QPEApplication *app; | ||
30 | #endif | ||
31 | |||
32 | extern int SDL_main(int argc, char *argv[]); | ||
33 | |||
34 | int main(int argc, char *argv[]) | ||
35 | { | ||
36 | #ifdef QWS | ||
37 | // This initializes the Qtopia application. It needs to be done here | ||
38 | // because it parses command line options. | ||
39 | app = new QPEApplication(argc, argv); | ||
40 | QWidget dummy; | ||
41 | app->showMainWidget(&dummy); | ||
42 | atexit(cleanupQCop); | ||
43 | #endif | ||
44 | // Exit here because if return is used, the application | ||
45 | // doesn't seem to quit correctly. | ||
46 | exit(SDL_main(argc, argv)); | ||
47 | } | ||
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 | |||
diff --git a/apps/plugins/sdl/src/main/win32/SDL_win32_main.c b/apps/plugins/sdl/src/main/win32/SDL_win32_main.c new file mode 100644 index 0000000000..672b48c12e --- /dev/null +++ b/apps/plugins/sdl/src/main/win32/SDL_win32_main.c | |||
@@ -0,0 +1,402 @@ | |||
1 | /* | ||
2 | SDL_main.c, placed in the public domain by Sam Lantinga 4/13/98 | ||
3 | |||
4 | The WinMain function -- calls your program's main() function | ||
5 | */ | ||
6 | |||
7 | #include <stdio.h> | ||
8 | #include <stdlib.h> | ||
9 | |||
10 | #define WIN32_LEAN_AND_MEAN | ||
11 | #include <windows.h> | ||
12 | |||
13 | #ifdef _WIN32_WCE | ||
14 | # define DIR_SEPERATOR TEXT("\\") | ||
15 | # undef _getcwd | ||
16 | # define _getcwd(str,len) wcscpy(str,TEXT("")) | ||
17 | # define setbuf(f,b) | ||
18 | # define setvbuf(w,x,y,z) | ||
19 | # define fopen _wfopen | ||
20 | # define freopen _wfreopen | ||
21 | # define remove(x) DeleteFile(x) | ||
22 | #else | ||
23 | # define DIR_SEPERATOR TEXT("/") | ||
24 | # include <direct.h> | ||
25 | #endif | ||
26 | |||
27 | /* Include the SDL main definition header */ | ||
28 | #include "SDL.h" | ||
29 | #include "SDL_main.h" | ||
30 | |||
31 | #ifdef main | ||
32 | # ifndef _WIN32_WCE_EMULATION | ||
33 | # undef main | ||
34 | # endif /* _WIN32_WCE_EMULATION */ | ||
35 | #endif /* main */ | ||
36 | |||
37 | /* The standard output files */ | ||
38 | #define STDOUT_FILE TEXT("stdout.txt") | ||
39 | #define STDERR_FILE TEXT("stderr.txt") | ||
40 | |||
41 | /* Set a variable to tell if the stdio redirect has been enabled. */ | ||
42 | static int stdioRedirectEnabled = 0; | ||
43 | |||
44 | #ifdef _WIN32_WCE | ||
45 | static wchar_t stdoutPath[MAX_PATH]; | ||
46 | static wchar_t stderrPath[MAX_PATH]; | ||
47 | #else | ||
48 | static char stdoutPath[MAX_PATH]; | ||
49 | static char stderrPath[MAX_PATH]; | ||
50 | #endif | ||
51 | |||
52 | #if defined(_WIN32_WCE) && _WIN32_WCE < 300 | ||
53 | /* seems to be undefined in Win CE although in online help */ | ||
54 | #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) | ||
55 | #endif /* _WIN32_WCE < 300 */ | ||
56 | |||
57 | static void UnEscapeQuotes( char *arg ) | ||
58 | { | ||
59 | char *last = NULL; | ||
60 | |||
61 | while( *arg ) { | ||
62 | if( *arg == '"' && *last == '\\' ) { | ||
63 | char *c_curr = arg; | ||
64 | char *c_last = last; | ||
65 | |||
66 | while( *c_curr ) { | ||
67 | *c_last = *c_curr; | ||
68 | c_last = c_curr; | ||
69 | c_curr++; | ||
70 | } | ||
71 | *c_last = '\0'; | ||
72 | } | ||
73 | last = arg; | ||
74 | arg++; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | /* Parse a command line buffer into arguments */ | ||
79 | static int ParseCommandLine(char *cmdline, char **argv) | ||
80 | { | ||
81 | char *bufp; | ||
82 | char *lastp = NULL; | ||
83 | int argc, last_argc; | ||
84 | |||
85 | argc = last_argc = 0; | ||
86 | for ( bufp = cmdline; *bufp; ) { | ||
87 | /* Skip leading whitespace */ | ||
88 | while ( isspace(*bufp) ) { | ||
89 | ++bufp; | ||
90 | } | ||
91 | /* Skip over argument */ | ||
92 | if ( *bufp == '"' ) { | ||
93 | ++bufp; | ||
94 | if ( *bufp ) { | ||
95 | if ( argv ) { | ||
96 | argv[argc] = bufp; | ||
97 | } | ||
98 | ++argc; | ||
99 | } | ||
100 | /* Skip over word */ | ||
101 | while ( *bufp && ( *bufp != '"' || (lastp && *lastp == '\\') ) ) { | ||
102 | lastp = bufp; | ||
103 | ++bufp; | ||
104 | } | ||
105 | } else { | ||
106 | if ( *bufp ) { | ||
107 | if ( argv ) { | ||
108 | argv[argc] = bufp; | ||
109 | } | ||
110 | ++argc; | ||
111 | } | ||
112 | /* Skip over word */ | ||
113 | while ( *bufp && ! isspace(*bufp) ) { | ||
114 | ++bufp; | ||
115 | } | ||
116 | } | ||
117 | if ( *bufp ) { | ||
118 | if ( argv ) { | ||
119 | *bufp = '\0'; | ||
120 | } | ||
121 | ++bufp; | ||
122 | } | ||
123 | |||
124 | /* Strip out \ from \" sequences */ | ||
125 | if( argv && last_argc != argc ) { | ||
126 | UnEscapeQuotes( argv[last_argc] ); | ||
127 | } | ||
128 | last_argc = argc; | ||
129 | } | ||
130 | if ( argv ) { | ||
131 | argv[argc] = NULL; | ||
132 | } | ||
133 | return(argc); | ||
134 | } | ||
135 | |||
136 | /* Show an error message */ | ||
137 | static void ShowError(const char *title, const char *message) | ||
138 | { | ||
139 | /* If USE_MESSAGEBOX is defined, you need to link with user32.lib */ | ||
140 | #ifdef USE_MESSAGEBOX | ||
141 | MessageBox(NULL, message, title, MB_ICONEXCLAMATION|MB_OK); | ||
142 | #else | ||
143 | fprintf(stderr, "%s: %s\n", title, message); | ||
144 | #endif | ||
145 | } | ||
146 | |||
147 | /* Pop up an out of memory message, returns to Windows */ | ||
148 | static BOOL OutOfMemory(void) | ||
149 | { | ||
150 | ShowError("Fatal Error", "Out of memory - aborting"); | ||
151 | return FALSE; | ||
152 | } | ||
153 | |||
154 | /* SDL_Quit() shouldn't be used with atexit() directly because | ||
155 | calling conventions may differ... */ | ||
156 | static void cleanup(void) | ||
157 | { | ||
158 | SDL_Quit(); | ||
159 | } | ||
160 | |||
161 | /* Remove the output files if there was no output written */ | ||
162 | static void cleanup_output(void) { | ||
163 | FILE *file; | ||
164 | int empty; | ||
165 | |||
166 | /* Flush the output in case anything is queued */ | ||
167 | fclose(stdout); | ||
168 | fclose(stderr); | ||
169 | |||
170 | /* Without redirection we're done */ | ||
171 | if (!stdioRedirectEnabled) { | ||
172 | return; | ||
173 | } | ||
174 | |||
175 | /* See if the files have any output in them */ | ||
176 | if ( stdoutPath[0] ) { | ||
177 | file = fopen(stdoutPath, TEXT("rb")); | ||
178 | if ( file ) { | ||
179 | empty = (fgetc(file) == EOF) ? 1 : 0; | ||
180 | fclose(file); | ||
181 | if ( empty ) { | ||
182 | remove(stdoutPath); | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | if ( stderrPath[0] ) { | ||
187 | file = fopen(stderrPath, TEXT("rb")); | ||
188 | if ( file ) { | ||
189 | empty = (fgetc(file) == EOF) ? 1 : 0; | ||
190 | fclose(file); | ||
191 | if ( empty ) { | ||
192 | remove(stderrPath); | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | |||
198 | /* Redirect the output (stdout and stderr) to a file */ | ||
199 | static void redirect_output(void) | ||
200 | { | ||
201 | DWORD pathlen; | ||
202 | #ifdef _WIN32_WCE | ||
203 | wchar_t path[MAX_PATH]; | ||
204 | #else | ||
205 | char path[MAX_PATH]; | ||
206 | #endif | ||
207 | FILE *newfp; | ||
208 | |||
209 | pathlen = GetModuleFileName(NULL, path, SDL_arraysize(path)); | ||
210 | while ( pathlen > 0 && path[pathlen] != '\\' ) { | ||
211 | --pathlen; | ||
212 | } | ||
213 | path[pathlen] = '\0'; | ||
214 | |||
215 | #ifdef _WIN32_WCE | ||
216 | wcsncpy( stdoutPath, path, SDL_arraysize(stdoutPath) ); | ||
217 | wcsncat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); | ||
218 | #else | ||
219 | SDL_strlcpy( stdoutPath, path, SDL_arraysize(stdoutPath) ); | ||
220 | SDL_strlcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); | ||
221 | #endif | ||
222 | |||
223 | /* Redirect standard input and standard output */ | ||
224 | newfp = freopen(stdoutPath, TEXT("w"), stdout); | ||
225 | |||
226 | #ifndef _WIN32_WCE | ||
227 | if ( newfp == NULL ) { /* This happens on NT */ | ||
228 | #if !defined(stdout) | ||
229 | stdout = fopen(stdoutPath, TEXT("w")); | ||
230 | #else | ||
231 | newfp = fopen(stdoutPath, TEXT("w")); | ||
232 | if ( newfp ) { | ||
233 | *stdout = *newfp; | ||
234 | } | ||
235 | #endif | ||
236 | } | ||
237 | #endif /* _WIN32_WCE */ | ||
238 | |||
239 | #ifdef _WIN32_WCE | ||
240 | wcsncpy( stderrPath, path, SDL_arraysize(stdoutPath) ); | ||
241 | wcsncat( stderrPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); | ||
242 | #else | ||
243 | SDL_strlcpy( stderrPath, path, SDL_arraysize(stderrPath) ); | ||
244 | SDL_strlcat( stderrPath, DIR_SEPERATOR STDERR_FILE, SDL_arraysize(stderrPath) ); | ||
245 | #endif | ||
246 | |||
247 | newfp = freopen(stderrPath, TEXT("w"), stderr); | ||
248 | #ifndef _WIN32_WCE | ||
249 | if ( newfp == NULL ) { /* This happens on NT */ | ||
250 | #if !defined(stderr) | ||
251 | stderr = fopen(stderrPath, TEXT("w")); | ||
252 | #else | ||
253 | newfp = fopen(stderrPath, TEXT("w")); | ||
254 | if ( newfp ) { | ||
255 | *stderr = *newfp; | ||
256 | } | ||
257 | #endif | ||
258 | } | ||
259 | #endif /* _WIN32_WCE */ | ||
260 | |||
261 | setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ | ||
262 | setbuf(stderr, NULL); /* No buffering */ | ||
263 | stdioRedirectEnabled = 1; | ||
264 | } | ||
265 | |||
266 | #if defined(_MSC_VER) && !defined(_WIN32_WCE) | ||
267 | /* The VC++ compiler needs main defined */ | ||
268 | #define console_main main | ||
269 | #endif | ||
270 | |||
271 | /* This is where execution begins [console apps] */ | ||
272 | int console_main(int argc, char *argv[]) | ||
273 | { | ||
274 | size_t n; | ||
275 | char *bufp, *appname; | ||
276 | int status; | ||
277 | |||
278 | /* Get the class name from argv[0] */ | ||
279 | appname = argv[0]; | ||
280 | if ( (bufp=SDL_strrchr(argv[0], '\\')) != NULL ) { | ||
281 | appname = bufp+1; | ||
282 | } else | ||
283 | if ( (bufp=SDL_strrchr(argv[0], '/')) != NULL ) { | ||
284 | appname = bufp+1; | ||
285 | } | ||
286 | |||
287 | if ( (bufp=SDL_strrchr(appname, '.')) == NULL ) | ||
288 | n = SDL_strlen(appname); | ||
289 | else | ||
290 | n = (bufp-appname); | ||
291 | |||
292 | bufp = SDL_stack_alloc(char, n+1); | ||
293 | if ( bufp == NULL ) { | ||
294 | return OutOfMemory(); | ||
295 | } | ||
296 | SDL_strlcpy(bufp, appname, n+1); | ||
297 | appname = bufp; | ||
298 | |||
299 | /* Load SDL dynamic link library */ | ||
300 | if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) { | ||
301 | ShowError("WinMain() error", SDL_GetError()); | ||
302 | return(FALSE); | ||
303 | } | ||
304 | atexit(cleanup_output); | ||
305 | atexit(cleanup); | ||
306 | |||
307 | /* Sam: | ||
308 | We still need to pass in the application handle so that | ||
309 | DirectInput will initialize properly when SDL_RegisterApp() | ||
310 | is called later in the video initialization. | ||
311 | */ | ||
312 | SDL_SetModuleHandle(GetModuleHandle(NULL)); | ||
313 | |||
314 | /* Run the application main() code */ | ||
315 | status = SDL_main(argc, argv); | ||
316 | |||
317 | /* Exit cleanly, calling atexit() functions */ | ||
318 | exit(status); | ||
319 | |||
320 | /* Hush little compiler, don't you cry... */ | ||
321 | return 0; | ||
322 | } | ||
323 | |||
324 | /* This is where execution begins [windowed apps] */ | ||
325 | #ifdef _WIN32_WCE | ||
326 | int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw) | ||
327 | #else | ||
328 | int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) | ||
329 | #endif | ||
330 | { | ||
331 | HMODULE handle; | ||
332 | char **argv; | ||
333 | int argc; | ||
334 | char *cmdline; | ||
335 | char *env_str; | ||
336 | #ifdef _WIN32_WCE | ||
337 | wchar_t *bufp; | ||
338 | int nLen; | ||
339 | #else | ||
340 | char *bufp; | ||
341 | size_t nLen; | ||
342 | #endif | ||
343 | |||
344 | /* Start up DDHELP.EXE before opening any files, so DDHELP doesn't | ||
345 | keep them open. This is a hack.. hopefully it will be fixed | ||
346 | someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded. | ||
347 | */ | ||
348 | handle = LoadLibrary(TEXT("DDRAW.DLL")); | ||
349 | if ( handle != NULL ) { | ||
350 | FreeLibrary(handle); | ||
351 | } | ||
352 | |||
353 | /* Check for stdio redirect settings and do the redirection */ | ||
354 | if ((env_str = SDL_getenv("SDL_STDIO_REDIRECT"))) { | ||
355 | if (SDL_atoi(env_str)) { | ||
356 | redirect_output(); | ||
357 | } | ||
358 | } | ||
359 | #ifndef NO_STDIO_REDIRECT | ||
360 | else { | ||
361 | redirect_output(); | ||
362 | } | ||
363 | #endif | ||
364 | |||
365 | #ifdef _WIN32_WCE | ||
366 | nLen = wcslen(szCmdLine)+128+1; | ||
367 | bufp = SDL_stack_alloc(wchar_t, nLen*2); | ||
368 | wcscpy (bufp, TEXT("\"")); | ||
369 | GetModuleFileName(NULL, bufp+1, 128-3); | ||
370 | wcscpy (bufp+wcslen(bufp), TEXT("\" ")); | ||
371 | wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp)); | ||
372 | nLen = wcslen(bufp)+1; | ||
373 | cmdline = SDL_stack_alloc(char, nLen); | ||
374 | if ( cmdline == NULL ) { | ||
375 | return OutOfMemory(); | ||
376 | } | ||
377 | WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL); | ||
378 | #else | ||
379 | /* Grab the command line */ | ||
380 | bufp = GetCommandLine(); | ||
381 | nLen = SDL_strlen(bufp)+1; | ||
382 | cmdline = SDL_stack_alloc(char, nLen); | ||
383 | if ( cmdline == NULL ) { | ||
384 | return OutOfMemory(); | ||
385 | } | ||
386 | SDL_strlcpy(cmdline, bufp, nLen); | ||
387 | #endif | ||
388 | |||
389 | /* Parse it into argv and argc */ | ||
390 | argc = ParseCommandLine(cmdline, NULL); | ||
391 | argv = SDL_stack_alloc(char*, argc+1); | ||
392 | if ( argv == NULL ) { | ||
393 | return OutOfMemory(); | ||
394 | } | ||
395 | ParseCommandLine(cmdline, argv); | ||
396 | |||
397 | /* Run the main program (after a little SDL initialization) */ | ||
398 | console_main(argc, argv); | ||
399 | |||
400 | /* Hush little compiler, don't you cry... */ | ||
401 | return 0; | ||
402 | } | ||
diff --git a/apps/plugins/sdl/src/main/win32/version.rc b/apps/plugins/sdl/src/main/win32/version.rc new file mode 100644 index 0000000000..38fb6423e8 --- /dev/null +++ b/apps/plugins/sdl/src/main/win32/version.rc | |||
@@ -0,0 +1,38 @@ | |||
1 | |||
2 | #include "winresrc.h" | ||
3 | |||
4 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US | ||
5 | |||
6 | ///////////////////////////////////////////////////////////////////////////// | ||
7 | // | ||
8 | // Version | ||
9 | // | ||
10 | |||
11 | VS_VERSION_INFO VERSIONINFO | ||
12 | FILEVERSION 1,2,14,0 | ||
13 | PRODUCTVERSION 1,2,14,0 | ||
14 | FILEFLAGSMASK 0x3fL | ||
15 | FILEFLAGS 0x0L | ||
16 | FILEOS 0x40004L | ||
17 | FILETYPE 0x2L | ||
18 | FILESUBTYPE 0x0L | ||
19 | BEGIN | ||
20 | BLOCK "StringFileInfo" | ||
21 | BEGIN | ||
22 | BLOCK "040904b0" | ||
23 | BEGIN | ||
24 | VALUE "CompanyName", "\0" | ||
25 | VALUE "FileDescription", "SDL\0" | ||
26 | VALUE "FileVersion", "1, 2, 14, 0\0" | ||
27 | VALUE "InternalName", "SDL\0" | ||
28 | VALUE "LegalCopyright", "Copyright 2009 Sam Lantinga\0" | ||
29 | VALUE "OriginalFilename", "SDL.dll\0" | ||
30 | VALUE "ProductName", "Simple DirectMedia Layer\0" | ||
31 | VALUE "ProductVersion", "1, 2, 14, 0\0" | ||
32 | END | ||
33 | END | ||
34 | BLOCK "VarFileInfo" | ||
35 | BEGIN | ||
36 | VALUE "Translation", 0x409, 1200 | ||
37 | END | ||
38 | END | ||