More Mac OS X Spinbox refinements. Still not working, but if I have to do everything the manual way then at least I can do so cleanly now.
This commit is contained in:
parent
6d58f434b7
commit
2a3809cfd1
|
@ -152,7 +152,8 @@ extern id newWarningPopover(char *);
|
|||
extern void warningPopoverShow(id, id);
|
||||
|
||||
/* spinbox_darwin.m */
|
||||
extern id newSpinboxStepper(void);
|
||||
extern id spinboxSetup(id, id, void *);
|
||||
extern id newSpinbox(void *);
|
||||
extern id spinboxTextField(id);
|
||||
extern id spinboxStepper(id);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,22 +21,26 @@ import "C"
|
|||
// - proper spacing between edit and spinner: Interface Builder isn't clear; NSDatePicker doesn't spill the beans
|
||||
|
||||
type spinbox struct {
|
||||
textfield C.id
|
||||
stepper C.id
|
||||
objcspinbox C.id
|
||||
id C.id
|
||||
}
|
||||
|
||||
func newSpinbox() Spinbox {
|
||||
s := new(spinbox)
|
||||
s.textfield = C.newTextField()
|
||||
s.stepper = C.newSpinboxStepper()
|
||||
s.objcspinbox = C.spinboxSetup(s.textfield, s.stepper, unsafe.Pointer(s))
|
||||
s.id = C.newSpinbox(unsafe.Pointer(s))
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *spinbox) textfield() C.id {
|
||||
return C.spinboxTextField(s.id)
|
||||
}
|
||||
|
||||
func (s *spinbox) stepper() C.id {
|
||||
return C.spinboxStepper(s.id)
|
||||
}
|
||||
|
||||
func (s *spinbox) setParent(p *controlParent) {
|
||||
C.parent(s.textfield, p.id)
|
||||
C.parent(s.stepper, p.id)
|
||||
C.parent(s.textfield(), p.id)
|
||||
C.parent(s.stepper(), p.id)
|
||||
}
|
||||
|
||||
func (s *spinbox) preferredSize(d *sizing) (width, height int) {
|
||||
|
@ -46,8 +50,8 @@ func (s *spinbox) preferredSize(d *sizing) (width, height int) {
|
|||
|
||||
func (s *spinbox) resize(x int, y int, width int, height int, d *sizing) {
|
||||
// TODO
|
||||
C.moveControl(s.textfield, C.intptr_t(x), C.intptr_t(y), C.intptr_t(width - 20), C.intptr_t(height))
|
||||
C.moveControl(s.stepper, C.intptr_t(x + width - 15), C.intptr_t(y), C.intptr_t(15), C.intptr_t(height))
|
||||
C.moveControl(s.textfield(), C.intptr_t(x), C.intptr_t(y), C.intptr_t(width - 20), C.intptr_t(height))
|
||||
C.moveControl(s.stepper(), C.intptr_t(x + width - 15), C.intptr_t(y), C.intptr_t(15), C.intptr_t(height))
|
||||
}
|
||||
|
||||
func (s *spinbox) nTabStops() int {
|
||||
|
|
|
@ -4,37 +4,58 @@
|
|||
#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 newSpinboxStepper(void)
|
||||
id newSpinbox(void *gospinbox)
|
||||
{
|
||||
NSStepper *s;
|
||||
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];
|
||||
|
||||
s = [[NSStepper alloc] initWithFrame:NSZeroRect];
|
||||
[s setMinValue:0];
|
||||
[s setMaxValue:100];
|
||||
[s setIncrement:1];
|
||||
[s setAutorepeat:YES]; // hold mouse button to step repeatedly
|
||||
return (id) s;
|
||||
}
|
||||
|
||||
id spinboxSetup(id textfield, id stepper, void *gospinbox)
|
||||
id spinboxTextField(id spinbox)
|
||||
{
|
||||
goSpinbox *g;
|
||||
|
||||
g = [goSpinbox new];
|
||||
g->gospinbox = gospinbox;
|
||||
// TODO set any options?
|
||||
[textfield bind:@"integerValue" toObject:g withKeyPath:@"integerValue" options:nil];
|
||||
[stepper bind:@"integerValue" toObject:g withKeyPath:@"integerValue" options:nil];
|
||||
return (id) g;
|
||||
return (id) (togoSpinbox(spinbox)->textfield);
|
||||
}
|
||||
|
||||
id spinboxStepper(id spinbox)
|
||||
{
|
||||
return (id) (togoSpinbox(spinbox)->stepper);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue