summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-29 03:09:01 -0400
committerPietro Gagliardi <[email protected]>2014-06-29 03:09:01 -0400
commitdff7ed33218f40980b7da57d730c47a43dd27522 (patch)
treeaf1d4f7b0058102c2aa57d4985e02b849dcd4482
parentc807771092db14e46067084308d500ec87a74982 (diff)
Migrated the Mac OS X delegate code to the new API.
-rw-r--r--delegate_darwin.go16
-rw-r--r--delegateuitask_darwin.m17
2 files changed, 18 insertions, 15 deletions
diff --git a/delegate_darwin.go b/delegate_darwin.go
index 7d21c3d..27031c3 100644
--- a/delegate_darwin.go
+++ b/delegate_darwin.go
@@ -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()
}
diff --git a/delegateuitask_darwin.m b/delegateuitask_darwin.m
index ed912eb..84be5be 100644
--- a/delegateuitask_darwin.m
+++ b/delegateuitask_darwin.m
@@ -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