diff options
| author | Pietro Gagliardi <[email protected]> | 2014-08-04 19:46:49 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-08-04 19:46:49 -0400 |
| commit | 9ed4ec52597e03b080331efeac526322b669e565 (patch) | |
| tree | 3fbd62fc272409d26ec10b56a7d546dbb9e5bc98 /redo/container_windows.c | |
| parent | 88c01bf69532243f432e03121b922a94d19b0ae1 (diff) | |
Split layout and Window on Windows to use two separate window classes. This is the first half of the two-part migration of the Windows backend to use container.
Diffstat (limited to 'redo/container_windows.c')
| -rw-r--r-- | redo/container_windows.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/redo/container_windows.c b/redo/container_windows.c new file mode 100644 index 0000000..5db4548 --- /dev/null +++ b/redo/container_windows.c @@ -0,0 +1,84 @@ +/* 17 july 2014 */ + +#include "winapi_windows.h" +#include "_cgo_export.h" + +/* +This could all just be part of Window, but doing so just makes things complex. +In this case, I chose to waste a window handle rather than keep things super complex. +If this is seriously an issue in the future, I can roll it back. +*/ + +#define containerclass L"gouicontainer" + +static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + void *data; + RECT r; + + data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); + if (data == NULL) { + /* the lpParam is available during WM_NCCREATE and WM_CREATE */ + if (uMsg == WM_NCCREATE) { + storelpParam(hwnd, lParam); + data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); + storeContainerHWND(data, hwnd); + } + /* act as if we're not ready yet, even during WM_NCCREATE (nothing important to the switch statement below happens here anyway) */ + return DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + + switch (uMsg) { + case WM_COMMAND: + return forwardCommand(hwnd, uMsg, wParam, lParam); + case WM_NOTIFY: + return forwardNotify(hwnd, uMsg, wParam, lParam); + case WM_SIZE: + if (GetClientRect(hwnd, &r) == 0) + xpanic("error getting client rect for Window in WM_SIZE", GetLastError()); + containerResize(data, &r); + return 0; + default: + return DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + xmissedmsg("container", "containerWndProc()", uMsg); + return 0; /* unreached */ +} + +DWORD makeContainerWindowClass(char **errmsg) +{ + WNDCLASSW wc; + + ZeroMemory(&wc, sizeof (WNDCLASSW)); + wc.lpfnWndProc = containerWndProc; + wc.hInstance = hInstance; + wc.hIcon = hDefaultIcon; + wc.hCursor = hArrowCursor; + wc.hbrBackground = (HBRUSH) GetStockObject(HOLLOW_BRUSH); + if (wc.hbrBackground == NULL) { + *errmsg = "error getting hollow brush for container window class"; + return GetLastError(); + } + wc.lpszClassName = containerclass; + if (RegisterClassW(&wc) == 0) { + *errmsg = "error registering container window class"; + return GetLastError(); + } + return 0; +} + +HWND newContainer(void *data) +{ + HWND hwnd; + + hwnd = CreateWindowExW( + 0, + containerclass, L"", + WS_CHILD | WS_VISIBLE, + CW_USEDEFAULT, CW_USEDEFAULT, + 100, 100, + msgwin, NULL, hInstance, data); + if (hwnd == NULL) + xpanic("container creation failed", GetLastError()); + return hwnd; +} |
