Add a special EVT_DESTRUCT event to give event handlers a chance to clean-up/free any resources they have allocated.
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5757 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
571f019dbf
commit
54df5e1b9e
|
@ -206,11 +206,18 @@ void widgetInit(widget *self, const char *id)
|
|||
|
||||
void widgetDestroyImpl(widget *self)
|
||||
{
|
||||
eventTableEntry *currEntry;
|
||||
|
||||
// Release the container
|
||||
vectorMapAndDestroy(self->children, (mapCallback) widgetDestroy);
|
||||
|
||||
// Release the event handler table
|
||||
vectorMapAndDestroy(self->eventVtbl, free);
|
||||
while ((currEntry = vectorHead(self->eventVtbl)))
|
||||
{
|
||||
widgetRemoveEventHandler(self, currEntry->id);
|
||||
}
|
||||
|
||||
vectorDestroy(self->eventVtbl);
|
||||
|
||||
// Destroy the cairo context
|
||||
cairo_destroy(self->cr);
|
||||
|
@ -486,6 +493,17 @@ void widgetRemoveEventHandlerImpl(widget *self, int id)
|
|||
// If the handler matches, remove it
|
||||
if (handler->id == id)
|
||||
{
|
||||
// Generate an EVT_DESTRUCT event to allow the handler to clean-up
|
||||
eventMisc evtDestruct;
|
||||
evtDestruct.event.type = EVT_DESTRUCT;
|
||||
|
||||
handler->callback(self, (event *) &evtDestruct, handler->id,
|
||||
handler->userData);
|
||||
|
||||
// Release the handler
|
||||
free(handler);
|
||||
|
||||
// Finally, remove the event handler from the table
|
||||
vectorRemoveAt(self->eventVtbl, i);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,9 @@ typedef enum
|
|||
|
||||
// Misc
|
||||
EVT_FOCUS,
|
||||
EVT_BLUR
|
||||
EVT_BLUR,
|
||||
|
||||
EVT_DESTRUCT
|
||||
} eventType;
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue