Files
gimp/app/core/gimpunit.c
Michael Natterer a74a8997b4 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 12:45:22 +00:00

269 lines
6.9 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
*
* gimpunit.c
* Copyright (C) 1999-2000 Michael Natterer <mitch@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>
#include "libgimpbase/gimpbase.h"
#include "core-types.h"
#include "gimp.h"
#include "gimpunit.h"
#include "libgimp/gimpintl.h"
/* internal structures */
typedef struct
{
gboolean delete_on_exit;
gdouble factor;
gint digits;
gchar *identifier;
gchar *symbol;
gchar *abbreviation;
gchar *singular;
gchar *plural;
} GimpUnitDef;
/* these are the built-in units
*/
static GimpUnitDef gimp_unit_defs[GIMP_UNIT_END] =
{
/* pseudo unit */
{ FALSE, 0.0, 0, "pixels", "px", "px", N_("pixel"), N_("pixels") },
/* standard units */
{ FALSE, 1.0, 2, "inches", "''", "in", N_("inch"), N_("inches") },
{ FALSE, 25.4, 1, "millimeters", "mm", "mm", N_("millimeter"), N_("millimeters") },
/* professional units */
{ FALSE, 72.0, 0, "points", "pt", "pt", N_("point"), N_("points") },
{ FALSE, 6.0, 1, "picas", "pc", "pc", N_("pica"), N_("picas") },
};
/* not a unit at all but kept here to have the strings in one place
*/
static GimpUnitDef gimp_unit_percent =
{
FALSE, 0.0, 0, "percent", "%", "%", N_("percent"), N_("percent")
};
/* private functions */
static GimpUnitDef *
_gimp_unit_get_user_unit (Gimp *gimp,
GimpUnit unit)
{
return g_list_nth_data (gimp->user_units, unit - GIMP_UNIT_END);
}
/* public functions */
gint
_gimp_unit_get_number_of_units (Gimp *gimp)
{
return GIMP_UNIT_END + gimp->n_user_units;
}
gint
_gimp_unit_get_number_of_built_in_units (Gimp *gimp)
{
return GIMP_UNIT_END;
}
GimpUnit
_gimp_unit_new (Gimp *gimp,
gchar *identifier,
gdouble factor,
gint digits,
gchar *symbol,
gchar *abbreviation,
gchar *singular,
gchar *plural)
{
GimpUnitDef *user_unit;
user_unit = g_new0 (GimpUnitDef, 1);
user_unit->delete_on_exit = TRUE;
user_unit->factor = factor;
user_unit->digits = digits;
user_unit->identifier = g_strdup (identifier);
user_unit->symbol = g_strdup (symbol);
user_unit->abbreviation = g_strdup (abbreviation);
user_unit->singular = g_strdup (singular);
user_unit->plural = g_strdup (plural);
gimp->user_units = g_list_append (gimp->user_units, user_unit);
gimp->n_user_units++;
return GIMP_UNIT_END + gimp->n_user_units - 1;
}
gboolean
_gimp_unit_get_deletion_flag (Gimp *gimp,
GimpUnit unit)
{
g_return_val_if_fail ((unit >= GIMP_UNIT_PIXEL) &&
(unit < (GIMP_UNIT_END + gimp->n_user_units)), FALSE);
if (unit < GIMP_UNIT_END)
return FALSE;
return _gimp_unit_get_user_unit (gimp, unit)->delete_on_exit;
}
void
_gimp_unit_set_deletion_flag (Gimp *gimp,
GimpUnit unit,
gboolean deletion_flag)
{
g_return_if_fail ((unit >= GIMP_UNIT_END) &&
(unit < (GIMP_UNIT_END + gimp->n_user_units)));
_gimp_unit_get_user_unit (gimp, unit)->delete_on_exit =
deletion_flag ? TRUE : FALSE;
}
gdouble
_gimp_unit_get_factor (Gimp *gimp,
GimpUnit unit)
{
g_return_val_if_fail ((unit >= GIMP_UNIT_PIXEL) &&
(unit < (GIMP_UNIT_END + gimp->n_user_units)),
gimp_unit_defs[GIMP_UNIT_INCH].factor);
if (unit < GIMP_UNIT_END)
return gimp_unit_defs[unit].factor;
return _gimp_unit_get_user_unit (gimp, unit)->factor;
}
gint
_gimp_unit_get_digits (Gimp *gimp,
GimpUnit unit)
{
g_return_val_if_fail ((unit >= GIMP_UNIT_PIXEL) &&
(unit < (GIMP_UNIT_END + gimp->n_user_units)),
gimp_unit_defs[GIMP_UNIT_INCH].digits);
if (unit < GIMP_UNIT_END)
return gimp_unit_defs[unit].digits;
return _gimp_unit_get_user_unit (gimp, unit)->digits;
}
const gchar *
_gimp_unit_get_identifier (Gimp *gimp,
GimpUnit unit)
{
g_return_val_if_fail (((unit >= GIMP_UNIT_PIXEL) &&
(unit < (GIMP_UNIT_END + gimp->n_user_units))) ||
(unit == GIMP_UNIT_PERCENT),
gimp_unit_defs[GIMP_UNIT_INCH].identifier);
if (unit < GIMP_UNIT_END)
return gimp_unit_defs[unit].identifier;
if (unit == GIMP_UNIT_PERCENT)
return gimp_unit_percent.identifier;
return _gimp_unit_get_user_unit (gimp, unit)->identifier;
}
const gchar *
_gimp_unit_get_symbol (Gimp *gimp,
GimpUnit unit)
{
g_return_val_if_fail (((unit >= GIMP_UNIT_PIXEL) &&
(unit < (GIMP_UNIT_END + gimp->n_user_units))) ||
(unit == GIMP_UNIT_PERCENT),
gimp_unit_defs[GIMP_UNIT_INCH].symbol);
if (unit < GIMP_UNIT_END)
return gimp_unit_defs[unit].symbol;
if (unit == GIMP_UNIT_PERCENT)
return gimp_unit_percent.symbol;
return _gimp_unit_get_user_unit (gimp, unit)->symbol;
}
const gchar *
_gimp_unit_get_abbreviation (Gimp *gimp,
GimpUnit unit)
{
g_return_val_if_fail (((unit >= GIMP_UNIT_PIXEL) &&
(unit < (GIMP_UNIT_END + gimp->n_user_units))) ||
(unit == GIMP_UNIT_PERCENT),
gimp_unit_defs[GIMP_UNIT_INCH].abbreviation);
if (unit < GIMP_UNIT_END)
return gimp_unit_defs[unit].abbreviation;
if (unit == GIMP_UNIT_PERCENT)
return gimp_unit_percent.abbreviation;
return _gimp_unit_get_user_unit (gimp, unit)->abbreviation;
}
const gchar *
_gimp_unit_get_singular (Gimp *gimp,
GimpUnit unit)
{
g_return_val_if_fail (((unit >= GIMP_UNIT_PIXEL) &&
(unit < (GIMP_UNIT_END + gimp->n_user_units))) ||
(unit == GIMP_UNIT_PERCENT),
gettext (gimp_unit_defs[GIMP_UNIT_INCH].singular));
if (unit < GIMP_UNIT_END)
return gettext (gimp_unit_defs[unit].singular);
if (unit == GIMP_UNIT_PERCENT)
return gettext (gimp_unit_percent.singular);
return gettext (_gimp_unit_get_user_unit (gimp, unit)->singular);
}
const gchar *
_gimp_unit_get_plural (Gimp *gimp,
GimpUnit unit)
{
g_return_val_if_fail (((unit >= GIMP_UNIT_PIXEL) &&
(unit < (GIMP_UNIT_END + gimp->n_user_units))) ||
(unit == GIMP_UNIT_PERCENT),
gettext (gimp_unit_defs[GIMP_UNIT_INCH].plural));
if (unit < GIMP_UNIT_END)
return gettext (gimp_unit_defs[unit].plural);
if (unit == GIMP_UNIT_PERCENT)
return gettext (gimp_unit_percent.plural);
return gettext (_gimp_unit_get_user_unit (gimp, unit)->plural);
}