Added Mac OS X Buttons. Code hangs due to a preferredSize() issue...
This commit is contained in:
parent
859c240a21
commit
bbb37bb2a6
|
@ -11,7 +11,7 @@ This creates a class goAppDelegate that will be used as the delegate for /everyt
|
||||||
- runs uitask requests (uitask:)
|
- runs uitask requests (uitask:)
|
||||||
- handles window close events (windowShouldClose:)
|
- handles window close events (windowShouldClose:)
|
||||||
- handles window resize events (windowDidResize: (TODO also windowDidEndLiveResize:?))
|
- handles window resize events (windowDidResize: (TODO also windowDidEndLiveResize:?))
|
||||||
- handles button click events (buttonClick:)
|
- handles button click events (buttonClicked:)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
|
// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
|
||||||
|
@ -20,6 +20,7 @@ This creates a class goAppDelegate that will be used as the delegate for /everyt
|
||||||
// extern void appDelegate_uitask(id, SEL, id); /* from uitask_darwin.go */
|
// extern void appDelegate_uitask(id, SEL, id); /* from uitask_darwin.go */
|
||||||
// extern BOOL appDelegate_windowShouldClose(id, SEL, id);
|
// extern BOOL appDelegate_windowShouldClose(id, SEL, id);
|
||||||
// extern void appDelegate_windowDidResize(id, SEL, id);
|
// extern void appDelegate_windowDidResize(id, SEL, id);
|
||||||
|
// extern void appDelegate_buttonClicked(id, SEL, id);
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -34,6 +35,7 @@ var (
|
||||||
_uitask = sel_getUid("uitask:")
|
_uitask = sel_getUid("uitask:")
|
||||||
_windowShouldClose = sel_getUid("windowShouldClose:")
|
_windowShouldClose = sel_getUid("windowShouldClose:")
|
||||||
_windowDidResize = sel_getUid("windowDidResize:")
|
_windowDidResize = sel_getUid("windowDidResize:")
|
||||||
|
_buttonClicked = sel_getUid("buttonClicked:")
|
||||||
)
|
)
|
||||||
|
|
||||||
func mkAppDelegate() error {
|
func mkAppDelegate() error {
|
||||||
|
@ -56,6 +58,11 @@ func mkAppDelegate() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error adding NSApplication delegate windowDidResize: method (to handle window resize events): %v", err)
|
return fmt.Errorf("error adding NSApplication delegate windowDidResize: method (to handle window resize events): %v", err)
|
||||||
}
|
}
|
||||||
|
err = addDelegateMethod(appdelegateclass, _buttonClicked,
|
||||||
|
C.appDelegate_buttonClicked, delegate_void)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error adding NSApplication delegate buttonClicked: method (to handle button clicks): %v", err)
|
||||||
|
}
|
||||||
// TODO using objc_new() causes a segfault; find out why
|
// TODO using objc_new() causes a segfault; find out why
|
||||||
// TODO make alloc followed by init (I thought NSObject provided its own init?)
|
// TODO make alloc followed by init (I thought NSObject provided its own init?)
|
||||||
appDelegate = objc_alloc(objc_getClass(_goAppDelegate))
|
appDelegate = objc_alloc(objc_getClass(_goAppDelegate))
|
||||||
|
@ -86,6 +93,12 @@ func appDelegate_windowDidResize(self C.id, sel C.SEL, notification C.id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export appDelegate_buttonClicked
|
||||||
|
func appDelegate_buttonClicked(self C.id, sel C.SEL, button C.id) {
|
||||||
|
sysData := getSysData(button)
|
||||||
|
sysData.signal()
|
||||||
|
}
|
||||||
|
|
||||||
// this actually constructs the delegate class
|
// this actually constructs the delegate class
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -27,8 +27,10 @@ type classData struct {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_NSWindow = objc_getClass("NSWindow")
|
_NSWindow = objc_getClass("NSWindow")
|
||||||
|
_NSButton = objc_getClass("NSButton")
|
||||||
|
|
||||||
_initWithContentRect = sel_getUid("initWithContentRect:styleMask:backing:defer:")
|
_initWithContentRect = sel_getUid("initWithContentRect:styleMask:backing:defer:")
|
||||||
|
_initWithFrame = sel_getUid("initWithFrame:")
|
||||||
_makeKeyAndOrderFront = sel_getUid("makeKeyAndOrderFront:")
|
_makeKeyAndOrderFront = sel_getUid("makeKeyAndOrderFront:")
|
||||||
_orderOut = sel_getUid("orderOut:")
|
_orderOut = sel_getUid("orderOut:")
|
||||||
_setHidden = sel_getUid("setHidden:")
|
_setHidden = sel_getUid("setHidden:")
|
||||||
|
@ -41,6 +43,11 @@ var (
|
||||||
// TODO others
|
// TODO others
|
||||||
_frame = sel_getUid("frame")
|
_frame = sel_getUid("frame")
|
||||||
_setFrameDisplay = sel_getUid("setFrame:display:")
|
_setFrameDisplay = sel_getUid("setFrame:display:")
|
||||||
|
_setBezelStyle = sel_getUid("setBezelStyle:")
|
||||||
|
_setTarget = sel_getUid("setTarget:")
|
||||||
|
_setAction = sel_getUid("setAction:")
|
||||||
|
_contentView = sel_getUid("contentView")
|
||||||
|
_addSubview = sel_getUid("addSubview:")
|
||||||
)
|
)
|
||||||
|
|
||||||
func controlShow(what C.id) {
|
func controlShow(what C.id) {
|
||||||
|
@ -84,6 +91,22 @@ var classTypes = [nctypes]*classData{
|
||||||
textsel: _title,
|
textsel: _title,
|
||||||
},
|
},
|
||||||
c_button: &classData{
|
c_button: &classData{
|
||||||
|
make: func(parentWindow C.id) C.id {
|
||||||
|
button := objc_alloc(_NSButton)
|
||||||
|
// NSControl requires that we specify a frame; dummy frame for now
|
||||||
|
button = objc_msgSend_rect(button, _initWithFrame,
|
||||||
|
0, 0, 100, 100)
|
||||||
|
objc_msgSend_uint(button, _setBezelStyle, 1) // NSRoundedBezelStyle
|
||||||
|
C.objc_msgSend_id(button, _setTarget, appDelegate)
|
||||||
|
C.objc_msgSend_sel(button, _setAction, _buttonClicked)
|
||||||
|
windowView := C.objc_msgSend_noargs(parentWindow, _contentView)
|
||||||
|
C.objc_msgSend_id(windowView, _addSubview, button)
|
||||||
|
return button
|
||||||
|
},
|
||||||
|
show: controlShow,
|
||||||
|
hide: controlHide,
|
||||||
|
settextsel: _setTitle,
|
||||||
|
textsel: _title,
|
||||||
},
|
},
|
||||||
c_checkbox: &classData{
|
c_checkbox: &classData{
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue