1use crate::{
6 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, Editable, LayoutManager,
7 Overflow, Widget,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 #[doc(alias = "GtkPasswordEntry")]
19 pub struct PasswordEntry(Object<ffi::GtkPasswordEntry, ffi::GtkPasswordEntryClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Editable;
20
21 match fn {
22 type_ => || ffi::gtk_password_entry_get_type(),
23 }
24}
25
26impl PasswordEntry {
27 #[doc(alias = "gtk_password_entry_new")]
28 pub fn new() -> PasswordEntry {
29 assert_initialized_main_thread!();
30 unsafe { Widget::from_glib_none(ffi::gtk_password_entry_new()).unsafe_cast() }
31 }
32
33 pub fn builder() -> PasswordEntryBuilder {
38 PasswordEntryBuilder::new()
39 }
40
41 #[doc(alias = "gtk_password_entry_get_extra_menu")]
42 #[doc(alias = "get_extra_menu")]
43 #[doc(alias = "extra-menu")]
44 pub fn extra_menu(&self) -> Option<gio::MenuModel> {
45 unsafe {
46 from_glib_none(ffi::gtk_password_entry_get_extra_menu(
47 self.to_glib_none().0,
48 ))
49 }
50 }
51
52 #[doc(alias = "gtk_password_entry_get_show_peek_icon")]
53 #[doc(alias = "get_show_peek_icon")]
54 #[doc(alias = "show-peek-icon")]
55 pub fn shows_peek_icon(&self) -> bool {
56 unsafe {
57 from_glib(ffi::gtk_password_entry_get_show_peek_icon(
58 self.to_glib_none().0,
59 ))
60 }
61 }
62
63 #[doc(alias = "gtk_password_entry_set_extra_menu")]
64 #[doc(alias = "extra-menu")]
65 pub fn set_extra_menu(&self, model: Option<&impl IsA<gio::MenuModel>>) {
66 unsafe {
67 ffi::gtk_password_entry_set_extra_menu(
68 self.to_glib_none().0,
69 model.map(|p| p.as_ref()).to_glib_none().0,
70 );
71 }
72 }
73
74 #[doc(alias = "gtk_password_entry_set_show_peek_icon")]
75 #[doc(alias = "show-peek-icon")]
76 pub fn set_show_peek_icon(&self, show_peek_icon: bool) {
77 unsafe {
78 ffi::gtk_password_entry_set_show_peek_icon(
79 self.to_glib_none().0,
80 show_peek_icon.into_glib(),
81 );
82 }
83 }
84
85 #[doc(alias = "activates-default")]
86 pub fn activates_default(&self) -> bool {
87 ObjectExt::property(self, "activates-default")
88 }
89
90 #[doc(alias = "activates-default")]
91 pub fn set_activates_default(&self, activates_default: bool) {
92 ObjectExt::set_property(self, "activates-default", activates_default)
93 }
94
95 #[doc(alias = "placeholder-text")]
96 pub fn placeholder_text(&self) -> Option<glib::GString> {
97 ObjectExt::property(self, "placeholder-text")
98 }
99
100 #[doc(alias = "placeholder-text")]
101 pub fn set_placeholder_text(&self, placeholder_text: Option<&str>) {
102 ObjectExt::set_property(self, "placeholder-text", placeholder_text)
103 }
104
105 #[doc(alias = "activate")]
106 pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
107 unsafe extern "C" fn activate_trampoline<F: Fn(&PasswordEntry) + 'static>(
108 this: *mut ffi::GtkPasswordEntry,
109 f: glib::ffi::gpointer,
110 ) {
111 let f: &F = &*(f as *const F);
112 f(&from_glib_borrow(this))
113 }
114 unsafe {
115 let f: Box_<F> = Box_::new(f);
116 connect_raw(
117 self.as_ptr() as *mut _,
118 c"activate".as_ptr() as *const _,
119 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
120 activate_trampoline::<F> as *const (),
121 )),
122 Box_::into_raw(f),
123 )
124 }
125 }
126
127 pub fn emit_activate(&self) {
128 self.emit_by_name::<()>("activate", &[]);
129 }
130
131 #[doc(alias = "activates-default")]
132 pub fn connect_activates_default_notify<F: Fn(&Self) + 'static>(
133 &self,
134 f: F,
135 ) -> SignalHandlerId {
136 unsafe extern "C" fn notify_activates_default_trampoline<
137 F: Fn(&PasswordEntry) + 'static,
138 >(
139 this: *mut ffi::GtkPasswordEntry,
140 _param_spec: glib::ffi::gpointer,
141 f: glib::ffi::gpointer,
142 ) {
143 let f: &F = &*(f as *const F);
144 f(&from_glib_borrow(this))
145 }
146 unsafe {
147 let f: Box_<F> = Box_::new(f);
148 connect_raw(
149 self.as_ptr() as *mut _,
150 c"notify::activates-default".as_ptr() as *const _,
151 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
152 notify_activates_default_trampoline::<F> as *const (),
153 )),
154 Box_::into_raw(f),
155 )
156 }
157 }
158
159 #[doc(alias = "extra-menu")]
160 pub fn connect_extra_menu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
161 unsafe extern "C" fn notify_extra_menu_trampoline<F: Fn(&PasswordEntry) + 'static>(
162 this: *mut ffi::GtkPasswordEntry,
163 _param_spec: glib::ffi::gpointer,
164 f: glib::ffi::gpointer,
165 ) {
166 let f: &F = &*(f as *const F);
167 f(&from_glib_borrow(this))
168 }
169 unsafe {
170 let f: Box_<F> = Box_::new(f);
171 connect_raw(
172 self.as_ptr() as *mut _,
173 c"notify::extra-menu".as_ptr() as *const _,
174 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
175 notify_extra_menu_trampoline::<F> as *const (),
176 )),
177 Box_::into_raw(f),
178 )
179 }
180 }
181
182 #[doc(alias = "placeholder-text")]
183 pub fn connect_placeholder_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
184 unsafe extern "C" fn notify_placeholder_text_trampoline<F: Fn(&PasswordEntry) + 'static>(
185 this: *mut ffi::GtkPasswordEntry,
186 _param_spec: glib::ffi::gpointer,
187 f: glib::ffi::gpointer,
188 ) {
189 let f: &F = &*(f as *const F);
190 f(&from_glib_borrow(this))
191 }
192 unsafe {
193 let f: Box_<F> = Box_::new(f);
194 connect_raw(
195 self.as_ptr() as *mut _,
196 c"notify::placeholder-text".as_ptr() as *const _,
197 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
198 notify_placeholder_text_trampoline::<F> as *const (),
199 )),
200 Box_::into_raw(f),
201 )
202 }
203 }
204
205 #[doc(alias = "show-peek-icon")]
206 pub fn connect_show_peek_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
207 unsafe extern "C" fn notify_show_peek_icon_trampoline<F: Fn(&PasswordEntry) + 'static>(
208 this: *mut ffi::GtkPasswordEntry,
209 _param_spec: glib::ffi::gpointer,
210 f: glib::ffi::gpointer,
211 ) {
212 let f: &F = &*(f as *const F);
213 f(&from_glib_borrow(this))
214 }
215 unsafe {
216 let f: Box_<F> = Box_::new(f);
217 connect_raw(
218 self.as_ptr() as *mut _,
219 c"notify::show-peek-icon".as_ptr() as *const _,
220 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
221 notify_show_peek_icon_trampoline::<F> as *const (),
222 )),
223 Box_::into_raw(f),
224 )
225 }
226 }
227}
228
229impl Default for PasswordEntry {
230 fn default() -> Self {
231 Self::new()
232 }
233}
234
235#[must_use = "The builder must be built to be used"]
240pub struct PasswordEntryBuilder {
241 builder: glib::object::ObjectBuilder<'static, PasswordEntry>,
242}
243
244impl PasswordEntryBuilder {
245 fn new() -> Self {
246 Self {
247 builder: glib::object::Object::builder(),
248 }
249 }
250
251 pub fn activates_default(self, activates_default: bool) -> Self {
252 Self {
253 builder: self
254 .builder
255 .property("activates-default", activates_default),
256 }
257 }
258
259 pub fn extra_menu(self, extra_menu: &impl IsA<gio::MenuModel>) -> Self {
260 Self {
261 builder: self
262 .builder
263 .property("extra-menu", extra_menu.clone().upcast()),
264 }
265 }
266
267 pub fn placeholder_text(self, placeholder_text: impl Into<glib::GString>) -> Self {
268 Self {
269 builder: self
270 .builder
271 .property("placeholder-text", placeholder_text.into()),
272 }
273 }
274
275 pub fn show_peek_icon(self, show_peek_icon: bool) -> Self {
276 Self {
277 builder: self.builder.property("show-peek-icon", show_peek_icon),
278 }
279 }
280
281 pub fn can_focus(self, can_focus: bool) -> Self {
282 Self {
283 builder: self.builder.property("can-focus", can_focus),
284 }
285 }
286
287 pub fn can_target(self, can_target: bool) -> Self {
288 Self {
289 builder: self.builder.property("can-target", can_target),
290 }
291 }
292
293 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
294 Self {
295 builder: self.builder.property("css-classes", css_classes.into()),
296 }
297 }
298
299 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
300 Self {
301 builder: self.builder.property("css-name", css_name.into()),
302 }
303 }
304
305 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
306 Self {
307 builder: self.builder.property("cursor", cursor.clone()),
308 }
309 }
310
311 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
312 Self {
313 builder: self.builder.property("focus-on-click", focus_on_click),
314 }
315 }
316
317 pub fn focusable(self, focusable: bool) -> Self {
318 Self {
319 builder: self.builder.property("focusable", focusable),
320 }
321 }
322
323 pub fn halign(self, halign: Align) -> Self {
324 Self {
325 builder: self.builder.property("halign", halign),
326 }
327 }
328
329 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
330 Self {
331 builder: self.builder.property("has-tooltip", has_tooltip),
332 }
333 }
334
335 pub fn height_request(self, height_request: i32) -> Self {
336 Self {
337 builder: self.builder.property("height-request", height_request),
338 }
339 }
340
341 pub fn hexpand(self, hexpand: bool) -> Self {
342 Self {
343 builder: self.builder.property("hexpand", hexpand),
344 }
345 }
346
347 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
348 Self {
349 builder: self.builder.property("hexpand-set", hexpand_set),
350 }
351 }
352
353 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
354 Self {
355 builder: self
356 .builder
357 .property("layout-manager", layout_manager.clone().upcast()),
358 }
359 }
360
361 #[cfg(feature = "v4_18")]
362 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
363 pub fn limit_events(self, limit_events: bool) -> Self {
364 Self {
365 builder: self.builder.property("limit-events", limit_events),
366 }
367 }
368
369 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
370 Self {
371 builder: self.builder.property("margin-bottom", margin_bottom),
372 }
373 }
374
375 pub fn margin_end(self, margin_end: i32) -> Self {
376 Self {
377 builder: self.builder.property("margin-end", margin_end),
378 }
379 }
380
381 pub fn margin_start(self, margin_start: i32) -> Self {
382 Self {
383 builder: self.builder.property("margin-start", margin_start),
384 }
385 }
386
387 pub fn margin_top(self, margin_top: i32) -> Self {
388 Self {
389 builder: self.builder.property("margin-top", margin_top),
390 }
391 }
392
393 pub fn name(self, name: impl Into<glib::GString>) -> Self {
394 Self {
395 builder: self.builder.property("name", name.into()),
396 }
397 }
398
399 pub fn opacity(self, opacity: f64) -> Self {
400 Self {
401 builder: self.builder.property("opacity", opacity),
402 }
403 }
404
405 pub fn overflow(self, overflow: Overflow) -> Self {
406 Self {
407 builder: self.builder.property("overflow", overflow),
408 }
409 }
410
411 pub fn receives_default(self, receives_default: bool) -> Self {
412 Self {
413 builder: self.builder.property("receives-default", receives_default),
414 }
415 }
416
417 pub fn sensitive(self, sensitive: bool) -> Self {
418 Self {
419 builder: self.builder.property("sensitive", sensitive),
420 }
421 }
422
423 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
424 Self {
425 builder: self
426 .builder
427 .property("tooltip-markup", tooltip_markup.into()),
428 }
429 }
430
431 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
432 Self {
433 builder: self.builder.property("tooltip-text", tooltip_text.into()),
434 }
435 }
436
437 pub fn valign(self, valign: Align) -> Self {
438 Self {
439 builder: self.builder.property("valign", valign),
440 }
441 }
442
443 pub fn vexpand(self, vexpand: bool) -> Self {
444 Self {
445 builder: self.builder.property("vexpand", vexpand),
446 }
447 }
448
449 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
450 Self {
451 builder: self.builder.property("vexpand-set", vexpand_set),
452 }
453 }
454
455 pub fn visible(self, visible: bool) -> Self {
456 Self {
457 builder: self.builder.property("visible", visible),
458 }
459 }
460
461 pub fn width_request(self, width_request: i32) -> Self {
462 Self {
463 builder: self.builder.property("width-request", width_request),
464 }
465 }
466
467 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
468 Self {
469 builder: self.builder.property("accessible-role", accessible_role),
470 }
471 }
472
473 pub fn editable(self, editable: bool) -> Self {
474 Self {
475 builder: self.builder.property("editable", editable),
476 }
477 }
478
479 pub fn enable_undo(self, enable_undo: bool) -> Self {
480 Self {
481 builder: self.builder.property("enable-undo", enable_undo),
482 }
483 }
484
485 pub fn max_width_chars(self, max_width_chars: i32) -> Self {
486 Self {
487 builder: self.builder.property("max-width-chars", max_width_chars),
488 }
489 }
490
491 pub fn text(self, text: impl Into<glib::GString>) -> Self {
492 Self {
493 builder: self.builder.property("text", text.into()),
494 }
495 }
496
497 pub fn width_chars(self, width_chars: i32) -> Self {
498 Self {
499 builder: self.builder.property("width-chars", width_chars),
500 }
501 }
502
503 pub fn xalign(self, xalign: f32) -> Self {
504 Self {
505 builder: self.builder.property("xalign", xalign),
506 }
507 }
508
509 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
512 pub fn build(self) -> PasswordEntry {
513 assert_initialized_main_thread!();
514 self.builder.build()
515 }
516}