diff --git a/listbox.go b/listbox.go index 92067c0..7c11f78 100644 --- a/listbox.go +++ b/listbox.go @@ -148,6 +148,8 @@ func (l *Listbox) make(window *sysData) (err error) { for _, s := range l.initItems { l.sysData.append(s) } + // some platforms automatically select an item; undo that + l.sysData.selectIndices(nil) l.created = true return nil } diff --git a/listbox_darwin.go b/listbox_darwin.go index e6804e7..b5f26a8 100644 --- a/listbox_darwin.go +++ b/listbox_darwin.go @@ -241,6 +241,7 @@ var ( _selectedRowIndexes = sel_getUid("selectedRowIndexes") _count = sel_getUid("count") _numberOfRows = sel_getUid("numberOfRows") + _deselectAll = sel_getUid("deselectAll:") ) func makeListbox(parentWindow C.id, alternate bool) C.id { @@ -315,3 +316,12 @@ func deleteListbox(listbox C.id, index int) { func listboxLen(listbox C.id) int { return int(C.objc_msgSend_intret_noargs(listboxInScrollView(listbox), _numberOfRows)) } + +func selectListboxIndices(id C.id, indices []int) { + listbox := listboxInScrollView(id) + if len(indices) == 0 { + C.objc_msgSend_id(listbox, _deselectAll, listbox) + return + } + panic("selectListboxIndices() > 0 not yet implemented (TODO)") +} diff --git a/sysdata.go b/sysdata.go index d2ac699..176a42d 100644 --- a/sysdata.go +++ b/sysdata.go @@ -41,6 +41,7 @@ var _xSysData interface { len() int setAreaSize(int, int) selectIndex(int) + selectIndices([]int) } = &sysData{} // this line will error if there's an inconsistency // signal sends the event signal. This raise is done asynchronously to avoid deadlocking the UI task. diff --git a/sysdata_darwin.go b/sysdata_darwin.go index cfbd00e..12b6b12 100644 --- a/sysdata_darwin.go +++ b/sysdata_darwin.go @@ -34,6 +34,7 @@ type classData struct { delete func(id C.id, index int) len func(id C.id) int selectIndex func(id C.id, index int, alternate bool) + selectIndices func(id C.id, indices []int) } var ( @@ -304,6 +305,7 @@ var classTypes = [nctypes]*classData{ selTexts: selectedListboxTexts, delete: deleteListbox, len: listboxLen, + selectIndices: selectListboxIndices, }, c_progressbar: &classData{ make: func(parentWindow C.id, alternate bool) C.id { @@ -571,3 +573,13 @@ func (s *sysData) selectIndex(index int) { } <-ret } + +func (s *sysData) selectIndices(indices []int) { + ret := make(chan struct{}) + defer close(ret) + uitask <- func() { + classTypes[s.ctype].selectIndices(s.id, indices) + ret <- struct{}{} + } + <-ret +} diff --git a/sysdata_unix.go b/sysdata_unix.go index 93b3704..c9be614 100644 --- a/sysdata_unix.go +++ b/sysdata_unix.go @@ -363,3 +363,7 @@ func (s *sysData) setAreaSize(width int, height int) { func (s *sysData) selectIndex(index int) { // TODO not yet implemented on Unix (added for Mac only right now) } + +func (s *sysData) selectIndices(indices []int) { + // TODO not yet implemented on Windows (added for Mac only right now) +} diff --git a/sysdata_windows.go b/sysdata_windows.go index ba3520e..35d246f 100644 --- a/sysdata_windows.go +++ b/sysdata_windows.go @@ -645,3 +645,7 @@ func (s *sysData) setAreaSize(width int, height int) { func (s *sysData) selectIndex(index int) { // TODO not yet implemented on Windows (added for Mac only right now) } + +func (s *sysData) selectIndices(indices []int) { + // TODO not yet implemented on Windows (added for Mac only right now) +} diff --git a/todo.md b/todo.md index 5b87be6..f03eacc 100644 --- a/todo.md +++ b/todo.md @@ -1,5 +1,4 @@ important things: -- NSTableViews start out with an initial selection (which is against our docs) - NSComboBox scans the entered text to see if it matches one of the items and returns the index of that item if it does; find out how to suppress this so that it returns -1 unless the item was chosen from the list (like the other platforms) - some Cocoa controls don't seem to resize correctly: Buttons have space around the edges - LineEdit heights on Windows seem too big; either that or LineEdit, Button, and Label text is not vertically centered properly