From 518a5ddbf15d50a254c732a80d5907ef8878abe0 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 15 Apr 2015 18:49:45 -0400 Subject: Split all OS backends into their own folders. --- new/darwin/init.m | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 new/darwin/init.m (limited to 'new/darwin/init.m') diff --git a/new/darwin/init.m b/new/darwin/init.m new file mode 100644 index 0000000..4f14a0a --- /dev/null +++ b/new/darwin/init.m @@ -0,0 +1,67 @@ +// 6 april 2015 +#import "uipriv_darwin.h" + +@interface uiApplication : NSApplication +@end + +@implementation uiApplication + +// hey look! we're overriding terminate:! +// we're going to make sure we can go back to main() whether Cocoa likes it or not! +// and just how are we going to do that, hm? +// (note: this is called after applicationShouldTerminate:) +- (void)terminate:(id)sender +{ + // yes that's right folks: DO ABSOLUTELY NOTHING. + // the magic is [NSApp run] will just... stop. + + // for debugging + NSLog(@"in terminate:"); +} + +@end + +@interface uiAppDelegate : NSObject +@end + +@implementation uiAppDelegate + +- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app +{ + // for debugging + NSLog(@"in applicationShouldTerminate:"); + return NSTerminateNow; +} + +- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app +{ + return NO; +} + +@end + +// we are not in control of the actual lifetimes and refcounts of NSViews (see http://stackoverflow.com/a/29523141/3408572) +// when we're done with a view, it'll be added as a subview of this one, and this one will be released on application shutdown +// we need this separate view because it's possible for controls to have no parent but still be alive +NSView *destroyedControlsView; + +uiInitOptions options; + +const char *uiInit(uiInitOptions *o) +{ + options = *o; + [uiApplication 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:[uiAppDelegate new]]; + + // we can use a stock NSView for this + destroyedControlsView = [[NSView alloc] initWithFrame:NSZeroRect]; + + return NULL; +} + +void uiFreeInitError(const char *err) +{ +} -- cgit v1.2.3