Made containers transparent on Windows. This is the first of a four-part set (though IDK if it will be four commits) to make both containers and areas both transparent and flicker-free. Also added a Space() tab to the test program to test the transparency.
This commit is contained in:
parent
2ea9987c98
commit
ddbb719918
|
@ -15,6 +15,10 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
|
||||||
{
|
{
|
||||||
void *data;
|
void *data;
|
||||||
RECT r;
|
RECT r;
|
||||||
|
HDC dc;
|
||||||
|
PAINTSTRUCT ps;
|
||||||
|
HWND parent;
|
||||||
|
POINT client;
|
||||||
|
|
||||||
data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
|
@ -33,6 +37,29 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
|
||||||
return forwardCommand(hwnd, uMsg, wParam, lParam);
|
return forwardCommand(hwnd, uMsg, wParam, lParam);
|
||||||
case WM_NOTIFY:
|
case WM_NOTIFY:
|
||||||
return forwardNotify(hwnd, uMsg, wParam, lParam);
|
return forwardNotify(hwnd, uMsg, wParam, lParam);
|
||||||
|
case WM_PAINT:
|
||||||
|
/* paint the parent's background in a flicker-free way */
|
||||||
|
dc = BeginPaint(hwnd, &ps);
|
||||||
|
if (dc == NULL)
|
||||||
|
abort();//TODO
|
||||||
|
parent = GetParent(hwnd);
|
||||||
|
if (parent == NULL)
|
||||||
|
abort();//TODO
|
||||||
|
if (GetWindowRect(hwnd, &r) == 0)
|
||||||
|
abort();//TODO
|
||||||
|
/* GetWindowRect() returns in screen coordinates; we want parent client */
|
||||||
|
client.x = r.left;
|
||||||
|
client.y = r.top;
|
||||||
|
if (ScreenToClient(parent, &client) == 0)
|
||||||
|
abort();//TODO
|
||||||
|
if (SetWindowOrgEx(dc, client.x, client.y, NULL) == 0)
|
||||||
|
abort();//TODO
|
||||||
|
SendMessageW(parent, WM_PRINTCLIENT, (WPARAM) dc, PRF_CLIENT);
|
||||||
|
EndPaint(hwnd, &ps);
|
||||||
|
return 0;
|
||||||
|
case WM_ERASEBKGND:
|
||||||
|
/* we paint our own background above */
|
||||||
|
return 1;
|
||||||
case WM_SIZE:
|
case WM_SIZE:
|
||||||
if (GetClientRect(hwnd, &r) == 0)
|
if (GetClientRect(hwnd, &r) == 0)
|
||||||
xpanic("error getting client rect for Window in WM_SIZE", GetLastError());
|
xpanic("error getting client rect for Window in WM_SIZE", GetLastError());
|
||||||
|
@ -54,8 +81,7 @@ DWORD makeContainerWindowClass(char **errmsg)
|
||||||
wc.hInstance = hInstance;
|
wc.hInstance = hInstance;
|
||||||
wc.hIcon = hDefaultIcon;
|
wc.hIcon = hDefaultIcon;
|
||||||
wc.hCursor = hArrowCursor;
|
wc.hCursor = hArrowCursor;
|
||||||
/* TODO won't this override our visual styles? */
|
wc.hbrBackground = NULL; /* we paint our own background */
|
||||||
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
|
|
||||||
wc.lpszClassName = containerclass;
|
wc.lpszClassName = containerclass;
|
||||||
if (RegisterClassW(&wc) == 0) {
|
if (RegisterClassW(&wc) == 0) {
|
||||||
*errmsg = "error registering container window class";
|
*errmsg = "error registering container window class";
|
||||||
|
@ -69,7 +95,7 @@ HWND newContainer(void *data)
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
|
|
||||||
hwnd = CreateWindowExW(
|
hwnd = CreateWindowExW(
|
||||||
0,
|
WS_EX_TRANSPARENT,
|
||||||
containerclass, L"",
|
containerclass, L"",
|
||||||
WS_CHILD | WS_VISIBLE,
|
WS_CHILD | WS_VISIBLE,
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||||
|
|
|
@ -94,11 +94,9 @@ func (t *tab) commitResize(c *allocation, d *sizing) {
|
||||||
r.top = C.LONG(0)
|
r.top = C.LONG(0)
|
||||||
r.right = C.LONG(c.width)
|
r.right = C.LONG(c.width)
|
||||||
r.bottom = C.LONG(c.height)
|
r.bottom = C.LONG(c.height)
|
||||||
println(r.left, r.top, r.right, r.bottom)
|
|
||||||
C.tabGetContentRect(t._hwnd, &r)
|
C.tabGetContentRect(t._hwnd, &r)
|
||||||
// and resize tabs
|
// and resize tabs
|
||||||
// don't resize just the current tab; resize all tabs!
|
// don't resize just the current tab; resize all tabs!
|
||||||
println(r.left, r.top, r.right, r.bottom)
|
|
||||||
for _, c := range t.tabs {
|
for _, c := range t.tabs {
|
||||||
// because each widget is actually a child of the Window, the origin is the one we calculated above
|
// because each widget is actually a child of the Window, the origin is the one we calculated above
|
||||||
c.move(&r)
|
c.move(&r)
|
||||||
|
|
|
@ -64,6 +64,7 @@ func (tw *testwin) make(done chan struct{}) {
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
tw.t.Append("Space", Space())
|
||||||
tw.a = NewArea(200, 200, &areaHandler{})
|
tw.a = NewArea(200, 200, &areaHandler{})
|
||||||
tw.t.Append("Area", tw.a)
|
tw.t.Append("Area", tw.a)
|
||||||
tw.spw = NewHorizontalStack(
|
tw.spw = NewHorizontalStack(
|
||||||
|
|
Loading…
Reference in New Issue