2015-04-24 12:59:49 -05:00
|
|
|
// 6 april 2015
|
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
2015-11-27 11:21:40 -06:00
|
|
|
// TODO http://blogs.msdn.com/b/oldnewthing/archive/2005/04/08/406509.aspx when adding accelerators, TranslateMessage() before IsDialogMessage()
|
2015-04-24 12:59:49 -05:00
|
|
|
|
2015-05-06 17:37:21 -05:00
|
|
|
static void msgloop_else(MSG *msg)
|
2015-04-24 12:59:49 -05:00
|
|
|
{
|
|
|
|
TranslateMessage(msg);
|
2015-05-25 12:46:38 -05:00
|
|
|
DispatchMessageW(msg);
|
2015-04-24 12:59:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiMain(void)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
int res;
|
2015-11-27 20:45:30 -06:00
|
|
|
HWND active;
|
2015-04-24 12:59:49 -05:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
SetLastError(0);
|
|
|
|
res = GetMessageW(&msg, NULL, 0, 0);
|
|
|
|
if (res < 0)
|
|
|
|
logLastError("error calling GetMessage() in uiMain()");
|
|
|
|
if (res == 0) // WM_QUIT
|
|
|
|
break;
|
|
|
|
active = GetActiveWindow();
|
|
|
|
if (active == NULL) {
|
2015-05-06 17:37:21 -05:00
|
|
|
msgloop_else(&msg);
|
2015-04-24 12:59:49 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-11-27 20:45:30 -06:00
|
|
|
// TODO find documentation that says IsDialogMessage() calls CallMsgFilter() for us, because that's what's happening
|
|
|
|
// TODO rewrite this whole function to compensate
|
2015-04-24 12:59:49 -05:00
|
|
|
|
|
|
|
if (IsDialogMessage(active, &msg) != 0)
|
|
|
|
continue;
|
2015-05-06 17:37:21 -05:00
|
|
|
msgloop_else(&msg);
|
2015-04-24 12:59:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiQuit(void)
|
|
|
|
{
|
|
|
|
PostQuitMessage(0);
|
|
|
|
}
|
2015-12-04 22:42:03 -06:00
|
|
|
|
|
|
|
void uiQueueMain(void (*f)(void *data), void *data)
|
|
|
|
{
|
|
|
|
if (PostMessageW(utilWindow, msgQueued, (WPARAM) f, (LPARAM) data) == 0)
|
|
|
|
// TODO make sure this is safe to call across threads
|
|
|
|
logLastError("error queueing function to run on main thread in uiQueueMain()");
|
|
|
|
}
|