use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
glib::wrapper! {
#[doc(alias = "WebKitPrintCustomWidget")]
pub struct PrintCustomWidget(Object<ffi::WebKitPrintCustomWidget, ffi::WebKitPrintCustomWidgetClass>);
match fn {
type_ => || ffi::webkit_print_custom_widget_get_type(),
}
}
impl PrintCustomWidget {
#[doc(alias = "webkit_print_custom_widget_new")]
pub fn new<P: IsA<gtk::Widget>>(widget: &P, title: &str) -> PrintCustomWidget {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::webkit_print_custom_widget_new(
widget.as_ref().to_glib_none().0,
title.to_glib_none().0,
))
}
}
pub fn builder() -> PrintCustomWidgetBuilder {
PrintCustomWidgetBuilder::default()
}
}
#[cfg(any(feature = "v2_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_16")))]
impl Default for PrintCustomWidget {
fn default() -> Self {
glib::object::Object::new::<Self>(&[])
.expect("Can't construct PrintCustomWidget object with default parameters")
}
}
#[derive(Clone, Default)]
pub struct PrintCustomWidgetBuilder {
#[cfg(any(feature = "v2_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_16")))]
title: Option<String>,
#[cfg(any(feature = "v2_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_16")))]
widget: Option<gtk::Widget>,
}
impl PrintCustomWidgetBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn build(self) -> PrintCustomWidget {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
#[cfg(any(feature = "v2_16", feature = "dox"))]
if let Some(ref title) = self.title {
properties.push(("title", title));
}
#[cfg(any(feature = "v2_16", feature = "dox"))]
if let Some(ref widget) = self.widget {
properties.push(("widget", widget));
}
glib::Object::new::<PrintCustomWidget>(&properties)
.expect("Failed to create an instance of PrintCustomWidget")
}
#[cfg(any(feature = "v2_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_16")))]
pub fn title(mut self, title: &str) -> Self {
self.title = Some(title.to_string());
self
}
#[cfg(any(feature = "v2_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_16")))]
pub fn widget<P: IsA<gtk::Widget>>(mut self, widget: &P) -> Self {
self.widget = Some(widget.clone().upcast());
self
}
}
pub const NONE_PRINT_CUSTOM_WIDGET: Option<&PrintCustomWidget> = None;
pub trait PrintCustomWidgetExt: 'static {
#[doc(alias = "webkit_print_custom_widget_get_title")]
#[doc(alias = "get_title")]
fn title(&self) -> Option<glib::GString>;
#[doc(alias = "webkit_print_custom_widget_get_widget")]
#[doc(alias = "get_widget")]
fn widget(&self) -> Option<gtk::Widget>;
#[cfg(any(feature = "v2_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_16")))]
#[doc(alias = "apply")]
fn connect_apply<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[cfg(any(feature = "v2_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_16")))]
#[doc(alias = "update")]
fn connect_update<F: Fn(&Self, >k::PageSetup, >k::PrintSettings) + 'static>(
&self,
f: F,
) -> SignalHandlerId;
}
impl<O: IsA<PrintCustomWidget>> PrintCustomWidgetExt for O {
fn title(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::webkit_print_custom_widget_get_title(
self.as_ref().to_glib_none().0,
))
}
}
fn widget(&self) -> Option<gtk::Widget> {
unsafe {
from_glib_none(ffi::webkit_print_custom_widget_get_widget(
self.as_ref().to_glib_none().0,
))
}
}
#[cfg(any(feature = "v2_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_16")))]
fn connect_apply<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn apply_trampoline<P: IsA<PrintCustomWidget>, F: Fn(&P) + 'static>(
this: *mut ffi::WebKitPrintCustomWidget,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(PrintCustomWidget::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"apply\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
apply_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(any(feature = "v2_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_16")))]
fn connect_update<F: Fn(&Self, >k::PageSetup, >k::PrintSettings) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn update_trampoline<
P: IsA<PrintCustomWidget>,
F: Fn(&P, >k::PageSetup, >k::PrintSettings) + 'static,
>(
this: *mut ffi::WebKitPrintCustomWidget,
page_setup: *mut gtk::ffi::GtkPageSetup,
print_settings: *mut gtk::ffi::GtkPrintSettings,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
PrintCustomWidget::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(page_setup),
&from_glib_borrow(print_settings),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"update\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
update_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for PrintCustomWidget {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("PrintCustomWidget")
}
}