evolution-3.6.4/widgets/table/e-table-col.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  *		Miguel de Icaza <miguel@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 <glib/gi18n.h>
 28 #include "e-util/e-util.h"
 29 
 30 #include "e-table-col.h"
 31 
 32 G_DEFINE_TYPE (ETableCol, e_table_col, G_TYPE_OBJECT)
 33 
 34 enum {
 35 	PROP_0,
 36 	PROP_COMPARE_COL
 37 };
 38 
 39 static void
 40 etc_load_icon (ETableCol *etc)
 41 {
 42 	/* FIXME This ignores theme changes. */
 43 
 44 	GtkIconTheme *icon_theme;
 45 	gint width, height;
 46 	GError *error = NULL;
 47 
 48 	icon_theme = gtk_icon_theme_get_default ();
 49 	gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
 50 
 51 	etc->pixbuf = gtk_icon_theme_load_icon (
 52 		icon_theme, etc->icon_name, height, 0, &error);
 53 
 54 	if (error != NULL) {
 55 		g_warning ("%s", error->message);
 56 		g_error_free (error);
 57 	}
 58 }
 59 
 60 static void
 61 etc_dispose (GObject *object)
 62 {
 63 	ETableCol *etc = E_TABLE_COL (object);
 64 
 65 	if (etc->ecell)
 66 		g_object_unref (etc->ecell);
 67 	etc->ecell = NULL;
 68 
 69 	if (etc->pixbuf)
 70 		g_object_unref (etc->pixbuf);
 71 	etc->pixbuf = NULL;
 72 
 73 	g_free (etc->text);
 74 	etc->text = NULL;
 75 
 76 	g_free (etc->icon_name);
 77 	etc->icon_name = NULL;
 78 
 79 	/* Chain up to parent's dispose() method. */
 80 	G_OBJECT_CLASS (e_table_col_parent_class)->dispose (object);
 81 }
 82 
 83 static void
 84 etc_set_property (GObject *object,
 85                   guint property_id,
 86                   const GValue *value,
 87                   GParamSpec *pspec)
 88 {
 89 	ETableCol *etc = E_TABLE_COL (object);
 90 
 91 	switch (property_id) {
 92 	case PROP_COMPARE_COL:
 93 		etc->compare_col = g_value_get_int (value);
 94 		break;
 95 	default:
 96 		break;
 97 	}
 98 }
 99 
100 static void
101 etc_get_property (GObject *object,
102                   guint property_id,
103                   GValue *value,
104                   GParamSpec *pspec)
105 {
106 	ETableCol *etc = E_TABLE_COL (object);
107 
108 	switch (property_id) {
109 	case PROP_COMPARE_COL:
110 		g_value_set_int (value, etc->compare_col);
111 		break;
112 	default:
113 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
114 		break;
115 	}
116 }
117 
118 static void
119 e_table_col_class_init (ETableColClass *class)
120 {
121 	GObjectClass *object_class = G_OBJECT_CLASS (class);
122 
123 	object_class->dispose = etc_dispose;
124 	object_class->set_property = etc_set_property;
125 	object_class->get_property = etc_get_property;
126 
127 	g_object_class_install_property (
128 		object_class,
129 		PROP_COMPARE_COL,
130 		g_param_spec_int (
131 			"compare_col",
132 			"Width",
133 			"Width",
134 			0, G_MAXINT, 0,
135 			G_PARAM_READWRITE));
136 }
137 
138 static void
139 e_table_col_init (ETableCol *etc)
140 {
141 	etc->width = 0;
142 	etc->sortable = 1;
143 	etc->groupable = 1;
144 	etc->justification = GTK_JUSTIFY_LEFT;
145 	etc->priority = 0;
146 }
147 
148 /**
149  * e_table_col_new:
150  * @col_idx: the column we represent in the model
151  * @text: a title for this column
152  * @icon_name: name of the icon to be used for the header, or %NULL
153  * @expansion: FIXME
154  * @min_width: minimum width in pixels for this column
155  * @ecell: the renderer to be used for this column
156  * @compare: comparision function for the elements stored in this column
157  * @resizable: whether the column can be resized interactively by the user
158  * @priority: FIXME
159  *
160  * The ETableCol represents a column to be used inside an ETable.  The
161  * ETableCol objects are inserted inside an ETableHeader (which is just a
162  * collection of ETableCols).  The ETableHeader is the definition of the
163  * order in which columns are shown to the user.
164  *
165  * The @text argument is the the text that will be shown as a header to the
166  * user. @col_idx reflects where the data for this ETableCol object will
167  * be fetch from an ETableModel.  So even if the user changes the order
168  * of the columns being viewed (the ETableCols in the ETableHeader), the
169  * column will always point to the same column inside the ETableModel.
170  *
171  * The @ecell argument is an ECell object that needs to know how to
172  * render the data in the ETableModel for this specific row.
173  *
174  * Data passed to @compare can be (if not %NULL) a cmp_cache, which
175  * can be accessed by e_table_sorting_utils_add_to_cmp_cache() and
176  * e_table_sorting_utils_lookup_cmp_cache().
177  *
178  * Returns: the newly created ETableCol object.
179  */
180 ETableCol *
181 e_table_col_new (gint col_idx,
182                  const gchar *text,
183                  const gchar *icon_name,
184                  gdouble expansion,
185                  gint min_width,
186                  ECell *ecell,
187                  GCompareDataFunc compare,
188                  gboolean resizable,
189                  gboolean disabled,
190                  gint priority)
191 {
192 	ETableCol *etc;
193 
194 	g_return_val_if_fail (expansion >= 0, NULL);
195 	g_return_val_if_fail (min_width >= 0, NULL);
196 	g_return_val_if_fail (ecell != NULL, NULL);
197 	g_return_val_if_fail (compare != NULL, NULL);
198 	g_return_val_if_fail (text != NULL, NULL);
199 
200 	etc = g_object_new (E_TYPE_TABLE_COL, NULL);
201 
202 	etc->col_idx = col_idx;
203 	etc->compare_col = col_idx;
204 	etc->text = g_strdup (text);
205 	etc->icon_name = g_strdup (icon_name);
206 	etc->pixbuf = NULL;
207 	etc->expansion = expansion;
208 	etc->min_width = min_width;
209 	etc->ecell = ecell;
210 	etc->compare = compare;
211 	etc->disabled = disabled;
212 	etc->priority = priority;
213 
214 	etc->selected = 0;
215 	etc->resizable = resizable;
216 
217 	g_object_ref (etc->ecell);
218 
219 	if (etc->icon_name != NULL)
220 		etc_load_icon (etc);
221 
222 	return etc;
223 }