From: John Darrington Date: Wed, 26 Nov 2008 04:21:38 +0000 (+0900) Subject: Remove the gsheet-row-* modules and replaced with psppire-axis-* X-Git-Tag: v0.7.1~113 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f79c3114efb645934af16035e489fdedc4cab85e;p=pspp-builds.git Remove the gsheet-row-* modules and replaced with psppire-axis-* --- diff --git a/lib/gtksheet/automake.mk b/lib/gtksheet/automake.mk index c5999498..fc7708aa 100644 --- a/lib/gtksheet/automake.mk +++ b/lib/gtksheet/automake.mk @@ -8,11 +8,6 @@ lib_gtksheet_libgtksheet_a_CFLAGS = $(GTK_CFLAGS) -Wall -DGDK_MULTIHEAD_SAFE=1 lib_gtksheet_libgtksheet_a_SOURCES = \ lib/gtksheet/gsheetmodel.c \ lib/gtksheet/gsheetmodel.h \ - lib/gtksheet/gsheet-row-iface.c \ - lib/gtksheet/gsheet-row-iface.h \ - lib/gtksheet/gsheet-uniform-row.c \ - lib/gtksheet/gsheet-uniform-row.h \ - lib/gtksheet/gtkextrafeatures.h \ lib/gtksheet/gtkextra-marshal.c \ lib/gtksheet/gtkextra-marshal.h \ lib/gtksheet/gtkextra-sheet.h \ @@ -23,7 +18,12 @@ lib_gtksheet_libgtksheet_a_SOURCES = \ lib/gtksheet/gtkxpaned.c \ lib/gtksheet/gtkxpaned.h \ lib/gtksheet/psppire-axis.c \ - lib/gtksheet/psppire-axis.h + lib/gtksheet/psppire-axis.h \ + lib/gtksheet/psppire-axis-hetero.c \ + lib/gtksheet/psppire-axis-hetero.h \ + lib/gtksheet/psppire-axis-uniform.c \ + lib/gtksheet/psppire-axis-uniform.h + EXTRA_DIST += lib/gtksheet/OChangeLog \ diff --git a/lib/gtksheet/gsheet-row-iface.c b/lib/gtksheet/gsheet-row-iface.c deleted file mode 100644 index 4bbd2e1c..00000000 --- a/lib/gtksheet/gsheet-row-iface.c +++ /dev/null @@ -1,254 +0,0 @@ -/* GSheetRow --- an abstract model of the row 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-row-iface.h" -#include "gtkextra-marshal.h" - - -enum { - ROWS_CHANGED, - LAST_SIGNAL -}; - -static guint sheet_row_signals[LAST_SIGNAL]; - - - -static void g_sheet_row_base_init (gpointer g_class); - - -GType -g_sheet_row_get_type (void) -{ - static GType sheet_row_type = 0; - - if (! sheet_row_type) - { - static const GTypeInfo sheet_row_info = - - { - sizeof (GSheetRowIface), /* class_size */ - g_sheet_row_base_init, /* base_init */ - NULL, /* base_finalize */ - NULL, - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, - 0, /* n_preallocs */ - NULL - }; - - sheet_row_type = - g_type_register_static (G_TYPE_INTERFACE, "GSheetRow", - &sheet_row_info, 0); - - g_type_interface_add_prerequisite (sheet_row_type, G_TYPE_OBJECT); - } - - return sheet_row_type; -} - - -static GtkSheetButton default_button; - -static void -g_sheet_row_base_init (gpointer g_class) -{ - static gboolean initialized = FALSE; - - if (! initialized) - { - - sheet_row_signals[ROWS_CHANGED] = - g_signal_new ("rows_changed", - G_TYPE_SHEET_ROW, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GSheetRowIface, rows_changed), - NULL, NULL, - gtkextra_VOID__INT_INT, - G_TYPE_NONE, 2, - G_TYPE_INT, - G_TYPE_INT); - - - default_button.state = GTK_STATE_NORMAL; - default_button.label = NULL; - default_button.label_visible = TRUE; - default_button.justification = GTK_JUSTIFY_FILL; - - initialized = TRUE; - } -} - -void -g_sheet_row_set_height (GSheetRow *row_geo, - glong row, gint size) -{ - g_return_if_fail (G_IS_SHEET_ROW (row_geo)); - - if ((G_SHEET_ROW_GET_IFACE (row_geo)->set_height) ) - (G_SHEET_ROW_GET_IFACE (row_geo)->set_height) (row_geo, row, - size); -} - - -gint -g_sheet_row_get_height (const GSheetRow *row_geo, - glong row) -{ - g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), -1); - - g_assert (G_SHEET_ROW_GET_IFACE (row_geo)->get_height); - - return (G_SHEET_ROW_GET_IFACE (row_geo)->get_height) (row_geo, row); -} - - - -gboolean -g_sheet_row_get_sensitivity (const GSheetRow *row_geo, - glong row) -{ - g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), FALSE); - - g_assert (G_SHEET_ROW_GET_IFACE (row_geo)->get_sensitivity); - - return (G_SHEET_ROW_GET_IFACE (row_geo)->get_sensitivity) (row_geo, - row); -} - - -GtkSheetButton * -g_sheet_row_get_button (const GSheetRow *row_geo, - glong row) -{ - GtkSheetButton *button = gtk_sheet_button_new (); - - GSheetRowIface *iface = G_SHEET_ROW_GET_IFACE (row_geo); - - g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), FALSE); - - if ( iface->get_button_label) - button->label = iface->get_button_label (row_geo, row); - - return button; -} - -gchar * -g_sheet_row_get_subtitle (const GSheetRow *row_geo, glong row) -{ - g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), NULL); - - if ( ! G_SHEET_ROW_GET_IFACE (row_geo)->get_subtitle ) - return NULL; - - return (G_SHEET_ROW_GET_IFACE (row_geo)->get_subtitle) (row_geo, row); -} - - - - -glong -g_sheet_row_get_row_count (const GSheetRow *geo) -{ - g_return_val_if_fail (G_IS_SHEET_ROW (geo), -1); - - g_assert ( G_SHEET_ROW_GET_IFACE (geo)->get_row_count); - - return (G_SHEET_ROW_GET_IFACE (geo)->get_row_count) (geo); -} - -/** - * g_sheet_row_start_pixel: - * @geo: the row model - * @row: the row number - * @sheet: pointer to the sheet - * - * Returns the top y pixel for ROW. - * ROW may point to the row BELOW the last row, in which case it should - * return the position where it would start if it existed. - * Instances may override this method in order to achieve time and/or memory - * optmisation. - * - * Returns: the y coordinate of the top of the row. - */ - -gint -g_sheet_row_start_pixel (const GSheetRow *geo, glong row) -{ - gint i; - gint start_pixel = 0; - - g_return_val_if_fail (G_IS_SHEET_ROW (geo), -1); - g_return_val_if_fail (row >= 0, -1); - g_return_val_if_fail (row <= g_sheet_row_get_row_count (geo), -1); - - if ( G_SHEET_ROW_GET_IFACE (geo)->top_ypixel) - return (G_SHEET_ROW_GET_IFACE (geo)->top_ypixel)(geo, row); - - for (i = 0; i < row; ++i) - { - start_pixel += g_sheet_row_get_height (geo, i); - } - - return start_pixel; -} - - -glong -g_sheet_row_pixel_to_row (const GSheetRow *geo, gint pixel) -{ - gint i, cy; - g_return_val_if_fail (G_IS_SHEET_ROW (geo), -1); - g_return_val_if_fail (pixel >= 0, -1) ; - - if ( G_SHEET_ROW_GET_IFACE (geo)->pixel_to_row) - return (G_SHEET_ROW_GET_IFACE (geo)->pixel_to_row)(geo, pixel); - - cy = 0; - for (i = 0; i < g_sheet_row_get_row_count (geo); ++i ) - { - if (pixel >= cy && - pixel <= (cy + g_sheet_row_get_height (geo, i))) - return i; - - cy += g_sheet_row_get_height (geo, i); - } - - /* no match */ - return g_sheet_row_get_row_count (geo) - 1; -} - - - -void -g_sheet_row_rows_deleted (GSheetRow *geo, - glong first, glong n_rows) -{ - g_return_if_fail (G_IS_SHEET_ROW (geo)); - - g_signal_emit (geo, sheet_row_signals[ROWS_CHANGED], 0, - first, n_rows); -} diff --git a/lib/gtksheet/gsheet-row-iface.h b/lib/gtksheet/gsheet-row-iface.h deleted file mode 100644 index ce67b326..00000000 --- a/lib/gtksheet/gsheet-row-iface.h +++ /dev/null @@ -1,117 +0,0 @@ -/* GSheetRow --- an abstract model of the row 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 __G_SHEET_ROW_IFACE_H__ -#define __G_SHEET_ROW_IFACE_H__ - -#include -#include -#include - -#include "gtkextra-sheet.h" - - -G_BEGIN_DECLS - -#define G_TYPE_SHEET_ROW (g_sheet_row_get_type ()) -#define G_SHEET_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_SHEET_ROW, GSheetRow)) -#define G_IS_SHEET_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_SHEET_ROW)) -#define G_SHEET_ROW_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), G_TYPE_SHEET_ROW, GSheetRowIface)) - - - - -typedef struct _GSheetRow GSheetRow; -typedef struct _GSheetRowIface GSheetRowIface; - -struct _GSheetRowIface -{ - GTypeInterface g_iface; - - - /* Signals */ - void (* rows_changed) (GSheetRow *geo, - glong row, glong n_rows); - - /* Virtual Table */ - gint (* get_height) (const GSheetRow *grow, glong row); - void (* set_height) (GSheetRow *grow, glong row, gint height); - - gboolean (* get_sensitivity) (const GSheetRow *grow, glong row); - - const GtkSheetButton * (* get_button) (const GSheetRow *grow, glong row); - - glong (* get_row_count) (const GSheetRow *geo); - - GtkStateType (*get_button_state) (const GSheetRow *geo, glong row); - - gchar * (*get_button_label) (const GSheetRow *geo, glong row); - - gchar * (*get_subtitle) (const GSheetRow *geo, glong row); - - gboolean (*get_button_visibility) (const GSheetRow *geo, - glong row); - - guint (*top_ypixel) (const GSheetRow *geo, glong row); - glong (*pixel_to_row) (const GSheetRow *geo, guint pixel); -}; - - -GType g_sheet_row_get_type (void) G_GNUC_CONST; - - -gint g_sheet_row_get_height (const GSheetRow *grow, - glong row); - - -void g_sheet_row_set_height (GSheetRow *grow, - glong row, gint size); - - -gboolean g_sheet_row_get_visibility (const GSheetRow *grow, - glong row); - -gboolean g_sheet_row_get_sensitivity (const GSheetRow *grow, - glong row); - - -GtkSheetButton *g_sheet_row_get_button (const GSheetRow *grow, - glong row); - - -glong g_sheet_row_get_row_count (const GSheetRow *geo); - -/* Return the top pixel of row ROW */ -gint g_sheet_row_start_pixel (const GSheetRow *geo, glong row); - - -/* Return the row contained by pixel PIXEL */ -glong g_sheet_row_pixel_to_row (const GSheetRow *geo, gint pixel); - - -void g_sheet_row_rows_deleted (GSheetRow *geo, - glong first, glong n_rows); - - -gchar *g_sheet_row_get_subtitle (const GSheetRow *row_geo, glong row); - - -G_END_DECLS - -#endif /* __G_SHEET_ROW_IFACE_H__ */ diff --git a/lib/gtksheet/gsheet-uniform-row.c b/lib/gtksheet/gsheet-uniform-row.c deleted file mode 100644 index 847916c5..00000000 --- a/lib/gtksheet/gsheet-uniform-row.c +++ /dev/null @@ -1,190 +0,0 @@ -/* gsheet-uniform-row.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-row-iface.h" -#include "gsheet-uniform-row.h" - - -static void g_sheet_uniform_row_init (GSheetUniformRow *ug); -static void g_sheet_uniform_row_class_init (GSheetUniformRowClass *class); -static void g_sheet_uniform_row_finalize (GObject *object); - -static void g_sheet_row_init (GSheetRowIface *iface); - - -static GObjectClass *parent_class = NULL; - -GType -g_sheet_uniform_row_get_type (void) -{ - static GType uniform_row_type = 0; - - if (!uniform_row_type) - { - static const GTypeInfo uniform_row_info = - { - sizeof (GSheetUniformRowClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) g_sheet_uniform_row_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GSheetUniformRow), - 0, - (GInstanceInitFunc) g_sheet_uniform_row_init, - }; - - static const GInterfaceInfo row_info = - { - (GInterfaceInitFunc) g_sheet_row_init, - NULL, - NULL - }; - - uniform_row_type = - g_type_register_static (G_TYPE_OBJECT, "g_sheet_uniform_row", - &uniform_row_info, 0); - - g_type_add_interface_static (uniform_row_type, - G_TYPE_SHEET_ROW, - &row_info); - } - - return uniform_row_type; -} - - -/** - * g_sheet_uniform_row_new: - * @height: The size of rows in this uniform row - * - * Return value: a new #g_sheet_uniform_row - **/ -GObject * -g_sheet_uniform_row_new (gint height, gint n_rows) -{ - GSheetUniformRow *ug; - GObject *retval; - - retval = g_object_new (G_TYPE_SHEET_UNIFORM_ROW, NULL); - - ug = G_SHEET_UNIFORM_ROW(retval); - ug->n_rows = n_rows; - ug->height = height; - - return retval; -} - -static gint -g_sheet_uniform_row_get_height (const GSheetRow *geom, glong u) -{ - GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom); - - return ug->height; -} - -static gboolean -g_sheet_uniform_row_get_sensitivity (const GSheetRow *geom, glong u) -{ - GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom); - - return (u < ug->n_rows); -} - - -static gchar * -g_sheet_uniform_row_get_button_label (const GSheetRow *geom, glong u) -{ - gchar *label = g_strdup_printf("%ld", u); - - return label; -} - - - -static glong -g_sheet_uniform_row_get_row_count (const GSheetRow *geom) -{ - GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom); - - return ug->n_rows; -} - - -static void -g_sheet_uniform_row_class_init (GSheetUniformRowClass *class) -{ - GObjectClass *object_class; - - parent_class = g_type_class_peek_parent (class); - object_class = (GObjectClass*) class; - - object_class->finalize = g_sheet_uniform_row_finalize; - -} - - -static void -g_sheet_uniform_row_init (GSheetUniformRow *o) -{ -} - -static void -g_sheet_uniform_row_finalize (GObject *object) -{ -} - - -static guint -g_sheet_uniform_row_top_ypixel (const GSheetRow *geo, glong row) -{ - GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geo); - - return row * ug->height; -} - -static glong -g_sheet_uniform_row_pixel_to_row (const GSheetRow *geo, guint pixel) -{ - GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geo); - - gint row = pixel / ug->height; - - if (row >= g_sheet_uniform_row_get_row_count(geo)) - row = g_sheet_uniform_row_get_row_count(geo) - 1; - - return row; -} - - - -static void -g_sheet_row_init (GSheetRowIface *iface) -{ - iface->get_height = g_sheet_uniform_row_get_height; - iface->get_sensitivity = g_sheet_uniform_row_get_sensitivity ; - iface->get_row_count = g_sheet_uniform_row_get_row_count; - iface->get_button_label = g_sheet_uniform_row_get_button_label; - iface->top_ypixel = g_sheet_uniform_row_top_ypixel; - iface->pixel_to_row = g_sheet_uniform_row_pixel_to_row; -} - diff --git a/lib/gtksheet/gsheet-uniform-row.h b/lib/gtksheet/gsheet-uniform-row.h deleted file mode 100644 index 96551f3f..00000000 --- a/lib/gtksheet/gsheet-uniform-row.h +++ /dev/null @@ -1,65 +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_ROW_H__ -#define __G_SHEET_UNIFORM_ROW_H__ - -#include -#include - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define G_TYPE_SHEET_UNIFORM_ROW (g_sheet_uniform_row_get_type ()) - -#define G_SHEET_UNIFORM_ROW(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, G_TYPE_SHEET_UNIFORM_ROW, GSheetUniformRow ) -#define G_SHEET_UNIFORM_ROW_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, g_sheet_uniform_row_get_type (), GSheetUniformRowClass) -#define G_IS_SHEET_UNIFORM_ROW(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, G_TYPE_SHEET_UNIFORM_ROW) - - - struct _GSheetUniformRow{ - GObject parent; - - gint n_rows; - gint height; - }; - - struct _GSheetUniformRowClass - { - GObjectClass parent_class; - }; - - /* create a new row */ - GObject * g_sheet_uniform_row_new (gint height, gint n_rows); - - GType g_sheet_uniform_row_get_type (void); - - - typedef struct _GSheetUniformRow GSheetUniformRow; - typedef struct _GSheetUniformRowClass GSheetUniformRowClass; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __G_SHEET_UNIFORM_ROW_H__ */ - - diff --git a/lib/gtksheet/gsheetmodel.c b/lib/gtksheet/gsheetmodel.c index 7e975237..0839f221 100644 --- a/lib/gtksheet/gsheetmodel.c +++ b/lib/gtksheet/gsheetmodel.c @@ -511,7 +511,7 @@ g_sheet_model_get_row_count(const GSheetModel *model) -/* New functions since AXIS_TRANSITION */ +/* Column related functions */ gboolean g_sheet_model_get_column_sensitivity (const GSheetModel *model, gint col) { @@ -559,3 +559,43 @@ g_sheet_model_get_column_justification (const GSheetModel *model, return GTK_JUSTIFY_LEFT; } + + +gboolean +g_sheet_model_get_row_sensitivity (const GSheetModel *model, gint row) +{ + if ( NULL == G_SHEET_MODEL_GET_IFACE (model)->get_row_sensitivity) + return TRUE; + + return G_SHEET_MODEL_GET_IFACE (model)->get_row_sensitivity (model, row); +} + + + +gchar * +g_sheet_model_get_row_subtitle (const GSheetModel *model, + gint row) +{ + g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL); + + if ( NULL == G_SHEET_MODEL_GET_IFACE (model)->get_row_subtitle) + return NULL; + + return G_SHEET_MODEL_GET_IFACE (model)->get_row_subtitle (model, row); +} + + +GtkSheetButton * +g_sheet_model_get_row_button (const GSheetModel *model, + gint row) +{ + 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_row_title) + button->label = G_SHEET_MODEL_GET_IFACE (model)->get_row_title (model, row); + + return button; +} + diff --git a/lib/gtksheet/gsheetmodel.h b/lib/gtksheet/gsheetmodel.h index eb661c99..792e6921 100644 --- a/lib/gtksheet/gsheetmodel.h +++ b/lib/gtksheet/gsheetmodel.h @@ -128,9 +128,9 @@ struct _GSheetModelIface /* 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); + gchar * (*get_column_title) (const GSheetModel *, gint col); + gchar * (*get_column_subtitle) (const GSheetModel *, gint col); + gboolean (*get_column_sensitivity) (const GSheetModel *, gint col); GtkJustification (*get_column_justification) (const GSheetModel *mode, gint col); const GtkSheetButton * (* get_button) (const GSheetModel *model, gint col); @@ -138,7 +138,10 @@ struct _GSheetModelIface /* row related metadata */ + gchar * (*get_row_title) (const GSheetModel *, gint row); + gchar * (*get_row_subtitle) (const GSheetModel *, gint row); glong (*get_row_count) (const GSheetModel *model); + gboolean (*get_row_sensitivity) (const GSheetModel *, gint row); }; @@ -217,6 +220,20 @@ GtkSheetButton * g_sheet_model_get_column_button (const GSheetModel *, gint); GtkJustification g_sheet_model_get_column_justification (const GSheetModel *, gint); + + +gboolean g_sheet_model_get_row_sensitivity (const GSheetModel *model, + gint row); + + +gchar * g_sheet_model_get_row_subtitle (const GSheetModel *model, + gint row); + + +GtkSheetButton * g_sheet_model_get_row_button (const GSheetModel *, gint); + + + G_END_DECLS diff --git a/lib/gtksheet/gtksheet.c b/lib/gtksheet/gtksheet.c index d8517ae3..45ee30d7 100644 --- a/lib/gtksheet/gtksheet.c +++ b/lib/gtksheet/gtksheet.c @@ -113,44 +113,48 @@ dispose_string (const GtkSheet *sheet, gchar *text) g_free (text); } -/* Return the row containing pixel Y */ -static gint -yyy_row_ypixel_to_row (const GtkSheet *sheet, gint y) -{ - GSheetRow *geo = sheet->row_geometry; - g_return_val_if_fail (y >= 0, -1); +/* FIXME: Why bother with these two ? */ - return g_sheet_row_pixel_to_row (geo, y); +/* returns the column index from a pixel location */ +static inline gint +column_from_xpixel (const GtkSheet *sheet, gint pixel) +{ + return psppire_axis_get_unit_at_pixel (sheet->haxis, pixel); +} + +static inline gint +row_from_ypixel (const GtkSheet *sheet, gint pixel) +{ + return psppire_axis_get_unit_at_pixel (sheet->vaxis, pixel); } + /* Return the lowest row number which is wholly or partially on the visible range of the sheet */ static inline glong min_visible_row (const GtkSheet *sheet) { - return yyy_row_ypixel_to_row (sheet, sheet->vadjustment->value); + return row_from_ypixel (sheet, sheet->vadjustment->value); } static inline glong min_fully_visible_row (const GtkSheet *sheet) { - glong row = yyy_row_ypixel_to_row (sheet, sheet->vadjustment->value); + glong row = min_visible_row (sheet); - if ( g_sheet_row_start_pixel (sheet->row_geometry, row) < sheet->vadjustment->value) + if ( psppire_axis_pixel_start (sheet->vaxis, row) < sheet->vadjustment->value) row++; - return row; + return row; } - - static inline glong max_visible_row (const GtkSheet *sheet) { - return yyy_row_ypixel_to_row (sheet, - sheet->vadjustment->value + - sheet->vadjustment->page_size); + return row_from_ypixel (sheet, + sheet->vadjustment->value + + sheet->vadjustment->page_size); } @@ -159,9 +163,9 @@ max_fully_visible_row (const GtkSheet *sheet) { glong row = max_visible_row (sheet); - if ( g_sheet_row_start_pixel (sheet->row_geometry, row) + if ( psppire_axis_pixel_start (sheet->vaxis, row) + - g_sheet_row_get_height (sheet->row_geometry, row) + psppire_axis_unit_size (sheet->vaxis, row) > sheet->vadjustment->value) row--; @@ -169,14 +173,6 @@ max_fully_visible_row (const GtkSheet *sheet) } -/* returns the column index from a pixel location */ -static inline gint -column_from_xpixel (const GtkSheet *sheet, gint pixel) -{ - return psppire_axis_get_unit_at_pixel (sheet->haxis, pixel); -} - - /* Returns the lowest column number which is wholly or partially on the sheet */ static inline glong @@ -251,30 +247,6 @@ on_column_boundary (const GtkSheet *sheet, gint x, gint *column) return FALSE; } -static inline gboolean -POSSIBLE_YDRAG (const GtkSheet *sheet, gint y, gint *drag_row) -{ - gint row, ydrag; - - y += sheet->vadjustment->value; - row = yyy_row_ypixel_to_row (sheet, y); - *drag_row = row; - - ydrag = g_sheet_row_start_pixel (sheet->row_geometry, row) + CELL_SPACING; - if (y <= ydrag + DRAG_WIDTH / 2 && row != 0) - { - *drag_row = row - 1; - return g_sheet_row_get_sensitivity (sheet->row_geometry, row - 1); - } - - ydrag += g_sheet_row_get_height (sheet->row_geometry, row); - - if (y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2) - return g_sheet_row_get_sensitivity (sheet->row_geometry, row); - - return FALSE; -} - static inline gboolean POSSIBLE_DRAG (const GtkSheet *sheet, gint x, gint y, gint *drag_row, gint *drag_column) @@ -287,20 +259,20 @@ POSSIBLE_DRAG (const GtkSheet *sheet, gint x, gint y, return FALSE; *drag_column = column_from_xpixel (sheet, x); - *drag_row = yyy_row_ypixel_to_row (sheet, y); + *drag_row = row_from_ypixel (sheet, y); 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); + ydrag = psppire_axis_pixel_start (sheet->vaxis, sheet->range.row0); if (y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2) { *drag_row = sheet->range.row0; return TRUE; } - ydrag = g_sheet_row_start_pixel (sheet->row_geometry, sheet->range.rowi) + - g_sheet_row_get_height (sheet->row_geometry, sheet->range.rowi); + ydrag = psppire_axis_pixel_start (sheet->vaxis, sheet->range.rowi) + + psppire_axis_unit_size (sheet->vaxis, sheet->range.rowi); if (y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2) { *drag_row = sheet->range.rowi; @@ -308,9 +280,9 @@ POSSIBLE_DRAG (const GtkSheet *sheet, gint x, gint y, } } - if (y >= g_sheet_row_start_pixel (sheet->row_geometry, sheet->range.row0) - DRAG_WIDTH / 2 && - 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) + if (y >= psppire_axis_pixel_start (sheet->vaxis, sheet->range.row0) - DRAG_WIDTH / 2 && + y <= psppire_axis_pixel_start (sheet->vaxis, sheet->range.rowi) + + psppire_axis_unit_size (sheet->vaxis, sheet->range.rowi) + DRAG_WIDTH / 2) { xdrag = psppire_axis_pixel_start (sheet->haxis, sheet->range.col0); if (x >= xdrag - DRAG_WIDTH / 2 && x <= xdrag + DRAG_WIDTH / 2) @@ -344,17 +316,17 @@ POSSIBLE_RESIZE (const GtkSheet *sheet, gint x, gint y, 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); + ydrag = psppire_axis_pixel_start (sheet->vaxis, sheet->range.rowi) + + psppire_axis_unit_size (sheet->vaxis, sheet->range.rowi); if (sheet->state == GTK_SHEET_COLUMN_SELECTED) - ydrag = g_sheet_row_start_pixel (sheet->row_geometry, min_visible_row (sheet)); + ydrag = psppire_axis_pixel_start (sheet->vaxis, min_visible_row (sheet)); if (sheet->state == GTK_SHEET_ROW_SELECTED) 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); + *drag_row = row_from_ypixel (sheet, y); if (x >= xdrag - DRAG_WIDTH / 2 && x <= xdrag + DRAG_WIDTH / 2 && y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2) return TRUE; @@ -376,7 +348,7 @@ rectangle_from_range (GtkSheet *sheet, const GtkSheetRange *range, r->x += sheet->row_title_area.width; - r->y = g_sheet_row_start_pixel (sheet->row_geometry, range->row0); + r->y = psppire_axis_pixel_start (sheet->vaxis, range->row0); r->y -= round (sheet->vadjustment->value); if ( sheet->column_titles_visible) @@ -386,9 +358,9 @@ rectangle_from_range (GtkSheet *sheet, const GtkSheetRange *range, 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) + - g_sheet_row_get_height (sheet->row_geometry, range->rowi); + r->height = psppire_axis_pixel_start (sheet->vaxis, range->rowi) - + psppire_axis_pixel_start (sheet->vaxis, range->row0) + + psppire_axis_unit_size (sheet->vaxis, range->rowi); return TRUE; } @@ -679,21 +651,11 @@ gtk_sheet_cell_get_type (void) enum { PROP_0, - PROP_ROW_GEO, + PROP_VAXIS, PROP_HAXIS, PROP_MODEL }; -static void -gtk_sheet_set_row_geometry (GtkSheet *sheet, GSheetRow *geo) -{ - if ( sheet->row_geometry ) g_object_unref (sheet->row_geometry); - - sheet->row_geometry = geo; - - if ( sheet->row_geometry ) g_object_ref (sheet->row_geometry); -} - static void gtk_sheet_set_horizontal_axis (GtkSheet *sheet, PsppireAxis *a) { @@ -706,6 +668,18 @@ gtk_sheet_set_horizontal_axis (GtkSheet *sheet, PsppireAxis *a) g_object_ref (sheet->haxis); } +static void +gtk_sheet_set_vertical_axis (GtkSheet *sheet, PsppireAxis *a) +{ + if ( sheet->vaxis ) + g_object_unref (sheet->vaxis); + + sheet->vaxis = a; + + if ( sheet->vaxis ) + g_object_ref (sheet->vaxis); +} + static void gtk_sheet_set_property (GObject *object, @@ -718,8 +692,8 @@ gtk_sheet_set_property (GObject *object, switch (prop_id) { - case PROP_ROW_GEO: - gtk_sheet_set_row_geometry (sheet, g_value_get_pointer (value)); + case PROP_VAXIS: + gtk_sheet_set_vertical_axis (sheet, g_value_get_pointer (value)); break; case PROP_HAXIS: gtk_sheet_set_horizontal_axis (sheet, g_value_get_pointer (value)); @@ -743,8 +717,8 @@ gtk_sheet_get_property (GObject *object, switch (prop_id) { - case PROP_ROW_GEO: - g_value_set_pointer (value, sheet->row_geometry); + case PROP_VAXIS: + g_value_set_pointer (value, sheet->vaxis); break; case PROP_HAXIS: g_value_set_pointer (value, sheet->haxis); @@ -764,8 +738,8 @@ gtk_sheet_class_init (GtkSheetClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - GParamSpec *row_geo_spec ; GParamSpec *haxis_spec ; + GParamSpec *vaxis_spec ; GParamSpec *model_spec ; GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); @@ -968,10 +942,10 @@ gtk_sheet_class_init (GtkSheetClass *klass) object_class->finalize = gtk_sheet_finalize; - row_geo_spec = - g_param_spec_pointer ("row-geometry", - "Row Geometry", - "A pointer to the model of the row geometry", + vaxis_spec = + g_param_spec_pointer ("vertical-axis", + "Vertical Axis", + "A pointer to the PsppireAxis object for the rows", G_PARAM_READABLE | G_PARAM_WRITABLE ); haxis_spec = @@ -991,8 +965,8 @@ gtk_sheet_class_init (GtkSheetClass *klass) object_class->get_property = gtk_sheet_get_property; g_object_class_install_property (object_class, - PROP_ROW_GEO, - row_geo_spec); + PROP_VAXIS, + vaxis_spec); g_object_class_install_property (object_class, PROP_HAXIS, @@ -1036,7 +1010,7 @@ gtk_sheet_init (GtkSheet *sheet) { sheet->model = NULL; sheet->haxis = NULL; - sheet->row_geometry = NULL; + sheet->vaxis = NULL; sheet->flags = 0; sheet->selection_mode = GTK_SELECTION_NONE; @@ -1126,7 +1100,7 @@ columns_inserted_deleted_callback (GSheetModel *model, gint first_column, range.col0 = first_column; range.row0 = 0; range.coli = psppire_axis_unit_count (sheet->haxis) - 1; - range.rowi = g_sheet_row_get_row_count (sheet->row_geometry) - 1; + range.rowi = psppire_axis_unit_count (sheet->vaxis) - 1; adjust_scrollbars (sheet); @@ -1156,7 +1130,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.rowi = psppire_axis_unit_count (sheet->vaxis) - 1; range.coli = psppire_axis_unit_count (sheet->haxis) - 1; adjust_scrollbars (sheet); @@ -1236,10 +1210,9 @@ range_update_callback (GSheetModel *m, gint row0, gint col0, * Returns: the new sheet widget */ GtkWidget * -gtk_sheet_new (GSheetRow *vgeo, void *hgeo, GSheetModel *model) +gtk_sheet_new (void *vgeo, void *hgeo, GSheetModel *model) { GtkWidget *widget = g_object_new (GTK_TYPE_SHEET, - "row-geometry", vgeo, "model", model, NULL); return widget; @@ -1469,14 +1442,14 @@ gtk_sheet_moveto (GtkSheet *sheet, g_return_if_fail (col < psppire_axis_unit_count (sheet->haxis)); g_return_if_fail (row < - g_sheet_row_get_row_count (sheet->row_geometry)); + psppire_axis_unit_count (sheet->vaxis)); gdk_drawable_get_size (sheet->sheet_window, &width, &height); if (row >= 0) { - gint y = g_sheet_row_start_pixel (sheet->row_geometry, row); + gint y = psppire_axis_pixel_start (sheet->vaxis, row); gtk_adjustment_set_value (sheet->vadjustment, y - height * row_align); } @@ -1517,7 +1490,7 @@ gtk_sheet_select_row (GtkSheet *sheet, gint row) g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (row < 0 || row >= g_sheet_row_get_row_count (sheet->row_geometry)) + if (row < 0 || row >= psppire_axis_unit_count (sheet->vaxis)) return; if (sheet->state != GTK_SHEET_NORMAL) @@ -1551,7 +1524,7 @@ gtk_sheet_select_column (GtkSheet *sheet, gint column) sheet->state = GTK_SHEET_COLUMN_SELECTED; sheet->range.row0 = 0; sheet->range.col0 = column; - sheet->range.rowi = g_sheet_row_get_row_count (sheet->row_geometry) - 1; + sheet->range.rowi = psppire_axis_unit_count (sheet->vaxis) - 1; sheet->range.coli = column; sheet->active_cell.row = 0; sheet->active_cell.col = column; @@ -1569,10 +1542,10 @@ gtk_sheet_range_isvisible (const GtkSheet *sheet, { g_return_val_if_fail (sheet != NULL, FALSE); - if (range.row0 < 0 || range.row0 >= g_sheet_row_get_row_count (sheet->row_geometry)) + if (range.row0 < 0 || range.row0 >= psppire_axis_unit_count (sheet->vaxis)) return FALSE; - if (range.rowi < 0 || range.rowi >= g_sheet_row_get_row_count (sheet->row_geometry)) + if (range.rowi < 0 || range.rowi >= psppire_axis_unit_count (sheet->vaxis)) return FALSE; if (range.col0 < 0 || range.col0 >= psppire_axis_unit_count (sheet->haxis)) @@ -1682,7 +1655,7 @@ gtk_sheet_dispose (GObject *object) sheet->dispose_has_run = TRUE; if (sheet->model) g_object_unref (sheet->model); - if (sheet->row_geometry) g_object_unref (sheet->row_geometry); + if (sheet->vaxis) g_object_unref (sheet->vaxis); if (sheet->haxis) g_object_unref (sheet->haxis); g_object_unref (sheet->entry_container); @@ -2053,7 +2026,7 @@ gtk_sheet_cell_draw (GtkSheet *sheet, gint row, gint col) if (!GTK_WIDGET_DRAWABLE (sheet)) return; if (row < 0 || - row >= g_sheet_row_get_row_count (sheet->row_geometry)) + row >= psppire_axis_unit_count (sheet->vaxis)) return; if (col < 0 || @@ -2153,7 +2126,7 @@ gtk_sheet_range_draw (GtkSheet *sheet, const GtkSheetRange *range) drawing_range.row0 = min_visible_row (sheet); drawing_range.col0 = min_visible_column (sheet); drawing_range.rowi = MIN (max_visible_row (sheet), - g_sheet_row_get_row_count (sheet->row_geometry) - 1); + psppire_axis_unit_count (sheet->vaxis) - 1); drawing_range.coli = max_visible_column (sheet); gdk_drawable_get_size (sheet->sheet_window, &area.width, &area.height); area.x = area.y = 0; @@ -2278,7 +2251,7 @@ gtk_sheet_set_cell (GtkSheet *sheet, gint row, gint col, g_return_if_fail (GTK_IS_SHEET (sheet)); if (col >= psppire_axis_unit_count (sheet->haxis) - || row >= g_sheet_row_get_row_count (sheet->row_geometry)) + || row >= psppire_axis_unit_count (sheet->vaxis)) return; if (col < 0 || row < 0) return; @@ -2303,7 +2276,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 >= psppire_axis_unit_count (sheet->haxis) || - row >= g_sheet_row_get_row_count (sheet->row_geometry)) return; + row >= psppire_axis_unit_count (sheet->vaxis)) return; if (column < 0 || row < 0) return; @@ -2339,7 +2312,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 >= psppire_axis_unit_count (sheet->haxis) || row >= g_sheet_row_get_row_count (sheet->row_geometry)) + if (col >= psppire_axis_unit_count (sheet->haxis) || row >= psppire_axis_unit_count (sheet->vaxis)) return NULL; if (col < 0 || row < 0) return NULL; @@ -2360,7 +2333,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 >= psppire_axis_unit_count (sheet->haxis) || row >= g_sheet_row_get_row_count (sheet->row_geometry)) return 0; + if (col >= psppire_axis_unit_count (sheet->haxis) || row >= psppire_axis_unit_count (sheet->vaxis)) return 0; if (col < 0 || row < 0) return 0; state = sheet->state; @@ -2424,8 +2397,8 @@ gtk_sheet_get_pixel_info (GtkSheet *sheet, } else { - trow = yyy_row_ypixel_to_row (sheet, y); - if (trow > g_sheet_row_get_row_count (sheet->row_geometry)) + trow = row_from_ypixel (sheet, y); + if (trow > psppire_axis_unit_count (sheet->vaxis)) return FALSE; } @@ -2461,17 +2434,17 @@ 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 >= psppire_axis_unit_count (sheet->haxis)) + if (row >= psppire_axis_unit_count (sheet->vaxis) || column >= psppire_axis_unit_count (sheet->haxis)) return FALSE; 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->y = (row == -1) ? 0 : psppire_axis_pixel_start (sheet->vaxis, row); area->width= (column == -1) ? sheet->row_title_area.width : 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); + : psppire_axis_unit_size (sheet->vaxis, row); return TRUE; } @@ -2485,7 +2458,7 @@ gtk_sheet_set_active_cell (GtkSheet *sheet, gint row, gint col) if (row < -1 || col < -1) return; - if (row >= g_sheet_row_get_row_count (sheet->row_geometry) + if (row >= psppire_axis_unit_count (sheet->vaxis) || col >= psppire_axis_unit_count (sheet->haxis)) return; @@ -2597,7 +2570,7 @@ change_active_cell (GtkSheet *sheet, gint row, gint col) if (row < 0 || col < 0) return; - if ( row > g_sheet_row_get_row_count (sheet->row_geometry) + if ( row > psppire_axis_unit_count (sheet->vaxis) || col > psppire_axis_unit_count (sheet->haxis)) return; @@ -2782,10 +2755,10 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) if (mask1 != mask2) { x = psppire_axis_pixel_start (sheet->haxis, j); - y = g_sheet_row_start_pixel (sheet->row_geometry, i); + y = psppire_axis_pixel_start (sheet->vaxis, i); 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); + height = psppire_axis_pixel_start (sheet->vaxis, i) - y + psppire_axis_unit_size (sheet->vaxis, i); if (i == sheet->range.row0) { @@ -2803,11 +2776,11 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) if (i != sheet->active_cell.row || j != sheet->active_cell.col) { x = psppire_axis_pixel_start (sheet->haxis, j); - y = g_sheet_row_start_pixel (sheet->row_geometry, i); + y = psppire_axis_pixel_start (sheet->vaxis, i); 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); + height = psppire_axis_pixel_start (sheet->vaxis, i) - y + psppire_axis_unit_size (sheet->vaxis, i); if (i == new_range.row0) { @@ -2846,9 +2819,9 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) { x = psppire_axis_pixel_start (sheet->haxis, j); - y = g_sheet_row_start_pixel (sheet->row_geometry, i); + y = psppire_axis_pixel_start (sheet->vaxis, i); 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); + height = psppire_axis_pixel_start (sheet->vaxis, i) - y + psppire_axis_unit_size (sheet->vaxis, i); if (i == sheet->range.row0) { @@ -2881,9 +2854,9 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) { x = psppire_axis_pixel_start (sheet->haxis, j); - y = g_sheet_row_start_pixel (sheet->row_geometry, i); + y = psppire_axis_pixel_start (sheet->vaxis, i); 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); + height = psppire_axis_pixel_start (sheet->vaxis, i) - y + psppire_axis_unit_size (sheet->vaxis, i); if (i == new_range.row0) { @@ -2927,9 +2900,9 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) if (mask2 != mask1 || (mask2 == mask1 && state != GTK_STATE_SELECTED)) { x = psppire_axis_pixel_start (sheet->haxis, j); - y = g_sheet_row_start_pixel (sheet->row_geometry, i); + y = psppire_axis_pixel_start (sheet->vaxis, i); width = psppire_axis_unit_size (sheet->haxis, j); - height = g_sheet_row_get_height (sheet->row_geometry, i); + height = psppire_axis_unit_size (sheet->vaxis, i); if (mask2 & 1) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, @@ -3130,12 +3103,12 @@ gtk_sheet_expose (GtkWidget *widget, range.row0 = - yyy_row_ypixel_to_row (sheet, + row_from_ypixel (sheet, event->area.y + sheet->vadjustment->value); range.row0--; range.rowi = - yyy_row_ypixel_to_row (sheet, + row_from_ypixel (sheet, event->area.y + event->area.height + sheet->vadjustment->value); range.rowi++; @@ -3231,8 +3204,7 @@ gtk_sheet_button_press (GtkWidget *widget, sheet_signals[BUTTON_EVENT_ROW], 0, row, event); - - if (g_sheet_row_get_sensitivity (sheet->row_geometry, row)) + if (g_sheet_model_get_row_sensitivity (sheet->model, row)) { if ( event->type == GDK_2BUTTON_PRESS && event->button == 1) g_signal_emit (sheet, @@ -3277,6 +3249,7 @@ gtk_sheet_button_press (GtkWidget *widget, { gtk_widget_get_pointer (widget, NULL, &sheet->y_drag); +#if AXIS_TRANSITION if (POSSIBLE_YDRAG (sheet, sheet->y_drag, &sheet->drag_cell.row)) { guint req; @@ -3291,6 +3264,7 @@ gtk_sheet_button_press (GtkWidget *widget, draw_xor_hline (sheet); return TRUE; } +#endif } /* the sheet itself does not handle other than single click events */ @@ -3402,8 +3376,8 @@ gtk_sheet_button_press (GtkWidget *widget, y += sheet->vadjustment->value; - row = yyy_row_ypixel_to_row (sheet, y); - if (g_sheet_row_get_sensitivity (sheet->row_geometry, row)) + row = row_from_ypixel (sheet, y); + if (g_sheet_model_get_row_sensitivity (sheet->model, row)) { veto = gtk_sheet_click_cell (sheet, row, -1); gtk_grab_add (GTK_WIDGET (sheet)); @@ -3424,7 +3398,7 @@ gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column) cell.row = row; cell.col = column; - if (row >= g_sheet_row_get_row_count (sheet->row_geometry) + if (row >= psppire_axis_unit_count (sheet->vaxis) || column >= psppire_axis_unit_count (sheet->haxis)) { return FALSE; @@ -3463,7 +3437,7 @@ gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column) { sheet->range.row0 = 0; sheet->range.col0 = 0; - sheet->range.rowi = g_sheet_row_get_row_count (sheet->row_geometry) - 1; + sheet->range.rowi = psppire_axis_unit_count (sheet->vaxis) - 1; sheet->range.coli = psppire_axis_unit_count (sheet->haxis) - 1; sheet->active_cell.row = 0; @@ -3735,8 +3709,7 @@ motion_timeout_callback (gpointer data) { if (sheet->row_title_under) { - GSheetRow *row_geo = sheet->row_geometry; - gchar *text = g_sheet_row_get_subtitle (row_geo, row); + gchar *text = g_sheet_model_get_row_subtitle (sheet->model, row); show_subtitle (sheet, row, -1, text); g_free (text); @@ -3833,6 +3806,7 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) if (event->window == sheet->row_title_window && gtk_sheet_rows_resizable (sheet)) { +#if AXIS_TRANSITION if (!GTK_SHEET_IN_SELECTION (sheet) && POSSIBLE_YDRAG (sheet, y, &column)) { new_cursor = GDK_SB_V_DOUBLE_ARROW; @@ -3844,6 +3818,7 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) } } else +#endif { new_cursor = GDK_TOP_LEFT_ARROW; if (!GTK_SHEET_IN_YDRAG (sheet) && @@ -3936,13 +3911,13 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) { GtkSheetRange aux; column = column_from_xpixel (sheet, x)- sheet->drag_cell.col; - row = yyy_row_ypixel_to_row (sheet, y) - sheet->drag_cell.row; + row = row_from_ypixel (sheet, y) - sheet->drag_cell.row; if (sheet->state == GTK_SHEET_COLUMN_SELECTED) row = 0; if (sheet->state == GTK_SHEET_ROW_SELECTED) column = 0; sheet->x_drag = x; sheet->y_drag = y; aux = sheet->range; - if (aux.row0 + row >= 0 && aux.rowi + row < g_sheet_row_get_row_count (sheet->row_geometry) && + if (aux.row0 + row >= 0 && aux.rowi + row < psppire_axis_unit_count (sheet->vaxis) && aux.col0 + column >= 0 && aux.coli + column < psppire_axis_unit_count (sheet->haxis)) { aux = sheet->drag_range; @@ -3966,10 +3941,10 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) gint v_h, current_col, current_row, col_threshold, row_threshold; v_h = 1; 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; + abs (y - psppire_axis_pixel_start (sheet->vaxis, sheet->drag_cell.row))) v_h = 2; current_col = column_from_xpixel (sheet, x); - current_row = yyy_row_ypixel_to_row (sheet, y); + current_row = row_from_ypixel (sheet, y); column = current_col - sheet->drag_cell.col; row = current_row - sheet->drag_cell.row; @@ -3987,8 +3962,8 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) if (x > col_threshold) column +=1; } - row_threshold = g_sheet_row_start_pixel (sheet->row_geometry, current_row) + - g_sheet_row_get_height (sheet->row_geometry, current_row)/2; + row_threshold = psppire_axis_pixel_start (sheet->vaxis, current_row) + + psppire_axis_unit_size (sheet->vaxis, current_row)/2; if (row > 0) { if (y < row_threshold) @@ -4011,7 +3986,7 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) else row = 0; - if (aux.row0 + row >= 0 && aux.rowi + row < g_sheet_row_get_row_count (sheet->row_geometry) && + if (aux.row0 + row >= 0 && aux.rowi + row < psppire_axis_unit_count (sheet->vaxis) && aux.col0 + column >= 0 && aux.coli + column < psppire_axis_unit_count (sheet->haxis)) { aux = sheet->drag_range; @@ -4083,7 +4058,7 @@ gtk_sheet_extend_selection (GtkSheet *sheet, gint row, gint column) 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; + row = psppire_axis_unit_count (sheet->vaxis) - 1; break; case GTK_SHEET_NORMAL: sheet->state = GTK_SHEET_RANGE_SELECTED; @@ -4131,11 +4106,11 @@ static void page_vertical (GtkSheet *sheet, GtkScrollType dir) { gint old_row = sheet->active_cell.row ; - glong vpixel = g_sheet_row_start_pixel (sheet->row_geometry, old_row); + glong vpixel = psppire_axis_pixel_start (sheet->vaxis, old_row); gint new_row; - vpixel -= g_sheet_row_start_pixel (sheet->row_geometry, + vpixel -= psppire_axis_pixel_start (sheet->vaxis, min_visible_row (sheet)); switch ( dir) @@ -4157,10 +4132,10 @@ page_vertical (GtkSheet *sheet, GtkScrollType dir) } - vpixel += g_sheet_row_start_pixel (sheet->row_geometry, + vpixel += psppire_axis_pixel_start (sheet->vaxis, min_visible_row (sheet)); - new_row = yyy_row_ypixel_to_row (sheet, vpixel); + new_row = row_from_ypixel (sheet, vpixel); change_active_cell (sheet, new_row, sheet->active_cell.col); @@ -4202,7 +4177,7 @@ step_sheet (GtkSheet *sheet, GtkScrollType dir) maximize_int (&new_cell.col, 0); minimize_int (&new_cell.row, - g_sheet_row_get_row_count (sheet->row_geometry) - 1); + psppire_axis_unit_count (sheet->vaxis) - 1); minimize_int (&new_cell.col, psppire_axis_unit_count (sheet->haxis) - 1); @@ -4241,7 +4216,7 @@ step_sheet (GtkSheet *sheet, GtkScrollType dir) if ( new_cell.row > max_fully_visible_row (sheet)) { glong vpos = - g_sheet_row_start_pixel (sheet->row_geometry, + psppire_axis_pixel_start (sheet->vaxis, new_cell.row + 1); vpos -= sheet->vadjustment->page_size; @@ -4251,7 +4226,7 @@ step_sheet (GtkSheet *sheet, GtkScrollType dir) else if ( new_cell.row < min_fully_visible_row (sheet)) { glong vpos = - g_sheet_row_start_pixel (sheet->row_geometry, + psppire_axis_pixel_start (sheet->vaxis, new_cell.row); gtk_adjustment_set_value (sheet->vadjustment, @@ -4310,7 +4285,7 @@ gtk_sheet_key_press (GtkWidget *widget, /* change_active_cellx (sheet, - g_sheet_row_get_row_count (sheet->row_geometry) - 1, + psppire_axis_unit_count (sheet->vaxis) - 1, sheet->active_cell.col); */ break; @@ -4396,13 +4371,19 @@ gtk_sheet_size_allocate (GtkWidget *widget, /* position the window which holds the column title buttons */ sheet->column_title_area.x = 0; sheet->column_title_area.y = 0; + sheet->column_title_area.width = sheet_allocation.width ; + + + /* position the window which holds the row title buttons */ + sheet->row_title_area.x = 0; + sheet->row_title_area.y = 0; + sheet->row_title_area.height = sheet_allocation.height; if (sheet->row_titles_visible) - { - sheet->column_title_area.x = sheet->row_title_area.width; - } + sheet->column_title_area.x += sheet->row_title_area.width; - sheet->column_title_area.width = sheet_allocation.width ; + if (sheet->column_titles_visible) + sheet->row_title_area.y += sheet->column_title_area.height; if (GTK_WIDGET_REALIZED (widget) && sheet->column_titles_visible) @@ -4413,17 +4394,6 @@ gtk_sheet_size_allocate (GtkWidget *widget, sheet->column_title_area.height); - /* position the window which holds the row title buttons */ - sheet->row_title_area.x = 0; - sheet->row_title_area.y = 0; - if (sheet->column_titles_visible) - { - sheet->row_title_area.y = sheet->column_title_area.height; - } - - sheet->row_title_area.height = sheet_allocation.height - - sheet->row_title_area.y; - if (GTK_WIDGET_REALIZED (widget) && sheet->row_titles_visible) gdk_window_move_resize (sheet->row_title_window, sheet->row_title_area.x, @@ -4431,11 +4401,6 @@ gtk_sheet_size_allocate (GtkWidget *widget, sheet->row_title_area.width, sheet->row_title_area.height); - - - - - if (sheet->haxis) { gint width = sheet->column_title_area.width; @@ -4449,6 +4414,19 @@ gtk_sheet_size_allocate (GtkWidget *widget, } + if (sheet->vaxis) + { + gint height = sheet->row_title_area.height; + + if ( sheet->column_titles_visible) + height -= sheet->column_title_area.height; + + g_object_set (sheet->vaxis, + "minimum-extent", height, + NULL); + } + + /* set the scrollbars adjustments */ adjust_scrollbars (sheet); } @@ -4524,7 +4502,7 @@ draw_row_title_buttons (GtkSheet *sheet) sheet->row_title_area.height); } - if (max_visible_row (sheet) == g_sheet_row_get_row_count (sheet->row_geometry) - 1) + if (max_visible_row (sheet) == psppire_axis_unit_count (sheet->vaxis) - 1) gdk_window_clear_area (sheet->row_title_window, 0, 0, sheet->row_title_area.width, @@ -4869,15 +4847,15 @@ draw_row_title_buttons_range (GtkSheet *sheet, gint first, gint last) gboolean is_sensitive = FALSE; GtkSheetButton *button = - g_sheet_row_get_button (sheet->row_geometry, row); + g_sheet_model_get_row_button (sheet->model, row); allocation.x = 0; - allocation.y = g_sheet_row_start_pixel (sheet->row_geometry, row) + allocation.y = psppire_axis_pixel_start (sheet->vaxis, row) + CELL_SPACING; allocation.y -= sheet->vadjustment->value; allocation.width = sheet->row_title_area.width; - allocation.height = g_sheet_row_get_height (sheet->row_geometry, row); - is_sensitive = g_sheet_row_get_sensitivity (sheet->row_geometry, row); + allocation.height = psppire_axis_unit_size (sheet->vaxis, row); + is_sensitive = g_sheet_model_get_row_sensitivity (sheet->model, row); draw_button (sheet, sheet->row_title_window, button, is_sensitive, allocation); @@ -4911,23 +4889,23 @@ adjust_scrollbars (GtkSheet *sheet) if (sheet->vadjustment) { - glong last_row = g_sheet_row_get_row_count (sheet->row_geometry) - 1; + glong last_row = psppire_axis_unit_count (sheet->vaxis) - 1; sheet->vadjustment->step_increment = ROWS_PER_STEP * - g_sheet_row_get_height (sheet->row_geometry, last_row); + psppire_axis_unit_size (sheet->vaxis, last_row); sheet->vadjustment->page_increment = height - sheet->column_title_area.height - - g_sheet_row_get_height (sheet->row_geometry, last_row); + psppire_axis_unit_size (sheet->vaxis, last_row); sheet->vadjustment->upper = - g_sheet_row_start_pixel (sheet->row_geometry, last_row) + psppire_axis_pixel_start (sheet->vaxis, last_row) + - g_sheet_row_get_height (sheet->row_geometry, last_row) + psppire_axis_unit_size (sheet->vaxis, last_row) ; sheet->vadjustment->lower = 0; @@ -5064,11 +5042,11 @@ draw_xor_rectangle (GtkSheet *sheet, GtkSheetRange range) GdkGCValues values; area.x = psppire_axis_pixel_start (sheet->haxis, range.col0); - area.y = g_sheet_row_start_pixel (sheet->row_geometry, range.row0); + area.y = psppire_axis_pixel_start (sheet->vaxis, range.row0); 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); + area.height = psppire_axis_pixel_start (sheet->vaxis, range.rowi)- area.y + + psppire_axis_unit_size (sheet->vaxis, range.rowi); clip_area.x = sheet->row_title_area.width; clip_area.y = sheet->column_title_area.height; @@ -5154,19 +5132,21 @@ new_row_height (GtkSheet *sheet, gint row, gint *y) min_height = sheet->row_requisition; /* you can't shrink a row to less than its minimum height */ - if (cy < g_sheet_row_start_pixel (sheet->row_geometry, row) + min_height) + if (cy < psppire_axis_pixel_start (sheet->vaxis, row) + min_height) { - *y = cy = g_sheet_row_start_pixel (sheet->row_geometry, row) + min_height; + *y = cy = psppire_axis_pixel_start (sheet->vaxis, row) + min_height; } /* calculate new row height making sure it doesn't end up * less than the minimum height */ - height = (cy - g_sheet_row_start_pixel (sheet->row_geometry, row)); + height = (cy - psppire_axis_pixel_start (sheet->vaxis, row)); if (height < min_height) height = min_height; +#if AXIS_TRANSITION g_sheet_row_set_height (sheet->row_geometry, row, height); +#endif draw_row_title_buttons (sheet); return height; @@ -5213,13 +5193,15 @@ gtk_sheet_set_row_height (GtkSheet *sheet, g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (row < 0 || row >= g_sheet_row_get_row_count (sheet->row_geometry)) + if (row < 0 || row >= psppire_axis_unit_count (sheet->vaxis)) return; gtk_sheet_row_size_request (sheet, row, &min_height); if (height < min_height) return; +#if AXIS_TRANSITION g_sheet_row_set_height (sheet->row_geometry, row, height); +#endif if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)) ) { @@ -5322,7 +5304,7 @@ gtk_sheet_row_size_request (GtkSheet *sheet, GtkRequisition button_requisition; gtk_sheet_button_size_request (sheet, - g_sheet_row_get_button (sheet->row_geometry, row), + g_sheet_model_get_row_button (sheet->model, row), &button_requisition); *requisition = button_requisition.height; diff --git a/lib/gtksheet/gtksheet.h b/lib/gtksheet/gtksheet.h index de308a60..ba2294f8 100644 --- a/lib/gtksheet/gtksheet.h +++ b/lib/gtksheet/gtksheet.h @@ -30,7 +30,6 @@ #include "gtkextra-sheet.h" #include "gsheetmodel.h" -#include "gsheet-row-iface.h" #include "psppire-axis.h" G_BEGIN_DECLS @@ -90,11 +89,8 @@ struct _GtkSheet GtkBin parent; gboolean dispose_has_run; - /* - GSheetColumn *column_geometry; - */ PsppireAxis *haxis; - GSheetRow *row_geometry; + PsppireAxis *vaxis; guint16 flags; @@ -233,19 +229,14 @@ GtkType gtk_sheet_range_get_type (void); /* create a new sheet */ -GtkWidget * gtk_sheet_new (GSheetRow *vgeo, void *hgeo, +GtkWidget * gtk_sheet_new (void *vgeo, void *hgeo, GSheetModel *model); /* create a new sheet with custom entry */ GtkWidget * -gtk_sheet_new_with_custom_entry (GSheetRow *vgeo, +gtk_sheet_new_with_custom_entry (void *vgeo, void *hgeo, GtkType entry_type); -void -gtk_sheet_construct_with_custom_entry (GtkSheet *sheet, - GSheetRow *vgeo, - void *hgeo, - GtkType entry_type); /* Change entry */ void gtk_sheet_change_entry (GtkSheet *sheet, GtkType entry_type); diff --git a/lib/gtksheet/psppire-axis-hetero.c b/lib/gtksheet/psppire-axis-hetero.c new file mode 100644 index 00000000..aad3da71 --- /dev/null +++ b/lib/gtksheet/psppire-axis-hetero.c @@ -0,0 +1,263 @@ +/* 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 +#include "psppire-axis-hetero.h" +#include + + +/* --- prototypes --- */ +static void psppire_axis_hetero_class_init (PsppireAxisHeteroClass *class); +static void psppire_axis_hetero_init (PsppireAxisHetero *axis); +static void psppire_axis_hetero_finalize (GObject *object); + + +/* --- variables --- */ +static GObjectClass *parent_class = NULL; + + +static gint +get_unit_at_pixel (const PsppireAxis *a, glong pixel) +{ + PsppireAxisHetero *ah = PSPPIRE_AXIS_HETERO (a); + const struct tower_node *node; + unsigned long int node_start; + + if (pixel >= tower_height (&ah->tower)) + return tower_count (&ah->tower); + + node = tower_lookup (&ah->tower, pixel, &node_start); + + return tower_node_get_index (node); +} + + +static gint +unit_count (const PsppireAxis *a) +{ + PsppireAxisHetero *ah = PSPPIRE_AXIS_HETERO (a); + return tower_count (&ah->tower); +} + + +static glong +pixel_start (const PsppireAxis *a, gint unit) +{ + PsppireAxisHetero *ah = PSPPIRE_AXIS_HETERO (a); + const struct tower_node *node; + + if ( unit >= tower_count (&ah->tower)) + return tower_height (&ah->tower); + + node = tower_get (&ah->tower, unit); + + return tower_node_get_level (node); +} + + +static gint +unit_size (const PsppireAxis *a, gint unit) +{ + PsppireAxisHetero *ah = PSPPIRE_AXIS_HETERO (a); + const struct tower_node *node; + if (unit >= tower_count (&ah->tower)) + return 0; + + node = tower_get (&ah->tower, unit); + + return tower_node_get_size (node); +} + + +static glong +total_size (const PsppireAxis *a) +{ + glong s; + PsppireAxisHetero *ah = PSPPIRE_AXIS_HETERO (a); + + s = tower_height (&ah->tower); + return s; +} + +static void +psppire_hetero_iface_init (PsppireAxisIface *iface) +{ + iface->unit_size = unit_size; + iface->unit_count = unit_count; + iface->pixel_start = pixel_start; + iface->get_unit_at_pixel = get_unit_at_pixel; + iface->total_size = total_size; +} + +/* --- functions --- */ +/** + * psppire_axis_hetero_get_type: + * @returns: the type ID for accelerator groups. + */ +GType +psppire_axis_hetero_get_type (void) +{ + static GType object_type = 0; + + if (!object_type) + { + static const GTypeInfo object_info = { + sizeof (PsppireAxisHeteroClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) psppire_axis_hetero_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (PsppireAxisHetero), + 0, /* n_preallocs */ + (GInstanceInitFunc) psppire_axis_hetero_init, + }; + + + static const GInterfaceInfo interface_info = + { + (GInterfaceInitFunc) psppire_hetero_iface_init, + NULL, + NULL + }; + + object_type = g_type_register_static (G_TYPE_PSPPIRE_AXIS, + "PsppireAxisHetero", + &object_info, 0); + + g_type_add_interface_static (object_type, + PSPPIRE_TYPE_AXIS_IFACE, + &interface_info); + } + + return object_type; +} + +static void +psppire_axis_hetero_class_init (PsppireAxisHeteroClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + parent_class = g_type_class_peek_parent (class); + + object_class->finalize = psppire_axis_hetero_finalize; +} + + +static void +psppire_axis_hetero_init (PsppireAxisHetero *axis) +{ + axis->pool = NULL; + psppire_axis_hetero_clear (axis); +} + + +static void +psppire_axis_hetero_finalize (GObject *object) +{ + PsppireAxisHetero *a = PSPPIRE_AXIS_HETERO (object); + pool_destroy (a->pool); + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +/** + * psppire_axis_hetero_new: + * @returns: a new #PsppireAxisHetero object + * + * Creates a new #PsppireAxisHetero. + */ +PsppireAxisHetero* +psppire_axis_hetero_new (void) +{ + return g_object_new (G_TYPE_PSPPIRE_AXIS_HETERO, NULL); +} + + +void +psppire_axis_hetero_append (PsppireAxisHetero *a, gint size) +{ + struct tower_node *new ; + + g_return_if_fail (PSPPIRE_IS_AXIS_HETERO (a)); + + new = pool_malloc (a->pool, sizeof *new); + + tower_insert (&a->tower, size, new, NULL); +} + + + +/* Insert a new unit of size SIZE before position POSN */ +void +psppire_axis_hetero_insert (PsppireAxisHetero *a, gint size, gint posn) +{ + struct tower_node *new; + struct tower_node *before = NULL; + + g_return_if_fail (PSPPIRE_IS_AXIS_HETERO (a)); + + new = pool_malloc (a->pool, sizeof *new); + + if ( posn != tower_count (&a->tower)) + before = tower_get (&a->tower, posn); + + tower_insert (&a->tower, size, new, before); +} + + +void +psppire_axis_hetero_remove (PsppireAxisHetero *a, gint posn) +{ + struct tower_node *node; + + g_return_if_fail (PSPPIRE_IS_AXIS_HETERO (a)); + + node = tower_get (&a->tower, posn); + + tower_delete (&a->tower, node); + + pool_free (a->pool, node); +} + + +void +psppire_axis_hetero_resize_unit (PsppireAxisHetero *a, gint size, gint posn) +{ + struct tower_node *node; + + g_return_if_fail (PSPPIRE_IS_AXIS_HETERO (a)); + + node = tower_get (&a->tower, posn); + + tower_resize (&a->tower, node, size); +} + + +void +psppire_axis_hetero_clear (PsppireAxisHetero *a) +{ + g_return_if_fail (PSPPIRE_IS_AXIS_HETERO (a)); + + pool_destroy (a->pool); + a->pool = pool_create (); + tower_init (&a->tower); +} + + diff --git a/lib/gtksheet/psppire-axis-hetero.h b/lib/gtksheet/psppire-axis-hetero.h new file mode 100644 index 00000000..c1b674cc --- /dev/null +++ b/lib/gtksheet/psppire-axis-hetero.h @@ -0,0 +1,80 @@ +/* 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_HETERO_H__ +#define PSPPIRE_AXIS_HETERO_H__ + + +#include +#include + +#include +#include "psppire-axis.h" + +G_BEGIN_DECLS + + +/* --- type macros --- */ +#define G_TYPE_PSPPIRE_AXIS_HETERO (psppire_axis_hetero_get_type ()) +#define PSPPIRE_AXIS_HETERO(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_PSPPIRE_AXIS_HETERO, PsppireAxisHetero)) +#define PSPPIRE_AXIS_HETERO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G_TYPE_PSPPIRE_AXIS_HETERO, PsppireAxisHeteroClass)) +#define PSPPIRE_IS_AXIS_HETERO(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_PSPPIRE_AXIS_HETERO)) +#define PSPPIRE_IS_AXIS_HETERO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G_TYPE_PSPPIRE_AXIS_HETERO)) +#define PSPPIRE_AXIS_HETERO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G_TYPE_PSPPIRE_AXIS_HETERO, PsppireAxisHeteroClass)) + + + +/* --- typedefs & structures --- */ +typedef struct _PsppireAxisHetero PsppireAxisHetero; +typedef struct _PsppireAxisHeteroClass PsppireAxisHeteroClass; + +struct pool; + +struct _PsppireAxisHetero +{ + PsppireAxis parent; + + struct tower tower; + struct pool *pool; +}; + +struct _PsppireAxisHeteroClass +{ + PsppireAxisClass parent_class; +}; + +GType psppire_axis_hetero_get_type (void); + +PsppireAxisHetero* psppire_axis_hetero_new (void); + + +/* Interface between axis and model */ + +void psppire_axis_hetero_clear (PsppireAxisHetero *a); + +void psppire_axis_hetero_append (PsppireAxisHetero *a, gint size); + +void psppire_axis_hetero_insert (PsppireAxisHetero *a, gint size, gint posn); + +void psppire_axis_hetero_remove (PsppireAxisHetero *a, gint posn); + +void psppire_axis_hetero_resize_unit (PsppireAxisHetero *a, gint size, gint posn); + + +G_END_DECLS + +#endif /* PSPPIRE_AXIS_HETERO_H__ */ diff --git a/lib/gtksheet/psppire-axis-uniform.c b/lib/gtksheet/psppire-axis-uniform.c new file mode 100644 index 00000000..8763da10 --- /dev/null +++ b/lib/gtksheet/psppire-axis-uniform.c @@ -0,0 +1,196 @@ +/* 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 +#include "psppire-axis-uniform.h" +#include + + +/* --- prototypes --- */ +static void psppire_axis_uniform_class_init (PsppireAxisUniformClass *class); +static void psppire_axis_uniform_init (PsppireAxisUniform *axis); +static void psppire_axis_uniform_finalize (GObject *object); + + +/* --- variables --- */ +static GObjectClass *parent_class = NULL; + + +#define UNIT_SIZE 25 + +static gint +get_unit_at_pixel (const PsppireAxis *a, glong pixel) +{ + gint unit_size; + PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a); + + g_object_get (au, "default-size", &unit_size, NULL); + + return pixel / unit_size; +} + + +static gint +unit_count (const PsppireAxis *a) +{ + PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a); + + return au->n_items; +} + + +static glong +pixel_start (const PsppireAxis *a, gint unit) +{ + gint unit_size; + PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a); + + g_object_get (au, "default-size", &unit_size, NULL); + + return unit * unit_size; +} + + +static gint +unit_size (const PsppireAxis *a, gint unit) +{ + gint unit_size; + PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a); + + g_object_get (au, "default-size", &unit_size, NULL); + + return unit_size; +} + + +static glong +total_size (const PsppireAxis *a) +{ + gint unit_size; + PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a); + + g_object_get (au, "default-size", &unit_size, NULL); + + return unit_size * au->n_items; +} + + + +static void +psppire_uniform_iface_init (PsppireAxisIface *iface) +{ + iface->unit_size = unit_size; + iface->unit_count = unit_count; + iface->pixel_start = pixel_start; + iface->get_unit_at_pixel = get_unit_at_pixel; + iface->total_size = total_size; +} + +/* --- functions --- */ +/** + * psppire_axis_uniform_get_type: + * @returns: the type ID for accelerator groups. + */ +GType +psppire_axis_uniform_get_type (void) +{ + static GType object_type = 0; + + if (!object_type) + { + static const GTypeInfo object_info = { + sizeof (PsppireAxisUniformClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) psppire_axis_uniform_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (PsppireAxisUniform), + 0, /* n_preallocs */ + (GInstanceInitFunc) psppire_axis_uniform_init, + }; + + static const GInterfaceInfo interface_info = + { + (GInterfaceInitFunc) psppire_uniform_iface_init, + NULL, + NULL + }; + + + object_type = g_type_register_static (G_TYPE_PSPPIRE_AXIS, + "PsppireAxisUniform", + &object_info, 0); + + + g_type_add_interface_static (object_type, + PSPPIRE_TYPE_AXIS_IFACE, + &interface_info); + } + + return object_type; +} + +static void +psppire_axis_uniform_class_init (PsppireAxisUniformClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + parent_class = g_type_class_peek_parent (class); + + object_class->finalize = psppire_axis_uniform_finalize; +} + + +static void +psppire_axis_uniform_init (PsppireAxisUniform *axis) +{ + axis->n_items = 0; +} + + +static void +psppire_axis_uniform_finalize (GObject *object) +{ + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +/** + * psppire_axis_uniform_new: + * @returns: a new #PsppireAxisUniform object + * + * Creates a new #PsppireAxisUniform. + */ +PsppireAxisUniform* +psppire_axis_uniform_new (void) +{ + return g_object_new (G_TYPE_PSPPIRE_AXIS_UNIFORM, NULL); +} + + + + + + +void +psppire_axis_uniform_set_count (PsppireAxisUniform *axis, gint n) +{ + axis->n_items = n; +} diff --git a/lib/gtksheet/psppire-axis-uniform.h b/lib/gtksheet/psppire-axis-uniform.h new file mode 100644 index 00000000..49f434d4 --- /dev/null +++ b/lib/gtksheet/psppire-axis-uniform.h @@ -0,0 +1,72 @@ +/* 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_UNIFORM_H__ +#define PSPPIRE_AXIS_UNIFORM_H__ + + +#include +#include + +#include "psppire-axis.h" + +G_BEGIN_DECLS + + +/* --- type macros --- */ +#define G_TYPE_PSPPIRE_AXIS_UNIFORM (psppire_axis_uniform_get_type ()) +#define PSPPIRE_AXIS_UNIFORM(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_PSPPIRE_AXIS_UNIFORM, PsppireAxisUniform)) +#define PSPPIRE_AXIS_UNIFORM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G_TYPE_PSPPIRE_AXIS_UNIFORM, PsppireAxisUniformClass)) +#define PSPPIRE_IS_AXIS_UNIFORM(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_PSPPIRE_AXIS_UNIFORM)) +#define PSPPIRE_IS_AXIS_UNIFORM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G_TYPE_PSPPIRE_AXIS_UNIFORM)) +#define PSPPIRE_AXIS_UNIFORM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G_TYPE_PSPPIRE_AXIS_UNIFORM, PsppireAxisUniformClass)) + + + +/* --- typedefs & structures --- */ +typedef struct _PsppireAxisUniform PsppireAxisUniform; +typedef struct _PsppireAxisUniformClass PsppireAxisUniformClass; + +struct pool; + +struct _PsppireAxisUniform +{ + PsppireAxis parent; + + gint n_items; +}; + +struct _PsppireAxisUniformClass +{ + PsppireAxisClass parent_class; +}; + +GType psppire_axis_uniform_get_type (void); + +PsppireAxisUniform* psppire_axis_uniform_new (void); + + +/* Interface between axis and model */ + + +void psppire_axis_uniform_set_count (PsppireAxisUniform *axis, gint n); + + + +G_END_DECLS + +#endif /* PSPPIRE_AXIS_UNIFORM_H__ */ diff --git a/lib/gtksheet/psppire-axis.c b/lib/gtksheet/psppire-axis.c index a46bb483..92eba59b 100644 --- a/lib/gtksheet/psppire-axis.c +++ b/lib/gtksheet/psppire-axis.c @@ -24,47 +24,52 @@ #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; +#define PSPPIRE_AXIS_GET_IFACE(obj) \ + (G_TYPE_INSTANCE_GET_INTERFACE ((obj), PSPPIRE_TYPE_AXIS_IFACE, PsppireAxisIface)) -/* --- functions --- */ -/** - * psppire_axis_get_type: - * @returns: the type ID for accelerator groups. - */ GType -psppire_axis_get_type (void) +psppire_axis_iface_get_type (void) { - static GType object_type = 0; + static GType psppire_axis_iface_type = 0; - if (!object_type) + if (! psppire_axis_iface_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, + static const GTypeInfo psppire_axis_iface_info = + { + sizeof (PsppireAxisIface), /* class_size */ + NULL, /* base init */ + NULL, /* base_finalize */ + NULL, + NULL, /* class_finalize */ + NULL, /* class_data */ + 0, + 0, /* n_preallocs */ + NULL }; - object_type = g_type_register_static (G_TYPE_OBJECT, - "PsppireAxis", - &object_info, 0); + psppire_axis_iface_type = + g_type_register_static (G_TYPE_INTERFACE, "PsppireAxisIface", + &psppire_axis_iface_info, 0); } - return object_type; + return psppire_axis_iface_type; } +G_DEFINE_ABSTRACT_TYPE(PsppireAxis, psppire_axis, G_TYPE_OBJECT); + + + +/* --- 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; + + + enum { PROP_0, @@ -131,10 +136,10 @@ psppire_axis_class_init (PsppireAxisClass *class) min_extent_spec = g_param_spec_long ("minimum-extent", "Minimum Extent", - "The smallest extent to which the axis will provide units (typically set to the height/width of the associated widget)", + "The smallest extent to which the axis will provide units (typically set to the height/width of the associated widget).", 0, G_MAXLONG, - 800, - G_PARAM_WRITABLE | G_PARAM_READABLE ); + 0, + G_PARAM_CONSTRUCT | G_PARAM_WRITABLE | G_PARAM_READABLE ); g_object_class_install_property (object_class, PROP_MIN_EXTENT, @@ -142,10 +147,12 @@ psppire_axis_class_init (PsppireAxisClass *class) default_size_spec = - g_param_spec_pointer ("default-size", - "Default Size", - "The size given to units which haven't been explicity inserted", - G_PARAM_WRITABLE | G_PARAM_READABLE ); + g_param_spec_int ("default-size", + "Default Size", + "The size given to units which haven't been explicity inserted", + 0, G_MAXINT, + 25, + G_PARAM_CONSTRUCT | G_PARAM_WRITABLE | G_PARAM_READABLE ); g_object_class_install_property (object_class, @@ -161,149 +168,89 @@ psppire_axis_class_init (PsppireAxisClass *class) static void psppire_axis_init (PsppireAxis *axis) { - axis->min_extent = 800; - axis->default_size = 75; - axis->pool = NULL; - psppire_axis_clear (axis); } static void psppire_axis_finalize (GObject *object) { - PsppireAxis *a = PSPPIRE_AXIS (object); - pool_destroy (a->pool); G_OBJECT_CLASS (parent_class)->finalize (object); } -/** - * psppire_axis_new: - * @returns: a new #PsppireAxis object - * - * Creates a new #PsppireAxis. - */ -PsppireAxis* -psppire_axis_new (void) +gint +psppire_axis_unit_size (const PsppireAxis *a, gint unit) { - return g_object_new (G_TYPE_PSPPIRE_AXIS, NULL); -} + g_return_val_if_fail (PSPPIRE_IS_AXIS (a), -1); + g_return_val_if_fail (PSPPIRE_AXIS_GET_IFACE (a)->unit_size, -1); -gint -psppire_axis_unit_size (PsppireAxis *a, gint unit) -{ - const struct tower_node *node; - if (unit >= tower_count (&a->tower)) - return a->default_size; - node = tower_get (&a->tower, unit); + if (unit >= PSPPIRE_AXIS_GET_IFACE (a)->unit_count(a)) + return a->default_size; - return tower_node_get_size (node); + return PSPPIRE_AXIS_GET_IFACE (a)->unit_size (a, unit); } gint -psppire_axis_unit_count (PsppireAxis *a) +psppire_axis_unit_count (const PsppireAxis *a) { glong padding = 0; + glong actual_size; - if ( tower_height (&a->tower) < a->min_extent ) - padding = (a->min_extent - tower_height (&a->tower)) - / a->default_size; + g_return_val_if_fail (PSPPIRE_IS_AXIS (a), -1); + g_return_val_if_fail (PSPPIRE_AXIS_GET_IFACE (a)->unit_count, -1); - return tower_count (&a->tower) + padding; + actual_size = PSPPIRE_AXIS_GET_IFACE (a)->total_size (a); + + if ( actual_size < a->min_extent ) + padding = (a->min_extent - actual_size) / a->default_size; + + return PSPPIRE_AXIS_GET_IFACE (a)->unit_count (a) + padding; } /* Return the starting pixel of UNIT */ glong -psppire_axis_pixel_start (PsppireAxis *a, gint unit) +psppire_axis_pixel_start (const PsppireAxis *a, gint unit) { - const struct tower_node *node; + gint the_count, total_size ; + g_return_val_if_fail (PSPPIRE_IS_AXIS (a), -1); - if ( unit >= tower_count (&a->tower)) - { - return tower_height (&a->tower) + - (unit - tower_count (&a->tower)) * a->default_size; - } + the_count = PSPPIRE_AXIS_GET_IFACE (a)->unit_count (a); + total_size = PSPPIRE_AXIS_GET_IFACE (a)->total_size (a); - node = tower_get (&a->tower, unit); - return tower_node_get_level (node); -} - - -/* Return the unit covered by PIXEL */ -gint -psppire_axis_get_unit_at_pixel (PsppireAxis *a, glong pixel) -{ - const struct tower_node *node; - unsigned long int node_start; - - if (pixel >= tower_height (&a->tower)) + if ( unit >= the_count) { - glong extra = pixel - tower_height (&a->tower); - - if ( extra > a->min_extent - tower_height (&a->tower)) - extra = a->min_extent - tower_height (&a->tower); - - return tower_count (&a->tower) - 1 + extra / a->default_size; + return total_size + (unit - the_count) * a->default_size; } - node = tower_lookup (&a->tower, pixel, &node_start); - - return tower_node_get_index (node); -} - -void -psppire_axis_append (PsppireAxis *a, gint size) -{ - struct tower_node *new = pool_malloc (a->pool, sizeof *new); + // g_print ("%s %d\n", __FUNCTION__, unit); - tower_insert (&a->tower, size, new, NULL); + return PSPPIRE_AXIS_GET_IFACE (a)->pixel_start (a, unit); } - -/* Insert a new unit of size SIZE before position POSN */ -void -psppire_axis_insert (PsppireAxis *a, gint size, gint posn) -{ - struct tower_node *new = pool_malloc (a->pool, sizeof *new); - - struct tower_node *before = NULL; - - if ( posn != tower_count (&a->tower)) - before = tower_get (&a->tower, posn); - - tower_insert (&a->tower, size, new, before); -} - - -void -psppire_axis_remove (PsppireAxis *a, gint posn) +/* Return the unit covered by PIXEL */ +gint +psppire_axis_get_unit_at_pixel (const PsppireAxis *a, glong pixel) { - struct tower_node *node = tower_get (&a->tower, posn); + glong total_size; - tower_delete (&a->tower, node); + g_return_val_if_fail (PSPPIRE_IS_AXIS (a), -1); - pool_free (a->pool, node); -} + g_return_val_if_fail (PSPPIRE_AXIS_GET_IFACE (a), -1); + g_return_val_if_fail (PSPPIRE_AXIS_GET_IFACE (a)->get_unit_at_pixel, -1); -void -psppire_axis_resize_unit (PsppireAxis *a, gint size, gint posn) -{ - struct tower_node *node = tower_get (&a->tower, posn); + total_size = PSPPIRE_AXIS_GET_IFACE (a)->total_size (a); - tower_resize (&a->tower, node, size); -} + if (pixel >= total_size) + { + gint n_items = PSPPIRE_AXIS_GET_IFACE (a)->unit_count (a); + glong extra = pixel - total_size; + return n_items - 1 + extra / a->default_size; + } -void -psppire_axis_clear (PsppireAxis *a) -{ - pool_destroy (a->pool); - a->pool = pool_create (); - tower_init (&a->tower); + return PSPPIRE_AXIS_GET_IFACE (a)->get_unit_at_pixel (a, pixel); } - - diff --git a/lib/gtksheet/psppire-axis.h b/lib/gtksheet/psppire-axis.h index ef4b2908..4ec23137 100644 --- a/lib/gtksheet/psppire-axis.h +++ b/lib/gtksheet/psppire-axis.h @@ -27,6 +27,7 @@ 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)) @@ -36,20 +37,14 @@ G_BEGIN_DECLS #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 pool; - struct _PsppireAxis { GObject parent; - struct tower tower; - struct pool *pool; - glong min_extent; gint default_size; }; @@ -59,34 +54,46 @@ struct _PsppireAxisClass GObjectClass parent_class; }; + GType psppire_axis_get_type (void); -PsppireAxis* psppire_axis_new (void); -/* Interface between sheet and axis */ -gint psppire_axis_unit_size (PsppireAxis *a, gint unit); +GType psppire_axis_iface_get_type (void); + +#define PSPPIRE_TYPE_AXIS_IFACE (psppire_axis_iface_get_type ()) -gint psppire_axis_unit_count (PsppireAxis *a); +typedef struct _PsppireAxisIface PsppireAxisIface; + +struct _PsppireAxisIface +{ + GTypeInterface g_iface; -glong psppire_axis_pixel_start (PsppireAxis *a, gint unit); -gint psppire_axis_get_unit_at_pixel (PsppireAxis *a, glong pixel); + /* Virtual Table */ + gint (*unit_size) (const PsppireAxis *a, gint unit); + gint (*unit_count) (const PsppireAxis *a); -/* Interface between axis and model */ + glong (*pixel_start) (const PsppireAxis *a, gint unit); -void psppire_axis_clear (PsppireAxis *a); + gint (*get_unit_at_pixel) (const PsppireAxis *a, glong pixel); + + glong (*total_size ) (const PsppireAxis *a); +}; + + +/* Interface between sheet and axis */ -void psppire_axis_append (PsppireAxis *a, gint size); +gint psppire_axis_unit_size (const PsppireAxis *a, gint unit); -void psppire_axis_insert (PsppireAxis *a, gint size, gint posn); +gint psppire_axis_unit_count (const PsppireAxis *a); -void psppire_axis_remove (PsppireAxis *a, gint posn); +glong psppire_axis_pixel_start (const PsppireAxis *a, gint unit); -void psppire_axis_resize_unit (PsppireAxis *a, gint size, gint posn); +gint psppire_axis_get_unit_at_pixel (const PsppireAxis *a, glong pixel); G_END_DECLS diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 505cf4a1..c1908387 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -23,6 +23,8 @@ #include #include "psppire-data-store.h" +#include +#include #include "helper.h" #include @@ -200,6 +202,23 @@ enum #define WIDTH_OF_M 10 +#define DEFAULT_ROW_HEIGHT 25 + +static void +new_data_callback (PsppireDataStore *ds, gpointer data) +{ + PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data); + gint i; + for (i = 0 ; i < 4 ; ++i) + { + PsppireAxisUniform *vaxis; + casenumber n_cases = psppire_case_file_get_case_count (ds->case_file); + + g_object_get (de->data_sheet[i], "vertical-axis", &vaxis, NULL); + + psppire_axis_uniform_set_count (vaxis, n_cases); + } +} static void new_variables_callback (PsppireDict *dict, gpointer data) @@ -207,18 +226,26 @@ new_variables_callback (PsppireDict *dict, gpointer data) gint v, i; PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data); + PsppireAxisHetero *vaxis; + g_object_get (de->var_sheet, "vertical-axis", &vaxis, NULL); + + psppire_axis_hetero_clear (vaxis); + + for (v = 0 ; v < psppire_dict_get_var_cnt (dict); ++v) + psppire_axis_hetero_append (vaxis, DEFAULT_ROW_HEIGHT); + for (i = 0 ; i < 4 ; ++i) { - PsppireAxis *haxis; + PsppireAxisHetero *haxis; g_object_get (de->data_sheet[i], "horizontal-axis", &haxis, NULL); - psppire_axis_clear (haxis); + psppire_axis_hetero_clear (haxis); for (v = 0 ; v < psppire_dict_get_var_cnt (dict); ++v) { const struct variable *var = psppire_dict_get_variable (dict, v); - psppire_axis_append (haxis, 10 * var_get_display_width (var)); + psppire_axis_hetero_append (haxis, 10 * var_get_display_width (var)); } } } @@ -229,29 +256,40 @@ insert_variable_callback (PsppireDict *dict, gint x, gpointer data) gint i; PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data); + PsppireAxisHetero *var_vaxis; + g_object_get (de->var_sheet, "vertical-axis", &var_vaxis, NULL); + + psppire_axis_hetero_insert (var_vaxis, DEFAULT_ROW_HEIGHT, x); + for (i = 0 ; i < 4 ; ++i) { const struct variable *var = psppire_dict_get_variable (dict, x); - PsppireAxis *haxis; + PsppireAxisHetero *haxis; g_object_get (de->data_sheet[i], "horizontal-axis", &haxis, NULL); - psppire_axis_insert (haxis, WIDTH_OF_M * var_get_display_width (var), x); + psppire_axis_hetero_insert (haxis, WIDTH_OF_M * var_get_display_width (var), x); } } static void -delete_variable_callback (PsppireDict *dict, gint posn, gint x UNUSED, gint y UNUSED, gpointer data) +delete_variable_callback (PsppireDict *dict, gint posn, + gint x UNUSED, gint y UNUSED, gpointer data) { gint i; PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data); + PsppireAxisHetero *var_vaxis; + g_object_get (de->var_sheet, "vertical-axis", &var_vaxis, NULL); + + psppire_axis_hetero_remove (var_vaxis, posn); + for (i = 0 ; i < 4 ; ++i) { - PsppireAxis *haxis; + PsppireAxisHetero *haxis; g_object_get (de->data_sheet[i], "horizontal-axis", &haxis, NULL); - psppire_axis_remove (haxis, posn); + psppire_axis_hetero_remove (haxis, posn); } } @@ -265,10 +303,12 @@ rewidth_variable_callback (PsppireDict *dict, gint posn, gpointer data) for (i = 0 ; i < 4 ; ++i) { const struct variable *var = psppire_dict_get_variable (dict, posn); - PsppireAxis *haxis; + PsppireAxisHetero *haxis; g_object_get (de->data_sheet[i], "horizontal-axis", &haxis, NULL); - psppire_axis_resize_unit (haxis, WIDTH_OF_M * var_get_display_width (var), posn); + psppire_axis_hetero_resize_unit (haxis, + WIDTH_OF_M * + var_get_display_width (var), posn); } } @@ -294,7 +334,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, "model", de->data_store, NULL); @@ -302,6 +341,8 @@ psppire_data_editor_set_property (GObject *object, g_signal_connect (de->data_store->dict, "variable-inserted", G_CALLBACK (insert_variable_callback), de); g_signal_connect (de->data_store->dict, "variable-deleted", G_CALLBACK (delete_variable_callback), de); g_signal_connect (de->data_store->dict, "variable-display-width-changed", G_CALLBACK (rewidth_variable_callback), de); + + g_signal_connect (de->data_store, "backend-changed", G_CALLBACK (new_data_callback), de); break; case PROP_VAR_STORE: if ( de->var_store) g_object_unref (de->var_store); @@ -309,7 +350,6 @@ psppire_data_editor_set_property (GObject *object, g_object_ref (de->var_store); g_object_set (de->var_sheet, - "row-geometry", de->var_store, "model", de->var_store, NULL); break; @@ -691,7 +731,8 @@ static void init_sheet (PsppireDataEditor *de, int i, GtkAdjustment *hadj, GtkAdjustment *vadj) { - PsppireAxis *haxis = psppire_axis_new (); + PsppireAxisHetero *haxis = psppire_axis_hetero_new (); + PsppireAxisUniform *vaxis = psppire_axis_uniform_new (); de->sheet_bin[i] = gtk_scrolled_window_new (hadj, vadj); de->data_sheet[i] = gtk_sheet_new (NULL, NULL, NULL); @@ -701,8 +742,12 @@ init_sheet (PsppireDataEditor *de, int i, "shadow-type", GTK_SHADOW_ETCHED_IN, NULL); + g_object_set (haxis, "default-size", 75, NULL); + g_object_set (vaxis, "default-size", 25, NULL); + g_object_set (de->data_sheet[i], "horizontal-axis", haxis, + "vertical-axis", vaxis, NULL); gtk_container_add (GTK_CONTAINER (de->sheet_bin[i]), de->data_sheet[i]); diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 9835d307..f3c22337 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -26,7 +26,6 @@ #include #include -#include #include @@ -44,7 +43,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_row_init (GSheetRowIface *iface); static void psppire_data_store_finalize (GObject *object); static void psppire_data_store_dispose (GObject *object); @@ -53,13 +51,11 @@ static gboolean psppire_data_store_clear_datum (GSheetModel *model, glong row, glong column); -#define MIN_COLUMNS 10 -#define TRAILING_ROWS 10 - static GObjectClass *parent_class = NULL; enum {FONT_CHANGED, + BACKEND_CHANGED, n_SIGNALS}; static guint signals [n_SIGNALS]; @@ -92,13 +88,6 @@ psppire_data_store_get_type (void) NULL }; - static const GInterfaceInfo sheet_row_info = - { - (GInterfaceInitFunc) psppire_data_store_sheet_row_init, - NULL, - NULL - }; - data_store_type = g_type_register_static (G_TYPE_OBJECT, "PsppireDataStore", &data_store_info, 0); @@ -107,9 +96,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_ROW, - &sheet_row_info); } return data_store_type; @@ -136,6 +122,17 @@ psppire_data_store_class_init (PsppireDataStoreClass *class) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + + signals [BACKEND_CHANGED] = + g_signal_new ("backend-changed", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); } @@ -209,6 +206,9 @@ 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 gchar * get_row_button_label (const GSheetModel *model, gint row); +static gboolean get_row_sensitivity (const GSheetModel *model, gint row); + static void psppire_data_store_sheet_model_init (GSheetModelIface *iface) @@ -230,6 +230,9 @@ psppire_data_store_sheet_model_init (GSheetModelIface *iface) iface->get_column_title = get_column_button_label; iface->get_column_sensitivity = get_column_sensitivity; iface->get_column_justification = get_column_justification; + + iface->get_row_title = get_row_button_label; + iface->get_row_sensitivity = get_row_sensitivity; } static void @@ -251,11 +254,11 @@ delete_cases_callback (GtkWidget *w, static void insert_case_callback (GtkWidget *w, casenumber casenum, gpointer data) { - PsppireDataStore *store ; + PsppireDataStore *store = PSPPIRE_DATA_STORE (data); g_return_if_fail (data); - store = PSPPIRE_DATA_STORE (data); + g_print ("%s\n", __FUNCTION__); g_sheet_model_range_changed (G_SHEET_MODEL (store), casenum, -1, @@ -394,8 +397,6 @@ psppire_data_store_set_case_file (PsppireDataStore *ds, { gint i; if ( ds->case_file) g_object_unref (ds->case_file); - - ds->case_file = cf; g_sheet_model_range_changed (G_SHEET_MODEL (ds), @@ -433,6 +434,8 @@ psppire_data_store_set_case_file (PsppireDataStore *ds, g_signal_connect (ds->case_file, "case-changed", G_CALLBACK (changed_case_callback), ds); + + g_signal_emit (ds, signals[BACKEND_CHANGED], 0); } @@ -764,109 +767,21 @@ psppire_data_store_get_reader (PsppireDataStore *ds) /* Column related funcs */ -#if AXIS_TRANSITION -static glong -geometry_get_column_count (const GSheetColumn *geom) -{ - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - return MAX (MIN_COLUMNS, psppire_dict_get_var_cnt (ds->dict)); -} - - - -static gint -geometry_get_width (const GSheetColumn *geom, glong unit) -{ - const struct variable *pv ; - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - if ( unit >= psppire_dict_get_var_cnt (ds->dict) ) - return ds->width_of_m * 8 ; - - pv = psppire_dict_get_variable (ds->dict, unit); - - if ( pv == NULL ) - return ds->width_of_m * 8 ; - - return ds->width_of_m * var_get_display_width (pv); -} - -static void -geometry_set_width (GSheetColumn *geom, glong unit, gint width) -{ - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - struct variable *v = psppire_dict_get_variable (ds->dict, unit); - - g_return_if_fail (v); - - var_set_display_width (v, width / ds->width_of_m ); -} - -#endif - static const gchar null_var_name[]=N_("var"); + /* Row related funcs */ -static glong -geometry_get_row_count (const GSheetRow *geom) -{ - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - return TRAILING_ROWS + psppire_case_file_get_case_count (ds->case_file); -} - -#define ROW_HEIGHT 25 - -static gint -geometry_get_height (const GSheetRow *geom, glong unit) -{ - return ROW_HEIGHT; -} - -static guint -geometry_get_top_ypixel (const GSheetRow *geo, glong row) -{ - return row * ROW_HEIGHT; -} - -static glong -geometry_pixel_to_row (const GSheetRow *geo, guint pixel) -{ - glong row = pixel / ROW_HEIGHT; - - if (row >= geometry_get_row_count (geo)) - row = geometry_get_row_count (geo) - 1; - - return row; -} - - -static gboolean -geometry_get_row_sensitivity (const GSheetRow *geom, glong unit) -{ - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - - return (unit < psppire_case_file_get_case_count (ds->case_file)); -} - static gchar * -geometry_get_row_button_label (const GSheetRow *geom, glong unit) +get_row_button_label (const GSheetModel *model, gint unit) { gchar *text; gchar *s; - PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom); - - if ( unit > - TRAILING_ROWS + psppire_case_file_get_case_count (ds->case_file)) - return 0; + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); - s = g_strdup_printf (_("%ld"), unit + FIRST_CASE_NUMBER); + s = g_strdup_printf (_("%d"), unit + 1); text = pspp_locale_to_utf8 (s, -1, 0); @@ -875,17 +790,13 @@ geometry_get_row_button_label (const GSheetRow *geom, glong unit) return text; } -static void -psppire_data_store_sheet_row_init (GSheetRowIface *iface) + +static gboolean +get_row_sensitivity (const GSheetModel *model, gint unit) { - iface->get_row_count = geometry_get_row_count; + PsppireDataStore *ds = PSPPIRE_DATA_STORE (model); - iface->get_height = geometry_get_height; - iface->set_height = 0; - iface->get_sensitivity = geometry_get_row_sensitivity; - iface->top_ypixel = geometry_get_top_ypixel; - iface->pixel_to_row = geometry_pixel_to_row; - iface->get_button_label = geometry_get_row_button_label; + return (unit < psppire_case_file_get_case_count (ds->case_file)); } diff --git a/src/ui/gui/psppire-var-sheet.c b/src/ui/gui/psppire-var-sheet.c index 03365202..493fd05c 100644 --- a/src/ui/gui/psppire-var-sheet.c +++ b/src/ui/gui/psppire-var-sheet.c @@ -16,6 +16,7 @@ #include #include "psppire-var-sheet.h" +#include #include #include "helper.h" @@ -483,12 +484,9 @@ var_sheet_change_active_cell (PsppireVarSheet *vs, } - - static void psppire_var_sheet_init (PsppireVarSheet *vs) { - // gint i; GladeXML *xml = XML_NEW ("data-editor.glade"); vs->val_labs_dialog = val_labs_dialog_create (xml); @@ -500,14 +498,6 @@ 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_width (G_SHEET_HETERO_COLUMN (geo), i, - column_def[i].width); - } -#endif - g_signal_connect (vs, "activate", G_CALLBACK (var_sheet_change_active_cell), NULL); @@ -534,14 +524,25 @@ GtkWidget* psppire_var_sheet_new (void) { gint i; - PsppireAxis *a = psppire_axis_new (); + PsppireAxisHetero *ha = psppire_axis_hetero_new (); + PsppireAxisHetero *va = psppire_axis_hetero_new (); + 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); + psppire_axis_hetero_append (ha, column_def[i].width); + + + g_object_set (va, + "default-size", 25, + NULL); + + g_object_set (ha, "minimum-extent", 0, + NULL); g_object_set (w, - "horizontal-axis", a, + "horizontal-axis", ha, + "vertical-axis", va, NULL); return w; diff --git a/src/ui/gui/psppire-var-store.c b/src/ui/gui/psppire-var-store.c index 4575bd3b..1f963cab 100644 --- a/src/ui/gui/psppire-var-store.c +++ b/src/ui/gui/psppire-var-store.c @@ -28,7 +28,6 @@ #include #include "psppire-var-store.h" -#include #include "helper.h" #include @@ -71,10 +70,6 @@ static glong psppire_var_store_get_column_count (const GSheetModel * model); static gchar *text_for_column (const struct variable *pv, gint c, GError **err); -static void psppire_var_store_sheet_row_init (GSheetRowIface *iface); - - - static GObjectClass *parent_class = NULL; GType @@ -128,24 +123,11 @@ psppire_var_store_get_type (void) NULL }; - static const GInterfaceInfo sheet_row_info = - { - (GInterfaceInitFunc) psppire_var_store_sheet_row_init, - NULL, - NULL - }; - var_store_type = g_type_register_static (G_TYPE_OBJECT, "PsppireVarStore", &var_store_info, 0); g_type_add_interface_static (var_store_type, G_TYPE_SHEET_MODEL, &sheet_model_info); - - g_type_add_interface_static (var_store_type, - G_TYPE_SHEET_ROW, - &sheet_row_info); - - } return var_store_type; @@ -328,8 +310,9 @@ psppire_var_store_get_font_desc (const GSheetModel *model, return store->font_desc; } - static gchar *get_column_title (const GSheetModel *model, gint col); +static gchar *get_row_title (const GSheetModel *model, gint row); +static gboolean get_row_sensitivity (const GSheetModel *model, gint row); static void psppire_var_store_sheet_model_init (GSheetModelIface *iface) @@ -349,6 +332,9 @@ psppire_var_store_sheet_model_init (GSheetModelIface *iface) iface->get_justification = NULL; iface->get_column_title = get_column_title; + + iface->get_row_title = get_row_title; + iface->get_row_sensitivity = get_row_sensitivity; } /** @@ -793,33 +779,15 @@ psppire_var_store_get_column_count (const GSheetModel * model) return PSPPIRE_VAR_STORE_n_COLS ; } + /* Row related funcs */ -static glong -geometry_get_row_count (const GSheetRow *geom) -{ - gint rows = 0; - PsppireVarStore *vs = PSPPIRE_VAR_STORE (geom); - - if (vs->dict) - rows = psppire_dict_get_var_cnt (vs->dict); - - return rows + vs->trailing_rows; -} - - -static gint -geometry_get_height (const GSheetRow *geom, glong row) -{ - return 25; -} - static gboolean -geometry_is_sensitive (const GSheetRow *geom, glong row) +get_row_sensitivity (const GSheetModel *model, gint row) { - PsppireVarStore *vs = PSPPIRE_VAR_STORE (geom); + PsppireVarStore *vs = PSPPIRE_VAR_STORE (model); if ( ! vs->dict) return FALSE; @@ -827,23 +795,11 @@ geometry_is_sensitive (const GSheetRow *geom, glong row) return row < psppire_dict_get_var_cnt (vs->dict); } -static gchar * -geometry_get_button_label (const GSheetRow *geom, glong unit) -{ - gchar *label = g_strdup_printf (_("%ld"), unit + 1); - return label; -} - -static void -psppire_var_store_sheet_row_init (GSheetRowIface *iface) +static gchar * +get_row_title (const GSheetModel *model, gint unit) { - iface->get_row_count = geometry_get_row_count; - iface->get_height = geometry_get_height; - iface->set_height = NULL; - iface->get_sensitivity = geometry_is_sensitive; - - iface->get_button_label = geometry_get_button_label; + return g_strdup_printf (_("%d"), unit + 1); }