/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2013 Free Software Foundation
+ Copyright (C) 2013, 2014 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
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+/* This file implements a GtkTreeModel. It allows GtkComboBox and
+ GtkTreeView to display the names and non-empty cell ranges of the
+ sheets aka "Tables" of spreadsheet files.
+ It doesn't take any notice of the spreadsheet data itself.
+*/
#include <config.h>
#include <glib.h>
-#include "psppire-spreadsheet-model.h"
+#include <stdint.h>
+
+#include <gettext.h>
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
+#include "psppire-spreadsheet-model.h"
#include "data/spreadsheet-reader.h"
-#include "data/gnumeric-reader.h"
-#include "data/ods-reader.h"
static void psppire_spreadsheet_model_init (PsppireSpreadsheetModel *
spreadsheetModel);
const GValue * value,
GParamSpec * pspec)
{
- PsppireSpreadsheetModel *spreadsheetModel =
+ PsppireSpreadsheetModel *spreadsheetModel =
PSPPIRE_SPREADSHEET_MODEL (object);
switch (prop_id)
{
case PROP_SPREADSHEET:
spreadsheetModel->spreadsheet = g_value_get_pointer (value);
+ spreadsheet_ref (spreadsheetModel->spreadsheet);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
static void
psppire_spreadsheet_model_dispose (GObject * object)
{
+ PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (object);
+
+ if (!spreadsheetModel->dispose_has_run)
+ {
+ spreadsheet_unref (spreadsheetModel->spreadsheet);
+
+ spreadsheetModel->dispose_has_run = TRUE;
+ }
}
static void
n = indices[0];
iter->stamp = spreadsheetModel->stamp;
- iter->user_data = (gpointer) n;
+ iter->user_data = (gpointer) (intptr_t) n;
return TRUE;
}
static gboolean
tree_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter)
{
- PsppireSpreadsheetModel *spreadsheetModel =
- PSPPIRE_SPREADSHEET_MODEL (model);
+ PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (model);
+ g_assert (iter);
g_return_val_if_fail (iter->stamp == spreadsheetModel->stamp, FALSE);
- if (iter == NULL)
- return FALSE;
-
- if ((gint) iter->user_data >= spreadsheetModel->spreadsheet->n_sheets - 1)
+ if ((intptr_t) iter->user_data >= spreadsheetModel->spreadsheet->n_sheets - 1)
{
iter->user_data = NULL;
iter->stamp = 0;
case PSPPIRE_SPREADSHEET_MODEL_COL_NAME:
{
const char *x =
- ods_get_sheet_name (spreadsheetModel->spreadsheet,
- (gint) iter->user_data);
-
+ spreadsheet_get_sheet_name (spreadsheetModel->spreadsheet,
+ (intptr_t) iter->user_data);
+
g_value_set_string (value, x);
}
break;
case PSPPIRE_SPREADSHEET_MODEL_COL_RANGE:
{
char *x =
- ods_get_sheet_range (spreadsheetModel->spreadsheet,
- (gint) iter->user_data);
+ spreadsheet_get_sheet_range (spreadsheetModel->spreadsheet,
+ (intptr_t) iter->user_data);
- g_value_set_string (value, x ? x : "(empty)");
+ g_value_set_string (value, x ? x : _("(empty)"));
g_free (x);
}
break;
return FALSE;
iter->stamp = spreadsheetModel->stamp;
- iter->user_data = (gpointer) n;
+ iter->user_data = (gpointer) (intptr_t) n;
return TRUE;
}
PsppireSpreadsheetModel *spreadsheetModel =
PSPPIRE_SPREADSHEET_MODEL (model);
GtkTreePath *path;
- gint index = (gint) iter->user_data;
+ gint index = (intptr_t) iter->user_data;
g_return_val_if_fail (iter->stamp == spreadsheetModel->stamp, NULL);
iter->stamp = spreadsheetModel->stamp;
iter->user_data = 0;
-
+
return TRUE;
}