Skip to main content

gtk/
message_dialog.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::ButtonsType;
4use crate::DialogFlags;
5use crate::MessageDialog;
6use crate::MessageType;
7use crate::Widget;
8use crate::Window;
9use glib::object::{Cast, IsA};
10use glib::translate::*;
11use libc::c_char;
12use std::ptr;
13
14impl MessageDialog {
15    /// Creates a new message dialog, which is a simple dialog with some text
16    /// the user may want to see. When the user clicks a button a “response”
17    /// signal is emitted with response IDs from [`ResponseType`][crate::ResponseType]. See
18    /// [`Dialog`][crate::Dialog] for more details.
19    /// ## `parent`
20    /// transient parent, or [`None`] for none
21    /// ## `flags`
22    /// flags
23    /// ## `type_`
24    /// type of message
25    /// ## `buttons`
26    /// set of buttons to use
27    /// ## `message_format`
28    /// `printf()`-style format string, or [`None`]
29    ///
30    /// # Returns
31    ///
32    /// a new [`MessageDialog`][crate::MessageDialog]
33    #[doc(alias = "gtk_message_dialog_new")]
34    pub fn new<T: IsA<Window>>(
35        parent: Option<&T>,
36        flags: DialogFlags,
37        type_: MessageType,
38        buttons: ButtonsType,
39        message: &str,
40    ) -> MessageDialog {
41        assert_initialized_main_thread!();
42        unsafe {
43            let message: Stash<*const c_char, _> = message.to_glib_none();
44            Widget::from_glib_none(ffi::gtk_message_dialog_new(
45                parent.map(|p| p.as_ref()).to_glib_none().0,
46                flags.into_glib(),
47                type_.into_glib(),
48                buttons.into_glib(),
49                b"%s\0".as_ptr() as *const c_char,
50                message.0,
51                ptr::null::<c_char>(),
52            ))
53            .unsafe_cast()
54        }
55    }
56}
57
58mod sealed {
59    pub trait Sealed {}
60    impl<T: glib::IsA<crate::MessageDialog>> Sealed for T {}
61}
62
63pub trait MessageDialogExt: IsA<MessageDialog> + sealed::Sealed + 'static {
64    #[doc(alias = "gtk_message_dialog_format_secondary_markup")]
65    fn set_secondary_markup(&self, message: Option<&str>) {
66        match message {
67            Some(m) => unsafe {
68                let message: Stash<*const c_char, _> = m.to_glib_none();
69                ffi::gtk_message_dialog_format_secondary_markup(
70                    self.as_ref().to_glib_none().0,
71                    b"%s\0".as_ptr() as *const c_char,
72                    message.0,
73                    ptr::null::<c_char>(),
74                )
75            },
76            None => unsafe {
77                ffi::gtk_message_dialog_format_secondary_markup(
78                    self.as_ref().to_glib_none().0,
79                    ptr::null::<c_char>(),
80                )
81            },
82        }
83    }
84
85    #[doc(alias = "gtk_message_dialog_format_secondary_text")]
86    fn set_secondary_text(&self, message: Option<&str>) {
87        match message {
88            Some(m) => unsafe {
89                let message: Stash<*const c_char, _> = m.to_glib_none();
90                ffi::gtk_message_dialog_format_secondary_text(
91                    self.as_ref().to_glib_none().0,
92                    b"%s\0".as_ptr() as *const c_char,
93                    message.0,
94                    ptr::null::<c_char>(),
95                )
96            },
97            None => unsafe {
98                ffi::gtk_message_dialog_format_secondary_text(
99                    self.as_ref().to_glib_none().0,
100                    ptr::null::<c_char>(),
101                )
102            },
103        }
104    }
105}
106
107impl<O: IsA<MessageDialog>> MessageDialogExt for O {}