Implemented TextField.OnChanged() on Mac OS X.
This commit is contained in:
parent
ac6d0429f1
commit
77ab711705
|
@ -9,7 +9,7 @@
|
||||||
#define toNSView(x) ((NSView *) (x))
|
#define toNSView(x) ((NSView *) (x))
|
||||||
#define toNSBox(x) ((NSBox *) (x))
|
#define toNSBox(x) ((NSBox *) (x))
|
||||||
|
|
||||||
@interface goControlDelegate : NSObject {
|
@interface goControlDelegate : NSObject <NSTextFieldDelegate> {
|
||||||
@public
|
@public
|
||||||
void *gocontrol;
|
void *gocontrol;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,11 @@
|
||||||
checkboxToggled(self->gocontrol);
|
checkboxToggled(self->gocontrol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)controlTextDidChange:(NSNotification *)note
|
||||||
|
{
|
||||||
|
textfieldChanged(self->gocontrol);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
id newButton(void)
|
id newButton(void)
|
||||||
|
@ -136,6 +141,15 @@ id newPasswordField(void)
|
||||||
return finishNewTextField(toNSTextField(t), YES);
|
return finishNewTextField(toNSTextField(t), YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void textfieldSetDelegate(id textfield, void *t)
|
||||||
|
{
|
||||||
|
goControlDelegate *d;
|
||||||
|
|
||||||
|
d = [goControlDelegate new];
|
||||||
|
d->gocontrol = t;
|
||||||
|
[toNSTextField(textfield) setDelegate:d];
|
||||||
|
}
|
||||||
|
|
||||||
// also good for labels
|
// also good for labels
|
||||||
const char *textFieldText(id t)
|
const char *textFieldText(id t)
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,6 +68,7 @@ extern BOOL checkboxChecked(id);
|
||||||
extern void checkboxSetChecked(id, BOOL);
|
extern void checkboxSetChecked(id, BOOL);
|
||||||
extern id newTextField(void);
|
extern id newTextField(void);
|
||||||
extern id newPasswordField(void);
|
extern id newPasswordField(void);
|
||||||
|
extern void textfieldSetDelegate(id, void *);
|
||||||
extern const char *textFieldText(id);
|
extern const char *textFieldText(id);
|
||||||
extern void textFieldSetText(id, char *);
|
extern void textFieldSetText(id, char *);
|
||||||
extern id newLabel(void);
|
extern id newLabel(void);
|
||||||
|
|
|
@ -11,12 +11,16 @@ import "C"
|
||||||
|
|
||||||
type textfield struct {
|
type textfield struct {
|
||||||
_id C.id
|
_id C.id
|
||||||
|
changed *event
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTextField() *textfield {
|
func newTextField() *textfield {
|
||||||
return &textfield{
|
t := &textfield{
|
||||||
_id: C.newTextField(),
|
_id: C.newTextField(),
|
||||||
|
changed: newEvent(),
|
||||||
}
|
}
|
||||||
|
C.textfieldSetDelegate(t._id, unsafe.Pointer(t))
|
||||||
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPasswordField() *textfield {
|
func newPasswordField() *textfield {
|
||||||
|
@ -35,6 +39,21 @@ func (t *textfield) SetText(text string) {
|
||||||
C.textFieldSetText(t._id, ctext)
|
C.textFieldSetText(t._id, ctext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *textfield) OnChanged(f func()) {
|
||||||
|
t.changed.set(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *textfield) Invalid(reason string) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
//export textfieldChanged
|
||||||
|
func textfieldChanged(data unsafe.Pointer) {
|
||||||
|
t := (*textfield)(data)
|
||||||
|
println("changed")
|
||||||
|
t.changed.fire()
|
||||||
|
}
|
||||||
|
|
||||||
func (t *textfield) id() C.id {
|
func (t *textfield) id() C.id {
|
||||||
return t._id
|
return t._id
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue