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 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() 116 { 117 return gtkPrintOperation; 118 } 119 120 /** the main Gtk struct as a void* */ 121 protected override void* getStruct() 122 { 123 return cast(void*)gtkPrintOperation; 124 } 125 126 protected override void setStruct(GObject* obj) 127 { 128 gtkPrintOperation = cast(GtkPrintOperation*)obj; 129 super.setStruct(obj); 130 } 131 132 /** 133 * Sets our main struct and passes it to the parent class. 134 */ 135 public this (GtkPrintOperation* gtkPrintOperation, bool ownedRef = false) 136 { 137 this.gtkPrintOperation = gtkPrintOperation; 138 super(cast(GObject*)gtkPrintOperation, ownedRef); 139 } 140 141 // add the PrintOperationPreview capabilities 142 mixin PrintOperationPreviewT!(GtkPrintOperation); 143 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 int[string] connectedSignals; 724 725 void delegate(PrintContext, PrintOperation)[] onBeginPrintListeners; 726 /** 727 * Emitted after the user has finished changing print settings 728 * in the dialog, before the actual rendering starts. 729 * 730 * A typical use for ::begin-print is to use the parameters from the 731 * #GtkPrintContext and paginate the document accordingly, and then 732 * set the number of pages with gtk_print_operation_set_n_pages(). 733 * 734 * Params: 735 * context = the #GtkPrintContext for the current operation 736 * 737 * Since: 2.10 738 */ 739 void addOnBeginPrint(void delegate(PrintContext, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 740 { 741 if ( "begin-print" !in connectedSignals ) 742 { 743 Signals.connectData( 744 this, 745 "begin-print", 746 cast(GCallback)&callBackBeginPrint, 747 cast(void*)this, 748 null, 749 connectFlags); 750 connectedSignals["begin-print"] = 1; 751 } 752 onBeginPrintListeners ~= dlg; 753 } 754 extern(C) static void callBackBeginPrint(GtkPrintOperation* printoperationStruct, GtkPrintContext* context, PrintOperation _printoperation) 755 { 756 foreach ( void delegate(PrintContext, PrintOperation) dlg; _printoperation.onBeginPrintListeners ) 757 { 758 dlg(ObjectG.getDObject!(PrintContext)(context), _printoperation); 759 } 760 } 761 762 ObjectG delegate(PrintOperation)[] onCreateCustomWidgetListeners; 763 /** 764 * Emitted when displaying the print dialog. If you return a 765 * widget in a handler for this signal it will be added to a custom 766 * tab in the print dialog. You typically return a container widget 767 * with multiple widgets in it. 768 * 769 * The print dialog owns the returned widget, and its lifetime is not 770 * controlled by the application. However, the widget is guaranteed 771 * to stay around until the #GtkPrintOperation::custom-widget-apply 772 * signal is emitted on the operation. Then you can read out any 773 * information you need from the widgets. 774 * 775 * Return: A custom widget that gets embedded in 776 * the print dialog, or %NULL 777 * 778 * Since: 2.10 779 */ 780 void addOnCreateCustomWidget(ObjectG delegate(PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 781 { 782 if ( "create-custom-widget" !in connectedSignals ) 783 { 784 Signals.connectData( 785 this, 786 "create-custom-widget", 787 cast(GCallback)&callBackCreateCustomWidget, 788 cast(void*)this, 789 null, 790 connectFlags); 791 connectedSignals["create-custom-widget"] = 1; 792 } 793 onCreateCustomWidgetListeners ~= dlg; 794 } 795 extern(C) static GObject* callBackCreateCustomWidget(GtkPrintOperation* printoperationStruct, PrintOperation _printoperation) 796 { 797 foreach ( ObjectG delegate(PrintOperation) dlg; _printoperation.onCreateCustomWidgetListeners ) 798 { 799 if ( auto r = dlg(_printoperation) ) 800 return r.getObjectGStruct(); 801 } 802 803 return null; 804 } 805 806 void delegate(Widget, PrintOperation)[] onCustomWidgetApplyListeners; 807 /** 808 * Emitted right before #GtkPrintOperation::begin-print if you added 809 * a custom widget in the #GtkPrintOperation::create-custom-widget handler. 810 * When you get this signal you should read the information from the 811 * custom widgets, as the widgets are not guaraneed to be around at a 812 * later time. 813 * 814 * Params: 815 * widget = the custom widget added in create-custom-widget 816 * 817 * Since: 2.10 818 */ 819 void addOnCustomWidgetApply(void delegate(Widget, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 820 { 821 if ( "custom-widget-apply" !in connectedSignals ) 822 { 823 Signals.connectData( 824 this, 825 "custom-widget-apply", 826 cast(GCallback)&callBackCustomWidgetApply, 827 cast(void*)this, 828 null, 829 connectFlags); 830 connectedSignals["custom-widget-apply"] = 1; 831 } 832 onCustomWidgetApplyListeners ~= dlg; 833 } 834 extern(C) static void callBackCustomWidgetApply(GtkPrintOperation* printoperationStruct, GtkWidget* widget, PrintOperation _printoperation) 835 { 836 foreach ( void delegate(Widget, PrintOperation) dlg; _printoperation.onCustomWidgetApplyListeners ) 837 { 838 dlg(ObjectG.getDObject!(Widget)(widget), _printoperation); 839 } 840 } 841 842 void delegate(GtkPrintOperationResult, PrintOperation)[] onDoneListeners; 843 /** 844 * Emitted when the print operation run has finished doing 845 * everything required for printing. 846 * 847 * @result gives you information about what happened during the run. 848 * If @result is %GTK_PRINT_OPERATION_RESULT_ERROR then you can call 849 * gtk_print_operation_get_error() for more information. 850 * 851 * If you enabled print status tracking then 852 * gtk_print_operation_is_finished() may still return %FALSE 853 * after #GtkPrintOperation::done was emitted. 854 * 855 * Params: 856 * result = the result of the print operation 857 * 858 * Since: 2.10 859 */ 860 void addOnDone(void delegate(GtkPrintOperationResult, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 861 { 862 if ( "done" !in connectedSignals ) 863 { 864 Signals.connectData( 865 this, 866 "done", 867 cast(GCallback)&callBackDone, 868 cast(void*)this, 869 null, 870 connectFlags); 871 connectedSignals["done"] = 1; 872 } 873 onDoneListeners ~= dlg; 874 } 875 extern(C) static void callBackDone(GtkPrintOperation* printoperationStruct, GtkPrintOperationResult result, PrintOperation _printoperation) 876 { 877 foreach ( void delegate(GtkPrintOperationResult, PrintOperation) dlg; _printoperation.onDoneListeners ) 878 { 879 dlg(result, _printoperation); 880 } 881 } 882 883 void delegate(PrintContext, int, PrintOperation)[] onDrawPageListeners; 884 /** 885 * Emitted for every page that is printed. The signal handler 886 * must render the @page_nr's page onto the cairo context obtained 887 * from @context using gtk_print_context_get_cairo_context(). 888 * |[<!-- language="C" --> 889 * static void 890 * draw_page (GtkPrintOperation *operation, 891 * GtkPrintContext *context, 892 * gint page_nr, 893 * gpointer user_data) 894 * { 895 * cairo_t *cr; 896 * PangoLayout *layout; 897 * gdouble width, text_height; 898 * gint layout_height; 899 * PangoFontDescription *desc; 900 * 901 * cr = gtk_print_context_get_cairo_context (context); 902 * width = gtk_print_context_get_width (context); 903 * 904 * cairo_rectangle (cr, 0, 0, width, HEADER_HEIGHT); 905 * 906 * cairo_set_source_rgb (cr, 0.8, 0.8, 0.8); 907 * cairo_fill (cr); 908 * 909 * layout = gtk_print_context_create_pango_layout (context); 910 * 911 * desc = pango_font_description_from_string ("sans 14"); 912 * pango_layout_set_font_description (layout, desc); 913 * pango_font_description_free (desc); 914 * 915 * pango_layout_set_text (layout, "some text", -1); 916 * pango_layout_set_width (layout, width * PANGO_SCALE); 917 * pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); 918 * 919 * pango_layout_get_size (layout, NULL, &layout_height); 920 * text_height = (gdouble)layout_height / PANGO_SCALE; 921 * 922 * cairo_move_to (cr, width / 2, (HEADER_HEIGHT - text_height) / 2); 923 * pango_cairo_show_layout (cr, layout); 924 * 925 * g_object_unref (layout); 926 * } 927 * ]| 928 * 929 * Use gtk_print_operation_set_use_full_page() and 930 * gtk_print_operation_set_unit() before starting the print operation 931 * to set up the transformation of the cairo context according to your 932 * needs. 933 * 934 * Params: 935 * context = the #GtkPrintContext for the current operation 936 * pageNr = the number of the currently printed page (0-based) 937 * 938 * Since: 2.10 939 */ 940 void addOnDrawPage(void delegate(PrintContext, int, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 941 { 942 if ( "draw-page" !in connectedSignals ) 943 { 944 Signals.connectData( 945 this, 946 "draw-page", 947 cast(GCallback)&callBackDrawPage, 948 cast(void*)this, 949 null, 950 connectFlags); 951 connectedSignals["draw-page"] = 1; 952 } 953 onDrawPageListeners ~= dlg; 954 } 955 extern(C) static void callBackDrawPage(GtkPrintOperation* printoperationStruct, GtkPrintContext* context, int pageNr, PrintOperation _printoperation) 956 { 957 foreach ( void delegate(PrintContext, int, PrintOperation) dlg; _printoperation.onDrawPageListeners ) 958 { 959 dlg(ObjectG.getDObject!(PrintContext)(context), pageNr, _printoperation); 960 } 961 } 962 963 void delegate(PrintContext, PrintOperation)[] onEndPrintListeners; 964 /** 965 * Emitted after all pages have been rendered. 966 * A handler for this signal can clean up any resources that have 967 * been allocated in the #GtkPrintOperation::begin-print handler. 968 * 969 * Params: 970 * context = the #GtkPrintContext for the current operation 971 * 972 * Since: 2.10 973 */ 974 void addOnEndPrint(void delegate(PrintContext, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 975 { 976 if ( "end-print" !in connectedSignals ) 977 { 978 Signals.connectData( 979 this, 980 "end-print", 981 cast(GCallback)&callBackEndPrint, 982 cast(void*)this, 983 null, 984 connectFlags); 985 connectedSignals["end-print"] = 1; 986 } 987 onEndPrintListeners ~= dlg; 988 } 989 extern(C) static void callBackEndPrint(GtkPrintOperation* printoperationStruct, GtkPrintContext* context, PrintOperation _printoperation) 990 { 991 foreach ( void delegate(PrintContext, PrintOperation) dlg; _printoperation.onEndPrintListeners ) 992 { 993 dlg(ObjectG.getDObject!(PrintContext)(context), _printoperation); 994 } 995 } 996 997 bool delegate(PrintContext, PrintOperation)[] onPaginateListeners; 998 /** 999 * Emitted after the #GtkPrintOperation::begin-print signal, but before 1000 * the actual rendering starts. It keeps getting emitted until a connected 1001 * signal handler returns %TRUE. 1002 * 1003 * The ::paginate signal is intended to be used for paginating a document 1004 * in small chunks, to avoid blocking the user interface for a long 1005 * time. The signal handler should update the number of pages using 1006 * gtk_print_operation_set_n_pages(), and return %TRUE if the document 1007 * has been completely paginated. 1008 * 1009 * If you don't need to do pagination in chunks, you can simply do 1010 * it all in the ::begin-print handler, and set the number of pages 1011 * from there. 1012 * 1013 * Params: 1014 * context = the #GtkPrintContext for the current operation 1015 * 1016 * Return: %TRUE if pagination is complete 1017 * 1018 * Since: 2.10 1019 */ 1020 void addOnPaginate(bool delegate(PrintContext, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1021 { 1022 if ( "paginate" !in connectedSignals ) 1023 { 1024 Signals.connectData( 1025 this, 1026 "paginate", 1027 cast(GCallback)&callBackPaginate, 1028 cast(void*)this, 1029 null, 1030 connectFlags); 1031 connectedSignals["paginate"] = 1; 1032 } 1033 onPaginateListeners ~= dlg; 1034 } 1035 extern(C) static int callBackPaginate(GtkPrintOperation* printoperationStruct, GtkPrintContext* context, PrintOperation _printoperation) 1036 { 1037 foreach ( bool delegate(PrintContext, PrintOperation) dlg; _printoperation.onPaginateListeners ) 1038 { 1039 if ( dlg(ObjectG.getDObject!(PrintContext)(context), _printoperation) ) 1040 { 1041 return 1; 1042 } 1043 } 1044 1045 return 0; 1046 } 1047 1048 bool delegate(PrintOperationPreviewIF, PrintContext, Window, PrintOperation)[] onPreviewListeners; 1049 /** 1050 * Gets emitted when a preview is requested from the native dialog. 1051 * 1052 * The default handler for this signal uses an external viewer 1053 * application to preview. 1054 * 1055 * To implement a custom print preview, an application must return 1056 * %TRUE from its handler for this signal. In order to use the 1057 * provided @context for the preview implementation, it must be 1058 * given a suitable cairo context with gtk_print_context_set_cairo_context(). 1059 * 1060 * The custom preview implementation can use 1061 * gtk_print_operation_preview_is_selected() and 1062 * gtk_print_operation_preview_render_page() to find pages which 1063 * are selected for print and render them. The preview must be 1064 * finished by calling gtk_print_operation_preview_end_preview() 1065 * (typically in response to the user clicking a close button). 1066 * 1067 * Params: 1068 * preview = the #GtkPrintOperationPreview for the current operation 1069 * context = the #GtkPrintContext that will be used 1070 * parent = the #GtkWindow to use as window parent, or %NULL 1071 * 1072 * Return: %TRUE if the listener wants to take over control of the preview 1073 * 1074 * Since: 2.10 1075 */ 1076 void addOnPreview(bool delegate(PrintOperationPreviewIF, PrintContext, Window, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1077 { 1078 if ( "preview" !in connectedSignals ) 1079 { 1080 Signals.connectData( 1081 this, 1082 "preview", 1083 cast(GCallback)&callBackPreview, 1084 cast(void*)this, 1085 null, 1086 connectFlags); 1087 connectedSignals["preview"] = 1; 1088 } 1089 onPreviewListeners ~= dlg; 1090 } 1091 extern(C) static int callBackPreview(GtkPrintOperation* printoperationStruct, GtkPrintOperationPreview* preview, GtkPrintContext* context, GtkWindow* parent, PrintOperation _printoperation) 1092 { 1093 foreach ( bool delegate(PrintOperationPreviewIF, PrintContext, Window, PrintOperation) dlg; _printoperation.onPreviewListeners ) 1094 { 1095 if ( dlg(ObjectG.getDObject!(PrintOperationPreview, PrintOperationPreviewIF)(preview), ObjectG.getDObject!(PrintContext)(context), ObjectG.getDObject!(Window)(parent), _printoperation) ) 1096 { 1097 return 1; 1098 } 1099 } 1100 1101 return 0; 1102 } 1103 1104 void delegate(PrintContext, int, PageSetup, PrintOperation)[] onRequestPageSetupListeners; 1105 /** 1106 * Emitted once for every page that is printed, to give 1107 * the application a chance to modify the page setup. Any changes 1108 * done to @setup will be in force only for printing this page. 1109 * 1110 * Params: 1111 * context = the #GtkPrintContext for the current operation 1112 * pageNr = the number of the currently printed page (0-based) 1113 * setup = the #GtkPageSetup 1114 * 1115 * Since: 2.10 1116 */ 1117 void addOnRequestPageSetup(void delegate(PrintContext, int, PageSetup, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1118 { 1119 if ( "request-page-setup" !in connectedSignals ) 1120 { 1121 Signals.connectData( 1122 this, 1123 "request-page-setup", 1124 cast(GCallback)&callBackRequestPageSetup, 1125 cast(void*)this, 1126 null, 1127 connectFlags); 1128 connectedSignals["request-page-setup"] = 1; 1129 } 1130 onRequestPageSetupListeners ~= dlg; 1131 } 1132 extern(C) static void callBackRequestPageSetup(GtkPrintOperation* printoperationStruct, GtkPrintContext* context, int pageNr, GtkPageSetup* setup, PrintOperation _printoperation) 1133 { 1134 foreach ( void delegate(PrintContext, int, PageSetup, PrintOperation) dlg; _printoperation.onRequestPageSetupListeners ) 1135 { 1136 dlg(ObjectG.getDObject!(PrintContext)(context), pageNr, ObjectG.getDObject!(PageSetup)(setup), _printoperation); 1137 } 1138 } 1139 1140 void delegate(PrintOperation)[] onStatusChangedListeners; 1141 /** 1142 * Emitted at between the various phases of the print operation. 1143 * See #GtkPrintStatus for the phases that are being discriminated. 1144 * Use gtk_print_operation_get_status() to find out the current 1145 * status. 1146 * 1147 * Since: 2.10 1148 */ 1149 void addOnStatusChanged(void delegate(PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1150 { 1151 if ( "status-changed" !in connectedSignals ) 1152 { 1153 Signals.connectData( 1154 this, 1155 "status-changed", 1156 cast(GCallback)&callBackStatusChanged, 1157 cast(void*)this, 1158 null, 1159 connectFlags); 1160 connectedSignals["status-changed"] = 1; 1161 } 1162 onStatusChangedListeners ~= dlg; 1163 } 1164 extern(C) static void callBackStatusChanged(GtkPrintOperation* printoperationStruct, PrintOperation _printoperation) 1165 { 1166 foreach ( void delegate(PrintOperation) dlg; _printoperation.onStatusChangedListeners ) 1167 { 1168 dlg(_printoperation); 1169 } 1170 } 1171 1172 void delegate(Widget, PageSetup, PrintSettings, PrintOperation)[] onUpdateCustomWidgetListeners; 1173 /** 1174 * Emitted after change of selected printer. The actual page setup and 1175 * print settings are passed to the custom widget, which can actualize 1176 * itself according to this change. 1177 * 1178 * Params: 1179 * widget = the custom widget added in create-custom-widget 1180 * setup = actual page setup 1181 * settings = actual print settings 1182 * 1183 * Since: 2.18 1184 */ 1185 void addOnUpdateCustomWidget(void delegate(Widget, PageSetup, PrintSettings, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1186 { 1187 if ( "update-custom-widget" !in connectedSignals ) 1188 { 1189 Signals.connectData( 1190 this, 1191 "update-custom-widget", 1192 cast(GCallback)&callBackUpdateCustomWidget, 1193 cast(void*)this, 1194 null, 1195 connectFlags); 1196 connectedSignals["update-custom-widget"] = 1; 1197 } 1198 onUpdateCustomWidgetListeners ~= dlg; 1199 } 1200 extern(C) static void callBackUpdateCustomWidget(GtkPrintOperation* printoperationStruct, GtkWidget* widget, GtkPageSetup* setup, GtkPrintSettings* settings, PrintOperation _printoperation) 1201 { 1202 foreach ( void delegate(Widget, PageSetup, PrintSettings, PrintOperation) dlg; _printoperation.onUpdateCustomWidgetListeners ) 1203 { 1204 dlg(ObjectG.getDObject!(Widget)(widget), ObjectG.getDObject!(PageSetup)(setup), ObjectG.getDObject!(PrintSettings)(settings), _printoperation); 1205 } 1206 } 1207 1208 /** 1209 * Runs a page setup dialog, letting the user modify the values from 1210 * @page_setup. If the user cancels the dialog, the returned #GtkPageSetup 1211 * is identical to the passed in @page_setup, otherwise it contains the 1212 * modifications done in the dialog. 1213 * 1214 * Note that this function may use a recursive mainloop to show the page 1215 * setup dialog. See gtk_print_run_page_setup_dialog_async() if this is 1216 * a problem. 1217 * 1218 * Params: 1219 * parent = transient parent 1220 * pageSetup = an existing #GtkPageSetup 1221 * settings = a #GtkPrintSettings 1222 * 1223 * Return: a new #GtkPageSetup 1224 * 1225 * Since: 2.10 1226 */ 1227 public static PageSetup printRunPageSetupDialog(Window parent, PageSetup pageSetup, PrintSettings settings) 1228 { 1229 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()); 1230 1231 if(p is null) 1232 { 1233 return null; 1234 } 1235 1236 return ObjectG.getDObject!(PageSetup)(cast(GtkPageSetup*) p, true); 1237 } 1238 1239 /** 1240 * Runs a page setup dialog, letting the user modify the values from @page_setup. 1241 * 1242 * In contrast to gtk_print_run_page_setup_dialog(), this function returns after 1243 * showing the page setup dialog on platforms that support this, and calls @done_cb 1244 * from a signal handler for the ::response signal of the dialog. 1245 * 1246 * Params: 1247 * parent = transient parent, or %NULL 1248 * pageSetup = an existing #GtkPageSetup, or %NULL 1249 * settings = a #GtkPrintSettings 1250 * doneCb = a function to call when the user saves 1251 * the modified page setup 1252 * data = user data to pass to @done_cb 1253 * 1254 * Since: 2.10 1255 */ 1256 public static void printRunPageSetupDialogAsync(Window parent, PageSetup pageSetup, PrintSettings settings, GtkPageSetupDoneFunc doneCb, void* data) 1257 { 1258 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); 1259 } 1260 }