Add implementation of atk_attribute_register, atk_attribute_for_name Udate
authorPadraig O'Briain <padraigo@src.gnome.org>
Tue, 4 Dec 2001 18:39:20 +0000 (18:39 +0000)
committerPadraig O'Briain <padraigo@src.gnome.org>
Tue, 4 Dec 2001 18:39:20 +0000 (18:39 +0000)
* atk/atktext.c:
Add implementation of atk_attribute_register, atk_attribute_for_name
Udate atk_attribute_get_name to use ATK_TYPE_TEXT__ATTRIBUTE and
support extra attributes being defined

* atk/atktext.h:
Add ATK_TEXT_ATTR_INVALID and ATK_TEXT_ATTR_LAST_DEFINED to allow
extra attributes to be defined
Add atk_attribute_register() and atk_attribute_for_name()

* atk/atk.def:
Add new functions

* docs/atk-sections.txt docs/tmpl/atktext.sgml
Update because of additions to atk/atktext.h

* tests/testrelation.c:
Add tests for text attributes

ChangeLog
atk/atk.def
atk/atktext.c
atk/atktext.h
docs/atk-sections.txt
docs/tmpl/atktext.sgml
tests/testrelation.c

index 39ee883..51886a4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
 2001-12-04  Padraig O'Briain  <padraig.obriain@sun.com>
 
+       * atk/atktext.c:
+       Add implementation of atk_attribute_register, atk_attribute_for_name
+       Udate atk_attribute_get_name to use ATK_TYPE_TEXT__ATTRIBUTE and
+       support extra attributes being defined
+
+       * atk/atktext.h:
+       Add ATK_TEXT_ATTR_INVALID and ATK_TEXT_ATTR_LAST_DEFINED to allow
+       extra attributes to be defined
+       Add atk_attribute_register() and atk_attribute_for_name()
+
+       * atk/atk.def:
+       Add new functions
+
+       * docs/atk-sections.txt docs/tmpl/atktext.sgml
+       Update because of additions to atk/atktext.h
+
+       * tests/testrelation.c:
+       Add tests for text attributes
+
+2001-12-04  Padraig O'Briain  <padraig.obriain@sun.com>
+
        * atk/atkobject.c:
        Update atk_role_register() to allow extra roles to be defined
        Update atk_role_get_name() and atk_role_for_name() for newly defined
index fa352dd..cbc0d76 100644 (file)
@@ -9,8 +9,9 @@ EXPORTS
        atk_add_focus_tracker
        atk_add_global_event_listener
        atk_add_key_event_listener
-       atk_attribute_get_name
        atk_attribute_get_value
+       atk_attribute_for_name
+       atk_attribute_register
        atk_attribute_set_free
        atk_component_add_focus_handler
        atk_component_contains
@@ -24,6 +25,7 @@ EXPORTS
        atk_component_set_extents
        atk_component_set_position
        atk_component_set_size
+       atk_coord_type_get_type
        atk_document_get_document
        atk_document_get_document_type
        atk_document_get_type
@@ -52,6 +54,7 @@ EXPORTS
        atk_hypertext_get_link_index
        atk_hypertext_get_n_links
        atk_hypertext_get_type
+       atk_key_event_type_get_type
        atk_image_get_image_description
        atk_image_get_image_position
        atk_image_get_image_size
@@ -59,6 +62,7 @@ EXPORTS
        atk_image_set_image_description
        atk_implementor_get_type
        atk_implementor_ref_accessible
+       atk_layer_get_type
        atk_no_op_object_factory_get_type
        atk_no_op_object_factory_new
        atk_no_op_object_get_type
@@ -103,10 +107,14 @@ EXPORTS
        atk_relation_set_remove
        atk_relation_type_for_name
        atk_relation_type_get_name
+       atk_relation_type_get_type
        atk_relation_type_register
        atk_remove_focus_tracker
        atk_remove_global_event_listener
        atk_remove_key_event_listener
+       atk_role_get_name
+       atk_role_get_type
+       atk_role_for_name
        atk_role_register
        atk_selection_add_selection
        atk_selection_clear_selection
@@ -130,6 +138,7 @@ EXPORTS
        atk_state_set_xor_sets
        atk_state_type_for_name
        atk_state_type_get_name
+       atk_state_type_get_type
        atk_state_type_register
        atk_streamable_content_get_mime_type
        atk_streamable_content_get_n_mime_types
@@ -167,6 +176,7 @@ EXPORTS
        atk_table_set_summary
        atk_text_add_selection
        atk_text_get_caret_offset
+       atk_text_attribute_get_type
        atk_text_get_character_at_offset
        atk_text_get_character_count
        atk_text_get_character_extents
index 0e985a9..4ab7415 100755 (executable)
@@ -19,6 +19,9 @@
 
 #include "atktext.h"
 #include "atkmarshal.h"
+#include "atk-enum-types.h"
+
+GPtrArray *extra_attributes = NULL;
 
 enum {
   TEXT_CHANGED,
@@ -27,36 +30,6 @@ enum {
   LAST_SIGNAL
 };
 
-static const gchar * text_attr_name[] = {
-  "left_margin",
-  "right_margin",
-  "indent",
-  "invisible",
-  "editable",
-  "pixels_above_lines",
-  "pixels_below_lines",
-  "pixels_inside_wrap",
-  "bg_full_height",
-  "rise",
-  "underline",
-  "strikethrough",
-  "size",
-  "scale",
-  "weight",
-  "language",
-  "family_name",
-  "bg_color",
-  "fg_color",
-  "bg_stipple",
-  "fg_stipple",
-  "wrap_mode",
-  "direction",
-  "justification",
-  "stretch",
-  "variant",
-  "slant_style",
-};
-
 static const gchar *bool[] = {"false",
                               "true"};
 static const gchar *style[] = {"normal",
@@ -891,6 +864,26 @@ atk_attribute_set_free (AtkAttributeSet *attrib_set)
 }
 
 /**
+ * atk_attribute_register:
+ * @name: a name string
+ *
+ * Associate @name with a new #AtkTextAttribute
+ *
+ * Returns: an #AtkTextAttribute associated with @name
+ **/
+AtkTextAttribute
+atk_attribute_register (const gchar *name)
+{
+  g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
+
+  if (!extra_attributes)
+    extra_attributes = g_ptr_array_new ();
+
+  g_ptr_array_add (extra_attributes, g_strdup (name));
+  return extra_attributes->len + ATK_TEXT_ATTR_LAST_DEFINED;
+}
+
+/**
  * atk_attribute_get_name:
  * @attr: The #AtkTextAttribute whose name is required
  *
@@ -901,10 +894,90 @@ atk_attribute_set_free (AtkAttributeSet *attrib_set)
 G_CONST_RETURN gchar*
 atk_attribute_get_name (AtkTextAttribute attr)
 {
-  g_assert (attr >= 0 && attr <= ATK_TEXT_ATTR_STYLE);
-  return text_attr_name[attr];
+  GTypeClass *type_class;
+  GEnumValue *value;
+  gchar *name = NULL;
+
+  type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
+  g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
+
+  value = g_enum_get_value (G_ENUM_CLASS (type_class), attr);
+
+  if (value)
+    {
+      name = value->value_nick;
+    }
+  else
+    {
+      if (extra_attributes)
+        {
+          gint n = attr;
+
+          n -= ATK_TEXT_ATTR_LAST_DEFINED + 1;
+
+          if (n < extra_attributes->len)
+
+            name = g_ptr_array_index (extra_attributes, n);
+        }
+    }
+  g_type_class_unref (type_class);
+  return name;
+}
+
+/**
+ * atk_attribute_for_name:
+ * @name: a string which is the (non-localized) name of an ATK text attribute.
+ *
+ * Get the #AtkTextAttribute type corresponding to a text attribute name.
+ *
+ * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
+name,
+ *          or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
+ **/
+AtkTextAttribute
+atk_attribute_for_name (const gchar *name)
+{
+  GTypeClass *type_class;
+  GEnumValue *value;
+  AtkTextAttribute type = ATK_TEXT_ATTR_INVALID;
+
+  g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
+
+  type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
+  g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_TEXT_ATTR_INVALID);
+
+  value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
+
+  if (value)
+    {
+      type = value->value;
+    }
+  else
+    {
+      gint i;
+
+      if (extra_attributes)
+        {
+          for (i = 0; i < extra_attributes->len; i++)
+            {
+              gchar *extra_attribute = (gchar *)g_ptr_array_index (extra_attributes, i);
+
+              g_return_val_if_fail (extra_attribute, ATK_TEXT_ATTR_INVALID);
+
+              if (strcmp (name, extra_attribute) == 0)
+                {
+                  type = i + 1 + ATK_TEXT_ATTR_LAST_DEFINED;
+                  break;
+                }
+            }
+        }
+    }
+  g_type_class_unref (type_class);
+
+  return type;
 }
 
+
 /**
  * atk_attribute_get_value:
  * @attr: The #AtkTextAttribute for which a value is required
index d8b92ca..80378ab 100755 (executable)
@@ -57,6 +57,7 @@ struct _AtkAttribute {
 
 /**
  *AtkTextAttribute
+ *@ATK_TEXT_ATTR_INVALID: Invalid attribute
  *@ATK_TEXT_ATTR_LEFT_MARGIN: The pixel width of the left margin
  *@ATK_TEXT_ATTR_RIGHT_MARGIN: The pixel width of the right margin
  *@ATK_TEXT_ATTR_INDENT: The number of pixels that the text is indented
@@ -84,11 +85,13 @@ struct _AtkAttribute {
  *@ATK_TEXT_ATTR_STRETCH: The stretch of the text, if set. Values are "ultra_condensed", "extra_condensed", "condensed", "semi_condensed", "normal", "semi_expanded", "expanded", "extra_expanded" or "ultra_expanded"
  *@ATK_TEXT_ATTR_VARIANT: The capitalization variant of the text, if set. Values are "normal" or "small_caps"
  *@ATK_TEXT_ATTR_STYLE: The slant style of the text, if set. Values are "normal", "oblique" or "italic"
+ *@ATK_TEXT_ATTR_LAST_DEFINED: not a valid text attribute, used for finding end of enumeration
  *
  * Describes the text attributes supported
  **/
 typedef enum
 {
+  ATK_TEXT_ATTR_INVALID = 0,
   ATK_TEXT_ATTR_LEFT_MARGIN,
   ATK_TEXT_ATTR_RIGHT_MARGIN,
   ATK_TEXT_ATTR_INDENT,
@@ -115,9 +118,13 @@ typedef enum
   ATK_TEXT_ATTR_JUSTIFICATION,
   ATK_TEXT_ATTR_STRETCH,
   ATK_TEXT_ATTR_VARIANT,
-  ATK_TEXT_ATTR_STYLE
+  ATK_TEXT_ATTR_STYLE,
+  ATK_TEXT_ATTR_LAST_DEFINED
 } AtkTextAttribute;
 
+AtkTextAttribute         atk_attribute_register        (const gchar *name);
+
+
 #define ATK_TYPE_TEXT                    (atk_text_get_type ())
 #define ATK_IS_TEXT(obj)                 G_TYPE_CHECK_INSTANCE_TYPE ((obj), ATK_TYPE_TEXT)
 #define ATK_TEXT(obj)                    G_TYPE_CHECK_INSTANCE_CAST ((obj), ATK_TYPE_TEXT, AtkText)
@@ -287,6 +294,7 @@ gboolean      atk_text_set_caret_offset                   (AtkText          *tex
                                                            gint             offset);
 void         atk_attribute_set_free                      (AtkAttributeSet  *attrib_set);
 G_CONST_RETURN gchar*  atk_attribute_get_name             (AtkTextAttribute attr);
+AtkTextAttribute       atk_attribute_for_name             (const gchar      *name);
 G_CONST_RETURN gchar*  atk_attribute_get_value            (AtkTextAttribute attr,
                                                            gint             index);
 
index 13aece2..bf58b80 100644 (file)
@@ -377,7 +377,9 @@ atk_text_remove_selection
 atk_text_set_selection
 atk_text_set_caret_offset
 atk_attribute_set_free
+atk_attribute_register
 atk_attribute_get_name
+atk_attribute_for_name
 atk_attribute_get_value
 <SUBSECTION Standard>
 ATK_TEXT
index c04552b..0e04e6a 100644 (file)
@@ -79,6 +79,7 @@ AtkText
 
 </para>
 
+@ATK_TEXT_ATTR_INVALID: 
 @ATK_TEXT_ATTR_LEFT_MARGIN: 
 @ATK_TEXT_ATTR_RIGHT_MARGIN: 
 @ATK_TEXT_ATTR_INDENT: 
@@ -106,6 +107,7 @@ AtkText
 @ATK_TEXT_ATTR_STRETCH: 
 @ATK_TEXT_ATTR_VARIANT: 
 @ATK_TEXT_ATTR_STYLE: 
+@ATK_TEXT_ATTR_LAST_DEFINED: 
 
 <!-- ##### FUNCTION atk_text_get_text ##### -->
 <para>
@@ -306,6 +308,15 @@ AtkText
 @attrib_set: 
 
 
+<!-- ##### FUNCTION atk_attribute_register ##### -->
+<para>
+
+</para>
+
+@name: 
+@Returns: 
+
+
 <!-- ##### FUNCTION atk_attribute_get_name ##### -->
 <para>
 
@@ -315,6 +326,15 @@ AtkText
 @Returns: 
 
 
+<!-- ##### FUNCTION atk_attribute_for_name ##### -->
+<para>
+
+</para>
+
+@name: 
+@Returns: 
+
+
 <!-- ##### FUNCTION atk_attribute_get_value ##### -->
 <para>
 
index 6ea90ac..9c2216b 100644 (file)
@@ -110,7 +110,7 @@ test_role (void)
   role1 = atk_role_for_name ("list-item");
   if (role1 != ATK_ROLE_LIST_ITEM)
     {
-      g_print ("Unexpected role for list_item\n");
+      g_print ("Unexpected role for list-item\n");
       return FALSE;
     }
 
@@ -135,7 +135,7 @@ test_role (void)
       return FALSE;
     }
   /*
-   * Check that a non-existent type returns NULL
+   * Check that a non-existent role returns NULL
    */
   name = atk_role_get_name (ATK_ROLE_LAST_DEFINED + 2);
   if (name)
@@ -146,6 +146,67 @@ test_role (void)
   return TRUE;
 }
 
+static gboolean
+test_text_attr (void)
+{
+  AtkTextAttribute attr1, attr2;
+  G_CONST_RETURN gchar *name;
+
+  name = atk_attribute_get_name (ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP);
+  g_return_val_if_fail (name, FALSE);
+  if (strcmp (name, "pixels-inside-wrap") != 0)
+    {
+      g_print ("Unexpected name for ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP %s\n", name);
+      return FALSE;
+    }
+
+  name = atk_attribute_get_name (ATK_TEXT_ATTR_BG_STIPPLE);
+  g_return_val_if_fail (name, FALSE);
+  if (strcmp (name, "bg-stipple") != 0)
+    {
+      g_print ("Unexpected name for ATK_TEXT_ATTR_BG_STIPPLE %s\n", name);
+      return FALSE;
+    }
+
+  attr1 = atk_attribute_for_name ("left-margin");
+  if (attr1 != ATK_TEXT_ATTR_LEFT_MARGIN)
+    {
+      g_print ("Unexpected attribute for left-margin\n");
+      return FALSE;
+    }
+
+  attr1 = atk_attribute_register ("test-attribute");
+  name = atk_attribute_get_name (attr1);
+  g_return_val_if_fail (name, FALSE);
+  if (strcmp (name, "test-attribute") != 0)
+    {
+      g_print ("Unexpected name for test-attribute %s\n", name);
+      return FALSE;
+    }
+  attr2 = atk_attribute_for_name ("test-attribute");
+  if (attr1 != attr2)
+  {
+    g_print ("Unexpected attribute for test-attribute\n");
+    return FALSE;
+  }
+  attr2 = atk_attribute_for_name ("TEST_ATTR");
+  if (attr2 != 0)
+    {
+      g_print ("Unexpected attribute for TEST_ATTR\n");
+      return FALSE;
+    }
+  /*
+   * Check that a non-existent attribute returns NULL
+   */
+  name = atk_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2);
+  if (name)
+    {
+      g_print ("Unexpected name for undefined attribute %s\n", name);
+      return FALSE;
+    }
+  return TRUE;
+}
+
 int
 gtk_module_init (gint  argc, 
                  char* argv[])
@@ -164,5 +225,10 @@ gtk_module_init (gint  argc,
     g_print ("Role tests succeeded\n");
   else
     g_print ("Role tests failed\n");
+  b_ret = test_text_attr ();
+  if (b_ret)
+    g_print ("Text Attribute tests succeeded\n");
+  else
+    g_print ("Text Attribute tests failed\n");
   return 0;
 }