+- (void)applicationWillFinishLaunching:(NSApplication *)sender;
+
+- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename;
+- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender;
+- (BOOL)application:(NSApplication *)sender printFile:(NSString *)filename;
+- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event
+ withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
+
+- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender;
+- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
+- (void)applicationWillTerminate:(NSApplication *)sender;
+@end
+
+@implementation wxNSAppController
+
+- (void)applicationWillFinishLaunching:(NSApplication *)application {
+ wxUnusedVar(application);
+}
+
+- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename;
+{
+ wxUnusedVar(sender);
+ wxCFStringRef cf(wxCFRetain(filename));
+ wxTheApp->MacOpenFile(cf.AsString()) ;
+ return YES;
+}
+
+- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender;
+{
+ wxUnusedVar(sender);
+ wxTheApp->MacNewFile() ;
+ return NO;
+}
+
+- (BOOL)application:(NSApplication *)sender printFile:(NSString *)filename
+{
+ wxUnusedVar(sender);
+ wxCFStringRef cf(wxCFRetain(filename));
+ wxTheApp->MacPrintFile(cf.AsString()) ;
+ return YES;
+}
+
+- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag
+{
+ wxUnusedVar(flag);
+ wxUnusedVar(sender);
+ wxTheApp->MacReopenApp() ;
+ return NO;
+}
+
+- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event
+ withReplyEvent:(NSAppleEventDescriptor *)replyEvent
+{
+ wxUnusedVar(replyEvent);
+ NSString* url = [[event descriptorAtIndex:1] stringValue];
+ wxCFStringRef cf(wxCFRetain(url));
+ wxTheApp->MacOpenURL(cf.AsString()) ;
+}
+
+/*
+ Allowable return values are:
+ NSTerminateNow - it is ok to proceed with termination
+ NSTerminateCancel - the application should not be terminated
+ NSTerminateLater - it may be ok to proceed with termination later. The application must call -replyToApplicationShouldTerminate: with YES or NO once the answer is known
+ this return value is for delegates who need to provide document modal alerts (sheets) in order to decide whether to quit.
+*/
+- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
+{
+ wxUnusedVar(sender);
+ wxCloseEvent event;
+ wxTheApp->OnQueryEndSession(event);
+ if ( event.GetVeto() )
+ return NSTerminateCancel;
+
+ return NSTerminateNow;
+}
+
+- (void)applicationWillTerminate:(NSApplication *)application {
+ wxUnusedVar(application);
+ wxCloseEvent event;
+ event.SetCanVeto(false);
+ wxTheApp->OnEndSession(event);
+}
+
+- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
+{
+ wxUnusedVar(sender);
+ // let wx do this, not cocoa
+ return NO;
+}
+
+@end
+
+/*
+ allows ShowModal to work when using sheets.
+ see include/wx/osx/cocoa/private.h for more info
+*/
+@implementation ModalDialogDelegate
+- (id)init
+{
+ [super init];
+ sheetFinished = NO;
+ resultCode = -1;
+ impl = 0;
+ return self;
+}
+
+- (void)setImplementation: (wxDialog *)dialog
+{
+ impl = dialog;
+}
+
+- (BOOL)finished
+{
+ return sheetFinished;
+}
+
+- (int)code
+{
+ return resultCode;
+}
+
+- (void)waitForSheetToFinish
+{
+ while (!sheetFinished)
+ {
+ wxSafeYield();
+ }
+}
+
+- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
+{
+ wxUnusedVar(contextInfo);
+ resultCode = returnCode;
+ sheetFinished = YES;
+ // NSAlerts don't need nor respond to orderOut
+ if ([sheet respondsToSelector:@selector(orderOut:)])
+ [sheet orderOut: self];
+
+ if (impl)
+ impl->ModalFinishedCallback(sheet, returnCode);
+}
+@end
+