X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fdialog-common.c;h=c61cb14a64a88ef4b3dba174f194277c5c552216;hb=fb4eeb650749403036535786a7d3660af0945e75;hp=b4a127230fa8e737b46a860363dcbfe2077952f1;hpb=a675bf52fd2ed392ff50f0f86e0efd6aefa29a03;p=pspp-builds.git diff --git a/src/ui/gui/dialog-common.c b/src/ui/gui/dialog-common.c index b4a12723..c61cb14a 100644 --- a/src/ui/gui/dialog-common.c +++ b/src/ui/gui/dialog-common.c @@ -15,130 +15,13 @@ along with this program. If not, see . */ #include -#include "dialog-common.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. -*/ -gint -append_variable_names (GString *string, - PsppireDict *dict, GtkTreeView *treeview) -{ - gint n_vars = 0; - GtkTreeIter iter; - - GtkTreeModel *list_store = - gtk_tree_view_get_model (treeview); - - if ( gtk_tree_model_get_iter_first (list_store, &iter) ) - { - do - { - GValue value = {0}; - struct variable *var; - GtkTreePath *path = gtk_tree_model_get_path (list_store, &iter); - - gtk_tree_model_get_value (list_store, &iter, 0, &value); - - var = psppire_dict_get_variable (dict, g_value_get_int (&value)); - g_value_unset (&value); - - g_string_append (string, " "); - g_string_append (string, var_get_name (var)); - - gtk_tree_path_free (path); - n_vars++; - } - while (gtk_tree_model_iter_next (list_store, &iter)); - } - - return n_vars; -} - - - -struct variable * -get_selected_variable (GtkTreeModel *treemodel, - GtkTreeIter *iter, - PsppireDict *dict) -{ - struct variable *var; - GValue value = {0}; - - GtkTreePath *path = gtk_tree_model_get_path (treemodel, iter); - - gtk_tree_model_get_value (treemodel, iter, 0, &value); - - gtk_tree_path_free (path); - - var = psppire_dict_get_variable (dict, g_value_get_int (&value)); - - g_value_unset (&value); - return var; -} - - - - -/* 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; - - var = get_selected_variable (tree_model, iter, dict); - - name = pspp_locale_to_utf8 (var_get_name (var), -1, NULL); - g_object_set (cell, "text", name, NULL); - g_free (name); -} - - - -/* Set a model for DEST, which is an GtkListStore of g_int's - whose values are the indices into DICT */ -void -set_dest_model (GtkTreeView *dest, PsppireDict *dict) -{ - GtkTreeViewColumn *col; - GtkListStore *dest_list = gtk_list_store_new (1, G_TYPE_INT); - GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); - - 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_tree_view_column_set_cell_data_func (col, renderer, - cell_var_name, - dict, 0); - - /* FIXME: make this a value in terms of character widths */ - g_object_set (col, "min-width", 100, NULL); - - gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED); +#include +#include "dialog-common.h" - gtk_tree_view_append_column (GTK_TREE_VIEW (dest), col); -} +#include "psppire-var-ptr.h" +#include "helper.h" /* Returns FALSE if the variables represented by the union of the rows @@ -178,16 +61,15 @@ homogeneous_types (GtkWidget *source, GtkWidget *dest) for (l = list; l ; l = l->next) { GtkTreePath *path = l->data; - GtkTreePath *fpath; - gint *idx; - const struct variable *v; + GtkTreePath *fpath = + gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (model), path); - fpath = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (model), path); + gint *idx = gtk_tree_path_get_indices (fpath); - idx = gtk_tree_path_get_indices (fpath); + const struct variable *v = psppire_dict_get_variable (dict, idx[0]); - v = psppire_dict_get_variable (dict, idx[0]); + gtk_tree_path_free (fpath); if ( type != -1 ) { @@ -214,11 +96,8 @@ homogeneous_types (GtkWidget *source, GtkWidget *dest) ok; ok = gtk_tree_model_iter_next (model, &iter)) { - gint idx; const struct variable *v; - gtk_tree_model_get (model, &iter, 0, &idx, -1); - - v = psppire_dict_get_variable (dict, idx); + gtk_tree_model_get (model, &iter, 0, &v, -1); if ( type != -1 ) { @@ -232,7 +111,6 @@ homogeneous_types (GtkWidget *source, GtkWidget *dest) type = var_get_type (v); } - return retval; } @@ -265,17 +143,14 @@ numeric_only (GtkWidget *source, GtkWidget *dest) for (l = list; l ; l = l->next) { GtkTreePath *path = l->data; - GtkTreePath *fpath; - gint *idx; - - const struct variable *v; - - fpath = gtk_tree_model_filter_convert_path_to_child_path + GtkTreePath *fpath = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (model), path); - idx = gtk_tree_path_get_indices (fpath); + gint *idx = gtk_tree_path_get_indices (fpath); + + const struct variable *v = psppire_dict_get_variable (dict, idx[0]); - v = psppire_dict_get_variable (dict, idx[0]); + gtk_tree_path_free (fpath); if ( var_is_alpha (v)) {