]> Pileus Git - ~andy/gtk/blobdiff - tests/prop-editor.c
Don't leak the tooltip object.
[~andy/gtk] / tests / prop-editor.c
index 851f700a6b0adbbbaaaa46117aa54269bc8bd2d2..0dc055b3d9d755218584ed4d07e354ed66c66e14 100644 (file)
@@ -17,6 +17,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#include <config.h>
 #include <string.h>
 
 #undef GTK_DISABLE_DEPRECATED
@@ -430,6 +431,7 @@ object_changed (GObject *object, GParamSpec *pspec, gpointer data)
   label = GTK_WIDGET (children->data);
   button = GTK_WIDGET (children->next->data);
   g_object_get (object, pspec->name, &obj, NULL);
+  g_list_free (children);
 
   if (obj)
     name = g_type_name (G_TYPE_FROM_INSTANCE (obj));
@@ -686,13 +688,20 @@ properties_from_type (GObject     *object,
   GtkWidget *sw;
   GtkWidget *vbox;
   GtkWidget *table;
-  GObjectClass *class;
   GParamSpec **specs;
   gint n_specs;
   int i;
 
-  class = G_OBJECT_CLASS (g_type_class_peek (type));
-  specs = g_object_class_list_properties (class, &n_specs);
+  if (G_TYPE_IS_INTERFACE (type))
+    {
+      gpointer vtable = g_type_default_interface_peek (type);
+      specs = g_object_interface_list_properties (vtable, &n_specs);
+    }
+  else
+    {
+      GObjectClass *class = G_OBJECT_CLASS (g_type_class_peek (type));
+      specs = g_object_class_list_properties (class, &n_specs);
+    }
         
   if (n_specs == 0)
     return NULL;
@@ -763,6 +772,12 @@ properties_from_type (GObject     *object,
   return sw;
 }
 
+static void
+kill_tips (GtkWindow *win, GtkObject *tips)
+{
+  gtk_object_destroy (tips);
+  g_object_unref (tips);
+}
 
 /* Pass zero for type if you want all properties */
 GtkWidget*
@@ -775,7 +790,9 @@ create_prop_editor (GObject   *object,
   GtkWidget *properties;
   GtkWidget *label;
   gchar *title;
-
+  GType *ifaces;
+  guint n_ifaces;
+  
   if ((win = g_object_get_data (G_OBJECT (object), "prop-editor-win")))
     {
       gtk_window_present (GTK_WINDOW (win));
@@ -786,10 +803,13 @@ create_prop_editor (GObject   *object,
   if (GTK_IS_WIDGET (object))
     gtk_window_set_screen (GTK_WINDOW (win),
                           gtk_widget_get_screen (GTK_WIDGET (object)));
-  
+
   tips = gtk_tooltips_new ();
-  g_signal_connect_swapped (win, "destroy",
-                           G_CALLBACK (gtk_object_destroy), tips);
+  g_object_ref (tips);
+  gtk_object_sink (GTK_OBJECT (tips));
+
+  /* Kill the tips when the widget goes away.  */
+  g_signal_connect (G_OBJECT (win), "destroy", G_CALLBACK (kill_tips), tips);
 
   /* hold a weak ref to the object we're editing */
   g_object_set_data_full (G_OBJECT (object), "prop-editor-win", win, model_destroy);
@@ -820,6 +840,20 @@ create_prop_editor (GObject   *object,
          
          type = g_type_parent (type);
        }
+
+      ifaces = g_type_interfaces (G_TYPE_FROM_INSTANCE (object), &n_ifaces);
+      while (n_ifaces--)
+       {
+         properties = properties_from_type (object, ifaces[n_ifaces], tips);
+         if (properties)
+           {
+             label = gtk_label_new (g_type_name (ifaces[n_ifaces]));
+             gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
+                                       properties, label);
+           }
+       }
+
+      g_free (ifaces);
     }
   else
     {
@@ -827,6 +861,7 @@ create_prop_editor (GObject   *object,
       gtk_container_add (GTK_CONTAINER (win), properties);
       title = g_strdup_printf ("Properties of %s", g_type_name (type));
       gtk_window_set_title (GTK_WINDOW (win), title);
+      g_free (title);
     }
   
   gtk_window_set_default_size (GTK_WINDOW (win), -1, 400);