Skip to main content

gtk4/
message_dialog.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::ptr;
4
5use glib::translate::*;
6
7use crate::{
8    ButtonsType, DialogFlags, MessageDialog, MessageType, Widget, Window, ffi, prelude::*,
9};
10
11impl MessageDialog {
12    ///  signal is emitted with
13    /// response IDs from [`ResponseType`][crate::ResponseType]. See [`Dialog`][crate::Dialog]
14    /// for more details.
15    ///
16    /// # Deprecated since 4.10
17    ///
18    /// Use [`AlertDialog`][crate::AlertDialog] instead
19    /// ## `parent`
20    /// transient parent
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
29    ///
30    /// # Returns
31    ///
32    /// a new [`MessageDialog`][crate::MessageDialog]
33    #[doc(alias = "gtk_message_dialog_new")]
34    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
35    #[allow(deprecated)]
36    pub fn new(
37        parent: Option<&impl IsA<Window>>,
38        flags: DialogFlags,
39        type_: MessageType,
40        buttons: ButtonsType,
41        message: impl IntoGStr,
42    ) -> Self {
43        assert_initialized_main_thread!();
44        unsafe {
45            message.run_with_gstr(|message| {
46                Widget::from_glib_none(ffi::gtk_message_dialog_new(
47                    parent.map(|p| p.as_ref()).to_glib_none().0,
48                    flags.into_glib(),
49                    type_.into_glib(),
50                    buttons.into_glib(),
51                    c"%s".as_ptr() as *const libc::c_char,
52                    message.as_ptr(),
53                    ptr::null::<libc::c_char>(),
54                ))
55                .unsafe_cast()
56            })
57        }
58    }
59
60    ///  characters) or as a string
61    /// argument.
62    ///
63    /// **⚠️ The following code is in c ⚠️**
64    ///
65    /// ```c
66    /// GtkWidget *dialog;
67    /// GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
68    /// dialog = gtk_message_dialog_new (parent_window,
69    ///                                  flags,
70    ///                                  GTK_MESSAGE_ERROR,
71    ///                                  GTK_BUTTONS_CLOSE,
72    ///                                  NULL);
73    /// gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
74    ///                                markup);
75    /// ```
76    ///
77    /// # Deprecated since 4.10
78    ///
79    /// Use [`AlertDialog`][crate::AlertDialog] instead
80    /// ## `parent`
81    /// transient parent
82    /// ## `flags`
83    /// flags
84    /// ## `type_`
85    /// type of message
86    /// ## `buttons`
87    /// set of buttons to use
88    /// ## `message_format`
89    /// printf()-style format string
90    ///
91    /// # Returns
92    ///
93    /// a new [`MessageDialog`][crate::MessageDialog]
94    #[doc(alias = "gtk_message_dialog_new_with_markup")]
95    #[doc(alias = "new_with_markup")]
96    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
97    #[allow(deprecated)]
98    pub fn with_markup(
99        parent: Option<&impl IsA<Window>>,
100        flags: DialogFlags,
101        type_: MessageType,
102        buttons: ButtonsType,
103        message: impl IntoOptionalGStr,
104    ) -> Self {
105        assert_initialized_main_thread!();
106        unsafe {
107            message.run_with_gstr(|message| {
108                Widget::from_glib_none(ffi::gtk_message_dialog_new_with_markup(
109                    parent.map(|p| p.as_ref()).to_glib_none().0,
110                    flags.into_glib(),
111                    type_.into_glib(),
112                    buttons.into_glib(),
113                    message.to_glib_none().0,
114                ))
115                .unsafe_cast()
116            })
117        }
118    }
119
120    /// Sets the secondary text of the message dialog.
121    ///
122    /// The @message_format is assumed to contain Pango markup.
123    ///
124    /// Due to an oversight, this function does not escape special
125    /// XML characters like [`with_markup()`][Self::with_markup()]
126    /// does. Thus, if the arguments may contain special XML characters,
127    /// you should use g_markup_printf_escaped() to escape it.
128    ///
129    /// **⚠️ The following code is in c ⚠️**
130    ///
131    /// ```c
132    /// char *msg;
133    ///
134    /// msg = g_markup_printf_escaped (message_format, ...);
135    /// gtk_message_dialog_format_secondary_markup (message_dialog,
136    ///                                             "%s", msg);
137    /// g_free (msg);
138    /// ```
139    ///
140    /// # Deprecated since 4.10
141    ///
142    /// Use [`AlertDialog`][crate::AlertDialog] instead
143    /// ## `message_format`
144    /// printf()-style string with Pango markup
145    #[doc(alias = "gtk_message_dialog_format_secondary_markup")]
146    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
147    #[allow(deprecated)]
148    pub fn format_secondary_markup(&self, message: impl IntoOptionalGStr) {
149        unsafe {
150            message.run_with_gstr(|message| {
151                ffi::gtk_message_dialog_format_secondary_markup(
152                    self.to_glib_none().0,
153                    message.to_glib_none().0,
154                )
155            })
156        }
157    }
158
159    /// Sets the secondary text of the message dialog.
160    ///
161    /// # Deprecated since 4.10
162    ///
163    /// Use [`AlertDialog`][crate::AlertDialog] instead
164    /// ## `message_format`
165    /// printf()-style format string
166    #[doc(alias = "gtk_message_dialog_format_secondary_text")]
167    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
168    #[allow(deprecated)]
169    pub fn format_secondary_text(&self, message: impl IntoOptionalGStr) {
170        unsafe {
171            message.run_with_gstr(|message| {
172                ffi::gtk_message_dialog_format_secondary_text(
173                    self.to_glib_none().0,
174                    message.to_glib_none().0,
175                )
176            })
177        }
178    }
179}
180
181impl Default for MessageDialog {
182    fn default() -> Self {
183        glib::Object::new()
184    }
185}