gnome.pages.gitlab.gnome.org

Gtk.PrintOperation

Class

GtkPrintOperation

Description [src]

class Gtk.PrintOperation : GObject.Object
  implements Gtk.PrintOperationPreview {
  /* No available fields */
}

High-level, portable printing API.

It looks a bit different than other GTK dialogs such as the GtkFileChooser, since some platforms don’t expose enough infrastructure to implement a good print dialog. On such platforms, GtkPrintOperation uses the native print dialog. On platforms which do not provide a native print dialog, GTK uses its own, see GtkPrintUnixDialog.

The typical way to use the high-level printing API is to create a GtkPrintOperation object with gtk_print_operation_new() when the user selects to print. Then you set some properties on it, e.g. the page size, any GtkPrintSettings from previous print operations, the number of pages, the current page, etc.

Then you start the print operation by calling gtk_print_operation_run(). It will then show a dialog, let the user select a printer and options. When the user finished the dialog, various signals will be emitted on the GtkPrintOperation, the main one being GtkPrintOperation::draw-page, which you are supposed to handle and render the page on the provided GtkPrintContext using Cairo.

The high-level printing API

static GtkPrintSettings *settings = NULL;
static void
do_print (void)
{
  GtkPrintOperation *print;
  GtkPrintOperationResult res;
  print = gtk_print_operation_new ();
  if (settings != NULL)
    gtk_print_operation_set_print_settings (print, settings);
  g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), NULL);
  g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL);
  res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                 GTK_WINDOW (main_window), NULL);
  if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
    {
      if (settings != NULL)
        g_object_unref (settings);
      settings = g_object_ref (gtk_print_operation_get_print_settings (print));
    }
  g_object_unref (print);
}

By default GtkPrintOperation uses an external application to do print preview. To implement a custom print preview, an application must connect to the preview signal. The functions gtk_print_operation_preview_render_page(), gtk_print_operation_preview_end_preview() and gtk_print_operation_preview_is_selected() are useful when implementing a print preview.

Constructors

Instance methods

gtk_print_operation_set_unit

Sets up the transformation for the cairo context obtained from GtkPrintContext in such a way that distances are measured in units of unit.

Methods inherited from GObject (43)

Please see GObject for a full list of methods.

Properties

Gtk.PrintOperation:unit

The transformation for the cairo context obtained from GtkPrintContext is set up in such a way that distances are measured in units of unit.

Gtk.PrintOperation:use-full-page

If TRUE, the transformation for the cairo context obtained from GtkPrintContext puts the origin at the top left corner of the page.

Signals

Signals inherited from GObject (1)
GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

Class structure

struct GtkPrintOperationClass {
  GObjectClass parent_class;
  void (* done) (
    GtkPrintOperation* operation,
    GtkPrintOperationResult result
  );
  void (* begin_print) (
    GtkPrintOperation* operation,
    GtkPrintContext* context
  );
  gboolean (* paginate) (
    GtkPrintOperation* operation,
    GtkPrintContext* context
  );
  void (* request_page_setup) (
    GtkPrintOperation* operation,
    GtkPrintContext* context,
    int page_nr,
    GtkPageSetup* setup
  );
  void (* draw_page) (
    GtkPrintOperation* operation,
    GtkPrintContext* context,
    int page_nr
  );
  void (* end_print) (
    GtkPrintOperation* operation,
    GtkPrintContext* context
  );
  void (* status_changed) (
    GtkPrintOperation* operation
  );
  GtkWidget* (* create_custom_widget) (
    GtkPrintOperation* operation
  );
  void (* custom_widget_apply) (
    GtkPrintOperation* operation,
    GtkWidget* widget
  );
  gboolean (* preview) (
    GtkPrintOperation* operation,
    GtkPrintOperationPreview* preview,
    GtkPrintContext* context,
    GtkWindow* parent
  );
  void (* update_custom_widget) (
    GtkPrintOperation* operation,
    GtkWidget* widget,
    GtkPageSetup* setup,
    GtkPrintSettings* settings
  );
}

No description available.

Class members
parent_class: GObjectClass

The parent class.

done: void (* done) ( GtkPrintOperation* operation, GtkPrintOperationResult result )

Signal emitted when the print operation run has finished doing everything required for printing.

begin_print: void (* begin_print) ( GtkPrintOperation* operation, GtkPrintContext* context )

Signal emitted after the user has finished changing print settings in the dialog, before the actual rendering starts.

paginate: gboolean (* paginate) ( GtkPrintOperation* operation, GtkPrintContext* context )

Signal emitted after the “begin-print” signal, but before the actual rendering starts.

request_page_setup: void (* request_page_setup) ( GtkPrintOperation* operation, GtkPrintContext* context, int page_nr, GtkPageSetup* setup )

Emitted once for every page that is printed, to give the application a chance to modify the page setup.

draw_page: void (* draw_page) ( GtkPrintOperation* operation, GtkPrintContext* context, int page_nr )

Signal emitted for every page that is printed.

end_print: void (* end_print) ( GtkPrintOperation* operation, GtkPrintContext* context )

Signal emitted after all pages have been rendered.

status_changed: void (* status_changed) ( GtkPrintOperation* operation )

Emitted at between the various phases of the print operation.

create_custom_widget: GtkWidget* (* create_custom_widget) ( GtkPrintOperation* operation )

Signal emitted when displaying the print dialog.

custom_widget_apply: void (* custom_widget_apply) ( GtkPrintOperation* operation, GtkWidget* widget )

Signal emitted right before “begin-print” if you added a custom widget in the “create-custom-widget” handler.

preview: gboolean (* preview) ( GtkPrintOperation* operation, GtkPrintOperationPreview* preview, GtkPrintContext* context, GtkWindow* parent )

Signal emitted when a preview is requested from the native dialog.

update_custom_widget: void (* update_custom_widget) ( GtkPrintOperation* operation, GtkWidget* widget, GtkPageSetup* setup, GtkPrintSettings* settings )

Emitted after change of selected printer.

Virtual methods