summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-03-02 17:19:25 -0500
committerPietro Gagliardi <[email protected]>2014-03-02 17:19:25 -0500
commit01e587174144ed4b6b5383346fdf2697f86f9423 (patch)
tree5d92cf706dd8c2dff231678bad875f4d2e07cb1b
parentdb1c6c5c17efa0aa160de1bdf8193f984197f658 (diff)
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.
-rw-r--r--cocoalists78
-rw-r--r--sysdata_darwin.go52
2 files changed, 129 insertions, 1 deletions
diff --git a/cocoalists b/cocoalists
new file mode 100644
index 0000000..ee7283c
--- /dev/null
+++ b/cocoalists
@@ -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]
diff --git a/sysdata_darwin.go b/sysdata_darwin.go
index 8966324..311827e 100644
--- a/sysdata_darwin.go
+++ b/sysdata_darwin.go
@@ -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
}