Added popup menus to column and row title areas in datasheet.
[pspp-builds.git] / src / ui / gui / psppire-case-file.c
index 215eecc51802be034fea0f7dfb50f4e99be65ca2..a44309eed8c67fb14a68bb3e818194d1f8684bc3 100644 (file)
@@ -1,21 +1,18 @@
-/*
-    PSPPIRE --- A Graphical User Interface for PSPP
-    Copyright (C) 2006  Free Software Foundation
+/* 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
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
+   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 3 of the License, or
+   (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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. */
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <config.h>
 #include <string.h>
@@ -167,14 +164,17 @@ psppire_case_file_new (const struct casereader *reader)
 
 
 gboolean
-psppire_case_file_delete_cases (PsppireCaseFile *cf, gint n_cases, gint first)
+psppire_case_file_delete_cases (PsppireCaseFile *cf, casenumber n_cases, casenumber first)
 {
   g_return_val_if_fail (cf, FALSE);
   g_return_val_if_fail (cf->datasheet, FALSE);
 
+  g_return_val_if_fail (first + n_cases <=
+                       psppire_case_file_get_case_count (cf), FALSE);
+
   datasheet_delete_rows (cf->datasheet, first, n_cases);
 
-  g_signal_emit (cf, signals [CASES_DELETED], 0, n_cases, first);
+  g_signal_emit (cf, signals [CASES_DELETED], 0, first, n_cases);
 
   return TRUE;
 }
@@ -182,8 +182,8 @@ psppire_case_file_delete_cases (PsppireCaseFile *cf, gint n_cases, gint first)
 /* Insert case CC into the case file before POSN */
 gboolean
 psppire_case_file_insert_case (PsppireCaseFile *cf,
-                             struct ccase *cc,
-                             gint posn)
+                              struct ccase *cc,
+                              casenumber posn)
 {
   struct ccase tmp;
   bool result ;
@@ -197,7 +197,7 @@ psppire_case_file_insert_case (PsppireCaseFile *cf,
   if ( result )
     g_signal_emit (cf, signals [CASE_INSERTED], 0, posn);
   else
-    g_warning ("Cannot insert case at position %d\n", posn);
+    g_warning ("Cannot insert case at position %ld\n", posn);
 
   return result;
 }
@@ -226,7 +226,7 @@ psppire_case_file_append_case (PsppireCaseFile *cf,
 }
 
 
-inline gint
+inline casenumber
 psppire_case_file_get_case_count (const PsppireCaseFile *cf)
 {
   g_return_val_if_fail (cf, FALSE);
@@ -280,7 +280,7 @@ psppire_case_file_clear (PsppireCaseFile *cf)
 /* Set the IDXth value of case C to V.
    Returns true if successful, false on I/O error. */
 gboolean
-psppire_case_file_set_value (PsppireCaseFile *cf, gint casenum, gint idx,
+psppire_case_file_set_value (PsppireCaseFile *cf, casenumber casenum, gint idx,
                            union value *v, gint width)
 {
   bool ok;
@@ -300,7 +300,7 @@ psppire_case_file_set_value (PsppireCaseFile *cf, gint casenum, gint idx,
 
 /* Set the IDXth value of case C using D_IN */
 gboolean
-psppire_case_file_data_in (PsppireCaseFile *cf, gint casenum, gint idx,
+psppire_case_file_data_in (PsppireCaseFile *cf, casenumber casenum, gint idx,
                           struct substring input, const struct fmt_spec *fmt)
 {
   union value *value;
@@ -344,30 +344,38 @@ psppire_case_file_sort (PsppireCaseFile *cf, struct case_ordering *ordering)
 
 
 /* Resize the cases in the casefile, by inserting N_VALUES into every
-   one of them. */
+   one of them at the position immediately preceeding WHERE.
+*/
 gboolean
 psppire_case_file_insert_values (PsppireCaseFile *cf,
-                                gint n_values, gint before)
+                                gint n_values, gint where)
 {
-  union value *values;
   g_return_val_if_fail (cf, FALSE);
   g_return_val_if_fail (cf->accessible, FALSE);
 
+  if ( n_values == 0 )
+    return FALSE;
+
+  g_assert (n_values > 0);
+
   if ( ! cf->datasheet )
     cf->datasheet = datasheet_create (NULL);
 
-  values = xcalloc (n_values, sizeof *values);
-  datasheet_insert_columns (cf->datasheet, values, n_values, before);
+  {
+    union value *values = xcalloc (n_values, sizeof *values);
+    datasheet_insert_columns (cf->datasheet, values, n_values, where);
   free (values);
+  }
 
   return TRUE;
 }
 
+
 /* Fills C with the CASENUMth case.
    Returns true on success, false otherwise.
  */
 gboolean
-psppire_case_file_get_case (const PsppireCaseFile *cf, gint casenum,
+psppire_case_file_get_case (const PsppireCaseFile *cf, casenumber casenum,
                           struct ccase *c)
 {
   g_return_val_if_fail (cf, FALSE);