From 4175480de6b81700a624d6bfc1d4d7a1478dc3d8 Mon Sep 17 00:00:00 2001 From: Anders Broman Date: Fri, 6 Mar 2009 17:16:56 +0000 Subject: Get rid of a Clist and move the functon to display floats with two decimals to gui_utils. svn path=/trunk/; revision=27621 --- gtk/gui_utils.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'gtk/gui_utils.c') diff --git a/gtk/gui_utils.c b/gtk/gui_utils.c index 5453b4cdab..417ed41165 100644 --- a/gtk/gui_utils.c +++ b/gtk/gui_utils.c @@ -29,6 +29,7 @@ #endif #include +#include #include #include @@ -1136,4 +1137,38 @@ tree_view_key_pressed_cb(GtkWidget *tree, GdkEventKey *event, gpointer user_data return FALSE; } +/* + * This function can be called from gtk_tree_view_column_set_cell_data_func() + * the user data must be the colum number. + * Present floats with two decimals + */ +void +float_data_func (GtkTreeViewColumn *column _U_, + GtkCellRenderer *renderer, + GtkTreeModel *model, + GtkTreeIter *iter, + gpointer user_data) + { + gfloat float_val; + gchar buf[20]; + char *savelocale; + + /* the col to get data from is in userdata */ + gint float_col = GPOINTER_TO_INT(user_data); + + gtk_tree_model_get(model, iter, float_col, &float_val, -1); + + /* save the current locale */ + savelocale = setlocale(LC_NUMERIC, NULL); + /* switch to "C" locale to avoid problems with localized decimal separators + * in g_snprintf("%f") functions + */ + setlocale(LC_NUMERIC, "C"); + + g_snprintf(buf, sizeof(buf), "%.2f", float_val); + /* restore previous locale setting */ + setlocale(LC_NUMERIC, savelocale); + + g_object_set(renderer, "text", buf, NULL); + } -- cgit v1.2.3