summaryrefslogtreecommitdiff
path: root/redo/checkbox_unix.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-03 16:28:21 -0400
committerPietro Gagliardi <[email protected]>2014-08-03 16:28:21 -0400
commitb6d07237b423b690570e105e5f0810d35693b0d0 (patch)
treefdf2f0ec2a66f217080dfeb0b60de9e763a9bd95 /redo/checkbox_unix.go
parentfd48be68ee957e936c272348d3f0b0bddaba5c92 (diff)
Migrated the GTK+ backend to the new Control system. Added controlParent to deal with interface issues; need to apply this to the Windows backend too.
Diffstat (limited to 'redo/checkbox_unix.go')
-rw-r--r--redo/checkbox_unix.go72
1 files changed, 62 insertions, 10 deletions
diff --git a/redo/checkbox_unix.go b/redo/checkbox_unix.go
index 45048d1..070b84f 100644
--- a/redo/checkbox_unix.go
+++ b/redo/checkbox_unix.go
@@ -9,33 +9,48 @@ import (
)
// #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
+ _widget *C.GtkWidget
+ 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)
- return &checkbox{
- button: finishNewButton(widget, "toggled", C.checkboxToggled),
+ c := &checkbox{
+ _widget: 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
}
-//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) 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 {
@@ -46,3 +61,40 @@ 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()
+}
+
+func (c *checkbox) widget() *C.GtkWidget {
+ return c._widget
+}
+
+func (c *checkbox) setParent(p *controlParent) {
+ basesetParent(c, p)
+}
+
+func (c *checkbox) containerShow() {
+ basecontainerShow(c)
+}
+
+func (c *checkbox) containerHide() {
+ basecontainerHide(c)
+}
+
+func (c *checkbox) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
+ return baseallocate(c, x, y, width, height, d)
+}
+
+func (c *checkbox) preferredSize(d *sizing) (width, height int) {
+ return basepreferredSize(c, d)
+}
+
+func (c *checkbox) commitResize(a *allocation, d *sizing) {
+ basecommitResize(c, a, d)
+}
+
+func (c *checkbox) getAuxResizeInfo(d *sizing) {
+ basegetAuxResizeInfo(d)
+}