+\f
+/***********************************************************************
+ Printing
+ ***********************************************************************/
+#ifdef USE_CAIRO
+static GtkPrintSettings *print_settings = NULL;
+static GtkPageSetup *page_setup = NULL;
+
+void
+xg_page_setup_dialog (void)
+{
+ GtkPageSetup *new_page_setup = NULL;
+
+ if (print_settings == NULL)
+ print_settings = gtk_print_settings_new ();
+ new_page_setup = gtk_print_run_page_setup_dialog (NULL, page_setup,
+ print_settings);
+ if (page_setup)
+ g_object_unref (page_setup);
+ page_setup = new_page_setup;
+}
+
+Lisp_Object
+xg_get_page_setup (void)
+{
+ Lisp_Object orientation_symbol;
+
+ if (page_setup == NULL)
+ page_setup = gtk_page_setup_new ();
+
+ switch (gtk_page_setup_get_orientation (page_setup))
+ {
+ case GTK_PAGE_ORIENTATION_PORTRAIT:
+ orientation_symbol = Qportrait;
+ break;
+ case GTK_PAGE_ORIENTATION_LANDSCAPE:
+ orientation_symbol = Qlandscape;
+ break;
+ case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT:
+ orientation_symbol = Qreverse_portrait;
+ break;
+ case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE:
+ orientation_symbol = Qreverse_landscape;
+ break;
+ default:
+ eassume (false);
+ }
+
+ return listn (CONSTYPE_HEAP, 7,
+ Fcons (Qorientation, orientation_symbol),
+#define MAKE_FLOAT_PAGE_SETUP(f) make_float (f (page_setup, GTK_UNIT_POINTS))
+ Fcons (Qwidth,
+ MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_page_width)),
+ Fcons (Qheight,
+ MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_page_height)),
+ Fcons (Qleft_margin,
+ MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_left_margin)),
+ Fcons (Qright_margin,
+ MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_right_margin)),
+ Fcons (Qtop_margin,
+ MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_top_margin)),
+ Fcons (Qbottom_margin,
+ MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_bottom_margin))
+#undef MAKE_FLOAT_PAGE_SETUP
+ );
+}
+
+static void
+draw_page (GtkPrintOperation *operation, GtkPrintContext *context,
+ gint page_nr, gpointer user_data)
+{
+ Lisp_Object frames = *((Lisp_Object *) user_data);
+ struct frame *f = XFRAME (Fnth (make_number (page_nr), frames));
+ cairo_t *cr = gtk_print_context_get_cairo_context (context);
+
+ x_cr_draw_frame (cr, f);
+}
+
+void
+xg_print_frames_dialog (Lisp_Object frames)
+{
+ GtkPrintOperation *print;
+ GtkPrintOperationResult res;
+
+ print = gtk_print_operation_new ();
+ if (print_settings != NULL)
+ gtk_print_operation_set_print_settings (print, print_settings);
+ if (page_setup != NULL)
+ gtk_print_operation_set_default_page_setup (print, page_setup);
+ gtk_print_operation_set_n_pages (print, XINT (Flength (frames)));
+ g_signal_connect (print, "draw-page", G_CALLBACK (draw_page), &frames);
+ res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
+ NULL, NULL);
+ if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
+ {
+ if (print_settings != NULL)
+ g_object_unref (print_settings);
+ print_settings =
+ g_object_ref (gtk_print_operation_get_print_settings (print));
+ }
+ g_object_unref (print);
+}
+
+#endif /* USE_CAIRO */
+