]> Pileus Git - ~andy/gtk/blob - tests/prop-editor.c
Version 1.3.11 Require GLib-1.3.11, Pango-0.22, ATK-0.7. Restore to
[~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   GType type = G_PARAM_SPEC_TYPE (spec);
460
461   if (type == G_TYPE_PARAM_INT)
462     {
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     }
481   else if (type == G_TYPE_PARAM_UINT)
482     {
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     }
502   else if (type == G_TYPE_PARAM_FLOAT)
503     {
504
505       adj = GTK_ADJUSTMENT (gtk_adjustment_new (G_PARAM_SPEC_FLOAT (spec)->default_value,
506                                                 G_PARAM_SPEC_FLOAT (spec)->minimum,
507                                                 G_PARAM_SPEC_FLOAT (spec)->maximum,
508                                                 0.1,
509                                                 MAX ((G_PARAM_SPEC_FLOAT (spec)->maximum -
510                                                       G_PARAM_SPEC_FLOAT (spec)->minimum) / 10, 0.1),
511                                                 0.0));
512       
513       prop_edit = gtk_spin_button_new (adj, 0.1, 2);
514       
515       g_object_connect_property (object, spec->name,
516                                  GTK_SIGNAL_FUNC (float_changed),
517                                  adj, G_OBJECT (adj));
518       
519       if (can_modify)
520         connect_controller (G_OBJECT (adj), "value_changed",
521                             object, spec->name, (GtkSignalFunc) float_modified);
522     }
523   else if (type == G_TYPE_PARAM_DOUBLE)
524     {
525       adj = GTK_ADJUSTMENT (gtk_adjustment_new (G_PARAM_SPEC_DOUBLE (spec)->default_value,
526                                                 G_PARAM_SPEC_DOUBLE (spec)->minimum,
527                                                 G_PARAM_SPEC_DOUBLE (spec)->maximum,
528                                                 0.1,
529                                                 MAX ((G_PARAM_SPEC_DOUBLE (spec)->maximum -
530                                                       G_PARAM_SPEC_DOUBLE (spec)->minimum) / 10, 0.1),
531                                                 0.0));
532       
533       prop_edit = gtk_spin_button_new (adj, 0.1, 2);
534       
535       g_object_connect_property (object, spec->name,
536                                  GTK_SIGNAL_FUNC (double_changed),
537                                  adj, G_OBJECT (adj));
538       
539       if (can_modify)
540         connect_controller (G_OBJECT (adj), "value_changed",
541                             object, spec->name, (GtkSignalFunc) double_modified);
542     }
543   else if (type == G_TYPE_PARAM_STRING)
544     {
545       prop_edit = gtk_entry_new ();
546       
547       g_object_connect_property (object, spec->name,
548                                  GTK_SIGNAL_FUNC (string_changed),
549                                  prop_edit, G_OBJECT (prop_edit));
550       
551       if (can_modify)
552         connect_controller (G_OBJECT (prop_edit), "changed",
553                             object, spec->name, (GtkSignalFunc) string_modified);
554     }
555   else if (type == G_TYPE_PARAM_BOOLEAN)
556     {
557       prop_edit = gtk_toggle_button_new_with_label ("");
558       
559       g_object_connect_property (object, spec->name,
560                                  GTK_SIGNAL_FUNC (bool_changed),
561                                  prop_edit, G_OBJECT (prop_edit));
562       
563       if (can_modify)
564         connect_controller (G_OBJECT (prop_edit), "toggled",
565                             object, spec->name, (GtkSignalFunc) bool_modified);
566     }
567   else if (type == G_TYPE_PARAM_ENUM)
568     {
569       {
570         GtkWidget *menu;
571         GEnumClass *eclass;
572         gint j;
573         
574         prop_edit = gtk_option_menu_new ();
575         
576         menu = gtk_menu_new ();
577         
578         eclass = G_ENUM_CLASS (g_type_class_ref (spec->value_type));
579         
580         j = 0;
581         while (j < eclass->n_values)
582           {
583             GtkWidget *mi;
584             
585             mi = gtk_menu_item_new_with_label (eclass->values[j].value_name);
586             
587             gtk_widget_show (mi);
588             
589             gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
590             
591             ++j;
592           }
593         
594         g_type_class_unref (eclass);
595         
596         gtk_option_menu_set_menu (GTK_OPTION_MENU (prop_edit), menu);
597         
598         g_object_connect_property (object, spec->name,
599                                    GTK_SIGNAL_FUNC (enum_changed),
600                                    prop_edit, G_OBJECT (prop_edit));
601         
602         if (can_modify)
603           connect_controller (G_OBJECT (prop_edit), "changed",
604                               object, spec->name, (GtkSignalFunc) enum_modified);
605       }
606     }
607   else if (type == G_TYPE_PARAM_UNICHAR)
608     {
609       prop_edit = gtk_entry_new ();
610       gtk_entry_set_max_length (GTK_ENTRY (prop_edit), 1);
611       
612       g_object_connect_property (object, spec->name,
613                                  GTK_SIGNAL_FUNC (unichar_changed),
614                                  prop_edit, G_OBJECT (prop_edit));
615       
616       if (can_modify)
617         connect_controller (G_OBJECT (prop_edit), "changed",
618                             object, spec->name, (GtkSignalFunc) unichar_modified);
619     }
620   else if (type == G_TYPE_PARAM_POINTER)
621     {
622       prop_edit = gtk_label_new ("");
623       
624       g_object_connect_property (object, spec->name,
625                                  GTK_SIGNAL_FUNC (pointer_changed),
626                                  prop_edit, G_OBJECT (prop_edit));
627     }
628   else if (type == G_TYPE_PARAM_OBJECT)
629     {
630       prop_edit = gtk_label_new ("");
631       
632       g_object_connect_property (object, spec->name,
633                                  GTK_SIGNAL_FUNC (object_changed),
634                                  prop_edit, G_OBJECT (prop_edit));
635     }
636   else
637     {  
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