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