summaryrefslogtreecommitdiff
path: root/spinbox_darwin.m
blob: f767a76d0571ca7e9d5a388f82fdf0418ef5b67c (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
// 29 october 2014

#include "objc_darwin.h"
#include "_cgo_export.h"
#import <Cocoa/Cocoa.h>

#define togoSpinbox(x) ((goSpinbox *) (x))

@interface goSpinbox : NSObject {
@public
	void *gospinbox;
	NSTextField *textfield;
	NSNumberFormatter *formatter;
	NSStepper *stepper;
}
@property NSInteger integerValue;
@property NSInteger minimum;
@property NSInteger maximum;
@end

@implementation goSpinbox
@synthesize integerValue;
@synthesize minimum;
@synthesize maximum;
@end

id newSpinbox(void *gospinbox)
{
	goSpinbox *s;

	s = [goSpinbox new];
	s->gospinbox = gospinbox;
	s->textfield = (NSTextField *) newTextField();
	s->formatter = [NSNumberFormatter new];
	[s->formatter setAllowsFloats:NO];
	[s->textfield setFormatter:s->formatter];
	s->stepper = [[NSStepper alloc] initWithFrame:NSZeroRect];
	[s->stepper setAutorepeat:YES];		// hold mouse button to step repeatedly

	[s setMinimum:0];
	[s setMaximum:100];

	[s->textfield bind:@"integerValue" toObject:s withKeyPath:@"integerValue" options:nil];
	[s->stepper bind:@"integerValue" toObject:s withKeyPath:@"integerValue" options:nil];
//	[s->formatter bind:@"minimum" toObject:s withKeyPath:@"minimum" options:nil];
	[s->stepper bind:@"minValue" toObject:s withKeyPath:@"minimum" options:nil];
//	[s->formatter bind:@"maximum" toObject:s withkeyPath:@"maximum" options:nil];
	[s->stepper bind:@"maxValue" toObject:s withKeyPath:@"maximum" options:nil];

	return (id) s;
}

id spinboxTextField(id spinbox)
{
	return (id) (togoSpinbox(spinbox)->textfield);
}

id spinboxStepper(id spinbox)
{
	return (id) (togoSpinbox(spinbox)->stepper);
}