gtk4/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
5#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::{Accessible, AccessiblePlatformState};
8use crate::{Buildable, ConstraintTarget, Widget, ffi};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{SignalHandlerId, connect_raw},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17#[cfg(feature = "v4_10")]
18#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
19glib::wrapper! {
20 /// text_widget, gtk_widget_unparent);
21 /// ...
22 /// }
23 /// ```text
24 ///
25 /// Finally, use [func@Gtk.Editable.delegate_set_property] in your `set_property`
26 /// function (and similar for `get_property`), to set the editable properties:
27 ///
28 /// ```c
29 /// ...
30 /// if (gtk_editable_delegate_set_property (object, prop_id, value, pspec))
31 /// return;
32 ///
33 /// switch (prop_id)
34 /// ...
35 /// ```text
36 ///
37 /// It is important to note that if you create a [`Editable`][crate::Editable] that uses
38 /// a delegate, the low level [`insert-text`][struct@crate::Editable#insert-text] and
39 /// [`delete-text`][struct@crate::Editable#delete-text] signals will be propagated from the
40 /// "wrapper" editable to the delegate, but they will not be propagated from
41 /// the delegate to the "wrapper" editable, as they would cause an infinite
42 /// recursion. If you wish to connect to the [`insert-text`][struct@crate::Editable#insert-text]
43 /// and [`delete-text`][struct@crate::Editable#delete-text] signals, you will need to connect
44 /// to them on the delegate obtained via [`EditableExt::delegate()`][crate::prelude::EditableExt::delegate()].
45 ///
46 /// ## Properties
47 ///
48 ///
49 /// #### `complete-text`
50 /// The contents of the entry, including uncommited content such as the
51 /// preedit.
52 ///
53 /// Readable
54 ///
55 ///
56 /// #### `cursor-position`
57 /// The current position of the insertion cursor in chars.
58 ///
59 /// Readable
60 ///
61 ///
62 /// #### `editable`
63 /// Whether the entry contents can be edited.
64 ///
65 /// Readable | Writable
66 ///
67 ///
68 /// #### `enable-undo`
69 /// If undo/redo should be enabled for the editable.
70 ///
71 /// Readable | Writable
72 ///
73 ///
74 /// #### `max-width-chars`
75 /// The desired maximum width of the entry, in characters.
76 ///
77 /// Readable | Writable
78 ///
79 ///
80 /// #### `selection-bound`
81 /// The position of the opposite end of the selection from the cursor in chars.
82 ///
83 /// Readable
84 ///
85 ///
86 /// #### `text`
87 /// The contents of the entry.
88 ///
89 /// Readable | Writable
90 ///
91 ///
92 /// #### `width-chars`
93 /// Number of characters to leave space for in the entry.
94 ///
95 /// Readable | Writable
96 ///
97 ///
98 /// #### `xalign`
99 /// The horizontal alignment, from 0 (left) to 1 (right).
100 ///
101 /// Reversed for RTL layouts.
102 ///
103 /// Readable | Writable
104 /// <details><summary><h4>Widget</h4></summary>
105 ///
106 ///
107 /// #### `can-focus`
108 /// Whether the widget or any of its descendents can accept
109 /// the input focus.
110 ///
111 /// This property is meant to be set by widget implementations,
112 /// typically in their instance init function.
113 ///
114 /// Readable | Writable
115 ///
116 ///
117 /// #### `can-target`
118 /// Whether the widget can receive pointer events.
119 ///
120 /// Readable | Writable
121 ///
122 ///
123 /// #### `css-classes`
124 /// A list of css classes applied to this widget.
125 ///
126 /// Readable | Writable
127 ///
128 ///
129 /// #### `css-name`
130 /// The name of this widget in the CSS tree.
131 ///
132 /// This property is meant to be set by widget implementations,
133 /// typically in their instance init function.
134 ///
135 /// Readable | Writable | Construct Only
136 ///
137 ///
138 /// #### `cursor`
139 /// The cursor used by @widget.
140 ///
141 /// Readable | Writable
142 ///
143 ///
144 /// #### `focus-on-click`
145 /// Whether the widget should grab focus when it is clicked with the mouse.
146 ///
147 /// This property is only relevant for widgets that can take focus.
148 ///
149 /// Readable | Writable
150 ///
151 ///
152 /// #### `focusable`
153 /// Whether this widget itself will accept the input focus.
154 ///
155 /// Readable | Writable
156 ///
157 ///
158 /// #### `halign`
159 /// How to distribute horizontal space if widget gets extra space.
160 ///
161 /// Readable | Writable
162 ///
163 ///
164 /// #### `has-default`
165 /// Whether the widget is the default widget.
166 ///
167 /// Readable
168 ///
169 ///
170 /// #### `has-focus`
171 /// Whether the widget has the input focus.
172 ///
173 /// Readable
174 ///
175 ///
176 /// #### `has-tooltip`
177 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
178 /// signal on @widget.
179 ///
180 /// A true value indicates that @widget can have a tooltip, in this case
181 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
182 /// determine whether it will provide a tooltip or not.
183 ///
184 /// Readable | Writable
185 ///
186 ///
187 /// #### `height-request`
188 /// Overrides for height request of the widget.
189 ///
190 /// If this is -1, the natural request will be used.
191 ///
192 /// Readable | Writable
193 ///
194 ///
195 /// #### `hexpand`
196 /// Whether to expand horizontally.
197 ///
198 /// Readable | Writable
199 ///
200 ///
201 /// #### `hexpand-set`
202 /// Whether to use the `hexpand` property.
203 ///
204 /// Readable | Writable
205 ///
206 ///
207 /// #### `layout-manager`
208 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
209 /// the preferred size of the widget, and allocate its children.
210 ///
211 /// This property is meant to be set by widget implementations,
212 /// typically in their instance init function.
213 ///
214 /// Readable | Writable
215 ///
216 ///
217 /// #### `limit-events`
218 /// Makes this widget act like a modal dialog, with respect to
219 /// event delivery.
220 ///
221 /// Global event controllers will not handle events with targets
222 /// inside the widget, unless they are set up to ignore propagation
223 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
224 ///
225 /// Readable | Writable
226 ///
227 ///
228 /// #### `margin-bottom`
229 /// Margin on bottom side of widget.
230 ///
231 /// This property adds margin outside of the widget's normal size
232 /// request, the margin will be added in addition to the size from
233 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
234 ///
235 /// Readable | Writable
236 ///
237 ///
238 /// #### `margin-end`
239 /// Margin on end of widget, horizontally.
240 ///
241 /// This property supports left-to-right and right-to-left text
242 /// directions.
243 ///
244 /// This property adds margin outside of the widget's normal size
245 /// request, the margin will be added in addition to the size from
246 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
247 ///
248 /// Readable | Writable
249 ///
250 ///
251 /// #### `margin-start`
252 /// Margin on start of widget, horizontally.
253 ///
254 /// This property supports left-to-right and right-to-left text
255 /// directions.
256 ///
257 /// This property adds margin outside of the widget's normal size
258 /// request, the margin will be added in addition to the size from
259 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
260 ///
261 /// Readable | Writable
262 ///
263 ///
264 /// #### `margin-top`
265 /// Margin on top side of widget.
266 ///
267 /// This property adds margin outside of the widget's normal size
268 /// request, the margin will be added in addition to the size from
269 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
270 ///
271 /// Readable | Writable
272 ///
273 ///
274 /// #### `name`
275 /// The name of the widget.
276 ///
277 /// Readable | Writable
278 ///
279 ///
280 /// #### `opacity`
281 /// The requested opacity of the widget.
282 ///
283 /// Readable | Writable
284 ///
285 ///
286 /// #### `overflow`
287 /// How content outside the widget's content area is treated.
288 ///
289 /// This property is meant to be set by widget implementations,
290 /// typically in their instance init function.
291 ///
292 /// Readable | Writable
293 ///
294 ///
295 /// #### `parent`
296 /// The parent widget of this widget.
297 ///
298 /// Readable
299 ///
300 ///
301 /// #### `receives-default`
302 /// Whether the widget will receive the default action when it is focused.
303 ///
304 /// Readable | Writable
305 ///
306 ///
307 /// #### `root`
308 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
309 ///
310 /// This will be `NULL` if the widget is not contained in a root widget.
311 ///
312 /// Readable
313 ///
314 ///
315 /// #### `scale-factor`
316 /// The scale factor of the widget.
317 ///
318 /// Readable
319 ///
320 ///
321 /// #### `sensitive`
322 /// Whether the widget responds to input.
323 ///
324 /// Readable | Writable
325 ///
326 ///
327 /// #### `tooltip-markup`
328 /// Sets the text of tooltip to be the given string, which is marked up
329 /// with Pango markup.
330 ///
331 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
332 ///
333 /// This is a convenience property which will take care of getting the
334 /// tooltip shown if the given string is not `NULL`:
335 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
336 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
337 /// the default signal handler.
338 ///
339 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
340 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
341 ///
342 /// Readable | Writable
343 ///
344 ///
345 /// #### `tooltip-text`
346 /// Sets the text of tooltip to be the given string.
347 ///
348 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
349 ///
350 /// This is a convenience property which will take care of getting the
351 /// tooltip shown if the given string is not `NULL`:
352 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
353 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
354 /// the default signal handler.
355 ///
356 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
357 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
358 ///
359 /// Readable | Writable
360 ///
361 ///
362 /// #### `valign`
363 /// How to distribute vertical space if widget gets extra space.
364 ///
365 /// Readable | Writable
366 ///
367 ///
368 /// #### `vexpand`
369 /// Whether to expand vertically.
370 ///
371 /// Readable | Writable
372 ///
373 ///
374 /// #### `vexpand-set`
375 /// Whether to use the `vexpand` property.
376 ///
377 /// Readable | Writable
378 ///
379 ///
380 /// #### `visible`
381 /// Whether the widget is visible.
382 ///
383 /// Readable | Writable
384 ///
385 ///
386 /// #### `width-request`
387 /// Overrides for width request of the widget.
388 ///
389 /// If this is -1, the natural request will be used.
390 ///
391 /// Readable | Writable
392 /// </details>
393 /// <details><summary><h4>Accessible</h4></summary>
394 ///
395 ///
396 /// #### `accessible-role`
397 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
398 ///
399 /// The accessible role cannot be changed once set.
400 ///
401 /// Readable | Writable
402 /// </details>
403 ///
404 /// ## Signals
405 ///
406 ///
407 /// #### `changed`
408 /// Emitted at the end of a single user-visible operation on the
409 /// contents.
410 ///
411 /// E.g., a paste operation that replaces the contents of the
412 /// selection will cause only one signal emission (even though it
413 /// is implemented by first deleting the selection, then inserting
414 /// the new content, and may cause multiple ::notify::text signals
415 /// to be emitted).
416 ///
417 ///
418 ///
419 ///
420 /// #### `delete-text`
421 /// Emitted when text is deleted from the widget by the user.
422 ///
423 /// The default handler for this signal will normally be responsible for
424 /// deleting the text, so by connecting to this signal and then stopping
425 /// the signal with g_signal_stop_emission(), it is possible to modify the
426 /// range of deleted text, or prevent it from being deleted entirely.
427 ///
428 /// The @start_pos and @end_pos parameters are interpreted as for
429 /// [`EditableExt::delete_text()`][crate::prelude::EditableExt::delete_text()].
430 ///
431 ///
432 ///
433 ///
434 /// #### `insert-text`
435 /// Emitted when text is inserted into the widget by the user.
436 ///
437 /// The default handler for this signal will normally be responsible
438 /// for inserting the text, so by connecting to this signal and then
439 /// stopping the signal with g_signal_stop_emission(), it is possible
440 /// to modify the inserted text, or prevent it from being inserted entirely.
441 ///
442 ///
443 /// <details><summary><h4>Widget</h4></summary>
444 ///
445 ///
446 /// #### `destroy`
447 /// Signals that all holders of a reference to the widget should release
448 /// the reference that they hold.
449 ///
450 /// May result in finalization of the widget if all references are released.
451 ///
452 /// This signal is not suitable for saving widget state.
453 ///
454 ///
455 ///
456 ///
457 /// #### `direction-changed`
458 /// Emitted when the text direction of a widget changes.
459 ///
460 ///
461 ///
462 ///
463 /// #### `hide`
464 /// Emitted when @widget is hidden.
465 ///
466 ///
467 ///
468 ///
469 /// #### `keynav-failed`
470 /// Emitted if keyboard navigation fails.
471 ///
472 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
473 ///
474 ///
475 ///
476 ///
477 /// #### `map`
478 /// Emitted when @widget is going to be mapped.
479 ///
480 /// A widget is mapped when the widget is visible (which is controlled with
481 /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
482 /// are also visible.
483 ///
484 /// The `::map` signal can be used to determine whether a widget will be drawn,
485 /// for instance it can resume an animation that was stopped during the
486 /// emission of [`unmap`][struct@crate::Widget#unmap].
487 ///
488 ///
489 ///
490 ///
491 /// #### `mnemonic-activate`
492 /// Emitted when a widget is activated via a mnemonic.
493 ///
494 /// The default handler for this signal activates @widget if @group_cycling
495 /// is false, or just makes @widget grab focus if @group_cycling is true.
496 ///
497 ///
498 ///
499 ///
500 /// #### `move-focus`
501 /// to move backward.
502 ///
503 /// Action
504 ///
505 ///
506 /// #### `query-tooltip`
507 /// s tooltip is about to be shown.
508 ///
509 /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
510 /// is true and the hover timeout has expired with the cursor hovering
511 /// above @widget; or emitted when @widget got focus in keyboard mode.
512 ///
513 /// Using the given coordinates, the signal handler should determine
514 /// whether a tooltip should be shown for @widget. If this is the case
515 /// true should be returned, false otherwise. Note that if @keyboard_mode
516 /// is true, the values of @x and @y are undefined and should not be used.
517 ///
518 /// The signal handler is free to manipulate @tooltip with the therefore
519 /// destined function calls.
520 ///
521 ///
522 ///
523 ///
524 /// #### `realize`
525 /// Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
526 ///
527 /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
528 /// or the widget has been mapped (that is, it is going to be drawn).
529 ///
530 ///
531 ///
532 ///
533 /// #### `show`
534 /// Emitted when @widget is shown.
535 ///
536 ///
537 ///
538 ///
539 /// #### `state-flags-changed`
540 /// Emitted when the widget state changes.
541 ///
542 /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
543 ///
544 ///
545 ///
546 ///
547 /// #### `unmap`
548 /// Emitted when @widget is going to be unmapped.
549 ///
550 /// A widget is unmapped when either it or any of its parents up to the
551 /// toplevel widget have been set as hidden.
552 ///
553 /// As `::unmap` indicates that a widget will not be shown any longer,
554 /// it can be used to, for example, stop an animation on the widget.
555 ///
556 ///
557 ///
558 ///
559 /// #### `unrealize`
560 /// Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
561 ///
562 /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
563 /// or the widget has been unmapped (that is, it is going to be hidden).
564 ///
565 ///
566 /// </details>
567 ///
568 /// # Implements
569 ///
570 /// [`EditableExt`][trait@crate::prelude::EditableExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`EditableExtManual`][trait@crate::prelude::EditableExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
571 #[doc(alias = "GtkEditable")]
572 pub struct Editable(Interface<ffi::GtkEditable, ffi::GtkEditableInterface>) @requires Widget, Accessible, Buildable, ConstraintTarget;
573
574 match fn {
575 type_ => || ffi::gtk_editable_get_type(),
576 }
577}
578
579#[cfg(not(feature = "v4_10"))]
580glib::wrapper! {
581 #[doc(alias = "GtkEditable")]
582 pub struct Editable(Interface<ffi::GtkEditable, ffi::GtkEditableInterface>) @requires Widget, Buildable, ConstraintTarget;
583
584 match fn {
585 type_ => || ffi::gtk_editable_get_type(),
586 }
587}
588
589impl Editable {
590 pub const NONE: Option<&'static Editable> = None;
591}
592
593/// Trait containing all [`struct@Editable`] methods.
594///
595/// # Implementors
596///
597/// [`EditableLabel`][struct@crate::EditableLabel], [`Editable`][struct@crate::Editable], [`Entry`][struct@crate::Entry], [`PasswordEntry`][struct@crate::PasswordEntry], [`SearchEntry`][struct@crate::SearchEntry], [`SpinButton`][struct@crate::SpinButton], [`Text`][struct@crate::Text]
598pub trait EditableExt: IsA<Editable> + 'static {
599 /// get_platform_state = your_editable_get_accessible_platform_state;
600 /// }
601 ///
602 /// static gboolean
603 /// your_editable_get_accessible_platform_state (GtkAccessible *accessible,
604 /// GtkAccessiblePlatformState state)
605 /// {
606 /// return gtk_editable_delegate_get_accessible_platform_state (GTK_EDITABLE (accessible), state);
607 /// }
608 /// ```text
609 ///
610 /// Note that the widget which is the delegate *must* be a direct child of
611 /// this widget, otherwise your implementation of `vfunc::Gtk::Accessible::get_platform_state`
612 /// might not even be called, as the platform change will originate from
613 /// the parent of the delegate, and, as a result, will not work properly.
614 ///
615 /// So, if you can't ensure the direct child condition, you should give the
616 /// delegate the [`AccessibleRole::TextBox`][crate::AccessibleRole::TextBox] role, or you can
617 /// change your tree to allow this function to work.
618 /// ## `state`
619 /// what kind of accessible state to retrieve
620 ///
621 /// # Returns
622 ///
623 /// the accessible platform state of the delegate
624 #[cfg(feature = "v4_10")]
625 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
626 #[doc(alias = "gtk_editable_delegate_get_accessible_platform_state")]
627 fn delegate_get_accessible_platform_state(&self, state: AccessiblePlatformState) -> bool {
628 unsafe {
629 from_glib(ffi::gtk_editable_delegate_get_accessible_platform_state(
630 self.as_ref().to_glib_none().0,
631 state.into_glib(),
632 ))
633 }
634 }
635
636 /// t do anything if there is no selected text.
637 #[doc(alias = "gtk_editable_delete_selection")]
638 fn delete_selection(&self) {
639 unsafe {
640 ffi::gtk_editable_delete_selection(self.as_ref().to_glib_none().0);
641 }
642 }
643
644 /// Deletes a sequence of characters.
645 ///
646 /// The characters that are deleted are those characters at positions
647 /// from @start_pos up to, but not including @end_pos. If @end_pos is
648 /// negative, then the characters deleted are those from @start_pos to
649 /// the end of the text.
650 ///
651 /// Note that the positions are specified in characters, not bytes.
652 /// ## `start_pos`
653 /// start position
654 /// ## `end_pos`
655 /// end position
656 #[doc(alias = "gtk_editable_delete_text")]
657 fn delete_text(&self, start_pos: i32, end_pos: i32) {
658 unsafe {
659 ffi::gtk_editable_delete_text(self.as_ref().to_glib_none().0, start_pos, end_pos);
660 }
661 }
662
663 /// Undoes the setup done by [`init_delegate()`][Self::init_delegate()].
664 ///
665 /// This is a helper function that should be called from dispose,
666 /// before removing the delegate object.
667 #[doc(alias = "gtk_editable_finish_delegate")]
668 fn finish_delegate(&self) {
669 unsafe {
670 ffi::gtk_editable_finish_delegate(self.as_ref().to_glib_none().0);
671 }
672 }
673
674 /// Gets the alignment of the editable.
675 ///
676 /// # Returns
677 ///
678 /// the alignment
679 #[doc(alias = "gtk_editable_get_alignment")]
680 #[doc(alias = "get_alignment")]
681 #[doc(alias = "xalign")]
682 fn alignment(&self) -> f32 {
683 unsafe { ffi::gtk_editable_get_alignment(self.as_ref().to_glib_none().0) }
684 }
685
686 /// Retrieves a sequence of characters.
687 ///
688 /// The characters that are retrieved are those characters at positions
689 /// from @start_pos up to, but not including @end_pos. If @end_pos is negative,
690 /// then the characters retrieved are those characters from @start_pos to
691 /// the end of the text.
692 ///
693 /// Note that positions are specified in characters, not bytes.
694 /// ## `start_pos`
695 /// start of text
696 /// ## `end_pos`
697 /// end of text
698 ///
699 /// # Returns
700 ///
701 /// a pointer to the contents of the widget as a
702 /// string. This string is allocated by the [`Editable`][crate::Editable] implementation
703 /// and should be freed by the caller.
704 #[doc(alias = "gtk_editable_get_chars")]
705 #[doc(alias = "get_chars")]
706 fn chars(&self, start_pos: i32, end_pos: i32) -> glib::GString {
707 unsafe {
708 from_glib_full(ffi::gtk_editable_get_chars(
709 self.as_ref().to_glib_none().0,
710 start_pos,
711 end_pos,
712 ))
713 }
714 }
715
716 /// Retrieves the contents of @self, including *pseudo-content*
717 /// such as the preedit buffer.
718 ///
719 /// # Returns
720 ///
721 /// the complete contents of the editable
722 #[cfg(feature = "v4_24")]
723 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
724 #[doc(alias = "gtk_editable_get_complete_text")]
725 #[doc(alias = "get_complete_text")]
726 #[doc(alias = "complete-text")]
727 fn complete_text(&self) -> glib::GString {
728 unsafe {
729 from_glib_full(ffi::gtk_editable_get_complete_text(
730 self.as_ref().to_glib_none().0,
731 ))
732 }
733 }
734
735 /// Gets the [`Editable`][crate::Editable] that @self is delegating its
736 /// implementation to.
737 ///
738 /// Typically, the delegate is a [`Text`][crate::Text] widget.
739 ///
740 /// # Returns
741 ///
742 /// the delegate [`Editable`][crate::Editable]
743 #[doc(alias = "gtk_editable_get_delegate")]
744 #[doc(alias = "get_delegate")]
745 #[must_use]
746 fn delegate(&self) -> Option<Editable> {
747 unsafe {
748 from_glib_none(ffi::gtk_editable_get_delegate(
749 self.as_ref().to_glib_none().0,
750 ))
751 }
752 }
753
754 /// Retrieves whether @self is editable.
755 ///
756 /// # Returns
757 ///
758 /// [`true`] if @self is editable.
759 #[doc(alias = "gtk_editable_get_editable")]
760 #[doc(alias = "get_editable")]
761 #[doc(alias = "editable")]
762 fn is_editable(&self) -> bool {
763 unsafe {
764 from_glib(ffi::gtk_editable_get_editable(
765 self.as_ref().to_glib_none().0,
766 ))
767 }
768 }
769
770 /// Gets if undo/redo actions are enabled for @self
771 ///
772 /// # Returns
773 ///
774 /// [`true`] if undo is enabled
775 #[doc(alias = "gtk_editable_get_enable_undo")]
776 #[doc(alias = "get_enable_undo")]
777 #[doc(alias = "enable-undo")]
778 fn enables_undo(&self) -> bool {
779 unsafe {
780 from_glib(ffi::gtk_editable_get_enable_undo(
781 self.as_ref().to_glib_none().0,
782 ))
783 }
784 }
785
786 /// Retrieves the desired maximum width of @self, in characters.
787 ///
788 /// # Returns
789 ///
790 /// the maximum width of the entry, in characters
791 #[doc(alias = "gtk_editable_get_max_width_chars")]
792 #[doc(alias = "get_max_width_chars")]
793 #[doc(alias = "max-width-chars")]
794 fn max_width_chars(&self) -> i32 {
795 unsafe { ffi::gtk_editable_get_max_width_chars(self.as_ref().to_glib_none().0) }
796 }
797
798 /// Retrieves the current position of the cursor relative
799 /// to the start of the content of the editable.
800 ///
801 /// Note that this position is in characters, not in bytes.
802 ///
803 /// # Returns
804 ///
805 /// the cursor position
806 #[doc(alias = "gtk_editable_get_position")]
807 #[doc(alias = "get_position")]
808 #[doc(alias = "cursor-position")]
809 fn position(&self) -> i32 {
810 unsafe { ffi::gtk_editable_get_position(self.as_ref().to_glib_none().0) }
811 }
812
813 /// Retrieves the selection bound of the editable.
814 ///
815 /// @start_pos will be filled with the start of the selection and
816 /// @end_pos with end. If no text was selected both will be identical
817 /// and [`false`] will be returned.
818 ///
819 /// Note that positions are specified in characters, not bytes.
820 ///
821 /// # Returns
822 ///
823 /// [`true`] if there is a non-empty selection, [`false`] otherwise
824 ///
825 /// ## `start_pos`
826 /// location to store the starting position
827 ///
828 /// ## `end_pos`
829 /// location to store the end position
830 #[doc(alias = "gtk_editable_get_selection_bounds")]
831 #[doc(alias = "get_selection_bounds")]
832 fn selection_bounds(&self) -> Option<(i32, i32)> {
833 unsafe {
834 let mut start_pos = std::mem::MaybeUninit::uninit();
835 let mut end_pos = std::mem::MaybeUninit::uninit();
836 let ret = from_glib(ffi::gtk_editable_get_selection_bounds(
837 self.as_ref().to_glib_none().0,
838 start_pos.as_mut_ptr(),
839 end_pos.as_mut_ptr(),
840 ));
841 if ret {
842 Some((start_pos.assume_init(), end_pos.assume_init()))
843 } else {
844 None
845 }
846 }
847 }
848
849 /// Retrieves the contents of @self.
850 ///
851 /// The returned string is owned by GTK and must not be modified or freed.
852 ///
853 /// # Returns
854 ///
855 /// a pointer to the contents of the editable
856 #[doc(alias = "gtk_editable_get_text")]
857 #[doc(alias = "get_text")]
858 fn text(&self) -> glib::GString {
859 unsafe { from_glib_none(ffi::gtk_editable_get_text(self.as_ref().to_glib_none().0)) }
860 }
861
862 /// Gets the number of characters of space reserved
863 /// for the contents of the editable.
864 ///
865 /// # Returns
866 ///
867 /// number of chars to request space for, or negative if unset
868 #[doc(alias = "gtk_editable_get_width_chars")]
869 #[doc(alias = "get_width_chars")]
870 #[doc(alias = "width-chars")]
871 fn width_chars(&self) -> i32 {
872 unsafe { ffi::gtk_editable_get_width_chars(self.as_ref().to_glib_none().0) }
873 }
874
875 /// Sets up a delegate for [`Editable`][crate::Editable].
876 ///
877 /// This is assuming that the get_delegate vfunc in the [`Editable`][crate::Editable]
878 /// interface has been set up for the @self's type.
879 ///
880 /// This is a helper function that should be called in instance init,
881 /// after creating the delegate object.
882 #[doc(alias = "gtk_editable_init_delegate")]
883 fn init_delegate(&self) {
884 unsafe {
885 ffi::gtk_editable_init_delegate(self.as_ref().to_glib_none().0);
886 }
887 }
888
889 /// Inserts @length bytes of @text into the contents of the
890 /// widget, at position @position.
891 ///
892 /// Note that the position is in characters, not in bytes.
893 /// The function updates @position to point after the newly
894 /// inserted text.
895 /// ## `text`
896 /// the text to insert
897 /// ## `length`
898 /// the length of the text in bytes, or -1
899 ///
900 /// # Returns
901 ///
902 ///
903 /// ## `position`
904 /// location of the position text will be inserted at
905 #[doc(alias = "gtk_editable_insert_text")]
906 fn insert_text(&self, text: &str, position: &mut i32) {
907 let length = text.len() as _;
908 unsafe {
909 ffi::gtk_editable_insert_text(
910 self.as_ref().to_glib_none().0,
911 text.to_glib_none().0,
912 length,
913 position,
914 );
915 }
916 }
917
918 /// Selects a region of text.
919 ///
920 /// The characters that are selected are those characters at positions
921 /// from @start_pos up to, but not including @end_pos. If @end_pos is
922 /// negative, then the characters selected are those characters from
923 /// @start_pos to the end of the text.
924 ///
925 /// Note that positions are specified in characters, not bytes.
926 /// ## `start_pos`
927 /// start of region
928 /// ## `end_pos`
929 /// end of region
930 #[doc(alias = "gtk_editable_select_region")]
931 fn select_region(&self, start_pos: i32, end_pos: i32) {
932 unsafe {
933 ffi::gtk_editable_select_region(self.as_ref().to_glib_none().0, start_pos, end_pos);
934 }
935 }
936
937 /// Sets the alignment for the contents of the editable.
938 ///
939 /// This controls the horizontal positioning of the contents when
940 /// the displayed text is shorter than the width of the editable.
941 /// ## `xalign`
942 /// The horizontal alignment, from 0 (left) to 1 (right).
943 /// Reversed for RTL layouts
944 #[doc(alias = "gtk_editable_set_alignment")]
945 #[doc(alias = "xalign")]
946 fn set_alignment(&self, xalign: f32) {
947 unsafe {
948 ffi::gtk_editable_set_alignment(self.as_ref().to_glib_none().0, xalign);
949 }
950 }
951
952 /// Determines if the user can edit the text in the editable widget.
953 /// ## `is_editable`
954 /// [`true`] if the user is allowed to edit the text
955 /// in the widget
956 #[doc(alias = "gtk_editable_set_editable")]
957 #[doc(alias = "editable")]
958 fn set_editable(&self, is_editable: bool) {
959 unsafe {
960 ffi::gtk_editable_set_editable(self.as_ref().to_glib_none().0, is_editable.into_glib());
961 }
962 }
963
964 /// If enabled, changes to @self will be saved for undo/redo
965 /// actions.
966 ///
967 /// This results in an additional copy of text changes and are not
968 /// stored in secure memory. As such, undo is forcefully disabled
969 /// when [`visibility`][struct@crate::Text#visibility] is set to [`false`].
970 /// ## `enable_undo`
971 /// if undo/redo should be enabled
972 #[doc(alias = "gtk_editable_set_enable_undo")]
973 #[doc(alias = "enable-undo")]
974 fn set_enable_undo(&self, enable_undo: bool) {
975 unsafe {
976 ffi::gtk_editable_set_enable_undo(
977 self.as_ref().to_glib_none().0,
978 enable_undo.into_glib(),
979 );
980 }
981 }
982
983 /// Sets the desired maximum width in characters of @self.
984 /// ## `n_chars`
985 /// the new desired maximum width, in characters
986 #[doc(alias = "gtk_editable_set_max_width_chars")]
987 #[doc(alias = "max-width-chars")]
988 fn set_max_width_chars(&self, n_chars: i32) {
989 unsafe {
990 ffi::gtk_editable_set_max_width_chars(self.as_ref().to_glib_none().0, n_chars);
991 }
992 }
993
994 /// Sets the cursor position in the editable to the given value.
995 ///
996 /// The cursor is displayed before the character with the given (base 0)
997 /// index in the contents of the editable. The value must be less than
998 /// or equal to the number of characters in the editable. A value of -1
999 /// indicates that the position should be set after the last character
1000 /// of the editable. Note that @position is in characters, not in bytes.
1001 /// ## `position`
1002 /// the position of the cursor
1003 #[doc(alias = "gtk_editable_set_position")]
1004 #[doc(alias = "cursor-position")]
1005 fn set_position(&self, position: i32) {
1006 unsafe {
1007 ffi::gtk_editable_set_position(self.as_ref().to_glib_none().0, position);
1008 }
1009 }
1010
1011 /// Sets the text in the editable to the given value.
1012 ///
1013 /// This is replacing the current contents.
1014 /// ## `text`
1015 /// the text to set
1016 #[doc(alias = "gtk_editable_set_text")]
1017 #[doc(alias = "text")]
1018 fn set_text(&self, text: &str) {
1019 unsafe {
1020 ffi::gtk_editable_set_text(self.as_ref().to_glib_none().0, text.to_glib_none().0);
1021 }
1022 }
1023
1024 /// Changes the size request of the editable to be about the
1025 /// right size for @n_chars characters.
1026 ///
1027 /// Note that it changes the size request, the size can still
1028 /// be affected by how you pack the widget into containers.
1029 /// If @n_chars is -1, the size reverts to the default size.
1030 /// ## `n_chars`
1031 /// width in chars
1032 #[doc(alias = "gtk_editable_set_width_chars")]
1033 #[doc(alias = "width-chars")]
1034 fn set_width_chars(&self, n_chars: i32) {
1035 unsafe {
1036 ffi::gtk_editable_set_width_chars(self.as_ref().to_glib_none().0, n_chars);
1037 }
1038 }
1039
1040 /// The position of the opposite end of the selection from the cursor in chars.
1041 #[doc(alias = "selection-bound")]
1042 fn selection_bound(&self) -> i32 {
1043 ObjectExt::property(self.as_ref(), "selection-bound")
1044 }
1045
1046 /// Emitted at the end of a single user-visible operation on the
1047 /// contents.
1048 ///
1049 /// E.g., a paste operation that replaces the contents of the
1050 /// selection will cause only one signal emission (even though it
1051 /// is implemented by first deleting the selection, then inserting
1052 /// the new content, and may cause multiple ::notify::text signals
1053 /// to be emitted).
1054 #[doc(alias = "changed")]
1055 fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1056 unsafe extern "C" fn changed_trampoline<P: IsA<Editable>, F: Fn(&P) + 'static>(
1057 this: *mut ffi::GtkEditable,
1058 f: glib::ffi::gpointer,
1059 ) {
1060 unsafe {
1061 let f: &F = &*(f as *const F);
1062 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
1063 }
1064 }
1065 unsafe {
1066 let f: Box_<F> = Box_::new(f);
1067 connect_raw(
1068 self.as_ptr() as *mut _,
1069 c"changed".as_ptr(),
1070 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1071 changed_trampoline::<Self, F> as *const (),
1072 )),
1073 Box_::into_raw(f),
1074 )
1075 }
1076 }
1077
1078 /// Emitted when text is deleted from the widget by the user.
1079 ///
1080 /// The default handler for this signal will normally be responsible for
1081 /// deleting the text, so by connecting to this signal and then stopping
1082 /// the signal with g_signal_stop_emission(), it is possible to modify the
1083 /// range of deleted text, or prevent it from being deleted entirely.
1084 ///
1085 /// The @start_pos and @end_pos parameters are interpreted as for
1086 /// [`delete_text()`][Self::delete_text()].
1087 /// ## `start_pos`
1088 /// the starting position
1089 /// ## `end_pos`
1090 /// the end position
1091 #[doc(alias = "delete-text")]
1092 fn connect_delete_text<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId {
1093 unsafe extern "C" fn delete_text_trampoline<
1094 P: IsA<Editable>,
1095 F: Fn(&P, i32, i32) + 'static,
1096 >(
1097 this: *mut ffi::GtkEditable,
1098 start_pos: std::ffi::c_int,
1099 end_pos: std::ffi::c_int,
1100 f: glib::ffi::gpointer,
1101 ) {
1102 unsafe {
1103 let f: &F = &*(f as *const F);
1104 f(
1105 Editable::from_glib_borrow(this).unsafe_cast_ref(),
1106 start_pos,
1107 end_pos,
1108 )
1109 }
1110 }
1111 unsafe {
1112 let f: Box_<F> = Box_::new(f);
1113 connect_raw(
1114 self.as_ptr() as *mut _,
1115 c"delete-text".as_ptr(),
1116 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1117 delete_text_trampoline::<Self, F> as *const (),
1118 )),
1119 Box_::into_raw(f),
1120 )
1121 }
1122 }
1123
1124 #[cfg(feature = "v4_24")]
1125 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
1126 #[doc(alias = "complete-text")]
1127 fn connect_complete_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1128 unsafe extern "C" fn notify_complete_text_trampoline<
1129 P: IsA<Editable>,
1130 F: Fn(&P) + 'static,
1131 >(
1132 this: *mut ffi::GtkEditable,
1133 _param_spec: glib::ffi::gpointer,
1134 f: glib::ffi::gpointer,
1135 ) {
1136 unsafe {
1137 let f: &F = &*(f as *const F);
1138 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
1139 }
1140 }
1141 unsafe {
1142 let f: Box_<F> = Box_::new(f);
1143 connect_raw(
1144 self.as_ptr() as *mut _,
1145 c"notify::complete-text".as_ptr(),
1146 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1147 notify_complete_text_trampoline::<Self, F> as *const (),
1148 )),
1149 Box_::into_raw(f),
1150 )
1151 }
1152 }
1153
1154 #[doc(alias = "cursor-position")]
1155 fn connect_cursor_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1156 unsafe extern "C" fn notify_cursor_position_trampoline<
1157 P: IsA<Editable>,
1158 F: Fn(&P) + 'static,
1159 >(
1160 this: *mut ffi::GtkEditable,
1161 _param_spec: glib::ffi::gpointer,
1162 f: glib::ffi::gpointer,
1163 ) {
1164 unsafe {
1165 let f: &F = &*(f as *const F);
1166 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
1167 }
1168 }
1169 unsafe {
1170 let f: Box_<F> = Box_::new(f);
1171 connect_raw(
1172 self.as_ptr() as *mut _,
1173 c"notify::cursor-position".as_ptr(),
1174 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1175 notify_cursor_position_trampoline::<Self, F> as *const (),
1176 )),
1177 Box_::into_raw(f),
1178 )
1179 }
1180 }
1181
1182 #[doc(alias = "editable")]
1183 fn connect_editable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1184 unsafe extern "C" fn notify_editable_trampoline<P: IsA<Editable>, F: Fn(&P) + 'static>(
1185 this: *mut ffi::GtkEditable,
1186 _param_spec: glib::ffi::gpointer,
1187 f: glib::ffi::gpointer,
1188 ) {
1189 unsafe {
1190 let f: &F = &*(f as *const F);
1191 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
1192 }
1193 }
1194 unsafe {
1195 let f: Box_<F> = Box_::new(f);
1196 connect_raw(
1197 self.as_ptr() as *mut _,
1198 c"notify::editable".as_ptr(),
1199 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1200 notify_editable_trampoline::<Self, F> as *const (),
1201 )),
1202 Box_::into_raw(f),
1203 )
1204 }
1205 }
1206
1207 #[doc(alias = "enable-undo")]
1208 fn connect_enable_undo_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1209 unsafe extern "C" fn notify_enable_undo_trampoline<
1210 P: IsA<Editable>,
1211 F: Fn(&P) + 'static,
1212 >(
1213 this: *mut ffi::GtkEditable,
1214 _param_spec: glib::ffi::gpointer,
1215 f: glib::ffi::gpointer,
1216 ) {
1217 unsafe {
1218 let f: &F = &*(f as *const F);
1219 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
1220 }
1221 }
1222 unsafe {
1223 let f: Box_<F> = Box_::new(f);
1224 connect_raw(
1225 self.as_ptr() as *mut _,
1226 c"notify::enable-undo".as_ptr(),
1227 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1228 notify_enable_undo_trampoline::<Self, F> as *const (),
1229 )),
1230 Box_::into_raw(f),
1231 )
1232 }
1233 }
1234
1235 #[doc(alias = "max-width-chars")]
1236 fn connect_max_width_chars_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1237 unsafe extern "C" fn notify_max_width_chars_trampoline<
1238 P: IsA<Editable>,
1239 F: Fn(&P) + 'static,
1240 >(
1241 this: *mut ffi::GtkEditable,
1242 _param_spec: glib::ffi::gpointer,
1243 f: glib::ffi::gpointer,
1244 ) {
1245 unsafe {
1246 let f: &F = &*(f as *const F);
1247 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
1248 }
1249 }
1250 unsafe {
1251 let f: Box_<F> = Box_::new(f);
1252 connect_raw(
1253 self.as_ptr() as *mut _,
1254 c"notify::max-width-chars".as_ptr(),
1255 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1256 notify_max_width_chars_trampoline::<Self, F> as *const (),
1257 )),
1258 Box_::into_raw(f),
1259 )
1260 }
1261 }
1262
1263 #[doc(alias = "selection-bound")]
1264 fn connect_selection_bound_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1265 unsafe extern "C" fn notify_selection_bound_trampoline<
1266 P: IsA<Editable>,
1267 F: Fn(&P) + 'static,
1268 >(
1269 this: *mut ffi::GtkEditable,
1270 _param_spec: glib::ffi::gpointer,
1271 f: glib::ffi::gpointer,
1272 ) {
1273 unsafe {
1274 let f: &F = &*(f as *const F);
1275 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
1276 }
1277 }
1278 unsafe {
1279 let f: Box_<F> = Box_::new(f);
1280 connect_raw(
1281 self.as_ptr() as *mut _,
1282 c"notify::selection-bound".as_ptr(),
1283 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1284 notify_selection_bound_trampoline::<Self, F> as *const (),
1285 )),
1286 Box_::into_raw(f),
1287 )
1288 }
1289 }
1290
1291 #[doc(alias = "text")]
1292 fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1293 unsafe extern "C" fn notify_text_trampoline<P: IsA<Editable>, F: Fn(&P) + 'static>(
1294 this: *mut ffi::GtkEditable,
1295 _param_spec: glib::ffi::gpointer,
1296 f: glib::ffi::gpointer,
1297 ) {
1298 unsafe {
1299 let f: &F = &*(f as *const F);
1300 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
1301 }
1302 }
1303 unsafe {
1304 let f: Box_<F> = Box_::new(f);
1305 connect_raw(
1306 self.as_ptr() as *mut _,
1307 c"notify::text".as_ptr(),
1308 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1309 notify_text_trampoline::<Self, F> as *const (),
1310 )),
1311 Box_::into_raw(f),
1312 )
1313 }
1314 }
1315
1316 #[doc(alias = "width-chars")]
1317 fn connect_width_chars_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1318 unsafe extern "C" fn notify_width_chars_trampoline<
1319 P: IsA<Editable>,
1320 F: Fn(&P) + 'static,
1321 >(
1322 this: *mut ffi::GtkEditable,
1323 _param_spec: glib::ffi::gpointer,
1324 f: glib::ffi::gpointer,
1325 ) {
1326 unsafe {
1327 let f: &F = &*(f as *const F);
1328 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
1329 }
1330 }
1331 unsafe {
1332 let f: Box_<F> = Box_::new(f);
1333 connect_raw(
1334 self.as_ptr() as *mut _,
1335 c"notify::width-chars".as_ptr(),
1336 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1337 notify_width_chars_trampoline::<Self, F> as *const (),
1338 )),
1339 Box_::into_raw(f),
1340 )
1341 }
1342 }
1343
1344 #[doc(alias = "xalign")]
1345 fn connect_xalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1346 unsafe extern "C" fn notify_xalign_trampoline<P: IsA<Editable>, F: Fn(&P) + 'static>(
1347 this: *mut ffi::GtkEditable,
1348 _param_spec: glib::ffi::gpointer,
1349 f: glib::ffi::gpointer,
1350 ) {
1351 unsafe {
1352 let f: &F = &*(f as *const F);
1353 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
1354 }
1355 }
1356 unsafe {
1357 let f: Box_<F> = Box_::new(f);
1358 connect_raw(
1359 self.as_ptr() as *mut _,
1360 c"notify::xalign".as_ptr(),
1361 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1362 notify_xalign_trampoline::<Self, F> as *const (),
1363 )),
1364 Box_::into_raw(f),
1365 )
1366 }
1367 }
1368}
1369
1370impl<O: IsA<Editable>> EditableExt for O {}