]> Pileus Git - ~andy/gtk/blob - tests/prop-editor.c
param spec fix
[~andy/gtk] / tests / prop-editor.c
1 /* prop-editor.c
2  * Copyright (C) 2000  Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <string.h>
21
22 #include <gtk/gtk.h>
23
24 #include "prop-editor.h"
25
26
27 typedef struct
28 {
29   gpointer instance;
30   GObject *alive_object;
31   guint id;
32 } DisconnectData;
33
34 static void
35 disconnect_func (gpointer data)
36 {
37   DisconnectData *dd = data;
38   
39   g_signal_handler_disconnect (dd->instance, dd->id);
40 }
41
42 static void
43 signal_removed (gpointer  data,
44                 GClosure *closure)
45 {
46   DisconnectData *dd = data;
47
48   g_object_steal_data (dd->alive_object, "alive-object-data");
49   g_free (dd);
50 }
51
52 static void
53 g_object_connect_property (GObject *object,
54                            const gchar *prop_name,
55                            GtkSignalFunc func,
56                            gpointer data,
57                            GObject *alive_object)
58 {
59   GClosure *closure;
60   gchar *with_detail = g_strconcat ("notify::", prop_name, NULL);
61   DisconnectData *dd;
62
63   dd = g_new (DisconnectData, 1);
64
65   closure = g_cclosure_new (func, data, NULL);
66
67   g_closure_add_invalidate_notifier (closure, dd, signal_removed);
68
69   dd->id = g_signal_connect_closure (object, with_detail,
70                                      closure, FALSE);
71
72   dd->instance = object;
73   dd->alive_object = alive_object;
74   
75   g_object_set_data_full (G_OBJECT (alive_object),
76                           "alive-object-data",
77                           dd,
78                           disconnect_func);
79   
80   g_free (with_detail);
81 }
82
83 typedef struct 
84 {
85   GObject *obj;
86   gchar *prop;
87   gint modified_id;
88 } ObjectProperty;
89
90 static void
91 free_object_property (ObjectProperty *p)
92 {
93   g_free (p->prop);
94   g_free (p);
95 }
96
97 static void
98 connect_controller (GObject *controller,
99                     const gchar *signal,
100                     GObject *model,
101                     const gchar *prop_name,
102                     GtkSignalFunc func)
103 {
104   ObjectProperty *p;
105
106   p = g_new (ObjectProperty, 1);
107   p->obj = model;
108   p->prop = g_strdup (prop_name);
109
110   p->modified_id = g_signal_connect_data (controller, signal, func, p,
111                                           (GClosureNotify)free_object_property,
112                                           0);
113   g_object_set_data (controller, "object-property", p);
114 }
115
116 static void
117 block_controller (GObject *controller)
118 {
119   ObjectProperty *p = g_object_get_data (controller, "object-property");
120
121   if (p)
122     g_signal_handler_block (controller, p->modified_id);
123 }
124
125 static void
126 unblock_controller (GObject *controller)
127 {
128   ObjectProperty *p = g_object_get_data (controller, "object-property");
129
130   if (p)
131     g_signal_handler_unblock (controller, p->modified_id);
132 }
133
134 static void
135 int_modified (GtkAdjustment *adj, gpointer data)
136 {
137   ObjectProperty *p = data;
138
139   g_object_set (p->obj, p->prop, (int) adj->value, NULL);
140 }
141
142 static void
143 int_changed (GObject *object, GParamSpec *pspec, gpointer data)
144 {
145   GtkAdjustment *adj = GTK_ADJUSTMENT (data);
146   GValue val = { 0, };  
147
148   g_value_init (&val, G_TYPE_INT);
149   g_object_get_property (object, pspec->name, &val);
150
151   if (g_value_get_int (&val) != (int)adj->value)
152     {
153       block_controller (G_OBJECT (adj));
154       gtk_adjustment_set_value (adj, g_value_get_int (&val));
155       unblock_controller (G_OBJECT (adj));
156     }
157
158   g_value_unset (&val);
159 }
160
161 static void
162 uint_modified (GtkAdjustment *adj, gpointer data)
163 {
164   ObjectProperty *p = data;
165
166   g_object_set (p->obj, p->prop, (guint) adj->value, NULL);
167 }
168
169 static void
170 uint_changed (GObject *object, GParamSpec *pspec, gpointer data)
171 {
172   GtkAdjustment *adj = GTK_ADJUSTMENT (data);
173   GValue val = { 0, };  
174
175   g_value_init (&val, G_TYPE_UINT);
176   g_object_get_property (object, pspec->name, &val);
177
178   if (g_value_get_uint (&val) != (guint)adj->value)
179     {
180       block_controller (G_OBJECT (adj));
181       gtk_adjustment_set_value (adj, g_value_get_uint (&val));
182       unblock_controller (G_OBJECT (adj));
183     }
184
185   g_value_unset (&val);
186 }
187
188 static void
189 float_modified (GtkAdjustment *adj, gpointer data)
190 {
191   ObjectProperty *p = data;
192
193   g_object_set (p->obj, p->prop, (float) adj->value, NULL);
194 }
195
196 static void
197 float_changed (GObject *object, GParamSpec *pspec, gpointer data)
198 {
199   GtkAdjustment *adj = GTK_ADJUSTMENT (data);
200   GValue val = { 0, };  
201
202   g_value_init (&val, G_TYPE_FLOAT);
203   g_object_get_property (object, pspec->name, &val);
204
205   if (g_value_get_float (&val) != (float) adj->value)
206     {
207       block_controller (G_OBJECT (adj));
208       gtk_adjustment_set_value (adj, g_value_get_float (&val));
209       unblock_controller (G_OBJECT (adj));
210     }
211
212   g_value_unset (&val);
213 }
214
215 static void
216 double_modified (GtkAdjustment *adj, gpointer data)
217 {
218   ObjectProperty *p = data;
219
220   g_object_set (p->obj, p->prop, (double) adj->value, NULL);
221 }
222
223 static void
224 double_changed (GObject *object, GParamSpec *pspec, gpointer data)
225 {
226   GtkAdjustment *adj = GTK_ADJUSTMENT (data);
227   GValue val = { 0, };  
228
229   g_value_init (&val, G_TYPE_DOUBLE);
230   g_object_get_property (object, pspec->name, &val);
231
232   if (g_value_get_double (&val) != adj->value)
233     {
234       block_controller (G_OBJECT (adj));
235       gtk_adjustment_set_value (adj, g_value_get_double (&val));
236       unblock_controller (G_OBJECT (adj));
237     }
238
239   g_value_unset (&val);
240 }
241
242 static void
243 string_modified (GtkEntry *entry, gpointer data)
244 {
245   ObjectProperty *p = data;
246   const gchar *text;
247
248   text = gtk_entry_get_text (entry);
249
250   g_object_set (p->obj, p->prop, text, NULL);
251 }
252
253 static void
254 string_changed (GObject *object, GParamSpec *pspec, gpointer data)
255 {
256   GtkEntry *entry = GTK_ENTRY (data);
257   GValue val = { 0, };  
258   const gchar *str;
259   const gchar *text;
260   
261   g_value_init (&val, G_TYPE_STRING);
262   g_object_get_property (object, pspec->name, &val);
263
264   str = g_value_get_string (&val);
265   if (str == NULL)
266     str = "";
267   text = gtk_entry_get_text (entry);
268
269   if (strcmp (str, text) != 0)
270     {
271       block_controller (G_OBJECT (entry));
272       gtk_entry_set_text (entry, str);
273       unblock_controller (G_OBJECT (entry));
274     }
275   
276   g_value_unset (&val);
277 }
278
279 static void
280 bool_modified (GtkToggleButton *tb, gpointer data)
281 {
282   ObjectProperty *p = data;
283
284   g_object_set (p->obj, p->prop, (int) tb->active, NULL);
285 }
286
287 static void
288 bool_changed (GObject *object, GParamSpec *pspec, gpointer data)
289 {
290   GtkToggleButton *tb = GTK_TOGGLE_BUTTON (data);
291   GValue val = { 0, };  
292   
293   g_value_init (&val, G_TYPE_BOOLEAN);
294   g_object_get_property (object, pspec->name, &val);
295
296   if (g_value_get_boolean (&val) != tb->active)
297     {
298       block_controller (G_OBJECT (tb));
299       gtk_toggle_button_set_active (tb, g_value_get_boolean (&val));
300       unblock_controller (G_OBJECT (tb));
301     }
302
303   gtk_label_set_text (GTK_LABEL (GTK_BIN (tb)->child), g_value_get_boolean (&val) ?
304                       "TRUE" : "FALSE");
305   
306   g_value_unset (&val);
307 }
308
309
310 static void
311 enum_modified (GtkOptionMenu *om, gpointer data)
312 {
313   ObjectProperty *p = data;
314   gint i;
315   GParamSpec *spec;
316   GEnumClass *eclass;
317   
318   spec = g_object_class_find_property (G_OBJECT_GET_CLASS (p->obj),
319                                        p->prop);
320
321   eclass = G_ENUM_CLASS (g_type_class_peek (spec->value_type));
322   
323   i = gtk_option_menu_get_history (om);
324
325   g_object_set (p->obj, p->prop, eclass->values[i].value, NULL);
326 }
327
328 static void
329 enum_changed (GObject *object, GParamSpec *pspec, gpointer data)
330 {
331   GtkOptionMenu *om = GTK_OPTION_MENU (data);
332   GValue val = { 0, };  
333   GEnumClass *eclass;
334   gint i;
335
336   eclass = G_ENUM_CLASS (g_type_class_peek (pspec->value_type));
337   
338   g_value_init (&val, pspec->value_type);
339   g_object_get_property (object, pspec->name, &val);
340
341   i = 0;
342   while (i < eclass->n_values)
343     {
344       if (eclass->values[i].value == g_value_get_enum (&val))
345         break;
346       ++i;
347     }
348   
349   if (gtk_option_menu_get_history (om) != i)
350     {
351       block_controller (G_OBJECT (om));
352       gtk_option_menu_set_history (om, i);
353       unblock_controller (G_OBJECT (om));
354     }
355   
356   g_value_unset (&val);
357
358 }
359
360 static gunichar
361 unichar_get_value (GtkEntry *entry)
362 {
363   const gchar *text = gtk_entry_get_text (entry);
364   
365   if (text[0])
366     return g_utf8_get_char (text);
367   else
368     return 0;
369 }
370
371 static void
372 unichar_modified (GtkEntry *entry, gpointer data)
373 {
374   ObjectProperty *p = data;
375   gunichar val = unichar_get_value (entry);
376
377   g_object_set (p->obj, p->prop, val, NULL);
378 }
379
380 static void
381 unichar_changed (GObject *object, GParamSpec *pspec, gpointer data)
382 {
383   GtkEntry *entry = GTK_ENTRY (data);
384   gunichar new_val;
385   gunichar old_val = unichar_get_value (entry);
386   gchar buf[7];
387   gint len;
388
389   g_object_get (object, pspec->name, &new_val, NULL);
390
391   if (new_val != old_val)
392     {
393       if (!new_val)
394         len = 0;
395       else
396         len = g_unichar_to_utf8 (new_val, buf);
397       
398       buf[len] = '\0';
399       
400       block_controller (G_OBJECT (entry));
401       gtk_entry_set_text (entry, buf);
402       unblock_controller (G_OBJECT (entry));
403     }
404 }
405
406 static void
407 pointer_changed (GObject *object, GParamSpec *pspec, gpointer data)
408 {
409   GtkLabel *label = GTK_LABEL (data);
410   gchar *str;
411   gpointer ptr;
412   
413   g_object_get (object, pspec->name, &ptr, NULL);
414
415   str = g_strdup_printf ("Pointer: %p", ptr);
416   gtk_label_set_text (label, str);
417   g_free (str);
418 }
419
420 static void
421 object_changed (GObject *object, GParamSpec *pspec, gpointer data)
422 {
423   GtkLabel *label = GTK_LABEL (data);
424   gchar *str;
425   GObject *obj;
426   const gchar *name;
427   
428   g_object_get (object, pspec->name, &obj, NULL);
429
430   if (obj)
431     name = g_type_name (G_TYPE_FROM_INSTANCE (obj));
432   else
433     name = "unknown";
434   str = g_strdup_printf ("Object: %p (%s)", obj, name);
435   
436   gtk_label_set_text (label, str);
437   g_free (str);
438 }
439
440 void
441 model_destroy (gpointer data)
442 {
443   g_object_steal_data (data, "model-object");
444   gtk_widget_destroy (data);
445 }
446
447 void
448 window_destroy (gpointer data)
449 {
450   g_object_steal_data (data, "prop-editor-win");
451 }
452
453 static GtkWidget *
454 property_widget (GObject *object, GParamSpec *spec, gboolean can_modify)
455 {
456   GtkWidget *prop_edit;
457   GtkAdjustment *adj;
458   gchar *msg;
459   
460   switch (G_PARAM_SPEC_TYPE (spec))
461     {
462     case G_TYPE_PARAM_INT:
463       adj = GTK_ADJUSTMENT (gtk_adjustment_new (G_PARAM_SPEC_INT (spec)->default_value,
464                                                 G_PARAM_SPEC_INT (spec)->minimum,
465                                                 G_PARAM_SPEC_INT (spec)->maximum,
466                                                 1,
467                                                 MAX ((G_PARAM_SPEC_INT (spec)->maximum -
468                                                       G_PARAM_SPEC_INT (spec)->minimum) / 10, 1),
469                                                 0.0));
470       
471       prop_edit = gtk_spin_button_new (adj, 1.0, 0);
472       
473       g_object_connect_property (object, spec->name,
474                                  GTK_SIGNAL_FUNC (int_changed),
475                                  adj, G_OBJECT (adj));
476       
477       if (can_modify)
478         connect_controller (G_OBJECT (adj), "value_changed",
479                             object, spec->name, (GtkSignalFunc) int_modified);
480       break;
481       
482     case G_TYPE_PARAM_UINT:
483       adj = GTK_ADJUSTMENT (
484              gtk_adjustment_new (G_PARAM_SPEC_UINT (spec)->default_value,
485                                  G_PARAM_SPEC_UINT (spec)->minimum,
486                                  G_PARAM_SPEC_UINT (spec)->maximum,
487                                  1,
488                                  MAX ((G_PARAM_SPEC_UINT (spec)->maximum -
489                                        G_PARAM_SPEC_UINT (spec)->minimum) / 10, 1),
490                                  0.0));
491       
492       prop_edit = gtk_spin_button_new (adj, 1.0, 0);
493       
494       g_object_connect_property (object, spec->name,
495                                  GTK_SIGNAL_FUNC (uint_changed),
496                                  adj, G_OBJECT (adj));
497       
498       if (can_modify)
499         connect_controller (G_OBJECT (adj), "value_changed",
500                             object, spec->name, (GtkSignalFunc) uint_modified);
501       break;
502       
503     case G_TYPE_PARAM_FLOAT:
504       adj = GTK_ADJUSTMENT (gtk_adjustment_new (G_PARAM_SPEC_FLOAT (spec)->default_value,
505                                                 G_PARAM_SPEC_FLOAT (spec)->minimum,
506                                                 G_PARAM_SPEC_FLOAT (spec)->maximum,
507                                                 0.1,
508                                                 MAX ((G_PARAM_SPEC_FLOAT (spec)->maximum -
509                                                       G_PARAM_SPEC_FLOAT (spec)->minimum) / 10, 0.1),
510                                                 0.0));
511       
512       prop_edit = gtk_spin_button_new (adj, 0.1, 2);
513       
514       g_object_connect_property (object, spec->name,
515                                  GTK_SIGNAL_FUNC (float_changed),
516                                  adj, G_OBJECT (adj));
517       
518       if (can_modify)
519         connect_controller (G_OBJECT (adj), "value_changed",
520                             object, spec->name, (GtkSignalFunc) float_modified);
521       break;
522       
523     case G_TYPE_PARAM_DOUBLE:
524       adj = GTK_ADJUSTMENT (gtk_adjustment_new (G_PARAM_SPEC_DOUBLE (spec)->default_value,
525                                                 G_PARAM_SPEC_DOUBLE (spec)->minimum,
526                                                 G_PARAM_SPEC_DOUBLE (spec)->maximum,
527                                                 0.1,
528                                                 MAX ((G_PARAM_SPEC_DOUBLE (spec)->maximum -
529                                                       G_PARAM_SPEC_DOUBLE (spec)->minimum) / 10, 0.1),
530                                                 0.0));
531       
532       prop_edit = gtk_spin_button_new (adj, 0.1, 2);
533       
534       g_object_connect_property (object, spec->name,
535                                  GTK_SIGNAL_FUNC (double_changed),
536                                  adj, G_OBJECT (adj));
537       
538       if (can_modify)
539         connect_controller (G_OBJECT (adj), "value_changed",
540                             object, spec->name, (GtkSignalFunc) double_modified);
541       break;
542       
543     case G_TYPE_PARAM_STRING:
544       prop_edit = gtk_entry_new ();
545       
546       g_object_connect_property (object, spec->name,
547                                  GTK_SIGNAL_FUNC (string_changed),
548                                  prop_edit, G_OBJECT (prop_edit));
549       
550       if (can_modify)
551         connect_controller (G_OBJECT (prop_edit), "changed",
552                             object, spec->name, (GtkSignalFunc) string_modified);
553       break;
554       
555     case G_TYPE_PARAM_BOOLEAN:
556       prop_edit = gtk_toggle_button_new_with_label ("");
557       
558       g_object_connect_property (object, spec->name,
559                                  GTK_SIGNAL_FUNC (bool_changed),
560                                  prop_edit, G_OBJECT (prop_edit));
561       
562       if (can_modify)
563         connect_controller (G_OBJECT (prop_edit), "toggled",
564                             object, spec->name, (GtkSignalFunc) bool_modified);
565       break;
566       
567     case G_TYPE_PARAM_ENUM:
568       {
569         GtkWidget *menu;
570         GEnumClass *eclass;
571         gint j;
572         
573         prop_edit = gtk_option_menu_new ();
574         
575         menu = gtk_menu_new ();
576         
577         eclass = G_ENUM_CLASS (g_type_class_ref (spec->value_type));
578         
579         j = 0;
580         while (j < eclass->n_values)
581           {
582             GtkWidget *mi;
583             
584             mi = gtk_menu_item_new_with_label (eclass->values[j].value_name);
585             
586             gtk_widget_show (mi);
587             
588             gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
589             
590             ++j;
591           }
592         
593         g_type_class_unref (eclass);
594         
595         gtk_option_menu_set_menu (GTK_OPTION_MENU (prop_edit), menu);
596         
597         g_object_connect_property (object, spec->name,
598                                    GTK_SIGNAL_FUNC (enum_changed),
599                                    prop_edit, G_OBJECT (prop_edit));
600         
601         if (can_modify)
602           connect_controller (G_OBJECT (prop_edit), "changed",
603                               object, spec->name, (GtkSignalFunc) enum_modified);
604       }
605       break;
606       
607     case G_TYPE_PARAM_UNICHAR:
608       prop_edit = gtk_entry_new ();
609       gtk_entry_set_max_length (GTK_ENTRY (prop_edit), 1);
610       
611       g_object_connect_property (object, spec->name,
612                                  GTK_SIGNAL_FUNC (unichar_changed),
613                                  prop_edit, G_OBJECT (prop_edit));
614       
615       if (can_modify)
616         connect_controller (G_OBJECT (prop_edit), "changed",
617                             object, spec->name, (GtkSignalFunc) unichar_modified);
618       break;
619       
620     case G_TYPE_PARAM_POINTER:
621       prop_edit = gtk_label_new ("");
622       
623       g_object_connect_property (object, spec->name,
624                                  GTK_SIGNAL_FUNC (pointer_changed),
625                                  prop_edit, G_OBJECT (prop_edit));
626       break;
627       
628     case G_TYPE_PARAM_OBJECT:
629       prop_edit = gtk_label_new ("");
630       
631       g_object_connect_property (object, spec->name,
632                                  GTK_SIGNAL_FUNC (object_changed),
633                                  prop_edit, G_OBJECT (prop_edit));
634       break;
635       
636       
637     default:
638       msg = g_strdup_printf ("uneditable property type: %s",
639                              g_type_name (G_PARAM_SPEC_TYPE (spec)));
640       prop_edit = gtk_label_new (msg);            
641       g_free (msg);
642       gtk_misc_set_alignment (GTK_MISC (prop_edit), 0.0, 0.5);
643     }
644   
645   return prop_edit;
646 }
647
648 static GtkWidget *
649 properties_from_type (GObject     *object,
650                       GType        type,
651                       GtkTooltips *tips)
652 {
653   GtkWidget *prop_edit;
654   GtkWidget *label;
655   GtkWidget *sw;
656   GtkWidget *vbox;
657   GtkWidget *table;
658   GObjectClass *class;
659   GParamSpec **specs;
660   gint n_specs;
661   int i;
662
663   class = G_OBJECT_CLASS (g_type_class_peek (type));
664   specs = g_object_class_list_properties (class, &n_specs);
665         
666   if (n_specs == 0)
667     return NULL;
668   
669   table = gtk_table_new (n_specs, 2, FALSE);
670   gtk_table_set_col_spacing (GTK_TABLE (table), 0, 10);
671   gtk_table_set_row_spacings (GTK_TABLE (table), 3);
672
673   i = 0;
674   while (i < n_specs)
675     {
676       GParamSpec *spec = specs[i];
677       gboolean can_modify;
678       
679       prop_edit = NULL;
680
681       can_modify = ((spec->flags & G_PARAM_WRITABLE) != 0 &&
682                     (spec->flags & G_PARAM_CONSTRUCT_ONLY) == 0);
683       
684       if ((spec->flags & G_PARAM_READABLE) == 0)
685         {
686           /* can't display unreadable properties */
687           ++i;
688           continue;
689         }
690       
691       if (spec->owner_type != type)
692         {
693           /* we're only interested in params of type */
694           ++i;
695           continue;
696         }
697
698       label = gtk_label_new (g_param_spec_get_nick (spec));
699       gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
700       gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, i, i + 1);
701       
702       prop_edit = property_widget (object, spec, can_modify);
703       gtk_table_attach_defaults (GTK_TABLE (table), prop_edit, 1, 2, i, i + 1);
704
705       if (prop_edit)
706         {
707           if (!can_modify)
708             gtk_widget_set_sensitive (prop_edit, FALSE);
709
710           if (g_param_spec_get_blurb (spec))
711             gtk_tooltips_set_tip (tips, prop_edit, g_param_spec_get_blurb (spec), NULL);
712           
713           /* set initial value */
714           g_object_notify (object, spec->name);
715         }
716       
717       ++i;
718     }
719
720
721   vbox = gtk_vbox_new (FALSE, 0);
722   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
723
724   sw = gtk_scrolled_window_new (NULL, NULL);
725   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
726                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
727   
728   gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), vbox);
729
730   g_free (specs);
731
732   return sw;
733 }
734
735
736 /* Pass zero for type if you want all properties */
737 GtkWidget*
738 create_prop_editor (GObject *object, GType type)
739 {
740   GtkWidget *win;
741   GtkWidget *notebook;
742   GtkTooltips *tips;
743   GtkWidget *properties;
744   GtkWidget *label;
745   gchar *title;
746
747   if ((win = g_object_get_data (G_OBJECT (object), "prop-editor-win")))
748     {
749       gtk_window_present (GTK_WINDOW (win));
750       return win;
751     }
752
753   win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
754
755   tips = gtk_tooltips_new ();
756   gtk_signal_connect_object (GTK_OBJECT (win), "destroy",
757                              GTK_SIGNAL_FUNC (gtk_object_destroy), GTK_OBJECT (tips));
758
759   /* hold a weak ref to the object we're editing */
760   g_object_set_data_full (G_OBJECT (object), "prop-editor-win", win, model_destroy);
761   g_object_set_data_full (G_OBJECT (win), "model-object", object, window_destroy);
762
763   if (type == 0)
764     {
765       notebook = gtk_notebook_new ();
766       gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_LEFT);
767       
768       gtk_container_add (GTK_CONTAINER (win), notebook);
769       
770       type = G_TYPE_FROM_INSTANCE (object);
771
772       title = g_strdup_printf ("Properties of %s widget", g_type_name (type));
773       gtk_window_set_title (GTK_WINDOW (win), title);
774       g_free (title);
775       
776       while (type)
777         {
778           properties = properties_from_type (object, type, tips);
779           if (properties)
780             {
781               label = gtk_label_new (g_type_name (type));
782               gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
783                                         properties, label);
784             }
785           
786           type = g_type_parent (type);
787         }
788     }
789   else
790     {
791       properties = properties_from_type (object, type, tips);
792       gtk_container_add (GTK_CONTAINER (win), properties);
793       title = g_strdup_printf ("Properties of %s", g_type_name (type));
794       gtk_window_set_title (GTK_WINDOW (win), title);
795     }
796   
797   gtk_window_set_default_size (GTK_WINDOW (win), -1, 400);
798   
799   gtk_widget_show_all (win);
800
801   return win;
802 }
803