Skip to main content

gtk/auto/
editable.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::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// ;
10    ///
11    /// void
12    /// insert_text_handler (GtkEditable *editable,
13    ///  const gchar *text,
14    ///  gint length,
15    ///  gint *position,
16    ///  gpointer data)
17    /// {
18    ///  gchar *result = g_utf8_strup (text, length);
19    ///
20    ///  g_signal_handlers_block_by_func (editable,
21    ///  (gpointer) insert_text_handler, data);
22    ///  gtk_editable_insert_text (editable, result, length, position);
23    ///  g_signal_handlers_unblock_by_func (editable,
24    ///  (gpointer) insert_text_handler, data);
25    ///
26    ///  g_signal_stop_emission_by_name (editable, "insert_text");
27    ///
28    ///  g_free (result);
29    /// }
30    /// ]|
31    ///
32    /// ## Signals
33    ///
34    ///
35    /// #### `changed`
36    ///  The ::changed signal is emitted at the end of a single
37    /// user-visible operation on the contents of the [`Editable`][crate::Editable].
38    ///
39    /// E.g., a paste operation that replaces the contents of the
40    /// selection will cause only one signal emission (even though it
41    /// is implemented by first deleting the selection, then inserting
42    /// the new content, and may cause multiple ::notify::text signals
43    /// to be emitted).
44    ///
45    ///
46    ///
47    ///
48    /// #### `delete-text`
49    ///  This signal is emitted when text is deleted from
50    /// the widget by the user. The default handler for
51    /// this signal will normally be responsible for deleting
52    /// the text, so by connecting to this signal and then
53    /// stopping the signal with `g_signal_stop_emission()`, it
54    /// is possible to modify the range of deleted text, or
55    /// prevent it from being deleted entirely. The `start_pos`
56    /// and `end_pos` parameters are interpreted as for
57    /// [`EditableExt::delete_text()`][crate::prelude::EditableExt::delete_text()].
58    ///
59    ///
60    ///
61    ///
62    /// #### `insert-text`
63    ///  This signal is emitted when text is inserted into
64    /// the widget by the user. The default handler for
65    /// this signal will normally be responsible for inserting
66    /// the text, so by connecting to this signal and then
67    /// stopping the signal with `g_signal_stop_emission()`, it
68    /// is possible to modify the inserted text, or prevent
69    /// it from being inserted entirely.
70    ///
71    ///
72    ///
73    /// # Implements
74    ///
75    /// [`EditableExt`][trait@crate::prelude::EditableExt], [`EditableSignals`][trait@crate::prelude::EditableSignals]
76    #[doc(alias = "GtkEditable")]
77    pub struct Editable(Interface<ffi::GtkEditable, ffi::GtkEditableInterface>);
78
79    match fn {
80        type_ => || ffi::gtk_editable_get_type(),
81    }
82}
83
84impl Editable {
85    pub const NONE: Option<&'static Editable> = None;
86}
87
88/// Trait containing all [`struct@Editable`] methods.
89///
90/// # Implementors
91///
92/// [`Editable`][struct@crate::Editable], [`Entry`][struct@crate::Entry], [`SearchEntry`][struct@crate::SearchEntry], [`SpinButton`][struct@crate::SpinButton]
93pub trait EditableExt: IsA<Editable> + 'static {
94    /// Copies the contents of the currently selected content in the editable and
95    /// puts it on the clipboard.
96    #[doc(alias = "gtk_editable_copy_clipboard")]
97    fn copy_clipboard(&self) {
98        unsafe {
99            ffi::gtk_editable_copy_clipboard(self.as_ref().to_glib_none().0);
100        }
101    }
102
103    /// Removes the contents of the currently selected content in the editable and
104    /// puts it on the clipboard.
105    #[doc(alias = "gtk_editable_cut_clipboard")]
106    fn cut_clipboard(&self) {
107        unsafe {
108            ffi::gtk_editable_cut_clipboard(self.as_ref().to_glib_none().0);
109        }
110    }
111
112    /// Deletes the currently selected text of the editable.
113    /// This call doesn’t do anything if there is no selected text.
114    #[doc(alias = "gtk_editable_delete_selection")]
115    fn delete_selection(&self) {
116        unsafe {
117            ffi::gtk_editable_delete_selection(self.as_ref().to_glib_none().0);
118        }
119    }
120
121    /// Deletes a sequence of characters. The characters that are deleted are
122    /// those characters at positions from `start_pos` up to, but not including
123    /// `end_pos`. If `end_pos` is negative, then the characters deleted
124    /// are those from `start_pos` to the end of the text.
125    ///
126    /// Note that the positions are specified in characters, not bytes.
127    /// ## `start_pos`
128    /// start position
129    /// ## `end_pos`
130    /// end position
131    #[doc(alias = "gtk_editable_delete_text")]
132    fn delete_text(&self, start_pos: i32, end_pos: i32) {
133        unsafe {
134            ffi::gtk_editable_delete_text(self.as_ref().to_glib_none().0, start_pos, end_pos);
135        }
136    }
137
138    /// Retrieves a sequence of characters. The characters that are retrieved
139    /// are those characters at positions from `start_pos` up to, but not
140    /// including `end_pos`. If `end_pos` is negative, then the characters
141    /// retrieved are those characters from `start_pos` to the end of the text.
142    ///
143    /// Note that positions are specified in characters, not bytes.
144    /// ## `start_pos`
145    /// start of text
146    /// ## `end_pos`
147    /// end of text
148    ///
149    /// # Returns
150    ///
151    /// a pointer to the contents of the widget as a
152    ///  string. This string is allocated by the [`Editable`][crate::Editable]
153    ///  implementation and should be freed by the caller.
154    #[doc(alias = "gtk_editable_get_chars")]
155    #[doc(alias = "get_chars")]
156    fn chars(&self, start_pos: i32, end_pos: i32) -> Option<glib::GString> {
157        unsafe {
158            from_glib_full(ffi::gtk_editable_get_chars(
159                self.as_ref().to_glib_none().0,
160                start_pos,
161                end_pos,
162            ))
163        }
164    }
165
166    /// Retrieves whether `self` is editable. See
167    /// [`set_editable()`][Self::set_editable()].
168    ///
169    /// # Returns
170    ///
171    /// [`true`] if `self` is editable.
172    #[doc(alias = "gtk_editable_get_editable")]
173    #[doc(alias = "get_editable")]
174    fn is_editable(&self) -> bool {
175        unsafe {
176            from_glib(ffi::gtk_editable_get_editable(
177                self.as_ref().to_glib_none().0,
178            ))
179        }
180    }
181
182    /// Retrieves the current position of the cursor relative to the start
183    /// of the content of the editable.
184    ///
185    /// Note that this position is in characters, not in bytes.
186    ///
187    /// # Returns
188    ///
189    /// the cursor position
190    #[doc(alias = "gtk_editable_get_position")]
191    #[doc(alias = "get_position")]
192    fn position(&self) -> i32 {
193        unsafe { ffi::gtk_editable_get_position(self.as_ref().to_glib_none().0) }
194    }
195
196    /// Retrieves the selection bound of the editable. start_pos will be filled
197    /// with the start of the selection and `end_pos` with end. If no text was
198    /// selected both will be identical and [`false`] will be returned.
199    ///
200    /// Note that positions are specified in characters, not bytes.
201    ///
202    /// # Returns
203    ///
204    /// [`true`] if an area is selected, [`false`] otherwise
205    ///
206    /// ## `start_pos`
207    /// location to store the starting position, or [`None`]
208    ///
209    /// ## `end_pos`
210    /// location to store the end position, or [`None`]
211    #[doc(alias = "gtk_editable_get_selection_bounds")]
212    #[doc(alias = "get_selection_bounds")]
213    fn selection_bounds(&self) -> Option<(i32, i32)> {
214        unsafe {
215            let mut start_pos = std::mem::MaybeUninit::uninit();
216            let mut end_pos = std::mem::MaybeUninit::uninit();
217            let ret = from_glib(ffi::gtk_editable_get_selection_bounds(
218                self.as_ref().to_glib_none().0,
219                start_pos.as_mut_ptr(),
220                end_pos.as_mut_ptr(),
221            ));
222            if ret {
223                Some((start_pos.assume_init(), end_pos.assume_init()))
224            } else {
225                None
226            }
227        }
228    }
229
230    /// Inserts `new_text_length` bytes of `new_text` into the contents of the
231    /// widget, at position `position`.
232    ///
233    /// Note that the position is in characters, not in bytes.
234    /// The function updates `position` to point after the newly inserted text.
235    /// ## `new_text`
236    /// the text to append
237    /// ## `new_text_length`
238    /// the length of the text in bytes, or -1
239    ///
240    /// # Returns
241    ///
242    ///
243    /// ## `position`
244    /// location of the position text will be inserted at
245    #[doc(alias = "gtk_editable_insert_text")]
246    fn insert_text(&self, new_text: &str, position: &mut i32) {
247        let new_text_length = new_text.len() as _;
248        unsafe {
249            ffi::gtk_editable_insert_text(
250                self.as_ref().to_glib_none().0,
251                new_text.to_glib_none().0,
252                new_text_length,
253                position,
254            );
255        }
256    }
257
258    /// Pastes the content of the clipboard to the current position of the
259    /// cursor in the editable.
260    #[doc(alias = "gtk_editable_paste_clipboard")]
261    fn paste_clipboard(&self) {
262        unsafe {
263            ffi::gtk_editable_paste_clipboard(self.as_ref().to_glib_none().0);
264        }
265    }
266
267    /// Selects a region of text. The characters that are selected are
268    /// those characters at positions from `start_pos` up to, but not
269    /// including `end_pos`. If `end_pos` is negative, then the
270    /// characters selected are those characters from `start_pos` to
271    /// the end of the text.
272    ///
273    /// Note that positions are specified in characters, not bytes.
274    /// ## `start_pos`
275    /// start of region
276    /// ## `end_pos`
277    /// end of region
278    #[doc(alias = "gtk_editable_select_region")]
279    fn select_region(&self, start_pos: i32, end_pos: i32) {
280        unsafe {
281            ffi::gtk_editable_select_region(self.as_ref().to_glib_none().0, start_pos, end_pos);
282        }
283    }
284
285    /// Determines if the user can edit the text in the editable
286    /// widget or not.
287    /// ## `is_editable`
288    /// [`true`] if the user is allowed to edit the text
289    ///  in the widget
290    #[doc(alias = "gtk_editable_set_editable")]
291    fn set_editable(&self, is_editable: bool) {
292        unsafe {
293            ffi::gtk_editable_set_editable(self.as_ref().to_glib_none().0, is_editable.into_glib());
294        }
295    }
296
297    /// Sets the cursor position in the editable to the given value.
298    ///
299    /// The cursor is displayed before the character with the given (base 0)
300    /// index in the contents of the editable. The value must be less than or
301    /// equal to the number of characters in the editable. A value of -1
302    /// indicates that the position should be set after the last character
303    /// of the editable. Note that `position` is in characters, not in bytes.
304    /// ## `position`
305    /// the position of the cursor
306    #[doc(alias = "gtk_editable_set_position")]
307    fn set_position(&self, position: i32) {
308        unsafe {
309            ffi::gtk_editable_set_position(self.as_ref().to_glib_none().0, position);
310        }
311    }
312}
313
314impl<O: IsA<Editable>> EditableExt for O {}