Moved code to handle window user data in the Windows backend to a single function.

This commit is contained in:
Pietro Gagliardi 2014-08-14 16:12:43 -04:00
parent d944af8609
commit 868161b7f0
5 changed files with 31 additions and 43 deletions

View File

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

View File

@ -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;
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;
}
/*

View File

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

View File

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

View File

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