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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2003. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #include "gtkmessagedialog.h"
33 #include "gtkaccessible.h"
34 #include "gtkbuildable.h"
39 #include "gtkiconfactory.h"
41 #include "gtkprivate.h"
42 #include "gtktypebuiltins.h"
45 * SECTION:gtkmessagedialog
46 * @Short_description: A convenient message window
47 * @Title: GtkMessageDialog
48 * @See_also:#GtkDialog
50 * #GtkMessageDialog presents a dialog with an image representing the type of
51 * message (Error, Question, etc.) alongside some message text. It's simply a
52 * convenience widget; you could construct the equivalent of #GtkMessageDialog
53 * from #GtkDialog without too much effort, but #GtkMessageDialog saves typing.
55 * The easiest way to do a modal message dialog is to use gtk_dialog_run(), though
56 * you can also pass in the %GTK_DIALOG_MODAL flag, gtk_dialog_run() automatically
57 * makes the dialog modal and waits for the user to respond to it. gtk_dialog_run()
58 * returns when any dialog button is clicked.
60 * <title>A modal dialog.</title>
62 * dialog = gtk_message_dialog_new (main_application_window,
63 * GTK_DIALOG_DESTROY_WITH_PARENT,
66 * "Error loading file '%s': %s",
67 * filename, g_strerror (errno));
68 * gtk_dialog_run (GTK_DIALOG (dialog));
69 * gtk_widget_destroy (dialog);
72 * You might do a non-modal #GtkMessageDialog as follows:
74 * <title>A non-modal dialog.</title>
76 * dialog = gtk_message_dialog_new (main_application_window,
77 * GTK_DIALOG_DESTROY_WITH_PARENT,
80 * "Error loading file '%s': %s",
81 * filename, g_strerror (errno));
83 * /* Destroy the dialog when the user responds to it (e.g. clicks a button) */
84 * g_signal_connect_swapped (dialog, "response",
85 * G_CALLBACK (gtk_widget_destroy),
90 * <refsect2 id="GtkMessageDialog-BUILDER-UI">
91 * <title>GtkMessageDialog as GtkBuildable</title>
93 * The GtkMessageDialog implementation of the GtkBuildable interface exposes
94 * the message area as an internal child with the name "message_area".
99 struct _GtkMessageDialogPrivate
103 GtkWidget *message_area; /* vbox for the primary and secondary labels, and any extra content from the caller */
104 GtkWidget *secondary_label;
106 guint has_primary_markup : 1;
107 guint has_secondary_text : 1;
108 guint message_type : 3;
111 static void gtk_message_dialog_style_updated (GtkWidget *widget);
113 static void gtk_message_dialog_set_property (GObject *object,
117 static void gtk_message_dialog_get_property (GObject *object,
121 static void gtk_message_dialog_add_buttons (GtkMessageDialog *message_dialog,
122 GtkButtonsType buttons);
123 static void gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface);
124 static GObject * gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
126 const gchar *childname);
136 PROP_SECONDARY_USE_MARKUP,
141 G_DEFINE_TYPE_WITH_CODE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG,
142 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
143 gtk_message_dialog_buildable_interface_init))
145 static GtkBuildableIface *parent_buildable_iface;
148 gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface)
150 parent_buildable_iface = g_type_interface_peek_parent (iface);
151 iface->get_internal_child = gtk_message_dialog_buildable_get_internal_child;
152 iface->custom_tag_start = parent_buildable_iface->custom_tag_start;
153 iface->custom_finished = parent_buildable_iface->custom_finished;
157 gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
159 const gchar *childname)
161 if (strcmp (childname, "message_area") == 0)
162 return G_OBJECT (gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (buildable)));
164 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
169 gtk_message_dialog_class_init (GtkMessageDialogClass *class)
171 GtkWidgetClass *widget_class;
172 GObjectClass *gobject_class;
174 widget_class = GTK_WIDGET_CLASS (class);
175 gobject_class = G_OBJECT_CLASS (class);
177 widget_class->style_updated = gtk_message_dialog_style_updated;
179 gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_ALERT);
181 gobject_class->set_property = gtk_message_dialog_set_property;
182 gobject_class->get_property = gtk_message_dialog_get_property;
184 gtk_widget_class_install_style_property (widget_class,
185 g_param_spec_int ("message-border",
186 P_("Image/label border"),
187 P_("Width of border around the label and image in the message dialog"),
191 GTK_PARAM_READABLE));
194 * GtkMessageDialog:message-type:
196 * The type of the message. The type is used to determine
197 * the image that is shown in the dialog, unless the image is
198 * explicitly set by the ::image property.
200 g_object_class_install_property (gobject_class,
202 g_param_spec_enum ("message-type",
204 P_("The type of message"),
205 GTK_TYPE_MESSAGE_TYPE,
207 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
208 g_object_class_install_property (gobject_class,
210 g_param_spec_enum ("buttons",
211 P_("Message Buttons"),
212 P_("The buttons shown in the message dialog"),
213 GTK_TYPE_BUTTONS_TYPE,
215 GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
218 * GtkMessageDialog:text:
220 * The primary text of the message dialog. If the dialog has
221 * a secondary text, this will appear as the title.
225 g_object_class_install_property (gobject_class,
227 g_param_spec_string ("text",
229 P_("The primary text of the message dialog"),
231 GTK_PARAM_READWRITE));
234 * GtkMessageDialog:use-markup:
236 * %TRUE if the primary text of the dialog includes Pango markup.
237 * See pango_parse_markup().
241 g_object_class_install_property (gobject_class,
243 g_param_spec_boolean ("use-markup",
245 P_("The primary text of the title includes Pango markup."),
247 GTK_PARAM_READWRITE));
250 * GtkMessageDialog:secondary-text:
252 * The secondary text of the message dialog.
256 g_object_class_install_property (gobject_class,
258 g_param_spec_string ("secondary-text",
259 P_("Secondary Text"),
260 P_("The secondary text of the message dialog"),
262 GTK_PARAM_READWRITE));
265 * GtkMessageDialog:secondary-use-markup:
267 * %TRUE if the secondary text of the dialog includes Pango markup.
268 * See pango_parse_markup().
272 g_object_class_install_property (gobject_class,
273 PROP_SECONDARY_USE_MARKUP,
274 g_param_spec_boolean ("secondary-use-markup",
275 P_("Use Markup in secondary"),
276 P_("The secondary text includes Pango markup."),
278 GTK_PARAM_READWRITE));
281 * GtkMessageDialog:image:
283 * The image for this dialog.
287 g_object_class_install_property (gobject_class,
289 g_param_spec_object ("image",
293 GTK_PARAM_READWRITE));
296 * GtkMessageDialog:message-area
298 * The #GtkVBox that corresponds to the message area of this dialog. See
299 * gtk_message_dialog_get_message_area() for a detailed description of this
304 g_object_class_install_property (gobject_class,
306 g_param_spec_object ("message-area",
308 P_("GtkVBox that holds the dialog's primary and secondary labels"),
310 GTK_PARAM_READABLE));
312 g_type_class_add_private (gobject_class, sizeof (GtkMessageDialogPrivate));
316 gtk_message_dialog_init (GtkMessageDialog *dialog)
319 GtkDialog *message_dialog = GTK_DIALOG (dialog);
320 GtkWidget *action_area, *content_area;
321 GtkMessageDialogPrivate *priv;
323 dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
324 GTK_TYPE_MESSAGE_DIALOG,
325 GtkMessageDialogPrivate);
328 content_area = gtk_dialog_get_content_area (message_dialog);
329 action_area = gtk_dialog_get_action_area (message_dialog);
331 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
332 gtk_window_set_title (GTK_WINDOW (dialog), "");
333 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
335 priv->has_primary_markup = FALSE;
336 priv->has_secondary_text = FALSE;
337 priv->secondary_label = gtk_label_new (NULL);
338 gtk_widget_set_no_show_all (priv->secondary_label, TRUE);
340 priv->label = gtk_label_new (NULL);
341 priv->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
342 gtk_widget_set_halign (priv->image, GTK_ALIGN_CENTER);
343 gtk_widget_set_valign (priv->image, GTK_ALIGN_START);
345 gtk_label_set_line_wrap (GTK_LABEL (priv->label), TRUE);
346 gtk_label_set_selectable (GTK_LABEL (priv->label), TRUE);
347 gtk_widget_set_halign (priv->label, GTK_ALIGN_START);
348 gtk_widget_set_valign (priv->label, GTK_ALIGN_START);
350 gtk_label_set_line_wrap (GTK_LABEL (priv->secondary_label), TRUE);
351 gtk_label_set_selectable (GTK_LABEL (priv->secondary_label), TRUE);
352 gtk_widget_set_halign (priv->secondary_label, GTK_ALIGN_START);
353 gtk_widget_set_valign (priv->secondary_label, GTK_ALIGN_START);
355 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
356 priv->message_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
358 gtk_box_pack_start (GTK_BOX (priv->message_area), priv->label,
361 gtk_box_pack_start (GTK_BOX (priv->message_area), priv->secondary_label,
364 gtk_box_pack_start (GTK_BOX (hbox), priv->image,
367 gtk_box_pack_start (GTK_BOX (hbox), priv->message_area,
370 gtk_box_pack_start (GTK_BOX (content_area),
374 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
375 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
376 gtk_box_set_spacing (GTK_BOX (content_area), 14); /* 14 + 2 * 5 = 24 */
377 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
378 gtk_box_set_spacing (GTK_BOX (action_area), 6);
380 gtk_message_dialog_style_updated (GTK_WIDGET (dialog));
382 gtk_widget_show_all (hbox);
386 setup_primary_label_font (GtkMessageDialog *dialog)
388 GtkMessageDialogPrivate *priv = dialog->priv;
390 PangoFontDescription *font_desc;
391 GtkStyleContext *context;
394 /* unset the font settings */
395 gtk_widget_override_font (priv->label, NULL);
397 if (priv->has_secondary_text && !priv->has_primary_markup)
399 context = gtk_widget_get_style_context (priv->label);
400 state = gtk_widget_get_state_flags (priv->label);
402 size = pango_font_description_get_size (gtk_style_context_get_font (context, state));
403 font_desc = pango_font_description_new ();
404 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
405 pango_font_description_set_size (font_desc, size * PANGO_SCALE_LARGE);
406 gtk_widget_override_font (priv->label, font_desc);
407 pango_font_description_free (font_desc);
412 setup_type (GtkMessageDialog *dialog,
415 GtkMessageDialogPrivate *priv = dialog->priv;
416 const gchar *stock_id = NULL;
419 priv->message_type = type;
423 case GTK_MESSAGE_INFO:
424 stock_id = GTK_STOCK_DIALOG_INFO;
427 case GTK_MESSAGE_QUESTION:
428 stock_id = GTK_STOCK_DIALOG_QUESTION;
431 case GTK_MESSAGE_WARNING:
432 stock_id = GTK_STOCK_DIALOG_WARNING;
435 case GTK_MESSAGE_ERROR:
436 stock_id = GTK_STOCK_DIALOG_ERROR;
439 case GTK_MESSAGE_OTHER:
443 g_warning ("Unknown GtkMessageType %u", type);
448 gtk_image_set_from_stock (GTK_IMAGE (priv->image), stock_id,
449 GTK_ICON_SIZE_DIALOG);
451 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (dialog));
452 if (GTK_IS_ACCESSIBLE (atk_obj))
454 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
459 gtk_stock_lookup (stock_id, &item);
460 atk_object_set_name (atk_obj, item.label);
466 gtk_message_dialog_set_property (GObject *object,
471 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
472 GtkMessageDialogPrivate *priv = dialog->priv;
476 case PROP_MESSAGE_TYPE:
477 setup_type (dialog, g_value_get_enum (value));
480 gtk_message_dialog_add_buttons (dialog, g_value_get_enum (value));
483 if (priv->has_primary_markup)
484 gtk_label_set_markup (GTK_LABEL (priv->label),
485 g_value_get_string (value));
487 gtk_label_set_text (GTK_LABEL (priv->label),
488 g_value_get_string (value));
490 case PROP_USE_MARKUP:
491 priv->has_primary_markup = g_value_get_boolean (value) != FALSE;
492 gtk_label_set_use_markup (GTK_LABEL (priv->label),
493 priv->has_primary_markup);
494 setup_primary_label_font (dialog);
496 case PROP_SECONDARY_TEXT:
498 const gchar *txt = g_value_get_string (value);
500 if (gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)))
501 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), txt);
503 gtk_label_set_text (GTK_LABEL (priv->secondary_label), txt);
507 priv->has_secondary_text = TRUE;
508 gtk_widget_show (priv->secondary_label);
512 priv->has_secondary_text = FALSE;
513 gtk_widget_hide (priv->secondary_label);
515 setup_primary_label_font (dialog);
518 case PROP_SECONDARY_USE_MARKUP:
519 gtk_label_set_use_markup (GTK_LABEL (priv->secondary_label),
520 g_value_get_boolean (value));
523 gtk_message_dialog_set_image (dialog, g_value_get_object (value));
527 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
533 gtk_message_dialog_get_property (GObject *object,
538 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
539 GtkMessageDialogPrivate *priv = dialog->priv;
543 case PROP_MESSAGE_TYPE:
544 g_value_set_enum (value, (GtkMessageType) priv->message_type);
547 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (priv->label)));
549 case PROP_USE_MARKUP:
550 g_value_set_boolean (value, priv->has_primary_markup);
552 case PROP_SECONDARY_TEXT:
553 if (priv->has_secondary_text)
554 g_value_set_string (value,
555 gtk_label_get_label (GTK_LABEL (priv->secondary_label)));
557 g_value_set_string (value, NULL);
559 case PROP_SECONDARY_USE_MARKUP:
560 if (priv->has_secondary_text)
561 g_value_set_boolean (value,
562 gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)));
564 g_value_set_boolean (value, FALSE);
567 g_value_set_object (value, priv->image);
569 case PROP_MESSAGE_AREA:
570 g_value_set_object (value, priv->message_area);
573 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
579 * gtk_message_dialog_new:
580 * @parent: (allow-none): transient parent, or %NULL for none
582 * @type: type of message
583 * @buttons: set of buttons to use
584 * @message_format: (allow-none): printf()-style format string, or %NULL
585 * @...: arguments for @message_format
587 * Creates a new message dialog, which is a simple dialog with an icon
588 * indicating the dialog type (error, warning, etc.) and some text the
589 * user may want to see. When the user clicks a button a "response"
590 * signal is emitted with response IDs from #GtkResponseType. See
591 * #GtkDialog for more details.
593 * Return value: (transfer none): a new #GtkMessageDialog
596 gtk_message_dialog_new (GtkWindow *parent,
597 GtkDialogFlags flags,
599 GtkButtonsType buttons,
600 const gchar *message_format,
608 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
610 widget = g_object_new (GTK_TYPE_MESSAGE_DIALOG,
611 "message-type", type,
614 dialog = GTK_DIALOG (widget);
618 va_start (args, message_format);
619 msg = g_strdup_vprintf (message_format, args);
622 gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (widget)->priv->label),
629 gtk_window_set_transient_for (GTK_WINDOW (widget),
630 GTK_WINDOW (parent));
632 if (flags & GTK_DIALOG_MODAL)
633 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
635 if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
636 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
642 * gtk_message_dialog_new_with_markup:
643 * @parent: (allow-none): transient parent, or %NULL for none
645 * @type: type of message
646 * @buttons: set of buttons to use
647 * @message_format: (allow-none): printf()-style format string, or %NULL
648 * @...: arguments for @message_format
650 * Creates a new message dialog, which is a simple dialog with an icon
651 * indicating the dialog type (error, warning, etc.) and some text which
652 * is marked up with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
653 * When the user clicks a button a "response" signal is emitted with
654 * response IDs from #GtkResponseType. See #GtkDialog for more details.
656 * Special XML characters in the printf() arguments passed to this
657 * function will automatically be escaped as necessary.
658 * (See g_markup_printf_escaped() for how this is implemented.)
659 * Usually this is what you want, but if you have an existing
660 * Pango markup string that you want to use literally as the
661 * label, then you need to use gtk_message_dialog_set_markup()
662 * instead, since you can't pass the markup string either
663 * as the format (it might contain '%' characters) or as a string
667 * dialog = gtk_message_dialog_new (main_application_window,
668 * GTK_DIALOG_DESTROY_WITH_PARENT,
672 * gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
676 * Return value: a new #GtkMessageDialog
681 gtk_message_dialog_new_with_markup (GtkWindow *parent,
682 GtkDialogFlags flags,
684 GtkButtonsType buttons,
685 const gchar *message_format,
692 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
694 widget = gtk_message_dialog_new (parent, flags, type, buttons, NULL);
698 va_start (args, message_format);
699 msg = g_markup_vprintf_escaped (message_format, args);
702 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (widget), msg);
711 * gtk_message_dialog_set_image:
712 * @dialog: a #GtkMessageDialog
715 * Sets the dialog's image to @image.
720 gtk_message_dialog_set_image (GtkMessageDialog *dialog,
723 GtkMessageDialogPrivate *priv;
726 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (dialog));
727 g_return_if_fail (image == NULL || GTK_IS_WIDGET (image));
733 image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
734 gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
735 gtk_widget_set_valign (image, GTK_ALIGN_START);
738 priv->message_type = GTK_MESSAGE_OTHER;
740 parent = gtk_widget_get_parent (priv->image);
741 gtk_container_add (GTK_CONTAINER (parent), image);
742 gtk_container_remove (GTK_CONTAINER (parent), priv->image);
743 gtk_box_reorder_child (GTK_BOX (parent), image, 0);
747 g_object_notify (G_OBJECT (dialog), "image");
751 * gtk_message_dialog_get_image:
752 * @dialog: a #GtkMessageDialog
754 * Gets the dialog's image.
756 * Return value: (transfer none): the dialog's image
761 gtk_message_dialog_get_image (GtkMessageDialog *dialog)
763 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (dialog), NULL);
765 return dialog->priv->image;
769 * gtk_message_dialog_set_markup:
770 * @message_dialog: a #GtkMessageDialog
771 * @str: markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>)
773 * Sets the text of the message dialog to be @str, which is marked
774 * up with the <link linkend="PangoMarkupFormat">Pango text markup
780 gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
783 GtkMessageDialogPrivate *priv;
785 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
787 priv = message_dialog->priv;
789 priv->has_primary_markup = TRUE;
790 gtk_label_set_markup (GTK_LABEL (priv->label), str);
794 * gtk_message_dialog_format_secondary_text:
795 * @message_dialog: a #GtkMessageDialog
796 * @message_format: (allow-none): printf()-style format string, or %NULL
797 * @...: arguments for @message_format
799 * Sets the secondary text of the message dialog to be @message_format
800 * (with printf()-style).
802 * Note that setting a secondary text makes the primary text become
803 * bold, unless you have provided explicit markup.
808 gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog,
809 const gchar *message_format,
814 GtkMessageDialogPrivate *priv;
816 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
818 priv = message_dialog->priv;
822 priv->has_secondary_text = TRUE;
824 va_start (args, message_format);
825 msg = g_strdup_vprintf (message_format, args);
828 gtk_widget_show (priv->secondary_label);
829 gtk_label_set_text (GTK_LABEL (priv->secondary_label), msg);
835 priv->has_secondary_text = FALSE;
836 gtk_widget_hide (priv->secondary_label);
839 setup_primary_label_font (message_dialog);
843 * gtk_message_dialog_format_secondary_markup:
844 * @message_dialog: a #GtkMessageDialog
845 * @message_format: printf()-style markup string (see
846 <link linkend="PangoMarkupFormat">Pango markup format</link>), or %NULL
847 * @...: arguments for @message_format
849 * Sets the secondary text of the message dialog to be @message_format (with
850 * printf()-style), which is marked up with the
851 * <link linkend="PangoMarkupFormat">Pango text markup language</link>.
853 * Note that setting a secondary text makes the primary text become
854 * bold, unless you have provided explicit markup.
856 * Due to an oversight, this function does not escape special XML characters
857 * like gtk_message_dialog_new_with_markup() does. Thus, if the arguments
858 * may contain special XML characters, you should use g_markup_printf_escaped()
861 * <informalexample><programlisting>
864 * msg = g_markup_printf_escaped (message_format, ...);
865 * gtk_message_dialog_format_secondary_markup (message_dialog, "%s", msg);
867 * </programlisting></informalexample>
872 gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
873 const gchar *message_format,
878 GtkMessageDialogPrivate *priv;
880 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
882 priv = message_dialog->priv;
886 priv->has_secondary_text = TRUE;
888 va_start (args, message_format);
889 msg = g_strdup_vprintf (message_format, args);
892 gtk_widget_show (priv->secondary_label);
893 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), msg);
899 priv->has_secondary_text = FALSE;
900 gtk_widget_hide (priv->secondary_label);
903 setup_primary_label_font (message_dialog);
907 * gtk_message_dialog_get_message_area:
908 * @message_dialog: a #GtkMessageDialog
910 * Returns the message area of the dialog. This is the box where the
911 * dialog's primary and secondary labels are packed. You can add your
912 * own extra content to that box and it will appear below those labels,
913 * on the right side of the dialog's image (or on the left for right-to-left
914 * languages). See gtk_dialog_get_content_area() for the corresponding
915 * function in the parent #GtkDialog.
917 * Return value: (transfer none): A #GtkVBox corresponding to the
918 * "message area" in the @message_dialog.
923 gtk_message_dialog_get_message_area (GtkMessageDialog *message_dialog)
925 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog), NULL);
927 return message_dialog->priv->message_area;
931 gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
932 GtkButtonsType buttons)
934 GtkDialog* dialog = GTK_DIALOG (message_dialog);
938 case GTK_BUTTONS_NONE:
943 gtk_dialog_add_button (dialog,
948 case GTK_BUTTONS_CLOSE:
949 gtk_dialog_add_button (dialog,
954 case GTK_BUTTONS_CANCEL:
955 gtk_dialog_add_button (dialog,
957 GTK_RESPONSE_CANCEL);
960 case GTK_BUTTONS_YES_NO:
961 gtk_dialog_add_button (dialog,
964 gtk_dialog_add_button (dialog,
967 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
973 case GTK_BUTTONS_OK_CANCEL:
974 gtk_dialog_add_button (dialog,
976 GTK_RESPONSE_CANCEL);
977 gtk_dialog_add_button (dialog,
980 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
987 g_warning ("Unknown GtkButtonsType");
991 g_object_notify (G_OBJECT (message_dialog), "buttons");
995 gtk_message_dialog_style_updated (GtkWidget *widget)
997 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget);
1001 parent = gtk_widget_get_parent (gtk_message_dialog_get_image (dialog));
1005 gtk_widget_style_get (widget, "message-border",
1006 &border_width, NULL);
1008 gtk_container_set_border_width (GTK_CONTAINER (parent),
1009 MAX (0, border_width - 7));
1012 setup_primary_label_font (dialog);
1014 GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_updated (widget);