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