mirror of https://github.com/GNOME/gimp.git
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:
parent
493156cc7a
commit
9638102418
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "gimp-memsize.h"
|
||||
#include "gimpdata.h"
|
||||
#include "gimpidtable.h"
|
||||
#include "gimptag.h"
|
||||
#include "gimptagged.h"
|
||||
|
||||
|
@ -44,6 +45,7 @@ enum
|
|||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_ID,
|
||||
PROP_FILE,
|
||||
PROP_WRITABLE,
|
||||
PROP_DELETABLE,
|
||||
|
@ -53,6 +55,7 @@ enum
|
|||
|
||||
struct _GimpDataPrivate
|
||||
{
|
||||
gint ID;
|
||||
GFile *file;
|
||||
GQuark mime_type;
|
||||
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 GimpIdTable *data_id_table = NULL;
|
||||
|
||||
|
||||
static void
|
||||
gimp_data_class_init (GimpDataClass *klass)
|
||||
|
@ -151,6 +156,11 @@ gimp_data_class_init (GimpDataClass *klass)
|
|||
klass->duplicate = gimp_data_real_duplicate;
|
||||
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_param_spec_object ("file", NULL, NULL,
|
||||
G_TYPE_FILE,
|
||||
|
@ -171,6 +181,8 @@ gimp_data_class_init (GimpDataClass *klass)
|
|||
NULL,
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
data_id_table = gimp_id_table_new ();
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -190,6 +202,7 @@ gimp_data_init (GimpData *data)
|
|||
|
||||
data->priv = private;
|
||||
|
||||
private->ID = gimp_id_table_insert (data_id_table, data);
|
||||
private->writable = TRUE;
|
||||
private->deletable = TRUE;
|
||||
private->dirty = TRUE;
|
||||
|
@ -216,6 +229,8 @@ gimp_data_finalize (GObject *object)
|
|||
{
|
||||
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object);
|
||||
|
||||
gimp_id_table_remove (data_id_table, private->ID);
|
||||
|
||||
g_clear_object (&private->file);
|
||||
|
||||
if (private->tags)
|
||||
|
@ -278,6 +293,10 @@ gimp_data_get_property (GObject *object,
|
|||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_ID:
|
||||
g_value_set_int (value, private->ID);
|
||||
break;
|
||||
|
||||
case PROP_FILE:
|
||||
g_value_set_object (value, private->file);
|
||||
break;
|
||||
|
@ -492,6 +511,23 @@ gimp_data_get_checksum (GimpTagged *tagged)
|
|||
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:
|
||||
* @data: object whose contents are to be saved.
|
||||
|
|
|
@ -74,6 +74,9 @@ struct _GimpDataClass
|
|||
|
||||
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,
|
||||
GError **error);
|
||||
|
||||
|
|
|
@ -25,25 +25,22 @@
|
|||
#include "core-types.h"
|
||||
|
||||
#include "gimp.h"
|
||||
#include "gimpbrush.h"
|
||||
#include "gimpdisplay.h"
|
||||
#include "gimpgradient.h"
|
||||
#include "gimpimage.h"
|
||||
#include "gimplayer.h"
|
||||
#include "gimplayermask.h"
|
||||
#include "gimppalette.h"
|
||||
#include "gimpparamspecs.h"
|
||||
#include "gimppattern.h"
|
||||
#include "gimpselection.h"
|
||||
|
||||
#include "text/gimpfont.h"
|
||||
#include "text/gimptextlayer.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
|
||||
|
@ -346,15 +343,14 @@ gimp_param_spec_enum_exclude_value (GimpParamSpecEnum *espec,
|
|||
/* include the implementation of the remaining paramspecs, they are
|
||||
* shared between app/ and libgimp/ but need different headers.
|
||||
*/
|
||||
#define gimp_image_is_valid(image) TRUE
|
||||
#define gimp_item_is_valid(item) TRUE
|
||||
#define gimp_image_is_valid(image) TRUE
|
||||
#define gimp_item_is_valid(item) TRUE
|
||||
#define gimp_display_is_valid(display) TRUE
|
||||
/* resource types. */
|
||||
#define gimp_brush_is_valid(image) TRUE
|
||||
#define gimp_font_is_valid(image) TRUE
|
||||
#define gimp_gradient_is_valid(image) TRUE
|
||||
#define gimp_palette_is_valid(image) TRUE
|
||||
#define gimp_pattern_is_valid(image) TRUE
|
||||
#define gimp_resource_is_valid(image) TRUE
|
||||
#define gimp_brush_is_valid(image) TRUE
|
||||
#define gimp_font_is_valid(image) TRUE
|
||||
#define gimp_gradient_is_valid(image) TRUE
|
||||
#define gimp_palette_is_valid(image) TRUE
|
||||
#define gimp_pattern_is_valid(image) TRUE
|
||||
|
||||
#include "../../libgimp/gimpparamspecs-body.c"
|
||||
#include "../../libgimp/gimpparamspecs-body-resource.c"
|
||||
|
|
|
@ -63,10 +63,42 @@ brush_new_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (success)
|
||||
{
|
||||
brush = (GimpBrush*) gimp_data_factory_data_new (gimp->brush_factory,
|
||||
context, name);
|
||||
brush = (GimpBrush *) gimp_data_factory_data_new (gimp->brush_factory,
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -98,7 +130,7 @@ brush_duplicate_invoker (GimpProcedure *procedure,
|
|||
{
|
||||
brush_copy = (GimpBrush *)
|
||||
gimp_data_factory_data_duplicate (gimp->brush_factory, GIMP_DATA (brush));
|
||||
/* Assert the copy has a unique name. */
|
||||
|
||||
if (!brush_copy)
|
||||
success = FALSE;
|
||||
}
|
||||
|
@ -141,33 +173,6 @@ brush_is_generated_invoker (GimpProcedure *procedure,
|
|||
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 *
|
||||
brush_rename_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
|
@ -921,6 +926,36 @@ register_brush_procs (GimpPDB *pdb)
|
|||
gimp_pdb_register_procedure (pdb, 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
|
||||
*/
|
||||
|
@ -979,36 +1014,6 @@ register_brush_procs (GimpPDB *pdb)
|
|||
gimp_pdb_register_procedure (pdb, 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
|
||||
*/
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "core/gimp.h"
|
||||
#include "core/gimpparamspecs.h"
|
||||
#include "text/gimpfont.h"
|
||||
|
||||
#include "gimppdb.h"
|
||||
#include "gimppdb-utils.h"
|
||||
|
@ -39,28 +40,33 @@
|
|||
|
||||
|
||||
static GimpValueArray *
|
||||
font_id_is_valid_invoker (GimpProcedure *procedure,
|
||||
font_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 *id;
|
||||
gboolean valid = FALSE;
|
||||
const gchar *name;
|
||||
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.
|
||||
* Clear error so GIMP not display error dialog.
|
||||
*/
|
||||
g_clear_error (error);
|
||||
if (! font)
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
|
||||
g_value_set_boolean (gimp_value_array_index (return_vals, 1), valid);
|
||||
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), font);
|
||||
|
||||
return return_vals;
|
||||
}
|
||||
|
@ -71,30 +77,30 @@ register_font_procs (GimpPDB *pdb)
|
|||
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-font-id-is-valid");
|
||||
"gimp-font-get-by-name");
|
||||
gimp_procedure_set_static_help (procedure,
|
||||
"Whether the ID is a valid reference to installed data.",
|
||||
"Returns TRUE if this ID is valid.",
|
||||
"Returns the font with the given name.",
|
||||
"Returns the font with the given name.",
|
||||
NULL);
|
||||
gimp_procedure_set_static_attribution (procedure,
|
||||
"Lloyd Konneker",
|
||||
"Lloyd Konneker",
|
||||
"2022");
|
||||
"Michael Natterer <mitch@gimp.org>",
|
||||
"Michael Natterer",
|
||||
"2023");
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_string ("id",
|
||||
"id",
|
||||
"The font ID",
|
||||
gimp_param_spec_string ("name",
|
||||
"name",
|
||||
"The name of the font",
|
||||
FALSE, FALSE, TRUE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_return_value (procedure,
|
||||
g_param_spec_boolean ("valid",
|
||||
"valid",
|
||||
"TRUE if the font ID is valid",
|
||||
gimp_param_spec_font ("font",
|
||||
"font",
|
||||
"The font",
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
|
|
|
@ -79,6 +79,38 @@ gradient_new_invoker (GimpProcedure *procedure,
|
|||
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 *
|
||||
gradient_duplicate_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
|
@ -98,8 +130,8 @@ gradient_duplicate_invoker (GimpProcedure *procedure,
|
|||
{
|
||||
gradient_copy = (GimpGradient *)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -160,16 +192,9 @@ gradient_rename_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (success)
|
||||
{
|
||||
/* Rename the gradient in app. */
|
||||
gimp_object_set_name (GIMP_OBJECT (gradient), new_name);
|
||||
/* Assert GIMP might have set a name different from new_name. */
|
||||
|
||||
/* Return a reference.
|
||||
* 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;
|
||||
gradient_renamed = gradient;
|
||||
}
|
||||
|
||||
return_vals = gimp_procedure_get_return_values (procedure, success,
|
||||
|
@ -376,33 +401,6 @@ gradient_get_custom_samples_invoker (GimpProcedure *procedure,
|
|||
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 *
|
||||
gradient_segment_get_left_color_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
|
@ -1432,6 +1430,36 @@ register_gradient_procs (GimpPDB *pdb)
|
|||
gimp_pdb_register_procedure (pdb, 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
|
||||
*/
|
||||
|
@ -1498,8 +1526,7 @@ register_gradient_procs (GimpPDB *pdb)
|
|||
"gimp-gradient-rename");
|
||||
gimp_procedure_set_static_help (procedure,
|
||||
"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"
|
||||
"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.",
|
||||
"Renames a gradient.",
|
||||
NULL);
|
||||
gimp_procedure_set_static_attribution (procedure,
|
||||
"Shlomi Fish <shlomif@iglu.org.il>",
|
||||
|
@ -1676,36 +1703,6 @@ register_gradient_procs (GimpPDB *pdb)
|
|||
gimp_pdb_register_procedure (pdb, 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
|
||||
*/
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "internal-procs.h"
|
||||
|
||||
|
||||
/* 772 procedures registered total */
|
||||
/* 779 procedures registered total */
|
||||
|
||||
void
|
||||
internal_procs_init (GimpPDB *pdb)
|
||||
|
@ -85,6 +85,7 @@ internal_procs_init (GimpPDB *pdb)
|
|||
register_plug_in_procs (pdb);
|
||||
register_plug_in_compat_procs (pdb);
|
||||
register_progress_procs (pdb);
|
||||
register_resource_procs (pdb);
|
||||
register_selection_procs (pdb);
|
||||
register_text_layer_procs (pdb);
|
||||
register_text_tool_procs (pdb);
|
||||
|
|
|
@ -72,6 +72,7 @@ void register_pdb_procs (GimpPDB *pdb);
|
|||
void register_plug_in_procs (GimpPDB *pdb);
|
||||
void register_plug_in_compat_procs (GimpPDB *pdb);
|
||||
void register_progress_procs (GimpPDB *pdb);
|
||||
void register_resource_procs (GimpPDB *pdb);
|
||||
void register_selection_procs (GimpPDB *pdb);
|
||||
void register_text_layer_procs (GimpPDB *pdb);
|
||||
void register_text_tool_procs (GimpPDB *pdb);
|
||||
|
|
|
@ -57,6 +57,7 @@ libappinternalprocs_sources = [
|
|||
'plug-in-cmds.c',
|
||||
'plug-in-compat-cmds.c',
|
||||
'progress-cmds.c',
|
||||
'resource-cmds.c',
|
||||
'selection-cmds.c',
|
||||
'text-layer-cmds.c',
|
||||
'text-tool-cmds.c',
|
||||
|
|
|
@ -76,6 +76,38 @@ palette_new_invoker (GimpProcedure *procedure,
|
|||
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 *
|
||||
palette_duplicate_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
|
@ -109,33 +141,6 @@ palette_duplicate_invoker (GimpProcedure *procedure,
|
|||
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 *
|
||||
palette_rename_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
|
@ -604,6 +609,36 @@ register_palette_procs (GimpPDB *pdb)
|
|||
gimp_pdb_register_procedure (pdb, 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
|
||||
*/
|
||||
|
@ -633,36 +668,6 @@ register_palette_procs (GimpPDB *pdb)
|
|||
gimp_pdb_register_procedure (pdb, 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
|
||||
*/
|
||||
|
|
|
@ -44,6 +44,38 @@
|
|||
#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 *
|
||||
pattern_get_info_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
|
@ -136,39 +168,41 @@ pattern_get_pixels_invoker (GimpProcedure *procedure,
|
|||
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
|
||||
register_pattern_procs (GimpPDB *pdb)
|
||||
{
|
||||
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
|
||||
*/
|
||||
|
@ -256,34 +290,4 @@ register_pattern_procs (GimpPDB *pdb)
|
|||
GIMP_PARAM_READWRITE));
|
||||
gimp_pdb_register_procedure (pdb, 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -52,6 +52,10 @@
|
|||
#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
|
||||
* libgimp/ but need different headers.
|
||||
*/
|
||||
|
|
|
@ -11,6 +11,7 @@ EXPORTS
|
|||
gimp_brush_duplicate
|
||||
gimp_brush_get_angle
|
||||
gimp_brush_get_aspect_ratio
|
||||
gimp_brush_get_by_name
|
||||
gimp_brush_get_hardness
|
||||
gimp_brush_get_info
|
||||
gimp_brush_get_pixels
|
||||
|
@ -19,10 +20,8 @@ EXPORTS
|
|||
gimp_brush_get_spacing
|
||||
gimp_brush_get_spikes
|
||||
gimp_brush_get_type
|
||||
gimp_brush_id_is_valid
|
||||
gimp_brush_is_editable
|
||||
gimp_brush_is_generated
|
||||
gimp_brush_is_valid
|
||||
gimp_brush_new
|
||||
gimp_brush_rename
|
||||
gimp_brush_set_angle
|
||||
|
@ -294,9 +293,8 @@ EXPORTS
|
|||
gimp_floating_sel_attach
|
||||
gimp_floating_sel_remove
|
||||
gimp_floating_sel_to_layer
|
||||
gimp_font_get_by_name
|
||||
gimp_font_get_type
|
||||
gimp_font_id_is_valid
|
||||
gimp_font_is_valid
|
||||
gimp_fonts_close_popup
|
||||
gimp_fonts_get_list
|
||||
gimp_fonts_popup
|
||||
|
@ -319,13 +317,12 @@ EXPORTS
|
|||
gimp_gimprc_set
|
||||
gimp_gradient_delete
|
||||
gimp_gradient_duplicate
|
||||
gimp_gradient_get_by_name
|
||||
gimp_gradient_get_custom_samples
|
||||
gimp_gradient_get_number_of_segments
|
||||
gimp_gradient_get_type
|
||||
gimp_gradient_get_uniform_samples
|
||||
gimp_gradient_id_is_valid
|
||||
gimp_gradient_is_editable
|
||||
gimp_gradient_is_valid
|
||||
gimp_gradient_new
|
||||
gimp_gradient_rename
|
||||
gimp_gradient_segment_get_blending_function
|
||||
|
@ -646,13 +643,12 @@ EXPORTS
|
|||
gimp_palette_entry_get_name
|
||||
gimp_palette_entry_set_color
|
||||
gimp_palette_entry_set_name
|
||||
gimp_palette_get_by_name
|
||||
gimp_palette_get_color_count
|
||||
gimp_palette_get_colors
|
||||
gimp_palette_get_columns
|
||||
gimp_palette_get_type
|
||||
gimp_palette_id_is_valid
|
||||
gimp_palette_is_editable
|
||||
gimp_palette_is_valid
|
||||
gimp_palette_new
|
||||
gimp_palette_rename
|
||||
gimp_palette_set_columns
|
||||
|
@ -694,11 +690,10 @@ EXPORTS
|
|||
gimp_param_spec_vectors
|
||||
gimp_param_text_layer_get_type
|
||||
gimp_param_vectors_get_type
|
||||
gimp_pattern_get_by_name
|
||||
gimp_pattern_get_info
|
||||
gimp_pattern_get_pixels
|
||||
gimp_pattern_get_type
|
||||
gimp_pattern_id_is_valid
|
||||
gimp_pattern_is_valid
|
||||
gimp_patterns_close_popup
|
||||
gimp_patterns_get_list
|
||||
gimp_patterns_popup
|
||||
|
@ -808,8 +803,23 @@ EXPORTS
|
|||
gimp_progress_uninstall
|
||||
gimp_progress_update
|
||||
gimp_quit
|
||||
gimp_resource_get_by_id
|
||||
gimp_resource_get_by_name
|
||||
gimp_resource_get_id
|
||||
gimp_resource_get_name
|
||||
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_new
|
||||
gimp_resource_select_set
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#include <libgimp/gimpprocedureconfig.h>
|
||||
#include <libgimp/gimpprocedure-params.h>
|
||||
#include <libgimp/gimpprogress.h>
|
||||
#include <libgimp/gimpresource.h>
|
||||
#include <libgimp/gimpsaveprocedure.h>
|
||||
#include <libgimp/gimpselection.h>
|
||||
#include <libgimp/gimptextlayer.h>
|
||||
|
@ -63,9 +64,7 @@
|
|||
#include <libgimp/gimpvectors.h>
|
||||
|
||||
/* Resources and their widgets. Order important. */
|
||||
#include <libgimp/gimpresource.h>
|
||||
#include <libgimp/gimpresourceselect.h>
|
||||
#include <libgimp/gimpresource-subclass.h>
|
||||
|
||||
#include <libgimp/gimp_pdb_headers.h>
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
#include <libgimp/gimppatterns_pdb.h>
|
||||
#include <libgimp/gimppatternselect_pdb.h>
|
||||
#include <libgimp/gimpprogress_pdb.h>
|
||||
#include <libgimp/gimpresource_pdb.h>
|
||||
#include <libgimp/gimpselection_pdb.h>
|
||||
#include <libgimp/gimptextlayer_pdb.h>
|
||||
#include <libgimp/gimptexttool_pdb.h>
|
||||
|
|
|
@ -72,6 +72,42 @@ gimp_brush_new (const gchar *name)
|
|||
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:
|
||||
* @brush: The brush.
|
||||
|
@ -144,42 +180,6 @@ gimp_brush_is_generated (GimpBrush *brush)
|
|||
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:
|
||||
* @brush: The brush.
|
||||
|
|
|
@ -33,9 +33,9 @@ G_BEGIN_DECLS
|
|||
|
||||
|
||||
GimpBrush* gimp_brush_new (const gchar *name);
|
||||
GimpBrush* gimp_brush_get_by_name (const gchar *name);
|
||||
GimpBrush* gimp_brush_duplicate (GimpBrush *brush);
|
||||
gboolean gimp_brush_is_generated (GimpBrush *brush);
|
||||
gboolean gimp_brush_id_is_valid (const gchar *id);
|
||||
GimpBrush* gimp_brush_rename (GimpBrush *brush,
|
||||
const gchar *new_name);
|
||||
gboolean gimp_brush_delete (GimpBrush *brush);
|
||||
|
|
|
@ -55,7 +55,6 @@ typedef struct _PreviewBitmap
|
|||
|
||||
struct _GimpBrushSelectButton
|
||||
{
|
||||
/* !! Not a pointer, is contained. */
|
||||
GimpResourceSelectButton parent_instance;
|
||||
|
||||
/* Partial view of brush image. Receives drag. Receives mouse down to popup zoom. */
|
||||
|
@ -66,7 +65,6 @@ struct _GimpBrushSelectButton
|
|||
|
||||
/* local */
|
||||
|
||||
/* implement virtual. */
|
||||
static void gimp_brush_select_button_finalize (GObject *object);
|
||||
static void gimp_brush_select_button_draw_interior (GimpResourceSelectButton *self);
|
||||
|
||||
|
@ -116,36 +114,18 @@ G_DEFINE_FINAL_TYPE (GimpBrushSelectButton,
|
|||
static void
|
||||
gimp_brush_select_button_class_init (GimpBrushSelectButtonClass *klass)
|
||||
{
|
||||
/* Alias cast klass to super classes. */
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GimpResourceSelectButtonClass *superclass = GIMP_RESOURCE_SELECT_BUTTON_CLASS (klass);
|
||||
|
||||
g_debug ("%s called", G_STRFUNC);
|
||||
|
||||
object_class->finalize = gimp_brush_select_button_finalize;
|
||||
|
||||
/* Implement pure virtual functions. */
|
||||
superclass->draw_interior = gimp_brush_select_button_draw_interior;
|
||||
|
||||
/* Set data member of class. */
|
||||
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
|
||||
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_set_drag_target (self);
|
||||
|
|
|
@ -29,9 +29,6 @@
|
|||
|
||||
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 ())
|
||||
G_DECLARE_FINAL_TYPE (GimpBrushSelectButton,
|
||||
gimp_brush_select_button,
|
||||
|
|
|
@ -37,37 +37,37 @@
|
|||
|
||||
|
||||
/**
|
||||
* gimp_font_id_is_valid:
|
||||
* @id: The font ID.
|
||||
* gimp_font_get_by_name:
|
||||
* @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
|
||||
**/
|
||||
gboolean
|
||||
gimp_font_id_is_valid (const gchar *id)
|
||||
GimpFont *
|
||||
gimp_font_get_by_name (const gchar *name)
|
||||
{
|
||||
GimpValueArray *args;
|
||||
GimpValueArray *return_vals;
|
||||
gboolean valid = FALSE;
|
||||
GimpFont *font = NULL;
|
||||
|
||||
args = gimp_value_array_new_from_types (NULL,
|
||||
G_TYPE_STRING, id,
|
||||
G_TYPE_STRING, name,
|
||||
G_TYPE_NONE);
|
||||
|
||||
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
|
||||
"gimp-font-id-is-valid",
|
||||
"gimp-font-get-by-name",
|
||||
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);
|
||||
font = GIMP_VALUES_GET_FONT (return_vals, 1);
|
||||
|
||||
gimp_value_array_unref (return_vals);
|
||||
|
||||
return valid;
|
||||
return font;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ G_BEGIN_DECLS
|
|||
/* 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
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
|
||||
struct _GimpFontSelectButton
|
||||
{
|
||||
/* !! Not a pointer, is contained. */
|
||||
GimpResourceSelectButton parent_instance;
|
||||
|
||||
GtkWidget *font_name_label;
|
||||
|
@ -53,18 +52,15 @@ struct _GimpFontSelectButton
|
|||
GtkWidget *button;
|
||||
};
|
||||
|
||||
/* local */
|
||||
|
||||
/* implement virtual */
|
||||
static void gimp_font_select_button_finalize (GObject *object);
|
||||
static void gimp_font_select_button_draw_interior (GimpResourceSelectButton *self);
|
||||
static void gimp_font_select_button_draw_interior (GimpResourceSelectButton *self);
|
||||
|
||||
/* Called at init. */
|
||||
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 };
|
||||
|
||||
|
||||
G_DEFINE_FINAL_TYPE (GimpFontSelectButton,
|
||||
gimp_font_select_button,
|
||||
GIMP_TYPE_RESOURCE_SELECT_BUTTON)
|
||||
|
@ -73,24 +69,10 @@ G_DEFINE_FINAL_TYPE (GimpFontSelectButton,
|
|||
static void
|
||||
gimp_font_select_button_class_init (GimpFontSelectButtonClass *klass)
|
||||
{
|
||||
/* Alias cast klass to super classes. */
|
||||
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_font_select_button_finalize;
|
||||
|
||||
/* Implement pure virtual functions. */
|
||||
superclass->draw_interior = gimp_font_select_button_draw_interior;
|
||||
|
||||
/* Set data member of class. */
|
||||
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
|
||||
|
@ -98,26 +80,14 @@ gimp_font_select_button_init (GimpFontSelectButton *self)
|
|||
{
|
||||
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);
|
||||
/* require self has sub widgets initialized. */
|
||||
|
||||
/* Embed the whole button.*/
|
||||
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),
|
||||
self->drag_region_widget,
|
||||
&drag_target);
|
||||
/* Super handles button clicks. */
|
||||
|
||||
gimp_resource_select_button_set_clickable (GIMP_RESOURCE_SELECT_BUTTON (self),
|
||||
self->button);
|
||||
}
|
||||
|
@ -142,24 +112,11 @@ gimp_font_select_button_new (const gchar *title,
|
|||
{
|
||||
GtkWidget *self;
|
||||
|
||||
g_debug ("%s called", G_STRFUNC);
|
||||
g_return_val_if_fail (resource == NULL || GIMP_IS_FONT (resource), NULL);
|
||||
|
||||
if (resource == NULL)
|
||||
{
|
||||
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);
|
||||
resource = GIMP_RESOURCE (gimp_context_get_font ());
|
||||
|
||||
/* 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)
|
||||
self = g_object_new (GIMP_TYPE_FONT_SELECT_BUTTON,
|
||||
"title", title,
|
||||
|
@ -170,26 +127,11 @@ gimp_font_select_button_new (const gchar *title,
|
|||
"resource", resource,
|
||||
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));
|
||||
|
||||
g_debug ("%s returns", G_STRFUNC);
|
||||
|
||||
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:
|
||||
* @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);
|
||||
|
||||
/* Delegate to super w upcast arg and downcast result. */
|
||||
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_debug ("%s", G_STRFUNC);
|
||||
|
||||
/* Delegate to super with upcasts */
|
||||
gimp_resource_select_button_set_resource (GIMP_RESOURCE_SELECT_BUTTON (self), GIMP_RESOURCE (font));
|
||||
}
|
||||
|
||||
|
||||
/* 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.
|
||||
*
|
||||
* Create a widget that is the interior of a button.
|
||||
|
@ -268,68 +192,36 @@ gimp_font_select_button_create_interior (GimpFontSelectButton *self)
|
|||
GtkWidget *label;
|
||||
gchar *font_name = "unknown";
|
||||
|
||||
g_debug ("%s", G_STRFUNC);
|
||||
|
||||
/* Outermost is-a button. */
|
||||
button = gtk_button_new ();
|
||||
|
||||
/* inside the button is hbox. */
|
||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
||||
gtk_container_add (GTK_CONTAINER (button), hbox);
|
||||
|
||||
/* first item in hbox is an icon. */
|
||||
image = gtk_image_new_from_icon_name (GIMP_ICON_FONT,
|
||||
GTK_ICON_SIZE_BUTTON);
|
||||
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);
|
||||
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->drag_region_widget = hbox;
|
||||
self->button = button;
|
||||
|
||||
/* This subclass does not connect to draw signal on interior widget. */
|
||||
|
||||
/* Return the whole interior, which is-a 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
|
||||
gimp_font_select_button_draw_interior (GimpResourceSelectButton *self)
|
||||
{
|
||||
gchar *font_name;
|
||||
GimpFontSelectButton *font_select= GIMP_FONT_SELECT_BUTTON (self);
|
||||
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));
|
||||
self_as_font_select = GIMP_FONT_SELECT_BUTTON (self);
|
||||
if (resource)
|
||||
name = gimp_resource_get_name (resource);
|
||||
|
||||
g_object_get (self, "resource", &resource, NULL);
|
||||
|
||||
/* 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);
|
||||
gtk_label_set_text (GTK_LABEL (font_select->font_name_label), name);
|
||||
}
|
||||
|
|
|
@ -29,9 +29,6 @@
|
|||
|
||||
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 ())
|
||||
G_DECLARE_FINAL_TYPE (GimpFontSelectButton,
|
||||
gimp_font_select_button,
|
||||
|
@ -42,7 +39,6 @@ G_DECLARE_FINAL_TYPE (GimpFontSelectButton,
|
|||
GtkWidget * gimp_font_select_button_new (const gchar *title,
|
||||
GimpResource *resource);
|
||||
|
||||
/* FUTURE eliminate. Use superclass method get_resource */
|
||||
GimpFont * gimp_font_select_button_get_font (GimpFontSelectButton *self);
|
||||
void gimp_font_select_button_set_font (GimpFontSelectButton *self,
|
||||
GimpFont *font);
|
||||
|
|
|
@ -197,19 +197,22 @@ _gimp_gp_param_def_to_param_spec (const GPParamDef *param_def)
|
|||
param_def->meta.m_id.none_ok,
|
||||
flags);
|
||||
|
||||
/* Resources */
|
||||
if (! strcmp (param_def->type_name, "GimpParamBrush"))
|
||||
return gimp_param_spec_brush (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok, flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamFont"))
|
||||
return gimp_param_spec_font (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok, flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamGradient"))
|
||||
return gimp_param_spec_gradient (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok, flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamPalette"))
|
||||
return gimp_param_spec_palette (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok, flags);
|
||||
|
||||
if (! strcmp (param_def->type_name, "GimpParamPattern"))
|
||||
return gimp_param_spec_pattern (name, nick, blurb,
|
||||
param_def->meta.m_id.none_ok, flags);
|
||||
|
@ -223,7 +226,8 @@ _gimp_gp_param_def_to_param_spec (const GPParamDef *param_def)
|
|||
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;
|
||||
}
|
||||
|
@ -355,46 +359,45 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
|
|||
|
||||
param_def->meta.m_id.none_ok = ispec->none_ok;
|
||||
}
|
||||
/* Resources. */
|
||||
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->meta.m_id.none_ok = ispec->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;
|
||||
param_def->meta.m_id.none_ok = rspec->none_ok;
|
||||
}
|
||||
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->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))
|
||||
{
|
||||
|
@ -476,7 +479,8 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
|
|||
else
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
/* 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 *
|
||||
get_resource_by_id (gpointer gimp,
|
||||
GType gtype,
|
||||
gchar *id)
|
||||
get_resource_by_id (gint id)
|
||||
{
|
||||
GObject *resource = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
g_return_val_if_fail (id != NULL, NULL);
|
||||
|
||||
#ifdef LIBGIMP_COMPILATION
|
||||
/* Return a new proxy instance, not any instance already existing.
|
||||
* 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");
|
||||
return (GObject *) gimp_resource_get_by_id (id);
|
||||
#else
|
||||
if (gtype == GIMP_TYPE_BRUSH)
|
||||
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);
|
||||
return (GObject *) gimp_data_get_by_id (id);
|
||||
#endif
|
||||
|
||||
g_clear_error (&error);
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
/* Return a resource's ID.
|
||||
* 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 *
|
||||
static gint
|
||||
get_resource_id (GObject *resource)
|
||||
{
|
||||
|
||||
#ifdef LIBGIMP_COMPILATION
|
||||
gchar *id = NULL;
|
||||
|
||||
/* Require resource is-a GimpResource having property id. */
|
||||
g_debug ("libgimp: %s", G_STRFUNC);
|
||||
g_object_get (resource, "id", &id, NULL);
|
||||
return id;
|
||||
return gimp_resource_get_id (GIMP_RESOURCE (resource));
|
||||
#else
|
||||
/* Cast to avoid "discarding const qualifier" */
|
||||
return (gchar*) gimp_object_get_name (resource);
|
||||
return gimp_data_get_id (GIMP_DATA (resource));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Deserialize a gp_param (from the wire) to an instance of object or primitive type.
|
||||
/* Deserialize a gp_param (from the wire) to an instance of object or
|
||||
* primitive type.
|
||||
*
|
||||
* This is used on both the core and plugin (libgimp) side,
|
||||
* each having its own class definitions for a same named class.
|
||||
* 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);
|
||||
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. */
|
||||
|
||||
|
@ -737,13 +692,7 @@ gimp_gp_param_to_value (gpointer gimp,
|
|||
}
|
||||
else if (GIMP_VALUE_HOLDS_RESOURCE (value))
|
||||
{
|
||||
/* when compiled in app, use generic pointer. */
|
||||
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);
|
||||
g_value_set_object (value, get_resource_by_id (param->data.d_int));
|
||||
}
|
||||
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);
|
||||
|
||||
/* Represent by a char*, which must be NULL when resource is NULL.
|
||||
* resource may be NULL e.g. for return value of a canceled dialog.
|
||||
*/
|
||||
param->param_type = GP_PARAM_TYPE_STRING;
|
||||
param->param_type = GP_PARAM_TYPE_INT;
|
||||
|
||||
if (resource != NULL)
|
||||
{
|
||||
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* )
|
||||
*/
|
||||
param->data.d_int = resource ? get_resource_id (resource) : -1;
|
||||
}
|
||||
else if (G_VALUE_HOLDS_PARAM (value))
|
||||
{
|
||||
|
|
|
@ -72,6 +72,42 @@ gimp_gradient_new (const gchar *name)
|
|||
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:
|
||||
* @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
|
||||
* 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.
|
||||
* 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.
|
||||
* Renames a gradient.
|
||||
*
|
||||
* Returns: (transfer full): A reference to the renamed gradient.
|
||||
*
|
||||
|
@ -383,42 +413,6 @@ gimp_gradient_get_custom_samples (GimpGradient *gradient,
|
|||
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:
|
||||
* @gradient: The gradient.
|
||||
|
|
|
@ -33,6 +33,7 @@ G_BEGIN_DECLS
|
|||
|
||||
|
||||
GimpGradient* gimp_gradient_new (const gchar *name);
|
||||
GimpGradient* gimp_gradient_get_by_name (const gchar *name);
|
||||
GimpGradient* gimp_gradient_duplicate (GimpGradient *gradient);
|
||||
gboolean gimp_gradient_is_editable (GimpGradient *gradient);
|
||||
GimpGradient* gimp_gradient_rename (GimpGradient *gradient,
|
||||
|
@ -50,7 +51,6 @@ gboolean gimp_gradient_get_custom_samples (GimpGradient
|
|||
gboolean reverse,
|
||||
gint *num_color_samples,
|
||||
gdouble **color_samples);
|
||||
gboolean gimp_gradient_id_is_valid (const gchar *id);
|
||||
gboolean gimp_gradient_segment_get_left_color (GimpGradient *gradient,
|
||||
gint segment,
|
||||
GimpRGB *color,
|
||||
|
|
|
@ -232,29 +232,20 @@ static gboolean
|
|||
get_gradient_data (GimpGradientSelectButton *self,
|
||||
gint allocation_width,
|
||||
gint *sample_count,
|
||||
gdouble **sample_array
|
||||
)
|
||||
gdouble **sample_array)
|
||||
{
|
||||
gboolean result;
|
||||
gdouble *samples;
|
||||
gint n_samples;
|
||||
|
||||
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_return_val_if_fail (GIMP_IS_GRADIENT (gradient), FALSE);
|
||||
|
||||
result = gimp_gradient_get_uniform_samples (
|
||||
gradient,
|
||||
allocation_width,
|
||||
FALSE, /* not reversed. */
|
||||
&n_samples,
|
||||
&samples);
|
||||
result = gimp_gradient_get_uniform_samples (gradient,
|
||||
allocation_width,
|
||||
FALSE, /* not reversed. */
|
||||
&n_samples,
|
||||
&samples);
|
||||
|
||||
if (result)
|
||||
{
|
||||
|
|
|
@ -75,6 +75,42 @@ gimp_palette_new (const gchar *name)
|
|||
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:
|
||||
* @palette: The palette.
|
||||
|
@ -111,42 +147,6 @@ gimp_palette_duplicate (GimpPalette *palette)
|
|||
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:
|
||||
* @palette: The palette.
|
||||
|
|
|
@ -33,8 +33,8 @@ G_BEGIN_DECLS
|
|||
|
||||
|
||||
GimpPalette* gimp_palette_new (const gchar *name);
|
||||
GimpPalette* gimp_palette_get_by_name (const gchar *name);
|
||||
GimpPalette* gimp_palette_duplicate (GimpPalette *palette);
|
||||
gboolean gimp_palette_id_is_valid (const gchar *id);
|
||||
GimpPalette* gimp_palette_rename (GimpPalette *palette,
|
||||
const gchar *new_name);
|
||||
gboolean gimp_palette_delete (GimpPalette *palette);
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
* <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Similar to gimpfontselectbutton.c, initially created by simple substitution. */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gegl.h>
|
||||
|
@ -47,7 +45,6 @@
|
|||
|
||||
struct _GimpPaletteSelectButton
|
||||
{
|
||||
/* !! Not a pointer, is contained. */
|
||||
GimpResourceSelectButton parent_instance;
|
||||
|
||||
GtkWidget *palette_name_label;
|
||||
|
@ -55,18 +52,16 @@ struct _GimpPaletteSelectButton
|
|||
GtkWidget *button;
|
||||
};
|
||||
|
||||
/* local */
|
||||
|
||||
/* implement virtual */
|
||||
static void gimp_palette_select_button_finalize (GObject *object);
|
||||
static void gimp_palette_select_button_draw_interior (GimpResourceSelectButton *self);
|
||||
|
||||
/* Called at init. */
|
||||
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 };
|
||||
|
||||
|
||||
G_DEFINE_FINAL_TYPE (GimpPaletteSelectButton,
|
||||
gimp_palette_select_button,
|
||||
GIMP_TYPE_RESOURCE_SELECT_BUTTON)
|
||||
|
@ -75,24 +70,13 @@ G_DEFINE_FINAL_TYPE (GimpPaletteSelectButton,
|
|||
static void
|
||||
gimp_palette_select_button_class_init (GimpPaletteSelectButtonClass *klass)
|
||||
{
|
||||
/* Alias cast klass to super classes. */
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
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_palette_select_button_finalize;
|
||||
|
||||
/* Implement pure virtual functions. */
|
||||
superclass->draw_interior = gimp_palette_select_button_draw_interior;
|
||||
|
||||
/* Set data member of class. */
|
||||
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
|
||||
|
@ -100,26 +84,13 @@ gimp_palette_select_button_init (GimpPaletteSelectButton *self)
|
|||
{
|
||||
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);
|
||||
/* require self has sub widgets initialized. */
|
||||
|
||||
/* Embed the whole button.*/
|
||||
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),
|
||||
self->drag_region_widget,
|
||||
&drag_target);
|
||||
/* Super handles button clicks. */
|
||||
gimp_resource_select_button_set_clickable (GIMP_RESOURCE_SELECT_BUTTON (self),
|
||||
self->button);
|
||||
}
|
||||
|
@ -144,24 +115,9 @@ gimp_palette_select_button_new (const gchar *title,
|
|||
{
|
||||
GtkWidget *self;
|
||||
|
||||
g_debug ("%s called", G_STRFUNC);
|
||||
|
||||
if (resource == NULL)
|
||||
{
|
||||
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);
|
||||
resource = GIMP_RESOURCE (gimp_context_get_palette ());
|
||||
|
||||
/* 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)
|
||||
self = g_object_new (GIMP_TYPE_PALETTE_SELECT_BUTTON,
|
||||
"title", title,
|
||||
|
@ -172,17 +128,8 @@ gimp_palette_select_button_new (const gchar *title,
|
|||
"resource", resource,
|
||||
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));
|
||||
|
||||
g_debug ("%s returns", G_STRFUNC);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -303,35 +250,17 @@ gimp_palette_select_button_create_interior (GimpPaletteSelectButton *self)
|
|||
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
|
||||
gimp_palette_select_button_draw_interior (GimpResourceSelectButton *self)
|
||||
{
|
||||
gchar *palette_name;
|
||||
GimpResource *resource;
|
||||
GimpPaletteSelectButton *self_as_palette_select;
|
||||
GimpPaletteSelectButton *palette_select= GIMP_PALETTE_SELECT_BUTTON (self);
|
||||
GimpResource *resource;
|
||||
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));
|
||||
self_as_palette_select = GIMP_PALETTE_SELECT_BUTTON (self);
|
||||
if (resource)
|
||||
name = gimp_resource_get_name (resource);
|
||||
|
||||
g_object_get (self, "resource", &resource, NULL);
|
||||
|
||||
/* 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);
|
||||
gtk_label_set_text (GTK_LABEL (palette_select->palette_name_label), name);
|
||||
}
|
||||
|
|
|
@ -29,9 +29,6 @@
|
|||
|
||||
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 ())
|
||||
G_DECLARE_FINAL_TYPE (GimpPaletteSelectButton,
|
||||
gimp_palette_select_button,
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -460,10 +460,10 @@ gimp_param_text_layer_init (GParamSpec *pspec)
|
|||
**/
|
||||
GParamSpec *
|
||||
gimp_param_spec_text_layer (const gchar *name,
|
||||
const gchar *nick,
|
||||
const gchar *blurb,
|
||||
gboolean none_ok,
|
||||
GParamFlags flags)
|
||||
const gchar *nick,
|
||||
const gchar *blurb,
|
||||
gboolean none_ok,
|
||||
GParamFlags flags)
|
||||
{
|
||||
GimpParamSpecItem *ispec;
|
||||
|
||||
|
@ -855,7 +855,7 @@ gimp_param_display_validate (GParamSpec *pspec,
|
|||
GimpDisplay *display = value->data[0].v_pointer;
|
||||
|
||||
if (! dspec->none_ok && display == NULL)
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
|
||||
if (display && (! GIMP_IS_DISPLAY (display) ||
|
||||
! gimp_display_is_valid (display)))
|
||||
|
@ -903,3 +903,518 @@ gimp_param_spec_display (const gchar *name,
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* LIBGIMP - The GIMP Library
|
||||
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
||||
*
|
||||
|
@ -17,7 +16,6 @@
|
|||
* <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#if !defined (__GIMP_H_INSIDE__) && !defined (GIMP_COMPILATION)
|
||||
#error "Only <libgimp/gimp.h> can be included directly."
|
||||
#endif
|
||||
|
@ -31,7 +29,8 @@ G_BEGIN_DECLS
|
|||
* 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_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
|
||||
{
|
||||
GParamSpecObject parent_instance;
|
||||
|
||||
gboolean none_ok;
|
||||
};
|
||||
|
||||
GType gimp_param_resource_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GParamSpec * gimp_param_spec_resource (
|
||||
const gchar *name,
|
||||
const gchar *nick,
|
||||
const gchar *blurb,
|
||||
gboolean none_ok,
|
||||
GParamFlags flags);
|
||||
|
||||
GParamSpec * gimp_param_spec_resource (const gchar *name,
|
||||
const gchar *nick,
|
||||
const gchar *blurb,
|
||||
gboolean none_ok,
|
||||
GParamFlags flags);
|
||||
|
||||
|
||||
/*
|
||||
* 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_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))
|
||||
|
@ -69,8 +69,7 @@ typedef struct _GimpParamSpecBrush GimpParamSpecBrush;
|
|||
|
||||
struct _GimpParamSpecBrush
|
||||
{
|
||||
GParamSpecObject parent_instance;
|
||||
gboolean none_ok;
|
||||
GimpParamSpecResource parent_instance;
|
||||
};
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#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_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))
|
||||
|
@ -96,8 +97,7 @@ typedef struct _GimpParamSpecFont GimpParamSpecFont;
|
|||
|
||||
struct _GimpParamSpecFont
|
||||
{
|
||||
GParamSpecObject parent_instance;
|
||||
gboolean none_ok;
|
||||
GimpParamSpecResource parent_instance;
|
||||
};
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#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_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))
|
||||
|
@ -123,8 +125,7 @@ typedef struct _GimpParamSpecGradient GimpParamSpecGradient;
|
|||
|
||||
struct _GimpParamSpecGradient
|
||||
{
|
||||
GParamSpecObject parent_instance;
|
||||
gboolean none_ok;
|
||||
GimpParamSpecResource parent_instance;
|
||||
};
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#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_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))
|
||||
|
@ -150,8 +153,7 @@ typedef struct _GimpParamSpecPalette GimpParamSpecPalette;
|
|||
|
||||
struct _GimpParamSpecPalette
|
||||
{
|
||||
GParamSpecObject parent_instance;
|
||||
gboolean none_ok;
|
||||
GimpParamSpecResource parent_instance;
|
||||
};
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#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_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))
|
||||
|
@ -177,8 +181,7 @@ typedef struct _GimpParamSpecPattern GimpParamSpecPattern;
|
|||
|
||||
struct _GimpParamSpecPattern
|
||||
{
|
||||
GParamSpecObject parent_instance;
|
||||
gboolean none_ok;
|
||||
GimpParamSpecResource parent_instance;
|
||||
};
|
||||
|
||||
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,
|
||||
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
|
||||
|
||||
#endif /* __LIBGIMP_GIMP_PARAM_SPECS_RESOURCE_H__ */
|
||||
|
|
|
@ -31,5 +31,6 @@
|
|||
/* include the implementation, they are shared between app/ and
|
||||
* libgimp/ but need different headers.
|
||||
*/
|
||||
#define LIBGIMP_COMPILATION
|
||||
#include "gimpparamspecs-body.c"
|
||||
#include "gimpparamspecs-body-resource.c"
|
||||
#undef LIBGIMP_COMPILATION
|
||||
|
|
|
@ -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:
|
||||
* @pattern: The pattern.
|
||||
|
@ -146,39 +182,3 @@ gimp_pattern_get_pixels (GimpPattern *pattern,
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -32,16 +32,16 @@ G_BEGIN_DECLS
|
|||
/* For information look into the C source or the html documentation */
|
||||
|
||||
|
||||
gboolean gimp_pattern_get_info (GimpPattern *pattern,
|
||||
gint *width,
|
||||
gint *height,
|
||||
gint *bpp);
|
||||
gboolean gimp_pattern_get_pixels (GimpPattern *pattern,
|
||||
gint *width,
|
||||
gint *height,
|
||||
gint *bpp,
|
||||
GBytes **color_bytes);
|
||||
gboolean gimp_pattern_id_is_valid (const gchar *id);
|
||||
GimpPattern* gimp_pattern_get_by_name (const gchar *name);
|
||||
gboolean gimp_pattern_get_info (GimpPattern *pattern,
|
||||
gint *width,
|
||||
gint *height,
|
||||
gint *bpp);
|
||||
gboolean gimp_pattern_get_pixels (GimpPattern *pattern,
|
||||
gint *width,
|
||||
gint *height,
|
||||
gint *bpp,
|
||||
GBytes **color_bytes);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -53,6 +53,8 @@ GimpImage * _gimp_plug_in_get_image (GimpPlugIn *plug_in,
|
|||
gint32 image_id);
|
||||
GimpItem * _gimp_plug_in_get_item (GimpPlugIn *plug_in,
|
||||
gint32 item_id);
|
||||
GimpResource * _gimp_plug_in_get_resource (GimpPlugIn *plug_in,
|
||||
gint32 resource_id);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -152,6 +152,7 @@ struct _GimpPlugInPrivate
|
|||
GHashTable *displays;
|
||||
GHashTable *images;
|
||||
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);
|
||||
|
||||
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->items, 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->items, TRUE);
|
||||
gimp_plug_in_destroy_proxies (plug_in->priv->resources, TRUE);
|
||||
|
||||
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_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->items, 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->items, FALSE);
|
||||
gimp_plug_in_destroy_proxies (plug_in->priv->resources, FALSE);
|
||||
|
||||
if (! plug_in->priv->procedure_stack)
|
||||
{
|
||||
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->items, 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->items, TRUE);
|
||||
gimp_plug_in_destroy_proxies (plug_in->priv->resources, TRUE);
|
||||
|
||||
gimp_plug_in_destroy_hashes (plug_in);
|
||||
}
|
||||
|
@ -1583,12 +1587,73 @@ _gimp_plug_in_get_item (GimpPlugIn *plug_in,
|
|||
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
|
||||
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->images, g_hash_table_unref);
|
||||
g_clear_pointer (&plug_in->priv->items, 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->items, g_hash_table_unref);
|
||||
g_clear_pointer (&plug_in->priv->resources, g_hash_table_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -29,14 +29,16 @@
|
|||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
GimpDisplay * _gimp_procedure_get_display (GimpProcedure *procedure,
|
||||
gint32 display_id);
|
||||
GimpImage * _gimp_procedure_get_image (GimpProcedure *procedure,
|
||||
gint32 image_id);
|
||||
GimpItem * _gimp_procedure_get_item (GimpProcedure *procedure,
|
||||
gint32 item_id);
|
||||
GimpDisplay * _gimp_procedure_get_display (GimpProcedure *procedure,
|
||||
gint32 display_id);
|
||||
GimpImage * _gimp_procedure_get_image (GimpProcedure *procedure,
|
||||
gint32 image_id);
|
||||
GimpItem * _gimp_procedure_get_item (GimpProcedure *procedure,
|
||||
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
|
||||
|
|
|
@ -92,6 +92,7 @@ struct _GimpProcedurePrivate
|
|||
GHashTable *displays;
|
||||
GHashTable *images;
|
||||
GHashTable *items;
|
||||
GHashTable *resources;
|
||||
};
|
||||
|
||||
|
||||
|
@ -2280,12 +2281,46 @@ _gimp_procedure_get_item (GimpProcedure *procedure,
|
|||
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
|
||||
_gimp_procedure_destroy_proxies (GimpProcedure *procedure)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_PROCEDURE (procedure));
|
||||
|
||||
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->items, 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->items, g_hash_table_unref);
|
||||
g_clear_pointer (&procedure->priv->resources, g_hash_table_unref);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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__ */
|
|
@ -20,8 +20,11 @@
|
|||
|
||||
#include "gimp.h"
|
||||
|
||||
/* deriveable type not included in gimp.h. */
|
||||
#include "gimpresource.h"
|
||||
#include "libgimpbase/gimpwire.h" /* FIXME kill this include */
|
||||
|
||||
#include "gimpplugin-private.h"
|
||||
#include "gimpprocedure-private.h"
|
||||
|
||||
|
||||
/* GimpResource: base class for resources.
|
||||
*
|
||||
|
@ -65,13 +68,12 @@
|
|||
* a GimpResource on the libgimp side is a proxy.
|
||||
* There is no GimpResource class in core.
|
||||
*
|
||||
* One use of GimpResource and its subclasses
|
||||
* is as a held type of GParamSpecObject, used to declare the parameters of a PDB procedure.
|
||||
* A GimpResource is serializable just for the purpose of serializing GimpProcedureConfig,
|
||||
* a "settings" i.e. a set of values for the arguments to a GimpProcedure.
|
||||
* A GimpResource just holds the id as a way to identify a *resource*
|
||||
* in calls to PDB procedures that ultimately access the core instance of the resource.
|
||||
|
||||
* One use of GimpResource and its subclasses is as a held type of
|
||||
* GParamSpecObject, used to declare the parameters of a PDB
|
||||
* procedure. A GimpResource just holds the id as a way to identify a
|
||||
* *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*
|
||||
* that might not still exist in core in the set of loaded resources (files.)
|
||||
*
|
||||
|
@ -103,13 +105,12 @@ enum
|
|||
N_PROPS
|
||||
};
|
||||
|
||||
/* Private structure definition. */
|
||||
typedef struct
|
||||
|
||||
typedef struct _GimpResourcePrivate
|
||||
{
|
||||
char *id;
|
||||
gint id;
|
||||
} GimpResourcePrivate;
|
||||
|
||||
static void gimp_resource_finalize (GObject *object);
|
||||
|
||||
static void gimp_resource_set_property (GObject *object,
|
||||
guint property_id,
|
||||
|
@ -120,128 +121,51 @@ static void gimp_resource_get_property (GObject *object,
|
|||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
/* Implementation of the GimpConfigInterface */
|
||||
static void gimp_resource_config_iface_init (GimpConfigInterface *iface);
|
||||
|
||||
static gboolean gimp_resource_serialize (GimpConfig *config,
|
||||
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))
|
||||
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GimpResource, gimp_resource, G_TYPE_OBJECT)
|
||||
|
||||
#define parent_class gimp_resource_parent_class
|
||||
|
||||
static GParamSpec *props[N_PROPS] = { NULL, };
|
||||
|
||||
/* Class construction */
|
||||
|
||||
static void
|
||||
gimp_resource_class_init (GimpResourceClass *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->get_property = gimp_resource_get_property;
|
||||
|
||||
props[PROP_ID] =
|
||||
g_param_spec_string ("id",
|
||||
"The id",
|
||||
"The id for internal use",
|
||||
"unknown",
|
||||
GIMP_PARAM_READWRITE);
|
||||
g_param_spec_int ("id",
|
||||
"The id",
|
||||
"The id for internal use",
|
||||
0, G_MAXINT32, 0,
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, props);
|
||||
}
|
||||
|
||||
/* Instance construction. */
|
||||
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
|
||||
gimp_resource_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpResource *self = GIMP_RESOURCE (object);
|
||||
GimpResourcePrivate *priv = gimp_resource_get_instance_private (self);
|
||||
GimpResource *resource = GIMP_RESOURCE (object);
|
||||
GimpResourcePrivate *priv = gimp_resource_get_instance_private (resource);
|
||||
|
||||
g_debug ("gimp_resource_set_property");
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_ID:
|
||||
g_free (priv->id);
|
||||
priv->id = g_value_dup_string (value);
|
||||
priv->id = g_value_get_int (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -256,15 +180,13 @@ gimp_resource_get_property (GObject *object,
|
|||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpResource *self = GIMP_RESOURCE (object);
|
||||
GimpResourcePrivate *priv = gimp_resource_get_instance_private (self);
|
||||
GimpResource *resource = GIMP_RESOURCE (object);
|
||||
GimpResourcePrivate *priv = gimp_resource_get_instance_private (resource);
|
||||
|
||||
g_debug ("gimp_resource_get_property");
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_ID:
|
||||
g_value_set_string (value, priv->id);
|
||||
/* Assert id string was copied into GValue. */
|
||||
g_value_set_int (value, priv->id);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -273,74 +195,251 @@ gimp_resource_get_property (GObject *object,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* config iface */
|
||||
|
||||
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.
|
||||
/**
|
||||
* gimp_resource_get_id:
|
||||
* @resource: The resource.
|
||||
*
|
||||
* Requires the id is not NULL.
|
||||
* When id is NULL, writes nothing and returns FALSE.
|
||||
*/
|
||||
static gboolean
|
||||
gimp_resource_serialize (GimpConfig *config,
|
||||
GimpConfigWriter *writer,
|
||||
gpointer data) /* Unused. */
|
||||
* Returns: the resource ID.
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
gint32
|
||||
gimp_resource_get_id (GimpResource *resource)
|
||||
{
|
||||
/* Require config is-a GimpResource instance implementing Config iface. */
|
||||
GimpResource *self = GIMP_RESOURCE (config);
|
||||
GimpResourcePrivate *priv = gimp_resource_get_instance_private (self);
|
||||
|
||||
g_debug ("resource serialize");
|
||||
|
||||
if (priv->id != NULL)
|
||||
if (resource)
|
||||
{
|
||||
g_debug ("resource serialize: %s", priv->id);
|
||||
/* require the caller opened and will close writer.
|
||||
* Caller wrote the subclass type name "Gimp<Foo>"
|
||||
*/
|
||||
gimp_config_writer_string (writer, priv->id);
|
||||
return TRUE;
|
||||
GimpResourcePrivate *priv = gimp_resource_get_instance_private (resource);
|
||||
|
||||
return priv->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_debug ("resource serialize failed: NULL id");
|
||||
return FALSE;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
gimp_resource_deserialize (GimpConfig *config,
|
||||
GScanner *scanner,
|
||||
gint nest_level,
|
||||
gpointer data)
|
||||
/**
|
||||
* gimp_resource_get_by_id:
|
||||
* @resource_id: The resource id.
|
||||
*
|
||||
* Returns a #GimpResource representing @resource_id. Since #GimpResource is an
|
||||
* 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;
|
||||
GimpResource *self = GIMP_RESOURCE (config);
|
||||
GimpResourcePrivate *priv = gimp_resource_get_instance_private (self);
|
||||
|
||||
g_debug ("resource deserialize");
|
||||
|
||||
if (! gimp_scanner_parse_string (scanner, &id))
|
||||
if (resource_id > 0)
|
||||
{
|
||||
g_scanner_error (scanner,
|
||||
"Fail scan string for resource");
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_debug ("resource deserialize: %s", id);
|
||||
priv->id = id;
|
||||
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||
GimpProcedure *procedure = _gimp_plug_in_get_procedure (plug_in);
|
||||
|
||||
return _gimp_procedure_get_resource (procedure, resource_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) {}
|
||||
|
|
|
@ -25,10 +25,13 @@
|
|||
|
||||
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 ())
|
||||
G_DECLARE_DERIVABLE_TYPE (GimpResource, gimp_resource, GIMP, RESOURCE, GObject)
|
||||
|
||||
|
||||
struct _GimpResourceClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
@ -44,7 +47,34 @@ struct _GimpResourceClass
|
|||
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
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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__ */
|
|
@ -34,9 +34,8 @@
|
|||
typedef struct
|
||||
{
|
||||
/* This portion is passed to and from idle. */
|
||||
/* !!! resource is not long lived, only during a transfer to idle. */
|
||||
guint idle_id;
|
||||
GimpResource *resource;
|
||||
gint resource_id;
|
||||
GType resource_type;
|
||||
gboolean closing;
|
||||
|
||||
|
@ -132,10 +131,6 @@ static void
|
|||
create_callback_PDB_procedure_params (GimpProcedure *procedure,
|
||||
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",
|
||||
"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))
|
||||
{
|
||||
GIMP_PROC_ARG_DOUBLE (procedure, "opacity",
|
||||
"Opacity",
|
||||
NULL,
|
||||
0.0, 100.0, 100.0,
|
||||
G_PARAM_READWRITE);
|
||||
"Opacity",
|
||||
NULL,
|
||||
0.0, 100.0, 100.0,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
GIMP_PROC_ARG_INT (procedure, "spacing",
|
||||
"Spacing",
|
||||
|
@ -236,7 +231,6 @@ create_callback_PDB_procedure_params (GimpProcedure *procedure,
|
|||
g_warning ("%s: unhandled resource type", G_STRFUNC);
|
||||
}
|
||||
|
||||
/* Suffix of args is same across resource_type. */
|
||||
GIMP_PROC_ARG_BOOLEAN (procedure, "closing",
|
||||
"Closing",
|
||||
"If the dialog was closing",
|
||||
|
@ -258,10 +252,8 @@ popup_remote_chooser (const gchar *title,
|
|||
gboolean result = FALSE;
|
||||
gchar *resource_name;
|
||||
|
||||
g_debug ("%s", G_STRFUNC);
|
||||
|
||||
/* The PDB procedure still takes a name aka ID instead of a resource object. */
|
||||
g_object_get (resource, "id", &resource_name, NULL);
|
||||
/* The PDB procedure still takes a name */
|
||||
resource_name = gimp_resource_get_name (resource);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
return 8;
|
||||
return 7;
|
||||
}
|
||||
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))
|
||||
{
|
||||
return 6;
|
||||
return 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -375,15 +368,13 @@ index_of_is_closing_arg (GType resource_type)
|
|||
* string belongs to the resource selection dialog and will be
|
||||
* freed automatically when the dialog is closed.
|
||||
**/
|
||||
|
||||
|
||||
const gchar *
|
||||
gimp_resource_select_new (const gchar *title,
|
||||
GimpResource *resource,
|
||||
GType resource_type,
|
||||
GimpResourceChoosedCallback callback,
|
||||
gpointer owner_data,
|
||||
GDestroyNotify data_destroy)
|
||||
gimp_resource_select_new (const gchar *title,
|
||||
GimpResource *resource,
|
||||
GType resource_type,
|
||||
GimpResourceChoosedCallback callback,
|
||||
gpointer owner_data,
|
||||
GDestroyNotify data_destroy)
|
||||
{
|
||||
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||
GimpProcedure *procedure;
|
||||
|
@ -420,7 +411,8 @@ const gchar *
|
|||
gimp_plug_in_add_temp_procedure (plug_in, 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 */
|
||||
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 ();
|
||||
|
||||
g_debug ("%s", G_STRFUNC);
|
||||
|
||||
g_return_if_fail (temp_PDB_callback_name != NULL);
|
||||
|
||||
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,
|
||||
GType resource_type)
|
||||
{
|
||||
gchar * resource_name;
|
||||
|
||||
g_debug ("%s", G_STRFUNC);
|
||||
gchar *resource_name;
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
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))
|
||||
{
|
||||
|
@ -514,21 +497,16 @@ gimp_resource_select_set (const gchar *temp_pdb_callback,
|
|||
static void
|
||||
gimp_resource_data_free (GimpResourceAdaption *adaption)
|
||||
{
|
||||
g_debug ("%s", G_STRFUNC);
|
||||
|
||||
if (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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/* Destroy any inner generic data passed by the owner. */
|
||||
if (adaption->data_destroy)
|
||||
adaption->data_destroy (adaption->owner_data);
|
||||
|
||||
|
@ -541,33 +519,24 @@ gimp_resource_data_free (GimpResourceAdaption *adaption)
|
|||
static GimpValueArray *
|
||||
gimp_temp_resource_run (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data) /* is-a adaption */
|
||||
gpointer run_data)
|
||||
{
|
||||
GimpResourceAdaption *adaption = run_data;
|
||||
const gchar *resource_name;
|
||||
GimpResource *resource;
|
||||
|
||||
g_debug ("%s", G_STRFUNC);
|
||||
resource_name = GIMP_VALUES_GET_STRING (args, 0);
|
||||
|
||||
/* Convert name string to object. */
|
||||
resource_name = GIMP_VALUES_GET_STRING(args, 0);
|
||||
resource = g_object_new (adaption->resource_type, "id", resource_name, NULL);
|
||||
/* Pass the new resource object to the idle func, which will transfer ownership.
|
||||
* and clear adaption->resource.
|
||||
* Thus assert that adaption->resource is NULL, and this is not a leak.
|
||||
*/
|
||||
adaption->resource = resource;
|
||||
resource = gimp_resource_get_by_name (adaption->resource_type,
|
||||
resource_name);
|
||||
|
||||
adaption->resource_id = gimp_resource_get_id (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));
|
||||
|
||||
/* Set idle_id to remember an idle source exists,
|
||||
* but idle_id is not used by the idle func.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
@ -577,18 +546,12 @@ gimp_temp_resource_idle (GimpResourceAdaption *adaption)
|
|||
{
|
||||
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)
|
||||
adaption->callback (adaption->resource,
|
||||
adaption->callback (gimp_resource_get_by_id (adaption->resource_id),
|
||||
adaption->closing,
|
||||
adaption->owner_data);
|
||||
|
||||
/* Ownership of resource transfers to whom we are calling back. */
|
||||
adaption->resource = NULL;
|
||||
adaption->resource_id = 0;
|
||||
|
||||
if (adaption->closing)
|
||||
{
|
||||
|
|
|
@ -32,12 +32,11 @@
|
|||
#include "libgimp-intl.h"
|
||||
|
||||
|
||||
/* Annotation for the class, which appears in the GimpUi doc. */
|
||||
|
||||
/**
|
||||
* SECTION: 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.
|
||||
*
|
||||
|
@ -75,12 +74,6 @@
|
|||
* 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
|
||||
{
|
||||
|
@ -97,36 +90,17 @@ enum
|
|||
};
|
||||
|
||||
|
||||
/* Private structure definition. */
|
||||
typedef struct
|
||||
{
|
||||
GimpResource *resource; /* Thing self widget chooses*/
|
||||
/* Type of resource is known by the class, not instance.
|
||||
* e.g. GimpFont, some subclass of GimpResource
|
||||
*/
|
||||
|
||||
/* 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;
|
||||
|
||||
GimpResource *resource;
|
||||
gchar *title;
|
||||
const gchar *temp_callback_from_remote_dialog;
|
||||
GtkWidget *interior_widget;
|
||||
} GimpResourceSelectButtonPrivate;
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
/* Overridden GObject methods. */
|
||||
static void gimp_resource_select_button_dispose (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
|
||||
gimp_resource_select_button_class_init (GimpResourceSelectButtonClass *klass)
|
||||
{
|
||||
/* Root super class */
|
||||
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->finalize = gimp_resource_select_button_finalize;
|
||||
object_class->set_property = gimp_resource_select_button_set_property;
|
||||
object_class->get_property = gimp_resource_select_button_get_property;
|
||||
|
||||
/* Signals */
|
||||
klass->resource_set = NULL;
|
||||
klass->resource_set = NULL;
|
||||
|
||||
/**
|
||||
* GimpResourceSelectButton:title:
|
||||
|
@ -190,14 +159,13 @@ gimp_resource_select_button_class_init (GimpResourceSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
/* Default is not localized i18n since caller should provide a value. */
|
||||
resource_button_props[PROP_TITLE]
|
||||
= g_param_spec_string ("title",
|
||||
"Title",
|
||||
"The title to be used for the resource selection popup dialog",
|
||||
"Resource Selection", /* default */
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY);
|
||||
resource_button_props[PROP_TITLE] =
|
||||
g_param_spec_string ("title",
|
||||
"Title",
|
||||
"The title to be used for the resource selection popup dialog",
|
||||
"Resource Selection",
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
/**
|
||||
* GimpResourceSelectButton:resource:
|
||||
|
@ -206,15 +174,15 @@ gimp_resource_select_button_class_init (GimpResourceSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
/* Has no default. */
|
||||
resource_button_props[PROP_RESOURCE]
|
||||
= gimp_param_spec_resource ("resource", /* name */
|
||||
"Resource", /* nick */
|
||||
"The currently selected resource",
|
||||
TRUE, /* none_ok */
|
||||
GIMP_PARAM_READWRITE);
|
||||
resource_button_props[PROP_RESOURCE] =
|
||||
gimp_param_spec_resource ("resource",
|
||||
"Resource",
|
||||
"The currently selected resource",
|
||||
TRUE, /* none_ok */
|
||||
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:
|
||||
|
@ -241,25 +209,34 @@ gimp_resource_select_button_class_init (GimpResourceSelectButtonClass *klass)
|
|||
static void
|
||||
gimp_resource_select_button_init (GimpResourceSelectButton *self)
|
||||
{
|
||||
GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self);
|
||||
|
||||
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;
|
||||
gtk_orientable_set_orientation (GTK_ORIENTABLE (self),
|
||||
GTK_ORIENTATION_HORIZONTAL);
|
||||
}
|
||||
|
||||
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:
|
||||
* @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
|
||||
*
|
||||
* Called by a subclass init to specialize the instance.
|
||||
|
@ -271,13 +248,10 @@ gimp_resource_select_button_init (GimpResourceSelectButton *self)
|
|||
* Since: 3.0
|
||||
**/
|
||||
void
|
||||
gimp_resource_select_button_set_drag_target (
|
||||
GimpResourceSelectButton *self,
|
||||
GtkWidget *drag_region_widget,
|
||||
const GtkTargetEntry *drag_target)
|
||||
gimp_resource_select_button_set_drag_target (GimpResourceSelectButton *self,
|
||||
GtkWidget *drag_region_widget,
|
||||
const GtkTargetEntry *drag_target)
|
||||
{
|
||||
g_debug ("%s", G_STRFUNC);
|
||||
|
||||
g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self));
|
||||
g_return_if_fail (drag_target != NULL);
|
||||
g_return_if_fail (drag_region_widget != NULL);
|
||||
|
@ -312,8 +286,6 @@ void
|
|||
gimp_resource_select_button_set_clickable (GimpResourceSelectButton *self,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
g_debug ("%s", G_STRFUNC);
|
||||
|
||||
g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self));
|
||||
g_return_if_fail (widget != NULL);
|
||||
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);
|
||||
|
||||
priv = gimp_resource_select_button_get_instance_private (self);
|
||||
|
||||
return priv->resource;
|
||||
}
|
||||
|
||||
|
@ -367,8 +340,6 @@ gimp_resource_select_button_set_resource (GimpResourceSelectButton *self,
|
|||
|
||||
priv = gimp_resource_select_button_get_instance_private (self);
|
||||
|
||||
g_debug ("%s", G_STRFUNC);
|
||||
|
||||
if (priv->temp_callback_from_remote_dialog)
|
||||
{
|
||||
/* A popup chooser dialog is already shown.
|
||||
|
@ -398,7 +369,8 @@ gimp_resource_select_button_set_resource (GimpResourceSelectButton *self,
|
|||
* Since: 3.0
|
||||
*/
|
||||
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 (GTK_IS_WIDGET (interior));
|
||||
|
@ -406,7 +378,6 @@ gimp_resource_select_button_embed_interior (GimpResourceSelectButton *self, GtkW
|
|||
|
||||
gtk_container_add (GTK_CONTAINER (self), interior);
|
||||
|
||||
/* Show self as widget, now it is complete. */
|
||||
gtk_widget_show_all (GTK_WIDGET (self));
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
static void
|
||||
gimp_resource_select_button_draw_interior (GimpResourceSelectButton *self, GimpResource *resource)
|
||||
gimp_resource_select_button_draw_interior (GimpResourceSelectButton *self,
|
||||
GimpResource *resource)
|
||||
{
|
||||
GimpResourceSelectButtonClass *klass;
|
||||
|
||||
g_debug ("%s", G_STRFUNC);
|
||||
|
||||
g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self));
|
||||
g_return_if_fail (GIMP_IS_RESOURCE (resource));
|
||||
|
||||
klass = GIMP_RESOURCE_SELECT_BUTTON_GET_CLASS (self);
|
||||
|
||||
/* Check subclass has overridden before calling it. */
|
||||
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,
|
||||
* 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.
|
||||
*/
|
||||
klass->draw_interior (self);
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
static void
|
||||
|
@ -454,15 +417,12 @@ gimp_resource_select_button_set_remote_dialog (GimpResourceSelectButton *self,
|
|||
GimpResourceSelectButtonPrivate *priv;
|
||||
GimpResourceSelectButtonClass *klass;
|
||||
|
||||
g_debug ("%s", G_STRFUNC);
|
||||
|
||||
g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (self));
|
||||
g_return_if_fail (resource != NULL);
|
||||
|
||||
priv = gimp_resource_select_button_get_instance_private (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);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* 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
|
||||
gimp_resource_select_button_set_property (GObject *object,
|
||||
guint property_id,
|
||||
|
@ -490,8 +444,6 @@ gimp_resource_select_button_set_property (GObject *object,
|
|||
GimpResourceSelectButton *self = GIMP_RESOURCE_SELECT_BUTTON (object);
|
||||
GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self);
|
||||
|
||||
g_debug ("%s, id: %i", G_STRFUNC, property_id);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_TITLE:
|
||||
|
@ -499,18 +451,7 @@ gimp_resource_select_button_set_property (GObject *object,
|
|||
break;
|
||||
|
||||
case PROP_RESOURCE:
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
priv->resource = g_value_get_object (gvalue);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -519,14 +460,13 @@ gimp_resource_select_button_set_property (GObject *object,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gimp_resource_select_button_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
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);
|
||||
|
||||
switch (property_id)
|
||||
|
@ -562,31 +502,27 @@ gimp_resource_select_button_callback (GimpResource *resource,
|
|||
GimpResourceSelectButton *self = GIMP_RESOURCE_SELECT_BUTTON (user_data);
|
||||
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;
|
||||
|
||||
/* Feedback user choice of resource into the look of the widget interior.
|
||||
* 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)
|
||||
priv->temp_callback_from_remote_dialog = NULL;
|
||||
|
||||
g_signal_emit (self, resource_button_signals[RESOURCE_SET], 0, resource, dialog_closing);
|
||||
g_object_notify_by_pspec (G_OBJECT (self), resource_button_props[PROP_RESOURCE]);
|
||||
g_signal_emit (self, resource_button_signals[RESOURCE_SET], 0,
|
||||
resource, dialog_closing);
|
||||
g_object_notify_by_pspec (G_OBJECT (self),
|
||||
resource_button_props[PROP_RESOURCE]);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gimp_resource_select_button_clicked (GimpResourceSelectButton *self)
|
||||
{
|
||||
GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self);
|
||||
GimpResourceSelectButtonClass *klass = GIMP_RESOURCE_SELECT_BUTTON_GET_CLASS (self);
|
||||
|
||||
g_debug ("%s called", G_STRFUNC);
|
||||
GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self);
|
||||
GimpResourceSelectButtonClass *klass = GIMP_RESOURCE_SELECT_BUTTON_GET_CLASS (self);
|
||||
|
||||
if (priv->temp_callback_from_remote_dialog)
|
||||
{
|
||||
|
@ -595,8 +531,6 @@ gimp_resource_select_button_clicked (GimpResourceSelectButton *self)
|
|||
}
|
||||
else
|
||||
{
|
||||
g_debug ("%s calling newer of remote dialog", G_STRFUNC);
|
||||
|
||||
/* Call GimpResourceSelect which dispatches on resource_type. */
|
||||
priv->temp_callback_from_remote_dialog =
|
||||
gimp_resource_select_new (priv->title,
|
||||
|
@ -606,7 +540,6 @@ gimp_resource_select_button_clicked (GimpResourceSelectButton *self)
|
|||
self,
|
||||
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;
|
||||
|
||||
g_debug ("%s called", G_STRFUNC);
|
||||
|
||||
klass = GIMP_RESOURCE_SELECT_BUTTON_GET_CLASS (self);
|
||||
/* Require class resource_type was initialized. */
|
||||
g_assert (klass->resource_type != 0);
|
||||
|
@ -655,10 +586,7 @@ gimp_resource_select_drag_data_received (GimpResourceSelectButton *self,
|
|||
gchar *name = str + name_offset;
|
||||
GimpResource *resource;
|
||||
|
||||
/* Create just a proxy object, not a new resource in core.
|
||||
* Create an instance of the type (e.g. GimpFont) that this class creates.
|
||||
*/
|
||||
resource = g_object_new (klass->resource_type, "id", name, NULL);
|
||||
resource = gimp_resource_get_by_name (klass->resource_type, name);
|
||||
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:
|
||||
* @self: A #GimpResourceSelectButton
|
||||
|
@ -701,8 +612,6 @@ gimp_resource_select_button_close_popup (GimpResourceSelectButton *self)
|
|||
{
|
||||
GimpResourceSelectButtonPrivate *priv;
|
||||
|
||||
g_debug ("%s", G_STRFUNC);
|
||||
|
||||
g_return_if_fail (GIMP_IS_RESOURCE_SELECT_BUTTON (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. */
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -25,42 +25,27 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* Inherits GtkBox
|
||||
* Inheritable by e.g. GimpBrushSelectButton.
|
||||
*/
|
||||
#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
|
||||
{
|
||||
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,
|
||||
GimpResource *resource,
|
||||
gboolean dialog_closing);
|
||||
|
||||
/* virtual methods. */
|
||||
void (*draw_interior) (GimpResourceSelectButton *self);
|
||||
|
||||
/* Specialized by subclass. */
|
||||
GType resource_type; /* e.g. GimpBrush */
|
||||
GType resource_type;
|
||||
|
||||
/* Padding for future expansion */
|
||||
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);
|
||||
void gimp_resource_select_button_set_resource (GimpResourceSelectButton *self,
|
||||
GimpResource *resource);
|
||||
|
|
|
@ -104,6 +104,7 @@ pdb_wrappers_sources = [
|
|||
'gimppatterns_pdb.c',
|
||||
'gimppatternselect_pdb.c',
|
||||
'gimpprogress_pdb.c',
|
||||
'gimpresource_pdb.c',
|
||||
'gimpselection_pdb.c',
|
||||
'gimptextlayer_pdb.c',
|
||||
'gimptexttool_pdb.c',
|
||||
|
@ -157,6 +158,7 @@ pdb_wrappers_headers = [
|
|||
'gimppatterns_pdb.h',
|
||||
'gimppatternselect_pdb.h',
|
||||
'gimpprogress_pdb.h',
|
||||
'gimpresource_pdb.h',
|
||||
'gimpselection_pdb.h',
|
||||
'gimptextlayer_pdb.h',
|
||||
'gimptexttool_pdb.h',
|
||||
|
@ -188,7 +190,6 @@ libgimp_sources_introspectable = [
|
|||
'gimpprogress.c',
|
||||
'gimpresource.c',
|
||||
'gimpresourceselect.c',
|
||||
'gimpresource-subclass.c',
|
||||
'gimpsaveprocedure.c',
|
||||
'gimpselection.c',
|
||||
'gimptextlayer.c',
|
||||
|
@ -243,7 +244,6 @@ libgimp_headers_introspectable = [
|
|||
'gimpprogress.h',
|
||||
'gimpresource.h',
|
||||
'gimpresourceselect.h',
|
||||
'gimpresource-subclass.h',
|
||||
'gimpsaveprocedure.h',
|
||||
'gimpselection.h',
|
||||
'gimptextlayer.h',
|
||||
|
@ -413,8 +413,7 @@ libgimp_introspectable_files = [
|
|||
libgimpconfig_introspectable,
|
||||
libgimpmath_introspectable,
|
||||
libgimpmodule_introspectable,
|
||||
'gimpparamspecs-body.c',
|
||||
'gimpparamspecs-body-resource.c',
|
||||
'gimpparamspecs-body.c'
|
||||
]
|
||||
|
||||
libgimpui_introspectable_files = [
|
||||
|
|
10
pdb/app.pl
10
pdb/app.pl
|
@ -237,6 +237,16 @@ gimp_param_spec_image ("$name",
|
|||
"$blurb",
|
||||
$none_ok,
|
||||
$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
|
||||
}
|
||||
elsif ($pdbtype eq 'brush') {
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
plug_in
|
||||
plug_in_compat
|
||||
progress
|
||||
resource
|
||||
selection
|
||||
text_layer
|
||||
text_tool
|
||||
|
|
|
@ -40,10 +40,37 @@ sub brush_new {
|
|||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
brush = (GimpBrush*) gimp_data_factory_data_new (gimp->brush_factory,
|
||||
context, name);
|
||||
brush = (GimpBrush *) gimp_data_factory_data_new (gimp->brush_factory,
|
||||
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;
|
||||
}
|
||||
CODE
|
||||
|
@ -71,7 +98,7 @@ sub brush_duplicate {
|
|||
{
|
||||
brush_copy = (GimpBrush *)
|
||||
gimp_data_factory_data_duplicate (gimp->brush_factory, GIMP_DATA (brush));
|
||||
/* Assert the copy has a unique name. */
|
||||
|
||||
if (!brush_copy)
|
||||
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 {
|
||||
$blurb = "Whether the brush is generated (parametric versus raster).";
|
||||
$help = "Returns TRUE when brush is parametric.";
|
||||
|
@ -891,9 +884,9 @@ CODE
|
|||
"gimppdb-utils.h");
|
||||
|
||||
@procs = qw(brush_new
|
||||
brush_get_by_name
|
||||
brush_duplicate
|
||||
brush_is_generated
|
||||
brush_id_is_valid
|
||||
brush_rename
|
||||
brush_delete
|
||||
brush_is_editable
|
||||
|
|
|
@ -19,44 +19,38 @@
|
|||
# The invoke code is compiled on the app side.
|
||||
# The invoke code must assign to each result var
|
||||
|
||||
sub font_id_is_valid {
|
||||
$blurb = "Whether the ID is a valid reference to installed data.";
|
||||
$help = "Returns TRUE if this ID is valid.";
|
||||
sub font_get_by_name {
|
||||
$blurb = "Returns the font with the given name.";
|
||||
$help = "Returns the font with the given name.";
|
||||
|
||||
&bootchk_pdb_misc('2022', '3.0');
|
||||
&mitch_pdb_misc('2023', '3.0');
|
||||
|
||||
@inargs = (
|
||||
{ name => 'id',
|
||||
type => 'string',
|
||||
non_empty => 1,
|
||||
no_validate => 1,
|
||||
desc => 'The font ID' }
|
||||
{ name => 'name', type => 'string', non_empty => 1,
|
||||
desc => 'The name of the font' }
|
||||
);
|
||||
|
||||
@outargs = (
|
||||
{ name => 'valid', type => 'boolean',
|
||||
desc => 'TRUE if the font ID is valid' }
|
||||
{ name => 'font', type => 'font', non_empty => 1,
|
||||
desc => 'The font' }
|
||||
);
|
||||
|
||||
%invoke = (
|
||||
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.
|
||||
* Clear error so GIMP not display error dialog.
|
||||
*/
|
||||
g_clear_error (error);
|
||||
if (! font)
|
||||
success = FALSE;
|
||||
}
|
||||
CODE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@headers = qw("core/gimp.h"
|
||||
"gimppdb-utils.h");
|
||||
|
||||
@procs = qw(font_id_is_valid);
|
||||
@procs = qw(font_get_by_name);
|
||||
|
||||
%exports = (app => [@procs], lib => [@procs]);
|
||||
|
||||
|
|
|
@ -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 {
|
||||
$blurb = 'Duplicates a gradient';
|
||||
$help = 'Returns a copy having a different, unique ID';
|
||||
|
@ -89,47 +116,14 @@ sub gradient_duplicate {
|
|||
{
|
||||
gradient_copy = (GimpGradient *)
|
||||
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;
|
||||
}
|
||||
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 {
|
||||
$blurb = 'Tests if gradient can be edited';
|
||||
$help = 'Returns TRUE if you have permission to change the gradient';
|
||||
|
@ -155,18 +149,8 @@ CODE
|
|||
}
|
||||
|
||||
sub gradient_rename {
|
||||
$blurb = "Renames a gradient. When the name is in use, renames to a unique name.";
|
||||
$help = <<'HELP';
|
||||
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
|
||||
$blurb = "Renames a gradient. When the name is in use, renames to a unique name.";
|
||||
$help = 'Renames a gradient.';
|
||||
|
||||
&shlomi_pdb_misc('2003', '2.2');
|
||||
|
||||
|
@ -185,16 +169,9 @@ HELP
|
|||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
/* Rename the gradient in app. */
|
||||
gimp_object_set_name (GIMP_OBJECT (gradient), new_name);
|
||||
/* Assert GIMP might have set a name different from new_name. */
|
||||
|
||||
/* Return a reference.
|
||||
* 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;
|
||||
gradient_renamed = gradient;
|
||||
}
|
||||
CODE
|
||||
);
|
||||
|
@ -1389,6 +1366,7 @@ CODE
|
|||
"gimppdb-utils.h");
|
||||
|
||||
@procs = qw(gradient_new
|
||||
gradient_get_by_name
|
||||
gradient_duplicate
|
||||
gradient_is_editable
|
||||
gradient_rename
|
||||
|
@ -1396,7 +1374,6 @@ CODE
|
|||
gradient_get_number_of_segments
|
||||
gradient_get_uniform_samples
|
||||
gradient_get_custom_samples
|
||||
gradient_id_is_valid
|
||||
gradient_segment_get_left_color gradient_segment_set_left_color
|
||||
gradient_segment_get_right_color gradient_segment_set_right_color
|
||||
gradient_segment_get_left_pos gradient_segment_set_left_pos
|
||||
|
|
|
@ -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 {
|
||||
$blurb = "Whether the palette can be edited";
|
||||
$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 {
|
||||
$blurb = "Rename a palette";
|
||||
$help = <<'HELP';
|
||||
|
@ -555,8 +550,8 @@ CODE
|
|||
"gimppdb-utils.h");
|
||||
|
||||
@procs = qw(palette_new
|
||||
palette_get_by_name
|
||||
palette_duplicate
|
||||
palette_id_is_valid
|
||||
palette_rename
|
||||
palette_delete
|
||||
palette_is_editable
|
||||
|
|
|
@ -24,6 +24,34 @@ $pattern_arg_spec = { name => 'pattern', type => 'pattern', non_empty => 1,
|
|||
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 {
|
||||
$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>
|
||||
"gegl/gimp-babl-compat.h"
|
||||
|
@ -156,9 +150,9 @@ CODE
|
|||
"core/gimptempbuf.h"
|
||||
"gimppdb-utils.h");
|
||||
|
||||
@procs = qw(pattern_get_info
|
||||
pattern_get_pixels
|
||||
pattern_id_is_valid);
|
||||
@procs = qw(pattern_get_by_name
|
||||
pattern_get_info
|
||||
pattern_get_pixels);
|
||||
|
||||
%exports = (app => [@procs], lib => [@procs]);
|
||||
|
||||
|
|
|
@ -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;
|
|
@ -50,6 +50,7 @@ pdb_names = [
|
|||
'plug_in_compat',
|
||||
'plug_in',
|
||||
'progress',
|
||||
'resource',
|
||||
'selection',
|
||||
'text_layer',
|
||||
'text_tool',
|
||||
|
|
39
pdb/pdb.pl
39
pdb/pdb.pl
|
@ -414,7 +414,18 @@ package Gimp::CodeGen::pdb;
|
|||
set_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',
|
||||
gtype => 'GIMP_TYPE_BRUSH',
|
||||
type => 'GimpBrush *',
|
||||
|
@ -427,18 +438,18 @@ package Gimp::CodeGen::pdb;
|
|||
take_value_func => 'g_value_set_object ($value, $var)',
|
||||
headers => [ qw("core/gimpbrush.h") ] },
|
||||
|
||||
# !!! include file /app/text/gimpfont.h
|
||||
font => { name => 'FONT',
|
||||
gtype => 'GIMP_TYPE_FONT',
|
||||
type => 'GimpFont *',
|
||||
const_type => 'GimpFont *',
|
||||
|
||||
pattern => { name => 'PATTERN',
|
||||
gtype => 'GIMP_TYPE_PATTERN',
|
||||
type => 'GimpPattern *',
|
||||
const_type => 'GimpPattern *',
|
||||
init_value => 'NULL',
|
||||
out_annotate => '(transfer full)',
|
||||
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)',
|
||||
take_value_func => 'g_value_set_object ($value, $var)',
|
||||
headers => [ qw("text/gimpfont.h") ] },
|
||||
headers => [ qw("core/gimppattern.h") ] },
|
||||
|
||||
gradient => { name => 'GRADIENT',
|
||||
gtype => 'GIMP_TYPE_GRADIENT',
|
||||
|
@ -464,17 +475,17 @@ package Gimp::CodeGen::pdb;
|
|||
take_value_func => 'g_value_set_object ($value, $var)',
|
||||
headers => [ qw("core/gimppalette.h") ] },
|
||||
|
||||
pattern => { name => 'PATTERN',
|
||||
gtype => 'GIMP_TYPE_PATTERN',
|
||||
type => 'GimpPattern *',
|
||||
const_type => 'GimpPattern *',
|
||||
font => { name => 'FONT',
|
||||
gtype => 'GIMP_TYPE_FONT',
|
||||
type => 'GimpFont *',
|
||||
const_type => 'GimpFont *',
|
||||
init_value => 'NULL',
|
||||
out_annotate => '(transfer full)',
|
||||
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)',
|
||||
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
|
||||
|
|
|
@ -744,8 +744,7 @@ draw_number (GimpLayer *layer,
|
|||
GimpFont *font = filmvals.number_font;
|
||||
gchar *fontname;
|
||||
|
||||
/* FIXME: gimp_text methods should take GimpFont font instead of font_name */
|
||||
g_object_get (font, "id", &fontname, NULL);
|
||||
fontname = gimp_resource_get_name (GIMP_RESOURCE (font));
|
||||
|
||||
g_snprintf (buf, sizeof (buf), "%d", num);
|
||||
|
||||
|
@ -1428,7 +1427,7 @@ film_load_settings (void)
|
|||
* Restore pointer from the name which was also serialized.
|
||||
* 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
|
||||
|
@ -1436,7 +1435,7 @@ film_save_settings (void)
|
|||
{
|
||||
/* Copy font name from font, i.e. serialize string not pointer. */
|
||||
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);
|
||||
|
||||
gimp_set_data (PLUG_IN_PROC, &filmvals, sizeof (FilmVals));
|
||||
|
|
|
@ -82,28 +82,20 @@ gfig_read_resource (gchar **text,
|
|||
ptr++;
|
||||
if (!strcmp (tmpstr, tag))
|
||||
{
|
||||
/* Create a resource object, just a proxy for the thing in core. */
|
||||
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.
|
||||
*/
|
||||
const gchar *resource_name = g_strchug (ptr);
|
||||
|
||||
*style_entry = gimp_resource_get_by_name (resource_type,
|
||||
resource_name);
|
||||
g_free (tmpstr);
|
||||
return;
|
||||
}
|
||||
|
||||
g_free (tmpstr);
|
||||
}
|
||||
|
||||
++n;
|
||||
}
|
||||
|
||||
/* Fail */
|
||||
*style_entry = NULL;
|
||||
g_message ("Parameter '%s' not found", tag);
|
||||
}
|
||||
|
@ -374,11 +366,11 @@ gfig_save_style (Style *style,
|
|||
|
||||
if (gfig_context->debug_styles)
|
||||
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, "BrushName: %s\n",
|
||||
gimp_resource_get_id (GIMP_RESOURCE (style->brush)));
|
||||
gimp_resource_get_name (GIMP_RESOURCE (style->brush)));
|
||||
if (!style->brush)
|
||||
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_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",
|
||||
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_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. */
|
||||
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? */
|
||||
|
||||
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))
|
||||
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);
|
||||
|
||||
gimp_context_set_brush_default_size ();
|
||||
|
|
|
@ -5057,15 +5057,13 @@ gradient_get_values_real_external (const gchar *gradient_name,
|
|||
gint nvalues,
|
||||
gboolean reverse)
|
||||
{
|
||||
gint n_tmp_values;
|
||||
gdouble *tmp_values;
|
||||
gint i;
|
||||
gint j;
|
||||
|
||||
GimpGradient *gradient;
|
||||
gint n_tmp_values;
|
||||
gdouble *tmp_values;
|
||||
gint i;
|
||||
gint j;
|
||||
|
||||
/* New proxy for gradient. */
|
||||
gradient = g_object_new (GIMP_TYPE_GRADIENT, "id", gradient_name, NULL);
|
||||
gradient = gimp_gradient_get_by_name (gradient_name);
|
||||
|
||||
gimp_gradient_get_uniform_samples (gradient, nvalues, reverse,
|
||||
&n_tmp_values, &tmp_values);
|
||||
|
|
|
@ -188,8 +188,8 @@ marshal_returned_object_array_to_vector (scheme *sc,
|
|||
*/
|
||||
for (int j = n - 1; j >= 0; j--)
|
||||
{
|
||||
gint id;
|
||||
GObject *object = object_array[j];
|
||||
gint id;
|
||||
|
||||
if (object)
|
||||
g_object_get (object, "id", &id, NULL); /* get property "id" */
|
||||
|
|
|
@ -1256,23 +1256,17 @@ script_fu_marshal_procedure_call (scheme *sc,
|
|||
}
|
||||
else if (GIMP_VALUE_HOLDS_RESOURCE (&value))
|
||||
{
|
||||
GType type = G_VALUE_TYPE (&value);
|
||||
|
||||
if (! sc->vptr->is_string (sc->vptr->pair_car (a)))
|
||||
return script_type_error (sc, "string", i, proc_name);
|
||||
else
|
||||
{
|
||||
/* Create new instance of a resource object. */
|
||||
GimpResource *resource;
|
||||
gchar* id = sc->vptr->string_value (sc->vptr->pair_car (a));
|
||||
|
||||
resource = g_object_new (type, NULL);
|
||||
|
||||
g_object_set (resource, "id", id, NULL);
|
||||
/* Assert set property copies the string. */
|
||||
GType type = G_VALUE_TYPE (&value);
|
||||
const gchar *name = sc->vptr->string_value (sc->vptr->pair_car (a));
|
||||
resource = gimp_resource_get_by_name (type, name);
|
||||
|
||||
g_value_set_object (&value, resource);
|
||||
/* Assert set_object refs the resource. */
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1397,26 +1391,18 @@ script_fu_marshal_procedure_call (scheme *sc,
|
|||
{
|
||||
/* ScriptFu represents resource objects by ther unique string ID's. */
|
||||
GObject *object = g_value_get_object (value);
|
||||
gchar *id = "";
|
||||
gchar *name = NULL;
|
||||
|
||||
/* expect a GIMP opaque object having an "id" property */
|
||||
if (object)
|
||||
{
|
||||
g_object_get (object, "id", &id, NULL);
|
||||
g_object_unref (object);
|
||||
}
|
||||
name = gimp_resource_get_name (GIMP_RESOURCE(object));
|
||||
|
||||
/* id is empty when the gvalue had no GObject*,
|
||||
* or the referenced object had no property "id".
|
||||
* 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.");
|
||||
if (! name)
|
||||
g_warning("PDB procedure returned NULL 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))
|
||||
{
|
||||
|
@ -1438,7 +1424,7 @@ script_fu_marshal_procedure_call (scheme *sc,
|
|||
* It is not necessarily an error in the script.
|
||||
*/
|
||||
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);
|
||||
|
||||
|
|
|
@ -586,24 +586,16 @@ script_fu_arg_append_repr_from_gvalue (SFArg *arg,
|
|||
case SF_GRADIENT:
|
||||
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;
|
||||
gchar *resource_name;
|
||||
|
||||
/* !!! 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 ));
|
||||
gchar *name = NULL;
|
||||
|
||||
resource = g_value_get_object (gvalue);
|
||||
|
||||
g_object_get (resource, "id", &resource_name, NULL);
|
||||
g_string_append_printf (result_string, "\"%s\"", resource_name);
|
||||
if (resource)
|
||||
name = gimp_resource_get_name (resource);
|
||||
|
||||
g_string_append_printf (result_string, "\"%s\"", name);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -602,42 +602,25 @@ script_fu_resource_widget (const gchar *title,
|
|||
GtkWidget *result_widget = NULL;
|
||||
GimpResource *resource;
|
||||
|
||||
/* New resource instance, from string *id_handle. */
|
||||
resource = g_object_new (resource_type, "id", *id_handle, NULL);
|
||||
resource = gimp_resource_get_by_name (resource_type, *id_handle);
|
||||
|
||||
/* If not valid, substitute NULL
|
||||
* String provided by script author might not name an installed font.
|
||||
*/
|
||||
/*
|
||||
if ( ! gimp_resource_is_valid (resource) )
|
||||
if (g_type_is_a (resource_type, GIMP_TYPE_FONT))
|
||||
{
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@ -737,7 +720,7 @@ script_fu_resource_set_handler (gpointer data, /* callback "data" */
|
|||
g_free (*id_handle);
|
||||
|
||||
/* 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 ();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue