diff options
-rw-r--r-- | atspi/atspi-relation.c | 135 | ||||
-rw-r--r-- | atspi/atspi-relation.h | 61 |
2 files changed, 196 insertions, 0 deletions
diff --git a/atspi/atspi-relation.c b/atspi/atspi-relation.c new file mode 100644 index 00000000..6fc5591e --- /dev/null +++ b/atspi/atspi-relation.c @@ -0,0 +1,135 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) + * + * Copyright 2001, 2002 Sun Microsystems Inc., + * Copyright 2001, 2002 Ximian, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library 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 "atspi-private.h" + +/** + * atspi_relation_get_relation_type: + * @obj: a pointer to the #AtspiRelation object to query. + * + * Get the type of relationship represented by an #AtspiRelation. + * + * Returns: an #AtspiRelationType indicating the type of relation + * encapsulated in this #AtspiRelation object. + * + **/ +AtspiRelationType +atspi_relation_get_relation_type (AtspiRelation *obj) +{ + return obj->relation_type; +} + +/** + * atspi_relation_get_n_targets: + * @obj: a pointer to the #AtspiRelation object to query. + * + * Get the number of objects which this relationship has as its + * target objects (the subject is the #Accessible from which this + * #AtspiRelation originated). + * + * Returns: a short integer indicating how many target objects which the + * originating #Accessible object has the #AtspiRelation + * relationship with. + **/ +gint +atspi_relation_get_n_targets (AtspiRelation *obj) +{ + return obj->targets->len; +} + +/** + * atspi_relation_get_target: + * @obj: a pointer to the #AtspiRelation object to query. + * @i: a (zero-index) integer indicating which (of possibly several) target is requested. + * + * Get the @i-th target of a specified #AtspiRelation relationship. + * + * Returns: (transfer full): an #AtspiAccessible which is the @i-th object + * with which the originating #AtspiAccessible has relationship + * specified in the #AtspiRelation object. + * + **/ +AtspiAccessible * +atspi_relation_get_target (AtspiRelation *obj, gint i) +{ + g_return_val_if_fail (obj, NULL); + + g_return_val_if_fail (i >= 0 && i < obj->targets->len, NULL); + return g_object_ref (g_array_index (obj->targets, AtspiAccessible *, i)); +} + +AtspiRelation * +_atspi_relation_new_from_iter (DBusMessageIter *iter) +{ + DBusMessageIter iter_struct, iter_array; + dbus_uint32_t d_type; + AtspiRelation *relation = g_object_new (ATSPI_TYPE_RELATION, NULL); + + if (!relation) + return NULL; + + dbus_message_iter_recurse (iter, &iter_struct); + dbus_message_iter_get_basic (&iter_struct, &d_type); + relation->relation_type = d_type; + dbus_message_iter_next (&iter_struct); + + relation->targets = g_array_new (TRUE, TRUE, sizeof (AtspiAccessible *)); + dbus_message_iter_recurse (&iter_struct, &iter_array); + while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID) + { + AtspiAccessible *accessible; + GArray *new_array; + accessible = _atspi_dbus_return_accessible_from_iter (&iter_array); + new_array = g_array_append_val (relation->targets, accessible); + if (new_array) + relation->targets = new_array; + /* Iter was moved already, so no need to call dbus_message_iter_next */ + } + return relation; +} + +G_DEFINE_TYPE (AtspiRelation, atspi_relation, G_TYPE_OBJECT) + +static void +atspi_relation_init (AtspiRelation *relation) +{ +} + +static void +atspi_relation_finalize (GObject *obj) +{ + AtspiRelation *relation = ATSPI_RELATION (obj); + gint i; + + for (i = 0; i < relation->targets->len; i++) + g_object_unref (g_array_index (relation->targets, AtspiAccessible *, i)); + g_array_free (relation->targets, TRUE); +} + +static void +atspi_relation_class_init (AtspiRelationClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = atspi_relation_finalize; +} diff --git a/atspi/atspi-relation.h b/atspi/atspi-relation.h new file mode 100644 index 00000000..13f7eae3 --- /dev/null +++ b/atspi/atspi-relation.h @@ -0,0 +1,61 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) + * + * Copyright 2002 Ximian, Inc. + * 2002 Sun Microsystems Inc. + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library 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. + */ + +#ifndef _ATSPI_RELATION_H_ +#define _ATSPI_RELATION_H_ + +#include "glib-object.h" + +#include "atspi-constants.h" + +#define ATSPI_TYPE_RELATION (atspi_relation_get_type ()) +#define ATSPI_IS_RELATION(obj) G_TYPE_CHECK_INSTANCE_TYPE ((obj), ATSPI_TYPE_RELATION) +#define ATSPI_RELATION(obj) G_TYPE_CHECK_INSTANCE_CAST ((obj), ATSPI_TYPE_RELATION, AtspiRelation) +#define ATSPI_RELATION_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), ATSPI_TYPE_RELATION, AtspiRelation)) + +GType atspi_relation_get_type (); + +typedef struct _AtspiRelation AtspiRelation; +struct _AtspiRelation +{ + GObject parent; + AtspiRelationType relation_type; + GArray *targets; +}; + +typedef struct _AtspiRelationClass AtspiRelationClass; +struct _AtspiRelationClass +{ + GObjectClass parent_class; +}; + +AtspiRelationType atspi_relation_get_relation_type (AtspiRelation *obj); + +gint atspi_relation_get_n_targets (AtspiRelation *obj); + +AtspiAccessible * atspi_relation_get_target (AtspiRelation *obj, gint i); + +/* private */ +AtspiRelation * _atspi_relation_new_from_iter (DBusMessageIter *iter); +#endif /* _ATSPI_RELATION_H_ */ |