app: enable adjustment based prop widgets for all numeric param types

This commit is contained in:
Michael Natterer 2010-11-01 21:48:19 +01:00
parent fc0e19022e
commit 8bf497294e

View file

@ -70,6 +70,13 @@ static GParamSpec * check_param_spec_w (GObject *object,
GType type,
const gchar *strloc);
static gboolean get_numeric_values (GObject *object,
GParamSpec *param_spec,
gdouble *value,
gdouble *lower,
gdouble *upper,
const gchar *strloc);
static void connect_notify (GObject *config,
const gchar *property_name,
GCallback callback,
@ -443,13 +450,13 @@ gimp_prop_scale_button_notify (GObject *config,
}
/****************/
/* spin scale */
/****************/
/*****************/
/* adjustments */
/*****************/
static void gimp_prop_spin_scale_callback (GtkAdjustment *adjustment,
static void gimp_prop_adjustment_callback (GtkAdjustment *adjustment,
GObject *config);
static void gimp_prop_spin_scale_notify (GObject *config,
static void gimp_prop_adjustment_notify (GObject *config,
GParamSpec *param_spec,
GtkAdjustment *adjustment);
@ -477,20 +484,21 @@ gimp_prop_spin_scale_new (GObject *config,
GtkObject *adjustment;
GtkWidget *scale;
gdouble value;
gdouble lower;
gdouble upper;
param_spec = check_param_spec_w (config, property_name,
G_TYPE_PARAM_DOUBLE, G_STRFUNC);
param_spec = find_param_spec (config, property_name, G_STRFUNC);
if (! param_spec)
return NULL;
g_object_get (config,
param_spec->name, &value,
NULL);
if (! get_numeric_values (config,
param_spec, &value, &lower, &upper, G_STRFUNC))
return NULL;
adjustment = gtk_adjustment_new (value,
G_PARAM_SPEC_DOUBLE (param_spec)->minimum,
G_PARAM_SPEC_DOUBLE (param_spec)->maximum,
if (! G_IS_PARAM_SPEC_DOUBLE (param_spec))
digits = 0;
adjustment = gtk_adjustment_new (value, lower, upper,
step_increment, page_increment, 0.0);
scale = gimp_spin_scale_new (GTK_ADJUSTMENT (adjustment), label, digits);
@ -498,59 +506,161 @@ gimp_prop_spin_scale_new (GObject *config,
set_param_spec (G_OBJECT (adjustment), scale, param_spec);
g_signal_connect (adjustment, "value-changed",
G_CALLBACK (gimp_prop_spin_scale_callback),
G_CALLBACK (gimp_prop_adjustment_callback),
config);
connect_notify (config, property_name,
G_CALLBACK (gimp_prop_spin_scale_notify),
G_CALLBACK (gimp_prop_adjustment_notify),
adjustment);
return scale;
}
static void
gimp_prop_spin_scale_callback (GtkAdjustment *adjustment,
gimp_prop_adjustment_callback (GtkAdjustment *adjustment,
GObject *config)
{
GParamSpec *param_spec;
gdouble value;
param_spec = get_param_spec (G_OBJECT (adjustment));
if (! param_spec)
return;
g_signal_handlers_block_by_func (config,
gimp_prop_spin_scale_notify,
adjustment);
value = gtk_adjustment_get_value (adjustment);
g_object_set (config,
param_spec->name, gtk_adjustment_get_value (adjustment),
NULL);
if (G_IS_PARAM_SPEC_INT (param_spec))
{
g_object_set (config,
param_spec->name, (gint) value,
NULL);
}
else if (G_IS_PARAM_SPEC_UINT (param_spec))
{
g_object_set (config,
param_spec->name, (guint) value,
NULL);
}
else if (G_IS_PARAM_SPEC_LONG (param_spec))
{
g_object_set (config,
param_spec->name, (glong) value,
NULL);
}
else if (G_IS_PARAM_SPEC_ULONG (param_spec))
{
g_object_set (config,
param_spec->name, (gulong) value,
NULL);
}
else if (G_IS_PARAM_SPEC_INT64 (param_spec))
{
g_object_set (config,
param_spec->name, (gint64) value,
NULL);
}
else if (G_IS_PARAM_SPEC_UINT64 (param_spec))
{
g_object_set (config,
param_spec->name, (guint64) value,
NULL);
}
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
{
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (adjustment),
"opacity-scale")))
value /= 100.0;
g_signal_handlers_unblock_by_func (config,
gimp_prop_spin_scale_notify,
adjustment);
g_object_set (config, param_spec->name, value, NULL);
}
}
static void
gimp_prop_spin_scale_notify (GObject *config,
gimp_prop_adjustment_notify (GObject *config,
GParamSpec *param_spec,
GtkAdjustment *adjustment)
{
gdouble value;
g_object_get (config,
param_spec->name, &value,
NULL);
if (G_IS_PARAM_SPEC_INT (param_spec))
{
gint int_value;
g_signal_handlers_block_by_func (adjustment,
gimp_prop_spin_scale_callback,
config);
g_object_get (config, param_spec->name, &int_value, NULL);
gtk_adjustment_set_value (adjustment, value);
value = int_value;
}
else if (G_IS_PARAM_SPEC_UINT (param_spec))
{
guint uint_value;
g_signal_handlers_unblock_by_func (adjustment,
gimp_prop_spin_scale_callback,
config);
g_object_get (config, param_spec->name, &uint_value, NULL);
value = uint_value;
}
else if (G_IS_PARAM_SPEC_LONG (param_spec))
{
glong long_value;
g_object_get (config, param_spec->name, &long_value, NULL);
value = long_value;
}
else if (G_IS_PARAM_SPEC_ULONG (param_spec))
{
gulong ulong_value;
g_object_get (config, param_spec->name, &ulong_value, NULL);
value = ulong_value;
}
else if (G_IS_PARAM_SPEC_INT64 (param_spec))
{
gint64 int64_value;
g_object_get (config, param_spec->name, &int64_value, NULL);
value = int64_value;
}
else if (G_IS_PARAM_SPEC_UINT64 (param_spec))
{
guint64 uint64_value;
g_object_get (config, param_spec->name, &uint64_value, NULL);
#if defined _MSC_VER && (_MSC_VER < 1300)
value = (gint64) uint64_value;
#else
value = uint64_value;
#endif
}
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
{
g_object_get (config, param_spec->name, &value, NULL);
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (adjustment),
"opacity-scale")))
value *= 100.0;
}
else
{
g_warning ("%s: unhandled param spec of type %s",
G_STRFUNC, G_PARAM_SPEC_TYPE_NAME (param_spec));
return;
}
if (gtk_adjustment_get_value (adjustment) != value)
{
g_signal_handlers_block_by_func (adjustment,
gimp_prop_adjustment_callback,
config);
gtk_adjustment_set_value (adjustment, value);
g_signal_handlers_unblock_by_func (adjustment,
gimp_prop_adjustment_callback,
config);
}
}
@ -1367,6 +1477,57 @@ check_param_spec_w (GObject *object,
return param_spec;
}
static gboolean
get_numeric_values (GObject *object,
GParamSpec *param_spec,
gdouble *value,
gdouble *lower,
gdouble *upper,
const gchar *strloc)
{
if (G_IS_PARAM_SPEC_INT (param_spec))
{
GParamSpecInt *int_spec = G_PARAM_SPEC_INT (param_spec);
gint int_value;
g_object_get (object, param_spec->name, &int_value, NULL);
*value = int_value;
*lower = int_spec->minimum;
*upper = int_spec->maximum;
}
else if (G_IS_PARAM_SPEC_UINT (param_spec))
{
GParamSpecUInt *uint_spec = G_PARAM_SPEC_UINT (param_spec);
guint uint_value;
g_object_get (object, param_spec->name, &uint_value, NULL);
*value = uint_value;
*lower = uint_spec->minimum;
*upper = uint_spec->maximum;
}
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
{
GParamSpecDouble *double_spec = G_PARAM_SPEC_DOUBLE (param_spec);
g_object_get (object, param_spec->name, value, NULL);
*lower = double_spec->minimum;
*upper = double_spec->maximum;
}
else
{
g_warning ("%s: property '%s' of %s is not numeric",
strloc,
param_spec->name,
g_type_name (G_TYPE_FROM_INSTANCE (object)));
return FALSE;
}
return TRUE;
}
static void
connect_notify (GObject *config,
const gchar *property_name,