gimp/app/core/gimp.c

301 lines
8.1 KiB
C
Raw Normal View History

app/core/Makefile.am app/core/core-types.h added an "application object" 2001-07-04 Michael Natterer <mitch@gimp.org> * app/core/Makefile.am * app/core/core-types.h * app/core/gimp.[ch]: added an "application object" called Gimp. Currently, it contains the image list, the clipboard, the data factories, the procedural hashtable and the tool info list. It's the toplevel object of the core object system. Finally, creating a Gimp object will return a standalone gimp core engine instance with no other global states/variables involved. * app/app_procs.[ch]: allocate a "Gimp" instance called "the_gimp" :) Removed stuff which is now done by the "Gimp" object. Merged gimp_init() into app_init() because gimp_init() is taken now. * app/context_manager.[ch]: removed stuff done by "Gimp". * app/batch.[ch] * app/gimage.[ch] * app/xcf/xcf-load.[ch] * app/xcf/xcf.[ch] * app/core/gimpedit.[ch] * app/tools/tool_manager.[ch]: pass around an additional "Gimp" argument. * app/pdb/procedural_db.[ch]: pass a "Gimp" pointer as first parameter to all internal procedures and to all procedural_db_* functions. * app/core/gimpcontext.[ch] * app/core/gimpimage.[ch]: added a "Gimp" pointer to the structs. * app/devices.c * app/errors.c * app/file-open.c * app/file-save.c * app/gimphelp.c * app/gimpunit.c * app/image_new.c * app/main.c * app/nav_window.c * app/plug_in.c * app/base/base.c * app/core/gimpdatafactory.c * app/core/gimpimage-duplicate.c * app/core/gimpimage-mask.c * app/core/gimptoolinfo.[ch] * app/gui/brush-select.c * app/gui/convert-dialog.c * app/gui/dialogs-constructors.c * app/gui/edit-commands.c * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradient-select.c * app/gui/gui.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/menus.c * app/gui/palette-editor.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/paths-dialog.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/test-commands.c * app/gui/toolbox.c * app/gui/tools-commands.c * app/tools/gimpbezierselecttool.c * app/tools/gimpbucketfilltool.c * app/tools/gimppainttool.h * app/tools/gimptexttool.c * app/tools/gimptransformtool.h * app/widgets/gimpbufferview.c * app/widgets/gimpcontainerview-utils.c * app/widgets/gimpcursor.c * app/widgets/gimpdnd.c * app/widgets/gimpimagedock.c: changed accordingly. Cleaned up lots of includes. Many files still access the global "the_gimp" variable exported by app_procs.h. * tools/pdbgen/app.pl * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/palette.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb * tools/pdbgen/pdb/procedural_db.pdb: changed accordingly. Don't use "the_gimp" here because all procedures get passed a "Gimp" pointer now. * app/pdb/*: regenerated.
2001-07-05 03:31:35 +08:00
/* 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 "core-types.h"
#include "base/tile-manager.h"
#include "pdb/procedural_db.h"
#include "gimp.h"
#include "gimpbrush.h"
#include "gimpbrushgenerated.h"
#include "gimpbrushpipe.h"
#include "gimpbuffer.h"
#include "gimpdatafactory.h"
#include "gimpgradient.h"
#include "gimpimage.h"
#include "gimplist.h"
#include "gimppalette.h"
#include "gimppattern.h"
#include "gimptoolinfo.h"
#include "appenv.h"
#include "app_procs.h"
#include "gimpparasite.h"
#include "gimprc.h"
#include "libgimp/gimpintl.h"
static void gimp_class_init (GimpClass *klass);
static void gimp_init (Gimp *gimp);
static void gimp_destroy (GtkObject *object);
static GimpObjectClass *parent_class = NULL;
GtkType
gimp_get_type (void)
{
static GtkType object_type = 0;
if (! object_type)
{
GtkTypeInfo object_info =
{
"Gimp",
sizeof (Gimp),
sizeof (GimpClass),
(GtkClassInitFunc) gimp_class_init,
(GtkObjectInitFunc) gimp_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
object_type = gtk_type_unique (GIMP_TYPE_OBJECT, &object_info);
}
return object_type;
}
static void
gimp_class_init (GimpClass *klass)
{
GtkObjectClass *object_class;
object_class = (GtkObjectClass *) klass;
parent_class = gtk_type_class (GIMP_TYPE_OBJECT);
object_class->destroy = gimp_destroy;
}
static void
gimp_init (Gimp *gimp)
{
static const GimpDataFactoryLoaderEntry brush_loader_entries[] =
{
{ gimp_brush_load, GIMP_BRUSH_FILE_EXTENSION },
{ gimp_brush_load, GIMP_BRUSH_PIXMAP_FILE_EXTENSION },
{ gimp_brush_generated_load, GIMP_BRUSH_GENERATED_FILE_EXTENSION },
{ gimp_brush_pipe_load, GIMP_BRUSH_PIPE_FILE_EXTENSION }
};
static gint n_brush_loader_entries = (sizeof (brush_loader_entries) /
sizeof (brush_loader_entries[0]));
static const GimpDataFactoryLoaderEntry pattern_loader_entries[] =
{
{ gimp_pattern_load, GIMP_PATTERN_FILE_EXTENSION }
};
static gint n_pattern_loader_entries = (sizeof (pattern_loader_entries) /
sizeof (pattern_loader_entries[0]));
static const GimpDataFactoryLoaderEntry gradient_loader_entries[] =
{
{ gimp_gradient_load, GIMP_GRADIENT_FILE_EXTENSION },
{ gimp_gradient_load, NULL /* legacy loader */ }
};
static gint n_gradient_loader_entries = (sizeof (gradient_loader_entries) /
sizeof (gradient_loader_entries[0]));
static const GimpDataFactoryLoaderEntry palette_loader_entries[] =
{
{ gimp_palette_load, GIMP_PALETTE_FILE_EXTENSION },
{ gimp_palette_load, NULL /* legacy loader */ }
};
static gint n_palette_loader_entries = (sizeof (palette_loader_entries) /
sizeof (palette_loader_entries[0]));
gimp->images = gimp_list_new (GIMP_TYPE_IMAGE,
GIMP_CONTAINER_POLICY_WEAK);
gtk_object_ref (GTK_OBJECT (gimp->images));
gtk_object_sink (GTK_OBJECT (gimp->images));
gimp->global_buffer = NULL;
gimp->named_buffers = gimp_list_new (GIMP_TYPE_BUFFER,
GIMP_CONTAINER_POLICY_STRONG);
gtk_object_ref (GTK_OBJECT (gimp->named_buffers));
gtk_object_sink (GTK_OBJECT (gimp->named_buffers));
gimp->brush_factory =
gimp_data_factory_new (GIMP_TYPE_BRUSH,
(const gchar **) &gimprc.brush_path,
brush_loader_entries,
n_brush_loader_entries,
gimp_brush_new,
gimp_brush_get_standard);
gtk_object_ref (GTK_OBJECT (gimp->brush_factory));
gtk_object_sink (GTK_OBJECT (gimp->brush_factory));
gimp->pattern_factory =
gimp_data_factory_new (GIMP_TYPE_PATTERN,
(const gchar **) &gimprc.pattern_path,
pattern_loader_entries,
n_pattern_loader_entries,
gimp_pattern_new,
gimp_pattern_get_standard);
gtk_object_ref (GTK_OBJECT (gimp->pattern_factory));
gtk_object_sink (GTK_OBJECT (gimp->pattern_factory));
gimp->gradient_factory =
gimp_data_factory_new (GIMP_TYPE_GRADIENT,
(const gchar **) &gimprc.gradient_path,
gradient_loader_entries,
n_gradient_loader_entries,
gimp_gradient_new,
gimp_gradient_get_standard);
gtk_object_ref (GTK_OBJECT (gimp->gradient_factory));
gtk_object_sink (GTK_OBJECT (gimp->gradient_factory));
gimp->palette_factory =
gimp_data_factory_new (GIMP_TYPE_PALETTE,
(const gchar **) &gimprc.palette_path,
palette_loader_entries,
n_palette_loader_entries,
gimp_palette_new,
gimp_palette_get_standard);
gtk_object_ref (GTK_OBJECT (gimp->palette_factory));
gtk_object_sink (GTK_OBJECT (gimp->palette_factory));
procedural_db_init (gimp);
gimp->tool_info_list = gimp_list_new (GIMP_TYPE_TOOL_INFO,
GIMP_CONTAINER_POLICY_STRONG);
gtk_object_ref (GTK_OBJECT (gimp->tool_info_list));
gtk_object_sink (GTK_OBJECT (gimp->tool_info_list));
}
static void
gimp_destroy (GtkObject *object)
{
Gimp *gimp;
gimp = GIMP (object);
if (gimp->tool_info_list)
{
gtk_object_unref (GTK_OBJECT (gimp->tool_info_list));
gimp->tool_info_list = NULL;
}
procedural_db_free (gimp);
if (gimp->brush_factory)
{
gimp_data_factory_data_free (gimp->brush_factory);
gtk_object_unref (GTK_OBJECT (gimp->brush_factory));
gimp->brush_factory = NULL;
}
if (gimp->pattern_factory)
{
gimp_data_factory_data_free (gimp->pattern_factory);
gtk_object_unref (GTK_OBJECT (gimp->pattern_factory));
gimp->pattern_factory = NULL;
}
if (gimp->gradient_factory)
{
gimp_data_factory_data_free (gimp->gradient_factory);
gtk_object_unref (GTK_OBJECT (gimp->gradient_factory));
gimp->gradient_factory = NULL;
}
if (gimp->palette_factory)
{
gimp_data_factory_data_free (gimp->palette_factory);
gtk_object_unref (GTK_OBJECT (gimp->palette_factory));
gimp->palette_factory = NULL;
}
if (gimp->named_buffers)
{
gtk_object_unref (GTK_OBJECT (gimp->named_buffers));
gimp->named_buffers = NULL;
}
if (gimp->global_buffer)
{
tile_manager_destroy (gimp->global_buffer);
gimp->global_buffer = NULL;
}
if (gimp->images)
{
gtk_object_unref (GTK_OBJECT (gimp->images));
gimp->images = NULL;
}
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
Gimp *
gimp_new (void)
{
Gimp *gimp;
gimp = gtk_type_new (GIMP_TYPE_GIMP);
return gimp;
}
void
gimp_initialize (Gimp *gimp)
{
g_return_if_fail (gimp != NULL);
g_return_if_fail (GIMP_IS_GIMP (gimp));
/* initialize the global parasite table */
app_init_update_status (_("Looking for data files"), _("Parasites"), 0.00);
gimp_init_parasites ();
/* initialize the list of gimp brushes */
app_init_update_status (NULL, _("Brushes"), 0.20);
gimp_data_factory_data_init (gimp->brush_factory, no_data);
/* initialize the list of gimp patterns */
app_init_update_status (NULL, _("Patterns"), 0.40);
gimp_data_factory_data_init (gimp->pattern_factory, no_data);
/* initialize the list of gimp palettes */
app_init_update_status (NULL, _("Palettes"), 0.60);
gimp_data_factory_data_init (gimp->palette_factory, no_data);
/* initialize the list of gimp gradients */
app_init_update_status (NULL, _("Gradients"), 0.80);
gimp_data_factory_data_init (gimp->gradient_factory, no_data);
app_init_update_status (NULL, NULL, 1.00);
}