diff --git a/ui_windows.h b/ui_windows.h index f2bfd4bd..8bd8c8c4 100644 --- a/ui_windows.h +++ b/ui_windows.h @@ -28,8 +28,10 @@ struct uiWindowsNewControlParams { BOOL (*onWM_COMMAND)(uiControl *c, WORD code, LRESULT *lResult); // TODO set idFrom to 0? BOOL (*onWM_NOTIFY)(uiControl *c, NMHDR *nm, LRESULT *lResult); - // This is called in WM_DESTROY. - void (*onWM_DESTROY)(uiControl *c); + + // This is called when the widget is ready to be destroyed. + void (*onDestroy)(void *data); + void *onDestroyData; }; void uiWindowsNewControl(uiControl *c, uiWindowsNewControlParams *p); diff --git a/windows/button.c b/windows/button.c index 42a5f0e7..0f0b2d93 100644 --- a/windows/button.c +++ b/windows/button.c @@ -24,9 +24,9 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult) return FALSE; } -static void onWM_DESTROY(uiControl *c) +static void onDestroy(void *data) { - struct button *b = (struct button *) c; + struct button *b = (struct button *) data; uiFree(b); } @@ -95,7 +95,8 @@ uiButton *uiNewButton(const char *text) p.useStandardControlFont = TRUE; p.onWM_COMMAND = onWM_COMMAND; p.onWM_NOTIFY = onWM_NOTIFY; - p.onWM_DESTROY = onWM_DESTROY; + p.onDestroy = onDestroy; + p.onDestroyData = b; uiWindowsNewControl(uiControl(b), &p); uiFree(wtext); diff --git a/windows/checkbox.c b/windows/checkbox.c index 08c31f0e..5d39622a 100644 --- a/windows/checkbox.c +++ b/windows/checkbox.c @@ -32,9 +32,9 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult) return FALSE; } -static void onWM_DESTROY(uiControl *cc) +static void onDestroy(void *data) { - struct checkbox *c = (struct checkbox *) cc; + struct checkbox *c = (struct checkbox *) data; uiFree(c); } @@ -110,7 +110,8 @@ uiCheckbox *uiNewCheckbox(const char *text) p.useStandardControlFont = TRUE; p.onWM_COMMAND = onWM_COMMAND; p.onWM_NOTIFY = onWM_NOTIFY; - p.onWM_DESTROY = onWM_DESTROY; + p.onDestroy = onDestroy; + p.onDestroyData = c; uiWindowsNewControl(uiControl(c), &p); uiFree(wtext); diff --git a/windows/entry.c b/windows/entry.c index 2a3630ee..2aa066a2 100644 --- a/windows/entry.c +++ b/windows/entry.c @@ -16,9 +16,9 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult) return FALSE; } -static void onWM_DESTROY(uiControl *c) +static void onDestroy(void *data) { - struct entry *e = (struct entry *) c; + struct entry *e = (struct entry *) data; uiFree(e); } @@ -58,7 +58,8 @@ uiEntry *uiNewEntry(void) p.useStandardControlFont = TRUE; p.onWM_COMMAND = onWM_COMMAND; p.onWM_NOTIFY = onWM_NOTIFY; - p.onWM_DESTROY = onWM_DESTROY; + p.onDestroy = onDestroy; + p.onDestroyData = e; uiWindowsNewControl(uiControl(e), &p); e->hwnd = HWND(e); diff --git a/windows/label.c b/windows/label.c index 066b2271..916d0ca8 100644 --- a/windows/label.c +++ b/windows/label.c @@ -16,9 +16,9 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult) return FALSE; } -static void onWM_DESTROY(uiControl *c) +static void onDestroy(void *data) { - struct label *l = (struct label *) c; + struct label *l = (struct label *) data; uiFree(l); } @@ -63,7 +63,8 @@ uiLabel *uiNewLabel(const char *text) p.useStandardControlFont = TRUE; p.onWM_COMMAND = onWM_COMMAND; p.onWM_NOTIFY = onWM_NOTIFY; - p.onWM_DESTROY = onWM_DESTROY; + p.onDestroy = onDestroy; + p.onDestroyData = l; uiWindowsNewControl(uiControl(l), &p); uiFree(wtext); diff --git a/windows/newcontrol.c b/windows/newcontrol.c index 059a34db..4c4d89da 100644 --- a/windows/newcontrol.c +++ b/windows/newcontrol.c @@ -7,7 +7,8 @@ struct singleHWND { HWND hwnd; BOOL (*onWM_COMMAND)(uiControl *, WORD, LRESULT *); BOOL (*onWM_NOTIFY)(uiControl *, NMHDR *, LRESULT *); - void (*onWM_DESTROY)(uiControl *); + void (*onDestroy)(void *); + void *onDestroyData; uiParent *parent; BOOL userHid; BOOL containerHid; @@ -165,7 +166,7 @@ static LRESULT CALLBACK singleSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, case WM_DESTROY: if (!s->canDestroy) complain("trying to destroy control with singleWidget at %p before uiControlDestroy()", s); - (*(s->onWM_DESTROY))(c); + (*(s->onDestroy))(s->onDestroyData); uiFree(s); break; case WM_NCDESTROY: @@ -192,7 +193,9 @@ void uiWindowsNewControl(uiControl *c, uiWindowsNewControlParams *p) logLastError("error creating control in uiWindowsNewControl()"); s->onWM_COMMAND = p->onWM_COMMAND; s->onWM_NOTIFY = p->onWM_NOTIFY; - s->onWM_DESTROY = p->onWM_DESTROY; + + s->onDestroy = p->onDestroy; + s->onDestroyData = p->onDestroyData; c->Destroy = singleDestroy; c->Handle = singleHandle; diff --git a/windows/tab.c b/windows/tab.c index 39e52e40..5cb1619d 100644 --- a/windows/tab.c +++ b/windows/tab.c @@ -45,9 +45,9 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult) return FALSE; } -static void onWM_DESTROY(uiControl *c) +static void onDestroy(void *data) { - struct tab *t = (struct tab *) c; + struct tab *t = (struct tab *) data; uintmax_t i; for (i = 0; i < t->len; i++) @@ -194,7 +194,8 @@ uiTab *uiNewTab(void) p.useStandardControlFont = TRUE; p.onWM_COMMAND = onWM_COMMAND; p.onWM_NOTIFY = onWM_NOTIFY; - p.onWM_DESTROY = onWM_DESTROY; + p.onDestroy = onDestroy; + p.onDestroyData = t; uiWindowsNewControl(uiControl(t), &p); t->hwnd = HWND(t); diff --git a/windows/uipriv_windows.h b/windows/uipriv_windows.h index 929d0e52..1165a865 100644 --- a/windows/uipriv_windows.h +++ b/windows/uipriv_windows.h @@ -34,6 +34,7 @@ enum { msgCOMMAND = WM_APP + 0x40, // start offset just to be safe msgNOTIFY, msgUpdateChild, // fake because Windows seems to SWP_NOSIZE MoveWindow()s and SetWindowPos()s that don't change the window size (even if SWP_NOSIZE isn't specified) + msgCanDestroyNow, }; #define HWND(c) ((HWND) uiControlHandle(uiControl(c)))