| 1 |
/* GTK+ - accessibility implementations |
| 2 |
* Copyright (C) 2010 Intel Corporation |
| 3 |
* Copyright (C) 2010 RedHat, Inc. |
| 4 |
* |
| 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. |
| 9 |
* |
| 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. |
| 14 |
* |
| 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/>. |
| 17 |
* |
| 18 |
* Author: |
| 19 |
* Emmanuele Bassi <[email protected]> |
| 20 |
* Matthias Clasen <[email protected]> |
| 21 |
* |
| 22 |
* Based on similar code from Mx. |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "config.h" |
| 26 |
|
| 27 |
#include <glib/gi18n-lib.h> |
| 28 |
#include <gtk/gtk.h> |
| 29 |
#include "gtkintl.h" |
| 30 |
#include "gtkswitchaccessible.h" |
| 31 |
|
| 32 |
|
| 33 |
static void atk_action_interface_init (AtkActionIface *iface); |
| 34 |
|
| 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)) |
| 37 |
|
| 38 |
static AtkStateSet * |
| 39 |
gtk_switch_accessible_ref_state_set (AtkObject *accessible) |
| 40 |
{ |
| 41 |
AtkStateSet *state_set; |
| 42 |
GtkWidget *widget; |
| 43 |
|
| 44 |
state_set = ATK_OBJECT_CLASS (gtk_switch_accessible_parent_class)->ref_state_set (accessible); |
| 45 |
|
| 46 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)); |
| 47 |
if (widget == NULL) |
| 48 |
return state_set; |
| 49 |
|
| 50 |
if (gtk_switch_get_active (GTK_SWITCH (widget))) |
| 51 |
atk_state_set_add_state (state_set, ATK_STATE_CHECKED); |
| 52 |
|
| 53 |
return state_set; |
| 54 |
} |
| 55 |
|
| 56 |
static void |
| 57 |
gtk_switch_accessible_class_init (GtkSwitchAccessibleClass *klass) |
| 58 |
{ |
| 59 |
AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass); |
| 60 |
|
| 61 |
atk_class->ref_state_set = gtk_switch_accessible_ref_state_set; |
| 62 |
} |
| 63 |
|
| 64 |
static void |
| 65 |
gtk_switch_accessible_init (GtkSwitchAccessible *self) |
| 66 |
{ |
| 67 |
} |
| 68 |
|
| 69 |
static gint |
| 70 |
gtk_switch_action_get_n_actions (AtkAction *action) |
| 71 |
{ |
| 72 |
return 1; |
| 73 |
} |
| 74 |
|
| 75 |
static const gchar * |
| 76 |
gtk_switch_action_get_name (AtkAction *action, |
| 77 |
gint i) |
| 78 |
{ |
| 79 |
if (i == 0) |
| 80 |
return "toggle"; |
| 81 |
return NULL; |
| 82 |
} |
| 83 |
|
| 84 |
static const gchar * |
| 85 |
gtk_switch_action_get_localized_name (AtkAction *action, |
| 86 |
gint i) |
| 87 |
{ |
| 88 |
if (i == 0) |
| 89 |
return C_("Action name", "Toggle"); |
| 90 |
return NULL; |
| 91 |
} |
| 92 |
|
| 93 |
static const gchar * |
| 94 |
gtk_switch_action_get_description (AtkAction *action, |
| 95 |
gint i) |
| 96 |
{ |
| 97 |
if (i == 0) |
| 98 |
return C_("Action description", "Toggles the switch"); |
| 99 |
return NULL; |
| 100 |
} |
| 101 |
|
| 102 |
static gboolean |
| 103 |
gtk_switch_action_do_action (AtkAction *action, |
| 104 |
gint i) |
| 105 |
{ |
| 106 |
GtkSwitch *sw; |
| 107 |
GtkWidget *widget; |
| 108 |
|
| 109 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action)); |
| 110 |
if (widget == NULL) |
| 111 |
return FALSE; |
| 112 |
|
| 113 |
if (i != 0) |
| 114 |
return FALSE; |
| 115 |
|
| 116 |
if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget)) |
| 117 |
return FALSE; |
| 118 |
|
| 119 |
sw = GTK_SWITCH (widget); |
| 120 |
gtk_switch_set_active (sw, !gtk_switch_get_active (sw)); |
| 121 |
|
| 122 |
return TRUE; |
| 123 |
} |
| 124 |
|
| 125 |
static void |
| 126 |
atk_action_interface_init (AtkActionIface *iface) |
| 127 |
{ |
| 128 |
iface->do_action = gtk_switch_action_do_action; |
| 129 |
iface->get_n_actions = gtk_switch_action_get_n_actions; |
| 130 |
iface->get_name = gtk_switch_action_get_name; |
| 131 |
iface->get_localized_name = gtk_switch_action_get_localized_name; |
| 132 |
iface->get_description = gtk_switch_action_get_description; |
| 133 |
} |