From 9682c8870b8ff5e4ac2e4c70b759f791c6f38c1f Mon Sep 17 00:00:00 2001 From: Jesse Hall Date: Mon, 9 Jul 2012 11:27:07 -0700 Subject: Import SDL release-1.2.15 Change-Id: I505c4aea24325cad475f217db5589814b4c75dbf --- distrib/sdl-1.2.15/src/main/beos/SDL_BeApp.cc | 111 +++ distrib/sdl-1.2.15/src/main/beos/SDL_BeApp.h | 33 + distrib/sdl-1.2.15/src/main/dummy/SDL_dummy_main.c | 13 + distrib/sdl-1.2.15/src/main/macos/SDL.r | 1 + distrib/sdl-1.2.15/src/main/macos/SDL.shlib.r | 1 + distrib/sdl-1.2.15/src/main/macos/SDL_main.c | 610 ++++++++++++ distrib/sdl-1.2.15/src/main/macos/SIZE.r | 1 + distrib/sdl-1.2.15/src/main/macos/exports/Makefile | 39 + distrib/sdl-1.2.15/src/main/macos/exports/SDL.x | 1 + .../sdl-1.2.15/src/main/macos/exports/gendef.pl | 43 + distrib/sdl-1.2.15/src/main/macosx/Info.plist.in | 24 + distrib/sdl-1.2.15/src/main/macosx/SDLMain.h | 16 + distrib/sdl-1.2.15/src/main/macosx/SDLMain.m | 381 +++++++ .../src/main/macosx/SDLMain.nib/classes.nib | 12 + .../src/main/macosx/SDLMain.nib/info.nib | 12 + .../src/main/macosx/SDLMain.nib/objects.nib | Bin 0 -> 1701 bytes distrib/sdl-1.2.15/src/main/macosx/info.nib | 1 + .../sdl-1.2.15/src/main/qtopia/SDL_qtopia_main.cc | 47 + .../sdl-1.2.15/src/main/symbian/EKA1/SDL_main.cpp | 152 +++ .../sdl-1.2.15/src/main/symbian/EKA2/SDL_main.cpp | 1035 ++++++++++++++++++++ .../sdl-1.2.15/src/main/symbian/EKA2/sdlexe.cpp | 809 +++++++++++++++ .../sdl-1.2.15/src/main/symbian/EKA2/sdllib.cpp | 12 + .../src/main/symbian/EKA2/vectorbuffer.cpp | 62 ++ .../src/main/symbian/EKA2/vectorbuffer.h | 240 +++++ distrib/sdl-1.2.15/src/main/win32/SDL_win32_main.c | 402 ++++++++ distrib/sdl-1.2.15/src/main/win32/version.rc | 38 + 26 files changed, 4096 insertions(+) create mode 100644 distrib/sdl-1.2.15/src/main/beos/SDL_BeApp.cc create mode 100644 distrib/sdl-1.2.15/src/main/beos/SDL_BeApp.h create mode 100644 distrib/sdl-1.2.15/src/main/dummy/SDL_dummy_main.c create mode 100644 distrib/sdl-1.2.15/src/main/macos/SDL.r create mode 100644 distrib/sdl-1.2.15/src/main/macos/SDL.shlib.r create mode 100644 distrib/sdl-1.2.15/src/main/macos/SDL_main.c create mode 100644 distrib/sdl-1.2.15/src/main/macos/SIZE.r create mode 100644 distrib/sdl-1.2.15/src/main/macos/exports/Makefile create mode 100644 distrib/sdl-1.2.15/src/main/macos/exports/SDL.x create mode 100644 distrib/sdl-1.2.15/src/main/macos/exports/gendef.pl create mode 100644 distrib/sdl-1.2.15/src/main/macosx/Info.plist.in create mode 100644 distrib/sdl-1.2.15/src/main/macosx/SDLMain.h create mode 100644 distrib/sdl-1.2.15/src/main/macosx/SDLMain.m create mode 100644 distrib/sdl-1.2.15/src/main/macosx/SDLMain.nib/classes.nib create mode 100644 distrib/sdl-1.2.15/src/main/macosx/SDLMain.nib/info.nib create mode 100644 distrib/sdl-1.2.15/src/main/macosx/SDLMain.nib/objects.nib create mode 100644 distrib/sdl-1.2.15/src/main/macosx/info.nib create mode 100644 distrib/sdl-1.2.15/src/main/qtopia/SDL_qtopia_main.cc create mode 100644 distrib/sdl-1.2.15/src/main/symbian/EKA1/SDL_main.cpp create mode 100644 distrib/sdl-1.2.15/src/main/symbian/EKA2/SDL_main.cpp create mode 100644 distrib/sdl-1.2.15/src/main/symbian/EKA2/sdlexe.cpp create mode 100644 distrib/sdl-1.2.15/src/main/symbian/EKA2/sdllib.cpp create mode 100644 distrib/sdl-1.2.15/src/main/symbian/EKA2/vectorbuffer.cpp create mode 100644 distrib/sdl-1.2.15/src/main/symbian/EKA2/vectorbuffer.h create mode 100644 distrib/sdl-1.2.15/src/main/win32/SDL_win32_main.c create mode 100644 distrib/sdl-1.2.15/src/main/win32/version.rc (limited to 'distrib/sdl-1.2.15/src/main') diff --git a/distrib/sdl-1.2.15/src/main/beos/SDL_BeApp.cc b/distrib/sdl-1.2.15/src/main/beos/SDL_BeApp.cc new file mode 100644 index 0000000..8b79377 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/beos/SDL_BeApp.cc @@ -0,0 +1,111 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* Handle the BeApp specific portions of the application */ + +#include +#include +#include +#include + +#include "SDL_BeApp.h" +#include "SDL_thread.h" +#include "SDL_timer.h" +#include "SDL_error.h" + +/* Flag to tell whether or not the Be application is active or not */ +int SDL_BeAppActive = 0; +static SDL_Thread *SDL_AppThread = NULL; + +static int StartBeApp(void *unused) +{ + if(!be_app) { + BApplication *App; + + App = new BApplication("application/x-SDL-executable"); + + App->Run(); + delete App; + } + return(0); +} + +/* Initialize the Be Application, if it's not already started */ +int SDL_InitBeApp(void) +{ + /* Create the BApplication that handles appserver interaction */ + if ( SDL_BeAppActive <= 0 ) { + SDL_AppThread = SDL_CreateThread(StartBeApp, NULL); + if ( SDL_AppThread == NULL ) { + SDL_SetError("Couldn't create BApplication thread"); + return(-1); + } + + /* Change working to directory to that of executable */ + app_info info; + if (B_OK == be_app->GetAppInfo(&info)) { + entry_ref ref = info.ref; + BEntry entry; + if (B_OK == entry.SetTo(&ref)) { + BPath path; + if (B_OK == path.SetTo(&entry)) { + if (B_OK == path.GetParent(&path)) { + chdir(path.Path()); + } + } + } + } + + do { + SDL_Delay(10); + } while ( (be_app == NULL) || be_app->IsLaunching() ); + + /* Mark the application active */ + SDL_BeAppActive = 0; + } + + /* Increment the application reference count */ + ++SDL_BeAppActive; + + /* The app is running, and we're ready to go */ + return(0); +} + +/* Quit the Be Application, if there's nothing left to do */ +void SDL_QuitBeApp(void) +{ + /* Decrement the application reference count */ + --SDL_BeAppActive; + + /* If the reference count reached zero, clean up the app */ + if ( SDL_BeAppActive == 0 ) { + if ( SDL_AppThread != NULL ) { + if ( be_app != NULL ) { /* Not tested */ + be_app->PostMessage(B_QUIT_REQUESTED); + } + SDL_WaitThread(SDL_AppThread, NULL); + SDL_AppThread = NULL; + } + /* be_app should now be NULL since be_app has quit */ + } +} diff --git a/distrib/sdl-1.2.15/src/main/beos/SDL_BeApp.h b/distrib/sdl-1.2.15/src/main/beos/SDL_BeApp.h new file mode 100644 index 0000000..9f88212 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/beos/SDL_BeApp.h @@ -0,0 +1,33 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* Handle the BeApp specific portions of the application */ + +/* Initialize the Be Application, if it's not already started */ +extern int SDL_InitBeApp(void); + +/* Quit the Be Application, if there's nothing left to do */ +extern void SDL_QuitBeApp(void); + +/* Flag to tell whether the app is active or not */ +extern int SDL_BeAppActive; diff --git a/distrib/sdl-1.2.15/src/main/dummy/SDL_dummy_main.c b/distrib/sdl-1.2.15/src/main/dummy/SDL_dummy_main.c new file mode 100644 index 0000000..da47d06 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/dummy/SDL_dummy_main.c @@ -0,0 +1,13 @@ + +/* Include the SDL main definition header */ +#include "SDL_main.h" + +#ifdef main +#undef main +int main(int argc, char *argv[]) +{ + return(SDL_main(argc, argv)); +} +#else +/* Nothing to do on this platform */ +#endif diff --git a/distrib/sdl-1.2.15/src/main/macos/SDL.r b/distrib/sdl-1.2.15/src/main/macos/SDL.r new file mode 100644 index 0000000..a8fceca --- /dev/null +++ b/distrib/sdl-1.2.15/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/distrib/sdl-1.2.15/src/main/macos/SDL.shlib.r b/distrib/sdl-1.2.15/src/main/macos/SDL.shlib.r new file mode 100644 index 0000000..2523106 --- /dev/null +++ b/distrib/sdl-1.2.15/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/distrib/sdl-1.2.15/src/main/macos/SDL_main.c b/distrib/sdl-1.2.15/src/main/macos/SDL_main.c new file mode 100644 index 0000000..ff1ffdc --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/macos/SDL_main.c @@ -0,0 +1,610 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* This file takes care of command line argument parsing, and stdio redirection + in the MacOS environment. (stdio/stderr is *not* directed for Mach-O builds) + */ + +#if defined(__APPLE__) && defined(__MACH__) +#include +#elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) +#include +#else +#include +#include +#include +#include +#include +#endif + +/* Include the SDL main definition header */ +#include "SDL.h" +#include "SDL_main.h" +#ifdef main +#undef main +#endif + +#if !(defined(__APPLE__) && defined(__MACH__)) +/* The standard output files */ +#define STDOUT_FILE "stdout.txt" +#define STDERR_FILE "stderr.txt" +#endif + +#if !defined(__MWERKS__) && !TARGET_API_MAC_CARBON + /* In MPW, the qd global has been removed from the libraries */ + QDGlobals qd; +#endif + +/* Structure for keeping prefs in 1 variable */ +typedef struct { + Str255 command_line; + Str255 video_driver_name; + Boolean output_to_file; +} PrefsRecord; + +/* See if the command key is held down at startup */ +static Boolean CommandKeyIsDown(void) +{ + KeyMap theKeyMap; + + GetKeys(theKeyMap); + + if (((unsigned char *) theKeyMap)[6] & 0x80) { + return(true); + } + return(false); +} + +#if !(defined(__APPLE__) && defined(__MACH__)) + +/* Parse a command line buffer into arguments */ +static int ParseCommandLine(char *cmdline, char **argv) +{ + char *bufp; + int argc; + + argc = 0; + for ( bufp = cmdline; *bufp; ) { + /* Skip leading whitespace */ + while ( SDL_isspace(*bufp) ) { + ++bufp; + } + /* Skip over argument */ + if ( *bufp == '"' ) { + ++bufp; + if ( *bufp ) { + if ( argv ) { + argv[argc] = bufp; + } + ++argc; + } + /* Skip over word */ + while ( *bufp && (*bufp != '"') ) { + ++bufp; + } + } else { + if ( *bufp ) { + if ( argv ) { + argv[argc] = bufp; + } + ++argc; + } + /* Skip over word */ + while ( *bufp && ! SDL_isspace(*bufp) ) { + ++bufp; + } + } + if ( *bufp ) { + if ( argv ) { + *bufp = '\0'; + } + ++bufp; + } + } + if ( argv ) { + argv[argc] = NULL; + } + return(argc); +} + +/* Remove the output files if there was no output written */ +static void cleanup_output(void) +{ + FILE *file; + int empty; + + /* Flush the output in case anything is queued */ + fclose(stdout); + fclose(stderr); + + /* See if the files have any output in them */ + file = fopen(STDOUT_FILE, "rb"); + if ( file ) { + empty = (fgetc(file) == EOF) ? 1 : 0; + fclose(file); + if ( empty ) { + remove(STDOUT_FILE); + } + } + file = fopen(STDERR_FILE, "rb"); + if ( file ) { + empty = (fgetc(file) == EOF) ? 1 : 0; + fclose(file); + if ( empty ) { + remove(STDERR_FILE); + } + } +} + +#endif //!(defined(__APPLE__) && defined(__MACH__)) + +static int getCurrentAppName (StrFileName name) { + + ProcessSerialNumber process; + ProcessInfoRec process_info; + FSSpec process_fsp; + + process.highLongOfPSN = 0; + process.lowLongOfPSN = kCurrentProcess; + process_info.processInfoLength = sizeof (process_info); + process_info.processName = NULL; + process_info.processAppSpec = &process_fsp; + + if ( noErr != GetProcessInformation (&process, &process_info) ) + return 0; + + SDL_memcpy(name, process_fsp.name, process_fsp.name[0] + 1); + return 1; +} + +static int getPrefsFile (FSSpec *prefs_fsp, int create) { + + /* The prefs file name is the application name, possibly truncated, */ + /* plus " Preferences */ + + #define SUFFIX " Preferences" + #define MAX_NAME 19 /* 31 - strlen (SUFFIX) */ + + short volume_ref_number; + long directory_id; + StrFileName prefs_name; + StrFileName app_name; + + /* Get Preferences folder - works with Multiple Users */ + if ( noErr != FindFolder ( kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, + &volume_ref_number, &directory_id) ) + exit (-1); + + if ( ! getCurrentAppName (app_name) ) + exit (-1); + + /* Truncate if name is too long */ + if (app_name[0] > MAX_NAME ) + app_name[0] = MAX_NAME; + + SDL_memcpy(prefs_name + 1, app_name + 1, app_name[0]); + SDL_memcpy(prefs_name + app_name[0] + 1, SUFFIX, strlen (SUFFIX)); + prefs_name[0] = app_name[0] + strlen (SUFFIX); + + /* Make the file spec for prefs file */ + if ( noErr != FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp) ) { + if ( !create ) + return 0; + else { + /* Create the prefs file */ + SDL_memcpy(prefs_fsp->name, prefs_name, prefs_name[0] + 1); + prefs_fsp->parID = directory_id; + prefs_fsp->vRefNum = volume_ref_number; + + FSpCreateResFile (prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph + + if ( noErr != ResError () ) + return 0; + } + } + return 1; +} + +static int readPrefsResource (PrefsRecord *prefs) { + + Handle prefs_handle; + + prefs_handle = Get1Resource( 'CLne', 128 ); + + if (prefs_handle != NULL) { + int offset = 0; +// int j = 0; + + HLock(prefs_handle); + + /* Get command line string */ + SDL_memcpy(prefs->command_line, *prefs_handle, (*prefs_handle)[0]+1); + + /* Get video driver name */ + offset += (*prefs_handle)[0] + 1; + SDL_memcpy(prefs->video_driver_name, *prefs_handle + offset, (*prefs_handle)[offset] + 1); + + /* Get save-to-file option (1 or 0) */ + offset += (*prefs_handle)[offset] + 1; + prefs->output_to_file = (*prefs_handle)[offset]; + + ReleaseResource( prefs_handle ); + + return ResError() == noErr; + } + + return 0; +} + +static int writePrefsResource (PrefsRecord *prefs, short resource_file) { + + Handle prefs_handle; + + UseResFile (resource_file); + + prefs_handle = Get1Resource ( 'CLne', 128 ); + if (prefs_handle != NULL) + RemoveResource (prefs_handle); + + prefs_handle = NewHandle ( prefs->command_line[0] + prefs->video_driver_name[0] + 4 ); + if (prefs_handle != NULL) { + + int offset; + + HLock (prefs_handle); + + /* Command line text */ + offset = 0; + SDL_memcpy(*prefs_handle, prefs->command_line, prefs->command_line[0] + 1); + + /* Video driver name */ + offset += prefs->command_line[0] + 1; + SDL_memcpy(*prefs_handle + offset, prefs->video_driver_name, prefs->video_driver_name[0] + 1); + + /* Output-to-file option */ + offset += prefs->video_driver_name[0] + 1; + *( *((char**)prefs_handle) + offset) = (char)prefs->output_to_file; + *( *((char**)prefs_handle) + offset + 1) = 0; + + AddResource (prefs_handle, 'CLne', 128, "\pCommand Line"); + WriteResource (prefs_handle); + UpdateResFile (resource_file); + DisposeHandle (prefs_handle); + + return ResError() == noErr; + } + + return 0; +} + +static int readPreferences (PrefsRecord *prefs) { + + int no_error = 1; + FSSpec prefs_fsp; + + /* Check for prefs file first */ + if ( getPrefsFile (&prefs_fsp, 0) ) { + + short prefs_resource; + + prefs_resource = FSpOpenResFile (&prefs_fsp, fsRdPerm); + if ( prefs_resource == -1 ) /* this shouldn't happen, but... */ + return 0; + + UseResFile (prefs_resource); + no_error = readPrefsResource (prefs); + CloseResFile (prefs_resource); + } + + /* Fall back to application's resource fork (reading only, so this is safe) */ + else { + + no_error = readPrefsResource (prefs); + } + + return no_error; +} + +static int writePreferences (PrefsRecord *prefs) { + + int no_error = 1; + FSSpec prefs_fsp; + + /* Get prefs file, create if it doesn't exist */ + if ( getPrefsFile (&prefs_fsp, 1) ) { + + short prefs_resource; + + prefs_resource = FSpOpenResFile (&prefs_fsp, fsRdWrPerm); + if (prefs_resource == -1) + return 0; + no_error = writePrefsResource (prefs, prefs_resource); + CloseResFile (prefs_resource); + } + + return no_error; +} + +/* This is where execution begins */ +int main(int argc, char *argv[]) +{ + +#if !(defined(__APPLE__) && defined(__MACH__)) +#pragma unused(argc, argv) +#endif + +#define DEFAULT_ARGS "\p" /* pascal string for default args */ +#define DEFAULT_VIDEO_DRIVER "\ptoolbox" /* pascal string for default video driver name */ +#define DEFAULT_OUTPUT_TO_FILE 1 /* 1 == output to file, 0 == no output */ + +#define VIDEO_ID_DRAWSPROCKET 1 /* these correspond to popup menu choices */ +#define VIDEO_ID_TOOLBOX 2 + + PrefsRecord prefs = { DEFAULT_ARGS, DEFAULT_VIDEO_DRIVER, DEFAULT_OUTPUT_TO_FILE }; + +#if !(defined(__APPLE__) && defined(__MACH__)) + int nargs; + char **args; + char *commandLine; + + StrFileName appNameText; +#endif + int videodriver = VIDEO_ID_TOOLBOX; + int settingsChanged = 0; + + long i; + + /* Kyle's SDL command-line dialog code ... */ +#if !TARGET_API_MAC_CARBON + InitGraf (&qd.thePort); + InitFonts (); + InitWindows (); + InitMenus (); + InitDialogs (nil); +#endif + InitCursor (); + FlushEvents(everyEvent,0); +#if !TARGET_API_MAC_CARBON + MaxApplZone (); +#endif + MoreMasters (); + MoreMasters (); +#if 0 + /* Intialize SDL, and put up a dialog if we fail */ + if ( SDL_Init (0) < 0 ) { + +#define kErr_OK 1 +#define kErr_Text 2 + + DialogPtr errorDialog; + short dummyType; + Rect dummyRect; + Handle dummyHandle; + short itemHit; + + errorDialog = GetNewDialog (1001, nil, (WindowPtr)-1); + if (errorDialog == NULL) + return -1; + DrawDialog (errorDialog); + + GetDialogItem (errorDialog, kErr_Text, &dummyType, &dummyHandle, &dummyRect); + SetDialogItemText (dummyHandle, "\pError Initializing SDL"); + +#if TARGET_API_MAC_CARBON + SetPort (GetDialogPort(errorDialog)); +#else + SetPort (errorDialog); +#endif + do { + ModalDialog (nil, &itemHit); + } while (itemHit != kErr_OK); + + DisposeDialog (errorDialog); + exit (-1); + } + atexit(cleanup_output); + atexit(SDL_Quit); +#endif + +/* Set up SDL's QuickDraw environment */ +#if !TARGET_API_MAC_CARBON + SDL_InitQuickDraw(&qd); +#endif + + if ( readPreferences (&prefs) ) { + + if (SDL_memcmp(prefs.video_driver_name+1, "DSp", 3) == 0) + videodriver = 1; + else if (SDL_memcmp(prefs.video_driver_name+1, "toolbox", 7) == 0) + videodriver = 2; + } + + if ( CommandKeyIsDown() ) { + +#define kCL_OK 1 +#define kCL_Cancel 2 +#define kCL_Text 3 +#define kCL_File 4 +#define kCL_Video 6 + + DialogPtr commandDialog; + short dummyType; + Rect dummyRect; + Handle dummyHandle; + short itemHit; + #if TARGET_API_MAC_CARBON + ControlRef control; + #endif + + /* Assume that they will change settings, rather than do exhaustive check */ + settingsChanged = 1; + + /* Create dialog and display it */ + commandDialog = GetNewDialog (1000, nil, (WindowPtr)-1); + #if TARGET_API_MAC_CARBON + SetPort ( GetDialogPort(commandDialog) ); + #else + SetPort (commandDialog); + #endif + + /* Setup controls */ + #if TARGET_API_MAC_CARBON + GetDialogItemAsControl(commandDialog, kCL_File, &control); + SetControlValue (control, prefs.output_to_file); + #else + GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ + SetControlValue ((ControlHandle)dummyHandle, prefs.output_to_file ); + #endif + + GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); + SetDialogItemText (dummyHandle, prefs.command_line); + + #if TARGET_API_MAC_CARBON + GetDialogItemAsControl(commandDialog, kCL_Video, &control); + SetControlValue (control, videodriver); + #else + GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); + SetControlValue ((ControlRef)dummyHandle, videodriver); + #endif + + SetDialogDefaultItem (commandDialog, kCL_OK); + SetDialogCancelItem (commandDialog, kCL_Cancel); + + do { + + ModalDialog(nil, &itemHit); /* wait for user response */ + + /* Toggle command-line output checkbox */ + if ( itemHit == kCL_File ) { + #if TARGET_API_MAC_CARBON + GetDialogItemAsControl(commandDialog, kCL_File, &control); + SetControlValue (control, !GetControlValue(control)); + #else + GetDialogItem(commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ + SetControlValue((ControlHandle)dummyHandle, !GetControlValue((ControlHandle)dummyHandle) ); + #endif + } + + } while (itemHit != kCL_OK && itemHit != kCL_Cancel); + + /* Get control values, even if they did not change */ + GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); /* MJS */ + GetDialogItemText (dummyHandle, prefs.command_line); + + #if TARGET_API_MAC_CARBON + GetDialogItemAsControl(commandDialog, kCL_File, &control); + prefs.output_to_file = GetControlValue(control); + #else + GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ + prefs.output_to_file = GetControlValue ((ControlHandle)dummyHandle); + #endif + + #if TARGET_API_MAC_CARBON + GetDialogItemAsControl(commandDialog, kCL_Video, &control); + videodriver = GetControlValue(control); + #else + GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); + videodriver = GetControlValue ((ControlRef)dummyHandle); + #endif + + DisposeDialog (commandDialog); + + if (itemHit == kCL_Cancel ) { + exit (0); + } + } + + /* Set pseudo-environment variables for video driver, update prefs */ + switch ( videodriver ) { + case VIDEO_ID_DRAWSPROCKET: + SDL_putenv("SDL_VIDEODRIVER=DSp"); + SDL_memcpy(prefs.video_driver_name, "\pDSp", 4); + break; + case VIDEO_ID_TOOLBOX: + SDL_putenv("SDL_VIDEODRIVER=toolbox"); + SDL_memcpy(prefs.video_driver_name, "\ptoolbox", 8); + break; + } + +#if !(defined(__APPLE__) && defined(__MACH__)) + /* Redirect standard I/O to files */ + if ( prefs.output_to_file ) { + freopen (STDOUT_FILE, "w", stdout); + freopen (STDERR_FILE, "w", stderr); + } else { + fclose (stdout); + fclose (stderr); + } +#endif + + if (settingsChanged) { + /* Save the prefs, even if they might not have changed (but probably did) */ + if ( ! writePreferences (&prefs) ) + fprintf (stderr, "WARNING: Could not save preferences!\n"); + } + +#if !(defined(__APPLE__) && defined(__MACH__)) + appNameText[0] = 0; + getCurrentAppName (appNameText); /* check for error here ? */ + + commandLine = (char*) malloc (appNameText[0] + prefs.command_line[0] + 2); + if ( commandLine == NULL ) { + exit(-1); + } + + /* Rather than rewrite ParseCommandLine method, let's replace */ + /* any spaces in application name with underscores, */ + /* so that the app name is only 1 argument */ + for (i = 1; i < 1+appNameText[0]; i++) + if ( appNameText[i] == ' ' ) appNameText[i] = '_'; + + /* Copy app name & full command text to command-line C-string */ + SDL_memcpy(commandLine, appNameText + 1, appNameText[0]); + commandLine[appNameText[0]] = ' '; + SDL_memcpy(commandLine + appNameText[0] + 1, prefs.command_line + 1, prefs.command_line[0]); + commandLine[ appNameText[0] + 1 + prefs.command_line[0] ] = '\0'; + + /* Parse C-string into argv and argc */ + nargs = ParseCommandLine (commandLine, NULL); + args = (char **)malloc((nargs+1)*(sizeof *args)); + if ( args == NULL ) { + exit(-1); + } + ParseCommandLine (commandLine, args); + + /* Run the main application code */ + SDL_main(nargs, args); + free (args); + free (commandLine); + + /* Remove useless stdout.txt and stderr.txt */ + cleanup_output (); +#else // defined(__APPLE__) && defined(__MACH__) + SDL_main(argc, argv); +#endif + + /* Exit cleanly, calling atexit() functions */ + exit (0); + + /* Never reached, but keeps the compiler quiet */ + return (0); +} diff --git a/distrib/sdl-1.2.15/src/main/macos/SIZE.r b/distrib/sdl-1.2.15/src/main/macos/SIZE.r new file mode 100644 index 0000000..fe63e19 --- /dev/null +++ b/distrib/sdl-1.2.15/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/distrib/sdl-1.2.15/src/main/macos/exports/Makefile b/distrib/sdl-1.2.15/src/main/macos/exports/Makefile new file mode 100644 index 0000000..5f37ae0 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/macos/exports/Makefile @@ -0,0 +1,39 @@ + +EXPORTS = SDL.x +HEADERS = \ + ../../../../include/SDL.h \ + ../../../../include/SDL_active.h \ + ../../../../include/SDL_audio.h \ + ../../../../include/SDL_byteorder.h \ + ../../../../include/SDL_cdrom.h \ + ../../../../include/SDL_copying.h \ + ../../../../include/SDL_cpuinfo.h \ + ../../../../include/SDL_endian.h \ + ../../../../include/SDL_error.h \ + ../../../../include/SDL_events.h \ + ../../../../include/SDL_getenv.h \ + ../../../../include/SDL_joystick.h \ + ../../../../include/SDL_keyboard.h \ + ../../../../include/SDL_keysym.h \ + ../../../../include/SDL_loadso.h \ + ../../../../include/SDL_mouse.h \ + ../../../../include/SDL_mutex.h \ + ../../../../include/SDL_name.h \ + ../../../../include/SDL_platform.h \ + ../../../../include/SDL_quit.h \ + ../../../../include/SDL_rwops.h \ + ../../../../include/SDL_syswm.h \ + ../../../../include/SDL_thread.h \ + ../../../../include/SDL_timer.h \ + ../../../../include/SDL_types.h \ + ../../../../include/SDL_version.h \ + ../../../../include/SDL_video.h + + +all: $(EXPORTS) + +$(EXPORTS): Makefile gendef.pl $(HEADERS) + perl gendef.pl $(HEADERS) >$@ || rm $@ + +clean: + rm -f $(EXPORTS) diff --git a/distrib/sdl-1.2.15/src/main/macos/exports/SDL.x b/distrib/sdl-1.2.15/src/main/macos/exports/SDL.x new file mode 100644 index 0000000..ce9e96e --- /dev/null +++ b/distrib/sdl-1.2.15/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/distrib/sdl-1.2.15/src/main/macos/exports/gendef.pl b/distrib/sdl-1.2.15/src/main/macos/exports/gendef.pl new file mode 100644 index 0000000..9cffca9 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/macos/exports/gendef.pl @@ -0,0 +1,43 @@ +#!/usr/bin/perl +# +# Program to take a set of header files and generate DLL export definitions + +# Special exports to ignore for this platform + +while ( ($file = shift(@ARGV)) ) { + if ( ! defined(open(FILE, $file)) ) { + warn "Couldn't open $file: $!\n"; + next; + } + $printed_header = 0; + $file =~ s,.*/,,; + while () { + if ( / DECLSPEC.* SDLCALL ([^\s\(]+)/ ) { + if ( not $exclude{$1} ) { + print "\t$1\r"; + } + } + } + close(FILE); +} + +# Special exports to include for this platform +print "\tSDL_putenv\r"; +print "\tSDL_getenv\r"; +print "\tSDL_qsort\r"; +print "\tSDL_revcpy\r"; +print "\tSDL_strlcpy\r"; +print "\tSDL_strlcat\r"; +print "\tSDL_strdup\r"; +print "\tSDL_strrev\r"; +print "\tSDL_strupr\r"; +print "\tSDL_strlwr\r"; +print "\tSDL_ltoa\r"; +print "\tSDL_ultoa\r"; +print "\tSDL_strcasecmp\r"; +print "\tSDL_strncasecmp\r"; +print "\tSDL_snprintf\r"; +print "\tSDL_vsnprintf\r"; +print "\tSDL_iconv\r"; +print "\tSDL_iconv_string\r"; +print "\tSDL_InitQuickDraw\r"; diff --git a/distrib/sdl-1.2.15/src/main/macosx/Info.plist.in b/distrib/sdl-1.2.15/src/main/macosx/Info.plist.in new file mode 100644 index 0000000..b3d69ab --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/macosx/Info.plist.in @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + @EXECUTABLE_NAME@ + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + @PACKAGE@ + CFBundlePackageType + APPL + CFBundleShortVersionString + @VERSION@ + CFBundleSignature + ???? + NSMainNibFile + SDLMain.nib + NSPrincipalClass + NSApplication + + diff --git a/distrib/sdl-1.2.15/src/main/macosx/SDLMain.h b/distrib/sdl-1.2.15/src/main/macosx/SDLMain.h new file mode 100644 index 0000000..c56d90c --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/macosx/SDLMain.h @@ -0,0 +1,16 @@ +/* SDLMain.m - main entry point for our Cocoa-ized SDL app + Initial Version: Darrell Walisser + Non-NIB-Code & other changes: Max Horn + + Feel free to customize this file to suit your needs +*/ + +#ifndef _SDLMain_h_ +#define _SDLMain_h_ + +#import + +@interface SDLMain : NSObject +@end + +#endif /* _SDLMain_h_ */ diff --git a/distrib/sdl-1.2.15/src/main/macosx/SDLMain.m b/distrib/sdl-1.2.15/src/main/macosx/SDLMain.m new file mode 100644 index 0000000..2434f81 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/macosx/SDLMain.m @@ -0,0 +1,381 @@ +/* SDLMain.m - main entry point for our Cocoa-ized SDL app + Initial Version: Darrell Walisser + Non-NIB-Code & other changes: Max Horn + + Feel free to customize this file to suit your needs +*/ + +#include "SDL.h" +#include "SDLMain.h" +#include /* for MAXPATHLEN */ +#include + +/* For some reaon, Apple removed setAppleMenu from the headers in 10.4, + but the method still is there and works. To avoid warnings, we declare + it ourselves here. */ +@interface NSApplication(SDL_Missing_Methods) +- (void)setAppleMenu:(NSMenu *)menu; +@end + +/* Use this flag to determine whether we use SDLMain.nib or not */ +#define SDL_USE_NIB_FILE 0 + +/* Use this flag to determine whether we use CPS (docking) or not */ +#define SDL_USE_CPS 1 +#ifdef SDL_USE_CPS +/* Portions of CPS.h */ +typedef struct CPSProcessSerNum +{ + UInt32 lo; + UInt32 hi; +} CPSProcessSerNum; + +extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn); +extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); +extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn); + +#endif /* SDL_USE_CPS */ + +static int gArgc; +static char **gArgv; +static BOOL gFinderLaunch; +static BOOL gCalledAppMainline = FALSE; + +static NSString *getApplicationName(void) +{ + const NSDictionary *dict; + NSString *appName = 0; + + /* Determine the application name */ + dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); + if (dict) + appName = [dict objectForKey: @"CFBundleName"]; + + if (![appName length]) + appName = [[NSProcessInfo processInfo] processName]; + + return appName; +} + +#if SDL_USE_NIB_FILE +/* A helper category for NSString */ +@interface NSString (ReplaceSubString) +- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; +@end +#endif + +@interface NSApplication (SDLApplication) +@end + +@implementation NSApplication (SDLApplication) +/* Invoked from the Quit menu item */ +- (void)terminate:(id)sender +{ + /* Post a SDL_QUIT event */ + SDL_Event event; + event.type = SDL_QUIT; + SDL_PushEvent(&event); +} +@end + +/* The main class of the application, the application's delegate */ +@implementation SDLMain + +/* Set the working directory to the .app's parent directory */ +- (void) setupWorkingDirectory:(BOOL)shouldChdir +{ + if (shouldChdir) + { + char parentdir[MAXPATHLEN]; + CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); + if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) { + chdir(parentdir); /* chdir to the binary app's parent */ + } + CFRelease(url); + CFRelease(url2); + } +} + +#if SDL_USE_NIB_FILE + +/* Fix menu to contain the real app name instead of "SDL App" */ +- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName +{ + NSRange aRange; + NSEnumerator *enumerator; + NSMenuItem *menuItem; + + aRange = [[aMenu title] rangeOfString:@"SDL App"]; + if (aRange.length != 0) + [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]]; + + enumerator = [[aMenu itemArray] objectEnumerator]; + while ((menuItem = [enumerator nextObject])) + { + aRange = [[menuItem title] rangeOfString:@"SDL App"]; + if (aRange.length != 0) + [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]]; + if ([menuItem hasSubmenu]) + [self fixMenu:[menuItem submenu] withAppName:appName]; + } +} + +#else + +static void setApplicationMenu(void) +{ + /* warning: this code is very odd */ + NSMenu *appleMenu; + NSMenuItem *menuItem; + NSString *title; + NSString *appName; + + appName = getApplicationName(); + appleMenu = [[NSMenu alloc] initWithTitle:@""]; + + /* Add menu items */ + title = [@"About " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; + + [appleMenu addItem:[NSMenuItem separatorItem]]; + + title = [@"Hide " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; + + menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; + [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; + + [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; + + [appleMenu addItem:[NSMenuItem separatorItem]]; + + title = [@"Quit " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; + + + /* Put menu into the menubar */ + menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; + [menuItem setSubmenu:appleMenu]; + [[NSApp mainMenu] addItem:menuItem]; + + /* Tell the application object that this is now the application menu */ + [NSApp setAppleMenu:appleMenu]; + + /* Finally give up our references to the objects */ + [appleMenu release]; + [menuItem release]; +} + +/* Create a window menu */ +static void setupWindowMenu(void) +{ + NSMenu *windowMenu; + NSMenuItem *windowMenuItem; + NSMenuItem *menuItem; + + windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; + + /* "Minimize" item */ + menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; + [windowMenu addItem:menuItem]; + [menuItem release]; + + /* Put menu into the menubar */ + windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; + [windowMenuItem setSubmenu:windowMenu]; + [[NSApp mainMenu] addItem:windowMenuItem]; + + /* Tell the application object that this is now the window menu */ + [NSApp setWindowsMenu:windowMenu]; + + /* Finally give up our references to the objects */ + [windowMenu release]; + [windowMenuItem release]; +} + +/* Replacement for NSApplicationMain */ +static void CustomApplicationMain (int argc, char **argv) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + SDLMain *sdlMain; + + /* Ensure the application object is initialised */ + [NSApplication sharedApplication]; + +#ifdef SDL_USE_CPS + { + CPSProcessSerNum PSN; + /* Tell the dock about us */ + if (!CPSGetCurrentProcess(&PSN)) + if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103)) + if (!CPSSetFrontProcess(&PSN)) + [NSApplication sharedApplication]; + } +#endif /* SDL_USE_CPS */ + + /* Set up the menubar */ + [NSApp setMainMenu:[[NSMenu alloc] init]]; + setApplicationMenu(); + setupWindowMenu(); + + /* Create SDLMain and make it the app delegate */ + sdlMain = [[SDLMain alloc] init]; + [NSApp setDelegate:sdlMain]; + + /* Start the main event loop */ + [NSApp run]; + + [sdlMain release]; + [pool release]; +} + +#endif + + +/* + * Catch document open requests...this lets us notice files when the app + * was launched by double-clicking a document, or when a document was + * dragged/dropped on the app's icon. You need to have a + * CFBundleDocumentsType section in your Info.plist to get this message, + * apparently. + * + * Files are added to gArgv, so to the app, they'll look like command line + * arguments. Previously, apps launched from the finder had nothing but + * an argv[0]. + * + * This message may be received multiple times to open several docs on launch. + * + * This message is ignored once the app's mainline has been called. + */ +- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename +{ + const char *temparg; + size_t arglen; + char *arg; + char **newargv; + + if (!gFinderLaunch) /* MacOS is passing command line args. */ + return FALSE; + + if (gCalledAppMainline) /* app has started, ignore this document. */ + return FALSE; + + temparg = [filename UTF8String]; + arglen = SDL_strlen(temparg) + 1; + arg = (char *) SDL_malloc(arglen); + if (arg == NULL) + return FALSE; + + newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2)); + if (newargv == NULL) + { + SDL_free(arg); + return FALSE; + } + gArgv = newargv; + + SDL_strlcpy(arg, temparg, arglen); + gArgv[gArgc++] = arg; + gArgv[gArgc] = NULL; + return TRUE; +} + + +/* Called when the internal event loop has just started running */ +- (void) applicationDidFinishLaunching: (NSNotification *) note +{ + int status; + + /* Set the working directory to the .app's parent directory */ + [self setupWorkingDirectory:gFinderLaunch]; + +#if SDL_USE_NIB_FILE + /* Set the main menu to contain the real app name instead of "SDL App" */ + [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()]; +#endif + + /* Hand off to main application code */ + gCalledAppMainline = TRUE; + status = SDL_main (gArgc, gArgv); + + /* We're done, thank you for playing */ + exit(status); +} +@end + + +@implementation NSString (ReplaceSubString) + +- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString +{ + unsigned int bufferSize; + unsigned int selfLen = [self length]; + unsigned int aStringLen = [aString length]; + unichar *buffer; + NSRange localRange; + NSString *result; + + bufferSize = selfLen + aStringLen - aRange.length; + buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar)); + + /* Get first part into buffer */ + localRange.location = 0; + localRange.length = aRange.location; + [self getCharacters:buffer range:localRange]; + + /* Get middle part into buffer */ + localRange.location = 0; + localRange.length = aStringLen; + [aString getCharacters:(buffer+aRange.location) range:localRange]; + + /* Get last part into buffer */ + localRange.location = aRange.location + aRange.length; + localRange.length = selfLen - localRange.location; + [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange]; + + /* Build output string */ + result = [NSString stringWithCharacters:buffer length:bufferSize]; + + NSDeallocateMemoryPages(buffer, bufferSize); + + return result; +} + +@end + + + +#ifdef main +# undef main +#endif + + +/* Main entry point to executable - should *not* be SDL_main! */ +int main (int argc, char **argv) +{ + /* Copy the arguments into a global variable */ + /* This is passed if we are launched by double-clicking */ + if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + gArgv = (char **) SDL_malloc(sizeof (char *) * 2); + gArgv[0] = argv[0]; + gArgv[1] = NULL; + gArgc = 1; + gFinderLaunch = YES; + } else { + int i; + gArgc = argc; + gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1)); + for (i = 0; i <= argc; i++) + gArgv[i] = argv[i]; + gFinderLaunch = NO; + } + +#if SDL_USE_NIB_FILE + NSApplicationMain (argc, argv); +#else + CustomApplicationMain (argc, argv); +#endif + return 0; +} + diff --git a/distrib/sdl-1.2.15/src/main/macosx/SDLMain.nib/classes.nib b/distrib/sdl-1.2.15/src/main/macosx/SDLMain.nib/classes.nib new file mode 100644 index 0000000..f8f4e9a --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/macosx/SDLMain.nib/classes.nib @@ -0,0 +1,12 @@ +{ + IBClasses = ( + {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, + { + ACTIONS = {makeFullscreen = id; quit = id; }; + CLASS = SDLMain; + LANGUAGE = ObjC; + SUPERCLASS = NSObject; + } + ); + IBVersion = 1; +} diff --git a/distrib/sdl-1.2.15/src/main/macosx/SDLMain.nib/info.nib b/distrib/sdl-1.2.15/src/main/macosx/SDLMain.nib/info.nib new file mode 100644 index 0000000..2211cf9 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/macosx/SDLMain.nib/info.nib @@ -0,0 +1,12 @@ + + + + + IBDocumentLocation + 49 97 356 240 0 0 987 746 + IBMainMenuLocation + 20 515 195 44 0 46 800 532 + IBUserGuides + + + diff --git a/distrib/sdl-1.2.15/src/main/macosx/SDLMain.nib/objects.nib b/distrib/sdl-1.2.15/src/main/macosx/SDLMain.nib/objects.nib new file mode 100644 index 0000000..9f697b0 Binary files /dev/null and b/distrib/sdl-1.2.15/src/main/macosx/SDLMain.nib/objects.nib differ diff --git a/distrib/sdl-1.2.15/src/main/macosx/info.nib b/distrib/sdl-1.2.15/src/main/macosx/info.nib new file mode 100644 index 0000000..d13726f --- /dev/null +++ b/distrib/sdl-1.2.15/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/distrib/sdl-1.2.15/src/main/qtopia/SDL_qtopia_main.cc b/distrib/sdl-1.2.15/src/main/qtopia/SDL_qtopia_main.cc new file mode 100644 index 0000000..46fd518 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/qtopia/SDL_qtopia_main.cc @@ -0,0 +1,47 @@ + +/* Include the SDL main definition header */ +#include "SDL_main.h" +#include +#include +#ifdef main +#undef main +#endif +#ifdef QWS +#include +#include +#include +#include + +// Workaround for OPIE to remove taskbar icon. Also fixes +// some issues in Qtopia where there are left-over qcop files in /tmp/. +// I'm guessing this will also clean up the taskbar in the Sharp version +// of Qtopia. +static inline void cleanupQCop() { + QString appname(qApp->argv()[0]); + int slash = appname.findRev("/"); + if(slash != -1) { appname = appname.mid(slash+1); } + QString cmd = QPEApplication::qpeDir() + "bin/qcop QPE/System 'closing(QString)' '"+appname+"'"; + system(cmd.latin1()); + cmd = "/tmp/qcop-msg-"+appname; + unlink(cmd.latin1()); +} + +static QPEApplication *app; +#endif + +extern int SDL_main(int argc, char *argv[]); + +int main(int argc, char *argv[]) +{ +#ifdef QWS + // This initializes the Qtopia application. It needs to be done here + // because it parses command line options. + app = new QPEApplication(argc, argv); + QWidget dummy; + app->showMainWidget(&dummy); + atexit(cleanupQCop); +#endif + // Exit here because if return is used, the application + // doesn't seem to quit correctly. + exit(SDL_main(argc, argv)); +} diff --git a/distrib/sdl-1.2.15/src/main/symbian/EKA1/SDL_main.cpp b/distrib/sdl-1.2.15/src/main/symbian/EKA1/SDL_main.cpp new file mode 100644 index 0000000..683db87 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/symbian/EKA1/SDL_main.cpp @@ -0,0 +1,152 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +/* + SDL_main.cpp + The Epoc executable startup functions + + Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi) +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SDL_error.h" + +#if defined(__WINS__) +#include +IMPORT_C void RegisterWsExe(const TDesC &aName); +#endif + +/* The prototype for the application's main() function */ +#define main SDL_main +extern "C" int main (int argc, char *argv[], char *envp[]); +extern "C" void exit (int ret); + + +/* Epoc main function */ + +#ifdef __WINS__ + + +void GetCmdLine(int& aArgc, char**& aArgv) + { + RChunk chunk; + + if(chunk.OpenGlobal(RThread().Name(), ETrue) != KErrNone) + return; + + TUint* ptr = (TUint*) chunk.Base(); + if(ptr != NULL) + { + aArgc = (int) *(ptr); // count + aArgv = (char**) *(ptr + 1); + } + chunk.Close(); + } + +#endif + + +TInt E32Main() + { + /* Get the clean-up stack */ + CTrapCleanup* cleanup = CTrapCleanup::New(); + + /* Arrange for multi-threaded operation */ + SpawnPosixServerThread(); + + /* Get args and environment */ + int argc=0; + char** argv=0; + char** envp=0; + +#ifndef __WINS__ + __crt0(argc,argv,envp); +#else + GetCmdLine(argc, argv); +#endif + /* Start the application! */ + + /* Create stdlib */ + _REENT; + + /* Set process and thread priority and name */ + + RThread currentThread; + RProcess thisProcess; + TParse exeName; + exeName.Set(thisProcess.FileName(), NULL, NULL); + currentThread.Rename(exeName.Name()); + currentThread.SetProcessPriority(EPriorityLow); + currentThread.SetPriority(EPriorityMuchLess); + + /* Call stdlib main */ + int ret = main(argc, argv, envp); /* !! process exits here if there is "exit()" in main! */ + + /* Call exit */ + //exit(ret); /* !! process exits here! */ + //Markus: I do not understand above + //I commented it at let this function + //to return ret value - was it purpose + //that cleanup below is not called at all - why? + + /* Free resources and return */ + + _cleanup(); //this is normally called at exit, I call it here, Markus + + CloseSTDLIB(); + delete cleanup; +#ifdef __WINS__ +// User::Panic(_L("exit"), ret); + // RThread().Kill(ret); //Markus get rid of this thread + // RThread().RaiseException(EExcKill); +#endif + return ret;//Markus, or exit(ret); ?? + //return(KErrNone); + } + + +#ifdef __WINS__ +EXPORT_C TInt WinsMain() + { + return E32Main(); + // return WinsMain(0, 0, 0); + } +#endif + +/* Epoc dll entry point */ +#if defined(__WINS__) +GLDEF_C TInt E32Dll(TDllReason) + { + return(KErrNone); + } +#endif + + diff --git a/distrib/sdl-1.2.15/src/main/symbian/EKA2/SDL_main.cpp b/distrib/sdl-1.2.15/src/main/symbian/EKA2/SDL_main.cpp new file mode 100644 index 0000000..3dc69d4 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/symbian/EKA2/SDL_main.cpp @@ -0,0 +1,1035 @@ +/* + SDL_Main.cpp + Symbian OS services for SDL + + Markus Mertama +*/ + + +#include "epoc_sdl.h" + +#include"sdlepocapi.h" +#include +#include +#include +#include + +#include "vectorbuffer.h" +#include +#include +#include +#include "SDL_epocevents_c.h" +#include "SDL_keysym.h" +#include "dsa.h" + + +#ifdef SYMBIANC +#include +#endif + +//Markus Mertama + + +extern SDLKey* KeyMap(); +extern void ResetKeyMap(); + +class CCurrentAppUi; + +//const TUid KSDLUid = { 0xF01F3D69 }; + +NONSHARABLE_CLASS(EnvUtils) + { + public: + static void DisableKeyBlocking(); + static TBool Rendezvous(RThread& aThread, TRequestStatus& aStatus); + }; + +TInt Panic(TInt aErr, TInt aLine) + { + TBuf<64> b; + b.Format(_L("Main at %d"), aLine); + User::Panic(b, aErr); + return 0; + } + + +NONSHARABLE_CLASS(CCurrentAppUi) : public CAknAppUi + { + public: + static CCurrentAppUi* Cast(CEikAppUi* aUi); + void DisableKeyBlocking(); + }; + + +CCurrentAppUi* CCurrentAppUi::Cast(CEikAppUi* aUi) + { + return static_cast(aUi); + } + +void CCurrentAppUi::DisableKeyBlocking() + { + SetKeyBlockMode(ENoKeyBlock); + } + + +class CEventQueue : public CBase, public MEventQueue + { + public: + static CEventQueue* NewL(); + ~CEventQueue(); + public: + TInt Append(const TWsEvent& aEvent); + const TWsEvent& Shift(); + void Lock(); + void Unlock(); + TBool HasData(); + private: + TVector iVector; + RCriticalSection iCS; + }; + + CEventQueue* CEventQueue::NewL() + { + CEventQueue* q = new (ELeave) CEventQueue(); + CleanupStack::PushL(q); + User::LeaveIfError(q->iCS.CreateLocal()); + CleanupStack::Pop(); + return q; + } + +CEventQueue::~CEventQueue() + { + iCS.Close(); + } + +TInt CEventQueue::Append(const TWsEvent& aEvent) + { + iCS.Wait(); + const TInt err = iVector.Append(aEvent); + iCS.Signal(); + return err; + } + + +TBool CEventQueue::HasData() + { + return iVector.Size() > 0; + } + + +void CEventQueue::Lock() + { + iCS.Wait(); + } + +void CEventQueue::Unlock() + { + iCS.Signal(); + } + +const TWsEvent& CEventQueue::Shift() + { + const TWsEvent& event = iVector.Shift(); + return event; + } + + +TSdlCleanupItem::TSdlCleanupItem(TSdlCleanupOperation aOperation, TAny* aItem) : +iOperation(aOperation), iItem(aItem), iThread(RThread().Id()) + { + } + +class CEikonEnv; +class CSdlAppServ; + + +NONSHARABLE_CLASS(EpocSdlEnvData) + { + public: + void Free(); + CEventQueue* iEventQueue; + TMainFunc iMain; + TInt iEpocEnvFlags; + int iArgc; + char** iArgv; + CDsa* iDsa; + CSdlAppServ* iAppSrv; + TThreadId iId; + CArrayFix* iCleanupItems; + CEikAppUi* iAppUi; + CSDL* iSdl; + }; + + +EpocSdlEnvData* gEpocEnv; + +#define MAINFUNC(x) EXPORT_C TMainFunc::TMainFunc(mainfunc##x aFunc){Mem::FillZ(iMainFunc, sizeof(iMainFunc)); iMainFunc[x - 1] = (void*) aFunc;} + +MAINFUNC(1) +MAINFUNC(2) +MAINFUNC(3) +MAINFUNC(4) +MAINFUNC(5) +MAINFUNC(6) + +EXPORT_C TMainFunc::TMainFunc() + { + Mem::FillZ(iMainFunc, sizeof(iMainFunc)); + } + + +const void* TMainFunc::operator[](TInt aIndex) const + { + return iMainFunc[aIndex]; + } + + +NONSHARABLE_CLASS(CSdlAppServ) : public CActive + { + public: + enum + { + EAppSrvNoop = CDsa::ELastDsaRequest, + EAppSrvWindowWidth, + EAppSrvWindowHeight, + EAppSrvWindowDisplayMode, + EAppSrvWindowPointerCursorMode, + EAppSrvDsaStatus, + EAppSrvStopThread, + EAppSrvWaitDsa + }; + CSdlAppServ(); + void ConstructL(); + ~CSdlAppServ(); + TInt Request(TInt aService); + TInt RequestValue(TInt aService); + void Init(); + void PanicMain(TInt aReason); + void PanicMain(const TDesC& aInfo, TInt aReason); + void SetObserver(MSDLObserver* aObserver); + TInt ObserverEvent(TInt aEvent, TInt aParam); + void SetParam(TInt aParam); + void HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread); + MSDLObserver* Observer(); + private: + void RunL(); + void DoCancel(); + private: + const TThreadId iMainId; + RThread iAppThread; + TInt iService; + TInt iReturnValue; + RSemaphore iSema; + MSDLObserver* iObserver; + TRequestStatus* iStatusPtr; + }; + +CSdlAppServ::CSdlAppServ() : CActive(CActive::EPriorityHigh), iMainId(RThread().Id()) + { + } + + + +MSDLObserver* CSdlAppServ::Observer() + { + return iObserver; + } + + +void CSdlAppServ::SetObserver(MSDLObserver* aObserver) + { + iObserver = aObserver; + } + +TInt CSdlAppServ::ObserverEvent(TInt aEvent, TInt aParam) + { + if(iObserver != NULL) + { + if(RThread().Id() == gEpocEnv->iId) + { + return iObserver->SdlThreadEvent(aEvent, aParam); + } + else if(RThread().Id() == iMainId) + { + return iObserver->SdlEvent(aEvent, aParam); + } + PANIC(KErrNotSupported); + } + return 0; + } + +void CSdlAppServ::PanicMain(TInt aReason) + { + iAppThread.Panic(RThread().Name(), aReason); + } + +void CSdlAppServ::PanicMain(const TDesC& aInfo, TInt aReason) + { + iAppThread.Panic(aInfo, aReason); + } + +void CSdlAppServ::ConstructL() + { + CActiveScheduler::Add(this); + User::LeaveIfError(iSema.CreateLocal(1)); + iStatus = KRequestPending; + iStatusPtr = &iStatus; + SetActive(); + } + + CSdlAppServ::~CSdlAppServ() + { + Cancel(); + if(iSema.Handle() != NULL) + iSema.Signal(); + iSema.Close(); + iAppThread.Close(); + } + +TInt CSdlAppServ::Request(TInt aService) + { + if(RThread().Id() != iAppThread.Id()) + { + iSema.Wait(); + iService = aService; + iAppThread.RequestComplete(iStatusPtr, KErrNone); + return KErrNone; + } + return KErrBadHandle; + } + +TInt CSdlAppServ::RequestValue(TInt aService) + { + Request(aService); + Request(EAppSrvNoop); + return iReturnValue; + } + +void CSdlAppServ::Init() + { + PANIC_IF_ERROR(iAppThread.Open(iMainId)); + } + +void CSdlAppServ::SetParam(TInt aParam) + { + iReturnValue = aParam; + } + +void CSdlAppServ::HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread) + { + if(iObserver != NULL && aMainThread) + { + switch(aService) + { + case MSDLObserver::EEventScreenSizeChanged: + if(aReturnValue == MSDLObserver::EScreenSizeChangedDefaultPalette) + EpocSdlEnv::LockPalette(EFalse); + break; + } + } + if(!aMainThread && aService == MSDLObserver::EEventSuspend) + { + if(iObserver == NULL || + (gEpocEnv->iDsa->Stopped() && aReturnValue != MSDLObserver::ESuspendNoSuspend)) + { + EpocSdlEnv::Suspend(); + } + } + } + +void CSdlAppServ::RunL() + { + if(iStatus == KErrNone) + { + switch(iService) + { + case CSdlAppServ::EAppSrvWaitDsa: + EpocSdlEnv::SetWaitDsa(); + iReturnValue = EpocSdlEnv::IsDsaAvailable(); + // } + // gEpocEnv->iDsa->Stop(); + // gEpocEnv->iDsa->RestartL(); + break; + case CSdlAppServ::EAppSrvStopThread: + gEpocEnv->iDsa->SetSuspend(); + break; + case EpocSdlEnv::EDisableKeyBlocking: + EnvUtils::DisableKeyBlocking(); + break; + + case EAppSrvWindowPointerCursorMode: + iReturnValue = gEpocEnv->iDsa != NULL ? + gEpocEnv->iDsa->Session().PointerCursorMode() : KErrNotReady; + break; + case EAppSrvDsaStatus: + gEpocEnv->iDsa->Stop(); + iReturnValue = KErrNone; + break; + case CDsa::ERequestUpdate: + gEpocEnv->iDsa->UnlockHWSurfaceRequestComplete(); + break; + case EAppSrvNoop: + break; + case MSDLObserver::EEventResume: + case MSDLObserver::EEventSuspend: + case MSDLObserver::EEventScreenSizeChanged: + case MSDLObserver::EEventWindowReserved: + case MSDLObserver::EEventKeyMapInit: + case MSDLObserver::EEventWindowNotAvailable: + case MSDLObserver::EEventMainExit: + iReturnValue = ObserverEvent(iService, iReturnValue); + HandleObserverValue(iService, iReturnValue, ETrue); + break; + default: + PANIC(KErrNotSupported); + } + iStatus = KRequestPending; + iStatusPtr = &iStatus; + SetActive(); + } + iSema.Signal(); + } + +void CSdlAppServ::DoCancel() + { + iSema.Wait(); + TRequestStatus* s = &iStatus; + iAppThread.RequestComplete(s, KErrCancel); + } + + + +MEventQueue& EpocSdlEnv::EventQueue() + { + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + return *gEpocEnv->iEventQueue; + } + + +TBool EpocSdlEnv::Flags(TInt aFlag) + { + const TInt flag = gEpocEnv->iEpocEnvFlags & aFlag; + return flag == aFlag; + } + +TInt EpocSdlEnv::Argc() + { + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + return gEpocEnv->iArgc; + } + + +char** EpocSdlEnv::Argv() + { + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + return gEpocEnv->iArgv; + } + + +TBool EpocSdlEnv::IsDsaAvailable() + { + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + return gEpocEnv->iDsa != NULL && gEpocEnv->iDsa->IsDsaAvailable(); + } + + +void EpocSdlEnv::WaitDsaAvailable() + { + EpocSdlEnv::ObserverEvent(MSDLObserver::EEventWindowNotAvailable, 0); + gEpocEnv->iAppSrv->Request(CSdlAppServ::EAppSrvStopThread); + if(EpocSdlEnv::Flags(CSDL::EEnableFocusStop)) + { + EpocSdlEnv::ObserverEvent(MSDLObserver::EEventSuspend, 0); + } + } + +void EpocSdlEnv::Suspend() + { + if(gEpocEnv->iDsa->Stopped() || EpocSdlEnv::Flags(CSDL::EEnableFocusStop)) + { + // gEpocEnv->iDsa->ReleaseStop(); + gEpocEnv->iDsa->SetSuspend(); + RThread().Suspend(); + EpocSdlEnv::ObserverEvent(MSDLObserver::EEventResume, 0); + } + } + +void EpocSdlEnv::SetWaitDsa() + { + if(!IsDsaAvailable()) + { + RThread th; + th.Open(gEpocEnv->iId); + th.Suspend(); + th.Close(); + gEpocEnv->iDsa->SetSuspend(); + } + } + +void EpocSdlEnv::Resume() + { + gEpocEnv->iDsa->Resume(); + RThread th; + th.Open(gEpocEnv->iId); + th.Resume(); + th.Close(); + + const TInt value = gEpocEnv->iAppSrv->ObserverEvent(MSDLObserver::EEventResume, 0); + gEpocEnv->iAppSrv->HandleObserverValue(MSDLObserver::EEventResume, value, ETrue); + } + + +TInt EpocSdlEnv::AllocSwSurface(const TSize& aSize, TDisplayMode aMode) + { + return gEpocEnv->iDsa->AllocSurface(EFalse, aSize, aMode); + } + +TInt EpocSdlEnv::AllocHwSurface(const TSize& aSize, TDisplayMode aMode) + { + return gEpocEnv->iDsa->AllocSurface(ETrue, aSize, aMode); + } + + +void EpocSdlEnv::UnlockHwSurface() + { + gEpocEnv->iDsa->UnlockHwSurface(); + } + +TUint8* EpocSdlEnv::LockHwSurface() + { + return gEpocEnv->iDsa->LockHwSurface(); + } + + +void EpocSdlEnv::UpdateSwSurface() + { + gEpocEnv->iDsa->UpdateSwSurface(); + } + +TBool EpocSdlEnv::AddUpdateRect(TUint8* aAddress, const TRect& aUpdateRect, const TRect& aRect) + { + return gEpocEnv->iDsa->AddUpdateRect(aAddress, aUpdateRect, aRect); + } + +void EpocSdlEnv::Request(TInt aService) + { + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + gEpocEnv->iAppSrv->Request(aService); + } + + +TSize EpocSdlEnv::WindowSize(const TSize& aRequestedSize) + { + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + if(EpocSdlEnv::Flags(CSDL::EAllowImageResize) && gEpocEnv->iDsa->WindowSize() != aRequestedSize) + { + TRAP_IGNORE(gEpocEnv->iDsa->CreateZoomerL(aRequestedSize)); + } + return gEpocEnv->iDsa->WindowSize(); + } + + TSize EpocSdlEnv::WindowSize() + { + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + return gEpocEnv->iDsa->WindowSize(); + } + +TDisplayMode EpocSdlEnv::DisplayMode() + { + return gEpocEnv->iDsa->DisplayMode(); + } + +TPointerCursorMode EpocSdlEnv::PointerMode() + { + return static_cast + (gEpocEnv->iAppSrv->RequestValue(CSdlAppServ::EAppSrvWindowPointerCursorMode)); + } + +TInt EpocSdlEnv::SetPalette(TInt aFirstcolor, TInt aColorCount, TUint32* aPalette) + { + return gEpocEnv->iDsa->SetPalette(aFirstcolor, aColorCount, aPalette); + } + +void EpocSdlEnv::PanicMain(TInt aErr) + { + gEpocEnv->iAppSrv->PanicMain(aErr); + } + + +TInt EpocSdlEnv::AppendCleanupItem(const TSdlCleanupItem& aItem) + { + TRAPD(err, gEpocEnv->iCleanupItems->AppendL(aItem)); + return err; + } + +void EpocSdlEnv::RemoveCleanupItem(TAny* aItem) + { + for(TInt i = 0; i < gEpocEnv->iCleanupItems->Count(); i++) + { + if(gEpocEnv->iCleanupItems->At(i).iItem == aItem) + gEpocEnv->iCleanupItems->Delete(i); + } + } + +void EpocSdlEnv::CleanupItems() + { + const TThreadId id = RThread().Id(); + TInt last = gEpocEnv->iCleanupItems->Count() - 1; + TInt i; + for(i = last; i >= 0 ; i--) + { + TSdlCleanupItem& item = gEpocEnv->iCleanupItems->At(i); + if(item.iThread == id) + { + item.iThread = TThreadId(0); + item.iOperation(item.iItem); + } + } + last = gEpocEnv->iCleanupItems->Count() - 1; + for(i = last; i >= 0 ; i--) + { + TSdlCleanupItem& item = gEpocEnv->iCleanupItems->At(i); + if(item.iThread == TThreadId(0)) + { + gEpocEnv->iCleanupItems->Delete(i); + } + } + } + +void EpocSdlEnv::FreeSurface() + { + Request(CSdlAppServ::EAppSrvDsaStatus); + gEpocEnv->iDsa->Free(); + } + +void EpocSdlEnv::LockPalette(TBool aLock) + { + gEpocEnv->iDsa->LockPalette(aLock); + } + +void EpocSdlEnv::ObserverEvent(TInt aService, TInt aParam) + { + const TBool sdlThread = RThread().Id() == gEpocEnv->iId; + const TInt valuea = gEpocEnv->iAppSrv->ObserverEvent(aService, aParam); + gEpocEnv->iAppSrv->HandleObserverValue(aService, valuea, !sdlThread); + if(sdlThread) + { + gEpocEnv->iAppSrv->SetParam(aParam); + const TInt valuet = gEpocEnv->iAppSrv->RequestValue(aService); + gEpocEnv->iAppSrv->HandleObserverValue(aService, valuet, EFalse); + } + } + + +TPoint EpocSdlEnv::WindowCoordinates(const TPoint& aPoint) + { + return gEpocEnv->iDsa->WindowCoordinates(aPoint); + } + +void EpocSdlEnv::PanicMain(const TDesC& aInfo, TInt aErr) + { + gEpocEnv->iAppSrv->PanicMain(aInfo, aErr); + } +//Dsa is a low priority ao, it has to wait if its pending event, but ws +//event has been prioritized before it +//this is not called from app thread! +void EpocSdlEnv::WaitDeviceChange() + { + LockPalette(ETrue); + gEpocEnv->iAppSrv->RequestValue(CSdlAppServ::EAppSrvWaitDsa); + const TSize sz = WindowSize(); + const TInt param = reinterpret_cast(&sz); + ObserverEvent(MSDLObserver::EEventScreenSizeChanged, param); + + // RThread().Suspend(); + } + +LOCAL_C TBool CheckSdl() + { + TInt isExit = ETrue; + RThread sdl; + if(sdl.Open(gEpocEnv->iId) == KErrNone) + { + if(sdl.ExitType() == EExitPending) + { + isExit = EFalse; + } + sdl.Close(); + } + return isExit; + } + +void EpocSdlEnvData::Free() + { + if(RThread().Id() == gEpocEnv->iId) + { + iDsa->Free(); + return; + } + + __ASSERT_ALWAYS(iArgv == NULL || CheckSdl(), PANIC(KErrNotReady)); + + for(TInt i = 0; i < iArgc; i++) + User::Free( iArgv[i] ); + + User::Free(iArgv); + + + delete iEventQueue; + + if(iDsa != NULL) + iDsa->Free(); + + delete iDsa; + delete iAppSrv; + } + +_LIT(KSDLMain, "SDLMain"); + +LOCAL_C int MainL() + { + gEpocEnv->iCleanupItems = new (ELeave) CArrayFixFlat(8); + + char** envp=0; + /* !! process exits here if there is "exit()" in main! */ + int ret = 0; + for(TInt i = 0; i < 6; i++) + { + void* f = (void*) gEpocEnv->iMain[i]; + if(f != NULL) + { + switch(i) + { + case 0: + ret = ((mainfunc1)f)(); + return ret; + case 3: + ((mainfunc1)f)(); + return ret; + case 1: + ret = ((mainfunc2)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv()); + return ret; + case 4: + ((mainfunc2)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv()); + return ret; + case 2: + ret = ((mainfunc3)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv(), envp); + return ret; + case 5: + ((mainfunc3)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv(), envp); + return ret; + } + } + } + PANIC(KErrNotFound); + return 0; + } + +LOCAL_C TInt DoMain(TAny* /*aParam*/) + { + + + CTrapCleanup* cleanup = CTrapCleanup::New(); + + TBool fbsconnected = EFalse; + if(RFbsSession::GetSession() == NULL) + { + PANIC_IF_ERROR(RFbsSession::Connect()); + fbsconnected = ETrue; + } + + gEpocEnv->iAppSrv->Init(); + +#ifdef SYMBIANC + // Create stdlib + _REENT; +#endif + + // Call stdlib main + int ret = 0; + + //completes waiting rendesvous + RThread::Rendezvous(KErrNone); + + TRAPD(err, err = MainL()); + + EpocSdlEnv::ObserverEvent(MSDLObserver::EEventMainExit, err); + + // Free resources and return + + EpocSdlEnv::CleanupItems(); + + gEpocEnv->iCleanupItems->Reset(); + delete gEpocEnv->iCleanupItems; + gEpocEnv->iCleanupItems = NULL; + + gEpocEnv->Free(); //free up in thread resources + +#ifdef SYMBIANC + _cleanup(); //this is normally called at exit, I call it here +#endif + + if(fbsconnected) + RFbsSession::Disconnect(); + +#ifdef SYMBIANC + CloseSTDLIB(); +#endif + + // delete as; + delete cleanup; + + return err == KErrNone ? ret : err;; + } + + + +EXPORT_C CSDL::~CSDL() + { + gEpocEnv->Free(); + User::Free(gEpocEnv); + gEpocEnv->iSdl = NULL; + } + +EXPORT_C CSDL* CSDL::NewL(TInt aFlags) + { + __ASSERT_ALWAYS(gEpocEnv == NULL, PANIC(KErrAlreadyExists)); + gEpocEnv = (EpocSdlEnvData*) User::AllocL(sizeof(EpocSdlEnvData)); + Mem::FillZ(gEpocEnv, sizeof(EpocSdlEnvData)); + + gEpocEnv->iEpocEnvFlags = aFlags; + gEpocEnv->iEventQueue = CEventQueue::NewL(); + + gEpocEnv->iAppSrv = new (ELeave) CSdlAppServ(); + gEpocEnv->iAppSrv->ConstructL(); + + CSDL* sdl = new (ELeave) CSDL(); + + gEpocEnv->iSdl = sdl; + + return sdl; + } + + /* +EXPORT_C void CSDL::ReInitL(TFlags aFlags) + { + const TFlags prevFlags = gEpocEnv->iEpocEnvFlags; + gEpocEnv->iEpocEnvFlags = aFlags; + TInt err = KErrNone; + if(((prevFlags & EDrawModeDSB) != (aFlags & EDrawModeDSB)) && gEpocEnv->iDsa) + { + delete gEpocEnv->iDsa; + gEpocEnv->iDsa = NULL; + gEpocEnv->iDsa = CDsa::RecreateL(EpocSdlEnv::Flags(CSDL::EDrawModeDSB)); + } + } + */ + + +EXPORT_C void CSDL::SetContainerWindowL(RWindow& aWindow, RWsSession& aSession, CWsScreenDevice& aDevice) + { + if(gEpocEnv->iDsa == NULL) + gEpocEnv->iDsa = CDsa::CreateL(aSession); + gEpocEnv->iDsa->ConstructL(aWindow, aDevice); + } + + +EXPORT_C TThreadId CSDL::CallMainL(const TMainFunc& aFunc, TRequestStatus* const aStatus, const CDesC8Array* const aArg, TInt aFlags, TInt aStackSize) + { + ASSERT(gEpocEnv != NULL); + gEpocEnv->iMain = aFunc; + const TBool args = aArg != NULL; + + gEpocEnv->iArgc = aArg->Count() + 1; + gEpocEnv->iArgv = (char**) User::AllocL(sizeof(char*) * (gEpocEnv->iArgc + 1)); + + TInt k = 0; + const TFileName processName = RProcess().FileName(); + const TInt len = processName.Length(); + gEpocEnv->iArgv[k] = (char*) User::AllocL(len + 1); + Mem::Copy(gEpocEnv->iArgv[k], processName.Ptr(), len); + gEpocEnv->iArgv[k][len] = 0; + + for(TInt i = 0; args && (i < aArg->Count()); i++) + { + k++; + const TInt len = aArg->MdcaPoint(i).Length(); + gEpocEnv->iArgv[k] = (char*) User::AllocL(len + 1); + Mem::Copy(gEpocEnv->iArgv[k], aArg->MdcaPoint(i).Ptr(), len); + gEpocEnv->iArgv[k][len] = 0; + } + + gEpocEnv->iArgv[gEpocEnv->iArgc] = NULL; + + RThread thread; + User::LeaveIfError(thread.Create(KSDLMain, DoMain, aStackSize, NULL, NULL)); + + if(aStatus != NULL) + { + thread.Logon(*aStatus); + } + + gEpocEnv->iId = thread.Id(); + thread.SetPriority(EPriorityLess); + if((aFlags & CSDL::ERequestResume) == 0) + { + thread.Resume(); + } + thread.Close(); + return gEpocEnv->iId; + } + +EXPORT_C TInt CSDL::AppendWsEvent(const TWsEvent& aEvent) + { + return EpocSdlEnv::EventQueue().Append(aEvent); + } + +EXPORT_C void CSDL::SDLPanic(const TDesC& aInfo, TInt aErr) + { + EpocSdlEnv::PanicMain(aInfo, aErr); + } + +EXPORT_C TInt CSDL::GetSDLCode(TInt aScanCode) + { + if(aScanCode < 0) + return MAX_SCANCODE; + if(aScanCode >= MAX_SCANCODE) + return -1; + return KeyMap()[aScanCode]; + } + +EXPORT_C TInt CSDL::SDLCodesCount() const + { + return MAX_SCANCODE; + } + +EXPORT_C void CSDL::ResetSDLCodes() + { + ResetKeyMap(); + } + +EXPORT_C void CSDL::SetOrientation(TOrientationMode aMode) + { + gEpocEnv->iDsa->SetOrientation(aMode); + } + +EXPORT_C TInt CSDL::SetSDLCode(TInt aScanCode, TInt aSDLCode) + { + const TInt current = GetSDLCode(aScanCode); + if(aScanCode >= 0 && aScanCode < MAX_SCANCODE) + KeyMap()[aScanCode] = static_cast(aSDLCode); + return current; + } + + +EXPORT_C MSDLObserver* CSDL::Observer() + { + return gEpocEnv->iAppSrv->Observer(); + } + +EXPORT_C void CSDL::SetObserver(MSDLObserver* aObserver) + { + gEpocEnv->iAppSrv->SetObserver(aObserver); + } + +EXPORT_C void CSDL::Resume() + { + EpocSdlEnv::Resume(); + } + +EXPORT_C void CSDL::Suspend() + { + gEpocEnv->iDsa->DoStop(); + } + +EXPORT_C CSDL::CSDL() + { + } + +EXPORT_C void CSDL::DisableKeyBlocking(CAknAppUi& aAppUi) const + { + gEpocEnv->iAppUi = &aAppUi; + EnvUtils::DisableKeyBlocking(); + } + +EXPORT_C TInt CSDL::SetBlitter(MBlitter* aBlitter) + { + if(gEpocEnv && gEpocEnv->iDsa) + { + gEpocEnv->iDsa->SetBlitter(aBlitter); + return KErrNone; + } + return KErrNotReady; + } + + +EXPORT_C TInt CSDL::AppendOverlay(MOverlay& aOverlay, TInt aPriority) + { + if(gEpocEnv && gEpocEnv->iDsa) + { + return gEpocEnv->iDsa->AppendOverlay(aOverlay, aPriority); + } + return KErrNotReady; + } + +EXPORT_C TInt CSDL::RemoveOverlay(MOverlay& aOverlay) + { + if(gEpocEnv && gEpocEnv->iDsa) + { + return gEpocEnv->iDsa->RemoveOverlay(aOverlay); + } + return KErrNotReady; + } + +EXPORT_C TInt CSDL::RedrawRequest() + { + if(gEpocEnv && gEpocEnv->iDsa) + { + return gEpocEnv->iDsa->RedrawRequest(); + } + return KErrNotReady; + } + +/* +EXPORT_C CSDL* CSDL::Current() + { + return gEpocEnv != NULL ? gEpocEnv->iSdl : NULL; + } + + +EXPORT_C TInt CSDL::SetVolume(TInt aVolume) + { + return EpocSdlEnv::SetVolume(aVolume); + } + +EXPORT_C TInt CSDL::Volume() const + { + return EpocSdlEnv::Volume(); + } + +EXPORT_C TInt CSDL::MaxVolume() const + { + return EpocSdlEnv::MaxVolume(); + } +*/ + +void EnvUtils::DisableKeyBlocking() + { + if(gEpocEnv->iAppUi != NULL) + return CCurrentAppUi::Cast(gEpocEnv->iAppUi)->DisableKeyBlocking(); + } + +TBool EnvUtils::Rendezvous(RThread& aThread, TRequestStatus& aStatus) + { + if(gEpocEnv->iId != TThreadId(0) && + aThread.Open(gEpocEnv->iId) && + aThread.ExitType() == EExitPending) + { + aThread.Rendezvous(aStatus); + return ETrue; + } + return EFalse; + } + + + diff --git a/distrib/sdl-1.2.15/src/main/symbian/EKA2/sdlexe.cpp b/distrib/sdl-1.2.15/src/main/symbian/EKA2/sdlexe.cpp new file mode 100644 index 0000000..bb160c4 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/symbian/EKA2/sdlexe.cpp @@ -0,0 +1,809 @@ +// INCLUDES +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +// FORWARD DECLARATIONS +class CApaDocument; + + +//const TUid KSDLUID = { 0xF01F605E }; + +LOCAL_C void MakeCCmdLineL(const TDesC8& aParam, CDesC8Array& aArray) + { + + const TChar dq('\"'); + + TLex8 lex(aParam); + TBool in = EFalse; + + lex.SkipSpaceAndMark(); + + while(!lex.Eos()) + { + TPtrC8 ptr; + if(in) + { + const TPtrC8 rem = lex.RemainderFromMark(); + const TInt pos = rem.Locate(dq); + if(pos > 0) + { + lex.Inc(pos); + ptr.Set(lex.MarkedToken()); + lex.SkipAndMark(1); + } + else + { + ptr.Set(rem); + } + in = EFalse; + } + else + { + ptr.Set(lex.NextToken()); + const TInt pos = ptr.Locate(dq); + if(pos == 0) + { + lex.UnGetToMark(); + lex.SkipAndMark(1); + in = ETrue; + continue; // back to in brace + } + else + lex.SkipSpaceAndMark(); + } + + aArray.AppendL(ptr); + + } + } + +NONSHARABLE_CLASS(TVirtualCursor) : public MOverlay + { + public: + TVirtualCursor(); + void Set(const TRect& aRect, CFbsBitmap* aBmp, CFbsBitmap* aAlpha); + void Move(TInt aX, TInt aY); + void MakeEvent(TWsEvent& aEvent, const TPoint& aBasePos) const; + void Toggle(); + TBool IsOn() const; + private: + void Draw(CBitmapContext& aGc, const TRect& aTargetRect, const TSize& aSize); + private: + TRect iRect; + TPoint iInc; + TPoint iPos; + TBool iIsOn; + CFbsBitmap* iCBmp; + CFbsBitmap* iAlpha; + }; + + +TVirtualCursor::TVirtualCursor() : iInc(0, 0), iIsOn(EFalse), iCBmp(NULL) + { + } + +const TInt KMaxMove = 10; + +void TVirtualCursor::Move(TInt aX, TInt aY) + { + if(aX > 0 && iInc.iX > 0) + ++iInc.iX; + else if(aX < 0 && iInc.iX < 0) + --iInc.iX; + else + iInc.iX = aX; + + if(aY > 0 && iInc.iY > 0) + ++iInc.iY; + else if(aY < 0 && iInc.iY < 0) + --iInc.iY; + else + iInc.iY = aY; + + iInc.iX = Min(KMaxMove, iInc.iX); + + iInc.iX = Max(-KMaxMove, iInc.iX); + + iInc.iY = Min(KMaxMove, iInc.iY); + + iInc.iY =Max(-KMaxMove, iInc.iY); + + const TPoint pos = iPos + iInc; + if(iRect.Contains(pos)) + { + iPos = pos; + } + else + { + iInc = TPoint(0, 0); + } + } + + +void TVirtualCursor::Toggle() + { + iIsOn = !iIsOn; + } + + +TBool TVirtualCursor::IsOn() const + { + return iIsOn; + } + +void TVirtualCursor::Set(const TRect& aRect, CFbsBitmap* aBmp, CFbsBitmap* aAlpha) + { + iRect = aRect; + iCBmp = aBmp; + iAlpha = aAlpha; + } + + +void TVirtualCursor::MakeEvent(TWsEvent& aEvent, const TPoint& aBasePos) const + { + aEvent.SetType(EEventPointer), + aEvent.SetTimeNow(); + TPointerEvent& pointer = *aEvent.Pointer(); + pointer.iType = TPointerEvent::EButton1Down; + pointer.iPosition = iPos; + pointer.iParentPosition = aBasePos; + } + + +void TVirtualCursor::Draw(CBitmapContext& aGc, const TRect& /*aTargetRect*/, const TSize& /*aSize*/) + { + if(iIsOn && iCBmp != NULL) + { + const TRect rect(TPoint(0, 0), iCBmp->SizeInPixels()); + aGc.AlphaBlendBitmaps(iPos, iCBmp, rect, iAlpha, TPoint(0, 0)); + } + + } + +NONSHARABLE_CLASS(TSdlClass) + { + public: + TSdlClass(); + void SetMain(const TMainFunc& aFunc, TInt aFlags, MSDLMainObs* aObs, TInt aExeFlags); + TInt SdlFlags() const; + const TMainFunc& Main() const; + void SendEvent(TInt aEvent, TInt aParam, CSDL* aSDL); + TInt AppFlags() const; + void AppFlags(TInt aFlags); + private: + TMainFunc iFunc; + TInt iSdlFlags; + TInt iExeFlags; + MSDLMainObs* iObs; + }; + + +void TSdlClass::AppFlags(TInt aFlags) + { + iExeFlags |= aFlags; + } + +void TSdlClass::SendEvent(TInt aEvent, TInt aParam, CSDL* aSDL) + { + if(iObs != NULL) + iObs->SDLMainEvent(aEvent, aParam, aSDL); + } + +TInt TSdlClass::AppFlags() const + { + return iExeFlags; + } + +void TSdlClass::SetMain(const TMainFunc& aFunc, TInt aFlags, MSDLMainObs* aObs, TInt aExeFlags) + { + iFunc = aFunc; + iSdlFlags = aFlags; + iExeFlags = aExeFlags; + iObs = aObs; + } + +const TMainFunc& TSdlClass::Main() const + { + return iFunc; + } + + + TInt TSdlClass::SdlFlags() const + { + return iSdlFlags; + } + + + +TSdlClass::TSdlClass() + { + Mem::FillZ(this, sizeof(this)); + } + +TSdlClass gSDLClass; + + +//////////////////////////////////////////////////////////////// + +NONSHARABLE_CLASS(CSDLApplication) : public CAknApplication + { + public: + CSDLApplication(); + private: + CApaDocument* CreateDocumentL(); + TFileName ResourceFileName() const; + TUid AppDllUid() const; + void FindMeL(); + TUid iUid; + }; + +NONSHARABLE_CLASS(CSDLDocument) : public CEikDocument + { + public: + CSDLDocument(CEikApplication& aApp); + private: + CEikAppUi* CreateAppUiL(); + + }; + + //////////////////////////////////////////////////////////////////// + + +NONSHARABLE_CLASS(MExitWait) + { + public: + virtual void DoExit(TInt aErr) = 0; + }; + +///////////////////////////////////////////////////////////////////////// + +NONSHARABLE_CLASS(CExitWait) : public CActive + { + public: + CExitWait(MExitWait& aWait); + ~CExitWait(); + private: + void RunL(); + void DoCancel(); + private: + MExitWait& iWait; + TRequestStatus* iStatusPtr; + }; + +//////////////////////////////////////////////////////////////////////// + + +NONSHARABLE_CLASS(CSDLWin) : public CCoeControl + { + public: + void ConstructL(const TRect& aRect); + RWindow& GetWindow() const; + void SetNoDraw(); + private: + void Draw(const TRect& aRect) const; + private: + TBool iNoDraw; + }; + + +//////////////////////////////////////////////////////////////////////////// + +NONSHARABLE_CLASS(CSDLAppUi) : public CAknAppUi, public MExitWait, MSDLObserver + { + public: + ~CSDLAppUi(); + private: // New functions + void ConstructL(); + void HandleCommandL(TInt aCommand); + void HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination); + void HandleResourceChangeL(TInt aType); + + void DoExit(TInt aErr); + + TInt SdlEvent(TInt aEvent, TInt aParam); + TInt SdlThreadEvent(TInt aEvent, TInt aParam); + + void StartL(); + static TBool StartL(TAny* aThis); + + TBool ParamEditorL(TDes& aCheat); + + TBool ProcessCommandParametersL(CApaCommandLine &aCommandLine); + + void PrepareToExit(); + void HandleConsoleWindowL(); + void HandleConsoleWindow(); + void HandleForegroundEventL(TBool aForeground); + + static TBool IdleRequestL(TAny* aThis); + + TBool HandleKeyL(const TWsEvent& aEvent); + + + private: + CExitWait* iWait; + CSDLWin* iSDLWin; + CSDL* iSdl; + CIdle* iStarter; + TBool iExitRequest; + CDesC8Array* iParams; + TInt iResOffset; + CIdle* iIdle; + TInt iStdOut; + TVirtualCursor iCursor; + CFbsBitmap* iCBmp; + CFbsBitmap* iAlpha; + // TTime iLastPress; + // CSDL::TOrientationMode iOrientation; + }; + +////////////////////////////////////////////////////////////////////////////////////////7 + +CApaDocument* CSDLApplication::CreateDocumentL() + { + return new (ELeave) CSDLDocument(*this); + } + +TUid CSDLApplication::AppDllUid() const + { + return iUid; + } + + +CSDLApplication::CSDLApplication() + { + TRAPD(err, FindMeL()); + ASSERT(err == KErrNone); + } + +void CSDLApplication::FindMeL() + { + RApaLsSession apa; + User::LeaveIfError(apa.Connect()); + CleanupClosePushL(apa); + User::LeaveIfError(apa.GetAllApps()); + TFileName name = RProcess().FileName(); + TApaAppInfo info; + while(apa.GetNextApp(info) == KErrNone) + { + if(info.iFullName.CompareF(name) == 0) + { + iUid = info.iUid; + break; + } + } + CleanupStack::PopAndDestroy(); + } + +TFileName CSDLApplication::ResourceFileName() const + { + return KNullDesC(); + } + +/////////////////////////////////////////////////////////////////////////////////////////// + +CExitWait::CExitWait(MExitWait& aWait) : CActive(CActive::EPriorityStandard), iWait(aWait) + { + CActiveScheduler::Add(this); + SetActive(); + iStatusPtr = &iStatus; + } + +CExitWait::~CExitWait() + { + Cancel(); + } + +void CExitWait::RunL() + { + if(iStatusPtr != NULL ) + iWait.DoExit(iStatus.Int()); + } + +void CExitWait::DoCancel() + { + if(iStatusPtr != NULL ) + User::RequestComplete(iStatusPtr , KErrCancel); + } + + +////////////////////////////////////////////////////////////////////////////////////////////// + +CSDLDocument::CSDLDocument(CEikApplication& aApp) : CEikDocument(aApp) + {} + +CEikAppUi* CSDLDocument::CreateAppUiL() + { + return new (ELeave) CSDLAppUi; + } + +/////////////////////////////////////////////////////////////////////////// + +void CSDLWin:: ConstructL(const TRect& aRect) + { + CreateWindowL(); + SetRect(aRect); + ActivateL(); + } + + +RWindow& CSDLWin::GetWindow() const + { + return Window(); + } + + +void CSDLWin::Draw(const TRect& /*aRect*/) const + { + if(!iNoDraw) + { + CWindowGc& gc = SystemGc(); + gc.SetPenStyle(CGraphicsContext::ESolidPen); + gc.SetPenColor(KRgbGray); + gc.SetBrushStyle(CGraphicsContext::ESolidBrush); + gc.SetBrushColor(0xaaaaaa); + gc.DrawRect(Rect()); + } + } + +void CSDLWin::SetNoDraw() + { + iNoDraw = ETrue; + } + +///////////////////////////////////////////////////////////////////////// + +CSDLAppUi::~CSDLAppUi() + { + if(iIdle) + iIdle->Cancel(); + delete iIdle; + if(iStarter != NULL) + iStarter->Cancel(); + delete iStarter; + delete iWait; + delete iSdl; + delete iSDLWin; + delete iParams; + delete iCBmp; + delete iAlpha; + } + + +void CSDLAppUi::ConstructL() + { + BaseConstructL(ENoAppResourceFile | ENoScreenFurniture); + + + RLibrary lib; + User::LeaveIfError(lib.Load(_L("sdlexe.dll"))); + TFileName name = lib.FileName(); + lib.Close(); + name.Replace(3, name.Length() - 3, _L("resource\\apps\\sdlexe.rsc")); + BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(), name); + iResOffset = iCoeEnv->AddResourceFileL(name); + + name.Replace(name.Length() - 3, 3, _L("mbm")); + + TEntry e; + const TInt err = iEikonEnv->FsSession().Entry(name, e); + + iCBmp = iEikonEnv->CreateBitmapL(name, 0); + iAlpha = iEikonEnv->CreateBitmapL(name, 1); + + iIdle = CIdle::NewL(CActive::EPriorityIdle); + + iSDLWin = new (ELeave) CSDLWin; + iSDLWin->ConstructL(ApplicationRect()); + + iSdl = CSDL::NewL(gSDLClass.SdlFlags()); + + gSDLClass.SendEvent(MSDLMainObs::ESDLCreated, 0, iSdl); + + iSdl->SetObserver(this); + iSdl->DisableKeyBlocking(*this); + iSdl->SetContainerWindowL( + iSDLWin->GetWindow(), + iEikonEnv->WsSession(), + *iEikonEnv->ScreenDevice()); + iSdl->AppendOverlay(iCursor, 0); + + iCursor.Set(TRect(TPoint(0, 0), iSDLWin->Size()), iCBmp, iAlpha); + + iStarter = CIdle::NewL(CActive::EPriorityLow); + iStarter->Start(TCallBack(StartL, this)); + + + } + + + +TBool CSDLAppUi::StartL(TAny* aThis) + { + static_cast(aThis)->StartL(); + return EFalse; + } + + +void CSDLAppUi::PrepareToExit() + { + CAknAppUiBase::PrepareToExit(); //aknappu::PrepareToExit crashes + iCoeEnv->DeleteResourceFile(iResOffset); + } + +TBool CSDLAppUi::ProcessCommandParametersL(CApaCommandLine &aCommandLine) + { + const TPtrC8 cmdLine = aCommandLine.TailEnd(); + iParams = new (ELeave) CDesC8ArrayFlat(8); + MakeCCmdLineL(cmdLine, *iParams); + return EFalse; + } + + + TBool CSDLAppUi::ParamEditorL(TDes& aCheat) + { + CAknTextQueryDialog* query = CAknTextQueryDialog::NewL(aCheat); + CleanupStack::PushL(query); + query->SetPromptL(_L("Enter parameters")); + CleanupStack::Pop(); + return query->ExecuteLD(R_PARAMEDITOR); + } + + void CSDLAppUi::StartL() + { + if(gSDLClass.AppFlags() & SDLEnv::EParamQuery) + { + TBuf8<256> cmd; + RFile file; + TInt err = file.Open(iEikonEnv->FsSession(), _L("sdl_param.txt"),EFileRead); + if(err == KErrNone) + { + file.Read(cmd); + file.Close(); + MakeCCmdLineL(cmd, *iParams); + } + if(err != KErrNone || gSDLClass.AppFlags() & (SDLEnv::EParamQueryDialog ^ SDLEnv::EParamQuery)) + { + TBuf<256> buffer; + if(ParamEditorL(buffer)) + { + cmd.Copy(buffer); + MakeCCmdLineL(cmd, *iParams); + } + } + } + iWait = new (ELeave) CExitWait(*this); + iSdl->CallMainL(gSDLClass.Main(), &iWait->iStatus, iParams, CSDL::ENoParamFlags, 0xA000); + } + +void CSDLAppUi::HandleCommandL(TInt aCommand) + { + switch(aCommand) + { + case EAknSoftkeyBack: + case EAknSoftkeyExit: + case EAknCmdExit: + case EEikCmdExit: + gSDLClass.AppFlags(SDLEnv::EAllowConsoleView); + if(iWait == NULL || !iWait->IsActive() || iSdl == NULL) + { + Exit(); + } + else if(!iExitRequest) + { + iExitRequest = ETrue; //trick how SDL can be closed! + iSdl->Suspend(); + } + break; + } + } + + + +TBool CSDLAppUi::HandleKeyL(const TWsEvent& aEvent) + { + const TInt type = aEvent.Type(); + if(!(type == EEventKey || type == EEventKeyUp || type == EEventKeyDown)) + { + return ETrue; + } + const TKeyEvent& key = *aEvent.Key(); + if((key.iScanCode == EStdKeyYes) && (gSDLClass.AppFlags() & SDLEnv::EVirtualMouse)) + { + if(type == EEventKeyUp) + { + iCursor.Toggle(); + iSdl->RedrawRequest(); + } + return EFalse; + } + if(iCursor.IsOn()) + { + switch(key.iScanCode) + { + case EStdKeyUpArrow: + iCursor.Move(0, -1); + break; + case EStdKeyDownArrow: + iCursor.Move(0, 1); + break; + case EStdKeyLeftArrow: + iCursor.Move(-1, 0); + break; + case EStdKeyRightArrow: + iCursor.Move(1, 0); + break; + case EStdKeyDevice3: + if(type == EEventKeyUp) + { + TWsEvent event; + iCursor.MakeEvent(event, iSDLWin->Position()); + iSdl->AppendWsEvent(event); + } + return EFalse; + default: + return ETrue; + } + iSdl->RedrawRequest(); + return EFalse; + } + return ETrue; + } + + void CSDLAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination) + { + if(iSdl && iWait && HandleKeyL(aEvent)) + iSdl->AppendWsEvent(aEvent); + CAknAppUi::HandleWsEventL(aEvent, aDestination); + } + + void CSDLAppUi::HandleResourceChangeL(TInt aType) + { + CAknAppUi::HandleResourceChangeL(aType); + if(aType == KEikDynamicLayoutVariantSwitch) + { + iSDLWin->SetRect(ApplicationRect()); + iSdl->SetContainerWindowL( + iSDLWin->GetWindow(), + iEikonEnv->WsSession(), + *iEikonEnv->ScreenDevice()); + } + } + + +void CSDLAppUi::DoExit(TInt/*Err*/) + { + iExitRequest = ETrue; + Exit(); + } + + + TInt CSDLAppUi::SdlThreadEvent(TInt aEvent, TInt /*aParam*/) + { + switch(aEvent) + { + case MSDLObserver::EEventResume: + break; + case MSDLObserver::EEventSuspend: + if(iExitRequest) + return MSDLObserver::ESuspendNoSuspend; + break; + case MSDLObserver::EEventWindowReserved: + break; + case MSDLObserver::EEventWindowNotAvailable: + break; + case MSDLObserver::EEventScreenSizeChanged: + break; + } + return MSDLObserver::EParameterNone; + } + +TInt CSDLAppUi::SdlEvent(TInt aEvent, TInt /*aParam*/) + { + switch(aEvent) + { + case MSDLObserver::EEventResume: + break; + case MSDLObserver::EEventSuspend: + if(iExitRequest) + return MSDLObserver::ESuspendNoSuspend; + break; + case MSDLObserver::EEventWindowReserved: + break; + case MSDLObserver::EEventWindowNotAvailable: + { + TRAP_IGNORE(HandleConsoleWindowL()); + } + break; + case MSDLObserver::EEventScreenSizeChanged: + break; + case MSDLObserver::EEventKeyMapInit: + break; + case MSDLObserver::EEventMainExit: + if(iStdOut != 0) + { + gSDLClass.AppFlags(SDLEnv::EAllowConsoleView); + iEikonEnv->WsSession().SetWindowGroupOrdinalPosition(iStdOut, 0); + } + break; + } + return MSDLObserver::EParameterNone; + } + +void CSDLAppUi::HandleForegroundEventL(TBool aForeground) + { + CAknAppUi::HandleForegroundEventL(aForeground); + if(!aForeground) + HandleConsoleWindow(); + } + +void CSDLAppUi::HandleConsoleWindow() + { + if(!iIdle->IsActive()) + iIdle->Start(TCallBack(IdleRequestL, this)); + } + +TBool CSDLAppUi::IdleRequestL(TAny* aThis) + { + static_cast(aThis)->HandleConsoleWindowL(); + return EFalse; + } + +void CSDLAppUi::HandleConsoleWindowL() + { + if(gSDLClass.AppFlags() & SDLEnv::EAllowConsoleView) + { + return; + } + RWsSession& ses = iEikonEnv->WsSession(); + const TInt focus = ses.GetFocusWindowGroup(); + CApaWindowGroupName* name = CApaWindowGroupName::NewLC(ses, focus); + const TPtrC caption = name->Caption(); + if(0 == caption.CompareF(_L("STDOUT"))) + { + iStdOut = focus; + ses.SetWindowGroupOrdinalPosition(iEikonEnv->RootWin().Identifier(), 0); + } + CleanupStack::PopAndDestroy(); //name + } + + +//////////////////////////////////////////////////////////////////////// + + +CApaApplication* NewApplication() + { + return new CSDLApplication(); + } + + +EXPORT_C TInt SDLEnv::SetMain(const TMainFunc& aFunc, TInt aSdlFlags, MSDLMainObs* aObs, TInt aSdlExeFlags) + { + gSDLClass.SetMain(aFunc, aSdlFlags, aObs, aSdlExeFlags); + return EikStart::RunApplication(NewApplication); + } + +////////////////////////////////////////////////////////////////////// + +TInt SDLUiPrint(const TDesC8& /*aInfo*/) + { + return KErrNotFound; + } + + + diff --git a/distrib/sdl-1.2.15/src/main/symbian/EKA2/sdllib.cpp b/distrib/sdl-1.2.15/src/main/symbian/EKA2/sdllib.cpp new file mode 100644 index 0000000..7c09996 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/symbian/EKA2/sdllib.cpp @@ -0,0 +1,12 @@ +#include +#include +#include + + +GLREF_C TInt E32Main() + { + return SDLEnv::SetMain(SDL_main, CSDL::EEnableFocusStop | CSDL::EAllowImageResize, + NULL, SDLEnv::EParamQuery | SDLEnv::EVirtualMouse); + } + + \ No newline at end of file diff --git a/distrib/sdl-1.2.15/src/main/symbian/EKA2/vectorbuffer.cpp b/distrib/sdl-1.2.15/src/main/symbian/EKA2/vectorbuffer.cpp new file mode 100644 index 0000000..72c3b3e --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/symbian/EKA2/vectorbuffer.cpp @@ -0,0 +1,62 @@ +/* + vectorbuffer.cpp + yet another circle buffer + + Markus Mertama +*/ + +#include"vectorbuffer.h" + + + +void VectorPanic(TInt aErr, TInt aLine) + { + TBuf<64> b; + b.Format(_L("vector buffer at % d "), aLine); + User::Panic(b, aErr); + } + +void TNodeBuffer::TNode::Terminator(TNodeBuffer::TNode* aNode) + { + Mem::Copy(iSucc, &aNode, sizeof(TNode*)); + } + +TInt TNodeBuffer::TNode::Size() const + { + return reinterpret_cast(iSucc) - Ptr(); + } + +const TUint8* TNodeBuffer::TNode::Ptr() const + { + return reinterpret_cast(this) + sizeof(TNode); + } + +TNodeBuffer::TNode* TNodeBuffer::TNode::Empty(TUint8* aBuffer) + { + TNode* node = reinterpret_cast(aBuffer); + node->iSucc = node + 1; + return node; + } + + TNodeBuffer::TNode* TNodeBuffer::TNode::New(TNode* aPred, const TDesC8& aData) + { + TNode* node = aPred->Size() == 0 ? aPred : aPred->iSucc; + + + TUint8* start = reinterpret_cast(node) + sizeof(TNode); + node->iSucc = reinterpret_cast(start + aData.Size()); + node->iSucc->iSucc = NULL; //terminator + + __ASSERT_DEBUG(node->Size() == aData.Size(), VECPANIC(KErrCorrupt)); + + Mem::Copy(start, aData.Ptr(), aData.Size()); + return node; + } + + + + + + + + \ No newline at end of file diff --git a/distrib/sdl-1.2.15/src/main/symbian/EKA2/vectorbuffer.h b/distrib/sdl-1.2.15/src/main/symbian/EKA2/vectorbuffer.h new file mode 100644 index 0000000..3d8be58 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/symbian/EKA2/vectorbuffer.h @@ -0,0 +1,240 @@ +/* + vectorbuffer.cpp + yet another circle buffer + + Markus Mertama +*/ + +#ifndef __VECTORBUFFER_H__ +#define __VECTORBUFFER_H__ + +#include +#define VLOG(x) +#define VECPANIC(x) VectorPanic(x, __LINE__) +void VectorPanic(TInt, TInt); + + +//int DEBUG_INT; + +NONSHARABLE_CLASS(TNodeBuffer) + { + public: + protected: + NONSHARABLE_CLASS(TNode) + { + public: + static TNode* Empty(TUint8* iBuffer); + static TNode* New(TNode* aPrev, const TDesC8& aData); + const TUint8* Ptr() const; + TInt Size() const; + inline TNode* Succ(); + static void SetSucc(TNode*& aNode); + void Terminator(TNode* aNode); + private: + TNode* iSucc; + }; + }; + +inline TNodeBuffer::TNode* TNodeBuffer::TNode::Succ() + { + return iSucc; + } + +template +NONSHARABLE_CLASS(TVectorBuffer) : public TNodeBuffer + { + public: + TVectorBuffer(); + TInt Append(const TDesC8& aData); + // TInt AppendOverwrite(const TDesC8& aData); + TPtrC8 Shift(); + TPtrC8 operator[](TInt aIndex) const; + TInt Size() const; + private: + TInt GetRoom(TInt aSize) const; + TInt Unreserved() const; + private: + TNode* iTop; + TNode* iBottom; + TInt iSize; + TUint8 iBuffer[C]; + }; + +template +TVectorBuffer::TVectorBuffer() : iSize(0) + { + Mem::FillZ(iBuffer, C); + iTop = TNode::Empty(iBuffer); //these points to buffer + iBottom = TNode::Empty(iBuffer); + } + +template +TInt TVectorBuffer::Unreserved() const + { + __ASSERT_DEBUG(iBottom < iBottom->Succ(), VECPANIC(KErrCorrupt)); + const TInt bytesbetween = + reinterpret_cast(iBottom->Succ()) - + reinterpret_cast(iTop); + const TInt topsize = sizeof(TNode); + if(bytesbetween > 0) //bytesbetween is room between bottom and top + { //therefore free room is subracted from free space + + const TInt room = C - bytesbetween - topsize; + return room; + } + if(bytesbetween == 0) + { + + if(Size() > 0) + return 0; + else + return C - topsize; + } + const TInt room = -bytesbetween - topsize; //free is space between pointers + return room; + } + +template +TInt TVectorBuffer::GetRoom(TInt aSize) const + { + const TInt bytesnew = sizeof(TNode) + aSize; + const TInt room = Unreserved() - bytesnew; + return room; + } + +template +TInt TVectorBuffer::Append(const TDesC8& aData) //ei ole ok! + { + const TInt len = aData.Length(); + if(GetRoom(len) < 0) + { + return KErrOverflow; + } + if(iBottom->Succ()->Ptr() - iBuffer > (C - (len + TInt(sizeof(TNode))))) + { + VLOG("rc"); + // RDebug::Print(_L("vector: append")); + TNode* p = TNode::Empty(iBuffer); + iBottom->Terminator(p); + iBottom = p; + return Append(aData); + // Append(); + // iBottom = TNode::New(p, aData); //just append something into end + } + + //DEBUG_INT++; + + iBottom = TNode::New(iBottom, aData); + + iSize += len; + return KErrNone; + } + +/* +template +TInt TVectorBuffer::AppendOverwrite(const TDesC8& aData) //ei ole ok! + { + while(Append(aData) == KErrOverflow) + { + if(iTop->Succ() == NULL) + { + return KErrUnderflow; + } + //Shift(); //data is lost + } + return KErrNone; + } +*/ +template +TPtrC8 TVectorBuffer::Shift() + { + __ASSERT_ALWAYS(iTop->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom + TNode* node = iTop; + iTop = iTop->Succ(); + if(iTop > node) + { + // DEBUG_INT--; + iSize -= node->Size(); + return TPtrC8(node->Ptr(), node->Size()); + } + else + { + // RDebug::Print(_L("vector: shift")); + return Shift(); //this happens when buffer is terminated, and data lies in next + } + } + +template +TInt TVectorBuffer::Size() const + { + return iSize; + } + +template +TPtrC8 TVectorBuffer::operator[](TInt aIndex) const + { + TInt index = 0; + TNode* t = iTop->Size() > 0 ? iTop : iTop->Succ(); //eliminate terminator + while(index < aIndex) + { + TNode* nt = t->Succ(); + if(nt < t) + { + nt = nt->Succ(); + } + t = nt; + if(t->Size() > 0) + index++; + __ASSERT_ALWAYS(t->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom + } + return t->Ptr(); + } + + +template +NONSHARABLE_CLASS(TVector) : public TVectorBuffer + { + public: + TVector(); + TInt Append(const T& aData); + const T& Shift(); + TInt Size() const; + const T& operator[](TInt aIndex) const; + }; + +template +TVector::TVector() : TVectorBuffer() + { + } + +template +TInt TVector::Append(const T& aData) + { + const TPckgC data(aData); + return TVectorBuffer::Append(data); + } + +template +const T& TVector::Shift() + { + const TPtrC8 ptr = TVectorBuffer::Shift(); + return *(reinterpret_cast(ptr.Ptr())); + } + + +template +TInt TVector::Size() const + { + return TVectorBuffer::Size() / sizeof(T); + } + +template +const T& TVector::operator[](TInt aIndex) const + { + const TPtrC8 ptr = TVectorBuffer::operator[](aIndex); + return *(reinterpret_cast(ptr.Ptr())); + } + +#endif + + diff --git a/distrib/sdl-1.2.15/src/main/win32/SDL_win32_main.c b/distrib/sdl-1.2.15/src/main/win32/SDL_win32_main.c new file mode 100644 index 0000000..672b48c --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/win32/SDL_win32_main.c @@ -0,0 +1,402 @@ +/* + SDL_main.c, placed in the public domain by Sam Lantinga 4/13/98 + + The WinMain function -- calls your program's main() function +*/ + +#include +#include + +#define WIN32_LEAN_AND_MEAN +#include + +#ifdef _WIN32_WCE +# define DIR_SEPERATOR TEXT("\\") +# undef _getcwd +# define _getcwd(str,len) wcscpy(str,TEXT("")) +# define setbuf(f,b) +# define setvbuf(w,x,y,z) +# define fopen _wfopen +# define freopen _wfreopen +# define remove(x) DeleteFile(x) +#else +# define DIR_SEPERATOR TEXT("/") +# include +#endif + +/* Include the SDL main definition header */ +#include "SDL.h" +#include "SDL_main.h" + +#ifdef main +# ifndef _WIN32_WCE_EMULATION +# undef main +# endif /* _WIN32_WCE_EMULATION */ +#endif /* main */ + +/* The standard output files */ +#define STDOUT_FILE TEXT("stdout.txt") +#define STDERR_FILE TEXT("stderr.txt") + +/* Set a variable to tell if the stdio redirect has been enabled. */ +static int stdioRedirectEnabled = 0; + +#ifdef _WIN32_WCE + static wchar_t stdoutPath[MAX_PATH]; + static wchar_t stderrPath[MAX_PATH]; +#else + static char stdoutPath[MAX_PATH]; + static char stderrPath[MAX_PATH]; +#endif + +#if defined(_WIN32_WCE) && _WIN32_WCE < 300 +/* seems to be undefined in Win CE although in online help */ +#define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) +#endif /* _WIN32_WCE < 300 */ + +static void UnEscapeQuotes( char *arg ) +{ + char *last = NULL; + + while( *arg ) { + if( *arg == '"' && *last == '\\' ) { + char *c_curr = arg; + char *c_last = last; + + while( *c_curr ) { + *c_last = *c_curr; + c_last = c_curr; + c_curr++; + } + *c_last = '\0'; + } + last = arg; + arg++; + } +} + +/* Parse a command line buffer into arguments */ +static int ParseCommandLine(char *cmdline, char **argv) +{ + char *bufp; + char *lastp = NULL; + int argc, last_argc; + + argc = last_argc = 0; + for ( bufp = cmdline; *bufp; ) { + /* Skip leading whitespace */ + while ( isspace(*bufp) ) { + ++bufp; + } + /* Skip over argument */ + if ( *bufp == '"' ) { + ++bufp; + if ( *bufp ) { + if ( argv ) { + argv[argc] = bufp; + } + ++argc; + } + /* Skip over word */ + while ( *bufp && ( *bufp != '"' || (lastp && *lastp == '\\') ) ) { + lastp = bufp; + ++bufp; + } + } else { + if ( *bufp ) { + if ( argv ) { + argv[argc] = bufp; + } + ++argc; + } + /* Skip over word */ + while ( *bufp && ! isspace(*bufp) ) { + ++bufp; + } + } + if ( *bufp ) { + if ( argv ) { + *bufp = '\0'; + } + ++bufp; + } + + /* Strip out \ from \" sequences */ + if( argv && last_argc != argc ) { + UnEscapeQuotes( argv[last_argc] ); + } + last_argc = argc; + } + if ( argv ) { + argv[argc] = NULL; + } + return(argc); +} + +/* Show an error message */ +static void ShowError(const char *title, const char *message) +{ +/* If USE_MESSAGEBOX is defined, you need to link with user32.lib */ +#ifdef USE_MESSAGEBOX + MessageBox(NULL, message, title, MB_ICONEXCLAMATION|MB_OK); +#else + fprintf(stderr, "%s: %s\n", title, message); +#endif +} + +/* Pop up an out of memory message, returns to Windows */ +static BOOL OutOfMemory(void) +{ + ShowError("Fatal Error", "Out of memory - aborting"); + return FALSE; +} + +/* SDL_Quit() shouldn't be used with atexit() directly because + calling conventions may differ... */ +static void cleanup(void) +{ + SDL_Quit(); +} + +/* Remove the output files if there was no output written */ +static void cleanup_output(void) { + FILE *file; + int empty; + + /* Flush the output in case anything is queued */ + fclose(stdout); + fclose(stderr); + + /* Without redirection we're done */ + if (!stdioRedirectEnabled) { + return; + } + + /* See if the files have any output in them */ + if ( stdoutPath[0] ) { + file = fopen(stdoutPath, TEXT("rb")); + if ( file ) { + empty = (fgetc(file) == EOF) ? 1 : 0; + fclose(file); + if ( empty ) { + remove(stdoutPath); + } + } + } + if ( stderrPath[0] ) { + file = fopen(stderrPath, TEXT("rb")); + if ( file ) { + empty = (fgetc(file) == EOF) ? 1 : 0; + fclose(file); + if ( empty ) { + remove(stderrPath); + } + } + } +} + +/* Redirect the output (stdout and stderr) to a file */ +static void redirect_output(void) +{ + DWORD pathlen; +#ifdef _WIN32_WCE + wchar_t path[MAX_PATH]; +#else + char path[MAX_PATH]; +#endif + FILE *newfp; + + pathlen = GetModuleFileName(NULL, path, SDL_arraysize(path)); + while ( pathlen > 0 && path[pathlen] != '\\' ) { + --pathlen; + } + path[pathlen] = '\0'; + +#ifdef _WIN32_WCE + wcsncpy( stdoutPath, path, SDL_arraysize(stdoutPath) ); + wcsncat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); +#else + SDL_strlcpy( stdoutPath, path, SDL_arraysize(stdoutPath) ); + SDL_strlcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); +#endif + + /* Redirect standard input and standard output */ + newfp = freopen(stdoutPath, TEXT("w"), stdout); + +#ifndef _WIN32_WCE + if ( newfp == NULL ) { /* This happens on NT */ +#if !defined(stdout) + stdout = fopen(stdoutPath, TEXT("w")); +#else + newfp = fopen(stdoutPath, TEXT("w")); + if ( newfp ) { + *stdout = *newfp; + } +#endif + } +#endif /* _WIN32_WCE */ + +#ifdef _WIN32_WCE + wcsncpy( stderrPath, path, SDL_arraysize(stdoutPath) ); + wcsncat( stderrPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); +#else + SDL_strlcpy( stderrPath, path, SDL_arraysize(stderrPath) ); + SDL_strlcat( stderrPath, DIR_SEPERATOR STDERR_FILE, SDL_arraysize(stderrPath) ); +#endif + + newfp = freopen(stderrPath, TEXT("w"), stderr); +#ifndef _WIN32_WCE + if ( newfp == NULL ) { /* This happens on NT */ +#if !defined(stderr) + stderr = fopen(stderrPath, TEXT("w")); +#else + newfp = fopen(stderrPath, TEXT("w")); + if ( newfp ) { + *stderr = *newfp; + } +#endif + } +#endif /* _WIN32_WCE */ + + setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ + setbuf(stderr, NULL); /* No buffering */ + stdioRedirectEnabled = 1; +} + +#if defined(_MSC_VER) && !defined(_WIN32_WCE) +/* The VC++ compiler needs main defined */ +#define console_main main +#endif + +/* This is where execution begins [console apps] */ +int console_main(int argc, char *argv[]) +{ + size_t n; + char *bufp, *appname; + int status; + + /* Get the class name from argv[0] */ + appname = argv[0]; + if ( (bufp=SDL_strrchr(argv[0], '\\')) != NULL ) { + appname = bufp+1; + } else + if ( (bufp=SDL_strrchr(argv[0], '/')) != NULL ) { + appname = bufp+1; + } + + if ( (bufp=SDL_strrchr(appname, '.')) == NULL ) + n = SDL_strlen(appname); + else + n = (bufp-appname); + + bufp = SDL_stack_alloc(char, n+1); + if ( bufp == NULL ) { + return OutOfMemory(); + } + SDL_strlcpy(bufp, appname, n+1); + appname = bufp; + + /* Load SDL dynamic link library */ + if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) { + ShowError("WinMain() error", SDL_GetError()); + return(FALSE); + } + atexit(cleanup_output); + atexit(cleanup); + + /* Sam: + We still need to pass in the application handle so that + DirectInput will initialize properly when SDL_RegisterApp() + is called later in the video initialization. + */ + SDL_SetModuleHandle(GetModuleHandle(NULL)); + + /* Run the application main() code */ + status = SDL_main(argc, argv); + + /* Exit cleanly, calling atexit() functions */ + exit(status); + + /* Hush little compiler, don't you cry... */ + return 0; +} + +/* This is where execution begins [windowed apps] */ +#ifdef _WIN32_WCE +int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw) +#else +int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) +#endif +{ + HMODULE handle; + char **argv; + int argc; + char *cmdline; + char *env_str; +#ifdef _WIN32_WCE + wchar_t *bufp; + int nLen; +#else + char *bufp; + size_t nLen; +#endif + + /* Start up DDHELP.EXE before opening any files, so DDHELP doesn't + keep them open. This is a hack.. hopefully it will be fixed + someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded. + */ + handle = LoadLibrary(TEXT("DDRAW.DLL")); + if ( handle != NULL ) { + FreeLibrary(handle); + } + + /* Check for stdio redirect settings and do the redirection */ + if ((env_str = SDL_getenv("SDL_STDIO_REDIRECT"))) { + if (SDL_atoi(env_str)) { + redirect_output(); + } + } +#ifndef NO_STDIO_REDIRECT + else { + redirect_output(); + } +#endif + +#ifdef _WIN32_WCE + nLen = wcslen(szCmdLine)+128+1; + bufp = SDL_stack_alloc(wchar_t, nLen*2); + wcscpy (bufp, TEXT("\"")); + GetModuleFileName(NULL, bufp+1, 128-3); + wcscpy (bufp+wcslen(bufp), TEXT("\" ")); + wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp)); + nLen = wcslen(bufp)+1; + cmdline = SDL_stack_alloc(char, nLen); + if ( cmdline == NULL ) { + return OutOfMemory(); + } + WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL); +#else + /* Grab the command line */ + bufp = GetCommandLine(); + nLen = SDL_strlen(bufp)+1; + cmdline = SDL_stack_alloc(char, nLen); + if ( cmdline == NULL ) { + return OutOfMemory(); + } + SDL_strlcpy(cmdline, bufp, nLen); +#endif + + /* Parse it into argv and argc */ + argc = ParseCommandLine(cmdline, NULL); + argv = SDL_stack_alloc(char*, argc+1); + if ( argv == NULL ) { + return OutOfMemory(); + } + ParseCommandLine(cmdline, argv); + + /* Run the main program (after a little SDL initialization) */ + console_main(argc, argv); + + /* Hush little compiler, don't you cry... */ + return 0; +} diff --git a/distrib/sdl-1.2.15/src/main/win32/version.rc b/distrib/sdl-1.2.15/src/main/win32/version.rc new file mode 100644 index 0000000..38fb642 --- /dev/null +++ b/distrib/sdl-1.2.15/src/main/win32/version.rc @@ -0,0 +1,38 @@ + +#include "winresrc.h" + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,2,14,0 + PRODUCTVERSION 1,2,14,0 + FILEFLAGSMASK 0x3fL + FILEFLAGS 0x0L + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "\0" + VALUE "FileDescription", "SDL\0" + VALUE "FileVersion", "1, 2, 14, 0\0" + VALUE "InternalName", "SDL\0" + VALUE "LegalCopyright", "Copyright 2009 Sam Lantinga\0" + VALUE "OriginalFilename", "SDL.dll\0" + VALUE "ProductName", "Simple DirectMedia Layer\0" + VALUE "ProductVersion", "1, 2, 14, 0\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END -- cgit v1.1