From d2a5bea737a4001c143ab9f528f828a02371437d Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Sun, 23 Feb 2020 15:32:24 +0800 Subject: [PATCH] use NotifyWindow to implement NotifyParentEx --- include/ctrl/ctrlhelper.h | 33 ++++++++++++++++++++------------- src/control/ctrlmisc.c | 18 ++++++++++++++++-- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/include/ctrl/ctrlhelper.h b/include/ctrl/ctrlhelper.h index 6c50573b..30da8e3a 100644 --- a/include/ctrl/ctrlhelper.h +++ b/include/ctrl/ctrlhelper.h @@ -184,24 +184,30 @@ MG_EXPORT void ResetToolTipWin (HWND hwnd, int x, int y, MG_EXPORT void DestroyToolTipWin (HWND hwnd); /** - * \fn void GUIAPI NotifyParentEx (HWND hwnd, LINT id, int code, DWORD add_data) - * \brief Sends a notification message to the parent. + * \fn void GUIAPI NotifyParentEx (HWND hwnd, LINT id, int code, + * DWORD add_data) + * \brief Send a notification message to the parent. * - * By default, the notification from a control will be sent to its parent - * window within a MSG_COMMAND messsage. + * This function calls \a NotifyWindow to send a notification message + * to the parent. * - * Since version 1.2.6, MiniGUI defines the Nofication Callback Procedure - * for control. You can specify a callback function for a control by calling + * In the early version, the notification from a control will be sent to + * its parent window within a MSG_COMMAND message. + * + * Since version 1.2.6, MiniGUI defines the Notification Callback Procedure + * for a window. You can specify a callback function to a window by calling * \a SetNotificationCallback to receive and handle the notification from - * the control. + * its children in the procedure. * - * If you have defined the Notificaton Callback Procedure for the control, - * calling NotifyParentEx will call the notification callback procedure, - * not send the notification message to the parent. + * If you have set the notification callback procedure for the parent, + * MiniGUI will call the callback procedure eventually, instead of dispatching + * a MSG_COMMAND message to the window procedure. * - * Note that if the control has WS_EX_NOPARENTNOTIFY style, this function + * Note that if the control has \a WS_EX_NOPARENTNOTIFY style, this function * will not notify the parent. * + * Since 5.0.0, you can call NotifyWindow to notify any kind of window. + * * \param hwnd The handle to current control window. * \param id The identifier of current control. * \param code The notification code. @@ -209,9 +215,10 @@ MG_EXPORT void DestroyToolTipWin (HWND hwnd); * * \note The type of \a id change from int to LINT since v3.2. * - * \sa SetNotificationCallback + * \sa NotifyWindow, SetNotificationCallback */ -MG_EXPORT void GUIAPI NotifyParentEx (HWND hwnd, LINT id, int code, DWORD add_data); +MG_EXPORT void GUIAPI NotifyParentEx (HWND hwnd, LINT id, int code, + DWORD add_data); /** * \def NotifyParent(hwnd, id, code) diff --git a/src/control/ctrlmisc.c b/src/control/ctrlmisc.c index 35a99233..8b3ee8c7 100644 --- a/src/control/ctrlmisc.c +++ b/src/control/ctrlmisc.c @@ -239,11 +239,24 @@ void GUIAPI DisabledTextOutEx (HDC hdc, HWND hwnd, int x, int y, const char* szT void GUIAPI NotifyParentEx (HWND hwnd, LINT id, int code, DWORD add_data) { - NOTIFPROC notif_proc; + HWND parent; if (GetWindowExStyle (hwnd) & WS_EX_NOPARENTNOTIFY) return; + /* Since 5.0.0: use NotifyWindow */ + parent = GetParent (hwnd); + if (parent == HWND_INVALID) { + _DBG_PRINTF ("failed to get parent of window (%p)\n", hwnd); + return; + } + + if (NotifyWindow (parent, id, code, add_data)) { + _DBG_PRINTF ("failed to notify parent window (%p)\n", parent); + } + +#if 0 /* deprecated code */ + NOTIFPROC notif_proc; notif_proc = GetNotificationCallback (hwnd); if (notif_proc) { @@ -251,8 +264,9 @@ void GUIAPI NotifyParentEx (HWND hwnd, LINT id, int code, DWORD add_data) } else { SendNotifyMessage (GetParent (hwnd), MSG_COMMAND, - (WPARAM) MAKELONG (id, code), (LPARAM)hwnd); + (WPARAM) MAKELONG (id, code), (LPARAM)hwnd); } +#endif /* deprecated code */ } LRESULT GUIAPI DefaultPageProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)