From 7c96841392d64e611d1d99f1c5a241b92e95f4d3 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 31 Oct 2014 19:57:48 -0400 Subject: Added Spinbox.OnChanged() and implemented it on GTK+ and Mac OS X. Implementing it on Windows is going to be a pain... --- spinbox_unix.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'spinbox_unix.go') diff --git a/spinbox_unix.go b/spinbox_unix.go index b6b2ec3..ca84b28 100644 --- a/spinbox_unix.go +++ b/spinbox_unix.go @@ -9,6 +9,7 @@ import ( ) // #include "gtk_unix.h" +// extern void spinboxChanged(GtkSpinButton *, gpointer); import "C" // TODO preferred width may be too wide @@ -16,6 +17,7 @@ import "C" type spinbox struct { *controlSingleWidget spinbutton *C.GtkSpinButton + changed *event } func newSpinbox(min int, max int) Spinbox { @@ -24,9 +26,18 @@ func newSpinbox(min int, max int) Spinbox { s := &spinbox{ controlSingleWidget: newControlSingleWidget(widget), spinbutton: (*C.GtkSpinButton)(unsafe.Pointer(widget)), + changed: newEvent(), } C.gtk_spin_button_set_digits(s.spinbutton, 0) // integers C.gtk_spin_button_set_numeric(s.spinbutton, C.TRUE) // digits only + // this isn't specifically documented as the signal to connect to until 3.14 + // it has existed as far back as 3.4, though, if not earlier + // there's also ::change-value which is for keyboard changing + g_signal_connect( + C.gpointer(unsafe.Pointer(s.spinbutton)), + "value-changed", + C.GCallback(C.spinboxChanged), + C.gpointer(unsafe.Pointer(s))) return s } @@ -46,3 +57,13 @@ func (s *spinbox) SetValue(value int) { } C.gtk_spin_button_set_value(s.spinbutton, C.gdouble(value)) } + +func (s *spinbox) OnChanged(e func()) { + s.changed.set(e) +} + +//export spinboxChanged +func spinboxChanged(swid *C.GtkSpinButton, data C.gpointer) { + s := (*spinbox)(unsafe.Pointer(data)) + s.changed.fire() +} -- cgit v1.2.3