Skip to main content

gtk4/auto/
entry_buffer.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// s concept of undo/redo.
15    ///
16    /// ## Properties
17    ///
18    ///
19    /// #### `length`
20    ///  The length (in characters) of the text in buffer.
21    ///
22    /// Readable
23    ///
24    ///
25    /// #### `max-length`
26    ///  The maximum length (in characters) of the text in the buffer.
27    ///
28    /// Readable | Writable
29    ///
30    ///
31    /// #### `text`
32    ///  The contents of the buffer.
33    ///
34    /// Readable | Writable
35    ///
36    /// ## Signals
37    ///
38    ///
39    /// #### `deleted-text`
40    ///  The text is altered in the default handler for this signal.
41    ///
42    /// If you want access to the text after the text has been modified,
43    /// use `G_CONNECT_AFTER`.
44    ///
45    ///
46    ///
47    ///
48    /// #### `inserted-text`
49    ///  This signal is emitted after text is inserted into the buffer.
50    ///
51    ///
52    ///
53    /// # Implements
54    ///
55    /// [`EntryBufferExt`][trait@crate::prelude::EntryBufferExt], [`trait@glib::ObjectExt`], [`EntryBufferExtManual`][trait@crate::prelude::EntryBufferExtManual]
56    #[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    // rustdoc-stripper-ignore-next
68    /// Creates a new builder-pattern struct instance to construct [`EntryBuffer`] objects.
69    ///
70    /// This method returns an instance of [`EntryBufferBuilder`](crate::builders::EntryBufferBuilder) which can be used to create [`EntryBuffer`] objects.
71    pub fn builder() -> EntryBufferBuilder {
72        EntryBufferBuilder::new()
73    }
74}
75
76// rustdoc-stripper-ignore-next
77/// A [builder-pattern] type to construct [`EntryBuffer`] objects.
78///
79/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
80#[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    /// The maximum length (in characters) of the text in the buffer.
93    pub fn max_length(self, max_length: i32) -> Self {
94        Self {
95            builder: self.builder.property("max-length", max_length),
96        }
97    }
98
99    /// The contents of the buffer.
100    pub fn text(self, text: impl Into<glib::GString>) -> Self {
101        Self {
102            builder: self.builder.property("text", text.into()),
103        }
104    }
105
106    // rustdoc-stripper-ignore-next
107    /// Build the [`EntryBuffer`].
108    #[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
115/// Trait containing all [`struct@EntryBuffer`] methods.
116///
117/// # Implementors
118///
119/// [`EntryBuffer`][struct@crate::EntryBuffer], [`PasswordEntryBuffer`][struct@crate::PasswordEntryBuffer]
120pub trait EntryBufferExt: IsA<EntryBuffer> + 'static {
121    /// Used when subclassing [`EntryBuffer`][crate::EntryBuffer].
122    /// ## `position`
123    /// position at which text was deleted
124    /// ## `n_chars`
125    /// number of characters deleted
126    #[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    /// Used when subclassing [`EntryBuffer`][crate::EntryBuffer].
138    /// ## `position`
139    /// position at which text was inserted
140    /// ## `chars`
141    /// text that was inserted
142    /// ## `n_chars`
143    /// number of characters inserted
144    #[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 {}