/* Inserts the name of the selected variable into the destination widget. The destination widget must be a GtkTextView */ static void insert_source_row_into_text_view (GtkTreeIter iter, GtkWidget *dest, GtkTreeModel *model, gpointer data ) { GtkTreePath *path; PsppireDict *dict; gint *idx; struct variable *var; GtkTreeIter dict_iter; GtkTextBuffer *buffer; g_return_if_fail (GTK_IS_TEXT_VIEW (dest)); if ( GTK_IS_TREE_MODEL_FILTER (model)) { dict = PSPPIRE_DICT (gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(model))); gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &dict_iter, &iter); } else { dict = PSPPIRE_DICT (model); dict_iter = iter; } path = gtk_tree_model_get_path (GTK_TREE_MODEL (dict), &dict_iter); idx = gtk_tree_path_get_indices (path); var = psppire_dict_get_variable (dict, *idx); gtk_tree_path_free (path); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dest)); erase_selection (buffer); gtk_text_buffer_insert_at_cursor (buffer, var_get_name (var), -1); }
/* Returns true iff the variable selected by SOURCE is numeric */ gboolean numeric_only (GtkWidget *source, GtkWidget *dest) { gboolean retval = TRUE; GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source)); PsppireDict *dict; GtkTreeSelection *selection; 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)); 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); const struct variable *v = psppire_dict_get_variable (dict, idx[0]); gtk_tree_path_free (fpath); if ( var_is_alpha (v)) { retval = FALSE; break; } } g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL); g_list_free (list); return retval; }
/* Returns true iff the variable selected by SOURCE is numeric */ gboolean numeric_only (GtkWidget *source, GtkWidget *dest) { gboolean retval = TRUE; GtkTreeModel *top_model = gtk_tree_view_get_model (GTK_TREE_VIEW (source)); GtkTreeModel *model = NULL; PsppireDict *dict; GtkTreeSelection *selection; GList *list, *l; get_base_model (top_model, NULL, &model, NULL); dict = PSPPIRE_DICT (model); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source)); list = gtk_tree_selection_get_selected_rows (selection, &top_model); /* Iterate through the selection of the source treeview */ for (l = list; l ; l = l->next) { GtkTreePath *p = get_base_tree_path (top_model, l->data); gint *idx = gtk_tree_path_get_indices (p); const struct variable *v = psppire_dict_get_variable (dict, idx[0]); gtk_tree_path_free (p); if ( var_is_alpha (v)) { retval = FALSE; break; } } g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL); g_list_free (list); return retval; }
/* 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. */ gboolean homogeneous_types (GtkWidget *source, GtkWidget *dest) { gboolean ok; GtkTreeIter iter; gboolean retval = TRUE; GtkTreeModel *top_model = gtk_tree_view_get_model (GTK_TREE_VIEW (source)); GtkTreeModel *model; PsppireDict *dict; GtkTreeSelection *selection; enum val_type type; GList *list, *l; bool have_type; get_base_model (top_model, NULL, &model, NULL); dict = PSPPIRE_DICT (model); 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 */ have_type = false; for (l = list; l ; l = l->next) { GtkTreePath *p = get_base_tree_path (top_model, l->data); gint *idx = gtk_tree_path_get_indices (p); const struct variable *v = psppire_dict_get_variable (dict, idx[0]); gtk_tree_path_free (p); if (have_type && var_get_type (v) != type) { retval = FALSE; break; } type = var_get_type (v); have_type = true; } g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL); g_list_free (list); if ( retval == FALSE ) return FALSE; /* now deal with the dest widget */ model = gtk_tree_view_get_model (GTK_TREE_VIEW (dest)); 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); if ( have_type && var_get_type (v) != type ) { retval = FALSE; break; } type = var_get_type (v); have_type = true; } return retval; }
/* 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. */ gboolean homogeneous_types (GtkWidget *source, GtkWidget *dest) { 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)); 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); const struct variable *v = psppire_dict_get_variable (dict, idx[0]); gtk_tree_path_free (fpath); if ( type != -1 ) { 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); if ( retval == FALSE ) return FALSE; /* now deal with the dest widget */ model = gtk_tree_view_get_model (GTK_TREE_VIEW (dest)); 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); if ( type != -1 ) { if ( var_get_type (v) != type ) { retval = FALSE; break; } } type = var_get_type (v); } return retval; }