diff options
| author | Pietro Gagliardi <[email protected]> | 2014-10-17 20:02:34 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-10-17 20:02:34 -0400 |
| commit | 8f1165e0c7246a1faec655088004cce8c5e047d7 (patch) | |
| tree | 961c5712ff842e10121958f04d8ada57533221b7 /newctrl/textfield_unix.go | |
| parent | 344a344abd471e36ebd6ea0ced71df1ce74ea189 (diff) | |
Did most of the GTK+ migration.
Diffstat (limited to 'newctrl/textfield_unix.go')
| -rw-r--r-- | newctrl/textfield_unix.go | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/newctrl/textfield_unix.go b/newctrl/textfield_unix.go new file mode 100644 index 0000000..286ad3f --- /dev/null +++ b/newctrl/textfield_unix.go @@ -0,0 +1,81 @@ +// +build !windows,!darwin + +// 7 july 2014 + +package ui + +import ( + "unsafe" +) + +// #include "gtk_unix.h" +// extern void textfieldChanged(GtkEditable *, gpointer); +// /* because cgo doesn't like GTK_STOCK_DIALOG_ERROR */ +// static inline void setErrorIcon(GtkEntry *entry) +// { +// gtk_entry_set_icon_from_stock(entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_DIALOG_ERROR); +// } +import "C" + +type textfield struct { + *controlSingleWidget + entry *C.GtkEntry + changed *event +} + +func startNewTextField() *textfield { + widget := C.gtk_entry_new() + t := &textfield{ + controlSingleWidget: newControlSingleWidget(widget), + entry: (*C.GtkEntry)(unsafe.Pointer(widget)), + changed: newEvent(), + } + g_signal_connect( + C.gpointer(unsafe.Pointer(t._widget)), + "changed", + C.GCallback(C.textfieldChanged), + C.gpointer(unsafe.Pointer(t))) + return t +} + +func newTextField() *textfield { + return startNewTextField() +} + +func newPasswordField() *textfield { + t := startNewTextField() + C.gtk_entry_set_visibility(t.entry, C.FALSE) + return t +} + +func (t *textfield) Text() string { + return fromgstr(C.gtk_entry_get_text(t.entry)) +} + +func (t *textfield) SetText(text string) { + ctext := togstr(text) + defer freegstr(ctext) + C.gtk_entry_set_text(t.entry, ctext) +} + +func (t *textfield) OnChanged(f func()) { + t.changed.set(f) +} + +func (t *textfield) Invalid(reason string) { + if reason == "" { + C.gtk_entry_set_icon_from_stock(t.entry, C.GTK_ENTRY_ICON_SECONDARY, nil) + return + } + C.setErrorIcon(t.entry) + creason := togstr(reason) + defer freegstr(creason) + C.gtk_entry_set_icon_tooltip_text(t.entry, C.GTK_ENTRY_ICON_SECONDARY, creason) + C.gtk_widget_error_bell(t._widget) +} + +//export textfieldChanged +func textfieldChanged(editable *C.GtkEditable, data C.gpointer) { + t := (*textfield)(unsafe.Pointer(data)) + t.changed.fire() +} |
