Cleanup. Fix beeping when pressing certain keys while windowed. It still beeps in full screen and command key presses beep all the time.

I need to just replace SDL entirely to fix this. LowLevelWindow is all that remains.
This commit is contained in:
Steve Checkoway
2005-10-24 13:41:01 +00:00
parent 7280c1ccb3
commit 04d79278d4
+13 -74
View File
@@ -10,40 +10,14 @@
#import <sys/param.h> /* for MAXPATHLEN */ #import <sys/param.h> /* for MAXPATHLEN */
#import <unistd.h> #import <unistd.h>
/* 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 int gArgc;
static char **gArgv; static char **gArgv;
static BOOL gFinderLaunch; static BOOL gFinderLaunch;
#if SDL_USE_NIB_FILE
/* A helper category for NSString */
@interface NSString (ReplaceSubString)
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
@end
#else
/* An internal Apple class used to setup Apple menus */ /* An internal Apple class used to setup Apple menus */
@interface NSAppleMenuController:NSObject {} @interface NSAppleMenuController : NSObject {}
- (void)controlMenu:(NSMenu *)aMenu; - (void)controlMenu:(NSMenu *)aMenu;
@end @end
#endif
@interface SDLApplication : NSApplication @interface SDLApplication : NSApplication
@end @end
@@ -59,14 +33,25 @@ static BOOL gFinderLaunch;
} }
@end @end
@interface HelperWindow : NSWindow
@end
@implementation HelperWindow
/* Override NSWindow's keyDown to keep it from beeping. */
- (void) keyDown:(NSEvent *)event
{
}
@end
/* The main class of the application, the application's delegate */ /* The main class of the application, the application's delegate */
@implementation SDLMain @implementation SDLMain
- (void) startGame:(id)obj - (void) startGame:(id)obj
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
/* Hand off to main application code */ /* Hand off to main application code */
exit(SDL_main (gArgc, gArgv)); exit(SDL_main (gArgc, gArgv));
[pool release]; // not really needed, but shuts gcc up.
} }
/* Set the working directory to the .app's parent directory */ /* Set the working directory to the .app's parent directory */
@@ -94,32 +79,6 @@ static BOOL gFinderLaunch;
} }
} }
#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];
}
[ aMenu sizeToFit ];
}
#else
void setupAppleMenu(void) void setupAppleMenu(void)
{ {
@@ -183,17 +142,6 @@ void CustomApplicationMain (int argc, char **argv)
/* Ensure the application object is initialised */ /* Ensure the application object is initialised */
[SDLApplication sharedApplication]; [SDLApplication 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))
[SDLApplication sharedApplication];
}
#endif /* SDL_USE_CPS */
/* Set up the menubar */ /* Set up the menubar */
[NSApp setMainMenu:[[NSMenu alloc] init]]; [NSApp setMainMenu:[[NSMenu alloc] init]];
setupAppleMenu(); setupAppleMenu();
@@ -210,7 +158,6 @@ void CustomApplicationMain (int argc, char **argv)
[pool release]; [pool release];
} }
#endif
/* Called when the internal event loop has just started running */ /* Called when the internal event loop has just started running */
- (void) applicationDidFinishLaunching: (NSNotification *) note - (void) applicationDidFinishLaunching: (NSNotification *) note
@@ -218,11 +165,6 @@ void CustomApplicationMain (int argc, char **argv)
/* Set the working directory to the .app's parent directory */ /* Set the working directory to the .app's parent directory */
[self setupWorkingDirectory:gFinderLaunch]; [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:[[NSProcessInfo processInfo] processName]];
#endif
#if 1 #if 1
[NSThread detachNewThreadSelector:@selector(startGame:) toTarget:self withObject:nil]; [NSThread detachNewThreadSelector:@selector(startGame:) toTarget:self withObject:nil];
#else #else
@@ -302,11 +244,8 @@ int main (int argc, char **argv)
gArgv[i] = argv[i]; gArgv[i] = argv[i];
gArgv[i] = NULL; gArgv[i] = NULL;
#if SDL_USE_NIB_FILE [HelperWindow poseAsClass:[NSWindow class]];
[SDLApplication poseAsClass:[NSApplication class]]; [SDLApplication poseAsClass:[NSApplication class]];
NSApplicationMain (argc, argv);
#else
CustomApplicationMain (argc, argv); CustomApplicationMain (argc, argv);
#endif
return 0; return 0;
} }