Add new files atkstateset.c and atkstateset.h
authorPadraig O'Briain <padraigo@src.gnome.org>
Thu, 3 May 2001 14:40:34 +0000 (14:40 +0000)
committerPadraig O'Briain <padraigo@src.gnome.org>
Thu, 3 May 2001 14:40:34 +0000 (14:40 +0000)
Change atk_object_get_state to atk_object_ref_state_set

atk/Makefile.am
atk/atk.h
atk/atkobject.c
atk/atkobject.h
atk/atkstateset.c [new file with mode: 0755]
atk/atkstateset.h [new file with mode: 0755]

index ee37ed2..208751a 100644 (file)
@@ -18,6 +18,7 @@ libatk_la_SOURCES =           \
        atkrelation.c           \
        atkrelationset.c        \
        atkselection.c          \
+       atkstateset.c           \
        atktable.c              \
        atktext.c               \
        atkutil.c               \
@@ -47,6 +48,7 @@ libatkinclude_HEADERS =       \
         atkrelation.h          \
         atkrelationset.h       \
         atkselection.h         \
+        atkstateset.h          \
         atktable.h             \
         atktext.h              \
         atkutil.h              \
index a501c3e..382e681 100755 (executable)
--- a/atk/atk.h
+++ b/atk/atk.h
@@ -29,6 +29,7 @@
 #include <atk/atkrelation.h>
 #include <atk/atkrelationset.h>
 #include <atk/atkselection.h>
+#include <atk/atkstateset.h>
 #include <atk/atktable.h>
 #include <atk/atktext.h>
 #include <atk/atkutil.h>
index 4d7f7bc..b71ea33 100755 (executable)
@@ -25,6 +25,8 @@
 
 #define NUM_POSSIBLE_STATES                     (sizeof(AtkStateMask)*8)
 
+#define ATK_STATE(state_enum)             ((AtkStateMask)(1 << ((guint64)(state_enum)%64)))
+
 /* New GObject properties registered by AtkObject */
 enum
 {
@@ -425,24 +427,25 @@ atk_state_type_register (const gchar *name)
 }
 
 /**
- * atk_object_get_state
+ * atk_object_ref_state_set
  * @accessible: a #AtkObject
- * return values: a #AtkState which is the state of the accessible
+ * return values: a reference to a #AtkStateSet which is the state set of the accessible
  *
- * Gets the state of the accessible
+ * returns a reference to the state set of the accessible; the caller should
+ * unreference it.
  **/
-AtkState
-atk_object_get_state (AtkObject *accessible) {
+AtkStateSet*
+atk_object_ref_state_set (AtkObject *accessible) {
   AtkObjectClass *klass;
 
-  g_return_val_if_fail (accessible != NULL, 0);
-  g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
+  g_return_val_if_fail (accessible != NULL, NULL);
+  g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
 
   klass = ATK_OBJECT_GET_CLASS (accessible);
-  if (klass->get_state)
-    return (klass->get_state) (accessible);
+  if (klass->ref_state_set)
+    return (klass->ref_state_set) (accessible);
   else
-    return 0;
+    return NULL;
 }
 
 /**
@@ -468,6 +471,13 @@ atk_object_get_index_in_parent (AtkObject *accessible)
     return -1;
 }
 
+/**
+ * atk_object_set_name
+ * @accessible: a #AtkObject
+ * @name : a character string to be set as the accessible name
+ *
+ * Sets the accessible name of the accessible
+ **/
 void
 atk_object_set_name (AtkObject    *accessible,
                      const gchar  *name)
@@ -486,6 +496,13 @@ atk_object_set_name (AtkObject    *accessible,
   }
 }
 
+/**
+ * atk_object_set_name
+ * @accessible: a #AtkObject
+ * @description : a character string to be set as the accessible description
+ *
+ * Sets the accessible description of the accessible
+ **/
 void
 atk_object_set_description (AtkObject   *accessible,
                             const gchar *description)
@@ -504,6 +521,13 @@ atk_object_set_description (AtkObject   *accessible,
   }
 }
 
+/**
+ * atk_object_set_name
+ * @accessible: a #AtkObject
+ * @parent : a #AtkObject to be set as the accessible parent
+ *
+ * Sets the accessible parent of the accessible
+ **/
 void
 atk_object_set_parent (AtkObject *accessible,
                        AtkObject *parent)
@@ -518,6 +542,13 @@ atk_object_set_parent (AtkObject *accessible,
     (klass->set_parent) (accessible, parent);
 }
 
+/**
+ * atk_object_set_name
+ * @accessible: a #AtkObject
+ * @role : a #AtkRole to be set as the role
+ *
+ * Sets the role of the accessible
+ **/
 void
 atk_object_set_role (AtkObject *accessible, 
                      AtkRole   role)
@@ -656,9 +687,9 @@ atk_object_real_set_property (GObject      *object,
 
 static void
 atk_object_real_get_property (GObject      *object,
-                         guint         prop_id,
-                         GValue       *value,
-                         GParamSpec   *pspec)
+                              guint         prop_id,
+                              GValue       *value,
+                              GParamSpec   *pspec)
 {
   AtkObject *accessible;
 
@@ -672,9 +703,6 @@ atk_object_real_get_property (GObject      *object,
     case PROP_DESCRIPTION:
       g_value_set_string (value, atk_object_get_description (accessible));
       break;
-    case PROP_STATE:
-      g_value_set_int (value, atk_object_get_state (accessible));
-      break;
     default:
       break;
   }
index d802bf9..b0c6e5f 100755 (executable)
@@ -237,10 +237,12 @@ typedef enum
   /* Indicates this object is collapsed */
   ATK_STATE_COLLAPSED,
   /* Indicates the user can change the contents of this object */
+  ATK_STATE_DEFUNCT,
+  /* Indicates this object may have been removed by the application */
   ATK_STATE_EDITABLE,
   /* Indicates this object allows progressive disclosure of its children */
   ATK_STATE_EXPANDABLE,
-  /* Indicates this object its expanded */
+  /* Indicates this object is expandable */
   ATK_STATE_EXPANDED,
   /*
    * Indicates this object can accept keyboard focus, which means all
@@ -325,11 +327,11 @@ typedef struct _AtkImplementorIface       AtkImplementorIface;
 typedef struct _AtkObject                 AtkObject;
 typedef struct _AtkObjectClass            AtkObjectClass;
 typedef struct _AtkRelationSet            AtkRelationSet;
+typedef struct _AtkStateSet               AtkStateSet;
 
-typedef guint64                           AtkStateMask;
 typedef guint64                           AtkState;
+typedef guint64                           AtkStateMask;
 
-#define ATK_STATE(state_enum)             ((AtkStateMask)(1 << ((guint64)(state_enum)%64)))
 
 struct _AtkPropertyValues
 {
@@ -410,7 +412,7 @@ struct _AtkObjectClass
   /*
    * Gets the state set of the object
    */
-  AtkState                (* get_state)           (AtkObject                 *accessible);
+  AtkStateSet*            (* ref_state_set)       (AtkObject                 *accessible);
   /*
    * Sets the accessible name of the object
    */
@@ -489,7 +491,7 @@ AtkObject*              atk_object_ref_accessible_child           (AtkObject *ac
                                                                    gint        i);
 AtkRelationSet*         atk_object_ref_relation_set               (AtkObject *accessible);
 AtkRole                 atk_object_get_role                       (AtkObject *accessible);
-AtkState                atk_object_get_state                      (AtkObject *accessible);
+AtkStateSet*            atk_object_ref_state_set                  (AtkObject *accessible);
 gint                    atk_object_get_index_in_parent            (AtkObject *accessible);
 void                    atk_object_set_name                       (AtkObject *accessible,
                                                                    const gchar *name);
diff --git a/atk/atkstateset.c b/atk/atkstateset.c
new file mode 100755 (executable)
index 0000000..5f5e683
--- /dev/null
@@ -0,0 +1,353 @@
+/* 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 <glib-object.h>
+
+#include "atkobject.h"
+#include "atkstateset.h"
+
+#define ATK_STATE(state_enum)             ((AtkStateMask)(1 << ((guint64)(state_enum)%64)))
+
+struct _AtkRealStateSet
+{
+  GObject parent;
+
+  AtkState state;
+};
+
+typedef struct _AtkRealStateSet      AtkRealStateSet;
+
+static void            atk_state_set_class_init       (AtkStateSetClass  *klass);
+
+GType
+atk_state_set_get_type (void)
+{
+  static GType type = 0;
+
+  if (!type)
+    {
+      static const GTypeInfo typeInfo =
+      {
+        sizeof (AtkStateSetClass),
+        (GBaseInitFunc) NULL,
+        (GBaseFinalizeFunc) NULL,
+        (GClassInitFunc) atk_state_set_class_init,
+        (GClassFinalizeFunc) NULL,
+        NULL,
+        sizeof (AtkRealStateSet),
+        0,
+        (GInstanceInitFunc) NULL,
+      } ;
+      type = g_type_register_static (G_TYPE_OBJECT, "AtkStateSet", &typeInfo, 0) ;
+    }
+  return type;
+}
+
+static void
+atk_state_set_class_init (AtkStateSetClass *klass)
+{
+}
+
+/**
+ * atk_state_set_new
+ * return values: a new #AtkStateSet 
+ * 
+ * Creates a new empty state set.
+ **/
+AtkStateSet*
+atk_state_set_new (void)
+{
+  return (AtkStateSet*) g_object_new (ATK_TYPE_STATE_SET, NULL);
+}
+
+/**
+ * atk_state_set_is_empty
+ * @type: a #AtkStateType
+ * return values: %TRUE if @set has no states set
+ *
+ * Checks whether the state set is empty, i.e. has no states set.
+ **/
+gboolean
+atk_state_set_is_empty (AtkStateSet   *set)
+{
+  AtkRealStateSet *real_set;
+  g_return_val_if_fail (set != NULL, FALSE);
+  g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
+
+  real_set = (AtkRealStateSet *)set;
+
+  if (real_set->state)
+    return TRUE;
+  else
+    return FALSE;
+}
+
+/**
+ * atk_state_set_add_state
+ * @set: a #AtkStateSet
+ * @type: a #AtkStateType
+ * return values: %TRUE if  the state for @type is not already in @set.
+ *
+ * Add a new state for the specified type to the current state set if
+ * it is not already present
+ **/
+gboolean
+atk_state_set_add_state (AtkStateSet   *set,
+                         AtkStateType  type)
+{
+  AtkRealStateSet *real_set;
+  g_return_val_if_fail (set != NULL, FALSE);
+  g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
+
+  real_set = (AtkRealStateSet *)set;
+
+  if (real_set->state & ATK_STATE (type))
+    return FALSE;
+  else
+  {
+    real_set->state |= ATK_STATE (type);
+    return TRUE;
+  }
+}
+/**
+ * atk_state_set_add_states
+ * @set: a #AtkStateSet
+ * @types: a array of #AtkStateType
+ * @n_types: The number of elements in the array
+ *
+ * Add the states for the specified types to the current state set
+ **/
+void
+atk_state_set_add_states (AtkStateSet   *set,
+                          AtkStateType  *types,
+                          gint          n_types)
+{
+  AtkRealStateSet *real_set;
+  gint     i;
+  g_return_if_fail (set != NULL);
+  g_return_if_fail (ATK_IS_STATE_SET (set));
+
+  real_set = (AtkRealStateSet *)set;
+
+  for (i = 0; i < n_types; i++)
+  {
+    real_set->state |= ATK_STATE (types[i]);
+  }
+}
+
+/**
+ * atk_state_set_clear_states
+ * @set: a #AtkStateSet
+ *
+ * Removes all states from the state set.
+ **/
+void
+atk_state_set_clear_states (AtkStateSet   *set)
+{
+  AtkRealStateSet *real_set;
+  g_return_if_fail (set != NULL);
+  g_return_if_fail (ATK_IS_STATE_SET (set));
+
+  real_set = (AtkRealStateSet *)set;
+
+  real_set->state = 0;
+}
+
+/**
+ * atk_state_set_contains_state
+ * @set: a #AtkStateSet
+ * @type: a #AtkStateType
+ * return values: %TRUE if @type is the state type is in @set.
+ *
+ * Checks whether the state for the specified type is in the specified set.
+ **/
+gboolean
+atk_state_set_contains_state (AtkStateSet   *set,
+                              AtkStateType  type)
+{
+  AtkRealStateSet *real_set;
+  g_return_val_if_fail (set != NULL, FALSE);
+  g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
+
+  real_set = (AtkRealStateSet *)set;
+
+  if (real_set->state & ATK_STATE (type))
+    return TRUE;
+  else
+    return FALSE;
+}
+
+/**
+ * atk_state_set_contains_states
+ * @set: a #AtkStateSet
+ * @types: a array of #AtkStateType
+ * @n_types: The number of elements in the array
+ * return values: %TRUE if all the states for @type are in @set.
+ *
+ * Checks whether the states for all the specified types are in the 
+ * specified set.
+ **/
+gboolean
+atk_state_set_contains_states (AtkStateSet   *set,
+                               AtkStateType  *types,
+                               gint          n_types)
+{
+  AtkRealStateSet *real_set;
+  gint i;
+  g_return_val_if_fail (set != NULL, FALSE);
+  g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
+
+  real_set = (AtkRealStateSet *)set;
+
+  for (i = 0; i < n_types; i++)
+  {
+    if (!(real_set->state & ATK_STATE (types[i])))
+      return FALSE;
+  }
+  return TRUE;
+}
+
+/**
+ * atk_state_set_remove_state
+ * @set: a #AtkStateSet
+ * @type: a #AtkType
+ * return values: %TRUE if @type was the state type is in @set.
+ *
+ * Removes the state for the specified type from the state set.
+ **/
+gboolean
+atk_state_set_remove_state (AtkStateSet  *set,
+                            AtkStateType type)
+{
+  AtkRealStateSet *real_set;
+  g_return_val_if_fail (set != NULL, FALSE);
+  g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
+
+  real_set = (AtkRealStateSet *)set;
+
+  if (real_set->state & ATK_STATE (type))
+  {
+    real_set->state ^= ATK_STATE (type);
+    return TRUE;
+  }
+  else
+    return FALSE;
+}
+
+/**
+ * atk_state_set_and_sets
+ * @set: a #AtkStateSet
+ * @compare_set: another #AtkStateSet
+ * return values: a new #AtkStateSet which is the intersection of the two sets.
+ *
+ * Constructs the intersection of the two sets, returning NULL if the
+ * intersection is empty.
+ **/
+AtkStateSet*
+atk_state_set_and_sets (AtkStateSet  *set,
+                        AtkStateSet  *compare_set)
+{
+  AtkRealStateSet *real_set, *real_compare_set;
+  AtkStateSet *return_set = NULL;
+  AtkState state;
+
+  g_return_val_if_fail (set != NULL, FALSE);
+  g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
+  g_return_val_if_fail (compare_set != NULL, FALSE);
+  g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), FALSE);
+
+  real_set = (AtkRealStateSet *)set;
+  real_compare_set = (AtkRealStateSet *)compare_set;
+
+  state = real_set->state & real_compare_set->state;
+  if (state)
+  {
+    return_set = atk_state_set_new();
+    ((AtkRealStateSet *) return_set)->state = state;
+  }
+  return return_set;
+}
+
+/**
+ * atk_state_set_or_sets
+ * @set: a #AtkStateSet
+ * @compare_set: another #AtkStateSet
+ * return values: a new #AtkStateSet which is the union of the two sets.
+ *
+ * Constructs the union of the two sets.
+ **/
+AtkStateSet*
+atk_state_set_or_sets (AtkStateSet  *set,
+                       AtkStateSet  *compare_set)
+{
+  AtkRealStateSet *real_set, *real_compare_set;
+  AtkStateSet *return_set = NULL;
+  AtkState state;
+
+  g_return_val_if_fail (set != NULL, FALSE);
+  g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
+  g_return_val_if_fail (compare_set != NULL, FALSE);
+  g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), FALSE);
+
+  real_set = (AtkRealStateSet *)set;
+  real_compare_set = (AtkRealStateSet *)compare_set;
+
+  state = real_set->state | real_compare_set->state;
+
+  return_set = atk_state_set_new();
+  ((AtkRealStateSet *) return_set)->state = state;
+
+  return return_set;
+}
+
+/**
+ * atk_state_set_xor_sets
+ * @set: a #AtkStateSet
+ * @compare_set: another #AtkStateSet
+ * return values: a new #AtkStateSet which contains the states which are in exactly one of ht two sets.
+ *
+ * Constructs the xor of the two sets, returing NULL is empty. The set returned by this operation contains the4 sattes in exactly one of the two sets.
+ **/
+AtkStateSet*
+atk_state_set_xor_sets (AtkStateSet  *set,
+                        AtkStateSet  *compare_set)
+{
+  AtkRealStateSet *real_set, *real_compare_set;
+  AtkStateSet *return_set = NULL;
+  AtkState state, state1, state2;
+
+  g_return_val_if_fail (set != NULL, FALSE);
+  g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
+  g_return_val_if_fail (compare_set != NULL, FALSE);
+  g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), FALSE);
+
+  real_set = (AtkRealStateSet *)set;
+  real_compare_set = (AtkRealStateSet *)compare_set;
+
+  state1 = real_set->state & (~real_compare_set->state);
+  state2 = (~real_set->state) & real_compare_set->state;
+  state = state1 | state2;
+
+  if (state)
+  {
+    return_set = atk_state_set_new();
+    ((AtkRealStateSet *) return_set)->state = state;
+  }
+  return return_set;
+}
diff --git a/atk/atkstateset.h b/atk/atkstateset.h
new file mode 100755 (executable)
index 0000000..9fc68e8
--- /dev/null
@@ -0,0 +1,80 @@
+/* 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 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 __ATK_STATE_SET_H__
+#define __ATK_STATE_SET_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <glib-object.h>
+#include <atk/atkobject.h>
+
+#define ATK_TYPE_STATE_SET                        (atk_state_set_get_type ())
+#define ATK_STATE_SET(obj)                        (G_TYPE_CHECK_INSTANCE_CAST ((obj), ATK_TYPE_STATE_SET, AtkStateSet))
+#define ATK_STATE_SET_CLASS(klass)                (G_TYPE_CHECK_CLASS_CAST ((klass), ATK_TYPE_STATE_SET, AtkStateSetClass))
+#define ATK_IS_STATE_SET(obj)                     (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ATK_TYPE_STATE_SET))
+#define ATK_IS_STATE_SET_CLASS(klass)             (G_TYPE_CHECK_CLASS_TYPE ((klass), ATK_TYPE_STATE_SET))
+#define ATK_STATE_SET_GET_CLASS(obj)              (G_TYPE_INSTANCE_GET_CLASS ((obj), ATK_TYPE_STATE_SET, AtkStateSetClass))
+
+typedef struct _AtkStateSetClass       AtkStateSetClass;
+
+
+struct _AtkStateSet
+{
+  GObject parent;
+
+};
+
+struct _AtkStateSetClass
+{
+  GObjectClass parent;
+};
+
+GType atk_state_set_get_type (void);
+
+AtkStateSet*    atk_state_set_new               (void);
+gboolean        atk_state_set_is_empty          (AtkStateSet  *set);
+gboolean        atk_state_set_add_state         (AtkStateSet  *set,
+                                                 AtkStateType type);
+void            atk_state_set_add_states        (AtkStateSet  *set,
+                                                 AtkStateType *types,
+                                                 gint         n_types);
+void            atk_state_set_clear_states      (AtkStateSet  *set);
+gboolean        atk_state_set_contains_state    (AtkStateSet  *set,
+                                                 AtkStateType type);
+gboolean        atk_state_set_contains_states   (AtkStateSet  *set,
+                                                 AtkStateType *types,
+                                                 gint         n_types);
+gboolean        atk_state_set_remove_state      (AtkStateSet  *set,
+                                                 AtkStateType type);
+AtkStateSet*    atk_state_set_and_sets          (AtkStateSet  *set,
+                                                 AtkStateSet  *compare_set);
+AtkStateSet*    atk_state_set_or_sets           (AtkStateSet  *set,
+                                                 AtkStateSet  *compare_set);
+AtkStateSet*    atk_state_set_xor_sets          (AtkStateSet  *set,
+                                                 AtkStateSet  *compare_set);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+
+#endif /* __ATK_STATE_SET_H__ */