2015-05-20 21:46:50 -05:00
|
|
|
// 20 may 2015
|
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
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 {
|
|
|
|
HWND hwnd;
|
|
|
|
BOOL (*handler)(uiControl *, WORD, LRESULT *);
|
|
|
|
uiControl *c;
|
2015-05-21 10:02:10 -05:00
|
|
|
UT_hash_handle hh;
|
2015-05-20 21:46:50 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct notifyHandler {
|
|
|
|
HWND hwnd;
|
|
|
|
BOOL (*handler)(uiControl *, NMHDR *, LRESULT *);
|
|
|
|
uiControl *c;
|
2015-05-21 10:02:10 -05:00
|
|
|
UT_hash_handle hh;
|
2015-05-20 21:46:50 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hscrollHandler {
|
|
|
|
HWND hwnd;
|
|
|
|
BOOL (*handler)(uiControl *, WORD, LRESULT *);
|
|
|
|
uiControl *c;
|
2015-05-21 10:02:10 -05:00
|
|
|
UT_hash_handle hh;
|
2015-05-20 21:46:50 -05:00
|
|
|
};
|
|
|
|
|
2015-05-21 10:02:10 -05:00
|
|
|
struct commandHandler *commandHandlers = NULL;
|
|
|
|
struct notifyHandler *notifyHandlers = NULL;
|
|
|
|
struct hscrollHandler *hscrollHandlers = NULL;
|
2015-05-20 21:46:50 -05:00
|
|
|
|
|
|
|
void uiWindowsRegisterWM_COMMANDHandler(HWND hwnd, BOOL (*handler)(uiControl *, WORD, LRESULT *), uiControl *c)
|
|
|
|
{
|
|
|
|
struct commandHandler *ch;
|
|
|
|
|
2015-05-21 10:02:10 -05:00
|
|
|
HASH_FIND_PTR(commandHandlers, &hwnd, ch);
|
|
|
|
if (ch != NULL)
|
|
|
|
complain("window handle %p already subscribed to receive WM_COMMANDs in uiWindowsRegisterWM_COMMANDHandler()", hwnd);
|
2015-05-20 21:46:50 -05:00
|
|
|
ch = uiNew(struct commandHandler);
|
|
|
|
ch->hwnd = hwnd;
|
|
|
|
ch->handler = handler;
|
|
|
|
ch->c = c;
|
2015-05-21 10:02:10 -05:00
|
|
|
HASH_ADD_PTR(commandHandlers, hwnd, ch);
|
2015-05-20 21:46:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowsUnregisterWM_COMMANDHandler(HWND hwnd)
|
|
|
|
{
|
|
|
|
struct commandHandler *ch;
|
|
|
|
|
2015-05-21 10:02:10 -05:00
|
|
|
HASH_FIND_PTR(commandHandlers, &hwnd, ch);
|
|
|
|
if (ch == NULL)
|
|
|
|
complain("window handle %p not registered with a WM_COMMAND handler in uiWindowsUnregisterWM_COMMANDHandler()", hwnd);
|
|
|
|
HASH_DEL(commandHandlers, ch);
|
|
|
|
uiFree(ch);
|
2015-05-20 21:46:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL runWM_COMMAND(WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
|
|
|
{
|
|
|
|
HWND control;
|
|
|
|
struct commandHandler *ch;
|
|
|
|
|
|
|
|
// bounce back to the control in question
|
|
|
|
// don't bounce back if to the utility window, in which case act as if the message was ignored
|
|
|
|
control = (HWND) lParam;
|
|
|
|
if (control != NULL && IsChild(utilWindow, control) == 0) {
|
2015-05-21 10:02:10 -05:00
|
|
|
HASH_FIND_PTR(commandHandlers, &control, ch);
|
|
|
|
if (ch != NULL)
|
|
|
|
return (*(ch->handler))(ch->c, HIWORD(wParam), lResult);
|
2015-05-20 21:46:50 -05:00
|
|
|
// not registered; fall out to return FALSE
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|