gtk4/auto/
entry_buffer.rs1use crate::ffi;
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkEntryBuffer")]
57 pub struct EntryBuffer(Object<ffi::GtkEntryBuffer, ffi::GtkEntryBufferClass>);
58
59 match fn {
60 type_ => || ffi::gtk_entry_buffer_get_type(),
61 }
62}
63
64impl EntryBuffer {
65 pub const NONE: Option<&'static EntryBuffer> = None;
66
67 pub fn builder() -> EntryBufferBuilder {
72 EntryBufferBuilder::new()
73 }
74}
75
76#[must_use = "The builder must be built to be used"]
81pub struct EntryBufferBuilder {
82 builder: glib::object::ObjectBuilder<'static, EntryBuffer>,
83}
84
85impl EntryBufferBuilder {
86 fn new() -> Self {
87 Self {
88 builder: glib::object::Object::builder(),
89 }
90 }
91
92 pub fn max_length(self, max_length: i32) -> Self {
94 Self {
95 builder: self.builder.property("max-length", max_length),
96 }
97 }
98
99 pub fn text(self, text: impl Into<glib::GString>) -> Self {
101 Self {
102 builder: self.builder.property("text", text.into()),
103 }
104 }
105
106 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
109 pub fn build(self) -> EntryBuffer {
110 assert_initialized_main_thread!();
111 self.builder.build()
112 }
113}
114
115pub trait EntryBufferExt: IsA<EntryBuffer> + 'static {
121 #[doc(alias = "gtk_entry_buffer_emit_deleted_text")]
127 fn emit_deleted_text(&self, position: u32, n_chars: u32) {
128 unsafe {
129 ffi::gtk_entry_buffer_emit_deleted_text(
130 self.as_ref().to_glib_none().0,
131 position,
132 n_chars,
133 );
134 }
135 }
136
137 #[doc(alias = "gtk_entry_buffer_emit_inserted_text")]
145 fn emit_inserted_text(&self, position: u32, chars: &str, n_chars: u32) {
146 unsafe {
147 ffi::gtk_entry_buffer_emit_inserted_text(
148 self.as_ref().to_glib_none().0,
149 position,
150 chars.to_glib_none().0,
151 n_chars,
152 );
153 }
154 }
155
156 #[doc(alias = "length")]
157 fn connect_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
158 unsafe extern "C" fn notify_length_trampoline<P: IsA<EntryBuffer>, F: Fn(&P) + 'static>(
159 this: *mut ffi::GtkEntryBuffer,
160 _param_spec: glib::ffi::gpointer,
161 f: glib::ffi::gpointer,
162 ) {
163 unsafe {
164 let f: &F = &*(f as *const F);
165 f(EntryBuffer::from_glib_borrow(this).unsafe_cast_ref())
166 }
167 }
168 unsafe {
169 let f: Box_<F> = Box_::new(f);
170 connect_raw(
171 self.as_ptr() as *mut _,
172 c"notify::length".as_ptr(),
173 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
174 notify_length_trampoline::<Self, F> as *const (),
175 )),
176 Box_::into_raw(f),
177 )
178 }
179 }
180
181 #[doc(alias = "max-length")]
182 fn connect_max_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
183 unsafe extern "C" fn notify_max_length_trampoline<
184 P: IsA<EntryBuffer>,
185 F: Fn(&P) + 'static,
186 >(
187 this: *mut ffi::GtkEntryBuffer,
188 _param_spec: glib::ffi::gpointer,
189 f: glib::ffi::gpointer,
190 ) {
191 unsafe {
192 let f: &F = &*(f as *const F);
193 f(EntryBuffer::from_glib_borrow(this).unsafe_cast_ref())
194 }
195 }
196 unsafe {
197 let f: Box_<F> = Box_::new(f);
198 connect_raw(
199 self.as_ptr() as *mut _,
200 c"notify::max-length".as_ptr(),
201 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
202 notify_max_length_trampoline::<Self, F> as *const (),
203 )),
204 Box_::into_raw(f),
205 )
206 }
207 }
208
209 #[doc(alias = "text")]
210 fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
211 unsafe extern "C" fn notify_text_trampoline<P: IsA<EntryBuffer>, F: Fn(&P) + 'static>(
212 this: *mut ffi::GtkEntryBuffer,
213 _param_spec: glib::ffi::gpointer,
214 f: glib::ffi::gpointer,
215 ) {
216 unsafe {
217 let f: &F = &*(f as *const F);
218 f(EntryBuffer::from_glib_borrow(this).unsafe_cast_ref())
219 }
220 }
221 unsafe {
222 let f: Box_<F> = Box_::new(f);
223 connect_raw(
224 self.as_ptr() as *mut _,
225 c"notify::text".as_ptr(),
226 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
227 notify_text_trampoline::<Self, F> as *const (),
228 )),
229 Box_::into_raw(f),
230 )
231 }
232 }
233}
234
235impl<O: IsA<EntryBuffer>> EntryBufferExt for O {}