From 8710fa8941546be0e7ed9ff933cb77ab3ff00844 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 19 Feb 2001 22:54:12 +0000 Subject: [PATCH] app/commands.[ch] first version of the new layers and channels dialogs. 2001-02-19 Michael Natterer * app/commands.[ch] * app/menus.c: first version of the new layers and channels dialogs. * app/gimpcontainergridview.c * app/gimpcontainerlistview.c: allow creation with a NULL container. * app/gimpdnd.[ch]: added generic DND functions for all drawable types (not just setting the DND icon). Started to remove code duplication. * app/gimpdrawablepreview.c: with some magic calculations and ugly assumptions the drawable previews now look exactly like in the old L&C dialog. * app/gimpimagepreview.c: no need to say "return" at the end of a void function. * app/gimppreview.[ch]: added the "is_popup" boolean also to the default constructor. Call gimp_preview_set_viewable() before calculating the preview size. --- ChangeLog | 23 ++ app/actions/help-commands.c | 126 ++++++- app/actions/help-commands.h | 9 +- app/commands.c | 126 ++++++- app/commands.h | 9 +- app/gimpcontainergridview.c | 6 +- app/gimpcontainerlistview.c | 8 +- app/gimpdnd.c | 420 ++++++++++++++++------ app/gimpdnd.h | 33 ++ app/gimpdrawablepreview.c | 230 ++++++++++++ app/gimpimagepreview.c | 2 - app/gimppreview.c | 11 +- app/gimppreview.h | 3 +- app/gui/commands.c | 126 ++++++- app/gui/commands.h | 9 +- app/gui/help-commands.c | 126 ++++++- app/gui/help-commands.h | 9 +- app/gui/menus.c | 36 +- app/menus.c | 36 +- app/menus/menus.c | 36 +- app/widgets/gimpcontainergridview.c | 6 +- app/widgets/gimpcontainerlistview.c | 8 +- app/widgets/gimpdnd.c | 420 ++++++++++++++++------ app/widgets/gimpdnd.h | 33 ++ app/widgets/gimpdrawablepreview.c | 230 ++++++++++++ app/widgets/gimpimagepreview.c | 2 - app/widgets/gimpitemfactory.c | 36 +- app/widgets/gimppreview.c | 11 +- app/widgets/gimppreview.h | 3 +- app/widgets/gimppreviewrenderer.c | 11 +- app/widgets/gimppreviewrenderer.h | 3 +- app/widgets/gimppreviewrendererdrawable.c | 230 ++++++++++++ app/widgets/gimppreviewrendererimage.c | 2 - app/widgets/gimpview.c | 11 +- app/widgets/gimpview.h | 3 +- app/widgets/gimpviewrenderer.c | 11 +- app/widgets/gimpviewrenderer.h | 3 +- app/widgets/gimpviewrendererdrawable.c | 230 ++++++++++++ app/widgets/gimpviewrendererimage.c | 2 - 39 files changed, 2320 insertions(+), 319 deletions(-) diff --git a/ChangeLog b/ChangeLog index fdfdcaf5cd..72e841bb4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2001-02-19 Michael Natterer + + * app/commands.[ch] + * app/menus.c: first version of the new layers and channels dialogs. + + * app/gimpcontainergridview.c + * app/gimpcontainerlistview.c: allow creation with a NULL container. + + * app/gimpdnd.[ch]: added generic DND functions for all drawable + types (not just setting the DND icon). Started to remove code + duplication. + + * app/gimpdrawablepreview.c: with some magic calculations and ugly + assumptions the drawable previews now look exactly like in the old + L&C dialog. + + * app/gimpimagepreview.c: no need to say "return" at the end of a + void function. + + * app/gimppreview.[ch]: added the "is_popup" boolean also to the + default constructor. Call gimp_preview_set_viewable() before + calculating the preview size. + 2001-02-19 Michael Natterer * app/Makefile.am diff --git a/app/actions/help-commands.c b/app/actions/help-commands.c index 2b87e48d48..cbce8f3aa6 100644 --- a/app/actions/help-commands.c +++ b/app/actions/help-commands.c @@ -938,8 +938,8 @@ layers_previous_cmd_callback (GtkWidget *widget, current_layer = gimp_image_get_layer_index (gdisp->gimage, gdisp->gimage->active_layer); - new_layer = gimp_container_get_child_by_index (gdisp->gimage->layers, - current_layer - 1); + new_layer = (GimpLayer *) gimp_container_get_child_by_index (gdisp->gimage->layers, + current_layer - 1); if (new_layer) { @@ -962,8 +962,8 @@ layers_next_cmd_callback (GtkWidget *widget, current_layer = gimp_image_get_layer_index (gdisp->gimage, gdisp->gimage->active_layer); - new_layer = gimp_container_get_child_by_index (gdisp->gimage->layers, - current_layer + 1); + new_layer = (GimpLayer *) gimp_container_get_child_by_index (gdisp->gimage->layers, + current_layer + 1); if (new_layer) { @@ -1779,6 +1779,124 @@ dialogs_test_multi_container_grid_view_cmd_callback (GtkWidget *widget, 32); } +static void +layers_view_image_changed (GimpContext *context, + GimpImage *gimage, + GimpContainerView *view) +{ + gimp_container_view_set_container (view, gimage ? gimage->layers : NULL); +} + +static void +channels_view_image_changed (GimpContext *context, + GimpImage *gimage, + GimpContainerView *view) +{ + gimp_container_view_set_container (view, gimage ? gimage->channels : NULL); +} + +static void +drawable_view_new (GimpViewType view_type, + gchar *title, + gboolean channels, + GimpContext *context) +{ + GimpImage *gimage; + GtkWidget *dialog; + GtkWidget *view; + + if (view_type == GIMP_VIEW_TYPE_LIST) + { + view = gimp_container_list_view_new (NULL, + NULL, + preview_size, + 5, 5); + } + else + { + view = gimp_container_grid_view_new (NULL, + NULL, + preview_size, + 5, 5); + } + + gimage = gimp_context_get_image (context); + + if (channels) + { + if (gimage) + gimp_container_view_set_container (GIMP_CONTAINER_VIEW (view), + gimage->channels); + + gtk_signal_connect (GTK_OBJECT (context), "image_changed", + GTK_SIGNAL_FUNC (channels_view_image_changed), + view); + } + else + { + if (gimage) + gimp_container_view_set_container (GIMP_CONTAINER_VIEW (view), + gimage->layers); + + gtk_signal_connect (GTK_OBJECT (context), "image_changed", + GTK_SIGNAL_FUNC (layers_view_image_changed), + view); + } + + dialog = gimp_dialog_new (title, "test", + gimp_standard_help_func, + NULL, + GTK_WIN_POS_MOUSE, + FALSE, TRUE, TRUE, + + "_delete_event_", gtk_widget_destroy, + NULL, 1, NULL, TRUE, TRUE, + + NULL); + + gtk_widget_hide (GTK_DIALOG (dialog)->action_area); + /* + gtk_widget_hide (GTK_WIDGET (g_list_nth_data (gtk_container_children (GTK_CONTAINER (GTK_BIN (dialog)->child)), 1))); + */ + + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), view); + gtk_widget_show (view); + + gtk_widget_show (dialog); +} + +void +dialogs_test_layer_list_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_LIST, "Layer List", FALSE, + gimp_context_get_user ()); +} + +void +dialogs_test_layer_grid_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_GRID, "Layer Grid", FALSE, + gimp_context_get_user ()); +} + +void +dialogs_test_channel_list_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_LIST, "Channel List", TRUE, + gimp_context_get_user ()); +} + +void +dialogs_test_channel_grid_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_GRID, "Channel Grid", TRUE, + gimp_context_get_user ()); +} + /***** Help *****/ void diff --git a/app/actions/help-commands.h b/app/actions/help-commands.h index 03e76e43aa..d097bc0e83 100644 --- a/app/actions/help-commands.h +++ b/app/actions/help-commands.h @@ -142,8 +142,13 @@ void dialogs_test_pattern_container_grid_view_cmd_callback (GtkWidget *, gpoint void dialogs_test_gradient_container_grid_view_cmd_callback (GtkWidget *, gpointer); void dialogs_test_palette_container_grid_view_cmd_callback (GtkWidget *, gpointer); -void dialogs_test_multi_container_list_view_cmd_callback (GtkWidget *, gpointer); -void dialogs_test_multi_container_grid_view_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_multi_container_list_view_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_multi_container_grid_view_cmd_callback (GtkWidget *, gpointer); + +void dialogs_test_layer_list_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_layer_grid_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_channel_list_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_channel_grid_cmd_callback (GtkWidget *, gpointer); void help_help_cmd_callback (GtkWidget *, gpointer); void help_context_help_cmd_callback (GtkWidget *, gpointer); diff --git a/app/commands.c b/app/commands.c index 2b87e48d48..cbce8f3aa6 100644 --- a/app/commands.c +++ b/app/commands.c @@ -938,8 +938,8 @@ layers_previous_cmd_callback (GtkWidget *widget, current_layer = gimp_image_get_layer_index (gdisp->gimage, gdisp->gimage->active_layer); - new_layer = gimp_container_get_child_by_index (gdisp->gimage->layers, - current_layer - 1); + new_layer = (GimpLayer *) gimp_container_get_child_by_index (gdisp->gimage->layers, + current_layer - 1); if (new_layer) { @@ -962,8 +962,8 @@ layers_next_cmd_callback (GtkWidget *widget, current_layer = gimp_image_get_layer_index (gdisp->gimage, gdisp->gimage->active_layer); - new_layer = gimp_container_get_child_by_index (gdisp->gimage->layers, - current_layer + 1); + new_layer = (GimpLayer *) gimp_container_get_child_by_index (gdisp->gimage->layers, + current_layer + 1); if (new_layer) { @@ -1779,6 +1779,124 @@ dialogs_test_multi_container_grid_view_cmd_callback (GtkWidget *widget, 32); } +static void +layers_view_image_changed (GimpContext *context, + GimpImage *gimage, + GimpContainerView *view) +{ + gimp_container_view_set_container (view, gimage ? gimage->layers : NULL); +} + +static void +channels_view_image_changed (GimpContext *context, + GimpImage *gimage, + GimpContainerView *view) +{ + gimp_container_view_set_container (view, gimage ? gimage->channels : NULL); +} + +static void +drawable_view_new (GimpViewType view_type, + gchar *title, + gboolean channels, + GimpContext *context) +{ + GimpImage *gimage; + GtkWidget *dialog; + GtkWidget *view; + + if (view_type == GIMP_VIEW_TYPE_LIST) + { + view = gimp_container_list_view_new (NULL, + NULL, + preview_size, + 5, 5); + } + else + { + view = gimp_container_grid_view_new (NULL, + NULL, + preview_size, + 5, 5); + } + + gimage = gimp_context_get_image (context); + + if (channels) + { + if (gimage) + gimp_container_view_set_container (GIMP_CONTAINER_VIEW (view), + gimage->channels); + + gtk_signal_connect (GTK_OBJECT (context), "image_changed", + GTK_SIGNAL_FUNC (channels_view_image_changed), + view); + } + else + { + if (gimage) + gimp_container_view_set_container (GIMP_CONTAINER_VIEW (view), + gimage->layers); + + gtk_signal_connect (GTK_OBJECT (context), "image_changed", + GTK_SIGNAL_FUNC (layers_view_image_changed), + view); + } + + dialog = gimp_dialog_new (title, "test", + gimp_standard_help_func, + NULL, + GTK_WIN_POS_MOUSE, + FALSE, TRUE, TRUE, + + "_delete_event_", gtk_widget_destroy, + NULL, 1, NULL, TRUE, TRUE, + + NULL); + + gtk_widget_hide (GTK_DIALOG (dialog)->action_area); + /* + gtk_widget_hide (GTK_WIDGET (g_list_nth_data (gtk_container_children (GTK_CONTAINER (GTK_BIN (dialog)->child)), 1))); + */ + + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), view); + gtk_widget_show (view); + + gtk_widget_show (dialog); +} + +void +dialogs_test_layer_list_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_LIST, "Layer List", FALSE, + gimp_context_get_user ()); +} + +void +dialogs_test_layer_grid_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_GRID, "Layer Grid", FALSE, + gimp_context_get_user ()); +} + +void +dialogs_test_channel_list_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_LIST, "Channel List", TRUE, + gimp_context_get_user ()); +} + +void +dialogs_test_channel_grid_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_GRID, "Channel Grid", TRUE, + gimp_context_get_user ()); +} + /***** Help *****/ void diff --git a/app/commands.h b/app/commands.h index 03e76e43aa..d097bc0e83 100644 --- a/app/commands.h +++ b/app/commands.h @@ -142,8 +142,13 @@ void dialogs_test_pattern_container_grid_view_cmd_callback (GtkWidget *, gpoint void dialogs_test_gradient_container_grid_view_cmd_callback (GtkWidget *, gpointer); void dialogs_test_palette_container_grid_view_cmd_callback (GtkWidget *, gpointer); -void dialogs_test_multi_container_list_view_cmd_callback (GtkWidget *, gpointer); -void dialogs_test_multi_container_grid_view_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_multi_container_list_view_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_multi_container_grid_view_cmd_callback (GtkWidget *, gpointer); + +void dialogs_test_layer_list_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_layer_grid_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_channel_list_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_channel_grid_cmd_callback (GtkWidget *, gpointer); void help_help_cmd_callback (GtkWidget *, gpointer); void help_context_help_cmd_callback (GtkWidget *, gpointer); diff --git a/app/gimpcontainergridview.c b/app/gimpcontainergridview.c index 94fe259cb2..60b6184582 100644 --- a/app/gimpcontainergridview.c +++ b/app/gimpcontainergridview.c @@ -177,8 +177,7 @@ gimp_container_grid_view_new (GimpContainer *container, GimpContainerView *view; gint window_border; - g_return_val_if_fail (container != NULL, NULL); - g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL); + g_return_val_if_fail (! container || GIMP_IS_CONTAINER (container), NULL); g_return_val_if_fail (! context || GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (preview_size > 0 && preview_size <= 64, NULL); g_return_val_if_fail (min_items_x > 0 && min_items_x <= 64, NULL); @@ -199,7 +198,8 @@ gimp_container_grid_view_new (GimpContainer *container, (preview_size + 2) * min_items_x + window_border, (preview_size + 2) * min_items_y + window_border); - gimp_container_view_set_container (view, container); + if (container) + gimp_container_view_set_container (view, container); gimp_container_view_set_context (view, context); diff --git a/app/gimpcontainerlistview.c b/app/gimpcontainerlistview.c index 853046ba75..36f4b7568a 100644 --- a/app/gimpcontainerlistview.c +++ b/app/gimpcontainerlistview.c @@ -174,8 +174,7 @@ gimp_container_list_view_new (GimpContainer *container, GimpContainerView *view; gint window_border; - g_return_val_if_fail (container != NULL, NULL); - g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL); + g_return_val_if_fail (! container || GIMP_IS_CONTAINER (container), NULL); g_return_val_if_fail (! context || GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (preview_size > 0 && preview_size <= 64, NULL); g_return_val_if_fail (min_items_x > 0 && min_items_x <= 64, NULL); @@ -196,7 +195,8 @@ gimp_container_list_view_new (GimpContainer *container, (preview_size + 2) * min_items_x + window_border, (preview_size + 6) * min_items_y + window_border); - gimp_container_view_set_container (view, container); + if (container) + gimp_container_view_set_container (view, container); gimp_container_view_set_context (view, context); @@ -224,7 +224,7 @@ gimp_container_list_view_insert_item (GimpContainerView *view, gtk_container_add (GTK_CONTAINER (list_item), hbox); gtk_widget_show (hbox); - preview = gimp_preview_new (viewable, view->preview_size, 1); + preview = gimp_preview_new (viewable, view->preview_size, 1, FALSE); gtk_box_pack_start (GTK_BOX (hbox), preview, FALSE, FALSE, 0); gtk_widget_show (preview); diff --git a/app/gimpdnd.c b/app/gimpdnd.c index d9053f841c..72449e1866 100644 --- a/app/gimpdnd.c +++ b/app/gimpdnd.c @@ -18,6 +18,7 @@ #include "config.h" +#include #include #include @@ -31,11 +32,14 @@ #include "fileops.h" #include "gimpimage.h" #include "gimpbrush.h" +#include "gimpchannel.h" #include "gimpcontainer.h" #include "gimpdatafactory.h" #include "gimpdnd.h" #include "gimpdrawable.h" #include "gimpgradient.h" +#include "gimplayer.h" +#include "gimplayermask.h" #include "gimppalette.h" #include "gimppattern.h" #include "gimppreview.h" @@ -54,6 +58,9 @@ typedef enum { GIMP_DND_DATA_COLOR = 1, + GIMP_DND_DATA_LAYER, + GIMP_DND_DATA_CHANNEL, + GIMP_DND_DATA_LAYER_MASK, GIMP_DND_DATA_BRUSH, GIMP_DND_DATA_PATTERN, GIMP_DND_DATA_GRADIENT, @@ -94,21 +101,12 @@ struct _GimpDndDataDef }; +static GtkWidget * gimp_dnd_get_viewable_icon (GtkWidget *widget, + GtkSignalFunc get_viewable_func, + gpointer get_viewable_data); static GtkWidget * gimp_dnd_get_color_icon (GtkWidget *widget, GtkSignalFunc get_color_func, gpointer get_color_data); -static GtkWidget * gimp_dnd_get_brush_icon (GtkWidget *widget, - GtkSignalFunc get_brush_func, - gpointer get_brush_data); -static GtkWidget * gimp_dnd_get_pattern_icon (GtkWidget *widget, - GtkSignalFunc get_pattern_func, - gpointer get_pattern_data); -static GtkWidget * gimp_dnd_get_gradient_icon (GtkWidget *widget, - GtkSignalFunc get_gradient_func, - gpointer get_gradient_data); -static GtkWidget * gimp_dnd_get_palette_icon (GtkWidget *widget, - GtkSignalFunc get_palette_func, - gpointer get_palette_data); static GtkWidget * gimp_dnd_get_tool_icon (GtkWidget *widget, GtkSignalFunc get_tool_func, gpointer get_tool_data); @@ -118,6 +116,11 @@ static guchar * gimp_dnd_get_color_data (GtkWidget *widget, gpointer get_color_data, gint *format, gint *length); +static guchar * gimp_dnd_get_drawable_data (GtkWidget *widget, + GtkSignalFunc get_drawable_func, + gpointer get_drawable_data, + gint *format, + gint *length); static guchar * gimp_dnd_get_brush_data (GtkWidget *widget, GtkSignalFunc get_brush_func, gpointer get_brush_data, @@ -150,6 +153,12 @@ static void gimp_dnd_set_color_data (GtkWidget *widget, guchar *vals, gint format, gint length); +static void gimp_dnd_set_drawable_data (GtkWidget *widget, + GtkSignalFunc set_drawable_func, + gpointer set_drawable_data, + guchar *vals, + gint format, + gint length); static void gimp_dnd_set_brush_data (GtkWidget *widget, GtkSignalFunc set_brush_func, gpointer set_brush_data, @@ -206,13 +215,46 @@ static GimpDndDataDef dnd_data_defs[] = gimp_dnd_set_color_data }, + { + GIMP_TARGET_LAYER, + + "gimp_dnd_set_layer_func", + "gimp_dnd_set_layer_data", + + gimp_dnd_get_viewable_icon, + gimp_dnd_get_drawable_data, + gimp_dnd_set_drawable_data, + }, + + { + GIMP_TARGET_CHANNEL, + + "gimp_dnd_set_channel_func", + "gimp_dnd_set_channel_data", + + gimp_dnd_get_viewable_icon, + gimp_dnd_get_drawable_data, + gimp_dnd_set_drawable_data, + }, + + { + GIMP_TARGET_LAYER_MASK, + + "gimp_dnd_set_layer_mask_func", + "gimp_dnd_set_layer_mask_data", + + gimp_dnd_get_viewable_icon, + gimp_dnd_get_drawable_data, + gimp_dnd_set_drawable_data, + }, + { GIMP_TARGET_BRUSH, "gimp_dnd_set_brush_func", "gimp_dnd_set_brush_data", - gimp_dnd_get_brush_icon, + gimp_dnd_get_viewable_icon, gimp_dnd_get_brush_data, gimp_dnd_set_brush_data }, @@ -223,7 +265,7 @@ static GimpDndDataDef dnd_data_defs[] = "gimp_dnd_set_pattern_func", "gimp_dnd_set_pattern_data", - gimp_dnd_get_pattern_icon, + gimp_dnd_get_viewable_icon, gimp_dnd_get_pattern_data, gimp_dnd_set_pattern_data }, @@ -234,7 +276,7 @@ static GimpDndDataDef dnd_data_defs[] = "gimp_dnd_set_gradient_func", "gimp_dnd_set_gradient_data", - gimp_dnd_get_gradient_icon, + gimp_dnd_get_viewable_icon, gimp_dnd_get_gradient_data, gimp_dnd_set_gradient_data }, @@ -245,7 +287,7 @@ static GimpDndDataDef dnd_data_defs[] = "gimp_dnd_set_palette_func", "gimp_dnd_set_palette_data", - gimp_dnd_get_palette_icon, + gimp_dnd_get_viewable_icon, gimp_dnd_get_palette_data, gimp_dnd_set_palette_data }, @@ -624,6 +666,46 @@ gimp_dnd_color_dest_unset (GtkWidget *widget) /* GimpViewable (by GtkType) dnd functions */ /*********************************************/ +static GtkWidget * +gimp_dnd_get_viewable_icon (GtkWidget *widget, + GtkSignalFunc get_viewable_func, + gpointer get_viewable_data) +{ + GtkWidget *preview; + GimpViewable *viewable; + + viewable = (* (GimpDndDragViewableFunc) get_viewable_func) (widget, + get_viewable_data); + + if (! viewable) + return NULL; + + preview = gimp_preview_new (viewable, DRAG_PREVIEW_SIZE, 0, TRUE); + + return preview; +} + +static const GtkTargetEntry layer_target_table[] = +{ + GIMP_TARGET_LAYER +}; +static const guint layer_n_targets = (sizeof (layer_target_table) / + sizeof (layer_target_table[0])); + +static const GtkTargetEntry channel_target_table[] = +{ + GIMP_TARGET_CHANNEL +}; +static const guint channel_n_targets = (sizeof (channel_target_table) / + sizeof (layer_target_table[0])); + +static const GtkTargetEntry layer_mask_target_table[] = +{ + GIMP_TARGET_LAYER_MASK +}; +static const guint layer_mask_n_targets = (sizeof (layer_mask_target_table) / + sizeof (layer_mask_target_table[0])); + static const GtkTargetEntry brush_target_table[] = { GIMP_TARGET_BRUSH @@ -662,7 +744,22 @@ gimp_gtk_drag_source_set_by_type (GtkWidget *widget, const GtkTargetEntry *target_table = NULL; guint n_targets = 0; - if (type == GIMP_TYPE_BRUSH) + if (type == GIMP_TYPE_LAYER) + { + target_table = layer_target_table; + n_targets = layer_n_targets; + } + else if (type == GIMP_TYPE_CHANNEL) + { + target_table = channel_target_table; + n_targets = channel_n_targets; + } + else if (type == GIMP_TYPE_LAYER_MASK) + { + target_table = layer_mask_target_table; + n_targets = layer_mask_n_targets; + } + else if (type == GIMP_TYPE_BRUSH) { target_table = brush_target_table; n_targets = brush_n_targets; @@ -706,7 +803,22 @@ gimp_gtk_drag_dest_set_by_type (GtkWidget *widget, const GtkTargetEntry *target_table = NULL; guint n_targets = 0; - if (type == GIMP_TYPE_BRUSH) + if (type == GIMP_TYPE_LAYER) + { + target_table = layer_target_table; + n_targets = layer_n_targets; + } + else if (type == GIMP_TYPE_CHANNEL) + { + target_table = channel_target_table; + n_targets = channel_n_targets; + } + else if (type == GIMP_TYPE_LAYER_MASK) + { + target_table = layer_mask_target_table; + n_targets = layer_mask_n_targets; + } + else if (type == GIMP_TYPE_BRUSH) { target_table = brush_target_table; n_targets = brush_n_targets; @@ -746,7 +858,25 @@ gimp_dnd_viewable_source_set (GtkWidget *widget, GimpDndDragViewableFunc get_viewable_func, gpointer data) { - if (type == GIMP_TYPE_BRUSH) + if (type == GIMP_TYPE_LAYER) + { + gimp_dnd_layer_source_set (widget, + (GimpDndDragDrawableFunc) get_viewable_func, + data); + } + else if (type == GIMP_TYPE_CHANNEL) + { + gimp_dnd_channel_source_set (widget, + (GimpDndDragDrawableFunc) get_viewable_func, + data); + } + else if (type == GIMP_TYPE_LAYER_MASK) + { + gimp_dnd_layer_mask_source_set (widget, + (GimpDndDragDrawableFunc) get_viewable_func, + data); + } + else if (type == GIMP_TYPE_BRUSH) { gimp_dnd_brush_source_set (widget, (GimpDndDragBrushFunc) get_viewable_func, @@ -782,7 +912,25 @@ gimp_dnd_viewable_dest_set (GtkWidget *widget, GimpDndDropViewableFunc set_viewable_func, gpointer data) { - if (type == GIMP_TYPE_BRUSH) + if (type == GIMP_TYPE_LAYER) + { + gimp_dnd_layer_dest_set (widget, + (GimpDndDropDrawableFunc) set_viewable_func, + data); + } + else if (type == GIMP_TYPE_CHANNEL) + { + gimp_dnd_channel_dest_set (widget, + (GimpDndDropDrawableFunc) set_viewable_func, + data); + } + else if (type == GIMP_TYPE_LAYER_MASK) + { + gimp_dnd_layer_mask_dest_set (widget, + (GimpDndDropDrawableFunc) set_viewable_func, + data); + } + else if (type == GIMP_TYPE_BRUSH) { gimp_dnd_brush_dest_set (widget, (GimpDndDropBrushFunc) set_viewable_func, @@ -816,7 +964,19 @@ void gimp_dnd_viewable_dest_unset (GtkWidget *widget, GtkType type) { - if (type == GIMP_TYPE_BRUSH) + if (type == GIMP_TYPE_LAYER) + { + gimp_dnd_layer_dest_unset (widget); + } + else if (type == GIMP_TYPE_CHANNEL) + { + gimp_dnd_channel_dest_unset (widget); + } + else if (type == GIMP_TYPE_LAYER_MASK) + { + gimp_dnd_layer_mask_dest_unset (widget); + } + else if (type == GIMP_TYPE_BRUSH) { gimp_dnd_brush_dest_unset (widget); } @@ -839,28 +999,149 @@ gimp_dnd_viewable_dest_unset (GtkWidget *widget, } +/****************************/ +/* drawable dnd functions */ +/****************************/ + +static guchar * +gimp_dnd_get_drawable_data (GtkWidget *widget, + GtkSignalFunc get_drawable_func, + gpointer get_drawable_data, + gint *format, + gint *length) +{ + GimpDrawable *drawable; + gchar *id; + + drawable = + (* (GimpDndDragDrawableFunc) get_drawable_func) (widget, get_drawable_data); + + if (! drawable) + return NULL; + + id = g_strdup_printf ("%d", gimp_drawable_get_ID (drawable)); + + *format = 8; + *length = strlen (id) + 1; + + return (guchar *) id; +} + +static void +gimp_dnd_set_drawable_data (GtkWidget *widget, + GtkSignalFunc set_drawable_func, + gpointer set_drawable_data, + guchar *vals, + gint format, + gint length) +{ + GimpDrawable *drawable; + gchar *id; + gint ID; + + if ((format != 8) || (length < 1)) + { + g_warning ("Received invalid drawable ID data"); + return; + } + + id = (gchar *) vals; + + ID = atoi (id); + + if (! ID) + return; + + drawable = gimp_drawable_get_by_ID (ID); + + if (drawable) + (* (GimpDndDropDrawableFunc) set_drawable_func) (widget, drawable, + set_drawable_data); +} + +void +gimp_dnd_layer_source_set (GtkWidget *widget, + GimpDndDragDrawableFunc get_drawable_func, + gpointer data) +{ + gimp_dnd_data_source_set (GIMP_DND_DATA_LAYER, widget, + GTK_SIGNAL_FUNC (get_drawable_func), + data); +} + +void +gimp_dnd_layer_dest_set (GtkWidget *widget, + GimpDndDropDrawableFunc set_drawable_func, + gpointer data) +{ + gimp_dnd_data_dest_set (GIMP_DND_DATA_LAYER, widget, + GTK_SIGNAL_FUNC (set_drawable_func), + data); +} + +void +gimp_dnd_layer_dest_unset (GtkWidget *widget) +{ + gimp_dnd_data_dest_unset (GIMP_DND_DATA_LAYER, widget); +} + +void +gimp_dnd_channel_source_set (GtkWidget *widget, + GimpDndDragDrawableFunc get_drawable_func, + gpointer data) +{ + gimp_dnd_data_source_set (GIMP_DND_DATA_CHANNEL, widget, + GTK_SIGNAL_FUNC (get_drawable_func), + data); +} + +void +gimp_dnd_channel_dest_set (GtkWidget *widget, + GimpDndDropDrawableFunc set_drawable_func, + gpointer data) +{ + gimp_dnd_data_dest_set (GIMP_DND_DATA_CHANNEL, widget, + GTK_SIGNAL_FUNC (set_drawable_func), + data); +} + +void +gimp_dnd_channel_dest_unset (GtkWidget *widget) +{ + gimp_dnd_data_dest_unset (GIMP_DND_DATA_CHANNEL, widget); +} + +void +gimp_dnd_layer_mask_source_set (GtkWidget *widget, + GimpDndDragDrawableFunc get_drawable_func, + gpointer data) +{ + gimp_dnd_data_source_set (GIMP_DND_DATA_LAYER_MASK, widget, + GTK_SIGNAL_FUNC (get_drawable_func), + data); +} + +void +gimp_dnd_layer_mask_dest_set (GtkWidget *widget, + GimpDndDropDrawableFunc set_drawable_func, + gpointer data) +{ + gimp_dnd_data_dest_set (GIMP_DND_DATA_LAYER_MASK, widget, + GTK_SIGNAL_FUNC (set_drawable_func), + data); +} + +void +gimp_dnd_layer_mask_dest_unset (GtkWidget *widget) +{ + gimp_dnd_data_dest_unset (GIMP_DND_DATA_LAYER_MASK, widget); +} + + /*************************/ /* brush dnd functions */ /*************************/ -static GtkWidget * -gimp_dnd_get_brush_icon (GtkWidget *widget, - GtkSignalFunc get_brush_func, - gpointer get_brush_data) -{ - GtkWidget *preview; - GimpBrush *brush; - - brush = (* (GimpDndDragBrushFunc) get_brush_func) (widget, get_brush_data); - - if (! brush) - return NULL; - - preview = gimp_preview_new (GIMP_VIEWABLE (brush), DRAG_PREVIEW_SIZE, 0); - - return preview; -} - static guchar * gimp_dnd_get_brush_data (GtkWidget *widget, GtkSignalFunc get_brush_func, @@ -948,25 +1229,6 @@ gimp_dnd_brush_dest_unset (GtkWidget *widget) /* pattern dnd functions */ /***************************/ -static GtkWidget * -gimp_dnd_get_pattern_icon (GtkWidget *widget, - GtkSignalFunc get_pattern_func, - gpointer get_pattern_data) -{ - GtkWidget *preview; - GimpPattern *pattern; - - pattern = (* (GimpDndDragPatternFunc) get_pattern_func) (widget, - get_pattern_data); - - if (! pattern) - return NULL; - - preview = gimp_preview_new (GIMP_VIEWABLE (pattern), DRAG_PREVIEW_SIZE, 0); - - return preview; -} - static guchar * gimp_dnd_get_pattern_data (GtkWidget *widget, GtkSignalFunc get_pattern_func, @@ -1053,29 +1315,6 @@ gimp_dnd_pattern_dest_unset (GtkWidget *widget) /* gradient dnd functions */ /****************************/ -static GtkWidget * -gimp_dnd_get_gradient_icon (GtkWidget *widget, - GtkSignalFunc get_gradient_func, - gpointer get_gradient_data) -{ - GtkWidget *preview; - GimpGradient *gradient; - - gradient = - (* (GimpDndDragGradientFunc) get_gradient_func) (widget, get_gradient_data); - - if (! gradient) - return NULL; - - preview = gimp_preview_new_full (GIMP_VIEWABLE (gradient), - DRAG_PREVIEW_SIZE * 2, DRAG_PREVIEW_SIZE / 2, - 0, - TRUE, FALSE, FALSE); - - - return preview; -} - static guchar * gimp_dnd_get_gradient_data (GtkWidget *widget, GtkSignalFunc get_gradient_func, @@ -1162,25 +1401,6 @@ gimp_dnd_gradient_dest_unset (GtkWidget *widget) /* palette dnd functions */ /***************************/ -static GtkWidget * -gimp_dnd_get_palette_icon (GtkWidget *widget, - GtkSignalFunc get_palette_func, - gpointer get_palette_data) -{ - GtkWidget *preview; - GimpPalette *palette; - - palette = (* (GimpDndDragPaletteFunc) get_palette_func) (widget, - get_palette_data); - - if (! palette) - return NULL; - - preview = gimp_preview_new (GIMP_VIEWABLE (palette), DRAG_PREVIEW_SIZE, 0); - - return preview; -} - static guchar * gimp_dnd_get_palette_data (GtkWidget *widget, GtkSignalFunc get_palette_func, diff --git a/app/gimpdnd.h b/app/gimpdnd.h index 4f4707b76b..b827d34566 100644 --- a/app/gimpdnd.h +++ b/app/gimpdnd.h @@ -140,6 +140,39 @@ void gimp_dnd_viewable_dest_unset (GtkWidget *widget, GtkType type); +/* drawable dnd functions */ + +typedef void (* GimpDndDropDrawableFunc) (GtkWidget *widget, + GimpDrawable *drawable, + gpointer data); +typedef GimpDrawable * (* GimpDndDragDrawableFunc) (GtkWidget *widget, + gpointer data); + +void gimp_dnd_layer_source_set (GtkWidget *widget, + GimpDndDragDrawableFunc get_drawable_func, + gpointer data); +void gimp_dnd_layer_dest_set (GtkWidget *widget, + GimpDndDropDrawableFunc set_drawable_func, + gpointer data); +void gimp_dnd_layer_dest_unset (GtkWidget *widget); + +void gimp_dnd_channel_source_set (GtkWidget *widget, + GimpDndDragDrawableFunc get_drawable_func, + gpointer data); +void gimp_dnd_channel_dest_set (GtkWidget *widget, + GimpDndDropDrawableFunc set_drawable_func, + gpointer data); +void gimp_dnd_channel_dest_unset (GtkWidget *widget); + +void gimp_dnd_layer_mask_source_set (GtkWidget *widget, + GimpDndDragDrawableFunc get_drawable_func, + gpointer data); +void gimp_dnd_layer_mask_dest_set (GtkWidget *widget, + GimpDndDropDrawableFunc set_drawable_func, + gpointer data); +void gimp_dnd_layer_mask_dest_unset (GtkWidget *widget); + + /* brush dnd functions */ typedef void (* GimpDndDropBrushFunc) (GtkWidget *widget, diff --git a/app/gimpdrawablepreview.c b/app/gimpdrawablepreview.c index 294fd4ff64..978dc8ffbb 100644 --- a/app/gimpdrawablepreview.c +++ b/app/gimpdrawablepreview.c @@ -23,16 +23,32 @@ #include +#include "libgimpmath/gimpmath.h" + #include "apptypes.h" +#include "gimpdrawable.h" #include "gimpdrawablepreview.h" +#include "gimpimage.h" +#include "temp_buf.h" static void gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass); static void gimp_drawable_preview_init (GimpDrawablePreview *preview); static void gimp_drawable_preview_render (GimpPreview *preview); +static void gimp_drawable_preview_get_size (GimpPreview *preview, + gint size, + gint *width, + gint *height); static GtkWidget * gimp_drawable_preview_create_popup (GimpPreview *preview); +static void gimp_drawable_preview_calc_size (gint drawable_width, + gint drawable_height, + gint width, + gint height, + gint *return_width, + gint *return_height, + gboolean *scaling_up); static GimpPreviewClass *parent_class = NULL; @@ -73,6 +89,10 @@ gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass) preview_class = (GimpPreviewClass *) klass; parent_class = gtk_type_class (GIMP_TYPE_PREVIEW); + + preview_class->render = gimp_drawable_preview_render; + preview_class->get_size = gimp_drawable_preview_get_size; + preview_class->create_popup = gimp_drawable_preview_create_popup; } static void @@ -80,12 +100,222 @@ gimp_drawable_preview_init (GimpDrawablePreview *preview) { } +static void +gimp_drawable_preview_get_size (GimpPreview *preview, + gint size, + gint *width, + gint *height) +{ + GimpDrawable *drawable; + GimpImage *gimage; + gboolean scaling_up; + + drawable = GIMP_DRAWABLE (preview->viewable); + gimage = drawable->gimage; + + if (gimage) + { + gimp_drawable_preview_calc_size (gimage->width, + gimage->height, + size, + size, + width, + height, + &scaling_up); + } + else + { + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + size, + size, + width, + height, + &scaling_up); + } +} + static void gimp_drawable_preview_render (GimpPreview *preview) { + GimpDrawable *drawable; + GimpImage *gimage; + gint width; + gint height; + gint preview_width; + gint preview_height; + gboolean scaling_up; + TempBuf *render_buf; + + drawable = GIMP_DRAWABLE (preview->viewable); + gimage = drawable->gimage; + + width = preview->width; + height = preview->height; + + if (gimage && ! preview->is_popup) + { + width = MAX (1, ROUND ((((gdouble) width / (gdouble) gimage->width) * + (gdouble) drawable->width))); + height = MAX (1, ROUND ((((gdouble) height / (gdouble) gimage->height) * + (gdouble) drawable->height))); + + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + width, + height, + &preview_width, + &preview_height, + &scaling_up); + } + else + { + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + width, + height, + &preview_width, + &preview_height, + &scaling_up); + } + + if (scaling_up) + { + TempBuf *temp_buf; + + temp_buf = gimp_viewable_get_new_preview (preview->viewable, + drawable->width, + drawable->height); + render_buf = temp_buf_scale (temp_buf, preview_width, preview_height); + + temp_buf_free (temp_buf); + } + else + { + render_buf = gimp_viewable_get_new_preview (preview->viewable, + preview_width, + preview_height); + } + + if (gimage && ! preview->is_popup) + { + if (preview_width < preview->width) + render_buf->x = + ROUND ((((gdouble) preview->width / (gdouble) gimage->width) * + (gdouble) drawable->offset_x)); + + if (preview_height < preview->height) + render_buf->y = + ROUND ((((gdouble) preview->height / (gdouble) gimage->height) * + (gdouble) drawable->offset_y)); + } + else + { + if (preview_width < width) + render_buf->x = (width - preview_width) / 2; + + if (preview_height < height) + render_buf->y = (height - preview_height) / 2; + } + + if (! gimage && (render_buf->x || render_buf->y)) + { + TempBuf *temp_buf; + guchar white[4] = { 0, 0, 0, 0 }; + + temp_buf = temp_buf_new (width, height, + render_buf->bytes, + 0, 0, + white); + + temp_buf_copy_area (render_buf, temp_buf, + 0, 0, + render_buf->width, + render_buf->height, + render_buf->x, + render_buf->y); + + temp_buf_free (render_buf); + + gimp_preview_render_and_flush (preview, + temp_buf, + -1); + + temp_buf_free (temp_buf); + + return; + } + + gimp_preview_render_and_flush (preview, + render_buf, + -1); + + temp_buf_free (render_buf); } static GtkWidget * gimp_drawable_preview_create_popup (GimpPreview *preview) { + GimpDrawable *drawable; + gint popup_width; + gint popup_height; + gboolean scaling_up; + + drawable = GIMP_DRAWABLE (preview->viewable); + + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + MIN (preview->width * 2, 256), + MIN (preview->height * 2, 256), + &popup_width, + &popup_height, + &scaling_up); + + if (scaling_up) + { + return gimp_preview_new_full (preview->viewable, + drawable->width, + drawable->height, + 0, + TRUE, FALSE, FALSE); + } + else + { + return gimp_preview_new_full (preview->viewable, + popup_width, + popup_height, + 0, + TRUE, FALSE, FALSE); + } +} + +static void +gimp_drawable_preview_calc_size (gint drawable_width, + gint drawable_height, + gint width, + gint height, + gint *return_width, + gint *return_height, + gboolean *scaling_up) +{ + gdouble ratio; + + if (drawable_width > drawable_height) + { + ratio = (gdouble) width / (gdouble) drawable_width; + } + else + { + ratio = (gdouble) height / (gdouble) drawable_height; + } + + width = RINT (ratio * (gdouble) drawable_width); + height = RINT (ratio * (gdouble) drawable_height); + + if (width < 1) width = 1; + if (height < 1) height = 1; + + *return_width = width; + *return_height = height; + *scaling_up = (ratio > 1.0); } diff --git a/app/gimpimagepreview.c b/app/gimpimagepreview.c index ff2a5523bf..01d32decd9 100644 --- a/app/gimpimagepreview.c +++ b/app/gimpimagepreview.c @@ -171,8 +171,6 @@ gimp_image_preview_render (GimpPreview *preview) -1); temp_buf_free (render_buf); - - return; } static GtkWidget * diff --git a/app/gimppreview.c b/app/gimppreview.c index cf20a92777..dae75c5ff9 100644 --- a/app/gimppreview.c +++ b/app/gimppreview.c @@ -275,7 +275,8 @@ gimp_preview_destroy (GtkObject *object) GtkWidget * gimp_preview_new (GimpViewable *viewable, gint size, - gint border_width) + gint border_width, + gboolean is_popup) { GimpPreview *preview; gint width, height; @@ -314,13 +315,15 @@ gimp_preview_new (GimpViewable *viewable, preview = gtk_type_new (GIMP_TYPE_PREVIEW); } + preview->is_popup = is_popup; + preview->border_width = border_width; + + gimp_preview_set_viewable (preview, viewable); + gimp_preview_get_size (preview, size, &width, &height); preview->width = width; preview->height = height; - preview->border_width = border_width; - - gimp_preview_set_viewable (preview, viewable); gtk_preview_size (GTK_PREVIEW (preview), width + 2 * border_width, diff --git a/app/gimppreview.h b/app/gimppreview.h index 13e8769eb1..5c22dbc9bc 100644 --- a/app/gimppreview.h +++ b/app/gimppreview.h @@ -84,7 +84,8 @@ GtkType gimp_preview_get_type (void); GtkWidget * gimp_preview_new (GimpViewable *viewable, gint size, - gint border_width); + gint border_width, + gboolean is_popup); GtkWidget * gimp_preview_new_full (GimpViewable *viewable, gint width, gint height, diff --git a/app/gui/commands.c b/app/gui/commands.c index 2b87e48d48..cbce8f3aa6 100644 --- a/app/gui/commands.c +++ b/app/gui/commands.c @@ -938,8 +938,8 @@ layers_previous_cmd_callback (GtkWidget *widget, current_layer = gimp_image_get_layer_index (gdisp->gimage, gdisp->gimage->active_layer); - new_layer = gimp_container_get_child_by_index (gdisp->gimage->layers, - current_layer - 1); + new_layer = (GimpLayer *) gimp_container_get_child_by_index (gdisp->gimage->layers, + current_layer - 1); if (new_layer) { @@ -962,8 +962,8 @@ layers_next_cmd_callback (GtkWidget *widget, current_layer = gimp_image_get_layer_index (gdisp->gimage, gdisp->gimage->active_layer); - new_layer = gimp_container_get_child_by_index (gdisp->gimage->layers, - current_layer + 1); + new_layer = (GimpLayer *) gimp_container_get_child_by_index (gdisp->gimage->layers, + current_layer + 1); if (new_layer) { @@ -1779,6 +1779,124 @@ dialogs_test_multi_container_grid_view_cmd_callback (GtkWidget *widget, 32); } +static void +layers_view_image_changed (GimpContext *context, + GimpImage *gimage, + GimpContainerView *view) +{ + gimp_container_view_set_container (view, gimage ? gimage->layers : NULL); +} + +static void +channels_view_image_changed (GimpContext *context, + GimpImage *gimage, + GimpContainerView *view) +{ + gimp_container_view_set_container (view, gimage ? gimage->channels : NULL); +} + +static void +drawable_view_new (GimpViewType view_type, + gchar *title, + gboolean channels, + GimpContext *context) +{ + GimpImage *gimage; + GtkWidget *dialog; + GtkWidget *view; + + if (view_type == GIMP_VIEW_TYPE_LIST) + { + view = gimp_container_list_view_new (NULL, + NULL, + preview_size, + 5, 5); + } + else + { + view = gimp_container_grid_view_new (NULL, + NULL, + preview_size, + 5, 5); + } + + gimage = gimp_context_get_image (context); + + if (channels) + { + if (gimage) + gimp_container_view_set_container (GIMP_CONTAINER_VIEW (view), + gimage->channels); + + gtk_signal_connect (GTK_OBJECT (context), "image_changed", + GTK_SIGNAL_FUNC (channels_view_image_changed), + view); + } + else + { + if (gimage) + gimp_container_view_set_container (GIMP_CONTAINER_VIEW (view), + gimage->layers); + + gtk_signal_connect (GTK_OBJECT (context), "image_changed", + GTK_SIGNAL_FUNC (layers_view_image_changed), + view); + } + + dialog = gimp_dialog_new (title, "test", + gimp_standard_help_func, + NULL, + GTK_WIN_POS_MOUSE, + FALSE, TRUE, TRUE, + + "_delete_event_", gtk_widget_destroy, + NULL, 1, NULL, TRUE, TRUE, + + NULL); + + gtk_widget_hide (GTK_DIALOG (dialog)->action_area); + /* + gtk_widget_hide (GTK_WIDGET (g_list_nth_data (gtk_container_children (GTK_CONTAINER (GTK_BIN (dialog)->child)), 1))); + */ + + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), view); + gtk_widget_show (view); + + gtk_widget_show (dialog); +} + +void +dialogs_test_layer_list_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_LIST, "Layer List", FALSE, + gimp_context_get_user ()); +} + +void +dialogs_test_layer_grid_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_GRID, "Layer Grid", FALSE, + gimp_context_get_user ()); +} + +void +dialogs_test_channel_list_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_LIST, "Channel List", TRUE, + gimp_context_get_user ()); +} + +void +dialogs_test_channel_grid_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_GRID, "Channel Grid", TRUE, + gimp_context_get_user ()); +} + /***** Help *****/ void diff --git a/app/gui/commands.h b/app/gui/commands.h index 03e76e43aa..d097bc0e83 100644 --- a/app/gui/commands.h +++ b/app/gui/commands.h @@ -142,8 +142,13 @@ void dialogs_test_pattern_container_grid_view_cmd_callback (GtkWidget *, gpoint void dialogs_test_gradient_container_grid_view_cmd_callback (GtkWidget *, gpointer); void dialogs_test_palette_container_grid_view_cmd_callback (GtkWidget *, gpointer); -void dialogs_test_multi_container_list_view_cmd_callback (GtkWidget *, gpointer); -void dialogs_test_multi_container_grid_view_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_multi_container_list_view_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_multi_container_grid_view_cmd_callback (GtkWidget *, gpointer); + +void dialogs_test_layer_list_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_layer_grid_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_channel_list_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_channel_grid_cmd_callback (GtkWidget *, gpointer); void help_help_cmd_callback (GtkWidget *, gpointer); void help_context_help_cmd_callback (GtkWidget *, gpointer); diff --git a/app/gui/help-commands.c b/app/gui/help-commands.c index 2b87e48d48..cbce8f3aa6 100644 --- a/app/gui/help-commands.c +++ b/app/gui/help-commands.c @@ -938,8 +938,8 @@ layers_previous_cmd_callback (GtkWidget *widget, current_layer = gimp_image_get_layer_index (gdisp->gimage, gdisp->gimage->active_layer); - new_layer = gimp_container_get_child_by_index (gdisp->gimage->layers, - current_layer - 1); + new_layer = (GimpLayer *) gimp_container_get_child_by_index (gdisp->gimage->layers, + current_layer - 1); if (new_layer) { @@ -962,8 +962,8 @@ layers_next_cmd_callback (GtkWidget *widget, current_layer = gimp_image_get_layer_index (gdisp->gimage, gdisp->gimage->active_layer); - new_layer = gimp_container_get_child_by_index (gdisp->gimage->layers, - current_layer + 1); + new_layer = (GimpLayer *) gimp_container_get_child_by_index (gdisp->gimage->layers, + current_layer + 1); if (new_layer) { @@ -1779,6 +1779,124 @@ dialogs_test_multi_container_grid_view_cmd_callback (GtkWidget *widget, 32); } +static void +layers_view_image_changed (GimpContext *context, + GimpImage *gimage, + GimpContainerView *view) +{ + gimp_container_view_set_container (view, gimage ? gimage->layers : NULL); +} + +static void +channels_view_image_changed (GimpContext *context, + GimpImage *gimage, + GimpContainerView *view) +{ + gimp_container_view_set_container (view, gimage ? gimage->channels : NULL); +} + +static void +drawable_view_new (GimpViewType view_type, + gchar *title, + gboolean channels, + GimpContext *context) +{ + GimpImage *gimage; + GtkWidget *dialog; + GtkWidget *view; + + if (view_type == GIMP_VIEW_TYPE_LIST) + { + view = gimp_container_list_view_new (NULL, + NULL, + preview_size, + 5, 5); + } + else + { + view = gimp_container_grid_view_new (NULL, + NULL, + preview_size, + 5, 5); + } + + gimage = gimp_context_get_image (context); + + if (channels) + { + if (gimage) + gimp_container_view_set_container (GIMP_CONTAINER_VIEW (view), + gimage->channels); + + gtk_signal_connect (GTK_OBJECT (context), "image_changed", + GTK_SIGNAL_FUNC (channels_view_image_changed), + view); + } + else + { + if (gimage) + gimp_container_view_set_container (GIMP_CONTAINER_VIEW (view), + gimage->layers); + + gtk_signal_connect (GTK_OBJECT (context), "image_changed", + GTK_SIGNAL_FUNC (layers_view_image_changed), + view); + } + + dialog = gimp_dialog_new (title, "test", + gimp_standard_help_func, + NULL, + GTK_WIN_POS_MOUSE, + FALSE, TRUE, TRUE, + + "_delete_event_", gtk_widget_destroy, + NULL, 1, NULL, TRUE, TRUE, + + NULL); + + gtk_widget_hide (GTK_DIALOG (dialog)->action_area); + /* + gtk_widget_hide (GTK_WIDGET (g_list_nth_data (gtk_container_children (GTK_CONTAINER (GTK_BIN (dialog)->child)), 1))); + */ + + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), view); + gtk_widget_show (view); + + gtk_widget_show (dialog); +} + +void +dialogs_test_layer_list_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_LIST, "Layer List", FALSE, + gimp_context_get_user ()); +} + +void +dialogs_test_layer_grid_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_GRID, "Layer Grid", FALSE, + gimp_context_get_user ()); +} + +void +dialogs_test_channel_list_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_LIST, "Channel List", TRUE, + gimp_context_get_user ()); +} + +void +dialogs_test_channel_grid_cmd_callback (GtkWidget *widget, + gpointer client_data) +{ + drawable_view_new (GIMP_VIEW_TYPE_GRID, "Channel Grid", TRUE, + gimp_context_get_user ()); +} + /***** Help *****/ void diff --git a/app/gui/help-commands.h b/app/gui/help-commands.h index 03e76e43aa..d097bc0e83 100644 --- a/app/gui/help-commands.h +++ b/app/gui/help-commands.h @@ -142,8 +142,13 @@ void dialogs_test_pattern_container_grid_view_cmd_callback (GtkWidget *, gpoint void dialogs_test_gradient_container_grid_view_cmd_callback (GtkWidget *, gpointer); void dialogs_test_palette_container_grid_view_cmd_callback (GtkWidget *, gpointer); -void dialogs_test_multi_container_list_view_cmd_callback (GtkWidget *, gpointer); -void dialogs_test_multi_container_grid_view_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_multi_container_list_view_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_multi_container_grid_view_cmd_callback (GtkWidget *, gpointer); + +void dialogs_test_layer_list_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_layer_grid_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_channel_list_cmd_callback (GtkWidget *, gpointer); +void dialogs_test_channel_grid_cmd_callback (GtkWidget *, gpointer); void help_help_cmd_callback (GtkWidget *, gpointer); void help_context_help_cmd_callback (GtkWidget *, gpointer); diff --git a/app/gui/menus.c b/app/gui/menus.c index 9a2d12e151..ac7a22b4bc 100644 --- a/app/gui/menus.c +++ b/app/gui/menus.c @@ -154,33 +154,45 @@ static GimpItemFactoryEntry toolbox_entries[] = "file/dialogs/display_filters/display_filters.html", NULL }, #endif /* DISPLAY_FILTERS */ - { { "/File/Test Dialogs/List of all Images...", NULL, dialogs_test_image_container_list_view_cmd_callback, 0 }, + { { N_("/File/Test Dialogs/Layer List..."), NULL, dialogs_test_layer_list_cmd_callback, 1 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Images...", NULL, dialogs_test_image_container_grid_view_cmd_callback, 0 }, + { { N_("/File/Test Dialogs/Layer Grid..."), NULL, dialogs_test_layer_grid_cmd_callback, 1 }, + NULL, NULL }, + { { N_("/File/Test Dialogs/Channel List..."), NULL, dialogs_test_channel_list_cmd_callback, 1 }, + NULL, NULL }, + { { N_("/File/Test Dialogs/Channel Grid..."), NULL, dialogs_test_channel_grid_cmd_callback, 1 }, NULL, NULL }, { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, NULL, NULL }, - { { "/File/Test Dialogs/List of all Brushes...", NULL, dialogs_test_brush_container_list_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Images List...", NULL, dialogs_test_image_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/List of all Patterns...", NULL, dialogs_test_pattern_container_list_view_cmd_callback, 0 }, - NULL, NULL }, - { { "/File/Test Dialogs/List of all Gradients...", NULL, dialogs_test_gradient_container_list_view_cmd_callback, 0 }, - NULL, NULL }, - { { "/File/Test Dialogs/List of all Palettes...", NULL, dialogs_test_palette_container_list_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Images Grid...", NULL, dialogs_test_image_container_grid_view_cmd_callback, 0 }, NULL, NULL }, { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Brushes...", NULL, dialogs_test_brush_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Brushe List...", NULL, dialogs_test_brush_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Patterns...", NULL, dialogs_test_pattern_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Pattern List...", NULL, dialogs_test_pattern_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Gradients...", NULL, dialogs_test_gradient_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Gradient List...", NULL, dialogs_test_gradient_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Palettes...", NULL, dialogs_test_palette_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Palette List...", NULL, dialogs_test_palette_container_list_view_cmd_callback, 0 }, + NULL, NULL }, + + { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, + NULL, NULL }, + + { { "/File/Test Dialogs/Brushe Grid...", NULL, dialogs_test_brush_container_grid_view_cmd_callback, 0 }, + NULL, NULL }, + { { "/File/Test Dialogs/Pattern Grid...", NULL, dialogs_test_pattern_container_grid_view_cmd_callback, 0 }, + NULL, NULL }, + { { "/File/Test Dialogs/Gradient Grid...", NULL, dialogs_test_gradient_container_grid_view_cmd_callback, 0 }, + NULL, NULL }, + { { "/File/Test Dialogs/Palette Grid...", NULL, dialogs_test_palette_container_grid_view_cmd_callback, 0 }, NULL, NULL }, { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, diff --git a/app/menus.c b/app/menus.c index 9a2d12e151..ac7a22b4bc 100644 --- a/app/menus.c +++ b/app/menus.c @@ -154,33 +154,45 @@ static GimpItemFactoryEntry toolbox_entries[] = "file/dialogs/display_filters/display_filters.html", NULL }, #endif /* DISPLAY_FILTERS */ - { { "/File/Test Dialogs/List of all Images...", NULL, dialogs_test_image_container_list_view_cmd_callback, 0 }, + { { N_("/File/Test Dialogs/Layer List..."), NULL, dialogs_test_layer_list_cmd_callback, 1 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Images...", NULL, dialogs_test_image_container_grid_view_cmd_callback, 0 }, + { { N_("/File/Test Dialogs/Layer Grid..."), NULL, dialogs_test_layer_grid_cmd_callback, 1 }, + NULL, NULL }, + { { N_("/File/Test Dialogs/Channel List..."), NULL, dialogs_test_channel_list_cmd_callback, 1 }, + NULL, NULL }, + { { N_("/File/Test Dialogs/Channel Grid..."), NULL, dialogs_test_channel_grid_cmd_callback, 1 }, NULL, NULL }, { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, NULL, NULL }, - { { "/File/Test Dialogs/List of all Brushes...", NULL, dialogs_test_brush_container_list_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Images List...", NULL, dialogs_test_image_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/List of all Patterns...", NULL, dialogs_test_pattern_container_list_view_cmd_callback, 0 }, - NULL, NULL }, - { { "/File/Test Dialogs/List of all Gradients...", NULL, dialogs_test_gradient_container_list_view_cmd_callback, 0 }, - NULL, NULL }, - { { "/File/Test Dialogs/List of all Palettes...", NULL, dialogs_test_palette_container_list_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Images Grid...", NULL, dialogs_test_image_container_grid_view_cmd_callback, 0 }, NULL, NULL }, { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Brushes...", NULL, dialogs_test_brush_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Brushe List...", NULL, dialogs_test_brush_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Patterns...", NULL, dialogs_test_pattern_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Pattern List...", NULL, dialogs_test_pattern_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Gradients...", NULL, dialogs_test_gradient_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Gradient List...", NULL, dialogs_test_gradient_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Palettes...", NULL, dialogs_test_palette_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Palette List...", NULL, dialogs_test_palette_container_list_view_cmd_callback, 0 }, + NULL, NULL }, + + { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, + NULL, NULL }, + + { { "/File/Test Dialogs/Brushe Grid...", NULL, dialogs_test_brush_container_grid_view_cmd_callback, 0 }, + NULL, NULL }, + { { "/File/Test Dialogs/Pattern Grid...", NULL, dialogs_test_pattern_container_grid_view_cmd_callback, 0 }, + NULL, NULL }, + { { "/File/Test Dialogs/Gradient Grid...", NULL, dialogs_test_gradient_container_grid_view_cmd_callback, 0 }, + NULL, NULL }, + { { "/File/Test Dialogs/Palette Grid...", NULL, dialogs_test_palette_container_grid_view_cmd_callback, 0 }, NULL, NULL }, { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, diff --git a/app/menus/menus.c b/app/menus/menus.c index 9a2d12e151..ac7a22b4bc 100644 --- a/app/menus/menus.c +++ b/app/menus/menus.c @@ -154,33 +154,45 @@ static GimpItemFactoryEntry toolbox_entries[] = "file/dialogs/display_filters/display_filters.html", NULL }, #endif /* DISPLAY_FILTERS */ - { { "/File/Test Dialogs/List of all Images...", NULL, dialogs_test_image_container_list_view_cmd_callback, 0 }, + { { N_("/File/Test Dialogs/Layer List..."), NULL, dialogs_test_layer_list_cmd_callback, 1 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Images...", NULL, dialogs_test_image_container_grid_view_cmd_callback, 0 }, + { { N_("/File/Test Dialogs/Layer Grid..."), NULL, dialogs_test_layer_grid_cmd_callback, 1 }, + NULL, NULL }, + { { N_("/File/Test Dialogs/Channel List..."), NULL, dialogs_test_channel_list_cmd_callback, 1 }, + NULL, NULL }, + { { N_("/File/Test Dialogs/Channel Grid..."), NULL, dialogs_test_channel_grid_cmd_callback, 1 }, NULL, NULL }, { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, NULL, NULL }, - { { "/File/Test Dialogs/List of all Brushes...", NULL, dialogs_test_brush_container_list_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Images List...", NULL, dialogs_test_image_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/List of all Patterns...", NULL, dialogs_test_pattern_container_list_view_cmd_callback, 0 }, - NULL, NULL }, - { { "/File/Test Dialogs/List of all Gradients...", NULL, dialogs_test_gradient_container_list_view_cmd_callback, 0 }, - NULL, NULL }, - { { "/File/Test Dialogs/List of all Palettes...", NULL, dialogs_test_palette_container_list_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Images Grid...", NULL, dialogs_test_image_container_grid_view_cmd_callback, 0 }, NULL, NULL }, { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Brushes...", NULL, dialogs_test_brush_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Brushe List...", NULL, dialogs_test_brush_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Patterns...", NULL, dialogs_test_pattern_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Pattern List...", NULL, dialogs_test_pattern_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Gradients...", NULL, dialogs_test_gradient_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Gradient List...", NULL, dialogs_test_gradient_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Palettes...", NULL, dialogs_test_palette_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Palette List...", NULL, dialogs_test_palette_container_list_view_cmd_callback, 0 }, + NULL, NULL }, + + { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, + NULL, NULL }, + + { { "/File/Test Dialogs/Brushe Grid...", NULL, dialogs_test_brush_container_grid_view_cmd_callback, 0 }, + NULL, NULL }, + { { "/File/Test Dialogs/Pattern Grid...", NULL, dialogs_test_pattern_container_grid_view_cmd_callback, 0 }, + NULL, NULL }, + { { "/File/Test Dialogs/Gradient Grid...", NULL, dialogs_test_gradient_container_grid_view_cmd_callback, 0 }, + NULL, NULL }, + { { "/File/Test Dialogs/Palette Grid...", NULL, dialogs_test_palette_container_grid_view_cmd_callback, 0 }, NULL, NULL }, { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, diff --git a/app/widgets/gimpcontainergridview.c b/app/widgets/gimpcontainergridview.c index 94fe259cb2..60b6184582 100644 --- a/app/widgets/gimpcontainergridview.c +++ b/app/widgets/gimpcontainergridview.c @@ -177,8 +177,7 @@ gimp_container_grid_view_new (GimpContainer *container, GimpContainerView *view; gint window_border; - g_return_val_if_fail (container != NULL, NULL); - g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL); + g_return_val_if_fail (! container || GIMP_IS_CONTAINER (container), NULL); g_return_val_if_fail (! context || GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (preview_size > 0 && preview_size <= 64, NULL); g_return_val_if_fail (min_items_x > 0 && min_items_x <= 64, NULL); @@ -199,7 +198,8 @@ gimp_container_grid_view_new (GimpContainer *container, (preview_size + 2) * min_items_x + window_border, (preview_size + 2) * min_items_y + window_border); - gimp_container_view_set_container (view, container); + if (container) + gimp_container_view_set_container (view, container); gimp_container_view_set_context (view, context); diff --git a/app/widgets/gimpcontainerlistview.c b/app/widgets/gimpcontainerlistview.c index 853046ba75..36f4b7568a 100644 --- a/app/widgets/gimpcontainerlistview.c +++ b/app/widgets/gimpcontainerlistview.c @@ -174,8 +174,7 @@ gimp_container_list_view_new (GimpContainer *container, GimpContainerView *view; gint window_border; - g_return_val_if_fail (container != NULL, NULL); - g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL); + g_return_val_if_fail (! container || GIMP_IS_CONTAINER (container), NULL); g_return_val_if_fail (! context || GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (preview_size > 0 && preview_size <= 64, NULL); g_return_val_if_fail (min_items_x > 0 && min_items_x <= 64, NULL); @@ -196,7 +195,8 @@ gimp_container_list_view_new (GimpContainer *container, (preview_size + 2) * min_items_x + window_border, (preview_size + 6) * min_items_y + window_border); - gimp_container_view_set_container (view, container); + if (container) + gimp_container_view_set_container (view, container); gimp_container_view_set_context (view, context); @@ -224,7 +224,7 @@ gimp_container_list_view_insert_item (GimpContainerView *view, gtk_container_add (GTK_CONTAINER (list_item), hbox); gtk_widget_show (hbox); - preview = gimp_preview_new (viewable, view->preview_size, 1); + preview = gimp_preview_new (viewable, view->preview_size, 1, FALSE); gtk_box_pack_start (GTK_BOX (hbox), preview, FALSE, FALSE, 0); gtk_widget_show (preview); diff --git a/app/widgets/gimpdnd.c b/app/widgets/gimpdnd.c index d9053f841c..72449e1866 100644 --- a/app/widgets/gimpdnd.c +++ b/app/widgets/gimpdnd.c @@ -18,6 +18,7 @@ #include "config.h" +#include #include #include @@ -31,11 +32,14 @@ #include "fileops.h" #include "gimpimage.h" #include "gimpbrush.h" +#include "gimpchannel.h" #include "gimpcontainer.h" #include "gimpdatafactory.h" #include "gimpdnd.h" #include "gimpdrawable.h" #include "gimpgradient.h" +#include "gimplayer.h" +#include "gimplayermask.h" #include "gimppalette.h" #include "gimppattern.h" #include "gimppreview.h" @@ -54,6 +58,9 @@ typedef enum { GIMP_DND_DATA_COLOR = 1, + GIMP_DND_DATA_LAYER, + GIMP_DND_DATA_CHANNEL, + GIMP_DND_DATA_LAYER_MASK, GIMP_DND_DATA_BRUSH, GIMP_DND_DATA_PATTERN, GIMP_DND_DATA_GRADIENT, @@ -94,21 +101,12 @@ struct _GimpDndDataDef }; +static GtkWidget * gimp_dnd_get_viewable_icon (GtkWidget *widget, + GtkSignalFunc get_viewable_func, + gpointer get_viewable_data); static GtkWidget * gimp_dnd_get_color_icon (GtkWidget *widget, GtkSignalFunc get_color_func, gpointer get_color_data); -static GtkWidget * gimp_dnd_get_brush_icon (GtkWidget *widget, - GtkSignalFunc get_brush_func, - gpointer get_brush_data); -static GtkWidget * gimp_dnd_get_pattern_icon (GtkWidget *widget, - GtkSignalFunc get_pattern_func, - gpointer get_pattern_data); -static GtkWidget * gimp_dnd_get_gradient_icon (GtkWidget *widget, - GtkSignalFunc get_gradient_func, - gpointer get_gradient_data); -static GtkWidget * gimp_dnd_get_palette_icon (GtkWidget *widget, - GtkSignalFunc get_palette_func, - gpointer get_palette_data); static GtkWidget * gimp_dnd_get_tool_icon (GtkWidget *widget, GtkSignalFunc get_tool_func, gpointer get_tool_data); @@ -118,6 +116,11 @@ static guchar * gimp_dnd_get_color_data (GtkWidget *widget, gpointer get_color_data, gint *format, gint *length); +static guchar * gimp_dnd_get_drawable_data (GtkWidget *widget, + GtkSignalFunc get_drawable_func, + gpointer get_drawable_data, + gint *format, + gint *length); static guchar * gimp_dnd_get_brush_data (GtkWidget *widget, GtkSignalFunc get_brush_func, gpointer get_brush_data, @@ -150,6 +153,12 @@ static void gimp_dnd_set_color_data (GtkWidget *widget, guchar *vals, gint format, gint length); +static void gimp_dnd_set_drawable_data (GtkWidget *widget, + GtkSignalFunc set_drawable_func, + gpointer set_drawable_data, + guchar *vals, + gint format, + gint length); static void gimp_dnd_set_brush_data (GtkWidget *widget, GtkSignalFunc set_brush_func, gpointer set_brush_data, @@ -206,13 +215,46 @@ static GimpDndDataDef dnd_data_defs[] = gimp_dnd_set_color_data }, + { + GIMP_TARGET_LAYER, + + "gimp_dnd_set_layer_func", + "gimp_dnd_set_layer_data", + + gimp_dnd_get_viewable_icon, + gimp_dnd_get_drawable_data, + gimp_dnd_set_drawable_data, + }, + + { + GIMP_TARGET_CHANNEL, + + "gimp_dnd_set_channel_func", + "gimp_dnd_set_channel_data", + + gimp_dnd_get_viewable_icon, + gimp_dnd_get_drawable_data, + gimp_dnd_set_drawable_data, + }, + + { + GIMP_TARGET_LAYER_MASK, + + "gimp_dnd_set_layer_mask_func", + "gimp_dnd_set_layer_mask_data", + + gimp_dnd_get_viewable_icon, + gimp_dnd_get_drawable_data, + gimp_dnd_set_drawable_data, + }, + { GIMP_TARGET_BRUSH, "gimp_dnd_set_brush_func", "gimp_dnd_set_brush_data", - gimp_dnd_get_brush_icon, + gimp_dnd_get_viewable_icon, gimp_dnd_get_brush_data, gimp_dnd_set_brush_data }, @@ -223,7 +265,7 @@ static GimpDndDataDef dnd_data_defs[] = "gimp_dnd_set_pattern_func", "gimp_dnd_set_pattern_data", - gimp_dnd_get_pattern_icon, + gimp_dnd_get_viewable_icon, gimp_dnd_get_pattern_data, gimp_dnd_set_pattern_data }, @@ -234,7 +276,7 @@ static GimpDndDataDef dnd_data_defs[] = "gimp_dnd_set_gradient_func", "gimp_dnd_set_gradient_data", - gimp_dnd_get_gradient_icon, + gimp_dnd_get_viewable_icon, gimp_dnd_get_gradient_data, gimp_dnd_set_gradient_data }, @@ -245,7 +287,7 @@ static GimpDndDataDef dnd_data_defs[] = "gimp_dnd_set_palette_func", "gimp_dnd_set_palette_data", - gimp_dnd_get_palette_icon, + gimp_dnd_get_viewable_icon, gimp_dnd_get_palette_data, gimp_dnd_set_palette_data }, @@ -624,6 +666,46 @@ gimp_dnd_color_dest_unset (GtkWidget *widget) /* GimpViewable (by GtkType) dnd functions */ /*********************************************/ +static GtkWidget * +gimp_dnd_get_viewable_icon (GtkWidget *widget, + GtkSignalFunc get_viewable_func, + gpointer get_viewable_data) +{ + GtkWidget *preview; + GimpViewable *viewable; + + viewable = (* (GimpDndDragViewableFunc) get_viewable_func) (widget, + get_viewable_data); + + if (! viewable) + return NULL; + + preview = gimp_preview_new (viewable, DRAG_PREVIEW_SIZE, 0, TRUE); + + return preview; +} + +static const GtkTargetEntry layer_target_table[] = +{ + GIMP_TARGET_LAYER +}; +static const guint layer_n_targets = (sizeof (layer_target_table) / + sizeof (layer_target_table[0])); + +static const GtkTargetEntry channel_target_table[] = +{ + GIMP_TARGET_CHANNEL +}; +static const guint channel_n_targets = (sizeof (channel_target_table) / + sizeof (layer_target_table[0])); + +static const GtkTargetEntry layer_mask_target_table[] = +{ + GIMP_TARGET_LAYER_MASK +}; +static const guint layer_mask_n_targets = (sizeof (layer_mask_target_table) / + sizeof (layer_mask_target_table[0])); + static const GtkTargetEntry brush_target_table[] = { GIMP_TARGET_BRUSH @@ -662,7 +744,22 @@ gimp_gtk_drag_source_set_by_type (GtkWidget *widget, const GtkTargetEntry *target_table = NULL; guint n_targets = 0; - if (type == GIMP_TYPE_BRUSH) + if (type == GIMP_TYPE_LAYER) + { + target_table = layer_target_table; + n_targets = layer_n_targets; + } + else if (type == GIMP_TYPE_CHANNEL) + { + target_table = channel_target_table; + n_targets = channel_n_targets; + } + else if (type == GIMP_TYPE_LAYER_MASK) + { + target_table = layer_mask_target_table; + n_targets = layer_mask_n_targets; + } + else if (type == GIMP_TYPE_BRUSH) { target_table = brush_target_table; n_targets = brush_n_targets; @@ -706,7 +803,22 @@ gimp_gtk_drag_dest_set_by_type (GtkWidget *widget, const GtkTargetEntry *target_table = NULL; guint n_targets = 0; - if (type == GIMP_TYPE_BRUSH) + if (type == GIMP_TYPE_LAYER) + { + target_table = layer_target_table; + n_targets = layer_n_targets; + } + else if (type == GIMP_TYPE_CHANNEL) + { + target_table = channel_target_table; + n_targets = channel_n_targets; + } + else if (type == GIMP_TYPE_LAYER_MASK) + { + target_table = layer_mask_target_table; + n_targets = layer_mask_n_targets; + } + else if (type == GIMP_TYPE_BRUSH) { target_table = brush_target_table; n_targets = brush_n_targets; @@ -746,7 +858,25 @@ gimp_dnd_viewable_source_set (GtkWidget *widget, GimpDndDragViewableFunc get_viewable_func, gpointer data) { - if (type == GIMP_TYPE_BRUSH) + if (type == GIMP_TYPE_LAYER) + { + gimp_dnd_layer_source_set (widget, + (GimpDndDragDrawableFunc) get_viewable_func, + data); + } + else if (type == GIMP_TYPE_CHANNEL) + { + gimp_dnd_channel_source_set (widget, + (GimpDndDragDrawableFunc) get_viewable_func, + data); + } + else if (type == GIMP_TYPE_LAYER_MASK) + { + gimp_dnd_layer_mask_source_set (widget, + (GimpDndDragDrawableFunc) get_viewable_func, + data); + } + else if (type == GIMP_TYPE_BRUSH) { gimp_dnd_brush_source_set (widget, (GimpDndDragBrushFunc) get_viewable_func, @@ -782,7 +912,25 @@ gimp_dnd_viewable_dest_set (GtkWidget *widget, GimpDndDropViewableFunc set_viewable_func, gpointer data) { - if (type == GIMP_TYPE_BRUSH) + if (type == GIMP_TYPE_LAYER) + { + gimp_dnd_layer_dest_set (widget, + (GimpDndDropDrawableFunc) set_viewable_func, + data); + } + else if (type == GIMP_TYPE_CHANNEL) + { + gimp_dnd_channel_dest_set (widget, + (GimpDndDropDrawableFunc) set_viewable_func, + data); + } + else if (type == GIMP_TYPE_LAYER_MASK) + { + gimp_dnd_layer_mask_dest_set (widget, + (GimpDndDropDrawableFunc) set_viewable_func, + data); + } + else if (type == GIMP_TYPE_BRUSH) { gimp_dnd_brush_dest_set (widget, (GimpDndDropBrushFunc) set_viewable_func, @@ -816,7 +964,19 @@ void gimp_dnd_viewable_dest_unset (GtkWidget *widget, GtkType type) { - if (type == GIMP_TYPE_BRUSH) + if (type == GIMP_TYPE_LAYER) + { + gimp_dnd_layer_dest_unset (widget); + } + else if (type == GIMP_TYPE_CHANNEL) + { + gimp_dnd_channel_dest_unset (widget); + } + else if (type == GIMP_TYPE_LAYER_MASK) + { + gimp_dnd_layer_mask_dest_unset (widget); + } + else if (type == GIMP_TYPE_BRUSH) { gimp_dnd_brush_dest_unset (widget); } @@ -839,28 +999,149 @@ gimp_dnd_viewable_dest_unset (GtkWidget *widget, } +/****************************/ +/* drawable dnd functions */ +/****************************/ + +static guchar * +gimp_dnd_get_drawable_data (GtkWidget *widget, + GtkSignalFunc get_drawable_func, + gpointer get_drawable_data, + gint *format, + gint *length) +{ + GimpDrawable *drawable; + gchar *id; + + drawable = + (* (GimpDndDragDrawableFunc) get_drawable_func) (widget, get_drawable_data); + + if (! drawable) + return NULL; + + id = g_strdup_printf ("%d", gimp_drawable_get_ID (drawable)); + + *format = 8; + *length = strlen (id) + 1; + + return (guchar *) id; +} + +static void +gimp_dnd_set_drawable_data (GtkWidget *widget, + GtkSignalFunc set_drawable_func, + gpointer set_drawable_data, + guchar *vals, + gint format, + gint length) +{ + GimpDrawable *drawable; + gchar *id; + gint ID; + + if ((format != 8) || (length < 1)) + { + g_warning ("Received invalid drawable ID data"); + return; + } + + id = (gchar *) vals; + + ID = atoi (id); + + if (! ID) + return; + + drawable = gimp_drawable_get_by_ID (ID); + + if (drawable) + (* (GimpDndDropDrawableFunc) set_drawable_func) (widget, drawable, + set_drawable_data); +} + +void +gimp_dnd_layer_source_set (GtkWidget *widget, + GimpDndDragDrawableFunc get_drawable_func, + gpointer data) +{ + gimp_dnd_data_source_set (GIMP_DND_DATA_LAYER, widget, + GTK_SIGNAL_FUNC (get_drawable_func), + data); +} + +void +gimp_dnd_layer_dest_set (GtkWidget *widget, + GimpDndDropDrawableFunc set_drawable_func, + gpointer data) +{ + gimp_dnd_data_dest_set (GIMP_DND_DATA_LAYER, widget, + GTK_SIGNAL_FUNC (set_drawable_func), + data); +} + +void +gimp_dnd_layer_dest_unset (GtkWidget *widget) +{ + gimp_dnd_data_dest_unset (GIMP_DND_DATA_LAYER, widget); +} + +void +gimp_dnd_channel_source_set (GtkWidget *widget, + GimpDndDragDrawableFunc get_drawable_func, + gpointer data) +{ + gimp_dnd_data_source_set (GIMP_DND_DATA_CHANNEL, widget, + GTK_SIGNAL_FUNC (get_drawable_func), + data); +} + +void +gimp_dnd_channel_dest_set (GtkWidget *widget, + GimpDndDropDrawableFunc set_drawable_func, + gpointer data) +{ + gimp_dnd_data_dest_set (GIMP_DND_DATA_CHANNEL, widget, + GTK_SIGNAL_FUNC (set_drawable_func), + data); +} + +void +gimp_dnd_channel_dest_unset (GtkWidget *widget) +{ + gimp_dnd_data_dest_unset (GIMP_DND_DATA_CHANNEL, widget); +} + +void +gimp_dnd_layer_mask_source_set (GtkWidget *widget, + GimpDndDragDrawableFunc get_drawable_func, + gpointer data) +{ + gimp_dnd_data_source_set (GIMP_DND_DATA_LAYER_MASK, widget, + GTK_SIGNAL_FUNC (get_drawable_func), + data); +} + +void +gimp_dnd_layer_mask_dest_set (GtkWidget *widget, + GimpDndDropDrawableFunc set_drawable_func, + gpointer data) +{ + gimp_dnd_data_dest_set (GIMP_DND_DATA_LAYER_MASK, widget, + GTK_SIGNAL_FUNC (set_drawable_func), + data); +} + +void +gimp_dnd_layer_mask_dest_unset (GtkWidget *widget) +{ + gimp_dnd_data_dest_unset (GIMP_DND_DATA_LAYER_MASK, widget); +} + + /*************************/ /* brush dnd functions */ /*************************/ -static GtkWidget * -gimp_dnd_get_brush_icon (GtkWidget *widget, - GtkSignalFunc get_brush_func, - gpointer get_brush_data) -{ - GtkWidget *preview; - GimpBrush *brush; - - brush = (* (GimpDndDragBrushFunc) get_brush_func) (widget, get_brush_data); - - if (! brush) - return NULL; - - preview = gimp_preview_new (GIMP_VIEWABLE (brush), DRAG_PREVIEW_SIZE, 0); - - return preview; -} - static guchar * gimp_dnd_get_brush_data (GtkWidget *widget, GtkSignalFunc get_brush_func, @@ -948,25 +1229,6 @@ gimp_dnd_brush_dest_unset (GtkWidget *widget) /* pattern dnd functions */ /***************************/ -static GtkWidget * -gimp_dnd_get_pattern_icon (GtkWidget *widget, - GtkSignalFunc get_pattern_func, - gpointer get_pattern_data) -{ - GtkWidget *preview; - GimpPattern *pattern; - - pattern = (* (GimpDndDragPatternFunc) get_pattern_func) (widget, - get_pattern_data); - - if (! pattern) - return NULL; - - preview = gimp_preview_new (GIMP_VIEWABLE (pattern), DRAG_PREVIEW_SIZE, 0); - - return preview; -} - static guchar * gimp_dnd_get_pattern_data (GtkWidget *widget, GtkSignalFunc get_pattern_func, @@ -1053,29 +1315,6 @@ gimp_dnd_pattern_dest_unset (GtkWidget *widget) /* gradient dnd functions */ /****************************/ -static GtkWidget * -gimp_dnd_get_gradient_icon (GtkWidget *widget, - GtkSignalFunc get_gradient_func, - gpointer get_gradient_data) -{ - GtkWidget *preview; - GimpGradient *gradient; - - gradient = - (* (GimpDndDragGradientFunc) get_gradient_func) (widget, get_gradient_data); - - if (! gradient) - return NULL; - - preview = gimp_preview_new_full (GIMP_VIEWABLE (gradient), - DRAG_PREVIEW_SIZE * 2, DRAG_PREVIEW_SIZE / 2, - 0, - TRUE, FALSE, FALSE); - - - return preview; -} - static guchar * gimp_dnd_get_gradient_data (GtkWidget *widget, GtkSignalFunc get_gradient_func, @@ -1162,25 +1401,6 @@ gimp_dnd_gradient_dest_unset (GtkWidget *widget) /* palette dnd functions */ /***************************/ -static GtkWidget * -gimp_dnd_get_palette_icon (GtkWidget *widget, - GtkSignalFunc get_palette_func, - gpointer get_palette_data) -{ - GtkWidget *preview; - GimpPalette *palette; - - palette = (* (GimpDndDragPaletteFunc) get_palette_func) (widget, - get_palette_data); - - if (! palette) - return NULL; - - preview = gimp_preview_new (GIMP_VIEWABLE (palette), DRAG_PREVIEW_SIZE, 0); - - return preview; -} - static guchar * gimp_dnd_get_palette_data (GtkWidget *widget, GtkSignalFunc get_palette_func, diff --git a/app/widgets/gimpdnd.h b/app/widgets/gimpdnd.h index 4f4707b76b..b827d34566 100644 --- a/app/widgets/gimpdnd.h +++ b/app/widgets/gimpdnd.h @@ -140,6 +140,39 @@ void gimp_dnd_viewable_dest_unset (GtkWidget *widget, GtkType type); +/* drawable dnd functions */ + +typedef void (* GimpDndDropDrawableFunc) (GtkWidget *widget, + GimpDrawable *drawable, + gpointer data); +typedef GimpDrawable * (* GimpDndDragDrawableFunc) (GtkWidget *widget, + gpointer data); + +void gimp_dnd_layer_source_set (GtkWidget *widget, + GimpDndDragDrawableFunc get_drawable_func, + gpointer data); +void gimp_dnd_layer_dest_set (GtkWidget *widget, + GimpDndDropDrawableFunc set_drawable_func, + gpointer data); +void gimp_dnd_layer_dest_unset (GtkWidget *widget); + +void gimp_dnd_channel_source_set (GtkWidget *widget, + GimpDndDragDrawableFunc get_drawable_func, + gpointer data); +void gimp_dnd_channel_dest_set (GtkWidget *widget, + GimpDndDropDrawableFunc set_drawable_func, + gpointer data); +void gimp_dnd_channel_dest_unset (GtkWidget *widget); + +void gimp_dnd_layer_mask_source_set (GtkWidget *widget, + GimpDndDragDrawableFunc get_drawable_func, + gpointer data); +void gimp_dnd_layer_mask_dest_set (GtkWidget *widget, + GimpDndDropDrawableFunc set_drawable_func, + gpointer data); +void gimp_dnd_layer_mask_dest_unset (GtkWidget *widget); + + /* brush dnd functions */ typedef void (* GimpDndDropBrushFunc) (GtkWidget *widget, diff --git a/app/widgets/gimpdrawablepreview.c b/app/widgets/gimpdrawablepreview.c index 294fd4ff64..978dc8ffbb 100644 --- a/app/widgets/gimpdrawablepreview.c +++ b/app/widgets/gimpdrawablepreview.c @@ -23,16 +23,32 @@ #include +#include "libgimpmath/gimpmath.h" + #include "apptypes.h" +#include "gimpdrawable.h" #include "gimpdrawablepreview.h" +#include "gimpimage.h" +#include "temp_buf.h" static void gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass); static void gimp_drawable_preview_init (GimpDrawablePreview *preview); static void gimp_drawable_preview_render (GimpPreview *preview); +static void gimp_drawable_preview_get_size (GimpPreview *preview, + gint size, + gint *width, + gint *height); static GtkWidget * gimp_drawable_preview_create_popup (GimpPreview *preview); +static void gimp_drawable_preview_calc_size (gint drawable_width, + gint drawable_height, + gint width, + gint height, + gint *return_width, + gint *return_height, + gboolean *scaling_up); static GimpPreviewClass *parent_class = NULL; @@ -73,6 +89,10 @@ gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass) preview_class = (GimpPreviewClass *) klass; parent_class = gtk_type_class (GIMP_TYPE_PREVIEW); + + preview_class->render = gimp_drawable_preview_render; + preview_class->get_size = gimp_drawable_preview_get_size; + preview_class->create_popup = gimp_drawable_preview_create_popup; } static void @@ -80,12 +100,222 @@ gimp_drawable_preview_init (GimpDrawablePreview *preview) { } +static void +gimp_drawable_preview_get_size (GimpPreview *preview, + gint size, + gint *width, + gint *height) +{ + GimpDrawable *drawable; + GimpImage *gimage; + gboolean scaling_up; + + drawable = GIMP_DRAWABLE (preview->viewable); + gimage = drawable->gimage; + + if (gimage) + { + gimp_drawable_preview_calc_size (gimage->width, + gimage->height, + size, + size, + width, + height, + &scaling_up); + } + else + { + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + size, + size, + width, + height, + &scaling_up); + } +} + static void gimp_drawable_preview_render (GimpPreview *preview) { + GimpDrawable *drawable; + GimpImage *gimage; + gint width; + gint height; + gint preview_width; + gint preview_height; + gboolean scaling_up; + TempBuf *render_buf; + + drawable = GIMP_DRAWABLE (preview->viewable); + gimage = drawable->gimage; + + width = preview->width; + height = preview->height; + + if (gimage && ! preview->is_popup) + { + width = MAX (1, ROUND ((((gdouble) width / (gdouble) gimage->width) * + (gdouble) drawable->width))); + height = MAX (1, ROUND ((((gdouble) height / (gdouble) gimage->height) * + (gdouble) drawable->height))); + + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + width, + height, + &preview_width, + &preview_height, + &scaling_up); + } + else + { + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + width, + height, + &preview_width, + &preview_height, + &scaling_up); + } + + if (scaling_up) + { + TempBuf *temp_buf; + + temp_buf = gimp_viewable_get_new_preview (preview->viewable, + drawable->width, + drawable->height); + render_buf = temp_buf_scale (temp_buf, preview_width, preview_height); + + temp_buf_free (temp_buf); + } + else + { + render_buf = gimp_viewable_get_new_preview (preview->viewable, + preview_width, + preview_height); + } + + if (gimage && ! preview->is_popup) + { + if (preview_width < preview->width) + render_buf->x = + ROUND ((((gdouble) preview->width / (gdouble) gimage->width) * + (gdouble) drawable->offset_x)); + + if (preview_height < preview->height) + render_buf->y = + ROUND ((((gdouble) preview->height / (gdouble) gimage->height) * + (gdouble) drawable->offset_y)); + } + else + { + if (preview_width < width) + render_buf->x = (width - preview_width) / 2; + + if (preview_height < height) + render_buf->y = (height - preview_height) / 2; + } + + if (! gimage && (render_buf->x || render_buf->y)) + { + TempBuf *temp_buf; + guchar white[4] = { 0, 0, 0, 0 }; + + temp_buf = temp_buf_new (width, height, + render_buf->bytes, + 0, 0, + white); + + temp_buf_copy_area (render_buf, temp_buf, + 0, 0, + render_buf->width, + render_buf->height, + render_buf->x, + render_buf->y); + + temp_buf_free (render_buf); + + gimp_preview_render_and_flush (preview, + temp_buf, + -1); + + temp_buf_free (temp_buf); + + return; + } + + gimp_preview_render_and_flush (preview, + render_buf, + -1); + + temp_buf_free (render_buf); } static GtkWidget * gimp_drawable_preview_create_popup (GimpPreview *preview) { + GimpDrawable *drawable; + gint popup_width; + gint popup_height; + gboolean scaling_up; + + drawable = GIMP_DRAWABLE (preview->viewable); + + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + MIN (preview->width * 2, 256), + MIN (preview->height * 2, 256), + &popup_width, + &popup_height, + &scaling_up); + + if (scaling_up) + { + return gimp_preview_new_full (preview->viewable, + drawable->width, + drawable->height, + 0, + TRUE, FALSE, FALSE); + } + else + { + return gimp_preview_new_full (preview->viewable, + popup_width, + popup_height, + 0, + TRUE, FALSE, FALSE); + } +} + +static void +gimp_drawable_preview_calc_size (gint drawable_width, + gint drawable_height, + gint width, + gint height, + gint *return_width, + gint *return_height, + gboolean *scaling_up) +{ + gdouble ratio; + + if (drawable_width > drawable_height) + { + ratio = (gdouble) width / (gdouble) drawable_width; + } + else + { + ratio = (gdouble) height / (gdouble) drawable_height; + } + + width = RINT (ratio * (gdouble) drawable_width); + height = RINT (ratio * (gdouble) drawable_height); + + if (width < 1) width = 1; + if (height < 1) height = 1; + + *return_width = width; + *return_height = height; + *scaling_up = (ratio > 1.0); } diff --git a/app/widgets/gimpimagepreview.c b/app/widgets/gimpimagepreview.c index ff2a5523bf..01d32decd9 100644 --- a/app/widgets/gimpimagepreview.c +++ b/app/widgets/gimpimagepreview.c @@ -171,8 +171,6 @@ gimp_image_preview_render (GimpPreview *preview) -1); temp_buf_free (render_buf); - - return; } static GtkWidget * diff --git a/app/widgets/gimpitemfactory.c b/app/widgets/gimpitemfactory.c index 9a2d12e151..ac7a22b4bc 100644 --- a/app/widgets/gimpitemfactory.c +++ b/app/widgets/gimpitemfactory.c @@ -154,33 +154,45 @@ static GimpItemFactoryEntry toolbox_entries[] = "file/dialogs/display_filters/display_filters.html", NULL }, #endif /* DISPLAY_FILTERS */ - { { "/File/Test Dialogs/List of all Images...", NULL, dialogs_test_image_container_list_view_cmd_callback, 0 }, + { { N_("/File/Test Dialogs/Layer List..."), NULL, dialogs_test_layer_list_cmd_callback, 1 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Images...", NULL, dialogs_test_image_container_grid_view_cmd_callback, 0 }, + { { N_("/File/Test Dialogs/Layer Grid..."), NULL, dialogs_test_layer_grid_cmd_callback, 1 }, + NULL, NULL }, + { { N_("/File/Test Dialogs/Channel List..."), NULL, dialogs_test_channel_list_cmd_callback, 1 }, + NULL, NULL }, + { { N_("/File/Test Dialogs/Channel Grid..."), NULL, dialogs_test_channel_grid_cmd_callback, 1 }, NULL, NULL }, { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, NULL, NULL }, - { { "/File/Test Dialogs/List of all Brushes...", NULL, dialogs_test_brush_container_list_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Images List...", NULL, dialogs_test_image_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/List of all Patterns...", NULL, dialogs_test_pattern_container_list_view_cmd_callback, 0 }, - NULL, NULL }, - { { "/File/Test Dialogs/List of all Gradients...", NULL, dialogs_test_gradient_container_list_view_cmd_callback, 0 }, - NULL, NULL }, - { { "/File/Test Dialogs/List of all Palettes...", NULL, dialogs_test_palette_container_list_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Images Grid...", NULL, dialogs_test_image_container_grid_view_cmd_callback, 0 }, NULL, NULL }, { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Brushes...", NULL, dialogs_test_brush_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Brushe List...", NULL, dialogs_test_brush_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Patterns...", NULL, dialogs_test_pattern_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Pattern List...", NULL, dialogs_test_pattern_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Gradients...", NULL, dialogs_test_gradient_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Gradient List...", NULL, dialogs_test_gradient_container_list_view_cmd_callback, 0 }, NULL, NULL }, - { { "/File/Test Dialogs/Grid of all Palettes...", NULL, dialogs_test_palette_container_grid_view_cmd_callback, 0 }, + { { "/File/Test Dialogs/Palette List...", NULL, dialogs_test_palette_container_list_view_cmd_callback, 0 }, + NULL, NULL }, + + { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, + NULL, NULL }, + + { { "/File/Test Dialogs/Brushe Grid...", NULL, dialogs_test_brush_container_grid_view_cmd_callback, 0 }, + NULL, NULL }, + { { "/File/Test Dialogs/Pattern Grid...", NULL, dialogs_test_pattern_container_grid_view_cmd_callback, 0 }, + NULL, NULL }, + { { "/File/Test Dialogs/Gradient Grid...", NULL, dialogs_test_gradient_container_grid_view_cmd_callback, 0 }, + NULL, NULL }, + { { "/File/Test Dialogs/Palette Grid...", NULL, dialogs_test_palette_container_grid_view_cmd_callback, 0 }, NULL, NULL }, { { "/File/Test Dialogs/---", NULL, NULL, 0, "" }, diff --git a/app/widgets/gimppreview.c b/app/widgets/gimppreview.c index cf20a92777..dae75c5ff9 100644 --- a/app/widgets/gimppreview.c +++ b/app/widgets/gimppreview.c @@ -275,7 +275,8 @@ gimp_preview_destroy (GtkObject *object) GtkWidget * gimp_preview_new (GimpViewable *viewable, gint size, - gint border_width) + gint border_width, + gboolean is_popup) { GimpPreview *preview; gint width, height; @@ -314,13 +315,15 @@ gimp_preview_new (GimpViewable *viewable, preview = gtk_type_new (GIMP_TYPE_PREVIEW); } + preview->is_popup = is_popup; + preview->border_width = border_width; + + gimp_preview_set_viewable (preview, viewable); + gimp_preview_get_size (preview, size, &width, &height); preview->width = width; preview->height = height; - preview->border_width = border_width; - - gimp_preview_set_viewable (preview, viewable); gtk_preview_size (GTK_PREVIEW (preview), width + 2 * border_width, diff --git a/app/widgets/gimppreview.h b/app/widgets/gimppreview.h index 13e8769eb1..5c22dbc9bc 100644 --- a/app/widgets/gimppreview.h +++ b/app/widgets/gimppreview.h @@ -84,7 +84,8 @@ GtkType gimp_preview_get_type (void); GtkWidget * gimp_preview_new (GimpViewable *viewable, gint size, - gint border_width); + gint border_width, + gboolean is_popup); GtkWidget * gimp_preview_new_full (GimpViewable *viewable, gint width, gint height, diff --git a/app/widgets/gimppreviewrenderer.c b/app/widgets/gimppreviewrenderer.c index cf20a92777..dae75c5ff9 100644 --- a/app/widgets/gimppreviewrenderer.c +++ b/app/widgets/gimppreviewrenderer.c @@ -275,7 +275,8 @@ gimp_preview_destroy (GtkObject *object) GtkWidget * gimp_preview_new (GimpViewable *viewable, gint size, - gint border_width) + gint border_width, + gboolean is_popup) { GimpPreview *preview; gint width, height; @@ -314,13 +315,15 @@ gimp_preview_new (GimpViewable *viewable, preview = gtk_type_new (GIMP_TYPE_PREVIEW); } + preview->is_popup = is_popup; + preview->border_width = border_width; + + gimp_preview_set_viewable (preview, viewable); + gimp_preview_get_size (preview, size, &width, &height); preview->width = width; preview->height = height; - preview->border_width = border_width; - - gimp_preview_set_viewable (preview, viewable); gtk_preview_size (GTK_PREVIEW (preview), width + 2 * border_width, diff --git a/app/widgets/gimppreviewrenderer.h b/app/widgets/gimppreviewrenderer.h index 13e8769eb1..5c22dbc9bc 100644 --- a/app/widgets/gimppreviewrenderer.h +++ b/app/widgets/gimppreviewrenderer.h @@ -84,7 +84,8 @@ GtkType gimp_preview_get_type (void); GtkWidget * gimp_preview_new (GimpViewable *viewable, gint size, - gint border_width); + gint border_width, + gboolean is_popup); GtkWidget * gimp_preview_new_full (GimpViewable *viewable, gint width, gint height, diff --git a/app/widgets/gimppreviewrendererdrawable.c b/app/widgets/gimppreviewrendererdrawable.c index 294fd4ff64..978dc8ffbb 100644 --- a/app/widgets/gimppreviewrendererdrawable.c +++ b/app/widgets/gimppreviewrendererdrawable.c @@ -23,16 +23,32 @@ #include +#include "libgimpmath/gimpmath.h" + #include "apptypes.h" +#include "gimpdrawable.h" #include "gimpdrawablepreview.h" +#include "gimpimage.h" +#include "temp_buf.h" static void gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass); static void gimp_drawable_preview_init (GimpDrawablePreview *preview); static void gimp_drawable_preview_render (GimpPreview *preview); +static void gimp_drawable_preview_get_size (GimpPreview *preview, + gint size, + gint *width, + gint *height); static GtkWidget * gimp_drawable_preview_create_popup (GimpPreview *preview); +static void gimp_drawable_preview_calc_size (gint drawable_width, + gint drawable_height, + gint width, + gint height, + gint *return_width, + gint *return_height, + gboolean *scaling_up); static GimpPreviewClass *parent_class = NULL; @@ -73,6 +89,10 @@ gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass) preview_class = (GimpPreviewClass *) klass; parent_class = gtk_type_class (GIMP_TYPE_PREVIEW); + + preview_class->render = gimp_drawable_preview_render; + preview_class->get_size = gimp_drawable_preview_get_size; + preview_class->create_popup = gimp_drawable_preview_create_popup; } static void @@ -80,12 +100,222 @@ gimp_drawable_preview_init (GimpDrawablePreview *preview) { } +static void +gimp_drawable_preview_get_size (GimpPreview *preview, + gint size, + gint *width, + gint *height) +{ + GimpDrawable *drawable; + GimpImage *gimage; + gboolean scaling_up; + + drawable = GIMP_DRAWABLE (preview->viewable); + gimage = drawable->gimage; + + if (gimage) + { + gimp_drawable_preview_calc_size (gimage->width, + gimage->height, + size, + size, + width, + height, + &scaling_up); + } + else + { + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + size, + size, + width, + height, + &scaling_up); + } +} + static void gimp_drawable_preview_render (GimpPreview *preview) { + GimpDrawable *drawable; + GimpImage *gimage; + gint width; + gint height; + gint preview_width; + gint preview_height; + gboolean scaling_up; + TempBuf *render_buf; + + drawable = GIMP_DRAWABLE (preview->viewable); + gimage = drawable->gimage; + + width = preview->width; + height = preview->height; + + if (gimage && ! preview->is_popup) + { + width = MAX (1, ROUND ((((gdouble) width / (gdouble) gimage->width) * + (gdouble) drawable->width))); + height = MAX (1, ROUND ((((gdouble) height / (gdouble) gimage->height) * + (gdouble) drawable->height))); + + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + width, + height, + &preview_width, + &preview_height, + &scaling_up); + } + else + { + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + width, + height, + &preview_width, + &preview_height, + &scaling_up); + } + + if (scaling_up) + { + TempBuf *temp_buf; + + temp_buf = gimp_viewable_get_new_preview (preview->viewable, + drawable->width, + drawable->height); + render_buf = temp_buf_scale (temp_buf, preview_width, preview_height); + + temp_buf_free (temp_buf); + } + else + { + render_buf = gimp_viewable_get_new_preview (preview->viewable, + preview_width, + preview_height); + } + + if (gimage && ! preview->is_popup) + { + if (preview_width < preview->width) + render_buf->x = + ROUND ((((gdouble) preview->width / (gdouble) gimage->width) * + (gdouble) drawable->offset_x)); + + if (preview_height < preview->height) + render_buf->y = + ROUND ((((gdouble) preview->height / (gdouble) gimage->height) * + (gdouble) drawable->offset_y)); + } + else + { + if (preview_width < width) + render_buf->x = (width - preview_width) / 2; + + if (preview_height < height) + render_buf->y = (height - preview_height) / 2; + } + + if (! gimage && (render_buf->x || render_buf->y)) + { + TempBuf *temp_buf; + guchar white[4] = { 0, 0, 0, 0 }; + + temp_buf = temp_buf_new (width, height, + render_buf->bytes, + 0, 0, + white); + + temp_buf_copy_area (render_buf, temp_buf, + 0, 0, + render_buf->width, + render_buf->height, + render_buf->x, + render_buf->y); + + temp_buf_free (render_buf); + + gimp_preview_render_and_flush (preview, + temp_buf, + -1); + + temp_buf_free (temp_buf); + + return; + } + + gimp_preview_render_and_flush (preview, + render_buf, + -1); + + temp_buf_free (render_buf); } static GtkWidget * gimp_drawable_preview_create_popup (GimpPreview *preview) { + GimpDrawable *drawable; + gint popup_width; + gint popup_height; + gboolean scaling_up; + + drawable = GIMP_DRAWABLE (preview->viewable); + + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + MIN (preview->width * 2, 256), + MIN (preview->height * 2, 256), + &popup_width, + &popup_height, + &scaling_up); + + if (scaling_up) + { + return gimp_preview_new_full (preview->viewable, + drawable->width, + drawable->height, + 0, + TRUE, FALSE, FALSE); + } + else + { + return gimp_preview_new_full (preview->viewable, + popup_width, + popup_height, + 0, + TRUE, FALSE, FALSE); + } +} + +static void +gimp_drawable_preview_calc_size (gint drawable_width, + gint drawable_height, + gint width, + gint height, + gint *return_width, + gint *return_height, + gboolean *scaling_up) +{ + gdouble ratio; + + if (drawable_width > drawable_height) + { + ratio = (gdouble) width / (gdouble) drawable_width; + } + else + { + ratio = (gdouble) height / (gdouble) drawable_height; + } + + width = RINT (ratio * (gdouble) drawable_width); + height = RINT (ratio * (gdouble) drawable_height); + + if (width < 1) width = 1; + if (height < 1) height = 1; + + *return_width = width; + *return_height = height; + *scaling_up = (ratio > 1.0); } diff --git a/app/widgets/gimppreviewrendererimage.c b/app/widgets/gimppreviewrendererimage.c index ff2a5523bf..01d32decd9 100644 --- a/app/widgets/gimppreviewrendererimage.c +++ b/app/widgets/gimppreviewrendererimage.c @@ -171,8 +171,6 @@ gimp_image_preview_render (GimpPreview *preview) -1); temp_buf_free (render_buf); - - return; } static GtkWidget * diff --git a/app/widgets/gimpview.c b/app/widgets/gimpview.c index cf20a92777..dae75c5ff9 100644 --- a/app/widgets/gimpview.c +++ b/app/widgets/gimpview.c @@ -275,7 +275,8 @@ gimp_preview_destroy (GtkObject *object) GtkWidget * gimp_preview_new (GimpViewable *viewable, gint size, - gint border_width) + gint border_width, + gboolean is_popup) { GimpPreview *preview; gint width, height; @@ -314,13 +315,15 @@ gimp_preview_new (GimpViewable *viewable, preview = gtk_type_new (GIMP_TYPE_PREVIEW); } + preview->is_popup = is_popup; + preview->border_width = border_width; + + gimp_preview_set_viewable (preview, viewable); + gimp_preview_get_size (preview, size, &width, &height); preview->width = width; preview->height = height; - preview->border_width = border_width; - - gimp_preview_set_viewable (preview, viewable); gtk_preview_size (GTK_PREVIEW (preview), width + 2 * border_width, diff --git a/app/widgets/gimpview.h b/app/widgets/gimpview.h index 13e8769eb1..5c22dbc9bc 100644 --- a/app/widgets/gimpview.h +++ b/app/widgets/gimpview.h @@ -84,7 +84,8 @@ GtkType gimp_preview_get_type (void); GtkWidget * gimp_preview_new (GimpViewable *viewable, gint size, - gint border_width); + gint border_width, + gboolean is_popup); GtkWidget * gimp_preview_new_full (GimpViewable *viewable, gint width, gint height, diff --git a/app/widgets/gimpviewrenderer.c b/app/widgets/gimpviewrenderer.c index cf20a92777..dae75c5ff9 100644 --- a/app/widgets/gimpviewrenderer.c +++ b/app/widgets/gimpviewrenderer.c @@ -275,7 +275,8 @@ gimp_preview_destroy (GtkObject *object) GtkWidget * gimp_preview_new (GimpViewable *viewable, gint size, - gint border_width) + gint border_width, + gboolean is_popup) { GimpPreview *preview; gint width, height; @@ -314,13 +315,15 @@ gimp_preview_new (GimpViewable *viewable, preview = gtk_type_new (GIMP_TYPE_PREVIEW); } + preview->is_popup = is_popup; + preview->border_width = border_width; + + gimp_preview_set_viewable (preview, viewable); + gimp_preview_get_size (preview, size, &width, &height); preview->width = width; preview->height = height; - preview->border_width = border_width; - - gimp_preview_set_viewable (preview, viewable); gtk_preview_size (GTK_PREVIEW (preview), width + 2 * border_width, diff --git a/app/widgets/gimpviewrenderer.h b/app/widgets/gimpviewrenderer.h index 13e8769eb1..5c22dbc9bc 100644 --- a/app/widgets/gimpviewrenderer.h +++ b/app/widgets/gimpviewrenderer.h @@ -84,7 +84,8 @@ GtkType gimp_preview_get_type (void); GtkWidget * gimp_preview_new (GimpViewable *viewable, gint size, - gint border_width); + gint border_width, + gboolean is_popup); GtkWidget * gimp_preview_new_full (GimpViewable *viewable, gint width, gint height, diff --git a/app/widgets/gimpviewrendererdrawable.c b/app/widgets/gimpviewrendererdrawable.c index 294fd4ff64..978dc8ffbb 100644 --- a/app/widgets/gimpviewrendererdrawable.c +++ b/app/widgets/gimpviewrendererdrawable.c @@ -23,16 +23,32 @@ #include +#include "libgimpmath/gimpmath.h" + #include "apptypes.h" +#include "gimpdrawable.h" #include "gimpdrawablepreview.h" +#include "gimpimage.h" +#include "temp_buf.h" static void gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass); static void gimp_drawable_preview_init (GimpDrawablePreview *preview); static void gimp_drawable_preview_render (GimpPreview *preview); +static void gimp_drawable_preview_get_size (GimpPreview *preview, + gint size, + gint *width, + gint *height); static GtkWidget * gimp_drawable_preview_create_popup (GimpPreview *preview); +static void gimp_drawable_preview_calc_size (gint drawable_width, + gint drawable_height, + gint width, + gint height, + gint *return_width, + gint *return_height, + gboolean *scaling_up); static GimpPreviewClass *parent_class = NULL; @@ -73,6 +89,10 @@ gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass) preview_class = (GimpPreviewClass *) klass; parent_class = gtk_type_class (GIMP_TYPE_PREVIEW); + + preview_class->render = gimp_drawable_preview_render; + preview_class->get_size = gimp_drawable_preview_get_size; + preview_class->create_popup = gimp_drawable_preview_create_popup; } static void @@ -80,12 +100,222 @@ gimp_drawable_preview_init (GimpDrawablePreview *preview) { } +static void +gimp_drawable_preview_get_size (GimpPreview *preview, + gint size, + gint *width, + gint *height) +{ + GimpDrawable *drawable; + GimpImage *gimage; + gboolean scaling_up; + + drawable = GIMP_DRAWABLE (preview->viewable); + gimage = drawable->gimage; + + if (gimage) + { + gimp_drawable_preview_calc_size (gimage->width, + gimage->height, + size, + size, + width, + height, + &scaling_up); + } + else + { + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + size, + size, + width, + height, + &scaling_up); + } +} + static void gimp_drawable_preview_render (GimpPreview *preview) { + GimpDrawable *drawable; + GimpImage *gimage; + gint width; + gint height; + gint preview_width; + gint preview_height; + gboolean scaling_up; + TempBuf *render_buf; + + drawable = GIMP_DRAWABLE (preview->viewable); + gimage = drawable->gimage; + + width = preview->width; + height = preview->height; + + if (gimage && ! preview->is_popup) + { + width = MAX (1, ROUND ((((gdouble) width / (gdouble) gimage->width) * + (gdouble) drawable->width))); + height = MAX (1, ROUND ((((gdouble) height / (gdouble) gimage->height) * + (gdouble) drawable->height))); + + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + width, + height, + &preview_width, + &preview_height, + &scaling_up); + } + else + { + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + width, + height, + &preview_width, + &preview_height, + &scaling_up); + } + + if (scaling_up) + { + TempBuf *temp_buf; + + temp_buf = gimp_viewable_get_new_preview (preview->viewable, + drawable->width, + drawable->height); + render_buf = temp_buf_scale (temp_buf, preview_width, preview_height); + + temp_buf_free (temp_buf); + } + else + { + render_buf = gimp_viewable_get_new_preview (preview->viewable, + preview_width, + preview_height); + } + + if (gimage && ! preview->is_popup) + { + if (preview_width < preview->width) + render_buf->x = + ROUND ((((gdouble) preview->width / (gdouble) gimage->width) * + (gdouble) drawable->offset_x)); + + if (preview_height < preview->height) + render_buf->y = + ROUND ((((gdouble) preview->height / (gdouble) gimage->height) * + (gdouble) drawable->offset_y)); + } + else + { + if (preview_width < width) + render_buf->x = (width - preview_width) / 2; + + if (preview_height < height) + render_buf->y = (height - preview_height) / 2; + } + + if (! gimage && (render_buf->x || render_buf->y)) + { + TempBuf *temp_buf; + guchar white[4] = { 0, 0, 0, 0 }; + + temp_buf = temp_buf_new (width, height, + render_buf->bytes, + 0, 0, + white); + + temp_buf_copy_area (render_buf, temp_buf, + 0, 0, + render_buf->width, + render_buf->height, + render_buf->x, + render_buf->y); + + temp_buf_free (render_buf); + + gimp_preview_render_and_flush (preview, + temp_buf, + -1); + + temp_buf_free (temp_buf); + + return; + } + + gimp_preview_render_and_flush (preview, + render_buf, + -1); + + temp_buf_free (render_buf); } static GtkWidget * gimp_drawable_preview_create_popup (GimpPreview *preview) { + GimpDrawable *drawable; + gint popup_width; + gint popup_height; + gboolean scaling_up; + + drawable = GIMP_DRAWABLE (preview->viewable); + + gimp_drawable_preview_calc_size (drawable->width, + drawable->height, + MIN (preview->width * 2, 256), + MIN (preview->height * 2, 256), + &popup_width, + &popup_height, + &scaling_up); + + if (scaling_up) + { + return gimp_preview_new_full (preview->viewable, + drawable->width, + drawable->height, + 0, + TRUE, FALSE, FALSE); + } + else + { + return gimp_preview_new_full (preview->viewable, + popup_width, + popup_height, + 0, + TRUE, FALSE, FALSE); + } +} + +static void +gimp_drawable_preview_calc_size (gint drawable_width, + gint drawable_height, + gint width, + gint height, + gint *return_width, + gint *return_height, + gboolean *scaling_up) +{ + gdouble ratio; + + if (drawable_width > drawable_height) + { + ratio = (gdouble) width / (gdouble) drawable_width; + } + else + { + ratio = (gdouble) height / (gdouble) drawable_height; + } + + width = RINT (ratio * (gdouble) drawable_width); + height = RINT (ratio * (gdouble) drawable_height); + + if (width < 1) width = 1; + if (height < 1) height = 1; + + *return_width = width; + *return_height = height; + *scaling_up = (ratio > 1.0); } diff --git a/app/widgets/gimpviewrendererimage.c b/app/widgets/gimpviewrendererimage.c index ff2a5523bf..01d32decd9 100644 --- a/app/widgets/gimpviewrendererimage.c +++ b/app/widgets/gimpviewrendererimage.c @@ -171,8 +171,6 @@ gimp_image_preview_render (GimpPreview *preview) -1); temp_buf_free (render_buf); - - return; } static GtkWidget *