Added atk_marshal_VOID__INT_INT marshaller. Updated the Makefiles so the
[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  **/
106 void
107 atk_remove_focus_tracker (guint            tracker_id)
108 {
109   FocusTracker *item;
110   guint i;
111
112   if (trackers == NULL)
113     return;
114
115   if (tracker_id == 0)
116     return;
117
118   for (i = 0; i < trackers->len; i++)
119   {
120     item = &g_array_index (trackers, FocusTracker, i);
121     if (item->index == tracker_id)
122     {
123       trackers = g_array_remove_index (trackers, i);
124       break;
125     }
126   }
127 }
128
129 /**
130  * atk_focus_tracker_notify:
131  * @object: an #AtkObject
132  *
133  * Cause the focus tracker functions which have been specified to be
134  * executed for the object.
135  *
136  **/
137 void
138 atk_focus_tracker_notify (AtkObject       *object)
139 {
140   FocusTracker *item;
141   guint i;
142
143   if (trackers == NULL)
144     return;
145
146   for (i = 0; i < trackers->len; i++)
147   {
148     item = &g_array_index (trackers, FocusTracker, i);
149     g_return_if_fail (item != NULL);
150     item->func (object);
151   }
152 }