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:
parent
89d584cdcd
commit
55fe50463f
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)))
|
||||
|
|
Loading…
Reference in New Issue