GUI: Move .ui files from goffice resources to glib resources
[gnumeric.git] / src / dialogs / dialog-analysis-tool-wilcoxon-mann-whitney.c
blobfd9fc91eec6434e7d8e07c94f7090b11824bde92
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * dialog-analysis-tool-wilcoxon-mann-whitney.c:
5 * Authors:
6 * Andreas J. Guelzow <aguelzow@pyrshep.ca>
8 * (C) Copyright 2010 by Andreas J. Guelzow <aguelzow@pyrshep.ca>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <https://www.gnu.org/licenses/>.
24 #include <gnumeric-config.h>
25 #include <glib/gi18n-lib.h>
26 #include <gnumeric.h>
27 #include "dialogs.h"
28 #include "analysis-wilcoxon-mann-whitney.h"
29 #include "analysis-tools.h"
31 #include <workbook.h>
32 #include <workbook-control.h>
33 #include <wbc-gtk.h>
34 #include <workbook-view.h>
35 #include <gui-util.h>
36 #include <parse-util.h>
37 #include <gnm-format.h>
38 #include <tool-dialogs.h>
39 #include <dao-gui-utils.h>
40 #include <sheet.h>
41 #include <expr.h>
42 #include <number-match.h>
43 #include <ranges.h>
44 #include <selection.h>
45 #include <value.h>
46 #include <commands.h>
47 #include "help.h"
49 #include <widgets/gnm-dao.h>
50 #include <widgets/gnumeric-expr-entry.h>
52 #include <string.h>
53 #include <gtk/gtk.h>
55 #define WILCOXON_MANN_WHITNEY_KEY "analysistools-principal-components-dialog"
57 static char const * const grouped_by_group[] = {
58 "grouped_by_row",
59 "grouped_by_col",
60 "grouped_by_area",
61 NULL
64 static void
65 wilcoxon_mann_whitney_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget *dummy,
66 GenericToolState *state)
68 GnmValue *input_range;
69 GnmValue *input_range_2;
70 gboolean input_1_ready = FALSE;
71 gboolean input_2_ready = FALSE;
73 /* Checking Input Ranges */
74 input_range = gnm_expr_entry_parse_as_value (
75 GNM_EXPR_ENTRY (state->input_entry), state->sheet);
76 input_range_2 = gnm_expr_entry_parse_as_value
77 (GNM_EXPR_ENTRY (state->input_entry_2), state->sheet);
79 input_1_ready = (input_range != NULL);
80 input_2_ready = ((state->input_entry_2 == NULL) || (input_range_2 != NULL));
81 value_release (input_range);
82 value_release (input_range_2);
84 if (!input_1_ready) {
85 gtk_label_set_text (GTK_LABEL (state->warning),
86 _("The input range for variable 1 is invalid."));
87 gtk_widget_set_sensitive (state->ok_button, FALSE);
88 return;
89 } else if (!input_2_ready) {
90 gtk_label_set_text (GTK_LABEL (state->warning),
91 _("The input range for variable 2 is invalid."));
92 gtk_widget_set_sensitive (state->ok_button, FALSE);
93 return;
96 /* Checking Output Page */
97 if (!gnm_dao_is_ready (GNM_DAO (state->gdao))) {
98 gtk_label_set_text (GTK_LABEL (state->warning),
99 _("The output specification "
100 "is invalid."));
101 gtk_widget_set_sensitive (state->ok_button, FALSE);
102 return;
105 gtk_label_set_text (GTK_LABEL (state->warning), "");
106 gtk_widget_set_sensitive (state->ok_button, TRUE);
108 return;
112 * wilcoxon_mann_whitney_tool_ok_clicked_cb:
113 * @button:
114 * @state:
117 static void
118 wilcoxon_mann_whitney_tool_ok_clicked_cb (G_GNUC_UNUSED GtkWidget *button,
119 GenericToolState *state)
121 data_analysis_output_t *dao;
122 analysis_tools_data_generic_b_t *data;
124 GtkWidget *w;
126 if (state->warning_dialog != NULL)
127 gtk_widget_destroy (state->warning_dialog);
129 data = g_new0 (analysis_tools_data_generic_b_t, 1);
130 dao = parse_output (state, NULL);
132 data->wbc = GNM_WBC (state->wbcg);
134 data->range_1 = gnm_expr_entry_parse_as_value
135 (GNM_EXPR_ENTRY (state->input_entry), state->sheet);
137 data->range_2 = gnm_expr_entry_parse_as_value
138 (GNM_EXPR_ENTRY (state->input_entry_2), state->sheet);
140 w = go_gtk_builder_get_widget (state->gui, "labels_button");
141 data->labels = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
143 if (cmd_analysis_tool (GNM_WBC (state->wbcg), state->sheet,
144 dao, data,
145 analysis_tool_wilcoxon_mann_whitney_engine, TRUE)) {
146 char *text;
147 text = g_strdup_printf (
148 _("An unexpected error has occurred."));
149 error_in_entry (state, GTK_WIDGET (state->input_entry), text);
150 g_free (text);
151 } else
152 gtk_widget_destroy (state->dialog);
153 return;
159 * dialog_wilcoxon_mann_whitney_tool:
160 * @wbcg:
161 * @sheet:
163 * Show the dialog (guru).
167 dialog_wilcoxon_m_w_tool (WBCGtk *wbcg, Sheet *sheet)
169 GenericToolState *state;
170 char const * plugins[] = { "Gnumeric_fnstat",
171 "Gnumeric_fnmath",
172 "Gnumeric_fnlookup",
173 NULL};
175 if ((wbcg == NULL) ||
176 gnm_check_for_plugins_missing (plugins, wbcg_toplevel (wbcg)))
177 return 1;
179 /* Only pop up one copy per workbook */
180 if (gnm_dialog_raise_if_exists (wbcg, WILCOXON_MANN_WHITNEY_KEY))
181 return 0;
183 state = g_new0 (GenericToolState, 1);
185 if (dialog_tool_init (state, wbcg, sheet,
186 GNUMERIC_HELP_LINK_WILCOXON_MANN_WHITNEY,
187 "res:ui/wilcoxon-mann-whitney.ui", "WilcoxonMannWhitney",
188 _("Could not create the Wilcoxon-Mann-Whitney Analysis Tool dialog."),
189 WILCOXON_MANN_WHITNEY_KEY,
190 G_CALLBACK (wilcoxon_mann_whitney_tool_ok_clicked_cb), NULL,
191 G_CALLBACK (wilcoxon_mann_whitney_tool_update_sensitivity_cb),
192 GNM_EE_SINGLE_RANGE))
193 return 0;
195 gnm_dao_set_put (GNM_DAO (state->gdao), TRUE, TRUE);
196 wilcoxon_mann_whitney_tool_update_sensitivity_cb (NULL, state);
197 tool_load_selection ((GenericToolState *)state, TRUE);
199 return 0;