]> git.tdb.fi Git - ext/subsurface.git/blob - print.c
Separate out the UI from the program logic
[ext/subsurface.git] / print.c
1 #include <gtk/gtk.h>
2
3 #include "dive.h"
4 #include "display.h"
5 #include "display-gtk.h"
6
7 static void draw_page(GtkPrintOperation *operation,
8                         GtkPrintContext *context,
9                         gint page_nr,
10                         gpointer user_data)
11 {
12         cairo_t *cr;
13         PangoLayout *layout;
14         double w, h;
15         struct graphics_context gc = { .printer = 1 };
16
17         cr = gtk_print_context_get_cairo_context(context);
18         gc.cr = cr;
19
20         layout=gtk_print_context_create_pango_layout(context);
21
22         w = gtk_print_context_get_width(context);
23         h = gtk_print_context_get_height(context);
24
25         /* Do the profile on the top half of the page.. */
26         if (current_dive)
27                 plot(&gc, w, h/2, current_dive);
28
29         pango_cairo_show_layout(cr,layout);
30         g_object_unref(layout);
31 }
32
33 static void begin_print(GtkPrintOperation *operation, gpointer user_data)
34 {
35 }
36
37 static GtkPrintSettings *settings = NULL;
38
39 void do_print(void)
40 {
41         GtkPrintOperation *print;
42         GtkPrintOperationResult res;
43
44         print = gtk_print_operation_new();
45         if (settings != NULL)
46                 gtk_print_operation_set_print_settings(print, settings);
47         gtk_print_operation_set_n_pages(print, 1);
48         g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL);
49         g_signal_connect(print, "draw_page", G_CALLBACK(draw_page), NULL);
50         res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
51                                          GTK_WINDOW(main_window), NULL);
52         if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
53                 if (settings != NULL)
54                         g_object_unref(settings);
55                 settings = g_object_ref(gtk_print_operation_get_print_settings(print));
56         }
57         g_object_unref(print);
58 }