summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-03-01 18:01:30 -0500
committerPietro Gagliardi <[email protected]>2014-03-01 18:01:30 -0500
commitd9cf76c1ab46dad314a3cfafad31f7f57845b8b6 (patch)
tree0e892e47fb823405c1706fdd005993de78369f20
parent5caf0fe84a81e5adbe18568eabe06f2ec674c1b3 (diff)
Added windowDidResize: to the Mac OS X delegate for resizing windows. Now to figure out why I can't resize windows myself...
-rw-r--r--delegate_darwin.go24
-rw-r--r--prefsize_darwin.go1
2 files changed, 25 insertions, 0 deletions
diff --git a/delegate_darwin.go b/delegate_darwin.go
index f6870e6..8d27281 100644
--- a/delegate_darwin.go
+++ b/delegate_darwin.go
@@ -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 (
diff --git a/prefsize_darwin.go b/prefsize_darwin.go
index 316662e..630969e 100644
--- a/prefsize_darwin.go
+++ b/prefsize_darwin.go
@@ -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)