int min_col;
int node_type;
int sheet_index;
-
+
+ xmlChar **sheet_names;
const xmlChar *target_sheet;
int target_sheet_index;
bool used_first_case;
};
+
+char *
+gnumeric_get_sheet_name (struct spreadsheet *s, int n)
+{
+ struct gnumeric_reader *gr = (struct gnumeric_reader *) s;
+ assert (n < s->sheets);
+
+ return gr->sheet_names[n];
+}
+
static void process_node (struct gnumeric_reader *r);
static void
gnm_file_casereader_destroy (struct casereader *reader UNUSED, void *r_)
{
+ int i;
struct gnumeric_reader *r = r_;
if ( r == NULL)
return ;
caseproto_unref (r->proto);
+ for (i = 0; i < r->spreadsheet.sheets; ++i)
+ {
+ xmlFree (r->sheet_names[i]);
+ }
+
+ free (r->sheet_names);
+
free (r);
}
XML_READER_TYPE_ELEMENT == r->node_type)
{
r->spreadsheet.sheets++;
+ r->sheet_names = xrealloc (r->sheet_names, r->spreadsheet.sheets * sizeof *r->sheet_names);
}
else if (0 == xmlStrcasecmp (name, _xml("gnm:SheetNameIndex")) &&
XML_READER_TYPE_END_ELEMENT == r->node_type)
{
r->state = STATE_INIT;
}
+ else if (XML_READER_TYPE_TEXT == r->node_type)
+ {
+ r->sheet_names [r->spreadsheet.sheets - 1] = xmlTextReaderValue (r->xtr);
+ }
break;
case STATE_INIT:
#include "data/spreadsheet-reader.h"
+#include "data/gnumeric-reader.h"
+
static void psppire_spreadsheet_model_init (PsppireSpreadsheetModel *spreadsheetModel);
static void psppire_spreadsheet_model_class_init (PsppireSpreadsheetModelClass *class);
g_type_add_interface_static (object_type, GTK_TYPE_TREE_MODEL,
&tree_model_info);
-
}
return object_type;
static gint
tree_model_n_columns (GtkTreeModel *model)
{
- g_print ("%s\n", __FUNCTION__);
return N_COLS;
}
static GtkTreeModelFlags
tree_model_get_flags (GtkTreeModel *model)
{
- g_print ("%s\n", __FUNCTION__);
g_return_val_if_fail (PSPPIRE_IS_SPREADSHEET_MODEL (model), (GtkTreeModelFlags) 0);
return GTK_TREE_MODEL_LIST_ONLY;
static GType
tree_model_column_type (GtkTreeModel *model, gint index)
{
- g_print ("%s %d\n", __FUNCTION__, index);
g_return_val_if_fail (PSPPIRE_IS_SPREADSHEET_MODEL (model), (GType) 0);
g_return_val_if_fail (index < N_COLS, (GType) 0);
static gboolean
tree_model_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreePath *path)
{
- gint *indices, depth;
-
PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (model);
+ gint *indices, depth;
+ gint n;
g_return_val_if_fail (path, FALSE);
- indices = gtk_tree_path_get_indices (path);
-
depth = gtk_tree_path_get_depth (path);
g_return_val_if_fail (depth == 1, FALSE);
- g_print ("%s %d\n", __FUNCTION__, *indices);
+ indices = gtk_tree_path_get_indices (path);
+
+ n = indices [0];
iter->stamp = spreadsheetModel->stamp;
- iter->user_data = *indices; // kludge
+ iter->user_data = (gpointer) n;
return TRUE;
}
PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (model);
g_return_val_if_fail (iter->stamp == spreadsheetModel->stamp, FALSE);
- g_print ("%s %d\n", __FUNCTION__, iter->user_data);
-
- if ( iter->user_data >= spreadsheetModel->spreadsheet->sheets - 1)
+ if ( iter == NULL)
return FALSE;
+ if ( (gint) iter->user_data >= spreadsheetModel->spreadsheet->sheets - 1)
+ {
+ iter->user_data = NULL;
+ iter->stamp = 0;
+ return FALSE;
+ }
+
iter->user_data++;
return TRUE;
PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (model);
g_return_if_fail (column < N_COLS);
g_return_if_fail (iter->stamp == spreadsheetModel->stamp);
- g_print ("%s col %d\n", __FUNCTION__, column);
g_value_init (value, G_TYPE_STRING);
- if ( column > 0)
- g_value_set_string (value, "foo");
- else
- g_value_set_string (value, "bar");
+ switch (column)
+ {
+ case 0:
+ {
+ char *x = gnumeric_get_sheet_name (spreadsheetModel->spreadsheet, (gint) iter->user_data);
+ g_value_set_string (value, x);
+ }
+ break;
+ case 1:
+ g_value_set_string (value, "bar");
+ break;
+ default:
+ g_critical ("Bad column");
+ break;
+ }
}
-
static gboolean
tree_model_nth_child (GtkTreeModel *model, GtkTreeIter *iter,
GtkTreeIter *parent, gint n)
return FALSE;
iter->stamp = spreadsheetModel->stamp;
+ iter->user_data = (gpointer) n;
return TRUE;
}
+static gint
+tree_model_n_children (GtkTreeModel *model,
+ GtkTreeIter *iter)
+{
+ PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (model);
+
+ if ( iter == NULL )
+ return spreadsheetModel->spreadsheet->sheets;
+
+ return 0;
+}
+
+static gboolean
+tree_model_iter_has_child (GtkTreeModel *tree_model,
+ GtkTreeIter *iter)
+{
+ return FALSE;
+}
+
+static GtkTreePath *
+tree_model_get_path (GtkTreeModel *model, GtkTreeIter *iter)
+{
+ PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (model);
+ GtkTreePath *path;
+ gint index = (gint) iter->user_data;
+
+ g_return_val_if_fail (iter->stamp == spreadsheetModel->stamp, NULL);
+
+ path = gtk_tree_path_new ();
+
+ gtk_tree_path_append_index (path, index);
+
+ return path;
+}
+
+
static void
spreadsheet_tree_model_init (GtkTreeModelIface *iface)
iface->get_column_type = tree_model_column_type;
iface->get_iter = tree_model_get_iter;
iface->iter_next = tree_model_iter_next;
-
iface->get_value = tree_model_get_value;
-#if 0
+ iface->iter_children = NULL;
+ iface->iter_parent = NULL;
+
iface->get_path = tree_model_get_path;
- iface->iter_children = tree_model_iter_children ;
iface->iter_has_child = tree_model_iter_has_child ;
iface->iter_n_children = tree_model_n_children ;
-
- iface->iter_parent = tree_model_iter_parent ;
-#endif
-
iface->iter_nth_child = tree_model_nth_child ;
}
main (int argc, char *argv[] )
{
GtkWidget *window;
+ GtkWidget *hbox;
+ GtkWidget *vbox;
GtkWidget *treeview;
+ GtkWidget *combo_box;
GtkTreeModel *tm;
+ struct spreadsheet *sp = NULL;
gtk_init (&argc, &argv);
if ( argc < 2)
g_error ("Usage: prog file\n");
- struct spreadsheet *sp = gnumeric_probe (argv[1]);
+ sp = gnumeric_probe (argv[1]);
if (sp == NULL)
{
return 0;
}
+
+
tm = psppire_spreadsheet_model_new (sp);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ hbox = gtk_hbox_new (FALSE, 5);
+ vbox = gtk_vbox_new (FALSE, 5);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
-
+ // tm = GTK_TREE_MODEL (make_store ());
+ combo_box = gtk_combo_box_new_with_model (tm);
+
+ {
+ GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
+ "text", 0,
+ NULL);
+ }
+
+
+
+ gtk_combo_box_set_active (combo_box, 0);
+
treeview = gtk_tree_view_new_with_model (tm);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
"text", 1,
NULL);
- gtk_container_add (GTK_CONTAINER (window), treeview);
+
+ gtk_box_pack_start (GTK_BOX (hbox), treeview, TRUE, TRUE, 5);
+
+ gtk_box_pack_start (GTK_BOX (vbox), combo_box, FALSE, FALSE, 5);
+ gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 5);
+
+ gtk_container_add (GTK_CONTAINER (window), hbox);
gtk_widget_show_all (window);