summaryrefslogtreecommitdiff
path: root/redo/controls_darwin.m
blob: a21ac0f1627460c957283715fc3a83a9abab2fbb (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
// 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))
#define toNSButton(x) ((NSButton *) (x))

void unparent(id control)
{
	[toNSView(control) retain];		// save from being freed when released by the removal selector below
	// TODO removeFromSuperviewWithoutNeedingDisplay?
	[toNSView(control) removeFromSuperview];
}

void parent(id control, id parentid, BOOL floating)
{
	[[toNSWindow(parentid) contentView] addSubview:toNSView(control)];
	if (floating)		// previously unparented
		[toNSView(control) release];
}

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];
	return b;
}

const char *buttonText(id button)
{
	return [[toNSButton(button) title] UTF8String];
}

void buttonSetText(id button, char *text)
{
	[toNSButton(button) setTitle:[NSString stringWithUTF8String:text]];
}