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