]> Pileus Git - ~andy/gtk/blob - gtk/gtkmessagedialog.c
Alert dialogs should not have titles and should not be displayed in the
[~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, I_("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   gtk_window_set_title (GTK_WINDOW (dialog), "");
176   gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
177
178   priv->has_primary_markup = FALSE;
179   priv->has_secondary_text = FALSE;
180   priv->secondary_label = gtk_label_new (NULL);
181   gtk_widget_set_no_show_all (priv->secondary_label, TRUE);
182   
183   dialog->label = gtk_label_new (NULL);
184   dialog->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
185   gtk_misc_set_alignment (GTK_MISC (dialog->image), 0.5, 0.0);
186   
187   gtk_label_set_line_wrap  (GTK_LABEL (dialog->label), TRUE);
188   gtk_label_set_selectable (GTK_LABEL (dialog->label), TRUE);
189   gtk_misc_set_alignment   (GTK_MISC  (dialog->label), 0.0, 0.0);
190   
191   gtk_label_set_line_wrap  (GTK_LABEL (priv->secondary_label), TRUE);
192   gtk_label_set_selectable (GTK_LABEL (priv->secondary_label), TRUE);
193   gtk_misc_set_alignment   (GTK_MISC  (priv->secondary_label), 0.0, 0.0);
194
195   hbox = gtk_hbox_new (FALSE, 12);
196   vbox = gtk_vbox_new (FALSE, 12);
197
198   gtk_box_pack_start (GTK_BOX (vbox), dialog->label,
199                       FALSE, FALSE, 0);
200
201   gtk_box_pack_start (GTK_BOX (vbox), priv->secondary_label,
202                       TRUE, TRUE, 0);
203
204   gtk_box_pack_start (GTK_BOX (hbox), dialog->image,
205                       FALSE, FALSE, 0);
206
207   gtk_box_pack_start (GTK_BOX (hbox), vbox,
208                       TRUE, TRUE, 0);
209
210   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
211                       hbox,
212                       FALSE, FALSE, 0);
213
214   gtk_widget_show_all (hbox);
215
216   _gtk_dialog_set_ignore_separator (GTK_DIALOG (dialog), TRUE);
217
218   g_signal_connect (G_OBJECT (dialog), "style-set",
219                     G_CALLBACK (gtk_message_dialog_font_size_change), NULL);
220 }
221
222 static GtkMessageType
223 gtk_message_dialog_get_message_type (GtkMessageDialog *dialog)
224 {
225   const gchar* stock_id = NULL;
226
227   g_return_val_if_fail (GTK_IS_MESSAGE_DIALOG (dialog), GTK_MESSAGE_INFO);
228   g_return_val_if_fail (GTK_IS_IMAGE(dialog->image), GTK_MESSAGE_INFO);
229
230   stock_id = GTK_IMAGE(dialog->image)->data.stock.stock_id;
231
232   /* Look at the stock id of the image to guess the
233    * GtkMessageType value that was used to choose it
234    * in setup_type()
235    */
236   if (strcmp (stock_id, GTK_STOCK_DIALOG_INFO) == 0)
237     return GTK_MESSAGE_INFO;
238   else if (strcmp (stock_id, GTK_STOCK_DIALOG_QUESTION) == 0)
239     return GTK_MESSAGE_QUESTION;
240   else if (strcmp (stock_id, GTK_STOCK_DIALOG_WARNING) == 0)
241     return GTK_MESSAGE_WARNING;
242   else if (strcmp (stock_id, GTK_STOCK_DIALOG_ERROR) == 0)
243     return GTK_MESSAGE_ERROR;
244   else
245     {
246       g_assert_not_reached (); 
247       return GTK_MESSAGE_INFO;
248     }
249 }
250
251 static void
252 setup_primary_label_font (GtkMessageDialog *dialog)
253 {
254   gint size;
255   PangoFontDescription *font_desc;
256   GtkMessageDialogPrivate *priv;
257
258   priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
259
260   if (priv->has_primary_markup)
261     return;
262
263   /* unset the font settings */
264   gtk_widget_modify_font (dialog->label, NULL);
265
266   if (priv->has_secondary_text)
267     {
268       size = pango_font_description_get_size (dialog->label->style->font_desc);
269       font_desc = pango_font_description_new ();
270       pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
271       pango_font_description_set_size (font_desc, size * PANGO_SCALE_LARGE);
272       gtk_widget_modify_font (dialog->label, font_desc);
273       pango_font_description_free (font_desc);
274     }
275 }
276
277 static void
278 setup_type (GtkMessageDialog *dialog,
279             GtkMessageType    type)
280 {
281   const gchar *stock_id = NULL;
282   GtkStockItem item;
283   
284   switch (type)
285     {
286     case GTK_MESSAGE_INFO:
287       stock_id = GTK_STOCK_DIALOG_INFO;
288       break;
289
290     case GTK_MESSAGE_QUESTION:
291       stock_id = GTK_STOCK_DIALOG_QUESTION;
292       break;
293
294     case GTK_MESSAGE_WARNING:
295       stock_id = GTK_STOCK_DIALOG_WARNING;
296       break;
297       
298     case GTK_MESSAGE_ERROR:
299       stock_id = GTK_STOCK_DIALOG_ERROR;
300       break;
301
302     default:
303       g_warning ("Unknown GtkMessageType %d", type);
304       break;
305     }
306
307   if (stock_id == NULL)
308     stock_id = GTK_STOCK_DIALOG_INFO;
309
310   if (gtk_stock_lookup (stock_id, &item))
311     gtk_image_set_from_stock (GTK_IMAGE (dialog->image), stock_id,
312                               GTK_ICON_SIZE_DIALOG);
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_BUTTONS_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  * Due to an oversight, this function does not escape special XML characters
601  * like gtk_message_dialog_new_with_markup() does. Thus, if the arguments 
602  * may contain special XML characters, you should use g_markup_printf_escaped()
603  * to escape it.
604
605  * <informalexample><programlisting>
606  * gchar *msg;
607  *  
608  * msg = g_markup_printf_escaped (message_format, ...);
609  * gtk_message_dialog_format_secondary_markup (message_dialog, "&percnt;s", msg);
610  * g_free (msg);
611  * </programlisting></informalexample>
612  *
613  * Since: 2.6
614  **/
615 void
616 gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
617                                             const gchar      *message_format,
618                                             ...)
619 {
620   va_list args;
621   gchar *msg = NULL;
622   GtkMessageDialogPrivate *priv;
623
624   g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
625
626   priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog);
627
628   if (message_format)
629     {
630       priv->has_secondary_text = TRUE;
631
632       va_start (args, message_format);
633       msg = g_strdup_vprintf (message_format, args);
634       va_end (args);
635
636       gtk_widget_show (priv->secondary_label);
637       gtk_label_set_markup (GTK_LABEL (priv->secondary_label), msg);
638
639       g_free (msg);
640     }
641   else
642     {
643       priv->has_secondary_text = FALSE;
644       gtk_widget_hide (priv->secondary_label);
645     }
646
647   setup_primary_label_font (message_dialog);
648 }
649
650 static void
651 gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
652                                 GtkButtonsType buttons)
653 {
654   GtkDialog* dialog = GTK_DIALOG (message_dialog);
655
656   switch (buttons)
657     {
658     case GTK_BUTTONS_NONE:
659       /* nothing */
660       break;
661
662     case GTK_BUTTONS_OK:
663       gtk_dialog_add_button (dialog,
664                              GTK_STOCK_OK,
665                              GTK_RESPONSE_OK);
666       break;
667
668     case GTK_BUTTONS_CLOSE:
669       gtk_dialog_add_button (dialog,
670                              GTK_STOCK_CLOSE,
671                              GTK_RESPONSE_CLOSE);
672       break;
673
674     case GTK_BUTTONS_CANCEL:
675       gtk_dialog_add_button (dialog,
676                              GTK_STOCK_CANCEL,
677                              GTK_RESPONSE_CANCEL);
678       break;
679
680     case GTK_BUTTONS_YES_NO:
681       gtk_dialog_add_button (dialog,
682                              GTK_STOCK_NO,
683                              GTK_RESPONSE_NO);
684       gtk_dialog_add_button (dialog,
685                              GTK_STOCK_YES,
686                              GTK_RESPONSE_YES);
687       gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
688                                                GTK_RESPONSE_YES,
689                                                GTK_RESPONSE_NO,
690                                                -1);
691       break;
692
693     case GTK_BUTTONS_OK_CANCEL:
694       gtk_dialog_add_button (dialog,
695                              GTK_STOCK_CANCEL,
696                              GTK_RESPONSE_CANCEL);
697       gtk_dialog_add_button (dialog,
698                              GTK_STOCK_OK,
699                              GTK_RESPONSE_OK);
700       gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
701                                                GTK_RESPONSE_OK,
702                                                GTK_RESPONSE_CANCEL,
703                                                -1);
704       break;
705       
706     default:
707       g_warning ("Unknown GtkButtonsType");
708       break;
709     } 
710
711   g_object_notify (G_OBJECT (message_dialog), "buttons");
712 }
713
714 static void
715 gtk_message_dialog_style_set (GtkWidget *widget,
716                               GtkStyle  *prev_style)
717 {
718   GtkWidget *parent;
719   gint border_width = 0;
720   gboolean use_separator;
721
722   parent = GTK_WIDGET (GTK_MESSAGE_DIALOG (widget)->image->parent);
723
724   if (parent)
725     {
726       gtk_widget_style_get (widget, "message-border",
727                             &border_width, NULL);
728       
729       gtk_container_set_border_width (GTK_CONTAINER (parent),
730                                       border_width);
731     }
732
733   gtk_widget_style_get (widget,
734                         "use-separator", &use_separator,
735                         NULL);
736   _gtk_dialog_set_ignore_separator (GTK_DIALOG (widget), FALSE);
737   gtk_dialog_set_has_separator (GTK_DIALOG (widget), use_separator);
738   _gtk_dialog_set_ignore_separator (GTK_DIALOG (widget), TRUE);
739
740   if (GTK_WIDGET_CLASS (parent_class)->style_set)
741     (GTK_WIDGET_CLASS (parent_class)->style_set) (widget, prev_style);
742 }
743
744 #define __GTK_MESSAGE_DIALOG_C__
745 #include "gtkaliasdef.c"