Moved code to handle window user data in the Windows backend to a single function.
This commit is contained in:
parent
d944af8609
commit
868161b7f0
|
@ -314,19 +314,11 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
|
||||||
void *data;
|
void *data;
|
||||||
DWORD which;
|
DWORD which;
|
||||||
uintptr_t heldButtons = (uintptr_t) wParam;
|
uintptr_t heldButtons = (uintptr_t) wParam;
|
||||||
|
LRESULT lResult;
|
||||||
|
|
||||||
data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
data = getWindowData(hwnd, uMsg, wParam, lParam, &lResult, storeAreaHWND);
|
||||||
if (data == NULL) {
|
if (data == NULL)
|
||||||
// the lpParam is available during WM_NCCREATE and WM_CREATE
|
return lResult;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
paintArea(hwnd, data);
|
paintArea(hwnd, data);
|
||||||
|
|
|
@ -29,11 +29,23 @@ void updateWindow(HWND hwnd)
|
||||||
xpanic("error calling UpdateWindow()", GetLastError());
|
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;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -15,21 +15,13 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
|
||||||
{
|
{
|
||||||
void *data;
|
void *data;
|
||||||
RECT r;
|
RECT r;
|
||||||
LRESULT shared;
|
LRESULT lResult;
|
||||||
|
|
||||||
data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
data = getWindowData(hwnd, uMsg, wParam, lParam, &lResult, storeContainerHWND);
|
||||||
if (data == NULL) {
|
if (data == NULL)
|
||||||
// the lpParam is available during WM_NCCREATE and WM_CREATE
|
return lResult;
|
||||||
if (uMsg == WM_NCCREATE) {
|
if (sharedWndProc(hwnd, uMsg, wParam, lParam, &lResult))
|
||||||
storelpParam(hwnd, lParam);
|
return lResult;
|
||||||
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;
|
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
case WM_SIZE:
|
case WM_SIZE:
|
||||||
if (GetClientRect(hwnd, &r) == 0)
|
if (GetClientRect(hwnd, &r) == 0)
|
||||||
|
|
|
@ -81,7 +81,7 @@ extern LRESULT getWindowTextLen(HWND);
|
||||||
extern void getWindowText(HWND, WPARAM, LPWSTR);
|
extern void getWindowText(HWND, WPARAM, LPWSTR);
|
||||||
extern void setWindowText(HWND, LPWSTR);
|
extern void setWindowText(HWND, LPWSTR);
|
||||||
extern void updateWindow(HWND);
|
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 *);
|
extern BOOL sharedWndProc(HWND, UINT, WPARAM, LPARAM, LRESULT *);
|
||||||
|
|
||||||
// tab_windows.go
|
// tab_windows.go
|
||||||
|
|
|
@ -9,21 +9,13 @@ static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA
|
||||||
{
|
{
|
||||||
void *data;
|
void *data;
|
||||||
RECT r;
|
RECT r;
|
||||||
LRESULT shared;
|
LRESULT lResult;
|
||||||
|
|
||||||
data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
data = getWindowData(hwnd, uMsg, wParam, lParam, &lResult, storeWindowHWND);
|
||||||
if (data == NULL) {
|
if (data == NULL)
|
||||||
// the lpParam is available during WM_NCCREATE and WM_CREATE
|
return lResult;
|
||||||
if (uMsg == WM_NCCREATE) {
|
if (sharedWndProc(hwnd, uMsg, wParam, lParam, &lResult))
|
||||||
storelpParam(hwnd, lParam);
|
return lResult;
|
||||||
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;
|
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
case WM_SIZE:
|
case WM_SIZE:
|
||||||
if (GetClientRect(hwnd, &r) == 0)
|
if (GetClientRect(hwnd, &r) == 0)
|
||||||
|
|
Loading…
Reference in New Issue