Re: bug in signal lookup?
- From: Paolo Molaro <lupus lettere unipd it>
- To: gtk-devel-list redhat com
- Subject: Re: bug in signal lookup?
- Date: Sat, 9 Jan 1999 12:08:33 +0100
On Fri, Jan 08, 1999 at 06:51:33PM +0100, Paolo Molaro wrote:
> There are two solutions to this: have an hook for type generation
> (that can be of some use to interpreted languages also) or have a
> function that initailizes a class's signals.
Here is a patch against the latest cvs code: it doesn't break
binary compatibility and it's very straightforward, so I plan
to check it in soon.
With this patch the programmer can have an hook called at
object/type creation. Only the GtkTypeQuery info is exposed.
I think this is very useful for language bindings, so they
can more easily add runtime support for new types.
Comments welcome.
lupus
Index: gtktypeutils.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktypeutils.c,v
retrieving revision 1.50
diff -u -r1.50 gtktypeutils.c
--- gtktypeutils.c 1998/12/20 01:24:40 1.50
+++ gtktypeutils.c 1999/01/09 10:55:46
@@ -37,7 +37,6 @@
GMemChunk *mem_chunk;
};
-
#define LOOKUP_TYPE_NODE(node_var, type) { \
GtkTypeNode *__node = NULL; \
GtkType sqn = GTK_TYPE_SEQNO (type); \
@@ -66,6 +65,7 @@
static guint n_ftype_nodes = 0;
static GHashTable *type_name_2_type_ht = NULL;
+static GHookList *creation_hook_list = NULL;
static GtkTypeNode*
gtk_type_node_next_and_invalidate (GtkType parent_type)
@@ -228,6 +228,15 @@
return new_node->type;
}
+static gboolean
+gtk_creation_marshaller (GHook* hook, gpointer data)
+{
+ GtkTypeQuery *query = (GtkTypeQuery*) data;
+ GtkCreationHook func = hook->func;
+
+ return func(query, hook->data);
+}
+
GtkType
gtk_type_unique (GtkType parent_type,
const GtkTypeInfo *type_info)
@@ -253,7 +262,17 @@
if (!new_type)
g_free (type_name);
-
+ else if ( creation_hook_list )
+ {
+ GtkTypeQuery data;
+ data.type = new_type;
+ data.type_name = type_name;
+ data.object_size = type_info->object_size;
+ data.class_size = type_info->class_size;
+
+ g_hook_list_marshal_check(creation_hook_list, FALSE, gtk_creation_marshaller, &data);
+ }
+
return new_type;
}
@@ -1014,4 +1033,41 @@
identifier_type = gtk_type_register_intern ("GtkIdentifier", GTK_TYPE_STRING, NULL);
return identifier_type;
+}
+
+guint
+gtk_type_add_creation_hook (GtkCreationHook hook_func,
+ gpointer data,
+ GDestroyNotify destroy)
+{
+ static guint seq_id =1;
+ GHook * hook;
+
+ g_return_val_if_fail(hook_func != NULL, 0);
+
+ if (!creation_hook_list)
+ {
+ creation_hook_list = g_new(GHookList, 1);
+ g_hook_list_init(creation_hook_list, sizeof(GHook));
+ }
+
+ hook = g_hook_alloc (creation_hook_list);
+ hook->data = data;
+ hook->func = hook_func;
+ hook->destroy = destroy;
+
+ creation_hook_list->seq_id = seq_id;
+ g_hook_prepend(creation_hook_list, hook);
+ seq_id = creation_hook_list->seq_id;
+
+ return hook->hook_id;
+}
+
+void
+gtk_type_remove_creation_hook (guint hook_id)
+{
+ g_return_if_fail(hook_id != 0);
+
+ if (!creation_hook_list || !g_hook_destroy(creation_hook_list, hook_id))
+ g_warning("gtk_type_remove_creation_hook(): could not find hook (%u)", hook_id);
}
Index: gtktypeutils.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktypeutils.h,v
retrieving revision 1.41
diff -u -r1.41 gtktypeutils.h
--- gtktypeutils.h 1998/12/08 23:57:25 1.41
+++ gtktypeutils.h 1999/01/09 10:55:48
@@ -153,8 +153,9 @@
GtkSignalFunc func,
gpointer func_data,
GtkArg *args);
+typedef gboolean (*GtkCreationHook) (GtkTypeQuery *type_info,
+ gpointer data);
-
/* deprecated */
typedef void (*GtkArgGetFunc) (GtkObject*, GtkArg*, guint);
typedef void (*GtkArgSetFunc) (GtkObject*, GtkArg*, guint);
@@ -361,8 +362,11 @@
* must not modify data pointed to by the members of GtkTypeQuery
*/
GtkTypeQuery* gtk_type_query (GtkType type);
-
+guint gtk_type_add_creation_hook (GtkCreationHook hook,
+ gpointer data,
+ GDestroyNotify destroy);
+void gtk_type_remove_creation_hook (guint hook_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]