1
/* LIBGIMP - The GIMP Library
2
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
5
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
27
#include <glib-object.h>
29
#include "gimpbasetypes.h"
31
#include "gimpbase-private.h"
35
static void unit_to_string (const GValue *src_value,
37
static void string_to_unit (const GValue *src_value,
41
gimp_unit_get_type (void)
43
static GType unit_type = 0;
47
static const GTypeInfo type_info = { 0, };
49
unit_type = g_type_register_static (G_TYPE_INT, "GimpUnit",
52
g_value_register_transform_func (unit_type, G_TYPE_STRING,
54
g_value_register_transform_func (G_TYPE_STRING, unit_type,
62
unit_to_string (const GValue *src_value,
65
GimpUnit unit = (GimpUnit) g_value_get_int (src_value);
67
g_value_set_string (dest_value, gimp_unit_get_identifier (unit));
71
string_to_unit (const GValue *src_value,
78
str = g_value_get_string (src_value);
83
num_units = gimp_unit_get_number_of_units ();
85
for (i = GIMP_UNIT_PIXEL; i < num_units; i++)
86
if (strcmp (str, gimp_unit_get_identifier (i)) == 0)
91
if (strcmp (str, gimp_unit_get_identifier (GIMP_UNIT_PERCENT)) == 0)
92
i = GIMP_UNIT_PERCENT;
97
g_value_set_int (dest_value, i);
101
g_warning ("Can't convert string to GimpUnit.");
106
* gimp_unit_get_number_of_units:
108
* Returns the number of units which are known to the #GimpUnit system.
110
* Returns: The number of defined units.
113
gimp_unit_get_number_of_units (void)
115
g_return_val_if_fail (_gimp_unit_vtable.unit_get_number_of_units != NULL,
118
return _gimp_unit_vtable.unit_get_number_of_units ();
122
* gimp_unit_get_number_of_built_in_units:
124
* Returns the number of #GimpUnit's which are hardcoded in the unit system
125
* (UNIT_INCH, UNIT_MM, UNIT_POINT, UNIT_PICA and the two "pseudo unit"
128
* Returns: The number of built-in units.
131
gimp_unit_get_number_of_built_in_units (void)
133
g_return_val_if_fail (_gimp_unit_vtable.unit_get_number_of_built_in_units
134
!= NULL, GIMP_UNIT_END);
136
return _gimp_unit_vtable.unit_get_number_of_built_in_units ();
141
* @identifier: The unit's identifier string.
142
* @factor: The unit's factor (how many units are in one inch).
143
* @digits: The unit's suggested number of digits (see gimp_unit_get_digits()).
144
* @symbol: The symbol of the unit (e.g. "''" for inch).
145
* @abbreviation: The abbreviation of the unit.
146
* @singular: The singular form of the unit.
147
* @plural: The plural form of the unit.
149
* Returns the integer ID of the new #GimpUnit.
151
* Note that a new unit is always created with it's deletion flag
152
* set to %TRUE. You will have to set it to %FALSE with
153
* gimp_unit_set_deletion_flag() to make the unit definition persistent.
155
* Returns: The ID of the new unit.
158
gimp_unit_new (gchar *identifier,
166
g_return_val_if_fail (_gimp_unit_vtable.unit_new != NULL, GIMP_UNIT_INCH);
168
return _gimp_unit_vtable.unit_new (identifier, factor, digits,
169
symbol, abbreviation, singular, plural);
173
* gimp_unit_get_deletion_flag:
174
* @unit: The unit you want to know the @deletion_flag of.
176
* Returns: The unit's @deletion_flag.
179
gimp_unit_get_deletion_flag (GimpUnit unit)
181
g_return_val_if_fail (_gimp_unit_vtable.unit_get_deletion_flag != NULL, FALSE);
183
return _gimp_unit_vtable.unit_get_deletion_flag (unit);
187
* gimp_unit_set_deletion_flag:
188
* @unit: The unit you want to set the @deletion_flag for.
189
* @deletion_flag: The new deletion_flag.
191
* Sets a #GimpUnit's @deletion_flag. If the @deletion_flag of a unit is
192
* %TRUE when GIMP exits, this unit will not be saved in the users's
195
* Trying to change the @deletion_flag of a built-in unit will be silently
199
gimp_unit_set_deletion_flag (GimpUnit unit,
200
gboolean deletion_flag)
202
g_return_if_fail (_gimp_unit_vtable.unit_set_deletion_flag != NULL);
204
_gimp_unit_vtable.unit_set_deletion_flag (unit, deletion_flag);
208
* gimp_unit_get_factor:
209
* @unit: The unit you want to know the factor of.
211
* A #GimpUnit's @factor is defined to be:
213
* distance_in_units == (@factor * distance_in_inches)
215
* Returns 0 for @unit == GIMP_UNIT_PIXEL.
217
* Returns: The unit's factor.
220
gimp_unit_get_factor (GimpUnit unit)
222
g_return_val_if_fail (_gimp_unit_vtable.unit_get_factor != NULL, 1.0);
224
return _gimp_unit_vtable.unit_get_factor (unit);
228
* gimp_unit_get_digits:
229
* @unit: The unit you want to know the digits.
231
* Returns the number of digits an entry field should provide to get
232
* approximately the same accuracy as an inch input field with two digits.
234
* Returns 0 for @unit == GIMP_UNIT_PIXEL.
236
* Returns: The suggested number of digits.
239
gimp_unit_get_digits (GimpUnit unit)
241
g_return_val_if_fail (_gimp_unit_vtable.unit_get_digits != NULL, 2);
243
return _gimp_unit_vtable.unit_get_digits (unit);
247
* gimp_unit_get_identifier:
248
* @unit: The unit you want to know the identifier of.
250
* This is an unstranslated string and must not be changed or freed.
252
* Returns: The unit's identifier.
255
gimp_unit_get_identifier (GimpUnit unit)
257
g_return_val_if_fail (_gimp_unit_vtable.unit_get_identifier != NULL, NULL);
259
return _gimp_unit_vtable.unit_get_identifier (unit);
263
* gimp_unit_get_symbol:
264
* @unit: The unit you want to know the symbol of.
266
* This is e.g. "''" for UNIT_INCH.
268
* NOTE: This string must not be changed or freed.
270
* Returns: The unit's symbol.
273
gimp_unit_get_symbol (GimpUnit unit)
275
g_return_val_if_fail (_gimp_unit_vtable.unit_get_symbol != NULL, NULL);
277
return _gimp_unit_vtable.unit_get_symbol (unit);
281
* gimp_unit_get_abbreviation:
282
* @unit: The unit you want to know the abbreviation of.
284
* For built-in units, this function returns the translated abbreviation
287
* NOTE: This string must not be changed or freed.
289
* Returns: The unit's abbreviation.
292
gimp_unit_get_abbreviation (GimpUnit unit)
294
g_return_val_if_fail (_gimp_unit_vtable.unit_get_abbreviation != NULL, NULL);
296
return _gimp_unit_vtable.unit_get_abbreviation (unit);
300
* gimp_unit_get_singular:
301
* @unit: The unit you want to know the singular form of.
303
* For built-in units, this function returns the translated singular form
304
* of the unit's name.
306
* NOTE: This string must not be changed or freed.
308
* Returns: The unit's singular form.
311
gimp_unit_get_singular (GimpUnit unit)
313
g_return_val_if_fail (_gimp_unit_vtable.unit_get_singular != NULL, NULL);
315
return _gimp_unit_vtable.unit_get_singular (unit);
319
* gimp_unit_get_plural:
320
* @unit: The unit you want to know the plural form of.
322
* For built-in units, this function returns the translated plural form
323
* of the unit's name.
325
* NOTE: This string must not be changed or freed.
327
* Returns: The unit's plural form.
330
gimp_unit_get_plural (GimpUnit unit)
332
g_return_val_if_fail (_gimp_unit_vtable.unit_get_plural != NULL, NULL);
334
return _gimp_unit_vtable.unit_get_plural (unit);