Commit bd427b2e authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

libgimpbase/Makefile.am libgimpbase/gimpbase.h libgimpbase/gimpbase.def

2004-07-27  Sven Neumann  <sven@gimp.org>

	* libgimpbase/Makefile.am
	* libgimpbase/gimpbase.h
	* libgimpbase/gimpbase.def
	* libgimpbase/gimpmemsize.[ch]: added new files with memsize
	related functions (moved here from gimputil.c) and
	GIMP_TYPE_MEMSIZE (moved here from app/config/gimpconfig-types.[ch]).

	* libgimpbase/gimputils.[ch]: removed gimp_memsize_to_string() here.

	* libgimpbase/gimpunit.[ch]: added GIMP_TYPE_UNIT (moved here from
	app/config/gimpconfig-types.[ch]).

	* libgimpbase/gimpbase-private.c
	* libgimp/gimptile.c
	* libgimp/gimpunitcache.c
	* plug-ins/help/domain.c
	* app/xcf/xcf-read.c: need to include glib-object.h.

	* plug-ins/common/uniteditor.c: use GIMP_TYPE_UNIT.

	* app/config/gimpconfig-types.[ch]: removed code that lives in
	libgimpbase now.

	* app/config/gimpconfig-deserialize.c: changed accordingly.

	* app/config/gimpbaseconfig.c
	* app/config/gimpdisplayconfig.c
	* app/core/gimpcontext.c
	* app/gui/grid-dialog.c
	* app/tools/gimpcolortool.c
	* app/widgets/gimpaction.c
	* app/widgets/gimpunitstore.c: no need to include gimpconfig-types.h
	any longer.
parent ed3f8fd1
2004-07-27 Michael Natterer <mitch@gimp.org>
2004-07-27 Sven Neumann <sven@gimp.org>
* libgimpbase/Makefile.am
* libgimpbase/gimpbase.h
* libgimpbase/gimpbase.def
* libgimpbase/gimpmemsize.[ch]: added new files with memsize
related functions (moved here from gimputil.c) and
GIMP_TYPE_MEMSIZE (moved here from app/config/gimpconfig-types.[ch]).
* libgimpbase/gimputils.[ch]: removed gimp_memsize_to_string() here.
* libgimpbase/gimpunit.[ch]: added GIMP_TYPE_UNIT (moved here from
app/config/gimpconfig-types.[ch]).
* libgimpbase/gimpbase-private.c
* libgimp/gimptile.c
* libgimp/gimpunitcache.c
* plug-ins/help/domain.c
* app/xcf/xcf-read.c: need to include glib-object.h.
* plug-ins/common/uniteditor.c: use GIMP_TYPE_UNIT.
* app/config/gimpconfig-types.[ch]: removed code that lives in
libgimpbase now.
* app/config/gimpconfig-deserialize.c: changed accordingly.
* app/config/gimpbaseconfig.c
* app/config/gimpdisplayconfig.c
* app/core/gimpcontext.c
* app/gui/grid-dialog.c
* app/tools/gimpcolortool.c
* app/widgets/gimpaction.c
* app/widgets/gimpunitstore.c: no need to include gimpconfig-types.h
any longer.
004-07-27 Michael Natterer <mitch@gimp.org>
* libgimp/Makefile.am
* libgimp/gimp.h
......
......@@ -28,7 +28,6 @@
#include "config-types.h"
#include "gimpconfig-params.h"
#include "gimpconfig-types.h"
#include "gimprc-blurbs.h"
#include "gimpbaseconfig.h"
......
......@@ -560,8 +560,9 @@ gimp_config_deserialize_memsize (GValue *value,
GParamSpec *prop_spec,
GScanner *scanner)
{
gchar *orig_cset_first = scanner->config->cset_identifier_first;
gchar *orig_cset_nth = scanner->config->cset_identifier_nth;
gchar *orig_cset_first = scanner->config->cset_identifier_first;
gchar *orig_cset_nth = scanner->config->cset_identifier_nth;
guint64 memsize;
scanner->config->cset_identifier_first = G_CSET_DIGITS;
scanner->config->cset_identifier_nth = G_CSET_DIGITS "gGmMkKbB";
......@@ -574,10 +575,12 @@ gimp_config_deserialize_memsize (GValue *value,
scanner->config->cset_identifier_first = orig_cset_first;
scanner->config->cset_identifier_nth = orig_cset_nth;
if (gimp_memsize_set_from_string (value, scanner->value.v_identifier))
return G_TOKEN_RIGHT_PAREN;
else
if (! gimp_memsize_deserialize (scanner->value.v_identifier, &memsize))
return G_TOKEN_NONE;
g_value_set_uint64 (value, memsize);
return G_TOKEN_RIGHT_PAREN;
}
static GTokenType
......
......@@ -21,12 +21,8 @@
#include "config.h"
#include <errno.h>
#include <string.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h"
#include "config-types.h"
......@@ -34,35 +30,8 @@
#include "gimpconfig-types.h"
static GimpRGB * color_copy (const GimpRGB *color);
static void color_free (GimpRGB *color);
static GimpMatrix2 * matrix2_copy (const GimpMatrix2 *matrix);
static void matrix2_free (GimpMatrix2 *matrix);
static void memsize_to_string (const GValue *src_value,
GValue *dest_value);
static void string_to_memsize (const GValue *src_value,
GValue *dest_value);
static void unit_to_string (const GValue *src_value,
GValue *dest_value);
static void string_to_unit (const GValue *src_value,
GValue *dest_value);
GType
gimp_color_get_type (void)
{
static GType color_type = 0;
if (!color_type)
color_type = g_boxed_type_register_static ("GimpColor",
(GBoxedCopyFunc) color_copy,
(GBoxedFreeFunc) color_free);
static GimpMatrix2 * matrix2_copy (const GimpMatrix2 *matrix);
return color_type;
}
GType
gimp_matrix2_get_type (void)
......@@ -72,85 +41,17 @@ gimp_matrix2_get_type (void)
if (!matrix_type)
matrix_type = g_boxed_type_register_static ("GimpMatrix2",
(GBoxedCopyFunc) matrix2_copy,
(GBoxedFreeFunc) matrix2_free);
(GBoxedFreeFunc) g_free);
return matrix_type;
}
GType
gimp_memsize_get_type (void)
static GimpMatrix2 *
matrix2_copy (const GimpMatrix2 *matrix)
{
static GType memsize_type = 0;
if (!memsize_type)
{
static const GTypeInfo type_info = { 0, };
memsize_type = g_type_register_static (G_TYPE_UINT64, "GimpMemsize",
&type_info, 0);
g_value_register_transform_func (memsize_type, G_TYPE_STRING,
memsize_to_string);
g_value_register_transform_func (G_TYPE_STRING, memsize_type,
string_to_memsize);
}
return memsize_type;
return (GimpMatrix2 *) g_memdup (matrix, sizeof (GimpMatrix2));
}
gboolean
gimp_memsize_set_from_string (GValue *value,
const gchar *string)
{
gchar *end;
guint64 size;
g_return_val_if_fail (GIMP_VALUE_HOLDS_MEMSIZE (value), FALSE);
g_return_val_if_fail (string != NULL, FALSE);
size = g_ascii_strtoull (string, &end, 0);
if (size == G_MAXUINT64 && errno == ERANGE)
return FALSE;
if (end && *end)
{
guint shift;
switch (g_ascii_tolower (*end))
{
case 'b':
shift = 0;
break;
case 'k':
shift = 10;
break;
case 'm':
shift = 20;
break;
case 'g':
shift = 30;
break;
default:
return FALSE;
}
/* protect against overflow */
if (shift)
{
guint64 limit = G_MAXUINT64 >> shift;
if (size != (size & limit))
return FALSE;
size <<= shift;
}
}
g_value_set_uint64 (value, size);
return TRUE;
}
GType
gimp_path_get_type (void)
......@@ -167,126 +68,3 @@ gimp_path_get_type (void)
return path_type;
}
GType
gimp_unit_get_type (void)
{
static GType unit_type = 0;
if (!unit_type)
{
static const GTypeInfo type_info = { 0, };
unit_type = g_type_register_static (G_TYPE_INT, "GimpUnit",
&type_info, 0);
g_value_register_transform_func (unit_type, G_TYPE_STRING,
unit_to_string);
g_value_register_transform_func (G_TYPE_STRING, unit_type,
string_to_unit);
}
return unit_type;
}
static GimpRGB *
color_copy (const GimpRGB *color)
{
return (GimpRGB *) g_memdup (color, sizeof (GimpRGB));
}
static void
color_free (GimpRGB *color)
{
g_free (color);
}
static void
memsize_to_string (const GValue *src_value,
GValue *dest_value)
{
guint64 size;
gchar *str;
size = g_value_get_uint64 (src_value);
if (size > (1 << 30) && size % (1 << 30) == 0)
str = g_strdup_printf ("%" G_GUINT64_FORMAT "G", size >> 30);
else if (size > (1 << 20) && size % (1 << 20) == 0)
str = g_strdup_printf ("%" G_GUINT64_FORMAT "M", size >> 20);
else if (size > (1 << 10) && size % (1 << 10) == 0)
str = g_strdup_printf ("%" G_GUINT64_FORMAT "k", size >> 10);
else
str = g_strdup_printf ("%" G_GUINT64_FORMAT, size);
g_value_take_string (dest_value, str);
}
static void
string_to_memsize (const GValue *src_value,
GValue *dest_value)
{
const gchar *str = g_value_get_string (src_value);
if (!str || !gimp_memsize_set_from_string (dest_value, str))
g_warning ("Can't convert string to GimpMemsize.");
}
static GimpMatrix2 *
matrix2_copy (const GimpMatrix2 *matrix)
{
return (GimpMatrix2 *) g_memdup (matrix, sizeof (GimpMatrix2));
}
static void
matrix2_free (GimpMatrix2 *matrix)
{
g_free (matrix);
}
static void
unit_to_string (const GValue *src_value,
GValue *dest_value)
{
GimpUnit unit = (GimpUnit) g_value_get_int (src_value);
g_value_set_string (dest_value, gimp_unit_get_identifier (unit));
}
static void
string_to_unit (const GValue *src_value,
GValue *dest_value)
{
const gchar *str;
gint num_units;
gint i;
str = g_value_get_string (src_value);
if (!str || !*str)
goto error;
num_units = gimp_unit_get_number_of_units ();
for (i = GIMP_UNIT_PIXEL; i < num_units; i++)
if (strcmp (str, gimp_unit_get_identifier (i)) == 0)
break;
if (i == num_units)
{
if (strcmp (str, gimp_unit_get_identifier (GIMP_UNIT_PERCENT)) == 0)
i = GIMP_UNIT_PERCENT;
else
goto error;
}
g_value_set_int (dest_value, i);
return;
error:
g_warning ("Can't convert string to GimpUnit.");
}
......@@ -29,24 +29,10 @@
GType gimp_matrix2_get_type (void) G_GNUC_CONST;
#define GIMP_TYPE_MEMSIZE (gimp_memsize_get_type ())
#define GIMP_VALUE_HOLDS_MEMSIZE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_MEMSIZE))
GType gimp_memsize_get_type (void) G_GNUC_CONST;
gboolean gimp_memsize_set_from_string (GValue *value,
const gchar *string);
#define GIMP_TYPE_PATH (gimp_path_get_type ())
#define GIMP_VALUE_HOLDS_PATH(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_PATH))
GType gimp_path_get_type (void) G_GNUC_CONST;
#define GIMP_TYPE_UNIT (gimp_unit_get_type ())
#define GIMP_VALUE_HOLDS_UNIT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_UNIT))
GType gimp_unit_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_CONFIG_TYPES_H__ */
......@@ -33,7 +33,6 @@
#include "gimpconfig.h"
#include "gimpconfig-params.h"
#include "gimpconfig-types.h"
#include "gimpconfig-utils.h"
#include "gimprc-blurbs.h"
......
......@@ -34,7 +34,6 @@
#include "config/gimpconfig.h"
#include "config/gimpconfig-params.h"
#include "config/gimpconfig-serialize.h"
#include "config/gimpconfig-types.h"
#include "config/gimpconfigwriter.h"
#include "config/gimpcoreconfig.h"
#include "config/gimpscanner.h"
......
......@@ -29,7 +29,6 @@
#include "gui-types.h"
#include "config/gimpconfig.h"
#include "config/gimpconfig-types.h"
#include "config/gimpconfig-utils.h"
#include "config/gimpcoreconfig.h"
......
......@@ -29,7 +29,6 @@
#include "gui-types.h"
#include "config/gimpconfig.h"
#include "config/gimpconfig-types.h"
#include "config/gimpconfig-utils.h"
#include "config/gimpcoreconfig.h"
......
......@@ -25,8 +25,6 @@
#include "tools-types.h"
#include "config/gimpconfig-types.h"
#include "core/gimpimage.h"
#include "core/gimpimage-pick-color.h"
#include "core/gimpitem.h"
......
......@@ -31,7 +31,6 @@
#include "widgets-types.h"
#include "config/gimpconfig-params.h"
#include "config/gimpconfig-types.h"
#include "core/gimpmarshal.h"
#include "core/gimpviewable.h"
......
......@@ -28,8 +28,6 @@
#include "widgets-types.h"
#include "config/gimpconfig-types.h"
#include "gimpunitstore.h"
......
......@@ -20,7 +20,7 @@
#include <stdio.h>
#include <glib.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
......
2004-07-27 Sven Neumann <sven@gimp.org>
* libgimpbase/libgimpbase-docs.sgml
* libgimpbase/libgimpbase-sections.txt
* libgimpbase/tmpl/gimpmemsize.sgml
* libgimpbase/tmpl/gimpunit.sgml
* libgimpbase/tmpl/gimputils.sgml: added docs for new unit and
memsize functions.
2004-07-27 Michael Natterer <mitch@gimp.org>
* libgimp/tmpl/gimppalettemenu.sgml
......
......@@ -9,13 +9,11 @@ gimppalettemenu
</para>
<!-- ##### SECTION See_Also ##### -->
<para>
</para>
<!-- ##### FUNCTION gimp_palette_select_widget_new ##### -->
<para>
......
......@@ -9,13 +9,11 @@ gimppaletteselect
</para>
<!-- ##### SECTION See_Also ##### -->
<para>
</para>
<!-- ##### USER_FUNCTION GimpRunPaletteCallback ##### -->
<para>
......
......@@ -18,6 +18,7 @@
<xi:include href="xml/gimplimits.xml" />
<xi:include href="xml/gimpdatafiles.xml" />
<xi:include href="xml/gimpenv.xml" />
<xi:include href="xml/gimpmemsize.xml" />
<xi:include href="xml/gimpparasite.xml" />
<xi:include href="xml/gimpparasiteio.xml" />
<xi:include href="xml/gimpsignal.xml" />
......
......@@ -36,6 +36,17 @@ GIMP_CHECK_DARK
GIMP_CHECK_LIGHT
</SECTION>
<SECTION>
<FILE>gimpmemsize</FILE>
gimp_memsize_serialize
gimp_memsize_deserialize
gimp_memsize_to_string
GIMP_VALUE_HOLDS_MEMSIZE
<SUBSECTION Standard>
GIMP_TYPE_MEMSIZE
gimp_memsize_get_type
</SECTION>
<SECTION>
<FILE>gimpparasite</FILE>
GimpParasite
......@@ -119,6 +130,10 @@ gimp_unit_get_symbol
gimp_unit_get_abbreviation
gimp_unit_get_singular
gimp_unit_get_plural
GIMP_VALUE_HOLDS_UNIT
<SUBSECTION Standard>
GIMP_TYPE_UNIT
gimp_unit_get_type
</SECTION>
<SECTION>
......@@ -126,7 +141,6 @@ gimp_unit_get_plural
gimp_any_to_utf8
gimp_filename_to_utf8
gimp_utf8_strtrim
gimp_memsize_to_string
gimp_escape_uline
gimp_strip_uline
</SECTION>
......
<!-- ##### SECTION Title ##### -->
gimpmemsize
<!-- ##### SECTION Short_Description ##### -->
<!-- ##### SECTION Long_Description ##### -->
<para>
</para>
<!-- ##### SECTION See_Also ##### -->
<para>
</para>
<!-- ##### FUNCTION gimp_memsize_serialize ##### -->
<para>
</para>
@memsize:
@Returns:
<!-- ##### FUNCTION gimp_memsize_deserialize ##### -->
<para>
</para>
@string:
@memsize:
@Returns:
<!-- ##### FUNCTION gimp_memsize_to_string ##### -->
<para>
</para>
@memsize:
@Returns:
<!-- ##### MACRO GIMP_VALUE_HOLDS_MEMSIZE ##### -->
<para>
</para>
@value:
......@@ -145,3 +145,11 @@ user-defined units.
@Returns:
<!-- ##### MACRO GIMP_VALUE_HOLDS_UNIT ##### -->
<para>
</para>
@value:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment