32e93dbd4ca37afe07f9bd14ebcf01953199ec27
[pspp-builds.git] / src / ui / gui / goto-case-dialog.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2007  Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17
18 #include "goto-case-dialog.h"
19 #include "helper.h"
20 #include "psppire-dialog.h"
21 #include "data-editor.h"
22 #include "psppire-data-store.h"
23 #include <gtksheet/gtksheet.h>
24
25
26 static void
27 refresh (const struct data_editor *de, GladeXML *xml)
28 {
29   GtkSheet *data_sheet =
30     GTK_SHEET (get_widget_assert (de->xml, "data_sheet"));
31
32   PsppireDataStore *ds =
33     PSPPIRE_DATA_STORE (gtk_sheet_get_model (data_sheet));
34
35   GtkWidget *case_num_entry =
36     get_widget_assert (xml, "goto-case-case-num-entry");
37
38   casenumber case_count =
39     psppire_data_store_get_case_count (ds);
40
41   gtk_spin_button_set_range (GTK_SPIN_BUTTON (case_num_entry),
42                              1, case_count);
43 }
44
45 void
46 goto_case_dialog (GObject *o, gpointer data)
47 {
48   gint response;
49   GladeXML *xml = XML_NEW ("psppire.glade");
50   struct data_editor *de = data;
51
52   GtkWidget *dialog = get_widget_assert   (xml, "goto-case-dialog");
53
54
55   gtk_window_set_transient_for (GTK_WINDOW (dialog), de->parent.window);
56
57   refresh (de, xml);
58
59   response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
60
61   if ( response == PSPPIRE_RESPONSE_GOTO )
62     {
63       gint row, column;
64       GtkSheet *data_sheet =
65         GTK_SHEET (get_widget_assert (de->xml, "data_sheet"));
66
67
68       GtkWidget *case_num_entry =
69         get_widget_assert (xml, "goto-case-case-num-entry");
70
71       gtk_sheet_get_active_cell (data_sheet, &row, &column);
72
73       row =
74         gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (case_num_entry))
75         - FIRST_CASE_NUMBER ;
76
77       gtk_sheet_moveto (data_sheet,
78                         row, column,
79                         0.5, 0.5);
80
81       gtk_sheet_set_active_cell (data_sheet, row, column);
82     }
83 }