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;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HHOOK areaFilter;
|
|
||||||
|
|
||||||
// TODO affect visibility properly
|
// TODO affect visibility properly
|
||||||
// TODO what did this mean
|
// 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;
|
LRESULT handled;
|
||||||
|
|
||||||
if (code < 0)
|
|
||||||
goto callNext;
|
|
||||||
|
|
||||||
// is the recipient an area?
|
// is the recipient an area?
|
||||||
if (msg->hwnd == NULL) // this can happen; for example, WM_TIMER
|
if (msg->hwnd == NULL) // this can happen; for example, WM_TIMER
|
||||||
goto callNext;
|
return FALSE;
|
||||||
if (windowClassOf(msg->hwnd, areaClass, NULL) != 0)
|
if (windowClassOf(msg->hwnd, areaClass, NULL) != 0)
|
||||||
goto callNext; // nope
|
return FALSE; // nope
|
||||||
|
|
||||||
handled = 0;
|
handled = 0;
|
||||||
switch (msg->message) {
|
switch (msg->message) {
|
||||||
|
@ -423,27 +417,5 @@ static LRESULT CALLBACK areaFilterProc(int code, WPARAM wParam, LPARAM lParam)
|
||||||
break;
|
break;
|
||||||
// otherwise handled remains 0, as we didn't handle this
|
// otherwise handled remains 0, as we didn't handle this
|
||||||
}
|
}
|
||||||
if (!handled)
|
return (BOOL) 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()");
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,8 +126,9 @@ const char *uiInit(uiInitOptions *o)
|
||||||
|
|
||||||
if (registerAreaClass(hDefaultIcon, hDefaultCursor) == 0)
|
if (registerAreaClass(hDefaultIcon, hDefaultCursor) == 0)
|
||||||
return ieLastErr("registering uiArea window class");
|
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)
|
if (registerD2DScratchClass(hDefaultIcon, hDefaultCursor) == 0)
|
||||||
return ieLastErr("initializing D2D scratch window class");
|
return ieLastErr("initializing D2D scratch window class");
|
||||||
|
@ -139,6 +140,7 @@ void uiUninit(void)
|
||||||
{
|
{
|
||||||
uninitMenus();
|
uninitMenus();
|
||||||
unregisterD2DScratchClass();
|
unregisterD2DScratchClass();
|
||||||
|
unregisterMessageFilter();
|
||||||
unregisterArea();
|
unregisterArea();
|
||||||
uninitDrawText();
|
uninitDrawText();
|
||||||
uninitDraw();
|
uninitDraw();
|
||||||
|
|
|
@ -1,6 +1,43 @@
|
||||||
// 6 april 2015
|
// 6 april 2015
|
||||||
#include "uipriv_windows.hpp"
|
#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()
|
// TODO http://blogs.msdn.com/b/oldnewthing/archive/2005/04/08/406509.aspx when adding accelerators, TranslateAccelerators() before IsDialogMessage()
|
||||||
|
|
||||||
void uiMain(void)
|
void uiMain(void)
|
||||||
|
|
|
@ -59,3 +59,7 @@ extern uiInitOptions options;
|
||||||
extern HWND utilWindow;
|
extern HWND utilWindow;
|
||||||
extern const char *initUtilWindow(HICON hDefaultIcon, HCURSOR hDefaultCursor);
|
extern const char *initUtilWindow(HICON hDefaultIcon, HCURSOR hDefaultCursor);
|
||||||
extern void uninitUtilWindow(void);
|
extern void uninitUtilWindow(void);
|
||||||
|
|
||||||
|
// main.cpp
|
||||||
|
extern void registerMessageFilter(void);
|
||||||
|
extern void unregisterMessageFilter(void);
|
||||||
|
|
Loading…
Reference in New Issue