X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fdict-display.c;h=ada7fb40fcbd5ab45ad55edca1c5508c5a4c8c07;hb=5aee303c40fc10d689756324133ed46de4fe62fa;hp=5129f13988c433b3d3171bf939c5773956273611;hpb=b06c888cf2e8c126b04d4678120439533a5086e5;p=pspp
diff --git a/src/ui/gui/dict-display.c b/src/ui/gui/dict-display.c
index 5129f13988..ada7fb40fc 100644
--- a/src/ui/gui/dict-display.c
+++ b/src/ui/gui/dict-display.c
@@ -1,10 +1,9 @@
-/*
- PSPPIRE --- A Graphical User Interface for PSPP
+/* 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
+ 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
+ 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,
@@ -13,86 +12,27 @@
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. */
+ along with this program. If not, see . */
#include
#include
#include
+#include "psppire-conf.h"
#include "dict-display.h"
#include "psppire-dict.h"
+#include "psppire-var-view.h"
+#include
#include "helper.h"
#include
+#include
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
-
-/* A GtkTreeModelFilterVisibleFunc to filter lines in the treeview */
-static gboolean
-filter_variables (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
-{
- var_predicate_func *predicate = data;
- struct variable *var;
- PsppireDict *dict = PSPPIRE_DICT (model);
-
- GtkTreePath *path = gtk_tree_model_get_path (model, iter);
-
- gint *idx = gtk_tree_path_get_indices (path);
-
- var = psppire_dict_get_variable (dict, *idx);
-
- gtk_tree_path_free (path);
-
- return predicate (var);
-}
-
-/* A GtkTreeCellDataFunc which sets the icon appropriate to the type
- of variable */
static void
-var_icon_cell_data_func (GtkTreeViewColumn *col,
- GtkCellRenderer *cell,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- struct variable *var;
- gtk_tree_model_get (model, iter, DICT_TVM_COL_VAR, &var, -1);
-
- if ( var_is_alpha (var))
- {
- g_object_set (cell, "stock-id", "var-string", NULL);
- }
- else
- {
- const struct fmt_spec *fs = var_get_write_format (var);
- int cat = fmt_get_category (fs->type);
- switch ( var_get_measure (var))
- {
- case MEASURE_NOMINAL:
- g_object_set (cell, "stock-id", "var-nominal", NULL);
- break;
- case MEASURE_ORDINAL:
- g_object_set (cell, "stock-id", "var-ordinal", NULL);
- break;
- case MEASURE_SCALE:
- if ( ( FMT_CAT_DATE | FMT_CAT_TIME ) & cat )
- g_object_set (cell, "stock-id", "var-date-scale", NULL);
- else
- g_object_set (cell, "stock-id", "var-scale", NULL);
- break;
- default:
- g_assert_not_reached ();
- };
- }
-}
-
-
-void
get_base_model (GtkTreeModel *top_model, GtkTreeIter *top_iter,
GtkTreeModel **model, GtkTreeIter *iter
)
@@ -114,121 +54,12 @@ get_base_model (GtkTreeModel *top_model, GtkTreeIter *top_iter,
g_assert (PSPPIRE_IS_DICT (*model));
}
-/* A GtkTreeCellDataFunc which renders the name and/or label of the
- variable */
-static void
-var_description_cell_data_func (GtkTreeViewColumn *col,
- GtkCellRenderer *cell,
- GtkTreeModel *top_model,
- GtkTreeIter *top_iter,
- gpointer data)
-{
- struct variable *var;
- GtkTreeIter iter;
- GtkTreeModel *model;
-
-
- get_base_model (top_model, top_iter, &model, &iter);
-
- g_assert (PSPPIRE_IS_DICT (model));
-
-
- gtk_tree_model_get (model,
- &iter, DICT_TVM_COL_VAR, &var, -1);
-
- if ( var_has_label (var))
- {
- gchar *text = g_strdup_printf (
- "%s"
- " (%s)",
- var_get_label (var),
- var_get_name (var));
-
- char *utf8 = pspp_locale_to_utf8 (text, -1, NULL);
-
- g_free (text);
- g_object_set (cell, "markup", utf8, NULL);
- g_free (utf8);
- }
- else
- {
- g_object_set (cell, "text", var_get_name (var), NULL);
- }
-}
-
- /* Sets up TREEVIEW to display the variables of DICT.
- MODE is the selection mode for TREEVIEW.
- PREDICATE determines which variables should be visible, or NULL if
- all are to be visible.
- */
-void
-attach_dictionary_to_treeview (GtkTreeView *treeview, PsppireDict *dict,
- GtkSelectionMode mode,
- var_predicate_func *predicate
- )
-{
- GtkTreeViewColumn *col;
-
- GtkTreeSelection *selection =
- gtk_tree_view_get_selection (treeview);
-
- GtkCellRenderer *renderer;
-
- GtkTreeModel *model ;
-
- if ( predicate )
- {
- model = gtk_tree_model_filter_new (GTK_TREE_MODEL (dict),
- NULL);
-
- gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (model),
- filter_variables,
- predicate,
- NULL);
- }
- else
- {
- model = GTK_TREE_MODEL (dict);
- }
-
- gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), model);
-
-
- col = gtk_tree_view_column_new ();
- gtk_tree_view_column_set_title (col, _("Variable"));
-
- renderer = gtk_cell_renderer_pixbuf_new ();
- gtk_tree_view_column_pack_start (col, renderer, FALSE);
-
- gtk_tree_view_column_set_cell_data_func (col, renderer,
- var_icon_cell_data_func,
- NULL, NULL);
-
-
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (col, renderer, TRUE);
- gtk_tree_view_column_set_cell_data_func (col, renderer,
- var_description_cell_data_func,
- NULL, NULL);
-
- g_object_set (renderer, "ellipsize-set", TRUE, NULL);
- g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_MIDDLE, NULL);
-
- gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
-
- /* FIXME: make this a value in terms of character widths */
- gtk_tree_view_column_set_min_width (col, 150);
-
- gtk_tree_view_append_column (treeview, col);
-
- gtk_tree_selection_set_mode (selection, mode);
-}
-
void
insert_source_row_into_entry (GtkTreeIter iter,
GtkWidget *dest,
- GtkTreeModel *model
+ GtkTreeModel *model,
+ gpointer data
)
{
GtkTreePath *path;
@@ -236,7 +67,6 @@ insert_source_row_into_entry (GtkTreeIter iter,
gint *idx;
struct variable *var;
GtkTreeIter dict_iter;
- gchar *name;
g_return_if_fail (GTK_IS_ENTRY(dest));
@@ -250,54 +80,60 @@ insert_source_row_into_entry (GtkTreeIter iter,
gtk_tree_path_free (path);
- name = pspp_locale_to_utf8 (var_get_name (var), -1, NULL);
- gtk_entry_set_text (GTK_ENTRY (dest), name);
- g_free (name);
+ gtk_entry_set_text (GTK_ENTRY (dest), var_get_name (var));
}
-
void
insert_source_row_into_tree_view (GtkTreeIter iter,
GtkWidget *dest,
- GtkTreeModel *model
+ GtkTreeModel *model,
+ gpointer data
)
{
GtkTreePath *path;
GtkTreeIter dest_iter;
GtkTreeIter dict_iter;
gint *row ;
- GtkTreeModel *destmodel = gtk_tree_view_get_model ( GTK_TREE_VIEW (dest));
+ GtkTreeModel *destmodel = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
+ const struct variable *var;
GtkTreeModel *dict;
-
get_base_model (model, &iter, &dict, &dict_iter);
path = gtk_tree_model_get_path (dict, &dict_iter);
row = gtk_tree_path_get_indices (path);
+ var = psppire_dict_get_variable (PSPPIRE_DICT (dict), *row);
+
gtk_list_store_append (GTK_LIST_STORE (destmodel), &dest_iter);
- gtk_list_store_set (GTK_LIST_STORE (destmodel), &dest_iter, 0, *row, -1);
+
+ gtk_list_store_set (GTK_LIST_STORE (destmodel), &dest_iter, 0, var, -1);
gtk_tree_path_free (path);
}
+
gboolean
is_currently_in_entry (GtkTreeModel *model, GtkTreeIter *iter,
PsppireSelector *selector)
{
gboolean result;
- gchar *name;
GtkTreeIter dict_iter;
GtkTreeModel *dict;
struct variable *var;
gint dict_index;
gint *indeces;
GtkTreePath *path;
- const gchar *text = gtk_entry_get_text (GTK_ENTRY (selector->dest));
+ GtkWidget *entry = NULL;
+ const gchar *text = NULL;
+
+ g_object_get (selector, "dest-widget", &entry, NULL);
+
+ text = gtk_entry_get_text (GTK_ENTRY (entry));
get_base_model (model, iter, &dict, &dict_iter);
@@ -311,11 +147,8 @@ is_currently_in_entry (GtkTreeModel *model, GtkTreeIter *iter,
gtk_tree_path_free (path);
- name = pspp_locale_to_utf8 (var_get_name (var), -1, NULL);
- result = ( 0 == strcmp (text, name));
- g_free (name);
+ result = ( 0 == strcmp (text, var_get_name (var) ));
return result;
}
-