From 234b724403bb93171a0eac72a8c24db3879c5900 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 2 Mar 2014 17:44:13 -0500 Subject: [PATCH] Added the other Combobox modification functions to the Mac OS X backend. Before continuing, I'll get messageboxes working... --- bleh_darwin.m | 5 +++++ objc_darwin.h | 1 + sysdata_darwin.go | 32 ++++++++++++++++++++++++++++++-- todo.md | 1 + 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/bleh_darwin.m b/bleh_darwin.m index 80896ef..1b58e77 100644 --- a/bleh_darwin.m +++ b/bleh_darwin.m @@ -36,6 +36,11 @@ id objc_msgSend_int(id obj, SEL sel, intptr_t a) return objc_msgSend(obj, sel, (NSInteger) a); } +id objc_msgSend_id_int(id obj, SEL sel, id a, intptr_t b) +{ + return objc_msgSend(obj, sel, a, (NSInteger) b); +} + /* These are the objc_msgSend() wrappers around NSRect. The problem is that while on 32-bit systems, NSRect is a concrete structure, on 64-bit systems it's just a typedef to CGRect. While in practice just using CGRect everywhere seems to work, better to be safe than sorry. diff --git a/objc_darwin.h b/objc_darwin.h index 5d6bd41..e02f41e 100644 --- a/objc_darwin.h +++ b/objc_darwin.h @@ -79,6 +79,7 @@ extern id objc_msgSend_int(id obj, SEL sel, intptr_t a); m2(id_id, id, id) extern id _objc_msgSend_rect_bool(id obj, SEL sel, int64_t x, int64_t y, int64_t w, int64_t h, BOOL b); +extern id objc_msgSend_id_int(id obj, SEL sel, id a, intptr_t b); m3(id_id_id, id, id, id) m3(sel_id_bool, SEL, id, BOOL) diff --git a/sysdata_darwin.go b/sysdata_darwin.go index 311827e..88d9ddb 100644 --- a/sysdata_darwin.go +++ b/sysdata_darwin.go @@ -25,6 +25,9 @@ type classData struct { textsel C.SEL alttextsel C.SEL append func(id C.id, what string, alternate bool) + insertBefore func(id C.id, what string, before int, alternate bool) + // TODO others + delete func(id C.id, index int) } var ( @@ -169,6 +172,17 @@ var classTypes = [nctypes]*classData{ C.objc_msgSend_id(id, _addItemWithTitle, str) } }, + insertBefore: func(id C.id, what string, before int, alternate bool) { + str := toNSString(what) + if alternate { + C.objc_msgSend_id_int(id, _insertItemWithObjectValueAtIndex, str, C.intptr_t(before)) + } else { + C.objc_msgSend_id_int(id, _insertItemWithTitleAtIndex, str, C.intptr_t(before)) + } + }, + delete: func(id C.id, index int) { + C.objc_msgSend_int(id, _removeItemAtIndex, C.intptr_t(index)) + }, }, c_lineedit: &classData{ }, @@ -315,7 +329,14 @@ if classTypes[s.ctype].append == nil { return nil } } func (s *sysData) insertBefore(what string, before int) error { - // TODO +if classTypes[s.ctype].insertBefore == nil { return nil } + ret := make(chan struct{}) + defer close(ret) + uitask <- func() { + classTypes[s.ctype].insertBefore(s.id, what, before, s.alternate) + ret <- struct{}{} + } + <-ret return nil } @@ -350,7 +371,14 @@ func (s *sysData) setWindowSize(width int, height int) error { } func (s *sysData) delete(index int) error { - // TODO +if classTypes[s.ctype].delete == nil { return nil } + ret := make(chan struct{}) + defer close(ret) + uitask <- func() { + classTypes[s.ctype].delete(s.id, index) + ret <- struct{}{} + } + <-ret return nil } diff --git a/todo.md b/todo.md index 883d951..bac231e 100644 --- a/todo.md +++ b/todo.md @@ -28,6 +28,7 @@ important things: - Cocoa coordinates have (0,0) at the bottom left: need to fix this somehow - I think Cocoa NSButton text is not vertically aligned properly...? - resizing Cocoa windows does not redraw controls correctly +- figure out what to do about deleting a nonexistent item; each backend responds differently by default - there's no GTK+ error handling whatsoever; we need to figure out how it works - make sure GTK+ documentation point differences don't matter - button sizes and LineEdit sizes on Windows seem too big; Comboboxes have margins