evolution-3.6.4/widgets/table/gal-a11y-e-tree.c

No issues found

  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		Yuedong Du <yuedong.du@sun.com>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  *
 21  */
 22 
 23 #ifdef HAVE_CONFIG_H
 24 #include <config.h>
 25 #endif
 26 
 27 #include "a11y/gal-a11y-util.h"
 28 #include "table/e-table-item.h"
 29 #include "table/e-tree.h"
 30 
 31 #include "gal-a11y-e-table-item.h"
 32 #include "gal-a11y-e-tree.h"
 33 #include "gal-a11y-e-tree-factory.h"
 34 
 35 #define CS_CLASS(a11y) (G_TYPE_INSTANCE_GET_CLASS ((a11y), C_TYPE_STREAM, GalA11yETreeClass))
 36 static AtkObjectClass *parent_class;
 37 static GType parent_type;
 38 static gint priv_offset;
 39 #define GET_PRIVATE(object) ((GalA11yETreePrivate *) (((gchar *) object) + priv_offset))
 40 #define PARENT_TYPE (parent_type)
 41 
 42 struct _GalA11yETreePrivate {
 43 	AtkObject *child_item;
 44 };
 45 
 46 /* Static functions */
 47 
 48 static void
 49 init_child_item (GalA11yETree *a11y)
 50 {
 51 	GalA11yETreePrivate *priv = GET_PRIVATE (a11y);
 52 	ETree *tree;
 53 	ETableItem * eti;
 54 
 55 	tree = E_TREE (gtk_accessible_get_widget (GTK_ACCESSIBLE (a11y)));
 56 	g_return_if_fail (tree);
 57 
 58 	eti = e_tree_get_item (tree);
 59 	if (priv->child_item == NULL) {
 60 		priv->child_item = atk_gobject_accessible_for_object (G_OBJECT (eti));
 61 	}
 62 }
 63 
 64 static AtkObject *
 65 et_ref_accessible_at_point (AtkComponent *component,
 66                              gint x,
 67                              gint y,
 68                              AtkCoordType coord_type)
 69 {
 70 	GalA11yETree *a11y = GAL_A11Y_E_TREE (component);
 71 	init_child_item (a11y);
 72 	return GET_PRIVATE (a11y)->child_item;
 73 }
 74 
 75 static gint
 76 et_get_n_children (AtkObject *accessible)
 77 {
 78 	return 1;
 79 }
 80 
 81 static AtkObject *
 82 et_ref_child (AtkObject *accessible,
 83               gint i)
 84 {
 85 	GalA11yETree *a11y = GAL_A11Y_E_TREE (accessible);
 86 	if (i != 0)
 87 		return NULL;
 88 	init_child_item (a11y);
 89 	g_object_ref (GET_PRIVATE (a11y)->child_item);
 90 	return GET_PRIVATE (a11y)->child_item;
 91 }
 92 
 93 static AtkLayer
 94 et_get_layer (AtkComponent *component)
 95 {
 96 	return ATK_LAYER_WIDGET;
 97 }
 98 
 99 static void
100 et_class_init (GalA11yETreeClass *class)
101 {
102 	AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (class);
103 
104 	parent_class                              = g_type_class_ref (PARENT_TYPE);
105 
106 	atk_object_class->get_n_children          = et_get_n_children;
107 	atk_object_class->ref_child               = et_ref_child;
108 }
109 
110 static void
111 et_atk_component_iface_init (AtkComponentIface *iface)
112 {
113 	iface->ref_accessible_at_point = et_ref_accessible_at_point;
114 	iface->get_layer = et_get_layer;
115 }
116 
117 static void
118 et_init (GalA11yETree *a11y)
119 {
120 	GalA11yETreePrivate *priv;
121 
122 	priv = GET_PRIVATE (a11y);
123 
124 	priv->child_item = NULL;
125 }
126 
127 /**
128  * gal_a11y_e_tree_get_type:
129  * @void:
130  *
131  * Registers the &GalA11yETree class if necessary, and returns the type ID
132  * associated to it.
133  *
134  * Return value: The type ID of the &GalA11yETree class.
135  **/
136 GType
137 gal_a11y_e_tree_get_type (void)
138 {
139 	static GType type = 0;
140 
141 	if (!type) {
142 		AtkObjectFactory *factory;
143 
144 		GTypeInfo info = {
145 			sizeof (GalA11yETreeClass),
146 			(GBaseInitFunc) NULL,
147 			(GBaseFinalizeFunc) NULL,
148 			(GClassInitFunc) et_class_init,
149 			(GClassFinalizeFunc) NULL,
150 			NULL, /* class_data */
151 			sizeof (GalA11yETree),
152 			0,
153 			(GInstanceInitFunc) et_init,
154 			NULL /* value_tree */
155 		};
156 
157 		static const GInterfaceInfo atk_component_info = {
158 			(GInterfaceInitFunc) et_atk_component_iface_init,
159 			(GInterfaceFinalizeFunc) NULL,
160 			NULL
161 		};
162 
163 		factory = atk_registry_get_factory (atk_get_default_registry (), GTK_TYPE_WIDGET);
164 		parent_type = atk_object_factory_get_accessible_type (factory);
165 
166 		type = gal_a11y_type_register_static_with_private (
167 			PARENT_TYPE, "GalA11yETree", &info, 0,
168 			sizeof (GalA11yETreePrivate), &priv_offset);
169 		g_type_add_interface_static (type, ATK_TYPE_COMPONENT, &atk_component_info);
170 	}
171 
172 	return type;
173 }
174 
175 AtkObject *
176 gal_a11y_e_tree_new (GObject *widget)
177 {
178 	GalA11yETree *a11y;
179 
180 	a11y = g_object_new (gal_a11y_e_tree_get_type (), NULL);
181 
182 	gtk_accessible_set_widget (GTK_ACCESSIBLE (a11y), GTK_WIDGET (widget));
183 
184 	return ATK_OBJECT (a11y);
185 }
186 
187 void
188 gal_a11y_e_tree_init (void)
189 {
190 	if (atk_get_root ())
191 		atk_registry_set_factory_type (
192 			atk_get_default_registry (),
193 			E_TYPE_TREE,
194 			gal_a11y_e_tree_factory_get_type ());
195 }