#include "psppire-variable.h"
#include "psppire-data-store.h"
+#include "helper.h"
#include <data/dictionary.h>
#include <data/missing-values.h>
static void psppire_data_store_sheet_column_init (GSheetColumnIface *iface);
static void psppire_data_store_finalize (GObject *object);
-static const gchar *const psppire_data_store_get_string(GSheetModel *sheet_model, gint row, gint column);
+static const gchar *psppire_data_store_get_string(GSheetModel *sheet_model, gint row, gint column);
static gboolean psppire_data_store_set_string(GSheetModel *model,
const gchar *text, gint row, gint column);
static void
psppire_data_store_sheet_model_init (GSheetModelIface *iface)
{
+ iface->free_strings = TRUE;
iface->get_string = psppire_data_store_get_string;
iface->set_string = psppire_data_store_set_string;
iface->clear_datum = psppire_data_store_clear_datum;
}
-static const gchar *const
+static const gchar *
psppire_data_store_get_string(GSheetModel *model, gint row, gint column)
{
+ const char *text;
const struct fmt_spec *fp ;
const struct PsppireVariable *pv ;
const union value *v ;
- static gchar s[255];
+ GString *s;
PsppireDataStore *store = PSPPIRE_DATA_STORE(model);
g_return_val_if_fail(store->dict, NULL);
if ( row >= psppire_case_array_get_n_cases(store->cases))
return NULL;
+
pv = psppire_dict_get_variable(store->dict, column);
v = psppire_case_array_get_value(store->cases, row,
const gchar *label;
if ( (label = val_labs_find(vl, *v)) )
{
- return label;
+ return pspp_locale_to_utf8(label, -1, 0);
}
}
fp = psppire_variable_get_write_spec(pv);
- if ( psppire_variable_get_type(pv) == NUMERIC )
- {
- /* Converts binary value V into printable form in the exactly
- FP->W character in buffer S according to format specification
- FP. No null terminator is appended to the buffer. */
- data_out (s, fp, v);
- s[fp->w] = '\0';
- }
- else
- {
- const gint len = psppire_variable_get_width(pv);
- memcpy(s, v->s, len);
- s[len] = '\0';
- }
+ s = g_string_sized_new (fp->w + 1);
+ g_string_set_size(s, fp->w);
+
+ memset(s->str, 0, fp->w);
- {
- static gchar buf[255];
- GError *err = NULL;
- gchar *text = g_locale_to_utf8(s, fp->w, 0, 0, &err);
- if ( !err )
- {
- g_snprintf(buf, 255, text);
- g_free(text);
- }
- else
- {
- g_warning("Cannot convert string \"%s\" to utf-8: %s\n", s, err->message);
- g_error_free(err);
- return NULL;
- }
+ g_assert(fp->w == s->len);
+
+ /* Converts binary value V into printable form in the exactly
+ FP->W character in buffer S according to format specification
+ FP. No null terminator is appended to the buffer. */
+ data_out (s->str, fp, v);
- return buf ;
- }
+
+ text = pspp_locale_to_utf8(s->str, fp->w, 0);
+ g_string_free(s, TRUE);
+
+ return text;
}
/* FIXME: make this a member of the data store */
static PangoLayout *layout = 0;
-
gtk_sheet_get_attributes(sheet, row, col, &attributes);
if (! layout )
layout = gtk_widget_create_pango_layout (GTK_WIDGET(sheet), "M");
+
+ g_assert(layout);
pango_layout_set_font_description (layout,
attributes.font_desc);
static const gchar *
geometry_get_button_label(const GSheetColumn *geom, gint unit)
{
+ const gchar *text;
struct PsppireVariable *pv ;
PsppireDataStore *ds = PSPPIRE_DATA_STORE(geom);
if ( unit >= psppire_dict_get_var_cnt(ds->dict) )
- return null_var_name;
+ return pspp_locale_to_utf8(null_var_name, -1, 0);
pv = psppire_dict_get_variable(ds->dict, unit);
- return psppire_variable_get_name(pv);
+ text = pspp_locale_to_utf8(psppire_variable_get_name(pv), -1, 0);
+
+ return text;
}