gtk4/auto/
password_entry.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::{
6    ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, Editable, LayoutManager,
7    Overflow, Widget,
8};
9use glib::{
10    object::ObjectType as _,
11    prelude::*,
12    signal::{connect_raw, SignalHandlerId},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18    /// A single-line text entry widget for entering passwords and other secrets.
19    ///
20    /// <picture>
21    ///   <source srcset="password-entry-dark.png" media="(prefers-color-scheme: dark)">
22    ///   <img alt="An example GtkPasswordEntry" src="password-entry.png">
23    /// </picture>
24    ///
25    /// It does not show its contents in clear text, does not allow to copy it
26    /// to the clipboard, and it shows a warning when Caps Lock is engaged. If
27    /// the underlying platform allows it, [`PasswordEntry`][crate::PasswordEntry] will also place
28    /// the text in a non-pageable memory area, to avoid it being written out
29    /// to disk by the operating system.
30    ///
31    /// Optionally, it can offer a way to reveal the contents in clear text.
32    ///
33    /// [`PasswordEntry`][crate::PasswordEntry] provides only minimal API and should be used with
34    /// the [`Editable`][crate::Editable] API.
35    ///
36    /// # CSS Nodes
37    ///
38    /// ```text
39    /// entry.password
40    /// ╰── text
41    ///     ├── image.caps-lock-indicator
42    ///     ┊
43    /// ```
44    ///
45    /// [`PasswordEntry`][crate::PasswordEntry] has a single CSS node with name entry that carries
46    /// a .passwordstyle class. The text Css node below it has a child with
47    /// name image and style class .caps-lock-indicator for the Caps Lock
48    /// icon, and possibly other children.
49    ///
50    /// # Accessibility
51    ///
52    /// [`PasswordEntry`][crate::PasswordEntry] uses the [enum@Gtk.AccessibleRole.text_box] role.
53    ///
54    /// ## Properties
55    ///
56    ///
57    /// #### `activates-default`
58    ///  Whether to activate the default widget when Enter is pressed.
59    ///
60    /// Readable | Writeable
61    ///
62    ///
63    /// #### `extra-menu`
64    ///  A menu model whose contents will be appended to
65    /// the context menu.
66    ///
67    /// Readable | Writeable
68    ///
69    ///
70    /// #### `placeholder-text`
71    ///  The text that will be displayed in the [`PasswordEntry`][crate::PasswordEntry]
72    /// when it is empty and unfocused.
73    ///
74    /// Readable | Writeable
75    ///
76    ///
77    /// #### `show-peek-icon`
78    ///  Whether to show an icon for revealing the content.
79    ///
80    /// Readable | Writeable
81    /// <details><summary><h4>Widget</h4></summary>
82    ///
83    ///
84    /// #### `can-focus`
85    ///  Whether the widget or any of its descendents can accept
86    /// the input focus.
87    ///
88    /// This property is meant to be set by widget implementations,
89    /// typically in their instance init function.
90    ///
91    /// Readable | Writeable
92    ///
93    ///
94    /// #### `can-target`
95    ///  Whether the widget can receive pointer events.
96    ///
97    /// Readable | Writeable
98    ///
99    ///
100    /// #### `css-classes`
101    ///  A list of css classes applied to this widget.
102    ///
103    /// Readable | Writeable
104    ///
105    ///
106    /// #### `css-name`
107    ///  The name of this widget in the CSS tree.
108    ///
109    /// This property is meant to be set by widget implementations,
110    /// typically in their instance init function.
111    ///
112    /// Readable | Writeable | Construct Only
113    ///
114    ///
115    /// #### `cursor`
116    ///  The cursor used by @widget.
117    ///
118    /// Readable | Writeable
119    ///
120    ///
121    /// #### `focus-on-click`
122    ///  Whether the widget should grab focus when it is clicked with the mouse.
123    ///
124    /// This property is only relevant for widgets that can take focus.
125    ///
126    /// Readable | Writeable
127    ///
128    ///
129    /// #### `focusable`
130    ///  Whether this widget itself will accept the input focus.
131    ///
132    /// Readable | Writeable
133    ///
134    ///
135    /// #### `halign`
136    ///  How to distribute horizontal space if widget gets extra space.
137    ///
138    /// Readable | Writeable
139    ///
140    ///
141    /// #### `has-default`
142    ///  Whether the widget is the default widget.
143    ///
144    /// Readable
145    ///
146    ///
147    /// #### `has-focus`
148    ///  Whether the widget has the input focus.
149    ///
150    /// Readable
151    ///
152    ///
153    /// #### `has-tooltip`
154    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
155    /// signal on @widget.
156    ///
157    /// A true value indicates that @widget can have a tooltip, in this case
158    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
159    /// determine whether it will provide a tooltip or not.
160    ///
161    /// Readable | Writeable
162    ///
163    ///
164    /// #### `height-request`
165    ///  Overrides for height request of the widget.
166    ///
167    /// If this is -1, the natural request will be used.
168    ///
169    /// Readable | Writeable
170    ///
171    ///
172    /// #### `hexpand`
173    ///  Whether to expand horizontally.
174    ///
175    /// Readable | Writeable
176    ///
177    ///
178    /// #### `hexpand-set`
179    ///  Whether to use the `hexpand` property.
180    ///
181    /// Readable | Writeable
182    ///
183    ///
184    /// #### `layout-manager`
185    ///  The [`LayoutManager`][crate::LayoutManager] instance to use to compute
186    /// the preferred size of the widget, and allocate its children.
187    ///
188    /// This property is meant to be set by widget implementations,
189    /// typically in their instance init function.
190    ///
191    /// Readable | Writeable
192    ///
193    ///
194    /// #### `limit-events`
195    ///  Makes this widget act like a modal dialog, with respect to
196    /// event delivery.
197    ///
198    /// Global event controllers will not handle events with targets
199    /// inside the widget, unless they are set up to ignore propagation
200    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
201    ///
202    /// Readable | Writeable
203    ///
204    ///
205    /// #### `margin-bottom`
206    ///  Margin on bottom side of widget.
207    ///
208    /// This property adds margin outside of the widget's normal size
209    /// request, the margin will be added in addition to the size from
210    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
211    ///
212    /// Readable | Writeable
213    ///
214    ///
215    /// #### `margin-end`
216    ///  Margin on end of widget, horizontally.
217    ///
218    /// This property supports left-to-right and right-to-left text
219    /// directions.
220    ///
221    /// This property adds margin outside of the widget's normal size
222    /// request, the margin will be added in addition to the size from
223    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
224    ///
225    /// Readable | Writeable
226    ///
227    ///
228    /// #### `margin-start`
229    ///  Margin on start of widget, horizontally.
230    ///
231    /// This property supports left-to-right and right-to-left text
232    /// directions.
233    ///
234    /// This property adds margin outside of the widget's normal size
235    /// request, the margin will be added in addition to the size from
236    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
237    ///
238    /// Readable | Writeable
239    ///
240    ///
241    /// #### `margin-top`
242    ///  Margin on top side of widget.
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 | Writeable
249    ///
250    ///
251    /// #### `name`
252    ///  The name of the widget.
253    ///
254    /// Readable | Writeable
255    ///
256    ///
257    /// #### `opacity`
258    ///  The requested opacity of the widget.
259    ///
260    /// Readable | Writeable
261    ///
262    ///
263    /// #### `overflow`
264    ///  How content outside the widget's content area is treated.
265    ///
266    /// This property is meant to be set by widget implementations,
267    /// typically in their instance init function.
268    ///
269    /// Readable | Writeable
270    ///
271    ///
272    /// #### `parent`
273    ///  The parent widget of this widget.
274    ///
275    /// Readable
276    ///
277    ///
278    /// #### `receives-default`
279    ///  Whether the widget will receive the default action when it is focused.
280    ///
281    /// Readable | Writeable
282    ///
283    ///
284    /// #### `root`
285    ///  The [`Root`][crate::Root] widget of the widget tree containing this widget.
286    ///
287    /// This will be `NULL` if the widget is not contained in a root widget.
288    ///
289    /// Readable
290    ///
291    ///
292    /// #### `scale-factor`
293    ///  The scale factor of the widget.
294    ///
295    /// Readable
296    ///
297    ///
298    /// #### `sensitive`
299    ///  Whether the widget responds to input.
300    ///
301    /// Readable | Writeable
302    ///
303    ///
304    /// #### `tooltip-markup`
305    ///  Sets the text of tooltip to be the given string, which is marked up
306    /// with Pango markup.
307    ///
308    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
309    ///
310    /// This is a convenience property which will take care of getting the
311    /// tooltip shown if the given string is not `NULL`:
312    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
313    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
314    /// the default signal handler.
315    ///
316    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
317    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
318    ///
319    /// Readable | Writeable
320    ///
321    ///
322    /// #### `tooltip-text`
323    ///  Sets the text of tooltip to be the given string.
324    ///
325    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
326    ///
327    /// This is a convenience property which will take care of getting the
328    /// tooltip shown if the given string is not `NULL`:
329    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
330    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
331    /// the default signal handler.
332    ///
333    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
334    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
335    ///
336    /// Readable | Writeable
337    ///
338    ///
339    /// #### `valign`
340    ///  How to distribute vertical space if widget gets extra space.
341    ///
342    /// Readable | Writeable
343    ///
344    ///
345    /// #### `vexpand`
346    ///  Whether to expand vertically.
347    ///
348    /// Readable | Writeable
349    ///
350    ///
351    /// #### `vexpand-set`
352    ///  Whether to use the `vexpand` property.
353    ///
354    /// Readable | Writeable
355    ///
356    ///
357    /// #### `visible`
358    ///  Whether the widget is visible.
359    ///
360    /// Readable | Writeable
361    ///
362    ///
363    /// #### `width-request`
364    ///  Overrides for width request of the widget.
365    ///
366    /// If this is -1, the natural request will be used.
367    ///
368    /// Readable | Writeable
369    /// </details>
370    /// <details><summary><h4>Accessible</h4></summary>
371    ///
372    ///
373    /// #### `accessible-role`
374    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
375    ///
376    /// The accessible role cannot be changed once set.
377    ///
378    /// Readable | Writeable
379    /// </details>
380    /// <details><summary><h4>Editable</h4></summary>
381    ///
382    ///
383    /// #### `cursor-position`
384    ///  The current position of the insertion cursor in chars.
385    ///
386    /// Readable
387    ///
388    ///
389    /// #### `editable`
390    ///  Whether the entry contents can be edited.
391    ///
392    /// Readable | Writeable
393    ///
394    ///
395    /// #### `enable-undo`
396    ///  If undo/redo should be enabled for the editable.
397    ///
398    /// Readable | Writeable
399    ///
400    ///
401    /// #### `max-width-chars`
402    ///  The desired maximum width of the entry, in characters.
403    ///
404    /// Readable | Writeable
405    ///
406    ///
407    /// #### `selection-bound`
408    ///  The position of the opposite end of the selection from the cursor in chars.
409    ///
410    /// Readable
411    ///
412    ///
413    /// #### `text`
414    ///  The contents of the entry.
415    ///
416    /// Readable | Writeable
417    ///
418    ///
419    /// #### `width-chars`
420    ///  Number of characters to leave space for in the entry.
421    ///
422    /// Readable | Writeable
423    ///
424    ///
425    /// #### `xalign`
426    ///  The horizontal alignment, from 0 (left) to 1 (right).
427    ///
428    /// Reversed for RTL layouts.
429    ///
430    /// Readable | Writeable
431    /// </details>
432    ///
433    /// ## Signals
434    ///
435    ///
436    /// #### `activate`
437    ///  Emitted when the entry is activated.
438    ///
439    /// The keybindings for this signal are all forms of the Enter key.
440    ///
441    /// Action
442    /// <details><summary><h4>Widget</h4></summary>
443    ///
444    ///
445    /// #### `destroy`
446    ///  Signals that all holders of a reference to the widget should release
447    /// the reference that they hold.
448    ///
449    /// May result in finalization of the widget if all references are released.
450    ///
451    /// This signal is not suitable for saving widget state.
452    ///
453    ///
454    ///
455    ///
456    /// #### `direction-changed`
457    ///  Emitted when the text direction of a widget changes.
458    ///
459    ///
460    ///
461    ///
462    /// #### `hide`
463    ///  Emitted when @widget is hidden.
464    ///
465    ///
466    ///
467    ///
468    /// #### `keynav-failed`
469    ///  Emitted if keyboard navigation fails.
470    ///
471    /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
472    ///
473    ///
474    ///
475    ///
476    /// #### `map`
477    ///  Emitted when @widget is going to be mapped.
478    ///
479    /// A widget is mapped when the widget is visible (which is controlled with
480    /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
481    /// are also visible.
482    ///
483    /// The `::map` signal can be used to determine whether a widget will be drawn,
484    /// for instance it can resume an animation that was stopped during the
485    /// emission of [`unmap`][struct@crate::Widget#unmap].
486    ///
487    ///
488    ///
489    ///
490    /// #### `mnemonic-activate`
491    ///  Emitted when a widget is activated via a mnemonic.
492    ///
493    /// The default handler for this signal activates @widget if @group_cycling
494    /// is false, or just makes @widget grab focus if @group_cycling is true.
495    ///
496    ///
497    ///
498    ///
499    /// #### `move-focus`
500    ///  Emitted when the focus is moved.
501    ///
502    /// The `::move-focus` signal is a [keybinding signal](class.SignalAction.html).
503    ///
504    /// The default bindings for this signal are <kbd>Tab</kbd> to move forward,
505    /// and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
506    ///
507    /// Action
508    ///
509    ///
510    /// #### `query-tooltip`
511    ///  Emitted when the widget’s tooltip is about to be shown.
512    ///
513    /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
514    /// is true and the hover timeout has expired with the cursor hovering
515    /// above @widget; or emitted when @widget got focus in keyboard mode.
516    ///
517    /// Using the given coordinates, the signal handler should determine
518    /// whether a tooltip should be shown for @widget. If this is the case
519    /// true should be returned, false otherwise. Note that if @keyboard_mode
520    /// is true, the values of @x and @y are undefined and should not be used.
521    ///
522    /// The signal handler is free to manipulate @tooltip with the therefore
523    /// destined function calls.
524    ///
525    ///
526    ///
527    ///
528    /// #### `realize`
529    ///  Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
530    ///
531    /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
532    /// or the widget has been mapped (that is, it is going to be drawn).
533    ///
534    ///
535    ///
536    ///
537    /// #### `show`
538    ///  Emitted when @widget is shown.
539    ///
540    ///
541    ///
542    ///
543    /// #### `state-flags-changed`
544    ///  Emitted when the widget state changes.
545    ///
546    /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
547    ///
548    ///
549    ///
550    ///
551    /// #### `unmap`
552    ///  Emitted when @widget is going to be unmapped.
553    ///
554    /// A widget is unmapped when either it or any of its parents up to the
555    /// toplevel widget have been set as hidden.
556    ///
557    /// As `::unmap` indicates that a widget will not be shown any longer,
558    /// it can be used to, for example, stop an animation on the widget.
559    ///
560    ///
561    ///
562    ///
563    /// #### `unrealize`
564    ///  Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
565    ///
566    /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
567    /// or the widget has been unmapped (that is, it is going to be hidden).
568    ///
569    ///
570    /// </details>
571    /// <details><summary><h4>Editable</h4></summary>
572    ///
573    ///
574    /// #### `changed`
575    ///  Emitted at the end of a single user-visible operation on the
576    /// contents.
577    ///
578    /// E.g., a paste operation that replaces the contents of the
579    /// selection will cause only one signal emission (even though it
580    /// is implemented by first deleting the selection, then inserting
581    /// the new content, and may cause multiple ::notify::text signals
582    /// to be emitted).
583    ///
584    ///
585    ///
586    ///
587    /// #### `delete-text`
588    ///  Emitted when text is deleted from the widget by the user.
589    ///
590    /// The default handler for this signal will normally be responsible for
591    /// deleting the text, so by connecting to this signal and then stopping
592    /// the signal with g_signal_stop_emission(), it is possible to modify the
593    /// range of deleted text, or prevent it from being deleted entirely.
594    ///
595    /// The @start_pos and @end_pos parameters are interpreted as for
596    /// [`EditableExt::delete_text()`][crate::prelude::EditableExt::delete_text()].
597    ///
598    ///
599    ///
600    ///
601    /// #### `insert-text`
602    ///  Emitted when text is inserted into the widget by the user.
603    ///
604    /// The default handler for this signal will normally be responsible
605    /// for inserting the text, so by connecting to this signal and then
606    /// stopping the signal with g_signal_stop_emission(), it is possible
607    /// to modify the inserted text, or prevent it from being inserted entirely.
608    ///
609    ///
610    /// </details>
611    ///
612    /// # Implements
613    ///
614    /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`EditableExt`][trait@crate::prelude::EditableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual], [`EditableExtManual`][trait@crate::prelude::EditableExtManual]
615    #[doc(alias = "GtkPasswordEntry")]
616    pub struct PasswordEntry(Object<ffi::GtkPasswordEntry, ffi::GtkPasswordEntryClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Editable;
617
618    match fn {
619        type_ => || ffi::gtk_password_entry_get_type(),
620    }
621}
622
623impl PasswordEntry {
624    /// Creates a [`PasswordEntry`][crate::PasswordEntry].
625    ///
626    /// # Returns
627    ///
628    /// a new [`PasswordEntry`][crate::PasswordEntry]
629    #[doc(alias = "gtk_password_entry_new")]
630    pub fn new() -> PasswordEntry {
631        assert_initialized_main_thread!();
632        unsafe { Widget::from_glib_none(ffi::gtk_password_entry_new()).unsafe_cast() }
633    }
634
635    // rustdoc-stripper-ignore-next
636    /// Creates a new builder-pattern struct instance to construct [`PasswordEntry`] objects.
637    ///
638    /// This method returns an instance of [`PasswordEntryBuilder`](crate::builders::PasswordEntryBuilder) which can be used to create [`PasswordEntry`] objects.
639    pub fn builder() -> PasswordEntryBuilder {
640        PasswordEntryBuilder::new()
641    }
642
643    /// Gets the menu model set with gtk_password_entry_set_extra_menu().
644    ///
645    /// # Returns
646    ///
647    /// the menu model
648    #[doc(alias = "gtk_password_entry_get_extra_menu")]
649    #[doc(alias = "get_extra_menu")]
650    #[doc(alias = "extra-menu")]
651    pub fn extra_menu(&self) -> Option<gio::MenuModel> {
652        unsafe {
653            from_glib_none(ffi::gtk_password_entry_get_extra_menu(
654                self.to_glib_none().0,
655            ))
656        }
657    }
658
659    /// Returns whether the entry is showing an icon to
660    /// reveal the contents.
661    ///
662    /// # Returns
663    ///
664    /// [`true`] if an icon is shown
665    #[doc(alias = "gtk_password_entry_get_show_peek_icon")]
666    #[doc(alias = "get_show_peek_icon")]
667    #[doc(alias = "show-peek-icon")]
668    pub fn shows_peek_icon(&self) -> bool {
669        unsafe {
670            from_glib(ffi::gtk_password_entry_get_show_peek_icon(
671                self.to_glib_none().0,
672            ))
673        }
674    }
675
676    /// Sets a menu model to add when constructing
677    /// the context menu for @self.
678    /// ## `model`
679    /// a `GMenuModel`
680    #[doc(alias = "gtk_password_entry_set_extra_menu")]
681    #[doc(alias = "extra-menu")]
682    pub fn set_extra_menu(&self, model: Option<&impl IsA<gio::MenuModel>>) {
683        unsafe {
684            ffi::gtk_password_entry_set_extra_menu(
685                self.to_glib_none().0,
686                model.map(|p| p.as_ref()).to_glib_none().0,
687            );
688        }
689    }
690
691    /// Sets whether the entry should have a clickable icon
692    /// to reveal the contents.
693    ///
694    /// Setting this to [`false`] also hides the text again.
695    /// ## `show_peek_icon`
696    /// whether to show the peek icon
697    #[doc(alias = "gtk_password_entry_set_show_peek_icon")]
698    #[doc(alias = "show-peek-icon")]
699    pub fn set_show_peek_icon(&self, show_peek_icon: bool) {
700        unsafe {
701            ffi::gtk_password_entry_set_show_peek_icon(
702                self.to_glib_none().0,
703                show_peek_icon.into_glib(),
704            );
705        }
706    }
707
708    /// Whether to activate the default widget when Enter is pressed.
709    #[doc(alias = "activates-default")]
710    pub fn activates_default(&self) -> bool {
711        ObjectExt::property(self, "activates-default")
712    }
713
714    /// Whether to activate the default widget when Enter is pressed.
715    #[doc(alias = "activates-default")]
716    pub fn set_activates_default(&self, activates_default: bool) {
717        ObjectExt::set_property(self, "activates-default", activates_default)
718    }
719
720    /// The text that will be displayed in the [`PasswordEntry`][crate::PasswordEntry]
721    /// when it is empty and unfocused.
722    #[doc(alias = "placeholder-text")]
723    pub fn placeholder_text(&self) -> Option<glib::GString> {
724        ObjectExt::property(self, "placeholder-text")
725    }
726
727    /// The text that will be displayed in the [`PasswordEntry`][crate::PasswordEntry]
728    /// when it is empty and unfocused.
729    #[doc(alias = "placeholder-text")]
730    pub fn set_placeholder_text(&self, placeholder_text: Option<&str>) {
731        ObjectExt::set_property(self, "placeholder-text", placeholder_text)
732    }
733
734    /// Emitted when the entry is activated.
735    ///
736    /// The keybindings for this signal are all forms of the Enter key.
737    #[doc(alias = "activate")]
738    pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
739        unsafe extern "C" fn activate_trampoline<F: Fn(&PasswordEntry) + 'static>(
740            this: *mut ffi::GtkPasswordEntry,
741            f: glib::ffi::gpointer,
742        ) {
743            let f: &F = &*(f as *const F);
744            f(&from_glib_borrow(this))
745        }
746        unsafe {
747            let f: Box_<F> = Box_::new(f);
748            connect_raw(
749                self.as_ptr() as *mut _,
750                c"activate".as_ptr() as *const _,
751                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
752                    activate_trampoline::<F> as *const (),
753                )),
754                Box_::into_raw(f),
755            )
756        }
757    }
758
759    pub fn emit_activate(&self) {
760        self.emit_by_name::<()>("activate", &[]);
761    }
762
763    #[doc(alias = "activates-default")]
764    pub fn connect_activates_default_notify<F: Fn(&Self) + 'static>(
765        &self,
766        f: F,
767    ) -> SignalHandlerId {
768        unsafe extern "C" fn notify_activates_default_trampoline<
769            F: Fn(&PasswordEntry) + 'static,
770        >(
771            this: *mut ffi::GtkPasswordEntry,
772            _param_spec: glib::ffi::gpointer,
773            f: glib::ffi::gpointer,
774        ) {
775            let f: &F = &*(f as *const F);
776            f(&from_glib_borrow(this))
777        }
778        unsafe {
779            let f: Box_<F> = Box_::new(f);
780            connect_raw(
781                self.as_ptr() as *mut _,
782                c"notify::activates-default".as_ptr() as *const _,
783                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
784                    notify_activates_default_trampoline::<F> as *const (),
785                )),
786                Box_::into_raw(f),
787            )
788        }
789    }
790
791    #[doc(alias = "extra-menu")]
792    pub fn connect_extra_menu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
793        unsafe extern "C" fn notify_extra_menu_trampoline<F: Fn(&PasswordEntry) + 'static>(
794            this: *mut ffi::GtkPasswordEntry,
795            _param_spec: glib::ffi::gpointer,
796            f: glib::ffi::gpointer,
797        ) {
798            let f: &F = &*(f as *const F);
799            f(&from_glib_borrow(this))
800        }
801        unsafe {
802            let f: Box_<F> = Box_::new(f);
803            connect_raw(
804                self.as_ptr() as *mut _,
805                c"notify::extra-menu".as_ptr() as *const _,
806                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
807                    notify_extra_menu_trampoline::<F> as *const (),
808                )),
809                Box_::into_raw(f),
810            )
811        }
812    }
813
814    #[doc(alias = "placeholder-text")]
815    pub fn connect_placeholder_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
816        unsafe extern "C" fn notify_placeholder_text_trampoline<F: Fn(&PasswordEntry) + 'static>(
817            this: *mut ffi::GtkPasswordEntry,
818            _param_spec: glib::ffi::gpointer,
819            f: glib::ffi::gpointer,
820        ) {
821            let f: &F = &*(f as *const F);
822            f(&from_glib_borrow(this))
823        }
824        unsafe {
825            let f: Box_<F> = Box_::new(f);
826            connect_raw(
827                self.as_ptr() as *mut _,
828                c"notify::placeholder-text".as_ptr() as *const _,
829                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
830                    notify_placeholder_text_trampoline::<F> as *const (),
831                )),
832                Box_::into_raw(f),
833            )
834        }
835    }
836
837    #[doc(alias = "show-peek-icon")]
838    pub fn connect_show_peek_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
839        unsafe extern "C" fn notify_show_peek_icon_trampoline<F: Fn(&PasswordEntry) + 'static>(
840            this: *mut ffi::GtkPasswordEntry,
841            _param_spec: glib::ffi::gpointer,
842            f: glib::ffi::gpointer,
843        ) {
844            let f: &F = &*(f as *const F);
845            f(&from_glib_borrow(this))
846        }
847        unsafe {
848            let f: Box_<F> = Box_::new(f);
849            connect_raw(
850                self.as_ptr() as *mut _,
851                c"notify::show-peek-icon".as_ptr() as *const _,
852                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
853                    notify_show_peek_icon_trampoline::<F> as *const (),
854                )),
855                Box_::into_raw(f),
856            )
857        }
858    }
859}
860
861impl Default for PasswordEntry {
862    fn default() -> Self {
863        Self::new()
864    }
865}
866
867// rustdoc-stripper-ignore-next
868/// A [builder-pattern] type to construct [`PasswordEntry`] objects.
869///
870/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
871#[must_use = "The builder must be built to be used"]
872pub struct PasswordEntryBuilder {
873    builder: glib::object::ObjectBuilder<'static, PasswordEntry>,
874}
875
876impl PasswordEntryBuilder {
877    fn new() -> Self {
878        Self {
879            builder: glib::object::Object::builder(),
880        }
881    }
882
883    /// Whether to activate the default widget when Enter is pressed.
884    pub fn activates_default(self, activates_default: bool) -> Self {
885        Self {
886            builder: self
887                .builder
888                .property("activates-default", activates_default),
889        }
890    }
891
892    /// A menu model whose contents will be appended to
893    /// the context menu.
894    pub fn extra_menu(self, extra_menu: &impl IsA<gio::MenuModel>) -> Self {
895        Self {
896            builder: self
897                .builder
898                .property("extra-menu", extra_menu.clone().upcast()),
899        }
900    }
901
902    /// The text that will be displayed in the [`PasswordEntry`][crate::PasswordEntry]
903    /// when it is empty and unfocused.
904    pub fn placeholder_text(self, placeholder_text: impl Into<glib::GString>) -> Self {
905        Self {
906            builder: self
907                .builder
908                .property("placeholder-text", placeholder_text.into()),
909        }
910    }
911
912    /// Whether to show an icon for revealing the content.
913    pub fn show_peek_icon(self, show_peek_icon: bool) -> Self {
914        Self {
915            builder: self.builder.property("show-peek-icon", show_peek_icon),
916        }
917    }
918
919    /// Whether the widget or any of its descendents can accept
920    /// the input focus.
921    ///
922    /// This property is meant to be set by widget implementations,
923    /// typically in their instance init function.
924    pub fn can_focus(self, can_focus: bool) -> Self {
925        Self {
926            builder: self.builder.property("can-focus", can_focus),
927        }
928    }
929
930    /// Whether the widget can receive pointer events.
931    pub fn can_target(self, can_target: bool) -> Self {
932        Self {
933            builder: self.builder.property("can-target", can_target),
934        }
935    }
936
937    /// A list of css classes applied to this widget.
938    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
939        Self {
940            builder: self.builder.property("css-classes", css_classes.into()),
941        }
942    }
943
944    /// The name of this widget in the CSS tree.
945    ///
946    /// This property is meant to be set by widget implementations,
947    /// typically in their instance init function.
948    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
949        Self {
950            builder: self.builder.property("css-name", css_name.into()),
951        }
952    }
953
954    /// The cursor used by @widget.
955    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
956        Self {
957            builder: self.builder.property("cursor", cursor.clone()),
958        }
959    }
960
961    /// Whether the widget should grab focus when it is clicked with the mouse.
962    ///
963    /// This property is only relevant for widgets that can take focus.
964    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
965        Self {
966            builder: self.builder.property("focus-on-click", focus_on_click),
967        }
968    }
969
970    /// Whether this widget itself will accept the input focus.
971    pub fn focusable(self, focusable: bool) -> Self {
972        Self {
973            builder: self.builder.property("focusable", focusable),
974        }
975    }
976
977    /// How to distribute horizontal space if widget gets extra space.
978    pub fn halign(self, halign: Align) -> Self {
979        Self {
980            builder: self.builder.property("halign", halign),
981        }
982    }
983
984    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
985    /// signal on @widget.
986    ///
987    /// A true value indicates that @widget can have a tooltip, in this case
988    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
989    /// determine whether it will provide a tooltip or not.
990    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
991        Self {
992            builder: self.builder.property("has-tooltip", has_tooltip),
993        }
994    }
995
996    /// Overrides for height request of the widget.
997    ///
998    /// If this is -1, the natural request will be used.
999    pub fn height_request(self, height_request: i32) -> Self {
1000        Self {
1001            builder: self.builder.property("height-request", height_request),
1002        }
1003    }
1004
1005    /// Whether to expand horizontally.
1006    pub fn hexpand(self, hexpand: bool) -> Self {
1007        Self {
1008            builder: self.builder.property("hexpand", hexpand),
1009        }
1010    }
1011
1012    /// Whether to use the `hexpand` property.
1013    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1014        Self {
1015            builder: self.builder.property("hexpand-set", hexpand_set),
1016        }
1017    }
1018
1019    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
1020    /// the preferred size of the widget, and allocate its children.
1021    ///
1022    /// This property is meant to be set by widget implementations,
1023    /// typically in their instance init function.
1024    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
1025        Self {
1026            builder: self
1027                .builder
1028                .property("layout-manager", layout_manager.clone().upcast()),
1029        }
1030    }
1031
1032    /// Makes this widget act like a modal dialog, with respect to
1033    /// event delivery.
1034    ///
1035    /// Global event controllers will not handle events with targets
1036    /// inside the widget, unless they are set up to ignore propagation
1037    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1038    #[cfg(feature = "v4_18")]
1039    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1040    pub fn limit_events(self, limit_events: bool) -> Self {
1041        Self {
1042            builder: self.builder.property("limit-events", limit_events),
1043        }
1044    }
1045
1046    /// Margin on bottom side of widget.
1047    ///
1048    /// This property adds margin outside of the widget's normal size
1049    /// request, the margin will be added in addition to the size from
1050    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1051    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1052        Self {
1053            builder: self.builder.property("margin-bottom", margin_bottom),
1054        }
1055    }
1056
1057    /// Margin on end of widget, horizontally.
1058    ///
1059    /// This property supports left-to-right and right-to-left text
1060    /// directions.
1061    ///
1062    /// This property adds margin outside of the widget's normal size
1063    /// request, the margin will be added in addition to the size from
1064    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1065    pub fn margin_end(self, margin_end: i32) -> Self {
1066        Self {
1067            builder: self.builder.property("margin-end", margin_end),
1068        }
1069    }
1070
1071    /// Margin on start of widget, horizontally.
1072    ///
1073    /// This property supports left-to-right and right-to-left text
1074    /// directions.
1075    ///
1076    /// This property adds margin outside of the widget's normal size
1077    /// request, the margin will be added in addition to the size from
1078    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1079    pub fn margin_start(self, margin_start: i32) -> Self {
1080        Self {
1081            builder: self.builder.property("margin-start", margin_start),
1082        }
1083    }
1084
1085    /// Margin on top side of widget.
1086    ///
1087    /// This property adds margin outside of the widget's normal size
1088    /// request, the margin will be added in addition to the size from
1089    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1090    pub fn margin_top(self, margin_top: i32) -> Self {
1091        Self {
1092            builder: self.builder.property("margin-top", margin_top),
1093        }
1094    }
1095
1096    /// The name of the widget.
1097    pub fn name(self, name: impl Into<glib::GString>) -> Self {
1098        Self {
1099            builder: self.builder.property("name", name.into()),
1100        }
1101    }
1102
1103    /// The requested opacity of the widget.
1104    pub fn opacity(self, opacity: f64) -> Self {
1105        Self {
1106            builder: self.builder.property("opacity", opacity),
1107        }
1108    }
1109
1110    /// How content outside the widget's content area is treated.
1111    ///
1112    /// This property is meant to be set by widget implementations,
1113    /// typically in their instance init function.
1114    pub fn overflow(self, overflow: Overflow) -> Self {
1115        Self {
1116            builder: self.builder.property("overflow", overflow),
1117        }
1118    }
1119
1120    /// Whether the widget will receive the default action when it is focused.
1121    pub fn receives_default(self, receives_default: bool) -> Self {
1122        Self {
1123            builder: self.builder.property("receives-default", receives_default),
1124        }
1125    }
1126
1127    /// Whether the widget responds to input.
1128    pub fn sensitive(self, sensitive: bool) -> Self {
1129        Self {
1130            builder: self.builder.property("sensitive", sensitive),
1131        }
1132    }
1133
1134    /// Sets the text of tooltip to be the given string, which is marked up
1135    /// with Pango markup.
1136    ///
1137    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1138    ///
1139    /// This is a convenience property which will take care of getting the
1140    /// tooltip shown if the given string is not `NULL`:
1141    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1142    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1143    /// the default signal handler.
1144    ///
1145    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1146    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1147    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1148        Self {
1149            builder: self
1150                .builder
1151                .property("tooltip-markup", tooltip_markup.into()),
1152        }
1153    }
1154
1155    /// Sets the text of tooltip to be the given string.
1156    ///
1157    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1158    ///
1159    /// This is a convenience property which will take care of getting the
1160    /// tooltip shown if the given string is not `NULL`:
1161    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1162    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1163    /// the default signal handler.
1164    ///
1165    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1166    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1167    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1168        Self {
1169            builder: self.builder.property("tooltip-text", tooltip_text.into()),
1170        }
1171    }
1172
1173    /// How to distribute vertical space if widget gets extra space.
1174    pub fn valign(self, valign: Align) -> Self {
1175        Self {
1176            builder: self.builder.property("valign", valign),
1177        }
1178    }
1179
1180    /// Whether to expand vertically.
1181    pub fn vexpand(self, vexpand: bool) -> Self {
1182        Self {
1183            builder: self.builder.property("vexpand", vexpand),
1184        }
1185    }
1186
1187    /// Whether to use the `vexpand` property.
1188    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1189        Self {
1190            builder: self.builder.property("vexpand-set", vexpand_set),
1191        }
1192    }
1193
1194    /// Whether the widget is visible.
1195    pub fn visible(self, visible: bool) -> Self {
1196        Self {
1197            builder: self.builder.property("visible", visible),
1198        }
1199    }
1200
1201    /// Overrides for width request of the widget.
1202    ///
1203    /// If this is -1, the natural request will be used.
1204    pub fn width_request(self, width_request: i32) -> Self {
1205        Self {
1206            builder: self.builder.property("width-request", width_request),
1207        }
1208    }
1209
1210    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1211    ///
1212    /// The accessible role cannot be changed once set.
1213    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1214        Self {
1215            builder: self.builder.property("accessible-role", accessible_role),
1216        }
1217    }
1218
1219    /// Whether the entry contents can be edited.
1220    pub fn editable(self, editable: bool) -> Self {
1221        Self {
1222            builder: self.builder.property("editable", editable),
1223        }
1224    }
1225
1226    /// If undo/redo should be enabled for the editable.
1227    pub fn enable_undo(self, enable_undo: bool) -> Self {
1228        Self {
1229            builder: self.builder.property("enable-undo", enable_undo),
1230        }
1231    }
1232
1233    /// The desired maximum width of the entry, in characters.
1234    pub fn max_width_chars(self, max_width_chars: i32) -> Self {
1235        Self {
1236            builder: self.builder.property("max-width-chars", max_width_chars),
1237        }
1238    }
1239
1240    /// The contents of the entry.
1241    pub fn text(self, text: impl Into<glib::GString>) -> Self {
1242        Self {
1243            builder: self.builder.property("text", text.into()),
1244        }
1245    }
1246
1247    /// Number of characters to leave space for in the entry.
1248    pub fn width_chars(self, width_chars: i32) -> Self {
1249        Self {
1250            builder: self.builder.property("width-chars", width_chars),
1251        }
1252    }
1253
1254    /// The horizontal alignment, from 0 (left) to 1 (right).
1255    ///
1256    /// Reversed for RTL layouts.
1257    pub fn xalign(self, xalign: f32) -> Self {
1258        Self {
1259            builder: self.builder.property("xalign", xalign),
1260        }
1261    }
1262
1263    // rustdoc-stripper-ignore-next
1264    /// Build the [`PasswordEntry`].
1265    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1266    pub fn build(self) -> PasswordEntry {
1267        assert_initialized_main_thread!();
1268        self.builder.build()
1269    }
1270}