Migrated the Mac OS X delegate code to the new API.

This commit is contained in:
Pietro Gagliardi 2014-06-29 03:09:01 -04:00
parent c807771092
commit dff7ed3321
2 changed files with 18 additions and 15 deletions

View File

@ -24,9 +24,11 @@ func makeAppDelegate() {
}
//export appDelegate_windowShouldClose
func appDelegate_windowShouldClose(win C.id) {
func appDelegate_windowShouldClose(win C.id) C.BOOL {
sysData := getSysData(win)
sysData.signal()
b := false // TODO
sysData.close(&b)
return toBOOL(b)
}
//export appDelegate_windowDidResize
@ -42,13 +44,5 @@ func appDelegate_windowDidResize(win C.id) {
//export appDelegate_buttonClicked
func appDelegate_buttonClicked(button C.id) {
sysData := getSysData(button)
sysData.signal()
}
//export appDelegate_applicationShouldTerminate
func appDelegate_applicationShouldTerminate() {
// asynchronous so as to return control to the event loop
go func() {
AppQuit <- struct{}{}
}()
sysData.event()
}

View File

@ -63,8 +63,7 @@ extern NSRect dummyRect;
- (BOOL)windowShouldClose:(id)win
{
appDelegate_windowShouldClose(win);
return NO; // don't close
return appDelegate_windowShouldClose(win);
}
- (void)windowDidResize:(NSNotification *)n
@ -79,8 +78,18 @@ extern NSRect dummyRect;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app
{
appDelegate_applicationShouldTerminate();
return NSTerminateCancel;
NSArray *windows;
NSUInteger i;
// try to close all windows
windows = [NSApp windows];
for (i = 0; i < [windows count]; i++)
[[windows objectAtIndex:i] performClose:self];
// if any windows are left, cancel
if ([[NSApp windows] count] != 0)
return NSTerminateCancel;
// no windows are left; we're good
return NSTerminateNow;
}
- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)chan