X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fpsppire-spreadsheet-model.c;h=f5be69d8705981d52300008499046662675ebafc;hb=42993d3ae61750a8f1e291297d8ac91465afcff2;hp=4742cee9c08cc81d1f728c9861836bb1bb5cf5b7;hpb=69d9ffe0d82f468b541d04508999eced384fef10;p=pspp
diff --git a/src/ui/gui/psppire-spreadsheet-model.c b/src/ui/gui/psppire-spreadsheet-model.c
index 4742cee9c0..f5be69d870 100644
--- a/src/ui/gui/psppire-spreadsheet-model.c
+++ b/src/ui/gui/psppire-spreadsheet-model.c
@@ -14,15 +14,23 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
+/* 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
#include
-#include "psppire-spreadsheet-model.h"
+#include
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
+#include "psppire-spreadsheet-model.h"
#include "data/spreadsheet-reader.h"
-#include "data/gnumeric-reader.h"
static void psppire_spreadsheet_model_init (PsppireSpreadsheetModel *
spreadsheetModel);
@@ -89,7 +97,7 @@ psppire_spreadsheet_model_set_property (GObject * object,
const GValue * value,
GParamSpec * pspec)
{
- PsppireSpreadsheetModel *spreadsheetModel =
+ PsppireSpreadsheetModel *spreadsheetModel =
PSPPIRE_SPREADSHEET_MODEL (object);
switch (prop_id)
@@ -157,18 +165,10 @@ psppire_spreadsheet_model_new (struct spreadsheet *sp)
-
-enum
-{
- COL_SHEET_NAME,
- COL_SHEET_RANGE,
- N_COLS
-};
-
static gint
tree_model_n_columns (GtkTreeModel * model)
{
- return N_COLS;
+ return PSPPIRE_SPREADSHEET_MODEL_N_COLS;
}
static GtkTreeModelFlags
@@ -184,7 +184,7 @@ static GType
tree_model_column_type (GtkTreeModel * model, gint index)
{
g_return_val_if_fail (PSPPIRE_IS_SPREADSHEET_MODEL (model), (GType) 0);
- g_return_val_if_fail (index < N_COLS, (GType) 0);
+ g_return_val_if_fail (index < PSPPIRE_SPREADSHEET_MODEL_N_COLS, (GType) 0);
return G_TYPE_STRING;
}
@@ -216,7 +216,7 @@ tree_model_get_iter (GtkTreeModel * model, GtkTreeIter * iter,
}
static gboolean
-tree_model_iter_next (GtkTreeModel * model, GtkTreeIter * iter)
+tree_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter)
{
PsppireSpreadsheetModel *spreadsheetModel =
PSPPIRE_SPREADSHEET_MODEL (model);
@@ -225,7 +225,7 @@ tree_model_iter_next (GtkTreeModel * model, GtkTreeIter * iter)
if (iter == NULL)
return FALSE;
- if ((gint) iter->user_data >= spreadsheetModel->spreadsheet->sheets - 1)
+ if ((gint) iter->user_data >= spreadsheetModel->spreadsheet->n_sheets - 1)
{
iter->user_data = NULL;
iter->stamp = 0;
@@ -244,31 +244,34 @@ tree_model_get_value (GtkTreeModel * model, GtkTreeIter * iter,
{
PsppireSpreadsheetModel *spreadsheetModel =
PSPPIRE_SPREADSHEET_MODEL (model);
- g_return_if_fail (column < N_COLS);
+ g_return_if_fail (column < PSPPIRE_SPREADSHEET_MODEL_N_COLS);
g_return_if_fail (iter->stamp == spreadsheetModel->stamp);
g_value_init (value, G_TYPE_STRING);
switch (column)
{
- case COL_SHEET_NAME:
+ case PSPPIRE_SPREADSHEET_MODEL_COL_NAME:
{
const char *x =
- gnumeric_get_sheet_name (spreadsheetModel->spreadsheet,
+ spreadsheet_get_sheet_name (spreadsheetModel->spreadsheet,
(gint) iter->user_data);
+
g_value_set_string (value, x);
}
break;
- case COL_SHEET_RANGE:
+ case PSPPIRE_SPREADSHEET_MODEL_COL_RANGE:
{
- const char *x =
- gnumeric_get_sheet_range (spreadsheetModel->spreadsheet,
+ char *x =
+ spreadsheet_get_sheet_range (spreadsheetModel->spreadsheet,
(gint) iter->user_data);
- g_value_set_string (value, x);
+
+ g_value_set_string (value, x ? x : _("(empty)"));
+ g_free (x);
}
break;
default:
- g_error ("%s:%d Invalid column in spreadsheet model", __FILE__,
- __LINE__);
+ g_error ("%s:%d Invalid column in spreadsheet model",
+ __FILE__, __LINE__);
break;
}
}
@@ -283,7 +286,7 @@ tree_model_nth_child (GtkTreeModel * model, GtkTreeIter * iter,
if (parent)
return FALSE;
- if (n >= spreadsheetModel->spreadsheet->sheets)
+ if (n >= spreadsheetModel->spreadsheet->n_sheets)
return FALSE;
iter->stamp = spreadsheetModel->stamp;
@@ -299,13 +302,13 @@ tree_model_n_children (GtkTreeModel * model, GtkTreeIter * iter)
PSPPIRE_SPREADSHEET_MODEL (model);
if (iter == NULL)
- return spreadsheetModel->spreadsheet->sheets;
+ return spreadsheetModel->spreadsheet->n_sheets;
return 0;
}
static gboolean
-tree_model_iter_has_child (GtkTreeModel * tree_model, GtkTreeIter * iter)
+tree_model_iter_has_child (GtkTreeModel *tree_model, GtkTreeIter *iter)
{
return FALSE;
}
@@ -328,6 +331,21 @@ tree_model_get_path (GtkTreeModel * model, GtkTreeIter * iter)
}
+static gboolean
+tree_model_children (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent)
+{
+ PsppireSpreadsheetModel *spreadsheetModel = PSPPIRE_SPREADSHEET_MODEL (model);
+
+ if (parent != NULL)
+ return FALSE;
+
+ iter->stamp = spreadsheetModel->stamp;
+ iter->user_data = 0;
+
+ return TRUE;
+}
+
+
static void
spreadsheet_tree_model_init (GtkTreeModelIface * iface)
@@ -339,7 +357,7 @@ spreadsheet_tree_model_init (GtkTreeModelIface * iface)
iface->iter_next = tree_model_iter_next;
iface->get_value = tree_model_get_value;
- iface->iter_children = NULL;
+ iface->iter_children = tree_model_children;
iface->iter_parent = NULL;
iface->get_path = tree_model_get_path;