use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::{boxed::Box as Box_, fmt, mem::transmute};
glib::wrapper! {
#[doc(alias = "GtkEntryBuffer")]
pub struct EntryBuffer(Object<ffi::GtkEntryBuffer, ffi::GtkEntryBufferClass>);
match fn {
type_ => || ffi::gtk_entry_buffer_get_type(),
}
}
impl EntryBuffer {
pub const NONE: Option<&'static EntryBuffer> = None;
pub fn builder() -> EntryBufferBuilder {
EntryBufferBuilder::new()
}
}
#[must_use = "The builder must be built to be used"]
pub struct EntryBufferBuilder {
builder: glib::object::ObjectBuilder<'static, EntryBuffer>,
}
impl EntryBufferBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
pub fn max_length(self, max_length: i32) -> Self {
Self {
builder: self.builder.property("max-length", max_length),
}
}
pub fn text(self, text: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("text", text.into()),
}
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> EntryBuffer {
self.builder.build()
}
}
pub trait EntryBufferExt: 'static {
#[doc(alias = "gtk_entry_buffer_emit_deleted_text")]
fn emit_deleted_text(&self, position: u32, n_chars: u32);
#[doc(alias = "gtk_entry_buffer_emit_inserted_text")]
fn emit_inserted_text(&self, position: u32, chars: &str, n_chars: u32);
#[doc(alias = "length")]
fn connect_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[doc(alias = "max-length")]
fn connect_max_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[doc(alias = "text")]
fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<EntryBuffer>> EntryBufferExt for O {
fn emit_deleted_text(&self, position: u32, n_chars: u32) {
unsafe {
ffi::gtk_entry_buffer_emit_deleted_text(
self.as_ref().to_glib_none().0,
position,
n_chars,
);
}
}
fn emit_inserted_text(&self, position: u32, chars: &str, n_chars: u32) {
unsafe {
ffi::gtk_entry_buffer_emit_inserted_text(
self.as_ref().to_glib_none().0,
position,
chars.to_glib_none().0,
n_chars,
);
}
}
fn connect_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_length_trampoline<P: IsA<EntryBuffer>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkEntryBuffer,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(EntryBuffer::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::length\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_length_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_max_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_max_length_trampoline<
P: IsA<EntryBuffer>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkEntryBuffer,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(EntryBuffer::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::max-length\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_max_length_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_text_trampoline<P: IsA<EntryBuffer>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkEntryBuffer,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(EntryBuffer::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::text\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_text_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for EntryBuffer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("EntryBuffer")
}
}