Converted crosstabs-dialog to the new way of doing things 20121202030502/pspp 20121203030504/pspp
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 1 Dec 2012 11:15:56 +0000 (12:15 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 1 Dec 2012 11:17:20 +0000 (12:17 +0100)
src/ui/gui/automake.mk
src/ui/gui/crosstabs-dialog.c [deleted file]
src/ui/gui/crosstabs-dialog.h [deleted file]
src/ui/gui/data-editor.ui
src/ui/gui/psppire-data-window.c
src/ui/gui/psppire-dialog-action-crosstabs.c [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-crosstabs.h [new file with mode: 0644]
src/ui/gui/widgets.c

index d9ed78e8757b08baeaa894cb6eaf5412ca91b590..6d3b6d0ec3710fee9498dbbe8c4f3cd4e90712d7 100644 (file)
@@ -176,8 +176,6 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/chi-square-dialog.h \
        src/ui/gui/count-dialog.c \
        src/ui/gui/count-dialog.h \
-       src/ui/gui/crosstabs-dialog.c \
-       src/ui/gui/crosstabs-dialog.h \
        src/ui/gui/customentry.c \
        src/ui/gui/customentry.h \
        src/ui/gui/dialog-common.c \
@@ -226,6 +224,8 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/psppire-dialog-action-binomial.h \
        src/ui/gui/psppire-dialog-action-correlation.c \
        src/ui/gui/psppire-dialog-action-correlation.h \
+       src/ui/gui/psppire-dialog-action-crosstabs.c \
+       src/ui/gui/psppire-dialog-action-crosstabs.h \
        src/ui/gui/psppire-dialog-action-descriptives.c \
        src/ui/gui/psppire-dialog-action-descriptives.h \
        src/ui/gui/psppire-dialog-action-examine.c \
diff --git a/src/ui/gui/crosstabs-dialog.c b/src/ui/gui/crosstabs-dialog.c
deleted file mode 100644 (file)
index dc04667..0000000
+++ /dev/null
@@ -1,435 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2008, 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 "checkbox-treeview.h"
-#include "crosstabs-dialog.h"
-#include "psppire-var-view.h"
-
-#include <gtk/gtk.h>
-#include <stdlib.h>
-
-#include <ui/gui/psppire-data-window.h>
-#include <ui/gui/dialog-common.h>
-#include <ui/gui/dict-display.h>
-#include "executor.h"
-#include <ui/gui/psppire-dialog.h>
-#include <ui/gui/psppire-var-store.h>
-#include <ui/gui/builder-wrapper.h>
-#include "helper.h"
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
-
-
-#define CROSSTABS_STATS                         \
-  CS (CHISQ, N_("Chisq"))                       \
-  CS (PHI, N_("Phi"))                           \
-  CS (CC, N_("CC"))                             \
-  CS (LAMBDA, N_("Lambda"))                     \
-  CS (UC, N_("UC"))                             \
-  CS (BTAU, N_("BTau"))                         \
-  CS (CTAU, N_("CTau"))                         \
-  CS (RISK, N_("Risk"))                         \
-  CS (GAMMA, N_("Gamma"))                       \
-  CS (D, N_("D"))                               \
-  CS (KAPPA, N_("Kappa"))                       \
-  CS (ETA, N_("Eta"))                           \
-  CS (CORR, N_("Corr"))                         \
-  CS (STATS_NONE, N_("None"))
-
-#define CROSSTABS_CELLS                         \
-  CS (COUNT, N_("Count"))                       \
-  CS (ROW, N_("Row"))                           \
-  CS (COLUMN, N_("Column"))                     \
-  CS (TOTAL, N_("Total"))                       \
-  CS (EXPECTED, N_("Expected"))                 \
-  CS (RESIDUAL, N_("Residual"))                 \
-  CS (SRESIDUAL, N_("Std. Residual"))           \
-  CS (ASRESIDUAL, N_("Adjusted Std. Residual")) \
-  CS (CELLS_NONE, N_("None"))
-
-enum
-  {
-#define CS(NAME, LABEL) CS_##NAME,
-    CROSSTABS_STATS
-#undef CS
-    N_CROSSTABS_STATS
-  };
-
-enum
-  {
-#define CS(NAME, LABEL) CS_##NAME,
-    CROSSTABS_CELLS
-#undef CS
-    N_CROSSTABS_CELLS
-  };
-
-enum
-  {
-#define CS(NAME, LABEL) B_CS_##NAME = 1u << CS_##NAME,
-    CROSSTABS_STATS
-    CROSSTABS_CELLS
-#undef CS
-    B_CS_STATS_ALL = (1u << N_CROSSTABS_STATS) - 1,
-    B_CS_CELLS_ALL = (1u << N_CROSSTABS_CELLS) - 1,
-    B_CS_STATS_DEFAULT = B_CS_CHISQ,
-    B_CS_CELL_DEFAULT = B_CS_COUNT | B_CS_ROW | B_CS_COLUMN | B_CS_TOTAL,
-    B_CS_NONE
-  };
-
-static const struct checkbox_entry_item stats[] =
-  {
-#define CS(NAME, LABEL) {#NAME, LABEL},
-    CROSSTABS_STATS \
-    CS(NONE, N_("None"))
-#undef CS
-  };
-
-static const struct checkbox_entry_item cells[] =
-  {
-#define CS(NAME, LABEL) {#NAME, LABEL},
-    CROSSTABS_CELLS \
-    CS(NONE, N_("None"))
-#undef CS
-  };
-
-struct format_options
-{
-  gboolean avalue;
-  gboolean pivot;
-  gboolean table;
-};
-
-struct crosstabs_dialog
-{
-  GtkTreeView *row_vars;
-  GtkTreeView *col_vars;
-  PsppireDict *dict;
-
-  GtkToggleButton *table_button;
-  GtkToggleButton *pivot_button;
-
-  GtkWidget *format_dialog;
-  GtkWidget *cell_dialog;
-  GtkWidget *stat_dialog;
-
-  GtkToggleButton  *avalue;
-  GtkTreeModel *stat;
-  GtkTreeModel *cell;
-
-  GtkWidget *stat_view;
-  GtkWidget *cell_view;
-  struct format_options current_opts;
-};
-
-static void
-refresh (PsppireDialog *dialog, struct crosstabs_dialog *cd)
-{
-  GtkTreeModel *liststore = gtk_tree_view_get_model (cd->row_vars);
-  gtk_list_store_clear (GTK_LIST_STORE (liststore));
-  
-  liststore = gtk_tree_view_get_model (cd->col_vars);
-  gtk_list_store_clear (GTK_LIST_STORE (liststore));
-}
-static void
-on_format_clicked (struct crosstabs_dialog *cd)
-{
-  int ret;
-
-  if (cd->current_opts.avalue)
-    {
-      gtk_toggle_button_set_active (cd->avalue, TRUE);
-    }
-  if (cd->current_opts.table)
-    {
-      gtk_toggle_button_set_active (cd->table_button, TRUE);
-    }
-  if (cd->current_opts.pivot)
-    {
-      gtk_toggle_button_set_active (cd->pivot_button, TRUE);
-    }
-
-  ret = psppire_dialog_run (PSPPIRE_DIALOG (cd->format_dialog));
-
-  if ( ret == PSPPIRE_RESPONSE_CONTINUE )
-    {
-      cd->current_opts.avalue = (gtk_toggle_button_get_active (cd->avalue) == TRUE ) 
-       ? TRUE : FALSE;
-      cd->current_opts.table = (gtk_toggle_button_get_active (cd->table_button) == TRUE)
-       ? TRUE : FALSE;
-      cd->current_opts.pivot = (gtk_toggle_button_get_active (cd->pivot_button) == TRUE)
-       ? TRUE : FALSE;
-    }
-}
-
-static void
-on_statistics_clicked (struct crosstabs_dialog *cd)
-{
-  GtkListStore *liststore;
-  int ret;
-
-  liststore = clone_list_store (GTK_LIST_STORE (cd->stat));
-
-  ret = psppire_dialog_run (PSPPIRE_DIALOG (cd->stat_dialog));
-
-  if ( ret == PSPPIRE_RESPONSE_CONTINUE )
-    {
-      g_object_unref (liststore);
-    }
-  else
-    {
-      g_object_unref (cd->stat);
-      gtk_tree_view_set_model (GTK_TREE_VIEW (cd->stat_view) , GTK_TREE_MODEL (liststore));
-      cd->stat = GTK_TREE_MODEL (liststore);
-    }
-}
-static void
-on_cell_clicked (struct crosstabs_dialog *cd)
-{
-  GtkListStore *liststore;
-  int ret;
-
-  liststore = clone_list_store (GTK_LIST_STORE (cd->cell));
-
-  ret = psppire_dialog_run (PSPPIRE_DIALOG (cd->cell_dialog));
-
-  if ( ret == PSPPIRE_RESPONSE_CONTINUE )
-    {
-      g_object_unref (liststore);
-    }
-  else
-    {
-      g_object_unref (cd->cell);
-      gtk_tree_view_set_model (GTK_TREE_VIEW (cd->cell_view) , GTK_TREE_MODEL (liststore));
-      cd->cell = GTK_TREE_MODEL (liststore);
-    }
-}
-
-static char *
-generate_syntax (const struct crosstabs_dialog *cd)
-{
-  gint i;
-  int n;
-  guint selected;
-  GtkTreeIter iter;
-  gboolean ok;
-
-  gchar *text;
-  GString *string = g_string_new ("CROSSTABS");
-
-  g_string_append (string, "\n\t/TABLES=");
-  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (cd->row_vars), 0, string);
-  g_string_append (string, "\tBY\t");
-  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (cd->col_vars), 0, string);
-
-  g_string_append (string, "\n\t/FORMAT=");
-
-  if (cd->current_opts.avalue)
-    {
-      g_string_append (string, "AVALUE");
-    }
-  else 
-    {
-      g_string_append (string, "DVALUE");
-    }
-  g_string_append (string, " ");
-  if (cd->current_opts.table)
-    g_string_append (string, "TABLES");
-  else
-    g_string_append (string, "NOTABLES");
-  g_string_append (string, " ");
-
-  if (cd->current_opts.pivot)
-    g_string_append (string, "PIVOT");
-  else 
-    g_string_append (string, "NOPIVOT");
-
-  selected = 0;
-  for (i = 0, ok = gtk_tree_model_get_iter_first (cd->stat, &iter); ok; 
-       i++, ok = gtk_tree_model_iter_next (cd->stat, &iter))
-    {
-      gboolean toggled;
-      gtk_tree_model_get (cd->stat, &iter,
-                         CHECKBOX_COLUMN_SELECTED, &toggled, -1); 
-      if (toggled) 
-       selected |= 1u << i; 
-      else 
-       selected &= ~(1u << i);
-    }
-
-  if (!(selected & (1u << CS_STATS_NONE)))
-    {
-      if (selected)
-       {
-         g_string_append (string, "\n\t/STATISTICS=");
-         n = 0;
-         for (i = 0; i < N_CROSSTABS_STATS; i++)
-           if (selected & (1u << i))
-             {
-               if (n++)
-                 g_string_append (string, " ");
-               g_string_append (string, stats[i].name);
-             }
-       }
-    }
-
-  selected = 0;
-  for (i = 0, ok = gtk_tree_model_get_iter_first (cd->cell, &iter); ok; 
-       i++, ok = gtk_tree_model_iter_next (cd->cell, &iter))
-    {
-      gboolean toggled;
-      gtk_tree_model_get (cd->cell, &iter,
-                         CHECKBOX_COLUMN_SELECTED, &toggled, -1); 
-      if (toggled) 
-       selected |= 1u << i; 
-      else 
-       selected &= ~(1u << i);
-    }
-
-  g_string_append (string, "\n\t/CELLS=");
-  if (selected & (1u << CS_CELLS_NONE))
-    g_string_append (string, "NONE");
-  else
-    {
-      n = 0;
-      for (i = 0; i < N_CROSSTABS_CELLS; i++)
-       if (selected & (1u << i))
-         {
-           if (n++)
-             g_string_append (string, " ");
-           g_string_append (string, cells[i].name);
-         }
-    }
-  
-  g_string_append (string, ".\n");
-
-  text = string->str;
-
-  g_string_free (string, FALSE);
-
-  return text;
-}
-
-/* Dialog is valid iff at least one row and one column variable has
-   been selected. */
-static gboolean
-dialog_state_valid (gpointer data)
-{
-  struct crosstabs_dialog *cd = data;
-
-  GtkTreeModel *row_vars = gtk_tree_view_get_model (cd->row_vars);
-  GtkTreeModel *col_vars = gtk_tree_view_get_model (cd->col_vars);
-
-  GtkTreeIter notused;
-
-  return (gtk_tree_model_get_iter_first (row_vars, &notused) 
-    && gtk_tree_model_get_iter_first (col_vars, &notused));
-}
-
-/* Pops up the Crosstabs dialog box */
-void
-crosstabs_dialog (PsppireDataWindow *de)
-{
-  gint response;
-  struct crosstabs_dialog cd;
-
-  GtkBuilder *xml = builder_new ("crosstabs.ui");
-  PsppireVarStore *vs = NULL;
-  PsppireDict *dict = NULL;
-
-
-  GtkWidget *dialog = get_widget_assert   (xml, "crosstabs-dialog");
-  GtkWidget *source = get_widget_assert   (xml, "dict-treeview");
-  GtkWidget *dest_rows =   get_widget_assert   (xml, "rows");
-  GtkWidget *dest_cols =   get_widget_assert   (xml, "cols");
-  GtkWidget *format_button = get_widget_assert (xml, "format-button");
-  GtkWidget *stat_button = get_widget_assert (xml, "stats-button");
-  GtkWidget *cell_button = get_widget_assert (xml, "cell-button");
-
-
-  cd.stat_view = get_widget_assert (xml, "stats-view");
-  cd.cell_view = get_widget_assert (xml, "cell-view");
-
-  g_object_get (de->data_editor, "var-store", &vs, NULL);
-
-  put_checkbox_items_in_treeview (GTK_TREE_VIEW(cd.stat_view),
-                                 B_CS_STATS_DEFAULT,
-                                 N_CROSSTABS_STATS,
-                                 stats
-                                 );
-  put_checkbox_items_in_treeview (GTK_TREE_VIEW(cd.cell_view),
-                                 B_CS_CELL_DEFAULT,
-                                 N_CROSSTABS_CELLS,
-                                 cells
-                                 );
-
-  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
-
-  g_object_get (vs, "dictionary", &dict, NULL);
-  g_object_set (source, "model", dict, NULL);
-
-  cd.row_vars = GTK_TREE_VIEW (dest_rows);
-  cd.col_vars = GTK_TREE_VIEW (dest_cols);
-  g_object_get (vs, "dictionary", &cd.dict, NULL);
-  cd.format_dialog = get_widget_assert (xml, "format-dialog");
-  cd.table_button = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "print-tables"));
-  cd.pivot_button = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "pivot"));
-  cd.stat_dialog = get_widget_assert (xml, "stat-dialog");
-  cd.cell_dialog = get_widget_assert (xml, "cell-dialog");
-
-  cd.stat = gtk_tree_view_get_model (GTK_TREE_VIEW (cd.stat_view));
-  cd.cell = gtk_tree_view_get_model (GTK_TREE_VIEW (cd.cell_view));
-  cd.avalue = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "ascending"));
-  cd.current_opts.avalue = TRUE;
-  cd.current_opts.table = TRUE;
-  cd.current_opts.pivot = TRUE;
-
-  gtk_window_set_transient_for (GTK_WINDOW (cd.format_dialog), GTK_WINDOW (de));
-  gtk_window_set_transient_for (GTK_WINDOW (cd.cell_dialog), GTK_WINDOW (de));
-  gtk_window_set_transient_for (GTK_WINDOW (cd.stat_dialog), GTK_WINDOW (de));
-
-  g_signal_connect (dialog, "refresh", G_CALLBACK (refresh),  &cd);
-
-  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
-                                     dialog_state_valid, &cd);
-
-  g_signal_connect_swapped (format_button, "clicked",
-                           G_CALLBACK (on_format_clicked),  &cd);
-  g_signal_connect_swapped (stat_button, "clicked",
-                           G_CALLBACK (on_statistics_clicked),  &cd);
-  g_signal_connect_swapped (cell_button, "clicked",
-                           G_CALLBACK (on_cell_clicked),  &cd);
-
-  response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
-
-
-  switch (response)
-    {
-    case GTK_RESPONSE_OK:
-      g_free (execute_syntax_string (de, generate_syntax (&cd)));
-      break;
-    case PSPPIRE_RESPONSE_PASTE:
-      g_free (paste_syntax_to_window (generate_syntax (&cd)));
-      break;
-    default:
-      break;
-    }
-
-  g_object_unref (xml);
-}
diff --git a/src/ui/gui/crosstabs-dialog.h b/src/ui/gui/crosstabs-dialog.h
deleted file mode 100644 (file)
index 65e4761..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2008, 2010  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/>. */
-
-#ifndef __CROSSTABS_DIALOG_H
-#define __CROSSTABS_DIALOG_H
-
-#include "psppire-data-window.h"
-
-void crosstabs_dialog (PsppireDataWindow * data);
-
-#endif
index 8d948a5b6e9c0b648b9c15b8d5a2d3887a221f66..da3a4a5e5999ebd6b2efc50e86baa1de5947ef69 100644 (file)
           </object>
         </child>
         <child>
-          <object class="GtkAction" id="crosstabs">
+          <object class="PsppireDialogActionCrosstabs" id="crosstabs">
             <property name="name">crosstabs</property>
+            <property name="manager">uimanager1</property>
             <property name="label" translatable="yes">_Crosstabs...</property>
           </object>
         </child>
index 3a032f0a285de1cc050d3d47b22aafd99e73cf34..9e5860b7199521358c3ae57a4eb08de8d882d32c 100644 (file)
@@ -31,7 +31,6 @@
 #include "ui/gui/comments-dialog.h"
 #include "ui/gui/compute-dialog.h"
 #include "ui/gui/count-dialog.h"
-#include "ui/gui/crosstabs-dialog.h"
 #include "ui/gui/entry-dialog.h"
 #include "ui/gui/executor.h"
 #include "ui/gui/find-dialog.h"
@@ -1090,7 +1089,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
   connect_action (de, "transform_count", G_CALLBACK (count_dialog));
   connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog));
   connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog));
-  connect_action (de, "crosstabs", G_CALLBACK (crosstabs_dialog));
   connect_action (de, "univariate", G_CALLBACK (univariate_dialog));
   connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog));
   connect_action (de, "runs", G_CALLBACK (runs_dialog));
diff --git a/src/ui/gui/psppire-dialog-action-crosstabs.c b/src/ui/gui/psppire-dialog-action-crosstabs.c
new file mode 100644 (file)
index 0000000..2bc07c6
--- /dev/null
@@ -0,0 +1,395 @@
+/* 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 <config.h>
+
+#include "psppire-dialog-action-crosstabs.h"
+#include "psppire-value-entry.h"
+
+#include "dialog-common.h"
+#include "helper.h"
+#include <ui/syntax-gen.h>
+#include "psppire-var-view.h"
+
+#include "psppire-dialog.h"
+#include "builder-wrapper.h"
+#include "checkbox-treeview.h"
+#include "psppire-dict.h"
+#include "libpspp/str.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
+
+static void
+psppire_dialog_action_crosstabs_class_init (PsppireDialogActionCrosstabsClass *class);
+
+G_DEFINE_TYPE (PsppireDialogActionCrosstabs, psppire_dialog_action_crosstabs, PSPPIRE_TYPE_DIALOG_ACTION);
+
+static gboolean
+dialog_state_valid (gpointer data)
+{
+  PsppireDialogActionCrosstabs *cd = PSPPIRE_DIALOG_ACTION_CROSSTABS (data);
+
+  GtkTreeModel *row_vars = gtk_tree_view_get_model (GTK_TREE_VIEW (cd->dest_rows));
+  GtkTreeModel *col_vars = gtk_tree_view_get_model (GTK_TREE_VIEW (cd->dest_cols));
+
+  GtkTreeIter notused;
+
+  return (gtk_tree_model_get_iter_first (row_vars, &notused) 
+    && gtk_tree_model_get_iter_first (col_vars, &notused));
+}
+
+static void
+refresh (PsppireDialogAction *rd_)
+{
+  PsppireDialogActionCrosstabs *cd = PSPPIRE_DIALOG_ACTION_CROSSTABS (rd_);
+
+  GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (cd->dest_rows));
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+  
+  liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (cd->dest_cols));
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+}
+
+#define CROSSTABS_STATS                         \
+  CS (CHISQ, N_("Chisq"))                       \
+  CS (PHI, N_("Phi"))                           \
+  CS (CC, N_("CC"))                             \
+  CS (LAMBDA, N_("Lambda"))                     \
+  CS (UC, N_("UC"))                             \
+  CS (BTAU, N_("BTau"))                         \
+  CS (CTAU, N_("CTau"))                         \
+  CS (RISK, N_("Risk"))                         \
+  CS (GAMMA, N_("Gamma"))                       \
+  CS (D, N_("D"))                               \
+  CS (KAPPA, N_("Kappa"))                       \
+  CS (ETA, N_("Eta"))                           \
+  CS (CORR, N_("Corr"))                         \
+  CS (STATS_NONE, N_("None"))
+
+
+#define CROSSTABS_CELLS                         \
+  CS (COUNT, N_("Count"))                       \
+  CS (ROW, N_("Row"))                           \
+  CS (COLUMN, N_("Column"))                     \
+  CS (TOTAL, N_("Total"))                       \
+  CS (EXPECTED, N_("Expected"))                 \
+  CS (RESIDUAL, N_("Residual"))                 \
+  CS (SRESIDUAL, N_("Std. Residual"))           \
+  CS (ASRESIDUAL, N_("Adjusted Std. Residual")) \
+  CS (CELLS_NONE, N_("None"))
+
+enum
+  {
+#define CS(NAME, LABEL) CS_##NAME,
+    CROSSTABS_STATS
+#undef CS
+    N_CROSSTABS_STATS
+  };
+
+enum
+  {
+#define CS(NAME, LABEL) CS_##NAME,
+    CROSSTABS_CELLS
+#undef CS
+    N_CROSSTABS_CELLS
+  };
+
+enum
+  {
+#define CS(NAME, LABEL) B_CS_##NAME = 1u << CS_##NAME,
+    CROSSTABS_STATS
+    CROSSTABS_CELLS
+#undef CS
+    B_CS_STATS_ALL = (1u << N_CROSSTABS_STATS) - 1,
+    B_CS_CELLS_ALL = (1u << N_CROSSTABS_CELLS) - 1,
+    B_CS_STATS_DEFAULT = B_CS_CHISQ,
+    B_CS_CELL_DEFAULT = B_CS_COUNT | B_CS_ROW | B_CS_COLUMN | B_CS_TOTAL,
+    B_CS_NONE
+  };
+
+static const struct checkbox_entry_item stats[] =
+  {
+#define CS(NAME, LABEL) {#NAME, LABEL},
+    CROSSTABS_STATS \
+    CS(NONE, N_("None"))
+#undef CS
+  };
+
+static const struct checkbox_entry_item cells[] =
+  {
+#define CS(NAME, LABEL) {#NAME, LABEL},
+    CROSSTABS_CELLS \
+    CS(NONE, N_("None"))
+#undef CS
+  };
+
+static void
+on_format_clicked (PsppireDialogActionCrosstabs *cd)
+{
+  int ret;
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cd->avalue_button), cd->format_options_avalue);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cd->table_button), cd->format_options_table);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cd->pivot_button), cd->format_options_pivot);
+
+  ret = psppire_dialog_run (PSPPIRE_DIALOG (cd->format_dialog));
+
+  if ( ret == PSPPIRE_RESPONSE_CONTINUE )
+    {
+      cd->format_options_avalue =
+       gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cd->avalue_button));
+
+      cd->format_options_table =
+       gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cd->table_button));
+
+      cd->format_options_pivot = 
+       gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cd->pivot_button));
+    }
+}
+
+static void
+on_cell_clicked (PsppireDialogActionCrosstabs *cd)
+{
+  GtkListStore *liststore = clone_list_store (GTK_LIST_STORE (cd->cell));
+
+  gint ret = psppire_dialog_run (PSPPIRE_DIALOG (cd->cell_dialog));
+
+  if ( ret == PSPPIRE_RESPONSE_CONTINUE )
+    {
+      g_object_unref (liststore);
+    }
+  else
+    {
+      gtk_tree_view_set_model (GTK_TREE_VIEW (cd->cell_view) , GTK_TREE_MODEL (liststore));
+      cd->cell = GTK_TREE_MODEL (liststore);
+    }
+}
+
+
+static void
+on_statistics_clicked (PsppireDialogActionCrosstabs *cd)
+{
+  GtkListStore *liststore = clone_list_store (GTK_LIST_STORE (cd->stat));
+
+  gint ret = psppire_dialog_run (PSPPIRE_DIALOG (cd->stat_dialog));
+
+  if ( ret == PSPPIRE_RESPONSE_CONTINUE )
+    {
+      g_object_unref (liststore);
+    }
+  else
+    {
+      gtk_tree_view_set_model (GTK_TREE_VIEW (cd->stat_view) , GTK_TREE_MODEL (liststore));
+      cd->stat = GTK_TREE_MODEL (liststore);
+    }
+}
+
+
+static void
+psppire_dialog_action_crosstabs_activate (GtkAction *a)
+{
+  PsppireDialogActionCrosstabs *act = PSPPIRE_DIALOG_ACTION_CROSSTABS (a);
+  PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
+
+  GtkBuilder *xml = builder_new ("crosstabs.ui");
+
+  pda->dialog = get_widget_assert   (xml, "crosstabs-dialog");
+  pda->source = get_widget_assert   (xml, "dict-treeview");
+
+  act->dest_rows =   get_widget_assert   (xml, "rows");
+  act->dest_cols =   get_widget_assert   (xml, "cols");
+  act->format_button = get_widget_assert (xml, "format-button");
+  act->stat_button = get_widget_assert (xml, "stats-button");
+  act->cell_button = get_widget_assert (xml, "cell-button");
+  act->stat_view =   get_widget_assert (xml, "stats-view");
+  act->cell_view =   get_widget_assert (xml, "cell-view");
+  act->cell_dialog = get_widget_assert (xml, "cell-dialog");
+  act->stat_dialog = get_widget_assert (xml, "stat-dialog");
+  act->format_dialog = get_widget_assert (xml, "format-dialog");
+
+  act->avalue_button = get_widget_assert (xml, "ascending");
+  act->table_button = get_widget_assert (xml, "print-tables");
+  act->pivot_button = get_widget_assert (xml, "pivot");
+
+
+  g_object_unref (xml);
+
+  act->format_options_avalue = TRUE;
+  act->format_options_table = TRUE;
+  act->format_options_pivot = TRUE;
+
+  put_checkbox_items_in_treeview (GTK_TREE_VIEW (act->cell_view),
+                                 B_CS_CELL_DEFAULT,
+                                 N_CROSSTABS_CELLS,
+                                 cells
+                                 );
+
+  act->cell = gtk_tree_view_get_model (GTK_TREE_VIEW (act->cell_view));
+
+  put_checkbox_items_in_treeview (GTK_TREE_VIEW (act->stat_view),
+                                 B_CS_STATS_DEFAULT,
+                                 N_CROSSTABS_STATS,
+                                 stats
+                                 );
+
+  act->stat = gtk_tree_view_get_model (GTK_TREE_VIEW (act->stat_view));
+
+  psppire_dialog_action_set_refresh (pda, refresh);
+
+  psppire_dialog_action_set_valid_predicate (pda,
+                                       dialog_state_valid);
+
+  g_signal_connect_swapped (act->cell_button, "clicked",
+                           G_CALLBACK (on_cell_clicked), act);
+
+  g_signal_connect_swapped (act->stat_button, "clicked",
+                           G_CALLBACK (on_statistics_clicked), act);
+
+  g_signal_connect_swapped (act->format_button, "clicked",
+                           G_CALLBACK (on_format_clicked), act);
+
+
+  if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_crosstabs_parent_class)->activate)
+    PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_crosstabs_parent_class)->activate (pda);
+}
+
+
+
+static char *
+generate_syntax (PsppireDialogAction *a)
+{
+  PsppireDialogActionCrosstabs *cd = PSPPIRE_DIALOG_ACTION_CROSSTABS (a);
+  gchar *text = NULL;
+  int i, n;
+  guint selected;
+  GString *string = g_string_new ("CROSSTABS ");
+  gboolean ok;
+  GtkTreeIter iter;
+
+  g_string_append (string, "\n\t/TABLES=");
+  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (cd->dest_rows), 0, string);
+  g_string_append (string, "\tBY\t");
+  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (cd->dest_cols), 0, string);
+
+
+  g_string_append (string, "\n\t/FORMAT=");
+
+  if (cd->format_options_avalue)
+    g_string_append (string, "AVALUE");
+  else 
+    g_string_append (string, "DVALUE");
+  g_string_append (string, " ");
+
+  if (cd->format_options_table)
+    g_string_append (string, "TABLES");
+  else
+    g_string_append (string, "NOTABLES");
+  g_string_append (string, " ");
+
+  if (cd->format_options_pivot)
+    g_string_append (string, "PIVOT");
+  else 
+    g_string_append (string, "NOPIVOT");
+
+
+  selected = 0;
+  for (i = 0, ok = gtk_tree_model_get_iter_first (cd->stat, &iter); ok; 
+       i++, ok = gtk_tree_model_iter_next (cd->stat, &iter))
+    {
+      gboolean toggled;
+      gtk_tree_model_get (cd->stat, &iter,
+                         CHECKBOX_COLUMN_SELECTED, &toggled, -1); 
+      if (toggled) 
+       selected |= 1u << i; 
+      else 
+       selected &= ~(1u << i);
+    }
+
+  if (!(selected & (1u << CS_STATS_NONE)))
+    {
+      if (selected)
+       {
+         g_string_append (string, "\n\t/STATISTICS=");
+         n = 0;
+         for (i = 0; i < N_CROSSTABS_STATS; i++)
+           if (selected & (1u << i))
+             {
+               if (n++)
+                 g_string_append (string, " ");
+               g_string_append (string, stats[i].name);
+             }
+       }
+    }
+
+  selected = 0;
+  for (i = 0, ok = gtk_tree_model_get_iter_first (cd->cell, &iter); ok; 
+       i++, ok = gtk_tree_model_iter_next (cd->cell, &iter))
+    {
+      gboolean toggled;
+      gtk_tree_model_get (cd->cell, &iter,
+                         CHECKBOX_COLUMN_SELECTED, &toggled, -1); 
+      if (toggled) 
+       selected |= 1u << i; 
+      else 
+       selected &= ~(1u << i);
+    }
+
+
+
+  g_string_append (string, "\n\t/CELLS=");
+  if (selected & (1u << CS_CELLS_NONE))
+    g_string_append (string, "NONE");
+  else
+    {
+      n = 0;
+      for (i = 0; i < N_CROSSTABS_CELLS; i++)
+       if (selected & (1u << i))
+         {
+           if (n++)
+             g_string_append (string, " ");
+           g_string_append (string, cells[i].name);
+         }
+    }
+
+  g_string_append (string, ".\n");
+
+  text = string->str;
+
+  g_string_free (string, FALSE);
+
+  return text;
+}
+
+static void
+psppire_dialog_action_crosstabs_class_init (PsppireDialogActionCrosstabsClass *class)
+{
+  GtkActionClass *action_class = GTK_ACTION_CLASS (class);
+
+  action_class->activate = psppire_dialog_action_crosstabs_activate;
+
+  PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
+}
+
+
+static void
+psppire_dialog_action_crosstabs_init (PsppireDialogActionCrosstabs *act)
+{
+}
+
diff --git a/src/ui/gui/psppire-dialog-action-crosstabs.h b/src/ui/gui/psppire-dialog-action-crosstabs.h
new file mode 100644 (file)
index 0000000..ee8169a
--- /dev/null
@@ -0,0 +1,102 @@
+/* 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_CROSSTABS_H__
+#define __PSPPIRE_DIALOG_ACTION_CROSSTABS_H__
+
+G_BEGIN_DECLS
+
+
+#define PSPPIRE_TYPE_DIALOG_ACTION_CROSSTABS (psppire_dialog_action_crosstabs_get_type ())
+
+#define PSPPIRE_DIALOG_ACTION_CROSSTABS(obj)   \
+                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                 PSPPIRE_TYPE_DIALOG_ACTION_CROSSTABS, PsppireDialogActionCrosstabs))
+
+#define PSPPIRE_DIALOG_ACTION_CROSSTABS_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_CAST ((klass), \
+                                PSPPIRE_TYPE_DIALOG_ACTION_CROSSTABS, \
+                                 PsppireDialogActionCrosstabsClass))
+
+
+#define PSPPIRE_IS_DIALOG_ACTION_CROSSTABS(obj) \
+                    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_CROSSTABS))
+
+#define PSPPIRE_IS_DIALOG_ACTION_CROSSTABS_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_CROSSTABS))
+
+
+#define PSPPIRE_DIALOG_ACTION_CROSSTABS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                  PSPPIRE_TYPE_DIALOG_ACTION_CROSSTABS, \
+                                  PsppireDialogActionCrosstabsClass))
+
+typedef struct _PsppireDialogActionCrosstabs       PsppireDialogActionCrosstabs;
+typedef struct _PsppireDialogActionCrosstabsClass  PsppireDialogActionCrosstabsClass;
+
+
+struct _PsppireDialogActionCrosstabs
+{
+  PsppireDialogAction parent;
+
+  /*< private >*/
+  gboolean dispose_has_run ;
+
+  GtkWidget *col_vars;
+  GtkWidget *row_vars;
+
+  GtkWidget *dest_rows; 
+  GtkWidget *dest_cols ;
+  GtkWidget *format_button ;
+  GtkWidget *stat_button ;
+  GtkWidget *cell_button ;
+
+  GtkWidget *stat_view ;
+
+  GtkWidget *cell_view ;
+  GtkTreeModel *cell ;
+  GtkWidget *cell_dialog ;
+  GtkTreeModel *stat;
+  GtkWidget *stat_dialog ;
+
+  gboolean format_options_avalue;
+  gboolean format_options_pivot;
+  gboolean format_options_table;
+
+  GtkWidget *table_button;
+  GtkWidget *pivot_button;
+
+  GtkWidget *format_dialog;
+  GtkWidget *avalue_button;
+};
+
+
+struct _PsppireDialogActionCrosstabsClass
+{
+  PsppireDialogActionClass parent_class;
+};
+
+
+GType psppire_dialog_action_crosstabs_get_type (void) ;
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_DIALOG_ACTION_CROSSTABS_H__ */
index 433ab4f36bccf60c57e6efbba92319a8856086ab..488656e9e6365173805a373c0fa64e03e6fe8ad6 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "psppire-dialog-action-binomial.h"
 #include "psppire-dialog-action-correlation.h"
+#include "psppire-dialog-action-crosstabs.h"
 #include "psppire-dialog-action-descriptives.h"
 #include "psppire-dialog-action-examine.h"
 #include "psppire-dialog-action-factor.h"
@@ -55,6 +56,7 @@ preregister_widgets (void)
 
   psppire_dialog_action_binomial_get_type ();
   psppire_dialog_action_correlation_get_type ();
+  psppire_dialog_action_crosstabs_get_type ();
   psppire_dialog_action_descriptives_get_type ();
   psppire_dialog_action_examine_get_type ();
   psppire_dialog_action_factor_get_type ();