1 /* GTK - The GIMP Toolkit
2 * gtkprintoperation.c: Print Operation
3 * Copyright (C) 2006, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include "gtkprintoperation-private.h"
24 #include "gtkmarshalers.h"
25 #include <cairo-pdf.h>
27 #include "gtkprivate.h"
28 #include "gtkmessagedialog.h"
31 #define SHOW_PROGRESS_TIME 1200
33 #define GTK_PRINT_OPERATION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_PRINT_OPERATION, GtkPrintOperationPrivate))
49 PROP_DEFAULT_PAGE_SETUP,
55 PROP_TRACK_PRINT_STATUS,
65 static guint signals[LAST_SIGNAL] = { 0 };
66 static int job_nr = 0;
68 G_DEFINE_TYPE (GtkPrintOperation, gtk_print_operation, G_TYPE_OBJECT)
71 * gtk_print_error_quark:
73 * Registers an error quark for #GtkPrintOperation if necessary.
75 * Return value: The error quark used for #GtkPrintOperation errors.
80 gtk_print_error_quark (void)
82 static GQuark quark = 0;
84 quark = g_quark_from_static_string ("gtk-print-error-quark");
89 gtk_print_operation_finalize (GObject *object)
91 GtkPrintOperation *print_operation = GTK_PRINT_OPERATION (object);
92 GtkPrintOperationPrivate *priv = print_operation->priv;
94 if (priv->free_platform_data &&
97 priv->free_platform_data (priv->platform_data);
98 priv->free_platform_data = NULL;
101 if (priv->default_page_setup)
102 g_object_unref (priv->default_page_setup);
104 if (priv->print_settings)
105 g_object_unref (priv->print_settings);
107 g_free (priv->pdf_target);
108 g_free (priv->job_name);
109 g_free (priv->custom_tab_label);
111 if (priv->print_pages_idle_id > 0)
112 g_source_remove (priv->print_pages_idle_id);
114 if (priv->show_progress_timeout_id > 0)
115 g_source_remove (priv->show_progress_timeout_id);
117 G_OBJECT_CLASS (gtk_print_operation_parent_class)->finalize (object);
121 gtk_print_operation_init (GtkPrintOperation *operation)
123 GtkPrintOperationPrivate *priv;
126 priv = operation->priv = GTK_PRINT_OPERATION_GET_PRIVATE (operation);
128 priv->status = GTK_PRINT_STATUS_INITIAL;
129 priv->status_string = g_strdup ("");
130 priv->default_page_setup = NULL;
131 priv->print_settings = NULL;
132 priv->nr_of_pages = -1;
133 priv->current_page = -1;
134 priv->use_full_page = FALSE;
135 priv->show_dialog = TRUE;
136 priv->show_progress = FALSE;
137 priv->pdf_target = NULL;
138 priv->track_print_status = FALSE;
139 priv->is_sync = FALSE;
142 priv->unit = GTK_UNIT_PIXEL;
144 appname = g_get_application_name ();
145 priv->job_name = g_strdup_printf ("%s job #%d", appname, ++job_nr);
149 gtk_print_operation_set_property (GObject *object,
154 GtkPrintOperation *op = GTK_PRINT_OPERATION (object);
158 case PROP_DEFAULT_PAGE_SETUP:
159 gtk_print_operation_set_default_page_setup (op, g_value_get_object (value));
161 case PROP_PRINT_SETTINGS:
162 gtk_print_operation_set_print_settings (op, g_value_get_object (value));
165 gtk_print_operation_set_job_name (op, g_value_get_string (value));
168 gtk_print_operation_set_n_pages (op, g_value_get_int (value));
170 case PROP_CURRENT_PAGE:
171 gtk_print_operation_set_current_page (op, g_value_get_int (value));
173 case PROP_USE_FULL_PAGE:
174 gtk_print_operation_set_use_full_page (op, g_value_get_boolean (value));
176 case PROP_TRACK_PRINT_STATUS:
177 gtk_print_operation_set_track_print_status (op, g_value_get_boolean (value));
180 gtk_print_operation_set_unit (op, g_value_get_enum (value));
182 case PROP_SHOW_DIALOG:
183 gtk_print_operation_set_show_dialog (op, g_value_get_boolean (value));
185 case PROP_SHOW_PROGRESS:
186 gtk_print_operation_set_show_progress (op, g_value_get_boolean (value));
188 case PROP_PDF_TARGET:
189 gtk_print_operation_set_pdf_target (op, g_value_get_string (value));
191 case PROP_CUSTOM_TAB_LABEL:
192 gtk_print_operation_set_custom_tab_label (op, g_value_get_string (value));
195 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
201 gtk_print_operation_get_property (GObject *object,
206 GtkPrintOperation *op = GTK_PRINT_OPERATION (object);
207 GtkPrintOperationPrivate *priv = op->priv;
211 case PROP_DEFAULT_PAGE_SETUP:
212 g_value_set_object (value, priv->default_page_setup);
214 case PROP_PRINT_SETTINGS:
215 g_value_set_object (value, priv->print_settings);
218 g_value_set_string (value, priv->job_name);
221 g_value_set_int (value, priv->nr_of_pages);
223 case PROP_CURRENT_PAGE:
224 g_value_set_int (value, priv->current_page);
226 case PROP_USE_FULL_PAGE:
227 g_value_set_boolean (value, priv->use_full_page);
229 case PROP_TRACK_PRINT_STATUS:
230 g_value_set_boolean (value, priv->track_print_status);
233 g_value_set_enum (value, priv->unit);
235 case PROP_SHOW_DIALOG:
236 g_value_set_boolean (value, priv->show_dialog);
238 case PROP_SHOW_PROGRESS:
239 g_value_set_boolean (value, priv->show_progress);
241 case PROP_PDF_TARGET:
242 g_value_set_string (value, priv->pdf_target);
245 g_value_set_enum (value, priv->status);
247 case PROP_STATUS_STRING:
248 g_value_set_string (value, priv->status_string);
250 case PROP_CUSTOM_TAB_LABEL:
251 g_value_set_string (value, priv->custom_tab_label);
254 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
260 gtk_print_operation_create_custom_widget (GtkPrintOperation *operation)
266 custom_widget_accumulator (GSignalInvocationHint *ihint,
268 const GValue *handler_return,
271 gboolean continue_emission;
274 widget = g_value_get_pointer (handler_return);
276 g_value_set_pointer (return_accu, widget);
277 continue_emission = (widget == NULL);
279 return continue_emission;
283 gtk_print_operation_class_init (GtkPrintOperationClass *class)
285 GObjectClass *gobject_class = (GObjectClass *)class;
287 gobject_class->set_property = gtk_print_operation_set_property;
288 gobject_class->get_property = gtk_print_operation_get_property;
289 gobject_class->finalize = gtk_print_operation_finalize;
291 class->create_custom_widget = gtk_print_operation_create_custom_widget;
293 g_type_class_add_private (gobject_class, sizeof (GtkPrintOperationPrivate));
296 * GtkPrintOperation::begin-print:
297 * @operation: the #GtkPrintOperation on which the signal was emitted
298 * @context: the #GtkPrintContext for the current operation
300 * Gets emitted after the user has finished changing print settings
301 * in the dialog, before the actual rendering starts.
303 * A typical use for this signal is to use the parameters from the
304 * #GtkPrintContext and paginate the document accordingly, and then
305 * set the number of pages with gtk_print_operation_set_n_pages().
309 signals[BEGIN_PRINT] =
310 g_signal_new (I_("begin-print"),
311 G_TYPE_FROM_CLASS (gobject_class),
313 G_STRUCT_OFFSET (GtkPrintOperationClass, begin_print),
315 g_cclosure_marshal_VOID__OBJECT,
316 G_TYPE_NONE, 1, GTK_TYPE_PRINT_CONTEXT);
319 * Gtkprintoperation::paginate:
320 * @operation: the #GtkPrintOperation on which the signal was emitted
321 * @context: the #GtkPrintContext for the current operation
323 * Gets emitted after the begin-print signal, but before the actual
324 * rendering starts. It keeps getting emitted until it returns %FALSE.
326 * This signal is intended to be used for paginating the document
327 * in small chunks, to avoid blocking the user interface for a long
328 * time. The signal handler should update the number of pages using
329 * gtk_print_operation_set_n_pages(), and return %TRUE if the document
330 * has been completely paginated.
332 * If you don't need to do pagination in chunks, you can simply do
333 * it all in the begin-print handler, and set the number of pages
339 g_signal_new (I_("paginate"),
340 G_TYPE_FROM_CLASS (gobject_class),
342 G_STRUCT_OFFSET (GtkPrintOperationClass, paginate),
343 _gtk_boolean_handled_accumulator, NULL,
344 _gtk_marshal_BOOLEAN__OBJECT,
345 G_TYPE_BOOLEAN, 1, GTK_TYPE_PRINT_CONTEXT);
349 * GtkPrintOperation::request-page-setup:
350 * @operation: the #GtkPrintOperation on which the signal was emitted
351 * @context: the #GtkPrintContext for the current operation
352 * @page_nr: the number of the currently printed page
353 * @setup: the #GtkPageSetup
355 * Gets emitted once for every page that is printed, to give
356 * the application a chance to modify the page setup. Any changes
357 * done to @setup will be in force only for printing this page.
361 signals[REQUEST_PAGE_SETUP] =
362 g_signal_new (I_("request-page-setup"),
363 G_TYPE_FROM_CLASS (gobject_class),
365 G_STRUCT_OFFSET (GtkPrintOperationClass, request_page_setup),
367 _gtk_marshal_VOID__OBJECT_INT_OBJECT,
369 GTK_TYPE_PRINT_CONTEXT,
371 GTK_TYPE_PAGE_SETUP);
374 * GtkPrintOperation::draw-page:
375 * @operation: the #GtkPrintOperation on which the signal was emitted
376 * @context: the #GtkPrintContext for the current operation
377 * @page_nr: the number of the currently printed page
379 * Gets emitted for every page that is printed. The signal handler
380 * must render the @page_nr's page onto the cairo context obtained
381 * from @context using gtk_print_context_get_cairo_context().
383 * <informalexample><programlisting>
385 * draw_page (GtkPrintOperation *operation,
386 * GtkPrintContext *context,
388 * gpointer user_data)
391 * PangoLayout *layout;
392 * gdouble width, text_height;
393 * gint layout_height;
394 * PangoFontDescription *desc;
396 * cr = gtk_print_context_get_cairo_context (context);
397 * width = gtk_print_context_get_width (context);
399 * cairo_rectangle (cr, 0, 0, width, HEADER_HEIGHT);
401 * cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
404 * layout = gtk_print_context_create_pango_layout (context);
406 * desc = pango_font_description_from_string ("sans 14");
407 * pango_layout_set_font_description (layout, desc);
408 * pango_font_description_free (desc);
410 * pango_layout_set_text (layout, "some text", -1);
411 * pango_layout_set_width (layout, width);
412 * pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
414 * pango_layout_get_size (layout, NULL, &layout_height);
415 * text_height = (gdouble)layout_height / PANGO_SCALE;
417 * cairo_move_to (cr, width / 2, (HEADER_HEIGHT - text_height) / 2);
418 * pango_cairo_show_layout (cr, layout);
420 * g_object_unref (layout);
422 * </programlisting></informalexample>
424 * Use gtk_print_operation_set_use_full_page() and
425 * gtk_print_operation_set_unit() before starting the print operation
426 * to set up the transformation of the cairo context according to your
432 g_signal_new (I_("draw-page"),
433 G_TYPE_FROM_CLASS (gobject_class),
435 G_STRUCT_OFFSET (GtkPrintOperationClass, draw_page),
437 _gtk_marshal_VOID__OBJECT_INT,
439 GTK_TYPE_PRINT_CONTEXT,
443 * GtkPrintOperation::end-print:
444 * @operation: the #GtkPrintOperation on which the signal was emitted
445 * @context: the #GtkPrintContext for the current operation
447 * Gets emitted after all pages have been rendered.
448 * A handler for this signal can clean up any resources that have
449 * been allocated in the ::begin-print handler.
454 g_signal_new (I_("end-print"),
455 G_TYPE_FROM_CLASS (gobject_class),
457 G_STRUCT_OFFSET (GtkPrintOperationClass, end_print),
459 g_cclosure_marshal_VOID__OBJECT,
460 G_TYPE_NONE, 1, GTK_TYPE_PRINT_CONTEXT);
463 * GtkPrintOperation::status-changed:
464 * @operation: the #GtkPrintOperation on which the signal was emitted
466 * Gets emitted at between the various phases of the print operation.
467 * See #GtkPrintStatus for the phases that are being discriminated.
468 * Use gtk_print_operation_get_status() to find out the current
473 signals[STATUS_CHANGED] =
474 g_signal_new (I_("status-changed"),
475 G_TYPE_FROM_CLASS (class),
477 G_STRUCT_OFFSET (GtkPrintOperationClass, status_changed),
479 g_cclosure_marshal_VOID__VOID,
484 * GtkPrintOperation::create-custom-widget:
485 * @operation: the #GtkPrintOperation on which the signal was emitted
487 * Gets emitted when displaying the print dialog. If you return a
488 * widget in a handler for this signal it will be added to a custom
489 * tab in the print dialog. You typically return a container widget
490 * with multiple widgets in it.
492 * The print dialog owns the returned widget, and its lifetime
493 * isn't controlled by the app. However, the widget is guaranteed
494 * to stay around until the custom-widget-apply signal is emitted
495 * on the operation. Then you can read out any information you need
498 * Returns: A custom widget that gets embedded in the print dialog,
503 signals[CREATE_CUSTOM_WIDGET] =
504 g_signal_new (I_("create-custom-widget"),
505 G_TYPE_FROM_CLASS (class),
507 G_STRUCT_OFFSET (GtkPrintOperationClass, create_custom_widget),
508 custom_widget_accumulator, NULL,
509 _gtk_marshal_POINTER__VOID,
513 * GtkPrintOperation::custom-widget-apply:
514 * @operation: the #GtkPrintOperation on which the signal was emitted
515 * @widget: the custom widget added in create-custom-widget
517 * This signal gets emitted right before begin-print if you added
518 * a custom widget in the create-custom-widget handler. When you get
519 * this signal you should read the information from the custom widgets,
520 * as the widgets are not guaraneed to be around at a later time.
524 signals[CUSTOM_WIDGET_APPLY] =
525 g_signal_new (I_("custom-widget-apply"),
526 G_TYPE_FROM_CLASS (class),
528 G_STRUCT_OFFSET (GtkPrintOperationClass, custom_widget_apply),
530 g_cclosure_marshal_VOID__OBJECT,
531 G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
534 * GtkPrintOperation:default-page-setup:
536 * The #GtkPageSetup used by default.
538 * This page setup will be used by gtk_print_operation_run(),
539 * but it can be overridden on a per-page basis by connecting
540 * to the ::request-page-setup signal.
544 g_object_class_install_property (gobject_class,
545 PROP_DEFAULT_PAGE_SETUP,
546 g_param_spec_object ("default-page-setup",
547 P_("Default Page Setup"),
548 P_("The GtkPageSetup used by default"),
550 GTK_PARAM_READWRITE));
553 * GtkPrintOperation:print-settings:
555 * The #GtkPrintSettings used for initializing the dialog.
557 * Setting this property is typically used to re-establish
558 * print settings from a previous print operation, see
559 * gtk_print_operation_run().
563 g_object_class_install_property (gobject_class,
565 g_param_spec_object ("print-settings",
566 P_("Print Settings"),
567 P_("The GtkPrintSettings used for initializing the dialog"),
568 GTK_TYPE_PRINT_SETTINGS,
569 GTK_PARAM_READWRITE));
572 * GtkPrintOperation:job-name:
574 * A string used to identify the job (e.g. in monitoring
575 * applications like eggcups).
577 * If you don't set a job name, GTK+ picks a default one
578 * by numbering successive print jobs.
582 g_object_class_install_property (gobject_class,
584 g_param_spec_string ("job-name",
586 P_("A string used for identifying the print job."),
588 GTK_PARAM_READWRITE));
591 * GtkPrintOperation:n-pages:
593 * The number of pages in the document.
595 * This <emphasis>must</emphasis> be set to a positive number
596 * before the rendering starts. It may be set in a ::begin-print
599 * Note that the page numbers passed to the ::request-page-setup
600 * and ::draw-page signals are 0-based, i.e. if the user chooses
601 * to print all pages, the last ::draw-page signal will be for
606 g_object_class_install_property (gobject_class,
608 g_param_spec_int ("n-pages",
609 P_("Number of Pages"),
610 P_("The number of pages in the document."),
614 GTK_PARAM_READWRITE));
617 * GtkPrintOperation:current-page:
619 * The current page in the document.
621 * If this is set before gtk_print_operation_run(),
622 * the user will be able to select to print only the current page.
624 * Note that this only makes sense for pre-paginated documents.
628 g_object_class_install_property (gobject_class,
630 g_param_spec_int ("current-page",
632 P_("The current page in the document."),
636 GTK_PARAM_READWRITE));
639 * GtkPrintOperation:use-full-page:
641 * If %TRUE, the transformation for the cairo context obtained
642 * from #GtkPrintContext puts the origin at the top left corner
643 * of the page (which may not be the top left corner of the sheet,
644 * depending on page orientation and the number of pages per sheet).
645 * Otherwise, the origin is at the top left corner of the imageable
646 * area (i.e. inside the margins).
650 g_object_class_install_property (gobject_class,
652 g_param_spec_boolean ("use-full-page",
654 P_("TRUE if the the origin of the context should be at the corner of the page and not the corner of the imageable area"),
656 GTK_PARAM_READWRITE));
660 * GtkPrintOperation:track-print-status:
662 * If %TRUE, the print operation will try to continue report on
663 * the status of the print job in the printer queues and printer.
664 * This can allow your application to show things like "out of paper"
665 * issues, and when the print job actually reaches the printer.
666 * However, this is often implemented using polling, and should
667 * not be enabled unless needed.
671 g_object_class_install_property (gobject_class,
673 g_param_spec_boolean ("track-print-status",
674 P_("Track Print Status"),
675 P_("TRUE if the print operation will continue to report on the print job status after the print data has been sent to the printer or print server."),
677 GTK_PARAM_READWRITE));
681 * GtkPrintOperation:unit:
683 * The transformation for the cairo context obtained from
684 * #GtkPrintContext is set up in such a way that distances
685 * are measured in units of @unit.
689 g_object_class_install_property (gobject_class,
691 g_param_spec_enum ("unit",
693 P_("The unit in which distances can be measured in the context"),
696 GTK_PARAM_READWRITE));
700 * GtkPrintOperation:show-dialog:
702 * Determines whether calling gtk_print_operation_run() will present
703 * a print dialog to the user, or just print to the default printer.
707 g_object_class_install_property (gobject_class,
709 g_param_spec_boolean ("show-dialog",
711 P_("TRUE if gtk_print_operation_run() should show the print dialog."),
713 GTK_PARAM_READWRITE));
717 * GtkPrintOperation:show-progress:
719 * Determines whether to show a progress dialog during the
724 g_object_class_install_property (gobject_class,
726 g_param_spec_boolean ("show-progress",
728 P_("TRUE if a progress dialog is shown while printing."),
730 GTK_PARAM_READWRITE));
734 * GtkPrintOperation:pdf-target:
736 * The name of a PDF file to generate instead of showing
739 * The intended use of this property is for implementing
740 * "Export to PDF" actions.
742 * "Print to PDF" support is independent of this and is done
743 * by letting the user pick the "Print to PDF" item from the
744 * list of printers in the print dialog.
748 g_object_class_install_property (gobject_class,
750 g_param_spec_string ("pdf-target",
751 P_("PDF target filename"),
752 P_("PDF target filename"),
754 GTK_PARAM_READWRITE));
757 * GtkPrintOperation:status:
759 * The status of the print operation.
763 g_object_class_install_property (gobject_class,
765 g_param_spec_enum ("status",
767 P_("The status of the print operation"),
768 GTK_TYPE_PRINT_STATUS,
769 GTK_PRINT_STATUS_INITIAL,
770 GTK_PARAM_READABLE));
773 * GtkPrintOperation:status-string:
775 * A string representation of the status of the print operation.
776 * The string is translated and suitable for displaying the print
777 * status e.g. in a #GtkStatusbar.
779 * See the ::status property for a status value that is suitable
780 * for programmatic use.
784 g_object_class_install_property (gobject_class,
786 g_param_spec_string ("status-string",
788 P_("A human-readable description of the status"),
790 GTK_PARAM_READABLE));
794 * GtkPrintOperation:custom-tab-label:
796 * Used as the label of the tab containing custom widgets.
797 * Note that this property may be ignored on some platforms.
799 * If this is %NULL, GTK+ uses a default label.
803 g_object_class_install_property (gobject_class,
804 PROP_CUSTOM_TAB_LABEL,
805 g_param_spec_string ("custom-tab-label",
806 P_("Custom tab label"),
807 P_("Label for the tab containing custom widgets."),
809 GTK_PARAM_READWRITE));
814 * gtk_print_operation_new:
816 * Creates a new #GtkPrintOperation.
818 * Returns: a new #GtkPrintOperation
823 gtk_print_operation_new (void)
825 GtkPrintOperation *print_operation;
827 print_operation = g_object_new (GTK_TYPE_PRINT_OPERATION, NULL);
829 return print_operation;
833 * gtk_print_operation_set_default_page_setup:
834 * @op: a #GtkPrintOperation
835 * @default_page_setup: a #GtkPageSetup, or %NULL
837 * Makes @default_page_setup the default page setup for @op.
839 * This page setup will be used by gtk_print_operation_run(),
840 * but it can be overridden on a per-page basis by connecting
841 * to the ::request-page-setup signal.
846 gtk_print_operation_set_default_page_setup (GtkPrintOperation *op,
847 GtkPageSetup *default_page_setup)
849 GtkPrintOperationPrivate *priv;
851 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
852 g_return_if_fail (default_page_setup == NULL ||
853 GTK_IS_PAGE_SETUP (default_page_setup));
857 if (default_page_setup != priv->default_page_setup)
859 if (default_page_setup)
860 g_object_ref (default_page_setup);
862 if (priv->default_page_setup)
863 g_object_unref (priv->default_page_setup);
865 priv->default_page_setup = default_page_setup;
867 g_object_notify (G_OBJECT (op), "default-page-setup");
872 * gtk_print_operation_get_default_page_setup:
873 * @op: a #GtkPrintOperation
875 * Returns the default page setup, see
876 * gtk_print_operation_set_default_page_setup().
878 * Returns: the default page setup
883 gtk_print_operation_get_default_page_setup (GtkPrintOperation *op)
885 g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op), NULL);
887 return op->priv->default_page_setup;
892 * gtk_print_operation_set_print_settings:
893 * @op: a #GtkPrintOperation
894 * @print_settings: #GtkPrintSettings, or %NULL
896 * Sets the print settings for @op. This is typically used to
897 * re-establish print settings from a previous print operation,
898 * see gtk_print_operation_run().
903 gtk_print_operation_set_print_settings (GtkPrintOperation *op,
904 GtkPrintSettings *print_settings)
906 GtkPrintOperationPrivate *priv;
908 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
909 g_return_if_fail (print_settings == NULL ||
910 GTK_IS_PRINT_SETTINGS (print_settings));
914 if (print_settings != priv->print_settings)
917 g_object_ref (print_settings);
919 if (priv->print_settings)
920 g_object_unref (priv->print_settings);
922 priv->print_settings = print_settings;
924 g_object_notify (G_OBJECT (op), "print-settings");
929 * gtk_print_operation_get_print_settings:
930 * @op: a #GtkPrintOperation
932 * Returns the current print settings.
934 * Note that the return value is %NULL until either
935 * gtk_print_operation_set_print_settings() or
936 * gtk_print_operation_run() have been called.
938 * Return value: the current print settings of @op.
943 gtk_print_operation_get_print_settings (GtkPrintOperation *op)
945 g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op), NULL);
947 return op->priv->print_settings;
951 * gtk_print_operation_set_job_name:
952 * @op: a #GtkPrintOperation
953 * @job_name: a string that identifies the print job
955 * Sets the name of the print job. The name is used to identify
956 * the job (e.g. in monitoring applications like eggcups).
958 * If you don't set a job name, GTK+ picks a default one by
959 * numbering successive print jobs.
964 gtk_print_operation_set_job_name (GtkPrintOperation *op,
965 const gchar *job_name)
967 GtkPrintOperationPrivate *priv;
969 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
970 g_return_if_fail (g_utf8_validate (job_name, -1, NULL));
974 g_free (priv->job_name);
975 priv->job_name = g_strdup (job_name);
977 g_object_notify (G_OBJECT (op), "job-name");
981 * gtk_print_operation_set_n_pages:
982 * @op: a #GtkPrintOperation
983 * @n_pages: the number of pages
985 * Sets the number of pages in the document.
987 * This <emphasis>must</emphasis> be set to a positive number
988 * before the rendering starts. It may be set in a ::begin-print
991 * Note that the page numbers passed to the ::request-page-setup
992 * and ::draw-page signals are 0-based, i.e. if the user chooses
993 * to print all pages, the last ::draw-page signal will be
994 * for page @n_pages - 1.
999 gtk_print_operation_set_n_pages (GtkPrintOperation *op,
1002 GtkPrintOperationPrivate *priv;
1004 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
1005 g_return_if_fail (n_pages > 0);
1008 g_return_if_fail (priv->current_page == -1 ||
1009 priv->current_page < n_pages);
1011 if (priv->nr_of_pages != n_pages)
1013 priv->nr_of_pages = n_pages;
1015 g_object_notify (G_OBJECT (op), "n-pages");
1020 * gtk_print_operation_set_current_page:
1021 * @op: a #GtkPrintOperation
1022 * @current_page: the current page, 0-based
1024 * Sets the current page.
1026 * If this is called before gtk_print_operation_run(),
1027 * the user will be able to select to print only the current page.
1029 * Note that this only makes sense for pre-paginated documents.
1034 gtk_print_operation_set_current_page (GtkPrintOperation *op,
1037 GtkPrintOperationPrivate *priv;
1039 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
1040 g_return_if_fail (current_page >= 0);
1043 g_return_if_fail (priv->nr_of_pages == -1 ||
1044 current_page < priv->nr_of_pages);
1046 if (priv->current_page != current_page)
1048 priv->current_page = current_page;
1050 g_object_notify (G_OBJECT (op), "current-page");
1055 * gtk_print_operation_set_use_full_page:
1056 * @op: a #GtkPrintOperation
1057 * @full_page: %TRUE to set up the #GtkPrintContext for the full page
1059 * If @full_page is %TRUE, the transformation for the cairo context
1060 * obtained from #GtkPrintContext puts the origin at the top left
1061 * corner of the page (which may not be the top left corner of the
1062 * sheet, depending on page orientation and the number of pages per
1063 * sheet). Otherwise, the origin is at the top left corner of the
1064 * imageable area (i.e. inside the margins).
1069 gtk_print_operation_set_use_full_page (GtkPrintOperation *op,
1072 GtkPrintOperationPrivate *priv;
1074 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
1076 full_page = full_page != FALSE;
1080 if (priv->use_full_page != full_page)
1082 priv->use_full_page = full_page;
1084 g_object_notify (G_OBJECT (op), "use-full-page");
1089 * gtk_print_operation_set_unit:
1090 * @op: a #GtkPrintOperation
1091 * @unit: the unit to use
1093 * Sets up the transformation for the cairo context obtained from
1094 * #GtkPrintContext in such a way that distances are measured in
1100 gtk_print_operation_set_unit (GtkPrintOperation *op,
1103 GtkPrintOperationPrivate *priv;
1105 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
1109 if (priv->unit != unit)
1113 g_object_notify (G_OBJECT (op), "unit");
1118 * gtk_print_operation_set_track_print_status:
1119 * @op: a #GtkPrintOperation
1120 * @track_status: %TRUE to track status after printing
1122 * If track_status is %TRUE, the print operation will try to continue report
1123 * on the status of the print job in the printer queues and printer. This
1124 * can allow your application to show things like "out of paper" issues,
1125 * and when the print job actually reaches the printer.
1127 * This function is often implemented using some form of polling, so it should
1128 * not be enabled unless needed.
1133 gtk_print_operation_set_track_print_status (GtkPrintOperation *op,
1134 gboolean track_status)
1136 GtkPrintOperationPrivate *priv;
1138 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
1142 if (priv->track_print_status != track_status)
1144 priv->track_print_status = track_status;
1146 g_object_notify (G_OBJECT (op), "track-print-status");
1151 _gtk_print_operation_set_status (GtkPrintOperation *op,
1152 GtkPrintStatus status,
1153 const gchar *string)
1155 GtkPrintOperationPrivate *priv = op->priv;
1156 static const gchar *status_strs[] = {
1157 /* translators, strip the prefix up to and including the first | */
1158 N_("print operation status|Initial state"),
1159 /* translators, strip the prefix up to and including the first | */
1160 N_("print operation status|Preparing to print"),
1161 /* translators, strip the prefix up to and including the first | */
1162 N_("print operation status|Generating data"),
1163 /* translators, strip the prefix up to and including the first | */
1164 N_("print operation status|Sending data"),
1165 /* translators, strip the prefix up to and including the first | */
1166 N_("print operation status|Waiting"),
1167 /* translators, strip the prefix up to and including the first | */
1168 N_("print operation status|Blocking on issue"),
1169 /* translators, strip the prefix up to and including the first | */
1170 N_("print operation status|Printing"),
1171 /* translators, strip the prefix up to and including the first | */
1172 N_("print operation status|Finished"),
1173 /* translators, strip the prefix up to and including the first | */
1174 N_("print operation status|Finished with error")
1177 if (status < 0 || status > GTK_PRINT_STATUS_FINISHED_ABORTED)
1178 status = GTK_PRINT_STATUS_FINISHED_ABORTED;
1181 string = g_strip_context (status_strs[status],
1182 gettext (status_strs[status]));
1184 if (priv->status == status &&
1185 strcmp (string, priv->status_string) == 0)
1188 g_free (priv->status_string);
1189 priv->status_string = g_strdup (string);
1190 priv->status = status;
1192 g_object_notify (G_OBJECT (op), "status");
1193 g_object_notify (G_OBJECT (op), "status-string");
1195 g_signal_emit (op, signals[STATUS_CHANGED], 0);
1200 * gtk_print_operation_get_status:
1201 * @op: a #GtkPrintOperation
1203 * Returns the status of the print operation.
1204 * Also see gtk_print_operation_get_status_string().
1206 * Return value: the status of the print operation
1211 gtk_print_operation_get_status (GtkPrintOperation *op)
1213 g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op),
1214 GTK_PRINT_STATUS_FINISHED_ABORTED);
1216 return op->priv->status;
1220 * gtk_print_operation_get_status_string:
1221 * @op: a #GtkPrintOperation
1223 * Returns a string representation of the status of the
1224 * print operation. The string is translated and suitable
1225 * for displaying the print status e.g. in a #GtkStatusbar.
1227 * Use gtk_print_operation_get_status() to obtain a status
1228 * value that is suitable for programmatic use.
1230 * Return value: a string representation of the status
1231 * of the print operation
1235 G_CONST_RETURN gchar *
1236 gtk_print_operation_get_status_string (GtkPrintOperation *op)
1238 g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op), "");
1240 return op->priv->status_string;
1244 * gtk_print_operation_is_finished:
1245 * @op: a #GtkPrintOperation
1247 * A convenience function to find out if the print operation
1248 * is finished, either successfully (%GTK_PRINT_STATUS_FINISHED)
1249 * or unsuccessfully (%GTK_PRINT_STATUS_FINISHED_ABORTED).
1251 * Return value: %TRUE, if the print operation is finished.
1256 gtk_print_operation_is_finished (GtkPrintOperation *op)
1258 GtkPrintOperationPrivate *priv;
1260 g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op), TRUE);
1264 priv->status == GTK_PRINT_STATUS_FINISHED_ABORTED ||
1265 priv->status == GTK_PRINT_STATUS_FINISHED;
1270 * gtk_print_operation_set_show_dialog:
1271 * @op: a #GtkPrintOperation
1272 * @show_dialog: %TRUE to show the print dialog
1274 * Sets whether calling gtk_print_operation_run() will present
1275 * a print dialog to the user, or just print to the default printer.
1280 gtk_print_operation_set_show_dialog (GtkPrintOperation *op,
1281 gboolean show_dialog)
1283 GtkPrintOperationPrivate *priv;
1285 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
1289 show_dialog = show_dialog != FALSE;
1291 if (priv->show_dialog != show_dialog)
1293 priv->show_dialog = show_dialog;
1295 g_object_notify (G_OBJECT (op), "show-dialog");
1301 * gtk_print_operation_set_show_progress:
1302 * @op: a #GtkPrintOperation
1303 * @show_progress: %TRUE to show a progress dialog
1305 * If @show_progress is %TRUE, the print operation will show a
1306 * progress dialog during the print operation.
1311 gtk_print_operation_set_show_progress (GtkPrintOperation *op,
1312 gboolean show_progress)
1314 GtkPrintOperationPrivate *priv;
1316 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
1320 show_progress = show_progress != FALSE;
1322 if (priv->show_progress != show_progress)
1324 priv->show_progress = show_progress;
1326 g_object_notify (G_OBJECT (op), "show-progress");
1331 * gtk_print_operation_set_custom_tag_label:
1332 * @op: a #GtkPrintOperation
1333 * @label: the label to use, or %NULL to use the default label
1335 * Sets the label for the tab holding custom widgets.
1340 gtk_print_operation_set_custom_tab_label (GtkPrintOperation *op,
1343 GtkPrintOperationPrivate *priv;
1345 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
1349 g_free (priv->custom_tab_label);
1350 priv->custom_tab_label = g_strdup (label);
1352 g_object_notify (G_OBJECT (op), "custom-tab-label");
1357 * gtk_print_operation_set_pdf_target:
1358 * @op: a #GtkPrintOperation
1359 * @filename: the filename for the PDF file
1361 * Sets up the #GtkPrintOperation to generate a PDF file instead
1362 * of showing the print dialog. The indended use of this function
1363 * is for implementing "Export to PDF" actions.
1365 * "Print to PDF" support is independent of this and is done
1366 * by letting the user pick the "Print to PDF" item from the list
1367 * of printers in the print dialog.
1372 gtk_print_operation_set_pdf_target (GtkPrintOperation *op,
1373 const gchar *filename)
1375 GtkPrintOperationPrivate *priv;
1377 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
1381 g_free (priv->pdf_target);
1382 priv->pdf_target = g_strdup (filename);
1384 g_object_notify (G_OBJECT (op), "pdf-target");
1387 /* Creates the initial page setup used for printing unless the
1388 * app overrides this on a per-page basis using request_page_setup.
1390 * Data is taken from, in order, if existing:
1392 * PrintSettings returned from the print dialog
1393 * (initial dialog values are set from default_page_setup
1394 * if unset in app specified print_settings)
1395 * default_page_setup
1396 * per-locale default setup
1398 static GtkPageSetup *
1399 create_page_setup (GtkPrintOperation *op)
1401 GtkPrintOperationPrivate *priv = op->priv;
1402 GtkPageSetup *page_setup;
1403 GtkPrintSettings *settings;
1405 if (priv->default_page_setup)
1406 page_setup = gtk_page_setup_copy (priv->default_page_setup);
1408 page_setup = gtk_page_setup_new ();
1410 settings = priv->print_settings;
1413 GtkPaperSize *paper_size;
1415 if (gtk_print_settings_has_key (settings, GTK_PRINT_SETTINGS_ORIENTATION))
1416 gtk_page_setup_set_orientation (page_setup,
1417 gtk_print_settings_get_orientation (settings));
1420 paper_size = gtk_print_settings_get_paper_size (settings);
1423 gtk_page_setup_set_paper_size (page_setup, paper_size);
1424 gtk_paper_size_free (paper_size);
1427 /* TODO: Margins? */
1434 pdf_start_page (GtkPrintOperation *op,
1435 GtkPrintContext *print_context,
1436 GtkPageSetup *page_setup)
1438 GtkPaperSize *paper_size;
1441 paper_size = gtk_page_setup_get_paper_size (page_setup);
1443 w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS);
1444 h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS);
1446 cairo_pdf_surface_set_size (op->priv->surface, w, h);
1450 pdf_end_page (GtkPrintOperation *op,
1451 GtkPrintContext *print_context)
1455 cr = gtk_print_context_get_cairo_context (print_context);
1456 cairo_show_page (cr);
1460 pdf_end_run (GtkPrintOperation *op,
1464 GtkPrintOperationPrivate *priv = op->priv;
1466 cairo_surface_destroy (priv->surface);
1467 priv->surface = NULL;
1470 static GtkPrintOperationResult
1471 run_pdf (GtkPrintOperation *op,
1476 GtkPrintOperationPrivate *priv = op->priv;
1477 GtkPageSetup *page_setup;
1478 double width, height;
1479 /* This will be overwritten later by the non-default size, but
1480 we need to pass some size: */
1482 page_setup = create_page_setup (op);
1483 width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
1484 height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
1485 g_object_unref (page_setup);
1487 priv->surface = cairo_pdf_surface_create (priv->pdf_target,
1489 cairo_pdf_surface_set_dpi (priv->surface, 300, 300);
1494 priv->print_pages = GTK_PRINT_PAGES_ALL;
1495 priv->page_ranges = NULL;
1496 priv->num_page_ranges = 0;
1498 priv->manual_num_copies = 1;
1499 priv->manual_collation = FALSE;
1500 priv->manual_reverse = FALSE;
1501 priv->manual_page_set = GTK_PAGE_SET_ALL;
1502 priv->manual_scale = 1.0;
1503 priv->manual_orientation = TRUE;
1507 priv->start_page = pdf_start_page;
1508 priv->end_page = pdf_end_page;
1509 priv->end_run = pdf_end_run;
1511 return GTK_PRINT_OPERATION_RESULT_APPLY;
1516 GtkPrintOperation *op;
1517 gint uncollated_copies;
1518 gint collated_copies;
1519 gint uncollated, collated, total;
1521 gint range, num_ranges;
1522 GtkPageRange *ranges;
1523 GtkPageRange one_range;
1525 gint page, start, end, inc;
1527 GtkPageSetup *initial_page_setup;
1528 GtkPrintContext *print_context;
1530 GtkWidget *progress;
1534 find_range (PrintPagesData *data)
1536 GtkPageRange *range;
1538 range = &data->ranges[data->range];
1542 data->start = range->end;
1543 data->end = range->start - 1;
1547 data->start = range->start;
1548 data->end = range->end + 1;
1553 increment_page_sequence (PrintPagesData *data)
1555 GtkPrintOperationPrivate *priv = data->op->priv;
1558 data->page += data->inc;
1559 if (data->page == data->end)
1561 data->range += data->inc;
1562 if (data->range == -1 || data->range == data->num_ranges)
1565 if (data->uncollated == data->uncollated_copies)
1568 data->range = data->inc < 0 ? data->num_ranges - 1 : 0;
1571 data->page = data->start;
1574 while ((priv->manual_page_set == GTK_PAGE_SET_EVEN && data->page % 2 == 0) ||
1575 (priv->manual_page_set == GTK_PAGE_SET_ODD && data->page % 2 == 1));
1581 print_pages_idle_done (gpointer user_data)
1583 PrintPagesData *data;
1584 GtkPrintOperationPrivate *priv;
1586 GDK_THREADS_ENTER ();
1588 data = (PrintPagesData*)user_data;
1589 priv = data->op->priv;
1591 priv->print_pages_idle_id = 0;
1593 if (priv->show_progress_timeout_id > 0)
1595 g_source_remove (priv->show_progress_timeout_id);
1596 priv->show_progress_timeout_id = 0;
1600 gtk_widget_destroy (data->progress);
1602 g_object_unref (data->print_context);
1603 g_object_unref (data->initial_page_setup);
1605 g_object_unref (data->op);
1608 g_main_loop_quit (priv->rloop);
1612 GDK_THREADS_LEAVE ();
1616 update_progress (PrintPagesData *data)
1618 GtkPrintOperationPrivate *priv;
1621 priv = data->op->priv;
1625 if (priv->status == GTK_PRINT_STATUS_PREPARING)
1627 if (priv->nr_of_pages > 0)
1628 text = g_strdup_printf (_("Preparing %d"), priv->nr_of_pages);
1630 text = g_strdup (_("Preparing"));
1632 else if (priv->status == GTK_PRINT_STATUS_GENERATING_DATA)
1633 text = g_strdup_printf (_("Printing %d"), data->total);
1637 g_object_set (data->progress, "text", text, NULL);
1644 print_pages_idle (gpointer user_data)
1646 PrintPagesData *data;
1647 GtkPrintOperationPrivate *priv;
1648 GtkPageSetup *page_setup;
1650 gboolean done = FALSE;
1652 GDK_THREADS_ENTER ();
1654 data = (PrintPagesData*)user_data;
1655 priv = data->op->priv;
1657 if (priv->status == GTK_PRINT_STATUS_PREPARING)
1659 if (!data->print_context)
1661 data->print_context = _gtk_print_context_new (data->op);
1662 data->initial_page_setup = create_page_setup (data->op);
1664 _gtk_print_context_set_page_setup (data->print_context,
1665 data->initial_page_setup);
1667 g_signal_emit (data->op, signals[BEGIN_PRINT], 0, data->print_context);
1669 if (priv->manual_collation)
1671 data->uncollated_copies = priv->manual_num_copies;
1672 data->collated_copies = 1;
1676 data->uncollated_copies = 1;
1677 data->collated_copies = priv->manual_num_copies;
1683 if (g_signal_has_handler_pending (data->op, signals[PAGINATE], 0, FALSE))
1685 gboolean paginated = FALSE;
1687 g_signal_emit (data->op, signals[PAGINATE], 0, data->print_context, &paginated);
1692 /* FIXME handle this better */
1693 if (priv->nr_of_pages == 0)
1694 g_warning ("no pages to print");
1696 /* Initialize parts of PrintPagesData that depend on nr_of_pages
1698 if (priv->print_pages == GTK_PRINT_PAGES_RANGES)
1700 data->ranges = priv->page_ranges;
1701 data->num_ranges = priv->num_page_ranges;
1703 else if (priv->print_pages == GTK_PRINT_PAGES_CURRENT &&
1704 priv->current_page != -1)
1706 data->ranges = &data->one_range;
1707 data->num_ranges = 1;
1708 data->ranges[0].start = priv->current_page;
1709 data->ranges[0].end = priv->current_page;
1713 data->ranges = &data->one_range;
1714 data->num_ranges = 1;
1715 data->ranges[0].start = 0;
1716 data->ranges[0].end = priv->nr_of_pages - 1;
1719 if (priv->manual_reverse)
1721 data->range = data->num_ranges - 1;
1731 /* go back one page, since we preincrement below */
1732 data->page = data->start - data->inc;
1733 data->collated = data->collated_copies - 1;
1735 _gtk_print_operation_set_status (data->op,
1736 GTK_PRINT_STATUS_GENERATING_DATA,
1744 if (data->collated == data->collated_copies)
1747 if (!increment_page_sequence (data))
1755 page_setup = gtk_page_setup_copy (data->initial_page_setup);
1756 g_signal_emit (data->op, signals[REQUEST_PAGE_SETUP], 0,
1757 data->print_context, data->page, page_setup);
1759 _gtk_print_context_set_page_setup (data->print_context, page_setup);
1760 priv->start_page (data->op, data->print_context, page_setup);
1762 cr = gtk_print_context_get_cairo_context (data->print_context);
1765 if (priv->manual_scale != 1.0)
1768 priv->manual_scale);
1770 if (priv->manual_orientation)
1771 _gtk_print_context_rotate_according_to_orientation (data->print_context);
1773 if (!priv->use_full_page)
1774 _gtk_print_context_translate_into_margin (data->print_context);
1776 g_signal_emit (data->op, signals[DRAW_PAGE], 0,
1777 data->print_context, data->page);
1779 priv->end_page (data->op, data->print_context);
1783 g_object_unref (page_setup);
1787 if (priv->cancelled)
1789 _gtk_print_operation_set_status (data->op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
1796 g_signal_emit (data->op, signals[END_PRINT], 0, data->print_context);
1798 cairo_surface_finish (priv->surface);
1799 priv->end_run (data->op, priv->is_sync, priv->cancelled);
1802 update_progress (data);
1804 GDK_THREADS_LEAVE ();
1810 handle_progress_response (GtkWidget *dialog,
1814 GtkPrintOperation *op = (GtkPrintOperation *)data;
1816 gtk_widget_hide (dialog);
1817 gtk_print_operation_cancel (op);
1821 show_progress_timeout (PrintPagesData *data)
1823 GDK_THREADS_ENTER ();
1825 gtk_window_present (GTK_WINDOW (data->progress));
1827 data->op->priv->show_progress_timeout_id = 0;
1829 GDK_THREADS_LEAVE ();
1835 print_pages (GtkPrintOperation *op,
1838 GtkPrintOperationPrivate *priv = op->priv;
1839 PrintPagesData *data;
1841 _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_PREPARING, NULL);
1843 data = g_new0 (PrintPagesData, 1);
1844 data->op = g_object_ref (op);
1846 if (priv->show_progress)
1848 GtkWidget *progress;
1850 progress = gtk_message_dialog_new (parent, 0,
1854 g_signal_connect (progress, "response",
1855 G_CALLBACK (handle_progress_response), op);
1857 priv->show_progress_timeout_id =
1858 g_timeout_add (SHOW_PROGRESS_TIME,
1859 (GSourceFunc)show_progress_timeout,
1862 data->progress = progress;
1865 priv->print_pages_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
1868 print_pages_idle_done);
1870 /* Recursive main loop to make sure we don't exit
1871 * on sync operations
1875 priv->rloop = g_main_loop_new (NULL, FALSE);
1877 GDK_THREADS_LEAVE ();
1878 g_main_loop_run (priv->rloop);
1879 GDK_THREADS_ENTER ();
1881 g_main_loop_unref (priv->rloop);
1886 * gtk_print_operation_run:
1887 * @op: a #GtkPrintOperation
1888 * @parent: Transient parent of the dialog, or %NULL
1889 * @error: Return location for errors, or %NULL
1891 * Runs the print operation, by first letting the user modify
1892 * print settings in the print dialog, and then print the
1895 * Note that this function does not return until the rendering of all
1896 * pages is complete. You can connect to the ::status-changed signal on
1897 * @op to obtain some information about the progress of the print operation.
1898 * Furthermore, it may use a recursive mainloop to show the print dialog.
1899 * See gtk_print_operation_run_async() if this is a problem.
1901 * <informalexample><programlisting>
1902 * if (settings != NULL)
1903 * gtk_print_operation_set_print_settings (print, settings);
1905 * if (page_setup != NULL)
1906 * gtk_print_operation_set_default_page_setup (print, page_setup);
1908 * g_signal_connect (print, "begin-print",
1909 * G_CALLBACK (begin_print), &data);
1910 * g_signal_connect (print, "draw-page",
1911 * G_CALLBACK (draw_page), &data);
1913 * res = gtk_print_operation_run (print, parent, &error);
1915 * if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
1917 * error_dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
1918 * GTK_DIALOG_DESTROY_WITH_PARENT,
1919 * GTK_MESSAGE_ERROR,
1920 * GTK_BUTTONS_CLOSE,
1921 * "Error printing file:\n%s",
1923 * g_signal_connect (error_dialog, "response",
1924 * G_CALLBACK (gtk_widget_destroy), NULL);
1925 * gtk_widget_show (error_dialog);
1926 * g_error_free (error);
1928 * else if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
1930 * if (settings != NULL)
1931 * g_object_unref (settings);
1932 * settings = g_object_ref (gtk_print_operation_get_print_settings (print));
1934 * </programlisting></informalexample>
1936 * Return value: the result of the print operation. A return value of
1937 * %GTK_PRINT_OPERATION_RESULT_APPLY indicates that the printing was
1938 * completed successfully. In this case, it is a good idea to obtain
1939 * the used print settings with gtk_print_operation_get_print_settings()
1940 * and store them for reuse with the next print operation.
1944 GtkPrintOperationResult
1945 gtk_print_operation_run (GtkPrintOperation *op,
1949 GtkPrintOperationPrivate *priv;
1950 GtkPrintOperationResult result;
1953 g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op),
1954 GTK_PRINT_OPERATION_RESULT_ERROR);
1957 priv->is_sync = TRUE;
1959 if (priv->pdf_target != NULL)
1960 result = run_pdf (op, parent, &do_print, error);
1962 result = _gtk_print_operation_platform_backend_run_dialog (op,
1967 print_pages (op, parent);
1969 _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
1975 * gtk_print_operation_run_async:
1976 * @op: a #GtkPrintOperation
1977 * @parent: Transient parent of the dialog, or %NULL
1979 * Runs the print operation, by first letting the user modify
1980 * print settings in the print dialog, and then print the
1983 * In contrast to gtk_print_operation_run(), this function returns after
1984 * showing the print dialog on platforms that support this, and handles
1985 * the printing by connecting a signal handler to the ::response signal
1988 * If you use this function, it is recommended that you store the modified
1989 * #GtkPrintSettings in a ::begin-print or ::end-print signal handler.
1994 gtk_print_operation_run_async (GtkPrintOperation *op,
1997 GtkPrintOperationPrivate *priv;
2000 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
2003 priv->is_sync = FALSE;
2005 if (priv->pdf_target != NULL)
2007 run_pdf (op, parent, &do_print, NULL);
2009 print_pages (op, parent);
2011 _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
2014 _gtk_print_operation_platform_backend_run_dialog_async (op,
2021 * gtk_print_operation_cancel:
2022 * @op: a #GtkPrintOperation
2024 * Cancels a running print operation. This function may
2025 * be called from a begin-print, paginate or draw-page
2026 * signal handler to stop the currently running print
2032 gtk_print_operation_cancel (GtkPrintOperation *op)
2034 g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
2036 op->priv->cancelled = TRUE;
2041 #define __GTK_PRINT_OPERATION_C__
2042 #include "gtkaliasdef.c"