VBoxSDLMain-darwin.m revision 67b414aa650cb27688d387c2184f8488d801cd72
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
Feel free to customize this file to suit your needs
*/
#import "SDL.h"
#import "VBoxSDLMain-darwin.h"
#import <sys/param.h> /* for MAXPATHLEN */
#import <unistd.h>
/* 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)
@end
/* Use this flag to determine whether we use SDLMain.nib or not */
/* Use this flag to determine whether we use CPS (docking) or not */
/* Portions of CPS.h */
{
extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
#endif /* SDL_USE_CPS */
static int gArgc;
static char **gArgv;
static BOOL gFinderLaunch;
static NSString *getApplicationName(void)
{
/* Determine the application name */
if (dict)
return appName;
}
#if SDL_USE_NIB_FILE
/* A helper category for NSString */
@interface NSString (ReplaceSubString)
@end
@interface SDLApplication : NSApplication
@end
/* Invoked from the Quit menu item */
{
/* Post a SDL_QUIT event */
}
@end
/* The main class of the application, the application's delegate */
/* Set the working directory to the .app's parent directory */
{
if (shouldChdir)
{
char parentdir[MAXPATHLEN];
}
}
}
#if SDL_USE_NIB_FILE
/* Fix menu to contain the real app name instead of "SDL App" */
{
{
if ([menuItem hasSubmenu])
}
}
#else
static void setApplicationMenu(void)
{
/* warning: this code is very odd */
/* Add menu items */
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
/* Put menu into the menubar */
/* Tell the application object that this is now the application menu */
/* Finally give up our references to the objects */
}
/* Create a window menu */
static void setupWindowMenu(void)
{
/* "Minimize" item */
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
/* Put menu into the menubar */
/* Tell the application object that this is now the window menu */
/* Finally give up our references to the objects */
}
/* Replacement for NSApplicationMain */
{
/* Ensure the application object is initialised */
{
/* Tell the dock about us */
if (!CPSGetCurrentProcess(&PSN))
if (!CPSSetFrontProcess(&PSN))
}
#endif /* SDL_USE_CPS */
/* Set up the menubar */
/* Create SDLMain and make it the app delegate */
/* Start the main event loop */
}
/*
* Catch document open requests...this lets us notice files when the app
* was launched by double-clicking a document, or when a document was
* 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.
*/
{
const char *temparg;
char *arg;
char **newargv;
if (!gFinderLaunch) /* MacOS is passing command line args. */
return FALSE;
if (gCalledAppMainline) /* app has started, ignore this document. */
return FALSE;
return FALSE;
{
return FALSE;
}
return TRUE;
}
/* Called when the internal event loop has just started running */
{
int status;
/* Set the working directory to the .app's parent directory */
#if SDL_USE_NIB_FILE
/* Set the main menu to contain the real app name instead of "SDL App" */
/* Hand off to main application code */
/* We're done, thank you for playing */
}
@end
{
unsigned int bufferSize;
/* Get first part into buffer */
/* Get middle part into buffer */
/* Get last part into buffer */
/* Build output string */
return result;
}
@end
/* Main entry point to executable - should *not* be SDL_main! */
{
/* Copy the arguments into a global variable */
/* This is passed if we are launched by double-clicking */
gArgc = 1;
gFinderLaunch = YES;
} else {
int i;
for (i = 0; i <= argc; i++)
gFinderLaunch = NO;
}
#if SDL_USE_NIB_FILE
#else
return 0;
}