From d8ab2332521e3934c07eec2bb727920e66f293e8 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 25 Nov 2008 10:01:48 +0900 Subject: [PATCH] Added "min-extent" and "default-size" properties. Before rows/columns have been added, which are sufficient to cover "min-extent", there will be implicit rows/columns of "default-size". --- lib/gtksheet/psppire-axis.c | 110 +++++++++++++++++++++++++++++++++--- lib/gtksheet/psppire-axis.h | 4 +- 2 files changed, 106 insertions(+), 8 deletions(-) diff --git a/lib/gtksheet/psppire-axis.c b/lib/gtksheet/psppire-axis.c index c83c6b46..4a8de3e8 100644 --- a/lib/gtksheet/psppire-axis.c +++ b/lib/gtksheet/psppire-axis.c @@ -65,20 +65,102 @@ psppire_axis_get_type (void) return object_type; } +enum + { + PROP_0, + PROP_MIN_EXTENT, + PROP_DEFAULT_SIZE + }; + + +static void +psppire_axis_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PsppireAxis *axis = PSPPIRE_AXIS (object); + + switch (prop_id) + { + case PROP_MIN_EXTENT: + g_value_set_long (value, axis->min_extent); + break; + case PROP_DEFAULT_SIZE: + g_value_set_int (value, axis->default_size); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + }; +} + + +static void +psppire_axis_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PsppireAxis *axis = PSPPIRE_AXIS (object); + + switch (prop_id) + { + case PROP_MIN_EXTENT: + axis->min_extent = g_value_get_long (value); + break; + case PROP_DEFAULT_SIZE: + axis->default_size = g_value_get_int (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + }; +} static void psppire_axis_class_init (PsppireAxisClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); + GParamSpec *min_extent_spec; + GParamSpec *default_size_spec; + + object_class->set_property = psppire_axis_set_property; + object_class->get_property = psppire_axis_get_property; + + min_extent_spec = + g_param_spec_pointer ("minimum-extent", + "Minimum Extent", + "The smallest extent to which the axis will provide units (typically set to the height/width of the associated widget)", + G_PARAM_WRITABLE | G_PARAM_READABLE ); + + g_object_class_install_property (object_class, + PROP_MIN_EXTENT, + min_extent_spec); + + + 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_object_class_install_property (object_class, + PROP_DEFAULT_SIZE, + default_size_spec); parent_class = g_type_class_peek_parent (class); object_class->finalize = psppire_axis_finalize; } + static void psppire_axis_init (PsppireAxis *axis) { + axis->min_extent = 800; + axis->default_size = 75; axis->pool = NULL; psppire_axis_clear (axis); } @@ -110,7 +192,7 @@ psppire_axis_unit_size (PsppireAxis *a, gint unit) { const struct tower_node *node; if (unit >= tower_count (&a->tower)) - return 0; + return a->default_size; node = tower_get (&a->tower, unit); @@ -120,22 +202,34 @@ psppire_axis_unit_size (PsppireAxis *a, gint unit) gint psppire_axis_unit_count (PsppireAxis *a) { - return tower_count (&a->tower); + glong padding = 0; + + if ( tower_height (&a->tower) < a->min_extent ) + padding = (a->min_extent - tower_height (&a->tower)) + / a->default_size; + + return tower_count (&a->tower) + padding; } + +/* Return the starting pixel of UNIT */ glong psppire_axis_pixel_start (PsppireAxis *a, gint unit) { const struct tower_node *node; if ( unit >= tower_count (&a->tower)) - return tower_height (&a->tower); + { + return tower_height (&a->tower) + + (unit - tower_count (&a->tower)) * a->default_size; + } 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) { @@ -143,11 +237,14 @@ psppire_axis_get_unit_at_pixel (PsppireAxis *a, glong pixel) unsigned long int node_start; if (pixel >= tower_height (&a->tower)) - return tower_count (&a->tower); + { + glong extra = pixel - tower_height (&a->tower); + return tower_count (&a->tower) + extra / a->default_size; + } node = tower_lookup (&a->tower, pixel, &node_start); - return tower_node_get_index (node); + return tower_node_get_index (node); } void @@ -195,7 +292,6 @@ psppire_axis_resize_unit (PsppireAxis *a, gint size, gint posn) } - void psppire_axis_clear (PsppireAxis *a) { diff --git a/lib/gtksheet/psppire-axis.h b/lib/gtksheet/psppire-axis.h index 72484773..ef4b2908 100644 --- a/lib/gtksheet/psppire-axis.h +++ b/lib/gtksheet/psppire-axis.h @@ -49,12 +49,14 @@ struct _PsppireAxis struct tower tower; struct pool *pool; + + glong min_extent; + gint default_size; }; struct _PsppireAxisClass { GObjectClass parent_class; - }; GType psppire_axis_get_type (void); -- 2.30.2