Fixed up a bunch of Mac OS X function names, mostly Listbox-related, to be more clear and more consistent.

This commit is contained in:
Pietro Gagliardi 2014-05-16 20:44:19 -04:00
parent 6d67bce9b1
commit d8a7d9b53e
6 changed files with 35 additions and 37 deletions

View File

@ -15,7 +15,7 @@ import "C"
func makeArea(parentWindow C.id, alternate bool, s *sysData) C.id { func makeArea(parentWindow C.id, alternate bool, s *sysData) C.id {
area := C.makeArea() area := C.makeArea()
area = newScrollView(area) area = makeScrollView(area)
addControl(parentWindow, area) addControl(parentWindow, area)
return area return area
} }

View File

@ -14,8 +14,6 @@ Under normal circumstances we would have to build our own data source class, as
After switching from using the Objective-C runtime to using Objective-C directly, you will now need to look both here and in listbox_darwin.m to get what's going on. After switching from using the Objective-C runtime to using Objective-C directly, you will now need to look both here and in listbox_darwin.m to get what's going on.
PERSONAL TODO - make a post somewhere that does all this in Objective-C itself, for the benefit of the programming community. PERSONAL TODO - make a post somewhere that does all this in Objective-C itself, for the benefit of the programming community.
TODO - change the name of some of these functions? specifically the functions that get data about the NSTableView?
*/ */
// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit // #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
@ -65,23 +63,23 @@ But what is arrangedObjects? Why care about arranging objects? We don't have to
Of course, Mac OS X 10.5 adds the ability to automatically arrange objects. So let's just turn that off to be safe. Of course, Mac OS X 10.5 adds the ability to automatically arrange objects. So let's just turn that off to be safe.
*/ */
func newListboxArray() C.id { func makeListboxArray() C.id {
return C.newListboxArray() return C.makeListboxArray()
} }
func appendListboxArray(array C.id, what string) { func listboxArrayAppend(array C.id, what string) {
C.listboxArrayAppend(array, toListboxItem(what)) C.listboxArrayAppend(array, toListboxItem(what))
} }
func insertListboxArrayBefore(array C.id, what string, before int) { func listboxArrayInsertBefore(array C.id, what string, before int) {
C.listboxArrayInsertBefore(array, toListboxItem(what), C.uintptr_t(before)) C.listboxArrayInsertBefore(array, toListboxItem(what), C.uintptr_t(before))
} }
func deleteListboxArray(array C.id, index int) { func listboxArrayDelete(array C.id, index int) {
C.listboxArrayDelete(array, C.uintptr_t(index)) C.listboxArrayDelete(array, C.uintptr_t(index))
} }
func indexListboxArray(array C.id, index int) string { func listboxArrayItemAt(array C.id, index int) string {
dict := C.listboxArrayItemAt(array, C.uintptr_t(index)) dict := C.listboxArrayItemAt(array, C.uintptr_t(index))
return fromListboxItem(dict) return fromListboxItem(dict)
} }
@ -114,7 +112,7 @@ func bindListboxArray(tableColumn C.id, array C.id) {
array, listboxItemKeyPath) array, listboxItemKeyPath)
} }
func listboxArrayController(tableColumn C.id) C.id { func boundListboxArray(tableColumn C.id) C.id {
return C.boundListboxArray(tableColumn, tableColumnBinding) return C.boundListboxArray(tableColumn, tableColumnBinding)
} }
@ -126,9 +124,9 @@ Columns need string identifiers; we'll just reuse the item key.
Editability is also handled here, as opposed to in NSTableView itself. Editability is also handled here, as opposed to in NSTableView itself.
*/ */
func newListboxTableColumn() C.id { func makeListboxTableColumn() C.id {
column := C.makeListboxTableColumn(listboxItemKey) column := C.makeListboxTableColumn(listboxItemKey)
bindListboxArray(column, newListboxArray()) bindListboxArray(column, makeListboxArray())
return column return column
} }
@ -142,8 +140,8 @@ The NSTableViews don't draw their own scrollbars; we have to drop our NSTableVie
The actual creation code was moved to objc_darwin.go. The actual creation code was moved to objc_darwin.go.
*/ */
func newListboxScrollView(listbox C.id) C.id { func makeListboxScrollView(listbox C.id) C.id {
scrollview := newScrollView(listbox) scrollview := makeScrollView(listbox)
C.giveScrollViewBezelBorder(scrollview) // this is what Interface Builder gives the scroll view C.giveScrollViewBezelBorder(scrollview) // this is what Interface Builder gives the scroll view
return scrollview return scrollview
} }
@ -157,7 +155,7 @@ And now, a helper function that takes a scroll view and gets out the array.
*/ */
func listboxArray(listbox C.id) C.id { func listboxArray(listbox C.id) C.id {
return listboxArrayController(listboxTableColumn(listboxInScrollView(listbox))) return boundListboxArray(listboxTableColumn(listboxInScrollView(listbox)))
} }
/* /*
@ -167,26 +165,26 @@ We'll handle selections from the NSTableView too. The only trickery is dealing w
*/ */
func makeListbox(parentWindow C.id, alternate bool, s *sysData) C.id { func makeListbox(parentWindow C.id, alternate bool, s *sysData) C.id {
listbox := C.makeListbox(newListboxTableColumn(), toBOOL(alternate)) listbox := C.makeListbox(makeListboxTableColumn(), toBOOL(alternate))
listbox = newListboxScrollView(listbox) listbox = makeListboxScrollView(listbox)
addControl(parentWindow, listbox) addControl(parentWindow, listbox)
return listbox return listbox
} }
func appendListbox(listbox C.id, what string, alternate bool) { func listboxAppend(listbox C.id, what string, alternate bool) {
array := listboxArray(listbox) array := listboxArray(listbox)
appendListboxArray(array, what) listboxArrayAppend(array, what)
} }
func insertListboxBefore(listbox C.id, what string, before int, alternate bool) { func listboxInsertBefore(listbox C.id, what string, before int, alternate bool) {
array := listboxArray(listbox) array := listboxArray(listbox)
insertListboxArrayBefore(array, what, before) listboxArrayInsertBefore(array, what, before)
} }
// technique from http://stackoverflow.com/questions/3773180/how-to-get-indexes-from-nsindexset-into-an-nsarray-in-cocoa // technique from http://stackoverflow.com/questions/3773180/how-to-get-indexes-from-nsindexset-into-an-nsarray-in-cocoa
// we don't care that the indices were originally NSUInteger since by this point we have a problem anyway; Go programs generally use int indices anyway // we don't care that the indices were originally NSUInteger since by this point we have a problem anyway; Go programs generally use int indices anyway
// we also don't care about NSNotFound because we check the count first AND because NSIndexSet is always sorted (and NSNotFound can be a valid index if the list is large enough... since it's NSIntegerMax, not NSUIntegerMax) // we also don't care about NSNotFound because we check the count first AND because NSIndexSet is always sorted (and NSNotFound can be a valid index if the list is large enough... since it's NSIntegerMax, not NSUIntegerMax)
func selectedListboxIndices(listbox C.id) (list []int) { func listboxSelectedIndices(listbox C.id) (list []int) {
indices := C.listboxSelectedRowIndexes(listboxInScrollView(listbox)) indices := C.listboxSelectedRowIndexes(listboxInScrollView(listbox))
count := int(C.listboxIndexesCount(indices)) count := int(C.listboxIndexesCount(indices))
if count == 0 { if count == 0 {
@ -200,29 +198,29 @@ func selectedListboxIndices(listbox C.id) (list []int) {
return list return list
} }
func selectedListboxTexts(listbox C.id) (texts []string) { func listboxSelectedTexts(listbox C.id) (texts []string) {
indices := selectedListboxIndices(listbox) indices := listboxSelectedIndices(listbox)
if len(indices) == 0 { if len(indices) == 0 {
return nil return nil
} }
array := listboxArray(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] = listboxArrayItemAt(array, indices[i])
} }
return texts return texts
} }
func deleteListbox(listbox C.id, index int) { func listboxDelete(listbox C.id, index int) {
array := listboxArray(listbox) array := listboxArray(listbox)
deleteListboxArray(array, index) listboxArrayDelete(array, index)
} }
func listboxLen(listbox C.id) int { func listboxLen(listbox C.id) int {
return int(C.listboxLen(listboxInScrollView(listbox))) return int(C.listboxLen(listboxInScrollView(listbox)))
} }
func selectListboxIndices(id C.id, indices []int) { func listboxSelectIndices(id C.id, indices []int) {
listbox := listboxInScrollView(id) listbox := listboxInScrollView(id)
if len(indices) == 0 { if len(indices) == 0 {
C.listboxDeselectAll(listbox) C.listboxDeselectAll(listbox)

View File

@ -31,7 +31,7 @@ id fromListboxItem(id item, id key)
return [toNSMutableDictionary(item) objectForKey:key]; return [toNSMutableDictionary(item) objectForKey:key];
} }
id newListboxArray(void) id makeListboxArray(void)
{ {
NSArrayController *ac; NSArrayController *ac;

View File

@ -31,7 +31,7 @@ func toBOOL(what bool) C.BOOL {
// These consolidate the NSScrollView code (used by listbox_darwin.go and area_darwin.go) into a single place. // These consolidate the NSScrollView code (used by listbox_darwin.go and area_darwin.go) into a single place.
func newScrollView(content C.id) C.id { func makeScrollView(content C.id) C.id {
return C.makeScrollView(content) return C.makeScrollView(content)
} }

View File

@ -64,7 +64,7 @@ extern void msgBoxError(id, id);
/* listbox_darwin.m */ /* listbox_darwin.m */
extern id toListboxItem(id, id); extern id toListboxItem(id, id);
extern id fromListboxItem(id, id); extern id fromListboxItem(id, id);
extern id newListboxArray(void); extern id makeListboxArray(void);
extern void listboxArrayAppend(id, id); extern void listboxArrayAppend(id, id);
extern void listboxArrayInsertBefore(id, id, uintptr_t); extern void listboxArrayInsertBefore(id, id, uintptr_t);
extern void listboxArrayDelete(id, uintptr_t); extern void listboxArrayDelete(id, uintptr_t);

View File

@ -177,13 +177,13 @@ var classTypes = [nctypes]*classData{
make: makeListbox, make: makeListbox,
show: controlShow, show: controlShow,
hide: controlHide, hide: controlHide,
append: appendListbox, append: listboxAppend,
insertBefore: insertListboxBefore, insertBefore: listboxInsertBefore,
selIndices: selectedListboxIndices, selIndices: listboxSelectedIndices,
selTexts: selectedListboxTexts, selTexts: listboxSelectedTexts,
delete: deleteListbox, delete: listboxDelete,
len: listboxLen, len: listboxLen,
selectIndices: selectListboxIndices, selectIndices: listboxSelectIndices,
}, },
c_progressbar: &classData{ c_progressbar: &classData{
make: func(parentWindow C.id, alternate bool, s *sysData) C.id { make: func(parentWindow C.id, alternate bool, s *sysData) C.id {