From e1e9dddfddaeba49bae60249ad3cb113f7f1104e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 10 May 2015 14:27:25 -0400 Subject: [PATCH] Fixed some more warnings on the OS X backend. This also introduces realNSApp() and makes applicationClass global, which is important for fixing a few other TODOs (the setAppleMenu: one, for instance). --- darwin/main.m | 17 +++++++---------- darwin/menu.m | 6 +++--- darwin/uipriv_darwin.h | 6 +++++- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/darwin/main.m b/darwin/main.m index 2a977261..172e5844 100644 --- a/darwin/main.m +++ b/darwin/main.m @@ -3,9 +3,6 @@ static BOOL canQuit = NO; -@interface applicationClass : NSApplication -@end - @implementation applicationClass // hey look! we're overriding terminate:! @@ -26,7 +23,7 @@ static BOOL canQuit = NO; if (!canQuit) complain("call to [NSApp terminate:] when not ready to terminate"); - [NSApp stop:NSApp]; + [realNSApp() stop:realNSApp()]; // stop: won't register until another event has passed; let's synthesize one e = [NSEvent otherEventWithType:NSApplicationDefined location:NSZeroPoint @@ -37,7 +34,7 @@ static BOOL canQuit = NO; subtype:0 data1:0 data2:0]; - [NSApp postEvent:e atStart:NO]; // let pending events take priority (this is what PostQuitMessage() on Windows does so we have to do it here too for parity; thanks to mikeash in irc.freenode.net/#macdev for confirming that this parameter should indeed be NO) + [realNSApp() postEvent:e atStart:NO]; // let pending events take priority (this is what PostQuitMessage() on Windows does so we have to do it here too for parity; thanks to mikeash in irc.freenode.net/#macdev for confirming that this parameter should indeed be NO) } @end @@ -77,14 +74,14 @@ const char *uiInit(uiInitOptions *o) [applicationClass sharedApplication]; // don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy! // see https://github.com/andlabs/ui/issues/6 - [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; - [NSApp setDelegate:[appDelegate new]]; + [realNSApp() setActivationPolicy:NSApplicationActivationPolicyRegular]; + [realNSApp() setDelegate:[appDelegate new]]; initAlloc(); // always do this so we always have an application menu appDelegate().menuManager = [menuManager new]; - [NSApp setMainMenu:[appDelegate().menuManager makeMenubar]]; + [realNSApp() setMainMenu:[appDelegate().menuManager makeMenubar]]; return NULL; } @@ -103,11 +100,11 @@ void uiFreeInitError(const char *err) void uiMain(void) { - [NSApp run]; + [realNSApp() run]; } void uiQuit(void) { canQuit = YES; - [NSApp terminate:NSApp]; + [realNSApp() terminate:realNSApp()]; } diff --git a/darwin/menu.m b/darwin/menu.m index d5cb84b8..db789466 100644 --- a/darwin/menu.m +++ b/darwin/menu.m @@ -61,7 +61,7 @@ enum { if (item->type == typeCheckbox) uiMenuItemSetChecked(uiMenuItem(item), !uiMenuItemChecked(uiMenuItem(item))); // use the key window as the source of the menu event; it's the active window - (*(item->onClicked))(uiMenuItem(item), windowFromNSWindow([NSApp keyWindow]), item->onClickedData); + (*(item->onClicked))(uiMenuItem(item), windowFromNSWindow([realNSApp() keyWindow]), item->onClickedData); } - (IBAction)onQuitClicked:(id)sender @@ -153,7 +153,7 @@ enum { item = [[NSMenuItem alloc] initWithTitle:@"Services" action:NULL keyEquivalent:@""]; servicesMenu = [[NSMenu alloc] initWithTitle:@"Services"]; [item setSubmenu:servicesMenu]; - [NSApp setServicesMenu:servicesMenu]; + [realNSApp() setServicesMenu:servicesMenu]; [appMenu addItem:item]; [appMenu addItem:[NSMenuItem separatorItem]]; @@ -337,7 +337,7 @@ uiMenu *uiNewMenu(const char *name) m->items = [NSMutableArray new]; - [[NSApp mainMenu] addItem:m->item]; + [[realNSApp() mainMenu] addItem:m->item]; [menus addObject:[NSValue valueWithPointer:m]]; diff --git a/darwin/uipriv_darwin.h b/darwin/uipriv_darwin.h index 7a0f5f12..17f282ac 100644 --- a/darwin/uipriv_darwin.h +++ b/darwin/uipriv_darwin.h @@ -33,10 +33,14 @@ extern void finalizeMenus(void); extern void uninitMenus(void); // init.m +@interface applicationClass : NSApplication +@end +// this is needed because NSApp is of type id, confusing clang +#define realNSApp() ((applicationClass *) NSApp) @interface appDelegate : NSObject @property (strong) menuManager *menuManager; @end -#define appDelegate() ((appDelegate *) [NSApp delegate]) +#define appDelegate() ((appDelegate *) [realNSApp() delegate]) // util.m extern void setStandardControlFont(NSControl *);