libgimp*, plug-ins: now hide GimpParamSpecChoice struct.

New libgimpbase functions:

- gimp_param_spec_choice_get_choice
- gimp_param_spec_choice_get_default

Now the only GParamSpec in libgimpbase whose struct is visible is
GimpParamSpecObject. This can't change since it is derived into param
specs defined in libgimp and therefore needs to be visible.
This commit is contained in:
Jehan 2025-01-25 01:21:13 +01:00
parent 080b09bb96
commit b1acb256e1
12 changed files with 152 additions and 110 deletions

View File

@ -537,13 +537,12 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
/* Must be before G_IS_PARAM_SPEC_STRING() because it's a parent. */
else if (pspec_type == GIMP_TYPE_PARAM_CHOICE)
{
GimpParamSpecChoice *cspec = GIMP_PARAM_SPEC_CHOICE (pspec);
GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
param_def->param_def_type = GP_PARAM_DEF_TYPE_CHOICE;
param_def->meta.m_choice.default_val = sspec->default_value;
param_def->meta.m_choice.choice = cspec->choice;
param_def->meta.m_choice.choice = gimp_param_spec_choice_get_choice (pspec);
}
else if (G_IS_PARAM_SPEC_STRING (pspec) &&
#ifdef LIBGIMP_COMPILATION

View File

@ -57,11 +57,12 @@ gimp_param_spec_unit_desc (GParamSpec *pspec)
static gchar *
gimp_param_spec_choice_desc (GParamSpec *pspec)
{
GimpParamSpecChoice *cspec = GIMP_PARAM_SPEC_CHOICE (pspec);
GList *choices;
GString *desc;
GimpChoice *choice;
GList *choices;
GString *desc;
choices = gimp_choice_list_nicks (cspec->choice);
choice = gimp_param_spec_choice_get_choice (pspec);
choices = gimp_choice_list_nicks (choice);
desc = g_string_new ("\n");
g_string_append_printf (desc, "<i>%s</i>", _("Allowed values:"));
@ -72,7 +73,7 @@ gimp_param_spec_choice_desc (GParamSpec *pspec)
gchar *label = NULL;
gchar *help = NULL;
gimp_choice_get_documentation (cspec->choice, (const gchar *) nick, (const gchar **) &label, (const gchar **) &help);
gimp_choice_get_documentation (choice, (const gchar *) nick, (const gchar **) &label, (const gchar **) &help);
nick = g_markup_escape_text (nick, -1);
label = g_markup_escape_text (label, -1);
help = (help != NULL ? g_markup_escape_text (help, -1) : NULL);

View File

@ -671,11 +671,11 @@ gimp_procedure_config_set_color_array (GimpProcedureConfig *config,
/**
* gimp_procedure_config_get_choice_id:
* @config: a #GimpProcedureConfig
* @property_name: the name of a [struct@ParamSpecChoice] property.
* @property_name: the name of a #GimpParamSpecChoice property.
*
* A utility function which will get the current string value of a
* [struct@ParamSpecChoice] property in @config and convert it to the integer ID
* mapped to this value.
* #GimpParamSpecChoice property in @config and convert it to the
* integer ID mapped to this value.
* This makes it easy to work with an Enum type locally, within a plug-in code.
*
* Since: 3.0
@ -684,10 +684,10 @@ gint
gimp_procedure_config_get_choice_id (GimpProcedureConfig *config,
const gchar *property_name)
{
GParamSpec *param_spec;
GimpParamSpecChoice *cspec;
gchar *value = NULL;
gint id;
GParamSpec *param_spec;
GimpChoice *choice;
gchar *value = NULL;
gint id;
param_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (config),
property_name);
@ -711,11 +711,11 @@ gimp_procedure_config_get_choice_id (GimpProcedureConfig *config,
return 0;
}
cspec = GIMP_PARAM_SPEC_CHOICE (param_spec);
choice = gimp_param_spec_choice_get_choice (param_spec);
g_object_get (config,
property_name, &value,
NULL);
id = gimp_choice_get_id (cspec->choice, value);
id = gimp_choice_get_id (choice, value);
g_free (value);

View File

@ -140,6 +140,8 @@ EXPORTS
gimp_param_parasite_get_type
gimp_param_spec_array
gimp_param_spec_choice
gimp_param_spec_choice_get_choice
gimp_param_spec_choice_get_default
gimp_param_spec_core_object_array
gimp_param_spec_core_object_array_get_object_type
gimp_param_spec_double_array

View File

@ -401,6 +401,17 @@ gimp_choice_desc_free (GimpChoiceDesc *desc)
* GIMP_TYPE_PARAM_CHOICE
*/
#define GIMP_PARAM_SPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_CHOICE, GimpParamSpecChoice))
typedef struct _GimpParamSpecChoice GimpParamSpecChoice;
struct _GimpParamSpecChoice
{
GParamSpecString parent_instance;
GimpChoice *choice;
};
static void gimp_param_choice_class_init (GParamSpecClass *klass);
static void gimp_param_choice_init (GParamSpec *pspec);
static void gimp_param_choice_finalize (GParamSpec *pspec);
@ -568,3 +579,39 @@ gimp_param_spec_choice (const gchar *name,
return G_PARAM_SPEC (choice_spec);
}
/**
* gimp_param_spec_choice_get_choice:
* @pspec: a #GParamSpec to hold a #GimpParamSpecChoice value.
*
* Returns: (transfer none): the choice object defining the valid values.
*
* Since: 3.0
**/
GimpChoice *
gimp_param_spec_choice_get_choice (GParamSpec *pspec)
{
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_CHOICE (pspec), NULL);
return GIMP_PARAM_SPEC_CHOICE (pspec)->choice;
}
/**
* gimp_param_spec_choice_get_default:
* @pspec: a #GParamSpec to hold a #GimpParamSpecChoice value.
*
* Returns: the default value.
*
* Since: 3.0
**/
const gchar *
gimp_param_spec_choice_get_default (GParamSpec *pspec)
{
const GValue *value;
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_CHOICE (pspec), NULL);
value = g_param_spec_get_default_value (pspec);
return g_value_get_string (value);
}

View File

@ -73,26 +73,20 @@ void gimp_choice_set_sensitive (GimpChoice *choice,
*/
#define GIMP_TYPE_PARAM_CHOICE (gimp_param_choice_get_type ())
#define GIMP_PARAM_SPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_CHOICE, GimpParamSpecChoice))
#define GIMP_IS_PARAM_SPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_CHOICE))
typedef struct _GimpParamSpecChoice GimpParamSpecChoice;
struct _GimpParamSpecChoice
{
GParamSpecString parent_instance;
GType gimp_param_choice_get_type (void) G_GNUC_CONST;
GimpChoice *choice;
};
GParamSpec * gimp_param_spec_choice (const gchar *name,
const gchar *nick,
const gchar *blurb,
GimpChoice *choice,
const gchar *default_value,
GParamFlags flags);
GType gimp_param_choice_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_choice (const gchar *name,
const gchar *nick,
const gchar *blurb,
GimpChoice *choice,
const gchar *default_value,
GParamFlags flags);
GimpChoice * gimp_param_spec_choice_get_choice (GParamSpec *pspec);
const gchar * gimp_param_spec_choice_get_default (GParamSpec *pspec);
G_END_DECLS

View File

@ -96,11 +96,9 @@ gimp_config_param_spec_duplicate (GParamSpec *pspec)
if (GIMP_IS_PARAM_SPEC_CHOICE (pspec))
{
GimpParamSpecChoice *cspec = GIMP_PARAM_SPEC_CHOICE (pspec);
copy = gimp_param_spec_choice (name, nick, blurb,
g_object_ref (cspec->choice),
spec->default_value,
g_object_ref (gimp_param_spec_choice_get_choice (pspec)),
gimp_param_spec_choice_get_default (pspec),
flags);
}
else if (GEGL_IS_PARAM_SPEC_FILE_PATH (pspec))

View File

@ -2622,12 +2622,12 @@ GtkWidget *
gimp_prop_choice_combo_box_new (GObject *config,
const gchar *property_name)
{
GParamSpec *param_spec;
GimpParamSpecChoice *cspec;
GtkWidget *combo_box;
GtkListStore *store;
GList *values;
GList *iter;
GParamSpec *param_spec;
GimpChoice *choice;
GtkWidget *combo_box;
GtkListStore *store;
GList *values;
GList *iter;
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
g_return_val_if_fail (property_name != NULL, NULL);
@ -2637,14 +2637,14 @@ gimp_prop_choice_combo_box_new (GObject *config,
if (! param_spec)
return NULL;
cspec = GIMP_PARAM_SPEC_CHOICE (param_spec);
values = gimp_choice_list_nicks (cspec->choice);
choice = gimp_param_spec_choice_get_choice (param_spec);
values = gimp_choice_list_nicks (choice);
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
for (iter = values; iter; iter = iter->next)
{
const gchar *nick = iter->data;
const gchar *label = gimp_choice_get_label (cspec->choice, nick);
const gchar *label = gimp_choice_get_label (choice, nick);
gtk_list_store_insert_with_values (store, NULL, -1,
0, nick,
@ -2658,8 +2658,8 @@ gimp_prop_choice_combo_box_new (GObject *config,
gimp_string_combo_box_set_sensitivity (GIMP_STRING_COMBO_BOX (combo_box),
(GimpStringSensitivityFunc) gimp_prop_choice_combo_box_is_sensitive,
cspec->choice, NULL);
g_signal_connect_swapped (cspec->choice, "sensitivity-changed",
choice, NULL);
g_signal_connect_swapped (choice, "sensitivity-changed",
G_CALLBACK (gtk_widget_queue_draw),
combo_box);
@ -2764,12 +2764,12 @@ GtkWidget *
gimp_prop_choice_radio_frame_new (GObject *config,
const gchar *property_name)
{
GParamSpec *param_spec;
GimpParamSpecChoice *cspec;
GtkWidget *frame;
GimpIntStore *store;
GList *values;
GList *iter;
GParamSpec *param_spec;
GimpChoice *choice;
GtkWidget *frame;
GimpIntStore *store;
GList *values;
GList *iter;
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
g_return_val_if_fail (property_name != NULL, NULL);
@ -2779,15 +2779,15 @@ gimp_prop_choice_radio_frame_new (GObject *config,
if (! param_spec)
return NULL;
cspec = GIMP_PARAM_SPEC_CHOICE (param_spec);
values = gimp_choice_list_nicks (cspec->choice);
choice = gimp_param_spec_choice_get_choice (param_spec);
values = gimp_choice_list_nicks (choice);
store = g_object_new (GIMP_TYPE_INT_STORE, NULL);
for (iter = values; iter; iter = iter->next)
{
const gchar *nick = iter->data;
const gchar *label = gimp_choice_get_label (cspec->choice, nick);
gint id = gimp_choice_get_id (cspec->choice, nick);
const gchar *label = gimp_choice_get_label (choice, nick);
gint id = gimp_choice_get_id (choice, nick);
gtk_list_store_insert_with_values (GTK_LIST_STORE (store), NULL, -1,
GIMP_INT_STORE_VALUE, id,
@ -2803,14 +2803,14 @@ gimp_prop_choice_radio_frame_new (GObject *config,
gimp_int_radio_frame_set_sensitivity (GIMP_INT_RADIO_FRAME (frame),
(GimpIntRadioFrameSensitivityFunc) gimp_prop_widget_choice_is_sensitive,
cspec->choice, NULL);
choice, NULL);
g_object_bind_property_full (config, property_name,
frame, "value",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
gimp_prop_widget_choice_string_to_int,
gimp_prop_widget_choice_int_to_string,
cspec->choice, NULL);
choice, NULL);
gimp_widget_set_bound_property (frame, config, property_name);

View File

@ -936,11 +936,12 @@ open_dialog (GimpProcedure *procedure,
gint num_components,
GError **error)
{
const gchar *title;
GtkWidget *dialog;
gboolean run;
GimpParamSpecChoice *cspec;
OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_SRGB;
const gchar *title;
GtkWidget *dialog;
gboolean run;
GParamSpec *cspec;
GimpChoice *choice;
OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_SRGB;
if (format == OPJ_CODEC_J2K)
/* Not having color information is expected. */
@ -955,21 +956,19 @@ open_dialog (GimpProcedure *procedure,
GIMP_PROCEDURE_CONFIG (config),
_(title));
cspec =
GIMP_PARAM_SPEC_CHOICE (g_object_class_find_property (G_OBJECT_GET_CLASS (config),
"colorspace"));
cspec = g_object_class_find_property (G_OBJECT_GET_CLASS (config), "colorspace");
choice = gimp_param_spec_choice_get_choice (cspec);
if (num_components == 3)
{
/* Can be RGB, YUV and YCC. */
gimp_choice_set_sensitive (cspec->choice, "grayscale", FALSE);
gimp_choice_set_sensitive (cspec->choice, "cmyk", FALSE);
gimp_choice_set_sensitive (choice, "grayscale", FALSE);
gimp_choice_set_sensitive (choice, "cmyk", FALSE);
}
else if (num_components == 4)
{
/* Can be RGB, YUV and YCC with alpha or CMYK. */
gimp_choice_set_sensitive (cspec->choice, "grayscale", FALSE);
gimp_choice_set_sensitive (choice, "grayscale", FALSE);
}
else
{
@ -984,7 +983,7 @@ open_dialog (GimpProcedure *procedure,
if (num_components == 3 || num_components == 4)
{
/* By default, RGB is active. */
gimp_choice_set_sensitive (cspec->choice, "unknown", FALSE);
gimp_choice_set_sensitive (choice, "unknown", FALSE);
g_object_set (config, "colorspace", "srgb", NULL);
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dialog),

View File

@ -1607,14 +1607,14 @@ mng_save_dialog (GimpImage *image,
if (num_layers == 1)
{
GimpParamSpecChoice *cspec;
GParamSpec *cspec;
GimpChoice *choice;
cspec =
GIMP_PARAM_SPEC_CHOICE (g_object_class_find_property (G_OBJECT_GET_CLASS (config),
"default-chunks"));
cspec = g_object_class_find_property (G_OBJECT_GET_CLASS (config), "default-chunks");
choice = gimp_param_spec_choice_get_choice (cspec);
gimp_choice_set_sensitive (cspec->choice, "all-png", FALSE);
gimp_choice_set_sensitive (cspec->choice, "all-jng", FALSE);
gimp_choice_set_sensitive (choice, "all-png", FALSE);
gimp_choice_set_sensitive (choice, "all-jng", FALSE);
}
combo = gimp_procedure_dialog_get_widget (GIMP_PROCEDURE_DIALOG (dialog),

View File

@ -1748,8 +1748,9 @@ config_notify (GimpProcedureConfig *config,
}
else if (! strcmp (pspec->name, "save-type"))
{
gint savetype;
GimpParamSpecChoice *pspec;
GParamSpec *cspec;
GimpChoice *choice;
gint savetype;
savetype = gimp_procedure_config_get_choice_id (config, "save-type");
@ -1774,9 +1775,9 @@ config_notify (GimpProcedureConfig *config,
break;
}
pspec = GIMP_PARAM_SPEC_CHOICE (g_object_class_find_property (G_OBJECT_GET_CLASS (config),
"mipmaps"));
gimp_choice_set_sensitive (pspec->choice, "existing", check_mipmaps (savetype));
cspec = g_object_class_find_property (G_OBJECT_GET_CLASS (config), "mipmaps");
choice = gimp_param_spec_choice_get_choice (cspec);
gimp_choice_set_sensitive (choice, "existing", check_mipmaps (savetype));
}
else if (! strcmp (pspec->name, "mipmaps"))
{
@ -1906,10 +1907,11 @@ save_dialog (GimpImage *image,
GimpProcedure *procedure,
GimpProcedureConfig *config)
{
GtkWidget *dialog;
GimpParamSpecChoice *cspec;
GimpImageBaseType base_type;
gboolean run;
GtkWidget *dialog;
GParamSpec *cspec;
GimpChoice *choice;
GimpImageBaseType base_type;
gboolean run;
base_type = gimp_image_get_base_type (image);
@ -1956,17 +1958,17 @@ save_dialog (GimpImage *image,
gimp_procedure_dialog_get_widget (GIMP_PROCEDURE_DIALOG (dialog),
"save-type", G_TYPE_NONE);
cspec = GIMP_PARAM_SPEC_CHOICE (g_object_class_find_property (G_OBJECT_GET_CLASS (config),
"save-type"));
gimp_choice_set_sensitive (cspec->choice, "cube", is_cubemap);
gimp_choice_set_sensitive (cspec->choice, "volume", is_volume);
gimp_choice_set_sensitive (cspec->choice, "array", is_array);
cspec = g_object_class_find_property (G_OBJECT_GET_CLASS (config), "save-type");
choice = gimp_param_spec_choice_get_choice (cspec);
gimp_choice_set_sensitive (choice, "cube", is_cubemap);
gimp_choice_set_sensitive (choice, "volume", is_volume);
gimp_choice_set_sensitive (choice, "array", is_array);
gimp_procedure_dialog_get_widget (GIMP_PROCEDURE_DIALOG (dialog),
"mipmaps", G_TYPE_NONE);
cspec = GIMP_PARAM_SPEC_CHOICE (g_object_class_find_property (G_OBJECT_GET_CLASS (config),
"mipmaps"));
gimp_choice_set_sensitive (cspec->choice, "existing",
cspec = g_object_class_find_property (G_OBJECT_GET_CLASS (config), "mipmaps");
choice = gimp_param_spec_choice_get_choice (cspec);
gimp_choice_set_sensitive (choice, "existing",
! (is_volume || is_cubemap) && is_mipmap_chain_valid);
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dialog),

View File

@ -1234,22 +1234,22 @@ save_dialog (GimpImage *image,
gboolean is_multi_layer,
gboolean classic_tiff_failed)
{
GtkWidget *dialog;
GtkWidget *profile_label;
gchar **parasites;
GimpCompression compression;
gboolean run;
gboolean has_geotiff = FALSE;
gint i;
GimpColorProfile *cmyk_profile = NULL;
GParamSpec *comp_spec;
GimpParamSpecChoice *cspec;
GtkWidget *dialog;
GtkWidget *profile_label;
gchar **parasites;
GimpCompression compression;
gboolean run;
gboolean has_geotiff = FALSE;
gint i;
GimpColorProfile *cmyk_profile = NULL;
GParamSpec *cspec;
GimpChoice *choice;
comp_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (config), "compression");
cspec = GIMP_PARAM_SPEC_CHOICE (comp_spec);
gimp_choice_set_sensitive (cspec->choice, "ccittfax3", is_monochrome);
gimp_choice_set_sensitive (cspec->choice, "ccittfax4", is_monochrome);
gimp_choice_set_sensitive (cspec->choice, "jpeg", ! is_indexed);
cspec = g_object_class_find_property (G_OBJECT_GET_CLASS (config), "compression");
choice = gimp_param_spec_choice_get_choice (cspec);
gimp_choice_set_sensitive (choice, "ccittfax3", is_monochrome);
gimp_choice_set_sensitive (choice, "ccittfax4", is_monochrome);
gimp_choice_set_sensitive (choice, "jpeg", ! is_indexed);
parasites = gimp_image_get_parasite_list (image);
for (i = 0; i < g_strv_length (parasites); i++)