X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fa11y%2Fgtkcellaccessible.c;h=b5846e8c21210db6ccf45c4ddfce9d3a56819ca3;hb=56bcb1933f6de613e5d8689e23420d47b65425c3;hp=d24dd435bb8564f380d7939727327af2b8a8edca;hpb=7f42a9465a6d8935250911f113c9d79889c14638;p=~andy%2Fgtk diff --git a/gtk/a11y/gtkcellaccessible.c b/gtk/a11y/gtkcellaccessible.c index d24dd435b..b5846e8c2 100644 --- a/gtk/a11y/gtkcellaccessible.c +++ b/gtk/a11y/gtkcellaccessible.c @@ -1,4 +1,4 @@ -/* GAIL - The GNOME Accessibility Implementation Library +/* GTK+ - accessibility implementations * Copyright 2001 Sun Microsystems Inc. * * This library is free software; you can redistribute it and/or @@ -12,26 +12,17 @@ * 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. + * License along with this library. If not, see . */ #include "config.h" +#include #include #include "gtkcontainercellaccessible.h" -#include "gtkcellaccessible.h" +#include "gtkcellaccessibleprivate.h" #include "gtkcellaccessibleparent.h" -typedef struct _ActionInfo ActionInfo; -struct _ActionInfo { - gchar *name; - gchar *description; - gchar *keybinding; - void (*do_action_func) (GtkCellAccessible *cell); -}; - static const struct { AtkState atk_state; GtkCellRendererState renderer_state; @@ -47,37 +38,23 @@ static const struct { { ATK_STATE_EXPANDED, GTK_CELL_RENDERER_EXPANDED, FALSE }, }; +static GtkCellRendererState gtk_cell_accessible_get_state (GtkCellAccessible *cell); static void atk_action_interface_init (AtkActionIface *iface); static void atk_component_interface_init (AtkComponentIface *iface); -G_DEFINE_TYPE_WITH_CODE (GtkCellAccessible, _gtk_cell_accessible, ATK_TYPE_OBJECT, +G_DEFINE_TYPE_WITH_CODE (GtkCellAccessible, gtk_cell_accessible, GTK_TYPE_ACCESSIBLE, G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init) G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)) -static void -destroy_action_info (gpointer action_info) -{ - ActionInfo *info = (ActionInfo *)action_info; - - g_free (info->name); - g_free (info->description); - g_free (info->keybinding); - g_free (info); -} - static void gtk_cell_accessible_object_finalize (GObject *obj) { - GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (obj); AtkRelationSet *relation_set; AtkRelation *relation; GPtrArray *target; gpointer target_object; gint i; - if (cell->action_list) - g_list_free_full (cell->action_list, destroy_action_info); - relation_set = atk_object_ref_relation_set (ATK_OBJECT (obj)); if (ATK_IS_RELATION_SET (relation_set)) { @@ -95,7 +72,7 @@ gtk_cell_accessible_object_finalize (GObject *obj) } g_object_unref (relation_set); } - G_OBJECT_CLASS (_gtk_cell_accessible_parent_class)->finalize (obj); + G_OBJECT_CLASS (gtk_cell_accessible_parent_class)->finalize (obj); } static gint @@ -108,13 +85,13 @@ gtk_cell_accessible_get_index_in_parent (AtkObject *obj) parent = atk_object_get_parent (obj); if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent)) - return g_list_index (GTK_CONTAINER_CELL_ACCESSIBLE (parent)->children, obj); + return g_list_index (gtk_container_cell_accessible_get_children (GTK_CONTAINER_CELL_ACCESSIBLE (parent)), obj); - parent = gtk_widget_get_accessible (cell->widget); + parent = gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell))); if (parent == NULL) return -1; - return _gtk_cell_accessible_parent_get_child_index (GTK_CELL_ACCESSIBLE_PARENT (parent), cell); + return gtk_cell_accessible_parent_get_child_index (GTK_CELL_ACCESSIBLE_PARENT (parent), cell); } static AtkStateSet * @@ -129,16 +106,17 @@ gtk_cell_accessible_ref_state_set (AtkObject *accessible) state_set = atk_state_set_new (); - if (cell_accessible->widget == NULL) + if (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell_accessible)) == NULL) { atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT); return state_set; } - flags = _gtk_cell_accessible_get_state (cell_accessible); + flags = gtk_cell_accessible_get_state (cell_accessible); - atk_state_set_add_state (state_set, ATK_STATE_TRANSIENT); + atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE); atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE); + atk_state_set_add_state (state_set, ATK_STATE_TRANSIENT); atk_state_set_add_state (state_set, ATK_STATE_VISIBLE); for (i = 0; i < G_N_ELEMENTS (state_map); i++) @@ -155,7 +133,7 @@ gtk_cell_accessible_ref_state_set (AtkObject *accessible) } } - if (gtk_widget_get_mapped (cell_accessible->widget)) + if (gtk_widget_get_mapped (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell_accessible)))) atk_state_set_add_state (state_set, ATK_STATE_SHOWING); return state_set; @@ -163,7 +141,7 @@ gtk_cell_accessible_ref_state_set (AtkObject *accessible) static void -_gtk_cell_accessible_class_init (GtkCellAccessibleClass *klass) +gtk_cell_accessible_class_init (GtkCellAccessibleClass *klass) { AtkObjectClass *class = ATK_OBJECT_CLASS (klass); GObjectClass *g_object_class = G_OBJECT_CLASS (klass); @@ -175,29 +153,17 @@ _gtk_cell_accessible_class_init (GtkCellAccessibleClass *klass) } static void -_gtk_cell_accessible_init (GtkCellAccessible *cell) -{ - cell->widget = NULL; - cell->action_list = NULL; -} - -static void -widget_destroyed (GtkWidget *widget, - GtkCellAccessible *cell) +gtk_cell_accessible_init (GtkCellAccessible *cell) { - cell->widget = NULL; } void -_gtk_cell_accessible_initialise (GtkCellAccessible *cell, +_gtk_cell_accessible_initialize (GtkCellAccessible *cell, GtkWidget *widget, AtkObject *parent) { - cell->widget = widget; + gtk_accessible_set_widget (GTK_ACCESSIBLE (cell), widget); atk_object_set_parent (ATK_OBJECT (cell), parent); - - g_signal_connect_object (G_OBJECT (widget), "destroy", - G_CALLBACK (widget_destroyed), cell, 0); } gboolean @@ -259,129 +225,68 @@ _gtk_cell_accessible_remove_state (GtkCellAccessible *cell, return TRUE; } -gboolean -_gtk_cell_accessible_add_action (GtkCellAccessible *cell, - const gchar *name, - const gchar *description, - const gchar *keybinding, - void (*func) (GtkCellAccessible *)) -{ - ActionInfo *info; - - info = g_new (ActionInfo, 1); - info->name = g_strdup (name); - info->description = g_strdup (description); - info->keybinding = g_strdup (keybinding); - info->do_action_func = func; - - cell->action_list = g_list_append (cell->action_list, info); - - return TRUE; -} - -gboolean -_gtk_cell_accessible_remove_action (GtkCellAccessible *cell, - gint index) -{ - GList *l; - - l = g_list_nth (cell->action_list, index); - if (l == NULL) - return FALSE; - - destroy_action_info (l->data); - cell->action_list = g_list_remove_link (cell->action_list, l); - - return TRUE; -} - - -gboolean -_gtk_cell_accessible_remove_action_by_name (GtkCellAccessible *cell, - const gchar *name) -{ - GList *l; - - for (l = cell->action_list; l; l = l->next) - { - ActionInfo *info = l->data; - - if (g_strcmp0 (info->name, name) == 0) - break; - } - - if (l == NULL) - return FALSE; - - destroy_action_info (l->data); - cell->action_list = g_list_remove_link (cell->action_list, l); - - return TRUE; -} - -static ActionInfo * -get_action_info (GtkCellAccessible *cell, - gint index) -{ - GList *l; - - l = g_list_nth (cell->action_list, index); - if (l == NULL) - return NULL; - - return (ActionInfo *) (l->data); -} - static gint gtk_cell_accessible_action_get_n_actions (AtkAction *action) { - GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE(action); - if (cell->action_list != NULL) - return g_list_length (cell->action_list); - else - return 0; + return 3; } static const gchar * gtk_cell_accessible_action_get_name (AtkAction *action, gint index) { - GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action); - ActionInfo *info; - - info = get_action_info (cell, index); - if (info == NULL) - return NULL; + switch (index) + { + case 0: + return "expand or contract"; + case 1: + return "edit"; + case 2: + return "activate"; + default: + return NULL; + } +} - return info->name; +static const gchar * +gtk_cell_accessible_action_get_localized_name (AtkAction *action, + gint index) +{ + switch (index) + { + case 0: + return C_("Action name", "Expand or contract"); + case 1: + return C_("Action name", "Edit"); + case 2: + return C_("Action name", "Activate"); + default: + return NULL; + } } static const gchar * gtk_cell_accessible_action_get_description (AtkAction *action, gint index) { - GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action); - ActionInfo *info; - - info = get_action_info (cell, index); - if (info == NULL) - return NULL; - - return info->description; + switch (index) + { + case 0: + return C_("Action description", "Expands or contracts the row in the tree view containing this cell"); + case 1: + return C_("Action description", "Creates a widget in which the contents of the cell can be edited"); + case 2: + return C_("Action description", "Activates the cell"); + default: + return NULL; + } } static const gchar * gtk_cell_accessible_action_get_keybinding (AtkAction *action, gint index) { - GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action); - ActionInfo *info; - - info = get_action_info (cell, index); - if (info == NULL) - return NULL; - - return info->keybinding; + return NULL; } static gboolean @@ -389,16 +294,28 @@ gtk_cell_accessible_action_do_action (AtkAction *action, gint index) { GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action); - ActionInfo *info; + GtkCellAccessibleParent *parent; - info = get_action_info (cell, index); - if (info == NULL) + cell = GTK_CELL_ACCESSIBLE (action); + if (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)) == NULL) return FALSE; - if (info->do_action_func == NULL) - return FALSE; + parent = GTK_CELL_ACCESSIBLE_PARENT (gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)))); - info->do_action_func (cell); + switch (index) + { + case 0: + gtk_cell_accessible_parent_expand_collapse (parent, cell); + break; + case 1: + gtk_cell_accessible_parent_edit (parent, cell); + break; + case 2: + gtk_cell_accessible_parent_activate (parent, cell); + break; + default: + return FALSE; + } return TRUE; } @@ -409,6 +326,7 @@ atk_action_interface_init (AtkActionIface *iface) iface->get_n_actions = gtk_cell_accessible_action_get_n_actions; iface->do_action = gtk_cell_accessible_action_do_action; iface->get_name = gtk_cell_accessible_action_get_name; + iface->get_localized_name = gtk_cell_accessible_action_get_localized_name; iface->get_description = gtk_cell_accessible_action_get_description; iface->get_keybinding = gtk_cell_accessible_action_get_keybinding; } @@ -425,9 +343,9 @@ gtk_cell_accessible_get_extents (AtkComponent *component, AtkObject *parent; cell = GTK_CELL_ACCESSIBLE (component); - parent = gtk_widget_get_accessible (cell->widget); + parent = gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell))); - _gtk_cell_accessible_parent_get_cell_extents (GTK_CELL_ACCESSIBLE_PARENT (parent), + gtk_cell_accessible_parent_get_cell_extents (GTK_CELL_ACCESSIBLE_PARENT (parent), cell, x, y, width, height, coord_type); } @@ -439,9 +357,9 @@ gtk_cell_accessible_grab_focus (AtkComponent *component) AtkObject *parent; cell = GTK_CELL_ACCESSIBLE (component); - parent = gtk_widget_get_accessible (cell->widget); + parent = gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell))); - return _gtk_cell_accessible_parent_grab_focus (GTK_CELL_ACCESSIBLE_PARENT (parent), cell); + return gtk_cell_accessible_parent_grab_focus (GTK_CELL_ACCESSIBLE_PARENT (parent), cell); } static void @@ -451,53 +369,22 @@ atk_component_interface_init (AtkComponentIface *iface) iface->grab_focus = gtk_cell_accessible_grab_focus; } -/** - * _gtk_cell_accessible_set_cell_data: - * @cell: a #GtkCellAccessible - * - * Sets the cell data to the row used by @cell. This is useful in - * particular if you want to work with cell renderers. - * - * Note that this function is potentially slow, so be careful. - **/ -void -_gtk_cell_accessible_set_cell_data (GtkCellAccessible *cell) -{ - AtkObject *parent; - - g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (cell)); - - parent = gtk_widget_get_accessible (cell->widget); - if (parent == NULL) - return; - - _gtk_cell_accessible_parent_set_cell_data (GTK_CELL_ACCESSIBLE_PARENT (parent), cell); -} - -/** - * _gtk_cell_accessible_get_state: - * @cell: a #GtkCellAccessible - * - * Gets the state that would be used to render the area referenced by @cell. - * - * Returns: the #GtkCellRendererState for cell - **/ -GtkCellRendererState -_gtk_cell_accessible_get_state (GtkCellAccessible *cell) +static GtkCellRendererState +gtk_cell_accessible_get_state (GtkCellAccessible *cell) { AtkObject *parent; g_return_val_if_fail (GTK_IS_CELL_ACCESSIBLE (cell), 0); - parent = gtk_widget_get_accessible (cell->widget); + parent = gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell))); if (parent == NULL) return 0; - return _gtk_cell_accessible_parent_get_renderer_state (GTK_CELL_ACCESSIBLE_PARENT (parent), cell); + return gtk_cell_accessible_parent_get_renderer_state (GTK_CELL_ACCESSIBLE_PARENT (parent), cell); } -/** - * _gtk_cell_accessible_state_changed: +/* + * gtk_cell_accessible_state_changed: * @cell: a #GtkCellAccessible * @added: the flags that were added from @cell * @removed: the flags that were removed from @cell @@ -522,12 +409,39 @@ _gtk_cell_accessible_state_changed (GtkCellAccessible *cell, for (i = 0; i < G_N_ELEMENTS (state_map); i++) { if (added & state_map[i].renderer_state) - atk_object_notify_state_change (object, + atk_object_notify_state_change (object, state_map[i].atk_state, !state_map[i].invert); - if (added & state_map[i].renderer_state) - atk_object_notify_state_change (object, + if (removed & state_map[i].renderer_state) + atk_object_notify_state_change (object, state_map[i].atk_state, state_map[i].invert); } } + +/* + * gtk_cell_accessible_update_cache: + * @cell: the cell that is changed + * + * Notifies the cell that the values in the data in the row that + * is used to feed the cell renderer with has changed. The + * cell_changed function of @cell is called to send update + * notifications for the properties it takes from its cell + * renderer. + * + * Note that there is no higher granularity available about which + * properties changed, so you will need to make do with this + * function. + **/ +void +_gtk_cell_accessible_update_cache (GtkCellAccessible *cell) +{ + GtkCellAccessibleClass *klass; + + g_return_if_fail (GTK_CELL_ACCESSIBLE (cell)); + + klass = GTK_CELL_ACCESSIBLE_GET_CLASS (cell); + + if (klass->update_cache) + klass->update_cache (cell); +}