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 /// #### `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 unsafe {
744 let f: &F = &*(f as *const F);
745 f(&from_glib_borrow(this))
746 }
747 }
748 unsafe {
749 let f: Box_<F> = Box_::new(f);
750 connect_raw(
751 self.as_ptr() as *mut _,
752 c"activate".as_ptr() as *const _,
753 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
754 activate_trampoline::<F> as *const (),
755 )),
756 Box_::into_raw(f),
757 )
758 }
759 }
760
761 pub fn emit_activate(&self) {
762 self.emit_by_name::<()>("activate", &[]);
763 }
764
765 #[doc(alias = "activates-default")]
766 pub fn connect_activates_default_notify<F: Fn(&Self) + 'static>(
767 &self,
768 f: F,
769 ) -> SignalHandlerId {
770 unsafe extern "C" fn notify_activates_default_trampoline<
771 F: Fn(&PasswordEntry) + 'static,
772 >(
773 this: *mut ffi::GtkPasswordEntry,
774 _param_spec: glib::ffi::gpointer,
775 f: glib::ffi::gpointer,
776 ) {
777 unsafe {
778 let f: &F = &*(f as *const F);
779 f(&from_glib_borrow(this))
780 }
781 }
782 unsafe {
783 let f: Box_<F> = Box_::new(f);
784 connect_raw(
785 self.as_ptr() as *mut _,
786 c"notify::activates-default".as_ptr() as *const _,
787 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
788 notify_activates_default_trampoline::<F> as *const (),
789 )),
790 Box_::into_raw(f),
791 )
792 }
793 }
794
795 #[doc(alias = "extra-menu")]
796 pub fn connect_extra_menu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
797 unsafe extern "C" fn notify_extra_menu_trampoline<F: Fn(&PasswordEntry) + 'static>(
798 this: *mut ffi::GtkPasswordEntry,
799 _param_spec: glib::ffi::gpointer,
800 f: glib::ffi::gpointer,
801 ) {
802 unsafe {
803 let f: &F = &*(f as *const F);
804 f(&from_glib_borrow(this))
805 }
806 }
807 unsafe {
808 let f: Box_<F> = Box_::new(f);
809 connect_raw(
810 self.as_ptr() as *mut _,
811 c"notify::extra-menu".as_ptr() as *const _,
812 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
813 notify_extra_menu_trampoline::<F> as *const (),
814 )),
815 Box_::into_raw(f),
816 )
817 }
818 }
819
820 #[doc(alias = "placeholder-text")]
821 pub fn connect_placeholder_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
822 unsafe extern "C" fn notify_placeholder_text_trampoline<F: Fn(&PasswordEntry) + 'static>(
823 this: *mut ffi::GtkPasswordEntry,
824 _param_spec: glib::ffi::gpointer,
825 f: glib::ffi::gpointer,
826 ) {
827 unsafe {
828 let f: &F = &*(f as *const F);
829 f(&from_glib_borrow(this))
830 }
831 }
832 unsafe {
833 let f: Box_<F> = Box_::new(f);
834 connect_raw(
835 self.as_ptr() as *mut _,
836 c"notify::placeholder-text".as_ptr() as *const _,
837 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
838 notify_placeholder_text_trampoline::<F> as *const (),
839 )),
840 Box_::into_raw(f),
841 )
842 }
843 }
844
845 #[doc(alias = "show-peek-icon")]
846 pub fn connect_show_peek_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
847 unsafe extern "C" fn notify_show_peek_icon_trampoline<F: Fn(&PasswordEntry) + 'static>(
848 this: *mut ffi::GtkPasswordEntry,
849 _param_spec: glib::ffi::gpointer,
850 f: glib::ffi::gpointer,
851 ) {
852 unsafe {
853 let f: &F = &*(f as *const F);
854 f(&from_glib_borrow(this))
855 }
856 }
857 unsafe {
858 let f: Box_<F> = Box_::new(f);
859 connect_raw(
860 self.as_ptr() as *mut _,
861 c"notify::show-peek-icon".as_ptr() as *const _,
862 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
863 notify_show_peek_icon_trampoline::<F> as *const (),
864 )),
865 Box_::into_raw(f),
866 )
867 }
868 }
869}
870
871impl Default for PasswordEntry {
872 fn default() -> Self {
873 Self::new()
874 }
875}
876
877// rustdoc-stripper-ignore-next
878/// A [builder-pattern] type to construct [`PasswordEntry`] objects.
879///
880/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
881#[must_use = "The builder must be built to be used"]
882pub struct PasswordEntryBuilder {
883 builder: glib::object::ObjectBuilder<'static, PasswordEntry>,
884}
885
886impl PasswordEntryBuilder {
887 fn new() -> Self {
888 Self {
889 builder: glib::object::Object::builder(),
890 }
891 }
892
893 /// Whether to activate the default widget when Enter is pressed.
894 pub fn activates_default(self, activates_default: bool) -> Self {
895 Self {
896 builder: self
897 .builder
898 .property("activates-default", activates_default),
899 }
900 }
901
902 /// A menu model whose contents will be appended to
903 /// the context menu.
904 pub fn extra_menu(self, extra_menu: &impl IsA<gio::MenuModel>) -> Self {
905 Self {
906 builder: self
907 .builder
908 .property("extra-menu", extra_menu.clone().upcast()),
909 }
910 }
911
912 /// The text that will be displayed in the [`PasswordEntry`][crate::PasswordEntry]
913 /// when it is empty and unfocused.
914 pub fn placeholder_text(self, placeholder_text: impl Into<glib::GString>) -> Self {
915 Self {
916 builder: self
917 .builder
918 .property("placeholder-text", placeholder_text.into()),
919 }
920 }
921
922 /// Whether to show an icon for revealing the content.
923 pub fn show_peek_icon(self, show_peek_icon: bool) -> Self {
924 Self {
925 builder: self.builder.property("show-peek-icon", show_peek_icon),
926 }
927 }
928
929 /// Whether the widget or any of its descendents can accept
930 /// the input focus.
931 ///
932 /// This property is meant to be set by widget implementations,
933 /// typically in their instance init function.
934 pub fn can_focus(self, can_focus: bool) -> Self {
935 Self {
936 builder: self.builder.property("can-focus", can_focus),
937 }
938 }
939
940 /// Whether the widget can receive pointer events.
941 pub fn can_target(self, can_target: bool) -> Self {
942 Self {
943 builder: self.builder.property("can-target", can_target),
944 }
945 }
946
947 /// A list of css classes applied to this widget.
948 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
949 Self {
950 builder: self.builder.property("css-classes", css_classes.into()),
951 }
952 }
953
954 /// The name of this widget in the CSS tree.
955 ///
956 /// This property is meant to be set by widget implementations,
957 /// typically in their instance init function.
958 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
959 Self {
960 builder: self.builder.property("css-name", css_name.into()),
961 }
962 }
963
964 /// The cursor used by @widget.
965 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
966 Self {
967 builder: self.builder.property("cursor", cursor.clone()),
968 }
969 }
970
971 /// Whether the widget should grab focus when it is clicked with the mouse.
972 ///
973 /// This property is only relevant for widgets that can take focus.
974 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
975 Self {
976 builder: self.builder.property("focus-on-click", focus_on_click),
977 }
978 }
979
980 /// Whether this widget itself will accept the input focus.
981 pub fn focusable(self, focusable: bool) -> Self {
982 Self {
983 builder: self.builder.property("focusable", focusable),
984 }
985 }
986
987 /// How to distribute horizontal space if widget gets extra space.
988 pub fn halign(self, halign: Align) -> Self {
989 Self {
990 builder: self.builder.property("halign", halign),
991 }
992 }
993
994 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
995 /// signal on @widget.
996 ///
997 /// A true value indicates that @widget can have a tooltip, in this case
998 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
999 /// determine whether it will provide a tooltip or not.
1000 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
1001 Self {
1002 builder: self.builder.property("has-tooltip", has_tooltip),
1003 }
1004 }
1005
1006 /// Overrides for height request of the widget.
1007 ///
1008 /// If this is -1, the natural request will be used.
1009 pub fn height_request(self, height_request: i32) -> Self {
1010 Self {
1011 builder: self.builder.property("height-request", height_request),
1012 }
1013 }
1014
1015 /// Whether to expand horizontally.
1016 pub fn hexpand(self, hexpand: bool) -> Self {
1017 Self {
1018 builder: self.builder.property("hexpand", hexpand),
1019 }
1020 }
1021
1022 /// Whether to use the `hexpand` property.
1023 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1024 Self {
1025 builder: self.builder.property("hexpand-set", hexpand_set),
1026 }
1027 }
1028
1029 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
1030 /// the preferred size of the widget, and allocate its children.
1031 ///
1032 /// This property is meant to be set by widget implementations,
1033 /// typically in their instance init function.
1034 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
1035 Self {
1036 builder: self
1037 .builder
1038 .property("layout-manager", layout_manager.clone().upcast()),
1039 }
1040 }
1041
1042 /// Makes this widget act like a modal dialog, with respect to
1043 /// event delivery.
1044 ///
1045 /// Global event controllers will not handle events with targets
1046 /// inside the widget, unless they are set up to ignore propagation
1047 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1048 #[cfg(feature = "v4_18")]
1049 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1050 pub fn limit_events(self, limit_events: bool) -> Self {
1051 Self {
1052 builder: self.builder.property("limit-events", limit_events),
1053 }
1054 }
1055
1056 /// Margin on bottom side of widget.
1057 ///
1058 /// This property adds margin outside of the widget's normal size
1059 /// request, the margin will be added in addition to the size from
1060 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1061 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1062 Self {
1063 builder: self.builder.property("margin-bottom", margin_bottom),
1064 }
1065 }
1066
1067 /// Margin on end of widget, horizontally.
1068 ///
1069 /// This property supports left-to-right and right-to-left text
1070 /// directions.
1071 ///
1072 /// This property adds margin outside of the widget's normal size
1073 /// request, the margin will be added in addition to the size from
1074 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1075 pub fn margin_end(self, margin_end: i32) -> Self {
1076 Self {
1077 builder: self.builder.property("margin-end", margin_end),
1078 }
1079 }
1080
1081 /// Margin on start of widget, horizontally.
1082 ///
1083 /// This property supports left-to-right and right-to-left text
1084 /// directions.
1085 ///
1086 /// This property adds margin outside of the widget's normal size
1087 /// request, the margin will be added in addition to the size from
1088 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1089 pub fn margin_start(self, margin_start: i32) -> Self {
1090 Self {
1091 builder: self.builder.property("margin-start", margin_start),
1092 }
1093 }
1094
1095 /// Margin on top side of widget.
1096 ///
1097 /// This property adds margin outside of the widget's normal size
1098 /// request, the margin will be added in addition to the size from
1099 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1100 pub fn margin_top(self, margin_top: i32) -> Self {
1101 Self {
1102 builder: self.builder.property("margin-top", margin_top),
1103 }
1104 }
1105
1106 /// The name of the widget.
1107 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1108 Self {
1109 builder: self.builder.property("name", name.into()),
1110 }
1111 }
1112
1113 /// The requested opacity of the widget.
1114 pub fn opacity(self, opacity: f64) -> Self {
1115 Self {
1116 builder: self.builder.property("opacity", opacity),
1117 }
1118 }
1119
1120 /// How content outside the widget's content area is treated.
1121 ///
1122 /// This property is meant to be set by widget implementations,
1123 /// typically in their instance init function.
1124 pub fn overflow(self, overflow: Overflow) -> Self {
1125 Self {
1126 builder: self.builder.property("overflow", overflow),
1127 }
1128 }
1129
1130 /// Whether the widget will receive the default action when it is focused.
1131 pub fn receives_default(self, receives_default: bool) -> Self {
1132 Self {
1133 builder: self.builder.property("receives-default", receives_default),
1134 }
1135 }
1136
1137 /// Whether the widget responds to input.
1138 pub fn sensitive(self, sensitive: bool) -> Self {
1139 Self {
1140 builder: self.builder.property("sensitive", sensitive),
1141 }
1142 }
1143
1144 /// Sets the text of tooltip to be the given string, which is marked up
1145 /// with Pango markup.
1146 ///
1147 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1148 ///
1149 /// This is a convenience property which will take care of getting the
1150 /// tooltip shown if the given string is not `NULL`:
1151 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1152 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1153 /// the default signal handler.
1154 ///
1155 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1156 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1157 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1158 Self {
1159 builder: self
1160 .builder
1161 .property("tooltip-markup", tooltip_markup.into()),
1162 }
1163 }
1164
1165 /// Sets the text of tooltip to be the given string.
1166 ///
1167 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1168 ///
1169 /// This is a convenience property which will take care of getting the
1170 /// tooltip shown if the given string is not `NULL`:
1171 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1172 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1173 /// the default signal handler.
1174 ///
1175 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1176 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1177 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1178 Self {
1179 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1180 }
1181 }
1182
1183 /// How to distribute vertical space if widget gets extra space.
1184 pub fn valign(self, valign: Align) -> Self {
1185 Self {
1186 builder: self.builder.property("valign", valign),
1187 }
1188 }
1189
1190 /// Whether to expand vertically.
1191 pub fn vexpand(self, vexpand: bool) -> Self {
1192 Self {
1193 builder: self.builder.property("vexpand", vexpand),
1194 }
1195 }
1196
1197 /// Whether to use the `vexpand` property.
1198 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1199 Self {
1200 builder: self.builder.property("vexpand-set", vexpand_set),
1201 }
1202 }
1203
1204 /// Whether the widget is visible.
1205 pub fn visible(self, visible: bool) -> Self {
1206 Self {
1207 builder: self.builder.property("visible", visible),
1208 }
1209 }
1210
1211 /// Overrides for width request of the widget.
1212 ///
1213 /// If this is -1, the natural request will be used.
1214 pub fn width_request(self, width_request: i32) -> Self {
1215 Self {
1216 builder: self.builder.property("width-request", width_request),
1217 }
1218 }
1219
1220 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1221 ///
1222 /// The accessible role cannot be changed once set.
1223 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1224 Self {
1225 builder: self.builder.property("accessible-role", accessible_role),
1226 }
1227 }
1228
1229 /// Whether the entry contents can be edited.
1230 pub fn editable(self, editable: bool) -> Self {
1231 Self {
1232 builder: self.builder.property("editable", editable),
1233 }
1234 }
1235
1236 /// If undo/redo should be enabled for the editable.
1237 pub fn enable_undo(self, enable_undo: bool) -> Self {
1238 Self {
1239 builder: self.builder.property("enable-undo", enable_undo),
1240 }
1241 }
1242
1243 /// The desired maximum width of the entry, in characters.
1244 pub fn max_width_chars(self, max_width_chars: i32) -> Self {
1245 Self {
1246 builder: self.builder.property("max-width-chars", max_width_chars),
1247 }
1248 }
1249
1250 /// The contents of the entry.
1251 pub fn text(self, text: impl Into<glib::GString>) -> Self {
1252 Self {
1253 builder: self.builder.property("text", text.into()),
1254 }
1255 }
1256
1257 /// Number of characters to leave space for in the entry.
1258 pub fn width_chars(self, width_chars: i32) -> Self {
1259 Self {
1260 builder: self.builder.property("width-chars", width_chars),
1261 }
1262 }
1263
1264 /// The horizontal alignment, from 0 (left) to 1 (right).
1265 ///
1266 /// Reversed for RTL layouts.
1267 pub fn xalign(self, xalign: f32) -> Self {
1268 Self {
1269 builder: self.builder.property("xalign", xalign),
1270 }
1271 }
1272
1273 // rustdoc-stripper-ignore-next
1274 /// Build the [`PasswordEntry`].
1275 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1276 pub fn build(self) -> PasswordEntry {
1277 assert_initialized_main_thread!();
1278 self.builder.build()
1279 }
1280}