Wrapped Mac OS X Listboxes in NSScrollViews. Their preferredSize seems to be more reasonable now. Now to just add scrollbars...
This commit is contained in:
parent
dd2abbacce
commit
8bacbf8cd6
|
@ -139,7 +139,7 @@ func bindListboxArray(tableColumn C.id, array C.id) {
|
||||||
C.nilid) // no options
|
C.nilid) // no options
|
||||||
}
|
}
|
||||||
|
|
||||||
func listboxArray(tableColumn C.id) C.id {
|
func listboxArrayController(tableColumn C.id) C.id {
|
||||||
dict := C.objc_msgSend_id(tableColumn, _infoForBinding, tableColumnBinding)
|
dict := C.objc_msgSend_id(tableColumn, _infoForBinding, tableColumnBinding)
|
||||||
return C.objc_msgSend_id(dict, _objectForKey, *C._NSObservedObjectKey)
|
return C.objc_msgSend_id(dict, _objectForKey, *C._NSObservedObjectKey)
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,37 @@ func listboxTableColumn(listbox C.id) C.id {
|
||||||
return C.objc_msgSend_id(listbox, _tableColumnWithIdentifier, listboxItemKey)
|
return C.objc_msgSend_id(listbox, _tableColumnWithIdentifier, listboxItemKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
The NSTableViews don't draw their own scrollbars; we have to drop our NSTableViews in NSScrollViews for this.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var (
|
||||||
|
_NSScrollView = objc_getClass("NSScrollView")
|
||||||
|
|
||||||
|
_setDocumentView = sel_getUid("setDocumentView:")
|
||||||
|
_documentView = sel_getUid("documentView")
|
||||||
|
)
|
||||||
|
|
||||||
|
func newListboxScrollView(listbox C.id) C.id {
|
||||||
|
scrollview := objc_alloc(_NSScrollView)
|
||||||
|
scrollview = objc_msgSend_rect(scrollview, _initWithFrame,
|
||||||
|
0, 0, 100, 100)
|
||||||
|
C.objc_msgSend_id(scrollview, _setDocumentView, listbox)
|
||||||
|
return scrollview
|
||||||
|
}
|
||||||
|
|
||||||
|
func listboxInScrollView(scrollview C.id) C.id {
|
||||||
|
return C.objc_msgSend_noargs(scrollview, _documentView)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
And now, a helper function that takes a scroll view and gets out the array.
|
||||||
|
*/
|
||||||
|
|
||||||
|
func listboxArray(listbox C.id) C.id {
|
||||||
|
return listboxArrayController(listboxTableColumn(listboxInScrollView(listbox)))
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
...and finally, we work with the NSTableView directly. These are the methods sysData calls.
|
...and finally, we work with the NSTableView directly. These are the methods sysData calls.
|
||||||
|
|
||||||
|
@ -199,18 +230,19 @@ func makeListbox(parentWindow C.id, alternate bool) C.id {
|
||||||
C.objc_msgSend_bool(listbox, _setAllowsEmptySelection, C.BOOL(C.YES))
|
C.objc_msgSend_bool(listbox, _setAllowsEmptySelection, C.BOOL(C.YES))
|
||||||
C.objc_msgSend_id(listbox, _setHeaderView, C.nilid)
|
C.objc_msgSend_id(listbox, _setHeaderView, C.nilid)
|
||||||
// TODO others?
|
// TODO others?
|
||||||
|
listbox = newListboxScrollView(listbox)
|
||||||
windowView := C.objc_msgSend_noargs(parentWindow, _contentView)
|
windowView := C.objc_msgSend_noargs(parentWindow, _contentView)
|
||||||
C.objc_msgSend_id(windowView, _addSubview, listbox)
|
C.objc_msgSend_id(windowView, _addSubview, listbox)
|
||||||
return listbox
|
return listbox
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendListbox(listbox C.id, what string, alternate bool) {
|
func appendListbox(listbox C.id, what string, alternate bool) {
|
||||||
array := listboxArray(listboxTableColumn(listbox))
|
array := listboxArray(listbox)
|
||||||
appendListboxArray(array, what)
|
appendListboxArray(array, what)
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertListboxBefore(listbox C.id, what string, before int, alternate bool) {
|
func insertListboxBefore(listbox C.id, what string, before int, alternate bool) {
|
||||||
array := listboxArray(listboxTableColumn(listbox))
|
array := listboxArray(listbox)
|
||||||
insertListboxArrayBefore(array, what, before)
|
insertListboxArrayBefore(array, what, before)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +252,7 @@ func insertListboxBefore(listbox C.id, what string, before int, alternate bool)
|
||||||
func selectedListboxIndices(listbox C.id) (list []int) {
|
func selectedListboxIndices(listbox C.id) (list []int) {
|
||||||
var cindices []C.uintptr_t
|
var cindices []C.uintptr_t
|
||||||
|
|
||||||
indices := C.objc_msgSend_noargs(listbox, _selectedRowIndexes)
|
indices := C.objc_msgSend_noargs(listboxInScrollView(listbox), _selectedRowIndexes)
|
||||||
count := int(C.objc_msgSend_uintret_noargs(indices, _count))
|
count := int(C.objc_msgSend_uintret_noargs(indices, _count))
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -243,7 +275,7 @@ func selectedListboxTexts(listbox C.id) (texts []string) {
|
||||||
if len(indices) == 0 {
|
if len(indices) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
array := listboxArray(listboxTableColumn(listbox))
|
array := listboxArray(listbox)
|
||||||
texts = make([]string, len(indices))
|
texts = make([]string, len(indices))
|
||||||
for i := 0; i < len(texts); i++ {
|
for i := 0; i < len(texts); i++ {
|
||||||
texts[i] = indexListboxArray(array, indices[i])
|
texts[i] = indexListboxArray(array, indices[i])
|
||||||
|
@ -252,6 +284,6 @@ func selectedListboxTexts(listbox C.id) (texts []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteListbox(listbox C.id, index int) {
|
func deleteListbox(listbox C.id, index int) {
|
||||||
array := listboxArray(listboxTableColumn(listbox))
|
array := listboxArray(listbox)
|
||||||
deleteListboxArray(array, index)
|
deleteListboxArray(array, index)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ Cocoa doesn't provide a reliable way to get the preferred size of a control (you
|
||||||
var (
|
var (
|
||||||
_sizeToFit = sel_getUid("sizeToFit")
|
_sizeToFit = sel_getUid("sizeToFit")
|
||||||
// _frame in sysdata_darwin.go
|
// _frame in sysdata_darwin.go
|
||||||
// _documentView in listbox_darwin.go
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// standard case: control immediately passed in
|
// standard case: control immediately passed in
|
||||||
|
@ -24,8 +23,7 @@ func controlPrefSize(control C.id) (width int, height int) {
|
||||||
|
|
||||||
// NSTableView is actually in a NSScrollView so we have to get it out first
|
// NSTableView is actually in a NSScrollView so we have to get it out first
|
||||||
func listboxPrefSize(control C.id) (width int, height int) {
|
func listboxPrefSize(control C.id) (width int, height int) {
|
||||||
// return controlPrefSize(C.objc_msgSend_noargs(control, _documentView))
|
return controlPrefSize(listboxInScrollView(control))
|
||||||
return controlPrefSize(control)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var prefsizefuncs = [nctypes]func(C.id) (int, int){
|
var prefsizefuncs = [nctypes]func(C.id) (int, int){
|
||||||
|
|
Loading…
Reference in New Issue