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
|
/* ATK - Accessibility Toolkit
* Copyright 2001 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.
*/
#include "atkutil.h"
/*
* This file supports the addition and removal of multiple focus handlers
* as long as they are all called in the same thread.
*/
static AtkFocusTrackerInit focus_tracker_init = NULL;
static gboolean init_done = FALSE;
/*
* Array of FocusTracker structs
*/
static GArray *trackers = NULL;
static guint index = 0;
struct _FocusTracker {
guint index;
AtkFocusTracker func;
};
typedef struct _FocusTracker FocusTracker;
void
atk_focus_tracker_init (AtkFocusTrackerInit init)
{
if (focus_tracker_init == NULL)
focus_tracker_init = init;
}
guint
atk_add_focus_tracker (AtkFocusTracker focus_tracker)
{
g_return_val_if_fail ((focus_tracker != NULL), 0);
if (!init_done)
{
if (focus_tracker_init != NULL)
{
focus_tracker_init ();
}
trackers = g_array_sized_new (FALSE, TRUE, sizeof (FocusTracker), 0);
init_done = TRUE;
}
if (init_done)
{
FocusTracker item;
item.index = ++index;
item.func = focus_tracker;
trackers = g_array_append_val (trackers, item);
return index;
}
else
{
return 0;
}
}
void
atk_remove_focus_tracker (guint tracker_id)
{
FocusTracker *item;
guint i;
if (trackers == NULL)
return;
if (tracker_id == 0)
return;
for (i = 0; i < trackers->len; i++)
{
item = &g_array_index (trackers, FocusTracker, i);
if (item->index == tracker_id)
{
trackers = g_array_remove_index (trackers, i);
break;
}
}
}
void
atk_focus_tracker_notify (AtkObject *object)
{
FocusTracker *item;
guint i;
if (trackers == NULL)
return;
for (i = 0; i < trackers->len; i++)
{
item = &g_array_index (trackers, FocusTracker, i);
g_return_if_fail (item != NULL);
item->func (object);
}
}
|