2014-07-08 15:47:28 -05:00
|
|
|
// 8 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
2014-07-15 13:04:20 -05:00
|
|
|
"fmt"
|
2014-07-08 15:47:28 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// #include "objc_darwin.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type window struct {
|
|
|
|
id C.id
|
|
|
|
|
|
|
|
closing *event
|
2014-07-17 10:24:58 -05:00
|
|
|
|
2014-07-25 19:10:09 -05:00
|
|
|
*container
|
|
|
|
}
|
|
|
|
|
|
|
|
type controlParent interface {
|
|
|
|
setParent(C.id)
|
2014-07-08 15:47:28 -05:00
|
|
|
}
|
|
|
|
|
2014-07-25 19:10:09 -05:00
|
|
|
func newWindow(title string, width int, height int, control Control) *window {
|
2014-07-19 08:44:32 -05:00
|
|
|
id := C.newWindow(C.intptr_t(width), C.intptr_t(height))
|
|
|
|
ctitle := C.CString(title)
|
|
|
|
defer C.free(unsafe.Pointer(ctitle))
|
|
|
|
C.windowSetTitle(id, ctitle)
|
|
|
|
w := &window{
|
2014-07-25 19:10:09 -05:00
|
|
|
id: id,
|
|
|
|
closing: newEvent(),
|
|
|
|
container: new(container),
|
2014-07-08 15:47:28 -05:00
|
|
|
}
|
2014-07-25 19:10:09 -05:00
|
|
|
w.container.beginResize = w.beginResize
|
2014-07-19 08:44:32 -05:00
|
|
|
C.windowSetDelegate(id, unsafe.Pointer(w))
|
2014-07-25 19:10:09 -05:00
|
|
|
w.child = control
|
2014-07-25 22:11:41 -05:00
|
|
|
w.child.setParent(C.windowContentView(w.id))
|
2014-07-19 08:44:32 -05:00
|
|
|
return w
|
2014-07-08 15:47:28 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *window) Title() string {
|
|
|
|
return C.GoString(C.windowTitle(w.id))
|
2014-07-08 15:47:28 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *window) SetTitle(title string) {
|
|
|
|
ctitle := C.CString(title)
|
|
|
|
defer C.free(unsafe.Pointer(ctitle))
|
|
|
|
C.windowSetTitle(w.id, ctitle)
|
2014-07-08 15:47:28 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *window) Show() {
|
|
|
|
C.windowShow(w.id)
|
2014-07-08 15:47:28 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *window) Hide() {
|
|
|
|
C.windowHide(w.id)
|
2014-07-08 15:47:28 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *window) Close() {
|
|
|
|
C.windowClose(w.id)
|
2014-07-08 15:47:28 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *window) OnClosing(e func() bool) {
|
|
|
|
w.closing.setbool(e)
|
2014-07-08 15:47:28 -05:00
|
|
|
}
|
|
|
|
|
2014-07-08 16:43:50 -05:00
|
|
|
//export windowClosing
|
|
|
|
func windowClosing(xw unsafe.Pointer) C.BOOL {
|
|
|
|
w := (*window)(unsafe.Pointer(xw))
|
|
|
|
close := w.closing.fire()
|
|
|
|
if close {
|
|
|
|
return C.YES
|
|
|
|
}
|
|
|
|
return C.NO
|
|
|
|
}
|
2014-07-15 13:04:20 -05:00
|
|
|
|
|
|
|
//export windowResized
|
|
|
|
func windowResized(xw unsafe.Pointer, width C.uintptr_t, height C.uintptr_t) {
|
|
|
|
w := (*window)(unsafe.Pointer(xw))
|
2014-07-25 19:10:09 -05:00
|
|
|
w.resize(int(width), int(height))
|
2014-07-15 13:04:20 -05:00
|
|
|
fmt.Printf("new size %d x %d\n", width, height)
|
|
|
|
}
|