Cleaned up docs.
[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 #include "atkmarshal.c"
22
23 /*
24  * This file supports the addition and removal of multiple focus handlers
25  * as long as they are all called in the same thread.
26  */
27 static AtkFocusTrackerInit  focus_tracker_init = (AtkFocusTrackerInit) NULL;
28
29 static gboolean init_done = FALSE;
30
31 /*
32  * Array of FocusTracker structs
33  */
34 static GArray *trackers = NULL;
35 static guint  index = 0;
36
37 struct _FocusTracker {
38   guint index;
39   AtkFocusTracker func;
40 };
41 typedef struct _FocusTracker FocusTracker;
42   
43 /**
44  * atk_focus_tracker_init:
45  * @add_function: Function to be called for focus tracker initialization
46  *
47  * Specifies the function to be called for focus tracker initialization.
48  * This function should be called by an implementation of the
49  * ATK interface if any specific work needs to be done to enable
50  * focus tracking.
51  **/
52 void
53 atk_focus_tracker_init (AtkFocusTrackerInit    init)
54 {
55   if (!focus_tracker_init)
56     focus_tracker_init = init;
57 }
58
59 /**
60  * atk_add_focus_tracker:
61  * @focus_tracker: Function to be added to the list of functions to be called
62  * when an object receives focus. 
63  *
64  * Adds the specified function to the list of functions to be called
65  * when an object receives focus.
66  *
67  * Returns: added focus tracker id, or 0 on failure.
68  **/
69 guint
70 atk_add_focus_tracker (AtkFocusTracker   focus_tracker)
71 {
72   g_return_val_if_fail (focus_tracker, 0);
73
74   if (!init_done)
75   {
76     if (focus_tracker_init)
77     {
78       focus_tracker_init ();
79     }
80     trackers = g_array_sized_new (FALSE, TRUE, sizeof (FocusTracker), 0);
81     init_done = TRUE;
82   }
83   if (init_done)
84   {
85     FocusTracker item;
86
87     item.index = ++index;
88     item.func = focus_tracker;
89     trackers = g_array_append_val (trackers, item); 
90     return index;
91   }
92   else
93   {
94     return 0;
95   }
96 }
97
98 /**
99  * atk_remove_focus_tracker:
100  * @tracker_id: the id of the focus tracker to remove
101  *
102  * Removes the specified focus tracker from the list of functions
103  * to be called when any object receives focus.
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 void
136 atk_focus_tracker_notify (AtkObject       *object)
137 {
138   FocusTracker *item;
139   guint i;
140
141   if (trackers == NULL)
142     return;
143
144   for (i = 0; i < trackers->len; i++)
145   {
146     item = &g_array_index (trackers, FocusTracker, i);
147     g_return_if_fail (item != NULL);
148     item->func (object);
149   }
150 }