use crate::{WebPage, ffi};
use glib::{
object::ObjectType as _,
prelude::*,
signal::{SignalHandlerId, connect_raw},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "WebKitWebEditor")]
pub struct WebEditor(Object<ffi::WebKitWebEditor, ffi::WebKitWebEditorClass>);
match fn {
type_ => || ffi::webkit_web_editor_get_type(),
}
}
impl WebEditor {
#[doc(alias = "webkit_web_editor_get_page")]
#[doc(alias = "get_page")]
pub fn page(&self) -> Option<WebPage> {
unsafe { from_glib_none(ffi::webkit_web_editor_get_page(self.to_glib_none().0)) }
}
#[doc(alias = "selection-changed")]
pub fn connect_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn selection_changed_trampoline<F: Fn(&WebEditor) + 'static>(
this: *mut ffi::WebKitWebEditor,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"selection-changed".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
selection_changed_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}