Added psppire-dialog and psppire-buttonbox widgets.
[pspp-builds.git] / src / ui / gui / weight-cases-dialog.c
1 /*
2     PSPPIRE --- A Graphical User Interface for PSPP
3     Copyright (C) 2007  Free Software Foundation
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18     02110-1301, USA. */
19
20
21 #include <config.h>
22
23 #include "psppire-var-select.h"
24 #include <glade/glade.h>
25 #include "helper.h"
26 #include <gettext.h>
27
28 #include "psppire-var-store.h"
29 #include "weight-cases-dialog.h"
30
31 #include "psppire-dialog.h"
32
33 #define _(msgid) gettext (msgid)
34 #define N_(msgid) msgid
35
36 static void
37 refresh_var_select (PsppireVarSelect *vs)
38 {
39   struct variable *weight;
40
41   psppire_var_select_deselect_all (vs);
42
43   weight = psppire_dict_get_weight_variable (vs->dict);
44
45   if ( weight )
46     psppire_var_select_set_variable (vs, weight);
47 }
48
49
50 static void
51 on_refresh (GtkWidget *dialog, gpointer data)
52 {
53   refresh_var_select (data);
54 }
55
56
57 static void
58 on_radiobutton_toggle (GtkToggleButton *button, gpointer data)
59 {
60   PsppireVarSelect *vs = data;
61   if ( gtk_toggle_button_get_active (button) )
62     {
63       psppire_var_select_deselect_all (vs);
64     }
65 }
66
67
68 /* Callback for when new variable is selected.
69    IDX is the dict index of the variable selected.
70    Updates the label and toggle buttons in the dialog box
71    to reflect this new selection. */
72 static void
73 select_var_callback (PsppireVarSelect *vs, gint idx, gpointer data)
74 {
75   GladeXML * xml  = data;
76
77   GtkWidget *label =  get_widget_assert (xml, "weight-status-label");
78
79   GtkWidget *radiobutton2 =  get_widget_assert (xml, "radiobutton2");
80
81   struct variable *var = psppire_dict_get_variable (vs->dict, idx);
82
83   gtk_label_set_text (GTK_LABEL (label), var_get_name(var));
84
85   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton2), TRUE);
86 }
87
88
89
90 static void
91 deselect_all (PsppireVarSelect *vs, gpointer data)
92 {
93   GladeXML * xml  = data;
94
95   GtkWidget *label =  get_widget_assert (xml, "weight-status-label");
96
97   GtkWidget *radiobutton1 =  get_widget_assert (xml, "radiobutton1");
98
99   gtk_label_set_text (GTK_LABEL (label), _("Do not weight cases"));
100
101   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton1), TRUE);
102 }
103
104
105
106 PsppireDialog *
107 create_weight_dialog (PsppireVarSelect *select, GladeXML *xml)
108 {
109   GtkWidget *dialog =  get_widget_assert (xml, "weight-cases-dialog");
110   GtkWidget *radiobutton1 =  get_widget_assert (xml, "radiobutton1");
111
112   g_signal_connect (dialog, "refresh", G_CALLBACK (on_refresh), select);
113
114   g_signal_connect (select, "variable-selected",
115                     G_CALLBACK (select_var_callback), xml);
116
117   g_signal_connect (select, "deselect-all",
118                     G_CALLBACK (deselect_all), xml);
119
120   g_signal_connect (radiobutton1, "toggled",
121                     G_CALLBACK (on_radiobutton_toggle),
122                     select);
123
124   refresh_var_select (select);
125
126   return PSPPIRE_DIALOG (dialog);
127 }