Re: Outstanding patches, #58609



----- Original Message -----
From: "Owen Taylor" <otaylor redhat com>
To: "Matthias Clasen" <matthiasc poet de>
Cc: <gtk-devel-list gnome org>
Sent: Tuesday, August 07, 2001 11:43 PM
Subject: Re: Outstanding patches, #58609


>
> This has two problems:
>
>  - g_object_class_list_properties() returns allocated memory.
>
>  - g_object_class_list_properties() lists all the properties
>    for the class and its parents, not just the ones you
>    want.
>
>    What you need to do is in create_prop_editor() when type == 0:
>    create all the pages in the notebook, call
>    g_object_class_list_properties(), sort the results by name,
>    and then iterate through them adding them to the appropriate
>    page based on param_spec->owner_type.
>
>    For type != 0, you want to just find the properties
>    where param_spec->owner_type == type.
>

Here is a new patch, hopefully addressing the issues. Less efficient than
what you propose for type == 0, since we
repeatedly allocate and free the params, but that should not be a problem, I
guess. There is also a simple typo fix thrown in.

Matthias

Index: tests/prop-editor.c
===================================================================
RCS file: /cvs/gnome/gtk+/tests/prop-editor.c,v
retrieving revision 1.5
diff -u -r1.5 prop-editor.c
--- tests/prop-editor.c 2001/06/28 17:12:40 1.5
+++ tests/prop-editor.c 2001/08/08 08:23:16
@@ -23,21 +23,6 @@

 #include "prop-editor.h"

-static void
-get_param_specs (GType         type,
-                 GParamSpec ***specs,
-                 gint         *n_specs)
-{
-  GObjectClass *class = g_type_class_peek (type);
-
-  /* We count on the fact we have an instance, or else we'd have
-   * to use g_type_class_ref ();
-   */
-
-  /* Use private interface for now, fix later */
-  *specs = NULL; /* class->property_specs; */
-  *n_specs = 0; /* class->n_property_specs; */
-}

 typedef struct
 {
@@ -446,7 +431,7 @@
     name = g_type_name (G_TYPE_FROM_INSTANCE (obj));
   else
     name = "unknown";
-  str = g_strdup_printf ("Objetct: %p (%s)", obj, name);
+  str = g_strdup_printf ("Object: %p (%s)", obj, name);

   gtk_label_set_text (label, str);
   g_free (str);
@@ -670,12 +655,14 @@
   GtkWidget *sw;
   GtkWidget *vbox;
   GtkWidget *table;
+  GObjectClass *class;
+  GParamSpec **specs;
+  gint n_specs;
   int i;
-  gint n_specs = 0;
-  GParamSpec **specs = NULL;

-  get_param_specs (type, &specs, &n_specs);
-
+  class = g_type_class_peek (type);
+  specs = g_object_class_list_properties (class, &n_specs);
+
   if (n_specs == 0)
     return NULL;

@@ -701,6 +688,13 @@
           continue;
         }

+      if (spec->owner_type != type)
+ {
+   /* we're only interested in params of type */
+   ++i;
+   continue;
+ }
+
       label = gtk_label_new (spec->nick);
       gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
       gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, i, i + 1);
@@ -732,6 +726,9 @@
                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);

   gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), vbox);
+
+  g_free (specs);
+
   return sw;
 }

@@ -771,7 +768,7 @@
       gtk_container_add (GTK_CONTAINER (win), notebook);

       type = G_TYPE_FROM_INSTANCE (object);
-
+
       title = g_strdup_printf ("Properties of %s widget", g_type_name
(type));
       gtk_window_set_title (GTK_WINDOW (win), title);
       g_free (title);







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