1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
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.
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.
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.
21 #include "atkmarshal.c"
24 * This file supports the addition and removal of multiple focus handlers
25 * as long as they are all called in the same thread.
27 static AtkFocusTrackerInit focus_tracker_init = (AtkFocusTrackerInit) NULL;
29 static gboolean init_done = FALSE;
32 * Array of FocusTracker structs
34 static GArray *trackers = NULL;
35 static guint index = 0;
37 struct _FocusTracker {
41 typedef struct _FocusTracker FocusTracker;
44 * atk_focus_tracker_init:
45 * @add_function: Function to be called for focus tracker initialization
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
53 atk_focus_tracker_init (AtkFocusTrackerInit init)
55 if (!focus_tracker_init)
56 focus_tracker_init = init;
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.
64 * Adds the specified function to the list of functions to be called
65 * when an object receives focus.
67 * Returns: added focus tracker id, or 0 on failure.
70 atk_add_focus_tracker (AtkFocusTracker focus_tracker)
72 g_return_val_if_fail (focus_tracker, 0);
76 if (focus_tracker_init)
78 focus_tracker_init ();
80 trackers = g_array_sized_new (FALSE, TRUE, sizeof (FocusTracker), 0);
88 item.func = focus_tracker;
89 trackers = g_array_append_val (trackers, item);
99 * atk_remove_focus_tracker:
100 * @tracker_id: the id of the focus tracker to remove
102 * Removes the specified focus tracker from the list of functions
103 * to be called when any object receives focus.
106 atk_remove_focus_tracker (guint tracker_id)
111 if (trackers == NULL)
117 for (i = 0; i < trackers->len; i++)
119 item = &g_array_index (trackers, FocusTracker, i);
120 if (item->index == tracker_id)
122 trackers = g_array_remove_index (trackers, i);
129 * atk_focus_tracker_notify:
130 * @object: an #AtkObject
132 * Cause the focus tracker functions which have been specified to be
133 * executed for the object.
136 atk_focus_tracker_notify (AtkObject *object)
141 if (trackers == NULL)
144 for (i = 0; i < trackers->len; i++)
146 item = &g_array_index (trackers, FocusTracker, i);
147 g_return_if_fail (item != NULL);