]> Pileus Git - ~andy/gtk/commitdiff
Convert GailComboBox to GtkComboBoxAccessible
authorMatthias Clasen <mclasen@redhat.com>
Wed, 29 Jun 2011 21:31:09 +0000 (17:31 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 5 Jul 2011 20:08:56 +0000 (16:08 -0400)
gtk/a11y/Makefile.am
gtk/a11y/gail.c
gtk/a11y/gailcombobox.c [deleted file]
gtk/a11y/gailcombobox.h [deleted file]
gtk/a11y/gtkcomboboxaccessible.c [new file with mode: 0644]
gtk/a11y/gtkcomboboxaccessible.h [new file with mode: 0644]
gtk/a11y/gtkentryaccessible.c
gtk/gtkcombobox.c

index 449d3132e92decdc7268f2f04271cea897e3a396..51a681069bd0e8edce5fdfd3fc30ef7cda6d954a 100644 (file)
@@ -11,7 +11,7 @@ gail_c_sources =                      \
        gailcellparent.c                \
        gailcheckmenuitem.c             \
        gailchecksubmenuitem.c          \
-       gailcombobox.c                  \
+       gtkcomboboxaccessible.c         \
        gailcontainer.c                 \
        gailcontainercell.c             \
        gtkentryaccessible.c            \
@@ -61,7 +61,7 @@ gail_private_h_sources =              \
        gailcellparent.h                \
        gailcheckmenuitem.h             \
        gailchecksubmenuitem.h          \
-       gailcombobox.h                  \
+       gtkcomboboxaccessible.h         \
        gailcontainercell.h             \
        gailcontainer.h                 \
        gtkentryaccessible.h            \
index 6b4ed4c512c1612f57e1aab15e3290ac1e32f4c1..3a4e1ca1d34b3cec062b750f8d98647feefa0af9 100644 (file)
@@ -27,7 +27,6 @@
 #include "gailbutton.h"
 #include "gailcell.h"
 #include "gailcheckmenuitem.h"
-#include "gailcombobox.h"
 #include "gailcontainer.h"
 #include "gailcontainercell.h"
 #include "gailexpander.h"
@@ -96,7 +95,6 @@ GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_WIDGET, GailWidget, gail_widget, GTK_TYPE_WIDG
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_CONTAINER, GailContainer, gail_container, GTK_TYPE_CONTAINER)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_BUTTON, GailButton, gail_button, GTK_TYPE_BUTTON)
 GAIL_IMPLEMENT_FACTORY_WITH_FUNC (GAIL_TYPE_MENU_ITEM, GailMenuItem, gail_menu_item, gail_menu_item_new)
-GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_COMBO_BOX, GailComboBox, gail_combo_box, GTK_TYPE_COMBO_BOX)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_MENU_SHELL, GailMenuShell, gail_menu_shell, GTK_TYPE_MENU_SHELL)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_MENU, GailMenu, gail_menu, GTK_TYPE_MENU)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_WINDOW, GailWindow, gail_window, GTK_TYPE_BIN)
@@ -854,7 +852,6 @@ gail_accessibility_module_init (void)
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CONTAINER, gail_container);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_BUTTON, gail_button);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU_ITEM, gail_menu_item);
-  GAIL_WIDGET_SET_FACTORY (GTK_TYPE_COMBO_BOX, gail_combo_box);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU_BAR, gail_menu_shell);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU, gail_menu);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_WINDOW, gail_window);
diff --git a/gtk/a11y/gailcombobox.c b/gtk/a11y/gailcombobox.c
deleted file mode 100644 (file)
index c7d563d..0000000
+++ /dev/null
@@ -1,514 +0,0 @@
-/* GAIL - The GNOME Accessibility Implementation Library
- * Copyright 2004 Sun Microsystems 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, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
-#include "gailcombobox.h"
-
-static void         gail_combo_box_class_init              (GailComboBoxClass *klass);
-static void         gail_combo_box_init                    (GailComboBox      *combo_box);
-static void         gail_combo_box_real_initialize         (AtkObject      *obj,
-                                                            gpointer       data);
-
-static void         gail_combo_box_changed_gtk             (GtkWidget      *widget);
-
-static const gchar* gail_combo_box_get_name       (AtkObject      *obj);
-static gint         gail_combo_box_get_n_children          (AtkObject      *obj);
-static AtkObject*   gail_combo_box_ref_child               (AtkObject      *obj,
-                                                            gint           i);
-static void         gail_combo_box_finalize                (GObject        *object);
-static void         atk_action_interface_init              (AtkActionIface *iface);
-
-static gboolean     gail_combo_box_do_action               (AtkAction      *action,
-                                                            gint           i);
-static gint         gail_combo_box_get_n_actions           (AtkAction      *action);
-static const gchar* gail_combo_box_get_keybinding   (AtkAction       *action,
-                                                            gint            i);
-static const gchar* gail_combo_box_action_get_name(AtkAction      *action,
-                                                            gint           i);
-static void         atk_selection_interface_init           (AtkSelectionIface *iface);
-static gboolean     gail_combo_box_add_selection           (AtkSelection   *selection,
-                                                            gint           i);
-static gboolean     gail_combo_box_clear_selection         (AtkSelection   *selection);
-static AtkObject*   gail_combo_box_ref_selection           (AtkSelection   *selection,
-                                                            gint           i);
-static gint         gail_combo_box_get_selection_count     (AtkSelection   *selection);
-static gboolean     gail_combo_box_is_child_selected       (AtkSelection   *selection,
-                                                            gint           i);
-static gboolean     gail_combo_box_remove_selection        (AtkSelection   *selection,
-                                                            gint           i);
-
-G_DEFINE_TYPE_WITH_CODE (GailComboBox, gail_combo_box, GAIL_TYPE_CONTAINER,
-                         G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
-                         G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
-
-static void
-gail_combo_box_class_init (GailComboBoxClass *klass)
-{
-  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
-
-  gobject_class->finalize = gail_combo_box_finalize;
-
-  class->get_name = gail_combo_box_get_name;
-  class->get_n_children = gail_combo_box_get_n_children;
-  class->ref_child = gail_combo_box_ref_child;
-  class->initialize = gail_combo_box_real_initialize;
-}
-
-static void
-gail_combo_box_init (GailComboBox      *combo_box)
-{
-  combo_box->press_keybinding = NULL;
-  combo_box->old_selection = -1;
-  combo_box->name = NULL;
-  combo_box->popup_set = FALSE;
-}
-
-static void
-gail_combo_box_real_initialize (AtkObject *obj,
-                                gpointer  data)
-{
-  GtkComboBox *combo_box;
-  GailComboBox *gail_combo_box;
-  AtkObject *popup;
-
-  ATK_OBJECT_CLASS (gail_combo_box_parent_class)->initialize (obj, data);
-
-  combo_box = GTK_COMBO_BOX (data);
-
-  gail_combo_box = GAIL_COMBO_BOX (obj);
-
-  g_signal_connect (combo_box,
-                    "changed",
-                    G_CALLBACK (gail_combo_box_changed_gtk),
-                    NULL);
-  gail_combo_box->old_selection = gtk_combo_box_get_active (combo_box);
-
-  popup = gtk_combo_box_get_popup_accessible (combo_box);
-  if (popup)
-    {
-      atk_object_set_parent (popup, obj);
-      gail_combo_box->popup_set = TRUE;
-    }
-  if (gtk_combo_box_get_has_entry (combo_box))
-    atk_object_set_parent (gtk_widget_get_accessible (gtk_bin_get_child (GTK_BIN (combo_box))), obj);
-
-  obj->role = ATK_ROLE_COMBO_BOX;
-}
-
-static void
-gail_combo_box_changed_gtk (GtkWidget *widget)
-{
-  GtkComboBox *combo_box;
-  AtkObject *obj;
-  GailComboBox *gail_combo_box;
-  gint index;
-
-  combo_box = GTK_COMBO_BOX (widget);
-
-  index = gtk_combo_box_get_active (combo_box);
-  obj = gtk_widget_get_accessible (widget);
-  gail_combo_box = GAIL_COMBO_BOX (obj);
-  if (gail_combo_box->old_selection != index)
-    {
-      gail_combo_box->old_selection = index;
-      g_object_notify (G_OBJECT (obj), "accessible-name");
-      g_signal_emit_by_name (obj, "selection_changed");
-    }
-}
-
-static const gchar*
-gail_combo_box_get_name (AtkObject *obj)
-{
-  GtkWidget *widget;
-  GtkComboBox *combo_box;
-  GailComboBox *gail_combo_box;
-  GtkTreeIter iter;
-  const gchar *name;
-  GtkTreeModel *model;
-  gint n_columns;
-  gint i;
-
-  g_return_val_if_fail (GAIL_IS_COMBO_BOX (obj), NULL);
-
-  name = ATK_OBJECT_CLASS (gail_combo_box_parent_class)->get_name (obj);
-  if (name)
-    return name;
-
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
-  if (widget == NULL)
-    /*
-     * State is defunct
-     */
-    return NULL;
-
-  combo_box = GTK_COMBO_BOX (widget);
-  gail_combo_box = GAIL_COMBO_BOX (obj);
-  if (gtk_combo_box_get_active_iter (combo_box, &iter))
-    {
-      model = gtk_combo_box_get_model (combo_box);
-      n_columns = gtk_tree_model_get_n_columns (model);
-      for (i = 0; i < n_columns; i++)
-        {
-          GValue value = { 0, };
-
-          gtk_tree_model_get_value (model, &iter, i, &value);
-          if (G_VALUE_HOLDS_STRING (&value))
-            {
-             if (gail_combo_box->name) g_free (gail_combo_box->name);
-              gail_combo_box->name =  g_strdup ((gchar *) 
-                                               g_value_get_string (&value));
-             g_value_unset (&value);
-              break;
-            }
-         else
-           g_value_unset (&value);
-        }
-    }
-  return gail_combo_box->name;
-}
-
-/*
- * The children of a GailComboBox are the list of items and the entry field
- * if it is editable.
- */
-static gint
-gail_combo_box_get_n_children (AtkObject* obj)
-{
-  gint n_children = 0;
-  GtkWidget *widget;
-
-  g_return_val_if_fail (GAIL_IS_COMBO_BOX (obj), 0);
-
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
-
-  if (widget == NULL)
-    /*
-     * State is defunct
-     */
-    return 0;
-
-  n_children++;
-  if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (widget)))
-    n_children ++;
-
-  return n_children;
-}
-
-static AtkObject*
-gail_combo_box_ref_child (AtkObject *obj,
-                          gint      i)
-{
-  GtkWidget *widget;
-  AtkObject *child;
-  GailComboBox *box;
-
-  g_return_val_if_fail (GAIL_IS_COMBO_BOX (obj), NULL);
-
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
-
-  if (widget == NULL)
-    /*
-     * State is defunct
-     */
-    return NULL;
-
-  if (i == 0)
-    {
-      child = gtk_combo_box_get_popup_accessible (GTK_COMBO_BOX (widget));
-      box = GAIL_COMBO_BOX (obj);
-      if (box->popup_set == FALSE)
-        {
-          atk_object_set_parent (child, obj);
-          box->popup_set = TRUE;
-        }
-    }
-  else if (i == 1 && gtk_combo_box_get_has_entry (GTK_COMBO_BOX (widget)))
-    {
-      child = gtk_widget_get_accessible (gtk_bin_get_child (GTK_BIN (widget)));
-    }
-  else
-    {
-      return NULL;
-    }
-  return g_object_ref (child);
-}
-
-static void
-atk_action_interface_init (AtkActionIface *iface)
-{
-  iface->do_action = gail_combo_box_do_action;
-  iface->get_n_actions = gail_combo_box_get_n_actions;
-  iface->get_keybinding = gail_combo_box_get_keybinding;
-  iface->get_name = gail_combo_box_action_get_name;
-}
-
-static gboolean
-gail_combo_box_do_action (AtkAction *action,
-                          gint      i)
-{
-  GtkComboBox *combo_box;
-  GtkWidget *widget;
-  gboolean popup_shown;
-
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
-
-  if (widget == NULL)
-    /*
-     * State is defunct
-     */
-    return FALSE;
-
-  if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
-    return FALSE;
-
-  if (i == 0)
-    {
-      combo_box = GTK_COMBO_BOX (widget);
-      g_object_get (combo_box, "popup-shown", &popup_shown, NULL);
-      if (popup_shown)
-          gtk_combo_box_popdown (combo_box);
-      else
-          gtk_combo_box_popup (combo_box);
-      return TRUE;
-    }
-  else
-    return FALSE;
-}
-
-static gint
-gail_combo_box_get_n_actions (AtkAction *action)
-{
-  /*
-   * The default behavior of a combo_box box is to have one action -
-   */
-  return 1;
-}
-
-static const gchar*
-gail_combo_box_get_keybinding (AtkAction *action,
-                                   gint      i)
-{
-  GailComboBox *combo_box;
-  gchar *return_value = NULL;
-  switch (i)
-  {
-     case 0:
-      {
-         GtkWidget *widget;
-         GtkWidget *label;
-         AtkRelationSet *set;
-         AtkRelation *relation;
-         GPtrArray *target;
-         gpointer target_object;
-         guint key_val;
-
-         combo_box = GAIL_COMBO_BOX (action);
-          widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (combo_box));
-         if (widget == NULL)
-             return NULL;
-         set = atk_object_ref_relation_set (ATK_OBJECT (action));
-         if (!set)
-             return NULL;
-         label = NULL;
-         relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY);
-         if (relation)
-         {
-            target = atk_relation_get_target (relation);
-            target_object = g_ptr_array_index (target, 0);
-             widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (target_object));
-         }
-         g_object_unref (set);
-         if (GTK_IS_LABEL (label))
-         {
-             key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label));
-            if (key_val != GDK_KEY_VoidSymbol)
-             return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
-         }
-          g_free (combo_box->press_keybinding);
-          combo_box->press_keybinding = return_value;
-          break;
-       }
-    default:
-          break;
-  }
-  return return_value;
-}
-
-
-static const gchar*
-gail_combo_box_action_get_name (AtkAction *action,
-                                gint      i)
-{
-  if (i == 0)
-    return "press";
-  else
-    return NULL;
-}
-
-static void
-atk_selection_interface_init (AtkSelectionIface *iface)
-{
-  iface->add_selection = gail_combo_box_add_selection;
-  iface->clear_selection = gail_combo_box_clear_selection;
-  iface->ref_selection = gail_combo_box_ref_selection;
-  iface->get_selection_count = gail_combo_box_get_selection_count;
-  iface->is_child_selected = gail_combo_box_is_child_selected;
-  iface->remove_selection = gail_combo_box_remove_selection;
-  /*
-   * select_all_selection does not make sense for a combo_box
-   * so no implementation is provided.
-   */
-}
-
-static gboolean
-gail_combo_box_add_selection (AtkSelection *selection,
-                              gint         i)
-{
-  GtkComboBox *combo_box;
-  GtkWidget *widget;
-
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
-
-  if (widget == NULL)
-    /*
-     * State is defunct
-     */
-    return FALSE;
-
-  combo_box = GTK_COMBO_BOX (widget);
-
-  gtk_combo_box_set_active (combo_box, i);
-  return TRUE;
-}
-
-static gboolean 
-gail_combo_box_clear_selection (AtkSelection *selection)
-{
-  GtkComboBox *combo_box;
-  GtkWidget *widget;
-
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
-
-  if (widget == NULL)
-    /*
-     * State is defunct
-     */
-    return FALSE;
-
-  combo_box = GTK_COMBO_BOX (widget);
-
-  gtk_combo_box_set_active (combo_box, -1);
-  return TRUE;
-}
-
-static AtkObject*
-gail_combo_box_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)
-    /*
-     * State is defunct
-     */
-    return NULL;
-
-  combo_box = GTK_COMBO_BOX (widget);
-
-  /*
-   * A combo_box box can have only one selection.
-   */
-  if (i != 0)
-    return NULL;
-
-  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
-gail_combo_box_get_selection_count (AtkSelection *selection)
-{
-  GtkComboBox *combo_box;
-  GtkWidget *widget;
-
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
-
-  if (widget == NULL)
-    /*
-     * State is defunct
-     */
-    return 0;
-
-  combo_box = GTK_COMBO_BOX (widget);
-
-  return (gtk_combo_box_get_active (combo_box) == -1) ? 0 : 1;
-}
-
-static gboolean
-gail_combo_box_is_child_selected (AtkSelection *selection,
-                                  gint         i)
-{
-  GtkComboBox *combo_box;
-  gint j;
-  GtkWidget *widget;
-
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
-
-  if (widget == NULL)
-    /*
-     * State is defunct
-     */
-    return FALSE;
-
-  combo_box = GTK_COMBO_BOX (widget);
-
-  j = gtk_combo_box_get_active (combo_box);
-
-  return (j == i);
-}
-
-static gboolean
-gail_combo_box_remove_selection (AtkSelection *selection,
-                                 gint         i)
-{
-  if (atk_selection_is_child_selected (selection, i))
-    atk_selection_clear_selection (selection);
-
-  return TRUE;
-}
-
-static void
-gail_combo_box_finalize (GObject *object)
-{
-  GailComboBox *combo_box = GAIL_COMBO_BOX (object);
-
-  g_free (combo_box->press_keybinding);
-  g_free (combo_box->name);
-  G_OBJECT_CLASS (gail_combo_box_parent_class)->finalize (object);
-}
diff --git a/gtk/a11y/gailcombobox.h b/gtk/a11y/gailcombobox.h
deleted file mode 100644 (file)
index dd7e471..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/* GAIL - The GNOME Accessibility Implementation Library
- * Copyright 2004 Sun Microsystems Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef __GAIL_COMBO_BOX_H__
-#define __GAIL_COMBO_BOX_H__
-
-#include "gailcontainer.h"
-
-G_BEGIN_DECLS
-
-#define GAIL_TYPE_COMBO_BOX                      (gail_combo_box_get_type ())
-#define GAIL_COMBO_BOX(obj)                      (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAIL_TYPE_COMBO_BOX, GailComboBox))
-#define GAIL_COMBO_BOX_CLASS(klass)              (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_COMBO_BOX, GailComboBoxClass))
-#define GAIL_IS_COMBO_BOX(obj)                   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAIL_TYPE_COMBO_BOX))
-#define GAIL_IS_COMBO_BOX_CLASS(klass)           (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_COMBO_BOX))
-#define GAIL_COMBO_BOX_GET_CLASS(obj)            (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_COMBO_BOX, GailComboBoxClass))
-
-typedef struct _GailComboBox              GailComboBox;
-typedef struct _GailComboBoxClass         GailComboBoxClass;
-
-struct _GailComboBox
-{
-  GailContainer parent;
-
-  gchar         *press_keybinding;
-
-  gchar         *name;
-  gint          old_selection;
-  gboolean      popup_set;
-};
-
-GType gail_combo_box_get_type (void);
-
-struct _GailComboBoxClass
-{
-  GailContainerClass parent_class;
-};
-
-G_END_DECLS
-
-#endif /* __GAIL_COMBO_BOX_H__ */
diff --git a/gtk/a11y/gtkcomboboxaccessible.c b/gtk/a11y/gtkcomboboxaccessible.c
new file mode 100644 (file)
index 0000000..5f48459
--- /dev/null
@@ -0,0 +1,411 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2004 Sun Microsystems 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+#include "gtkcomboboxaccessible.h"
+
+
+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, GAIL_TYPE_CONTAINER,
+                         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)
+{
+  GtkComboBox *combo_box;
+  AtkObject *obj;
+  GtkComboBoxAccessible *accessible;
+  gint index;
+
+  combo_box = GTK_COMBO_BOX (widget);
+
+  index = gtk_combo_box_get_active (combo_box);
+  obj = gtk_widget_get_accessible (widget);
+  accessible = GTK_COMBO_BOX_ACCESSIBLE (obj);
+  if (accessible->old_selection != index)
+    {
+      accessible->old_selection = index;
+      g_object_notify (G_OBJECT (obj), "accessible-name");
+      g_signal_emit_by_name (obj, "selection_changed");
+    }
+}
+
+static void
+gtk_combo_box_accessible_initialize (AtkObject *obj,
+                                     gpointer   data)
+{
+  GtkComboBox *combo_box;
+  GtkComboBoxAccessible *accessible;
+  AtkObject *popup;
+
+  ATK_OBJECT_CLASS (gtk_combo_box_accessible_parent_class)->initialize (obj, data);
+
+  combo_box = GTK_COMBO_BOX (data);
+  accessible = GTK_COMBO_BOX_ACCESSIBLE (obj);
+
+  g_signal_connect (combo_box, "changed", G_CALLBACK (changed_cb), NULL);
+  accessible->old_selection = gtk_combo_box_get_active (combo_box);
+
+  popup = gtk_combo_box_get_popup_accessible (combo_box);
+  if (popup)
+    {
+      atk_object_set_parent (popup, obj);
+      accessible->popup_set = TRUE;
+    }
+  if (gtk_combo_box_get_has_entry (combo_box))
+    atk_object_set_parent (gtk_widget_get_accessible (gtk_bin_get_child (GTK_BIN (combo_box))), obj);
+
+  obj->role = ATK_ROLE_COMBO_BOX;
+}
+
+static void
+gtk_combo_box_accessible_finalize (GObject *object)
+{
+  GtkComboBoxAccessible *combo_box = GTK_COMBO_BOX_ACCESSIBLE (object);
+
+  g_free (combo_box->name);
+
+  G_OBJECT_CLASS (gtk_combo_box_accessible_parent_class)->finalize (object);
+}
+
+static const gchar*
+gtk_combo_box_accessible_get_name (AtkObject *obj)
+{
+  GtkWidget *widget;
+  GtkComboBox *combo_box;
+  GtkComboBoxAccessible *accessible;
+  GtkTreeIter iter;
+  const gchar *name;
+  GtkTreeModel *model;
+  gint n_columns;
+  gint i;
+
+  name = ATK_OBJECT_CLASS (gtk_combo_box_accessible_parent_class)->get_name (obj);
+  if (name)
+    return name;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  if (widget == NULL)
+    return NULL;
+
+  combo_box = GTK_COMBO_BOX (widget);
+  accessible = GTK_COMBO_BOX_ACCESSIBLE (obj);
+  if (gtk_combo_box_get_active_iter (combo_box, &iter))
+    {
+      model = gtk_combo_box_get_model (combo_box);
+      n_columns = gtk_tree_model_get_n_columns (model);
+      for (i = 0; i < n_columns; i++)
+        {
+          GValue value = { 0, };
+
+          gtk_tree_model_get_value (model, &iter, i, &value);
+          if (G_VALUE_HOLDS_STRING (&value))
+            {
+              g_free (accessible->name);
+              accessible->name =  g_strdup (g_value_get_string (&value));
+              g_value_unset (&value);
+              break;
+            }
+          else
+            g_value_unset (&value);
+        }
+    }
+  return accessible->name;
+}
+
+static gint
+gtk_combo_box_accessible_get_n_children (AtkObject* obj)
+{
+  gint n_children = 0;
+  GtkWidget *widget;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  if (widget == NULL)
+    return 0;
+
+  n_children++;
+  if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (widget)))
+    n_children++;
+
+  return n_children;
+}
+
+static AtkObject *
+gtk_combo_box_accessible_ref_child (AtkObject *obj,
+                                    gint       i)
+{
+  GtkWidget *widget;
+  AtkObject *child;
+  GtkComboBoxAccessible *box;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  if (widget == NULL)
+    return NULL;
+
+  if (i == 0)
+    {
+      child = gtk_combo_box_get_popup_accessible (GTK_COMBO_BOX (widget));
+      box = GTK_COMBO_BOX_ACCESSIBLE (obj);
+      if (box->popup_set == FALSE)
+        {
+          atk_object_set_parent (child, obj);
+          box->popup_set = TRUE;
+        }
+    }
+  else if (i == 1 && gtk_combo_box_get_has_entry (GTK_COMBO_BOX (widget)))
+    {
+      child = gtk_widget_get_accessible (gtk_bin_get_child (GTK_BIN (widget)));
+    }
+  else
+    {
+      return NULL;
+    }
+
+  return g_object_ref (child);
+}
+
+static void
+gtk_combo_box_accessible_class_init (GtkComboBoxAccessibleClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+
+  gobject_class->finalize = gtk_combo_box_accessible_finalize;
+
+  class->get_name = gtk_combo_box_accessible_get_name;
+  class->get_n_children = gtk_combo_box_accessible_get_n_children;
+  class->ref_child = gtk_combo_box_accessible_ref_child;
+  class->initialize = gtk_combo_box_accessible_initialize;
+}
+
+static void
+gtk_combo_box_accessible_init (GtkComboBoxAccessible *combo_box)
+{
+  combo_box->old_selection = -1;
+  combo_box->name = NULL;
+  combo_box->popup_set = FALSE;
+}
+
+static gboolean
+gtk_combo_box_accessible_do_action (AtkAction *action,
+                                    gint       i)
+{
+  GtkComboBox *combo_box;
+  GtkWidget *widget;
+  gboolean popup_shown;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
+  if (widget == NULL)
+    return FALSE;
+
+  if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
+    return FALSE;
+
+  if (i == 0)
+    {
+      combo_box = GTK_COMBO_BOX (widget);
+      g_object_get (combo_box, "popup-shown", &popup_shown, NULL);
+      if (popup_shown)
+        gtk_combo_box_popdown (combo_box);
+      else
+        gtk_combo_box_popup (combo_box);
+      return TRUE;
+    }
+  else
+    return FALSE;
+}
+
+static gint
+gtk_combo_box_accessible_get_n_actions (AtkAction *action)
+{
+  return 1;
+}
+
+static const gchar *
+gtk_combo_box_accessible_get_keybinding (AtkAction *action,
+                                         gint       i)
+{
+  GtkComboBoxAccessible *combo_box;
+  GtkWidget *widget;
+  GtkWidget *label;
+  AtkRelationSet *set;
+  AtkRelation *relation;
+  GPtrArray *target;
+  gpointer target_object;
+  guint key_val;
+  gchar *return_value = NULL;
+
+  if (i != 0)
+    return NULL;
+
+  combo_box = GTK_COMBO_BOX_ACCESSIBLE (action);
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (combo_box));
+  if (widget == NULL)
+    return NULL;
+
+  set = atk_object_ref_relation_set (ATK_OBJECT (action));
+  if (set == NULL)
+    return NULL;
+
+  label = NULL;
+  relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY);
+  if (relation)
+    {
+      target = atk_relation_get_target (relation);
+      target_object = g_ptr_array_index (target, 0);
+      widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (target_object));
+    }
+  g_object_unref (set);
+  if (GTK_IS_LABEL (label))
+    {
+      key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label));
+      if (key_val != GDK_KEY_VoidSymbol)
+        return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
+    }
+
+  return return_value;
+}
+
+static const gchar *
+gtk_combo_box_accessible_action_get_name (AtkAction *action,
+                                          gint       i)
+{
+  if (i != 0)
+    return NULL;
+
+  return "press";
+}
+
+static void
+atk_action_interface_init (AtkActionIface *iface)
+{
+  iface->do_action = gtk_combo_box_accessible_do_action;
+  iface->get_n_actions = gtk_combo_box_accessible_get_n_actions;
+  iface->get_keybinding = gtk_combo_box_accessible_get_keybinding;
+  iface->get_name = gtk_combo_box_accessible_action_get_name;
+}
+
+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/gtk/a11y/gtkcomboboxaccessible.h b/gtk/a11y/gtkcomboboxaccessible.h
new file mode 100644 (file)
index 0000000..d422805
--- /dev/null
@@ -0,0 +1,55 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2004 Sun Microsystems Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_COMBO_BOX_ACCESSIBLE_H__
+#define __GTK_COMBO_BOX_ACCESSIBLE_H__
+
+#include "gailcontainer.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_COMBO_BOX_ACCESSIBLE                      (gtk_combo_box_accessible_get_type ())
+#define GTK_COMBO_BOX_ACCESSIBLE(obj)                      (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COMBO_BOX_ACCESSIBLE, GtkComboBoxAccessible))
+#define GTK_COMBO_BOX_ACCESSIBLE_CLASS(klass)              (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COMBO_BOX_ACCESSIBLE, GtkComboBoxAccessibleClass))
+#define GTK_IS_COMBO_BOX_ACCESSIBLE(obj)                   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COMBO_BOX_ACCESSIBLE))
+#define GTK_IS_COMBO_BOX_ACCESSIBLE_CLASS(klass)           (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COMBO_BOX_ACCESSIBLE))
+#define GTK_COMBO_BOX_ACCESSIBLE_GET_CLASS(obj)            (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COMBO_BOX_ACCESSIBLE, GtkComboBoxAccessibleClass))
+
+typedef struct _GtkComboBoxAccessible      GtkComboBoxAccessible;
+typedef struct _GtkComboBoxAccessibleClass GtkComboBoxAccessibleClass;
+
+struct _GtkComboBoxAccessible
+{
+  GailContainer  parent;
+
+  gchar         *name;
+  gint           old_selection;
+  gboolean       popup_set;
+};
+
+struct _GtkComboBoxAccessibleClass
+{
+  GailContainerClass parent_class;
+};
+
+GType gtk_combo_box_accessible_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GTK_COMBO_BOX_ACCESSIBLE_H__ */
index 962df0d706cb097759a49e3093ce15a9e5327155..1f42be52abb68e858b94840affde87fba24f2f31 100644 (file)
@@ -24,7 +24,7 @@
 #include "gtkpango.h"
 #include <gdk/gdkkeysyms.h>
 #include "gtkentryaccessible.h"
-#include "gailcombobox.h"
+#include "gtkcomboboxaccessible.h"
 
 /* Callbacks */
 
@@ -199,7 +199,7 @@ gtk_entry_accessible_get_index_in_parent (AtkObject *accessible)
    * otherwise do the normal thing.
    */
   if (accessible->accessible_parent)
-    if (GAIL_IS_COMBO_BOX (accessible->accessible_parent))
+    if (GTK_IS_COMBO_BOX_ACCESSIBLE (accessible->accessible_parent))
       return 1;
 
   return ATK_OBJECT_CLASS (gtk_entry_accessible_parent_class)->get_index_in_parent (accessible);
index 8a74f8f1a68b51495abe942ca2ee061170ff2fd8..38b064bc8ff7d8270a30acc63862571136de4df2 100644 (file)
@@ -53,6 +53,7 @@
 
 #include "gtkentryprivate.h"
 #include "gtktreeprivate.h"
+#include "a11y/gtkcomboboxaccessible.h"
 
 
 /**
@@ -1005,6 +1006,8 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
                                                               GTK_PARAM_READABLE));
 
   g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
+
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_COMBO_BOX_ACCESSIBLE);
 }
 
 static void