X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-data-store.c;h=9835d307fb80eafc3361d062e72b121f77fc7d89;hb=11706f97dd318697e43e6468b130ca5b7f1bff87;hp=1e6568b78afa6bfe6247142da7d0a3f7ac649b00;hpb=32884aab5da9ba8455d482dc1f52989ff7de4ee6;p=pspp-builds.git diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 1e6568b7..9835d307 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 Free Software Foundation + Copyright (C) 2006, 2008 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,9 +25,8 @@ #include #include -#include #include -#include +#include #include @@ -39,22 +38,22 @@ #include #include #include +#include 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_column_init (GSheetColumnIface *iface); static void psppire_data_store_sheet_row_init (GSheetRowIface *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, glong row, glong column); #define MIN_COLUMNS 10 - #define TRAILING_ROWS 10 static GObjectClass *parent_class = NULL; @@ -66,7 +65,7 @@ enum {FONT_CHANGED, static guint signals [n_SIGNALS]; -inline GType +GType psppire_data_store_get_type (void) { static GType data_store_type = 0; @@ -93,13 +92,6 @@ psppire_data_store_get_type (void) NULL }; - static const GInterfaceInfo sheet_column_info = - { - (GInterfaceInitFunc) psppire_data_store_sheet_column_init, - NULL, - NULL - }; - static const GInterfaceInfo sheet_row_info = { (GInterfaceInitFunc) psppire_data_store_sheet_row_init, @@ -115,10 +107,6 @@ psppire_data_store_get_type (void) G_TYPE_SHEET_MODEL, &sheet_model_info); - g_type_add_interface_static (data_store_type, - G_TYPE_SHEET_COLUMN, - &sheet_column_info); - g_type_add_interface_static (data_store_type, G_TYPE_SHEET_ROW, &sheet_row_info); @@ -137,6 +125,7 @@ psppire_data_store_class_init (PsppireDataStoreClass *class) object_class = (GObjectClass*) class; object_class->finalize = psppire_data_store_finalize; + object_class->dispose = psppire_data_store_dispose; signals [FONT_CHANGED] = g_signal_new ("font_changed", @@ -159,13 +148,19 @@ psppire_data_store_get_var_count (const GSheetModel *model) return psppire_dict_get_var_cnt (store->dict); } -inline casenumber +casenumber psppire_data_store_get_case_count (const PsppireDataStore *store) { return psppire_case_file_get_case_count (store->case_file); } -inline casenumber +size_t +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) { const PsppireDataStore *store = PSPPIRE_DATA_STORE (model); @@ -176,10 +171,9 @@ static void psppire_data_store_init (PsppireDataStore *data_store) { data_store->dict = 0; - data_store->case_file = 0; + data_store->case_file = NULL; data_store->width_of_m = 10; - - + data_store->dispose_has_run = FALSE; } const PangoFontDescription * @@ -210,6 +204,11 @@ 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 void psppire_data_store_sheet_model_init (GSheetModelIface *iface) @@ -226,15 +225,13 @@ psppire_data_store_sheet_model_init (GSheetModelIface *iface) 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; -} -static -gboolean always_true () -{ - return TRUE; + iface->get_column_subtitle = get_column_subtitle; + iface->get_column_title = get_column_button_label; + iface->get_column_sensitivity = get_column_sensitivity; + iface->get_column_justification = get_column_justification; } - static void delete_cases_callback (GtkWidget *w, casenumber first, casenumber n_cases, gpointer data) @@ -293,10 +290,12 @@ delete_variable_callback (GObject *obj, gint dict_index, { PsppireDataStore *store = PSPPIRE_DATA_STORE (data); +#if AXIS_TRANSITION g_sheet_model_columns_deleted (G_SHEET_MODEL (store), dict_index, 1); g_sheet_column_columns_changed (G_SHEET_COLUMN (store), dict_index, -1); +#endif } @@ -305,6 +304,7 @@ variable_changed_callback (GObject *obj, gint var_num, gpointer data) { PsppireDataStore *store = PSPPIRE_DATA_STORE (data); +#if AXIS_TRANSITION g_sheet_column_columns_changed (G_SHEET_COLUMN (store), var_num, 1); @@ -312,6 +312,7 @@ variable_changed_callback (GObject *obj, gint var_num, gpointer data) g_sheet_model_range_changed (G_SHEET_MODEL (store), -1, var_num, -1, var_num); +#endif } static void @@ -340,8 +341,10 @@ insert_variable_callback (GObject *obj, gint var_num, gpointer data) psppire_case_file_insert_values (store->case_file, 1, posn); +#if AXIS_TRANSITION g_sheet_column_columns_changed (G_SHEET_COLUMN (store), var_num, 1); +#endif g_sheet_model_columns_inserted (G_SHEET_MODEL (store), var_num, 1); } @@ -390,10 +393,8 @@ psppire_data_store_set_case_file (PsppireDataStore *ds, PsppireCaseFile *cf) { gint i; - if ( ds->case_file) - { - g_object_unref (ds->case_file); - } + if ( ds->case_file) g_object_unref (ds->case_file); + ds->case_file = cf; @@ -487,8 +488,9 @@ 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); +#if AXIS_TRANSITION g_sheet_column_columns_changed (G_SHEET_COLUMN (data_store), 0, -1); - +#endif if ( data_store->dict ) for (i = 0 ; i < n_dict_signals; ++i ) @@ -509,6 +511,24 @@ psppire_data_store_finalize (GObject *object) (* parent_class->finalize) (object); } + +static void +psppire_data_store_dispose (GObject *object) +{ + PsppireDataStore *ds = PSPPIRE_DATA_STORE (object); + + if (ds->dispose_has_run) + return; + + if (ds->case_file) g_object_unref (ds->case_file); + + /* must chain up */ + (* parent_class->dispose) (object); + + ds->dispose_has_run = TRUE; +} + + gboolean psppire_data_store_delete_cases (PsppireDataStore *ds, casenumber first, casenumber count) @@ -653,23 +673,17 @@ gboolean psppire_data_store_set_string (PsppireDataStore *store, const gchar *text, glong row, glong col) { + glong n_cases; const struct variable *pv = psppire_dict_get_variable (store->dict, col); g_return_val_if_fail (pv, FALSE); -#if 0 - /* Allow the user to insert a lot of blank cases, simply by skipping rows */ - for (r = psppire_case_file_get_case_count (store->case_file); r <= row ; ++r) - { - - gint c; - - psppire_case_array_insert_case (store->cases, r, 0, 0); + n_cases = psppire_data_store_get_case_count (store); + if ( row > n_cases) + return FALSE; - for (c = 0 ; c < psppire_dict_get_var_cnt (store->dict); ++c ) - psppire_data_store_clear_datum (model, r, c); - } -#endif + if (row == n_cases) + psppire_data_store_insert_new_case (store, row); psppire_case_file_data_in (store->case_file, row, var_get_case_index (pv), ss_cstr (text), @@ -750,6 +764,7 @@ psppire_data_store_get_reader (PsppireDataStore *ds) /* Column related funcs */ +#if AXIS_TRANSITION static glong geometry_get_column_count (const GSheetColumn *geom) { @@ -782,99 +797,23 @@ geometry_set_width (GSheetColumn *geom, glong unit, gint width) { PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - struct variable *pv = psppire_dict_get_variable (ds->dict, unit); - - var_set_display_width (pv, width / ds->width_of_m ); -} - - - -static GtkJustification -geometry_get_justification (const GSheetColumn *geom, glong unit) -{ - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - const struct variable *pv ; + struct variable *v = psppire_dict_get_variable (ds->dict, unit); + g_return_if_fail (v); - if ( unit >= psppire_dict_get_var_cnt (ds->dict) ) - return GTK_JUSTIFY_LEFT; - - pv = psppire_dict_get_variable (ds->dict, unit); - - return (var_get_alignment (pv) == ALIGN_LEFT ? GTK_JUSTIFY_LEFT - : var_get_alignment (pv) == ALIGN_RIGHT ? GTK_JUSTIFY_RIGHT - : GTK_JUSTIFY_CENTER); + var_set_display_width (v, width / ds->width_of_m ); } - -static const gchar null_var_name[]=N_("var"); - -static gchar * -geometry_get_column_button_label (const GSheetColumn *geom, glong unit) -{ - gchar *text; - struct variable *pv ; - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - if ( unit >= psppire_dict_get_var_cnt (ds->dict) ) - return g_locale_to_utf8 (null_var_name, -1, 0, 0, 0); - - pv = psppire_dict_get_variable (ds->dict, unit); - - text = pspp_locale_to_utf8 (var_get_name (pv), -1, 0); - - return text; -} - - -static gchar * -geometry_get_column_subtitle (const GSheetColumn *geom, glong unit) -{ - gchar *text; - const struct variable *v ; - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - if ( unit >= psppire_dict_get_var_cnt (ds->dict) ) - return NULL; - - v = psppire_dict_get_variable (ds->dict, unit); - - if ( ! var_has_label (v)) - return NULL; - - text = pspp_locale_to_utf8 (var_get_label (v), -1, 0); - - return text; -} - - -static gboolean -geometry_get_sensitivity (const GSheetColumn *geom, glong unit) -{ - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - return (unit < psppire_dict_get_var_cnt (ds->dict)); -} +#endif -static void -psppire_data_store_sheet_column_init (GSheetColumnIface *iface) -{ - iface->get_column_count = geometry_get_column_count; - iface->get_width = geometry_get_width; - iface->set_width = geometry_set_width; - iface->get_visibility = always_true; - iface->get_sensitivity = geometry_get_sensitivity; - iface->get_justification = geometry_get_justification; - iface->get_button_label = geometry_get_column_button_label; - iface->get_subtitle = geometry_get_column_subtitle; -} +static const gchar null_var_name[]=N_("var"); /* Row related funcs */ static glong -geometry_get_row_count (const GSheetRow *geom, gpointer data) +geometry_get_row_count (const GSheetRow *geom) { PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); @@ -884,31 +823,31 @@ geometry_get_row_count (const GSheetRow *geom, gpointer data) #define ROW_HEIGHT 25 static gint -geometry_get_height (const GSheetRow *geom, glong unit, gpointer data) +geometry_get_height (const GSheetRow *geom, glong unit) { return ROW_HEIGHT; } static guint -geometry_get_top_ypixel (const GSheetRow *geo, glong row, gpointer data) +geometry_get_top_ypixel (const GSheetRow *geo, glong row) { return row * ROW_HEIGHT; } static glong -geometry_pixel_to_row (const GSheetRow *geo, guint pixel, gpointer data) +geometry_pixel_to_row (const GSheetRow *geo, guint pixel) { glong row = pixel / ROW_HEIGHT; - if (row >= geometry_get_row_count (geo, data)) - row = geometry_get_row_count (geo, data) - 1; + if (row >= geometry_get_row_count (geo)) + row = geometry_get_row_count (geo) - 1; return row; } static gboolean -geometry_get_row_sensitivity (const GSheetRow *geom, glong unit, gpointer data) +geometry_get_row_sensitivity (const GSheetRow *geom, glong unit) { PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); @@ -916,9 +855,8 @@ geometry_get_row_sensitivity (const GSheetRow *geom, glong unit, gpointer data) return (unit < psppire_case_file_get_case_count (ds->case_file)); } - static gchar * -geometry_get_row_button_label (const GSheetRow *geom, glong unit, gpointer data) +geometry_get_row_button_label (const GSheetRow *geom, glong unit) { gchar *text; gchar *s; @@ -944,9 +882,78 @@ psppire_data_store_sheet_row_init (GSheetRowIface *iface) iface->get_height = geometry_get_height; iface->set_height = 0; - iface->get_visibility = always_true; iface->get_sensitivity = geometry_get_row_sensitivity; iface->top_ypixel = geometry_get_top_ypixel; iface->pixel_to_row = geometry_pixel_to_row; iface->get_button_label = geometry_get_row_button_label; } + + + + +/* Column related stuff */ + +static gchar * +get_column_subtitle (const GSheetModel *model, gint col) +{ + gchar *text; + const struct variable *v ; + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); + + if ( col >= psppire_dict_get_var_cnt (ds->dict) ) + return NULL; + + v = psppire_dict_get_variable (ds->dict, col); + + if ( ! var_has_label (v)) + return NULL; + + text = pspp_locale_to_utf8 (var_get_label (v), -1, 0); + + return text; +} + +static gchar * +get_column_button_label (const GSheetModel *model, gint col) +{ + gchar *text; + struct variable *pv ; + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); + + if ( col >= psppire_dict_get_var_cnt (ds->dict) ) + return g_locale_to_utf8 (null_var_name, -1, 0, 0, 0); + + pv = psppire_dict_get_variable (ds->dict, col); + + text = pspp_locale_to_utf8 (var_get_name (pv), -1, 0); + + return text; +} + +static gboolean +get_column_sensitivity (const GSheetModel *model, gint col) +{ + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); + + return (col < psppire_dict_get_var_cnt (ds->dict)); +} + + + +static GtkJustification +get_column_justification (const GSheetModel *model, gint col) +{ + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); + const struct variable *pv ; + + if ( col >= psppire_dict_get_var_cnt (ds->dict) ) + return GTK_JUSTIFY_LEFT; + + pv = psppire_dict_get_variable (ds->dict, col); + + return (var_get_alignment (pv) == ALIGN_LEFT ? GTK_JUSTIFY_LEFT + : var_get_alignment (pv) == ALIGN_RIGHT ? GTK_JUSTIFY_RIGHT + : GTK_JUSTIFY_CENTER); +} + +