Released 0.1
[atk.git] / atk / atkutil.c
blobe9317f573f177749261f4257105772a6fd6e02ad
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.
20 #include "atkutil.h"
23 * This file supports the addition and removal of multiple focus handlers
24 * as long as they are all called in the same thread.
26 static AtkFocusTrackerInit focus_tracker_init = NULL;
28 static gboolean init_done = FALSE;
31 * Array of FocusTracker structs
33 static GArray *trackers = NULL;
34 static guint index = 0;
36 struct _FocusTracker {
37 guint index;
38 AtkFocusTracker func;
40 typedef struct _FocusTracker FocusTracker;
42 void
43 atk_focus_tracker_init (AtkFocusTrackerInit init)
45 if (focus_tracker_init == NULL)
46 focus_tracker_init = init;
49 guint
50 atk_add_focus_tracker (AtkFocusTracker focus_tracker)
52 g_return_val_if_fail ((focus_tracker != NULL), 0);
54 if (!init_done)
56 if (focus_tracker_init != NULL)
58 focus_tracker_init ();
60 trackers = g_array_sized_new (FALSE, TRUE, sizeof (FocusTracker), 0);
61 init_done = TRUE;
63 if (init_done)
65 FocusTracker item;
67 item.index = ++index;
68 item.func = focus_tracker;
69 trackers = g_array_append_val (trackers, item);
70 return index;
72 else
74 return 0;
78 void
79 atk_remove_focus_tracker (guint tracker_id)
81 FocusTracker *item;
82 guint i;
84 if (trackers == NULL)
85 return;
87 if (tracker_id == 0)
88 return;
90 for (i = 0; i < trackers->len; i++)
92 item = &g_array_index (trackers, FocusTracker, i);
93 if (item->index == tracker_id)
95 trackers = g_array_remove_index (trackers, i);
96 break;
101 void
102 atk_focus_tracker_notify (AtkObject *object)
104 FocusTracker *item;
105 guint i;
107 if (trackers == NULL)
108 return;
110 for (i = 0; i < trackers->len; i++)
112 item = &g_array_index (trackers, FocusTracker, i);
113 g_return_if_fail (item != NULL);
114 item->func (object);