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