diff --git a/ChangeLog b/ChangeLog index d4d4454aef..7f06aa21e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +2002-03-08 Michael Natterer + + * app/core/gimpchannel.[ch]: changed gimp_channel_get_color() to + not return the color but take a second GimpRGB* parameter like all + other _get_color() functions. Reordered some functions to make + more sense, added some g_return_if_fail(). + + * app/core/gimppalette.[ch]: added gimp_palette_[set|get]_n_columns() + + * app/gui/menus.c: added a "" item factory. + + * app/gui/Makefile.am + * app/gui/palette-editor-commands.[ch]: callbacks for the factory. + + * app/widgets/gimppaletteeditor.[ch]: removed the menu stuff here, + added a spinbutton to adjust the number of columns. + + * app/gui/gradient-editor-commands.c: removed usage of "the_gimp". + + * app/widgets/gimpgradienteditor.c: minor cleanup. + + * app/widgets/gimpbrusheditor.h + * app/widgets/gimpgradienteditor.h + * app/widgets/gimppaletteeditor.h: forgot to declare the _get_type() + functions publically. + 2002-03-08 Sven Neumann Handle gtk-doc just like GTK+ does it now: diff --git a/app/actions/gradient-editor-commands.c b/app/actions/gradient-editor-commands.c index ed7c933d04..15e2e7944e 100644 --- a/app/actions/gradient-editor-commands.c +++ b/app/actions/gradient-editor-commands.c @@ -35,8 +35,6 @@ #include "color-notebook.h" #include "gradient-editor-commands.h" -#include "app_procs.h" - #include "libgimp/gimpintl.h" @@ -113,7 +111,7 @@ gradient_editor_load_left_cmd_callback (GtkWidget *widget, gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data); - user_context = gimp_get_user_context (the_gimp); + user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp); i = (gint) action; @@ -236,7 +234,7 @@ gradient_editor_load_right_cmd_callback (GtkWidget *widget, gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data); - user_context = gimp_get_user_context (the_gimp); + user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp); i = (gint) action; @@ -947,9 +945,9 @@ gradient_editor_menu_update (GtkItemFactory *factory, gboolean selection; gboolean delete; - editor = (GimpGradientEditor *) data; + editor = GIMP_GRADIENT_EDITOR (data); - user_context = gimp_get_user_context (the_gimp); + user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp); if (editor->control_sel_l->prev) left_seg = editor->control_sel_l->prev; diff --git a/app/actions/palette-editor-commands.c b/app/actions/palette-editor-commands.c new file mode 100644 index 0000000000..64c8bc07f6 --- /dev/null +++ b/app/actions/palette-editor-commands.c @@ -0,0 +1,210 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 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 + +#include "libgimpwidgets/gimpwidgets.h" + +#include "gui-types.h" + +#include "core/gimp.h" +#include "core/gimpcontext.h" +#include "core/gimppalette.h" + +#include "widgets/gimppaletteeditor.h" +#include "widgets/gimpitemfactory.h" +#include "widgets/gimpwidgets-utils.h" + +#include "color-area.h" +#include "color-notebook.h" +#include "palette-editor-commands.h" + +#include "libgimp/gimpintl.h" + + +/* local function prototypes */ + +static void palette_editor_color_notebook_callback (ColorNotebook *color_notebook, + const GimpRGB *color, + ColorNotebookState state, + gpointer data); + + +/* public functions */ + +void +palette_editor_new_color_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpPaletteEditor *editor; + GimpPalette *palette; + GimpContext *user_context; + GimpRGB color; + + editor = (GimpPaletteEditor *) gimp_widget_get_callback_context (widget); + + if (! editor) + return; + + palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); + + if (! palette) + return; + + user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp); + + if (active_color == FOREGROUND) + gimp_context_get_foreground (user_context, &color); + else if (active_color == BACKGROUND) + gimp_context_get_background (user_context, &color); + + editor->color = gimp_palette_add_entry (palette, NULL, &color); +} + +void +palette_editor_edit_color_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpPaletteEditor *editor; + GimpPalette *palette; + + editor = (GimpPaletteEditor *) gimp_widget_get_callback_context (widget); + + if (! editor) + return; + + palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); + + if (! (palette && editor->color)) + return; + + if (! editor->color_notebook) + { + editor->color_notebook = + color_notebook_new (_("Edit Palette Color"), + (const GimpRGB *) &editor->color->color, + palette_editor_color_notebook_callback, + editor, + FALSE, + FALSE); + editor->color_notebook_active = TRUE; + } + else + { + if (! editor->color_notebook_active) + { + color_notebook_show (editor->color_notebook); + editor->color_notebook_active = TRUE; + } + + color_notebook_set_color (editor->color_notebook, + &editor->color->color); + } +} + +void +palette_editor_delete_color_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpPaletteEditor *editor; + GimpPalette *palette; + + editor = (GimpPaletteEditor *) gimp_widget_get_callback_context (widget); + + if (! editor) + return; + + palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); + + + if (! (palette && editor->color)) + return; + + gimp_palette_delete_entry (palette, editor->color); +} + +void +palette_editor_menu_update (GtkItemFactory *factory, + gpointer data) +{ + GimpPaletteEditor *editor; + + editor = GIMP_PALETTE_EDITOR (data); + +#define SET_SENSITIVE(menu,condition) \ + gimp_item_factory_set_sensitive (factory, menu, (condition) != 0) + + SET_SENSITIVE ("/New Color", TRUE); + SET_SENSITIVE ("/Edit Color...", editor->color); + SET_SENSITIVE ("/Delete Color", editor->color); + +#undef SET_SENSITIVE +} + + +/* private functions */ + +static void +palette_editor_color_notebook_callback (ColorNotebook *color_notebook, + const GimpRGB *color, + ColorNotebookState state, + gpointer data) +{ + GimpPaletteEditor *editor; + GimpPalette *palette; + GimpContext *user_context; + + editor = GIMP_PALETTE_EDITOR (data); + + palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); + + user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp); + + switch (state) + { + case COLOR_NOTEBOOK_UPDATE: + break; + + case COLOR_NOTEBOOK_OK: + if (editor->color) + { + editor->color->color = *color; + + /* Update either foreground or background colors */ + if (active_color == FOREGROUND) + gimp_context_set_foreground (user_context, color); + else if (active_color == BACKGROUND) + gimp_context_set_background (user_context, color); + + gimp_data_dirty (GIMP_DATA (palette)); + } + + /* Fallthrough */ + case COLOR_NOTEBOOK_CANCEL: + if (editor->color_notebook_active) + { + color_notebook_hide (editor->color_notebook); + editor->color_notebook_active = FALSE; + } + } +} diff --git a/app/actions/palette-editor-commands.h b/app/actions/palette-editor-commands.h new file mode 100644 index 0000000000..76facfa89e --- /dev/null +++ b/app/actions/palette-editor-commands.h @@ -0,0 +1,37 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 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. + */ + +#ifndef __PALETTE_EDITOR_COMMANDS_H__ +#define __PALETTE_EDITOR_COMMANDS_H__ + + +void palette_editor_new_color_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void palette_editor_edit_color_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void palette_editor_delete_color_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); + +void palette_editor_menu_update (GtkItemFactory *factory, + gpointer data); + + +#endif /* __PALETTE_EDITOR_COMMANDS_H__ */ diff --git a/app/core/gimpchannel-combine.c b/app/core/gimpchannel-combine.c index ccc519cb77..8050068962 100644 --- a/app/core/gimpchannel-combine.c +++ b/app/core/gimpchannel-combine.c @@ -250,12 +250,14 @@ gimp_channel_set_color (GimpChannel *channel, } } -const GimpRGB * -gimp_channel_get_color (const GimpChannel *channel) +void +gimp_channel_get_color (const GimpChannel *channel, + GimpRGB *color) { - g_return_val_if_fail (GIMP_IS_CHANNEL (channel), NULL); + g_return_if_fail (GIMP_IS_CHANNEL (channel)); + g_return_if_fail (color != NULL); - return &channel->color; + *color = channel->color; } gdouble @@ -1195,6 +1197,28 @@ gimp_channel_feather (GimpChannel *mask, mask->bounds_known = FALSE; } +void +gimp_channel_sharpen (GimpChannel *mask) +{ + PixelRegion maskPR; + GimpLut *lut; + + g_return_if_fail (GIMP_IS_CHANNEL (mask)); + + /* push the current channel onto the undo stack */ + gimp_channel_push_undo (mask); + + pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles, + 0, 0, + GIMP_DRAWABLE (mask)->width, + GIMP_DRAWABLE (mask)->height, TRUE); + lut = threshold_lut_new (0.5, 1); + + pixel_regions_process_parallel ((p_func) gimp_lut_process_inline, + lut, 1, &maskPR); + gimp_lut_free (lut); +} + void gimp_channel_push_undo (GimpChannel *mask) { @@ -1261,52 +1285,6 @@ gimp_channel_clear (GimpChannel *mask) mask->y2 = GIMP_DRAWABLE (mask)->height; } -void -gimp_channel_invert (GimpChannel *mask) -{ - PixelRegion maskPR; - GimpLut *lut; - - g_return_if_fail (GIMP_IS_CHANNEL (mask)); - - /* push the current channel onto the undo stack */ - gimp_channel_push_undo (mask); - - pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles, - 0, 0, - GIMP_DRAWABLE (mask)->width, - GIMP_DRAWABLE (mask)->height, TRUE); - - lut = invert_lut_new (1); - - pixel_regions_process_parallel ((p_func) gimp_lut_process_inline, - lut, 1, &maskPR); - gimp_lut_free (lut); - mask->bounds_known = FALSE; -} - -void -gimp_channel_sharpen (GimpChannel *mask) -{ - PixelRegion maskPR; - GimpLut *lut; - - g_return_if_fail (GIMP_IS_CHANNEL (mask)); - - /* push the current channel onto the undo stack */ - gimp_channel_push_undo (mask); - - pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles, - 0, 0, - GIMP_DRAWABLE (mask)->width, - GIMP_DRAWABLE (mask)->height, TRUE); - lut = threshold_lut_new (0.5, 1); - - pixel_regions_process_parallel ((p_func) gimp_lut_process_inline, - lut, 1, &maskPR); - gimp_lut_free (lut); -} - void gimp_channel_all (GimpChannel *mask) { @@ -1334,6 +1312,30 @@ gimp_channel_all (GimpChannel *mask) mask->y2 = GIMP_DRAWABLE (mask)->height; } +void +gimp_channel_invert (GimpChannel *mask) +{ + PixelRegion maskPR; + GimpLut *lut; + + g_return_if_fail (GIMP_IS_CHANNEL (mask)); + + /* push the current channel onto the undo stack */ + gimp_channel_push_undo (mask); + + pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles, + 0, 0, + GIMP_DRAWABLE (mask)->width, + GIMP_DRAWABLE (mask)->height, TRUE); + + lut = invert_lut_new (1); + + pixel_regions_process_parallel ((p_func) gimp_lut_process_inline, + lut, 1, &maskPR); + gimp_lut_free (lut); + mask->bounds_known = FALSE; +} + void gimp_channel_border (GimpChannel *mask, gint radius_x, @@ -1601,6 +1603,7 @@ gimp_channel_layer_alpha (GimpChannel *mask, g_return_if_fail (GIMP_IS_CHANNEL (mask)); g_return_if_fail (GIMP_IS_LAYER (layer)); + g_return_if_fail (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer))); /* push the current mask onto the undo stack */ gimp_channel_push_undo (mask); @@ -1640,6 +1643,7 @@ gimp_channel_layer_mask (GimpChannel *mask, g_return_if_fail (GIMP_IS_CHANNEL (mask)); g_return_if_fail (GIMP_IS_LAYER (layer)); + g_return_if_fail (gimp_layer_get_mask (layer)); /* push the current mask onto the undo stack */ gimp_channel_push_undo (mask); diff --git a/app/core/gimpchannel-combine.h b/app/core/gimpchannel-combine.h index 5e3d16cd70..44581612fc 100644 --- a/app/core/gimpchannel-combine.h +++ b/app/core/gimpchannel-combine.h @@ -80,7 +80,8 @@ gdouble gimp_channel_get_opacity (const GimpChannel *channel); void gimp_channel_set_opacity (GimpChannel *channel, gdouble opacity); -const GimpRGB * gimp_channel_get_color (const GimpChannel *channel); +void gimp_channel_get_color (const GimpChannel *channel, + GimpRGB *color); void gimp_channel_set_color (GimpChannel *channel, const GimpRGB *color); @@ -100,6 +101,7 @@ void gimp_channel_resize (GimpChannel *channel, GimpChannel * gimp_channel_new_mask (GimpImage *gimage, gint width, gint height); + gboolean gimp_channel_boundary (GimpChannel *mask, BoundSeg **segs_in, BoundSeg **segs_out, @@ -118,6 +120,7 @@ gint gimp_channel_value (GimpChannel *mask, gint x, gint y); gboolean gimp_channel_is_empty (GimpChannel *mask); + void gimp_channel_add_segment (GimpChannel *mask, gint x, gint y, @@ -146,16 +149,18 @@ void gimp_channel_combine_mask (GimpChannel *mask, ChannelOps op, gint off_x, gint off_y); + void gimp_channel_feather (GimpChannel *mask, gdouble radius_x, gdouble radius_y, gboolean push_undo); +void gimp_channel_sharpen (GimpChannel *mask); void gimp_channel_push_undo (GimpChannel *mask); + void gimp_channel_clear (GimpChannel *mask); -void gimp_channel_invert (GimpChannel *mask); -void gimp_channel_sharpen (GimpChannel *mask); void gimp_channel_all (GimpChannel *mask); +void gimp_channel_invert (GimpChannel *mask); void gimp_channel_border (GimpChannel *mask, gint radius_x, diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c index ccc519cb77..8050068962 100644 --- a/app/core/gimpchannel.c +++ b/app/core/gimpchannel.c @@ -250,12 +250,14 @@ gimp_channel_set_color (GimpChannel *channel, } } -const GimpRGB * -gimp_channel_get_color (const GimpChannel *channel) +void +gimp_channel_get_color (const GimpChannel *channel, + GimpRGB *color) { - g_return_val_if_fail (GIMP_IS_CHANNEL (channel), NULL); + g_return_if_fail (GIMP_IS_CHANNEL (channel)); + g_return_if_fail (color != NULL); - return &channel->color; + *color = channel->color; } gdouble @@ -1195,6 +1197,28 @@ gimp_channel_feather (GimpChannel *mask, mask->bounds_known = FALSE; } +void +gimp_channel_sharpen (GimpChannel *mask) +{ + PixelRegion maskPR; + GimpLut *lut; + + g_return_if_fail (GIMP_IS_CHANNEL (mask)); + + /* push the current channel onto the undo stack */ + gimp_channel_push_undo (mask); + + pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles, + 0, 0, + GIMP_DRAWABLE (mask)->width, + GIMP_DRAWABLE (mask)->height, TRUE); + lut = threshold_lut_new (0.5, 1); + + pixel_regions_process_parallel ((p_func) gimp_lut_process_inline, + lut, 1, &maskPR); + gimp_lut_free (lut); +} + void gimp_channel_push_undo (GimpChannel *mask) { @@ -1261,52 +1285,6 @@ gimp_channel_clear (GimpChannel *mask) mask->y2 = GIMP_DRAWABLE (mask)->height; } -void -gimp_channel_invert (GimpChannel *mask) -{ - PixelRegion maskPR; - GimpLut *lut; - - g_return_if_fail (GIMP_IS_CHANNEL (mask)); - - /* push the current channel onto the undo stack */ - gimp_channel_push_undo (mask); - - pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles, - 0, 0, - GIMP_DRAWABLE (mask)->width, - GIMP_DRAWABLE (mask)->height, TRUE); - - lut = invert_lut_new (1); - - pixel_regions_process_parallel ((p_func) gimp_lut_process_inline, - lut, 1, &maskPR); - gimp_lut_free (lut); - mask->bounds_known = FALSE; -} - -void -gimp_channel_sharpen (GimpChannel *mask) -{ - PixelRegion maskPR; - GimpLut *lut; - - g_return_if_fail (GIMP_IS_CHANNEL (mask)); - - /* push the current channel onto the undo stack */ - gimp_channel_push_undo (mask); - - pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles, - 0, 0, - GIMP_DRAWABLE (mask)->width, - GIMP_DRAWABLE (mask)->height, TRUE); - lut = threshold_lut_new (0.5, 1); - - pixel_regions_process_parallel ((p_func) gimp_lut_process_inline, - lut, 1, &maskPR); - gimp_lut_free (lut); -} - void gimp_channel_all (GimpChannel *mask) { @@ -1334,6 +1312,30 @@ gimp_channel_all (GimpChannel *mask) mask->y2 = GIMP_DRAWABLE (mask)->height; } +void +gimp_channel_invert (GimpChannel *mask) +{ + PixelRegion maskPR; + GimpLut *lut; + + g_return_if_fail (GIMP_IS_CHANNEL (mask)); + + /* push the current channel onto the undo stack */ + gimp_channel_push_undo (mask); + + pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles, + 0, 0, + GIMP_DRAWABLE (mask)->width, + GIMP_DRAWABLE (mask)->height, TRUE); + + lut = invert_lut_new (1); + + pixel_regions_process_parallel ((p_func) gimp_lut_process_inline, + lut, 1, &maskPR); + gimp_lut_free (lut); + mask->bounds_known = FALSE; +} + void gimp_channel_border (GimpChannel *mask, gint radius_x, @@ -1601,6 +1603,7 @@ gimp_channel_layer_alpha (GimpChannel *mask, g_return_if_fail (GIMP_IS_CHANNEL (mask)); g_return_if_fail (GIMP_IS_LAYER (layer)); + g_return_if_fail (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer))); /* push the current mask onto the undo stack */ gimp_channel_push_undo (mask); @@ -1640,6 +1643,7 @@ gimp_channel_layer_mask (GimpChannel *mask, g_return_if_fail (GIMP_IS_CHANNEL (mask)); g_return_if_fail (GIMP_IS_LAYER (layer)); + g_return_if_fail (gimp_layer_get_mask (layer)); /* push the current mask onto the undo stack */ gimp_channel_push_undo (mask); diff --git a/app/core/gimpchannel.h b/app/core/gimpchannel.h index 5e3d16cd70..44581612fc 100644 --- a/app/core/gimpchannel.h +++ b/app/core/gimpchannel.h @@ -80,7 +80,8 @@ gdouble gimp_channel_get_opacity (const GimpChannel *channel); void gimp_channel_set_opacity (GimpChannel *channel, gdouble opacity); -const GimpRGB * gimp_channel_get_color (const GimpChannel *channel); +void gimp_channel_get_color (const GimpChannel *channel, + GimpRGB *color); void gimp_channel_set_color (GimpChannel *channel, const GimpRGB *color); @@ -100,6 +101,7 @@ void gimp_channel_resize (GimpChannel *channel, GimpChannel * gimp_channel_new_mask (GimpImage *gimage, gint width, gint height); + gboolean gimp_channel_boundary (GimpChannel *mask, BoundSeg **segs_in, BoundSeg **segs_out, @@ -118,6 +120,7 @@ gint gimp_channel_value (GimpChannel *mask, gint x, gint y); gboolean gimp_channel_is_empty (GimpChannel *mask); + void gimp_channel_add_segment (GimpChannel *mask, gint x, gint y, @@ -146,16 +149,18 @@ void gimp_channel_combine_mask (GimpChannel *mask, ChannelOps op, gint off_x, gint off_y); + void gimp_channel_feather (GimpChannel *mask, gdouble radius_x, gdouble radius_y, gboolean push_undo); +void gimp_channel_sharpen (GimpChannel *mask); void gimp_channel_push_undo (GimpChannel *mask); + void gimp_channel_clear (GimpChannel *mask); -void gimp_channel_invert (GimpChannel *mask); -void gimp_channel_sharpen (GimpChannel *mask); void gimp_channel_all (GimpChannel *mask); +void gimp_channel_invert (GimpChannel *mask); void gimp_channel_border (GimpChannel *mask, gint radius_x, diff --git a/app/core/gimppalette-load.c b/app/core/gimppalette-load.c index 451f9cfc59..296f4eac52 100644 --- a/app/core/gimppalette-load.c +++ b/app/core/gimppalette-load.c @@ -525,7 +525,6 @@ gimp_palette_add_entry (GimpPalette *palette, GimpPaletteEntry *entry; g_return_val_if_fail (GIMP_IS_PALETTE (palette), NULL); - g_return_val_if_fail (color != NULL, NULL); entry = g_new0 (GimpPaletteEntry, 1); @@ -551,7 +550,6 @@ gimp_palette_delete_entry (GimpPalette *palette, gint pos = 0; g_return_if_fail (GIMP_IS_PALETTE (palette)); - g_return_if_fail (entry != NULL); if (g_list_find (palette->colors, entry)) @@ -587,6 +585,33 @@ gimp_palette_delete_entry (GimpPalette *palette, } } +void +gimp_palette_set_n_columns (GimpPalette *palette, + gint n_columns) +{ + g_return_if_fail (GIMP_IS_PALETTE (palette)); + + n_columns = CLAMP (n_columns, 0, 64); + + if (palette->n_columns != n_columns) + { + palette->n_columns = n_columns; + + gimp_data_dirty (GIMP_DATA (palette)); + } +} + +gint +gimp_palette_get_n_columns (GimpPalette *palette) +{ + g_return_val_if_fail (GIMP_IS_PALETTE (palette), 0); + + return palette->n_columns; +} + + +/* private functions */ + static void gimp_palette_entry_free (GimpPaletteEntry *entry) { diff --git a/app/core/gimppalette-save.c b/app/core/gimppalette-save.c index 451f9cfc59..296f4eac52 100644 --- a/app/core/gimppalette-save.c +++ b/app/core/gimppalette-save.c @@ -525,7 +525,6 @@ gimp_palette_add_entry (GimpPalette *palette, GimpPaletteEntry *entry; g_return_val_if_fail (GIMP_IS_PALETTE (palette), NULL); - g_return_val_if_fail (color != NULL, NULL); entry = g_new0 (GimpPaletteEntry, 1); @@ -551,7 +550,6 @@ gimp_palette_delete_entry (GimpPalette *palette, gint pos = 0; g_return_if_fail (GIMP_IS_PALETTE (palette)); - g_return_if_fail (entry != NULL); if (g_list_find (palette->colors, entry)) @@ -587,6 +585,33 @@ gimp_palette_delete_entry (GimpPalette *palette, } } +void +gimp_palette_set_n_columns (GimpPalette *palette, + gint n_columns) +{ + g_return_if_fail (GIMP_IS_PALETTE (palette)); + + n_columns = CLAMP (n_columns, 0, 64); + + if (palette->n_columns != n_columns) + { + palette->n_columns = n_columns; + + gimp_data_dirty (GIMP_DATA (palette)); + } +} + +gint +gimp_palette_get_n_columns (GimpPalette *palette) +{ + g_return_val_if_fail (GIMP_IS_PALETTE (palette), 0); + + return palette->n_columns; +} + + +/* private functions */ + static void gimp_palette_entry_free (GimpPaletteEntry *entry) { diff --git a/app/core/gimppalette.c b/app/core/gimppalette.c index 451f9cfc59..296f4eac52 100644 --- a/app/core/gimppalette.c +++ b/app/core/gimppalette.c @@ -525,7 +525,6 @@ gimp_palette_add_entry (GimpPalette *palette, GimpPaletteEntry *entry; g_return_val_if_fail (GIMP_IS_PALETTE (palette), NULL); - g_return_val_if_fail (color != NULL, NULL); entry = g_new0 (GimpPaletteEntry, 1); @@ -551,7 +550,6 @@ gimp_palette_delete_entry (GimpPalette *palette, gint pos = 0; g_return_if_fail (GIMP_IS_PALETTE (palette)); - g_return_if_fail (entry != NULL); if (g_list_find (palette->colors, entry)) @@ -587,6 +585,33 @@ gimp_palette_delete_entry (GimpPalette *palette, } } +void +gimp_palette_set_n_columns (GimpPalette *palette, + gint n_columns) +{ + g_return_if_fail (GIMP_IS_PALETTE (palette)); + + n_columns = CLAMP (n_columns, 0, 64); + + if (palette->n_columns != n_columns) + { + palette->n_columns = n_columns; + + gimp_data_dirty (GIMP_DATA (palette)); + } +} + +gint +gimp_palette_get_n_columns (GimpPalette *palette) +{ + g_return_val_if_fail (GIMP_IS_PALETTE (palette), 0); + + return palette->n_columns; +} + + +/* private functions */ + static void gimp_palette_entry_free (GimpPaletteEntry *entry) { diff --git a/app/core/gimppalette.h b/app/core/gimppalette.h index 75ca551b0d..7db2ddef77 100644 --- a/app/core/gimppalette.h +++ b/app/core/gimppalette.h @@ -74,5 +74,9 @@ GimpPaletteEntry * gimp_palette_add_entry (GimpPalette *palette, void gimp_palette_delete_entry (GimpPalette *palette, GimpPaletteEntry *entry); +void gimp_palette_set_n_columns (GimpPalette *palette, + gint n_columns); +gint gimp_palette_get_n_columns (GimpPalette *palette); + #endif /* __GIMP_PALETTE_H__ */ diff --git a/app/gui/Makefile.am b/app/gui/Makefile.am index ce03899611..d4606a2a5b 100644 --- a/app/gui/Makefile.am +++ b/app/gui/Makefile.am @@ -79,6 +79,8 @@ libappgui_a_SOURCES = @STRIP_BEGIN@ \ module-browser.h \ offset-dialog.c \ offset-dialog.h \ + palette-editor-commands.c \ + palette-editor-commands.h \ palette-import-dialog.c \ palette-import-dialog.h \ palette-select.c \ diff --git a/app/gui/gradient-editor-commands.c b/app/gui/gradient-editor-commands.c index ed7c933d04..15e2e7944e 100644 --- a/app/gui/gradient-editor-commands.c +++ b/app/gui/gradient-editor-commands.c @@ -35,8 +35,6 @@ #include "color-notebook.h" #include "gradient-editor-commands.h" -#include "app_procs.h" - #include "libgimp/gimpintl.h" @@ -113,7 +111,7 @@ gradient_editor_load_left_cmd_callback (GtkWidget *widget, gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data); - user_context = gimp_get_user_context (the_gimp); + user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp); i = (gint) action; @@ -236,7 +234,7 @@ gradient_editor_load_right_cmd_callback (GtkWidget *widget, gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data); - user_context = gimp_get_user_context (the_gimp); + user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp); i = (gint) action; @@ -947,9 +945,9 @@ gradient_editor_menu_update (GtkItemFactory *factory, gboolean selection; gboolean delete; - editor = (GimpGradientEditor *) data; + editor = GIMP_GRADIENT_EDITOR (data); - user_context = gimp_get_user_context (the_gimp); + user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp); if (editor->control_sel_l->prev) left_seg = editor->control_sel_l->prev; diff --git a/app/gui/menus.c b/app/gui/menus.c index cad8c0b8a8..deeffadf09 100644 --- a/app/gui/menus.c +++ b/app/gui/menus.c @@ -62,6 +62,7 @@ #include "image-commands.h" #include "layers-commands.h" #include "menus.h" +#include "palette-editor-commands.h" #include "palettes-commands.h" #include "paths-dialog.h" #include "patterns-commands.h" @@ -1743,6 +1744,28 @@ static GimpItemFactoryEntry gradients_entries[] = }; +/***** *****/ + +static GimpItemFactoryEntry palette_editor_entries[] = +{ + { { N_("/New Color"), NULL, + palette_editor_new_color_cmd_callback, 0, + "", GTK_STOCK_NEW }, + NULL, + NULL, NULL }, + { { N_("/Edit Color..."), NULL, + palette_editor_edit_color_cmd_callback, 0, + "", GIMP_STOCK_EDIT }, + NULL, + NULL, NULL }, + { { N_("/Delete Color"), NULL, + palette_editor_delete_color_cmd_callback, 0, + "", GTK_STOCK_DELETE }, + NULL, + NULL, NULL } +}; + + /***** *****/ static GimpItemFactoryEntry palettes_entries[] = @@ -1893,6 +1916,7 @@ static GimpItemFactory *brushes_factory = NULL; static GimpItemFactory *patterns_factory = NULL; static GimpItemFactory *gradient_editor_factory = NULL; static GimpItemFactory *gradients_factory = NULL; +static GimpItemFactory *palette_editor_factory = NULL; static GimpItemFactory *palettes_factory = NULL; static GimpItemFactory *buffers_factory = NULL; static GimpItemFactory *documents_factory = NULL; @@ -2070,6 +2094,14 @@ menus_init (Gimp *gimp) gimp, FALSE); + palette_editor_factory = gimp_item_factory_new (GTK_TYPE_MENU, + "", "palette_editor", + palette_editor_menu_update, + G_N_ELEMENTS (palette_editor_entries), + palette_editor_entries, + gimp, + FALSE); + palettes_factory = gimp_item_factory_new (GTK_TYPE_MENU, "", "palettes", palettes_menu_update, @@ -2268,6 +2300,12 @@ menus_exit (Gimp *gimp) gradients_factory = NULL; } + if (palette_editor_factory) + { + g_object_unref (G_OBJECT (palette_editor_factory)); + palette_editor_factory = NULL; + } + if (palettes_factory) { g_object_unref (G_OBJECT (palettes_factory)); diff --git a/app/gui/palette-editor-commands.c b/app/gui/palette-editor-commands.c new file mode 100644 index 0000000000..64c8bc07f6 --- /dev/null +++ b/app/gui/palette-editor-commands.c @@ -0,0 +1,210 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 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 + +#include "libgimpwidgets/gimpwidgets.h" + +#include "gui-types.h" + +#include "core/gimp.h" +#include "core/gimpcontext.h" +#include "core/gimppalette.h" + +#include "widgets/gimppaletteeditor.h" +#include "widgets/gimpitemfactory.h" +#include "widgets/gimpwidgets-utils.h" + +#include "color-area.h" +#include "color-notebook.h" +#include "palette-editor-commands.h" + +#include "libgimp/gimpintl.h" + + +/* local function prototypes */ + +static void palette_editor_color_notebook_callback (ColorNotebook *color_notebook, + const GimpRGB *color, + ColorNotebookState state, + gpointer data); + + +/* public functions */ + +void +palette_editor_new_color_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpPaletteEditor *editor; + GimpPalette *palette; + GimpContext *user_context; + GimpRGB color; + + editor = (GimpPaletteEditor *) gimp_widget_get_callback_context (widget); + + if (! editor) + return; + + palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); + + if (! palette) + return; + + user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp); + + if (active_color == FOREGROUND) + gimp_context_get_foreground (user_context, &color); + else if (active_color == BACKGROUND) + gimp_context_get_background (user_context, &color); + + editor->color = gimp_palette_add_entry (palette, NULL, &color); +} + +void +palette_editor_edit_color_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpPaletteEditor *editor; + GimpPalette *palette; + + editor = (GimpPaletteEditor *) gimp_widget_get_callback_context (widget); + + if (! editor) + return; + + palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); + + if (! (palette && editor->color)) + return; + + if (! editor->color_notebook) + { + editor->color_notebook = + color_notebook_new (_("Edit Palette Color"), + (const GimpRGB *) &editor->color->color, + palette_editor_color_notebook_callback, + editor, + FALSE, + FALSE); + editor->color_notebook_active = TRUE; + } + else + { + if (! editor->color_notebook_active) + { + color_notebook_show (editor->color_notebook); + editor->color_notebook_active = TRUE; + } + + color_notebook_set_color (editor->color_notebook, + &editor->color->color); + } +} + +void +palette_editor_delete_color_cmd_callback (GtkWidget *widget, + gpointer data, + guint action) +{ + GimpPaletteEditor *editor; + GimpPalette *palette; + + editor = (GimpPaletteEditor *) gimp_widget_get_callback_context (widget); + + if (! editor) + return; + + palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); + + + if (! (palette && editor->color)) + return; + + gimp_palette_delete_entry (palette, editor->color); +} + +void +palette_editor_menu_update (GtkItemFactory *factory, + gpointer data) +{ + GimpPaletteEditor *editor; + + editor = GIMP_PALETTE_EDITOR (data); + +#define SET_SENSITIVE(menu,condition) \ + gimp_item_factory_set_sensitive (factory, menu, (condition) != 0) + + SET_SENSITIVE ("/New Color", TRUE); + SET_SENSITIVE ("/Edit Color...", editor->color); + SET_SENSITIVE ("/Delete Color", editor->color); + +#undef SET_SENSITIVE +} + + +/* private functions */ + +static void +palette_editor_color_notebook_callback (ColorNotebook *color_notebook, + const GimpRGB *color, + ColorNotebookState state, + gpointer data) +{ + GimpPaletteEditor *editor; + GimpPalette *palette; + GimpContext *user_context; + + editor = GIMP_PALETTE_EDITOR (data); + + palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); + + user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp); + + switch (state) + { + case COLOR_NOTEBOOK_UPDATE: + break; + + case COLOR_NOTEBOOK_OK: + if (editor->color) + { + editor->color->color = *color; + + /* Update either foreground or background colors */ + if (active_color == FOREGROUND) + gimp_context_set_foreground (user_context, color); + else if (active_color == BACKGROUND) + gimp_context_set_background (user_context, color); + + gimp_data_dirty (GIMP_DATA (palette)); + } + + /* Fallthrough */ + case COLOR_NOTEBOOK_CANCEL: + if (editor->color_notebook_active) + { + color_notebook_hide (editor->color_notebook); + editor->color_notebook_active = FALSE; + } + } +} diff --git a/app/gui/palette-editor-commands.h b/app/gui/palette-editor-commands.h new file mode 100644 index 0000000000..76facfa89e --- /dev/null +++ b/app/gui/palette-editor-commands.h @@ -0,0 +1,37 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 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. + */ + +#ifndef __PALETTE_EDITOR_COMMANDS_H__ +#define __PALETTE_EDITOR_COMMANDS_H__ + + +void palette_editor_new_color_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void palette_editor_edit_color_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); +void palette_editor_delete_color_cmd_callback (GtkWidget *widget, + gpointer data, + guint action); + +void palette_editor_menu_update (GtkItemFactory *factory, + gpointer data); + + +#endif /* __PALETTE_EDITOR_COMMANDS_H__ */ diff --git a/app/menus/menus.c b/app/menus/menus.c index cad8c0b8a8..deeffadf09 100644 --- a/app/menus/menus.c +++ b/app/menus/menus.c @@ -62,6 +62,7 @@ #include "image-commands.h" #include "layers-commands.h" #include "menus.h" +#include "palette-editor-commands.h" #include "palettes-commands.h" #include "paths-dialog.h" #include "patterns-commands.h" @@ -1743,6 +1744,28 @@ static GimpItemFactoryEntry gradients_entries[] = }; +/***** *****/ + +static GimpItemFactoryEntry palette_editor_entries[] = +{ + { { N_("/New Color"), NULL, + palette_editor_new_color_cmd_callback, 0, + "", GTK_STOCK_NEW }, + NULL, + NULL, NULL }, + { { N_("/Edit Color..."), NULL, + palette_editor_edit_color_cmd_callback, 0, + "", GIMP_STOCK_EDIT }, + NULL, + NULL, NULL }, + { { N_("/Delete Color"), NULL, + palette_editor_delete_color_cmd_callback, 0, + "", GTK_STOCK_DELETE }, + NULL, + NULL, NULL } +}; + + /***** *****/ static GimpItemFactoryEntry palettes_entries[] = @@ -1893,6 +1916,7 @@ static GimpItemFactory *brushes_factory = NULL; static GimpItemFactory *patterns_factory = NULL; static GimpItemFactory *gradient_editor_factory = NULL; static GimpItemFactory *gradients_factory = NULL; +static GimpItemFactory *palette_editor_factory = NULL; static GimpItemFactory *palettes_factory = NULL; static GimpItemFactory *buffers_factory = NULL; static GimpItemFactory *documents_factory = NULL; @@ -2070,6 +2094,14 @@ menus_init (Gimp *gimp) gimp, FALSE); + palette_editor_factory = gimp_item_factory_new (GTK_TYPE_MENU, + "", "palette_editor", + palette_editor_menu_update, + G_N_ELEMENTS (palette_editor_entries), + palette_editor_entries, + gimp, + FALSE); + palettes_factory = gimp_item_factory_new (GTK_TYPE_MENU, "", "palettes", palettes_menu_update, @@ -2268,6 +2300,12 @@ menus_exit (Gimp *gimp) gradients_factory = NULL; } + if (palette_editor_factory) + { + g_object_unref (G_OBJECT (palette_editor_factory)); + palette_editor_factory = NULL; + } + if (palettes_factory) { g_object_unref (G_OBJECT (palettes_factory)); diff --git a/app/widgets/gimpbrusheditor.h b/app/widgets/gimpbrusheditor.h index ec076be812..1d141c1581 100644 --- a/app/widgets/gimpbrusheditor.h +++ b/app/widgets/gimpbrusheditor.h @@ -62,7 +62,9 @@ struct _GimpBrushEditorClass }; -GimpDataEditor * gimp_brush_editor_new (Gimp *gimp); +GType gimp_brush_editor_get_type (void) G_GNUC_CONST; + +GimpDataEditor * gimp_brush_editor_new (Gimp *gimp); #endif /* __GIMP_BRUSH_EDITOR_H__ */ diff --git a/app/widgets/gimpgradienteditor.c b/app/widgets/gimpgradienteditor.c index 54a93429cb..ec46bccb82 100644 --- a/app/widgets/gimpgradienteditor.c +++ b/app/widgets/gimpgradienteditor.c @@ -706,12 +706,10 @@ preview_events (GtkWidget *widget, { case GDK_EXPOSE: preview_update (editor, FALSE); - return FALSE; case GDK_LEAVE_NOTIFY: gradient_editor_set_hint (editor, "", "", ""); - break; case GDK_MOTION_NOTIFY: @@ -735,7 +733,6 @@ preview_events (GtkWidget *widget, preview_set_hint (editor, x); } } - break; case GDK_BUTTON_PRESS: @@ -767,7 +764,6 @@ preview_events (GtkWidget *widget, default: break; } - break; case GDK_SCROLL: @@ -792,7 +788,6 @@ preview_events (GtkWidget *widget, gtk_adjustment_set_value (adj, new_value); } - break; case GDK_BUTTON_RELEASE: @@ -810,7 +805,6 @@ preview_events (GtkWidget *widget, preview_set_foreground (editor, x); break; } - break; default: diff --git a/app/widgets/gimpgradienteditor.h b/app/widgets/gimpgradienteditor.h index d01914e2c9..5e362ac6cd 100644 --- a/app/widgets/gimpgradienteditor.h +++ b/app/widgets/gimpgradienteditor.h @@ -114,10 +114,12 @@ struct _GimpGradientEditorClass }; -GimpDataEditor * gimp_gradient_editor_new (Gimp *gimp); +GType gimp_gradient_editor_get_type (void) G_GNUC_CONST; -void gimp_gradient_editor_update (GimpGradientEditor *editor, - GradientEditorUpdateMask flags); +GimpDataEditor * gimp_gradient_editor_new (Gimp *gimp); + +void gimp_gradient_editor_update (GimpGradientEditor *editor, + GradientEditorUpdateMask flags); #endif /* __GIMP_GRADIENT_EDITOR_H__ */ diff --git a/app/widgets/gimppaletteeditor.c b/app/widgets/gimppaletteeditor.c index 9bc4079a71..221767d650 100644 --- a/app/widgets/gimppaletteeditor.c +++ b/app/widgets/gimppaletteeditor.c @@ -38,6 +38,7 @@ #include "core/gimppalette.h" #include "gimpdnd.h" +#include "gimpitemfactory.h" #include "gimppaletteeditor.h" #include "gimppreview.h" @@ -72,18 +73,6 @@ static void gimp_palette_editor_unmap (GtkWidget *widget); static void gimp_palette_editor_set_data (GimpDataEditor *editor, GimpData *data); -static void palette_editor_create_popup_menu (GimpPaletteEditor *editor); -static void palette_editor_new_entry_callback (GtkWidget *widget, - GimpPaletteEditor *editor); -static void palette_editor_edit_entry_callback (GtkWidget *widget, - GimpPaletteEditor *editor); -static void palette_editor_delete_entry_callback (GtkWidget *widget, - GimpPaletteEditor *editor); -static void palette_editor_color_notebook_callback (ColorNotebook *color_notebook, - const GimpRGB *color, - ColorNotebookState state, - gpointer data); - static gint palette_editor_eventbox_button_press (GtkWidget *widget, GdkEventButton *bevent, GimpPaletteEditor *editor); @@ -98,6 +87,8 @@ static void palette_editor_scroll_top_left (GimpPaletteEditor *editor); static void palette_editor_color_name_changed (GtkWidget *widget, GimpPaletteEditor *editor); +static void palette_editor_columns_changed (GtkAdjustment *adj, + GimpPaletteEditor *editor); static void palette_editor_zoom_in_callback (GtkWidget *widget, GimpPaletteEditor *editor); static void palette_editor_zoom_out_callback (GtkWidget *widget, @@ -183,9 +174,11 @@ gimp_palette_editor_init (GimpPaletteEditor *editor) { GtkWidget *scrolledwindow; GtkWidget *palette_region; - GtkWidget *entry; GtkWidget *eventbox; GtkWidget *alignment; + GtkWidget *hbox; + GtkWidget *label; + GtkWidget *spinbutton; editor->zoom_factor = 1.0; editor->columns = COLUMNS; @@ -248,18 +241,36 @@ gimp_palette_editor_init (GimpPaletteEditor *editor) palette_editor_drop_palette, editor); + hbox = gtk_hbox_new (FALSE, 2); + gtk_box_pack_start (GTK_BOX (editor), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + /* The color name entry */ - entry = editor->color_name = gtk_entry_new (); - gtk_box_pack_start (GTK_BOX (editor), entry, FALSE, FALSE, 0); - gtk_entry_set_text (GTK_ENTRY (entry), _("Undefined")); - gtk_widget_set_sensitive (entry, FALSE); - gtk_widget_show (entry); + editor->color_name = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (hbox), editor->color_name, TRUE, TRUE, 0); + gtk_entry_set_text (GTK_ENTRY (editor->color_name), _("Undefined")); + gtk_widget_set_sensitive (editor->color_name, FALSE); + gtk_widget_show (editor->color_name); editor->entry_sig_id = - g_signal_connect (G_OBJECT (entry), "changed", + g_signal_connect (G_OBJECT (editor->color_name), "changed", G_CALLBACK (palette_editor_color_name_changed), editor); + label = gtk_label_new (_("Columns:")); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + spinbutton = gimp_spin_button_new ((GtkObject **) &editor->columns_data, + 0, 0, 64, 1, 4, 4, 1, 0); + gtk_widget_set_size_request (spinbutton, 50, -1); + gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0); + gtk_widget_show (spinbutton); + + g_signal_connect (G_OBJECT (editor->columns_data), "value_changed", + G_CALLBACK (palette_editor_columns_changed), + editor); + /* + and - buttons */ gimp_editor_add_button (GIMP_EDITOR (editor), GTK_STOCK_ZOOM_FIT, @@ -281,8 +292,6 @@ gimp_palette_editor_init (GimpPaletteEditor *editor) G_CALLBACK (palette_editor_zoom_out_callback), NULL, editor); - - palette_editor_create_popup_menu (editor); } static void @@ -326,6 +335,12 @@ gimp_palette_editor_set_data (GimpDataEditor *editor, palette_editor = GIMP_PALETTE_EDITOR (editor); + g_signal_handler_block (G_OBJECT (palette_editor->color_name), + palette_editor->entry_sig_id); + g_signal_handlers_block_by_func (G_OBJECT (palette_editor->columns_data), + palette_editor_columns_changed, + editor); + if (editor->data) { if (palette_editor->color_notebook) @@ -342,31 +357,41 @@ gimp_palette_editor_set_data (GimpDataEditor *editor, palette_editor->columns_valid = FALSE; palette_editor->color = NULL; - g_signal_handler_block (G_OBJECT (palette_editor->color_name), - palette_editor->entry_sig_id); - gtk_entry_set_text (GTK_ENTRY (palette_editor->color_name), _("Undefined")); - g_signal_handler_unblock (G_OBJECT (palette_editor->color_name), - palette_editor->entry_sig_id); - gtk_widget_set_sensitive (palette_editor->color_name, FALSE); + + gtk_adjustment_set_value (palette_editor->columns_data, 0); } GIMP_DATA_EDITOR_CLASS (parent_class)->set_data (editor, data); if (editor->data) { + GimpPalette *palette; + + palette = GIMP_PALETTE (editor->data); + g_signal_connect (G_OBJECT (editor->data), "invalidate_preview", G_CALLBACK (palette_editor_invalidate_preview), editor); + gtk_adjustment_set_value (palette_editor->columns_data, + palette->n_columns); + palette_editor_invalidate_preview (GIMP_PALETTE (editor->data), palette_editor); palette_editor_scroll_top_left (palette_editor); + } + + g_signal_handlers_unblock_by_func (G_OBJECT (palette_editor->columns_data), + palette_editor_columns_changed, + editor); + g_signal_handler_unblock (G_OBJECT (palette_editor->color_name), + palette_editor->entry_sig_id); } /* public functions */ @@ -427,162 +452,6 @@ gimp_palette_editor_update_color (GimpContext *context, /* private functions */ -/* the palette dialog popup menu & callbacks *******************************/ - -static void -palette_editor_create_popup_menu (GimpPaletteEditor *palette_editor) -{ - GtkWidget *menu; - GtkWidget *menu_item; - - palette_editor->popup_menu = menu = gtk_menu_new (); - - menu_item = gtk_menu_item_new_with_label (_("New")); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); - gtk_widget_show (menu_item); - - g_signal_connect (G_OBJECT (menu_item), "activate", - G_CALLBACK (palette_editor_new_entry_callback), - palette_editor); - - menu_item = gtk_menu_item_new_with_label (_("Edit")); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); - gtk_widget_show (menu_item); - - g_signal_connect (G_OBJECT (menu_item), "activate", - G_CALLBACK (palette_editor_edit_entry_callback), - palette_editor); - - palette_editor->edit_menu_item = menu_item; - - menu_item = gtk_menu_item_new_with_label (_("Delete")); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); - gtk_widget_show (menu_item); - - g_signal_connect (G_OBJECT (menu_item), "activate", - G_CALLBACK (palette_editor_delete_entry_callback), - palette_editor); - - palette_editor->delete_menu_item = menu_item; -} - -static void -palette_editor_new_entry_callback (GtkWidget *widget, - GimpPaletteEditor *editor) -{ - GimpPalette *palette; - GimpContext *user_context; - GimpRGB color; - - palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); - - if (! palette) - return; - - user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp); - - if (active_color == FOREGROUND) - gimp_context_get_foreground (user_context, &color); - else if (active_color == BACKGROUND) - gimp_context_get_background (user_context, &color); - - editor->color = gimp_palette_add_entry (palette, NULL, &color); -} - -static void -palette_editor_edit_entry_callback (GtkWidget *widget, - GimpPaletteEditor *editor) -{ - GimpPalette *palette; - - palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); - - if (! (palette && editor->color)) - return; - - if (! editor->color_notebook) - { - editor->color_notebook = - color_notebook_new (_("Edit Palette Color"), - (const GimpRGB *) &editor->color->color, - palette_editor_color_notebook_callback, - editor, - FALSE, - FALSE); - editor->color_notebook_active = TRUE; - } - else - { - if (! editor->color_notebook_active) - { - color_notebook_show (editor->color_notebook); - editor->color_notebook_active = TRUE; - } - - color_notebook_set_color (editor->color_notebook, - &editor->color->color); - } -} - -static void -palette_editor_delete_entry_callback (GtkWidget *widget, - GimpPaletteEditor *editor) -{ - GimpPalette *palette; - - palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); - - if (! (palette && editor->color)) - return; - - gimp_palette_delete_entry (palette, editor->color); -} - -static void -palette_editor_color_notebook_callback (ColorNotebook *color_notebook, - const GimpRGB *color, - ColorNotebookState state, - gpointer data) -{ - GimpPaletteEditor *editor; - GimpPalette *palette; - GimpContext *user_context; - - editor = GIMP_PALETTE_EDITOR (data); - - palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); - - user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->gimp); - - switch (state) - { - case COLOR_NOTEBOOK_UPDATE: - break; - - case COLOR_NOTEBOOK_OK: - if (editor->color) - { - editor->color->color = *color; - - /* Update either foreground or background colors */ - if (active_color == FOREGROUND) - gimp_context_set_foreground (user_context, color); - else if (active_color == BACKGROUND) - gimp_context_set_background (user_context, color); - - gimp_data_dirty (GIMP_DATA (palette)); - } - - /* Fallthrough */ - case COLOR_NOTEBOOK_CANCEL: - if (editor->color_notebook_active) - { - color_notebook_hide (editor->color_notebook); - editor->color_notebook_active = FALSE; - } - } -} - /* the color area event callbacks ******************************************/ static gint @@ -595,15 +464,11 @@ palette_editor_eventbox_button_press (GtkWidget *widget, if (bevent->button == 3) { - if (GTK_WIDGET_SENSITIVE (editor->edit_menu_item)) - { - gtk_widget_set_sensitive (editor->edit_menu_item, FALSE); - gtk_widget_set_sensitive (editor->delete_menu_item, FALSE); - } + GimpItemFactory *factory; - gtk_menu_popup (GTK_MENU (editor->popup_menu), NULL, NULL, - NULL, NULL, 3, - bevent->time); + factory = gimp_item_factory_from_path (""); + + gimp_item_factory_popup_with_data (factory, editor, NULL); } return TRUE; @@ -631,7 +496,7 @@ palette_editor_color_area_events (GtkWidget *widget, { case GDK_EXPOSE: palette_editor_redraw (editor); - break; + return FALSE; case GDK_BUTTON_PRESS: bevent = (GdkEventButton *) event; @@ -685,9 +550,6 @@ palette_editor_color_area_events (GtkWidget *widget, palette_editor_draw_entries (editor, row, col); /* Update the active color name */ - g_print ("former color name: '%s'\n", - editor->color->name); - g_signal_handler_block (G_OBJECT (editor->color_name), editor->entry_sig_id); @@ -697,40 +559,27 @@ palette_editor_color_area_events (GtkWidget *widget, g_signal_handler_unblock (G_OBJECT (editor->color_name), editor->entry_sig_id); - g_print ("new color name: '%s'\n", - editor->color->name); - gtk_widget_set_sensitive (editor->color_name, TRUE); /* palette_update_current_entry (editor); */ if (bevent->button == 3) { - if (! GTK_WIDGET_SENSITIVE (editor->edit_menu_item)) - { - gtk_widget_set_sensitive (editor->edit_menu_item, TRUE); - gtk_widget_set_sensitive (editor->delete_menu_item, TRUE); - } + GimpItemFactory *factory; - gtk_menu_popup (GTK_MENU (editor->popup_menu), - NULL, NULL, - NULL, NULL, 3, - bevent->time); + factory = gimp_item_factory_from_path (""); + + gimp_item_factory_popup_with_data (factory, editor, NULL); } } else { if (bevent->button == 3) { - if (GTK_WIDGET_SENSITIVE (editor->edit_menu_item)) - { - gtk_widget_set_sensitive (editor->edit_menu_item, FALSE); - gtk_widget_set_sensitive (editor->delete_menu_item, FALSE); - } + GimpItemFactory *factory; - gtk_menu_popup (GTK_MENU (editor->popup_menu), - NULL, NULL, - NULL, NULL, 3, - bevent->time); + factory = gimp_item_factory_from_path (""); + + gimp_item_factory_popup_with_data (factory, editor, NULL); } } } @@ -740,7 +589,7 @@ palette_editor_color_area_events (GtkWidget *widget, break; } - return FALSE; + return TRUE; } /* functions for drawing & updating the palette dialog color area **********/ @@ -1092,6 +941,22 @@ palette_editor_color_name_changed (GtkWidget *widget, gimp_data_dirty (GIMP_DATA (palette)); } +/* the columns spinbutton callback *****************************************/ + +static void +palette_editor_columns_changed (GtkAdjustment *adj, + GimpPaletteEditor *editor) +{ + GimpPalette *palette; + + palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); + + if (! palette) + return; + + gimp_palette_set_n_columns (palette, ROUND (adj->value)); +} + /* palette zoom functions & callbacks **************************************/ static void @@ -1154,12 +1019,22 @@ palette_editor_redraw_zoom (GimpPaletteEditor *editor) editor->zoom_factor = 0.1; } - editor->columns = COLUMNS; + if (GIMP_DATA_EDITOR (editor)->data) + { + GimpPalette *palette; - editor->columns_valid = FALSE; - palette_editor_redraw (editor); + palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); - palette_editor_scroll_top_left (editor); + if (palette->n_columns) + editor->columns = palette->n_columns; + else + editor->columns = COLUMNS; + + editor->columns_valid = FALSE; + palette_editor_redraw (editor); + + palette_editor_scroll_top_left (editor); + } } @@ -1214,6 +1089,11 @@ static void palette_editor_invalidate_preview (GimpPalette *palette, GimpPaletteEditor *editor) { + if (palette->n_columns) + editor->columns = palette->n_columns; + else + editor->columns = COLUMNS; + editor->columns_valid = FALSE; palette_editor_redraw (editor); diff --git a/app/widgets/gimppaletteeditor.h b/app/widgets/gimppaletteeditor.h index 170ee44b9e..3adc6037f0 100644 --- a/app/widgets/gimppaletteeditor.h +++ b/app/widgets/gimppaletteeditor.h @@ -49,11 +49,9 @@ struct _GimpPaletteEditor GtkWidget *color_area; GtkWidget *scrolled_window; - GtkWidget *color_name; - GtkWidget *popup_menu; - GtkWidget *delete_menu_item; - GtkWidget *edit_menu_item; + GtkWidget *color_name; + GtkAdjustment *columns_data; ColorNotebook *color_notebook; gboolean color_notebook_active; @@ -76,6 +74,8 @@ struct _GimpPaletteEditorClass }; +GType gimp_palette_editor_get_type (void) G_GNUC_CONST; + GimpDataEditor * gimp_palette_editor_new (Gimp *gimp); void gimp_palette_editor_update_color (GimpContext *context,