1
/* GIMP - The GNU 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 <libgimp/gimp.h>
24
#include <libgimp/gimpui.h>
27
#include "print-page-layout.h"
29
#include "libgimp/stdplugins-intl.h"
37
GimpSizeEntry *size_entry;
38
GimpSizeEntry *resolution_entry;
39
GimpChainButton *chain;
40
GtkWidget *area_label;
44
static void run_page_setup_dialog (GtkWidget *widget,
47
static GtkWidget * print_size_frame (PrintData *data);
49
static void print_size_info_size_changed (GtkWidget *widget);
50
static void print_size_info_resolution_changed (GtkWidget *widget);
51
static void print_size_info_unit_changed (GtkWidget *widget);
52
static void print_size_info_chain_toggled (GtkWidget *widget);
54
static void print_size_info_set_size (PrintSizeInfo *info,
58
static void print_size_info_set_resolution (PrintSizeInfo *info,
63
static void print_size_info_set_page_setup (PrintSizeInfo *info);
66
static PrintSizeInfo info;
70
print_page_layout_gui (PrintData *data)
78
memset (&info, 0, sizeof (PrintSizeInfo));
81
info.image_width = gimp_image_width (data->image_id);
82
info.image_height = gimp_image_height (data->image_id);
84
main_vbox = gtk_vbox_new (FALSE, 12);
85
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
87
hbox = gtk_hbox_new (FALSE, 0);
88
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
89
gtk_widget_show (hbox);
91
button = gtk_button_new_with_mnemonic (_("_Adjust Page Size "
93
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
94
g_signal_connect (G_OBJECT (button), "clicked",
95
G_CALLBACK (run_page_setup_dialog),
97
gtk_widget_show (button);
100
/* Commented out until the header becomes a little more configurable
101
* and we can provide a user interface to include/exclude information.
103
button = gtk_check_button_new_with_label ("Print image header");
104
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
105
data->show_info_header);
106
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
107
g_signal_connect (G_OBJECT (button), "toggled",
108
G_CALLBACK (gimp_toggle_button_update),
109
&data->show_info_header);
110
gtk_widget_show (button);
113
/* label for the printable area */
115
hbox = gtk_hbox_new (FALSE, 6);
116
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
117
gtk_widget_show (hbox);
119
label = gtk_label_new (_("Printable area:"));
120
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
121
gtk_widget_show (label);
123
label = gtk_label_new (NULL);
124
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
125
gimp_label_set_attributes (GTK_LABEL (label),
126
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
128
info.area_label = label;
130
gtk_box_pack_start (GTK_BOX (hbox), info.area_label, FALSE, FALSE, 0);
131
gtk_widget_show (info.area_label);
133
/* size entry area for the image's print size */
135
hbox = gtk_hbox_new (FALSE, 0);
136
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
137
gtk_widget_show (hbox);
139
frame = print_size_frame (data);
140
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
141
gtk_widget_show (frame);
143
print_size_info_set_page_setup (&info);
149
run_page_setup_dialog (GtkWidget *widget,
152
GtkPrintOperation *operation;
153
GtkPrintSettings *settings;
154
GtkPageSetup *page_setup;
157
operation = data->operation;
159
/* find a transient parent if possible */
160
toplevel = gtk_widget_get_toplevel (widget);
161
if (! GTK_WIDGET_TOPLEVEL (toplevel))
164
settings = gtk_print_operation_get_print_settings (operation);
166
settings = gtk_print_settings_new ();
168
page_setup = gtk_print_operation_get_default_page_setup (operation);
170
page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (toplevel),
171
page_setup, settings);
173
gtk_print_operation_set_default_page_setup (operation, page_setup);
175
print_size_info_set_page_setup (&info);
182
print_size_frame (PrintData *data)
191
GtkSizeGroup *label_group;
192
GtkSizeGroup *entry_group;
195
gdouble image_height;
197
image_width = (info.image_width *
198
gimp_unit_get_factor (data->unit) / data->xres);
199
image_height = (info.image_height *
200
gimp_unit_get_factor (data->unit) / data->yres);
202
frame = gimp_frame_new (_("Image Size"));
204
vbox = gtk_vbox_new (FALSE, 12);
205
gtk_container_add (GTK_CONTAINER (frame), vbox);
206
gtk_widget_show (vbox);
208
label_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
209
entry_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
211
/* the print size entry */
213
hbox = gtk_hbox_new (FALSE, 0);
214
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
215
gtk_widget_show (hbox);
217
entry = gimp_size_entry_new (1, data->unit, "%p",
218
FALSE, FALSE, FALSE, SB_WIDTH,
219
GIMP_SIZE_ENTRY_UPDATE_NONE);
220
gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
221
gtk_widget_show (entry);
223
info.size_entry = GIMP_SIZE_ENTRY (entry);
225
gtk_table_set_row_spacings (GTK_TABLE (entry), 2);
226
gtk_table_set_col_spacing (GTK_TABLE (entry), 0, 6);
227
gtk_table_set_col_spacing (GTK_TABLE (entry), 2, 6);
229
height = gimp_spin_button_new (&adj, 1, 1, 1, 1, 10, 0, 1, 2);
230
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (entry),
231
GTK_SPIN_BUTTON (height), NULL);
232
gtk_table_attach_defaults (GTK_TABLE (entry), height, 1, 2, 0, 1);
233
gtk_widget_show (height);
235
gtk_size_group_add_widget (entry_group, height);
236
g_object_unref (entry_group);
238
gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (entry),
239
_("_Width:"), 0, 0, 0.0);
240
label = gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (entry),
241
_("_Height:"), 1, 0, 0.0);
243
gtk_size_group_add_widget (label_group, label);
244
g_object_unref (label_group);
246
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 0,
248
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 1,
251
gimp_size_entry_set_value (GIMP_SIZE_ENTRY (entry), 0, image_width);
252
gimp_size_entry_set_value (GIMP_SIZE_ENTRY (entry), 1, image_height);
254
/* the resolution entry */
256
hbox = gtk_hbox_new (FALSE, 0);
257
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
258
gtk_widget_show (hbox);
260
entry = gimp_size_entry_new (1, gimp_image_get_unit (data->image_id),
262
FALSE, FALSE, FALSE, SB_WIDTH,
263
GIMP_SIZE_ENTRY_UPDATE_RESOLUTION);
264
gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
265
gtk_widget_show (entry);
267
info.resolution_entry = GIMP_SIZE_ENTRY (entry);
269
gtk_table_set_row_spacings (GTK_TABLE (entry), 2);
270
gtk_table_set_col_spacing (GTK_TABLE (entry), 0, 6);
271
gtk_table_set_col_spacing (GTK_TABLE (entry), 2, 6);
273
height = gimp_spin_button_new (&adj, 1, 1, 1, 1, 10, 0, 1, 2);
274
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (entry),
275
GTK_SPIN_BUTTON (height), NULL);
276
gtk_table_attach_defaults (GTK_TABLE (entry), height, 1, 2, 0, 1);
277
gtk_widget_show (height);
279
gtk_size_group_add_widget (entry_group, height);
281
gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (entry),
282
_("_X resolution:"), 0, 0, 0.0);
283
label = gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (entry),
284
_("_Y resolution:"), 1, 0, 0.0);
286
gtk_size_group_add_widget (label_group, label);
288
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (entry), 0,
290
GIMP_MAX_RESOLUTION);
291
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (entry), 1,
293
GIMP_MAX_RESOLUTION);
295
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (entry), 0, data->xres);
296
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (entry), 1, data->yres);
298
chain = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
299
gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain), TRUE);
300
gtk_table_attach (GTK_TABLE (entry), chain, 2, 3, 0, 2,
301
GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
302
gtk_widget_show (chain);
304
info.chain = GIMP_CHAIN_BUTTON (chain);
306
g_signal_connect (info.size_entry, "value-changed",
307
G_CALLBACK (print_size_info_size_changed),
309
g_signal_connect (info.resolution_entry, "value-changed",
310
G_CALLBACK (print_size_info_resolution_changed),
312
g_signal_connect (info.size_entry, "unit-changed",
313
G_CALLBACK (print_size_info_unit_changed),
315
g_signal_connect (info.chain, "toggled",
316
G_CALLBACK (print_size_info_chain_toggled),
323
print_size_info_size_changed (GtkWidget *widget)
331
scale = gimp_unit_get_factor (gimp_size_entry_get_unit (info.size_entry));
333
width = gimp_size_entry_get_value (info.size_entry, 0);
334
height = gimp_size_entry_get_value (info.size_entry, 1);
336
xres = scale * info.image_width / MAX (0.0001, width);
337
yres = scale * info.image_height / MAX (0.0001, height);
339
print_size_info_set_resolution (&info, xres, yres);
343
print_size_info_resolution_changed (GtkWidget *widget)
345
GimpSizeEntry *entry = info.resolution_entry;
346
gdouble xres = gimp_size_entry_get_refval (entry, 0);
347
gdouble yres = gimp_size_entry_get_refval (entry, 1);
349
print_size_info_set_resolution (&info, xres, yres);
353
print_size_info_unit_changed (GtkWidget *widget)
355
PrintData *data = info.data;
356
GimpSizeEntry *entry = info.size_entry;
357
gdouble factor = gimp_unit_get_factor (data->unit);
360
data->unit = gimp_size_entry_get_unit (entry);
362
factor = gimp_unit_get_factor (data->unit) / factor;
364
w = gimp_size_entry_get_value (entry, 0) * factor;
365
h = gimp_size_entry_get_value (entry, 1) * factor;
367
print_size_info_set_page_setup (&info);
368
print_size_info_set_size (&info, w, h);
372
print_size_info_chain_toggled (GtkWidget *widget)
374
print_size_info_set_page_setup (&info);
378
print_size_info_set_size (PrintSizeInfo *info,
382
g_signal_handlers_block_by_func (info->size_entry,
383
print_size_info_size_changed,
386
gimp_size_entry_set_value (info->size_entry, 0, width);
387
gimp_size_entry_set_value (info->size_entry, 1, height);
389
g_signal_handlers_unblock_by_func (info->size_entry,
390
print_size_info_size_changed,
395
print_size_info_set_resolution (PrintSizeInfo *info,
399
PrintData *data = info->data;
401
xres = CLAMP (xres, GIMP_MIN_RESOLUTION, GIMP_MAX_RESOLUTION);
402
yres = CLAMP (yres, GIMP_MIN_RESOLUTION, GIMP_MAX_RESOLUTION);
404
if (info->chain && gimp_chain_button_get_active (info->chain))
406
if (xres != data->xres)
415
g_signal_handlers_block_by_func (info->resolution_entry,
416
print_size_info_resolution_changed,
419
gimp_size_entry_set_refval (info->resolution_entry, 0, xres);
420
gimp_size_entry_set_refval (info->resolution_entry, 1, yres);
422
g_signal_handlers_unblock_by_func (info->resolution_entry,
423
print_size_info_resolution_changed,
426
g_signal_handlers_block_by_func (info->size_entry,
427
print_size_info_size_changed,
430
gimp_size_entry_set_value (info->size_entry, 0,
432
gimp_unit_get_factor (data->unit) / xres);
433
gimp_size_entry_set_value (info->size_entry, 1,
435
gimp_unit_get_factor (data->unit) / yres);
437
g_signal_handlers_unblock_by_func (info->size_entry,
438
print_size_info_size_changed,
443
print_size_info_set_page_setup (PrintSizeInfo *info)
446
PrintData *data = info->data;
454
setup = gtk_print_operation_get_default_page_setup (data->operation);
457
setup = gtk_page_setup_new ();
458
gtk_print_operation_set_default_page_setup (data->operation, setup);
461
page_width = (gtk_page_setup_get_page_width (setup, GTK_UNIT_INCH) *
462
gimp_unit_get_factor (data->unit));
463
page_height = (gtk_page_setup_get_page_height (setup, GTK_UNIT_INCH) *
464
gimp_unit_get_factor (data->unit));
466
format = g_strdup_printf ("%%.%df x %%.%df %s",
467
gimp_unit_get_digits (data->unit),
468
gimp_unit_get_digits (data->unit),
469
gimp_unit_get_plural (data->unit));
470
text = g_strdup_printf (format, page_width, page_height);
473
gtk_label_set_text (GTK_LABEL (info->area_label), text);
479
if (info->chain && gimp_chain_button_get_active (info->chain))
483
ratio = (gdouble) info->image_width / (gdouble) info->image_height;
491
gimp_size_entry_set_value_boundaries (info->size_entry, 0, 0.0, x);
492
gimp_size_entry_set_value_boundaries (info->size_entry, 1, 0.0, y);
494
x = info->image_width / page_width;
495
y = info->image_height / page_height;
497
if (info->chain && gimp_chain_button_get_active (info->chain))
499
gdouble max = MAX (x, y);
504
gimp_size_entry_set_refval_boundaries (info->resolution_entry, 0,
505
x, GIMP_MAX_RESOLUTION);
506
gimp_size_entry_set_refval_boundaries (info->resolution_entry, 1,
507
y, GIMP_MAX_RESOLUTION);
509
/* FIXME: is this still needed at all? */
510
data->orientation = gtk_page_setup_get_orientation (setup);