diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-08 17:43:50 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-08 17:44:08 -0400 |
| commit | 44811e5351c13917f400fe5eed0145e224f0c43e (patch) | |
| tree | a06e521b64197002196737f09c0f781c38654fb2 | |
| parent | edd81e2e48d4e2c14820370dd5829fecaf19d387 (diff) | |
Implemented window closing on Mac OS X. This drops the "single delegate object for everything" setup but keeping that map and holding its lock is already meh so.
| -rw-r--r-- | redo/objc_darwin.h | 2 | ||||
| -rw-r--r-- | redo/window_darwin.go | 17 | ||||
| -rw-r--r-- | redo/window_darwin.m | 24 |
3 files changed, 37 insertions, 6 deletions
diff --git a/redo/objc_darwin.h b/redo/objc_darwin.h index b3d362d..3b33e26 100644 --- a/redo/objc_darwin.h +++ b/redo/objc_darwin.h @@ -18,7 +18,7 @@ extern void issue(void *); /* window_darwin.m */ extern id newWindow(intptr_t, intptr_t); -extern void windowSetAppDelegate(id); +extern void windowSetDelegate(id, void *); extern const char *windowTitle(id); extern void windowSetTitle(id, const char *); extern void windowShow(id); diff --git a/redo/window_darwin.go b/redo/window_darwin.go index c6d9585..c3d4521 100644 --- a/redo/window_darwin.go +++ b/redo/window_darwin.go @@ -23,11 +23,12 @@ func newWindow(title string, width int, height int) *Request { ctitle := C.CString(title) defer C.free(unsafe.Pointer(ctitle)) C.windowSetTitle(id, ctitle) - C.windowSetAppDelegate(id) - c <- &window{ + w := &window{ id: id, closing: newEvent(), } + C.windowSetDelegate(id, unsafe.Pointer(w)) + c <- w }, resp: c, } @@ -112,7 +113,17 @@ func (w *window) OnClosing(e func(c Doer) bool) *Request { } } -// TODO windowClosing +//export windowClosing +func windowClosing(xw unsafe.Pointer) C.BOOL { + w := (*window)(unsafe.Pointer(xw)) + close := w.closing.fire() + if close { + // TODO make sure this actually closes the window the way we want + return C.YES + } + return C.NO +} + // TODO for testing func newButton(string) *Request { return nil } diff --git a/redo/window_darwin.m b/redo/window_darwin.m index 870243c..d0b1347 100644 --- a/redo/window_darwin.m +++ b/redo/window_darwin.m @@ -6,6 +6,22 @@ #define toNSWindow(x) ((NSWindow *) (x)) +// TODO why do I need the explicit interface specification? +@interface goWindowDelegate : NSObject <NSWindowDelegate> { +@public + void *gowin; +} +@end + +@implementation goWindowDelegate + +- (BOOL)windowShouldClose:(id)win +{ + return windowClosing(self->gowin); +} + +@end + id newWindow(intptr_t width, intptr_t height) { return [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height) @@ -14,9 +30,13 @@ id newWindow(intptr_t width, intptr_t height) defer:YES]; } -void windowSetAppDelegate(id win) +void windowSetDelegate(id win, void *w) { - [toNSWindow(win) setDelegate:getAppDelegate()]; + goWindowDelegate *d; + + d = [goWindowDelegate new]; + d->gowin = w; + [toNSWindow(win) setDelegate:d]; } const char *windowTitle(id win) |
