From 002d37e6e303aa57bd7c577f4e448e2e38eefa03 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 10 Jul 1998 02:33:06 +0000 Subject: [PATCH] added a new internal type GTK_TYPE_IDENTIFIER which is derived from Fri Jul 10 04:20:35 1998 Tim Janik * gtk/gtktypeutils.h: * gtk/gtktypeutils.c: added a new internal type GTK_TYPE_IDENTIFIER which is derived from GTK_TYPE_STRING. * gtk/gtkbindings.c: reworked the argument type handling. --- ChangeLog | 8 ++++ ChangeLog.pre-2-0 | 8 ++++ ChangeLog.pre-2-10 | 8 ++++ ChangeLog.pre-2-2 | 8 ++++ ChangeLog.pre-2-4 | 8 ++++ ChangeLog.pre-2-6 | 8 ++++ ChangeLog.pre-2-8 | 8 ++++ gtk/gtkbindings.c | 109 ++++++++++++++++++++++++++++----------------- gtk/gtkbindings.h | 24 +++++----- gtk/gtktypeutils.c | 11 +++++ gtk/gtktypeutils.h | 9 +++- 11 files changed, 156 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f8cc96116..f768c3f152 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Jul 10 04:20:35 1998 Tim Janik + + * gtk/gtktypeutils.h: + * gtk/gtktypeutils.c: added a new internal type GTK_TYPE_IDENTIFIER + which is derived from GTK_TYPE_STRING. + + * gtk/gtkbindings.c: reworked the argument type handling. + Thu Jul 9 21:03:19 CDT 1998 Shawn T. Amundson * gtk/gtkpreview.c: add in just enough support for 1 or 4 bits diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 4f8cc96116..f768c3f152 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,11 @@ +Fri Jul 10 04:20:35 1998 Tim Janik + + * gtk/gtktypeutils.h: + * gtk/gtktypeutils.c: added a new internal type GTK_TYPE_IDENTIFIER + which is derived from GTK_TYPE_STRING. + + * gtk/gtkbindings.c: reworked the argument type handling. + Thu Jul 9 21:03:19 CDT 1998 Shawn T. Amundson * gtk/gtkpreview.c: add in just enough support for 1 or 4 bits diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 4f8cc96116..f768c3f152 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +Fri Jul 10 04:20:35 1998 Tim Janik + + * gtk/gtktypeutils.h: + * gtk/gtktypeutils.c: added a new internal type GTK_TYPE_IDENTIFIER + which is derived from GTK_TYPE_STRING. + + * gtk/gtkbindings.c: reworked the argument type handling. + Thu Jul 9 21:03:19 CDT 1998 Shawn T. Amundson * gtk/gtkpreview.c: add in just enough support for 1 or 4 bits diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 4f8cc96116..f768c3f152 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,11 @@ +Fri Jul 10 04:20:35 1998 Tim Janik + + * gtk/gtktypeutils.h: + * gtk/gtktypeutils.c: added a new internal type GTK_TYPE_IDENTIFIER + which is derived from GTK_TYPE_STRING. + + * gtk/gtkbindings.c: reworked the argument type handling. + Thu Jul 9 21:03:19 CDT 1998 Shawn T. Amundson * gtk/gtkpreview.c: add in just enough support for 1 or 4 bits diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 4f8cc96116..f768c3f152 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +Fri Jul 10 04:20:35 1998 Tim Janik + + * gtk/gtktypeutils.h: + * gtk/gtktypeutils.c: added a new internal type GTK_TYPE_IDENTIFIER + which is derived from GTK_TYPE_STRING. + + * gtk/gtkbindings.c: reworked the argument type handling. + Thu Jul 9 21:03:19 CDT 1998 Shawn T. Amundson * gtk/gtkpreview.c: add in just enough support for 1 or 4 bits diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 4f8cc96116..f768c3f152 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +Fri Jul 10 04:20:35 1998 Tim Janik + + * gtk/gtktypeutils.h: + * gtk/gtktypeutils.c: added a new internal type GTK_TYPE_IDENTIFIER + which is derived from GTK_TYPE_STRING. + + * gtk/gtkbindings.c: reworked the argument type handling. + Thu Jul 9 21:03:19 CDT 1998 Shawn T. Amundson * gtk/gtkpreview.c: add in just enough support for 1 or 4 bits diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 4f8cc96116..f768c3f152 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +Fri Jul 10 04:20:35 1998 Tim Janik + + * gtk/gtktypeutils.h: + * gtk/gtktypeutils.c: added a new internal type GTK_TYPE_IDENTIFIER + which is derived from GTK_TYPE_STRING. + + * gtk/gtkbindings.c: reworked the argument type handling. + Thu Jul 9 21:03:19 CDT 1998 Shawn T. Amundson * gtk/gtkpreview.c: add in just enough support for 1 or 4 bits diff --git a/gtk/gtkbindings.c b/gtk/gtkbindings.c index 50222147d3..a7193d8032 100644 --- a/gtk/gtkbindings.c +++ b/gtk/gtkbindings.c @@ -30,13 +30,6 @@ /* --- defines --- */ #define BINDING_MOD_MASK() (gtk_accelerator_get_default_mod_mask () | GDK_RELEASE_MASK) -#define BINDING_TYPE_INT (GTK_TYPE_INT) -#define BINDING_TYPE_LONG (GTK_TYPE_LONG) -#define BINDING_TYPE_FLOAT (GTK_TYPE_FLOAT) -#define BINDING_TYPE_DOUBLE (GTK_TYPE_DOUBLE) -#define BINDING_TYPE_STRING (GTK_TYPE_STRING) -#define BINDING_TYPE_IDENTIFIER (42) - /* --- variables --- */ static GHashTable *binding_entry_hash_table = NULL; @@ -68,8 +61,7 @@ binding_signal_free (GtkBindingSignal *sig) for (i = 0; i < sig->n_args; i++) { - if (sig->args[i].arg_type == BINDING_TYPE_STRING || - sig->args[i].arg_type == BINDING_TYPE_IDENTIFIER) + if (GTK_FUNDAMENTAL_TYPE (sig->args[i].arg_type) == GTK_TYPE_STRING) g_free (sig->args[i].d.string_data); } g_free (sig->args); @@ -270,47 +262,57 @@ binding_compose_params (GtkBindingArg *args, valid = TRUE; for (i = 0; i < query->nparams && valid; i++) { + GtkType param_ftype; + params->type = *types; params->name = NULL; - switch (args->arg_type) + param_ftype = GTK_FUNDAMENTAL_TYPE (params->type); + switch (GTK_FUNDAMENTAL_TYPE (args->arg_type)) { - case BINDING_TYPE_DOUBLE: - if (params->type == GTK_TYPE_FLOAT) + case GTK_TYPE_DOUBLE: + if (param_ftype == GTK_TYPE_FLOAT) GTK_VALUE_FLOAT (*params) = args->d.double_data; - else if (params->type == GTK_TYPE_DOUBLE) + else if (param_ftype == GTK_TYPE_DOUBLE) GTK_VALUE_DOUBLE (*params) = args->d.double_data; else valid = FALSE; break; - case BINDING_TYPE_LONG: - if (params->type == GTK_TYPE_BOOL && + case GTK_TYPE_LONG: + if (param_ftype == GTK_TYPE_BOOL && (args->d.long_data == 0 || args->d.long_data == 1)) GTK_VALUE_BOOL (*params) = args->d.long_data; - else if (params->type == GTK_TYPE_INT) + else if (param_ftype == GTK_TYPE_INT || + param_ftype == GTK_TYPE_ENUM) GTK_VALUE_INT (*params) = args->d.long_data; - else if (params->type == GTK_TYPE_UINT && + else if ((param_ftype == GTK_TYPE_UINT || + param_ftype == GTK_TYPE_FLAGS) && args->d.long_data >= 0) GTK_VALUE_UINT (*params) = args->d.long_data; - else if (params->type == GTK_TYPE_LONG) + else if (param_ftype == GTK_TYPE_LONG) GTK_VALUE_LONG (*params) = args->d.long_data; - else if (params->type == GTK_TYPE_ULONG && + else if (param_ftype == GTK_TYPE_ULONG && args->d.long_data >= 0) GTK_VALUE_ULONG (*params) = args->d.long_data; - else if (params->type == GTK_TYPE_FLOAT) + else if (param_ftype == GTK_TYPE_FLOAT) GTK_VALUE_FLOAT (*params) = args->d.long_data; - else if (params->type == GTK_TYPE_DOUBLE) + else if (param_ftype == GTK_TYPE_DOUBLE) GTK_VALUE_DOUBLE (*params) = args->d.long_data; else valid = FALSE; break; - case BINDING_TYPE_STRING: - if (params->type == GTK_TYPE_STRING) + case GTK_TYPE_STRING: + if (param_ftype == GTK_TYPE_STRING) GTK_VALUE_STRING (*params) = args->d.string_data; + else if (param_ftype == GTK_TYPE_ENUM || + param_ftype == GTK_TYPE_FLAGS) + { + /* FIXME: we need identifier lookups here */ + valid = FALSE; + } else valid = FALSE; break; - case BINDING_TYPE_IDENTIFIER: default: valid = FALSE; break; @@ -566,26 +568,28 @@ gtk_binding_entry_add_signall (GtkBindingSet *binding_set, binding_signal_free (signal); return; } - arg->arg_type = tmp_arg->arg_type; - switch (tmp_arg->arg_type) + switch (GTK_FUNDAMENTAL_TYPE (tmp_arg->arg_type)) { - case BINDING_TYPE_INT: - case BINDING_TYPE_LONG: + case GTK_TYPE_LONG: + arg->arg_type = GTK_TYPE_LONG; arg->d.long_data = tmp_arg->d.long_data; break; - case BINDING_TYPE_FLOAT: - case BINDING_TYPE_DOUBLE: + case GTK_TYPE_DOUBLE: + arg->arg_type = GTK_TYPE_DOUBLE; arg->d.double_data = tmp_arg->d.double_data; break; - case BINDING_TYPE_STRING: - if (!tmp_arg->d.string_data) + case GTK_TYPE_STRING: + if (tmp_arg->arg_type != GTK_TYPE_IDENTIFIER) + arg->arg_type = GTK_TYPE_STRING; + else + arg->arg_type = GTK_TYPE_IDENTIFIER; + arg->d.string_data = g_strdup (tmp_arg->d.string_data); + if (!arg->d.string_data) { g_warning ("gtk_binding_entry_add_signall(): value of `string' arg[%u] is `NULL'", n); - arg->d.string_data = NULL; binding_signal_free (signal); return; } - arg->d.string_data = g_strdup (tmp_arg->d.string_data); break; default: g_warning ("gtk_binding_entry_add_signall(): unsupported type `%s' for arg[%u]", @@ -637,28 +641,51 @@ gtk_binding_entry_add_signal (GtkBindingSet *binding_set, slist = g_slist_prepend (slist, arg); arg->arg_type = va_arg (args, GtkType); - switch (arg->arg_type) + switch (GTK_FUNDAMENTAL_TYPE (arg->arg_type)) { - case BINDING_TYPE_INT: + case GTK_TYPE_CHAR: + arg->arg_type = GTK_TYPE_LONG; + arg->d.long_data = va_arg (args, gchar); + break; + case GTK_TYPE_BOOL: + arg->arg_type = GTK_TYPE_LONG; + arg->d.long_data = va_arg (args, gboolean) != 0; + break; + case GTK_TYPE_INT: + case GTK_TYPE_UINT: + arg->arg_type = GTK_TYPE_LONG; arg->d.long_data = va_arg (args, gint); break; - case BINDING_TYPE_LONG: + case GTK_TYPE_LONG: + case GTK_TYPE_ULONG: + arg->arg_type = GTK_TYPE_LONG; arg->d.long_data = va_arg (args, glong); break; - case BINDING_TYPE_FLOAT: + case GTK_TYPE_FLOAT: + arg->arg_type = GTK_TYPE_DOUBLE; arg->d.double_data = va_arg (args, gfloat); break; - case BINDING_TYPE_DOUBLE: + case GTK_TYPE_DOUBLE: + arg->arg_type = GTK_TYPE_DOUBLE; arg->d.double_data = va_arg (args, gdouble); break; - case BINDING_TYPE_STRING: + case GTK_TYPE_STRING: + if (arg->arg_type != GTK_TYPE_IDENTIFIER) + arg->arg_type = GTK_TYPE_STRING; arg->d.string_data = va_arg (args, gchar*); if (!arg->d.string_data) { - g_warning ("gtk_binding_entry_add_signal(): value of `string' arg[%u] is `NULL'", i); + g_warning ("gtk_binding_entry_add_signal(): type `%s' arg[%u] is `NULL'", + gtk_type_name (arg->arg_type), + i); i += n_args + 1; } break; + case GTK_TYPE_ENUM: + case GTK_TYPE_FLAGS: + arg->arg_type = GTK_TYPE_LONG; + arg->d.long_data = va_arg (args, gint); + break; default: g_warning ("gtk_binding_entry_add_signal(): unsupported type `%s' for arg[%u]", gtk_type_name (arg->arg_type), i); diff --git a/gtk/gtkbindings.h b/gtk/gtkbindings.h index 15df76b3cb..fc3012ba62 100644 --- a/gtk/gtkbindings.h +++ b/gtk/gtkbindings.h @@ -113,8 +113,9 @@ struct _GtkBindingArg } d; }; -/* Binding sets - */ + +/* Application-level methods */ + GtkBindingSet* gtk_binding_set_new (const gchar *set_name); GtkBindingSet* gtk_binding_set_by_class(gpointer object_class); GtkBindingSet* gtk_binding_set_find (const gchar *set_name); @@ -129,26 +130,29 @@ gboolean gtk_binding_set_activate (GtkBindingSet *binding_set, void gtk_binding_entry_clear (GtkBindingSet *binding_set, guint keyval, guint modifiers); -void gtk_binding_entry_remove (GtkBindingSet *binding_set, - guint keyval, - guint modifiers); void gtk_binding_entry_add_signal (GtkBindingSet *binding_set, guint keyval, guint modifiers, const gchar *signal_name, guint n_args, ...); -void gtk_binding_entry_add_signall (GtkBindingSet *binding_set, - guint keyval, - guint modifiers, - const gchar *signal_name, - GSList *binding_args); void gtk_binding_set_add_path (GtkBindingSet *binding_set, GtkPathType path_type, const gchar *path_pattern, GtkPathPriorityType priority); +/* Non-public methods */ + +void gtk_binding_entry_remove (GtkBindingSet *binding_set, + guint keyval, + guint modifiers); +void gtk_binding_entry_add_signall (GtkBindingSet *binding_set, + guint keyval, + guint modifiers, + const gchar *signal_name, + GSList *binding_args); + diff --git a/gtk/gtktypeutils.c b/gtk/gtktypeutils.c index ac0f9323d5..44f240ef45 100644 --- a/gtk/gtktypeutils.c +++ b/gtk/gtktypeutils.c @@ -746,3 +746,14 @@ gtk_type_init_builtin_types (void) (*builtin_info[i].type_id) = type_id; } } + +GtkType +gtk_identifier_get_type (void) +{ + static GtkType identifier_type = 0; + + if (!identifier_type) + identifier_type = gtk_type_register_intern ("GtkIdentifier", GTK_TYPE_STRING, NULL); + + return identifier_type; +} diff --git a/gtk/gtktypeutils.h b/gtk/gtktypeutils.h index 98e4968315..bf1d8aff1b 100644 --- a/gtk/gtktypeutils.h +++ b/gtk/gtktypeutils.h @@ -59,7 +59,9 @@ typedef enum GTK_TYPE_SIGNAL, GTK_TYPE_C_CALLBACK, - GTK_TYPE_OBJECT + GTK_TYPE_OBJECT, + + GTK_FUNDAMENTAL_TYPE_LAST } GtkFundamentalType; typedef guint GtkType; @@ -68,10 +70,13 @@ typedef guint GtkType; */ #include +#define GTK_TYPE_IDENTIFIER (gtk_identifier_get_type ()) +GtkType gtk_identifier_get_type (void); + /* 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_FUNDAMENTAL_TYPE(type) ((GtkFundamentalType) ((type) & 0xFF)) #define GTK_TYPE_SEQNO(type) ((type) > 0xFF ? (type) >> 8 : (type)) typedef struct _GtkArg GtkArg;