gimp/app/core/gimpparasitelist.c

299 lines
6.5 KiB
C
Raw Normal View History

/* parasitelist.c: Copyright 1998 Jay Cox <jaycox@earthlink.net>
*
* 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 <string.h>
#include <gtk/gtk.h>
Makefile.am configure.in added new directory libgimpbase/ 2001-05-21 Michael Natterer <mitch@gimp.org> * Makefile.am * configure.in * gimptool-1.4.in: added new directory libgimpbase/ * app/Makefile.am: link against the new lib. * app/appenums.h: removed the PDB enums which are in libgimpbase/gimpbasetypes.h now. They are all "Gimp" prefixed. * app/apptypes.h: #include "libgimpbase/gimpbasetypes.h" * app/[lots] * app/core/[of] * app/gui/[files] * app/tools/: changed includes and all PDB types. * app/pdb/*: regenerated. * libgimp/Makefile.am: don't build libgimpi.a uglyness any more. * libgimp/gimpenv.[ch] * libgimp/gimplimits.[hh] * libgimp/gimpparasite.[ch] * libgimp/gimpparasiteio.[ch] * libgimp/gimpprotocol.[ch] * libgimp/gimpsignal.[ch] * libgimp/gimpunit.h * libgimp/gimputils.[ch] * libgimp/gimpwire.[ch]: removed... * libgimpbase/*: ...and added here as new library. * libgimp/gimp.[ch] * libgimp/gimpdrawable.[ch] * libgimp/gimpenums.h * libgimp/gimpimage.[ch] * libgimp/gimptile.c * libgimp/gimptypes.h * libgimp/gimpunit.c: changed accordingly. Added the gimp_*_add_new_parasite to gimp.[ch], gimpdrawable.[ch] and gimpimage.[ch]. * libgimpwidgets/gimppatheditor.c * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpsizeentry.c * libgimpwidgets/gimpunitmenu.c * libgimpwidgets/gimpwidgets.c * libgimpwidgets/gimpwidgetstypes.h: changed includes accordingly. * plug-ins/*/Makefile.am * plug-ins/common/mkgen.pl: link against libgimpbase. * tools/pdbgen/Makefile.am: scan libgimpbase/gimpbasetypes.h, so the enums are known to pdbgen... * tools/pdbgen/enumcode.pl: ...but don't write them out to libgimp/gimpenums.h * tools/pdbgen/app.pl: include libgimp/gimpbase.h in all *_cmds.c files. Added GIMP_ to the type names ganerated in app/. * tools/pdbgen/enums.pl: regenerated. * tools/pdbgen/pdb.pl * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/procedural_db.pdb * tools/pdbgen/pdb/unit.pdb: changed includes.
2001-05-21 21:58:46 +08:00
#include "libgimpbase/gimpbase.h"
#include "core-types.h"
#include "gimpparasitelist.h"
enum
{
ADD,
REMOVE,
LAST_SIGNAL
};
static void gimp_parasite_list_class_init (GimpParasiteListClass *klass);
static void gimp_parasite_list_init (GimpParasiteList *list);
static void gimp_parasite_list_finalize (GObject *object);
static gint free_a_parasite (gpointer key,
gpointer parasite,
gpointer unused);
static guint parasite_list_signals[LAST_SIGNAL] = { 0 };
static GimpObjectClass *parent_class = NULL;
GType
gimp_parasite_list_get_type (void)
{
static GType list_type = 0;
if (! list_type)
{
static const GTypeInfo list_info =
{
sizeof (GimpParasiteListClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_parasite_list_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpParasiteList),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_parasite_list_init,
};
list_type = g_type_register_static (GIMP_TYPE_OBJECT,
"GimpParasiteList",
&list_info, 0);
}
return list_type;
}
static void
gimp_parasite_list_class_init (GimpParasiteListClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
parasite_list_signals[ADD] =
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
g_signal_new ("add",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpParasiteListClass, add),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
parasite_list_signals[REMOVE] =
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
g_signal_new ("remove",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpParasiteListClass, remove),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
GTK_TYPE_POINTER);
object_class->finalize = gimp_parasite_list_finalize;
klass->add = NULL;
klass->remove = NULL;
}
static void
gimp_parasite_list_init (GimpParasiteList *list)
{
list->table = NULL;
}
GimpParasiteList *
gimp_parasite_list_new (void)
{
GimpParasiteList *list;
list = g_object_new (GIMP_TYPE_PARASITE_LIST, NULL);
return list;
}
static void
gimp_parasite_list_finalize (GObject *object)
{
GimpParasiteList *list;
g_return_if_fail (GIMP_IS_PARASITE_LIST (object));
list = GIMP_PARASITE_LIST (object);
if (list->table)
{
g_hash_table_foreach_remove (list->table, free_a_parasite, NULL);
g_hash_table_destroy (list->table);
list->table = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gint
free_a_parasite (void *key,
void *parasite,
void *unused)
{
gimp_parasite_free ((GimpParasite *) parasite);
return TRUE;
}
static void
parasite_copy_one (gpointer key,
gpointer p,
gpointer data)
{
GimpParasiteList *list = (GimpParasiteList *) data;
GimpParasite *parasite = (GimpParasite *) p;
gimp_parasite_list_add (list, parasite);
}
GimpParasiteList *
gimp_parasite_list_copy (const GimpParasiteList *list)
{
GimpParasiteList *newlist;
g_return_val_if_fail (GIMP_IS_PARASITE_LIST (list), NULL);
newlist = gimp_parasite_list_new ();
if (list->table)
g_hash_table_foreach (list->table, parasite_copy_one, newlist);
return newlist;
}
void
gimp_parasite_list_add (GimpParasiteList *list,
GimpParasite *parasite)
{
g_return_if_fail (GIMP_IS_PARASITE_LIST (list));
g_return_if_fail (parasite != NULL);
g_return_if_fail (parasite->name != NULL);
if (list->table == NULL)
list->table = g_hash_table_new (g_str_hash, g_str_equal);
gimp_parasite_list_remove (list, parasite->name);
parasite = gimp_parasite_copy (parasite);
g_hash_table_insert (list->table, parasite->name, parasite);
g_signal_emit (G_OBJECT (list), parasite_list_signals[ADD], 0,
parasite);
}
void
gimp_parasite_list_remove (GimpParasiteList *list,
const gchar *name)
{
GimpParasite *parasite;
g_return_if_fail (GIMP_IS_PARASITE_LIST (list));
if (list->table)
{
parasite = gimp_parasite_list_find (list, name);
if (parasite)
{
g_hash_table_remove (list->table, name);
g_signal_emit (G_OBJECT (list), parasite_list_signals[REMOVE], 0,
parasite);
gimp_parasite_free (parasite);
}
}
}
gint
gimp_parasite_list_length (GimpParasiteList *list)
{
g_return_val_if_fail (GIMP_IS_PARASITE_LIST (list), 0);
if (! list->table)
return 0;
return g_hash_table_size (list->table);
}
static void
ppcount_func (gchar *key,
GimpParasite *p,
gint *count)
{
if (gimp_parasite_is_persistent (p))
*count = *count + 1;
}
gint
gimp_parasite_list_persistent_length (GimpParasiteList *list)
{
gint ppcount = 0;
g_return_val_if_fail (GIMP_IS_PARASITE_LIST (list), 0);
if (!list->table)
return 0;
gimp_parasite_list_foreach (list, (GHFunc) ppcount_func, &ppcount);
return ppcount;
}
void
gimp_parasite_list_foreach (GimpParasiteList *list,
GHFunc function,
gpointer user_data)
{
g_return_if_fail (GIMP_IS_PARASITE_LIST (list));
if (!list->table)
return;
g_hash_table_foreach (list->table, function, user_data);
}
GimpParasite *
gimp_parasite_list_find (GimpParasiteList *list,
const gchar *name)
{
g_return_val_if_fail (GIMP_IS_PARASITE_LIST (list), NULL);
if (list->table)
return (GimpParasite *) g_hash_table_lookup (list->table, name);
else
return NULL;
}
void
gimp_parasite_shift_parent (GimpParasite *parasite)
{
if (parasite == NULL)
return;
parasite->flags = (parasite->flags >> 8);
}