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 <gegl.h>
21 #include <gtk/gtk.h>
22
23 #include "widgets-types.h"
24
25 #include "core/gimpcontext.h"
26 #include "core/gimpimage.h"
27
28 #include "gimpdocked.h"
29 #include "gimpimageeditor.h"
30 #include "gimpuimanager.h"
31
32
33 static void gimp_image_editor_docked_iface_init (GimpDockedInterface *iface);
34
35 static void gimp_image_editor_set_context (GimpDocked *docked,
36 GimpContext *context);
37
38 static void gimp_image_editor_dispose (GObject *object);
39
40 static void gimp_image_editor_real_set_image (GimpImageEditor *editor,
41 GimpImage *image);
42 static void gimp_image_editor_image_flush (GimpImage *image,
43 gboolean invalidate_preview,
44 GimpImageEditor *editor);
45
46
G_DEFINE_TYPE_WITH_CODE(GimpImageEditor,gimp_image_editor,GIMP_TYPE_EDITOR,G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,gimp_image_editor_docked_iface_init))47 G_DEFINE_TYPE_WITH_CODE (GimpImageEditor, gimp_image_editor, GIMP_TYPE_EDITOR,
48 G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
49 gimp_image_editor_docked_iface_init))
50
51 #define parent_class gimp_image_editor_parent_class
52
53
54 static void
55 gimp_image_editor_class_init (GimpImageEditorClass *klass)
56 {
57 GObjectClass *object_class = G_OBJECT_CLASS (klass);
58
59 object_class->dispose = gimp_image_editor_dispose;
60
61 klass->set_image = gimp_image_editor_real_set_image;
62 }
63
64 static void
gimp_image_editor_init(GimpImageEditor * editor)65 gimp_image_editor_init (GimpImageEditor *editor)
66 {
67 editor->image = NULL;
68
69 gtk_widget_set_sensitive (GTK_WIDGET (editor), FALSE);
70 }
71
72 static void
gimp_image_editor_docked_iface_init(GimpDockedInterface * iface)73 gimp_image_editor_docked_iface_init (GimpDockedInterface *iface)
74 {
75 iface->set_context = gimp_image_editor_set_context;
76 }
77
78 static void
gimp_image_editor_set_context(GimpDocked * docked,GimpContext * context)79 gimp_image_editor_set_context (GimpDocked *docked,
80 GimpContext *context)
81 {
82 GimpImageEditor *editor = GIMP_IMAGE_EDITOR (docked);
83 GimpImage *image = NULL;
84
85 if (editor->context)
86 {
87 g_signal_handlers_disconnect_by_func (editor->context,
88 gimp_image_editor_set_image,
89 editor);
90
91 g_object_unref (editor->context);
92 }
93
94 editor->context = context;
95
96 if (context)
97 {
98 g_object_ref (editor->context);
99
100 g_signal_connect_swapped (context, "image-changed",
101 G_CALLBACK (gimp_image_editor_set_image),
102 editor);
103
104 image = gimp_context_get_image (context);
105 }
106
107 gimp_image_editor_set_image (editor, image);
108 }
109
110 static void
gimp_image_editor_dispose(GObject * object)111 gimp_image_editor_dispose (GObject *object)
112 {
113 GimpImageEditor *editor = GIMP_IMAGE_EDITOR (object);
114
115 if (editor->image)
116 gimp_image_editor_set_image (editor, NULL);
117
118 G_OBJECT_CLASS (parent_class)->dispose (object);
119 }
120
121 static void
gimp_image_editor_real_set_image(GimpImageEditor * editor,GimpImage * image)122 gimp_image_editor_real_set_image (GimpImageEditor *editor,
123 GimpImage *image)
124 {
125 if (editor->image)
126 g_signal_handlers_disconnect_by_func (editor->image,
127 gimp_image_editor_image_flush,
128 editor);
129
130 editor->image = image;
131
132 if (editor->image)
133 g_signal_connect (editor->image, "flush",
134 G_CALLBACK (gimp_image_editor_image_flush),
135 editor);
136
137 gtk_widget_set_sensitive (GTK_WIDGET (editor), image != NULL);
138 }
139
140
141 /* public functions */
142
143 void
gimp_image_editor_set_image(GimpImageEditor * editor,GimpImage * image)144 gimp_image_editor_set_image (GimpImageEditor *editor,
145 GimpImage *image)
146 {
147 g_return_if_fail (GIMP_IS_IMAGE_EDITOR (editor));
148 g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
149
150 if (image != editor->image)
151 {
152 GIMP_IMAGE_EDITOR_GET_CLASS (editor)->set_image (editor, image);
153
154 if (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)))
155 gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)),
156 gimp_editor_get_popup_data (GIMP_EDITOR (editor)));
157 }
158 }
159
160 GimpImage *
gimp_image_editor_get_image(GimpImageEditor * editor)161 gimp_image_editor_get_image (GimpImageEditor *editor)
162 {
163 g_return_val_if_fail (GIMP_IS_IMAGE_EDITOR (editor), NULL);
164
165 return editor->image;
166 }
167
168
169 /* private functions */
170
171 static void
gimp_image_editor_image_flush(GimpImage * image,gboolean invalidate_preview,GimpImageEditor * editor)172 gimp_image_editor_image_flush (GimpImage *image,
173 gboolean invalidate_preview,
174 GimpImageEditor *editor)
175 {
176 if (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)))
177 gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)),
178 gimp_editor_get_popup_data (GIMP_EDITOR (editor)));
179 }
180