diff options
Diffstat (limited to 'platform/osx/godot_osx.mm')
-rw-r--r-- | platform/osx/godot_osx.mm | 212 |
1 files changed, 102 insertions, 110 deletions
diff --git a/platform/osx/godot_osx.mm b/platform/osx/godot_osx.mm index 76762213bf..626406ad1d 100644 --- a/platform/osx/godot_osx.mm +++ b/platform/osx/godot_osx.mm @@ -27,144 +27,139 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "godot_osx.h" + #include <sys/param.h> /* for MAXPATHLEN */ #include <unistd.h> -#include "godot_osx.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() +@interface NSApplication () - (void)setAppleMenu:(NSMenu *)menu; @end -static int global_argc; -static char **global_argv; -static BOOL gCalledAppMainline = FALSE; +static int global_argc; +static char **global_argv; +static BOOL gCalledAppMainline = FALSE; -static NSString *getApplicationName(void) -{ - const NSDictionary *dict; - NSString *appName = 0; +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"]; + /* Determine the application name */ + dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); + if (dict) + appName = [dict objectForKey:@"CFBundleName"]; - if (![appName length]) - appName = [[NSProcessInfo processInfo] processName]; + if (![appName length]) + appName = [[NSProcessInfo processInfo] processName]; - return appName; + return appName; } /* The main class of the application, the application's delegate */ @implementation GodotMain -static void setApplicationMenu(void) -{ - /* warning: this code is very odd */ - NSMenu *appleMenu; - NSMenuItem *menuItem; - NSString *title; - NSString *appName; +static void setApplicationMenu(void) { + /* warning: this code is very odd */ + NSMenu *appleMenu; + NSMenuItem *menuItem; + NSString *title; + NSString *appName; - appName = getApplicationName(); - appleMenu = [[NSMenu alloc] initWithTitle:@""]; + appName = getApplicationName(); + appleMenu = [[NSMenu alloc] initWithTitle:@""]; - /* Add menu items */ - title = [@"About " stringByAppendingString:appName]; - [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; + /* Add menu items */ + title = [@"About " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; - [appleMenu addItem:[NSMenuItem separatorItem]]; + [appleMenu addItem:[NSMenuItem separatorItem]]; - title = [@"Hide " stringByAppendingString:appName]; - [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; + 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)]; + menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; + [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask)]; - [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; + [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; - [appleMenu addItem:[NSMenuItem separatorItem]]; + [appleMenu addItem:[NSMenuItem separatorItem]]; - title = [@"Quit " stringByAppendingString:appName]; - [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; + 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]; - /* 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]; - /* 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]; + /* 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]; +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]; - GodotMain *main; +static void CustomApplicationMain(int argc, char **argv) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + GodotMain *main; - /* Ensure the application object is initialised */ - [NSApplication sharedApplication]; + /* Ensure the application object is initialised */ + [NSApplication sharedApplication]; - /* Set up the menubar */ - [NSApp setMainMenu:[[NSMenu alloc] init]]; - setApplicationMenu(); - setupWindowMenu(); + /* Set up the menubar */ + [NSApp setMainMenu:[[NSMenu alloc] init]]; + setApplicationMenu(); + setupWindowMenu(); main = [[main alloc] init]; [NSApp setDelegate:main]; - /* Start the main event loop */ - [NSApp run]; + /* Start the main event loop */ + [NSApp run]; [main release]; - [pool release]; + [pool release]; } -extern int godot_main(int argc, char** argv); +extern int godot_main(int argc, char **argv); /* Called when the internal event loop has just started running */ -- (void) applicationDidFinishLaunching: (NSNotification *) note -{ - int status; +- (void)applicationDidFinishLaunching:(NSNotification *)note { + int status; - /* Hand off to main application code */ - gCalledAppMainline = TRUE; + /* Hand off to main application code */ + gCalledAppMainline = TRUE; int ret = godot_main(global_argc, global_argv); @@ -173,16 +168,14 @@ extern int godot_main(int argc, char** argv); @end #ifdef main -# undef main +#undef main #endif - -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 ) { - global_argv = (char **) malloc(sizeof (char *) * 2); +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) { + global_argv = (char **)malloc(sizeof(char *) * 2); global_argv[0] = argv[0]; global_argv[1] = NULL; global_argc = 1; @@ -190,27 +183,26 @@ int main (int argc, char **argv) // chdir to binary's dir when launched from finder int len = strlen(global_argv[0]); - while (len--){ + while (len--) { if (global_argv[0][len] == '/') break; } - if (len>=0) { - char *path = (char *)malloc(len+1); + if (len >= 0) { + char *path = (char *)malloc(len + 1); memcpy(path, global_argv[0], len); - path[len]=0; + path[len] = 0; printf("Path: %s\n", path); chdir(path); } - } else { - int i; + } else { + int i; global_argc = argc; - global_argv = (char **) malloc(sizeof (char *) * (argc+1)); - for (i = 0; i <= argc; i++) + global_argv = (char **)malloc(sizeof(char *) * (argc + 1)); + for (i = 0; i <= argc; i++) global_argv[i] = argv[i]; - } + } - CustomApplicationMain (argc, argv); - return 0; + CustomApplicationMain(argc, argv); + return 0; } - |