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