webkit2gtk 1.1.1

Rust bindings for webkit-gtk library
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/tauri-apps/gir-files)
// DO NOT EDIT

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 {
  pub const NONE: Option<&'static PrintCustomWidget> = None;

  #[cfg_attr(feature = "v2_40", deprecated = "Since 2.40")]
  #[doc(alias = "webkit_print_custom_widget_new")]
  pub fn new(widget: &impl IsA<gtk::Widget>, 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,
      ))
    }
  }

  // rustdoc-stripper-ignore-next
  /// Creates a new builder-pattern struct instance to construct [`PrintCustomWidget`] objects.
  ///
  /// This method returns an instance of [`PrintCustomWidgetBuilder`](crate::builders::PrintCustomWidgetBuilder) which can be used to create [`PrintCustomWidget`] objects.
  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>(&[])
  }
}

#[derive(Clone, Default)]
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`PrintCustomWidget`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct PrintCustomWidgetBuilder {
  #[cfg(any(feature = "v2_16", feature = "dox"))]
  #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_16")))]
  #[cfg_attr(feature = "v2_40", deprecated = "Since 2.40")]
  title: Option<String>,
  #[cfg(any(feature = "v2_16", feature = "dox"))]
  #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_16")))]
  #[cfg_attr(feature = "v2_40", deprecated = "Since 2.40")]
  widget: Option<gtk::Widget>,
}

impl PrintCustomWidgetBuilder {
  // rustdoc-stripper-ignore-next
  /// Create a new [`PrintCustomWidgetBuilder`].
  pub fn new() -> Self {
    Self::default()
  }

  // rustdoc-stripper-ignore-next
  /// Build the [`PrintCustomWidget`].
  #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
  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)
  }

  #[cfg(any(feature = "v2_16", feature = "dox"))]
  #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_16")))]
  #[cfg_attr(feature = "v2_40", deprecated = "Since 2.40")]
  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")))]
  #[cfg_attr(feature = "v2_40", deprecated = "Since 2.40")]
  pub fn widget(mut self, widget: &impl IsA<gtk::Widget>) -> Self {
    self.widget = Some(widget.clone().upcast());
    self
  }
}

pub trait PrintCustomWidgetExt: 'static {
  #[cfg_attr(feature = "v2_40", deprecated = "Since 2.40")]
  #[doc(alias = "webkit_print_custom_widget_get_title")]
  #[doc(alias = "get_title")]
  fn title(&self) -> Option<glib::GString>;

  #[cfg_attr(feature = "v2_40", deprecated = "Since 2.40")]
  #[doc(alias = "webkit_print_custom_widget_get_widget")]
  #[doc(alias = "get_widget")]
  fn widget(&self) -> Option<gtk::Widget>;

  #[cfg_attr(feature = "v2_40", deprecated = "Since 2.40")]
  #[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_attr(feature = "v2_40", deprecated = "Since 2.40")]
  #[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, &gtk::PageSetup, &gtk::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, &gtk::PageSetup, &gtk::PrintSettings) + 'static>(
    &self,
    f: F,
  ) -> SignalHandlerId {
    unsafe extern "C" fn update_trampoline<
      P: IsA<PrintCustomWidget>,
      F: Fn(&P, &gtk::PageSetup, &gtk::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")
  }
}