gtk4/auto/
entry_buffer.rs
1use crate::ffi;
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkEntryBuffer")]
66 pub struct EntryBuffer(Object<ffi::GtkEntryBuffer, ffi::GtkEntryBufferClass>);
67
68 match fn {
69 type_ => || ffi::gtk_entry_buffer_get_type(),
70 }
71}
72
73impl EntryBuffer {
74 pub const NONE: Option<&'static EntryBuffer> = None;
75
76 pub fn builder() -> EntryBufferBuilder {
81 EntryBufferBuilder::new()
82 }
83}
84
85#[must_use = "The builder must be built to be used"]
90pub struct EntryBufferBuilder {
91 builder: glib::object::ObjectBuilder<'static, EntryBuffer>,
92}
93
94impl EntryBufferBuilder {
95 fn new() -> Self {
96 Self {
97 builder: glib::object::Object::builder(),
98 }
99 }
100
101 pub fn max_length(self, max_length: i32) -> Self {
103 Self {
104 builder: self.builder.property("max-length", max_length),
105 }
106 }
107
108 pub fn text(self, text: impl Into<glib::GString>) -> Self {
110 Self {
111 builder: self.builder.property("text", text.into()),
112 }
113 }
114
115 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
118 pub fn build(self) -> EntryBuffer {
119 assert_initialized_main_thread!();
120 self.builder.build()
121 }
122}
123
124mod sealed {
125 pub trait Sealed {}
126 impl<T: super::IsA<super::EntryBuffer>> Sealed for T {}
127}
128
129pub trait EntryBufferExt: IsA<EntryBuffer> + sealed::Sealed + 'static {
135 #[doc(alias = "gtk_entry_buffer_emit_deleted_text")]
141 fn emit_deleted_text(&self, position: u32, n_chars: u32) {
142 unsafe {
143 ffi::gtk_entry_buffer_emit_deleted_text(
144 self.as_ref().to_glib_none().0,
145 position,
146 n_chars,
147 );
148 }
149 }
150
151 #[doc(alias = "gtk_entry_buffer_emit_inserted_text")]
159 fn emit_inserted_text(&self, position: u32, chars: &str, n_chars: u32) {
160 unsafe {
161 ffi::gtk_entry_buffer_emit_inserted_text(
162 self.as_ref().to_glib_none().0,
163 position,
164 chars.to_glib_none().0,
165 n_chars,
166 );
167 }
168 }
169
170 #[doc(alias = "length")]
171 fn connect_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
172 unsafe extern "C" fn notify_length_trampoline<P: IsA<EntryBuffer>, F: Fn(&P) + 'static>(
173 this: *mut ffi::GtkEntryBuffer,
174 _param_spec: glib::ffi::gpointer,
175 f: glib::ffi::gpointer,
176 ) {
177 let f: &F = &*(f as *const F);
178 f(EntryBuffer::from_glib_borrow(this).unsafe_cast_ref())
179 }
180 unsafe {
181 let f: Box_<F> = Box_::new(f);
182 connect_raw(
183 self.as_ptr() as *mut _,
184 b"notify::length\0".as_ptr() as *const _,
185 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
186 notify_length_trampoline::<Self, F> as *const (),
187 )),
188 Box_::into_raw(f),
189 )
190 }
191 }
192
193 #[doc(alias = "max-length")]
194 fn connect_max_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
195 unsafe extern "C" fn notify_max_length_trampoline<
196 P: IsA<EntryBuffer>,
197 F: Fn(&P) + 'static,
198 >(
199 this: *mut ffi::GtkEntryBuffer,
200 _param_spec: glib::ffi::gpointer,
201 f: glib::ffi::gpointer,
202 ) {
203 let f: &F = &*(f as *const F);
204 f(EntryBuffer::from_glib_borrow(this).unsafe_cast_ref())
205 }
206 unsafe {
207 let f: Box_<F> = Box_::new(f);
208 connect_raw(
209 self.as_ptr() as *mut _,
210 b"notify::max-length\0".as_ptr() as *const _,
211 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
212 notify_max_length_trampoline::<Self, F> as *const (),
213 )),
214 Box_::into_raw(f),
215 )
216 }
217 }
218
219 #[doc(alias = "text")]
220 fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
221 unsafe extern "C" fn notify_text_trampoline<P: IsA<EntryBuffer>, F: Fn(&P) + 'static>(
222 this: *mut ffi::GtkEntryBuffer,
223 _param_spec: glib::ffi::gpointer,
224 f: glib::ffi::gpointer,
225 ) {
226 let f: &F = &*(f as *const F);
227 f(EntryBuffer::from_glib_borrow(this).unsafe_cast_ref())
228 }
229 unsafe {
230 let f: Box_<F> = Box_::new(f);
231 connect_raw(
232 self.as_ptr() as *mut _,
233 b"notify::text\0".as_ptr() as *const _,
234 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
235 notify_text_trampoline::<Self, F> as *const (),
236 )),
237 Box_::into_raw(f),
238 )
239 }
240 }
241}
242
243impl<O: IsA<EntryBuffer>> EntryBufferExt for O {}