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.

This commit is contained in:
Pietro Gagliardi 2014-07-08 17:43:50 -04:00
parent edd81e2e48
commit 44811e5351
3 changed files with 37 additions and 6 deletions

View File

@ -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);

View File

@ -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 }

View File

@ -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)