1 /* GTK+ - accessibility implementations
2 * Copyright (C) 2010 Intel Corporation
3 * Copyright (C) 2010 RedHat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Emmanuele Bassi <ebassi@linux.intel.com>
20 * Matthias Clasen <mclasen@redhat.com>
22 * Based on similar code from Mx.
27 #include <glib/gi18n-lib.h>
30 #include "gtkswitchaccessible.h"
33 static void atk_action_interface_init (AtkActionIface *iface);
35 G_DEFINE_TYPE_WITH_CODE (GtkSwitchAccessible, gtk_switch_accessible, GTK_TYPE_WIDGET_ACCESSIBLE,
36 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
39 gtk_switch_accessible_ref_state_set (AtkObject *accessible)
41 AtkStateSet *state_set;
44 state_set = ATK_OBJECT_CLASS (gtk_switch_accessible_parent_class)->ref_state_set (accessible);
46 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
50 if (gtk_switch_get_active (GTK_SWITCH (widget)))
51 atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
57 gtk_switch_accessible_initialize (AtkObject *accessible,
60 ATK_OBJECT_CLASS (gtk_switch_accessible_parent_class)->initialize (accessible, widget);
62 atk_object_set_role (accessible, ATK_ROLE_TOGGLE_BUTTON);
63 atk_object_set_name (accessible, C_("light switch widget", "Switch"));
64 atk_object_set_description (accessible, _("Switches between on and off states"));
68 gtk_switch_accessible_class_init (GtkSwitchAccessibleClass *klass)
70 AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
72 atk_class->initialize = gtk_switch_accessible_initialize;
73 atk_class->ref_state_set = gtk_switch_accessible_ref_state_set;
77 gtk_switch_accessible_init (GtkSwitchAccessible *self)
82 gtk_switch_action_get_n_actions (AtkAction *action)
88 gtk_switch_action_get_name (AtkAction *action,
97 gtk_switch_action_get_localized_name (AtkAction *action,
101 return C_("Action name", "Toggle");
106 gtk_switch_action_get_description (AtkAction *action,
110 return C_("Action description", "Toggles the switch");
115 gtk_switch_action_do_action (AtkAction *action,
121 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
128 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
131 sw = GTK_SWITCH (widget);
132 gtk_switch_set_active (sw, !gtk_switch_get_active (sw));
138 atk_action_interface_init (AtkActionIface *iface)
140 iface->do_action = gtk_switch_action_do_action;
141 iface->get_n_actions = gtk_switch_action_get_n_actions;
142 iface->get_name = gtk_switch_action_get_name;
143 iface->get_localized_name = gtk_switch_action_get_localized_name;
144 iface->get_description = gtk_switch_action_get_description;