Converted strings to utf8 before passing to gtksheet. Should work properly now with
[pspp-builds.git] / src / ui / gui / psppire-var-store.c
index b6966f6a83f719c04b4e53fc90b0ad7047d282e5..77ea7343636244c1c2cfc0403f7116ea1f7b339d 100644 (file)
@@ -30,6 +30,7 @@
 #include "psppire-variable.h"
 #include "psppire-var-store.h"
 #include "var-sheet.h"
+#include "helper.h"
 
 #include <data/dictionary.h>
 #include <data/variable.h>
@@ -48,7 +49,7 @@ static void         psppire_var_store_class_init      (PsppireVarStoreClass *cla
 static void         psppire_var_store_sheet_model_init (GSheetModelIface *iface);
 static void         psppire_var_store_finalize        (GObject           *object);
 
-static const gchar *const psppire_var_store_get_string(GSheetModel *sheet_model, gint row, gint column);
+static const gchar *psppire_var_store_get_string(GSheetModel *sheet_model, gint row, gint column);
 
 static gboolean  psppire_var_store_clear(GSheetModel *model,  gint row, gint col);
 
@@ -57,7 +58,7 @@ static gboolean psppire_var_store_set_string(GSheetModel *model,
                                          const gchar *text, gint row, gint column);
 
 
-static const gchar *const text_for_column(const struct PsppireVariable *pv, gint c);
+static const gchar *text_for_column(const struct PsppireVariable *pv, gint c);
 
 
 static GObjectClass *parent_class = NULL;
@@ -115,11 +116,10 @@ psppire_var_store_class_init (PsppireVarStoreClass *class)
 static void
 psppire_var_store_init (PsppireVarStore *var_store)
 {
+  GdkColormap *colormap = gdk_colormap_get_system();
 
   g_assert(gdk_color_parse("gray", &var_store->disabled));
 
-  GdkColormap *colormap = gdk_colormap_get_system();
-
   gdk_colormap_alloc_color (colormap, &var_store->disabled, FALSE, TRUE);
 
   var_store->dict = 0;
@@ -128,6 +128,7 @@ psppire_var_store_init (PsppireVarStore *var_store)
 static gboolean
 psppire_var_store_item_editable(PsppireVarStore *var_store, gint row, gint column)
 {
+  const struct fmt_spec *write_spec ;
 
   struct PsppireVariable *pv = psppire_var_store_get_variable(var_store, row);
 
@@ -137,7 +138,7 @@ psppire_var_store_item_editable(PsppireVarStore *var_store, gint row, gint colum
   if ( ALPHA == psppire_variable_get_type(pv) && column == COL_DECIMALS ) 
     return FALSE;
 
-  const struct fmt_spec *write_spec = psppire_variable_get_write_spec(pv);
+  write_spec = psppire_variable_get_write_spec(pv);
 
   switch ( write_spec->type ) 
     {
@@ -295,9 +296,11 @@ psppire_var_store_finalize (GObject *object)
   (* parent_class->finalize) (object);
 }
 
-static const gchar *const 
+static const gchar *
 psppire_var_store_get_string(GSheetModel *model, gint row, gint column)
 {
+  const gchar *s ;
+
   PsppireVarStore *store = PSPPIRE_VAR_STORE(model);
 
   struct PsppireVariable *pv;
@@ -307,9 +310,9 @@ psppire_var_store_get_string(GSheetModel *model, gint row, gint column)
   
   pv = psppire_dict_get_variable (store->dict, row);
   
-  const gchar *s = text_for_column(pv, column);
+  s = text_for_column(pv, column);
 
-  return s;
+  return pspp_locale_to_utf8(s, -1, 0);
 }
 
 
@@ -332,12 +335,14 @@ psppire_var_store_get_variable(PsppireVarStore *store, gint row)
 static gboolean 
 psppire_var_store_clear(GSheetModel *model,  gint row, gint col)
 {
+  struct PsppireVariable *pv ;
+
   PsppireVarStore *var_store = PSPPIRE_VAR_STORE(model);
 
   if ( row >= psppire_dict_get_var_cnt(var_store->dict))
       return FALSE;
 
-  struct PsppireVariable *pv = psppire_var_store_get_variable(var_store, row);
+  pv = psppire_var_store_get_variable(var_store, row);
 
   if ( !pv ) 
     return FALSE;
@@ -361,13 +366,14 @@ static gboolean
 psppire_var_store_set_string(GSheetModel *model, 
                          const gchar *text, gint row, gint col)
 {
+  struct PsppireVariable *pv ;
+
   PsppireVarStore *var_store = PSPPIRE_VAR_STORE(model);
 
   if ( row >= psppire_dict_get_var_cnt(var_store->dict))
       return FALSE;
 
-  struct PsppireVariable *pv = psppire_var_store_get_variable(var_store, row);
-
+  pv = psppire_var_store_get_variable(var_store, row);
   if ( !pv ) 
     return FALSE;
 
@@ -411,7 +417,7 @@ psppire_var_store_set_string(GSheetModel *model,
 
 #define MAX_CELL_TEXT_LEN 255
 
-static const gchar *const
+static const gchar *
 text_for_column(const struct PsppireVariable *pv, gint c)
 {
   static gchar buf[MAX_CELL_TEXT_LEN];
@@ -583,11 +589,12 @@ text_for_column(const struct PsppireVariable *pv, gint c)
 
            g_assert(vl);
 
-           gchar *const vstr = value_to_text(vl->value, *write_spec);
-
-           g_snprintf(buf, MAX_CELL_TEXT_LEN, "{%s,\"%s\"}_", vstr, vl->label);
+           {
+             gchar *const vstr = value_to_text(vl->value, *write_spec);
 
-           g_free(vstr);
+             g_snprintf(buf, MAX_CELL_TEXT_LEN, "{%s,\"%s\"}_", vstr, vl->label);
+             g_free(vstr);
+           }
 
            val_labs_done(&ip);