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/.
31 #include "gtkmessagedialog.h"
32 #include "gtkaccessible.h"
33 #include "gtkbuildable.h"
39 #include "gtkiconfactory.h"
41 #include "gtkprivate.h"
44 * SECTION:gtkmessagedialog
45 * @Short_description: A convenient message window
46 * @Title: GtkMessageDialog
47 * @See_also:#GtkDialog
49 * #GtkMessageDialog presents a dialog with an image representing the type of
50 * message (Error, Question, etc.) alongside some message text. It's simply a
51 * convenience widget; you could construct the equivalent of #GtkMessageDialog
52 * from #GtkDialog without too much effort, but #GtkMessageDialog saves typing.
54 * The easiest way to do a modal message dialog is to use gtk_dialog_run(), though
55 * you can also pass in the %GTK_DIALOG_MODAL flag, gtk_dialog_run() automatically
56 * makes the dialog modal and waits for the user to respond to it. gtk_dialog_run()
57 * returns when any dialog button is clicked.
59 * <title>A modal dialog.</title>
61 * dialog = gtk_message_dialog_new (main_application_window,
62 * GTK_DIALOG_DESTROY_WITH_PARENT,
65 * "Error loading file '%s': %s",
66 * filename, g_strerror (errno));
67 * gtk_dialog_run (GTK_DIALOG (dialog));
68 * gtk_widget_destroy (dialog);
71 * You might do a non-modal #GtkMessageDialog as follows:
73 * <title>A non-modal dialog.</title>
75 * dialog = gtk_message_dialog_new (main_application_window,
76 * GTK_DIALOG_DESTROY_WITH_PARENT,
79 * "Error loading file '%s': %s",
80 * filename, g_strerror (errno));
82 * /* Destroy the dialog when the user responds to it (e.g. clicks a button) */
83 * g_signal_connect_swapped (dialog, "response",
84 * G_CALLBACK (gtk_widget_destroy),
89 * <refsect2 id="GtkMessageDialog-BUILDER-UI">
90 * <title>GtkMessageDialog as GtkBuildable</title>
92 * The GtkMessageDialog implementation of the GtkBuildable interface exposes
93 * the message area as an internal child with the name "message_area".
98 #define GTK_MESSAGE_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_MESSAGE_DIALOG, GtkMessageDialogPrivate))
100 typedef struct _GtkMessageDialogPrivate GtkMessageDialogPrivate;
102 struct _GtkMessageDialogPrivate
104 GtkWidget *message_area; /* vbox for the primary and secondary labels, and any extra content from the caller */
105 GtkWidget *secondary_label;
106 guint message_type : 3;
107 guint has_primary_markup : 1;
108 guint has_secondary_text : 1;
111 static void gtk_message_dialog_style_set (GtkWidget *widget,
112 GtkStyle *prev_style);
114 static void gtk_message_dialog_set_property (GObject *object,
118 static void gtk_message_dialog_get_property (GObject *object,
122 static void gtk_message_dialog_add_buttons (GtkMessageDialog *message_dialog,
123 GtkButtonsType buttons);
124 static void gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface);
125 static GObject * gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
127 const gchar *childname);
137 PROP_SECONDARY_USE_MARKUP,
142 G_DEFINE_TYPE_WITH_CODE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG,
143 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
144 gtk_message_dialog_buildable_interface_init))
146 static GtkBuildableIface *parent_buildable_iface;
149 gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface)
151 parent_buildable_iface = g_type_interface_peek_parent (iface);
152 iface->get_internal_child = gtk_message_dialog_buildable_get_internal_child;
153 iface->custom_tag_start = parent_buildable_iface->custom_tag_start;
154 iface->custom_finished = parent_buildable_iface->custom_finished;
158 gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
160 const gchar *childname)
162 if (strcmp (childname, "message_area") == 0)
163 return G_OBJECT (gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (buildable)));
165 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
170 gtk_message_dialog_class_init (GtkMessageDialogClass *class)
172 GtkWidgetClass *widget_class;
173 GObjectClass *gobject_class;
175 widget_class = GTK_WIDGET_CLASS (class);
176 gobject_class = G_OBJECT_CLASS (class);
178 widget_class->style_set = gtk_message_dialog_style_set;
180 gobject_class->set_property = gtk_message_dialog_set_property;
181 gobject_class->get_property = gtk_message_dialog_get_property;
183 gtk_widget_class_install_style_property (widget_class,
184 g_param_spec_int ("message-border",
185 P_("Image/label border"),
186 P_("Width of border around the label and image in the message dialog"),
190 GTK_PARAM_READABLE));
192 * GtkMessageDialog:use-separator:
194 * Whether to draw a separator line between the message label and the buttons
199 gtk_widget_class_install_style_property (widget_class,
200 g_param_spec_boolean ("use-separator",
202 P_("Whether to put a separator between the message dialog's text and the buttons"),
204 GTK_PARAM_READABLE));
206 * GtkMessageDialog:message-type:
208 * The type of the message. The type is used to determine
209 * the image that is shown in the dialog, unless the image is
210 * explicitly set by the ::image property.
212 g_object_class_install_property (gobject_class,
214 g_param_spec_enum ("message-type",
216 P_("The type of message"),
217 GTK_TYPE_MESSAGE_TYPE,
219 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
220 g_object_class_install_property (gobject_class,
222 g_param_spec_enum ("buttons",
223 P_("Message Buttons"),
224 P_("The buttons shown in the message dialog"),
225 GTK_TYPE_BUTTONS_TYPE,
227 GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
230 * GtkMessageDialog:text:
232 * The primary text of the message dialog. If the dialog has
233 * a secondary text, this will appear as the title.
237 g_object_class_install_property (gobject_class,
239 g_param_spec_string ("text",
241 P_("The primary text of the message dialog"),
243 GTK_PARAM_READWRITE));
246 * GtkMessageDialog:use-markup:
248 * %TRUE if the primary text of the dialog includes Pango markup.
249 * See pango_parse_markup().
253 g_object_class_install_property (gobject_class,
255 g_param_spec_boolean ("use-markup",
257 P_("The primary text of the title includes Pango markup."),
259 GTK_PARAM_READWRITE));
262 * GtkMessageDialog:secondary-text:
264 * The secondary text of the message dialog.
268 g_object_class_install_property (gobject_class,
270 g_param_spec_string ("secondary-text",
271 P_("Secondary Text"),
272 P_("The secondary text of the message dialog"),
274 GTK_PARAM_READWRITE));
277 * GtkMessageDialog:secondary-use-markup:
279 * %TRUE if the secondary text of the dialog includes Pango markup.
280 * See pango_parse_markup().
284 g_object_class_install_property (gobject_class,
285 PROP_SECONDARY_USE_MARKUP,
286 g_param_spec_boolean ("secondary-use-markup",
287 P_("Use Markup in secondary"),
288 P_("The secondary text includes Pango markup."),
290 GTK_PARAM_READWRITE));
293 * GtkMessageDialog:image:
295 * The image for this dialog.
299 g_object_class_install_property (gobject_class,
301 g_param_spec_object ("image",
305 GTK_PARAM_READWRITE));
308 * GtkMessageDialog:message-area
310 * The #GtkVBox that corresponds to the message area of this dialog. See
311 * gtk_message_dialog_get_message_area() for a detailed description of this
316 g_object_class_install_property (gobject_class,
318 g_param_spec_object ("message-area",
320 P_("GtkVBox that holds the dialog's primary and secondary labels"),
322 GTK_PARAM_READABLE));
324 g_type_class_add_private (gobject_class,
325 sizeof (GtkMessageDialogPrivate));
329 gtk_message_dialog_init (GtkMessageDialog *dialog)
332 GtkDialog *message_dialog = GTK_DIALOG (dialog);
333 GtkWidget *action_area, *content_area;
334 GtkMessageDialogPrivate *priv;
336 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
338 content_area = gtk_dialog_get_content_area (message_dialog);
339 action_area = gtk_dialog_get_action_area (message_dialog);
341 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
342 gtk_window_set_title (GTK_WINDOW (dialog), "");
343 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
345 priv->has_primary_markup = FALSE;
346 priv->has_secondary_text = FALSE;
347 priv->secondary_label = gtk_label_new (NULL);
348 gtk_widget_set_no_show_all (priv->secondary_label, TRUE);
350 dialog->label = gtk_label_new (NULL);
351 dialog->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
352 gtk_misc_set_alignment (GTK_MISC (dialog->image), 0.5, 0.0);
354 gtk_label_set_line_wrap (GTK_LABEL (dialog->label), TRUE);
355 gtk_label_set_selectable (GTK_LABEL (dialog->label), TRUE);
356 gtk_misc_set_alignment (GTK_MISC (dialog->label), 0.0, 0.0);
358 gtk_label_set_line_wrap (GTK_LABEL (priv->secondary_label), TRUE);
359 gtk_label_set_selectable (GTK_LABEL (priv->secondary_label), TRUE);
360 gtk_misc_set_alignment (GTK_MISC (priv->secondary_label), 0.0, 0.0);
362 hbox = gtk_hbox_new (FALSE, 12);
363 priv->message_area = gtk_vbox_new (FALSE, 12);
365 gtk_box_pack_start (GTK_BOX (priv->message_area), dialog->label,
368 gtk_box_pack_start (GTK_BOX (priv->message_area), priv->secondary_label,
371 gtk_box_pack_start (GTK_BOX (hbox), dialog->image,
374 gtk_box_pack_start (GTK_BOX (hbox), priv->message_area,
377 gtk_box_pack_start (GTK_BOX (content_area),
381 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
382 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
383 gtk_box_set_spacing (GTK_BOX (content_area), 14); /* 14 + 2 * 5 = 24 */
384 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
385 gtk_box_set_spacing (GTK_BOX (action_area), 6);
387 gtk_widget_show_all (hbox);
389 _gtk_dialog_set_ignore_separator (GTK_DIALOG (dialog), TRUE);
393 setup_primary_label_font (GtkMessageDialog *dialog)
396 PangoFontDescription *font_desc;
397 GtkMessageDialogPrivate *priv;
399 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
401 /* unset the font settings */
402 gtk_widget_modify_font (dialog->label, NULL);
404 if (priv->has_secondary_text && !priv->has_primary_markup)
406 size = pango_font_description_get_size (dialog->label->style->font_desc);
407 font_desc = pango_font_description_new ();
408 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
409 pango_font_description_set_size (font_desc, size * PANGO_SCALE_LARGE);
410 gtk_widget_modify_font (dialog->label, font_desc);
411 pango_font_description_free (font_desc);
416 setup_type (GtkMessageDialog *dialog,
419 GtkMessageDialogPrivate *priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
420 const gchar *stock_id = NULL;
423 priv->message_type = type;
427 case GTK_MESSAGE_INFO:
428 stock_id = GTK_STOCK_DIALOG_INFO;
431 case GTK_MESSAGE_QUESTION:
432 stock_id = GTK_STOCK_DIALOG_QUESTION;
435 case GTK_MESSAGE_WARNING:
436 stock_id = GTK_STOCK_DIALOG_WARNING;
439 case GTK_MESSAGE_ERROR:
440 stock_id = GTK_STOCK_DIALOG_ERROR;
443 case GTK_MESSAGE_OTHER:
447 g_warning ("Unknown GtkMessageType %u", type);
452 gtk_image_set_from_stock (GTK_IMAGE (dialog->image), stock_id,
453 GTK_ICON_SIZE_DIALOG);
455 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (dialog));
456 if (GTK_IS_ACCESSIBLE (atk_obj))
458 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
463 gtk_stock_lookup (stock_id, &item);
464 atk_object_set_name (atk_obj, item.label);
470 gtk_message_dialog_set_property (GObject *object,
475 GtkMessageDialog *dialog;
476 GtkMessageDialogPrivate *priv;
478 dialog = GTK_MESSAGE_DIALOG (object);
479 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
483 case PROP_MESSAGE_TYPE:
484 setup_type (dialog, g_value_get_enum (value));
487 gtk_message_dialog_add_buttons (dialog, g_value_get_enum (value));
490 if (priv->has_primary_markup)
491 gtk_label_set_markup (GTK_LABEL (dialog->label),
492 g_value_get_string (value));
494 gtk_label_set_text (GTK_LABEL (dialog->label),
495 g_value_get_string (value));
497 case PROP_USE_MARKUP:
498 priv->has_primary_markup = g_value_get_boolean (value) != FALSE;
499 gtk_label_set_use_markup (GTK_LABEL (dialog->label),
500 priv->has_primary_markup);
501 setup_primary_label_font (dialog);
503 case PROP_SECONDARY_TEXT:
505 const gchar *txt = g_value_get_string (value);
507 if (gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)))
508 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), txt);
510 gtk_label_set_text (GTK_LABEL (priv->secondary_label), txt);
514 priv->has_secondary_text = TRUE;
515 gtk_widget_show (priv->secondary_label);
519 priv->has_secondary_text = FALSE;
520 gtk_widget_hide (priv->secondary_label);
522 setup_primary_label_font (dialog);
525 case PROP_SECONDARY_USE_MARKUP:
526 gtk_label_set_use_markup (GTK_LABEL (priv->secondary_label),
527 g_value_get_boolean (value));
530 gtk_message_dialog_set_image (dialog, g_value_get_object (value));
534 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
540 gtk_message_dialog_get_property (GObject *object,
545 GtkMessageDialog *dialog;
546 GtkMessageDialogPrivate *priv;
548 dialog = GTK_MESSAGE_DIALOG (object);
549 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
553 case PROP_MESSAGE_TYPE:
554 g_value_set_enum (value, (GtkMessageType) priv->message_type);
557 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (dialog->label)));
559 case PROP_USE_MARKUP:
560 g_value_set_boolean (value, priv->has_primary_markup);
562 case PROP_SECONDARY_TEXT:
563 if (priv->has_secondary_text)
564 g_value_set_string (value,
565 gtk_label_get_label (GTK_LABEL (priv->secondary_label)));
567 g_value_set_string (value, NULL);
569 case PROP_SECONDARY_USE_MARKUP:
570 if (priv->has_secondary_text)
571 g_value_set_boolean (value,
572 gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)));
574 g_value_set_boolean (value, FALSE);
577 g_value_set_object (value, dialog->image);
579 case PROP_MESSAGE_AREA:
580 g_value_set_object (value, priv->message_area);
583 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
589 * gtk_message_dialog_new:
590 * @parent: (allow-none): transient parent, or %NULL for none
592 * @type: type of message
593 * @buttons: set of buttons to use
594 * @message_format: (allow-none): printf()-style format string, or %NULL
595 * @Varargs: arguments for @message_format
597 * Creates a new message dialog, which is a simple dialog with an icon
598 * indicating the dialog type (error, warning, etc.) and some text the
599 * user may want to see. When the user clicks a button a "response"
600 * signal is emitted with response IDs from #GtkResponseType. See
601 * #GtkDialog for more details.
603 * Return value: (transfer none): a new #GtkMessageDialog
606 gtk_message_dialog_new (GtkWindow *parent,
607 GtkDialogFlags flags,
609 GtkButtonsType buttons,
610 const gchar *message_format,
618 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
620 widget = g_object_new (GTK_TYPE_MESSAGE_DIALOG,
621 "message-type", type,
624 dialog = GTK_DIALOG (widget);
626 if (flags & GTK_DIALOG_NO_SEPARATOR)
628 g_warning ("The GTK_DIALOG_NO_SEPARATOR flag cannot be used for GtkMessageDialog");
629 flags &= ~GTK_DIALOG_NO_SEPARATOR;
634 va_start (args, message_format);
635 msg = g_strdup_vprintf (message_format, args);
638 gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (widget)->label),
645 gtk_window_set_transient_for (GTK_WINDOW (widget),
646 GTK_WINDOW (parent));
648 if (flags & GTK_DIALOG_MODAL)
649 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
651 if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
652 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
658 * gtk_message_dialog_new_with_markup:
659 * @parent: (allow-none): transient parent, or %NULL for none
661 * @type: type of message
662 * @buttons: set of buttons to use
663 * @message_format: (allow-none): printf()-style format string, or %NULL
664 * @Varargs: arguments for @message_format
666 * Creates a new message dialog, which is a simple dialog with an icon
667 * indicating the dialog type (error, warning, etc.) and some text which
668 * is marked up with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
669 * When the user clicks a button a "response" signal is emitted with
670 * response IDs from #GtkResponseType. See #GtkDialog for more details.
672 * Special XML characters in the printf() arguments passed to this
673 * function will automatically be escaped as necessary.
674 * (See g_markup_printf_escaped() for how this is implemented.)
675 * Usually this is what you want, but if you have an existing
676 * Pango markup string that you want to use literally as the
677 * label, then you need to use gtk_message_dialog_set_markup()
678 * instead, since you can't pass the markup string either
679 * as the format (it might contain '%' characters) or as a string
683 * dialog = gtk_message_dialog_new (main_application_window,
684 * GTK_DIALOG_DESTROY_WITH_PARENT,
688 * gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
692 * Return value: a new #GtkMessageDialog
697 gtk_message_dialog_new_with_markup (GtkWindow *parent,
698 GtkDialogFlags flags,
700 GtkButtonsType buttons,
701 const gchar *message_format,
708 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
710 widget = gtk_message_dialog_new (parent, flags, type, buttons, NULL);
714 va_start (args, message_format);
715 msg = g_markup_vprintf_escaped (message_format, args);
718 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (widget), msg);
727 * gtk_message_dialog_set_image:
728 * @dialog: a #GtkMessageDialog
731 * Sets the dialog's image to @image.
736 gtk_message_dialog_set_image (GtkMessageDialog *dialog,
739 GtkMessageDialogPrivate *priv;
742 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (dialog));
743 g_return_if_fail (image == NULL || GTK_IS_WIDGET (image));
747 image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
748 gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
751 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
753 priv->message_type = GTK_MESSAGE_OTHER;
755 parent = dialog->image->parent;
756 gtk_container_add (GTK_CONTAINER (parent), image);
757 gtk_container_remove (GTK_CONTAINER (parent), dialog->image);
758 gtk_box_reorder_child (GTK_BOX (parent), image, 0);
760 dialog->image = image;
762 g_object_notify (G_OBJECT (dialog), "image");
766 * gtk_message_dialog_get_image:
767 * @dialog: a #GtkMessageDialog
769 * Gets the dialog's image.
771 * Return value: the dialog's image
776 gtk_message_dialog_get_image (GtkMessageDialog *dialog)
778 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (dialog), NULL);
780 return dialog->image;
784 * gtk_message_dialog_set_markup:
785 * @message_dialog: a #GtkMessageDialog
786 * @str: markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>)
788 * Sets the text of the message dialog to be @str, which is marked
789 * up with the <link linkend="PangoMarkupFormat">Pango text markup
795 gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
798 GtkMessageDialogPrivate *priv;
800 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
802 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog);
803 priv->has_primary_markup = TRUE;
804 gtk_label_set_markup (GTK_LABEL (message_dialog->label), str);
808 * gtk_message_dialog_format_secondary_text:
809 * @message_dialog: a #GtkMessageDialog
810 * @message_format: (allow-none): printf()-style format string, or %NULL
811 * @Varargs: arguments for @message_format
813 * Sets the secondary text of the message dialog to be @message_format
814 * (with printf()-style).
816 * Note that setting a secondary text makes the primary text become
817 * bold, unless you have provided explicit markup.
822 gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog,
823 const gchar *message_format,
828 GtkMessageDialogPrivate *priv;
830 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
832 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog);
836 priv->has_secondary_text = TRUE;
838 va_start (args, message_format);
839 msg = g_strdup_vprintf (message_format, args);
842 gtk_widget_show (priv->secondary_label);
843 gtk_label_set_text (GTK_LABEL (priv->secondary_label), msg);
849 priv->has_secondary_text = FALSE;
850 gtk_widget_hide (priv->secondary_label);
853 setup_primary_label_font (message_dialog);
857 * gtk_message_dialog_format_secondary_markup:
858 * @message_dialog: a #GtkMessageDialog
859 * @message_format: printf()-style markup string (see
860 <link linkend="PangoMarkupFormat">Pango markup format</link>), or %NULL
861 * @Varargs: arguments for @message_format
863 * Sets the secondary text of the message dialog to be @message_format (with
864 * printf()-style), which is marked up with the
865 * <link linkend="PangoMarkupFormat">Pango text markup language</link>.
867 * Note that setting a secondary text makes the primary text become
868 * bold, unless you have provided explicit markup.
870 * Due to an oversight, this function does not escape special XML characters
871 * like gtk_message_dialog_new_with_markup() does. Thus, if the arguments
872 * may contain special XML characters, you should use g_markup_printf_escaped()
875 * <informalexample><programlisting>
878 * msg = g_markup_printf_escaped (message_format, ...);
879 * gtk_message_dialog_format_secondary_markup (message_dialog, "%s", msg);
881 * </programlisting></informalexample>
886 gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
887 const gchar *message_format,
892 GtkMessageDialogPrivate *priv;
894 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
896 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog);
900 priv->has_secondary_text = TRUE;
902 va_start (args, message_format);
903 msg = g_strdup_vprintf (message_format, args);
906 gtk_widget_show (priv->secondary_label);
907 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), msg);
913 priv->has_secondary_text = FALSE;
914 gtk_widget_hide (priv->secondary_label);
917 setup_primary_label_font (message_dialog);
921 * gtk_message_dialog_get_message_area:
922 * @message_dialog: a #GtkMessageDialog
924 * Return value: A #GtkVBox corresponding to the "message area" in the
925 * @message_dialog. This is the box where the dialog's primary and secondary
926 * labels are packed. You can add your own extra content to that box and it
927 * will appear below those labels, on the right side of the dialog's image (or
928 * on the left for right-to-left languages). See gtk_dialog_get_content_area()
929 * for the corresponding function in the parent #GtkDialog.
934 gtk_message_dialog_get_message_area (GtkMessageDialog *message_dialog)
936 GtkMessageDialogPrivate *priv;
938 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog), NULL);
940 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog);
942 return priv->message_area;
946 gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
947 GtkButtonsType buttons)
949 GtkDialog* dialog = GTK_DIALOG (message_dialog);
953 case GTK_BUTTONS_NONE:
958 gtk_dialog_add_button (dialog,
963 case GTK_BUTTONS_CLOSE:
964 gtk_dialog_add_button (dialog,
969 case GTK_BUTTONS_CANCEL:
970 gtk_dialog_add_button (dialog,
972 GTK_RESPONSE_CANCEL);
975 case GTK_BUTTONS_YES_NO:
976 gtk_dialog_add_button (dialog,
979 gtk_dialog_add_button (dialog,
982 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
988 case GTK_BUTTONS_OK_CANCEL:
989 gtk_dialog_add_button (dialog,
991 GTK_RESPONSE_CANCEL);
992 gtk_dialog_add_button (dialog,
995 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
1002 g_warning ("Unknown GtkButtonsType");
1006 g_object_notify (G_OBJECT (message_dialog), "buttons");
1010 gtk_message_dialog_style_set (GtkWidget *widget,
1011 GtkStyle *prev_style)
1013 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget);
1014 gboolean use_separator;
1018 parent = GTK_WIDGET (GTK_MESSAGE_DIALOG (widget)->image->parent);
1022 gtk_widget_style_get (widget, "message-border",
1023 &border_width, NULL);
1025 gtk_container_set_border_width (GTK_CONTAINER (parent),
1026 MAX (0, border_width - 7));
1029 gtk_widget_style_get (widget,
1030 "use-separator", &use_separator,
1033 _gtk_dialog_set_ignore_separator (GTK_DIALOG (widget), FALSE);
1034 gtk_dialog_set_has_separator (GTK_DIALOG (widget), use_separator);
1035 _gtk_dialog_set_ignore_separator (GTK_DIALOG (widget), TRUE);
1037 setup_primary_label_font (dialog);
1039 GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_set (widget, prev_style);