gimp/app/config/gimpconfig-params.c

550 lines
14 KiB
C
Raw Normal View History

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* ParamSpecs for config objects
* Copyright (C) 2001-2003 Sven Neumann <sven@gimp.org>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib-object.h>
devel-docs/Makefile.am new file documenting the core's include policy. 2002-05-03 Michael Natterer <mitch@gimp.org> * devel-docs/Makefile.am * devel-docs/includes.txt: new file documenting the core's include policy. * HACKING: mention it here. * libgimptool/gimptooltypes.h: removed GimpToolOptions here. * app/core/core-types.h: and added it here. This is a temp hack needed because GimpToolInfo needs to know the GimpToolOptions type. * libgimpproxy/gimpproxytypes.h: regenerated. * libgimptool/gimptoolmodule.h: don't include gimptooltypes.h here... * libgimptool/gimptoolmodule.c: ...but here. * app/config/gimpconfig-params.c: include "libgimpbase/gimpbase.h" entirely, not single files from it. * app/core/gimp.c * app/core/gimpcontext.c * app/core/gimpcoreconfig.c * app/core/gimpdatafactory.c * app/core/gimpdocuments.c * app/core/gimpdrawable-blend.c * app/core/gimpdrawable-bucket-fill.c * app/core/gimpdrawable-offset.c * app/core/gimpdrawable-transform.c * app/core/gimpdrawable.c * app/core/gimpedit.c * app/core/gimpimage-convert.c * app/core/gimpimage-crop.c * app/core/gimpimage-duplicate.c * app/core/gimpimage-guides.c * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimpimage-new.c * app/core/gimpimage-projection.c * app/core/gimpimage-qmask.c * app/core/gimpimage-resize.c * app/core/gimpimage-scale.c * app/core/gimpimage.c * app/core/gimpitem.c * app/core/gimpmodules.c * app/core/gimppaintinfo.c * app/core/gimpparasite.c * app/core/gimppreviewcache.c * app/core/gimptoolinfo.c * app/core/gimpunit.c: include "core-types.h" and no other types file. * app/display/gimpdisplay.c * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell.c: include "tools/tools-types.h" instead of "libgimptool/gimptooltypes.h", warn about inclusion on "gui/gui-types.h" * app/file/file-open.c * app/file/file-save.c: don't include "libgimptool/gimptooltypes.h". * app/gui/about-dialog.c * app/gui/brush-select.c * app/gui/brushes-commands.c * app/gui/color-select.c * app/gui/data-commands.c * app/gui/device-status-dialog.c * app/gui/dialogs.c * app/gui/gradients-commands.c * app/gui/help-commands.c * app/gui/info-window.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/resize-dialog.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c: include "gui-types.h" and no other types file. * app/paint/gimpairbrush.c * app/paint/gimpclone.c * app/paint/gimpconvolve.c * app/paint/gimpdodgeburn.c * app/paint/gimperaser.c * app/paint/gimppaintbrush.c * app/paint/gimppaintcore-stroke.c * app/paint/gimppaintcore.c * app/paint/gimppaintoptions.c * app/paint/gimppencil.c * app/paint/gimpsmudge.c * app/paint/paint.c: include "paint-types.h" and no other types file. * app/pdb/pdb-types.h: don't include "libgimptool/gimptooltypes.h". * app/plug-in/plug-in-progress.c: warn about inclusion of "display/display-types.h" * app/tools/tools-types.h: include "libgimptool/gimptooltypes.h". * app/tools/gimpairbrushtool.c * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpbycolorselecttool.c * app/tools/gimpclonetool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpconvolvetool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimpdodgeburntool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpellipseselecttool.c * app/tools/gimperasertool.c * app/tools/gimpfliptool.c * app/tools/gimpfreeselecttool.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpinktool.c * app/tools/gimplevelstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppaintbrushtool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimppenciltool.c * app/tools/gimpperspectivetool.c * app/tools/gimpposterizetool.c * app/tools/gimprectselecttool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpselectiontool.c * app/tools/gimpsheartool.c * app/tools/gimpsmudgetool.c * app/tools/gimptexttool.c * app/tools/gimpthresholdtool.c * app/tools/gimptoolcontrol.c * app/tools/gimptoolcontrol.h * app/tools/gimptransformtool.c * app/tools/gimpvectortool.c * app/tools/tools.c: include "tools-types.h" and no other types file, warn about inclusion of "gui/gui-types.h". * app/widgets/gimpcolorpanel.c * app/widgets/gimptoolbox-color-area.c: warn about inclusion of "gui/gui-types.h". * app/xcf/xcf-load.c * app/xcf/xcf.c: don't include "libgimptool/gimptooltypes.h". Split tool-safe-mode up in two files, one including libgimpproxy, one libgimp. * plug-ins/tools/Makefile.am * plug-ins/tools/tool-safe-mode-plug-in.[ch]: new files including libgimp/ stuff only. * plug-ins/tools/tool-safe-mode.[ch]: include libgimpproxy/ and libgimptool/ but don't include libgimp/ because of conflicting declarations. Unrelated: * app/tools/gimpclonetool.c: create the clone core so we don't crash. * app/gui/file-open-dialog.c: changed the way we create previews so that only out-of-date previews are created on a click in the preview area. Unconditional creation can still be forced by <Ctrl>+click. Changed the tooltip to document this.
2002-05-03 20:45:22 +08:00
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "config-types.h"
#include "gimpconfig-params.h"
#include "gimpconfig-types.h"
/*
* GIMP_TYPE_PARAM_COLOR
*/
#define GIMP_PARAM_SPEC_COLOR(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_COLOR, GimpParamSpecColor))
static void gimp_param_color_class_init (GParamSpecClass *class);
static void gimp_param_color_init (GParamSpec *pspec);
static void gimp_param_color_set_default (GParamSpec *pspec,
GValue *value);
static gboolean gimp_param_color_validate (GParamSpec *pspec,
GValue *value);
static gint gimp_param_color_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2);
typedef struct _GimpParamSpecColor GimpParamSpecColor;
struct _GimpParamSpecColor
{
GParamSpecBoxed parent_instance;
GimpRGB default_value;
};
GType
gimp_param_color_get_type (void)
{
static GType spec_type = 0;
if (!spec_type)
{
static const GTypeInfo type_info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_color_class_init,
NULL, NULL,
sizeof (GimpParamSpecColor),
0,
(GInstanceInitFunc) gimp_param_color_init
};
spec_type = g_type_register_static (G_TYPE_PARAM_BOXED,
"GimpParamColor",
&type_info, 0);
}
return spec_type;
}
static void
gimp_param_color_class_init (GParamSpecClass *class)
{
class->value_type = GIMP_TYPE_COLOR;
class->value_set_default = gimp_param_color_set_default;
class->value_validate = gimp_param_color_validate;
class->values_cmp = gimp_param_color_values_cmp;
}
static void
gimp_param_color_init (GParamSpec *pspec)
{
GimpParamSpecColor *cspec = GIMP_PARAM_SPEC_COLOR (pspec);
gimp_rgba_set (&cspec->default_value, 0.0, 0.0, 0.0, 0.0);
}
static void
gimp_param_color_set_default (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecColor *cspec = GIMP_PARAM_SPEC_COLOR (pspec);
g_value_set_static_boxed (value, &cspec->default_value);
}
static gboolean
gimp_param_color_validate (GParamSpec *pspec,
GValue *value)
{
GimpRGB *color;
color = value->data[0].v_pointer;
if (color)
{
GimpRGB oval;
oval = *color;
gimp_rgb_clamp (color);
return (oval.r != color->r ||
oval.g != color->g ||
oval.b != color->b ||
oval.a != color->a);
}
return FALSE;
}
static gint
gimp_param_color_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2)
{
GimpRGB *color1;
GimpRGB *color2;
color1 = value1->data[0].v_pointer;
color2 = value2->data[0].v_pointer;
/* try to return at least *something*, it's useless anyway... */
if (! color1)
return color2 != NULL ? -1 : 0;
else if (! color2)
return color1 != NULL;
else
{
guint32 int1, int2;
gimp_rgba_get_uchar (color1,
((guchar *) &int1) + 0,
((guchar *) &int1) + 1,
((guchar *) &int1) + 2,
((guchar *) &int1) + 3);
gimp_rgba_get_uchar (color2,
((guchar *) &int2) + 0,
((guchar *) &int2) + 1,
((guchar *) &int2) + 2,
((guchar *) &int2) + 3);
return int1 - int2;
}
}
GParamSpec *
gimp_param_spec_color (const gchar *name,
const gchar *nick,
const gchar *blurb,
const GimpRGB *default_value,
GParamFlags flags)
{
GimpParamSpecColor *cspec;
g_return_val_if_fail (default_value != NULL, NULL);
cspec = g_param_spec_internal (GIMP_TYPE_PARAM_COLOR,
name, nick, blurb, flags);
cspec->default_value = *default_value;
return G_PARAM_SPEC (cspec);
}
/*
* GIMP_TYPE_PARAM_MATRIX2
*/
#define GIMP_PARAM_SPEC_MATRIX2(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_MATRIX2, GimpParamSpecMatrix2))
static void gimp_param_matrix2_class_init (GParamSpecClass *class);
static void gimp_param_matrix2_init (GParamSpec *pspec);
static void gimp_param_matrix2_set_default (GParamSpec *pspec,
GValue *value);
static gint gimp_param_matrix2_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2);
typedef struct _GimpParamSpecMatrix2 GimpParamSpecMatrix2;
struct _GimpParamSpecMatrix2
{
GParamSpecBoxed parent_instance;
GimpMatrix2 default_value;
};
GType
gimp_param_matrix2_get_type (void)
{
static GType spec_type = 0;
if (!spec_type)
{
static const GTypeInfo type_info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_matrix2_class_init,
NULL, NULL,
sizeof (GimpParamSpecMatrix2),
0,
(GInstanceInitFunc) gimp_param_matrix2_init
};
spec_type = g_type_register_static (G_TYPE_PARAM_BOXED,
"GimpParamMatrix2",
&type_info, 0);
}
return spec_type;
}
static void
gimp_param_matrix2_class_init (GParamSpecClass *class)
{
class->value_type = GIMP_TYPE_MATRIX2;
class->value_set_default = gimp_param_matrix2_set_default;
class->values_cmp = gimp_param_matrix2_values_cmp;
}
static void
gimp_param_matrix2_init (GParamSpec *pspec)
{
GimpParamSpecMatrix2 *cspec = GIMP_PARAM_SPEC_MATRIX2 (pspec);
gimp_matrix2_identity (&cspec->default_value);
}
static void
gimp_param_matrix2_set_default (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecMatrix2 *cspec = GIMP_PARAM_SPEC_MATRIX2 (pspec);
g_value_set_static_boxed (value, &cspec->default_value);
}
static gint
gimp_param_matrix2_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2)
{
GimpMatrix2 *matrix1;
GimpMatrix2 *matrix2;
gint i, j;
matrix1 = value1->data[0].v_pointer;
matrix2 = value2->data[0].v_pointer;
/* try to return at least *something*, it's useless anyway... */
if (! matrix1)
return matrix2 != NULL ? -1 : 0;
else if (! matrix2)
return matrix1 != NULL;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
if (matrix1->coeff[i][j] != matrix2->coeff[i][j])
return 1;
return 0;
}
GParamSpec *
gimp_param_spec_matrix2 (const gchar *name,
const gchar *nick,
const gchar *blurb,
const GimpMatrix2 *default_value,
GParamFlags flags)
{
GimpParamSpecMatrix2 *cspec;
g_return_val_if_fail (default_value != NULL, NULL);
cspec = g_param_spec_internal (GIMP_TYPE_PARAM_MATRIX2,
name, nick, blurb, flags);
cspec->default_value = *default_value;
return G_PARAM_SPEC (cspec);
}
/*
* GIMP_TYPE_PARAM_MEMSIZE
*/
static void gimp_param_memsize_class_init (GParamSpecClass *class);
GType
gimp_param_memsize_get_type (void)
{
static GType spec_type = 0;
if (!spec_type)
{
static const GTypeInfo type_info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_memsize_class_init,
NULL, NULL,
sizeof (GParamSpecUInt64),
0, NULL, NULL
};
spec_type = g_type_register_static (G_TYPE_PARAM_UINT64,
"GimpParamMemsize",
&type_info, 0);
}
return spec_type;
}
static void
gimp_param_memsize_class_init (GParamSpecClass *class)
{
class->value_type = GIMP_TYPE_MEMSIZE;
}
GParamSpec *
gimp_param_spec_memsize (const gchar *name,
const gchar *nick,
const gchar *blurb,
guint64 minimum,
guint64 maximum,
guint64 default_value,
GParamFlags flags)
{
GParamSpecUInt64 *pspec;
pspec = g_param_spec_internal (GIMP_TYPE_PARAM_MEMSIZE,
name, nick, blurb, flags);
pspec->minimum = minimum;
pspec->maximum = maximum;
pspec->default_value = default_value;
return G_PARAM_SPEC (pspec);
}
/*
* GIMP_TYPE_PARAM_PATH
*/
#define GIMP_PARAM_SPEC_PATH(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_PATH, GimpParamSpecPath))
typedef struct _GimpParamSpecPath GimpParamSpecPath;
struct _GimpParamSpecPath
{
GParamSpecString parent_instance;
GimpParamPathType type;
};
static void gimp_param_path_class_init (GParamSpecClass *class);
GType
gimp_param_path_get_type (void)
{
static GType spec_type = 0;
if (!spec_type)
{
static const GTypeInfo type_info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_path_class_init,
NULL, NULL,
sizeof (GimpParamSpecPath),
0, NULL, NULL
};
spec_type = g_type_register_static (G_TYPE_PARAM_STRING,
"GimpParamPath",
&type_info, 0);
}
return spec_type;
}
static void
gimp_param_path_class_init (GParamSpecClass *class)
{
class->value_type = GIMP_TYPE_PATH;
}
GParamSpec *
gimp_param_spec_path (const gchar *name,
const gchar *nick,
const gchar *blurb,
GimpParamPathType type,
gchar *default_value,
GParamFlags flags)
{
GParamSpecString *pspec;
pspec = g_param_spec_internal (GIMP_TYPE_PARAM_PATH,
name, nick, blurb, flags);
pspec->default_value = default_value;
GIMP_PARAM_SPEC_PATH (pspec)->type = type;
return G_PARAM_SPEC (pspec);
}
GimpParamPathType
gimp_param_spec_path_type (GParamSpec *pspec)
{
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_PATH (pspec), 0);
return GIMP_PARAM_SPEC_PATH (pspec)->type;
}
/*
* GIMP_TYPE_PARAM_UNIT
*/
#define GIMP_PARAM_SPEC_UNIT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_UNIT, GimpParamSpecUnit))
typedef struct _GimpParamSpecUnit GimpParamSpecUnit;
struct _GimpParamSpecUnit
{
GParamSpecInt parent_instance;
gboolean allow_percent;
};
static void gimp_param_unit_class_init (GParamSpecClass *class);
static gboolean gimp_param_unit_value_validate (GParamSpec *pspec,
GValue *value);
GType
gimp_param_unit_get_type (void)
{
static GType spec_type = 0;
if (!spec_type)
{
static const GTypeInfo type_info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_unit_class_init,
NULL, NULL,
sizeof (GimpParamSpecUnit),
0, NULL, NULL
};
spec_type = g_type_register_static (G_TYPE_PARAM_INT,
"GimpParamUnit",
&type_info, 0);
}
return spec_type;
}
static void
gimp_param_unit_class_init (GParamSpecClass *class)
{
class->value_type = GIMP_TYPE_UNIT;
class->value_validate = gimp_param_unit_value_validate;
}
static gboolean
gimp_param_unit_value_validate (GParamSpec *pspec,
GValue *value)
{
GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec);
gint oval = value->data[0].v_int;
if (uspec->allow_percent && value->data[0].v_int == GIMP_UNIT_PERCENT)
{
value->data[0].v_int = value->data[0].v_int;
}
else
{
value->data[0].v_int = CLAMP (value->data[0].v_int,
ispec->minimum,
gimp_unit_get_number_of_units () - 1);
}
return value->data[0].v_int != oval;
}
GParamSpec *
gimp_param_spec_unit (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean allow_pixels,
gboolean allow_percent,
GimpUnit default_value,
GParamFlags flags)
{
GimpParamSpecUnit *pspec;
GParamSpecInt *ispec;
pspec = g_param_spec_internal (GIMP_TYPE_PARAM_UNIT,
name, nick, blurb, flags);
ispec = G_PARAM_SPEC_INT (pspec);
ispec->default_value = default_value;
ispec->minimum = allow_pixels ? GIMP_UNIT_PIXEL : GIMP_UNIT_INCH;
ispec->maximum = GIMP_UNIT_PERCENT - 1;
pspec->allow_percent = allow_percent;
return G_PARAM_SPEC (pspec);
}