[go: up one dir, main page]

gtk4/auto/
dialog.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#![allow(deprecated)]
5
6#[cfg(feature = "v4_20")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
8use crate::WindowGravity;
9use crate::{
10    ffi, Accessible, AccessibleRole, Align, Application, Box, Buildable, ConstraintTarget,
11    HeaderBar, LayoutManager, Native, Overflow, ResponseType, Root, ShortcutManager, Widget,
12    Window,
13};
14use glib::{
15    object::ObjectType as _,
16    prelude::*,
17    signal::{connect_raw, SignalHandlerId},
18    translate::*,
19};
20use std::boxed::Box as Box_;
21
22glib::wrapper! {
23    #[doc(alias = "GtkDialog")]
24    pub struct Dialog(Object<ffi::GtkDialog, ffi::GtkDialogClass>) @extends Window, Widget, @implements Accessible, Buildable, ConstraintTarget, Native, Root, ShortcutManager;
25
26    match fn {
27        type_ => || ffi::gtk_dialog_get_type(),
28    }
29}
30
31impl Dialog {
32    pub const NONE: Option<&'static Dialog> = None;
33
34    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
35    #[allow(deprecated)]
36    #[doc(alias = "gtk_dialog_new")]
37    pub fn new() -> Dialog {
38        assert_initialized_main_thread!();
39        unsafe { Widget::from_glib_none(ffi::gtk_dialog_new()).unsafe_cast() }
40    }
41
42    // rustdoc-stripper-ignore-next
43    /// Creates a new builder-pattern struct instance to construct [`Dialog`] objects.
44    ///
45    /// This method returns an instance of [`DialogBuilder`](crate::builders::DialogBuilder) which can be used to create [`Dialog`] objects.
46    pub fn builder() -> DialogBuilder {
47        DialogBuilder::new()
48    }
49}
50
51impl Default for Dialog {
52    fn default() -> Self {
53        Self::new()
54    }
55}
56
57// rustdoc-stripper-ignore-next
58/// A [builder-pattern] type to construct [`Dialog`] objects.
59///
60/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
61#[must_use = "The builder must be built to be used"]
62pub struct DialogBuilder {
63    builder: glib::object::ObjectBuilder<'static, Dialog>,
64}
65
66impl DialogBuilder {
67    fn new() -> Self {
68        Self {
69            builder: glib::object::Object::builder(),
70        }
71    }
72
73    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
74    pub fn use_header_bar(self, use_header_bar: i32) -> Self {
75        Self {
76            builder: self.builder.property("use-header-bar", use_header_bar),
77        }
78    }
79
80    pub fn application(self, application: &impl IsA<Application>) -> Self {
81        Self {
82            builder: self
83                .builder
84                .property("application", application.clone().upcast()),
85        }
86    }
87
88    pub fn child(self, child: &impl IsA<Widget>) -> Self {
89        Self {
90            builder: self.builder.property("child", child.clone().upcast()),
91        }
92    }
93
94    pub fn decorated(self, decorated: bool) -> Self {
95        Self {
96            builder: self.builder.property("decorated", decorated),
97        }
98    }
99
100    pub fn default_height(self, default_height: i32) -> Self {
101        Self {
102            builder: self.builder.property("default-height", default_height),
103        }
104    }
105
106    pub fn default_widget(self, default_widget: &impl IsA<Widget>) -> Self {
107        Self {
108            builder: self
109                .builder
110                .property("default-widget", default_widget.clone().upcast()),
111        }
112    }
113
114    pub fn default_width(self, default_width: i32) -> Self {
115        Self {
116            builder: self.builder.property("default-width", default_width),
117        }
118    }
119
120    pub fn deletable(self, deletable: bool) -> Self {
121        Self {
122            builder: self.builder.property("deletable", deletable),
123        }
124    }
125
126    pub fn destroy_with_parent(self, destroy_with_parent: bool) -> Self {
127        Self {
128            builder: self
129                .builder
130                .property("destroy-with-parent", destroy_with_parent),
131        }
132    }
133
134    pub fn display(self, display: &impl IsA<gdk::Display>) -> Self {
135        Self {
136            builder: self.builder.property("display", display.clone().upcast()),
137        }
138    }
139
140    pub fn focus_visible(self, focus_visible: bool) -> Self {
141        Self {
142            builder: self.builder.property("focus-visible", focus_visible),
143        }
144    }
145
146    pub fn focus_widget(self, focus_widget: &impl IsA<Widget>) -> Self {
147        Self {
148            builder: self
149                .builder
150                .property("focus-widget", focus_widget.clone().upcast()),
151        }
152    }
153
154    pub fn fullscreened(self, fullscreened: bool) -> Self {
155        Self {
156            builder: self.builder.property("fullscreened", fullscreened),
157        }
158    }
159
160    #[cfg(feature = "v4_20")]
161    #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
162    pub fn gravity(self, gravity: WindowGravity) -> Self {
163        Self {
164            builder: self.builder.property("gravity", gravity),
165        }
166    }
167
168    #[cfg(feature = "v4_2")]
169    #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
170    pub fn handle_menubar_accel(self, handle_menubar_accel: bool) -> Self {
171        Self {
172            builder: self
173                .builder
174                .property("handle-menubar-accel", handle_menubar_accel),
175        }
176    }
177
178    pub fn hide_on_close(self, hide_on_close: bool) -> Self {
179        Self {
180            builder: self.builder.property("hide-on-close", hide_on_close),
181        }
182    }
183
184    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
185        Self {
186            builder: self.builder.property("icon-name", icon_name.into()),
187        }
188    }
189
190    pub fn maximized(self, maximized: bool) -> Self {
191        Self {
192            builder: self.builder.property("maximized", maximized),
193        }
194    }
195
196    pub fn mnemonics_visible(self, mnemonics_visible: bool) -> Self {
197        Self {
198            builder: self
199                .builder
200                .property("mnemonics-visible", mnemonics_visible),
201        }
202    }
203
204    pub fn modal(self, modal: bool) -> Self {
205        Self {
206            builder: self.builder.property("modal", modal),
207        }
208    }
209
210    pub fn resizable(self, resizable: bool) -> Self {
211        Self {
212            builder: self.builder.property("resizable", resizable),
213        }
214    }
215
216    pub fn startup_id(self, startup_id: impl Into<glib::GString>) -> Self {
217        Self {
218            builder: self.builder.property("startup-id", startup_id.into()),
219        }
220    }
221
222    pub fn title(self, title: impl Into<glib::GString>) -> Self {
223        Self {
224            builder: self.builder.property("title", title.into()),
225        }
226    }
227
228    #[cfg(feature = "v4_6")]
229    #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
230    pub fn titlebar(self, titlebar: &impl IsA<Widget>) -> Self {
231        Self {
232            builder: self.builder.property("titlebar", titlebar.clone().upcast()),
233        }
234    }
235
236    pub fn transient_for(self, transient_for: &impl IsA<Window>) -> Self {
237        Self {
238            builder: self
239                .builder
240                .property("transient-for", transient_for.clone().upcast()),
241        }
242    }
243
244    pub fn can_focus(self, can_focus: bool) -> Self {
245        Self {
246            builder: self.builder.property("can-focus", can_focus),
247        }
248    }
249
250    pub fn can_target(self, can_target: bool) -> Self {
251        Self {
252            builder: self.builder.property("can-target", can_target),
253        }
254    }
255
256    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
257        Self {
258            builder: self.builder.property("css-classes", css_classes.into()),
259        }
260    }
261
262    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
263        Self {
264            builder: self.builder.property("css-name", css_name.into()),
265        }
266    }
267
268    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
269        Self {
270            builder: self.builder.property("cursor", cursor.clone()),
271        }
272    }
273
274    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
275        Self {
276            builder: self.builder.property("focus-on-click", focus_on_click),
277        }
278    }
279
280    pub fn focusable(self, focusable: bool) -> Self {
281        Self {
282            builder: self.builder.property("focusable", focusable),
283        }
284    }
285
286    pub fn halign(self, halign: Align) -> Self {
287        Self {
288            builder: self.builder.property("halign", halign),
289        }
290    }
291
292    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
293        Self {
294            builder: self.builder.property("has-tooltip", has_tooltip),
295        }
296    }
297
298    pub fn height_request(self, height_request: i32) -> Self {
299        Self {
300            builder: self.builder.property("height-request", height_request),
301        }
302    }
303
304    pub fn hexpand(self, hexpand: bool) -> Self {
305        Self {
306            builder: self.builder.property("hexpand", hexpand),
307        }
308    }
309
310    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
311        Self {
312            builder: self.builder.property("hexpand-set", hexpand_set),
313        }
314    }
315
316    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
317        Self {
318            builder: self
319                .builder
320                .property("layout-manager", layout_manager.clone().upcast()),
321        }
322    }
323
324    #[cfg(feature = "v4_18")]
325    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
326    pub fn limit_events(self, limit_events: bool) -> Self {
327        Self {
328            builder: self.builder.property("limit-events", limit_events),
329        }
330    }
331
332    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
333        Self {
334            builder: self.builder.property("margin-bottom", margin_bottom),
335        }
336    }
337
338    pub fn margin_end(self, margin_end: i32) -> Self {
339        Self {
340            builder: self.builder.property("margin-end", margin_end),
341        }
342    }
343
344    pub fn margin_start(self, margin_start: i32) -> Self {
345        Self {
346            builder: self.builder.property("margin-start", margin_start),
347        }
348    }
349
350    pub fn margin_top(self, margin_top: i32) -> Self {
351        Self {
352            builder: self.builder.property("margin-top", margin_top),
353        }
354    }
355
356    pub fn name(self, name: impl Into<glib::GString>) -> Self {
357        Self {
358            builder: self.builder.property("name", name.into()),
359        }
360    }
361
362    pub fn opacity(self, opacity: f64) -> Self {
363        Self {
364            builder: self.builder.property("opacity", opacity),
365        }
366    }
367
368    pub fn overflow(self, overflow: Overflow) -> Self {
369        Self {
370            builder: self.builder.property("overflow", overflow),
371        }
372    }
373
374    pub fn receives_default(self, receives_default: bool) -> Self {
375        Self {
376            builder: self.builder.property("receives-default", receives_default),
377        }
378    }
379
380    pub fn sensitive(self, sensitive: bool) -> Self {
381        Self {
382            builder: self.builder.property("sensitive", sensitive),
383        }
384    }
385
386    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
387        Self {
388            builder: self
389                .builder
390                .property("tooltip-markup", tooltip_markup.into()),
391        }
392    }
393
394    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
395        Self {
396            builder: self.builder.property("tooltip-text", tooltip_text.into()),
397        }
398    }
399
400    pub fn valign(self, valign: Align) -> Self {
401        Self {
402            builder: self.builder.property("valign", valign),
403        }
404    }
405
406    pub fn vexpand(self, vexpand: bool) -> Self {
407        Self {
408            builder: self.builder.property("vexpand", vexpand),
409        }
410    }
411
412    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
413        Self {
414            builder: self.builder.property("vexpand-set", vexpand_set),
415        }
416    }
417
418    pub fn visible(self, visible: bool) -> Self {
419        Self {
420            builder: self.builder.property("visible", visible),
421        }
422    }
423
424    pub fn width_request(self, width_request: i32) -> Self {
425        Self {
426            builder: self.builder.property("width-request", width_request),
427        }
428    }
429
430    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
431        Self {
432            builder: self.builder.property("accessible-role", accessible_role),
433        }
434    }
435
436    // rustdoc-stripper-ignore-next
437    /// Build the [`Dialog`].
438    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
439    pub fn build(self) -> Dialog {
440        assert_initialized_main_thread!();
441        self.builder.build()
442    }
443}
444
445pub trait DialogExt: IsA<Dialog> + 'static {
446    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
447    #[allow(deprecated)]
448    #[doc(alias = "gtk_dialog_add_action_widget")]
449    fn add_action_widget(&self, child: &impl IsA<Widget>, response_id: ResponseType) {
450        unsafe {
451            ffi::gtk_dialog_add_action_widget(
452                self.as_ref().to_glib_none().0,
453                child.as_ref().to_glib_none().0,
454                response_id.into_glib(),
455            );
456        }
457    }
458
459    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
460    #[allow(deprecated)]
461    #[doc(alias = "gtk_dialog_add_button")]
462    fn add_button(&self, button_text: &str, response_id: ResponseType) -> Widget {
463        unsafe {
464            from_glib_none(ffi::gtk_dialog_add_button(
465                self.as_ref().to_glib_none().0,
466                button_text.to_glib_none().0,
467                response_id.into_glib(),
468            ))
469        }
470    }
471
472    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
473    #[allow(deprecated)]
474    #[doc(alias = "gtk_dialog_get_content_area")]
475    #[doc(alias = "get_content_area")]
476    fn content_area(&self) -> Box {
477        unsafe {
478            from_glib_none(ffi::gtk_dialog_get_content_area(
479                self.as_ref().to_glib_none().0,
480            ))
481        }
482    }
483
484    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
485    #[allow(deprecated)]
486    #[doc(alias = "gtk_dialog_get_header_bar")]
487    #[doc(alias = "get_header_bar")]
488    fn header_bar(&self) -> HeaderBar {
489        unsafe {
490            from_glib_none(ffi::gtk_dialog_get_header_bar(
491                self.as_ref().to_glib_none().0,
492            ))
493        }
494    }
495
496    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
497    #[allow(deprecated)]
498    #[doc(alias = "gtk_dialog_get_widget_for_response")]
499    #[doc(alias = "get_widget_for_response")]
500    fn widget_for_response(&self, response_id: ResponseType) -> Option<Widget> {
501        unsafe {
502            from_glib_none(ffi::gtk_dialog_get_widget_for_response(
503                self.as_ref().to_glib_none().0,
504                response_id.into_glib(),
505            ))
506        }
507    }
508
509    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
510    #[allow(deprecated)]
511    #[doc(alias = "gtk_dialog_response")]
512    fn response(&self, response_id: ResponseType) {
513        unsafe {
514            ffi::gtk_dialog_response(self.as_ref().to_glib_none().0, response_id.into_glib());
515        }
516    }
517
518    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
519    #[allow(deprecated)]
520    #[doc(alias = "gtk_dialog_set_default_response")]
521    fn set_default_response(&self, response_id: ResponseType) {
522        unsafe {
523            ffi::gtk_dialog_set_default_response(
524                self.as_ref().to_glib_none().0,
525                response_id.into_glib(),
526            );
527        }
528    }
529
530    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
531    #[allow(deprecated)]
532    #[doc(alias = "gtk_dialog_set_response_sensitive")]
533    fn set_response_sensitive(&self, response_id: ResponseType, setting: bool) {
534        unsafe {
535            ffi::gtk_dialog_set_response_sensitive(
536                self.as_ref().to_glib_none().0,
537                response_id.into_glib(),
538                setting.into_glib(),
539            );
540        }
541    }
542
543    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
544    #[doc(alias = "use-header-bar")]
545    fn use_header_bar(&self) -> i32 {
546        ObjectExt::property(self.as_ref(), "use-header-bar")
547    }
548
549    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
550    #[doc(alias = "close")]
551    fn connect_close<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
552        unsafe extern "C" fn close_trampoline<P: IsA<Dialog>, F: Fn(&P) + 'static>(
553            this: *mut ffi::GtkDialog,
554            f: glib::ffi::gpointer,
555        ) {
556            let f: &F = &*(f as *const F);
557            f(Dialog::from_glib_borrow(this).unsafe_cast_ref())
558        }
559        unsafe {
560            let f: Box_<F> = Box_::new(f);
561            connect_raw(
562                self.as_ptr() as *mut _,
563                c"close".as_ptr() as *const _,
564                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
565                    close_trampoline::<Self, F> as *const (),
566                )),
567                Box_::into_raw(f),
568            )
569        }
570    }
571
572    fn emit_close(&self) {
573        self.emit_by_name::<()>("close", &[]);
574    }
575
576    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
577    #[doc(alias = "response")]
578    fn connect_response<F: Fn(&Self, ResponseType) + 'static>(&self, f: F) -> SignalHandlerId {
579        unsafe extern "C" fn response_trampoline<
580            P: IsA<Dialog>,
581            F: Fn(&P, ResponseType) + 'static,
582        >(
583            this: *mut ffi::GtkDialog,
584            response_id: ffi::GtkResponseType,
585            f: glib::ffi::gpointer,
586        ) {
587            let f: &F = &*(f as *const F);
588            f(
589                Dialog::from_glib_borrow(this).unsafe_cast_ref(),
590                from_glib(response_id),
591            )
592        }
593        unsafe {
594            let f: Box_<F> = Box_::new(f);
595            connect_raw(
596                self.as_ptr() as *mut _,
597                c"response".as_ptr() as *const _,
598                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
599                    response_trampoline::<Self, F> as *const (),
600                )),
601                Box_::into_raw(f),
602            )
603        }
604    }
605}
606
607impl<O: IsA<Dialog>> DialogExt for O {}