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::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// A [`EntryBuffer`][crate::EntryBuffer] hold the text displayed in a [`Text`][crate::Text] widget.
15    ///
16    /// A single [`EntryBuffer`][crate::EntryBuffer] object can be shared by multiple widgets
17    /// which will then share the same text content, but not the cursor
18    /// position, visibility attributes, icon etc.
19    ///
20    /// [`EntryBuffer`][crate::EntryBuffer] may be derived from. Such a derived class might allow
21    /// text to be stored in an alternate location, such as non-pageable memory,
22    /// useful in the case of important passwords. Or a derived class could
23    /// integrate with an application’s concept of undo/redo.
24    ///
25    /// ## Properties
26    ///
27    ///
28    /// #### `length`
29    ///  The length (in characters) of the text in buffer.
30    ///
31    /// Readable
32    ///
33    ///
34    /// #### `max-length`
35    ///  The maximum length (in characters) of the text in the buffer.
36    ///
37    /// Readable | Writeable
38    ///
39    ///
40    /// #### `text`
41    ///  The contents of the buffer.
42    ///
43    /// Readable | Writeable
44    ///
45    /// ## Signals
46    ///
47    ///
48    /// #### `deleted-text`
49    ///  The text is altered in the default handler for this signal.
50    ///
51    /// If you want access to the text after the text has been modified,
52    /// use `G_CONNECT_AFTER`.
53    ///
54    ///
55    ///
56    ///
57    /// #### `inserted-text`
58    ///  This signal is emitted after text is inserted into the buffer.
59    ///
60    ///
61    ///
62    /// # Implements
63    ///
64    /// [`EntryBufferExt`][trait@crate::prelude::EntryBufferExt], [`trait@glib::ObjectExt`], [`EntryBufferExtManual`][trait@crate::prelude::EntryBufferExtManual]
65    #[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    // rustdoc-stripper-ignore-next
77    /// Creates a new builder-pattern struct instance to construct [`EntryBuffer`] objects.
78    ///
79    /// This method returns an instance of [`EntryBufferBuilder`](crate::builders::EntryBufferBuilder) which can be used to create [`EntryBuffer`] objects.
80    pub fn builder() -> EntryBufferBuilder {
81        EntryBufferBuilder::new()
82    }
83}
84
85// rustdoc-stripper-ignore-next
86/// A [builder-pattern] type to construct [`EntryBuffer`] objects.
87///
88/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
89#[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    /// The maximum length (in characters) of the text in the buffer.
102    pub fn max_length(self, max_length: i32) -> Self {
103        Self {
104            builder: self.builder.property("max-length", max_length),
105        }
106    }
107
108    /// The contents of the buffer.
109    pub fn text(self, text: impl Into<glib::GString>) -> Self {
110        Self {
111            builder: self.builder.property("text", text.into()),
112        }
113    }
114
115    // rustdoc-stripper-ignore-next
116    /// Build the [`EntryBuffer`].
117    #[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
129/// Trait containing all [`struct@EntryBuffer`] methods.
130///
131/// # Implementors
132///
133/// [`EntryBuffer`][struct@crate::EntryBuffer], [`PasswordEntryBuffer`][struct@crate::PasswordEntryBuffer]
134pub trait EntryBufferExt: IsA<EntryBuffer> + sealed::Sealed + 'static {
135    /// Used when subclassing [`EntryBuffer`][crate::EntryBuffer].
136    /// ## `position`
137    /// position at which text was deleted
138    /// ## `n_chars`
139    /// number of characters deleted
140    #[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    /// Used when subclassing [`EntryBuffer`][crate::EntryBuffer].
152    /// ## `position`
153    /// position at which text was inserted
154    /// ## `chars`
155    /// text that was inserted
156    /// ## `n_chars`
157    /// number of characters inserted
158    #[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 {}