Fix some compiler warnings
[pspp] / src / ui / gui / goto-case-dialog.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2007, 2011, 2012, 2016  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 <config.h>
19 #include "goto-case-dialog.h"
20 #include "builder-wrapper.h"
21 #include "psppire-dialog.h"
22 #include "psppire-data-window.h"
23 #include "psppire-data-store.h"
24 #include "psppire-data-sheet.h"
25
26
27 static void
28 refresh (PsppireDataSheet *ds, GtkBuilder *xml)
29 {
30   PsppireDataStore *store = NULL;
31   g_object_get (ds, "data-model", &store, NULL);
32
33   GtkWidget *case_num_entry = get_widget_assert (xml, "goto-case-case-num-entry");
34   casenumber case_count =  gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
35
36   gtk_spin_button_set_range (GTK_SPIN_BUTTON (case_num_entry), 1, case_count);
37 }
38
39 void
40 goto_case_dialog (PsppireDataSheet *ds)
41 {
42   GtkWindow *top_level;
43   gint response;
44   GtkBuilder *xml = builder_new ("goto-case.ui");
45   GtkWidget *dialog = get_widget_assert   (xml, "goto-case-dialog");
46
47   top_level = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (ds)));
48   gtk_window_set_transient_for (GTK_WINDOW (dialog), top_level);
49
50   refresh (ds, xml);
51
52   response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
53
54   if (response == PSPPIRE_RESPONSE_GOTO)
55     {
56       PsppireDataStore *store = NULL;
57       g_object_get (ds, "data-model", &store, NULL);
58
59       GtkWidget *case_num_entry =
60         get_widget_assert (xml, "goto-case-case-num-entry");
61
62       glong case_num =
63         gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (case_num_entry))
64         - FIRST_CASE_NUMBER ;
65
66       if (case_num >= 0 &&
67           case_num < gtk_tree_model_iter_n_children (GTK_TREE_MODEL (ds), NULL))
68       {
69         ssw_sheet_scroll_to (SSW_SHEET (ds), -1, case_num);
70         ssw_sheet_set_active_cell (SSW_SHEET (ds), -1, case_num, 0);
71       }
72     }
73 }