1 /*
2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU Lesser General Public License as published by
4 * the Free Software Foundation.
5 *
6 * This program is distributed in the hope that it will be useful, but
7 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9 * for more details.
10 *
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, see <http://www.gnu.org/licenses/>.
13 *
14 *
15 * Authors:
16 * Miguel de Icaza <miguel@ximian.com>
17 *
18 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
19 *
20 */
21
22 #include "evolution-config.h"
23
24 #include <glib/gi18n.h>
25
26 #include "e-table-col.h"
27
G_DEFINE_TYPE(ETableCol,e_table_col,G_TYPE_OBJECT)28 G_DEFINE_TYPE (ETableCol, e_table_col, G_TYPE_OBJECT)
29
30 static void
31 etc_load_icon (ETableCol *etc)
32 {
33 /* FIXME This ignores theme changes. */
34
35 GtkIconTheme *icon_theme;
36 gint width, height;
37 GError *error = NULL;
38
39 icon_theme = gtk_icon_theme_get_default ();
40 gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
41
42 etc->pixbuf = gtk_icon_theme_load_icon (
43 icon_theme, etc->icon_name, height, GTK_ICON_LOOKUP_FORCE_SIZE, &error);
44
45 if (error != NULL) {
46 g_warning ("%s", error->message);
47 g_error_free (error);
48 }
49 }
50
51 static void
etc_dispose(GObject * object)52 etc_dispose (GObject *object)
53 {
54 ETableCol *etc = E_TABLE_COL (object);
55
56 g_clear_object (&etc->spec);
57 g_clear_object (&etc->ecell);
58 g_clear_object (&etc->pixbuf);
59
60 g_free (etc->text);
61 etc->text = NULL;
62
63 g_free (etc->icon_name);
64 etc->icon_name = NULL;
65
66 /* Chain up to parent's dispose() method. */
67 G_OBJECT_CLASS (e_table_col_parent_class)->dispose (object);
68 }
69
70 static void
e_table_col_class_init(ETableColClass * class)71 e_table_col_class_init (ETableColClass *class)
72 {
73 GObjectClass *object_class = G_OBJECT_CLASS (class);
74
75 object_class->dispose = etc_dispose;
76 }
77
78 static void
e_table_col_init(ETableCol * etc)79 e_table_col_init (ETableCol *etc)
80 {
81 etc->width = 0;
82 etc->justification = GTK_JUSTIFY_LEFT;
83 }
84
85 /**
86 * e_table_col_new:
87 * @spec: an #ETableColumnSpecification
88 * @text: a title for this column
89 * @icon_name: name of the icon to be used for the header, or %NULL
90 * @ecell: the renderer to be used for this column
91 * @compare: comparision function for the elements stored in this column
92 *
93 * The ETableCol represents a column to be used inside an ETable. The
94 * ETableCol objects are inserted inside an ETableHeader (which is just a
95 * collection of ETableCols). The ETableHeader is the definition of the
96 * order in which columns are shown to the user.
97 *
98 * The @text argument is the text that will be shown as a header to the
99 * user. @col_idx reflects where the data for this ETableCol object will
100 * be fetch from an ETableModel. So even if the user changes the order
101 * of the columns being viewed (the ETableCols in the ETableHeader), the
102 * column will always point to the same column inside the ETableModel.
103 *
104 * The @ecell argument is an ECell object that needs to know how to
105 * render the data in the ETableModel for this specific row.
106 *
107 * Data passed to @compare can be (if not %NULL) a cmp_cache, which
108 * can be accessed by e_table_sorting_utils_add_to_cmp_cache() and
109 * e_table_sorting_utils_lookup_cmp_cache().
110 *
111 * Returns: the newly created ETableCol object.
112 */
113 ETableCol *
e_table_col_new(ETableColumnSpecification * spec,const gchar * text,const gchar * icon_name,ECell * ecell,GCompareDataFunc compare)114 e_table_col_new (ETableColumnSpecification *spec,
115 const gchar *text,
116 const gchar *icon_name,
117 ECell *ecell,
118 GCompareDataFunc compare)
119 {
120 ETableCol *etc;
121
122 g_return_val_if_fail (E_IS_TABLE_COLUMN_SPECIFICATION (spec), NULL);
123 g_return_val_if_fail (ecell != NULL, NULL);
124 g_return_val_if_fail (compare != NULL, NULL);
125 g_return_val_if_fail (text != NULL, NULL);
126
127 etc = g_object_new (E_TYPE_TABLE_COL, NULL);
128
129 etc->spec = g_object_ref (spec);
130 etc->text = g_strdup (text);
131 etc->icon_name = g_strdup (icon_name);
132 etc->pixbuf = NULL;
133 etc->min_width = spec->minimum_width;
134 etc->expansion = spec->expansion;
135 etc->ecell = g_object_ref (ecell);
136 etc->compare = compare;
137
138 etc->selected = 0;
139
140 if (etc->icon_name != NULL)
141 etc_load_icon (etc);
142
143 return etc;
144 }
145