diff --git a/ChangeLog b/ChangeLog index 30885a4770..7be3169cf4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,43 @@ +2001-02-18 Michael Natterer + + * app/gimpdnd.[ch]: added DND source functions which work by + GtkType. + + * app/commands.c + * app/brush_select.c + * app/gradient_select.[ch] + * app/pattern_select.c: removed the DND code here because it's all + done by the GimpContainerView now. + + * app/gimpbrushpreview.c + * app/gimpgradientpreview.c + * app/gimppalettepreview.c + * app/gimppatternpreview.c: use the DND by-type connect functions. + + * app/gimpbrushgenerated.c: implemented "duplicate", cleanup. + + * app/gimpcontainergridview.c + * app/gimpcontainerlistview.c + * app/gimpcontainerview.[ch]: added a "activate_item" signal + method which is emitted by the subclasses to indicate double click. + + * app/gimpdatafactoryview.c: connect to "activate_item" and show + the editor. + + * app/convert.c + * app/gimppalette.[ch] + * app/palette.c + * app/paletteP.h + * app/palette_import.c + * app/palette_select.[ch]: major cleanup: Behaves like the other + datatypes now: DND, context stuff, GimpContainerListViews in + the dialogs etc. Mostly just removal of code. + + * app/gradient_editor.c: fixed signal blocking/unblocking. + + * plug-ins/script-fu/scripts/Makefile.am: install the "Test Sphere" + script again. + 2001-02-17 Michael Natterer * app/gimpcontainer.[ch] diff --git a/app/actions/help-commands.c b/app/actions/help-commands.c index f0241e8a95..507ab9b090 100644 --- a/app/actions/help-commands.c +++ b/app/actions/help-commands.c @@ -83,7 +83,6 @@ #include "gimpcontainergridview.h" #include "gimpdatafactory.h" #include "gimpdatafactoryview.h" -#include "gimpdnd.h" #include "gimppreview.h" @@ -1335,108 +1334,38 @@ container_view_scale_callback (GtkAdjustment *adj, gimp_container_view_set_preview_size (view, ROUND (adj->value)); } -static void -drop_viewable_callback (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - GimpContainerView *view; - - view = GIMP_CONTAINER_VIEW (widget); - - gimp_context_set_by_type (view->context, - view->container->children_type, - GIMP_OBJECT (viewable)); -} - static void brushes_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_brush_factory->container); - - 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 patterns_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_pattern_factory->container); - - 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 gradients_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_gradient_factory->container); - - 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 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_factory->container); - - 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) { - 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, image_context); } @@ -1585,15 +1514,6 @@ container_multi_view_new (gboolean list, 5, 5); } - gimp_gtk_drag_dest_set_by_type (view, - GTK_DEST_DEFAULT_ALL, - container->children_type, - GDK_ACTION_COPY); - gimp_dnd_viewable_dest_set (GTK_WIDGET (view), - GIMP_CONTAINER_VIEW (view)->container->children_type, - drop_viewable_callback, - NULL); - dialog = gimp_dialog_new (title, "test", gimp_standard_help_func, NULL, @@ -1772,7 +1692,7 @@ dialogs_test_gradient_container_list_view_cmd_callback (GtkWidget *widget, data_factory_view_new (GIMP_VIEW_TYPE_LIST, "Gradient List", global_gradient_factory, - gradient_editor_set_gradient, + NULL, gimp_context_get_user (), 24); } @@ -1820,7 +1740,7 @@ dialogs_test_gradient_container_grid_view_cmd_callback (GtkWidget *widget, data_factory_view_new (GIMP_VIEW_TYPE_GRID, "Gradient Grid", global_gradient_factory, - gradient_editor_set_gradient, + NULL, gimp_context_get_user (), 24); } diff --git a/app/brush_select.c b/app/brush_select.c index 4bfb2de7ad..7920af8e68 100644 --- a/app/brush_select.c +++ b/app/brush_select.c @@ -37,7 +37,6 @@ #include "gimpcontext.h" #include "gimpdata.h" #include "gimpdatafactory.h" -#include "gimpdnd.h" #include "gimprc.h" #include "session.h" #include "temp_buf.h" @@ -58,9 +57,6 @@ static void brush_select_change_callbacks (BrushSelect *bsp, gboolean closing); -static void brush_select_drop_brush (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); static void brush_select_brush_changed (GimpContext *context, GimpBrush *brush, BrushSelect *bsp); @@ -93,8 +89,9 @@ GSList *brush_active_dialogs = NULL; /* the main brush selection dialog */ BrushSelect *brush_select_dialog = NULL; -/* Brush editor dialog */ -static BrushEditGeneratedWindow *brush_edit_generated_dialog; + +/* the main brush editor dialog */ +static BrushEditGeneratedWindow *brush_edit_generated_dialog = NULL; /* public functions */ @@ -246,15 +243,6 @@ brush_select_new (gchar *title, TRUE, TRUE, 0); gtk_widget_show (bsp->view); - gimp_gtk_drag_dest_set_by_type (bsp->view, - GTK_DEST_DEFAULT_ALL, - GIMP_TYPE_BRUSH, - GDK_ACTION_COPY); - gimp_dnd_viewable_dest_set (GTK_WIDGET (bsp->view), - GIMP_TYPE_BRUSH, - brush_select_drop_brush, - bsp); - gtk_widget_show (bsp->brush_selection_box); gtk_widget_show (bsp->left_box); @@ -264,6 +252,7 @@ brush_select_new (gchar *title, /* Create the active brush label */ util_box = gtk_hbox_new (FALSE, 0); + gtk_container_set_resize_mode (GTK_CONTAINER (util_box), GTK_RESIZE_QUEUE); gtk_box_pack_start (GTK_BOX (bsp->options_box), util_box, FALSE, FALSE, 2); bsp->brush_name = gtk_label_new (_("No Brushes available")); @@ -535,18 +524,6 @@ brush_select_dialogs_check (void) * Local functions */ -static void -brush_select_drop_brush (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - BrushSelect *bsp; - - bsp = (BrushSelect *) data; - - gimp_context_set_brush (bsp->context, GIMP_BRUSH (viewable)); -} - static void brush_select_brush_changed (GimpContext *context, GimpBrush *brush, @@ -556,6 +533,9 @@ brush_select_brush_changed (GimpContext *context, { brush_select_update_active_brush_field (bsp); + gtk_widget_set_sensitive (GIMP_DATA_FACTORY_VIEW (bsp->view)->edit_button, + GIMP_IS_BRUSH_GENERATED (brush)); + if (bsp->callback_name) brush_select_change_callbacks (bsp, FALSE); } diff --git a/app/commands.c b/app/commands.c index f0241e8a95..507ab9b090 100644 --- a/app/commands.c +++ b/app/commands.c @@ -83,7 +83,6 @@ #include "gimpcontainergridview.h" #include "gimpdatafactory.h" #include "gimpdatafactoryview.h" -#include "gimpdnd.h" #include "gimppreview.h" @@ -1335,108 +1334,38 @@ container_view_scale_callback (GtkAdjustment *adj, gimp_container_view_set_preview_size (view, ROUND (adj->value)); } -static void -drop_viewable_callback (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - GimpContainerView *view; - - view = GIMP_CONTAINER_VIEW (widget); - - gimp_context_set_by_type (view->context, - view->container->children_type, - GIMP_OBJECT (viewable)); -} - static void brushes_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_brush_factory->container); - - 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 patterns_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_pattern_factory->container); - - 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 gradients_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_gradient_factory->container); - - 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 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_factory->container); - - 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) { - 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, image_context); } @@ -1585,15 +1514,6 @@ container_multi_view_new (gboolean list, 5, 5); } - gimp_gtk_drag_dest_set_by_type (view, - GTK_DEST_DEFAULT_ALL, - container->children_type, - GDK_ACTION_COPY); - gimp_dnd_viewable_dest_set (GTK_WIDGET (view), - GIMP_CONTAINER_VIEW (view)->container->children_type, - drop_viewable_callback, - NULL); - dialog = gimp_dialog_new (title, "test", gimp_standard_help_func, NULL, @@ -1772,7 +1692,7 @@ dialogs_test_gradient_container_list_view_cmd_callback (GtkWidget *widget, data_factory_view_new (GIMP_VIEW_TYPE_LIST, "Gradient List", global_gradient_factory, - gradient_editor_set_gradient, + NULL, gimp_context_get_user (), 24); } @@ -1820,7 +1740,7 @@ dialogs_test_gradient_container_grid_view_cmd_callback (GtkWidget *widget, data_factory_view_new (GIMP_VIEW_TYPE_GRID, "Gradient Grid", global_gradient_factory, - gradient_editor_set_gradient, + NULL, gimp_context_get_user (), 24); } diff --git a/app/convert.c b/app/convert.c index f6114420a3..6a77efee5b 100644 --- a/app/convert.c +++ b/app/convert.c @@ -949,29 +949,23 @@ indexed_palette_select_destroy_callback (GtkWidget *widget, } static gint -indexed_palette_select_row_callback (GtkCList *clist, - gint row, - gint column, - GdkEventButton *event, - gpointer data) +indexed_palette_select_palette (GimpContext *context, + GimpPalette *palette, + gpointer data) { - IndexedDialog *dialog = (IndexedDialog *)data; - GimpPalette *palette; + IndexedDialog *dialog; - palette = (GimpPalette *) gtk_clist_get_row_data (clist, row); + dialog = (IndexedDialog *) data; if (palette) { if (palette->n_colors <= 256) { theCustomPalette = palette; + gtk_label_set_text (GTK_LABEL (GTK_BIN (dialog->custom_palette_button)->child), GIMP_OBJECT (theCustomPalette)->name); } - else - { - gtk_clist_unselect_row (clist, row, column); - } } return FALSE; @@ -993,8 +987,9 @@ indexed_custom_palette_button_callback (GtkWidget *widget, gtk_signal_connect (GTK_OBJECT (dialog->palette_select->shell), "destroy", GTK_SIGNAL_FUNC (indexed_palette_select_destroy_callback), dialog); - gtk_signal_connect (GTK_OBJECT (dialog->palette_select->clist), "select_row", - GTK_SIGNAL_FUNC (indexed_palette_select_row_callback), + gtk_signal_connect (GTK_OBJECT (dialog->palette_select->context), + "palette_changed", + GTK_SIGNAL_FUNC (indexed_palette_select_palette), dialog); } else diff --git a/app/core/gimpbrushgenerated-load.c b/app/core/gimpbrushgenerated-load.c index f0e3567041..0d865a7ca9 100644 --- a/app/core/gimpbrushgenerated-load.c +++ b/app/core/gimpbrushgenerated-load.c @@ -48,12 +48,13 @@ /* local function prototypes */ -static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass); -static void gimp_brush_generated_init (GimpBrushGenerated *brush); -static void gimp_brush_generated_destroy (GtkObject *object); -static gboolean gimp_brush_generated_save (GimpData *data); -static void gimp_brush_generated_dirty (GimpData *data); -static gchar * gimp_brush_generated_get_extension (GimpData *data); +static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass); +static void gimp_brush_generated_init (GimpBrushGenerated *brush); +static void gimp_brush_generated_destroy (GtkObject *object); +static gboolean gimp_brush_generated_save (GimpData *data); +static void gimp_brush_generated_dirty (GimpData *data); +static gchar * gimp_brush_generated_get_extension (GimpData *data); +static GimpData * gimp_brush_generated_duplicate (GimpData *data); static GimpBrushClass *parent_class = NULL; @@ -100,6 +101,7 @@ gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass) data_class->save = gimp_brush_generated_save; data_class->dirty = gimp_brush_generated_dirty; data_class->get_extension = gimp_brush_generated_get_extension; + data_class->duplicate = gimp_brush_generated_duplicate; } static void @@ -172,6 +174,19 @@ gimp_brush_generated_get_extension (GimpData *data) return GIMP_BRUSH_GENERATED_FILE_EXTENSION; } +static GimpData * +gimp_brush_generated_duplicate (GimpData *data) +{ + GimpBrushGenerated *brush; + + brush = GIMP_BRUSH_GENERATED (data); + + return gimp_brush_generated_new (brush->radius, + brush->hardness, + brush->angle, + brush->aspect_ratio); +} + static double gauss (gdouble f) { diff --git a/app/core/gimpbrushgenerated-save.c b/app/core/gimpbrushgenerated-save.c index f0e3567041..0d865a7ca9 100644 --- a/app/core/gimpbrushgenerated-save.c +++ b/app/core/gimpbrushgenerated-save.c @@ -48,12 +48,13 @@ /* local function prototypes */ -static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass); -static void gimp_brush_generated_init (GimpBrushGenerated *brush); -static void gimp_brush_generated_destroy (GtkObject *object); -static gboolean gimp_brush_generated_save (GimpData *data); -static void gimp_brush_generated_dirty (GimpData *data); -static gchar * gimp_brush_generated_get_extension (GimpData *data); +static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass); +static void gimp_brush_generated_init (GimpBrushGenerated *brush); +static void gimp_brush_generated_destroy (GtkObject *object); +static gboolean gimp_brush_generated_save (GimpData *data); +static void gimp_brush_generated_dirty (GimpData *data); +static gchar * gimp_brush_generated_get_extension (GimpData *data); +static GimpData * gimp_brush_generated_duplicate (GimpData *data); static GimpBrushClass *parent_class = NULL; @@ -100,6 +101,7 @@ gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass) data_class->save = gimp_brush_generated_save; data_class->dirty = gimp_brush_generated_dirty; data_class->get_extension = gimp_brush_generated_get_extension; + data_class->duplicate = gimp_brush_generated_duplicate; } static void @@ -172,6 +174,19 @@ gimp_brush_generated_get_extension (GimpData *data) return GIMP_BRUSH_GENERATED_FILE_EXTENSION; } +static GimpData * +gimp_brush_generated_duplicate (GimpData *data) +{ + GimpBrushGenerated *brush; + + brush = GIMP_BRUSH_GENERATED (data); + + return gimp_brush_generated_new (brush->radius, + brush->hardness, + brush->angle, + brush->aspect_ratio); +} + static double gauss (gdouble f) { diff --git a/app/core/gimpbrushgenerated.c b/app/core/gimpbrushgenerated.c index f0e3567041..0d865a7ca9 100644 --- a/app/core/gimpbrushgenerated.c +++ b/app/core/gimpbrushgenerated.c @@ -48,12 +48,13 @@ /* local function prototypes */ -static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass); -static void gimp_brush_generated_init (GimpBrushGenerated *brush); -static void gimp_brush_generated_destroy (GtkObject *object); -static gboolean gimp_brush_generated_save (GimpData *data); -static void gimp_brush_generated_dirty (GimpData *data); -static gchar * gimp_brush_generated_get_extension (GimpData *data); +static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass); +static void gimp_brush_generated_init (GimpBrushGenerated *brush); +static void gimp_brush_generated_destroy (GtkObject *object); +static gboolean gimp_brush_generated_save (GimpData *data); +static void gimp_brush_generated_dirty (GimpData *data); +static gchar * gimp_brush_generated_get_extension (GimpData *data); +static GimpData * gimp_brush_generated_duplicate (GimpData *data); static GimpBrushClass *parent_class = NULL; @@ -100,6 +101,7 @@ gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass) data_class->save = gimp_brush_generated_save; data_class->dirty = gimp_brush_generated_dirty; data_class->get_extension = gimp_brush_generated_get_extension; + data_class->duplicate = gimp_brush_generated_duplicate; } static void @@ -172,6 +174,19 @@ gimp_brush_generated_get_extension (GimpData *data) return GIMP_BRUSH_GENERATED_FILE_EXTENSION; } +static GimpData * +gimp_brush_generated_duplicate (GimpData *data) +{ + GimpBrushGenerated *brush; + + brush = GIMP_BRUSH_GENERATED (data); + + return gimp_brush_generated_new (brush->radius, + brush->hardness, + brush->angle, + brush->aspect_ratio); +} + static double gauss (gdouble f) { diff --git a/app/core/gimpimage-convert.c b/app/core/gimpimage-convert.c index f6114420a3..6a77efee5b 100644 --- a/app/core/gimpimage-convert.c +++ b/app/core/gimpimage-convert.c @@ -949,29 +949,23 @@ indexed_palette_select_destroy_callback (GtkWidget *widget, } static gint -indexed_palette_select_row_callback (GtkCList *clist, - gint row, - gint column, - GdkEventButton *event, - gpointer data) +indexed_palette_select_palette (GimpContext *context, + GimpPalette *palette, + gpointer data) { - IndexedDialog *dialog = (IndexedDialog *)data; - GimpPalette *palette; + IndexedDialog *dialog; - palette = (GimpPalette *) gtk_clist_get_row_data (clist, row); + dialog = (IndexedDialog *) data; if (palette) { if (palette->n_colors <= 256) { theCustomPalette = palette; + gtk_label_set_text (GTK_LABEL (GTK_BIN (dialog->custom_palette_button)->child), GIMP_OBJECT (theCustomPalette)->name); } - else - { - gtk_clist_unselect_row (clist, row, column); - } } return FALSE; @@ -993,8 +987,9 @@ indexed_custom_palette_button_callback (GtkWidget *widget, gtk_signal_connect (GTK_OBJECT (dialog->palette_select->shell), "destroy", GTK_SIGNAL_FUNC (indexed_palette_select_destroy_callback), dialog); - gtk_signal_connect (GTK_OBJECT (dialog->palette_select->clist), "select_row", - GTK_SIGNAL_FUNC (indexed_palette_select_row_callback), + gtk_signal_connect (GTK_OBJECT (dialog->palette_select->context), + "palette_changed", + GTK_SIGNAL_FUNC (indexed_palette_select_palette), dialog); } else diff --git a/app/core/gimppalette-load.c b/app/core/gimppalette-load.c index 678234322a..42fa118a4b 100644 --- a/app/core/gimppalette-load.c +++ b/app/core/gimppalette-load.c @@ -115,8 +115,6 @@ gimp_palette_init (GimpPalette *palette) palette->n_colors = 0; palette->n_columns = 0; - - palette->pixmap = NULL; } static void @@ -139,9 +137,6 @@ gimp_palette_destroy (GtkObject *object) g_list_free (palette->colors); - if (palette->pixmap) - gdk_pixmap_unref (palette->pixmap); - if (GTK_OBJECT_CLASS (parent_class)->destroy) GTK_OBJECT_CLASS (parent_class)->destroy (object); } @@ -555,70 +550,6 @@ gimp_palette_delete_entry (GimpPalette *palette, } } -void -gimp_palette_update_preview (GimpPalette *palette, - GdkGC *gc) -{ - GimpPaletteEntry *entry; - guchar rgb_buf[SM_PREVIEW_WIDTH * SM_PREVIEW_HEIGHT * 3]; - GList *list; - gint index; - - g_return_if_fail (palette != NULL); - g_return_if_fail (GIMP_IS_PALETTE (palette)); - - g_return_if_fail (gc != NULL); - - memset (rgb_buf, 0x0, sizeof (rgb_buf)); - - gdk_draw_rgb_image (palette->pixmap, - gc, - 0, - 0, - SM_PREVIEW_WIDTH, - SM_PREVIEW_HEIGHT, - GDK_RGB_DITHER_NORMAL, - rgb_buf, - SM_PREVIEW_WIDTH * 3); - - index = 0; - - for (list = palette->colors; list; list = g_list_next (list)) - { - guchar cell[3 * 3 * 3]; - gint loop; - - entry = (GimpPaletteEntry *) list->data; - - gimp_rgb_get_uchar (&entry->color, - &cell[0], - &cell[1], - &cell[2]); - - for (loop = 3; loop < 27 ; loop += 3) - { - cell[0 + loop] = cell[0]; - cell[1 + loop] = cell[1]; - cell[2 + loop] = cell[2]; - } - - gdk_draw_rgb_image (palette->pixmap, - gc, - 1 + (index % ((SM_PREVIEW_WIDTH-2) / 3)) * 3, - 1 + (index / ((SM_PREVIEW_WIDTH-2) / 3)) * 3, - 3, - 3, - GDK_RGB_DITHER_NORMAL, - cell, - 3); - - index++; - - if (index >= (((SM_PREVIEW_WIDTH - 2) * (SM_PREVIEW_HEIGHT - 2)) / 9)) - break; - } -} - static void gimp_palette_entry_free (GimpPaletteEntry *entry) { diff --git a/app/core/gimppalette-save.c b/app/core/gimppalette-save.c index 678234322a..42fa118a4b 100644 --- a/app/core/gimppalette-save.c +++ b/app/core/gimppalette-save.c @@ -115,8 +115,6 @@ gimp_palette_init (GimpPalette *palette) palette->n_colors = 0; palette->n_columns = 0; - - palette->pixmap = NULL; } static void @@ -139,9 +137,6 @@ gimp_palette_destroy (GtkObject *object) g_list_free (palette->colors); - if (palette->pixmap) - gdk_pixmap_unref (palette->pixmap); - if (GTK_OBJECT_CLASS (parent_class)->destroy) GTK_OBJECT_CLASS (parent_class)->destroy (object); } @@ -555,70 +550,6 @@ gimp_palette_delete_entry (GimpPalette *palette, } } -void -gimp_palette_update_preview (GimpPalette *palette, - GdkGC *gc) -{ - GimpPaletteEntry *entry; - guchar rgb_buf[SM_PREVIEW_WIDTH * SM_PREVIEW_HEIGHT * 3]; - GList *list; - gint index; - - g_return_if_fail (palette != NULL); - g_return_if_fail (GIMP_IS_PALETTE (palette)); - - g_return_if_fail (gc != NULL); - - memset (rgb_buf, 0x0, sizeof (rgb_buf)); - - gdk_draw_rgb_image (palette->pixmap, - gc, - 0, - 0, - SM_PREVIEW_WIDTH, - SM_PREVIEW_HEIGHT, - GDK_RGB_DITHER_NORMAL, - rgb_buf, - SM_PREVIEW_WIDTH * 3); - - index = 0; - - for (list = palette->colors; list; list = g_list_next (list)) - { - guchar cell[3 * 3 * 3]; - gint loop; - - entry = (GimpPaletteEntry *) list->data; - - gimp_rgb_get_uchar (&entry->color, - &cell[0], - &cell[1], - &cell[2]); - - for (loop = 3; loop < 27 ; loop += 3) - { - cell[0 + loop] = cell[0]; - cell[1 + loop] = cell[1]; - cell[2 + loop] = cell[2]; - } - - gdk_draw_rgb_image (palette->pixmap, - gc, - 1 + (index % ((SM_PREVIEW_WIDTH-2) / 3)) * 3, - 1 + (index / ((SM_PREVIEW_WIDTH-2) / 3)) * 3, - 3, - 3, - GDK_RGB_DITHER_NORMAL, - cell, - 3); - - index++; - - if (index >= (((SM_PREVIEW_WIDTH - 2) * (SM_PREVIEW_HEIGHT - 2)) / 9)) - break; - } -} - static void gimp_palette_entry_free (GimpPaletteEntry *entry) { diff --git a/app/core/gimppalette.c b/app/core/gimppalette.c index 678234322a..42fa118a4b 100644 --- a/app/core/gimppalette.c +++ b/app/core/gimppalette.c @@ -115,8 +115,6 @@ gimp_palette_init (GimpPalette *palette) palette->n_colors = 0; palette->n_columns = 0; - - palette->pixmap = NULL; } static void @@ -139,9 +137,6 @@ gimp_palette_destroy (GtkObject *object) g_list_free (palette->colors); - if (palette->pixmap) - gdk_pixmap_unref (palette->pixmap); - if (GTK_OBJECT_CLASS (parent_class)->destroy) GTK_OBJECT_CLASS (parent_class)->destroy (object); } @@ -555,70 +550,6 @@ gimp_palette_delete_entry (GimpPalette *palette, } } -void -gimp_palette_update_preview (GimpPalette *palette, - GdkGC *gc) -{ - GimpPaletteEntry *entry; - guchar rgb_buf[SM_PREVIEW_WIDTH * SM_PREVIEW_HEIGHT * 3]; - GList *list; - gint index; - - g_return_if_fail (palette != NULL); - g_return_if_fail (GIMP_IS_PALETTE (palette)); - - g_return_if_fail (gc != NULL); - - memset (rgb_buf, 0x0, sizeof (rgb_buf)); - - gdk_draw_rgb_image (palette->pixmap, - gc, - 0, - 0, - SM_PREVIEW_WIDTH, - SM_PREVIEW_HEIGHT, - GDK_RGB_DITHER_NORMAL, - rgb_buf, - SM_PREVIEW_WIDTH * 3); - - index = 0; - - for (list = palette->colors; list; list = g_list_next (list)) - { - guchar cell[3 * 3 * 3]; - gint loop; - - entry = (GimpPaletteEntry *) list->data; - - gimp_rgb_get_uchar (&entry->color, - &cell[0], - &cell[1], - &cell[2]); - - for (loop = 3; loop < 27 ; loop += 3) - { - cell[0 + loop] = cell[0]; - cell[1 + loop] = cell[1]; - cell[2 + loop] = cell[2]; - } - - gdk_draw_rgb_image (palette->pixmap, - gc, - 1 + (index % ((SM_PREVIEW_WIDTH-2) / 3)) * 3, - 1 + (index / ((SM_PREVIEW_WIDTH-2) / 3)) * 3, - 3, - 3, - GDK_RGB_DITHER_NORMAL, - cell, - 3); - - index++; - - if (index >= (((SM_PREVIEW_WIDTH - 2) * (SM_PREVIEW_HEIGHT - 2)) / 9)) - break; - } -} - static void gimp_palette_entry_free (GimpPaletteEntry *entry) { diff --git a/app/core/gimppalette.h b/app/core/gimppalette.h index 18c0bcb836..f2cd4ca584 100644 --- a/app/core/gimppalette.h +++ b/app/core/gimppalette.h @@ -55,9 +55,6 @@ struct _GimpPalette gint n_colors; gint n_columns; - - /* EEK */ - GdkPixmap *pixmap; }; struct _GimpPaletteClass diff --git a/app/dialogs/palette-import-dialog.c b/app/dialogs/palette-import-dialog.c index 1817ee1284..146249e84e 100644 --- a/app/dialogs/palette-import-dialog.c +++ b/app/dialogs/palette-import-dialog.c @@ -573,8 +573,6 @@ palette_import_create_from_grad (gchar *name) gimp_container_add (global_palette_factory->container, GIMP_OBJECT (palette)); - - palette_insert_all (palette); } } @@ -758,8 +756,6 @@ palette_import_image_make_palette (GHashTable *h_array, g_slist_free (sorted_list); gimp_container_add (global_palette_factory->container, GIMP_OBJECT (palette)); - - palette_insert_all (palette); } static void @@ -874,8 +870,6 @@ palette_import_create_from_indexed (GImage *gimage, } gimp_container_add (global_palette_factory->container, GIMP_OBJECT (palette)); - - palette_insert_all (palette); } /* the palette import action area callbacks ********************************/ diff --git a/app/gimpbrushgenerated.c b/app/gimpbrushgenerated.c index f0e3567041..0d865a7ca9 100644 --- a/app/gimpbrushgenerated.c +++ b/app/gimpbrushgenerated.c @@ -48,12 +48,13 @@ /* local function prototypes */ -static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass); -static void gimp_brush_generated_init (GimpBrushGenerated *brush); -static void gimp_brush_generated_destroy (GtkObject *object); -static gboolean gimp_brush_generated_save (GimpData *data); -static void gimp_brush_generated_dirty (GimpData *data); -static gchar * gimp_brush_generated_get_extension (GimpData *data); +static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass); +static void gimp_brush_generated_init (GimpBrushGenerated *brush); +static void gimp_brush_generated_destroy (GtkObject *object); +static gboolean gimp_brush_generated_save (GimpData *data); +static void gimp_brush_generated_dirty (GimpData *data); +static gchar * gimp_brush_generated_get_extension (GimpData *data); +static GimpData * gimp_brush_generated_duplicate (GimpData *data); static GimpBrushClass *parent_class = NULL; @@ -100,6 +101,7 @@ gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass) data_class->save = gimp_brush_generated_save; data_class->dirty = gimp_brush_generated_dirty; data_class->get_extension = gimp_brush_generated_get_extension; + data_class->duplicate = gimp_brush_generated_duplicate; } static void @@ -172,6 +174,19 @@ gimp_brush_generated_get_extension (GimpData *data) return GIMP_BRUSH_GENERATED_FILE_EXTENSION; } +static GimpData * +gimp_brush_generated_duplicate (GimpData *data) +{ + GimpBrushGenerated *brush; + + brush = GIMP_BRUSH_GENERATED (data); + + return gimp_brush_generated_new (brush->radius, + brush->hardness, + brush->angle, + brush->aspect_ratio); +} + static double gauss (gdouble f) { diff --git a/app/gimpbrushpreview.c b/app/gimpbrushpreview.c index c3f012af3b..bc4ae1f20d 100644 --- a/app/gimpbrushpreview.c +++ b/app/gimpbrushpreview.c @@ -41,8 +41,8 @@ static GtkWidget * gimp_brush_preview_create_popup (GimpPreview *preview) static gboolean gimp_brush_preview_needs_popup (GimpPreview *preview); static gboolean gimp_brush_preview_render_timeout_func (GimpBrushPreview *preview); -static GimpBrush * gimp_brush_preview_drag_brush (GtkWidget *widget, - gpointer data); +static GimpViewable * gimp_brush_preview_drag_viewable (GtkWidget *widget, + gpointer data); static GimpPreviewClass *parent_class = NULL; @@ -94,20 +94,14 @@ gimp_brush_preview_class_init (GimpBrushPreviewClass *klass) static void gimp_brush_preview_init (GimpBrushPreview *brush_preview) { - static GtkTargetEntry preview_target_table[] = - { - GIMP_TARGET_BRUSH - }; - static guint preview_n_targets = (sizeof (preview_target_table) / - sizeof (preview_target_table[0])); - - gtk_drag_source_set (GTK_WIDGET (brush_preview), - GDK_BUTTON2_MASK, - preview_target_table, preview_n_targets, - GDK_ACTION_COPY); - gimp_dnd_brush_source_set (GTK_WIDGET (brush_preview), - gimp_brush_preview_drag_brush, - brush_preview); + gimp_gtk_drag_source_set_by_type (GTK_WIDGET (brush_preview), + GDK_BUTTON2_MASK, + GIMP_TYPE_BRUSH, + GDK_ACTION_COPY); + gimp_dnd_viewable_source_set (GTK_WIDGET (brush_preview), + GIMP_TYPE_BRUSH, + gimp_brush_preview_drag_viewable, + NULL); brush_preview->pipe_timeout_id = 0; brush_preview->pipe_animation_index = 0; @@ -379,13 +373,9 @@ gimp_brush_preview_render_timeout_func (GimpBrushPreview *brush_preview) return TRUE; } -static GimpBrush * -gimp_brush_preview_drag_brush (GtkWidget *widget, - gpointer data) +static GimpViewable * +gimp_brush_preview_drag_viewable (GtkWidget *widget, + gpointer data) { - GimpPreview *preview; - - preview = GIMP_PREVIEW (data); - - return GIMP_BRUSH (preview->viewable); + return GIMP_PREVIEW (widget)->viewable; } diff --git a/app/gimpcontainergridview.c b/app/gimpcontainergridview.c index 3d052d2fa6..94fe259cb2 100644 --- a/app/gimpcontainergridview.c +++ b/app/gimpcontainergridview.c @@ -54,6 +54,8 @@ static void gimp_container_grid_view_clear_items (GimpContainerView *v static void gimp_container_grid_view_set_preview_size (GimpContainerView *view); static void gimp_container_grid_view_item_selected (GtkWidget *widget, gpointer data); +static void gimp_container_grid_view_item_activate (GtkWidget *widget, + gpointer data); static void gimp_container_grid_view_highlight_item (GimpContainerView *view, GimpViewable *viewable, gpointer insert_data); @@ -237,6 +239,10 @@ gimp_container_grid_view_insert_item (GimpContainerView *view, GTK_SIGNAL_FUNC (gimp_container_grid_view_item_selected), view); + gtk_signal_connect (GTK_OBJECT (preview), "double_clicked", + GTK_SIGNAL_FUNC (gimp_container_grid_view_item_activate), + view); + return (gpointer) preview; } @@ -338,6 +344,14 @@ gimp_container_grid_view_item_selected (GtkWidget *widget, GIMP_PREVIEW (widget)->viewable); } +static void +gimp_container_grid_view_item_activate (GtkWidget *widget, + gpointer data) +{ + gimp_container_view_item_activate (GIMP_CONTAINER_VIEW (data), + GIMP_PREVIEW (widget)->viewable); +} + static void gimp_container_grid_view_highlight_item (GimpContainerView *view, GimpViewable *viewable, diff --git a/app/gimpcontainerlistview.c b/app/gimpcontainerlistview.c index 36708b9165..853046ba75 100644 --- a/app/gimpcontainerlistview.c +++ b/app/gimpcontainerlistview.c @@ -28,6 +28,7 @@ #include "gimpcontainer.h" #include "gimpcontainerlistview.h" #include "gimpcontext.h" +#include "gimpdnd.h" #include "gimplist.h" #include "gimppreview.h" @@ -57,6 +58,11 @@ static void gimp_container_list_view_name_changed (GimpViewable *v static void gimp_container_list_view_item_selected (GtkWidget *widget, GtkWidget *child, gpointer data); +static gint gimp_container_list_view_item_activate (GtkWidget *widget, + GdkEventButton *bevent, + gpointer data); +static GimpViewable * gimp_container_list_view_drag_viewable (GtkWidget *widget, + gpointer data); static GimpContainerViewClass *parent_class = NULL; @@ -236,6 +242,19 @@ gimp_container_list_view_insert_item (GimpContainerView *view, label, GTK_OBJECT (list_view)); + gtk_signal_connect (GTK_OBJECT (list_item), "button_press_event", + GTK_SIGNAL_FUNC (gimp_container_list_view_item_activate), + list_view); + + gimp_gtk_drag_source_set_by_type (list_item, + GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, + view->container->children_type, + GDK_ACTION_COPY); + gimp_dnd_viewable_source_set (GTK_WIDGET (list_item), + view->container->children_type, + gimp_container_list_view_drag_viewable, + list_view); + gtk_widget_show (list_item); list = g_list_prepend (NULL, list_item); @@ -417,6 +436,35 @@ gimp_container_list_view_item_selected (GtkWidget *widget, viewable = GIMP_PREVIEW (gtk_object_get_data (GTK_OBJECT (child), "preview"))->viewable; - gimp_container_view_item_selected (GIMP_CONTAINER_VIEW (data), - viewable); + gimp_container_view_item_selected (GIMP_CONTAINER_VIEW (data), viewable); +} + +static gint +gimp_container_list_view_item_activate (GtkWidget *widget, + GdkEventButton *bevent, + gpointer data) +{ + if (bevent->type == GDK_2BUTTON_PRESS) + { + GimpViewable *viewable; + + viewable = GIMP_PREVIEW (gtk_object_get_data (GTK_OBJECT (widget), + "preview"))->viewable; + + gimp_container_view_item_activate (GIMP_CONTAINER_VIEW (data), viewable); + } + + return FALSE; +} + +static GimpViewable * +gimp_container_list_view_drag_viewable (GtkWidget *widget, + gpointer data) +{ + GimpViewable *viewable; + + viewable = GIMP_PREVIEW (gtk_object_get_data (GTK_OBJECT (widget), + "preview"))->viewable; + + return viewable; } diff --git a/app/gimpcontainerview.c b/app/gimpcontainerview.c index 52a1f582a7..e8055123c8 100644 --- a/app/gimpcontainerview.c +++ b/app/gimpcontainerview.c @@ -25,6 +25,7 @@ #include "gimpcontainer.h" #include "gimpcontainerview.h" #include "gimpcontext.h" +#include "gimpdnd.h" #include "gimpmarshal.h" #include "gimpviewable.h" @@ -35,6 +36,7 @@ enum REMOVE_ITEM, REORDER_ITEM, SELECT_ITEM, + ACTIVATE_ITEM, CLEAR_ITEMS, SET_PREVIEW_SIZE, LAST_SIGNAL @@ -64,6 +66,9 @@ static void gimp_container_view_reorder (GimpContainerView *view, static void gimp_container_view_context_changed (GimpContext *context, GimpViewable *viewable, GimpContainerView *view); +static void gimp_container_view_drop_viewable_callback (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); static guint view_signals[LAST_SIGNAL] = { 0 }; @@ -150,6 +155,17 @@ gimp_container_view_class_init (GimpContainerViewClass *klass) GIMP_TYPE_OBJECT, GTK_TYPE_POINTER); + view_signals[ACTIVATE_ITEM] = + gtk_signal_new ("activate_item", + GTK_RUN_FIRST, + object_class->type, + GTK_SIGNAL_OFFSET (GimpContainerViewClass, + activate_item), + gtk_marshal_NONE__POINTER_POINTER, + GTK_TYPE_NONE, 2, + GIMP_TYPE_OBJECT, + GTK_TYPE_POINTER); + view_signals[CLEAR_ITEMS] = gtk_signal_new ("clear_items", GTK_RUN_FIRST, @@ -176,6 +192,7 @@ gimp_container_view_class_init (GimpContainerViewClass *klass) klass->remove_item = NULL; klass->reorder_item = NULL; klass->select_item = NULL; + klass->activate_item = NULL; klass->clear_items = gimp_container_view_real_clear_items; klass->set_preview_size = NULL; } @@ -244,6 +261,10 @@ gimp_container_view_set_container (GimpContainerView *view, gtk_signal_disconnect_by_func (GTK_OBJECT (view->context), gimp_container_view_context_changed, view); + + gtk_drag_dest_unset (GTK_WIDGET (view)); + gimp_dnd_viewable_dest_unset (GTK_WIDGET (view), + view->container->children_type); } } @@ -285,6 +306,15 @@ gimp_container_view_set_container (GimpContainerView *view, gimp_container_view_select_item (view, object ? GIMP_VIEWABLE (object): NULL); + + 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, + gimp_container_view_drop_viewable_callback, + NULL); } } } @@ -305,6 +335,10 @@ gimp_container_view_set_context (GimpContainerView *view, gtk_signal_disconnect_by_func (GTK_OBJECT (view->context), gimp_container_view_context_changed, view); + + gtk_drag_dest_unset (GTK_WIDGET (view)); + gimp_dnd_viewable_dest_unset (GTK_WIDGET (view), + view->container->children_type); } view->context = context; @@ -326,6 +360,15 @@ gimp_container_view_set_context (GimpContainerView *view, gimp_container_view_select_item (view, object ? GIMP_VIEWABLE (object) : NULL); + + 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, + gimp_container_view_drop_viewable_callback, + NULL); } } @@ -358,6 +401,23 @@ gimp_container_view_select_item (GimpContainerView *view, viewable, insert_data); } +void +gimp_container_view_activate_item (GimpContainerView *view, + GimpViewable *viewable) +{ + gpointer insert_data; + + g_return_if_fail (view != NULL); + g_return_if_fail (GIMP_IS_CONTAINER_VIEW (view)); + g_return_if_fail (viewable != NULL); + g_return_if_fail (GIMP_IS_VIEWABLE (viewable)); + + insert_data = g_hash_table_lookup (view->hash_table, viewable); + + gtk_signal_emit (GTK_OBJECT (view), view_signals[ACTIVATE_ITEM], + viewable, insert_data); +} + void gimp_container_view_item_selected (GimpContainerView *view, GimpViewable *viewable) @@ -375,6 +435,18 @@ gimp_container_view_item_selected (GimpContainerView *view, GIMP_OBJECT (viewable)); } +void +gimp_container_view_item_activate (GimpContainerView *view, + GimpViewable *viewable) +{ + g_return_if_fail (view != NULL); + g_return_if_fail (GIMP_IS_CONTAINER_VIEW (view)); + g_return_if_fail (viewable != NULL); + g_return_if_fail (GIMP_IS_VIEWABLE (viewable)); + + gimp_container_view_activate_item (view, viewable); +} + static void gimp_container_view_clear_items (GimpContainerView *view) { @@ -465,3 +537,17 @@ gimp_container_view_context_changed (GimpContext *context, gtk_signal_emit (GTK_OBJECT (view), view_signals[SELECT_ITEM], viewable, insert_data); } + +static void +gimp_container_view_drop_viewable_callback (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) +{ + GimpContainerView *view; + + view = GIMP_CONTAINER_VIEW (widget); + + gimp_context_set_by_type (view->context, + view->container->children_type, + GIMP_OBJECT (viewable)); +} diff --git a/app/gimpcontainerview.h b/app/gimpcontainerview.h index 5e248d7a17..cb4f11d005 100644 --- a/app/gimpcontainerview.h +++ b/app/gimpcontainerview.h @@ -61,6 +61,9 @@ struct _GimpContainerViewClass void (* select_item) (GimpContainerView *view, GimpViewable *object, gpointer insert_data); + void (* activate_item) (GimpContainerView *view, + GimpViewable *object, + gpointer insert_data); void (* clear_items) (GimpContainerView *view); void (* set_preview_size) (GimpContainerView *view); }; @@ -76,12 +79,16 @@ void gimp_container_view_set_preview_size (GimpContainerView *view, gint preview_size); void gimp_container_view_select_item (GimpContainerView *view, GimpViewable *viewable); +void gimp_container_view_activate_item (GimpContainerView *view, + GimpViewable *viewable); /* private */ void gimp_container_view_item_selected (GimpContainerView *view, GimpViewable *item); +void gimp_container_view_item_activate (GimpContainerView *view, + GimpViewable *item); #endif /* __GIMP_CONTAINER_VIEW_H__ */ diff --git a/app/gimpdatafactoryview.c b/app/gimpdatafactoryview.c index 4049c28142..9567e20807 100644 --- a/app/gimpdatafactoryview.c +++ b/app/gimpdatafactoryview.c @@ -32,6 +32,7 @@ #include "gimpcontainergridview.h" #include "gimpcontainerlistview.h" #include "gimpcontext.h" +#include "gimpdnd.h" #include "gimpmarshal.h" #include "gimpviewable.h" @@ -52,16 +53,29 @@ static void gimp_data_factory_view_new_clicked (GtkWidget *wid GimpDataFactoryView *view); static void gimp_data_factory_view_duplicate_clicked (GtkWidget *widget, GimpDataFactoryView *view); +static void gimp_data_factory_view_duplicate_dropped (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); static void gimp_data_factory_view_edit_clicked (GtkWidget *widget, GimpDataFactoryView *view); +static void gimp_data_factory_view_edit_dropped (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); static void gimp_data_factory_view_delete_clicked (GtkWidget *widget, GimpDataFactoryView *view); +static void gimp_data_factory_view_delete_dropped (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); static void gimp_data_factory_view_refresh_clicked (GtkWidget *widget, GimpDataFactoryView *view); static void gimp_data_factory_view_data_changed (GimpContext *context, GimpData *data, GimpDataFactoryView *view); +static void gimp_data_factory_view_data_activate (GtkWidget *context, + GimpData *data, + gpointer insert_data, + GimpDataFactoryView *view); static GtkVBoxClass *parent_class = NULL; @@ -277,6 +291,42 @@ gimp_data_factory_view_new (GimpViewType view_type, factory_view, GTK_OBJECT (factory_view)); + gtk_signal_connect_while_alive + (GTK_OBJECT (factory_view->view), "activate_item", + GTK_SIGNAL_FUNC (gimp_data_factory_view_data_activate), + factory_view, + GTK_OBJECT (factory_view)); + + /* drop to "duplicate" */ + gimp_gtk_drag_dest_set_by_type (GTK_WIDGET (factory_view->duplicate_button), + GTK_DEST_DEFAULT_ALL, + factory_view->factory->container->children_type, + GDK_ACTION_COPY); + gimp_dnd_viewable_dest_set (GTK_WIDGET (factory_view->duplicate_button), + factory_view->factory->container->children_type, + gimp_data_factory_view_duplicate_dropped, + factory_view); + + /* drop to "edit" */ + gimp_gtk_drag_dest_set_by_type (GTK_WIDGET (factory_view->edit_button), + GTK_DEST_DEFAULT_ALL, + factory_view->factory->container->children_type, + GDK_ACTION_COPY); + gimp_dnd_viewable_dest_set (GTK_WIDGET (factory_view->edit_button), + factory_view->factory->container->children_type, + gimp_data_factory_view_edit_dropped, + factory_view); + + /* drop to "delete" */ + gimp_gtk_drag_dest_set_by_type (GTK_WIDGET (factory_view->delete_button), + GTK_DEST_DEFAULT_ALL, + factory_view->factory->container->children_type, + GDK_ACTION_COPY); + gimp_dnd_viewable_dest_set (GTK_WIDGET (factory_view->delete_button), + factory_view->factory->container->children_type, + gimp_data_factory_view_delete_dropped, + factory_view); + /* set button sensitivity */ gimp_data_factory_view_data_changed (context, @@ -346,6 +396,26 @@ gimp_data_factory_view_duplicate_clicked (GtkWidget *widget, } } +static void +gimp_data_factory_view_duplicate_dropped (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) +{ + GimpDataFactoryView *view; + + view = (GimpDataFactoryView *) data; + + if (viewable && gimp_container_have (view->factory->container, + GIMP_OBJECT (viewable))) + { + gimp_context_set_by_type (view->view->context, + view->factory->container->children_type, + GIMP_OBJECT (viewable)); + + gimp_data_factory_view_duplicate_clicked (NULL, data); + } +} + static void gimp_data_factory_view_edit_clicked (GtkWidget *widget, GimpDataFactoryView *view) @@ -365,6 +435,26 @@ gimp_data_factory_view_edit_clicked (GtkWidget *widget, } } +static void +gimp_data_factory_view_edit_dropped (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) +{ + GimpDataFactoryView *view; + + view = (GimpDataFactoryView *) data; + + if (viewable && gimp_container_have (view->factory->container, + GIMP_OBJECT (viewable))) + { + gimp_context_set_by_type (view->view->context, + view->factory->container->children_type, + GIMP_OBJECT (viewable)); + + gimp_data_factory_view_edit_clicked (NULL, data); + } +} + typedef struct _GimpDataDeleteData GimpDataDeleteData; @@ -444,6 +534,26 @@ gimp_data_factory_view_delete_clicked (GtkWidget *widget, } } +static void +gimp_data_factory_view_delete_dropped (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) +{ + GimpDataFactoryView *view; + + view = (GimpDataFactoryView *) data; + + if (viewable && gimp_container_have (view->factory->container, + GIMP_OBJECT (viewable))) + { + gimp_context_set_by_type (view->view->context, + view->factory->container->children_type, + GIMP_OBJECT (viewable)); + + gimp_data_factory_view_delete_clicked (NULL, data); + } +} + static void gimp_data_factory_view_refresh_clicked (GtkWidget *widget, GimpDataFactoryView *view) @@ -466,11 +576,24 @@ gimp_data_factory_view_data_changed (GimpContext *context, duplicate_sensitive = (GIMP_DATA_CLASS (GTK_OBJECT (data)->klass)->duplicate != NULL); - edit_sensitive = (view->data_edit_func != NULL); - delete_sensitive = TRUE; /* TODO: check permissions */ + edit_sensitive = (view->data_edit_func != NULL); + delete_sensitive = TRUE; /* TODO: check permissions */ } gtk_widget_set_sensitive (view->duplicate_button, duplicate_sensitive); gtk_widget_set_sensitive (view->edit_button, edit_sensitive); gtk_widget_set_sensitive (view->delete_button, delete_sensitive); } + +static void +gimp_data_factory_view_data_activate (GtkWidget *widget, + GimpData *data, + gpointer insert_data, + GimpDataFactoryView *view) +{ + if (data && gimp_container_have (view->factory->container, + GIMP_OBJECT (data))) + { + gimp_data_factory_view_edit_clicked (NULL, view); + } +} diff --git a/app/gimpdnd.c b/app/gimpdnd.c index 871a738693..d9053f841c 100644 --- a/app/gimpdnd.c +++ b/app/gimpdnd.c @@ -624,6 +624,79 @@ gimp_dnd_color_dest_unset (GtkWidget *widget) /* GimpViewable (by GtkType) dnd functions */ /*********************************************/ +static const GtkTargetEntry brush_target_table[] = +{ + GIMP_TARGET_BRUSH +}; +static const guint brush_n_targets = (sizeof (brush_target_table) / + sizeof (brush_target_table[0])); + +static const GtkTargetEntry pattern_target_table[] = +{ + GIMP_TARGET_PATTERN +}; +static const guint pattern_n_targets = (sizeof (pattern_target_table) / + sizeof (pattern_target_table[0])); + +static const GtkTargetEntry gradient_target_table[] = +{ + GIMP_TARGET_GRADIENT +}; +static const guint gradient_n_targets = (sizeof (gradient_target_table) / + sizeof (gradient_target_table[0])); + +static const GtkTargetEntry palette_target_table[] = +{ + GIMP_TARGET_PALETTE +}; +static const guint palette_n_targets = (sizeof (palette_target_table) / + sizeof (palette_target_table[0])); + + +void +gimp_gtk_drag_source_set_by_type (GtkWidget *widget, + GdkModifierType start_button_mask, + GtkType type, + GdkDragAction actions) +{ + const GtkTargetEntry *target_table = NULL; + guint n_targets = 0; + + if (type == GIMP_TYPE_BRUSH) + { + target_table = brush_target_table; + n_targets = brush_n_targets; + } + else if (type == GIMP_TYPE_PATTERN) + { + target_table = pattern_target_table; + n_targets = pattern_n_targets; + } + else if (type == GIMP_TYPE_GRADIENT) + { + target_table = gradient_target_table; + n_targets = gradient_n_targets; + } + else if (type == GIMP_TYPE_PALETTE) + { + target_table = palette_target_table; + n_targets = palette_n_targets; + } + else + { + g_warning ("%s(): unsupported GtkType", G_GNUC_FUNCTION); + } + + if (target_table && n_targets) + { + gtk_drag_source_set (widget, start_button_mask, + target_table, + n_targets, + actions); + } + +} + void gimp_gtk_drag_dest_set_by_type (GtkWidget *widget, GtkDestDefaults flags, @@ -633,34 +706,6 @@ gimp_gtk_drag_dest_set_by_type (GtkWidget *widget, const GtkTargetEntry *target_table = NULL; guint n_targets = 0; - static const GtkTargetEntry brush_target_table[] = - { - GIMP_TARGET_BRUSH - }; - static const guint brush_n_targets = (sizeof (brush_target_table) / - sizeof (brush_target_table[0])); - - static const GtkTargetEntry pattern_target_table[] = - { - GIMP_TARGET_PATTERN - }; - static const guint pattern_n_targets = (sizeof (pattern_target_table) / - sizeof (pattern_target_table[0])); - - static const GtkTargetEntry gradient_target_table[] = - { - GIMP_TARGET_GRADIENT - }; - static const guint gradient_n_targets = (sizeof (gradient_target_table) / - sizeof (gradient_target_table[0])); - - static const GtkTargetEntry palette_target_table[] = - { - GIMP_TARGET_PALETTE - }; - static const guint palette_n_targets = (sizeof (palette_target_table) / - sizeof (palette_target_table[0])); - if (type == GIMP_TYPE_BRUSH) { target_table = brush_target_table; @@ -695,6 +740,42 @@ gimp_gtk_drag_dest_set_by_type (GtkWidget *widget, } } +void +gimp_dnd_viewable_source_set (GtkWidget *widget, + GtkType type, + GimpDndDragViewableFunc get_viewable_func, + gpointer data) +{ + if (type == GIMP_TYPE_BRUSH) + { + gimp_dnd_brush_source_set (widget, + (GimpDndDragBrushFunc) get_viewable_func, + data); + } + else if (type == GIMP_TYPE_PATTERN) + { + gimp_dnd_pattern_source_set (widget, + (GimpDndDragPatternFunc) get_viewable_func, + data); + } + else if (type == GIMP_TYPE_GRADIENT) + { + gimp_dnd_gradient_source_set (widget, + (GimpDndDragGradientFunc) get_viewable_func, + data); + } + else if (type == GIMP_TYPE_PALETTE) + { + gimp_dnd_palette_source_set (widget, + (GimpDndDragPaletteFunc) get_viewable_func, + data); + } + else + { + g_warning ("%s(): unsupported GtkType", G_GNUC_FUNCTION); + } +} + void gimp_dnd_viewable_dest_set (GtkWidget *widget, GtkType type, diff --git a/app/gimpdnd.h b/app/gimpdnd.h index 3ee82f1051..4f4707b76b 100644 --- a/app/gimpdnd.h +++ b/app/gimpdnd.h @@ -113,20 +113,31 @@ void gimp_dnd_color_dest_unset (GtkWidget *widget); /* GimpViewable (by GtkType) dnd functions */ -typedef void (* GimpDndDropViewableFunc) (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); +typedef void (* GimpDndDropViewableFunc) (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); +typedef GimpViewable * (* GimpDndDragViewableFunc) (GtkWidget *widget, + gpointer data); -void gimp_gtk_drag_dest_set_by_type (GtkWidget *widget, - GtkDestDefaults flags, - GtkType type, - GdkDragAction actions); -void gimp_dnd_viewable_dest_set (GtkWidget *widget, - GtkType type, - GimpDndDropViewableFunc set_viewable_func, - gpointer data); -void gimp_dnd_viewable_dest_unset (GtkWidget *widget, - GtkType type); +void gimp_gtk_drag_source_set_by_type (GtkWidget *widget, + GdkModifierType start_button_mask, + GtkType type, + GdkDragAction actions); +void gimp_gtk_drag_dest_set_by_type (GtkWidget *widget, + GtkDestDefaults flags, + GtkType type, + GdkDragAction actions); + +void gimp_dnd_viewable_source_set (GtkWidget *widget, + GtkType type, + GimpDndDragViewableFunc get_viewable_func, + gpointer data); +void gimp_dnd_viewable_dest_set (GtkWidget *widget, + GtkType type, + GimpDndDropViewableFunc set_viewable_func, + gpointer data); +void gimp_dnd_viewable_dest_unset (GtkWidget *widget, + GtkType type); /* brush dnd functions */ diff --git a/app/gimpgradientpreview.c b/app/gimpgradientpreview.c index 995bec9980..d35f83b063 100644 --- a/app/gimpgradientpreview.c +++ b/app/gimpgradientpreview.c @@ -42,7 +42,7 @@ static void gimp_gradient_preview_get_size (GimpPreview *preview, static gboolean gimp_gradient_preview_needs_popup (GimpPreview *preview); static GtkWidget * gimp_gradient_preview_create_popup (GimpPreview *preview); -static GimpGradient * gimp_gradient_preview_drag_gradient (GtkWidget *widget, +static GimpViewable * gimp_gradient_preview_drag_viewable (GtkWidget *widget, gpointer data); @@ -94,20 +94,14 @@ gimp_gradient_preview_class_init (GimpGradientPreviewClass *klass) static void gimp_gradient_preview_init (GimpGradientPreview *gradient_preview) { - static GtkTargetEntry preview_target_table[] = - { - GIMP_TARGET_GRADIENT - }; - static guint preview_n_targets = (sizeof (preview_target_table) / - sizeof (preview_target_table[0])); - - gtk_drag_source_set (GTK_WIDGET (gradient_preview), - GDK_BUTTON2_MASK, - preview_target_table, preview_n_targets, - GDK_ACTION_COPY); - gimp_dnd_gradient_source_set (GTK_WIDGET (gradient_preview), - gimp_gradient_preview_drag_gradient, - gradient_preview); + gimp_gtk_drag_source_set_by_type (GTK_WIDGET (gradient_preview), + GDK_BUTTON2_MASK, + GIMP_TYPE_GRADIENT, + GDK_ACTION_COPY); + gimp_dnd_viewable_source_set (GTK_WIDGET (gradient_preview), + GIMP_TYPE_GRADIENT, + gimp_gradient_preview_drag_viewable, + NULL); } static void @@ -181,13 +175,9 @@ gimp_gradient_preview_create_popup (GimpPreview *preview) TRUE, FALSE, FALSE); } -static GimpGradient * -gimp_gradient_preview_drag_gradient (GtkWidget *widget, +static GimpViewable * +gimp_gradient_preview_drag_viewable (GtkWidget *widget, gpointer data) { - GimpPreview *preview; - - preview = GIMP_PREVIEW (data); - - return GIMP_GRADIENT (preview->viewable); + return GIMP_PREVIEW (widget)->viewable; } diff --git a/app/gimpimage-convert.c b/app/gimpimage-convert.c index f6114420a3..6a77efee5b 100644 --- a/app/gimpimage-convert.c +++ b/app/gimpimage-convert.c @@ -949,29 +949,23 @@ indexed_palette_select_destroy_callback (GtkWidget *widget, } static gint -indexed_palette_select_row_callback (GtkCList *clist, - gint row, - gint column, - GdkEventButton *event, - gpointer data) +indexed_palette_select_palette (GimpContext *context, + GimpPalette *palette, + gpointer data) { - IndexedDialog *dialog = (IndexedDialog *)data; - GimpPalette *palette; + IndexedDialog *dialog; - palette = (GimpPalette *) gtk_clist_get_row_data (clist, row); + dialog = (IndexedDialog *) data; if (palette) { if (palette->n_colors <= 256) { theCustomPalette = palette; + gtk_label_set_text (GTK_LABEL (GTK_BIN (dialog->custom_palette_button)->child), GIMP_OBJECT (theCustomPalette)->name); } - else - { - gtk_clist_unselect_row (clist, row, column); - } } return FALSE; @@ -993,8 +987,9 @@ indexed_custom_palette_button_callback (GtkWidget *widget, gtk_signal_connect (GTK_OBJECT (dialog->palette_select->shell), "destroy", GTK_SIGNAL_FUNC (indexed_palette_select_destroy_callback), dialog); - gtk_signal_connect (GTK_OBJECT (dialog->palette_select->clist), "select_row", - GTK_SIGNAL_FUNC (indexed_palette_select_row_callback), + gtk_signal_connect (GTK_OBJECT (dialog->palette_select->context), + "palette_changed", + GTK_SIGNAL_FUNC (indexed_palette_select_palette), dialog); } else diff --git a/app/gimppalette.c b/app/gimppalette.c index 678234322a..42fa118a4b 100644 --- a/app/gimppalette.c +++ b/app/gimppalette.c @@ -115,8 +115,6 @@ gimp_palette_init (GimpPalette *palette) palette->n_colors = 0; palette->n_columns = 0; - - palette->pixmap = NULL; } static void @@ -139,9 +137,6 @@ gimp_palette_destroy (GtkObject *object) g_list_free (palette->colors); - if (palette->pixmap) - gdk_pixmap_unref (palette->pixmap); - if (GTK_OBJECT_CLASS (parent_class)->destroy) GTK_OBJECT_CLASS (parent_class)->destroy (object); } @@ -555,70 +550,6 @@ gimp_palette_delete_entry (GimpPalette *palette, } } -void -gimp_palette_update_preview (GimpPalette *palette, - GdkGC *gc) -{ - GimpPaletteEntry *entry; - guchar rgb_buf[SM_PREVIEW_WIDTH * SM_PREVIEW_HEIGHT * 3]; - GList *list; - gint index; - - g_return_if_fail (palette != NULL); - g_return_if_fail (GIMP_IS_PALETTE (palette)); - - g_return_if_fail (gc != NULL); - - memset (rgb_buf, 0x0, sizeof (rgb_buf)); - - gdk_draw_rgb_image (palette->pixmap, - gc, - 0, - 0, - SM_PREVIEW_WIDTH, - SM_PREVIEW_HEIGHT, - GDK_RGB_DITHER_NORMAL, - rgb_buf, - SM_PREVIEW_WIDTH * 3); - - index = 0; - - for (list = palette->colors; list; list = g_list_next (list)) - { - guchar cell[3 * 3 * 3]; - gint loop; - - entry = (GimpPaletteEntry *) list->data; - - gimp_rgb_get_uchar (&entry->color, - &cell[0], - &cell[1], - &cell[2]); - - for (loop = 3; loop < 27 ; loop += 3) - { - cell[0 + loop] = cell[0]; - cell[1 + loop] = cell[1]; - cell[2 + loop] = cell[2]; - } - - gdk_draw_rgb_image (palette->pixmap, - gc, - 1 + (index % ((SM_PREVIEW_WIDTH-2) / 3)) * 3, - 1 + (index / ((SM_PREVIEW_WIDTH-2) / 3)) * 3, - 3, - 3, - GDK_RGB_DITHER_NORMAL, - cell, - 3); - - index++; - - if (index >= (((SM_PREVIEW_WIDTH - 2) * (SM_PREVIEW_HEIGHT - 2)) / 9)) - break; - } -} - static void gimp_palette_entry_free (GimpPaletteEntry *entry) { diff --git a/app/gimppalette.h b/app/gimppalette.h index 18c0bcb836..f2cd4ca584 100644 --- a/app/gimppalette.h +++ b/app/gimppalette.h @@ -55,9 +55,6 @@ struct _GimpPalette gint n_colors; gint n_columns; - - /* EEK */ - GdkPixmap *pixmap; }; struct _GimpPaletteClass diff --git a/app/gimppalettepreview.c b/app/gimppalettepreview.c index 9b2074e341..ee99362c9b 100644 --- a/app/gimppalettepreview.c +++ b/app/gimppalettepreview.c @@ -38,8 +38,8 @@ static void gimp_palette_preview_render (GimpPreview *preview); static GtkWidget * gimp_palette_preview_create_popup (GimpPreview *preview); static gboolean gimp_palette_preview_needs_popup (GimpPreview *preview); -static GimpPalette * gimp_palette_preview_drag_palette (GtkWidget *widget, - gpointer data); +static GimpViewable * gimp_palette_preview_drag_viewable (GtkWidget *widget, + gpointer data); static GimpPreviewClass *parent_class = NULL; @@ -89,20 +89,14 @@ gimp_palette_preview_class_init (GimpPalettePreviewClass *klass) static void gimp_palette_preview_init (GimpPalettePreview *palette_preview) { - static GtkTargetEntry preview_target_table[] = - { - GIMP_TARGET_PALETTE - }; - static guint preview_n_targets = (sizeof (preview_target_table) / - sizeof (preview_target_table[0])); - - gtk_drag_source_set (GTK_WIDGET (palette_preview), - GDK_BUTTON2_MASK, - preview_target_table, preview_n_targets, - GDK_ACTION_COPY); - gimp_dnd_palette_source_set (GTK_WIDGET (palette_preview), - gimp_palette_preview_drag_palette, - palette_preview); + gimp_gtk_drag_source_set_by_type (GTK_WIDGET (palette_preview), + GDK_BUTTON2_MASK, + GIMP_TYPE_PALETTE, + GDK_ACTION_COPY); + gimp_dnd_viewable_source_set (GTK_WIDGET (palette_preview), + GIMP_TYPE_PALETTE, + gimp_palette_preview_drag_viewable, + palette_preview); } static void @@ -176,13 +170,9 @@ gimp_palette_preview_needs_popup (GimpPreview *preview) return FALSE; } -static GimpPalette * -gimp_palette_preview_drag_palette (GtkWidget *widget, - gpointer data) +static GimpViewable * +gimp_palette_preview_drag_viewable (GtkWidget *widget, + gpointer data) { - GimpPreview *preview; - - preview = GIMP_PREVIEW (data); - - return GIMP_PALETTE (preview->viewable); + return GIMP_PREVIEW (widget)->viewable; } diff --git a/app/gimppatternpreview.c b/app/gimppatternpreview.c index 13916d7575..e69cacfc11 100644 --- a/app/gimppatternpreview.c +++ b/app/gimppatternpreview.c @@ -34,12 +34,12 @@ static void gimp_pattern_preview_class_init (GimpPatternPreviewClass *klass); static void gimp_pattern_preview_init (GimpPatternPreview *preview); -static void gimp_pattern_preview_render (GimpPreview *preview); -static GtkWidget * gimp_pattern_preview_create_popup (GimpPreview *preview); -static gboolean gimp_pattern_preview_needs_popup (GimpPreview *preview); +static void gimp_pattern_preview_render (GimpPreview *preview); +static GtkWidget * gimp_pattern_preview_create_popup (GimpPreview *preview); +static gboolean gimp_pattern_preview_needs_popup (GimpPreview *preview); -static GimpPattern * gimp_pattern_preview_drag_pattern (GtkWidget *widget, - gpointer data); +static GimpViewable * gimp_pattern_preview_drag_viewable (GtkWidget *widget, + gpointer data); static GimpPreviewClass *parent_class = NULL; @@ -89,20 +89,14 @@ gimp_pattern_preview_class_init (GimpPatternPreviewClass *klass) static void gimp_pattern_preview_init (GimpPatternPreview *pattern_preview) { - static GtkTargetEntry preview_target_table[] = - { - GIMP_TARGET_PATTERN - }; - static guint preview_n_targets = (sizeof (preview_target_table) / - sizeof (preview_target_table[0])); - - gtk_drag_source_set (GTK_WIDGET (pattern_preview), - GDK_BUTTON2_MASK, - preview_target_table, preview_n_targets, - GDK_ACTION_COPY); - gimp_dnd_pattern_source_set (GTK_WIDGET (pattern_preview), - gimp_pattern_preview_drag_pattern, - pattern_preview); + gimp_gtk_drag_source_set_by_type (GTK_WIDGET (pattern_preview), + GDK_BUTTON2_MASK, + GIMP_TYPE_PATTERN, + GDK_ACTION_COPY); + gimp_dnd_viewable_source_set (GTK_WIDGET (pattern_preview), + GIMP_TYPE_PATTERN, + gimp_pattern_preview_drag_viewable, + NULL); } static void @@ -184,13 +178,9 @@ gimp_pattern_preview_needs_popup (GimpPreview *preview) return FALSE; } -static GimpPattern * -gimp_pattern_preview_drag_pattern (GtkWidget *widget, - gpointer data) +static GimpViewable * +gimp_pattern_preview_drag_viewable (GtkWidget *widget, + gpointer data) { - GimpPreview *preview; - - preview = GIMP_PREVIEW (data); - - return GIMP_PATTERN (preview->viewable); + return GIMP_PREVIEW (widget)->viewable; } diff --git a/app/gradient_editor.c b/app/gradient_editor.c index 7733e8e803..c35c59e5fb 100644 --- a/app/gradient_editor.c +++ b/app/gradient_editor.c @@ -2933,7 +2933,8 @@ cpopup_adjust_blending_menu (GradientEditor *gradient_editor) for (i = 0; i < num_items; i++) gtk_signal_handler_block_by_data - (GTK_OBJECT (gradient_editor->control_blending_items[i]), (gpointer) i); + (GTK_OBJECT (gradient_editor->control_blending_items[i]), + gradient_editor); /* Set state */ if (equal) @@ -2949,7 +2950,8 @@ cpopup_adjust_blending_menu (GradientEditor *gradient_editor) /* Unblock signals */ for (i = 0; i < num_items; i++) - gtk_signal_handler_unblock_by_data (GTK_OBJECT (gradient_editor->control_blending_items[i]), (gpointer) i); + gtk_signal_handler_unblock_by_data (GTK_OBJECT (gradient_editor->control_blending_items[i]), + gradient_editor); } static void @@ -2968,7 +2970,8 @@ cpopup_adjust_coloring_menu (GradientEditor *gradient_editor) coloring = (int) gradient_editor->control_sel_l->color; for (i = 0; i < num_items; i++) - gtk_signal_handler_block_by_data (GTK_OBJECT (gradient_editor->control_coloring_items[i]), (gpointer) i); + gtk_signal_handler_block_by_data (GTK_OBJECT (gradient_editor->control_coloring_items[i]), + gradient_editor); /* Set state */ if (equal) @@ -2984,7 +2987,8 @@ cpopup_adjust_coloring_menu (GradientEditor *gradient_editor) /* Unblock signals */ for (i = 0; i < num_items; i++) - gtk_signal_handler_unblock_by_data (GTK_OBJECT (gradient_editor->control_coloring_items[i]), (gpointer) i); + gtk_signal_handler_unblock_by_data (GTK_OBJECT (gradient_editor->control_coloring_items[i]), + gradient_editor); } static void diff --git a/app/gradient_select.c b/app/gradient_select.c index d3325bafcb..ae0e1c3d9b 100644 --- a/app/gradient_select.c +++ b/app/gradient_select.c @@ -34,7 +34,6 @@ #include "gimpdatafactoryview.h" #include "gimpcontext.h" #include "gimpdatafactory.h" -#include "gimpdnd.h" #include "gimpgradient.h" #include "gradient_editor.h" #include "gradient_select.h" @@ -47,9 +46,6 @@ static void gradient_select_change_callbacks (GradientSelect *gsp, gboolean closing); -static void gradient_select_drop_gradient (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); static void gradient_select_gradient_changed (GimpContext *context, GimpGradient *gradient, GradientSelect *gsp); @@ -62,10 +58,11 @@ static void gradient_select_edit_gradient (GimpData *data); GSList *gradient_active_dialogs = NULL; /* the main gradient selection dialog */ -GradientSelect *gradient_select_dialog = NULL; +GradientSelect *gradient_select_dialog = NULL; -/* gradient editor dialog */ -static GradientEditor *gradient_editor_dialog; + +/* the main gradient editor dialog */ +static GradientEditor *gradient_editor_dialog = NULL; /* public functions */ @@ -179,15 +176,6 @@ gradient_select_new (gchar *title, gtk_box_pack_start (GTK_BOX (vbox), gsp->view, TRUE, TRUE, 0); gtk_widget_show (gsp->view); - gimp_gtk_drag_dest_set_by_type (gsp->view, - GTK_DEST_DEFAULT_ALL, - GIMP_TYPE_GRADIENT, - GDK_ACTION_COPY); - gimp_dnd_viewable_dest_set (GTK_WIDGET (gsp->view), - GIMP_TYPE_GRADIENT, - gradient_select_drop_gradient, - gsp); - gtk_widget_show (vbox); gtk_widget_show (gsp->shell); @@ -322,18 +310,6 @@ gradient_select_dialogs_check (void) } } -static void -gradient_select_drop_gradient (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - GradientSelect *gsp; - - gsp = (GradientSelect *) data; - - gimp_context_set_gradient (gsp->context, GIMP_GRADIENT (viewable)); -} - static void gradient_select_gradient_changed (GimpContext *context, GimpGradient *gradient, diff --git a/app/gradient_select.h b/app/gradient_select.h index fbde8d068c..70ec335513 100644 --- a/app/gradient_select.h +++ b/app/gradient_select.h @@ -37,7 +37,7 @@ struct _GradientSelect }; -/* list of active dialogs */ +/* list of active dialogs */ extern GSList *gradient_active_dialogs; /* the main gradient selection dialog */ diff --git a/app/gui/brush-select.c b/app/gui/brush-select.c index 4bfb2de7ad..7920af8e68 100644 --- a/app/gui/brush-select.c +++ b/app/gui/brush-select.c @@ -37,7 +37,6 @@ #include "gimpcontext.h" #include "gimpdata.h" #include "gimpdatafactory.h" -#include "gimpdnd.h" #include "gimprc.h" #include "session.h" #include "temp_buf.h" @@ -58,9 +57,6 @@ static void brush_select_change_callbacks (BrushSelect *bsp, gboolean closing); -static void brush_select_drop_brush (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); static void brush_select_brush_changed (GimpContext *context, GimpBrush *brush, BrushSelect *bsp); @@ -93,8 +89,9 @@ GSList *brush_active_dialogs = NULL; /* the main brush selection dialog */ BrushSelect *brush_select_dialog = NULL; -/* Brush editor dialog */ -static BrushEditGeneratedWindow *brush_edit_generated_dialog; + +/* the main brush editor dialog */ +static BrushEditGeneratedWindow *brush_edit_generated_dialog = NULL; /* public functions */ @@ -246,15 +243,6 @@ brush_select_new (gchar *title, TRUE, TRUE, 0); gtk_widget_show (bsp->view); - gimp_gtk_drag_dest_set_by_type (bsp->view, - GTK_DEST_DEFAULT_ALL, - GIMP_TYPE_BRUSH, - GDK_ACTION_COPY); - gimp_dnd_viewable_dest_set (GTK_WIDGET (bsp->view), - GIMP_TYPE_BRUSH, - brush_select_drop_brush, - bsp); - gtk_widget_show (bsp->brush_selection_box); gtk_widget_show (bsp->left_box); @@ -264,6 +252,7 @@ brush_select_new (gchar *title, /* Create the active brush label */ util_box = gtk_hbox_new (FALSE, 0); + gtk_container_set_resize_mode (GTK_CONTAINER (util_box), GTK_RESIZE_QUEUE); gtk_box_pack_start (GTK_BOX (bsp->options_box), util_box, FALSE, FALSE, 2); bsp->brush_name = gtk_label_new (_("No Brushes available")); @@ -535,18 +524,6 @@ brush_select_dialogs_check (void) * Local functions */ -static void -brush_select_drop_brush (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - BrushSelect *bsp; - - bsp = (BrushSelect *) data; - - gimp_context_set_brush (bsp->context, GIMP_BRUSH (viewable)); -} - static void brush_select_brush_changed (GimpContext *context, GimpBrush *brush, @@ -556,6 +533,9 @@ brush_select_brush_changed (GimpContext *context, { brush_select_update_active_brush_field (bsp); + gtk_widget_set_sensitive (GIMP_DATA_FACTORY_VIEW (bsp->view)->edit_button, + GIMP_IS_BRUSH_GENERATED (brush)); + if (bsp->callback_name) brush_select_change_callbacks (bsp, FALSE); } diff --git a/app/gui/commands.c b/app/gui/commands.c index f0241e8a95..507ab9b090 100644 --- a/app/gui/commands.c +++ b/app/gui/commands.c @@ -83,7 +83,6 @@ #include "gimpcontainergridview.h" #include "gimpdatafactory.h" #include "gimpdatafactoryview.h" -#include "gimpdnd.h" #include "gimppreview.h" @@ -1335,108 +1334,38 @@ container_view_scale_callback (GtkAdjustment *adj, gimp_container_view_set_preview_size (view, ROUND (adj->value)); } -static void -drop_viewable_callback (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - GimpContainerView *view; - - view = GIMP_CONTAINER_VIEW (widget); - - gimp_context_set_by_type (view->context, - view->container->children_type, - GIMP_OBJECT (viewable)); -} - static void brushes_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_brush_factory->container); - - 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 patterns_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_pattern_factory->container); - - 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 gradients_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_gradient_factory->container); - - 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 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_factory->container); - - 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) { - 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, image_context); } @@ -1585,15 +1514,6 @@ container_multi_view_new (gboolean list, 5, 5); } - gimp_gtk_drag_dest_set_by_type (view, - GTK_DEST_DEFAULT_ALL, - container->children_type, - GDK_ACTION_COPY); - gimp_dnd_viewable_dest_set (GTK_WIDGET (view), - GIMP_CONTAINER_VIEW (view)->container->children_type, - drop_viewable_callback, - NULL); - dialog = gimp_dialog_new (title, "test", gimp_standard_help_func, NULL, @@ -1772,7 +1692,7 @@ dialogs_test_gradient_container_list_view_cmd_callback (GtkWidget *widget, data_factory_view_new (GIMP_VIEW_TYPE_LIST, "Gradient List", global_gradient_factory, - gradient_editor_set_gradient, + NULL, gimp_context_get_user (), 24); } @@ -1820,7 +1740,7 @@ dialogs_test_gradient_container_grid_view_cmd_callback (GtkWidget *widget, data_factory_view_new (GIMP_VIEW_TYPE_GRID, "Gradient Grid", global_gradient_factory, - gradient_editor_set_gradient, + NULL, gimp_context_get_user (), 24); } diff --git a/app/gui/gradient-editor.c b/app/gui/gradient-editor.c index 7733e8e803..c35c59e5fb 100644 --- a/app/gui/gradient-editor.c +++ b/app/gui/gradient-editor.c @@ -2933,7 +2933,8 @@ cpopup_adjust_blending_menu (GradientEditor *gradient_editor) for (i = 0; i < num_items; i++) gtk_signal_handler_block_by_data - (GTK_OBJECT (gradient_editor->control_blending_items[i]), (gpointer) i); + (GTK_OBJECT (gradient_editor->control_blending_items[i]), + gradient_editor); /* Set state */ if (equal) @@ -2949,7 +2950,8 @@ cpopup_adjust_blending_menu (GradientEditor *gradient_editor) /* Unblock signals */ for (i = 0; i < num_items; i++) - gtk_signal_handler_unblock_by_data (GTK_OBJECT (gradient_editor->control_blending_items[i]), (gpointer) i); + gtk_signal_handler_unblock_by_data (GTK_OBJECT (gradient_editor->control_blending_items[i]), + gradient_editor); } static void @@ -2968,7 +2970,8 @@ cpopup_adjust_coloring_menu (GradientEditor *gradient_editor) coloring = (int) gradient_editor->control_sel_l->color; for (i = 0; i < num_items; i++) - gtk_signal_handler_block_by_data (GTK_OBJECT (gradient_editor->control_coloring_items[i]), (gpointer) i); + gtk_signal_handler_block_by_data (GTK_OBJECT (gradient_editor->control_coloring_items[i]), + gradient_editor); /* Set state */ if (equal) @@ -2984,7 +2987,8 @@ cpopup_adjust_coloring_menu (GradientEditor *gradient_editor) /* Unblock signals */ for (i = 0; i < num_items; i++) - gtk_signal_handler_unblock_by_data (GTK_OBJECT (gradient_editor->control_coloring_items[i]), (gpointer) i); + gtk_signal_handler_unblock_by_data (GTK_OBJECT (gradient_editor->control_coloring_items[i]), + gradient_editor); } static void diff --git a/app/gui/gradient-select.c b/app/gui/gradient-select.c index d3325bafcb..ae0e1c3d9b 100644 --- a/app/gui/gradient-select.c +++ b/app/gui/gradient-select.c @@ -34,7 +34,6 @@ #include "gimpdatafactoryview.h" #include "gimpcontext.h" #include "gimpdatafactory.h" -#include "gimpdnd.h" #include "gimpgradient.h" #include "gradient_editor.h" #include "gradient_select.h" @@ -47,9 +46,6 @@ static void gradient_select_change_callbacks (GradientSelect *gsp, gboolean closing); -static void gradient_select_drop_gradient (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); static void gradient_select_gradient_changed (GimpContext *context, GimpGradient *gradient, GradientSelect *gsp); @@ -62,10 +58,11 @@ static void gradient_select_edit_gradient (GimpData *data); GSList *gradient_active_dialogs = NULL; /* the main gradient selection dialog */ -GradientSelect *gradient_select_dialog = NULL; +GradientSelect *gradient_select_dialog = NULL; -/* gradient editor dialog */ -static GradientEditor *gradient_editor_dialog; + +/* the main gradient editor dialog */ +static GradientEditor *gradient_editor_dialog = NULL; /* public functions */ @@ -179,15 +176,6 @@ gradient_select_new (gchar *title, gtk_box_pack_start (GTK_BOX (vbox), gsp->view, TRUE, TRUE, 0); gtk_widget_show (gsp->view); - gimp_gtk_drag_dest_set_by_type (gsp->view, - GTK_DEST_DEFAULT_ALL, - GIMP_TYPE_GRADIENT, - GDK_ACTION_COPY); - gimp_dnd_viewable_dest_set (GTK_WIDGET (gsp->view), - GIMP_TYPE_GRADIENT, - gradient_select_drop_gradient, - gsp); - gtk_widget_show (vbox); gtk_widget_show (gsp->shell); @@ -322,18 +310,6 @@ gradient_select_dialogs_check (void) } } -static void -gradient_select_drop_gradient (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - GradientSelect *gsp; - - gsp = (GradientSelect *) data; - - gimp_context_set_gradient (gsp->context, GIMP_GRADIENT (viewable)); -} - static void gradient_select_gradient_changed (GimpContext *context, GimpGradient *gradient, diff --git a/app/gui/gradient-select.h b/app/gui/gradient-select.h index fbde8d068c..70ec335513 100644 --- a/app/gui/gradient-select.h +++ b/app/gui/gradient-select.h @@ -37,7 +37,7 @@ struct _GradientSelect }; -/* list of active dialogs */ +/* list of active dialogs */ extern GSList *gradient_active_dialogs; /* the main gradient selection dialog */ diff --git a/app/gui/help-commands.c b/app/gui/help-commands.c index f0241e8a95..507ab9b090 100644 --- a/app/gui/help-commands.c +++ b/app/gui/help-commands.c @@ -83,7 +83,6 @@ #include "gimpcontainergridview.h" #include "gimpdatafactory.h" #include "gimpdatafactoryview.h" -#include "gimpdnd.h" #include "gimppreview.h" @@ -1335,108 +1334,38 @@ container_view_scale_callback (GtkAdjustment *adj, gimp_container_view_set_preview_size (view, ROUND (adj->value)); } -static void -drop_viewable_callback (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - GimpContainerView *view; - - view = GIMP_CONTAINER_VIEW (widget); - - gimp_context_set_by_type (view->context, - view->container->children_type, - GIMP_OBJECT (viewable)); -} - static void brushes_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_brush_factory->container); - - 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 patterns_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_pattern_factory->container); - - 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 gradients_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_gradient_factory->container); - - 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 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_factory->container); - - 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) { - 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, image_context); } @@ -1585,15 +1514,6 @@ container_multi_view_new (gboolean list, 5, 5); } - gimp_gtk_drag_dest_set_by_type (view, - GTK_DEST_DEFAULT_ALL, - container->children_type, - GDK_ACTION_COPY); - gimp_dnd_viewable_dest_set (GTK_WIDGET (view), - GIMP_CONTAINER_VIEW (view)->container->children_type, - drop_viewable_callback, - NULL); - dialog = gimp_dialog_new (title, "test", gimp_standard_help_func, NULL, @@ -1772,7 +1692,7 @@ dialogs_test_gradient_container_list_view_cmd_callback (GtkWidget *widget, data_factory_view_new (GIMP_VIEW_TYPE_LIST, "Gradient List", global_gradient_factory, - gradient_editor_set_gradient, + NULL, gimp_context_get_user (), 24); } @@ -1820,7 +1740,7 @@ dialogs_test_gradient_container_grid_view_cmd_callback (GtkWidget *widget, data_factory_view_new (GIMP_VIEW_TYPE_GRID, "Gradient Grid", global_gradient_factory, - gradient_editor_set_gradient, + NULL, gimp_context_get_user (), 24); } diff --git a/app/gui/palette-editor.c b/app/gui/palette-editor.c index 9242fbe979..bcaf5e3431 100644 --- a/app/gui/palette-editor.c +++ b/app/gui/palette-editor.c @@ -30,11 +30,14 @@ #include "context_manager.h" #include "dialog_handler.h" #include "gimage.h" +#include "gimpcontainerlistview.h" #include "gimpcontext.h" #include "gimpdatafactory.h" +#include "gimpdatafactoryview.h" #include "gimpdatalist.h" #include "gimpdnd.h" #include "gimppalette.h" +#include "gimppreview.h" #include "gimprc.h" #include "palette.h" #include "palette_import.h" @@ -56,11 +59,12 @@ #define COLUMNS 16 #define ROWS 11 -#define PREVIEW_WIDTH ((ENTRY_WIDTH * COLUMNS) + (SPACING * (COLUMNS + 1))) -#define PREVIEW_HEIGHT ((ENTRY_HEIGHT * ROWS) + (SPACING * (ROWS + 1))) +#define PREVIEW_WIDTH ((ENTRY_WIDTH * COLUMNS) + (SPACING * (COLUMNS + 1))) +#define PREVIEW_HEIGHT ((ENTRY_HEIGHT * ROWS) + (SPACING * (ROWS + 1))) -#define PALETTE_EVENT_MASK GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | \ - GDK_ENTER_NOTIFY_MASK +#define PALETTE_EVENT_MASK (GDK_EXPOSURE_MASK | \ + GDK_BUTTON_PRESS_MASK | \ + GDK_ENTER_NOTIFY_MASK) typedef struct _PaletteDialog PaletteDialog; @@ -72,7 +76,10 @@ struct _PaletteDialog GtkWidget *color_area; GtkWidget *scrolled_window; GtkWidget *color_name; - GtkWidget *clist; + + GtkWidget *view; + + GimpContext *context; GtkWidget *popup_menu; GtkWidget *delete_menu_item; @@ -81,11 +88,9 @@ struct _PaletteDialog ColorNotebook *color_notebook; gboolean color_notebook_active; - GimpPalette *palette; GimpPaletteEntry *color; GimpPaletteEntry *dnd_color; - GdkGC *gc; guint entry_sig_id; gfloat zoom_factor; /* range from 0.1 to 4.0 */ gint col_width; @@ -93,23 +98,70 @@ struct _PaletteDialog gint columns; gboolean freeze_update; gboolean columns_valid; + + GQuark invalidate_preview_handler_id; }; /* local function prototypes */ -static void palette_dialog_draw_entries (PaletteDialog *palette, - gint row_start, - gint column_highlight); -static void palette_dialog_redraw (PaletteDialog *palette); -static void palette_dialog_scroll_top_left (PaletteDialog *palette); +static PaletteDialog * palette_dialog_new (gboolean editor); -static PaletteDialog * palette_dialog_new (gboolean editor); +static void palette_dialog_create_popup_menu (PaletteDialog *palette_dialog); +static void palette_dialog_new_entry_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_edit_entry_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_delete_entry_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_color_notebook_callback (ColorNotebook *color_notebook, + const GimpRGB *color, + ColorNotebookState state, + gpointer data); + +static gint palette_dialog_eventbox_button_press (GtkWidget *widget, + GdkEventButton *bevent, + PaletteDialog *palette_dialog); +static gint palette_dialog_color_area_events (GtkWidget *widget, + GdkEvent *event, + PaletteDialog *palette_dialog); +static void palette_dialog_draw_entries (PaletteDialog *palette, + gint row_start, + gint column_highlight); +static void palette_dialog_redraw (PaletteDialog *palette); +static void palette_dialog_scroll_top_left (PaletteDialog *palette); + +static void palette_dialog_color_name_changed (GtkWidget *widget, + gpointer data); +static void palette_dialog_zoomin_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_zoomout_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_redraw_zoom (PaletteDialog *palette_dialog); +static void palette_dialog_import_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_merge_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_do_merge_callback (GtkWidget *widget, + gchar *palette_name, + gpointer data); +static void palette_dialog_close_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_palette_changed (GimpContext *context, + GimpPalette *palette, + gpointer data); +static void palette_dialog_drag_color (GtkWidget *widget, + GimpRGB *color, + gpointer data); +static void palette_dialog_drop_color (GtkWidget *widget, + const GimpRGB *color, + gpointer data); +static void palette_dialog_invalidate_preview (GimpPalette *palette, + PaletteDialog *palette_dialog); +static void palette_dialog_edit_palette (GimpData *data); -PaletteDialog *top_level_edit_palette = NULL; -PaletteDialog *top_level_palette = NULL; - -static GimpPalette *default_palette_entries = NULL; +PaletteDialog *top_level_edit_palette = NULL; +PaletteDialog *top_level_palette = NULL; /* dnd stuff */ @@ -128,7 +180,7 @@ palette_dialog_create (void) { if (top_level_palette == NULL) { - top_level_palette = palette_dialog_new (TRUE); + top_level_palette = palette_dialog_new (FALSE); session_set_window_geometry (top_level_palette->shell, &palette_session_info, TRUE); dialog_register (top_level_palette->shell); @@ -155,10 +207,15 @@ palette_dialog_free (void) { palette_import_dialog_destroy (); - gdk_gc_destroy (top_level_edit_palette->gc); - if (top_level_edit_palette->color_notebook) - color_notebook_free (top_level_edit_palette->color_notebook); + color_notebook_free (top_level_edit_palette->color_notebook); + + gtk_signal_disconnect_by_func (GTK_OBJECT (top_level_edit_palette->context), + palette_dialog_palette_changed, + top_level_edit_palette); + + gimp_container_remove_handler (global_palette_factory->container, + top_level_edit_palette->invalidate_preview_handler_id); g_free (top_level_edit_palette); top_level_edit_palette = NULL; @@ -166,275 +223,24 @@ palette_dialog_free (void) if (top_level_palette) { - gdk_gc_destroy (top_level_palette->gc); session_get_window_info (top_level_palette->shell, &palette_session_info); if (top_level_palette->color_notebook) color_notebook_free (top_level_palette->color_notebook); + gtk_signal_disconnect_by_func (GTK_OBJECT (top_level_palette->context), + palette_dialog_palette_changed, + top_level_palette); + + gimp_container_remove_handler (global_palette_factory->container, + top_level_palette->invalidate_preview_handler_id); + g_free (top_level_palette); top_level_palette = NULL; } } -/* general palette clist update functions **********************************/ - -void -palette_clist_init (GtkWidget *clist, - GtkWidget *shell, - GdkGC *gc) -{ - GimpPalette *palette = NULL; - GList *list; - gint pos; - - for (list = GIMP_LIST (global_palette_factory->container)->list, pos = 0; - list; - list = g_list_next (list), pos++) - { - palette = (GimpPalette *) list->data; - - palette_clist_insert (clist, shell, gc, palette, pos); - } -} - -void -palette_clist_insert (GtkWidget *clist, - GtkWidget *shell, - GdkGC *gc, - GimpPalette *palette, - gint pos) -{ - gchar *string[3]; - - string[0] = NULL; - string[1] = g_strdup_printf ("%d", palette->n_colors); - string[2] = GIMP_OBJECT (palette)->name; - - gtk_clist_insert (GTK_CLIST (clist), pos, string); - - g_free (string[1]); - - if (palette->pixmap == NULL) - { - palette->pixmap = gdk_pixmap_new (shell->window, - SM_PREVIEW_WIDTH, - SM_PREVIEW_HEIGHT, - gtk_widget_get_visual (shell)->depth); - gimp_palette_update_preview (palette, gc); - } - - gtk_clist_set_pixmap (GTK_CLIST (clist), pos, 0, palette->pixmap, NULL); - gtk_clist_set_row_data (GTK_CLIST (clist), pos, (gpointer) palette); -} - -/* palette dialog clist update functions ***********************************/ - -static void -palette_dialog_clist_insert (PaletteDialog *palette_dialog, - GimpPalette *palette) -{ - gint pos; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (palette)); - - gtk_clist_freeze (GTK_CLIST (palette_dialog->clist)); - - palette_clist_insert (palette_dialog->clist, - palette_dialog->shell, - palette_dialog->gc, - palette, - pos); - - gtk_clist_thaw (GTK_CLIST (palette_dialog->clist)); -} - -static void -palette_dialog_clist_set_text (PaletteDialog *palette_dialog, - GimpPalette *palette) -{ - gchar *num_buf; - gint pos; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (palette)); - - num_buf = g_strdup_printf ("%d", palette->n_colors);; - - gtk_clist_set_text (GTK_CLIST (palette_dialog->clist), pos, 1, num_buf); - - g_free (num_buf); -} - -static void -palette_dialog_clist_refresh (PaletteDialog *palette_dialog) -{ - gtk_clist_freeze (GTK_CLIST (palette_dialog->clist)); - - gtk_clist_clear (GTK_CLIST (palette_dialog->clist)); - palette_clist_init (palette_dialog->clist, - palette_dialog->shell, - palette_dialog->gc); - - gtk_clist_thaw (GTK_CLIST (palette_dialog->clist)); - - palette_dialog->palette = (GimpPalette *) - gimp_container_get_child_by_index (global_palette_factory->container, 0); -} - -static void -palette_dialog_clist_scroll_to_current (PaletteDialog *palette_dialog) -{ - gint pos; - - if (! (palette_dialog && palette_dialog->palette)) - return; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (palette_dialog->palette)); - - gtk_clist_unselect_all (GTK_CLIST (palette_dialog->clist)); - gtk_clist_select_row (GTK_CLIST (palette_dialog->clist), pos, -1); - gtk_clist_moveto (GTK_CLIST (palette_dialog->clist), pos, 0, 0.0, 0.0); -} - -/* update functions for all palette dialogs ********************************/ - -void -palette_insert_all (GimpPalette *palette) -{ - PaletteDialog *palette_dialog; - - if ((palette_dialog = top_level_palette)) - { - palette_dialog_clist_insert (palette_dialog, palette); - - if (palette_dialog->palette == NULL) - { - palette_dialog->palette = palette; - palette_dialog_redraw (palette_dialog); - } - } - - if ((palette_dialog = top_level_edit_palette)) - { - palette_dialog_clist_insert (palette_dialog, palette); - - palette_dialog->palette = palette; - palette_dialog_redraw (palette_dialog); - - palette_dialog_clist_scroll_to_current (palette_dialog); - } - - /* Update other selectors on screen */ - palette_select_clist_insert_all (palette); -} - -static void -palette_update_all (GimpPalette *palette) -{ - PaletteDialog *palette_dialog; - GdkGC *gc = NULL; - - if (top_level_palette) - gc = top_level_palette->gc; - else if (top_level_edit_palette) - gc = top_level_edit_palette->gc; - - if (gc) - gimp_palette_update_preview (palette, gc); - - if ((palette_dialog = top_level_palette)) - { - if (palette_dialog->palette == palette) - { - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - } - palette_dialog_clist_set_text (palette_dialog, palette); - } - - if ((palette_dialog = top_level_edit_palette)) - { - if (palette_dialog->palette == palette) - { - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - palette_dialog_clist_scroll_to_current (palette_dialog); - } - palette_dialog_clist_set_text (palette_dialog, palette); - } - - /* Update other selectors on screen */ - palette_select_set_text_all (palette); -} - -static void -palette_draw_all (GimpPalette *palette, - GimpPaletteEntry *entry) -{ - PaletteDialog *palette_dialog; - GdkGC *gc = NULL; - - if (top_level_palette) - gc = top_level_palette->gc; - else if (top_level_edit_palette) - gc = top_level_edit_palette->gc; - - if (gc) - gimp_palette_update_preview (palette, gc); - - if ((palette_dialog = top_level_palette)) - { - if (palette_dialog->palette == palette) - { - palette_dialog_draw_entries (palette_dialog, - entry->position / palette_dialog->columns, - entry->position % palette_dialog->columns); - } - } - - if ((palette_dialog = top_level_edit_palette)) - { - if (palette_dialog->palette == palette) - { - palette_dialog_draw_entries (palette_dialog, - entry->position / palette_dialog->columns, - entry->position % palette_dialog->columns); - } - } -} - -static void -palette_refresh_all (void) -{ - PaletteDialog *palette_dialog; - - default_palette_entries = NULL; - - gimp_data_factory_data_init (global_palette_factory, FALSE); - - if ((palette_dialog = top_level_palette)) - { - palette_dialog_clist_refresh (palette_dialog); - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - palette_dialog_clist_scroll_to_current (palette_dialog); - } - - if ((palette_dialog = top_level_edit_palette)) - { - palette_dialog_clist_refresh (palette_dialog); - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - palette_dialog_clist_scroll_to_current (palette_dialog); - } - - /* Update other selectors on screen */ - palette_select_refresh_all (); -} /* called from color_picker.h *********************************************/ @@ -444,7 +250,8 @@ palette_set_active_color (gint r, gint b, gint state) { - GimpRGB color; + GimpPalette *palette; + GimpRGB color; gimp_rgba_set_uchar (&color, (guchar) r, @@ -452,29 +259,30 @@ palette_set_active_color (gint r, (guchar) b, 255); - if (top_level_edit_palette && top_level_edit_palette->palette) + if (top_level_edit_palette) { - switch (state) - { - case COLOR_NEW: - top_level_edit_palette->color = - gimp_palette_add_entry (top_level_edit_palette->palette, - NULL, - &color); + palette = gimp_context_get_palette (top_level_edit_palette->context); - palette_update_all (top_level_edit_palette->palette); - break; + if (palette) + { + switch (state) + { + case COLOR_NEW: + top_level_edit_palette->color = gimp_palette_add_entry (palette, + NULL, + &color); + break; - case COLOR_UPDATE_NEW: - top_level_edit_palette->color->color = color; + case COLOR_UPDATE_NEW: + top_level_edit_palette->color->color = color; - palette_draw_all (top_level_edit_palette->palette, - top_level_edit_palette->color); - break; + gimp_data_dirty (GIMP_DATA (palette)); + break; - default: - break; - } + default: + break; + } + } } if (active_color == FOREGROUND) @@ -485,22 +293,12 @@ palette_set_active_color (gint r, /* called from palette_select.c ********************************************/ -void -palette_select_palette_init (void) -{ - if (top_level_edit_palette == NULL) - { - top_level_edit_palette = palette_dialog_new (FALSE); - dialog_register (top_level_edit_palette->shell); - } -} - void palette_create_edit (GimpPalette *palette) { if (top_level_edit_palette == NULL) { - top_level_edit_palette = palette_dialog_new (FALSE); + top_level_edit_palette = palette_dialog_new (TRUE); dialog_register (top_level_edit_palette->shell); gtk_widget_show (top_level_edit_palette->shell); @@ -509,142 +307,259 @@ palette_create_edit (GimpPalette *palette) else { if (! GTK_WIDGET_VISIBLE (top_level_edit_palette->shell)) - { - gtk_widget_show (top_level_edit_palette->shell); - palette_dialog_draw_entries (top_level_edit_palette, -1, -1); - } + gtk_widget_show (top_level_edit_palette->shell); else - { - gdk_window_raise (top_level_edit_palette->shell->window); - } + gdk_window_raise (top_level_edit_palette->shell->window); } - if (palette != NULL) - { - top_level_edit_palette->palette = palette; - palette_dialog_clist_scroll_to_current (top_level_edit_palette); - } + gimp_context_set_palette (top_level_edit_palette->context, palette); } -static void -palette_select_callback (ColorNotebook *color_notebook, - const GimpRGB *color, - ColorNotebookState state, - gpointer data) + +/* private functions */ + +/* the palette & palette edit dialog constructor ***************************/ + +PaletteDialog * +palette_dialog_new (gboolean editor) { PaletteDialog *palette_dialog; - - palette_dialog = data; + GtkWidget *hbox; + GtkWidget *hbox2; + GtkWidget *vbox; + GtkWidget *scrolledwindow; + GtkWidget *palette_region; + GtkWidget *entry; + GtkWidget *eventbox; + GtkWidget *alignment; + GtkWidget *frame; + GtkWidget *button; - if (! (palette_dialog && palette_dialog->palette)) - return; + palette_dialog = g_new0 (PaletteDialog, 1); - switch (state) + if (! editor) + palette_dialog->context = gimp_context_get_user (); + else + palette_dialog->context = gimp_context_new (NULL, NULL); + + palette_dialog->zoom_factor = 1.0; + palette_dialog->columns = COLUMNS; + palette_dialog->columns_valid = TRUE; + palette_dialog->freeze_update = FALSE; + + if (editor) { - case COLOR_NOTEBOOK_UPDATE: - break; + palette_dialog->shell = + gimp_dialog_new (_("Color Palette Edit"), "color_palette_edit", + gimp_standard_help_func, + "dialogs/palette_editor/palette_editor.html", + GTK_WIN_POS_NONE, + FALSE, TRUE, FALSE, - case COLOR_NOTEBOOK_OK: - if (palette_dialog->color) - { - palette_dialog->color->color = *color; + "_delete_event_", palette_dialog_close_callback, + palette_dialog, NULL, NULL, TRUE, TRUE, - /* Update either foreground or background colors */ - if (active_color == FOREGROUND) - gimp_context_set_foreground (gimp_context_get_user (), color); - else if (active_color == BACKGROUND) - gimp_context_set_background (gimp_context_get_user (), color); - - palette_draw_all (palette_dialog->palette, palette_dialog->color); - } - - /* Fallthrough */ - case COLOR_NOTEBOOK_CANCEL: - if (palette_dialog->color_notebook_active) - { - color_notebook_hide (palette_dialog->color_notebook); - palette_dialog->color_notebook_active = FALSE; - } - } -} - -/* the palette dialog popup menu & callbacks *******************************/ - -static void -palette_dialog_new_entry_callback (GtkWidget *widget, - gpointer data) -{ - PaletteDialog *palette_dialog; - GimpRGB color; - - palette_dialog = (PaletteDialog *) data; - - if (! (palette_dialog && palette_dialog->palette)) - return; - - if (active_color == FOREGROUND) - gimp_context_get_foreground (gimp_context_get_user (), &color); - else if (active_color == BACKGROUND) - gimp_context_get_background (gimp_context_get_user (), &color); - - palette_dialog->color = gimp_palette_add_entry (palette_dialog->palette, - NULL, - &color); - - palette_update_all (palette_dialog->palette); -} - -static void -palette_dialog_edit_entry_callback (GtkWidget *widget, - gpointer data) -{ - PaletteDialog *palette_dialog; - - palette_dialog = (PaletteDialog *) data; - - if (! (palette_dialog && palette_dialog->palette && palette_dialog->color)) - return; - - if (! palette_dialog->color_notebook) - { - palette_dialog->color_notebook = - color_notebook_new (_("Edit Palette Color"), - (const GimpRGB *) &palette_dialog->color->color, - palette_select_callback, - palette_dialog, - FALSE, - FALSE); - palette_dialog->color_notebook_active = TRUE; + NULL); } else { - if (! palette_dialog->color_notebook_active) - { - color_notebook_show (palette_dialog->color_notebook); - palette_dialog->color_notebook_active = TRUE; - } + palette_dialog->shell = + gimp_dialog_new (_("Color Palette"), "color_palette", + gimp_standard_help_func, + "dialogs/palette_selection.html", + GTK_WIN_POS_NONE, + FALSE, TRUE, FALSE, - color_notebook_set_color (palette_dialog->color_notebook, - &palette_dialog->color->color); + "_delete_event_", palette_dialog_close_callback, + palette_dialog, NULL, NULL, TRUE, TRUE, + + NULL); + } + + gtk_widget_hide (GTK_WIDGET (g_list_nth_data (gtk_container_children (GTK_CONTAINER (GTK_DIALOG (palette_dialog->shell)->vbox)), 0))); + + gtk_widget_hide (GTK_DIALOG (palette_dialog->shell)->action_area); + + /* The main container widget */ + if (! editor) + { + hbox = gtk_notebook_new (); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 1); } + else + { + hbox = gtk_hbox_new (FALSE, 4); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 4); + } + + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (palette_dialog->shell)->vbox), + hbox); + gtk_widget_show (hbox); + + vbox = gtk_vbox_new (FALSE, 2); + gtk_widget_show (vbox); + + palette_dialog->scrolled_window = + scrolledwindow = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_ALWAYS); + gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0); + gtk_widget_show (scrolledwindow); + + eventbox = gtk_event_box_new (); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledwindow), + eventbox); + gtk_signal_connect (GTK_OBJECT (eventbox), "button_press_event", + GTK_SIGNAL_FUNC (palette_dialog_eventbox_button_press), + palette_dialog); + gtk_widget_show (eventbox); + + alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); + gtk_container_add (GTK_CONTAINER (eventbox), alignment); + gtk_widget_show (alignment); + + palette_dialog->color_area = palette_region = + gtk_preview_new (GTK_PREVIEW_COLOR); + gtk_preview_set_dither (GTK_PREVIEW (palette_dialog->color_area), + GDK_RGB_DITHER_MAX); + gtk_preview_size (GTK_PREVIEW (palette_region), PREVIEW_WIDTH, PREVIEW_HEIGHT); + + gtk_widget_set_events (palette_region, PALETTE_EVENT_MASK); + gtk_signal_connect (GTK_OBJECT (palette_dialog->color_area), "event", + GTK_SIGNAL_FUNC (palette_dialog_color_area_events), + palette_dialog); + + gtk_container_add (GTK_CONTAINER (alignment), palette_region); + gtk_widget_show (palette_region); + + /* dnd stuff */ + gtk_drag_source_set (palette_region, + GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, + color_palette_target_table, n_color_palette_targets, + GDK_ACTION_COPY | GDK_ACTION_MOVE); + gimp_dnd_color_source_set (palette_region, palette_dialog_drag_color, + palette_dialog); + + gtk_drag_dest_set (alignment, + GTK_DEST_DEFAULT_HIGHLIGHT | + GTK_DEST_DEFAULT_MOTION | + GTK_DEST_DEFAULT_DROP, + color_palette_target_table, n_color_palette_targets, + GDK_ACTION_COPY); + gimp_dnd_color_dest_set (alignment, palette_dialog_drop_color, palette_dialog); + + /* The color name entry */ + hbox2 = gtk_hbox_new (FALSE, 2); + gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0); + gtk_widget_show (hbox2); + + entry = palette_dialog->color_name = gtk_entry_new (); + gtk_widget_show (entry); + gtk_box_pack_start (GTK_BOX (hbox2), entry, TRUE, TRUE, 0); + gtk_entry_set_text (GTK_ENTRY (entry), _("Undefined")); + gtk_widget_set_sensitive (entry, FALSE); + palette_dialog->entry_sig_id = + gtk_signal_connect (GTK_OBJECT (entry), "changed", + GTK_SIGNAL_FUNC (palette_dialog_color_name_changed), + palette_dialog); + + /* + and - buttons */ + button = gimp_pixmap_button_new (zoom_in_xpm, NULL); + gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (palette_dialog_zoomin_callback), + palette_dialog); + gtk_widget_show (button); + + button = gimp_pixmap_button_new (zoom_out_xpm, NULL); + gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (palette_dialog_zoomout_callback), + palette_dialog); + gtk_widget_show (button); + + /* The Palette List */ + palette_dialog->view = + gimp_data_factory_view_new (GIMP_VIEW_TYPE_LIST, + global_palette_factory, + editor ? NULL : palette_dialog_edit_palette, + palette_dialog->context, + 64, /* FIXME: SM_PREVIEW_WIDTH */ + 3, /* FIXME: STD_PALETTE_COLUMNS */ + 3); /* FIXME: STD_PALETTE_ROWS */ + + if (! editor) + { + gtk_notebook_append_page (GTK_NOTEBOOK (hbox), vbox, + gtk_label_new (_("Palette"))); + gtk_notebook_append_page (GTK_NOTEBOOK (hbox), palette_dialog->view, + gtk_label_new (_("Select"))); + } + else + { + gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox), palette_dialog->view, TRUE, TRUE, 0); + } + + if (editor) + gtk_list_set_selection_mode (GTK_LIST (GIMP_CONTAINER_LIST_VIEW (GIMP_DATA_FACTORY_VIEW (palette_dialog->view)->view)->gtk_list), + GTK_SELECTION_EXTENDED); + + gtk_signal_connect (GTK_OBJECT (palette_dialog->context), "palette_changed", + GTK_SIGNAL_FUNC (palette_dialog_palette_changed), + palette_dialog); + + palette_dialog->invalidate_preview_handler_id = + gimp_container_add_handler (global_palette_factory->container, + "invalidate_preview", + GTK_SIGNAL_FUNC (palette_dialog_invalidate_preview), + palette_dialog); + + gtk_widget_show (palette_dialog->view); + + if (editor) + { + frame = gtk_frame_new (_("Palette Ops")); + gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0); + gtk_widget_show (frame); + + vbox = gtk_vbox_new (FALSE, 2); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); + gtk_container_add (GTK_CONTAINER (frame), vbox); + gtk_widget_show (vbox); + + button = gtk_button_new_with_label (_("Import")); + GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); + gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (palette_dialog_import_callback), + palette_dialog); + gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); + gimp_help_set_help_data (button, NULL, + "dialogs/palette_editor/import_palette.html"); + gtk_widget_show (button); + + button = gtk_button_new_with_label (_("Merge")); + GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); + gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (palette_dialog_merge_callback), + palette_dialog); + gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); + gimp_help_set_help_data (button, NULL, + "dialogs/palette_editor/merge_palette.html"); + gtk_widget_show (button); + } + + gtk_widget_realize (palette_dialog->shell); + + palette_dialog_create_popup_menu (palette_dialog); + + return palette_dialog; } -static void -palette_dialog_delete_entry_callback (GtkWidget *widget, - gpointer data) -{ - PaletteDialog *palette_dialog; - - palette_dialog = (PaletteDialog *) data; - - if (! (palette_dialog && palette_dialog->palette && palette_dialog->color)) - return; - - gimp_palette_delete_entry (palette_dialog->palette, - palette_dialog->color); - - palette_update_all (palette_dialog->palette); -} +/* the palette dialog popup menu & callbacks *******************************/ static void palette_dialog_create_popup_menu (PaletteDialog *palette_dialog) @@ -681,6 +596,123 @@ palette_dialog_create_popup_menu (PaletteDialog *palette_dialog) palette_dialog->delete_menu_item = menu_item; } +static void +palette_dialog_new_entry_callback (GtkWidget *widget, + gpointer data) +{ + PaletteDialog *palette_dialog; + GimpRGB color; + + palette_dialog = (PaletteDialog *) data; + + if (! (palette_dialog && gimp_context_get_palette (palette_dialog->context))) + return; + + if (active_color == FOREGROUND) + gimp_context_get_foreground (gimp_context_get_user (), &color); + else if (active_color == BACKGROUND) + gimp_context_get_background (gimp_context_get_user (), &color); + + palette_dialog->color = + gimp_palette_add_entry (gimp_context_get_palette (palette_dialog->context), + NULL, + &color); +} + +static void +palette_dialog_edit_entry_callback (GtkWidget *widget, + gpointer data) +{ + PaletteDialog *palette_dialog; + + palette_dialog = (PaletteDialog *) data; + + if (! (palette_dialog && gimp_context_get_palette (palette_dialog->context) + && palette_dialog->color)) + return; + + if (! palette_dialog->color_notebook) + { + palette_dialog->color_notebook = + color_notebook_new (_("Edit Palette Color"), + (const GimpRGB *) &palette_dialog->color->color, + palette_dialog_color_notebook_callback, + palette_dialog, + FALSE, + FALSE); + palette_dialog->color_notebook_active = TRUE; + } + else + { + if (! palette_dialog->color_notebook_active) + { + color_notebook_show (palette_dialog->color_notebook); + palette_dialog->color_notebook_active = TRUE; + } + + color_notebook_set_color (palette_dialog->color_notebook, + &palette_dialog->color->color); + } +} + +static void +palette_dialog_delete_entry_callback (GtkWidget *widget, + gpointer data) +{ + PaletteDialog *palette_dialog; + + palette_dialog = (PaletteDialog *) data; + + if (! (palette_dialog && gimp_context_get_palette (palette_dialog->context) && + palette_dialog->color)) + return; + + gimp_palette_delete_entry (gimp_context_get_palette (palette_dialog->context), + palette_dialog->color); +} + +static void +palette_dialog_color_notebook_callback (ColorNotebook *color_notebook, + const GimpRGB *color, + ColorNotebookState state, + gpointer data) +{ + PaletteDialog *palette_dialog; + GimpPalette *palette; + + palette_dialog = data; + + palette = gimp_context_get_palette (palette_dialog->context); + + switch (state) + { + case COLOR_NOTEBOOK_UPDATE: + break; + + case COLOR_NOTEBOOK_OK: + if (palette_dialog->color) + { + palette_dialog->color->color = *color; + + /* Update either foreground or background colors */ + if (active_color == FOREGROUND) + gimp_context_set_foreground (gimp_context_get_user (), color); + else if (active_color == BACKGROUND) + gimp_context_set_background (gimp_context_get_user (), color); + + gimp_data_dirty (GIMP_DATA (palette)); + } + + /* Fallthrough */ + case COLOR_NOTEBOOK_CANCEL: + if (palette_dialog->color_notebook_active) + { + color_notebook_hide (palette_dialog->color_notebook); + palette_dialog->color_notebook_active = FALSE; + } + } +} + /* the color area event callbacks ******************************************/ static gint @@ -733,8 +765,8 @@ palette_dialog_color_area_events (GtkWidget *widget, row = (bevent->y - 1) / entry_height; pos = row * palette_dialog->columns + col; - if (palette_dialog->palette) - list = g_list_nth (palette_dialog->palette->colors, pos); + if (gimp_context_get_palette (palette_dialog->context)) + list = g_list_nth (gimp_context_get_palette (palette_dialog->context)->colors, pos); else list = NULL; @@ -744,7 +776,7 @@ palette_dialog_color_area_events (GtkWidget *widget, palette_dialog->dnd_color = NULL; if ((bevent->button == 1 || bevent->button == 3) && - palette_dialog->palette) + gimp_context_get_palette (palette_dialog->context)) { if (list) { @@ -1001,7 +1033,7 @@ palette_dialog_draw_entries (PaletteDialog *palette_dialog, gint entry_height; gint index, y; - if (! (palette_dialog && palette_dialog->palette)) + if (! (palette_dialog && gimp_context_get_palette (palette_dialog->context))) return; width = palette_dialog->color_area->requisition.width; @@ -1019,13 +1051,13 @@ palette_dialog_draw_entries (PaletteDialog *palette_dialog, if (row_start < 0) { y = 0; - list = palette_dialog->palette->colors; + list = gimp_context_get_palette (palette_dialog->context)->colors; column_highlight = -1; } else { y = (entry_height + SPACING) * row_start; - list = g_list_nth (palette_dialog->palette->colors, + list = g_list_nth (gimp_context_get_palette (palette_dialog->context)->colors, row_start * palette_dialog->columns); } @@ -1103,7 +1135,7 @@ palette_dialog_redraw (PaletteDialog *palette_dialog) gint preview_width; guint width; - if (! palette_dialog->palette) + if (! gimp_context_get_palette (palette_dialog->context)) return; width = palette_dialog->color_area->parent->parent->parent->allocation.width; @@ -1116,7 +1148,7 @@ palette_dialog_redraw (PaletteDialog *palette_dialog) if (palette_dialog->col_width < 0) palette_dialog->col_width = 0; palette_dialog->columns_valid = TRUE; - n_entries = palette_dialog->palette->n_colors; + n_entries = gimp_context_get_palette (palette_dialog->context)->n_colors; nrows = n_entries / palette_dialog->columns; if (n_entries % palette_dialog->columns) nrows += 1; @@ -1137,23 +1169,27 @@ palette_dialog_redraw (PaletteDialog *palette_dialog) gtk_container_add (GTK_CONTAINER (parent), palette_dialog->color_area->parent); gtk_widget_unref (palette_dialog->color_area->parent); - palette_dialog_draw_entries (palette_dialog, -1, -1); + if (palette_dialog->color) + palette_dialog_draw_entries (palette_dialog, + palette_dialog->color->position / palette_dialog->columns, + palette_dialog->color->position % palette_dialog->columns); + else + palette_dialog_draw_entries (palette_dialog, -1, -1); } -/* the palette dialog clist "select_row" callback **************************/ - static void -palette_dialog_list_item_update (GtkWidget *widget, - gint row, - gint column, - GdkEventButton *event, - gpointer data) +palette_dialog_palette_changed (GimpContext *context, + GimpPalette *palette, + gpointer data) { PaletteDialog *palette_dialog; - GimpPalette *palette; palette_dialog = (PaletteDialog *) data; + /* FIXME */ + if (! palette) + return; + if (palette_dialog->color_notebook_active) { color_notebook_hide (palette_dialog->color_notebook); @@ -1164,17 +1200,12 @@ palette_dialog_list_item_update (GtkWidget *widget, color_notebook_free (palette_dialog->color_notebook); palette_dialog->color_notebook = NULL; - palette = - (GimpPalette *) gtk_clist_get_row_data (GTK_CLIST (palette_dialog->clist), - row); - - palette_dialog->palette = palette; palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); + palette_dialog_scroll_top_left (palette_dialog); - /* Stop errors in case no colors are selected */ + /* Stop errors in case no colors are selected */ gtk_signal_handler_block (GTK_OBJECT (palette_dialog->color_name), palette_dialog->entry_sig_id); gtk_entry_set_text (GTK_ENTRY (palette_dialog->color_name), _("Undefined")); @@ -1186,44 +1217,25 @@ palette_dialog_list_item_update (GtkWidget *widget, /* the color name entry callback *******************************************/ static void -palette_dialog_color_name_entry_changed (GtkWidget *widget, - gpointer data) +palette_dialog_color_name_changed (GtkWidget *widget, + gpointer data) { PaletteDialog *palette_dialog; palette_dialog = (PaletteDialog *) data; - g_return_if_fail (palette_dialog->palette != NULL); + g_return_if_fail (gimp_context_get_palette (palette_dialog->context) != NULL); if (palette_dialog->color->name) g_free (palette_dialog->color->name); palette_dialog->color->name = g_strdup (gtk_entry_get_text (GTK_ENTRY (palette_dialog->color_name))); - gimp_data_dirty (GIMP_DATA (palette_dialog->palette)); + gimp_data_dirty (GIMP_DATA (gimp_context_get_palette (palette_dialog->context))); } /* palette zoom functions & callbacks **************************************/ -static void -palette_dialog_redraw_zoom (PaletteDialog *palette_dialog) -{ - if (palette_dialog->zoom_factor > 4.0) - { - palette_dialog->zoom_factor = 4.0; - } - else if (palette_dialog->zoom_factor < 0.1) - { - palette_dialog->zoom_factor = 0.1; - } - - palette_dialog->columns = COLUMNS; - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - - palette_dialog_scroll_top_left (palette_dialog); -} - static void palette_dialog_zoomin_callback (GtkWidget *widget, gpointer data) @@ -1250,101 +1262,27 @@ palette_dialog_zoomout_callback (GtkWidget *widget, palette_dialog_redraw_zoom (palette_dialog); } -/* the palette edit ops callbacks ******************************************/ - static void -palette_dialog_add_entries_callback (GtkWidget *widget, - gchar *palette_name, - gpointer data) +palette_dialog_redraw_zoom (PaletteDialog *palette_dialog) { - GimpPalette *palette; + if (palette_dialog->zoom_factor > 4.0) + { + palette_dialog->zoom_factor = 4.0; + } + else if (palette_dialog->zoom_factor < 0.1) + { + palette_dialog->zoom_factor = 0.1; + } - palette = GIMP_PALETTE (gimp_palette_new (palette_name)); + palette_dialog->columns = COLUMNS; - gimp_container_add (global_palette_factory->container, GIMP_OBJECT (palette)); + palette_dialog->columns_valid = FALSE; + palette_dialog_redraw (palette_dialog); - /* update all dialogs */ - palette_insert_all (palette); + palette_dialog_scroll_top_left (palette_dialog); } -static void -palette_dialog_new_callback (GtkWidget *widget, - gpointer data) -{ - GtkWidget *qbox; - - qbox = gimp_query_string_box (_("New Palette"), - gimp_standard_help_func, - "dialogs/palette_editor/new_palette.html", - _("Enter a name for new palette"), - NULL, - NULL, NULL, - palette_dialog_add_entries_callback, data); - gtk_widget_show (qbox); -} - -static void -palette_dialog_do_delete_callback (GtkWidget *widget, - gboolean delete, - gpointer data) -{ - PaletteDialog *palette_dialog; - GimpPalette *palette; - - palette_dialog = (PaletteDialog *) data; - - gtk_widget_set_sensitive (palette_dialog->shell, TRUE); - - if (! delete) - return; - - if (! (palette_dialog && palette_dialog->palette)) - return; - - palette = palette_dialog->palette; - - if (GIMP_DATA (palette)->filename) - gimp_data_delete_from_disk (GIMP_DATA (palette)); - - gimp_container_remove (global_palette_factory->container, - GIMP_OBJECT (palette)); - - palette_refresh_all (); -} - -static void -palette_dialog_delete_callback (GtkWidget *widget, - gpointer data) -{ - PaletteDialog *palette_dialog; - GtkWidget *dialog; - gchar *str; - - palette_dialog = (PaletteDialog *) data; - - if (! (palette_dialog && palette_dialog->palette)) - return; - - gtk_widget_set_sensitive (palette_dialog->shell, FALSE); - - str = g_strdup_printf (_("Are you sure you want to delete\n" - "\"%s\" from the list and from disk?"), - GIMP_OBJECT (palette_dialog->palette)->name); - - dialog = gimp_query_boolean_box (_("Delete Palette"), - gimp_standard_help_func, - "dialogs/palette_editor/delete_palette.html", - FALSE, - str, - _("Delete"), _("Cancel"), - NULL, NULL, - palette_dialog_do_delete_callback, - palette_dialog); - - g_free (str); - - gtk_widget_show (dialog); -} +/* the palette dialog action callbacks **************************************/ static void palette_dialog_import_callback (GtkWidget *widget, @@ -1353,51 +1291,6 @@ palette_dialog_import_callback (GtkWidget *widget, palette_import_dialog_show (); } -static void -palette_dialog_merge_entries_callback (GtkWidget *widget, - gchar *palette_name, - gpointer data) -{ - PaletteDialog *palette_dialog; - GimpPalette *palette; - GimpPalette *new_palette; - GimpPaletteEntry *entry; - GList *sel_list; - - new_palette = GIMP_PALETTE (gimp_palette_new (palette_name)); - - palette_dialog = (PaletteDialog *) data; - - sel_list = GTK_CLIST (palette_dialog->clist)->selection; - - while (sel_list) - { - gint row; - GList *cols; - - row = GPOINTER_TO_INT (sel_list->data); - palette = - (GimpPalette *) gtk_clist_get_row_data (GTK_CLIST (palette_dialog->clist), row); - - /* Go through each palette and merge the colors */ - for (cols = palette->colors; cols; cols = g_list_next (cols)) - { - entry = (GimpPaletteEntry *) cols->data; - - gimp_palette_add_entry (new_palette, - entry->name, - &entry->color); - } - sel_list = sel_list->next; - } - - gimp_container_add (global_palette_factory->container, - GIMP_OBJECT (new_palette)); - - /* update all dialogs */ - palette_insert_all (new_palette); -} - static void palette_dialog_merge_callback (GtkWidget *widget, gpointer data) @@ -1410,51 +1303,56 @@ palette_dialog_merge_callback (GtkWidget *widget, _("Enter a name for merged palette"), NULL, NULL, NULL, - palette_dialog_merge_entries_callback, + palette_dialog_do_merge_callback, data); gtk_widget_show (qbox); } -/* the palette & palette edit action area callbacks ************************/ - static void -palette_dialog_save_callback (GtkWidget *widget, - gpointer data) +palette_dialog_do_merge_callback (GtkWidget *widget, + gchar *palette_name, + gpointer data) { - g_warning ("%s(): TODO", G_GNUC_FUNCTION); + PaletteDialog *palette_dialog; + GimpPalette *palette; + GimpPalette *new_palette; + GimpPaletteEntry *entry; + GList *sel_list; - /* - palette_save_palettes (); - */ -} - -static void -palette_dialog_refresh_callback (GtkWidget *widget, - gpointer data) -{ - palette_refresh_all (); -} - -static void -palette_dialog_edit_callback (GtkWidget *widget, - gpointer data) -{ - GimpPalette *palette = NULL; - PaletteDialog *palette_dialog; - GList *sel_list; + new_palette = GIMP_PALETTE (gimp_palette_new (palette_name)); palette_dialog = (PaletteDialog *) data; - sel_list = GTK_CLIST (palette_dialog->clist)->selection; + sel_list = GTK_LIST (GIMP_CONTAINER_LIST_VIEW (GIMP_DATA_FACTORY_VIEW (palette_dialog->view)->view)->gtk_list)->selection; - if (sel_list) + while (sel_list) { - palette = - (GimpPalette *) gtk_clist_get_row_data (GTK_CLIST (palette_dialog->clist), - GPOINTER_TO_INT (sel_list->data)); + GtkWidget *list_item; + GList *cols; + + list_item = GTK_WIDGET (sel_list->data); + + palette = (GimpPalette *) + GIMP_PREVIEW (gtk_object_get_data (GTK_OBJECT (list_item), + "preview"))->viewable; + + if (palette) + { + for (cols = palette->colors; cols; cols = g_list_next (cols)) + { + entry = (GimpPaletteEntry *) cols->data; + + gimp_palette_add_entry (new_palette, + entry->name, + &entry->color); + } + } + + sel_list = sel_list->next; } - palette_create_edit (palette); + gimp_container_add (global_palette_factory->container, + GIMP_OBJECT (new_palette)); } static void @@ -1494,7 +1392,9 @@ palette_dialog_drag_color (GtkWidget *widget, palette_dialog = (PaletteDialog *) data; - if (palette_dialog && palette_dialog->palette && palette_dialog->dnd_color) + if (palette_dialog && + gimp_context_get_palette (palette_dialog->context) && + palette_dialog->dnd_color) { *color = palette_dialog->dnd_color->color; } @@ -1513,283 +1413,32 @@ palette_dialog_drop_color (GtkWidget *widget, palette_dialog = (PaletteDialog *) data; - if (palette_dialog && palette_dialog->palette) + if (palette_dialog && gimp_context_get_palette (palette_dialog->context)) { - palette_dialog->color = gimp_palette_add_entry (palette_dialog->palette, - NULL, - (GimpRGB *) color); - - palette_update_all (palette_dialog->palette); + palette_dialog->color = + gimp_palette_add_entry (gimp_context_get_palette (palette_dialog->context), + NULL, + (GimpRGB *) color); } } -/* the palette & palette edit dialog constructor ***************************/ - -PaletteDialog * -palette_dialog_new (gboolean editor) +static void +palette_dialog_invalidate_preview (GimpPalette *palette, + PaletteDialog *palette_dialog) { - PaletteDialog *palette_dialog; - GtkWidget *hbox; - GtkWidget *hbox2; - GtkWidget *vbox; - GtkWidget *scrolledwindow; - GtkWidget *palette_region; - GtkWidget *entry; - GtkWidget *eventbox; - GtkWidget *alignment; - GtkWidget *frame; - GtkWidget *button; - gchar *titles[3]; - - palette_dialog = g_new0 (PaletteDialog, 1); - palette_dialog->palette = default_palette_entries; - palette_dialog->zoom_factor = 1.0; - palette_dialog->columns = COLUMNS; - palette_dialog->columns_valid = TRUE; - palette_dialog->freeze_update = FALSE; - - if (!editor) + if (palette == gimp_context_get_palette (palette_dialog->context)) { - palette_dialog->shell = - gimp_dialog_new (_("Color Palette Edit"), "color_palette_edit", - gimp_standard_help_func, - "dialogs/palette_editor/palette_editor.html", - GTK_WIN_POS_NONE, - FALSE, TRUE, FALSE, - - _("Save"), palette_dialog_save_callback, - palette_dialog, NULL, NULL, FALSE, FALSE, - _("Refresh"), palette_dialog_refresh_callback, - palette_dialog, NULL, NULL, FALSE, FALSE, - _("Close"), palette_dialog_close_callback, - palette_dialog, NULL, NULL, TRUE, TRUE, - - NULL); + palette_dialog->columns_valid = FALSE; + palette_dialog_redraw (palette_dialog); } - else - { - palette_dialog->shell = - gimp_dialog_new (_("Color Palette"), "color_palette", - gimp_standard_help_func, - "dialogs/palette_selection.html", - GTK_WIN_POS_NONE, - FALSE, TRUE, FALSE, - - _("Edit"), palette_dialog_edit_callback, - palette_dialog, NULL, NULL, FALSE, FALSE, - _("Close"), palette_dialog_close_callback, - palette_dialog, NULL, NULL, TRUE, TRUE, - - NULL); - } - - /* The main container widget */ - if (editor) - { - hbox = gtk_notebook_new (); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 1); - } - else - { - hbox = gtk_hbox_new (FALSE, 4); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 4); - } - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (palette_dialog->shell)->vbox), - hbox); - gtk_widget_show (hbox); - - vbox = gtk_vbox_new (FALSE, 2); - gtk_widget_show (vbox); - - palette_dialog->scrolled_window = - scrolledwindow = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_ALWAYS); - gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0); - gtk_widget_show (scrolledwindow); - - eventbox = gtk_event_box_new (); - gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledwindow), - eventbox); - gtk_signal_connect (GTK_OBJECT (eventbox), "button_press_event", - GTK_SIGNAL_FUNC (palette_dialog_eventbox_button_press), - palette_dialog); - gtk_widget_show (eventbox); - - alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); - gtk_container_add (GTK_CONTAINER (eventbox), alignment); - gtk_widget_show (alignment); - - palette_dialog->color_area = palette_region = - gtk_preview_new (GTK_PREVIEW_COLOR); - gtk_preview_set_dither (GTK_PREVIEW (palette_dialog->color_area), - GDK_RGB_DITHER_MAX); - gtk_preview_size (GTK_PREVIEW (palette_region), PREVIEW_WIDTH, PREVIEW_HEIGHT); - - gtk_widget_set_events (palette_region, PALETTE_EVENT_MASK); - gtk_signal_connect (GTK_OBJECT (palette_dialog->color_area), "event", - GTK_SIGNAL_FUNC (palette_dialog_color_area_events), - palette_dialog); - - gtk_container_add (GTK_CONTAINER (alignment), palette_region); - gtk_widget_show (palette_region); - - /* dnd stuff */ - gtk_drag_source_set (palette_region, - GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, - color_palette_target_table, n_color_palette_targets, - GDK_ACTION_COPY | GDK_ACTION_MOVE); - gimp_dnd_color_source_set (palette_region, palette_dialog_drag_color, - palette_dialog); - - gtk_drag_dest_set (alignment, - GTK_DEST_DEFAULT_HIGHLIGHT | - GTK_DEST_DEFAULT_MOTION | - GTK_DEST_DEFAULT_DROP, - color_palette_target_table, n_color_palette_targets, - GDK_ACTION_COPY); - gimp_dnd_color_dest_set (alignment, palette_dialog_drop_color, palette_dialog); - - /* The color name entry */ - hbox2 = gtk_hbox_new (FALSE, 2); - gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0); - gtk_widget_show (hbox2); - - entry = palette_dialog->color_name = gtk_entry_new (); - gtk_widget_show (entry); - gtk_box_pack_start (GTK_BOX (hbox2), entry, TRUE, TRUE, 0); - gtk_entry_set_text (GTK_ENTRY (entry), _("Undefined")); - gtk_widget_set_sensitive (entry, FALSE); - palette_dialog->entry_sig_id = - gtk_signal_connect (GTK_OBJECT (entry), "changed", - GTK_SIGNAL_FUNC (palette_dialog_color_name_entry_changed), - palette_dialog); - - /* + and - buttons */ - button = gimp_pixmap_button_new (zoom_in_xpm, NULL); - gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_zoomin_callback), - palette_dialog); - gtk_widget_show (button); - - button = gimp_pixmap_button_new (zoom_out_xpm, NULL); - gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_zoomout_callback), - palette_dialog); - gtk_widget_show (button); - - /* clist preview of palettes */ - scrolledwindow = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_ALWAYS); - - if (editor) - { - gtk_notebook_append_page (GTK_NOTEBOOK (hbox), vbox, - gtk_label_new (_("Palette"))); - gtk_notebook_append_page (GTK_NOTEBOOK (hbox), scrolledwindow, - gtk_label_new (_("Select"))); - } - else - { - gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (hbox), scrolledwindow, TRUE, TRUE, 0); - } - - gtk_widget_show (scrolledwindow); - - titles[0] = _("Palette"); - titles[1] = _("Ncols"); - titles[2] = _("Name"); - palette_dialog->clist = gtk_clist_new_with_titles (3, titles); - gtk_widget_set_usize (palette_dialog->clist, 203, 203); - gtk_clist_set_row_height (GTK_CLIST (palette_dialog->clist), - SM_PREVIEW_HEIGHT + 2); - gtk_clist_set_column_width (GTK_CLIST (palette_dialog->clist), 0, - SM_PREVIEW_WIDTH+2); - gtk_clist_column_titles_passive (GTK_CLIST (palette_dialog->clist)); - gtk_container_add (GTK_CONTAINER (scrolledwindow), palette_dialog->clist); - - if (!editor) - gtk_clist_set_selection_mode (GTK_CLIST (palette_dialog->clist), - GTK_SELECTION_EXTENDED); - - gtk_signal_connect (GTK_OBJECT (palette_dialog->clist), "select_row", - GTK_SIGNAL_FUNC (palette_dialog_list_item_update), - (gpointer) palette_dialog); - gtk_widget_show (palette_dialog->clist); - - if (!editor) - { - frame = gtk_frame_new (_("Palette Ops")); - gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0); - gtk_widget_show (frame); - - vbox = gtk_vbox_new (FALSE, 2); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); - gtk_container_add (GTK_CONTAINER (frame), vbox); - gtk_widget_show (vbox); - - button = gtk_button_new_with_label (_("New")); - GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); - gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_new_callback), - palette_dialog); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gimp_help_set_help_data (button, NULL, - "dialogs/palette_editor/new_palette.html"); - gtk_widget_show (button); - - button = gtk_button_new_with_label (_("Delete")); - GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); - gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_delete_callback), - palette_dialog); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gimp_help_set_help_data (button, NULL, - "dialogs/palette_editor/delete_palette.html"); - gtk_widget_show (button); - - button = gtk_button_new_with_label (_("Import")); - GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); - gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_import_callback), - palette_dialog); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gimp_help_set_help_data (button, NULL, - "dialogs/palette_editor/import_palette.html"); - gtk_widget_show (button); - - button = gtk_button_new_with_label (_("Merge")); - GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); - gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_merge_callback), - palette_dialog); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gimp_help_set_help_data (button, NULL, - "dialogs/palette_editor/merge_palette.html"); - gtk_widget_show (button); - } - - gtk_widget_realize (palette_dialog->shell); - - palette_dialog->gc = gdk_gc_new (palette_dialog->shell->window); - - /* fill the clist */ - palette_clist_init (palette_dialog->clist, - palette_dialog->shell, - palette_dialog->gc); - palette_dialog_clist_scroll_to_current (palette_dialog); - - palette_dialog_create_popup_menu (palette_dialog); - - return palette_dialog; +} + +static void +palette_dialog_edit_palette (GimpData *data) +{ + GimpPalette *palette; + + palette = GIMP_PALETTE (data); + + palette_create_edit (palette); } diff --git a/app/gui/palette-import-dialog.c b/app/gui/palette-import-dialog.c index 1817ee1284..146249e84e 100644 --- a/app/gui/palette-import-dialog.c +++ b/app/gui/palette-import-dialog.c @@ -573,8 +573,6 @@ palette_import_create_from_grad (gchar *name) gimp_container_add (global_palette_factory->container, GIMP_OBJECT (palette)); - - palette_insert_all (palette); } } @@ -758,8 +756,6 @@ palette_import_image_make_palette (GHashTable *h_array, g_slist_free (sorted_list); gimp_container_add (global_palette_factory->container, GIMP_OBJECT (palette)); - - palette_insert_all (palette); } static void @@ -874,8 +870,6 @@ palette_import_create_from_indexed (GImage *gimage, } gimp_container_add (global_palette_factory->container, GIMP_OBJECT (palette)); - - palette_insert_all (palette); } /* the palette import action area callbacks ********************************/ diff --git a/app/gui/palette-select.c b/app/gui/palette-select.c index 342d20b8a6..020d1dfa16 100644 --- a/app/gui/palette-select.c +++ b/app/gui/palette-select.c @@ -27,31 +27,39 @@ #include "apptypes.h" +#include "appenv.h" #include "context_manager.h" +#include "dialog_handler.h" #include "gimpcontainer.h" +#include "gimpcontext.h" +#include "gimpdatafactoryview.h" #include "gimpdatafactory.h" +#include "gimpdnd.h" #include "gimppalette.h" #include "palette_select.h" #include "palette.h" #include "paletteP.h" +#include "session.h" #include "libgimp/gimpintl.h" +#define STD_PALETTE_COLUMNS 6 +#define STD_PALETTE_ROWS 5 + + /* local function prototypes */ -static gint palette_select_button_press (GtkWidget *widget, - GdkEventButton *bevent, +static void palette_select_drop_palette (GtkWidget *widget, + GimpViewable *viewable, gpointer data); static void palette_select_close_callback (GtkWidget *widget, gpointer data); -static void palette_select_edit_callback (GtkWidget *widget, - gpointer data); +static void palette_select_edit_palette (GimpData *data); /* list of active dialogs */ - -static GSList *active_dialogs = NULL; +static GSList *palette_active_dialogs = NULL; /* public functions */ @@ -60,17 +68,14 @@ PaletteSelect * palette_select_new (const gchar *title, const gchar *initial_palette) { - GimpPalette *palette; PaletteSelect *psp; GtkWidget *vbox; - GtkWidget *hbox; - GtkWidget *scrolled_win; - gchar *titles[3]; - gint select_pos = -1; + GimpPalette *active = NULL; - palette_select_palette_init (); + static gboolean first_call = TRUE; + + psp = g_new0 (PaletteSelect, 1); - psp = g_new (PaletteSelect, 1); psp->callback_name = NULL; /* The shell and main vbox */ @@ -81,182 +86,99 @@ palette_select_new (const gchar *title, GTK_WIN_POS_MOUSE, FALSE, TRUE, FALSE, - _("Edit"), palette_select_edit_callback, - psp, NULL, NULL, TRUE, FALSE, - _("Close"), palette_select_close_callback, + "_delete_event_", palette_select_close_callback, psp, NULL, NULL, FALSE, TRUE, NULL); - vbox = gtk_vbox_new (FALSE, 1); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 1); + gtk_widget_hide (GTK_WIDGET (g_list_nth_data (gtk_container_children (GTK_CONTAINER (GTK_DIALOG (psp->shell)->vbox)), 0))); + + gtk_widget_hide (GTK_DIALOG (psp->shell)->action_area); + + if (title) + { + psp->context = gimp_context_new (title, NULL); + } + else + { + psp->context = gimp_context_get_user (); + + /* + session_set_window_geometry (psp->shell, &palette_select_session_info, + TRUE); + */ + + dialog_register (psp->shell); + } + + if (no_data && first_call) + gimp_data_factory_data_init (global_palette_factory, FALSE); + + first_call = FALSE; + + if (title && initial_palette && strlen (initial_palette)) + { + active = (GimpPalette *) + gimp_container_get_child_by_name (global_palette_factory->container, + initial_palette); + } + else + { + active = gimp_context_get_palette (gimp_context_get_user ()); + } + + if (!active) + active = gimp_context_get_palette (gimp_context_get_standard ()); + + if (title) + gimp_context_set_palette (psp->context, active); + + /* The main vbox */ + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); gtk_container_add (GTK_CONTAINER (GTK_DIALOG (psp->shell)->vbox), vbox); - hbox = gtk_hbox_new (FALSE, 8); - gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); + /* The Palette List */ + psp->view = gimp_data_factory_view_new (GIMP_VIEW_TYPE_LIST, + global_palette_factory, + palette_select_edit_palette, + psp->context, + 64, /* FIXME: SM_PREVIEW_WIDTH */ + 3, /* FIXME: STD_PALETTE_COLUMNS */ + 3); /* FIXME: STD_PALETTE_ROWS */ + gtk_box_pack_start (GTK_BOX (vbox), psp->view, TRUE, TRUE, 0); + gtk_widget_show (psp->view); - /* clist preview of gradients */ - scrolled_win = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_ALWAYS); - gtk_box_pack_start (GTK_BOX (hbox), scrolled_win, TRUE, TRUE, 0); - gtk_widget_show (scrolled_win); + gimp_gtk_drag_dest_set_by_type (psp->view, + GTK_DEST_DEFAULT_ALL, + GIMP_TYPE_PALETTE, + GDK_ACTION_COPY); + gimp_dnd_viewable_dest_set (GTK_WIDGET (psp->view), + GIMP_TYPE_PALETTE, + palette_select_drop_palette, + psp); - titles[0] = _("Palette"); - titles[1] = _("Ncols"); - titles[2] = _("Name"); - psp->clist = gtk_clist_new_with_titles (3, titles); - gtk_clist_set_shadow_type (GTK_CLIST (psp->clist), GTK_SHADOW_IN); - gtk_clist_set_row_height (GTK_CLIST (psp->clist), SM_PREVIEW_HEIGHT + 2); - gtk_clist_set_use_drag_icons (GTK_CLIST (psp->clist), FALSE); - gtk_clist_column_titles_passive (GTK_CLIST (psp->clist)); - gtk_widget_set_usize (psp->clist, 203, 200); - gtk_clist_set_column_width (GTK_CLIST (psp->clist), 0, SM_PREVIEW_WIDTH + 2); - gtk_container_add (GTK_CONTAINER (scrolled_win), psp->clist); - gtk_widget_show (psp->clist); - - palette = (GimpPalette *) - gimp_container_get_child_by_name (global_palette_factory->container, - initial_palette); - - if (palette) - select_pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (palette)); - - gtk_widget_realize (psp->shell); - psp->gc = gdk_gc_new (psp->shell->window); - - palette_clist_init (psp->clist, psp->shell, psp->gc); - gtk_signal_connect (GTK_OBJECT (psp->clist), "button_press_event", - GTK_SIGNAL_FUNC (palette_select_button_press), - (gpointer) psp); - - /* Now show the dialog */ gtk_widget_show (vbox); gtk_widget_show (psp->shell); - if (select_pos != -1) - { - gtk_clist_select_row (GTK_CLIST (psp->clist), select_pos, -1); - gtk_clist_moveto (GTK_CLIST (psp->clist), select_pos, 0, 0.0, 0.0); - } - else - gtk_clist_select_row (GTK_CLIST (psp->clist), 0, -1); - - active_dialogs = g_slist_append (active_dialogs, psp); + palette_active_dialogs = g_slist_append (palette_active_dialogs, psp); return psp; } -void -palette_select_clist_insert_all (GimpPalette *entries) -{ - PaletteSelect *psp; - GSList *list; - gint pos; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (entries)); - - for (list = active_dialogs; list; list = g_slist_next (list)) - { - psp = (PaletteSelect *) list->data; - - gtk_clist_freeze (GTK_CLIST (psp->clist)); - palette_clist_insert (psp->clist, psp->shell, psp->gc, entries, pos); - gtk_clist_thaw (GTK_CLIST (psp->clist)); - } -} - -void -palette_select_set_text_all (GimpPalette *entries) -{ - PaletteSelect *psp; - GSList *list; - gchar *num_buf; - gint pos; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (entries)); - - num_buf = g_strdup_printf ("%d", entries->n_colors); - - for (list = active_dialogs; list; list = g_slist_next (list)) - { - psp = (PaletteSelect *) list->data; - - gtk_clist_set_text (GTK_CLIST (psp->clist), pos, 1, num_buf); - } - - g_free (num_buf); -} - -void -palette_select_refresh_all (void) -{ - PaletteSelect *psp; - GSList *list; - - for (list = active_dialogs; list; list = g_slist_next (list)) - { - psp = (PaletteSelect *) list->data; - - gtk_clist_freeze (GTK_CLIST (psp->clist)); - gtk_clist_clear (GTK_CLIST (psp->clist)); - palette_clist_init (psp->clist, psp->shell, psp->gc); - gtk_clist_thaw (GTK_CLIST (psp->clist)); - } -} /* local functions */ -static gint -palette_select_button_press (GtkWidget *widget, - GdkEventButton *bevent, - gpointer data) -{ - PaletteSelect *psp; - - psp = (PaletteSelect *) data; - - if (bevent->button == 1 && bevent->type == GDK_2BUTTON_PRESS) - { - palette_select_edit_callback (widget, data); - - return TRUE; - } - - return FALSE; -} - static void -palette_select_edit_callback (GtkWidget *widget, - gpointer data) +palette_select_drop_palette (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) { - GimpPalette *p_entries = NULL; PaletteSelect *psp; - GList *sel_list; psp = (PaletteSelect *) data; - sel_list = GTK_CLIST (psp->clist)->selection; - - while (sel_list) - { - gint row; - - row = GPOINTER_TO_INT (sel_list->data); - - p_entries = - (GimpPalette *) gtk_clist_get_row_data (GTK_CLIST (psp->clist), row); - - palette_create_edit (p_entries); - - /* One only */ - return; - } + gimp_context_set_palette (psp->context, GIMP_PALETTE (viewable)); } static void @@ -270,7 +192,7 @@ palette_select_free (PaletteSelect *psp) */ /* remove from active list */ - active_dialogs = g_slist_remove (active_dialogs, psp); + palette_active_dialogs = g_slist_remove (palette_active_dialogs, psp); g_free (psp); } @@ -290,3 +212,13 @@ palette_select_close_callback (GtkWidget *widget, gtk_widget_destroy (psp->shell); palette_select_free (psp); } + +static void +palette_select_edit_palette (GimpData *data) +{ + GimpPalette *palette; + + palette = GIMP_PALETTE (data); + + palette_create_edit (palette); +} diff --git a/app/gui/palette-select.h b/app/gui/palette-select.h index d8774a7b64..3ccab5600e 100644 --- a/app/gui/palette-select.h +++ b/app/gui/palette-select.h @@ -28,19 +28,17 @@ typedef struct _PaletteSelect PaletteSelect; struct _PaletteSelect { - GtkWidget *shell; - GtkWidget *clist; - GdkGC *gc; - gchar *callback_name; + GtkWidget *shell; + GtkWidget *view; + + gchar *callback_name; + + GimpContext *context; }; PaletteSelect * palette_select_new (const gchar *title, const gchar *initial_palette); -void palette_select_clist_insert_all (GimpPalette *palette); -void palette_select_set_text_all (GimpPalette *palette); -void palette_select_refresh_all (void); - #endif /* __PALETTE_SELECT_H__ */ diff --git a/app/gui/pattern-select.c b/app/gui/pattern-select.c index ca907d509b..68b5ce387b 100644 --- a/app/gui/pattern-select.c +++ b/app/gui/pattern-select.c @@ -30,10 +30,9 @@ #include "context_manager.h" #include "dialog_handler.h" #include "gimpcontainer.h" -#include "gimpdatafactoryview.h" #include "gimpcontext.h" +#include "gimpdatafactoryview.h" #include "gimpdatafactory.h" -#include "gimpdnd.h" #include "gimppattern.h" #include "pattern_select.h" #include "session.h" @@ -53,9 +52,6 @@ static void pattern_select_change_callbacks (PatternSelect *psp, gboolean closing); -static void pattern_select_drop_pattern (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); static void pattern_select_pattern_changed (GimpContext *context, GimpPattern *pattern, PatternSelect *psp); @@ -209,15 +205,6 @@ pattern_select_new (gchar *title, gtk_box_pack_start (GTK_BOX (vbox), psp->view, TRUE, TRUE, 0); gtk_widget_show (psp->view); - gimp_gtk_drag_dest_set_by_type (psp->view, - GTK_DEST_DEFAULT_ALL, - GIMP_TYPE_PATTERN, - GDK_ACTION_COPY); - gimp_dnd_viewable_dest_set (GTK_WIDGET (psp->view), - GIMP_TYPE_PATTERN, - pattern_select_drop_pattern, - psp); - gtk_widget_show (vbox); /* add callbacks to keep the display area current */ @@ -353,19 +340,6 @@ pattern_select_dialogs_check (void) * Local functions */ -static void -pattern_select_drop_pattern (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - PatternSelect *psp; - - psp = (PatternSelect *) data; - - gimp_context_set_pattern (psp->context, GIMP_PATTERN (viewable)); -} - - static void pattern_select_pattern_changed (GimpContext *context, GimpPattern *pattern, diff --git a/app/palette.c b/app/palette.c index 9242fbe979..bcaf5e3431 100644 --- a/app/palette.c +++ b/app/palette.c @@ -30,11 +30,14 @@ #include "context_manager.h" #include "dialog_handler.h" #include "gimage.h" +#include "gimpcontainerlistview.h" #include "gimpcontext.h" #include "gimpdatafactory.h" +#include "gimpdatafactoryview.h" #include "gimpdatalist.h" #include "gimpdnd.h" #include "gimppalette.h" +#include "gimppreview.h" #include "gimprc.h" #include "palette.h" #include "palette_import.h" @@ -56,11 +59,12 @@ #define COLUMNS 16 #define ROWS 11 -#define PREVIEW_WIDTH ((ENTRY_WIDTH * COLUMNS) + (SPACING * (COLUMNS + 1))) -#define PREVIEW_HEIGHT ((ENTRY_HEIGHT * ROWS) + (SPACING * (ROWS + 1))) +#define PREVIEW_WIDTH ((ENTRY_WIDTH * COLUMNS) + (SPACING * (COLUMNS + 1))) +#define PREVIEW_HEIGHT ((ENTRY_HEIGHT * ROWS) + (SPACING * (ROWS + 1))) -#define PALETTE_EVENT_MASK GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | \ - GDK_ENTER_NOTIFY_MASK +#define PALETTE_EVENT_MASK (GDK_EXPOSURE_MASK | \ + GDK_BUTTON_PRESS_MASK | \ + GDK_ENTER_NOTIFY_MASK) typedef struct _PaletteDialog PaletteDialog; @@ -72,7 +76,10 @@ struct _PaletteDialog GtkWidget *color_area; GtkWidget *scrolled_window; GtkWidget *color_name; - GtkWidget *clist; + + GtkWidget *view; + + GimpContext *context; GtkWidget *popup_menu; GtkWidget *delete_menu_item; @@ -81,11 +88,9 @@ struct _PaletteDialog ColorNotebook *color_notebook; gboolean color_notebook_active; - GimpPalette *palette; GimpPaletteEntry *color; GimpPaletteEntry *dnd_color; - GdkGC *gc; guint entry_sig_id; gfloat zoom_factor; /* range from 0.1 to 4.0 */ gint col_width; @@ -93,23 +98,70 @@ struct _PaletteDialog gint columns; gboolean freeze_update; gboolean columns_valid; + + GQuark invalidate_preview_handler_id; }; /* local function prototypes */ -static void palette_dialog_draw_entries (PaletteDialog *palette, - gint row_start, - gint column_highlight); -static void palette_dialog_redraw (PaletteDialog *palette); -static void palette_dialog_scroll_top_left (PaletteDialog *palette); +static PaletteDialog * palette_dialog_new (gboolean editor); -static PaletteDialog * palette_dialog_new (gboolean editor); +static void palette_dialog_create_popup_menu (PaletteDialog *palette_dialog); +static void palette_dialog_new_entry_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_edit_entry_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_delete_entry_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_color_notebook_callback (ColorNotebook *color_notebook, + const GimpRGB *color, + ColorNotebookState state, + gpointer data); + +static gint palette_dialog_eventbox_button_press (GtkWidget *widget, + GdkEventButton *bevent, + PaletteDialog *palette_dialog); +static gint palette_dialog_color_area_events (GtkWidget *widget, + GdkEvent *event, + PaletteDialog *palette_dialog); +static void palette_dialog_draw_entries (PaletteDialog *palette, + gint row_start, + gint column_highlight); +static void palette_dialog_redraw (PaletteDialog *palette); +static void palette_dialog_scroll_top_left (PaletteDialog *palette); + +static void palette_dialog_color_name_changed (GtkWidget *widget, + gpointer data); +static void palette_dialog_zoomin_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_zoomout_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_redraw_zoom (PaletteDialog *palette_dialog); +static void palette_dialog_import_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_merge_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_do_merge_callback (GtkWidget *widget, + gchar *palette_name, + gpointer data); +static void palette_dialog_close_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_palette_changed (GimpContext *context, + GimpPalette *palette, + gpointer data); +static void palette_dialog_drag_color (GtkWidget *widget, + GimpRGB *color, + gpointer data); +static void palette_dialog_drop_color (GtkWidget *widget, + const GimpRGB *color, + gpointer data); +static void palette_dialog_invalidate_preview (GimpPalette *palette, + PaletteDialog *palette_dialog); +static void palette_dialog_edit_palette (GimpData *data); -PaletteDialog *top_level_edit_palette = NULL; -PaletteDialog *top_level_palette = NULL; - -static GimpPalette *default_palette_entries = NULL; +PaletteDialog *top_level_edit_palette = NULL; +PaletteDialog *top_level_palette = NULL; /* dnd stuff */ @@ -128,7 +180,7 @@ palette_dialog_create (void) { if (top_level_palette == NULL) { - top_level_palette = palette_dialog_new (TRUE); + top_level_palette = palette_dialog_new (FALSE); session_set_window_geometry (top_level_palette->shell, &palette_session_info, TRUE); dialog_register (top_level_palette->shell); @@ -155,10 +207,15 @@ palette_dialog_free (void) { palette_import_dialog_destroy (); - gdk_gc_destroy (top_level_edit_palette->gc); - if (top_level_edit_palette->color_notebook) - color_notebook_free (top_level_edit_palette->color_notebook); + color_notebook_free (top_level_edit_palette->color_notebook); + + gtk_signal_disconnect_by_func (GTK_OBJECT (top_level_edit_palette->context), + palette_dialog_palette_changed, + top_level_edit_palette); + + gimp_container_remove_handler (global_palette_factory->container, + top_level_edit_palette->invalidate_preview_handler_id); g_free (top_level_edit_palette); top_level_edit_palette = NULL; @@ -166,275 +223,24 @@ palette_dialog_free (void) if (top_level_palette) { - gdk_gc_destroy (top_level_palette->gc); session_get_window_info (top_level_palette->shell, &palette_session_info); if (top_level_palette->color_notebook) color_notebook_free (top_level_palette->color_notebook); + gtk_signal_disconnect_by_func (GTK_OBJECT (top_level_palette->context), + palette_dialog_palette_changed, + top_level_palette); + + gimp_container_remove_handler (global_palette_factory->container, + top_level_palette->invalidate_preview_handler_id); + g_free (top_level_palette); top_level_palette = NULL; } } -/* general palette clist update functions **********************************/ - -void -palette_clist_init (GtkWidget *clist, - GtkWidget *shell, - GdkGC *gc) -{ - GimpPalette *palette = NULL; - GList *list; - gint pos; - - for (list = GIMP_LIST (global_palette_factory->container)->list, pos = 0; - list; - list = g_list_next (list), pos++) - { - palette = (GimpPalette *) list->data; - - palette_clist_insert (clist, shell, gc, palette, pos); - } -} - -void -palette_clist_insert (GtkWidget *clist, - GtkWidget *shell, - GdkGC *gc, - GimpPalette *palette, - gint pos) -{ - gchar *string[3]; - - string[0] = NULL; - string[1] = g_strdup_printf ("%d", palette->n_colors); - string[2] = GIMP_OBJECT (palette)->name; - - gtk_clist_insert (GTK_CLIST (clist), pos, string); - - g_free (string[1]); - - if (palette->pixmap == NULL) - { - palette->pixmap = gdk_pixmap_new (shell->window, - SM_PREVIEW_WIDTH, - SM_PREVIEW_HEIGHT, - gtk_widget_get_visual (shell)->depth); - gimp_palette_update_preview (palette, gc); - } - - gtk_clist_set_pixmap (GTK_CLIST (clist), pos, 0, palette->pixmap, NULL); - gtk_clist_set_row_data (GTK_CLIST (clist), pos, (gpointer) palette); -} - -/* palette dialog clist update functions ***********************************/ - -static void -palette_dialog_clist_insert (PaletteDialog *palette_dialog, - GimpPalette *palette) -{ - gint pos; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (palette)); - - gtk_clist_freeze (GTK_CLIST (palette_dialog->clist)); - - palette_clist_insert (palette_dialog->clist, - palette_dialog->shell, - palette_dialog->gc, - palette, - pos); - - gtk_clist_thaw (GTK_CLIST (palette_dialog->clist)); -} - -static void -palette_dialog_clist_set_text (PaletteDialog *palette_dialog, - GimpPalette *palette) -{ - gchar *num_buf; - gint pos; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (palette)); - - num_buf = g_strdup_printf ("%d", palette->n_colors);; - - gtk_clist_set_text (GTK_CLIST (palette_dialog->clist), pos, 1, num_buf); - - g_free (num_buf); -} - -static void -palette_dialog_clist_refresh (PaletteDialog *palette_dialog) -{ - gtk_clist_freeze (GTK_CLIST (palette_dialog->clist)); - - gtk_clist_clear (GTK_CLIST (palette_dialog->clist)); - palette_clist_init (palette_dialog->clist, - palette_dialog->shell, - palette_dialog->gc); - - gtk_clist_thaw (GTK_CLIST (palette_dialog->clist)); - - palette_dialog->palette = (GimpPalette *) - gimp_container_get_child_by_index (global_palette_factory->container, 0); -} - -static void -palette_dialog_clist_scroll_to_current (PaletteDialog *palette_dialog) -{ - gint pos; - - if (! (palette_dialog && palette_dialog->palette)) - return; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (palette_dialog->palette)); - - gtk_clist_unselect_all (GTK_CLIST (palette_dialog->clist)); - gtk_clist_select_row (GTK_CLIST (palette_dialog->clist), pos, -1); - gtk_clist_moveto (GTK_CLIST (palette_dialog->clist), pos, 0, 0.0, 0.0); -} - -/* update functions for all palette dialogs ********************************/ - -void -palette_insert_all (GimpPalette *palette) -{ - PaletteDialog *palette_dialog; - - if ((palette_dialog = top_level_palette)) - { - palette_dialog_clist_insert (palette_dialog, palette); - - if (palette_dialog->palette == NULL) - { - palette_dialog->palette = palette; - palette_dialog_redraw (palette_dialog); - } - } - - if ((palette_dialog = top_level_edit_palette)) - { - palette_dialog_clist_insert (palette_dialog, palette); - - palette_dialog->palette = palette; - palette_dialog_redraw (palette_dialog); - - palette_dialog_clist_scroll_to_current (palette_dialog); - } - - /* Update other selectors on screen */ - palette_select_clist_insert_all (palette); -} - -static void -palette_update_all (GimpPalette *palette) -{ - PaletteDialog *palette_dialog; - GdkGC *gc = NULL; - - if (top_level_palette) - gc = top_level_palette->gc; - else if (top_level_edit_palette) - gc = top_level_edit_palette->gc; - - if (gc) - gimp_palette_update_preview (palette, gc); - - if ((palette_dialog = top_level_palette)) - { - if (palette_dialog->palette == palette) - { - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - } - palette_dialog_clist_set_text (palette_dialog, palette); - } - - if ((palette_dialog = top_level_edit_palette)) - { - if (palette_dialog->palette == palette) - { - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - palette_dialog_clist_scroll_to_current (palette_dialog); - } - palette_dialog_clist_set_text (palette_dialog, palette); - } - - /* Update other selectors on screen */ - palette_select_set_text_all (palette); -} - -static void -palette_draw_all (GimpPalette *palette, - GimpPaletteEntry *entry) -{ - PaletteDialog *palette_dialog; - GdkGC *gc = NULL; - - if (top_level_palette) - gc = top_level_palette->gc; - else if (top_level_edit_palette) - gc = top_level_edit_palette->gc; - - if (gc) - gimp_palette_update_preview (palette, gc); - - if ((palette_dialog = top_level_palette)) - { - if (palette_dialog->palette == palette) - { - palette_dialog_draw_entries (palette_dialog, - entry->position / palette_dialog->columns, - entry->position % palette_dialog->columns); - } - } - - if ((palette_dialog = top_level_edit_palette)) - { - if (palette_dialog->palette == palette) - { - palette_dialog_draw_entries (palette_dialog, - entry->position / palette_dialog->columns, - entry->position % palette_dialog->columns); - } - } -} - -static void -palette_refresh_all (void) -{ - PaletteDialog *palette_dialog; - - default_palette_entries = NULL; - - gimp_data_factory_data_init (global_palette_factory, FALSE); - - if ((palette_dialog = top_level_palette)) - { - palette_dialog_clist_refresh (palette_dialog); - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - palette_dialog_clist_scroll_to_current (palette_dialog); - } - - if ((palette_dialog = top_level_edit_palette)) - { - palette_dialog_clist_refresh (palette_dialog); - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - palette_dialog_clist_scroll_to_current (palette_dialog); - } - - /* Update other selectors on screen */ - palette_select_refresh_all (); -} /* called from color_picker.h *********************************************/ @@ -444,7 +250,8 @@ palette_set_active_color (gint r, gint b, gint state) { - GimpRGB color; + GimpPalette *palette; + GimpRGB color; gimp_rgba_set_uchar (&color, (guchar) r, @@ -452,29 +259,30 @@ palette_set_active_color (gint r, (guchar) b, 255); - if (top_level_edit_palette && top_level_edit_palette->palette) + if (top_level_edit_palette) { - switch (state) - { - case COLOR_NEW: - top_level_edit_palette->color = - gimp_palette_add_entry (top_level_edit_palette->palette, - NULL, - &color); + palette = gimp_context_get_palette (top_level_edit_palette->context); - palette_update_all (top_level_edit_palette->palette); - break; + if (palette) + { + switch (state) + { + case COLOR_NEW: + top_level_edit_palette->color = gimp_palette_add_entry (palette, + NULL, + &color); + break; - case COLOR_UPDATE_NEW: - top_level_edit_palette->color->color = color; + case COLOR_UPDATE_NEW: + top_level_edit_palette->color->color = color; - palette_draw_all (top_level_edit_palette->palette, - top_level_edit_palette->color); - break; + gimp_data_dirty (GIMP_DATA (palette)); + break; - default: - break; - } + default: + break; + } + } } if (active_color == FOREGROUND) @@ -485,22 +293,12 @@ palette_set_active_color (gint r, /* called from palette_select.c ********************************************/ -void -palette_select_palette_init (void) -{ - if (top_level_edit_palette == NULL) - { - top_level_edit_palette = palette_dialog_new (FALSE); - dialog_register (top_level_edit_palette->shell); - } -} - void palette_create_edit (GimpPalette *palette) { if (top_level_edit_palette == NULL) { - top_level_edit_palette = palette_dialog_new (FALSE); + top_level_edit_palette = palette_dialog_new (TRUE); dialog_register (top_level_edit_palette->shell); gtk_widget_show (top_level_edit_palette->shell); @@ -509,142 +307,259 @@ palette_create_edit (GimpPalette *palette) else { if (! GTK_WIDGET_VISIBLE (top_level_edit_palette->shell)) - { - gtk_widget_show (top_level_edit_palette->shell); - palette_dialog_draw_entries (top_level_edit_palette, -1, -1); - } + gtk_widget_show (top_level_edit_palette->shell); else - { - gdk_window_raise (top_level_edit_palette->shell->window); - } + gdk_window_raise (top_level_edit_palette->shell->window); } - if (palette != NULL) - { - top_level_edit_palette->palette = palette; - palette_dialog_clist_scroll_to_current (top_level_edit_palette); - } + gimp_context_set_palette (top_level_edit_palette->context, palette); } -static void -palette_select_callback (ColorNotebook *color_notebook, - const GimpRGB *color, - ColorNotebookState state, - gpointer data) + +/* private functions */ + +/* the palette & palette edit dialog constructor ***************************/ + +PaletteDialog * +palette_dialog_new (gboolean editor) { PaletteDialog *palette_dialog; - - palette_dialog = data; + GtkWidget *hbox; + GtkWidget *hbox2; + GtkWidget *vbox; + GtkWidget *scrolledwindow; + GtkWidget *palette_region; + GtkWidget *entry; + GtkWidget *eventbox; + GtkWidget *alignment; + GtkWidget *frame; + GtkWidget *button; - if (! (palette_dialog && palette_dialog->palette)) - return; + palette_dialog = g_new0 (PaletteDialog, 1); - switch (state) + if (! editor) + palette_dialog->context = gimp_context_get_user (); + else + palette_dialog->context = gimp_context_new (NULL, NULL); + + palette_dialog->zoom_factor = 1.0; + palette_dialog->columns = COLUMNS; + palette_dialog->columns_valid = TRUE; + palette_dialog->freeze_update = FALSE; + + if (editor) { - case COLOR_NOTEBOOK_UPDATE: - break; + palette_dialog->shell = + gimp_dialog_new (_("Color Palette Edit"), "color_palette_edit", + gimp_standard_help_func, + "dialogs/palette_editor/palette_editor.html", + GTK_WIN_POS_NONE, + FALSE, TRUE, FALSE, - case COLOR_NOTEBOOK_OK: - if (palette_dialog->color) - { - palette_dialog->color->color = *color; + "_delete_event_", palette_dialog_close_callback, + palette_dialog, NULL, NULL, TRUE, TRUE, - /* Update either foreground or background colors */ - if (active_color == FOREGROUND) - gimp_context_set_foreground (gimp_context_get_user (), color); - else if (active_color == BACKGROUND) - gimp_context_set_background (gimp_context_get_user (), color); - - palette_draw_all (palette_dialog->palette, palette_dialog->color); - } - - /* Fallthrough */ - case COLOR_NOTEBOOK_CANCEL: - if (palette_dialog->color_notebook_active) - { - color_notebook_hide (palette_dialog->color_notebook); - palette_dialog->color_notebook_active = FALSE; - } - } -} - -/* the palette dialog popup menu & callbacks *******************************/ - -static void -palette_dialog_new_entry_callback (GtkWidget *widget, - gpointer data) -{ - PaletteDialog *palette_dialog; - GimpRGB color; - - palette_dialog = (PaletteDialog *) data; - - if (! (palette_dialog && palette_dialog->palette)) - return; - - if (active_color == FOREGROUND) - gimp_context_get_foreground (gimp_context_get_user (), &color); - else if (active_color == BACKGROUND) - gimp_context_get_background (gimp_context_get_user (), &color); - - palette_dialog->color = gimp_palette_add_entry (palette_dialog->palette, - NULL, - &color); - - palette_update_all (palette_dialog->palette); -} - -static void -palette_dialog_edit_entry_callback (GtkWidget *widget, - gpointer data) -{ - PaletteDialog *palette_dialog; - - palette_dialog = (PaletteDialog *) data; - - if (! (palette_dialog && palette_dialog->palette && palette_dialog->color)) - return; - - if (! palette_dialog->color_notebook) - { - palette_dialog->color_notebook = - color_notebook_new (_("Edit Palette Color"), - (const GimpRGB *) &palette_dialog->color->color, - palette_select_callback, - palette_dialog, - FALSE, - FALSE); - palette_dialog->color_notebook_active = TRUE; + NULL); } else { - if (! palette_dialog->color_notebook_active) - { - color_notebook_show (palette_dialog->color_notebook); - palette_dialog->color_notebook_active = TRUE; - } + palette_dialog->shell = + gimp_dialog_new (_("Color Palette"), "color_palette", + gimp_standard_help_func, + "dialogs/palette_selection.html", + GTK_WIN_POS_NONE, + FALSE, TRUE, FALSE, - color_notebook_set_color (palette_dialog->color_notebook, - &palette_dialog->color->color); + "_delete_event_", palette_dialog_close_callback, + palette_dialog, NULL, NULL, TRUE, TRUE, + + NULL); + } + + gtk_widget_hide (GTK_WIDGET (g_list_nth_data (gtk_container_children (GTK_CONTAINER (GTK_DIALOG (palette_dialog->shell)->vbox)), 0))); + + gtk_widget_hide (GTK_DIALOG (palette_dialog->shell)->action_area); + + /* The main container widget */ + if (! editor) + { + hbox = gtk_notebook_new (); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 1); } + else + { + hbox = gtk_hbox_new (FALSE, 4); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 4); + } + + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (palette_dialog->shell)->vbox), + hbox); + gtk_widget_show (hbox); + + vbox = gtk_vbox_new (FALSE, 2); + gtk_widget_show (vbox); + + palette_dialog->scrolled_window = + scrolledwindow = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_ALWAYS); + gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0); + gtk_widget_show (scrolledwindow); + + eventbox = gtk_event_box_new (); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledwindow), + eventbox); + gtk_signal_connect (GTK_OBJECT (eventbox), "button_press_event", + GTK_SIGNAL_FUNC (palette_dialog_eventbox_button_press), + palette_dialog); + gtk_widget_show (eventbox); + + alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); + gtk_container_add (GTK_CONTAINER (eventbox), alignment); + gtk_widget_show (alignment); + + palette_dialog->color_area = palette_region = + gtk_preview_new (GTK_PREVIEW_COLOR); + gtk_preview_set_dither (GTK_PREVIEW (palette_dialog->color_area), + GDK_RGB_DITHER_MAX); + gtk_preview_size (GTK_PREVIEW (palette_region), PREVIEW_WIDTH, PREVIEW_HEIGHT); + + gtk_widget_set_events (palette_region, PALETTE_EVENT_MASK); + gtk_signal_connect (GTK_OBJECT (palette_dialog->color_area), "event", + GTK_SIGNAL_FUNC (palette_dialog_color_area_events), + palette_dialog); + + gtk_container_add (GTK_CONTAINER (alignment), palette_region); + gtk_widget_show (palette_region); + + /* dnd stuff */ + gtk_drag_source_set (palette_region, + GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, + color_palette_target_table, n_color_palette_targets, + GDK_ACTION_COPY | GDK_ACTION_MOVE); + gimp_dnd_color_source_set (palette_region, palette_dialog_drag_color, + palette_dialog); + + gtk_drag_dest_set (alignment, + GTK_DEST_DEFAULT_HIGHLIGHT | + GTK_DEST_DEFAULT_MOTION | + GTK_DEST_DEFAULT_DROP, + color_palette_target_table, n_color_palette_targets, + GDK_ACTION_COPY); + gimp_dnd_color_dest_set (alignment, palette_dialog_drop_color, palette_dialog); + + /* The color name entry */ + hbox2 = gtk_hbox_new (FALSE, 2); + gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0); + gtk_widget_show (hbox2); + + entry = palette_dialog->color_name = gtk_entry_new (); + gtk_widget_show (entry); + gtk_box_pack_start (GTK_BOX (hbox2), entry, TRUE, TRUE, 0); + gtk_entry_set_text (GTK_ENTRY (entry), _("Undefined")); + gtk_widget_set_sensitive (entry, FALSE); + palette_dialog->entry_sig_id = + gtk_signal_connect (GTK_OBJECT (entry), "changed", + GTK_SIGNAL_FUNC (palette_dialog_color_name_changed), + palette_dialog); + + /* + and - buttons */ + button = gimp_pixmap_button_new (zoom_in_xpm, NULL); + gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (palette_dialog_zoomin_callback), + palette_dialog); + gtk_widget_show (button); + + button = gimp_pixmap_button_new (zoom_out_xpm, NULL); + gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (palette_dialog_zoomout_callback), + palette_dialog); + gtk_widget_show (button); + + /* The Palette List */ + palette_dialog->view = + gimp_data_factory_view_new (GIMP_VIEW_TYPE_LIST, + global_palette_factory, + editor ? NULL : palette_dialog_edit_palette, + palette_dialog->context, + 64, /* FIXME: SM_PREVIEW_WIDTH */ + 3, /* FIXME: STD_PALETTE_COLUMNS */ + 3); /* FIXME: STD_PALETTE_ROWS */ + + if (! editor) + { + gtk_notebook_append_page (GTK_NOTEBOOK (hbox), vbox, + gtk_label_new (_("Palette"))); + gtk_notebook_append_page (GTK_NOTEBOOK (hbox), palette_dialog->view, + gtk_label_new (_("Select"))); + } + else + { + gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox), palette_dialog->view, TRUE, TRUE, 0); + } + + if (editor) + gtk_list_set_selection_mode (GTK_LIST (GIMP_CONTAINER_LIST_VIEW (GIMP_DATA_FACTORY_VIEW (palette_dialog->view)->view)->gtk_list), + GTK_SELECTION_EXTENDED); + + gtk_signal_connect (GTK_OBJECT (palette_dialog->context), "palette_changed", + GTK_SIGNAL_FUNC (palette_dialog_palette_changed), + palette_dialog); + + palette_dialog->invalidate_preview_handler_id = + gimp_container_add_handler (global_palette_factory->container, + "invalidate_preview", + GTK_SIGNAL_FUNC (palette_dialog_invalidate_preview), + palette_dialog); + + gtk_widget_show (palette_dialog->view); + + if (editor) + { + frame = gtk_frame_new (_("Palette Ops")); + gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0); + gtk_widget_show (frame); + + vbox = gtk_vbox_new (FALSE, 2); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); + gtk_container_add (GTK_CONTAINER (frame), vbox); + gtk_widget_show (vbox); + + button = gtk_button_new_with_label (_("Import")); + GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); + gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (palette_dialog_import_callback), + palette_dialog); + gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); + gimp_help_set_help_data (button, NULL, + "dialogs/palette_editor/import_palette.html"); + gtk_widget_show (button); + + button = gtk_button_new_with_label (_("Merge")); + GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); + gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (palette_dialog_merge_callback), + palette_dialog); + gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); + gimp_help_set_help_data (button, NULL, + "dialogs/palette_editor/merge_palette.html"); + gtk_widget_show (button); + } + + gtk_widget_realize (palette_dialog->shell); + + palette_dialog_create_popup_menu (palette_dialog); + + return palette_dialog; } -static void -palette_dialog_delete_entry_callback (GtkWidget *widget, - gpointer data) -{ - PaletteDialog *palette_dialog; - - palette_dialog = (PaletteDialog *) data; - - if (! (palette_dialog && palette_dialog->palette && palette_dialog->color)) - return; - - gimp_palette_delete_entry (palette_dialog->palette, - palette_dialog->color); - - palette_update_all (palette_dialog->palette); -} +/* the palette dialog popup menu & callbacks *******************************/ static void palette_dialog_create_popup_menu (PaletteDialog *palette_dialog) @@ -681,6 +596,123 @@ palette_dialog_create_popup_menu (PaletteDialog *palette_dialog) palette_dialog->delete_menu_item = menu_item; } +static void +palette_dialog_new_entry_callback (GtkWidget *widget, + gpointer data) +{ + PaletteDialog *palette_dialog; + GimpRGB color; + + palette_dialog = (PaletteDialog *) data; + + if (! (palette_dialog && gimp_context_get_palette (palette_dialog->context))) + return; + + if (active_color == FOREGROUND) + gimp_context_get_foreground (gimp_context_get_user (), &color); + else if (active_color == BACKGROUND) + gimp_context_get_background (gimp_context_get_user (), &color); + + palette_dialog->color = + gimp_palette_add_entry (gimp_context_get_palette (palette_dialog->context), + NULL, + &color); +} + +static void +palette_dialog_edit_entry_callback (GtkWidget *widget, + gpointer data) +{ + PaletteDialog *palette_dialog; + + palette_dialog = (PaletteDialog *) data; + + if (! (palette_dialog && gimp_context_get_palette (palette_dialog->context) + && palette_dialog->color)) + return; + + if (! palette_dialog->color_notebook) + { + palette_dialog->color_notebook = + color_notebook_new (_("Edit Palette Color"), + (const GimpRGB *) &palette_dialog->color->color, + palette_dialog_color_notebook_callback, + palette_dialog, + FALSE, + FALSE); + palette_dialog->color_notebook_active = TRUE; + } + else + { + if (! palette_dialog->color_notebook_active) + { + color_notebook_show (palette_dialog->color_notebook); + palette_dialog->color_notebook_active = TRUE; + } + + color_notebook_set_color (palette_dialog->color_notebook, + &palette_dialog->color->color); + } +} + +static void +palette_dialog_delete_entry_callback (GtkWidget *widget, + gpointer data) +{ + PaletteDialog *palette_dialog; + + palette_dialog = (PaletteDialog *) data; + + if (! (palette_dialog && gimp_context_get_palette (palette_dialog->context) && + palette_dialog->color)) + return; + + gimp_palette_delete_entry (gimp_context_get_palette (palette_dialog->context), + palette_dialog->color); +} + +static void +palette_dialog_color_notebook_callback (ColorNotebook *color_notebook, + const GimpRGB *color, + ColorNotebookState state, + gpointer data) +{ + PaletteDialog *palette_dialog; + GimpPalette *palette; + + palette_dialog = data; + + palette = gimp_context_get_palette (palette_dialog->context); + + switch (state) + { + case COLOR_NOTEBOOK_UPDATE: + break; + + case COLOR_NOTEBOOK_OK: + if (palette_dialog->color) + { + palette_dialog->color->color = *color; + + /* Update either foreground or background colors */ + if (active_color == FOREGROUND) + gimp_context_set_foreground (gimp_context_get_user (), color); + else if (active_color == BACKGROUND) + gimp_context_set_background (gimp_context_get_user (), color); + + gimp_data_dirty (GIMP_DATA (palette)); + } + + /* Fallthrough */ + case COLOR_NOTEBOOK_CANCEL: + if (palette_dialog->color_notebook_active) + { + color_notebook_hide (palette_dialog->color_notebook); + palette_dialog->color_notebook_active = FALSE; + } + } +} + /* the color area event callbacks ******************************************/ static gint @@ -733,8 +765,8 @@ palette_dialog_color_area_events (GtkWidget *widget, row = (bevent->y - 1) / entry_height; pos = row * palette_dialog->columns + col; - if (palette_dialog->palette) - list = g_list_nth (palette_dialog->palette->colors, pos); + if (gimp_context_get_palette (palette_dialog->context)) + list = g_list_nth (gimp_context_get_palette (palette_dialog->context)->colors, pos); else list = NULL; @@ -744,7 +776,7 @@ palette_dialog_color_area_events (GtkWidget *widget, palette_dialog->dnd_color = NULL; if ((bevent->button == 1 || bevent->button == 3) && - palette_dialog->palette) + gimp_context_get_palette (palette_dialog->context)) { if (list) { @@ -1001,7 +1033,7 @@ palette_dialog_draw_entries (PaletteDialog *palette_dialog, gint entry_height; gint index, y; - if (! (palette_dialog && palette_dialog->palette)) + if (! (palette_dialog && gimp_context_get_palette (palette_dialog->context))) return; width = palette_dialog->color_area->requisition.width; @@ -1019,13 +1051,13 @@ palette_dialog_draw_entries (PaletteDialog *palette_dialog, if (row_start < 0) { y = 0; - list = palette_dialog->palette->colors; + list = gimp_context_get_palette (palette_dialog->context)->colors; column_highlight = -1; } else { y = (entry_height + SPACING) * row_start; - list = g_list_nth (palette_dialog->palette->colors, + list = g_list_nth (gimp_context_get_palette (palette_dialog->context)->colors, row_start * palette_dialog->columns); } @@ -1103,7 +1135,7 @@ palette_dialog_redraw (PaletteDialog *palette_dialog) gint preview_width; guint width; - if (! palette_dialog->palette) + if (! gimp_context_get_palette (palette_dialog->context)) return; width = palette_dialog->color_area->parent->parent->parent->allocation.width; @@ -1116,7 +1148,7 @@ palette_dialog_redraw (PaletteDialog *palette_dialog) if (palette_dialog->col_width < 0) palette_dialog->col_width = 0; palette_dialog->columns_valid = TRUE; - n_entries = palette_dialog->palette->n_colors; + n_entries = gimp_context_get_palette (palette_dialog->context)->n_colors; nrows = n_entries / palette_dialog->columns; if (n_entries % palette_dialog->columns) nrows += 1; @@ -1137,23 +1169,27 @@ palette_dialog_redraw (PaletteDialog *palette_dialog) gtk_container_add (GTK_CONTAINER (parent), palette_dialog->color_area->parent); gtk_widget_unref (palette_dialog->color_area->parent); - palette_dialog_draw_entries (palette_dialog, -1, -1); + if (palette_dialog->color) + palette_dialog_draw_entries (palette_dialog, + palette_dialog->color->position / palette_dialog->columns, + palette_dialog->color->position % palette_dialog->columns); + else + palette_dialog_draw_entries (palette_dialog, -1, -1); } -/* the palette dialog clist "select_row" callback **************************/ - static void -palette_dialog_list_item_update (GtkWidget *widget, - gint row, - gint column, - GdkEventButton *event, - gpointer data) +palette_dialog_palette_changed (GimpContext *context, + GimpPalette *palette, + gpointer data) { PaletteDialog *palette_dialog; - GimpPalette *palette; palette_dialog = (PaletteDialog *) data; + /* FIXME */ + if (! palette) + return; + if (palette_dialog->color_notebook_active) { color_notebook_hide (palette_dialog->color_notebook); @@ -1164,17 +1200,12 @@ palette_dialog_list_item_update (GtkWidget *widget, color_notebook_free (palette_dialog->color_notebook); palette_dialog->color_notebook = NULL; - palette = - (GimpPalette *) gtk_clist_get_row_data (GTK_CLIST (palette_dialog->clist), - row); - - palette_dialog->palette = palette; palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); + palette_dialog_scroll_top_left (palette_dialog); - /* Stop errors in case no colors are selected */ + /* Stop errors in case no colors are selected */ gtk_signal_handler_block (GTK_OBJECT (palette_dialog->color_name), palette_dialog->entry_sig_id); gtk_entry_set_text (GTK_ENTRY (palette_dialog->color_name), _("Undefined")); @@ -1186,44 +1217,25 @@ palette_dialog_list_item_update (GtkWidget *widget, /* the color name entry callback *******************************************/ static void -palette_dialog_color_name_entry_changed (GtkWidget *widget, - gpointer data) +palette_dialog_color_name_changed (GtkWidget *widget, + gpointer data) { PaletteDialog *palette_dialog; palette_dialog = (PaletteDialog *) data; - g_return_if_fail (palette_dialog->palette != NULL); + g_return_if_fail (gimp_context_get_palette (palette_dialog->context) != NULL); if (palette_dialog->color->name) g_free (palette_dialog->color->name); palette_dialog->color->name = g_strdup (gtk_entry_get_text (GTK_ENTRY (palette_dialog->color_name))); - gimp_data_dirty (GIMP_DATA (palette_dialog->palette)); + gimp_data_dirty (GIMP_DATA (gimp_context_get_palette (palette_dialog->context))); } /* palette zoom functions & callbacks **************************************/ -static void -palette_dialog_redraw_zoom (PaletteDialog *palette_dialog) -{ - if (palette_dialog->zoom_factor > 4.0) - { - palette_dialog->zoom_factor = 4.0; - } - else if (palette_dialog->zoom_factor < 0.1) - { - palette_dialog->zoom_factor = 0.1; - } - - palette_dialog->columns = COLUMNS; - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - - palette_dialog_scroll_top_left (palette_dialog); -} - static void palette_dialog_zoomin_callback (GtkWidget *widget, gpointer data) @@ -1250,101 +1262,27 @@ palette_dialog_zoomout_callback (GtkWidget *widget, palette_dialog_redraw_zoom (palette_dialog); } -/* the palette edit ops callbacks ******************************************/ - static void -palette_dialog_add_entries_callback (GtkWidget *widget, - gchar *palette_name, - gpointer data) +palette_dialog_redraw_zoom (PaletteDialog *palette_dialog) { - GimpPalette *palette; + if (palette_dialog->zoom_factor > 4.0) + { + palette_dialog->zoom_factor = 4.0; + } + else if (palette_dialog->zoom_factor < 0.1) + { + palette_dialog->zoom_factor = 0.1; + } - palette = GIMP_PALETTE (gimp_palette_new (palette_name)); + palette_dialog->columns = COLUMNS; - gimp_container_add (global_palette_factory->container, GIMP_OBJECT (palette)); + palette_dialog->columns_valid = FALSE; + palette_dialog_redraw (palette_dialog); - /* update all dialogs */ - palette_insert_all (palette); + palette_dialog_scroll_top_left (palette_dialog); } -static void -palette_dialog_new_callback (GtkWidget *widget, - gpointer data) -{ - GtkWidget *qbox; - - qbox = gimp_query_string_box (_("New Palette"), - gimp_standard_help_func, - "dialogs/palette_editor/new_palette.html", - _("Enter a name for new palette"), - NULL, - NULL, NULL, - palette_dialog_add_entries_callback, data); - gtk_widget_show (qbox); -} - -static void -palette_dialog_do_delete_callback (GtkWidget *widget, - gboolean delete, - gpointer data) -{ - PaletteDialog *palette_dialog; - GimpPalette *palette; - - palette_dialog = (PaletteDialog *) data; - - gtk_widget_set_sensitive (palette_dialog->shell, TRUE); - - if (! delete) - return; - - if (! (palette_dialog && palette_dialog->palette)) - return; - - palette = palette_dialog->palette; - - if (GIMP_DATA (palette)->filename) - gimp_data_delete_from_disk (GIMP_DATA (palette)); - - gimp_container_remove (global_palette_factory->container, - GIMP_OBJECT (palette)); - - palette_refresh_all (); -} - -static void -palette_dialog_delete_callback (GtkWidget *widget, - gpointer data) -{ - PaletteDialog *palette_dialog; - GtkWidget *dialog; - gchar *str; - - palette_dialog = (PaletteDialog *) data; - - if (! (palette_dialog && palette_dialog->palette)) - return; - - gtk_widget_set_sensitive (palette_dialog->shell, FALSE); - - str = g_strdup_printf (_("Are you sure you want to delete\n" - "\"%s\" from the list and from disk?"), - GIMP_OBJECT (palette_dialog->palette)->name); - - dialog = gimp_query_boolean_box (_("Delete Palette"), - gimp_standard_help_func, - "dialogs/palette_editor/delete_palette.html", - FALSE, - str, - _("Delete"), _("Cancel"), - NULL, NULL, - palette_dialog_do_delete_callback, - palette_dialog); - - g_free (str); - - gtk_widget_show (dialog); -} +/* the palette dialog action callbacks **************************************/ static void palette_dialog_import_callback (GtkWidget *widget, @@ -1353,51 +1291,6 @@ palette_dialog_import_callback (GtkWidget *widget, palette_import_dialog_show (); } -static void -palette_dialog_merge_entries_callback (GtkWidget *widget, - gchar *palette_name, - gpointer data) -{ - PaletteDialog *palette_dialog; - GimpPalette *palette; - GimpPalette *new_palette; - GimpPaletteEntry *entry; - GList *sel_list; - - new_palette = GIMP_PALETTE (gimp_palette_new (palette_name)); - - palette_dialog = (PaletteDialog *) data; - - sel_list = GTK_CLIST (palette_dialog->clist)->selection; - - while (sel_list) - { - gint row; - GList *cols; - - row = GPOINTER_TO_INT (sel_list->data); - palette = - (GimpPalette *) gtk_clist_get_row_data (GTK_CLIST (palette_dialog->clist), row); - - /* Go through each palette and merge the colors */ - for (cols = palette->colors; cols; cols = g_list_next (cols)) - { - entry = (GimpPaletteEntry *) cols->data; - - gimp_palette_add_entry (new_palette, - entry->name, - &entry->color); - } - sel_list = sel_list->next; - } - - gimp_container_add (global_palette_factory->container, - GIMP_OBJECT (new_palette)); - - /* update all dialogs */ - palette_insert_all (new_palette); -} - static void palette_dialog_merge_callback (GtkWidget *widget, gpointer data) @@ -1410,51 +1303,56 @@ palette_dialog_merge_callback (GtkWidget *widget, _("Enter a name for merged palette"), NULL, NULL, NULL, - palette_dialog_merge_entries_callback, + palette_dialog_do_merge_callback, data); gtk_widget_show (qbox); } -/* the palette & palette edit action area callbacks ************************/ - static void -palette_dialog_save_callback (GtkWidget *widget, - gpointer data) +palette_dialog_do_merge_callback (GtkWidget *widget, + gchar *palette_name, + gpointer data) { - g_warning ("%s(): TODO", G_GNUC_FUNCTION); + PaletteDialog *palette_dialog; + GimpPalette *palette; + GimpPalette *new_palette; + GimpPaletteEntry *entry; + GList *sel_list; - /* - palette_save_palettes (); - */ -} - -static void -palette_dialog_refresh_callback (GtkWidget *widget, - gpointer data) -{ - palette_refresh_all (); -} - -static void -palette_dialog_edit_callback (GtkWidget *widget, - gpointer data) -{ - GimpPalette *palette = NULL; - PaletteDialog *palette_dialog; - GList *sel_list; + new_palette = GIMP_PALETTE (gimp_palette_new (palette_name)); palette_dialog = (PaletteDialog *) data; - sel_list = GTK_CLIST (palette_dialog->clist)->selection; + sel_list = GTK_LIST (GIMP_CONTAINER_LIST_VIEW (GIMP_DATA_FACTORY_VIEW (palette_dialog->view)->view)->gtk_list)->selection; - if (sel_list) + while (sel_list) { - palette = - (GimpPalette *) gtk_clist_get_row_data (GTK_CLIST (palette_dialog->clist), - GPOINTER_TO_INT (sel_list->data)); + GtkWidget *list_item; + GList *cols; + + list_item = GTK_WIDGET (sel_list->data); + + palette = (GimpPalette *) + GIMP_PREVIEW (gtk_object_get_data (GTK_OBJECT (list_item), + "preview"))->viewable; + + if (palette) + { + for (cols = palette->colors; cols; cols = g_list_next (cols)) + { + entry = (GimpPaletteEntry *) cols->data; + + gimp_palette_add_entry (new_palette, + entry->name, + &entry->color); + } + } + + sel_list = sel_list->next; } - palette_create_edit (palette); + gimp_container_add (global_palette_factory->container, + GIMP_OBJECT (new_palette)); } static void @@ -1494,7 +1392,9 @@ palette_dialog_drag_color (GtkWidget *widget, palette_dialog = (PaletteDialog *) data; - if (palette_dialog && palette_dialog->palette && palette_dialog->dnd_color) + if (palette_dialog && + gimp_context_get_palette (palette_dialog->context) && + palette_dialog->dnd_color) { *color = palette_dialog->dnd_color->color; } @@ -1513,283 +1413,32 @@ palette_dialog_drop_color (GtkWidget *widget, palette_dialog = (PaletteDialog *) data; - if (palette_dialog && palette_dialog->palette) + if (palette_dialog && gimp_context_get_palette (palette_dialog->context)) { - palette_dialog->color = gimp_palette_add_entry (palette_dialog->palette, - NULL, - (GimpRGB *) color); - - palette_update_all (palette_dialog->palette); + palette_dialog->color = + gimp_palette_add_entry (gimp_context_get_palette (palette_dialog->context), + NULL, + (GimpRGB *) color); } } -/* the palette & palette edit dialog constructor ***************************/ - -PaletteDialog * -palette_dialog_new (gboolean editor) +static void +palette_dialog_invalidate_preview (GimpPalette *palette, + PaletteDialog *palette_dialog) { - PaletteDialog *palette_dialog; - GtkWidget *hbox; - GtkWidget *hbox2; - GtkWidget *vbox; - GtkWidget *scrolledwindow; - GtkWidget *palette_region; - GtkWidget *entry; - GtkWidget *eventbox; - GtkWidget *alignment; - GtkWidget *frame; - GtkWidget *button; - gchar *titles[3]; - - palette_dialog = g_new0 (PaletteDialog, 1); - palette_dialog->palette = default_palette_entries; - palette_dialog->zoom_factor = 1.0; - palette_dialog->columns = COLUMNS; - palette_dialog->columns_valid = TRUE; - palette_dialog->freeze_update = FALSE; - - if (!editor) + if (palette == gimp_context_get_palette (palette_dialog->context)) { - palette_dialog->shell = - gimp_dialog_new (_("Color Palette Edit"), "color_palette_edit", - gimp_standard_help_func, - "dialogs/palette_editor/palette_editor.html", - GTK_WIN_POS_NONE, - FALSE, TRUE, FALSE, - - _("Save"), palette_dialog_save_callback, - palette_dialog, NULL, NULL, FALSE, FALSE, - _("Refresh"), palette_dialog_refresh_callback, - palette_dialog, NULL, NULL, FALSE, FALSE, - _("Close"), palette_dialog_close_callback, - palette_dialog, NULL, NULL, TRUE, TRUE, - - NULL); + palette_dialog->columns_valid = FALSE; + palette_dialog_redraw (palette_dialog); } - else - { - palette_dialog->shell = - gimp_dialog_new (_("Color Palette"), "color_palette", - gimp_standard_help_func, - "dialogs/palette_selection.html", - GTK_WIN_POS_NONE, - FALSE, TRUE, FALSE, - - _("Edit"), palette_dialog_edit_callback, - palette_dialog, NULL, NULL, FALSE, FALSE, - _("Close"), palette_dialog_close_callback, - palette_dialog, NULL, NULL, TRUE, TRUE, - - NULL); - } - - /* The main container widget */ - if (editor) - { - hbox = gtk_notebook_new (); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 1); - } - else - { - hbox = gtk_hbox_new (FALSE, 4); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 4); - } - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (palette_dialog->shell)->vbox), - hbox); - gtk_widget_show (hbox); - - vbox = gtk_vbox_new (FALSE, 2); - gtk_widget_show (vbox); - - palette_dialog->scrolled_window = - scrolledwindow = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_ALWAYS); - gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0); - gtk_widget_show (scrolledwindow); - - eventbox = gtk_event_box_new (); - gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledwindow), - eventbox); - gtk_signal_connect (GTK_OBJECT (eventbox), "button_press_event", - GTK_SIGNAL_FUNC (palette_dialog_eventbox_button_press), - palette_dialog); - gtk_widget_show (eventbox); - - alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); - gtk_container_add (GTK_CONTAINER (eventbox), alignment); - gtk_widget_show (alignment); - - palette_dialog->color_area = palette_region = - gtk_preview_new (GTK_PREVIEW_COLOR); - gtk_preview_set_dither (GTK_PREVIEW (palette_dialog->color_area), - GDK_RGB_DITHER_MAX); - gtk_preview_size (GTK_PREVIEW (palette_region), PREVIEW_WIDTH, PREVIEW_HEIGHT); - - gtk_widget_set_events (palette_region, PALETTE_EVENT_MASK); - gtk_signal_connect (GTK_OBJECT (palette_dialog->color_area), "event", - GTK_SIGNAL_FUNC (palette_dialog_color_area_events), - palette_dialog); - - gtk_container_add (GTK_CONTAINER (alignment), palette_region); - gtk_widget_show (palette_region); - - /* dnd stuff */ - gtk_drag_source_set (palette_region, - GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, - color_palette_target_table, n_color_palette_targets, - GDK_ACTION_COPY | GDK_ACTION_MOVE); - gimp_dnd_color_source_set (palette_region, palette_dialog_drag_color, - palette_dialog); - - gtk_drag_dest_set (alignment, - GTK_DEST_DEFAULT_HIGHLIGHT | - GTK_DEST_DEFAULT_MOTION | - GTK_DEST_DEFAULT_DROP, - color_palette_target_table, n_color_palette_targets, - GDK_ACTION_COPY); - gimp_dnd_color_dest_set (alignment, palette_dialog_drop_color, palette_dialog); - - /* The color name entry */ - hbox2 = gtk_hbox_new (FALSE, 2); - gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0); - gtk_widget_show (hbox2); - - entry = palette_dialog->color_name = gtk_entry_new (); - gtk_widget_show (entry); - gtk_box_pack_start (GTK_BOX (hbox2), entry, TRUE, TRUE, 0); - gtk_entry_set_text (GTK_ENTRY (entry), _("Undefined")); - gtk_widget_set_sensitive (entry, FALSE); - palette_dialog->entry_sig_id = - gtk_signal_connect (GTK_OBJECT (entry), "changed", - GTK_SIGNAL_FUNC (palette_dialog_color_name_entry_changed), - palette_dialog); - - /* + and - buttons */ - button = gimp_pixmap_button_new (zoom_in_xpm, NULL); - gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_zoomin_callback), - palette_dialog); - gtk_widget_show (button); - - button = gimp_pixmap_button_new (zoom_out_xpm, NULL); - gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_zoomout_callback), - palette_dialog); - gtk_widget_show (button); - - /* clist preview of palettes */ - scrolledwindow = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_ALWAYS); - - if (editor) - { - gtk_notebook_append_page (GTK_NOTEBOOK (hbox), vbox, - gtk_label_new (_("Palette"))); - gtk_notebook_append_page (GTK_NOTEBOOK (hbox), scrolledwindow, - gtk_label_new (_("Select"))); - } - else - { - gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (hbox), scrolledwindow, TRUE, TRUE, 0); - } - - gtk_widget_show (scrolledwindow); - - titles[0] = _("Palette"); - titles[1] = _("Ncols"); - titles[2] = _("Name"); - palette_dialog->clist = gtk_clist_new_with_titles (3, titles); - gtk_widget_set_usize (palette_dialog->clist, 203, 203); - gtk_clist_set_row_height (GTK_CLIST (palette_dialog->clist), - SM_PREVIEW_HEIGHT + 2); - gtk_clist_set_column_width (GTK_CLIST (palette_dialog->clist), 0, - SM_PREVIEW_WIDTH+2); - gtk_clist_column_titles_passive (GTK_CLIST (palette_dialog->clist)); - gtk_container_add (GTK_CONTAINER (scrolledwindow), palette_dialog->clist); - - if (!editor) - gtk_clist_set_selection_mode (GTK_CLIST (palette_dialog->clist), - GTK_SELECTION_EXTENDED); - - gtk_signal_connect (GTK_OBJECT (palette_dialog->clist), "select_row", - GTK_SIGNAL_FUNC (palette_dialog_list_item_update), - (gpointer) palette_dialog); - gtk_widget_show (palette_dialog->clist); - - if (!editor) - { - frame = gtk_frame_new (_("Palette Ops")); - gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0); - gtk_widget_show (frame); - - vbox = gtk_vbox_new (FALSE, 2); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); - gtk_container_add (GTK_CONTAINER (frame), vbox); - gtk_widget_show (vbox); - - button = gtk_button_new_with_label (_("New")); - GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); - gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_new_callback), - palette_dialog); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gimp_help_set_help_data (button, NULL, - "dialogs/palette_editor/new_palette.html"); - gtk_widget_show (button); - - button = gtk_button_new_with_label (_("Delete")); - GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); - gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_delete_callback), - palette_dialog); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gimp_help_set_help_data (button, NULL, - "dialogs/palette_editor/delete_palette.html"); - gtk_widget_show (button); - - button = gtk_button_new_with_label (_("Import")); - GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); - gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_import_callback), - palette_dialog); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gimp_help_set_help_data (button, NULL, - "dialogs/palette_editor/import_palette.html"); - gtk_widget_show (button); - - button = gtk_button_new_with_label (_("Merge")); - GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); - gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_merge_callback), - palette_dialog); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gimp_help_set_help_data (button, NULL, - "dialogs/palette_editor/merge_palette.html"); - gtk_widget_show (button); - } - - gtk_widget_realize (palette_dialog->shell); - - palette_dialog->gc = gdk_gc_new (palette_dialog->shell->window); - - /* fill the clist */ - palette_clist_init (palette_dialog->clist, - palette_dialog->shell, - palette_dialog->gc); - palette_dialog_clist_scroll_to_current (palette_dialog); - - palette_dialog_create_popup_menu (palette_dialog); - - return palette_dialog; +} + +static void +palette_dialog_edit_palette (GimpData *data) +{ + GimpPalette *palette; + + palette = GIMP_PALETTE (data); + + palette_create_edit (palette); } diff --git a/app/paletteP.h b/app/paletteP.h index 0cc939b84b..10fdc8c3c1 100644 --- a/app/paletteP.h +++ b/app/paletteP.h @@ -20,19 +20,8 @@ #define __PALETTE_P_H__ -void palette_clist_init (GtkWidget *clist, - GtkWidget *shell, - GdkGC *gc); -void palette_clist_insert (GtkWidget *clist, - GtkWidget *shell, - GdkGC *gc, - GimpPalette *palette, - gint pos); - void palette_select_palette_init (void); void palette_create_edit (GimpPalette *palette); -void palette_insert_all (GimpPalette *palette); - #endif /* __PALETTE_P_H__ */ diff --git a/app/palette_import.c b/app/palette_import.c index 1817ee1284..146249e84e 100644 --- a/app/palette_import.c +++ b/app/palette_import.c @@ -573,8 +573,6 @@ palette_import_create_from_grad (gchar *name) gimp_container_add (global_palette_factory->container, GIMP_OBJECT (palette)); - - palette_insert_all (palette); } } @@ -758,8 +756,6 @@ palette_import_image_make_palette (GHashTable *h_array, g_slist_free (sorted_list); gimp_container_add (global_palette_factory->container, GIMP_OBJECT (palette)); - - palette_insert_all (palette); } static void @@ -874,8 +870,6 @@ palette_import_create_from_indexed (GImage *gimage, } gimp_container_add (global_palette_factory->container, GIMP_OBJECT (palette)); - - palette_insert_all (palette); } /* the palette import action area callbacks ********************************/ diff --git a/app/palette_select.c b/app/palette_select.c index 342d20b8a6..020d1dfa16 100644 --- a/app/palette_select.c +++ b/app/palette_select.c @@ -27,31 +27,39 @@ #include "apptypes.h" +#include "appenv.h" #include "context_manager.h" +#include "dialog_handler.h" #include "gimpcontainer.h" +#include "gimpcontext.h" +#include "gimpdatafactoryview.h" #include "gimpdatafactory.h" +#include "gimpdnd.h" #include "gimppalette.h" #include "palette_select.h" #include "palette.h" #include "paletteP.h" +#include "session.h" #include "libgimp/gimpintl.h" +#define STD_PALETTE_COLUMNS 6 +#define STD_PALETTE_ROWS 5 + + /* local function prototypes */ -static gint palette_select_button_press (GtkWidget *widget, - GdkEventButton *bevent, +static void palette_select_drop_palette (GtkWidget *widget, + GimpViewable *viewable, gpointer data); static void palette_select_close_callback (GtkWidget *widget, gpointer data); -static void palette_select_edit_callback (GtkWidget *widget, - gpointer data); +static void palette_select_edit_palette (GimpData *data); /* list of active dialogs */ - -static GSList *active_dialogs = NULL; +static GSList *palette_active_dialogs = NULL; /* public functions */ @@ -60,17 +68,14 @@ PaletteSelect * palette_select_new (const gchar *title, const gchar *initial_palette) { - GimpPalette *palette; PaletteSelect *psp; GtkWidget *vbox; - GtkWidget *hbox; - GtkWidget *scrolled_win; - gchar *titles[3]; - gint select_pos = -1; + GimpPalette *active = NULL; - palette_select_palette_init (); + static gboolean first_call = TRUE; + + psp = g_new0 (PaletteSelect, 1); - psp = g_new (PaletteSelect, 1); psp->callback_name = NULL; /* The shell and main vbox */ @@ -81,182 +86,99 @@ palette_select_new (const gchar *title, GTK_WIN_POS_MOUSE, FALSE, TRUE, FALSE, - _("Edit"), palette_select_edit_callback, - psp, NULL, NULL, TRUE, FALSE, - _("Close"), palette_select_close_callback, + "_delete_event_", palette_select_close_callback, psp, NULL, NULL, FALSE, TRUE, NULL); - vbox = gtk_vbox_new (FALSE, 1); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 1); + gtk_widget_hide (GTK_WIDGET (g_list_nth_data (gtk_container_children (GTK_CONTAINER (GTK_DIALOG (psp->shell)->vbox)), 0))); + + gtk_widget_hide (GTK_DIALOG (psp->shell)->action_area); + + if (title) + { + psp->context = gimp_context_new (title, NULL); + } + else + { + psp->context = gimp_context_get_user (); + + /* + session_set_window_geometry (psp->shell, &palette_select_session_info, + TRUE); + */ + + dialog_register (psp->shell); + } + + if (no_data && first_call) + gimp_data_factory_data_init (global_palette_factory, FALSE); + + first_call = FALSE; + + if (title && initial_palette && strlen (initial_palette)) + { + active = (GimpPalette *) + gimp_container_get_child_by_name (global_palette_factory->container, + initial_palette); + } + else + { + active = gimp_context_get_palette (gimp_context_get_user ()); + } + + if (!active) + active = gimp_context_get_palette (gimp_context_get_standard ()); + + if (title) + gimp_context_set_palette (psp->context, active); + + /* The main vbox */ + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); gtk_container_add (GTK_CONTAINER (GTK_DIALOG (psp->shell)->vbox), vbox); - hbox = gtk_hbox_new (FALSE, 8); - gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); + /* The Palette List */ + psp->view = gimp_data_factory_view_new (GIMP_VIEW_TYPE_LIST, + global_palette_factory, + palette_select_edit_palette, + psp->context, + 64, /* FIXME: SM_PREVIEW_WIDTH */ + 3, /* FIXME: STD_PALETTE_COLUMNS */ + 3); /* FIXME: STD_PALETTE_ROWS */ + gtk_box_pack_start (GTK_BOX (vbox), psp->view, TRUE, TRUE, 0); + gtk_widget_show (psp->view); - /* clist preview of gradients */ - scrolled_win = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_ALWAYS); - gtk_box_pack_start (GTK_BOX (hbox), scrolled_win, TRUE, TRUE, 0); - gtk_widget_show (scrolled_win); + gimp_gtk_drag_dest_set_by_type (psp->view, + GTK_DEST_DEFAULT_ALL, + GIMP_TYPE_PALETTE, + GDK_ACTION_COPY); + gimp_dnd_viewable_dest_set (GTK_WIDGET (psp->view), + GIMP_TYPE_PALETTE, + palette_select_drop_palette, + psp); - titles[0] = _("Palette"); - titles[1] = _("Ncols"); - titles[2] = _("Name"); - psp->clist = gtk_clist_new_with_titles (3, titles); - gtk_clist_set_shadow_type (GTK_CLIST (psp->clist), GTK_SHADOW_IN); - gtk_clist_set_row_height (GTK_CLIST (psp->clist), SM_PREVIEW_HEIGHT + 2); - gtk_clist_set_use_drag_icons (GTK_CLIST (psp->clist), FALSE); - gtk_clist_column_titles_passive (GTK_CLIST (psp->clist)); - gtk_widget_set_usize (psp->clist, 203, 200); - gtk_clist_set_column_width (GTK_CLIST (psp->clist), 0, SM_PREVIEW_WIDTH + 2); - gtk_container_add (GTK_CONTAINER (scrolled_win), psp->clist); - gtk_widget_show (psp->clist); - - palette = (GimpPalette *) - gimp_container_get_child_by_name (global_palette_factory->container, - initial_palette); - - if (palette) - select_pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (palette)); - - gtk_widget_realize (psp->shell); - psp->gc = gdk_gc_new (psp->shell->window); - - palette_clist_init (psp->clist, psp->shell, psp->gc); - gtk_signal_connect (GTK_OBJECT (psp->clist), "button_press_event", - GTK_SIGNAL_FUNC (palette_select_button_press), - (gpointer) psp); - - /* Now show the dialog */ gtk_widget_show (vbox); gtk_widget_show (psp->shell); - if (select_pos != -1) - { - gtk_clist_select_row (GTK_CLIST (psp->clist), select_pos, -1); - gtk_clist_moveto (GTK_CLIST (psp->clist), select_pos, 0, 0.0, 0.0); - } - else - gtk_clist_select_row (GTK_CLIST (psp->clist), 0, -1); - - active_dialogs = g_slist_append (active_dialogs, psp); + palette_active_dialogs = g_slist_append (palette_active_dialogs, psp); return psp; } -void -palette_select_clist_insert_all (GimpPalette *entries) -{ - PaletteSelect *psp; - GSList *list; - gint pos; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (entries)); - - for (list = active_dialogs; list; list = g_slist_next (list)) - { - psp = (PaletteSelect *) list->data; - - gtk_clist_freeze (GTK_CLIST (psp->clist)); - palette_clist_insert (psp->clist, psp->shell, psp->gc, entries, pos); - gtk_clist_thaw (GTK_CLIST (psp->clist)); - } -} - -void -palette_select_set_text_all (GimpPalette *entries) -{ - PaletteSelect *psp; - GSList *list; - gchar *num_buf; - gint pos; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (entries)); - - num_buf = g_strdup_printf ("%d", entries->n_colors); - - for (list = active_dialogs; list; list = g_slist_next (list)) - { - psp = (PaletteSelect *) list->data; - - gtk_clist_set_text (GTK_CLIST (psp->clist), pos, 1, num_buf); - } - - g_free (num_buf); -} - -void -palette_select_refresh_all (void) -{ - PaletteSelect *psp; - GSList *list; - - for (list = active_dialogs; list; list = g_slist_next (list)) - { - psp = (PaletteSelect *) list->data; - - gtk_clist_freeze (GTK_CLIST (psp->clist)); - gtk_clist_clear (GTK_CLIST (psp->clist)); - palette_clist_init (psp->clist, psp->shell, psp->gc); - gtk_clist_thaw (GTK_CLIST (psp->clist)); - } -} /* local functions */ -static gint -palette_select_button_press (GtkWidget *widget, - GdkEventButton *bevent, - gpointer data) -{ - PaletteSelect *psp; - - psp = (PaletteSelect *) data; - - if (bevent->button == 1 && bevent->type == GDK_2BUTTON_PRESS) - { - palette_select_edit_callback (widget, data); - - return TRUE; - } - - return FALSE; -} - static void -palette_select_edit_callback (GtkWidget *widget, - gpointer data) +palette_select_drop_palette (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) { - GimpPalette *p_entries = NULL; PaletteSelect *psp; - GList *sel_list; psp = (PaletteSelect *) data; - sel_list = GTK_CLIST (psp->clist)->selection; - - while (sel_list) - { - gint row; - - row = GPOINTER_TO_INT (sel_list->data); - - p_entries = - (GimpPalette *) gtk_clist_get_row_data (GTK_CLIST (psp->clist), row); - - palette_create_edit (p_entries); - - /* One only */ - return; - } + gimp_context_set_palette (psp->context, GIMP_PALETTE (viewable)); } static void @@ -270,7 +192,7 @@ palette_select_free (PaletteSelect *psp) */ /* remove from active list */ - active_dialogs = g_slist_remove (active_dialogs, psp); + palette_active_dialogs = g_slist_remove (palette_active_dialogs, psp); g_free (psp); } @@ -290,3 +212,13 @@ palette_select_close_callback (GtkWidget *widget, gtk_widget_destroy (psp->shell); palette_select_free (psp); } + +static void +palette_select_edit_palette (GimpData *data) +{ + GimpPalette *palette; + + palette = GIMP_PALETTE (data); + + palette_create_edit (palette); +} diff --git a/app/palette_select.h b/app/palette_select.h index d8774a7b64..3ccab5600e 100644 --- a/app/palette_select.h +++ b/app/palette_select.h @@ -28,19 +28,17 @@ typedef struct _PaletteSelect PaletteSelect; struct _PaletteSelect { - GtkWidget *shell; - GtkWidget *clist; - GdkGC *gc; - gchar *callback_name; + GtkWidget *shell; + GtkWidget *view; + + gchar *callback_name; + + GimpContext *context; }; PaletteSelect * palette_select_new (const gchar *title, const gchar *initial_palette); -void palette_select_clist_insert_all (GimpPalette *palette); -void palette_select_set_text_all (GimpPalette *palette); -void palette_select_refresh_all (void); - #endif /* __PALETTE_SELECT_H__ */ diff --git a/app/pattern_select.c b/app/pattern_select.c index ca907d509b..68b5ce387b 100644 --- a/app/pattern_select.c +++ b/app/pattern_select.c @@ -30,10 +30,9 @@ #include "context_manager.h" #include "dialog_handler.h" #include "gimpcontainer.h" -#include "gimpdatafactoryview.h" #include "gimpcontext.h" +#include "gimpdatafactoryview.h" #include "gimpdatafactory.h" -#include "gimpdnd.h" #include "gimppattern.h" #include "pattern_select.h" #include "session.h" @@ -53,9 +52,6 @@ static void pattern_select_change_callbacks (PatternSelect *psp, gboolean closing); -static void pattern_select_drop_pattern (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); static void pattern_select_pattern_changed (GimpContext *context, GimpPattern *pattern, PatternSelect *psp); @@ -209,15 +205,6 @@ pattern_select_new (gchar *title, gtk_box_pack_start (GTK_BOX (vbox), psp->view, TRUE, TRUE, 0); gtk_widget_show (psp->view); - gimp_gtk_drag_dest_set_by_type (psp->view, - GTK_DEST_DEFAULT_ALL, - GIMP_TYPE_PATTERN, - GDK_ACTION_COPY); - gimp_dnd_viewable_dest_set (GTK_WIDGET (psp->view), - GIMP_TYPE_PATTERN, - pattern_select_drop_pattern, - psp); - gtk_widget_show (vbox); /* add callbacks to keep the display area current */ @@ -353,19 +340,6 @@ pattern_select_dialogs_check (void) * Local functions */ -static void -pattern_select_drop_pattern (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - PatternSelect *psp; - - psp = (PatternSelect *) data; - - gimp_context_set_pattern (psp->context, GIMP_PATTERN (viewable)); -} - - static void pattern_select_pattern_changed (GimpContext *context, GimpPattern *pattern, diff --git a/app/widgets/gimpbrushpreview.c b/app/widgets/gimpbrushpreview.c index c3f012af3b..bc4ae1f20d 100644 --- a/app/widgets/gimpbrushpreview.c +++ b/app/widgets/gimpbrushpreview.c @@ -41,8 +41,8 @@ static GtkWidget * gimp_brush_preview_create_popup (GimpPreview *preview) static gboolean gimp_brush_preview_needs_popup (GimpPreview *preview); static gboolean gimp_brush_preview_render_timeout_func (GimpBrushPreview *preview); -static GimpBrush * gimp_brush_preview_drag_brush (GtkWidget *widget, - gpointer data); +static GimpViewable * gimp_brush_preview_drag_viewable (GtkWidget *widget, + gpointer data); static GimpPreviewClass *parent_class = NULL; @@ -94,20 +94,14 @@ gimp_brush_preview_class_init (GimpBrushPreviewClass *klass) static void gimp_brush_preview_init (GimpBrushPreview *brush_preview) { - static GtkTargetEntry preview_target_table[] = - { - GIMP_TARGET_BRUSH - }; - static guint preview_n_targets = (sizeof (preview_target_table) / - sizeof (preview_target_table[0])); - - gtk_drag_source_set (GTK_WIDGET (brush_preview), - GDK_BUTTON2_MASK, - preview_target_table, preview_n_targets, - GDK_ACTION_COPY); - gimp_dnd_brush_source_set (GTK_WIDGET (brush_preview), - gimp_brush_preview_drag_brush, - brush_preview); + gimp_gtk_drag_source_set_by_type (GTK_WIDGET (brush_preview), + GDK_BUTTON2_MASK, + GIMP_TYPE_BRUSH, + GDK_ACTION_COPY); + gimp_dnd_viewable_source_set (GTK_WIDGET (brush_preview), + GIMP_TYPE_BRUSH, + gimp_brush_preview_drag_viewable, + NULL); brush_preview->pipe_timeout_id = 0; brush_preview->pipe_animation_index = 0; @@ -379,13 +373,9 @@ gimp_brush_preview_render_timeout_func (GimpBrushPreview *brush_preview) return TRUE; } -static GimpBrush * -gimp_brush_preview_drag_brush (GtkWidget *widget, - gpointer data) +static GimpViewable * +gimp_brush_preview_drag_viewable (GtkWidget *widget, + gpointer data) { - GimpPreview *preview; - - preview = GIMP_PREVIEW (data); - - return GIMP_BRUSH (preview->viewable); + return GIMP_PREVIEW (widget)->viewable; } diff --git a/app/widgets/gimpcontainergridview.c b/app/widgets/gimpcontainergridview.c index 3d052d2fa6..94fe259cb2 100644 --- a/app/widgets/gimpcontainergridview.c +++ b/app/widgets/gimpcontainergridview.c @@ -54,6 +54,8 @@ static void gimp_container_grid_view_clear_items (GimpContainerView *v static void gimp_container_grid_view_set_preview_size (GimpContainerView *view); static void gimp_container_grid_view_item_selected (GtkWidget *widget, gpointer data); +static void gimp_container_grid_view_item_activate (GtkWidget *widget, + gpointer data); static void gimp_container_grid_view_highlight_item (GimpContainerView *view, GimpViewable *viewable, gpointer insert_data); @@ -237,6 +239,10 @@ gimp_container_grid_view_insert_item (GimpContainerView *view, GTK_SIGNAL_FUNC (gimp_container_grid_view_item_selected), view); + gtk_signal_connect (GTK_OBJECT (preview), "double_clicked", + GTK_SIGNAL_FUNC (gimp_container_grid_view_item_activate), + view); + return (gpointer) preview; } @@ -338,6 +344,14 @@ gimp_container_grid_view_item_selected (GtkWidget *widget, GIMP_PREVIEW (widget)->viewable); } +static void +gimp_container_grid_view_item_activate (GtkWidget *widget, + gpointer data) +{ + gimp_container_view_item_activate (GIMP_CONTAINER_VIEW (data), + GIMP_PREVIEW (widget)->viewable); +} + static void gimp_container_grid_view_highlight_item (GimpContainerView *view, GimpViewable *viewable, diff --git a/app/widgets/gimpcontainerlistview.c b/app/widgets/gimpcontainerlistview.c index 36708b9165..853046ba75 100644 --- a/app/widgets/gimpcontainerlistview.c +++ b/app/widgets/gimpcontainerlistview.c @@ -28,6 +28,7 @@ #include "gimpcontainer.h" #include "gimpcontainerlistview.h" #include "gimpcontext.h" +#include "gimpdnd.h" #include "gimplist.h" #include "gimppreview.h" @@ -57,6 +58,11 @@ static void gimp_container_list_view_name_changed (GimpViewable *v static void gimp_container_list_view_item_selected (GtkWidget *widget, GtkWidget *child, gpointer data); +static gint gimp_container_list_view_item_activate (GtkWidget *widget, + GdkEventButton *bevent, + gpointer data); +static GimpViewable * gimp_container_list_view_drag_viewable (GtkWidget *widget, + gpointer data); static GimpContainerViewClass *parent_class = NULL; @@ -236,6 +242,19 @@ gimp_container_list_view_insert_item (GimpContainerView *view, label, GTK_OBJECT (list_view)); + gtk_signal_connect (GTK_OBJECT (list_item), "button_press_event", + GTK_SIGNAL_FUNC (gimp_container_list_view_item_activate), + list_view); + + gimp_gtk_drag_source_set_by_type (list_item, + GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, + view->container->children_type, + GDK_ACTION_COPY); + gimp_dnd_viewable_source_set (GTK_WIDGET (list_item), + view->container->children_type, + gimp_container_list_view_drag_viewable, + list_view); + gtk_widget_show (list_item); list = g_list_prepend (NULL, list_item); @@ -417,6 +436,35 @@ gimp_container_list_view_item_selected (GtkWidget *widget, viewable = GIMP_PREVIEW (gtk_object_get_data (GTK_OBJECT (child), "preview"))->viewable; - gimp_container_view_item_selected (GIMP_CONTAINER_VIEW (data), - viewable); + gimp_container_view_item_selected (GIMP_CONTAINER_VIEW (data), viewable); +} + +static gint +gimp_container_list_view_item_activate (GtkWidget *widget, + GdkEventButton *bevent, + gpointer data) +{ + if (bevent->type == GDK_2BUTTON_PRESS) + { + GimpViewable *viewable; + + viewable = GIMP_PREVIEW (gtk_object_get_data (GTK_OBJECT (widget), + "preview"))->viewable; + + gimp_container_view_item_activate (GIMP_CONTAINER_VIEW (data), viewable); + } + + return FALSE; +} + +static GimpViewable * +gimp_container_list_view_drag_viewable (GtkWidget *widget, + gpointer data) +{ + GimpViewable *viewable; + + viewable = GIMP_PREVIEW (gtk_object_get_data (GTK_OBJECT (widget), + "preview"))->viewable; + + return viewable; } diff --git a/app/widgets/gimpcontainerview.c b/app/widgets/gimpcontainerview.c index 52a1f582a7..e8055123c8 100644 --- a/app/widgets/gimpcontainerview.c +++ b/app/widgets/gimpcontainerview.c @@ -25,6 +25,7 @@ #include "gimpcontainer.h" #include "gimpcontainerview.h" #include "gimpcontext.h" +#include "gimpdnd.h" #include "gimpmarshal.h" #include "gimpviewable.h" @@ -35,6 +36,7 @@ enum REMOVE_ITEM, REORDER_ITEM, SELECT_ITEM, + ACTIVATE_ITEM, CLEAR_ITEMS, SET_PREVIEW_SIZE, LAST_SIGNAL @@ -64,6 +66,9 @@ static void gimp_container_view_reorder (GimpContainerView *view, static void gimp_container_view_context_changed (GimpContext *context, GimpViewable *viewable, GimpContainerView *view); +static void gimp_container_view_drop_viewable_callback (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); static guint view_signals[LAST_SIGNAL] = { 0 }; @@ -150,6 +155,17 @@ gimp_container_view_class_init (GimpContainerViewClass *klass) GIMP_TYPE_OBJECT, GTK_TYPE_POINTER); + view_signals[ACTIVATE_ITEM] = + gtk_signal_new ("activate_item", + GTK_RUN_FIRST, + object_class->type, + GTK_SIGNAL_OFFSET (GimpContainerViewClass, + activate_item), + gtk_marshal_NONE__POINTER_POINTER, + GTK_TYPE_NONE, 2, + GIMP_TYPE_OBJECT, + GTK_TYPE_POINTER); + view_signals[CLEAR_ITEMS] = gtk_signal_new ("clear_items", GTK_RUN_FIRST, @@ -176,6 +192,7 @@ gimp_container_view_class_init (GimpContainerViewClass *klass) klass->remove_item = NULL; klass->reorder_item = NULL; klass->select_item = NULL; + klass->activate_item = NULL; klass->clear_items = gimp_container_view_real_clear_items; klass->set_preview_size = NULL; } @@ -244,6 +261,10 @@ gimp_container_view_set_container (GimpContainerView *view, gtk_signal_disconnect_by_func (GTK_OBJECT (view->context), gimp_container_view_context_changed, view); + + gtk_drag_dest_unset (GTK_WIDGET (view)); + gimp_dnd_viewable_dest_unset (GTK_WIDGET (view), + view->container->children_type); } } @@ -285,6 +306,15 @@ gimp_container_view_set_container (GimpContainerView *view, gimp_container_view_select_item (view, object ? GIMP_VIEWABLE (object): NULL); + + 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, + gimp_container_view_drop_viewable_callback, + NULL); } } } @@ -305,6 +335,10 @@ gimp_container_view_set_context (GimpContainerView *view, gtk_signal_disconnect_by_func (GTK_OBJECT (view->context), gimp_container_view_context_changed, view); + + gtk_drag_dest_unset (GTK_WIDGET (view)); + gimp_dnd_viewable_dest_unset (GTK_WIDGET (view), + view->container->children_type); } view->context = context; @@ -326,6 +360,15 @@ gimp_container_view_set_context (GimpContainerView *view, gimp_container_view_select_item (view, object ? GIMP_VIEWABLE (object) : NULL); + + 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, + gimp_container_view_drop_viewable_callback, + NULL); } } @@ -358,6 +401,23 @@ gimp_container_view_select_item (GimpContainerView *view, viewable, insert_data); } +void +gimp_container_view_activate_item (GimpContainerView *view, + GimpViewable *viewable) +{ + gpointer insert_data; + + g_return_if_fail (view != NULL); + g_return_if_fail (GIMP_IS_CONTAINER_VIEW (view)); + g_return_if_fail (viewable != NULL); + g_return_if_fail (GIMP_IS_VIEWABLE (viewable)); + + insert_data = g_hash_table_lookup (view->hash_table, viewable); + + gtk_signal_emit (GTK_OBJECT (view), view_signals[ACTIVATE_ITEM], + viewable, insert_data); +} + void gimp_container_view_item_selected (GimpContainerView *view, GimpViewable *viewable) @@ -375,6 +435,18 @@ gimp_container_view_item_selected (GimpContainerView *view, GIMP_OBJECT (viewable)); } +void +gimp_container_view_item_activate (GimpContainerView *view, + GimpViewable *viewable) +{ + g_return_if_fail (view != NULL); + g_return_if_fail (GIMP_IS_CONTAINER_VIEW (view)); + g_return_if_fail (viewable != NULL); + g_return_if_fail (GIMP_IS_VIEWABLE (viewable)); + + gimp_container_view_activate_item (view, viewable); +} + static void gimp_container_view_clear_items (GimpContainerView *view) { @@ -465,3 +537,17 @@ gimp_container_view_context_changed (GimpContext *context, gtk_signal_emit (GTK_OBJECT (view), view_signals[SELECT_ITEM], viewable, insert_data); } + +static void +gimp_container_view_drop_viewable_callback (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) +{ + GimpContainerView *view; + + view = GIMP_CONTAINER_VIEW (widget); + + gimp_context_set_by_type (view->context, + view->container->children_type, + GIMP_OBJECT (viewable)); +} diff --git a/app/widgets/gimpcontainerview.h b/app/widgets/gimpcontainerview.h index 5e248d7a17..cb4f11d005 100644 --- a/app/widgets/gimpcontainerview.h +++ b/app/widgets/gimpcontainerview.h @@ -61,6 +61,9 @@ struct _GimpContainerViewClass void (* select_item) (GimpContainerView *view, GimpViewable *object, gpointer insert_data); + void (* activate_item) (GimpContainerView *view, + GimpViewable *object, + gpointer insert_data); void (* clear_items) (GimpContainerView *view); void (* set_preview_size) (GimpContainerView *view); }; @@ -76,12 +79,16 @@ void gimp_container_view_set_preview_size (GimpContainerView *view, gint preview_size); void gimp_container_view_select_item (GimpContainerView *view, GimpViewable *viewable); +void gimp_container_view_activate_item (GimpContainerView *view, + GimpViewable *viewable); /* private */ void gimp_container_view_item_selected (GimpContainerView *view, GimpViewable *item); +void gimp_container_view_item_activate (GimpContainerView *view, + GimpViewable *item); #endif /* __GIMP_CONTAINER_VIEW_H__ */ diff --git a/app/widgets/gimpdatafactoryview.c b/app/widgets/gimpdatafactoryview.c index 4049c28142..9567e20807 100644 --- a/app/widgets/gimpdatafactoryview.c +++ b/app/widgets/gimpdatafactoryview.c @@ -32,6 +32,7 @@ #include "gimpcontainergridview.h" #include "gimpcontainerlistview.h" #include "gimpcontext.h" +#include "gimpdnd.h" #include "gimpmarshal.h" #include "gimpviewable.h" @@ -52,16 +53,29 @@ static void gimp_data_factory_view_new_clicked (GtkWidget *wid GimpDataFactoryView *view); static void gimp_data_factory_view_duplicate_clicked (GtkWidget *widget, GimpDataFactoryView *view); +static void gimp_data_factory_view_duplicate_dropped (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); static void gimp_data_factory_view_edit_clicked (GtkWidget *widget, GimpDataFactoryView *view); +static void gimp_data_factory_view_edit_dropped (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); static void gimp_data_factory_view_delete_clicked (GtkWidget *widget, GimpDataFactoryView *view); +static void gimp_data_factory_view_delete_dropped (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); static void gimp_data_factory_view_refresh_clicked (GtkWidget *widget, GimpDataFactoryView *view); static void gimp_data_factory_view_data_changed (GimpContext *context, GimpData *data, GimpDataFactoryView *view); +static void gimp_data_factory_view_data_activate (GtkWidget *context, + GimpData *data, + gpointer insert_data, + GimpDataFactoryView *view); static GtkVBoxClass *parent_class = NULL; @@ -277,6 +291,42 @@ gimp_data_factory_view_new (GimpViewType view_type, factory_view, GTK_OBJECT (factory_view)); + gtk_signal_connect_while_alive + (GTK_OBJECT (factory_view->view), "activate_item", + GTK_SIGNAL_FUNC (gimp_data_factory_view_data_activate), + factory_view, + GTK_OBJECT (factory_view)); + + /* drop to "duplicate" */ + gimp_gtk_drag_dest_set_by_type (GTK_WIDGET (factory_view->duplicate_button), + GTK_DEST_DEFAULT_ALL, + factory_view->factory->container->children_type, + GDK_ACTION_COPY); + gimp_dnd_viewable_dest_set (GTK_WIDGET (factory_view->duplicate_button), + factory_view->factory->container->children_type, + gimp_data_factory_view_duplicate_dropped, + factory_view); + + /* drop to "edit" */ + gimp_gtk_drag_dest_set_by_type (GTK_WIDGET (factory_view->edit_button), + GTK_DEST_DEFAULT_ALL, + factory_view->factory->container->children_type, + GDK_ACTION_COPY); + gimp_dnd_viewable_dest_set (GTK_WIDGET (factory_view->edit_button), + factory_view->factory->container->children_type, + gimp_data_factory_view_edit_dropped, + factory_view); + + /* drop to "delete" */ + gimp_gtk_drag_dest_set_by_type (GTK_WIDGET (factory_view->delete_button), + GTK_DEST_DEFAULT_ALL, + factory_view->factory->container->children_type, + GDK_ACTION_COPY); + gimp_dnd_viewable_dest_set (GTK_WIDGET (factory_view->delete_button), + factory_view->factory->container->children_type, + gimp_data_factory_view_delete_dropped, + factory_view); + /* set button sensitivity */ gimp_data_factory_view_data_changed (context, @@ -346,6 +396,26 @@ gimp_data_factory_view_duplicate_clicked (GtkWidget *widget, } } +static void +gimp_data_factory_view_duplicate_dropped (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) +{ + GimpDataFactoryView *view; + + view = (GimpDataFactoryView *) data; + + if (viewable && gimp_container_have (view->factory->container, + GIMP_OBJECT (viewable))) + { + gimp_context_set_by_type (view->view->context, + view->factory->container->children_type, + GIMP_OBJECT (viewable)); + + gimp_data_factory_view_duplicate_clicked (NULL, data); + } +} + static void gimp_data_factory_view_edit_clicked (GtkWidget *widget, GimpDataFactoryView *view) @@ -365,6 +435,26 @@ gimp_data_factory_view_edit_clicked (GtkWidget *widget, } } +static void +gimp_data_factory_view_edit_dropped (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) +{ + GimpDataFactoryView *view; + + view = (GimpDataFactoryView *) data; + + if (viewable && gimp_container_have (view->factory->container, + GIMP_OBJECT (viewable))) + { + gimp_context_set_by_type (view->view->context, + view->factory->container->children_type, + GIMP_OBJECT (viewable)); + + gimp_data_factory_view_edit_clicked (NULL, data); + } +} + typedef struct _GimpDataDeleteData GimpDataDeleteData; @@ -444,6 +534,26 @@ gimp_data_factory_view_delete_clicked (GtkWidget *widget, } } +static void +gimp_data_factory_view_delete_dropped (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) +{ + GimpDataFactoryView *view; + + view = (GimpDataFactoryView *) data; + + if (viewable && gimp_container_have (view->factory->container, + GIMP_OBJECT (viewable))) + { + gimp_context_set_by_type (view->view->context, + view->factory->container->children_type, + GIMP_OBJECT (viewable)); + + gimp_data_factory_view_delete_clicked (NULL, data); + } +} + static void gimp_data_factory_view_refresh_clicked (GtkWidget *widget, GimpDataFactoryView *view) @@ -466,11 +576,24 @@ gimp_data_factory_view_data_changed (GimpContext *context, duplicate_sensitive = (GIMP_DATA_CLASS (GTK_OBJECT (data)->klass)->duplicate != NULL); - edit_sensitive = (view->data_edit_func != NULL); - delete_sensitive = TRUE; /* TODO: check permissions */ + edit_sensitive = (view->data_edit_func != NULL); + delete_sensitive = TRUE; /* TODO: check permissions */ } gtk_widget_set_sensitive (view->duplicate_button, duplicate_sensitive); gtk_widget_set_sensitive (view->edit_button, edit_sensitive); gtk_widget_set_sensitive (view->delete_button, delete_sensitive); } + +static void +gimp_data_factory_view_data_activate (GtkWidget *widget, + GimpData *data, + gpointer insert_data, + GimpDataFactoryView *view) +{ + if (data && gimp_container_have (view->factory->container, + GIMP_OBJECT (data))) + { + gimp_data_factory_view_edit_clicked (NULL, view); + } +} diff --git a/app/widgets/gimpdnd.c b/app/widgets/gimpdnd.c index 871a738693..d9053f841c 100644 --- a/app/widgets/gimpdnd.c +++ b/app/widgets/gimpdnd.c @@ -624,6 +624,79 @@ gimp_dnd_color_dest_unset (GtkWidget *widget) /* GimpViewable (by GtkType) dnd functions */ /*********************************************/ +static const GtkTargetEntry brush_target_table[] = +{ + GIMP_TARGET_BRUSH +}; +static const guint brush_n_targets = (sizeof (brush_target_table) / + sizeof (brush_target_table[0])); + +static const GtkTargetEntry pattern_target_table[] = +{ + GIMP_TARGET_PATTERN +}; +static const guint pattern_n_targets = (sizeof (pattern_target_table) / + sizeof (pattern_target_table[0])); + +static const GtkTargetEntry gradient_target_table[] = +{ + GIMP_TARGET_GRADIENT +}; +static const guint gradient_n_targets = (sizeof (gradient_target_table) / + sizeof (gradient_target_table[0])); + +static const GtkTargetEntry palette_target_table[] = +{ + GIMP_TARGET_PALETTE +}; +static const guint palette_n_targets = (sizeof (palette_target_table) / + sizeof (palette_target_table[0])); + + +void +gimp_gtk_drag_source_set_by_type (GtkWidget *widget, + GdkModifierType start_button_mask, + GtkType type, + GdkDragAction actions) +{ + const GtkTargetEntry *target_table = NULL; + guint n_targets = 0; + + if (type == GIMP_TYPE_BRUSH) + { + target_table = brush_target_table; + n_targets = brush_n_targets; + } + else if (type == GIMP_TYPE_PATTERN) + { + target_table = pattern_target_table; + n_targets = pattern_n_targets; + } + else if (type == GIMP_TYPE_GRADIENT) + { + target_table = gradient_target_table; + n_targets = gradient_n_targets; + } + else if (type == GIMP_TYPE_PALETTE) + { + target_table = palette_target_table; + n_targets = palette_n_targets; + } + else + { + g_warning ("%s(): unsupported GtkType", G_GNUC_FUNCTION); + } + + if (target_table && n_targets) + { + gtk_drag_source_set (widget, start_button_mask, + target_table, + n_targets, + actions); + } + +} + void gimp_gtk_drag_dest_set_by_type (GtkWidget *widget, GtkDestDefaults flags, @@ -633,34 +706,6 @@ gimp_gtk_drag_dest_set_by_type (GtkWidget *widget, const GtkTargetEntry *target_table = NULL; guint n_targets = 0; - static const GtkTargetEntry brush_target_table[] = - { - GIMP_TARGET_BRUSH - }; - static const guint brush_n_targets = (sizeof (brush_target_table) / - sizeof (brush_target_table[0])); - - static const GtkTargetEntry pattern_target_table[] = - { - GIMP_TARGET_PATTERN - }; - static const guint pattern_n_targets = (sizeof (pattern_target_table) / - sizeof (pattern_target_table[0])); - - static const GtkTargetEntry gradient_target_table[] = - { - GIMP_TARGET_GRADIENT - }; - static const guint gradient_n_targets = (sizeof (gradient_target_table) / - sizeof (gradient_target_table[0])); - - static const GtkTargetEntry palette_target_table[] = - { - GIMP_TARGET_PALETTE - }; - static const guint palette_n_targets = (sizeof (palette_target_table) / - sizeof (palette_target_table[0])); - if (type == GIMP_TYPE_BRUSH) { target_table = brush_target_table; @@ -695,6 +740,42 @@ gimp_gtk_drag_dest_set_by_type (GtkWidget *widget, } } +void +gimp_dnd_viewable_source_set (GtkWidget *widget, + GtkType type, + GimpDndDragViewableFunc get_viewable_func, + gpointer data) +{ + if (type == GIMP_TYPE_BRUSH) + { + gimp_dnd_brush_source_set (widget, + (GimpDndDragBrushFunc) get_viewable_func, + data); + } + else if (type == GIMP_TYPE_PATTERN) + { + gimp_dnd_pattern_source_set (widget, + (GimpDndDragPatternFunc) get_viewable_func, + data); + } + else if (type == GIMP_TYPE_GRADIENT) + { + gimp_dnd_gradient_source_set (widget, + (GimpDndDragGradientFunc) get_viewable_func, + data); + } + else if (type == GIMP_TYPE_PALETTE) + { + gimp_dnd_palette_source_set (widget, + (GimpDndDragPaletteFunc) get_viewable_func, + data); + } + else + { + g_warning ("%s(): unsupported GtkType", G_GNUC_FUNCTION); + } +} + void gimp_dnd_viewable_dest_set (GtkWidget *widget, GtkType type, diff --git a/app/widgets/gimpdnd.h b/app/widgets/gimpdnd.h index 3ee82f1051..4f4707b76b 100644 --- a/app/widgets/gimpdnd.h +++ b/app/widgets/gimpdnd.h @@ -113,20 +113,31 @@ void gimp_dnd_color_dest_unset (GtkWidget *widget); /* GimpViewable (by GtkType) dnd functions */ -typedef void (* GimpDndDropViewableFunc) (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); +typedef void (* GimpDndDropViewableFunc) (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); +typedef GimpViewable * (* GimpDndDragViewableFunc) (GtkWidget *widget, + gpointer data); -void gimp_gtk_drag_dest_set_by_type (GtkWidget *widget, - GtkDestDefaults flags, - GtkType type, - GdkDragAction actions); -void gimp_dnd_viewable_dest_set (GtkWidget *widget, - GtkType type, - GimpDndDropViewableFunc set_viewable_func, - gpointer data); -void gimp_dnd_viewable_dest_unset (GtkWidget *widget, - GtkType type); +void gimp_gtk_drag_source_set_by_type (GtkWidget *widget, + GdkModifierType start_button_mask, + GtkType type, + GdkDragAction actions); +void gimp_gtk_drag_dest_set_by_type (GtkWidget *widget, + GtkDestDefaults flags, + GtkType type, + GdkDragAction actions); + +void gimp_dnd_viewable_source_set (GtkWidget *widget, + GtkType type, + GimpDndDragViewableFunc get_viewable_func, + gpointer data); +void gimp_dnd_viewable_dest_set (GtkWidget *widget, + GtkType type, + GimpDndDropViewableFunc set_viewable_func, + gpointer data); +void gimp_dnd_viewable_dest_unset (GtkWidget *widget, + GtkType type); /* brush dnd functions */ diff --git a/app/widgets/gimpgradienteditor.c b/app/widgets/gimpgradienteditor.c index 7733e8e803..c35c59e5fb 100644 --- a/app/widgets/gimpgradienteditor.c +++ b/app/widgets/gimpgradienteditor.c @@ -2933,7 +2933,8 @@ cpopup_adjust_blending_menu (GradientEditor *gradient_editor) for (i = 0; i < num_items; i++) gtk_signal_handler_block_by_data - (GTK_OBJECT (gradient_editor->control_blending_items[i]), (gpointer) i); + (GTK_OBJECT (gradient_editor->control_blending_items[i]), + gradient_editor); /* Set state */ if (equal) @@ -2949,7 +2950,8 @@ cpopup_adjust_blending_menu (GradientEditor *gradient_editor) /* Unblock signals */ for (i = 0; i < num_items; i++) - gtk_signal_handler_unblock_by_data (GTK_OBJECT (gradient_editor->control_blending_items[i]), (gpointer) i); + gtk_signal_handler_unblock_by_data (GTK_OBJECT (gradient_editor->control_blending_items[i]), + gradient_editor); } static void @@ -2968,7 +2970,8 @@ cpopup_adjust_coloring_menu (GradientEditor *gradient_editor) coloring = (int) gradient_editor->control_sel_l->color; for (i = 0; i < num_items; i++) - gtk_signal_handler_block_by_data (GTK_OBJECT (gradient_editor->control_coloring_items[i]), (gpointer) i); + gtk_signal_handler_block_by_data (GTK_OBJECT (gradient_editor->control_coloring_items[i]), + gradient_editor); /* Set state */ if (equal) @@ -2984,7 +2987,8 @@ cpopup_adjust_coloring_menu (GradientEditor *gradient_editor) /* Unblock signals */ for (i = 0; i < num_items; i++) - gtk_signal_handler_unblock_by_data (GTK_OBJECT (gradient_editor->control_coloring_items[i]), (gpointer) i); + gtk_signal_handler_unblock_by_data (GTK_OBJECT (gradient_editor->control_coloring_items[i]), + gradient_editor); } static void diff --git a/app/widgets/gimpgradientpreview.c b/app/widgets/gimpgradientpreview.c index 995bec9980..d35f83b063 100644 --- a/app/widgets/gimpgradientpreview.c +++ b/app/widgets/gimpgradientpreview.c @@ -42,7 +42,7 @@ static void gimp_gradient_preview_get_size (GimpPreview *preview, static gboolean gimp_gradient_preview_needs_popup (GimpPreview *preview); static GtkWidget * gimp_gradient_preview_create_popup (GimpPreview *preview); -static GimpGradient * gimp_gradient_preview_drag_gradient (GtkWidget *widget, +static GimpViewable * gimp_gradient_preview_drag_viewable (GtkWidget *widget, gpointer data); @@ -94,20 +94,14 @@ gimp_gradient_preview_class_init (GimpGradientPreviewClass *klass) static void gimp_gradient_preview_init (GimpGradientPreview *gradient_preview) { - static GtkTargetEntry preview_target_table[] = - { - GIMP_TARGET_GRADIENT - }; - static guint preview_n_targets = (sizeof (preview_target_table) / - sizeof (preview_target_table[0])); - - gtk_drag_source_set (GTK_WIDGET (gradient_preview), - GDK_BUTTON2_MASK, - preview_target_table, preview_n_targets, - GDK_ACTION_COPY); - gimp_dnd_gradient_source_set (GTK_WIDGET (gradient_preview), - gimp_gradient_preview_drag_gradient, - gradient_preview); + gimp_gtk_drag_source_set_by_type (GTK_WIDGET (gradient_preview), + GDK_BUTTON2_MASK, + GIMP_TYPE_GRADIENT, + GDK_ACTION_COPY); + gimp_dnd_viewable_source_set (GTK_WIDGET (gradient_preview), + GIMP_TYPE_GRADIENT, + gimp_gradient_preview_drag_viewable, + NULL); } static void @@ -181,13 +175,9 @@ gimp_gradient_preview_create_popup (GimpPreview *preview) TRUE, FALSE, FALSE); } -static GimpGradient * -gimp_gradient_preview_drag_gradient (GtkWidget *widget, +static GimpViewable * +gimp_gradient_preview_drag_viewable (GtkWidget *widget, gpointer data) { - GimpPreview *preview; - - preview = GIMP_PREVIEW (data); - - return GIMP_GRADIENT (preview->viewable); + return GIMP_PREVIEW (widget)->viewable; } diff --git a/app/widgets/gimppaletteeditor.c b/app/widgets/gimppaletteeditor.c index 9242fbe979..bcaf5e3431 100644 --- a/app/widgets/gimppaletteeditor.c +++ b/app/widgets/gimppaletteeditor.c @@ -30,11 +30,14 @@ #include "context_manager.h" #include "dialog_handler.h" #include "gimage.h" +#include "gimpcontainerlistview.h" #include "gimpcontext.h" #include "gimpdatafactory.h" +#include "gimpdatafactoryview.h" #include "gimpdatalist.h" #include "gimpdnd.h" #include "gimppalette.h" +#include "gimppreview.h" #include "gimprc.h" #include "palette.h" #include "palette_import.h" @@ -56,11 +59,12 @@ #define COLUMNS 16 #define ROWS 11 -#define PREVIEW_WIDTH ((ENTRY_WIDTH * COLUMNS) + (SPACING * (COLUMNS + 1))) -#define PREVIEW_HEIGHT ((ENTRY_HEIGHT * ROWS) + (SPACING * (ROWS + 1))) +#define PREVIEW_WIDTH ((ENTRY_WIDTH * COLUMNS) + (SPACING * (COLUMNS + 1))) +#define PREVIEW_HEIGHT ((ENTRY_HEIGHT * ROWS) + (SPACING * (ROWS + 1))) -#define PALETTE_EVENT_MASK GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | \ - GDK_ENTER_NOTIFY_MASK +#define PALETTE_EVENT_MASK (GDK_EXPOSURE_MASK | \ + GDK_BUTTON_PRESS_MASK | \ + GDK_ENTER_NOTIFY_MASK) typedef struct _PaletteDialog PaletteDialog; @@ -72,7 +76,10 @@ struct _PaletteDialog GtkWidget *color_area; GtkWidget *scrolled_window; GtkWidget *color_name; - GtkWidget *clist; + + GtkWidget *view; + + GimpContext *context; GtkWidget *popup_menu; GtkWidget *delete_menu_item; @@ -81,11 +88,9 @@ struct _PaletteDialog ColorNotebook *color_notebook; gboolean color_notebook_active; - GimpPalette *palette; GimpPaletteEntry *color; GimpPaletteEntry *dnd_color; - GdkGC *gc; guint entry_sig_id; gfloat zoom_factor; /* range from 0.1 to 4.0 */ gint col_width; @@ -93,23 +98,70 @@ struct _PaletteDialog gint columns; gboolean freeze_update; gboolean columns_valid; + + GQuark invalidate_preview_handler_id; }; /* local function prototypes */ -static void palette_dialog_draw_entries (PaletteDialog *palette, - gint row_start, - gint column_highlight); -static void palette_dialog_redraw (PaletteDialog *palette); -static void palette_dialog_scroll_top_left (PaletteDialog *palette); +static PaletteDialog * palette_dialog_new (gboolean editor); -static PaletteDialog * palette_dialog_new (gboolean editor); +static void palette_dialog_create_popup_menu (PaletteDialog *palette_dialog); +static void palette_dialog_new_entry_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_edit_entry_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_delete_entry_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_color_notebook_callback (ColorNotebook *color_notebook, + const GimpRGB *color, + ColorNotebookState state, + gpointer data); + +static gint palette_dialog_eventbox_button_press (GtkWidget *widget, + GdkEventButton *bevent, + PaletteDialog *palette_dialog); +static gint palette_dialog_color_area_events (GtkWidget *widget, + GdkEvent *event, + PaletteDialog *palette_dialog); +static void palette_dialog_draw_entries (PaletteDialog *palette, + gint row_start, + gint column_highlight); +static void palette_dialog_redraw (PaletteDialog *palette); +static void palette_dialog_scroll_top_left (PaletteDialog *palette); + +static void palette_dialog_color_name_changed (GtkWidget *widget, + gpointer data); +static void palette_dialog_zoomin_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_zoomout_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_redraw_zoom (PaletteDialog *palette_dialog); +static void palette_dialog_import_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_merge_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_do_merge_callback (GtkWidget *widget, + gchar *palette_name, + gpointer data); +static void palette_dialog_close_callback (GtkWidget *widget, + gpointer data); +static void palette_dialog_palette_changed (GimpContext *context, + GimpPalette *palette, + gpointer data); +static void palette_dialog_drag_color (GtkWidget *widget, + GimpRGB *color, + gpointer data); +static void palette_dialog_drop_color (GtkWidget *widget, + const GimpRGB *color, + gpointer data); +static void palette_dialog_invalidate_preview (GimpPalette *palette, + PaletteDialog *palette_dialog); +static void palette_dialog_edit_palette (GimpData *data); -PaletteDialog *top_level_edit_palette = NULL; -PaletteDialog *top_level_palette = NULL; - -static GimpPalette *default_palette_entries = NULL; +PaletteDialog *top_level_edit_palette = NULL; +PaletteDialog *top_level_palette = NULL; /* dnd stuff */ @@ -128,7 +180,7 @@ palette_dialog_create (void) { if (top_level_palette == NULL) { - top_level_palette = palette_dialog_new (TRUE); + top_level_palette = palette_dialog_new (FALSE); session_set_window_geometry (top_level_palette->shell, &palette_session_info, TRUE); dialog_register (top_level_palette->shell); @@ -155,10 +207,15 @@ palette_dialog_free (void) { palette_import_dialog_destroy (); - gdk_gc_destroy (top_level_edit_palette->gc); - if (top_level_edit_palette->color_notebook) - color_notebook_free (top_level_edit_palette->color_notebook); + color_notebook_free (top_level_edit_palette->color_notebook); + + gtk_signal_disconnect_by_func (GTK_OBJECT (top_level_edit_palette->context), + palette_dialog_palette_changed, + top_level_edit_palette); + + gimp_container_remove_handler (global_palette_factory->container, + top_level_edit_palette->invalidate_preview_handler_id); g_free (top_level_edit_palette); top_level_edit_palette = NULL; @@ -166,275 +223,24 @@ palette_dialog_free (void) if (top_level_palette) { - gdk_gc_destroy (top_level_palette->gc); session_get_window_info (top_level_palette->shell, &palette_session_info); if (top_level_palette->color_notebook) color_notebook_free (top_level_palette->color_notebook); + gtk_signal_disconnect_by_func (GTK_OBJECT (top_level_palette->context), + palette_dialog_palette_changed, + top_level_palette); + + gimp_container_remove_handler (global_palette_factory->container, + top_level_palette->invalidate_preview_handler_id); + g_free (top_level_palette); top_level_palette = NULL; } } -/* general palette clist update functions **********************************/ - -void -palette_clist_init (GtkWidget *clist, - GtkWidget *shell, - GdkGC *gc) -{ - GimpPalette *palette = NULL; - GList *list; - gint pos; - - for (list = GIMP_LIST (global_palette_factory->container)->list, pos = 0; - list; - list = g_list_next (list), pos++) - { - palette = (GimpPalette *) list->data; - - palette_clist_insert (clist, shell, gc, palette, pos); - } -} - -void -palette_clist_insert (GtkWidget *clist, - GtkWidget *shell, - GdkGC *gc, - GimpPalette *palette, - gint pos) -{ - gchar *string[3]; - - string[0] = NULL; - string[1] = g_strdup_printf ("%d", palette->n_colors); - string[2] = GIMP_OBJECT (palette)->name; - - gtk_clist_insert (GTK_CLIST (clist), pos, string); - - g_free (string[1]); - - if (palette->pixmap == NULL) - { - palette->pixmap = gdk_pixmap_new (shell->window, - SM_PREVIEW_WIDTH, - SM_PREVIEW_HEIGHT, - gtk_widget_get_visual (shell)->depth); - gimp_palette_update_preview (palette, gc); - } - - gtk_clist_set_pixmap (GTK_CLIST (clist), pos, 0, palette->pixmap, NULL); - gtk_clist_set_row_data (GTK_CLIST (clist), pos, (gpointer) palette); -} - -/* palette dialog clist update functions ***********************************/ - -static void -palette_dialog_clist_insert (PaletteDialog *palette_dialog, - GimpPalette *palette) -{ - gint pos; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (palette)); - - gtk_clist_freeze (GTK_CLIST (palette_dialog->clist)); - - palette_clist_insert (palette_dialog->clist, - palette_dialog->shell, - palette_dialog->gc, - palette, - pos); - - gtk_clist_thaw (GTK_CLIST (palette_dialog->clist)); -} - -static void -palette_dialog_clist_set_text (PaletteDialog *palette_dialog, - GimpPalette *palette) -{ - gchar *num_buf; - gint pos; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (palette)); - - num_buf = g_strdup_printf ("%d", palette->n_colors);; - - gtk_clist_set_text (GTK_CLIST (palette_dialog->clist), pos, 1, num_buf); - - g_free (num_buf); -} - -static void -palette_dialog_clist_refresh (PaletteDialog *palette_dialog) -{ - gtk_clist_freeze (GTK_CLIST (palette_dialog->clist)); - - gtk_clist_clear (GTK_CLIST (palette_dialog->clist)); - palette_clist_init (palette_dialog->clist, - palette_dialog->shell, - palette_dialog->gc); - - gtk_clist_thaw (GTK_CLIST (palette_dialog->clist)); - - palette_dialog->palette = (GimpPalette *) - gimp_container_get_child_by_index (global_palette_factory->container, 0); -} - -static void -palette_dialog_clist_scroll_to_current (PaletteDialog *palette_dialog) -{ - gint pos; - - if (! (palette_dialog && palette_dialog->palette)) - return; - - pos = gimp_container_get_child_index (global_palette_factory->container, - GIMP_OBJECT (palette_dialog->palette)); - - gtk_clist_unselect_all (GTK_CLIST (palette_dialog->clist)); - gtk_clist_select_row (GTK_CLIST (palette_dialog->clist), pos, -1); - gtk_clist_moveto (GTK_CLIST (palette_dialog->clist), pos, 0, 0.0, 0.0); -} - -/* update functions for all palette dialogs ********************************/ - -void -palette_insert_all (GimpPalette *palette) -{ - PaletteDialog *palette_dialog; - - if ((palette_dialog = top_level_palette)) - { - palette_dialog_clist_insert (palette_dialog, palette); - - if (palette_dialog->palette == NULL) - { - palette_dialog->palette = palette; - palette_dialog_redraw (palette_dialog); - } - } - - if ((palette_dialog = top_level_edit_palette)) - { - palette_dialog_clist_insert (palette_dialog, palette); - - palette_dialog->palette = palette; - palette_dialog_redraw (palette_dialog); - - palette_dialog_clist_scroll_to_current (palette_dialog); - } - - /* Update other selectors on screen */ - palette_select_clist_insert_all (palette); -} - -static void -palette_update_all (GimpPalette *palette) -{ - PaletteDialog *palette_dialog; - GdkGC *gc = NULL; - - if (top_level_palette) - gc = top_level_palette->gc; - else if (top_level_edit_palette) - gc = top_level_edit_palette->gc; - - if (gc) - gimp_palette_update_preview (palette, gc); - - if ((palette_dialog = top_level_palette)) - { - if (palette_dialog->palette == palette) - { - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - } - palette_dialog_clist_set_text (palette_dialog, palette); - } - - if ((palette_dialog = top_level_edit_palette)) - { - if (palette_dialog->palette == palette) - { - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - palette_dialog_clist_scroll_to_current (palette_dialog); - } - palette_dialog_clist_set_text (palette_dialog, palette); - } - - /* Update other selectors on screen */ - palette_select_set_text_all (palette); -} - -static void -palette_draw_all (GimpPalette *palette, - GimpPaletteEntry *entry) -{ - PaletteDialog *palette_dialog; - GdkGC *gc = NULL; - - if (top_level_palette) - gc = top_level_palette->gc; - else if (top_level_edit_palette) - gc = top_level_edit_palette->gc; - - if (gc) - gimp_palette_update_preview (palette, gc); - - if ((palette_dialog = top_level_palette)) - { - if (palette_dialog->palette == palette) - { - palette_dialog_draw_entries (palette_dialog, - entry->position / palette_dialog->columns, - entry->position % palette_dialog->columns); - } - } - - if ((palette_dialog = top_level_edit_palette)) - { - if (palette_dialog->palette == palette) - { - palette_dialog_draw_entries (palette_dialog, - entry->position / palette_dialog->columns, - entry->position % palette_dialog->columns); - } - } -} - -static void -palette_refresh_all (void) -{ - PaletteDialog *palette_dialog; - - default_palette_entries = NULL; - - gimp_data_factory_data_init (global_palette_factory, FALSE); - - if ((palette_dialog = top_level_palette)) - { - palette_dialog_clist_refresh (palette_dialog); - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - palette_dialog_clist_scroll_to_current (palette_dialog); - } - - if ((palette_dialog = top_level_edit_palette)) - { - palette_dialog_clist_refresh (palette_dialog); - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - palette_dialog_clist_scroll_to_current (palette_dialog); - } - - /* Update other selectors on screen */ - palette_select_refresh_all (); -} /* called from color_picker.h *********************************************/ @@ -444,7 +250,8 @@ palette_set_active_color (gint r, gint b, gint state) { - GimpRGB color; + GimpPalette *palette; + GimpRGB color; gimp_rgba_set_uchar (&color, (guchar) r, @@ -452,29 +259,30 @@ palette_set_active_color (gint r, (guchar) b, 255); - if (top_level_edit_palette && top_level_edit_palette->palette) + if (top_level_edit_palette) { - switch (state) - { - case COLOR_NEW: - top_level_edit_palette->color = - gimp_palette_add_entry (top_level_edit_palette->palette, - NULL, - &color); + palette = gimp_context_get_palette (top_level_edit_palette->context); - palette_update_all (top_level_edit_palette->palette); - break; + if (palette) + { + switch (state) + { + case COLOR_NEW: + top_level_edit_palette->color = gimp_palette_add_entry (palette, + NULL, + &color); + break; - case COLOR_UPDATE_NEW: - top_level_edit_palette->color->color = color; + case COLOR_UPDATE_NEW: + top_level_edit_palette->color->color = color; - palette_draw_all (top_level_edit_palette->palette, - top_level_edit_palette->color); - break; + gimp_data_dirty (GIMP_DATA (palette)); + break; - default: - break; - } + default: + break; + } + } } if (active_color == FOREGROUND) @@ -485,22 +293,12 @@ palette_set_active_color (gint r, /* called from palette_select.c ********************************************/ -void -palette_select_palette_init (void) -{ - if (top_level_edit_palette == NULL) - { - top_level_edit_palette = palette_dialog_new (FALSE); - dialog_register (top_level_edit_palette->shell); - } -} - void palette_create_edit (GimpPalette *palette) { if (top_level_edit_palette == NULL) { - top_level_edit_palette = palette_dialog_new (FALSE); + top_level_edit_palette = palette_dialog_new (TRUE); dialog_register (top_level_edit_palette->shell); gtk_widget_show (top_level_edit_palette->shell); @@ -509,142 +307,259 @@ palette_create_edit (GimpPalette *palette) else { if (! GTK_WIDGET_VISIBLE (top_level_edit_palette->shell)) - { - gtk_widget_show (top_level_edit_palette->shell); - palette_dialog_draw_entries (top_level_edit_palette, -1, -1); - } + gtk_widget_show (top_level_edit_palette->shell); else - { - gdk_window_raise (top_level_edit_palette->shell->window); - } + gdk_window_raise (top_level_edit_palette->shell->window); } - if (palette != NULL) - { - top_level_edit_palette->palette = palette; - palette_dialog_clist_scroll_to_current (top_level_edit_palette); - } + gimp_context_set_palette (top_level_edit_palette->context, palette); } -static void -palette_select_callback (ColorNotebook *color_notebook, - const GimpRGB *color, - ColorNotebookState state, - gpointer data) + +/* private functions */ + +/* the palette & palette edit dialog constructor ***************************/ + +PaletteDialog * +palette_dialog_new (gboolean editor) { PaletteDialog *palette_dialog; - - palette_dialog = data; + GtkWidget *hbox; + GtkWidget *hbox2; + GtkWidget *vbox; + GtkWidget *scrolledwindow; + GtkWidget *palette_region; + GtkWidget *entry; + GtkWidget *eventbox; + GtkWidget *alignment; + GtkWidget *frame; + GtkWidget *button; - if (! (palette_dialog && palette_dialog->palette)) - return; + palette_dialog = g_new0 (PaletteDialog, 1); - switch (state) + if (! editor) + palette_dialog->context = gimp_context_get_user (); + else + palette_dialog->context = gimp_context_new (NULL, NULL); + + palette_dialog->zoom_factor = 1.0; + palette_dialog->columns = COLUMNS; + palette_dialog->columns_valid = TRUE; + palette_dialog->freeze_update = FALSE; + + if (editor) { - case COLOR_NOTEBOOK_UPDATE: - break; + palette_dialog->shell = + gimp_dialog_new (_("Color Palette Edit"), "color_palette_edit", + gimp_standard_help_func, + "dialogs/palette_editor/palette_editor.html", + GTK_WIN_POS_NONE, + FALSE, TRUE, FALSE, - case COLOR_NOTEBOOK_OK: - if (palette_dialog->color) - { - palette_dialog->color->color = *color; + "_delete_event_", palette_dialog_close_callback, + palette_dialog, NULL, NULL, TRUE, TRUE, - /* Update either foreground or background colors */ - if (active_color == FOREGROUND) - gimp_context_set_foreground (gimp_context_get_user (), color); - else if (active_color == BACKGROUND) - gimp_context_set_background (gimp_context_get_user (), color); - - palette_draw_all (palette_dialog->palette, palette_dialog->color); - } - - /* Fallthrough */ - case COLOR_NOTEBOOK_CANCEL: - if (palette_dialog->color_notebook_active) - { - color_notebook_hide (palette_dialog->color_notebook); - palette_dialog->color_notebook_active = FALSE; - } - } -} - -/* the palette dialog popup menu & callbacks *******************************/ - -static void -palette_dialog_new_entry_callback (GtkWidget *widget, - gpointer data) -{ - PaletteDialog *palette_dialog; - GimpRGB color; - - palette_dialog = (PaletteDialog *) data; - - if (! (palette_dialog && palette_dialog->palette)) - return; - - if (active_color == FOREGROUND) - gimp_context_get_foreground (gimp_context_get_user (), &color); - else if (active_color == BACKGROUND) - gimp_context_get_background (gimp_context_get_user (), &color); - - palette_dialog->color = gimp_palette_add_entry (palette_dialog->palette, - NULL, - &color); - - palette_update_all (palette_dialog->palette); -} - -static void -palette_dialog_edit_entry_callback (GtkWidget *widget, - gpointer data) -{ - PaletteDialog *palette_dialog; - - palette_dialog = (PaletteDialog *) data; - - if (! (palette_dialog && palette_dialog->palette && palette_dialog->color)) - return; - - if (! palette_dialog->color_notebook) - { - palette_dialog->color_notebook = - color_notebook_new (_("Edit Palette Color"), - (const GimpRGB *) &palette_dialog->color->color, - palette_select_callback, - palette_dialog, - FALSE, - FALSE); - palette_dialog->color_notebook_active = TRUE; + NULL); } else { - if (! palette_dialog->color_notebook_active) - { - color_notebook_show (palette_dialog->color_notebook); - palette_dialog->color_notebook_active = TRUE; - } + palette_dialog->shell = + gimp_dialog_new (_("Color Palette"), "color_palette", + gimp_standard_help_func, + "dialogs/palette_selection.html", + GTK_WIN_POS_NONE, + FALSE, TRUE, FALSE, - color_notebook_set_color (palette_dialog->color_notebook, - &palette_dialog->color->color); + "_delete_event_", palette_dialog_close_callback, + palette_dialog, NULL, NULL, TRUE, TRUE, + + NULL); + } + + gtk_widget_hide (GTK_WIDGET (g_list_nth_data (gtk_container_children (GTK_CONTAINER (GTK_DIALOG (palette_dialog->shell)->vbox)), 0))); + + gtk_widget_hide (GTK_DIALOG (palette_dialog->shell)->action_area); + + /* The main container widget */ + if (! editor) + { + hbox = gtk_notebook_new (); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 1); } + else + { + hbox = gtk_hbox_new (FALSE, 4); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 4); + } + + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (palette_dialog->shell)->vbox), + hbox); + gtk_widget_show (hbox); + + vbox = gtk_vbox_new (FALSE, 2); + gtk_widget_show (vbox); + + palette_dialog->scrolled_window = + scrolledwindow = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_ALWAYS); + gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0); + gtk_widget_show (scrolledwindow); + + eventbox = gtk_event_box_new (); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledwindow), + eventbox); + gtk_signal_connect (GTK_OBJECT (eventbox), "button_press_event", + GTK_SIGNAL_FUNC (palette_dialog_eventbox_button_press), + palette_dialog); + gtk_widget_show (eventbox); + + alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); + gtk_container_add (GTK_CONTAINER (eventbox), alignment); + gtk_widget_show (alignment); + + palette_dialog->color_area = palette_region = + gtk_preview_new (GTK_PREVIEW_COLOR); + gtk_preview_set_dither (GTK_PREVIEW (palette_dialog->color_area), + GDK_RGB_DITHER_MAX); + gtk_preview_size (GTK_PREVIEW (palette_region), PREVIEW_WIDTH, PREVIEW_HEIGHT); + + gtk_widget_set_events (palette_region, PALETTE_EVENT_MASK); + gtk_signal_connect (GTK_OBJECT (palette_dialog->color_area), "event", + GTK_SIGNAL_FUNC (palette_dialog_color_area_events), + palette_dialog); + + gtk_container_add (GTK_CONTAINER (alignment), palette_region); + gtk_widget_show (palette_region); + + /* dnd stuff */ + gtk_drag_source_set (palette_region, + GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, + color_palette_target_table, n_color_palette_targets, + GDK_ACTION_COPY | GDK_ACTION_MOVE); + gimp_dnd_color_source_set (palette_region, palette_dialog_drag_color, + palette_dialog); + + gtk_drag_dest_set (alignment, + GTK_DEST_DEFAULT_HIGHLIGHT | + GTK_DEST_DEFAULT_MOTION | + GTK_DEST_DEFAULT_DROP, + color_palette_target_table, n_color_palette_targets, + GDK_ACTION_COPY); + gimp_dnd_color_dest_set (alignment, palette_dialog_drop_color, palette_dialog); + + /* The color name entry */ + hbox2 = gtk_hbox_new (FALSE, 2); + gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0); + gtk_widget_show (hbox2); + + entry = palette_dialog->color_name = gtk_entry_new (); + gtk_widget_show (entry); + gtk_box_pack_start (GTK_BOX (hbox2), entry, TRUE, TRUE, 0); + gtk_entry_set_text (GTK_ENTRY (entry), _("Undefined")); + gtk_widget_set_sensitive (entry, FALSE); + palette_dialog->entry_sig_id = + gtk_signal_connect (GTK_OBJECT (entry), "changed", + GTK_SIGNAL_FUNC (palette_dialog_color_name_changed), + palette_dialog); + + /* + and - buttons */ + button = gimp_pixmap_button_new (zoom_in_xpm, NULL); + gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (palette_dialog_zoomin_callback), + palette_dialog); + gtk_widget_show (button); + + button = gimp_pixmap_button_new (zoom_out_xpm, NULL); + gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (palette_dialog_zoomout_callback), + palette_dialog); + gtk_widget_show (button); + + /* The Palette List */ + palette_dialog->view = + gimp_data_factory_view_new (GIMP_VIEW_TYPE_LIST, + global_palette_factory, + editor ? NULL : palette_dialog_edit_palette, + palette_dialog->context, + 64, /* FIXME: SM_PREVIEW_WIDTH */ + 3, /* FIXME: STD_PALETTE_COLUMNS */ + 3); /* FIXME: STD_PALETTE_ROWS */ + + if (! editor) + { + gtk_notebook_append_page (GTK_NOTEBOOK (hbox), vbox, + gtk_label_new (_("Palette"))); + gtk_notebook_append_page (GTK_NOTEBOOK (hbox), palette_dialog->view, + gtk_label_new (_("Select"))); + } + else + { + gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox), palette_dialog->view, TRUE, TRUE, 0); + } + + if (editor) + gtk_list_set_selection_mode (GTK_LIST (GIMP_CONTAINER_LIST_VIEW (GIMP_DATA_FACTORY_VIEW (palette_dialog->view)->view)->gtk_list), + GTK_SELECTION_EXTENDED); + + gtk_signal_connect (GTK_OBJECT (palette_dialog->context), "palette_changed", + GTK_SIGNAL_FUNC (palette_dialog_palette_changed), + palette_dialog); + + palette_dialog->invalidate_preview_handler_id = + gimp_container_add_handler (global_palette_factory->container, + "invalidate_preview", + GTK_SIGNAL_FUNC (palette_dialog_invalidate_preview), + palette_dialog); + + gtk_widget_show (palette_dialog->view); + + if (editor) + { + frame = gtk_frame_new (_("Palette Ops")); + gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0); + gtk_widget_show (frame); + + vbox = gtk_vbox_new (FALSE, 2); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); + gtk_container_add (GTK_CONTAINER (frame), vbox); + gtk_widget_show (vbox); + + button = gtk_button_new_with_label (_("Import")); + GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); + gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (palette_dialog_import_callback), + palette_dialog); + gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); + gimp_help_set_help_data (button, NULL, + "dialogs/palette_editor/import_palette.html"); + gtk_widget_show (button); + + button = gtk_button_new_with_label (_("Merge")); + GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); + gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (palette_dialog_merge_callback), + palette_dialog); + gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); + gimp_help_set_help_data (button, NULL, + "dialogs/palette_editor/merge_palette.html"); + gtk_widget_show (button); + } + + gtk_widget_realize (palette_dialog->shell); + + palette_dialog_create_popup_menu (palette_dialog); + + return palette_dialog; } -static void -palette_dialog_delete_entry_callback (GtkWidget *widget, - gpointer data) -{ - PaletteDialog *palette_dialog; - - palette_dialog = (PaletteDialog *) data; - - if (! (palette_dialog && palette_dialog->palette && palette_dialog->color)) - return; - - gimp_palette_delete_entry (palette_dialog->palette, - palette_dialog->color); - - palette_update_all (palette_dialog->palette); -} +/* the palette dialog popup menu & callbacks *******************************/ static void palette_dialog_create_popup_menu (PaletteDialog *palette_dialog) @@ -681,6 +596,123 @@ palette_dialog_create_popup_menu (PaletteDialog *palette_dialog) palette_dialog->delete_menu_item = menu_item; } +static void +palette_dialog_new_entry_callback (GtkWidget *widget, + gpointer data) +{ + PaletteDialog *palette_dialog; + GimpRGB color; + + palette_dialog = (PaletteDialog *) data; + + if (! (palette_dialog && gimp_context_get_palette (palette_dialog->context))) + return; + + if (active_color == FOREGROUND) + gimp_context_get_foreground (gimp_context_get_user (), &color); + else if (active_color == BACKGROUND) + gimp_context_get_background (gimp_context_get_user (), &color); + + palette_dialog->color = + gimp_palette_add_entry (gimp_context_get_palette (palette_dialog->context), + NULL, + &color); +} + +static void +palette_dialog_edit_entry_callback (GtkWidget *widget, + gpointer data) +{ + PaletteDialog *palette_dialog; + + palette_dialog = (PaletteDialog *) data; + + if (! (palette_dialog && gimp_context_get_palette (palette_dialog->context) + && palette_dialog->color)) + return; + + if (! palette_dialog->color_notebook) + { + palette_dialog->color_notebook = + color_notebook_new (_("Edit Palette Color"), + (const GimpRGB *) &palette_dialog->color->color, + palette_dialog_color_notebook_callback, + palette_dialog, + FALSE, + FALSE); + palette_dialog->color_notebook_active = TRUE; + } + else + { + if (! palette_dialog->color_notebook_active) + { + color_notebook_show (palette_dialog->color_notebook); + palette_dialog->color_notebook_active = TRUE; + } + + color_notebook_set_color (palette_dialog->color_notebook, + &palette_dialog->color->color); + } +} + +static void +palette_dialog_delete_entry_callback (GtkWidget *widget, + gpointer data) +{ + PaletteDialog *palette_dialog; + + palette_dialog = (PaletteDialog *) data; + + if (! (palette_dialog && gimp_context_get_palette (palette_dialog->context) && + palette_dialog->color)) + return; + + gimp_palette_delete_entry (gimp_context_get_palette (palette_dialog->context), + palette_dialog->color); +} + +static void +palette_dialog_color_notebook_callback (ColorNotebook *color_notebook, + const GimpRGB *color, + ColorNotebookState state, + gpointer data) +{ + PaletteDialog *palette_dialog; + GimpPalette *palette; + + palette_dialog = data; + + palette = gimp_context_get_palette (palette_dialog->context); + + switch (state) + { + case COLOR_NOTEBOOK_UPDATE: + break; + + case COLOR_NOTEBOOK_OK: + if (palette_dialog->color) + { + palette_dialog->color->color = *color; + + /* Update either foreground or background colors */ + if (active_color == FOREGROUND) + gimp_context_set_foreground (gimp_context_get_user (), color); + else if (active_color == BACKGROUND) + gimp_context_set_background (gimp_context_get_user (), color); + + gimp_data_dirty (GIMP_DATA (palette)); + } + + /* Fallthrough */ + case COLOR_NOTEBOOK_CANCEL: + if (palette_dialog->color_notebook_active) + { + color_notebook_hide (palette_dialog->color_notebook); + palette_dialog->color_notebook_active = FALSE; + } + } +} + /* the color area event callbacks ******************************************/ static gint @@ -733,8 +765,8 @@ palette_dialog_color_area_events (GtkWidget *widget, row = (bevent->y - 1) / entry_height; pos = row * palette_dialog->columns + col; - if (palette_dialog->palette) - list = g_list_nth (palette_dialog->palette->colors, pos); + if (gimp_context_get_palette (palette_dialog->context)) + list = g_list_nth (gimp_context_get_palette (palette_dialog->context)->colors, pos); else list = NULL; @@ -744,7 +776,7 @@ palette_dialog_color_area_events (GtkWidget *widget, palette_dialog->dnd_color = NULL; if ((bevent->button == 1 || bevent->button == 3) && - palette_dialog->palette) + gimp_context_get_palette (palette_dialog->context)) { if (list) { @@ -1001,7 +1033,7 @@ palette_dialog_draw_entries (PaletteDialog *palette_dialog, gint entry_height; gint index, y; - if (! (palette_dialog && palette_dialog->palette)) + if (! (palette_dialog && gimp_context_get_palette (palette_dialog->context))) return; width = palette_dialog->color_area->requisition.width; @@ -1019,13 +1051,13 @@ palette_dialog_draw_entries (PaletteDialog *palette_dialog, if (row_start < 0) { y = 0; - list = palette_dialog->palette->colors; + list = gimp_context_get_palette (palette_dialog->context)->colors; column_highlight = -1; } else { y = (entry_height + SPACING) * row_start; - list = g_list_nth (palette_dialog->palette->colors, + list = g_list_nth (gimp_context_get_palette (palette_dialog->context)->colors, row_start * palette_dialog->columns); } @@ -1103,7 +1135,7 @@ palette_dialog_redraw (PaletteDialog *palette_dialog) gint preview_width; guint width; - if (! palette_dialog->palette) + if (! gimp_context_get_palette (palette_dialog->context)) return; width = palette_dialog->color_area->parent->parent->parent->allocation.width; @@ -1116,7 +1148,7 @@ palette_dialog_redraw (PaletteDialog *palette_dialog) if (palette_dialog->col_width < 0) palette_dialog->col_width = 0; palette_dialog->columns_valid = TRUE; - n_entries = palette_dialog->palette->n_colors; + n_entries = gimp_context_get_palette (palette_dialog->context)->n_colors; nrows = n_entries / palette_dialog->columns; if (n_entries % palette_dialog->columns) nrows += 1; @@ -1137,23 +1169,27 @@ palette_dialog_redraw (PaletteDialog *palette_dialog) gtk_container_add (GTK_CONTAINER (parent), palette_dialog->color_area->parent); gtk_widget_unref (palette_dialog->color_area->parent); - palette_dialog_draw_entries (palette_dialog, -1, -1); + if (palette_dialog->color) + palette_dialog_draw_entries (palette_dialog, + palette_dialog->color->position / palette_dialog->columns, + palette_dialog->color->position % palette_dialog->columns); + else + palette_dialog_draw_entries (palette_dialog, -1, -1); } -/* the palette dialog clist "select_row" callback **************************/ - static void -palette_dialog_list_item_update (GtkWidget *widget, - gint row, - gint column, - GdkEventButton *event, - gpointer data) +palette_dialog_palette_changed (GimpContext *context, + GimpPalette *palette, + gpointer data) { PaletteDialog *palette_dialog; - GimpPalette *palette; palette_dialog = (PaletteDialog *) data; + /* FIXME */ + if (! palette) + return; + if (palette_dialog->color_notebook_active) { color_notebook_hide (palette_dialog->color_notebook); @@ -1164,17 +1200,12 @@ palette_dialog_list_item_update (GtkWidget *widget, color_notebook_free (palette_dialog->color_notebook); palette_dialog->color_notebook = NULL; - palette = - (GimpPalette *) gtk_clist_get_row_data (GTK_CLIST (palette_dialog->clist), - row); - - palette_dialog->palette = palette; palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); + palette_dialog_scroll_top_left (palette_dialog); - /* Stop errors in case no colors are selected */ + /* Stop errors in case no colors are selected */ gtk_signal_handler_block (GTK_OBJECT (palette_dialog->color_name), palette_dialog->entry_sig_id); gtk_entry_set_text (GTK_ENTRY (palette_dialog->color_name), _("Undefined")); @@ -1186,44 +1217,25 @@ palette_dialog_list_item_update (GtkWidget *widget, /* the color name entry callback *******************************************/ static void -palette_dialog_color_name_entry_changed (GtkWidget *widget, - gpointer data) +palette_dialog_color_name_changed (GtkWidget *widget, + gpointer data) { PaletteDialog *palette_dialog; palette_dialog = (PaletteDialog *) data; - g_return_if_fail (palette_dialog->palette != NULL); + g_return_if_fail (gimp_context_get_palette (palette_dialog->context) != NULL); if (palette_dialog->color->name) g_free (palette_dialog->color->name); palette_dialog->color->name = g_strdup (gtk_entry_get_text (GTK_ENTRY (palette_dialog->color_name))); - gimp_data_dirty (GIMP_DATA (palette_dialog->palette)); + gimp_data_dirty (GIMP_DATA (gimp_context_get_palette (palette_dialog->context))); } /* palette zoom functions & callbacks **************************************/ -static void -palette_dialog_redraw_zoom (PaletteDialog *palette_dialog) -{ - if (palette_dialog->zoom_factor > 4.0) - { - palette_dialog->zoom_factor = 4.0; - } - else if (palette_dialog->zoom_factor < 0.1) - { - palette_dialog->zoom_factor = 0.1; - } - - palette_dialog->columns = COLUMNS; - palette_dialog->columns_valid = FALSE; - palette_dialog_redraw (palette_dialog); - - palette_dialog_scroll_top_left (palette_dialog); -} - static void palette_dialog_zoomin_callback (GtkWidget *widget, gpointer data) @@ -1250,101 +1262,27 @@ palette_dialog_zoomout_callback (GtkWidget *widget, palette_dialog_redraw_zoom (palette_dialog); } -/* the palette edit ops callbacks ******************************************/ - static void -palette_dialog_add_entries_callback (GtkWidget *widget, - gchar *palette_name, - gpointer data) +palette_dialog_redraw_zoom (PaletteDialog *palette_dialog) { - GimpPalette *palette; + if (palette_dialog->zoom_factor > 4.0) + { + palette_dialog->zoom_factor = 4.0; + } + else if (palette_dialog->zoom_factor < 0.1) + { + palette_dialog->zoom_factor = 0.1; + } - palette = GIMP_PALETTE (gimp_palette_new (palette_name)); + palette_dialog->columns = COLUMNS; - gimp_container_add (global_palette_factory->container, GIMP_OBJECT (palette)); + palette_dialog->columns_valid = FALSE; + palette_dialog_redraw (palette_dialog); - /* update all dialogs */ - palette_insert_all (palette); + palette_dialog_scroll_top_left (palette_dialog); } -static void -palette_dialog_new_callback (GtkWidget *widget, - gpointer data) -{ - GtkWidget *qbox; - - qbox = gimp_query_string_box (_("New Palette"), - gimp_standard_help_func, - "dialogs/palette_editor/new_palette.html", - _("Enter a name for new palette"), - NULL, - NULL, NULL, - palette_dialog_add_entries_callback, data); - gtk_widget_show (qbox); -} - -static void -palette_dialog_do_delete_callback (GtkWidget *widget, - gboolean delete, - gpointer data) -{ - PaletteDialog *palette_dialog; - GimpPalette *palette; - - palette_dialog = (PaletteDialog *) data; - - gtk_widget_set_sensitive (palette_dialog->shell, TRUE); - - if (! delete) - return; - - if (! (palette_dialog && palette_dialog->palette)) - return; - - palette = palette_dialog->palette; - - if (GIMP_DATA (palette)->filename) - gimp_data_delete_from_disk (GIMP_DATA (palette)); - - gimp_container_remove (global_palette_factory->container, - GIMP_OBJECT (palette)); - - palette_refresh_all (); -} - -static void -palette_dialog_delete_callback (GtkWidget *widget, - gpointer data) -{ - PaletteDialog *palette_dialog; - GtkWidget *dialog; - gchar *str; - - palette_dialog = (PaletteDialog *) data; - - if (! (palette_dialog && palette_dialog->palette)) - return; - - gtk_widget_set_sensitive (palette_dialog->shell, FALSE); - - str = g_strdup_printf (_("Are you sure you want to delete\n" - "\"%s\" from the list and from disk?"), - GIMP_OBJECT (palette_dialog->palette)->name); - - dialog = gimp_query_boolean_box (_("Delete Palette"), - gimp_standard_help_func, - "dialogs/palette_editor/delete_palette.html", - FALSE, - str, - _("Delete"), _("Cancel"), - NULL, NULL, - palette_dialog_do_delete_callback, - palette_dialog); - - g_free (str); - - gtk_widget_show (dialog); -} +/* the palette dialog action callbacks **************************************/ static void palette_dialog_import_callback (GtkWidget *widget, @@ -1353,51 +1291,6 @@ palette_dialog_import_callback (GtkWidget *widget, palette_import_dialog_show (); } -static void -palette_dialog_merge_entries_callback (GtkWidget *widget, - gchar *palette_name, - gpointer data) -{ - PaletteDialog *palette_dialog; - GimpPalette *palette; - GimpPalette *new_palette; - GimpPaletteEntry *entry; - GList *sel_list; - - new_palette = GIMP_PALETTE (gimp_palette_new (palette_name)); - - palette_dialog = (PaletteDialog *) data; - - sel_list = GTK_CLIST (palette_dialog->clist)->selection; - - while (sel_list) - { - gint row; - GList *cols; - - row = GPOINTER_TO_INT (sel_list->data); - palette = - (GimpPalette *) gtk_clist_get_row_data (GTK_CLIST (palette_dialog->clist), row); - - /* Go through each palette and merge the colors */ - for (cols = palette->colors; cols; cols = g_list_next (cols)) - { - entry = (GimpPaletteEntry *) cols->data; - - gimp_palette_add_entry (new_palette, - entry->name, - &entry->color); - } - sel_list = sel_list->next; - } - - gimp_container_add (global_palette_factory->container, - GIMP_OBJECT (new_palette)); - - /* update all dialogs */ - palette_insert_all (new_palette); -} - static void palette_dialog_merge_callback (GtkWidget *widget, gpointer data) @@ -1410,51 +1303,56 @@ palette_dialog_merge_callback (GtkWidget *widget, _("Enter a name for merged palette"), NULL, NULL, NULL, - palette_dialog_merge_entries_callback, + palette_dialog_do_merge_callback, data); gtk_widget_show (qbox); } -/* the palette & palette edit action area callbacks ************************/ - static void -palette_dialog_save_callback (GtkWidget *widget, - gpointer data) +palette_dialog_do_merge_callback (GtkWidget *widget, + gchar *palette_name, + gpointer data) { - g_warning ("%s(): TODO", G_GNUC_FUNCTION); + PaletteDialog *palette_dialog; + GimpPalette *palette; + GimpPalette *new_palette; + GimpPaletteEntry *entry; + GList *sel_list; - /* - palette_save_palettes (); - */ -} - -static void -palette_dialog_refresh_callback (GtkWidget *widget, - gpointer data) -{ - palette_refresh_all (); -} - -static void -palette_dialog_edit_callback (GtkWidget *widget, - gpointer data) -{ - GimpPalette *palette = NULL; - PaletteDialog *palette_dialog; - GList *sel_list; + new_palette = GIMP_PALETTE (gimp_palette_new (palette_name)); palette_dialog = (PaletteDialog *) data; - sel_list = GTK_CLIST (palette_dialog->clist)->selection; + sel_list = GTK_LIST (GIMP_CONTAINER_LIST_VIEW (GIMP_DATA_FACTORY_VIEW (palette_dialog->view)->view)->gtk_list)->selection; - if (sel_list) + while (sel_list) { - palette = - (GimpPalette *) gtk_clist_get_row_data (GTK_CLIST (palette_dialog->clist), - GPOINTER_TO_INT (sel_list->data)); + GtkWidget *list_item; + GList *cols; + + list_item = GTK_WIDGET (sel_list->data); + + palette = (GimpPalette *) + GIMP_PREVIEW (gtk_object_get_data (GTK_OBJECT (list_item), + "preview"))->viewable; + + if (palette) + { + for (cols = palette->colors; cols; cols = g_list_next (cols)) + { + entry = (GimpPaletteEntry *) cols->data; + + gimp_palette_add_entry (new_palette, + entry->name, + &entry->color); + } + } + + sel_list = sel_list->next; } - palette_create_edit (palette); + gimp_container_add (global_palette_factory->container, + GIMP_OBJECT (new_palette)); } static void @@ -1494,7 +1392,9 @@ palette_dialog_drag_color (GtkWidget *widget, palette_dialog = (PaletteDialog *) data; - if (palette_dialog && palette_dialog->palette && palette_dialog->dnd_color) + if (palette_dialog && + gimp_context_get_palette (palette_dialog->context) && + palette_dialog->dnd_color) { *color = palette_dialog->dnd_color->color; } @@ -1513,283 +1413,32 @@ palette_dialog_drop_color (GtkWidget *widget, palette_dialog = (PaletteDialog *) data; - if (palette_dialog && palette_dialog->palette) + if (palette_dialog && gimp_context_get_palette (palette_dialog->context)) { - palette_dialog->color = gimp_palette_add_entry (palette_dialog->palette, - NULL, - (GimpRGB *) color); - - palette_update_all (palette_dialog->palette); + palette_dialog->color = + gimp_palette_add_entry (gimp_context_get_palette (palette_dialog->context), + NULL, + (GimpRGB *) color); } } -/* the palette & palette edit dialog constructor ***************************/ - -PaletteDialog * -palette_dialog_new (gboolean editor) +static void +palette_dialog_invalidate_preview (GimpPalette *palette, + PaletteDialog *palette_dialog) { - PaletteDialog *palette_dialog; - GtkWidget *hbox; - GtkWidget *hbox2; - GtkWidget *vbox; - GtkWidget *scrolledwindow; - GtkWidget *palette_region; - GtkWidget *entry; - GtkWidget *eventbox; - GtkWidget *alignment; - GtkWidget *frame; - GtkWidget *button; - gchar *titles[3]; - - palette_dialog = g_new0 (PaletteDialog, 1); - palette_dialog->palette = default_palette_entries; - palette_dialog->zoom_factor = 1.0; - palette_dialog->columns = COLUMNS; - palette_dialog->columns_valid = TRUE; - palette_dialog->freeze_update = FALSE; - - if (!editor) + if (palette == gimp_context_get_palette (palette_dialog->context)) { - palette_dialog->shell = - gimp_dialog_new (_("Color Palette Edit"), "color_palette_edit", - gimp_standard_help_func, - "dialogs/palette_editor/palette_editor.html", - GTK_WIN_POS_NONE, - FALSE, TRUE, FALSE, - - _("Save"), palette_dialog_save_callback, - palette_dialog, NULL, NULL, FALSE, FALSE, - _("Refresh"), palette_dialog_refresh_callback, - palette_dialog, NULL, NULL, FALSE, FALSE, - _("Close"), palette_dialog_close_callback, - palette_dialog, NULL, NULL, TRUE, TRUE, - - NULL); + palette_dialog->columns_valid = FALSE; + palette_dialog_redraw (palette_dialog); } - else - { - palette_dialog->shell = - gimp_dialog_new (_("Color Palette"), "color_palette", - gimp_standard_help_func, - "dialogs/palette_selection.html", - GTK_WIN_POS_NONE, - FALSE, TRUE, FALSE, - - _("Edit"), palette_dialog_edit_callback, - palette_dialog, NULL, NULL, FALSE, FALSE, - _("Close"), palette_dialog_close_callback, - palette_dialog, NULL, NULL, TRUE, TRUE, - - NULL); - } - - /* The main container widget */ - if (editor) - { - hbox = gtk_notebook_new (); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 1); - } - else - { - hbox = gtk_hbox_new (FALSE, 4); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 4); - } - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (palette_dialog->shell)->vbox), - hbox); - gtk_widget_show (hbox); - - vbox = gtk_vbox_new (FALSE, 2); - gtk_widget_show (vbox); - - palette_dialog->scrolled_window = - scrolledwindow = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_ALWAYS); - gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0); - gtk_widget_show (scrolledwindow); - - eventbox = gtk_event_box_new (); - gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledwindow), - eventbox); - gtk_signal_connect (GTK_OBJECT (eventbox), "button_press_event", - GTK_SIGNAL_FUNC (palette_dialog_eventbox_button_press), - palette_dialog); - gtk_widget_show (eventbox); - - alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); - gtk_container_add (GTK_CONTAINER (eventbox), alignment); - gtk_widget_show (alignment); - - palette_dialog->color_area = palette_region = - gtk_preview_new (GTK_PREVIEW_COLOR); - gtk_preview_set_dither (GTK_PREVIEW (palette_dialog->color_area), - GDK_RGB_DITHER_MAX); - gtk_preview_size (GTK_PREVIEW (palette_region), PREVIEW_WIDTH, PREVIEW_HEIGHT); - - gtk_widget_set_events (palette_region, PALETTE_EVENT_MASK); - gtk_signal_connect (GTK_OBJECT (palette_dialog->color_area), "event", - GTK_SIGNAL_FUNC (palette_dialog_color_area_events), - palette_dialog); - - gtk_container_add (GTK_CONTAINER (alignment), palette_region); - gtk_widget_show (palette_region); - - /* dnd stuff */ - gtk_drag_source_set (palette_region, - GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, - color_palette_target_table, n_color_palette_targets, - GDK_ACTION_COPY | GDK_ACTION_MOVE); - gimp_dnd_color_source_set (palette_region, palette_dialog_drag_color, - palette_dialog); - - gtk_drag_dest_set (alignment, - GTK_DEST_DEFAULT_HIGHLIGHT | - GTK_DEST_DEFAULT_MOTION | - GTK_DEST_DEFAULT_DROP, - color_palette_target_table, n_color_palette_targets, - GDK_ACTION_COPY); - gimp_dnd_color_dest_set (alignment, palette_dialog_drop_color, palette_dialog); - - /* The color name entry */ - hbox2 = gtk_hbox_new (FALSE, 2); - gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0); - gtk_widget_show (hbox2); - - entry = palette_dialog->color_name = gtk_entry_new (); - gtk_widget_show (entry); - gtk_box_pack_start (GTK_BOX (hbox2), entry, TRUE, TRUE, 0); - gtk_entry_set_text (GTK_ENTRY (entry), _("Undefined")); - gtk_widget_set_sensitive (entry, FALSE); - palette_dialog->entry_sig_id = - gtk_signal_connect (GTK_OBJECT (entry), "changed", - GTK_SIGNAL_FUNC (palette_dialog_color_name_entry_changed), - palette_dialog); - - /* + and - buttons */ - button = gimp_pixmap_button_new (zoom_in_xpm, NULL); - gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_zoomin_callback), - palette_dialog); - gtk_widget_show (button); - - button = gimp_pixmap_button_new (zoom_out_xpm, NULL); - gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_zoomout_callback), - palette_dialog); - gtk_widget_show (button); - - /* clist preview of palettes */ - scrolledwindow = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_ALWAYS); - - if (editor) - { - gtk_notebook_append_page (GTK_NOTEBOOK (hbox), vbox, - gtk_label_new (_("Palette"))); - gtk_notebook_append_page (GTK_NOTEBOOK (hbox), scrolledwindow, - gtk_label_new (_("Select"))); - } - else - { - gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (hbox), scrolledwindow, TRUE, TRUE, 0); - } - - gtk_widget_show (scrolledwindow); - - titles[0] = _("Palette"); - titles[1] = _("Ncols"); - titles[2] = _("Name"); - palette_dialog->clist = gtk_clist_new_with_titles (3, titles); - gtk_widget_set_usize (palette_dialog->clist, 203, 203); - gtk_clist_set_row_height (GTK_CLIST (palette_dialog->clist), - SM_PREVIEW_HEIGHT + 2); - gtk_clist_set_column_width (GTK_CLIST (palette_dialog->clist), 0, - SM_PREVIEW_WIDTH+2); - gtk_clist_column_titles_passive (GTK_CLIST (palette_dialog->clist)); - gtk_container_add (GTK_CONTAINER (scrolledwindow), palette_dialog->clist); - - if (!editor) - gtk_clist_set_selection_mode (GTK_CLIST (palette_dialog->clist), - GTK_SELECTION_EXTENDED); - - gtk_signal_connect (GTK_OBJECT (palette_dialog->clist), "select_row", - GTK_SIGNAL_FUNC (palette_dialog_list_item_update), - (gpointer) palette_dialog); - gtk_widget_show (palette_dialog->clist); - - if (!editor) - { - frame = gtk_frame_new (_("Palette Ops")); - gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0); - gtk_widget_show (frame); - - vbox = gtk_vbox_new (FALSE, 2); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); - gtk_container_add (GTK_CONTAINER (frame), vbox); - gtk_widget_show (vbox); - - button = gtk_button_new_with_label (_("New")); - GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); - gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_new_callback), - palette_dialog); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gimp_help_set_help_data (button, NULL, - "dialogs/palette_editor/new_palette.html"); - gtk_widget_show (button); - - button = gtk_button_new_with_label (_("Delete")); - GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); - gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_delete_callback), - palette_dialog); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gimp_help_set_help_data (button, NULL, - "dialogs/palette_editor/delete_palette.html"); - gtk_widget_show (button); - - button = gtk_button_new_with_label (_("Import")); - GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); - gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_import_callback), - palette_dialog); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gimp_help_set_help_data (button, NULL, - "dialogs/palette_editor/import_palette.html"); - gtk_widget_show (button); - - button = gtk_button_new_with_label (_("Merge")); - GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT); - gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (palette_dialog_merge_callback), - palette_dialog); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gimp_help_set_help_data (button, NULL, - "dialogs/palette_editor/merge_palette.html"); - gtk_widget_show (button); - } - - gtk_widget_realize (palette_dialog->shell); - - palette_dialog->gc = gdk_gc_new (palette_dialog->shell->window); - - /* fill the clist */ - palette_clist_init (palette_dialog->clist, - palette_dialog->shell, - palette_dialog->gc); - palette_dialog_clist_scroll_to_current (palette_dialog); - - palette_dialog_create_popup_menu (palette_dialog); - - return palette_dialog; +} + +static void +palette_dialog_edit_palette (GimpData *data) +{ + GimpPalette *palette; + + palette = GIMP_PALETTE (data); + + palette_create_edit (palette); } diff --git a/app/widgets/gimppalettepreview.c b/app/widgets/gimppalettepreview.c index 9b2074e341..ee99362c9b 100644 --- a/app/widgets/gimppalettepreview.c +++ b/app/widgets/gimppalettepreview.c @@ -38,8 +38,8 @@ static void gimp_palette_preview_render (GimpPreview *preview); static GtkWidget * gimp_palette_preview_create_popup (GimpPreview *preview); static gboolean gimp_palette_preview_needs_popup (GimpPreview *preview); -static GimpPalette * gimp_palette_preview_drag_palette (GtkWidget *widget, - gpointer data); +static GimpViewable * gimp_palette_preview_drag_viewable (GtkWidget *widget, + gpointer data); static GimpPreviewClass *parent_class = NULL; @@ -89,20 +89,14 @@ gimp_palette_preview_class_init (GimpPalettePreviewClass *klass) static void gimp_palette_preview_init (GimpPalettePreview *palette_preview) { - static GtkTargetEntry preview_target_table[] = - { - GIMP_TARGET_PALETTE - }; - static guint preview_n_targets = (sizeof (preview_target_table) / - sizeof (preview_target_table[0])); - - gtk_drag_source_set (GTK_WIDGET (palette_preview), - GDK_BUTTON2_MASK, - preview_target_table, preview_n_targets, - GDK_ACTION_COPY); - gimp_dnd_palette_source_set (GTK_WIDGET (palette_preview), - gimp_palette_preview_drag_palette, - palette_preview); + gimp_gtk_drag_source_set_by_type (GTK_WIDGET (palette_preview), + GDK_BUTTON2_MASK, + GIMP_TYPE_PALETTE, + GDK_ACTION_COPY); + gimp_dnd_viewable_source_set (GTK_WIDGET (palette_preview), + GIMP_TYPE_PALETTE, + gimp_palette_preview_drag_viewable, + palette_preview); } static void @@ -176,13 +170,9 @@ gimp_palette_preview_needs_popup (GimpPreview *preview) return FALSE; } -static GimpPalette * -gimp_palette_preview_drag_palette (GtkWidget *widget, - gpointer data) +static GimpViewable * +gimp_palette_preview_drag_viewable (GtkWidget *widget, + gpointer data) { - GimpPreview *preview; - - preview = GIMP_PREVIEW (data); - - return GIMP_PALETTE (preview->viewable); + return GIMP_PREVIEW (widget)->viewable; } diff --git a/app/widgets/gimppatternpreview.c b/app/widgets/gimppatternpreview.c index 13916d7575..e69cacfc11 100644 --- a/app/widgets/gimppatternpreview.c +++ b/app/widgets/gimppatternpreview.c @@ -34,12 +34,12 @@ static void gimp_pattern_preview_class_init (GimpPatternPreviewClass *klass); static void gimp_pattern_preview_init (GimpPatternPreview *preview); -static void gimp_pattern_preview_render (GimpPreview *preview); -static GtkWidget * gimp_pattern_preview_create_popup (GimpPreview *preview); -static gboolean gimp_pattern_preview_needs_popup (GimpPreview *preview); +static void gimp_pattern_preview_render (GimpPreview *preview); +static GtkWidget * gimp_pattern_preview_create_popup (GimpPreview *preview); +static gboolean gimp_pattern_preview_needs_popup (GimpPreview *preview); -static GimpPattern * gimp_pattern_preview_drag_pattern (GtkWidget *widget, - gpointer data); +static GimpViewable * gimp_pattern_preview_drag_viewable (GtkWidget *widget, + gpointer data); static GimpPreviewClass *parent_class = NULL; @@ -89,20 +89,14 @@ gimp_pattern_preview_class_init (GimpPatternPreviewClass *klass) static void gimp_pattern_preview_init (GimpPatternPreview *pattern_preview) { - static GtkTargetEntry preview_target_table[] = - { - GIMP_TARGET_PATTERN - }; - static guint preview_n_targets = (sizeof (preview_target_table) / - sizeof (preview_target_table[0])); - - gtk_drag_source_set (GTK_WIDGET (pattern_preview), - GDK_BUTTON2_MASK, - preview_target_table, preview_n_targets, - GDK_ACTION_COPY); - gimp_dnd_pattern_source_set (GTK_WIDGET (pattern_preview), - gimp_pattern_preview_drag_pattern, - pattern_preview); + gimp_gtk_drag_source_set_by_type (GTK_WIDGET (pattern_preview), + GDK_BUTTON2_MASK, + GIMP_TYPE_PATTERN, + GDK_ACTION_COPY); + gimp_dnd_viewable_source_set (GTK_WIDGET (pattern_preview), + GIMP_TYPE_PATTERN, + gimp_pattern_preview_drag_viewable, + NULL); } static void @@ -184,13 +178,9 @@ gimp_pattern_preview_needs_popup (GimpPreview *preview) return FALSE; } -static GimpPattern * -gimp_pattern_preview_drag_pattern (GtkWidget *widget, - gpointer data) +static GimpViewable * +gimp_pattern_preview_drag_viewable (GtkWidget *widget, + gpointer data) { - GimpPreview *preview; - - preview = GIMP_PREVIEW (data); - - return GIMP_PATTERN (preview->viewable); + return GIMP_PREVIEW (widget)->viewable; } diff --git a/app/widgets/gimppreviewrendererbrush.c b/app/widgets/gimppreviewrendererbrush.c index c3f012af3b..bc4ae1f20d 100644 --- a/app/widgets/gimppreviewrendererbrush.c +++ b/app/widgets/gimppreviewrendererbrush.c @@ -41,8 +41,8 @@ static GtkWidget * gimp_brush_preview_create_popup (GimpPreview *preview) static gboolean gimp_brush_preview_needs_popup (GimpPreview *preview); static gboolean gimp_brush_preview_render_timeout_func (GimpBrushPreview *preview); -static GimpBrush * gimp_brush_preview_drag_brush (GtkWidget *widget, - gpointer data); +static GimpViewable * gimp_brush_preview_drag_viewable (GtkWidget *widget, + gpointer data); static GimpPreviewClass *parent_class = NULL; @@ -94,20 +94,14 @@ gimp_brush_preview_class_init (GimpBrushPreviewClass *klass) static void gimp_brush_preview_init (GimpBrushPreview *brush_preview) { - static GtkTargetEntry preview_target_table[] = - { - GIMP_TARGET_BRUSH - }; - static guint preview_n_targets = (sizeof (preview_target_table) / - sizeof (preview_target_table[0])); - - gtk_drag_source_set (GTK_WIDGET (brush_preview), - GDK_BUTTON2_MASK, - preview_target_table, preview_n_targets, - GDK_ACTION_COPY); - gimp_dnd_brush_source_set (GTK_WIDGET (brush_preview), - gimp_brush_preview_drag_brush, - brush_preview); + gimp_gtk_drag_source_set_by_type (GTK_WIDGET (brush_preview), + GDK_BUTTON2_MASK, + GIMP_TYPE_BRUSH, + GDK_ACTION_COPY); + gimp_dnd_viewable_source_set (GTK_WIDGET (brush_preview), + GIMP_TYPE_BRUSH, + gimp_brush_preview_drag_viewable, + NULL); brush_preview->pipe_timeout_id = 0; brush_preview->pipe_animation_index = 0; @@ -379,13 +373,9 @@ gimp_brush_preview_render_timeout_func (GimpBrushPreview *brush_preview) return TRUE; } -static GimpBrush * -gimp_brush_preview_drag_brush (GtkWidget *widget, - gpointer data) +static GimpViewable * +gimp_brush_preview_drag_viewable (GtkWidget *widget, + gpointer data) { - GimpPreview *preview; - - preview = GIMP_PREVIEW (data); - - return GIMP_BRUSH (preview->viewable); + return GIMP_PREVIEW (widget)->viewable; } diff --git a/app/widgets/gimpviewrendererbrush.c b/app/widgets/gimpviewrendererbrush.c index c3f012af3b..bc4ae1f20d 100644 --- a/app/widgets/gimpviewrendererbrush.c +++ b/app/widgets/gimpviewrendererbrush.c @@ -41,8 +41,8 @@ static GtkWidget * gimp_brush_preview_create_popup (GimpPreview *preview) static gboolean gimp_brush_preview_needs_popup (GimpPreview *preview); static gboolean gimp_brush_preview_render_timeout_func (GimpBrushPreview *preview); -static GimpBrush * gimp_brush_preview_drag_brush (GtkWidget *widget, - gpointer data); +static GimpViewable * gimp_brush_preview_drag_viewable (GtkWidget *widget, + gpointer data); static GimpPreviewClass *parent_class = NULL; @@ -94,20 +94,14 @@ gimp_brush_preview_class_init (GimpBrushPreviewClass *klass) static void gimp_brush_preview_init (GimpBrushPreview *brush_preview) { - static GtkTargetEntry preview_target_table[] = - { - GIMP_TARGET_BRUSH - }; - static guint preview_n_targets = (sizeof (preview_target_table) / - sizeof (preview_target_table[0])); - - gtk_drag_source_set (GTK_WIDGET (brush_preview), - GDK_BUTTON2_MASK, - preview_target_table, preview_n_targets, - GDK_ACTION_COPY); - gimp_dnd_brush_source_set (GTK_WIDGET (brush_preview), - gimp_brush_preview_drag_brush, - brush_preview); + gimp_gtk_drag_source_set_by_type (GTK_WIDGET (brush_preview), + GDK_BUTTON2_MASK, + GIMP_TYPE_BRUSH, + GDK_ACTION_COPY); + gimp_dnd_viewable_source_set (GTK_WIDGET (brush_preview), + GIMP_TYPE_BRUSH, + gimp_brush_preview_drag_viewable, + NULL); brush_preview->pipe_timeout_id = 0; brush_preview->pipe_animation_index = 0; @@ -379,13 +373,9 @@ gimp_brush_preview_render_timeout_func (GimpBrushPreview *brush_preview) return TRUE; } -static GimpBrush * -gimp_brush_preview_drag_brush (GtkWidget *widget, - gpointer data) +static GimpViewable * +gimp_brush_preview_drag_viewable (GtkWidget *widget, + gpointer data) { - GimpPreview *preview; - - preview = GIMP_PREVIEW (data); - - return GIMP_BRUSH (preview->viewable); + return GIMP_PREVIEW (widget)->viewable; } diff --git a/plug-ins/script-fu/scripts/Makefile.am b/plug-ins/script-fu/scripts/Makefile.am index a51220863b..edead4e2fa 100644 --- a/plug-ins/script-fu/scripts/Makefile.am +++ b/plug-ins/script-fu/scripts/Makefile.am @@ -97,11 +97,12 @@ scriptdata_DATA = \ unsharp-mask.scm \ waves-anim.scm \ weave.scm \ - xach-effect.scm - -EXTRA_DIST = $(scriptdata_DATA) \ + xach-effect.scm \ + \ test-sphere.scm +EXTRA_DIST = $(scriptdata_DATA) + files: @files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \ echo $$p; \