Commit 68216c6f authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Made a GimpContainer out of the palette list:

2001-02-11  Michael Natterer  <mitch@gimp.org>

	Made a GimpContainer out of the palette list:

	* app/Makefile.am
	* app/palettes.[ch]: new files for the global palette list.

	* app/gimpgradientpreview.[ch]
	* app/gimppalettepreview.[ch]: new widgets.

	* app/gimppalette.[ch]: derive it from GimpData to get all the
	preview etc. stuff.

	* app/datafiles.[ch]: new function datafiles_check_extension(),
	added a "loader_data" parameter to datafiles_read_directories()
	and pass it to the loader function.

	* app/gimpcontext.[ch]: added the palette (not really used yet
	except by the test dialogs).

	* app/gimpdatalist.[ch]: new function gimp_data_list_save_and_clear()
	which does everything needed for patterns_free(), brushes_free() ...

	* app/gimpdnd.c: added palette DND.

	* app/app_procs.c
	* app/brushes.c
	* app/color_notebook.h
	* app/commands.c
	* app/convert.c
	* app/gimpbrush.h
	* app/gimpbrushpipe.h
	* app/gimpgradient.c
	* app/gimppattern.h
	* app/gimppreview.c
	* app/gradients.c
	* app/module_db.c
	* app/palette.[ch]
	* app/paletteP.h
	* app/palette_import.c
	* app/palette_select.[ch]
	* app/patterns.c
	* app/plug_in.c
	* app/pdb/convert_cmds.c
	* app/pdb/palette_cmds.c
	* tools/pdbgen/pdb/convert.pdb
	* tools/pdbgen/pdb/palette.pdb: lotsa stuff: changed due to the above
	API changes, #define the file extensions in the GimpData subclasses'
	header files instead of hardcoding them in several places, ...

	* data/palettes/*: The same file format change as for the gradient
	files:

	- Save the palette name in a parsable form (as part of the file
	  format, not in a comment.
	- Removed unserscores from the palette names.
	- Added an extension (Gimp PaLettes are ".gpl" files now ;-)
parent 0f1e1535
2001-02-11 Michael Natterer <mitch@gimp.org>
Made a GimpContainer out of the palette list:
* app/Makefile.am
* app/palettes.[ch]: new files for the global palette list.
* app/gimpgradientpreview.[ch]
* app/gimppalettepreview.[ch]: new widgets.
* app/gimppalette.[ch]: derive it from GimpData to get all the
preview etc. stuff.
* app/datafiles.[ch]: new function datafiles_check_extension(),
added a "loader_data" parameter to datafiles_read_directories()
and pass it to the loader function.
* app/gimpcontext.[ch]: added the palette (not really used yet
except by the test dialogs).
* app/gimpdatalist.[ch]: new function gimp_data_list_save_and_clear()
which does everything needed for patterns_free(), brushes_free() ...
* app/gimpdnd.c: added palette DND.
* app/app_procs.c
* app/brushes.c
* app/color_notebook.h
* app/commands.c
* app/convert.c
* app/gimpbrush.h
* app/gimpbrushpipe.h
* app/gimpgradient.c
* app/gimppattern.h
* app/gimppreview.c
* app/gradients.c
* app/module_db.c
* app/palette.[ch]
* app/paletteP.h
* app/palette_import.c
* app/palette_select.[ch]
* app/patterns.c
* app/plug_in.c
* app/pdb/convert_cmds.c
* app/pdb/palette_cmds.c
* tools/pdbgen/pdb/convert.pdb
* tools/pdbgen/pdb/palette.pdb: lotsa stuff: changed due to the above
API changes, #define the file extensions in the GimpData subclasses'
header files instead of hardcoding them in several places, ...
* data/palettes/*: The same file format change as for the gradient
files:
- Save the palette name in a parsable form (as part of the file
format, not in a comment.
- Removed unserscores from the palette names.
- Added an extension (Gimp PaLettes are ".gpl" files now ;-)
2001-02-11 Michael Natterer <mitch@gimp.org>
* app/Makefile.am
......
......@@ -216,6 +216,8 @@ gimp_SOURCES = \
palette_import.h \
palette_select.c \
palette_select.h \
palettes.c \
palettes.h \
paletteP.h \
parasitelist.c \
parasitelist.h \
......@@ -297,8 +299,12 @@ gimp_SOURCES = \
gimpcontainerview.c \
gimpdrawablepreview.c \
gimpdrawablepreview.h \
gimpgradientpreview.h \
gimpgradientpreview.c \
gimpimagepreview.h \
gimpimagepreview.c \
gimppalettepreview.h \
gimppalettepreview.c \
gimppatternpreview.h \
gimppatternpreview.c \
gimppreview.h \
......
......@@ -79,6 +79,7 @@
/* for the example dialogs */
#include "brushes.h"
#include "gradients.h"
#include "palettes.h"
#include "patterns.h"
#include "gimpcontainer.h"
#include "gimpcontainerlistview.h"
......@@ -1406,6 +1407,26 @@ gradients_callback (GtkWidget *widget,
NULL);
}
static void
palettes_callback (GtkWidget *widget,
GimpContainerView *view)
{
gtk_drag_dest_unset (GTK_WIDGET (view));
gimp_dnd_viewable_dest_unset (GTK_WIDGET (view),
view->container->children_type);
gimp_container_view_set_container (view, global_palette_list);
gimp_gtk_drag_dest_set_by_type (GTK_WIDGET (view),
GTK_DEST_DEFAULT_ALL,
view->container->children_type,
GDK_ACTION_COPY);
gimp_dnd_viewable_dest_set (GTK_WIDGET (view),
view->container->children_type,
drop_viewable_callback,
NULL);
}
static void
images_callback (GtkWidget *widget,
GimpContainerView *view)
......@@ -1595,6 +1616,24 @@ container_multi_view_new (gboolean list,
GTK_SIGNAL_FUNC (gimp_preview_set_viewable),
GTK_OBJECT (preview));
preview =
gimp_preview_new_full (GIMP_VIEWABLE (gimp_context_get_palette (context)),
32, 32, 1,
FALSE, TRUE, FALSE);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), preview,
FALSE, FALSE, 0);
gtk_widget_show (preview);
gtk_signal_connect (GTK_OBJECT (preview), "clicked",
GTK_SIGNAL_FUNC (palettes_callback),
view);
gtk_signal_connect_object_while_alive
(GTK_OBJECT (context),
"palette_changed",
GTK_SIGNAL_FUNC (gimp_preview_set_viewable),
GTK_OBJECT (preview));
/*
preview =
gimp_preview_new_full (GIMP_VIEWABLE (gimp_context_get_image (context)),
......
......@@ -150,7 +150,8 @@ static void plug_in_handle_proc_return (GPProcReturn *proc_return);
static void plug_in_handle_proc_install (GPProcInstall *proc_install);
static void plug_in_handle_proc_uninstall (GPProcUninstall *proc_uninstall);
static void plug_in_write_rc (const gchar *filename);
static void plug_in_init_file (const gchar *filename);
static void plug_in_init_file (const gchar *filename,
gpointer loader_data);
static void plug_in_query (PlugInDef *plug_in_def);
static void plug_in_add_to_db (void);
static void plug_in_make_menu (void);
......@@ -315,7 +316,8 @@ plug_in_init (void)
plug_in_init_shm ();
/* search for binaries in the plug-in directory path */
datafiles_read_directories (plug_in_path, plug_in_init_file, MODE_EXECUTABLE);
datafiles_read_directories (plug_in_path, MODE_EXECUTABLE,
plug_in_init_file, NULL);
/* read the pluginrc file for cached data */
filename = NULL;
......@@ -2336,7 +2338,8 @@ plug_in_write_rc (const gchar *filename)
}
static void
plug_in_init_file (const gchar *filename)
plug_in_init_file (const gchar *filename,
gpointer loader_data)
{
GSList *tmp;
PlugInDef *plug_in_def;
......
......@@ -69,6 +69,7 @@
#include "lc_dialog.h"
#include "menus.h"
#include "paint_funcs.h"
#include "palettes.h"
#include "palette.h"
#include "pattern_select.h"
#include "patterns.h"
......
......@@ -42,15 +42,17 @@
#include "libgimp/gimpintl.h"
/* local function prototypes */
static void brushes_brush_load (const gchar *filename,
gpointer loader_data);
/* global variables */
GimpContainer *global_brush_list = NULL;
/* local function prototypes */
static void brushes_brush_load (const gchar *filename);
/* public functions */
/* function declarations */
void
brushes_init (gboolean no_data)
{
......@@ -63,8 +65,11 @@ brushes_init (gboolean no_data)
{
brush_select_freeze_all ();
datafiles_read_directories (brush_path, brushes_brush_load, 0);
datafiles_read_directories (brush_vbr_path, brushes_brush_load, 0);
datafiles_read_directories (brush_path, 0,
brushes_brush_load, global_brush_list);
datafiles_read_directories (brush_vbr_path, 0,
brushes_brush_load, global_brush_list);
brush_select_thaw_all ();
}
......@@ -72,6 +77,21 @@ brushes_init (gboolean no_data)
gimp_context_refresh_brushes ();
}
void
brushes_free (void)
{
if (! global_brush_list)
return;
brush_select_freeze_all ();
gimp_data_list_save_and_clear (GIMP_DATA_LIST (global_brush_list),
brush_vbr_path,
GIMP_BRUSH_GENERATED_FILE_EXTENSION);
brush_select_thaw_all ();
}
GimpBrush *
brushes_get_standard_brush (void)
{
......@@ -93,27 +113,33 @@ brushes_get_standard_brush (void)
return standard_brush;
}
/* private functions */
static void
brushes_brush_load (const gchar *filename)
brushes_brush_load (const gchar *filename,
gpointer loader_data)
{
GimpBrush *brush = NULL;
if (strcmp (&filename[strlen (filename) - 4], ".gbr") == 0 ||
strcmp (&filename[strlen (filename) - 4], ".gpb") == 0)
if (datafiles_check_extension (filename, GIMP_BRUSH_FILE_EXTENSION) ||
datafiles_check_extension (filename, GIMP_BRUSH_PIXMAP_FILE_EXTENSION))
{
brush = gimp_brush_load (filename);
if (! brush)
g_message (_("Warning: Failed to load brush\n\"%s\""), filename);
}
else if (strcmp (&filename[strlen(filename) - 4], ".vbr") == 0)
else if (datafiles_check_extension (filename,
GIMP_BRUSH_GENERATED_FILE_EXTENSION))
{
brush = gimp_brush_generated_load (filename);
if (! brush)
g_message (_("Warning: Failed to load brush\n\"%s\""), filename);
}
else if (strcmp (&filename[strlen (filename) - 4], ".gih") == 0)
else if (datafiles_check_extension (filename,
GIMP_BRUSH_PIPE_FILE_EXTENSION))
{
brush = gimp_brush_pipe_load (filename);
......@@ -121,35 +147,6 @@ brushes_brush_load (const gchar *filename)
g_message (_("Warning: Failed to load brush pipe\n\"%s\""), filename);
}
if (brush != NULL)
gimp_container_add (global_brush_list, GIMP_OBJECT (brush));
}
void
brushes_free (void)
{
if (! global_brush_list)
return;
brush_select_freeze_all ();
while (GIMP_LIST (global_brush_list)->list)
{
GimpData *data;
data = GIMP_DATA (GIMP_LIST (global_brush_list)->list->data);
if (! GIMP_DATA (data)->filename)
gimp_data_create_filename (data,
GIMP_OBJECT (data)->name,
GIMP_BRUSH_GENERATED_FILE_EXTENSION,
brush_path);
if (data->dirty)
gimp_data_save (data);
gimp_container_remove (global_brush_list, GIMP_OBJECT (data));
}
brush_select_thaw_all ();
if (brush)
gimp_container_add (GIMP_CONTAINER (loader_data), GIMP_OBJECT (brush));
}
......@@ -20,6 +20,9 @@
#define __COLOR_NOTEBOOK_H__
#include <stdio.h> /* for FILE */
typedef enum
{
COLOR_NOTEBOOK_OK,
......
......@@ -79,6 +79,7 @@
/* for the example dialogs */
#include "brushes.h"
#include "gradients.h"
#include "palettes.h"
#include "patterns.h"
#include "gimpcontainer.h"
#include "gimpcontainerlistview.h"
......@@ -1406,6 +1407,26 @@ gradients_callback (GtkWidget *widget,
NULL);
}
static void
palettes_callback (GtkWidget *widget,
GimpContainerView *view)
{
gtk_drag_dest_unset (GTK_WIDGET (view));
gimp_dnd_viewable_dest_unset (GTK_WIDGET (view),
view->container->children_type);
gimp_container_view_set_container (view, global_palette_list);
gimp_gtk_drag_dest_set_by_type (GTK_WIDGET (view),
GTK_DEST_DEFAULT_ALL,
view->container->children_type,
GDK_ACTION_COPY);
gimp_dnd_viewable_dest_set (GTK_WIDGET (view),
view->container->children_type,
drop_viewable_callback,
NULL);
}
static void
images_callback (GtkWidget *widget,
GimpContainerView *view)
......@@ -1595,6 +1616,24 @@ container_multi_view_new (gboolean list,
GTK_SIGNAL_FUNC (gimp_preview_set_viewable),
GTK_OBJECT (preview));
preview =
gimp_preview_new_full (GIMP_VIEWABLE (gimp_context_get_palette (context)),
32, 32, 1,
FALSE, TRUE, FALSE);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), preview,
FALSE, FALSE, 0);
gtk_widget_show (preview);
gtk_signal_connect (GTK_OBJECT (preview), "clicked",
GTK_SIGNAL_FUNC (palettes_callback),
view);
gtk_signal_connect_object_while_alive
(GTK_OBJECT (context),
"palette_changed",
GTK_SIGNAL_FUNC (gimp_preview_set_viewable),
GTK_OBJECT (preview));
/*
preview =
gimp_preview_new_full (GIMP_VIEWABLE (gimp_context_get_image (context)),
......
......@@ -104,9 +104,10 @@
#include "gdisplay.h"
#include "gimpdrawable.h"
#include "gimpimage.h"
#include "gimplist.h"
#include "gimplayer.h"
#include "gimppalette.h"
#include "palette.h"
#include "palettes.h"
#include "palette_select.h"
#include "pixel_region.h"
#include "tile_manager.h"
......@@ -783,7 +784,7 @@ convert_to_indexed (GimpImage *gimage)
static GtkWidget *
build_palette_button (void)
{
GSList *list;
GList *list;
GimpPalette *palette;
GimpPalette *theWebPalette = NULL;
gint i;
......@@ -791,21 +792,19 @@ build_palette_button (void)
UserHasWebPal = FALSE;
if (!palettes_list)
{
palettes_init (FALSE);
}
if (! global_palette_list)
palettes_init (FALSE);
list = palettes_list;
list = GIMP_LIST (global_palette_list)->list;
if (!list)
if (! list)
{
return NULL;
}
for (i = 0, list = palettes_list, default_palette = -1;
for (i = 0, default_palette = -1;
list;
i++, list = g_slist_next (list))
i++, list = g_list_next (list))
{
palette = (GimpPalette *) list->data;
......@@ -838,9 +837,9 @@ build_palette_button (void)
}
else
{
for (i = 0, list = palettes_list;
for (i = 0, list = GIMP_LIST (global_palette_list)->list;
list && default_palette == -1;
i++, list = g_slist_next (list))
i++, list = g_list_next (list))
{
palette = (GimpPalette *) list->data;
......
......@@ -23,6 +23,10 @@
#include "gimpdata.h"
#define GIMP_BRUSH_FILE_EXTENSION ".gbr"
#define GIMP_BRUSH_PIXMAP_FILE_EXTENSION ".gpb"
#define GIMP_TYPE_BRUSH (gimp_brush_get_type ())
#define GIMP_BRUSH(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_BRUSH, GimpBrush))
#define GIMP_BRUSH_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GIMP_TYPE_BRUSH, GimpBrushClass))
......
......@@ -24,6 +24,9 @@
#include "gimpbrush.h"
#define GIMP_BRUSH_PIPE_FILE_EXTENSION ".gih"
#define GIMP_TYPE_BRUSH_PIPE (gimp_brush_pipe_get_type ())
#define GIMP_BRUSH_PIPE(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_PIPE, GimpBrushPipe))
#define GIMP_BRUSH_PIPE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GIMP_TYPE_BRUSH_PIPE, GimpBrushPipeClass))
......
......@@ -35,9 +35,11 @@
#include "gimpgradient.h"
#include "gimpimage.h"
#include "gimpmarshal.h"
#include "gimppalette.h"
#include "gimppattern.h"
#include "gimprc.h"
#include "gradients.h"
#include "palettes.h"
#include "patterns.h"
#include "temp_buf.h"
......@@ -144,6 +146,17 @@ static void gimp_context_real_set_gradient (GimpContext *context,
static void gimp_context_copy_gradient (GimpContext *src,
GimpContext *dest);
/* palette */
static void gimp_context_palette_dirty (GimpPalette *palette,
GimpContext *context);
static void gimp_context_palette_removed (GimpContainer *brush_list,
GimpPalette *palatte,
GimpContext *context);
static void gimp_context_real_set_palette (GimpContext *context,
GimpPalette *palatte);
static void gimp_context_copy_palette (GimpContext *src,
GimpContext *dest);
/* arguments & signals */
......@@ -159,7 +172,8 @@ enum
ARG_PAINT_MODE,
ARG_BRUSH,
ARG_PATTERN,
ARG_GRADIENT
ARG_GRADIENT,
ARG_PALETTE
};
enum
......@@ -174,6 +188,7 @@ enum
BRUSH_CHANGED,
PATTERN_CHANGED,
GRADIENT_CHANGED,
PALETTE_CHANGED,
LAST_SIGNAL
};
......@@ -188,7 +203,8 @@ static gchar *gimp_context_arg_names[] =
"GimpContext::paint_mode",
"GimpContext::brush",
"GimpContext::pattern",
"GimpContext::gradient"
"GimpContext::gradient",
"GimpContext::palette"
};
static GimpContextCopyArgFunc gimp_context_copy_arg_funcs[] =
......@@ -202,7 +218,8 @@ static GimpContextCopyArgFunc gimp_context_copy_arg_funcs[] =
gimp_context_copy_paint_mode,
gimp_context_copy_brush,
gimp_context_copy_pattern,
gimp_context_copy_gradient
gimp_context_copy_gradient,
gimp_context_copy_palette
};
static GtkType gimp_context_arg_types[] =
......@@ -216,6 +233,7 @@ static GtkType gimp_context_arg_types[] =
GTK_TYPE_NONE,
0,
0,
0,
0
};
......@@ -230,7 +248,8 @@ static gchar *gimp_context_signal_names[] =
"paint_mode_changed",
"brush_changed",
"pattern_changed",
"gradient_changed"
"gradient_changed",
"palette_changed"
};
static GtkSignalFunc gimp_context_signal_handlers[] =
......@@ -244,7 +263,8 @@ static GtkSignalFunc gimp_context_signal_handlers[] =
gimp_context_real_set_paint_mode,
gimp_context_real_set_brush,
gimp_context_real_set_pattern,
gimp_context_real_set_gradient
gimp_context_real_set_gradient,
gimp_context_real_set_palette
};
......@@ -284,6 +304,7 @@ gimp_context_class_init (GimpContextClass *klass)
gimp_context_arg_types[GIMP_CONTEXT_ARG_BRUSH] = GIMP_TYPE_BRUSH;
gimp_context_arg_types[GIMP_CONTEXT_ARG_PATTERN] = GIMP_TYPE_PATTERN;
gimp_context_arg_types[GIMP_CONTEXT_ARG_GRADIENT] = GIMP_TYPE_GRADIENT;
gimp_context_arg_types[GIMP_CONTEXT_ARG_PALETTE] = GIMP_TYPE_PALETTE;
gtk_object_add_arg_type (gimp_context_arg_names[IMAGE_CHANGED],
GTK_TYPE_POINTER, GTK_ARG_READWRITE,
......@@ -315,6 +336,9 @@ gimp_context_class_init (GimpContextClass *klass)
gtk_object_add_arg_type (gimp_context_arg_names[GRADIENT_CHANGED],
GTK_TYPE_POINTER, GTK_ARG_READWRITE,
ARG_GRADIENT);
gtk_object_add_arg_type (gimp_context_arg_names[PALETTE_CHANGED],
GTK_TYPE_POINTER, GTK_ARG_READWRITE,
ARG_PALETTE);
gimp_context_signals[IMAGE_CHANGED] =
gtk_signal_new (gimp_context_signal_names[IMAGE_CHANGED],
......@@ -416,6 +440,16 @@ gimp_context_class_init (GimpContextClass *klass)
GTK_TYPE_NONE, 1,
GTK_TYPE_POINTER);
gimp_context_signals[PALETTE_CHANGED] =
gtk_signal_new (gimp_context_signal_names[PALETTE_CHANGED],
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET (GimpContextClass,
palette_changed),
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE, 1,
GTK_TYPE_POINTER);
gtk_object_class_add_signals (object_class, gimp_context_signals,
LAST_SIGNAL);
......@@ -433,35 +467,39 @@ gimp_context_class_init (GimpContextClass *klass)
klass->brush_changed = NULL;
klass->pattern_changed = NULL;
klass->gradient_changed = NULL;
klass->palette_changed = NULL;
}
static void
gimp_context_init (GimpContext *context)
{
context->parent = NULL;
context->parent = NULL;
context->defined_args = GIMP_CONTEXT_ALL_ARGS_MASK;
context->defined_args = GIMP_CONTEXT_ALL_ARGS_MASK;
context->image = NULL;
context->display = NULL;
context->image = NULL;
context->display = NULL;
context->tool = RECT_SELECT;
context->tool = RECT_SELECT;
gimp_rgba_set (&context->foreground, 0.0, 0.0, 0.0, 1.0);
gimp_rgba_set (&context->background, 1.0, 1.0, 1.0, 1.0);
context->opacity = 1.0;
context->paint_mode = NORMAL_MODE;
context->opacity = 1.0;
context->paint_mode = NORMAL_MODE;
context->brush = NULL;
context->brush_name = NULL;
context->brush = NULL;
context->brush_name = NULL;
context->pattern = NULL;
context->pattern_name = NULL;
context->pattern = NULL;
context->pattern_name = NULL;
context->gradient = NULL;
context->gradient_name = NULL;
context->palette = NULL;
context->palette_name = NULL;
context_list = g_slist_prepend (context_list, context);
}
......@@ -522,6 +560,23 @@ gimp_context_destroy (GtkObject *object)
context->gradient_name = NULL;
}
if (context->palette)
{
gtk_signal_disconnect_by_func (GTK_OBJECT (context->palette),
gimp_context_palette_dirty,
context);
gtk_signal_disconnect_by_func (GTK_OBJECT (global_palette_list),
gimp_context_palette_removed,
context);
gtk_object_unref (GTK_OBJECT (context->palette));
}
if (context->palette_name)
{
g_free (context->palette_name);
context->palette_name = NULL;
}
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
......@@ -569,6 +624,9 @@ gimp_context_set_arg (GtkObject *object,
case ARG_GRADIENT:
gimp_context_set_gradient (context, GTK_VALUE_POINTER (*arg));
break;
case ARG_PALETTE:
gimp_context_set_palette (context, GTK_VALUE_POINTER (*arg));
break;
default:
break;
}
......@@ -615,6 +673,9 @@ gimp_context_get_arg (GtkObject *object,
case ARG_GRADIENT:
GTK_VALUE_POINTER (*arg) = gimp_context_get_gradient (context);
break;
case ARG_PALETTE:
GTK_VALUE_POINTER (*arg) = gimp_context_get_palette (context);
break;
default:
arg->type = GTK_TYPE_INVALID;
break;
......@@ -1958,3 +2019,175 @@ gimp_context_update_gradients (GimpGradient *gradient)
{