summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redo/area_windows.c16
-rw-r--r--redo/common_windows.c16
-rw-r--r--redo/container_windows.c20
-rw-r--r--redo/winapi_windows.h2
-rw-r--r--redo/window_windows.c20
5 files changed, 31 insertions, 43 deletions
diff --git a/redo/area_windows.c b/redo/area_windows.c
index e6347bd..e9ded14 100644
--- a/redo/area_windows.c
+++ b/redo/area_windows.c
@@ -314,19 +314,11 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
void *data;
DWORD which;
uintptr_t heldButtons = (uintptr_t) wParam;
+ LRESULT lResult;
- 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);
- storeAreaHWND(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);
- }
-
+ data = getWindowData(hwnd, uMsg, wParam, lParam, &lResult, storeAreaHWND);
+ if (data == NULL)
+ return lResult;
switch (uMsg) {
case WM_PAINT:
paintArea(hwnd, data);
diff --git a/redo/common_windows.c b/redo/common_windows.c
index 01da0ef..53f2b3e 100644
--- a/redo/common_windows.c
+++ b/redo/common_windows.c
@@ -29,11 +29,23 @@ void updateWindow(HWND hwnd)
xpanic("error calling UpdateWindow()", GetLastError());
}
-void storelpParam(HWND hwnd, LPARAM lParam)
+void *getWindowData(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult, void (*storeHWND)(void *, HWND))
{
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
+ void *data;
- SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams));
+ data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
+ if (data == NULL) {
+ // the lpParam is available during WM_NCCREATE and WM_CREATE
+ if (uMsg == WM_NCCREATE) {
+ SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams));
+ data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
+ (*storeHWND)(data, hwnd);
+ }
+ // act as if we're not ready yet, even during WM_NCCREATE (nothing important to the switch statement below happens here anyway)
+ *lResult = DefWindowProcW(hwnd, uMsg, wParam, lParam);
+ }
+ return data;
}
/*
diff --git a/redo/container_windows.c b/redo/container_windows.c
index 4d5215a..a95818d 100644
--- a/redo/container_windows.c
+++ b/redo/container_windows.c
@@ -15,21 +15,13 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
{
void *data;
RECT r;
- LRESULT shared;
+ LRESULT lResult;
- 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);
- }
- if (sharedWndProc(hwnd, uMsg, wParam, lParam, &shared))
- return shared;
+ data = getWindowData(hwnd, uMsg, wParam, lParam, &lResult, storeContainerHWND);
+ if (data == NULL)
+ return lResult;
+ if (sharedWndProc(hwnd, uMsg, wParam, lParam, &lResult))
+ return lResult;
switch (uMsg) {
case WM_SIZE:
if (GetClientRect(hwnd, &r) == 0)
diff --git a/redo/winapi_windows.h b/redo/winapi_windows.h
index 328e0a3..028f3c3 100644
--- a/redo/winapi_windows.h
+++ b/redo/winapi_windows.h
@@ -81,7 +81,7 @@ extern LRESULT getWindowTextLen(HWND);
extern void getWindowText(HWND, WPARAM, LPWSTR);
extern void setWindowText(HWND, LPWSTR);
extern void updateWindow(HWND);
-extern void storelpParam(HWND, LPARAM);
+extern void *getWindowData(HWND, UINT, WPARAM, LPARAM, LRESULT *, void (*)(void *, HWND));
extern BOOL sharedWndProc(HWND, UINT, WPARAM, LPARAM, LRESULT *);
// tab_windows.go
diff --git a/redo/window_windows.c b/redo/window_windows.c
index 5ea83f1..e4ea875 100644
--- a/redo/window_windows.c
+++ b/redo/window_windows.c
@@ -9,21 +9,13 @@ static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA
{
void *data;
RECT r;
- LRESULT shared;
+ LRESULT lResult;
- 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);
- storeWindowHWND(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);
- }
- if (sharedWndProc(hwnd, uMsg, wParam, lParam, &shared))
- return shared;
+ data = getWindowData(hwnd, uMsg, wParam, lParam, &lResult, storeWindowHWND);
+ if (data == NULL)
+ return lResult;
+ if (sharedWndProc(hwnd, uMsg, wParam, lParam, &lResult))
+ return lResult;
switch (uMsg) {
case WM_SIZE:
if (GetClientRect(hwnd, &r) == 0)