From dd1d5c871e09f3c05305b496db7ca3e885605f6f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 26 Apr 2016 22:17:42 -0400 Subject: [PATCH] Migrated the container stuff. --- windows/container.cpp | 32 ++++++++++++++++++++++++++++++-- windows/uipriv_windows.hpp | 1 - 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/windows/container.cpp b/windows/container.cpp index 89aa70c2..b6d2402d 100644 --- a/windows/container.cpp +++ b/windows/container.cpp @@ -5,16 +5,38 @@ // - uiBox // - uiRadioButtons +struct containerInit { + void (*onResize)(void *data); + void *data; +}; + static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { RECT r; HDC dc; PAINTSTRUCT ps; + CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam; + WINDOWPOS *wp = (WINDOWPOS *) lParam; + struct containerInit *init; + void (*onResize)(void *); + void *data; LRESULT lResult; if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) return lResult; switch (uMsg) { + case WM_CREATE: + init = (struct containerInit *) (cs->lpParam); + SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (init->onResize)); + SetWindowLongPtrW(hwnd, 0, (LONG_PTR) (init->data)); + break; // defer to DefWindowProc() + case WM_WINDOWPOSCHANGED: + if ((wp->flags & SWP_NOSIZE) != 0) + break; // defer to DefWindowProc(); + onResize = (void (*)(void *)) GetWindowLongPtrW(hwnd, GWLP_USERDATA); + data = (void *) GetWindowLongPtrW(hwnd, 0); + (*(onResize))(data); + return 0; case WM_PAINT: dc = BeginPaint(hwnd, &ps); if (dc == NULL) { @@ -54,6 +76,7 @@ ATOM initContainer(HICON hDefaultIcon, HCURSOR hDefaultCursor) wc.hIcon = hDefaultIcon; wc.hCursor = hDefaultCursor; wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); + wc.cbWndExtra = sizeof (void *); return RegisterClassW(&wc); } @@ -63,11 +86,16 @@ void uninitContainer(void) logLastError(L"error unregistering container window class"); } -HWND newContainer(void) +HWND uiWindowsMakeContainer(void (*onResize)(void *data), void *data) { + struct containerInit init; + + // TODO onResize cannot be NULL + init.onResize = onResize; + init.data = data; return uiWindowsEnsureCreateControlHWND(WS_EX_CONTROLPARENT, containerClass, L"", 0, - hInstance, NULL, + hInstance, (LPVOID) (&init), FALSE); } diff --git a/windows/uipriv_windows.hpp b/windows/uipriv_windows.hpp index 85de595c..689f2d96 100644 --- a/windows/uipriv_windows.hpp +++ b/windows/uipriv_windows.hpp @@ -115,7 +115,6 @@ extern void ensureMinimumWindowSize(uiWindow *); #define containerClass L"libui_uiContainerClass" extern ATOM initContainer(HICON, HCURSOR); extern void uninitContainer(void); -extern HWND newContainer(void); // TODO