2014-07-08 15:47:28 -05:00
|
|
|
// 8 july 2014
|
|
|
|
|
|
|
|
#import "objc_darwin.h"
|
|
|
|
#import "_cgo_export.h"
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#define toNSWindow(x) ((NSWindow *) (x))
|
|
|
|
|
2014-07-08 16:43:50 -05:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2014-07-15 13:04:20 -05:00
|
|
|
- (void)windowDidResize:(NSNotification *)n
|
2014-07-18 14:16:41 -05:00
|
|
|
{
|
|
|
|
[self doWindowResize:[n object]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)doWindowResize:(id)win
|
2014-07-15 13:04:20 -05:00
|
|
|
{
|
|
|
|
NSWindow *w;
|
|
|
|
NSRect r;
|
|
|
|
|
2014-07-18 14:16:41 -05:00
|
|
|
w = toNSWindow(win);
|
2014-07-15 13:04:20 -05:00
|
|
|
r = [[w contentView] frame];
|
|
|
|
windowResized(self->gowin, (uintptr_t) r.size.width, (uintptr_t) r.size.height);
|
|
|
|
}
|
|
|
|
|
2014-07-08 16:43:50 -05:00
|
|
|
@end
|
|
|
|
|
2014-07-08 15:47:28 -05:00
|
|
|
id newWindow(intptr_t width, intptr_t height)
|
|
|
|
{
|
|
|
|
return [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height)
|
|
|
|
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:YES];
|
|
|
|
}
|
|
|
|
|
2014-07-08 16:43:50 -05:00
|
|
|
void windowSetDelegate(id win, void *w)
|
2014-07-08 15:47:28 -05:00
|
|
|
{
|
2014-07-08 16:43:50 -05:00
|
|
|
goWindowDelegate *d;
|
|
|
|
|
|
|
|
d = [goWindowDelegate new];
|
|
|
|
d->gowin = w;
|
|
|
|
[toNSWindow(win) setDelegate:d];
|
2014-07-08 15:47:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *windowTitle(id win)
|
|
|
|
{
|
|
|
|
return [[toNSWindow(win) title] UTF8String];
|
|
|
|
}
|
|
|
|
|
|
|
|
void windowSetTitle(id win, const char * title)
|
|
|
|
{
|
|
|
|
[toNSWindow(win) setTitle:[NSString stringWithUTF8String:title]];
|
|
|
|
}
|
|
|
|
|
|
|
|
void windowShow(id win)
|
|
|
|
{
|
2014-07-18 14:19:55 -05:00
|
|
|
goWindowDelegate *d;
|
|
|
|
|
2014-07-08 15:47:28 -05:00
|
|
|
[toNSWindow(win) makeKeyAndOrderFront:toNSWindow(win)];
|
2014-07-18 14:16:41 -05:00
|
|
|
// calling the above the first time won't emit a size changed event (unlike on Windows and GTK+), so fake one to get the controls laid out properly
|
2014-07-18 14:19:55 -05:00
|
|
|
d = [toNSWindow(win) delegate];
|
|
|
|
[d doWindowResize:win];
|
2014-07-08 15:47:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void windowHide(id win)
|
|
|
|
{
|
|
|
|
[toNSWindow(win) orderOut:toNSWindow(win)];
|
|
|
|
}
|
|
|
|
|
|
|
|
void windowClose(id win)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|