1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
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 2 of the License, or
7
* (at your option) any later version.
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.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "libgimpwidgets/gimpwidgets.h"
25
#include "actions-types.h"
27
#include "core/core-enums.h"
28
#include "core/gimp.h"
29
#include "core/gimpchannel.h"
30
#include "core/gimpcontext.h"
31
#include "core/gimpimage.h"
32
#include "core/gimpimage-convert.h"
33
#include "core/gimpimage-crop.h"
34
#include "core/gimpimage-duplicate.h"
35
#include "core/gimpimage-flip.h"
36
#include "core/gimpimage-merge.h"
37
#include "core/gimpimage-resize.h"
38
#include "core/gimpimage-rotate.h"
39
#include "core/gimpimage-scale.h"
40
#include "core/gimpimage-undo.h"
41
#include "core/gimpprogress.h"
43
#include "widgets/gimpdialogfactory.h"
44
#include "widgets/gimpdock.h"
45
#include "widgets/gimphelp-ids.h"
47
#include "display/gimpdisplay.h"
48
#include "display/gimpdisplayshell.h"
50
#include "dialogs/convert-dialog.h"
51
#include "dialogs/dialogs.h"
52
#include "dialogs/grid-dialog.h"
53
#include "dialogs/image-merge-layers-dialog.h"
54
#include "dialogs/image-new-dialog.h"
55
#include "dialogs/image-scale-dialog.h"
56
#include "dialogs/print-size-dialog.h"
57
#include "dialogs/resize-dialog.h"
60
#include "image-commands.h"
62
#include "gimp-intl.h"
65
typedef struct _ImageResizeOptions ImageResizeOptions;
67
struct _ImageResizeOptions
74
/* local function prototypes */
76
static void image_resize_callback (GtkWidget *dialog,
77
GimpViewable *viewable,
83
static void image_print_size_callback (GtkWidget *dialog,
87
GimpUnit resolution_unit,
89
static void image_scale_callback (ImageScaleDialog *dialog);
91
static void image_merge_layers_response (GtkWidget *widget,
93
ImageMergeLayersDialog *dialog);
96
/* private variables */
98
static GimpMergeType image_merge_layers_type = GIMP_EXPAND_AS_NECESSARY;
101
/* public functions */
104
image_new_cmd_callback (GtkAction *action,
109
return_if_no_widget (widget, data);
111
dialog = gimp_dialog_factory_dialog_new (global_dialog_factory,
112
gtk_widget_get_screen (widget),
113
"gimp-image-new-dialog", -1, FALSE);
117
image_new_dialog_set (dialog, NULL, NULL);
119
gtk_window_present (GTK_WINDOW (dialog));
124
image_new_from_image_cmd_callback (GtkAction *action,
129
return_if_no_widget (widget, data);
131
dialog = gimp_dialog_factory_dialog_new (global_dialog_factory,
132
gtk_widget_get_screen (widget),
133
"gimp-image-new-dialog", -1, FALSE);
137
GimpImage *gimage = action_data_get_image (data);
139
image_new_dialog_set (dialog, gimage, NULL);
141
gtk_window_present (GTK_WINDOW (dialog));
146
image_convert_cmd_callback (GtkAction *action,
153
return_if_no_image (gimage, data);
154
return_if_no_widget (widget, data);
155
return_if_no_display (gdisp, data);
157
switch ((GimpImageBaseType) value)
161
gimp_image_convert (gimage, (GimpImageBaseType) value,
162
0, 0, FALSE, FALSE, 0, NULL, NULL);
163
gimp_image_flush (gimage);
167
gtk_widget_show (convert_dialog_new (gimage, widget,
168
GIMP_PROGRESS (gdisp)));
174
image_resize_cmd_callback (GtkAction *action,
177
ImageResizeOptions *options;
182
return_if_no_image (gimage, data);
183
return_if_no_widget (widget, data);
184
return_if_no_display (gdisp, data);
186
options = g_new0 (ImageResizeOptions, 1);
188
options->gdisp = gdisp;
189
options->context = action_data_get_context (data);
191
dialog = resize_dialog_new (GIMP_VIEWABLE (gimage),
192
_("Set Image Canvas Size"), "gimp-image-resize",
194
gimp_standard_help_func, GIMP_HELP_IMAGE_RESIZE,
195
GIMP_DISPLAY_SHELL (gdisp->shell)->unit,
196
image_resize_callback,
199
g_signal_connect_object (gdisp, "disconnect",
200
G_CALLBACK (gtk_widget_destroy),
201
dialog, G_CONNECT_SWAPPED);
203
g_object_weak_ref (G_OBJECT (dialog),
204
(GWeakNotify) g_free, options);
206
gtk_widget_show (dialog);
210
image_resize_to_layers_cmd_callback (GtkAction *action,
214
GimpProgress *progress;
216
return_if_no_display (gdisp, data);
218
progress = gimp_progress_start (GIMP_PROGRESS (gdisp),
219
_("Resizing..."), FALSE);
221
gimp_image_resize_to_layers (gdisp->gimage,
222
action_data_get_context (data),
226
gimp_progress_end (progress);
228
gimp_image_flush (gdisp->gimage);
232
image_print_size_cmd_callback (GtkAction *action,
238
return_if_no_display (gdisp, data);
239
return_if_no_widget (widget, data);
241
dialog = print_size_dialog_new (gdisp->gimage,
242
_("Set Image Print Resolution"),
243
"gimp-image-print-size",
245
gimp_standard_help_func,
246
GIMP_HELP_IMAGE_PRINT_SIZE,
247
image_print_size_callback,
250
g_signal_connect_object (gdisp, "disconnect",
251
G_CALLBACK (gtk_widget_destroy),
252
dialog, G_CONNECT_SWAPPED);
254
gtk_widget_show (dialog);
258
image_scale_cmd_callback (GtkAction *action,
261
ImageScaleDialog *dialog;
264
return_if_no_display (gdisp, data);
265
return_if_no_widget (widget, data);
267
dialog = image_scale_dialog_new (gdisp->gimage, gdisp,
268
action_data_get_context (data),
270
image_scale_callback);
272
g_signal_connect_object (gdisp, "disconnect",
273
G_CALLBACK (gtk_widget_destroy),
274
dialog->dialog, G_CONNECT_SWAPPED);
276
gtk_widget_show (dialog->dialog);
280
image_flip_cmd_callback (GtkAction *action,
285
GimpProgress *progress;
286
return_if_no_display (gdisp, data);
288
progress = gimp_progress_start (GIMP_PROGRESS (gdisp),
289
_("Flipping..."), FALSE);
291
gimp_image_flip (gdisp->gimage, action_data_get_context (data),
292
(GimpOrientationType) value, progress);
295
gimp_progress_end (progress);
297
gimp_image_flush (gdisp->gimage);
301
image_rotate_cmd_callback (GtkAction *action,
306
GimpProgress *progress;
307
return_if_no_display (gdisp, data);
309
progress = gimp_progress_start (GIMP_PROGRESS (gdisp),
310
_("Rotating..."), FALSE);
312
gimp_image_rotate (gdisp->gimage, action_data_get_context (data),
313
(GimpRotationType) value, progress);
316
gimp_progress_end (progress);
318
gimp_image_flush (gdisp->gimage);
322
image_crop_cmd_callback (GtkAction *action,
327
return_if_no_image (gimage, data);
329
if (! gimp_channel_bounds (gimp_image_get_mask (gimage),
332
g_message (_("Cannot crop because the current selection is empty."));
336
gimp_image_crop (gimage, action_data_get_context (data),
337
x1, y1, x2, y2, FALSE, TRUE);
338
gimp_image_flush (gimage);
342
image_duplicate_cmd_callback (GtkAction *action,
346
GimpDisplayShell *shell;
347
GimpImage *new_gimage;
348
return_if_no_display (gdisp, data);
350
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
352
new_gimage = gimp_image_duplicate (gdisp->gimage);
354
gimp_create_display (new_gimage->gimp,
356
shell->unit, shell->scale);
358
g_object_unref (new_gimage);
362
image_merge_layers_cmd_callback (GtkAction *action,
365
ImageMergeLayersDialog *dialog;
368
return_if_no_image (gimage, data);
369
return_if_no_widget (widget, data);
371
dialog = image_merge_layers_dialog_new (gimage,
372
action_data_get_context (data),
374
image_merge_layers_type);
376
g_signal_connect (dialog->dialog, "response",
377
G_CALLBACK (image_merge_layers_response),
380
gtk_widget_show (dialog->dialog);
384
image_flatten_image_cmd_callback (GtkAction *action,
388
return_if_no_image (gimage, data);
390
gimp_image_flatten (gimage, action_data_get_context (data));
391
gimp_image_flush (gimage);
395
image_configure_grid_cmd_callback (GtkAction *action,
399
GimpDisplayShell *shell;
401
return_if_no_display (gdisp, data);
403
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
404
gimage = gdisp->gimage;
406
if (! shell->grid_dialog)
408
shell->grid_dialog = grid_dialog_new (gdisp->gimage, gdisp->shell);
410
gtk_window_set_transient_for (GTK_WINDOW (shell->grid_dialog),
411
GTK_WINDOW (gdisp->shell));
412
gtk_window_set_destroy_with_parent (GTK_WINDOW (shell->grid_dialog),
415
g_object_add_weak_pointer (G_OBJECT (shell->grid_dialog),
416
(gpointer *) &shell->grid_dialog);
419
gtk_window_present (GTK_WINDOW (shell->grid_dialog));
423
/* private functions */
426
image_resize_callback (GtkWidget *dialog,
427
GimpViewable *viewable,
434
ImageResizeOptions *options = data;
436
if (width > 0 && height > 0)
438
GimpImage *image = GIMP_IMAGE (viewable);
439
GimpDisplay *gdisp = options->gdisp;
440
GimpContext *context = options->context;
441
GimpProgress *progress;
443
gtk_widget_destroy (dialog);
445
if (width == image->width && height == image->height)
448
progress = gimp_progress_start (GIMP_PROGRESS (gdisp),
449
_("Resizing..."), FALSE);
451
gimp_image_resize (image,
453
width, height, offset_x, offset_y,
457
gimp_progress_end (progress);
459
gimp_image_flush (image);
463
g_warning ("Resize Error: "
464
"Both width and height must be greater than zero.");
469
image_print_size_callback (GtkWidget *dialog,
473
GimpUnit resolution_unit,
476
gtk_widget_destroy (dialog);
478
if (xresolution == image->xresolution &&
479
yresolution == image->yresolution &&
480
resolution_unit == image->resolution_unit)
483
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_SCALE,
484
_("Change Print Size"));
486
gimp_image_set_resolution (image, xresolution, yresolution);
487
gimp_image_set_unit (image, resolution_unit);
489
gimp_image_undo_group_end (image);
491
gimp_image_flush (image);
496
image_scale_callback (ImageScaleDialog *dialog)
498
GimpImage *image = dialog->gimage;
500
if (dialog->width == image->width &&
501
dialog->height == image->height &&
502
dialog->xresolution == image->xresolution &&
503
dialog->yresolution == image->yresolution &&
504
dialog->resolution_unit == image->resolution_unit)
507
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_SCALE,
510
gimp_image_set_resolution (image,
511
dialog->xresolution, dialog->yresolution);
512
gimp_image_set_unit (image, dialog->resolution_unit);
514
if (dialog->width != image->width || dialog->height != image->height)
516
if (dialog->width > 0 && dialog->height > 0)
518
GimpProgress *progress;
520
progress = gimp_progress_start (GIMP_PROGRESS (dialog->gdisp),
521
_("Scaling..."), FALSE);
523
gimp_image_scale (image,
526
dialog->interpolation,
530
gimp_progress_end (progress);
534
g_warning ("Scale Error: "
535
"Both width and height must be greater than zero.");
539
gimp_image_undo_group_end (image);
541
gimp_image_flush (image);
545
image_merge_layers_response (GtkWidget *widget,
547
ImageMergeLayersDialog *dialog)
549
if (response_id == GTK_RESPONSE_OK)
551
image_merge_layers_type = dialog->merge_type;
553
gimp_image_merge_visible_layers (dialog->gimage,
555
image_merge_layers_type);
556
gimp_image_flush (dialog->gimage);
559
gtk_widget_destroy (widget);