Split apart the Windows Window code so that the same window class can be used for both top-level windows and tab pages (next commit). This makes things slightly messy in the short term, but this will all be cleaned up soon, and has the advantage of taking care of the sizer mess~
This commit is contained in:
parent
2c107d7057
commit
950548563d
|
@ -0,0 +1,58 @@
|
|||
// 4 august 2014
|
||||
|
||||
package ui
|
||||
|
||||
// TODO clean this up relative to window_windows.go
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "winapi_windows.h"
|
||||
import "C"
|
||||
|
||||
type layout struct {
|
||||
hwnd C.HWND
|
||||
|
||||
closing *event
|
||||
|
||||
*sizer
|
||||
}
|
||||
|
||||
func newLayout(title string, width int, height int, child C.BOOL, control Control) *layout {
|
||||
l := &layout{
|
||||
// hwnd set in WM_CREATE handler
|
||||
closing: newEvent(),
|
||||
sizer: new(sizer),
|
||||
}
|
||||
hwnd := C.newWindow(toUTF16(title), C.int(width), C.int(height), child, unsafe.Pointer(l))
|
||||
if hwnd != l.hwnd {
|
||||
panic(fmt.Errorf("inconsistency: hwnd returned by CreateWindowEx() (%p) and hwnd stored in window/layout (%p) differ", hwnd, l.hwnd))
|
||||
}
|
||||
l.child = control
|
||||
l.child.setParent(&controlParent{l.hwnd})
|
||||
return l
|
||||
}
|
||||
|
||||
//export storeWindowHWND
|
||||
func storeWindowHWND(data unsafe.Pointer, hwnd C.HWND) {
|
||||
l := (*layout)(data)
|
||||
l.hwnd = hwnd
|
||||
}
|
||||
|
||||
//export windowResize
|
||||
func windowResize(data unsafe.Pointer, r *C.RECT) {
|
||||
l := (*layout)(data)
|
||||
// the origin of the window's content area is always (0, 0), but let's use the values from the RECT just to be safe
|
||||
l.resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top))
|
||||
}
|
||||
|
||||
//export windowClosing
|
||||
func windowClosing(data unsafe.Pointer) {
|
||||
l := (*layout)(data)
|
||||
close := l.closing.fire()
|
||||
if close {
|
||||
C.windowClose(l.hwnd)
|
||||
}
|
||||
}
|
|
@ -74,7 +74,7 @@ extern LONG controlTextLength(HWND, LPWSTR);
|
|||
|
||||
/* window_windows.c */
|
||||
extern DWORD makeWindowWindowClass(char **);
|
||||
extern HWND newWindow(LPWSTR, int, int, void *);
|
||||
extern HWND newWindow(LPWSTR, int, int, BOOL, void *);
|
||||
extern void windowClose(HWND);
|
||||
|
||||
/* common_windows.c */
|
||||
|
|
|
@ -60,19 +60,28 @@ DWORD makeWindowWindowClass(char **errmsg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
HWND newWindow(LPWSTR title, int width, int height, void *data)
|
||||
HWND newWindow(LPWSTR title, int width, int height, BOOL child, void *data)
|
||||
{
|
||||
HWND hwnd;
|
||||
DWORD style;
|
||||
HWND parent;
|
||||
|
||||
style = WS_OVERLAPPEDWINDOW;
|
||||
parent = NULL;
|
||||
if (child) {
|
||||
style = WS_CHILD;
|
||||
parent = msgwin;
|
||||
}
|
||||
hwnd = CreateWindowExW(
|
||||
0,
|
||||
windowclass, title,
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
style,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
width, height,
|
||||
NULL, NULL, hInstance, data);
|
||||
parent, NULL, hInstance, data);
|
||||
if (hwnd == NULL)
|
||||
xpanic("Window creation failed", GetLastError());
|
||||
if (!child)
|
||||
calculateBaseUnits(hwnd);
|
||||
return hwnd;
|
||||
}
|
||||
|
|
|
@ -5,24 +5,16 @@ package ui
|
|||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// #include "winapi_windows.h"
|
||||
import "C"
|
||||
|
||||
type window struct {
|
||||
hwnd C.HWND
|
||||
*layout
|
||||
shownbefore bool
|
||||
|
||||
closing *event
|
||||
|
||||
*sizer
|
||||
}
|
||||
|
||||
const windowclassname = ""
|
||||
var windowclassptr = syscall.StringToUTF16Ptr(windowclassname)
|
||||
|
||||
func makeWindowWindowClass() error {
|
||||
var errmsg *C.char
|
||||
|
||||
|
@ -35,21 +27,13 @@ func makeWindowWindowClass() error {
|
|||
|
||||
func newWindow(title string, width int, height int, control Control) *window {
|
||||
w := &window{
|
||||
// hwnd set in WM_CREATE handler
|
||||
closing: newEvent(),
|
||||
sizer: new(sizer),
|
||||
}
|
||||
hwnd := C.newWindow(toUTF16(title), C.int(width), C.int(height), unsafe.Pointer(w))
|
||||
if hwnd != w.hwnd {
|
||||
panic(fmt.Errorf("inconsistency: hwnd returned by CreateWindowEx() (%p) and hwnd stored in window (%p) differ", hwnd, w.hwnd))
|
||||
layout: newLayout(title, width, height, C.FALSE, control),
|
||||
}
|
||||
// TODO keep?
|
||||
hresult := C.EnableThemeDialogTexture(w.hwnd, C.ETDT_ENABLE | C.ETDT_USETABTEXTURE)
|
||||
if hresult != C.S_OK {
|
||||
panic(fmt.Errorf("error setting tab background texture on Window; HRESULT: 0x%X", hresult))
|
||||
}
|
||||
w.child = control
|
||||
w.child.setParent(&controlParent{w.hwnd})
|
||||
return w
|
||||
}
|
||||
|
||||
|
@ -82,25 +66,3 @@ func (w *window) Close() {
|
|||
func (w *window) OnClosing(e func() bool) {
|
||||
w.closing.setbool(e)
|
||||
}
|
||||
|
||||
//export storeWindowHWND
|
||||
func storeWindowHWND(data unsafe.Pointer, hwnd C.HWND) {
|
||||
w := (*window)(data)
|
||||
w.hwnd = hwnd
|
||||
}
|
||||
|
||||
//export windowResize
|
||||
func windowResize(data unsafe.Pointer, r *C.RECT) {
|
||||
w := (*window)(data)
|
||||
// the origin of the window's content area is always (0, 0), but let's use the values from the RECT just to be safe
|
||||
w.resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top))
|
||||
}
|
||||
|
||||
//export windowClosing
|
||||
func windowClosing(data unsafe.Pointer) {
|
||||
w := (*window)(data)
|
||||
close := w.closing.fire()
|
||||
if close {
|
||||
C.windowClose(w.hwnd)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue