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 "libgimpwidgets/gimpwidgets.h"
24
25 #include "actions-types.h"
26
27 #include "core/gimp.h"
28 #include "core/gimpcontext.h"
29 #include "core/gimpimage.h"
30 #include "core/gimplayermask.h"
31
32 #include "widgets/gimpactiongroup.h"
33 #include "widgets/gimphelp-ids.h"
34
35 #include "actions.h"
36 #include "drawable-actions.h"
37 #include "drawable-commands.h"
38
39 #include "gimp-intl.h"
40
41
42 static const GimpActionEntry drawable_actions[] =
43 {
44 { "drawable-equalize", NULL,
45 NC_("drawable-action", "_Equalize"), NULL,
46 NC_("drawable-action", "Automatic contrast enhancement"),
47 drawable_equalize_cmd_callback,
48 GIMP_HELP_LAYER_EQUALIZE },
49
50 { "drawable-levels-stretch", NULL,
51 NC_("drawable-action", "_White Balance"), NULL,
52 NC_("drawable-action", "Automatic white balance correction"),
53 drawable_levels_stretch_cmd_callback,
54 GIMP_HELP_LAYER_WHITE_BALANCE }
55 };
56
57 static const GimpToggleActionEntry drawable_toggle_actions[] =
58 {
59 { "drawable-visible", GIMP_ICON_VISIBLE,
60 NC_("drawable-action", "Toggle Drawable _Visibility"), NULL, NULL,
61 drawable_visible_cmd_callback,
62 FALSE,
63 GIMP_HELP_LAYER_VISIBLE },
64
65 { "drawable-linked", GIMP_ICON_LINKED,
66 NC_("drawable-action", "Toggle Drawable _Linked State"), NULL, NULL,
67 drawable_linked_cmd_callback,
68 FALSE,
69 GIMP_HELP_LAYER_LINKED },
70
71 { "drawable-lock-content", NULL /* GIMP_ICON_LOCK */,
72 NC_("drawable-action", "L_ock Pixels of Drawable"), NULL,
73 NC_("drawable-action",
74 "Keep the pixels on this drawable from being modified"),
75 drawable_lock_content_cmd_callback,
76 FALSE,
77 GIMP_HELP_LAYER_LOCK_PIXELS },
78
79 { "drawable-lock-position", GIMP_ICON_TOOL_MOVE,
80 NC_("drawable-action", "L_ock Position of Drawable"), NULL,
81 NC_("drawable-action",
82 "Keep the position on this drawable from being modified"),
83 drawable_lock_position_cmd_callback,
84 FALSE,
85 GIMP_HELP_LAYER_LOCK_POSITION },
86 };
87
88 static const GimpEnumActionEntry drawable_flip_actions[] =
89 {
90 { "drawable-flip-horizontal", GIMP_ICON_OBJECT_FLIP_HORIZONTAL,
91 NC_("drawable-action", "Flip _Horizontally"), NULL,
92 NC_("drawable-action", "Flip drawable horizontally"),
93 GIMP_ORIENTATION_HORIZONTAL, FALSE,
94 GIMP_HELP_LAYER_FLIP_HORIZONTAL },
95
96 { "drawable-flip-vertical", GIMP_ICON_OBJECT_FLIP_VERTICAL,
97 NC_("drawable-action", "Flip _Vertically"), NULL,
98 NC_("drawable-action", "Flip drawable vertically"),
99 GIMP_ORIENTATION_VERTICAL, FALSE,
100 GIMP_HELP_LAYER_FLIP_VERTICAL }
101 };
102
103 static const GimpEnumActionEntry drawable_rotate_actions[] =
104 {
105 { "drawable-rotate-90", GIMP_ICON_OBJECT_ROTATE_90,
106 NC_("drawable-action", "Rotate 90° _clockwise"), NULL,
107 NC_("drawable-action", "Rotate drawable 90 degrees to the right"),
108 GIMP_ROTATE_90, FALSE,
109 GIMP_HELP_LAYER_ROTATE_90 },
110
111 { "drawable-rotate-180", GIMP_ICON_OBJECT_ROTATE_180,
112 NC_("drawable-action", "Rotate _180°"), NULL,
113 NC_("drawable-action", "Turn drawable upside-down"),
114 GIMP_ROTATE_180, FALSE,
115 GIMP_HELP_LAYER_ROTATE_180 },
116
117 { "drawable-rotate-270", GIMP_ICON_OBJECT_ROTATE_270,
118 NC_("drawable-action", "Rotate 90° counter-clock_wise"), NULL,
119 NC_("drawable-action", "Rotate drawable 90 degrees to the left"),
120 GIMP_ROTATE_270, FALSE,
121 GIMP_HELP_LAYER_ROTATE_270 }
122 };
123
124
125 void
drawable_actions_setup(GimpActionGroup * group)126 drawable_actions_setup (GimpActionGroup *group)
127 {
128 gimp_action_group_add_actions (group, "drawable-action",
129 drawable_actions,
130 G_N_ELEMENTS (drawable_actions));
131
132 gimp_action_group_add_toggle_actions (group, "drawable-action",
133 drawable_toggle_actions,
134 G_N_ELEMENTS (drawable_toggle_actions));
135
136 gimp_action_group_add_enum_actions (group, "drawable-action",
137 drawable_flip_actions,
138 G_N_ELEMENTS (drawable_flip_actions),
139 drawable_flip_cmd_callback);
140
141 gimp_action_group_add_enum_actions (group, "drawable-action",
142 drawable_rotate_actions,
143 G_N_ELEMENTS (drawable_rotate_actions),
144 drawable_rotate_cmd_callback);
145
146 #define SET_ALWAYS_SHOW_IMAGE(action,show) \
147 gimp_action_group_set_action_always_show_image (group, action, show)
148
149 SET_ALWAYS_SHOW_IMAGE ("drawable-rotate-90", TRUE);
150 SET_ALWAYS_SHOW_IMAGE ("drawable-rotate-180", TRUE);
151 SET_ALWAYS_SHOW_IMAGE ("drawable-rotate-270", TRUE);
152
153 #undef SET_ALWAYS_SHOW_IMAGE
154 }
155
156 void
drawable_actions_update(GimpActionGroup * group,gpointer data)157 drawable_actions_update (GimpActionGroup *group,
158 gpointer data)
159 {
160 GimpImage *image;
161 GimpDrawable *drawable = NULL;
162 gboolean is_rgb = FALSE;
163 gboolean visible = FALSE;
164 gboolean linked = FALSE;
165 gboolean locked = FALSE;
166 gboolean can_lock = FALSE;
167 gboolean locked_pos = FALSE;
168 gboolean can_lock_pos = FALSE;
169 gboolean writable = FALSE;
170 gboolean movable = FALSE;
171 gboolean children = FALSE;
172
173 image = action_data_get_image (data);
174
175 if (image)
176 {
177 drawable = gimp_image_get_active_drawable (image);
178
179 if (drawable)
180 {
181 GimpItem *item;
182
183 is_rgb = gimp_drawable_is_rgb (drawable);
184
185 if (GIMP_IS_LAYER_MASK (drawable))
186 item = GIMP_ITEM (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (drawable)));
187 else
188 item = GIMP_ITEM (drawable);
189
190 visible = gimp_item_get_visible (item);
191 linked = gimp_item_get_linked (item);
192 locked = gimp_item_get_lock_content (item);
193 can_lock = gimp_item_can_lock_content (item);
194 writable = ! gimp_item_is_content_locked (item);
195 locked_pos = gimp_item_get_lock_position (item);
196 can_lock_pos = gimp_item_can_lock_position (item);
197 movable = ! gimp_item_is_position_locked (item);
198
199 if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
200 children = TRUE;
201 }
202 }
203
204 #define SET_SENSITIVE(action,condition) \
205 gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
206 #define SET_ACTIVE(action,condition) \
207 gimp_action_group_set_action_active (group, action, (condition) != 0)
208
209 SET_SENSITIVE ("drawable-equalize", writable && !children);
210 SET_SENSITIVE ("drawable-levels-stretch", writable && !children && is_rgb);
211
212 SET_SENSITIVE ("drawable-visible", drawable);
213 SET_SENSITIVE ("drawable-linked", drawable);
214 SET_SENSITIVE ("drawable-lock-content", can_lock);
215 SET_SENSITIVE ("drawable-lock-position", can_lock_pos);
216
217 SET_ACTIVE ("drawable-visible", visible);
218 SET_ACTIVE ("drawable-linked", linked);
219 SET_ACTIVE ("drawable-lock-content", locked);
220 SET_ACTIVE ("drawable-lock-position", locked_pos);
221
222 SET_SENSITIVE ("drawable-flip-horizontal", writable && movable);
223 SET_SENSITIVE ("drawable-flip-vertical", writable && movable);
224
225 SET_SENSITIVE ("drawable-rotate-90", writable && movable);
226 SET_SENSITIVE ("drawable-rotate-180", writable && movable);
227 SET_SENSITIVE ("drawable-rotate-270", writable && movable);
228
229 #undef SET_SENSITIVE
230 #undef SET_ACTIVE
231 }
232