gtk: Remove bindings

The whole binding functionality is now handled by shortcuts.
This commit is contained in:
Benjamin Otte 2018-08-12 22:07:27 +02:00 committed by Matthias Clasen
parent a062b96051
commit fb99f834e6
17 changed files with 255 additions and 2005 deletions

View File

@ -4620,27 +4620,6 @@ gtk_css_provider_error_quark
gtk_css_section_get_type gtk_css_section_get_type
</SECTION> </SECTION>
<SECTION>
<FILE>gtkbindings</FILE>
<TITLE>Bindings</TITLE>
GtkBindingSet
gtk_binding_set_new
gtk_binding_set_by_class
gtk_binding_set_find
gtk_bindings_activate
gtk_bindings_activate_event
gtk_binding_set_activate
gtk_binding_entry_add_action
gtk_binding_entry_add_action_variant
GtkBindingCallback
gtk_binding_entry_add_callback
gtk_binding_entry_add_signal
gtk_binding_entry_add_signal_variant
gtk_binding_entry_add_signal_from_string
gtk_binding_entry_skip
gtk_binding_entry_remove
</SECTION>
<SECTION> <SECTION>
<FILE>gtkenums</FILE> <FILE>gtkenums</FILE>
<TITLE>Standard Enumerations</TITLE> <TITLE>Standard Enumerations</TITLE>

View File

@ -49,7 +49,6 @@
#include <gtk/gtkassistant.h> #include <gtk/gtkassistant.h>
#include <gtk/gtkbin.h> #include <gtk/gtkbin.h>
#include <gtk/gtkbinlayout.h> #include <gtk/gtkbinlayout.h>
#include <gtk/gtkbindings.h>
#include <gtk/gtkborder.h> #include <gtk/gtkborder.h>
#include <gtk/gtkboxlayout.h> #include <gtk/gtkboxlayout.h>
#include <gtk/gtkbox.h> #include <gtk/gtkbox.h>

File diff suppressed because it is too large Load Diff

View File

@ -1,130 +0,0 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* GtkBindingSet: Keybinding manager for GObjects.
* Copyright (C) 1998 Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __GTK_BINDINGS_H__
#define __GTK_BINDINGS_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gdk/gdk.h>
#include <gtk/gtkenums.h>
#include <gtk/gtktypes.h>
G_BEGIN_DECLS
typedef struct _GtkBindingSet GtkBindingSet;
/**
* GtkBindingCallback:
* @widget: The object to invoke the callback on
* @args: (allow-none): The arguments or %NULL if none
* @user_data: The user data passed when registering the callback
*
* Prototype of the callback function registered with
* gtk_binding_entry_add_callback.
*/
typedef void (* GtkBindingCallback) (GtkWidget *widget,
GVariant *args,
gpointer user_data);
GDK_AVAILABLE_IN_ALL
GtkBindingSet *gtk_binding_set_new (const gchar *set_name);
GDK_AVAILABLE_IN_ALL
GtkBindingSet *gtk_binding_set_by_class (gpointer object_class);
GDK_AVAILABLE_IN_ALL
GtkBindingSet *gtk_binding_set_find (const gchar *set_name);
GDK_AVAILABLE_IN_ALL
gboolean gtk_bindings_activate (GObject *object,
guint keyval,
GdkModifierType modifiers);
GDK_AVAILABLE_IN_ALL
gboolean gtk_bindings_activate_event (GObject *object,
GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gtk_binding_set_activate (GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers,
GObject *object);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_skip (GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_add_signal_variant (GtkBindingSet*binding_set,
guint keyval,
GdkModifierType modifiers,
const gchar *signal_name,
GVariant *binding_args);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_add_signal (GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers,
const gchar *signal_name,
guint n_args,
...);
GDK_AVAILABLE_IN_ALL
GTokenType gtk_binding_entry_add_signal_from_string
(GtkBindingSet *binding_set,
const gchar *signal_desc);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_add_action_variant
(GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers,
const char *action_name,
GVariant *args);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_add_action (GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers,
const char *action_name,
const char *format_string,
...);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_add_callback(GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers,
GtkBindingCallback callback,
GVariant *args,
gpointer user_data,
GDestroyNotify user_destroy);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_remove (GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers);
G_END_DECLS
#endif /* __GTK_BINDINGS_H__ */

View File

@ -1,41 +0,0 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 2011 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_BINDINGS_PRIVATE_H__
#define __GTK_BINDINGS_PRIVATE_H__
#include "gtkbindings.h"
G_BEGIN_DECLS
guint _gtk_binding_parse_binding (GScanner *scanner);
void _gtk_binding_reset_parsed (void);
gboolean gtk_binding_emit_signal (GObject *object,
const char *signal,
GVariant *args,
gboolean *handled,
GError **error);
gboolean gtk_binding_activate_action (GObject *object,
const char *action,
GVariant *args,
gboolean *handled,
GError **error);
G_END_DECLS
#endif /* __GTK_BINDINGS_PRIVATE_H__ */

View File

@ -32,7 +32,6 @@
#include "gtkscrollable.h" #include "gtkscrollable.h"
#include "gtktypebuiltins.h" #include "gtktypebuiltins.h"
#include "gtkwidgetprivate.h" #include "gtkwidgetprivate.h"
#include "gtkbindings.h"
#include "a11y/gtklistboxaccessibleprivate.h" #include "a11y/gtklistboxaccessibleprivate.h"
#include "a11y/gtklistboxrowaccessible.h" #include "a11y/gtklistboxrowaccessible.h"

View File

@ -21,7 +21,6 @@
#include "gtkshortcut.h" #include "gtkshortcut.h"
#include "gtkbindingsprivate.h"
#include "gtkintl.h" #include "gtkintl.h"
#include "gtkshortcuttrigger.h" #include "gtkshortcuttrigger.h"
#include "gtkwidget.h" #include "gtkwidget.h"
@ -267,6 +266,251 @@ gtk_shortcut_trigger (GtkShortcut *self,
return gtk_shortcut_trigger_trigger (self->trigger, event); return gtk_shortcut_trigger_trigger (self->trigger, event);
} }
static gboolean
binding_compose_params (GObject *object,
GVariantIter *args,
GSignalQuery *query,
GValue **params_p)
{
GValue *params;
const GType *types;
guint i;
gboolean valid;
params = g_new0 (GValue, query->n_params + 1);
*params_p = params;
/* The instance we emit on is the first object in the array
*/
g_value_init (params, G_TYPE_OBJECT);
g_value_set_object (params, G_OBJECT (object));
params++;
types = query->param_types;
valid = TRUE;
for (i = 1; i < query->n_params + 1 && valid; i++)
{
GValue tmp_value = G_VALUE_INIT;
GVariant *tmp_variant;
g_value_init (params, *types);
tmp_variant = g_variant_iter_next_value (args);
switch ((guint) g_variant_classify (tmp_variant))
{
case G_VARIANT_CLASS_BOOLEAN:
g_value_init (&tmp_value, G_TYPE_BOOLEAN);
g_value_set_boolean (&tmp_value, g_variant_get_boolean (tmp_variant));
break;
case G_VARIANT_CLASS_DOUBLE:
g_value_init (&tmp_value, G_TYPE_DOUBLE);
g_value_set_double (&tmp_value, g_variant_get_double (tmp_variant));
break;
case G_VARIANT_CLASS_INT32:
g_value_init (&tmp_value, G_TYPE_LONG);
g_value_set_long (&tmp_value, g_variant_get_int32 (tmp_variant));
break;
case G_VARIANT_CLASS_UINT32:
g_value_init (&tmp_value, G_TYPE_LONG);
g_value_set_long (&tmp_value, g_variant_get_uint32 (tmp_variant));
break;
case G_VARIANT_CLASS_INT64:
g_value_init (&tmp_value, G_TYPE_LONG);
g_value_set_long (&tmp_value, g_variant_get_int64 (tmp_variant));
break;
case G_VARIANT_CLASS_STRING:
/* gtk_rc_parse_flags/enum() has fancier parsing for this; we can't call
* that since we don't have a GParamSpec, so just do something simple
*/
if (G_TYPE_FUNDAMENTAL (*types) == G_TYPE_ENUM)
{
GEnumClass *class = G_ENUM_CLASS (g_type_class_ref (*types));
GEnumValue *enum_value;
const char *s = g_variant_get_string (tmp_variant, NULL);
valid = FALSE;
enum_value = g_enum_get_value_by_name (class, s);
if (!enum_value)
enum_value = g_enum_get_value_by_nick (class, s);
if (enum_value)
{
g_value_init (&tmp_value, *types);
g_value_set_enum (&tmp_value, enum_value->value);
valid = TRUE;
}
g_type_class_unref (class);
}
/* This is just a hack for compatibility with GTK+-1.2 where a string
* could be used for a single flag value / without the support for multiple
* values in gtk_rc_parse_flags(), this isn't very useful.
*/
else if (G_TYPE_FUNDAMENTAL (*types) == G_TYPE_FLAGS)
{
GFlagsClass *class = G_FLAGS_CLASS (g_type_class_ref (*types));
GFlagsValue *flags_value;
const char *s = g_variant_get_string (tmp_variant, NULL);
valid = FALSE;
flags_value = g_flags_get_value_by_name (class, s);
if (!flags_value)
flags_value = g_flags_get_value_by_nick (class, s);
if (flags_value)
{
g_value_init (&tmp_value, *types);
g_value_set_flags (&tmp_value, flags_value->value);
valid = TRUE;
}
g_type_class_unref (class);
}
else
{
g_value_init (&tmp_value, G_TYPE_STRING);
g_value_set_static_string (&tmp_value, g_variant_get_string (tmp_variant, NULL));
}
break;
default:
valid = FALSE;
break;
}
if (valid)
{
if (!g_value_transform (&tmp_value, params))
valid = FALSE;
g_value_unset (&tmp_value);
}
g_variant_unref (tmp_variant);
types++;
params++;
}
if (!valid)
{
guint j;
for (j = 0; j < i; j++)
g_value_unset (&(*params_p)[j]);
g_free (*params_p);
*params_p = NULL;
}
return valid;
}
static gboolean
gtk_shortcut_emit_signal (GObject *object,
const char *signal,
GVariant *args,
gboolean *handled,
GError **error)
{
GSignalQuery query;
guint signal_id;
GValue *params = NULL;
GValue return_val = G_VALUE_INIT;
GVariantIter args_iter;
gsize n_args;
guint i;
*handled = FALSE;
signal_id = g_signal_lookup (signal, G_OBJECT_TYPE (object));
if (!signal_id)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Could not find signal \"%s\" in the '%s' class ancestry",
signal,
g_type_name (G_OBJECT_TYPE (object)));
return FALSE;
}
g_signal_query (signal_id, &query);
if (args)
n_args = g_variant_iter_init (&args_iter, args);
else
n_args = 0;
if (query.n_params != n_args ||
(query.return_type != G_TYPE_NONE && query.return_type != G_TYPE_BOOLEAN) ||
!binding_compose_params (object, &args_iter, &query, &params))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"signature mismatch for signal \"%s\" in the '%s' class ancestry",
signal,
g_type_name (G_OBJECT_TYPE (object)));
return FALSE;
}
else if (!(query.signal_flags & G_SIGNAL_ACTION))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"signal \"%s\" in the '%s' class ancestry cannot be used for action emissions",
signal,
g_type_name (G_OBJECT_TYPE (object)));
return FALSE;
}
if (query.return_type == G_TYPE_BOOLEAN)
g_value_init (&return_val, G_TYPE_BOOLEAN);
g_signal_emitv (params, signal_id, 0, &return_val);
if (query.return_type == G_TYPE_BOOLEAN)
{
if (g_value_get_boolean (&return_val))
*handled = TRUE;
g_value_unset (&return_val);
}
else
*handled = TRUE;
if (params != NULL)
{
for (i = 0; i < query.n_params + 1; i++)
g_value_unset (&params[i]);
g_free (params);
}
return TRUE;
}
static gboolean
gtk_shortcut_activate_action (GObject *object,
const char *action,
GVariant *args,
gboolean *handled,
GError **error)
{
if (!GTK_IS_WIDGET (object))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"actions must be emitted on GtkWidget subtypes, \"%s\" is not supported",
G_OBJECT_TYPE_NAME (object));
return FALSE;
}
if (!gtk_widget_activate_action_variant (GTK_WIDGET (object), action, args))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"action \"%s\" does not exist on class \"%s\"",
action,
G_OBJECT_TYPE_NAME (object));
return FALSE;
}
if (handled)
*handled = TRUE;
return TRUE;
}
gboolean gboolean
gtk_shortcut_activate (GtkShortcut *self, gtk_shortcut_activate (GtkShortcut *self,
GtkWidget *widget) GtkWidget *widget)
@ -283,11 +527,11 @@ gtk_shortcut_activate (GtkShortcut *self,
GError *error = NULL; GError *error = NULL;
gboolean handled; gboolean handled;
if (!gtk_binding_emit_signal (G_OBJECT (widget), if (!gtk_shortcut_emit_signal (G_OBJECT (widget),
self->signal, self->signal,
self->args, self->args,
&handled, &handled,
&error)) &error))
{ {
char *accelerator = gtk_shortcut_trigger_to_string (self->trigger); char *accelerator = gtk_shortcut_trigger_to_string (self->trigger);
g_warning ("gtk_shortcut_activate(): \":%s\": %s", g_warning ("gtk_shortcut_activate(): \":%s\": %s",
@ -304,11 +548,11 @@ gtk_shortcut_activate (GtkShortcut *self,
GError *error = NULL; GError *error = NULL;
gboolean handled; gboolean handled;
if (!gtk_binding_activate_action (G_OBJECT (widget), if (!gtk_shortcut_activate_action (G_OBJECT (widget),
self->action, self->action,
self->args, self->args,
&handled, &handled,
&error)) &error))
{ {
char *accelerator = gtk_shortcut_trigger_to_string (self->trigger); char *accelerator = gtk_shortcut_trigger_to_string (self->trigger);
g_warning ("gtk_shortcut_activate(): \":%s\": %s", g_warning ("gtk_shortcut_activate(): \":%s\": %s",

View File

@ -32,7 +32,6 @@
#include "gtkshortcutcontrollerprivate.h" #include "gtkshortcutcontrollerprivate.h"
#include "gtkeventcontrollerprivate.h" #include "gtkeventcontrollerprivate.h"
#include "gtkbindings.h"
#include "gtkshortcut.h" #include "gtkshortcut.h"
#include "gtkwidgetprivate.h" #include "gtkwidgetprivate.h"
@ -84,7 +83,6 @@ gtk_shortcut_controller_handle_event (GtkEventController *controller,
double y) double y)
{ {
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller); GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
GdkEventType event_type = gdk_event_get_event_type (event);
GtkWidget *widget; GtkWidget *widget;
const GSList *l; const GSList *l;
@ -98,13 +96,6 @@ gtk_shortcut_controller_handle_event (GtkEventController *controller,
{ {
widget = gtk_event_controller_get_widget (controller); widget = gtk_event_controller_get_widget (controller);
if (event_type == GDK_KEY_PRESS ||
event_type == GDK_KEY_RELEASE)
{
if (gtk_bindings_activate_event (G_OBJECT (widget), event))
return TRUE;
}
for (l = gtk_widget_class_get_shortcuts (GTK_WIDGET_GET_CLASS (widget)); l; l = l->next) for (l = gtk_widget_class_get_shortcuts (GTK_WIDGET_GET_CLASS (widget)); l; l = l->next)
{ {
if (gtk_shortcut_controller_trigger_shortcut (self, l->data, event)) if (gtk_shortcut_controller_trigger_shortcut (self, l->data, event))

View File

@ -25,7 +25,6 @@
#include "gtkactionable.h" #include "gtkactionable.h"
#include "gtkadjustment.h" #include "gtkadjustment.h"
#include "gtkbindings.h"
#include "gtkbox.h" #include "gtkbox.h"
#include "gtkbutton.h" #include "gtkbutton.h"
#include "gtkcssnodeprivate.h" #include "gtkcssnodeprivate.h"

View File

@ -166,7 +166,6 @@ gtk_public_sources = files([
'gtkassistant.c', 'gtkassistant.c',
'gtkbin.c', 'gtkbin.c',
'gtkbinlayout.c', 'gtkbinlayout.c',
'gtkbindings.c',
'gtkborder.c', 'gtkborder.c',
'gtkboxlayout.c', 'gtkboxlayout.c',
'gtkbox.c', 'gtkbox.c',
@ -420,7 +419,6 @@ gtk_public_headers = files([
'gtkassistant.h', 'gtkassistant.h',
'gtkbin.h', 'gtkbin.h',
'gtkbinlayout.h', 'gtkbinlayout.h',
'gtkbindings.h',
'gtkborder.h', 'gtkborder.h',
'gtkbox.h', 'gtkbox.h',
'gtkboxlayout.h', 'gtkboxlayout.h',

View File

@ -77,7 +77,6 @@ gtk/gtkapplicationwindow.c
gtk/gtkaspectframe.c gtk/gtkaspectframe.c
gtk/gtkassistant.c gtk/gtkassistant.c
gtk/gtkbin.c gtk/gtkbin.c
gtk/gtkbindings.c
gtk/gtkbookmarksmanager.c gtk/gtkbookmarksmanager.c
gtk/gtkbox.c gtk/gtkbox.c
gtk/gtkboxlayout.c gtk/gtkboxlayout.c

View File

@ -77,7 +77,6 @@ gtk/gtkapplicationwindow.c
gtk/gtkaspectframe.c gtk/gtkaspectframe.c
gtk/gtkassistant.c gtk/gtkassistant.c
gtk/gtkbin.c gtk/gtkbin.c
gtk/gtkbindings.c
gtk/gtkbookmarksmanager.c gtk/gtkbookmarksmanager.c
gtk/gtkbox.c gtk/gtkbox.c
gtk/gtkboxlayout.c gtk/gtkboxlayout.c

View File

@ -6232,7 +6232,6 @@ main (int argc, char *argv[])
{ {
GtkCssProvider *provider, *memory_provider; GtkCssProvider *provider, *memory_provider;
GdkDisplay *display; GdkDisplay *display;
GtkBindingSet *binding_set;
int i; int i;
gboolean done_benchmarks = FALSE; gboolean done_benchmarks = FALSE;
@ -6316,15 +6315,6 @@ main (int argc, char *argv[])
if (done_benchmarks) if (done_benchmarks)
return 0; return 0;
/* bindings test
*/
binding_set = gtk_binding_set_by_class (g_type_class_ref (GTK_TYPE_WIDGET));
gtk_binding_entry_add_signal (binding_set,
'9', GDK_CONTROL_MASK | GDK_RELEASE_MASK,
"debug_msg",
1,
G_TYPE_STRING, "GtkWidgetClass <ctrl><release>9 test");
memory_provider = gtk_css_provider_new (); memory_provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (memory_provider, gtk_css_provider_load_from_data (memory_provider,
"#testgtk-version-label {\n" "#testgtk-version-label {\n"

View File

@ -1 +0,0 @@
@define-color color darker ( @blue ) ;

View File

@ -1 +0,0 @@
at-invalid-22.css:1:21-27: error: GTK_CSS_PARSER_ERROR_SYNTAX

View File

@ -92,9 +92,6 @@ test_data = [
'at-invalid-21.css', 'at-invalid-21.css',
'at-invalid-21.errors', 'at-invalid-21.errors',
'at-invalid-21.ref.css', 'at-invalid-21.ref.css',
'at-invalid-22.css',
'at-invalid-22.errors',
'at-invalid-22.ref.css',
'at-valid-01.css', 'at-valid-01.css',
'at-valid-01.ref.css', 'at-valid-01.ref.css',
'at-valid-02.css', 'at-valid-02.css',