Implemented TextField.OnChanged() on Mac OS X.

This commit is contained in:
Pietro Gagliardi 2014-08-20 15:26:48 -04:00
parent ac6d0429f1
commit 77ab711705
3 changed files with 38 additions and 4 deletions

View File

@ -9,7 +9,7 @@
#define toNSView(x) ((NSView *) (x))
#define toNSBox(x) ((NSBox *) (x))
@interface goControlDelegate : NSObject {
@interface goControlDelegate : NSObject <NSTextFieldDelegate> {
@public
void *gocontrol;
}
@ -27,6 +27,11 @@
checkboxToggled(self->gocontrol);
}
- (void)controlTextDidChange:(NSNotification *)note
{
textfieldChanged(self->gocontrol);
}
@end
id newButton(void)
@ -136,6 +141,15 @@ id newPasswordField(void)
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
const char *textFieldText(id t)
{

View File

@ -68,6 +68,7 @@ extern BOOL checkboxChecked(id);
extern void checkboxSetChecked(id, BOOL);
extern id newTextField(void);
extern id newPasswordField(void);
extern void textfieldSetDelegate(id, void *);
extern const char *textFieldText(id);
extern void textFieldSetText(id, char *);
extern id newLabel(void);

View File

@ -10,13 +10,17 @@ import (
import "C"
type textfield struct {
_id C.id
_id C.id
changed *event
}
func newTextField() *textfield {
return &textfield{
_id: C.newTextField(),
t := &textfield{
_id: C.newTextField(),
changed: newEvent(),
}
C.textfieldSetDelegate(t._id, unsafe.Pointer(t))
return t
}
func newPasswordField() *textfield {
@ -35,6 +39,21 @@ func (t *textfield) SetText(text string) {
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 {
return t._id
}