X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fpsppire-data-store.c;h=eeaf31d660548dd7922295a2dae1f25615babfb9;hb=c2ccb0d20912f25021d9a6c24d9c2de1b81b87bf;hp=6c82a30bb5020e82cf90f09b53a932f9c3af206e;hpb=57b436a22d9ae0e395fb2e3ce101c2b5c2e6939e;p=pspp-builds.git diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 6c82a30b..eeaf31d6 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -33,8 +33,11 @@ #include #include +#include + #include "psppire-variable.h" #include "psppire-data-store.h" +#include "psppire-case-file.h" #include "helper.h" #include @@ -70,6 +73,13 @@ static gboolean psppire_data_store_clear_datum(GSheetModel *model, static GObjectClass *parent_class = NULL; + +enum {FONT_CHANGED, + n_SIGNALS}; + +static guint signal[n_SIGNALS]; + + inline GType psppire_data_store_get_type (void) { @@ -131,6 +141,7 @@ psppire_data_store_get_type (void) return data_store_type; } + static void psppire_data_store_class_init (PsppireDataStoreClass *class) { @@ -140,6 +151,16 @@ psppire_data_store_class_init (PsppireDataStoreClass *class) object_class = (GObjectClass*) class; object_class->finalize = psppire_data_store_finalize; + + signal[FONT_CHANGED] = + g_signal_new ("font_changed", + G_TYPE_FROM_CLASS(class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); } @@ -166,6 +187,7 @@ psppire_data_store_init (PsppireDataStore *data_store) { data_store->dict = 0; data_store->case_file = 0; + data_store->width_of_m = 10; } const PangoFontDescription * @@ -305,9 +327,6 @@ dict_size_change_callback(GObject *obj, store = PSPPIRE_DATA_STORE(data); - /* - if ( adjustment > 0 ) - */ psppire_case_file_insert_values (store->case_file, adjustment, posn); } @@ -401,8 +420,43 @@ psppire_data_store_finalize (GObject *object) } + +/* Insert a blank case before POSN */ +gboolean +psppire_data_store_insert_new_case(PsppireDataStore *ds, gint posn) +{ + gboolean result; + gint val_cnt, v; + struct ccase cc; + g_return_val_if_fail (ds, FALSE); + + + /* Opportunity for optimisation exists here when creating a blank case */ + val_cnt = casefile_get_value_cnt(ds->case_file->flexifile) ; + + case_create (&cc, val_cnt); + + memset ( case_data_rw (&cc, 0), 0, val_cnt * MAX_SHORT_STRING); + + for (v = 0 ; v < psppire_dict_get_var_cnt (ds->dict) ; ++v) + { + const struct PsppireVariable *pv = psppire_dict_get_variable(ds->dict, v); + if (ALPHA == psppire_variable_get_type(pv) ) + continue; + + case_data_rw (&cc, psppire_variable_get_fv (pv))->f = SYSMIS; + } + + result = psppire_case_file_insert_case (ds->case_file, &cc, posn); + + case_destroy (&cc); + + return result; +} + + static gchar * -psppire_data_store_get_string(const GSheetModel *model, gint row, gint column) +psppire_data_store_get_string (const GSheetModel *model, gint row, gint column) { gint idx; char *text; @@ -412,26 +466,26 @@ psppire_data_store_get_string(const GSheetModel *model, gint row, gint column) GString *s; PsppireDataStore *store = PSPPIRE_DATA_STORE(model); - g_return_val_if_fail(store->dict, NULL); - g_return_val_if_fail(store->case_file, NULL); + g_return_val_if_fail (store->dict, NULL); + g_return_val_if_fail (store->case_file, NULL); - if (column >= psppire_dict_get_var_cnt(store->dict)) + if (column >= psppire_dict_get_var_cnt (store->dict)) return NULL; - if ( row >= psppire_case_file_get_case_count(store->case_file)) + if ( row >= psppire_case_file_get_case_count (store->case_file)) return NULL; - pv = psppire_dict_get_variable(store->dict, column); + pv = psppire_dict_get_variable (store->dict, column); - idx = psppire_variable_get_fv(pv); + idx = psppire_variable_get_fv (pv); - v = psppire_case_file_get_value(store->case_file, row, idx); + v = psppire_case_file_get_value (store->case_file, row, idx); g_return_val_if_fail(v, NULL); if ( store->show_labels) { - const struct val_labs * vl = psppire_variable_get_value_labels(pv); + const struct val_labs * vl = psppire_variable_get_value_labels (pv); const gchar *label; if ( (label = val_labs_find(vl, *v)) ) @@ -440,29 +494,31 @@ psppire_data_store_get_string(const GSheetModel *model, gint row, gint column) } } - fp = psppire_variable_get_write_spec(pv); + fp = psppire_variable_get_write_spec (pv); s = g_string_sized_new (fp->w + 1); - g_string_set_size(s, fp->w); + g_string_set_size (s, fp->w); - memset(s->str, 0, fp->w); + memset (s->str, 0, fp->w); - g_assert(fp->w == s->len); + 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); - text = pspp_locale_to_utf8(s->str, fp->w, 0); - g_string_free(s, TRUE); + text = pspp_locale_to_utf8 (s->str, fp->w, 0); + g_string_free (s, TRUE); + + g_strchomp (text); return text; } static gboolean -psppire_data_store_clear_datum(GSheetModel *model, +psppire_data_store_clear_datum (GSheetModel *model, gint row, gint col) { @@ -531,12 +587,19 @@ psppire_data_store_set_string(GSheetModel *model, void -psppire_data_store_set_font(PsppireDataStore *store, PangoFontDescription *fd) +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, signal[FONT_CHANGED], 0); + + g_sheet_model_range_changed (G_SHEET_MODEL(store), -1, -1, -1, -1); } @@ -556,10 +619,13 @@ psppire_data_store_show_labels(PsppireDataStore *store, gboolean show_labels) +/* FIXME: There's no reason to actually have this function. + It should be done by a procedure */ void psppire_data_store_create_system_file(PsppireDataStore *store, struct file_handle *handle) { + gint i, var_cnt; const struct sfm_write_options wo = { true, /* writeable */ false, /* dont compress */ @@ -575,9 +641,19 @@ psppire_data_store_create_system_file(PsppireDataStore *store, if ( ! writer) return; -#if 0 - psppire_case_array_iterate_case(store->cases, write_case, writer); -#endif + + var_cnt = psppire_data_store_get_var_count (G_SHEET_MODEL(store)); + + for (i = 0 ; i < psppire_case_file_get_case_count(store->case_file); ++i ) + { + struct ccase c; + + case_create (&c, var_cnt); + psppire_case_file_get_case (store->case_file, i, &c); + sfm_write_case (writer, &c); + + case_destroy (&c); + } sfm_close_writer(writer); } @@ -598,84 +674,46 @@ psppire_data_store_clear(PsppireDataStore *data_store) /* Column related funcs */ static gint -geometry_get_column_count(const GSheetColumn *geom, gpointer data) +geometry_get_column_count(const GSheetColumn *geom) { PsppireDataStore *ds = PSPPIRE_DATA_STORE(geom); return MAX(MIN_COLUMNS, psppire_dict_get_var_cnt(ds->dict)); } -/* Return the width that an 'M' character would occupy when typeset at - row, col */ -static guint -M_width(const GtkSheet *sheet, gint row, gint col) -{ - GtkSheetCellAttr attributes; - PangoRectangle rect; - /* 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); - - pango_layout_get_extents (layout, NULL, &rect); - -#if 0 - g_object_unref(G_OBJECT(layout)); -#endif - - return PANGO_PIXELS(rect.width); -} - - -/* Return the number of pixels corresponding to a column of - WIDTH characters */ -static inline guint -columnWidthToPixels(GtkSheet *sheet, gint column, guint width) -{ - return (M_width(sheet, 0, column) * width); -} static gint -geometry_get_width(const GSheetColumn *geom, gint unit, GtkSheet *sheet) +geometry_get_width(const GSheetColumn *geom, gint unit) { const struct PsppireVariable *pv ; PsppireDataStore *ds = PSPPIRE_DATA_STORE(geom); if ( unit >= psppire_dict_get_var_cnt(ds->dict) ) - return 75; + return ds->width_of_m * 8 ; - /* FIXME: We can optimise this by caching the widths until they're resized */ pv = psppire_dict_get_variable(ds->dict, unit); - return columnWidthToPixels(sheet, unit, psppire_variable_get_columns(pv)); -} - - + if ( pv == NULL ) + return ds->width_of_m * 8 ; + return ds->width_of_m * psppire_variable_get_columns(pv); +} static void -geometry_set_width(GSheetColumn *geom, gint unit, gint width, GtkSheet *sheet) +geometry_set_width(GSheetColumn *geom, gint unit, gint width) { PsppireDataStore *ds = PSPPIRE_DATA_STORE(geom); struct PsppireVariable *pv = psppire_dict_get_variable(ds->dict, unit); - psppire_variable_set_columns(pv, width / M_width(sheet, 1, unit)); + psppire_variable_set_columns(pv, width / ds->width_of_m ); } static GtkJustification -geometry_get_justification(const GSheetColumn *geom, gint unit, gpointer data) +geometry_get_justification(const GSheetColumn *geom, gint unit) { PsppireDataStore *ds = PSPPIRE_DATA_STORE(geom); const struct PsppireVariable *pv ; @@ -695,8 +733,7 @@ geometry_get_justification(const GSheetColumn *geom, gint unit, gpointer data) static const gchar null_var_name[]=N_("var"); static gchar * -geometry_get_column_button_label(const GSheetColumn *geom, gint unit, - gpointer data) +geometry_get_column_button_label(const GSheetColumn *geom, gint unit) { gchar *text; struct PsppireVariable *pv ; @@ -714,11 +751,10 @@ geometry_get_column_button_label(const GSheetColumn *geom, gint unit, static gboolean -geometry_get_sensitivity(const GSheetColumn *geom, gint unit, gpointer data) +geometry_get_sensitivity(const GSheetColumn *geom, gint unit) { PsppireDataStore *ds = PSPPIRE_DATA_STORE(geom); - return (unit < psppire_dict_get_var_cnt(ds->dict)); } @@ -732,7 +768,6 @@ psppire_data_store_sheet_column_init (GSheetColumnIface *iface) 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; } @@ -798,7 +833,3 @@ psppire_data_store_sheet_row_init (GSheetRowIface *iface) iface->get_button_label = geometry_get_row_button_label; } - - - -