2016-04-22 13:06:22 -05:00
|
|
|
// 6 april 2015
|
|
|
|
#include "uipriv_windows.hpp"
|
|
|
|
|
2016-04-22 13:36:21 -05:00
|
|
|
static HHOOK filter;
|
|
|
|
|
|
|
|
static LRESULT CALLBACK filterProc(int code, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
MSG *msg = (MSG *) lParam;
|
|
|
|
|
|
|
|
if (code < 0)
|
|
|
|
goto callNext;
|
|
|
|
|
2016-04-22 13:56:09 -05:00
|
|
|
if (areaFilter(msg)) // don't continue to our IsDialogMessage() hack if the area handled it
|
|
|
|
goto discard;
|
2016-04-22 13:36:21 -05:00
|
|
|
|
2016-04-22 13:56:09 -05:00
|
|
|
// TODO IsDialogMessage() hack here
|
|
|
|
|
|
|
|
// otherwise keep going
|
|
|
|
goto callNext;
|
2016-04-22 13:36:21 -05:00
|
|
|
|
2016-04-22 13:56:09 -05:00
|
|
|
discard:
|
2016-04-22 13:36:21 -05:00
|
|
|
// we handled it; discard the message so the dialog manager doesn't see it
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
callNext:
|
|
|
|
return CallNextHookEx(areaFilter, code, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
int registerMessageFilter(void)
|
|
|
|
{
|
|
|
|
filter = SetWindowsHookExW(WH_MSGFILTER,
|
|
|
|
filterProc,
|
|
|
|
hInstance,
|
|
|
|
GetCurrentThreadId());
|
|
|
|
return filter != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void unregisterMessageFilter(void)
|
|
|
|
{
|
|
|
|
if (UnhookWindowsHookEx(areaFilter) == 0)
|
|
|
|
logLastError(L"error unregistering libui message filter");
|
|
|
|
}
|
|
|
|
|
2016-04-22 13:06:22 -05:00
|
|
|
// TODO http://blogs.msdn.com/b/oldnewthing/archive/2005/04/08/406509.aspx when adding accelerators, TranslateAccelerators() before IsDialogMessage()
|
|
|
|
|
|
|
|
void uiMain(void)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
int res;
|
|
|
|
HWND active;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
res = GetMessageW(&msg, NULL, 0, 0);
|
|
|
|
if (res < 0) {
|
|
|
|
logLastError(L"error calling GetMessage()");
|
|
|
|
break; // bail out on error
|
|
|
|
}
|
|
|
|
if (res == 0) // WM_QUIT
|
|
|
|
break;
|
|
|
|
// TODO really active? or parentToplevel(msg->hwnd)?
|
|
|
|
active = GetActiveWindow();
|
|
|
|
if (active != NULL)
|
|
|
|
// TODO find documentation that says IsDialogMessage() calls CallMsgFilter() for us, because that's what's happening
|
|
|
|
if (IsDialogMessage(active, &msg) != 0)
|
|
|
|
continue;
|
|
|
|
TranslateMessage(msg);
|
|
|
|
DispatchMessageW(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiQuit(void)
|
|
|
|
{
|
|
|
|
PostQuitMessage(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiQueueMain(void (*f)(void *data), void *data)
|
|
|
|
{
|
|
|
|
if (PostMessageW(utilWindow, msgQueued, (WPARAM) f, (LPARAM) data) == 0)
|
|
|
|
// TODO this is likely not safe to call across threads (allocates memory)
|
|
|
|
logLastError(L"error queueing function to run on main thread");
|
|
|
|
}
|