diff options
author | Padraig O'Briain <padraigo@src.gnome.org> | 2001-05-09 17:21:06 +0000 |
---|---|---|
committer | Padraig O'Briain <padraigo@src.gnome.org> | 2001-05-09 17:21:06 +0000 |
commit | 3c9d927bbeacec90436f53d5eecca478706ce24d (patch) | |
tree | 68a10b3130da138ebd6319fbfd3f523e6e15e605 | |
parent | 70f373359027afced7afda327825507745338dc2 (diff) | |
download | atk-3c9d927bbeacec90436f53d5eecca478706ce24d.tar.gz |
Add atk/atkstate.c and atk.atkstate.h
Move interfaces for ATK state from atkobject to atkstate
Add tests for atk_state_* functions in teststateset
-rw-r--r-- | atk/Makefile.am | 2 | ||||
-rwxr-xr-x | atk/atk.h | 1 | ||||
-rwxr-xr-x | atk/atkobject.c | 80 | ||||
-rwxr-xr-x | atk/atkobject.h | 90 | ||||
-rwxr-xr-x | atk/atkstate.c | 112 | ||||
-rwxr-xr-x | atk/atkstate.h | 124 | ||||
-rwxr-xr-x | atk/atkstateset.c | 2 | ||||
-rwxr-xr-x | atk/atkstateset.h | 1 | ||||
-rw-r--r-- | tests/teststateset.c | 83 |
9 files changed, 318 insertions, 177 deletions
diff --git a/atk/Makefile.am b/atk/Makefile.am index 208751a..125cfd9 100644 --- a/atk/Makefile.am +++ b/atk/Makefile.am @@ -18,6 +18,7 @@ libatk_la_SOURCES = \ atkrelation.c \ atkrelationset.c \ atkselection.c \ + atkstate.c \ atkstateset.c \ atktable.c \ atktext.c \ @@ -48,6 +49,7 @@ libatkinclude_HEADERS = \ atkrelation.h \ atkrelationset.h \ atkselection.h \ + atkstate.h \ atkstateset.h \ atktable.h \ atktext.h \ @@ -29,6 +29,7 @@ #include <atk/atkrelation.h> #include <atk/atkrelationset.h> #include <atk/atkselection.h> +#include <atk/atkstate.h> #include <atk/atkstateset.h> #include <atk/atktable.h> #include <atk/atktext.h> diff --git a/atk/atkobject.c b/atk/atkobject.c index b71ea33..271488d 100755 --- a/atk/atkobject.c +++ b/atk/atkobject.c @@ -23,10 +23,6 @@ #include "atk.h" -#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 { @@ -63,8 +59,6 @@ static void atk_object_real_get_property(GObject *object, GParamSpec *pspec); static void atk_object_finalize (GObject *object); -static gchar* state_names[NUM_POSSIBLE_STATES]; - #if 0 static guint atk_object_signals[LAST_SIGNAL] = { 0, }; #endif @@ -112,32 +106,6 @@ atk_object_class_init (AtkObjectClass *klass) klass->ref_relation_set = atk_object_real_ref_relation_set; - state_names[ATK_STATE_ARMED] = "armed"; - state_names[ATK_STATE_BUSY] = "busy"; - state_names[ATK_STATE_CHECKED] = "checked"; - state_names[ATK_STATE_COLLAPSED] = "collapsed"; - state_names[ATK_STATE_EDITABLE] = "editable"; - state_names[ATK_STATE_EXPANDABLE] = "expandable"; - state_names[ATK_STATE_EXPANDED] = "expanded"; - state_names[ATK_STATE_FOCUSABLE] = "focusable"; - state_names[ATK_STATE_FOCUSED] = "focused"; - state_names[ATK_STATE_HORIZONTAL] = "horizontal"; - state_names[ATK_STATE_ICONIFIED] = "iconified"; - state_names[ATK_STATE_MODAL] = "modal"; - state_names[ATK_STATE_MULTI_LINE] = "multi-line"; - state_names[ATK_STATE_MULTISELECTABLE] = "multiselectable"; - state_names[ATK_STATE_OPAQUE] = "opaque"; - state_names[ATK_STATE_PRESSED] = "pressed"; - state_names[ATK_STATE_RESIZABLE] = "resizeable"; - state_names[ATK_STATE_SELECTABLE] = "selectable"; - state_names[ATK_STATE_SELECTED] = "selected"; - state_names[ATK_STATE_SENSITIVE] = "sensitive"; - state_names[ATK_STATE_SHOWING] = "showing"; - state_names[ATK_STATE_SINGLE_LINE] = "single-line"; - state_names[ATK_STATE_TRANSIENT] = "transient"; - state_names[ATK_STATE_VERTICAL] = "vertical"; - state_names[ATK_STATE_VISIBLE] = "visible"; - klass->children_changed = NULL; g_object_class_install_property (gobject_class, @@ -409,24 +377,6 @@ atk_object_get_role (AtkObject *accessible) { } /** - * atk_state_register - * @name: a character string describing the new state. - * return values: a #AtkState value for the new state. - * - * Returns a #AtkState value for the new state. - **/ -AtkStateType -atk_state_type_register (const gchar *name) -{ - /* TODO: associate name with new type */ - static guint type = ATK_STATE_LAST_DEFINED; - if (type < NUM_POSSIBLE_STATES) { - return (++type); - } - return ATK_STATE_INVALID; /* caller needs to check */ -} - -/** * atk_object_ref_state_set * @accessible: a #AtkObject * return values: a reference to a #AtkStateSet which is the state set of the accessible @@ -594,36 +544,6 @@ atk_object_remove_property_change_handler (AtkObject *accessible, (klass->remove_property_change_handler) (accessible, handler_id); } -G_CONST_RETURN gchar* -atk_state_mask_get_name (AtkStateMask state) -{ - gint n; - - if (state == 0) - return NULL; - - for (n=0; n<NUM_POSSIBLE_STATES; ++n) - { - /* fall through and return null if multiple bits are set */ - if (state == (1 << n)) return state_names[n]; - } - - return NULL; -} - -AtkStateMask -atk_state_mask_for_name (const gchar *name) -{ - gint i; - - g_return_val_if_fail ((strlen(name)>0), 0); - for (i=0; i<NUM_POSSIBLE_STATES; ++i) - { - if (!strcmp(name, state_names[i])) return ATK_STATE(i); - } - return 0; -} - /** * atk_implementor_ref_accessible * @object: The GObject instance which should implement #AtkImplementorIface diff --git a/atk/atkobject.h b/atk/atkobject.h index b0c6e5f..744b03e 100755 --- a/atk/atkobject.h +++ b/atk/atkobject.h @@ -223,89 +223,6 @@ typedef enum AtkRole atk_role_register (const gchar *name); -typedef enum -{ - ATK_STATE_INVALID, - /* Indicates a window is currently the active window */ - ATK_STATE_ACTIVE, - /* Indicates that the object is armed */ - ATK_STATE_ARMED, - /* Indicates the current object is busy */ - ATK_STATE_BUSY, - /* Indicates this object is currently checked */ - ATK_STATE_CHECKED, - /* 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 is expandable */ - ATK_STATE_EXPANDED, - /* - * Indicates this object can accept keyboard focus, which means all - * events resulting from typing on the keyboard will normally be passed - * to it when it has focus - */ - ATK_STATE_FOCUSABLE, - /* Indicates this object currently has the keyboard focus */ - ATK_STATE_FOCUSED, - /* Indicates the orientation of thsi object is horizontal */ - ATK_STATE_HORIZONTAL, - /* Indicates this object is minimized and is represented only by an icon */ - ATK_STATE_ICONIFIED, - /* - * Indicates something must be done with this object before the user can - * interact with an object in a different window. - */ - ATK_STATE_MODAL, - /* Indicates this (text) object can contain multiple lines of text */ - ATK_STATE_MULTI_LINE, - /* - * Indicates this object allows more than one of its children to be - * selected at the same time - */ - ATK_STATE_MULTISELECTABLE, - /* Indicates this object paints every pixel within its rectangular region. */ - ATK_STATE_OPAQUE, - /* Indicates this object is currently pressed */ - ATK_STATE_PRESSED, - /* Indicates the size of this object is not fixed */ - ATK_STATE_RESIZABLE, - /* - * Indicates this object is the child of an object that allows its - * children to be selected and that this child is one of those children - * that can be selected. - */ - ATK_STATE_SELECTABLE, - /* - * Indicates this object is the child of an object that allows its - * children to be selected and that this child is one of those children - * that has been selected. - */ - ATK_STATE_SELECTED, - /* Indicates this object is sensitive */ - ATK_STATE_SENSITIVE, - /* - * Indicates this object, the object's parent, the object's parent's - * parent, and so on, are all visible - */ - ATK_STATE_SHOWING, - /* Indicates this (text) object can contain only a single line of text */ - ATK_STATE_SINGLE_LINE, - /* Indicates this object is transient */ - ATK_STATE_TRANSIENT, - /* Indicates the orientation of this object is vertical */ - ATK_STATE_VERTICAL, - /* Indicates this object is visible */ - ATK_STATE_VISIBLE, - ATK_STATE_LAST_DEFINED -} AtkStateType; - -AtkStateType atk_state_type_register (const gchar *name); - #define ATK_TYPE_OBJECT (atk_object_get_type ()) #define ATK_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ATK_TYPE_OBJECT, AtkObject)) @@ -329,10 +246,6 @@ typedef struct _AtkObjectClass AtkObjectClass; typedef struct _AtkRelationSet AtkRelationSet; typedef struct _AtkStateSet AtkStateSet; -typedef guint64 AtkState; -typedef guint64 AtkStateMask; - - struct _AtkPropertyValues { gchar *property_name; @@ -564,9 +477,6 @@ void atk_object_remove_property_change_handler (AtkObject * cpos = atk_text_get_caret_position (ATK_TEXT (accessible)); */ -G_CONST_RETURN gchar* atk_state_mask_get_name (AtkStateMask state); -AtkStateMask atk_state_mask_for_name (const gchar *name); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/atk/atkstate.c b/atk/atkstate.c new file mode 100755 index 0000000..31a1f2e --- /dev/null +++ b/atk/atkstate.c @@ -0,0 +1,112 @@ +/* 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 "atkstate.h" + +#define NUM_POSSIBLE_STATES (sizeof(AtkState)*8) + +static gchar* state_names[NUM_POSSIBLE_STATES] = { + "invalid", + "active", + "armed", + "busy", + "checked", + "collapsed", + "defunct", + "editable", + "expandable", + "expanded", + "focusable", + "focused", + "horizontal", + "iconified", + "modal", + "multi-line", + "multiselect,ble", + "opaque", + "pressed", + "resizeable", + "selectable", + "selected", + "sensitive", + "showing", + "single-line", + "transient", + "vertical", + "visible" +}; + +/** + * atk_state_type_register + * @name: a character string describing the new state. + * return values: a #AtkState value for the new state. + * + * Returns a #AtkState value for the new state. + **/ +AtkStateType +atk_state_type_register (const gchar *name) +{ + static guint type = ATK_STATE_LAST_DEFINED; + if (type < NUM_POSSIBLE_STATES) + { + state_names[++type] = g_strdup (name); + return (type); + } + return ATK_STATE_INVALID; /* caller needs to check */ +} + +/** + * atk_state_type_get_name + * @state: The #AtkStateType whose name is required + * Return the string describing the state + */ +G_CONST_RETURN gchar* +atk_state_type_get_name (AtkStateType state) +{ + gint n; + + if (state == 0) + return NULL; + + for (n=0; n<NUM_POSSIBLE_STATES; n++) + { + if (state == n) + return state_names[n]; + } + + return NULL; +} + +AtkStateType +atk_state_type_for_name (const gchar *name) +{ + gint i; + + g_return_val_if_fail (name != NULL, 0); + g_return_val_if_fail (strlen (name) > 0, 0); + + for (i = 0; i < NUM_POSSIBLE_STATES; i++) + { + if (state_names[i] == NULL) + continue; + if (!strcmp(name, state_names[i])) + return i; + } + return 0; +} diff --git a/atk/atkstate.h b/atk/atkstate.h new file mode 100755 index 0000000..bc5833e --- /dev/null +++ b/atk/atkstate.h @@ -0,0 +1,124 @@ +/* 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_H__ +#define __ATK_STATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include <glib-object.h> + +typedef enum +{ + ATK_STATE_INVALID, + /* Indicates a window is currently the active window */ + ATK_STATE_ACTIVE, + /* Indicates that the object is armed */ + ATK_STATE_ARMED, + /* Indicates the current object is busy */ + ATK_STATE_BUSY, + /* Indicates this object is currently checked */ + ATK_STATE_CHECKED, + /* Indicates this object is collapsed */ + ATK_STATE_COLLAPSED, + /* + * Indicates the user interface object corresponding to this object + * no longer exists. + */ + ATK_STATE_DEFUNCT, + /* Indicates the user can change the contents of this object */ + ATK_STATE_EDITABLE, + /* Indicates this object allows progressive disclosure of its children */ + ATK_STATE_EXPANDABLE, + /* Indicates this object its expanded */ + ATK_STATE_EXPANDED, + /* + * Indicates this object can accept keyboard focus, which means all + * events resulting from typing on the keyboard will normally be passed + * to it when it has focus + */ + ATK_STATE_FOCUSABLE, + /* Indicates this object currently has the keyboard focus */ + ATK_STATE_FOCUSED, + /* Indicates the orientation of thsi object is horizontal */ + ATK_STATE_HORIZONTAL, + /* Indicates this object is minimized and is represented only by an icon */ + ATK_STATE_ICONIFIED, + /* + * Indicates something must be done with this object before the user can + * interact with an object in a different window. + */ + ATK_STATE_MODAL, + /* Indicates this (text) object can contain multiple lines of text */ + ATK_STATE_MULTI_LINE, + /* + * Indicates this object allows more than one of its children to be + * selected at the same time + */ + ATK_STATE_MULTISELECTABLE, + /* Indicates this object paints every pixel within its rectangular region. */ + ATK_STATE_OPAQUE, + /* Indicates this object is currently pressed */ + ATK_STATE_PRESSED, + /* Indicates the size of this object is not fixed */ + ATK_STATE_RESIZABLE, + /* + * Indicates this object is the child of an object that allows its + * children to be selected and that this child is one of those children + * that can be selected. + */ + ATK_STATE_SELECTABLE, + /* + * Indicates this object is the child of an object that allows its + * children to be selected and that this child is one of those children + * that has been selected. + */ + ATK_STATE_SELECTED, + /* Indicates this object is sensitive */ + ATK_STATE_SENSITIVE, + /* + * Indicates this object, the object's parent, the object's parent's + * parent, and so on, are all visible + */ + ATK_STATE_SHOWING, + /* Indicates this (text) object can contain only a single line of text */ + ATK_STATE_SINGLE_LINE, + /* Indicates this object is transient */ + ATK_STATE_TRANSIENT, + /* Indicates the orientation of this object is vertical */ + ATK_STATE_VERTICAL, + /* Indicates this object is visible */ + ATK_STATE_VISIBLE, + ATK_STATE_LAST_DEFINED +} AtkStateType; + +typedef guint64 AtkState; + +AtkStateType atk_state_type_register (const gchar *name); + +G_CONST_RETURN gchar* atk_state_type_get_name (AtkStateType type); +AtkStateType atk_state_type_for_name (const gchar *name); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __ATK_STATE_H__ */ diff --git a/atk/atkstateset.c b/atk/atkstateset.c index 5f5e683..6c80021 100755 --- a/atk/atkstateset.c +++ b/atk/atkstateset.c @@ -22,7 +22,7 @@ #include "atkobject.h" #include "atkstateset.h" -#define ATK_STATE(state_enum) ((AtkStateMask)(1 << ((guint64)(state_enum)%64))) +#define ATK_STATE(state_enum) ((AtkState)(1 << ((guint64)(state_enum)%64))) struct _AtkRealStateSet { diff --git a/atk/atkstateset.h b/atk/atkstateset.h index 9fc68e8..43c3ea3 100755 --- a/atk/atkstateset.h +++ b/atk/atkstateset.h @@ -26,6 +26,7 @@ extern "C" { #include <glib-object.h> #include <atk/atkobject.h> +#include <atk/atkstate.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)) diff --git a/tests/teststateset.c b/tests/teststateset.c index 3c5a674..7132d29 100644 --- a/tests/teststateset.c +++ b/tests/teststateset.c @@ -19,16 +19,17 @@ #include <atk/atk.h> -static gboolean test_state_set(); +static gboolean test_state_set (); +static gboolean test_state (); static gboolean -test_state_set() +test_state_set () { AtkStateSet *state_set1, *state_set2, *state_set3; AtkStateType state_array[3]; gboolean b_val; - state_set1 = atk_state_set_new(); + state_set1 = atk_state_set_new (); b_val = atk_state_set_is_empty (state_set1); if (b_val) @@ -201,15 +202,76 @@ test_state_set() } +static gboolean +test_state () +{ + AtkStateType type1, type2; + G_CONST_RETURN gchar *name; + + name = atk_state_type_get_name (ATK_STATE_VISIBLE); + g_return_val_if_fail (name, FALSE); + if (strcmp (name, "visible") != 0) + { + g_print ("Unexpected name for ATK_STATE_VISIBLE %s\n", name); + return FALSE; + } + + name = atk_state_type_get_name (ATK_STATE_MODAL); + g_return_val_if_fail (name, FALSE); + if (strcmp (name, "modal") != 0) + { + g_print ("Unexpected name for ATK_STATE_MODAL %s\n", name); + return FALSE; + } + + type1 = atk_state_type_for_name ("focused"); + if (type1 != ATK_STATE_FOCUSED) + { + g_print ("Unexpected type for focused\n"); + return FALSE; + } + + type1 = atk_state_type_register ("test_state"); + name = atk_state_type_get_name (type1); + g_return_val_if_fail (name, FALSE); + if (strcmp (name, "test_state") != 0) + { + g_print ("Unexpected name for test_state %s\n", name); + return FALSE; + } + type2 = atk_state_type_for_name ("test_state"); + g_return_val_if_fail (name, FALSE); + if (type1 != type2) + { + g_print ("Unexpected type for test_state\n"); + return FALSE; + } + type2 = atk_state_type_for_name ("TEST-STATE"); + if (type2 != 0) + { + g_print ("Unexpected type for TEST-STATE\n"); + return FALSE; + } + /* + * Check that a non-existent type returns NULL + */ + name = atk_state_type_get_name (ATK_STATE_LAST_DEFINED +2); + if (name) + { + g_print ("Unexpected name for undefined type\n"); + return FALSE; + } + return TRUE; +} + int -gtk_module_init(gint argc, char* argv[]) +gtk_module_init (gint argc, char* argv[]) { gboolean b_ret; g_print("State Set test module loaded\n"); - b_ret = test_state_set(); - + b_ret = test_state_set (); if (b_ret) { g_print ("State Set tests succeeded\n"); @@ -218,5 +280,14 @@ gtk_module_init(gint argc, char* argv[]) { g_print ("State Set tests failed\n"); } + b_ret = test_state (); + if (b_ret) + { + g_print ("State tests succeeded\n"); + } + else + { + g_print ("State tests failed\n"); + } return 0; } |