Added better gtk-doc comments.
[platform/upstream/atk.git] / atk / atkutil.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "atkutil.h"
21
22 /*
23  * This file supports the addition and removal of multiple focus handlers
24  * as long as they are all called in the same thread.
25  */
26 static AtkFocusTrackerInit  focus_tracker_init = NULL;
27
28 static gboolean init_done = FALSE;
29
30 /*
31  * Array of FocusTracker structs
32  */
33 static GArray *trackers = NULL;
34 static guint  index = 0;
35
36 struct _FocusTracker {
37   guint index;
38   AtkFocusTracker func;
39 };
40 typedef struct _FocusTracker FocusTracker;
41   
42 /**
43  *atk_focus_tracker_init:
44  *@add_function: Function to be called for focus tracker initialization
45  *
46  * Specifies the function to be called for focus tracker initialization.
47  * This function should be called by an implementation of the
48  * ATK interface if any specific work needs to be done to enable
49  * focus tracking.
50  **/
51 void
52 atk_focus_tracker_init (AtkFocusTrackerInit    init)
53 {
54   if (focus_tracker_init == NULL)
55     focus_tracker_init = init;
56 }
57
58 /**
59  *atk_add_focus_tracker:
60  *@focus_tracker: Function to be added to the list of functions to be called
61  * when an object receives focus. 
62  *
63  * Adds the specified function to the list of functions to be called
64  * when an object receives focus.
65  *
66  * Returns: added focus tracker id, or 0 on failure.
67  **/
68 guint
69 atk_add_focus_tracker (AtkFocusTracker   focus_tracker)
70 {
71   g_return_val_if_fail ((focus_tracker != NULL), 0);
72
73   if (!init_done)
74   {
75     if (focus_tracker_init != NULL)
76     {
77       focus_tracker_init ();
78     }
79     trackers = g_array_sized_new (FALSE, TRUE, sizeof (FocusTracker), 0);
80     init_done = TRUE;
81   }
82   if (init_done)
83   {
84     FocusTracker item;
85
86     item.index = ++index;
87     item.func = focus_tracker;
88     trackers = g_array_append_val (trackers, item); 
89     return index;
90   }
91   else
92   {
93     return 0;
94   }
95 }
96
97 /**
98  *atk_remove_focus_tracker:
99  *@tracker_id: the id of the focus tracker to remove
100  *
101  * Removes the specified focus tracker from the list of functions
102  * to be called when any object receives focus
103  *
104  **/
105 void
106 atk_remove_focus_tracker (guint            tracker_id)
107 {
108   FocusTracker *item;
109   guint i;
110
111   if (trackers == NULL)
112     return;
113
114   if (tracker_id == 0)
115     return;
116
117   for (i = 0; i < trackers->len; i++)
118   {
119     item = &g_array_index (trackers, FocusTracker, i);
120     if (item->index == tracker_id)
121     {
122       trackers = g_array_remove_index (trackers, i);
123       break;
124     }
125   }
126 }
127
128 /**
129  *atk_focus_tracker_notify:
130  *@object: an #AtkObject
131  *
132  * Cause the focus tracker functions which have been specified to be
133  * executed for the object.
134  *
135  **/
136 void
137 atk_focus_tracker_notify (AtkObject       *object)
138 {
139   FocusTracker *item;
140   guint i;
141
142   if (trackers == NULL)
143     return;
144
145   for (i = 0; i < trackers->len; i++)
146   {
147     item = &g_array_index (trackers, FocusTracker, i);
148     g_return_if_fail (item != NULL);
149     item->func (object);
150   }
151 }