Implemented the previous commit's stuff on Mac OS X.
This commit is contained in:
parent
3c73f10cc1
commit
4a98fdb907
|
@ -152,8 +152,10 @@ extern id newWarningPopover(char *);
|
||||||
extern void warningPopoverShow(id, id);
|
extern void warningPopoverShow(id, id);
|
||||||
|
|
||||||
/* spinbox_darwin.m */
|
/* spinbox_darwin.m */
|
||||||
extern id newSpinbox(void *);
|
extern id newSpinbox(void *, intmax_t, intmax_t);
|
||||||
extern id spinboxTextField(id);
|
extern id spinboxTextField(id);
|
||||||
extern id spinboxStepper(id);
|
extern id spinboxStepper(id);
|
||||||
|
extern intmax_t spinboxValue(id);
|
||||||
|
extern void spinboxSetValue(id, intmax_t);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,12 +24,20 @@ type spinbox struct {
|
||||||
id C.id
|
id C.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSpinbox() Spinbox {
|
func newSpinbox(min int, max int) Spinbox {
|
||||||
s := new(spinbox)
|
s := new(spinbox)
|
||||||
s.id = C.newSpinbox(unsafe.Pointer(s))
|
s.id = C.newSpinbox(unsafe.Pointer(s), C.intmax_t(min), C.intmax_t(max))
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *spinbox) Value() int {
|
||||||
|
return int(C.spinboxValue(s.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *spinbox) SetValue(value int) {
|
||||||
|
C.spinboxSetValue(s.id, C.intmax_t(value))
|
||||||
|
}
|
||||||
|
|
||||||
func (s *spinbox) textfield() C.id {
|
func (s *spinbox) textfield() C.id {
|
||||||
return C.spinboxTextField(s.id)
|
return C.spinboxTextField(s.id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
@implementation goSpinbox
|
@implementation goSpinbox
|
||||||
|
|
||||||
- (id)init
|
- (id)initWithMinimum:(NSInteger)minimum maximum:(NSInteger)maximum
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self == nil)
|
if (self == nil)
|
||||||
|
@ -40,13 +40,14 @@
|
||||||
|
|
||||||
self->stepper = [[NSStepper alloc] initWithFrame:NSZeroRect];
|
self->stepper = [[NSStepper alloc] initWithFrame:NSZeroRect];
|
||||||
[self->stepper setIncrement:1];
|
[self->stepper setIncrement:1];
|
||||||
|
[self->stepper setValueWraps:NO];
|
||||||
[self->stepper setAutorepeat:YES]; // hold mouse button to step repeatedly
|
[self->stepper setAutorepeat:YES]; // hold mouse button to step repeatedly
|
||||||
|
|
||||||
// TODO how SHOULD the formatter treat invald input?
|
// TODO how SHOULD the formatter treat invald input?
|
||||||
|
|
||||||
[self setMinimum:0];
|
[self setMinimum:minimum];
|
||||||
[self setMaximum:100];
|
[self setMaximum:maximum];
|
||||||
[self setValue:0];
|
[self setValue:self->minimum];
|
||||||
|
|
||||||
[self->textfield setDelegate:self];
|
[self->textfield setDelegate:self];
|
||||||
[self->stepper setTarget:self];
|
[self->stepper setTarget:self];
|
||||||
|
@ -57,42 +58,49 @@
|
||||||
|
|
||||||
- (void)setValue:(NSInteger)value
|
- (void)setValue:(NSInteger)value
|
||||||
{
|
{
|
||||||
|
if (self->value < self->minimum)
|
||||||
|
self->value = self->minimum;
|
||||||
|
if (self->value > self->maximum)
|
||||||
|
self->value = self->maximum;
|
||||||
self->value = value;
|
self->value = value;
|
||||||
[self->textfield setIntegerValue:value];
|
// TODO does not work?
|
||||||
[self->stepper setIntegerValue:value];
|
[self->textfield setIntegerValue:self->value];
|
||||||
|
[self->stepper setIntegerValue:self->value];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setMinimum:(NSInteger)min
|
- (void)setMinimum:(NSInteger)min
|
||||||
{
|
{
|
||||||
self->minimum = min;
|
self->minimum = min;
|
||||||
[self->formatter setMinimum:[NSNumber numberWithInteger:min]];
|
[self->formatter setMinimum:[NSNumber numberWithInteger:self->minimum]];
|
||||||
[self->stepper setMinValue:((double) min)];
|
[self->stepper setMinValue:((double) (self->minimum))];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setMaximum:(NSInteger)max
|
- (void)setMaximum:(NSInteger)max
|
||||||
{
|
{
|
||||||
self->maximum = max;
|
self->maximum = max;
|
||||||
[self->formatter setMaximum:[NSNumber numberWithInteger:max]];
|
[self->formatter setMaximum:[NSNumber numberWithInteger:self->maximum]];
|
||||||
[self->stepper setMaxValue:((double) max)];
|
[self->stepper setMaxValue:((double) (self->maximum))];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)stepperClicked:(id)sender
|
- (IBAction)stepperClicked:(id)sender
|
||||||
{
|
{
|
||||||
|
NSLog(@"stepperClicked %d\n", [self->stepper integerValue]);
|
||||||
[self setValue:[self->stepper integerValue]];
|
[self setValue:[self->stepper integerValue]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)controlTextDidChange:(NSNotification *)note
|
- (void)controlTextDidChange:(NSNotification *)note
|
||||||
{
|
{
|
||||||
|
NSLog(@"controlTextDidChange %d\n", [self->textfield integerValue]);
|
||||||
[self setValue:[self->textfield integerValue]];
|
[self setValue:[self->textfield integerValue]];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
id newSpinbox(void *gospinbox)
|
id newSpinbox(void *gospinbox, intmax_t minimum, intmax_t maximum)
|
||||||
{
|
{
|
||||||
goSpinbox *s;
|
goSpinbox *s;
|
||||||
|
|
||||||
s = [goSpinbox new];
|
s = [[goSpinbox new] initWithMinimum:((NSInteger) minimum) maximum:((NSInteger) maximum)];
|
||||||
s->gospinbox = gospinbox;
|
s->gospinbox = gospinbox;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -106,3 +114,13 @@ id spinboxStepper(id spinbox)
|
||||||
{
|
{
|
||||||
return (id) (togoSpinbox(spinbox)->stepper);
|
return (id) (togoSpinbox(spinbox)->stepper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
intmax_t spinboxValue(id spinbox)
|
||||||
|
{
|
||||||
|
return (intmax_t) (togoSpinbox(spinbox)->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void spinboxSetValue(id spinbox, intmax_t value)
|
||||||
|
{
|
||||||
|
[togoSpinbox(spinbox) setValue:((NSInteger) value)];
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue