From 791345fa97693016ae3786f3951083edfb752f85 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 13 May 2014 07:09:22 -0400 Subject: [PATCH] Finished migrating sysdata_darwin.go away from calling objc_msgSend() directly. initWithDummyFrame() is still there as other files use it. --- sysdata_darwin.go | 62 ++++++++++++++++++++++++++++------------------- sysdata_darwin.h | 7 ++++++ sysdata_darwin.m | 37 ++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 25 deletions(-) diff --git a/sysdata_darwin.go b/sysdata_darwin.go index f4fe145..3b2bc38 100644 --- a/sysdata_darwin.go +++ b/sysdata_darwin.go @@ -24,12 +24,8 @@ type classData struct { getinside func(scrollview C.id) C.id show func(what C.id) hide func(what C.id) -// settext func(what C.id, text string) - settextsel C.SEL -// text func(what C.id) string - textsel C.SEL -// alttextsel func(what C.id) string - alttextsel C.SEL + settext func(what C.id, text C.id) + text func(what C.id, alternate bool) C.id append func(id C.id, what string, alternate bool) insertBefore func(id C.id, what string, before int, alternate bool) selIndex func(id C.id) int @@ -142,8 +138,12 @@ var classTypes = [nctypes]*classData{ hide: func(what C.id) { C.windowHide(what) }, - settextsel: _setTitle, - textsel: _title, + settext: func(what C.id, text C.id) { + C.windowSetTitle(what, text) + }, + text: func(what C.id, alternate bool) C.id { + return C.windowTitle(what) + }, }, c_button: &classData{ make: func(parentWindow C.id, alternate bool, s *sysData) C.id { @@ -155,8 +155,12 @@ var classTypes = [nctypes]*classData{ }, show: controlShow, hide: controlHide, - settextsel: _setTitle, - textsel: _title, + settext: func(what C.id, text C.id) { + C.buttonSetText(what, text) + }, + text: func(what C.id, alternate bool) C.id { + return C.buttonText(what) + }, }, c_checkbox: &classData{ make: func(parentWindow C.id, alternate bool, s *sysData) C.id { @@ -167,8 +171,12 @@ var classTypes = [nctypes]*classData{ }, show: controlShow, hide: controlHide, - settextsel: _setTitle, - textsel: _title, + settext: func(what C.id, text C.id) { + C.buttonSetText(what, text) + }, + text: func(what C.id, alternate bool) C.id { + return C.buttonText(what) + }, }, c_combobox: &classData{ make: func(parentWindow C.id, alternate bool, s *sysData) C.id { @@ -179,8 +187,9 @@ var classTypes = [nctypes]*classData{ }, show: controlShow, hide: controlHide, - textsel: _titleOfSelectedItem, - alttextsel: _stringValue, + text: func(what C.id, alternate bool) C.id { + return C.comboboxText(what, toBOOL(alternate)) + }, append: func(id C.id, what string, alternate bool) { C.comboboxAppend(id, toBOOL(alternate), toNSString(what)) }, @@ -210,9 +219,12 @@ var classTypes = [nctypes]*classData{ }, show: controlShow, hide: controlHide, - settextsel: _setStringValue, - textsel: _stringValue, - alttextsel: _stringValue, + settext: func(what C.id, text C.id) { + C.lineeditSetText(what, text) + }, + text: func(what C.id, alternate bool) C.id { + return C.lineeditText(what) + }, }, c_label: &classData{ make: func(parentWindow C.id, alternate bool, s *sysData) C.id { @@ -223,8 +235,12 @@ var classTypes = [nctypes]*classData{ }, show: controlShow, hide: controlHide, - settextsel: _setStringValue, - textsel: _stringValue, + settext: func(what C.id, text C.id) { + C.lineeditSetText(what, text) + }, + text: func(what C.id, alternate bool) C.id { + return C.lineeditText(what) + }, }, c_listbox: &classData{ make: makeListbox, @@ -332,7 +348,7 @@ func (s *sysData) setText(text string) { ret := make(chan struct{}) defer close(ret) uitask <- func() { - C.objc_msgSend_id(s.id, classTypes[s.ctype].settextsel, toNSString(text)) + classTypes[s.ctype].settext(s.id, toNSString(text)) ret <- struct{}{} } <-ret @@ -357,14 +373,10 @@ func (s *sysData) isChecked() bool { } func (s *sysData) text() string { - sel := classTypes[s.ctype].textsel - if s.alternate { - sel = classTypes[s.ctype].alttextsel - } ret := make(chan string) defer close(ret) uitask <- func() { - str := C.objc_msgSend_noargs(s.id, sel) + str := classTypes[s.ctype].text(s.id, s.alternate) ret <- fromNSString(str) } return <-ret diff --git a/sysdata_darwin.h b/sysdata_darwin.h index 24e24c3..49824fc 100644 --- a/sysdata_darwin.h +++ b/sysdata_darwin.h @@ -9,10 +9,15 @@ extern void applyStandardControlFont(id); extern id makeWindow(id); extern void windowShow(id); extern void windowHide(id); +extern void windowSetTitle(id, id); +extern id windowTitle(id); extern id makeButton(void); extern void buttonSetTargetAction(id, id); +extern void buttonSetText(id, id); +extern id buttonText(id); extern id makeCheckbox(void); extern id makeCombobox(BOOL); +extern id comboboxText(id, BOOL); extern void comboboxAppend(id, BOOL, id); extern void comboboxInsertBefore(id, BOOL, id, intptr_t); extern intptr_t comboboxSelectedIndex(id); @@ -20,6 +25,8 @@ extern void comboboxDelete(id, intptr_t); extern intptr_t comboboxLen(id); extern void comboboxSelectIndex(id, BOOL, intptr_t); extern id makeLineEdit(BOOL); // TODO I accidentally left this as taking no arguments and clang didn't complain when compiling sysdata_darwin.m?! +extern void lineeditSetText(id, id); +extern id lineeditText(id); extern id makeLabel(void); extern id makeProgressBar(void); extern void setRect(id, intptr_t, intptr_t, intptr_t, intptr_t); diff --git a/sysdata_darwin.m b/sysdata_darwin.m index 75202a9..bfefe4e 100644 --- a/sysdata_darwin.m +++ b/sysdata_darwin.m @@ -80,6 +80,16 @@ void windowHide(id window) [toNSWindow(window) orderOut:window]; } +void windowSetTitle(id window, id title) +{ + [toNSWindow(window) setTitle:title]; +} + +id windowTitle(id window) +{ + return [toNSWindow(window) title]; +} + id makeButton(void) { NSButton *button; @@ -96,6 +106,16 @@ void buttonSetTargetAction(id button, id delegate) [toNSButton(button) setAction:@selector(buttonClicked:)]; } +void buttonSetText(id button, id text) +{ + [toNSButton(button) setTitle:text]; +} + +id buttonText(id button) +{ + return [toNSButton(button) title]; +} + id makeCheckbox(void) { NSButton *checkbox; @@ -125,6 +145,13 @@ id makeCombobox(BOOL editable) return combobox; } +id comboboxText(id combobox, BOOL editable) +{ + if (!editable) + return [toNSPopUpButton(combobox) titleOfSelectedItem]; + return [toNSComboBox(combobox) stringValue]; +} + void comboboxAppend(id combobox, BOOL editable, id str) { if (!editable) { @@ -193,6 +220,16 @@ id makeLineEdit(BOOL password) initWithFrame:dummyRect]; } +void lineeditSetText(id lineedit, id text) +{ + [toNSTextField(lineedit) setStringValue:text]; +} + +id lineeditText(id lineedit) +{ + return [toNSTextField(lineedit) stringValue]; +} + id makeLabel(void) { NSTextField *label;