X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-data-store.c;h=f21dfbd68031156dbb2001cb40ffb97aad679cbb;hb=62215e63f11b18112899541b29b3151e25f7eb6e;hp=47292d92fc6c12391eb1f2107df97ab595852741;hpb=880d5a149fbdfdc074f49f590cb8aca8457b2446;p=pspp-builds.git diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 47292d92..f21dfbd6 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 @@ -26,8 +26,6 @@ #include #include -#include -#include #include @@ -39,13 +37,12 @@ #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); @@ -54,20 +51,17 @@ 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; -enum {FONT_CHANGED, +enum { + BACKEND_CHANGED, n_SIGNALS}; static guint signals [n_SIGNALS]; -inline GType +GType psppire_data_store_get_type (void) { static GType data_store_type = 0; @@ -94,20 +88,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, - NULL, - NULL - }; - data_store_type = g_type_register_static (G_TYPE_OBJECT, "PsppireDataStore", &data_store_info, 0); @@ -116,13 +96,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); } return data_store_type; @@ -140,8 +113,8 @@ psppire_data_store_class_init (PsppireDataStoreClass *class) object_class->finalize = psppire_data_store_finalize; object_class->dispose = psppire_data_store_dispose; - signals [FONT_CHANGED] = - g_signal_new ("font_changed", + signals [BACKEND_CHANGED] = + g_signal_new ("backend-changed", G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_FIRST, 0, @@ -161,7 +134,7 @@ 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); @@ -173,7 +146,7 @@ psppire_data_store_get_value_count (const PsppireDataStore *store) return psppire_dict_get_value_cnt (store->dict); } -inline casenumber +casenumber psppire_data_store_get_case_count_wrapper (const GSheetModel *model) { const PsppireDataStore *store = PSPPIRE_DATA_STORE (model); @@ -185,19 +158,9 @@ psppire_data_store_init (PsppireDataStore *data_store) { data_store->dict = 0; data_store->case_file = NULL; - data_store->width_of_m = 10; data_store->dispose_has_run = FALSE; } -const PangoFontDescription * -psppire_data_store_get_font_desc (const GSheetModel *model, - glong row, glong column) -{ - PsppireDataStore *store = PSPPIRE_DATA_STORE (model); - - return store->font_desc; -} - static inline gchar * psppire_data_store_get_string_wrapper (const GSheetModel *model, glong row, glong column) @@ -217,6 +180,14 @@ 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_row_button_label (const GSheetModel *model, gint row); +static gboolean get_row_sensitivity (const GSheetModel *model, gint row); + static void psppire_data_store_sheet_model_init (GSheetModelIface *iface) @@ -226,21 +197,20 @@ psppire_data_store_sheet_model_init (GSheetModelIface *iface) iface->set_string = psppire_data_store_set_string_wrapper; iface->clear_datum = psppire_data_store_clear_datum; iface->is_editable = NULL; - iface->is_visible = NULL; iface->get_foreground = NULL; iface->get_background = NULL; - iface->get_font_desc = psppire_data_store_get_font_desc; 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; + iface->get_row_title = get_row_button_label; + iface->get_row_sensitivity = get_row_sensitivity; +} static void delete_cases_callback (GtkWidget *w, @@ -261,11 +231,11 @@ delete_cases_callback (GtkWidget *w, static void insert_case_callback (GtkWidget *w, casenumber casenum, gpointer data) { - PsppireDataStore *store ; + PsppireDataStore *store = PSPPIRE_DATA_STORE (data); g_return_if_fail (data); - store = PSPPIRE_DATA_STORE (data); + g_print ("%s\n", __FUNCTION__); g_sheet_model_range_changed (G_SHEET_MODEL (store), casenum, -1, @@ -300,10 +270,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 } @@ -312,6 +284,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); @@ -319,6 +292,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 @@ -347,8 +321,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); } @@ -398,8 +374,6 @@ psppire_data_store_set_case_file (PsppireDataStore *ds, { gint i; if ( ds->case_file) g_object_unref (ds->case_file); - - ds->case_file = cf; g_sheet_model_range_changed (G_SHEET_MODEL (ds), @@ -437,6 +411,8 @@ psppire_data_store_set_case_file (PsppireDataStore *ds, g_signal_connect (ds->case_file, "case-changed", G_CALLBACK (changed_case_callback), ds); + + g_signal_emit (ds, signals[BACKEND_CHANGED], 0); } @@ -492,8 +468,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 ) @@ -696,24 +673,6 @@ psppire_data_store_set_string (PsppireDataStore *store, } -void -psppire_data_store_set_font (PsppireDataStore *store, - const PangoFontDescription *fd) -{ - g_return_if_fail (store); - g_return_if_fail (PSPPIRE_IS_DATA_STORE (store)); - - store->font_desc = fd; -#if 0 - store->width_of_m = calc_m_width (fd); -#endif - g_signal_emit (store, signals [FONT_CHANGED], 0); - - - g_sheet_model_range_changed (G_SHEET_MODEL (store), - -1, -1, -1, -1); -} - void psppire_data_store_show_labels (PsppireDataStore *store, gboolean show_labels) @@ -767,94 +726,54 @@ psppire_data_store_get_reader (PsppireDataStore *ds) /* Column related funcs */ -static glong -geometry_get_column_count (const GSheetColumn *geom) -{ - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - return MAX (MIN_COLUMNS, psppire_dict_get_var_cnt (ds->dict)); -} +static const gchar null_var_name[]=N_("var"); + +/* Row related funcs */ -static gint -geometry_get_width (const GSheetColumn *geom, glong unit) +static gchar * +get_row_button_label (const GSheetModel *model, gint unit) { - const struct variable *pv ; - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - if ( unit >= psppire_dict_get_var_cnt (ds->dict) ) - return ds->width_of_m * 8 ; - - pv = psppire_dict_get_variable (ds->dict, unit); - - if ( pv == NULL ) - return ds->width_of_m * 8 ; + gchar *text; + gchar *s; + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); - return ds->width_of_m * var_get_display_width (pv); -} + s = g_strdup_printf (_("%d"), unit + 1); -static void -geometry_set_width (GSheetColumn *geom, glong unit, gint width) -{ - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); + text = pspp_locale_to_utf8 (s, -1, 0); - struct variable *pv = psppire_dict_get_variable (ds->dict, unit); + g_free (s); - var_set_display_width (pv, width / ds->width_of_m ); + return text; } - -static GtkJustification -geometry_get_justification (const GSheetColumn *geom, glong unit) +static gboolean +get_row_sensitivity (const GSheetModel *model, gint unit) { - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - const struct variable *pv ; - + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); - 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); + return (unit < psppire_case_file_get_case_count (ds->case_file)); } -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; -} + +/* Column related stuff */ static gchar * -geometry_get_column_subtitle (const GSheetColumn *geom, glong unit) +get_column_subtitle (const GSheetModel *model, gint col) { gchar *text; const struct variable *v ; - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); - if ( unit >= psppire_dict_get_var_cnt (ds->dict) ) + if ( col >= psppire_dict_get_var_cnt (ds->dict) ) return NULL; - v = psppire_dict_get_variable (ds->dict, unit); + v = psppire_dict_get_variable (ds->dict, col); if ( ! var_has_label (v)) return NULL; @@ -864,106 +783,47 @@ geometry_get_column_subtitle (const GSheetColumn *geom, glong unit) 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)); -} - - -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; -} - - -/* Row related funcs */ - -static glong -geometry_get_row_count (const GSheetRow *geom) -{ - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - return TRAILING_ROWS + psppire_case_file_get_case_count (ds->case_file); -} - -#define ROW_HEIGHT 25 - -static gint -geometry_get_height (const GSheetRow *geom, glong unit) +static gchar * +get_column_button_label (const GSheetModel *model, gint col) { - return ROW_HEIGHT; -} + gchar *text; + struct variable *pv ; + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); -static guint -geometry_get_top_ypixel (const GSheetRow *geo, glong row) -{ - return row * ROW_HEIGHT; -} + if ( col >= psppire_dict_get_var_cnt (ds->dict) ) + return g_locale_to_utf8 (null_var_name, -1, 0, 0, 0); -static glong -geometry_pixel_to_row (const GSheetRow *geo, guint pixel) -{ - glong row = pixel / ROW_HEIGHT; + pv = psppire_dict_get_variable (ds->dict, col); - if (row >= geometry_get_row_count (geo)) - row = geometry_get_row_count (geo) - 1; + text = pspp_locale_to_utf8 (var_get_name (pv), -1, 0); - return row; + return text; } - static gboolean -geometry_get_row_sensitivity (const GSheetRow *geom, glong unit) +get_column_sensitivity (const GSheetModel *model, gint col) { - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); - - return (unit < psppire_case_file_get_case_count (ds->case_file)); + return (col < psppire_dict_get_var_cnt (ds->dict)); } -static gchar * -geometry_get_row_button_label (const GSheetRow *geom, glong unit) -{ - gchar *text; - gchar *s; - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - if ( unit > - TRAILING_ROWS + psppire_case_file_get_case_count (ds->case_file)) - return 0; - s = g_strdup_printf (_("%ld"), unit + FIRST_CASE_NUMBER); +static GtkJustification +get_column_justification (const GSheetModel *model, gint col) +{ + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); + const struct variable *pv ; - text = pspp_locale_to_utf8 (s, -1, 0); + if ( col >= psppire_dict_get_var_cnt (ds->dict) ) + return GTK_JUSTIFY_LEFT; - g_free (s); + pv = psppire_dict_get_variable (ds->dict, col); - return text; + return (var_get_alignment (pv) == ALIGN_LEFT ? GTK_JUSTIFY_LEFT + : var_get_alignment (pv) == ALIGN_RIGHT ? GTK_JUSTIFY_RIGHT + : GTK_JUSTIFY_CENTER); } -static void -psppire_data_store_sheet_row_init (GSheetRowIface *iface) -{ - iface->get_row_count = geometry_get_row_count; - 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; -}