gtk4/auto/print_operation_preview.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{ffi, PageSetup, PrintContext};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// [`PrintOperationPreview`][crate::PrintOperationPreview] is the interface that is used to
/// implement print preview.
///
/// A [`PrintOperationPreview`][crate::PrintOperationPreview] object is passed to the
/// [`preview`][struct@crate::PrintOperation#preview] signal by
/// [`PrintOperation`][crate::PrintOperation].
///
/// ## Signals
///
///
/// #### `got-page-size`
/// Emitted once for each page that gets rendered to the preview.
///
/// A handler for this signal should update the @context
/// according to @page_setup and set up a suitable cairo
/// context, using [`PrintContext::set_cairo_context()`][crate::PrintContext::set_cairo_context()].
///
///
///
///
/// #### `ready`
/// The ::ready signal gets emitted once per preview operation,
/// before the first page is rendered.
///
/// A handler for this signal can be used for setup tasks.
///
///
///
/// # Implements
///
/// [`PrintOperationPreviewExt`][trait@crate::prelude::PrintOperationPreviewExt]
#[doc(alias = "GtkPrintOperationPreview")]
pub struct PrintOperationPreview(Interface<ffi::GtkPrintOperationPreview, ffi::GtkPrintOperationPreviewIface>);
match fn {
type_ => || ffi::gtk_print_operation_preview_get_type(),
}
}
impl PrintOperationPreview {
pub const NONE: Option<&'static PrintOperationPreview> = None;
}
/// Trait containing all [`struct@PrintOperationPreview`] methods.
///
/// # Implementors
///
/// [`PrintOperationPreview`][struct@crate::PrintOperationPreview], [`PrintOperation`][struct@crate::PrintOperation]
pub trait PrintOperationPreviewExt: IsA<PrintOperationPreview> + 'static {
/// Ends a preview.
///
/// This function must be called to finish a custom print preview.
#[doc(alias = "gtk_print_operation_preview_end_preview")]
fn end_preview(&self) {
unsafe {
ffi::gtk_print_operation_preview_end_preview(self.as_ref().to_glib_none().0);
}
}
/// Returns whether the given page is included in the set of pages that
/// have been selected for printing.
/// ## `page_nr`
/// a page number
///
/// # Returns
///
/// [`true`] if the page has been selected for printing
#[doc(alias = "gtk_print_operation_preview_is_selected")]
fn is_selected(&self, page_nr: i32) -> bool {
unsafe {
from_glib(ffi::gtk_print_operation_preview_is_selected(
self.as_ref().to_glib_none().0,
page_nr,
))
}
}
/// Renders a page to the preview.
///
/// This is using the print context that was passed to the
/// [`preview`][struct@crate::PrintOperation#preview] handler together
/// with @self.
///
/// A custom print preview should use this function to render
/// the currently selected page.
///
/// Note that this function requires a suitable cairo context to
/// be associated with the print context.
/// ## `page_nr`
/// the page to render
#[doc(alias = "gtk_print_operation_preview_render_page")]
fn render_page(&self, page_nr: i32) {
unsafe {
ffi::gtk_print_operation_preview_render_page(self.as_ref().to_glib_none().0, page_nr);
}
}
/// Emitted once for each page that gets rendered to the preview.
///
/// A handler for this signal should update the @context
/// according to @page_setup and set up a suitable cairo
/// context, using [`PrintContext::set_cairo_context()`][crate::PrintContext::set_cairo_context()].
/// ## `context`
/// the current [`PrintContext`][crate::PrintContext]
/// ## `page_setup`
/// the [`PageSetup`][crate::PageSetup] for the current page
#[doc(alias = "got-page-size")]
fn connect_got_page_size<F: Fn(&Self, &PrintContext, &PageSetup) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn got_page_size_trampoline<
P: IsA<PrintOperationPreview>,
F: Fn(&P, &PrintContext, &PageSetup) + 'static,
>(
this: *mut ffi::GtkPrintOperationPreview,
context: *mut ffi::GtkPrintContext,
page_setup: *mut ffi::GtkPageSetup,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
PrintOperationPreview::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(context),
&from_glib_borrow(page_setup),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"got-page-size\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
got_page_size_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
/// The ::ready signal gets emitted once per preview operation,
/// before the first page is rendered.
///
/// A handler for this signal can be used for setup tasks.
/// ## `context`
/// the current [`PrintContext`][crate::PrintContext]
#[doc(alias = "ready")]
fn connect_ready<F: Fn(&Self, &PrintContext) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn ready_trampoline<
P: IsA<PrintOperationPreview>,
F: Fn(&P, &PrintContext) + 'static,
>(
this: *mut ffi::GtkPrintOperationPreview,
context: *mut ffi::GtkPrintContext,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
PrintOperationPreview::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(context),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"ready\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
ready_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<PrintOperationPreview>> PrintOperationPreviewExt for O {}