2015-05-20 21:46:50 -05:00
|
|
|
// 20 may 2015
|
2016-04-20 21:10:04 -05:00
|
|
|
#include "uipriv_windows.hpp"
|
|
|
|
|
2016-04-21 11:20:37 -05:00
|
|
|
struct handler {
|
|
|
|
BOOL (*commandHandler)(uiControl *, HWND, WORD, LRESULT *);
|
|
|
|
BOOL (*notifyHandler)(uiControl *, HWND, NMHDR *, LRESULT *);
|
|
|
|
BOOL (*hscrollHandler)(uiControl *, HWND, WORD, LRESULT *);
|
2015-05-20 21:46:50 -05:00
|
|
|
uiControl *c;
|
|
|
|
|
2016-04-21 14:01:05 -05:00
|
|
|
// just to ensure handlers[new HWND] initializes properly
|
2016-04-21 11:20:37 -05:00
|
|
|
struct handler()
|
|
|
|
{
|
|
|
|
this->commandHandler = NULL;
|
|
|
|
this->notifyHandler = NULL;
|
|
|
|
this->hscrollHandler = NULL;
|
2016-04-21 11:22:02 -05:00
|
|
|
this->c = NULL;
|
2016-04-21 11:20:37 -05:00
|
|
|
}
|
2015-05-20 21:46:50 -05:00
|
|
|
};
|
|
|
|
|
2016-04-21 11:20:37 -05:00
|
|
|
static std::map<HWND, struct handler> handlers;
|
2016-04-21 10:22:34 -05:00
|
|
|
|
|
|
|
void uiWindowsRegisterWM_COMMANDHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c)
|
|
|
|
{
|
2016-04-21 11:20:37 -05:00
|
|
|
if (handlers[hwnd].commandHandler != NULL)
|
2016-05-13 20:07:48 -05:00
|
|
|
implbug("already registered a WM_COMMAND handler to window handle %p", hwnd);
|
2016-04-21 11:20:37 -05:00
|
|
|
handlers[hwnd].commandHandler = handler;
|
|
|
|
handlers[hwnd].c = c;
|
2016-04-21 10:22:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsRegisterWM_NOTIFYHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, NMHDR *, LRESULT *), uiControl *c)
|
|
|
|
{
|
2016-04-21 11:20:37 -05:00
|
|
|
if (handlers[hwnd].notifyHandler != NULL)
|
2016-05-13 20:07:48 -05:00
|
|
|
implbug("already registered a WM_NOTIFY handler to window handle %p", hwnd);
|
2016-04-21 11:20:37 -05:00
|
|
|
handlers[hwnd].notifyHandler = handler;
|
|
|
|
handlers[hwnd].c = c;
|
2016-04-21 10:22:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsRegisterWM_HSCROLLHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c)
|
|
|
|
{
|
2016-04-21 11:20:37 -05:00
|
|
|
if (handlers[hwnd].hscrollHandler != NULL)
|
2016-05-13 20:07:48 -05:00
|
|
|
implbug("already registered a WM_HSCROLL handler to window handle %p", hwnd);
|
2016-04-21 11:20:37 -05:00
|
|
|
handlers[hwnd].hscrollHandler = handler;
|
|
|
|
handlers[hwnd].c = c;
|
2016-04-21 10:22:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsUnregisterWM_COMMANDHandler(HWND hwnd)
|
|
|
|
{
|
2016-04-21 11:20:37 -05:00
|
|
|
if (handlers[hwnd].commandHandler == NULL)
|
2016-05-13 20:07:48 -05:00
|
|
|
implbug("window handle %p not registered to receive WM_COMMAND events", hwnd);
|
2016-04-21 11:20:37 -05:00
|
|
|
handlers[hwnd].commandHandler = NULL;
|
2016-04-21 10:22:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsUnregisterWM_NOTIFYHandler(HWND hwnd)
|
|
|
|
{
|
2016-04-21 11:20:37 -05:00
|
|
|
if (handlers[hwnd].notifyHandler == NULL)
|
2016-05-13 20:07:48 -05:00
|
|
|
implbug("window handle %p not registered to receive WM_NOTIFY events", hwnd);
|
2016-04-21 11:20:37 -05:00
|
|
|
handlers[hwnd].notifyHandler = NULL;
|
2016-04-21 10:22:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsUnregisterWM_HSCROLLHandler(HWND hwnd)
|
|
|
|
{
|
2016-04-21 11:20:37 -05:00
|
|
|
if (handlers[hwnd].hscrollHandler == NULL)
|
2016-05-13 20:07:48 -05:00
|
|
|
implbug("window handle %p not registered to receive WM_HSCROLL events", hwnd);
|
2016-04-21 11:20:37 -05:00
|
|
|
handlers[hwnd].hscrollHandler = NULL;
|
2016-04-21 10:22:34 -05:00
|
|
|
}
|
|
|
|
|
2016-04-21 11:20:37 -05:00
|
|
|
template<typename T>
|
|
|
|
static BOOL shouldRun(HWND hwnd, T method)
|
2016-04-21 10:22:34 -05:00
|
|
|
{
|
2016-04-21 11:20:37 -05:00
|
|
|
// not from a window
|
|
|
|
if (hwnd == NULL)
|
|
|
|
return FALSE;
|
|
|
|
// don't bounce back if to the utility window, in which case act as if the message was ignored
|
|
|
|
if (IsChild(utilWindow, hwnd) != 0)
|
|
|
|
return FALSE;
|
|
|
|
// registered?
|
2016-04-23 23:54:31 -05:00
|
|
|
return method != NULL;
|
2016-04-21 10:22:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL runWM_COMMAND(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
|
|
|
{
|
2016-04-21 11:20:37 -05:00
|
|
|
HWND hwnd;
|
|
|
|
WORD arg3;
|
|
|
|
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;
|
|
|
|
}
|
2016-04-21 10:22:34 -05:00
|
|
|
|
|
|
|
BOOL runWM_NOTIFY(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
|
|
|
{
|
2016-04-21 11:20:37 -05:00
|
|
|
HWND hwnd;
|
|
|
|
NMHDR *arg3;
|
2016-04-23 21:23:07 -05:00
|
|
|
BOOL (*handler)(uiControl *, HWND, NMHDR *, LRESULT *);
|
2016-04-21 11:20:37 -05:00
|
|
|
uiControl *c;
|
|
|
|
|
|
|
|
arg3 = (NMHDR *) lParam;
|
|
|
|
hwnd = arg3->hwndFrom;
|
|
|
|
handler = handlers[hwnd].notifyHandler;
|
|
|
|
c = handlers[hwnd].c;
|
|
|
|
if (shouldRun(hwnd, handler))
|
|
|
|
return (*handler)(c, hwnd, arg3, lResult);
|
|
|
|
return FALSE;
|
2016-04-21 10:22:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL runWM_HSCROLL(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
|
|
|
{
|
2016-04-21 11:20:37 -05:00
|
|
|
HWND hwnd;
|
|
|
|
WORD arg3;
|
|
|
|
BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *);
|
|
|
|
uiControl *c;
|
|
|
|
|
|
|
|
hwnd = (HWND) lParam;
|
|
|
|
arg3 = LOWORD(wParam);
|
|
|
|
handler = handlers[hwnd].hscrollHandler;
|
|
|
|
c = handlers[hwnd].c;
|
|
|
|
if (shouldRun(hwnd, handler))
|
|
|
|
return (*handler)(c, hwnd, arg3, lResult);
|
|
|
|
return FALSE;
|
2016-04-21 10:22:34 -05:00
|
|
|
}
|
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])
|
2016-05-13 20:07:48 -05:00
|
|
|
implbug("window handle %p already subscribed to receive WM_WINICHANGEs", 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])
|
2016-05-13 20:07:48 -05:00
|
|
|
implbug("window handle %p not registered to receive WM_WININICHANGEs", 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
|
|
|
}
|