aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/gui_utils.c
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2009-03-06 17:16:56 +0000
committerAnders Broman <anders.broman@ericsson.com>2009-03-06 17:16:56 +0000
commit4175480de6b81700a624d6bfc1d4d7a1478dc3d8 (patch)
treefeb4ee47e7d0ac342b73a73dc106b73e45e4b6a5 /gtk/gui_utils.c
parent6485cd2d62c9d1d58923bf9f7d1396af118bab37 (diff)
Get rid of a Clist and move the functon to display floats with two decimals to gui_utils.
svn path=/trunk/; revision=27621
Diffstat (limited to 'gtk/gui_utils.c')
-rw-r--r--gtk/gui_utils.c35
1 files changed, 35 insertions, 0 deletions
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 <string.h>
+#include <locale.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
@@ -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);
+ }