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:
Pietro Gagliardi 2014-08-06 21:34:31 -04:00
parent 2ea9987c98
commit ddbb719918
3 changed files with 30 additions and 5 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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(