summaryrefslogtreecommitdiff
path: root/BBB_GOFILES/combobox.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2018-08-26 09:55:07 -0400
committerPietro Gagliardi <[email protected]>2018-08-26 09:55:07 -0400
commit62ac2527732a01dfa6bd2c9523215c0ba3816641 (patch)
tree84244a69e048f79e4d9f134c121f4cf581200986 /BBB_GOFILES/combobox.go
parenta5a00c644c08a6e0f52740c3f2a280977929a285 (diff)
Moved all the Go files out of the way again, this time so we can migrate them to more proper cgo usage.
Diffstat (limited to 'BBB_GOFILES/combobox.go')
-rw-r--r--BBB_GOFILES/combobox.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/BBB_GOFILES/combobox.go b/BBB_GOFILES/combobox.go
new file mode 100644
index 0000000..1e381de
--- /dev/null
+++ b/BBB_GOFILES/combobox.go
@@ -0,0 +1,67 @@
+// 12 december 2015
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "ui.h"
+// extern void doComboboxOnSelected(uiCombobox *, void *);
+// // see golang/go#19835
+// typedef void (*comboboxCallback)(uiCombobox *, void *);
+import "C"
+
+// Combobox is a Control that represents a drop-down list of strings
+// that the user can choose one of at any time. For a Combobox that
+// users can type values into, see EditableCombobox.
+type Combobox struct {
+ ControlBase
+ c *C.uiCombobox
+ onSelected func(*Combobox)
+}
+
+// NewCombobox creates a new Combobox.
+func NewCombobox() *Combobox {
+ c := new(Combobox)
+
+ c.c = C.uiNewCombobox()
+
+ C.uiComboboxOnSelected(c.c, C.comboboxCallback(C.doComboboxOnSelected), nil)
+
+ c.ControlBase = NewControlBase(c, uintptr(unsafe.Pointer(c.c)))
+ return c
+}
+
+// Append adds the named item to the end of the Combobox.
+func (c *Combobox) Append(text string) {
+ ctext := C.CString(text)
+ C.uiComboboxAppend(c.c, ctext)
+ freestr(ctext)
+}
+
+// Selected returns the index of the currently selected item in the
+// Combobox, or -1 if nothing is selected.
+func (c *Combobox) Selected() int {
+ return int(C.uiComboboxSelected(c.c))
+}
+
+// SetSelected sets the currently selected item in the Combobox
+// to index. If index is -1 no item will be selected.
+func (c *Combobox) SetSelected(index int) {
+ C.uiComboboxSetSelected(c.c, C.int(index))
+}
+
+// OnSelected registers f to be run when the user selects an item in
+// the Combobox. Only one function can be registered at a time.
+func (c *Combobox) OnSelected(f func(*Combobox)) {
+ c.onSelected = f
+}
+
+//export doComboboxOnSelected
+func doComboboxOnSelected(cc *C.uiCombobox, data unsafe.Pointer) {
+ c := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*Combobox)
+ if c.onSelected != nil {
+ c.onSelected(c)
+ }
+}