1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "checkbox-treeview.h"
23 #define _(msgid) gettext (msgid)
24 #define N_(msgid) msgid
27 /* Callback for checkbox cells in the statistics tree view.
28 Toggles the checkbox. */
30 toggle (GtkCellRendererToggle *cell_renderer, gchar *path_str, gpointer data)
32 GtkTreeView *tv = GTK_TREE_VIEW (data);
33 GtkTreeModel *model = gtk_tree_view_get_model (tv);
35 GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
38 gtk_tree_model_get_iter (model, &iter, path);
39 gtk_tree_model_get (model, &iter, CHECKBOX_COLUMN_SELECTED, &selected, -1);
40 gtk_list_store_set (GTK_LIST_STORE (model), &iter, CHECKBOX_COLUMN_SELECTED,
42 gtk_tree_path_free (path);
47 treeview_create_checkbox_model (GtkTreeView *treeview,
50 const struct checkbox_entry_item *items
56 list = gtk_list_store_new (N_CHECKBOX_COLUMNS,
57 G_TYPE_STRING, G_TYPE_BOOLEAN);
58 gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (list));
60 for (i = 0; i < n_items; i++)
63 gtk_list_store_append (list, &iter);
64 gtk_list_store_set (list, &iter,
65 CHECKBOX_COLUMN_LABEL, items[i].label,
66 CHECKBOX_COLUMN_SELECTED,
67 (default_items & (1u << i)) != 0,
73 treeview_checkbox_populate (GtkTreeView *treeview)
75 GtkTreeViewColumn *col;
76 GtkCellRenderer *renderer;
78 /* Checkbox column. */
79 col = gtk_tree_view_column_new ();
80 renderer = gtk_cell_renderer_toggle_new ();
82 gtk_tree_view_column_pack_start (col, renderer, TRUE);
84 gtk_tree_view_append_column (treeview, col);
86 gtk_tree_view_column_add_attribute (col, renderer, "active", CHECKBOX_COLUMN_SELECTED);
88 g_signal_connect (GTK_CELL_RENDERER_TOGGLE (renderer),
89 "toggled", G_CALLBACK (toggle), treeview);
93 col = gtk_tree_view_column_new ();
94 gtk_tree_view_column_set_title (col, _("Statistic"));
95 renderer = gtk_cell_renderer_text_new ();
96 gtk_tree_view_column_pack_start (col, renderer, TRUE);
98 gtk_tree_view_column_add_attribute (col, renderer, "text", CHECKBOX_COLUMN_LABEL);
100 g_object_set (renderer, "ellipsize-set", TRUE, NULL);
101 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
102 gtk_tree_view_column_set_min_width (col, 200);
103 gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
104 gtk_tree_view_column_set_resizable (col, TRUE);
105 gtk_tree_view_append_column (treeview, col);
110 put_checkbox_items_in_treeview (GtkTreeView *treeview,
113 const struct checkbox_entry_item *items
116 treeview_create_checkbox_model (treeview, default_items, n_items, items);
117 treeview_checkbox_populate (treeview);