mirror of https://github.com/GNOME/gimp.git
app, libgimp*, pdb: new GimpParamSpecObject abstract spec type.
This abstract spec type is basically a GParamSpecObject with a default value. It will be used by various object spec with default values, such as GimpParamSpecColor, GimpParamSpecUnit and all GimpParamSpecResource subtypes. Also it has a duplicate() class method so that every spec type can implement the proper way to duplicate itself. This fixes the fact that in gimp_config_param_spec_duplicate(), all unknown object spec types (because they are implemented in libgimp, which is invisible to libgimpconfig) are just copied as GParamSpecObject, hence losing default values and other parameters. As a second enhancement, it also makes it easier to detect the object spec types for which we have default value support in gimp_config_reset_properties(). As a side fix, gimp_param_spec_color() now just always duplicates the passed default color, making it hence much easier to avoid bugs when reusing a GeglColor.
This commit is contained in:
parent
a7bc5f07f2
commit
ba3da3d338
|
@ -5783,6 +5783,7 @@ register_context_procs (GimpPDB *pdb)
|
|||
gimp_param_spec_resource ("resource",
|
||||
"resource",
|
||||
"The active resource",
|
||||
GIMP_TYPE_RESOURCE,
|
||||
FALSE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
|
|
@ -542,6 +542,7 @@ register_resource_procs (GimpPDB *pdb)
|
|||
gimp_param_spec_resource ("resource",
|
||||
"resource",
|
||||
"The resource",
|
||||
GIMP_TYPE_RESOURCE,
|
||||
TRUE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
@ -593,6 +594,7 @@ register_resource_procs (GimpPDB *pdb)
|
|||
gimp_param_spec_resource ("resource",
|
||||
"resource",
|
||||
"The resource",
|
||||
GIMP_TYPE_RESOURCE,
|
||||
FALSE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
@ -793,6 +795,7 @@ register_resource_procs (GimpPDB *pdb)
|
|||
gimp_param_spec_resource ("resource",
|
||||
"resource",
|
||||
"The resource",
|
||||
GIMP_TYPE_RESOURCE,
|
||||
FALSE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
@ -826,6 +829,7 @@ register_resource_procs (GimpPDB *pdb)
|
|||
gimp_param_spec_resource ("resource",
|
||||
"resource",
|
||||
"The resource",
|
||||
GIMP_TYPE_RESOURCE,
|
||||
FALSE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
@ -870,6 +874,7 @@ register_resource_procs (GimpPDB *pdb)
|
|||
gimp_param_spec_resource ("resource",
|
||||
"resource",
|
||||
"The resource",
|
||||
GIMP_TYPE_RESOURCE,
|
||||
FALSE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
@ -900,6 +905,7 @@ register_resource_procs (GimpPDB *pdb)
|
|||
gimp_param_spec_resource ("resource",
|
||||
"resource",
|
||||
"The resource",
|
||||
GIMP_TYPE_RESOURCE,
|
||||
FALSE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
@ -907,6 +913,7 @@ register_resource_procs (GimpPDB *pdb)
|
|||
gimp_param_spec_resource ("resource-copy",
|
||||
"resource copy",
|
||||
"A copy of the resource.",
|
||||
GIMP_TYPE_RESOURCE,
|
||||
FALSE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
@ -931,6 +938,7 @@ register_resource_procs (GimpPDB *pdb)
|
|||
gimp_param_spec_resource ("resource",
|
||||
"resource",
|
||||
"The resource",
|
||||
GIMP_TYPE_RESOURCE,
|
||||
FALSE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
@ -962,6 +970,7 @@ register_resource_procs (GimpPDB *pdb)
|
|||
gimp_param_spec_resource ("resource",
|
||||
"resource",
|
||||
"The resource",
|
||||
GIMP_TYPE_RESOURCE,
|
||||
FALSE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
|
|
@ -268,7 +268,7 @@ _gimp_gp_param_def_to_param_spec (const GPParamDef *param_def)
|
|||
* Args to PDB procedures are not sent as GimpParamResource crossing wire.
|
||||
*/
|
||||
if (! strcmp (param_def->type_name, "GimpParamResource"))
|
||||
return gimp_param_spec_resource (name, nick, blurb,
|
||||
return gimp_param_spec_resource (name, nick, blurb, GIMP_TYPE_RESOURCE,
|
||||
param_def->meta.m_id.none_ok, NULL, flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamBrush"))
|
||||
|
@ -431,7 +431,7 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
|
|||
}
|
||||
else if (GIMP_IS_PARAM_SPEC_COLOR (pspec))
|
||||
{
|
||||
default_color = gimp_param_spec_color_get_default (pspec);
|
||||
default_color = GEGL_COLOR (gimp_param_spec_object_get_default (pspec));
|
||||
param_def->meta.m_gegl_color.has_alpha = gimp_param_spec_color_has_alpha (pspec);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -989,24 +989,23 @@ gimp_param_spec_display (const gchar *name,
|
|||
* GIMP_TYPE_PARAM_RESOURCE
|
||||
*/
|
||||
|
||||
static void gimp_param_resource_class_init (GParamSpecClass *klass);
|
||||
static void gimp_param_resource_init (GParamSpec *pspec);
|
||||
static void gimp_param_resource_finalize (GParamSpec *pspec);
|
||||
static gboolean gimp_param_resource_validate (GParamSpec *pspec,
|
||||
static void gimp_param_resource_class_init (GimpParamSpecObjectClass *klass);
|
||||
static void gimp_param_resource_init (GParamSpec *pspec);
|
||||
static GParamSpec * gimp_param_resource_duplicate (GParamSpec *pspec);
|
||||
static gboolean gimp_param_resource_validate (GParamSpec *pspec,
|
||||
GValue *value);
|
||||
static void gimp_param_resource_value_set_default
|
||||
(GParamSpec *pspec,
|
||||
GValue *value);
|
||||
GType
|
||||
gimp_param_resource_get_type (void)
|
||||
{
|
||||
|
||||
|
||||
GType
|
||||
gimp_param_resource_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
|
||||
if (! type)
|
||||
{
|
||||
const GTypeInfo info =
|
||||
{
|
||||
sizeof (GParamSpecClass),
|
||||
sizeof (GimpParamSpecObjectClass),
|
||||
NULL, NULL,
|
||||
(GClassInitFunc) gimp_param_resource_class_init,
|
||||
NULL, NULL,
|
||||
|
@ -1015,20 +1014,21 @@ gimp_param_spec_display (const gchar *name,
|
|||
(GInstanceInitFunc) gimp_param_resource_init
|
||||
};
|
||||
|
||||
type = g_type_register_static (G_TYPE_PARAM_OBJECT,
|
||||
"GimpParamResource", &info, 0);
|
||||
type = g_type_register_static (GIMP_TYPE_PARAM_OBJECT, "GimpParamResource", &info, 0);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_param_resource_class_init (GParamSpecClass *klass)
|
||||
gimp_param_resource_class_init (GimpParamSpecObjectClass *klass)
|
||||
{
|
||||
klass->value_type = GIMP_TYPE_RESOURCE;
|
||||
klass->finalize = gimp_param_resource_finalize;
|
||||
klass->value_validate = gimp_param_resource_validate;
|
||||
klass->value_set_default = gimp_param_resource_value_set_default;
|
||||
GParamSpecClass *pclass = G_PARAM_SPEC_CLASS (klass);
|
||||
|
||||
klass->duplicate = gimp_param_resource_duplicate;
|
||||
|
||||
pclass->value_type = GIMP_TYPE_RESOURCE;
|
||||
pclass->value_validate = gimp_param_resource_validate;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1037,19 +1037,24 @@ gimp_param_resource_init (GParamSpec *pspec)
|
|||
GimpParamSpecResource *rspec = GIMP_PARAM_SPEC_RESOURCE (pspec);
|
||||
|
||||
rspec->none_ok = FALSE;
|
||||
rspec->default_value = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_param_resource_finalize (GParamSpec *pspec)
|
||||
static GParamSpec *
|
||||
gimp_param_resource_duplicate (GParamSpec *pspec)
|
||||
{
|
||||
GimpParamSpecResource *rspec = GIMP_PARAM_SPEC_RESOURCE (pspec);
|
||||
GParamSpecClass *parent_class = g_type_class_peek (
|
||||
g_type_parent (GIMP_TYPE_PARAM_RESOURCE));
|
||||
GParamSpec *duplicate;
|
||||
|
||||
g_clear_object (&rspec->default_value);
|
||||
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_RESOURCE (pspec), NULL);
|
||||
|
||||
parent_class->finalize (pspec);
|
||||
duplicate = gimp_param_spec_resource (pspec->name,
|
||||
g_param_spec_get_nick (pspec),
|
||||
g_param_spec_get_blurb (pspec),
|
||||
pspec->value_type,
|
||||
GIMP_PARAM_SPEC_RESOURCE (pspec)->none_ok,
|
||||
GIMP_RESOURCE (gimp_param_spec_object_get_default (pspec)),
|
||||
pspec->flags);
|
||||
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -1073,16 +1078,6 @@ gimp_param_resource_validate (GParamSpec *pspec,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_param_resource_value_set_default (GParamSpec *pspec,
|
||||
GValue *value)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_PARAM_SPEC_RESOURCE (pspec));
|
||||
|
||||
g_value_set_object (value, GIMP_PARAM_SPEC_RESOURCE (pspec)->default_value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gimp_param_spec_resource:
|
||||
* @name: Canonical name of the property specified.
|
||||
|
@ -1117,22 +1112,37 @@ GParamSpec *
|
|||
gimp_param_spec_resource (const gchar *name,
|
||||
const gchar *nick,
|
||||
const gchar *blurb,
|
||||
GType resource_type,
|
||||
gboolean none_ok,
|
||||
GimpResource *default_value,
|
||||
GParamFlags flags)
|
||||
{
|
||||
GimpParamSpecResource *rspec;
|
||||
GType param_type;
|
||||
|
||||
rspec = g_param_spec_internal (GIMP_TYPE_PARAM_RESOURCE,
|
||||
name, nick, blurb, flags);
|
||||
if (resource_type == GIMP_TYPE_RESOURCE ||
|
||||
resource_type == G_TYPE_NONE)
|
||||
param_type = GIMP_TYPE_PARAM_RESOURCE;
|
||||
else if (resource_type == GIMP_TYPE_BRUSH)
|
||||
param_type = GIMP_TYPE_PARAM_BRUSH;
|
||||
else if (resource_type == GIMP_TYPE_PATTERN)
|
||||
param_type = GIMP_TYPE_PARAM_PATTERN;
|
||||
else if (resource_type == GIMP_TYPE_GRADIENT)
|
||||
param_type = GIMP_TYPE_PARAM_GRADIENT;
|
||||
else if (resource_type == GIMP_TYPE_PALETTE)
|
||||
param_type = GIMP_TYPE_PARAM_PALETTE;
|
||||
else if (resource_type == GIMP_TYPE_FONT)
|
||||
param_type = GIMP_TYPE_PARAM_FONT;
|
||||
else
|
||||
g_return_val_if_reached (NULL);
|
||||
|
||||
rspec = g_param_spec_internal (param_type, name, nick, blurb, flags);
|
||||
|
||||
g_return_val_if_fail (rspec, NULL);
|
||||
|
||||
rspec->none_ok = none_ok ? TRUE : FALSE;
|
||||
|
||||
rspec->default_value = default_value;
|
||||
if (default_value)
|
||||
g_object_ref (default_value);
|
||||
gimp_param_spec_object_set_default (G_PARAM_SPEC (rspec), G_OBJECT (default_value));
|
||||
|
||||
return G_PARAM_SPEC (rspec);
|
||||
}
|
||||
|
@ -1154,7 +1164,7 @@ gimp_param_brush_get_type (void)
|
|||
{
|
||||
const GTypeInfo info =
|
||||
{
|
||||
sizeof (GParamSpecClass),
|
||||
sizeof (GimpParamSpecObjectClass),
|
||||
NULL, NULL,
|
||||
(GClassInitFunc) gimp_param_brush_class_init,
|
||||
NULL, NULL,
|
||||
|
@ -1209,20 +1219,9 @@ gimp_param_spec_brush (const gchar *name,
|
|||
GimpBrush *default_value,
|
||||
GParamFlags flags)
|
||||
{
|
||||
GimpParamSpecResource *rspec;
|
||||
|
||||
rspec = g_param_spec_internal (GIMP_TYPE_PARAM_BRUSH,
|
||||
name, nick, blurb, flags);
|
||||
|
||||
g_return_val_if_fail (rspec, NULL);
|
||||
|
||||
rspec->none_ok = none_ok ? TRUE : FALSE;
|
||||
|
||||
rspec->default_value = GIMP_RESOURCE (default_value);
|
||||
if (default_value)
|
||||
g_object_ref (default_value);
|
||||
|
||||
return G_PARAM_SPEC (rspec);
|
||||
return gimp_param_spec_resource (name, nick, blurb, GIMP_TYPE_BRUSH,
|
||||
none_ok, GIMP_RESOURCE (default_value),
|
||||
flags);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1242,7 +1241,7 @@ gimp_param_pattern_get_type (void)
|
|||
{
|
||||
const GTypeInfo info =
|
||||
{
|
||||
sizeof (GParamSpecClass),
|
||||
sizeof (GimpParamSpecObjectClass),
|
||||
NULL, NULL,
|
||||
(GClassInitFunc) gimp_param_pattern_class_init,
|
||||
NULL, NULL,
|
||||
|
@ -1297,20 +1296,9 @@ gimp_param_spec_pattern (const gchar *name,
|
|||
GimpPattern *default_value,
|
||||
GParamFlags flags)
|
||||
{
|
||||
GimpParamSpecResource *rspec;
|
||||
|
||||
rspec = g_param_spec_internal (GIMP_TYPE_PARAM_PATTERN,
|
||||
name, nick, blurb, flags);
|
||||
|
||||
g_return_val_if_fail (rspec, NULL);
|
||||
|
||||
rspec->none_ok = none_ok ? TRUE : FALSE;
|
||||
|
||||
rspec->default_value = GIMP_RESOURCE (default_value);
|
||||
if (default_value)
|
||||
g_object_ref (default_value);
|
||||
|
||||
return G_PARAM_SPEC (rspec);
|
||||
return gimp_param_spec_resource (name, nick, blurb, GIMP_TYPE_PATTERN,
|
||||
none_ok, GIMP_RESOURCE (default_value),
|
||||
flags);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1330,7 +1318,7 @@ gimp_param_gradient_get_type (void)
|
|||
{
|
||||
const GTypeInfo info =
|
||||
{
|
||||
sizeof (GParamSpecClass),
|
||||
sizeof (GimpParamSpecObjectClass),
|
||||
NULL, NULL,
|
||||
(GClassInitFunc) gimp_param_gradient_class_init,
|
||||
NULL, NULL,
|
||||
|
@ -1385,18 +1373,9 @@ gimp_param_spec_gradient (const gchar *name,
|
|||
GimpGradient *default_value,
|
||||
GParamFlags flags)
|
||||
{
|
||||
GimpParamSpecResource *rspec;
|
||||
|
||||
rspec = g_param_spec_internal (GIMP_TYPE_PARAM_GRADIENT,
|
||||
name, nick, blurb, flags);
|
||||
|
||||
g_return_val_if_fail (rspec, NULL);
|
||||
|
||||
rspec->none_ok = none_ok ? TRUE : FALSE;
|
||||
|
||||
rspec->default_value = GIMP_RESOURCE (default_value);
|
||||
|
||||
return G_PARAM_SPEC (rspec);
|
||||
return gimp_param_spec_resource (name, nick, blurb, GIMP_TYPE_GRADIENT,
|
||||
none_ok, GIMP_RESOURCE (default_value),
|
||||
flags);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1416,7 +1395,7 @@ gimp_param_palette_get_type (void)
|
|||
{
|
||||
const GTypeInfo info =
|
||||
{
|
||||
sizeof (GParamSpecClass),
|
||||
sizeof (GimpParamSpecObjectClass),
|
||||
NULL, NULL,
|
||||
(GClassInitFunc) gimp_param_palette_class_init,
|
||||
NULL, NULL,
|
||||
|
@ -1471,20 +1450,9 @@ gimp_param_spec_palette (const gchar *name,
|
|||
GimpPalette *default_value,
|
||||
GParamFlags flags)
|
||||
{
|
||||
GimpParamSpecResource *rspec;
|
||||
|
||||
rspec = g_param_spec_internal (GIMP_TYPE_PARAM_PALETTE,
|
||||
name, nick, blurb, flags);
|
||||
|
||||
g_return_val_if_fail (rspec, NULL);
|
||||
|
||||
rspec->none_ok = none_ok ? TRUE : FALSE;
|
||||
|
||||
rspec->default_value = GIMP_RESOURCE (default_value);
|
||||
if (default_value)
|
||||
g_object_ref (default_value);
|
||||
|
||||
return G_PARAM_SPEC (rspec);
|
||||
return gimp_param_spec_resource (name, nick, blurb, GIMP_TYPE_PALETTE,
|
||||
none_ok, GIMP_RESOURCE (default_value),
|
||||
flags);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1504,7 +1472,7 @@ gimp_param_font_get_type (void)
|
|||
{
|
||||
const GTypeInfo info =
|
||||
{
|
||||
sizeof (GParamSpecClass),
|
||||
sizeof (GimpParamSpecObjectClass),
|
||||
NULL, NULL,
|
||||
(GClassInitFunc) gimp_param_font_class_init,
|
||||
NULL, NULL,
|
||||
|
@ -1559,18 +1527,7 @@ gimp_param_spec_font (const gchar *name,
|
|||
GimpFont *default_value,
|
||||
GParamFlags flags)
|
||||
{
|
||||
GimpParamSpecResource *rspec;
|
||||
|
||||
rspec = g_param_spec_internal (GIMP_TYPE_PARAM_FONT,
|
||||
name, nick, blurb, flags);
|
||||
|
||||
g_return_val_if_fail (rspec, NULL);
|
||||
|
||||
rspec->none_ok = none_ok ? TRUE : FALSE;
|
||||
|
||||
rspec->default_value = GIMP_RESOURCE (default_value);
|
||||
if (default_value)
|
||||
g_object_ref (default_value);
|
||||
|
||||
return G_PARAM_SPEC (rspec);
|
||||
return gimp_param_spec_resource (name, nick, blurb, GIMP_TYPE_FONT,
|
||||
none_ok, GIMP_RESOURCE (default_value),
|
||||
flags);
|
||||
}
|
||||
|
|
|
@ -337,8 +337,7 @@ GParamSpec * gimp_param_spec_display (const gchar *name,
|
|||
* GIMP_TYPE_PARAM_RESOURCE
|
||||
*/
|
||||
|
||||
#define GIMP_VALUE_HOLDS_RESOURCE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), \
|
||||
GIMP_TYPE_RESOURCE))
|
||||
#define GIMP_VALUE_HOLDS_RESOURCE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_RESOURCE))
|
||||
|
||||
#define GIMP_TYPE_PARAM_RESOURCE (gimp_param_resource_get_type ())
|
||||
#define GIMP_PARAM_SPEC_RESOURCE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_RESOURCE, GimpParamSpecResource))
|
||||
|
@ -348,10 +347,9 @@ typedef struct _GimpParamSpecResource GimpParamSpecResource;
|
|||
|
||||
struct _GimpParamSpecResource
|
||||
{
|
||||
GParamSpecObject parent_instance;
|
||||
GimpParamSpecObject parent_instance;
|
||||
|
||||
gboolean none_ok;
|
||||
GimpResource *default_value;
|
||||
};
|
||||
|
||||
GType gimp_param_resource_get_type (void) G_GNUC_CONST;
|
||||
|
@ -359,6 +357,7 @@ GType gimp_param_resource_get_type (void) G_GNUC_CONST;
|
|||
GParamSpec * gimp_param_spec_resource (const gchar *name,
|
||||
const gchar *nick,
|
||||
const gchar *blurb,
|
||||
GType resource_type,
|
||||
gboolean none_ok,
|
||||
GimpResource *default_value,
|
||||
GParamFlags flags);
|
||||
|
|
|
@ -151,6 +151,7 @@ typedef struct _GimpPlugInPrivate
|
|||
GList *temp_procedures;
|
||||
|
||||
GList *procedure_stack;
|
||||
GList *ran_procedure_stack;
|
||||
GHashTable *displays;
|
||||
GHashTable *images;
|
||||
GHashTable *items;
|
||||
|
@ -292,6 +293,13 @@ gimp_plug_in_class_init (GimpPlugInClass *klass)
|
|||
static void
|
||||
gimp_plug_in_init (GimpPlugIn *plug_in)
|
||||
{
|
||||
GimpPlugInPrivate *priv;
|
||||
|
||||
priv = gimp_plug_in_get_instance_private (plug_in);
|
||||
|
||||
priv->procedure_stack = NULL;
|
||||
priv->ran_procedure_stack = NULL;
|
||||
priv->temp_procedures = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -369,6 +377,7 @@ gimp_plug_in_finalize (GObject *object)
|
|||
gimp_plug_in_destroy_proxies (plug_in, priv->resources, "resource", TRUE);
|
||||
|
||||
gimp_plug_in_destroy_hashes (plug_in);
|
||||
g_clear_list (&priv->ran_procedure_stack, g_object_unref);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -600,9 +609,8 @@ gimp_plug_in_remove_temp_procedure (GimpPlugIn *plug_in,
|
|||
|
||||
priv = gimp_plug_in_get_instance_private (plug_in);
|
||||
|
||||
priv->temp_procedures =
|
||||
g_list_remove (priv->temp_procedures,
|
||||
procedure);
|
||||
priv->temp_procedures = g_list_remove (priv->temp_procedures, procedure);
|
||||
if (! g_list_find (priv->ran_procedure_stack, procedure))
|
||||
g_object_unref (procedure);
|
||||
}
|
||||
}
|
||||
|
@ -1436,12 +1444,9 @@ gimp_plug_in_main_proc_run (GimpPlugIn *plug_in,
|
|||
priv = gimp_plug_in_get_instance_private (plug_in);
|
||||
|
||||
if (procedure)
|
||||
{
|
||||
gimp_plug_in_proc_run_internal (plug_in,
|
||||
proc_run, procedure,
|
||||
&proc_return);
|
||||
g_object_unref (procedure);
|
||||
}
|
||||
|
||||
gimp_plug_in_main_run_cleanup (plug_in);
|
||||
|
||||
|
@ -1464,11 +1469,9 @@ gimp_plug_in_temp_proc_run (GimpPlugIn *plug_in,
|
|||
priv = gimp_plug_in_get_instance_private (plug_in);
|
||||
|
||||
if (procedure)
|
||||
{
|
||||
gimp_plug_in_proc_run_internal (plug_in,
|
||||
proc_run, procedure,
|
||||
&proc_return);
|
||||
}
|
||||
|
||||
gimp_plug_in_temp_run_cleanup (plug_in);
|
||||
|
||||
|
@ -1651,6 +1654,8 @@ gimp_plug_in_pop_procedure (GimpPlugIn *plug_in,
|
|||
GimpPlugInPrivate *priv = gimp_plug_in_get_instance_private (plug_in);
|
||||
|
||||
priv->procedure_stack = g_list_remove (priv->procedure_stack, procedure);
|
||||
if (! g_list_find (priv->ran_procedure_stack, procedure))
|
||||
priv->ran_procedure_stack = g_list_prepend (priv->ran_procedure_stack, procedure);
|
||||
|
||||
/* Don't destroy proxies now because any proc, especially temporary procs,
|
||||
* may have passed a reference to a proc higher in the stack e.g. the main procedure.
|
||||
|
@ -1940,23 +1945,34 @@ gimp_plug_in_destroy_proxies (GimpPlugIn *plug_in,
|
|||
const gchar *type,
|
||||
gboolean destroy_all)
|
||||
{
|
||||
GimpPlugInPrivate *priv;
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
|
||||
if (! hash_table)
|
||||
return;
|
||||
|
||||
priv = gimp_plug_in_get_instance_private (plug_in);
|
||||
|
||||
g_hash_table_iter_init (&iter, hash_table);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||
{
|
||||
GObject *object = value;
|
||||
gint ref_count = 0;
|
||||
|
||||
if (object->ref_count == 1)
|
||||
for (GList *list = priv->ran_procedure_stack; list; list = list->next)
|
||||
ref_count += _gimp_procedure_get_ref_count (list->data, object);
|
||||
|
||||
if (object->ref_count == 1 + ref_count * 2)
|
||||
{
|
||||
/* There may be additional references as argument defaults (we
|
||||
* multiply by 2, because there would be one copy of the spec
|
||||
* in the config type too).
|
||||
*/
|
||||
g_hash_table_iter_remove (&iter);
|
||||
}
|
||||
else if (! G_IS_OBJECT (object))
|
||||
else if (! G_IS_OBJECT (object) || object->ref_count < 1 + ref_count * 2)
|
||||
{
|
||||
/* this is debug code, a plug-in MUST NOT unref a proxy. To be nice,
|
||||
* we steal the object from the table, as removing it normally would
|
||||
|
|
|
@ -2371,6 +2371,7 @@ gimp_procedure_add_resource_argument (GimpProcedure *procedure,
|
|||
{
|
||||
_gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_resource (name, nick, blurb,
|
||||
GIMP_TYPE_RESOURCE,
|
||||
none_ok,
|
||||
default_value,
|
||||
flags));
|
||||
|
@ -2399,6 +2400,7 @@ gimp_procedure_add_resource_aux_argument (GimpProcedure *procedure,
|
|||
{
|
||||
_gimp_procedure_add_aux_argument (procedure,
|
||||
gimp_param_spec_resource (name, nick, blurb,
|
||||
GIMP_TYPE_RESOURCE,
|
||||
TRUE,
|
||||
default_value,
|
||||
flags));
|
||||
|
@ -2425,6 +2427,7 @@ gimp_procedure_add_resource_return_value (GimpProcedure *procedure,
|
|||
{
|
||||
_gimp_procedure_add_return_value (procedure,
|
||||
gimp_param_spec_resource (name, nick, blurb,
|
||||
GIMP_TYPE_RESOURCE,
|
||||
TRUE, NULL, flags));
|
||||
}
|
||||
|
||||
|
|
|
@ -2229,6 +2229,43 @@ gimp_procedure_create_config (GimpProcedure *procedure)
|
|||
priv->n_args);
|
||||
}
|
||||
|
||||
/**
|
||||
* _gimp_procedure_get_ref_count:
|
||||
* @procedure: A #GimpProcedure
|
||||
*
|
||||
* Internal function to count the number of reference held by this
|
||||
* procedure inside its list of arguments's defaults.
|
||||
*
|
||||
* Returns: a reference count, which you will probably have to multiply
|
||||
* by 2, if a config object has been created too.
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
gint
|
||||
_gimp_procedure_get_ref_count (GimpProcedure *procedure,
|
||||
GObject *object)
|
||||
{
|
||||
GimpProcedurePrivate *priv;
|
||||
gint ref_count = 0;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), 0);
|
||||
|
||||
priv = gimp_procedure_get_instance_private (procedure);
|
||||
for (gint i = 0; i < priv->n_args; i++)
|
||||
{
|
||||
GParamSpec *pspec = priv->args[i];
|
||||
|
||||
if (GIMP_IS_PARAM_SPEC_OBJECT (pspec))
|
||||
{
|
||||
if (gimp_param_spec_object_has_default (pspec) &&
|
||||
gimp_param_spec_object_get_default (pspec) == object)
|
||||
ref_count++;
|
||||
}
|
||||
}
|
||||
|
||||
return ref_count;
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
|
|
|
@ -225,6 +225,9 @@ G_GNUC_INTERNAL GimpProcedureConfig * _gimp_procedure_create_run_config (GimpPro
|
|||
G_GNUC_INTERNAL GimpValueArray * _gimp_procedure_run_array (GimpProcedure *procedure,
|
||||
GimpValueArray *args);
|
||||
|
||||
G_GNUC_INTERNAL gint _gimp_procedure_get_ref_count (GimpProcedure *procedure,
|
||||
GObject *object);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -188,6 +188,7 @@ gimp_resource_chooser_class_init (GimpResourceChooserClass *klass)
|
|||
gimp_param_spec_resource ("resource",
|
||||
"Resource",
|
||||
"The currently selected resource",
|
||||
GIMP_TYPE_RESOURCE,
|
||||
TRUE, /* none_ok */
|
||||
NULL, /* no default for this property. */
|
||||
GIMP_PARAM_READWRITE);
|
||||
|
|
|
@ -130,6 +130,7 @@ EXPORTS
|
|||
gimp_param_int32_array_get_type
|
||||
gimp_param_memsize_get_type
|
||||
gimp_param_object_array_get_type
|
||||
gimp_param_object_get_type
|
||||
gimp_param_parasite_get_type
|
||||
gimp_param_spec_array
|
||||
gimp_param_spec_choice
|
||||
|
@ -138,6 +139,10 @@ EXPORTS
|
|||
gimp_param_spec_int32_array
|
||||
gimp_param_spec_memsize
|
||||
gimp_param_spec_object_array
|
||||
gimp_param_spec_object_duplicate
|
||||
gimp_param_spec_object_get_default
|
||||
gimp_param_spec_object_has_default
|
||||
gimp_param_spec_object_set_default
|
||||
gimp_param_spec_parasite
|
||||
gimp_param_spec_unit
|
||||
gimp_param_spec_value_array
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <gegl.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "libgimpmath/gimpmath.h"
|
||||
|
@ -33,6 +34,7 @@
|
|||
|
||||
#include "gimplimits.h"
|
||||
#include "gimpmetadata.h"
|
||||
#include "gimpparamspecs.h"
|
||||
#include "gimpunit.h"
|
||||
|
||||
#include "libgimp/libgimp-intl.h"
|
||||
|
|
|
@ -97,9 +97,12 @@ static void
|
|||
gimp_param_choice_finalize (GParamSpec *pspec)
|
||||
{
|
||||
GimpParamSpecChoice *spec_choice = GIMP_PARAM_SPEC_CHOICE (pspec);
|
||||
GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (GIMP_TYPE_PARAM_CHOICE));
|
||||
|
||||
g_free (spec_choice->default_value);
|
||||
g_object_unref (spec_choice->choice);
|
||||
|
||||
parent_class->finalize (pspec);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -188,6 +191,183 @@ gimp_param_spec_choice (const gchar *name,
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* GIMP_TYPE_PARAM_OBJECT
|
||||
*/
|
||||
|
||||
static void gimp_param_object_class_init (GimpParamSpecObjectClass *klass);
|
||||
static void gimp_param_object_init (GimpParamSpecObject *pspec);
|
||||
static void gimp_param_object_finalize (GParamSpec *pspec);
|
||||
static void gimp_param_object_value_set_default (GParamSpec *pspec,
|
||||
GValue *value);
|
||||
|
||||
static GParamSpec * gimp_param_spec_object_real_duplicate (GParamSpec *pspec);
|
||||
|
||||
|
||||
GType
|
||||
gimp_param_object_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
|
||||
if (! type)
|
||||
{
|
||||
const GTypeInfo info =
|
||||
{
|
||||
sizeof (GimpParamSpecObjectClass),
|
||||
NULL, NULL,
|
||||
(GClassInitFunc) gimp_param_object_class_init,
|
||||
NULL, NULL,
|
||||
sizeof (GimpParamSpecObject),
|
||||
0,
|
||||
(GInstanceInitFunc) gimp_param_object_init
|
||||
};
|
||||
|
||||
type = g_type_register_static (G_TYPE_PARAM_OBJECT,
|
||||
"GimpParamObject", &info, G_TYPE_FLAG_ABSTRACT);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_param_object_class_init (GimpParamSpecObjectClass *klass)
|
||||
{
|
||||
GParamSpecClass *pclass = G_PARAM_SPEC_CLASS (klass);
|
||||
|
||||
klass->duplicate = gimp_param_spec_object_real_duplicate;
|
||||
|
||||
pclass->value_type = G_TYPE_OBJECT;
|
||||
pclass->finalize = gimp_param_object_finalize;
|
||||
pclass->value_set_default = gimp_param_object_value_set_default;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_param_object_init (GimpParamSpecObject *ospec)
|
||||
{
|
||||
ospec->_default_value = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_param_object_finalize (GParamSpec *pspec)
|
||||
{
|
||||
GimpParamSpecObject *ospec = GIMP_PARAM_SPEC_OBJECT (pspec);
|
||||
GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (GIMP_TYPE_PARAM_OBJECT));
|
||||
|
||||
g_clear_object (&ospec->_default_value);
|
||||
|
||||
parent_class->finalize (pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_param_object_value_set_default (GParamSpec *pspec,
|
||||
GValue *value)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_PARAM_SPEC_OBJECT (pspec));
|
||||
|
||||
g_value_set_object (value, GIMP_PARAM_SPEC_OBJECT (pspec)->_default_value);
|
||||
}
|
||||
|
||||
static GParamSpec *
|
||||
gimp_param_spec_object_real_duplicate (GParamSpec *pspec)
|
||||
{
|
||||
GimpParamSpecObject *ospec;
|
||||
GimpParamSpecObject *duplicate;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_OBJECT (pspec), NULL);
|
||||
|
||||
ospec = GIMP_PARAM_SPEC_OBJECT (pspec);
|
||||
duplicate = g_param_spec_internal (G_TYPE_FROM_INSTANCE (pspec),
|
||||
pspec->name,
|
||||
g_param_spec_get_nick (pspec),
|
||||
g_param_spec_get_blurb (pspec),
|
||||
pspec->flags);
|
||||
|
||||
duplicate->_default_value = ospec->_default_value ? g_object_ref (ospec->_default_value) : NULL;
|
||||
duplicate->_has_default = ospec->_has_default;
|
||||
|
||||
return G_PARAM_SPEC (duplicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_param_spec_object_get_default:
|
||||
* @pspec: a #GObject #GParamSpec
|
||||
*
|
||||
* Get the default object value of the param spec.
|
||||
*
|
||||
* It is a programming error to call this on a
|
||||
* [struct@Gimp.ParamSpecObject] with no default value. You should
|
||||
* verify first with [func@Gimp.ParamSpecObject.has_default].
|
||||
*
|
||||
* Returns: (transfer none): the default value.
|
||||
*/
|
||||
GObject *
|
||||
gimp_param_spec_object_get_default (GParamSpec *pspec)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_OBJECT (pspec), NULL);
|
||||
g_return_val_if_fail (GIMP_PARAM_SPEC_OBJECT (pspec)->_has_default, NULL);
|
||||
|
||||
return GIMP_PARAM_SPEC_OBJECT (pspec)->_default_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_param_spec_object_set_default:
|
||||
* @pspec: a #GObject #GParamSpec
|
||||
* @default_value: (transfer none) (nullable): a default value.
|
||||
*
|
||||
* Set the default object value of the param spec. This will switch the
|
||||
* `has_default` flag so that [func@Gimp.ParamSpecObject.has_default]
|
||||
* will now return %TRUE.
|
||||
*
|
||||
* A %NULL @default_value still counts as a default (unless the specific
|
||||
* @pspec does not allow %NULL as a default).
|
||||
*/
|
||||
void
|
||||
gimp_param_spec_object_set_default (GParamSpec *pspec,
|
||||
GObject *default_value)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_PARAM_SPEC_OBJECT (pspec));
|
||||
|
||||
GIMP_PARAM_SPEC_OBJECT (pspec)->_has_default = TRUE;
|
||||
g_set_object (&GIMP_PARAM_SPEC_OBJECT (pspec)->_default_value, default_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_param_spec_object_has_default:
|
||||
* @pspec: a #GObject #GParamSpec
|
||||
*
|
||||
* This function tells whether a default was set, typically with
|
||||
* [func@Gimp.ParamSpecObject.set_default] or any other way. It
|
||||
* does not guarantee that the default is an actual object (it may be
|
||||
* %NULL if valid as a default).
|
||||
*
|
||||
* Returns: whether a default value was set.
|
||||
*/
|
||||
gboolean
|
||||
gimp_param_spec_object_has_default (GParamSpec *pspec)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_OBJECT (pspec), FALSE);
|
||||
|
||||
return GIMP_PARAM_SPEC_OBJECT (pspec)->_has_default;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_param_spec_object_duplicate:
|
||||
* @pspec: a [struct@Gimp.ParamSpecObject].
|
||||
*
|
||||
* This function duplicates @pspec appropriately, depending on the
|
||||
* accurate spec type.
|
||||
*
|
||||
* Returns: (transfer floating): a newly created param spec.
|
||||
*/
|
||||
GParamSpec *
|
||||
gimp_param_spec_object_duplicate (GParamSpec *pspec)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_OBJECT (pspec), NULL);
|
||||
|
||||
return GIMP_PARAM_SPEC_OBJECT_GET_CLASS (pspec)->duplicate (pspec);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GIMP_TYPE_ARRAY
|
||||
*/
|
||||
|
|
|
@ -118,6 +118,68 @@ GParamSpec * gimp_param_spec_choice (const gchar *name,
|
|||
GParamFlags flags);
|
||||
|
||||
|
||||
/*
|
||||
* GIMP_TYPE_PARAM_OBJECT
|
||||
*/
|
||||
|
||||
#define GIMP_TYPE_PARAM_OBJECT (gimp_param_object_get_type ())
|
||||
#define GIMP_PARAM_SPEC_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_OBJECT, GimpParamSpecObject))
|
||||
#define GIMP_PARAM_SPEC_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PARAM_OBJECT, GimpParamSpecObjectClass))
|
||||
#define GIMP_IS_PARAM_SPEC_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_OBJECT))
|
||||
#define GIMP_IS_PARAM_SPEC_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PARAM_OBJECT))
|
||||
#define GIMP_PARAM_SPEC_OBJECT_GET_CLASS(pspec) (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM_OBJECT, GimpParamSpecObjectClass))
|
||||
|
||||
|
||||
typedef struct _GimpParamSpecObject GimpParamSpecObject;
|
||||
typedef struct _GimpParamSpecObjectClass GimpParamSpecObjectClass;
|
||||
|
||||
struct _GimpParamSpecObject
|
||||
{
|
||||
GParamSpecObject parent_instance;
|
||||
|
||||
/*< private >*/
|
||||
GObject *_default_value;
|
||||
gboolean _has_default;
|
||||
};
|
||||
|
||||
struct _GimpParamSpecObjectClass
|
||||
{
|
||||
/* XXX: vapigen fails with the following error without the private
|
||||
* comment:
|
||||
* > error: The type name `GLib.ParamSpecClass' could not be found
|
||||
* Not sure why it doesn't search for GObject.ParamSpecClass instead.
|
||||
* Anyway putting it private is good enough and hides the parent_class
|
||||
* to bindings.
|
||||
*/
|
||||
/*< private >*/
|
||||
GParamSpecClass parent_class;
|
||||
|
||||
GParamSpec * (* duplicate) (GParamSpec *pspec);
|
||||
|
||||
/* Padding for future expansion */
|
||||
void (*_gimp_reserved0) (void);
|
||||
void (*_gimp_reserved1) (void);
|
||||
void (*_gimp_reserved2) (void);
|
||||
void (*_gimp_reserved3) (void);
|
||||
void (*_gimp_reserved4) (void);
|
||||
void (*_gimp_reserved5) (void);
|
||||
void (*_gimp_reserved6) (void);
|
||||
void (*_gimp_reserved7) (void);
|
||||
void (*_gimp_reserved8) (void);
|
||||
void (*_gimp_reserved9) (void);
|
||||
};
|
||||
|
||||
GType gimp_param_object_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GObject * gimp_param_spec_object_get_default (GParamSpec *pspec);
|
||||
void gimp_param_spec_object_set_default (GParamSpec *pspec,
|
||||
GObject *default_value);
|
||||
gboolean gimp_param_spec_object_has_default (GParamSpec *pspec);
|
||||
|
||||
GParamSpec * gimp_param_spec_object_duplicate (GParamSpec *pspec);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* GIMP_TYPE_ARRAY
|
||||
*/
|
||||
|
|
|
@ -929,8 +929,9 @@ gimp_units_to_points (gdouble value,
|
|||
* GIMP_TYPE_PARAM_UNIT
|
||||
*/
|
||||
|
||||
static void gimp_param_unit_class_init (GParamSpecClass *klass);
|
||||
static void gimp_param_unit_class_init (GimpParamSpecObjectClass *klass);
|
||||
static void gimp_param_unit_init (GParamSpec *pspec);
|
||||
static GParamSpec * gimp_param_unit_duplicate (GParamSpec *pspec);
|
||||
static void gimp_param_unit_set_default (GParamSpec *pspec,
|
||||
GValue *value);
|
||||
static gboolean gimp_param_unit_validate (GParamSpec *pspec,
|
||||
|
@ -954,7 +955,7 @@ gimp_param_unit_get_type (void)
|
|||
{
|
||||
const GTypeInfo info =
|
||||
{
|
||||
sizeof (GParamSpecClass),
|
||||
sizeof (GimpParamSpecObjectClass),
|
||||
NULL, NULL,
|
||||
(GClassInitFunc) gimp_param_unit_class_init,
|
||||
NULL, NULL,
|
||||
|
@ -963,7 +964,7 @@ gimp_param_unit_get_type (void)
|
|||
(GInstanceInitFunc) gimp_param_unit_init
|
||||
};
|
||||
|
||||
type = g_type_register_static (G_TYPE_PARAM_OBJECT,
|
||||
type = g_type_register_static (GIMP_TYPE_PARAM_OBJECT,
|
||||
"GimpParamUnit", &info, 0);
|
||||
}
|
||||
|
||||
|
@ -971,11 +972,15 @@ gimp_param_unit_get_type (void)
|
|||
}
|
||||
|
||||
static void
|
||||
gimp_param_unit_class_init (GParamSpecClass *klass)
|
||||
gimp_param_unit_class_init (GimpParamSpecObjectClass *klass)
|
||||
{
|
||||
klass->value_type = GIMP_TYPE_UNIT;
|
||||
klass->value_set_default = gimp_param_unit_set_default;
|
||||
klass->value_validate = gimp_param_unit_validate;
|
||||
GParamSpecClass *pclass = G_PARAM_SPEC_CLASS (klass);
|
||||
|
||||
klass->duplicate = gimp_param_unit_duplicate;
|
||||
|
||||
pclass->value_type = GIMP_TYPE_UNIT;
|
||||
pclass->value_set_default = gimp_param_unit_set_default;
|
||||
pclass->value_validate = gimp_param_unit_validate;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -988,6 +993,26 @@ gimp_param_unit_init (GParamSpec *pspec)
|
|||
uspec->default_value = gimp_unit_inch ();
|
||||
}
|
||||
|
||||
static GParamSpec *
|
||||
gimp_param_unit_duplicate (GParamSpec *pspec)
|
||||
{
|
||||
GParamSpec *duplicate;
|
||||
GimpParamSpecUnit *uspec;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_UNIT (pspec), NULL);
|
||||
|
||||
uspec = GIMP_PARAM_SPEC_UNIT (pspec);
|
||||
duplicate = gimp_param_spec_unit (pspec->name,
|
||||
g_param_spec_get_nick (pspec),
|
||||
g_param_spec_get_blurb (pspec),
|
||||
uspec->allow_pixel,
|
||||
uspec->allow_percent,
|
||||
uspec->default_value,
|
||||
pspec->flags);
|
||||
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_param_unit_set_default (GParamSpec *pspec,
|
||||
GValue *value)
|
||||
|
|
|
@ -94,7 +94,7 @@ typedef struct _GimpParamSpecUnit GimpParamSpecUnit;
|
|||
|
||||
struct _GimpParamSpecUnit
|
||||
{
|
||||
GParamSpecObject parent_instance;
|
||||
GimpParamSpecObject parent_instance;
|
||||
|
||||
gboolean allow_pixel;
|
||||
gboolean allow_percent;
|
||||
|
|
|
@ -43,17 +43,6 @@
|
|||
**/
|
||||
|
||||
|
||||
static void gimp_param_color_class_init (GParamSpecClass *klass);
|
||||
static void gimp_param_color_init (GParamSpec *pspec);
|
||||
static void gimp_param_color_finalize (GParamSpec *pspec);
|
||||
static gboolean gimp_param_color_validate (GParamSpec *pspec,
|
||||
GValue *value);
|
||||
static void gimp_param_color_set_default (GParamSpec *pspec,
|
||||
GValue *value);
|
||||
static gint gimp_param_color_cmp (GParamSpec *param_spec,
|
||||
const GValue *value1,
|
||||
const GValue *value2);
|
||||
|
||||
static const Babl * gimp_babl_format_get_with_alpha (const Babl *format);
|
||||
static gfloat gimp_color_get_CIE2000_distance (GeglColor *color1,
|
||||
GeglColor *color2);
|
||||
|
@ -340,11 +329,21 @@ gimp_color_is_out_of_gamut (GeglColor *color,
|
|||
* GIMP_TYPE_PARAM_COLOR
|
||||
*/
|
||||
|
||||
static void gimp_param_color_class_init (GimpParamSpecObjectClass *klass);
|
||||
static void gimp_param_color_init (GParamSpec *pspec);
|
||||
static GParamSpec * gimp_param_color_duplicate (GParamSpec *pspec);
|
||||
static gboolean gimp_param_color_validate (GParamSpec *pspec,
|
||||
GValue *value);
|
||||
static void gimp_param_color_set_default (GParamSpec *pspec,
|
||||
GValue *value);
|
||||
static gint gimp_param_color_cmp (GParamSpec *param_spec,
|
||||
const GValue *value1,
|
||||
const GValue *value2);
|
||||
|
||||
struct _GimpParamSpecColor
|
||||
{
|
||||
GParamSpecObject parent_instance;
|
||||
GimpParamSpecObject parent_instance;
|
||||
|
||||
GeglColor *default_color;
|
||||
gboolean has_alpha;
|
||||
|
||||
/* TODO: these 2 settings are not currently settable:
|
||||
|
@ -372,7 +371,7 @@ gimp_param_color_get_type (void)
|
|||
{
|
||||
const GTypeInfo info =
|
||||
{
|
||||
sizeof (GParamSpecClass),
|
||||
sizeof (GimpParamSpecObjectClass),
|
||||
NULL, NULL,
|
||||
(GClassInitFunc) gimp_param_color_class_init,
|
||||
NULL, NULL,
|
||||
|
@ -381,20 +380,23 @@ gimp_param_color_get_type (void)
|
|||
(GInstanceInitFunc) gimp_param_color_init
|
||||
};
|
||||
|
||||
type = g_type_register_static (G_TYPE_PARAM_OBJECT, "GimpParamColor", &info, 0);
|
||||
type = g_type_register_static (GIMP_TYPE_PARAM_OBJECT, "GimpParamColor", &info, 0);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_param_color_class_init (GParamSpecClass *klass)
|
||||
gimp_param_color_class_init (GimpParamSpecObjectClass *klass)
|
||||
{
|
||||
klass->finalize = gimp_param_color_finalize;
|
||||
klass->value_type = GEGL_TYPE_COLOR;
|
||||
klass->value_validate = gimp_param_color_validate;
|
||||
klass->value_set_default = gimp_param_color_set_default;
|
||||
klass->values_cmp = gimp_param_color_cmp;
|
||||
GParamSpecClass *pclass = G_PARAM_SPEC_CLASS (klass);
|
||||
|
||||
klass->duplicate = gimp_param_color_duplicate;
|
||||
|
||||
pclass->value_type = GEGL_TYPE_COLOR;
|
||||
pclass->value_validate = gimp_param_color_validate;
|
||||
pclass->value_set_default = gimp_param_color_set_default;
|
||||
pclass->values_cmp = gimp_param_color_cmp;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -402,21 +404,28 @@ gimp_param_color_init (GParamSpec *pspec)
|
|||
{
|
||||
GimpParamSpecColor *cspec = GIMP_PARAM_SPEC_COLOR (pspec);
|
||||
|
||||
cspec->default_color = NULL;
|
||||
cspec->has_alpha = TRUE;
|
||||
cspec->none_ok = TRUE;
|
||||
cspec->validate = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_param_color_finalize (GParamSpec *pspec)
|
||||
static GParamSpec *
|
||||
gimp_param_color_duplicate (GParamSpec *pspec)
|
||||
{
|
||||
GimpParamSpecColor *cspec = GIMP_PARAM_SPEC_COLOR (pspec);
|
||||
GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (GIMP_TYPE_PARAM_COLOR));
|
||||
GParamSpec *duplicate;
|
||||
GimpParamSpecColor *cspec;
|
||||
|
||||
g_clear_object (&cspec->default_color);
|
||||
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_COLOR (pspec), NULL);
|
||||
|
||||
parent_class->finalize (pspec);
|
||||
cspec = GIMP_PARAM_SPEC_COLOR (pspec);
|
||||
duplicate = gimp_param_spec_color (pspec->name,
|
||||
g_param_spec_get_nick (pspec),
|
||||
g_param_spec_get_blurb (pspec),
|
||||
cspec->has_alpha,
|
||||
GEGL_COLOR (gimp_param_spec_object_get_default (pspec)),
|
||||
pspec->flags);
|
||||
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -451,10 +460,11 @@ static void
|
|||
gimp_param_color_set_default (GParamSpec *pspec,
|
||||
GValue *value)
|
||||
{
|
||||
GimpParamSpecColor *cspec = GIMP_PARAM_SPEC_COLOR (pspec);
|
||||
GeglColor *color;
|
||||
|
||||
if (cspec->default_color)
|
||||
g_value_take_object (value, gegl_color_duplicate (cspec->default_color));
|
||||
color = GEGL_COLOR (gimp_param_spec_object_get_default (pspec));
|
||||
if (color)
|
||||
g_value_take_object (value, gegl_color_duplicate (color));
|
||||
}
|
||||
|
||||
static gint
|
||||
|
@ -496,6 +506,9 @@ gimp_param_color_cmp (GParamSpec *param_spec,
|
|||
* @flags: flags for the property specified
|
||||
*
|
||||
* Creates a new #GParamSpec instance specifying a #GeglColor property.
|
||||
* Note that the @default_color is duplicated, so reusing object will
|
||||
* not change the default color of the returned
|
||||
* [struct@Gimp.ParamSpecColor].
|
||||
*
|
||||
* Returns: (transfer full): a newly created parameter specification
|
||||
*/
|
||||
|
@ -508,12 +521,15 @@ gimp_param_spec_color (const gchar *name,
|
|||
GParamFlags flags)
|
||||
{
|
||||
GimpParamSpecColor *cspec;
|
||||
GeglColor *dup_color = NULL;
|
||||
|
||||
cspec = g_param_spec_internal (GIMP_TYPE_PARAM_COLOR, name, nick, blurb, flags);
|
||||
|
||||
cspec->default_color = default_color;
|
||||
if (default_color)
|
||||
g_object_ref (default_color);
|
||||
dup_color = gegl_color_duplicate (default_color);
|
||||
|
||||
gimp_param_spec_object_set_default (G_PARAM_SPEC (cspec), G_OBJECT (dup_color));
|
||||
g_clear_object (&dup_color);
|
||||
|
||||
cspec->has_alpha = has_alpha;
|
||||
|
||||
|
@ -542,30 +558,20 @@ gimp_param_spec_color_from_string (const gchar *name,
|
|||
GParamFlags flags)
|
||||
{
|
||||
GimpParamSpecColor *cspec;
|
||||
GeglColor *default_color;
|
||||
|
||||
cspec = g_param_spec_internal (GIMP_TYPE_PARAM_COLOR,
|
||||
name, nick, blurb, flags);
|
||||
|
||||
cspec->default_color = g_object_new (GEGL_TYPE_COLOR,
|
||||
default_color = g_object_new (GEGL_TYPE_COLOR,
|
||||
"string", default_color_string,
|
||||
NULL);
|
||||
gimp_param_spec_object_set_default (G_PARAM_SPEC (cspec), G_OBJECT (default_color));
|
||||
cspec->has_alpha = has_alpha;
|
||||
|
||||
return G_PARAM_SPEC (cspec);
|
||||
}
|
||||
g_clear_object (&default_color);
|
||||
|
||||
/**
|
||||
* gimp_param_spec_color_get_default:
|
||||
* @pspec: a #GeglColor #GParamSpec
|
||||
*
|
||||
* Get the default color value of the param spec
|
||||
*
|
||||
* Returns: (transfer none): the default #GeglColor
|
||||
*/
|
||||
GeglColor *
|
||||
gimp_param_spec_color_get_default (GParamSpec *pspec)
|
||||
{
|
||||
return GIMP_PARAM_SPEC_COLOR (pspec)->default_color;
|
||||
return G_PARAM_SPEC (cspec);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,7 +72,6 @@ EXPORTS
|
|||
gimp_param_color_get_type
|
||||
gimp_param_spec_color
|
||||
gimp_param_spec_color_from_string
|
||||
gimp_param_spec_color_get_default
|
||||
gimp_param_spec_color_has_alpha
|
||||
gimp_pixbuf_create_buffer
|
||||
gimp_pixbuf_get_format
|
||||
|
|
|
@ -93,7 +93,6 @@ GParamSpec * gimp_param_spec_color_from_string (const gchar *name,
|
|||
const gchar *default_color_string,
|
||||
GParamFlags flags);
|
||||
|
||||
GeglColor * gimp_param_spec_color_get_default (GParamSpec *pspec);
|
||||
gboolean gimp_param_spec_color_has_alpha (GParamSpec *pspec);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -229,16 +229,6 @@ gimp_config_param_spec_duplicate (GParamSpec *pspec)
|
|||
flags);
|
||||
}
|
||||
}
|
||||
else if (GIMP_IS_PARAM_SPEC_UNIT (pspec))
|
||||
{
|
||||
GimpParamSpecUnit *spec = GIMP_PARAM_SPEC_UNIT (pspec);
|
||||
|
||||
copy = gimp_param_spec_unit (name, nick, blurb,
|
||||
spec->allow_pixel,
|
||||
spec->allow_percent,
|
||||
spec->default_value,
|
||||
flags);
|
||||
}
|
||||
else if (GIMP_IS_PARAM_SPEC_CHOICE (pspec))
|
||||
{
|
||||
GimpParamSpecChoice *spec = GIMP_PARAM_SPEC_CHOICE (pspec);
|
||||
|
@ -248,33 +238,20 @@ gimp_config_param_spec_duplicate (GParamSpec *pspec)
|
|||
spec->default_value,
|
||||
flags);
|
||||
}
|
||||
else if (GIMP_IS_PARAM_SPEC_COLOR (pspec))
|
||||
else if (GIMP_IS_PARAM_SPEC_OBJECT (pspec))
|
||||
{
|
||||
GeglColor *color;
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_value_init (&value, GEGL_TYPE_COLOR);
|
||||
g_param_value_set_default (pspec, &value);
|
||||
color = g_value_dup_object (&value);
|
||||
g_value_unset (&value);
|
||||
|
||||
copy = gimp_param_spec_color (name, nick, blurb,
|
||||
gimp_param_spec_color_has_alpha (pspec),
|
||||
color, flags);
|
||||
g_clear_object (&color);
|
||||
/* GimpParamSpecColor, GimpParamSpecUnit and all GimpParamSpecResource types. */
|
||||
copy = gimp_param_spec_object_duplicate (pspec);
|
||||
copy->flags = flags;
|
||||
}
|
||||
else if (GEGL_IS_PARAM_SPEC_COLOR (pspec))
|
||||
{
|
||||
GeglColor *color;
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_value_init (&value, GEGL_TYPE_COLOR);
|
||||
g_param_value_set_default (pspec, &value);
|
||||
color = g_value_dup_object (&value);
|
||||
g_value_unset (&value);
|
||||
color = gegl_param_spec_color_get_default (pspec);
|
||||
color = gegl_color_duplicate (color);
|
||||
|
||||
copy = gegl_param_spec_color (name, nick, blurb,
|
||||
color, flags);
|
||||
copy = gegl_param_spec_color (name, nick, blurb, color, flags);
|
||||
g_clear_object (&color);
|
||||
}
|
||||
else if (G_IS_PARAM_SPEC_OBJECT (pspec) &&
|
||||
|
@ -284,7 +261,9 @@ gimp_config_param_spec_duplicate (GParamSpec *pspec)
|
|||
GeglColor *color;
|
||||
|
||||
value = (GValue *) g_param_spec_get_default_value (pspec);
|
||||
color = g_value_dup_object (value);
|
||||
color = g_value_get_object (value);
|
||||
if (color)
|
||||
color = gegl_color_duplicate (color);
|
||||
|
||||
copy = gegl_param_spec_color (name, nick, blurb,
|
||||
/*TRUE,*/
|
||||
|
@ -350,12 +329,6 @@ gimp_config_param_spec_duplicate (GParamSpec *pspec)
|
|||
g_strcmp0 (type_name, "GimpItem") == 0 ||
|
||||
g_strcmp0 (type_name, "GimpLayerMask") == 0 ||
|
||||
g_strcmp0 (type_name, "GimpSelection") == 0 ||
|
||||
g_strcmp0 (type_name, "GimpResource") == 0 ||
|
||||
g_strcmp0 (type_name, "GimpBrush") == 0 ||
|
||||
g_strcmp0 (type_name, "GimpFont") == 0 ||
|
||||
g_strcmp0 (type_name, "GimpGradient") == 0 ||
|
||||
g_strcmp0 (type_name, "GimpPalette") == 0 ||
|
||||
g_strcmp0 (type_name, "GimpPattern") == 0 ||
|
||||
g_strcmp0 (type_name, "GimpPath") == 0)
|
||||
{
|
||||
copy = g_param_spec_object (name, nick, blurb,
|
||||
|
|
|
@ -303,14 +303,13 @@ gimp_config_reset_properties (GObject *object)
|
|||
! (prop_spec->flags & G_PARAM_CONSTRUCT_ONLY))
|
||||
{
|
||||
if (G_IS_PARAM_SPEC_OBJECT (prop_spec) &&
|
||||
! GIMP_IS_PARAM_SPEC_COLOR (prop_spec) &&
|
||||
! GEGL_IS_PARAM_SPEC_COLOR (prop_spec) &&
|
||||
! GIMP_IS_PARAM_SPEC_UNIT (prop_spec))
|
||||
{
|
||||
if ((prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE) &&
|
||||
(prop_spec->flags & GIMP_CONFIG_PARAM_AGGREGATE) &&
|
||||
! GIMP_IS_PARAM_SPEC_OBJECT (prop_spec) &&
|
||||
g_type_class_peek (prop_spec->value_type) &&
|
||||
g_type_interface_peek (g_type_class_peek (prop_spec->value_type),
|
||||
GIMP_TYPE_CONFIG))
|
||||
{
|
||||
if ((prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE) &&
|
||||
(prop_spec->flags & GIMP_CONFIG_PARAM_AGGREGATE))
|
||||
{
|
||||
g_value_init (&value, prop_spec->value_type);
|
||||
|
||||
|
|
|
@ -246,6 +246,7 @@ CODE
|
|||
gimp_param_spec_resource ("$name",
|
||||
"$nick",
|
||||
"$blurb",
|
||||
GIMP_TYPE_RESOURCE,
|
||||
$none_ok,
|
||||
$default,
|
||||
$flags)
|
||||
|
|
Loading…
Reference in New Issue