[gtk/stack-fixes: 11/13] stack: Use gtk_single_selection_get_selected_item



commit b715d59c4dc807c5517416fb7bce7fbbf7f91002
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 9 13:07:50 2019 -0500

    stack: Use gtk_single_selection_get_selected_item
    
    Use this api where it makes sense, and fix memory
    leaks related to g_list_model_get_item.

 gtk/gtkstack.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index 99b6bd103c..369376faf1 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -2223,18 +2223,21 @@ transform_to (GBinding *binding,
   GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
   GtkWidget *child;
   guint i;
+  guint pos = GTK_INVALID_LIST_POSITION;
 
   child = g_value_get_object (from_value);
   for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (priv->pages)); i++)
     {
-      if (g_list_model_get_item (G_LIST_MODEL (priv->pages), i) == child)
-        {
-          g_value_set_uint (to_value, i);
-          return TRUE;
-        }
+      GtkWidget *widget;
+      widget = g_list_model_get_item (G_LIST_MODEL (priv->pages), i);
+      if (widget == child)
+        pos = i;
+      g_object_unref (widget);
+      if (pos != GTK_INVALID_LIST_POSITION)
+        break;
     }
 
-  g_value_set_uint (to_value, GTK_INVALID_LIST_POSITION);
+  g_value_set_uint (to_value, pos);
   return TRUE;
 }
 
@@ -2254,6 +2257,7 @@ transform_from (GBinding *binding,
       GtkWidget *child;
       child = g_list_model_get_item (G_LIST_MODEL (priv->pages), selected);
       g_value_set_object (to_value, child);
+      g_object_unref (child);
       return TRUE;
     }
   else


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]