diff options
author | Bill Haneman <billh@src.gnome.org> | 2001-04-26 14:23:41 +0000 |
---|---|---|
committer | Bill Haneman <billh@src.gnome.org> | 2001-04-26 14:23:41 +0000 |
commit | dba66b4bec94a908cd35a5537209db255fa5fa33 (patch) | |
tree | 3c6361db3558e2e2c70e9c802193974f45d24bf0 /atk/atkutil.c | |
download | atk-dba66b4bec94a908cd35a5537209db255fa5fa33.tar.gz |
Initial revision
Diffstat (limited to 'atk/atkutil.c')
-rwxr-xr-x | atk/atkutil.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/atk/atkutil.c b/atk/atkutil.c new file mode 100755 index 0000000..e9317f5 --- /dev/null +++ b/atk/atkutil.c @@ -0,0 +1,116 @@ +/* ATK - Accessibility Toolkit + * Copyright 2001 Sun Microsystems Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "atkutil.h" + +/* + * This file supports the addition and removal of multiple focus handlers + * as long as they are all called in the same thread. + */ +static AtkFocusTrackerInit focus_tracker_init = NULL; + +static gboolean init_done = FALSE; + +/* + * Array of FocusTracker structs + */ +static GArray *trackers = NULL; +static guint index = 0; + +struct _FocusTracker { + guint index; + AtkFocusTracker func; +}; +typedef struct _FocusTracker FocusTracker; + +void +atk_focus_tracker_init (AtkFocusTrackerInit init) +{ + if (focus_tracker_init == NULL) + focus_tracker_init = init; +} + +guint +atk_add_focus_tracker (AtkFocusTracker focus_tracker) +{ + g_return_val_if_fail ((focus_tracker != NULL), 0); + + if (!init_done) + { + if (focus_tracker_init != NULL) + { + focus_tracker_init (); + } + trackers = g_array_sized_new (FALSE, TRUE, sizeof (FocusTracker), 0); + init_done = TRUE; + } + if (init_done) + { + FocusTracker item; + + item.index = ++index; + item.func = focus_tracker; + trackers = g_array_append_val (trackers, item); + return index; + } + else + { + return 0; + } +} + +void +atk_remove_focus_tracker (guint tracker_id) +{ + FocusTracker *item; + guint i; + + if (trackers == NULL) + return; + + if (tracker_id == 0) + return; + + for (i = 0; i < trackers->len; i++) + { + item = &g_array_index (trackers, FocusTracker, i); + if (item->index == tracker_id) + { + trackers = g_array_remove_index (trackers, i); + break; + } + } +} + +void +atk_focus_tracker_notify (AtkObject *object) +{ + FocusTracker *item; + guint i; + + if (trackers == NULL) + return; + + for (i = 0; i < trackers->len; i++) + { + item = &g_array_index (trackers, FocusTracker, i); + g_return_if_fail (item != NULL); + item->func (object); + } +} |