2014-07-16 12:25:09 -05:00
|
|
|
// 16 july 2014
|
|
|
|
|
|
|
|
#import "objc_darwin.h"
|
|
|
|
#import "_cgo_export.h"
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#define toNSView(x) ((NSView *) (x))
|
|
|
|
#define toNSWindow(x) ((NSWindow *) (x))
|
2014-07-18 10:47:48 -05:00
|
|
|
#define toNSControl(x) ((NSControl *) (x))
|
2014-07-16 12:25:09 -05:00
|
|
|
#define toNSButton(x) ((NSButton *) (x))
|
|
|
|
|
|
|
|
void unparent(id control)
|
|
|
|
{
|
2014-07-22 16:45:29 -05:00
|
|
|
NSWindow *old;
|
|
|
|
|
2014-07-16 12:25:09 -05:00
|
|
|
[toNSView(control) retain]; // save from being freed when released by the removal selector below
|
2014-07-22 16:45:29 -05:00
|
|
|
old = [toNSView(control) window];
|
2014-07-16 12:25:09 -05:00
|
|
|
[toNSView(control) removeFromSuperview];
|
2014-07-22 16:45:29 -05:00
|
|
|
// redraw since we changed controls
|
|
|
|
windowRedraw((id) old);
|
2014-07-16 12:25:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void parent(id control, id parentid, BOOL floating)
|
|
|
|
{
|
|
|
|
[[toNSWindow(parentid) contentView] addSubview:toNSView(control)];
|
|
|
|
if (floating) // previously unparented
|
|
|
|
[toNSView(control) release];
|
2014-07-22 16:45:29 -05:00
|
|
|
// redraw since we changed controls
|
|
|
|
windowRedraw(parentid);
|
2014-07-16 12:25:09 -05:00
|
|
|
}
|
|
|
|
|
2014-07-18 10:47:48 -05:00
|
|
|
static inline void setStandardControlFont(id control)
|
|
|
|
{
|
|
|
|
[toNSControl(control) setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
|
|
|
|
}
|
|
|
|
|
2014-07-17 11:02:39 -05:00
|
|
|
@interface goControlDelegate : NSObject {
|
|
|
|
@public
|
|
|
|
void *gocontrol;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation goControlDelegate
|
|
|
|
|
|
|
|
- (IBAction)buttonClicked:(id)sender
|
|
|
|
{
|
|
|
|
buttonClicked(self->gocontrol);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2014-07-16 12:25:09 -05:00
|
|
|
id newButton(char *text)
|
|
|
|
{
|
|
|
|
NSButton *b;
|
|
|
|
|
|
|
|
// TODO cache the initial rect?
|
|
|
|
b = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
|
|
|
|
// TODO verify all of these against Interface Builder
|
|
|
|
[b setButtonType:NSMomentaryLightButton];
|
|
|
|
[b setTitle:[NSString stringWithUTF8String:text]];
|
|
|
|
[b setBordered:YES];
|
|
|
|
[b setBezelStyle:NSRoundedBezelStyle];
|
2014-07-18 10:47:48 -05:00
|
|
|
setStandardControlFont(b);
|
2014-07-16 12:25:09 -05:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2014-07-17 11:02:39 -05:00
|
|
|
void buttonSetDelegate(id button, void *b)
|
|
|
|
{
|
|
|
|
goControlDelegate *d;
|
|
|
|
|
|
|
|
d = [goControlDelegate new];
|
|
|
|
d->gocontrol = b;
|
|
|
|
[toNSButton(button) setTarget:d];
|
|
|
|
[toNSButton(button) setAction:@selector(buttonClicked:)];
|
|
|
|
}
|
|
|
|
|
2014-07-16 12:25:09 -05:00
|
|
|
const char *buttonText(id button)
|
|
|
|
{
|
|
|
|
return [[toNSButton(button) title] UTF8String];
|
|
|
|
}
|
|
|
|
|
|
|
|
void buttonSetText(id button, char *text)
|
|
|
|
{
|
|
|
|
[toNSButton(button) setTitle:[NSString stringWithUTF8String:text]];
|
|
|
|
}
|