From 757f109376fa598629c86309d47b2caa21391f1d Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 11 Aug 2018 16:40:02 -0400 Subject: Readded Combobox and added EditableCombobox. --- AAA_GOFILES/combobox.go | 132 ------------------------------------------------ combobox.go | 116 ++++++++++++++++++++++++++++++++++++++++++ editablecombobox.go | 120 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 236 insertions(+), 132 deletions(-) delete mode 100644 AAA_GOFILES/combobox.go create mode 100644 combobox.go create mode 100644 editablecombobox.go diff --git a/AAA_GOFILES/combobox.go b/AAA_GOFILES/combobox.go deleted file mode 100644 index 2afa294..0000000 --- a/AAA_GOFILES/combobox.go +++ /dev/null @@ -1,132 +0,0 @@ -// 12 december 2015 - -package ui - -import ( - "unsafe" -) - -// #include "ui.h" -// extern void doComboboxOnSelected(uiCombobox *, void *); -// static inline void realuiComboboxOnSelected(uiCombobox *c) -// { -// uiComboboxOnSelected(c, doComboboxOnSelected, NULL); -// } -import "C" - -// no need to lock this; only the GUI thread can access it -var comboboxes = make(map[*C.uiCombobox]*Combobox) - -// Combobox is a Control that represents a drop-down list of strings -// that the user can choose one of at any time. An editable -// Combobox also has an entry field that the user can type an alternate -// choice into. -type Combobox struct { - co *C.uiControl - c *C.uiCombobox - - onSelected func(*Combobox) -} - -// NewCombobox creates a new Combobox. -// This Combobox is not editable. -func NewCombobox() *Combobox { - c := new(Combobox) - - c.c = C.uiNewCombobox() - c.co = (*C.uiControl)(unsafe.Pointer(c.c)) - - C.realuiComboboxOnSelected(c.c) - comboboxes[c.c] = c - - return c -} -/*TODO -// NewEditableCombobox creates a new editable Combobox. -func NewEditableCombobox() *Combobox { - c := new(Combobox) - - c.c = C.uiNewEditableCombobox() - c.co = (*C.uiControl)(unsafe.Pointer(c.c)) - - C.realuiComboboxOnSelected(c.c) - comboboxes[c.c] = c - - return c -} -*/ -// Destroy destroys the Combobox. -func (c *Combobox) Destroy() { - delete(comboboxes, c.c) - C.uiControlDestroy(c.co) -} - -// LibuiControl returns the libui uiControl pointer that backs -// the Window. This is only used by package ui itself and should -// not be called by programs. -func (c *Combobox) LibuiControl() uintptr { - return uintptr(unsafe.Pointer(c.co)) -} - -// Handle returns the OS-level handle associated with this Combobox. -// On Windows this is an HWND of a standard Windows API COMBOBOX -// class (as provided by Common Controls version 6). -// On GTK+ this is a pointer to a GtkComboBoxText. -// On OS X this is a pointer to a NSComboBox for editable Comboboxes -// and to a NSPopUpButton for noneditable Comboboxes. -func (c *Combobox) Handle() uintptr { - return uintptr(C.uiControlHandle(c.co)) -} - -// Show shows the Combobox. -func (c *Combobox) Show() { - C.uiControlShow(c.co) -} - -// Hide hides the Combobox. -func (c *Combobox) Hide() { - C.uiControlHide(c.co) -} - -// Enable enables the Combobox. -func (c *Combobox) Enable() { - C.uiControlEnable(c.co) -} - -// Disable disables the Combobox. -func (c *Combobox) Disable() { - C.uiControlDisable(c.co) -} - -// 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)) -} - -// SetChecked sets the currently select 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.intmax_t(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 := comboboxes[cc] - if c.onSelected != nil { - c.onSelected(c) - } -} diff --git a/combobox.go b/combobox.go new file mode 100644 index 0000000..1224e1e --- /dev/null +++ b/combobox.go @@ -0,0 +1,116 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +// extern void doComboboxOnSelected(uiCombobox *, void *); +// static inline void realuiComboboxOnSelected(uiCombobox *c) +// { +// uiComboboxOnSelected(c, doComboboxOnSelected, NULL); +// } +import "C" + +// no need to lock this; only the GUI thread can access it +var comboboxes = make(map[*C.uiCombobox]*Combobox) + +// 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 { + co *C.uiControl + c *C.uiCombobox + + onSelected func(*Combobox) +} + +// NewCombobox creates a new Combobox. +func NewCombobox() *Combobox { + c := new(Combobox) + + c.c = C.uiNewCombobox() + c.co = (*C.uiControl)(unsafe.Pointer(c.c)) + + C.realuiComboboxOnSelected(c.c) + comboboxes[c.c] = c + + return c +} + +// Destroy destroys the Combobox. +func (c *Combobox) Destroy() { + delete(comboboxes, c.c) + C.uiControlDestroy(c.co) +} + +// LibuiControl returns the libui uiControl pointer that backs +// the Window. This is only used by package ui itself and should +// not be called by programs. +func (c *Combobox) LibuiControl() uintptr { + return uintptr(unsafe.Pointer(c.co)) +} + +// Handle returns the OS-level handle associated with this Combobox. +// On Windows this is an HWND of a standard Windows API COMBOBOX +// class (as provided by Common Controls version 6). +// On GTK+ this is a pointer to a GtkComboBoxText. +// On OS X this is a pointer to a NSPopUpButton. +func (c *Combobox) Handle() uintptr { + return uintptr(C.uiControlHandle(c.co)) +} + +// Show shows the Combobox. +func (c *Combobox) Show() { + C.uiControlShow(c.co) +} + +// Hide hides the Combobox. +func (c *Combobox) Hide() { + C.uiControlHide(c.co) +} + +// Enable enables the Combobox. +func (c *Combobox) Enable() { + C.uiControlEnable(c.co) +} + +// Disable disables the Combobox. +func (c *Combobox) Disable() { + C.uiControlDisable(c.co) +} + +// 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)) +} + +// SetChecked sets the currently select 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.intmax_t(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 := comboboxes[cc] + if c.onSelected != nil { + c.onSelected(c) + } +} diff --git a/editablecombobox.go b/editablecombobox.go new file mode 100644 index 0000000..8f6a825 --- /dev/null +++ b/editablecombobox.go @@ -0,0 +1,120 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +// extern void doEditableComboboxOnChanged(uiCombobox *, void *); +// static inline void realuiEditableComboboxOnChanged(uiCombobox *c) +// { +// uiEditableComboboxOnChanged(c, doEditableComboboxOnChanged, NULL); +// } +import "C" + +// no need to lock this; only the GUI thread can access it +var editableComboboxes = make(map[*C.uiEditableCombobox]*Combobox) + +// EditableCombobox is a Control that represents a drop-down list +// of strings that the user can choose one of at any time. It also has +// an entry field that the user can type an alternate choice into. +type EditableCombobox struct { + co *C.uiControl + c *C.uiEditableCombobox + + onChanged func(*EditableCombobox) +} + +// NewEditableCombobox creates a new EditableCombobox. +func NewEditableCombobox() *EditableCombobox { + c := new(EditableCombobox) + + c.c = C.uiNewEditableCombobox() + c.co = (*C.uiControl)(unsafe.Pointer(c.c)) + + C.realuiEditableComboboxOnChanged(c.c) + editableComboboxes[c.c] = c + + return c +} + +// Destroy destroys the EditableCombobox. +func (c *Combobox) Destroy() { + delete(editableComboboxes, c.c) + C.uiControlDestroy(c.co) +} + +// LibuiControl returns the libui uiControl pointer that backs +// the EditableCombobox. This is only used by package ui itself and +// should not be called by programs. +func (c *Combobox) LibuiControl() uintptr { + return uintptr(unsafe.Pointer(c.co)) +} + +// Handle returns the OS-level handle associated with this EditableCombobox. +// On Windows this is an HWND of a standard Windows API COMBOBOX +// class (as provided by Common Controls version 6). +// On GTK+ this is a pointer to a GtkComboBoxText. +// On OS X this is a pointer to a NSComboBox. +func (c *Combobox) Handle() uintptr { + return uintptr(C.uiControlHandle(c.co)) +} + +// Show shows the EditableCombobox. +func (c *Combobox) Show() { + C.uiControlShow(c.co) +} + +// Hide hides the EditableCombobox. +func (c *Combobox) Hide() { + C.uiControlHide(c.co) +} + +// Enable enables the EditableCombobox. +func (c *Combobox) Enable() { + C.uiControlEnable(c.co) +} + +// Disable disables the EditableCombobox. +func (c *Combobox) Disable() { + C.uiControlDisable(c.co) +} + +// Append adds the named item to the end of the EditableCombobox. +func (c *Combobox) Append(text string) { + ctext := C.CString(text) + C.uiComboboxAppend(c.c, ctext) + freestr(ctext) +} + +// Text returns the text in the entry of the EditableCombobox, which +// could be one of the choices in the list if the user has selected one. +func (c *Combobox) Text() string { + ctext := C.uiEditableComboboxText(c.c) + text := C.GoString(ctext) + C.uiFreeText(ctext) + return text +} + +// SetText sets the text in the entry of the EditableCombobox. +func (c *Combobox) SetText(index int) { + ctext := C.CString(text) + C.uiEditableComboboxSetText(c.c, ctext) + freestr(ctext) +} + +// OnChanged 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) OnChanged(f func(*Combobox)) { + c.onChanged = f +} + +//export doComboboxOnChanged +func doComboboxOnChanged(cc *C.uiCombobox, data unsafe.Pointer) { + c := editableComboboxes[cc] + if c.onChanged != nil { + c.onChanged(c) + } +} -- cgit v1.2.3