[gtk+] testgtk: Make dialogs example work without static variable
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] testgtk: Make dialogs example work without static variable
- Date: Thu, 10 Apr 2014 15:09:20 +0000 (UTC)
commit 4f7a972aacbfc04f231a970c6be8ce86608be57c
Author: Benjamin Otte <otte redhat com>
Date: Thu Apr 10 16:16:41 2014 +0200
testgtk: Make dialogs example work without static variable
Makes it a bit more complicated, but meh.
tests/testgtk.c | 29 +++++++++++++++++++++--------
1 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/tests/testgtk.c b/tests/testgtk.c
index a6232f9..5827bb5 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;
+
+ 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;
+ }
+ }
- if (label == NULL)
+ /* 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]