mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-23 04:51:44 +00:00
05e15eb1cc
2001-10-29 Michael Natterer <mitch@gimp.org> Cleanup weekend... * app/app_procs.c: pass "no_interface" to gimp_new(). * app/core/gimp.[ch]: added "gboolean no_interface" and the load_procs and save_procs GSLists. * app/core/gimptoolinfo.[ch]: added a "Gimp" pointer to the GimpToolInfo object so more functions find their context without accessing the global "the_gimp" variable. * app/display/display-types.h: removed the GDisplay -> GimpDisplay typedef. * app/display/gimpdisplay.c: look at gimp->no_interface, don't include "appenv.h". * app/file/file-open.[ch] * app/file/file-save.[ch]: don't use "the_gimp" any more. Instead, pass around lots of "Gimp" pointers. Removed the global load_procs and save_procs variables here. Use access() to find out whether a file is readable/writable, removed the manual voodoo and it's Win32 wrappers. Added an optional (can be NULL) "PlunInProcDef" parameter to file_save(), removed file_save_with_proc(). * app/gui/menus.c: Use the unused "gpointer data" parameter of the GtkItemFactory callbacks to pass a "Gimp" pointer to all of them. This reduces the usage of the global "the_gimp" hack to zero in app/gui/... yeah. * app/gui/channels-commands.c * app/gui/edit-commands.c * app/gui/file-commands.c * app/gui/image-commands.c * app/gui/layers-commands.c * app/gui/palettes-commands.c * app/gui/select-commands.c * app/gui/test-commands.c * app/gui/tools-commands.c * app/gui/view-commands.c: use the passed "Gimp" pointer. * app/gui/color-area.[ch] * app/gui/convert-dialog.c * app/gui/dialogs-constructors.c * app/gui/file-new-dialog.[ch] * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.[ch] * app/gui/gui.c * app/gui/info-window.[ch] * app/gui/module-browser.[ch] * app/gui/palette-editor.c * app/gui/palette-import-dialog.[ch] * app/gui/paths-dialog.c * app/gui/preferences-dialog.[ch] * app/gui/resize-dialog.[ch] * app/gui/tool-options-dialog.[ch] * app/gui/toolbox.c: pass around lots more "Gimp" and "GimpContext" pointers and don't use "the_gimp" any more. * app/tools/gimptool.h: added a pointer to the corresponding GimpToolInfo object (which in turn has a pointer to a Gimp). * app/tools/tool_manager.[ch]: set the pointer after creating the tool object. Removed tool_manager_get_info_by_tool() as there is a tool->tool_info pointer now. * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpclonetool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpconvolvetool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimpdodgeburntool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpellipseselecttool.c * app/tools/gimperasertool.c * app/tools/gimpfliptool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpinktool.c * app/tools/gimplevelstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimpperspectivetool.c * app/tools/gimpposterizetool.c * app/tools/gimprectselecttool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpsheartool.c * app/tools/gimptexttool.c * app/tools/gimpthresholdtool.c * app/tools/path_tool.c * app/tools/xinput_airbrush.c: s/GDisplay/GimpDisplay/g. Use tool->tool_info and tool_info->gimp in some places to get rid of using "the_gimp". Removing the remaining ones involves changing the tool options system and is scheduled next... * app/widgets/gimpdnd.c * app/widgets/gimpdocumentview.c: pass a "Gimp" pointer to all file_open_*() functions. * app/gdisplay_color.[ch] * app/gdisplay_color_ui.[ch] * app/image_map.[ch] * app/nav_window.[ch] * app/path.c * app/path_bezier.c * app/path_transform.h * app/qmask.[ch]: s/GDisplay/GimpDisplay/g * tools/pdbgen/pdb/fileops.pdb: load_procs and save_procs are members of the "Gimp" object now. * tools/pdbgen/pdb/plug_in.pdb: use gimp->no_interface, don't include "appenv.h". * app/pdb/fileops_cmds.c * app/pdb/plug_in_cmds.c: regenerated.
366 lines
8.1 KiB
C
366 lines
8.1 KiB
C
/* The GIMP -- an image manipulation program
|
|
* Copyright (C) 1999 Manish Singh
|
|
*
|
|
* 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 <gmodule.h>
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
#include "apptypes.h"
|
|
#include "gdisplay_color.h"
|
|
#include "gdisplay.h"
|
|
#include "gimpimageP.h"
|
|
#include "gimpui.h"
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
typedef struct _ColorDisplayInfo ColorDisplayInfo;
|
|
|
|
struct _ColorDisplayInfo
|
|
{
|
|
gchar *name;
|
|
GimpColorDisplayMethods methods;
|
|
GSList *refs;
|
|
};
|
|
|
|
static GHashTable *color_display_table = NULL;
|
|
|
|
static void color_display_foreach_real (gpointer key,
|
|
gpointer value,
|
|
gpointer user_data);
|
|
static void gdisplay_color_detach_real (GimpDisplay *gdisp,
|
|
ColorDisplayNode *node,
|
|
gboolean unref);
|
|
static gint node_name_compare (ColorDisplayNode *node,
|
|
const gchar *name);
|
|
|
|
void
|
|
color_display_init (void)
|
|
{
|
|
}
|
|
|
|
G_MODULE_EXPORT gboolean
|
|
gimp_color_display_register (const gchar *name,
|
|
GimpColorDisplayMethods *methods)
|
|
{
|
|
ColorDisplayInfo *info;
|
|
|
|
info = g_new (ColorDisplayInfo, 1);
|
|
|
|
info->name = g_strdup (name);
|
|
info->methods = *methods;
|
|
info->refs = NULL;
|
|
|
|
if (!color_display_table)
|
|
color_display_table = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
if (g_hash_table_lookup (color_display_table, name))
|
|
return FALSE;
|
|
|
|
if (!methods->convert)
|
|
return FALSE;
|
|
|
|
g_hash_table_insert (color_display_table, info->name, info);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
G_MODULE_EXPORT gboolean
|
|
gimp_color_display_unregister (const gchar *name)
|
|
{
|
|
ColorDisplayInfo *info;
|
|
GimpDisplay *gdisp;
|
|
GList *node;
|
|
|
|
if ((info = g_hash_table_lookup (color_display_table, name)))
|
|
{
|
|
GSList *refs = info->refs;
|
|
|
|
while (refs)
|
|
{
|
|
gdisp = (GimpDisplay *) refs->data;
|
|
|
|
node = g_list_find_custom (gdisp->cd_list, (gpointer) name,
|
|
(GCompareFunc) node_name_compare);
|
|
gdisp->cd_list = g_list_remove_link (gdisp->cd_list, node);
|
|
|
|
gdisplay_color_detach_real (gdisp, node->data, FALSE);
|
|
|
|
g_list_free_1 (node);
|
|
|
|
refs = refs->next;
|
|
}
|
|
|
|
g_slist_free (info->refs);
|
|
|
|
g_hash_table_remove (color_display_table, name);
|
|
|
|
g_free (info->name);
|
|
g_free (info);
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
typedef struct _DisplayForeachData DisplayForeachData;
|
|
|
|
struct _DisplayForeachData
|
|
{
|
|
GimpCDFunc func;
|
|
gpointer user_data;
|
|
};
|
|
|
|
void
|
|
color_display_foreach (GimpCDFunc func,
|
|
gpointer user_data)
|
|
{
|
|
DisplayForeachData data;
|
|
|
|
data.func = func;
|
|
data.user_data = user_data;
|
|
|
|
g_hash_table_foreach (color_display_table, color_display_foreach_real, &data);
|
|
}
|
|
|
|
static void
|
|
color_display_foreach_real (gpointer key,
|
|
gpointer value,
|
|
gpointer user_data)
|
|
{
|
|
DisplayForeachData *data = (DisplayForeachData *) user_data;
|
|
data->func (key, data->user_data);
|
|
}
|
|
|
|
ColorDisplayNode *
|
|
gdisplay_color_attach (GimpDisplay *gdisp,
|
|
const gchar *name)
|
|
{
|
|
ColorDisplayInfo *info;
|
|
ColorDisplayNode *node;
|
|
|
|
g_return_val_if_fail (gdisp != NULL, NULL);
|
|
|
|
if ((info = g_hash_table_lookup (color_display_table, name)))
|
|
{
|
|
node = g_new (ColorDisplayNode, 1);
|
|
|
|
node->cd_name = g_strdup (name);
|
|
node->cd_ID = NULL;
|
|
|
|
if (!info->refs && info->methods.init)
|
|
info->methods.init ();
|
|
|
|
info->refs = g_slist_append (info->refs, gdisp);
|
|
|
|
if (info->methods.new)
|
|
node->cd_ID = info->methods.new (gdisp->gimage->base_type);
|
|
|
|
node->cd_convert = info->methods.convert;
|
|
|
|
gdisp->cd_list = g_list_append (gdisp->cd_list, node);
|
|
|
|
return node;
|
|
}
|
|
else
|
|
g_warning ("Tried to attach a nonexistant color display");
|
|
|
|
return NULL;
|
|
}
|
|
|
|
ColorDisplayNode *
|
|
gdisplay_color_attach_clone (GimpDisplay *gdisp,
|
|
ColorDisplayNode *node)
|
|
{
|
|
ColorDisplayInfo *info;
|
|
ColorDisplayNode *clone;
|
|
|
|
g_return_val_if_fail (gdisp != NULL, NULL);
|
|
g_return_val_if_fail (node != NULL, NULL);
|
|
|
|
if ((info = g_hash_table_lookup (color_display_table, node->cd_name)))
|
|
{
|
|
clone = g_new (ColorDisplayNode, 1);
|
|
|
|
clone->cd_name = g_strdup (node->cd_name);
|
|
clone->cd_ID = NULL;
|
|
|
|
info->refs = g_slist_append (info->refs, gdisp);
|
|
|
|
if (info->methods.clone)
|
|
node->cd_ID = info->methods.clone (node->cd_ID);
|
|
|
|
node->cd_convert = info->methods.convert;
|
|
|
|
gdisp->cd_list = g_list_append (gdisp->cd_list, node);
|
|
|
|
return node;
|
|
}
|
|
else
|
|
g_warning ("Tried to clone a nonexistant color display");
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void
|
|
gdisplay_color_detach (GimpDisplay *gdisp,
|
|
ColorDisplayNode *node)
|
|
{
|
|
g_return_if_fail (gdisp != NULL);
|
|
|
|
gdisp->cd_list = g_list_remove (gdisp->cd_list, node);
|
|
}
|
|
|
|
void
|
|
gdisplay_color_detach_destroy (GimpDisplay *gdisp,
|
|
ColorDisplayNode *node)
|
|
{
|
|
g_return_if_fail (gdisp != NULL);
|
|
|
|
gdisplay_color_detach_real (gdisp, node, TRUE);
|
|
gdisp->cd_list = g_list_remove (gdisp->cd_list, node);
|
|
}
|
|
|
|
void
|
|
gdisplay_color_detach_all (GimpDisplay *gdisp)
|
|
{
|
|
GList *list;
|
|
|
|
g_return_if_fail (gdisp != NULL);
|
|
|
|
list = gdisp->cd_list;
|
|
|
|
while (list)
|
|
{
|
|
gdisplay_color_detach_real (gdisp, list->data, TRUE);
|
|
list = list->next;
|
|
}
|
|
|
|
g_list_free (gdisp->cd_list);
|
|
gdisp->cd_list = NULL;
|
|
}
|
|
|
|
static void
|
|
gdisplay_color_detach_real (GimpDisplay *gdisp,
|
|
ColorDisplayNode *node,
|
|
gboolean unref)
|
|
{
|
|
ColorDisplayInfo *info;
|
|
|
|
g_return_if_fail (gdisp != NULL);
|
|
g_return_if_fail (node != NULL);
|
|
|
|
if ((info = g_hash_table_lookup (color_display_table, node->cd_name)))
|
|
{
|
|
if (info->methods.destroy)
|
|
info->methods.destroy (node->cd_ID);
|
|
|
|
if (unref)
|
|
info->refs = g_slist_remove (info->refs, gdisp);
|
|
|
|
if (!info->refs && info->methods.finalize)
|
|
info->methods.finalize ();
|
|
}
|
|
|
|
g_free (node->cd_name);
|
|
g_free (node);
|
|
}
|
|
|
|
void
|
|
gdisplay_color_reorder_up (GimpDisplay *gdisp,
|
|
ColorDisplayNode *node)
|
|
{
|
|
GList *node_list;
|
|
|
|
node_list = g_list_find (gdisp->cd_list, node);
|
|
|
|
if (node_list->prev)
|
|
{
|
|
node_list->data = node_list->prev->data;
|
|
node_list->prev->data = node;
|
|
}
|
|
}
|
|
|
|
void
|
|
gdisplay_color_reorder_down (GimpDisplay *gdisp,
|
|
ColorDisplayNode *node)
|
|
{
|
|
GList *node_list;
|
|
|
|
g_return_if_fail (gdisp != NULL);
|
|
|
|
node_list = g_list_find (gdisp->cd_list, node);
|
|
|
|
if (node_list->next)
|
|
{
|
|
node_list->data = node_list->next->data;
|
|
node_list->next->data = node;
|
|
}
|
|
}
|
|
|
|
static gint
|
|
node_name_compare (ColorDisplayNode *node,
|
|
const char *name)
|
|
{
|
|
return strcmp (node->cd_name, name);
|
|
}
|
|
|
|
void
|
|
gdisplay_color_configure (ColorDisplayNode *node,
|
|
GFunc ok_func,
|
|
gpointer ok_data,
|
|
GFunc cancel_func,
|
|
gpointer cancel_data)
|
|
{
|
|
ColorDisplayInfo *info;
|
|
|
|
g_return_if_fail (node != NULL);
|
|
|
|
if ((info = g_hash_table_lookup (color_display_table, node->cd_name)))
|
|
{
|
|
if (info->methods.configure)
|
|
info->methods.configure (node->cd_ID,
|
|
ok_func, ok_data,
|
|
cancel_func, cancel_data);
|
|
}
|
|
else
|
|
g_warning ("Tried to configure a nonexistant color display");
|
|
|
|
return;
|
|
}
|
|
|
|
void
|
|
gdisplay_color_configure_cancel (ColorDisplayNode *node)
|
|
{
|
|
ColorDisplayInfo *info;
|
|
|
|
g_return_if_fail (node != NULL);
|
|
|
|
if ((info = g_hash_table_lookup (color_display_table, node->cd_name)))
|
|
{
|
|
if (info->methods.cancel)
|
|
info->methods.cancel (node->cd_ID);
|
|
}
|
|
else
|
|
g_warning ("Tried to configure cancel a nonexistant color display");
|
|
|
|
return;
|
|
}
|