5 #include "display-gtk.h"
7 static void show_one_dive(struct dive *dive, cairo_t *cr, double w, double h)
9 struct graphics_context gc = {
13 plot(&gc, w, h, dive);
16 static void print(int divenr, cairo_t *cr, double x, double y, double w, double h)
20 dive = get_dive(divenr);
24 cairo_translate(cr, x, y);
26 /* Dive plot in the upper half */
27 show_one_dive(dive, cr, w, h/2);
29 /* Dive information in the lower half */
34 static void draw_page(GtkPrintOperation *operation,
35 GtkPrintContext *context,
44 cr = gtk_print_context_get_cairo_context(context);
45 layout=gtk_print_context_create_pango_layout(context);
47 w = gtk_print_context_get_width(context) / 2;
48 h = gtk_print_context_get_height(context) / 2;
51 print(nr+0, cr, 0, 0, w, h);
52 print(nr+1, cr, w, 0, w, h);
53 print(nr+2, cr, 0, h, w, h);
54 print(nr+3, cr, w, h, w, h);
56 pango_cairo_show_layout(cr,layout);
57 g_object_unref(layout);
60 static void begin_print(GtkPrintOperation *operation, gpointer user_data)
64 static GtkPrintSettings *settings = NULL;
69 GtkPrintOperation *print;
70 GtkPrintOperationResult res;
72 print = gtk_print_operation_new();
74 gtk_print_operation_set_print_settings(print, settings);
75 pages = (dive_table.nr + 3) / 4;
76 gtk_print_operation_set_n_pages(print, pages);
77 g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL);
78 g_signal_connect(print, "draw_page", G_CALLBACK(draw_page), NULL);
79 res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
80 GTK_WINDOW(main_window), NULL);
81 if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
83 g_object_unref(settings);
84 settings = g_object_ref(gtk_print_operation_get_print_settings(print));
86 g_object_unref(print);