return NULL;
}
co->data = bu;
+ co->destroyCallback = NULL;
bu->text = strdup(text);
bu->compact = compact;
co->ops = &cbOps;
co->callback = NULL;
+ co->destroyCallback = NULL;
co->height = 1;
co->width = wstrlen(text, -1) + 4;
co->top = top;
co = malloc(sizeof(*co));
ct = malloc(sizeof(struct CheckboxTree));
co->callback = NULL;
+ co->destroyCallback = NULL;
co->data = ct;
co->left = left;
co->top = top;
co->width = width;
co->isMapped = 0;
co->callback = NULL;
+ co->destroyCallback = NULL;
co->ops = &entryOps;
co->takesFocus = 0; /* we may have 0 components */
co->ops = &formOps;
+ co->destroyCallback = NULL;
form->help = help;
form->flags = flags;
return er;
}
+/* Destroy a component. Components which have been added to a form
+ * are destroyed when the form is destroyed; this is just for the
+ * (rare) case of components which for whatever reason weren't added
+ * to a form.
+ */
+void newtComponentDestroy(newtComponent co) {
+ /* If the user registered a destroy callback for this component,
+ * now is a good time to call it.
+ */
+ if (co->destroyCallback)
+ co->destroyCallback(co, co->destroyCallbackData);
+
+ if (co->ops->destroy) {
+ co->ops->destroy(co);
+ } else {
+ if (co->data) free(co->data);
+ free(co);
+ }
+}
+
/* this also destroys all of the components on the form */
void newtFormDestroy(newtComponent co) {
newtComponent subco;
/* first, destroy all of the components */
for (i = 0; i < form->numComps; i++) {
subco = form->elements[i].co;
- if (subco->ops->destroy) {
- subco->ops->destroy(subco);
- } else {
- if (subco->data) free(subco->data);
- free(subco);
- }
+ newtComponentDestroy(subco);
}
if (form->hotKeys) free(form->hotKeys);
co->callbackData = data;
}
+/* Add a callback which is called when the component is destroyed. */
+void newtComponentAddDestroyCallback(newtComponent co,
+ newtCallback f, void * data) {
+ co->destroyCallback = f;
+ co->destroyCallbackData = data;
+}
+
void newtComponentTakesFocus(newtComponent co, int val) {
co->takesFocus = val;
}
co = malloc(sizeof(*co));
la = malloc(sizeof(struct label));
co->data = la;
+ co->destroyCallback = NULL;
co->ops = &labelOps;
co->ops = &listboxOps;
co->takesFocus = 1;
co->callback = NULL;
+ co->destroyCallback = NULL;
updateWidth(co, li, 5);
newtSetColor;
newtPopWindowNoRefresh;
} NEWT_0.52;
+
+NEWT_0.52.9 {
+ global:
+ newtComponentAddDestroyCallback;
+ newtComponentDestroy;
+} NEWT_0.52.6;
void newtComponentAddCallback(newtComponent co, newtCallback f, void * data);
void newtComponentTakesFocus(newtComponent co, int val);
+/* This callback is called when a component is destroyed. */
+void newtComponentAddDestroyCallback(newtComponent co,
+ newtCallback f, void * data);
+
/* this also destroys all of the components (including other forms) on the
form */
void newtFormDestroy(newtComponent form);
+/* NB: You SHOULD NOT call this for components which have been added
+ * to a form (ie. almost all components). They are destroyed along
+ * with the form when you call newtFormDestroy.
+ */
+void newtComponentDestroy(newtComponent co);
+
/* Key codes */
#define NEWT_KEY_TAB '\t'
newtCallback callback;
void * callbackData;
+ newtCallback destroyCallback;
+ void * destroyCallbackData;
+
void * data;
} ;
co = malloc(sizeof(*co));
sc = malloc(sizeof(struct scale));
co->data = sc;
+ co->destroyCallback = NULL;
co->ops = &scaleOps;
co = malloc(sizeof(*co));
sb = malloc(sizeof(*sb));
co->data = sb;
+ co->destroyCallback = NULL;
if (height >= 2) {
sb->arrows = 1;
co->left = left;
co->takesFocus = 0;
co->width = width;
+ co->destroyCallback = NULL;
tb->doWrap = flags & NEWT_FLAG_WRAP;
tb->numLines = 0;