2014-07-12 10:29:54 -05:00
|
|
|
// 12 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"syscall"
|
2014-08-04 19:04:16 -05:00
|
|
|
"unsafe"
|
2014-07-12 10:29:54 -05:00
|
|
|
)
|
|
|
|
|
2014-07-17 22:11:16 -05:00
|
|
|
// #include "winapi_windows.h"
|
|
|
|
import "C"
|
|
|
|
|
2014-07-12 10:29:54 -05:00
|
|
|
type window struct {
|
2014-10-02 09:05:53 -05:00
|
|
|
hwnd C.HWND
|
|
|
|
shownbefore bool
|
2014-08-04 18:46:49 -05:00
|
|
|
|
2014-10-02 09:05:53 -05:00
|
|
|
closing *event
|
2014-08-04 18:46:49 -05:00
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
child Control
|
|
|
|
margined bool
|
2014-07-12 10:29:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func makeWindowWindowClass() error {
|
2014-07-17 22:11:16 -05:00
|
|
|
var errmsg *C.char
|
|
|
|
|
|
|
|
err := C.makeWindowWindowClass(&errmsg)
|
|
|
|
if err != 0 || errmsg != nil {
|
|
|
|
return fmt.Errorf("%s: %v", C.GoString(errmsg), syscall.Errno(err))
|
2014-07-12 10:29:54 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-07-25 16:34:45 -05:00
|
|
|
func newWindow(title string, width int, height int, control Control) *window {
|
2014-07-19 08:44:32 -05:00
|
|
|
w := &window{
|
2014-10-02 09:05:53 -05:00
|
|
|
closing: newEvent(),
|
2014-10-18 16:03:07 -05:00
|
|
|
child: control,
|
2014-07-19 08:44:32 -05:00
|
|
|
}
|
2014-10-18 16:03:07 -05:00
|
|
|
w.hwnd = C.newWindow(toUTF16(title), C.int(width), C.int(height), unsafe.Pointer(w))
|
2014-10-02 09:05:53 -05:00
|
|
|
hresult := C.EnableThemeDialogTexture(w.hwnd, C.ETDT_ENABLE|C.ETDT_USETABTEXTURE)
|
2014-07-25 14:58:24 -05:00
|
|
|
if hresult != C.S_OK {
|
|
|
|
panic(fmt.Errorf("error setting tab background texture on Window; HRESULT: 0x%X", hresult))
|
|
|
|
}
|
2014-10-18 16:03:07 -05:00
|
|
|
w.child.setParent(&controlParent{w.hwnd})
|
2014-07-19 08:44:32 -05:00
|
|
|
return w
|
2014-07-12 10:29:54 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *window) Title() string {
|
|
|
|
return getWindowText(w.hwnd)
|
2014-07-12 10:29:54 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *window) SetTitle(title string) {
|
|
|
|
C.setWindowText(w.hwnd, toUTF16(title))
|
2014-07-12 10:29:54 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *window) Show() {
|
|
|
|
if !w.shownbefore {
|
|
|
|
C.ShowWindow(w.hwnd, C.nCmdShow)
|
|
|
|
C.updateWindow(w.hwnd)
|
|
|
|
w.shownbefore = true
|
|
|
|
} else {
|
|
|
|
C.ShowWindow(w.hwnd, C.SW_SHOW)
|
2014-07-12 10:29:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *window) Hide() {
|
|
|
|
C.ShowWindow(w.hwnd, C.SW_HIDE)
|
2014-07-12 10:29:54 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *window) Close() {
|
|
|
|
C.windowClose(w.hwnd)
|
2014-07-12 10:29:54 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *window) OnClosing(e func() bool) {
|
|
|
|
w.closing.setbool(e)
|
2014-07-12 10:29:54 -05:00
|
|
|
}
|
2014-08-04 18:46:49 -05:00
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
func (w *window) Margined() bool {
|
|
|
|
return w.margined
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *window) SetMargined(margined bool) {
|
|
|
|
w.margined = margined
|
2014-08-04 18:46:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//export windowResize
|
|
|
|
func windowResize(data unsafe.Pointer, r *C.RECT) {
|
|
|
|
w := (*window)(data)
|
2014-10-26 13:43:45 -05:00
|
|
|
d := beginResize(w.hwnd)
|
2014-10-18 16:03:07 -05:00
|
|
|
if w.margined {
|
|
|
|
marginRectDLU(r, marginDialogUnits, marginDialogUnits, marginDialogUnits, marginDialogUnits, d)
|
|
|
|
}
|
|
|
|
w.child.resize(int(r.left), int (r.top), int(r.right - r.left), int(r.bottom - r.top), d)
|
2014-08-04 18:46:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//export windowClosing
|
|
|
|
func windowClosing(data unsafe.Pointer) {
|
2014-08-04 19:04:16 -05:00
|
|
|
w := (*window)(data)
|
|
|
|
close := w.closing.fire()
|
2014-08-04 18:46:49 -05:00
|
|
|
if close {
|
2014-08-04 19:04:16 -05:00
|
|
|
C.windowClose(w.hwnd)
|
2014-08-04 18:46:49 -05:00
|
|
|
}
|
|
|
|
}
|