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