From ddbb71991891731c43ebb8c6e82b16a8179855cc Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 6 Aug 2014 21:34:31 -0400 Subject: [PATCH] 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. --- redo/container_windows.c | 32 +++++++++++++++++++++++++++++--- redo/tab_windows.go | 2 -- redo/zz_test.go | 1 + 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/redo/container_windows.c b/redo/container_windows.c index 927e03b..ea19695 100644 --- a/redo/container_windows.c +++ b/redo/container_windows.c @@ -15,6 +15,10 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP { void *data; RECT r; + HDC dc; + PAINTSTRUCT ps; + HWND parent; + POINT client; data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); if (data == NULL) { @@ -33,6 +37,29 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP return forwardCommand(hwnd, uMsg, wParam, lParam); case WM_NOTIFY: 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: if (GetClientRect(hwnd, &r) == 0) xpanic("error getting client rect for Window in WM_SIZE", GetLastError()); @@ -54,8 +81,7 @@ DWORD makeContainerWindowClass(char **errmsg) wc.hInstance = hInstance; wc.hIcon = hDefaultIcon; wc.hCursor = hArrowCursor; - /* TODO won't this override our visual styles? */ - wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); + wc.hbrBackground = NULL; /* we paint our own background */ wc.lpszClassName = containerclass; if (RegisterClassW(&wc) == 0) { *errmsg = "error registering container window class"; @@ -69,7 +95,7 @@ HWND newContainer(void *data) HWND hwnd; hwnd = CreateWindowExW( - 0, + WS_EX_TRANSPARENT, containerclass, L"", WS_CHILD | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, diff --git a/redo/tab_windows.go b/redo/tab_windows.go index 3c1862d..31493cd 100644 --- a/redo/tab_windows.go +++ b/redo/tab_windows.go @@ -94,11 +94,9 @@ func (t *tab) commitResize(c *allocation, d *sizing) { r.top = C.LONG(0) r.right = C.LONG(c.width) r.bottom = C.LONG(c.height) -println(r.left, r.top, r.right, r.bottom) C.tabGetContentRect(t._hwnd, &r) // and resize 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 { // because each widget is actually a child of the Window, the origin is the one we calculated above c.move(&r) diff --git a/redo/zz_test.go b/redo/zz_test.go index c54c614..22ab0bc 100644 --- a/redo/zz_test.go +++ b/redo/zz_test.go @@ -64,6 +64,7 @@ func (tw *testwin) make(done chan struct{}) { done <- struct{}{} return true }) + tw.t.Append("Space", Space()) tw.a = NewArea(200, 200, &areaHandler{}) tw.t.Append("Area", tw.a) tw.spw = NewHorizontalStack(