[gtk+/gtk-3-16] search bar: Clean up weak pointer handling
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-16] search bar: Clean up weak pointer handling
- Date: Mon, 23 Mar 2015 03:14:57 +0000 (UTC)
commit 111a84bd1c9b405f1de407e2ff1f352ecab6b485
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 22 11:46:16 2015 -0400
search bar: Clean up weak pointer handling
Break out a setter that manages the weak pointer, and
use it in finalize. This also fixes a bug where we were
forgetting to disconnect the right signal handler in
some cases.
gtk/gtksearchbar.c | 60 +++++++++++++++++++++++++++------------------------
1 files changed, 32 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtksearchbar.c b/gtk/gtksearchbar.c
index d1b3f3c..97d48d1 100644
--- a/gtk/gtksearchbar.c
+++ b/gtk/gtksearchbar.c
@@ -344,18 +344,15 @@ gtk_search_bar_get_property (GObject *object,
}
}
+static void gtk_search_bar_set_entry (GtkSearchBar *bar,
+ GtkEntry *entry);
+
static void
gtk_search_bar_dispose (GObject *object)
{
GtkSearchBar *bar = GTK_SEARCH_BAR (object);
- GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
- if (priv->entry)
- {
- g_signal_handlers_disconnect_by_func (priv->entry, entry_key_pressed_event_cb, bar);
- g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *) &priv->entry);
- priv->entry = NULL;
- }
+ gtk_search_bar_set_entry (bar, NULL);
G_OBJECT_CLASS (gtk_search_bar_parent_class)->dispose (object);
}
@@ -471,27 +468,12 @@ gtk_search_bar_new (void)
return g_object_new (GTK_TYPE_SEARCH_BAR, NULL);
}
-/**
- * gtk_search_bar_connect_entry:
- * @bar: a #GtkSearchBar
- * @entry: a #GtkEntry
- *
- * Connects the #GtkEntry widget passed as the one to be used in
- * this search bar. The entry should be a descendant of the search bar.
- * This is only required if the entry isn’t the direct child of the
- * search bar (as in our main example).
- *
- * Since: 3.10
- */
-void
-gtk_search_bar_connect_entry (GtkSearchBar *bar,
- GtkEntry *entry)
+static void
+gtk_search_bar_set_entry (GtkSearchBar *bar,
+ GtkEntry *entry)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
- g_return_if_fail (GTK_IS_SEARCH_BAR (bar));
- g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
-
if (priv->entry != NULL)
{
if (GTK_IS_SEARCH_ENTRY (priv->entry))
@@ -499,12 +481,12 @@ gtk_search_bar_connect_entry (GtkSearchBar *bar,
else
g_signal_handlers_disconnect_by_func (priv->entry, entry_key_pressed_event_cb, bar);
g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *) &priv->entry);
- priv->entry = NULL;
}
- if (entry != NULL)
+ priv->entry = GTK_WIDGET (entry);
+
+ if (priv->entry != NULL)
{
- priv->entry = GTK_WIDGET (entry);
g_object_add_weak_pointer (G_OBJECT (priv->entry), (gpointer *) &priv->entry);
if (GTK_IS_SEARCH_ENTRY (priv->entry))
g_signal_connect (priv->entry, "stop-search",
@@ -516,6 +498,28 @@ gtk_search_bar_connect_entry (GtkSearchBar *bar,
}
/**
+ * gtk_search_bar_connect_entry:
+ * @bar: a #GtkSearchBar
+ * @entry: a #GtkEntry
+ *
+ * Connects the #GtkEntry widget passed as the one to be used in
+ * this search bar. The entry should be a descendant of the search bar.
+ * This is only required if the entry isn’t the direct child of the
+ * search bar (as in our main example).
+ *
+ * Since: 3.10
+ */
+void
+gtk_search_bar_connect_entry (GtkSearchBar *bar,
+ GtkEntry *entry)
+{
+ g_return_if_fail (GTK_IS_SEARCH_BAR (bar));
+ g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
+
+ gtk_search_bar_set_entry (bar, entry);
+}
+
+/**
* gtk_search_bar_get_search_mode:
* @bar: a #GtkSearchBar
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]