X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-data-store.c;h=45fa82488b4e19dabbdf991bae83681fe2e93075;hb=73d03a239e23f6adb9b4c5a3596abed8c0198ca0;hp=29efbb16c72783d360410a1d6e095ee68f41d731;hpb=fe7885d731f2dcb6f30e97192b51f493abcfc2c9;p=pspp-builds.git diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 29efbb16..45fa8248 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2006, 2008 Free Software Foundation + Copyright (C) 2006, 2008, 2009 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,12 +25,13 @@ #include #include -#include -#include +#include +#include #include #include "psppire-data-store.h" +#include #include "helper.h" #include @@ -48,12 +49,12 @@ static void psppire_data_store_init (PsppireDataStore *data_store); static void psppire_data_store_class_init (PsppireDataStoreClass *class); -static void psppire_data_store_sheet_model_init (GSheetModelIface *iface); +static void psppire_data_store_sheet_model_init (PsppireSheetModelIface *iface); static void psppire_data_store_finalize (GObject *object); static void psppire_data_store_dispose (GObject *object); -static gboolean psppire_data_store_clear_datum (GSheetModel *model, +static gboolean psppire_data_store_clear_datum (PsppireSheetModel *model, glong row, glong column); @@ -117,7 +118,7 @@ psppire_data_store_get_type (void) &data_store_info, 0); g_type_add_interface_static (data_store_type, - G_TYPE_SHEET_MODEL, + PSPPIRE_TYPE_SHEET_MODEL, &sheet_model_info); } @@ -203,7 +204,7 @@ psppire_data_store_set_value (PsppireDataStore *ds, casenumber casenum, static glong -psppire_data_store_get_var_count (const GSheetModel *model) +psppire_data_store_get_var_count (const PsppireSheetModel *model) { const PsppireDataStore *store = PSPPIRE_DATA_STORE (model); @@ -222,8 +223,8 @@ psppire_data_store_get_value_count (const PsppireDataStore *store) return psppire_dict_get_value_cnt (store->dict); } -casenumber -psppire_data_store_get_case_count_wrapper (const GSheetModel *model) +static casenumber +psppire_data_store_get_case_count_wrapper (const PsppireSheetModel *model) { const PsppireDataStore *store = PSPPIRE_DATA_STORE (model); return psppire_data_store_get_case_count (store); @@ -238,7 +239,7 @@ psppire_data_store_init (PsppireDataStore *data_store) } static inline gchar * -psppire_data_store_get_string_wrapper (const GSheetModel *model, glong row, +psppire_data_store_get_string_wrapper (const PsppireSheetModel *model, glong row, glong column) { return psppire_data_store_get_string (PSPPIRE_DATA_STORE (model), row, column); @@ -246,7 +247,7 @@ psppire_data_store_get_string_wrapper (const GSheetModel *model, glong row, static inline gboolean -psppire_data_store_set_string_wrapper (GSheetModel *model, +psppire_data_store_set_string_wrapper (PsppireSheetModel *model, const gchar *text, glong row, glong column) { @@ -256,17 +257,18 @@ psppire_data_store_set_string_wrapper (GSheetModel *model, -static gchar * get_column_subtitle (const GSheetModel *model, gint col); -static gchar * get_column_button_label (const GSheetModel *model, gint col); -static gboolean get_column_sensitivity (const GSheetModel *model, gint col); -static GtkJustification get_column_justification (const GSheetModel *model, gint col); +static gchar * get_column_subtitle (const PsppireSheetModel *model, gint col); +static gchar * get_column_button_label (const PsppireSheetModel *model, gint col); +static gboolean get_column_sensitivity (const PsppireSheetModel *model, gint col); +static GtkJustification get_column_justification (const PsppireSheetModel *model, gint col); -static gchar * get_row_button_label (const GSheetModel *model, gint row); -static gboolean get_row_sensitivity (const GSheetModel *model, gint row); +static gchar * get_row_button_label (const PsppireSheetModel *model, gint row); +static gboolean get_row_sensitivity (const PsppireSheetModel *model, gint row); +static gboolean get_row_overstrike (const PsppireSheetModel *model, gint row); static void -psppire_data_store_sheet_model_init (GSheetModelIface *iface) +psppire_data_store_sheet_model_init (PsppireSheetModelIface *iface) { iface->free_strings = TRUE; iface->get_string = psppire_data_store_get_string_wrapper; @@ -275,7 +277,6 @@ psppire_data_store_sheet_model_init (GSheetModelIface *iface) iface->is_editable = NULL; iface->get_foreground = NULL; iface->get_background = NULL; - iface->get_cell_border = NULL; iface->get_column_count = psppire_data_store_get_var_count; iface->get_row_count = psppire_data_store_get_case_count_wrapper; @@ -286,6 +287,7 @@ psppire_data_store_sheet_model_init (GSheetModelIface *iface) iface->get_row_title = get_row_button_label; iface->get_row_sensitivity = get_row_sensitivity; + iface->get_row_overstrike = get_row_overstrike; } @@ -299,27 +301,26 @@ delete_variable_callback (GObject *obj, gint dict_index, { PsppireDataStore *store = PSPPIRE_DATA_STORE (data); + + psppire_sheet_model_columns_deleted (PSPPIRE_SHEET_MODEL (store), dict_index, 1); #if AXIS_TRANSITION - g_sheet_model_columns_deleted (G_SHEET_MODEL (store), dict_index, 1); - g_sheet_column_columns_changed (G_SHEET_COLUMN (store), + + psppire_sheet_column_columns_changed (PSPPIRE_SHEET_COLUMN (store), dict_index, -1); #endif } - - static void variable_changed_callback (GObject *obj, gint var_num, gpointer data) { +#if AXIS_TRANSITION PsppireDataStore *store = PSPPIRE_DATA_STORE (data); -#if AXIS_TRANSITION - g_sheet_column_columns_changed (G_SHEET_COLUMN (store), + psppire_sheet_column_columns_changed (PSPPIRE_SHEET_COLUMN (store), var_num, 1); - - g_sheet_model_range_changed (G_SHEET_MODEL (store), + psppire_sheet_model_range_changed (PSPPIRE_SHEET_MODEL (store), -1, var_num, -1, var_num); #endif @@ -352,11 +353,12 @@ insert_variable_callback (GObject *obj, gint var_num, gpointer data) psppire_data_store_insert_values (store, 1, posn); #if AXIS_TRANSITION - g_sheet_column_columns_changed (G_SHEET_COLUMN (store), + + psppire_sheet_column_columns_changed (PSPPIRE_SHEET_COLUMN (store), var_num, 1); #endif - g_sheet_model_columns_inserted (G_SHEET_MODEL (store), var_num, 1); + psppire_sheet_model_columns_inserted (PSPPIRE_SHEET_MODEL (store), var_num, 1); } @@ -408,7 +410,7 @@ psppire_data_store_set_reader (PsppireDataStore *ds, ds->datasheet = datasheet_create (reader); - g_sheet_model_range_changed (G_SHEET_MODEL (ds), + psppire_sheet_model_range_changed (PSPPIRE_SHEET_MODEL (ds), -1, -1, -1, -1); if ( ds->dict ) @@ -475,10 +477,10 @@ psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *di /* The entire model has changed */ - g_sheet_model_range_changed (G_SHEET_MODEL (data_store), -1, -1, -1, -1); + psppire_sheet_model_range_changed (PSPPIRE_SHEET_MODEL (data_store), -1, -1, -1, -1); #if AXIS_TRANSITION - g_sheet_column_columns_changed (G_SHEET_COLUMN (data_store), 0, -1); + psppire_sheet_column_columns_changed (PSPPIRE_SHEET_COLUMN (data_store), 0, -1); #endif if ( data_store->dict ) @@ -529,7 +531,7 @@ psppire_data_store_insert_new_case (PsppireDataStore *ds, casenumber posn) { gboolean result; gint val_cnt, v; - struct ccase cc; + struct ccase *cc; g_return_val_if_fail (ds, FALSE); val_cnt = datasheet_get_column_cnt (ds->datasheet) ; @@ -538,9 +540,9 @@ psppire_data_store_insert_new_case (PsppireDataStore *ds, casenumber posn) g_return_val_if_fail (posn <= psppire_data_store_get_case_count (ds), FALSE); - case_create (&cc, val_cnt); + cc = case_create (val_cnt); - memset ( case_data_rw_idx (&cc, 0), 0, val_cnt * MAX_SHORT_STRING); + memset ( case_data_rw_idx (cc, 0), 0, val_cnt * MAX_SHORT_STRING); for (v = 0 ; v < psppire_dict_get_var_cnt (ds->dict) ; ++v) { @@ -548,12 +550,12 @@ psppire_data_store_insert_new_case (PsppireDataStore *ds, casenumber posn) if ( var_is_alpha (pv)) continue; - case_data_rw (&cc, pv)->f = SYSMIS; + case_data_rw (cc, pv)->f = SYSMIS; } - result = psppire_data_store_insert_case (ds, &cc, posn); + result = psppire_data_store_insert_case (ds, cc, posn); - case_destroy (&cc); + case_unref (cc); return result; } @@ -597,7 +599,8 @@ psppire_data_store_get_string (PsppireDataStore *store, glong row, glong column) if (label) { free (v); - return pspp_locale_to_utf8 (label, -1, 0); + return recode_string (UTF8, psppire_dict_encoding (store->dict), + label, -1); } } @@ -615,7 +618,8 @@ psppire_data_store_get_string (PsppireDataStore *store, glong row, glong column) FP. No null terminator is appended to the buffer. */ data_out (v, fp, s->str); - text = pspp_locale_to_utf8 (s->str, fp->w, 0); + text = recode_string (UTF8, psppire_dict_encoding (store->dict), + s->str, fp->w); g_string_free (s, TRUE); g_strchomp (text); @@ -626,7 +630,7 @@ psppire_data_store_get_string (PsppireDataStore *store, glong row, glong column) static gboolean -psppire_data_store_clear_datum (GSheetModel *model, +psppire_data_store_clear_datum (PsppireSheetModel *model, glong row, glong col) { PsppireDataStore *store = PSPPIRE_DATA_STORE (model); @@ -644,6 +648,8 @@ psppire_data_store_clear_datum (GSheetModel *model, psppire_data_store_set_value (store, row, index, &v, var_get_width (pv)); + psppire_sheet_model_range_changed (model, row, col, row, col); + return TRUE; } @@ -656,9 +662,11 @@ gboolean psppire_data_store_set_string (PsppireDataStore *store, const gchar *text, glong row, glong col) { + gchar *s; glong n_cases; const struct variable *pv = psppire_dict_get_variable (store->dict, col); - g_return_val_if_fail (pv, FALSE); + if ( NULL == pv) + return FALSE; n_cases = psppire_data_store_get_case_count (store); @@ -668,9 +676,14 @@ psppire_data_store_set_string (PsppireDataStore *store, if (row == n_cases) psppire_data_store_insert_new_case (store, row); + s = recode_string (psppire_dict_encoding (store->dict), UTF8, text, -1); + psppire_data_store_data_in (store, row, - var_get_case_index (pv), ss_cstr (text), + var_get_case_index (pv), ss_cstr (s), var_get_write_format (pv)); + free (s); + + psppire_sheet_model_range_changed (PSPPIRE_SHEET_MODEL (store), row, col, row, col); return TRUE; } @@ -685,7 +698,7 @@ psppire_data_store_show_labels (PsppireDataStore *store, gboolean show_labels) store->show_labels = show_labels; - g_sheet_model_range_changed (G_SHEET_MODEL (store), + psppire_sheet_model_range_changed (PSPPIRE_SHEET_MODEL (store), -1, -1, -1, -1); } @@ -737,11 +750,13 @@ static const gchar null_var_name[]=N_("var"); /* Row related funcs */ static gchar * -get_row_button_label (const GSheetModel *model, gint unit) +get_row_button_label (const PsppireSheetModel *model, gint unit) { + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); gchar *s = g_strdup_printf (_("%d"), unit + FIRST_CASE_NUMBER); - gchar *text = pspp_locale_to_utf8 (s, -1, 0); + gchar *text = recode_string (UTF8, psppire_dict_encoding (ds->dict), + s, -1); g_free (s); @@ -750,7 +765,7 @@ get_row_button_label (const GSheetModel *model, gint unit) static gboolean -get_row_sensitivity (const GSheetModel *model, gint unit) +get_row_sensitivity (const PsppireSheetModel *model, gint unit) { PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); @@ -763,7 +778,7 @@ get_row_sensitivity (const GSheetModel *model, gint unit) /* Column related stuff */ static gchar * -get_column_subtitle (const GSheetModel *model, gint col) +get_column_subtitle (const PsppireSheetModel *model, gint col) { gchar *text; const struct variable *v ; @@ -777,13 +792,14 @@ get_column_subtitle (const GSheetModel *model, gint col) if ( ! var_has_label (v)) return NULL; - text = pspp_locale_to_utf8 (var_get_label (v), -1, 0); + text = recode_string (UTF8, psppire_dict_encoding (ds->dict), + var_get_label (v), -1); return text; } static gchar * -get_column_button_label (const GSheetModel *model, gint col) +get_column_button_label (const PsppireSheetModel *model, gint col) { gchar *text; struct variable *pv ; @@ -794,13 +810,14 @@ get_column_button_label (const GSheetModel *model, gint col) pv = psppire_dict_get_variable (ds->dict, col); - text = pspp_locale_to_utf8 (var_get_name (pv), -1, 0); + text = recode_string (UTF8, psppire_dict_encoding (ds->dict), + var_get_name (pv), -1); return text; } static gboolean -get_column_sensitivity (const GSheetModel *model, gint col) +get_column_sensitivity (const PsppireSheetModel *model, gint col) { PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); @@ -810,7 +827,7 @@ get_column_sensitivity (const GSheetModel *model, gint col) static GtkJustification -get_column_justification (const GSheetModel *model, gint col) +get_column_justification (const PsppireSheetModel *model, gint col) { PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); const struct variable *pv ; @@ -830,18 +847,16 @@ get_column_justification (const GSheetModel *model, gint col) -/* Fills C with the CASENUMth case. - Returns true on success, false otherwise. +/* Returns the CASENUMth case, or a null pointer on failure. */ -gboolean +struct ccase * psppire_data_store_get_case (const PsppireDataStore *ds, - casenumber casenum, - struct ccase *c) + casenumber casenum) { g_return_val_if_fail (ds, FALSE); g_return_val_if_fail (ds->datasheet, FALSE); - return datasheet_get_row (ds->datasheet, casenum, c); + return datasheet_get_row (ds->datasheet, casenum); } @@ -859,6 +874,7 @@ psppire_data_store_delete_cases (PsppireDataStore *ds, casenumber first, datasheet_delete_rows (ds->datasheet, first, n_cases); g_signal_emit (ds, signals [CASES_DELETED], 0, first, n_cases); + psppire_sheet_model_rows_deleted (PSPPIRE_SHEET_MODEL (ds), first, n_cases); return TRUE; } @@ -871,17 +887,19 @@ psppire_data_store_insert_case (PsppireDataStore *ds, struct ccase *cc, casenumber posn) { - struct ccase tmp; bool result ; g_return_val_if_fail (ds, FALSE); g_return_val_if_fail (ds->datasheet, FALSE); - case_clone (&tmp, cc); - result = datasheet_insert_rows (ds->datasheet, posn, &tmp, 1); + case_ref (cc); + result = datasheet_insert_rows (ds->datasheet, posn, &cc, 1); if ( result ) - g_signal_emit (ds, signals [CASE_INSERTED], 0, posn); + { + g_signal_emit (ds, signals [CASE_INSERTED], 0, posn); + psppire_sheet_model_rows_inserted (PSPPIRE_SHEET_MODEL (ds), posn, 1); + } else g_warning ("Cannot insert case at position %ld\n", posn); @@ -938,6 +956,7 @@ psppire_data_store_set_value (PsppireDataStore *ds, casenumber casenum, ok = datasheet_put_value (ds->datasheet, casenum, idx, v, width); if (ok) g_signal_emit (ds, signals [CASE_CHANGED], 0, casenum); + return ok; } @@ -964,12 +983,12 @@ psppire_data_store_data_in (PsppireDataStore *ds, casenumber casenum, gint idx, && data_in (input, LEGACY_NATIVE, fmt->type, 0, 0, 0, value, width) && datasheet_put_value (ds->datasheet, casenum, idx, value, width)); + freea (value); + if (ok) g_signal_emit (ds, signals [CASE_CHANGED], 0, casenum); - freea (value); - - return TRUE; + return ok; } /* Resize the cases in the casefile, by inserting N_VALUES into every @@ -997,3 +1016,30 @@ psppire_data_store_insert_values (PsppireDataStore *ds, return TRUE; } + +static gboolean +get_row_overstrike (const PsppireSheetModel *model, gint row) +{ + union value val; + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); + + const struct dictionary *dict = ds->dict->dict; + + const struct variable *filter = dict_get_filter (dict); + + if ( row < 0 || row >= datasheet_get_row_cnt (ds->datasheet)) + return FALSE; + + if ( ! filter) + return FALSE; + + g_assert (var_is_numeric (filter)); + + if ( ! datasheet_get_value (ds->datasheet, row, + var_get_case_index (filter), + &val, 0) ) + return FALSE; + + + return (val.f == 0.0); +}