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