1/* GTK - The GIMP Toolkit
2 * gtkprintoperation.h: Print Operation
3 * Copyright (C) 2006, Red Hat, Inc.
4 *
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.
9 *
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.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef __GTK_PRINT_OPERATION_H__
20#define __GTK_PRINT_OPERATION_H__
21
22
23#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
24#error "Only <gtk/gtk.h> can be included directly."
25#endif
26
27#include <cairo.h>
28#include <gtk/gtkmain.h>
29#include <gtk/gtkwindow.h>
30#include <gtk/gtkpagesetup.h>
31#include <gtk/gtkprintsettings.h>
32#include <gtk/gtkprintcontext.h>
33#include <gtk/gtkprintoperationpreview.h>
34
35
36G_BEGIN_DECLS
37
38#define GTK_TYPE_PRINT_OPERATION (gtk_print_operation_get_type ())
39#define GTK_PRINT_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PRINT_OPERATION, GtkPrintOperation))
40#define GTK_PRINT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PRINT_OPERATION, GtkPrintOperationClass))
41#define GTK_IS_PRINT_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PRINT_OPERATION))
42#define GTK_IS_PRINT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PRINT_OPERATION))
43#define GTK_PRINT_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PRINT_OPERATION, GtkPrintOperationClass))
44
45typedef struct _GtkPrintOperationClass GtkPrintOperationClass;
46typedef struct _GtkPrintOperationPrivate GtkPrintOperationPrivate;
47typedef struct _GtkPrintOperation GtkPrintOperation;
48
49/**
50 * GtkPrintStatus:
51 * @GTK_PRINT_STATUS_INITIAL: The printing has not started yet; this
52 * status is set initially, and while the print dialog is shown.
53 * @GTK_PRINT_STATUS_PREPARING: This status is set while the begin-print
54 * signal is emitted and during pagination.
55 * @GTK_PRINT_STATUS_GENERATING_DATA: This status is set while the
56 * pages are being rendered.
57 * @GTK_PRINT_STATUS_SENDING_DATA: The print job is being sent off to the
58 * printer.
59 * @GTK_PRINT_STATUS_PENDING: The print job has been sent to the printer,
60 * but is not printed for some reason, e.g. the printer may be stopped.
61 * @GTK_PRINT_STATUS_PENDING_ISSUE: Some problem has occurred during
62 * printing, e.g. a paper jam.
63 * @GTK_PRINT_STATUS_PRINTING: The printer is processing the print job.
64 * @GTK_PRINT_STATUS_FINISHED: The printing has been completed successfully.
65 * @GTK_PRINT_STATUS_FINISHED_ABORTED: The printing has been aborted.
66 *
67 * The status gives a rough indication of the completion of a running
68 * print operation.
69 */
70typedef enum {
71 GTK_PRINT_STATUS_INITIAL,
72 GTK_PRINT_STATUS_PREPARING,
73 GTK_PRINT_STATUS_GENERATING_DATA,
74 GTK_PRINT_STATUS_SENDING_DATA,
75 GTK_PRINT_STATUS_PENDING,
76 GTK_PRINT_STATUS_PENDING_ISSUE,
77 GTK_PRINT_STATUS_PRINTING,
78 GTK_PRINT_STATUS_FINISHED,
79 GTK_PRINT_STATUS_FINISHED_ABORTED
80} GtkPrintStatus;
81
82/**
83 * GtkPrintOperationResult:
84 * @GTK_PRINT_OPERATION_RESULT_ERROR: An error has occurred.
85 * @GTK_PRINT_OPERATION_RESULT_APPLY: The print settings should be stored.
86 * @GTK_PRINT_OPERATION_RESULT_CANCEL: The print operation has been canceled,
87 * the print settings should not be stored.
88 * @GTK_PRINT_OPERATION_RESULT_IN_PROGRESS: The print operation is not complete
89 * yet. This value will only be returned when running asynchronously.
90 *
91 * The result of a print operation.
92 *
93 * A value of this type is returned by [method@Gtk.PrintOperation.run].
94 */
95typedef enum {
96 GTK_PRINT_OPERATION_RESULT_ERROR,
97 GTK_PRINT_OPERATION_RESULT_APPLY,
98 GTK_PRINT_OPERATION_RESULT_CANCEL,
99 GTK_PRINT_OPERATION_RESULT_IN_PROGRESS
100} GtkPrintOperationResult;
101
102/**
103 * GtkPrintOperationAction:
104 * @GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG: Show the print dialog.
105 * @GTK_PRINT_OPERATION_ACTION_PRINT: Start to print without showing
106 * the print dialog, based on the current print settings.
107 * @GTK_PRINT_OPERATION_ACTION_PREVIEW: Show the print preview.
108 * @GTK_PRINT_OPERATION_ACTION_EXPORT: Export to a file. This requires
109 * the export-filename property to be set.
110 *
111 * Determines what action the print operation should perform.
112 *
113 * A parameter of this typs is passed to [method@Gtk.PrintOperation.run].
114 */
115typedef enum {
116 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
117 GTK_PRINT_OPERATION_ACTION_PRINT,
118 GTK_PRINT_OPERATION_ACTION_PREVIEW,
119 GTK_PRINT_OPERATION_ACTION_EXPORT
120} GtkPrintOperationAction;
121
122
123struct _GtkPrintOperation
124{
125 GObject parent_instance;
126
127 /*< private >*/
128 GtkPrintOperationPrivate *priv;
129};
130
131/**
132 * GtkPrintOperationClass:
133 * @parent_class: The parent class.
134 * @done: Signal emitted when the print operation run has finished
135 * doing everything required for printing.
136 * @begin_print: Signal emitted after the user has finished changing
137 * print settings in the dialog, before the actual rendering starts.
138 * @paginate: Signal emitted after the “begin-print” signal, but
139 * before the actual rendering starts.
140 * @request_page_setup: Emitted once for every page that is printed,
141 * to give the application a chance to modify the page setup.
142 * @draw_page: Signal emitted for every page that is printed.
143 * @end_print: Signal emitted after all pages have been rendered.
144 * @status_changed: Emitted at between the various phases of the print
145 * operation.
146 * @create_custom_widget: Signal emitted when displaying the print dialog.
147 * @custom_widget_apply: Signal emitted right before “begin-print” if
148 * you added a custom widget in the “create-custom-widget” handler.
149 * @preview: Signal emitted when a preview is requested from the
150 * native dialog.
151 * @update_custom_widget: Emitted after change of selected printer.
152 */
153struct _GtkPrintOperationClass
154{
155 GObjectClass parent_class;
156
157 /*< public >*/
158
159 void (*done) (GtkPrintOperation *operation,
160 GtkPrintOperationResult result);
161 void (*begin_print) (GtkPrintOperation *operation,
162 GtkPrintContext *context);
163 gboolean (*paginate) (GtkPrintOperation *operation,
164 GtkPrintContext *context);
165 void (*request_page_setup) (GtkPrintOperation *operation,
166 GtkPrintContext *context,
167 int page_nr,
168 GtkPageSetup *setup);
169 void (*draw_page) (GtkPrintOperation *operation,
170 GtkPrintContext *context,
171 int page_nr);
172 void (*end_print) (GtkPrintOperation *operation,
173 GtkPrintContext *context);
174 void (*status_changed) (GtkPrintOperation *operation);
175
176 GtkWidget *(*create_custom_widget) (GtkPrintOperation *operation);
177 void (*custom_widget_apply) (GtkPrintOperation *operation,
178 GtkWidget *widget);
179
180 gboolean (*preview) (GtkPrintOperation *operation,
181 GtkPrintOperationPreview *preview,
182 GtkPrintContext *context,
183 GtkWindow *parent);
184
185 void (*update_custom_widget) (GtkPrintOperation *operation,
186 GtkWidget *widget,
187 GtkPageSetup *setup,
188 GtkPrintSettings *settings);
189
190 /*< private >*/
191
192 gpointer padding[8];
193};
194
195/**
196 * GTK_PRINT_ERROR:
197 *
198 * The error domain for `GtkPrintError` errors.
199 */
200#define GTK_PRINT_ERROR gtk_print_error_quark ()
201
202/**
203 * GtkPrintError:
204 * @GTK_PRINT_ERROR_GENERAL: An unspecified error occurred.
205 * @GTK_PRINT_ERROR_INTERNAL_ERROR: An internal error occurred.
206 * @GTK_PRINT_ERROR_NOMEM: A memory allocation failed.
207 * @GTK_PRINT_ERROR_INVALID_FILE: An error occurred while loading a page setup
208 * or paper size from a key file.
209 *
210 * Error codes that identify various errors that can occur while
211 * using the GTK printing support.
212 */
213typedef enum
214{
215 GTK_PRINT_ERROR_GENERAL,
216 GTK_PRINT_ERROR_INTERNAL_ERROR,
217 GTK_PRINT_ERROR_NOMEM,
218 GTK_PRINT_ERROR_INVALID_FILE
219} GtkPrintError;
220
221GDK_AVAILABLE_IN_ALL
222GQuark gtk_print_error_quark (void);
223
224GDK_AVAILABLE_IN_ALL
225GType gtk_print_operation_get_type (void) G_GNUC_CONST;
226GDK_AVAILABLE_IN_ALL
227GtkPrintOperation * gtk_print_operation_new (void);
228GDK_AVAILABLE_IN_ALL
229void gtk_print_operation_set_default_page_setup (GtkPrintOperation *op,
230 GtkPageSetup *default_page_setup);
231GDK_AVAILABLE_IN_ALL
232GtkPageSetup * gtk_print_operation_get_default_page_setup (GtkPrintOperation *op);
233GDK_AVAILABLE_IN_ALL
234void gtk_print_operation_set_print_settings (GtkPrintOperation *op,
235 GtkPrintSettings *print_settings);
236GDK_AVAILABLE_IN_ALL
237GtkPrintSettings * gtk_print_operation_get_print_settings (GtkPrintOperation *op);
238GDK_AVAILABLE_IN_ALL
239void gtk_print_operation_set_job_name (GtkPrintOperation *op,
240 const char *job_name);
241GDK_AVAILABLE_IN_ALL
242void gtk_print_operation_set_n_pages (GtkPrintOperation *op,
243 int n_pages);
244GDK_AVAILABLE_IN_ALL
245void gtk_print_operation_set_current_page (GtkPrintOperation *op,
246 int current_page);
247GDK_AVAILABLE_IN_ALL
248void gtk_print_operation_set_use_full_page (GtkPrintOperation *op,
249 gboolean full_page);
250GDK_AVAILABLE_IN_ALL
251void gtk_print_operation_set_unit (GtkPrintOperation *op,
252 GtkUnit unit);
253GDK_AVAILABLE_IN_ALL
254void gtk_print_operation_set_export_filename (GtkPrintOperation *op,
255 const char *filename);
256GDK_AVAILABLE_IN_ALL
257void gtk_print_operation_set_track_print_status (GtkPrintOperation *op,
258 gboolean track_status);
259GDK_AVAILABLE_IN_ALL
260void gtk_print_operation_set_show_progress (GtkPrintOperation *op,
261 gboolean show_progress);
262GDK_AVAILABLE_IN_ALL
263void gtk_print_operation_set_allow_async (GtkPrintOperation *op,
264 gboolean allow_async);
265GDK_AVAILABLE_IN_ALL
266void gtk_print_operation_set_custom_tab_label (GtkPrintOperation *op,
267 const char *label);
268GDK_AVAILABLE_IN_ALL
269GtkPrintOperationResult gtk_print_operation_run (GtkPrintOperation *op,
270 GtkPrintOperationAction action,
271 GtkWindow *parent,
272 GError **error);
273GDK_AVAILABLE_IN_ALL
274void gtk_print_operation_get_error (GtkPrintOperation *op,
275 GError **error);
276GDK_AVAILABLE_IN_ALL
277GtkPrintStatus gtk_print_operation_get_status (GtkPrintOperation *op);
278GDK_AVAILABLE_IN_ALL
279const char * gtk_print_operation_get_status_string (GtkPrintOperation *op);
280GDK_AVAILABLE_IN_ALL
281gboolean gtk_print_operation_is_finished (GtkPrintOperation *op);
282GDK_AVAILABLE_IN_ALL
283void gtk_print_operation_cancel (GtkPrintOperation *op);
284GDK_AVAILABLE_IN_ALL
285void gtk_print_operation_draw_page_finish (GtkPrintOperation *op);
286GDK_AVAILABLE_IN_ALL
287void gtk_print_operation_set_defer_drawing (GtkPrintOperation *op);
288GDK_AVAILABLE_IN_ALL
289void gtk_print_operation_set_support_selection (GtkPrintOperation *op,
290 gboolean support_selection);
291GDK_AVAILABLE_IN_ALL
292gboolean gtk_print_operation_get_support_selection (GtkPrintOperation *op);
293GDK_AVAILABLE_IN_ALL
294void gtk_print_operation_set_has_selection (GtkPrintOperation *op,
295 gboolean has_selection);
296GDK_AVAILABLE_IN_ALL
297gboolean gtk_print_operation_get_has_selection (GtkPrintOperation *op);
298GDK_AVAILABLE_IN_ALL
299void gtk_print_operation_set_embed_page_setup (GtkPrintOperation *op,
300 gboolean embed);
301GDK_AVAILABLE_IN_ALL
302gboolean gtk_print_operation_get_embed_page_setup (GtkPrintOperation *op);
303GDK_AVAILABLE_IN_ALL
304int gtk_print_operation_get_n_pages_to_print (GtkPrintOperation *op);
305
306GDK_AVAILABLE_IN_ALL
307GtkPageSetup *gtk_print_run_page_setup_dialog (GtkWindow *parent,
308 GtkPageSetup *page_setup,
309 GtkPrintSettings *settings);
310
311/**
312 * GtkPageSetupDoneFunc:
313 * @page_setup: the `GtkPageSetup` that has been passed to
314 * gtk_print_run_page_setup_dialog_async()
315 * @data: (closure): user data that has been passed to
316 * gtk_print_run_page_setup_dialog_async()
317 *
318 * The type of function that is passed to
319 * gtk_print_run_page_setup_dialog_async().
320 *
321 * This function will be called when the page setup dialog
322 * is dismissed, and also serves as destroy notify for @data.
323 */
324typedef void (* GtkPageSetupDoneFunc) (GtkPageSetup *page_setup,
325 gpointer data);
326
327GDK_AVAILABLE_IN_ALL
328void gtk_print_run_page_setup_dialog_async (GtkWindow *parent,
329 GtkPageSetup *page_setup,
330 GtkPrintSettings *settings,
331 GtkPageSetupDoneFunc done_cb,
332 gpointer data);
333
334G_END_DECLS
335
336#endif /* __GTK_PRINT_OPERATION_H__ */
337

source code of gtk/gtk/gtkprintoperation.h