evolution-3.6.4/widgets/table/gal-a11y-e-table-column-header.c

No issues found

  1 /*
  2  *
  3  * This program is free software; you can redistribute it and/or
  4  * modify it under the terms of the GNU Lesser General Public
  5  * License as published by the Free Software Foundation; either
  6  * version 2 of the License, or (at your option) version 3.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11  * Lesser General Public License for more details.
 12  *
 13  * You should have received a copy of the GNU Lesser General Public
 14  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 15  *
 16  *
 17  * Authors:
 18  *		Li Yuan <li.yuan@sun.com>
 19  *
 20  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 21  *
 22  */
 23 
 24 #ifdef HAVE_CONFIG_H
 25 #include <config.h>
 26 #endif
 27 
 28 #include <glib/gi18n.h>
 29 #include <atk/atkobject.h>
 30 #include <atk/atkregistry.h>
 31 #include "table/e-table-header-item.h"
 32 #include "a11y/gal-a11y-util.h"
 33 #include "gal-a11y-e-table-column-header.h"
 34 
 35 static GObjectClass *parent_class;
 36 static gint priv_offset;
 37 
 38 #define GET_PRIVATE(object) \
 39 	((GalA11yETableColumnHeaderPrivate *) \
 40 	(((gchar *) object) + priv_offset))
 41 #define PARENT_TYPE (atk_gobject_accessible_get_type ())
 42 
 43 struct _GalA11yETableColumnHeaderPrivate {
 44 	ETableItem *item;
 45 	AtkObject  *parent;
 46 	AtkStateSet *state_set;
 47 };
 48 
 49 static void
 50 etch_init (GalA11yETableColumnHeader *a11y)
 51 {
 52 	GET_PRIVATE (a11y)->item = NULL;
 53 	GET_PRIVATE (a11y)->parent = NULL;
 54 	GET_PRIVATE (a11y)->state_set = NULL;
 55 }
 56 
 57 static AtkStateSet *
 58 gal_a11y_e_table_column_header_ref_state_set (AtkObject *accessible)
 59 {
 60 	GalA11yETableColumnHeaderPrivate *priv = GET_PRIVATE (accessible);
 61 
 62 	g_return_val_if_fail (priv->state_set, NULL);
 63 
 64 	g_object_ref (priv->state_set);
 65 
 66 	return priv->state_set;
 67 }
 68 
 69 static void
 70 gal_a11y_e_table_column_header_real_initialize (AtkObject *obj,
 71                                                 gpointer data)
 72 {
 73 	ATK_OBJECT_CLASS (parent_class)->initialize (obj, data);
 74 }
 75 
 76 static void
 77 gal_a11y_e_table_column_header_dispose (GObject *object)
 78 {
 79 	GalA11yETableColumnHeader *a11y = GAL_A11Y_E_TABLE_COLUMN_HEADER (object);
 80 	GalA11yETableColumnHeaderPrivate *priv = GET_PRIVATE (a11y);
 81 
 82 	if (priv->state_set) {
 83 		g_object_unref (priv->state_set);
 84 		priv->state_set = NULL;
 85 	}
 86 
 87 	if (parent_class->dispose)
 88 		parent_class->dispose (object);
 89 
 90 }
 91 
 92 static void
 93 etch_class_init (GalA11yETableColumnHeaderClass *class)
 94 {
 95 	AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (class);
 96 	GObjectClass *object_class = G_OBJECT_CLASS (class);
 97 
 98 	parent_class = g_type_class_ref (PARENT_TYPE);
 99 
100 	object_class->dispose = gal_a11y_e_table_column_header_dispose;
101 
102 	atk_object_class->ref_state_set = gal_a11y_e_table_column_header_ref_state_set;
103 	atk_object_class->initialize = gal_a11y_e_table_column_header_real_initialize;
104 }
105 
106 inline static GObject *
107 etch_a11y_get_gobject (AtkGObjectAccessible *accessible)
108 {
109 	return atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible));
110 }
111 
112 static gboolean
113 gal_a11y_e_table_column_header_do_action (AtkAction *action,
114                                           gint i)
115 {
116 	gboolean return_value = TRUE;
117 	GtkWidget *widget;
118 	GalA11yETableColumnHeader *a11y;
119 	ETableHeaderItem *ethi;
120 	ETableItem *item;
121 	ETableCol *col;
122 
123 	switch (i) {
124 		case 0:
125 			a11y = GAL_A11Y_E_TABLE_COLUMN_HEADER (action);
126 			col = E_TABLE_COL (etch_a11y_get_gobject (
127 				ATK_GOBJECT_ACCESSIBLE (a11y)));
128 			item = GET_PRIVATE (a11y)->item;
129 			widget = gtk_widget_get_parent (GTK_WIDGET (item->parent.canvas));
130 			if (E_IS_TREE (widget)) {
131 				ethi = E_TABLE_HEADER_ITEM (
132 					e_tree_get_header_item (E_TREE (widget)));
133 			}
134 			else if (E_IS_TABLE (widget))
135 				ethi = E_TABLE_HEADER_ITEM (
136 					E_TABLE (widget)->header_item);
137 			else
138 				break;
139 			ethi_change_sort_state (ethi, col);
140 		default:
141 			return_value = FALSE;
142 			break;
143 	}
144 	return return_value;
145 }
146 
147 static gint
148 gal_a11y_e_table_column_header_get_n_actions (AtkAction *action)
149 {
150 	return 1;
151 }
152 
153 static const gchar *
154 gal_a11y_e_table_column_header_action_get_name (AtkAction *action,
155                                                 gint i)
156 {
157 	const gchar *return_value;
158 
159 	switch (i) {
160 		case 0:
161 			return_value = _("sort");
162 			break;
163 		default:
164 			return_value = NULL;
165 			break;
166 	}
167 	return return_value;
168 }
169 
170 static void
171 atk_action_interface_init (AtkActionIface *iface)
172 {
173 	g_return_if_fail (iface != NULL);
174 
175 	iface->do_action = gal_a11y_e_table_column_header_do_action;
176 	iface->get_n_actions = gal_a11y_e_table_column_header_get_n_actions;
177 	iface->get_name = gal_a11y_e_table_column_header_action_get_name;
178 }
179 
180 GType
181 gal_a11y_e_table_column_header_get_type (void)
182 {
183 	static GType type = 0;
184 
185 	if (!type) {
186 		GTypeInfo info = {
187 			sizeof (GalA11yETableColumnHeaderClass),
188 			(GBaseInitFunc) NULL,
189 			(GBaseFinalizeFunc) NULL,
190 			(GClassInitFunc) etch_class_init,
191 			(GClassFinalizeFunc) NULL,
192 			NULL,
193 			sizeof (GalA11yETableColumnHeader),
194 			0,
195 			(GInstanceInitFunc) etch_init,
196 			NULL
197 		};
198 		static const GInterfaceInfo atk_action_info = {
199 			(GInterfaceInitFunc) atk_action_interface_init,
200 			(GInterfaceFinalizeFunc) NULL,
201 			NULL
202 		};
203 
204 		type = gal_a11y_type_register_static_with_private (
205 			PARENT_TYPE, "GalA11yETableColumnHeader", &info, 0,
206 			sizeof (GalA11yETableColumnHeaderPrivate), &priv_offset);
207 
208 		g_type_add_interface_static (
209 			type, ATK_TYPE_ACTION, &atk_action_info);
210 	}
211 
212 	return type;
213 }
214 
215 AtkObject *
216 gal_a11y_e_table_column_header_new (ETableCol *ecol,
217                                     ETableItem *item)
218 {
219 	GalA11yETableColumnHeader *a11y;
220 	AtkObject *accessible;
221 
222 	g_return_val_if_fail (E_IS_TABLE_COL (ecol), NULL);
223 
224 	a11y = g_object_new (gal_a11y_e_table_column_header_get_type (), NULL);
225 	accessible  = ATK_OBJECT (a11y);
226 	atk_object_initialize (accessible, ecol);
227 
228 	GET_PRIVATE (a11y)->item = item;
229 	GET_PRIVATE (a11y)->state_set = atk_state_set_new ();
230 
231 	atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_VISIBLE);
232 	atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_SHOWING);
233 	atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_SENSITIVE);
234 	atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_ENABLED);
235 
236 	if (ecol->text)
237 		atk_object_set_name (accessible, ecol->text);
238 	atk_object_set_role (accessible, ATK_ROLE_TABLE_COLUMN_HEADER);
239 
240 	return ATK_OBJECT (a11y);
241 }