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 /// Native dialogs are platform dialogs that don't use [`Dialog`][crate::Dialog].
16 ///
17 /// They are used in order to integrate better with a platform, by
18 /// 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
89mod sealed {
90 pub trait Sealed {}
91 impl<T: super::IsA<super::NativeDialog>> Sealed for T {}
92}
93
94/// Trait containing all [`struct@NativeDialog`] methods.
95///
96/// # Implementors
97///
98/// [`FileChooserNative`][struct@crate::FileChooserNative], [`NativeDialog`][struct@crate::NativeDialog]
99pub trait NativeDialogExt: IsA<NativeDialog> + sealed::Sealed + 'static {
100 #[doc(alias = "gtk_native_dialog_destroy")]
101 fn destroy(&self) {
102 unsafe {
103 ffi::gtk_native_dialog_destroy(self.as_ref().to_glib_none().0);
104 }
105 }
106
107 /// Returns whether the dialog is modal.
108 ///
109 /// # Returns
110 ///
111 /// [`true`] if the dialog is set to be modal
112 #[doc(alias = "gtk_native_dialog_get_modal")]
113 #[doc(alias = "get_modal")]
114 #[doc(alias = "modal")]
115 fn is_modal(&self) -> bool {
116 unsafe {
117 from_glib(ffi::gtk_native_dialog_get_modal(
118 self.as_ref().to_glib_none().0,
119 ))
120 }
121 }
122
123 /// Gets the title of the [`NativeDialog`][crate::NativeDialog].
124 ///
125 /// # Returns
126 ///
127 /// the title of the dialog, or [`None`] if none has
128 /// been set explicitly. The returned string is owned by the widget
129 /// and must not be modified or freed.
130 #[doc(alias = "gtk_native_dialog_get_title")]
131 #[doc(alias = "get_title")]
132 fn title(&self) -> Option<glib::GString> {
133 unsafe {
134 from_glib_none(ffi::gtk_native_dialog_get_title(
135 self.as_ref().to_glib_none().0,
136 ))
137 }
138 }
139
140 /// Fetches the transient parent for this window.
141 ///
142 /// # Returns
143 ///
144 /// the transient parent for this window,
145 /// or [`None`] if no transient parent has been set.
146 #[doc(alias = "gtk_native_dialog_get_transient_for")]
147 #[doc(alias = "get_transient_for")]
148 #[doc(alias = "transient-for")]
149 fn transient_for(&self) -> Option<Window> {
150 unsafe {
151 from_glib_none(ffi::gtk_native_dialog_get_transient_for(
152 self.as_ref().to_glib_none().0,
153 ))
154 }
155 }
156
157 /// Determines whether the dialog is visible.
158 ///
159 /// # Returns
160 ///
161 /// [`true`] if the dialog is visible
162 #[doc(alias = "gtk_native_dialog_get_visible")]
163 #[doc(alias = "get_visible")]
164 #[doc(alias = "visible")]
165 fn is_visible(&self) -> bool {
166 unsafe {
167 from_glib(ffi::gtk_native_dialog_get_visible(
168 self.as_ref().to_glib_none().0,
169 ))
170 }
171 }
172
173 /// Hides the dialog if it is visible, aborting any interaction.
174 ///
175 /// Once this is called the [`response`][struct@crate::NativeDialog#response] signal
176 /// will *not* be emitted until after the next call to
177 /// [`show()`][Self::show()].
178 ///
179 /// If the dialog is not visible this does nothing.
180 #[doc(alias = "gtk_native_dialog_hide")]
181 fn hide(&self) {
182 unsafe {
183 ffi::gtk_native_dialog_hide(self.as_ref().to_glib_none().0);
184 }
185 }
186
187 /// Sets a dialog modal or non-modal.
188 ///
189 /// Modal dialogs prevent interaction with other windows in the same
190 /// application. To keep modal dialogs on top of main application
191 /// windows, use [`set_transient_for()`][Self::set_transient_for()] to make
192 /// the dialog transient for the parent; most window managers will
193 /// then disallow lowering the dialog below the parent.
194 /// ## `modal`
195 /// whether the window is modal
196 #[doc(alias = "gtk_native_dialog_set_modal")]
197 #[doc(alias = "modal")]
198 fn set_modal(&self, modal: bool) {
199 unsafe {
200 ffi::gtk_native_dialog_set_modal(self.as_ref().to_glib_none().0, modal.into_glib());
201 }
202 }
203
204 /// Sets the title of the [`NativeDialog`][crate::NativeDialog]
205 /// ## `title`
206 /// title of the dialog
207 #[doc(alias = "gtk_native_dialog_set_title")]
208 #[doc(alias = "title")]
209 fn set_title(&self, title: &str) {
210 unsafe {
211 ffi::gtk_native_dialog_set_title(
212 self.as_ref().to_glib_none().0,
213 title.to_glib_none().0,
214 );
215 }
216 }
217
218 /// Dialog windows should be set transient for the main application
219 /// window they were spawned from.
220 ///
221 /// This allows window managers to e.g. keep the dialog on top of the
222 /// main window, or center the dialog over the main window.
223 ///
224 /// Passing [`None`] for @parent unsets the current transient window.
225 /// ## `parent`
226 /// parent window
227 #[doc(alias = "gtk_native_dialog_set_transient_for")]
228 #[doc(alias = "transient-for")]
229 fn set_transient_for(&self, parent: Option<&impl IsA<Window>>) {
230 unsafe {
231 ffi::gtk_native_dialog_set_transient_for(
232 self.as_ref().to_glib_none().0,
233 parent.map(|p| p.as_ref()).to_glib_none().0,
234 );
235 }
236 }
237
238 /// Shows the dialog on the display.
239 ///
240 /// When the user accepts the state of the dialog the dialog will
241 /// be automatically hidden and the [`response`][struct@crate::NativeDialog#response]
242 /// signal will be emitted.
243 ///
244 /// Multiple calls while the dialog is visible will be ignored.
245 #[doc(alias = "gtk_native_dialog_show")]
246 fn show(&self) {
247 unsafe {
248 ffi::gtk_native_dialog_show(self.as_ref().to_glib_none().0);
249 }
250 }
251
252 /// Whether the window is currently visible.
253 fn set_visible(&self, visible: bool) {
254 ObjectExt::set_property(self.as_ref(), "visible", visible)
255 }
256
257 /// Emitted when the user responds to the dialog.
258 ///
259 /// When this is called the dialog has been hidden.
260 ///
261 /// If you call [`hide()`][Self::hide()] before the user
262 /// responds to the dialog this signal will not be emitted.
263 /// ## `response_id`
264 /// the response ID
265 #[doc(alias = "response")]
266 fn connect_response<F: Fn(&Self, ResponseType) + 'static>(&self, f: F) -> SignalHandlerId {
267 unsafe extern "C" fn response_trampoline<
268 P: IsA<NativeDialog>,
269 F: Fn(&P, ResponseType) + 'static,
270 >(
271 this: *mut ffi::GtkNativeDialog,
272 response_id: ffi::GtkResponseType,
273 f: glib::ffi::gpointer,
274 ) {
275 let f: &F = &*(f as *const F);
276 f(
277 NativeDialog::from_glib_borrow(this).unsafe_cast_ref(),
278 from_glib(response_id),
279 )
280 }
281 unsafe {
282 let f: Box_<F> = Box_::new(f);
283 connect_raw(
284 self.as_ptr() as *mut _,
285 b"response\0".as_ptr() as *const _,
286 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
287 response_trampoline::<Self, F> as *const (),
288 )),
289 Box_::into_raw(f),
290 )
291 }
292 }
293
294 #[doc(alias = "modal")]
295 fn connect_modal_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
296 unsafe extern "C" fn notify_modal_trampoline<P: IsA<NativeDialog>, F: Fn(&P) + 'static>(
297 this: *mut ffi::GtkNativeDialog,
298 _param_spec: glib::ffi::gpointer,
299 f: glib::ffi::gpointer,
300 ) {
301 let f: &F = &*(f as *const F);
302 f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
303 }
304 unsafe {
305 let f: Box_<F> = Box_::new(f);
306 connect_raw(
307 self.as_ptr() as *mut _,
308 b"notify::modal\0".as_ptr() as *const _,
309 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
310 notify_modal_trampoline::<Self, F> as *const (),
311 )),
312 Box_::into_raw(f),
313 )
314 }
315 }
316
317 #[doc(alias = "title")]
318 fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
319 unsafe extern "C" fn notify_title_trampoline<P: IsA<NativeDialog>, F: Fn(&P) + 'static>(
320 this: *mut ffi::GtkNativeDialog,
321 _param_spec: glib::ffi::gpointer,
322 f: glib::ffi::gpointer,
323 ) {
324 let f: &F = &*(f as *const F);
325 f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
326 }
327 unsafe {
328 let f: Box_<F> = Box_::new(f);
329 connect_raw(
330 self.as_ptr() as *mut _,
331 b"notify::title\0".as_ptr() as *const _,
332 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
333 notify_title_trampoline::<Self, F> as *const (),
334 )),
335 Box_::into_raw(f),
336 )
337 }
338 }
339
340 #[doc(alias = "transient-for")]
341 fn connect_transient_for_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
342 unsafe extern "C" fn notify_transient_for_trampoline<
343 P: IsA<NativeDialog>,
344 F: Fn(&P) + 'static,
345 >(
346 this: *mut ffi::GtkNativeDialog,
347 _param_spec: glib::ffi::gpointer,
348 f: glib::ffi::gpointer,
349 ) {
350 let f: &F = &*(f as *const F);
351 f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
352 }
353 unsafe {
354 let f: Box_<F> = Box_::new(f);
355 connect_raw(
356 self.as_ptr() as *mut _,
357 b"notify::transient-for\0".as_ptr() as *const _,
358 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
359 notify_transient_for_trampoline::<Self, F> as *const (),
360 )),
361 Box_::into_raw(f),
362 )
363 }
364 }
365
366 #[doc(alias = "visible")]
367 fn connect_visible_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
368 unsafe extern "C" fn notify_visible_trampoline<
369 P: IsA<NativeDialog>,
370 F: Fn(&P) + 'static,
371 >(
372 this: *mut ffi::GtkNativeDialog,
373 _param_spec: glib::ffi::gpointer,
374 f: glib::ffi::gpointer,
375 ) {
376 let f: &F = &*(f as *const F);
377 f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
378 }
379 unsafe {
380 let f: Box_<F> = Box_::new(f);
381 connect_raw(
382 self.as_ptr() as *mut _,
383 b"notify::visible\0".as_ptr() as *const _,
384 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
385 notify_visible_trampoline::<Self, F> as *const (),
386 )),
387 Box_::into_raw(f),
388 )
389 }
390 }
391}
392
393impl<O: IsA<NativeDialog>> NativeDialogExt for O {}