gtk4/auto/
native_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
5use crate::{ffi, ResponseType, Window};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// Base class for platform dialogs that don't use [`Dialog`][crate::Dialog].
16    ///
17    /// Native dialogs are used in order to integrate better with a platform,
18    /// by looking the same as other native applications and supporting
19    /// platform specific features.
20    ///
21    /// The [`Dialog`][crate::Dialog] functions cannot be used on such objects,
22    /// but we need a similar API in order to drive them. The [`NativeDialog`][crate::NativeDialog]
23    /// object is an API that allows you to do this. It allows you to set
24    /// various common properties on the dialog, as well as show and hide
25    /// it and get a [`response`][struct@crate::NativeDialog#response] signal when the user
26    /// finished with the dialog.
27    ///
28    /// Note that unlike [`Dialog`][crate::Dialog], [`NativeDialog`][crate::NativeDialog] objects are not
29    /// toplevel widgets, and GTK does not keep them alive. It is your
30    /// responsibility to keep a reference until you are done with the
31    /// object.
32    ///
33    /// This is an Abstract Base Class, you cannot instantiate it.
34    ///
35    /// ## Properties
36    ///
37    ///
38    /// #### `modal`
39    ///  Whether the window should be modal with respect to its transient parent.
40    ///
41    /// Readable | Writeable
42    ///
43    ///
44    /// #### `title`
45    ///  The title of the dialog window
46    ///
47    /// Readable | Writeable
48    ///
49    ///
50    /// #### `transient-for`
51    ///  The transient parent of the dialog, or [`None`] for none.
52    ///
53    /// Readable | Writeable | Construct
54    ///
55    ///
56    /// #### `visible`
57    ///  Whether the window is currently visible.
58    ///
59    /// Readable | Writeable
60    ///
61    /// ## Signals
62    ///
63    ///
64    /// #### `response`
65    ///  Emitted when the user responds to the dialog.
66    ///
67    /// When this is called the dialog has been hidden.
68    ///
69    /// If you call [`NativeDialogExt::hide()`][crate::prelude::NativeDialogExt::hide()] before the user
70    /// responds to the dialog this signal will not be emitted.
71    ///
72    ///
73    ///
74    /// # Implements
75    ///
76    /// [`NativeDialogExt`][trait@crate::prelude::NativeDialogExt], [`trait@glib::ObjectExt`], [`NativeDialogExtManual`][trait@crate::prelude::NativeDialogExtManual]
77    #[doc(alias = "GtkNativeDialog")]
78    pub struct NativeDialog(Object<ffi::GtkNativeDialog, ffi::GtkNativeDialogClass>);
79
80    match fn {
81        type_ => || ffi::gtk_native_dialog_get_type(),
82    }
83}
84
85impl NativeDialog {
86    pub const NONE: Option<&'static NativeDialog> = None;
87}
88
89/// Trait containing all [`struct@NativeDialog`] methods.
90///
91/// # Implementors
92///
93/// [`FileChooserNative`][struct@crate::FileChooserNative], [`NativeDialog`][struct@crate::NativeDialog]
94pub trait NativeDialogExt: IsA<NativeDialog> + 'static {
95    #[doc(alias = "gtk_native_dialog_destroy")]
96    fn destroy(&self) {
97        unsafe {
98            ffi::gtk_native_dialog_destroy(self.as_ref().to_glib_none().0);
99        }
100    }
101
102    /// Returns whether the dialog is modal.
103    ///
104    /// # Returns
105    ///
106    /// [`true`] if the dialog is set to be modal
107    #[doc(alias = "gtk_native_dialog_get_modal")]
108    #[doc(alias = "get_modal")]
109    #[doc(alias = "modal")]
110    fn is_modal(&self) -> bool {
111        unsafe {
112            from_glib(ffi::gtk_native_dialog_get_modal(
113                self.as_ref().to_glib_none().0,
114            ))
115        }
116    }
117
118    /// Gets the title of the [`NativeDialog`][crate::NativeDialog].
119    ///
120    /// # Returns
121    ///
122    /// the title of the dialog, or [`None`] if none has
123    ///    been set explicitly. The returned string is owned by the widget
124    ///    and must not be modified or freed.
125    #[doc(alias = "gtk_native_dialog_get_title")]
126    #[doc(alias = "get_title")]
127    fn title(&self) -> Option<glib::GString> {
128        unsafe {
129            from_glib_none(ffi::gtk_native_dialog_get_title(
130                self.as_ref().to_glib_none().0,
131            ))
132        }
133    }
134
135    /// Fetches the transient parent for this window.
136    ///
137    /// # Returns
138    ///
139    /// the transient parent for this window,
140    ///   or [`None`] if no transient parent has been set.
141    #[doc(alias = "gtk_native_dialog_get_transient_for")]
142    #[doc(alias = "get_transient_for")]
143    #[doc(alias = "transient-for")]
144    fn transient_for(&self) -> Option<Window> {
145        unsafe {
146            from_glib_none(ffi::gtk_native_dialog_get_transient_for(
147                self.as_ref().to_glib_none().0,
148            ))
149        }
150    }
151
152    /// Determines whether the dialog is visible.
153    ///
154    /// # Returns
155    ///
156    /// [`true`] if the dialog is visible
157    #[doc(alias = "gtk_native_dialog_get_visible")]
158    #[doc(alias = "get_visible")]
159    #[doc(alias = "visible")]
160    fn is_visible(&self) -> bool {
161        unsafe {
162            from_glib(ffi::gtk_native_dialog_get_visible(
163                self.as_ref().to_glib_none().0,
164            ))
165        }
166    }
167
168    /// Hides the dialog if it is visible, aborting any interaction.
169    ///
170    /// Once this is called the [`response`][struct@crate::NativeDialog#response] signal
171    /// will *not* be emitted until after the next call to
172    /// [`show()`][Self::show()].
173    ///
174    /// If the dialog is not visible this does nothing.
175    #[doc(alias = "gtk_native_dialog_hide")]
176    fn hide(&self) {
177        unsafe {
178            ffi::gtk_native_dialog_hide(self.as_ref().to_glib_none().0);
179        }
180    }
181
182    /// Sets a dialog modal or non-modal.
183    ///
184    /// Modal dialogs prevent interaction with other windows in the same
185    /// application. To keep modal dialogs on top of main application
186    /// windows, use [`set_transient_for()`][Self::set_transient_for()] to make
187    /// the dialog transient for the parent; most window managers will
188    /// then disallow lowering the dialog below the parent.
189    /// ## `modal`
190    /// whether the window is modal
191    #[doc(alias = "gtk_native_dialog_set_modal")]
192    #[doc(alias = "modal")]
193    fn set_modal(&self, modal: bool) {
194        unsafe {
195            ffi::gtk_native_dialog_set_modal(self.as_ref().to_glib_none().0, modal.into_glib());
196        }
197    }
198
199    /// Sets the title of the [`NativeDialog`][crate::NativeDialog]
200    /// ## `title`
201    /// title of the dialog
202    #[doc(alias = "gtk_native_dialog_set_title")]
203    #[doc(alias = "title")]
204    fn set_title(&self, title: &str) {
205        unsafe {
206            ffi::gtk_native_dialog_set_title(
207                self.as_ref().to_glib_none().0,
208                title.to_glib_none().0,
209            );
210        }
211    }
212
213    /// Dialog windows should be set transient for the main application
214    /// window they were spawned from.
215    ///
216    /// This allows window managers to e.g. keep the dialog on top of the
217    /// main window, or center the dialog over the main window.
218    ///
219    /// Passing [`None`] for @parent unsets the current transient window.
220    /// ## `parent`
221    /// parent window
222    #[doc(alias = "gtk_native_dialog_set_transient_for")]
223    #[doc(alias = "transient-for")]
224    fn set_transient_for(&self, parent: Option<&impl IsA<Window>>) {
225        unsafe {
226            ffi::gtk_native_dialog_set_transient_for(
227                self.as_ref().to_glib_none().0,
228                parent.map(|p| p.as_ref()).to_glib_none().0,
229            );
230        }
231    }
232
233    /// Shows the dialog on the display.
234    ///
235    /// When the user accepts the state of the dialog the dialog will
236    /// be automatically hidden and the [`response`][struct@crate::NativeDialog#response]
237    /// signal will be emitted.
238    ///
239    /// Multiple calls while the dialog is visible will be ignored.
240    #[doc(alias = "gtk_native_dialog_show")]
241    fn show(&self) {
242        unsafe {
243            ffi::gtk_native_dialog_show(self.as_ref().to_glib_none().0);
244        }
245    }
246
247    /// Whether the window is currently visible.
248    fn set_visible(&self, visible: bool) {
249        ObjectExt::set_property(self.as_ref(), "visible", visible)
250    }
251
252    /// Emitted when the user responds to the dialog.
253    ///
254    /// When this is called the dialog has been hidden.
255    ///
256    /// If you call [`hide()`][Self::hide()] before the user
257    /// responds to the dialog this signal will not be emitted.
258    /// ## `response_id`
259    /// the response ID
260    #[doc(alias = "response")]
261    fn connect_response<F: Fn(&Self, ResponseType) + 'static>(&self, f: F) -> SignalHandlerId {
262        unsafe extern "C" fn response_trampoline<
263            P: IsA<NativeDialog>,
264            F: Fn(&P, ResponseType) + 'static,
265        >(
266            this: *mut ffi::GtkNativeDialog,
267            response_id: ffi::GtkResponseType,
268            f: glib::ffi::gpointer,
269        ) {
270            let f: &F = &*(f as *const F);
271            f(
272                NativeDialog::from_glib_borrow(this).unsafe_cast_ref(),
273                from_glib(response_id),
274            )
275        }
276        unsafe {
277            let f: Box_<F> = Box_::new(f);
278            connect_raw(
279                self.as_ptr() as *mut _,
280                c"response".as_ptr() as *const _,
281                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
282                    response_trampoline::<Self, F> as *const (),
283                )),
284                Box_::into_raw(f),
285            )
286        }
287    }
288
289    #[doc(alias = "modal")]
290    fn connect_modal_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
291        unsafe extern "C" fn notify_modal_trampoline<P: IsA<NativeDialog>, F: Fn(&P) + 'static>(
292            this: *mut ffi::GtkNativeDialog,
293            _param_spec: glib::ffi::gpointer,
294            f: glib::ffi::gpointer,
295        ) {
296            let f: &F = &*(f as *const F);
297            f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
298        }
299        unsafe {
300            let f: Box_<F> = Box_::new(f);
301            connect_raw(
302                self.as_ptr() as *mut _,
303                c"notify::modal".as_ptr() as *const _,
304                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
305                    notify_modal_trampoline::<Self, F> as *const (),
306                )),
307                Box_::into_raw(f),
308            )
309        }
310    }
311
312    #[doc(alias = "title")]
313    fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
314        unsafe extern "C" fn notify_title_trampoline<P: IsA<NativeDialog>, F: Fn(&P) + 'static>(
315            this: *mut ffi::GtkNativeDialog,
316            _param_spec: glib::ffi::gpointer,
317            f: glib::ffi::gpointer,
318        ) {
319            let f: &F = &*(f as *const F);
320            f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
321        }
322        unsafe {
323            let f: Box_<F> = Box_::new(f);
324            connect_raw(
325                self.as_ptr() as *mut _,
326                c"notify::title".as_ptr() as *const _,
327                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
328                    notify_title_trampoline::<Self, F> as *const (),
329                )),
330                Box_::into_raw(f),
331            )
332        }
333    }
334
335    #[doc(alias = "transient-for")]
336    fn connect_transient_for_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
337        unsafe extern "C" fn notify_transient_for_trampoline<
338            P: IsA<NativeDialog>,
339            F: Fn(&P) + 'static,
340        >(
341            this: *mut ffi::GtkNativeDialog,
342            _param_spec: glib::ffi::gpointer,
343            f: glib::ffi::gpointer,
344        ) {
345            let f: &F = &*(f as *const F);
346            f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
347        }
348        unsafe {
349            let f: Box_<F> = Box_::new(f);
350            connect_raw(
351                self.as_ptr() as *mut _,
352                c"notify::transient-for".as_ptr() as *const _,
353                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
354                    notify_transient_for_trampoline::<Self, F> as *const (),
355                )),
356                Box_::into_raw(f),
357            )
358        }
359    }
360
361    #[doc(alias = "visible")]
362    fn connect_visible_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
363        unsafe extern "C" fn notify_visible_trampoline<
364            P: IsA<NativeDialog>,
365            F: Fn(&P) + 'static,
366        >(
367            this: *mut ffi::GtkNativeDialog,
368            _param_spec: glib::ffi::gpointer,
369            f: glib::ffi::gpointer,
370        ) {
371            let f: &F = &*(f as *const F);
372            f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
373        }
374        unsafe {
375            let f: Box_<F> = Box_::new(f);
376            connect_raw(
377                self.as_ptr() as *mut _,
378                c"notify::visible".as_ptr() as *const _,
379                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
380                    notify_visible_trampoline::<Self, F> as *const (),
381                )),
382                Box_::into_raw(f),
383            )
384        }
385    }
386}
387
388impl<O: IsA<NativeDialog>> NativeDialogExt for O {}