summaryrefslogtreecommitdiff
path: root/atk/atkrelation.c
diff options
context:
space:
mode:
authorPadraig O'Briain <padraigo@src.gnome.org>2001-11-22 15:58:58 +0000
committerPadraig O'Briain <padraigo@src.gnome.org>2001-11-22 15:58:58 +0000
commit904c325f06e97a4c2cf376f294b95bc23d0793d8 (patch)
treee7f4534e104092ab64ac96a8cf058fa982493323 /atk/atkrelation.c
parent77626512f3d262bf2eb3986f5d42cb567184554d (diff)
downloadatk-904c325f06e97a4c2cf376f294b95bc23d0793d8.tar.gz
Change atk_relation_type_from_string to atk_relation_type_for_name Add
* atk/atk.def, atk/atkrelationtype.h, docs/atk-sections.txt, docs/tmpl/atkrelation.sgml: Change atk_relation_type_from_string to atk_relation_type_for_name Add atk_relation_type_get_name * atk/atkrelationtype.c: Change atk_relation_type_from_string to atk_relation_type_for_name Add atk_relation_type_get_name Update atk_relation_type_register() to correctly register new relation types * atk/atkstate.c: Changed name of static variable type to last_type Changed name of paremeter if atk_state_type_get_name to type to match comments * docs/tmpl/*sgml Updated files * tests/README, tests/Makefile.am Add new test file testrelation.c
Diffstat (limited to 'atk/atkrelation.c')
-rwxr-xr-xatk/atkrelation.c89
1 files changed, 74 insertions, 15 deletions
diff --git a/atk/atkrelation.c b/atk/atkrelation.c
index e1d8944..9737fb1 100755
--- a/atk/atkrelation.c
+++ b/atk/atkrelation.c
@@ -22,6 +22,18 @@
#include "atkobject.h"
#include "atkrelation.h"
+static gchar *relation_names[ATK_RELATION_LAST_DEFINED] = {
+ "null",
+ "controlled_by",
+ "controller_for",
+ "label_for",
+ "labelled_by",
+ "member_of",
+ "node_child_of"
+};
+
+GPtrArray *extra_names = NULL;
+
static void atk_relation_class_init (AtkRelationClass *klass);
static void atk_relation_finalize (GObject *object);
@@ -68,14 +80,48 @@ atk_relation_class_init (AtkRelationClass *klass)
AtkRelationType
atk_relation_type_register (const gchar *name)
{
- /* TODO: associate name with new type */
- static guint type = ATK_RELATION_LAST_DEFINED;
- return (++type);
+ g_return_val_if_fail (name, ATK_RELATION_NULL);
+
+ if (!extra_names)
+ extra_names = g_ptr_array_new ();
+
+ g_ptr_array_add (extra_names, g_strdup (name));
+ return extra_names->len + ATK_RELATION_LAST_DEFINED - 1;
}
+/**
+ * atk_relation_type_get_name:
+ * @type: The #AtkRelationType whose name is required
+ *
+ * Gets the description string describing the #AtkRelationType @type.
+ *
+ * Returns: the string describing the AtkRelationType
+ */
+G_CONST_RETURN gchar*
+atk_relation_type_get_name (AtkRelationType type)
+{
+ gint n;
+
+ n = type;
+
+ if (n >= 0)
+ {
+ if (n < ATK_RELATION_LAST_DEFINED)
+ return relation_names[n];
+ else if (extra_names)
+ {
+ n -= ATK_RELATION_LAST_DEFINED;
+
+ if (n < extra_names->len)
+ return g_ptr_array_index (extra_names, n);
+ }
+ }
+ return ATK_RELATION_NULL;
+
+}
/**
- * atk_relation_type_from_string:
+ * atk_relation_type_for_name:
* @name: a string which is the (non-localized) name of an ATK relation type.
*
* Get the #AtkRelationType type corresponding to a relation name.
@@ -84,18 +130,31 @@ atk_relation_type_register (const gchar *name)
* or #ATK_RELATION_NULL if no matching relation type is found.
**/
AtkRelationType
-atk_relation_type_from_string (const gchar *name)
+atk_relation_type_for_name (const gchar *name)
{
- /*
- * TODO: implement properly,
- * checking type namelist in conjunction with above function.
- */
- if ( !strcmp (name, "controlled_by") ) return ATK_RELATION_CONTROLLED_BY;
- else if (!strcmp (name, "controller_for")) return ATK_RELATION_CONTROLLER_FOR;
- else if (!strcmp (name, "label_for")) return ATK_RELATION_LABEL_FOR;
- else if (!strcmp (name, "labelled_by")) return ATK_RELATION_LABELLED_BY;
- else if (!strcmp (name, "member_of")) return ATK_RELATION_MEMBER_OF;
- else return ATK_RELATION_NULL;
+ gint i;
+
+ g_return_val_if_fail (name, ATK_RELATION_NULL);
+
+ for (i = 0; i < ATK_RELATION_LAST_DEFINED; i++)
+ {
+ if (strcmp (name, relation_names[i]) == 0)
+ return i;
+ }
+
+ if (extra_names)
+ {
+ for (i = 0; i < extra_names->len; i++)
+ {
+ gchar *extra_name = (gchar *)g_ptr_array_index (extra_names, i);
+
+ g_return_val_if_fail (extra_name, ATK_RELATION_NULL);
+
+ if (strcmp (name, extra_name) == 0)
+ return i + ATK_RELATION_LAST_DEFINED;
+ }
+ }
+ return ATK_RELATION_NULL;
}