From 11706f97dd318697e43e6468b130ca5b7f1bff87 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 23 Nov 2008 17:07:33 +0900 Subject: [PATCH] Replace gsheet-column interface by psppire-axis Created a new object psppire-axis, which is a thinish wrapper around src/libpspp/tower.c, and can be used to maintain the positions and widths of rows/columns in the data/variable sheets. This change also deletes the lib/gtksheet/*-column-* modules, and uses a psppire-axis in their place. Some functions previously performed by gsheet-column-iface have been moved to gsheetmodel. This change doesn't touch lib/gtksheet/*-row-* but it will be straightforward to replace that too. --- examples/grid.sps | 4 +- lib/gtksheet/automake.mk | 11 +- lib/gtksheet/gsheet-column-iface.c | 214 ------------------------ lib/gtksheet/gsheet-column-iface.h | 104 ------------ lib/gtksheet/gsheet-hetero-column.c | 228 ------------------------- lib/gtksheet/gsheet-hetero-column.h | 87 ---------- lib/gtksheet/gsheet-uniform-column.c | 173 ------------------- lib/gtksheet/gsheet-uniform-column.h | 67 -------- lib/gtksheet/gsheetmodel.c | 51 ++++++ lib/gtksheet/gsheetmodel.h | 34 +++- lib/gtksheet/gtksheet.c | 240 +++++++++++++-------------- lib/gtksheet/gtksheet.h | 12 +- lib/gtksheet/psppire-axis.c | 181 ++++++++++++++++++++ lib/gtksheet/psppire-axis.h | 82 +++++++++ src/ui/gui/psppire-data-editor.c | 7 +- src/ui/gui/psppire-data-store.c | 184 ++++++++++---------- src/ui/gui/psppire-data-store.h | 1 - src/ui/gui/psppire-var-sheet.c | 52 +++--- src/ui/gui/psppire-var-store.c | 30 +++- src/ui/gui/psppire-var-store.h | 1 - 20 files changed, 621 insertions(+), 1142 deletions(-) delete mode 100644 lib/gtksheet/gsheet-column-iface.c delete mode 100644 lib/gtksheet/gsheet-column-iface.h delete mode 100644 lib/gtksheet/gsheet-hetero-column.c delete mode 100644 lib/gtksheet/gsheet-hetero-column.h delete mode 100644 lib/gtksheet/gsheet-uniform-column.c delete mode 100644 lib/gtksheet/gsheet-uniform-column.h create mode 100644 lib/gtksheet/psppire-axis.c create mode 100644 lib/gtksheet/psppire-axis.h diff --git a/examples/grid.sps b/examples/grid.sps index cfaa80a6..ea7f9d74 100644 --- a/examples/grid.sps +++ b/examples/grid.sps @@ -3,7 +3,7 @@ COMMENT -*-pspp-*- . COMMENT This program is useful for testing the behaviour of the Data and Variable Sheets. input program. - vector var(500 F8.3). +vector var(500 F8.3). loop #c = 1 to 1000. loop #v = 1 to 500. compute var(#v) = #v + #c / 1000. @@ -13,6 +13,8 @@ input program. end file. end input program. +variable label var1 'First variable' var2 'Second variable' var3 'Third variable'. + save outfile='grid.sav'. execute. diff --git a/lib/gtksheet/automake.mk b/lib/gtksheet/automake.mk index bba6becc..c5999498 100644 --- a/lib/gtksheet/automake.mk +++ b/lib/gtksheet/automake.mk @@ -6,16 +6,10 @@ lib_gtksheet_libgtksheet_a_CFLAGS = $(GTK_CFLAGS) -Wall -DGDK_MULTIHEAD_SAFE=1 lib_gtksheet_libgtksheet_a_SOURCES = \ - lib/gtksheet/gsheet-column-iface.c \ - lib/gtksheet/gsheet-column-iface.h \ - lib/gtksheet/gsheet-hetero-column.c \ - lib/gtksheet/gsheet-hetero-column.h \ lib/gtksheet/gsheetmodel.c \ lib/gtksheet/gsheetmodel.h \ lib/gtksheet/gsheet-row-iface.c \ lib/gtksheet/gsheet-row-iface.h \ - lib/gtksheet/gsheet-uniform-column.c \ - lib/gtksheet/gsheet-uniform-column.h \ lib/gtksheet/gsheet-uniform-row.c \ lib/gtksheet/gsheet-uniform-row.h \ lib/gtksheet/gtkextrafeatures.h \ @@ -27,7 +21,10 @@ lib_gtksheet_libgtksheet_a_SOURCES = \ lib/gtksheet/gtksheet.c \ lib/gtksheet/gtksheet.h \ lib/gtksheet/gtkxpaned.c \ - lib/gtksheet/gtkxpaned.h + lib/gtksheet/gtkxpaned.h \ + lib/gtksheet/psppire-axis.c \ + lib/gtksheet/psppire-axis.h + EXTRA_DIST += lib/gtksheet/OChangeLog \ lib/gtksheet/README diff --git a/lib/gtksheet/gsheet-column-iface.c b/lib/gtksheet/gsheet-column-iface.c deleted file mode 100644 index 56dcbca8..00000000 --- a/lib/gtksheet/gsheet-column-iface.c +++ /dev/null @@ -1,214 +0,0 @@ -/* GSheetColumn --- an abstract model of the column geometry of a - GSheet widget. - - * Copyright (C) 2006 Free Software Foundation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include -#include -#include -#include -#include -#include "gsheet-column-iface.h" -#include "gtkextra-marshal.h" -#include "gtkextra-sheet.h" - -enum { - COLUMNS_CHANGED, - LAST_SIGNAL -}; - -static guint sheet_column_signals[LAST_SIGNAL]; - -static void g_sheet_column_base_init (gpointer g_class); - -GType -g_sheet_column_get_type (void) -{ - static GType sheet_column_type = 0; - - if (! sheet_column_type) - { - static const GTypeInfo sheet_column_info = - - { - sizeof (GSheetColumnIface), /* class_size */ - g_sheet_column_base_init, /* base_init */ - NULL, /* base_finalize */ - NULL, - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, - 0, /* n_preallocs */ - NULL - }; - - sheet_column_type = - g_type_register_static (G_TYPE_INTERFACE, "GSheetColumn", - &sheet_column_info, 0); - - g_assert (sheet_column_type); - - g_type_interface_add_prerequisite (sheet_column_type, G_TYPE_OBJECT); - } - - return sheet_column_type; -} - - -static void -g_sheet_column_base_init (gpointer g_class) -{ - static gboolean initialized = FALSE; - - if (! initialized) - { - - sheet_column_signals[COLUMNS_CHANGED] = - g_signal_new ("columns_changed", - G_TYPE_SHEET_COLUMN, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GSheetColumnIface, columns_changed), - NULL, NULL, - gtkextra_VOID__INT_INT, - G_TYPE_NONE, 2, - G_TYPE_INT, - G_TYPE_INT); - - - initialized = TRUE; - } -} - - -void -g_sheet_column_set_width (GSheetColumn *column, glong col, gint size) -{ - g_return_if_fail (G_IS_SHEET_COLUMN (column)); - - if ((G_SHEET_COLUMN_GET_IFACE (column)->set_width) ) - (G_SHEET_COLUMN_GET_IFACE (column)->set_width) (column, col, size); -} - - -gint -g_sheet_column_get_width (const GSheetColumn *column, glong col) -{ - g_return_val_if_fail (G_IS_SHEET_COLUMN (column), -1); - - g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_width); - - return (G_SHEET_COLUMN_GET_IFACE (column)->get_width) (column, col); -} - - - -gboolean -g_sheet_column_get_sensitivity (const GSheetColumn *column, - glong col) -{ - g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE); - - g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_sensitivity); - - return (G_SHEET_COLUMN_GET_IFACE (column)->get_sensitivity) (column, - col); - -} - - -GtkSheetButton * -g_sheet_column_get_button (const GSheetColumn *column, - glong col) -{ - GtkSheetButton *button = gtk_sheet_button_new (); - - GSheetColumnIface *iface = G_SHEET_COLUMN_GET_IFACE (column); - - g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE); - - if ( iface->get_button_label) - button->label = iface->get_button_label (column, col); - - return button; -} - -GtkJustification -g_sheet_column_get_justification (const GSheetColumn *column, - glong col) -{ - g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE); - - g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_justification); - - return (G_SHEET_COLUMN_GET_IFACE (column)->get_justification) (column, col); -} - -gchar * -g_sheet_column_get_subtitle (const GSheetColumn *column, glong col) -{ - g_return_val_if_fail (G_IS_SHEET_COLUMN (column), NULL); - - if ( ! G_SHEET_COLUMN_GET_IFACE (column)->get_subtitle) - return NULL; - - return (G_SHEET_COLUMN_GET_IFACE (column)->get_subtitle) (column, col); -} - - - -glong -g_sheet_column_get_column_count (const GSheetColumn *geo) -{ - g_return_val_if_fail (G_IS_SHEET_COLUMN (geo), -1); - - g_assert ( G_SHEET_COLUMN_GET_IFACE (geo)->get_column_count); - - return (G_SHEET_COLUMN_GET_IFACE (geo)->get_column_count) (geo); -} - -gint -g_sheet_column_start_pixel (const GSheetColumn *geo, glong col) -{ - gint i; - gint start_pixel = 0; - - g_return_val_if_fail (G_IS_SHEET_COLUMN (geo), -1); - g_return_val_if_fail (col <= g_sheet_column_get_column_count (geo), -1); - - for (i = 0; i < col; ++i) - { - start_pixel += g_sheet_column_get_width (geo, i); - } - - return start_pixel; -} - - - -void -g_sheet_column_columns_changed (GSheetColumn *geo, - glong first, glong n_columns) -{ - g_return_if_fail (G_IS_SHEET_COLUMN (geo)); - - g_signal_emit (geo, sheet_column_signals[COLUMNS_CHANGED], 0, - first, n_columns); -} - diff --git a/lib/gtksheet/gsheet-column-iface.h b/lib/gtksheet/gsheet-column-iface.h deleted file mode 100644 index 34ccbf21..00000000 --- a/lib/gtksheet/gsheet-column-iface.h +++ /dev/null @@ -1,104 +0,0 @@ -/* GSheetColumn --- an abstract model of the column geometry of a - * GSheet widget. - * Copyright (C) 2006 Free Software Foundation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __GSHEET_COLUMN_IFACE_H -#define __GSHEET_COLUMN_IFACE_H - -#include -#include -#include - -#include "gtkextra-sheet.h" - - -G_BEGIN_DECLS - -#define G_TYPE_SHEET_COLUMN (g_sheet_column_get_type ()) -#define G_SHEET_COLUMN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_SHEET_COLUMN, GSheetColumn)) -#define G_IS_SHEET_COLUMN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_SHEET_COLUMN)) -#define G_SHEET_COLUMN_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), G_TYPE_SHEET_COLUMN, GSheetColumnIface)) - - -typedef struct _GSheetColumn GSheetColumn; -typedef struct _GSheetColumnIface GSheetColumnIface; -struct _GSheetColumnIface -{ - GTypeInterface g_iface; - - - /* Signals */ - void (* columns_changed) (GSheetColumn *geo, - glong col, glong n_columns); - - /* Virtual Table */ - gint (* get_width) (const GSheetColumn *gcolumn, glong col); - void (* set_width) (GSheetColumn *gcolumn, glong col, gint width); - - gboolean (* get_sensitivity) (const GSheetColumn *gcolumn, glong col); - const GtkSheetButton * (* get_button) (const GSheetColumn *gcolumn, glong col); - GtkJustification (* get_justification) (const GSheetColumn *gcolumn, glong col); - - glong (* get_column_count) (const GSheetColumn *geo); - - - GtkStateType (*get_button_state)(const GSheetColumn *geo, glong col); - gchar * (*get_button_label)(const GSheetColumn *geo, glong col); - gchar * (*get_subtitle)(const GSheetColumn *geo, glong col); - - gboolean (*get_button_visibility)(const GSheetColumn *geo, - glong col); - - GtkJustification * (*get_button_justification)(const GSheetColumn *geo, - glong col); -}; - - -GType g_sheet_column_get_type (void) G_GNUC_CONST; - - -gint g_sheet_column_get_width (const GSheetColumn *gcolumn, - glong col); - - -void g_sheet_column_set_width (GSheetColumn *gcolumn, - glong col, gint size); - - -gboolean g_sheet_column_get_sensitivity (const GSheetColumn *gcolumn, - glong col); - - -GtkSheetButton *g_sheet_column_get_button (const GSheetColumn *gcolumn, - glong col); - -gchar *g_sheet_column_get_subtitle (const GSheetColumn *, glong); - -GtkJustification g_sheet_column_get_justification (const GSheetColumn *gcolumn, glong col); - - -glong g_sheet_column_get_column_count (const GSheetColumn *geo); - -gint g_sheet_column_start_pixel (const GSheetColumn *geo, glong col); - -void g_sheet_column_columns_changed (GSheetColumn *geo, - glong first, glong n_columns); - -G_END_DECLS - -#endif /* __G_SHEET_COLUMN_IFACE_H__ */ diff --git a/lib/gtksheet/gsheet-hetero-column.c b/lib/gtksheet/gsheet-hetero-column.c deleted file mode 100644 index 42b1035f..00000000 --- a/lib/gtksheet/gsheet-hetero-column.c +++ /dev/null @@ -1,228 +0,0 @@ -/* gsheet-hetero-column.c - * PSPPIRE --- A Graphical User Interface for PSPP - * Copyright (C) 2006 Free Software Foundation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include - -#include "gsheet-column-iface.h" -#include "gsheet-hetero-column.h" -#include - - -static void g_sheet_hetero_column_init (GSheetHeteroColumn *hg); -static void g_sheet_hetero_column_class_init (GSheetHeteroColumnClass *class); -static void g_sheet_hetero_column_finalize (GObject *object); - -static void g_sheet_column_init (GSheetColumnIface *iface); - - -static GObjectClass *parent_class = NULL; - -GType -g_sheet_hetero_column_get_type (void) -{ - static GType hetero_column_type = 0; - - if (!hetero_column_type) - { - static const GTypeInfo hetero_column_info = - { - sizeof (GSheetHeteroColumnClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) g_sheet_hetero_column_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GSheetHeteroColumn), - 0, - (GInstanceInitFunc) g_sheet_hetero_column_init, - }; - - static const GInterfaceInfo column_info = - { - (GInterfaceInitFunc) g_sheet_column_init, - NULL, - NULL - }; - - hetero_column_type = - g_type_register_static (G_TYPE_OBJECT, "g_sheet_hetero_column", - &hetero_column_info, 0); - - g_type_add_interface_static (hetero_column_type, - G_TYPE_SHEET_COLUMN, - &column_info); - } - - return hetero_column_type; -} - - -static GtkSheetButton default_button; - - - -/** - * g_sheet_hetero_column_new: - * @width: The size of columns in this hetero column - * - * Return value: a new #g_sheet_hetero_column - **/ -GObject * -g_sheet_hetero_column_new (gint default_width, gint n_columns) -{ - gint i; - GSheetHeteroColumn *hg; - GObject *retval; - - retval = g_object_new (G_TYPE_SHEET_HETERO_COLUMN, NULL); - - hg = G_SHEET_HETERO_COLUMN (retval); - hg->n_columns = n_columns; - hg->default_width = default_width; - hg->col = g_new0 (struct GSheetHeteroColumnUnit, n_columns); - - for (i = 0 ; i < hg->n_columns; ++i ) - { - hg->col[i].button = default_button; - } - - return retval; -} - -static gint -g_sheet_hetero_column_get_width (const GSheetColumn *geom, glong i) -{ - GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN (geom); - - g_return_val_if_fail (i < hg->n_columns, -1); - - return hg->col[i].width; -} - -static gboolean -g_sheet_hetero_column_get_sensitivity (const GSheetColumn *geom, glong u) -{ - return TRUE; -} - - -static gchar * -g_sheet_hetero_column_get_button_label (const GSheetColumn *geom, glong u) -{ - GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN (geom); - - return g_locale_to_utf8 (hg->col[u].button.label, -1, 0, 0, 0); -} - - -static GtkJustification -g_sheet_hetero_column_get_justification (const GSheetColumn *geom, glong u) -{ - return GTK_JUSTIFY_LEFT; -} - - - -static glong -g_sheet_hetero_column_get_column_count (const GSheetColumn *geom) -{ - GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN (geom); - - return hg->n_columns; -} - -static void -g_sheet_hetero_column_class_init (GSheetHeteroColumnClass *class) -{ - GObjectClass *object_class; - - parent_class = g_type_class_peek_parent (class); - object_class = (GObjectClass*) class; - - object_class->finalize = g_sheet_hetero_column_finalize; - - default_button.label=NULL; - default_button.state=GTK_STATE_NORMAL; - default_button.justification=GTK_JUSTIFY_CENTER; - default_button.label_visible = TRUE; -} - - -static void -g_sheet_hetero_column_init (GSheetHeteroColumn *o) -{ -} - -static void -g_sheet_hetero_column_finalize (GObject *object) -{ - GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN (object); - - g_free (hg->col); -} - -static void -hetero_column_set_width (GSheetColumn *geo, glong i, gint size) -{ - GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN (geo); - - g_return_if_fail (i < hg->n_columns); - - hg->col[i].width = size; -} - - - -static void -g_sheet_column_init (GSheetColumnIface *iface) -{ - iface->get_width = g_sheet_hetero_column_get_width ; - iface->set_width = hetero_column_set_width ; - iface->get_sensitivity = g_sheet_hetero_column_get_sensitivity ; - iface->get_justification = g_sheet_hetero_column_get_justification; - iface->get_column_count = g_sheet_hetero_column_get_column_count; - - iface->get_button_label = g_sheet_hetero_column_get_button_label; -} - - -void -g_sheet_hetero_column_set_button_label (GSheetHeteroColumn *geo, - glong i, const gchar *label) -{ - g_return_if_fail (i < geo->n_columns); - - g_free (geo->col[i].button.label); - geo->col[i].button.label = g_malloc (strlen (label) + 1); - - g_stpcpy (geo->col[i].button.label, label); -} - - - - -void -g_sheet_hetero_column_set_width (GSheetHeteroColumn *geo, glong i, gint size) -{ - GSheetColumn *iface = G_SHEET_COLUMN (geo); - - hetero_column_set_width (iface, i, size); -} - - - diff --git a/lib/gtksheet/gsheet-hetero-column.h b/lib/gtksheet/gsheet-hetero-column.h deleted file mode 100644 index 9b19c1f3..00000000 --- a/lib/gtksheet/gsheet-hetero-column.h +++ /dev/null @@ -1,87 +0,0 @@ -/* GtkSheet widget for Gtk+. - * Copyright (C) 2006 Free Software Foundation - - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __G_SHEET_HETERO_COLUMN_H__ -#define __G_SHEET_HETERO_COLUMN_H__ - -#include -#include - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define G_TYPE_SHEET_HETERO_COLUMN (g_sheet_hetero_column_get_type ()) - -#define G_SHEET_HETERO_COLUMN(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, G_TYPE_SHEET_HETERO_COLUMN, GSheetHeteroColumn ) -#define G_SHEET_HETERO_COLUMN_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, g_sheet_hetero_column_get_type (), GSheetHeteroColumnClass) -#define G_IS_SHEET_HETERO_COLUMN(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, G_TYPE_SHEET_HETERO_COLUMN) - - - struct GSheetHeteroColumnUnit - { - GtkSheetButton button; - - gint width; - gboolean is_sensitive; - }; - - - struct _GSheetHeteroColumn{ - GObject parent; - - gint n_columns; - gint default_width; - - struct GSheetHeteroColumnUnit *col; - - }; - - struct _GSheetHeteroColumnClass - { - GObjectClass parent_class; - }; - - - - - /* create a new column */ - GObject * g_sheet_hetero_column_new (gint default_width, gint n_columns); - - GType g_sheet_hetero_column_get_type (void); - - - typedef struct _GSheetHeteroColumn GSheetHeteroColumn; - typedef struct _GSheetHeteroColumnClass GSheetHeteroColumnClass; - - - void g_sheet_hetero_column_set_button_label (GSheetHeteroColumn *geo, - glong i, const gchar *label); - - void g_sheet_hetero_column_set_width (GSheetHeteroColumn *geo, - glong i, gint size); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __G_SHEET_HETERO_COLUMN_H__ */ - - diff --git a/lib/gtksheet/gsheet-uniform-column.c b/lib/gtksheet/gsheet-uniform-column.c deleted file mode 100644 index c0f6732a..00000000 --- a/lib/gtksheet/gsheet-uniform-column.c +++ /dev/null @@ -1,173 +0,0 @@ -/* gsheet-uniform-column.c - * - * PSPPIRE --- A Graphical User Interface for PSPP - * Copyright (C) 2006 Free Software Foundation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include "gsheet-column-iface.h" -#include "gsheet-uniform-column.h" - - -static void g_sheet_uniform_column_init (GSheetUniformColumn *ug); -static void g_sheet_uniform_column_class_init (GSheetUniformColumnClass *class); -static void g_sheet_uniform_column_finalize (GObject *object); - -static void g_sheet_column_init (GSheetColumnIface *iface); - - -static GObjectClass *parent_class = NULL; - -GType -g_sheet_uniform_column_get_type (void) -{ - static GType uniform_column_type = 0; - - if (!uniform_column_type) - { - static const GTypeInfo uniform_column_info = - { - sizeof (GSheetUniformColumnClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) g_sheet_uniform_column_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GSheetUniformColumn), - 0, - (GInstanceInitFunc) g_sheet_uniform_column_init, - }; - - static const GInterfaceInfo column_info = - { - (GInterfaceInitFunc) g_sheet_column_init, - NULL, - NULL - }; - - uniform_column_type = - g_type_register_static (G_TYPE_OBJECT, "g_sheet_uniform_column", - &uniform_column_info, 0); - - g_type_add_interface_static (uniform_column_type, - G_TYPE_SHEET_COLUMN, - &column_info); - } - - return uniform_column_type; -} - - -/** - * g_sheet_uniform_column_new: - * @width: The size of columns in this uniform column - * - * Return value: a new #g_sheet_uniform_column - **/ -GObject * -g_sheet_uniform_column_new (gint width, gint n_columns) -{ - GSheetUniformColumn *ug; - GObject *retval; - - retval = g_object_new (G_TYPE_SHEET_UNIFORM_COLUMN, NULL); - - ug = G_SHEET_UNIFORM_COLUMN(retval); - ug->n_columns = n_columns; - ug->width = width; - ug->is_sensitive = FALSE; - - return retval; -} - -static gint -g_sheet_uniform_column_get_width (const GSheetColumn *geom, glong u) -{ - GSheetUniformColumn *ug = G_SHEET_UNIFORM_COLUMN (geom); - - return ug->width; -} - -static gboolean -g_sheet_uniform_column_get_sensitivity (const GSheetColumn *geom, glong u) -{ - GSheetUniformColumn *ug = G_SHEET_UNIFORM_COLUMN (geom); - - return ug->is_sensitive; -} - - -static gchar * -g_sheet_uniform_column_get_button_label (const GSheetColumn *geom, glong u) -{ - gchar *label = g_strdup_printf ("%ld", u); - - return label; -} - - -static GtkJustification -g_sheet_uniform_column_get_justification (const GSheetColumn *geom, glong u) -{ - return GTK_JUSTIFY_FILL; -} - - - -static glong -g_sheet_uniform_column_get_column_count (const GSheetColumn *geom) -{ - GSheetUniformColumn *ug = G_SHEET_UNIFORM_COLUMN (geom); - - return ug->n_columns; -} - -static void -g_sheet_uniform_column_class_init (GSheetUniformColumnClass *class) -{ - GObjectClass *object_class; - - parent_class = g_type_class_peek_parent (class); - object_class = (GObjectClass*) class; - - object_class->finalize = g_sheet_uniform_column_finalize; - -} - - -static void -g_sheet_uniform_column_init (GSheetUniformColumn *o) -{ -} - -static void -g_sheet_uniform_column_finalize (GObject *object) -{ -} - - -static void -g_sheet_column_init (GSheetColumnIface *iface) -{ - iface->get_width = g_sheet_uniform_column_get_width ; - iface->get_sensitivity = g_sheet_uniform_column_get_sensitivity ; - iface->get_justification = g_sheet_uniform_column_get_justification; - iface->get_column_count = g_sheet_uniform_column_get_column_count; - iface->get_button_label = g_sheet_uniform_column_get_button_label; -} - diff --git a/lib/gtksheet/gsheet-uniform-column.h b/lib/gtksheet/gsheet-uniform-column.h deleted file mode 100644 index 51fc53a0..00000000 --- a/lib/gtksheet/gsheet-uniform-column.h +++ /dev/null @@ -1,67 +0,0 @@ -/* GtkSheet widget for Gtk+. - * Copyright (C) 2006 Free Software Foundation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __G_SHEET_UNIFORM_COLUMN_H__ -#define __G_SHEET_UNIFORM_COLUMN_H__ - - -#include -#include - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define G_TYPE_SHEET_UNIFORM_COLUMN (g_sheet_uniform_column_get_type ()) - -#define G_SHEET_UNIFORM_COLUMN(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, G_TYPE_SHEET_UNIFORM_COLUMN, GSheetUniformColumn ) -#define G_SHEET_UNIFORM_COLUMN_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, g_sheet_uniform_column_get_type (), GSheetUniformColumnClass) -#define G_IS_SHEET_UNIFORM_COLUMN(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, G_TYPE_SHEET_UNIFORM_COLUMN) - - - struct _GSheetUniformColumn{ - GObject parent; - - gint n_columns; - gint width; - gboolean is_sensitive; - }; - - struct _GSheetUniformColumnClass - { - GObjectClass parent_class; - }; - - /* create a new column */ - GObject * g_sheet_uniform_column_new (gint width, gint n_columns); - - GType g_sheet_uniform_column_get_type (void); - - - typedef struct _GSheetUniformColumn GSheetUniformColumn; - typedef struct _GSheetUniformColumnClass GSheetUniformColumnClass; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __G_SHEET_UNIFORM_COLUMN_H__ */ - - diff --git a/lib/gtksheet/gsheetmodel.c b/lib/gtksheet/gsheetmodel.c index f06dc638..7e975237 100644 --- a/lib/gtksheet/gsheetmodel.c +++ b/lib/gtksheet/gsheetmodel.c @@ -508,3 +508,54 @@ g_sheet_model_get_row_count(const GSheetModel *model) return G_SHEET_MODEL_GET_IFACE (model)->get_row_count (model); } + + + +/* New functions since AXIS_TRANSITION */ +gboolean +g_sheet_model_get_column_sensitivity (const GSheetModel *model, gint col) +{ + if ( NULL == G_SHEET_MODEL_GET_IFACE (model)->get_column_sensitivity) + return TRUE; + + return G_SHEET_MODEL_GET_IFACE (model)->get_column_sensitivity (model, col); +} + + +gchar * +g_sheet_model_get_column_subtitle (const GSheetModel *model, + gint col) +{ + g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL); + + if ( NULL == G_SHEET_MODEL_GET_IFACE (model)->get_column_subtitle) + return NULL; + + return G_SHEET_MODEL_GET_IFACE (model)->get_column_subtitle (model, col); +} + + +GtkSheetButton * +g_sheet_model_get_column_button (const GSheetModel *model, + gint col) +{ + GtkSheetButton *button = gtk_sheet_button_new (); + + g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL); + + if ( G_SHEET_MODEL_GET_IFACE (model)->get_column_title) + button->label = G_SHEET_MODEL_GET_IFACE (model)->get_column_title (model, col); + + return button; +} + +GtkJustification +g_sheet_model_get_column_justification (const GSheetModel *model, + gint col) +{ + if ( G_SHEET_MODEL_GET_IFACE (model)->get_column_justification) + return G_SHEET_MODEL_GET_IFACE (model)->get_column_justification (model, col); + + return GTK_JUSTIFY_LEFT; +} + diff --git a/lib/gtksheet/gsheetmodel.h b/lib/gtksheet/gsheetmodel.h index 43583eb3..eb661c99 100644 --- a/lib/gtksheet/gsheetmodel.h +++ b/lib/gtksheet/gsheetmodel.h @@ -26,7 +26,7 @@ #include #include #include - +#include "gtkextra-sheet.h" G_BEGIN_DECLS @@ -51,8 +51,8 @@ typedef struct _GtkSheetCellBorder GtkSheetCellBorder; struct _GtkSheetRange { - glong row0,col0; /* upper-left cell */ - glong rowi,coli; /* lower-right cell */ + glong row0, col0; /* upper-left cell */ + glong rowi, coli; /* lower-right cell */ }; struct _GtkSheetCellBorder @@ -93,6 +93,8 @@ struct _GSheetModelIface + + /* Virtual Table */ gchar * (* get_string) (const GSheetModel *sheet_model, @@ -123,10 +125,20 @@ struct _GSheetModelIface glong row, glong column); + + /* column related metadata */ + + gchar * (*get_column_title) (const GSheetModel *mode, gint col); + gchar * (*get_column_subtitle) (const GSheetModel *mode, gint col); + gboolean * (*get_column_sensitivity) (const GSheetModel *mode, gint col); + GtkJustification (*get_column_justification) (const GSheetModel *mode, gint col); + const GtkSheetButton * (* get_button) (const GSheetModel *model, gint col); + glong (*get_column_count) (const GSheetModel *model); - glong (*get_row_count) (const GSheetModel *model); + /* row related metadata */ + glong (*get_row_count) (const GSheetModel *model); }; @@ -192,6 +204,20 @@ glong g_sheet_model_get_column_count (const GSheetModel *sheet_model); gint g_sheet_model_get_row_count (const GSheetModel *sheet_model); + + +gboolean g_sheet_model_get_column_sensitivity (const GSheetModel *model, + gint col); + +gchar * g_sheet_model_get_column_subtitle (const GSheetModel *model, + gint col); + +GtkSheetButton * g_sheet_model_get_column_button (const GSheetModel *, gint); + +GtkJustification g_sheet_model_get_column_justification (const GSheetModel *, + gint); + + G_END_DECLS #endif /* __G_SHEET_MODEL_H__ */ diff --git a/lib/gtksheet/gtksheet.c b/lib/gtksheet/gtksheet.c index f7ca3c28..31f242d2 100644 --- a/lib/gtksheet/gtksheet.c +++ b/lib/gtksheet/gtksheet.c @@ -176,7 +176,7 @@ max_fully_visible_row (const GtkSheet *sheet) glong row = max_visible_row (sheet); if ( g_sheet_row_start_pixel (sheet->row_geometry, row) - + + + g_sheet_row_get_height (sheet->row_geometry, row) > sheet->vadjustment->value) row--; @@ -185,26 +185,11 @@ max_fully_visible_row (const GtkSheet *sheet) } -/* returns the column index from a x pixel location */ +/* returns the column index from a pixel location */ static inline gint -column_from_xpixel (const GtkSheet *sheet, gint x) +column_from_xpixel (const GtkSheet *sheet, gint pixel) { - gint i; - gint cx = 0; - - if (x < 0) return -1; - for (i = 0; - i < g_sheet_column_get_column_count (sheet->column_geometry); i++) - { - if (x >= cx && - x <= (cx + g_sheet_column_get_width (sheet->column_geometry, i))) - return i; - - cx += g_sheet_column_get_width (sheet->column_geometry, i); - } - - /* no match */ - return g_sheet_column_get_column_count (sheet->column_geometry) - 1; + return psppire_axis_get_unit_at_pixel (sheet->haxis, pixel); } @@ -221,7 +206,7 @@ min_fully_visible_column (const GtkSheet *sheet) { glong col = min_visible_column (sheet); - if ( g_sheet_column_start_pixel (sheet->column_geometry, col) < sheet->hadjustment->value) + if ( psppire_axis_pixel_start (sheet->haxis, col) < sheet->hadjustment->value) col++; return col; @@ -243,9 +228,9 @@ max_fully_visible_column (const GtkSheet *sheet) { glong col = max_visible_column (sheet); - if ( g_sheet_column_start_pixel (sheet->column_geometry, col) + if ( psppire_axis_pixel_start (sheet->haxis, col) + - g_sheet_column_get_width (sheet->column_geometry, col) + psppire_axis_unit_size (sheet->haxis, col) > sheet->hadjustment->value) col--; @@ -320,9 +305,9 @@ POSSIBLE_DRAG (const GtkSheet *sheet, gint x, gint y, *drag_column = column_from_xpixel (sheet, x); *drag_row = yyy_row_ypixel_to_row (sheet, y); - if (x >= g_sheet_column_start_pixel (sheet->column_geometry, sheet->range.col0) - DRAG_WIDTH / 2 && - x <= g_sheet_column_start_pixel (sheet->column_geometry, sheet->range.coli) + - g_sheet_column_get_width (sheet->column_geometry, sheet->range.coli) + DRAG_WIDTH / 2) + if (x >= psppire_axis_pixel_start (sheet->haxis, sheet->range.col0) - DRAG_WIDTH / 2 && + x <= psppire_axis_pixel_start (sheet->haxis, sheet->range.coli) + + psppire_axis_unit_size (sheet->haxis, sheet->range.coli) + DRAG_WIDTH / 2) { ydrag = g_sheet_row_start_pixel (sheet->row_geometry, sheet->range.row0); if (y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2) @@ -343,14 +328,14 @@ POSSIBLE_DRAG (const GtkSheet *sheet, gint x, gint y, y <= g_sheet_row_start_pixel (sheet->row_geometry, sheet->range.rowi) + g_sheet_row_get_height (sheet->row_geometry, sheet->range.rowi) + DRAG_WIDTH / 2) { - xdrag = g_sheet_column_start_pixel (sheet->column_geometry, sheet->range.col0); + xdrag = psppire_axis_pixel_start (sheet->haxis, sheet->range.col0); if (x >= xdrag - DRAG_WIDTH / 2 && x <= xdrag + DRAG_WIDTH / 2) { *drag_column = sheet->range.col0; return TRUE; } - xdrag = g_sheet_column_start_pixel (sheet->column_geometry, sheet->range.coli) + - g_sheet_column_get_width (sheet->column_geometry, sheet->range.coli); + xdrag = psppire_axis_pixel_start (sheet->haxis, sheet->range.coli) + + psppire_axis_unit_size (sheet->haxis, sheet->range.coli); if (x >= xdrag - DRAG_WIDTH / 2 && x <= xdrag + DRAG_WIDTH / 2) { *drag_column = sheet->range.coli; @@ -372,8 +357,8 @@ POSSIBLE_RESIZE (const GtkSheet *sheet, gint x, gint y, sheet->range.col0 < 0 || sheet->range.coli < 0 ) return FALSE; - xdrag = g_sheet_column_start_pixel (sheet->column_geometry, sheet->range.coli)+ - g_sheet_column_get_width (sheet->column_geometry, sheet->range.coli); + xdrag = psppire_axis_pixel_start (sheet->haxis, sheet->range.coli)+ + psppire_axis_unit_size (sheet->haxis, sheet->range.coli); ydrag = g_sheet_row_start_pixel (sheet->row_geometry, sheet->range.rowi) + g_sheet_row_get_height (sheet->row_geometry, sheet->range.rowi); @@ -382,7 +367,7 @@ POSSIBLE_RESIZE (const GtkSheet *sheet, gint x, gint y, ydrag = g_sheet_row_start_pixel (sheet->row_geometry, min_visible_row (sheet)); if (sheet->state == GTK_SHEET_ROW_SELECTED) - xdrag = g_sheet_column_start_pixel (sheet->column_geometry, min_visible_column (sheet)); + xdrag = psppire_axis_pixel_start (sheet->haxis, min_visible_column (sheet)); *drag_column = column_from_xpixel (sheet, x); *drag_row = yyy_row_ypixel_to_row (sheet, y); @@ -400,7 +385,7 @@ rectangle_from_range (GtkSheet *sheet, const GtkSheetRange *range, { g_return_val_if_fail (range, FALSE); - r->x = g_sheet_column_start_pixel (sheet->column_geometry, range->col0); + r->x = psppire_axis_pixel_start (sheet->haxis, range->col0); r->x -= round (sheet->hadjustment->value); if ( sheet->row_titles_visible) @@ -413,9 +398,9 @@ rectangle_from_range (GtkSheet *sheet, const GtkSheetRange *range, if ( sheet->column_titles_visible) r->y += sheet->column_title_area.height; - r->width = g_sheet_column_start_pixel (sheet->column_geometry, range->coli) - - g_sheet_column_start_pixel (sheet->column_geometry, range->col0) + - g_sheet_column_get_width (sheet->column_geometry, range->coli); + r->width = psppire_axis_pixel_start (sheet->haxis, range->coli) - + psppire_axis_pixel_start (sheet->haxis, range->col0) + + psppire_axis_unit_size (sheet->haxis, range->coli); r->height = g_sheet_row_start_pixel (sheet->row_geometry, range->rowi) - g_sheet_row_start_pixel (sheet->row_geometry, range->row0) + @@ -714,7 +699,7 @@ enum { PROP_0, PROP_ROW_GEO, - PROP_COL_GEO, + PROP_HAXIS, PROP_MODEL }; @@ -729,13 +714,15 @@ gtk_sheet_set_row_geometry (GtkSheet *sheet, GSheetRow *geo) } static void -gtk_sheet_set_column_geometry (GtkSheet *sheet, GSheetColumn *geo) +gtk_sheet_set_horizontal_axis (GtkSheet *sheet, PsppireAxis *a) { - if ( sheet->column_geometry ) g_object_unref (sheet->column_geometry); + if ( sheet->haxis ) + g_object_unref (sheet->haxis); - sheet->column_geometry = geo; + sheet->haxis = a; - if ( sheet->column_geometry ) g_object_ref (sheet->column_geometry); + if ( sheet->haxis ) + g_object_ref (sheet->haxis); } @@ -753,11 +740,8 @@ gtk_sheet_set_property (GObject *object, case PROP_ROW_GEO: gtk_sheet_set_row_geometry (sheet, g_value_get_pointer (value)); break; - case PROP_COL_GEO: - gtk_sheet_set_column_geometry (sheet, g_value_get_pointer (value)); - if ( sheet->column_geometry) - g_signal_connect (sheet->column_geometry, "columns_changed", - G_CALLBACK (column_titles_changed), sheet); + case PROP_HAXIS: + gtk_sheet_set_horizontal_axis (sheet, g_value_get_pointer (value)); break; case PROP_MODEL: gtk_sheet_set_model (sheet, g_value_get_pointer (value)); @@ -781,8 +765,8 @@ gtk_sheet_get_property (GObject *object, case PROP_ROW_GEO: g_value_set_pointer (value, sheet->row_geometry); break; - case PROP_COL_GEO: - g_value_set_pointer (value, sheet->column_geometry); + case PROP_HAXIS: + g_value_set_pointer (value, sheet->haxis); break; case PROP_MODEL: g_value_set_pointer (value, sheet->model); @@ -800,7 +784,7 @@ gtk_sheet_class_init (GtkSheetClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); GParamSpec *row_geo_spec ; - GParamSpec *col_geo_spec ; + GParamSpec *haxis_spec ; GParamSpec *model_spec ; GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); @@ -1009,10 +993,10 @@ gtk_sheet_class_init (GtkSheetClass *klass) "A pointer to the model of the row geometry", G_PARAM_READABLE | G_PARAM_WRITABLE ); - col_geo_spec = - g_param_spec_pointer ("column-geometry", - "Column Geometry", - "A pointer to the model of the column geometry", + haxis_spec = + g_param_spec_pointer ("horizontal-axis", + "Horizontal Axis", + "A pointer to the PsppireAxis object for the columns", G_PARAM_READABLE | G_PARAM_WRITABLE ); model_spec = @@ -1030,8 +1014,8 @@ gtk_sheet_class_init (GtkSheetClass *klass) row_geo_spec); g_object_class_install_property (object_class, - PROP_COL_GEO, - col_geo_spec); + PROP_HAXIS, + haxis_spec); g_object_class_install_property (object_class, PROP_MODEL, @@ -1070,7 +1054,7 @@ static void gtk_sheet_init (GtkSheet *sheet) { sheet->model = NULL; - sheet->column_geometry = NULL; + sheet->haxis = NULL; sheet->row_geometry = NULL; sheet->flags = 0; @@ -1161,7 +1145,7 @@ columns_inserted_deleted_callback (GSheetModel *model, gint first_column, */ range.col0 = first_column; range.row0 = 0; - range.coli = g_sheet_column_get_column_count (sheet->column_geometry) - 1; + range.coli = psppire_axis_unit_count (sheet->haxis) - 1; range.rowi = g_sheet_row_get_row_count (sheet->row_geometry) - 1; adjust_scrollbars (sheet); @@ -1194,7 +1178,7 @@ rows_inserted_deleted_callback (GSheetModel *model, gint first_row, range.row0 = first_row; range.col0 = 0; range.rowi = g_sheet_row_get_row_count (sheet->row_geometry) - 1; - range.coli = g_sheet_column_get_column_count (sheet->column_geometry) - 1; + range.coli = psppire_axis_unit_count (sheet->haxis) - 1; adjust_scrollbars (sheet); @@ -1276,11 +1260,10 @@ range_update_callback (GSheetModel *m, gint row0, gint col0, * Returns: the new sheet widget */ GtkWidget * -gtk_sheet_new (GSheetRow *vgeo, GSheetColumn *hgeo, GSheetModel *model) +gtk_sheet_new (GSheetRow *vgeo, void *hgeo, GSheetModel *model) { GtkWidget *widget = g_object_new (GTK_TYPE_SHEET, "row-geometry", vgeo, - "column-geometry", hgeo, "model", model, NULL); return widget; @@ -1340,7 +1323,7 @@ column_titles_changed (GtkWidget *w, gint first, gint n_columns, gpointer data) if ( n_columns == -1 ) { extremity = TRUE; - n_columns = g_sheet_column_get_column_count (sheet->column_geometry) - 1 ; + n_columns = psppire_axis_unit_count (sheet->haxis) - 1 ; } if ( extremity) @@ -1399,7 +1382,7 @@ gtk_sheet_get_columns_count (GtkSheet *sheet) g_return_val_if_fail (sheet != NULL, 0); g_return_val_if_fail (GTK_IS_SHEET (sheet), 0); - return g_sheet_column_get_column_count (sheet->column_geometry); + return psppire_axis_unit_count (sheet->haxis); } static void @@ -1416,7 +1399,7 @@ gtk_sheet_autoresize_column (GtkSheet *sheet, gint column) g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (column >= g_sheet_column_get_column_count (sheet->column_geometry) || column < 0) return; + if (column >= psppire_axis_unit_count (sheet->haxis) || column < 0) return; for (row = 0; row < g_sheet_row_get_row_count (sheet->row_geometry); row++) { @@ -1438,7 +1421,7 @@ gtk_sheet_autoresize_column (GtkSheet *sheet, gint column) dispose_string (sheet, text); } - if (text_width > g_sheet_column_get_width (sheet->column_geometry, column) ) + if (text_width > psppire_axis_unit_size (sheet->haxis, column) ) { gtk_sheet_set_column_width (sheet, column, text_width); } @@ -1565,7 +1548,7 @@ gtk_sheet_moveto (GtkSheet *sheet, g_return_if_fail (col_align <= 1); g_return_if_fail (col < - g_sheet_column_get_column_count (sheet->column_geometry)); + psppire_axis_unit_count (sheet->haxis)); g_return_if_fail (row < g_sheet_row_get_row_count (sheet->row_geometry)); @@ -1582,7 +1565,7 @@ gtk_sheet_moveto (GtkSheet *sheet, if (col >= 0) { - gint x = g_sheet_column_start_pixel (sheet->column_geometry, col); + gint x = psppire_axis_pixel_start (sheet->haxis, col); gtk_adjustment_set_value (sheet->hadjustment, x - width * col_align); } @@ -1625,7 +1608,7 @@ gtk_sheet_select_row (GtkSheet *sheet, gint row) sheet->range.row0 = row; sheet->range.col0 = 0; sheet->range.rowi = row; - sheet->range.coli = g_sheet_column_get_column_count (sheet->column_geometry) - 1; + sheet->range.coli = psppire_axis_unit_count (sheet->haxis) - 1; sheet->active_cell.row = row; sheet->active_cell.col = 0; @@ -1640,7 +1623,7 @@ gtk_sheet_select_column (GtkSheet *sheet, gint column) g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (column < 0 || column >= g_sheet_column_get_column_count (sheet->column_geometry)) + if (column < 0 || column >= psppire_axis_unit_count (sheet->haxis)) return; if (sheet->state != GTK_SHEET_NORMAL) @@ -1673,10 +1656,10 @@ gtk_sheet_range_isvisible (const GtkSheet *sheet, if (range.rowi < 0 || range.rowi >= g_sheet_row_get_row_count (sheet->row_geometry)) return FALSE; - if (range.col0 < 0 || range.col0 >= g_sheet_column_get_column_count (sheet->column_geometry)) + if (range.col0 < 0 || range.col0 >= psppire_axis_unit_count (sheet->haxis)) return FALSE; - if (range.coli < 0 || range.coli >= g_sheet_column_get_column_count (sheet->column_geometry)) + if (range.coli < 0 || range.coli >= psppire_axis_unit_count (sheet->haxis)) return FALSE; if (range.rowi < min_visible_row (sheet)) @@ -1781,7 +1764,7 @@ gtk_sheet_dispose (GObject *object) if (sheet->model) g_object_unref (sheet->model); if (sheet->row_geometry) g_object_unref (sheet->row_geometry); - if (sheet->column_geometry) g_object_unref (sheet->column_geometry); + if (sheet->haxis) g_object_unref (sheet->haxis); g_object_unref (sheet->entry_container); sheet->entry_container = NULL; @@ -2155,7 +2138,7 @@ gtk_sheet_cell_draw (GtkSheet *sheet, gint row, gint col) return; if (col < 0 || - col >= g_sheet_column_get_column_count (sheet->column_geometry)) + col >= psppire_axis_unit_count (sheet->haxis)) return; gtk_sheet_get_attributes (sheet, row, col, &attributes); @@ -2380,7 +2363,7 @@ gtk_sheet_set_cell (GtkSheet *sheet, gint row, gint col, g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (col >= g_sheet_column_get_column_count (sheet->column_geometry) + if (col >= psppire_axis_unit_count (sheet->haxis) || row >= g_sheet_row_get_row_count (sheet->row_geometry)) return; @@ -2402,7 +2385,7 @@ gtk_sheet_cell_clear (GtkSheet *sheet, gint row, gint column) g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (column >= g_sheet_column_get_column_count (sheet->column_geometry) || + if (column >= psppire_axis_unit_count (sheet->haxis) || row >= g_sheet_row_get_row_count (sheet->row_geometry)) return; if (column < 0 || row < 0) return; @@ -2439,7 +2422,7 @@ gtk_sheet_cell_get_text (const GtkSheet *sheet, gint row, gint col) g_return_val_if_fail (sheet != NULL, NULL); g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL); - if (col >= g_sheet_column_get_column_count (sheet->column_geometry) || row >= g_sheet_row_get_row_count (sheet->row_geometry)) + if (col >= psppire_axis_unit_count (sheet->haxis) || row >= g_sheet_row_get_row_count (sheet->row_geometry)) return NULL; if (col < 0 || row < 0) return NULL; @@ -2460,7 +2443,7 @@ gtk_sheet_cell_get_state (GtkSheet *sheet, gint row, gint col) g_return_val_if_fail (sheet != NULL, 0); g_return_val_if_fail (GTK_IS_SHEET (sheet), 0); - if (col >= g_sheet_column_get_column_count (sheet->column_geometry) || row >= g_sheet_row_get_row_count (sheet->row_geometry)) return 0; + if (col >= psppire_axis_unit_count (sheet->haxis) || row >= g_sheet_row_get_row_count (sheet->row_geometry)) return 0; if (col < 0 || row < 0) return 0; state = sheet->state; @@ -2543,7 +2526,7 @@ gtk_sheet_get_pixel_info (GtkSheet *sheet, else { tcol = column_from_xpixel (sheet, x); - if (tcol > g_sheet_column_get_column_count (sheet->column_geometry)) + if (tcol > psppire_axis_unit_count (sheet->haxis)) return FALSE; } @@ -2561,14 +2544,14 @@ gtk_sheet_get_cell_area (GtkSheet *sheet, g_return_val_if_fail (sheet != NULL, 0); g_return_val_if_fail (GTK_IS_SHEET (sheet), 0); - if (row >= g_sheet_row_get_row_count (sheet->row_geometry) || column >= g_sheet_column_get_column_count (sheet->column_geometry)) + if (row >= g_sheet_row_get_row_count (sheet->row_geometry) || column >= psppire_axis_unit_count (sheet->haxis)) return FALSE; - area->x = (column == -1) ? 0 : g_sheet_column_start_pixel (sheet->column_geometry, column); + area->x = (column == -1) ? 0 : psppire_axis_pixel_start (sheet->haxis, column); area->y = (row == -1) ? 0 : g_sheet_row_start_pixel (sheet->row_geometry, row); area->width= (column == -1) ? sheet->row_title_area.width - : g_sheet_column_get_width (sheet->column_geometry, column); + : psppire_axis_unit_size (sheet->haxis, column); area->height= (row == -1) ? sheet->column_title_area.height : g_sheet_row_get_height (sheet->row_geometry, row); @@ -2587,7 +2570,7 @@ gtk_sheet_set_active_cell (GtkSheet *sheet, gint row, gint col) if (row >= g_sheet_row_get_row_count (sheet->row_geometry) || - col >= g_sheet_column_get_column_count (sheet->column_geometry)) + col >= psppire_axis_unit_count (sheet->haxis)) return; sheet->active_cell.row = row; @@ -2696,7 +2679,7 @@ change_active_cell (GtkSheet *sheet, gint row, gint col) return; if ( row > g_sheet_row_get_row_count (sheet->row_geometry) - || col > g_sheet_column_get_column_count (sheet->column_geometry)) + || col > psppire_axis_unit_count (sheet->haxis)) return; if (sheet->state != GTK_SHEET_NORMAL) @@ -2880,10 +2863,10 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) if (mask1 != mask2) { - x = g_sheet_column_start_pixel (sheet->column_geometry, j); + x = psppire_axis_pixel_start (sheet->haxis, j); y = g_sheet_row_start_pixel (sheet->row_geometry, i); - width = g_sheet_column_start_pixel (sheet->column_geometry, j)- x+ - g_sheet_column_get_width (sheet->column_geometry, j); + width = psppire_axis_pixel_start (sheet->haxis, j)- x+ + psppire_axis_unit_size (sheet->haxis, j); height = g_sheet_row_start_pixel (sheet->row_geometry, i) - y + g_sheet_row_get_height (sheet->row_geometry, i); if (i == sheet->range.row0) @@ -2901,10 +2884,10 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) if (i != sheet->active_cell.row || j != sheet->active_cell.col) { - x = g_sheet_column_start_pixel (sheet->column_geometry, j); + x = psppire_axis_pixel_start (sheet->haxis, j); y = g_sheet_row_start_pixel (sheet->row_geometry, i); - width = g_sheet_column_start_pixel (sheet->column_geometry, j)- x+ - g_sheet_column_get_width (sheet->column_geometry, j); + width = psppire_axis_pixel_start (sheet->haxis, j)- x+ + psppire_axis_unit_size (sheet->haxis, j); height = g_sheet_row_start_pixel (sheet->row_geometry, i) - y + g_sheet_row_get_height (sheet->row_geometry, i); @@ -2944,9 +2927,9 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) if (state == GTK_STATE_SELECTED && !selected) { - x = g_sheet_column_start_pixel (sheet->column_geometry, j); + x = psppire_axis_pixel_start (sheet->haxis, j); y = g_sheet_row_start_pixel (sheet->row_geometry, i); - width = g_sheet_column_start_pixel (sheet->column_geometry, j) - x + g_sheet_column_get_width (sheet->column_geometry, j); + width = psppire_axis_pixel_start (sheet->haxis, j) - x + psppire_axis_unit_size (sheet->haxis, j); height = g_sheet_row_start_pixel (sheet->row_geometry, i) - y + g_sheet_row_get_height (sheet->row_geometry, i); if (i == sheet->range.row0) @@ -2979,9 +2962,9 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) (i != sheet->active_cell.row || j != sheet->active_cell.col)) { - x = g_sheet_column_start_pixel (sheet->column_geometry, j); + x = psppire_axis_pixel_start (sheet->haxis, j); y = g_sheet_row_start_pixel (sheet->row_geometry, i); - width = g_sheet_column_start_pixel (sheet->column_geometry, j) - x + g_sheet_column_get_width (sheet->column_geometry, j); + width = psppire_axis_pixel_start (sheet->haxis, j) - x + psppire_axis_unit_size (sheet->haxis, j); height = g_sheet_row_start_pixel (sheet->row_geometry, i) - y + g_sheet_row_get_height (sheet->row_geometry, i); if (i == new_range.row0) @@ -3025,9 +3008,9 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) mask2 = j == new_range.coli ? mask2 + 8 : mask2; if (mask2 != mask1 || (mask2 == mask1 && state != GTK_STATE_SELECTED)) { - x = g_sheet_column_start_pixel (sheet->column_geometry, j); + x = psppire_axis_pixel_start (sheet->haxis, j); y = g_sheet_row_start_pixel (sheet->row_geometry, i); - width = g_sheet_column_get_width (sheet->column_geometry, j); + width = psppire_axis_unit_size (sheet->haxis, j); height = g_sheet_row_get_height (sheet->row_geometry, i); if (mask2 & 1) gdk_draw_rectangle (sheet->sheet_window, @@ -3319,7 +3302,7 @@ gtk_sheet_button_press (GtkWidget *widget, sheet_signals[BUTTON_EVENT_COLUMN], 0, column, event); - if (g_sheet_column_get_sensitivity (sheet->column_geometry, column)) + if (g_sheet_model_get_column_sensitivity (sheet->model, column)) { if ( event->type == GDK_2BUTTON_PRESS && event->button == 1) g_signal_emit (sheet, @@ -3492,7 +3475,7 @@ gtk_sheet_button_press (GtkWidget *widget, column = column_from_xpixel (sheet, x); - if (g_sheet_column_get_sensitivity (sheet->column_geometry, column)) + if (g_sheet_model_get_column_sensitivity (sheet->model, column)) { veto = gtk_sheet_click_cell (sheet, -1, column); gtk_grab_add (GTK_WIDGET (sheet)); @@ -3532,7 +3515,7 @@ gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column) cell.col = column; if (row >= g_sheet_row_get_row_count (sheet->row_geometry) - || column >= g_sheet_column_get_column_count (sheet->column_geometry)) + || column >= psppire_axis_unit_count (sheet->haxis)) { return FALSE; } @@ -3572,7 +3555,7 @@ gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column) sheet->range.col0 = 0; sheet->range.rowi = g_sheet_row_get_row_count (sheet->row_geometry) - 1; sheet->range.coli = - g_sheet_column_get_column_count (sheet->column_geometry) - 1; + psppire_axis_unit_count (sheet->haxis) - 1; sheet->active_cell.row = 0; sheet->active_cell.col = 0; gtk_sheet_select_range (sheet, NULL); @@ -3843,9 +3826,7 @@ motion_timeout_callback (gpointer data) if (sheet->row_title_under) { GSheetRow *row_geo = sheet->row_geometry; - gchar *text; - - text = g_sheet_row_get_subtitle (row_geo, row); + gchar *text = g_sheet_row_get_subtitle (row_geo, row); show_subtitle (sheet, row, -1, text); g_free (text); @@ -3853,10 +3834,8 @@ motion_timeout_callback (gpointer data) if (sheet->column_title_under) { - GSheetColumn *col_geo = sheet->column_geometry; - gchar *text; - - text = g_sheet_column_get_subtitle (col_geo, column); + gchar *text = g_sheet_model_get_column_subtitle (sheet->model, + column); show_subtitle (sheet, -1, column, text); @@ -4054,7 +4033,7 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) sheet->y_drag = y; aux = sheet->range; if (aux.row0 + row >= 0 && aux.rowi + row < g_sheet_row_get_row_count (sheet->row_geometry) && - aux.col0 + column >= 0 && aux.coli + column < g_sheet_column_get_column_count (sheet->column_geometry)) + aux.col0 + column >= 0 && aux.coli + column < psppire_axis_unit_count (sheet->haxis)) { aux = sheet->drag_range; sheet->drag_range.row0 = sheet->range.row0 + row; @@ -4076,7 +4055,7 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) GtkSheetRange aux; gint v_h, current_col, current_row, col_threshold, row_threshold; v_h = 1; - if (abs (x - g_sheet_column_start_pixel (sheet->column_geometry, sheet->drag_cell.col)) > + if (abs (x - psppire_axis_pixel_start (sheet->haxis, sheet->drag_cell.col)) > abs (y - g_sheet_row_start_pixel (sheet->row_geometry, sheet->drag_cell.row))) v_h = 2; current_col = column_from_xpixel (sheet, x); @@ -4086,8 +4065,8 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) /*use half of column width resp. row height as threshold to expand selection*/ - col_threshold = g_sheet_column_start_pixel (sheet->column_geometry, current_col) + - g_sheet_column_get_width (sheet->column_geometry, current_col) / 2; + col_threshold = psppire_axis_pixel_start (sheet->haxis, current_col) + + psppire_axis_unit_size (sheet->haxis, current_col) / 2; if (column > 0) { if (x < col_threshold) @@ -4123,7 +4102,7 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) row = 0; if (aux.row0 + row >= 0 && aux.rowi + row < g_sheet_row_get_row_count (sheet->row_geometry) && - aux.col0 + column >= 0 && aux.coli + column < g_sheet_column_get_column_count (sheet->column_geometry)) + aux.col0 + column >= 0 && aux.coli + column < psppire_axis_unit_count (sheet->haxis)) { aux = sheet->drag_range; sheet->drag_range = sheet->range; @@ -4191,7 +4170,7 @@ gtk_sheet_extend_selection (GtkSheet *sheet, gint row, gint column) switch (sheet->state) { case GTK_SHEET_ROW_SELECTED: - column = g_sheet_column_get_column_count (sheet->column_geometry) - 1; + column = psppire_axis_unit_count (sheet->haxis) - 1; break; case GTK_SHEET_COLUMN_SELECTED: row = g_sheet_row_get_row_count (sheet->row_geometry) - 1; @@ -4316,7 +4295,7 @@ step_sheet (GtkSheet *sheet, GtkScrollType dir) g_sheet_row_get_row_count (sheet->row_geometry) - 1); minimize_int (&new_cell.col, - g_sheet_column_get_column_count (sheet->column_geometry) - 1); + psppire_axis_unit_count (sheet->haxis) - 1); g_signal_emit (sheet, sheet_signals[TRAVERSE], 0, &sheet->active_cell, @@ -4331,7 +4310,7 @@ step_sheet (GtkSheet *sheet, GtkScrollType dir) if ( new_cell.col > max_fully_visible_column (sheet)) { glong hpos = - g_sheet_column_start_pixel (sheet->column_geometry, + psppire_axis_pixel_start (sheet->haxis, new_cell.col + 1); hpos -= sheet->hadjustment->page_size; @@ -4341,7 +4320,7 @@ step_sheet (GtkSheet *sheet, GtkScrollType dir) else if ( new_cell.col < min_fully_visible_column (sheet)) { glong hpos = - g_sheet_column_start_pixel (sheet->column_geometry, + psppire_axis_pixel_start (sheet->haxis, new_cell.col); gtk_adjustment_set_value (sheet->hadjustment, @@ -4584,7 +4563,7 @@ draw_column_title_buttons (GtkSheet *sheet) } if (max_visible_column (sheet) == - g_sheet_column_get_column_count (sheet->column_geometry) - 1) + psppire_axis_unit_count (sheet->haxis) - 1) gdk_window_clear_area (sheet->column_title_window, 0, 0, sheet->column_title_area.width, @@ -4945,14 +4924,14 @@ gtk_sheet_column_title_button_draw (GtkSheet *sheet, gint column) if (column < min_visible_column (sheet)) return; if (column > max_visible_column (sheet)) return; - button = g_sheet_column_get_button (sheet->column_geometry, column); + button = g_sheet_model_get_column_button (sheet->model, column); allocation.y = 0; - allocation.x = g_sheet_column_start_pixel (sheet->column_geometry, column) + CELL_SPACING; + allocation.x = psppire_axis_pixel_start (sheet->haxis, column) + CELL_SPACING; allocation.x -= sheet->hadjustment->value; allocation.height = sheet->column_title_area.height; - allocation.width = g_sheet_column_get_width (sheet->column_geometry, column); - is_sensitive = g_sheet_column_get_sensitivity (sheet->column_geometry, column); + allocation.width = psppire_axis_unit_size (sheet->haxis, column); + is_sensitive = g_sheet_model_get_column_sensitivity (sheet->model, column); gtk_sheet_button_draw (sheet, sheet->column_title_window, button, is_sensitive, allocation); @@ -5044,12 +5023,12 @@ adjust_scrollbars (GtkSheet *sheet) sheet->hadjustment->page_increment = width; - last_col = g_sheet_column_get_column_count (sheet->column_geometry) - 1; + last_col = psppire_axis_unit_count (sheet->haxis) - 1; sheet->hadjustment->upper = - g_sheet_column_start_pixel (sheet->column_geometry, last_col) + psppire_axis_pixel_start (sheet->haxis, last_col) + - g_sheet_column_get_width (sheet->column_geometry, last_col) + psppire_axis_unit_size (sheet->haxis, last_col) ; sheet->hadjustment->lower = 0; @@ -5164,10 +5143,10 @@ draw_xor_rectangle (GtkSheet *sheet, GtkSheetRange range) GdkRectangle clip_area, area; GdkGCValues values; - area.x = g_sheet_column_start_pixel (sheet->column_geometry, range.col0); + area.x = psppire_axis_pixel_start (sheet->haxis, range.col0); area.y = g_sheet_row_start_pixel (sheet->row_geometry, range.row0); - area.width = g_sheet_column_start_pixel (sheet->column_geometry, range.coli)- area.x+ - g_sheet_column_get_width (sheet->column_geometry, range.coli); + area.width = psppire_axis_pixel_start (sheet->haxis, range.coli)- area.x+ + psppire_axis_unit_size (sheet->haxis, range.coli); area.height = g_sheet_row_start_pixel (sheet->row_geometry, range.rowi)- area.y + g_sheet_row_get_height (sheet->row_geometry, range.rowi); @@ -5222,7 +5201,7 @@ draw_xor_rectangle (GtkSheet *sheet, GtkSheetRange range) static guint new_column_width (GtkSheet *sheet, gint column, gint *x) { - gint left_pos = g_sheet_column_start_pixel (sheet->column_geometry, column) + gint left_pos = psppire_axis_pixel_start (sheet->haxis, column) - sheet->hadjustment->value; gint width = *x - left_pos; @@ -5233,7 +5212,9 @@ new_column_width (GtkSheet *sheet, gint column, gint *x) *x = left_pos + width; } +#if AXIS_TRANSITION g_sheet_column_set_width (sheet->column_geometry, column, width); +#endif draw_column_title_buttons (sheet); @@ -5281,13 +5262,15 @@ gtk_sheet_set_column_width (GtkSheet *sheet, g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (column < 0 || column >= g_sheet_column_get_column_count (sheet->column_geometry)) + if (column < 0 || column >= psppire_axis_unit_count (sheet->haxis)) return; gtk_sheet_column_size_request (sheet, column, &min_width); if (width < min_width) return; +#if AXIS_TRANSITION g_sheet_column_set_width (sheet->column_geometry, column, width); +#endif if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) { @@ -5374,7 +5357,7 @@ gtk_sheet_get_attributes (const GtkSheet *sheet, gint row, gint col, } attr->justification = - g_sheet_column_get_justification (sheet->column_geometry, col); + g_sheet_model_get_column_justification (sheet->model, col); j = g_sheet_model_get_justification (sheet->model, row, col); if (j) @@ -5434,7 +5417,7 @@ gtk_sheet_column_size_request (GtkSheet *sheet, { GtkRequisition button_requisition; - GtkSheetButton *button = g_sheet_column_get_button (sheet->column_geometry, col); + GtkSheetButton *button = g_sheet_model_get_column_button (sheet->model, col); gtk_sheet_button_size_request (sheet, button, @@ -5498,7 +5481,6 @@ gtk_sheet_button_free (GtkSheetButton *button) g_free (button); } - static void append_cell_text (GString *string, const GtkSheet *sheet, gint r, gint c) { diff --git a/lib/gtksheet/gtksheet.h b/lib/gtksheet/gtksheet.h index fa1ac422..de308a60 100644 --- a/lib/gtksheet/gtksheet.h +++ b/lib/gtksheet/gtksheet.h @@ -30,9 +30,8 @@ #include "gtkextra-sheet.h" #include "gsheetmodel.h" -#include "gsheet-column-iface.h" #include "gsheet-row-iface.h" - +#include "psppire-axis.h" G_BEGIN_DECLS @@ -91,7 +90,10 @@ struct _GtkSheet GtkBin parent; gboolean dispose_has_run; + /* GSheetColumn *column_geometry; + */ + PsppireAxis *haxis; GSheetRow *row_geometry; guint16 flags; @@ -231,18 +233,18 @@ GtkType gtk_sheet_range_get_type (void); /* create a new sheet */ -GtkWidget * gtk_sheet_new (GSheetRow *vgeo, GSheetColumn *hgeo, +GtkWidget * gtk_sheet_new (GSheetRow *vgeo, void *hgeo, GSheetModel *model); /* create a new sheet with custom entry */ GtkWidget * gtk_sheet_new_with_custom_entry (GSheetRow *vgeo, - GSheetColumn *hgeo, + void *hgeo, GtkType entry_type); void gtk_sheet_construct_with_custom_entry (GtkSheet *sheet, GSheetRow *vgeo, - GSheetColumn *hgeo, + void *hgeo, GtkType entry_type); /* Change entry */ void gtk_sheet_change_entry (GtkSheet *sheet, GtkType entry_type); diff --git a/lib/gtksheet/psppire-axis.c b/lib/gtksheet/psppire-axis.c new file mode 100644 index 00000000..2a69fbef --- /dev/null +++ b/lib/gtksheet/psppire-axis.c @@ -0,0 +1,181 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2008 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 +#include + +#include +#include "psppire-axis.h" +#include + + +/* --- prototypes --- */ +static void psppire_axis_class_init (PsppireAxisClass *class); +static void psppire_axis_init (PsppireAxis *axis); +static void psppire_axis_finalize (GObject *object); + + +/* --- variables --- */ +static GObjectClass *parent_class = NULL; + +/* --- functions --- */ +/** + * psppire_axis_get_type: + * @returns: the type ID for accelerator groups. + */ +GType +psppire_axis_get_type (void) +{ + static GType object_type = 0; + + if (!object_type) + { + static const GTypeInfo object_info = { + sizeof (PsppireAxisClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) psppire_axis_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (PsppireAxis), + 0, /* n_preallocs */ + (GInstanceInitFunc) psppire_axis_init, + }; + + object_type = g_type_register_static (G_TYPE_OBJECT, + "PsppireAxis", + &object_info, 0); + } + + return object_type; +} + + +static void +psppire_axis_class_init (PsppireAxisClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + parent_class = g_type_class_peek_parent (class); + + object_class->finalize = psppire_axis_finalize; +} + +static void +psppire_axis_init (PsppireAxis *axis) +{ + tower_init (&axis->tower); +} + + +static void +psppire_axis_finalize (GObject *object) +{ + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +/** + * psppire_axis_new: + * @returns: a new #PsppireAxis object + * + * Creates a new #PsppireAxis. + */ +PsppireAxis* +psppire_axis_new (gint w) +{ + PsppireAxis *new_axis = g_object_new (G_TYPE_PSPPIRE_AXIS, NULL); + + new_axis->width = w; + + return new_axis; +} + + +gint +psppire_axis_unit_size (PsppireAxis *a, gint unit) +{ + if ( a->width == -1) + { + const struct tower_node *node; + if (unit >= tower_count (&a->tower)) + return 0; + + node = tower_get (&a->tower, unit); + + return tower_node_get_size (node); + } + + return a->width; +} + +gint +psppire_axis_unit_count (PsppireAxis *a) +{ + if (a->width == -1) + return tower_count (&a->tower); + + return 600; +} + +glong +psppire_axis_pixel_start (PsppireAxis *a, gint unit) +{ + if ( a->width == -1 ) + { + const struct tower_node *node; + + if ( unit >= tower_count (&a->tower)) + return tower_height (&a->tower); + + node = tower_get (&a->tower, unit); + + return tower_node_get_level (node); + } + + return a->width * unit; +} + +gint +psppire_axis_get_unit_at_pixel (PsppireAxis *a, glong pixel) +{ + if (a->width == -1) + { + const struct tower_node *node; + unsigned long int node_start; + + if (pixel >= tower_height (&a->tower)) + return tower_count (&a->tower); + + node = tower_lookup (&a->tower, pixel, &node_start); + + return tower_node_get_index (node); + } + + return pixel / a->width; +} + +void +psppire_axis_append (PsppireAxis *a, gint width) +{ + struct tower_node *new = g_slice_alloc0 (sizeof *new); + tower_insert (&a->tower, width, new, NULL); +} + + + + + diff --git a/lib/gtksheet/psppire-axis.h b/lib/gtksheet/psppire-axis.h new file mode 100644 index 00000000..8c362d6e --- /dev/null +++ b/lib/gtksheet/psppire-axis.h @@ -0,0 +1,82 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2008 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 PSPPIRE_AXIS_H__ +#define PSPPIRE_AXIS_H__ + + +#include +#include + +#include + +G_BEGIN_DECLS + + +/* --- type macros --- */ +#define G_TYPE_PSPPIRE_AXIS (psppire_axis_get_type ()) +#define PSPPIRE_AXIS(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_PSPPIRE_AXIS, PsppireAxis)) +#define PSPPIRE_AXIS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G_TYPE_PSPPIRE_AXIS, PsppireAxisClass)) +#define PSPPIRE_IS_AXIS(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_PSPPIRE_AXIS)) +#define PSPPIRE_IS_AXIS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G_TYPE_PSPPIRE_AXIS)) +#define PSPPIRE_AXIS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G_TYPE_PSPPIRE_AXIS, PsppireAxisClass)) + + + +/* --- typedefs & structures --- */ +typedef struct _PsppireAxis PsppireAxis; +typedef struct _PsppireAxisClass PsppireAxisClass; + + +struct _PsppireAxis +{ + GObject parent; + gint width ; + + struct tower tower; +}; + +struct _PsppireAxisClass +{ + GObjectClass parent_class; + +}; + +GType psppire_axis_get_type (void); + +PsppireAxis* psppire_axis_new (gint w); + + +/* Interface between sheet and axis */ + +gint psppire_axis_unit_size (PsppireAxis *a, gint unit); + +gint psppire_axis_unit_count (PsppireAxis *a); + +glong psppire_axis_pixel_start (PsppireAxis *a, gint unit); + +gint psppire_axis_get_unit_at_pixel (PsppireAxis *a, glong pixel); + + + +/* Interface between axis and model */ + +void psppire_axis_append (PsppireAxis *a, gint width); + +G_END_DECLS + +#endif /* PSPPIRE_AXIS_H__ */ diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 072e55ba..fe4fcb62 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -21,7 +21,6 @@ #include "psppire-data-editor.h" #include "psppire-var-sheet.h" -#include #include #include "psppire-data-store.h" #include "helper.h" @@ -221,7 +220,6 @@ psppire_data_editor_set_property (GObject *object, for (i = 0 ; i < 4 ; ++i ) g_object_set (de->data_sheet[i], "row-geometry", de->data_store, - "column-geometry", de->data_store, "model", de->data_store, NULL); break; @@ -613,6 +611,7 @@ static void init_sheet (PsppireDataEditor *de, int i, GtkAdjustment *hadj, GtkAdjustment *vadj) { + PsppireAxis *haxis = psppire_axis_new (100); de->sheet_bin[i] = gtk_scrolled_window_new (hadj, vadj); de->data_sheet[i] = gtk_sheet_new (NULL, NULL, NULL); @@ -622,6 +621,10 @@ init_sheet (PsppireDataEditor *de, int i, "shadow-type", GTK_SHADOW_ETCHED_IN, NULL); + g_object_set (de->data_sheet[i], + "horizontal-axis", haxis, + NULL); + gtk_container_add (GTK_CONTAINER (de->sheet_bin[i]), de->data_sheet[i]); g_signal_connect (de->data_sheet[i], "traverse", diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 9f7e4075..9835d307 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2006 Free Software Foundation + Copyright (C) 2006, 2008 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 @@ -26,7 +26,6 @@ #include #include -#include #include #include @@ -45,7 +44,6 @@ static void psppire_data_store_init (PsppireDataStore *data_store); static void psppire_data_store_class_init (PsppireDataStoreClass *class); static void psppire_data_store_sheet_model_init (GSheetModelIface *iface); -static void psppire_data_store_sheet_column_init (GSheetColumnIface *iface); static void psppire_data_store_sheet_row_init (GSheetRowIface *iface); static void psppire_data_store_finalize (GObject *object); @@ -94,13 +92,6 @@ psppire_data_store_get_type (void) NULL }; - static const GInterfaceInfo sheet_column_info = - { - (GInterfaceInitFunc) psppire_data_store_sheet_column_init, - NULL, - NULL - }; - static const GInterfaceInfo sheet_row_info = { (GInterfaceInitFunc) psppire_data_store_sheet_row_init, @@ -116,10 +107,6 @@ psppire_data_store_get_type (void) G_TYPE_SHEET_MODEL, &sheet_model_info); - g_type_add_interface_static (data_store_type, - G_TYPE_SHEET_COLUMN, - &sheet_column_info); - g_type_add_interface_static (data_store_type, G_TYPE_SHEET_ROW, &sheet_row_info); @@ -217,6 +204,11 @@ psppire_data_store_set_string_wrapper (GSheetModel *model, +static gchar * get_column_subtitle (const GSheetModel *model, gint col); +static gchar * get_column_button_label (const GSheetModel *model, gint col); +static gboolean get_column_sensitivity (const GSheetModel *model, gint col); +static GtkJustification get_column_justification (const GSheetModel *model, gint col); + static void psppire_data_store_sheet_model_init (GSheetModelIface *iface) @@ -233,6 +225,11 @@ psppire_data_store_sheet_model_init (GSheetModelIface *iface) iface->get_cell_border = NULL; iface->get_column_count = psppire_data_store_get_var_count; iface->get_row_count = psppire_data_store_get_case_count_wrapper; + + iface->get_column_subtitle = get_column_subtitle; + iface->get_column_title = get_column_button_label; + iface->get_column_sensitivity = get_column_sensitivity; + iface->get_column_justification = get_column_justification; } static void @@ -293,10 +290,12 @@ delete_variable_callback (GObject *obj, gint dict_index, { PsppireDataStore *store = PSPPIRE_DATA_STORE (data); +#if AXIS_TRANSITION g_sheet_model_columns_deleted (G_SHEET_MODEL (store), dict_index, 1); g_sheet_column_columns_changed (G_SHEET_COLUMN (store), dict_index, -1); +#endif } @@ -305,6 +304,7 @@ variable_changed_callback (GObject *obj, gint var_num, gpointer data) { PsppireDataStore *store = PSPPIRE_DATA_STORE (data); +#if AXIS_TRANSITION g_sheet_column_columns_changed (G_SHEET_COLUMN (store), var_num, 1); @@ -312,6 +312,7 @@ variable_changed_callback (GObject *obj, gint var_num, gpointer data) g_sheet_model_range_changed (G_SHEET_MODEL (store), -1, var_num, -1, var_num); +#endif } static void @@ -340,8 +341,10 @@ insert_variable_callback (GObject *obj, gint var_num, gpointer data) psppire_case_file_insert_values (store->case_file, 1, posn); +#if AXIS_TRANSITION g_sheet_column_columns_changed (G_SHEET_COLUMN (store), var_num, 1); +#endif g_sheet_model_columns_inserted (G_SHEET_MODEL (store), var_num, 1); } @@ -485,8 +488,9 @@ psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *di /* The entire model has changed */ g_sheet_model_range_changed (G_SHEET_MODEL (data_store), -1, -1, -1, -1); +#if AXIS_TRANSITION g_sheet_column_columns_changed (G_SHEET_COLUMN (data_store), 0, -1); - +#endif if ( data_store->dict ) for (i = 0 ; i < n_dict_signals; ++i ) @@ -760,6 +764,7 @@ psppire_data_store_get_reader (PsppireDataStore *ds) /* Column related funcs */ +#if AXIS_TRANSITION static glong geometry_get_column_count (const GSheetColumn *geom) { @@ -799,88 +804,11 @@ geometry_set_width (GSheetColumn *geom, glong unit, gint width) var_set_display_width (v, width / ds->width_of_m ); } - - -static GtkJustification -geometry_get_justification (const GSheetColumn *geom, glong unit) -{ - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - const struct variable *pv ; - - - if ( unit >= psppire_dict_get_var_cnt (ds->dict) ) - return GTK_JUSTIFY_LEFT; - - pv = psppire_dict_get_variable (ds->dict, unit); - - return (var_get_alignment (pv) == ALIGN_LEFT ? GTK_JUSTIFY_LEFT - : var_get_alignment (pv) == ALIGN_RIGHT ? GTK_JUSTIFY_RIGHT - : GTK_JUSTIFY_CENTER); -} +#endif static const gchar null_var_name[]=N_("var"); -static gchar * -geometry_get_column_button_label (const GSheetColumn *geom, glong unit) -{ - gchar *text; - struct variable *pv ; - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - if ( unit >= psppire_dict_get_var_cnt (ds->dict) ) - return g_locale_to_utf8 (null_var_name, -1, 0, 0, 0); - - pv = psppire_dict_get_variable (ds->dict, unit); - - text = pspp_locale_to_utf8 (var_get_name (pv), -1, 0); - - return text; -} - - -static gchar * -geometry_get_column_subtitle (const GSheetColumn *geom, glong unit) -{ - gchar *text; - const struct variable *v ; - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - if ( unit >= psppire_dict_get_var_cnt (ds->dict) ) - return NULL; - - v = psppire_dict_get_variable (ds->dict, unit); - - if ( ! var_has_label (v)) - return NULL; - - text = pspp_locale_to_utf8 (var_get_label (v), -1, 0); - - return text; -} - - -static gboolean -geometry_get_sensitivity (const GSheetColumn *geom, glong unit) -{ - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - return (unit < psppire_dict_get_var_cnt (ds->dict)); -} - - -static void -psppire_data_store_sheet_column_init (GSheetColumnIface *iface) -{ - iface->get_column_count = geometry_get_column_count; - iface->get_width = geometry_get_width; - iface->set_width = geometry_set_width; - iface->get_sensitivity = geometry_get_sensitivity; - iface->get_justification = geometry_get_justification; - iface->get_button_label = geometry_get_column_button_label; - iface->get_subtitle = geometry_get_column_subtitle; -} - /* Row related funcs */ @@ -959,3 +887,73 @@ psppire_data_store_sheet_row_init (GSheetRowIface *iface) iface->pixel_to_row = geometry_pixel_to_row; iface->get_button_label = geometry_get_row_button_label; } + + + + +/* Column related stuff */ + +static gchar * +get_column_subtitle (const GSheetModel *model, gint col) +{ + gchar *text; + const struct variable *v ; + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); + + if ( col >= psppire_dict_get_var_cnt (ds->dict) ) + return NULL; + + v = psppire_dict_get_variable (ds->dict, col); + + if ( ! var_has_label (v)) + return NULL; + + text = pspp_locale_to_utf8 (var_get_label (v), -1, 0); + + return text; +} + +static gchar * +get_column_button_label (const GSheetModel *model, gint col) +{ + gchar *text; + struct variable *pv ; + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); + + if ( col >= psppire_dict_get_var_cnt (ds->dict) ) + return g_locale_to_utf8 (null_var_name, -1, 0, 0, 0); + + pv = psppire_dict_get_variable (ds->dict, col); + + text = pspp_locale_to_utf8 (var_get_name (pv), -1, 0); + + return text; +} + +static gboolean +get_column_sensitivity (const GSheetModel *model, gint col) +{ + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); + + return (col < psppire_dict_get_var_cnt (ds->dict)); +} + + + +static GtkJustification +get_column_justification (const GSheetModel *model, gint col) +{ + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); + const struct variable *pv ; + + if ( col >= psppire_dict_get_var_cnt (ds->dict) ) + return GTK_JUSTIFY_LEFT; + + pv = psppire_dict_get_variable (ds->dict, col); + + return (var_get_alignment (pv) == ALIGN_LEFT ? GTK_JUSTIFY_LEFT + : var_get_alignment (pv) == ALIGN_RIGHT ? GTK_JUSTIFY_RIGHT + : GTK_JUSTIFY_CENTER); +} + + diff --git a/src/ui/gui/psppire-data-store.h b/src/ui/gui/psppire-data-store.h index 06a5e403..8f30afa4 100644 --- a/src/ui/gui/psppire-data-store.h +++ b/src/ui/gui/psppire-data-store.h @@ -17,7 +17,6 @@ #ifndef __PSPPIRE_DATA_STORE_H__ #define __PSPPIRE_DATA_STORE_H__ -#include #include "psppire-dict.h" #include "psppire-case-file.h" diff --git a/src/ui/gui/psppire-var-sheet.c b/src/ui/gui/psppire-var-sheet.c index 0708bf3e..54069491 100644 --- a/src/ui/gui/psppire-var-sheet.c +++ b/src/ui/gui/psppire-var-sheet.c @@ -19,7 +19,7 @@ #include #include "helper.h" -#include + #include "customentry.h" #include #include "psppire-var-store.h" @@ -95,20 +95,6 @@ struct column_parameters gint width ; }; -static const struct column_parameters column_def[] = { - { N_("Name"), 80}, - { N_("Type"), 100}, - { N_("Width"), 57}, - { N_("Decimals"),91}, - { N_("Label"), 95}, - { N_("Values"), 103}, - { N_("Missing"), 95}, - { N_("Columns"), 80}, - { N_("Align"), 69}, - { N_("Measure"), 99}, -}; - - #define n_ALIGNMENTS 3 const gchar *const alignments[n_ALIGNMENTS + 1]={ @@ -502,8 +488,7 @@ var_sheet_change_active_cell (PsppireVarSheet *vs, static void psppire_var_sheet_init (PsppireVarSheet *vs) { - gint i; - GObject *geo = g_sheet_hetero_column_new (75, PSPPIRE_VAR_STORE_n_COLS); + // gint i; GladeXML *xml = XML_NEW ("data-editor.glade"); vs->val_labs_dialog = val_labs_dialog_create (xml); @@ -515,16 +500,13 @@ psppire_var_sheet_init (PsppireVarSheet *vs) vs->dispose_has_run = FALSE; vs->may_create_vars = TRUE; +#if 0 for (i = 0 ; i < PSPPIRE_VAR_STORE_n_COLS ; ++i ) { - g_sheet_hetero_column_set_button_label (G_SHEET_HETERO_COLUMN (geo), i, - gettext (column_def[i].label)); - g_sheet_hetero_column_set_width (G_SHEET_HETERO_COLUMN (geo), i, column_def[i].width); } - - g_object_set (vs, "column-geometry", geo, NULL); +#endif g_signal_connect (vs, "activate", G_CALLBACK (var_sheet_change_active_cell), @@ -535,8 +517,32 @@ psppire_var_sheet_init (PsppireVarSheet *vs) } +static const struct column_parameters column_def[] = { + { N_("Name"), 80}, + { N_("Type"), 100}, + { N_("Width"), 57}, + { N_("Decimals"),91}, + { N_("Label"), 95}, + { N_("Values"), 103}, + { N_("Missing"), 95}, + { N_("Columns"), 80}, + { N_("Align"), 69}, + { N_("Measure"), 99}, +}; + GtkWidget* psppire_var_sheet_new (void) { - return GTK_WIDGET (g_object_new (psppire_var_sheet_get_type (), NULL)); + gint i; + PsppireAxis *a = psppire_axis_new (-1); + GtkWidget *w = g_object_new (psppire_var_sheet_get_type (), NULL); + + for (i = 0 ; i < 10 ; ++i) + psppire_axis_append (a, column_def[i].width); + + g_object_set (w, + "horizontal-axis", a, + NULL); + + return w; } diff --git a/src/ui/gui/psppire-var-store.c b/src/ui/gui/psppire-var-store.c index efe1ae0d..4575bd3b 100644 --- a/src/ui/gui/psppire-var-store.c +++ b/src/ui/gui/psppire-var-store.c @@ -329,7 +329,7 @@ psppire_var_store_get_font_desc (const GSheetModel *model, } - +static gchar *get_column_title (const GSheetModel *model, gint col); static void psppire_var_store_sheet_model_init (GSheetModelIface *iface) @@ -347,9 +347,9 @@ psppire_var_store_sheet_model_init (GSheetModelIface *iface) iface->get_font_desc = psppire_var_store_get_font_desc; iface->get_cell_border = NULL; iface->get_justification = NULL; -} - + iface->get_column_title = get_column_title; +} /** * psppire_var_store_new: @@ -846,3 +846,27 @@ psppire_var_store_sheet_row_init (GSheetRowIface *iface) iface->get_button_label = geometry_get_button_label; } + + + +static const gchar *column_titles[] = { + N_("Name"), + N_("Type"), + N_("Width"), + N_("Decimals"), + N_("Label"), + N_("Values"), + N_("Missing"), + N_("Columns"), + N_("Align"), + N_("Measure"), +}; + + +static gchar * +get_column_title (const GSheetModel *model, gint col) +{ + if ( col >= 10) + return NULL; + return g_strdup (gettext (column_titles[col])); +} diff --git a/src/ui/gui/psppire-var-store.h b/src/ui/gui/psppire-var-store.h index a4782efc..72c9192c 100644 --- a/src/ui/gui/psppire-var-store.h +++ b/src/ui/gui/psppire-var-store.h @@ -17,7 +17,6 @@ #ifndef __PSPPIRE_VAR_STORE_H__ #define __PSPPIRE_VAR_STORE_H__ -#include #include "psppire-dict.h" #include -- 2.30.2