Added the beginning of the Mac OS X implementation of Combobox; also added a file to plan out how lists will be implemented/are being implemented.

This commit is contained in:
Pietro Gagliardi 2014-03-02 17:19:25 -05:00
parent db1c6c5c17
commit 01e5871741
2 changed files with 129 additions and 1 deletions

78
cocoalists Normal file
View File

@ -0,0 +1,78 @@
NSPopUpButton (non-editable combo box)
make:
b = [[NSPopUpButton alloc]
initWithFrame:(0, 0, 100, 100)
pullsDown:NO]
add:
[b addItemWithTitle:toNSString(s)]
insertBefore:
[b insertItemWithTitle:toNSString(s)
atIndex:index] (NSInteger)
remove:
[b removeItemAtIndex:index] (NSInteger)
selection:
fromNSString([b titleOfSelectedItem])
(returns nil if nothing is selected; need to edit to return "" if so)
selectedIndex:
[b indexOfSelectedItem] (NSInteger)
(returns -1 if nothing is selected)
NSComboBox (editable combo box)
make:
b = [[NSComboBox alloc]
initWithFrame:(0, 0, 100, 100)]
[b setUsesDataSource:NO] // internal data soruce
add:
[b addItemWithObjectValue:toNSString(s)]
insertBefore:
[b insertItemWithObjectValue:toNSString(s)
atIndex:index] (NSInteger)
remove:
[b removeItemAtIndex:index] (NSInteger)
selection:
this depends on if the /user/ selecting an item changes the edit box
this appears to be the case, so
fromNSString([b stringValue])
note that if we ever add Combobox.SetText(), we are responsible for managing both the edit field AND the list, as they are programmatically separate
selectedIndex:
[b indexOfSelectedItem] (NSInteger)
(returns -1 if nothing is selected)
(TODO custom text?)
NSTableView (listbox)
make:
b = [[NSTableView alloc]
initWithFrame:(0, 0, 100, 100)]
col = [[NSTableColumn alloc]
initWithIdentifier:@"listboxcolumn"]
listDict = [NSMutableDictionary xxxx]
listItems = [[xxx]]
[listItems addObject:listDict]
[col bind:@"value"
toObject:listItems
withKeyPath:@"xxxxx.listboxcolumn"
options:nilid]
[b addTableColumn:col]
// TODO autoresizing
add:
insertBefore:
remove:
selection:
idx = [b selectedRow] (NSInteger)
if idx == -1 {
return ""
}
dataSource = [b dataSource]
selectedIndex:
[b selectedRow] (NSInteger)
(returns -1 if none selected)
selectedIndices:
nsidx = [b selectedRowIndexes]
c = [nsidx count] (NSUInteger)
nsidxbuf = C.makeNSUIntegerArray(c)
[nsidx getIndexes:nsidxbuf
maxCont:c
inIndexRange:nilid]
// and just copy out of nsidxbuf somehow
// I think this is going to have to make 2 temporary arrays; a better option will be needed! TODO
selectedTexts:
indices := selectedIndices()
dataSource = [b dataSource]

View File

@ -24,11 +24,14 @@ type classData struct {
settextsel C.SEL
textsel C.SEL
alttextsel C.SEL
append func(id C.id, what string, alternate bool)
}
var (
_NSWindow = objc_getClass("NSWindow")
_NSButton = objc_getClass("NSButton")
_NSPopUpButton = objc_getClass("NSPopUpButton")
_NSComboBox = objc_getClass("NSComboBox")
_initWithContentRect = sel_getUid("initWithContentRect:styleMask:backing:defer:")
_initWithFrame = sel_getUid("initWithFrame:")
@ -50,6 +53,15 @@ var (
_contentView = sel_getUid("contentView")
_addSubview = sel_getUid("addSubview:")
_setButtonType = sel_getUid("setButtonType:")
_initWithFramePullsDown = sel_getUid("initWithFrame:pullsDown:")
_setUsesDataSource = sel_getUid("setUsesDataSource:")
_addItemWithTitle = sel_getUid("addItemWithTitle:")
_insertItemWithTitleAtIndex = sel_getUid("insertItemWithTitle:atIndex:")
_removeItemAtIndex = sel_getUid("removeItemAtIndex:")
_titleOfSelectedItem = sel_getUid("titleOfSelectedItem")
_indexOfSelectedItem = sel_getUid("indexOfSelectedItem")
_addItemWithObjectValue = sel_getUid("addItemWithObjectValue:")
_insertItemWithObjectValueAtIndex = sel_getUid("insertItemWithObjectValue:atIndex:")
)
func controlShow(what C.id) {
@ -126,6 +138,37 @@ var classTypes = [nctypes]*classData{
textsel: _title,
},
c_combobox: &classData{
make: func(parentWindow C.id, alternate bool) C.id {
var combobox C.id
if alternate {
combobox = objc_alloc(_NSComboBox)
combobox = objc_msgSend_rect(combobox, _initWithFrame,
0, 0, 100, 100)
C.objc_msgSend_bool(combobox, _setUsesDataSource, C.BOOL(C.NO))
} else {
combobox = objc_alloc(_NSPopUpButton)
combobox = objc_msgSend_rect_bool(combobox, _initWithFramePullsDown,
0, 0, 100, 100,
C.BOOL(C.NO))
}
windowView := C.objc_msgSend_noargs(parentWindow, _contentView)
C.objc_msgSend_id(windowView, _addSubview, combobox)
return combobox
},
show: controlShow,
hide: controlHide,
// TODO setText
textsel: _titleOfSelectedItem,
alttextsel: _stringValue,
append: func(id C.id, what string, alternate bool) {
str := toNSString(what)
if alternate {
C.objc_msgSend_id(id, _addItemWithObjectValue, str)
} else {
C.objc_msgSend_id(id, _addItemWithTitle, str)
}
},
},
c_lineedit: &classData{
},
@ -260,7 +303,14 @@ if classTypes[s.ctype].textsel == zero { return "" }
}
func (s *sysData) append(what string) error {
// TODO
if classTypes[s.ctype].append == nil { return nil }
ret := make(chan struct{})
defer close(ret)
uitask <- func() {
classTypes[s.ctype].append(s.id, what, s.alternate)
ret <- struct{}{}
}
<-ret
return nil
}