From 0e16dee73f1bff3b08748dea8a72d29054333218 Mon Sep 17 00:00:00 2001
From: John Darrington
Date: Wed, 2 Oct 2013 15:14:15 +0200
Subject: [PATCH] Replace checkbox-treeview functions with a object
PsppireCheckboxTreeview
Prior to this change there existed a function which operated on
a GtkTreeView which populated it with a model and renderers such
that it would display a list of annotated checkboxes.
This change subclasses GtkTreeView and moves the function to a
method of that class.
I anticipate this will ease implementation of upcoming functionality.
---
src/ui/gui/automake.mk | 4 +-
src/ui/gui/checkbox-treeview.c | 118 -------------------
src/ui/gui/checkbox-treeview.h | 43 -------
src/ui/gui/crosstabs.ui | 4 +-
src/ui/gui/descriptives.ui | 2 +-
src/ui/gui/frequencies.ui | 2 +-
src/ui/gui/psppire-checkbox-treeview.c | 141 +++++++++++++++++++++++
src/ui/gui/psppire-checkbox-treeview.h | 88 ++++++++++++++
src/ui/gui/psppire-dialog-action-crosstabs.c | 20 ++--
src/ui/gui/psppire-dialog-action-descriptives.c | 8 +-
src/ui/gui/psppire-dialog-action-frequencies.c | 4 +-
src/ui/gui/psppire-dialog-action-regression.c | 10 +-
src/ui/gui/regression.ui | 2 +-
src/ui/gui/widgets.c | 2 +
14 files changed, 258 insertions(+), 190 deletions(-)
delete mode 100644 src/ui/gui/checkbox-treeview.c
delete mode 100644 src/ui/gui/checkbox-treeview.h
create mode 100644 src/ui/gui/psppire-checkbox-treeview.c
create mode 100644 src/ui/gui/psppire-checkbox-treeview.h
diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk
index 47a3215..f5bd07b 100644
--- a/src/ui/gui/automake.mk
+++ b/src/ui/gui/automake.mk
@@ -137,8 +137,6 @@ src_ui_gui_psppire_SOURCES = \
src/ui/gui/aggregate-dialog.h \
src/ui/gui/builder-wrapper.c \
src/ui/gui/builder-wrapper.h \
- src/ui/gui/checkbox-treeview.c \
- src/ui/gui/checkbox-treeview.h \
src/ui/gui/comments-dialog.c \
src/ui/gui/comments-dialog.h \
src/ui/gui/compute-dialog.c \
@@ -178,6 +176,8 @@ src_ui_gui_psppire_SOURCES = \
src/ui/gui/psppire.h \
src/ui/gui/psppire-acr.h \
src/ui/gui/psppire-buttonbox.h \
+ src/ui/gui/psppire-checkbox-treeview.c \
+ src/ui/gui/psppire-checkbox-treeview.h \
src/ui/gui/psppire-conf.c \
src/ui/gui/psppire-conf.h \
src/ui/gui/psppire-data-editor.c \
diff --git a/src/ui/gui/checkbox-treeview.c b/src/ui/gui/checkbox-treeview.c
deleted file mode 100644
index 324943a..0000000
--- a/src/ui/gui/checkbox-treeview.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007, 2012 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 "checkbox-treeview.h"
-#include
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
-
-
-/* Callback for checkbox cells in the statistics tree view.
- Toggles the checkbox. */
-static void
-toggle (GtkCellRendererToggle *cell_renderer, gchar *path_str, gpointer data)
-{
- GtkTreeView *tv = GTK_TREE_VIEW (data);
- GtkTreeModel *model = gtk_tree_view_get_model (tv);
- GtkTreeIter iter;
- GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
- gboolean selected;
-
- gtk_tree_model_get_iter (model, &iter, path);
- gtk_tree_model_get (model, &iter, CHECKBOX_COLUMN_SELECTED, &selected, -1);
- gtk_list_store_set (GTK_LIST_STORE (model), &iter, CHECKBOX_COLUMN_SELECTED,
- !selected, -1);
- gtk_tree_path_free (path);
-}
-
-
-static void
-treeview_create_checkbox_model (GtkTreeView *treeview,
- guint default_items,
- gint n_items,
- const struct checkbox_entry_item *items
- )
-{
- GtkListStore *list;
- size_t i;
-
- list = gtk_list_store_new (N_CHECKBOX_COLUMNS,
- G_TYPE_STRING, G_TYPE_BOOLEAN);
-
- for (i = 0; i < n_items; i++)
- {
- GtkTreeIter iter;
- gtk_list_store_append (list, &iter);
- gtk_list_store_set (list, &iter,
- CHECKBOX_COLUMN_LABEL, gettext (items[i].label),
- CHECKBOX_COLUMN_SELECTED,
- (default_items & (1u << i)) != 0,
- -1);
- }
-
- gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (list));
- g_object_unref (list);
-}
-
-static void
-treeview_checkbox_populate (GtkTreeView *treeview)
-{
- GtkTreeViewColumn *col;
- GtkCellRenderer *renderer;
-
- /* Checkbox column. */
- col = gtk_tree_view_column_new ();
- renderer = gtk_cell_renderer_toggle_new ();
-
- gtk_tree_view_column_pack_start (col, renderer, TRUE);
-
- gtk_tree_view_append_column (treeview, col);
-
- gtk_tree_view_column_add_attribute (col, renderer, "active", CHECKBOX_COLUMN_SELECTED);
-
- g_signal_connect (renderer, "toggled", G_CALLBACK (toggle), treeview);
-
- /* Label column. */
- col = gtk_tree_view_column_new ();
- gtk_tree_view_column_set_title (col, _("Statistic"));
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (col, renderer, TRUE);
-
- gtk_tree_view_column_add_attribute (col, renderer, "text", CHECKBOX_COLUMN_LABEL);
-
- g_object_set (renderer, "ellipsize-set", TRUE, NULL);
- g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
- gtk_tree_view_column_set_min_width (col, 200);
- gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
- gtk_tree_view_column_set_resizable (col, TRUE);
- gtk_tree_view_append_column (treeview, col);
-}
-
-
-void
-put_checkbox_items_in_treeview (GtkTreeView *treeview,
- guint default_items,
- gint n_items,
- const struct checkbox_entry_item *items
- )
-{
- treeview_create_checkbox_model (treeview, default_items, n_items, items);
- treeview_checkbox_populate (treeview);
-}
diff --git a/src/ui/gui/checkbox-treeview.h b/src/ui/gui/checkbox-treeview.h
deleted file mode 100644
index 1616b73..0000000
--- a/src/ui/gui/checkbox-treeview.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* 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 . */
-
-
-#ifndef __CHECKBOX_TREEVIEW_H__
-#define __CHECKBOX_TREEVIEW_H__ 1
-
-
-#include
-
-struct checkbox_entry_item
- {
- const char *name;
- const char *label;
- };
-
-enum
- {
- CHECKBOX_COLUMN_LABEL,
- CHECKBOX_COLUMN_SELECTED,
- N_CHECKBOX_COLUMNS
- };
-
-
-void put_checkbox_items_in_treeview (GtkTreeView *treeview,
- guint default_items,
- gint n_items,
- const struct checkbox_entry_item *items
- );
-#endif
diff --git a/src/ui/gui/crosstabs.ui b/src/ui/gui/crosstabs.ui
index 3e6ceb5..ac86404 100644
--- a/src/ui/gui/crosstabs.ui
+++ b/src/ui/gui/crosstabs.ui
@@ -355,7 +355,7 @@
automaticin
-