Further refactoring and de-runtime-izing of sysdata_darwin.go. These changes currently untested.

This commit is contained in:
Pietro Gagliardi 2014-05-12 23:55:56 -04:00
parent fd60061ded
commit 3949fb94e9
3 changed files with 27 additions and 43 deletions

View File

@ -24,8 +24,11 @@ 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
append func(id C.id, what string, alternate bool)
insertBefore func(id C.id, what string, before int, alternate bool)
@ -110,9 +113,13 @@ func controlHide(what C.id) {
C.controlHide(what)
}
const (
_NSRegularControlSize = 0
)
// TODO move to objc_darwin.go unless the only thing that uses it is alternate
func toBOOL(what bool) C.BOOL {
if what {
return C.YES
}
return C.NO
}
// By default some controls do not use the correct font.
// These functions set the appropriate control font.
@ -127,10 +134,7 @@ func applyStandardControlFont(id C.id) {
var classTypes = [nctypes]*classData{
c_window: &classData{
make: func(parentWindow C.id, alternate bool, s *sysData) C.id {
win := C.makeWindow()
C.objc_msgSend_id(win, _setDelegate, appDelegate)
// we do not need setAcceptsMouseMovedEvents: here since we are using a tracking rect in Areas for that
return win
return C.makeWindow(appDelegate)
},
show: func(what C.id) {
C.windowShow(what)
@ -168,13 +172,7 @@ var classTypes = [nctypes]*classData{
},
c_combobox: &classData{
make: func(parentWindow C.id, alternate bool, s *sysData) C.id {
var combobox C.id
if alternate {
combobox = C.makeCombobox(C.YES)
} else {
combobox = C.makeCombobox(C.NO)
}
combobox := C.makeCombobox(toBOOL(alternate))
applyStandardControlFont(combobox)
addControl(parentWindow, combobox)
return combobox
@ -184,20 +182,11 @@ var classTypes = [nctypes]*classData{
textsel: _titleOfSelectedItem,
alttextsel: _stringValue,
append: func(id C.id, what string, alternate bool) {
str := toNSString(what)
if alternate {
C.comboboxAppend(id, C.YES, str)
} else {
C.comboboxAppend(id, C.NO, str)
}
C.comboboxAppend(id, toBOOL(alternate), toNSString(what))
},
insertBefore: func(id C.id, what string, before int, alternate bool) {
str := toNSString(what)
if alternate {
C.comboboxInsertBefore(id, C.YES, str, C.intptr_t(before))
} else {
C.comboboxInsertBefore(id, C.NO, str, C.intptr_t(before))
}
C.comboboxInsertBefore(id, toBOOL(alternate),
toNSString(what), C.intptr_t(before))
},
selIndex: func(id C.id) int {
return int(C.comboboxSelectedIndex(id))
@ -209,23 +198,12 @@ var classTypes = [nctypes]*classData{
return int(C.comboboxLen(id))
},
selectIndex: func(id C.id, index int, alternate bool) {
// NSPopUpButton makes this easy
if alternate {
C.comboboxSelectIndex(id, C.YES, C.intptr_t(index))
} else {
C.comboboxSelectIndex(id, C.NO, C.intptr_t(index))
}
C.comboboxSelectIndex(id, toBOOL(alternate), C.intptr_t(index))
},
},
c_lineedit: &classData{
make: func(parentWindow C.id, alternate bool, s *sysData) C.id {
var lineedit C.id
if alternate {
lineedit = C.makeLineEdit(C.YES)
} else {
lineedit = C.makeLineEdit(C.NO)
}
lineedit := C.makeLineEdit(toBOOL(alternate))
applyStandardControlFont(lineedit)
addControl(parentWindow, lineedit)
return lineedit

View File

@ -6,7 +6,7 @@ extern void addControl(id, id);
extern void controlShow(id);
extern void controlHide(id);
extern void applyStandardControlFont(id);
extern id makeWindow(void);
extern id makeWindow(id);
extern void windowShow(id);
extern void windowHide(id);
extern id makeButton(void);

View File

@ -5,7 +5,7 @@
#include <Foundation/NSGeometry.h>
#include <AppKit/NSWindow.h>
#include <AppKit/NSView.h>
#include <AppKit/NSCell.h>
#include <AppKit/NSControl.h>
#include <AppKit/NSButton.h>
#include <AppKit/NSPopUpButton.h>
#include <AppKit/NSComboBox.h>
@ -19,6 +19,7 @@ static NSRect dummyRect;// = NSMakeRect(0, 0, 100, 100);
#define to(T, x) ((T *) (x))
#define toNSWindow(x) to(NSWindow, (x))
#define toNSView(x) to(NSView, (x))
#define toNSControl(x) to(NSControl, (x))
#define toNSButton(x) to(NSButton, (x))
#define toNSPopUpButton(x) to(NSPopUpButton, (x))
#define toNSComboBox(x) to(NSComboBox, (x))
@ -53,15 +54,20 @@ void applyStandardControlFont(id what)
objc_setFont(what, NSRegularControlSize);
}
id makeWindow(void)
id makeWindow(id delegate)
{
NSWindow *w;
// TODO separate to initilaizer
dummyRect = NSMakeRect(0, 0, 100, 100);
return [[NSWindow alloc]
w = [[NSWindow alloc]
initWithContentRect:dummyRect
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
backing:NSBackingStoreBuffered
defer:YES]; // defer creation of device until we show the window
[w setDelegate:delegate];
// we do not need setAcceptsMouseMovedEvents: here since we are using a tracking rect in Areas for that
return w;
}
void windowShow(id window)