gimp/app/core/gimplist.c

254 lines
6.3 KiB
C
Raw Normal View History

/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* 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 <gtk/gtk.h>
#include "apptypes.h"
#include "gimpcontainer.h"
Jens Lautenbacher <jtl@gimp.org> 2000-12-18 Sven Neumann <sven@gimp.org> Jens Lautenbacher <jtl@gimp.org> * app/Makefile.am * app/gimpbrushlistP.h * app/gimpbrushpipeP.h * app/gimpobjectP.h: removed these three files * app/parasitelistP.h * app/channels_dialog.c * app/docindex.c * app/gimpdrawable.c * app/gimpdrawableP.h * app/gimpimage.c * app/gimpimageP.h * app/gimplist.[ch] * app/gimpobject.c * app/gimpobject.h * app/gimpsetP.h: changed according to header removal * app/airbrush.c * app/brush_select.[ch] * app/brushes_cmds.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushlist.[ch] * app/gimpbrushpipe.[ch] * app/gimpcontextpreview.c * app/paint_core.c * app/paintbrush.c * app/pencil.c * tools/pdbgen/pdb/brushes.pdb: Big Brushes Cleanup. The GimpBrush* object hierarchy and the file formats were broken by "design". This made it overly difficult to read and write pixmap brushes and brush pipes, leading to the situation that The GIMP was not able to read it's very own file formats. Since the GimpBrush format did support arbitrary color depths, the introduction of a file format for pixmap brushes was unnecessary. The GimpBrushPixmap object is dead. GimpBrush has an additional pixmap temp_buf and handles pixmap brushes transparently. The file format of pixmap brushes is not any longer a grayscale brush plus a pattern, but a simple brush with RGBA data. The old brushes can still be loaded, but the .gpb format is deprecated. GimpBrushPipe derives from GimpBrush. The fileformat is still a text header, followed by a number of brushes, but those brushes are stored in the new GimpBrush format (no pattern anymore). The pipe does not care about the depth of the contained GimpBrushes, so we get grayscale BrushPipes for free. Since the brush loader still loads the old format, old .gih files can also still be loaded. Since the brushes in the GimpBrushPipe do not any longer contain a pointer to the pipe object, we do only temporarily switch brushes in the paint_core routines. This is not very elegant, but the best we can do without a major redesign. * app/patterns.[ch]: changed the loader to work with a filedescriptor instead of a filehandle to make it work with the new brush loading code. * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/common/gih.c: new plug-in that saves GIH files in the new format (loader will follow soon) * plug-ins/common/gpb.c: removed since Pixmap Brushes are no longer supported as a special file format. * plug-ins/common/gbr.c: load and save brushes in the new brush format which allows RGBA brushes too. * plug-ins/common/pat.c: load and save grayscale patterns too
2000-12-18 23:14:08 +08:00
#include "gimplist.h"
static void gimp_list_class_init (GimpListClass *klass);
static void gimp_list_init (GimpList *list);
static void gimp_list_destroy (GtkObject *object);
static void gimp_list_add (GimpContainer *container,
GimpObject *object);
static void gimp_list_remove (GimpContainer *container,
GimpObject *object);
static void gimp_list_reorder (GimpContainer *container,
GimpObject *object,
gint new_index);
static gboolean gimp_list_have (GimpContainer *container,
GimpObject *object);
static void gimp_list_foreach (GimpContainer *container,
GFunc func,
gpointer user_data);
static GimpObject * gimp_list_get_child_by_name (GimpContainer *container,
gchar *name);
static GimpObject * gimp_list_get_child_by_index (GimpContainer *container,
gint index);
static gint gimp_list_get_child_index (GimpContainer *container,
GimpObject *object);
static GimpContainerClass *parent_class = NULL;
1999-10-27 02:27:27 +08:00
GtkType
gimp_list_get_type (void)
{
static GtkType list_type = 0;
1999-10-27 02:27:27 +08:00
if (! list_type)
{
GtkTypeInfo list_info =
{
"GimpList",
sizeof (GimpList),
sizeof (GimpListClass),
(GtkClassInitFunc) gimp_list_class_init,
(GtkObjectInitFunc) gimp_list_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL
};
list_type = gtk_type_unique (GIMP_TYPE_CONTAINER, &list_info);
}
return list_type;
1999-10-27 02:27:27 +08:00
}
static void
gimp_list_class_init (GimpListClass *klass)
1999-10-27 02:27:27 +08:00
{
GtkObjectClass *object_class;
GimpContainerClass *container_class;
1999-10-27 02:27:27 +08:00
object_class = (GtkObjectClass *) klass;
container_class = (GimpContainerClass *) klass;
1999-10-27 02:27:27 +08:00
parent_class = gtk_type_class (GIMP_TYPE_CONTAINER);
1999-10-27 02:27:27 +08:00
object_class->destroy = gimp_list_destroy;
container_class->add = gimp_list_add;
container_class->remove = gimp_list_remove;
container_class->reorder = gimp_list_reorder;
container_class->have = gimp_list_have;
container_class->foreach = gimp_list_foreach;
container_class->get_child_by_name = gimp_list_get_child_by_name;
container_class->get_child_by_index = gimp_list_get_child_by_index;
container_class->get_child_index = gimp_list_get_child_index;
}
static void
gimp_list_init (GimpList *list)
{
list->list = NULL;
}
static void
gimp_list_destroy (GtkObject *object)
1999-10-27 02:27:27 +08:00
{
GimpList *list;
1999-10-27 02:27:27 +08:00
list = GIMP_LIST (object);
1999-10-27 02:27:27 +08:00
while (list->list)
{
gimp_container_remove (GIMP_CONTAINER (list),
GIMP_OBJECT (list->list->data));
}
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
gimp_list_add (GimpContainer *container,
GimpObject *object)
{
GimpList *list;
list = GIMP_LIST (container);
list->list = g_list_prepend (list->list, object);
}
static void
gimp_list_remove (GimpContainer *container,
GimpObject *object)
{
GimpList *list;
list = GIMP_LIST (container);
list->list = g_list_remove (list->list, object);
}
static void
gimp_list_reorder (GimpContainer *container,
GimpObject *object,
gint new_index)
{
GimpList *list;
list = GIMP_LIST (container);
list->list = g_list_remove (list->list, object);
if (new_index == -1 || new_index == container->num_children - 1)
list->list = g_list_append (list->list, object);
else
list->list = g_list_insert (list->list, object, new_index);
}
static gboolean
gimp_list_have (GimpContainer *container,
GimpObject *object)
{
GimpList *list;
1999-10-27 02:27:27 +08:00
list = GIMP_LIST (container);
1999-10-27 02:27:27 +08:00
return g_list_find (list->list, object) ? TRUE : FALSE;
}
static void
gimp_list_foreach (GimpContainer *container,
GFunc func,
gpointer user_data)
{
GimpList *list;
1999-10-27 02:27:27 +08:00
list = GIMP_LIST (container);
1999-10-27 02:27:27 +08:00
g_list_foreach (list->list, func, user_data);
}
1999-10-27 02:27:27 +08:00
GimpList *
gimp_list_new (GtkType children_type,
GimpContainerPolicy policy)
{
GimpList *list;
g_return_val_if_fail (gtk_type_is_a (children_type, GIMP_TYPE_OBJECT), NULL);
g_return_val_if_fail (policy == GIMP_CONTAINER_POLICY_STRONG ||
policy == GIMP_CONTAINER_POLICY_WEAK, NULL);
1999-10-27 02:27:27 +08:00
list = gtk_type_new (GIMP_TYPE_LIST);
GIMP_CONTAINER (list)->children_type = children_type;
GIMP_CONTAINER (list)->policy = policy;
return list;
}
static GimpObject *
gimp_list_get_child_by_name (GimpContainer *container,
gchar *name)
1999-10-27 02:27:27 +08:00
{
GimpList *list;
GimpObject *object;
GList *glist;
list = GIMP_LIST (container);
for (glist = list->list; glist; glist = g_list_next (glist))
{
object = (GimpObject *) glist->data;
if (! strcmp (object->name, name))
return object;
}
return NULL;
}
static GimpObject *
gimp_list_get_child_by_index (GimpContainer *container,
gint index)
{
GimpList *list;
GList *glist;
list = GIMP_LIST (container);
glist = g_list_nth (list->list, index);
if (glist)
return (GimpObject *) glist->data;
return NULL;
}
static gint
gimp_list_get_child_index (GimpContainer *container,
GimpObject *object)
1999-10-27 02:27:27 +08:00
{
GimpList *list;
list = GIMP_LIST (container);
return g_list_index (list->list, (gpointer) object);
}