1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2013 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/>. */
21 #include "psppire-spreadsheet-model.h"
23 static void psppire_spreadsheet_model_init (PsppireSpreadsheetModel *spreadsheetModel);
24 static void psppire_spreadsheet_model_class_init (PsppireSpreadsheetModelClass *class);
26 static void psppire_spreadsheet_model_finalize (GObject *object);
27 static void psppire_spreadsheet_model_dispose (GObject *object);
29 static GObjectClass *parent_class = NULL;
32 static void spreadsheet_tree_model_init (GtkTreeModelIface *iface);
36 psppire_spreadsheet_model_get_type (void)
38 static GType object_type = 0;
42 static const GTypeInfo spreadsheet_model_info =
44 sizeof (PsppireSpreadsheetModelClass),
46 NULL, /* base_finalize */
47 (GClassInitFunc) psppire_spreadsheet_model_class_init,
48 NULL, /* class_finalize */
49 NULL, /* class_data */
50 sizeof (PsppireSpreadsheetModel),
52 (GInstanceInitFunc) psppire_spreadsheet_model_init,
55 static const GInterfaceInfo tree_model_info = {
56 (GInterfaceInitFunc) spreadsheet_tree_model_init,
61 object_type = g_type_register_static (G_TYPE_OBJECT,
62 "PsppireSpreadsheetModel",
63 &spreadsheet_model_info, 0);
65 g_type_add_interface_static (object_type, GTK_TYPE_TREE_MODEL,
75 psppire_spreadsheet_model_dispose (GObject *object)
80 psppire_spreadsheet_model_finalize (GObject *object)
82 // PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (object);
86 psppire_spreadsheet_model_class_init (PsppireSpreadsheetModelClass *class)
88 GObjectClass *object_class;
90 parent_class = g_type_class_peek_parent (class);
91 object_class = (GObjectClass*) class;
93 object_class->finalize = psppire_spreadsheet_model_finalize;
94 object_class->dispose = psppire_spreadsheet_model_dispose;
99 psppire_spreadsheet_model_init (PsppireSpreadsheetModel *spreadsheetModel)
101 spreadsheetModel->dispose_has_run = FALSE;
102 spreadsheetModel->stamp = g_random_int ();
107 psppire_spreadsheet_model_new (void)
109 return g_object_new (psppire_spreadsheet_model_get_type (), NULL);
117 static const gint N_COLS = 2;
120 tree_model_n_columns (GtkTreeModel *model)
122 g_print ("%s\n", __FUNCTION__);
126 static GtkTreeModelFlags
127 tree_model_get_flags (GtkTreeModel *model)
129 g_print ("%s\n", __FUNCTION__);
130 g_return_val_if_fail (PSPPIRE_IS_SPREADSHEET_MODEL (model), (GtkTreeModelFlags) 0);
132 return GTK_TREE_MODEL_LIST_ONLY;
136 tree_model_column_type (GtkTreeModel *model, gint index)
138 g_print ("%s %d\n", __FUNCTION__, index);
139 g_return_val_if_fail (PSPPIRE_IS_SPREADSHEET_MODEL (model), (GType) 0);
140 g_return_val_if_fail (index < N_COLS, (GType) 0);
142 return G_TYPE_STRING;
147 tree_model_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreePath *path)
149 gint *indices, depth;
151 PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (model);
153 g_return_val_if_fail (path, FALSE);
155 indices = gtk_tree_path_get_indices (path);
157 depth = gtk_tree_path_get_depth (path);
159 g_return_val_if_fail (depth == 1, FALSE);
161 g_print ("%s %d\n", __FUNCTION__, *indices);
163 iter->stamp = spreadsheetModel->stamp;
164 iter->user_data = *indices; // kludge
170 tree_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter)
172 PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (model);
173 g_return_val_if_fail (iter->stamp == spreadsheetModel->stamp, FALSE);
175 g_print ("%s %d\n", __FUNCTION__, iter->user_data);
177 if ( iter->user_data >= 5 - 1)
187 tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter,
188 gint column, GValue *value)
190 PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (model);
191 g_return_if_fail (column < N_COLS);
192 g_return_if_fail (iter->stamp == spreadsheetModel->stamp);
193 g_print ("%s col %d\n", __FUNCTION__, column);
195 g_value_init (value, G_TYPE_STRING);
197 g_value_set_string (value, "foo");
199 g_value_set_string (value, "bar");
204 tree_model_nth_child (GtkTreeModel *model, GtkTreeIter *iter,
205 GtkTreeIter *parent, gint n)
207 PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (model);
215 iter->stamp = spreadsheetModel->stamp;
217 iter->user_data = psppire_dict_get_variable (dict, n);
219 if ( !iter->user_data)
228 spreadsheet_tree_model_init (GtkTreeModelIface *iface)
230 iface->get_flags = tree_model_get_flags;
231 iface->get_n_columns = tree_model_n_columns;
232 iface->get_column_type = tree_model_column_type;
233 iface->get_iter = tree_model_get_iter;
234 iface->iter_next = tree_model_iter_next;
236 iface->get_value = tree_model_get_value;
239 iface->get_path = tree_model_get_path;
240 iface->iter_children = tree_model_iter_children ;
241 iface->iter_has_child = tree_model_iter_has_child ;
242 iface->iter_n_children = tree_model_n_children ;
244 iface->iter_parent = tree_model_iter_parent ;
247 iface->iter_nth_child = tree_model_nth_child ;