Fixed Comboboxes on Mac OS X having an initial selection. This also lays the groundwork for adding Combobox/Listbox.Select() as a public function...
This commit is contained in:
parent
b9e5ef8e4b
commit
274fa0c292
|
@ -145,6 +145,8 @@ func (c *Combobox) make(window *sysData) (err error) {
|
||||||
for _, s := range c.initItems {
|
for _, s := range c.initItems {
|
||||||
c.sysData.append(s)
|
c.sysData.append(s)
|
||||||
}
|
}
|
||||||
|
// some platforms automatically select an item; undo that
|
||||||
|
c.sysData.selectIndex(-1)
|
||||||
c.created = true
|
c.created = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ var _xSysData interface {
|
||||||
setProgress(int)
|
setProgress(int)
|
||||||
len() int
|
len() int
|
||||||
setAreaSize(int, int)
|
setAreaSize(int, int)
|
||||||
|
selectIndex(int)
|
||||||
} = &sysData{} // this line will error if there's an inconsistency
|
} = &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.
|
// signal sends the event signal. This raise is done asynchronously to avoid deadlocking the UI task.
|
||||||
|
|
|
@ -33,6 +33,7 @@ type classData struct {
|
||||||
selTexts func(id C.id) []string
|
selTexts func(id C.id) []string
|
||||||
delete func(id C.id, index int)
|
delete func(id C.id, index int)
|
||||||
len func(id C.id) int
|
len func(id C.id) int
|
||||||
|
selectIndex func(id C.id, index int, alternate bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -82,6 +83,8 @@ var (
|
||||||
_setIndeterminate = sel_getUid("setIndeterminate:")
|
_setIndeterminate = sel_getUid("setIndeterminate:")
|
||||||
_setDoubleValue = sel_getUid("setDoubleValue:")
|
_setDoubleValue = sel_getUid("setDoubleValue:")
|
||||||
_numberOfItems = sel_getUid("numberOfItems")
|
_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)
|
// 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 {
|
len: func(id C.id) int {
|
||||||
return int(C.objc_msgSend_intret_noargs(id, _numberOfItems))
|
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{
|
c_lineedit: &classData{
|
||||||
make: func(parentWindow C.id, alternate bool) C.id {
|
make: func(parentWindow C.id, alternate bool) C.id {
|
||||||
|
@ -542,3 +561,13 @@ func (s *sysData) setAreaSize(width int, height int) {
|
||||||
}
|
}
|
||||||
<-ret
|
<-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
|
||||||
|
}
|
||||||
|
|
|
@ -359,3 +359,7 @@ func (s *sysData) setAreaSize(width int, height int) {
|
||||||
}
|
}
|
||||||
<-ret
|
<-ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *sysData) selectIndex(index int) {
|
||||||
|
// TODO not yet implemented on Unix (added for Mac only right now)
|
||||||
|
}
|
||||||
|
|
|
@ -641,3 +641,7 @@ func (s *sysData) setAreaSize(width int, height int) {
|
||||||
}
|
}
|
||||||
<-ret
|
<-ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *sysData) selectIndex(index int) {
|
||||||
|
// TODO not yet implemented on Windows (added for Mac only right now)
|
||||||
|
}
|
||||||
|
|
4
todo.md
4
todo.md
|
@ -1,7 +1,5 @@
|
||||||
important things:
|
important things:
|
||||||
- NSPopUpButton does allow no initial selection ([b setSelectedIndex:-1]); use it
|
- NSTableViews start out with an initial selection (which is against our docs)
|
||||||
- need to use it /after/ adding initial items, otherwise it won't work
|
|
||||||
- find out if I can do the same with the ListBoxes
|
|
||||||
- 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)
|
- 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
|
- 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
|
- LineEdit heights on Windows seem too big; either that or LineEdit, Button, and Label text is not vertically centered properly
|
||||||
|
|
Loading…
Reference in New Issue