Hoogle Search
Within LTS Haskell 24.38 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
module GI.Gtk.Objects.
PrintOperation GtkPrintOperation is the high-level, portable printing API. It looks a bit different than other GTK+ dialogs such as the FileChooser, 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 printOperationNew when the user selects to print. Then you set some properties on it, e.g. the page size, any PrintSettings from previous print operations, the number of pages, the current page, etc. Then you start the print operation by calling printOperationRun. 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 PrintOperation, the main one being PrintOperation::drawPage, which you are supposed to catch and render the page on the provided PrintContext using Cairo.
The high-level printing API
C code
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 printOperationPreviewRenderPage, printOperationPreviewEndPreview and printOperationPreviewIsSelected are useful when implementing a print preview.-
gi-gtk3 GI.Gtk.Objects.PrintOperation Memory-managed wrapper type.
PrintOperation :: ManagedPtr PrintOperation -> PrintOperationgi-gtk3 GI.Gtk.Objects.PrintOperation No documentation available.
type
PrintOperationBeginPrintCallback = PrintContext -> IO ()gi-gtk3 GI.Gtk.Objects.PrintOperation Emitted after the user has finished changing print settings in the dialog, before the actual rendering starts. A typical use for beginPrint is to use the parameters from the PrintContext and paginate the document accordingly, and then set the number of pages with printOperationSetNPages. Since: 2.10
type
PrintOperationCreateCustomWidgetCallback = IO Objectgi-gtk3 GI.Gtk.Objects.PrintOperation Emitted when displaying the print dialog. If you return a widget in a handler for this signal it will be added to a custom tab in the print dialog. You typically return a container widget with multiple widgets in it. The print dialog owns the returned widget, and its lifetime is not controlled by the application. However, the widget is guaranteed to stay around until the PrintOperation::customWidgetApply signal is emitted on the operation. Then you can read out any information you need from the widgets. Since: 2.10
type
PrintOperationCustomWidgetApplyCallback = Widget -> IO ()gi-gtk3 GI.Gtk.Objects.PrintOperation Emitted right before PrintOperation::beginPrint if you added a custom widget in the PrintOperation::createCustomWidget handler. When you get this signal you should read the information from the custom widgets, as the widgets are not guaraneed to be around at a later time. Since: 2.10
type
PrintOperationDoneCallback = PrintOperationResult -> IO ()gi-gtk3 GI.Gtk.Objects.PrintOperation Emitted when the print operation run has finished doing everything required for printing. result gives you information about what happened during the run. If result is PrintOperationResultError then you can call printOperationGetError for more information. If you enabled print status tracking then printOperationIsFinished may still return False after PrintOperation::done was emitted. Since: 2.10
type
PrintOperationDrawPageCallback = PrintContext -> Int32 -> IO ()gi-gtk3 GI.Gtk.Objects.PrintOperation Emitted for every page that is printed. The signal handler must render the pageNr's page onto the cairo context obtained from context using printContextGetCairoContext.
C code
static void draw_page (GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data) { cairo_t *cr; PangoLayout *layout; gdouble width, text_height; gint layout_height; PangoFontDescription *desc; cr = gtk_print_context_get_cairo_context (context); width = gtk_print_context_get_width (context); cairo_rectangle (cr, 0, 0, width, HEADER_HEIGHT); cairo_set_source_rgb (cr, 0.8, 0.8, 0.8); cairo_fill (cr); layout = gtk_print_context_create_pango_layout (context); desc = pango_font_description_from_string ("sans 14"); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); pango_layout_set_text (layout, "some text", -1); pango_layout_set_width (layout, width * PANGO_SCALE); pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); pango_layout_get_size (layout, NULL, &layout_height); text_height = (gdouble)layout_height / PANGO_SCALE; cairo_move_to (cr, width / 2, (HEADER_HEIGHT - text_height) / 2); pango_cairo_show_layout (cr, layout); g_object_unref (layout); }Use printOperationSetUseFullPage and printOperationSetUnit before starting the print operation to set up the transformation of the cairo context according to your needs. Since: 2.10type
PrintOperationEndPrintCallback = PrintContext -> IO ()gi-gtk3 GI.Gtk.Objects.PrintOperation Emitted after all pages have been rendered. A handler for this signal can clean up any resources that have been allocated in the PrintOperation::beginPrint handler. Since: 2.10
type
PrintOperationPaginateCallback = PrintContext -> IO Boolgi-gtk3 GI.Gtk.Objects.PrintOperation Emitted after the PrintOperation::beginPrint signal, but before the actual rendering starts. It keeps getting emitted until a connected signal handler returns True. The paginate signal is intended to be used for paginating a document in small chunks, to avoid blocking the user interface for a long time. The signal handler should update the number of pages using printOperationSetNPages, and return True if the document has been completely paginated. If you don't need to do pagination in chunks, you can simply do it all in the beginPrint handler, and set the number of pages from there. Since: 2.10