2014-03-01 15:56:22 -06:00
|
|
|
// 27 february 2014
|
2014-03-12 20:55:45 -05:00
|
|
|
|
2014-03-01 15:56:22 -06:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
2014-04-04 20:32:10 -05:00
|
|
|
// ...
|
2014-03-01 15:56:22 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
This creates a class goAppDelegate that will be used as the delegate for /everything/. Specifically, it:
|
|
|
|
- runs uitask requests (uitask:)
|
|
|
|
- handles window close events (windowShouldClose:)
|
2014-03-11 10:54:32 -05:00
|
|
|
- handles window resize events (windowDidResize:)
|
2014-03-01 20:34:37 -06:00
|
|
|
- handles button click events (buttonClicked:)
|
2014-04-06 22:33:27 -05:00
|
|
|
- handles the application-global Quit event (such as from the Dock) (applicationShouldTerminate)
|
2014-03-01 15:56:22 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
|
|
|
|
// #include <stdlib.h>
|
|
|
|
// #include "objc_darwin.h"
|
2014-05-13 07:14:28 -05:00
|
|
|
// #include "delegateuitask_darwin.h"
|
2014-03-01 15:56:22 -06:00
|
|
|
import "C"
|
|
|
|
|
|
|
|
var (
|
|
|
|
appDelegate C.id
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
_goAppDelegate = "goAppDelegate"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2014-04-04 20:06:01 -05:00
|
|
|
_uitask = sel_getUid("uitask:") // used by uitask_darwin.go
|
|
|
|
_buttonClicked = sel_getUid("buttonClicked:") // used by sysdata_darwin.go
|
2014-03-01 15:56:22 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func mkAppDelegate() error {
|
2014-05-13 06:56:37 -05:00
|
|
|
appDelegate = C.makeAppDelegate()
|
2014-03-01 15:56:22 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//export appDelegate_windowShouldClose
|
2014-05-13 06:56:37 -05:00
|
|
|
func appDelegate_windowShouldClose(win C.id) {
|
2014-03-01 15:56:22 -06:00
|
|
|
sysData := getSysData(win)
|
|
|
|
sysData.signal()
|
|
|
|
}
|
|
|
|
|
2014-03-01 17:01:30 -06:00
|
|
|
var (
|
|
|
|
_object = sel_getUid("object")
|
2014-03-02 18:13:26 -06:00
|
|
|
_display = sel_getUid("display")
|
2014-03-01 17:01:30 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
//export appDelegate_windowDidResize
|
2014-05-13 06:56:37 -05:00
|
|
|
func appDelegate_windowDidResize(win C.id) {
|
2014-03-29 22:57:49 -05:00
|
|
|
s := getSysData(win)
|
2014-05-13 06:56:37 -05:00
|
|
|
wincv := C.windowGetContentView(win) // we want the content view's size, not the window's
|
2014-03-02 18:16:36 -06:00
|
|
|
r := C.objc_msgSend_stret_rect_noargs(wincv, _frame)
|
2014-04-07 13:32:25 -05:00
|
|
|
// winheight is used here because (0,0) is the bottom-left corner, not the top-left corner
|
|
|
|
s.doResize(0, 0, int(r.width), int(r.height), int(r.height))
|
2014-03-02 18:13:26 -06:00
|
|
|
C.objc_msgSend_noargs(win, _display) // redraw everything; TODO only if resize() was called?
|
2014-03-01 17:01:30 -06:00
|
|
|
}
|
|
|
|
|
2014-03-01 20:34:37 -06:00
|
|
|
//export appDelegate_buttonClicked
|
2014-05-13 06:56:37 -05:00
|
|
|
func appDelegate_buttonClicked(button C.id) {
|
2014-03-01 20:34:37 -06:00
|
|
|
sysData := getSysData(button)
|
|
|
|
sysData.signal()
|
|
|
|
}
|
2014-04-06 22:33:27 -05:00
|
|
|
|
|
|
|
//export appDelegate_applicationShouldTerminate
|
|
|
|
func appDelegate_applicationShouldTerminate() {
|
|
|
|
// asynchronous so as to return control to the event loop
|
|
|
|
go func() {
|
|
|
|
AppQuit <- struct{}{}
|
|
|
|
}()
|
|
|
|
}
|