[gtk+/gtk-2-24] Add accessors for GtkRange::round-digits



commit dfa1ea8245ddfd7371826432b0be34f1f686543e
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jan 15 00:26:08 2011 -0500

    Add accessors for GtkRange::round-digits
    
        Patch by Christian Dywan,
        https://bugzilla.gnome.org/show_bug.cgi?id=351755

 docs/reference/gtk/gtk-sections.txt |    4 +-
 gtk/gtk.symbols                     |    2 +
 gtk/gtkrange.c                      |   72 +++++++++++++++++++++++++++++++++-
 gtk/gtkrange.h                      |    4 ++
 4 files changed, 78 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt
index 3dc22cf..76c6a7f 100644
--- a/docs/reference/gtk/gtk-sections.txt
+++ b/docs/reference/gtk/gtk-sections.txt
@@ -3138,10 +3138,12 @@ gtk_range_set_adjustment
 gtk_range_get_inverted
 gtk_range_set_inverted
 gtk_range_get_update_policy
-gtk_range_get_value
 gtk_range_set_increments
 gtk_range_set_range
+gtk_range_get_value
 gtk_range_set_value
+gtk_range_get_round_digits
+gtk_range_set_round_digits
 GtkSensitivityType
 gtk_range_set_lower_stepper_sensitivity
 gtk_range_get_lower_stepper_sensitivity
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 566283e..6d5d5b6 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -3431,6 +3431,8 @@ gtk_range_set_update_policy
 #endif
 gtk_range_set_upper_stepper_sensitivity
 gtk_range_set_value
+gtk_range_set_round_digits
+gtk_range_get_round_digits
 #endif
 #endif
 
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 664d387..aba2d6e 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -56,7 +56,8 @@ enum {
   PROP_UPPER_STEPPER_SENSITIVITY,
   PROP_SHOW_FILL_LEVEL,
   PROP_RESTRICT_TO_FILL_LEVEL,
-  PROP_FILL_LEVEL
+  PROP_FILL_LEVEL,
+  PROP_ROUND_DIGITS
 };
 
 enum {
@@ -339,8 +340,8 @@ gtk_range_class_init (GtkRangeClass *class)
    *
    * The value parameter is unrounded.  An application that overrides
    * the ::change-value signal is responsible for clamping the value to
-   * the desired number of decimal digits; the default GTK+ handler 
-   * clamps the value based on @range->round_digits.
+   * the desired number of decimal digits; the default GTK+ handler
+   * clamps the value based on #GtkRange:round_digits.
    *
    * It is not possible to use delayed update policies in an overridden
    * ::change-value handler.
@@ -457,6 +458,24 @@ gtk_range_class_init (GtkRangeClass *class)
                                                         G_MAXDOUBLE,
                                                         GTK_PARAM_READWRITE));
 
+  /**
+   * GtkRange:round-digits:
+   *
+   * The number of digits to round the value to when
+   * it changes, or -1. See #GtkRange::change-value.
+   *
+   * Since: 2.24
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_ROUND_DIGITS,
+                                   g_param_spec_int ("round-digits",
+                                                     P_("Round Digits"),
+                                                     P_("The number of digits to round the value to."),
+                                                     -1,
+                                                     G_MAXINT,
+                                                     -1,
+                                                     GTK_PARAM_READWRITE));
+
   gtk_widget_class_install_style_property (widget_class,
 					   g_param_spec_int ("slider-width",
 							     P_("Slider Width"),
@@ -642,6 +661,9 @@ gtk_range_set_property (GObject      *object,
     case PROP_FILL_LEVEL:
       gtk_range_set_fill_level (range, g_value_get_double (value));
       break;
+    case PROP_ROUND_DIGITS:
+      gtk_range_set_round_digits (range, g_value_get_int (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -685,6 +707,9 @@ gtk_range_get_property (GObject      *object,
     case PROP_FILL_LEVEL:
       g_value_set_double (value, gtk_range_get_fill_level (range));
       break;
+    case PROP_ROUND_DIGITS:
+      g_value_set_int (value, gtk_range_get_round_digits (range));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -3935,5 +3960,46 @@ _gtk_range_get_stop_positions (GtkRange  *range,
   return range->layout->n_marks;
 }
 
+/**
+ * gtk_range_set_round_digits:
+ * @range: a #GtkRange
+ * @round_digits: the precision in digits, or -1
+ *
+ * Sets the number of digits to round the value to when
+ * it changes. See #GtkRange::change-value.
+ *
+ * Since: 2.24
+ */
+gtk_range_set_round_digits (GtkRange *range,
+                            gint      round_digits)
+{
+  g_return_if_fail (GTK_IS_RANGE (range));
+  g_return_if_fail (round_digits >= -1);
+
+  range->round_digits = round_digits;
+
+  g_object_notify (G_OBJECT (range), "round-digits");
+}
+
+/**
+ * gtk_range_get_round_digits:
+ * @range: a #GtkRange
+ *
+ * Gets the number of digits to round the value to when
+ * it changes. See #GtkRange::change-value.
+ *
+ * Return value: the number of digits to round to
+ *
+ * Since: 2.24
+ */
+gint
+gtk_range_get_round_digits (GtkRange *range)
+{
+  g_return_val_if_fail (GTK_IS_RANGE (range), -1);
+
+  return range->round_digits;
+}
+
+
 #define __GTK_RANGE_C__
 #include "gtkaliasdef.c"
diff --git a/gtk/gtkrange.h b/gtk/gtkrange.h
index 04bfda1..a708879 100644
--- a/gtk/gtkrange.h
+++ b/gtk/gtkrange.h
@@ -193,6 +193,10 @@ gboolean           gtk_range_get_restrict_to_fill_level    (GtkRange      *range
 void               gtk_range_set_fill_level                (GtkRange      *range,
                                                             gdouble        fill_level);
 gdouble            gtk_range_get_fill_level                (GtkRange      *range);
+void               gtk_range_set_round_digits              (GtkRange      *range,
+                                                            gint           round_digits);
+gint                gtk_range_get_round_digits             (GtkRange      *range);
+
 
 /* internal API */
 gdouble            _gtk_range_get_wheel_delta              (GtkRange      *range,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]