1#![allow(deprecated)]
5
6use crate::{
7 ffi, Accessible, AccessibleRole, Align, AppChooser, Buildable, ConstraintTarget, LayoutManager,
8 Overflow, Widget,
9};
10use glib::{
11 object::ObjectType as _,
12 prelude::*,
13 signal::{connect_raw, SignalHandlerId},
14 translate::*,
15};
16use std::boxed::Box as Box_;
17
18glib::wrapper! {
19 #[doc(alias = "GtkAppChooserButton")]
20 pub struct AppChooserButton(Object<ffi::GtkAppChooserButton>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, AppChooser;
21
22 match fn {
23 type_ => || ffi::gtk_app_chooser_button_get_type(),
24 }
25}
26
27impl AppChooserButton {
28 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
29 #[allow(deprecated)]
30 #[doc(alias = "gtk_app_chooser_button_new")]
31 pub fn new(content_type: &str) -> AppChooserButton {
32 assert_initialized_main_thread!();
33 unsafe {
34 Widget::from_glib_none(ffi::gtk_app_chooser_button_new(
35 content_type.to_glib_none().0,
36 ))
37 .unsafe_cast()
38 }
39 }
40
41 pub fn builder() -> AppChooserButtonBuilder {
46 AppChooserButtonBuilder::new()
47 }
48
49 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
50 #[allow(deprecated)]
51 #[doc(alias = "gtk_app_chooser_button_append_custom_item")]
52 pub fn append_custom_item(&self, name: &str, label: &str, icon: &impl IsA<gio::Icon>) {
53 unsafe {
54 ffi::gtk_app_chooser_button_append_custom_item(
55 self.to_glib_none().0,
56 name.to_glib_none().0,
57 label.to_glib_none().0,
58 icon.as_ref().to_glib_none().0,
59 );
60 }
61 }
62
63 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
64 #[allow(deprecated)]
65 #[doc(alias = "gtk_app_chooser_button_append_separator")]
66 pub fn append_separator(&self) {
67 unsafe {
68 ffi::gtk_app_chooser_button_append_separator(self.to_glib_none().0);
69 }
70 }
71
72 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
73 #[allow(deprecated)]
74 #[doc(alias = "gtk_app_chooser_button_get_heading")]
75 #[doc(alias = "get_heading")]
76 pub fn heading(&self) -> Option<glib::GString> {
77 unsafe {
78 from_glib_none(ffi::gtk_app_chooser_button_get_heading(
79 self.to_glib_none().0,
80 ))
81 }
82 }
83
84 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
85 #[allow(deprecated)]
86 #[doc(alias = "gtk_app_chooser_button_get_modal")]
87 #[doc(alias = "get_modal")]
88 #[doc(alias = "modal")]
89 pub fn is_modal(&self) -> bool {
90 unsafe { from_glib(ffi::gtk_app_chooser_button_get_modal(self.to_glib_none().0)) }
91 }
92
93 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
94 #[allow(deprecated)]
95 #[doc(alias = "gtk_app_chooser_button_get_show_default_item")]
96 #[doc(alias = "get_show_default_item")]
97 #[doc(alias = "show-default-item")]
98 pub fn shows_default_item(&self) -> bool {
99 unsafe {
100 from_glib(ffi::gtk_app_chooser_button_get_show_default_item(
101 self.to_glib_none().0,
102 ))
103 }
104 }
105
106 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
107 #[allow(deprecated)]
108 #[doc(alias = "gtk_app_chooser_button_get_show_dialog_item")]
109 #[doc(alias = "get_show_dialog_item")]
110 #[doc(alias = "show-dialog-item")]
111 pub fn shows_dialog_item(&self) -> bool {
112 unsafe {
113 from_glib(ffi::gtk_app_chooser_button_get_show_dialog_item(
114 self.to_glib_none().0,
115 ))
116 }
117 }
118
119 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
120 #[allow(deprecated)]
121 #[doc(alias = "gtk_app_chooser_button_set_active_custom_item")]
122 pub fn set_active_custom_item(&self, name: &str) {
123 unsafe {
124 ffi::gtk_app_chooser_button_set_active_custom_item(
125 self.to_glib_none().0,
126 name.to_glib_none().0,
127 );
128 }
129 }
130
131 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
132 #[allow(deprecated)]
133 #[doc(alias = "gtk_app_chooser_button_set_heading")]
134 #[doc(alias = "heading")]
135 pub fn set_heading(&self, heading: &str) {
136 unsafe {
137 ffi::gtk_app_chooser_button_set_heading(
138 self.to_glib_none().0,
139 heading.to_glib_none().0,
140 );
141 }
142 }
143
144 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
145 #[allow(deprecated)]
146 #[doc(alias = "gtk_app_chooser_button_set_modal")]
147 #[doc(alias = "modal")]
148 pub fn set_modal(&self, modal: bool) {
149 unsafe {
150 ffi::gtk_app_chooser_button_set_modal(self.to_glib_none().0, modal.into_glib());
151 }
152 }
153
154 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
155 #[allow(deprecated)]
156 #[doc(alias = "gtk_app_chooser_button_set_show_default_item")]
157 #[doc(alias = "show-default-item")]
158 pub fn set_show_default_item(&self, setting: bool) {
159 unsafe {
160 ffi::gtk_app_chooser_button_set_show_default_item(
161 self.to_glib_none().0,
162 setting.into_glib(),
163 );
164 }
165 }
166
167 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
168 #[allow(deprecated)]
169 #[doc(alias = "gtk_app_chooser_button_set_show_dialog_item")]
170 #[doc(alias = "show-dialog-item")]
171 pub fn set_show_dialog_item(&self, setting: bool) {
172 unsafe {
173 ffi::gtk_app_chooser_button_set_show_dialog_item(
174 self.to_glib_none().0,
175 setting.into_glib(),
176 );
177 }
178 }
179
180 #[cfg(feature = "v4_4")]
181 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
182 #[doc(alias = "activate")]
183 pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
184 unsafe extern "C" fn activate_trampoline<F: Fn(&AppChooserButton) + 'static>(
185 this: *mut ffi::GtkAppChooserButton,
186 f: glib::ffi::gpointer,
187 ) {
188 let f: &F = &*(f as *const F);
189 f(&from_glib_borrow(this))
190 }
191 unsafe {
192 let f: Box_<F> = Box_::new(f);
193 connect_raw(
194 self.as_ptr() as *mut _,
195 c"activate".as_ptr() as *const _,
196 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
197 activate_trampoline::<F> as *const (),
198 )),
199 Box_::into_raw(f),
200 )
201 }
202 }
203
204 #[cfg(feature = "v4_4")]
205 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
206 pub fn emit_activate(&self) {
207 self.emit_by_name::<()>("activate", &[]);
208 }
209
210 #[doc(alias = "changed")]
211 pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
212 unsafe extern "C" fn changed_trampoline<F: Fn(&AppChooserButton) + 'static>(
213 this: *mut ffi::GtkAppChooserButton,
214 f: glib::ffi::gpointer,
215 ) {
216 let f: &F = &*(f as *const F);
217 f(&from_glib_borrow(this))
218 }
219 unsafe {
220 let f: Box_<F> = Box_::new(f);
221 connect_raw(
222 self.as_ptr() as *mut _,
223 c"changed".as_ptr() as *const _,
224 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
225 changed_trampoline::<F> as *const (),
226 )),
227 Box_::into_raw(f),
228 )
229 }
230 }
231
232 #[doc(alias = "custom-item-activated")]
233 pub fn connect_custom_item_activated<F: Fn(&Self, &str) + 'static>(
234 &self,
235 detail: Option<&str>,
236 f: F,
237 ) -> SignalHandlerId {
238 unsafe extern "C" fn custom_item_activated_trampoline<
239 F: Fn(&AppChooserButton, &str) + 'static,
240 >(
241 this: *mut ffi::GtkAppChooserButton,
242 item_name: *mut std::ffi::c_char,
243 f: glib::ffi::gpointer,
244 ) {
245 let f: &F = &*(f as *const F);
246 f(
247 &from_glib_borrow(this),
248 &glib::GString::from_glib_borrow(item_name),
249 )
250 }
251 unsafe {
252 let f: Box_<F> = Box_::new(f);
253 let detailed_signal_name =
254 detail.map(|name| format!("custom-item-activated::{name}\0"));
255 let signal_name: &[u8] = detailed_signal_name
256 .as_ref()
257 .map_or(c"custom-item-activated".to_bytes(), |n| n.as_bytes());
258 connect_raw(
259 self.as_ptr() as *mut _,
260 signal_name.as_ptr() as *const _,
261 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
262 custom_item_activated_trampoline::<F> as *const (),
263 )),
264 Box_::into_raw(f),
265 )
266 }
267 }
268
269 #[doc(alias = "heading")]
270 pub fn connect_heading_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
271 unsafe extern "C" fn notify_heading_trampoline<F: Fn(&AppChooserButton) + 'static>(
272 this: *mut ffi::GtkAppChooserButton,
273 _param_spec: glib::ffi::gpointer,
274 f: glib::ffi::gpointer,
275 ) {
276 let f: &F = &*(f as *const F);
277 f(&from_glib_borrow(this))
278 }
279 unsafe {
280 let f: Box_<F> = Box_::new(f);
281 connect_raw(
282 self.as_ptr() as *mut _,
283 c"notify::heading".as_ptr() as *const _,
284 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
285 notify_heading_trampoline::<F> as *const (),
286 )),
287 Box_::into_raw(f),
288 )
289 }
290 }
291
292 #[doc(alias = "modal")]
293 pub fn connect_modal_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
294 unsafe extern "C" fn notify_modal_trampoline<F: Fn(&AppChooserButton) + 'static>(
295 this: *mut ffi::GtkAppChooserButton,
296 _param_spec: glib::ffi::gpointer,
297 f: glib::ffi::gpointer,
298 ) {
299 let f: &F = &*(f as *const F);
300 f(&from_glib_borrow(this))
301 }
302 unsafe {
303 let f: Box_<F> = Box_::new(f);
304 connect_raw(
305 self.as_ptr() as *mut _,
306 c"notify::modal".as_ptr() as *const _,
307 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
308 notify_modal_trampoline::<F> as *const (),
309 )),
310 Box_::into_raw(f),
311 )
312 }
313 }
314
315 #[doc(alias = "show-default-item")]
316 pub fn connect_show_default_item_notify<F: Fn(&Self) + 'static>(
317 &self,
318 f: F,
319 ) -> SignalHandlerId {
320 unsafe extern "C" fn notify_show_default_item_trampoline<
321 F: Fn(&AppChooserButton) + 'static,
322 >(
323 this: *mut ffi::GtkAppChooserButton,
324 _param_spec: glib::ffi::gpointer,
325 f: glib::ffi::gpointer,
326 ) {
327 let f: &F = &*(f as *const F);
328 f(&from_glib_borrow(this))
329 }
330 unsafe {
331 let f: Box_<F> = Box_::new(f);
332 connect_raw(
333 self.as_ptr() as *mut _,
334 c"notify::show-default-item".as_ptr() as *const _,
335 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
336 notify_show_default_item_trampoline::<F> as *const (),
337 )),
338 Box_::into_raw(f),
339 )
340 }
341 }
342
343 #[doc(alias = "show-dialog-item")]
344 pub fn connect_show_dialog_item_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
345 unsafe extern "C" fn notify_show_dialog_item_trampoline<
346 F: Fn(&AppChooserButton) + 'static,
347 >(
348 this: *mut ffi::GtkAppChooserButton,
349 _param_spec: glib::ffi::gpointer,
350 f: glib::ffi::gpointer,
351 ) {
352 let f: &F = &*(f as *const F);
353 f(&from_glib_borrow(this))
354 }
355 unsafe {
356 let f: Box_<F> = Box_::new(f);
357 connect_raw(
358 self.as_ptr() as *mut _,
359 c"notify::show-dialog-item".as_ptr() as *const _,
360 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
361 notify_show_dialog_item_trampoline::<F> as *const (),
362 )),
363 Box_::into_raw(f),
364 )
365 }
366 }
367}
368
369impl Default for AppChooserButton {
370 fn default() -> Self {
371 glib::object::Object::new::<Self>()
372 }
373}
374
375#[must_use = "The builder must be built to be used"]
380pub struct AppChooserButtonBuilder {
381 builder: glib::object::ObjectBuilder<'static, AppChooserButton>,
382}
383
384impl AppChooserButtonBuilder {
385 fn new() -> Self {
386 Self {
387 builder: glib::object::Object::builder(),
388 }
389 }
390
391 pub fn heading(self, heading: impl Into<glib::GString>) -> Self {
392 Self {
393 builder: self.builder.property("heading", heading.into()),
394 }
395 }
396
397 pub fn modal(self, modal: bool) -> Self {
398 Self {
399 builder: self.builder.property("modal", modal),
400 }
401 }
402
403 pub fn show_default_item(self, show_default_item: bool) -> Self {
404 Self {
405 builder: self
406 .builder
407 .property("show-default-item", show_default_item),
408 }
409 }
410
411 pub fn show_dialog_item(self, show_dialog_item: bool) -> Self {
412 Self {
413 builder: self.builder.property("show-dialog-item", show_dialog_item),
414 }
415 }
416
417 pub fn can_focus(self, can_focus: bool) -> Self {
418 Self {
419 builder: self.builder.property("can-focus", can_focus),
420 }
421 }
422
423 pub fn can_target(self, can_target: bool) -> Self {
424 Self {
425 builder: self.builder.property("can-target", can_target),
426 }
427 }
428
429 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
430 Self {
431 builder: self.builder.property("css-classes", css_classes.into()),
432 }
433 }
434
435 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
436 Self {
437 builder: self.builder.property("css-name", css_name.into()),
438 }
439 }
440
441 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
442 Self {
443 builder: self.builder.property("cursor", cursor.clone()),
444 }
445 }
446
447 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
448 Self {
449 builder: self.builder.property("focus-on-click", focus_on_click),
450 }
451 }
452
453 pub fn focusable(self, focusable: bool) -> Self {
454 Self {
455 builder: self.builder.property("focusable", focusable),
456 }
457 }
458
459 pub fn halign(self, halign: Align) -> Self {
460 Self {
461 builder: self.builder.property("halign", halign),
462 }
463 }
464
465 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
466 Self {
467 builder: self.builder.property("has-tooltip", has_tooltip),
468 }
469 }
470
471 pub fn height_request(self, height_request: i32) -> Self {
472 Self {
473 builder: self.builder.property("height-request", height_request),
474 }
475 }
476
477 pub fn hexpand(self, hexpand: bool) -> Self {
478 Self {
479 builder: self.builder.property("hexpand", hexpand),
480 }
481 }
482
483 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
484 Self {
485 builder: self.builder.property("hexpand-set", hexpand_set),
486 }
487 }
488
489 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
490 Self {
491 builder: self
492 .builder
493 .property("layout-manager", layout_manager.clone().upcast()),
494 }
495 }
496
497 #[cfg(feature = "v4_18")]
498 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
499 pub fn limit_events(self, limit_events: bool) -> Self {
500 Self {
501 builder: self.builder.property("limit-events", limit_events),
502 }
503 }
504
505 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
506 Self {
507 builder: self.builder.property("margin-bottom", margin_bottom),
508 }
509 }
510
511 pub fn margin_end(self, margin_end: i32) -> Self {
512 Self {
513 builder: self.builder.property("margin-end", margin_end),
514 }
515 }
516
517 pub fn margin_start(self, margin_start: i32) -> Self {
518 Self {
519 builder: self.builder.property("margin-start", margin_start),
520 }
521 }
522
523 pub fn margin_top(self, margin_top: i32) -> Self {
524 Self {
525 builder: self.builder.property("margin-top", margin_top),
526 }
527 }
528
529 pub fn name(self, name: impl Into<glib::GString>) -> Self {
530 Self {
531 builder: self.builder.property("name", name.into()),
532 }
533 }
534
535 pub fn opacity(self, opacity: f64) -> Self {
536 Self {
537 builder: self.builder.property("opacity", opacity),
538 }
539 }
540
541 pub fn overflow(self, overflow: Overflow) -> Self {
542 Self {
543 builder: self.builder.property("overflow", overflow),
544 }
545 }
546
547 pub fn receives_default(self, receives_default: bool) -> Self {
548 Self {
549 builder: self.builder.property("receives-default", receives_default),
550 }
551 }
552
553 pub fn sensitive(self, sensitive: bool) -> Self {
554 Self {
555 builder: self.builder.property("sensitive", sensitive),
556 }
557 }
558
559 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
560 Self {
561 builder: self
562 .builder
563 .property("tooltip-markup", tooltip_markup.into()),
564 }
565 }
566
567 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
568 Self {
569 builder: self.builder.property("tooltip-text", tooltip_text.into()),
570 }
571 }
572
573 pub fn valign(self, valign: Align) -> Self {
574 Self {
575 builder: self.builder.property("valign", valign),
576 }
577 }
578
579 pub fn vexpand(self, vexpand: bool) -> Self {
580 Self {
581 builder: self.builder.property("vexpand", vexpand),
582 }
583 }
584
585 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
586 Self {
587 builder: self.builder.property("vexpand-set", vexpand_set),
588 }
589 }
590
591 pub fn visible(self, visible: bool) -> Self {
592 Self {
593 builder: self.builder.property("visible", visible),
594 }
595 }
596
597 pub fn width_request(self, width_request: i32) -> Self {
598 Self {
599 builder: self.builder.property("width-request", width_request),
600 }
601 }
602
603 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
604 Self {
605 builder: self.builder.property("accessible-role", accessible_role),
606 }
607 }
608
609 pub fn content_type(self, content_type: impl Into<glib::GString>) -> Self {
610 Self {
611 builder: self.builder.property("content-type", content_type.into()),
612 }
613 }
614
615 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
618 pub fn build(self) -> AppChooserButton {
619 assert_initialized_main_thread!();
620 self.builder.build()
621 }
622}