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 gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.0);
354 gtk_misc_set_alignment (GTK_MISC (priv->secondary_label), 0.0, 0.0);
356 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
357 priv->message_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
359 gtk_box_pack_start (GTK_BOX (priv->message_area), priv->label,
362 gtk_box_pack_start (GTK_BOX (priv->message_area), priv->secondary_label,
365 gtk_box_pack_start (GTK_BOX (hbox), priv->image,
368 gtk_box_pack_start (GTK_BOX (hbox), priv->message_area,
371 gtk_box_pack_start (GTK_BOX (content_area),
375 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
376 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
377 gtk_box_set_spacing (GTK_BOX (content_area), 14); /* 14 + 2 * 5 = 24 */
378 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
379 gtk_box_set_spacing (GTK_BOX (action_area), 6);
381 gtk_message_dialog_style_updated (GTK_WIDGET (dialog));
383 gtk_widget_show_all (hbox);
387 setup_primary_label_font (GtkMessageDialog *dialog)
389 GtkMessageDialogPrivate *priv = dialog->priv;
391 if (priv->has_secondary_text && !priv->has_primary_markup)
393 PangoAttrList *attributes;
394 PangoAttribute *attr;
396 attributes = pango_attr_list_new ();
398 attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
399 pango_attr_list_insert (attributes, attr);
401 attr = pango_attr_scale_new (PANGO_SCALE_LARGE);
402 pango_attr_list_insert (attributes, attr);
404 gtk_label_set_attributes (GTK_LABEL (priv->label), attributes);
405 pango_attr_list_unref (attributes);
409 /* unset the font settings */
410 gtk_label_set_attributes (GTK_LABEL (priv->label), NULL);
415 setup_type (GtkMessageDialog *dialog,
418 GtkMessageDialogPrivate *priv = dialog->priv;
419 const gchar *stock_id = NULL;
422 priv->message_type = type;
426 case GTK_MESSAGE_INFO:
427 stock_id = GTK_STOCK_DIALOG_INFO;
430 case GTK_MESSAGE_QUESTION:
431 stock_id = GTK_STOCK_DIALOG_QUESTION;
434 case GTK_MESSAGE_WARNING:
435 stock_id = GTK_STOCK_DIALOG_WARNING;
438 case GTK_MESSAGE_ERROR:
439 stock_id = GTK_STOCK_DIALOG_ERROR;
442 case GTK_MESSAGE_OTHER:
446 g_warning ("Unknown GtkMessageType %u", type);
451 gtk_image_set_from_stock (GTK_IMAGE (priv->image), stock_id,
452 GTK_ICON_SIZE_DIALOG);
454 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (dialog));
455 if (GTK_IS_ACCESSIBLE (atk_obj))
457 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
462 gtk_stock_lookup (stock_id, &item);
463 atk_object_set_name (atk_obj, item.label);
469 gtk_message_dialog_set_property (GObject *object,
474 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
475 GtkMessageDialogPrivate *priv = dialog->priv;
479 case PROP_MESSAGE_TYPE:
480 setup_type (dialog, g_value_get_enum (value));
483 gtk_message_dialog_add_buttons (dialog, g_value_get_enum (value));
486 if (priv->has_primary_markup)
487 gtk_label_set_markup (GTK_LABEL (priv->label),
488 g_value_get_string (value));
490 gtk_label_set_text (GTK_LABEL (priv->label),
491 g_value_get_string (value));
493 case PROP_USE_MARKUP:
494 priv->has_primary_markup = g_value_get_boolean (value) != FALSE;
495 gtk_label_set_use_markup (GTK_LABEL (priv->label),
496 priv->has_primary_markup);
497 setup_primary_label_font (dialog);
499 case PROP_SECONDARY_TEXT:
501 const gchar *txt = g_value_get_string (value);
503 if (gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)))
504 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), txt);
506 gtk_label_set_text (GTK_LABEL (priv->secondary_label), txt);
510 priv->has_secondary_text = TRUE;
511 gtk_widget_show (priv->secondary_label);
515 priv->has_secondary_text = FALSE;
516 gtk_widget_hide (priv->secondary_label);
518 setup_primary_label_font (dialog);
521 case PROP_SECONDARY_USE_MARKUP:
522 gtk_label_set_use_markup (GTK_LABEL (priv->secondary_label),
523 g_value_get_boolean (value));
526 gtk_message_dialog_set_image (dialog, g_value_get_object (value));
530 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
536 gtk_message_dialog_get_property (GObject *object,
541 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
542 GtkMessageDialogPrivate *priv = dialog->priv;
546 case PROP_MESSAGE_TYPE:
547 g_value_set_enum (value, (GtkMessageType) priv->message_type);
550 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (priv->label)));
552 case PROP_USE_MARKUP:
553 g_value_set_boolean (value, priv->has_primary_markup);
555 case PROP_SECONDARY_TEXT:
556 if (priv->has_secondary_text)
557 g_value_set_string (value,
558 gtk_label_get_label (GTK_LABEL (priv->secondary_label)));
560 g_value_set_string (value, NULL);
562 case PROP_SECONDARY_USE_MARKUP:
563 if (priv->has_secondary_text)
564 g_value_set_boolean (value,
565 gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)));
567 g_value_set_boolean (value, FALSE);
570 g_value_set_object (value, priv->image);
572 case PROP_MESSAGE_AREA:
573 g_value_set_object (value, priv->message_area);
576 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
582 * gtk_message_dialog_new:
583 * @parent: (allow-none): transient parent, or %NULL for none
585 * @type: type of message
586 * @buttons: set of buttons to use
587 * @message_format: (allow-none): printf()-style format string, or %NULL
588 * @...: arguments for @message_format
590 * Creates a new message dialog, which is a simple dialog with an icon
591 * indicating the dialog type (error, warning, etc.) and some text the
592 * user may want to see. When the user clicks a button a "response"
593 * signal is emitted with response IDs from #GtkResponseType. See
594 * #GtkDialog for more details.
596 * Return value: (transfer none): a new #GtkMessageDialog
599 gtk_message_dialog_new (GtkWindow *parent,
600 GtkDialogFlags flags,
602 GtkButtonsType buttons,
603 const gchar *message_format,
611 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
613 widget = g_object_new (GTK_TYPE_MESSAGE_DIALOG,
614 "message-type", type,
617 dialog = GTK_DIALOG (widget);
621 va_start (args, message_format);
622 msg = g_strdup_vprintf (message_format, args);
625 gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (widget)->priv->label),
632 gtk_window_set_transient_for (GTK_WINDOW (widget),
633 GTK_WINDOW (parent));
635 if (flags & GTK_DIALOG_MODAL)
636 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
638 if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
639 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
645 * gtk_message_dialog_new_with_markup:
646 * @parent: (allow-none): transient parent, or %NULL for none
648 * @type: type of message
649 * @buttons: set of buttons to use
650 * @message_format: (allow-none): printf()-style format string, or %NULL
651 * @...: arguments for @message_format
653 * Creates a new message dialog, which is a simple dialog with an icon
654 * indicating the dialog type (error, warning, etc.) and some text which
655 * is marked up with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
656 * When the user clicks a button a "response" signal is emitted with
657 * response IDs from #GtkResponseType. See #GtkDialog for more details.
659 * Special XML characters in the printf() arguments passed to this
660 * function will automatically be escaped as necessary.
661 * (See g_markup_printf_escaped() for how this is implemented.)
662 * Usually this is what you want, but if you have an existing
663 * Pango markup string that you want to use literally as the
664 * label, then you need to use gtk_message_dialog_set_markup()
665 * instead, since you can't pass the markup string either
666 * as the format (it might contain '%' characters) or as a string
670 * dialog = gtk_message_dialog_new (main_application_window,
671 * GTK_DIALOG_DESTROY_WITH_PARENT,
675 * gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
679 * Return value: a new #GtkMessageDialog
684 gtk_message_dialog_new_with_markup (GtkWindow *parent,
685 GtkDialogFlags flags,
687 GtkButtonsType buttons,
688 const gchar *message_format,
695 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
697 widget = gtk_message_dialog_new (parent, flags, type, buttons, NULL);
701 va_start (args, message_format);
702 msg = g_markup_vprintf_escaped (message_format, args);
705 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (widget), msg);
714 * gtk_message_dialog_set_image:
715 * @dialog: a #GtkMessageDialog
718 * Sets the dialog's image to @image.
723 gtk_message_dialog_set_image (GtkMessageDialog *dialog,
726 GtkMessageDialogPrivate *priv;
729 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (dialog));
730 g_return_if_fail (image == NULL || GTK_IS_WIDGET (image));
736 image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
737 gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
738 gtk_widget_set_valign (image, GTK_ALIGN_START);
741 priv->message_type = GTK_MESSAGE_OTHER;
743 parent = gtk_widget_get_parent (priv->image);
744 gtk_container_add (GTK_CONTAINER (parent), image);
745 gtk_container_remove (GTK_CONTAINER (parent), priv->image);
746 gtk_box_reorder_child (GTK_BOX (parent), image, 0);
750 g_object_notify (G_OBJECT (dialog), "image");
754 * gtk_message_dialog_get_image:
755 * @dialog: a #GtkMessageDialog
757 * Gets the dialog's image.
759 * Return value: (transfer none): the dialog's image
764 gtk_message_dialog_get_image (GtkMessageDialog *dialog)
766 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (dialog), NULL);
768 return dialog->priv->image;
772 * gtk_message_dialog_set_markup:
773 * @message_dialog: a #GtkMessageDialog
774 * @str: markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>)
776 * Sets the text of the message dialog to be @str, which is marked
777 * up with the <link linkend="PangoMarkupFormat">Pango text markup
783 gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
786 GtkMessageDialogPrivate *priv;
788 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
790 priv = message_dialog->priv;
792 priv->has_primary_markup = TRUE;
793 gtk_label_set_markup (GTK_LABEL (priv->label), str);
797 * gtk_message_dialog_format_secondary_text:
798 * @message_dialog: a #GtkMessageDialog
799 * @message_format: (allow-none): printf()-style format string, or %NULL
800 * @...: arguments for @message_format
802 * Sets the secondary text of the message dialog to be @message_format
803 * (with printf()-style).
805 * Note that setting a secondary text makes the primary text become
806 * bold, unless you have provided explicit markup.
811 gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog,
812 const gchar *message_format,
817 GtkMessageDialogPrivate *priv;
819 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
821 priv = message_dialog->priv;
825 priv->has_secondary_text = TRUE;
827 va_start (args, message_format);
828 msg = g_strdup_vprintf (message_format, args);
831 gtk_widget_show (priv->secondary_label);
832 gtk_label_set_text (GTK_LABEL (priv->secondary_label), msg);
838 priv->has_secondary_text = FALSE;
839 gtk_widget_hide (priv->secondary_label);
842 setup_primary_label_font (message_dialog);
846 * gtk_message_dialog_format_secondary_markup:
847 * @message_dialog: a #GtkMessageDialog
848 * @message_format: printf()-style markup string (see
849 <link linkend="PangoMarkupFormat">Pango markup format</link>), or %NULL
850 * @...: arguments for @message_format
852 * Sets the secondary text of the message dialog to be @message_format (with
853 * printf()-style), which is marked up with the
854 * <link linkend="PangoMarkupFormat">Pango text markup language</link>.
856 * Note that setting a secondary text makes the primary text become
857 * bold, unless you have provided explicit markup.
859 * Due to an oversight, this function does not escape special XML characters
860 * like gtk_message_dialog_new_with_markup() does. Thus, if the arguments
861 * may contain special XML characters, you should use g_markup_printf_escaped()
864 * <informalexample><programlisting>
867 * msg = g_markup_printf_escaped (message_format, ...);
868 * gtk_message_dialog_format_secondary_markup (message_dialog, "%s", msg);
870 * </programlisting></informalexample>
875 gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
876 const gchar *message_format,
881 GtkMessageDialogPrivate *priv;
883 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
885 priv = message_dialog->priv;
889 priv->has_secondary_text = TRUE;
891 va_start (args, message_format);
892 msg = g_strdup_vprintf (message_format, args);
895 gtk_widget_show (priv->secondary_label);
896 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), msg);
902 priv->has_secondary_text = FALSE;
903 gtk_widget_hide (priv->secondary_label);
906 setup_primary_label_font (message_dialog);
910 * gtk_message_dialog_get_message_area:
911 * @message_dialog: a #GtkMessageDialog
913 * Returns the message area of the dialog. This is the box where the
914 * dialog's primary and secondary labels are packed. You can add your
915 * own extra content to that box and it will appear below those labels,
916 * on the right side of the dialog's image (or on the left for right-to-left
917 * languages). See gtk_dialog_get_content_area() for the corresponding
918 * function in the parent #GtkDialog.
920 * Return value: (transfer none): A #GtkVBox corresponding to the
921 * "message area" in the @message_dialog.
926 gtk_message_dialog_get_message_area (GtkMessageDialog *message_dialog)
928 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog), NULL);
930 return message_dialog->priv->message_area;
934 gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
935 GtkButtonsType buttons)
937 GtkDialog* dialog = GTK_DIALOG (message_dialog);
941 case GTK_BUTTONS_NONE:
946 gtk_dialog_add_button (dialog,
951 case GTK_BUTTONS_CLOSE:
952 gtk_dialog_add_button (dialog,
957 case GTK_BUTTONS_CANCEL:
958 gtk_dialog_add_button (dialog,
960 GTK_RESPONSE_CANCEL);
963 case GTK_BUTTONS_YES_NO:
964 gtk_dialog_add_button (dialog,
967 gtk_dialog_add_button (dialog,
970 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
976 case GTK_BUTTONS_OK_CANCEL:
977 gtk_dialog_add_button (dialog,
979 GTK_RESPONSE_CANCEL);
980 gtk_dialog_add_button (dialog,
983 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
990 g_warning ("Unknown GtkButtonsType");
994 g_object_notify (G_OBJECT (message_dialog), "buttons");
998 gtk_message_dialog_style_updated (GtkWidget *widget)
1000 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget);
1004 parent = gtk_widget_get_parent (gtk_message_dialog_get_image (dialog));
1008 gtk_widget_style_get (widget, "message-border",
1009 &border_width, NULL);
1011 gtk_container_set_border_width (GTK_CONTAINER (parent),
1012 MAX (0, border_width - 7));
1015 GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_updated (widget);