blob: 21287cf96127bbfb17f5dde06887eedcf79ae66c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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];
}
|