diff options
| author | Pietro Gagliardi <[email protected]> | 2015-12-11 20:37:59 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2015-12-11 20:37:59 -0500 |
| commit | f8e3f12ab02b528f2a05a4f713d7af7ea8e44b42 (patch) | |
| tree | 82dedf4d37f0f6d31e88ebb2ca1ce6499dead261 /prev/window_darwin.m | |
| parent | e34c561ed5bedeb180437ec165882b98d70d38c1 (diff) | |
LET'S GET THIS FINAL REWRITE EVER STARTED
Diffstat (limited to 'prev/window_darwin.m')
| -rw-r--r-- | prev/window_darwin.m | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/prev/window_darwin.m b/prev/window_darwin.m new file mode 100644 index 0000000..21287cf --- /dev/null +++ b/prev/window_darwin.m @@ -0,0 +1,86 @@ +// 8 july 2014 + +#import "objc_darwin.h" +#import "_cgo_export.h" +#import <Cocoa/Cocoa.h> + +#define toNSWindow(x) ((NSWindow *) (x)) +#define toNSView(x) ((NSView *) (x)) + +@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) +{ + NSWindow *w; + NSTextView *tv; + + w = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height) + styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask) + backing:NSBackingStoreBuffered + defer:YES]; + // we do not want substitutions + // text fields, labels, etc. take their smart quotes and other autocorrect settings from their parent window, which provides a shared "field editor" + // so we have to turn them off here + // thanks akempgen in irc.freenode.net/#macdev + // for some reason, this selector returns NSText but is documented to return NSTextView... + disableAutocorrect((id) [w fieldEditor:YES forObject:nil]); + return w; +} + +void windowSetDelegate(id win, void *w) +{ + goWindowDelegate *d; + + d = [goWindowDelegate new]; + d->gowin = w; + [toNSWindow(win) setDelegate:d]; +} + +void windowSetContentView(id win, id view) +{ + [toNSWindow(win) setContentView:toNSView(view)]; +} + +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) +{ + [toNSWindow(win) makeKeyAndOrderFront:toNSWindow(win)]; + // no need to worry about reshowing the window initially; that's handled by our container view (container_darwin.m) +} + +void windowHide(id win) +{ + [toNSWindow(win) orderOut:toNSWindow(win)]; +} + +void windowClose(id win) +{ + [toNSWindow(win) close]; +} + +id windowContentView(id win) +{ + return (id) [toNSWindow(win) contentView]; +} |
