[libgd] GdTaggedEntry: Fix inserting tag when unmapped
- From: Volker Sobek <vsobek src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgd] GdTaggedEntry: Fix inserting tag when unmapped
- Date: Thu, 19 Dec 2013 22:51:57 +0000 (UTC)
commit b94302706ebe4a641e4c9137cc00e3c83db221c3
Author: Volker Sobek <reklov live com>
Date: Thu Dec 19 14:57:46 2013 +0100
GdTaggedEntry: Fix inserting tag when unmapped
When a GdTaggedEntryTag was inserted into an unmapped but realized
GdTaggedEntry, the tag's GDK window wasn't created. This resulted in a
drawing failure on showing the entry again. Fix this by making sure to
realize the tag at once if the entry is already realized.
Also enhance test-tagged-entry to allow testing this.
https://bugzilla.gnome.org/show_bug.cgi?id=712755
libgd/gd-tagged-entry.c | 8 +++---
test-tagged-entry.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 55 insertions(+), 6 deletions(-)
---
diff --git a/libgd/gd-tagged-entry.c b/libgd/gd-tagged-entry.c
index d0f3f26..023a82b 100644
--- a/libgd/gd-tagged-entry.c
+++ b/libgd/gd-tagged-entry.c
@@ -1020,11 +1020,11 @@ gd_tagged_entry_insert_tag (GdTaggedEntry *self,
self->priv->tags = g_list_insert (self->priv->tags, g_object_ref (tag), position);
+ if (gtk_widget_get_realized (GTK_WIDGET (self)))
+ gd_tagged_entry_tag_realize (tag, self);
+
if (gtk_widget_get_mapped (GTK_WIDGET (self)))
- {
- gd_tagged_entry_tag_realize (tag, self);
- gdk_window_show_unraised (tag->priv->window);
- }
+ gdk_window_show_unraised (tag->priv->window);
gtk_widget_queue_resize (GTK_WIDGET (self));
diff --git a/test-tagged-entry.c b/test-tagged-entry.c
index fa52bbb..0f583d9 100644
--- a/test-tagged-entry.c
+++ b/test-tagged-entry.c
@@ -1,6 +1,8 @@
#include <gtk/gtk.h>
#include <libgd/gd-tagged-entry.h>
+static GdTaggedEntryTag *toggle_tag;
+
static void
on_tag_clicked (GdTaggedEntry *entry,
GdTaggedEntryTag *tag,
@@ -17,17 +19,49 @@ on_tag_button_clicked (GdTaggedEntry *entry,
g_print ("tag button clicked: %s\n", gd_tagged_entry_tag_get_label (tag));
}
+static void
+on_toggle_visible (GtkButton *button,
+ GtkWidget *entry)
+{
+ gboolean active;
+
+ active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+ g_print ("%s tagged entry\n", active ? "show" : "hide");
+ gtk_widget_set_visible (entry, active);
+}
+
+static void
+on_toggle_tag (GtkButton *button,
+ GdTaggedEntry *entry)
+{
+ gboolean active;
+
+ active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+ if (active)
+ {
+ g_print ("adding tag 'Toggle Tag'\n");
+ gd_tagged_entry_insert_tag (entry, toggle_tag, 0);
+ }
+ else
+ {
+ g_print ("removing tag 'Toggle Tag'\n");
+ gd_tagged_entry_remove_tag (entry, toggle_tag);
+ }
+}
+
gint
main (gint argc,
gchar ** argv)
{
- GtkWidget *window, *box, *entry;
+ GtkWidget *window, *box, *entry, *toggle_visible_button, *toggle_tag_button;
GdTaggedEntryTag *tag;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_widget_set_size_request (window, 300, 300);
+ gtk_widget_set_size_request (window, 300, 0);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (window), box);
@@ -53,6 +87,21 @@ main (gint argc,
gd_tagged_entry_insert_tag (GD_TAGGED_ENTRY (entry), tag, 0);
g_object_unref (tag);
+ toggle_visible_button = gtk_toggle_button_new_with_label ("Visible");
+ gtk_widget_set_vexpand (toggle_visible_button, TRUE);
+ gtk_widget_set_valign (toggle_visible_button, GTK_ALIGN_END);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle_visible_button), TRUE);
+ g_signal_connect (toggle_visible_button, "toggled",
+ G_CALLBACK (on_toggle_visible), entry);
+ gtk_container_add (GTK_CONTAINER (box), toggle_visible_button);
+
+ toggle_tag = gd_tagged_entry_tag_new ("Toggle Tag");
+
+ toggle_tag_button = gtk_toggle_button_new_with_label ("Toggle Tag");
+ g_signal_connect (toggle_tag_button, "toggled",
+ G_CALLBACK (on_toggle_tag), entry);
+ gtk_container_add (GTK_CONTAINER (box), toggle_tag_button);
+
gtk_widget_show_all (window);
gtk_main ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]