1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::object::{Cast, IsA};
use glib::translate::*;
use libc::c_char;
use std::ptr;

use crate::{ButtonsType, DialogFlags, MessageDialog, MessageType, Widget, Window};

impl MessageDialog {
    /// Creates a new message dialog.
    ///
    /// This is a simple dialog with some text the user may want to see.
    /// When the user clicks a button a “response” signal is emitted with
    /// response IDs from [`ResponseType`][crate::ResponseType]. See [`Dialog`][crate::Dialog]
    /// for more details.
    /// ## `parent`
    /// transient parent
    /// ## `flags`
    /// flags
    /// ## `type_`
    /// type of message
    /// ## `buttons`
    /// set of buttons to use
    /// ## `message_format`
    /// printf()-style format string
    ///
    /// # Returns
    ///
    /// a new [`MessageDialog`][crate::MessageDialog]
    #[doc(alias = "gtk_message_dialog_new")]
    pub fn new(
        parent: Option<&impl IsA<Window>>,
        flags: DialogFlags,
        type_: MessageType,
        buttons: ButtonsType,
        message: &str,
    ) -> Self {
        assert_initialized_main_thread!();
        unsafe {
            let message: Stash<*const c_char, _> = message.to_glib_none();
            Widget::from_glib_none(ffi::gtk_message_dialog_new(
                parent.map(|p| p.as_ref()).to_glib_none().0,
                flags.into_glib(),
                type_.into_glib(),
                buttons.into_glib(),
                b"%s\0".as_ptr() as *const c_char,
                message.0,
                ptr::null::<c_char>(),
            ))
            .unsafe_cast()
        }
    }

    /// Creates a new message dialog.
    ///
    /// This is a simple dialog with some text that is marked up with
    /// Pango markup. When the user clicks a button a “response” signal
    /// is emitted with response IDs from [`ResponseType`][crate::ResponseType]. See
    /// [`Dialog`][crate::Dialog] for more details.
    ///
    /// Special XML characters in the printf() arguments passed to this
    /// function will automatically be escaped as necessary.
    /// (See g_markup_printf_escaped() for how this is implemented.)
    /// Usually this is what you want, but if you have an existing
    /// Pango markup string that you want to use literally as the
    /// label, then you need to use [`set_markup()`][Self::set_markup()]
    /// instead, since you can’t pass the markup string either
    /// as the format (it might contain “%” characters) or as a string
    /// argument.
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// GtkWidget *dialog;
    /// GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
    /// dialog = gtk_message_dialog_new (parent_window,
    ///                                  flags,
    ///                                  GTK_MESSAGE_ERROR,
    ///                                  GTK_BUTTONS_CLOSE,
    ///                                  NULL);
    /// gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
    ///                                markup);
    /// ```
    /// ## `parent`
    /// transient parent
    /// ## `flags`
    /// flags
    /// ## `type_`
    /// type of message
    /// ## `buttons`
    /// set of buttons to use
    /// ## `message_format`
    /// printf()-style format string
    ///
    /// # Returns
    ///
    /// a new [`MessageDialog`][crate::MessageDialog]
    #[doc(alias = "gtk_message_dialog_new_with_markup")]
    #[doc(alias = "new_with_markup")]
    pub fn with_markup(
        parent: Option<&impl IsA<Window>>,
        flags: DialogFlags,
        type_: MessageType,
        buttons: ButtonsType,
        message: Option<&str>,
    ) -> Self {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_message_dialog_new_with_markup(
                parent.map(|p| p.as_ref()).to_glib_none().0,
                flags.into_glib(),
                type_.into_glib(),
                buttons.into_glib(),
                message.to_glib_none().0,
            ))
            .unsafe_cast()
        }
    }

    /// Sets the secondary text of the message dialog.
    ///
    /// The @message_format is assumed to contain Pango markup.
    ///
    /// Due to an oversight, this function does not escape special
    /// XML characters like [`with_markup()`][Self::with_markup()]
    /// does. Thus, if the arguments may contain special XML characters,
    /// you should use g_markup_printf_escaped() to escape it.
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// char *msg;
    ///
    /// msg = g_markup_printf_escaped (message_format, ...);
    /// gtk_message_dialog_format_secondary_markup (message_dialog,
    ///                                             "%s", msg);
    /// g_free (msg);
    /// ```
    /// ## `message_format`
    /// printf()-style string with Pango markup
    #[doc(alias = "gtk_message_dialog_format_secondary_markup")]
    pub fn format_secondary_markup(&self, message: Option<&str>) {
        unsafe {
            ffi::gtk_message_dialog_format_secondary_markup(
                self.to_glib_none().0,
                message.to_glib_none().0,
            )
        }
    }

    /// Sets the secondary text of the message dialog.
    /// ## `message_format`
    /// printf()-style format string
    #[doc(alias = "gtk_message_dialog_format_secondary_text")]
    pub fn format_secondary_text(&self, message: Option<&str>) {
        unsafe {
            ffi::gtk_message_dialog_format_secondary_text(
                self.to_glib_none().0,
                message.to_glib_none().0,
            )
        }
    }
}

impl Default for MessageDialog {
    fn default() -> Self {
        glib::object::Object::new::<Self>(&[])
            .expect("Can't construct MessageDialog object with default parameters")
    }
}