1use crate::{
6 Align, AppChooser, BaselinePosition, Box, Buildable, Container, Menu, Orientable, Orientation,
7 ResizeMode, Widget,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::{boxed::Box as Box_, fmt, mem::transmute};
15
16glib::wrapper! {
17 #[doc(alias = "GtkAppChooserWidget")]
18 pub struct AppChooserWidget(Object<ffi::GtkAppChooserWidget, ffi::GtkAppChooserWidgetClass>) @extends Box, Container, Widget, @implements Buildable, Orientable, AppChooser;
19
20 match fn {
21 type_ => || ffi::gtk_app_chooser_widget_get_type(),
22 }
23}
24
25impl AppChooserWidget {
26 pub const NONE: Option<&'static AppChooserWidget> = None;
27
28 #[doc(alias = "gtk_app_chooser_widget_new")]
29 pub fn new(content_type: &str) -> AppChooserWidget {
30 assert_initialized_main_thread!();
31 unsafe {
32 Widget::from_glib_none(ffi::gtk_app_chooser_widget_new(
33 content_type.to_glib_none().0,
34 ))
35 .unsafe_cast()
36 }
37 }
38
39 pub fn builder() -> AppChooserWidgetBuilder {
44 AppChooserWidgetBuilder::new()
45 }
46}
47
48impl Default for AppChooserWidget {
49 fn default() -> Self {
50 glib::object::Object::new::<Self>()
51 }
52}
53
54#[must_use = "The builder must be built to be used"]
59pub struct AppChooserWidgetBuilder {
60 builder: glib::object::ObjectBuilder<'static, AppChooserWidget>,
61}
62
63impl AppChooserWidgetBuilder {
64 fn new() -> Self {
65 Self {
66 builder: glib::object::Object::builder(),
67 }
68 }
69
70 pub fn default_text(self, default_text: impl Into<glib::GString>) -> Self {
71 Self {
72 builder: self.builder.property("default-text", default_text.into()),
73 }
74 }
75
76 pub fn show_all(self, show_all: bool) -> Self {
77 Self {
78 builder: self.builder.property("show-all", show_all),
79 }
80 }
81
82 pub fn show_default(self, show_default: bool) -> Self {
83 Self {
84 builder: self.builder.property("show-default", show_default),
85 }
86 }
87
88 pub fn show_fallback(self, show_fallback: bool) -> Self {
89 Self {
90 builder: self.builder.property("show-fallback", show_fallback),
91 }
92 }
93
94 pub fn show_other(self, show_other: bool) -> Self {
95 Self {
96 builder: self.builder.property("show-other", show_other),
97 }
98 }
99
100 pub fn show_recommended(self, show_recommended: bool) -> Self {
101 Self {
102 builder: self.builder.property("show-recommended", show_recommended),
103 }
104 }
105
106 pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
107 Self {
108 builder: self
109 .builder
110 .property("baseline-position", baseline_position),
111 }
112 }
113
114 pub fn homogeneous(self, homogeneous: bool) -> Self {
115 Self {
116 builder: self.builder.property("homogeneous", homogeneous),
117 }
118 }
119
120 pub fn spacing(self, spacing: i32) -> Self {
121 Self {
122 builder: self.builder.property("spacing", spacing),
123 }
124 }
125
126 pub fn border_width(self, border_width: u32) -> Self {
127 Self {
128 builder: self.builder.property("border-width", border_width),
129 }
130 }
131
132 pub fn child(self, child: &impl IsA<Widget>) -> Self {
133 Self {
134 builder: self.builder.property("child", child.clone().upcast()),
135 }
136 }
137
138 pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
139 Self {
140 builder: self.builder.property("resize-mode", resize_mode),
141 }
142 }
143
144 pub fn app_paintable(self, app_paintable: bool) -> Self {
145 Self {
146 builder: self.builder.property("app-paintable", app_paintable),
147 }
148 }
149
150 pub fn can_default(self, can_default: bool) -> Self {
151 Self {
152 builder: self.builder.property("can-default", can_default),
153 }
154 }
155
156 pub fn can_focus(self, can_focus: bool) -> Self {
157 Self {
158 builder: self.builder.property("can-focus", can_focus),
159 }
160 }
161
162 pub fn events(self, events: gdk::EventMask) -> Self {
163 Self {
164 builder: self.builder.property("events", events),
165 }
166 }
167
168 pub fn expand(self, expand: bool) -> Self {
169 Self {
170 builder: self.builder.property("expand", expand),
171 }
172 }
173
174 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
175 Self {
176 builder: self.builder.property("focus-on-click", focus_on_click),
177 }
178 }
179
180 pub fn halign(self, halign: Align) -> Self {
181 Self {
182 builder: self.builder.property("halign", halign),
183 }
184 }
185
186 pub fn has_default(self, has_default: bool) -> Self {
187 Self {
188 builder: self.builder.property("has-default", has_default),
189 }
190 }
191
192 pub fn has_focus(self, has_focus: bool) -> Self {
193 Self {
194 builder: self.builder.property("has-focus", has_focus),
195 }
196 }
197
198 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
199 Self {
200 builder: self.builder.property("has-tooltip", has_tooltip),
201 }
202 }
203
204 pub fn height_request(self, height_request: i32) -> Self {
205 Self {
206 builder: self.builder.property("height-request", height_request),
207 }
208 }
209
210 pub fn hexpand(self, hexpand: bool) -> Self {
211 Self {
212 builder: self.builder.property("hexpand", hexpand),
213 }
214 }
215
216 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
217 Self {
218 builder: self.builder.property("hexpand-set", hexpand_set),
219 }
220 }
221
222 pub fn is_focus(self, is_focus: bool) -> Self {
223 Self {
224 builder: self.builder.property("is-focus", is_focus),
225 }
226 }
227
228 pub fn margin(self, margin: i32) -> Self {
229 Self {
230 builder: self.builder.property("margin", margin),
231 }
232 }
233
234 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
235 Self {
236 builder: self.builder.property("margin-bottom", margin_bottom),
237 }
238 }
239
240 pub fn margin_end(self, margin_end: i32) -> Self {
241 Self {
242 builder: self.builder.property("margin-end", margin_end),
243 }
244 }
245
246 pub fn margin_start(self, margin_start: i32) -> Self {
247 Self {
248 builder: self.builder.property("margin-start", margin_start),
249 }
250 }
251
252 pub fn margin_top(self, margin_top: i32) -> Self {
253 Self {
254 builder: self.builder.property("margin-top", margin_top),
255 }
256 }
257
258 pub fn name(self, name: impl Into<glib::GString>) -> Self {
259 Self {
260 builder: self.builder.property("name", name.into()),
261 }
262 }
263
264 pub fn no_show_all(self, no_show_all: bool) -> Self {
265 Self {
266 builder: self.builder.property("no-show-all", no_show_all),
267 }
268 }
269
270 pub fn opacity(self, opacity: f64) -> Self {
271 Self {
272 builder: self.builder.property("opacity", opacity),
273 }
274 }
275
276 pub fn parent(self, parent: &impl IsA<Container>) -> Self {
277 Self {
278 builder: self.builder.property("parent", parent.clone().upcast()),
279 }
280 }
281
282 pub fn receives_default(self, receives_default: bool) -> Self {
283 Self {
284 builder: self.builder.property("receives-default", receives_default),
285 }
286 }
287
288 pub fn sensitive(self, sensitive: bool) -> Self {
289 Self {
290 builder: self.builder.property("sensitive", sensitive),
291 }
292 }
293
294 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
295 Self {
296 builder: self
297 .builder
298 .property("tooltip-markup", tooltip_markup.into()),
299 }
300 }
301
302 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
303 Self {
304 builder: self.builder.property("tooltip-text", tooltip_text.into()),
305 }
306 }
307
308 pub fn valign(self, valign: Align) -> Self {
309 Self {
310 builder: self.builder.property("valign", valign),
311 }
312 }
313
314 pub fn vexpand(self, vexpand: bool) -> Self {
315 Self {
316 builder: self.builder.property("vexpand", vexpand),
317 }
318 }
319
320 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
321 Self {
322 builder: self.builder.property("vexpand-set", vexpand_set),
323 }
324 }
325
326 pub fn visible(self, visible: bool) -> Self {
327 Self {
328 builder: self.builder.property("visible", visible),
329 }
330 }
331
332 pub fn width_request(self, width_request: i32) -> Self {
333 Self {
334 builder: self.builder.property("width-request", width_request),
335 }
336 }
337
338 pub fn orientation(self, orientation: Orientation) -> Self {
339 Self {
340 builder: self.builder.property("orientation", orientation),
341 }
342 }
343
344 pub fn content_type(self, content_type: impl Into<glib::GString>) -> Self {
345 Self {
346 builder: self.builder.property("content-type", content_type.into()),
347 }
348 }
349
350 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
353 pub fn build(self) -> AppChooserWidget {
354 self.builder.build()
355 }
356}
357
358mod sealed {
359 pub trait Sealed {}
360 impl<T: super::IsA<super::AppChooserWidget>> Sealed for T {}
361}
362
363pub trait AppChooserWidgetExt: IsA<AppChooserWidget> + sealed::Sealed + 'static {
364 #[doc(alias = "gtk_app_chooser_widget_get_default_text")]
365 #[doc(alias = "get_default_text")]
366 fn default_text(&self) -> Option<glib::GString> {
367 unsafe {
368 from_glib_none(ffi::gtk_app_chooser_widget_get_default_text(
369 self.as_ref().to_glib_none().0,
370 ))
371 }
372 }
373
374 #[doc(alias = "gtk_app_chooser_widget_get_show_all")]
375 #[doc(alias = "get_show_all")]
376 fn shows_all(&self) -> bool {
377 unsafe {
378 from_glib(ffi::gtk_app_chooser_widget_get_show_all(
379 self.as_ref().to_glib_none().0,
380 ))
381 }
382 }
383
384 #[doc(alias = "gtk_app_chooser_widget_get_show_default")]
385 #[doc(alias = "get_show_default")]
386 fn shows_default(&self) -> bool {
387 unsafe {
388 from_glib(ffi::gtk_app_chooser_widget_get_show_default(
389 self.as_ref().to_glib_none().0,
390 ))
391 }
392 }
393
394 #[doc(alias = "gtk_app_chooser_widget_get_show_fallback")]
395 #[doc(alias = "get_show_fallback")]
396 fn shows_fallback(&self) -> bool {
397 unsafe {
398 from_glib(ffi::gtk_app_chooser_widget_get_show_fallback(
399 self.as_ref().to_glib_none().0,
400 ))
401 }
402 }
403
404 #[doc(alias = "gtk_app_chooser_widget_get_show_other")]
405 #[doc(alias = "get_show_other")]
406 fn shows_other(&self) -> bool {
407 unsafe {
408 from_glib(ffi::gtk_app_chooser_widget_get_show_other(
409 self.as_ref().to_glib_none().0,
410 ))
411 }
412 }
413
414 #[doc(alias = "gtk_app_chooser_widget_get_show_recommended")]
415 #[doc(alias = "get_show_recommended")]
416 fn shows_recommended(&self) -> bool {
417 unsafe {
418 from_glib(ffi::gtk_app_chooser_widget_get_show_recommended(
419 self.as_ref().to_glib_none().0,
420 ))
421 }
422 }
423
424 #[doc(alias = "gtk_app_chooser_widget_set_default_text")]
425 fn set_default_text(&self, text: &str) {
426 unsafe {
427 ffi::gtk_app_chooser_widget_set_default_text(
428 self.as_ref().to_glib_none().0,
429 text.to_glib_none().0,
430 );
431 }
432 }
433
434 #[doc(alias = "gtk_app_chooser_widget_set_show_all")]
435 fn set_show_all(&self, setting: bool) {
436 unsafe {
437 ffi::gtk_app_chooser_widget_set_show_all(
438 self.as_ref().to_glib_none().0,
439 setting.into_glib(),
440 );
441 }
442 }
443
444 #[doc(alias = "gtk_app_chooser_widget_set_show_default")]
445 fn set_show_default(&self, setting: bool) {
446 unsafe {
447 ffi::gtk_app_chooser_widget_set_show_default(
448 self.as_ref().to_glib_none().0,
449 setting.into_glib(),
450 );
451 }
452 }
453
454 #[doc(alias = "gtk_app_chooser_widget_set_show_fallback")]
455 fn set_show_fallback(&self, setting: bool) {
456 unsafe {
457 ffi::gtk_app_chooser_widget_set_show_fallback(
458 self.as_ref().to_glib_none().0,
459 setting.into_glib(),
460 );
461 }
462 }
463
464 #[doc(alias = "gtk_app_chooser_widget_set_show_other")]
465 fn set_show_other(&self, setting: bool) {
466 unsafe {
467 ffi::gtk_app_chooser_widget_set_show_other(
468 self.as_ref().to_glib_none().0,
469 setting.into_glib(),
470 );
471 }
472 }
473
474 #[doc(alias = "gtk_app_chooser_widget_set_show_recommended")]
475 fn set_show_recommended(&self, setting: bool) {
476 unsafe {
477 ffi::gtk_app_chooser_widget_set_show_recommended(
478 self.as_ref().to_glib_none().0,
479 setting.into_glib(),
480 );
481 }
482 }
483
484 #[doc(alias = "application-activated")]
485 fn connect_application_activated<F: Fn(&Self, &gio::AppInfo) + 'static>(
486 &self,
487 f: F,
488 ) -> SignalHandlerId {
489 unsafe extern "C" fn application_activated_trampoline<
490 P: IsA<AppChooserWidget>,
491 F: Fn(&P, &gio::AppInfo) + 'static,
492 >(
493 this: *mut ffi::GtkAppChooserWidget,
494 application: *mut gio::ffi::GAppInfo,
495 f: glib::ffi::gpointer,
496 ) {
497 let f: &F = &*(f as *const F);
498 f(
499 AppChooserWidget::from_glib_borrow(this).unsafe_cast_ref(),
500 &from_glib_borrow(application),
501 )
502 }
503 unsafe {
504 let f: Box_<F> = Box_::new(f);
505 connect_raw(
506 self.as_ptr() as *mut _,
507 b"application-activated\0".as_ptr() as *const _,
508 Some(transmute::<_, unsafe extern "C" fn()>(
509 application_activated_trampoline::<Self, F> as *const (),
510 )),
511 Box_::into_raw(f),
512 )
513 }
514 }
515
516 #[doc(alias = "application-selected")]
517 fn connect_application_selected<F: Fn(&Self, &gio::AppInfo) + 'static>(
518 &self,
519 f: F,
520 ) -> SignalHandlerId {
521 unsafe extern "C" fn application_selected_trampoline<
522 P: IsA<AppChooserWidget>,
523 F: Fn(&P, &gio::AppInfo) + 'static,
524 >(
525 this: *mut ffi::GtkAppChooserWidget,
526 application: *mut gio::ffi::GAppInfo,
527 f: glib::ffi::gpointer,
528 ) {
529 let f: &F = &*(f as *const F);
530 f(
531 AppChooserWidget::from_glib_borrow(this).unsafe_cast_ref(),
532 &from_glib_borrow(application),
533 )
534 }
535 unsafe {
536 let f: Box_<F> = Box_::new(f);
537 connect_raw(
538 self.as_ptr() as *mut _,
539 b"application-selected\0".as_ptr() as *const _,
540 Some(transmute::<_, unsafe extern "C" fn()>(
541 application_selected_trampoline::<Self, F> as *const (),
542 )),
543 Box_::into_raw(f),
544 )
545 }
546 }
547
548 #[doc(alias = "populate-popup")]
549 fn connect_populate_popup<F: Fn(&Self, &Menu, &gio::AppInfo) + 'static>(
550 &self,
551 f: F,
552 ) -> SignalHandlerId {
553 unsafe extern "C" fn populate_popup_trampoline<
554 P: IsA<AppChooserWidget>,
555 F: Fn(&P, &Menu, &gio::AppInfo) + 'static,
556 >(
557 this: *mut ffi::GtkAppChooserWidget,
558 menu: *mut ffi::GtkMenu,
559 application: *mut gio::ffi::GAppInfo,
560 f: glib::ffi::gpointer,
561 ) {
562 let f: &F = &*(f as *const F);
563 f(
564 AppChooserWidget::from_glib_borrow(this).unsafe_cast_ref(),
565 &from_glib_borrow(menu),
566 &from_glib_borrow(application),
567 )
568 }
569 unsafe {
570 let f: Box_<F> = Box_::new(f);
571 connect_raw(
572 self.as_ptr() as *mut _,
573 b"populate-popup\0".as_ptr() as *const _,
574 Some(transmute::<_, unsafe extern "C" fn()>(
575 populate_popup_trampoline::<Self, F> as *const (),
576 )),
577 Box_::into_raw(f),
578 )
579 }
580 }
581
582 #[doc(alias = "default-text")]
583 fn connect_default_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
584 unsafe extern "C" fn notify_default_text_trampoline<
585 P: IsA<AppChooserWidget>,
586 F: Fn(&P) + 'static,
587 >(
588 this: *mut ffi::GtkAppChooserWidget,
589 _param_spec: glib::ffi::gpointer,
590 f: glib::ffi::gpointer,
591 ) {
592 let f: &F = &*(f as *const F);
593 f(AppChooserWidget::from_glib_borrow(this).unsafe_cast_ref())
594 }
595 unsafe {
596 let f: Box_<F> = Box_::new(f);
597 connect_raw(
598 self.as_ptr() as *mut _,
599 b"notify::default-text\0".as_ptr() as *const _,
600 Some(transmute::<_, unsafe extern "C" fn()>(
601 notify_default_text_trampoline::<Self, F> as *const (),
602 )),
603 Box_::into_raw(f),
604 )
605 }
606 }
607
608 #[doc(alias = "show-all")]
609 fn connect_show_all_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
610 unsafe extern "C" fn notify_show_all_trampoline<
611 P: IsA<AppChooserWidget>,
612 F: Fn(&P) + 'static,
613 >(
614 this: *mut ffi::GtkAppChooserWidget,
615 _param_spec: glib::ffi::gpointer,
616 f: glib::ffi::gpointer,
617 ) {
618 let f: &F = &*(f as *const F);
619 f(AppChooserWidget::from_glib_borrow(this).unsafe_cast_ref())
620 }
621 unsafe {
622 let f: Box_<F> = Box_::new(f);
623 connect_raw(
624 self.as_ptr() as *mut _,
625 b"notify::show-all\0".as_ptr() as *const _,
626 Some(transmute::<_, unsafe extern "C" fn()>(
627 notify_show_all_trampoline::<Self, F> as *const (),
628 )),
629 Box_::into_raw(f),
630 )
631 }
632 }
633
634 #[doc(alias = "show-default")]
635 fn connect_show_default_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
636 unsafe extern "C" fn notify_show_default_trampoline<
637 P: IsA<AppChooserWidget>,
638 F: Fn(&P) + 'static,
639 >(
640 this: *mut ffi::GtkAppChooserWidget,
641 _param_spec: glib::ffi::gpointer,
642 f: glib::ffi::gpointer,
643 ) {
644 let f: &F = &*(f as *const F);
645 f(AppChooserWidget::from_glib_borrow(this).unsafe_cast_ref())
646 }
647 unsafe {
648 let f: Box_<F> = Box_::new(f);
649 connect_raw(
650 self.as_ptr() as *mut _,
651 b"notify::show-default\0".as_ptr() as *const _,
652 Some(transmute::<_, unsafe extern "C" fn()>(
653 notify_show_default_trampoline::<Self, F> as *const (),
654 )),
655 Box_::into_raw(f),
656 )
657 }
658 }
659
660 #[doc(alias = "show-fallback")]
661 fn connect_show_fallback_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
662 unsafe extern "C" fn notify_show_fallback_trampoline<
663 P: IsA<AppChooserWidget>,
664 F: Fn(&P) + 'static,
665 >(
666 this: *mut ffi::GtkAppChooserWidget,
667 _param_spec: glib::ffi::gpointer,
668 f: glib::ffi::gpointer,
669 ) {
670 let f: &F = &*(f as *const F);
671 f(AppChooserWidget::from_glib_borrow(this).unsafe_cast_ref())
672 }
673 unsafe {
674 let f: Box_<F> = Box_::new(f);
675 connect_raw(
676 self.as_ptr() as *mut _,
677 b"notify::show-fallback\0".as_ptr() as *const _,
678 Some(transmute::<_, unsafe extern "C" fn()>(
679 notify_show_fallback_trampoline::<Self, F> as *const (),
680 )),
681 Box_::into_raw(f),
682 )
683 }
684 }
685
686 #[doc(alias = "show-other")]
687 fn connect_show_other_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
688 unsafe extern "C" fn notify_show_other_trampoline<
689 P: IsA<AppChooserWidget>,
690 F: Fn(&P) + 'static,
691 >(
692 this: *mut ffi::GtkAppChooserWidget,
693 _param_spec: glib::ffi::gpointer,
694 f: glib::ffi::gpointer,
695 ) {
696 let f: &F = &*(f as *const F);
697 f(AppChooserWidget::from_glib_borrow(this).unsafe_cast_ref())
698 }
699 unsafe {
700 let f: Box_<F> = Box_::new(f);
701 connect_raw(
702 self.as_ptr() as *mut _,
703 b"notify::show-other\0".as_ptr() as *const _,
704 Some(transmute::<_, unsafe extern "C" fn()>(
705 notify_show_other_trampoline::<Self, F> as *const (),
706 )),
707 Box_::into_raw(f),
708 )
709 }
710 }
711
712 #[doc(alias = "show-recommended")]
713 fn connect_show_recommended_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
714 unsafe extern "C" fn notify_show_recommended_trampoline<
715 P: IsA<AppChooserWidget>,
716 F: Fn(&P) + 'static,
717 >(
718 this: *mut ffi::GtkAppChooserWidget,
719 _param_spec: glib::ffi::gpointer,
720 f: glib::ffi::gpointer,
721 ) {
722 let f: &F = &*(f as *const F);
723 f(AppChooserWidget::from_glib_borrow(this).unsafe_cast_ref())
724 }
725 unsafe {
726 let f: Box_<F> = Box_::new(f);
727 connect_raw(
728 self.as_ptr() as *mut _,
729 b"notify::show-recommended\0".as_ptr() as *const _,
730 Some(transmute::<_, unsafe extern "C" fn()>(
731 notify_show_recommended_trampoline::<Self, F> as *const (),
732 )),
733 Box_::into_raw(f),
734 )
735 }
736 }
737}
738
739impl<O: IsA<AppChooserWidget>> AppChooserWidgetExt for O {}
740
741impl fmt::Display for AppChooserWidget {
742 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
743 f.write_str("AppChooserWidget")
744 }
745}