+\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 result, orientation_symbol;
+ GtkPageOrientation orientation;
+
+ if (page_setup == NULL)
+ page_setup = gtk_page_setup_new ();
+ result = list4 (Fcons (Qleft_margin,
+ make_float (gtk_page_setup_get_left_margin (page_setup,
+ GTK_UNIT_POINTS))),
+ Fcons (Qright_margin,
+ make_float (gtk_page_setup_get_right_margin (page_setup,
+ GTK_UNIT_POINTS))),
+ Fcons (Qtop_margin,
+ make_float (gtk_page_setup_get_top_margin (page_setup,
+ GTK_UNIT_POINTS))),
+ Fcons (Qbottom_margin,
+ make_float (gtk_page_setup_get_bottom_margin (page_setup,
+ GTK_UNIT_POINTS))));
+ result = Fcons (Fcons (Qheight,
+ make_float (gtk_page_setup_get_page_height (page_setup,
+ GTK_UNIT_POINTS))),
+ result);
+ result = Fcons (Fcons (Qwidth,
+ make_float (gtk_page_setup_get_page_width (page_setup,
+ GTK_UNIT_POINTS))),
+ result);
+ orientation = gtk_page_setup_get_orientation (page_setup);
+ if (orientation == GTK_PAGE_ORIENTATION_PORTRAIT)
+ orientation_symbol = Qportrait;
+ else if (orientation == GTK_PAGE_ORIENTATION_LANDSCAPE)
+ orientation_symbol = Qlandscape;
+ else if (orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
+ orientation_symbol = Qreverse_portrait;
+ else if (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE)
+ orientation_symbol = Qreverse_landscape;
+ result = Fcons (Fcons (Qorientation, orientation_symbol), result);
+
+ return result;
+}
+
+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 */
+