1 /* GIMP - The GNU Image Manipulation Program
2 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18 #include "config.h"
19
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include <gegl.h>
24 #include <gtk/gtk.h>
25
26 #include "libgimpwidgets/gimpwidgets.h"
27
28 #include "widgets-types.h"
29
30 #include "core/gimp.h"
31 #include "core/gimpcontext.h"
32 #include "core/gimpimage.h"
33
34 #include "gimpdnd.h"
35 #include "gimpview.h"
36 #include "gimptoolbox.h"
37 #include "gimptoolbox-image-area.h"
38 #include "gimpwindowstrategy.h"
39 #include "gimpwidgets-utils.h"
40
41 #include "gimp-intl.h"
42
43
44 static void
image_preview_clicked(GtkWidget * widget,GdkModifierType state,GimpToolbox * toolbox)45 image_preview_clicked (GtkWidget *widget,
46 GdkModifierType state,
47 GimpToolbox *toolbox)
48 {
49 GimpContext *context = gimp_toolbox_get_context (toolbox);
50
51 gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY (gimp_get_window_strategy (context->gimp)),
52 context->gimp,
53 gimp_dock_get_dialog_factory (GIMP_DOCK (toolbox)),
54 gtk_widget_get_screen (widget),
55 gimp_widget_get_monitor (widget),
56 "gimp-image-list|gimp-image-grid");
57 }
58
59 static void
image_preview_drop_image(GtkWidget * widget,gint x,gint y,GimpViewable * viewable,gpointer data)60 image_preview_drop_image (GtkWidget *widget,
61 gint x,
62 gint y,
63 GimpViewable *viewable,
64 gpointer data)
65 {
66 GimpContext *context = GIMP_CONTEXT (data);
67
68 gimp_context_set_image (context, GIMP_IMAGE (viewable));
69 }
70
71 static void
image_preview_set_viewable(GimpView * view,GimpViewable * old_viewable,GimpViewable * new_viewable)72 image_preview_set_viewable (GimpView *view,
73 GimpViewable *old_viewable,
74 GimpViewable *new_viewable)
75 {
76 if (! old_viewable && new_viewable)
77 {
78 gimp_dnd_xds_source_add (GTK_WIDGET (view),
79 (GimpDndDragViewableFunc) gimp_view_get_viewable,
80 NULL);
81 }
82 else if (old_viewable && ! new_viewable)
83 {
84 gimp_dnd_xds_source_remove (GTK_WIDGET (view));
85 }
86 }
87
88 /* public functions */
89
90 GtkWidget *
gimp_toolbox_image_area_create(GimpToolbox * toolbox,gint width,gint height)91 gimp_toolbox_image_area_create (GimpToolbox *toolbox,
92 gint width,
93 gint height)
94 {
95 GimpContext *context;
96 GtkWidget *image_view;
97 gchar *tooltip;
98
99 g_return_val_if_fail (GIMP_IS_TOOLBOX (toolbox), NULL);
100
101 context = gimp_toolbox_get_context (toolbox);
102
103 image_view = gimp_view_new_full_by_types (context,
104 GIMP_TYPE_VIEW, GIMP_TYPE_IMAGE,
105 width, height, 0,
106 FALSE, TRUE, TRUE);
107
108 g_signal_connect (image_view, "set-viewable",
109 G_CALLBACK (image_preview_set_viewable),
110 NULL);
111
112 gimp_view_set_viewable (GIMP_VIEW (image_view),
113 GIMP_VIEWABLE (gimp_context_get_image (context)));
114
115 gtk_widget_show (image_view);
116
117 #ifdef GDK_WINDOWING_X11
118 tooltip = g_strdup_printf ("%s\n%s",
119 _("The active image.\n"
120 "Click to open the Image Dialog."),
121 _("Drag to an XDS enabled file-manager to "
122 "save the image."));
123 #else
124 tooltip = g_strdup (_("The active image.\n"
125 "Click to open the Image Dialog."));
126 #endif
127
128 gimp_help_set_help_data (image_view, tooltip, NULL);
129 g_free (tooltip);
130
131 g_signal_connect_object (context, "image-changed",
132 G_CALLBACK (gimp_view_set_viewable),
133 image_view, G_CONNECT_SWAPPED);
134
135 g_signal_connect (image_view, "clicked",
136 G_CALLBACK (image_preview_clicked),
137 toolbox);
138
139 gimp_dnd_viewable_dest_add (image_view,
140 GIMP_TYPE_IMAGE,
141 image_preview_drop_image,
142 context);
143
144 return image_view;
145 }
146