Got rid of all the template cruft and other nonsense from events.cpp.
This commit is contained in:
parent
df190dc368
commit
99aba5a3b8
|
@ -1,121 +1,132 @@
|
||||||
// 20 may 2015
|
// 20 may 2015
|
||||||
#include "uipriv_windows.hpp"
|
#include "uipriv_windows.hpp"
|
||||||
|
|
||||||
// In each of these structures, hwnd is the hash key.
|
struct handler {
|
||||||
|
BOOL (*commandHandler)(uiControl *, HWND, WORD, LRESULT *);
|
||||||
struct commandHandler {
|
BOOL (*notifyHandler)(uiControl *, HWND, NMHDR *, LRESULT *);
|
||||||
BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *);
|
BOOL (*hscrollHandler)(uiControl *, HWND, WORD, LRESULT *);
|
||||||
uiControl *c;
|
uiControl *c;
|
||||||
|
|
||||||
|
struct handler()
|
||||||
|
{
|
||||||
|
this->commandHandler = NULL;
|
||||||
|
this->notifyHandler = NULL;
|
||||||
|
this->hscrollHandler = NULL;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct notifyHandler {
|
static std::map<HWND, struct handler> handlers;
|
||||||
BOOL (*handler)(uiControl *, HWND, NMHDR *, LRESULT *);
|
|
||||||
uiControl *c;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct hscrollHandler {
|
|
||||||
BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *);
|
|
||||||
uiControl *c;
|
|
||||||
};
|
|
||||||
|
|
||||||
static std::map<HWND, struct commandHandler> commandHandlers;
|
|
||||||
static std::map<HWND, struct notifyHandler> notifyHandlers;
|
|
||||||
static std::map<HWND, struct hscrollHandler> hscrollHandlers;
|
|
||||||
|
|
||||||
template<typename thirdArg, std::map<HWND, typename> &handlers>
|
|
||||||
static void registerHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, thirdArg, LRESULT *), uiControl *c, const char *mname, const char *fname)
|
|
||||||
{
|
|
||||||
if (handlers.find(hwnd) != handlers.end())
|
|
||||||
complain("window handle %p already subscribed with a %s handler in %s", hwnd, mname, fname);
|
|
||||||
handlers[hwnd].handler = handler;
|
|
||||||
handlers[hwnd].c = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void uiWindowsRegisterWM_COMMANDHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c)
|
void uiWindowsRegisterWM_COMMANDHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c)
|
||||||
{
|
{
|
||||||
registerHandler<WORD, commandHandlers>(hwnd, handler, c, "WM_COMMAND", "uiWindowsRegisterWM_COMMANDHandler()");
|
if (handlers[hwnd].commandHandler != NULL)
|
||||||
|
complain("already registered a WM_COMMAND handler to window handle %p in uiWindowsRegisterWM_COMMANDHandler()", hwnd);
|
||||||
|
handlers[hwnd].commandHandler = handler;
|
||||||
|
handlers[hwnd].c = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiWindowsRegisterWM_NOTIFYHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, NMHDR *, LRESULT *), uiControl *c)
|
void uiWindowsRegisterWM_NOTIFYHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, NMHDR *, LRESULT *), uiControl *c)
|
||||||
{
|
{
|
||||||
registerHandler<NMHDR *, notifyHandlers>(hwnd, handler, c, "WM_NOTIFY", "uiWindowsRegisterWM_NOTIFYHandler()");
|
if (handlers[hwnd].notifyHandler != NULL)
|
||||||
|
complain("already registered a WM_NOTIFY handler to window handle %p in uiWindowsRegisterWM_NOTIFYHandler()", hwnd);
|
||||||
|
handlers[hwnd].notifyHandler = handler;
|
||||||
|
handlers[hwnd].c = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiWindowsRegisterWM_HSCROLLHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c)
|
void uiWindowsRegisterWM_HSCROLLHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c)
|
||||||
{
|
{
|
||||||
registerHandler<WORD, hscrollHandlers>(hwnd, handler, c, "WM_HSCROLL", "uiWindowsRegisterWM_HSCROLLHandler");
|
if (handlers[hwnd].hscrollHandler != NULL)
|
||||||
}
|
complain("already registered a WM_HSCROLL handler to window handle %p in uiWindowsRegisterWM_HSCROLLHandler()", hwnd);
|
||||||
|
handlers[hwnd].hscrollHandler = handler;
|
||||||
template<std::map<HWND, typename> &handlers>
|
handlers[hwnd].c = c;
|
||||||
static void unregisterHandler(HWND hwnd, const char *mname, const char *fname)
|
|
||||||
{
|
|
||||||
if (handlers.find(hwnd) == handlers.end())
|
|
||||||
complain("window handle %p not registered with a %s handler in %s", hwnd, mname, fname);
|
|
||||||
handlers.erase(hwnd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiWindowsUnregisterWM_COMMANDHandler(HWND hwnd)
|
void uiWindowsUnregisterWM_COMMANDHandler(HWND hwnd)
|
||||||
{
|
{
|
||||||
unregisterHandler<commandHandlers>(hwnd, "WM_COMMAND", "uiWindowsUnregisterWM_COMMANDHandler()");
|
if (handlers[hwnd].commandHandler == NULL)
|
||||||
|
complain("window handle %p not registered to receive WM_COMMAND events in uiWindowsUnregisterWM_COMMANDHandler()", hwnd);
|
||||||
|
handlers[hwnd].commandHandler = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiWindowsUnregisterWM_NOTIFYHandler(HWND hwnd)
|
void uiWindowsUnregisterWM_NOTIFYHandler(HWND hwnd)
|
||||||
{
|
{
|
||||||
unregisterHandler<notifyHandlers>(hwnd, "WM_NOTIFY", "uiWindowsUnregisterWM_NOTIFYHandler()");
|
if (handlers[hwnd].notifyHandler == NULL)
|
||||||
|
complain("window handle %p not registered to receive WM_NOTIFY events in uiWindowsUnregisterWM_NOTIFYHandler()", hwnd);
|
||||||
|
handlers[hwnd].notifyHandler = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiWindowsUnregisterWM_HSCROLLHandler(HWND hwnd)
|
void uiWindowsUnregisterWM_HSCROLLHandler(HWND hwnd)
|
||||||
{
|
{
|
||||||
unregisterHandler<hscrollHandlers>(hwnd, "WM_HSCROLL", "uiWindowsUnregisterWM_HSCROLLHandler()");
|
if (handlers[hwnd].hscrollHandler == NULL)
|
||||||
|
complain("window handle %p not registered to receive WM_HSCROLL events in uiWindowsUnregisterWM_HSCROLLHandler()", hwnd);
|
||||||
|
handlers[hwnd].hscrollHandler = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename thirdArg, std::map<HWND, typename> &handlers, HWND (*getHWND)(WPARAM, LPARAM), thirdArg (*getThirdArg)(WPARAM, LPARAM)>
|
template<typename T>
|
||||||
static BOOL runHandler(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
static BOOL shouldRun(HWND hwnd, T method)
|
||||||
{
|
{
|
||||||
HWND control;
|
// not from a window
|
||||||
|
if (hwnd == NULL)
|
||||||
// bounce back to the control in question
|
return FALSE;
|
||||||
// dn't bounce back if to the utility window, in which case act as if the message was ignored
|
// don't bounce back if to the utility window, in which case act as if the message was ignored
|
||||||
control = (*getHWND)(wParam, lParam);
|
if (IsChild(utilWindow, hwnd) != 0)
|
||||||
if (control != NULL && IsChild(utilWindow, control) == 0) {
|
return FALSE;
|
||||||
if (handlers.find(control) != handlers.end())
|
// registered?
|
||||||
return (*(handlers[control].handler))(handlers[control].c, control, (*getThirdArg)(wParam, lParam), lResult);
|
return method == NULL;
|
||||||
// not registered; fall out to return FALSE
|
|
||||||
}
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL runWM_COMMAND(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
BOOL runWM_COMMAND(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
||||||
{
|
{
|
||||||
return runHandler<WORD, commandHandlers,
|
HWND hwnd;
|
||||||
[](WPARAM wParam, LPARAM lParam) {
|
WORD arg3;
|
||||||
return (HWND) lParam;
|
BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *);
|
||||||
|
uiControl *c;
|
||||||
|
|
||||||
|
hwnd = (HWND) lParam;
|
||||||
|
arg3 = HIWORD(wParam);
|
||||||
|
handler = handlers[hwnd].commandHandler;
|
||||||
|
c = handlers[hwnd].c;
|
||||||
|
if (shouldRun(hwnd, handler))
|
||||||
|
return (*handler)(c, hwnd, arg3, lResult);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
[](WPARAM wParam, LPARAM lParam) {
|
[](WPARAM wParam, LPARAM lParam) {
|
||||||
return HIWORD(wParam);
|
return ;
|
||||||
}>(wParam, lParam, lResult);
|
}>(wParam, lParam, lResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL runWM_NOTIFY(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
BOOL runWM_NOTIFY(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
||||||
{
|
{
|
||||||
return runHandler<NMHDR *, notifyHandlers,
|
HWND hwnd;
|
||||||
[](WPARAM wParam, LPARAM lParam) {
|
NMHDR *arg3;
|
||||||
return ((NMHDR *) lParam)->hwndFrom;
|
BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *);
|
||||||
},
|
uiControl *c;
|
||||||
[](WPARAM wParam, LPARAM lParam) {
|
|
||||||
return (NMHDR *) lParam;
|
arg3 = (NMHDR *) lParam;
|
||||||
}>(wParam, lParam, lResult);
|
hwnd = arg3->hwndFrom;
|
||||||
|
handler = handlers[hwnd].notifyHandler;
|
||||||
|
c = handlers[hwnd].c;
|
||||||
|
if (shouldRun(hwnd, handler))
|
||||||
|
return (*handler)(c, hwnd, arg3, lResult);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL runWM_HSCROLL(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
BOOL runWM_HSCROLL(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
||||||
{
|
{
|
||||||
return runHandler<WORD, hscrollHandlers,
|
HWND hwnd;
|
||||||
[](WPARAM wParam, LPARAM lParam) {
|
WORD arg3;
|
||||||
return (HWND) lParam;
|
BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *);
|
||||||
},
|
uiControl *c;
|
||||||
[](WPARAM wParam, LPARAM lParam) {
|
|
||||||
return LOWORD(wParam);
|
hwnd = (HWND) lParam;
|
||||||
}>(wParam, lParam, lResult);
|
arg3 = LOWORD(wParam);
|
||||||
|
handler = handlers[hwnd].hscrollHandler;
|
||||||
|
c = handlers[hwnd].c;
|
||||||
|
if (shouldRun(hwnd, handler))
|
||||||
|
return (*handler)(c, hwnd, arg3, lResult);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::map<HWND, bool> wininichanges;
|
static std::map<HWND, bool> wininichanges;
|
||||||
|
|
Loading…
Reference in New Issue