]> Pileus Git - ~andy/gtk/blob - gtk/gtkmessagedialog.c
Fix for #118764, David Bordoley:
[~andy/gtk] / gtk / gtkmessagedialog.c
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.
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 /*
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/. 
26  */
27
28 #include <config.h>
29 #include "gtkalias.h"
30 #include "gtkmessagedialog.h"
31 #include "gtklabel.h"
32 #include "gtkhbox.h"
33 #include "gtkimage.h"
34 #include "gtkstock.h"
35 #include "gtkiconfactory.h"
36 #include "gtkintl.h"
37 #include <string.h>
38
39 #define GTK_MESSAGE_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_MESSAGE_DIALOG, GtkMessageDialogPrivate))
40
41 typedef struct _GtkMessageDialogPrivate GtkMessageDialogPrivate;
42
43 struct _GtkMessageDialogPrivate
44 {
45   GtkWidget *secondary_label;
46   gboolean   has_primary_markup;
47   gboolean   has_secondary_text;
48 };
49
50 static void gtk_message_dialog_class_init (GtkMessageDialogClass *klass);
51 static void gtk_message_dialog_init       (GtkMessageDialog      *dialog);
52 static void gtk_message_dialog_style_set  (GtkWidget             *widget,
53                                            GtkStyle              *prev_style);
54
55 static void gtk_message_dialog_set_property (GObject          *object,
56                                              guint             prop_id,
57                                              const GValue     *value,
58                                              GParamSpec       *pspec);
59 static void gtk_message_dialog_get_property (GObject          *object,
60                                              guint             prop_id,
61                                              GValue           *value,
62                                              GParamSpec       *pspec);
63 static void gtk_message_dialog_add_buttons  (GtkMessageDialog *message_dialog,
64                                              GtkButtonsType    buttons);
65
66 static void gtk_message_dialog_font_size_change (GtkWidget *widget,
67                                                  GtkStyle  *prev_style,
68                                                  gpointer   data);
69
70 enum {
71   PROP_0,
72   PROP_MESSAGE_TYPE,
73   PROP_BUTTONS
74 };
75
76 static gpointer parent_class;
77
78 GType
79 gtk_message_dialog_get_type (void)
80 {
81   static GType dialog_type = 0;
82
83   if (!dialog_type)
84     {
85       static const GTypeInfo dialog_info =
86       {
87         sizeof (GtkMessageDialogClass),
88         NULL,           /* base_init */
89         NULL,           /* base_finalize */
90         (GClassInitFunc) gtk_message_dialog_class_init,
91         NULL,           /* class_finalize */
92         NULL,           /* class_data */
93         sizeof (GtkMessageDialog),
94         0,              /* n_preallocs */
95         (GInstanceInitFunc) gtk_message_dialog_init,
96       };
97
98       dialog_type = g_type_register_static (GTK_TYPE_DIALOG, "GtkMessageDialog",
99                                             &dialog_info, 0);
100     }
101
102   return dialog_type;
103 }
104
105 static void
106 gtk_message_dialog_class_init (GtkMessageDialogClass *class)
107 {
108   GtkWidgetClass *widget_class;
109   GObjectClass *gobject_class;
110
111   widget_class = GTK_WIDGET_CLASS (class);
112   gobject_class = G_OBJECT_CLASS (class);
113
114   parent_class = g_type_class_peek_parent (class);
115   
116   widget_class->style_set = gtk_message_dialog_style_set;
117
118   gobject_class->set_property = gtk_message_dialog_set_property;
119   gobject_class->get_property = gtk_message_dialog_get_property;
120   
121   gtk_widget_class_install_style_property (widget_class,
122                                            g_param_spec_int ("message_border",
123                                                              P_("Image/label border"),
124                                                              P_("Width of border around the label and image in the message dialog"),
125                                                              0,
126                                                              G_MAXINT,
127                                                              12,
128                                                              G_PARAM_READABLE));
129   /**
130    * GtkMessageDialog::use_separator
131    *
132    * Whether to draw a separator line between the message label and the buttons
133    * in the dialog.
134    *
135    * Since: 2.4
136    */
137   gtk_widget_class_install_style_property (widget_class,
138                                            g_param_spec_boolean ("use_separator",
139                                                                  P_("Use separator"),
140                                                                  P_("Whether to put a separator between the message dialog's text and the buttons"),
141                                                                  FALSE,
142                                                                  G_PARAM_READABLE));
143   g_object_class_install_property (gobject_class,
144                                    PROP_MESSAGE_TYPE,
145                                    g_param_spec_enum ("message_type",
146                                                       P_("Message Type"),
147                                                       P_("The type of message"),
148                                                       GTK_TYPE_MESSAGE_TYPE,
149                                                       GTK_MESSAGE_INFO,
150                                                       G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
151   g_object_class_install_property (gobject_class,
152                                    PROP_BUTTONS,
153                                    g_param_spec_enum ("buttons",
154                                                       P_("Message Buttons"),
155                                                       P_("The buttons shown in the message dialog"),
156                                                       GTK_TYPE_BUTTONS_TYPE,
157                                                       GTK_BUTTONS_NONE,
158                                                       G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
159   g_type_class_add_private (gobject_class,
160                             sizeof (GtkMessageDialogPrivate));
161 }
162
163 static void
164 gtk_message_dialog_init (GtkMessageDialog *dialog)
165 {
166   GtkWidget *hbox, *vbox;
167   GtkMessageDialogPrivate *priv;
168
169   priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
170
171   gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
172
173   priv->has_primary_markup = FALSE;
174   priv->has_secondary_text = FALSE;
175   priv->secondary_label = gtk_label_new (NULL);
176
177   dialog->label = gtk_label_new (NULL);
178   dialog->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
179   gtk_misc_set_alignment (GTK_MISC (dialog->image), 0.5, 0.0);
180   
181   gtk_label_set_line_wrap  (GTK_LABEL (dialog->label), TRUE);
182   gtk_label_set_selectable (GTK_LABEL (dialog->label), TRUE);
183   gtk_misc_set_alignment   (GTK_MISC  (dialog->label), 0.0, 0.0);
184   
185   gtk_label_set_line_wrap  (GTK_LABEL (priv->secondary_label), TRUE);
186   gtk_label_set_selectable (GTK_LABEL (priv->secondary_label), TRUE);
187   gtk_misc_set_alignment   (GTK_MISC  (priv->secondary_label), 0.0, 0.0);
188
189   hbox = gtk_hbox_new (FALSE, 12);
190   vbox = gtk_vbox_new (FALSE, 12);
191
192   gtk_box_pack_start (GTK_BOX (vbox), dialog->label,
193                       FALSE, FALSE, 0);
194
195   gtk_box_pack_start (GTK_BOX (vbox), priv->secondary_label,
196                       TRUE, TRUE, 0);
197
198   gtk_box_pack_start (GTK_BOX (hbox), dialog->image,
199                       FALSE, FALSE, 0);
200
201   gtk_box_pack_start (GTK_BOX (hbox), vbox,
202                       TRUE, TRUE, 0);
203
204   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
205                       hbox,
206                       FALSE, FALSE, 0);
207
208   gtk_widget_show_all (hbox);
209
210   _gtk_dialog_set_ignore_separator (GTK_DIALOG (dialog), TRUE);
211
212   g_signal_connect (G_OBJECT (dialog), "style-set",
213                     G_CALLBACK (gtk_message_dialog_font_size_change), NULL);
214 }
215
216 static GtkMessageType
217 gtk_message_dialog_get_message_type (GtkMessageDialog *dialog)
218 {
219   const gchar* stock_id = NULL;
220
221   g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (dialog), GTK_MESSAGE_INFO);
222   g_return_val_if_fail (GTK_IS_IMAGE(dialog->image), GTK_MESSAGE_INFO);
223
224   stock_id = GTK_IMAGE(dialog->image)->data.stock.stock_id;
225
226   /* Look at the stock id of the image to guess the
227    * GtkMessageType value that was used to choose it
228    * in setup_type()
229    */
230   if (strcmp (stock_id, GTK_STOCK_DIALOG_INFO) == 0)
231     return GTK_MESSAGE_INFO;
232   else if (strcmp (stock_id, GTK_STOCK_DIALOG_QUESTION) == 0)
233     return GTK_MESSAGE_QUESTION;
234   else if (strcmp (stock_id, GTK_STOCK_DIALOG_WARNING) == 0)
235     return GTK_MESSAGE_WARNING;
236   else if (strcmp (stock_id, GTK_STOCK_DIALOG_ERROR) == 0)
237     return GTK_MESSAGE_ERROR;
238   else
239     {
240       g_assert_not_reached (); 
241       return GTK_MESSAGE_INFO;
242     }
243 }
244
245 static void
246 setup_primary_label_font (GtkMessageDialog *dialog)
247 {
248   gint size;
249   PangoFontDescription *font_desc;
250   GtkMessageDialogPrivate *priv;
251
252   priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
253
254   if (priv->has_primary_markup)
255     return;
256
257   /* unset the font settings */
258   gtk_widget_modify_font (dialog->label, NULL);
259
260   if (priv->has_secondary_text)
261     {
262       size = pango_font_description_get_size (dialog->label->style->font_desc);
263       font_desc = pango_font_description_new ();
264       pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
265       pango_font_description_set_size (font_desc, size * PANGO_SCALE_LARGE);
266       gtk_widget_modify_font (dialog->label, font_desc);
267     }
268 }
269
270 static void
271 setup_type (GtkMessageDialog *dialog,
272             GtkMessageType    type)
273 {
274   const gchar *stock_id = NULL;
275   GtkStockItem item;
276   
277   switch (type)
278     {
279     case GTK_MESSAGE_INFO:
280       stock_id = GTK_STOCK_DIALOG_INFO;
281       break;
282
283     case GTK_MESSAGE_QUESTION:
284       stock_id = GTK_STOCK_DIALOG_QUESTION;
285       break;
286
287     case GTK_MESSAGE_WARNING:
288       stock_id = GTK_STOCK_DIALOG_WARNING;
289       break;
290       
291     case GTK_MESSAGE_ERROR:
292       stock_id = GTK_STOCK_DIALOG_ERROR;
293       break;
294
295     default:
296       g_warning ("Unknown GtkMessageType %d", type);
297       break;
298     }
299
300   if (stock_id == NULL)
301     stock_id = GTK_STOCK_DIALOG_INFO;
302
303   if (gtk_stock_lookup (stock_id, &item))
304     {
305       gtk_image_set_from_stock (GTK_IMAGE (dialog->image), stock_id,
306                                 GTK_ICON_SIZE_DIALOG);
307       
308       gtk_window_set_title (GTK_WINDOW (dialog), item.label);
309     }
310   else
311     g_warning ("Stock dialog ID doesn't exist?");  
312 }
313
314 static void 
315 gtk_message_dialog_set_property (GObject      *object,
316                                  guint         prop_id,
317                                  const GValue *value,
318                                  GParamSpec   *pspec)
319 {
320   GtkMessageDialog *dialog;
321   
322   dialog = GTK_MESSAGE_DIALOG (object);
323   
324   switch (prop_id)
325     {
326     case PROP_MESSAGE_TYPE:
327       setup_type (dialog, g_value_get_enum (value));
328       break;
329     case PROP_BUTTONS:
330       gtk_message_dialog_add_buttons (dialog, g_value_get_enum (value));
331       break;
332     default:
333       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
334       break;
335     }
336 }
337
338 static void 
339 gtk_message_dialog_get_property (GObject     *object,
340                                  guint        prop_id,
341                                  GValue      *value,
342                                  GParamSpec  *pspec)
343 {
344   GtkMessageDialog *dialog;
345   
346   dialog = GTK_MESSAGE_DIALOG (object);
347   
348   switch (prop_id)
349     {
350     case PROP_MESSAGE_TYPE:
351       g_value_set_enum (value, gtk_message_dialog_get_message_type (dialog));
352       break;
353     default:
354       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
355       break;
356     }
357 }
358
359 static void
360 gtk_message_dialog_font_size_change (GtkWidget *widget,
361                                      GtkStyle  *prev_style,
362                                      gpointer   data)
363 {
364   setup_primary_label_font (GTK_MESSAGE_DIALOG (widget));
365 }
366
367
368 /**
369  * gtk_message_dialog_new:
370  * @parent: transient parent, or NULL for none 
371  * @flags: flags
372  * @type: type of message
373  * @buttons: set of buttons to use
374  * @message_format: printf()-style format string, or NULL
375  * @Varargs: arguments for @message_format
376  * 
377  * Creates a new message dialog, which is a simple dialog with an icon
378  * indicating the dialog type (error, warning, etc.) and some text the
379  * user may want to see. When the user clicks a button a "response"
380  * signal is emitted with response IDs from #GtkResponseType. See
381  * #GtkDialog for more details.
382  * 
383  * Return value: a new #GtkMessageDialog
384  **/
385 GtkWidget*
386 gtk_message_dialog_new (GtkWindow     *parent,
387                         GtkDialogFlags flags,
388                         GtkMessageType type,
389                         GtkButtonsType buttons,
390                         const gchar   *message_format,
391                         ...)
392 {
393   GtkWidget *widget;
394   GtkDialog *dialog;
395   gchar* msg = 0;
396   va_list args;
397
398   g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
399
400   widget = g_object_new (GTK_TYPE_MESSAGE_DIALOG,
401                          "message_type", type,
402                          "buttons", buttons,
403                          NULL);
404   dialog = GTK_DIALOG (widget);
405
406   if (flags & GTK_DIALOG_NO_SEPARATOR)
407     {
408       g_warning ("The GTK_DIALOG_NO_SEPARATOR flag cannot be used for GtkMessageDialog");
409       flags &= ~GTK_DIALOG_NO_SEPARATOR;
410     }
411
412   if (message_format)
413     {
414       va_start (args, message_format);
415       msg = g_strdup_vprintf (message_format, args);
416       va_end (args);
417
418       gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (widget)->label),
419                           msg);
420
421       g_free (msg);
422     }
423
424   if (parent != NULL)
425     gtk_window_set_transient_for (GTK_WINDOW (widget),
426                                   GTK_WINDOW (parent));
427   
428   if (flags & GTK_DIALOG_MODAL)
429     gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
430
431   if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
432     gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
433
434   if (flags & GTK_DIALOG_NO_SEPARATOR)
435     gtk_dialog_set_has_separator (dialog, FALSE);
436
437   return widget;
438 }
439
440 /**
441  * gtk_message_dialog_new_with_markup:
442  * @parent: transient parent, or %NULL for none 
443  * @flags: flags
444  * @type: type of message
445  * @buttons: set of buttons to use
446  * @message_format: printf()-style format string, or %NULL
447  * @Varargs: arguments for @message_format
448  * 
449  * Creates a new message dialog, which is a simple dialog with an icon
450  * indicating the dialog type (error, warning, etc.) and some text which
451  * is marked up with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
452  * When the user clicks a button a "response" signal is emitted with
453  * response IDs from #GtkResponseType. See #GtkDialog for more details.
454  *
455  * Special XML characters in the printf() arguments passed to this
456  * function will automatically be escaped as necessary.
457  * (See g_markup_printf_escaped() for how this is implemented.)
458  * Usually this is what you want, but if you have an existing
459  * Pango markup string that you want to use literally as the
460  * label, then you need to use gtk_message_dialog_set_markup()
461  * instead, since you can't pass the markup string either
462  * as the format (it might contain '%' characters) or as a string
463  * argument.
464  *
465  * <informalexample><programlisting>
466  *  GtkWidget *dialog;
467  *  dialog = gtk_message_dialog_new (main_application_window,
468  *                                   GTK_DIALOG_DESTROY_WITH_PARENT,
469  *                                   GTK_MESSAGE_ERROR,
470  *                                   GTK_BUTTON_CLOSE,
471  *                                   NULL);
472  *  gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
473  *                                 markup);
474  * </programlisting></informalexample>
475  * 
476  * Return value: a new #GtkMessageDialog
477  *
478  * Since: 2.4
479  **/
480 GtkWidget*
481 gtk_message_dialog_new_with_markup (GtkWindow     *parent,
482                                     GtkDialogFlags flags,
483                                     GtkMessageType type,
484                                     GtkButtonsType buttons,
485                                     const gchar   *message_format,
486                                     ...)
487 {
488   GtkWidget *widget;
489   va_list args;
490   gchar *msg = NULL;
491
492   g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
493
494   widget = gtk_message_dialog_new (parent, flags, type, buttons, NULL);
495
496   if (message_format)
497     {
498       va_start (args, message_format);
499       msg = g_markup_vprintf_escaped (message_format, args);
500       va_end (args);
501
502       gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (widget), msg);
503
504       g_free (msg);
505     }
506
507   return widget;
508 }
509
510 /**
511  * gtk_message_dialog_set_markup:
512  * @message_dialog: a #GtkMessageDialog
513  * @str: markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>)
514  * 
515  * Sets the text of the message dialog to be @str, which is marked
516  * up with the <link linkend="PangoMarkupFormat">Pango text markup
517  * language</link>.
518  *
519  * Since: 2.4
520  **/
521 void
522 gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
523                                const gchar      *str)
524 {
525   GtkMessageDialogPrivate *priv;
526
527   g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
528
529   priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog);
530   priv->has_primary_markup = TRUE;
531   gtk_label_set_markup (GTK_LABEL (message_dialog->label), str);
532 }
533
534 /**
535  * gtk_message_dialog_format_secondary_text:
536  * @message_dialog: a #GtkMessageDialog
537  * @message_format: printf()-style format string, or %NULL
538  * @Varargs: arguments for @message_format
539  * 
540  * Sets the secondary text of the message dialog to be @message_format 
541  * (with printf()-style).
542  *
543  * Note that setting a secondary text makes the primary text become
544  * bold, unless you have provided explicit markup.
545  *
546  * Since: 2.6
547  **/
548 void
549 gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog,
550                                           const gchar      *message_format,
551                                           ...)
552 {
553   va_list args;
554   gchar *msg = NULL;
555   GtkMessageDialogPrivate *priv;
556
557   g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
558
559   priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog);
560
561   if (message_format)
562     {
563       priv->has_secondary_text = TRUE;
564
565       va_start (args, message_format);
566       msg = g_strdup_vprintf (message_format, args);
567       va_end (args);
568
569       gtk_widget_show (priv->secondary_label);
570       gtk_label_set_text (GTK_LABEL (priv->secondary_label), msg);
571
572       g_free (msg);
573     }
574   else
575     {
576       priv->has_secondary_text = FALSE;
577       gtk_widget_hide (priv->secondary_label);
578     }
579
580   setup_primary_label_font (message_dialog);
581 }
582
583 /**
584  * gtk_message_dialog_format_secondary_markup:
585  * @message_dialog: a #GtkMessageDialog
586  * @message_format: printf()-style markup string (see 
587      <link linkend="PangoMarkupFormat">Pango markup format</link>), or %NULL
588  * @Varargs: arguments for @message_format
589  * 
590  * Sets the secondary text of the message dialog to be @message_format (with 
591  * printf()-style), which is marked up with the 
592  * <link linkend="PangoMarkupFormat">Pango text markup language</link>.
593  *
594  * Note that setting a secondary text makes the primary text become
595  * bold, unless you have provided explicit markup.
596  *
597  * Since: 2.6
598  **/
599 void
600 gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
601                                             const gchar      *message_format,
602                                             ...)
603 {
604   va_list args;
605   gchar *msg = NULL;
606   GtkMessageDialogPrivate *priv;
607
608   g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
609
610   priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog);
611
612   if (message_format)
613     {
614       priv->has_secondary_text = TRUE;
615
616       va_start (args, message_format);
617       msg = g_strdup_vprintf (message_format, args);
618       va_end (args);
619
620       gtk_widget_show (priv->secondary_label);
621       gtk_label_set_markup (GTK_LABEL (priv->secondary_label), msg);
622
623       g_free (msg);
624     }
625   else
626     {
627       priv->has_secondary_text = FALSE;
628       gtk_widget_hide (priv->secondary_label);
629     }
630
631   setup_primary_label_font (message_dialog);
632 }
633
634 static void
635 gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
636                                 GtkButtonsType buttons)
637 {
638   GtkDialog* dialog = GTK_DIALOG (message_dialog);
639
640   switch (buttons)
641     {
642     case GTK_BUTTONS_NONE:
643       /* nothing */
644       break;
645
646     case GTK_BUTTONS_OK:
647       gtk_dialog_add_button (dialog,
648                              GTK_STOCK_OK,
649                              GTK_RESPONSE_OK);
650       break;
651
652     case GTK_BUTTONS_CLOSE:
653       gtk_dialog_add_button (dialog,
654                              GTK_STOCK_CLOSE,
655                              GTK_RESPONSE_CLOSE);
656       break;
657
658     case GTK_BUTTONS_CANCEL:
659       gtk_dialog_add_button (dialog,
660                              GTK_STOCK_CANCEL,
661                              GTK_RESPONSE_CANCEL);
662       break;
663
664     case GTK_BUTTONS_YES_NO:
665       gtk_dialog_add_button (dialog,
666                              GTK_STOCK_NO,
667                              GTK_RESPONSE_NO);
668       gtk_dialog_add_button (dialog,
669                              GTK_STOCK_YES,
670                              GTK_RESPONSE_YES);
671       gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
672                                                GTK_RESPONSE_YES,
673                                                GTK_RESPONSE_NO,
674                                                -1);
675       break;
676
677     case GTK_BUTTONS_OK_CANCEL:
678       gtk_dialog_add_button (dialog,
679                              GTK_STOCK_CANCEL,
680                              GTK_RESPONSE_CANCEL);
681       gtk_dialog_add_button (dialog,
682                              GTK_STOCK_OK,
683                              GTK_RESPONSE_OK);
684       gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
685                                                GTK_RESPONSE_OK,
686                                                GTK_RESPONSE_CANCEL,
687                                                -1);
688       break;
689       
690     default:
691       g_warning ("Unknown GtkButtonsType");
692       break;
693     } 
694
695   g_object_notify (G_OBJECT (message_dialog), "buttons");
696 }
697
698 static void
699 gtk_message_dialog_style_set (GtkWidget *widget,
700                               GtkStyle  *prev_style)
701 {
702   GtkWidget *parent;
703   gint border_width = 0;
704   gboolean use_separator;
705
706   parent = GTK_WIDGET (GTK_MESSAGE_DIALOG (widget)->image->parent);
707
708   if (parent)
709     {
710       gtk_widget_style_get (widget, "message_border",
711                             &border_width, NULL);
712       
713       gtk_container_set_border_width (GTK_CONTAINER (parent),
714                                       border_width);
715     }
716
717   gtk_widget_style_get (widget,
718                         "use_separator", &use_separator,
719                         NULL);
720   _gtk_dialog_set_ignore_separator (GTK_DIALOG (widget), FALSE);
721   gtk_dialog_set_has_separator (GTK_DIALOG (widget), use_separator);
722   _gtk_dialog_set_ignore_separator (GTK_DIALOG (widget), TRUE);
723
724   if (GTK_WIDGET_CLASS (parent_class)->style_set)
725     (GTK_WIDGET_CLASS (parent_class)->style_set) (widget, prev_style);
726 }