evolution-3.6.4/widgets/table/gal-a11y-e-cell-registry.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  *		Christopher James Lahey <clahey@ximian.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 "gal-a11y-e-cell.h"
 28 #include "gal-a11y-e-cell-registry.h"
 29 
 30 static GObjectClass *parent_class;
 31 static GalA11yECellRegistry *default_registry;
 32 #define PARENT_TYPE (G_TYPE_OBJECT)
 33 
 34 struct _GalA11yECellRegistryPrivate {
 35 	GHashTable *table;
 36 };
 37 
 38 /* Static functions */
 39 
 40 static void
 41 gal_a11y_e_cell_registry_finalize (GObject *obj)
 42 {
 43 	GalA11yECellRegistry *registry = GAL_A11Y_E_CELL_REGISTRY (obj);
 44 
 45 	g_hash_table_destroy (registry->priv->table);
 46 	g_free (registry->priv);
 47 
 48 	G_OBJECT_CLASS (parent_class)->finalize (obj);
 49 }
 50 
 51 static void
 52 gal_a11y_e_cell_registry_class_init (GalA11yECellRegistryClass *class)
 53 {
 54 	GObjectClass *object_class = G_OBJECT_CLASS (class);
 55 
 56 	parent_class = g_type_class_ref (PARENT_TYPE);
 57 
 58 	object_class->finalize = gal_a11y_e_cell_registry_finalize;
 59 }
 60 
 61 static void
 62 gal_a11y_e_cell_registry_init (GalA11yECellRegistry *registry)
 63 {
 64 	registry->priv = g_new (GalA11yECellRegistryPrivate, 1);
 65 	registry->priv->table = g_hash_table_new (NULL, NULL);
 66 }
 67 
 68 /**
 69  * gal_a11y_e_cell_registry_get_type:
 70  * @void:
 71  *
 72  * Registers the &GalA11yECellRegistry class if necessary, and returns the type ID
 73  * associated to it.
 74  *
 75  * Return value: The type ID of the &GalA11yECellRegistry class.
 76  **/
 77 GType
 78 gal_a11y_e_cell_registry_get_type (void)
 79 {
 80 	static GType type = 0;
 81 
 82 	if (!type) {
 83 		GTypeInfo info = {
 84 			sizeof (GalA11yECellRegistryClass),
 85 			(GBaseInitFunc) NULL,
 86 			(GBaseFinalizeFunc) NULL,
 87 			(GClassInitFunc) gal_a11y_e_cell_registry_class_init,
 88 			(GClassFinalizeFunc) NULL,
 89 			NULL, /* class_data */
 90 			sizeof (GalA11yECellRegistry),
 91 			0,
 92 			(GInstanceInitFunc) gal_a11y_e_cell_registry_init,
 93 			NULL /* value_cell */
 94 		};
 95 
 96 		type = g_type_register_static (
 97 			PARENT_TYPE, "GalA11yECellRegistry", &info, 0);
 98 	}
 99 
100 	return type;
101 }
102 
103 static void
104 init_default_registry (void)
105 {
106 	if (default_registry == NULL) {
107 		default_registry = g_object_new (gal_a11y_e_cell_registry_get_type (), NULL);
108 	}
109 }
110 
111 AtkObject *
112 gal_a11y_e_cell_registry_get_object (GalA11yECellRegistry *registry,
113                                      ETableItem *item,
114                                      ECellView *cell_view,
115                                      AtkObject *parent,
116                                      gint model_col,
117                                      gint view_col,
118                                      gint row)
119 {
120 	GalA11yECellRegistryFunc func = NULL;
121 	GType type;
122 
123 	if (registry == NULL) {
124 		init_default_registry ();
125 		registry = default_registry;
126 	}
127 
128 	type = G_OBJECT_TYPE (cell_view->ecell);
129 	while (func == NULL && type != 0) {
130 		func = g_hash_table_lookup (registry->priv->table, GINT_TO_POINTER (type));
131 		type = g_type_parent (type);
132 	}
133 
134 	if (func == NULL)
135 		func = gal_a11y_e_cell_new;
136 
137 	return func (item, cell_view, parent, model_col, view_col, row);
138 }
139 
140 void
141 gal_a11y_e_cell_registry_add_cell_type (GalA11yECellRegistry *registry,
142                                         GType type,
143                                         GalA11yECellRegistryFunc func)
144 {
145 	if (registry == NULL) {
146 		init_default_registry ();
147 		registry = default_registry;
148 	}
149 
150 	g_hash_table_insert (registry->priv->table, GINT_TO_POINTER (type), func);
151 }