Added windowDidResize: to the Mac OS X delegate for resizing windows. Now to figure out why I can't resize windows myself...
This commit is contained in:
parent
5caf0fe84a
commit
d9cf76c1ab
|
@ -19,6 +19,7 @@ This creates a class goAppDelegate that will be used as the delegate for /everyt
|
|||
// #include "objc_darwin.h"
|
||||
// extern void appDelegate_uitask(id, SEL, id); /* from uitask_darwin.go */
|
||||
// extern BOOL appDelegate_windowShouldClose(id, SEL, id);
|
||||
// extern void appDelegate_windowDidResize(id, SEL, id);
|
||||
import "C"
|
||||
|
||||
var (
|
||||
|
@ -32,6 +33,7 @@ const (
|
|||
var (
|
||||
_uitask = sel_getUid("uitask:")
|
||||
_windowShouldClose = sel_getUid("windowShouldClose:")
|
||||
_windowDidResize = sel_getUid("windowDidResize:")
|
||||
)
|
||||
|
||||
func mkAppDelegate() error {
|
||||
|
@ -49,6 +51,11 @@ func mkAppDelegate() error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("error adding NSApplication delegate windowShouldClose: method (to handle window close button events): %v", err)
|
||||
}
|
||||
err = addDelegateMethod(appdelegateclass, _windowDidResize,
|
||||
C.appDelegate_windowDidResize, delegate_void)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error adding NSApplication delegate windowDidResize: method (to handle window resize events): %v", err)
|
||||
}
|
||||
// TODO using objc_new() causes a segfault; find out why
|
||||
// TODO make alloc followed by init (I thought NSObject provided its own init?)
|
||||
appDelegate = objc_alloc(objc_getClass(_goAppDelegate))
|
||||
|
@ -62,6 +69,23 @@ func appDelegate_windowShouldClose(self C.id, sel C.SEL, win C.id) C.BOOL {
|
|||
return C.BOOL(C.NO) // don't close
|
||||
}
|
||||
|
||||
var (
|
||||
_object = sel_getUid("object")
|
||||
)
|
||||
|
||||
//export appDelegate_windowDidResize
|
||||
func appDelegate_windowDidResize(self C.id, sel C.SEL, notification C.id) {
|
||||
win := C.objc_msgSend_noargs(notification, _object)
|
||||
sysData := getSysData(win)
|
||||
r := C.objc_msgSend_stret_rect_noargs(win, _frame)
|
||||
if sysData.resize != nil {
|
||||
err := sysData.resize(int(r.x), int(r.y), int(r.width), int(r.height))
|
||||
if err != nil {
|
||||
panic("child resize failed: " + err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this actually constructs the delegate class
|
||||
|
||||
var (
|
||||
|
|
|
@ -15,6 +15,7 @@ var (
|
|||
)
|
||||
|
||||
func (s *sysData) preferredSize() (width int, height int) {
|
||||
if classTypes[s.ctype].make == nil { return 0, 0 } // prevent lockup during window resize
|
||||
cell := C.objc_msgSend_noargs(s.id, _cell)
|
||||
cs := C.objc_msgSend_stret_size_noargs(cell, _cellSize)
|
||||
return int(cs.width), int(cs.height)
|
||||
|
|
Loading…
Reference in New Issue