Deduplicate code in WndProc function callback implementations

This commit is contained in:
twinaphex 2020-08-28 00:38:15 +02:00
parent be3345b766
commit 5f2e810879
1 changed files with 64 additions and 188 deletions

View File

@ -1001,9 +1001,8 @@ static LRESULT CALLBACK wnd_proc_common(
return 0;
}
#if defined(HAVE_D3D) || defined (HAVE_D3D10) || defined (HAVE_D3D11) || defined (HAVE_D3D12)
LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
static LRESULT CALLBACK wnd_proc_common_internal(HWND hwnd,
UINT message, WPARAM wparam, LPARAM lparam)
{
LRESULT ret;
bool quit = false;
@ -1054,7 +1053,19 @@ LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
taskbar_is_created = true;
#endif
break;
case WM_CREATE:
}
return DefWindowProc(hwnd, message, wparam, lparam);
}
#if defined(HAVE_D3D) || defined (HAVE_D3D10) || defined (HAVE_D3D11) || defined (HAVE_D3D12)
LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
win32_common_state_t *g_win32 = (win32_common_state_t*)&win32_st;
if (message == WM_CREATE)
{
if (DragAcceptFiles_func)
DragAcceptFiles_func(hwnd, true);
@ -1062,7 +1073,7 @@ LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
return 0;
}
return DefWindowProc(hwnd, message, wparam, lparam);
return wnd_proc_common_internal(hwnd, message, wparam, lparam);
}
#endif
@ -1074,59 +1085,15 @@ LRESULT CALLBACK WndProcWGL(HWND hwnd, UINT message,
bool quit = false;
win32_common_state_t *g_win32 = (win32_common_state_t*)&win32_st;
switch (message)
if (message == WM_CREATE)
{
case WM_MOUSEMOVE:
case WM_POINTERDOWN:
case WM_POINTERUP:
case WM_POINTERUPDATE:
case WM_DEVICECHANGE:
case WM_MOUSEWHEEL:
case WM_MOUSEHWHEEL:
case WM_NCLBUTTONDBLCLK:
#if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true;
#endif
#ifdef HAVE_DINPUT
if (input_get_ptr() == &input_dinput)
{
void* input_data = input_get_data();
if (input_data && dinput_handle_message(input_data,
message, wparam, lparam))
return 0;
}
#endif
break;
case WM_DROPFILES:
case WM_SYSCOMMAND:
case WM_CHAR:
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
case WM_SYSKEYDOWN:
case WM_CLOSE:
case WM_DESTROY:
case WM_QUIT:
case WM_MOVE:
case WM_SIZE:
case WM_COMMAND:
ret = wnd_proc_common(&quit, hwnd, message, wparam, lparam);
if (quit)
return ret;
#if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true;
#endif
break;
case WM_CREATE:
create_graphics_context(hwnd, &g_win32->quit);
if (DragAcceptFiles_func)
DragAcceptFiles_func(hwnd, true);
return 0;
}
return DefWindowProc(hwnd, message, wparam, lparam);
return wnd_proc_common_internal(hwnd, message, wparam, lparam);
}
#endif
@ -1134,63 +1101,17 @@ LRESULT CALLBACK WndProcWGL(HWND hwnd, UINT message,
LRESULT CALLBACK WndProcVK(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
LRESULT ret;
bool quit = false;
win32_common_state_t *g_win32 = (win32_common_state_t*)&win32_st;
switch (message)
if (message == WM_CREATE)
{
case WM_MOUSEMOVE:
case WM_POINTERDOWN:
case WM_POINTERUP:
case WM_POINTERUPDATE:
case WM_DEVICECHANGE:
case WM_MOUSEWHEEL:
case WM_MOUSEHWHEEL:
case WM_NCLBUTTONDBLCLK:
#if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true;
#endif
#ifdef HAVE_DINPUT
if (input_get_ptr() == &input_dinput)
{
void* input_data = input_get_data();
if (input_data && dinput_handle_message(input_data,
message, wparam, lparam))
return 0;
}
#endif
break;
case WM_DROPFILES:
case WM_SYSCOMMAND:
case WM_CHAR:
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
case WM_SYSKEYDOWN:
case WM_CLOSE:
case WM_DESTROY:
case WM_QUIT:
case WM_MOVE:
case WM_SIZE:
case WM_COMMAND:
ret = wnd_proc_common(&quit, hwnd, message, wparam, lparam);
if (quit)
return ret;
#if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true;
#endif
break;
case WM_CREATE:
create_vk_context(hwnd, &g_win32->quit);
if (DragAcceptFiles_func)
DragAcceptFiles_func(hwnd, true);
return 0;
}
return DefWindowProc(hwnd, message, wparam, lparam);
return wnd_proc_common_internal(hwnd, message, wparam, lparam);
}
#endif
@ -1202,31 +1123,14 @@ LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
bool quit = false;
win32_common_state_t *g_win32 = (win32_common_state_t*)&win32_st;
switch (message)
if (message == WM_CREATE)
{
case WM_MOUSEMOVE:
case WM_POINTERDOWN:
case WM_POINTERUP:
case WM_POINTERUPDATE:
case WM_DEVICECHANGE:
case WM_MOUSEWHEEL:
case WM_MOUSEHWHEEL:
case WM_NCLBUTTONDBLCLK:
#if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true;
#endif
#ifdef HAVE_DINPUT
if (input_get_ptr() == &input_dinput)
{
void* input_data = input_get_data();
if (input_data && dinput_handle_message(input_data,
message, wparam, lparam))
create_gdi_context(hwnd, &g_win32->quit);
if (DragAcceptFiles_func)
DragAcceptFiles_func(hwnd, true);
return 0;
}
#endif
break;
case WM_PAINT:
else if (message == WM_PAINT)
{
gdi_t *gdi = (gdi_t*)video_driver_get_ptr(false);
@ -1256,37 +1160,9 @@ LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
&& message == g_win32->taskbar_message)
taskbar_is_created = true;
#endif
break;
}
case WM_DROPFILES:
case WM_SYSCOMMAND:
case WM_CHAR:
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
case WM_SYSKEYDOWN:
case WM_CLOSE:
case WM_DESTROY:
case WM_QUIT:
case WM_MOVE:
case WM_SIZE:
case WM_COMMAND:
ret = wnd_proc_common(&quit, hwnd, message, wparam, lparam);
if (quit)
return ret;
#if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true;
#endif
break;
case WM_CREATE:
create_gdi_context(hwnd, &g_win32->quit);
if (DragAcceptFiles_func)
DragAcceptFiles_func(hwnd, true);
return 0;
}
return DefWindowProc(hwnd, message, wparam, lparam);
return wnd_proc_common_internal(hwnd, message, wparam, lparam);
}
#endif