diff options
| author | Pietro Gagliardi <[email protected]> | 2014-08-02 22:35:58 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-08-02 22:35:58 -0400 |
| commit | d018953d7ef1b276cc3229e04ba6fc75018c888a (patch) | |
| tree | 3f980a017ca498bf499ff9c5e6a53210606b12f9 /redo/checkbox_unix.go | |
| parent | 1f6bcde3d9ddcab921f2f4347148f6784ca36a14 (diff) | |
Split all the Control implementations into their own files and renamed the containerctrls implementation files to say tab instead as they only hold Tab. This is the first part of what should hopefully be the final restructuring.
Diffstat (limited to 'redo/checkbox_unix.go')
| -rw-r--r-- | redo/checkbox_unix.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/redo/checkbox_unix.go b/redo/checkbox_unix.go new file mode 100644 index 0000000..45048d1 --- /dev/null +++ b/redo/checkbox_unix.go @@ -0,0 +1,48 @@ +// +build !windows,!darwin + +// 7 july 2014 + +package ui + +import ( + "unsafe" +) + +// #include "gtk_unix.h" +// extern void buttonClicked(GtkButton *, gpointer); +// extern void checkboxToggled(GtkToggleButton *, gpointer); +import "C" + +type checkbox struct { + // embed button so its methods and events carry over + *button + toggle *C.GtkToggleButton + checkbox *C.GtkCheckButton +} + +func newCheckbox(text string) *checkbox { + ctext := togstr(text) + defer freegstr(ctext) + widget := C.gtk_check_button_new_with_label(ctext) + return &checkbox{ + button: finishNewButton(widget, "toggled", C.checkboxToggled), + toggle: (*C.GtkToggleButton)(unsafe.Pointer(widget)), + checkbox: (*C.GtkCheckButton)(unsafe.Pointer(widget)), + } +} + +//export checkboxToggled +func checkboxToggled(bwid *C.GtkToggleButton, data C.gpointer) { + // note that the finishNewButton() call uses the embedded *button as data + // this is fine because we're only deferring to buttonClicked() anyway + buttonClicked(nil, data) +} + +func (c *checkbox) Checked() bool { + return fromgbool(C.gtk_toggle_button_get_active(c.toggle)) +} + +func (c *checkbox) SetChecked(checked bool) { + C.gtk_toggle_button_set_active(c.toggle, togbool(checked)) +} + |
