Abstracted out the message filter stuff so we can add a dialog message filter to allow tab navigation anywhere next.
This commit is contained in:
parent
6124d45c62
commit
960533ab1f
|
@ -393,23 +393,17 @@ BOOL areaDoEvents(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *l
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static HHOOK areaFilter;
|
||||
|
||||
// TODO affect visibility properly
|
||||
// TODO what did this mean
|
||||
static LRESULT CALLBACK areaFilterProc(int code, WPARAM wParam, LPARAM lParam)
|
||||
static BOOL areaFilter(MSG *msg)
|
||||
{
|
||||
MSG *msg = (MSG *) lParam;
|
||||
LRESULT handled;
|
||||
|
||||
if (code < 0)
|
||||
goto callNext;
|
||||
|
||||
// is the recipient an area?
|
||||
if (msg->hwnd == NULL) // this can happen; for example, WM_TIMER
|
||||
goto callNext;
|
||||
return FALSE;
|
||||
if (windowClassOf(msg->hwnd, areaClass, NULL) != 0)
|
||||
goto callNext; // nope
|
||||
return FALSE; // nope
|
||||
|
||||
handled = 0;
|
||||
switch (msg->message) {
|
||||
|
@ -423,27 +417,5 @@ static LRESULT CALLBACK areaFilterProc(int code, WPARAM wParam, LPARAM lParam)
|
|||
break;
|
||||
// otherwise handled remains 0, as we didn't handle this
|
||||
}
|
||||
if (!handled)
|
||||
goto callNext;
|
||||
|
||||
// we handled it; discard the message so the dialog manager doesn't see it
|
||||
return 1;
|
||||
|
||||
callNext:
|
||||
return CallNextHookEx(areaFilter, code, wParam, lParam);
|
||||
}
|
||||
|
||||
int registerAreaFilter(void)
|
||||
{
|
||||
areaFilter = SetWindowsHookExW(WH_MSGFILTER,
|
||||
areaFilterProc,
|
||||
hInstance,
|
||||
GetCurrentThreadId());
|
||||
return areaFilter != NULL;
|
||||
}
|
||||
|
||||
void unregisterAreaFilter(void)
|
||||
{
|
||||
if (UnhookWindowsHookEx(areaFilter) == 0)
|
||||
logLastError("error unregistering uiArea message filter in unregisterAreaFilter()");
|
||||
return (BOOL) handled;
|
||||
}
|
||||
|
|
|
@ -126,8 +126,9 @@ const char *uiInit(uiInitOptions *o)
|
|||
|
||||
if (registerAreaClass(hDefaultIcon, hDefaultCursor) == 0)
|
||||
return ieLastErr("registering uiArea window class");
|
||||
if (registerAreaFilter() == 0)
|
||||
return ieLastErr("registering uiArea message filter");
|
||||
|
||||
if (registerMessageFilter() == 0)
|
||||
return ieLastErr("registering libui message filter");
|
||||
|
||||
if (registerD2DScratchClass(hDefaultIcon, hDefaultCursor) == 0)
|
||||
return ieLastErr("initializing D2D scratch window class");
|
||||
|
@ -139,6 +140,7 @@ void uiUninit(void)
|
|||
{
|
||||
uninitMenus();
|
||||
unregisterD2DScratchClass();
|
||||
unregisterMessageFilter();
|
||||
unregisterArea();
|
||||
uninitDrawText();
|
||||
uninitDraw();
|
||||
|
|
|
@ -1,6 +1,43 @@
|
|||
// 6 april 2015
|
||||
#include "uipriv_windows.hpp"
|
||||
|
||||
static HHOOK filter;
|
||||
|
||||
static LRESULT CALLBACK filterProc(int code, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
MSG *msg = (MSG *) lParam;
|
||||
BOOL discard;
|
||||
|
||||
if (code < 0)
|
||||
goto callNext;
|
||||
|
||||
discard = !areaFilter(msg);
|
||||
|
||||
if (discard)
|
||||
goto callNext;
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
// TODO http://blogs.msdn.com/b/oldnewthing/archive/2005/04/08/406509.aspx when adding accelerators, TranslateAccelerators() before IsDialogMessage()
|
||||
|
||||
void uiMain(void)
|
||||
|
|
|
@ -59,3 +59,7 @@ extern uiInitOptions options;
|
|||
extern HWND utilWindow;
|
||||
extern const char *initUtilWindow(HICON hDefaultIcon, HCURSOR hDefaultCursor);
|
||||
extern void uninitUtilWindow(void);
|
||||
|
||||
// main.cpp
|
||||
extern void registerMessageFilter(void);
|
||||
extern void unregisterMessageFilter(void);
|
||||
|
|
Loading…
Reference in New Issue