Introduce a global ID space for GimpData/GimpResource objects

Much like for images and items. Change the PDB to transmit IDs
instead of names for brush, pattern etc. and refactor a whole
lot of libgimp code to deal with it.

	modified:   libgimp/gimpplugin-private.h
This commit is contained in:
Michael Natterer 2023-05-31 16:12:04 +02:00
parent 493156cc7a
commit 9638102418
69 changed files with 2985 additions and 2649 deletions

View File

@ -29,6 +29,7 @@
#include "gimp-memsize.h" #include "gimp-memsize.h"
#include "gimpdata.h" #include "gimpdata.h"
#include "gimpidtable.h"
#include "gimptag.h" #include "gimptag.h"
#include "gimptagged.h" #include "gimptagged.h"
@ -44,6 +45,7 @@ enum
enum enum
{ {
PROP_0, PROP_0,
PROP_ID,
PROP_FILE, PROP_FILE,
PROP_WRITABLE, PROP_WRITABLE,
PROP_DELETABLE, PROP_DELETABLE,
@ -53,6 +55,7 @@ enum
struct _GimpDataPrivate struct _GimpDataPrivate
{ {
gint ID;
GFile *file; GFile *file;
GQuark mime_type; GQuark mime_type;
guint writable : 1; guint writable : 1;
@ -115,6 +118,8 @@ G_DEFINE_TYPE_WITH_CODE (GimpData, gimp_data, GIMP_TYPE_VIEWABLE,
static guint data_signals[LAST_SIGNAL] = { 0 }; static guint data_signals[LAST_SIGNAL] = { 0 };
static GimpIdTable *data_id_table = NULL;
static void static void
gimp_data_class_init (GimpDataClass *klass) gimp_data_class_init (GimpDataClass *klass)
@ -151,6 +156,11 @@ gimp_data_class_init (GimpDataClass *klass)
klass->duplicate = gimp_data_real_duplicate; klass->duplicate = gimp_data_real_duplicate;
klass->compare = gimp_data_real_compare; klass->compare = gimp_data_real_compare;
g_object_class_install_property (object_class, PROP_ID,
g_param_spec_int ("id", NULL, NULL,
0, G_MAXINT, 0,
GIMP_PARAM_READABLE));
g_object_class_install_property (object_class, PROP_FILE, g_object_class_install_property (object_class, PROP_FILE,
g_param_spec_object ("file", NULL, NULL, g_param_spec_object ("file", NULL, NULL,
G_TYPE_FILE, G_TYPE_FILE,
@ -171,6 +181,8 @@ gimp_data_class_init (GimpDataClass *klass)
NULL, NULL,
GIMP_PARAM_READWRITE | GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY)); G_PARAM_CONSTRUCT_ONLY));
data_id_table = gimp_id_table_new ();
} }
static void static void
@ -190,6 +202,7 @@ gimp_data_init (GimpData *data)
data->priv = private; data->priv = private;
private->ID = gimp_id_table_insert (data_id_table, data);
private->writable = TRUE; private->writable = TRUE;
private->deletable = TRUE; private->deletable = TRUE;
private->dirty = TRUE; private->dirty = TRUE;
@ -216,6 +229,8 @@ gimp_data_finalize (GObject *object)
{ {
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object); GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object);
gimp_id_table_remove (data_id_table, private->ID);
g_clear_object (&private->file); g_clear_object (&private->file);
if (private->tags) if (private->tags)
@ -278,6 +293,10 @@ gimp_data_get_property (GObject *object,
switch (property_id) switch (property_id)
{ {
case PROP_ID:
g_value_set_int (value, private->ID);
break;
case PROP_FILE: case PROP_FILE:
g_value_set_object (value, private->file); g_value_set_object (value, private->file);
break; break;
@ -492,6 +511,23 @@ gimp_data_get_checksum (GimpTagged *tagged)
return NULL; return NULL;
} }
/* public functions */
gint
gimp_data_get_id (GimpData *data)
{
g_return_val_if_fail (GIMP_IS_DATA (data), -1);
return GIMP_DATA_GET_PRIVATE (data)->ID;
}
GimpData *
gimp_data_get_by_id (gint data_id)
{
return (GimpData *) gimp_id_table_lookup (data_id_table, data_id);
}
/** /**
* gimp_data_save: * gimp_data_save:
* @data: object whose contents are to be saved. * @data: object whose contents are to be saved.

View File

@ -74,6 +74,9 @@ struct _GimpDataClass
GType gimp_data_get_type (void) G_GNUC_CONST; GType gimp_data_get_type (void) G_GNUC_CONST;
gint gimp_data_get_id (GimpData *data);
GimpData * gimp_data_get_by_id (gint id);
gboolean gimp_data_save (GimpData *data, gboolean gimp_data_save (GimpData *data,
GError **error); GError **error);

View File

@ -25,25 +25,22 @@
#include "core-types.h" #include "core-types.h"
#include "gimp.h" #include "gimp.h"
#include "gimpbrush.h"
#include "gimpdisplay.h" #include "gimpdisplay.h"
#include "gimpgradient.h"
#include "gimpimage.h" #include "gimpimage.h"
#include "gimplayer.h" #include "gimplayer.h"
#include "gimplayermask.h" #include "gimplayermask.h"
#include "gimppalette.h"
#include "gimpparamspecs.h" #include "gimpparamspecs.h"
#include "gimppattern.h"
#include "gimpselection.h" #include "gimpselection.h"
#include "text/gimpfont.h"
#include "text/gimptextlayer.h" #include "text/gimptextlayer.h"
#include "vectors/gimpvectors.h" #include "vectors/gimpvectors.h"
/* resource types */
#include "gimpresource.h"
#include "gimpbrush.h"
#include "gimpgradient.h"
#include "gimppalette.h"
#include "gimppattern.h"
#include "text/gimpfont.h"
/* /*
* GIMP_TYPE_PARAM_STRING * GIMP_TYPE_PARAM_STRING
@ -346,15 +343,14 @@ gimp_param_spec_enum_exclude_value (GimpParamSpecEnum *espec,
/* include the implementation of the remaining paramspecs, they are /* include the implementation of the remaining paramspecs, they are
* shared between app/ and libgimp/ but need different headers. * shared between app/ and libgimp/ but need different headers.
*/ */
#define gimp_image_is_valid(image) TRUE #define gimp_image_is_valid(image) TRUE
#define gimp_item_is_valid(item) TRUE #define gimp_item_is_valid(item) TRUE
#define gimp_display_is_valid(display) TRUE #define gimp_display_is_valid(display) TRUE
/* resource types. */ #define gimp_resource_is_valid(image) TRUE
#define gimp_brush_is_valid(image) TRUE #define gimp_brush_is_valid(image) TRUE
#define gimp_font_is_valid(image) TRUE #define gimp_font_is_valid(image) TRUE
#define gimp_gradient_is_valid(image) TRUE #define gimp_gradient_is_valid(image) TRUE
#define gimp_palette_is_valid(image) TRUE #define gimp_palette_is_valid(image) TRUE
#define gimp_pattern_is_valid(image) TRUE #define gimp_pattern_is_valid(image) TRUE
#include "../../libgimp/gimpparamspecs-body.c" #include "../../libgimp/gimpparamspecs-body.c"
#include "../../libgimp/gimpparamspecs-body-resource.c"

View File

@ -63,10 +63,42 @@ brush_new_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
brush = (GimpBrush*) gimp_data_factory_data_new (gimp->brush_factory, brush = (GimpBrush *) gimp_data_factory_data_new (gimp->brush_factory,
context, name); context, name);
if (!brush) if (! brush)
success = FALSE;
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_object (gimp_value_array_index (return_vals, 1), brush);
return return_vals;
}
static GimpValueArray *
brush_get_by_name_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
const gchar *name;
GimpBrush *brush = NULL;
name = g_value_get_string (gimp_value_array_index (args, 0));
if (success)
{
brush = gimp_pdb_get_brush (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
if (! brush)
success = FALSE; success = FALSE;
} }
@ -98,7 +130,7 @@ brush_duplicate_invoker (GimpProcedure *procedure,
{ {
brush_copy = (GimpBrush *) brush_copy = (GimpBrush *)
gimp_data_factory_data_duplicate (gimp->brush_factory, GIMP_DATA (brush)); gimp_data_factory_data_duplicate (gimp->brush_factory, GIMP_DATA (brush));
/* Assert the copy has a unique name. */
if (!brush_copy) if (!brush_copy)
success = FALSE; success = FALSE;
} }
@ -141,33 +173,6 @@ brush_is_generated_invoker (GimpProcedure *procedure,
return return_vals; return return_vals;
} }
static GimpValueArray *
brush_id_is_valid_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
GimpValueArray *return_vals;
const gchar *id;
gboolean valid = FALSE;
id = g_value_get_string (gimp_value_array_index (args, 0));
valid = (gimp_pdb_get_brush (gimp, id, GIMP_PDB_DATA_ACCESS_READ, error) != NULL);
/* When ID is not valid, NULL is returned and error is set.
* Clear error so GIMP not display error dialog.
*/
g_clear_error (error);
return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
g_value_set_boolean (gimp_value_array_index (return_vals, 1), valid);
return return_vals;
}
static GimpValueArray * static GimpValueArray *
brush_rename_invoker (GimpProcedure *procedure, brush_rename_invoker (GimpProcedure *procedure,
Gimp *gimp, Gimp *gimp,
@ -921,6 +926,36 @@ register_brush_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure); gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure); g_object_unref (procedure);
/*
* gimp-brush-get-by-name
*/
procedure = gimp_procedure_new (brush_get_by_name_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-brush-get-by-name");
gimp_procedure_set_static_help (procedure,
"Returns the brush with the given name.",
"Returns the brush with the given name.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2023");
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("name",
"name",
"The name of the brush",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_brush ("brush",
"brush",
"The brush",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/* /*
* gimp-brush-duplicate * gimp-brush-duplicate
*/ */
@ -979,36 +1014,6 @@ register_brush_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure); gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure); g_object_unref (procedure);
/*
* gimp-brush-id-is-valid
*/
procedure = gimp_procedure_new (brush_id_is_valid_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-brush-id-is-valid");
gimp_procedure_set_static_help (procedure,
"Whether the ID is a valid reference to installed brush data.",
"Returns TRUE when ID is valid.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Lloyd Konneker",
"Lloyd Konneker",
"2022");
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("id",
"id",
"The brush ID",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("valid",
"valid",
"TRUE if the brush ID is valid",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/* /*
* gimp-brush-rename * gimp-brush-rename
*/ */

View File

@ -31,6 +31,7 @@
#include "core/gimp.h" #include "core/gimp.h"
#include "core/gimpparamspecs.h" #include "core/gimpparamspecs.h"
#include "text/gimpfont.h"
#include "gimppdb.h" #include "gimppdb.h"
#include "gimppdb-utils.h" #include "gimppdb-utils.h"
@ -39,28 +40,33 @@
static GimpValueArray * static GimpValueArray *
font_id_is_valid_invoker (GimpProcedure *procedure, font_get_by_name_invoker (GimpProcedure *procedure,
Gimp *gimp, Gimp *gimp,
GimpContext *context, GimpContext *context,
GimpProgress *progress, GimpProgress *progress,
const GimpValueArray *args, const GimpValueArray *args,
GError **error) GError **error)
{ {
gboolean success = TRUE;
GimpValueArray *return_vals; GimpValueArray *return_vals;
const gchar *id; const gchar *name;
gboolean valid = FALSE; GimpFont *font = NULL;
id = g_value_get_string (gimp_value_array_index (args, 0)); name = g_value_get_string (gimp_value_array_index (args, 0));
valid = (gimp_pdb_get_font (gimp, id, error) != NULL); if (success)
{
font = gimp_pdb_get_font (gimp, name, error);
/* When ID is not valid, NULL is returned and error is set. if (! font)
* Clear error so GIMP not display error dialog. success = FALSE;
*/ }
g_clear_error (error);
return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL); return_vals = gimp_procedure_get_return_values (procedure, success,
g_value_set_boolean (gimp_value_array_index (return_vals, 1), valid); error ? *error : NULL);
if (success)
g_value_set_object (gimp_value_array_index (return_vals, 1), font);
return return_vals; return return_vals;
} }
@ -71,30 +77,30 @@ register_font_procs (GimpPDB *pdb)
GimpProcedure *procedure; GimpProcedure *procedure;
/* /*
* gimp-font-id-is-valid * gimp-font-get-by-name
*/ */
procedure = gimp_procedure_new (font_id_is_valid_invoker); procedure = gimp_procedure_new (font_get_by_name_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure), gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-font-id-is-valid"); "gimp-font-get-by-name");
gimp_procedure_set_static_help (procedure, gimp_procedure_set_static_help (procedure,
"Whether the ID is a valid reference to installed data.", "Returns the font with the given name.",
"Returns TRUE if this ID is valid.", "Returns the font with the given name.",
NULL); NULL);
gimp_procedure_set_static_attribution (procedure, gimp_procedure_set_static_attribution (procedure,
"Lloyd Konneker", "Michael Natterer <mitch@gimp.org>",
"Lloyd Konneker", "Michael Natterer",
"2022"); "2023");
gimp_procedure_add_argument (procedure, gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("id", gimp_param_spec_string ("name",
"id", "name",
"The font ID", "The name of the font",
FALSE, FALSE, TRUE, FALSE, FALSE, TRUE,
NULL, NULL,
GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE)); GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure, gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("valid", gimp_param_spec_font ("font",
"valid", "font",
"TRUE if the font ID is valid", "The font",
FALSE, FALSE,
GIMP_PARAM_READWRITE)); GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure); gimp_pdb_register_procedure (pdb, procedure);

View File

@ -79,6 +79,38 @@ gradient_new_invoker (GimpProcedure *procedure,
return return_vals; return return_vals;
} }
static GimpValueArray *
gradient_get_by_name_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
const gchar *name;
GimpGradient *gradient = NULL;
name = g_value_get_string (gimp_value_array_index (args, 0));
if (success)
{
gradient = gimp_pdb_get_gradient (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
if (! gradient)
success = FALSE;
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_object (gimp_value_array_index (return_vals, 1), gradient);
return return_vals;
}
static GimpValueArray * static GimpValueArray *
gradient_duplicate_invoker (GimpProcedure *procedure, gradient_duplicate_invoker (GimpProcedure *procedure,
Gimp *gimp, Gimp *gimp,
@ -98,8 +130,8 @@ gradient_duplicate_invoker (GimpProcedure *procedure,
{ {
gradient_copy = (GimpGradient *) gradient_copy = (GimpGradient *)
gimp_data_factory_data_duplicate (gimp->gradient_factory, GIMP_DATA (gradient)); gimp_data_factory_data_duplicate (gimp->gradient_factory, GIMP_DATA (gradient));
/* Assert the copy has a unique name. */
if (!gradient_copy) if (! gradient_copy)
success = FALSE; success = FALSE;
} }
@ -160,16 +192,9 @@ gradient_rename_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
/* Rename the gradient in app. */
gimp_object_set_name (GIMP_OBJECT (gradient), new_name); gimp_object_set_name (GIMP_OBJECT (gradient), new_name);
/* Assert GIMP might have set a name different from new_name. */
/* Return a reference. gradient_renamed = gradient;
* The wire protocol will create a new proxy on the plugin side.
* We don't need an alias here, except to make clear
* that we are returning the same real object as passed.
*/
gradient_renamed = gradient;
} }
return_vals = gimp_procedure_get_return_values (procedure, success, return_vals = gimp_procedure_get_return_values (procedure, success,
@ -376,33 +401,6 @@ gradient_get_custom_samples_invoker (GimpProcedure *procedure,
return return_vals; return return_vals;
} }
static GimpValueArray *
gradient_id_is_valid_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
GimpValueArray *return_vals;
const gchar *id;
gboolean valid = FALSE;
id = g_value_get_string (gimp_value_array_index (args, 0));
valid = (gimp_pdb_get_gradient (gimp, id, GIMP_PDB_DATA_ACCESS_READ, error) != NULL);
/* When ID is not valid, NULL is returned and error is set.
* Clear error so GIMP not display error dialog.
*/
g_clear_error (error);
return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
g_value_set_boolean (gimp_value_array_index (return_vals, 1), valid);
return return_vals;
}
static GimpValueArray * static GimpValueArray *
gradient_segment_get_left_color_invoker (GimpProcedure *procedure, gradient_segment_get_left_color_invoker (GimpProcedure *procedure,
Gimp *gimp, Gimp *gimp,
@ -1432,6 +1430,36 @@ register_gradient_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure); gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure); g_object_unref (procedure);
/*
* gimp-gradient-get-by-name
*/
procedure = gimp_procedure_new (gradient_get_by_name_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-gradient-get-by-name");
gimp_procedure_set_static_help (procedure,
"Returns the gradient with the given name.",
"Returns the gradient with the given name.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2023");
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("name",
"name",
"The name of the gradient",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_gradient ("gradient",
"gradient",
"The gradient",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/* /*
* gimp-gradient-duplicate * gimp-gradient-duplicate
*/ */
@ -1498,8 +1526,7 @@ register_gradient_procs (GimpPDB *pdb)
"gimp-gradient-rename"); "gimp-gradient-rename");
gimp_procedure_set_static_help (procedure, gimp_procedure_set_static_help (procedure,
"Renames a gradient. When the name is in use, renames to a unique name.", "Renames a gradient. When the name is in use, renames to a unique name.",
"Renames a gradient. The name is the same as the ID. When the proposed name is already used, GIMP generates a unique name, which get_id() will return.\n" "Renames a gradient.",
"Returns a reference to a renamed gradient, which you should assign to the original var or a differently named var. Any existing references will be invalid. Resources in plugins are proxies holding an ID, which can be invalid when the resource is renamed.",
NULL); NULL);
gimp_procedure_set_static_attribution (procedure, gimp_procedure_set_static_attribution (procedure,
"Shlomi Fish <shlomif@iglu.org.il>", "Shlomi Fish <shlomif@iglu.org.il>",
@ -1676,36 +1703,6 @@ register_gradient_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure); gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure); g_object_unref (procedure);
/*
* gimp-gradient-id-is-valid
*/
procedure = gimp_procedure_new (gradient_id_is_valid_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-gradient-id-is-valid");
gimp_procedure_set_static_help (procedure,
"Whether the ID is a valid reference to installed data.",
"Returns TRUE if this ID is valid.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Lloyd Konneker",
"Lloyd Konneker",
"2022");
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("id",
"id",
"The gradient ID",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("valid",
"valid",
"TRUE if the gradient ID is valid",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/* /*
* gimp-gradient-segment-get-left-color * gimp-gradient-segment-get-left-color
*/ */

View File

@ -30,7 +30,7 @@
#include "internal-procs.h" #include "internal-procs.h"
/* 772 procedures registered total */ /* 779 procedures registered total */
void void
internal_procs_init (GimpPDB *pdb) internal_procs_init (GimpPDB *pdb)
@ -85,6 +85,7 @@ internal_procs_init (GimpPDB *pdb)
register_plug_in_procs (pdb); register_plug_in_procs (pdb);
register_plug_in_compat_procs (pdb); register_plug_in_compat_procs (pdb);
register_progress_procs (pdb); register_progress_procs (pdb);
register_resource_procs (pdb);
register_selection_procs (pdb); register_selection_procs (pdb);
register_text_layer_procs (pdb); register_text_layer_procs (pdb);
register_text_tool_procs (pdb); register_text_tool_procs (pdb);

View File

@ -72,6 +72,7 @@ void register_pdb_procs (GimpPDB *pdb);
void register_plug_in_procs (GimpPDB *pdb); void register_plug_in_procs (GimpPDB *pdb);
void register_plug_in_compat_procs (GimpPDB *pdb); void register_plug_in_compat_procs (GimpPDB *pdb);
void register_progress_procs (GimpPDB *pdb); void register_progress_procs (GimpPDB *pdb);
void register_resource_procs (GimpPDB *pdb);
void register_selection_procs (GimpPDB *pdb); void register_selection_procs (GimpPDB *pdb);
void register_text_layer_procs (GimpPDB *pdb); void register_text_layer_procs (GimpPDB *pdb);
void register_text_tool_procs (GimpPDB *pdb); void register_text_tool_procs (GimpPDB *pdb);

View File

@ -57,6 +57,7 @@ libappinternalprocs_sources = [
'plug-in-cmds.c', 'plug-in-cmds.c',
'plug-in-compat-cmds.c', 'plug-in-compat-cmds.c',
'progress-cmds.c', 'progress-cmds.c',
'resource-cmds.c',
'selection-cmds.c', 'selection-cmds.c',
'text-layer-cmds.c', 'text-layer-cmds.c',
'text-tool-cmds.c', 'text-tool-cmds.c',

View File

@ -76,6 +76,38 @@ palette_new_invoker (GimpProcedure *procedure,
return return_vals; return return_vals;
} }
static GimpValueArray *
palette_get_by_name_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
const gchar *name;
GimpPalette *palette = NULL;
name = g_value_get_string (gimp_value_array_index (args, 0));
if (success)
{
palette = gimp_pdb_get_palette (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
if (! palette)
success = FALSE;
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_object (gimp_value_array_index (return_vals, 1), palette);
return return_vals;
}
static GimpValueArray * static GimpValueArray *
palette_duplicate_invoker (GimpProcedure *procedure, palette_duplicate_invoker (GimpProcedure *procedure,
Gimp *gimp, Gimp *gimp,
@ -109,33 +141,6 @@ palette_duplicate_invoker (GimpProcedure *procedure,
return return_vals; return return_vals;
} }
static GimpValueArray *
palette_id_is_valid_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
GimpValueArray *return_vals;
const gchar *id;
gboolean valid = FALSE;
id = g_value_get_string (gimp_value_array_index (args, 0));
valid = (gimp_pdb_get_palette (gimp, id, GIMP_PDB_DATA_ACCESS_READ, error) != NULL);
/* When ID is not valid, NULL is returned and error is set.
* Clear error so GIMP not display error dialog.
*/
g_clear_error (error);
return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
g_value_set_boolean (gimp_value_array_index (return_vals, 1), valid);
return return_vals;
}
static GimpValueArray * static GimpValueArray *
palette_rename_invoker (GimpProcedure *procedure, palette_rename_invoker (GimpProcedure *procedure,
Gimp *gimp, Gimp *gimp,
@ -604,6 +609,36 @@ register_palette_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure); gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure); g_object_unref (procedure);
/*
* gimp-palette-get-by-name
*/
procedure = gimp_procedure_new (palette_get_by_name_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-palette-get-by-name");
gimp_procedure_set_static_help (procedure,
"Returns the palette with the given name.",
"Returns the palette with the given name.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2023");
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("name",
"name",
"The name of the palette",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_palette ("palette",
"palette",
"The palette",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/* /*
* gimp-palette-duplicate * gimp-palette-duplicate
*/ */
@ -633,36 +668,6 @@ register_palette_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure); gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure); g_object_unref (procedure);
/*
* gimp-palette-id-is-valid
*/
procedure = gimp_procedure_new (palette_id_is_valid_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-palette-id-is-valid");
gimp_procedure_set_static_help (procedure,
"Whether the ID is a valid reference to installed data.",
"Returns TRUE if this ID is valid.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Lloyd Konneker",
"Lloyd Konneker",
"2022");
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("id",
"id",
"The palette ID",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("valid",
"valid",
"TRUE if the palette ID is valid",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/* /*
* gimp-palette-rename * gimp-palette-rename
*/ */

View File

@ -44,6 +44,38 @@
#include "internal-procs.h" #include "internal-procs.h"
static GimpValueArray *
pattern_get_by_name_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
const gchar *name;
GimpPattern *pattern = NULL;
name = g_value_get_string (gimp_value_array_index (args, 0));
if (success)
{
pattern = gimp_pdb_get_pattern (gimp, name, error);
if (! pattern)
success = FALSE;
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_object (gimp_value_array_index (return_vals, 1), pattern);
return return_vals;
}
static GimpValueArray * static GimpValueArray *
pattern_get_info_invoker (GimpProcedure *procedure, pattern_get_info_invoker (GimpProcedure *procedure,
Gimp *gimp, Gimp *gimp,
@ -136,39 +168,41 @@ pattern_get_pixels_invoker (GimpProcedure *procedure,
return return_vals; return return_vals;
} }
static GimpValueArray *
pattern_id_is_valid_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
GimpValueArray *return_vals;
const gchar *id;
gboolean valid = FALSE;
id = g_value_get_string (gimp_value_array_index (args, 0));
/* !!! pattern has one fewer args than other resources. */
valid = (gimp_pdb_get_pattern (gimp, id, error) != NULL);
/* When ID is not valid, NULL is returned and error is set.
* Clear error so GIMP not display error dialog.
*/
g_clear_error (error);
return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
g_value_set_boolean (gimp_value_array_index (return_vals, 1), valid);
return return_vals;
}
void void
register_pattern_procs (GimpPDB *pdb) register_pattern_procs (GimpPDB *pdb)
{ {
GimpProcedure *procedure; GimpProcedure *procedure;
/*
* gimp-pattern-get-by-name
*/
procedure = gimp_procedure_new (pattern_get_by_name_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-pattern-get-by-name");
gimp_procedure_set_static_help (procedure,
"Returns the pattern with the given name.",
"Returns the pattern with the given name.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2023");
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("name",
"name",
"The name of the pattern",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_pattern ("pattern",
"pattern",
"The pattern",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/* /*
* gimp-pattern-get-info * gimp-pattern-get-info
*/ */
@ -256,34 +290,4 @@ register_pattern_procs (GimpPDB *pdb)
GIMP_PARAM_READWRITE)); GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure); gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure); g_object_unref (procedure);
/*
* gimp-pattern-id-is-valid
*/
procedure = gimp_procedure_new (pattern_id_is_valid_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-pattern-id-is-valid");
gimp_procedure_set_static_help (procedure,
"Whether the ID is a valid reference to installed data.",
"Returns TRUE if this ID is valid.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Lloyd Konneker",
"Lloyd Konneker",
"2022");
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("id",
"id",
"The pattern ID",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("valid",
"valid",
"TRUE if the pattern ID is valid",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
} }

470
app/pdb/resource-cmds.c Normal file
View File

@ -0,0 +1,470 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* NOTE: This file is auto-generated by pdbgen.pl. */
#include "config.h"
#include "stamp-pdbgen.h"
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "libgimpbase/gimpbase.h"
#include "pdb-types.h"
#include "core/gimpbrush.h"
#include "core/gimpgradient.h"
#include "core/gimppalette.h"
#include "core/gimpparamspecs.h"
#include "core/gimppattern.h"
#include "core/gimpresource.h"
#include "text/gimpfont.h"
#include "gimppdb.h"
#include "gimpprocedure.h"
#include "internal-procs.h"
#include "gimp-intl.h"
static GimpValueArray *
resource_id_is_valid_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
gint resource_id;
gboolean valid = FALSE;
resource_id = g_value_get_int (gimp_value_array_index (args, 0));
if (success)
{
GimpData *data = gimp_data_get_by_id (resource_id);
valid = GIMP_IS_DATA (data);
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_boolean (gimp_value_array_index (return_vals, 1), valid);
return return_vals;
}
static GimpValueArray *
resource_id_is_brush_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
gint resource_id;
gboolean brush = FALSE;
resource_id = g_value_get_int (gimp_value_array_index (args, 0));
if (success)
{
GimpData *data = gimp_data_get_by_id (resource_id);
brush = GIMP_IS_BRUSH (data);
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_boolean (gimp_value_array_index (return_vals, 1), brush);
return return_vals;
}
static GimpValueArray *
resource_id_is_pattern_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
gint resource_id;
gboolean pattern = FALSE;
resource_id = g_value_get_int (gimp_value_array_index (args, 0));
if (success)
{
GimpData *data = gimp_data_get_by_id (resource_id);
pattern = GIMP_IS_PATTERN (data);
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_boolean (gimp_value_array_index (return_vals, 1), pattern);
return return_vals;
}
static GimpValueArray *
resource_id_is_gradient_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
gint resource_id;
gboolean gradient = FALSE;
resource_id = g_value_get_int (gimp_value_array_index (args, 0));
if (success)
{
GimpData *data = gimp_data_get_by_id (resource_id);
gradient = GIMP_IS_GRADIENT (data);
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_boolean (gimp_value_array_index (return_vals, 1), gradient);
return return_vals;
}
static GimpValueArray *
resource_id_is_palette_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
gint resource_id;
gboolean palette = FALSE;
resource_id = g_value_get_int (gimp_value_array_index (args, 0));
if (success)
{
GimpData *data = gimp_data_get_by_id (resource_id);
palette = GIMP_IS_PALETTE (data);
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_boolean (gimp_value_array_index (return_vals, 1), palette);
return return_vals;
}
static GimpValueArray *
resource_id_is_font_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
gint resource_id;
gboolean font = FALSE;
resource_id = g_value_get_int (gimp_value_array_index (args, 0));
if (success)
{
GimpData *data = gimp_data_get_by_id (resource_id);
font = GIMP_IS_FONT (data);
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_boolean (gimp_value_array_index (return_vals, 1), font);
return return_vals;
}
static GimpValueArray *
resource_get_name_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
GimpResource *resource;
gchar *name = NULL;
resource = g_value_get_object (gimp_value_array_index (args, 0));
if (success)
{
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (resource)));
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_take_string (gimp_value_array_index (return_vals, 1), name);
return return_vals;
}
void
register_resource_procs (GimpPDB *pdb)
{
GimpProcedure *procedure;
/*
* gimp-resource-id-is-valid
*/
procedure = gimp_procedure_new (resource_id_is_valid_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-resource-id-is-valid");
gimp_procedure_set_static_help (procedure,
"Returns TRUE if the resource ID is valid.",
"This procedure checks if the given resource ID is valid and refers to an existing resource.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2023");
gimp_procedure_add_argument (procedure,
g_param_spec_int ("resource-id",
"resource id",
"The resource ID to check",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("valid",
"valid",
"Whether the resource ID is valid",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-resource-id-is-brush
*/
procedure = gimp_procedure_new (resource_id_is_brush_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-resource-id-is-brush");
gimp_procedure_set_static_help (procedure,
"Returns whether the resource ID is a brush.",
"This procedure returns TRUE if the specified resource ID is a brush.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2023");
gimp_procedure_add_argument (procedure,
g_param_spec_int ("resource-id",
"resource id",
"The resource ID",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("brush",
"brush",
"TRUE if the resource ID is a brush, FALSE otherwise",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-resource-id-is-pattern
*/
procedure = gimp_procedure_new (resource_id_is_pattern_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-resource-id-is-pattern");
gimp_procedure_set_static_help (procedure,
"Returns whether the resource ID is a pattern.",
"This procedure returns TRUE if the specified resource ID is a pattern.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2023");
gimp_procedure_add_argument (procedure,
g_param_spec_int ("resource-id",
"resource id",
"The resource ID",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("pattern",
"pattern",
"TRUE if the resource ID is a pattern, FALSE otherwise",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-resource-id-is-gradient
*/
procedure = gimp_procedure_new (resource_id_is_gradient_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-resource-id-is-gradient");
gimp_procedure_set_static_help (procedure,
"Returns whether the resource ID is a gradient.",
"This procedure returns TRUE if the specified resource ID is a gradient.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2023");
gimp_procedure_add_argument (procedure,
g_param_spec_int ("resource-id",
"resource id",
"The resource ID",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("gradient",
"gradient",
"TRUE if the resource ID is a gradient, FALSE otherwise",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-resource-id-is-palette
*/
procedure = gimp_procedure_new (resource_id_is_palette_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-resource-id-is-palette");
gimp_procedure_set_static_help (procedure,
"Returns whether the resource ID is a palette.",
"This procedure returns TRUE if the specified resource ID is a palette.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2023");
gimp_procedure_add_argument (procedure,
g_param_spec_int ("resource-id",
"resource id",
"The resource ID",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("palette",
"palette",
"TRUE if the resource ID is a palette, FALSE otherwise",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-resource-id-is-font
*/
procedure = gimp_procedure_new (resource_id_is_font_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-resource-id-is-font");
gimp_procedure_set_static_help (procedure,
"Returns whether the resource ID is a font.",
"This procedure returns TRUE if the specified resource ID is a font.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2023");
gimp_procedure_add_argument (procedure,
g_param_spec_int ("resource-id",
"resource id",
"The resource ID",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("font",
"font",
"TRUE if the resource ID is a font, FALSE otherwise",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-resource-get-name
*/
procedure = gimp_procedure_new (resource_get_name_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-resource-get-name");
gimp_procedure_set_static_help (procedure,
"Returns the resource's name.",
"This procedure returns the resource's name.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2023");
gimp_procedure_add_argument (procedure,
gimp_param_spec_resource ("resource",
"resource",
"The resource",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_string ("name",
"name",
"The resource's name",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
}

View File

@ -52,6 +52,10 @@
#include "libgimp/gimpgpparams.h" #include "libgimp/gimpgpparams.h"
#undef GIMP_VALUE_HOLDS_RESOURCE
#define GIMP_VALUE_HOLDS_RESOURCE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), \
GIMP_TYPE_DATA))
/* include the implementation, they are shared between app/ and /* include the implementation, they are shared between app/ and
* libgimp/ but need different headers. * libgimp/ but need different headers.
*/ */

View File

@ -11,6 +11,7 @@ EXPORTS
gimp_brush_duplicate gimp_brush_duplicate
gimp_brush_get_angle gimp_brush_get_angle
gimp_brush_get_aspect_ratio gimp_brush_get_aspect_ratio
gimp_brush_get_by_name
gimp_brush_get_hardness gimp_brush_get_hardness
gimp_brush_get_info gimp_brush_get_info
gimp_brush_get_pixels gimp_brush_get_pixels
@ -19,10 +20,8 @@ EXPORTS
gimp_brush_get_spacing gimp_brush_get_spacing
gimp_brush_get_spikes gimp_brush_get_spikes
gimp_brush_get_type gimp_brush_get_type
gimp_brush_id_is_valid
gimp_brush_is_editable gimp_brush_is_editable
gimp_brush_is_generated gimp_brush_is_generated
gimp_brush_is_valid
gimp_brush_new gimp_brush_new
gimp_brush_rename gimp_brush_rename
gimp_brush_set_angle gimp_brush_set_angle
@ -294,9 +293,8 @@ EXPORTS
gimp_floating_sel_attach gimp_floating_sel_attach
gimp_floating_sel_remove gimp_floating_sel_remove
gimp_floating_sel_to_layer gimp_floating_sel_to_layer
gimp_font_get_by_name
gimp_font_get_type gimp_font_get_type
gimp_font_id_is_valid
gimp_font_is_valid
gimp_fonts_close_popup gimp_fonts_close_popup
gimp_fonts_get_list gimp_fonts_get_list
gimp_fonts_popup gimp_fonts_popup
@ -319,13 +317,12 @@ EXPORTS
gimp_gimprc_set gimp_gimprc_set
gimp_gradient_delete gimp_gradient_delete
gimp_gradient_duplicate gimp_gradient_duplicate
gimp_gradient_get_by_name
gimp_gradient_get_custom_samples gimp_gradient_get_custom_samples
gimp_gradient_get_number_of_segments gimp_gradient_get_number_of_segments
gimp_gradient_get_type gimp_gradient_get_type
gimp_gradient_get_uniform_samples gimp_gradient_get_uniform_samples
gimp_gradient_id_is_valid
gimp_gradient_is_editable gimp_gradient_is_editable
gimp_gradient_is_valid
gimp_gradient_new gimp_gradient_new
gimp_gradient_rename gimp_gradient_rename
gimp_gradient_segment_get_blending_function gimp_gradient_segment_get_blending_function
@ -646,13 +643,12 @@ EXPORTS
gimp_palette_entry_get_name gimp_palette_entry_get_name
gimp_palette_entry_set_color gimp_palette_entry_set_color
gimp_palette_entry_set_name gimp_palette_entry_set_name
gimp_palette_get_by_name
gimp_palette_get_color_count gimp_palette_get_color_count
gimp_palette_get_colors gimp_palette_get_colors
gimp_palette_get_columns gimp_palette_get_columns
gimp_palette_get_type gimp_palette_get_type
gimp_palette_id_is_valid
gimp_palette_is_editable gimp_palette_is_editable
gimp_palette_is_valid
gimp_palette_new gimp_palette_new
gimp_palette_rename gimp_palette_rename
gimp_palette_set_columns gimp_palette_set_columns
@ -694,11 +690,10 @@ EXPORTS
gimp_param_spec_vectors gimp_param_spec_vectors
gimp_param_text_layer_get_type gimp_param_text_layer_get_type
gimp_param_vectors_get_type gimp_param_vectors_get_type
gimp_pattern_get_by_name
gimp_pattern_get_info gimp_pattern_get_info
gimp_pattern_get_pixels gimp_pattern_get_pixels
gimp_pattern_get_type gimp_pattern_get_type
gimp_pattern_id_is_valid
gimp_pattern_is_valid
gimp_patterns_close_popup gimp_patterns_close_popup
gimp_patterns_get_list gimp_patterns_get_list
gimp_patterns_popup gimp_patterns_popup
@ -808,8 +803,23 @@ EXPORTS
gimp_progress_uninstall gimp_progress_uninstall
gimp_progress_update gimp_progress_update
gimp_quit gimp_quit
gimp_resource_get_by_id
gimp_resource_get_by_name
gimp_resource_get_id gimp_resource_get_id
gimp_resource_get_name
gimp_resource_get_type gimp_resource_get_type
gimp_resource_id_is_brush
gimp_resource_id_is_font
gimp_resource_id_is_gradient
gimp_resource_id_is_palette
gimp_resource_id_is_pattern
gimp_resource_id_is_valid
gimp_resource_is_brush
gimp_resource_is_font
gimp_resource_is_gradient
gimp_resource_is_palette
gimp_resource_is_pattern
gimp_resource_is_valid
gimp_resource_select_destroy gimp_resource_select_destroy
gimp_resource_select_new gimp_resource_select_new
gimp_resource_select_set gimp_resource_select_set

View File

@ -56,6 +56,7 @@
#include <libgimp/gimpprocedureconfig.h> #include <libgimp/gimpprocedureconfig.h>
#include <libgimp/gimpprocedure-params.h> #include <libgimp/gimpprocedure-params.h>
#include <libgimp/gimpprogress.h> #include <libgimp/gimpprogress.h>
#include <libgimp/gimpresource.h>
#include <libgimp/gimpsaveprocedure.h> #include <libgimp/gimpsaveprocedure.h>
#include <libgimp/gimpselection.h> #include <libgimp/gimpselection.h>
#include <libgimp/gimptextlayer.h> #include <libgimp/gimptextlayer.h>
@ -63,9 +64,7 @@
#include <libgimp/gimpvectors.h> #include <libgimp/gimpvectors.h>
/* Resources and their widgets. Order important. */ /* Resources and their widgets. Order important. */
#include <libgimp/gimpresource.h>
#include <libgimp/gimpresourceselect.h> #include <libgimp/gimpresourceselect.h>
#include <libgimp/gimpresource-subclass.h>
#include <libgimp/gimp_pdb_headers.h> #include <libgimp/gimp_pdb_headers.h>

View File

@ -72,6 +72,7 @@
#include <libgimp/gimppatterns_pdb.h> #include <libgimp/gimppatterns_pdb.h>
#include <libgimp/gimppatternselect_pdb.h> #include <libgimp/gimppatternselect_pdb.h>
#include <libgimp/gimpprogress_pdb.h> #include <libgimp/gimpprogress_pdb.h>
#include <libgimp/gimpresource_pdb.h>
#include <libgimp/gimpselection_pdb.h> #include <libgimp/gimpselection_pdb.h>
#include <libgimp/gimptextlayer_pdb.h> #include <libgimp/gimptextlayer_pdb.h>
#include <libgimp/gimptexttool_pdb.h> #include <libgimp/gimptexttool_pdb.h>

View File

@ -72,6 +72,42 @@ gimp_brush_new (const gchar *name)
return brush; return brush;
} }
/**
* gimp_brush_get_by_name:
* @name: The name of the brush.
*
* Returns the brush with the given name.
*
* Returns the brush with the given name.
*
* Returns: (transfer full): The brush.
*
* Since: 3.0
**/
GimpBrush *
gimp_brush_get_by_name (const gchar *name)
{
GimpValueArray *args;
GimpValueArray *return_vals;
GimpBrush *brush = NULL;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_STRING, name,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-brush-get-by-name",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
brush = GIMP_VALUES_GET_BRUSH (return_vals, 1);
gimp_value_array_unref (return_vals);
return brush;
}
/** /**
* gimp_brush_duplicate: * gimp_brush_duplicate:
* @brush: The brush. * @brush: The brush.
@ -144,42 +180,6 @@ gimp_brush_is_generated (GimpBrush *brush)
return generated; return generated;
} }
/**
* gimp_brush_id_is_valid:
* @id: The brush ID.
*
* Whether the ID is a valid reference to installed brush data.
*
* Returns TRUE when ID is valid.
*
* Returns: TRUE if the brush ID is valid.
*
* Since: 3.0
**/
gboolean
gimp_brush_id_is_valid (const gchar *id)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean valid = FALSE;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_STRING, id,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-brush-id-is-valid",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
valid = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
gimp_value_array_unref (return_vals);
return valid;
}
/** /**
* gimp_brush_rename: * gimp_brush_rename:
* @brush: The brush. * @brush: The brush.

View File

@ -33,9 +33,9 @@ G_BEGIN_DECLS
GimpBrush* gimp_brush_new (const gchar *name); GimpBrush* gimp_brush_new (const gchar *name);
GimpBrush* gimp_brush_get_by_name (const gchar *name);
GimpBrush* gimp_brush_duplicate (GimpBrush *brush); GimpBrush* gimp_brush_duplicate (GimpBrush *brush);
gboolean gimp_brush_is_generated (GimpBrush *brush); gboolean gimp_brush_is_generated (GimpBrush *brush);
gboolean gimp_brush_id_is_valid (const gchar *id);
GimpBrush* gimp_brush_rename (GimpBrush *brush, GimpBrush* gimp_brush_rename (GimpBrush *brush,
const gchar *new_name); const gchar *new_name);
gboolean gimp_brush_delete (GimpBrush *brush); gboolean gimp_brush_delete (GimpBrush *brush);

View File

@ -55,7 +55,6 @@ typedef struct _PreviewBitmap
struct _GimpBrushSelectButton struct _GimpBrushSelectButton
{ {
/* !! Not a pointer, is contained. */
GimpResourceSelectButton parent_instance; GimpResourceSelectButton parent_instance;
/* Partial view of brush image. Receives drag. Receives mouse down to popup zoom. */ /* Partial view of brush image. Receives drag. Receives mouse down to popup zoom. */
@ -66,7 +65,6 @@ struct _GimpBrushSelectButton
/* local */ /* local */
/* implement virtual. */
static void gimp_brush_select_button_finalize (GObject *object); static void gimp_brush_select_button_finalize (GObject *object);
static void gimp_brush_select_button_draw_interior (GimpResourceSelectButton *self); static void gimp_brush_select_button_draw_interior (GimpResourceSelectButton *self);
@ -116,36 +114,18 @@ G_DEFINE_FINAL_TYPE (GimpBrushSelectButton,
static void static void
gimp_brush_select_button_class_init (GimpBrushSelectButtonClass *klass) gimp_brush_select_button_class_init (GimpBrushSelectButtonClass *klass)
{ {
/* Alias cast klass to super classes. */
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpResourceSelectButtonClass *superclass = GIMP_RESOURCE_SELECT_BUTTON_CLASS (klass); GimpResourceSelectButtonClass *superclass = GIMP_RESOURCE_SELECT_BUTTON_CLASS (klass);
g_debug ("%s called", G_STRFUNC);
object_class->finalize = gimp_brush_select_button_finalize; object_class->finalize = gimp_brush_select_button_finalize;
/* Implement pure virtual functions. */
superclass->draw_interior = gimp_brush_select_button_draw_interior; superclass->draw_interior = gimp_brush_select_button_draw_interior;
/* Set data member of class. */
superclass->resource_type = GIMP_TYPE_BRUSH; superclass->resource_type = GIMP_TYPE_BRUSH;
/* We don't define property getter/setters: use superclass getter/setters.
* But super property name is "resource", not "brush"
*/
} }
static void static void
gimp_brush_select_button_init (GimpBrushSelectButton *self) gimp_brush_select_button_init (GimpBrushSelectButton *self)
{ {
g_debug ("%s called", G_STRFUNC);
/* Specialize:
* - embed our widget interior instance to super widget instance.
* - connect our widget to dnd
* These will call superclass methods.
* These are on instance, not our subclass.
*/
gimp_brush_select_button_embed_interior (self); gimp_brush_select_button_embed_interior (self);
gimp_brush_select_button_set_drag_target (self); gimp_brush_select_button_set_drag_target (self);

View File

@ -29,9 +29,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/* This defines certain structs and the usual macros.
* A final type has no private.
*/
#define GIMP_TYPE_BRUSH_SELECT_BUTTON (gimp_brush_select_button_get_type ()) #define GIMP_TYPE_BRUSH_SELECT_BUTTON (gimp_brush_select_button_get_type ())
G_DECLARE_FINAL_TYPE (GimpBrushSelectButton, G_DECLARE_FINAL_TYPE (GimpBrushSelectButton,
gimp_brush_select_button, gimp_brush_select_button,

View File

@ -37,37 +37,37 @@
/** /**
* gimp_font_id_is_valid: * gimp_font_get_by_name:
* @id: The font ID. * @name: The name of the font.
* *
* Whether the ID is a valid reference to installed data. * Returns the font with the given name.
* *
* Returns TRUE if this ID is valid. * Returns the font with the given name.
* *
* Returns: TRUE if the font ID is valid. * Returns: (transfer full): The font.
* *
* Since: 3.0 * Since: 3.0
**/ **/
gboolean GimpFont *
gimp_font_id_is_valid (const gchar *id) gimp_font_get_by_name (const gchar *name)
{ {
GimpValueArray *args; GimpValueArray *args;
GimpValueArray *return_vals; GimpValueArray *return_vals;
gboolean valid = FALSE; GimpFont *font = NULL;
args = gimp_value_array_new_from_types (NULL, args = gimp_value_array_new_from_types (NULL,
G_TYPE_STRING, id, G_TYPE_STRING, name,
G_TYPE_NONE); G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (), return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-font-id-is-valid", "gimp-font-get-by-name",
args); args);
gimp_value_array_unref (args); gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
valid = GIMP_VALUES_GET_BOOLEAN (return_vals, 1); font = GIMP_VALUES_GET_FONT (return_vals, 1);
gimp_value_array_unref (return_vals); gimp_value_array_unref (return_vals);
return valid; return font;
} }

View File

@ -32,7 +32,7 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */ /* For information look into the C source or the html documentation */
gboolean gimp_font_id_is_valid (const gchar *id); GimpFont* gimp_font_get_by_name (const gchar *name);
G_END_DECLS G_END_DECLS

View File

@ -45,7 +45,6 @@
struct _GimpFontSelectButton struct _GimpFontSelectButton
{ {
/* !! Not a pointer, is contained. */
GimpResourceSelectButton parent_instance; GimpResourceSelectButton parent_instance;
GtkWidget *font_name_label; GtkWidget *font_name_label;
@ -53,18 +52,15 @@ struct _GimpFontSelectButton
GtkWidget *button; GtkWidget *button;
}; };
/* local */
/* implement virtual */ static void gimp_font_select_button_draw_interior (GimpResourceSelectButton *self);
static void gimp_font_select_button_finalize (GObject *object);
static void gimp_font_select_button_draw_interior (GimpResourceSelectButton *self);
/* Called at init. */
static GtkWidget *gimp_font_select_button_create_interior (GimpFontSelectButton *self); static GtkWidget *gimp_font_select_button_create_interior (GimpFontSelectButton *self);
/* A GtkTargetEntry has a string and two ints. This is one, but treat as an array.*/
static const GtkTargetEntry drag_target = { "application/x-gimp-font-name", 0, 0 }; static const GtkTargetEntry drag_target = { "application/x-gimp-font-name", 0, 0 };
G_DEFINE_FINAL_TYPE (GimpFontSelectButton, G_DEFINE_FINAL_TYPE (GimpFontSelectButton,
gimp_font_select_button, gimp_font_select_button,
GIMP_TYPE_RESOURCE_SELECT_BUTTON) GIMP_TYPE_RESOURCE_SELECT_BUTTON)
@ -73,24 +69,10 @@ G_DEFINE_FINAL_TYPE (GimpFontSelectButton,
static void static void
gimp_font_select_button_class_init (GimpFontSelectButtonClass *klass) gimp_font_select_button_class_init (GimpFontSelectButtonClass *klass)
{ {
/* Alias cast klass to super classes. */ GimpResourceSelectButtonClass *superclass = GIMP_RESOURCE_SELECT_BUTTON_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpResourceSelectButtonClass *superclass = GIMP_RESOURCE_SELECT_BUTTON_CLASS (klass);
g_debug ("%s called", G_STRFUNC);
/* Override virtual. */
object_class->finalize = gimp_font_select_button_finalize;
/* Implement pure virtual functions. */
superclass->draw_interior = gimp_font_select_button_draw_interior; superclass->draw_interior = gimp_font_select_button_draw_interior;
/* Set data member of class. */
superclass->resource_type = GIMP_TYPE_FONT; superclass->resource_type = GIMP_TYPE_FONT;
/* We don't define property getter/setters: use superclass getter/setters.
* But super property name is "resource", not "font"
*/
} }
static void static void
@ -98,26 +80,14 @@ gimp_font_select_button_init (GimpFontSelectButton *self)
{ {
GtkWidget *interior; GtkWidget *interior;
g_debug ("%s called", G_STRFUNC);
/* Specialize super:
* - embed our widget interior instance to super widget instance.
* - tell super our dnd widget
* - tell super our clickable button
* Call superclass methods, with upcasts.
* These are on instance, not our subclass.
*/
interior = gimp_font_select_button_create_interior (self); interior = gimp_font_select_button_create_interior (self);
/* require self has sub widgets initialized. */
/* Embed the whole button.*/
gimp_resource_select_button_embed_interior (GIMP_RESOURCE_SELECT_BUTTON (self), interior); gimp_resource_select_button_embed_interior (GIMP_RESOURCE_SELECT_BUTTON (self), interior);
/* Self knows the GtkTargetEntry, super creates target and handles receive drag. */
gimp_resource_select_button_set_drag_target (GIMP_RESOURCE_SELECT_BUTTON (self), gimp_resource_select_button_set_drag_target (GIMP_RESOURCE_SELECT_BUTTON (self),
self->drag_region_widget, self->drag_region_widget,
&drag_target); &drag_target);
/* Super handles button clicks. */
gimp_resource_select_button_set_clickable (GIMP_RESOURCE_SELECT_BUTTON (self), gimp_resource_select_button_set_clickable (GIMP_RESOURCE_SELECT_BUTTON (self),
self->button); self->button);
} }
@ -142,24 +112,11 @@ gimp_font_select_button_new (const gchar *title,
{ {
GtkWidget *self; GtkWidget *self;
g_debug ("%s called", G_STRFUNC); g_return_val_if_fail (resource == NULL || GIMP_IS_FONT (resource), NULL);
if (resource == NULL) if (resource == NULL)
{ resource = GIMP_RESOURCE (gimp_context_get_font ());
g_debug ("%s defaulting font from context", G_STRFUNC);
resource = GIMP_RESOURCE (gimp_context_get_font ());
}
g_assert (resource != NULL);
/* This method is polymorphic, so a factory can call it, but requires Font. */
g_return_val_if_fail (GIMP_IS_FONT (resource), NULL);
/* Create instance of self (not super.)
* This will call superclass init, self class init, superclass init, and instance init.
* Self subclass class_init will specialize by implementing virtual funcs
* that open and set remote chooser dialog, and that draw self interior.
*
* !!! property belongs to superclass and is named "resource"
*/
if (title) if (title)
self = g_object_new (GIMP_TYPE_FONT_SELECT_BUTTON, self = g_object_new (GIMP_TYPE_FONT_SELECT_BUTTON,
"title", title, "title", title,
@ -170,26 +127,11 @@ gimp_font_select_button_new (const gchar *title,
"resource", resource, "resource", resource,
NULL); NULL);
/* We don't subscribe to events from super (such as draw events.)
* Super will call our draw method when it's resource changes.
* Except that the above setting of property happens too late,
* so we now draw the initial resource.
*/
/* Draw with the initial resource. Cast self from Widget. */
gimp_font_select_button_draw_interior (GIMP_RESOURCE_SELECT_BUTTON (self)); gimp_font_select_button_draw_interior (GIMP_RESOURCE_SELECT_BUTTON (self));
g_debug ("%s returns", G_STRFUNC);
return self; return self;
} }
/* Getter and setter.
* We could omit these, and use only the superclass methods.
* But script-fu-interface.c uses these, until FUTURE.
*/
/** /**
* gimp_font_select_button_get_font: * gimp_font_select_button_get_font:
* @self: A #GimpFontSelectButton * @self: A #GimpFontSelectButton
@ -205,7 +147,6 @@ gimp_font_select_button_get_font (GimpFontSelectButton *self)
{ {
g_return_val_if_fail (GIMP_IS_FONT_SELECT_BUTTON (self), NULL); g_return_val_if_fail (GIMP_IS_FONT_SELECT_BUTTON (self), NULL);
/* Delegate to super w upcast arg and downcast result. */
return (GimpFont *) gimp_resource_select_button_get_resource ((GimpResourceSelectButton*) self); return (GimpFont *) gimp_resource_select_button_get_resource ((GimpResourceSelectButton*) self);
} }
@ -226,29 +167,12 @@ gimp_font_select_button_set_font (GimpFontSelectButton *self,
{ {
g_return_if_fail (GIMP_IS_FONT_SELECT_BUTTON (self)); g_return_if_fail (GIMP_IS_FONT_SELECT_BUTTON (self));
g_debug ("%s", G_STRFUNC);
/* Delegate to super with upcasts */
gimp_resource_select_button_set_resource (GIMP_RESOURCE_SELECT_BUTTON (self), GIMP_RESOURCE (font)); gimp_resource_select_button_set_resource (GIMP_RESOURCE_SELECT_BUTTON (self), GIMP_RESOURCE (font));
} }
/* private functions */ /* private functions */
static void
gimp_font_select_button_finalize (GObject *object)
{
g_debug ("%s called", G_STRFUNC);
/* Has no allocations.*/
/* Chain up. */
G_OBJECT_CLASS (gimp_font_select_button_parent_class)->finalize (object);
}
/* This is NOT an implementation of virtual function. /* This is NOT an implementation of virtual function.
* *
* Create a widget that is the interior of a button. * Create a widget that is the interior of a button.
@ -268,68 +192,36 @@ gimp_font_select_button_create_interior (GimpFontSelectButton *self)
GtkWidget *label; GtkWidget *label;
gchar *font_name = "unknown"; gchar *font_name = "unknown";
g_debug ("%s", G_STRFUNC);
/* Outermost is-a button. */
button = gtk_button_new (); button = gtk_button_new ();
/* inside the button is hbox. */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
gtk_container_add (GTK_CONTAINER (button), hbox); gtk_container_add (GTK_CONTAINER (button), hbox);
/* first item in hbox is an icon. */
image = gtk_image_new_from_icon_name (GIMP_ICON_FONT, image = gtk_image_new_from_icon_name (GIMP_ICON_FONT,
GTK_ICON_SIZE_BUTTON); GTK_ICON_SIZE_BUTTON);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
/* Second item in hbox is font name.
* The initial text is dummy, a draw will soon refresh it.
* This function does not know the resource/font.
*/
label = gtk_label_new (font_name); label = gtk_label_new (font_name);
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 4); gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 4);
/* Ensure sub widgets saved for subsequent use. */
self->font_name_label = label; /* Save label for redraw. */ self->font_name_label = label; /* Save label for redraw. */
self->drag_region_widget = hbox; self->drag_region_widget = hbox;
self->button = button; self->button = button;
/* This subclass does not connect to draw signal on interior widget. */
/* Return the whole interior, which is-a button. */
return button; return button;
} }
/* Knows how to draw self interior.
* Self knows resource, it is not passed.
*
* Overrides virtual method in super, so it is generic on Resource.
*/
static void static void
gimp_font_select_button_draw_interior (GimpResourceSelectButton *self) gimp_font_select_button_draw_interior (GimpResourceSelectButton *self)
{ {
gchar *font_name; GimpFontSelectButton *font_select= GIMP_FONT_SELECT_BUTTON (self);
GimpResource *resource; GimpResource *resource;
GimpFontSelectButton *self_as_font_select; gchar *name = NULL;
g_debug ("%s", G_STRFUNC); resource = gimp_resource_select_button_get_resource (self);
g_return_if_fail (GIMP_IS_FONT_SELECT_BUTTON (self)); if (resource)
self_as_font_select = GIMP_FONT_SELECT_BUTTON (self); name = gimp_resource_get_name (resource);
g_object_get (self, "resource", &resource, NULL); gtk_label_set_text (GTK_LABEL (font_select->font_name_label), name);
/* For now, the "id" property of the resource is the name.
* FUTURE: core will support name distinct from ID.
*/
g_object_get (resource, "id", &font_name, NULL);
/* We are not keeping a copy of font name, nothing to free. */
/* Not styling the text using the chosen font,
* just replacing the text with the name of the chosen font.
*/
gtk_label_set_text (GTK_LABEL (self_as_font_select->font_name_label), font_name);
} }

View File

@ -29,9 +29,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/* This defines certain structs and the usual macros.
* A final type has no private.
*/
#define GIMP_TYPE_FONT_SELECT_BUTTON (gimp_font_select_button_get_type ()) #define GIMP_TYPE_FONT_SELECT_BUTTON (gimp_font_select_button_get_type ())
G_DECLARE_FINAL_TYPE (GimpFontSelectButton, G_DECLARE_FINAL_TYPE (GimpFontSelectButton,
gimp_font_select_button, gimp_font_select_button,
@ -42,7 +39,6 @@ G_DECLARE_FINAL_TYPE (GimpFontSelectButton,
GtkWidget * gimp_font_select_button_new (const gchar *title, GtkWidget * gimp_font_select_button_new (const gchar *title,
GimpResource *resource); GimpResource *resource);
/* FUTURE eliminate. Use superclass method get_resource */
GimpFont * gimp_font_select_button_get_font (GimpFontSelectButton *self); GimpFont * gimp_font_select_button_get_font (GimpFontSelectButton *self);
void gimp_font_select_button_set_font (GimpFontSelectButton *self, void gimp_font_select_button_set_font (GimpFontSelectButton *self,
GimpFont *font); GimpFont *font);

View File

@ -197,19 +197,22 @@ _gimp_gp_param_def_to_param_spec (const GPParamDef *param_def)
param_def->meta.m_id.none_ok, param_def->meta.m_id.none_ok,
flags); flags);
/* Resources */
if (! strcmp (param_def->type_name, "GimpParamBrush")) if (! strcmp (param_def->type_name, "GimpParamBrush"))
return gimp_param_spec_brush (name, nick, blurb, return gimp_param_spec_brush (name, nick, blurb,
param_def->meta.m_id.none_ok, flags); param_def->meta.m_id.none_ok, flags);
if (! strcmp (param_def->type_name, "GimpParamFont")) if (! strcmp (param_def->type_name, "GimpParamFont"))
return gimp_param_spec_font (name, nick, blurb, return gimp_param_spec_font (name, nick, blurb,
param_def->meta.m_id.none_ok, flags); param_def->meta.m_id.none_ok, flags);
if (! strcmp (param_def->type_name, "GimpParamGradient")) if (! strcmp (param_def->type_name, "GimpParamGradient"))
return gimp_param_spec_gradient (name, nick, blurb, return gimp_param_spec_gradient (name, nick, blurb,
param_def->meta.m_id.none_ok, flags); param_def->meta.m_id.none_ok, flags);
if (! strcmp (param_def->type_name, "GimpParamPalette")) if (! strcmp (param_def->type_name, "GimpParamPalette"))
return gimp_param_spec_palette (name, nick, blurb, return gimp_param_spec_palette (name, nick, blurb,
param_def->meta.m_id.none_ok, flags); param_def->meta.m_id.none_ok, flags);
if (! strcmp (param_def->type_name, "GimpParamPattern")) if (! strcmp (param_def->type_name, "GimpParamPattern"))
return gimp_param_spec_pattern (name, nick, blurb, return gimp_param_spec_pattern (name, nick, blurb,
param_def->meta.m_id.none_ok, flags); param_def->meta.m_id.none_ok, flags);
@ -223,7 +226,8 @@ _gimp_gp_param_def_to_param_spec (const GPParamDef *param_def)
break; break;
} }
g_warning ("%s: GParamSpec type unsupported '%s'", G_STRFUNC, param_def->type_name); g_warning ("%s: GParamSpec type unsupported '%s'", G_STRFUNC,
param_def->type_name);
return NULL; return NULL;
} }
@ -355,46 +359,45 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
param_def->meta.m_id.none_ok = ispec->none_ok; param_def->meta.m_id.none_ok = ispec->none_ok;
} }
/* Resources. */
else if (GIMP_IS_PARAM_SPEC_BRUSH (pspec)) else if (GIMP_IS_PARAM_SPEC_BRUSH (pspec))
{ {
GimpParamSpecBrush *ispec = GIMP_PARAM_SPEC_BRUSH (pspec); GimpParamSpecResource *rspec = GIMP_PARAM_SPEC_RESOURCE (pspec);
param_def->param_def_type = GP_PARAM_DEF_TYPE_ID; param_def->param_def_type = GP_PARAM_DEF_TYPE_ID;
param_def->meta.m_id.none_ok = ispec->none_ok; param_def->meta.m_id.none_ok = rspec->none_ok;
}
else if (GIMP_IS_PARAM_SPEC_FONT (pspec))
{
GimpParamSpecFont *ispec = GIMP_PARAM_SPEC_FONT (pspec);
param_def->param_def_type = GP_PARAM_DEF_TYPE_ID;
param_def->meta.m_id.none_ok = ispec->none_ok;
}
else if (GIMP_IS_PARAM_SPEC_GRADIENT (pspec))
{
GimpParamSpecGradient *ispec = GIMP_PARAM_SPEC_GRADIENT (pspec);
param_def->param_def_type = GP_PARAM_DEF_TYPE_ID;
param_def->meta.m_id.none_ok = ispec->none_ok;
}
else if (GIMP_IS_PARAM_SPEC_PALETTE (pspec))
{
GimpParamSpecPalette *ispec = GIMP_PARAM_SPEC_PALETTE (pspec);
param_def->param_def_type = GP_PARAM_DEF_TYPE_ID;
param_def->meta.m_id.none_ok = ispec->none_ok;
} }
else if (GIMP_IS_PARAM_SPEC_PATTERN (pspec)) else if (GIMP_IS_PARAM_SPEC_PATTERN (pspec))
{ {
GimpParamSpecPattern *ispec = GIMP_PARAM_SPEC_PATTERN (pspec); GimpParamSpecResource *rspec = GIMP_PARAM_SPEC_RESOURCE (pspec);
param_def->param_def_type = GP_PARAM_DEF_TYPE_ID; param_def->param_def_type = GP_PARAM_DEF_TYPE_ID;
param_def->meta.m_id.none_ok = ispec->none_ok; param_def->meta.m_id.none_ok = rspec->none_ok;
}
else if (GIMP_IS_PARAM_SPEC_GRADIENT (pspec))
{
GimpParamSpecResource *rspec = GIMP_PARAM_SPEC_RESOURCE (pspec);
param_def->param_def_type = GP_PARAM_DEF_TYPE_ID;
param_def->meta.m_id.none_ok = rspec->none_ok;
}
else if (GIMP_IS_PARAM_SPEC_PALETTE (pspec))
{
GimpParamSpecResource *rspec = GIMP_PARAM_SPEC_RESOURCE (pspec);
param_def->param_def_type = GP_PARAM_DEF_TYPE_ID;
param_def->meta.m_id.none_ok = rspec->none_ok;
}
else if (GIMP_IS_PARAM_SPEC_FONT (pspec))
{
GimpParamSpecResource *rspec = GIMP_PARAM_SPEC_RESOURCE (pspec);
param_def->param_def_type = GP_PARAM_DEF_TYPE_ID;
param_def->meta.m_id.none_ok = rspec->none_ok;
} }
else if (GIMP_IS_PARAM_SPEC_OBJECT_ARRAY (pspec)) else if (GIMP_IS_PARAM_SPEC_OBJECT_ARRAY (pspec))
{ {
@ -476,7 +479,8 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
else else
{ {
g_warning ("%s: GParamSpecObject for unsupported type '%s:%s'", g_warning ("%s: GParamSpecObject for unsupported type '%s:%s'",
G_STRFUNC, param_def->type_name, param_def->value_type_name); G_STRFUNC,
param_def->type_name, param_def->value_type_name);
} }
} }
} }
@ -514,87 +518,30 @@ get_display_by_id (gpointer gimp,
#endif #endif
} }
/* Return an object instance by ID, for a subclass of GimpResource
*
* On app/core side, returns existing instance.
* (But GimpResource is not defined app/core)
*
* On libgimp side, creates a new instance of a proxy.
* The new instance is put in a GValue.
* The new instance's life is the same as the GValue.
* The GValue should eventually be freed by the caller,
* but not while the resource proxy instance is in use.
*/
static GObject * static GObject *
get_resource_by_id (gpointer gimp, get_resource_by_id (gint id)
GType gtype,
gchar *id)
{ {
GObject *resource = NULL;
GError *error = NULL;
g_return_val_if_fail (id != NULL, NULL);
#ifdef LIBGIMP_COMPILATION #ifdef LIBGIMP_COMPILATION
/* Return a new proxy instance, not any instance already existing. return (GObject *) gimp_resource_get_by_id (id);
* Primarily for class's new() and duplicate() methods,
* and for procedure args of a resource type.
*/
resource = g_object_new (gtype, NULL);
g_object_set (resource, "id", id, NULL);
g_debug ("libgimp:get_resource_by_id");
#else #else
if (gtype == GIMP_TYPE_BRUSH) return (GObject *) gimp_data_get_by_id (id);
resource = (GObject*) gimp_pdb_get_brush (gimp, id, GIMP_PDB_DATA_ACCESS_READ, &error);
else if (gtype == GIMP_TYPE_FONT)
resource = (GObject*) gimp_pdb_get_font (gimp, id, &error);
else if (gtype == GIMP_TYPE_GRADIENT)
resource = (GObject*) gimp_pdb_get_gradient (gimp, id, GIMP_PDB_DATA_ACCESS_READ, &error);
else if (gtype == GIMP_TYPE_PALETTE)
resource = (GObject*) gimp_pdb_get_palette (gimp, id, GIMP_PDB_DATA_ACCESS_READ, &error);
else if (gtype == GIMP_TYPE_PATTERN)
resource = (GObject*) gimp_pdb_get_pattern (gimp, id, &error);
else
g_warning ("%s unsupported type: %s", G_STRFUNC, g_type_name (gtype));
if (error != NULL)
g_warning ("A plugin is trying to use resource '%s' (of type %s) that is no longer installed: %s",
id, g_type_name (gtype), error->message);
#endif #endif
g_clear_error (&error);
return resource;
} }
/* Return a resource's ID. static gint
* This hides the fact that app/core uses object name as ID, and doesn't have a GimpResource class.
*
* On app/core side, object name. GimpResource is not a class.
*
* On libgimp side, returns the id property. Class GimpResource is defined.
*/
static gchar *
get_resource_id (GObject *resource) get_resource_id (GObject *resource)
{ {
#ifdef LIBGIMP_COMPILATION #ifdef LIBGIMP_COMPILATION
gchar *id = NULL; return gimp_resource_get_id (GIMP_RESOURCE (resource));
/* Require resource is-a GimpResource having property id. */
g_debug ("libgimp: %s", G_STRFUNC);
g_object_get (resource, "id", &id, NULL);
return id;
#else #else
/* Cast to avoid "discarding const qualifier" */ return gimp_data_get_id (GIMP_DATA (resource));
return (gchar*) gimp_object_get_name (resource);
#endif #endif
} }
/* Deserialize a gp_param (from the wire) to an instance of object or
/* Deserialize a gp_param (from the wire) to an instance of object or primitive type. * primitive type.
*
* This is used on both the core and plugin (libgimp) side, * This is used on both the core and plugin (libgimp) side,
* each having its own class definitions for a same named class. * each having its own class definitions for a same named class.
* Thus this creates different objects, depending on which side it is. * Thus this creates different objects, depending on which side it is.
@ -613,7 +560,15 @@ gimp_gp_param_to_value (gpointer gimp,
{ {
type = g_type_from_name (param->type_name); type = g_type_from_name (param->type_name);
if (type == 0) if (type == 0)
g_critical ("%s: type name %s is not registered", G_STRFUNC, param->type_name); {
if (! strcmp (param->type_name, "GimpResource"))
type = g_type_from_name ("GimpData");
else if (! strcmp (param->type_name, "GimpData"))
type = g_type_from_name ("GimpResource");
else
g_critical ("%s: type name %s is not registered", G_STRFUNC,
param->type_name);
}
} }
/* assert type is not G_TYPE_NONE and type is not G_TYPE_INVALID. */ /* assert type is not G_TYPE_NONE and type is not G_TYPE_INVALID. */
@ -737,13 +692,7 @@ gimp_gp_param_to_value (gpointer gimp,
} }
else if (GIMP_VALUE_HOLDS_RESOURCE (value)) else if (GIMP_VALUE_HOLDS_RESOURCE (value))
{ {
/* when compiled in app, use generic pointer. */ g_value_set_object (value, get_resource_by_id (param->data.d_int));
gpointer resource = NULL;
if (param->data.d_string != NULL)
resource = get_resource_by_id (gimp, G_VALUE_TYPE (value), param->data.d_string);
g_value_set_object (value, resource);
} }
else if (G_VALUE_HOLDS_PARAM (value)) else if (G_VALUE_HOLDS_PARAM (value))
{ {
@ -1082,28 +1031,9 @@ gimp_value_to_gp_param (const GValue *value,
{ {
GObject *resource = g_value_get_object (value); GObject *resource = g_value_get_object (value);
/* Represent by a char*, which must be NULL when resource is NULL. param->param_type = GP_PARAM_TYPE_INT;
* resource may be NULL e.g. for return value of a canceled dialog.
*/
param->param_type = GP_PARAM_TYPE_STRING;
if (resource != NULL) param->data.d_int = resource ? get_resource_id (resource) : -1;
{
gchar *resource_id = get_resource_id (resource);
/* resource_id can be NULL if resource is invalid. */
if (full_copy)
param->data.d_string = g_strdup (resource_id);
else
param->data.d_string = resource_id;
}
else
{
param->data.d_string = NULL;
}
/* Ensure ( full_copy AND ( d_string==NULL OR points to new allocation ))
* OR ( not full copy AND ( d_string==NULL OR points to resource's ID char* )
*/
} }
else if (G_VALUE_HOLDS_PARAM (value)) else if (G_VALUE_HOLDS_PARAM (value))
{ {

View File

@ -72,6 +72,42 @@ gimp_gradient_new (const gchar *name)
return gradient; return gradient;
} }
/**
* gimp_gradient_get_by_name:
* @name: The name of the gradient.
*
* Returns the gradient with the given name.
*
* Returns the gradient with the given name.
*
* Returns: (transfer full): The gradient.
*
* Since: 3.0
**/
GimpGradient *
gimp_gradient_get_by_name (const gchar *name)
{
GimpValueArray *args;
GimpValueArray *return_vals;
GimpGradient *gradient = NULL;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_STRING, name,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-gradient-get-by-name",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
gradient = GIMP_VALUES_GET_GRADIENT (return_vals, 1);
gimp_value_array_unref (return_vals);
return gradient;
}
/** /**
* gimp_gradient_duplicate: * gimp_gradient_duplicate:
* @gradient: The gradient. * @gradient: The gradient.
@ -152,13 +188,7 @@ gimp_gradient_is_editable (GimpGradient *gradient)
* Renames a gradient. When the name is in use, renames to a unique * Renames a gradient. When the name is in use, renames to a unique
* name. * name.
* *
* Renames a gradient. The name is the same as the ID. When the * Renames a gradient.
* proposed name is already used, GIMP generates a unique name, which
* get_id() will return.
* Returns a reference to a renamed gradient, which you should assign
* to the original var or a differently named var. Any existing
* references will be invalid. Resources in plugins are proxies holding
* an ID, which can be invalid when the resource is renamed.
* *
* Returns: (transfer full): A reference to the renamed gradient. * Returns: (transfer full): A reference to the renamed gradient.
* *
@ -383,42 +413,6 @@ gimp_gradient_get_custom_samples (GimpGradient *gradient,
return success; return success;
} }
/**
* gimp_gradient_id_is_valid:
* @id: The gradient ID.
*
* Whether the ID is a valid reference to installed data.
*
* Returns TRUE if this ID is valid.
*
* Returns: TRUE if the gradient ID is valid.
*
* Since: 3.0
**/
gboolean
gimp_gradient_id_is_valid (const gchar *id)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean valid = FALSE;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_STRING, id,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-gradient-id-is-valid",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
valid = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
gimp_value_array_unref (return_vals);
return valid;
}
/** /**
* gimp_gradient_segment_get_left_color: * gimp_gradient_segment_get_left_color:
* @gradient: The gradient. * @gradient: The gradient.

View File

@ -33,6 +33,7 @@ G_BEGIN_DECLS
GimpGradient* gimp_gradient_new (const gchar *name); GimpGradient* gimp_gradient_new (const gchar *name);
GimpGradient* gimp_gradient_get_by_name (const gchar *name);
GimpGradient* gimp_gradient_duplicate (GimpGradient *gradient); GimpGradient* gimp_gradient_duplicate (GimpGradient *gradient);
gboolean gimp_gradient_is_editable (GimpGradient *gradient); gboolean gimp_gradient_is_editable (GimpGradient *gradient);
GimpGradient* gimp_gradient_rename (GimpGradient *gradient, GimpGradient* gimp_gradient_rename (GimpGradient *gradient,
@ -50,7 +51,6 @@ gboolean gimp_gradient_get_custom_samples (GimpGradient
gboolean reverse, gboolean reverse,
gint *num_color_samples, gint *num_color_samples,
gdouble **color_samples); gdouble **color_samples);
gboolean gimp_gradient_id_is_valid (const gchar *id);
gboolean gimp_gradient_segment_get_left_color (GimpGradient *gradient, gboolean gimp_gradient_segment_get_left_color (GimpGradient *gradient,
gint segment, gint segment,
GimpRGB *color, GimpRGB *color,

View File

@ -232,29 +232,20 @@ static gboolean
get_gradient_data (GimpGradientSelectButton *self, get_gradient_data (GimpGradientSelectButton *self,
gint allocation_width, gint allocation_width,
gint *sample_count, gint *sample_count,
gdouble **sample_array gdouble **sample_array)
)
{ {
gboolean result;
gdouble *samples;
gint n_samples;
GimpGradient *gradient; GimpGradient *gradient;
gboolean result;
gdouble *samples;
gint n_samples;
g_debug ("%s", G_STRFUNC);
/* Self's gradient is property "resource"
* (resource field of super is private.)
*/
g_object_get (self, "resource", &gradient, NULL); g_object_get (self, "resource", &gradient, NULL);
g_return_val_if_fail (GIMP_IS_GRADIENT (gradient), FALSE);
result = gimp_gradient_get_uniform_samples ( result = gimp_gradient_get_uniform_samples (gradient,
gradient, allocation_width,
allocation_width, FALSE, /* not reversed. */
FALSE, /* not reversed. */ &n_samples,
&n_samples, &samples);
&samples);
if (result) if (result)
{ {

View File

@ -75,6 +75,42 @@ gimp_palette_new (const gchar *name)
return palette; return palette;
} }
/**
* gimp_palette_get_by_name:
* @name: The name of the palette.
*
* Returns the palette with the given name.
*
* Returns the palette with the given name.
*
* Returns: (transfer full): The palette.
*
* Since: 3.0
**/
GimpPalette *
gimp_palette_get_by_name (const gchar *name)
{
GimpValueArray *args;
GimpValueArray *return_vals;
GimpPalette *palette = NULL;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_STRING, name,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-palette-get-by-name",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
palette = GIMP_VALUES_GET_PALETTE (return_vals, 1);
gimp_value_array_unref (return_vals);
return palette;
}
/** /**
* gimp_palette_duplicate: * gimp_palette_duplicate:
* @palette: The palette. * @palette: The palette.
@ -111,42 +147,6 @@ gimp_palette_duplicate (GimpPalette *palette)
return palette_copy; return palette_copy;
} }
/**
* gimp_palette_id_is_valid:
* @id: The palette ID.
*
* Whether the ID is a valid reference to installed data.
*
* Returns TRUE if this ID is valid.
*
* Returns: TRUE if the palette ID is valid.
*
* Since: 3.0
**/
gboolean
gimp_palette_id_is_valid (const gchar *id)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean valid = FALSE;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_STRING, id,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-palette-id-is-valid",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
valid = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
gimp_value_array_unref (return_vals);
return valid;
}
/** /**
* gimp_palette_rename: * gimp_palette_rename:
* @palette: The palette. * @palette: The palette.

View File

@ -33,8 +33,8 @@ G_BEGIN_DECLS
GimpPalette* gimp_palette_new (const gchar *name); GimpPalette* gimp_palette_new (const gchar *name);
GimpPalette* gimp_palette_get_by_name (const gchar *name);
GimpPalette* gimp_palette_duplicate (GimpPalette *palette); GimpPalette* gimp_palette_duplicate (GimpPalette *palette);
gboolean gimp_palette_id_is_valid (const gchar *id);
GimpPalette* gimp_palette_rename (GimpPalette *palette, GimpPalette* gimp_palette_rename (GimpPalette *palette,
const gchar *new_name); const gchar *new_name);
gboolean gimp_palette_delete (GimpPalette *palette); gboolean gimp_palette_delete (GimpPalette *palette);

View File

@ -19,8 +19,6 @@
* <https://www.gnu.org/licenses/>. * <https://www.gnu.org/licenses/>.
*/ */
/* Similar to gimpfontselectbutton.c, initially created by simple substitution. */
#include "config.h" #include "config.h"
#include <gegl.h> #include <gegl.h>
@ -47,7 +45,6 @@
struct _GimpPaletteSelectButton struct _GimpPaletteSelectButton
{ {
/* !! Not a pointer, is contained. */
GimpResourceSelectButton parent_instance; GimpResourceSelectButton parent_instance;
GtkWidget *palette_name_label; GtkWidget *palette_name_label;
@ -55,18 +52,16 @@ struct _GimpPaletteSelectButton
GtkWidget *button; GtkWidget *button;
}; };
/* local */
/* implement virtual */
static void gimp_palette_select_button_finalize (GObject *object); static void gimp_palette_select_button_finalize (GObject *object);
static void gimp_palette_select_button_draw_interior (GimpResourceSelectButton *self); static void gimp_palette_select_button_draw_interior (GimpResourceSelectButton *self);
/* Called at init. */
static GtkWidget *gimp_palette_select_button_create_interior (GimpPaletteSelectButton *self); static GtkWidget *gimp_palette_select_button_create_interior (GimpPaletteSelectButton *self);
/* A GtkTargetEntry has a string and two ints. This is one, but treat as an array.*/
static const GtkTargetEntry drag_target = { "application/x-gimp-palette-name", 0, 0 }; static const GtkTargetEntry drag_target = { "application/x-gimp-palette-name", 0, 0 };
G_DEFINE_FINAL_TYPE (GimpPaletteSelectButton, G_DEFINE_FINAL_TYPE (GimpPaletteSelectButton,
gimp_palette_select_button, gimp_palette_select_button,
GIMP_TYPE_RESOURCE_SELECT_BUTTON) GIMP_TYPE_RESOURCE_SELECT_BUTTON)
@ -75,24 +70,13 @@ G_DEFINE_FINAL_TYPE (GimpPaletteSelectButton,
static void static void
gimp_palette_select_button_class_init (GimpPaletteSelectButtonClass *klass) gimp_palette_select_button_class_init (GimpPaletteSelectButtonClass *klass)
{ {
/* Alias cast klass to super classes. */ GObjectClass *object_class = G_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass); GimpResourceSelectButtonClass *superclass = GIMP_RESOURCE_SELECT_BUTTON_CLASS (klass);
GimpResourceSelectButtonClass *superclass = GIMP_RESOURCE_SELECT_BUTTON_CLASS (klass);
g_debug ("%s called", G_STRFUNC);
/* Override virtual. */
object_class->finalize = gimp_palette_select_button_finalize; object_class->finalize = gimp_palette_select_button_finalize;
/* Implement pure virtual functions. */
superclass->draw_interior = gimp_palette_select_button_draw_interior; superclass->draw_interior = gimp_palette_select_button_draw_interior;
/* Set data member of class. */
superclass->resource_type = GIMP_TYPE_PALETTE; superclass->resource_type = GIMP_TYPE_PALETTE;
/* We don't define property getter/setters: use superclass getter/setters.
* But super property name is "resource", not "palette"
*/
} }
static void static void
@ -100,26 +84,13 @@ gimp_palette_select_button_init (GimpPaletteSelectButton *self)
{ {
GtkWidget *interior; GtkWidget *interior;
g_debug ("%s called", G_STRFUNC);
/* Specialize super:
* - embed our widget interior instance to super widget instance.
* - tell super our dnd widget
* - tell super our clickable button
* Call superclass methods, with upcasts.
* These are on instance, not our subclass.
*/
interior = gimp_palette_select_button_create_interior (self); interior = gimp_palette_select_button_create_interior (self);
/* require self has sub widgets initialized. */
/* Embed the whole button.*/
gimp_resource_select_button_embed_interior (GIMP_RESOURCE_SELECT_BUTTON (self), interior); gimp_resource_select_button_embed_interior (GIMP_RESOURCE_SELECT_BUTTON (self), interior);
/* Self knows the GtkTargetEntry, super creates target and handles receive drag. */
gimp_resource_select_button_set_drag_target (GIMP_RESOURCE_SELECT_BUTTON (self), gimp_resource_select_button_set_drag_target (GIMP_RESOURCE_SELECT_BUTTON (self),
self->drag_region_widget, self->drag_region_widget,
&drag_target); &drag_target);
/* Super handles button clicks. */
gimp_resource_select_button_set_clickable (GIMP_RESOURCE_SELECT_BUTTON (self), gimp_resource_select_button_set_clickable (GIMP_RESOURCE_SELECT_BUTTON (self),
self->button); self->button);
} }
@ -144,24 +115,9 @@ gimp_palette_select_button_new (const gchar *title,
{ {
GtkWidget *self; GtkWidget *self;
g_debug ("%s called", G_STRFUNC);
if (resource == NULL) if (resource == NULL)
{ resource = GIMP_RESOURCE (gimp_context_get_palette ());
g_debug ("%s defaulting palette from context", G_STRFUNC);
resource = GIMP_RESOURCE (gimp_context_get_palette ());
}
g_assert (resource != NULL);
/* This method is polymorphic, so a factory can call it, but requires Palette. */
g_return_val_if_fail (GIMP_IS_PALETTE (resource), NULL);
/* Create instance of self (not super.)
* This will call superclass init, self class init, superclass init, and instance init.
* Self subclass class_init will specialize by implementing virtual funcs
* that open and set remote chooser dialog, and that draw self interior.
*
* !!! property belongs to superclass and is named "resource"
*/
if (title) if (title)
self = g_object_new (GIMP_TYPE_PALETTE_SELECT_BUTTON, self = g_object_new (GIMP_TYPE_PALETTE_SELECT_BUTTON,
"title", title, "title", title,
@ -172,17 +128,8 @@ gimp_palette_select_button_new (const gchar *title,
"resource", resource, "resource", resource,
NULL); NULL);
/* We don't subscribe to events from super (such as draw events.)
* Super will call our draw method when it's resource changes.
* Except that the above setting of property happens too late,
* so we now draw the initial resource.
*/
/* Draw with the initial resource. Cast self from Widget. */
gimp_palette_select_button_draw_interior (GIMP_RESOURCE_SELECT_BUTTON (self)); gimp_palette_select_button_draw_interior (GIMP_RESOURCE_SELECT_BUTTON (self));
g_debug ("%s returns", G_STRFUNC);
return self; return self;
} }
@ -303,35 +250,17 @@ gimp_palette_select_button_create_interior (GimpPaletteSelectButton *self)
return button; return button;
} }
/* Knows how to draw self interior.
* Self knows resource, it is not passed.
*
* Overrides virtual method in super, so it is generic on Resource.
*/
static void static void
gimp_palette_select_button_draw_interior (GimpResourceSelectButton *self) gimp_palette_select_button_draw_interior (GimpResourceSelectButton *self)
{ {
gchar *palette_name; GimpPaletteSelectButton *palette_select= GIMP_PALETTE_SELECT_BUTTON (self);
GimpResource *resource; GimpResource *resource;
GimpPaletteSelectButton *self_as_palette_select; gchar *name = NULL;
g_debug ("%s", G_STRFUNC); resource = gimp_resource_select_button_get_resource (self);
g_return_if_fail (GIMP_IS_PALETTE_SELECT_BUTTON (self)); if (resource)
self_as_palette_select = GIMP_PALETTE_SELECT_BUTTON (self); name = gimp_resource_get_name (resource);
g_object_get (self, "resource", &resource, NULL); gtk_label_set_text (GTK_LABEL (palette_select->palette_name_label), name);
/* For now, the "id" property of the resource is the name.
* FUTURE: core will support name distinct from ID.
*/
g_object_get (resource, "id", &palette_name, NULL);
/* We are not keeping a copy of palette name, nothing to free. */
/* Not styling the text using the chosen palette,
* just replacing the text with the name of the chosen palette.
*/
gtk_label_set_text (GTK_LABEL (self_as_palette_select->palette_name_label), palette_name);
} }

View File

@ -29,9 +29,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/* This defines certain structs and the usual macros.
* A final type has no private.
*/
#define GIMP_TYPE_PALETTE_SELECT_BUTTON (gimp_palette_select_button_get_type ()) #define GIMP_TYPE_PALETTE_SELECT_BUTTON (gimp_palette_select_button_get_type ())
G_DECLARE_FINAL_TYPE (GimpPaletteSelectButton, G_DECLARE_FINAL_TYPE (GimpPaletteSelectButton,
gimp_palette_select_button, gimp_palette_select_button,

View File

@ -1,697 +0,0 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
/* this .c file is included by both
*
* libgimp/gimpparamspecs.c
* app/core/gimpparamspecs.c
*/
/*
* GIMP_TYPE_PARAM_RESOURCE
*/
static void gimp_param_resource_class_init (GParamSpecClass *klass);
static void gimp_param_resource_init (GParamSpec *pspec);
static gboolean gimp_param_resource_validate (GParamSpec *pspec,
GValue *value);
GType
gimp_param_resource_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_resource_class_init,
NULL, NULL,
sizeof (GimpParamSpecResource),
0,
(GInstanceInitFunc) gimp_param_resource_init
};
type = g_type_register_static (G_TYPE_PARAM_OBJECT,
"GimpParamResource", &info, 0);
}
return type;
}
static void
gimp_param_resource_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_RESOURCE;
klass->value_validate = gimp_param_resource_validate;
}
static void
gimp_param_resource_init (GParamSpec *pspec)
{
GimpParamSpecResource *ispec = GIMP_PARAM_SPEC_RESOURCE (pspec);
ispec->none_ok = FALSE;
}
/* Return TRUE when value is invalid!!!
* FIXME: should be named is_invalid.
*/
static gboolean
gimp_param_resource_validate (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecResource *ispec = GIMP_PARAM_SPEC_RESOURCE (pspec);
GimpResource *resource = value->data[0].v_pointer;
g_debug (">>>>>%s", G_STRFUNC);
if (! ispec->none_ok && resource == NULL)
/* NULL when NULL not allowed is invalid. */
return TRUE;
if (resource != NULL)
{
if (GIMP_IS_BRUSH (resource) && gimp_brush_is_valid (GIMP_BRUSH (resource)))
return FALSE;
else if (GIMP_IS_FONT (resource) && gimp_font_is_valid (GIMP_FONT (resource)))
return FALSE;
else if (GIMP_IS_GRADIENT (resource) && gimp_gradient_is_valid (GIMP_GRADIENT (resource)))
return FALSE;
else if (GIMP_IS_PALETTE (resource) && gimp_palette_is_valid (GIMP_PALETTE (resource)))
return FALSE;
else if (GIMP_IS_PATTERN (resource) && gimp_pattern_is_valid (GIMP_PATTERN (resource)))
return FALSE;
else
{
/* Not a resource type or is invalid reference to core resource.
* Plugin might be using a resource that was uninstalled.
*/
g_object_unref (resource);
value->data[0].v_pointer = NULL;
return TRUE;
}
}
else
{
/* resource is NULL but null is valid.*/
return FALSE;
}
}
/**
* gimp_param_spec_resource:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecResource specifying a
* #GIMP_TYPE_RESOURCE property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecResource.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_resource (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
GParamFlags flags)
{
GimpParamSpecResource *ispec;
ispec = g_param_spec_internal (GIMP_TYPE_PARAM_RESOURCE,
name, nick, blurb, flags);
g_return_val_if_fail (ispec, NULL);
ispec->none_ok = none_ok ? TRUE : FALSE;
return G_PARAM_SPEC (ispec);
}
/*
* GIMP_TYPE_PARAM_BRUSH
*/
static void gimp_param_brush_class_init (GParamSpecClass *klass);
static void gimp_param_brush_init (GParamSpec *pspec);
static gboolean gimp_param_brush_validate (GParamSpec *pspec,
GValue *value);
GType
gimp_param_brush_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_brush_class_init,
NULL, NULL,
sizeof (GimpParamSpecBrush),
0,
(GInstanceInitFunc) gimp_param_brush_init
};
type = g_type_register_static (G_TYPE_PARAM_OBJECT,
"GimpParamBrush", &info, 0);
}
return type;
}
static void
gimp_param_brush_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_BRUSH;
klass->value_validate = gimp_param_brush_validate;
}
static void
gimp_param_brush_init (GParamSpec *pspec)
{
GimpParamSpecBrush *ispec = GIMP_PARAM_SPEC_BRUSH (pspec);
ispec->none_ok = FALSE;
}
static gboolean
gimp_param_brush_validate (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecBrush *ispec = GIMP_PARAM_SPEC_BRUSH (pspec);
GimpBrush *brush = value->data[0].v_pointer;
if (! ispec->none_ok && brush == NULL)
return TRUE;
if (brush && (! GIMP_IS_BRUSH (brush) ||
! gimp_brush_is_valid (brush)))
{
g_object_unref (brush);
value->data[0].v_pointer = NULL;
return TRUE;
}
return FALSE;
}
/**
* gimp_param_spec_brush:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecBrush specifying a
* #GIMP_TYPE_BRUSH property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecBrush.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_brush (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
GParamFlags flags)
{
GimpParamSpecBrush *ispec;
ispec = g_param_spec_internal (GIMP_TYPE_PARAM_BRUSH,
name, nick, blurb, flags);
g_return_val_if_fail (ispec, NULL);
ispec->none_ok = none_ok ? TRUE : FALSE;
return G_PARAM_SPEC (ispec);
}
/*
* GIMP_TYPE_PARAM_FONT
*/
static void gimp_param_font_class_init (GParamSpecClass *klass);
static void gimp_param_font_init (GParamSpec *pspec);
static gboolean gimp_param_font_validate (GParamSpec *pspec,
GValue *value);
GType
gimp_param_font_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_font_class_init,
NULL, NULL,
sizeof (GimpParamSpecFont),
0,
(GInstanceInitFunc) gimp_param_font_init
};
type = g_type_register_static (G_TYPE_PARAM_OBJECT,
"GimpParamFont", &info, 0);
}
return type;
}
static void
gimp_param_font_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_FONT;
klass->value_validate = gimp_param_font_validate;
}
static void
gimp_param_font_init (GParamSpec *pspec)
{
GimpParamSpecFont *ispec = GIMP_PARAM_SPEC_FONT (pspec);
ispec->none_ok = FALSE;
}
static gboolean
gimp_param_font_validate (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecFont *ispec = GIMP_PARAM_SPEC_FONT (pspec);
GimpFont *font = value->data[0].v_pointer;
if (! ispec->none_ok && font == NULL)
return TRUE;
if (font && (! GIMP_IS_FONT (font) ||
! gimp_font_is_valid (font)))
{
g_object_unref (font);
value->data[0].v_pointer = NULL;
return TRUE;
}
return FALSE;
}
/**
* gimp_param_spec_font:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecFont specifying a
* #GIMP_TYPE_FONT property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecFont.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_font (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
GParamFlags flags)
{
GimpParamSpecFont *ispec;
ispec = g_param_spec_internal (GIMP_TYPE_PARAM_FONT,
name, nick, blurb, flags);
g_return_val_if_fail (ispec, NULL);
ispec->none_ok = none_ok ? TRUE : FALSE;
return G_PARAM_SPEC (ispec);
}
/*
* GIMP_TYPE_PARAM_GRADIENT
*/
static void gimp_param_gradient_class_init (GParamSpecClass *klass);
static void gimp_param_gradient_init (GParamSpec *pspec);
static gboolean gimp_param_gradient_validate (GParamSpec *pspec,
GValue *value);
GType
gimp_param_gradient_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_gradient_class_init,
NULL, NULL,
sizeof (GimpParamSpecGradient),
0,
(GInstanceInitFunc) gimp_param_gradient_init
};
type = g_type_register_static (G_TYPE_PARAM_OBJECT,
"GimpParamGradient", &info, 0);
}
return type;
}
static void
gimp_param_gradient_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_GRADIENT;
klass->value_validate = gimp_param_gradient_validate;
}
static void
gimp_param_gradient_init (GParamSpec *pspec)
{
GimpParamSpecGradient *ispec = GIMP_PARAM_SPEC_GRADIENT (pspec);
ispec->none_ok = FALSE;
}
static gboolean
gimp_param_gradient_validate (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecGradient *ispec = GIMP_PARAM_SPEC_GRADIENT (pspec);
GimpGradient *gradient = value->data[0].v_pointer;
if (! ispec->none_ok && gradient == NULL)
return TRUE;
if (gradient && (! GIMP_IS_GRADIENT (gradient) ||
! gimp_gradient_is_valid (gradient)))
{
g_object_unref (gradient);
value->data[0].v_pointer = NULL;
return TRUE;
}
return FALSE;
}
/**
* gimp_param_spec_gradient:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecGradient specifying a
* #GIMP_TYPE_GRADIENT property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecGradient.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_gradient (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
GParamFlags flags)
{
GimpParamSpecGradient *ispec;
ispec = g_param_spec_internal (GIMP_TYPE_PARAM_GRADIENT,
name, nick, blurb, flags);
g_return_val_if_fail (ispec, NULL);
ispec->none_ok = none_ok ? TRUE : FALSE;
return G_PARAM_SPEC (ispec);
}
/*
* GIMP_TYPE_PARAM_PALETTE
*/
static void gimp_param_palette_class_init (GParamSpecClass *klass);
static void gimp_param_palette_init (GParamSpec *pspec);
static gboolean gimp_param_palette_validate (GParamSpec *pspec,
GValue *value);
GType
gimp_param_palette_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_palette_class_init,
NULL, NULL,
sizeof (GimpParamSpecPalette),
0,
(GInstanceInitFunc) gimp_param_palette_init
};
type = g_type_register_static (G_TYPE_PARAM_OBJECT,
"GimpParamPalette", &info, 0);
}
return type;
}
static void
gimp_param_palette_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_PALETTE;
klass->value_validate = gimp_param_palette_validate;
}
static void
gimp_param_palette_init (GParamSpec *pspec)
{
GimpParamSpecPalette *ispec = GIMP_PARAM_SPEC_PALETTE (pspec);
ispec->none_ok = FALSE;
}
static gboolean
gimp_param_palette_validate (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecPalette *ispec = GIMP_PARAM_SPEC_PALETTE (pspec);
GimpPalette *palette = value->data[0].v_pointer;
if (! ispec->none_ok && palette == NULL)
return TRUE;
if (palette && (! GIMP_IS_PALETTE (palette) ||
! gimp_palette_is_valid (palette)))
{
g_object_unref (palette);
value->data[0].v_pointer = NULL;
return TRUE;
}
return FALSE;
}
/**
* gimp_param_spec_palette:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecPalette specifying a
* #GIMP_TYPE_PALETTE property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecPalette.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_palette (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
GParamFlags flags)
{
GimpParamSpecPalette *ispec;
ispec = g_param_spec_internal (GIMP_TYPE_PARAM_PALETTE,
name, nick, blurb, flags);
g_return_val_if_fail (ispec, NULL);
ispec->none_ok = none_ok ? TRUE : FALSE;
return G_PARAM_SPEC (ispec);
}
/*
* GIMP_TYPE_PARAM_PATTERN
*/
static void gimp_param_pattern_class_init (GParamSpecClass *klass);
static void gimp_param_pattern_init (GParamSpec *pspec);
static gboolean gimp_param_pattern_validate (GParamSpec *pspec,
GValue *value);
GType
gimp_param_pattern_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_pattern_class_init,
NULL, NULL,
sizeof (GimpParamSpecPattern),
0,
(GInstanceInitFunc) gimp_param_pattern_init
};
type = g_type_register_static (G_TYPE_PARAM_OBJECT,
"GimpParamPattern", &info, 0);
}
return type;
}
static void
gimp_param_pattern_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_PATTERN;
klass->value_validate = gimp_param_pattern_validate;
}
static void
gimp_param_pattern_init (GParamSpec *pspec)
{
GimpParamSpecPattern *ispec = GIMP_PARAM_SPEC_PATTERN (pspec);
ispec->none_ok = FALSE;
}
static gboolean
gimp_param_pattern_validate (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecPattern *ispec = GIMP_PARAM_SPEC_PATTERN (pspec);
GimpPattern *pattern = value->data[0].v_pointer;
if (! ispec->none_ok && pattern == NULL)
return TRUE;
if (pattern && (! GIMP_IS_PATTERN (pattern) ||
! gimp_pattern_is_valid (pattern)))
{
g_object_unref (pattern);
value->data[0].v_pointer = NULL;
return TRUE;
}
return FALSE;
}
/**
* gimp_param_spec_pattern:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecPattern specifying a
* #GIMP_TYPE_PATTERN property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecPattern.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_pattern (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
GParamFlags flags)
{
GimpParamSpecPattern *ispec;
ispec = g_param_spec_internal (GIMP_TYPE_PARAM_PATTERN,
name, nick, blurb, flags);
g_return_val_if_fail (ispec, NULL);
ispec->none_ok = none_ok ? TRUE : FALSE;
return G_PARAM_SPEC (ispec);
}

View File

@ -460,10 +460,10 @@ gimp_param_text_layer_init (GParamSpec *pspec)
**/ **/
GParamSpec * GParamSpec *
gimp_param_spec_text_layer (const gchar *name, gimp_param_spec_text_layer (const gchar *name,
const gchar *nick, const gchar *nick,
const gchar *blurb, const gchar *blurb,
gboolean none_ok, gboolean none_ok,
GParamFlags flags) GParamFlags flags)
{ {
GimpParamSpecItem *ispec; GimpParamSpecItem *ispec;
@ -855,7 +855,7 @@ gimp_param_display_validate (GParamSpec *pspec,
GimpDisplay *display = value->data[0].v_pointer; GimpDisplay *display = value->data[0].v_pointer;
if (! dspec->none_ok && display == NULL) if (! dspec->none_ok && display == NULL)
return TRUE; return TRUE;
if (display && (! GIMP_IS_DISPLAY (display) || if (display && (! GIMP_IS_DISPLAY (display) ||
! gimp_display_is_valid (display))) ! gimp_display_is_valid (display)))
@ -903,3 +903,518 @@ gimp_param_spec_display (const gchar *name,
return G_PARAM_SPEC (dspec); return G_PARAM_SPEC (dspec);
} }
/*
* GIMP_TYPE_PARAM_RESOURCE
*/
static void gimp_param_resource_class_init (GParamSpecClass *klass);
static void gimp_param_resource_init (GParamSpec *pspec);
static gboolean gimp_param_resource_validate (GParamSpec *pspec,
GValue *value);
GType
gimp_param_resource_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_resource_class_init,
NULL, NULL,
sizeof (GimpParamSpecResource),
0,
(GInstanceInitFunc) gimp_param_resource_init
};
type = g_type_register_static (G_TYPE_PARAM_OBJECT,
"GimpParamResource", &info, 0);
}
return type;
}
static void
gimp_param_resource_class_init (GParamSpecClass *klass)
{
#ifdef LIBGIMP_COMPILATION
klass->value_type = GIMP_TYPE_RESOURCE;
#else
klass->value_type = GIMP_TYPE_DATA;
#endif
klass->value_validate = gimp_param_resource_validate;
}
static void
gimp_param_resource_init (GParamSpec *pspec)
{
GimpParamSpecResource *rspec = GIMP_PARAM_SPEC_RESOURCE (pspec);
rspec->none_ok = FALSE;
}
static gboolean
gimp_param_resource_validate (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecResource *rspec = GIMP_PARAM_SPEC_RESOURCE (pspec);
GObject *resource = value->data[0].v_pointer;
if (! rspec->none_ok && resource == NULL)
return TRUE;
if (resource && (! g_type_is_a (G_OBJECT_TYPE (resource), pspec->value_type) ||
! gimp_resource_is_valid ((gpointer) resource)))
{
g_object_unref (resource);
value->data[0].v_pointer = NULL;
return TRUE;
}
return FALSE;
}
/**
* gimp_param_spec_resource:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecResource specifying a
* #GIMP_TYPE_RESOURCE property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecResource.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_resource (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
GParamFlags flags)
{
GimpParamSpecResource *rspec;
rspec = g_param_spec_internal (GIMP_TYPE_PARAM_RESOURCE,
name, nick, blurb, flags);
g_return_val_if_fail (rspec, NULL);
rspec->none_ok = none_ok ? TRUE : FALSE;
return G_PARAM_SPEC (rspec);
}
/*
* GIMP_TYPE_PARAM_BRUSH
*/
static void gimp_param_brush_class_init (GParamSpecClass *klass);
static void gimp_param_brush_init (GParamSpec *pspec);
GType
gimp_param_brush_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_brush_class_init,
NULL, NULL,
sizeof (GimpParamSpecBrush),
0,
(GInstanceInitFunc) gimp_param_brush_init
};
type = g_type_register_static (GIMP_TYPE_PARAM_RESOURCE,
"GimpParamBrush", &info, 0);
}
return type;
}
static void
gimp_param_brush_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_BRUSH;
}
static void
gimp_param_brush_init (GParamSpec *pspec)
{
}
/**
* gimp_param_spec_brush:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecBrush specifying a
* #GIMP_TYPE_BRUSH property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecBrush.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_brush (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
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;
return G_PARAM_SPEC (rspec);
}
/*
* GIMP_TYPE_PARAM_FONT
*/
static void gimp_param_font_class_init (GParamSpecClass *klass);
static void gimp_param_font_init (GParamSpec *pspec);
GType
gimp_param_font_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_font_class_init,
NULL, NULL,
sizeof (GimpParamSpecFont),
0,
(GInstanceInitFunc) gimp_param_font_init
};
type = g_type_register_static (GIMP_TYPE_PARAM_RESOURCE,
"GimpParamFont", &info, 0);
}
return type;
}
static void
gimp_param_font_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_FONT;
}
static void
gimp_param_font_init (GParamSpec *pspec)
{
}
/**
* gimp_param_spec_font:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecFont specifying a
* #GIMP_TYPE_FONT property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecFont.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_font (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
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;
return G_PARAM_SPEC (rspec);
}
/*
* GIMP_TYPE_PARAM_GRADIENT
*/
static void gimp_param_gradient_class_init (GParamSpecClass *klass);
static void gimp_param_gradient_init (GParamSpec *pspec);
GType
gimp_param_gradient_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_gradient_class_init,
NULL, NULL,
sizeof (GimpParamSpecGradient),
0,
(GInstanceInitFunc) gimp_param_gradient_init
};
type = g_type_register_static (GIMP_TYPE_PARAM_RESOURCE,
"GimpParamGradient", &info, 0);
}
return type;
}
static void
gimp_param_gradient_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_GRADIENT;
}
static void
gimp_param_gradient_init (GParamSpec *pspec)
{
}
/**
* gimp_param_spec_gradient:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecGradient specifying a
* #GIMP_TYPE_GRADIENT property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecGradient.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_gradient (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
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;
return G_PARAM_SPEC (rspec);
}
/*
* GIMP_TYPE_PARAM_PALETTE
*/
static void gimp_param_palette_class_init (GParamSpecClass *klass);
static void gimp_param_palette_init (GParamSpec *pspec);
GType
gimp_param_palette_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_palette_class_init,
NULL, NULL,
sizeof (GimpParamSpecPalette),
0,
(GInstanceInitFunc) gimp_param_palette_init
};
type = g_type_register_static (GIMP_TYPE_PARAM_RESOURCE,
"GimpParamPalette", &info, 0);
}
return type;
}
static void
gimp_param_palette_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_PALETTE;
}
static void
gimp_param_palette_init (GParamSpec *pspec)
{
}
/**
* gimp_param_spec_palette:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecPalette specifying a
* #GIMP_TYPE_PALETTE property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecPalette.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_palette (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
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;
return G_PARAM_SPEC (rspec);
}
/*
* GIMP_TYPE_PARAM_PATTERN
*/
static void gimp_param_pattern_class_init (GParamSpecClass *klass);
static void gimp_param_pattern_init (GParamSpec *pspec);
GType
gimp_param_pattern_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_pattern_class_init,
NULL, NULL,
sizeof (GimpParamSpecPattern),
0,
(GInstanceInitFunc) gimp_param_pattern_init
};
type = g_type_register_static (GIMP_TYPE_PARAM_RESOURCE,
"GimpParamPattern", &info, 0);
}
return type;
}
static void
gimp_param_pattern_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_PATTERN;
}
static void
gimp_param_pattern_init (GParamSpec *pspec)
{
}
/**
* gimp_param_spec_pattern:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @none_ok: Whether no is a valid value.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecPattern specifying a
* #GIMP_TYPE_PATTERN property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer full): The newly created #GimpParamSpecPattern.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_pattern (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean none_ok,
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;
return G_PARAM_SPEC (rspec);
}

View File

@ -1,4 +1,3 @@
/* LIBGIMP - The GIMP Library /* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
* *
@ -17,7 +16,6 @@
* <https://www.gnu.org/licenses/>. * <https://www.gnu.org/licenses/>.
*/ */
#if !defined (__GIMP_H_INSIDE__) && !defined (GIMP_COMPILATION) #if !defined (__GIMP_H_INSIDE__) && !defined (GIMP_COMPILATION)
#error "Only <libgimp/gimp.h> can be included directly." #error "Only <libgimp/gimp.h> can be included directly."
#endif #endif
@ -31,7 +29,8 @@ G_BEGIN_DECLS
* GIMP_TYPE_PARAM_RESOURCE * GIMP_TYPE_PARAM_RESOURCE
*/ */
/* See bottom of this file for definition of GIMP_VALUE_HOLDS_RESOURCE(value) */ #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_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_PARAM_SPEC_RESOURCE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_RESOURCE, GimpParamSpecResource))
@ -42,25 +41,26 @@ typedef struct _GimpParamSpecResource GimpParamSpecResource;
struct _GimpParamSpecResource struct _GimpParamSpecResource
{ {
GParamSpecObject parent_instance; GParamSpecObject parent_instance;
gboolean none_ok; gboolean none_ok;
}; };
GType gimp_param_resource_get_type (void) G_GNUC_CONST; GType gimp_param_resource_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_resource ( GParamSpec * gimp_param_spec_resource (const gchar *name,
const gchar *name, const gchar *nick,
const gchar *nick, const gchar *blurb,
const gchar *blurb, gboolean none_ok,
gboolean none_ok, GParamFlags flags);
GParamFlags flags);
/* /*
* GIMP_TYPE_PARAM_BRUSH * GIMP_TYPE_PARAM_BRUSH
*/ */
#define GIMP_VALUE_HOLDS_BRUSH(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_BRUSH)) #define GIMP_VALUE_HOLDS_BRUSH(value) (G_TYPE_CHECK_VALUE_TYPE ((value), \
GIMP_TYPE_BRUSH))
#define GIMP_TYPE_PARAM_BRUSH (gimp_param_brush_get_type ()) #define GIMP_TYPE_PARAM_BRUSH (gimp_param_brush_get_type ())
#define GIMP_PARAM_SPEC_BRUSH(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_BRUSH, GimpParamSpecBrush)) #define GIMP_PARAM_SPEC_BRUSH(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_BRUSH, GimpParamSpecBrush))
#define GIMP_IS_PARAM_SPEC_BRUSH(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_BRUSH)) #define GIMP_IS_PARAM_SPEC_BRUSH(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_BRUSH))
@ -69,8 +69,7 @@ typedef struct _GimpParamSpecBrush GimpParamSpecBrush;
struct _GimpParamSpecBrush struct _GimpParamSpecBrush
{ {
GParamSpecObject parent_instance; GimpParamSpecResource parent_instance;
gboolean none_ok;
}; };
GType gimp_param_brush_get_type (void) G_GNUC_CONST; GType gimp_param_brush_get_type (void) G_GNUC_CONST;
@ -87,7 +86,9 @@ GParamSpec * gimp_param_spec_brush (const gchar *name,
* GIMP_TYPE_PARAM_FONT * GIMP_TYPE_PARAM_FONT
*/ */
#define GIMP_VALUE_HOLDS_FONT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_FONT)) #define GIMP_VALUE_HOLDS_FONT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), \
GIMP_TYPE_FONT))
#define GIMP_TYPE_PARAM_FONT (gimp_param_font_get_type ()) #define GIMP_TYPE_PARAM_FONT (gimp_param_font_get_type ())
#define GIMP_PARAM_SPEC_FONT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_FONT, GimpParamSpecFont)) #define GIMP_PARAM_SPEC_FONT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_FONT, GimpParamSpecFont))
#define GIMP_IS_PARAM_SPEC_FONT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_FONT)) #define GIMP_IS_PARAM_SPEC_FONT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_FONT))
@ -96,8 +97,7 @@ typedef struct _GimpParamSpecFont GimpParamSpecFont;
struct _GimpParamSpecFont struct _GimpParamSpecFont
{ {
GParamSpecObject parent_instance; GimpParamSpecResource parent_instance;
gboolean none_ok;
}; };
GType gimp_param_font_get_type (void) G_GNUC_CONST; GType gimp_param_font_get_type (void) G_GNUC_CONST;
@ -114,7 +114,9 @@ GParamSpec * gimp_param_spec_font (const gchar *name,
* GIMP_TYPE_PARAM_GRADIENT * GIMP_TYPE_PARAM_GRADIENT
*/ */
#define GIMP_VALUE_HOLDS_GRADIENT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_GRADIENT)) #define GIMP_VALUE_HOLDS_GRADIENT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), \
GIMP_TYPE_GRADIENT))
#define GIMP_TYPE_PARAM_GRADIENT (gimp_param_gradient_get_type ()) #define GIMP_TYPE_PARAM_GRADIENT (gimp_param_gradient_get_type ())
#define GIMP_PARAM_SPEC_GRADIENT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_GRADIENT, GimpParamSpecGradient)) #define GIMP_PARAM_SPEC_GRADIENT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_GRADIENT, GimpParamSpecGradient))
#define GIMP_IS_PARAM_SPEC_GRADIENT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_GRADIENT)) #define GIMP_IS_PARAM_SPEC_GRADIENT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_GRADIENT))
@ -123,8 +125,7 @@ typedef struct _GimpParamSpecGradient GimpParamSpecGradient;
struct _GimpParamSpecGradient struct _GimpParamSpecGradient
{ {
GParamSpecObject parent_instance; GimpParamSpecResource parent_instance;
gboolean none_ok;
}; };
GType gimp_param_gradient_get_type (void) G_GNUC_CONST; GType gimp_param_gradient_get_type (void) G_GNUC_CONST;
@ -141,7 +142,9 @@ GParamSpec * gimp_param_spec_gradient (const gchar *name,
* GIMP_TYPE_PARAM_PALETTE * GIMP_TYPE_PARAM_PALETTE
*/ */
#define GIMP_VALUE_HOLDS_PALETTE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_PALETTE)) #define GIMP_VALUE_HOLDS_PALETTE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), \
GIMP_TYPE_PALETTE))
#define GIMP_TYPE_PARAM_PALETTE (gimp_param_palette_get_type ()) #define GIMP_TYPE_PARAM_PALETTE (gimp_param_palette_get_type ())
#define GIMP_PARAM_SPEC_PALETTE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_PALETTE, GimpParamSpecPalette)) #define GIMP_PARAM_SPEC_PALETTE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_PALETTE, GimpParamSpecPalette))
#define GIMP_IS_PARAM_SPEC_PALETTE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_PALETTE)) #define GIMP_IS_PARAM_SPEC_PALETTE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_PALETTE))
@ -150,8 +153,7 @@ typedef struct _GimpParamSpecPalette GimpParamSpecPalette;
struct _GimpParamSpecPalette struct _GimpParamSpecPalette
{ {
GParamSpecObject parent_instance; GimpParamSpecResource parent_instance;
gboolean none_ok;
}; };
GType gimp_param_palette_get_type (void) G_GNUC_CONST; GType gimp_param_palette_get_type (void) G_GNUC_CONST;
@ -168,7 +170,9 @@ GParamSpec * gimp_param_spec_palette (const gchar *name,
* GIMP_TYPE_PARAM_PATTERN * GIMP_TYPE_PARAM_PATTERN
*/ */
#define GIMP_VALUE_HOLDS_PATTERN(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_PATTERN)) #define GIMP_VALUE_HOLDS_PATTERN(value) (G_TYPE_CHECK_VALUE_TYPE ((value), \
GIMP_TYPE_PATTERN))
#define GIMP_TYPE_PARAM_PATTERN (gimp_param_pattern_get_type ()) #define GIMP_TYPE_PARAM_PATTERN (gimp_param_pattern_get_type ())
#define GIMP_PARAM_SPEC_PATTERN(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_PATTERN, GimpParamSpecPattern)) #define GIMP_PARAM_SPEC_PATTERN(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_PATTERN, GimpParamSpecPattern))
#define GIMP_IS_PARAM_SPEC_PATTERN(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_PATTERN)) #define GIMP_IS_PARAM_SPEC_PATTERN(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_PATTERN))
@ -177,8 +181,7 @@ typedef struct _GimpParamSpecPattern GimpParamSpecPattern;
struct _GimpParamSpecPattern struct _GimpParamSpecPattern
{ {
GParamSpecObject parent_instance; GimpParamSpecResource parent_instance;
gboolean none_ok;
}; };
GType gimp_param_pattern_get_type (void) G_GNUC_CONST; GType gimp_param_pattern_get_type (void) G_GNUC_CONST;
@ -189,17 +192,6 @@ GParamSpec * gimp_param_spec_pattern (const gchar *name,
gboolean none_ok, gboolean none_ok,
GParamFlags flags); GParamFlags flags);
#define GIMP_VALUE_HOLDS_RESOURCE(value) (GIMP_VALUE_HOLDS_BRUSH (value) || \
GIMP_VALUE_HOLDS_FONT (value) || \
GIMP_VALUE_HOLDS_GRADIENT (value) || \
GIMP_VALUE_HOLDS_PALETTE (value) || \
GIMP_VALUE_HOLDS_PATTERN (value) )
G_END_DECLS G_END_DECLS
#endif /* __LIBGIMP_GIMP_PARAM_SPECS_RESOURCE_H__ */ #endif /* __LIBGIMP_GIMP_PARAM_SPECS_RESOURCE_H__ */

View File

@ -31,5 +31,6 @@
/* include the implementation, they are shared between app/ and /* include the implementation, they are shared between app/ and
* libgimp/ but need different headers. * libgimp/ but need different headers.
*/ */
#define LIBGIMP_COMPILATION
#include "gimpparamspecs-body.c" #include "gimpparamspecs-body.c"
#include "gimpparamspecs-body-resource.c" #undef LIBGIMP_COMPILATION

View File

@ -36,6 +36,42 @@
**/ **/
/**
* gimp_pattern_get_by_name:
* @name: The name of the pattern.
*
* Returns the pattern with the given name.
*
* Returns the pattern with the given name.
*
* Returns: (transfer full): The pattern.
*
* Since: 3.0
**/
GimpPattern *
gimp_pattern_get_by_name (const gchar *name)
{
GimpValueArray *args;
GimpValueArray *return_vals;
GimpPattern *pattern = NULL;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_STRING, name,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-pattern-get-by-name",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
pattern = GIMP_VALUES_GET_PATTERN (return_vals, 1);
gimp_value_array_unref (return_vals);
return pattern;
}
/** /**
* gimp_pattern_get_info: * gimp_pattern_get_info:
* @pattern: The pattern. * @pattern: The pattern.
@ -146,39 +182,3 @@ gimp_pattern_get_pixels (GimpPattern *pattern,
return success; return success;
} }
/**
* gimp_pattern_id_is_valid:
* @id: The pattern ID.
*
* Whether the ID is a valid reference to installed data.
*
* Returns TRUE if this ID is valid.
*
* Returns: TRUE if the pattern ID is valid.
*
* Since: 3.0
**/
gboolean
gimp_pattern_id_is_valid (const gchar *id)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean valid = FALSE;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_STRING, id,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-pattern-id-is-valid",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
valid = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
gimp_value_array_unref (return_vals);
return valid;
}

View File

@ -32,16 +32,16 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */ /* For information look into the C source or the html documentation */
gboolean gimp_pattern_get_info (GimpPattern *pattern, GimpPattern* gimp_pattern_get_by_name (const gchar *name);
gint *width, gboolean gimp_pattern_get_info (GimpPattern *pattern,
gint *height, gint *width,
gint *bpp); gint *height,
gboolean gimp_pattern_get_pixels (GimpPattern *pattern, gint *bpp);
gint *width, gboolean gimp_pattern_get_pixels (GimpPattern *pattern,
gint *height, gint *width,
gint *bpp, gint *height,
GBytes **color_bytes); gint *bpp,
gboolean gimp_pattern_id_is_valid (const gchar *id); GBytes **color_bytes);
G_END_DECLS G_END_DECLS

View File

@ -53,6 +53,8 @@ GimpImage * _gimp_plug_in_get_image (GimpPlugIn *plug_in,
gint32 image_id); gint32 image_id);
GimpItem * _gimp_plug_in_get_item (GimpPlugIn *plug_in, GimpItem * _gimp_plug_in_get_item (GimpPlugIn *plug_in,
gint32 item_id); gint32 item_id);
GimpResource * _gimp_plug_in_get_resource (GimpPlugIn *plug_in,
gint32 resource_id);
G_END_DECLS G_END_DECLS

View File

@ -152,6 +152,7 @@ struct _GimpPlugInPrivate
GHashTable *displays; GHashTable *displays;
GHashTable *images; GHashTable *images;
GHashTable *items; GHashTable *items;
GHashTable *resources;
}; };
@ -326,9 +327,10 @@ gimp_plug_in_finalize (GObject *object)
g_clear_pointer (&plug_in->priv->menu_branches, g_list_free); g_clear_pointer (&plug_in->priv->menu_branches, g_list_free);
gimp_plug_in_destroy_proxies (plug_in->priv->displays, TRUE); gimp_plug_in_destroy_proxies (plug_in->priv->displays, TRUE);
gimp_plug_in_destroy_proxies (plug_in->priv->images, TRUE); gimp_plug_in_destroy_proxies (plug_in->priv->images, TRUE);
gimp_plug_in_destroy_proxies (plug_in->priv->items, TRUE); gimp_plug_in_destroy_proxies (plug_in->priv->items, TRUE);
gimp_plug_in_destroy_proxies (plug_in->priv->resources, TRUE);
gimp_plug_in_destroy_hashes (plug_in); gimp_plug_in_destroy_hashes (plug_in);
@ -1439,15 +1441,17 @@ gimp_plug_in_pop_procedure (GimpPlugIn *plug_in,
_gimp_procedure_destroy_proxies (procedure); _gimp_procedure_destroy_proxies (procedure);
gimp_plug_in_destroy_proxies (plug_in->priv->displays, FALSE); gimp_plug_in_destroy_proxies (plug_in->priv->displays, FALSE);
gimp_plug_in_destroy_proxies (plug_in->priv->images, FALSE); gimp_plug_in_destroy_proxies (plug_in->priv->images, FALSE);
gimp_plug_in_destroy_proxies (plug_in->priv->items, FALSE); gimp_plug_in_destroy_proxies (plug_in->priv->items, FALSE);
gimp_plug_in_destroy_proxies (plug_in->priv->resources, FALSE);
if (! plug_in->priv->procedure_stack) if (! plug_in->priv->procedure_stack)
{ {
gimp_plug_in_destroy_proxies (plug_in->priv->displays, TRUE); gimp_plug_in_destroy_proxies (plug_in->priv->displays, TRUE);
gimp_plug_in_destroy_proxies (plug_in->priv->images, TRUE); gimp_plug_in_destroy_proxies (plug_in->priv->images, TRUE);
gimp_plug_in_destroy_proxies (plug_in->priv->items, TRUE); gimp_plug_in_destroy_proxies (plug_in->priv->items, TRUE);
gimp_plug_in_destroy_proxies (plug_in->priv->resources, TRUE);
gimp_plug_in_destroy_hashes (plug_in); gimp_plug_in_destroy_hashes (plug_in);
} }
@ -1583,12 +1587,73 @@ _gimp_plug_in_get_item (GimpPlugIn *plug_in,
return item; return item;
} }
GimpResource *
_gimp_plug_in_get_resource (GimpPlugIn *plug_in,
gint32 resource_id)
{
GimpResource *resource = NULL;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), NULL);
if (G_UNLIKELY (! plug_in->priv->resources))
plug_in->priv->resources =
g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
(GDestroyNotify) g_object_unref);
resource = g_hash_table_lookup (plug_in->priv->resources,
GINT_TO_POINTER (resource_id));
if (! resource)
{
if (gimp_resource_id_is_brush (resource_id))
{
resource = g_object_new (GIMP_TYPE_BRUSH,
"id", resource_id,
NULL);
}
else if (gimp_resource_id_is_pattern (resource_id))
{
resource = g_object_new (GIMP_TYPE_PATTERN,
"id", resource_id,
NULL);
}
else if (gimp_resource_id_is_gradient (resource_id))
{
resource = g_object_new (GIMP_TYPE_GRADIENT,
"id", resource_id,
NULL);
}
else if (gimp_resource_id_is_palette (resource_id))
{
resource = g_object_new (GIMP_TYPE_PALETTE,
"id", resource_id,
NULL);
}
else if (gimp_resource_id_is_font (resource_id))
{
resource = g_object_new (GIMP_TYPE_FONT,
"id", resource_id,
NULL);
}
if (resource)
g_hash_table_insert (plug_in->priv->resources,
GINT_TO_POINTER (resource_id),
g_object_ref (resource) /* add debug ref */);
}
return resource;
}
static void static void
gimp_plug_in_destroy_hashes (GimpPlugIn *plug_in) gimp_plug_in_destroy_hashes (GimpPlugIn *plug_in)
{ {
g_clear_pointer (&plug_in->priv->displays, g_hash_table_unref); g_clear_pointer (&plug_in->priv->displays, g_hash_table_unref);
g_clear_pointer (&plug_in->priv->images, g_hash_table_unref); g_clear_pointer (&plug_in->priv->images, g_hash_table_unref);
g_clear_pointer (&plug_in->priv->items, g_hash_table_unref); g_clear_pointer (&plug_in->priv->items, g_hash_table_unref);
g_clear_pointer (&plug_in->priv->resources, g_hash_table_unref);
} }
static void static void

View File

@ -29,14 +29,16 @@
G_BEGIN_DECLS G_BEGIN_DECLS
GimpDisplay * _gimp_procedure_get_display (GimpProcedure *procedure, GimpDisplay * _gimp_procedure_get_display (GimpProcedure *procedure,
gint32 display_id); gint32 display_id);
GimpImage * _gimp_procedure_get_image (GimpProcedure *procedure, GimpImage * _gimp_procedure_get_image (GimpProcedure *procedure,
gint32 image_id); gint32 image_id);
GimpItem * _gimp_procedure_get_item (GimpProcedure *procedure, GimpItem * _gimp_procedure_get_item (GimpProcedure *procedure,
gint32 item_id); gint32 item_id);
GimpResource * _gimp_procedure_get_resource (GimpProcedure *procedure,
gint32 resource_id);
void _gimp_procedure_destroy_proxies (GimpProcedure *procedure); void _gimp_procedure_destroy_proxies (GimpProcedure *procedure);
G_END_DECLS G_END_DECLS

View File

@ -92,6 +92,7 @@ struct _GimpProcedurePrivate
GHashTable *displays; GHashTable *displays;
GHashTable *images; GHashTable *images;
GHashTable *items; GHashTable *items;
GHashTable *resources;
}; };
@ -2280,12 +2281,46 @@ _gimp_procedure_get_item (GimpProcedure *procedure,
return item; return item;
} }
GimpResource *
_gimp_procedure_get_resource (GimpProcedure *procedure,
gint32 resource_id)
{
GimpResource *resource = NULL;
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), NULL);
g_return_val_if_fail (gimp_resource_id_is_valid (resource_id), NULL);
if (G_UNLIKELY (! procedure->priv->resources))
procedure->priv->resources =
g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
(GDestroyNotify) g_object_unref);
resource = g_hash_table_lookup (procedure->priv->resources,
GINT_TO_POINTER (resource_id));
if (! resource)
{
resource = _gimp_plug_in_get_resource (procedure->priv->plug_in,
resource_id);
if (resource)
g_hash_table_insert (procedure->priv->resources,
GINT_TO_POINTER (resource_id),
g_object_ref (resource));
}
return resource;
}
void void
_gimp_procedure_destroy_proxies (GimpProcedure *procedure) _gimp_procedure_destroy_proxies (GimpProcedure *procedure)
{ {
g_return_if_fail (GIMP_IS_PROCEDURE (procedure)); g_return_if_fail (GIMP_IS_PROCEDURE (procedure));
g_clear_pointer (&procedure->priv->displays, g_hash_table_unref); g_clear_pointer (&procedure->priv->displays, g_hash_table_unref);
g_clear_pointer (&procedure->priv->images, g_hash_table_unref); g_clear_pointer (&procedure->priv->images, g_hash_table_unref);
g_clear_pointer (&procedure->priv->items, g_hash_table_unref); g_clear_pointer (&procedure->priv->items, g_hash_table_unref);
g_clear_pointer (&procedure->priv->resources, g_hash_table_unref);
} }

View File

@ -1,242 +0,0 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gimp.h"
/*
* Subclasses of GimpResource.
*
* id_is_valid and other methods are in pdb/groups/<foo>.pd
*/
/* Each subclass:
* Is Final.
* Inherits GimpResource.
*
* See pdb/groups/<subclass>.pdb for:
* - annotations for a subclass,
* - more methods of a subclass,
*
* In bound languages, notation is Gimp.Brush.get_id()
* C code should use the superclass method, for example:
* gimp_resource_get_id (GIMP_RESOURCE (brush));
*
* For some methods, we need the same function name on the libgimp side and app/core side.
* Until gimp/core has a GimpResource class and GimpBrush derives from it,
* we must define the subclass specific gimp_brush_get_id method on the libgimp side.
*
* Some methods are in libgimp but not in the PDB e.g. is_valid
*
* Methods defined here may call class methods in the PDB.
* E.G. is_valid(self) calls class method id_is_valid(char *id)
*/
/* get_id is defined only for the superclass GimpResource.
* C code using libgimp can use: gimp_resource_get_id (GIMP_RESOURCE (brush))
* Note the macro to cast to the superclass to avoid compiler warnings.
* Bound languages can use for example: brush.get_id()
*/
/* Brush */
struct _GimpBrush
{
GimpResource parent_instance;
};
G_DEFINE_TYPE (GimpBrush, gimp_brush, GIMP_TYPE_RESOURCE);
static void gimp_brush_class_init (GimpBrushClass *klass) {}
static void gimp_brush_init (GimpBrush *self) {}
/**
* gimp_brush_is_valid:
* @self: The brush to check.
*
* Whether the brush has an ID that refers to installed data.
* The data might have been uninstalled after this object was created
* from saved settings.
*
* Returns: TRUE if the brush's ID refers to existing data.
*
* Since: 3.0
*/
gboolean
gimp_brush_is_valid (GimpBrush *self)
{
gchar *id;
/* Call superclass on cast self. */
id = gimp_resource_get_id (GIMP_RESOURCE (self));
/* Call class method in the PDB, which crosses the wire to core. */
return gimp_brush_id_is_valid (id);
}
/* Font */
struct _GimpFont
{
GimpResource parent_instance;
};
G_DEFINE_TYPE (GimpFont, gimp_font, GIMP_TYPE_RESOURCE);
static void gimp_font_class_init (GimpFontClass *klass) {}
static void gimp_font_init (GimpFont *self) {}
/**
* gimp_font_is_valid:
* @self: The font to check.
*
* Whether the font has an ID that refers to installed data.
* The data might have been uninstalled after this object was created
* from saved settings.
*
* Returns: TRUE if the font's ID refers to existing data.
*
* Since: 3.0
*/
gboolean
gimp_font_is_valid (GimpFont *self)
{
gchar *id;
/* Call superclass on cast self. */
id = gimp_resource_get_id (GIMP_RESOURCE (self));
/* Call class method in the PDB, which crosses the wire to core. */
return gimp_font_id_is_valid (id);
}
/* Gradient */
struct _GimpGradient
{
GimpResource parent_instance;
};
G_DEFINE_TYPE (GimpGradient, gimp_gradient, GIMP_TYPE_RESOURCE);
static void gimp_gradient_class_init (GimpGradientClass *klass) {}
static void gimp_gradient_init (GimpGradient *self) {}
/**
* gimp_gradient_is_valid:
* @self: The gradient to check.
*
* Whether the gradient has an ID that refers to installed data.
* The data might have been uninstalled after this object was created
* from saved settings.
*
* Returns: TRUE if the gradient's ID refers to existing data.
*
* Since: 3.0
*/
gboolean
gimp_gradient_is_valid (GimpGradient *self)
{
gchar *id;
/* Call superclass on cast self. */
id = gimp_resource_get_id (GIMP_RESOURCE (self));
/* Call class method in the PDB, which crosses the wire to core. */
return gimp_gradient_id_is_valid (id);
}
/* Palette */
struct _GimpPalette
{
GimpResource parent_instance;
};
G_DEFINE_TYPE (GimpPalette, gimp_palette, GIMP_TYPE_RESOURCE);
static void gimp_palette_class_init (GimpPaletteClass *klass) {}
static void gimp_palette_init (GimpPalette *self) {}
/**
* gimp_palette_is_valid:
* @self: The palette to check.
*
* Whether the palette has an ID that refers to installed data.
* The data might have been uninstalled after this object was created
* from saved settings.
*
* Returns: TRUE if the palette's ID refers to existing data.
*
* Since: 3.0
*/
gboolean
gimp_palette_is_valid (GimpPalette *self)
{
gchar *id;
/* Call superclass on cast self. */
id = gimp_resource_get_id (GIMP_RESOURCE (self));
/* Call class method in the PDB, which crosses the wire to core. */
return gimp_palette_id_is_valid (id);
}
/* Pattern */
struct _GimpPattern
{
GimpResource parent_instance;
};
G_DEFINE_TYPE (GimpPattern, gimp_pattern, GIMP_TYPE_RESOURCE);
static void gimp_pattern_class_init (GimpPatternClass *klass) {}
static void gimp_pattern_init (GimpPattern *self) {}
/**
* gimp_pattern_is_valid:
* @self: The pattern to check.
*
* Whether the pattern has an ID that refers to installed data.
* The data might have been uninstalled after this object was created
* from saved settings.
*
* Returns: TRUE if the pattern's ID refers to existing data.
*
* Since: 3.0
*/
gboolean
gimp_pattern_is_valid (GimpPattern *self)
{
gchar *id;
/* Call superclass on cast self. */
id = gimp_resource_get_id (GIMP_RESOURCE (self));
/* Call class method in the PDB, which crosses the wire to core. */
return gimp_pattern_id_is_valid (id);
}

View File

@ -1,69 +0,0 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_H_INSIDE__) && !defined (GIMP_COMPILATION)
#error "Only <libgimp/gimp.h> can be included directly."
#endif
#ifndef __LIBGIMP_GIMP_RESOURCE_SUBCLASS_H__
#define __LIBGIMP_GIMP_RESOURCE_SUBCLASS_H__
G_BEGIN_DECLS
/*
* Subclasses of GimpResource.
*
* id_is_valid and other methods are in pdb/groups/<foo>.pd
*/
#define GIMP_TYPE_BRUSH (gimp_brush_get_type ())
G_DECLARE_FINAL_TYPE (GimpBrush, gimp_brush, GIMP, BRUSH, GimpResource)
gboolean gimp_brush_is_valid (GimpBrush *self);
#define GIMP_TYPE_FONT (gimp_font_get_type ())
G_DECLARE_FINAL_TYPE (GimpFont, gimp_font, GIMP, FONT, GimpResource)
gboolean gimp_font_is_valid (GimpFont *self);
#define GIMP_TYPE_GRADIENT (gimp_gradient_get_type ())
G_DECLARE_FINAL_TYPE (GimpGradient, gimp_gradient, GIMP, GRADIENT, GimpResource)
gboolean gimp_gradient_is_valid (GimpGradient *self);
#define GIMP_TYPE_PALETTE (gimp_palette_get_type ())
G_DECLARE_FINAL_TYPE (GimpPalette, gimp_palette, GIMP, PALETTE, GimpResource)
gboolean gimp_palette_is_valid (GimpPalette *self);
#define GIMP_TYPE_PATTERN (gimp_pattern_get_type ())
G_DECLARE_FINAL_TYPE (GimpPattern, gimp_pattern, GIMP, PATTERN, GimpResource)
gboolean gimp_pattern_is_valid (GimpPattern *self);
G_END_DECLS
#endif /* __LIBGIMP_GIMP_RESOURCE_SUBCLASS_H__ */

View File

@ -20,8 +20,11 @@
#include "gimp.h" #include "gimp.h"
/* deriveable type not included in gimp.h. */ #include "libgimpbase/gimpwire.h" /* FIXME kill this include */
#include "gimpresource.h"
#include "gimpplugin-private.h"
#include "gimpprocedure-private.h"
/* GimpResource: base class for resources. /* GimpResource: base class for resources.
* *
@ -65,13 +68,12 @@
* a GimpResource on the libgimp side is a proxy. * a GimpResource on the libgimp side is a proxy.
* There is no GimpResource class in core. * There is no GimpResource class in core.
* *
* One use of GimpResource and its subclasses * One use of GimpResource and its subclasses is as a held type of
* is as a held type of GParamSpecObject, used to declare the parameters of a PDB procedure. * GParamSpecObject, used to declare the parameters of a PDB
* A GimpResource is serializable just for the purpose of serializing GimpProcedureConfig, * procedure. A GimpResource just holds the id as a way to identify a
* a "settings" i.e. a set of values for the arguments to a GimpProcedure. * *resource* in calls to PDB procedures that ultimately access the
* A GimpResource just holds the id as a way to identify a *resource* * core instance of the resource.
* in calls to PDB procedures that ultimately access the core instance of the resource. *
* A GimpResource that has been serialized in a GimpConfig refers to a *resource* * A GimpResource that has been serialized in a GimpConfig refers to a *resource*
* that might not still exist in core in the set of loaded resources (files.) * that might not still exist in core in the set of loaded resources (files.)
* *
@ -103,13 +105,12 @@ enum
N_PROPS N_PROPS
}; };
/* Private structure definition. */
typedef struct typedef struct _GimpResourcePrivate
{ {
char *id; gint id;
} GimpResourcePrivate; } GimpResourcePrivate;
static void gimp_resource_finalize (GObject *object);
static void gimp_resource_set_property (GObject *object, static void gimp_resource_set_property (GObject *object,
guint property_id, guint property_id,
@ -120,128 +121,51 @@ static void gimp_resource_get_property (GObject *object,
GValue *value, GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
/* Implementation of the GimpConfigInterface */
static void gimp_resource_config_iface_init (GimpConfigInterface *iface);
static gboolean gimp_resource_serialize (GimpConfig *config, G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GimpResource, gimp_resource, G_TYPE_OBJECT)
GimpConfigWriter *writer,
gpointer data);
static gboolean gimp_resource_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data);
/* The class type is both deriveable (has private) AND implements interface. */
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GimpResource, gimp_resource, G_TYPE_OBJECT,
G_ADD_PRIVATE (GimpResource)
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
gimp_resource_config_iface_init))
#define parent_class gimp_resource_parent_class #define parent_class gimp_resource_parent_class
static GParamSpec *props[N_PROPS] = { NULL, }; static GParamSpec *props[N_PROPS] = { NULL, };
/* Class construction */
static void static void
gimp_resource_class_init (GimpResourceClass *klass) gimp_resource_class_init (GimpResourceClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_debug("gimp_resource_class_init");
object_class->finalize = gimp_resource_finalize;
object_class->set_property = gimp_resource_set_property; object_class->set_property = gimp_resource_set_property;
object_class->get_property = gimp_resource_get_property; object_class->get_property = gimp_resource_get_property;
props[PROP_ID] = props[PROP_ID] =
g_param_spec_string ("id", g_param_spec_int ("id",
"The id", "The id",
"The id for internal use", "The id for internal use",
"unknown", 0, G_MAXINT32, 0,
GIMP_PARAM_READWRITE); GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, N_PROPS, props); g_object_class_install_properties (object_class, N_PROPS, props);
} }
/* Instance construction. */
static void static void
gimp_resource_init (GimpResource *self) gimp_resource_init (GimpResource *resource)
{ {
/* Initialize private data to 0 */
GimpResourcePrivate *priv = gimp_resource_get_instance_private (self);
priv->id = NULL;
g_debug("gimp_resource_init");
} }
/* The next comment annotates the class. */
/**
* GimpResource:
*
* Installable data having serializable ID. Superclass of Font, Brush, etc.
**/
/**
* gimp_resource_get_id:
* @self: The resource.
*
* Returns an internal key to the store of resources in the core app.
* The key can be invalid after a user uninstalls or deletes a resource.
*
* Returns: (transfer none): the resource's ID.
*
* Since: 3.0
**/
gchar *
gimp_resource_get_id (GimpResource *self)
{
GimpResourcePrivate *priv = gimp_resource_get_instance_private (self);
return self ? priv->id : "";
}
/* Two stage dispose/finalize.
* We don't need dispose since no objects to unref. id is a string, not a GObject.
* Some docs say must define both.
*/
static void
gimp_resource_finalize (GObject *self)
{
GimpResourcePrivate *priv = gimp_resource_get_instance_private (GIMP_RESOURCE(self));
g_debug ("gimp_resource_finalize");
/* Free string property. g_clear_pointer is safe if already freed. */
g_clear_pointer (&priv->id, g_free);
/* Chain up. */
G_OBJECT_CLASS (parent_class)->finalize (self);
}
/*
* Override the GObject methods for set/get property.
* i.e. override g_object_set_property.
*/
static void static void
gimp_resource_set_property (GObject *object, gimp_resource_set_property (GObject *object,
guint property_id, guint property_id,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpResource *self = GIMP_RESOURCE (object); GimpResource *resource = GIMP_RESOURCE (object);
GimpResourcePrivate *priv = gimp_resource_get_instance_private (self); GimpResourcePrivate *priv = gimp_resource_get_instance_private (resource);
g_debug ("gimp_resource_set_property");
switch (property_id) switch (property_id)
{ {
case PROP_ID: case PROP_ID:
g_free (priv->id); priv->id = g_value_get_int (value);
priv->id = g_value_dup_string (value);
break; break;
default: default:
@ -256,15 +180,13 @@ gimp_resource_get_property (GObject *object,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpResource *self = GIMP_RESOURCE (object); GimpResource *resource = GIMP_RESOURCE (object);
GimpResourcePrivate *priv = gimp_resource_get_instance_private (self); GimpResourcePrivate *priv = gimp_resource_get_instance_private (resource);
g_debug ("gimp_resource_get_property");
switch (property_id) switch (property_id)
{ {
case PROP_ID: case PROP_ID:
g_value_set_string (value, priv->id); g_value_set_int (value, priv->id);
/* Assert id string was copied into GValue. */
break; break;
default: default:
@ -273,74 +195,251 @@ gimp_resource_get_property (GObject *object,
} }
} }
/**
/* config iface */ * gimp_resource_get_id:
* @resource: The resource.
static void
gimp_resource_config_iface_init (GimpConfigInterface *iface)
{
/* We don't implement the serialize_property methods. */
iface->deserialize = gimp_resource_deserialize;
iface->serialize = gimp_resource_serialize;
}
/* Serialize the whole thing, which is the id.
* *
* Requires the id is not NULL. * Returns: the resource ID.
* When id is NULL, writes nothing and returns FALSE. *
*/ * Since: 3.0
static gboolean **/
gimp_resource_serialize (GimpConfig *config, gint32
GimpConfigWriter *writer, gimp_resource_get_id (GimpResource *resource)
gpointer data) /* Unused. */
{ {
/* Require config is-a GimpResource instance implementing Config iface. */ if (resource)
GimpResource *self = GIMP_RESOURCE (config);
GimpResourcePrivate *priv = gimp_resource_get_instance_private (self);
g_debug ("resource serialize");
if (priv->id != NULL)
{ {
g_debug ("resource serialize: %s", priv->id); GimpResourcePrivate *priv = gimp_resource_get_instance_private (resource);
/* require the caller opened and will close writer.
* Caller wrote the subclass type name "Gimp<Foo>" return priv->id;
*/
gimp_config_writer_string (writer, priv->id);
return TRUE;
} }
else else
{ {
g_debug ("resource serialize failed: NULL id"); return -1;
return FALSE;
} }
} }
/**
static gboolean * gimp_resource_get_by_id:
gimp_resource_deserialize (GimpConfig *config, * @resource_id: The resource id.
GScanner *scanner, *
gint nest_level, * Returns a #GimpResource representing @resource_id. Since #GimpResource is an
gpointer data) * abstract class, the real object type will actually be the proper
* subclass.
*
* Returns: (nullable) (transfer none): a #GimpResource for @resource_id or
* %NULL if @resource_id does not represent a valid resource.
* The object belongs to libgimp and you must not modify
* or unref it.
*
* Since: 3.0
**/
GimpResource *
gimp_resource_get_by_id (gint32 resource_id)
{ {
gchar *id; if (resource_id > 0)
GimpResource *self = GIMP_RESOURCE (config);
GimpResourcePrivate *priv = gimp_resource_get_instance_private (self);
g_debug ("resource deserialize");
if (! gimp_scanner_parse_string (scanner, &id))
{ {
g_scanner_error (scanner, GimpPlugIn *plug_in = gimp_get_plug_in ();
"Fail scan string for resource"); GimpProcedure *procedure = _gimp_plug_in_get_procedure (plug_in);
return FALSE;
} return _gimp_procedure_get_resource (procedure, resource_id);
else
{
g_debug ("resource deserialize: %s", id);
priv->id = id;
} }
return TRUE; return NULL;
} }
GimpResource *
gimp_resource_get_by_name (GType resource_type,
const gchar *resource_name)
{
g_return_val_if_fail (g_type_is_a (resource_type, GIMP_TYPE_RESOURCE), NULL);
if (resource_name == NULL)
return NULL;
if (g_type_is_a (resource_type, GIMP_TYPE_BRUSH))
{
return (GimpResource *) gimp_brush_get_by_name (resource_name);
}
else if (g_type_is_a (resource_type, GIMP_TYPE_PATTERN))
{
return (GimpResource *) gimp_pattern_get_by_name (resource_name);
}
else if (g_type_is_a (resource_type, GIMP_TYPE_GRADIENT))
{
return (GimpResource *) gimp_gradient_get_by_name (resource_name);
}
else if (g_type_is_a (resource_type, GIMP_TYPE_PALETTE))
{
return (GimpResource *) gimp_palette_get_by_name (resource_name);
}
else if (g_type_is_a (resource_type, GIMP_TYPE_FONT))
{
return (GimpResource *) gimp_font_get_by_name (resource_name);
}
g_return_val_if_reached (NULL);
}
/**
* gimp_resource_is_valid:
* @resource: The resource to check.
*
* Returns TRUE if the resource is valid.
*
* This procedure checks if the given resource is valid and refers to an
* existing resource.
*
* Returns: Whether the resource is valid.
*
* Since: 3.0
**/
gboolean
gimp_resource_is_valid (GimpResource *resource)
{
return gimp_resource_id_is_valid (gimp_resource_get_id (resource));
}
/**
* gimp_resource_is_brush:
* @resource: The resource.
*
* Returns whether the resource is a brush.
*
* This procedure returns TRUE if the specified resource is a brush.
*
* Returns: TRUE if the resource is a brush, FALSE otherwise.
*
* Since: 3.0
**/
gboolean
gimp_resource_is_brush (GimpResource *resource)
{
return gimp_resource_id_is_brush (gimp_resource_get_id (resource));
}
/**
* gimp_resource_is_pattern:
* @resource: The resource.
*
* Returns whether the resource is a pattern.
*
* This procedure returns TRUE if the specified resource is a pattern.
*
* Returns: TRUE if the resource is a pattern, FALSE otherwise.
*
* Since: 3.0
**/
gboolean
gimp_resource_is_pattern (GimpResource *resource)
{
return gimp_resource_id_is_pattern (gimp_resource_get_id (resource));
}
/**
* gimp_resource_is_gradient:
* @resource: The resource.
*
* Returns whether the resource is a gradient.
*
* This procedure returns TRUE if the specified resource is a gradient.
*
* Returns: TRUE if the resource is a gradient, FALSE otherwise.
*
* Since: 3.0
**/
gboolean
gimp_resource_is_gradient (GimpResource *resource)
{
return gimp_resource_id_is_gradient (gimp_resource_get_id (resource));
}
/**
* gimp_resource_is_palette:
* @resource: The resource.
*
* Returns whether the resource is a palette.
*
* This procedure returns TRUE if the specified resource is a palette.
*
* Returns: TRUE if the resource is a palette, FALSE otherwise.
*
* Since: 3.0
**/
gboolean
gimp_resource_is_palette (GimpResource *resource)
{
return gimp_resource_id_is_palette (gimp_resource_get_id (resource));
}
/**
* gimp_resource_is_font:
* @resource: The resource.
*
* Returns whether the resource is a font.
*
* This procedure returns TRUE if the specified resource is a font.
*
* Returns: TRUE if the resource is a font, FALSE otherwise.
*
* Since: 3.0
**/
gboolean
gimp_resource_is_font (GimpResource *resource)
{
return gimp_resource_id_is_font (gimp_resource_get_id (resource));
}
struct _GimpBrush
{
GimpResource parent_instance;
};
G_DEFINE_TYPE (GimpBrush, gimp_brush, GIMP_TYPE_RESOURCE);
static void gimp_brush_class_init (GimpBrushClass *klass) {}
static void gimp_brush_init (GimpBrush *self) {}
struct _GimpPattern
{
GimpResource parent_instance;
};
G_DEFINE_TYPE (GimpPattern, gimp_pattern, GIMP_TYPE_RESOURCE);
static void gimp_pattern_class_init (GimpPatternClass *klass) {}
static void gimp_pattern_init (GimpPattern *self) {}
struct _GimpGradient
{
GimpResource parent_instance;
};
G_DEFINE_TYPE (GimpGradient, gimp_gradient, GIMP_TYPE_RESOURCE);
static void gimp_gradient_class_init (GimpGradientClass *klass) {}
static void gimp_gradient_init (GimpGradient *self) {}
struct _GimpPalette
{
GimpResource parent_instance;
};
G_DEFINE_TYPE (GimpPalette, gimp_palette, GIMP_TYPE_RESOURCE);
static void gimp_palette_class_init (GimpPaletteClass *klass) {}
static void gimp_palette_init (GimpPalette *self) {}
struct _GimpFont
{
GimpResource parent_instance;
};
G_DEFINE_TYPE (GimpFont, gimp_font, GIMP_TYPE_RESOURCE);
static void gimp_font_class_init (GimpFontClass *klass) {}
static void gimp_font_init (GimpFont *self) {}

View File

@ -25,10 +25,13 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/* Inherits GObject. Inheritable by e.g. GimpBrush. */ /* For information look into the C source or the html documentation */
#define GIMP_TYPE_RESOURCE (gimp_resource_get_type ()) #define GIMP_TYPE_RESOURCE (gimp_resource_get_type ())
G_DECLARE_DERIVABLE_TYPE (GimpResource, gimp_resource, GIMP, RESOURCE, GObject) G_DECLARE_DERIVABLE_TYPE (GimpResource, gimp_resource, GIMP, RESOURCE, GObject)
struct _GimpResourceClass struct _GimpResourceClass
{ {
GObjectClass parent_class; GObjectClass parent_class;
@ -44,7 +47,34 @@ struct _GimpResourceClass
void (*_gimp_reserved8) (void); void (*_gimp_reserved8) (void);
}; };
gchar * gimp_resource_get_id (GimpResource *self); gint32 gimp_resource_get_id (GimpResource *resource);
GimpResource * gimp_resource_get_by_id (gint32 resource_id);
GimpResource * gimp_resource_get_by_name (GType resource_type,
const gchar *resource_name);
gboolean gimp_resource_is_valid (GimpResource *resource);
gboolean gimp_resource_is_brush (GimpResource *resource);
gboolean gimp_resource_is_pattern (GimpResource *resource);
gboolean gimp_resource_is_gradient (GimpResource *resource);
gboolean gimp_resource_is_palette (GimpResource *resource);
gboolean gimp_resource_is_font (GimpResource *resource);
#define GIMP_TYPE_BRUSH (gimp_brush_get_type ())
G_DECLARE_FINAL_TYPE (GimpBrush, gimp_brush, GIMP, BRUSH, GimpResource)
#define GIMP_TYPE_PATTERN (gimp_pattern_get_type ())
G_DECLARE_FINAL_TYPE (GimpPattern, gimp_pattern, GIMP, PATTERN, GimpResource)
#define GIMP_TYPE_GRADIENT (gimp_gradient_get_type ())
G_DECLARE_FINAL_TYPE (GimpGradient, gimp_gradient, GIMP, GRADIENT, GimpResource)
#define GIMP_TYPE_PALETTE (gimp_palette_get_type ())
G_DECLARE_FINAL_TYPE (GimpPalette, gimp_palette, GIMP, PALETTE, GimpResource)
#define GIMP_TYPE_FONT (gimp_font_get_type ())
G_DECLARE_FINAL_TYPE (GimpFont, gimp_font, GIMP, FONT, GimpResource)
G_END_DECLS G_END_DECLS

294
libgimp/gimpresource_pdb.c Normal file
View File

@ -0,0 +1,294 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
*
* gimpresource_pdb.c
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
/* NOTE: This file is auto-generated by pdbgen.pl */
#include "config.h"
#include "stamp-pdbgen.h"
#include "gimp.h"
/**
* SECTION: gimpresource
* @title: gimpresource
* @short_description: Functions to manipulate resources.
*
* Functions to manipulate resources.
**/
/**
* gimp_resource_id_is_valid:
* @resource_id: The resource ID to check.
*
* Returns TRUE if the resource ID is valid.
*
* This procedure checks if the given resource ID is valid and refers
* to an existing resource.
*
* Returns: Whether the resource ID is valid.
*
* Since: 3.0
**/
gboolean
gimp_resource_id_is_valid (gint resource_id)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean valid = FALSE;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_INT, resource_id,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-resource-id-is-valid",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
valid = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
gimp_value_array_unref (return_vals);
return valid;
}
/**
* gimp_resource_id_is_brush:
* @resource_id: The resource ID.
*
* Returns whether the resource ID is a brush.
*
* This procedure returns TRUE if the specified resource ID is a brush.
*
* Returns: TRUE if the resource ID is a brush, FALSE otherwise.
*
* Since: 3.0
**/
gboolean
gimp_resource_id_is_brush (gint resource_id)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean brush = FALSE;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_INT, resource_id,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-resource-id-is-brush",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
brush = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
gimp_value_array_unref (return_vals);
return brush;
}
/**
* gimp_resource_id_is_pattern:
* @resource_id: The resource ID.
*
* Returns whether the resource ID is a pattern.
*
* This procedure returns TRUE if the specified resource ID is a
* pattern.
*
* Returns: TRUE if the resource ID is a pattern, FALSE otherwise.
*
* Since: 3.0
**/
gboolean
gimp_resource_id_is_pattern (gint resource_id)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean pattern = FALSE;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_INT, resource_id,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-resource-id-is-pattern",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
pattern = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
gimp_value_array_unref (return_vals);
return pattern;
}
/**
* gimp_resource_id_is_gradient:
* @resource_id: The resource ID.
*
* Returns whether the resource ID is a gradient.
*
* This procedure returns TRUE if the specified resource ID is a
* gradient.
*
* Returns: TRUE if the resource ID is a gradient, FALSE otherwise.
*
* Since: 3.0
**/
gboolean
gimp_resource_id_is_gradient (gint resource_id)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean gradient = FALSE;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_INT, resource_id,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-resource-id-is-gradient",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
gradient = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
gimp_value_array_unref (return_vals);
return gradient;
}
/**
* gimp_resource_id_is_palette:
* @resource_id: The resource ID.
*
* Returns whether the resource ID is a palette.
*
* This procedure returns TRUE if the specified resource ID is a
* palette.
*
* Returns: TRUE if the resource ID is a palette, FALSE otherwise.
*
* Since: 3.0
**/
gboolean
gimp_resource_id_is_palette (gint resource_id)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean palette = FALSE;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_INT, resource_id,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-resource-id-is-palette",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
palette = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
gimp_value_array_unref (return_vals);
return palette;
}
/**
* gimp_resource_id_is_font:
* @resource_id: The resource ID.
*
* Returns whether the resource ID is a font.
*
* This procedure returns TRUE if the specified resource ID is a font.
*
* Returns: TRUE if the resource ID is a font, FALSE otherwise.
*
* Since: 3.0
**/
gboolean
gimp_resource_id_is_font (gint resource_id)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean font = FALSE;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_INT, resource_id,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-resource-id-is-font",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
font = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
gimp_value_array_unref (return_vals);
return font;
}
/**
* gimp_resource_get_name:
* @resource: The resource.
*
* Returns the resource's name.
*
* This procedure returns the resource's name.
*
* Returns: (transfer full): The resource's name.
* The returned value must be freed with g_free().
*
* Since: 3.0
**/
gchar *
gimp_resource_get_name (GimpResource *resource)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gchar *name = NULL;
args = gimp_value_array_new_from_types (NULL,
GIMP_TYPE_RESOURCE, resource,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-resource-get-name",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
name = GIMP_VALUES_DUP_STRING (return_vals, 1);
gimp_value_array_unref (return_vals);
return name;
}

View File

@ -0,0 +1,46 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
*
* gimpresource_pdb.h
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
/* NOTE: This file is auto-generated by pdbgen.pl */
#if !defined (__GIMP_H_INSIDE__) && !defined (GIMP_COMPILATION)
#error "Only <libgimp/gimp.h> can be included directly."
#endif
#ifndef __GIMP_RESOURCE_PDB_H__
#define __GIMP_RESOURCE_PDB_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
gboolean gimp_resource_id_is_valid (gint resource_id);
gboolean gimp_resource_id_is_brush (gint resource_id);
gboolean gimp_resource_id_is_pattern (gint resource_id);
gboolean gimp_resource_id_is_gradient (gint resource_id);
gboolean gimp_resource_id_is_palette (gint resource_id);
gboolean gimp_resource_id_is_font (gint resource_id);
gchar* gimp_resource_get_name (GimpResource *resource);
G_END_DECLS
#endif /* __GIMP_RESOURCE_PDB_H__ */

View File

@ -34,9 +34,8 @@
typedef struct typedef struct
{ {
/* This portion is passed to and from idle. */ /* This portion is passed to and from idle. */
/* !!! resource is not long lived, only during a transfer to idle. */
guint idle_id; guint idle_id;
GimpResource *resource; gint resource_id;
GType resource_type; GType resource_type;
gboolean closing; gboolean closing;
@ -132,10 +131,6 @@ static void
create_callback_PDB_procedure_params (GimpProcedure *procedure, create_callback_PDB_procedure_params (GimpProcedure *procedure,
GType resource_type) GType resource_type)
{ {
/* Order of args is important. */
/* Prefix of args is same across resource_type. */
/* !!! core gimp_pdb_dialog is still passing string. */
GIMP_PROC_ARG_STRING (procedure, "resource-name", GIMP_PROC_ARG_STRING (procedure, "resource-name",
"Resource name", "Resource name",
"The resource name", "The resource name",
@ -163,10 +158,10 @@ create_callback_PDB_procedure_params (GimpProcedure *procedure,
else if (g_type_is_a (resource_type, GIMP_TYPE_BRUSH)) else if (g_type_is_a (resource_type, GIMP_TYPE_BRUSH))
{ {
GIMP_PROC_ARG_DOUBLE (procedure, "opacity", GIMP_PROC_ARG_DOUBLE (procedure, "opacity",
"Opacity", "Opacity",
NULL, NULL,
0.0, 100.0, 100.0, 0.0, 100.0, 100.0,
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_INT (procedure, "spacing", GIMP_PROC_ARG_INT (procedure, "spacing",
"Spacing", "Spacing",
@ -236,7 +231,6 @@ create_callback_PDB_procedure_params (GimpProcedure *procedure,
g_warning ("%s: unhandled resource type", G_STRFUNC); g_warning ("%s: unhandled resource type", G_STRFUNC);
} }
/* Suffix of args is same across resource_type. */
GIMP_PROC_ARG_BOOLEAN (procedure, "closing", GIMP_PROC_ARG_BOOLEAN (procedure, "closing",
"Closing", "Closing",
"If the dialog was closing", "If the dialog was closing",
@ -258,10 +252,8 @@ popup_remote_chooser (const gchar *title,
gboolean result = FALSE; gboolean result = FALSE;
gchar *resource_name; gchar *resource_name;
g_debug ("%s", G_STRFUNC); /* The PDB procedure still takes a name */
resource_name = gimp_resource_get_name (resource);
/* The PDB procedure still takes a name aka ID instead of a resource object. */
g_object_get (resource, "id", &resource_name, NULL);
if (g_type_is_a (resource_type, GIMP_TYPE_BRUSH)) if (g_type_is_a (resource_type, GIMP_TYPE_BRUSH))
{ {
@ -287,6 +279,7 @@ popup_remote_chooser (const gchar *title,
{ {
g_warning ("%s: unhandled resource type", G_STRFUNC); g_warning ("%s: unhandled resource type", G_STRFUNC);
} }
return result; return result;
} }
@ -337,7 +330,7 @@ index_of_is_closing_arg (GType resource_type)
} }
else if (g_type_is_a (resource_type, GIMP_TYPE_BRUSH)) else if (g_type_is_a (resource_type, GIMP_TYPE_BRUSH))
{ {
return 8; return 7;
} }
else if (g_type_is_a (resource_type, GIMP_TYPE_PALETTE)) else if (g_type_is_a (resource_type, GIMP_TYPE_PALETTE))
{ {
@ -345,7 +338,7 @@ index_of_is_closing_arg (GType resource_type)
} }
else if (g_type_is_a (resource_type, GIMP_TYPE_PATTERN)) else if (g_type_is_a (resource_type, GIMP_TYPE_PATTERN))
{ {
return 6; return 5;
} }
else else
{ {
@ -375,15 +368,13 @@ index_of_is_closing_arg (GType resource_type)
* string belongs to the resource selection dialog and will be * string belongs to the resource selection dialog and will be
* freed automatically when the dialog is closed. * freed automatically when the dialog is closed.
**/ **/
const gchar * const gchar *
gimp_resource_select_new (const gchar *title, gimp_resource_select_new (const gchar *title,
GimpResource *resource, GimpResource *resource,
GType resource_type, GType resource_type,
GimpResourceChoosedCallback callback, GimpResourceChoosedCallback callback,
gpointer owner_data, gpointer owner_data,
GDestroyNotify data_destroy) GDestroyNotify data_destroy)
{ {
GimpPlugIn *plug_in = gimp_get_plug_in (); GimpPlugIn *plug_in = gimp_get_plug_in ();
GimpProcedure *procedure; GimpProcedure *procedure;
@ -420,7 +411,8 @@ const gchar *
gimp_plug_in_add_temp_procedure (plug_in, procedure); gimp_plug_in_add_temp_procedure (plug_in, procedure);
g_object_unref (procedure); g_object_unref (procedure);
if (popup_remote_chooser (title, resource, temp_PDB_callback_name, resource_type)) if (popup_remote_chooser (title, resource, temp_PDB_callback_name,
resource_type))
{ {
/* Allow callbacks to be watched */ /* Allow callbacks to be watched */
gimp_plug_in_extension_enable (plug_in); gimp_plug_in_extension_enable (plug_in);
@ -441,16 +433,9 @@ gimp_resource_select_destroy (const gchar *temp_PDB_callback_name)
{ {
GimpPlugIn *plug_in = gimp_get_plug_in (); GimpPlugIn *plug_in = gimp_get_plug_in ();
g_debug ("%s", G_STRFUNC);
g_return_if_fail (temp_PDB_callback_name != NULL); g_return_if_fail (temp_PDB_callback_name != NULL);
gimp_plug_in_remove_temp_procedure (plug_in, temp_PDB_callback_name); gimp_plug_in_remove_temp_procedure (plug_in, temp_PDB_callback_name);
/* Assert that removing temp procedure will callback the destroy function
* gimp_resource_data_free.
* The allocated adaption must not be used again.
*/
} }
@ -466,14 +451,12 @@ gimp_resource_select_set (const gchar *temp_pdb_callback,
GimpResource *resource, GimpResource *resource,
GType resource_type) GType resource_type)
{ {
gchar * resource_name; gchar *resource_name;
g_debug ("%s", G_STRFUNC);
/* The remote setter is e.g. gimp_fonts_set_popup, a PDB procedure. /* The remote setter is e.g. gimp_fonts_set_popup, a PDB procedure.
* It still takes a name aka ID instead of a resource object. * It still takes a name aka ID instead of a resource object.
*/ */
g_object_get (resource, "id", &resource_name, NULL); resource_name = gimp_resource_get_name (resource);
if (g_type_is_a (resource_type, GIMP_TYPE_FONT)) if (g_type_is_a (resource_type, GIMP_TYPE_FONT))
{ {
@ -514,21 +497,16 @@ gimp_resource_select_set (const gchar *temp_pdb_callback,
static void static void
gimp_resource_data_free (GimpResourceAdaption *adaption) gimp_resource_data_free (GimpResourceAdaption *adaption)
{ {
g_debug ("%s", G_STRFUNC);
if (adaption->idle_id) if (adaption->idle_id)
g_source_remove (adaption->idle_id); g_source_remove (adaption->idle_id);
/* adaption->resource should be NULL, else we failed to transfer to the owner. */
g_clear_object (&adaption->resource);
if (adaption->temp_PDB_callback_name) if (adaption->temp_PDB_callback_name)
{ {
close_remote_chooser (adaption->temp_PDB_callback_name, adaption->resource_type); close_remote_chooser (adaption->temp_PDB_callback_name,
adaption->resource_type);
g_free (adaption->temp_PDB_callback_name); g_free (adaption->temp_PDB_callback_name);
} }
/* Destroy any inner generic data passed by the owner. */
if (adaption->data_destroy) if (adaption->data_destroy)
adaption->data_destroy (adaption->owner_data); adaption->data_destroy (adaption->owner_data);
@ -541,33 +519,24 @@ gimp_resource_data_free (GimpResourceAdaption *adaption)
static GimpValueArray * static GimpValueArray *
gimp_temp_resource_run (GimpProcedure *procedure, gimp_temp_resource_run (GimpProcedure *procedure,
const GimpValueArray *args, const GimpValueArray *args,
gpointer run_data) /* is-a adaption */ gpointer run_data)
{ {
GimpResourceAdaption *adaption = run_data; GimpResourceAdaption *adaption = run_data;
const gchar *resource_name; const gchar *resource_name;
GimpResource *resource; GimpResource *resource;
g_debug ("%s", G_STRFUNC); resource_name = GIMP_VALUES_GET_STRING (args, 0);
/* Convert name string to object. */ resource = gimp_resource_get_by_name (adaption->resource_type,
resource_name = GIMP_VALUES_GET_STRING(args, 0); resource_name);
resource = g_object_new (adaption->resource_type, "id", resource_name, NULL);
/* Pass the new resource object to the idle func, which will transfer ownership. adaption->resource_id = gimp_resource_get_id (resource);
* and clear adaption->resource.
* Thus assert that adaption->resource is NULL, and this is not a leak.
*/
adaption->resource = resource;
/* !!! Adapting the temp PDB callback signature to simplified libgimp callback.
* I.E. discarding args that are attributes of the resource.
*/
adaption->closing = GIMP_VALUES_GET_BOOLEAN (args, index_of_is_closing_arg (adaption->resource_type)); adaption->closing = GIMP_VALUES_GET_BOOLEAN (args, index_of_is_closing_arg (adaption->resource_type));
/* Set idle_id to remember an idle source exists,
* but idle_id is not used by the idle func.
*/
if (! adaption->idle_id) if (! adaption->idle_id)
adaption->idle_id = g_idle_add ((GSourceFunc) gimp_temp_resource_idle, adaption); adaption->idle_id = g_idle_add ((GSourceFunc) gimp_temp_resource_idle,
adaption);
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL); return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
} }
@ -577,18 +546,12 @@ gimp_temp_resource_idle (GimpResourceAdaption *adaption)
{ {
adaption->idle_id = 0; adaption->idle_id = 0;
g_debug ("%s", G_STRFUNC);
/* We don't expect callback to be NULL, but check anyway.
* This is asynchronous so there could be a race.
*/
if (adaption->callback) if (adaption->callback)
adaption->callback (adaption->resource, adaption->callback (gimp_resource_get_by_id (adaption->resource_id),
adaption->closing, adaption->closing,
adaption->owner_data); adaption->owner_data);
/* Ownership of resource transfers to whom we are calling back. */ adaption->resource_id = 0;
adaption->resource = NULL;
if (adaption->closing) if (adaption->closing)
{ {

View File

@ -32,12 +32,11 @@
#include "libgimp-intl.h" #include "libgimp-intl.h"
/* Annotation for the class, which appears in the GimpUi doc. */
/** /**
* SECTION: gimpresourceselectbutton * SECTION: gimpresourceselectbutton
* @title: GimpResourceSelectButton * @title: GimpResourceSelectButton
* @short_description: Base class for buttons that popup a resource selection dialog. * @short_description: Base class for buttons that popup a resource
* selection dialog.
* *
* A button which pops up a resource selection dialog. * A button which pops up a resource selection dialog.
* *
@ -75,12 +74,6 @@
* Since: 3.0 * Since: 3.0
**/ **/
/* This class was derived from GimpSelectButton and its subclass GimpPatternSelectButton.
* By moving things from the subclass to the super class, generalizing.
* I.E. refactored by inheriting methods that are the same across subclasses.
*/
enum enum
{ {
@ -97,36 +90,17 @@ enum
}; };
/* Private structure definition. */
typedef struct typedef struct
{ {
GimpResource *resource; /* Thing self widget chooses*/ GimpResource *resource;
/* Type of resource is known by the class, not instance. gchar *title;
* e.g. GimpFont, some subclass of GimpResource const gchar *temp_callback_from_remote_dialog;
*/ GtkWidget *interior_widget;
/* Self collaborates with a remote widget, a popup chooser dialog. */
const gchar *title; /* Title of remote widget. */
/* Interface functions to remote dialog.
* Instance knows a temporary PDB procedure which the remote dialog callbacks self.
* This specializes us, and is returned by a call to e.g. gimp_pattern_select_new,
* a libgimp function that talks to remote dialog.
*
* It does not need to be freed, owned by the PDB.
*/
const gchar *temp_callback_from_remote_dialog;
/* Self is-a GtkContainer widget to which subclasses will embed. */
/* Widget interior to self, created and drawn by subclass. */
GtkWidget *interior_widget;
} GimpResourceSelectButtonPrivate; } GimpResourceSelectButtonPrivate;
/* local function prototypes */ /* local function prototypes */
/* Overridden GObject methods. */
static void gimp_resource_select_button_dispose (GObject *object); static void gimp_resource_select_button_dispose (GObject *object);
static void gimp_resource_select_button_finalize (GObject *object); static void gimp_resource_select_button_finalize (GObject *object);
@ -169,19 +143,14 @@ G_DEFINE_TYPE_WITH_PRIVATE (GimpResourceSelectButton, gimp_resource_select_butto
static void static void
gimp_resource_select_button_class_init (GimpResourceSelectButtonClass *klass) gimp_resource_select_button_class_init (GimpResourceSelectButtonClass *klass)
{ {
/* Root super class */
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_debug ("%s", G_STRFUNC);
/* Override to root super class GObject. */
object_class->dispose = gimp_resource_select_button_dispose; object_class->dispose = gimp_resource_select_button_dispose;
object_class->finalize = gimp_resource_select_button_finalize; object_class->finalize = gimp_resource_select_button_finalize;
object_class->set_property = gimp_resource_select_button_set_property; object_class->set_property = gimp_resource_select_button_set_property;
object_class->get_property = gimp_resource_select_button_get_property; object_class->get_property = gimp_resource_select_button_get_property;
/* Signals */ klass->resource_set = NULL;
klass->resource_set = NULL;
/** /**
* GimpResourceSelectButton:title: * GimpResourceSelectButton:title:
@ -190,14 +159,13 @@ gimp_resource_select_button_class_init (GimpResourceSelectButtonClass *klass)
* *
* Since: 2.4 * Since: 2.4
*/ */
/* Default is not localized i18n since caller should provide a value. */ resource_button_props[PROP_TITLE] =
resource_button_props[PROP_TITLE] g_param_spec_string ("title",
= g_param_spec_string ("title", "Title",
"Title", "The title to be used for the resource selection popup dialog",
"The title to be used for the resource selection popup dialog", "Resource Selection",
"Resource Selection", /* default */ GIMP_PARAM_READWRITE |
GIMP_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
G_PARAM_CONSTRUCT_ONLY);
/** /**
* GimpResourceSelectButton:resource: * GimpResourceSelectButton:resource:
@ -206,15 +174,15 @@ gimp_resource_select_button_class_init (GimpResourceSelectButtonClass *klass)
* *
* Since: 2.4 * Since: 2.4
*/ */
/* Has no default. */ resource_button_props[PROP_RESOURCE] =
resource_button_props[PROP_RESOURCE] gimp_param_spec_resource ("resource",
= gimp_param_spec_resource ("resource", /* name */ "Resource",
"Resource", /* nick */ "The currently selected resource",
"The currently selected resource", TRUE, /* none_ok */
TRUE, /* none_ok */ GIMP_PARAM_READWRITE);
GIMP_PARAM_READWRITE);
g_object_class_install_properties (object_class, N_PROPS, resource_button_props); g_object_class_install_properties (object_class,
N_PROPS, resource_button_props);
/** /**
* GimpResourceSelectButton::resource-set: * GimpResourceSelectButton::resource-set:
@ -241,25 +209,34 @@ gimp_resource_select_button_class_init (GimpResourceSelectButtonClass *klass)
static void static void
gimp_resource_select_button_init (GimpResourceSelectButton *self) gimp_resource_select_button_init (GimpResourceSelectButton *self)
{ {
GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self); gtk_orientable_set_orientation (GTK_ORIENTABLE (self),
GTK_ORIENTATION_HORIZONTAL);
g_debug ("%s", G_STRFUNC);
g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self));
gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
/* No need to initialize interior_widget. A subclass will add it, which must have a clickable.*/
/* Remote dialog not exist yet. */
priv->temp_callback_from_remote_dialog = NULL;
} }
static void
gimp_resource_select_button_dispose (GObject *self)
{
gimp_resource_select_button_close_popup (GIMP_RESOURCE_SELECT_BUTTON (self));
G_OBJECT_CLASS (gimp_resource_select_button_parent_class)->dispose (self);
}
static void
gimp_resource_select_button_finalize (GObject *object)
{
GimpResourceSelectButton *self = GIMP_RESOURCE_SELECT_BUTTON (object);
GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self);
g_clear_pointer (&priv->title, g_free);
G_OBJECT_CLASS (gimp_resource_select_button_parent_class)->finalize (object);
}
/** /**
* gimp_resource_select_button_set_drag_target: * gimp_resource_select_button_set_drag_target:
* @self: A #GimpResourceSelectButton * @self: A #GimpResourceSelectButton
* @drag_region_widget: An interior widget to be a droppable region and emit "drag-data-received" signal * @drag_region_widget: An interior widget to be a droppable region
* and emit "drag-data-received" signal
* @drag_target: The drag target to accept * @drag_target: The drag target to accept
* *
* Called by a subclass init to specialize the instance. * Called by a subclass init to specialize the instance.
@ -271,13 +248,10 @@ gimp_resource_select_button_init (GimpResourceSelectButton *self)
* Since: 3.0 * Since: 3.0
**/ **/
void void
gimp_resource_select_button_set_drag_target ( gimp_resource_select_button_set_drag_target (GimpResourceSelectButton *self,
GimpResourceSelectButton *self, GtkWidget *drag_region_widget,
GtkWidget *drag_region_widget, const GtkTargetEntry *drag_target)
const GtkTargetEntry *drag_target)
{ {
g_debug ("%s", G_STRFUNC);
g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self)); g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self));
g_return_if_fail (drag_target != NULL); g_return_if_fail (drag_target != NULL);
g_return_if_fail (drag_region_widget != NULL); g_return_if_fail (drag_region_widget != NULL);
@ -312,8 +286,6 @@ void
gimp_resource_select_button_set_clickable (GimpResourceSelectButton *self, gimp_resource_select_button_set_clickable (GimpResourceSelectButton *self,
GtkWidget *widget) GtkWidget *widget)
{ {
g_debug ("%s", G_STRFUNC);
g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self)); g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self));
g_return_if_fail (widget != NULL); g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (GTK_IS_WIDGET (widget));
@ -343,6 +315,7 @@ gimp_resource_select_button_get_resource (GimpResourceSelectButton *self)
g_return_val_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self), NULL); g_return_val_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self), NULL);
priv = gimp_resource_select_button_get_instance_private (self); priv = gimp_resource_select_button_get_instance_private (self);
return priv->resource; return priv->resource;
} }
@ -367,8 +340,6 @@ gimp_resource_select_button_set_resource (GimpResourceSelectButton *self,
priv = gimp_resource_select_button_get_instance_private (self); priv = gimp_resource_select_button_get_instance_private (self);
g_debug ("%s", G_STRFUNC);
if (priv->temp_callback_from_remote_dialog) if (priv->temp_callback_from_remote_dialog)
{ {
/* A popup chooser dialog is already shown. /* A popup chooser dialog is already shown.
@ -398,7 +369,8 @@ gimp_resource_select_button_set_resource (GimpResourceSelectButton *self,
* Since: 3.0 * Since: 3.0
*/ */
void void
gimp_resource_select_button_embed_interior (GimpResourceSelectButton *self, GtkWidget * interior) gimp_resource_select_button_embed_interior (GimpResourceSelectButton *self,
GtkWidget *interior)
{ {
g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self)); g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self));
g_return_if_fail (GTK_IS_WIDGET (interior)); g_return_if_fail (GTK_IS_WIDGET (interior));
@ -406,7 +378,6 @@ gimp_resource_select_button_embed_interior (GimpResourceSelectButton *self, GtkW
gtk_container_add (GTK_CONTAINER (self), interior); gtk_container_add (GTK_CONTAINER (self), interior);
/* Show self as widget, now it is complete. */
gtk_widget_show_all (GTK_WIDGET (self)); gtk_widget_show_all (GTK_WIDGET (self));
/* We can't draw the interior until self property "resource" is set. */ /* We can't draw the interior until self property "resource" is set. */
@ -421,30 +392,22 @@ gimp_resource_select_button_embed_interior (GimpResourceSelectButton *self, GtkW
* Not public. * Not public.
*/ */
static void static void
gimp_resource_select_button_draw_interior (GimpResourceSelectButton *self, GimpResource *resource) gimp_resource_select_button_draw_interior (GimpResourceSelectButton *self,
GimpResource *resource)
{ {
GimpResourceSelectButtonClass *klass; GimpResourceSelectButtonClass *klass;
g_debug ("%s", G_STRFUNC);
g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self)); g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self));
g_return_if_fail (GIMP_IS_RESOURCE (resource)); g_return_if_fail (GIMP_IS_RESOURCE (resource));
klass = GIMP_RESOURCE_SELECT_BUTTON_GET_CLASS (self); klass = GIMP_RESOURCE_SELECT_BUTTON_GET_CLASS (self);
/* Check subclass has overridden before calling it. */
g_return_if_fail (klass->draw_interior != NULL); g_return_if_fail (klass->draw_interior != NULL);
/* Call the subclass drawing method. */
klass->draw_interior (self);
/* Note that gtk_widget_queue_draw is specific to cairo drawing areas, klass->draw_interior (self);
* and is not a general method of forcing a refresh of a wiget.
* We always call the subclass draw method via its implementation
* of our virtual draw method.
* The subclass may use gtk_widget_queue_draw, but we don't.
*/
} }
/* private functions */ /* private functions */
static void static void
@ -454,15 +417,12 @@ gimp_resource_select_button_set_remote_dialog (GimpResourceSelectButton *self,
GimpResourceSelectButtonPrivate *priv; GimpResourceSelectButtonPrivate *priv;
GimpResourceSelectButtonClass *klass; GimpResourceSelectButtonClass *klass;
g_debug ("%s", G_STRFUNC);
g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self)); g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self));
g_return_if_fail (resource != NULL); g_return_if_fail (resource != NULL);
priv = gimp_resource_select_button_get_instance_private (self); priv = gimp_resource_select_button_get_instance_private (self);
klass = GIMP_RESOURCE_SELECT_BUTTON_GET_CLASS (self); klass = GIMP_RESOURCE_SELECT_BUTTON_GET_CLASS (self);
/* Require virtual method was overridden by subclass. */
g_return_if_fail (klass->resource_type != G_TYPE_INVALID); g_return_if_fail (klass->resource_type != G_TYPE_INVALID);
/* The ultimate remote setter is e.g. gimp_fonts_set_popup, a PDB procedure. /* The ultimate remote setter is e.g. gimp_fonts_set_popup, a PDB procedure.
@ -475,12 +435,6 @@ gimp_resource_select_button_set_remote_dialog (GimpResourceSelectButton *self,
klass->resource_type); klass->resource_type);
} }
/* Setter for property.
* Overrides setter of base class GObject.
* The underlying field may be NULL after init,
* but after that, do not allow it to be set to NULL.
* I.E. invariant is (priv->resource != NULL) after new ()
*/
static void static void
gimp_resource_select_button_set_property (GObject *object, gimp_resource_select_button_set_property (GObject *object,
guint property_id, guint property_id,
@ -490,8 +444,6 @@ gimp_resource_select_button_set_property (GObject *object,
GimpResourceSelectButton *self = GIMP_RESOURCE_SELECT_BUTTON (object); GimpResourceSelectButton *self = GIMP_RESOURCE_SELECT_BUTTON (object);
GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self); GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self);
g_debug ("%s, id: %i", G_STRFUNC, property_id);
switch (property_id) switch (property_id)
{ {
case PROP_TITLE: case PROP_TITLE:
@ -499,18 +451,7 @@ gimp_resource_select_button_set_property (GObject *object,
break; break;
case PROP_RESOURCE: case PROP_RESOURCE:
{ priv->resource = g_value_get_object (gvalue);
/* Do not use the exported method set_resource.
* That is internal and less safe
* because it is agnostic of NULL values passed,
* and does not unref any existing value.
*/
GimpResource *specific_value;
specific_value = g_value_get_object (gvalue);
g_assert (specific_value != NULL);
priv->resource = specific_value;
}
break; break;
default: default:
@ -519,14 +460,13 @@ gimp_resource_select_button_set_property (GObject *object,
} }
} }
static void static void
gimp_resource_select_button_get_property (GObject *object, gimp_resource_select_button_get_property (GObject *object,
guint property_id, guint property_id,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpResourceSelectButton *self = GIMP_RESOURCE_SELECT_BUTTON (object); GimpResourceSelectButton *self = GIMP_RESOURCE_SELECT_BUTTON (object);
GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self); GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self);
switch (property_id) switch (property_id)
@ -562,31 +502,27 @@ gimp_resource_select_button_callback (GimpResource *resource,
GimpResourceSelectButton *self = GIMP_RESOURCE_SELECT_BUTTON (user_data); GimpResourceSelectButton *self = GIMP_RESOURCE_SELECT_BUTTON (user_data);
GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self); GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self);
g_debug ("%s, id: %s", G_STRFUNC, gimp_resource_get_id (resource));
g_object_unref (priv->resource);
priv->resource = resource; priv->resource = resource;
/* Feedback user choice of resource into the look of the widget interior. /* Feedback user choice of resource into the look of the widget interior.
* Call virtual method overridden by subclass. * Call virtual method overridden by subclass.
*/ */
gimp_resource_select_button_draw_interior (self, resource); gimp_resource_select_button_draw_interior (self, priv->resource);
if (dialog_closing) if (dialog_closing)
priv->temp_callback_from_remote_dialog = NULL; priv->temp_callback_from_remote_dialog = NULL;
g_signal_emit (self, resource_button_signals[RESOURCE_SET], 0, resource, dialog_closing); g_signal_emit (self, resource_button_signals[RESOURCE_SET], 0,
g_object_notify_by_pspec (G_OBJECT (self), resource_button_props[PROP_RESOURCE]); resource, dialog_closing);
g_object_notify_by_pspec (G_OBJECT (self),
resource_button_props[PROP_RESOURCE]);
} }
static void static void
gimp_resource_select_button_clicked (GimpResourceSelectButton *self) gimp_resource_select_button_clicked (GimpResourceSelectButton *self)
{ {
GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self); GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self);
GimpResourceSelectButtonClass *klass = GIMP_RESOURCE_SELECT_BUTTON_GET_CLASS (self); GimpResourceSelectButtonClass *klass = GIMP_RESOURCE_SELECT_BUTTON_GET_CLASS (self);
g_debug ("%s called", G_STRFUNC);
if (priv->temp_callback_from_remote_dialog) if (priv->temp_callback_from_remote_dialog)
{ {
@ -595,8 +531,6 @@ gimp_resource_select_button_clicked (GimpResourceSelectButton *self)
} }
else else
{ {
g_debug ("%s calling newer of remote dialog", G_STRFUNC);
/* Call GimpResourceSelect which dispatches on resource_type. */ /* Call GimpResourceSelect which dispatches on resource_type. */
priv->temp_callback_from_remote_dialog = priv->temp_callback_from_remote_dialog =
gimp_resource_select_new (priv->title, gimp_resource_select_new (priv->title,
@ -606,7 +540,6 @@ gimp_resource_select_button_clicked (GimpResourceSelectButton *self)
self, self,
NULL); /* No func to free data. */ NULL); /* No func to free data. */
} }
g_debug ("%s returns", G_STRFUNC);
} }
@ -626,8 +559,6 @@ gimp_resource_select_drag_data_received (GimpResourceSelectButton *self,
GimpResourceSelectButtonClass *klass; GimpResourceSelectButtonClass *klass;
g_debug ("%s called", G_STRFUNC);
klass = GIMP_RESOURCE_SELECT_BUTTON_GET_CLASS (self); klass = GIMP_RESOURCE_SELECT_BUTTON_GET_CLASS (self);
/* Require class resource_type was initialized. */ /* Require class resource_type was initialized. */
g_assert (klass->resource_type != 0); g_assert (klass->resource_type != 0);
@ -655,10 +586,7 @@ gimp_resource_select_drag_data_received (GimpResourceSelectButton *self,
gchar *name = str + name_offset; gchar *name = str + name_offset;
GimpResource *resource; GimpResource *resource;
/* Create just a proxy object, not a new resource in core. resource = gimp_resource_get_by_name (klass->resource_type, name);
* Create an instance of the type (e.g. GimpFont) that this class creates.
*/
resource = g_object_new (klass->resource_type, "id", name, NULL);
gimp_resource_select_button_set_resource (self, resource); gimp_resource_select_button_set_resource (self, resource);
} }
} }
@ -667,23 +595,6 @@ gimp_resource_select_drag_data_received (GimpResourceSelectButton *self,
} }
/* Dispose, finalize, destroy. */
/* When self is disposed, e.g. when user Cancels owning dialog,
* close the remote popup, which will destroy it.
* Dispose is first phase to break possible cycle of the popup referencing self.
*/
static void
gimp_resource_select_button_dispose (GObject *self)
{
g_debug ("%s", G_STRFUNC);
gimp_resource_select_button_close_popup (GIMP_RESOURCE_SELECT_BUTTON (self));
/* Chain up. */
G_OBJECT_CLASS (gimp_resource_select_button_parent_class)->dispose (self);
}
/** /**
* gimp_resource_select_button_close_popup: * gimp_resource_select_button_close_popup:
* @self: A #GimpResourceSelectButton * @self: A #GimpResourceSelectButton
@ -701,8 +612,6 @@ gimp_resource_select_button_close_popup (GimpResourceSelectButton *self)
{ {
GimpResourceSelectButtonPrivate *priv; GimpResourceSelectButtonPrivate *priv;
g_debug ("%s", G_STRFUNC);
g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self)); g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self));
priv = gimp_resource_select_button_get_instance_private (self); priv = gimp_resource_select_button_get_instance_private (self);
@ -714,18 +623,3 @@ gimp_resource_select_button_close_popup (GimpResourceSelectButton *self)
} }
/* Else already closed. */ /* Else already closed. */
} }
static void
gimp_resource_select_button_finalize (GObject *object)
{
GimpResourceSelectButton *self = GIMP_RESOURCE_SELECT_BUTTON (object);
GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self);
g_debug ("%s", G_STRFUNC);
g_clear_pointer (&priv->resource, g_object_unref);
g_free ((gpointer) priv->title);
/* Chain up. */
G_OBJECT_CLASS (gimp_resource_select_button_parent_class)->finalize (object);
}

View File

@ -25,42 +25,27 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/* Inherits GtkBox
* Inheritable by e.g. GimpBrushSelectButton.
*/
#define GIMP_TYPE_RESOURCE_SELECT_BUTTON (gimp_resource_select_button_get_type ()) #define GIMP_TYPE_RESOURCE_SELECT_BUTTON (gimp_resource_select_button_get_type ())
G_DECLARE_DERIVABLE_TYPE (GimpResourceSelectButton, gimp_resource_select_button, GIMP, RESOURCE_SELECT_BUTTON, GtkBox) G_DECLARE_DERIVABLE_TYPE (GimpResourceSelectButton,
gimp_resource_select_button,
GIMP, RESOURCE_SELECT_BUTTON, GtkBox)
struct _GimpResourceSelectButtonClass struct _GimpResourceSelectButtonClass
{ {
GtkBoxClass parent_class; GtkBoxClass parent_class;
/* Signal resource_set. Emitted when user chooses a resource.
* The signal carries only the resource (a proxy having an ID).
* The resource knows its own attributes needed for drawing it.
* Such attributes are NOT in the signal.
*
* Seems to be unused by GIMP internal code,
* instead GimpPropChooser binds to property.
*/
/* FIXME: should be an annotation. */
void (* resource_set) (GimpResourceSelectButton *self, void (* resource_set) (GimpResourceSelectButton *self,
GimpResource *resource, GimpResource *resource,
gboolean dialog_closing); gboolean dialog_closing);
/* virtual methods. */
void (*draw_interior) (GimpResourceSelectButton *self); void (*draw_interior) (GimpResourceSelectButton *self);
/* Specialized by subclass. */ GType resource_type;
GType resource_type; /* e.g. GimpBrush */
/* Padding for future expansion */ /* Padding for future expansion */
gpointer padding[8]; gpointer padding[8];
}; };
/* Abstract, no new(), instead new a subclass. */
/* API from above, e.g. used by GimpPropChooser */
GimpResource *gimp_resource_select_button_get_resource (GimpResourceSelectButton *self); GimpResource *gimp_resource_select_button_get_resource (GimpResourceSelectButton *self);
void gimp_resource_select_button_set_resource (GimpResourceSelectButton *self, void gimp_resource_select_button_set_resource (GimpResourceSelectButton *self,
GimpResource *resource); GimpResource *resource);

View File

@ -104,6 +104,7 @@ pdb_wrappers_sources = [
'gimppatterns_pdb.c', 'gimppatterns_pdb.c',
'gimppatternselect_pdb.c', 'gimppatternselect_pdb.c',
'gimpprogress_pdb.c', 'gimpprogress_pdb.c',
'gimpresource_pdb.c',
'gimpselection_pdb.c', 'gimpselection_pdb.c',
'gimptextlayer_pdb.c', 'gimptextlayer_pdb.c',
'gimptexttool_pdb.c', 'gimptexttool_pdb.c',
@ -157,6 +158,7 @@ pdb_wrappers_headers = [
'gimppatterns_pdb.h', 'gimppatterns_pdb.h',
'gimppatternselect_pdb.h', 'gimppatternselect_pdb.h',
'gimpprogress_pdb.h', 'gimpprogress_pdb.h',
'gimpresource_pdb.h',
'gimpselection_pdb.h', 'gimpselection_pdb.h',
'gimptextlayer_pdb.h', 'gimptextlayer_pdb.h',
'gimptexttool_pdb.h', 'gimptexttool_pdb.h',
@ -188,7 +190,6 @@ libgimp_sources_introspectable = [
'gimpprogress.c', 'gimpprogress.c',
'gimpresource.c', 'gimpresource.c',
'gimpresourceselect.c', 'gimpresourceselect.c',
'gimpresource-subclass.c',
'gimpsaveprocedure.c', 'gimpsaveprocedure.c',
'gimpselection.c', 'gimpselection.c',
'gimptextlayer.c', 'gimptextlayer.c',
@ -243,7 +244,6 @@ libgimp_headers_introspectable = [
'gimpprogress.h', 'gimpprogress.h',
'gimpresource.h', 'gimpresource.h',
'gimpresourceselect.h', 'gimpresourceselect.h',
'gimpresource-subclass.h',
'gimpsaveprocedure.h', 'gimpsaveprocedure.h',
'gimpselection.h', 'gimpselection.h',
'gimptextlayer.h', 'gimptextlayer.h',
@ -413,8 +413,7 @@ libgimp_introspectable_files = [
libgimpconfig_introspectable, libgimpconfig_introspectable,
libgimpmath_introspectable, libgimpmath_introspectable,
libgimpmodule_introspectable, libgimpmodule_introspectable,
'gimpparamspecs-body.c', 'gimpparamspecs-body.c'
'gimpparamspecs-body-resource.c',
] ]
libgimpui_introspectable_files = [ libgimpui_introspectable_files = [

View File

@ -237,6 +237,16 @@ gimp_param_spec_image ("$name",
"$blurb", "$blurb",
$none_ok, $none_ok,
$flags) $flags)
CODE
}
elsif ($pdbtype eq 'resource') {
$none_ok = exists $arg->{none_ok} ? 'TRUE' : 'FALSE';
$pspec = <<CODE;
gimp_param_spec_resource ("$name",
"$nick",
"$blurb",
$none_ok,
$flags)
CODE CODE
} }
elsif ($pdbtype eq 'brush') { elsif ($pdbtype eq 'brush') {

View File

@ -48,6 +48,7 @@
plug_in plug_in
plug_in_compat plug_in_compat
progress progress
resource
selection selection
text_layer text_layer
text_tool text_tool

View File

@ -40,10 +40,37 @@ sub brush_new {
%invoke = ( %invoke = (
code => <<'CODE' code => <<'CODE'
{ {
brush = (GimpBrush*) gimp_data_factory_data_new (gimp->brush_factory, brush = (GimpBrush *) gimp_data_factory_data_new (gimp->brush_factory,
context, name); context, name);
if (!brush) if (! brush)
success = FALSE;
}
CODE
);
}
sub brush_get_by_name {
$blurb = "Returns the brush with the given name.";
$help = "Returns the brush with the given name.";
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'name', type => 'string', non_empty => 1,
desc => 'The name of the brush' }
);
@outargs = (
${brush_arg_spec}
);
%invoke = (
code => <<'CODE'
{
brush = gimp_pdb_get_brush (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
if (! brush)
success = FALSE; success = FALSE;
} }
CODE CODE
@ -71,7 +98,7 @@ sub brush_duplicate {
{ {
brush_copy = (GimpBrush *) brush_copy = (GimpBrush *)
gimp_data_factory_data_duplicate (gimp->brush_factory, GIMP_DATA (brush)); gimp_data_factory_data_duplicate (gimp->brush_factory, GIMP_DATA (brush));
/* Assert the copy has a unique name. */
if (!brush_copy) if (!brush_copy)
success = FALSE; success = FALSE;
} }
@ -79,40 +106,6 @@ CODE
); );
} }
sub brush_id_is_valid {
$blurb = "Whether the ID is a valid reference to installed brush data.";
$help = "Returns TRUE when ID is valid.";
&bootchk_pdb_misc('2022', '3.0');
@inargs = (
{ name => 'id',
type => 'string',
non_empty => 1,
no_validate => 1,
desc => 'The brush ID' }
);
@outargs = (
{ name => 'valid', type => 'boolean',
desc => 'TRUE if the brush ID is valid' }
);
%invoke = (
code => <<'CODE'
{
valid = (gimp_pdb_get_brush (gimp, id, GIMP_PDB_DATA_ACCESS_READ, error) != NULL);
/* When ID is not valid, NULL is returned and error is set.
* Clear error so GIMP not display error dialog.
*/
g_clear_error (error);
}
CODE
);
}
sub brush_is_generated { sub brush_is_generated {
$blurb = "Whether the brush is generated (parametric versus raster)."; $blurb = "Whether the brush is generated (parametric versus raster).";
$help = "Returns TRUE when brush is parametric."; $help = "Returns TRUE when brush is parametric.";
@ -891,9 +884,9 @@ CODE
"gimppdb-utils.h"); "gimppdb-utils.h");
@procs = qw(brush_new @procs = qw(brush_new
brush_get_by_name
brush_duplicate brush_duplicate
brush_is_generated brush_is_generated
brush_id_is_valid
brush_rename brush_rename
brush_delete brush_delete
brush_is_editable brush_is_editable

View File

@ -19,44 +19,38 @@
# The invoke code is compiled on the app side. # The invoke code is compiled on the app side.
# The invoke code must assign to each result var # The invoke code must assign to each result var
sub font_id_is_valid { sub font_get_by_name {
$blurb = "Whether the ID is a valid reference to installed data."; $blurb = "Returns the font with the given name.";
$help = "Returns TRUE if this ID is valid."; $help = "Returns the font with the given name.";
&bootchk_pdb_misc('2022', '3.0'); &mitch_pdb_misc('2023', '3.0');
@inargs = ( @inargs = (
{ name => 'id', { name => 'name', type => 'string', non_empty => 1,
type => 'string', desc => 'The name of the font' }
non_empty => 1,
no_validate => 1,
desc => 'The font ID' }
); );
@outargs = ( @outargs = (
{ name => 'valid', type => 'boolean', { name => 'font', type => 'font', non_empty => 1,
desc => 'TRUE if the font ID is valid' } desc => 'The font' }
); );
%invoke = ( %invoke = (
code => <<'CODE' code => <<'CODE'
{ {
valid = (gimp_pdb_get_font (gimp, id, error) != NULL); font = gimp_pdb_get_font (gimp, name, error);
/* When ID is not valid, NULL is returned and error is set. if (! font)
* Clear error so GIMP not display error dialog. success = FALSE;
*/
g_clear_error (error);
} }
CODE CODE
); );
} }
@headers = qw("core/gimp.h" @headers = qw("core/gimp.h"
"gimppdb-utils.h"); "gimppdb-utils.h");
@procs = qw(font_id_is_valid); @procs = qw(font_get_by_name);
%exports = (app => [@procs], lib => [@procs]); %exports = (app => [@procs], lib => [@procs]);

View File

@ -68,6 +68,33 @@ CODE
); );
} }
sub gradient_get_by_name {
$blurb = "Returns the gradient with the given name.";
$help = "Returns the gradient with the given name.";
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'name', type => 'string', non_empty => 1,
desc => 'The name of the gradient' }
);
@outargs = (
${gradient_arg_spec}
);
%invoke = (
code => <<'CODE'
{
gradient = gimp_pdb_get_gradient (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
if (! gradient)
success = FALSE;
}
CODE
);
}
sub gradient_duplicate { sub gradient_duplicate {
$blurb = 'Duplicates a gradient'; $blurb = 'Duplicates a gradient';
$help = 'Returns a copy having a different, unique ID'; $help = 'Returns a copy having a different, unique ID';
@ -89,47 +116,14 @@ sub gradient_duplicate {
{ {
gradient_copy = (GimpGradient *) gradient_copy = (GimpGradient *)
gimp_data_factory_data_duplicate (gimp->gradient_factory, GIMP_DATA (gradient)); gimp_data_factory_data_duplicate (gimp->gradient_factory, GIMP_DATA (gradient));
/* Assert the copy has a unique name. */
if (!gradient_copy) if (! gradient_copy)
success = FALSE; success = FALSE;
} }
CODE CODE
); );
} }
sub gradient_id_is_valid {
$blurb = "Whether the ID is a valid reference to installed data.";
$help = "Returns TRUE if this ID is valid.";
&bootchk_pdb_misc('2022', '3.0');
@inargs = (
{ name => 'id',
type => 'string',
non_empty => 1,
no_validate => 1,
desc => 'The gradient ID' }
);
@outargs = (
{ name => 'valid', type => 'boolean',
desc => 'TRUE if the gradient ID is valid' }
);
%invoke = (
code => <<'CODE'
{
valid = (gimp_pdb_get_gradient (gimp, id, GIMP_PDB_DATA_ACCESS_READ, error) != NULL);
/* When ID is not valid, NULL is returned and error is set.
* Clear error so GIMP not display error dialog.
*/
g_clear_error (error);
}
CODE
);
}
sub gradient_is_editable { sub gradient_is_editable {
$blurb = 'Tests if gradient can be edited'; $blurb = 'Tests if gradient can be edited';
$help = 'Returns TRUE if you have permission to change the gradient'; $help = 'Returns TRUE if you have permission to change the gradient';
@ -155,18 +149,8 @@ CODE
} }
sub gradient_rename { sub gradient_rename {
$blurb = "Renames a gradient. When the name is in use, renames to a unique name."; $blurb = "Renames a gradient. When the name is in use, renames to a unique name.";
$help = <<'HELP'; $help = 'Renames a gradient.';
Renames a gradient. The name is the same as the ID.
When the proposed name is already used, GIMP generates a unique name,
which get_id() will return.
Returns a reference to a renamed gradient, which you should assign
to the original var or a differently named var.
Any existing references will be invalid.
Resources in plugins are proxies holding an ID,
which can be invalid when the resource is renamed.
HELP
&shlomi_pdb_misc('2003', '2.2'); &shlomi_pdb_misc('2003', '2.2');
@ -185,16 +169,9 @@ HELP
%invoke = ( %invoke = (
code => <<'CODE' code => <<'CODE'
{ {
/* Rename the gradient in app. */
gimp_object_set_name (GIMP_OBJECT (gradient), new_name); gimp_object_set_name (GIMP_OBJECT (gradient), new_name);
/* Assert GIMP might have set a name different from new_name. */
/* Return a reference. gradient_renamed = gradient;
* The wire protocol will create a new proxy on the plugin side.
* We don't need an alias here, except to make clear
* that we are returning the same real object as passed.
*/
gradient_renamed = gradient;
} }
CODE CODE
); );
@ -1389,6 +1366,7 @@ CODE
"gimppdb-utils.h"); "gimppdb-utils.h");
@procs = qw(gradient_new @procs = qw(gradient_new
gradient_get_by_name
gradient_duplicate gradient_duplicate
gradient_is_editable gradient_is_editable
gradient_rename gradient_rename
@ -1396,7 +1374,6 @@ CODE
gradient_get_number_of_segments gradient_get_number_of_segments
gradient_get_uniform_samples gradient_get_uniform_samples
gradient_get_custom_samples gradient_get_custom_samples
gradient_id_is_valid
gradient_segment_get_left_color gradient_segment_set_left_color gradient_segment_get_left_color gradient_segment_set_left_color
gradient_segment_get_right_color gradient_segment_set_right_color gradient_segment_get_right_color gradient_segment_set_right_color
gradient_segment_get_left_pos gradient_segment_set_left_pos gradient_segment_get_left_pos gradient_segment_set_left_pos

View File

@ -54,6 +54,34 @@ CODE
); );
} }
sub palette_get_by_name {
$blurb = "Returns the palette with the given name.";
$help = "Returns the palette with the given name.";
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'name', type => 'string', non_empty => 1,
desc => 'The name of the palette' }
);
@outargs = (
{ name => 'palette', type => 'palette', non_empty => 1,
desc => 'The palette' }
);
%invoke = (
code => <<'CODE'
{
palette = gimp_pdb_get_palette (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
if (! palette)
success = FALSE;
}
CODE
);
}
sub palette_is_editable { sub palette_is_editable {
$blurb = "Whether the palette can be edited"; $blurb = "Whether the palette can be edited";
$help = "Returns TRUE if you have permission to change the palette"; $help = "Returns TRUE if you have permission to change the palette";
@ -107,39 +135,6 @@ CODE
); );
} }
sub palette_id_is_valid {
$blurb = "Whether the ID is a valid reference to installed data.";
$help = "Returns TRUE if this ID is valid.";
&bootchk_pdb_misc('2022', '3.0');
@inargs = (
{ name => 'id',
type => 'string',
non_empty => 1,
no_validate => 1,
desc => 'The palette ID' }
);
@outargs = (
{ name => 'valid', type => 'boolean',
desc => 'TRUE if the palette ID is valid' }
);
%invoke = (
code => <<'CODE'
{
valid = (gimp_pdb_get_palette (gimp, id, GIMP_PDB_DATA_ACCESS_READ, error) != NULL);
/* When ID is not valid, NULL is returned and error is set.
* Clear error so GIMP not display error dialog.
*/
g_clear_error (error);
}
CODE
);
}
sub palette_rename { sub palette_rename {
$blurb = "Rename a palette"; $blurb = "Rename a palette";
$help = <<'HELP'; $help = <<'HELP';
@ -555,8 +550,8 @@ CODE
"gimppdb-utils.h"); "gimppdb-utils.h");
@procs = qw(palette_new @procs = qw(palette_new
palette_get_by_name
palette_duplicate palette_duplicate
palette_id_is_valid
palette_rename palette_rename
palette_delete palette_delete
palette_is_editable palette_is_editable

View File

@ -24,6 +24,34 @@ $pattern_arg_spec = { name => 'pattern', type => 'pattern', non_empty => 1,
desc => 'The pattern' }; desc => 'The pattern' };
sub pattern_get_by_name {
$blurb = "Returns the pattern with the given name.";
$help = "Returns the pattern with the given name.";
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'name', type => 'string', non_empty => 1,
desc => 'The name of the pattern' }
);
@outargs = (
{ name => 'pattern', type => 'pattern', non_empty => 1,
desc => 'The pattern' }
);
%invoke = (
code => <<'CODE'
{
pattern = gimp_pdb_get_pattern (gimp, name, error);
if (! pattern)
success = FALSE;
}
CODE
);
}
sub pattern_get_info { sub pattern_get_info {
$blurb = 'Gets information about the pattern.'; $blurb = 'Gets information about the pattern.';
@ -113,40 +141,6 @@ CODE
); );
} }
sub pattern_id_is_valid {
$blurb = "Whether the ID is a valid reference to installed data.";
$help = "Returns TRUE if this ID is valid.";
&bootchk_pdb_misc('2022', '3.0');
@inargs = (
{ name => 'id',
type => 'string',
non_empty => 1,
no_validate => 1,
desc => 'The pattern ID' }
);
@outargs = (
{ name => 'valid', type => 'boolean',
desc => 'TRUE if the pattern ID is valid' }
);
%invoke = (
code => <<'CODE'
{
/* !!! pattern has one fewer args than other resources. */
valid = (gimp_pdb_get_pattern (gimp, id, error) != NULL);
/* When ID is not valid, NULL is returned and error is set.
* Clear error so GIMP not display error dialog.
*/
g_clear_error (error);
}
CODE
);
}
@headers = qw(<string.h> @headers = qw(<string.h>
"gegl/gimp-babl-compat.h" "gegl/gimp-babl-compat.h"
@ -156,9 +150,9 @@ CODE
"core/gimptempbuf.h" "core/gimptempbuf.h"
"gimppdb-utils.h"); "gimppdb-utils.h");
@procs = qw(pattern_get_info @procs = qw(pattern_get_by_name
pattern_get_pixels pattern_get_info
pattern_id_is_valid); pattern_get_pixels);
%exports = (app => [@procs], lib => [@procs]); %exports = (app => [@procs], lib => [@procs]);

251
pdb/groups/resource.pdb Normal file
View File

@ -0,0 +1,251 @@
# GIMP - The GNU Image Manipulation Program
# Copyright (C) 1995 Spencer Kimball and Peter Mattis
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
sub resource_id_is_valid {
$blurb = 'Returns TRUE if the resource ID is valid.';
$help = <<'HELP';
This procedure checks if the given resource ID is valid and refers to an
existing resource.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource_id', type => 'int32',
desc => 'The resource ID to check' }
);
@outargs = (
{ name => 'valid', type => 'boolean',
desc => 'Whether the resource ID is valid' }
);
%invoke = (
code => <<'CODE'
{
GimpData *data = gimp_data_get_by_id (resource_id);
valid = GIMP_IS_DATA (data);
}
CODE
);
}
sub resource_id_is_brush {
$blurb = 'Returns whether the resource ID is a brush.';
$help = <<HELP;
This procedure returns TRUE if the specified resource ID is a brush.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource_id', type => 'int32',
desc => 'The resource ID' }
);
@outargs = (
{ name => 'brush', type => 'boolean',
desc => 'TRUE if the resource ID is a brush, FALSE otherwise' }
);
%invoke = (
code => <<'CODE'
{
GimpData *data = gimp_data_get_by_id (resource_id);
brush = GIMP_IS_BRUSH (data);
}
CODE
);
}
sub resource_id_is_pattern {
$blurb = 'Returns whether the resource ID is a pattern.';
$help = <<HELP;
This procedure returns TRUE if the specified resource ID is a pattern.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource_id', type => 'int32',
desc => 'The resource ID' }
);
@outargs = (
{ name => 'pattern', type => 'boolean',
desc => 'TRUE if the resource ID is a pattern, FALSE otherwise' }
);
%invoke = (
code => <<'CODE'
{
GimpData *data = gimp_data_get_by_id (resource_id);
pattern = GIMP_IS_PATTERN (data);
}
CODE
);
}
sub resource_id_is_gradient {
$blurb = 'Returns whether the resource ID is a gradient.';
$help = <<HELP;
This procedure returns TRUE if the specified resource ID is a gradient.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource_id', type => 'int32',
desc => 'The resource ID' }
);
@outargs = (
{ name => 'gradient', type => 'boolean',
desc => 'TRUE if the resource ID is a gradient, FALSE otherwise' }
);
%invoke = (
code => <<'CODE'
{
GimpData *data = gimp_data_get_by_id (resource_id);
gradient = GIMP_IS_GRADIENT (data);
}
CODE
);
}
sub resource_id_is_palette {
$blurb = 'Returns whether the resource ID is a palette.';
$help = <<HELP;
This procedure returns TRUE if the specified resource ID is a palette.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource_id', type => 'int32',
desc => 'The resource ID' }
);
@outargs = (
{ name => 'palette', type => 'boolean',
desc => 'TRUE if the resource ID is a palette, FALSE otherwise' }
);
%invoke = (
code => <<'CODE'
{
GimpData *data = gimp_data_get_by_id (resource_id);
palette = GIMP_IS_PALETTE (data);
}
CODE
);
}
sub resource_id_is_font {
$blurb = 'Returns whether the resource ID is a font.';
$help = <<HELP;
This procedure returns TRUE if the specified resource ID is a font.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource_id', type => 'int32',
desc => 'The resource ID' }
);
@outargs = (
{ name => 'font', type => 'boolean',
desc => 'TRUE if the resource ID is a font, FALSE otherwise' }
);
%invoke = (
code => <<'CODE'
{
GimpData *data = gimp_data_get_by_id (resource_id);
font = GIMP_IS_FONT (data);
}
CODE
);
}
sub resource_get_name {
$blurb = "Returns the resource's name.";
$help = <<HELP;
This procedure returns the resource's name.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource', type => 'resource',
desc => 'The resource' }
);
@outargs = (
{ name => 'name', type => 'string',
desc => "The resource's name" }
);
%invoke = (
code => <<'CODE'
{
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (resource)));
}
CODE
);
}
@headers = qw("core/gimpbrush.h"
"core/gimpgradient.h"
"core/gimppalette.h"
"core/gimppattern.h"
"text/gimpfont.h"
"gimp-intl.h");
@procs = qw(resource_id_is_valid
resource_id_is_brush
resource_id_is_pattern
resource_id_is_gradient
resource_id_is_palette
resource_id_is_font
resource_get_name);
%exports = (app => [@procs], lib => [@procs]);
$desc = 'Resource procedures';
$doc_title = 'gimpresource';
$doc_short_desc = 'Functions to manipulate resources.';
$doc_long_desc = 'Functions to manipulate resources.';
1;

View File

@ -50,6 +50,7 @@ pdb_names = [
'plug_in_compat', 'plug_in_compat',
'plug_in', 'plug_in',
'progress', 'progress',
'resource',
'selection', 'selection',
'text_layer', 'text_layer',
'text_tool', 'text_tool',

View File

@ -414,7 +414,18 @@ package Gimp::CodeGen::pdb;
set_value_func => 'g_value_set_int ($value, $var)', set_value_func => 'g_value_set_int ($value, $var)',
take_value_func => 'g_value_set_int ($value, $var)' }, take_value_func => 'g_value_set_int ($value, $var)' },
# resources resource => { name => 'RESOURCE',
gtype => 'GIMP_TYPE_RESOURCE',
type => 'GimpResource *',
const_type => 'GimpResource *',
init_value => 'NULL',
out_annotate => '(transfer full)',
get_value_func => '$var = g_value_get_object ($value)',
dup_value_func => '$var = GIMP_VALUES_GET_RESOURCE ($value)',
set_value_func => 'g_value_set_object ($value, $var)',
take_value_func => 'g_value_set_object ($value, $var)',
headers => [ qw("core/gimpresource.h") ] },
brush => { name => 'BRUSH', brush => { name => 'BRUSH',
gtype => 'GIMP_TYPE_BRUSH', gtype => 'GIMP_TYPE_BRUSH',
type => 'GimpBrush *', type => 'GimpBrush *',
@ -427,18 +438,18 @@ package Gimp::CodeGen::pdb;
take_value_func => 'g_value_set_object ($value, $var)', take_value_func => 'g_value_set_object ($value, $var)',
headers => [ qw("core/gimpbrush.h") ] }, headers => [ qw("core/gimpbrush.h") ] },
# !!! include file /app/text/gimpfont.h
font => { name => 'FONT', pattern => { name => 'PATTERN',
gtype => 'GIMP_TYPE_FONT', gtype => 'GIMP_TYPE_PATTERN',
type => 'GimpFont *', type => 'GimpPattern *',
const_type => 'GimpFont *', const_type => 'GimpPattern *',
init_value => 'NULL', init_value => 'NULL',
out_annotate => '(transfer full)', out_annotate => '(transfer full)',
get_value_func => '$var = g_value_get_object ($value)', get_value_func => '$var = g_value_get_object ($value)',
dup_value_func => '$var = GIMP_VALUES_GET_FONT ($value)', dup_value_func => '$var = GIMP_VALUES_GET_PATTERN ($value)',
set_value_func => 'g_value_set_object ($value, $var)', set_value_func => 'g_value_set_object ($value, $var)',
take_value_func => 'g_value_set_object ($value, $var)', take_value_func => 'g_value_set_object ($value, $var)',
headers => [ qw("text/gimpfont.h") ] }, headers => [ qw("core/gimppattern.h") ] },
gradient => { name => 'GRADIENT', gradient => { name => 'GRADIENT',
gtype => 'GIMP_TYPE_GRADIENT', gtype => 'GIMP_TYPE_GRADIENT',
@ -464,17 +475,17 @@ package Gimp::CodeGen::pdb;
take_value_func => 'g_value_set_object ($value, $var)', take_value_func => 'g_value_set_object ($value, $var)',
headers => [ qw("core/gimppalette.h") ] }, headers => [ qw("core/gimppalette.h") ] },
pattern => { name => 'PATTERN', font => { name => 'FONT',
gtype => 'GIMP_TYPE_PATTERN', gtype => 'GIMP_TYPE_FONT',
type => 'GimpPattern *', type => 'GimpFont *',
const_type => 'GimpPattern *', const_type => 'GimpFont *',
init_value => 'NULL', init_value => 'NULL',
out_annotate => '(transfer full)', out_annotate => '(transfer full)',
get_value_func => '$var = g_value_get_object ($value)', get_value_func => '$var = g_value_get_object ($value)',
dup_value_func => '$var = GIMP_VALUES_GET_PATTERN ($value)', dup_value_func => '$var = GIMP_VALUES_GET_FONT ($value)',
set_value_func => 'g_value_set_object ($value, $var)', set_value_func => 'g_value_set_object ($value, $var)',
take_value_func => 'g_value_set_object ($value, $var)', take_value_func => 'g_value_set_object ($value, $var)',
headers => [ qw("core/gimppattern.h") ] } headers => [ qw("text/gimpfont.h") ] }
); );
# Split out the parts of an arg constraint # Split out the parts of an arg constraint

View File

@ -744,8 +744,7 @@ draw_number (GimpLayer *layer,
GimpFont *font = filmvals.number_font; GimpFont *font = filmvals.number_font;
gchar *fontname; gchar *fontname;
/* FIXME: gimp_text methods should take GimpFont font instead of font_name */ fontname = gimp_resource_get_name (GIMP_RESOURCE (font));
g_object_get (font, "id", &fontname, NULL);
g_snprintf (buf, sizeof (buf), "%d", num); g_snprintf (buf, sizeof (buf), "%d", num);
@ -1428,7 +1427,7 @@ film_load_settings (void)
* Restore pointer from the name which was also serialized. * Restore pointer from the name which was also serialized.
* A hack that goes away when GimpProcedureConfig is used. * A hack that goes away when GimpProcedureConfig is used.
*/ */
filmvals.number_font = g_object_new (GIMP_TYPE_FONT, "id", filmvals.font_name, NULL); filmvals.number_font = gimp_font_get_by_name (filmvals.font_name);
} }
static void static void
@ -1436,7 +1435,7 @@ film_save_settings (void)
{ {
/* Copy font name from font, i.e. serialize string not pointer. */ /* Copy font name from font, i.e. serialize string not pointer. */
g_strlcpy (filmvals.font_name, g_strlcpy (filmvals.font_name,
gimp_resource_get_id (GIMP_RESOURCE (filmvals.number_font)), gimp_resource_get_name (GIMP_RESOURCE (filmvals.number_font)),
FONT_LEN); FONT_LEN);
gimp_set_data (PLUG_IN_PROC, &filmvals, sizeof (FilmVals)); gimp_set_data (PLUG_IN_PROC, &filmvals, sizeof (FilmVals));

View File

@ -82,28 +82,20 @@ gfig_read_resource (gchar **text,
ptr++; ptr++;
if (!strcmp (tmpstr, tag)) if (!strcmp (tmpstr, tag))
{ {
/* Create a resource object, just a proxy for the thing in core. */ const gchar *resource_name = g_strchug (ptr);
GimpResource *resource;
gchar *resource_id = g_strdup (g_strchug (ptr));
resource = g_object_new (resource_type, "id", resource_id, NULL);
/* We own the resource object, its refcount is one.
* The resource object owns its string ID.
*/
*style_entry = resource;
/* We are not checking the ID is valid.
* The user might have uninstalled the resource.
*/
*style_entry = gimp_resource_get_by_name (resource_type,
resource_name);
g_free (tmpstr); g_free (tmpstr);
return; return;
} }
g_free (tmpstr); g_free (tmpstr);
} }
++n; ++n;
} }
/* Fail */
*style_entry = NULL; *style_entry = NULL;
g_message ("Parameter '%s' not found", tag); g_message ("Parameter '%s' not found", tag);
} }
@ -374,11 +366,11 @@ gfig_save_style (Style *style,
if (gfig_context->debug_styles) if (gfig_context->debug_styles)
g_printerr ("Saving style %s, brush name '%s'\n", style->name, g_printerr ("Saving style %s, brush name '%s'\n", style->name,
gimp_resource_get_id (GIMP_RESOURCE (style->brush))); gimp_resource_get_name (GIMP_RESOURCE (style->brush)));
g_string_append_printf (string, "<Style %s>\n", style->name); g_string_append_printf (string, "<Style %s>\n", style->name);
g_string_append_printf (string, "BrushName: %s\n", g_string_append_printf (string, "BrushName: %s\n",
gimp_resource_get_id (GIMP_RESOURCE (style->brush))); gimp_resource_get_name (GIMP_RESOURCE (style->brush)));
if (!style->brush) if (!style->brush)
g_message ("Error saving style %s: saving NULL for brush name", style->name); g_message ("Error saving style %s: saving NULL for brush name", style->name);
@ -390,9 +382,9 @@ gfig_save_style (Style *style,
g_ascii_dtostr (buffer, blen, style->fill_opacity)); g_ascii_dtostr (buffer, blen, style->fill_opacity));
g_string_append_printf (string, "Pattern: %s\n", g_string_append_printf (string, "Pattern: %s\n",
gimp_resource_get_id (GIMP_RESOURCE (style->pattern))); gimp_resource_get_name (GIMP_RESOURCE (style->pattern)));
g_string_append_printf (string, "Gradient: %s\n", g_string_append_printf (string, "Gradient: %s\n",
gimp_resource_get_id (GIMP_RESOURCE (style->gradient))); gimp_resource_get_name (GIMP_RESOURCE (style->gradient)));
g_string_append_printf (string, "Foreground: %s %s %s %s\n", g_string_append_printf (string, "Foreground: %s %s %s %s\n",
g_ascii_dtostr (buffer_r, blen, style->foreground.r), g_ascii_dtostr (buffer_r, blen, style->foreground.r),
@ -425,7 +417,7 @@ gfig_style_save_as_attributes (Style *style,
/* Tags must match the ones written, see below in the code. */ /* Tags must match the ones written, see below in the code. */
g_string_append_printf (string, "BrushName=\"%s\" ", g_string_append_printf (string, "BrushName=\"%s\" ",
gimp_resource_get_id (GIMP_RESOURCE (style->brush))); gimp_resource_get_name (GIMP_RESOURCE (style->brush)));
/* Why only brush and not pattern and gradient? */ /* Why only brush and not pattern and gradient? */
g_string_append_printf (string, "Foreground=\"%s %s %s %s\" ", g_string_append_printf (string, "Foreground=\"%s %s %s %s\" ",
@ -627,7 +619,7 @@ gfig_style_apply (Style *style)
if (! gimp_context_set_brush (style->brush)) if (! gimp_context_set_brush (style->brush))
g_message ("Style apply: Failed to set brush to '%s' in style '%s'", g_message ("Style apply: Failed to set brush to '%s' in style '%s'",
gimp_resource_get_id (GIMP_RESOURCE (style->brush)), gimp_resource_get_name (GIMP_RESOURCE (style->brush)),
style->name); style->name);
gimp_context_set_brush_default_size (); gimp_context_set_brush_default_size ();

View File

@ -5057,15 +5057,13 @@ gradient_get_values_real_external (const gchar *gradient_name,
gint nvalues, gint nvalues,
gboolean reverse) gboolean reverse)
{ {
gint n_tmp_values;
gdouble *tmp_values;
gint i;
gint j;
GimpGradient *gradient; GimpGradient *gradient;
gint n_tmp_values;
gdouble *tmp_values;
gint i;
gint j;
/* New proxy for gradient. */ gradient = gimp_gradient_get_by_name (gradient_name);
gradient = g_object_new (GIMP_TYPE_GRADIENT, "id", gradient_name, NULL);
gimp_gradient_get_uniform_samples (gradient, nvalues, reverse, gimp_gradient_get_uniform_samples (gradient, nvalues, reverse,
&n_tmp_values, &tmp_values); &n_tmp_values, &tmp_values);

View File

@ -188,8 +188,8 @@ marshal_returned_object_array_to_vector (scheme *sc,
*/ */
for (int j = n - 1; j >= 0; j--) for (int j = n - 1; j >= 0; j--)
{ {
gint id;
GObject *object = object_array[j]; GObject *object = object_array[j];
gint id;
if (object) if (object)
g_object_get (object, "id", &id, NULL); /* get property "id" */ g_object_get (object, "id", &id, NULL); /* get property "id" */

View File

@ -1256,23 +1256,17 @@ script_fu_marshal_procedure_call (scheme *sc,
} }
else if (GIMP_VALUE_HOLDS_RESOURCE (&value)) else if (GIMP_VALUE_HOLDS_RESOURCE (&value))
{ {
GType type = G_VALUE_TYPE (&value);
if (! sc->vptr->is_string (sc->vptr->pair_car (a))) if (! sc->vptr->is_string (sc->vptr->pair_car (a)))
return script_type_error (sc, "string", i, proc_name); return script_type_error (sc, "string", i, proc_name);
else else
{ {
/* Create new instance of a resource object. */ /* Create new instance of a resource object. */
GimpResource *resource; GimpResource *resource;
gchar* id = sc->vptr->string_value (sc->vptr->pair_car (a)); GType type = G_VALUE_TYPE (&value);
const gchar *name = sc->vptr->string_value (sc->vptr->pair_car (a));
resource = g_object_new (type, NULL); resource = gimp_resource_get_by_name (type, name);
g_object_set (resource, "id", id, NULL);
/* Assert set property copies the string. */
g_value_set_object (&value, resource); g_value_set_object (&value, resource);
/* Assert set_object refs the resource. */
} }
} }
else else
@ -1397,26 +1391,18 @@ script_fu_marshal_procedure_call (scheme *sc,
{ {
/* ScriptFu represents resource objects by ther unique string ID's. */ /* ScriptFu represents resource objects by ther unique string ID's. */
GObject *object = g_value_get_object (value); GObject *object = g_value_get_object (value);
gchar *id = ""; gchar *name = NULL;
/* expect a GIMP opaque object having an "id" property */
if (object) if (object)
{ name = gimp_resource_get_name (GIMP_RESOURCE(object));
g_object_get (object, "id", &id, NULL);
g_object_unref (object);
}
/* id is empty when the gvalue had no GObject*, if (! name)
* or the referenced object had no property "id". g_warning("PDB procedure returned NULL object.");
* This can be an undetected fault in the called procedure.
* It is not necessarily an error in the script.
*/
if (strlen(id) == 0)
g_warning("PDB procedure returned NULL GIMP object or non-GIMP object.");
g_debug ("PDB procedure returned object ID: %s", id); return_val = sc->vptr->cons (sc, sc->vptr->mk_string (sc, name),
return_val);
return_val = sc->vptr->cons (sc, sc->vptr->mk_string (sc, id), return_val); g_free (name);
} }
else if (G_VALUE_HOLDS_OBJECT (value)) else if (G_VALUE_HOLDS_OBJECT (value))
{ {
@ -1438,7 +1424,7 @@ script_fu_marshal_procedure_call (scheme *sc,
* It is not necessarily an error in the script. * It is not necessarily an error in the script.
*/ */
if (id == -1) if (id == -1)
g_warning("PDB procedure returned NULL GIMP object or non-GIMP object."); g_warning("PDB procedure returned NULL GIMP object.");
g_debug ("PDB procedure returned object ID: %i", id); g_debug ("PDB procedure returned object ID: %i", id);

View File

@ -586,24 +586,16 @@ script_fu_arg_append_repr_from_gvalue (SFArg *arg,
case SF_GRADIENT: case SF_GRADIENT:
case SF_BRUSH: case SF_BRUSH:
{ {
/* The GValue is a GObject of type inheriting GimpResource having property "id" */ /* The GValue is a GObject of type inheriting GimpResource */
GimpResource *resource; GimpResource *resource;
gchar *resource_name; gchar *name = NULL;
/* !!! These only check whether gvalue CAN hold object type, not that it does. */
g_assert (G_VALUE_HOLDS_OBJECT (gvalue));
g_assert (GIMP_VALUE_HOLDS_RESOURCE (gvalue));
g_debug ("gvalue type is: %s", G_VALUE_TYPE_NAME(gvalue));
/* Check the value's type is suitable for a gvalue. */
g_assert (G_TYPE_IS_VALUE (G_VALUE_TYPE (gvalue)));
/* Check that gvalue actually holds type, AND IS NOT NULL. */
g_assert (G_VALUE_HOLDS (gvalue, GIMP_TYPE_RESOURCE ));
resource = g_value_get_object (gvalue); resource = g_value_get_object (gvalue);
g_object_get (resource, "id", &resource_name, NULL); if (resource)
g_string_append_printf (result_string, "\"%s\"", resource_name); name = gimp_resource_get_name (resource);
g_string_append_printf (result_string, "\"%s\"", name);
} }
break; break;

View File

@ -602,42 +602,25 @@ script_fu_resource_widget (const gchar *title,
GtkWidget *result_widget = NULL; GtkWidget *result_widget = NULL;
GimpResource *resource; GimpResource *resource;
/* New resource instance, from string *id_handle. */ resource = gimp_resource_get_by_name (resource_type, *id_handle);
resource = g_object_new (resource_type, "id", *id_handle, NULL);
/* If not valid, substitute NULL if (g_type_is_a (resource_type, GIMP_TYPE_FONT))
* String provided by script author might not name an installed font.
*/
/*
if ( ! gimp_resource_is_valid (resource) )
{ {
g_object_unref (resource);
resource = NULL;
}
*/
if (resource_type == GIMP_TYPE_FONT)
{
if ( ! gimp_font_is_valid (GIMP_FONT (resource)))
{
g_object_unref (resource);
resource = NULL;
}
result_widget = gimp_font_select_button_new (title, resource); result_widget = gimp_font_select_button_new (title, resource);
} }
else if (resource_type == GIMP_TYPE_BRUSH) else if (g_type_is_a (resource_type, GIMP_TYPE_BRUSH))
{ {
result_widget = gimp_brush_select_button_new (title, resource); result_widget = gimp_brush_select_button_new (title, resource);
} }
else if (resource_type == GIMP_TYPE_GRADIENT) else if (g_type_is_a (resource_type, GIMP_TYPE_GRADIENT))
{ {
result_widget = gimp_gradient_select_button_new (title, resource); result_widget = gimp_gradient_select_button_new (title, resource);
} }
else if (resource_type == GIMP_TYPE_PALETTE) else if (g_type_is_a (resource_type, GIMP_TYPE_PALETTE))
{ {
result_widget = gimp_palette_select_button_new (title, resource); result_widget = gimp_palette_select_button_new (title, resource);
} }
else if (resource_type == GIMP_TYPE_PATTERN) else if (g_type_is_a (resource_type, GIMP_TYPE_PATTERN))
{ {
result_widget = gimp_pattern_select_button_new (title, resource); result_widget = gimp_pattern_select_button_new (title, resource);
} }
@ -737,7 +720,7 @@ script_fu_resource_set_handler (gpointer data, /* callback "data" */
g_free (*id_handle); g_free (*id_handle);
/* We don't own the resource, nor its string. Copy the string. */ /* We don't own the resource, nor its string. Copy the string. */
*id_handle = g_strdup (gimp_resource_get_id (resource)); *id_handle = g_strdup (gimp_resource_get_name (resource));
if (closing) script_fu_activate_main_dialog (); if (closing) script_fu_activate_main_dialog ();
} }