From d944af860934fdf8a3a38fc48a0b158428d90a0f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 14 Aug 2014 16:00:31 -0400 Subject: Split out common container window procedure code in Windows to its own function. --- redo/common_windows.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'redo/common_windows.c') diff --git a/redo/common_windows.c b/redo/common_windows.c index 3999953..01da0ef 100644 --- a/redo/common_windows.c +++ b/redo/common_windows.c @@ -35,3 +35,46 @@ void storelpParam(HWND hwnd, LPARAM lParam) SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams)); } + +/* +all container windows (including the message-only window, hence this is not in container_windows.c) have to call the sharedWndProc() to ensure messages go in the right place and control colors are handled properly +*/ + +/* +all controls that have events receive the events themselves through subclasses +to do this, all container windows (including the message-only window; see http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q104069) forward WM_COMMAND to each control with this function, WM_NOTIFY with forwardNotify, etc. +*/ +static LRESULT forwardCommand(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + HWND control = (HWND) lParam; + + // don't generate an event if the control (if there is one) is unparented (a child of the message-only window) + if (control != NULL && IsChild(msgwin, control) == 0) + return SendMessageW(control, msgCOMMAND, wParam, lParam); + return DefWindowProcW(hwnd, uMsg, wParam, lParam); +} + +static LRESULT forwardNotify(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + NMHDR *nmhdr = (NMHDR *) lParam; + HWND control = nmhdr->hwndFrom; + + // don't generate an event if the control (if there is one) is unparented (a child of the message-only window) + if (control != NULL && IsChild(msgwin, control) == 0) + return SendMessageW(control, msgNOTIFY, wParam, lParam); + return DefWindowProcW(hwnd, uMsg, wParam, lParam); +} + +// TODO give this a better name +BOOL sharedWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult) +{ + switch (uMsg) { + case WM_COMMAND: + *lResult = forwardCommand(hwnd, uMsg, wParam, lParam); + return TRUE; + case WM_NOTIFY: + *lResult = forwardNotify(hwnd, uMsg, wParam, lParam); + return TRUE; + } + return FALSE; +} -- cgit v1.2.3