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).
This commit is contained in:
parent
ce96272f03
commit
e1e9dddfdd
|
@ -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()];
|
||||
}
|
||||
|
|
|
@ -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]];
|
||||
|
||||
|
|
|
@ -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 <NSApplicationDelegate>
|
||||
@property (strong) menuManager *menuManager;
|
||||
@end
|
||||
#define appDelegate() ((appDelegate *) [NSApp delegate])
|
||||
#define appDelegate() ((appDelegate *) [realNSApp() delegate])
|
||||
|
||||
// util.m
|
||||
extern void setStandardControlFont(NSControl *);
|
||||
|
|
Loading…
Reference in New Issue