1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD 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
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.PrintOperation;
26 
27 private import glib.ConstructionException;
28 private import glib.ErrorG;
29 private import glib.GException;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gobject.Signals;
33 private import gtk.PageSetup;
34 private import gtk.PrintContext;
35 private import gtk.PrintOperationPreviewIF;
36 private import gtk.PrintOperationPreviewT;
37 private import gtk.PrintSettings;
38 private import gtk.Widget;
39 private import gtk.Window;
40 private import gtk.c.functions;
41 public  import gtk.c.types;
42 public  import gtkc.gtktypes;
43 private import std.algorithm;
44 
45 
46 /**
47  * GtkPrintOperation is the high-level, portable printing API.
48  * It looks a bit different than other GTK+ dialogs such as the
49  * #GtkFileChooser, since some platforms don’t expose enough
50  * infrastructure to implement a good print dialog. On such
51  * platforms, GtkPrintOperation uses the native print dialog.
52  * On platforms which do not provide a native print dialog, GTK+
53  * uses its own, see #GtkPrintUnixDialog.
54  * 
55  * The typical way to use the high-level printing API is to create
56  * a GtkPrintOperation object with gtk_print_operation_new() when
57  * the user selects to print. Then you set some properties on it,
58  * e.g. the page size, any #GtkPrintSettings from previous print
59  * operations, the number of pages, the current page, etc.
60  * 
61  * Then you start the print operation by calling gtk_print_operation_run().
62  * It will then show a dialog, let the user select a printer and
63  * options. When the user finished the dialog various signals will
64  * be emitted on the #GtkPrintOperation, the main one being
65  * #GtkPrintOperation::draw-page, which you are supposed to catch
66  * and render the page on the provided #GtkPrintContext using Cairo.
67  * 
68  * # The high-level printing API
69  * 
70  * |[<!-- language="C" -->
71  * static GtkPrintSettings *settings = NULL;
72  * 
73  * static void
74  * do_print (void)
75  * {
76  * GtkPrintOperation *print;
77  * GtkPrintOperationResult res;
78  * 
79  * print = gtk_print_operation_new ();
80  * 
81  * if (settings != NULL)
82  * gtk_print_operation_set_print_settings (print, settings);
83  * 
84  * g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), NULL);
85  * g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL);
86  * 
87  * res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
88  * GTK_WINDOW (main_window), NULL);
89  * 
90  * if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
91  * {
92  * if (settings != NULL)
93  * g_object_unref (settings);
94  * settings = g_object_ref (gtk_print_operation_get_print_settings (print));
95  * }
96  * 
97  * g_object_unref (print);
98  * }
99  * ]|
100  * 
101  * By default GtkPrintOperation uses an external application to do
102  * print preview. To implement a custom print preview, an application
103  * must connect to the preview signal. The functions
104  * gtk_print_operation_preview_render_page(),
105  * gtk_print_operation_preview_end_preview() and
106  * gtk_print_operation_preview_is_selected()
107  * are useful when implementing a print preview.
108  */
109 public class PrintOperation : ObjectG, PrintOperationPreviewIF
110 {
111 	/** the main Gtk struct */
112 	protected GtkPrintOperation* gtkPrintOperation;
113 
114 	/** Get the main Gtk struct */
115 	public GtkPrintOperation* getPrintOperationStruct(bool transferOwnership = false)
116 	{
117 		if (transferOwnership)
118 			ownedRef = false;
119 		return gtkPrintOperation;
120 	}
121 
122 	/** the main Gtk struct as a void* */
123 	protected override void* getStruct()
124 	{
125 		return cast(void*)gtkPrintOperation;
126 	}
127 
128 	protected override void setStruct(GObject* obj)
129 	{
130 		gtkPrintOperation = cast(GtkPrintOperation*)obj;
131 		super.setStruct(obj);
132 	}
133 
134 	/**
135 	 * Sets our main struct and passes it to the parent class.
136 	 */
137 	public this (GtkPrintOperation* gtkPrintOperation, bool ownedRef = false)
138 	{
139 		this.gtkPrintOperation = gtkPrintOperation;
140 		super(cast(GObject*)gtkPrintOperation, ownedRef);
141 	}
142 
143 	// add the PrintOperationPreview capabilities
144 	mixin PrintOperationPreviewT!(GtkPrintOperation);
145 
146 
147 	/** */
148 	public static GType getType()
149 	{
150 		return gtk_print_operation_get_type();
151 	}
152 
153 	/**
154 	 * Creates a new #GtkPrintOperation.
155 	 *
156 	 * Returns: a new #GtkPrintOperation
157 	 *
158 	 * Since: 2.10
159 	 *
160 	 * Throws: ConstructionException GTK+ fails to create the object.
161 	 */
162 	public this()
163 	{
164 		auto p = gtk_print_operation_new();
165 
166 		if(p is null)
167 		{
168 			throw new ConstructionException("null returned by new");
169 		}
170 
171 		this(cast(GtkPrintOperation*) p, true);
172 	}
173 
174 	/**
175 	 * Cancels a running print operation. This function may
176 	 * be called from a #GtkPrintOperation::begin-print,
177 	 * #GtkPrintOperation::paginate or #GtkPrintOperation::draw-page
178 	 * signal handler to stop the currently running print
179 	 * operation.
180 	 *
181 	 * Since: 2.10
182 	 */
183 	public void cancel()
184 	{
185 		gtk_print_operation_cancel(gtkPrintOperation);
186 	}
187 
188 	/**
189 	 * Signalize that drawing of particular page is complete.
190 	 *
191 	 * It is called after completion of page drawing (e.g. drawing in another
192 	 * thread).
193 	 * If gtk_print_operation_set_defer_drawing() was called before, then this function
194 	 * has to be called by application. In another case it is called by the library
195 	 * itself.
196 	 *
197 	 * Since: 2.16
198 	 */
199 	public void drawPageFinish()
200 	{
201 		gtk_print_operation_draw_page_finish(gtkPrintOperation);
202 	}
203 
204 	/**
205 	 * Returns the default page setup, see
206 	 * gtk_print_operation_set_default_page_setup().
207 	 *
208 	 * Returns: the default page setup
209 	 *
210 	 * Since: 2.10
211 	 */
212 	public PageSetup getDefaultPageSetup()
213 	{
214 		auto p = gtk_print_operation_get_default_page_setup(gtkPrintOperation);
215 
216 		if(p is null)
217 		{
218 			return null;
219 		}
220 
221 		return ObjectG.getDObject!(PageSetup)(cast(GtkPageSetup*) p);
222 	}
223 
224 	/**
225 	 * Gets the value of #GtkPrintOperation:embed-page-setup property.
226 	 *
227 	 * Returns: whether page setup selection combos are embedded
228 	 *
229 	 * Since: 2.18
230 	 */
231 	public bool getEmbedPageSetup()
232 	{
233 		return gtk_print_operation_get_embed_page_setup(gtkPrintOperation) != 0;
234 	}
235 
236 	/**
237 	 * Call this when the result of a print operation is
238 	 * %GTK_PRINT_OPERATION_RESULT_ERROR, either as returned by
239 	 * gtk_print_operation_run(), or in the #GtkPrintOperation::done signal
240 	 * handler. The returned #GError will contain more details on what went wrong.
241 	 *
242 	 * Since: 2.10
243 	 *
244 	 * Throws: GException on failure.
245 	 */
246 	public void getError()
247 	{
248 		GError* err = null;
249 
250 		gtk_print_operation_get_error(gtkPrintOperation, &err);
251 
252 		if (err !is null)
253 		{
254 			throw new GException( new ErrorG(err) );
255 		}
256 	}
257 
258 	/**
259 	 * Gets the value of #GtkPrintOperation:has-selection property.
260 	 *
261 	 * Returns: whether there is a selection
262 	 *
263 	 * Since: 2.18
264 	 */
265 	public bool getHasSelection()
266 	{
267 		return gtk_print_operation_get_has_selection(gtkPrintOperation) != 0;
268 	}
269 
270 	/**
271 	 * Returns the number of pages that will be printed.
272 	 *
273 	 * Note that this value is set during print preparation phase
274 	 * (%GTK_PRINT_STATUS_PREPARING), so this function should never be
275 	 * called before the data generation phase (%GTK_PRINT_STATUS_GENERATING_DATA).
276 	 * You can connect to the #GtkPrintOperation::status-changed signal
277 	 * and call gtk_print_operation_get_n_pages_to_print() when
278 	 * print status is %GTK_PRINT_STATUS_GENERATING_DATA.
279 	 * This is typically used to track the progress of print operation.
280 	 *
281 	 * Returns: the number of pages that will be printed
282 	 *
283 	 * Since: 2.18
284 	 */
285 	public int getNPagesToPrint()
286 	{
287 		return gtk_print_operation_get_n_pages_to_print(gtkPrintOperation);
288 	}
289 
290 	/**
291 	 * Returns the current print settings.
292 	 *
293 	 * Note that the return value is %NULL until either
294 	 * gtk_print_operation_set_print_settings() or
295 	 * gtk_print_operation_run() have been called.
296 	 *
297 	 * Returns: the current print settings of @op.
298 	 *
299 	 * Since: 2.10
300 	 */
301 	public PrintSettings getPrintSettings()
302 	{
303 		auto p = gtk_print_operation_get_print_settings(gtkPrintOperation);
304 
305 		if(p is null)
306 		{
307 			return null;
308 		}
309 
310 		return ObjectG.getDObject!(PrintSettings)(cast(GtkPrintSettings*) p);
311 	}
312 
313 	/**
314 	 * Returns the status of the print operation.
315 	 * Also see gtk_print_operation_get_status_string().
316 	 *
317 	 * Returns: the status of the print operation
318 	 *
319 	 * Since: 2.10
320 	 */
321 	public GtkPrintStatus getStatus()
322 	{
323 		return gtk_print_operation_get_status(gtkPrintOperation);
324 	}
325 
326 	/**
327 	 * Returns a string representation of the status of the
328 	 * print operation. The string is translated and suitable
329 	 * for displaying the print status e.g. in a #GtkStatusbar.
330 	 *
331 	 * Use gtk_print_operation_get_status() to obtain a status
332 	 * value that is suitable for programmatic use.
333 	 *
334 	 * Returns: a string representation of the status
335 	 *     of the print operation
336 	 *
337 	 * Since: 2.10
338 	 */
339 	public string getStatusString()
340 	{
341 		return Str.toString(gtk_print_operation_get_status_string(gtkPrintOperation));
342 	}
343 
344 	/**
345 	 * Gets the value of #GtkPrintOperation:support-selection property.
346 	 *
347 	 * Returns: whether the application supports print of selection
348 	 *
349 	 * Since: 2.18
350 	 */
351 	public bool getSupportSelection()
352 	{
353 		return gtk_print_operation_get_support_selection(gtkPrintOperation) != 0;
354 	}
355 
356 	/**
357 	 * A convenience function to find out if the print operation
358 	 * is finished, either successfully (%GTK_PRINT_STATUS_FINISHED)
359 	 * or unsuccessfully (%GTK_PRINT_STATUS_FINISHED_ABORTED).
360 	 *
361 	 * Note: when you enable print status tracking the print operation
362 	 * can be in a non-finished state even after done has been called, as
363 	 * the operation status then tracks the print job status on the printer.
364 	 *
365 	 * Returns: %TRUE, if the print operation is finished.
366 	 *
367 	 * Since: 2.10
368 	 */
369 	public bool isFinished()
370 	{
371 		return gtk_print_operation_is_finished(gtkPrintOperation) != 0;
372 	}
373 
374 	/**
375 	 * Runs the print operation, by first letting the user modify
376 	 * print settings in the print dialog, and then print the document.
377 	 *
378 	 * Normally that this function does not return until the rendering of all
379 	 * pages is complete. You can connect to the
380 	 * #GtkPrintOperation::status-changed signal on @op to obtain some
381 	 * information about the progress of the print operation.
382 	 * Furthermore, it may use a recursive mainloop to show the print dialog.
383 	 *
384 	 * If you call gtk_print_operation_set_allow_async() or set the
385 	 * #GtkPrintOperation:allow-async property the operation will run
386 	 * asynchronously if this is supported on the platform. The
387 	 * #GtkPrintOperation::done signal will be emitted with the result of the
388 	 * operation when the it is done (i.e. when the dialog is canceled, or when
389 	 * the print succeeds or fails).
390 	 * |[<!-- language="C" -->
391 	 * if (settings != NULL)
392 	 * gtk_print_operation_set_print_settings (print, settings);
393 	 *
394 	 * if (page_setup != NULL)
395 	 * gtk_print_operation_set_default_page_setup (print, page_setup);
396 	 *
397 	 * g_signal_connect (print, "begin-print",
398 	 * G_CALLBACK (begin_print), &data);
399 	 * g_signal_connect (print, "draw-page",
400 	 * G_CALLBACK (draw_page), &data);
401 	 *
402 	 * res = gtk_print_operation_run (print,
403 	 * GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
404 	 * parent,
405 	 * &error);
406 	 *
407 	 * if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
408 	 * {
409 	 * error_dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
410 	 * GTK_DIALOG_DESTROY_WITH_PARENT,
411 	 * GTK_MESSAGE_ERROR,
412 	 * GTK_BUTTONS_CLOSE,
413 	 * "Error printing file:\n%s",
414 	 * error->message);
415 	 * g_signal_connect (error_dialog, "response",
416 	 * G_CALLBACK (gtk_widget_destroy), NULL);
417 	 * gtk_widget_show (error_dialog);
418 	 * g_error_free (error);
419 	 * }
420 	 * else if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
421 	 * {
422 	 * if (settings != NULL)
423 	 * g_object_unref (settings);
424 	 * settings = g_object_ref (gtk_print_operation_get_print_settings (print));
425 	 * }
426 	 * ]|
427 	 *
428 	 * Note that gtk_print_operation_run() can only be called once on a
429 	 * given #GtkPrintOperation.
430 	 *
431 	 * Params:
432 	 *     action = the action to start
433 	 *     parent = Transient parent of the dialog
434 	 *
435 	 * Returns: the result of the print operation. A return value of
436 	 *     %GTK_PRINT_OPERATION_RESULT_APPLY indicates that the printing was
437 	 *     completed successfully. In this case, it is a good idea to obtain
438 	 *     the used print settings with gtk_print_operation_get_print_settings()
439 	 *     and store them for reuse with the next print operation. A value of
440 	 *     %GTK_PRINT_OPERATION_RESULT_IN_PROGRESS means the operation is running
441 	 *     asynchronously, and will emit the #GtkPrintOperation::done signal when
442 	 *     done.
443 	 *
444 	 * Since: 2.10
445 	 *
446 	 * Throws: GException on failure.
447 	 */
448 	public GtkPrintOperationResult run(GtkPrintOperationAction action, Window parent)
449 	{
450 		GError* err = null;
451 
452 		auto p = gtk_print_operation_run(gtkPrintOperation, action, (parent is null) ? null : parent.getWindowStruct(), &err);
453 
454 		if (err !is null)
455 		{
456 			throw new GException( new ErrorG(err) );
457 		}
458 
459 		return p;
460 	}
461 
462 	/**
463 	 * Sets whether the gtk_print_operation_run() may return
464 	 * before the print operation is completed. Note that
465 	 * some platforms may not allow asynchronous operation.
466 	 *
467 	 * Params:
468 	 *     allowAsync = %TRUE to allow asynchronous operation
469 	 *
470 	 * Since: 2.10
471 	 */
472 	public void setAllowAsync(bool allowAsync)
473 	{
474 		gtk_print_operation_set_allow_async(gtkPrintOperation, allowAsync);
475 	}
476 
477 	/**
478 	 * Sets the current page.
479 	 *
480 	 * If this is called before gtk_print_operation_run(),
481 	 * the user will be able to select to print only the current page.
482 	 *
483 	 * Note that this only makes sense for pre-paginated documents.
484 	 *
485 	 * Params:
486 	 *     currentPage = the current page, 0-based
487 	 *
488 	 * Since: 2.10
489 	 */
490 	public void setCurrentPage(int currentPage)
491 	{
492 		gtk_print_operation_set_current_page(gtkPrintOperation, currentPage);
493 	}
494 
495 	/**
496 	 * Sets the label for the tab holding custom widgets.
497 	 *
498 	 * Params:
499 	 *     label = the label to use, or %NULL to use the default label
500 	 *
501 	 * Since: 2.10
502 	 */
503 	public void setCustomTabLabel(string label)
504 	{
505 		gtk_print_operation_set_custom_tab_label(gtkPrintOperation, Str.toStringz(label));
506 	}
507 
508 	/**
509 	 * Makes @default_page_setup the default page setup for @op.
510 	 *
511 	 * This page setup will be used by gtk_print_operation_run(),
512 	 * but it can be overridden on a per-page basis by connecting
513 	 * to the #GtkPrintOperation::request-page-setup signal.
514 	 *
515 	 * Params:
516 	 *     defaultPageSetup = a #GtkPageSetup, or %NULL
517 	 *
518 	 * Since: 2.10
519 	 */
520 	public void setDefaultPageSetup(PageSetup defaultPageSetup)
521 	{
522 		gtk_print_operation_set_default_page_setup(gtkPrintOperation, (defaultPageSetup is null) ? null : defaultPageSetup.getPageSetupStruct());
523 	}
524 
525 	/**
526 	 * Sets up the #GtkPrintOperation to wait for calling of
527 	 * gtk_print_operation_draw_page_finish() from application. It can
528 	 * be used for drawing page in another thread.
529 	 *
530 	 * This function must be called in the callback of “draw-page” signal.
531 	 *
532 	 * Since: 2.16
533 	 */
534 	public void setDeferDrawing()
535 	{
536 		gtk_print_operation_set_defer_drawing(gtkPrintOperation);
537 	}
538 
539 	/**
540 	 * Embed page size combo box and orientation combo box into page setup page.
541 	 * Selected page setup is stored as default page setup in #GtkPrintOperation.
542 	 *
543 	 * Params:
544 	 *     embed = %TRUE to embed page setup selection in the #GtkPrintUnixDialog
545 	 *
546 	 * Since: 2.18
547 	 */
548 	public void setEmbedPageSetup(bool embed)
549 	{
550 		gtk_print_operation_set_embed_page_setup(gtkPrintOperation, embed);
551 	}
552 
553 	/**
554 	 * Sets up the #GtkPrintOperation to generate a file instead
555 	 * of showing the print dialog. The indended use of this function
556 	 * is for implementing “Export to PDF” actions. Currently, PDF
557 	 * is the only supported format.
558 	 *
559 	 * “Print to PDF” support is independent of this and is done
560 	 * by letting the user pick the “Print to PDF” item from the list
561 	 * of printers in the print dialog.
562 	 *
563 	 * Params:
564 	 *     filename = the filename for the exported file
565 	 *
566 	 * Since: 2.10
567 	 */
568 	public void setExportFilename(string filename)
569 	{
570 		gtk_print_operation_set_export_filename(gtkPrintOperation, Str.toStringz(filename));
571 	}
572 
573 	/**
574 	 * Sets whether there is a selection to print.
575 	 *
576 	 * Application has to set number of pages to which the selection
577 	 * will draw by gtk_print_operation_set_n_pages() in a callback of
578 	 * #GtkPrintOperation::begin-print.
579 	 *
580 	 * Params:
581 	 *     hasSelection = %TRUE indicates that a selection exists
582 	 *
583 	 * Since: 2.18
584 	 */
585 	public void setHasSelection(bool hasSelection)
586 	{
587 		gtk_print_operation_set_has_selection(gtkPrintOperation, hasSelection);
588 	}
589 
590 	/**
591 	 * Sets the name of the print job. The name is used to identify
592 	 * the job (e.g. in monitoring applications like eggcups).
593 	 *
594 	 * If you don’t set a job name, GTK+ picks a default one by
595 	 * numbering successive print jobs.
596 	 *
597 	 * Params:
598 	 *     jobName = a string that identifies the print job
599 	 *
600 	 * Since: 2.10
601 	 */
602 	public void setJobName(string jobName)
603 	{
604 		gtk_print_operation_set_job_name(gtkPrintOperation, Str.toStringz(jobName));
605 	}
606 
607 	/**
608 	 * Sets the number of pages in the document.
609 	 *
610 	 * This must be set to a positive number
611 	 * before the rendering starts. It may be set in a
612 	 * #GtkPrintOperation::begin-print signal hander.
613 	 *
614 	 * Note that the page numbers passed to the
615 	 * #GtkPrintOperation::request-page-setup
616 	 * and #GtkPrintOperation::draw-page signals are 0-based, i.e. if
617 	 * the user chooses to print all pages, the last ::draw-page signal
618 	 * will be for page @n_pages - 1.
619 	 *
620 	 * Params:
621 	 *     nPages = the number of pages
622 	 *
623 	 * Since: 2.10
624 	 */
625 	public void setNPages(int nPages)
626 	{
627 		gtk_print_operation_set_n_pages(gtkPrintOperation, nPages);
628 	}
629 
630 	/**
631 	 * Sets the print settings for @op. This is typically used to
632 	 * re-establish print settings from a previous print operation,
633 	 * see gtk_print_operation_run().
634 	 *
635 	 * Params:
636 	 *     printSettings = #GtkPrintSettings
637 	 *
638 	 * Since: 2.10
639 	 */
640 	public void setPrintSettings(PrintSettings printSettings)
641 	{
642 		gtk_print_operation_set_print_settings(gtkPrintOperation, (printSettings is null) ? null : printSettings.getPrintSettingsStruct());
643 	}
644 
645 	/**
646 	 * If @show_progress is %TRUE, the print operation will show a
647 	 * progress dialog during the print operation.
648 	 *
649 	 * Params:
650 	 *     showProgress = %TRUE to show a progress dialog
651 	 *
652 	 * Since: 2.10
653 	 */
654 	public void setShowProgress(bool showProgress)
655 	{
656 		gtk_print_operation_set_show_progress(gtkPrintOperation, showProgress);
657 	}
658 
659 	/**
660 	 * Sets whether selection is supported by #GtkPrintOperation.
661 	 *
662 	 * Params:
663 	 *     supportSelection = %TRUE to support selection
664 	 *
665 	 * Since: 2.18
666 	 */
667 	public void setSupportSelection(bool supportSelection)
668 	{
669 		gtk_print_operation_set_support_selection(gtkPrintOperation, supportSelection);
670 	}
671 
672 	/**
673 	 * If track_status is %TRUE, the print operation will try to continue report
674 	 * on the status of the print job in the printer queues and printer. This
675 	 * can allow your application to show things like “out of paper” issues,
676 	 * and when the print job actually reaches the printer.
677 	 *
678 	 * This function is often implemented using some form of polling, so it should
679 	 * not be enabled unless needed.
680 	 *
681 	 * Params:
682 	 *     trackStatus = %TRUE to track status after printing
683 	 *
684 	 * Since: 2.10
685 	 */
686 	public void setTrackPrintStatus(bool trackStatus)
687 	{
688 		gtk_print_operation_set_track_print_status(gtkPrintOperation, trackStatus);
689 	}
690 
691 	/**
692 	 * Sets up the transformation for the cairo context obtained from
693 	 * #GtkPrintContext in such a way that distances are measured in
694 	 * units of @unit.
695 	 *
696 	 * Params:
697 	 *     unit = the unit to use
698 	 *
699 	 * Since: 2.10
700 	 */
701 	public void setUnit(GtkUnit unit)
702 	{
703 		gtk_print_operation_set_unit(gtkPrintOperation, unit);
704 	}
705 
706 	/**
707 	 * If @full_page is %TRUE, the transformation for the cairo context
708 	 * obtained from #GtkPrintContext puts the origin at the top left
709 	 * corner of the page (which may not be the top left corner of the
710 	 * sheet, depending on page orientation and the number of pages per
711 	 * sheet). Otherwise, the origin is at the top left corner of the
712 	 * imageable area (i.e. inside the margins).
713 	 *
714 	 * Params:
715 	 *     fullPage = %TRUE to set up the #GtkPrintContext for the full page
716 	 *
717 	 * Since: 2.10
718 	 */
719 	public void setUseFullPage(bool fullPage)
720 	{
721 		gtk_print_operation_set_use_full_page(gtkPrintOperation, fullPage);
722 	}
723 
724 	protected class OnBeginPrintDelegateWrapper
725 	{
726 		void delegate(PrintContext, PrintOperation) dlg;
727 		gulong handlerId;
728 
729 		this(void delegate(PrintContext, PrintOperation) dlg)
730 		{
731 			this.dlg = dlg;
732 			onBeginPrintListeners ~= this;
733 		}
734 
735 		void remove(OnBeginPrintDelegateWrapper source)
736 		{
737 			foreach(index, wrapper; onBeginPrintListeners)
738 			{
739 				if (wrapper.handlerId == source.handlerId)
740 				{
741 					onBeginPrintListeners[index] = null;
742 					onBeginPrintListeners = std.algorithm.remove(onBeginPrintListeners, index);
743 					break;
744 				}
745 			}
746 		}
747 	}
748 	OnBeginPrintDelegateWrapper[] onBeginPrintListeners;
749 
750 	/**
751 	 * Emitted after the user has finished changing print settings
752 	 * in the dialog, before the actual rendering starts.
753 	 *
754 	 * A typical use for ::begin-print is to use the parameters from the
755 	 * #GtkPrintContext and paginate the document accordingly, and then
756 	 * set the number of pages with gtk_print_operation_set_n_pages().
757 	 *
758 	 * Params:
759 	 *     context = the #GtkPrintContext for the current operation
760 	 *
761 	 * Since: 2.10
762 	 */
763 	gulong addOnBeginPrint(void delegate(PrintContext, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
764 	{
765 		auto wrapper = new OnBeginPrintDelegateWrapper(dlg);
766 		wrapper.handlerId = Signals.connectData(
767 			this,
768 			"begin-print",
769 			cast(GCallback)&callBackBeginPrint,
770 			cast(void*)wrapper,
771 			cast(GClosureNotify)&callBackBeginPrintDestroy,
772 			connectFlags);
773 		return wrapper.handlerId;
774 	}
775 
776 	extern(C) static void callBackBeginPrint(GtkPrintOperation* printoperationStruct, GtkPrintContext* context, OnBeginPrintDelegateWrapper wrapper)
777 	{
778 		wrapper.dlg(ObjectG.getDObject!(PrintContext)(context), wrapper.outer);
779 	}
780 
781 	extern(C) static void callBackBeginPrintDestroy(OnBeginPrintDelegateWrapper wrapper, GClosure* closure)
782 	{
783 		wrapper.remove(wrapper);
784 	}
785 
786 	protected class OnCreateCustomWidgetDelegateWrapper
787 	{
788 		ObjectG delegate(PrintOperation) dlg;
789 		gulong handlerId;
790 
791 		this(ObjectG delegate(PrintOperation) dlg)
792 		{
793 			this.dlg = dlg;
794 			onCreateCustomWidgetListeners ~= this;
795 		}
796 
797 		void remove(OnCreateCustomWidgetDelegateWrapper source)
798 		{
799 			foreach(index, wrapper; onCreateCustomWidgetListeners)
800 			{
801 				if (wrapper.handlerId == source.handlerId)
802 				{
803 					onCreateCustomWidgetListeners[index] = null;
804 					onCreateCustomWidgetListeners = std.algorithm.remove(onCreateCustomWidgetListeners, index);
805 					break;
806 				}
807 			}
808 		}
809 	}
810 	OnCreateCustomWidgetDelegateWrapper[] onCreateCustomWidgetListeners;
811 
812 	/**
813 	 * Emitted when displaying the print dialog. If you return a
814 	 * widget in a handler for this signal it will be added to a custom
815 	 * tab in the print dialog. You typically return a container widget
816 	 * with multiple widgets in it.
817 	 *
818 	 * The print dialog owns the returned widget, and its lifetime is not
819 	 * controlled by the application. However, the widget is guaranteed
820 	 * to stay around until the #GtkPrintOperation::custom-widget-apply
821 	 * signal is emitted on the operation. Then you can read out any
822 	 * information you need from the widgets.
823 	 *
824 	 * Returns: A custom widget that gets embedded in
825 	 *     the print dialog, or %NULL
826 	 *
827 	 * Since: 2.10
828 	 */
829 	gulong addOnCreateCustomWidget(ObjectG delegate(PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
830 	{
831 		auto wrapper = new OnCreateCustomWidgetDelegateWrapper(dlg);
832 		wrapper.handlerId = Signals.connectData(
833 			this,
834 			"create-custom-widget",
835 			cast(GCallback)&callBackCreateCustomWidget,
836 			cast(void*)wrapper,
837 			cast(GClosureNotify)&callBackCreateCustomWidgetDestroy,
838 			connectFlags);
839 		return wrapper.handlerId;
840 	}
841 
842 	extern(C) static GObject* callBackCreateCustomWidget(GtkPrintOperation* printoperationStruct, OnCreateCustomWidgetDelegateWrapper wrapper)
843 	{
844 		auto r = wrapper.dlg(wrapper.outer);
845 		return r.getObjectGStruct();
846 	}
847 
848 	extern(C) static void callBackCreateCustomWidgetDestroy(OnCreateCustomWidgetDelegateWrapper wrapper, GClosure* closure)
849 	{
850 		wrapper.remove(wrapper);
851 	}
852 
853 	protected class OnCustomWidgetApplyDelegateWrapper
854 	{
855 		void delegate(Widget, PrintOperation) dlg;
856 		gulong handlerId;
857 
858 		this(void delegate(Widget, PrintOperation) dlg)
859 		{
860 			this.dlg = dlg;
861 			onCustomWidgetApplyListeners ~= this;
862 		}
863 
864 		void remove(OnCustomWidgetApplyDelegateWrapper source)
865 		{
866 			foreach(index, wrapper; onCustomWidgetApplyListeners)
867 			{
868 				if (wrapper.handlerId == source.handlerId)
869 				{
870 					onCustomWidgetApplyListeners[index] = null;
871 					onCustomWidgetApplyListeners = std.algorithm.remove(onCustomWidgetApplyListeners, index);
872 					break;
873 				}
874 			}
875 		}
876 	}
877 	OnCustomWidgetApplyDelegateWrapper[] onCustomWidgetApplyListeners;
878 
879 	/**
880 	 * Emitted right before #GtkPrintOperation::begin-print if you added
881 	 * a custom widget in the #GtkPrintOperation::create-custom-widget handler.
882 	 * When you get this signal you should read the information from the
883 	 * custom widgets, as the widgets are not guaraneed to be around at a
884 	 * later time.
885 	 *
886 	 * Params:
887 	 *     widget = the custom widget added in create-custom-widget
888 	 *
889 	 * Since: 2.10
890 	 */
891 	gulong addOnCustomWidgetApply(void delegate(Widget, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
892 	{
893 		auto wrapper = new OnCustomWidgetApplyDelegateWrapper(dlg);
894 		wrapper.handlerId = Signals.connectData(
895 			this,
896 			"custom-widget-apply",
897 			cast(GCallback)&callBackCustomWidgetApply,
898 			cast(void*)wrapper,
899 			cast(GClosureNotify)&callBackCustomWidgetApplyDestroy,
900 			connectFlags);
901 		return wrapper.handlerId;
902 	}
903 
904 	extern(C) static void callBackCustomWidgetApply(GtkPrintOperation* printoperationStruct, GtkWidget* widget, OnCustomWidgetApplyDelegateWrapper wrapper)
905 	{
906 		wrapper.dlg(ObjectG.getDObject!(Widget)(widget), wrapper.outer);
907 	}
908 
909 	extern(C) static void callBackCustomWidgetApplyDestroy(OnCustomWidgetApplyDelegateWrapper wrapper, GClosure* closure)
910 	{
911 		wrapper.remove(wrapper);
912 	}
913 
914 	protected class OnDoneDelegateWrapper
915 	{
916 		void delegate(GtkPrintOperationResult, PrintOperation) dlg;
917 		gulong handlerId;
918 
919 		this(void delegate(GtkPrintOperationResult, PrintOperation) dlg)
920 		{
921 			this.dlg = dlg;
922 			onDoneListeners ~= this;
923 		}
924 
925 		void remove(OnDoneDelegateWrapper source)
926 		{
927 			foreach(index, wrapper; onDoneListeners)
928 			{
929 				if (wrapper.handlerId == source.handlerId)
930 				{
931 					onDoneListeners[index] = null;
932 					onDoneListeners = std.algorithm.remove(onDoneListeners, index);
933 					break;
934 				}
935 			}
936 		}
937 	}
938 	OnDoneDelegateWrapper[] onDoneListeners;
939 
940 	/**
941 	 * Emitted when the print operation run has finished doing
942 	 * everything required for printing.
943 	 *
944 	 * @result gives you information about what happened during the run.
945 	 * If @result is %GTK_PRINT_OPERATION_RESULT_ERROR then you can call
946 	 * gtk_print_operation_get_error() for more information.
947 	 *
948 	 * If you enabled print status tracking then
949 	 * gtk_print_operation_is_finished() may still return %FALSE
950 	 * after #GtkPrintOperation::done was emitted.
951 	 *
952 	 * Params:
953 	 *     result = the result of the print operation
954 	 *
955 	 * Since: 2.10
956 	 */
957 	gulong addOnDone(void delegate(GtkPrintOperationResult, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
958 	{
959 		auto wrapper = new OnDoneDelegateWrapper(dlg);
960 		wrapper.handlerId = Signals.connectData(
961 			this,
962 			"done",
963 			cast(GCallback)&callBackDone,
964 			cast(void*)wrapper,
965 			cast(GClosureNotify)&callBackDoneDestroy,
966 			connectFlags);
967 		return wrapper.handlerId;
968 	}
969 
970 	extern(C) static void callBackDone(GtkPrintOperation* printoperationStruct, GtkPrintOperationResult result, OnDoneDelegateWrapper wrapper)
971 	{
972 		wrapper.dlg(result, wrapper.outer);
973 	}
974 
975 	extern(C) static void callBackDoneDestroy(OnDoneDelegateWrapper wrapper, GClosure* closure)
976 	{
977 		wrapper.remove(wrapper);
978 	}
979 
980 	protected class OnDrawPageDelegateWrapper
981 	{
982 		void delegate(PrintContext, int, PrintOperation) dlg;
983 		gulong handlerId;
984 
985 		this(void delegate(PrintContext, int, PrintOperation) dlg)
986 		{
987 			this.dlg = dlg;
988 			onDrawPageListeners ~= this;
989 		}
990 
991 		void remove(OnDrawPageDelegateWrapper source)
992 		{
993 			foreach(index, wrapper; onDrawPageListeners)
994 			{
995 				if (wrapper.handlerId == source.handlerId)
996 				{
997 					onDrawPageListeners[index] = null;
998 					onDrawPageListeners = std.algorithm.remove(onDrawPageListeners, index);
999 					break;
1000 				}
1001 			}
1002 		}
1003 	}
1004 	OnDrawPageDelegateWrapper[] onDrawPageListeners;
1005 
1006 	/**
1007 	 * Emitted for every page that is printed. The signal handler
1008 	 * must render the @page_nr's page onto the cairo context obtained
1009 	 * from @context using gtk_print_context_get_cairo_context().
1010 	 * |[<!-- language="C" -->
1011 	 * static void
1012 	 * draw_page (GtkPrintOperation *operation,
1013 	 * GtkPrintContext   *context,
1014 	 * gint               page_nr,
1015 	 * gpointer           user_data)
1016 	 * {
1017 	 * cairo_t *cr;
1018 	 * PangoLayout *layout;
1019 	 * gdouble width, text_height;
1020 	 * gint layout_height;
1021 	 * PangoFontDescription *desc;
1022 	 *
1023 	 * cr = gtk_print_context_get_cairo_context (context);
1024 	 * width = gtk_print_context_get_width (context);
1025 	 *
1026 	 * cairo_rectangle (cr, 0, 0, width, HEADER_HEIGHT);
1027 	 *
1028 	 * cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
1029 	 * cairo_fill (cr);
1030 	 *
1031 	 * layout = gtk_print_context_create_pango_layout (context);
1032 	 *
1033 	 * desc = pango_font_description_from_string ("sans 14");
1034 	 * pango_layout_set_font_description (layout, desc);
1035 	 * pango_font_description_free (desc);
1036 	 *
1037 	 * pango_layout_set_text (layout, "some text", -1);
1038 	 * pango_layout_set_width (layout, width * PANGO_SCALE);
1039 	 * pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
1040 	 *
1041 	 * pango_layout_get_size (layout, NULL, &layout_height);
1042 	 * text_height = (gdouble)layout_height / PANGO_SCALE;
1043 	 *
1044 	 * cairo_move_to (cr, width / 2,  (HEADER_HEIGHT - text_height) / 2);
1045 	 * pango_cairo_show_layout (cr, layout);
1046 	 *
1047 	 * g_object_unref (layout);
1048 	 * }
1049 	 * ]|
1050 	 *
1051 	 * Use gtk_print_operation_set_use_full_page() and
1052 	 * gtk_print_operation_set_unit() before starting the print operation
1053 	 * to set up the transformation of the cairo context according to your
1054 	 * needs.
1055 	 *
1056 	 * Params:
1057 	 *     context = the #GtkPrintContext for the current operation
1058 	 *     pageNr = the number of the currently printed page (0-based)
1059 	 *
1060 	 * Since: 2.10
1061 	 */
1062 	gulong addOnDrawPage(void delegate(PrintContext, int, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
1063 	{
1064 		auto wrapper = new OnDrawPageDelegateWrapper(dlg);
1065 		wrapper.handlerId = Signals.connectData(
1066 			this,
1067 			"draw-page",
1068 			cast(GCallback)&callBackDrawPage,
1069 			cast(void*)wrapper,
1070 			cast(GClosureNotify)&callBackDrawPageDestroy,
1071 			connectFlags);
1072 		return wrapper.handlerId;
1073 	}
1074 
1075 	extern(C) static void callBackDrawPage(GtkPrintOperation* printoperationStruct, GtkPrintContext* context, int pageNr, OnDrawPageDelegateWrapper wrapper)
1076 	{
1077 		wrapper.dlg(ObjectG.getDObject!(PrintContext)(context), pageNr, wrapper.outer);
1078 	}
1079 
1080 	extern(C) static void callBackDrawPageDestroy(OnDrawPageDelegateWrapper wrapper, GClosure* closure)
1081 	{
1082 		wrapper.remove(wrapper);
1083 	}
1084 
1085 	protected class OnEndPrintDelegateWrapper
1086 	{
1087 		void delegate(PrintContext, PrintOperation) dlg;
1088 		gulong handlerId;
1089 
1090 		this(void delegate(PrintContext, PrintOperation) dlg)
1091 		{
1092 			this.dlg = dlg;
1093 			onEndPrintListeners ~= this;
1094 		}
1095 
1096 		void remove(OnEndPrintDelegateWrapper source)
1097 		{
1098 			foreach(index, wrapper; onEndPrintListeners)
1099 			{
1100 				if (wrapper.handlerId == source.handlerId)
1101 				{
1102 					onEndPrintListeners[index] = null;
1103 					onEndPrintListeners = std.algorithm.remove(onEndPrintListeners, index);
1104 					break;
1105 				}
1106 			}
1107 		}
1108 	}
1109 	OnEndPrintDelegateWrapper[] onEndPrintListeners;
1110 
1111 	/**
1112 	 * Emitted after all pages have been rendered.
1113 	 * A handler for this signal can clean up any resources that have
1114 	 * been allocated in the #GtkPrintOperation::begin-print handler.
1115 	 *
1116 	 * Params:
1117 	 *     context = the #GtkPrintContext for the current operation
1118 	 *
1119 	 * Since: 2.10
1120 	 */
1121 	gulong addOnEndPrint(void delegate(PrintContext, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
1122 	{
1123 		auto wrapper = new OnEndPrintDelegateWrapper(dlg);
1124 		wrapper.handlerId = Signals.connectData(
1125 			this,
1126 			"end-print",
1127 			cast(GCallback)&callBackEndPrint,
1128 			cast(void*)wrapper,
1129 			cast(GClosureNotify)&callBackEndPrintDestroy,
1130 			connectFlags);
1131 		return wrapper.handlerId;
1132 	}
1133 
1134 	extern(C) static void callBackEndPrint(GtkPrintOperation* printoperationStruct, GtkPrintContext* context, OnEndPrintDelegateWrapper wrapper)
1135 	{
1136 		wrapper.dlg(ObjectG.getDObject!(PrintContext)(context), wrapper.outer);
1137 	}
1138 
1139 	extern(C) static void callBackEndPrintDestroy(OnEndPrintDelegateWrapper wrapper, GClosure* closure)
1140 	{
1141 		wrapper.remove(wrapper);
1142 	}
1143 
1144 	protected class OnPaginateDelegateWrapper
1145 	{
1146 		bool delegate(PrintContext, PrintOperation) dlg;
1147 		gulong handlerId;
1148 
1149 		this(bool delegate(PrintContext, PrintOperation) dlg)
1150 		{
1151 			this.dlg = dlg;
1152 			onPaginateListeners ~= this;
1153 		}
1154 
1155 		void remove(OnPaginateDelegateWrapper source)
1156 		{
1157 			foreach(index, wrapper; onPaginateListeners)
1158 			{
1159 				if (wrapper.handlerId == source.handlerId)
1160 				{
1161 					onPaginateListeners[index] = null;
1162 					onPaginateListeners = std.algorithm.remove(onPaginateListeners, index);
1163 					break;
1164 				}
1165 			}
1166 		}
1167 	}
1168 	OnPaginateDelegateWrapper[] onPaginateListeners;
1169 
1170 	/**
1171 	 * Emitted after the #GtkPrintOperation::begin-print signal, but before
1172 	 * the actual rendering starts. It keeps getting emitted until a connected
1173 	 * signal handler returns %TRUE.
1174 	 *
1175 	 * The ::paginate signal is intended to be used for paginating a document
1176 	 * in small chunks, to avoid blocking the user interface for a long
1177 	 * time. The signal handler should update the number of pages using
1178 	 * gtk_print_operation_set_n_pages(), and return %TRUE if the document
1179 	 * has been completely paginated.
1180 	 *
1181 	 * If you don't need to do pagination in chunks, you can simply do
1182 	 * it all in the ::begin-print handler, and set the number of pages
1183 	 * from there.
1184 	 *
1185 	 * Params:
1186 	 *     context = the #GtkPrintContext for the current operation
1187 	 *
1188 	 * Returns: %TRUE if pagination is complete
1189 	 *
1190 	 * Since: 2.10
1191 	 */
1192 	gulong addOnPaginate(bool delegate(PrintContext, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
1193 	{
1194 		auto wrapper = new OnPaginateDelegateWrapper(dlg);
1195 		wrapper.handlerId = Signals.connectData(
1196 			this,
1197 			"paginate",
1198 			cast(GCallback)&callBackPaginate,
1199 			cast(void*)wrapper,
1200 			cast(GClosureNotify)&callBackPaginateDestroy,
1201 			connectFlags);
1202 		return wrapper.handlerId;
1203 	}
1204 
1205 	extern(C) static int callBackPaginate(GtkPrintOperation* printoperationStruct, GtkPrintContext* context, OnPaginateDelegateWrapper wrapper)
1206 	{
1207 		return wrapper.dlg(ObjectG.getDObject!(PrintContext)(context), wrapper.outer);
1208 	}
1209 
1210 	extern(C) static void callBackPaginateDestroy(OnPaginateDelegateWrapper wrapper, GClosure* closure)
1211 	{
1212 		wrapper.remove(wrapper);
1213 	}
1214 
1215 	protected class OnPreviewDelegateWrapper
1216 	{
1217 		bool delegate(PrintOperationPreviewIF, PrintContext, Window, PrintOperation) dlg;
1218 		gulong handlerId;
1219 
1220 		this(bool delegate(PrintOperationPreviewIF, PrintContext, Window, PrintOperation) dlg)
1221 		{
1222 			this.dlg = dlg;
1223 			onPreviewListeners ~= this;
1224 		}
1225 
1226 		void remove(OnPreviewDelegateWrapper source)
1227 		{
1228 			foreach(index, wrapper; onPreviewListeners)
1229 			{
1230 				if (wrapper.handlerId == source.handlerId)
1231 				{
1232 					onPreviewListeners[index] = null;
1233 					onPreviewListeners = std.algorithm.remove(onPreviewListeners, index);
1234 					break;
1235 				}
1236 			}
1237 		}
1238 	}
1239 	OnPreviewDelegateWrapper[] onPreviewListeners;
1240 
1241 	/**
1242 	 * Gets emitted when a preview is requested from the native dialog.
1243 	 *
1244 	 * The default handler for this signal uses an external viewer
1245 	 * application to preview.
1246 	 *
1247 	 * To implement a custom print preview, an application must return
1248 	 * %TRUE from its handler for this signal. In order to use the
1249 	 * provided @context for the preview implementation, it must be
1250 	 * given a suitable cairo context with gtk_print_context_set_cairo_context().
1251 	 *
1252 	 * The custom preview implementation can use
1253 	 * gtk_print_operation_preview_is_selected() and
1254 	 * gtk_print_operation_preview_render_page() to find pages which
1255 	 * are selected for print and render them. The preview must be
1256 	 * finished by calling gtk_print_operation_preview_end_preview()
1257 	 * (typically in response to the user clicking a close button).
1258 	 *
1259 	 * Params:
1260 	 *     preview = the #GtkPrintOperationPreview for the current operation
1261 	 *     context = the #GtkPrintContext that will be used
1262 	 *     parent = the #GtkWindow to use as window parent, or %NULL
1263 	 *
1264 	 * Returns: %TRUE if the listener wants to take over control of the preview
1265 	 *
1266 	 * Since: 2.10
1267 	 */
1268 	gulong addOnPreview(bool delegate(PrintOperationPreviewIF, PrintContext, Window, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
1269 	{
1270 		auto wrapper = new OnPreviewDelegateWrapper(dlg);
1271 		wrapper.handlerId = Signals.connectData(
1272 			this,
1273 			"preview",
1274 			cast(GCallback)&callBackPreview,
1275 			cast(void*)wrapper,
1276 			cast(GClosureNotify)&callBackPreviewDestroy,
1277 			connectFlags);
1278 		return wrapper.handlerId;
1279 	}
1280 
1281 	extern(C) static int callBackPreview(GtkPrintOperation* printoperationStruct, GtkPrintOperationPreview* preview, GtkPrintContext* context, GtkWindow* parent, OnPreviewDelegateWrapper wrapper)
1282 	{
1283 		return wrapper.dlg(ObjectG.getDObject!(PrintOperationPreviewIF)(preview), ObjectG.getDObject!(PrintContext)(context), ObjectG.getDObject!(Window)(parent), wrapper.outer);
1284 	}
1285 
1286 	extern(C) static void callBackPreviewDestroy(OnPreviewDelegateWrapper wrapper, GClosure* closure)
1287 	{
1288 		wrapper.remove(wrapper);
1289 	}
1290 
1291 	protected class OnRequestPageSetupDelegateWrapper
1292 	{
1293 		void delegate(PrintContext, int, PageSetup, PrintOperation) dlg;
1294 		gulong handlerId;
1295 
1296 		this(void delegate(PrintContext, int, PageSetup, PrintOperation) dlg)
1297 		{
1298 			this.dlg = dlg;
1299 			onRequestPageSetupListeners ~= this;
1300 		}
1301 
1302 		void remove(OnRequestPageSetupDelegateWrapper source)
1303 		{
1304 			foreach(index, wrapper; onRequestPageSetupListeners)
1305 			{
1306 				if (wrapper.handlerId == source.handlerId)
1307 				{
1308 					onRequestPageSetupListeners[index] = null;
1309 					onRequestPageSetupListeners = std.algorithm.remove(onRequestPageSetupListeners, index);
1310 					break;
1311 				}
1312 			}
1313 		}
1314 	}
1315 	OnRequestPageSetupDelegateWrapper[] onRequestPageSetupListeners;
1316 
1317 	/**
1318 	 * Emitted once for every page that is printed, to give
1319 	 * the application a chance to modify the page setup. Any changes
1320 	 * done to @setup will be in force only for printing this page.
1321 	 *
1322 	 * Params:
1323 	 *     context = the #GtkPrintContext for the current operation
1324 	 *     pageNr = the number of the currently printed page (0-based)
1325 	 *     setup = the #GtkPageSetup
1326 	 *
1327 	 * Since: 2.10
1328 	 */
1329 	gulong addOnRequestPageSetup(void delegate(PrintContext, int, PageSetup, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
1330 	{
1331 		auto wrapper = new OnRequestPageSetupDelegateWrapper(dlg);
1332 		wrapper.handlerId = Signals.connectData(
1333 			this,
1334 			"request-page-setup",
1335 			cast(GCallback)&callBackRequestPageSetup,
1336 			cast(void*)wrapper,
1337 			cast(GClosureNotify)&callBackRequestPageSetupDestroy,
1338 			connectFlags);
1339 		return wrapper.handlerId;
1340 	}
1341 
1342 	extern(C) static void callBackRequestPageSetup(GtkPrintOperation* printoperationStruct, GtkPrintContext* context, int pageNr, GtkPageSetup* setup, OnRequestPageSetupDelegateWrapper wrapper)
1343 	{
1344 		wrapper.dlg(ObjectG.getDObject!(PrintContext)(context), pageNr, ObjectG.getDObject!(PageSetup)(setup), wrapper.outer);
1345 	}
1346 
1347 	extern(C) static void callBackRequestPageSetupDestroy(OnRequestPageSetupDelegateWrapper wrapper, GClosure* closure)
1348 	{
1349 		wrapper.remove(wrapper);
1350 	}
1351 
1352 	protected class OnStatusChangedDelegateWrapper
1353 	{
1354 		void delegate(PrintOperation) dlg;
1355 		gulong handlerId;
1356 
1357 		this(void delegate(PrintOperation) dlg)
1358 		{
1359 			this.dlg = dlg;
1360 			onStatusChangedListeners ~= this;
1361 		}
1362 
1363 		void remove(OnStatusChangedDelegateWrapper source)
1364 		{
1365 			foreach(index, wrapper; onStatusChangedListeners)
1366 			{
1367 				if (wrapper.handlerId == source.handlerId)
1368 				{
1369 					onStatusChangedListeners[index] = null;
1370 					onStatusChangedListeners = std.algorithm.remove(onStatusChangedListeners, index);
1371 					break;
1372 				}
1373 			}
1374 		}
1375 	}
1376 	OnStatusChangedDelegateWrapper[] onStatusChangedListeners;
1377 
1378 	/**
1379 	 * Emitted at between the various phases of the print operation.
1380 	 * See #GtkPrintStatus for the phases that are being discriminated.
1381 	 * Use gtk_print_operation_get_status() to find out the current
1382 	 * status.
1383 	 *
1384 	 * Since: 2.10
1385 	 */
1386 	gulong addOnStatusChanged(void delegate(PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
1387 	{
1388 		auto wrapper = new OnStatusChangedDelegateWrapper(dlg);
1389 		wrapper.handlerId = Signals.connectData(
1390 			this,
1391 			"status-changed",
1392 			cast(GCallback)&callBackStatusChanged,
1393 			cast(void*)wrapper,
1394 			cast(GClosureNotify)&callBackStatusChangedDestroy,
1395 			connectFlags);
1396 		return wrapper.handlerId;
1397 	}
1398 
1399 	extern(C) static void callBackStatusChanged(GtkPrintOperation* printoperationStruct, OnStatusChangedDelegateWrapper wrapper)
1400 	{
1401 		wrapper.dlg(wrapper.outer);
1402 	}
1403 
1404 	extern(C) static void callBackStatusChangedDestroy(OnStatusChangedDelegateWrapper wrapper, GClosure* closure)
1405 	{
1406 		wrapper.remove(wrapper);
1407 	}
1408 
1409 	protected class OnUpdateCustomWidgetDelegateWrapper
1410 	{
1411 		void delegate(Widget, PageSetup, PrintSettings, PrintOperation) dlg;
1412 		gulong handlerId;
1413 
1414 		this(void delegate(Widget, PageSetup, PrintSettings, PrintOperation) dlg)
1415 		{
1416 			this.dlg = dlg;
1417 			onUpdateCustomWidgetListeners ~= this;
1418 		}
1419 
1420 		void remove(OnUpdateCustomWidgetDelegateWrapper source)
1421 		{
1422 			foreach(index, wrapper; onUpdateCustomWidgetListeners)
1423 			{
1424 				if (wrapper.handlerId == source.handlerId)
1425 				{
1426 					onUpdateCustomWidgetListeners[index] = null;
1427 					onUpdateCustomWidgetListeners = std.algorithm.remove(onUpdateCustomWidgetListeners, index);
1428 					break;
1429 				}
1430 			}
1431 		}
1432 	}
1433 	OnUpdateCustomWidgetDelegateWrapper[] onUpdateCustomWidgetListeners;
1434 
1435 	/**
1436 	 * Emitted after change of selected printer. The actual page setup and
1437 	 * print settings are passed to the custom widget, which can actualize
1438 	 * itself according to this change.
1439 	 *
1440 	 * Params:
1441 	 *     widget = the custom widget added in create-custom-widget
1442 	 *     setup = actual page setup
1443 	 *     settings = actual print settings
1444 	 *
1445 	 * Since: 2.18
1446 	 */
1447 	gulong addOnUpdateCustomWidget(void delegate(Widget, PageSetup, PrintSettings, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
1448 	{
1449 		auto wrapper = new OnUpdateCustomWidgetDelegateWrapper(dlg);
1450 		wrapper.handlerId = Signals.connectData(
1451 			this,
1452 			"update-custom-widget",
1453 			cast(GCallback)&callBackUpdateCustomWidget,
1454 			cast(void*)wrapper,
1455 			cast(GClosureNotify)&callBackUpdateCustomWidgetDestroy,
1456 			connectFlags);
1457 		return wrapper.handlerId;
1458 	}
1459 
1460 	extern(C) static void callBackUpdateCustomWidget(GtkPrintOperation* printoperationStruct, GtkWidget* widget, GtkPageSetup* setup, GtkPrintSettings* settings, OnUpdateCustomWidgetDelegateWrapper wrapper)
1461 	{
1462 		wrapper.dlg(ObjectG.getDObject!(Widget)(widget), ObjectG.getDObject!(PageSetup)(setup), ObjectG.getDObject!(PrintSettings)(settings), wrapper.outer);
1463 	}
1464 
1465 	extern(C) static void callBackUpdateCustomWidgetDestroy(OnUpdateCustomWidgetDelegateWrapper wrapper, GClosure* closure)
1466 	{
1467 		wrapper.remove(wrapper);
1468 	}
1469 
1470 	/**
1471 	 * Runs a page setup dialog, letting the user modify the values from
1472 	 * @page_setup. If the user cancels the dialog, the returned #GtkPageSetup
1473 	 * is identical to the passed in @page_setup, otherwise it contains the
1474 	 * modifications done in the dialog.
1475 	 *
1476 	 * Note that this function may use a recursive mainloop to show the page
1477 	 * setup dialog. See gtk_print_run_page_setup_dialog_async() if this is
1478 	 * a problem.
1479 	 *
1480 	 * Params:
1481 	 *     parent = transient parent
1482 	 *     pageSetup = an existing #GtkPageSetup
1483 	 *     settings = a #GtkPrintSettings
1484 	 *
1485 	 * Returns: a new #GtkPageSetup
1486 	 *
1487 	 * Since: 2.10
1488 	 */
1489 	public static PageSetup printRunPageSetupDialog(Window parent, PageSetup pageSetup, PrintSettings settings)
1490 	{
1491 		auto p = gtk_print_run_page_setup_dialog((parent is null) ? null : parent.getWindowStruct(), (pageSetup is null) ? null : pageSetup.getPageSetupStruct(), (settings is null) ? null : settings.getPrintSettingsStruct());
1492 
1493 		if(p is null)
1494 		{
1495 			return null;
1496 		}
1497 
1498 		return ObjectG.getDObject!(PageSetup)(cast(GtkPageSetup*) p, true);
1499 	}
1500 
1501 	/**
1502 	 * Runs a page setup dialog, letting the user modify the values from @page_setup.
1503 	 *
1504 	 * In contrast to gtk_print_run_page_setup_dialog(), this function  returns after
1505 	 * showing the page setup dialog on platforms that support this, and calls @done_cb
1506 	 * from a signal handler for the ::response signal of the dialog.
1507 	 *
1508 	 * Params:
1509 	 *     parent = transient parent, or %NULL
1510 	 *     pageSetup = an existing #GtkPageSetup, or %NULL
1511 	 *     settings = a #GtkPrintSettings
1512 	 *     doneCb = a function to call when the user saves
1513 	 *         the modified page setup
1514 	 *     data = user data to pass to @done_cb
1515 	 *
1516 	 * Since: 2.10
1517 	 */
1518 	public static void printRunPageSetupDialogAsync(Window parent, PageSetup pageSetup, PrintSettings settings, GtkPageSetupDoneFunc doneCb, void* data)
1519 	{
1520 		gtk_print_run_page_setup_dialog_async((parent is null) ? null : parent.getWindowStruct(), (pageSetup is null) ? null : pageSetup.getPageSetupStruct(), (settings is null) ? null : settings.getPrintSettingsStruct(), doneCb, data);
1521 	}
1522 }