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"
40 #include "gtkiconfactory.h"
42 #include "gtkprivate.h"
43 #include "gtktypebuiltins.h"
46 * SECTION:gtkmessagedialog
47 * @Short_description: A convenient message window
48 * @Title: GtkMessageDialog
49 * @See_also:#GtkDialog
51 * #GtkMessageDialog presents a dialog with an image representing the type of
52 * message (Error, Question, etc.) alongside some message text. It's simply a
53 * convenience widget; you could construct the equivalent of #GtkMessageDialog
54 * from #GtkDialog without too much effort, but #GtkMessageDialog saves typing.
56 * The easiest way to do a modal message dialog is to use gtk_dialog_run(), though
57 * you can also pass in the %GTK_DIALOG_MODAL flag, gtk_dialog_run() automatically
58 * makes the dialog modal and waits for the user to respond to it. gtk_dialog_run()
59 * returns when any dialog button is clicked.
61 * <title>A modal dialog.</title>
63 * dialog = gtk_message_dialog_new (main_application_window,
64 * GTK_DIALOG_DESTROY_WITH_PARENT,
67 * "Error loading file '%s': %s",
68 * filename, g_strerror (errno));
69 * gtk_dialog_run (GTK_DIALOG (dialog));
70 * gtk_widget_destroy (dialog);
73 * You might do a non-modal #GtkMessageDialog as follows:
75 * <title>A non-modal dialog.</title>
77 * dialog = gtk_message_dialog_new (main_application_window,
78 * GTK_DIALOG_DESTROY_WITH_PARENT,
81 * "Error loading file '%s': %s",
82 * filename, g_strerror (errno));
84 * /* Destroy the dialog when the user responds to it (e.g. clicks a button) */
85 * g_signal_connect_swapped (dialog, "response",
86 * G_CALLBACK (gtk_widget_destroy),
91 * <refsect2 id="GtkMessageDialog-BUILDER-UI">
92 * <title>GtkMessageDialog as GtkBuildable</title>
94 * The GtkMessageDialog implementation of the GtkBuildable interface exposes
95 * the message area as an internal child with the name "message_area".
100 struct _GtkMessageDialogPrivate
104 GtkWidget *message_area; /* vbox for the primary and secondary labels, and any extra content from the caller */
105 GtkWidget *secondary_label;
107 guint has_primary_markup : 1;
108 guint has_secondary_text : 1;
109 guint message_type : 3;
112 static void gtk_message_dialog_style_updated (GtkWidget *widget);
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_updated = gtk_message_dialog_style_updated;
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));
193 * GtkMessageDialog:message-type:
195 * The type of the message. The type is used to determine
196 * the image that is shown in the dialog, unless the image is
197 * explicitly set by the ::image property.
199 g_object_class_install_property (gobject_class,
201 g_param_spec_enum ("message-type",
203 P_("The type of message"),
204 GTK_TYPE_MESSAGE_TYPE,
206 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
207 g_object_class_install_property (gobject_class,
209 g_param_spec_enum ("buttons",
210 P_("Message Buttons"),
211 P_("The buttons shown in the message dialog"),
212 GTK_TYPE_BUTTONS_TYPE,
214 GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
217 * GtkMessageDialog:text:
219 * The primary text of the message dialog. If the dialog has
220 * a secondary text, this will appear as the title.
224 g_object_class_install_property (gobject_class,
226 g_param_spec_string ("text",
228 P_("The primary text of the message dialog"),
230 GTK_PARAM_READWRITE));
233 * GtkMessageDialog:use-markup:
235 * %TRUE if the primary text of the dialog includes Pango markup.
236 * See pango_parse_markup().
240 g_object_class_install_property (gobject_class,
242 g_param_spec_boolean ("use-markup",
244 P_("The primary text of the title includes Pango markup."),
246 GTK_PARAM_READWRITE));
249 * GtkMessageDialog:secondary-text:
251 * The secondary text of the message dialog.
255 g_object_class_install_property (gobject_class,
257 g_param_spec_string ("secondary-text",
258 P_("Secondary Text"),
259 P_("The secondary text of the message dialog"),
261 GTK_PARAM_READWRITE));
264 * GtkMessageDialog:secondary-use-markup:
266 * %TRUE if the secondary text of the dialog includes Pango markup.
267 * See pango_parse_markup().
271 g_object_class_install_property (gobject_class,
272 PROP_SECONDARY_USE_MARKUP,
273 g_param_spec_boolean ("secondary-use-markup",
274 P_("Use Markup in secondary"),
275 P_("The secondary text includes Pango markup."),
277 GTK_PARAM_READWRITE));
280 * GtkMessageDialog:image:
282 * The image for this dialog.
286 g_object_class_install_property (gobject_class,
288 g_param_spec_object ("image",
292 GTK_PARAM_READWRITE));
295 * GtkMessageDialog:message-area
297 * The #GtkVBox that corresponds to the message area of this dialog. See
298 * gtk_message_dialog_get_message_area() for a detailed description of this
303 g_object_class_install_property (gobject_class,
305 g_param_spec_object ("message-area",
307 P_("GtkVBox that holds the dialog's primary and secondary labels"),
309 GTK_PARAM_READABLE));
311 g_type_class_add_private (gobject_class, sizeof (GtkMessageDialogPrivate));
315 gtk_message_dialog_init (GtkMessageDialog *dialog)
318 GtkDialog *message_dialog = GTK_DIALOG (dialog);
319 GtkWidget *action_area, *content_area;
320 GtkMessageDialogPrivate *priv;
322 dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
323 GTK_TYPE_MESSAGE_DIALOG,
324 GtkMessageDialogPrivate);
327 content_area = gtk_dialog_get_content_area (message_dialog);
328 action_area = gtk_dialog_get_action_area (message_dialog);
330 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
331 gtk_window_set_title (GTK_WINDOW (dialog), "");
332 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
334 priv->has_primary_markup = FALSE;
335 priv->has_secondary_text = FALSE;
336 priv->secondary_label = gtk_label_new (NULL);
337 gtk_widget_set_no_show_all (priv->secondary_label, TRUE);
339 priv->label = gtk_label_new (NULL);
340 priv->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
341 gtk_widget_set_halign (priv->image, GTK_ALIGN_CENTER);
342 gtk_widget_set_valign (priv->image, GTK_ALIGN_START);
344 gtk_label_set_line_wrap (GTK_LABEL (priv->label), TRUE);
345 gtk_label_set_selectable (GTK_LABEL (priv->label), TRUE);
346 gtk_widget_set_halign (priv->label, GTK_ALIGN_START);
347 gtk_widget_set_valign (priv->label, GTK_ALIGN_START);
349 gtk_label_set_line_wrap (GTK_LABEL (priv->secondary_label), TRUE);
350 gtk_label_set_selectable (GTK_LABEL (priv->secondary_label), TRUE);
351 gtk_widget_set_halign (priv->secondary_label, GTK_ALIGN_START);
352 gtk_widget_set_valign (priv->secondary_label, GTK_ALIGN_START);
354 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
355 priv->message_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
357 gtk_box_pack_start (GTK_BOX (priv->message_area), priv->label,
360 gtk_box_pack_start (GTK_BOX (priv->message_area), priv->secondary_label,
363 gtk_box_pack_start (GTK_BOX (hbox), priv->image,
366 gtk_box_pack_start (GTK_BOX (hbox), priv->message_area,
369 gtk_box_pack_start (GTK_BOX (content_area),
373 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
374 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
375 gtk_box_set_spacing (GTK_BOX (content_area), 14); /* 14 + 2 * 5 = 24 */
376 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
377 gtk_box_set_spacing (GTK_BOX (action_area), 6);
379 gtk_widget_show_all (hbox);
383 setup_primary_label_font (GtkMessageDialog *dialog)
385 GtkMessageDialogPrivate *priv = dialog->priv;
387 PangoFontDescription *font_desc;
388 GtkStyleContext *context;
391 /* unset the font settings */
392 gtk_widget_modify_font (priv->label, NULL);
394 if (priv->has_secondary_text && !priv->has_primary_markup)
396 context = gtk_widget_get_style_context (priv->label);
397 state = gtk_widget_get_state_flags (priv->label);
399 size = pango_font_description_get_size (gtk_style_context_get_font (context, state));
400 font_desc = pango_font_description_new ();
401 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
402 pango_font_description_set_size (font_desc, size * PANGO_SCALE_LARGE);
403 gtk_widget_modify_font (priv->label, font_desc);
404 pango_font_description_free (font_desc);
409 setup_type (GtkMessageDialog *dialog,
412 GtkMessageDialogPrivate *priv = dialog->priv;
413 const gchar *stock_id = NULL;
416 priv->message_type = type;
420 case GTK_MESSAGE_INFO:
421 stock_id = GTK_STOCK_DIALOG_INFO;
424 case GTK_MESSAGE_QUESTION:
425 stock_id = GTK_STOCK_DIALOG_QUESTION;
428 case GTK_MESSAGE_WARNING:
429 stock_id = GTK_STOCK_DIALOG_WARNING;
432 case GTK_MESSAGE_ERROR:
433 stock_id = GTK_STOCK_DIALOG_ERROR;
436 case GTK_MESSAGE_OTHER:
440 g_warning ("Unknown GtkMessageType %u", type);
445 gtk_image_set_from_stock (GTK_IMAGE (priv->image), stock_id,
446 GTK_ICON_SIZE_DIALOG);
448 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (dialog));
449 if (GTK_IS_ACCESSIBLE (atk_obj))
451 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
456 gtk_stock_lookup (stock_id, &item);
457 atk_object_set_name (atk_obj, item.label);
463 gtk_message_dialog_set_property (GObject *object,
468 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
469 GtkMessageDialogPrivate *priv = dialog->priv;
473 case PROP_MESSAGE_TYPE:
474 setup_type (dialog, g_value_get_enum (value));
477 gtk_message_dialog_add_buttons (dialog, g_value_get_enum (value));
480 if (priv->has_primary_markup)
481 gtk_label_set_markup (GTK_LABEL (priv->label),
482 g_value_get_string (value));
484 gtk_label_set_text (GTK_LABEL (priv->label),
485 g_value_get_string (value));
487 case PROP_USE_MARKUP:
488 priv->has_primary_markup = g_value_get_boolean (value) != FALSE;
489 gtk_label_set_use_markup (GTK_LABEL (priv->label),
490 priv->has_primary_markup);
491 setup_primary_label_font (dialog);
493 case PROP_SECONDARY_TEXT:
495 const gchar *txt = g_value_get_string (value);
497 if (gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)))
498 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), txt);
500 gtk_label_set_text (GTK_LABEL (priv->secondary_label), txt);
504 priv->has_secondary_text = TRUE;
505 gtk_widget_show (priv->secondary_label);
509 priv->has_secondary_text = FALSE;
510 gtk_widget_hide (priv->secondary_label);
512 setup_primary_label_font (dialog);
515 case PROP_SECONDARY_USE_MARKUP:
516 gtk_label_set_use_markup (GTK_LABEL (priv->secondary_label),
517 g_value_get_boolean (value));
520 gtk_message_dialog_set_image (dialog, g_value_get_object (value));
524 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
530 gtk_message_dialog_get_property (GObject *object,
535 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
536 GtkMessageDialogPrivate *priv = dialog->priv;
540 case PROP_MESSAGE_TYPE:
541 g_value_set_enum (value, (GtkMessageType) priv->message_type);
544 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (priv->label)));
546 case PROP_USE_MARKUP:
547 g_value_set_boolean (value, priv->has_primary_markup);
549 case PROP_SECONDARY_TEXT:
550 if (priv->has_secondary_text)
551 g_value_set_string (value,
552 gtk_label_get_label (GTK_LABEL (priv->secondary_label)));
554 g_value_set_string (value, NULL);
556 case PROP_SECONDARY_USE_MARKUP:
557 if (priv->has_secondary_text)
558 g_value_set_boolean (value,
559 gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)));
561 g_value_set_boolean (value, FALSE);
564 g_value_set_object (value, priv->image);
566 case PROP_MESSAGE_AREA:
567 g_value_set_object (value, priv->message_area);
570 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
576 * gtk_message_dialog_new:
577 * @parent: (allow-none): transient parent, or %NULL for none
579 * @type: type of message
580 * @buttons: set of buttons to use
581 * @message_format: (allow-none): printf()-style format string, or %NULL
582 * @Varargs: arguments for @message_format
584 * Creates a new message dialog, which is a simple dialog with an icon
585 * indicating the dialog type (error, warning, etc.) and some text the
586 * user may want to see. When the user clicks a button a "response"
587 * signal is emitted with response IDs from #GtkResponseType. See
588 * #GtkDialog for more details.
590 * Return value: (transfer none): a new #GtkMessageDialog
593 gtk_message_dialog_new (GtkWindow *parent,
594 GtkDialogFlags flags,
596 GtkButtonsType buttons,
597 const gchar *message_format,
605 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
607 widget = g_object_new (GTK_TYPE_MESSAGE_DIALOG,
608 "message-type", type,
611 dialog = GTK_DIALOG (widget);
615 va_start (args, message_format);
616 msg = g_strdup_vprintf (message_format, args);
619 gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (widget)->priv->label),
626 gtk_window_set_transient_for (GTK_WINDOW (widget),
627 GTK_WINDOW (parent));
629 if (flags & GTK_DIALOG_MODAL)
630 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
632 if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
633 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
639 * gtk_message_dialog_new_with_markup:
640 * @parent: (allow-none): transient parent, or %NULL for none
642 * @type: type of message
643 * @buttons: set of buttons to use
644 * @message_format: (allow-none): printf()-style format string, or %NULL
645 * @Varargs: arguments for @message_format
647 * Creates a new message dialog, which is a simple dialog with an icon
648 * indicating the dialog type (error, warning, etc.) and some text which
649 * is marked up with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
650 * When the user clicks a button a "response" signal is emitted with
651 * response IDs from #GtkResponseType. See #GtkDialog for more details.
653 * Special XML characters in the printf() arguments passed to this
654 * function will automatically be escaped as necessary.
655 * (See g_markup_printf_escaped() for how this is implemented.)
656 * Usually this is what you want, but if you have an existing
657 * Pango markup string that you want to use literally as the
658 * label, then you need to use gtk_message_dialog_set_markup()
659 * instead, since you can't pass the markup string either
660 * as the format (it might contain '%' characters) or as a string
664 * dialog = gtk_message_dialog_new (main_application_window,
665 * GTK_DIALOG_DESTROY_WITH_PARENT,
669 * gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
673 * Return value: a new #GtkMessageDialog
678 gtk_message_dialog_new_with_markup (GtkWindow *parent,
679 GtkDialogFlags flags,
681 GtkButtonsType buttons,
682 const gchar *message_format,
689 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
691 widget = gtk_message_dialog_new (parent, flags, type, buttons, NULL);
695 va_start (args, message_format);
696 msg = g_markup_vprintf_escaped (message_format, args);
699 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (widget), msg);
708 * gtk_message_dialog_set_image:
709 * @dialog: a #GtkMessageDialog
712 * Sets the dialog's image to @image.
717 gtk_message_dialog_set_image (GtkMessageDialog *dialog,
720 GtkMessageDialogPrivate *priv;
723 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (dialog));
724 g_return_if_fail (image == NULL || GTK_IS_WIDGET (image));
730 image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
731 gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
732 gtk_widget_set_valign (image, GTK_ALIGN_START);
735 priv->message_type = GTK_MESSAGE_OTHER;
737 parent = gtk_widget_get_parent (priv->image);
738 gtk_container_add (GTK_CONTAINER (parent), image);
739 gtk_container_remove (GTK_CONTAINER (parent), priv->image);
740 gtk_box_reorder_child (GTK_BOX (parent), image, 0);
744 g_object_notify (G_OBJECT (dialog), "image");
748 * gtk_message_dialog_get_image:
749 * @dialog: a #GtkMessageDialog
751 * Gets the dialog's image.
753 * Return value: (transfer none): the dialog's image
758 gtk_message_dialog_get_image (GtkMessageDialog *dialog)
760 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (dialog), NULL);
762 return dialog->priv->image;
766 * gtk_message_dialog_set_markup:
767 * @message_dialog: a #GtkMessageDialog
768 * @str: markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>)
770 * Sets the text of the message dialog to be @str, which is marked
771 * up with the <link linkend="PangoMarkupFormat">Pango text markup
777 gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
780 GtkMessageDialogPrivate *priv;
782 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
784 priv = message_dialog->priv;
786 priv->has_primary_markup = TRUE;
787 gtk_label_set_markup (GTK_LABEL (priv->label), str);
791 * gtk_message_dialog_format_secondary_text:
792 * @message_dialog: a #GtkMessageDialog
793 * @message_format: (allow-none): printf()-style format string, or %NULL
794 * @Varargs: arguments for @message_format
796 * Sets the secondary text of the message dialog to be @message_format
797 * (with printf()-style).
799 * Note that setting a secondary text makes the primary text become
800 * bold, unless you have provided explicit markup.
805 gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog,
806 const gchar *message_format,
811 GtkMessageDialogPrivate *priv;
813 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
815 priv = message_dialog->priv;
819 priv->has_secondary_text = TRUE;
821 va_start (args, message_format);
822 msg = g_strdup_vprintf (message_format, args);
825 gtk_widget_show (priv->secondary_label);
826 gtk_label_set_text (GTK_LABEL (priv->secondary_label), msg);
832 priv->has_secondary_text = FALSE;
833 gtk_widget_hide (priv->secondary_label);
836 setup_primary_label_font (message_dialog);
840 * gtk_message_dialog_format_secondary_markup:
841 * @message_dialog: a #GtkMessageDialog
842 * @message_format: printf()-style markup string (see
843 <link linkend="PangoMarkupFormat">Pango markup format</link>), or %NULL
844 * @Varargs: arguments for @message_format
846 * Sets the secondary text of the message dialog to be @message_format (with
847 * printf()-style), which is marked up with the
848 * <link linkend="PangoMarkupFormat">Pango text markup language</link>.
850 * Note that setting a secondary text makes the primary text become
851 * bold, unless you have provided explicit markup.
853 * Due to an oversight, this function does not escape special XML characters
854 * like gtk_message_dialog_new_with_markup() does. Thus, if the arguments
855 * may contain special XML characters, you should use g_markup_printf_escaped()
858 * <informalexample><programlisting>
861 * msg = g_markup_printf_escaped (message_format, ...);
862 * gtk_message_dialog_format_secondary_markup (message_dialog, "%s", msg);
864 * </programlisting></informalexample>
869 gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
870 const gchar *message_format,
875 GtkMessageDialogPrivate *priv;
877 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
879 priv = message_dialog->priv;
883 priv->has_secondary_text = TRUE;
885 va_start (args, message_format);
886 msg = g_strdup_vprintf (message_format, args);
889 gtk_widget_show (priv->secondary_label);
890 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), msg);
896 priv->has_secondary_text = FALSE;
897 gtk_widget_hide (priv->secondary_label);
900 setup_primary_label_font (message_dialog);
904 * gtk_message_dialog_get_message_area:
905 * @message_dialog: a #GtkMessageDialog
907 * Returns the message area of the dialog. This is the box where the
908 * dialog's primary and secondary labels are packed. You can add your
909 * own extra content to that box and it will appear below those labels,
910 * on the right side of the dialog's image (or on the left for right-to-left
911 * languages). See gtk_dialog_get_content_area() for the corresponding
912 * function in the parent #GtkDialog.
914 * Return value: (transfer none): A #GtkVBox corresponding to the
915 * "message area" in the @message_dialog.
920 gtk_message_dialog_get_message_area (GtkMessageDialog *message_dialog)
922 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog), NULL);
924 return message_dialog->priv->message_area;
928 gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
929 GtkButtonsType buttons)
931 GtkDialog* dialog = GTK_DIALOG (message_dialog);
935 case GTK_BUTTONS_NONE:
940 gtk_dialog_add_button (dialog,
945 case GTK_BUTTONS_CLOSE:
946 gtk_dialog_add_button (dialog,
951 case GTK_BUTTONS_CANCEL:
952 gtk_dialog_add_button (dialog,
954 GTK_RESPONSE_CANCEL);
957 case GTK_BUTTONS_YES_NO:
958 gtk_dialog_add_button (dialog,
961 gtk_dialog_add_button (dialog,
964 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
970 case GTK_BUTTONS_OK_CANCEL:
971 gtk_dialog_add_button (dialog,
973 GTK_RESPONSE_CANCEL);
974 gtk_dialog_add_button (dialog,
977 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
984 g_warning ("Unknown GtkButtonsType");
988 g_object_notify (G_OBJECT (message_dialog), "buttons");
992 gtk_message_dialog_style_updated (GtkWidget *widget)
994 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget);
998 parent = gtk_widget_get_parent (gtk_message_dialog_get_image (dialog));
1002 gtk_widget_style_get (widget, "message-border",
1003 &border_width, NULL);
1005 gtk_container_set_border_width (GTK_CONTAINER (parent),
1006 MAX (0, border_width - 7));
1009 setup_primary_label_font (dialog);
1011 GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_updated (widget);