2 PSPPIRE --- A Graphical User Interface for PSPP
3 Copyright (C) 2006 Free Software Foundation
4 Written by John Darrington
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "psppire-object.h"
26 #include "psppire-case-file.h"
28 #include <gtksheet/gtkextra-marshal.h>
30 #include <data/case.h>
31 #include <data/casefile.h>
32 #include <data/data-in.h>
34 /* --- prototypes --- */
35 static void psppire_case_file_class_init (PsppireCaseFileClass *class);
36 static void psppire_case_file_init (PsppireCaseFile *case_file);
37 static void psppire_case_file_finalize (GObject *object);
40 /* --- variables --- */
41 static GObjectClass *parent_class = NULL;
48 static guint signal[n_SIGNALS];
51 /* --- functions --- */
53 * psppire_case_file_get_type:
54 * @returns: the type ID for accelerator groups.
57 psppire_case_file_get_type (void)
59 static GType object_type = 0;
63 static const GTypeInfo object_info = {
64 sizeof (PsppireCaseFileClass),
66 (GBaseFinalizeFunc) NULL,
67 (GClassInitFunc) psppire_case_file_class_init,
68 NULL, /* class_finalize */
69 NULL, /* class_data */
70 sizeof (PsppireCaseFile),
72 (GInstanceInitFunc) psppire_case_file_init,
75 object_type = g_type_register_static (G_TYPE_PSPPIRE_OBJECT, "PsppireCaseFile",
84 psppire_case_file_class_init (PsppireCaseFileClass *class)
86 GObjectClass *object_class = G_OBJECT_CLASS (class);
88 parent_class = g_type_class_peek_parent (class);
90 object_class->finalize = psppire_case_file_finalize;
92 signal[CASE_CHANGED] =
93 g_signal_new ("case_changed",
94 G_TYPE_FROM_CLASS(class),
98 g_cclosure_marshal_VOID__INT,
104 signal[CASE_INSERTED] =
105 g_signal_new ("case_inserted",
106 G_TYPE_FROM_CLASS(class),
110 g_cclosure_marshal_VOID__INT,
116 signal[CASES_DELETED] =
117 g_signal_new ("cases_deleted",
118 G_TYPE_FROM_CLASS(class),
122 gtkextra_VOID__INT_INT,
125 G_TYPE_INT, G_TYPE_INT);
129 psppire_case_file_finalize (GObject *object)
131 PsppireCaseFile *cf = PSPPIRE_CASE_FILE (object);
134 casefile_destroy(cf->casefile);
136 G_OBJECT_CLASS (parent_class)->finalize (object);
140 psppire_case_file_init (PsppireCaseFile *cf)
146 * psppire_case_file_new:
147 * @returns: a new #PsppireCaseFile object
149 * Creates a new #PsppireCaseFile.
152 psppire_case_file_new (gint var_cnt)
154 PsppireCaseFile *cf = g_object_new (G_TYPE_PSPPIRE_CASE_FILE, NULL);
156 cf->casefile = casefile_create(var_cnt);
163 /* Append a case to the case file */
165 psppire_case_file_append_case(PsppireCaseFile *cf,
171 g_return_val_if_fail(cf, FALSE);
172 g_return_val_if_fail(cf->casefile, FALSE);
174 posn = casefile_get_case_cnt(cf->casefile);
176 result = casefile_append(cf->casefile, c);
178 g_signal_emit(cf, signal[CASE_INSERTED], 0, posn);
185 psppire_case_file_get_case_count(const PsppireCaseFile *cf)
187 g_return_val_if_fail(cf, FALSE);
192 return casefile_get_case_cnt(cf->casefile);
195 /* Return the IDXth value from case CASENUM.
196 The return value must not be freed or written to
199 psppire_case_file_get_value(const PsppireCaseFile *cf, gint casenum, gint idx)
201 const union value *v;
203 struct casereader *reader = casefile_get_random_reader (cf->casefile);
205 casereader_seek(reader, casenum);
207 casereader_read(reader, &c);
209 v = case_data(&c, idx);
210 casereader_destroy(reader);
217 psppire_case_file_clear(PsppireCaseFile *cf)
219 casefile_destroy(cf->casefile);
221 g_signal_emit(cf, signal[CASES_DELETED], 0, 0, -1);
224 /* Set the IDXth value of case C using FF and DATA */
226 psppire_case_file_set_value(PsppireCaseFile *cf, gint casenum, gint idx,
227 struct data_in *d_in)
231 struct casereader *reader = casefile_get_random_reader (cf->casefile);
233 casereader_seek(reader, casenum);
234 casereader_read(reader, &cc);
236 /* Cast away const in flagrant abuse of the casefile */
237 d_in->v = (union value *) case_data(&cc, idx);
239 if ( ! data_in(d_in) )
240 g_warning("Cant set value\n");
243 casereader_destroy(reader);
245 g_signal_emit(cf, signal[CASE_CHANGED], 0, casenum);