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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
/*******************************************************************************
**3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
** 10 20 30 40 50 60 70 80
**
** notify-osd
**
** bubble-window-accessible.c - implements an accessible bubble window
**
** Copyright 2009 Canonical Ltd.
**
** Authors:
** Eitan Isaacson <eitan@ascender.com>
**
** This program is free software: you can redistribute it and/or modify it
** under the terms of the GNU General Public License version 3, as published
** by the Free Software Foundation.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranties of
** MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
** PURPOSE. See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along
** with this program. If not, see <http://www.gnu.org/licenses/>.
**
*******************************************************************************/
#include "bubble-window-accessible.h"
#include "bubble.h"
#include <string.h>
static void bubble_window_accessible_init (BubbleWindowAccessible* object);
static void bubble_window_accessible_finalize (GObject* object);
static void bubble_window_accessible_class_init (BubbleWindowAccessibleClass* klass);
static const char* bubble_window_accessible_get_name (AtkObject* obj);
static const char* bubble_window_accessible_get_description (AtkObject* obj);
static void bubble_window_real_initialize (AtkObject* obj,
gpointer data);
static void atk_value_interface_init (AtkValueIface* iface);
static void atk_text_interface_init (AtkTextIface* iface);
static void bubble_window_get_current_value (AtkValue* obj,
GValue* value);
static void bubble_window_get_maximum_value (AtkValue* obj,
GValue* value);
static void bubble_window_get_minimum_value (AtkValue* obj,
GValue* value);
static void bubble_value_changed_event (Bubble* bubble,
gint value,
AtkObject *obj);
static void bubble_message_body_deleted_event (Bubble* bubble,
const gchar* text,
AtkObject* obj);
static void bubble_message_body_inserted_event (Bubble* bubble,
const gchar* text,
AtkObject* obj);
static gchar* bubble_window_get_text (AtkText *obj,
gint start_offset,
gint end_offset);
static gint bubble_window_get_character_count (AtkText *obj);
static gunichar bubble_window_get_character_at_offset (AtkText *obj,
gint offset);
static void* bubble_window_accessible_parent_class;
G_DEFINE_TYPE_WITH_CODE (BubbleWindowAccessible, bubble_window_accessible, GTK_TYPE_ACCESSIBLE,
G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, atk_text_interface_init)
G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
static void
atk_value_interface_init (AtkValueIface* iface)
{
g_return_if_fail (iface != NULL);
iface->get_current_value = bubble_window_get_current_value;
iface->get_maximum_value = bubble_window_get_maximum_value;
iface->get_minimum_value = bubble_window_get_minimum_value;
}
static void
atk_text_interface_init (AtkTextIface* iface)
{
g_return_if_fail (iface != NULL);
iface->get_text = bubble_window_get_text;
iface->get_character_count = bubble_window_get_character_count;
iface->get_character_at_offset = bubble_window_get_character_at_offset;
}
static void
bubble_window_accessible_init (BubbleWindowAccessible *object)
{
/* TODO: Add initialization code here */
}
static void
bubble_window_accessible_finalize (GObject *object)
{
/* TODO: Add deinitalization code here */
G_OBJECT_CLASS (bubble_window_accessible_parent_class)->finalize (object);
}
static void
bubble_window_accessible_class_init (BubbleWindowAccessibleClass *klass)
{
GObjectClass* object_class = G_OBJECT_CLASS (klass);
AtkObjectClass* class = ATK_OBJECT_CLASS (klass);
bubble_window_accessible_parent_class = g_type_class_peek_parent (klass);
class->get_name = bubble_window_accessible_get_name;
class->get_description = bubble_window_accessible_get_description;
class->initialize = bubble_window_real_initialize;
object_class->finalize = bubble_window_accessible_finalize;
}
static void
bubble_window_real_initialize (AtkObject* obj,
gpointer data)
{
GtkWidget* widget = GTK_WIDGET (data);
Bubble* bubble;
ATK_OBJECT_CLASS (bubble_window_accessible_parent_class)->initialize (obj, data);
bubble = g_object_get_data (G_OBJECT(widget), "bubble");
g_signal_connect (bubble,
"value-changed",
G_CALLBACK (bubble_value_changed_event),
obj);
g_signal_connect (bubble,
"message-body-deleted",
G_CALLBACK (bubble_message_body_deleted_event),
obj);
g_signal_connect (bubble,
"message-body-inserted",
G_CALLBACK (bubble_message_body_inserted_event),
obj);
atk_object_set_role (obj, ATK_ROLE_NOTIFICATION);
}
AtkObject*
bubble_window_accessible_new (GtkWidget *widget)
{
GObject *object;
AtkObject *aobj;
object = g_object_new (BUBBLE_WINDOW_TYPE_ACCESSIBLE, NULL);
aobj = ATK_OBJECT (object);
gtk_accessible_set_widget (GTK_ACCESSIBLE (aobj), widget);
atk_object_initialize (aobj, widget);
return aobj;
}
static const char*
bubble_window_accessible_get_name (AtkObject* obj)
{
GtkWidget* widget;
Bubble* bubble;
const gchar* title;
g_return_val_if_fail (BUBBLE_WINDOW_IS_ACCESSIBLE (obj), "");
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
if (widget == NULL)
return "";
bubble = g_object_get_data (G_OBJECT (widget), "bubble");
g_return_val_if_fail (IS_BUBBLE (bubble), "");
title = bubble_get_title(bubble);
if (g_strcmp0(title, " ") == 0)
{
/* HACK: Titles should never be empty. This solution is extremely wrong.
https://bugs.launchpad.net/notify-osd/+bug/334292 */
const gchar* synch_str;
synch_str = bubble_get_synchronous(bubble);
if (synch_str != NULL)
return synch_str;
else
return "";
}
return title;
}
static const char*
bubble_window_accessible_get_description (AtkObject* obj)
{
GtkWidget *widget;
Bubble *bubble;
g_return_val_if_fail (BUBBLE_WINDOW_IS_ACCESSIBLE (obj), "");
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
if (widget == NULL)
return "";
bubble = g_object_get_data (G_OBJECT (widget), "bubble");
g_return_val_if_fail (IS_BUBBLE (bubble), "");
return bubble_get_message_body(bubble);
}
static void
bubble_window_get_current_value (AtkValue* obj,
GValue* value)
{
gdouble current_value;
GtkWidget* widget;
Bubble* bubble;
g_return_if_fail (BUBBLE_WINDOW_IS_ACCESSIBLE (obj));
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
if (widget == NULL)
return;
bubble = g_object_get_data (G_OBJECT (widget), "bubble");
current_value = (gdouble) bubble_get_value(bubble);
memset (value, 0, sizeof (GValue));
g_value_init (value, G_TYPE_DOUBLE);
g_value_set_double (value,current_value);
}
static void
bubble_window_get_maximum_value (AtkValue* obj,
GValue* value)
{
memset (value, 0, sizeof (GValue));
g_value_init (value, G_TYPE_DOUBLE);
g_value_set_double (value, 100.0);
}
static void
bubble_window_get_minimum_value (AtkValue* obj,
GValue* value)
{
memset (value, 0, sizeof (GValue));
g_value_init (value, G_TYPE_DOUBLE);
g_value_set_double (value, 0.0);
}
static void
bubble_value_changed_event (Bubble* bubble,
gint value,
AtkObject* obj)
{
g_object_notify (G_OBJECT (obj), "accessible-value");
}
static void
bubble_message_body_deleted_event (Bubble* bubble,
const gchar* text,
AtkObject* obj)
{
/* Not getting very fancy here, delete is always complete */
g_signal_emit_by_name (
obj, "text_changed::delete", 0, g_utf8_strlen (text, -1));
}
static void
bubble_message_body_inserted_event (Bubble* bubble,
const gchar* text,
AtkObject* obj)
{
const gchar* message_body;
message_body = bubble_get_message_body (bubble);
g_signal_emit_by_name (
obj, "text_changed::insert",
g_utf8_strlen (message_body, -1) - g_utf8_strlen (text, -1),
g_utf8_strlen (message_body, -1));
}
static gchar*
bubble_window_get_text (AtkText *obj,
gint start_offset,
gint end_offset)
{
GtkWidget* widget;
Bubble* bubble;
const gchar* body_text;
gsize char_length;
glong body_strlen;
g_return_val_if_fail (BUBBLE_WINDOW_IS_ACCESSIBLE (obj), g_strdup(""));
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
g_return_val_if_fail (GTK_IS_WINDOW (widget), g_strdup(""));
bubble = g_object_get_data (G_OBJECT(widget), "bubble");
if (end_offset <= start_offset)
return g_strdup("");
body_text = bubble_get_message_body (bubble);
body_strlen = g_utf8_strlen(body_text, -1);
if (start_offset > body_strlen)
start_offset = body_strlen;
if (end_offset > body_strlen || end_offset == -1)
end_offset = body_strlen;
char_length = g_utf8_offset_to_pointer (body_text, end_offset) -
g_utf8_offset_to_pointer (body_text, start_offset);
return g_strndup (g_utf8_offset_to_pointer(body_text, start_offset),
char_length);
}
static gint
bubble_window_get_character_count (AtkText *obj)
{
GtkWidget* widget;
Bubble* bubble;
g_return_val_if_fail (BUBBLE_WINDOW_IS_ACCESSIBLE (obj), 0);
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
if (widget == NULL)
return 0;
bubble = g_object_get_data (G_OBJECT (widget), "bubble");
return g_utf8_strlen(bubble_get_message_body (bubble), -1);
}
static gunichar
bubble_window_get_character_at_offset (AtkText *obj,
gint offset)
{
GtkWidget* widget;
Bubble* bubble;
const gchar* body_text;
g_return_val_if_fail (BUBBLE_WINDOW_IS_ACCESSIBLE (obj), 0);
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
if (widget == NULL)
return 0;
bubble = g_object_get_data (G_OBJECT (widget), "bubble");
body_text = bubble_get_message_body (bubble);
return g_utf8_get_char (g_utf8_offset_to_pointer (body_text, offset));
}
|