[gtk+] Revert "a11y: Remove AtkSelection implementation from combobox"



commit 45d896a6b5c144c7bdf956f255f59c1108dc258a
Author: Benjamin Otte <otte redhat com>
Date:   Mon Sep 16 15:36:07 2013 +0200

    Revert "a11y: Remove AtkSelection implementation from combobox"
    
    This reverts commit 7cecc8e524f9ac3825622e10f8a98f5e01ac4727.
    
    It is impossible to use the selection object of the menu while it is
    collapsed (collapsed menus deselect everything for a start), so even
    though the original patch was correct, the followup issues are too big
    to solve this quickly to a release.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707786

 gtk/a11y/gtkcomboboxaccessible.c |  108 +++++++++++++++++++++++++++++++++++++-
 testsuite/a11y/combos.txt        |    4 ++
 testsuite/a11y/pickers.txt       |    1 +
 3 files changed, 112 insertions(+), 1 deletions(-)
---
diff --git a/gtk/a11y/gtkcomboboxaccessible.c b/gtk/a11y/gtkcomboboxaccessible.c
index e271f8e..1c6b294 100644
--- a/gtk/a11y/gtkcomboboxaccessible.c
+++ b/gtk/a11y/gtkcomboboxaccessible.c
@@ -29,10 +29,12 @@ struct _GtkComboBoxAccessiblePrivate
 };
 
 static void atk_action_interface_init    (AtkActionIface    *iface);
+static void atk_selection_interface_init (AtkSelectionIface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (GtkComboBoxAccessible, gtk_combo_box_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
                          G_ADD_PRIVATE (GtkComboBoxAccessible)
-                         G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
+                         G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
+                         G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
 
 static void
 changed_cb (GtkWidget *widget)
@@ -51,6 +53,7 @@ changed_cb (GtkWidget *widget)
     {
       accessible->priv->old_selection = index;
       g_object_notify (G_OBJECT (obj), "accessible-name");
+      g_signal_emit_by_name (obj, "selection-changed");
     }
 }
 
@@ -327,3 +330,106 @@ atk_action_interface_init (AtkActionIface *iface)
   iface->get_localized_name = gtk_combo_box_accessible_action_get_localized_name;
   iface->get_description = gtk_combo_box_accessible_action_get_description;
 }
+
+static gboolean
+gtk_combo_box_accessible_add_selection (AtkSelection *selection,
+                                        gint          i)
+{
+  GtkWidget *widget;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
+  if (widget == NULL)
+    return FALSE;
+
+  gtk_combo_box_set_active (GTK_COMBO_BOX (widget), i);
+
+  return TRUE;
+}
+
+static gboolean
+gtk_combo_box_accessible_clear_selection (AtkSelection *selection)
+{
+  GtkWidget *widget;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
+  if (widget == NULL)
+    return FALSE;
+
+  gtk_combo_box_set_active (GTK_COMBO_BOX (widget), -1);
+
+  return TRUE;
+}
+
+static AtkObject *
+gtk_combo_box_accessible_ref_selection (AtkSelection *selection,
+                                        gint          i)
+{
+  GtkComboBox *combo_box;
+  GtkWidget *widget;
+  AtkObject *obj;
+  gint index;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
+  if (widget == NULL)
+    return NULL;
+
+  if (i != 0)
+    return NULL;
+
+  combo_box = GTK_COMBO_BOX (widget);
+
+  obj = gtk_combo_box_get_popup_accessible (combo_box);
+  index = gtk_combo_box_get_active (combo_box);
+
+  return atk_object_ref_accessible_child (obj, index);
+}
+
+static gint
+gtk_combo_box_accessible_get_selection_count (AtkSelection *selection)
+{
+  GtkWidget *widget;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
+  if (widget == NULL)
+    return 0;
+
+  return (gtk_combo_box_get_active (GTK_COMBO_BOX (widget)) == -1) ? 0 : 1;
+}
+
+static gboolean
+gtk_combo_box_accessible_is_child_selected (AtkSelection *selection,
+                                            gint          i)
+{
+  GtkWidget *widget;
+  gint j;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
+
+  if (widget == NULL)
+    return FALSE;
+
+  j = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
+
+  return (j == i);
+}
+
+static gboolean
+gtk_combo_box_accessible_remove_selection (AtkSelection *selection,
+                                           gint          i)
+{
+  if (atk_selection_is_child_selected (selection, i))
+    atk_selection_clear_selection (selection);
+
+  return TRUE;
+}
+
+static void
+atk_selection_interface_init (AtkSelectionIface *iface)
+{
+  iface->add_selection = gtk_combo_box_accessible_add_selection;
+  iface->clear_selection = gtk_combo_box_accessible_clear_selection;
+  iface->ref_selection = gtk_combo_box_accessible_ref_selection;
+  iface->get_selection_count = gtk_combo_box_accessible_get_selection_count;
+  iface->is_child_selected = gtk_combo_box_accessible_is_child_selected;
+  iface->remove_selection = gtk_combo_box_accessible_remove_selection;
+}
diff --git a/testsuite/a11y/combos.txt b/testsuite/a11y/combos.txt
index 7bcd8e0..e450993 100644
--- a/testsuite/a11y/combos.txt
+++ b/testsuite/a11y/combos.txt
@@ -69,6 +69,7 @@ window1
       action 0 name: press
       action 0 description: Presses the combobox
       action 0 keybinding: <Alt>c
+      <AtkSelection>
       unnamed-GtkMenuAccessible-0
         "menu"
         parent: combo1
@@ -91,6 +92,7 @@ window1
       <AtkAction>
       action 0 name: press
       action 0 description: Presses the combobox
+      <AtkSelection>
       unnamed-GtkMenuAccessible-1
         "menu"
         parent: combo2
@@ -154,6 +156,7 @@ window1
       <AtkAction>
       action 0 name: press
       action 0 description: Presses the combobox
+      <AtkSelection>
       unnamed-GtkMenuAccessible-2
         "menu"
         parent: combo3
@@ -176,6 +179,7 @@ window1
       <AtkAction>
       action 0 name: press
       action 0 description: Presses the combobox
+      <AtkSelection>
       unnamed-GtkMenuAccessible-3
         "menu"
         parent: combo4
diff --git a/testsuite/a11y/pickers.txt b/testsuite/a11y/pickers.txt
index 237b1fc..387b18f 100644
--- a/testsuite/a11y/pickers.txt
+++ b/testsuite/a11y/pickers.txt
@@ -58,6 +58,7 @@ window1
       <AtkAction>
       action 0 name: press
       action 0 description: Presses the combobox
+      <AtkSelection>
       unnamed-GtkMenuAccessible-0
         "menu"
         parent: button1


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