From b1352e0bd746fd3ca70dafb1c1715deb70234a41 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Thu, 11 May 2006 14:28:02 +0000 Subject: [PATCH] Converted strings to utf8 before passing to gtksheet. Should work properly now with internationalised system files. --- lib/gtksheet/ChangeLog | 4 ++++ lib/gtksheet/gtksheet.c | 4 ++-- lib/gtksheet/gtksheet.h | 2 +- src/ui/gui/ChangeLog | 11 +++++++++++ src/ui/gui/data-sheet.c | 7 ++++++- src/ui/gui/helper.c | 24 +++++++++++++++++++++- src/ui/gui/helper.h | 4 ++++ src/ui/gui/psppire-data-store.c | 35 +++++++++++---------------------- src/ui/gui/psppire-dict.c | 4 ++-- src/ui/gui/psppire-var-store.c | 2 +- src/ui/gui/psppire.c | 2 +- src/ui/gui/var-sheet.c | 8 +++++--- 12 files changed, 71 insertions(+), 36 deletions(-) diff --git a/lib/gtksheet/ChangeLog b/lib/gtksheet/ChangeLog index 6d4075d8..2d2cfd04 100644 --- a/lib/gtksheet/ChangeLog +++ b/lib/gtksheet/ChangeLog @@ -1,3 +1,7 @@ +Thu May 11 22:20:04 WST 2006 John Darrington + + * gtksheet.c, gtksheet.h: Fixed broken deallocation of sheet->pixmap. + Thu May 4 17:55:48 WST 2006 John Darrington * gtksheet.c: Added callback on inserted rows. diff --git a/lib/gtksheet/gtksheet.c b/lib/gtksheet/gtksheet.c index 648126f0..2e9e416d 100644 --- a/lib/gtksheet/gtksheet.c +++ b/lib/gtksheet/gtksheet.c @@ -2782,7 +2782,7 @@ gtk_sheet_unrealize (GtkWidget * widget) gdk_window_destroy (sheet->row_title_window); if (sheet->pixmap){ - g_free (sheet->pixmap); + g_object_unref(sheet->pixmap); sheet->pixmap = NULL; } @@ -4134,7 +4134,7 @@ gtk_sheet_make_backing_pixmap (GtkSheet *sheet, guint width, guint height) &pixmap_width, &pixmap_height); if ((pixmap_width != width) || (pixmap_height != height)) { - g_free(sheet->pixmap); + g_object_unref(sheet->pixmap); sheet->pixmap = gdk_pixmap_new (sheet->sheet_window, width, height, -1); diff --git a/lib/gtksheet/gtksheet.h b/lib/gtksheet/gtksheet.h index 9f0a76da..3fecbc92 100644 --- a/lib/gtksheet/gtksheet.h +++ b/lib/gtksheet/gtksheet.h @@ -178,7 +178,7 @@ struct _GtkSheet{ guint sheet_window_height; /* sheet backing pixmap */ - GdkWindow *pixmap; + GdkPixmap *pixmap; /* offsets for scrolling */ gint hoffset; diff --git a/src/ui/gui/ChangeLog b/src/ui/gui/ChangeLog index ece35938..6aba2cf8 100644 --- a/src/ui/gui/ChangeLog +++ b/src/ui/gui/ChangeLog @@ -1,3 +1,14 @@ +Thu May 11 22:25:49 WST 2006 John Darrington + + * data-sheet.c helper.c helper.h psppire-data-store.c psppire-var-store.c + psppire.c: Converted strings to utf8 before passing to gtksheet. + + * psppire-dict.c: Changed buffer to more reasonable length + + * var-sheet.c: Changed maximum string length to use macro from + data/values.h + + Sun May 7 10:07:28 WST 2006 John Darrington * psppire-data-store.c: Fixed buglet initialising string members. diff --git a/src/ui/gui/data-sheet.c b/src/ui/gui/data-sheet.c index d32e6e37..20869dcb 100644 --- a/src/ui/gui/data-sheet.c +++ b/src/ui/gui/data-sheet.c @@ -98,6 +98,7 @@ update_data_ref_entry(GtkSheet *sheet, gint row, gint col) psppire_dict_get_variable(data_store->dict, col); gchar *text ; + gchar *s ; if ( !xml) return FALSE; @@ -107,9 +108,13 @@ update_data_ref_entry(GtkSheet *sheet, gint row, gint col) cell_ref_entry = GTK_ENTRY(get_widget_assert(xml, "cell_ref_entry")); - gtk_entry_set_text(cell_ref_entry, text); + s = pspp_locale_to_utf8(text, -1, 0); g_free(text); + + gtk_entry_set_text(cell_ref_entry, s); + + g_free(s); } return FALSE; diff --git a/src/ui/gui/helper.c b/src/ui/gui/helper.c index 549242e6..e3c4ee08 100644 --- a/src/ui/gui/helper.c +++ b/src/ui/gui/helper.c @@ -71,8 +71,30 @@ get_widget_assert(GladeXML *xml, const gchar *name) w = glade_xml_get_widget(xml, name); if ( !w ) - g_warning("Widget \"%s\" could not be found\n",name); + g_warning("Widget \"%s\" could not be found\n", name); return w; } +/* Converts a string in the pspp locale to utf-8 */ +const char * +pspp_locale_to_utf8(const gchar *text, gssize len, GError **err) +{ + GError *tmp_error = 0; + + const gchar *s; + + if ( ! text ) + return 0; + + s = g_locale_to_utf8(text, len, 0, 0, &tmp_error); + + if ( tmp_error) + { + g_warning("Error converting to UTF8: %s", tmp_error->message); + g_propagate_error (err, tmp_error); + } + + return s; +} + diff --git a/src/ui/gui/helper.h b/src/ui/gui/helper.h index eef64213..3ec352d9 100644 --- a/src/ui/gui/helper.h +++ b/src/ui/gui/helper.h @@ -38,4 +38,8 @@ gboolean text_to_value(const gchar *text, union value *v, GtkWidget * get_widget_assert(GladeXML *xml, const gchar *name); +/* Converts a string in the pspp locale to utf-8 */ +const char * pspp_locale_to_utf8(const gchar *text, gssize len, GError **err); + + #endif diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index cdd000b3..4a517db1 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -329,7 +329,7 @@ psppire_data_store_finalize (GObject *object) 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 ; @@ -358,7 +358,7 @@ psppire_data_store_get_string(GSheetModel *model, gint row, gint column) const gchar *label; if ( (label = val_labs_find(vl, *v)) ) { - return label; + return pspp_locale_to_utf8(label, -1, 0); } } @@ -375,28 +375,12 @@ psppire_data_store_get_string(GSheetModel *model, gint row, gint column) 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 g_string_free(s, FALSE); -#if 0 - { - 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; - } + text = pspp_locale_to_utf8(s->str, fp->w, 0); + g_string_free(s, TRUE); - return buf ; - } -#endif + return text; } @@ -658,15 +642,18 @@ static const gchar null_var_name[]=_("var"); 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; } diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index f9196504..5f2975a1 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -212,10 +212,10 @@ static gchar * auto_generate_var_name(PsppireDict *dict) { gint d = 0; - static gchar name[255]; + static gchar name[10]; - while (g_snprintf(name, 255, "VAR%05d",d++), + while (g_snprintf(name, 10, "VAR%05d",d++), psppire_dict_lookup_var(dict, name)) ; diff --git a/src/ui/gui/psppire-var-store.c b/src/ui/gui/psppire-var-store.c index 97695a13..77ea7343 100644 --- a/src/ui/gui/psppire-var-store.c +++ b/src/ui/gui/psppire-var-store.c @@ -312,7 +312,7 @@ psppire_var_store_get_string(GSheetModel *model, gint row, gint column) s = text_for_column(pv, column); - return g_locale_to_utf8(s, -1, 0,0,0); + return pspp_locale_to_utf8(s, -1, 0); } diff --git a/src/ui/gui/psppire.c b/src/ui/gui/psppire.c index aefb26e7..9d01f9f7 100644 --- a/src/ui/gui/psppire.c +++ b/src/ui/gui/psppire.c @@ -78,7 +78,7 @@ main(int argc, char *argv[]) var_store = psppire_var_store_new(the_dictionary); /* Create the model for the data sheet */ - the_cases = psppire_case_array_new(100, 20); + the_cases = psppire_case_array_new(100000, 20); data_store = psppire_data_store_new(the_dictionary, the_cases); diff --git a/src/ui/gui/var-sheet.c b/src/ui/gui/var-sheet.c index e04d4895..76065949 100644 --- a/src/ui/gui/var-sheet.c +++ b/src/ui/gui/var-sheet.c @@ -30,7 +30,9 @@ #include #include -#define min(A,B) ((A < B)?A:B) +#include + +#include #include #include @@ -366,11 +368,11 @@ var_sheet_cell_change_entry (GtkSheet * sheet, gint row, gint column, { case COL_WIDTH: r_min = fmt->d + 1; - r_max = (psppire_variable_get_type(pv) == ALPHA) ? 255 : 40; + r_max = (psppire_variable_get_type(pv) == ALPHA) ? MAX_STRING : 40; break; case COL_DECIMALS: r_min = 0 ; - r_max = min(fmt->w - 1, 16); + r_max = MIN(fmt->w - 1, 16); break; case COL_COLUMNS: r_min = 1; -- 2.30.2