andlabs-ui/prev/window_darwin.go

85 lines
1.6 KiB
Go
Raw Normal View History

// 8 july 2014
package ui
import (
"unsafe"
)
// #include "objc_darwin.h"
import "C"
type window struct {
id C.id
closing *event
2014-10-18 16:03:07 -05:00
child Control
container *container
}
func newWindow(title string, width int, height int, control Control) *window {
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{
id: id,
closing: newEvent(),
2014-10-18 16:03:07 -05:00
child: control,
}
C.windowSetDelegate(w.id, unsafe.Pointer(w))
2014-10-27 23:13:18 -05:00
w.container = newContainer(w.child.resize)
2014-10-18 16:03:07 -05:00
w.child.setParent(w.container.parent())
2014-10-27 23:13:18 -05:00
C.windowSetContentView(w.id, w.container.id)
2014-10-18 16:03:07 -05:00
// trigger an initial resize
return w
}
func (w *window) Title() string {
return C.GoString(C.windowTitle(w.id))
}
func (w *window) SetTitle(title string) {
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))
C.windowSetTitle(w.id, ctitle)
}
func (w *window) Show() {
C.windowShow(w.id)
2014-10-27 23:13:18 -05:00
// TODO we need a dummy resize here because things might not be in the right place
}
func (w *window) Hide() {
C.windowHide(w.id)
}
func (w *window) Close() {
C.windowClose(w.id)
}
func (w *window) OnClosing(e func() bool) {
w.closing.setbool(e)
}
2014-10-18 16:03:07 -05:00
func (w *window) Margined() bool {
return w.container.margined
2014-10-18 16:03:07 -05:00
}
func (w *window) SetMargined(margined bool) {
w.container.margined = margined
2014-10-18 16:03:07 -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-10-18 16:03:07 -05:00
// no need for windowResized; the child container takes care of that