2015-05-14 10:19:52 -05:00
|
|
|
// 14 may 2015
|
2016-04-22 12:52:02 -05:00
|
|
|
#include "uipriv_windows.hpp"
|
2015-05-14 10:19:52 -05:00
|
|
|
|
|
|
|
// The utility window is a special window that performs certain tasks internal to libui.
|
|
|
|
// It is not a message-only window, and it is always hidden and disabled.
|
|
|
|
// Its roles:
|
|
|
|
// - It is the initial parent of all controls. When a control loses its parent, it also becomes that control's parent.
|
2017-05-28 20:55:10 -05:00
|
|
|
// - It handles WM_QUERYENDSESSION requests.
|
2015-06-03 23:26:13 -05:00
|
|
|
// - It handles WM_WININICHANGE and forwards the message to any child windows that request it.
|
2015-12-04 22:49:04 -06:00
|
|
|
// - It handles executing functions queued to run by uiQueueMain().
|
2017-08-20 04:30:36 -05:00
|
|
|
// TODO explain why it isn't message-only
|
2015-05-14 10:19:52 -05:00
|
|
|
|
|
|
|
#define utilWindowClass L"libui_utilWindowClass"
|
|
|
|
|
|
|
|
HWND utilWindow;
|
|
|
|
|
|
|
|
static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2015-12-04 22:42:03 -06:00
|
|
|
void (*qf)(void *);
|
2015-05-14 10:19:52 -05:00
|
|
|
LRESULT lResult;
|
|
|
|
|
|
|
|
if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
|
|
|
|
return lResult;
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_QUERYENDSESSION:
|
2018-04-15 20:54:46 -05:00
|
|
|
// TODO block handler (TODO figure out if this meant the Vista-style block handler or not)
|
|
|
|
if (uiprivShouldQuit()) {
|
2015-05-14 10:19:52 -05:00
|
|
|
uiQuit();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2015-06-03 23:26:13 -05:00
|
|
|
case WM_WININICHANGE:
|
|
|
|
issueWM_WININICHANGE(wParam, lParam);
|
|
|
|
return 0;
|
2015-12-04 22:42:03 -06:00
|
|
|
case msgQueued:
|
|
|
|
qf = (void (*)(void *)) wParam;
|
|
|
|
(*qf)((void *) lParam);
|
|
|
|
return 0;
|
2015-05-14 10:19:52 -05:00
|
|
|
}
|
|
|
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *initUtilWindow(HICON hDefaultIcon, HCURSOR hDefaultCursor)
|
|
|
|
{
|
|
|
|
WNDCLASSW wc;
|
|
|
|
|
2015-05-16 10:37:45 -05:00
|
|
|
ZeroMemory(&wc, sizeof (WNDCLASSW));
|
2015-05-14 10:19:52 -05:00
|
|
|
wc.lpszClassName = utilWindowClass;
|
|
|
|
wc.lpfnWndProc = utilWindowWndProc;
|
|
|
|
wc.hInstance = hInstance;
|
|
|
|
wc.hIcon = hDefaultIcon;
|
|
|
|
wc.hCursor = hDefaultCursor;
|
|
|
|
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
|
|
|
|
if (RegisterClass(&wc) == 0)
|
2016-05-29 18:55:53 -05:00
|
|
|
// see init.cpp for an explanation of the =s
|
|
|
|
return "=registering utility window class";
|
2015-05-14 10:19:52 -05:00
|
|
|
|
|
|
|
utilWindow = CreateWindowExW(0,
|
|
|
|
utilWindowClass, L"libui utility window",
|
|
|
|
WS_OVERLAPPEDWINDOW,
|
|
|
|
0, 0, 100, 100,
|
|
|
|
NULL, NULL, hInstance, NULL);
|
|
|
|
if (utilWindow == NULL)
|
2016-05-29 18:55:53 -05:00
|
|
|
return "=creating utility window";
|
2015-05-14 10:19:52 -05:00
|
|
|
// and just to be safe
|
|
|
|
EnableWindow(utilWindow, FALSE);
|
|
|
|
|
2015-05-16 10:37:45 -05:00
|
|
|
return NULL;
|
2015-05-14 10:19:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uninitUtilWindow(void)
|
|
|
|
{
|
|
|
|
if (DestroyWindow(utilWindow) == 0)
|
2016-04-22 12:52:02 -05:00
|
|
|
logLastError(L"error destroying utility window");
|
2015-05-14 10:19:52 -05:00
|
|
|
if (UnregisterClass(utilWindowClass, hInstance) == 0)
|
2016-04-22 12:52:02 -05:00
|
|
|
logLastError(L"error unregistering utility window class");
|
2015-05-14 10:19:52 -05:00
|
|
|
}
|