Removed objc_msgSend_rect(). This also consolidates all initWithFrame: calls into a simple initWithDummyFrame().

This commit is contained in:
Pietro Gagliardi 2014-04-04 19:51:23 -04:00
parent dd4a7b9cbe
commit 5a5b486b6a
6 changed files with 22 additions and 35 deletions

View File

@ -278,8 +278,7 @@ func areaView_flagsChanged(self C.id, sel C.SEL, e C.id) {
func newAreaScrollView(area C.id) C.id { func newAreaScrollView(area C.id) C.id {
scrollview := objc_alloc(_NSScrollView) scrollview := objc_alloc(_NSScrollView)
scrollview = objc_msgSend_rect(scrollview, _initWithFrame, scrollview = initWithDummyFrame(scrollview)
0, 0, 100, 100)
C.objc_msgSend_bool(scrollview, _setHasHorizontalScroller, C.BOOL(C.YES)) C.objc_msgSend_bool(scrollview, _setHasHorizontalScroller, C.BOOL(C.YES))
C.objc_msgSend_bool(scrollview, _setHasVerticalScroller, C.BOOL(C.YES)) C.objc_msgSend_bool(scrollview, _setHasVerticalScroller, C.BOOL(C.YES))
C.objc_msgSend_bool(scrollview, _setAutohidesScrollers, C.BOOL(C.YES)) C.objc_msgSend_bool(scrollview, _setAutohidesScrollers, C.BOOL(C.YES))
@ -293,8 +292,7 @@ func areaInScrollView(scrollview C.id) C.id {
func makeArea(parentWindow C.id, alternate bool) C.id { func makeArea(parentWindow C.id, alternate bool) C.id {
area := objc_alloc(_goArea) area := objc_alloc(_goArea)
area = objc_msgSend_rect(area, _initWithFrame, area = initWithDummyFrame(area)
0, 0, 100, 100)
// TODO others? // TODO others?
area = newAreaScrollView(area) area = newAreaScrollView(area)
addControl(parentWindow, area) addControl(parentWindow, area)

View File

@ -103,7 +103,7 @@ struct xrect objc_msgSend_stret_rect_noargs(id obj, SEL sel)
#define OurRect() (NSMakeRect((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h)) #define OurRect() (NSMakeRect((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h))
id _objc_msgSend_rect(id obj, SEL sel, int64_t x, int64_t y, int64_t w, int64_t h) id objc_msgSend_rect(id obj, SEL sel, int64_t x, int64_t y, int64_t w, int64_t h)
{ {
return objc_msgSend(obj, sel, OurRect()); return objc_msgSend(obj, sel, OurRect());
} }

View File

@ -193,8 +193,7 @@ var (
func newListboxScrollView(listbox C.id) C.id { func newListboxScrollView(listbox C.id) C.id {
scrollview := objc_alloc(_NSScrollView) scrollview := objc_alloc(_NSScrollView)
scrollview = objc_msgSend_rect(scrollview, _initWithFrame, scrollview = initWithDummyFrame(scrollview)
0, 0, 100, 100)
C.objc_msgSend_bool(scrollview, _setHasHorizontalScroller, C.BOOL(C.YES)) C.objc_msgSend_bool(scrollview, _setHasHorizontalScroller, C.BOOL(C.YES))
C.objc_msgSend_bool(scrollview, _setHasVerticalScroller, C.BOOL(C.YES)) C.objc_msgSend_bool(scrollview, _setHasVerticalScroller, C.BOOL(C.YES))
C.objc_msgSend_bool(scrollview, _setAutohidesScrollers, C.BOOL(C.YES)) C.objc_msgSend_bool(scrollview, _setAutohidesScrollers, C.BOOL(C.YES))
@ -234,8 +233,7 @@ var (
func makeListbox(parentWindow C.id, alternate bool) C.id { func makeListbox(parentWindow C.id, alternate bool) C.id {
listbox := objc_alloc(_NSTableView) listbox := objc_alloc(_NSTableView)
listbox = objc_msgSend_rect(listbox, _initWithFrame, listbox = initWithDummyFrame(listbox)
0, 0, 100, 100)
C.objc_msgSend_id(listbox, _addTableColumn, newListboxTableColumn()) C.objc_msgSend_id(listbox, _addTableColumn, newListboxTableColumn())
multi := C.BOOL(C.NO) multi := C.BOOL(C.NO)
if alternate { if alternate {

View File

@ -56,12 +56,3 @@ func fromNSString(str C.id) string {
cstr := C.objc_msgSend_noargs(str, _UTF8String) cstr := C.objc_msgSend_noargs(str, _UTF8String)
return C.GoString((*C.char)(unsafe.Pointer(cstr))) return C.GoString((*C.char)(unsafe.Pointer(cstr)))
} }
/*
These are wrapper functions for the functions in bleh_darwin.m to wrap around stdint.h type casting.
*/
func objc_msgSend_rect(obj C.id, sel C.SEL, x int, y int, w int, h int) C.id {
return C._objc_msgSend_rect(obj, sel,
C.int64_t(x), C.int64_t(y), C.int64_t(w), C.int64_t(h))
}

View File

@ -84,7 +84,7 @@ extern uintptr_t objc_msgSend_ushortret_noargs(id objc, SEL sel);
m1(str, char *) /* TODO Go string? */ m1(str, char *) /* TODO Go string? */
m1(id, id) m1(id, id)
extern id _objc_msgSend_rect(id obj, SEL sel, int64_t x, int64_t y, int64_t w, int64_t h); extern id objc_msgSend_rect(id obj, SEL sel, int64_t x, int64_t y, int64_t w, int64_t h);
m1(sel, SEL) m1(sel, SEL)
extern id objc_msgSend_uint(id obj, SEL sel, uintptr_t a); extern id objc_msgSend_uint(id obj, SEL sel, uintptr_t a);
m1(ptr, void *) m1(ptr, void *)

View File

@ -84,6 +84,12 @@ var (
_numberOfItems = sel_getUid("numberOfItems") _numberOfItems = sel_getUid("numberOfItems")
) )
// because the only way to make a new NSControl/NSView is with a frame (it gets overridden later)
func initWithDummyFrame(self C.id) C.id {
return C.objc_msgSend_rect(self, _initWithFrame,
C.int64_t(0), C.int64_t(0), C.int64_t(100), C.int64_t(100))
}
func addControl(parentWindow C.id, control C.id) { func addControl(parentWindow C.id, control C.id) {
windowView := C.objc_msgSend_noargs(parentWindow, _contentView) windowView := C.objc_msgSend_noargs(parentWindow, _contentView)
C.objc_msgSend_id(windowView, _addSubview, control) C.objc_msgSend_id(windowView, _addSubview, control)
@ -134,9 +140,7 @@ var classTypes = [nctypes]*classData{
c_button: &classData{ c_button: &classData{
make: func(parentWindow C.id, alternate bool) C.id { make: func(parentWindow C.id, alternate bool) C.id {
button := objc_alloc(_NSButton) button := objc_alloc(_NSButton)
// NSControl requires that we specify a frame; dummy frame for now button = initWithDummyFrame(button)
button = objc_msgSend_rect(button, _initWithFrame,
0, 0, 100, 100)
C.objc_msgSend_uint(button, _setBezelStyle, C.uintptr_t(1)) // NSRoundedBezelStyle C.objc_msgSend_uint(button, _setBezelStyle, C.uintptr_t(1)) // NSRoundedBezelStyle
C.objc_msgSend_id(button, _setTarget, appDelegate) C.objc_msgSend_id(button, _setTarget, appDelegate)
C.objc_msgSend_sel(button, _setAction, _buttonClicked) C.objc_msgSend_sel(button, _setAction, _buttonClicked)
@ -154,8 +158,7 @@ var classTypes = [nctypes]*classData{
c_checkbox: &classData{ c_checkbox: &classData{
make: func(parentWindow C.id, alternate bool) C.id { make: func(parentWindow C.id, alternate bool) C.id {
checkbox := objc_alloc(_NSButton) checkbox := objc_alloc(_NSButton)
checkbox = objc_msgSend_rect(checkbox, _initWithFrame, checkbox = initWithDummyFrame(checkbox)
0, 0, 100, 100)
C.objc_msgSend_uint(checkbox, _setButtonType, C.uintptr_t(3)) // NSSwitchButton C.objc_msgSend_uint(checkbox, _setButtonType, C.uintptr_t(3)) // NSSwitchButton
addControl(parentWindow, checkbox) addControl(parentWindow, checkbox)
return checkbox return checkbox
@ -171,8 +174,7 @@ var classTypes = [nctypes]*classData{
if alternate { if alternate {
combobox = objc_alloc(_NSComboBox) combobox = objc_alloc(_NSComboBox)
combobox = objc_msgSend_rect(combobox, _initWithFrame, combobox = initWithDummyFrame(combobox)
0, 0, 100, 100)
C.objc_msgSend_bool(combobox, _setUsesDataSource, C.BOOL(C.NO)) C.objc_msgSend_bool(combobox, _setUsesDataSource, C.BOOL(C.NO))
} else { } else {
combobox = objc_alloc(_NSPopUpButton) combobox = objc_alloc(_NSPopUpButton)
@ -222,8 +224,7 @@ var classTypes = [nctypes]*classData{
} else { } else {
lineedit = objc_alloc(_NSTextField) lineedit = objc_alloc(_NSTextField)
} }
lineedit = objc_msgSend_rect(lineedit, _initWithFrame, lineedit = initWithDummyFrame(lineedit)
0, 0, 100, 100)
addControl(parentWindow, lineedit) addControl(parentWindow, lineedit)
return lineedit return lineedit
}, },
@ -236,8 +237,7 @@ var classTypes = [nctypes]*classData{
c_label: &classData{ c_label: &classData{
make: func(parentWindow C.id, alternate bool) C.id { make: func(parentWindow C.id, alternate bool) C.id {
label := objc_alloc(_NSTextField) label := objc_alloc(_NSTextField)
label = objc_msgSend_rect(label, _initWithFrame, label = initWithDummyFrame(label)
0, 0, 100, 100)
C.objc_msgSend_bool(label, _setEditable, C.BOOL(C.NO)) C.objc_msgSend_bool(label, _setEditable, C.BOOL(C.NO))
C.objc_msgSend_bool(label, _setBordered, C.BOOL(C.NO)) C.objc_msgSend_bool(label, _setBordered, C.BOOL(C.NO))
C.objc_msgSend_bool(label, _setDrawsBackground, C.BOOL(C.NO)) C.objc_msgSend_bool(label, _setDrawsBackground, C.BOOL(C.NO))
@ -264,8 +264,7 @@ var classTypes = [nctypes]*classData{
c_progressbar: &classData{ c_progressbar: &classData{
make: func(parentWindow C.id, alternate bool) C.id { make: func(parentWindow C.id, alternate bool) C.id {
pbar := objc_alloc(_NSProgressIndicator) pbar := objc_alloc(_NSProgressIndicator)
pbar = objc_msgSend_rect(pbar, _initWithFrame, pbar = initWithDummyFrame(pbar)
0, 0, 100, 100)
// TODO really int? // TODO really int?
C.objc_msgSend_int(pbar, _setStyle, 0) // NSProgressIndicatorBarStyle C.objc_msgSend_int(pbar, _setStyle, 0) // NSProgressIndicatorBarStyle
C.objc_msgSend_uint(pbar, _setControlSize, C.uintptr_t(0)) // NSRegularControlSize C.objc_msgSend_uint(pbar, _setControlSize, C.uintptr_t(0)) // NSRegularControlSize
@ -370,7 +369,8 @@ func (s *sysData) setText(text string) {
func (s *sysData) setRect(x int, y int, width int, height int, winheight int) error { func (s *sysData) setRect(x int, y int, width int, height int, winheight int) error {
// winheight - y because (0,0) is the bottom-left corner of the window and not the top-left corner // winheight - y because (0,0) is the bottom-left corner of the window and not the top-left corner
// (winheight - y) - height because (x, y) is the bottom-left corner of the control and not the top-left // (winheight - y) - height because (x, y) is the bottom-left corner of the control and not the top-left
objc_msgSend_rect(s.id, _setFrame, x, (winheight - y) - height, width, height) C.objc_msgSend_rect(s.id, _setFrame,
C.int64_t(x), C.int64_t((winheight - y) - height), C.int64_t(width), C.int64_t(height))
return nil return nil
} }
@ -506,8 +506,8 @@ func (s *sysData) setAreaSize(width int, height int) {
defer close(ret) defer close(ret)
uitask <- func() { uitask <- func() {
area := areaInScrollView(s.id) area := areaInScrollView(s.id)
objc_msgSend_rect(area, _setFrame, C.objc_msgSend_rect(area, _setFrame,
int(0), int(0), width, height) C.int64_t(0), C.int64_t(0), C.int64_t(width), C.int64_t(height))
C.objc_msgSend_noargs(area, _display) // and redraw C.objc_msgSend_noargs(area, _display) // and redraw
ret <- struct{}{} ret <- struct{}{}
} }