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"
45 * SECTION:gtkmessagedialog
46 * @Short_description: A convenient message window
47 * @Title: GtkMessageDialog
48 * @See_also:#GtkDialog
50 * #GtkMessageDialog presents a dialog with an image representing the type of
51 * message (Error, Question, etc.) alongside some message text. It's simply a
52 * convenience widget; you could construct the equivalent of #GtkMessageDialog
53 * from #GtkDialog without too much effort, but #GtkMessageDialog saves typing.
55 * The easiest way to do a modal message dialog is to use gtk_dialog_run(), though
56 * you can also pass in the %GTK_DIALOG_MODAL flag, gtk_dialog_run() automatically
57 * makes the dialog modal and waits for the user to respond to it. gtk_dialog_run()
58 * returns when any dialog button is clicked.
60 * <title>A modal dialog.</title>
62 * dialog = gtk_message_dialog_new (main_application_window,
63 * GTK_DIALOG_DESTROY_WITH_PARENT,
66 * "Error loading file '%s': %s",
67 * filename, g_strerror (errno));
68 * gtk_dialog_run (GTK_DIALOG (dialog));
69 * gtk_widget_destroy (dialog);
72 * You might do a non-modal #GtkMessageDialog as follows:
74 * <title>A non-modal dialog.</title>
76 * dialog = gtk_message_dialog_new (main_application_window,
77 * GTK_DIALOG_DESTROY_WITH_PARENT,
80 * "Error loading file '%s': %s",
81 * filename, g_strerror (errno));
83 * /* Destroy the dialog when the user responds to it (e.g. clicks a button) */
84 * g_signal_connect_swapped (dialog, "response",
85 * G_CALLBACK (gtk_widget_destroy),
90 * <refsect2 id="GtkMessageDialog-BUILDER-UI">
91 * <title>GtkMessageDialog as GtkBuildable</title>
93 * The GtkMessageDialog implementation of the GtkBuildable interface exposes
94 * the message area as an internal child with the name "message_area".
99 #define GTK_MESSAGE_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_MESSAGE_DIALOG, GtkMessageDialogPrivate))
101 typedef struct _GtkMessageDialogPrivate GtkMessageDialogPrivate;
103 struct _GtkMessageDialogPrivate
105 GtkWidget *message_area; /* vbox for the primary and secondary labels, and any extra content from the caller */
106 GtkWidget *secondary_label;
107 guint message_type : 3;
108 guint has_primary_markup : 1;
109 guint has_secondary_text : 1;
112 static void gtk_message_dialog_style_set (GtkWidget *widget,
113 GtkStyle *prev_style);
115 static void gtk_message_dialog_set_property (GObject *object,
119 static void gtk_message_dialog_get_property (GObject *object,
123 static void gtk_message_dialog_add_buttons (GtkMessageDialog *message_dialog,
124 GtkButtonsType buttons);
125 static void gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface);
126 static GObject * gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
128 const gchar *childname);
138 PROP_SECONDARY_USE_MARKUP,
143 G_DEFINE_TYPE_WITH_CODE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG,
144 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
145 gtk_message_dialog_buildable_interface_init))
147 static GtkBuildableIface *parent_buildable_iface;
150 gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface)
152 parent_buildable_iface = g_type_interface_peek_parent (iface);
153 iface->get_internal_child = gtk_message_dialog_buildable_get_internal_child;
154 iface->custom_tag_start = parent_buildable_iface->custom_tag_start;
155 iface->custom_finished = parent_buildable_iface->custom_finished;
159 gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
161 const gchar *childname)
163 if (strcmp (childname, "message_area") == 0)
164 return G_OBJECT (gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (buildable)));
166 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
171 gtk_message_dialog_class_init (GtkMessageDialogClass *class)
173 GtkWidgetClass *widget_class;
174 GObjectClass *gobject_class;
176 widget_class = GTK_WIDGET_CLASS (class);
177 gobject_class = G_OBJECT_CLASS (class);
179 widget_class->style_set = gtk_message_dialog_style_set;
181 gobject_class->set_property = gtk_message_dialog_set_property;
182 gobject_class->get_property = gtk_message_dialog_get_property;
184 gtk_widget_class_install_style_property (widget_class,
185 g_param_spec_int ("message-border",
186 P_("Image/label border"),
187 P_("Width of border around the label and image in the message dialog"),
191 GTK_PARAM_READABLE));
193 * GtkMessageDialog:use-separator:
195 * Whether to draw a separator line between the message label and the buttons
200 gtk_widget_class_install_style_property (widget_class,
201 g_param_spec_boolean ("use-separator",
203 P_("Whether to put a separator between the message dialog's text and the buttons"),
205 GTK_PARAM_READABLE));
207 * GtkMessageDialog:message-type:
209 * The type of the message. The type is used to determine
210 * the image that is shown in the dialog, unless the image is
211 * explicitly set by the ::image property.
213 g_object_class_install_property (gobject_class,
215 g_param_spec_enum ("message-type",
217 P_("The type of message"),
218 GTK_TYPE_MESSAGE_TYPE,
220 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
221 g_object_class_install_property (gobject_class,
223 g_param_spec_enum ("buttons",
224 P_("Message Buttons"),
225 P_("The buttons shown in the message dialog"),
226 GTK_TYPE_BUTTONS_TYPE,
228 GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
231 * GtkMessageDialog:text:
233 * The primary text of the message dialog. If the dialog has
234 * a secondary text, this will appear as the title.
238 g_object_class_install_property (gobject_class,
240 g_param_spec_string ("text",
242 P_("The primary text of the message dialog"),
244 GTK_PARAM_READWRITE));
247 * GtkMessageDialog:use-markup:
249 * %TRUE if the primary text of the dialog includes Pango markup.
250 * See pango_parse_markup().
254 g_object_class_install_property (gobject_class,
256 g_param_spec_boolean ("use-markup",
258 P_("The primary text of the title includes Pango markup."),
260 GTK_PARAM_READWRITE));
263 * GtkMessageDialog:secondary-text:
265 * The secondary text of the message dialog.
269 g_object_class_install_property (gobject_class,
271 g_param_spec_string ("secondary-text",
272 P_("Secondary Text"),
273 P_("The secondary text of the message dialog"),
275 GTK_PARAM_READWRITE));
278 * GtkMessageDialog:secondary-use-markup:
280 * %TRUE if the secondary text of the dialog includes Pango markup.
281 * See pango_parse_markup().
285 g_object_class_install_property (gobject_class,
286 PROP_SECONDARY_USE_MARKUP,
287 g_param_spec_boolean ("secondary-use-markup",
288 P_("Use Markup in secondary"),
289 P_("The secondary text includes Pango markup."),
291 GTK_PARAM_READWRITE));
294 * GtkMessageDialog:image:
296 * The image for this dialog.
300 g_object_class_install_property (gobject_class,
302 g_param_spec_object ("image",
306 GTK_PARAM_READWRITE));
309 * GtkMessageDialog:message-area
311 * The #GtkVBox that corresponds to the message area of this dialog. See
312 * gtk_message_dialog_get_message_area() for a detailed description of this
317 g_object_class_install_property (gobject_class,
319 g_param_spec_object ("message-area",
321 P_("GtkVBox that holds the dialog's primary and secondary labels"),
323 GTK_PARAM_READABLE));
325 g_type_class_add_private (gobject_class,
326 sizeof (GtkMessageDialogPrivate));
330 gtk_message_dialog_init (GtkMessageDialog *dialog)
333 GtkMessageDialogPrivate *priv;
335 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
337 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
338 gtk_window_set_title (GTK_WINDOW (dialog), "");
339 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
341 priv->has_primary_markup = FALSE;
342 priv->has_secondary_text = FALSE;
343 priv->secondary_label = gtk_label_new (NULL);
344 gtk_widget_set_no_show_all (priv->secondary_label, TRUE);
346 dialog->label = gtk_label_new (NULL);
347 dialog->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
348 gtk_misc_set_alignment (GTK_MISC (dialog->image), 0.5, 0.0);
350 gtk_label_set_line_wrap (GTK_LABEL (dialog->label), TRUE);
351 gtk_label_set_selectable (GTK_LABEL (dialog->label), TRUE);
352 gtk_misc_set_alignment (GTK_MISC (dialog->label), 0.0, 0.0);
354 gtk_label_set_line_wrap (GTK_LABEL (priv->secondary_label), TRUE);
355 gtk_label_set_selectable (GTK_LABEL (priv->secondary_label), TRUE);
356 gtk_misc_set_alignment (GTK_MISC (priv->secondary_label), 0.0, 0.0);
358 hbox = gtk_hbox_new (FALSE, 12);
359 priv->message_area = gtk_vbox_new (FALSE, 12);
361 gtk_box_pack_start (GTK_BOX (priv->message_area), dialog->label,
364 gtk_box_pack_start (GTK_BOX (priv->message_area), priv->secondary_label,
367 gtk_box_pack_start (GTK_BOX (hbox), dialog->image,
370 gtk_box_pack_start (GTK_BOX (hbox), priv->message_area,
373 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
377 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
378 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
379 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14); /* 14 + 2 * 5 = 24 */
380 gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5);
381 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 6);
383 gtk_widget_show_all (hbox);
385 _gtk_dialog_set_ignore_separator (GTK_DIALOG (dialog), TRUE);
389 setup_primary_label_font (GtkMessageDialog *dialog)
392 PangoFontDescription *font_desc;
393 GtkMessageDialogPrivate *priv;
395 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
397 /* unset the font settings */
398 gtk_widget_modify_font (dialog->label, NULL);
400 if (priv->has_secondary_text && !priv->has_primary_markup)
402 size = pango_font_description_get_size (dialog->label->style->font_desc);
403 font_desc = pango_font_description_new ();
404 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
405 pango_font_description_set_size (font_desc, size * PANGO_SCALE_LARGE);
406 gtk_widget_modify_font (dialog->label, font_desc);
407 pango_font_description_free (font_desc);
412 setup_type (GtkMessageDialog *dialog,
415 GtkMessageDialogPrivate *priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
416 const gchar *stock_id = NULL;
419 priv->message_type = type;
423 case GTK_MESSAGE_INFO:
424 stock_id = GTK_STOCK_DIALOG_INFO;
427 case GTK_MESSAGE_QUESTION:
428 stock_id = GTK_STOCK_DIALOG_QUESTION;
431 case GTK_MESSAGE_WARNING:
432 stock_id = GTK_STOCK_DIALOG_WARNING;
435 case GTK_MESSAGE_ERROR:
436 stock_id = GTK_STOCK_DIALOG_ERROR;
439 case GTK_MESSAGE_OTHER:
443 g_warning ("Unknown GtkMessageType %u", type);
448 gtk_image_set_from_stock (GTK_IMAGE (dialog->image), stock_id,
449 GTK_ICON_SIZE_DIALOG);
451 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (dialog));
452 if (GTK_IS_ACCESSIBLE (atk_obj))
454 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
459 gtk_stock_lookup (stock_id, &item);
460 atk_object_set_name (atk_obj, item.label);
466 gtk_message_dialog_set_property (GObject *object,
471 GtkMessageDialog *dialog;
472 GtkMessageDialogPrivate *priv;
474 dialog = GTK_MESSAGE_DIALOG (object);
475 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
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 (dialog->label),
488 g_value_get_string (value));
490 gtk_label_set_text (GTK_LABEL (dialog->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 (dialog->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;
542 GtkMessageDialogPrivate *priv;
544 dialog = GTK_MESSAGE_DIALOG (object);
545 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
549 case PROP_MESSAGE_TYPE:
550 g_value_set_enum (value, (GtkMessageType) priv->message_type);
553 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (dialog->label)));
555 case PROP_USE_MARKUP:
556 g_value_set_boolean (value, priv->has_primary_markup);
558 case PROP_SECONDARY_TEXT:
559 if (priv->has_secondary_text)
560 g_value_set_string (value,
561 gtk_label_get_label (GTK_LABEL (priv->secondary_label)));
563 g_value_set_string (value, NULL);
565 case PROP_SECONDARY_USE_MARKUP:
566 if (priv->has_secondary_text)
567 g_value_set_boolean (value,
568 gtk_label_get_use_markup (GTK_LABEL (priv->secondary_label)));
570 g_value_set_boolean (value, FALSE);
573 g_value_set_object (value, dialog->image);
575 case PROP_MESSAGE_AREA:
576 g_value_set_object (value, priv->message_area);
579 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
585 * gtk_message_dialog_new:
586 * @parent: (allow-none): transient parent, or %NULL for none
588 * @type: type of message
589 * @buttons: set of buttons to use
590 * @message_format: (allow-none): printf()-style format string, or %NULL
591 * @Varargs: arguments for @message_format
593 * Creates a new message dialog, which is a simple dialog with an icon
594 * indicating the dialog type (error, warning, etc.) and some text the
595 * user may want to see. When the user clicks a button a "response"
596 * signal is emitted with response IDs from #GtkResponseType. See
597 * #GtkDialog for more details.
599 * Return value: (transfer none): a new #GtkMessageDialog
602 gtk_message_dialog_new (GtkWindow *parent,
603 GtkDialogFlags flags,
605 GtkButtonsType buttons,
606 const gchar *message_format,
614 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
616 widget = g_object_new (GTK_TYPE_MESSAGE_DIALOG,
617 "message-type", type,
620 dialog = GTK_DIALOG (widget);
622 if (flags & GTK_DIALOG_NO_SEPARATOR)
624 g_warning ("The GTK_DIALOG_NO_SEPARATOR flag cannot be used for GtkMessageDialog");
625 flags &= ~GTK_DIALOG_NO_SEPARATOR;
630 va_start (args, message_format);
631 msg = g_strdup_vprintf (message_format, args);
634 gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (widget)->label),
641 gtk_window_set_transient_for (GTK_WINDOW (widget),
642 GTK_WINDOW (parent));
644 if (flags & GTK_DIALOG_MODAL)
645 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
647 if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
648 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
654 * gtk_message_dialog_new_with_markup:
655 * @parent: (allow-none): transient parent, or %NULL for none
657 * @type: type of message
658 * @buttons: set of buttons to use
659 * @message_format: (allow-none): printf()-style format string, or %NULL
660 * @Varargs: arguments for @message_format
662 * Creates a new message dialog, which is a simple dialog with an icon
663 * indicating the dialog type (error, warning, etc.) and some text which
664 * is marked up with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
665 * When the user clicks a button a "response" signal is emitted with
666 * response IDs from #GtkResponseType. See #GtkDialog for more details.
668 * Special XML characters in the printf() arguments passed to this
669 * function will automatically be escaped as necessary.
670 * (See g_markup_printf_escaped() for how this is implemented.)
671 * Usually this is what you want, but if you have an existing
672 * Pango markup string that you want to use literally as the
673 * label, then you need to use gtk_message_dialog_set_markup()
674 * instead, since you can't pass the markup string either
675 * as the format (it might contain '%' characters) or as a string
679 * dialog = gtk_message_dialog_new (main_application_window,
680 * GTK_DIALOG_DESTROY_WITH_PARENT,
684 * gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
688 * Return value: a new #GtkMessageDialog
693 gtk_message_dialog_new_with_markup (GtkWindow *parent,
694 GtkDialogFlags flags,
696 GtkButtonsType buttons,
697 const gchar *message_format,
704 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
706 widget = gtk_message_dialog_new (parent, flags, type, buttons, NULL);
710 va_start (args, message_format);
711 msg = g_markup_vprintf_escaped (message_format, args);
714 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (widget), msg);
723 * gtk_message_dialog_set_image:
724 * @dialog: a #GtkMessageDialog
727 * Sets the dialog's image to @image.
732 gtk_message_dialog_set_image (GtkMessageDialog *dialog,
735 GtkMessageDialogPrivate *priv;
738 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (dialog));
739 g_return_if_fail (image == NULL || GTK_IS_WIDGET (image));
743 image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
744 gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
747 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
749 priv->message_type = GTK_MESSAGE_OTHER;
751 parent = dialog->image->parent;
752 gtk_container_add (GTK_CONTAINER (parent), image);
753 gtk_container_remove (GTK_CONTAINER (parent), dialog->image);
754 gtk_box_reorder_child (GTK_BOX (parent), image, 0);
756 dialog->image = image;
758 g_object_notify (G_OBJECT (dialog), "image");
762 * gtk_message_dialog_get_image:
763 * @dialog: a #GtkMessageDialog
765 * Gets the dialog's image.
767 * Return value: the dialog's image
772 gtk_message_dialog_get_image (GtkMessageDialog *dialog)
774 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (dialog), NULL);
776 return dialog->image;
780 * gtk_message_dialog_set_markup:
781 * @message_dialog: a #GtkMessageDialog
782 * @str: markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>)
784 * Sets the text of the message dialog to be @str, which is marked
785 * up with the <link linkend="PangoMarkupFormat">Pango text markup
791 gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
794 GtkMessageDialogPrivate *priv;
796 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
798 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog);
799 priv->has_primary_markup = TRUE;
800 gtk_label_set_markup (GTK_LABEL (message_dialog->label), str);
804 * gtk_message_dialog_format_secondary_text:
805 * @message_dialog: a #GtkMessageDialog
806 * @message_format: (allow-none): printf()-style format string, or %NULL
807 * @Varargs: arguments for @message_format
809 * Sets the secondary text of the message dialog to be @message_format
810 * (with printf()-style).
812 * Note that setting a secondary text makes the primary text become
813 * bold, unless you have provided explicit markup.
818 gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog,
819 const gchar *message_format,
824 GtkMessageDialogPrivate *priv;
826 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
828 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog);
832 priv->has_secondary_text = TRUE;
834 va_start (args, message_format);
835 msg = g_strdup_vprintf (message_format, args);
838 gtk_widget_show (priv->secondary_label);
839 gtk_label_set_text (GTK_LABEL (priv->secondary_label), msg);
845 priv->has_secondary_text = FALSE;
846 gtk_widget_hide (priv->secondary_label);
849 setup_primary_label_font (message_dialog);
853 * gtk_message_dialog_format_secondary_markup:
854 * @message_dialog: a #GtkMessageDialog
855 * @message_format: printf()-style markup string (see
856 <link linkend="PangoMarkupFormat">Pango markup format</link>), or %NULL
857 * @Varargs: arguments for @message_format
859 * Sets the secondary text of the message dialog to be @message_format (with
860 * printf()-style), which is marked up with the
861 * <link linkend="PangoMarkupFormat">Pango text markup language</link>.
863 * Note that setting a secondary text makes the primary text become
864 * bold, unless you have provided explicit markup.
866 * Due to an oversight, this function does not escape special XML characters
867 * like gtk_message_dialog_new_with_markup() does. Thus, if the arguments
868 * may contain special XML characters, you should use g_markup_printf_escaped()
871 * <informalexample><programlisting>
874 * msg = g_markup_printf_escaped (message_format, ...);
875 * gtk_message_dialog_format_secondary_markup (message_dialog, "%s", msg);
877 * </programlisting></informalexample>
882 gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
883 const gchar *message_format,
888 GtkMessageDialogPrivate *priv;
890 g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
892 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog);
896 priv->has_secondary_text = TRUE;
898 va_start (args, message_format);
899 msg = g_strdup_vprintf (message_format, args);
902 gtk_widget_show (priv->secondary_label);
903 gtk_label_set_markup (GTK_LABEL (priv->secondary_label), msg);
909 priv->has_secondary_text = FALSE;
910 gtk_widget_hide (priv->secondary_label);
913 setup_primary_label_font (message_dialog);
917 * gtk_message_dialog_get_message_area:
918 * @message_dialog: a #GtkMessageDialog
920 * Return value: A #GtkVBox corresponding to the "message area" in the
921 * @message_dialog. This is the box where the dialog's primary and secondary
922 * labels are packed. You can add your own extra content to that box and it
923 * will appear below those labels, on the right side of the dialog's image (or
924 * on the left for right-to-left languages). See gtk_dialog_get_content_area()
925 * for the corresponding function in the parent #GtkDialog.
930 gtk_message_dialog_get_message_area (GtkMessageDialog *message_dialog)
932 GtkMessageDialogPrivate *priv;
934 g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog), NULL);
936 priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog);
938 return priv->message_area;
942 gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
943 GtkButtonsType buttons)
945 GtkDialog* dialog = GTK_DIALOG (message_dialog);
949 case GTK_BUTTONS_NONE:
954 gtk_dialog_add_button (dialog,
959 case GTK_BUTTONS_CLOSE:
960 gtk_dialog_add_button (dialog,
965 case GTK_BUTTONS_CANCEL:
966 gtk_dialog_add_button (dialog,
968 GTK_RESPONSE_CANCEL);
971 case GTK_BUTTONS_YES_NO:
972 gtk_dialog_add_button (dialog,
975 gtk_dialog_add_button (dialog,
978 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
984 case GTK_BUTTONS_OK_CANCEL:
985 gtk_dialog_add_button (dialog,
987 GTK_RESPONSE_CANCEL);
988 gtk_dialog_add_button (dialog,
991 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
998 g_warning ("Unknown GtkButtonsType");
1002 g_object_notify (G_OBJECT (message_dialog), "buttons");
1006 gtk_message_dialog_style_set (GtkWidget *widget,
1007 GtkStyle *prev_style)
1009 GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget);
1010 gboolean use_separator;
1014 parent = GTK_WIDGET (GTK_MESSAGE_DIALOG (widget)->image->parent);
1018 gtk_widget_style_get (widget, "message-border",
1019 &border_width, NULL);
1021 gtk_container_set_border_width (GTK_CONTAINER (parent),
1022 MAX (0, border_width - 7));
1025 gtk_widget_style_get (widget,
1026 "use-separator", &use_separator,
1029 _gtk_dialog_set_ignore_separator (GTK_DIALOG (widget), FALSE);
1030 gtk_dialog_set_has_separator (GTK_DIALOG (widget), use_separator);
1031 _gtk_dialog_set_ignore_separator (GTK_DIALOG (widget), TRUE);
1033 setup_primary_label_font (dialog);
1035 GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_set (widget, prev_style);
1038 #define __GTK_MESSAGE_DIALOG_C__
1039 #include "gtkaliasdef.c"