Skip to main content

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::{ResponseType, Window, ffi};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
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            unsafe {
271                let f: &F = &*(f as *const F);
272                f(
273                    NativeDialog::from_glib_borrow(this).unsafe_cast_ref(),
274                    from_glib(response_id),
275                )
276            }
277        }
278        unsafe {
279            let f: Box_<F> = Box_::new(f);
280            connect_raw(
281                self.as_ptr() as *mut _,
282                c"response".as_ptr() as *const _,
283                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
284                    response_trampoline::<Self, F> as *const (),
285                )),
286                Box_::into_raw(f),
287            )
288        }
289    }
290
291    #[doc(alias = "modal")]
292    fn connect_modal_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
293        unsafe extern "C" fn notify_modal_trampoline<P: IsA<NativeDialog>, F: Fn(&P) + 'static>(
294            this: *mut ffi::GtkNativeDialog,
295            _param_spec: glib::ffi::gpointer,
296            f: glib::ffi::gpointer,
297        ) {
298            unsafe {
299                let f: &F = &*(f as *const F);
300                f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
301            }
302        }
303        unsafe {
304            let f: Box_<F> = Box_::new(f);
305            connect_raw(
306                self.as_ptr() as *mut _,
307                c"notify::modal".as_ptr() as *const _,
308                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
309                    notify_modal_trampoline::<Self, F> as *const (),
310                )),
311                Box_::into_raw(f),
312            )
313        }
314    }
315
316    #[doc(alias = "title")]
317    fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
318        unsafe extern "C" fn notify_title_trampoline<P: IsA<NativeDialog>, F: Fn(&P) + 'static>(
319            this: *mut ffi::GtkNativeDialog,
320            _param_spec: glib::ffi::gpointer,
321            f: glib::ffi::gpointer,
322        ) {
323            unsafe {
324                let f: &F = &*(f as *const F);
325                f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
326            }
327        }
328        unsafe {
329            let f: Box_<F> = Box_::new(f);
330            connect_raw(
331                self.as_ptr() as *mut _,
332                c"notify::title".as_ptr() as *const _,
333                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
334                    notify_title_trampoline::<Self, F> as *const (),
335                )),
336                Box_::into_raw(f),
337            )
338        }
339    }
340
341    #[doc(alias = "transient-for")]
342    fn connect_transient_for_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
343        unsafe extern "C" fn notify_transient_for_trampoline<
344            P: IsA<NativeDialog>,
345            F: Fn(&P) + 'static,
346        >(
347            this: *mut ffi::GtkNativeDialog,
348            _param_spec: glib::ffi::gpointer,
349            f: glib::ffi::gpointer,
350        ) {
351            unsafe {
352                let f: &F = &*(f as *const F);
353                f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
354            }
355        }
356        unsafe {
357            let f: Box_<F> = Box_::new(f);
358            connect_raw(
359                self.as_ptr() as *mut _,
360                c"notify::transient-for".as_ptr() as *const _,
361                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
362                    notify_transient_for_trampoline::<Self, F> as *const (),
363                )),
364                Box_::into_raw(f),
365            )
366        }
367    }
368
369    #[doc(alias = "visible")]
370    fn connect_visible_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
371        unsafe extern "C" fn notify_visible_trampoline<
372            P: IsA<NativeDialog>,
373            F: Fn(&P) + 'static,
374        >(
375            this: *mut ffi::GtkNativeDialog,
376            _param_spec: glib::ffi::gpointer,
377            f: glib::ffi::gpointer,
378        ) {
379            unsafe {
380                let f: &F = &*(f as *const F);
381                f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
382            }
383        }
384        unsafe {
385            let f: Box_<F> = Box_::new(f);
386            connect_raw(
387                self.as_ptr() as *mut _,
388                c"notify::visible".as_ptr() as *const _,
389                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
390                    notify_visible_trampoline::<Self, F> as *const (),
391                )),
392                Box_::into_raw(f),
393            )
394        }
395    }
396}
397
398impl<O: IsA<NativeDialog>> NativeDialogExt for O {}