summaryrefslogtreecommitdiff
path: root/newctrl/checkbox_unix.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-10-17 20:02:34 -0400
committerPietro Gagliardi <[email protected]>2014-10-17 20:02:34 -0400
commit8f1165e0c7246a1faec655088004cce8c5e047d7 (patch)
tree961c5712ff842e10121958f04d8ada57533221b7 /newctrl/checkbox_unix.go
parent344a344abd471e36ebd6ea0ced71df1ce74ea189 (diff)
Did most of the GTK+ migration.
Diffstat (limited to 'newctrl/checkbox_unix.go')
-rw-r--r--newctrl/checkbox_unix.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/newctrl/checkbox_unix.go b/newctrl/checkbox_unix.go
new file mode 100644
index 0000000..fc27bee
--- /dev/null
+++ b/newctrl/checkbox_unix.go
@@ -0,0 +1,68 @@
+// +build !windows,!darwin
+
+// 7 july 2014
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "gtk_unix.h"
+// extern void checkboxToggled(GtkToggleButton *, gpointer);
+import "C"
+
+type checkbox struct {
+ *controlSingleWidget
+ button *C.GtkButton
+ toggle *C.GtkToggleButton
+ checkbox *C.GtkCheckButton
+ toggled *event
+}
+
+func newCheckbox(text string) *checkbox {
+ ctext := togstr(text)
+ defer freegstr(ctext)
+ widget := C.gtk_check_button_new_with_label(ctext)
+ c := &checkbox{
+ controlSingleWidget: newControlSingleWidget(widget),
+ button: (*C.GtkButton)(unsafe.Pointer(widget)),
+ toggle: (*C.GtkToggleButton)(unsafe.Pointer(widget)),
+ checkbox: (*C.GtkCheckButton)(unsafe.Pointer(widget)),
+ toggled: newEvent(),
+ }
+ g_signal_connect(
+ C.gpointer(unsafe.Pointer(c.checkbox)),
+ "toggled",
+ C.GCallback(C.checkboxToggled),
+ C.gpointer(unsafe.Pointer(c)))
+ return c
+}
+
+func (c *checkbox) OnToggled(e func()) {
+ c.toggled.set(e)
+}
+
+func (c *checkbox) Text() string {
+ return fromgstr(C.gtk_button_get_label(c.button))
+}
+
+func (c *checkbox) SetText(text string) {
+ ctext := togstr(text)
+ defer freegstr(ctext)
+ C.gtk_button_set_label(c.button, ctext)
+}
+
+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))
+}
+
+//export checkboxToggled
+func checkboxToggled(bwid *C.GtkToggleButton, data C.gpointer) {
+ c := (*checkbox)(unsafe.Pointer(data))
+ c.toggled.fire()
+}