Changed Windows onWM_DESTROY to a generic onDestroy handler with a data parameter. This will make decoupling widget destruction from WM_DESTROY (like we did on GTK+ by decoupling from ::destroy) easier.

This commit is contained in:
Pietro Gagliardi 2015-04-18 18:02:16 -04:00
parent 89d584cdcd
commit 55fe50463f
8 changed files with 31 additions and 20 deletions

View File

@ -28,8 +28,10 @@ struct uiWindowsNewControlParams {
BOOL (*onWM_COMMAND)(uiControl *c, WORD code, LRESULT *lResult); BOOL (*onWM_COMMAND)(uiControl *c, WORD code, LRESULT *lResult);
// TODO set idFrom to 0? // TODO set idFrom to 0?
BOOL (*onWM_NOTIFY)(uiControl *c, NMHDR *nm, LRESULT *lResult); 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); void uiWindowsNewControl(uiControl *c, uiWindowsNewControlParams *p);

View File

@ -24,9 +24,9 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
return FALSE; 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); uiFree(b);
} }
@ -95,7 +95,8 @@ uiButton *uiNewButton(const char *text)
p.useStandardControlFont = TRUE; p.useStandardControlFont = TRUE;
p.onWM_COMMAND = onWM_COMMAND; p.onWM_COMMAND = onWM_COMMAND;
p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_NOTIFY = onWM_NOTIFY;
p.onWM_DESTROY = onWM_DESTROY; p.onDestroy = onDestroy;
p.onDestroyData = b;
uiWindowsNewControl(uiControl(b), &p); uiWindowsNewControl(uiControl(b), &p);
uiFree(wtext); uiFree(wtext);

View File

@ -32,9 +32,9 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
return FALSE; 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); uiFree(c);
} }
@ -110,7 +110,8 @@ uiCheckbox *uiNewCheckbox(const char *text)
p.useStandardControlFont = TRUE; p.useStandardControlFont = TRUE;
p.onWM_COMMAND = onWM_COMMAND; p.onWM_COMMAND = onWM_COMMAND;
p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_NOTIFY = onWM_NOTIFY;
p.onWM_DESTROY = onWM_DESTROY; p.onDestroy = onDestroy;
p.onDestroyData = c;
uiWindowsNewControl(uiControl(c), &p); uiWindowsNewControl(uiControl(c), &p);
uiFree(wtext); uiFree(wtext);

View File

@ -16,9 +16,9 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
return FALSE; 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); uiFree(e);
} }
@ -58,7 +58,8 @@ uiEntry *uiNewEntry(void)
p.useStandardControlFont = TRUE; p.useStandardControlFont = TRUE;
p.onWM_COMMAND = onWM_COMMAND; p.onWM_COMMAND = onWM_COMMAND;
p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_NOTIFY = onWM_NOTIFY;
p.onWM_DESTROY = onWM_DESTROY; p.onDestroy = onDestroy;
p.onDestroyData = e;
uiWindowsNewControl(uiControl(e), &p); uiWindowsNewControl(uiControl(e), &p);
e->hwnd = HWND(e); e->hwnd = HWND(e);

View File

@ -16,9 +16,9 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
return FALSE; 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); uiFree(l);
} }
@ -63,7 +63,8 @@ uiLabel *uiNewLabel(const char *text)
p.useStandardControlFont = TRUE; p.useStandardControlFont = TRUE;
p.onWM_COMMAND = onWM_COMMAND; p.onWM_COMMAND = onWM_COMMAND;
p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_NOTIFY = onWM_NOTIFY;
p.onWM_DESTROY = onWM_DESTROY; p.onDestroy = onDestroy;
p.onDestroyData = l;
uiWindowsNewControl(uiControl(l), &p); uiWindowsNewControl(uiControl(l), &p);
uiFree(wtext); uiFree(wtext);

View File

@ -7,7 +7,8 @@ struct singleHWND {
HWND hwnd; HWND hwnd;
BOOL (*onWM_COMMAND)(uiControl *, WORD, LRESULT *); BOOL (*onWM_COMMAND)(uiControl *, WORD, LRESULT *);
BOOL (*onWM_NOTIFY)(uiControl *, NMHDR *, LRESULT *); BOOL (*onWM_NOTIFY)(uiControl *, NMHDR *, LRESULT *);
void (*onWM_DESTROY)(uiControl *); void (*onDestroy)(void *);
void *onDestroyData;
uiParent *parent; uiParent *parent;
BOOL userHid; BOOL userHid;
BOOL containerHid; BOOL containerHid;
@ -165,7 +166,7 @@ static LRESULT CALLBACK singleSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
case WM_DESTROY: case WM_DESTROY:
if (!s->canDestroy) if (!s->canDestroy)
complain("trying to destroy control with singleWidget at %p before uiControlDestroy()", s); complain("trying to destroy control with singleWidget at %p before uiControlDestroy()", s);
(*(s->onWM_DESTROY))(c); (*(s->onDestroy))(s->onDestroyData);
uiFree(s); uiFree(s);
break; break;
case WM_NCDESTROY: case WM_NCDESTROY:
@ -192,7 +193,9 @@ void uiWindowsNewControl(uiControl *c, uiWindowsNewControlParams *p)
logLastError("error creating control in uiWindowsNewControl()"); logLastError("error creating control in uiWindowsNewControl()");
s->onWM_COMMAND = p->onWM_COMMAND; s->onWM_COMMAND = p->onWM_COMMAND;
s->onWM_NOTIFY = p->onWM_NOTIFY; s->onWM_NOTIFY = p->onWM_NOTIFY;
s->onWM_DESTROY = p->onWM_DESTROY;
s->onDestroy = p->onDestroy;
s->onDestroyData = p->onDestroyData;
c->Destroy = singleDestroy; c->Destroy = singleDestroy;
c->Handle = singleHandle; c->Handle = singleHandle;

View File

@ -45,9 +45,9 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
return FALSE; 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; uintmax_t i;
for (i = 0; i < t->len; i++) for (i = 0; i < t->len; i++)
@ -194,7 +194,8 @@ uiTab *uiNewTab(void)
p.useStandardControlFont = TRUE; p.useStandardControlFont = TRUE;
p.onWM_COMMAND = onWM_COMMAND; p.onWM_COMMAND = onWM_COMMAND;
p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_NOTIFY = onWM_NOTIFY;
p.onWM_DESTROY = onWM_DESTROY; p.onDestroy = onDestroy;
p.onDestroyData = t;
uiWindowsNewControl(uiControl(t), &p); uiWindowsNewControl(uiControl(t), &p);
t->hwnd = HWND(t); t->hwnd = HWND(t);

View File

@ -34,6 +34,7 @@ enum {
msgCOMMAND = WM_APP + 0x40, // start offset just to be safe msgCOMMAND = WM_APP + 0x40, // start offset just to be safe
msgNOTIFY, 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) 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))) #define HWND(c) ((HWND) uiControlHandle(uiControl(c)))