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 Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, Editable, LayoutManager,
7 Overflow, Widget, ffi,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{SignalHandlerId, connect_raw},
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 /// #### `complete-text`
384 /// The contents of the entry, including uncommited content such as the
385 /// preedit.
386 ///
387 /// Readable
388 ///
389 ///
390 /// #### `cursor-position`
391 /// The current position of the insertion cursor in chars.
392 ///
393 /// Readable
394 ///
395 ///
396 /// #### `editable`
397 /// Whether the entry contents can be edited.
398 ///
399 /// Readable | Writeable
400 ///
401 ///
402 /// #### `enable-undo`
403 /// If undo/redo should be enabled for the editable.
404 ///
405 /// Readable | Writeable
406 ///
407 ///
408 /// #### `max-width-chars`
409 /// The desired maximum width of the entry, in characters.
410 ///
411 /// Readable | Writeable
412 ///
413 ///
414 /// #### `selection-bound`
415 /// The position of the opposite end of the selection from the cursor in chars.
416 ///
417 /// Readable
418 ///
419 ///
420 /// #### `text`
421 /// The contents of the entry.
422 ///
423 /// Readable | Writeable
424 ///
425 ///
426 /// #### `width-chars`
427 /// Number of characters to leave space for in the entry.
428 ///
429 /// Readable | Writeable
430 ///
431 ///
432 /// #### `xalign`
433 /// The horizontal alignment, from 0 (left) to 1 (right).
434 ///
435 /// Reversed for RTL layouts.
436 ///
437 /// Readable | Writeable
438 /// </details>
439 ///
440 /// ## Signals
441 ///
442 ///
443 /// #### `activate`
444 /// Emitted when the entry is activated.
445 ///
446 /// The keybindings for this signal are all forms of the Enter key.
447 ///
448 /// Action
449 /// <details><summary><h4>Widget</h4></summary>
450 ///
451 ///
452 /// #### `destroy`
453 /// Signals that all holders of a reference to the widget should release
454 /// the reference that they hold.
455 ///
456 /// May result in finalization of the widget if all references are released.
457 ///
458 /// This signal is not suitable for saving widget state.
459 ///
460 ///
461 ///
462 ///
463 /// #### `direction-changed`
464 /// Emitted when the text direction of a widget changes.
465 ///
466 ///
467 ///
468 ///
469 /// #### `hide`
470 /// Emitted when @widget is hidden.
471 ///
472 ///
473 ///
474 ///
475 /// #### `keynav-failed`
476 /// Emitted if keyboard navigation fails.
477 ///
478 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
479 ///
480 ///
481 ///
482 ///
483 /// #### `map`
484 /// Emitted when @widget is going to be mapped.
485 ///
486 /// A widget is mapped when the widget is visible (which is controlled with
487 /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
488 /// are also visible.
489 ///
490 /// The `::map` signal can be used to determine whether a widget will be drawn,
491 /// for instance it can resume an animation that was stopped during the
492 /// emission of [`unmap`][struct@crate::Widget#unmap].
493 ///
494 ///
495 ///
496 ///
497 /// #### `mnemonic-activate`
498 /// Emitted when a widget is activated via a mnemonic.
499 ///
500 /// The default handler for this signal activates @widget if @group_cycling
501 /// is false, or just makes @widget grab focus if @group_cycling is true.
502 ///
503 ///
504 ///
505 ///
506 /// #### `move-focus`
507 /// Emitted when the focus is moved.
508 ///
509 /// The `::move-focus` signal is a [keybinding signal](class.SignalAction.html).
510 ///
511 /// The default bindings for this signal are <kbd>Tab</kbd> to move forward,
512 /// and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
513 ///
514 /// Action
515 ///
516 ///
517 /// #### `query-tooltip`
518 /// Emitted when the widget’s tooltip is about to be shown.
519 ///
520 /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
521 /// is true and the hover timeout has expired with the cursor hovering
522 /// above @widget; or emitted when @widget got focus in keyboard mode.
523 ///
524 /// Using the given coordinates, the signal handler should determine
525 /// whether a tooltip should be shown for @widget. If this is the case
526 /// true should be returned, false otherwise. Note that if @keyboard_mode
527 /// is true, the values of @x and @y are undefined and should not be used.
528 ///
529 /// The signal handler is free to manipulate @tooltip with the therefore
530 /// destined function calls.
531 ///
532 ///
533 ///
534 ///
535 /// #### `realize`
536 /// Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
537 ///
538 /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
539 /// or the widget has been mapped (that is, it is going to be drawn).
540 ///
541 ///
542 ///
543 ///
544 /// #### `show`
545 /// Emitted when @widget is shown.
546 ///
547 ///
548 ///
549 ///
550 /// #### `state-flags-changed`
551 /// Emitted when the widget state changes.
552 ///
553 /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
554 ///
555 ///
556 ///
557 ///
558 /// #### `unmap`
559 /// Emitted when @widget is going to be unmapped.
560 ///
561 /// A widget is unmapped when either it or any of its parents up to the
562 /// toplevel widget have been set as hidden.
563 ///
564 /// As `::unmap` indicates that a widget will not be shown any longer,
565 /// it can be used to, for example, stop an animation on the widget.
566 ///
567 ///
568 ///
569 ///
570 /// #### `unrealize`
571 /// Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
572 ///
573 /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
574 /// or the widget has been unmapped (that is, it is going to be hidden).
575 ///
576 ///
577 /// </details>
578 /// <details><summary><h4>Editable</h4></summary>
579 ///
580 ///
581 /// #### `changed`
582 /// Emitted at the end of a single user-visible operation on the
583 /// contents.
584 ///
585 /// E.g., a paste operation that replaces the contents of the
586 /// selection will cause only one signal emission (even though it
587 /// is implemented by first deleting the selection, then inserting
588 /// the new content, and may cause multiple ::notify::text signals
589 /// to be emitted).
590 ///
591 ///
592 ///
593 ///
594 /// #### `delete-text`
595 /// Emitted when text is deleted from the widget by the user.
596 ///
597 /// The default handler for this signal will normally be responsible for
598 /// deleting the text, so by connecting to this signal and then stopping
599 /// the signal with g_signal_stop_emission(), it is possible to modify the
600 /// range of deleted text, or prevent it from being deleted entirely.
601 ///
602 /// The @start_pos and @end_pos parameters are interpreted as for
603 /// [`EditableExt::delete_text()`][crate::prelude::EditableExt::delete_text()].
604 ///
605 ///
606 ///
607 ///
608 /// #### `insert-text`
609 /// Emitted when text is inserted into the widget by the user.
610 ///
611 /// The default handler for this signal will normally be responsible
612 /// for inserting the text, so by connecting to this signal and then
613 /// stopping the signal with g_signal_stop_emission(), it is possible
614 /// to modify the inserted text, or prevent it from being inserted entirely.
615 ///
616 ///
617 /// </details>
618 ///
619 /// # Implements
620 ///
621 /// [`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]
622 #[doc(alias = "GtkPasswordEntry")]
623 pub struct PasswordEntry(Object<ffi::GtkPasswordEntry, ffi::GtkPasswordEntryClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Editable;
624
625 match fn {
626 type_ => || ffi::gtk_password_entry_get_type(),
627 }
628}
629
630impl PasswordEntry {
631 /// Creates a [`PasswordEntry`][crate::PasswordEntry].
632 ///
633 /// # Returns
634 ///
635 /// a new [`PasswordEntry`][crate::PasswordEntry]
636 #[doc(alias = "gtk_password_entry_new")]
637 pub fn new() -> PasswordEntry {
638 assert_initialized_main_thread!();
639 unsafe { Widget::from_glib_none(ffi::gtk_password_entry_new()).unsafe_cast() }
640 }
641
642 // rustdoc-stripper-ignore-next
643 /// Creates a new builder-pattern struct instance to construct [`PasswordEntry`] objects.
644 ///
645 /// This method returns an instance of [`PasswordEntryBuilder`](crate::builders::PasswordEntryBuilder) which can be used to create [`PasswordEntry`] objects.
646 pub fn builder() -> PasswordEntryBuilder {
647 PasswordEntryBuilder::new()
648 }
649
650 /// Gets the menu model set with gtk_password_entry_set_extra_menu().
651 ///
652 /// # Returns
653 ///
654 /// the menu model
655 #[doc(alias = "gtk_password_entry_get_extra_menu")]
656 #[doc(alias = "get_extra_menu")]
657 #[doc(alias = "extra-menu")]
658 pub fn extra_menu(&self) -> Option<gio::MenuModel> {
659 unsafe {
660 from_glib_none(ffi::gtk_password_entry_get_extra_menu(
661 self.to_glib_none().0,
662 ))
663 }
664 }
665
666 /// Returns whether the entry is showing an icon to
667 /// reveal the contents.
668 ///
669 /// # Returns
670 ///
671 /// [`true`] if an icon is shown
672 #[doc(alias = "gtk_password_entry_get_show_peek_icon")]
673 #[doc(alias = "get_show_peek_icon")]
674 #[doc(alias = "show-peek-icon")]
675 pub fn shows_peek_icon(&self) -> bool {
676 unsafe {
677 from_glib(ffi::gtk_password_entry_get_show_peek_icon(
678 self.to_glib_none().0,
679 ))
680 }
681 }
682
683 /// Sets a menu model to add when constructing
684 /// the context menu for @self.
685 /// ## `model`
686 /// a `GMenuModel`
687 #[doc(alias = "gtk_password_entry_set_extra_menu")]
688 #[doc(alias = "extra-menu")]
689 pub fn set_extra_menu(&self, model: Option<&impl IsA<gio::MenuModel>>) {
690 unsafe {
691 ffi::gtk_password_entry_set_extra_menu(
692 self.to_glib_none().0,
693 model.map(|p| p.as_ref()).to_glib_none().0,
694 );
695 }
696 }
697
698 /// Sets whether the entry should have a clickable icon
699 /// to reveal the contents.
700 ///
701 /// Setting this to [`false`] also hides the text again.
702 /// ## `show_peek_icon`
703 /// whether to show the peek icon
704 #[doc(alias = "gtk_password_entry_set_show_peek_icon")]
705 #[doc(alias = "show-peek-icon")]
706 pub fn set_show_peek_icon(&self, show_peek_icon: bool) {
707 unsafe {
708 ffi::gtk_password_entry_set_show_peek_icon(
709 self.to_glib_none().0,
710 show_peek_icon.into_glib(),
711 );
712 }
713 }
714
715 /// Whether to activate the default widget when Enter is pressed.
716 #[doc(alias = "activates-default")]
717 pub fn activates_default(&self) -> bool {
718 ObjectExt::property(self, "activates-default")
719 }
720
721 /// Whether to activate the default widget when Enter is pressed.
722 #[doc(alias = "activates-default")]
723 pub fn set_activates_default(&self, activates_default: bool) {
724 ObjectExt::set_property(self, "activates-default", activates_default)
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 placeholder_text(&self) -> Option<glib::GString> {
731 ObjectExt::property(self, "placeholder-text")
732 }
733
734 /// The text that will be displayed in the [`PasswordEntry`][crate::PasswordEntry]
735 /// when it is empty and unfocused.
736 #[doc(alias = "placeholder-text")]
737 pub fn set_placeholder_text(&self, placeholder_text: Option<&str>) {
738 ObjectExt::set_property(self, "placeholder-text", placeholder_text)
739 }
740
741 /// Emitted when the entry is activated.
742 ///
743 /// The keybindings for this signal are all forms of the Enter key.
744 #[doc(alias = "activate")]
745 pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
746 unsafe extern "C" fn activate_trampoline<F: Fn(&PasswordEntry) + 'static>(
747 this: *mut ffi::GtkPasswordEntry,
748 f: glib::ffi::gpointer,
749 ) {
750 unsafe {
751 let f: &F = &*(f as *const F);
752 f(&from_glib_borrow(this))
753 }
754 }
755 unsafe {
756 let f: Box_<F> = Box_::new(f);
757 connect_raw(
758 self.as_ptr() as *mut _,
759 c"activate".as_ptr(),
760 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
761 activate_trampoline::<F> as *const (),
762 )),
763 Box_::into_raw(f),
764 )
765 }
766 }
767
768 pub fn emit_activate(&self) {
769 self.emit_by_name::<()>("activate", &[]);
770 }
771
772 #[doc(alias = "activates-default")]
773 pub fn connect_activates_default_notify<F: Fn(&Self) + 'static>(
774 &self,
775 f: F,
776 ) -> SignalHandlerId {
777 unsafe extern "C" fn notify_activates_default_trampoline<
778 F: Fn(&PasswordEntry) + 'static,
779 >(
780 this: *mut ffi::GtkPasswordEntry,
781 _param_spec: glib::ffi::gpointer,
782 f: glib::ffi::gpointer,
783 ) {
784 unsafe {
785 let f: &F = &*(f as *const F);
786 f(&from_glib_borrow(this))
787 }
788 }
789 unsafe {
790 let f: Box_<F> = Box_::new(f);
791 connect_raw(
792 self.as_ptr() as *mut _,
793 c"notify::activates-default".as_ptr(),
794 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
795 notify_activates_default_trampoline::<F> as *const (),
796 )),
797 Box_::into_raw(f),
798 )
799 }
800 }
801
802 #[doc(alias = "extra-menu")]
803 pub fn connect_extra_menu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
804 unsafe extern "C" fn notify_extra_menu_trampoline<F: Fn(&PasswordEntry) + 'static>(
805 this: *mut ffi::GtkPasswordEntry,
806 _param_spec: glib::ffi::gpointer,
807 f: glib::ffi::gpointer,
808 ) {
809 unsafe {
810 let f: &F = &*(f as *const F);
811 f(&from_glib_borrow(this))
812 }
813 }
814 unsafe {
815 let f: Box_<F> = Box_::new(f);
816 connect_raw(
817 self.as_ptr() as *mut _,
818 c"notify::extra-menu".as_ptr(),
819 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
820 notify_extra_menu_trampoline::<F> as *const (),
821 )),
822 Box_::into_raw(f),
823 )
824 }
825 }
826
827 #[doc(alias = "placeholder-text")]
828 pub fn connect_placeholder_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
829 unsafe extern "C" fn notify_placeholder_text_trampoline<F: Fn(&PasswordEntry) + 'static>(
830 this: *mut ffi::GtkPasswordEntry,
831 _param_spec: glib::ffi::gpointer,
832 f: glib::ffi::gpointer,
833 ) {
834 unsafe {
835 let f: &F = &*(f as *const F);
836 f(&from_glib_borrow(this))
837 }
838 }
839 unsafe {
840 let f: Box_<F> = Box_::new(f);
841 connect_raw(
842 self.as_ptr() as *mut _,
843 c"notify::placeholder-text".as_ptr(),
844 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
845 notify_placeholder_text_trampoline::<F> as *const (),
846 )),
847 Box_::into_raw(f),
848 )
849 }
850 }
851
852 #[doc(alias = "show-peek-icon")]
853 pub fn connect_show_peek_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
854 unsafe extern "C" fn notify_show_peek_icon_trampoline<F: Fn(&PasswordEntry) + 'static>(
855 this: *mut ffi::GtkPasswordEntry,
856 _param_spec: glib::ffi::gpointer,
857 f: glib::ffi::gpointer,
858 ) {
859 unsafe {
860 let f: &F = &*(f as *const F);
861 f(&from_glib_borrow(this))
862 }
863 }
864 unsafe {
865 let f: Box_<F> = Box_::new(f);
866 connect_raw(
867 self.as_ptr() as *mut _,
868 c"notify::show-peek-icon".as_ptr(),
869 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
870 notify_show_peek_icon_trampoline::<F> as *const (),
871 )),
872 Box_::into_raw(f),
873 )
874 }
875 }
876}
877
878impl Default for PasswordEntry {
879 fn default() -> Self {
880 Self::new()
881 }
882}
883
884// rustdoc-stripper-ignore-next
885/// A [builder-pattern] type to construct [`PasswordEntry`] objects.
886///
887/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
888#[must_use = "The builder must be built to be used"]
889pub struct PasswordEntryBuilder {
890 builder: glib::object::ObjectBuilder<'static, PasswordEntry>,
891}
892
893impl PasswordEntryBuilder {
894 fn new() -> Self {
895 Self {
896 builder: glib::object::Object::builder(),
897 }
898 }
899
900 /// Whether to activate the default widget when Enter is pressed.
901 pub fn activates_default(self, activates_default: bool) -> Self {
902 Self {
903 builder: self
904 .builder
905 .property("activates-default", activates_default),
906 }
907 }
908
909 /// A menu model whose contents will be appended to
910 /// the context menu.
911 pub fn extra_menu(self, extra_menu: &impl IsA<gio::MenuModel>) -> Self {
912 Self {
913 builder: self
914 .builder
915 .property("extra-menu", extra_menu.clone().upcast()),
916 }
917 }
918
919 /// The text that will be displayed in the [`PasswordEntry`][crate::PasswordEntry]
920 /// when it is empty and unfocused.
921 pub fn placeholder_text(self, placeholder_text: impl Into<glib::GString>) -> Self {
922 Self {
923 builder: self
924 .builder
925 .property("placeholder-text", placeholder_text.into()),
926 }
927 }
928
929 /// Whether to show an icon for revealing the content.
930 pub fn show_peek_icon(self, show_peek_icon: bool) -> Self {
931 Self {
932 builder: self.builder.property("show-peek-icon", show_peek_icon),
933 }
934 }
935
936 /// Whether the widget or any of its descendents can accept
937 /// the input focus.
938 ///
939 /// This property is meant to be set by widget implementations,
940 /// typically in their instance init function.
941 pub fn can_focus(self, can_focus: bool) -> Self {
942 Self {
943 builder: self.builder.property("can-focus", can_focus),
944 }
945 }
946
947 /// Whether the widget can receive pointer events.
948 pub fn can_target(self, can_target: bool) -> Self {
949 Self {
950 builder: self.builder.property("can-target", can_target),
951 }
952 }
953
954 /// A list of css classes applied to this widget.
955 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
956 Self {
957 builder: self.builder.property("css-classes", css_classes.into()),
958 }
959 }
960
961 /// The name of this widget in the CSS tree.
962 ///
963 /// This property is meant to be set by widget implementations,
964 /// typically in their instance init function.
965 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
966 Self {
967 builder: self.builder.property("css-name", css_name.into()),
968 }
969 }
970
971 /// The cursor used by @widget.
972 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
973 Self {
974 builder: self.builder.property("cursor", cursor.clone()),
975 }
976 }
977
978 /// Whether the widget should grab focus when it is clicked with the mouse.
979 ///
980 /// This property is only relevant for widgets that can take focus.
981 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
982 Self {
983 builder: self.builder.property("focus-on-click", focus_on_click),
984 }
985 }
986
987 /// Whether this widget itself will accept the input focus.
988 pub fn focusable(self, focusable: bool) -> Self {
989 Self {
990 builder: self.builder.property("focusable", focusable),
991 }
992 }
993
994 /// How to distribute horizontal space if widget gets extra space.
995 pub fn halign(self, halign: Align) -> Self {
996 Self {
997 builder: self.builder.property("halign", halign),
998 }
999 }
1000
1001 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
1002 /// signal on @widget.
1003 ///
1004 /// A true value indicates that @widget can have a tooltip, in this case
1005 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
1006 /// determine whether it will provide a tooltip or not.
1007 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
1008 Self {
1009 builder: self.builder.property("has-tooltip", has_tooltip),
1010 }
1011 }
1012
1013 /// Overrides for height request of the widget.
1014 ///
1015 /// If this is -1, the natural request will be used.
1016 pub fn height_request(self, height_request: i32) -> Self {
1017 Self {
1018 builder: self.builder.property("height-request", height_request),
1019 }
1020 }
1021
1022 /// Whether to expand horizontally.
1023 pub fn hexpand(self, hexpand: bool) -> Self {
1024 Self {
1025 builder: self.builder.property("hexpand", hexpand),
1026 }
1027 }
1028
1029 /// Whether to use the `hexpand` property.
1030 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1031 Self {
1032 builder: self.builder.property("hexpand-set", hexpand_set),
1033 }
1034 }
1035
1036 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
1037 /// the preferred size of the widget, and allocate its children.
1038 ///
1039 /// This property is meant to be set by widget implementations,
1040 /// typically in their instance init function.
1041 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
1042 Self {
1043 builder: self
1044 .builder
1045 .property("layout-manager", layout_manager.clone().upcast()),
1046 }
1047 }
1048
1049 /// Makes this widget act like a modal dialog, with respect to
1050 /// event delivery.
1051 ///
1052 /// Global event controllers will not handle events with targets
1053 /// inside the widget, unless they are set up to ignore propagation
1054 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1055 #[cfg(feature = "v4_18")]
1056 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1057 pub fn limit_events(self, limit_events: bool) -> Self {
1058 Self {
1059 builder: self.builder.property("limit-events", limit_events),
1060 }
1061 }
1062
1063 /// Margin on bottom side of widget.
1064 ///
1065 /// This property adds margin outside of the widget's normal size
1066 /// request, the margin will be added in addition to the size from
1067 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1068 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1069 Self {
1070 builder: self.builder.property("margin-bottom", margin_bottom),
1071 }
1072 }
1073
1074 /// Margin on end of widget, horizontally.
1075 ///
1076 /// This property supports left-to-right and right-to-left text
1077 /// directions.
1078 ///
1079 /// This property adds margin outside of the widget's normal size
1080 /// request, the margin will be added in addition to the size from
1081 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1082 pub fn margin_end(self, margin_end: i32) -> Self {
1083 Self {
1084 builder: self.builder.property("margin-end", margin_end),
1085 }
1086 }
1087
1088 /// Margin on start of widget, horizontally.
1089 ///
1090 /// This property supports left-to-right and right-to-left text
1091 /// directions.
1092 ///
1093 /// This property adds margin outside of the widget's normal size
1094 /// request, the margin will be added in addition to the size from
1095 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1096 pub fn margin_start(self, margin_start: i32) -> Self {
1097 Self {
1098 builder: self.builder.property("margin-start", margin_start),
1099 }
1100 }
1101
1102 /// Margin on top side of widget.
1103 ///
1104 /// This property adds margin outside of the widget's normal size
1105 /// request, the margin will be added in addition to the size from
1106 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1107 pub fn margin_top(self, margin_top: i32) -> Self {
1108 Self {
1109 builder: self.builder.property("margin-top", margin_top),
1110 }
1111 }
1112
1113 /// The name of the widget.
1114 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1115 Self {
1116 builder: self.builder.property("name", name.into()),
1117 }
1118 }
1119
1120 /// The requested opacity of the widget.
1121 pub fn opacity(self, opacity: f64) -> Self {
1122 Self {
1123 builder: self.builder.property("opacity", opacity),
1124 }
1125 }
1126
1127 /// How content outside the widget's content area is treated.
1128 ///
1129 /// This property is meant to be set by widget implementations,
1130 /// typically in their instance init function.
1131 pub fn overflow(self, overflow: Overflow) -> Self {
1132 Self {
1133 builder: self.builder.property("overflow", overflow),
1134 }
1135 }
1136
1137 /// Whether the widget will receive the default action when it is focused.
1138 pub fn receives_default(self, receives_default: bool) -> Self {
1139 Self {
1140 builder: self.builder.property("receives-default", receives_default),
1141 }
1142 }
1143
1144 /// Whether the widget responds to input.
1145 pub fn sensitive(self, sensitive: bool) -> Self {
1146 Self {
1147 builder: self.builder.property("sensitive", sensitive),
1148 }
1149 }
1150
1151 /// Sets the text of tooltip to be the given string, which is marked up
1152 /// with Pango markup.
1153 ///
1154 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1155 ///
1156 /// This is a convenience property which will take care of getting the
1157 /// tooltip shown if the given string is not `NULL`:
1158 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1159 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1160 /// the default signal handler.
1161 ///
1162 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1163 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1164 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1165 Self {
1166 builder: self
1167 .builder
1168 .property("tooltip-markup", tooltip_markup.into()),
1169 }
1170 }
1171
1172 /// Sets the text of tooltip to be the given string.
1173 ///
1174 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1175 ///
1176 /// This is a convenience property which will take care of getting the
1177 /// tooltip shown if the given string is not `NULL`:
1178 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1179 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1180 /// the default signal handler.
1181 ///
1182 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1183 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1184 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1185 Self {
1186 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1187 }
1188 }
1189
1190 /// How to distribute vertical space if widget gets extra space.
1191 pub fn valign(self, valign: Align) -> Self {
1192 Self {
1193 builder: self.builder.property("valign", valign),
1194 }
1195 }
1196
1197 /// Whether to expand vertically.
1198 pub fn vexpand(self, vexpand: bool) -> Self {
1199 Self {
1200 builder: self.builder.property("vexpand", vexpand),
1201 }
1202 }
1203
1204 /// Whether to use the `vexpand` property.
1205 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1206 Self {
1207 builder: self.builder.property("vexpand-set", vexpand_set),
1208 }
1209 }
1210
1211 /// Whether the widget is visible.
1212 pub fn visible(self, visible: bool) -> Self {
1213 Self {
1214 builder: self.builder.property("visible", visible),
1215 }
1216 }
1217
1218 /// Overrides for width request of the widget.
1219 ///
1220 /// If this is -1, the natural request will be used.
1221 pub fn width_request(self, width_request: i32) -> Self {
1222 Self {
1223 builder: self.builder.property("width-request", width_request),
1224 }
1225 }
1226
1227 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1228 ///
1229 /// The accessible role cannot be changed once set.
1230 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1231 Self {
1232 builder: self.builder.property("accessible-role", accessible_role),
1233 }
1234 }
1235
1236 /// Whether the entry contents can be edited.
1237 pub fn editable(self, editable: bool) -> Self {
1238 Self {
1239 builder: self.builder.property("editable", editable),
1240 }
1241 }
1242
1243 /// If undo/redo should be enabled for the editable.
1244 pub fn enable_undo(self, enable_undo: bool) -> Self {
1245 Self {
1246 builder: self.builder.property("enable-undo", enable_undo),
1247 }
1248 }
1249
1250 /// The desired maximum width of the entry, in characters.
1251 pub fn max_width_chars(self, max_width_chars: i32) -> Self {
1252 Self {
1253 builder: self.builder.property("max-width-chars", max_width_chars),
1254 }
1255 }
1256
1257 /// The contents of the entry.
1258 pub fn text(self, text: impl Into<glib::GString>) -> Self {
1259 Self {
1260 builder: self.builder.property("text", text.into()),
1261 }
1262 }
1263
1264 /// Number of characters to leave space for in the entry.
1265 pub fn width_chars(self, width_chars: i32) -> Self {
1266 Self {
1267 builder: self.builder.property("width-chars", width_chars),
1268 }
1269 }
1270
1271 /// The horizontal alignment, from 0 (left) to 1 (right).
1272 ///
1273 /// Reversed for RTL layouts.
1274 pub fn xalign(self, xalign: f32) -> Self {
1275 Self {
1276 builder: self.builder.property("xalign", xalign),
1277 }
1278 }
1279
1280 // rustdoc-stripper-ignore-next
1281 /// Build the [`PasswordEntry`].
1282 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1283 pub fn build(self) -> PasswordEntry {
1284 assert_initialized_main_thread!();
1285 self.builder.build()
1286 }
1287}