libgimp: Fix critical for int SpinScale API

The GimpProcedureDialog API allows int and double  SpinScales. However,
it calls gimp_prop_widget_set_factor () which requires doubles.
A conditional check for a double property was added to this call.
A check was also added to ensure int properties have a factor of 1.0.
This commit is contained in:
Alx Sa 2023-04-14 20:44:00 +00:00
parent f785f18892
commit 7c72202416

View file

@ -1072,6 +1072,7 @@ gimp_procedure_dialog_get_int_radio (GimpProcedureDialog *dialog,
* #GimpSpinScale for. It must be a property of the * #GimpSpinScale for. It must be a property of the
* #GimpProcedure @dialog has been created for. * #GimpProcedure @dialog has been created for.
* @factor: a display factor for the range shown by the widget. * @factor: a display factor for the range shown by the widget.
* It must be set to 1.0 for integer properties.
* *
* Creates a new #GimpSpinScale for @property which must necessarily be * Creates a new #GimpSpinScale for @property which must necessarily be
* an integer or double property. * an integer or double property.
@ -1112,8 +1113,9 @@ gimp_procedure_dialog_get_spin_scale (GimpProcedureDialog *dialog,
return NULL; return NULL;
} }
g_return_val_if_fail (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT || g_return_val_if_fail (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_DOUBLE ||
G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_DOUBLE, NULL); (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT &&
factor == 1.0), NULL);
/* First check if it already exists. */ /* First check if it already exists. */
widget = g_hash_table_lookup (dialog->priv->widgets, property); widget = g_hash_table_lookup (dialog->priv->widgets, property);
@ -1139,7 +1141,8 @@ gimp_procedure_dialog_get_spin_scale (GimpProcedureDialog *dialog,
widget = gimp_prop_spin_scale_new (G_OBJECT (dialog->priv->config), widget = gimp_prop_spin_scale_new (G_OBJECT (dialog->priv->config),
property, step, page, digits); property, step, page, digits);
gimp_prop_widget_set_factor (widget, factor, step, page, digits); if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_DOUBLE)
gimp_prop_widget_set_factor (widget, factor, step, page, digits);
gimp_procedure_dialog_check_mnemonic (dialog, widget, property, NULL); gimp_procedure_dialog_check_mnemonic (dialog, widget, property, NULL);
g_hash_table_insert (dialog->priv->widgets, g_strdup (property), widget); g_hash_table_insert (dialog->priv->widgets, g_strdup (property), widget);
@ -1858,7 +1861,6 @@ gimp_procedure_dialog_fill_expander (GimpProcedureDialog *dialog,
return expander; return expander;
} }
/** /**
* gimp_procedure_dialog_fill_scrolled_window: * gimp_procedure_dialog_fill_scrolled_window:
* @dialog: the #GimpProcedureDialog. * @dialog: the #GimpProcedureDialog.