app, app, libgimp*: hide struct for several GParamSpec based off GimpParamSpecObject.

As a consequence, here are needed new functions:

* libgimp:
  - gimp_param_spec_resource_defaults_to_context()
  - gimp_param_spec_resource_none_allowed()

* libgimpbase:
  - gimp_param_spec_file_get_action()
  - gimp_param_spec_file_none_allowed()
  - gimp_param_spec_unit_percent_allowed()
  - gimp_param_spec_unit_pixel_allowed()
This commit is contained in:
Jehan 2025-01-24 23:42:20 +01:00
parent 40aa78ac10
commit 6e777c861b
17 changed files with 195 additions and 100 deletions

View file

@ -506,15 +506,13 @@ dump_describe_param (GParamSpec *param_spec)
}
else if (GIMP_IS_PARAM_SPEC_UNIT (param_spec))
{
GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (param_spec);
if (uspec->allow_pixel && uspec->allow_percent)
if (gimp_param_spec_unit_pixel_allowed (param_spec) && gimp_param_spec_unit_percent_allowed (param_spec))
values = "The unit can be one inches, millimeters, points or picas plus "
"those in your user units database. Pixel And Percent units are allowed too.";
else if (uspec->allow_pixel)
else if (gimp_param_spec_unit_pixel_allowed (param_spec))
values = "The unit can be one inches, millimeters, points or picas plus "
"those in your user units database. Pixel unit is allowed too.";
else if (uspec->allow_percent)
else if (gimp_param_spec_unit_percent_allowed (param_spec))
values = "The unit can be one inches, millimeters, points or picas plus "
"those in your user units database. Percent unit is allowed too.";
else

View file

@ -48,15 +48,14 @@ gimp_param_spec_boolean_desc (GParamSpec *pspec)
static gchar *
gimp_param_spec_unit_desc (GParamSpec *pspec)
{
GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec);
GObject *default_value;
GObject *default_value;
default_value = gimp_param_spec_object_get_default (pspec);
return g_strdup_printf ("<i>(default %s%s%s)</i>",
gimp_unit_get_abbreviation (GIMP_UNIT (default_value)),
uspec->allow_pixel ? ", pixel allowed": "",
uspec->allow_percent ? ", percent allowed": "");
gimp_param_spec_unit_pixel_allowed (pspec) ? ", pixel allowed": "",
gimp_param_spec_unit_percent_allowed (pspec) ? ", percent allowed": "");
}
static gchar *

View file

@ -954,9 +954,9 @@ gimp_procedure_validate_args (GimpProcedure *procedure,
}
else if (GIMP_IS_PARAM_SPEC_UNIT (pspec) &&
((GIMP_UNIT (old_value) == gimp_unit_pixel () &&
! GIMP_PARAM_SPEC_UNIT (pspec)->allow_pixel) ||
! gimp_param_spec_unit_pixel_allowed (pspec)) ||
(GIMP_UNIT (old_value) == gimp_unit_percent () &&
! GIMP_PARAM_SPEC_UNIT (pspec)->allow_percent)))
! gimp_param_spec_unit_percent_allowed (pspec))))
{
if (return_vals)
{

View file

@ -736,6 +736,8 @@ EXPORTS
gimp_param_spec_path
gimp_param_spec_pattern
gimp_param_spec_resource
gimp_param_spec_resource_defaults_to_context
gimp_param_spec_resource_none_allowed
gimp_param_spec_selection
gimp_param_spec_text_layer
gimp_param_text_layer_get_type

View file

@ -429,15 +429,14 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
}
else if (pspec_type == GIMP_TYPE_PARAM_UNIT)
{
GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec);
GObject *default_value;
GObject *default_value;
default_value = gimp_param_spec_object_get_default (pspec);
param_def->param_def_type = GP_PARAM_DEF_TYPE_UNIT;
param_def->meta.m_unit.allow_pixels = uspec->allow_pixel;
param_def->meta.m_unit.allow_percent = uspec->allow_percent;
param_def->meta.m_unit.allow_pixels = gimp_param_spec_unit_pixel_allowed (pspec);
param_def->meta.m_unit.allow_percent = gimp_param_spec_unit_percent_allowed (pspec);
param_def->meta.m_unit.default_val = gimp_unit_get_id (GIMP_UNIT (default_value));
}
#ifndef LIBGIMP_COMPILATION
@ -654,30 +653,30 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
}
else if (GIMP_IS_PARAM_SPEC_RESOURCE (pspec))
{
GimpParamSpecResource *rspec = GIMP_PARAM_SPEC_RESOURCE (pspec);
GObject *default_value = NULL;
GObject *default_value = NULL;
gboolean default_to_context;
param_def->param_def_type = GP_PARAM_DEF_TYPE_RESOURCE;
if (gimp_param_spec_object_has_default (pspec))
default_value = gimp_param_spec_object_get_default (pspec);
param_def->meta.m_resource.none_ok = rspec->none_ok;
param_def->meta.m_resource.default_to_context = rspec->default_to_context;
if (default_value != NULL && ! rspec->default_to_context)
param_def->meta.m_resource.none_ok = gimp_param_spec_resource_none_allowed (pspec);
default_to_context = gimp_param_spec_resource_defaults_to_context (pspec);
param_def->meta.m_resource.default_to_context = default_to_context;
if (default_value != NULL && ! default_to_context)
param_def->meta.m_resource.default_resource_id = get_resource_id (default_value);
else
param_def->meta.m_resource.default_resource_id = 0;
}
else if (pspec_type == GIMP_TYPE_PARAM_FILE)
{
GimpParamSpecFile *fspec = GIMP_PARAM_SPEC_FILE (pspec);
GimpParamSpecObject *ospec = GIMP_PARAM_SPEC_OBJECT (pspec);
param_def->param_def_type = GP_PARAM_DEF_TYPE_FILE;
param_def->meta.m_file.action = (gint32) fspec->action;
param_def->meta.m_file.none_ok = fspec->none_ok;
param_def->meta.m_file.action = (gint32) gimp_param_spec_file_get_action (pspec);
param_def->meta.m_file.none_ok = gimp_param_spec_file_none_allowed (pspec);
param_def->meta.m_file.default_uri =
ospec->_default_value ? g_file_get_uri (G_FILE (ospec->_default_value)) : NULL;
}

View file

@ -1069,6 +1069,18 @@ gimp_param_spec_display (const gchar *name,
* GIMP_TYPE_PARAM_RESOURCE
*/
#define GIMP_PARAM_SPEC_RESOURCE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_RESOURCE, GimpParamSpecResource))
typedef struct _GimpParamSpecResource GimpParamSpecResource;
struct _GimpParamSpecResource
{
GimpParamSpecObject parent_instance;
gboolean none_ok;
gboolean default_to_context;
};
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);
@ -1118,7 +1130,8 @@ gimp_param_resource_init (GParamSpec *pspec)
{
GimpParamSpecResource *rspec = GIMP_PARAM_SPEC_RESOURCE (pspec);
rspec->none_ok = FALSE;
rspec->none_ok = FALSE;
rspec->default_to_context = FALSE;
}
static GParamSpec *
@ -1293,6 +1306,22 @@ gimp_param_spec_resource (const gchar *name,
return G_PARAM_SPEC (rspec);
}
gboolean
gimp_param_spec_resource_none_allowed (GParamSpec *pspec)
{
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_RESOURCE (pspec), FALSE);
return GIMP_PARAM_SPEC_RESOURCE (pspec)->none_ok;
}
gboolean
gimp_param_spec_resource_defaults_to_context (GParamSpec *pspec)
{
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_RESOURCE (pspec), FALSE);
return GIMP_PARAM_SPEC_RESOURCE (pspec)->default_to_context;
}
/*
* GIMP_TYPE_PARAM_BRUSH

View file

@ -44,15 +44,14 @@ gimp_param_spec_boolean_desc (GParamSpec *pspec)
static gchar *
gimp_param_spec_unit_desc (GParamSpec *pspec)
{
GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec);
GObject *default_value;
GObject *default_value;
default_value = gimp_param_spec_object_get_default (pspec);
return g_strdup_printf ("<i>(default %s%s%s)</i>",
gimp_unit_get_abbreviation (GIMP_UNIT (default_value)),
uspec->allow_pixel ? ", pixel allowed": "",
uspec->allow_percent ? ", percent allowed": "");
gimp_param_spec_unit_pixel_allowed (pspec) ? ", pixel allowed": "",
gimp_param_spec_unit_percent_allowed (pspec) ? ", percent allowed": "");
}
static gchar *

View file

@ -305,29 +305,21 @@ GParamSpec * gimp_param_spec_display (const gchar *name,
#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))
#define GIMP_IS_PARAM_SPEC_RESOURCE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_RESOURCE))
typedef struct _GimpParamSpecResource GimpParamSpecResource;
GType gimp_param_resource_get_type (void) G_GNUC_CONST;
struct _GimpParamSpecResource
{
GimpParamSpecObject parent_instance;
GParamSpec * gimp_param_spec_resource (const gchar *name,
const gchar *nick,
const gchar *blurb,
GType resource_type,
gboolean none_ok,
GimpResource *default_value,
gboolean default_to_context,
GParamFlags flags);
gboolean none_ok;
gboolean default_to_context;
};
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,
gboolean default_to_context,
GParamFlags flags);
gboolean gimp_param_spec_resource_none_allowed (GParamSpec *pspec);
gboolean gimp_param_spec_resource_defaults_to_context (GParamSpec *pspec);
/*

View file

@ -844,11 +844,9 @@ gimp_procedure_dialog_get_widget (GimpProcedureDialog *dialog,
}
else if (GIMP_IS_PARAM_SPEC_FILE (pspec))
{
GimpParamSpecFile *fspec = GIMP_PARAM_SPEC_FILE (pspec);
widget = gimp_prop_file_chooser_button_new (G_OBJECT (priv->config),
property, NULL,
(GtkFileChooserAction) fspec->action);
(GtkFileChooserAction) gimp_param_spec_file_get_action (pspec));
}
else if (G_IS_PARAM_SPEC_OBJECT (pspec) && pspec->value_type == G_TYPE_FILE)
{

View file

@ -144,6 +144,8 @@ EXPORTS
gimp_param_spec_double_array
gimp_param_spec_export_options
gimp_param_spec_file
gimp_param_spec_file_get_action
gimp_param_spec_file_none_allowed
gimp_param_spec_int32_array
gimp_param_spec_memsize
gimp_param_spec_object_duplicate
@ -152,6 +154,8 @@ EXPORTS
gimp_param_spec_object_set_default
gimp_param_spec_parasite
gimp_param_spec_unit
gimp_param_spec_unit_percent_allowed
gimp_param_spec_unit_pixel_allowed
gimp_param_spec_value_array
gimp_param_unit_get_type
gimp_param_value_array_get_type

View file

@ -220,6 +220,19 @@ gimp_param_spec_object_duplicate (GParamSpec *pspec)
* GIMP_TYPE_PARAM_FILE
*/
#define GIMP_PARAM_SPEC_FILE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_FILE, GimpParamSpecFile))
typedef struct _GimpParamSpecFile GimpParamSpecFile;
struct _GimpParamSpecFile
{
GimpParamSpecObject parent_instance;
/*< private >*/
GimpFileChooserAction action;
gboolean none_ok;
};
static void gimp_param_file_class_init (GimpParamSpecObjectClass *klass);
static void gimp_param_file_init (GimpParamSpecFile *fspec);
@ -425,6 +438,37 @@ gimp_param_spec_file (const gchar *name,
return G_PARAM_SPEC (fspec);
}
/**
* gimp_param_spec_file_get_action:
* @pspec: a #GParamSpec to hold a #GFile value.
*
* Returns: the file action tied to @pspec.
*
* Since: 3.0
**/
GimpFileChooserAction
gimp_param_spec_file_get_action (GParamSpec *pspec)
{
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_FILE (pspec), GIMP_FILE_CHOOSER_ACTION_ANY);
return GIMP_PARAM_SPEC_FILE (pspec)->action;
}
/**
* gimp_param_spec_file_none_allowed:
* @pspec: a #GParamSpec to hold a #GFile value.
*
* Returns: %TRUE if a %NULL value is allowed.
*
* Since: 3.0
**/
gboolean
gimp_param_spec_file_none_allowed (GParamSpec *pspec)
{
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_FILE (pspec), FALSE);
return GIMP_PARAM_SPEC_FILE (pspec)->none_ok;
}
/*
* GIMP_TYPE_ARRAY

View file

@ -159,29 +159,22 @@ GParamSpec * gimp_param_spec_object_duplicate (GParamSpec *pspec);
#define GIMP_VALUE_HOLDS_FILE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FILE))
#define GIMP_TYPE_PARAM_FILE (gimp_param_file_get_type ())
#define GIMP_PARAM_SPEC_FILE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_FILE, GimpParamSpecFile))
#define GIMP_IS_PARAM_SPEC_FILE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_FILE))
typedef struct _GimpParamSpecFile GimpParamSpecFile;
struct _GimpParamSpecFile
{
GimpParamSpecObject parent_instance;
GType gimp_param_file_get_type (void) G_GNUC_CONST;
/*< private >*/
GimpFileChooserAction action;
gboolean none_ok;
};
GParamSpec * gimp_param_spec_file (const gchar *name,
const gchar *nick,
const gchar *blurb,
GimpFileChooserAction action,
gboolean none_ok,
GFile *default_value,
GParamFlags flags);
GType gimp_param_file_get_type (void) G_GNUC_CONST;
GimpFileChooserAction gimp_param_spec_file_get_action (GParamSpec *pspec);
gboolean gimp_param_spec_file_none_allowed (GParamSpec *pspec);
GParamSpec * gimp_param_spec_file (const gchar *name,
const gchar *nick,
const gchar *blurb,
GimpFileChooserAction action,
gboolean none_ok,
GFile *default_value,
GParamFlags flags);
/*

View file

@ -930,6 +930,18 @@ gimp_units_to_points (gdouble value,
* GIMP_TYPE_PARAM_UNIT
*/
#define GIMP_PARAM_SPEC_UNIT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_UNIT, GimpParamSpecUnit))
typedef struct _GimpParamSpecUnit GimpParamSpecUnit;
struct _GimpParamSpecUnit
{
GimpParamSpecObject parent_instance;
gboolean allow_pixel;
gboolean allow_percent;
};
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);
@ -1074,6 +1086,38 @@ gimp_param_spec_unit (const gchar *name,
return G_PARAM_SPEC (uspec);
}
/**
* gimp_param_spec_unit_pixel_allowed:
* @pspec: a #GParamSpec to hold an #GimpUnit value.
*
* Returns: %TRUE if the [func@Gimp.Unit.pixel] unit is allowed.
*
* Since: 3.0
**/
gboolean
gimp_param_spec_unit_pixel_allowed (GParamSpec *pspec)
{
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_UNIT (pspec), FALSE);
return GIMP_PARAM_SPEC_UNIT (pspec)->allow_pixel;
}
/**
* gimp_param_spec_unit_percent_allowed:
* @pspec: a #GParamSpec to hold an #GimpUnit value.
*
* Returns: %TRUE if the [func@Gimp.Unit.percent] unit is allowed.
*
* Since: 3.0
**/
gboolean
gimp_param_spec_unit_percent_allowed (GParamSpec *pspec)
{
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_UNIT (pspec), FALSE);
return GIMP_PARAM_SPEC_UNIT (pspec)->allow_percent;
}
static gint
print (gchar *buf,
gint len,

View file

@ -87,29 +87,21 @@ gdouble gimp_units_to_points (gdouble value,
#define GIMP_VALUE_HOLDS_UNIT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_UNIT))
#define GIMP_TYPE_PARAM_UNIT (gimp_param_unit_get_type ())
#define GIMP_PARAM_SPEC_UNIT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_UNIT, GimpParamSpecUnit))
#define GIMP_IS_PARAM_SPEC_UNIT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_UNIT))
typedef struct _GimpParamSpecUnit GimpParamSpecUnit;
struct _GimpParamSpecUnit
{
GimpParamSpecObject parent_instance;
GType gimp_param_unit_get_type (void) G_GNUC_CONST;
gboolean allow_pixel;
gboolean allow_percent;
};
GType gimp_param_unit_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_unit (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean allow_pixel,
gboolean allow_percent,
GimpUnit *default_value,
GParamFlags flags);
GParamSpec * gimp_param_spec_unit (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean allow_pixel,
gboolean allow_percent,
GimpUnit *default_value,
GParamFlags flags);
gboolean gimp_param_spec_unit_pixel_allowed (GParamSpec *pspec);
gboolean gimp_param_spec_unit_percent_allowed (GParamSpec *pspec);
G_END_DECLS

View file

@ -329,16 +329,9 @@ 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);
#define GIMP_PARAM_SPEC_COLOR(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_COLOR, GimpParamSpecColor))
typedef struct _GimpParamSpecColor GimpParamSpecColor;
struct _GimpParamSpecColor
{
@ -362,6 +355,17 @@ struct _GimpParamSpecColor
gboolean validate;
};
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);
GType
gimp_param_color_get_type (void)
{
@ -507,8 +511,7 @@ gimp_param_color_cmp (GParamSpec *param_spec,
*
* 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].
* not change the default color of the returned %GimpParamSpecColor.
*
* Returns: (transfer full): a newly created parameter specification
*/

View file

@ -70,8 +70,9 @@ gboolean gimp_color_is_out_of_gamut (GeglColor *color,
* GIMP_TYPE_PARAM_COLOR
*/
#define GIMP_VALUE_HOLDS_COLOR(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GEGL_TYPE_COLOR))
#define GIMP_TYPE_PARAM_COLOR (gimp_param_color_get_type ())
#define GIMP_PARAM_SPEC_COLOR(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_COLOR, GimpParamSpecColor))
#define GIMP_IS_PARAM_SPEC_COLOR(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_COLOR))
GType gimp_param_color_get_type (void) G_GNUC_CONST;

View file

@ -33,8 +33,6 @@ typedef struct _GimpColorManaged GimpColorManaged; /* dummy typedef */
typedef struct _GimpColorProfile GimpColorProfile;
typedef struct _GimpColorTransform GimpColorTransform;
typedef struct _GimpParamSpecColor GimpParamSpecColor;
G_END_DECLS