[gtk/shortcuts-rebased-again: 63/145] gtk: Remove bindings



commit ea178a1a18bf705c11203b02342529aed1882de9
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-docs.xml           |    1 -
 docs/reference/gtk/gtk4-sections.txt       |   20 -
 gtk/gtk.h                                  |    1 -
 gtk/gtkbindings.c                          | 1467 ----------------------------
 gtk/gtkbindings.h                          |   93 --
 gtk/gtkbindingsprivate.h                   |   36 -
 gtk/gtkcssprovider.c                       |    1 -
 gtk/gtkcssstylepropertyimpl.c              |    1 -
 gtk/gtkpopover.c                           |    2 -
 gtk/gtkshortcut.c                          |  226 ++++-
 gtk/gtkshortcutcontroller.c                |    4 -
 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 -
 19 files changed, 220 insertions(+), 1651 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-docs.xml b/docs/reference/gtk/gtk4-docs.xml
index 999bcc5637..61f9aa9151 100644
--- a/docs/reference/gtk/gtk4-docs.xml
+++ b/docs/reference/gtk/gtk4-docs.xml
@@ -358,7 +358,6 @@
     <xi:include href="xml/gtkaccelmap.xml" />
     <xi:include href="xml/gtkdnd.xml" />
     <xi:include href="xml/gtksettings.xml" />
-    <xi:include href="xml/gtkbindings.xml" />
     <xi:include href="xml/gtkenums.xml" />
     <xi:include href="xml/gtkselection.xml" />
     <xi:include href="xml/gtktesting.xml" />
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 7429009a92..03584b0497 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -5197,26 +5197,6 @@ gtk_drag_source_add_image_targets
 gtk_drag_source_add_uri_targets
 </SECTION>
 
-<SECTION>
-<FILE>gtkbindings</FILE>
-<TITLE>Bindings</TITLE>
-GtkBindingSet
-GtkBindingEntry
-GtkBindingSignal
-GtkBindingArg
-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_signal_variant
-gtk_binding_entry_add_signal
-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 9f1abe0933..28832f409c 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/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 6d6571b59b..15bf839b1e 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -32,7 +32,6 @@
 #include "gtkstylepropertyprivate.h"
 #include "gtkstyleproviderprivate.h"
 #include "gtkwidgetpath.h"
-#include "gtkbindings.h"
 #include "gtkmarshalers.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index a1987b751a..886e7b210a 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -35,7 +35,6 @@
 #include "fallback-c89.c"
 
 /* the actual parsers we have */
-#include "gtkbindings.h"
 #include "gtkcssarrayvalueprivate.h"
 #include "gtkcssbgsizevalueprivate.h"
 #include "gtkcssbordervalueprivate.h"
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index 9781c1a13e..6052bd80bd 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -111,10 +111,8 @@
 #include "gtkwidgetprivate.h"
 #include "gtkeventcontrollerkey.h"
 #include "gtkcssnodeprivate.h"
-#include "gtkbindings.h"
 #include "gtkenums.h"
 #include "gtktypebuiltins.h"
-#include "gtkmnemonichash.h"
 #include "gtkgizmoprivate.h"
 #include "gtkintl.h"
 #include "gtkprivate.h"
diff --git a/gtk/gtkshortcut.c b/gtk/gtkshortcut.c
index 69e087603b..1fac8d489d 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"
@@ -245,6 +244,221 @@ 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;
+}
+
 gboolean
 gtk_shortcut_activate (GtkShortcut *self,
                        GtkWidget   *widget)
@@ -261,11 +475,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",
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
index 44ab5019f0..0b8d1ee9ac 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"
 
@@ -95,9 +94,6 @@ gtk_shortcut_controller_handle_event (GtkEventController *controller,
     {
       widget = gtk_event_controller_get_widget (controller); 
 
-      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/meson.build b/gtk/meson.build
index f4acff3a14..26f30bd1dd 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -166,7 +166,6 @@ gtk_public_sources = files([
   'gtkassistant.c',
   'gtkbin.c',
   'gtkbinlayout.c',
-  'gtkbindings.c',
   'gtkborder.c',
   'gtkboxlayout.c',
   'gtkbox.c',
@@ -429,7 +428,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 0ba80227dc..5d1e610afa 100644
--- a/po-properties/POTFILES.in
+++ b/po-properties/POTFILES.in
@@ -76,7 +76,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 9f000034c1..6857cb6863 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -76,7 +76,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 3f6a5b17fb..2ff85dd413 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -6518,7 +6518,6 @@ main (int argc, char *argv[])
 {
   GtkCssProvider *provider, *memory_provider;
   GdkDisplay *display;
-  GtkBindingSet *binding_set;
   int i;
   gboolean done_benchmarks = FALSE;
 
@@ -6602,15 +6601,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 573f0a7087..3fd04b5d86 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]