summaryrefslogtreecommitdiff
path: root/redo/checkbox_darwin.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-03 20:08:25 -0400
committerPietro Gagliardi <[email protected]>2014-08-03 20:08:25 -0400
commit8c4cd789ca4dc69a56bf3327ff7ebbb5b88314be (patch)
treefe52b1a8a55552d2ebcea3480442f5953374afd3 /redo/checkbox_darwin.go
parentb6d07237b423b690570e105e5f0810d35693b0d0 (diff)
Migrated the Mac OS X backend to the new Control setup.
Diffstat (limited to 'redo/checkbox_darwin.go')
-rw-r--r--redo/checkbox_darwin.go74
1 files changed, 67 insertions, 7 deletions
diff --git a/redo/checkbox_darwin.go b/redo/checkbox_darwin.go
index ee7e88c..fa27892 100644
--- a/redo/checkbox_darwin.go
+++ b/redo/checkbox_darwin.go
@@ -2,26 +2,86 @@
package ui
+import (
+ "unsafe"
+)
+
// #include "objc_darwin.h"
import "C"
type checkbox struct {
- *button
+ _id C.id
+ toggled *event
}
func newCheckbox(text string) *checkbox {
- return &checkbox{
- button: finishNewButton(C.newCheckbox(), text),
+ ctext := C.CString(text)
+ defer C.free(unsafe.Pointer(ctext))
+ c := &checkbox{
+ _id: C.newCheckbox(),
+ toggled: newEvent(),
}
+ C.buttonSetText(c._id, ctext)
+ C.checkboxSetDelegate(c._id, unsafe.Pointer(c))
+ return c
+}
+
+func (c *checkbox) OnToggled(e func()) {
+ c.toggled.set(e)
}
-// we don't need to define our own event here; we can just reuse Button's
-// (it's all target-action anyway)
+func (c *checkbox) Text() string {
+ return C.GoString(C.buttonText(c._id))
+}
+
+func (c *checkbox) SetText(text string) {
+ ctext := C.CString(text)
+ defer C.free(unsafe.Pointer(ctext))
+ C.buttonSetText(c._id, ctext)
+}
func (c *checkbox) Checked() bool {
- return fromBOOL(C.checkboxChecked(c.id))
+ return fromBOOL(C.checkboxChecked(c._id))
}
func (c *checkbox) SetChecked(checked bool) {
- C.checkboxSetChecked(c.id, toBOOL(checked))
+ C.checkboxSetChecked(c._id, toBOOL(checked))
+}
+
+//export checkboxToggled
+func checkboxToggled(xc unsafe.Pointer) {
+ c := (*checkbox)(unsafe.Pointer(xc))
+ c.toggled.fire()
+}
+
+func (c *checkbox) id() C.id {
+ return c._id
+}
+
+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(c, d)
}