[gtk/wip/ebassi/shortcut: 225/267] gtk: Remove bindings



commit e27ed013748b5499ba76cbb58a2e8acf20060f17
Author: Benjamin Otte <otte redhat com>
Date:   Sun Aug 12 22:07:27 2018 +0200

    gtk: Remove bindings
    
    The whole binding functionality is now handled by shortcuts.

 docs/reference/gtk/gtk4-sections.txt       |   21 -
 gtk/gtk.h                                  |    1 -
 gtk/gtkbindings.c                          | 1778 ----------------------------
 gtk/gtkbindings.h                          |  130 --
 gtk/gtkbindingsprivate.h                   |   41 -
 gtk/gtkshortcut.c                          |  266 ++++-
 gtk/gtkshortcutcontroller.c                |    9 -
 gtk/gtktext.c                              |    1 -
 gtk/meson.build                            |    2 -
 po-properties/POTFILES.in                  |    1 -
 po/POTFILES.in                             |    1 -
 tests/testgtk.c                            |   10 -
 testsuite/css/parser/at-invalid-22.css     |    1 -
 testsuite/css/parser/at-invalid-22.errors  |    1 -
 testsuite/css/parser/at-invalid-22.ref.css |    0
 testsuite/css/parser/meson.build           |    3 -
 16 files changed, 255 insertions(+), 2011 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 174a82dc83..821afbfd26 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -4943,27 +4943,6 @@ GTK_TYPE_SELECTION_DATA
 gtk_selection_data_get_type
 </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>
 <FILE>gtkenums</FILE>
 <TITLE>Standard Enumerations</TITLE>
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 192fd186d3..e10a6a1352 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -49,7 +49,6 @@
 #include <gtk/gtkassistant.h>
 #include <gtk/gtkbin.h>
 #include <gtk/gtkbinlayout.h>
-#include <gtk/gtkbindings.h>
 #include <gtk/gtkborder.h>
 #include <gtk/gtkboxlayout.h>
 #include <gtk/gtkbox.h>
diff --git a/gtk/gtkshortcut.c b/gtk/gtkshortcut.c
index ddf79c67b2..8fb596fc50 100644
--- a/gtk/gtkshortcut.c
+++ b/gtk/gtkshortcut.c
@@ -21,7 +21,6 @@
 
 #include "gtkshortcut.h"
 
-#include "gtkbindingsprivate.h"
 #include "gtkintl.h"
 #include "gtkshortcuttrigger.h"
 #include "gtkwidget.h"
@@ -267,6 +266,251 @@ gtk_shortcut_trigger (GtkShortcut    *self,
   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
 gtk_shortcut_activate (GtkShortcut *self,
                        GtkWidget   *widget)
@@ -283,11 +527,11 @@ gtk_shortcut_activate (GtkShortcut *self,
       GError *error = NULL;
       gboolean handled;
 
-      if (!gtk_binding_emit_signal (G_OBJECT (widget),
-                                    self->signal,
-                                    self->args,
-                                    &handled,
-                                    &error))
+      if (!gtk_shortcut_emit_signal (G_OBJECT (widget),
+                                     self->signal,
+                                     self->args,
+                                     &handled,
+                                     &error))
         {
           char *accelerator = gtk_shortcut_trigger_to_string (self->trigger);
           g_warning ("gtk_shortcut_activate(): \":%s\": %s",
@@ -304,11 +548,11 @@ gtk_shortcut_activate (GtkShortcut *self,
       GError *error = NULL;
       gboolean handled;
 
-      if (!gtk_binding_activate_action (G_OBJECT (widget),
-                                        self->action,
-                                        self->args,
-                                        &handled,
-                                        &error))
+      if (!gtk_shortcut_activate_action (G_OBJECT (widget),
+                                         self->action,
+                                         self->args,
+                                         &handled,
+                                         &error))
         {
           char *accelerator = gtk_shortcut_trigger_to_string (self->trigger);
           g_warning ("gtk_shortcut_activate(): \":%s\": %s",
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
index f77781a0d0..77ccea9b8b 100644
--- a/gtk/gtkshortcutcontroller.c
+++ b/gtk/gtkshortcutcontroller.c
@@ -32,7 +32,6 @@
 #include "gtkshortcutcontrollerprivate.h"
 
 #include "gtkeventcontrollerprivate.h"
-#include "gtkbindings.h"
 #include "gtkshortcut.h"
 #include "gtkwidgetprivate.h"
 
@@ -82,7 +81,6 @@ gtk_shortcut_controller_handle_event (GtkEventController *controller,
                                       const GdkEvent     *event)
 {
   GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
-  GdkEventType event_type = gdk_event_get_event_type (event);
   GtkWidget *widget;
   const GSList *l;
 
@@ -96,13 +94,6 @@ gtk_shortcut_controller_handle_event (GtkEventController *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), (GdkEventKey *) event))
-            return TRUE;
-        }
-
       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))
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index cdf7871802..56d9c07662 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -25,7 +25,6 @@
 
 #include "gtkactionable.h"
 #include "gtkadjustment.h"
-#include "gtkbindings.h"
 #include "gtkbox.h"
 #include "gtkbutton.h"
 #include "gtkcssnodeprivate.h"
diff --git a/gtk/meson.build b/gtk/meson.build
index 87e202631b..b3c3717c8c 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -165,7 +165,6 @@ gtk_public_sources = files([
   'gtkassistant.c',
   'gtkbin.c',
   'gtkbinlayout.c',
-  'gtkbindings.c',
   'gtkborder.c',
   'gtkboxlayout.c',
   'gtkbox.c',
@@ -425,7 +424,6 @@ gtk_public_headers = files([
   'gtkassistant.h',
   'gtkbin.h',
   'gtkbinlayout.h',
-  'gtkbindings.h',
   'gtkborder.h',
   'gtkbox.h',
   'gtkboxlayout.h',
diff --git a/po-properties/POTFILES.in b/po-properties/POTFILES.in
index 543f02fead..09f6841709 100644
--- a/po-properties/POTFILES.in
+++ b/po-properties/POTFILES.in
@@ -75,7 +75,6 @@ gtk/gtkapplicationwindow.c
 gtk/gtkaspectframe.c
 gtk/gtkassistant.c
 gtk/gtkbin.c
-gtk/gtkbindings.c
 gtk/gtkbookmarksmanager.c
 gtk/gtkbox.c
 gtk/gtkboxlayout.c
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a686acd294..f8973113cd 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -75,7 +75,6 @@ gtk/gtkapplicationwindow.c
 gtk/gtkaspectframe.c
 gtk/gtkassistant.c
 gtk/gtkbin.c
-gtk/gtkbindings.c
 gtk/gtkbookmarksmanager.c
 gtk/gtkbox.c
 gtk/gtkboxlayout.c
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 998a13d218..00253398df 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -6370,7 +6370,6 @@ main (int argc, char *argv[])
 {
   GtkCssProvider *provider, *memory_provider;
   GdkDisplay *display;
-  GtkBindingSet *binding_set;
   int i;
   gboolean done_benchmarks = FALSE;
 
@@ -6454,15 +6453,6 @@ main (int argc, char *argv[])
   if (done_benchmarks)
     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 ();
   gtk_css_provider_load_from_data (memory_provider,
                                    "#testgtk-version-label {\n"
diff --git a/testsuite/css/parser/meson.build b/testsuite/css/parser/meson.build
index 9e501a0bd2..b4a3fc2aac 100644
--- a/testsuite/css/parser/meson.build
+++ b/testsuite/css/parser/meson.build
@@ -91,9 +91,6 @@ test_data = [
   'at-invalid-21.css',
   'at-invalid-21.errors',
   '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.ref.css',
   'at-valid-02.css',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]