Added "min-extent" and "default-size" properties.
authorJohn Darrington <john@darrington.wattle.id.au>
Tue, 25 Nov 2008 01:01:48 +0000 (10:01 +0900)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 25 Nov 2008 01:01:48 +0000 (10:01 +0900)
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
lib/gtksheet/psppire-axis.h

index c83c6b46e9b18d487d3a15d3b335f64dccee146f..4a8de3e88508dd55ae73125eb6a31a41d121c459 100644 (file)
@@ -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)
 {
index 72484773e895c88767b794887e065609440b46a6..ef4b2908ab0f99b35954d5ebb3e879102c745bef 100644 (file)
@@ -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);