[gimp] libgimp, libgimpwidgets: fix gimp_prop_scale_entry_new() for integer…



commit b7d55fa0665b1e36f155aa18a5ab0905c1b19077
Author: Jehan <jehan girinstud io>
Date:   Thu Nov 26 00:27:43 2020 +0100

    libgimp, libgimpwidgets: fix gimp_prop_scale_entry_new() for integer…
    
    … properties.
    Also a forgotten fix in a call of this function in GimpProcedureDialog.

 libgimp/gimpproceduredialog.c    |  2 +-
 libgimpwidgets/gimppropwidgets.c | 45 ++++++++++++++++++++++++++++------------
 2 files changed, 33 insertions(+), 14 deletions(-)
---
diff --git a/libgimp/gimpproceduredialog.c b/libgimp/gimpproceduredialog.c
index 54f09ea0ed..3b5c4166cd 100644
--- a/libgimp/gimpproceduredialog.c
+++ b/libgimp/gimpproceduredialog.c
@@ -462,7 +462,7 @@ gimp_procedure_dialog_get_widget (GimpProcedureDialog *dialog,
           widget = gimp_prop_scale_entry_new (G_OBJECT (dialog->priv->config),
                                               property,
                                               _(g_param_spec_get_nick (pspec)),
-                                              digits, FALSE, 0.0, 0.0);
+                                              1.0, FALSE, 0.0, 0.0);
         }
       else if (widget_type == GIMP_TYPE_SPIN_BUTTON)
         {
diff --git a/libgimpwidgets/gimppropwidgets.c b/libgimpwidgets/gimppropwidgets.c
index f92b4f0152..adbefe22e8 100644
--- a/libgimpwidgets/gimppropwidgets.c
+++ b/libgimpwidgets/gimppropwidgets.c
@@ -1523,6 +1523,8 @@ gimp_prop_hscale_new (GObject     *config,
  * @factor:         Optional multiplier to convert @property_name's
  *                  range into the #GimpScaleEntry's range. The common
  *                  usage is to set 1.0.
+ *                  For non-double properties, no other values than 1.0
+ *                  are acceptable.
  * @limit_scale:    %FALSE if the range of possible values of the
  *                  GtkHScale should be the same as of the GtkSpinButton.
  * @lower_limit:    The scale's lower boundary if @scale_limits is %TRUE.
@@ -1560,10 +1562,10 @@ gimp_prop_scale_entry_new (GObject     *config,
   GtkWidget   *widget;
   GParamSpec  *param_spec;
   const gchar *tooltip;
-  gdouble     *user_data;
   gdouble      value;
   gdouble      lower;
   gdouble      upper;
+  gint         digits = -1;
 
   g_return_val_if_fail (factor != 0.0, NULL);
 
@@ -1571,6 +1573,8 @@ gimp_prop_scale_entry_new (GObject     *config,
   if (! param_spec)
     return NULL;
 
+  g_return_val_if_fail (G_IS_PARAM_SPEC_DOUBLE (param_spec) || factor == 1.0, NULL);
+
   if (! get_numeric_values (config,
                             param_spec, &value, &lower, &upper, G_STRFUNC))
     return NULL;
@@ -1578,7 +1582,10 @@ gimp_prop_scale_entry_new (GObject     *config,
   if (! label)
     label = g_param_spec_get_nick (param_spec);
 
-  widget = gimp_scale_entry_new (label, value, lower * factor, upper * factor, -1);
+  if (G_IS_PARAM_SPEC_INT (param_spec) || G_IS_PARAM_SPEC_UINT (param_spec))
+    digits = 0;
+
+  widget = gimp_scale_entry_new (label, value, lower * factor, upper * factor, digits);
   if (limit_scale)
     gimp_scale_entry_set_bounds (GIMP_SCALE_ENTRY (widget),
                                  lower_limit, upper_limit,
@@ -1587,17 +1594,29 @@ gimp_prop_scale_entry_new (GObject     *config,
   tooltip = g_param_spec_get_blurb (param_spec);
   gimp_help_set_help_data (widget, tooltip, NULL);
 
-  user_data = g_new0 (gdouble, 1);
-  *user_data = factor;
-  /* With @factor == 1.0, this is equivalent to a
-   * g_object_bind_property().
-   */
-  g_object_bind_property_full (config, property_name,
-                               widget, "value",
-                               G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
-                               gimp_prop_widget_double_to_factor,
-                               gimp_prop_widget_double_from_factor,
-                               user_data, (GDestroyNotify) g_free);
+  if (factor != 1.0)
+    {
+      gdouble *user_data;
+
+      user_data = g_new0 (gdouble, 1);
+      *user_data = factor;
+      /* With @factor == 1.0, this is equivalent to a
+       * g_object_bind_property().
+       */
+      g_object_bind_property_full (config, property_name,
+                                   widget, "value",
+                                   G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
+                                   gimp_prop_widget_double_to_factor,
+                                   gimp_prop_widget_double_from_factor,
+                                   user_data, (GDestroyNotify) g_free);
+    }
+  else
+    {
+      g_object_bind_property (config, property_name,
+                              widget, "value",
+                              G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+    }
 
   return widget;
 }


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