summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redo/objc_darwin.h2
-rw-r--r--redo/window_darwin.go17
-rw-r--r--redo/window_darwin.m24
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)