From f5314dbc9e90b0a0d805f16838a6318201250285 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 14 Jun 2008 22:55:17 +0200 Subject: [PATCH] widgets: add destructors functions Signed-off-by: Julien Danjou --- widgets/graph.c | 25 ++++++++++++++++++++++++- widgets/iconbox.c | 20 +++++++++++++++----- widgets/progressbar.c | 21 ++++++++++++++++++++- widgets/taglist.c | 22 +++++++++++++++++++++- widgets/tasklist.c | 24 ++++++++++++++++++------ widgets/textbox.c | 9 +++++++++ 6 files changed, 107 insertions(+), 14 deletions(-) diff --git a/widgets/graph.c b/widgets/graph.c index 1a9cef76..811b5a84 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -71,7 +71,18 @@ struct graph_t graph_t *next, *prev; }; -DO_SLIST(graph_t, graph, p_delete) +static void +graph_delete(graph_t **g) +{ + p_delete(&(*g)->title); + p_delete(&(*g)->lines); + p_delete(&(*g)->values); + p_delete(&(*g)->pcolor_center); + p_delete(&(*g)->pcolor_end); + p_delete(g); +} + +DO_SLIST(graph_t, graph, graph_delete) typedef struct { @@ -431,6 +442,17 @@ graph_tell(widget_t *widget, const char *property, const char *new_value) return WIDGET_NOERROR; } +static void +graph_destructor(widget_t *widget) +{ + graph_data_t *d = widget->data; + + graph_list_wipe(&d->graphs); + p_delete(&d->draw_from); + p_delete(&d->draw_to); + p_delete(&d); +} + widget_t * graph_new(alignment_t align) { @@ -442,6 +464,7 @@ graph_new(alignment_t align) w->draw = graph_draw; w->tell = graph_tell; + w->destructor = graph_destructor; w->align = align; d = w->data = p_new(graph_data_t, 1); diff --git a/widgets/iconbox.c b/widgets/iconbox.c index 41cb45d3..432f2366 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -26,7 +26,7 @@ typedef struct { draw_image_t *image; bool resize; -} Data; +} iconbox_data_t; static int iconbox_draw(draw_context_t *ctx, int screen __attribute__ ((unused)), @@ -35,7 +35,7 @@ iconbox_draw(draw_context_t *ctx, int screen __attribute__ ((unused)), int used __attribute__ ((unused)), void *p __attribute__ ((unused))) { - Data *d = w->widget->data; + iconbox_data_t *d = w->widget->data; draw_image_t *image = d->image; /* image not valid */ @@ -68,7 +68,7 @@ iconbox_draw(draw_context_t *ctx, int screen __attribute__ ((unused)), static widget_tell_status_t iconbox_tell(widget_t *widget, const char *property, const char *new_value) { - Data *d = widget->data; + iconbox_data_t *d = widget->data; if(!new_value) return WIDGET_ERROR_NOVALUE; @@ -86,18 +86,28 @@ iconbox_tell(widget_t *widget, const char *property, const char *new_value) return WIDGET_NOERROR; } +static void +iconbox_destructor(widget_t *widget) +{ + iconbox_data_t *d = widget->data; + + draw_image_delete(&d->image); + p_delete(&d); +} + widget_t * iconbox_new(alignment_t align) { widget_t *w; - Data *d; + iconbox_data_t *d; w = p_new(widget_t, 1); widget_common_new(w); w->align = align; w->draw = iconbox_draw; w->tell = iconbox_tell; - w->data = d = p_new(Data, 1); + w->destructor = iconbox_destructor; + w->data = d = p_new(iconbox_data_t, 1); d->resize = true; return w; diff --git a/widgets/progressbar.c b/widgets/progressbar.c index 7d2c0b32..d9b7b018 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -55,7 +55,16 @@ struct bar_t bar_t *next, *prev; }; -DO_SLIST(bar_t, bar, p_delete) +static void +bar_delete(bar_t **bar) +{ + p_delete(&(*bar)->title); + p_delete(&(*bar)->pfg_center); + p_delete(&(*bar)->pfg_end); + p_delete(bar); +} + +DO_SLIST(bar_t, bar, bar_delete) typedef struct { @@ -494,6 +503,15 @@ progressbar_tell(widget_t *widget, const char *property, const char *new_value) return WIDGET_NOERROR; } +static void +progressbar_destructor(widget_t *widget) +{ + progressbar_data_t *d = widget->data; + + bar_list_wipe(&d->bars); + p_delete(&d); +} + widget_t * progressbar_new(alignment_t align) { @@ -505,6 +523,7 @@ progressbar_new(alignment_t align) w->align = align; w->draw = progressbar_draw; w->tell = progressbar_tell; + w->destructor = progressbar_destructor; d = w->data = p_new(progressbar_data_t, 1); d->height = 0.80; diff --git a/widgets/taglist.c b/widgets/taglist.c index b61875b3..20943963 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -37,7 +37,14 @@ struct taglist_drawn_area_t taglist_drawn_area_t *next, *prev; }; -DO_SLIST(taglist_drawn_area_t, taglist_drawn_area, p_delete); +static void +taglist_drawn_area_delete(taglist_drawn_area_t **a) +{ + area_list_wipe(&(*a)->area); + p_delete(a); +} + +DO_SLIST(taglist_drawn_area_t, taglist_drawn_area, taglist_drawn_area_delete); typedef struct { @@ -259,6 +266,18 @@ taglist_tell(widget_t *widget, const char *property, const char *new_value) return WIDGET_NOERROR; } +static void +taglist_destructor(widget_t *widget) +{ + taglist_data_t *d = widget->data; + + p_delete(&d->text_normal); + p_delete(&d->text_focus); + p_delete(&d->text_urgent); + taglist_drawn_area_list_wipe(&d->drawn_area); + p_delete(&d); +} + widget_t * taglist_new(alignment_t align) { @@ -271,6 +290,7 @@ taglist_new(alignment_t align) w->draw = taglist_draw; w->button_press = taglist_button_press; w->tell = taglist_tell; + w->destructor = taglist_destructor; w->data = d = p_new(taglist_data_t, 1); d->text_normal = a_strdup(" "); diff --git a/widgets/tasklist.c b/widgets/tasklist.c index fbd99093..ca8b2101 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -43,7 +43,7 @@ typedef struct showclient_t show; bool show_icons; char *text_normal, *text_urgent, *text_focus; -} Data; +} tasklist_data_t; static inline bool tasklist_isvisible(client_t *c, int screen, showclient_t show) @@ -69,7 +69,7 @@ tasklist_draw(draw_context_t *ctx, int screen, int offset, int used, void *q __attribute__ ((unused))) { client_t *c; - Data *d = w->widget->data; + tasklist_data_t *d = w->widget->data; area_t area; char *text; int n = 0, i = 0, box_width = 0, icon_width = 0, box_width_rest = 0, j = 0; @@ -205,7 +205,7 @@ tasklist_button_press(widget_node_t *w, { button_t *b; client_t *c; - Data *d = w->widget->data; + tasklist_data_t *d = w->widget->data; int n = 0, box_width = 0, i, ci = 0; for(c = globalconf.clients; c; c = c->next) @@ -242,7 +242,7 @@ tasklist_button_press(widget_node_t *w, static widget_tell_status_t tasklist_tell(widget_t *widget, const char *property, const char *new_value) { - Data *d = widget->data; + tasklist_data_t *d = widget->data; if(!a_strcmp(property, "text_normal")) { @@ -278,19 +278,31 @@ tasklist_tell(widget_t *widget, const char *property, const char *new_value) return WIDGET_NOERROR; } +static void +tasklist_destructor(widget_t *widget) +{ + tasklist_data_t *d = widget->data; + + p_delete(&d->text_normal); + p_delete(&d->text_focus); + p_delete(&d->text_urgent); + p_delete(&d); +} + widget_t * tasklist_new(alignment_t align __attribute__ ((unused))) { widget_t *w; - Data *d; + tasklist_data_t *d; w = p_new(widget_t, 1); widget_common_new(w); w->draw = tasklist_draw; w->button_press = tasklist_button_press; w->align = AlignFlex; - w->data = d = p_new(Data, 1); + w->data = d = p_new(tasklist_data_t, 1); w->tell = tasklist_tell; + w->destructor = tasklist_destructor; d->text_normal = a_strdup(" <title/> "); d->text_focus = a_strdup(" <title/> "); diff --git a/widgets/textbox.c b/widgets/textbox.c index 061c77e8..83f92f0f 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -83,6 +83,14 @@ textbox_tell(widget_t *widget, const char *property, const char *new_value) return WIDGET_NOERROR; } +static void +textbox_destructor(widget_t *w) +{ + textbox_data_t *d = w->data; + p_delete(&d->text); + p_delete(&d); +} + widget_t * textbox_new(alignment_t align) { @@ -94,6 +102,7 @@ textbox_new(alignment_t align) w->align = align; w->draw = textbox_draw; w->tell = textbox_tell; + w->destructor = textbox_destructor; w->data = d = p_new(textbox_data_t, 1); return w;