summaryrefslogtreecommitdiff
path: root/sysdata_darwin.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-04-12 21:49:41 -0400
committerPietro Gagliardi <[email protected]>2014-04-12 21:49:41 -0400
commit274fa0c2928e3d1573a83d2f68048963df5e16e4 (patch)
tree43d1062a682bffcbdf54a7910132ef740fffa0c4 /sysdata_darwin.go
parentb9e5ef8e4b042a3c734fbadac1d45e8302e6296a (diff)
Fixed Comboboxes on Mac OS X having an initial selection. This also lays the groundwork for adding Combobox/Listbox.Select() as a public function...
Diffstat (limited to 'sysdata_darwin.go')
-rw-r--r--sysdata_darwin.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/sysdata_darwin.go b/sysdata_darwin.go
index 1b6795c..cfbd00e 100644
--- a/sysdata_darwin.go
+++ b/sysdata_darwin.go
@@ -33,6 +33,7 @@ type classData struct {
selTexts func(id C.id) []string
delete func(id C.id, index int)
len func(id C.id) int
+ selectIndex func(id C.id, index int, alternate bool)
}
var (
@@ -82,6 +83,8 @@ var (
_setIndeterminate = sel_getUid("setIndeterminate:")
_setDoubleValue = sel_getUid("setDoubleValue:")
_numberOfItems = sel_getUid("numberOfItems")
+ _selectItemAtIndex = sel_getUid("selectItemAtIndex:")
+ _deselectItemAtIndex = sel_getUid("deselectItemAtIndex:")
)
// because the only way to make a new NSControl/NSView is with a frame (it gets overridden later)
@@ -238,6 +241,22 @@ var classTypes = [nctypes]*classData{
len: func(id C.id) int {
return int(C.objc_msgSend_intret_noargs(id, _numberOfItems))
},
+ selectIndex: func(id C.id, index int, alternate bool) {
+ // NSPopUpButton makes this easy
+ if !alternate {
+ C.objc_msgSend_int(id, _selectItemAtIndex, C.intptr_t(index))
+ return
+ }
+ // NSComboBox doesn't document that we can do [cb selectItemAtIndex:-1], so we have to do this to be safe
+ if index == -1 {
+ idx := C.objc_msgSend_intret_noargs(id, _indexOfSelectedItem)
+ if idx != -1 {
+ C.objc_msgSend_int(id, _deselectItemAtIndex, idx)
+ }
+ return
+ }
+ C.objc_msgSend_int(id, _selectItemAtIndex, C.intptr_t(index))
+ },
},
c_lineedit: &classData{
make: func(parentWindow C.id, alternate bool) C.id {
@@ -542,3 +561,13 @@ func (s *sysData) setAreaSize(width int, height int) {
}
<-ret
}
+
+func (s *sysData) selectIndex(index int) {
+ ret := make(chan struct{})
+ defer close(ret)
+ uitask <- func() {
+ classTypes[s.ctype].selectIndex(s.id, index, s.alternate)
+ ret <- struct{}{}
+ }
+ <-ret
+}