From 4f7a972aacbfc04f231a970c6be8ce86608be57c Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 10 Apr 2014 16:16:41 +0200 Subject: [PATCH] testgtk: Make dialogs example work without static variable Makes it a bit more complicated, but meh. --- tests/testgtk.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/testgtk.c b/tests/testgtk.c index a6232f94e5..5827bb5a04 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -5416,21 +5416,34 @@ static GtkWidget *dialog_window = NULL; static void label_toggle (GtkWidget *widget) { - static GtkWidget *label = NULL; + GtkWidget *content_area; + GList *l, *children; - if (label == NULL) + content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog_window)); + children = gtk_container_get_children (GTK_CONTAINER (content_area)); + + for (l = children; l; l = l->next) { + if (GTK_IS_LABEL (l->data)) + { + gtk_container_remove (GTK_CONTAINER (content_area), l->data); + break; + } + } + + /* no label removed, so add one */ + if (l == NULL) + { + GtkWidget *label; + label = gtk_label_new ("Dialog Test"); g_object_set (label, "margin", 10, NULL); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog_window))), + gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0); gtk_widget_show (label); } - else - { - gtk_widget_destroy (label); - label = NULL; - } + + g_list_free (children); } static void