1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 2000 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 * Modified by the GTK+ Team and others 1997-2003. See the AUTHORS
21 * file for a list of people on the GTK+ Team. See the ChangeLog
22 * files for a list of changes. These files are distributed with
23 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gtkmessagedialog.h"
31 #include "gtkaccessible.h"
32 #include "gtkbuildable.h"
37 #include "gtkiconfactory.h"
39 #include "gtkprivate.h"
40 #include "gtktypebuiltins.h"
43 * SECTION:gtkmessagedialog
44 * @Short_description: A convenient message window
45 * @Title: GtkMessageDialog
46 * @See_also:#GtkDialog
48 * #GtkMessageDialog presents a dialog with an image representing the type of
49 * message (Error, Question, etc.) alongside some message text. It's simply a
50 * convenience widget; you could construct the equivalent of #GtkMessageDialog
51 * from #GtkDialog without too much effort, but #GtkMessageDialog saves typing.
53 * The easiest way to do a modal message dialog is to use gtk_dialog_run(), though
54 * you can also pass in the %GTK_DIALOG_MODAL flag, gtk_dialog_run() automatically
55 * makes the dialog modal and waits for the user to respond to it. gtk_dialog_run()
56 * returns when any dialog button is clicked.
58 * <title>A modal dialog.</title>
60 * dialog = gtk_message_dialog_new (main_application_window,
61 * GTK_DIALOG_DESTROY_WITH_PARENT,
64 * "Error loading file '%s': %s",
65 * filename, g_strerror (errno));
66 * gtk_dialog_run (GTK_DIALOG (dialog));
67 * gtk_widget_destroy (dialog);
70 * You might do a non-modal #GtkMessageDialog as follows:
72 * <title>A non-modal dialog.</title>
74 * dialog = gtk_message_dialog_new (main_application_window,
75 * GTK_DIALOG_DESTROY_WITH_PARENT,
78 * "Error loading file '%s': %s",
79 * filename, g_strerror (errno));
81 * /* Destroy the dialog when the user responds to it (e.g. clicks a button) */
82 * g_signal_connect_swapped (dialog, "response",
83 * G_CALLBACK (gtk_widget_destroy),
88 * <refsect2 id="GtkMessageDialog-BUILDER-UI">
89 * <title>GtkMessageDialog as GtkBuildable</title>
91 * The GtkMessageDialog implementation of the GtkBuildable interface exposes
92 * the message area as an internal child with the name "message_area".
97 struct _GtkMessageDialogPrivate
101 GtkWidget *message_area; /* vbox for the primary and secondary labels, and any extra content from the caller */
102 GtkWidget *secondary_label;
104 guint has_primary_markup : 1;
105 guint has_secondary_text : 1;
106 guint message_type : 3;
109 static void gtk_message_dialog_style_updated (GtkWidget *widget);
111 static void gtk_message_dialog_set_property (GObject *object,
115 static void gtk_message_dialog_get_property (GObject *object,
119 static void gtk_message_dialog_add_buttons (GtkMessageDialog *message_dialog,
120 GtkButtonsType buttons);
121 static void gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface);
122 static GObject * gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
124 const gchar *childname);
134 PROP_SECONDARY_USE_MARKUP,
139 G_DEFINE_TYPE_WITH_CODE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG,
140 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
141 gtk_message_dialog_buildable_interface_init))
143 static GtkBuildableIface *parent_buildable_iface;
146 gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface)
148 parent_buildable_iface = g_type_interface_peek_parent (iface);
149 iface->get_internal_child = gtk_message_dialog_buildable_get_internal_child;
150 iface->custom_tag_start = parent_buildable_iface->custom_tag_start;
151 iface->custom_finished = parent_buildable_iface->custom_finished;
155 gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
157 const gchar *childname)
159 if (strcmp (childname, "message_area") == 0)
160 return G_OBJECT (gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (buildable)));
162 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
167 gtk_message_dialog_class_init (GtkMessageDialogClass *class)
169 GtkWidgetClass *widget_class;
170 GObjectClass *gobject_class;
172 widget_class = GTK_WIDGET_CLASS (class);
173 gobject_class = G_OBJECT_CLASS (class);
175 widget_class->style_updated = gtk_message_dialog_style_updated;
177 gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_ALERT);
179 gobject_class->set_property = gtk_message_dialog_set_property;
180 gobject_class->get_property = gtk_message_dialog_get_property;
182 gtk_widget_class_install_style_property (widget_class,
183 g_param_spec_int ("message-border",
184 P_("Image/label border"),
185 P_("Width of border around the label and image in the message dialog"),
189 GTK_PARAM_READABLE));
192 * GtkMessageDialog:message-type:
194 * The type of the message. The type is used to determine
195 * the image that is shown in the dialog, unless the image is
196 * explicitly set by the ::image property.
198 g_object_class_install_property (gobject_class,
200 g_param_spec_enum ("message-type",
202 P_("The type of message"),
203 GTK_TYPE_MESSAGE_TYPE,
205 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
206 g_object_class_install_property (gobject_class,
208 g_param_spec_enum ("buttons",
209 P_("Message Buttons"),
210 P_("The buttons shown in the message dialog"),
211 GTK_TYPE_BUTTONS_TYPE,
213 GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
216 * GtkMessageDialog:text:
218 * The primary text of the message dialog. If the dialog has
219 * a secondary text, this will appear as the title.
223 g_object_class_install_property (gobject_class,
225 g_param_spec_string ("text",
227 P_("The primary text of the message dialog"),
229 GTK_PARAM_READWRITE));
232 * GtkMessageDialog:use-markup:
234 * %TRUE if the primary text of the dialog includes Pango markup.
235 * See pango_parse_markup().
239 g_object_class_install_property (gobject_class,
241 g_param_spec_boolean ("use-markup",
243 P_("The primary text of the title includes Pango markup."),
245 GTK_PARAM_READWRITE));
248 * GtkMessageDialog:secondary-text:
250 * The secondary text of the message dialog.
254 g_object_class_install_property (gobject_class,
256 g_param_spec_string ("secondary-text",
257 P_("Secondary Text"),
258 P_("The secondary text of the message dialog"),
260 GTK_PARAM_READWRITE));
263 * GtkMessageDialog:secondary-use-markup:
265 * %TRUE if the secondary text of the dialog includes Pango markup.
266 * See pango_parse_markup().
270 g_object_class_install_property (gobject_class,
271 PROP_SECONDARY_USE_MARKUP,
272 g_param_spec_boolean ("secondary-use-markup",
273 P_("Use Markup in secondary"),
274 P_("The secondary text includes Pango markup."),
276 GTK_PARAM_READWRITE));
279 * GtkMessageDialog:image:
281 * The image for this dialog.
285 g_object_class_install_property (gobject_class,
287 g_param_spec_object ("image",
291 GTK_PARAM_READWRITE));
294 * GtkMessageDialog:message-area
296 * The #GtkVBox that corresponds to the message area of this dialog. See
297 * gtk_message_dialog_get_message_area() for a detailed description of this
302 g_object_class_install_property (gobject_class,
304 g_param_spec_object ("message-area",
306 P_("GtkVBox that holds the dialog's primary and secondary labels"),
308 GTK_PARAM_READABLE));
310 g_type_class_add_private (gobject_class, sizeof (GtkMessageDialogPrivate));
314 gtk_message_dialog_init (GtkMessageDialog *dialog)
317 GtkDialog *message_dialog = GTK_DIALOG (dialog);
318 GtkWidget *action_area, *content_area;
319 GtkMessageDialogPrivate *priv;
321 dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
322 GTK_TYPE_MESSAGE_DIALOG,
323 GtkMessageDialogPrivate);
326 content_area = gtk_dialog_get_content_area (message_dialog);
327 action_area = gtk_dialog_get_action_area (message_dialog);
329 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
330 gtk_window_set_title (GTK_WINDOW (dialog), "");
331 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
333 priv->has_primary_markup = FALSE;
334 priv->has_secondary_text = FALSE;
335 priv->secondary_label = gtk_label_new (NULL);
336 gtk_widget_set_no_show_all (priv->secondary_label, TRUE);
338 priv->label = gtk_label_new (NULL);
339 priv->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
340 gtk_widget_set_halign (priv->image, GTK_ALIGN_CENTER);
341 gtk_widget_set_valign (priv->image, GTK_ALIGN_START);
343 gtk_label_set_line_wrap (GTK_LABEL (priv->label), TRUE);
344 gtk_label_set_selectable (GTK_LABEL (priv->label), TRUE);
345 gtk_widget_set_halign (priv->label, GTK_ALIGN_START);
346 gtk_widget_set_valign (priv->label, GTK_ALIGN_START);
348 gtk_label_set_line_wrap (GTK_LABEL (priv->secondary_label), TRUE);
349 gtk_label_set_selectable (GTK_LABEL (priv->secondary_label), TRUE);
350 gtk_widget_set_halign (priv->secondary_label, GTK_ALIGN_START);
351 gtk_widget_set_valign (priv->secondary_label, GTK_ALIGN_START);
353 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
354 priv->message_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
356 gtk_box_pack_start (GTK_BOX (priv->message_area), priv->label,
359 gtk_box_pack_start (GTK_BOX (priv->message_area), priv->secondary_label,
362 gtk_box_pack_start (GTK_BOX (hbox), priv->image,
365 gtk_box_pack_start (GTK_BOX (hbox), priv->message_area,
368 gtk_box_pack_start (GTK_BOX (content_area),
372 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
373 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
374 gtk_box_set_spacing (GTK_BOX (content_area), 14); /* 14 + 2 * 5 = 24 */
375 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
376 gtk_box_set_spacing (GTK_BOX (action_area), 6);
378 gtk_message_dialog_style_updated (GTK_WIDGET (dialog));
380 gtk_widget_show_all (hbox);
384 setup_primary_label_font (GtkMessageDialog *dialog)
386 GtkMessageDialogPrivate *priv = dialog->priv;
388 PangoFontDescription *font_desc;
389 GtkStyleContext *context;
392 /* unset the font settings */
393 gtk_widget_override_font (priv->label, NULL);
395 if (priv->has_secondary_text && !priv->has_primary_markup)
397 context = gtk_widget_get_style_context (priv->label);
398 state = gtk_widget_get_state_flags (priv->label);
400 size = pango_font_description_get_size (gtk_style_context_get_font (context, state));
401 font_desc = pango_font_description_new ();
402 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
403 pango_font_description_set_size (font_desc, size * PANGO_SCALE_LARGE);
404 gtk_widget_override_font (priv->label, font_desc);
405 pango_font_description_free (font_desc);
410 setup_type (GtkMessageDialog *dialog,
413 GtkMessageDialogPrivate *priv = dialog->priv;
414 const gchar *stock_id = NULL;
417 priv->message_type = type;
421 case GTK_MESSAGE_INFO:
422 stock_id = GTK_STOCK_DIALOG_INFO;
425 case GTK_MESSAGE_QUESTION:
426 stock_id = GTK_STOCK_DIALOG_QUESTION;
429 case GTK_MESSAGE_WARNING:
430 stock_id = GTK_STOCK_DIALOG_WARNING;
433 case GTK_MESSAGE_ERROR:
434 stock_id = GTK_STOCK_DIALOG_ERROR;
437 case GTK_MESSAGE_OTHER:
441 g_warning ("Unknown GtkMessageType %u", type);
446 gtk_image_set_from_stock (GTK_IMAGE (priv->image), stock_id,
447 GTK_ICON_SIZE_DIALOG);
449 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (dialog));
450 if (GTK_IS_ACCESSIBLE (atk_obj))
452 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
457 gtk_stock_lookup (stock_id, &item);
458 atk_object_set_name (atk_obj, item.label);
464 gtk_message_dialog_set_property (GObject *object,
469 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
470 GtkMessageDialogPrivate *priv = dialog->priv;
474 case PROP_MESSAGE_TYPE:
475 setup_type (dialog, g_value_get_enum (value));
478 gtk_message_dialog_add_buttons (dialog, g_value_get_enum (value));
481 if (priv->has_primary_markup)
482 gtk_label_set_markup (GTK_LABEL (priv->label),
483 g_value_get_string (value));
485 gtk_label_set_text (GTK_LABEL (priv->label),
486 g_value_get_string (value));
488 case PROP_USE_MARKUP:
489 priv->has_primary_markup = g_value_get_boolean (value) != FALSE;
490 gtk_label_set_use_markup (GTK_LABEL (priv->label),
491 priv->has_primary_markup);
492 setup_primary_label_font (dialog);
494 case PROP_SECONDARY_TEXT:
496 const gchar *txt = g_value_get_string (value);
498 if (gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)))
499 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), txt);
501 gtk_label_set_text (GTK_LABEL (priv->secondary_label), txt);
505 priv->has_secondary_text = TRUE;
506 gtk_widget_show (priv->secondary_label);
510 priv->has_secondary_text = FALSE;
511 gtk_widget_hide (priv->secondary_label);
513 setup_primary_label_font (dialog);
516 case PROP_SECONDARY_USE_MARKUP:
517 gtk_label_set_use_markup (GTK_LABEL (priv->secondary_label),
518 g_value_get_boolean (value));
521 gtk_message_dialog_set_image (dialog, g_value_get_object (value));
525 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
531 gtk_message_dialog_get_property (GObject *object,
536 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
537 GtkMessageDialogPrivate *priv = dialog->priv;
541 case PROP_MESSAGE_TYPE:
542 g_value_set_enum (value, (GtkMessageType) priv->message_type);
545 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (priv->label)));
547 case PROP_USE_MARKUP:
548 g_value_set_boolean (value, priv->has_primary_markup);
550 case PROP_SECONDARY_TEXT:
551 if (priv->has_secondary_text)
552 g_value_set_string (value,
553 gtk_label_get_label (GTK_LABEL (priv->secondary_label)));
555 g_value_set_string (value, NULL);
557 case PROP_SECONDARY_USE_MARKUP:
558 if (priv->has_secondary_text)
559 g_value_set_boolean (value,
560 gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)));
562 g_value_set_boolean (value, FALSE);
565 g_value_set_object (value, priv->image);
567 case PROP_MESSAGE_AREA:
568 g_value_set_object (value, priv->message_area);
571 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
577 * gtk_message_dialog_new:
578 * @parent: (allow-none): transient parent, or %NULL for none
580 * @type: type of message
581 * @buttons: set of buttons to use
582 * @message_format: (allow-none): printf()-style format string, or %NULL
583 * @...: arguments for @message_format
585 * Creates a new message dialog, which is a simple dialog with an icon
586 * indicating the dialog type (error, warning, etc.) and some text the
587 * user may want to see. When the user clicks a button a "response"
588 * signal is emitted with response IDs from #GtkResponseType. See
589 * #GtkDialog for more details.
591 * Return value: (transfer none): a new #GtkMessageDialog
594 gtk_message_dialog_new (GtkWindow *parent,
595 GtkDialogFlags flags,
597 GtkButtonsType buttons,
598 const gchar *message_format,
606 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
608 widget = g_object_new (GTK_TYPE_MESSAGE_DIALOG,
609 "message-type", type,
612 dialog = GTK_DIALOG (widget);
616 va_start (args, message_format);
617 msg = g_strdup_vprintf (message_format, args);
620 gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (widget)->priv->label),
627 gtk_window_set_transient_for (GTK_WINDOW (widget),
628 GTK_WINDOW (parent));
630 if (flags & GTK_DIALOG_MODAL)
631 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
633 if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
634 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
640 * gtk_message_dialog_new_with_markup:
641 * @parent: (allow-none): transient parent, or %NULL for none
643 * @type: type of message
644 * @buttons: set of buttons to use
645 * @message_format: (allow-none): printf()-style format string, or %NULL
646 * @...: arguments for @message_format
648 * Creates a new message dialog, which is a simple dialog with an icon
649 * indicating the dialog type (error, warning, etc.) and some text which
650 * is marked up with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
651 * When the user clicks a button a "response" signal is emitted with
652 * response IDs from #GtkResponseType. See #GtkDialog for more details.
654 * Special XML characters in the printf() arguments passed to this
655 * function will automatically be escaped as necessary.
656 * (See g_markup_printf_escaped() for how this is implemented.)
657 * Usually this is what you want, but if you have an existing
658 * Pango markup string that you want to use literally as the
659 * label, then you need to use gtk_message_dialog_set_markup()
660 * instead, since you can't pass the markup string either
661 * as the format (it might contain '%' characters) or as a string
665 * dialog = gtk_message_dialog_new (main_application_window,
666 * GTK_DIALOG_DESTROY_WITH_PARENT,
670 * gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
674 * Return value: a new #GtkMessageDialog
679 gtk_message_dialog_new_with_markup (GtkWindow *parent,
680 GtkDialogFlags flags,
682 GtkButtonsType buttons,
683 const gchar *message_format,
690 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
692 widget = gtk_message_dialog_new (parent, flags, type, buttons, NULL);
696 va_start (args, message_format);
697 msg = g_markup_vprintf_escaped (message_format, args);
700 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (widget), msg);
709 * gtk_message_dialog_set_image:
710 * @dialog: a #GtkMessageDialog
713 * Sets the dialog's image to @image.
718 gtk_message_dialog_set_image (GtkMessageDialog *dialog,
721 GtkMessageDialogPrivate *priv;
724 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (dialog));
725 g_return_if_fail (image == NULL || GTK_IS_WIDGET (image));
731 image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
732 gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
733 gtk_widget_set_valign (image, GTK_ALIGN_START);
736 priv->message_type = GTK_MESSAGE_OTHER;
738 parent = gtk_widget_get_parent (priv->image);
739 gtk_container_add (GTK_CONTAINER (parent), image);
740 gtk_container_remove (GTK_CONTAINER (parent), priv->image);
741 gtk_box_reorder_child (GTK_BOX (parent), image, 0);
745 g_object_notify (G_OBJECT (dialog), "image");
749 * gtk_message_dialog_get_image:
750 * @dialog: a #GtkMessageDialog
752 * Gets the dialog's image.
754 * Return value: (transfer none): the dialog's image
759 gtk_message_dialog_get_image (GtkMessageDialog *dialog)
761 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (dialog), NULL);
763 return dialog->priv->image;
767 * gtk_message_dialog_set_markup:
768 * @message_dialog: a #GtkMessageDialog
769 * @str: markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>)
771 * Sets the text of the message dialog to be @str, which is marked
772 * up with the <link linkend="PangoMarkupFormat">Pango text markup
778 gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
781 GtkMessageDialogPrivate *priv;
783 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
785 priv = message_dialog->priv;
787 priv->has_primary_markup = TRUE;
788 gtk_label_set_markup (GTK_LABEL (priv->label), str);
792 * gtk_message_dialog_format_secondary_text:
793 * @message_dialog: a #GtkMessageDialog
794 * @message_format: (allow-none): printf()-style format string, or %NULL
795 * @...: arguments for @message_format
797 * Sets the secondary text of the message dialog to be @message_format
798 * (with printf()-style).
800 * Note that setting a secondary text makes the primary text become
801 * bold, unless you have provided explicit markup.
806 gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog,
807 const gchar *message_format,
812 GtkMessageDialogPrivate *priv;
814 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
816 priv = message_dialog->priv;
820 priv->has_secondary_text = TRUE;
822 va_start (args, message_format);
823 msg = g_strdup_vprintf (message_format, args);
826 gtk_widget_show (priv->secondary_label);
827 gtk_label_set_text (GTK_LABEL (priv->secondary_label), msg);
833 priv->has_secondary_text = FALSE;
834 gtk_widget_hide (priv->secondary_label);
837 setup_primary_label_font (message_dialog);
841 * gtk_message_dialog_format_secondary_markup:
842 * @message_dialog: a #GtkMessageDialog
843 * @message_format: printf()-style markup string (see
844 <link linkend="PangoMarkupFormat">Pango markup format</link>), or %NULL
845 * @...: arguments for @message_format
847 * Sets the secondary text of the message dialog to be @message_format (with
848 * printf()-style), which is marked up with the
849 * <link linkend="PangoMarkupFormat">Pango text markup language</link>.
851 * Note that setting a secondary text makes the primary text become
852 * bold, unless you have provided explicit markup.
854 * Due to an oversight, this function does not escape special XML characters
855 * like gtk_message_dialog_new_with_markup() does. Thus, if the arguments
856 * may contain special XML characters, you should use g_markup_printf_escaped()
859 * <informalexample><programlisting>
862 * msg = g_markup_printf_escaped (message_format, ...);
863 * gtk_message_dialog_format_secondary_markup (message_dialog, "%s", msg);
865 * </programlisting></informalexample>
870 gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
871 const gchar *message_format,
876 GtkMessageDialogPrivate *priv;
878 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
880 priv = message_dialog->priv;
884 priv->has_secondary_text = TRUE;
886 va_start (args, message_format);
887 msg = g_strdup_vprintf (message_format, args);
890 gtk_widget_show (priv->secondary_label);
891 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), msg);
897 priv->has_secondary_text = FALSE;
898 gtk_widget_hide (priv->secondary_label);
901 setup_primary_label_font (message_dialog);
905 * gtk_message_dialog_get_message_area:
906 * @message_dialog: a #GtkMessageDialog
908 * Returns the message area of the dialog. This is the box where the
909 * dialog's primary and secondary labels are packed. You can add your
910 * own extra content to that box and it will appear below those labels,
911 * on the right side of the dialog's image (or on the left for right-to-left
912 * languages). See gtk_dialog_get_content_area() for the corresponding
913 * function in the parent #GtkDialog.
915 * Return value: (transfer none): A #GtkVBox corresponding to the
916 * "message area" in the @message_dialog.
921 gtk_message_dialog_get_message_area (GtkMessageDialog *message_dialog)
923 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog), NULL);
925 return message_dialog->priv->message_area;
929 gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
930 GtkButtonsType buttons)
932 GtkDialog* dialog = GTK_DIALOG (message_dialog);
936 case GTK_BUTTONS_NONE:
941 gtk_dialog_add_button (dialog,
946 case GTK_BUTTONS_CLOSE:
947 gtk_dialog_add_button (dialog,
952 case GTK_BUTTONS_CANCEL:
953 gtk_dialog_add_button (dialog,
955 GTK_RESPONSE_CANCEL);
958 case GTK_BUTTONS_YES_NO:
959 gtk_dialog_add_button (dialog,
962 gtk_dialog_add_button (dialog,
965 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
971 case GTK_BUTTONS_OK_CANCEL:
972 gtk_dialog_add_button (dialog,
974 GTK_RESPONSE_CANCEL);
975 gtk_dialog_add_button (dialog,
978 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
985 g_warning ("Unknown GtkButtonsType");
989 g_object_notify (G_OBJECT (message_dialog), "buttons");
993 gtk_message_dialog_style_updated (GtkWidget *widget)
995 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget);
999 parent = gtk_widget_get_parent (gtk_message_dialog_get_image (dialog));
1003 gtk_widget_style_get (widget, "message-border",
1004 &border_width, NULL);
1006 gtk_container_set_border_width (GTK_CONTAINER (parent),
1007 MAX (0, border_width - 7));
1010 setup_primary_label_font (dialog);
1012 GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_updated (widget);