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