PrintOperationRef

public struct PrintOperationRef : PrintOperationProtocol, GWeakCapturing

GtkPrintOperation is the 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 [classGtk.PrintUnixDialog].

The typical way to use the high-level printing API is to create a GtkPrintOperation object with [ctorGtk.PrintOperation.new] when the user selects to print. Then you set some properties on it, e.g. the page size, any [classGtk.PrintSettings] from previous print operations, the number of pages, the current page, etc.

Then you start the print operation by calling [methodGtk.PrintOperation.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 [signalGtk.PrintOperation::draw-page], which you are supposed to handle and render the page on the provided [classGtk.PrintContext] 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 [methodGtk.PrintOperationPreview.render_page], [methodGtk.PrintOperationPreview.end_preview] and [methodGtk.PrintOperationPreview.is_selected] are useful when implementing a print preview.

The PrintOperationRef type acts as a lightweight Swift reference to an underlying GtkPrintOperation instance. It exposes methods that can operate on this data type through PrintOperationProtocol conformance. Use PrintOperationRef only as an unowned reference to an existing GtkPrintOperation instance.

  • ptr
    Untyped pointer to the underlying `GtkPrintOperation` instance.
    

    For type-safe access, use the generated, typed pointer print_operation_ptr property instead.

    Declaration

    Swift

    public let ptr: UnsafeMutableRawPointer!

PrintOperation Class

  • Designated initialiser from the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafeMutablePointer<GtkPrintOperation>)
  • Designated initialiser from a constant pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafePointer<GtkPrintOperation>)
  • Conditional initialiser from an optional pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafeMutablePointer<GtkPrintOperation>?)
  • Conditional initialiser from an optional, non-mutable pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafePointer<GtkPrintOperation>?)
  • Conditional initialiser from an optional gpointer

    Declaration

    Swift

    @inlinable
    init!(gpointer g: gpointer?)
  • Conditional initialiser from an optional, non-mutable gconstpointer

    Declaration

    Swift

    @inlinable
    init!(gconstpointer g: gconstpointer?)
  • Reference intialiser for a related type that implements PrintOperationProtocol

    Declaration

    Swift

    @inlinable
    init<T>(_ other: T) where T : PrintOperationProtocol
  • This factory is syntactic sugar for setting weak pointers wrapped in GWeak<T>

    Declaration

    Swift

    @inlinable
    static func unowned<T>(_ other: T) -> PrintOperationRef where T : PrintOperationProtocol
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PrintOperationProtocol.

    Declaration

    Swift

    @inlinable
    init<T>(cPointer: UnsafeMutablePointer<T>)
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PrintOperationProtocol.

    Declaration

    Swift

    @inlinable
    init<T>(constPointer: UnsafePointer<T>)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PrintOperationProtocol.

    Declaration

    Swift

    @inlinable
    init(mutating raw: UnsafeRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PrintOperationProtocol.

    Declaration

    Swift

    @inlinable
    init(raw: UnsafeMutableRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to PrintOperationProtocol.

    Declaration

    Swift

    @inlinable
    init(opaquePointer: OpaquePointer)
  • Creates a new GtkPrintOperation.

    Declaration

    Swift

    @inlinable
    init()