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

View File

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

View File

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