work on docs
[pspp] / src / ui / gui / psppire-dialog-action-oneway.c
index 77512977a9049f230bd393be8d108bb99da4566d..71d4873cd2ab54797020c0b0c0dd71ed4c6d02d2 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2012, 2013, 2014  Free Software Foundation
+   Copyright (C) 2012, 2013, 2014, 2019  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
 #define _(msgid) gettext (msgid)
 #define N_(msgid) msgid
 
+#define     POSTHOC_BONFERRONI  0x01
+#define     POSTHOC_GH          0x02
+#define     POSTHOC_LSD         0x04
+#define     POSTHOC_SCHEFFE     0x08
+#define     POSTHOC_SIDAK       0x10
+#define     POSTHOC_TUKEY       0x20
 
 static void next (GtkWidget *widget, PsppireDialogActionOneway *);
 static void prev (GtkWidget *widget, PsppireDialogActionOneway *);
+static void run_posthoc_dialog (PsppireDialogActionOneway *ow);
 static void run_contrasts_dialog (PsppireDialogActionOneway *csd);
 static void push_new_store (GArray *contrast_stack, PsppireDialogActionOneway *csd);
 
@@ -65,7 +72,7 @@ generate_syntax (const PsppireDialogAction *act)
 
   ds_put_cstr (&dss, gtk_entry_get_text (GTK_ENTRY (ow->factor_entry)));
 
-  if (descriptives || homogeneity )
+  if (descriptives || homogeneity)
     {
       ds_put_cstr (&dss, "\n\t/STATISTICS=");
       if (descriptives)
@@ -73,8 +80,23 @@ generate_syntax (const PsppireDialogAction *act)
       if (homogeneity)
        ds_put_cstr (&dss, "HOMOGENEITY ");
     }
-
-  for (i = 0 ; i < ow->contrasts_array->len ; ++i )
+  if (ow->posthoc)
+    {
+      ds_put_cstr (&dss, "\n\t/POSTHOC=");
+      if (ow->posthoc & POSTHOC_BONFERRONI)
+       ds_put_cstr (&dss, "BONFERRONI ");
+      if (ow->posthoc & POSTHOC_GH)
+       ds_put_cstr (&dss, "GH ");
+      if (ow->posthoc & POSTHOC_LSD)
+       ds_put_cstr (&dss, "LSD ");
+      if (ow->posthoc & POSTHOC_SCHEFFE)
+       ds_put_cstr (&dss, "SCHEFFE ");
+      if (ow->posthoc & POSTHOC_SIDAK)
+       ds_put_cstr (&dss, "SIDAK ");
+      if (ow->posthoc & POSTHOC_TUKEY)
+       ds_put_cstr (&dss, "TUKEY ");
+      }
+  for (i = 0 ; i < ow->contrasts_array->len ; ++i)
     {
       GtkListStore *ls = g_array_index (ow->contrasts_array, GtkListStore*, i);
       GtkTreeIter iter;
@@ -114,10 +136,10 @@ dialog_state_valid (gpointer data)
 
   GtkTreeIter notused;
 
-  if ( !gtk_tree_model_get_iter_first (vars, &notused) )
+  if (!gtk_tree_model_get_iter_first (vars, &notused))
     return FALSE;
 
-  if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (ow->factor_entry))))
+  if (0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (ow->factor_entry))))
     return FALSE;
 
 
@@ -159,7 +181,7 @@ list_store_changed (PsppireDialogActionOneway *csd)
 
   gtk_widget_set_sensitive (csd->prev, csd->c > 1);
 
-  if ( csd->c > 0 )
+  if (csd->c > 0)
     ls = g_array_index (csd->temp_contrasts, GtkTreeModel*, csd->c - 1);
 
   psppire_acr_set_model (PSPPIRE_ACR (csd->acr), GTK_LIST_STORE (ls));
@@ -172,7 +194,7 @@ list_store_changed (PsppireDialogActionOneway *csd)
   for (ok = gtk_tree_model_get_iter_first (ls, &iter);
        ok;
        ok = gtk_tree_model_iter_next (ls, &iter)
-       )
+)
     {
       gdouble v;
       gtk_tree_model_get (ls, &iter, 0, &v, -1);
@@ -197,7 +219,7 @@ clone_contrasts_array (GArray *src_array)
     g_array_sized_new (FALSE, FALSE, sizeof (GtkListStore *),
                       src_array->len);
 
-  for (i = 0 ; i < src_array->len ; ++i )
+  for (i = 0 ; i < src_array->len ; ++i)
     {
 
       GtkTreeIter src_iter;
@@ -224,10 +246,11 @@ psppire_dialog_action_oneway_activate (PsppireDialogAction *a, GVariant *param)
   PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
   PsppireDialogActionOneway *act = PSPPIRE_DIALOG_ACTION_ONEWAY (a);
 
-  GtkBuilder *xml = builder_new ( "oneway.ui");
+  GtkBuilder *xml = builder_new ("oneway.ui");
 
-  GtkWidget *contrasts_button =
-    get_widget_assert (xml, "contrasts-button");
+  GtkWidget *contrasts_button = get_widget_assert (xml, "contrasts-button");
+/* Posthoc button */
+  GtkWidget *posthoc_button= get_widget_assert (xml, "posthoc-button");
   GtkEntry *entry = GTK_ENTRY (get_widget_assert (xml, "entry1"));
 
   pda->dialog = get_widget_assert   (xml, "oneway-anova-dialog");
@@ -239,6 +262,20 @@ psppire_dialog_action_oneway_activate (PsppireDialogAction *a, GVariant *param)
   act->descriptives =  get_widget_assert (xml, "checkbutton1");
   act->homogeneity =  get_widget_assert (xml, "checkbutton2");
 
+/* Posthoc tests dialog */
+  act->posthoc_dialog = get_widget_assert (xml, "posthoc-dialog");
+
+  act->bonferroni_button = get_widget_assert (xml, "bonferroni-button");
+  act->gh_button = get_widget_assert (xml, "gh-button");
+  act->lsd_button = get_widget_assert (xml, "lsd-button");
+  act->scheffe_button = get_widget_assert (xml, "scheffe-button");
+  act->sidak_button = get_widget_assert (xml, "sidak-button");
+  act->tukey_button = get_widget_assert (xml, "tukey-button");
+
+  g_signal_connect_swapped (posthoc_button, "clicked",
+                   G_CALLBACK (run_posthoc_dialog), act);
+
+/* Contrast dialog */
   act->contrasts_dialog = get_widget_assert (xml, "contrasts-dialog");
 
   act->next = get_widget_assert (xml, "next-button");
@@ -280,11 +317,56 @@ psppire_dialog_action_oneway_init (PsppireDialogActionOneway *act)
 {
   act->contrasts_array = NULL;
   act->c = -1;
-
+  act->posthoc = 0;
 }
+/* Posthoc dialog */
+static void
+run_posthoc_dialog (PsppireDialogActionOneway *ow)
+{
+  gint response;
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ow->bonferroni_button),
+                               ow->posthoc & POSTHOC_BONFERRONI);
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ow->gh_button),
+                               ow->posthoc & POSTHOC_GH);
 
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ow->lsd_button),
+                               ow->posthoc & POSTHOC_LSD);
 
-\f
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ow->scheffe_button),
+                               ow->posthoc & POSTHOC_SCHEFFE);
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ow->sidak_button),
+                               ow->posthoc & POSTHOC_SIDAK);
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ow->tukey_button),
+                               ow->posthoc & POSTHOC_TUKEY);
+
+  response = psppire_dialog_run (PSPPIRE_DIALOG (ow->posthoc_dialog));
+
+  if (response == PSPPIRE_RESPONSE_CONTINUE)
+    {
+      ow->posthoc= 0;
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ow->bonferroni_button)))
+       ow->posthoc |= POSTHOC_BONFERRONI;
+
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ow->gh_button)))
+       ow->posthoc |= POSTHOC_GH;
+
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ow->lsd_button)))
+       ow->posthoc |= POSTHOC_LSD;
+
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ow->scheffe_button)))
+       ow->posthoc |= POSTHOC_SCHEFFE;
+
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ow->sidak_button)))
+       ow->posthoc |= POSTHOC_SIDAK;
+
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ow->tukey_button)))
+       ow->posthoc |= POSTHOC_TUKEY;
+    }
+}\f
 
 static void
 run_contrasts_dialog (PsppireDialogActionOneway *csd)
@@ -299,7 +381,7 @@ run_contrasts_dialog (PsppireDialogActionOneway *csd)
 
   response = psppire_dialog_run (PSPPIRE_DIALOG (csd->contrasts_dialog));
 
-  if ( response == PSPPIRE_RESPONSE_CONTINUE )
+  if (response == PSPPIRE_RESPONSE_CONTINUE)
     {
       csd->contrasts_array = clone_contrasts_array (csd->temp_contrasts);
     }
@@ -338,7 +420,7 @@ next (GtkWidget *widget, PsppireDialogActionOneway *csd)
 static void
 prev (GtkWidget *widget, PsppireDialogActionOneway *csd)
 {
-  if ( csd->c > 0 )
+  if (csd->c > 0)
     --csd->c;
 
   list_store_changed (csd);