X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=libspi%2Faccessible.c;h=1d0eb0ea70c5fe3b485d4bef5bc4c0257d23ed60;hb=d2e4455a1f174f2900ea63b59e9488416e47e32a;hp=ad5a89fd5dc7e91345b0a97d80c0ece542c757e2;hpb=7ff7c0d0b863f7346f21e03b6d170e8c7c6f9878;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/libspi/accessible.c b/libspi/accessible.c index ad5a89f..1d0eb0e 100644 --- a/libspi/accessible.c +++ b/libspi/accessible.c @@ -20,59 +20,114 @@ * Boston, MA 02111-1307, USA. */ -/* - * accessible.c: test for accessibility implementation - * - */ -#include -#include +/* accessible.c: the core of the accessibility implementation */ +#include #include +#include +#include +#include -/* - * This pulls the CORBA definitions for the "Accessibility::Accessible" server - */ -#include - -/* - * This pulls the definition for the BonoboObject (Gtk Type) - */ -#include "accessible.h" -#include "component.h" -#include "editabletext.h" -#include "hyperlink.h" -#include "hypertext.h" -#include "image.h" -#include "selection.h" -#include "table.h" -#include "text.h" -#include "value.h" - -/* - * Our parent Gtk object type - */ -#define PARENT_TYPE BONOBO_OBJECT_TYPE +/* Our parent Gtk object type */ +#define PARENT_TYPE SPI_TYPE_BASE -/* - * A pointer to our parent object class - */ -static GObjectClass *accessible_parent_class; +static Accessibility_Role +spi_role_from_atk_role (AtkRole role) +{ + Accessibility_Role spi_role; + + /* TODO: finish and/or make efficient! */ + switch (role) + { + case ATK_ROLE_INVALID: + spi_role = Accessibility_ROLE_INVALID; + break; + case ATK_ROLE_ACCEL_LABEL: + case ATK_ROLE_ALERT: + case ATK_ROLE_ANIMATION: + case ATK_ROLE_ARROW: + case ATK_ROLE_CALENDAR: + case ATK_ROLE_CANVAS: + case ATK_ROLE_CHECK_BOX: + case ATK_ROLE_CHECK_MENU_ITEM: + case ATK_ROLE_COLOR_CHOOSER: + case ATK_ROLE_COLUMN_HEADER: + case ATK_ROLE_COMBO_BOX: + case ATK_ROLE_DATE_EDITOR: + case ATK_ROLE_DESKTOP_ICON: + case ATK_ROLE_DESKTOP_FRAME: + case ATK_ROLE_DIAL: + case ATK_ROLE_DIALOG: + case ATK_ROLE_DIRECTORY_PANE: + case ATK_ROLE_DRAWING_AREA: + case ATK_ROLE_FILE_CHOOSER: + case ATK_ROLE_FILLER: + case ATK_ROLE_FONT_CHOOSER: + case ATK_ROLE_FRAME: + case ATK_ROLE_GLASS_PANE: + case ATK_ROLE_HTML_CONTAINER: + case ATK_ROLE_ICON: + case ATK_ROLE_IMAGE: + case ATK_ROLE_INTERNAL_FRAME: + case ATK_ROLE_LABEL: + case ATK_ROLE_LAYERED_PANE: + case ATK_ROLE_LIST: + case ATK_ROLE_LIST_ITEM: + case ATK_ROLE_MENU: + case ATK_ROLE_MENU_BAR: + case ATK_ROLE_MENU_ITEM: + case ATK_ROLE_OPTION_PANE: + case ATK_ROLE_PAGE_TAB: + case ATK_ROLE_PAGE_TAB_LIST: + case ATK_ROLE_PANEL: + case ATK_ROLE_PASSWORD_TEXT: + case ATK_ROLE_POPUP_MENU: + case ATK_ROLE_PROGRESS_BAR: + case ATK_ROLE_PUSH_BUTTON: + case ATK_ROLE_RADIO_BUTTON: + case ATK_ROLE_RADIO_MENU_ITEM: + case ATK_ROLE_ROOT_PANE: + case ATK_ROLE_ROW_HEADER: + case ATK_ROLE_SCROLL_BAR: + case ATK_ROLE_SCROLL_PANE: + case ATK_ROLE_SEPARATOR: + case ATK_ROLE_SLIDER: + case ATK_ROLE_SPLIT_PANE: + case ATK_ROLE_SPIN_BUTTON: + case ATK_ROLE_STATUSBAR: + case ATK_ROLE_TABLE: + case ATK_ROLE_TABLE_CELL: + case ATK_ROLE_TABLE_COLUMN_HEADER: + case ATK_ROLE_TABLE_ROW_HEADER: + case ATK_ROLE_TEAR_OFF_MENU_ITEM: + case ATK_ROLE_TERMINAL: + case ATK_ROLE_TEXT: + case ATK_ROLE_TOGGLE_BUTTON: + case ATK_ROLE_TOOL_BAR: + case ATK_ROLE_TOOL_TIP: + case ATK_ROLE_TREE: + case ATK_ROLE_TREE_TABLE: + case ATK_ROLE_UNKNOWN: + case ATK_ROLE_VIEWPORT: + case ATK_ROLE_WINDOW: + case ATK_ROLE_LAST_DEFINED: + default: + spi_role = Accessibility_ROLE_EXTENDED; + } + return spi_role; +} -/* - * Implemented GObject::finalize - */ -static void -accessible_object_finalize (GObject *object) +static AtkObject * +get_accessible_from_servant (PortableServer_Servant servant) { - Accessible *accessible = ACCESSIBLE (object); + SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant)); - printf("accessible_object_finalize called\n"); - ATK_OBJECT (accessible->atko); /* assertion */ - g_object_unref (G_OBJECT(accessible->atko)); - accessible->atko = NULL; + if (!object) + { + return NULL; + } - printf("atko freed, calling parent finalize\n"); - accessible_parent_class->finalize (object); + return object->atko; } /* @@ -82,13 +137,22 @@ static CORBA_char * impl_accessibility_accessible_get_name (PortableServer_Servant servant, CORBA_Environment *ev) { - CORBA_char * retval; - Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant)); - retval = (CORBA_char *) atk_object_get_name (accessible->atko); - if (retval ) - retval = CORBA_string_dup (retval); + const gchar *name; + CORBA_char *retval; + AtkObject *object = get_accessible_from_servant (servant); + + g_return_val_if_fail (object != NULL, CORBA_string_dup ("")); + + name = atk_object_get_name (object); + + if (name) + { + retval = CORBA_string_dup (name); + } else - retval = CORBA_string_dup (""); + { + retval = CORBA_string_dup (""); + } return retval; } @@ -101,9 +165,11 @@ impl_accessibility_accessible_set_name (PortableServer_Servant servant, const CORBA_char *name, CORBA_Environment *ev) { - Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant)); - atk_object_set_name (accessible->atko, name); - printf ("Accessible set_name called: %s\n", name); + AtkObject *object = get_accessible_from_servant (servant); + + g_return_if_fail (object != NULL); + + atk_object_set_name (object, name); } /* @@ -113,9 +179,22 @@ static CORBA_char * impl_accessibility_accessible_get_description (PortableServer_Servant servant, CORBA_Environment *ev) { - CORBA_char * retval; - Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant)); - retval = CORBA_string_dup (atk_object_get_description (accessible->atko)); + const gchar *descr; + CORBA_char *retval; + AtkObject *object = get_accessible_from_servant (servant); + + g_return_val_if_fail (object != NULL, CORBA_string_dup ("")); + + descr = atk_object_get_description (object); + + if (descr) + { + retval = CORBA_string_dup (descr); + } + else + { + retval = CORBA_string_dup (""); + } return retval; } @@ -125,12 +204,14 @@ impl_accessibility_accessible_get_description (PortableServer_Servant servant, */ static void impl_accessibility_accessible_set_description (PortableServer_Servant servant, - const CORBA_char *name, + const CORBA_char *descr, CORBA_Environment *ev) { - Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant)); - atk_object_set_description (accessible->atko, name); - printf ("Accessible set_description called: %s\n", name); + AtkObject *object = get_accessible_from_servant (servant); + + g_return_if_fail (object != NULL); + + atk_object_set_description (object, descr); } /* @@ -140,13 +221,14 @@ static Accessibility_Accessible impl_accessibility_accessible_get_parent (PortableServer_Servant servant, CORBA_Environment *ev) { - Accessibility_Accessible retval; - Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant)); AtkObject *parent; - parent = atk_object_get_parent (accessible->atko); - retval = BONOBO_OBJREF (accessible_new (parent)); - printf ("Accessible get_parent called\n"); - return CORBA_Object_duplicate (retval, &ev); + AtkObject *object = get_accessible_from_servant (servant); + + g_return_val_if_fail (object != NULL, CORBA_OBJECT_NIL); + + parent = atk_object_get_parent (object); + + return spi_accessible_new_return (parent, FALSE, ev); } /* @@ -156,11 +238,11 @@ static CORBA_long impl_accessibility_accessible_get_index_in_parent (PortableServer_Servant servant, CORBA_Environment *ev) { - CORBA_long retval; - Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant)); - retval = (CORBA_long) atk_object_get_index_in_parent (accessible->atko); - printf ("Accessible get_index_in_parent called\n"); - return retval; + AtkObject *object = get_accessible_from_servant (servant); + + g_return_val_if_fail (object != NULL, -1); + + return atk_object_get_index_in_parent (object); } /* @@ -170,11 +252,11 @@ static CORBA_long impl_accessibility_accessible_get_child_count (PortableServer_Servant servant, CORBA_Environment *ev) { - CORBA_long retval; - Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant)); - retval = (CORBA_long) atk_object_get_n_accessible_children (accessible->atko); - printf ("Accessible get_childCount called: %d\n", (int) retval); - return retval; + AtkObject *object = get_accessible_from_servant (servant); + + g_return_val_if_fail (object != NULL, 0); + + return atk_object_get_n_accessible_children (object); } /* @@ -185,12 +267,14 @@ impl_accessibility_accessible_get_child_at_index (PortableServer_Servant servant const CORBA_long index, CORBA_Environment *ev) { - Accessibility_Accessible retval; - Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant)); - AtkObject *child = atk_object_ref_accessible_child (accessible->atko, (gint) index); - retval = BONOBO_OBJREF (accessible_new (child)); - printf ("Accessible get_child_at_index called.\n"); - return CORBA_Object_duplicate (retval, &ev); + AtkObject *child; + AtkObject *object = get_accessible_from_servant (servant); + + g_return_val_if_fail (object != NULL, 0); + + child = atk_object_ref_accessible_child (object, index); + + return spi_accessible_new_return (child, TRUE, ev); } /* @@ -200,13 +284,14 @@ static Accessibility_StateSet impl_accessibility_accessible_get_state (PortableServer_Servant servant, CORBA_Environment *ev) { - Accessibility_StateSet retval; - Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant)); - AtkStateSet *state = atk_object_ref_state_set (accessible->atko); - retval = CORBA_OBJECT_NIL; - printf ("Accessible get_state.\n"); + AtkObject *object = get_accessible_from_servant (servant); + + bonobo_return_val_if_fail (object != NULL, NULL, ev); + + printf ("SpiAccessible get_state.\n"); + /* TODO: implement the bonobo stateset class */ - return (Accessibility_StateSet) retval; + return (Accessibility_StateSet) NULL; } /* @@ -217,14 +302,29 @@ impl_accessibility_accessible_get_relation_set (PortableServer_Servant servant, CORBA_Environment *ev) { Accessibility_RelationSet *retval; - Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant)); - AtkRelationSet *relation_set = atk_object_ref_relation_set (accessible->atko); + gint n_relations; + gint i; + AtkRelationSet *relation_set; + AtkObject *object = get_accessible_from_servant (servant); + + bonobo_return_val_if_fail (object != NULL, NULL, ev); + + relation_set = atk_object_ref_relation_set (object); + + n_relations = atk_relation_set_get_n_relations (relation_set); retval = CORBA_sequence_Accessibility_Relation__alloc (); - /* - * TODO: fill the sequence with relation set objects, themselves - * initialized from the AtkRelation object in the AtkRelationSet. - */ - printf ("Accessible get_relation_set.\n"); + CORBA_sequence_Accessibility_Relation_allocbuf (n_relations); + + for (i = 0; i < n_relations; ++i) + { + retval->_buffer[i] = + bonobo_object_dup_ref ( + BONOBO_OBJREF ( + spi_relation_new (atk_relation_set_get_relation (relation_set, i))), + ev); + } + + printf ("SpiAccessible get_relation_set.\n"); return retval; } @@ -235,22 +335,40 @@ static Accessibility_Role impl_accessibility_accessible_get_role (PortableServer_Servant servant, CORBA_Environment *ev) { + AtkRole role; + Accessibility_Role retval; + AtkObject *object = get_accessible_from_servant (servant); + + g_return_val_if_fail (object != NULL, 0); + + role = atk_object_get_role (object); + retval = spi_role_from_atk_role (role); + + return retval; +} + +/* + * CORBA Accessibility::Accessible::getRole method implementation + */ +static CORBA_char * +impl_accessibility_accessible_get_role_name (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + AtkRole role; Accessibility_Role retval; - Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant)); - AtkRole role = atk_object_get_role (accessible->atko); - retval = role; - printf ("Accessible get_role.\n"); - return (Accessibility_Role) retval; + AtkObject *object = get_accessible_from_servant (servant); + + g_return_val_if_fail (object != NULL, 0); + + role = atk_object_get_role (object); + + return CORBA_string_dup (atk_role_get_name (role)); } static void -accessible_class_init (AccessibleClass *klass) +spi_accessible_class_init (SpiAccessibleClass *klass) { - GObjectClass * object_class = (GObjectClass *) klass; POA_Accessibility_Accessible__epv *epv = &klass->epv; - accessible_parent_class = g_type_class_peek_parent (klass); - - object_class->finalize = accessible_object_finalize; epv->_get_name = impl_accessibility_accessible_get_name; epv->_set_name = impl_accessibility_accessible_set_name; @@ -265,118 +383,150 @@ accessible_class_init (AccessibleClass *klass) epv->getRelationSet = impl_accessibility_accessible_get_relation_set; epv->getState = impl_accessibility_accessible_get_state; epv->getRole = impl_accessibility_accessible_get_role; + epv->getRoleName = impl_accessibility_accessible_get_role_name; } static void -accessible_init (Accessible *accessible) +spi_accessible_init (SpiAccessible *accessible) { } -GType -accessible_get_type (void) +BONOBO_TYPE_FUNC_FULL (SpiAccessible, + Accessibility_Accessible, + PARENT_TYPE, + spi_accessible); + +static GHashTable *public_corba_refs = NULL; + +static GHashTable * +get_public_refs (void) +{ + if (!public_corba_refs) + { + public_corba_refs = g_hash_table_new (NULL, NULL); + } + return public_corba_refs; +} + +static void +de_register_public_ref (SpiBase *object) { - static GType type = 0; - - if (!type) { - static const GTypeInfo tinfo = { - sizeof (AccessibleClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) accessible_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class data */ - sizeof (Accessible), - 0, /* n preallocs */ - (GInstanceInitFunc) accessible_init, - NULL /* value table */ - }; - /* - * Bonobo_type_unique auto-generates a load of - * CORBA structures for us. All derived types must - * use bonobo_type_unique. - */ - type = bonobo_type_unique ( - PARENT_TYPE, - POA_Accessibility_Accessible__init, - NULL, - G_STRUCT_OFFSET (AccessibleClass, epv), - &tinfo, - "Accessible"); - } - - return type; + g_hash_table_remove (get_public_refs (), object->atko); } -Accessible * -accessible_new (AtkObject *o) +SpiAccessible * +spi_accessible_new (AtkObject *o) { - Accessible *retval = - ACCESSIBLE (g_object_new (accessible_get_type (), NULL)); + SpiAccessible *retval; CORBA_Environment ev; + CORBA_exception_init (&ev); - g_object_ref (o); - retval->atko = ATK_OBJECT (o); - /* - * TODO: add interface containers/constructors for EDITABLE_TEXT, HYPERTEXT, - * IMAGE, SELECTION, TABLE, TEXT, VALUE. - */ + g_assert (o); + + if ((retval = g_hash_table_lookup (get_public_refs (), o))) + { + bonobo_object_ref (BONOBO_OBJECT (retval)); + return retval; + } + + retval = g_object_new (SPI_ACCESSIBLE_TYPE, NULL); - /* add appropriate ATK interfaces */ + spi_base_construct (SPI_BASE (retval), o); + + g_hash_table_insert (get_public_refs (), o, retval); + g_signal_connect (G_OBJECT (retval), "destroy", + G_CALLBACK (de_register_public_ref), + NULL); + + /* aggregate appropriate SPI interfaces based on ATK interfaces */ if (ATK_IS_ACTION (o)) { bonobo_object_add_interface (bonobo_object (retval), - BONOBO_OBJECT (action_interface_new (o))); + BONOBO_OBJECT (spi_action_interface_new (o))); } - + if (ATK_IS_COMPONENT (o)) { bonobo_object_add_interface (bonobo_object (retval), - BONOBO_OBJECT (component_interface_new (o))); + BONOBO_OBJECT (spi_component_interface_new (o))); } if (ATK_IS_EDITABLE_TEXT (o)) { bonobo_object_add_interface (bonobo_object (retval), - BONOBO_OBJECT(editable_text_interface_new (o))); + BONOBO_OBJECT(spi_editable_text_interface_new (o))); } else if (ATK_IS_HYPERTEXT (o)) { bonobo_object_add_interface (bonobo_object (retval), - BONOBO_OBJECT (hypertext_interface_new (o))); + BONOBO_OBJECT (spi_hypertext_interface_new (o))); } else if (ATK_IS_TEXT (o)) { bonobo_object_add_interface (bonobo_object (retval), - BONOBO_OBJECT (text_interface_new (o))); + BONOBO_OBJECT (spi_text_interface_new (o))); } if (ATK_IS_IMAGE (o)) { bonobo_object_add_interface (bonobo_object (retval), - BONOBO_OBJECT (image_interface_new (o))); + BONOBO_OBJECT (spi_image_interface_new (o))); } if (ATK_IS_SELECTION (o)) { bonobo_object_add_interface (bonobo_object (retval), - BONOBO_OBJECT (selection_interface_new (o))); + BONOBO_OBJECT (spi_selection_interface_new (o))); } if (ATK_IS_TABLE (o)) { bonobo_object_add_interface (bonobo_object (retval), - BONOBO_OBJECT (table_interface_new (o))); + BONOBO_OBJECT (spi_table_interface_new (o))); } if (ATK_IS_VALUE (o)) { bonobo_object_add_interface (bonobo_object (retval), - BONOBO_OBJECT (value_interface_new (o))); + BONOBO_OBJECT (spi_value_interface_new (o))); } return retval; } + +/** + * spi_accessible_new_return: + * @o: an AtkObject or NULL + * @release_ref: whether to unref this AtkObject before return + * @ev: a CORBA environment + * + * A helper function to instantiate a CORBA accessiblility + * proxy from an AtkObject. + * + * Return value: the proxy or CORBA_OBJECT_NIL + **/ +Accessibility_Accessible +spi_accessible_new_return (AtkObject *o, + gboolean release_ref, + CORBA_Environment *ev) +{ + SpiAccessible *accessible; + + if (!o) + { + return CORBA_OBJECT_NIL; + } + + accessible = spi_accessible_new (o); + + if (release_ref) + { + g_object_unref (G_OBJECT (o)); + } + + return CORBA_Object_duplicate (BONOBO_OBJREF (accessible), ev); +}