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