evolution-3.6.4/widgets/table/e-cell-number.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  *		Chris 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 <sys/time.h>
28 #include <unistd.h>
29 
30 #include <glib/gi18n.h>
31 #include "e-util/e-util.h"
32 
33 #include "e-cell-number.h"
34 
35 G_DEFINE_TYPE (ECellNumber, e_cell_number, E_TYPE_CELL_TEXT)
36 
37 static gchar *
38 ecn_get_text (ECellText *cell,
39               ETableModel *model,
40               gint col,
41               gint row)
42 {
43 	gpointer value;
44 
45 	value = e_table_model_value_at (model, col, row);
46 
47 	return e_format_number (GPOINTER_TO_INT (value));
48 }
49 
50 static void
51 ecn_free_text (ECellText *cell,
52                gchar *text)
53 {
54 	g_free (text);
55 }
56 
57 static void
58 e_cell_number_class_init (ECellNumberClass *class)
59 {
60 	ECellTextClass *ectc = E_CELL_TEXT_CLASS (class);
61 
62 	ectc->get_text  = ecn_get_text;
63 	ectc->free_text = ecn_free_text;
64 }
65 
66 static void
67 e_cell_number_init (ECellNumber *cell_number)
68 {
69 }
70 
71 /**
72  * e_cell_number_new:
73  * @fontname: font to be used to render on the screen
74  * @justify: Justification of the string in the cell.
75  *
76  * Creates a new ECell renderer that can be used to render numbers that
77  * that come from the model.  The value returned from the model is
78  * interpreted as being an int.
79  *
80  * See ECellText for other features.
81  *
82  * Returns: an ECell object that can be used to render numbers.
83  */
84 ECell *
85 e_cell_number_new (const gchar *fontname,
86                    GtkJustification justify)
87 {
88 	ECellNumber *ecn = g_object_new (E_TYPE_CELL_NUMBER, NULL);
89 
90 	e_cell_text_construct (E_CELL_TEXT (ecn), fontname, justify);
91 
92 	return (ECell *) ecn;
93 }