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