This fixes all our GObject Introspection issues with GimpUnit which was both an enum and an int-derived type of user-defined units *completing* the enum values. GIR clearly didn't like this! Now GimpUnit is a proper class and units are unique objects, allowing to compare them with an identity test (i.e. `unit == gimp_unit_pixel ()` tells us if unit is the pixel unit or not), which makes it easy to use, just like with int, yet adding also methods, making for nicer introspected API. As an aside, this also fixes #10738, by having all the built-in units retrievable even if libgimpbase had not been properly initialized with gimp_base_init(). I haven't checked in details how GIR works to introspect, but it looks like it loads the library to inspect and runs functions, hence triggering some CRITICALS because virtual methods (supposed to be initialized with gimp_base_init() run by libgimp) are not set. This new code won't trigger any critical because the vtable method are now not necessary, at least for all built-in units. Note that GimpUnit is still in libgimpbase. It could have been moved to libgimp in order to avoid any virtual method table (since we need to keep core and libgimp side's units in sync, PDB is required), but too many libgimpwidgets widgets were already using GimpUnit. And technically most of GimpUnit logic doesn't require PDB (only the creation/sync part). This is one of the reasons why user-created GimpUnit list is handled and stored differently from other types of objects. Globally this simplifies the code a lot too and we don't need separate implementations of various utils for core and libgimp, which means less prone to errors.
403 lines
19 KiB
C
403 lines
19 KiB
C
/* 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 "libgimpbase/gimpbase.h"
|
|
|
|
#include "pdb-types.h"
|
|
|
|
#include "core/gimp.h"
|
|
#include "core/gimpparamspecs.h"
|
|
#include "core/gimpunit.h"
|
|
|
|
#include "gimppdb.h"
|
|
#include "gimpprocedure.h"
|
|
#include "internal-procs.h"
|
|
|
|
|
|
static GimpValueArray *
|
|
unit_new_invoker (GimpProcedure *procedure,
|
|
Gimp *gimp,
|
|
GimpContext *context,
|
|
GimpProgress *progress,
|
|
const GimpValueArray *args,
|
|
GError **error)
|
|
{
|
|
gboolean success = TRUE;
|
|
GimpValueArray *return_vals;
|
|
const gchar *identifier;
|
|
gdouble factor;
|
|
gint digits;
|
|
const gchar *symbol;
|
|
const gchar *abbreviation;
|
|
const gchar *singular;
|
|
const gchar *plural;
|
|
GimpUnit *unit = NULL;
|
|
|
|
identifier = g_value_get_string (gimp_value_array_index (args, 0));
|
|
factor = g_value_get_double (gimp_value_array_index (args, 1));
|
|
digits = g_value_get_int (gimp_value_array_index (args, 2));
|
|
symbol = g_value_get_string (gimp_value_array_index (args, 3));
|
|
abbreviation = g_value_get_string (gimp_value_array_index (args, 4));
|
|
singular = g_value_get_string (gimp_value_array_index (args, 5));
|
|
plural = g_value_get_string (gimp_value_array_index (args, 6));
|
|
|
|
if (success)
|
|
{
|
|
unit = _gimp_unit_new (gimp, identifier, factor, digits,
|
|
symbol, abbreviation, singular, plural);
|
|
}
|
|
|
|
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), unit);
|
|
|
|
return return_vals;
|
|
}
|
|
|
|
static GimpValueArray *
|
|
unit_get_data_invoker (GimpProcedure *procedure,
|
|
Gimp *gimp,
|
|
GimpContext *context,
|
|
GimpProgress *progress,
|
|
const GimpValueArray *args,
|
|
GError **error)
|
|
{
|
|
gboolean success = TRUE;
|
|
GimpValueArray *return_vals;
|
|
gint unit_id;
|
|
gchar *identifier = NULL;
|
|
gdouble factor = 0.0;
|
|
gint digits = 0;
|
|
gchar *symbol = NULL;
|
|
gchar *abbreviation = NULL;
|
|
gchar *singular = NULL;
|
|
gchar *plural = NULL;
|
|
|
|
unit_id = g_value_get_int (gimp_value_array_index (args, 0));
|
|
|
|
if (success)
|
|
{
|
|
if (unit_id >= 0)
|
|
{
|
|
GimpUnit *unit = gimp_unit_get_by_id (unit_id);
|
|
|
|
if (unit != NULL)
|
|
{
|
|
identifier = g_strdup (gimp_unit_get_identifier (unit));
|
|
factor = gimp_unit_get_factor (unit);
|
|
digits = gimp_unit_get_digits (unit);
|
|
symbol = g_strdup (gimp_unit_get_symbol (unit));
|
|
abbreviation = g_strdup (gimp_unit_get_abbreviation (unit));
|
|
singular = g_strdup (gimp_unit_get_singular (unit));
|
|
plural = g_strdup (gimp_unit_get_plural (unit));
|
|
}
|
|
}
|
|
}
|
|
|
|
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), identifier);
|
|
g_value_set_double (gimp_value_array_index (return_vals, 2), factor);
|
|
g_value_set_int (gimp_value_array_index (return_vals, 3), digits);
|
|
g_value_take_string (gimp_value_array_index (return_vals, 4), symbol);
|
|
g_value_take_string (gimp_value_array_index (return_vals, 5), abbreviation);
|
|
g_value_take_string (gimp_value_array_index (return_vals, 6), singular);
|
|
g_value_take_string (gimp_value_array_index (return_vals, 7), plural);
|
|
}
|
|
|
|
return return_vals;
|
|
}
|
|
|
|
static GimpValueArray *
|
|
unit_get_deletion_flag_invoker (GimpProcedure *procedure,
|
|
Gimp *gimp,
|
|
GimpContext *context,
|
|
GimpProgress *progress,
|
|
const GimpValueArray *args,
|
|
GError **error)
|
|
{
|
|
gboolean success = TRUE;
|
|
GimpValueArray *return_vals;
|
|
GimpUnit *unit;
|
|
gboolean deletion_flag = FALSE;
|
|
|
|
unit = g_value_get_object (gimp_value_array_index (args, 0));
|
|
|
|
if (success)
|
|
{
|
|
deletion_flag = gimp_unit_get_deletion_flag (unit);
|
|
}
|
|
|
|
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), deletion_flag);
|
|
|
|
return return_vals;
|
|
}
|
|
|
|
static GimpValueArray *
|
|
unit_set_deletion_flag_invoker (GimpProcedure *procedure,
|
|
Gimp *gimp,
|
|
GimpContext *context,
|
|
GimpProgress *progress,
|
|
const GimpValueArray *args,
|
|
GError **error)
|
|
{
|
|
gboolean success = TRUE;
|
|
GimpUnit *unit;
|
|
gboolean deletion_flag;
|
|
|
|
unit = g_value_get_object (gimp_value_array_index (args, 0));
|
|
deletion_flag = g_value_get_boolean (gimp_value_array_index (args, 1));
|
|
|
|
if (success)
|
|
{
|
|
gimp_unit_set_deletion_flag (unit, deletion_flag);
|
|
}
|
|
|
|
return gimp_procedure_get_return_values (procedure, success,
|
|
error ? *error : NULL);
|
|
}
|
|
|
|
void
|
|
register_unit_procs (GimpPDB *pdb)
|
|
{
|
|
GimpProcedure *procedure;
|
|
|
|
/*
|
|
* gimp-unit-new
|
|
*/
|
|
procedure = gimp_procedure_new (unit_new_invoker);
|
|
gimp_object_set_static_name (GIMP_OBJECT (procedure),
|
|
"gimp-unit-new");
|
|
gimp_procedure_set_static_help (procedure,
|
|
"Creates a new unit.",
|
|
"This procedure creates a new unit and returns it. Note that the new unit will have it's deletion flag set to TRUE, so you will have to set it to FALSE with 'gimp-unit-set-deletion-flag' to make it persistent.",
|
|
NULL);
|
|
gimp_procedure_set_static_attribution (procedure,
|
|
"Michael Natterer <mitch@gimp.org>",
|
|
"Michael Natterer",
|
|
"1999");
|
|
gimp_procedure_add_argument (procedure,
|
|
gimp_param_spec_string ("identifier",
|
|
"identifier",
|
|
"The new unit's identifier",
|
|
FALSE, FALSE, TRUE,
|
|
NULL,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_argument (procedure,
|
|
g_param_spec_double ("factor",
|
|
"factor",
|
|
"The new unit's factor",
|
|
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_argument (procedure,
|
|
g_param_spec_int ("digits",
|
|
"digits",
|
|
"The new unit's digits",
|
|
G_MININT32, G_MAXINT32, 0,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_argument (procedure,
|
|
gimp_param_spec_string ("symbol",
|
|
"symbol",
|
|
"The new unit's symbol",
|
|
FALSE, FALSE, TRUE,
|
|
NULL,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_argument (procedure,
|
|
gimp_param_spec_string ("abbreviation",
|
|
"abbreviation",
|
|
"The new unit's abbreviation",
|
|
FALSE, FALSE, TRUE,
|
|
NULL,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_argument (procedure,
|
|
gimp_param_spec_string ("singular",
|
|
"singular",
|
|
"The new unit's singular form",
|
|
FALSE, FALSE, TRUE,
|
|
NULL,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_argument (procedure,
|
|
gimp_param_spec_string ("plural",
|
|
"plural",
|
|
"The new unit's plural form",
|
|
FALSE, FALSE, TRUE,
|
|
NULL,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_return_value (procedure,
|
|
gimp_param_spec_unit ("unit",
|
|
"unit",
|
|
"The new unit",
|
|
FALSE,
|
|
FALSE,
|
|
gimp_unit_inch (),
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_pdb_register_procedure (pdb, procedure);
|
|
g_object_unref (procedure);
|
|
|
|
/*
|
|
* gimp-unit-get-data
|
|
*/
|
|
procedure = gimp_procedure_new (unit_get_data_invoker);
|
|
gimp_object_set_static_name (GIMP_OBJECT (procedure),
|
|
"gimp-unit-get-data");
|
|
gimp_procedure_set_static_help (procedure,
|
|
"Returns the various data pertaining to a given unit ID.",
|
|
"This procedure returns all properties making up an unit. It is only meant for internal usage to query non built-in units and it is a programming error to use it directly, in particular for any of the built-in units.",
|
|
NULL);
|
|
gimp_procedure_set_static_attribution (procedure,
|
|
"Jehan",
|
|
"Jehan",
|
|
"2023");
|
|
gimp_procedure_add_argument (procedure,
|
|
g_param_spec_int ("unit-id",
|
|
"unit id",
|
|
"The unit's integer ID",
|
|
G_MININT32, G_MAXINT32, 0,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_return_value (procedure,
|
|
gimp_param_spec_string ("identifier",
|
|
"identifier",
|
|
"The unit's textual identifier",
|
|
FALSE, FALSE, FALSE,
|
|
NULL,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_return_value (procedure,
|
|
g_param_spec_double ("factor",
|
|
"factor",
|
|
"The unit's factor",
|
|
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_return_value (procedure,
|
|
g_param_spec_int ("digits",
|
|
"digits",
|
|
"The unit's number of digits",
|
|
G_MININT32, G_MAXINT32, 0,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_return_value (procedure,
|
|
gimp_param_spec_string ("symbol",
|
|
"symbol",
|
|
"The unit's symbol",
|
|
FALSE, FALSE, FALSE,
|
|
NULL,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_return_value (procedure,
|
|
gimp_param_spec_string ("abbreviation",
|
|
"abbreviation",
|
|
"The unit's abbreviation",
|
|
FALSE, FALSE, FALSE,
|
|
NULL,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_return_value (procedure,
|
|
gimp_param_spec_string ("singular",
|
|
"singular",
|
|
"The unit's singular form",
|
|
FALSE, FALSE, FALSE,
|
|
NULL,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_return_value (procedure,
|
|
gimp_param_spec_string ("plural",
|
|
"plural",
|
|
"The unit's plural form",
|
|
FALSE, FALSE, FALSE,
|
|
NULL,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_pdb_register_procedure (pdb, procedure);
|
|
g_object_unref (procedure);
|
|
|
|
/*
|
|
* gimp-unit-get-deletion-flag
|
|
*/
|
|
procedure = gimp_procedure_new (unit_get_deletion_flag_invoker);
|
|
gimp_object_set_static_name (GIMP_OBJECT (procedure),
|
|
"gimp-unit-get-deletion-flag");
|
|
gimp_procedure_set_static_help (procedure,
|
|
"Returns the deletion flag of the unit.",
|
|
"This procedure returns the deletion flag of the unit. If this value is TRUE the unit's definition will not be saved in the user's unitrc file on gimp exit.",
|
|
NULL);
|
|
gimp_procedure_set_static_attribution (procedure,
|
|
"Michael Natterer <mitch@gimp.org>",
|
|
"Michael Natterer",
|
|
"1999");
|
|
gimp_procedure_add_argument (procedure,
|
|
gimp_param_spec_unit ("unit",
|
|
"unit",
|
|
"The unit",
|
|
FALSE,
|
|
FALSE,
|
|
gimp_unit_inch (),
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_return_value (procedure,
|
|
g_param_spec_boolean ("deletion-flag",
|
|
"deletion flag",
|
|
"The unit's deletion flag",
|
|
FALSE,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_pdb_register_procedure (pdb, procedure);
|
|
g_object_unref (procedure);
|
|
|
|
/*
|
|
* gimp-unit-set-deletion-flag
|
|
*/
|
|
procedure = gimp_procedure_new (unit_set_deletion_flag_invoker);
|
|
gimp_object_set_static_name (GIMP_OBJECT (procedure),
|
|
"gimp-unit-set-deletion-flag");
|
|
gimp_procedure_set_static_help (procedure,
|
|
"Sets the deletion flag of a unit.",
|
|
"This procedure sets the unit's deletion flag. If the deletion flag of a unit is TRUE on gimp exit, this unit's definition will not be saved in the user's unitrc.",
|
|
NULL);
|
|
gimp_procedure_set_static_attribution (procedure,
|
|
"Michael Natterer <mitch@gimp.org>",
|
|
"Michael Natterer",
|
|
"1999");
|
|
gimp_procedure_add_argument (procedure,
|
|
gimp_param_spec_unit ("unit",
|
|
"unit",
|
|
"The unit",
|
|
FALSE,
|
|
FALSE,
|
|
gimp_unit_inch (),
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_procedure_add_argument (procedure,
|
|
g_param_spec_boolean ("deletion-flag",
|
|
"deletion flag",
|
|
"The new deletion flag of the unit",
|
|
FALSE,
|
|
GIMP_PARAM_READWRITE));
|
|
gimp_pdb_register_procedure (pdb, procedure);
|
|
g_object_unref (procedure);
|
|
}
|