1#![allow(deprecated)]
5
6#[cfg(feature = "v4_20")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
8use crate::WindowGravity;
9use crate::{
10 ffi, Accessible, AccessibleRole, Align, Application, Buildable, ButtonsType, ConstraintTarget,
11 Dialog, LayoutManager, MessageType, Native, Overflow, Root, ShortcutManager, Widget, Window,
12};
13use glib::{
14 prelude::*,
15 signal::{connect_raw, SignalHandlerId},
16 translate::*,
17};
18use std::boxed::Box as Box_;
19
20glib::wrapper! {
21 #[doc(alias = "GtkMessageDialog")]
22 pub struct MessageDialog(Object<ffi::GtkMessageDialog, ffi::GtkMessageDialogClass>) @extends Dialog, Window, Widget, @implements Accessible, Buildable, ConstraintTarget, Native, Root, ShortcutManager;
23
24 match fn {
25 type_ => || ffi::gtk_message_dialog_get_type(),
26 }
27}
28
29impl MessageDialog {
30 pub fn builder() -> MessageDialogBuilder {
35 MessageDialogBuilder::new()
36 }
37
38 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
39 #[allow(deprecated)]
40 #[doc(alias = "gtk_message_dialog_get_message_area")]
41 #[doc(alias = "get_message_area")]
42 #[doc(alias = "message-area")]
43 pub fn message_area(&self) -> Widget {
44 unsafe {
45 from_glib_none(ffi::gtk_message_dialog_get_message_area(
46 self.to_glib_none().0,
47 ))
48 }
49 }
50
51 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
52 #[allow(deprecated)]
53 #[doc(alias = "gtk_message_dialog_set_markup")]
54 pub fn set_markup(&self, str: &str) {
55 unsafe {
56 ffi::gtk_message_dialog_set_markup(self.to_glib_none().0, str.to_glib_none().0);
57 }
58 }
59
60 #[doc(alias = "message-type")]
61 pub fn message_type(&self) -> MessageType {
62 ObjectExt::property(self, "message-type")
63 }
64
65 #[doc(alias = "message-type")]
66 pub fn set_message_type(&self, message_type: MessageType) {
67 ObjectExt::set_property(self, "message-type", message_type)
68 }
69
70 #[doc(alias = "secondary-text")]
71 pub fn secondary_text(&self) -> Option<glib::GString> {
72 ObjectExt::property(self, "secondary-text")
73 }
74
75 #[doc(alias = "secondary-text")]
76 pub fn set_secondary_text(&self, secondary_text: Option<&str>) {
77 ObjectExt::set_property(self, "secondary-text", secondary_text)
78 }
79
80 #[doc(alias = "secondary-use-markup")]
81 pub fn is_secondary_use_markup(&self) -> bool {
82 ObjectExt::property(self, "secondary-use-markup")
83 }
84
85 #[doc(alias = "secondary-use-markup")]
86 pub fn set_secondary_use_markup(&self, secondary_use_markup: bool) {
87 ObjectExt::set_property(self, "secondary-use-markup", secondary_use_markup)
88 }
89
90 pub fn text(&self) -> Option<glib::GString> {
91 ObjectExt::property(self, "text")
92 }
93
94 pub fn set_text(&self, text: Option<&str>) {
95 ObjectExt::set_property(self, "text", text)
96 }
97
98 #[doc(alias = "use-markup")]
99 pub fn uses_markup(&self) -> bool {
100 ObjectExt::property(self, "use-markup")
101 }
102
103 #[doc(alias = "use-markup")]
104 pub fn set_use_markup(&self, use_markup: bool) {
105 ObjectExt::set_property(self, "use-markup", use_markup)
106 }
107
108 #[doc(alias = "message-area")]
109 pub fn connect_message_area_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
110 unsafe extern "C" fn notify_message_area_trampoline<F: Fn(&MessageDialog) + 'static>(
111 this: *mut ffi::GtkMessageDialog,
112 _param_spec: glib::ffi::gpointer,
113 f: glib::ffi::gpointer,
114 ) {
115 let f: &F = &*(f as *const F);
116 f(&from_glib_borrow(this))
117 }
118 unsafe {
119 let f: Box_<F> = Box_::new(f);
120 connect_raw(
121 self.as_ptr() as *mut _,
122 c"notify::message-area".as_ptr() as *const _,
123 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
124 notify_message_area_trampoline::<F> as *const (),
125 )),
126 Box_::into_raw(f),
127 )
128 }
129 }
130
131 #[doc(alias = "message-type")]
132 pub fn connect_message_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
133 unsafe extern "C" fn notify_message_type_trampoline<F: Fn(&MessageDialog) + 'static>(
134 this: *mut ffi::GtkMessageDialog,
135 _param_spec: glib::ffi::gpointer,
136 f: glib::ffi::gpointer,
137 ) {
138 let f: &F = &*(f as *const F);
139 f(&from_glib_borrow(this))
140 }
141 unsafe {
142 let f: Box_<F> = Box_::new(f);
143 connect_raw(
144 self.as_ptr() as *mut _,
145 c"notify::message-type".as_ptr() as *const _,
146 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
147 notify_message_type_trampoline::<F> as *const (),
148 )),
149 Box_::into_raw(f),
150 )
151 }
152 }
153
154 #[doc(alias = "secondary-text")]
155 pub fn connect_secondary_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
156 unsafe extern "C" fn notify_secondary_text_trampoline<F: Fn(&MessageDialog) + 'static>(
157 this: *mut ffi::GtkMessageDialog,
158 _param_spec: glib::ffi::gpointer,
159 f: glib::ffi::gpointer,
160 ) {
161 let f: &F = &*(f as *const F);
162 f(&from_glib_borrow(this))
163 }
164 unsafe {
165 let f: Box_<F> = Box_::new(f);
166 connect_raw(
167 self.as_ptr() as *mut _,
168 c"notify::secondary-text".as_ptr() as *const _,
169 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
170 notify_secondary_text_trampoline::<F> as *const (),
171 )),
172 Box_::into_raw(f),
173 )
174 }
175 }
176
177 #[doc(alias = "secondary-use-markup")]
178 pub fn connect_secondary_use_markup_notify<F: Fn(&Self) + 'static>(
179 &self,
180 f: F,
181 ) -> SignalHandlerId {
182 unsafe extern "C" fn notify_secondary_use_markup_trampoline<
183 F: Fn(&MessageDialog) + 'static,
184 >(
185 this: *mut ffi::GtkMessageDialog,
186 _param_spec: glib::ffi::gpointer,
187 f: glib::ffi::gpointer,
188 ) {
189 let f: &F = &*(f as *const F);
190 f(&from_glib_borrow(this))
191 }
192 unsafe {
193 let f: Box_<F> = Box_::new(f);
194 connect_raw(
195 self.as_ptr() as *mut _,
196 c"notify::secondary-use-markup".as_ptr() as *const _,
197 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
198 notify_secondary_use_markup_trampoline::<F> as *const (),
199 )),
200 Box_::into_raw(f),
201 )
202 }
203 }
204
205 #[doc(alias = "text")]
206 pub fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
207 unsafe extern "C" fn notify_text_trampoline<F: Fn(&MessageDialog) + 'static>(
208 this: *mut ffi::GtkMessageDialog,
209 _param_spec: glib::ffi::gpointer,
210 f: glib::ffi::gpointer,
211 ) {
212 let f: &F = &*(f as *const F);
213 f(&from_glib_borrow(this))
214 }
215 unsafe {
216 let f: Box_<F> = Box_::new(f);
217 connect_raw(
218 self.as_ptr() as *mut _,
219 c"notify::text".as_ptr() as *const _,
220 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
221 notify_text_trampoline::<F> as *const (),
222 )),
223 Box_::into_raw(f),
224 )
225 }
226 }
227
228 #[doc(alias = "use-markup")]
229 pub fn connect_use_markup_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
230 unsafe extern "C" fn notify_use_markup_trampoline<F: Fn(&MessageDialog) + 'static>(
231 this: *mut ffi::GtkMessageDialog,
232 _param_spec: glib::ffi::gpointer,
233 f: glib::ffi::gpointer,
234 ) {
235 let f: &F = &*(f as *const F);
236 f(&from_glib_borrow(this))
237 }
238 unsafe {
239 let f: Box_<F> = Box_::new(f);
240 connect_raw(
241 self.as_ptr() as *mut _,
242 c"notify::use-markup".as_ptr() as *const _,
243 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
244 notify_use_markup_trampoline::<F> as *const (),
245 )),
246 Box_::into_raw(f),
247 )
248 }
249 }
250}
251
252#[must_use = "The builder must be built to be used"]
257pub struct MessageDialogBuilder {
258 builder: glib::object::ObjectBuilder<'static, MessageDialog>,
259}
260
261impl MessageDialogBuilder {
262 fn new() -> Self {
263 Self {
264 builder: glib::object::Object::builder(),
265 }
266 }
267
268 pub fn buttons(self, buttons: ButtonsType) -> Self {
269 Self {
270 builder: self.builder.property("buttons", buttons),
271 }
272 }
273
274 pub fn message_type(self, message_type: MessageType) -> Self {
275 Self {
276 builder: self.builder.property("message-type", message_type),
277 }
278 }
279
280 pub fn secondary_text(self, secondary_text: impl Into<glib::GString>) -> Self {
281 Self {
282 builder: self
283 .builder
284 .property("secondary-text", secondary_text.into()),
285 }
286 }
287
288 pub fn secondary_use_markup(self, secondary_use_markup: bool) -> Self {
289 Self {
290 builder: self
291 .builder
292 .property("secondary-use-markup", secondary_use_markup),
293 }
294 }
295
296 pub fn text(self, text: impl Into<glib::GString>) -> Self {
297 Self {
298 builder: self.builder.property("text", text.into()),
299 }
300 }
301
302 pub fn use_markup(self, use_markup: bool) -> Self {
303 Self {
304 builder: self.builder.property("use-markup", use_markup),
305 }
306 }
307
308 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
309 pub fn use_header_bar(self, use_header_bar: i32) -> Self {
310 Self {
311 builder: self.builder.property("use-header-bar", use_header_bar),
312 }
313 }
314
315 pub fn application(self, application: &impl IsA<Application>) -> Self {
316 Self {
317 builder: self
318 .builder
319 .property("application", application.clone().upcast()),
320 }
321 }
322
323 pub fn child(self, child: &impl IsA<Widget>) -> Self {
324 Self {
325 builder: self.builder.property("child", child.clone().upcast()),
326 }
327 }
328
329 pub fn decorated(self, decorated: bool) -> Self {
330 Self {
331 builder: self.builder.property("decorated", decorated),
332 }
333 }
334
335 pub fn default_height(self, default_height: i32) -> Self {
336 Self {
337 builder: self.builder.property("default-height", default_height),
338 }
339 }
340
341 pub fn default_widget(self, default_widget: &impl IsA<Widget>) -> Self {
342 Self {
343 builder: self
344 .builder
345 .property("default-widget", default_widget.clone().upcast()),
346 }
347 }
348
349 pub fn default_width(self, default_width: i32) -> Self {
350 Self {
351 builder: self.builder.property("default-width", default_width),
352 }
353 }
354
355 pub fn deletable(self, deletable: bool) -> Self {
356 Self {
357 builder: self.builder.property("deletable", deletable),
358 }
359 }
360
361 pub fn destroy_with_parent(self, destroy_with_parent: bool) -> Self {
362 Self {
363 builder: self
364 .builder
365 .property("destroy-with-parent", destroy_with_parent),
366 }
367 }
368
369 pub fn display(self, display: &impl IsA<gdk::Display>) -> Self {
370 Self {
371 builder: self.builder.property("display", display.clone().upcast()),
372 }
373 }
374
375 pub fn focus_visible(self, focus_visible: bool) -> Self {
376 Self {
377 builder: self.builder.property("focus-visible", focus_visible),
378 }
379 }
380
381 pub fn focus_widget(self, focus_widget: &impl IsA<Widget>) -> Self {
382 Self {
383 builder: self
384 .builder
385 .property("focus-widget", focus_widget.clone().upcast()),
386 }
387 }
388
389 pub fn fullscreened(self, fullscreened: bool) -> Self {
390 Self {
391 builder: self.builder.property("fullscreened", fullscreened),
392 }
393 }
394
395 #[cfg(feature = "v4_20")]
396 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
397 pub fn gravity(self, gravity: WindowGravity) -> Self {
398 Self {
399 builder: self.builder.property("gravity", gravity),
400 }
401 }
402
403 #[cfg(feature = "v4_2")]
404 #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
405 pub fn handle_menubar_accel(self, handle_menubar_accel: bool) -> Self {
406 Self {
407 builder: self
408 .builder
409 .property("handle-menubar-accel", handle_menubar_accel),
410 }
411 }
412
413 pub fn hide_on_close(self, hide_on_close: bool) -> Self {
414 Self {
415 builder: self.builder.property("hide-on-close", hide_on_close),
416 }
417 }
418
419 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
420 Self {
421 builder: self.builder.property("icon-name", icon_name.into()),
422 }
423 }
424
425 pub fn maximized(self, maximized: bool) -> Self {
426 Self {
427 builder: self.builder.property("maximized", maximized),
428 }
429 }
430
431 pub fn mnemonics_visible(self, mnemonics_visible: bool) -> Self {
432 Self {
433 builder: self
434 .builder
435 .property("mnemonics-visible", mnemonics_visible),
436 }
437 }
438
439 pub fn modal(self, modal: bool) -> Self {
440 Self {
441 builder: self.builder.property("modal", modal),
442 }
443 }
444
445 pub fn resizable(self, resizable: bool) -> Self {
446 Self {
447 builder: self.builder.property("resizable", resizable),
448 }
449 }
450
451 pub fn startup_id(self, startup_id: impl Into<glib::GString>) -> Self {
452 Self {
453 builder: self.builder.property("startup-id", startup_id.into()),
454 }
455 }
456
457 pub fn title(self, title: impl Into<glib::GString>) -> Self {
458 Self {
459 builder: self.builder.property("title", title.into()),
460 }
461 }
462
463 #[cfg(feature = "v4_6")]
464 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
465 pub fn titlebar(self, titlebar: &impl IsA<Widget>) -> Self {
466 Self {
467 builder: self.builder.property("titlebar", titlebar.clone().upcast()),
468 }
469 }
470
471 pub fn transient_for(self, transient_for: &impl IsA<Window>) -> Self {
472 Self {
473 builder: self
474 .builder
475 .property("transient-for", transient_for.clone().upcast()),
476 }
477 }
478
479 pub fn can_focus(self, can_focus: bool) -> Self {
480 Self {
481 builder: self.builder.property("can-focus", can_focus),
482 }
483 }
484
485 pub fn can_target(self, can_target: bool) -> Self {
486 Self {
487 builder: self.builder.property("can-target", can_target),
488 }
489 }
490
491 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
492 Self {
493 builder: self.builder.property("css-classes", css_classes.into()),
494 }
495 }
496
497 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
498 Self {
499 builder: self.builder.property("css-name", css_name.into()),
500 }
501 }
502
503 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
504 Self {
505 builder: self.builder.property("cursor", cursor.clone()),
506 }
507 }
508
509 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
510 Self {
511 builder: self.builder.property("focus-on-click", focus_on_click),
512 }
513 }
514
515 pub fn focusable(self, focusable: bool) -> Self {
516 Self {
517 builder: self.builder.property("focusable", focusable),
518 }
519 }
520
521 pub fn halign(self, halign: Align) -> Self {
522 Self {
523 builder: self.builder.property("halign", halign),
524 }
525 }
526
527 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
528 Self {
529 builder: self.builder.property("has-tooltip", has_tooltip),
530 }
531 }
532
533 pub fn height_request(self, height_request: i32) -> Self {
534 Self {
535 builder: self.builder.property("height-request", height_request),
536 }
537 }
538
539 pub fn hexpand(self, hexpand: bool) -> Self {
540 Self {
541 builder: self.builder.property("hexpand", hexpand),
542 }
543 }
544
545 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
546 Self {
547 builder: self.builder.property("hexpand-set", hexpand_set),
548 }
549 }
550
551 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
552 Self {
553 builder: self
554 .builder
555 .property("layout-manager", layout_manager.clone().upcast()),
556 }
557 }
558
559 #[cfg(feature = "v4_18")]
560 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
561 pub fn limit_events(self, limit_events: bool) -> Self {
562 Self {
563 builder: self.builder.property("limit-events", limit_events),
564 }
565 }
566
567 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
568 Self {
569 builder: self.builder.property("margin-bottom", margin_bottom),
570 }
571 }
572
573 pub fn margin_end(self, margin_end: i32) -> Self {
574 Self {
575 builder: self.builder.property("margin-end", margin_end),
576 }
577 }
578
579 pub fn margin_start(self, margin_start: i32) -> Self {
580 Self {
581 builder: self.builder.property("margin-start", margin_start),
582 }
583 }
584
585 pub fn margin_top(self, margin_top: i32) -> Self {
586 Self {
587 builder: self.builder.property("margin-top", margin_top),
588 }
589 }
590
591 pub fn name(self, name: impl Into<glib::GString>) -> Self {
592 Self {
593 builder: self.builder.property("name", name.into()),
594 }
595 }
596
597 pub fn opacity(self, opacity: f64) -> Self {
598 Self {
599 builder: self.builder.property("opacity", opacity),
600 }
601 }
602
603 pub fn overflow(self, overflow: Overflow) -> Self {
604 Self {
605 builder: self.builder.property("overflow", overflow),
606 }
607 }
608
609 pub fn receives_default(self, receives_default: bool) -> Self {
610 Self {
611 builder: self.builder.property("receives-default", receives_default),
612 }
613 }
614
615 pub fn sensitive(self, sensitive: bool) -> Self {
616 Self {
617 builder: self.builder.property("sensitive", sensitive),
618 }
619 }
620
621 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
622 Self {
623 builder: self
624 .builder
625 .property("tooltip-markup", tooltip_markup.into()),
626 }
627 }
628
629 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
630 Self {
631 builder: self.builder.property("tooltip-text", tooltip_text.into()),
632 }
633 }
634
635 pub fn valign(self, valign: Align) -> Self {
636 Self {
637 builder: self.builder.property("valign", valign),
638 }
639 }
640
641 pub fn vexpand(self, vexpand: bool) -> Self {
642 Self {
643 builder: self.builder.property("vexpand", vexpand),
644 }
645 }
646
647 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
648 Self {
649 builder: self.builder.property("vexpand-set", vexpand_set),
650 }
651 }
652
653 pub fn visible(self, visible: bool) -> Self {
654 Self {
655 builder: self.builder.property("visible", visible),
656 }
657 }
658
659 pub fn width_request(self, width_request: i32) -> Self {
660 Self {
661 builder: self.builder.property("width-request", width_request),
662 }
663 }
664
665 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
666 Self {
667 builder: self.builder.property("accessible-role", accessible_role),
668 }
669 }
670
671 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
674 pub fn build(self) -> MessageDialog {
675 assert_initialized_main_thread!();
676 self.builder.build()
677 }
678}