use crate::{WebView, ffi};
use glib::{
object::ObjectType as _,
prelude::*,
signal::{SignalHandlerId, connect_raw},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "WebKitFindController")]
pub struct FindController(Object<ffi::WebKitFindController, ffi::WebKitFindControllerClass>);
match fn {
type_ => || ffi::webkit_find_controller_get_type(),
}
}
impl FindController {
#[doc(alias = "webkit_find_controller_count_matches")]
pub fn count_matches(&self, search_text: &str, find_options: u32, max_match_count: u32) {
unsafe {
ffi::webkit_find_controller_count_matches(
self.to_glib_none().0,
search_text.to_glib_none().0,
find_options,
max_match_count,
);
}
}
#[doc(alias = "webkit_find_controller_get_max_match_count")]
#[doc(alias = "get_max_match_count")]
#[doc(alias = "max-match-count")]
pub fn max_match_count(&self) -> u32 {
unsafe { ffi::webkit_find_controller_get_max_match_count(self.to_glib_none().0) }
}
#[doc(alias = "webkit_find_controller_get_options")]
#[doc(alias = "get_options")]
pub fn options(&self) -> u32 {
unsafe { ffi::webkit_find_controller_get_options(self.to_glib_none().0) }
}
#[doc(alias = "webkit_find_controller_get_search_text")]
#[doc(alias = "get_search_text")]
pub fn search_text(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::webkit_find_controller_get_search_text(
self.to_glib_none().0,
))
}
}
#[doc(alias = "webkit_find_controller_get_web_view")]
#[doc(alias = "get_web_view")]
#[doc(alias = "web-view")]
pub fn web_view(&self) -> Option<WebView> {
unsafe {
from_glib_none(ffi::webkit_find_controller_get_web_view(
self.to_glib_none().0,
))
}
}
#[doc(alias = "webkit_find_controller_search")]
pub fn search(&self, search_text: &str, find_options: u32, max_match_count: u32) {
unsafe {
ffi::webkit_find_controller_search(
self.to_glib_none().0,
search_text.to_glib_none().0,
find_options,
max_match_count,
);
}
}
#[doc(alias = "webkit_find_controller_search_finish")]
pub fn search_finish(&self) {
unsafe {
ffi::webkit_find_controller_search_finish(self.to_glib_none().0);
}
}
#[doc(alias = "webkit_find_controller_search_next")]
pub fn search_next(&self) {
unsafe {
ffi::webkit_find_controller_search_next(self.to_glib_none().0);
}
}
#[doc(alias = "webkit_find_controller_search_previous")]
pub fn search_previous(&self) {
unsafe {
ffi::webkit_find_controller_search_previous(self.to_glib_none().0);
}
}
pub fn text(&self) -> Option<glib::GString> {
ObjectExt::property(self, "text")
}
#[doc(alias = "counted-matches")]
pub fn connect_counted_matches<F: Fn(&Self, u32) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn counted_matches_trampoline<F: Fn(&FindController, u32) + 'static>(
this: *mut ffi::WebKitFindController,
match_count: std::ffi::c_uint,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), match_count)
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"counted-matches".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
counted_matches_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "failed-to-find-text")]
pub fn connect_failed_to_find_text<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn failed_to_find_text_trampoline<F: Fn(&FindController) + 'static>(
this: *mut ffi::WebKitFindController,
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"failed-to-find-text".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
failed_to_find_text_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "found-text")]
pub fn connect_found_text<F: Fn(&Self, u32) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn found_text_trampoline<F: Fn(&FindController, u32) + 'static>(
this: *mut ffi::WebKitFindController,
match_count: std::ffi::c_uint,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), match_count)
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"found-text".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
found_text_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "max-match-count")]
pub fn connect_max_match_count_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_max_match_count_trampoline<F: Fn(&FindController) + 'static>(
this: *mut ffi::WebKitFindController,
_param_spec: glib::ffi::gpointer,
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"notify::max-match-count".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_max_match_count_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "options")]
pub fn connect_options_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_options_trampoline<F: Fn(&FindController) + 'static>(
this: *mut ffi::WebKitFindController,
_param_spec: glib::ffi::gpointer,
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"notify::options".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_options_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "text")]
pub fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_text_trampoline<F: Fn(&FindController) + 'static>(
this: *mut ffi::WebKitFindController,
_param_spec: glib::ffi::gpointer,
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"notify::text".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_text_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}