X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fdialog-common.c;h=9e97923e3f977188d305e791d3f3ad9c1ad887cc;hb=42993d3ae61750a8f1e291297d8ac91465afcff2;hp=4de436774032c2b25a93cec03280ee12a17802e7;hpb=1d5a97ba2afec23855a8294ff2814ab052f6777a;p=pspp
diff --git a/src/ui/gui/dialog-common.c b/src/ui/gui/dialog-common.c
index 4de4367740..9e97923e3f 100644
--- a/src/ui/gui/dialog-common.c
+++ b/src/ui/gui/dialog-common.c
@@ -1,145 +1,194 @@
-/*
- PSPPIRE --- A Graphical User Interface for PSPP
- Copyright (C) 2007 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 2 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-*/
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2007 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 . */
#include
+
+#include
#include "dialog-common.h"
+#include "psppire-var-ptr.h"
+
#include "helper.h"
-/* Append the names of selected variables to STRING.
- TREEVIEW is the treeview containing the variables.
- DICT is the dictionary for those variables.
+/* Returns FALSE if the variables represented by the union of the rows
+ currently selected by SOURCE widget, and contents of the DEST
+ widget, are of different types.
+
+ In other words, this function when passed as the argument to
+ psppire_selector_set_allow, ensures that the selector selects only
+ string variables, or only numeric variables, not a mixture.
*/
-gint
-append_variable_names (GString *string,
- PsppireDict *dict, GtkTreeView *treeview)
+gboolean
+homogeneous_types (GtkWidget *source, GtkWidget *dest)
{
- gint n_vars = 0;
+ gboolean ok;
GtkTreeIter iter;
+ gboolean retval = TRUE;
+
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source));
+
+ PsppireDict *dict;
+ GtkTreeSelection *selection;
+ enum val_type type = -1;
+ GList *list, *l;
+
+ while (GTK_IS_TREE_MODEL_FILTER (model))
+ {
+ model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
+ }
+
+ dict = PSPPIRE_DICT (model);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));
- GtkTreeModel *list_store =
- gtk_tree_view_get_model (treeview);
+ list = gtk_tree_selection_get_selected_rows (selection, &model);
- if ( gtk_tree_model_get_iter_first (list_store, &iter) )
+ /* Iterate through the selection of the source treeview */
+ for (l = list; l ; l = l->next)
{
- do
+ GtkTreePath *path = l->data;
+
+ GtkTreePath *fpath =
+ gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (model), path);
+
+ gint *idx = gtk_tree_path_get_indices (fpath);
+
+ const struct variable *v = psppire_dict_get_variable (dict, idx[0]);
+
+ gtk_tree_path_free (fpath);
+
+ if ( type != -1 )
{
- GValue value = {0};
- struct variable *var;
- GtkTreePath *path = gtk_tree_model_get_path (list_store, &iter);
+ if ( var_get_type (v) != type )
+ {
+ retval = FALSE;
+ break;
+ }
+ }
+
+ type = var_get_type (v);
+ }
+
+ g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
+ g_list_free (list);
- gtk_tree_model_get_value (list_store, &iter, 0, &value);
+ if ( retval == FALSE )
+ return FALSE;
- var = psppire_dict_get_variable (dict, g_value_get_int (&value));
- g_value_unset (&value);
+ /* now deal with the dest widget */
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
- g_string_append (string, " ");
- g_string_append (string, var_get_name (var));
+ for (ok = gtk_tree_model_get_iter_first (model, &iter);
+ ok;
+ ok = gtk_tree_model_iter_next (model, &iter))
+ {
+ const struct variable *v;
+ gtk_tree_model_get (model, &iter, 0, &v, -1);
- gtk_tree_path_free (path);
- n_vars++;
+ if ( type != -1 )
+ {
+ if ( var_get_type (v) != type )
+ {
+ retval = FALSE;
+ break;
+ }
}
- while (gtk_tree_model_iter_next (list_store, &iter));
+
+ type = var_get_type (v);
}
- return n_vars;
+ return retval;
}
-struct variable *
-get_selected_variable (GtkTreeModel *treemodel,
- GtkTreeIter *iter,
- PsppireDict *dict)
+/* Returns true iff the variable selected by SOURCE is numeric */
+gboolean
+numeric_only (GtkWidget *source, GtkWidget *dest)
{
- struct variable *var;
- GValue value = {0};
+ gboolean retval = TRUE;
- GtkTreePath *path = gtk_tree_model_get_path (treemodel, iter);
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source));
- gtk_tree_model_get_value (treemodel, iter, 0, &value);
+ PsppireDict *dict;
+ GtkTreeSelection *selection;
+ GList *list, *l;
- gtk_tree_path_free (path);
-
- var = psppire_dict_get_variable (dict, g_value_get_int (&value));
+ while (GTK_IS_TREE_MODEL_FILTER (model))
+ {
+ model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
+ }
- g_value_unset (&value);
+ dict = PSPPIRE_DICT (model);
- return var;
-}
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));
+ list = gtk_tree_selection_get_selected_rows (selection, &model);
+ /* Iterate through the selection of the source treeview */
+ for (l = list; l ; l = l->next)
+ {
+ GtkTreePath *path = l->data;
+ GtkTreePath *fpath = gtk_tree_model_filter_convert_path_to_child_path
+ (GTK_TREE_MODEL_FILTER (model), path);
+ gint *idx = gtk_tree_path_get_indices (fpath);
-/* A (*GtkTreeCellDataFunc) function.
- This function expects TREEMODEL to hold G_TYPE_INT. The ints it holds
- are the indices of the variables in the dictionary, which DATA points to.
- It renders the name of the variable into CELL.
-*/
-void
-cell_var_name (GtkTreeViewColumn *tree_column,
- GtkCellRenderer *cell,
- GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- gpointer data)
-{
- PsppireDict *dict = data;
- struct variable *var;
- gchar *name;
+ const struct variable *v = psppire_dict_get_variable (dict, idx[0]);
- var = get_selected_variable (tree_model, iter, dict);
+ gtk_tree_path_free (fpath);
- name = pspp_locale_to_utf8 (var_get_name (var), -1, NULL);
- g_object_set (cell, "text", name, NULL);
- g_free (name);
-}
+ if ( var_is_alpha (v))
+ {
+ retval = FALSE;
+ break;
+ }
+ }
+ g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
+ g_list_free (list);
+ return retval;
+}
-/* Set a model for DEST, which is an GtkListStore of g_int's
- whose values are the indices into DICT */
+/*
+ A pair of functions intended to be used as callbacks for the "toggled" signal
+ of a GtkToggleButton widget. They make the sensitivity of W follow the status
+ of the togglebutton.
+*/
void
-set_dest_model (GtkTreeView *dest, PsppireDict *dict)
+set_sensitivity_from_toggle (GtkToggleButton *togglebutton, GtkWidget *w)
{
- GtkTreeViewColumn *col;
- GtkListStore *dest_list = gtk_list_store_new (1, G_TYPE_INT);
- GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
+ gboolean active = gtk_toggle_button_get_active (togglebutton);
- gtk_tree_view_set_model (GTK_TREE_VIEW (dest), GTK_TREE_MODEL (dest_list));
-
- col = gtk_tree_view_column_new_with_attributes ("Var",
- renderer,
- "text",
- 0,
- NULL);
+ gtk_widget_set_sensitive (w, active);
+ if (active)
+ gtk_widget_grab_focus (w);
+}
- gtk_tree_view_column_set_cell_data_func (col, renderer,
- cell_var_name,
- dict, 0);
+/* */
+void
+set_sensitivity_from_toggle_invert (GtkToggleButton *togglebutton,
+ GtkWidget *w)
+{
+ gboolean active = gtk_toggle_button_get_active (togglebutton);
- /* FIXME: make this a value in terms of character widths */
- g_object_set (col, "min-width", 100, NULL);
+ gtk_widget_set_sensitive (w, !active);
+}
- gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
- gtk_tree_view_append_column (GTK_TREE_VIEW(dest), col);
-}