From 9e265193382fbd5578d99dc05b65fbc40e2598b7 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 7 Apr 2015 02:46:27 -0400 Subject: [PATCH] Added subclassing, which finishes off newcontrol_windows.c. --- newcontrol_windows.c | 27 +++++++++++++++++++++++++-- ui_windows.h | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/newcontrol_windows.c b/newcontrol_windows.c index 64d59a37..61f802a1 100644 --- a/newcontrol_windows.c +++ b/newcontrol_windows.c @@ -51,6 +51,28 @@ static void singleContainerHide(uiControl *c) ShowWindow(S(c)->hwnd, SW_HIDE); } +static LRESULT CALLBACK singleSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +{ + uiSingleHWNDControl *c = (uiSingleHWNDControl *) dwRefData; + LRESULT lResult; + + switch (uMsg) { + case msgCOMMAND: + if ((*(c->onWM_COMMAND))((uiControl *) c, wParam, lParam, c->onCommandNotifyData, &lResult) != FALSE) + return lResult; + break; + case msgNOTIFY: + if ((*(c->onWM_NOTIFY))((uiControl *) c, wParam, lParam, c->onCommandNotifyData, &lResult) != FALSE) + return lResult; + break; + case WM_NCDESTROY: + if ((*fv_RemoveWindowSubclass)(hwnd, singleSubclassProc, uIdSubclass) == FALSE) + logLastError("error removing Windows control subclass in singleSubclassProc()"); + break; + } + return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam); +} + uiControl *uiWindowsNewControl(uiWindowsNewControlParams *p) { uiSingleHWNDControl *c; @@ -64,7 +86,7 @@ uiControl *uiWindowsNewControl(uiWindowsNewControlParams *p) // TODO specify control IDs properly initialParent, NULL, p->hInstance, NULL); if (c->hwnd == NULL) - logLastError("error creating control in newSingleHWNDControl()"); + logLastError("error creating control in uiWindowsNewControl()"); c->control.handle = singleHandle; c->control.setParent = singleSetParent; @@ -78,7 +100,8 @@ uiControl *uiWindowsNewControl(uiWindowsNewControlParams *p) c->onCommandNotifyData = p->onCommandNotifyData; c->preferredSize = p->preferredSize; - // TODO subclass + if ((*fv_SetWindowSubclass)(c->hwnd, singleSubclassProc, 0, c) == FALSE) + logLastError("error subclassing Windows control in uiWindowsNewControl()"); return (uiControl *) c; } diff --git a/ui_windows.h b/ui_windows.h index c2a21b48..330b7cba 100644 --- a/ui_windows.h +++ b/ui_windows.h @@ -19,7 +19,7 @@ struct uiWindowsNewControlParams { // These are called when the control sends a WM_COMMAND or WM_NOTIFY (respectively) to its parent. // ui redirects the message back and calls these functions. - // Store the result in *lResult and return TRUE to return the given result; return FALSE to pass the notification up to your window procedure. + // Store the result in *lResult and return any non-FALSE value (such as TRUE) to return the given result; return FALSE to pass the notification up to your window procedure. // Note that these are only issued if they come from the uiControl itself; notifications from children of the uiControl (such as a header control) will be received normally. BOOL (*onWM_COMMAND)(uiControl *c, WPARAM wParam, LPARAM lParam, void *data, LRESULT *lResult); BOOL (*onWM_NOTIFY)(uiControl *c, WPARAM wParam, LPARAM lParam, void *data, LRESULT *lResult);