T-TEST Independent Samples Dialog: Converted to a PsppireDialogAction object
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 19 May 2012 09:55:12 +0000 (11:55 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 19 May 2012 09:55:12 +0000 (11:55 +0200)
src/ui/gui/automake.mk
src/ui/gui/data-editor.ui
src/ui/gui/psppire-data-window.c
src/ui/gui/psppire-dialog-action-indep-samps.c [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-indep-samps.h [new file with mode: 0644]
src/ui/gui/t-test-independent-samples-dialog.c [deleted file]
src/ui/gui/t-test-independent-samples-dialog.h [deleted file]
src/ui/gui/widgets.c

index a7cb1de5905345236a4a1379efbad7d888a13c34..3e2280a5d72e71a1fe3a64328eaba05f22d3b5c7 100644 (file)
@@ -230,6 +230,8 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/psppire-dialog-action-examine.h \
        src/ui/gui/psppire-dialog-action-factor.c \
        src/ui/gui/psppire-dialog-action-factor.h \
+       src/ui/gui/psppire-dialog-action-indep-samps.c \
+       src/ui/gui/psppire-dialog-action-indep-samps.h \
        src/ui/gui/psppire-dialog-action-kmeans.c \
        src/ui/gui/psppire-dialog-action-kmeans.h \
        src/ui/gui/psppire-dialog-action-means.c \
@@ -300,8 +302,6 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/text-data-import-dialog.h \
        src/ui/gui/transpose-dialog.c \
        src/ui/gui/transpose-dialog.h \
-       src/ui/gui/t-test-independent-samples-dialog.c \
-       src/ui/gui/t-test-independent-samples-dialog.h \
        src/ui/gui/t-test-one-sample.c \
        src/ui/gui/t-test-one-sample.h \
        src/ui/gui/t-test-options.c \
index 890d975c1fdeff81e604b561576b9629f466a271..19014e9cf16220f2bc5b87bc88b1b951deb136b1 100644 (file)
           </object>
         </child>
         <child>
-          <object class="GtkAction" id="indep-t-test">
+          <object class="PsppireDialogActionIndepSamps" id="indep-t-test">
             <property name="name">indep-t-test</property>
+            <property name="manager">uimanager1</property>
             <property name="label" translatable="yes">_Independent Samples T Test...</property>
           </object>
         </child>
index 81fe567c10b96ca8bc22ba22503d46cd0ef0371f..4e8d41a821a1aa5fe9cc45fa47b3f4d6efc54b3f 100644 (file)
@@ -54,7 +54,6 @@
 #include "ui/gui/regression-dialog.h"
 #include "ui/gui/select-cases-dialog.h"
 #include "ui/gui/split-file-dialog.h"
-#include "ui/gui/t-test-independent-samples-dialog.h"
 #include "ui/gui/t-test-one-sample.h"
 #include "ui/gui/t-test-paired-samples.h"
 #include "ui/gui/text-data-import-dialog.h"
@@ -1065,7 +1064,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
   connect_action (de, "data_split-file", G_CALLBACK (split_file_dialog));
   connect_action (de, "data_weight-cases", G_CALLBACK (weight_cases_dialog));
   connect_action (de, "oneway-anova", G_CALLBACK (oneway_anova_dialog));
-  connect_action (de, "indep-t-test", G_CALLBACK (t_test_independent_samples_dialog));
   connect_action (de, "paired-t-test", G_CALLBACK (t_test_paired_samples_dialog));
   connect_action (de, "one-sample-t-test", G_CALLBACK (t_test_one_sample_dialog));
   connect_action (de, "utilities_comments", G_CALLBACK (comments_dialog));
diff --git a/src/ui/gui/psppire-dialog-action-indep-samps.c b/src/ui/gui/psppire-dialog-action-indep-samps.c
new file mode 100644 (file)
index 0000000..3747d3e
--- /dev/null
@@ -0,0 +1,430 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2007, 2009, 2010, 2011, 2012  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 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.
+
+   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 "psppire-dialog-action-indep-samps.h"
+#include "psppire-value-entry.h"
+
+#include "dialog-common.h"
+#include <ui/syntax-gen.h>
+#include "psppire-var-view.h"
+
+#include "t-test-options.h"
+
+#include "psppire-dialog.h"
+#include "builder-wrapper.h"
+
+#include "psppire-dict.h"
+#include "libpspp/str.h"
+
+static void
+psppire_dialog_action_indep_samps_class_init (PsppireDialogActionIndepSampsClass *class);
+
+G_DEFINE_TYPE (PsppireDialogActionIndepSamps, psppire_dialog_action_indep_samps, PSPPIRE_TYPE_DIALOG_ACTION);
+
+static gboolean
+dialog_state_valid (gpointer data)
+{
+  PsppireDialogActionIndepSamps *act = PSPPIRE_DIALOG_ACTION_INDEP_SAMPS (data);
+
+  GtkTreeModel *vars = gtk_tree_view_get_model (GTK_TREE_VIEW (act->test_vars_tv));
+
+  GtkTreeIter notused;
+
+  if (NULL == act->grp_var)
+    return FALSE;
+
+  if ( 0 == gtk_tree_model_get_iter_first (vars, &notused))
+    return FALSE;
+
+  if ( act->group_defn == GROUPS_UNDEF)
+    return FALSE;
+
+  return TRUE;
+}
+
+
+static void
+refresh (PsppireDialogAction *da)
+{
+  PsppireDialogActionIndepSamps *act = PSPPIRE_DIALOG_ACTION_INDEP_SAMPS (da);
+
+  GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (act->test_vars_tv));
+
+  act->group_defn = GROUPS_UNDEF;
+
+  if (act->grp_var)
+    {
+      int width = var_get_width (act->grp_var);
+      value_destroy (&act->cut_point, width);
+      value_destroy (&act->grp_val[0], width);
+      value_destroy (&act->grp_val[1], width);
+      act->grp_var = NULL;
+    }
+
+  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (act->dg_grp_entry[0]), NULL);
+  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (act->dg_grp_entry[1]), NULL);
+  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (act->dg_cut_point_entry), NULL);
+
+  gtk_entry_set_text (GTK_ENTRY (act->group_var_entry), "");
+
+  gtk_list_store_clear (GTK_LIST_STORE (model));
+
+  gtk_widget_set_sensitive (act->define_groups_button, FALSE);
+}
+
+/* Return TRUE if VE contains a text which is not valid for VAR or if it
+   contains the SYSMIS value */
+static gboolean
+value_entry_contains_invalid (PsppireValueEntry *ve, const struct variable *var)
+{
+  gboolean result = FALSE;
+
+  if (var) 
+    {
+      union value val;
+      const int width = var_get_width (var);
+      value_init (&val, width);
+
+      if ( psppire_value_entry_get_value (ve, &val, width))
+       {
+         if (var_is_value_missing (var, &val, MV_SYSTEM))
+           {
+             result = TRUE;
+           }
+       }
+      else
+       result = TRUE;
+
+      value_destroy (&val, width);
+    }
+
+  return result;
+}
+
+/* Returns TRUE iff the define groups subdialog has a
+   state which defines a valid group criterion */
+static gboolean
+define_groups_state_valid (gpointer data)
+{
+  PsppireDialogActionIndepSamps *act = data;
+
+  if (gtk_toggle_button_get_active
+      (GTK_TOGGLE_BUTTON (act->dg_values_toggle_button)))
+    {
+      if (value_entry_contains_invalid (PSPPIRE_VALUE_ENTRY (act->dg_grp_entry[0]),
+                                       act->grp_var))
+        return FALSE;
+
+      if (value_entry_contains_invalid (PSPPIRE_VALUE_ENTRY (act->dg_grp_entry[1]),
+                                       act->grp_var))
+        return FALSE;
+    }
+  else
+    {
+      if (value_entry_contains_invalid (PSPPIRE_VALUE_ENTRY (act->dg_cut_point_entry),
+                                       act->grp_var))
+        return FALSE;
+    }
+
+  return TRUE;
+}
+
+
+static void
+run_define_groups (PsppireDialogActionIndepSamps *act)
+{
+  gint response;
+  PsppireDialogAction *da = PSPPIRE_DIALOG_ACTION (act);
+
+  if ( act->dg_table2->parent)
+    gtk_container_remove (GTK_CONTAINER (act->dg_table2->parent), act->dg_table2);
+
+  if ( act->dg_table1->parent)
+    gtk_container_remove (GTK_CONTAINER (act->dg_table1->parent), act->dg_table1);
+
+
+  if ( var_is_numeric (act->grp_var))
+    {
+      gtk_table_attach_defaults (GTK_TABLE (act->dg_table1), act->dg_table2,
+                                1, 2, 1, 2);
+
+      gtk_container_add (GTK_CONTAINER (act->dg_box), act->dg_table1);
+    }
+  else
+    {
+      gtk_container_add (GTK_CONTAINER (act->dg_box), act->dg_table2);
+      act->group_defn = GROUPS_VALUES;
+    }
+
+
+  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (act->dg_dialog),
+                                     define_groups_state_valid, act);
+
+  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (act->dg_grp_entry[0]), act->grp_var);
+  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (act->dg_grp_entry[1]), act->grp_var);
+  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (act->dg_cut_point_entry), act->grp_var);
+
+  if ( act->group_defn != GROUPS_CUT_POINT )
+    {
+      gtk_toggle_button_set_active
+       (GTK_TOGGLE_BUTTON (act->dg_cut_point_toggle_button), TRUE);
+
+      gtk_toggle_button_set_active
+       (GTK_TOGGLE_BUTTON (act->dg_values_toggle_button), TRUE);
+    }
+  else
+    {
+      gtk_toggle_button_set_active
+       (GTK_TOGGLE_BUTTON (act->dg_values_toggle_button), TRUE);
+
+      gtk_toggle_button_set_active
+       (GTK_TOGGLE_BUTTON (act->dg_cut_point_toggle_button), TRUE);
+    }
+
+  g_signal_emit_by_name (act->dg_grp_entry[0], "changed");
+  g_signal_emit_by_name (act->dg_grp_entry[1], "changed");
+  g_signal_emit_by_name (act->dg_cut_point_entry, "changed");
+
+  response = psppire_dialog_run (PSPPIRE_DIALOG (act->def_grps_dialog));
+
+  if (response == PSPPIRE_RESPONSE_CONTINUE)
+    {
+      const int width = var_get_width (act->grp_var);
+
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (act->dg_values_toggle_button)))
+       {
+         act->group_defn = GROUPS_VALUES;
+
+          psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (act->dg_grp_entry[0]),
+                                        &act->grp_val[0], width);
+
+          psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (act->dg_grp_entry[1]),
+                                        &act->grp_val[1], width);
+       }
+      else
+       {
+         act->group_defn = GROUPS_CUT_POINT;
+
+          psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (act->dg_cut_point_entry),
+                                        &act->cut_point, width);
+       }
+
+      psppire_dialog_notify_change (PSPPIRE_DIALOG (da->dialog));
+    }
+}
+
+/* Called whenever the group variable entry widget's contents change */
+static void
+on_grp_var_change (GtkEntry *entry, PsppireDialogActionIndepSamps *act)
+{
+  PsppireDialogAction *da = PSPPIRE_DIALOG_ACTION (act);
+  const gchar *text = gtk_entry_get_text (entry);
+
+  const struct variable *v = psppire_dict_lookup_var (da->dict, text);
+
+  gtk_widget_set_sensitive (act->define_groups_button, v != NULL);
+
+  if (act->grp_var)
+    {
+      int width = var_get_width (act->grp_var);
+      value_destroy (&act->cut_point, width);
+      value_destroy (&act->grp_val[0], width);
+      value_destroy (&act->grp_val[1], width);
+    }
+
+  if (v)
+    {
+      const int width = var_get_width (v);
+      value_init (&act->cut_point, width);
+      value_init (&act->grp_val[0], width);
+      value_init (&act->grp_val[1], width);
+
+      if (width == 0)
+        {
+          act->cut_point.f  = SYSMIS;
+          act->grp_val[0].f = SYSMIS;
+          act->grp_val[1].f = SYSMIS;
+        }
+      else
+        {
+          act->cut_point.short_string[0] = '\0';
+          act->grp_val[0].short_string[0] = '\0';
+          act->grp_val[1].short_string[0] = '\0';
+        }
+    }
+
+  act->grp_var = v;
+}
+
+static void
+set_group_criterion_type (GtkToggleButton *button,
+                         PsppireDialogActionIndepSamps *act)
+{
+  gboolean by_values = gtk_toggle_button_get_active (button);
+
+  gtk_widget_set_sensitive (act->dg_label, by_values);
+  gtk_widget_set_sensitive (act->dg_table2, by_values);
+
+  gtk_widget_set_sensitive (act->dg_hbox1, !by_values);
+}
+
+
+static void
+psppire_dialog_action_indep_samps_activate (GtkAction *a)
+{
+  PsppireDialogActionIndepSamps *act = PSPPIRE_DIALOG_ACTION_INDEP_SAMPS (a);
+  PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
+
+  GtkBuilder *xml = builder_new ("t-test.ui");
+
+  pda->dialog = get_widget_assert (xml,"t-test-independent-samples-dialog"); 
+  pda->source = get_widget_assert (xml, "indep-samples-t-test-treeview1");
+  act->define_groups_button = get_widget_assert (xml, "define-groups-button");
+  act->options_button = get_widget_assert (xml, "indep-samples-t-test-options-button");
+
+  act->def_grps_dialog = get_widget_assert (xml, "define-groups-dialog");
+  act->group_var_entry = get_widget_assert (xml, "indep-samples-t-test-entry");
+  act->test_vars_tv = get_widget_assert (xml, "indep-samples-t-test-treeview2");
+
+  act->dg_dialog = get_widget_assert (xml, "define-groups-dialog");
+  act->dg_grp_entry[0] = get_widget_assert (xml, "group1-entry");
+  act->dg_grp_entry[1] = get_widget_assert (xml, "group2-entry");
+  act->dg_cut_point_entry = get_widget_assert (xml, "cut-point-entry");
+  act->dg_box = get_widget_assert (xml, "dialog-hbox2");
+
+  act->dg_table1 = get_widget_assert (xml, "table1");
+  act->dg_table2 = get_widget_assert (xml, "table2");
+  act->dg_label  = get_widget_assert (xml, "label4");
+  act->dg_hbox1  = get_widget_assert (xml, "hbox1");
+  act->dg_values_toggle_button = get_widget_assert (xml, "radiobutton3");
+  act->dg_cut_point_toggle_button = get_widget_assert (xml, "radiobutton4");
+
+  act->opts = tt_options_dialog_create (GTK_WINDOW (pda->toplevel));
+
+  g_object_ref (act->dg_table1);
+  g_object_ref (act->dg_table2);
+
+  g_signal_connect (act->dg_values_toggle_button, "toggled",
+                   G_CALLBACK (set_group_criterion_type), act);
+
+
+  g_object_unref (xml);
+
+  psppire_dialog_action_set_refresh (pda, refresh);
+
+  psppire_dialog_action_set_valid_predicate (pda,
+                                       dialog_state_valid);
+
+  g_signal_connect_swapped (act->define_groups_button, "clicked",
+                           G_CALLBACK (run_define_groups), act);
+
+  g_signal_connect_swapped (act->options_button, "clicked",
+                           G_CALLBACK (tt_options_dialog_run), act->opts);
+
+
+  g_signal_connect (act->group_var_entry, "changed",
+                   G_CALLBACK (on_grp_var_change), act);
+
+  if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_indep_samps_parent_class)->activate)
+    PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_indep_samps_parent_class)->activate (pda);
+}
+
+
+
+static char *
+generate_syntax (PsppireDialogAction *a)
+{
+  PsppireDialogActionIndepSamps *act = PSPPIRE_DIALOG_ACTION_INDEP_SAMPS (a);
+  gchar *text;
+
+  GString *str = g_string_new ("T-TEST /VARIABLES=");
+
+  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (act->test_vars_tv), 0, str);
+
+  g_string_append (str, "\n\t/GROUPS=");
+
+  g_string_append (str, var_get_name (act->grp_var));
+
+  if (act->group_defn != GROUPS_UNDEF)
+    {
+      g_string_append (str, "(");
+
+      {
+        const union value *val = 
+          (act->group_defn == GROUPS_VALUES) ?
+          &act->grp_val[0] :
+          &act->cut_point;
+
+        struct string strx;        
+        ds_init_empty (&strx);
+        syntax_gen_value (&strx, val, var_get_width (act->grp_var),
+                          var_get_print_format (act->grp_var));
+      
+        g_string_append (str, ds_cstr (&strx));
+        ds_destroy (&strx);
+      }
+
+      if (act->group_defn == GROUPS_VALUES)
+       {
+         g_string_append (str, ",");
+
+          {
+            struct string strx;
+            ds_init_empty (&strx);
+            
+            syntax_gen_value (&strx, &act->grp_val[1], var_get_width (act->grp_var),
+                              var_get_print_format (act->grp_var));
+            
+            g_string_append (str, ds_cstr (&strx));
+            ds_destroy (&strx);
+          }
+       }
+
+      g_string_append (str, ")");
+    }
+
+  tt_options_dialog_append_syntax (act->opts, str);
+
+  g_string_append (str, ".\n");
+
+  text = str->str;
+
+  g_string_free (str, FALSE);
+
+  return text;
+}
+
+static void
+psppire_dialog_action_indep_samps_class_init (PsppireDialogActionIndepSampsClass *class)
+{
+  GtkActionClass *action_class = GTK_ACTION_CLASS (class);
+
+  action_class->activate = psppire_dialog_action_indep_samps_activate;
+
+  PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
+}
+
+
+static void
+psppire_dialog_action_indep_samps_init (PsppireDialogActionIndepSamps *act)
+{
+  act->grp_var = NULL;
+  act->group_defn = GROUPS_UNDEF;
+}
+
diff --git a/src/ui/gui/psppire-dialog-action-indep-samps.h b/src/ui/gui/psppire-dialog-action-indep-samps.h
new file mode 100644 (file)
index 0000000..359640d
--- /dev/null
@@ -0,0 +1,117 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2012  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 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.
+
+   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 <glib-object.h>
+#include <glib.h>
+
+#include "psppire-dialog-action.h"
+
+#ifndef __PSPPIRE_DIALOG_ACTION_INDEP_SAMPS_H__
+#define __PSPPIRE_DIALOG_ACTION_INDEP_SAMPS_H__
+
+G_BEGIN_DECLS
+
+
+#define PSPPIRE_TYPE_DIALOG_ACTION_INDEP_SAMPS (psppire_dialog_action_indep_samps_get_type ())
+
+#define PSPPIRE_DIALOG_ACTION_INDEP_SAMPS(obj) \
+                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                 PSPPIRE_TYPE_DIALOG_ACTION_INDEP_SAMPS, PsppireDialogActionIndepSamps))
+
+#define PSPPIRE_DIALOG_ACTION_INDEP_SAMPS_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_CAST ((klass), \
+                                PSPPIRE_TYPE_DIALOG_ACTION_INDEP_SAMPS, \
+                                 PsppireDialogActionIndepSampsClass))
+
+
+#define PSPPIRE_IS_DIALOG_ACTION_INDEP_SAMPS(obj) \
+                    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_INDEP_SAMPS))
+
+#define PSPPIRE_IS_DIALOG_ACTION_INDEP_SAMPS_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_INDEP_SAMPS))
+
+
+#define PSPPIRE_DIALOG_ACTION_INDEP_SAMPS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                  PSPPIRE_TYPE_DIALOG_ACTION_INDEP_SAMPS, \
+                                  PsppireDialogActionIndepSampsClass))
+
+typedef struct _PsppireDialogActionIndepSamps       PsppireDialogActionIndepSamps;
+typedef struct _PsppireDialogActionIndepSampsClass  PsppireDialogActionIndepSampsClass;
+
+
+enum group_definition
+  {
+    GROUPS_UNDEF,
+    GROUPS_VALUES,
+    GROUPS_CUT_POINT
+  };
+
+struct tt_options_dialog;
+
+struct _PsppireDialogActionIndepSamps
+{
+  PsppireDialogAction parent;
+
+  /*< private >*/
+  gboolean dispose_has_run ;
+
+  GtkWidget *test_vars_tv;
+  GtkWidget *def_grps_dialog;
+  GtkWidget *define_groups_button;
+  GtkWidget *options_button;
+
+  /* The variable which determines to which group a datum belongs */
+  const struct variable *grp_var;
+
+  /* The GtkEntry which holds the reference to the above variable */
+  GtkWidget *group_var_entry;
+
+  /* The define groups subdialog */
+  GtkWidget *dg_dialog;
+  GtkWidget *dg_label;
+  GtkWidget *dg_table1;
+  GtkWidget *dg_table2;
+  GtkWidget *dg_hbox1;
+  GtkWidget *dg_box;
+
+  GtkWidget *dg_values_toggle_button;
+  GtkWidget *dg_cut_point_toggle_button;
+
+  GtkWidget *dg_grp_entry[2];
+  GtkWidget *dg_cut_point_entry;
+
+  enum group_definition group_defn;
+
+  union value grp_val[2];
+  union value cut_point;
+
+  /* The options dialog */
+  struct tt_options_dialog *opts;
+};
+
+
+struct _PsppireDialogActionIndepSampsClass
+{
+  PsppireDialogActionClass parent_class;
+};
+
+
+GType psppire_dialog_action_indep_samps_get_type (void) ;
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_DIALOG_ACTION_INDEP_SAMPS_H__ */
diff --git a/src/ui/gui/t-test-independent-samples-dialog.c b/src/ui/gui/t-test-independent-samples-dialog.c
deleted file mode 100644 (file)
index 5c6dd5b..0000000
+++ /dev/null
@@ -1,524 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2007, 2009, 2010, 2011, 2012  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 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.
-
-   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 <gtk/gtk.h>
-#include "t-test-independent-samples-dialog.h"
-#include "psppire-dict.h"
-#include "psppire-var-store.h"
-#include "psppire-var-view.h"
-#include "psppire-value-entry.h"
-#include "executor.h"
-#include "psppire-data-window.h"
-#include "psppire-dialog.h"
-#include "dialog-common.h"
-#include "dict-display.h"
-#include "widget-io.h"
-#include "t-test-options.h"
-#include <ui/syntax-gen.h>
-
-#include "builder-wrapper.h"
-#include "helper.h"
-
-#include <gl/xalloc.h>
-
-#include <gettext.h>
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
-
-
-enum group_definition
-  {
-    GROUPS_UNDEF,
-    GROUPS_VALUES,
-    GROUPS_CUT_POINT
-  };
-
-struct tt_groups_dialog
-{
-  GtkWidget *dialog;
-  GtkWidget *label;
-  GtkWidget *table1;
-  GtkWidget *table2;
-  GtkWidget *hbox1;
-
-  GtkWidget *values_toggle_button;
-  GtkWidget *cut_point_toggle_button;
-
-  GtkWidget *grp_entry[2];
-  GtkWidget *cut_point_entry;
-
-  enum group_definition group_defn;
-
-  union value grp_val[2];
-  union value cut_point;
-};
-
-static void
-set_group_criterion_type (GtkToggleButton *button,
-                         struct tt_groups_dialog *groups)
-{
-  gboolean by_values = gtk_toggle_button_get_active (button);
-
-  gtk_widget_set_sensitive (groups->label, by_values);
-  gtk_widget_set_sensitive (groups->table2, by_values);
-
-  gtk_widget_set_sensitive (groups->hbox1, !by_values);
-}
-
-static void
-tt_groups_dialog_destroy (struct tt_groups_dialog *grps)
-{
-
-  g_object_unref (grps->table1);
-  g_object_unref (grps->table2);
-
-  g_free (grps);
-}
-
-static struct tt_groups_dialog *
-tt_groups_dialog_create (GtkBuilder *xml, GtkWindow *parent)
-{
-  struct tt_groups_dialog *grps = xmalloc (sizeof (*grps));
-
-  grps->group_defn = GROUPS_UNDEF;
-
-  grps->dialog = get_widget_assert (xml, "define-groups-dialog");
-  grps->table1 = get_widget_assert (xml, "table1");
-  grps->table2 = get_widget_assert (xml, "table2");
-  grps->label  = get_widget_assert (xml, "label4");
-  grps->hbox1  = get_widget_assert (xml, "hbox1");
-
-  grps->grp_entry[0] = get_widget_assert (xml, "group1-entry");
-  grps->grp_entry[1] = get_widget_assert (xml, "group2-entry");
-  grps->cut_point_entry = get_widget_assert (xml, "cut-point-entry");
-
-  grps->cut_point_toggle_button = get_widget_assert (xml, "radiobutton4");
-  grps->values_toggle_button = get_widget_assert (xml, "radiobutton3");
-
-  g_object_ref (grps->table1);
-  g_object_ref (grps->table2);
-
-  g_signal_connect (grps->values_toggle_button, "toggled",
-                   G_CALLBACK (set_group_criterion_type), grps);
-
-  gtk_window_set_transient_for (GTK_WINDOW (grps->dialog), parent);
-
-  return grps;
-}
-
-
-struct tt_indep_samples_dialog
-{
-  GtkBuilder *xml;  /* The xml that generated the widgets */
-  GtkWidget *dialog;
-  PsppireDict *dict;
-  GtkWidget *define_groups_button;
-  GtkWidget *groups_entry;
-
-  const struct variable *grp_var;
-
-  struct tt_groups_dialog *grps;
-  struct tt_options_dialog *opts;
-};
-
-
-/* Called whenever the group variable entry widget's contents change */
-static void
-on_grp_var_change (GtkEntry *entry,
-                              struct tt_indep_samples_dialog *tt_d)
-{
-  const gchar *text = gtk_entry_get_text (entry);
-
-  const struct variable *v = psppire_dict_lookup_var (tt_d->dict, text);
-
-  gtk_widget_set_sensitive (tt_d->define_groups_button, v != NULL);
-
-  if (tt_d->grp_var)
-    {
-      int width = var_get_width (tt_d->grp_var);
-      value_destroy (&tt_d->grps->cut_point, width);
-      value_destroy (&tt_d->grps->grp_val[0], width);
-      value_destroy (&tt_d->grps->grp_val[1], width);
-    }
-
-  if (v)
-    {
-      const int width = var_get_width (v);
-      value_init (&tt_d->grps->cut_point, width);
-      value_init (&tt_d->grps->grp_val[0], width);
-      value_init (&tt_d->grps->grp_val[1], width);
-
-      if (width == 0)
-        {
-          tt_d->grps->cut_point.f  = SYSMIS;
-          tt_d->grps->grp_val[0].f = SYSMIS;
-          tt_d->grps->grp_val[1].f = SYSMIS;
-        }
-      else
-        {
-          tt_d->grps->cut_point.short_string[0] = '\0';
-          tt_d->grps->grp_val[0].short_string[0] = '\0';
-          tt_d->grps->grp_val[1].short_string[0] = '\0';
-        }
-    }
-
-  tt_d->grp_var = v;
-}
-
-
-static gchar *
-generate_syntax (const struct tt_indep_samples_dialog *d)
-{
-  gchar *text;
-
-  GtkWidget *tv =
-    get_widget_assert (d->xml, "indep-samples-t-test-treeview2");
-
-  GString *str = g_string_new ("T-TEST /VARIABLES=");
-
-  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (tv), 0, str);
-
-  g_string_append (str, "\n\t/GROUPS=");
-
-  g_string_append (str, var_get_name (d->grp_var));
-
-  if (d->grps->group_defn != GROUPS_UNDEF)
-    {
-      g_string_append (str, "(");
-
-      {
-        const union value *val = 
-          (d->grps->group_defn == GROUPS_VALUES) ?
-          &d->grps->grp_val[0] :
-          &d->grps->cut_point;
-
-        struct string strx;        
-        ds_init_empty (&strx);
-        syntax_gen_value (&strx, val, var_get_width (d->grp_var),
-                          var_get_print_format (d->grp_var));
-      
-        g_string_append (str, ds_cstr (&strx));
-        ds_destroy (&strx);
-      }
-
-      if (d->grps->group_defn == GROUPS_VALUES)
-       {
-         g_string_append (str, ",");
-
-          {
-            struct string strx;
-            ds_init_empty (&strx);
-            
-            syntax_gen_value (&strx, &d->grps->grp_val[1], var_get_width (d->grp_var),
-                              var_get_print_format (d->grp_var));
-            
-            g_string_append (str, ds_cstr (&strx));
-            ds_destroy (&strx);
-          }
-       }
-
-      g_string_append (str, ")");
-    }
-
-  tt_options_dialog_append_syntax (d->opts, str);
-
-  g_string_append (str, ".\n");
-
-  text = str->str;
-
-  g_string_free (str, FALSE);
-
-  return text;
-}
-
-static void
-refresh (struct tt_indep_samples_dialog *ttd)
-{
-  GtkWidget *tv =
-    get_widget_assert (ttd->xml, "indep-samples-t-test-treeview2");
-
-  GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tv));
-
-  gtk_entry_set_text (GTK_ENTRY (ttd->groups_entry), "");
-
-  gtk_list_store_clear (GTK_LIST_STORE (model));
-
-  gtk_widget_set_sensitive (ttd->define_groups_button, FALSE);
-}
-
-
-/* Return TRUE if VE contains a text which is not valid for VAR or if it
-   contains the SYSMIS value */
-static gboolean
-value_entry_contains_invalid (PsppireValueEntry *ve, const struct variable *var)
-{
-  union value val;
-  gboolean result = FALSE;
-  const int width = var_get_width (var);
-  value_init (&val, width);
-
-  if ( psppire_value_entry_get_value (ve, &val, width))
-    {
-      if (var_is_value_missing (var, &val, MV_SYSTEM))
-        {
-          result = TRUE;
-        }
-    }
-  else
-    result = TRUE;
-
-  value_destroy (&val, width);
-
-
-  return result;
-}
-
-
-/* Returns TRUE iff the define groups subdialog has a
-   state which defines a valid group criterion */
-static gboolean
-define_groups_state_valid (gpointer data)
-{
-  struct tt_indep_samples_dialog *dialog = data;
-
-  if (gtk_toggle_button_get_active
-      (GTK_TOGGLE_BUTTON (dialog->grps->values_toggle_button)))
-    {
-      if (value_entry_contains_invalid (PSPPIRE_VALUE_ENTRY (dialog->grps->grp_entry[0]), dialog->grp_var))
-        return FALSE;
-
-      if (value_entry_contains_invalid (PSPPIRE_VALUE_ENTRY (dialog->grps->grp_entry[1]), dialog->grp_var))
-        return FALSE;
-    }
-  else
-    {
-      if (value_entry_contains_invalid (PSPPIRE_VALUE_ENTRY (dialog->grps->cut_point_entry), dialog->grp_var))
-        return FALSE;
-    }
-
-  return TRUE;
-}
-
-static void
-run_define_groups (struct tt_indep_samples_dialog *ttd)
-{
-  struct tt_groups_dialog *grps = ttd->grps;
-
-  gint response;
-
-  GtkWidget *box = get_widget_assert (ttd->xml, "dialog-hbox2");
-
-  const gchar *text = gtk_entry_get_text (GTK_ENTRY (ttd->groups_entry));
-
-  const struct variable *v = psppire_dict_lookup_var (ttd->dict, text);
-
-  if ( grps->table2->parent)
-    gtk_container_remove (GTK_CONTAINER (grps->table2->parent), grps->table2);
-
-  if ( grps->table1->parent)
-    gtk_container_remove (GTK_CONTAINER (grps->table1->parent), grps->table1);
-
-
-  if ( var_is_numeric (v))
-    {
-      gtk_table_attach_defaults (GTK_TABLE (grps->table1), grps->table2,
-                                1, 2, 1, 2);
-
-      gtk_container_add (GTK_CONTAINER (box), grps->table1);
-    }
-  else
-    {
-      gtk_container_add (GTK_CONTAINER (box), grps->table2);
-      grps->group_defn = GROUPS_VALUES;
-    }
-
-
-  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (grps->dialog),
-                                     define_groups_state_valid, ttd);
-
-  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (grps->grp_entry[0]), ttd->grp_var);
-  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (grps->grp_entry[1]), ttd->grp_var);
-  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (grps->cut_point_entry), ttd->grp_var);
-
-  if ( grps->group_defn != GROUPS_CUT_POINT )
-    {
-      gtk_toggle_button_set_active
-       (GTK_TOGGLE_BUTTON (grps->cut_point_toggle_button), TRUE);
-
-      gtk_toggle_button_set_active
-       (GTK_TOGGLE_BUTTON (grps->values_toggle_button), TRUE);
-    }
-  else
-    {
-      gtk_toggle_button_set_active
-       (GTK_TOGGLE_BUTTON (grps->values_toggle_button), TRUE);
-
-      gtk_toggle_button_set_active
-       (GTK_TOGGLE_BUTTON (grps->cut_point_toggle_button), TRUE);
-    }
-
-  g_signal_emit_by_name (grps->grp_entry[0], "changed");
-  g_signal_emit_by_name (grps->grp_entry[1], "changed");
-  g_signal_emit_by_name (grps->cut_point_entry, "changed");
-
-  response = psppire_dialog_run (PSPPIRE_DIALOG (grps->dialog));
-
-  if (response == PSPPIRE_RESPONSE_CONTINUE)
-    {
-      const int width = var_get_width (ttd->grp_var);
-
-      if (gtk_toggle_button_get_active
-         (GTK_TOGGLE_BUTTON (grps->values_toggle_button)))
-       {
-         grps->group_defn = GROUPS_VALUES;
-
-          psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (grps->grp_entry[0]), &grps->grp_val[0], width);
-          psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (grps->grp_entry[1]), &grps->grp_val[1], width);
-       }
-      else
-       {
-         grps->group_defn = GROUPS_CUT_POINT;
-
-          psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (grps->cut_point_entry), &grps->cut_point, width);
-       }
-
-      psppire_dialog_notify_change (PSPPIRE_DIALOG (ttd->dialog));
-    }
-}
-
-
-
-static gboolean
-dialog_state_valid (gpointer data)
-{
-  struct tt_indep_samples_dialog *tt_d = data;
-
-  GtkWidget *tv_vars =
-    get_widget_assert (tt_d->xml, "indep-samples-t-test-treeview2");
-
-  GtkTreeModel *vars = gtk_tree_view_get_model (GTK_TREE_VIEW (tv_vars));
-
-  GtkTreeIter notused;
-
-  if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (tt_d->groups_entry))))
-    return FALSE;
-
-  if ( 0 == gtk_tree_model_get_iter_first (vars, &notused))
-    return FALSE;
-
-  if ( tt_d->grps->group_defn == GROUPS_UNDEF)
-    return FALSE;
-
-  return TRUE;
-}
-
-/* Pops up the dialog box */
-void
-t_test_independent_samples_dialog (PsppireDataWindow *de)
-{
-  struct tt_indep_samples_dialog tt_d;
-  gint response;
-
-  PsppireVarStore *vs = NULL;
-
-  GtkBuilder *xml = builder_new ("t-test.ui");
-
-  GtkWidget *dict_view =
-    get_widget_assert (xml, "indep-samples-t-test-treeview1");
-
-  GtkWidget *selector2 =
-    get_widget_assert (xml, "indep-samples-t-test-selector2");
-
-  GtkWidget *selector1 =
-    get_widget_assert (xml, "indep-samples-t-test-selector1");
-
-  GtkWidget *options_button =
-    get_widget_assert (xml, "indep-samples-t-test-options-button");
-
-  g_object_get (de->data_editor, "var-store", &vs, NULL);
-
-  tt_d.dialog = get_widget_assert (xml, "t-test-independent-samples-dialog");
-  tt_d.xml = xml;
-  g_object_get (vs, "dictionary", &tt_d.dict, NULL);
-
-  tt_d.define_groups_button = get_widget_assert (xml, "define-groups-button");
-  tt_d.groups_entry = get_widget_assert (xml, "indep-samples-t-test-entry");
-  tt_d.opts = tt_options_dialog_create (GTK_WINDOW (de));
-  tt_d.grps = tt_groups_dialog_create (xml, GTK_WINDOW (de));
-
-  tt_d.grp_var = NULL;
-
-  gtk_window_set_transient_for (GTK_WINDOW (tt_d.dialog), GTK_WINDOW (de));
-
-  g_object_set (dict_view, "model", tt_d.dict, NULL);
-
-  psppire_selector_set_allow (PSPPIRE_SELECTOR (selector1),
-                             numeric_only);
-
-
-  psppire_selector_set_filter_func (PSPPIRE_SELECTOR (selector2),
-                                is_currently_in_entry);
-
-  g_signal_connect_swapped (tt_d.define_groups_button, "clicked",
-                           G_CALLBACK (run_define_groups), &tt_d);
-
-
-  g_signal_connect_swapped (options_button, "clicked",
-                           G_CALLBACK (tt_options_dialog_run), tt_d.opts);
-
-
-  g_signal_connect_swapped (tt_d.dialog, "refresh", G_CALLBACK (refresh),
-                           &tt_d);
-
-  g_signal_connect (tt_d.groups_entry, "changed",
-                   G_CALLBACK (on_grp_var_change), &tt_d);
-
-
-  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (tt_d.dialog),
-                                     dialog_state_valid, &tt_d);
-
-  response = psppire_dialog_run (PSPPIRE_DIALOG (tt_d.dialog));
-
-  switch (response)
-    {
-    case GTK_RESPONSE_OK:
-      g_free (execute_syntax_string (de, generate_syntax (&tt_d)));
-      break;
-    case PSPPIRE_RESPONSE_PASTE:
-      g_free (paste_syntax_to_window (generate_syntax (&tt_d)));
-      break;
-    default:
-      break;
-    }
-
-  if (tt_d.grp_var)
-  {
-    int width = var_get_width (tt_d.grp_var);
-    value_destroy (&tt_d.grps->cut_point, width);
-    value_destroy (&tt_d.grps->grp_val[0], width);
-    value_destroy (&tt_d.grps->grp_val[1], width);
-  }
-
-  tt_options_dialog_destroy (tt_d.opts);
-  tt_groups_dialog_destroy (tt_d.grps);
-
-  g_object_unref (xml);
-}
-
-
diff --git a/src/ui/gui/t-test-independent-samples-dialog.h b/src/ui/gui/t-test-independent-samples-dialog.h
deleted file mode 100644 (file)
index 409443c..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef T_TEST_INDEPENDENT_SAMPLES_DIALOG
-#define T_TEST_INDEPENDENT_SAMPLES_DIALOG
-
-#include "psppire-data-window.h"
-
-void t_test_independent_samples_dialog (PsppireDataWindow *) ;
-
-#endif
index 9ef2ae88330366fe1db7504696b8e13f703e2221..74cfd4cf9415454b6317141b3da10bf0df00fac9 100644 (file)
@@ -17,6 +17,7 @@
 #include "psppire-dialog-action-descriptives.h"
 #include "psppire-dialog-action-examine.h"
 #include "psppire-dialog-action-factor.h"
+#include "psppire-dialog-action-indep-samps.h"
 #include "psppire-dialog-action-kmeans.h"
 #include "psppire-dialog-action-means.h"
 #include "psppire-means-layer.h"
@@ -51,6 +52,7 @@ preregister_widgets (void)
   psppire_dialog_action_factor_get_type ();
   psppire_dialog_action_kmeans_get_type ();
   psppire_dialog_action_means_get_type ();
+  psppire_dialog_action_indep_samps_get_type ();
   psppire_means_layer_get_type ();
   psppire_dialog_action_var_info_get_type ();
   psppire_dialog_action_rank_get_type ();