2015-05-20 21:46:50 -05:00
|
|
|
// 20 may 2015
|
2016-04-20 21:10:04 -05:00
|
|
|
#include "uipriv_windows.hpp"
|
|
|
|
|
2015-05-21 10:02:10 -05:00
|
|
|
// In each of these structures, hwnd is the hash key.
|
2015-05-20 21:46:50 -05:00
|
|
|
|
|
|
|
struct commandHandler {
|
2015-05-21 13:52:21 -05:00
|
|
|
BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *);
|
2015-05-20 21:46:50 -05:00
|
|
|
uiControl *c;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct notifyHandler {
|
2015-05-21 13:52:21 -05:00
|
|
|
BOOL (*handler)(uiControl *, HWND, NMHDR *, LRESULT *);
|
2015-05-20 21:46:50 -05:00
|
|
|
uiControl *c;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hscrollHandler {
|
2015-05-21 13:52:21 -05:00
|
|
|
BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *);
|
2015-05-20 21:46:50 -05:00
|
|
|
uiControl *c;
|
|
|
|
};
|
|
|
|
|
2016-04-20 21:10:04 -05:00
|
|
|
static std::map<HWND, struct commandHandler> commandHandlers;
|
|
|
|
static std::map<HWND, struct notifyHandler> notifyHandlers;
|
|
|
|
static std::map<HWND, struct hscrollHandler> hscrollHandlers;
|
2015-05-20 21:46:50 -05:00
|
|
|
|
2016-04-21 10:22:34 -05:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
registerHandler<WORD, commandHandlers>(hwnd, handler, c, "WM_COMMAND", "uiWindowsRegisterWM_COMMANDHandler()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsRegisterWM_NOTIFYHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, NMHDR *, LRESULT *), uiControl *c)
|
|
|
|
{
|
|
|
|
registerHandler<NMHDR *, notifyHandlers>(hwnd, handler, c, "WM_NOTIFY", "uiWindowsRegisterWM_NOTIFYHandler()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsRegisterWM_HSCROLLHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c)
|
|
|
|
{
|
|
|
|
registerHandler<WORD, hscrollHandlers>(hwnd, handler, c, "WM_HSCROLL", "uiWindowsRegisterWM_HSCROLLHandler");
|
|
|
|
}
|
|
|
|
|
|
|
|
template<std::map<HWND, typename> &handlers>
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
unregisterHandler<commandHandlers>(hwnd, "WM_COMMAND", "uiWindowsUnregisterWM_COMMANDHandler()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsUnregisterWM_NOTIFYHandler(HWND hwnd)
|
|
|
|
{
|
|
|
|
unregisterHandler<notifyHandlers>(hwnd, "WM_NOTIFY", "uiWindowsUnregisterWM_NOTIFYHandler()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsUnregisterWM_HSCROLLHandler(HWND hwnd)
|
|
|
|
{
|
|
|
|
unregisterHandler<hscrollHandlers>(hwnd, "WM_HSCROLL", "uiWindowsUnregisterWM_HSCROLLHandler()");
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename thirdArg, std::map<HWND, typename> &handlers, HWND (*getHWND)(WPARAM, LPARAM), thirdArg (*getThirdArg)(WPARAM, LPARAM)>
|
|
|
|
static BOOL runHandler(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
|
|
|
{
|
|
|
|
HWND control;
|
|
|
|
|
|
|
|
// bounce back to the control in question
|
|
|
|
// dn't bounce back if to the utility window, in which case act as if the message was ignored
|
|
|
|
control = (*getHWND)(wParam, lParam);
|
|
|
|
if (control != NULL && IsChild(utilWindow, control) == 0) {
|
|
|
|
if (handlers.find(control) != handlers.end())
|
|
|
|
return (*(handlers[control].handler))(handlers[control].c, control, (*getThirdArg)(wParam, lParam), lResult);
|
|
|
|
// not registered; fall out to return FALSE
|
2015-05-20 21:46:50 -05:00
|
|
|
}
|
2016-04-21 10:22:34 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL runWM_COMMAND(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
|
|
|
{
|
|
|
|
return runHandler<WORD, commandHandlers,
|
|
|
|
[](WPARAM wParam, LPARAM lParam) {
|
|
|
|
return (HWND) lParam;
|
|
|
|
},
|
|
|
|
[](WPARAM wParam, LPARAM lParam) {
|
|
|
|
return HIWORD(wParam);
|
|
|
|
}>(wParam, lParam, lResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL runWM_NOTIFY(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
|
|
|
{
|
|
|
|
return runHandler<NMHDR *, notifyHandlers,
|
|
|
|
[](WPARAM wParam, LPARAM lParam) {
|
|
|
|
return ((NMHDR *) lParam)->hwndFrom;
|
|
|
|
},
|
|
|
|
[](WPARAM wParam, LPARAM lParam) {
|
|
|
|
return (NMHDR *) lParam;
|
|
|
|
}>(wParam, lParam, lResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL runWM_HSCROLL(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
|
|
|
{
|
|
|
|
return runHandler<WORD, hscrollHandlers,
|
|
|
|
[](WPARAM wParam, LPARAM lParam) {
|
|
|
|
return (HWND) lParam;
|
|
|
|
},
|
|
|
|
[](WPARAM wParam, LPARAM lParam) {
|
|
|
|
return LOWORD(wParam);
|
|
|
|
}>(wParam, lParam, lResult);
|
|
|
|
}
|
2015-06-03 23:26:13 -05:00
|
|
|
|
2016-04-20 21:10:04 -05:00
|
|
|
static std::map<HWND, bool> wininichanges;
|
2015-06-03 23:26:13 -05:00
|
|
|
|
|
|
|
void uiWindowsRegisterReceiveWM_WININICHANGE(HWND hwnd)
|
|
|
|
{
|
2016-04-20 21:10:04 -05:00
|
|
|
if (wininichanges[hwnd])
|
2015-06-03 23:26:13 -05:00
|
|
|
complain("window handle %p already subscribed to receive WM_WINICHANGEs in uiWindowsRegisterReceiveWM_WININICHANGE()", hwnd);
|
2016-04-20 21:10:04 -05:00
|
|
|
wininichanges[hwnd] = true;
|
2015-06-03 23:26:13 -05:00
|
|
|
}
|
|
|
|
|
2015-06-04 09:47:24 -05:00
|
|
|
void uiWindowsUnregisterReceiveWM_WININICHANGE(HWND hwnd)
|
2015-06-03 23:26:13 -05:00
|
|
|
{
|
2016-04-21 10:22:34 -05:00
|
|
|
if (!wininichanges[hwnd])
|
|
|
|
complain("window handle %p not registered to receive WM_WININICHANGEs in uiWindowsUnregisterReceiveWM_WININICHANGE
|
|
|
|
()", hwnd);
|
2016-04-20 21:10:04 -05:00
|
|
|
wininichanges[hwnd] = false;
|
2015-06-03 23:26:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void issueWM_WININICHANGE(WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
struct wininichange *ch;
|
|
|
|
|
2016-04-20 21:10:04 -05:00
|
|
|
for (const auto &iter : wininichanges)
|
|
|
|
SendMessageW(iter.first, WM_WININICHANGE, wParam, lParam);
|
2015-06-03 23:26:13 -05:00
|
|
|
}
|