X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-data-store.c;h=c223ccf2a469684854cc87d87594110acd5fc6eb;hb=02c766f3f1ff964f0d4fa4849f1a55e193afa48d;hp=d0a346170bc49ecb215038c625e5684093456b31;hpb=92c09e564002d356d20fc1e2e131027ef89f6748;p=pspp-builds.git
diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c
index d0a34617..c223ccf2 100644
--- a/src/ui/gui/psppire-data-store.c
+++ b/src/ui/gui/psppire-data-store.c
@@ -1,11 +1,9 @@
-/* psppire-data-store.c
-
- PSPPIRE --- A Graphical User Interface for PSPP
+/* PSPPIRE - a graphical user interface for PSPP.
Copyright (C) 2006 Free Software Foundation
- This program is free software; you can redistribute it and/or modify
+ 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
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@@ -14,9 +12,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ along with this program. If not, see . */
#include
#include
@@ -25,7 +21,6 @@
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
-#include
#include
#include
#include
@@ -45,10 +40,6 @@
#include
#include
-#include
-#include
-
-
static void psppire_data_store_init (PsppireDataStore *data_store);
static void psppire_data_store_class_init (PsppireDataStoreClass *class);
@@ -58,13 +49,8 @@ static void psppire_data_store_sheet_row_init (GSheetRowIface *iface);
static void psppire_data_store_finalize (GObject *object);
-static gchar *psppire_data_store_get_string (const GSheetModel *sheet_model, gint row, gint column);
-
-static gboolean psppire_data_store_set_string (GSheetModel *model,
- const gchar *text, gint row, gint column);
-
static gboolean psppire_data_store_clear_datum (GSheetModel *model,
- gint row, gint column);
+ glong row, glong column);
#define MIN_COLUMNS 10
@@ -165,7 +151,7 @@ psppire_data_store_class_init (PsppireDataStoreClass *class)
-static gint
+static glong
psppire_data_store_get_var_count (const GSheetModel *model)
{
const PsppireDataStore *store = PSPPIRE_DATA_STORE (model);
@@ -173,15 +159,20 @@ psppire_data_store_get_var_count (const GSheetModel *model)
return psppire_dict_get_var_cnt (store->dict);
}
-static gint
-psppire_data_store_get_case_count (const GSheetModel *model)
+casenumber
+psppire_data_store_get_case_count (PsppireDataStore *store)
+{
+ return psppire_case_file_get_case_count (store->case_file);
+}
+
+static glong
+psppire_data_store_get_case_count_from_model (const GSheetModel *model)
{
const PsppireDataStore *store = PSPPIRE_DATA_STORE (model);
return psppire_case_file_get_case_count (store->case_file);
}
-
static void
psppire_data_store_init (PsppireDataStore *data_store)
{
@@ -192,20 +183,39 @@ psppire_data_store_init (PsppireDataStore *data_store)
const PangoFontDescription *
psppire_data_store_get_font_desc (const GSheetModel *model,
- gint row, gint column)
+ 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)
+{
+ return psppire_data_store_get_string (PSPPIRE_DATA_STORE (model), row, column);
+}
+
+
+static inline gboolean
+psppire_data_store_set_string_wrapper (GSheetModel *model,
+ const gchar *text,
+ glong row, glong column)
+{
+ return psppire_data_store_set_string (PSPPIRE_DATA_STORE (model), text,
+ row, column);
+}
+
+
+
static void
psppire_data_store_sheet_model_init (GSheetModelIface *iface)
{
iface->free_strings = TRUE;
- iface->get_string = psppire_data_store_get_string;
- iface->set_string = psppire_data_store_set_string;
+ iface->get_string = psppire_data_store_get_string_wrapper;
+ 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;
@@ -214,7 +224,7 @@ psppire_data_store_sheet_model_init (GSheetModelIface *iface)
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;
+ iface->get_row_count = psppire_data_store_get_case_count_from_model;
}
static
@@ -225,7 +235,8 @@ gboolean always_true ()
static void
-delete_cases_callback (GtkWidget *w, gint first, gint n_cases, gpointer data)
+delete_cases_callback (GtkWidget *w,
+ casenumber first, casenumber n_cases, gpointer data)
{
PsppireDataStore *store ;
@@ -240,7 +251,7 @@ delete_cases_callback (GtkWidget *w, gint first, gint n_cases, gpointer data)
static void
-insert_case_callback (GtkWidget *w, gint casenum, gpointer data)
+insert_case_callback (GtkWidget *w, casenumber casenum, gpointer data)
{
PsppireDataStore *store ;
@@ -373,29 +384,16 @@ psppire_data_store_new (PsppireDict *dict)
}
-
-/**
- * psppire_data_store_replace_set_dictionary:
- * @data_store: The variable store
- * @dict: The dictionary to set
- *
- * If a dictionary is already associated with the data-store, then it will be
- * destroyed.
- **/
void
-psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *dict)
+psppire_data_store_set_case_file (PsppireDataStore *data_store,
+ PsppireCaseFile *cf)
{
- data_store->dict = dict;
-
if ( data_store->case_file)
{
g_object_unref (data_store->case_file);
- data_store->case_file = 0;
}
- data_store->case_file = psppire_case_file_new ();
-
-
+ data_store->case_file = cf;
g_signal_connect (data_store->case_file, "cases-deleted",
G_CALLBACK (delete_cases_callback),
@@ -409,6 +407,22 @@ psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *di
g_signal_connect (data_store->case_file, "case-changed",
G_CALLBACK (changed_case_callback),
data_store);
+}
+
+
+
+/**
+ * psppire_data_store_replace_set_dictionary:
+ * @data_store: The variable store
+ * @dict: The dictionary to set
+ *
+ * If a dictionary is already associated with the data-store, then it will be
+ * destroyed.
+ **/
+void
+psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *dict)
+{
+ data_store->dict = dict;
g_signal_connect (dict, "variable-inserted",
G_CALLBACK (insert_variable_callback),
@@ -445,17 +459,17 @@ psppire_data_store_finalize (GObject *object)
/* Insert a blank case before POSN */
gboolean
-psppire_data_store_insert_new_case (PsppireDataStore *ds, gint posn)
+psppire_data_store_insert_new_case (PsppireDataStore *ds, casenumber 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 = datasheet_get_column_cnt (ds->case_file->datasheet) ;
+ g_return_val_if_fail (val_cnt > 0, FALSE);
+
case_create (&cc, val_cnt);
memset ( case_data_rw_idx (&cc, 0), 0, val_cnt * MAX_SHORT_STRING);
@@ -477,8 +491,8 @@ psppire_data_store_insert_new_case (PsppireDataStore *ds, gint posn)
}
-static gchar *
-psppire_data_store_get_string (const GSheetModel *model, gint row, gint column)
+gchar *
+psppire_data_store_get_string (PsppireDataStore *store, glong row, glong column)
{
gint idx;
char *text;
@@ -486,7 +500,6 @@ psppire_data_store_get_string (const GSheetModel *model, gint row, gint column)
const struct variable *pv ;
union value *v ;
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);
@@ -507,7 +520,7 @@ psppire_data_store_get_string (const GSheetModel *model, gint row, gint column)
v = psppire_case_file_get_value (store->case_file, row, idx, NULL,
var_get_width (pv));
-
+
g_return_val_if_fail (v, NULL);
if ( store->show_labels)
@@ -546,8 +559,7 @@ psppire_data_store_get_string (const GSheetModel *model, gint row, gint column)
static gboolean
psppire_data_store_clear_datum (GSheetModel *model,
- gint row, gint col)
-
+ glong row, glong col)
{
PsppireDataStore *store = PSPPIRE_DATA_STORE (model);
@@ -572,12 +584,10 @@ psppire_data_store_clear_datum (GSheetModel *model,
to ROW, COL with the value TEXT.
Returns true if anything was updated, false otherwise.
*/
-static gboolean
-psppire_data_store_set_string (GSheetModel *model,
- const gchar *text, gint row, gint col)
+gboolean
+psppire_data_store_set_string (PsppireDataStore *store,
+ const gchar *text, glong row, glong col)
{
- PsppireDataStore *store = PSPPIRE_DATA_STORE (model);
-
const struct variable *pv = psppire_dict_get_variable (store->dict, col);
g_return_val_if_fail (pv, FALSE);
@@ -636,57 +646,32 @@ 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)
+psppire_data_store_clear (PsppireDataStore *data_store)
{
- gint i, var_cnt;
- const struct sfm_write_options wo = {
- true, /* writeable */
- false, /* dont compress */
- 3 /* version */
- };
-
- struct casewriter *writer;
-
- g_assert (handle);
-
- writer = sfm_open_writer (handle, store->dict->dict, wo);
-
- if ( ! writer)
- return;
-
-
- var_cnt = psppire_data_store_get_var_count (G_SHEET_MODEL (store));
+ psppire_case_file_clear (data_store->case_file);
- for (i = 0 ; i < psppire_case_file_get_case_count (store->case_file); ++i )
- {
- struct ccase c;
- psppire_case_file_get_case (store->case_file, i, &c);
- casewriter_write (writer, &c);
- }
- casewriter_destroy (writer);
+ psppire_dict_clear (data_store->dict);
}
-void
-psppire_data_store_clear (PsppireDataStore *data_store)
+/* Return a casereader made from this datastore */
+struct casereader *
+psppire_data_store_get_reader (PsppireDataStore *ds)
{
- psppire_case_file_clear (data_store->case_file);
+ struct casereader *reader ;
- psppire_dict_clear (data_store->dict);
-}
+ reader = psppire_case_file_make_reader (ds->case_file);
+ return reader;
+}
/* Column related funcs */
-static gint
+static glong
geometry_get_column_count (const GSheetColumn *geom)
{
PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom);
@@ -697,7 +682,7 @@ geometry_get_column_count (const GSheetColumn *geom)
static gint
-geometry_get_width (const GSheetColumn *geom, gint unit)
+geometry_get_width (const GSheetColumn *geom, glong unit)
{
const struct variable *pv ;
PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom);
@@ -714,7 +699,7 @@ geometry_get_width (const GSheetColumn *geom, gint unit)
}
static void
-geometry_set_width (GSheetColumn *geom, gint unit, gint width)
+geometry_set_width (GSheetColumn *geom, glong unit, gint width)
{
PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom);
@@ -726,7 +711,7 @@ geometry_set_width (GSheetColumn *geom, gint unit, gint width)
static GtkJustification
-geometry_get_justification (const GSheetColumn *geom, gint unit)
+geometry_get_justification (const GSheetColumn *geom, glong unit)
{
PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom);
const struct variable *pv ;
@@ -746,7 +731,7 @@ geometry_get_justification (const GSheetColumn *geom, gint unit)
static const gchar null_var_name[]=N_("var");
static gchar *
-geometry_get_column_button_label (const GSheetColumn *geom, gint unit)
+geometry_get_column_button_label (const GSheetColumn *geom, glong unit)
{
gchar *text;
struct variable *pv ;
@@ -763,8 +748,29 @@ geometry_get_column_button_label (const GSheetColumn *geom, gint unit)
}
+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, gint unit)
+geometry_get_sensitivity (const GSheetColumn *geom, glong unit)
{
PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom);
@@ -782,12 +788,13 @@ psppire_data_store_sheet_column_init (GSheetColumnIface *iface)
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 gint
+static glong
geometry_get_row_count (const GSheetRow *geom, gpointer data)
{
PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom);
@@ -797,14 +804,14 @@ geometry_get_row_count (const GSheetRow *geom, gpointer data)
static gint
-geometry_get_height (const GSheetRow *geom, gint unit, gpointer data)
+geometry_get_height (const GSheetRow *geom, glong unit, gpointer data)
{
return 25;
}
static gboolean
-geometry_get_row_sensitivity (const GSheetRow *geom, gint unit, gpointer data)
+geometry_get_row_sensitivity (const GSheetRow *geom, glong unit, gpointer data)
{
PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom);
@@ -814,7 +821,7 @@ geometry_get_row_sensitivity (const GSheetRow *geom, gint unit, gpointer data)
static gchar *
-geometry_get_row_button_label (const GSheetRow *geom, gint unit, gpointer data)
+geometry_get_row_button_label (const GSheetRow *geom, glong unit, gpointer data)
{
gchar *text;
gchar *s;
@@ -824,7 +831,7 @@ geometry_get_row_button_label (const GSheetRow *geom, gint unit, gpointer data)
TRAILING_ROWS + psppire_case_file_get_case_count (ds->case_file))
return 0;
- s = g_strdup_printf (_("%d"), unit);
+ s = g_strdup_printf (_("%ld"), unit + FIRST_CASE_NUMBER);
text = pspp_locale_to_utf8 (s, -1, 0);
@@ -846,4 +853,3 @@ psppire_data_store_sheet_row_init (GSheetRowIface *iface)
iface->get_button_label = geometry_get_row_button_label;
}
-