]> git.street.me.uk Git - andy/viking.git/blame - src/print.c
Fix translatable string with variable argument
[andy/viking.git] / src / print.c
CommitLineData
42f34743
QT
1/*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3 *
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
5 *
6 * print.c
7 * Copyright (C) 2007, Quy Tonthat <qtonthat@gmail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
4c77d5e0
GB
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
9a995996 27
42f34743
QT
28#include <string.h>
29#include <glib/gprintf.h>
4c77d5e0
GB
30#include <glib/gi18n.h>
31#include <gtk/gtk.h>
32
42f34743
QT
33#include "viking.h"
34#include "print.h"
35#include "print-preview.h"
36
37typedef enum
38{
39 VIK_PRINT_CENTER_NONE = 0,
40 VIK_PRINT_CENTER_HORIZONTALLY,
41 VIK_PRINT_CENTER_VERTICALLY,
42 VIK_PRINT_CENTER_BOTH,
43} PrintCenterMode;
44
45typedef struct {
46 gchar *name;
47 PrintCenterMode mode;
48} PrintCenterName;
49
50static const PrintCenterName center_modes[] = {
4c77d5e0
GB
51 {N_("None"), VIK_PRINT_CENTER_NONE},
52 {N_("Horizontally"), VIK_PRINT_CENTER_HORIZONTALLY},
53 {N_("Vertically"), VIK_PRINT_CENTER_VERTICALLY},
54 {N_("Both"), VIK_PRINT_CENTER_BOTH},
42f34743
QT
55 {NULL, -1}
56};
57
58typedef struct {
59 gint num_pages;
60 gboolean show_info_header;
61 VikWindow *vw;
62 VikViewport *vvp;
63 gdouble xmpp, ympp; /* zoom level (meters/pixel) */
64 gdouble xres;
65 gdouble yres;
66 gint width;
67 gint height;
68 gdouble offset_x;
69 gdouble offset_y;
70 PrintCenterMode center;
71 gboolean use_full_page;
72 GtkPrintOperation *operation;
73} PrintData;
74
75static GtkWidget *create_custom_widget_cb(GtkPrintOperation *operation, PrintData *data);
76static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context, PrintData *data);
77static void draw_page(GtkPrintOperation *print, GtkPrintContext *context, gint page_nr, PrintData *data);
78static void end_print(GtkPrintOperation *operation, GtkPrintContext *context, PrintData *data);
79
80void a_print(VikWindow *vw, VikViewport *vvp)
81{
82 /* TODO: make print_settings non-static when saving_settings_to_file is
83 * implemented. Keep it static for now to retain settings for each
84 * viking session
85 */
86 static GtkPrintSettings *print_settings = NULL;
87
88 GtkPrintOperation *print_oper;
89 GtkPrintOperationResult res;
90 PrintData data;
91
92 print_oper = gtk_print_operation_new ();
93
94 data.num_pages = 1;
95 data.vw = vw;
96 data.vvp = vvp;
97 data.offset_x = 0;
98 data.offset_y = 0;
99 data.center = VIK_PRINT_CENTER_BOTH;
100 data.use_full_page = FALSE;
101 data.operation = print_oper;
102
103 data.xmpp = vik_viewport_get_xmpp(vvp);
104 data.ympp = vik_viewport_get_ympp(vvp);
105 data.width = vik_viewport_get_width(vvp);
106 data.height = vik_viewport_get_height(vvp);
107
436fa17a 108 data.xres = data.yres = 1; // This forces it to default to a 100% page size
42f34743
QT
109
110 if (print_settings != NULL)
111 gtk_print_operation_set_print_settings (print_oper, print_settings);
112
113 g_signal_connect (print_oper, "begin_print", G_CALLBACK (begin_print), &data);
114 g_signal_connect (print_oper, "draw_page", G_CALLBACK (draw_page), &data);
115 g_signal_connect (print_oper, "end-print", G_CALLBACK (end_print), &data);
116 g_signal_connect (print_oper, "create-custom-widget", G_CALLBACK (create_custom_widget_cb), &data);
117
7760b0cf 118 gtk_print_operation_set_custom_tab_label (print_oper, _("Image Settings"));
42f34743
QT
119
120 res = gtk_print_operation_run (print_oper,
121 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
122 GTK_WINDOW (vw), NULL);
123
124 if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
125 if (print_settings != NULL)
126 g_object_unref (print_settings);
127 print_settings = g_object_ref (gtk_print_operation_get_print_settings (print_oper));
128 }
129
130 g_object_unref (print_oper);
131}
132
133static void begin_print(GtkPrintOperation *operation,
134 GtkPrintContext *context,
135 PrintData *data)
136{
137 // fputs("DEBUG: begin_print() called\n", stderr);
138 gtk_print_operation_set_n_pages (operation, data->num_pages);
139 gtk_print_operation_set_use_full_page (operation, data->use_full_page);
140
141}
142
143static void end_print(GtkPrintOperation *operation,
144 GtkPrintContext *context,
145 PrintData *data)
146{
147 // fputs("DEBUG: end_print() called\n", stderr);
148
149}
150
151static void copy_row_from_rgb(guchar *surface_pixels, guchar *pixbuf_pixels, gint width)
152{
153 guint32 *cairo_data = (guint32 *) surface_pixels;
154 guchar *p;
155 gint i;
156
157 for (i = 0, p = pixbuf_pixels; i < width; i++) {
158 guint32 r = *p++;
159 guint32 g = *p++;
160 guint32 b = *p++;
161 cairo_data[i] = 0xFF000000 | (r << 16) | (g << 8) | b;
162 }
163}
164
165#define INT_MULT(a,b,t) ((t) = (a) * (b) + 0x80, ((((t) >> 8) + (t)) >> 8))
166#define INT_BLEND(a,b,alpha,tmp) (INT_MULT((a) - (b), alpha, tmp) + (b))
167static void copy_row_from_rgba(guchar *surface_pixels, guchar *pixbuf_pixels, gint width)
168{
169 guint32 *cairo_data = (guint32 *) surface_pixels;
170 guchar *p;
171 gint i;
172
173 for (i = 0, p = pixbuf_pixels; i < width; i++) {
174 guint32 r = *p++;
175 guint32 g = *p++;
176 guint32 b = *p++;
177 guint32 a = *p++;
178
179 if (a != 255) {
180 guint32 tmp;
181 /* composite on a white background */
182 r = INT_BLEND (r, 255, a, tmp);
183 g = INT_BLEND (g, 255, a, tmp);
184 b = INT_BLEND (b, 255, a, tmp);
185 }
186 cairo_data[i] = 0xFF000000 | (r << 16) | (g << 8) | b;
187 }
188}
189
190static void draw_page_cairo(GtkPrintContext *context, PrintData *data)
191{
192 cairo_t *cr;
193 GdkPixbuf *pixbuf_to_draw;
194 cairo_surface_t *surface;
195 guchar *surface_pixels;
196 guchar *pixbuf_pixels;
197 gint stride;
198 gint pixbuf_stride;
199 gint pixbuf_n_channels;
42f34743
QT
200 gdouble cr_dpi_x;
201 gdouble cr_dpi_y;
202 gdouble scale_x;
203 gdouble scale_y;
204 gint y;
205
206 cr = gtk_print_context_get_cairo_context(context);
207 pixbuf_to_draw = gdk_pixbuf_get_from_drawable(NULL,
208 GDK_DRAWABLE(vik_viewport_get_pixmap(data->vvp)),
209 NULL, 0, 0, 0, 0, data->width, data->height);
210 surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
211 data->width, data->height);
212
42f34743
QT
213 cr_dpi_x = gtk_print_context_get_dpi_x (context);
214 cr_dpi_y = gtk_print_context_get_dpi_y (context);
215
216 scale_x = cr_dpi_x / data->xres;
217 scale_y = cr_dpi_y / data->yres;
218
219 cairo_translate (cr,
220 data->offset_x / cr_dpi_x * 72.0,
221 data->offset_y / cr_dpi_y * 72.0);
222 cairo_scale (cr, scale_x, scale_y);
223
224 surface_pixels = cairo_image_surface_get_data (surface);
225 stride = cairo_image_surface_get_stride (surface);
226 pixbuf_pixels = gdk_pixbuf_get_pixels (pixbuf_to_draw);
227 pixbuf_stride = gdk_pixbuf_get_rowstride(pixbuf_to_draw);
228 pixbuf_n_channels = gdk_pixbuf_get_n_channels(pixbuf_to_draw);
229
230 // fprintf(stderr, "DEBUG: %s() surface_pixels=%p pixbuf_pixels=%p size=%d surface_width=%d surface_height=%d stride=%d data_height=%d pixmap_stride=%d pixmap_nchannels=%d pixmap_bit_per_Sample=%d\n", __PRETTY_FUNCTION__, surface_pixels, pixbuf_pixels, stride * data->height, cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface), stride, data->height, gdk_pixbuf_get_rowstride(pixbuf_to_draw), gdk_pixbuf_get_n_channels(pixbuf_to_draw), gdk_pixbuf_get_bits_per_sample(pixbuf_to_draw));
231
232 /* Assume the pixbuf has 8 bits per channel */
233 for (y = 0; y < data->height; y++, surface_pixels += stride, pixbuf_pixels += pixbuf_stride) {
234 switch (pixbuf_n_channels) {
235 case 3:
236 copy_row_from_rgb (surface_pixels, pixbuf_pixels, data->width);
237 break;
238 case 4:
239 copy_row_from_rgba (surface_pixels, pixbuf_pixels, data->width);
240 break;
241 }
242 }
243
244 g_object_unref(G_OBJECT(pixbuf_to_draw));
245
246 cairo_set_source_surface(cr, surface, 0, 0);
247 cairo_rectangle(cr, 0, 0, data->width, data->height);
248 cairo_fill(cr);
249 cairo_surface_destroy(surface);
250}
251
252static void draw_page(GtkPrintOperation *print,
253 GtkPrintContext *context,
254 gint page_nr,
255 PrintData *data)
256{
257 // fprintf(stderr, "DEBUG: draw_page() page_nr=%d\n", page_nr);
258 draw_page_cairo(context, data);
259
260}
261
262/*********************** page layout gui *********************/
263typedef struct
264{
265 PrintData *data;
266 GtkWidget *center_combo;
267 GtkWidget *scale;
268 GtkWidget *scale_label;
269 GtkWidget *preview;
270} CustomWidgetInfo;
271
272enum
273{
274 BOTTOM,
275 TOP,
276 RIGHT,
277 LEFT,
278 WIDTH,
279 HEIGHT
280};
281
282static gboolean scale_change_value_cb(GtkRange *range, GtkScrollType scroll, gdouble value, CustomWidgetInfo *pinfo);
283static void get_page_dimensions (CustomWidgetInfo *info, gdouble *page_width, gdouble *page_height, GtkUnit unit);
284static void center_changed_cb (GtkWidget *combo, CustomWidgetInfo *info);
285static void get_max_offsets (CustomWidgetInfo *info, gdouble *offset_x_max, gdouble *offset_y_max);
286static void update_offsets (CustomWidgetInfo *info);
287
288static void set_scale_label(CustomWidgetInfo *pinfo, gdouble scale_val)
289{
290 static const gdouble inch_to_mm = 25.4;
291 gchar label_text[64];
292
293 g_snprintf(label_text, sizeof(label_text), "<i>%.0fx%0.f mm (%.0f%%)</i>",
294 inch_to_mm * pinfo->data->width / pinfo->data->xres,
295 inch_to_mm * pinfo->data->height / pinfo->data->yres,
296 scale_val);
297 gtk_label_set_markup (GTK_LABEL (pinfo->scale_label), label_text);
298}
299
300static void set_scale_value(CustomWidgetInfo *pinfo)
301{
302 gdouble width;
303 gdouble height;
304 gdouble ratio, ratio_w, ratio_h;
305
306
307 get_page_dimensions (pinfo, &width, &height, GTK_UNIT_INCH);
308 ratio_w = 100 * pinfo->data->width / pinfo->data->xres / width;
309 ratio_h = 100 * pinfo->data->height / pinfo->data->yres / height;
310
311 ratio = MAX(ratio_w, ratio_h);
312 g_signal_handlers_block_by_func(GTK_RANGE(pinfo->scale), scale_change_value_cb, pinfo);
313 gtk_range_set_value(GTK_RANGE(pinfo->scale), ratio);
314 g_signal_handlers_unblock_by_func(GTK_RANGE(pinfo->scale), scale_change_value_cb, pinfo);
315 set_scale_label(pinfo, ratio);
316}
317
318static void update_page_setup (CustomWidgetInfo *pinfo)
319{
320 gdouble paper_width;
321 gdouble paper_height;
322 gdouble offset_x_max, offset_y_max;
323 PrintData *data = pinfo->data;
324
325 get_page_dimensions (pinfo, &paper_width, &paper_height, GTK_UNIT_INCH);
326 if ((paper_width < (pinfo->data->width / data->xres)) ||
327 (paper_height < (pinfo->data->height / data->yres))) {
328 gdouble xres, yres;
329 xres = (gdouble) pinfo->data->width / paper_width;
330 yres = (gdouble) pinfo->data->height / paper_height;
331 data->xres = data->yres = MAX(xres, yres);
332 vik_print_preview_set_image_dpi (VIK_PRINT_PREVIEW (pinfo->preview),
333 data->xres, data->yres);
334 }
335 get_max_offsets (pinfo, &offset_x_max, &offset_y_max);
336 vik_print_preview_set_image_offsets_max (VIK_PRINT_PREVIEW (pinfo->preview),
337 offset_x_max, offset_y_max);
338 update_offsets (pinfo);
339 set_scale_value(pinfo);
340 if (pinfo->preview)
341 vik_print_preview_set_image_offsets (VIK_PRINT_PREVIEW (pinfo->preview),
342 pinfo->data->offset_x, pinfo->data->offset_y);
343
344}
345
346static void page_setup_cb (GtkWidget *widget, CustomWidgetInfo *info)
347{
348 PrintData *data = info->data;
349 GtkPrintOperation *operation = data->operation;
350 GtkPrintSettings *settings;
351 GtkPageSetup *page_setup;
352 GtkWidget *toplevel;
353
354 toplevel = gtk_widget_get_toplevel (widget);
2fd7c35e
RN
355#if GTK_CHECK_VERSION (2,18,0)
356 if (! gtk_widget_is_toplevel (toplevel))
357#else
42f34743 358 if (! GTK_WIDGET_TOPLEVEL (toplevel))
2fd7c35e 359#endif
42f34743
QT
360 toplevel = NULL;
361
362 settings = gtk_print_operation_get_print_settings (operation);
363 if (! settings)
364 settings = gtk_print_settings_new ();
365
366 page_setup = gtk_print_operation_get_default_page_setup (operation);
367
368 page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (toplevel),
369 page_setup, settings);
370
371 gtk_print_operation_set_default_page_setup (operation, page_setup);
372
373 vik_print_preview_set_page_setup (VIK_PRINT_PREVIEW (info->preview),
374 page_setup);
375
376 update_page_setup (info);
377
378}
379
380static void full_page_toggled_cb (GtkWidget *widget, CustomWidgetInfo *pinfo)
381{
382 gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
383
384 pinfo->data->use_full_page = active;
385 update_page_setup (pinfo);
386 vik_print_preview_set_use_full_page (VIK_PRINT_PREVIEW(pinfo->preview),
387 active);
388}
389
390static void set_center_none (CustomWidgetInfo *info)
391{
392 info->data->center = VIK_PRINT_CENTER_NONE;
393
394 if (info->center_combo) {
395 g_signal_handlers_block_by_func (info->center_combo,
396 center_changed_cb, info);
397
398 info->data->center = VIK_PRINT_CENTER_NONE;
399 gtk_combo_box_set_active(GTK_COMBO_BOX(info->center_combo), info->data->center);
400 g_signal_handlers_unblock_by_func (info->center_combo,
401 center_changed_cb, info);
402 }
403}
404
405static void preview_offsets_changed_cb (GtkWidget *widget,
406 gdouble offset_x, gdouble offset_y,
407 CustomWidgetInfo *info)
408{
409 set_center_none (info);
410
411 info->data->offset_x = offset_x;
412 info->data->offset_y = offset_y;
413
414 update_offsets (info);
415
416}
417
418static void get_page_dimensions (CustomWidgetInfo *info,
419 gdouble *page_width,
420 gdouble *page_height,
421 GtkUnit unit)
422{
423 GtkPageSetup *setup;
424
425 setup = gtk_print_operation_get_default_page_setup (info->data->operation);
426
427 *page_width = gtk_page_setup_get_paper_width (setup, unit);
428 *page_height = gtk_page_setup_get_paper_height (setup, unit);
429
430 if (!info->data->use_full_page) {
431 gdouble left_margin = gtk_page_setup_get_left_margin (setup, unit);
432 gdouble right_margin = gtk_page_setup_get_right_margin (setup, unit);
433 gdouble top_margin = gtk_page_setup_get_top_margin (setup, unit);
434 gdouble bottom_margin = gtk_page_setup_get_bottom_margin (setup, unit);
435
436 *page_width -= left_margin + right_margin;
437 *page_height -= top_margin + bottom_margin;
438 }
439
440}
441
442static void get_max_offsets (CustomWidgetInfo *info,
443 gdouble *offset_x_max,
444 gdouble *offset_y_max)
445{
446 gdouble width;
447 gdouble height;
448
449 get_page_dimensions (info, &width, &height, GTK_UNIT_POINTS);
450
451 *offset_x_max = width - 72.0 * info->data->width / info->data->xres;
452 *offset_x_max = MAX (0, *offset_x_max);
453
454 *offset_y_max = height - 72.0 * info->data->height / info->data->yres;
455 *offset_y_max = MAX (0, *offset_y_max);
456}
457
458static void update_offsets (CustomWidgetInfo *info)
459{
460 PrintData *data = info->data;
461 gdouble offset_x_max;
462 gdouble offset_y_max;
463
464 get_max_offsets (info, &offset_x_max, &offset_y_max);
465
466 switch (data->center) {
467 case VIK_PRINT_CENTER_NONE:
468 if (data->offset_x > offset_x_max)
469 data->offset_x = offset_x_max;
470 if (data->offset_y > offset_y_max)
471 data->offset_y = offset_y_max;
472 break;
473
474 case VIK_PRINT_CENTER_HORIZONTALLY:
475 data->offset_x = offset_x_max / 2.0;
476 break;
477
478 case VIK_PRINT_CENTER_VERTICALLY:
479 data->offset_y = offset_y_max / 2.0;
480 break;
481
482 case VIK_PRINT_CENTER_BOTH:
483 data->offset_x = offset_x_max / 2.0;
484 data->offset_y = offset_y_max / 2.0;
485 break;
486 }
487}
488
489static void center_changed_cb (GtkWidget *combo, CustomWidgetInfo *info)
490{
491 info->data->center = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
492 update_offsets (info);
493
494 if (info->preview)
495 vik_print_preview_set_image_offsets (VIK_PRINT_PREVIEW (info->preview),
496 info->data->offset_x, info->data->offset_y);
497}
498
499static gboolean scale_change_value_cb(GtkRange *range,
500 GtkScrollType scroll,
501 gdouble value,
502 CustomWidgetInfo *pinfo)
503{
504 gdouble paper_width;
505 gdouble paper_height;
506 gdouble xres, yres, res;
507 gdouble offset_x_max, offset_y_max;
508 gdouble scale = CLAMP(value, 1, 100);
509
510 get_page_dimensions (pinfo, &paper_width, &paper_height, GTK_UNIT_INCH);
511 xres = pinfo->data->width * 100 / paper_width / scale;
512 yres = pinfo->data->height * 100 / paper_height / scale;
513 res = MAX(xres, yres);
514 pinfo->data->xres = pinfo->data->yres = res;
515 get_max_offsets (pinfo, &offset_x_max, &offset_y_max);
516 update_offsets (pinfo);
517 if (pinfo->preview) {
518 vik_print_preview_set_image_dpi (VIK_PRINT_PREVIEW (pinfo->preview),
519 pinfo->data->xres, pinfo->data->yres);
520 vik_print_preview_set_image_offsets (VIK_PRINT_PREVIEW (pinfo->preview),
521 pinfo->data->offset_x, pinfo->data->offset_y);
522 vik_print_preview_set_image_offsets_max (VIK_PRINT_PREVIEW (pinfo->preview),
523 offset_x_max, offset_y_max);
524 }
525
526 set_scale_label(pinfo, scale);
527
528 return FALSE;
529}
530
531static void custom_widgets_cleanup(CustomWidgetInfo *info)
532{
533 g_free(info);
534}
535
536static GtkWidget *create_custom_widget_cb(GtkPrintOperation *operation, PrintData *data)
537{
538 GtkWidget *layout;
539 GtkWidget *main_hbox;
540 GtkWidget *main_vbox;
541 GtkWidget *hbox;
542 GtkWidget *vbox;
543 GtkWidget *button;
544 GtkWidget *label;
545 GtkPageSetup *setup;
546
547 CustomWidgetInfo *info = g_malloc0(sizeof(CustomWidgetInfo));
7760b0cf 548 g_signal_connect_swapped (data->operation, _("done"), G_CALLBACK (custom_widgets_cleanup), info);
42f34743
QT
549
550
551 info->data = data;
552
553 setup = gtk_print_operation_get_default_page_setup (data->operation);
554 if (! setup) {
555 setup = gtk_page_setup_new ();
556 gtk_print_operation_set_default_page_setup (data->operation, setup);
557 }
558
559 layout = gtk_vbox_new (FALSE, 6);
560 gtk_container_set_border_width (GTK_CONTAINER (layout), 12);
561
562 /* main hbox */
563 main_hbox = gtk_hbox_new (FALSE, 12);
564 gtk_box_pack_start (GTK_BOX (layout), main_hbox, TRUE, TRUE, 0);
565 gtk_widget_show (main_hbox);
566
567 /* main vbox */
568 main_vbox = gtk_vbox_new (FALSE, 12);
569 gtk_box_pack_start (GTK_BOX (main_hbox), main_vbox, FALSE, FALSE, 0);
570 gtk_widget_show (main_vbox);
571
572 vbox = gtk_vbox_new (FALSE, 6);
573 gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
574 gtk_widget_show (vbox);
575
576 /* Page Size */
7760b0cf
JJ
577 button = gtk_button_new_with_mnemonic (_("_Adjust Page Size "
578 "and Orientation"));
42f34743
QT
579 gtk_box_pack_start (GTK_BOX (main_vbox), button, FALSE, FALSE, 0);
580 g_signal_connect (G_OBJECT (button), "clicked",
581 G_CALLBACK (page_setup_cb),
582 info);
583 gtk_widget_show (button);
584
585 /* Center */
586 GtkWidget *combo;
587 const PrintCenterName *center;
588
589 hbox = gtk_hbox_new (FALSE, 6);
590 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
591 gtk_widget_show (hbox);
592
7760b0cf 593 label = gtk_label_new_with_mnemonic (_("C_enter:"));
42f34743
QT
594 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
595 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
596 gtk_widget_show (label);
597
1bc1c05b 598 combo = vik_combo_box_text_new ();
42f34743 599 for (center = center_modes; center->name; center++) {
1bc1c05b 600 vik_combo_box_text_append (combo, _(center->name));
42f34743
QT
601 }
602 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), VIK_PRINT_CENTER_BOTH);
603 gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
604 gtk_widget_show (combo);
605 gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
606 g_signal_connect(combo, "changed",
607 G_CALLBACK(center_changed_cb), info);
608 info->center_combo = combo;
609
610 /* ignore page margins */
7760b0cf 611 button = gtk_check_button_new_with_mnemonic (_("Ignore Page _Margins"));
42f34743
QT
612
613 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
614 data->use_full_page);
615 gtk_box_pack_start (GTK_BOX (main_vbox), button, FALSE, FALSE, 0);
616 g_signal_connect (button, "toggled",
617 G_CALLBACK (full_page_toggled_cb),
618 info);
619 gtk_widget_show (button);
620
621 /* scale */
622 vbox = gtk_vbox_new (FALSE, 1);
623 gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
624 gtk_widget_show (vbox);
625
626 hbox = gtk_hbox_new (FALSE, 6);
627 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
628 gtk_widget_show (hbox);
629
7760b0cf 630 label = gtk_label_new_with_mnemonic (_("Image S_ize:"));
42f34743
QT
631 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
632 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
633 gtk_widget_show (label);
634
635 label = gtk_label_new (NULL);
636 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
637 info->scale_label = label;
638 gtk_box_pack_start (GTK_BOX (hbox), info->scale_label, TRUE, TRUE, 0);
639 gtk_widget_show (info->scale_label);
640
641 info->scale = gtk_hscale_new_with_range(1, 100, 1);
642 gtk_box_pack_start (GTK_BOX (vbox), info->scale, TRUE, TRUE, 0);
643 gtk_scale_set_draw_value(GTK_SCALE(info->scale), FALSE);
644 gtk_widget_show (info->scale);
645 gtk_label_set_mnemonic_widget (GTK_LABEL (label), info->scale);
646
647 g_signal_connect(info->scale, "change_value",
648 G_CALLBACK(scale_change_value_cb), info);
649
650
651 info->preview = vik_print_preview_new (setup, GDK_DRAWABLE(vik_viewport_get_pixmap(data->vvp)));
652 vik_print_preview_set_use_full_page (VIK_PRINT_PREVIEW(info->preview),
653 data->use_full_page);
654 gtk_box_pack_start (GTK_BOX (main_hbox), info->preview, TRUE, TRUE, 0);
655 gtk_widget_show (info->preview);
656
657 g_signal_connect (info->preview, "offsets-changed",
658 G_CALLBACK (preview_offsets_changed_cb),
659 info);
660
661 update_page_setup (info);
662
663 gdouble offset_x_max, offset_y_max;
664 get_max_offsets (info, &offset_x_max, &offset_y_max);
665 vik_print_preview_set_image_offsets_max (VIK_PRINT_PREVIEW (info->preview),
666 offset_x_max, offset_y_max);
667
668 set_scale_value(info);
669
670 return layout;
671}