gtktogglebuttonaccessible.c 4.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* GAIL - The GNOME Accessibility Implementation Library
 * Copyright 2001, 2002, 2003 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.
 */

20
#include "config.h"
21

22 23
#include <string.h>
#include <gtk/gtk.h>
24
#include "gtktogglebuttonaccessible.h"
25 26


27
G_DEFINE_TYPE (GtkToggleButtonAccessible, _gtk_toggle_button_accessible, GTK_TYPE_BUTTON_ACCESSIBLE)
28 29

static void
30
gtk_toggle_button_accessible_toggled (GtkWidget *widget)
31
{
32 33
  AtkObject *accessible;
  GtkToggleButton *toggle_button;
34

35
  toggle_button = GTK_TOGGLE_BUTTON (widget);
36

37 38 39
  accessible = gtk_widget_get_accessible (widget);
  atk_object_notify_state_change (accessible, ATK_STATE_CHECKED,
                                  gtk_toggle_button_get_active (toggle_button));
40 41
}

42
static void
43 44
gtk_toggle_button_accessible_initialize (AtkObject *obj,
                                         gpointer   data)
45
{
46
  ATK_OBJECT_CLASS (_gtk_toggle_button_accessible_parent_class)->initialize (obj, data);
47

48 49
  g_signal_connect (data, "toggled",
                    G_CALLBACK (gtk_toggle_button_accessible_toggled), NULL);
50

51
  obj->role = ATK_ROLE_TOGGLE_BUTTON;
52 53 54
}

static void
55 56
gtk_toggle_button_accessible_notify_gtk (GObject    *obj,
                                         GParamSpec *pspec)
57
{
58 59 60 61
  GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (obj);
  AtkObject *atk_obj;
  gboolean sensitive;
  gboolean inconsistent;
62

63 64 65
  atk_obj = gtk_widget_get_accessible (GTK_WIDGET (toggle_button));
  sensitive = gtk_widget_get_sensitive (GTK_WIDGET (toggle_button));
  inconsistent = gtk_toggle_button_get_inconsistent (toggle_button);
66

67 68 69 70 71 72 73 74 75 76 77 78
  if (strcmp (pspec->name, "inconsistent") == 0)
    {
      atk_object_notify_state_change (atk_obj, ATK_STATE_INDETERMINATE, inconsistent);
      atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
    }
  else if (strcmp (pspec->name, "sensitive") == 0)
    {
      /* Need to override gailwidget behavior of notifying for ENABLED */
      atk_object_notify_state_change (atk_obj, ATK_STATE_SENSITIVE, sensitive);
      atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
    }
  else
79
    GTK_WIDGET_ACCESSIBLE_CLASS (_gtk_toggle_button_accessible_parent_class)->notify_gtk (obj, pspec);
80
}
81 82

static AtkStateSet*
83
gtk_toggle_button_accessible_ref_state_set (AtkObject *accessible)
84 85 86 87 88
{
  AtkStateSet *state_set;
  GtkToggleButton *toggle_button;
  GtkWidget *widget;

89
  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
90
  if (widget == NULL)
91
    return NULL;
92

93
  state_set = ATK_OBJECT_CLASS (_gtk_toggle_button_accessible_parent_class)->ref_state_set (accessible);
94 95 96 97 98 99
  toggle_button = GTK_TOGGLE_BUTTON (widget);

  if (gtk_toggle_button_get_active (toggle_button))
    atk_state_set_add_state (state_set, ATK_STATE_CHECKED);

  if (gtk_toggle_button_get_inconsistent (toggle_button))
100 101 102 103
    {
      atk_state_set_remove_state (state_set, ATK_STATE_ENABLED);
      atk_state_set_add_state (state_set, ATK_STATE_INDETERMINATE);
    }
104

105 106 107 108
  return state_set;
}

static void
109
_gtk_toggle_button_accessible_class_init (GtkToggleButtonAccessibleClass *klass)
110
{
111
  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
112
  GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
113

114
  widget_class->notify_gtk = gtk_toggle_button_accessible_notify_gtk;
115

116 117 118 119 120
  class->ref_state_set = gtk_toggle_button_accessible_ref_state_set;
  class->initialize = gtk_toggle_button_accessible_initialize;
}

static void
121
_gtk_toggle_button_accessible_init (GtkToggleButtonAccessible *button)
122
{
123
}