1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
/* GAIL - The GNOME Accessibility Implementation Library
* Copyright 2011 Red Hat, 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 "gtklinkbuttonaccessible.h"
typedef struct _GtkLinkButtonAccessibleLink GtkLinkButtonAccessibleLink;
typedef struct _GtkLinkButtonAccessibleLinkClass GtkLinkButtonAccessibleLinkClass;
struct _GtkLinkButtonAccessibleLink
{
AtkHyperlink parent;
GtkLinkButtonAccessible *button;
};
struct _GtkLinkButtonAccessibleLinkClass
{
AtkHyperlinkClass parent_class;
};
static void atk_action_interface_init (AtkActionIface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkLinkButtonAccessibleLink, _gtk_link_button_accessible_link, ATK_TYPE_HYPERLINK,
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
static AtkHyperlink *
gtk_link_button_accessible_link_new (GtkLinkButtonAccessible *button)
{
GtkLinkButtonAccessibleLink *l;
l = g_object_new (_gtk_link_button_accessible_link_get_type (), NULL);
l->button = button;
return ATK_HYPERLINK (l);
}
static gchar *
gtk_link_button_accessible_link_get_uri (AtkHyperlink *atk_link,
gint i)
{
GtkLinkButtonAccessibleLink *l = (GtkLinkButtonAccessibleLink *)atk_link;
GtkWidget *widget;
const gchar *uri;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (l->button));
uri = gtk_link_button_get_uri (GTK_LINK_BUTTON (widget));
return g_strdup (uri);
}
static gint
gtk_link_button_accessible_link_get_n_anchors (AtkHyperlink *atk_link)
{
return 1;
}
static gboolean
gtk_link_button_accessible_link_is_valid (AtkHyperlink *atk_link)
{
return TRUE;
}
static AtkObject *
gtk_link_button_accessible_link_get_object (AtkHyperlink *atk_link,
gint i)
{
GtkLinkButtonAccessibleLink *l = (GtkLinkButtonAccessibleLink *)atk_link;
return ATK_OBJECT (l->button);
}
static gint
gtk_link_button_accessible_link_get_start_index (AtkHyperlink *atk_link)
{
return 0;
}
static gint
gtk_link_button_accessible_link_get_end_index (AtkHyperlink *atk_link)
{
GtkLinkButtonAccessibleLink *l = (GtkLinkButtonAccessibleLink *)atk_link;
return atk_text_get_character_count (ATK_TEXT (l->button));
}
static void
_gtk_link_button_accessible_link_init (GtkLinkButtonAccessibleLink *l)
{
}
static void
_gtk_link_button_accessible_link_class_init (GtkLinkButtonAccessibleLinkClass *class)
{
AtkHyperlinkClass *atk_link_class = ATK_HYPERLINK_CLASS (class);
atk_link_class->get_uri = gtk_link_button_accessible_link_get_uri;
atk_link_class->get_n_anchors = gtk_link_button_accessible_link_get_n_anchors;
atk_link_class->is_valid = gtk_link_button_accessible_link_is_valid;
atk_link_class->get_object = gtk_link_button_accessible_link_get_object;
atk_link_class->get_start_index = gtk_link_button_accessible_link_get_start_index;
atk_link_class->get_end_index = gtk_link_button_accessible_link_get_end_index;
}
static gboolean
gtk_link_button_accessible_link_do_action (AtkAction *action,
gint i)
{
GtkLinkButtonAccessibleLink *l = (GtkLinkButtonAccessibleLink *)action;
GtkWidget *widget;
widget = GTK_WIDGET (l->button);
if (widget == NULL)
return FALSE;
if (i != 0)
return FALSE;
if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
return FALSE;
gtk_button_clicked (GTK_BUTTON (widget));
return TRUE;
}
static gint
gtk_link_button_accessible_link_get_n_actions (AtkAction *action)
{
return 1;
}
static const gchar *
gtk_link_button_accessible_link_get_name (AtkAction *action,
gint i)
{
if (i != 0)
return NULL;
return "activate";
}
static void
atk_action_interface_init (AtkActionIface *iface)
{
iface->do_action = gtk_link_button_accessible_link_do_action;
iface->get_n_actions = gtk_link_button_accessible_link_get_n_actions;
iface->get_name = gtk_link_button_accessible_link_get_name;
}
static gboolean
activate_link (GtkLinkButton *button,
AtkHyperlink *atk_link)
{
g_signal_emit_by_name (atk_link, "link-activated");
return FALSE;
}
static AtkHyperlink *
gtk_link_button_accessible_get_hyperlink (AtkHyperlinkImpl *impl)
{
GtkLinkButtonAccessible *button = GTK_LINK_BUTTON_ACCESSIBLE (impl);
if (!button->link)
{
button->link = gtk_link_button_accessible_link_new (button);
g_signal_connect (gtk_accessible_get_widget (GTK_ACCESSIBLE (button)),
"activate-link", G_CALLBACK (activate_link), button->link);
}
return g_object_ref (button->link);
}
static void atk_hypertext_impl_interface_init (AtkHyperlinkImplIface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkLinkButtonAccessible, _gtk_link_button_accessible, GTK_TYPE_BUTTON_ACCESSIBLE,
G_IMPLEMENT_INTERFACE (ATK_TYPE_HYPERLINK_IMPL, atk_hypertext_impl_interface_init))
static void
_gtk_link_button_accessible_init (GtkLinkButtonAccessible *button)
{
}
static void
gtk_link_button_accessible_finalize (GObject *object)
{
GtkLinkButtonAccessible *button = GTK_LINK_BUTTON_ACCESSIBLE (object);
if (button->link)
g_object_unref (button->link);
G_OBJECT_CLASS (_gtk_link_button_accessible_parent_class)->finalize (object);
}
static void
_gtk_link_button_accessible_class_init (GtkLinkButtonAccessibleClass *klass)
{
G_OBJECT_CLASS (klass)->finalize = gtk_link_button_accessible_finalize;
}
static void
atk_hypertext_impl_interface_init (AtkHyperlinkImplIface *iface)
{
iface->get_hyperlink = gtk_link_button_accessible_get_hyperlink;
}
|