mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-29 15:01:23 +00:00
bindings: Make gtk_binding_parse_signal() use GVariantBuilder
And because it's the last user of GtkBindingArg and gtk_binding_entry_add_signall(), also remove those two.
This commit is contained in:
parent
4675d74e42
commit
06660874ee
@ -66,7 +66,6 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct _GtkBindingEntry GtkBindingEntry;
|
typedef struct _GtkBindingEntry GtkBindingEntry;
|
||||||
typedef struct _GtkBindingSignal GtkBindingSignal;
|
typedef struct _GtkBindingSignal GtkBindingSignal;
|
||||||
typedef struct _GtkBindingArg GtkBindingArg;
|
|
||||||
typedef struct _GtkBindingSignalSignal GtkBindingSignalSignal;
|
typedef struct _GtkBindingSignalSignal GtkBindingSignalSignal;
|
||||||
typedef struct _GtkBindingSignalAction GtkBindingSignalAction;
|
typedef struct _GtkBindingSignalAction GtkBindingSignalAction;
|
||||||
typedef struct _GtkBindingSignalCallback GtkBindingSignalCallback;
|
typedef struct _GtkBindingSignalCallback GtkBindingSignalCallback;
|
||||||
@ -123,24 +122,6 @@ struct _GtkBindingEntry
|
|||||||
GtkBindingSignal *signals;
|
GtkBindingSignal *signals;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* GtkBindingArg:
|
|
||||||
* @arg_type: implementation detail
|
|
||||||
*
|
|
||||||
* A #GtkBindingArg holds the data associated with
|
|
||||||
* an argument for a key binding signal emission as
|
|
||||||
* stored in #GtkBindingSignal.
|
|
||||||
*/
|
|
||||||
struct _GtkBindingArg
|
|
||||||
{
|
|
||||||
GType arg_type;
|
|
||||||
union {
|
|
||||||
glong long_data;
|
|
||||||
gdouble double_data;
|
|
||||||
gchar *string_data;
|
|
||||||
} d;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
GTK_BINDING_SIGNAL,
|
GTK_BINDING_SIGNAL,
|
||||||
@ -1116,65 +1097,6 @@ gtk_binding_entry_add_signal_variant (GtkBindingSet *binding_set,
|
|||||||
*signal_p = signal;
|
*signal_p = signal;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gtk_binding_entry_add_signall (GtkBindingSet *binding_set,
|
|
||||||
guint keyval,
|
|
||||||
GdkModifierType modifiers,
|
|
||||||
const gchar *signal_name,
|
|
||||||
GSList *binding_args)
|
|
||||||
{
|
|
||||||
GSList *slist;
|
|
||||||
guint n = 0;
|
|
||||||
GVariantBuilder builder;
|
|
||||||
|
|
||||||
g_return_if_fail (binding_set != NULL);
|
|
||||||
g_return_if_fail (signal_name != NULL);
|
|
||||||
|
|
||||||
g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
|
|
||||||
|
|
||||||
for (slist = binding_args; slist; slist = slist->next)
|
|
||||||
{
|
|
||||||
GtkBindingArg *tmp_arg;
|
|
||||||
|
|
||||||
tmp_arg = slist->data;
|
|
||||||
if (!tmp_arg)
|
|
||||||
{
|
|
||||||
g_warning ("gtk_binding_entry_add_signall(): arg[%u] is 'NULL'", n);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (G_TYPE_FUNDAMENTAL (tmp_arg->arg_type))
|
|
||||||
{
|
|
||||||
case G_TYPE_LONG:
|
|
||||||
g_variant_builder_add (&builder, "x", (gint64) tmp_arg->d.long_data);
|
|
||||||
break;
|
|
||||||
case G_TYPE_DOUBLE:
|
|
||||||
g_variant_builder_add (&builder, "d", (double) tmp_arg->d.double_data);
|
|
||||||
break;
|
|
||||||
case G_TYPE_STRING:
|
|
||||||
if (!tmp_arg->d.string_data)
|
|
||||||
{
|
|
||||||
g_warning ("gtk_binding_entry_add_signall(): value of 'string' arg[%u] is 'NULL'", n);
|
|
||||||
g_variant_builder_clear (&builder);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g_variant_builder_add (&builder, "s", (gint64) tmp_arg->d.string_data);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
g_warning ("gtk_binding_entry_add_signall(): unsupported type '%s' for arg[%u]",
|
|
||||||
g_type_name (tmp_arg->arg_type), n);
|
|
||||||
g_variant_builder_clear (&builder);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_binding_entry_add_signal_variant (binding_set,
|
|
||||||
keyval,
|
|
||||||
modifiers,
|
|
||||||
signal_name,
|
|
||||||
g_variant_builder_end (&builder));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gtk_binding_entry_add_signal:
|
* gtk_binding_entry_add_signal:
|
||||||
* @binding_set: a #GtkBindingSet to install an entry for
|
* @binding_set: a #GtkBindingSet to install an entry for
|
||||||
@ -1378,12 +1300,11 @@ gtk_binding_parse_signal (GScanner *scanner,
|
|||||||
{
|
{
|
||||||
gchar *signal;
|
gchar *signal;
|
||||||
guint expected_token = 0;
|
guint expected_token = 0;
|
||||||
GSList *args;
|
|
||||||
GSList *slist;
|
|
||||||
gboolean done;
|
gboolean done;
|
||||||
gboolean negate;
|
gboolean negate;
|
||||||
gboolean need_arg;
|
gboolean need_arg;
|
||||||
gboolean seen_comma;
|
gboolean seen_comma;
|
||||||
|
GVariantBuilder builder;
|
||||||
|
|
||||||
g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
|
g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
|
||||||
|
|
||||||
@ -1403,8 +1324,8 @@ gtk_binding_parse_signal (GScanner *scanner,
|
|||||||
signal = g_strdup (scanner->value.v_string);
|
signal = g_strdup (scanner->value.v_string);
|
||||||
g_scanner_get_next_token (scanner);
|
g_scanner_get_next_token (scanner);
|
||||||
|
|
||||||
|
g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
|
||||||
negate = FALSE;
|
negate = FALSE;
|
||||||
args = NULL;
|
|
||||||
done = FALSE;
|
done = FALSE;
|
||||||
need_arg = TRUE;
|
need_arg = TRUE;
|
||||||
seen_comma = FALSE;
|
seen_comma = FALSE;
|
||||||
@ -1412,8 +1333,6 @@ gtk_binding_parse_signal (GScanner *scanner,
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
GtkBindingArg *arg;
|
|
||||||
|
|
||||||
if (need_arg)
|
if (need_arg)
|
||||||
expected_token = G_TOKEN_INT;
|
expected_token = G_TOKEN_INT;
|
||||||
else
|
else
|
||||||
@ -1426,17 +1345,13 @@ gtk_binding_parse_signal (GScanner *scanner,
|
|||||||
case G_TOKEN_FLOAT:
|
case G_TOKEN_FLOAT:
|
||||||
if (need_arg)
|
if (need_arg)
|
||||||
{
|
{
|
||||||
need_arg = FALSE;
|
|
||||||
arg = g_new (GtkBindingArg, 1);
|
|
||||||
arg->arg_type = G_TYPE_DOUBLE;
|
|
||||||
arg->d.double_data = scanner->value.v_float;
|
|
||||||
|
|
||||||
if (negate)
|
if (negate)
|
||||||
{
|
g_variant_builder_add (&builder, "d", (double) scanner->value.v_float);
|
||||||
arg->d.double_data = - arg->d.double_data;
|
else
|
||||||
negate = FALSE;
|
g_variant_builder_add (&builder, "d", (double) - scanner->value.v_float);
|
||||||
}
|
|
||||||
args = g_slist_prepend (args, arg);
|
need_arg = FALSE;
|
||||||
|
negate = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
@ -1445,17 +1360,13 @@ gtk_binding_parse_signal (GScanner *scanner,
|
|||||||
case G_TOKEN_INT:
|
case G_TOKEN_INT:
|
||||||
if (need_arg)
|
if (need_arg)
|
||||||
{
|
{
|
||||||
need_arg = FALSE;
|
|
||||||
arg = g_new (GtkBindingArg, 1);
|
|
||||||
arg->arg_type = G_TYPE_LONG;
|
|
||||||
arg->d.long_data = scanner->value.v_int;
|
|
||||||
|
|
||||||
if (negate)
|
if (negate)
|
||||||
{
|
g_variant_builder_add (&builder, "x", (gint64) - scanner->value.v_int);
|
||||||
arg->d.long_data = - arg->d.long_data;
|
else
|
||||||
negate = FALSE;
|
g_variant_builder_add (&builder, "x", (gint64) scanner->value.v_int);
|
||||||
}
|
|
||||||
args = g_slist_prepend (args, arg);
|
need_arg = FALSE;
|
||||||
|
negate = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
@ -1464,10 +1375,7 @@ gtk_binding_parse_signal (GScanner *scanner,
|
|||||||
if (need_arg && !negate)
|
if (need_arg && !negate)
|
||||||
{
|
{
|
||||||
need_arg = FALSE;
|
need_arg = FALSE;
|
||||||
arg = g_new (GtkBindingArg, 1);
|
g_variant_builder_add (&builder, "s", scanner->value.v_string);
|
||||||
arg->arg_type = G_TYPE_STRING;
|
|
||||||
arg->d.string_data = g_strdup (scanner->value.v_string);
|
|
||||||
args = g_slist_prepend (args, arg);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
@ -1477,10 +1385,7 @@ gtk_binding_parse_signal (GScanner *scanner,
|
|||||||
if (need_arg && !negate)
|
if (need_arg && !negate)
|
||||||
{
|
{
|
||||||
need_arg = FALSE;
|
need_arg = FALSE;
|
||||||
arg = g_new (GtkBindingArg, 1);
|
g_variant_builder_add (&builder, "s", scanner->value.v_string);
|
||||||
arg->arg_type = G_TYPE_STRING;
|
|
||||||
arg->d.string_data = g_strdup (scanner->value.v_identifier);
|
|
||||||
args = g_slist_prepend (args, arg);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
@ -1509,12 +1414,11 @@ gtk_binding_parse_signal (GScanner *scanner,
|
|||||||
case ')':
|
case ')':
|
||||||
if (!(need_arg && seen_comma) && !negate)
|
if (!(need_arg && seen_comma) && !negate)
|
||||||
{
|
{
|
||||||
args = g_slist_reverse (args);
|
gtk_binding_entry_add_signal_variant (binding_set,
|
||||||
gtk_binding_entry_add_signall (binding_set,
|
keyval,
|
||||||
keyval,
|
modifiers,
|
||||||
modifiers,
|
signal,
|
||||||
signal,
|
g_variant_builder_end (&builder));
|
||||||
args);
|
|
||||||
expected_token = G_TOKEN_NONE;
|
expected_token = G_TOKEN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1529,18 +1433,8 @@ gtk_binding_parse_signal (GScanner *scanner,
|
|||||||
|
|
||||||
scanner->config->scan_symbols = TRUE;
|
scanner->config->scan_symbols = TRUE;
|
||||||
|
|
||||||
for (slist = args; slist; slist = slist->next)
|
g_variant_builder_clear (&builder);
|
||||||
{
|
|
||||||
GtkBindingArg *arg;
|
|
||||||
|
|
||||||
arg = slist->data;
|
|
||||||
|
|
||||||
if (G_TYPE_FUNDAMENTAL (arg->arg_type) == G_TYPE_STRING)
|
|
||||||
g_free (arg->d.string_data);
|
|
||||||
g_free (arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_slist_free (args);
|
|
||||||
g_free (signal);
|
g_free (signal);
|
||||||
|
|
||||||
return expected_token;
|
return expected_token;
|
||||||
|
Loading…
Reference in New Issue
Block a user