From 518a8a9c4ed18ea4571e3c9c43c1dbc387e6627b Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Wed, 6 May 1998 01:43:56 +0000 Subject: [PATCH] reimplemented the signal storage system to use a linear array rather than Wed May 6 02:16:34 1998 Tim Janik * gtk/gtksignal.c: reimplemented the signal storage system to use a linear array rather than a hash table. be carefull *not* to keep any GtkSignal pointers across invokations of gtk_signal_next_and_invalidate() and therefore gtk_signal_new[v](). general code cleanups, made all allocations through memchunks. (gtk_signal_lookup): we now do the lookup of signals through a key_id for the signal names to avoid multiple hashing of the signal name on lookups for the several hirarchy levels of an object. Tue May 5 15:33:27 1998 Tim Janik * gtk/gtkmain.c (gtk_init): added gtk_signal_init() to avoid repeatedly checking for signal initialization in gtksignal.c. * gtk/gtktypeutils.c (TYPE_NODES_BLOCK_SIZE): reseted this to 200 after a long debugging period ;) Mon May 4 00:30:11 1998 Tim Janik * gtk/gtktypeutils.h (GTK_TYPE_IS_A): new macro to speedup gtk_type_is_a(). * gtk/gtktypeutils.c: reimplemented the type storage system to use a linear array rather than a hash table. it actually speeded up testgtk for a *considerable* amount. be carefull *not* to keep any GtkTypeNode pointers across invokations of gtk_type_node_next_and_invalidate() and therefore gtk_type_unique()! * gtk/gtkobject.h (GTK_IS_OBJECT_CLASS): new macro to test for the inheritance of a class pointer. (GTK_OBJECT): modifications for speedups. (GTK_IS_OBJECT): likewise. (GTK_OBJECT_CLASS): likewise. (suggested by owen). * gtk/gtkcontainer.h (GTK_IS_CONTAINER_CLASS): new macro. * gtk/gtkwidget.h (GTK_IS_WIDGET_CLASS): new macro. * gtk/gtk.defs (GtkTooltips): define GtkTooltips as object not as boxed, since its derivation changed 4 month ago ;(. showed up with the unique type name checking code in gtk_type_unique(). * random guint->GtkType and macro fixups. --- ChangeLog | 47 +- ChangeLog.pre-2-0 | 47 +- ChangeLog.pre-2-10 | 47 +- ChangeLog.pre-2-2 | 47 +- ChangeLog.pre-2-4 | 47 +- ChangeLog.pre-2-6 | 47 +- ChangeLog.pre-2-8 | 47 +- gtk/gtk.defs | 2 +- gtk/gtkaspectframe.c | 4 +- gtk/gtkaspectframe.h | 12 +- gtk/gtkbutton.c | 4 +- gtk/gtkbutton.h | 12 +- gtk/gtkcheckmenuitem.c | 4 +- gtk/gtkcheckmenuitem.h | 33 +- gtk/gtkcontainer.h | 9 +- gtk/gtkdata.c | 4 +- gtk/gtkdata.h | 12 +- gtk/gtkmain.c | 8 +- gtk/gtkobject.c | 10 +- gtk/gtkobject.h | 63 ++- gtk/gtksignal.c | 994 +++++++++++++++++++++-------------------- gtk/gtksignal.h | 7 +- gtk/gtktypebuiltins.c | 1 - gtk/gtktypebuiltins.h | 3 +- gtk/gtktypeutils.c | 457 +++++++++++-------- gtk/gtktypeutils.h | 35 +- gtk/gtkwidget.c | 16 +- gtk/gtkwidget.h | 23 +- gtk/gtkwindow.c | 4 +- gtk/gtkwindow.h | 20 +- 30 files changed, 1269 insertions(+), 797 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a4016d76a..c0f788ea79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +Wed May 6 02:16:34 1998 Tim Janik + + * gtk/gtksignal.c: reimplemented the signal storage system to use a + linear array rather than a hash table. + be carefull *not* to keep any GtkSignal pointers across invokations + of gtk_signal_next_and_invalidate() and therefore gtk_signal_new[v](). + general code cleanups, made all allocations through memchunks. + (gtk_signal_lookup): we now do the lookup of signals through a key_id + for the signal names to avoid multiple hashing of the signal name on + lookups for the several hirarchy levels of an object. + +Tue May 5 15:33:27 1998 Tim Janik + + * gtk/gtkmain.c (gtk_init): added gtk_signal_init() to avoid repeatedly + checking for signal initialization in gtksignal.c. + + * gtk/gtktypeutils.c (TYPE_NODES_BLOCK_SIZE): reseted this to 200 after + a long debugging period ;) + 1998-05-05 Stefan Jeske * gdk/gdkgc.c gdk/gdk.h gtk/gtkctree.c (gdk_gc_set_dashes): @@ -8,6 +27,33 @@ * configure.in: Added $x_libs in the other_libraries field in the check for XShapeCombineMask. +Mon May 4 00:30:11 1998 Tim Janik + + * gtk/gtktypeutils.h (GTK_TYPE_IS_A): new macro to speedup + gtk_type_is_a(). + * gtk/gtktypeutils.c: reimplemented the type storage system to use a + linear array rather than a hash table. it actually speeded up testgtk + for a *considerable* amount. be carefull *not* to keep any GtkTypeNode + pointers across invokations of gtk_type_node_next_and_invalidate() and + therefore gtk_type_unique()! + + * gtk/gtkobject.h (GTK_IS_OBJECT_CLASS): new macro to test for the + inheritance of a class pointer. + (GTK_OBJECT): modifications for speedups. + (GTK_IS_OBJECT): likewise. + (GTK_OBJECT_CLASS): likewise. + (suggested by owen). + + * gtk/gtkcontainer.h (GTK_IS_CONTAINER_CLASS): new macro. + + * gtk/gtkwidget.h (GTK_IS_WIDGET_CLASS): new macro. + + * gtk/gtk.defs (GtkTooltips): define GtkTooltips as object not as boxed, + since its derivation changed 4 month ago ;(. showed up with the unique + type name checking code in gtk_type_unique(). + + * random guint->GtkType and macro fixups. + Sat May 2 23:14:34 1998 Owen Taylor * gtk/gtkcurve.c (gtk_curve_graph_events): Ignore @@ -138,7 +184,6 @@ Sat May 2 20:19:03 1998 Tim Janik (gtk_adjustment_set_value): new function to emit the "value_changed" signal. ->>>>>>> 1.372 Fri May 1 12:28:35 1998 Owen Taylor * gtk/gtkcombo.c: Further changes to the way the window diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 4a4016d76a..c0f788ea79 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,22 @@ +Wed May 6 02:16:34 1998 Tim Janik + + * gtk/gtksignal.c: reimplemented the signal storage system to use a + linear array rather than a hash table. + be carefull *not* to keep any GtkSignal pointers across invokations + of gtk_signal_next_and_invalidate() and therefore gtk_signal_new[v](). + general code cleanups, made all allocations through memchunks. + (gtk_signal_lookup): we now do the lookup of signals through a key_id + for the signal names to avoid multiple hashing of the signal name on + lookups for the several hirarchy levels of an object. + +Tue May 5 15:33:27 1998 Tim Janik + + * gtk/gtkmain.c (gtk_init): added gtk_signal_init() to avoid repeatedly + checking for signal initialization in gtksignal.c. + + * gtk/gtktypeutils.c (TYPE_NODES_BLOCK_SIZE): reseted this to 200 after + a long debugging period ;) + 1998-05-05 Stefan Jeske * gdk/gdkgc.c gdk/gdk.h gtk/gtkctree.c (gdk_gc_set_dashes): @@ -8,6 +27,33 @@ * configure.in: Added $x_libs in the other_libraries field in the check for XShapeCombineMask. +Mon May 4 00:30:11 1998 Tim Janik + + * gtk/gtktypeutils.h (GTK_TYPE_IS_A): new macro to speedup + gtk_type_is_a(). + * gtk/gtktypeutils.c: reimplemented the type storage system to use a + linear array rather than a hash table. it actually speeded up testgtk + for a *considerable* amount. be carefull *not* to keep any GtkTypeNode + pointers across invokations of gtk_type_node_next_and_invalidate() and + therefore gtk_type_unique()! + + * gtk/gtkobject.h (GTK_IS_OBJECT_CLASS): new macro to test for the + inheritance of a class pointer. + (GTK_OBJECT): modifications for speedups. + (GTK_IS_OBJECT): likewise. + (GTK_OBJECT_CLASS): likewise. + (suggested by owen). + + * gtk/gtkcontainer.h (GTK_IS_CONTAINER_CLASS): new macro. + + * gtk/gtkwidget.h (GTK_IS_WIDGET_CLASS): new macro. + + * gtk/gtk.defs (GtkTooltips): define GtkTooltips as object not as boxed, + since its derivation changed 4 month ago ;(. showed up with the unique + type name checking code in gtk_type_unique(). + + * random guint->GtkType and macro fixups. + Sat May 2 23:14:34 1998 Owen Taylor * gtk/gtkcurve.c (gtk_curve_graph_events): Ignore @@ -138,7 +184,6 @@ Sat May 2 20:19:03 1998 Tim Janik (gtk_adjustment_set_value): new function to emit the "value_changed" signal. ->>>>>>> 1.372 Fri May 1 12:28:35 1998 Owen Taylor * gtk/gtkcombo.c: Further changes to the way the window diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 4a4016d76a..c0f788ea79 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,22 @@ +Wed May 6 02:16:34 1998 Tim Janik + + * gtk/gtksignal.c: reimplemented the signal storage system to use a + linear array rather than a hash table. + be carefull *not* to keep any GtkSignal pointers across invokations + of gtk_signal_next_and_invalidate() and therefore gtk_signal_new[v](). + general code cleanups, made all allocations through memchunks. + (gtk_signal_lookup): we now do the lookup of signals through a key_id + for the signal names to avoid multiple hashing of the signal name on + lookups for the several hirarchy levels of an object. + +Tue May 5 15:33:27 1998 Tim Janik + + * gtk/gtkmain.c (gtk_init): added gtk_signal_init() to avoid repeatedly + checking for signal initialization in gtksignal.c. + + * gtk/gtktypeutils.c (TYPE_NODES_BLOCK_SIZE): reseted this to 200 after + a long debugging period ;) + 1998-05-05 Stefan Jeske * gdk/gdkgc.c gdk/gdk.h gtk/gtkctree.c (gdk_gc_set_dashes): @@ -8,6 +27,33 @@ * configure.in: Added $x_libs in the other_libraries field in the check for XShapeCombineMask. +Mon May 4 00:30:11 1998 Tim Janik + + * gtk/gtktypeutils.h (GTK_TYPE_IS_A): new macro to speedup + gtk_type_is_a(). + * gtk/gtktypeutils.c: reimplemented the type storage system to use a + linear array rather than a hash table. it actually speeded up testgtk + for a *considerable* amount. be carefull *not* to keep any GtkTypeNode + pointers across invokations of gtk_type_node_next_and_invalidate() and + therefore gtk_type_unique()! + + * gtk/gtkobject.h (GTK_IS_OBJECT_CLASS): new macro to test for the + inheritance of a class pointer. + (GTK_OBJECT): modifications for speedups. + (GTK_IS_OBJECT): likewise. + (GTK_OBJECT_CLASS): likewise. + (suggested by owen). + + * gtk/gtkcontainer.h (GTK_IS_CONTAINER_CLASS): new macro. + + * gtk/gtkwidget.h (GTK_IS_WIDGET_CLASS): new macro. + + * gtk/gtk.defs (GtkTooltips): define GtkTooltips as object not as boxed, + since its derivation changed 4 month ago ;(. showed up with the unique + type name checking code in gtk_type_unique(). + + * random guint->GtkType and macro fixups. + Sat May 2 23:14:34 1998 Owen Taylor * gtk/gtkcurve.c (gtk_curve_graph_events): Ignore @@ -138,7 +184,6 @@ Sat May 2 20:19:03 1998 Tim Janik (gtk_adjustment_set_value): new function to emit the "value_changed" signal. ->>>>>>> 1.372 Fri May 1 12:28:35 1998 Owen Taylor * gtk/gtkcombo.c: Further changes to the way the window diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 4a4016d76a..c0f788ea79 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,22 @@ +Wed May 6 02:16:34 1998 Tim Janik + + * gtk/gtksignal.c: reimplemented the signal storage system to use a + linear array rather than a hash table. + be carefull *not* to keep any GtkSignal pointers across invokations + of gtk_signal_next_and_invalidate() and therefore gtk_signal_new[v](). + general code cleanups, made all allocations through memchunks. + (gtk_signal_lookup): we now do the lookup of signals through a key_id + for the signal names to avoid multiple hashing of the signal name on + lookups for the several hirarchy levels of an object. + +Tue May 5 15:33:27 1998 Tim Janik + + * gtk/gtkmain.c (gtk_init): added gtk_signal_init() to avoid repeatedly + checking for signal initialization in gtksignal.c. + + * gtk/gtktypeutils.c (TYPE_NODES_BLOCK_SIZE): reseted this to 200 after + a long debugging period ;) + 1998-05-05 Stefan Jeske * gdk/gdkgc.c gdk/gdk.h gtk/gtkctree.c (gdk_gc_set_dashes): @@ -8,6 +27,33 @@ * configure.in: Added $x_libs in the other_libraries field in the check for XShapeCombineMask. +Mon May 4 00:30:11 1998 Tim Janik + + * gtk/gtktypeutils.h (GTK_TYPE_IS_A): new macro to speedup + gtk_type_is_a(). + * gtk/gtktypeutils.c: reimplemented the type storage system to use a + linear array rather than a hash table. it actually speeded up testgtk + for a *considerable* amount. be carefull *not* to keep any GtkTypeNode + pointers across invokations of gtk_type_node_next_and_invalidate() and + therefore gtk_type_unique()! + + * gtk/gtkobject.h (GTK_IS_OBJECT_CLASS): new macro to test for the + inheritance of a class pointer. + (GTK_OBJECT): modifications for speedups. + (GTK_IS_OBJECT): likewise. + (GTK_OBJECT_CLASS): likewise. + (suggested by owen). + + * gtk/gtkcontainer.h (GTK_IS_CONTAINER_CLASS): new macro. + + * gtk/gtkwidget.h (GTK_IS_WIDGET_CLASS): new macro. + + * gtk/gtk.defs (GtkTooltips): define GtkTooltips as object not as boxed, + since its derivation changed 4 month ago ;(. showed up with the unique + type name checking code in gtk_type_unique(). + + * random guint->GtkType and macro fixups. + Sat May 2 23:14:34 1998 Owen Taylor * gtk/gtkcurve.c (gtk_curve_graph_events): Ignore @@ -138,7 +184,6 @@ Sat May 2 20:19:03 1998 Tim Janik (gtk_adjustment_set_value): new function to emit the "value_changed" signal. ->>>>>>> 1.372 Fri May 1 12:28:35 1998 Owen Taylor * gtk/gtkcombo.c: Further changes to the way the window diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 4a4016d76a..c0f788ea79 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,22 @@ +Wed May 6 02:16:34 1998 Tim Janik + + * gtk/gtksignal.c: reimplemented the signal storage system to use a + linear array rather than a hash table. + be carefull *not* to keep any GtkSignal pointers across invokations + of gtk_signal_next_and_invalidate() and therefore gtk_signal_new[v](). + general code cleanups, made all allocations through memchunks. + (gtk_signal_lookup): we now do the lookup of signals through a key_id + for the signal names to avoid multiple hashing of the signal name on + lookups for the several hirarchy levels of an object. + +Tue May 5 15:33:27 1998 Tim Janik + + * gtk/gtkmain.c (gtk_init): added gtk_signal_init() to avoid repeatedly + checking for signal initialization in gtksignal.c. + + * gtk/gtktypeutils.c (TYPE_NODES_BLOCK_SIZE): reseted this to 200 after + a long debugging period ;) + 1998-05-05 Stefan Jeske * gdk/gdkgc.c gdk/gdk.h gtk/gtkctree.c (gdk_gc_set_dashes): @@ -8,6 +27,33 @@ * configure.in: Added $x_libs in the other_libraries field in the check for XShapeCombineMask. +Mon May 4 00:30:11 1998 Tim Janik + + * gtk/gtktypeutils.h (GTK_TYPE_IS_A): new macro to speedup + gtk_type_is_a(). + * gtk/gtktypeutils.c: reimplemented the type storage system to use a + linear array rather than a hash table. it actually speeded up testgtk + for a *considerable* amount. be carefull *not* to keep any GtkTypeNode + pointers across invokations of gtk_type_node_next_and_invalidate() and + therefore gtk_type_unique()! + + * gtk/gtkobject.h (GTK_IS_OBJECT_CLASS): new macro to test for the + inheritance of a class pointer. + (GTK_OBJECT): modifications for speedups. + (GTK_IS_OBJECT): likewise. + (GTK_OBJECT_CLASS): likewise. + (suggested by owen). + + * gtk/gtkcontainer.h (GTK_IS_CONTAINER_CLASS): new macro. + + * gtk/gtkwidget.h (GTK_IS_WIDGET_CLASS): new macro. + + * gtk/gtk.defs (GtkTooltips): define GtkTooltips as object not as boxed, + since its derivation changed 4 month ago ;(. showed up with the unique + type name checking code in gtk_type_unique(). + + * random guint->GtkType and macro fixups. + Sat May 2 23:14:34 1998 Owen Taylor * gtk/gtkcurve.c (gtk_curve_graph_events): Ignore @@ -138,7 +184,6 @@ Sat May 2 20:19:03 1998 Tim Janik (gtk_adjustment_set_value): new function to emit the "value_changed" signal. ->>>>>>> 1.372 Fri May 1 12:28:35 1998 Owen Taylor * gtk/gtkcombo.c: Further changes to the way the window diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 4a4016d76a..c0f788ea79 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,22 @@ +Wed May 6 02:16:34 1998 Tim Janik + + * gtk/gtksignal.c: reimplemented the signal storage system to use a + linear array rather than a hash table. + be carefull *not* to keep any GtkSignal pointers across invokations + of gtk_signal_next_and_invalidate() and therefore gtk_signal_new[v](). + general code cleanups, made all allocations through memchunks. + (gtk_signal_lookup): we now do the lookup of signals through a key_id + for the signal names to avoid multiple hashing of the signal name on + lookups for the several hirarchy levels of an object. + +Tue May 5 15:33:27 1998 Tim Janik + + * gtk/gtkmain.c (gtk_init): added gtk_signal_init() to avoid repeatedly + checking for signal initialization in gtksignal.c. + + * gtk/gtktypeutils.c (TYPE_NODES_BLOCK_SIZE): reseted this to 200 after + a long debugging period ;) + 1998-05-05 Stefan Jeske * gdk/gdkgc.c gdk/gdk.h gtk/gtkctree.c (gdk_gc_set_dashes): @@ -8,6 +27,33 @@ * configure.in: Added $x_libs in the other_libraries field in the check for XShapeCombineMask. +Mon May 4 00:30:11 1998 Tim Janik + + * gtk/gtktypeutils.h (GTK_TYPE_IS_A): new macro to speedup + gtk_type_is_a(). + * gtk/gtktypeutils.c: reimplemented the type storage system to use a + linear array rather than a hash table. it actually speeded up testgtk + for a *considerable* amount. be carefull *not* to keep any GtkTypeNode + pointers across invokations of gtk_type_node_next_and_invalidate() and + therefore gtk_type_unique()! + + * gtk/gtkobject.h (GTK_IS_OBJECT_CLASS): new macro to test for the + inheritance of a class pointer. + (GTK_OBJECT): modifications for speedups. + (GTK_IS_OBJECT): likewise. + (GTK_OBJECT_CLASS): likewise. + (suggested by owen). + + * gtk/gtkcontainer.h (GTK_IS_CONTAINER_CLASS): new macro. + + * gtk/gtkwidget.h (GTK_IS_WIDGET_CLASS): new macro. + + * gtk/gtk.defs (GtkTooltips): define GtkTooltips as object not as boxed, + since its derivation changed 4 month ago ;(. showed up with the unique + type name checking code in gtk_type_unique(). + + * random guint->GtkType and macro fixups. + Sat May 2 23:14:34 1998 Owen Taylor * gtk/gtkcurve.c (gtk_curve_graph_events): Ignore @@ -138,7 +184,6 @@ Sat May 2 20:19:03 1998 Tim Janik (gtk_adjustment_set_value): new function to emit the "value_changed" signal. ->>>>>>> 1.372 Fri May 1 12:28:35 1998 Owen Taylor * gtk/gtkcombo.c: Further changes to the way the window diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 4a4016d76a..c0f788ea79 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,22 @@ +Wed May 6 02:16:34 1998 Tim Janik + + * gtk/gtksignal.c: reimplemented the signal storage system to use a + linear array rather than a hash table. + be carefull *not* to keep any GtkSignal pointers across invokations + of gtk_signal_next_and_invalidate() and therefore gtk_signal_new[v](). + general code cleanups, made all allocations through memchunks. + (gtk_signal_lookup): we now do the lookup of signals through a key_id + for the signal names to avoid multiple hashing of the signal name on + lookups for the several hirarchy levels of an object. + +Tue May 5 15:33:27 1998 Tim Janik + + * gtk/gtkmain.c (gtk_init): added gtk_signal_init() to avoid repeatedly + checking for signal initialization in gtksignal.c. + + * gtk/gtktypeutils.c (TYPE_NODES_BLOCK_SIZE): reseted this to 200 after + a long debugging period ;) + 1998-05-05 Stefan Jeske * gdk/gdkgc.c gdk/gdk.h gtk/gtkctree.c (gdk_gc_set_dashes): @@ -8,6 +27,33 @@ * configure.in: Added $x_libs in the other_libraries field in the check for XShapeCombineMask. +Mon May 4 00:30:11 1998 Tim Janik + + * gtk/gtktypeutils.h (GTK_TYPE_IS_A): new macro to speedup + gtk_type_is_a(). + * gtk/gtktypeutils.c: reimplemented the type storage system to use a + linear array rather than a hash table. it actually speeded up testgtk + for a *considerable* amount. be carefull *not* to keep any GtkTypeNode + pointers across invokations of gtk_type_node_next_and_invalidate() and + therefore gtk_type_unique()! + + * gtk/gtkobject.h (GTK_IS_OBJECT_CLASS): new macro to test for the + inheritance of a class pointer. + (GTK_OBJECT): modifications for speedups. + (GTK_IS_OBJECT): likewise. + (GTK_OBJECT_CLASS): likewise. + (suggested by owen). + + * gtk/gtkcontainer.h (GTK_IS_CONTAINER_CLASS): new macro. + + * gtk/gtkwidget.h (GTK_IS_WIDGET_CLASS): new macro. + + * gtk/gtk.defs (GtkTooltips): define GtkTooltips as object not as boxed, + since its derivation changed 4 month ago ;(. showed up with the unique + type name checking code in gtk_type_unique(). + + * random guint->GtkType and macro fixups. + Sat May 2 23:14:34 1998 Owen Taylor * gtk/gtkcurve.c (gtk_curve_graph_events): Ignore @@ -138,7 +184,6 @@ Sat May 2 20:19:03 1998 Tim Janik (gtk_adjustment_set_value): new function to emit the "value_changed" signal. ->>>>>>> 1.372 Fri May 1 12:28:35 1998 Owen Taylor * gtk/gtkcombo.c: Further changes to the way the window diff --git a/gtk/gtk.defs b/gtk/gtk.defs index 3b3fd5aea8..2f5ed1addf 100644 --- a/gtk/gtk.defs +++ b/gtk/gtk.defs @@ -1094,7 +1094,7 @@ ;; Tooltips -(define-boxed GtkTooltips +(define-object GtkTooltips gtk_tooltips_ref gtk_tooltips_unref) diff --git a/gtk/gtkaspectframe.c b/gtk/gtkaspectframe.c index b19977ca5e..9fa3304bc7 100644 --- a/gtk/gtkaspectframe.c +++ b/gtk/gtkaspectframe.c @@ -37,10 +37,10 @@ static void gtk_aspect_frame_size_allocate (GtkWidget *widget, #define MAX_RATIO 10000.0 #define MIN_RATIO 0.0001 -guint +GtkType gtk_aspect_frame_get_type (void) { - static guint aspect_frame_type = 0; + static GtkType aspect_frame_type = 0; if (!aspect_frame_type) { diff --git a/gtk/gtkaspectframe.h b/gtk/gtkaspectframe.h index bc795c1a4c..b3904fa45f 100644 --- a/gtk/gtkaspectframe.h +++ b/gtk/gtkaspectframe.h @@ -26,12 +26,16 @@ #ifdef __cplusplus extern "C" { +#pragma } #endif /* __cplusplus */ -#define GTK_ASPECT_FRAME(obj) ((GtkAspectFrame*) obj) -#define GTK_ASPECT_FRAME_CLASS(obj) ((GtkAspectFrameClass*) GTK_OBJECT_CLASS (obj)) -#define GTK_IS_ASPECT_FRAME(obj) (gtk_type_is_a (GTK_WIDGET_TYPE (obj), gtk_aspect_frame_get_type ())) +#define GTK_TYPE_ASPECT_FRAME (gtk_aspect_frame_get_type ()) +#define GTK_ASPECT_FRAME(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_ASPECT_FRAME, GtkAspectFrame)) +#define GTK_ASPECT_FRAME_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_ASPECT_FRAME, GtkAspectFrameClass)) +#define GTK_IS_ASPECT_FRAME(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_ASPECT_FRAME)) +#define GTK_IS_ASPECT_FRAME_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ASPECT_FRAME)) + typedef struct _GtkAspectFrame GtkAspectFrame; @@ -55,7 +59,7 @@ struct _GtkAspectFrameClass }; -guint gtk_aspect_frame_get_type (void); +GtkType gtk_aspect_frame_get_type (void); GtkWidget* gtk_aspect_frame_new (const gchar *label, gfloat xalign, gfloat yalign, diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index 7bed40f52a..68933ed224 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -93,10 +93,10 @@ static GtkContainerClass *parent_class; static guint button_signals[LAST_SIGNAL] = { 0 }; -guint +GtkType gtk_button_get_type (void) { - static guint button_type = 0; + static GtkType button_type = 0; if (!button_type) { diff --git a/gtk/gtkbutton.h b/gtk/gtkbutton.h index e1c5dc0424..66b5f5eb06 100644 --- a/gtk/gtkbutton.h +++ b/gtk/gtkbutton.h @@ -26,12 +26,14 @@ #ifdef __cplusplus extern "C" { +#pragma } #endif /* __cplusplus */ - -#define GTK_BUTTON(obj) (GTK_CHECK_CAST ((obj), gtk_button_get_type (), GtkButton)) -#define GTK_BUTTON_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), gtk_button_get_type (), GtkButtonClass)) -#define GTK_IS_BUTTON(obj) (GTK_CHECK_TYPE ((obj), gtk_button_get_type ())) +#define GTK_TYPE_BUTTON (gtk_button_get_type ()) +#define GTK_BUTTON(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_BUTTON, GtkButton)) +#define GTK_BUTTON_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_BUTTON, GtkButtonClass)) +#define GTK_IS_BUTTON(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_BUTTON)) +#define GTK_IS_BUTTON_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_BUTTON)) typedef struct _GtkButton GtkButton; @@ -59,7 +61,7 @@ struct _GtkButtonClass }; -guint gtk_button_get_type (void); +GtkType gtk_button_get_type (void); GtkWidget* gtk_button_new (void); GtkWidget* gtk_button_new_with_label (const gchar *label); void gtk_button_pressed (GtkButton *button); diff --git a/gtk/gtkcheckmenuitem.c b/gtk/gtkcheckmenuitem.c index 834faa6851..40e9deb1ac 100644 --- a/gtk/gtkcheckmenuitem.c +++ b/gtk/gtkcheckmenuitem.c @@ -47,10 +47,10 @@ static GtkMenuItemClass *parent_class = NULL; static guint check_menu_item_signals[LAST_SIGNAL] = { 0 }; -guint +GtkType gtk_check_menu_item_get_type (void) { - static guint check_menu_item_type = 0; + static GtkType check_menu_item_type = 0; if (!check_menu_item_type) { diff --git a/gtk/gtkcheckmenuitem.h b/gtk/gtkcheckmenuitem.h index 4255c3060d..d6a07ea7a7 100644 --- a/gtk/gtkcheckmenuitem.h +++ b/gtk/gtkcheckmenuitem.h @@ -8,7 +8,7 @@ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public @@ -26,12 +26,15 @@ #ifdef __cplusplus extern "C" { +#pragma } #endif /* __cplusplus */ -#define GTK_CHECK_MENU_ITEM(obj) ((GtkCheckMenuItem*) obj) -#define GTK_CHECK_MENU_ITEM_CLASS(obj) ((GtkCheckMenuItemClass*) GTK_OBJECT_CLASS (obj)) -#define GTK_IS_CHECK_MENU_ITEM(obj) (gtk_type_is_a (GTK_WIDGET_TYPE (obj), gtk_check_menu_item_get_type ())) +#define GTK_TYPE_CHECK_MENU_ITEM (gtk_check_menu_item_get_type ()) +#define GTK_CHECK_MENU_ITEM(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_CHECK_MENU_ITEM, GtkCheckMenuItem)) +#define GTK_CHECK_MENU_ITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_CHECK_MENU_ITEM, GtkCheckMenuItemClass)) +#define GTK_IS_CHECK_MENU_ITEM(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_CHECK_MENU_ITEM)) +#define GTK_IS_CHECK_MENU_ITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CHECK_MENU_ITEM)) typedef struct _GtkCheckMenuItem GtkCheckMenuItem; @@ -40,7 +43,7 @@ typedef struct _GtkCheckMenuItemClass GtkCheckMenuItemClass; struct _GtkCheckMenuItem { GtkMenuItem menu_item; - + guint active : 1; guint always_show_toggle : 1; }; @@ -48,21 +51,21 @@ struct _GtkCheckMenuItem struct _GtkCheckMenuItemClass { GtkMenuItemClass parent_class; - - void (* toggled) (GtkCheckMenuItem *check_menu_item); + + void (* toggled) (GtkCheckMenuItem *check_menu_item); void (* draw_indicator) (GtkCheckMenuItem *check_menu_item, - GdkRectangle *area); + GdkRectangle *area); }; -guint gtk_check_menu_item_get_type (void); -GtkWidget* gtk_check_menu_item_new (void); -GtkWidget* gtk_check_menu_item_new_with_label (const gchar *label); -void gtk_check_menu_item_set_state (GtkCheckMenuItem *check_menu_item, - gint state); +GtkType gtk_check_menu_item_get_type (void); +GtkWidget* gtk_check_menu_item_new (void); +GtkWidget* gtk_check_menu_item_new_with_label (const gchar *label); +void gtk_check_menu_item_set_state (GtkCheckMenuItem *check_menu_item, + gint state); void gtk_check_menu_item_set_show_toggle(GtkCheckMenuItem *menu_item, - gboolean always); -void gtk_check_menu_item_toggled (GtkCheckMenuItem *check_menu_item); + gboolean always); +void gtk_check_menu_item_toggled (GtkCheckMenuItem *check_menu_item); #ifdef __cplusplus diff --git a/gtk/gtkcontainer.h b/gtk/gtkcontainer.h index 78bd37dcb3..05b153c109 100644 --- a/gtk/gtkcontainer.h +++ b/gtk/gtkcontainer.h @@ -32,11 +32,12 @@ extern "C" { #endif /* __cplusplus */ -#define GTK_CONTAINER(obj) (GTK_CHECK_CAST ((obj), gtk_container_get_type (), GtkContainer)) -#define GTK_CONTAINER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), gtk_container_get_type (), GtkContainerClass)) -#define GTK_IS_CONTAINER(obj) (GTK_CHECK_TYPE ((obj), gtk_container_get_type ())) +#define GTK_TYPE_CONTAINER (gtk_container_get_type ()) +#define GTK_CONTAINER(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_CONTAINER, GtkContainer)) +#define GTK_CONTAINER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_CONTAINER, GtkContainerClass)) +#define GTK_IS_CONTAINER(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_CONTAINER)) +#define GTK_IS_CONTAINER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CONTAINER)) -#define GTK_TYPE_CONTAINER (gtk_container_get_type ()) typedef struct _GtkContainer GtkContainer; typedef struct _GtkContainerClass GtkContainerClass; diff --git a/gtk/gtkdata.c b/gtk/gtkdata.c index 6196b92c8d..5b503bacbe 100644 --- a/gtk/gtkdata.c +++ b/gtk/gtkdata.c @@ -32,10 +32,10 @@ static void gtk_data_class_init (GtkDataClass *klass); static guint data_signals[LAST_SIGNAL] = { 0 }; -guint +GtkType gtk_data_get_type (void) { - static guint data_type = 0; + static GtkType data_type = 0; if (!data_type) { diff --git a/gtk/gtkdata.h b/gtk/gtkdata.h index 92ec32f2f9..a39690b46f 100644 --- a/gtk/gtkdata.h +++ b/gtk/gtkdata.h @@ -26,12 +26,16 @@ #ifdef __cplusplus extern "C" { +#pragma } #endif /* __cplusplus */ -#define GTK_DATA(obj) GTK_CHECK_CAST (obj, gtk_data_get_type (), GtkData) -#define GTK_DATA_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_data_get_type (), GtkDataClass) -#define GTK_IS_DATA(obj) GTK_CHECK_TYPE (obj, gtk_data_get_type ()) +#define GTK_TYPE_DATA (gtk_data_get_type ()) +#define GTK_DATA(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_DATA, GtkData)) +#define GTK_DATA_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_DATA, GtkDataClass)) +#define GTK_IS_DATA(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_DATA)) +#define GTK_IS_DATA_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_DATA)) + typedef struct _GtkData GtkData; @@ -50,7 +54,7 @@ struct _GtkDataClass }; -guint gtk_data_get_type (void); +GtkType gtk_data_get_type (void); #ifdef __cplusplus diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index a4c4497be7..5be05a5ec7 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -327,7 +327,7 @@ gtk_init (int *argc, * C locale, or were using X's mb functions. (-DX_LOCALE && locale != C) */ - current_locale = g_strdup(setlocale (LC_CTYPE, NULL)); + current_locale = g_strdup (setlocale (LC_CTYPE, NULL)); #ifdef X_LOCALE if ((strcmp (current_locale, "C")) && (strcmp (current_locale, "POSIX"))) @@ -342,7 +342,7 @@ gtk_init (int *argc, g_free (current_locale); - GTK_NOTE(MISC, g_print("%s multi-byte string functions.\n", + GTK_NOTE (MISC, g_print("%s multi-byte string functions.\n", gtk_use_mb ? "Using" : "Not using")); /* Initialize the default visual and colormap to be @@ -351,9 +351,11 @@ gtk_init (int *argc, */ gtk_visual = gdk_visual_get_system (); gtk_colormap = gdk_colormap_get_system (); + + gtk_type_init (); + gtk_signal_init (); gtk_rc_init (); - gtk_type_init (); /* Register an exit function to make sure we are able to cleanup. */ diff --git a/gtk/gtkobject.c b/gtk/gtkobject.c index 346d90d40f..1b50af14b3 100644 --- a/gtk/gtkobject.c +++ b/gtk/gtkobject.c @@ -640,7 +640,7 @@ gtk_object_getv (GtkObject *object, g_free (lookup_name); continue; } - else if (!gtk_type_is_a (object->klass->type, info->class_type)) + else if (!GTK_TYPE_IS_A (object->klass->type, info->class_type)) { g_warning ("invalid arg for %s: \"%s\"\n", gtk_type_name (object->klass->type), lookup_name); args[i].type = GTK_TYPE_INVALID; @@ -704,7 +704,7 @@ gtk_object_query_args (GtkType class_type, *arg_flags = NULL; g_return_val_if_fail (nargs != NULL, NULL); *nargs = 0; - g_return_val_if_fail (gtk_type_is_a (class_type, gtk_object_get_type ()), NULL); + g_return_val_if_fail (GTK_TYPE_IS_A (class_type, gtk_object_get_type ()), NULL); if (!arg_info_ht) return NULL; @@ -844,7 +844,7 @@ gtk_object_setv (GtkObject *object, g_warning ("invalid arg type for: \"%s\"\n", lookup_name); arg_ok = FALSE; } - else if (!gtk_type_is_a (object->klass->type, info->class_type)) + else if (!GTK_TYPE_IS_A (object->klass->type, info->class_type)) { g_warning ("invalid arg for %s: \"%s\"\n", gtk_type_name (object->klass->type), lookup_name); arg_ok = FALSE; @@ -1270,7 +1270,7 @@ gtk_object_check_cast (GtkObject *obj, gtk_object_descriptive_type_name (cast_type)); return obj; } - if (!gtk_type_is_a (obj->klass->type, cast_type)) + if (!GTK_TYPE_IS_A (obj->klass->type, cast_type)) { g_warning ("invalid cast from `%s' to `%s'", gtk_object_descriptive_type_name (obj->klass->type), @@ -1306,7 +1306,7 @@ gtk_object_check_class_cast (GtkObjectClass *klass, gtk_object_descriptive_type_name (cast_type)); return klass; } - if (!gtk_type_is_a (klass->type, cast_type)) + if (!GTK_TYPE_IS_A (klass->type, cast_type)) { g_warning ("invalid class cast from `%s' to `%s'", gtk_object_descriptive_type_name (klass->type), diff --git a/gtk/gtkobject.h b/gtk/gtkobject.h index 37f7017cfb..7017498745 100644 --- a/gtk/gtkobject.h +++ b/gtk/gtkobject.h @@ -27,6 +27,7 @@ #ifdef __cplusplus extern "C" { +#pragma } #endif /* __cplusplus */ @@ -51,18 +52,43 @@ extern "C" { #endif /* GTK_NO_CHECK_CASTS */ -/* Determines whether 'obj' is a type of 'otype'. +/* Determines whether `obj' and `klass' are a type of `otype'. */ -#define GTK_CHECK_TYPE(obj,otype) (gtk_type_is_a (((GtkObject*) (obj))->klass->type, (otype))) +#define GTK_CHECK_TYPE(obj,otype) ( \ + GTK_TYPE_IS_A (((GtkObject*) (obj))->klass->type, (otype)) \ +) +#define GTK_CHECK_CLASS_TYPE(klass,otype) ( \ + GTK_TYPE_IS_A (((GtkObjectClass*) (klass))->type, (otype)) \ +) - -/* Macro for casting a pointer to a GtkObject pointer. +/* Macro for casting a pointer to a GtkObject or GtkObjectClass pointer. + * The second portion of the ?: statments are just in place to offer + * descriptive warning message. */ -#define GTK_OBJECT(obj) GTK_CHECK_CAST ((obj), gtk_object_get_type (), GtkObject) +#define GTK_OBJECT(object) ( \ + GTK_IS_OBJECT (object) ? \ + (GtkObject*) (object) : \ + (GtkObject*) gtk_object_check_cast ((GtkObject*) (object), GTK_TYPE_OBJECT) \ +) +#define GTK_OBJECT_CLASS(klass) ( \ + GTK_IS_OBJECT_CLASS (klass) ? \ + (GtkObjectClass*) (klass) : \ + (GtkObjectClass*) gtk_object_check_class_cast ((GtkObjectClass*) (klass), GTK_TYPE_OBJECT) \ +) + +/* Macro for testing whether `object' and `klass' are of type GTK_TYPE_OBJECT. + */ +#define GTK_IS_OBJECT(object) ( \ + (object) != NULL && \ + GTK_IS_OBJECT_CLASS (((GtkObject*) (object))->klass) \ +) +#define GTK_IS_OBJECT_CLASS(klass) ( \ + (klass) != NULL && \ + GTK_FUNDAMENTAL_TYPE (((GtkObjectClass*) (klass))->type) == GTK_TYPE_OBJECT \ +) /* Macros for extracting various fields from GtkObject and GtkObjectClass. */ -#define GTK_OBJECT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), gtk_object_get_type (), GtkObjectClass)) #define GTK_OBJECT_TYPE(obj) (GTK_OBJECT (obj)->klass->type) #define GTK_OBJECT_SIGNALS(obj) (GTK_OBJECT (obj)->klass->signals) #define GTK_OBJECT_NSIGNALS(obj) (GTK_OBJECT (obj)->klass->nsignals) @@ -81,17 +107,6 @@ enum GTK_OBJECT_FLAG_LAST = GTK_RESERVED_2 }; -/* GtkArg flag bits for gtk_object_add_arg_type - */ -enum -{ - GTK_ARG_READABLE = 1 << 0, - GTK_ARG_WRITABLE = 1 << 1, - GTK_ARG_CONSTRUCT = 1 << 2 -}; -#define GTK_ARG_READWRITE (GTK_ARG_READABLE | GTK_ARG_WRITABLE) - - /* Macros for extracting the object_flags from GtkObject. */ #define GTK_OBJECT_FLAGS(obj) (GTK_OBJECT (obj)->flags) @@ -103,9 +118,17 @@ enum #define GTK_OBJECT_SET_FLAGS(obj,flag) G_STMT_START{ (GTK_OBJECT_FLAGS (obj) |= (flag)); }G_STMT_END #define GTK_OBJECT_UNSET_FLAGS(obj,flag) G_STMT_START{ (GTK_OBJECT_FLAGS (obj) &= ~(flag)); }G_STMT_END -/* Macro for testing whether "obj" is of type GtkObject. +/* GtkArg flag bits for gtk_object_add_arg_type */ -#define GTK_IS_OBJECT(obj) (GTK_CHECK_TYPE ((obj), gtk_object_get_type ())) +enum +{ + GTK_ARG_READABLE = 1 << 0, + GTK_ARG_WRITABLE = 1 << 1, + GTK_ARG_CONSTRUCT = 1 << 2, + /* aliases + */ + GTK_ARG_READWRITE = GTK_ARG_READABLE | GTK_ARG_WRITABLE +}; typedef struct _GtkObjectClass GtkObjectClass; @@ -193,7 +216,7 @@ typedef void (*GtkSignalMarshaller) (GtkObject *object, /* Get the type identifier for GtkObject's. */ -guint gtk_object_get_type (void); +GtkType gtk_object_get_type (void); /* Append "signals" to those already defined in "class". */ diff --git a/gtk/gtksignal.c b/gtk/gtksignal.c index dd83e63e53..b432f56c34 100644 --- a/gtk/gtksignal.c +++ b/gtk/gtksignal.c @@ -8,7 +8,7 @@ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public @@ -20,226 +20,281 @@ #include "gtksignal.h" -#define MAX_PARAMS 20 -#define DONE 1 -#define RESTART 2 +#define SIGNAL_BLOCK_SIZE (100) +#define HANDLER_BLOCK_SIZE (200) +#define EMISSION_BLOCK_SIZE (100) +#define DISCONNECT_INFO_BLOCK_SIZE (64) +#define GTK_MAX_SIGNAL_PARAMS (32) -#define GTK_RUN_TYPE(x) ((x) & GTK_RUN_MASK) +enum +{ + EMISSION_CONTINUE, + EMISSION_RESTART, + EMISSION_DONE +}; + +#define GTK_RUN_TYPE(x) ((x) & GTK_RUN_MASK) -typedef struct _GtkSignal GtkSignal; -typedef struct _GtkSignalInfo GtkSignalInfo; -typedef struct _GtkHandler GtkHandler; -typedef struct _GtkHandlerInfo GtkHandlerInfo; -typedef struct _GtkEmission GtkEmission; +typedef struct _GtkSignal GtkSignal; +typedef struct _GtkSignalHash GtkSignalHash; +typedef struct _GtkHandler GtkHandler; +typedef struct _GtkHandlerInfo GtkHandlerInfo; +typedef struct _GtkEmission GtkEmission; +typedef struct _GtkDisconnectInfo GtkDisconnectInfo; typedef void (*GtkSignalMarshaller0) (GtkObject *object, - gpointer data); - -struct _GtkSignalInfo -{ - gchar *name; - GtkType object_type; - guint signal_type; -}; + gpointer data); struct _GtkSignal { - GtkSignalInfo info; - guint function_offset; - GtkSignalRunType run_type; + guint signal_id; + GtkType object_type; + gchar *name; + guint function_offset; + GtkSignalRunType run_type; GtkSignalMarshaller marshaller; - GtkType return_val; - GtkType *params; - guint nparams; + GtkType return_val; + GtkType *params; + guint nparams; +}; + +struct _GtkSignalHash +{ + GtkType object_type; + guint name_key_id; + guint signal_id; }; struct _GtkHandler { - guint id; - guint blocked : 20; - guint object_signal : 1; - guint after : 1; - guint no_marshal : 1; - guint16 ref_count; - guint16 signal_type; - GtkSignalFunc func; - gpointer func_data; + guint id; + guint blocked : 20; + guint object_signal : 1; + guint after : 1; + guint no_marshal : 1; + guint16 ref_count; + guint16 signal_id; + GtkSignalFunc func; + gpointer func_data; GtkSignalDestroy destroy_func; - GtkHandler *prev; - GtkHandler *next; + GtkHandler *prev; + GtkHandler *next; }; struct _GtkHandlerInfo { - GtkObject *object; + GtkObject *object; GtkSignalMarshaller marshaller; - GtkArg *params; - GtkType *param_types; - GtkType return_val; - GtkSignalRunType run_type; - guint nparams; - guint signal_type; + GtkArg *params; + GtkType *param_types; + GtkType return_val; + GtkSignalRunType run_type; + guint nparams; + guint signal_id; }; struct _GtkEmission { GtkObject *object; - guint signal_type; + guint signal_id; +}; + +struct _GtkDisconnectInfo +{ + GtkObject *object1; + guint disconnect_handler1; + guint signal_handler; + GtkObject *object2; + guint disconnect_handler2; }; -static void gtk_signal_init (void); -static guint gtk_signal_hash (guint *key); -static gint gtk_signal_compare (guint *a, - guint *b); -static guint gtk_signal_info_hash (GtkSignalInfo *a); -static gint gtk_signal_info_compare (GtkSignalInfo *a, - GtkSignalInfo *b); +static guint gtk_signal_hash (const gpointer h); +static gint gtk_signal_compare (const gpointer h1, + const gpointer h2); static GtkHandler* gtk_signal_handler_new (void); -static void gtk_signal_handler_ref (GtkHandler *handler); -static void gtk_signal_handler_unref (GtkHandler *handler, +static void gtk_signal_handler_ref (GtkHandler *handler); +static void gtk_signal_handler_unref (GtkHandler *handler, GtkObject *object); -static void gtk_signal_handler_insert (GtkObject *object, +static void gtk_signal_handler_insert (GtkObject *object, GtkHandler *handler); -static void gtk_signal_real_emit (GtkObject *object, - guint signal_type, - va_list args); +static void gtk_signal_real_emit (GtkObject *object, + guint signal_type, + va_list args); static GtkHandler* gtk_signal_get_handlers (GtkObject *object, - guint signal_type); -static guint gtk_signal_connect_by_type (GtkObject *object, - guint signal_type, + guint signal_type); +static guint gtk_signal_connect_by_type (GtkObject *object, + guint signal_id, GtkSignalFunc func, gpointer func_data, GtkSignalDestroy destroy_func, - gint object_signal, - gint after, - gint no_marshal); -static GtkEmission* gtk_emission_new (void); -static void gtk_emission_destroy (GtkEmission *emission); -static void gtk_emission_add (GList **emissions, + gint object_signal, + gint after, + gint no_marshal); +static guint gtk_alive_disconnecter (GtkDisconnectInfo *info); +static GtkEmission* gtk_emission_new (void); +static void gtk_emission_destroy (GtkEmission *emission); +static void gtk_emission_add (GList **emissions, GtkObject *object, - guint signal_type); -static void gtk_emission_remove (GList **emissions, + guint signal_type); +static void gtk_emission_remove (GList **emissions, GtkObject *object, - guint signal_type); -static gint gtk_emission_check (GList *emissions, + guint signal_type); +static gint gtk_emission_check (GList *emissions, GtkObject *object, - guint signal_type); -static gint gtk_handlers_run (GtkHandler *handlers, + guint signal_type); +static gint gtk_handlers_run (GtkHandler *handlers, GtkHandlerInfo *info, - gint after); -static void gtk_params_get (GtkArg *params, - guint nparams, - GtkType *param_types, - GtkType return_val, - va_list args); + gint after); +static void gtk_params_get (GtkArg *params, + guint nparams, + GtkType *param_types, + GtkType return_val, + va_list args); + +#define LOOKUP_SIGNAL_ID(signal_id) ( \ + signal_id > 0 && signal_id < gtk_n_signals ? \ + (GtkSignal*) gtk_signals + signal_id : \ + (GtkSignal*) 0 \ +) -static gint initialize = TRUE; -static GHashTable *signal_hash_table = NULL; -static GHashTable *signal_info_hash_table = NULL; -static guint next_signal = 1; -static guint next_handler_id = 1; +static GtkSignalMarshal global_marshaller = NULL; +static GtkSignalDestroy global_destroy_notify = NULL; -static const gchar *handler_key = "gtk-signal-handlers"; -static guint handler_key_id = 0; - -static GMemChunk *handler_mem_chunk = NULL; -static GMemChunk *emission_mem_chunk = NULL; +static guint gtk_handler_id = 1; +static guint handler_key_id = 0; +static GHashTable *gtk_signal_hash_table = NULL; +static GtkSignal *gtk_signals = NULL; +static guint gtk_n_signals = 0; +static GMemChunk *gtk_signal_hash_mem_chunk = NULL; +static GMemChunk *gtk_handler_mem_chunk = NULL; +static GMemChunk *gtk_emission_mem_chunk = NULL; +static GMemChunk *gtk_disconnect_info_mem_chunk = NULL; static GList *current_emissions = NULL; static GList *stop_emissions = NULL; static GList *restart_emissions = NULL; -static GtkSignalMarshal global_marshaller = NULL; -static GtkSignalDestroy global_destroy_notify = NULL; - - -guint -gtk_signal_new (const gchar *name, - GtkSignalRunType run_type, - GtkType object_type, - guint function_offset, - GtkSignalMarshaller marshaller, - GtkType return_val, - guint nparams, - ...) +static GtkSignal* +gtk_signal_next_and_invalidate (void) { - GtkType *params; - guint i; - va_list args; - guint return_id; + static guint gtk_n_free_signals = 0; + register GtkSignal *signal; + register guint new_signal_id; - g_return_val_if_fail (nparams < 16, 0); + /* don't keep *any* GtkSignal pointers across invokation of this function!!! + */ - if (nparams > 0) + if (gtk_n_free_signals == 0) { - params = g_new (GtkType, nparams); + register guint i; + register guint size; - va_start (args, nparams); + /* nearest pow + */ + size = gtk_n_signals + SIGNAL_BLOCK_SIZE; + size *= sizeof (GtkSignal); + i = 1; + while (i < size) + i <<= 1; + size = i; - for (i = 0; i < nparams; i++) - params[i] = va_arg (args, GtkType); + gtk_signals = g_realloc (gtk_signals, size); - va_end (args); + gtk_n_free_signals = size / sizeof (GtkSignal) - gtk_n_signals; + + memset (gtk_signals + gtk_n_signals, 0, gtk_n_free_signals * sizeof (GtkSignal)); } - else - params = NULL; - return_id = gtk_signal_newv (name, - run_type, - object_type, - function_offset, - marshaller, - return_val, - nparams, - params); + new_signal_id = gtk_n_signals++; + gtk_n_free_signals--; - g_free (params); + signal = LOOKUP_SIGNAL_ID (new_signal_id); + if (signal) + signal->signal_id = new_signal_id; - return return_id; + return signal; +} + +void +gtk_signal_init (void) +{ + if (!handler_key_id) + { + GtkSignal *zero; + + zero = gtk_signal_next_and_invalidate (); + g_assert (zero == NULL); + + handler_key_id = gtk_object_data_force_id ("gtk-signal-handlers"); + + gtk_signal_hash_mem_chunk = + g_mem_chunk_new ("GtkSignalHash mem chunk", + sizeof (GtkSignalHash), + sizeof (GtkSignalHash) * SIGNAL_BLOCK_SIZE, + G_ALLOC_ONLY); + gtk_handler_mem_chunk = + g_mem_chunk_new ("GtkHandler mem chunk", + sizeof (GtkHandler), + sizeof (GtkHandler) * HANDLER_BLOCK_SIZE, + G_ALLOC_AND_FREE); + gtk_emission_mem_chunk = + g_mem_chunk_new ("GtkEmission mem chunk", + sizeof (GtkEmission), + sizeof (GtkEmission) * EMISSION_BLOCK_SIZE, + G_ALLOC_AND_FREE); + gtk_disconnect_info_mem_chunk = + g_mem_chunk_new ("GtkDisconnectInfo mem chunk", + sizeof (GtkDisconnectInfo), + sizeof (GtkDisconnectInfo) * DISCONNECT_INFO_BLOCK_SIZE, + G_ALLOC_AND_FREE); + + gtk_signal_hash_table = g_hash_table_new (gtk_signal_hash, + gtk_signal_compare); + } } guint -gtk_signal_newv (const gchar *name, +gtk_signal_newv (const gchar *name, GtkSignalRunType run_type, - GtkType object_type, - guint function_offset, + GtkType object_type, + guint function_offset, GtkSignalMarshaller marshaller, - GtkType return_val, - guint nparams, + GtkType return_val, + guint nparams, GtkType *params) { GtkSignal *signal; - GtkSignalInfo info; - guint *type; + GtkSignalHash *hash; + guint type; guint i; g_return_val_if_fail (name != NULL, 0); g_return_val_if_fail (marshaller != NULL, 0); - g_return_val_if_fail (nparams < 16, 0); + g_return_val_if_fail (nparams <= GTK_MAX_SIGNAL_PARAMS, 0); if (nparams) g_return_val_if_fail (params != NULL, 0); - if (initialize) + if (!handler_key_id) gtk_signal_init (); - info.name = (char*)name; - info.object_type = object_type; - - type = g_hash_table_lookup (signal_info_hash_table, &info); + type = gtk_signal_lookup (name, object_type); if (type) { g_warning ("gtk_signal_newv(): signal \"%s\" already exists in the `%s' class ancestry\n", - name, gtk_type_name (object_type)); + name, + gtk_type_name (object_type)); return 0; } - signal = g_new (GtkSignal, 1); - signal->info.name = g_strdup (name); - signal->info.object_type = object_type; - signal->info.signal_type = next_signal++; + signal = gtk_signal_next_and_invalidate (); + + /* signal->signal_id already set */ + + signal->object_type = object_type; + signal->name = g_strdup (name); signal->function_offset = function_offset; signal->run_type = run_type; signal->marshaller = marshaller; @@ -256,10 +311,87 @@ gtk_signal_newv (const gchar *name, else signal->params = NULL; - g_hash_table_insert (signal_hash_table, &signal->info.signal_type, signal); - g_hash_table_insert (signal_info_hash_table, &signal->info, &signal->info.signal_type); + hash = g_chunk_new (GtkSignalHash, gtk_signal_hash_mem_chunk); + hash->object_type = object_type; + hash->name_key_id = gtk_object_data_force_id (signal->name); + hash->signal_id = signal->signal_id; + g_hash_table_insert (gtk_signal_hash_table, hash, (gpointer) hash->signal_id); - return signal->info.signal_type; + return signal->signal_id; +} + +guint +gtk_signal_new (const gchar *name, + GtkSignalRunType run_type, + GtkType object_type, + guint function_offset, + GtkSignalMarshaller marshaller, + GtkType return_val, + guint nparams, + ...) +{ + GtkType *params; + guint i; + va_list args; + guint signal_id; + + g_return_val_if_fail (nparams <= GTK_MAX_SIGNAL_PARAMS, 0); + + if (nparams > 0) + { + params = g_new (GtkType, nparams); + + va_start (args, nparams); + + for (i = 0; i < nparams; i++) + params[i] = va_arg (args, GtkType); + + va_end (args); + } + else + params = NULL; + + signal_id = gtk_signal_newv (name, + run_type, + object_type, + function_offset, + marshaller, + return_val, + nparams, + params); + + g_free (params); + + return signal_id; +} + +guint +gtk_signal_lookup (const gchar *name, + GtkType object_type) +{ + GtkSignalHash hash; + + g_return_val_if_fail (name != NULL, 0); + g_return_val_if_fail (GTK_TYPE_IS_A (object_type, GTK_TYPE_OBJECT), 0); + + hash.name_key_id = gtk_object_data_try_key (name); + if (hash.name_key_id) + { + while (object_type) + { + guint signal_id; + + hash.object_type = object_type; + + signal_id = (guint) g_hash_table_lookup (gtk_signal_hash_table, &hash); + if (signal_id) + return signal_id; + + object_type = gtk_type_parent (object_type); + } + } + + return 0; } GtkSignalQuery* @@ -270,14 +402,14 @@ gtk_signal_query (guint signal_id) g_return_val_if_fail (signal_id >= 1, NULL); - signal = g_hash_table_lookup (signal_hash_table, &signal_id); + signal = LOOKUP_SIGNAL_ID (signal_id); if (signal) { query = g_new (GtkSignalQuery, 1); - query->object_type = signal->info.object_type; + query->object_type = signal->object_type; query->signal_id = signal_id; - query->signal_name = signal->info.name; + query->signal_name = signal->name; query->is_user_signal = signal->function_offset == 0; query->run_type = signal->run_type; query->return_val = signal->return_val; @@ -290,36 +422,6 @@ gtk_signal_query (guint signal_id) return query; } -guint -gtk_signal_lookup (const gchar *name, - GtkType object_type) -{ - GtkSignalInfo info; - - g_return_val_if_fail (name != NULL, 0); - g_return_val_if_fail (gtk_type_is_a (object_type, GTK_TYPE_OBJECT), 0); - - if (initialize) - gtk_signal_init (); - - info.name = (char*)name; - - while (object_type) - { - guint *type; - - info.object_type = object_type; - - type = g_hash_table_lookup (signal_info_hash_table, &info); - if (type) - return *type; - - object_type = gtk_type_parent (object_type); - } - - return 0; -} - gchar* gtk_signal_name (guint signal_id) { @@ -327,16 +429,16 @@ gtk_signal_name (guint signal_id) g_return_val_if_fail (signal_id >= 1, NULL); - signal = g_hash_table_lookup (signal_hash_table, &signal_id); + signal = LOOKUP_SIGNAL_ID (signal_id); if (signal) - return signal->info.name; + return signal->name; return NULL; } void gtk_signal_emit (GtkObject *object, - guint signal_id, + guint signal_id, ...) { va_list args; @@ -344,9 +446,6 @@ gtk_signal_emit (GtkObject *object, g_return_if_fail (object != NULL); g_return_if_fail (signal_id >= 1); - if (initialize) - gtk_signal_init (); - va_start (args, signal_id); gtk_signal_real_emit (object, signal_id, args); @@ -355,94 +454,86 @@ gtk_signal_emit (GtkObject *object, } void -gtk_signal_emit_by_name (GtkObject *object, - const gchar *name, +gtk_signal_emit_by_name (GtkObject *object, + const gchar *name, ...) { - guint type; + guint signal_id; va_list args; g_return_if_fail (object != NULL); g_return_if_fail (name != NULL); - if (initialize) - gtk_signal_init (); + signal_id = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); - type = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); - - if (type >= 1) + if (signal_id >= 1) { va_start (args, name); - gtk_signal_real_emit (object, type, args); + gtk_signal_real_emit (object, signal_id, args); va_end (args); } else { g_warning ("gtk_signal_emit_by_name(): could not find signal \"%s\" in the `%s' class ancestry", - name, gtk_type_name (GTK_OBJECT_TYPE (object))); + name, + gtk_type_name (GTK_OBJECT_TYPE (object))); } } void gtk_signal_emit_stop (GtkObject *object, - guint signal_id) + guint signal_id) { g_return_if_fail (object != NULL); g_return_if_fail (signal_id >= 1); - if (initialize) - gtk_signal_init (); - if (gtk_emission_check (current_emissions, object, signal_id)) gtk_emission_add (&stop_emissions, object, signal_id); else g_warning ("gtk_signal_emit_stop(): no current emission (%u) for object `%s'", - signal_id, gtk_type_name (GTK_OBJECT_TYPE (object))); + signal_id, + gtk_type_name (GTK_OBJECT_TYPE (object))); } void -gtk_signal_emit_stop_by_name (GtkObject *object, +gtk_signal_emit_stop_by_name (GtkObject *object, const gchar *name) { - guint type; + guint signal_id; g_return_if_fail (object != NULL); g_return_if_fail (name != NULL); - if (initialize) - gtk_signal_init (); - - type = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); - if (type) - gtk_signal_emit_stop (object, type); + signal_id = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); + if (signal_id) + gtk_signal_emit_stop (object, signal_id); else g_warning ("gtk_signal_emit_stop_by_name(): could not find signal \"%s\" in the `%s' class ancestry", - name, gtk_type_name (GTK_OBJECT_TYPE (object))); + name, + gtk_type_name (GTK_OBJECT_TYPE (object))); } guint gtk_signal_n_emissions (GtkObject *object, - guint signal_id) + guint signal_id) { - GList *tmp; + GList *list; guint n; g_return_val_if_fail (object != NULL, 0); g_return_val_if_fail (GTK_IS_OBJECT (object), 0); - tmp = current_emissions; n = 0; - while (tmp) + for (list = current_emissions; list; list = list->next) { GtkEmission *emission; - emission = tmp->data; - tmp = tmp->next; + emission = list->data; if ((emission->object == object) && - (emission->signal_type == signal_id)) + (emission->signal_id == signal_id)) n++; } @@ -450,155 +541,146 @@ gtk_signal_n_emissions (GtkObject *object, } guint -gtk_signal_n_emissions_by_name (GtkObject *object, - const gchar *name) +gtk_signal_n_emissions_by_name (GtkObject *object, + const gchar *name) { - guint type; + guint signal_id; guint n; g_return_val_if_fail (object != NULL, 0); g_return_val_if_fail (GTK_IS_OBJECT (object), 0); g_return_val_if_fail (name != NULL, 0); - if (initialize) - gtk_signal_init (); - - type = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); - if (type) - n = gtk_signal_n_emissions (object, type); + signal_id = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); + if (signal_id) + n = gtk_signal_n_emissions (object, signal_id); else { g_warning ("gtk_signal_n_emissions_by_name(): could not find signal \"%s\" in the `%s' class ancestry", - name, gtk_type_name (GTK_OBJECT_TYPE (object))); + name, + gtk_type_name (GTK_OBJECT_TYPE (object))); n = 0; } - + return n; } guint -gtk_signal_connect (GtkObject *object, - const gchar *name, +gtk_signal_connect (GtkObject *object, + const gchar *name, GtkSignalFunc func, - gpointer func_data) + gpointer func_data) { - guint type; + guint signal_id; g_return_val_if_fail (object != NULL, 0); g_return_val_if_fail (GTK_IS_OBJECT (object), 0); - if (initialize) - gtk_signal_init (); - - type = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); - if (!type) + signal_id = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); + if (!signal_id) { g_warning ("gtk_signal_connect(): could not find signal \"%s\" in the `%s' class ancestry", - name, gtk_type_name (GTK_OBJECT_TYPE (object))); + name, + gtk_type_name (GTK_OBJECT_TYPE (object))); return 0; } - return gtk_signal_connect_by_type (object, type, + return gtk_signal_connect_by_type (object, signal_id, func, func_data, NULL, FALSE, FALSE, FALSE); } guint -gtk_signal_connect_after (GtkObject *object, - const gchar *name, - GtkSignalFunc func, - gpointer func_data) +gtk_signal_connect_after (GtkObject *object, + const gchar *name, + GtkSignalFunc func, + gpointer func_data) { - guint type; + guint signal_id; g_return_val_if_fail (object != NULL, 0); - if (initialize) - gtk_signal_init (); - - type = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); - if (!type) + signal_id = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); + if (!signal_id) { g_warning ("gtk_signal_connect_after(): could not find signal \"%s\" in the `%s' class ancestry", - name, gtk_type_name (GTK_OBJECT_TYPE (object))); + name, + gtk_type_name (GTK_OBJECT_TYPE (object))); return 0; } - return gtk_signal_connect_by_type (object, type, + return gtk_signal_connect_by_type (object, signal_id, func, func_data, NULL, FALSE, TRUE, FALSE); } -guint -gtk_signal_connect_full (GtkObject *object, - const gchar *name, - GtkSignalFunc func, +guint +gtk_signal_connect_full (GtkObject *object, + const gchar *name, + GtkSignalFunc func, GtkCallbackMarshal marshal, - gpointer func_data, + gpointer func_data, GtkDestroyNotify destroy_func, - gint object_signal, - gint after) + gint object_signal, + gint after) { - guint type; + guint signal_id; g_return_val_if_fail (object != NULL, 0); - if (initialize) - gtk_signal_init (); - - type = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); - if (!type) + signal_id = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); + if (!signal_id) { g_warning ("gtk_signal_connect_full(): could not find signal \"%s\" in the `%s' class ancestry", - name, gtk_type_name (GTK_OBJECT_TYPE (object))); + name, + gtk_type_name (GTK_OBJECT_TYPE (object))); return 0; } if (marshal) - return gtk_signal_connect_by_type (object, type, (GtkSignalFunc) marshal, + return gtk_signal_connect_by_type (object, signal_id, (GtkSignalFunc) marshal, func_data, destroy_func, object_signal, after, TRUE); else - return gtk_signal_connect_by_type (object, type, func, + return gtk_signal_connect_by_type (object, signal_id, func, func_data, destroy_func, object_signal, after, FALSE); } guint -gtk_signal_connect_interp (GtkObject *object, - const gchar *name, +gtk_signal_connect_interp (GtkObject *object, + const gchar *name, GtkCallbackMarshal func, - gpointer func_data, + gpointer func_data, GtkDestroyNotify destroy_func, - gint after) + gint after) { return gtk_signal_connect_full (object, name, NULL, func, func_data, destroy_func, FALSE, after); } guint -gtk_signal_connect_object (GtkObject *object, - const gchar *name, +gtk_signal_connect_object (GtkObject *object, + const gchar *name, GtkSignalFunc func, - GtkObject *slot_object) + GtkObject *slot_object) { - guint type; + guint signal_id; g_return_val_if_fail (object != NULL, 0); - /* slot_object needs to be treated as ordinary pointer */ + /* slot_object needs to be treated as ordinary pointer + */ - if (initialize) - gtk_signal_init (); - - type = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); - if (!type) + signal_id = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); + if (!signal_id) { g_warning ("gtk_signal_connect_object(): could not find signal \"%s\" in the `%s' class ancestry", - name, gtk_type_name (GTK_OBJECT_TYPE (object))); + name, + gtk_type_name (GTK_OBJECT_TYPE (object))); return 0; } - return gtk_signal_connect_by_type (object, type, + return gtk_signal_connect_by_type (object, signal_id, func, slot_object, NULL, TRUE, FALSE, FALSE); } @@ -606,58 +688,33 @@ gtk_signal_connect_object (GtkObject *object, guint gtk_signal_connect_object_after (GtkObject *object, const gchar *name, - GtkSignalFunc func, + GtkSignalFunc func, GtkObject *slot_object) { - guint type; + guint signal_id; g_return_val_if_fail (object != NULL, 0); - if (initialize) - gtk_signal_init (); - - type = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); - if (!type) + signal_id = gtk_signal_lookup (name, GTK_OBJECT_TYPE (object)); + if (!signal_id) { g_warning ("gtk_signal_connect_object_after(): could not find signal \"%s\" in the `%s' class ancestry", - name, gtk_type_name (GTK_OBJECT_TYPE (object))); + name, + gtk_type_name (GTK_OBJECT_TYPE (object))); return 0; } - return gtk_signal_connect_by_type (object, type, + return gtk_signal_connect_by_type (object, signal_id, func, slot_object, NULL, TRUE, TRUE, FALSE); } -typedef struct _GtkDisconnectInfo GtkDisconnectInfo; -struct _GtkDisconnectInfo -{ - GtkObject *object1; - guint disconnect_handler1; - guint signal_handler; - GtkObject *object2; - guint disconnect_handler2; -}; - -static guint -gtk_alive_disconnecter (GtkDisconnectInfo *info) -{ - g_return_val_if_fail (info != NULL, 0); - - gtk_signal_disconnect (info->object1, info->disconnect_handler1); - gtk_signal_disconnect (info->object1, info->signal_handler); - gtk_signal_disconnect (info->object2, info->disconnect_handler2); - g_free (info); - - return 0; -} - void -gtk_signal_connect_while_alive (GtkObject *object, - const gchar *signal, - GtkSignalFunc func, - gpointer func_data, - GtkObject *alive_object) +gtk_signal_connect_while_alive (GtkObject *object, + const gchar *signal, + GtkSignalFunc func, + gpointer func_data, + GtkObject *alive_object) { GtkDisconnectInfo *info; @@ -668,26 +725,28 @@ gtk_signal_connect_while_alive (GtkObject *object, g_return_if_fail (alive_object != NULL); g_return_if_fail (GTK_IS_OBJECT (alive_object)); - info = g_new (GtkDisconnectInfo, 1); + info = g_chunk_new (GtkDisconnectInfo, gtk_disconnect_info_mem_chunk); info->object1 = object; info->object2 = alive_object; info->signal_handler = gtk_signal_connect (object, signal, func, func_data); - info->disconnect_handler1 = gtk_signal_connect_object (info->object1, - "destroy", - GTK_SIGNAL_FUNC (gtk_alive_disconnecter), - (GtkObject*) info); - info->disconnect_handler2 = gtk_signal_connect_object (info->object2, - "destroy", - GTK_SIGNAL_FUNC (gtk_alive_disconnecter), - (GtkObject*) info); + info->disconnect_handler1 = + gtk_signal_connect_object (info->object1, + "destroy", + GTK_SIGNAL_FUNC (gtk_alive_disconnecter), + (GtkObject*) info); + info->disconnect_handler2 = + gtk_signal_connect_object (info->object2, + "destroy", + GTK_SIGNAL_FUNC (gtk_alive_disconnecter), + (GtkObject*) info); } void -gtk_signal_connect_object_while_alive (GtkObject *object, - const gchar *signal, - GtkSignalFunc func, - GtkObject *alive_object) +gtk_signal_connect_object_while_alive (GtkObject *object, + const gchar *signal, + GtkSignalFunc func, + GtkObject *alive_object) { GtkDisconnectInfo *info; @@ -698,24 +757,26 @@ gtk_signal_connect_object_while_alive (GtkObject *object, g_return_if_fail (alive_object != NULL); g_return_if_fail (GTK_IS_OBJECT (alive_object)); - info = g_new (GtkDisconnectInfo, 1); + info = g_chunk_new (GtkDisconnectInfo, gtk_disconnect_info_mem_chunk); info->object1 = object; info->object2 = alive_object; info->signal_handler = gtk_signal_connect_object (object, signal, func, alive_object); - info->disconnect_handler1 = gtk_signal_connect_object (info->object1, - "destroy", - GTK_SIGNAL_FUNC (gtk_alive_disconnecter), - (GtkObject*) info); - info->disconnect_handler2 = gtk_signal_connect_object (info->object2, - "destroy", - GTK_SIGNAL_FUNC (gtk_alive_disconnecter), - (GtkObject*) info); + info->disconnect_handler1 = + gtk_signal_connect_object (info->object1, + "destroy", + GTK_SIGNAL_FUNC (gtk_alive_disconnecter), + (GtkObject*) info); + info->disconnect_handler2 = + gtk_signal_connect_object (info->object2, + "destroy", + GTK_SIGNAL_FUNC (gtk_alive_disconnecter), + (GtkObject*) info); } void gtk_signal_disconnect (GtkObject *object, - guint handler_id) + guint handler_id) { GtkHandler *handler; @@ -742,7 +803,7 @@ gtk_signal_disconnect (GtkObject *object, void gtk_signal_disconnect_by_func (GtkObject *object, GtkSignalFunc func, - gpointer data) + gpointer data) { GtkHandler *handler; gint found_one; @@ -776,7 +837,7 @@ gtk_signal_disconnect_by_func (GtkObject *object, void gtk_signal_disconnect_by_data (GtkObject *object, - gpointer data) + gpointer data) { GtkHandler *handler; gint found_one; @@ -831,9 +892,9 @@ gtk_signal_handler_block (GtkObject *object, } void -gtk_signal_handler_block_by_func (GtkObject *object, - GtkSignalFunc func, - gpointer data) +gtk_signal_handler_block_by_func (GtkObject *object, + GtkSignalFunc func, + gpointer data) { GtkHandler *handler; gint found_one; @@ -896,9 +957,6 @@ gtk_signal_handler_unblock (GtkObject *object, g_return_if_fail (object != NULL); g_return_if_fail (handler_id > 0); - if (initialize) - gtk_signal_init (); - handler = gtk_object_get_data_by_id (object, handler_key_id); while (handler) @@ -918,9 +976,9 @@ gtk_signal_handler_unblock (GtkObject *object, } void -gtk_signal_handler_unblock_by_func (GtkObject *object, +gtk_signal_handler_unblock_by_func (GtkObject *object, GtkSignalFunc func, - gpointer data) + gpointer data) { GtkHandler *handler; gint found_one; @@ -964,7 +1022,7 @@ gtk_signal_handler_unblock_by_data (GtkObject *object, { if ((handler->id > 0) && (handler->func_data == data) && - (handler->blocked > 0)) + (handler->blocked > 0)) { handler->blocked -= 1; found_one = TRUE; @@ -1006,8 +1064,8 @@ gtk_signal_handlers_destroy (GtkObject *object) void gtk_signal_default_marshaller (GtkObject *object, GtkSignalFunc func, - gpointer func_data, - GtkArg *params) + gpointer func_data, + GtkArg *params) { GtkSignalMarshaller0 rfunc; @@ -1024,45 +1082,37 @@ gtk_signal_set_funcs (GtkSignalMarshal marshal_func, global_destroy_notify = destroy_func; } - -static void -gtk_signal_init (void) -{ - if (initialize) - { - initialize = FALSE; - signal_hash_table = g_hash_table_new ((GHashFunc) gtk_signal_hash, - (GCompareFunc) gtk_signal_compare); - signal_info_hash_table = g_hash_table_new ((GHashFunc) gtk_signal_info_hash, - (GCompareFunc) gtk_signal_info_compare); - } -} - static guint -gtk_signal_hash (guint *key) +gtk_signal_hash (const gpointer h) { - return *key; + register GtkSignalHash *hash = h; + + return hash->object_type ^ hash->name_key_id; } static gint -gtk_signal_compare (guint *a, - guint *b) +gtk_signal_compare (const gpointer h1, + const gpointer h2) { - return (*a == *b); + register GtkSignalHash *hash1 = h1; + register GtkSignalHash *hash2 = h2; + + return (hash1->name_key_id == hash2->name_key_id && + hash1->object_type == hash2->object_type); } static guint -gtk_signal_info_hash (GtkSignalInfo *a) +gtk_alive_disconnecter (GtkDisconnectInfo *info) { - return (g_str_hash (a->name) + a->object_type); -} - -static gint -gtk_signal_info_compare (GtkSignalInfo *a, - GtkSignalInfo *b) -{ - return ((a->object_type == b->object_type) && - g_str_equal (a->name, b->name)); + g_return_val_if_fail (info != NULL, 0); + + gtk_signal_disconnect (info->object1, info->disconnect_handler1); + gtk_signal_disconnect (info->object1, info->signal_handler); + gtk_signal_disconnect (info->object2, info->disconnect_handler2); + + g_mem_chunk_free (gtk_disconnect_info_mem_chunk, info); + + return 0; } static GtkHandler* @@ -1070,15 +1120,11 @@ gtk_signal_handler_new (void) { GtkHandler *handler; - if (!handler_mem_chunk) - handler_mem_chunk = g_mem_chunk_new ("handler mem chunk", sizeof (GtkHandler), - 1024, G_ALLOC_AND_FREE); - - handler = g_chunk_new (GtkHandler, handler_mem_chunk); + handler = g_chunk_new (GtkHandler, gtk_handler_mem_chunk); handler->id = 0; handler->blocked = 0; - handler->signal_type = 0; + handler->signal_id = 0; handler->object_signal = FALSE; handler->after = FALSE; handler->no_marshal = FALSE; @@ -1102,7 +1148,15 @@ static void gtk_signal_handler_unref (GtkHandler *handler, GtkObject *object) { + if (!handler->ref_count) + { + /* FIXME: i wanna get removed somewhen */ + g_warning ("gtk_signal_handler_unref(): handler with ref_count==0!"); + return; + } + handler->ref_count -= 1; + if (handler->ref_count == 0) { if (handler->destroy_func) @@ -1117,7 +1171,7 @@ gtk_signal_handler_unref (GtkHandler *handler, if (handler->next) handler->next->prev = handler->prev; - g_mem_chunk_free (handler_mem_chunk, handler); + g_mem_chunk_free (gtk_handler_mem_chunk, handler); } } @@ -1132,15 +1186,11 @@ gtk_signal_handler_insert (GtkObject *object, tmp = gtk_object_get_data_by_id (object, handler_key_id); if (!tmp) - { - if (!handler_key_id) - handler_key_id = gtk_object_data_force_id (handler_key); - gtk_object_set_data_by_id (object, handler_key_id, handler); - } + gtk_object_set_data_by_id (object, handler_key_id, handler); else while (tmp) { - if (tmp->signal_type < handler->signal_type) + if (tmp->signal_id < handler->signal_id) { if (tmp->prev) { @@ -1166,35 +1216,34 @@ gtk_signal_handler_insert (GtkObject *object, static void gtk_signal_real_emit (GtkObject *object, - guint signal_type, - va_list args) + guint signal_id, + va_list args) { - GtkSignal *signal; - GtkHandler *handlers; + GtkSignal *signal; + GtkHandler *handlers; GtkHandlerInfo info; - guchar **signal_func_offset; - GtkArg params[MAX_PARAMS]; + guchar **signal_func_offset; + GtkArg params[GTK_MAX_SIGNAL_PARAMS]; - signal = g_hash_table_lookup (signal_hash_table, &signal_type); + signal = LOOKUP_SIGNAL_ID (signal_id); g_return_if_fail (signal != NULL); - g_return_if_fail (gtk_type_is_a (GTK_OBJECT_TYPE (object), - signal->info.object_type)); + g_return_if_fail (GTK_TYPE_IS_A (GTK_OBJECT_TYPE (object), signal->object_type)); if ((signal->run_type & GTK_RUN_NO_RECURSE) && - gtk_emission_check (current_emissions, object, signal_type)) + gtk_emission_check (current_emissions, object, signal_id)) { - gtk_emission_add (&restart_emissions, object, signal_type); + gtk_emission_add (&restart_emissions, object, signal_id); return; } gtk_params_get (params, signal->nparams, signal->params, signal->return_val, args); - gtk_emission_add (¤t_emissions, object, signal_type); + gtk_emission_add (¤t_emissions, object, signal_id); gtk_object_ref (object); -restart: + emission_restart: if (GTK_RUN_TYPE (signal->run_type) != GTK_RUN_LAST && signal->function_offset != 0) { signal_func_offset = (guchar**) ((guchar*) object->klass + @@ -1211,18 +1260,20 @@ restart: info.return_val = signal->return_val; info.nparams = signal->nparams; info.run_type = signal->run_type; - info.signal_type = signal_type; + info.signal_id = signal_id; - handlers = gtk_signal_get_handlers (object, signal_type); + handlers = gtk_signal_get_handlers (object, signal_id); switch (gtk_handlers_run (handlers, &info, FALSE)) { - case DONE: - goto done; - case RESTART: - goto restart; + case EMISSION_CONTINUE: + break; + case EMISSION_RESTART: + goto emission_restart; + case EMISSION_DONE: + goto emission_done; } - if (GTK_RUN_TYPE (signal->run_type) != GTK_RUN_FIRST && signal->function_offset != 0) + if (GTK_RUN_TYPE (signal->run_type) != GTK_RUN_FIRST && signal->function_offset != 0) { signal_func_offset = (guchar**) ((guchar*) object->klass + signal->function_offset); @@ -1231,39 +1282,38 @@ restart: NULL, params); } - handlers = gtk_signal_get_handlers (object, signal_type); + handlers = gtk_signal_get_handlers (object, signal_id); switch (gtk_handlers_run (handlers, &info, TRUE)) { - case DONE: - goto done; - case RESTART: - goto restart; + case EMISSION_CONTINUE: + break; + case EMISSION_RESTART: + goto emission_restart; + case EMISSION_DONE: + goto emission_done; } -done: + emission_done: - gtk_emission_remove (¤t_emissions, object, signal_type); + gtk_emission_remove (¤t_emissions, object, signal_id); if (signal->run_type & GTK_RUN_NO_RECURSE) - gtk_emission_remove (&restart_emissions, object, signal_type); + gtk_emission_remove (&restart_emissions, object, signal_id); gtk_object_unref (object); } static GtkHandler* gtk_signal_get_handlers (GtkObject *object, - guint signal_type) + guint signal_id) { GtkHandler *handlers; - g_return_val_if_fail (object != NULL, NULL); - g_return_val_if_fail (signal_type >= 1, NULL); - handlers = gtk_object_get_data_by_id (object, handler_key_id); while (handlers) { - if (handlers->signal_type == signal_type) + if (handlers->signal_id == signal_id) return handlers; handlers = handlers->next; } @@ -1272,8 +1322,8 @@ gtk_signal_get_handlers (GtkObject *object, } guint -gtk_signal_handler_pending (GtkObject *object, - guint signal_id, +gtk_signal_handler_pending (GtkObject *object, + guint signal_id, gboolean may_be_blocked) { GtkHandler *handlers; @@ -1285,7 +1335,7 @@ gtk_signal_handler_pending (GtkObject *object, handlers = gtk_signal_get_handlers (object, signal_id); handler_id = 0; - while (handlers && handlers->signal_type == signal_id) + while (handlers && handlers->signal_id == signal_id) { if (handlers->id > 0 && (may_be_blocked || handlers->blocked == 0)) @@ -1301,14 +1351,14 @@ gtk_signal_handler_pending (GtkObject *object, } static guint -gtk_signal_connect_by_type (GtkObject *object, - guint signal_type, +gtk_signal_connect_by_type (GtkObject *object, + guint signal_id, GtkSignalFunc func, - gpointer func_data, + gpointer func_data, GtkSignalDestroy destroy_func, - gint object_signal, - gint after, - gint no_marshal) + gint object_signal, + gint after, + gint no_marshal) { GtkObjectClass *class; GtkHandler *handler; @@ -1335,7 +1385,7 @@ gtk_signal_connect_by_type (GtkObject *object, nsignals = class->nsignals; for (i = 0; i < nsignals; i++) - if (object_signals[i] == signal_type) + if (object_signals[i] == signal_id) { found_it = TRUE; break; @@ -1351,14 +1401,14 @@ gtk_signal_connect_by_type (GtkObject *object, if (!found_it) { g_warning ("gtk_signal_connect_by_type(): could not find signal id (%u) in the `%s' class ancestry", - signal_type, - gtk_type_name (class->type)); + signal_id, + gtk_type_name (object->klass->type)); return 0; } handler = gtk_signal_handler_new (); - handler->id = next_handler_id++; - handler->signal_type = signal_type; + handler->id = gtk_handler_id++; + handler->signal_id = signal_id; handler->object_signal = object_signal; handler->func = func; handler->func_data = func_data; @@ -1375,14 +1425,10 @@ gtk_emission_new (void) { GtkEmission *emission; - if (!emission_mem_chunk) - emission_mem_chunk = g_mem_chunk_new ("emission mem chunk", sizeof (GtkEmission), - 1024, G_ALLOC_AND_FREE); - - emission = g_chunk_new (GtkEmission, emission_mem_chunk); + emission = g_chunk_new (GtkEmission, gtk_emission_mem_chunk); emission->object = NULL; - emission->signal_type = 0; + emission->signal_id = 0; return emission; } @@ -1390,13 +1436,13 @@ gtk_emission_new (void) static void gtk_emission_destroy (GtkEmission *emission) { - g_mem_chunk_free (emission_mem_chunk, emission); + g_mem_chunk_free (gtk_emission_mem_chunk, emission); } static void -gtk_emission_add (GList **emissions, +gtk_emission_add (GList **emissions, GtkObject *object, - guint signal_type) + guint signal_id) { GtkEmission *emission; @@ -1405,15 +1451,15 @@ gtk_emission_add (GList **emissions, emission = gtk_emission_new (); emission->object = object; - emission->signal_type = signal_type; + emission->signal_id = signal_id; *emissions = g_list_prepend (*emissions, emission); } static void gtk_emission_remove (GList **emissions, - GtkObject *object, - guint signal_type) + GtkObject *object, + guint signal_id) { GtkEmission *emission; GList *tmp; @@ -1426,7 +1472,7 @@ gtk_emission_remove (GList **emissions, emission = tmp->data; if ((emission->object == object) && - (emission->signal_type == signal_type)) + (emission->signal_id == signal_id)) { gtk_emission_destroy (emission); *emissions = g_list_remove_link (*emissions, tmp); @@ -1441,7 +1487,7 @@ gtk_emission_remove (GList **emissions, static gint gtk_emission_check (GList *emissions, GtkObject *object, - guint signal_type) + guint signal_id) { GtkEmission *emission; GList *tmp; @@ -1453,18 +1499,18 @@ gtk_emission_check (GList *emissions, tmp = tmp->next; if ((emission->object == object) && - (emission->signal_type == signal_type)) + (emission->signal_id == signal_id)) return TRUE; } return FALSE; } static gint -gtk_handlers_run (GtkHandler *handlers, +gtk_handlers_run (GtkHandler *handlers, GtkHandlerInfo *info, - gint after) + gint after) { - while (handlers && handlers->signal_type == info->signal_type) + while (handlers && handlers->signal_id == info->signal_id) { GtkHandler *handlers_next; @@ -1498,26 +1544,26 @@ gtk_handlers_run (GtkHandler *handlers, info->param_types, info->return_val); - if (gtk_emission_check (stop_emissions, info->object, - info->signal_type)) + if (gtk_emission_check (stop_emissions, info->object, + info->signal_id)) { gtk_emission_remove (&stop_emissions, info->object, - info->signal_type); + info->signal_id); if (info->run_type & GTK_RUN_NO_RECURSE) gtk_emission_remove (&restart_emissions, info->object, - info->signal_type); + info->signal_id); gtk_signal_handler_unref (handlers, info->object); - return DONE; + return EMISSION_DONE; } else if ((info->run_type & GTK_RUN_NO_RECURSE) && gtk_emission_check (restart_emissions, info->object, - info->signal_type)) + info->signal_id)) { gtk_emission_remove (&restart_emissions, info->object, - info->signal_type); + info->signal_id); gtk_signal_handler_unref (handlers, info->object); - return RESTART; + return EMISSION_RESTART; } } @@ -1526,15 +1572,15 @@ gtk_handlers_run (GtkHandler *handlers, handlers = handlers_next; } - return 0; + return EMISSION_CONTINUE; } static void -gtk_params_get (GtkArg *params, - guint nparams, - GtkType *param_types, - GtkType return_val, - va_list args) +gtk_params_get (GtkArg *params, + guint nparams, + GtkType *param_types, + GtkType return_val, + va_list args) { gint i; diff --git a/gtk/gtksignal.h b/gtk/gtksignal.h index 95961b6e09..293c0d6dd2 100644 --- a/gtk/gtksignal.h +++ b/gtk/gtksignal.h @@ -32,9 +32,9 @@ extern "C" { #ifdef offsetof -#define GTK_SIGNAL_OFFSET(t, f) ((int) offsetof (t, f)) +#define GTK_SIGNAL_OFFSET(t, f) ((gint) offsetof (t, f)) #else /* offsetof */ -#define GTK_SIGNAL_OFFSET(t, f) ((int) ((char*) &((t*) 0)->f)) +#define GTK_SIGNAL_OFFSET(t, f) ((gint) ((gchar*) &((t*) 0)->f)) #endif /* offsetof */ @@ -53,13 +53,14 @@ struct _GtkSignalQuery GtkType object_type; guint signal_id; const gchar *signal_name; - gboolean is_user_signal; + guint is_user_signal : 1; GtkSignalRunType run_type; GtkType return_val; guint nparams; const GtkType *params; }; +void gtk_signal_init (void); guint gtk_signal_new (const gchar *name, GtkSignalRunType run_type, GtkType object_type, diff --git a/gtk/gtktypebuiltins.c b/gtk/gtktypebuiltins.c index d42ba64b94..683a73083c 100644 --- a/gtk/gtktypebuiltins.c +++ b/gtk/gtktypebuiltins.c @@ -56,4 +56,3 @@ { "GdkWindow", GTK_TYPE_BOXED }, { "GdkEvent", GTK_TYPE_BOXED }, { "GdkColor", GTK_TYPE_BOXED }, - { "GtkTooltips", GTK_TYPE_BOXED }, diff --git a/gtk/gtktypebuiltins.h b/gtk/gtktypebuiltins.h index 4cf9f8f403..ac7827864a 100644 --- a/gtk/gtktypebuiltins.h +++ b/gtk/gtktypebuiltins.h @@ -56,5 +56,4 @@ #define GTK_TYPE_GDK_WINDOW (gtk_type_builtins[53]) #define GTK_TYPE_GDK_EVENT (gtk_type_builtins[54]) #define GTK_TYPE_GDK_COLOR (gtk_type_builtins[55]) -#define GTK_TYPE_TOOLTIPS (gtk_type_builtins[56]) -#define GTK_TYPE_NUM_BUILTINS 57 +#define GTK_TYPE_NUM_BUILTINS 56 diff --git a/gtk/gtktypeutils.c b/gtk/gtktypeutils.c index 0dd7515e1c..5bf4028266 100644 --- a/gtk/gtktypeutils.c +++ b/gtk/gtktypeutils.c @@ -21,51 +21,102 @@ #include "gtktypeutils.h" +#define TYPE_NODES_BLOCK_SIZE (200) + typedef struct _GtkTypeNode GtkTypeNode; struct _GtkTypeNode { GtkType type; - gint init_class; - gpointer klass; GtkTypeInfo type_info; - GtkTypeNode *parent; - GList *children; + guint n_supers; + GtkType *supers; + GtkType parent_type; + gpointer klass; + GList *children_types; }; -static void gtk_type_insert (guint parent_type, - GtkType type, - GtkTypeInfo *type_info); -static void gtk_type_class_init (GtkTypeNode *node); -static void gtk_type_object_init (GtkTypeNode *node, - gpointer object); -static guint gtk_type_hash (GtkType *key); -static gint gtk_type_compare (GtkType *a, - GtkType *b); -static guint gtk_type_name_hash (const char *key); -static gint gtk_type_name_compare (const char *a, - const char *b); -static void gtk_type_init_builtin_types (void); +#define LOOKUP_TYPE_NODE(node_var, type) { \ + if (type > 0) \ + { \ + register GtkType sqn = GTK_TYPE_SEQNO (type); \ + if (sqn < n_type_nodes) \ + node_var = type_nodes + sqn; \ + else \ + node_var = NULL; \ + } \ + else \ + node_var = NULL; \ +} + +static void gtk_type_class_init (GtkTypeNode *node); +static guint gtk_type_name_hash (const char *key); +static gint gtk_type_name_compare (const char *a, + const char *b); +static void gtk_type_init_builtin_types (void); + +static GtkTypeNode *type_nodes = NULL; +static guint n_type_nodes = 0; +static GHashTable *type_name_2_type_ht = NULL; -static int initialize = TRUE; -static GHashTable *type_hash_table = NULL; -static GHashTable *name_hash_table = NULL; +static GtkTypeNode* +gtk_type_node_next_and_invalidate (void) +{ + static guint n_free_type_nodes = 0; + register GtkTypeNode *node; + register GtkType new_type; + /* don't keep *any* GtkTypeNode pointers across invokation of this function!!! + */ + + if (n_free_type_nodes == 0) + { + register guint i; + register guint size; + + /* nearest pow + */ + size = n_type_nodes + TYPE_NODES_BLOCK_SIZE; + size *= sizeof (GtkTypeNode); + i = 1; + while (i < size) + i <<= 1; + size = i; + + type_nodes = g_realloc (type_nodes, size); + + n_free_type_nodes = size / sizeof (GtkTypeNode) - n_type_nodes; + + memset (type_nodes + n_type_nodes, 0, n_free_type_nodes * sizeof (GtkTypeNode)); + } + + new_type = n_type_nodes++; + n_free_type_nodes--; + + LOOKUP_TYPE_NODE (node, new_type); + if (node) + node->type = new_type; + + return node; +} void gtk_type_init (void) { - if (initialize) + if (n_type_nodes == 0) { + GtkTypeNode *zero; + g_assert (sizeof (GtkType) >= 4); - initialize = FALSE; - type_hash_table = g_hash_table_new ((GHashFunc) gtk_type_hash, - (GCompareFunc) gtk_type_compare); - name_hash_table = g_hash_table_new ((GHashFunc) gtk_type_name_hash, - (GCompareFunc) gtk_type_name_compare); + zero = gtk_type_node_next_and_invalidate (); + g_assert (zero == NULL); + + type_name_2_type_ht = g_hash_table_new ((GHashFunc) gtk_type_name_hash, + (GCompareFunc) gtk_type_name_compare); + gtk_type_init_builtin_types (); } } @@ -74,22 +125,64 @@ GtkType gtk_type_unique (GtkType parent_type, GtkTypeInfo *type_info) { - static guint next_seqno = 0; - GtkType new_type; + GtkTypeNode *new_node; + GtkTypeNode *parent; + guint i; g_return_val_if_fail (type_info != NULL, 0); + if (g_hash_table_lookup (type_name_2_type_ht, type_info->type_name)) + { + g_warning ("gtk_type_unique(): type `%s' already exists.", type_info->type_name); + return 0; + } + if (parent_type) + { + GtkTypeNode *tmp_node; - if (initialize) - gtk_type_init (); + LOOKUP_TYPE_NODE (tmp_node, parent_type); + if (!tmp_node) + { + g_warning ("gtk_type_unique(): unknown parent type `%u'.", parent_type); + return 0; + } + } - next_seqno++; - if (parent_type == GTK_TYPE_INVALID) - new_type = next_seqno; + /* relookup pointer afterwards. + */ + new_node = gtk_type_node_next_and_invalidate (); + + if (parent_type) + { + new_node->type = GTK_TYPE_MAKE (parent_type, new_node->type); + LOOKUP_TYPE_NODE (parent, parent_type); + } else - new_type = GTK_TYPE_MAKE (GTK_FUNDAMENTAL_TYPE (parent_type), next_seqno); - gtk_type_insert (parent_type, new_type, type_info); + { + g_assert (new_node->type <= 0xff); + parent = NULL; + } - return new_type; + new_node->type_info = *type_info; + new_node->type_info.type_name = g_strdup (type_info->type_name); + new_node->n_supers = parent ? parent->n_supers + 1 : 0; + new_node->supers = g_new0 (GtkType, new_node->n_supers + 1); + new_node->parent_type = parent_type; + new_node->klass = NULL; + new_node->children_types = NULL; + + if (parent) + parent->children_types = g_list_append (parent->children_types, (gpointer) new_node->type); + + parent = new_node; + for (i = 0; i < new_node->n_supers + 1; i++) + { + new_node->supers[i] = parent->type; + LOOKUP_TYPE_NODE (parent, parent->parent_type); + } + + g_hash_table_insert (type_name_2_type_ht, new_node->type_info.type_name, (gpointer) new_node->type); + + return new_node->type; } gchar* @@ -97,10 +190,7 @@ gtk_type_name (GtkType type) { GtkTypeNode *node; - if (initialize) - gtk_type_init (); - - node = g_hash_table_lookup (type_hash_table, &type); + LOOKUP_TYPE_NODE (node, type); if (node) return node->type_info.type_name; @@ -111,15 +201,14 @@ gtk_type_name (GtkType type) GtkType gtk_type_from_name (const gchar *name) { - GtkTypeNode *node; + if (type_name_2_type_ht) + { + GtkType type; + + type = (GtkType) g_hash_table_lookup (type_name_2_type_ht, (gpointer) name); - if (initialize) - gtk_type_init (); - - node = g_hash_table_lookup (name_hash_table, (gpointer) name); - - if (node) - return node->type; + return type; + } return 0; } @@ -129,29 +218,46 @@ gtk_type_parent (GtkType type) { GtkTypeNode *node; - if (initialize) - gtk_type_init (); - - node = g_hash_table_lookup (type_hash_table, &type); - - if (node && node->parent) - return node->parent->type; + LOOKUP_TYPE_NODE (node, type); + if (node) + return node->parent_type; return 0; } +gpointer +gtk_type_parent_class (GtkType type) +{ + GtkTypeNode *node; + + LOOKUP_TYPE_NODE (node, type); + g_return_val_if_fail (node != NULL, NULL); + + if (node) + { + LOOKUP_TYPE_NODE (node, node->parent_type); + + if (node) + { + if (!node->klass) + gtk_type_class_init (node); + + return node->klass; + } + } + + return NULL; +} + gpointer gtk_type_class (GtkType type) { GtkTypeNode *node; - if (initialize) - gtk_type_init (); - - node = g_hash_table_lookup (type_hash_table, &type); + LOOKUP_TYPE_NODE (node, type); g_return_val_if_fail (node != NULL, NULL); - if (node->init_class) + if (!node->klass) gtk_type_class_init (node); return node->klass; @@ -161,17 +267,27 @@ gpointer gtk_type_new (GtkType type) { GtkTypeNode *node; - gpointer object; + GtkObject *object; + gpointer klass; + guint i; - if (initialize) - gtk_type_init (); - - node = g_hash_table_lookup (type_hash_table, &type); + LOOKUP_TYPE_NODE (node, type); g_return_val_if_fail (node != NULL, NULL); - object = g_new0 (guchar, node->type_info.object_size); - ((GtkObject*) object)->klass = gtk_type_class (type); - gtk_type_object_init (node, object); + klass = gtk_type_class (type); + object = g_malloc0 (node->type_info.object_size); + object->klass = klass; + + for (i = node->n_supers; i > 0; i--) + { + GtkTypeNode *pnode; + + LOOKUP_TYPE_NODE (pnode, node->supers[i]); + if (pnode->type_info.object_init_func) + (* pnode->type_info.object_init_func) (object); + } + if (node->type_info.object_init_func) + (* node->type_info.object_init_func) (object); return object; } @@ -182,10 +298,7 @@ gtk_type_describe_heritage (GtkType type) GtkTypeNode *node; gint first; - if (initialize) - gtk_type_init (); - - node = g_hash_table_lookup (type_hash_table, &type); + LOOKUP_TYPE_NODE (node, type); first = TRUE; while (node) @@ -201,7 +314,7 @@ gtk_type_describe_heritage (GtkType type) else g_print ("\n"); - node = node->parent; + LOOKUP_TYPE_NODE (node, node->parent_type); } } @@ -209,62 +322,61 @@ void gtk_type_describe_tree (GtkType type, gint show_size) { - static gint indent = 0; GtkTypeNode *node; - GtkTypeNode *child; - GList *children; - gint old_indent; - gint i; - - if (initialize) - gtk_type_init (); - - node = g_hash_table_lookup (type_hash_table, &type); - - for (i = 0; i < indent; i++) - g_print (" "); - - if (node->type_info.type_name) - g_print ("%s", node->type_info.type_name); - else - g_print (""); - - if (show_size) - g_print (" ( %d bytes )\n", node->type_info.object_size); - else - g_print ("\n"); - - old_indent = indent; - indent += 4; - - children = node->children; - while (children) + + LOOKUP_TYPE_NODE (node, type); + + if (node) { - child = children->data; - children = children->next; - - gtk_type_describe_tree (child->type, show_size); + static gint indent = 0; + GList *list; + guint old_indent; + guint i; + + for (i = 0; i < indent; i++) + g_print (" "); + + if (node->type_info.type_name) + g_print ("%s", node->type_info.type_name); + else + g_print ("(no-name)"); + + if (show_size) + g_print (" ( %d bytes )\n", node->type_info.object_size); + else + g_print ("\n"); + + old_indent = indent; + indent += 4; + + for (list = node->children_types; list; list = list->next) + gtk_type_describe_tree ((GtkType) list->data, show_size); + + indent = old_indent; } - - indent = old_indent; } gint gtk_type_is_a (GtkType type, GtkType is_a_type) { - GtkTypeNode *node; + register GtkTypeNode *node; - if (initialize) - gtk_type_init (); + /* we already check for type==is_a_type in the + * wrapper macro GTK_TYPE_IS_A() + */ - node = g_hash_table_lookup (type_hash_table, &type); - - while (node) + LOOKUP_TYPE_NODE (node, type); + if (node) { - if (node->type == is_a_type) - return TRUE; - node = node->parent; + register GtkTypeNode *a_node; + + LOOKUP_TYPE_NODE (a_node, is_a_type); + if (a_node) + { + if (a_node->n_supers <= node->n_supers) + return node->supers[node->n_supers - a_node->n_supers] == is_a_type; + } } return FALSE; @@ -281,10 +393,7 @@ gtk_type_get_arg (GtkObject *object, g_return_if_fail (object != NULL); g_return_if_fail (arg != NULL); - if (initialize) - gtk_type_init (); - - node = g_hash_table_lookup (type_hash_table, &type); + LOOKUP_TYPE_NODE (node, type); if (node && node->type_info.arg_get_func) (* node->type_info.arg_get_func) (object, arg, arg_id); @@ -303,10 +412,7 @@ gtk_type_set_arg (GtkObject *object, g_return_if_fail (object != NULL); g_return_if_fail (arg != NULL); - if (initialize) - gtk_type_init (); - - node = g_hash_table_lookup (type_hash_table, &type); + LOOKUP_TYPE_NODE (node, type); if (node && node->type_info.arg_set_func) (* node->type_info.arg_set_func) (object, arg, arg_id); @@ -333,85 +439,46 @@ gtk_arg_copy (GtkArg *src_arg, return dest_arg; } -static void -gtk_type_insert (GtkType parent_type, - GtkType type, - GtkTypeInfo *type_info) -{ - GtkTypeNode *node; - GtkTypeNode *parent; - - parent = g_hash_table_lookup (type_hash_table, &parent_type); - - node = g_new (GtkTypeNode, 1); - node->type = type; - node->init_class = TRUE; - node->klass = NULL; - node->type_info = *type_info; - node->parent = parent; - node->children = NULL; - - if (node->parent) - node->parent->children = g_list_append (node->parent->children, node); - - g_hash_table_insert (type_hash_table, &node->type, node); - g_hash_table_insert (name_hash_table, node->type_info.type_name, node); -} - static void gtk_type_class_init (GtkTypeNode *node) { - GtkObjectClass *object_class; - - if (node->init_class) + if (!node->klass && node->type_info.class_size) { - node->init_class = FALSE; node->klass = g_new0 (guchar, node->type_info.class_size); - if (node->parent) + if (node->parent_type) { - if (node->parent->init_class) - gtk_type_class_init (node->parent); + GtkTypeNode *parent; - memcpy (node->klass, node->parent->klass, node->parent->type_info.class_size); + LOOKUP_TYPE_NODE (parent, node->parent_type); + if (!parent->klass) + gtk_type_class_init (parent); + + if (parent->klass) + memcpy (node->klass, parent->klass, parent->type_info.class_size); } - object_class = node->klass; - object_class->type = node->type; - object_class->signals = NULL; - object_class->nsignals = 0; - object_class->n_args = 0; + if (GTK_TYPE_IS_A (node->type, GTK_TYPE_OBJECT)) + { + GtkObjectClass *object_class; + /* FIXME: this initialization needs to be done through + * a function pointer someday. + */ + g_assert (node->type_info.class_size >= sizeof (GtkObjectClass)); + + object_class = node->klass; + object_class->type = node->type; + object_class->signals = NULL; + object_class->nsignals = 0; + object_class->n_args = 0; + } + if (node->type_info.class_init_func) (* node->type_info.class_init_func) (node->klass); } } -static void -gtk_type_object_init (GtkTypeNode *node, - gpointer object) -{ - if (node->parent) - gtk_type_object_init (node->parent, object); - - if (node->type_info.object_init_func) - (* node->type_info.object_init_func) (object); -} - -static guint -gtk_type_hash (GtkType *key) -{ - return GTK_TYPE_SEQNO (*key); -} - -static gint -gtk_type_compare (GtkType *a, - GtkType *b) -{ - g_return_val_if_fail(a != NULL && b != NULL, 0); - return (*a == *b); -} - static guint gtk_type_name_hash (const char *key) { @@ -477,12 +544,12 @@ gtk_type_init_builtin_types (void) { GTK_TYPE_FOREIGN, "foreign" }, { GTK_TYPE_CALLBACK, "callback" }, { GTK_TYPE_ARGS, "args" }, - + { GTK_TYPE_POINTER, "pointer" }, { GTK_TYPE_SIGNAL, "signal" }, { GTK_TYPE_C_CALLBACK, "c_callback" } }; - + static struct { char *name; GtkType parent; @@ -490,19 +557,19 @@ gtk_type_init_builtin_types (void) #include "gtktypebuiltins.c" { NULL } }; - + int i; - - for (i = 0; i < sizeof (fundamental_info)/sizeof(fundamental_info[0]); i++) + + for (i = 0; i < sizeof (fundamental_info) / sizeof (fundamental_info[0]); i++) { GtkType id; id = gtk_type_register_builtin (fundamental_info[i].name, GTK_TYPE_INVALID); g_assert (id == fundamental_info[i].enum_id); } - + gtk_object_init_type (); - + for (i = 0; builtin_info[i].name; i++) { gtk_type_builtins[i] = diff --git a/gtk/gtktypeutils.h b/gtk/gtktypeutils.h index a77feff9a1..c17a33f5e9 100644 --- a/gtk/gtktypeutils.h +++ b/gtk/gtktypeutils.h @@ -25,11 +25,12 @@ #ifdef __cplusplus extern "C" { +#pragma } #endif /* __cplusplus */ -/* Fundamental Types */ - +/* Fundamental Types + */ typedef enum { GTK_TYPE_INVALID, @@ -49,29 +50,34 @@ typedef enum GTK_TYPE_FOREIGN, GTK_TYPE_CALLBACK, GTK_TYPE_ARGS, - + GTK_TYPE_POINTER, - - /* it'd be great if the next two could be removed eventually */ + + /* It'd be great if the next two could be removed eventually + */ GTK_TYPE_SIGNAL, GTK_TYPE_C_CALLBACK, - + GTK_TYPE_OBJECT - + } GtkFundamentalType; typedef guint GtkType; -/* Builtin Types */ - +/* Builtin Types + */ extern GtkType gtk_type_builtins[]; #include -/* General Types */ - -#define GTK_TYPE_MAKE(ft, seqno) (((seqno)<<8)|ft) -#define GTK_FUNDAMENTAL_TYPE(t) ((GtkFundamentalType)((t)&0xFF)) -#define GTK_TYPE_SEQNO(t) ((t)>0xFF? (t)>>8:(t)) +/* Macros + */ +#define GTK_TYPE_MAKE(parent_t, seqno) (((seqno) << 8) | GTK_FUNDAMENTAL_TYPE (parent_t)) +#define GTK_FUNDAMENTAL_TYPE(type) ((GtkFundamentalType) ((type) & 0xFF)) +#define GTK_TYPE_SEQNO(type) ((type) > 0xFF ? (type) >> 8 : (type)) +#define GTK_TYPE_IS_A(type, is_a_type) ( \ + ((GtkType) (type)) == ((GtkType) (is_a_type)) || \ + gtk_type_is_a (((GtkType) (type)), ((GtkType) (is_a_type))) \ +) typedef struct _GtkArg GtkArg; typedef struct _GtkObject GtkObject; /* forward declaration of object type */ @@ -183,6 +189,7 @@ gchar* gtk_type_name (guint type); GtkType gtk_type_from_name (const gchar *name); GtkType gtk_type_parent (GtkType type); gpointer gtk_type_class (GtkType type); +gpointer gtk_type_parent_class (GtkType type); gpointer gtk_type_new (GtkType type); void gtk_type_describe_heritage (GtkType type); void gtk_type_describe_tree (GtkType type, diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 47ab7bd328..7205c450e7 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -999,7 +999,7 @@ gtk_widget_new (guint type, va_list args1; va_list args2; - g_return_val_if_fail (gtk_type_is_a (type, gtk_widget_get_type ()), NULL); + g_return_val_if_fail (GTK_TYPE_IS_A (type, gtk_widget_get_type ()), NULL); obj = gtk_type_new (type); @@ -1029,7 +1029,7 @@ gtk_widget_newv (guint type, guint nargs, GtkArg *args) { - g_return_val_if_fail (gtk_type_is_a (type, gtk_widget_get_type ()), NULL); + g_return_val_if_fail (GTK_TYPE_IS_A (type, gtk_widget_get_type ()), NULL); return GTK_WIDGET (gtk_object_newv (type, nargs, args)); } @@ -2268,14 +2268,14 @@ gtk_widget_grab_focus (GtkWidget *widget) parent = widget->parent; child = widget; - while (parent && !gtk_type_is_a (GTK_WIDGET_TYPE (parent), window_type)) + while (parent && !GTK_TYPE_IS_A (GTK_WIDGET_TYPE (parent), window_type)) { gtk_container_set_focus_child (GTK_CONTAINER (parent), child); child = parent; parent = parent->parent; } - if (parent && gtk_type_is_a (GTK_WIDGET_TYPE (parent), window_type)) + if (parent && GTK_TYPE_IS_A (GTK_WIDGET_TYPE (parent), window_type)) { gtk_container_set_focus_child (GTK_CONTAINER (parent), child); gtk_window_set_focus (GTK_WINDOW (parent), widget); @@ -2303,10 +2303,10 @@ gtk_widget_grab_default (GtkWidget *widget) window_type = gtk_window_get_type (); window = widget->parent; - while (window && !gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type)) + while (window && !GTK_TYPE_IS_A (GTK_WIDGET_TYPE (window), window_type)) window = window->parent; - if (window && gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type)) + if (window && GTK_TYPE_IS_A (GTK_WIDGET_TYPE (window), window_type)) gtk_window_set_default (GTK_WINDOW (window), widget); } @@ -2986,10 +2986,10 @@ gtk_widget_get_ancestor (GtkWidget *widget, { g_return_val_if_fail (widget != NULL, NULL); - while (widget && !gtk_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)) + while (widget && !GTK_TYPE_IS_A (GTK_WIDGET_TYPE (widget), widget_type)) widget = widget->parent; - if (!(widget && gtk_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))) + if (!(widget && GTK_TYPE_IS_A (GTK_WIDGET_TYPE (widget), widget_type))) return NULL; return widget; diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index 9b43d2cd59..2dfc151024 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -28,9 +28,10 @@ #ifdef __cplusplus extern "C" { +#pragma } #endif /* __cplusplus */ - - + + /* The flags that are used by GtkWidget on top of the * flags field of GtkObject. */ @@ -54,13 +55,14 @@ enum }; -/* Macro for casting a pointer to a GtkWidget pointer. +/* Macro for casting a pointer to a GtkWidget or GtkWidgetClass pointer. + * Macros for testing whether `widget' or `klass' are of type GTK_TYPE_WIDGET. */ -#define GTK_WIDGET(wid) GTK_CHECK_CAST ((wid), gtk_widget_get_type (), GtkWidget) - -/* Macro for casting the klass field of a widget to a GtkWidgetClass pointer. - */ -#define GTK_WIDGET_CLASS(klass) GTK_CHECK_CLASS_CAST ((klass), gtk_widget_get_type (), GtkWidgetClass) +#define GTK_TYPE_WIDGET (gtk_widget_get_type ()) +#define GTK_WIDGET(widget) (GTK_CHECK_CAST ((widget), GTK_TYPE_WIDGET, GtkWidget)) +#define GTK_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_WIDGET, GtkWidgetClass)) +#define GTK_IS_WIDGET(widget) (GTK_CHECK_TYPE ((widget), GTK_TYPE_WIDGET)) +#define GTK_IS_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WIDGET)) /* Macros for extracting various fields from GtkWidget and GtkWidgetClass. */ @@ -94,11 +96,6 @@ enum #define GTK_WIDGET_SET_FLAGS(wid,flag) G_STMT_START{ (GTK_WIDGET_FLAGS (wid) |= (flag)); }G_STMT_END #define GTK_WIDGET_UNSET_FLAGS(wid,flag) G_STMT_START{ (GTK_WIDGET_FLAGS (wid) &= ~(flag)); }G_STMT_END -/* Macros for testing whether "wid" is of type GtkWidget. - */ -#define GTK_IS_WIDGET(wid) GTK_CHECK_TYPE ((wid), GTK_TYPE_WIDGET) -#define GTK_TYPE_WIDGET (gtk_widget_get_type ()) - typedef struct _GtkRequisition GtkRequisition; diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 80021a68e5..2d68eb1114 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -115,10 +115,10 @@ static GtkBinClass *parent_class = NULL; static guint window_signals[LAST_SIGNAL] = { 0 }; -guint +GtkType gtk_window_get_type (void) { - static guint window_type = 0; + static GtkType window_type = 0; if (!window_type) { diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h index b96f437e75..8940f8525f 100644 --- a/gtk/gtkwindow.h +++ b/gtk/gtkwindow.h @@ -26,10 +26,17 @@ #include #include +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ -#define GTK_WINDOW(obj) GTK_CHECK_CAST (obj, gtk_window_get_type (), GtkWindow) -#define GTK_WINDOW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_window_get_type (), GtkWindowClass) -#define GTK_IS_WINDOW(obj) GTK_CHECK_TYPE (obj, gtk_window_get_type ()) + +#define GTK_TYPE_WINDOW (gtk_window_get_type ()) +#define GTK_WINDOW(obj) (GTK_CHECK_CAST (obj, GTK_TYPE_WINDOW, GtkWindow)) +#define GTK_WINDOW_CLASS(klass) (GTK_CHECK_CLASS_CAST (klass, GTK_TYPE_WINDOW, GtkWindowClass)) +#define GTK_IS_WINDOW(obj) (GTK_CHECK_TYPE (obj, GTK_TYPE_WINDOW)) +#define GTK_IS_WINDOW_CLASS(klass) (GTK_CHECK_CLASS_TYPE (klass, GTK_TYPE_WINDOW)) typedef struct _GtkWindow GtkWindow; @@ -72,12 +79,7 @@ struct _GtkWindowClass }; -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -guint gtk_window_get_type (void); +GtkType gtk_window_get_type (void); GtkWidget* gtk_window_new (GtkWindowType type); void gtk_window_set_title (GtkWindow *window, const gchar *title);