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 struct _GtkMessageDialogPrivate
102 GtkWidget *message_area; /* vbox for the primary and secondary labels, and any extra content from the caller */
103 GtkWidget *secondary_label;
105 guint has_primary_markup : 1;
106 guint has_secondary_text : 1;
107 guint message_type : 3;
110 static void gtk_message_dialog_style_updated (GtkWidget *widget);
112 static void gtk_message_dialog_set_property (GObject *object,
116 static void gtk_message_dialog_get_property (GObject *object,
120 static void gtk_message_dialog_add_buttons (GtkMessageDialog *message_dialog,
121 GtkButtonsType buttons);
122 static void gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface);
123 static GObject * gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
125 const gchar *childname);
135 PROP_SECONDARY_USE_MARKUP,
140 G_DEFINE_TYPE_WITH_CODE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG,
141 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
142 gtk_message_dialog_buildable_interface_init))
144 static GtkBuildableIface *parent_buildable_iface;
147 gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface)
149 parent_buildable_iface = g_type_interface_peek_parent (iface);
150 iface->get_internal_child = gtk_message_dialog_buildable_get_internal_child;
151 iface->custom_tag_start = parent_buildable_iface->custom_tag_start;
152 iface->custom_finished = parent_buildable_iface->custom_finished;
156 gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
158 const gchar *childname)
160 if (strcmp (childname, "message_area") == 0)
161 return G_OBJECT (gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (buildable)));
163 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
168 gtk_message_dialog_class_init (GtkMessageDialogClass *class)
170 GtkWidgetClass *widget_class;
171 GObjectClass *gobject_class;
173 widget_class = GTK_WIDGET_CLASS (class);
174 gobject_class = G_OBJECT_CLASS (class);
176 widget_class->style_updated = gtk_message_dialog_style_updated;
178 gobject_class->set_property = gtk_message_dialog_set_property;
179 gobject_class->get_property = gtk_message_dialog_get_property;
181 gtk_widget_class_install_style_property (widget_class,
182 g_param_spec_int ("message-border",
183 P_("Image/label border"),
184 P_("Width of border around the label and image in the message dialog"),
188 GTK_PARAM_READABLE));
191 * GtkMessageDialog:message-type:
193 * The type of the message. The type is used to determine
194 * the image that is shown in the dialog, unless the image is
195 * explicitly set by the ::image property.
197 g_object_class_install_property (gobject_class,
199 g_param_spec_enum ("message-type",
201 P_("The type of message"),
202 GTK_TYPE_MESSAGE_TYPE,
204 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
205 g_object_class_install_property (gobject_class,
207 g_param_spec_enum ("buttons",
208 P_("Message Buttons"),
209 P_("The buttons shown in the message dialog"),
210 GTK_TYPE_BUTTONS_TYPE,
212 GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
215 * GtkMessageDialog:text:
217 * The primary text of the message dialog. If the dialog has
218 * a secondary text, this will appear as the title.
222 g_object_class_install_property (gobject_class,
224 g_param_spec_string ("text",
226 P_("The primary text of the message dialog"),
228 GTK_PARAM_READWRITE));
231 * GtkMessageDialog:use-markup:
233 * %TRUE if the primary text of the dialog includes Pango markup.
234 * See pango_parse_markup().
238 g_object_class_install_property (gobject_class,
240 g_param_spec_boolean ("use-markup",
242 P_("The primary text of the title includes Pango markup."),
244 GTK_PARAM_READWRITE));
247 * GtkMessageDialog:secondary-text:
249 * The secondary text of the message dialog.
253 g_object_class_install_property (gobject_class,
255 g_param_spec_string ("secondary-text",
256 P_("Secondary Text"),
257 P_("The secondary text of the message dialog"),
259 GTK_PARAM_READWRITE));
262 * GtkMessageDialog:secondary-use-markup:
264 * %TRUE if the secondary text of the dialog includes Pango markup.
265 * See pango_parse_markup().
269 g_object_class_install_property (gobject_class,
270 PROP_SECONDARY_USE_MARKUP,
271 g_param_spec_boolean ("secondary-use-markup",
272 P_("Use Markup in secondary"),
273 P_("The secondary text includes Pango markup."),
275 GTK_PARAM_READWRITE));
278 * GtkMessageDialog:image:
280 * The image for this dialog.
284 g_object_class_install_property (gobject_class,
286 g_param_spec_object ("image",
290 GTK_PARAM_READWRITE));
293 * GtkMessageDialog:message-area
295 * The #GtkVBox that corresponds to the message area of this dialog. See
296 * gtk_message_dialog_get_message_area() for a detailed description of this
301 g_object_class_install_property (gobject_class,
303 g_param_spec_object ("message-area",
305 P_("GtkVBox that holds the dialog's primary and secondary labels"),
307 GTK_PARAM_READABLE));
309 g_type_class_add_private (gobject_class, sizeof (GtkMessageDialogPrivate));
313 gtk_message_dialog_init (GtkMessageDialog *dialog)
316 GtkDialog *message_dialog = GTK_DIALOG (dialog);
317 GtkWidget *action_area, *content_area;
318 GtkMessageDialogPrivate *priv;
320 dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
321 GTK_TYPE_MESSAGE_DIALOG,
322 GtkMessageDialogPrivate);
325 content_area = gtk_dialog_get_content_area (message_dialog);
326 action_area = gtk_dialog_get_action_area (message_dialog);
328 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
329 gtk_window_set_title (GTK_WINDOW (dialog), "");
330 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
332 priv->has_primary_markup = FALSE;
333 priv->has_secondary_text = FALSE;
334 priv->secondary_label = gtk_label_new (NULL);
335 gtk_widget_set_no_show_all (priv->secondary_label, TRUE);
337 priv->label = gtk_label_new (NULL);
338 priv->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
339 gtk_misc_set_alignment (GTK_MISC (priv->image), 0.5, 0.0);
341 gtk_label_set_line_wrap (GTK_LABEL (priv->label), TRUE);
342 gtk_label_set_selectable (GTK_LABEL (priv->label), TRUE);
343 gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.0);
345 gtk_label_set_line_wrap (GTK_LABEL (priv->secondary_label), TRUE);
346 gtk_label_set_selectable (GTK_LABEL (priv->secondary_label), TRUE);
347 gtk_misc_set_alignment (GTK_MISC (priv->secondary_label), 0.0, 0.0);
349 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
350 priv->message_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
352 gtk_box_pack_start (GTK_BOX (priv->message_area), priv->label,
355 gtk_box_pack_start (GTK_BOX (priv->message_area), priv->secondary_label,
358 gtk_box_pack_start (GTK_BOX (hbox), priv->image,
361 gtk_box_pack_start (GTK_BOX (hbox), priv->message_area,
364 gtk_box_pack_start (GTK_BOX (content_area),
368 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
369 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
370 gtk_box_set_spacing (GTK_BOX (content_area), 14); /* 14 + 2 * 5 = 24 */
371 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
372 gtk_box_set_spacing (GTK_BOX (action_area), 6);
374 gtk_widget_show_all (hbox);
378 setup_primary_label_font (GtkMessageDialog *dialog)
380 GtkMessageDialogPrivate *priv = dialog->priv;
382 PangoFontDescription *font_desc;
383 GtkStyleContext *context;
386 /* unset the font settings */
387 gtk_widget_modify_font (priv->label, NULL);
389 if (priv->has_secondary_text && !priv->has_primary_markup)
391 context = gtk_widget_get_style_context (priv->label);
392 state = gtk_widget_get_state_flags (priv->label);
394 size = pango_font_description_get_size (gtk_style_context_get_font (context, state));
395 font_desc = pango_font_description_new ();
396 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
397 pango_font_description_set_size (font_desc, size * PANGO_SCALE_LARGE);
398 gtk_widget_modify_font (priv->label, font_desc);
399 pango_font_description_free (font_desc);
404 setup_type (GtkMessageDialog *dialog,
407 GtkMessageDialogPrivate *priv = dialog->priv;
408 const gchar *stock_id = NULL;
411 priv->message_type = type;
415 case GTK_MESSAGE_INFO:
416 stock_id = GTK_STOCK_DIALOG_INFO;
419 case GTK_MESSAGE_QUESTION:
420 stock_id = GTK_STOCK_DIALOG_QUESTION;
423 case GTK_MESSAGE_WARNING:
424 stock_id = GTK_STOCK_DIALOG_WARNING;
427 case GTK_MESSAGE_ERROR:
428 stock_id = GTK_STOCK_DIALOG_ERROR;
431 case GTK_MESSAGE_OTHER:
435 g_warning ("Unknown GtkMessageType %u", type);
440 gtk_image_set_from_stock (GTK_IMAGE (priv->image), stock_id,
441 GTK_ICON_SIZE_DIALOG);
443 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (dialog));
444 if (GTK_IS_ACCESSIBLE (atk_obj))
446 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
451 gtk_stock_lookup (stock_id, &item);
452 atk_object_set_name (atk_obj, item.label);
458 gtk_message_dialog_set_property (GObject *object,
463 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
464 GtkMessageDialogPrivate *priv = dialog->priv;
468 case PROP_MESSAGE_TYPE:
469 setup_type (dialog, g_value_get_enum (value));
472 gtk_message_dialog_add_buttons (dialog, g_value_get_enum (value));
475 if (priv->has_primary_markup)
476 gtk_label_set_markup (GTK_LABEL (priv->label),
477 g_value_get_string (value));
479 gtk_label_set_text (GTK_LABEL (priv->label),
480 g_value_get_string (value));
482 case PROP_USE_MARKUP:
483 priv->has_primary_markup = g_value_get_boolean (value) != FALSE;
484 gtk_label_set_use_markup (GTK_LABEL (priv->label),
485 priv->has_primary_markup);
486 setup_primary_label_font (dialog);
488 case PROP_SECONDARY_TEXT:
490 const gchar *txt = g_value_get_string (value);
492 if (gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)))
493 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), txt);
495 gtk_label_set_text (GTK_LABEL (priv->secondary_label), txt);
499 priv->has_secondary_text = TRUE;
500 gtk_widget_show (priv->secondary_label);
504 priv->has_secondary_text = FALSE;
505 gtk_widget_hide (priv->secondary_label);
507 setup_primary_label_font (dialog);
510 case PROP_SECONDARY_USE_MARKUP:
511 gtk_label_set_use_markup (GTK_LABEL (priv->secondary_label),
512 g_value_get_boolean (value));
515 gtk_message_dialog_set_image (dialog, g_value_get_object (value));
519 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
525 gtk_message_dialog_get_property (GObject *object,
530 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
531 GtkMessageDialogPrivate *priv = dialog->priv;
535 case PROP_MESSAGE_TYPE:
536 g_value_set_enum (value, (GtkMessageType) priv->message_type);
539 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (priv->label)));
541 case PROP_USE_MARKUP:
542 g_value_set_boolean (value, priv->has_primary_markup);
544 case PROP_SECONDARY_TEXT:
545 if (priv->has_secondary_text)
546 g_value_set_string (value,
547 gtk_label_get_label (GTK_LABEL (priv->secondary_label)));
549 g_value_set_string (value, NULL);
551 case PROP_SECONDARY_USE_MARKUP:
552 if (priv->has_secondary_text)
553 g_value_set_boolean (value,
554 gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)));
556 g_value_set_boolean (value, FALSE);
559 g_value_set_object (value, priv->image);
561 case PROP_MESSAGE_AREA:
562 g_value_set_object (value, priv->message_area);
565 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
571 * gtk_message_dialog_new:
572 * @parent: (allow-none): transient parent, or %NULL for none
574 * @type: type of message
575 * @buttons: set of buttons to use
576 * @message_format: (allow-none): printf()-style format string, or %NULL
577 * @Varargs: arguments for @message_format
579 * Creates a new message dialog, which is a simple dialog with an icon
580 * indicating the dialog type (error, warning, etc.) and some text the
581 * user may want to see. When the user clicks a button a "response"
582 * signal is emitted with response IDs from #GtkResponseType. See
583 * #GtkDialog for more details.
585 * Return value: (transfer none): a new #GtkMessageDialog
588 gtk_message_dialog_new (GtkWindow *parent,
589 GtkDialogFlags flags,
591 GtkButtonsType buttons,
592 const gchar *message_format,
600 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
602 widget = g_object_new (GTK_TYPE_MESSAGE_DIALOG,
603 "message-type", type,
606 dialog = GTK_DIALOG (widget);
610 va_start (args, message_format);
611 msg = g_strdup_vprintf (message_format, args);
614 gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (widget)->priv->label),
621 gtk_window_set_transient_for (GTK_WINDOW (widget),
622 GTK_WINDOW (parent));
624 if (flags & GTK_DIALOG_MODAL)
625 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
627 if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
628 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
634 * gtk_message_dialog_new_with_markup:
635 * @parent: (allow-none): transient parent, or %NULL for none
637 * @type: type of message
638 * @buttons: set of buttons to use
639 * @message_format: (allow-none): printf()-style format string, or %NULL
640 * @Varargs: arguments for @message_format
642 * Creates a new message dialog, which is a simple dialog with an icon
643 * indicating the dialog type (error, warning, etc.) and some text which
644 * is marked up with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
645 * When the user clicks a button a "response" signal is emitted with
646 * response IDs from #GtkResponseType. See #GtkDialog for more details.
648 * Special XML characters in the printf() arguments passed to this
649 * function will automatically be escaped as necessary.
650 * (See g_markup_printf_escaped() for how this is implemented.)
651 * Usually this is what you want, but if you have an existing
652 * Pango markup string that you want to use literally as the
653 * label, then you need to use gtk_message_dialog_set_markup()
654 * instead, since you can't pass the markup string either
655 * as the format (it might contain '%' characters) or as a string
659 * dialog = gtk_message_dialog_new (main_application_window,
660 * GTK_DIALOG_DESTROY_WITH_PARENT,
664 * gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
668 * Return value: a new #GtkMessageDialog
673 gtk_message_dialog_new_with_markup (GtkWindow *parent,
674 GtkDialogFlags flags,
676 GtkButtonsType buttons,
677 const gchar *message_format,
684 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
686 widget = gtk_message_dialog_new (parent, flags, type, buttons, NULL);
690 va_start (args, message_format);
691 msg = g_markup_vprintf_escaped (message_format, args);
694 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (widget), msg);
703 * gtk_message_dialog_set_image:
704 * @dialog: a #GtkMessageDialog
707 * Sets the dialog's image to @image.
712 gtk_message_dialog_set_image (GtkMessageDialog *dialog,
715 GtkMessageDialogPrivate *priv;
718 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (dialog));
719 g_return_if_fail (image == NULL || GTK_IS_WIDGET (image));
725 image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
726 gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
729 priv->message_type = GTK_MESSAGE_OTHER;
731 parent = gtk_widget_get_parent (priv->image);
732 gtk_container_add (GTK_CONTAINER (parent), image);
733 gtk_container_remove (GTK_CONTAINER (parent), priv->image);
734 gtk_box_reorder_child (GTK_BOX (parent), image, 0);
738 g_object_notify (G_OBJECT (dialog), "image");
742 * gtk_message_dialog_get_image:
743 * @dialog: a #GtkMessageDialog
745 * Gets the dialog's image.
747 * Return value: (transfer none): the dialog's image
752 gtk_message_dialog_get_image (GtkMessageDialog *dialog)
754 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (dialog), NULL);
756 return dialog->priv->image;
760 * gtk_message_dialog_set_markup:
761 * @message_dialog: a #GtkMessageDialog
762 * @str: markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>)
764 * Sets the text of the message dialog to be @str, which is marked
765 * up with the <link linkend="PangoMarkupFormat">Pango text markup
771 gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
774 GtkMessageDialogPrivate *priv;
776 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
778 priv = message_dialog->priv;
780 priv->has_primary_markup = TRUE;
781 gtk_label_set_markup (GTK_LABEL (priv->label), str);
785 * gtk_message_dialog_format_secondary_text:
786 * @message_dialog: a #GtkMessageDialog
787 * @message_format: (allow-none): printf()-style format string, or %NULL
788 * @Varargs: arguments for @message_format
790 * Sets the secondary text of the message dialog to be @message_format
791 * (with printf()-style).
793 * Note that setting a secondary text makes the primary text become
794 * bold, unless you have provided explicit markup.
799 gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog,
800 const gchar *message_format,
805 GtkMessageDialogPrivate *priv;
807 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
809 priv = message_dialog->priv;
813 priv->has_secondary_text = TRUE;
815 va_start (args, message_format);
816 msg = g_strdup_vprintf (message_format, args);
819 gtk_widget_show (priv->secondary_label);
820 gtk_label_set_text (GTK_LABEL (priv->secondary_label), msg);
826 priv->has_secondary_text = FALSE;
827 gtk_widget_hide (priv->secondary_label);
830 setup_primary_label_font (message_dialog);
834 * gtk_message_dialog_format_secondary_markup:
835 * @message_dialog: a #GtkMessageDialog
836 * @message_format: printf()-style markup string (see
837 <link linkend="PangoMarkupFormat">Pango markup format</link>), or %NULL
838 * @Varargs: arguments for @message_format
840 * Sets the secondary text of the message dialog to be @message_format (with
841 * printf()-style), which is marked up with the
842 * <link linkend="PangoMarkupFormat">Pango text markup language</link>.
844 * Note that setting a secondary text makes the primary text become
845 * bold, unless you have provided explicit markup.
847 * Due to an oversight, this function does not escape special XML characters
848 * like gtk_message_dialog_new_with_markup() does. Thus, if the arguments
849 * may contain special XML characters, you should use g_markup_printf_escaped()
852 * <informalexample><programlisting>
855 * msg = g_markup_printf_escaped (message_format, ...);
856 * gtk_message_dialog_format_secondary_markup (message_dialog, "%s", msg);
858 * </programlisting></informalexample>
863 gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
864 const gchar *message_format,
869 GtkMessageDialogPrivate *priv;
871 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
873 priv = message_dialog->priv;
877 priv->has_secondary_text = TRUE;
879 va_start (args, message_format);
880 msg = g_strdup_vprintf (message_format, args);
883 gtk_widget_show (priv->secondary_label);
884 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), msg);
890 priv->has_secondary_text = FALSE;
891 gtk_widget_hide (priv->secondary_label);
894 setup_primary_label_font (message_dialog);
898 * gtk_message_dialog_get_message_area:
899 * @message_dialog: a #GtkMessageDialog
901 * Returns the message area of the dialog. This is the box where the
902 * dialog's primary and secondary labels are packed. You can add your
903 * own extra content to that box and it will appear below those labels,
904 * on the right side of the dialog's image (or on the left for right-to-left
905 * languages). See gtk_dialog_get_content_area() for the corresponding
906 * function in the parent #GtkDialog.
908 * Return value: (transfer none): A #GtkVBox corresponding to the
909 * "message area" in the @message_dialog.
914 gtk_message_dialog_get_message_area (GtkMessageDialog *message_dialog)
916 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog), NULL);
918 return message_dialog->priv->message_area;
922 gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
923 GtkButtonsType buttons)
925 GtkDialog* dialog = GTK_DIALOG (message_dialog);
929 case GTK_BUTTONS_NONE:
934 gtk_dialog_add_button (dialog,
939 case GTK_BUTTONS_CLOSE:
940 gtk_dialog_add_button (dialog,
945 case GTK_BUTTONS_CANCEL:
946 gtk_dialog_add_button (dialog,
948 GTK_RESPONSE_CANCEL);
951 case GTK_BUTTONS_YES_NO:
952 gtk_dialog_add_button (dialog,
955 gtk_dialog_add_button (dialog,
958 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
964 case GTK_BUTTONS_OK_CANCEL:
965 gtk_dialog_add_button (dialog,
967 GTK_RESPONSE_CANCEL);
968 gtk_dialog_add_button (dialog,
971 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
978 g_warning ("Unknown GtkButtonsType");
982 g_object_notify (G_OBJECT (message_dialog), "buttons");
986 gtk_message_dialog_style_updated (GtkWidget *widget)
988 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget);
992 parent = gtk_widget_get_parent (gtk_message_dialog_get_image (dialog));
996 gtk_widget_style_get (widget, "message-border",
997 &border_width, NULL);
999 gtk_container_set_border_width (GTK_CONTAINER (parent),
1000 MAX (0, border_width - 7));
1003 setup_primary_label_font (dialog);
1005 GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_updated (widget);