]> Pileus Git - ~andy/gtk/blob - gtk/gtkdialog.c
gtk/gtkdialog.c: Use accessor functions to access GtkWindow
[~andy/gtk] / gtk / gtkdialog.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
25  */
26
27 #include <stdlib.h>
28 #include <string.h>
29 #include "config.h"
30 #include "gtkbutton.h"
31 #include "gtkdialog.h"
32 #include "gtkhbbox.h"
33 #include "gtklabel.h"
34 #include "gtkhseparator.h"
35 #include "gtkmarshalers.h"
36 #include "gtkvbox.h"
37 #include "gdkkeysyms.h"
38 #include "gtkmain.h"
39 #include "gtkintl.h"
40 #include "gtkbindings.h"
41 #include "gtkprivate.h"
42 #include "gtkbuildable.h"
43
44
45 struct _GtkDialogPriv
46 {
47   GtkWidget *vbox;
48   GtkWidget *action_area;
49
50   GtkWidget *separator;
51
52   guint ignore_separator : 1;
53 };
54
55 typedef struct _ResponseData ResponseData;
56
57 struct _ResponseData
58 {
59   gint response_id;
60 };
61
62 static void      gtk_dialog_add_buttons_valist   (GtkDialog    *dialog,
63                                                   const gchar  *first_button_text,
64                                                   va_list       args);
65
66 static gboolean  gtk_dialog_delete_event_handler (GtkWidget    *widget,
67                                                   GdkEventAny  *event,
68                                                   gpointer      user_data);
69
70 static void      gtk_dialog_set_property         (GObject      *object,
71                                                   guint         prop_id,
72                                                   const GValue *value,
73                                                   GParamSpec   *pspec);
74 static void      gtk_dialog_get_property         (GObject      *object,
75                                                   guint         prop_id,
76                                                   GValue       *value,
77                                                   GParamSpec   *pspec);
78 static void      gtk_dialog_style_set            (GtkWidget    *widget,
79                                                   GtkStyle     *prev_style);
80 static void      gtk_dialog_map                  (GtkWidget    *widget);
81
82 static void      gtk_dialog_close                (GtkDialog    *dialog);
83
84 static ResponseData * get_response_data          (GtkWidget    *widget,
85                                                   gboolean      create);
86
87 static void      gtk_dialog_buildable_interface_init     (GtkBuildableIface *iface);
88 static GObject * gtk_dialog_buildable_get_internal_child (GtkBuildable  *buildable,
89                                                           GtkBuilder    *builder,
90                                                           const gchar   *childname);
91 static gboolean  gtk_dialog_buildable_custom_tag_start   (GtkBuildable  *buildable,
92                                                           GtkBuilder    *builder,
93                                                           GObject       *child,
94                                                           const gchar   *tagname,
95                                                           GMarkupParser *parser,
96                                                           gpointer      *data);
97 static void      gtk_dialog_buildable_custom_finished    (GtkBuildable  *buildable,
98                                                           GtkBuilder    *builder,
99                                                           GObject       *child,
100                                                           const gchar   *tagname,
101                                                           gpointer       user_data);
102
103
104 enum {
105   PROP_0,
106   PROP_HAS_SEPARATOR
107 };
108
109 enum {
110   RESPONSE,
111   CLOSE,
112   LAST_SIGNAL
113 };
114
115 static guint dialog_signals[LAST_SIGNAL];
116
117 G_DEFINE_TYPE_WITH_CODE (GtkDialog, gtk_dialog, GTK_TYPE_WINDOW,
118                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
119                                                 gtk_dialog_buildable_interface_init))
120
121 static void
122 gtk_dialog_class_init (GtkDialogClass *class)
123 {
124   GObjectClass *gobject_class;
125   GtkWidgetClass *widget_class;
126   GtkBindingSet *binding_set;
127   
128   gobject_class = G_OBJECT_CLASS (class);
129   widget_class = GTK_WIDGET_CLASS (class);
130   
131   gobject_class->set_property = gtk_dialog_set_property;
132   gobject_class->get_property = gtk_dialog_get_property;
133   
134   widget_class->map = gtk_dialog_map;
135   widget_class->style_set = gtk_dialog_style_set;
136
137   class->close = gtk_dialog_close;
138   
139   g_type_class_add_private (gobject_class, sizeof (GtkDialogPriv));
140
141   /**
142    * GtkDialog:has-separator:
143    *
144    * When %TRUE, the dialog has a separator bar above its buttons.
145    */
146   g_object_class_install_property (gobject_class,
147                                    PROP_HAS_SEPARATOR,
148                                    g_param_spec_boolean ("has-separator",
149                                                          P_("Has separator"),
150                                                          P_("The dialog has a separator bar above its buttons"),
151                                                          TRUE,
152                                                          GTK_PARAM_READWRITE));
153
154   /**
155    * GtkDialog::response:
156    * @dialog: the object on which the signal is emitted
157    * @response_id: the response ID
158    * 
159    * Emitted when an action widget is clicked, the dialog receives a 
160    * delete event, or the application programmer calls gtk_dialog_response(). 
161    * On a delete event, the response ID is #GTK_RESPONSE_DELETE_EVENT. 
162    * Otherwise, it depends on which action widget was clicked.
163    */
164   dialog_signals[RESPONSE] =
165     g_signal_new (I_("response"),
166                   G_OBJECT_CLASS_TYPE (class),
167                   G_SIGNAL_RUN_LAST,
168                   G_STRUCT_OFFSET (GtkDialogClass, response),
169                   NULL, NULL,
170                   _gtk_marshal_VOID__INT,
171                   G_TYPE_NONE, 1,
172                   G_TYPE_INT);
173
174   /**
175    * GtkDialog::close:
176    *
177    * The ::close signal is a 
178    * <link linkend="keybinding-signals">keybinding signal</link>
179    * which gets emitted when the user uses a keybinding to close
180    * the dialog.
181    *
182    * The default binding for this signal is the Escape key.
183    */ 
184   dialog_signals[CLOSE] =
185     g_signal_new (I_("close"),
186                   G_OBJECT_CLASS_TYPE (class),
187                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
188                   G_STRUCT_OFFSET (GtkDialogClass, close),
189                   NULL, NULL,
190                   _gtk_marshal_VOID__VOID,
191                   G_TYPE_NONE, 0);
192   
193   gtk_widget_class_install_style_property (widget_class,
194                                            g_param_spec_int ("content-area-border",
195                                                              P_("Content area border"),
196                                                              P_("Width of border around the main dialog area"),
197                                                              0,
198                                                              G_MAXINT,
199                                                              2,
200                                                              GTK_PARAM_READABLE));
201   /**
202    * GtkDialog:content-area-spacing:
203    *
204    * The default spacing used between elements of the
205    * content area of the dialog, as returned by
206    * gtk_dialog_get_content_area(), unless gtk_box_set_spacing()
207    * was called on that widget directly.
208    *
209    * Since: 2.16
210    */
211   gtk_widget_class_install_style_property (widget_class,
212                                            g_param_spec_int ("content-area-spacing",
213                                                              P_("Content area spacing"),
214                                                              P_("Spacing between elements of the main dialog area"),
215                                                              0,
216                                                              G_MAXINT,
217                                                              0,
218                                                              GTK_PARAM_READABLE));
219   gtk_widget_class_install_style_property (widget_class,
220                                            g_param_spec_int ("button-spacing",
221                                                              P_("Button spacing"),
222                                                              P_("Spacing between buttons"),
223                                                              0,
224                                                              G_MAXINT,
225                                                              6,
226                                                              GTK_PARAM_READABLE));
227   
228   gtk_widget_class_install_style_property (widget_class,
229                                            g_param_spec_int ("action-area-border",
230                                                              P_("Action area border"),
231                                                              P_("Width of border around the button area at the bottom of the dialog"),
232                                                              0,
233                                                              G_MAXINT,
234                                                              5,
235                                                              GTK_PARAM_READABLE));
236
237   binding_set = gtk_binding_set_by_class (class);
238   
239   gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0, "close", 0);
240 }
241
242 static void
243 update_spacings (GtkDialog *dialog)
244 {
245   GtkDialogPriv *priv = dialog->priv;
246   gint content_area_border;
247   gint content_area_spacing;
248   gint button_spacing;
249   gint action_area_border;
250
251   gtk_widget_style_get (GTK_WIDGET (dialog),
252                         "content-area-border", &content_area_border,
253                         "content-area-spacing", &content_area_spacing,
254                         "button-spacing", &button_spacing,
255                         "action-area-border", &action_area_border,
256                         NULL);
257
258   gtk_container_set_border_width (GTK_CONTAINER (priv->vbox),
259                                   content_area_border);
260   if (!_gtk_box_get_spacing_set (GTK_BOX (priv->vbox)))
261     {
262       gtk_box_set_spacing (GTK_BOX (priv->vbox), content_area_spacing);
263       _gtk_box_set_spacing_set (GTK_BOX (priv->vbox), FALSE);
264     }
265   gtk_box_set_spacing (GTK_BOX (priv->action_area),
266                        button_spacing);
267   gtk_container_set_border_width (GTK_CONTAINER (priv->action_area),
268                                   action_area_border);
269 }
270
271 static void
272 gtk_dialog_init (GtkDialog *dialog)
273 {
274   GtkDialogPriv *priv;
275
276   dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
277                                               GTK_TYPE_DIALOG,
278                                               GtkDialogPriv);
279   priv = dialog->priv;
280
281   priv->ignore_separator = FALSE;
282
283   /* To avoid breaking old code that prevents destroy on delete event
284    * by connecting a handler, we have to have the FIRST signal
285    * connection on the dialog.
286    */
287   g_signal_connect (dialog,
288                     "delete-event",
289                     G_CALLBACK (gtk_dialog_delete_event_handler),
290                     NULL);
291
292   priv->vbox = gtk_vbox_new (FALSE, 0);
293
294   gtk_container_add (GTK_CONTAINER (dialog), priv->vbox);
295   gtk_widget_show (priv->vbox);
296
297   priv->action_area = gtk_hbutton_box_new ();
298
299   gtk_button_box_set_layout (GTK_BUTTON_BOX (priv->action_area),
300                              GTK_BUTTONBOX_END);
301
302   gtk_box_pack_end (GTK_BOX (priv->vbox), priv->action_area,
303                     FALSE, TRUE, 0);
304   gtk_widget_show (priv->action_area);
305
306   priv->separator = gtk_hseparator_new ();
307   gtk_box_pack_end (GTK_BOX (priv->vbox), priv->separator, FALSE, TRUE, 0);
308   gtk_widget_show (priv->separator);
309
310   gtk_window_set_type_hint (GTK_WINDOW (dialog),
311                             GDK_WINDOW_TYPE_HINT_DIALOG);
312   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ON_PARENT);
313 }
314
315 static GtkBuildableIface *parent_buildable_iface;
316
317 static void
318 gtk_dialog_buildable_interface_init (GtkBuildableIface *iface)
319 {
320   parent_buildable_iface = g_type_interface_peek_parent (iface);
321   iface->get_internal_child = gtk_dialog_buildable_get_internal_child;
322   iface->custom_tag_start = gtk_dialog_buildable_custom_tag_start;
323   iface->custom_finished = gtk_dialog_buildable_custom_finished;
324 }
325
326 static GObject *
327 gtk_dialog_buildable_get_internal_child (GtkBuildable *buildable,
328                                          GtkBuilder   *builder,
329                                          const gchar  *childname)
330 {
331   GtkDialogPriv *priv = GTK_DIALOG (buildable)->priv;
332
333   if (strcmp (childname, "vbox") == 0)
334     return G_OBJECT (priv->vbox);
335   else if (strcmp (childname, "action_area") == 0)
336     return G_OBJECT (priv->action_area);
337
338   return parent_buildable_iface->get_internal_child (buildable,
339                                                      builder,
340                                                      childname);
341 }
342
343 static void 
344 gtk_dialog_set_property (GObject      *object,
345                          guint         prop_id,
346                          const GValue *value,
347                          GParamSpec   *pspec)
348 {
349   GtkDialog *dialog;
350   
351   dialog = GTK_DIALOG (object);
352   
353   switch (prop_id)
354     {
355     case PROP_HAS_SEPARATOR:
356       gtk_dialog_set_has_separator (dialog, g_value_get_boolean (value));
357       break;
358
359     default:
360       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
361       break;
362     }
363 }
364
365 static void 
366 gtk_dialog_get_property (GObject     *object,
367                          guint        prop_id,
368                          GValue      *value,
369                          GParamSpec  *pspec)
370 {
371   GtkDialog *dialog = GTK_DIALOG (object);
372   GtkDialogPriv *priv = dialog->priv;
373   
374   switch (prop_id)
375     {
376     case PROP_HAS_SEPARATOR:
377       g_value_set_boolean (value, priv->separator != NULL);
378       break;
379
380     default:
381       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
382       break;
383     }
384 }
385
386 static gboolean
387 gtk_dialog_delete_event_handler (GtkWidget   *widget,
388                                  GdkEventAny *event,
389                                  gpointer     user_data)
390 {
391   /* emit response signal */
392   gtk_dialog_response (GTK_DIALOG (widget), GTK_RESPONSE_DELETE_EVENT);
393
394   /* Do the destroy by default */
395   return FALSE;
396 }
397
398 /* A far too tricky heuristic for getting the right initial
399  * focus widget if none was set. What we do is we focus the first
400  * widget in the tab chain, but if this results in the focus
401  * ending up on one of the response widgets _other_ than the
402  * default response, we focus the default response instead.
403  *
404  * Additionally, skip selectable labels when looking for the
405  * right initial focus widget.
406  */
407 static void
408 gtk_dialog_map (GtkWidget *widget)
409 {
410   GtkWidget *default_widget, *focus;
411   GtkWindow *window = GTK_WINDOW (widget);
412   GtkDialog *dialog = GTK_DIALOG (widget);
413   GtkDialogPriv *priv = dialog->priv;
414   
415   GTK_WIDGET_CLASS (gtk_dialog_parent_class)->map (widget);
416
417   focus = gtk_window_get_focus (window);
418   if (!focus)
419     {
420       GList *children, *tmp_list;
421       GtkWidget *first_focus = NULL;
422       
423       do 
424         {
425           g_signal_emit_by_name (window, "move_focus", GTK_DIR_TAB_FORWARD);
426
427           focus = gtk_window_get_focus (window);
428           if (first_focus == NULL)
429             first_focus = focus;
430           else if (first_focus == focus)
431             break;
432           if (!GTK_IS_LABEL (focus))
433             break;
434           if (!gtk_label_get_current_uri (GTK_LABEL (focus)))
435             gtk_label_select_region (GTK_LABEL (focus), 0, 0);
436         }
437       while (TRUE);
438
439       tmp_list = children = gtk_container_get_children (GTK_CONTAINER (priv->action_area));
440       
441       while (tmp_list)
442         {
443           GtkWidget *child = tmp_list->data;
444
445           default_widget = gtk_window_get_default_widget (window);
446           if ((focus == NULL || child == focus) &&
447               child != default_widget &&
448               default_widget)
449             {
450               gtk_widget_grab_focus (default_widget);
451               break;
452             }
453           
454           tmp_list = tmp_list->next;
455         }
456       
457       g_list_free (children);
458     }
459 }
460
461 static void
462 gtk_dialog_style_set (GtkWidget *widget,
463                       GtkStyle  *prev_style)
464 {
465   update_spacings (GTK_DIALOG (widget));
466 }
467
468 static GtkWidget *
469 dialog_find_button (GtkDialog *dialog,
470                     gint       response_id)
471 {
472   GtkDialogPriv *priv = dialog->priv;
473   GtkWidget *child = NULL;
474   GList *children, *tmp_list;
475       
476   children = gtk_container_get_children (GTK_CONTAINER (priv->action_area));
477
478   for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
479     {
480       ResponseData *rd = get_response_data (tmp_list->data, FALSE);
481       
482       if (rd && rd->response_id == response_id)
483         {
484           child = tmp_list->data;
485           break;
486         }
487     }
488
489   g_list_free (children);
490
491   return child;
492 }
493
494 static void
495 gtk_dialog_close (GtkDialog *dialog)
496 {
497   /* Synthesize delete_event to close dialog. */
498   
499   GtkWidget *widget = GTK_WIDGET (dialog);
500   GdkEvent *event;
501
502   event = gdk_event_new (GDK_DELETE);
503
504   event->any.window = g_object_ref (gtk_widget_get_window (widget));
505   event->any.send_event = TRUE;
506   
507   gtk_main_do_event (event);
508   gdk_event_free (event);
509 }
510
511 GtkWidget*
512 gtk_dialog_new (void)
513 {
514   return g_object_new (GTK_TYPE_DIALOG, NULL);
515 }
516
517 static GtkWidget*
518 gtk_dialog_new_empty (const gchar     *title,
519                       GtkWindow       *parent,
520                       GtkDialogFlags   flags)
521 {
522   GtkDialog *dialog;
523
524   dialog = g_object_new (GTK_TYPE_DIALOG, NULL);
525
526   if (title)
527     gtk_window_set_title (GTK_WINDOW (dialog), title);
528
529   if (parent)
530     gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
531
532   if (flags & GTK_DIALOG_MODAL)
533     gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
534   
535   if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
536     gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
537
538   if (flags & GTK_DIALOG_NO_SEPARATOR)
539     gtk_dialog_set_has_separator (dialog, FALSE);
540   
541   return GTK_WIDGET (dialog);
542 }
543
544 /**
545  * gtk_dialog_new_with_buttons:
546  * @title: (allow-none): Title of the dialog, or %NULL
547  * @parent: (allow-none): Transient parent of the dialog, or %NULL
548  * @flags: from #GtkDialogFlags
549  * @first_button_text: (allow-none): stock ID or text to go in first button, or %NULL
550  * @Varargs: response ID for first button, then additional buttons, ending with %NULL
551  *
552  * Creates a new #GtkDialog with title @title (or %NULL for the default
553  * title; see gtk_window_set_title()) and transient parent @parent (or
554  * %NULL for none; see gtk_window_set_transient_for()). The @flags
555  * argument can be used to make the dialog modal (#GTK_DIALOG_MODAL)
556  * and/or to have it destroyed along with its transient parent
557  * (#GTK_DIALOG_DESTROY_WITH_PARENT). After @flags, button
558  * text/response ID pairs should be listed, with a %NULL pointer ending
559  * the list. Button text can be either a stock ID such as
560  * #GTK_STOCK_OK, or some arbitrary text. A response ID can be
561  * any positive number, or one of the values in the #GtkResponseType
562  * enumeration. If the user clicks one of these dialog buttons,
563  * #GtkDialog will emit the #GtkDialog::response signal with the corresponding
564  * response ID. If a #GtkDialog receives the #GtkWidget::delete-event signal, 
565  * it will emit ::response with a response ID of #GTK_RESPONSE_DELETE_EVENT.
566  * However, destroying a dialog does not emit the ::response signal;
567  * so be careful relying on ::response when using the 
568  * #GTK_DIALOG_DESTROY_WITH_PARENT flag. Buttons are from left to right,
569  * so the first button in the list will be the leftmost button in the dialog.
570  *
571  * Here's a simple example:
572  * |[
573  *  GtkWidget *dialog = gtk_dialog_new_with_buttons ("My dialog",
574  *                                                   main_app_window,
575  *                                                   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
576  *                                                   GTK_STOCK_OK,
577  *                                                   GTK_RESPONSE_ACCEPT,
578  *                                                   GTK_STOCK_CANCEL,
579  *                                                   GTK_RESPONSE_REJECT,
580  *                                                   NULL);
581  * ]|
582  * 
583  * Return value: a new #GtkDialog
584  **/
585 GtkWidget*
586 gtk_dialog_new_with_buttons (const gchar    *title,
587                              GtkWindow      *parent,
588                              GtkDialogFlags  flags,
589                              const gchar    *first_button_text,
590                              ...)
591 {
592   GtkDialog *dialog;
593   va_list args;
594   
595   dialog = GTK_DIALOG (gtk_dialog_new_empty (title, parent, flags));
596
597   va_start (args, first_button_text);
598
599   gtk_dialog_add_buttons_valist (dialog,
600                                  first_button_text,
601                                  args);
602   
603   va_end (args);
604
605   return GTK_WIDGET (dialog);
606 }
607
608 static void 
609 response_data_free (gpointer data)
610 {
611   g_slice_free (ResponseData, data);
612 }
613
614 static ResponseData*
615 get_response_data (GtkWidget *widget,
616                    gboolean   create)
617 {
618   ResponseData *ad = g_object_get_data (G_OBJECT (widget),
619                                         "gtk-dialog-response-data");
620
621   if (ad == NULL && create)
622     {
623       ad = g_slice_new (ResponseData);
624       
625       g_object_set_data_full (G_OBJECT (widget),
626                               I_("gtk-dialog-response-data"),
627                               ad,
628                               response_data_free);
629     }
630
631   return ad;
632 }
633
634 static void
635 action_widget_activated (GtkWidget *widget, GtkDialog *dialog)
636 {
637   gint response_id;
638   
639   response_id = gtk_dialog_get_response_for_widget (dialog, widget);
640
641   gtk_dialog_response (dialog, response_id);
642 }
643
644 /**
645  * gtk_dialog_add_action_widget:
646  * @dialog: a #GtkDialog
647  * @child: an activatable widget
648  * @response_id: response ID for @child
649  * 
650  * Adds an activatable widget to the action area of a #GtkDialog,
651  * connecting a signal handler that will emit the #GtkDialog::response 
652  * signal on the dialog when the widget is activated. The widget is 
653  * appended to the end of the dialog's action area. If you want to add a
654  * non-activatable widget, simply pack it into the @action_area field 
655  * of the #GtkDialog struct.
656  **/
657 void
658 gtk_dialog_add_action_widget (GtkDialog *dialog,
659                               GtkWidget *child,
660                               gint       response_id)
661 {
662   GtkDialogPriv *priv;
663   ResponseData *ad;
664   guint signal_id;
665   
666   g_return_if_fail (GTK_IS_DIALOG (dialog));
667   g_return_if_fail (GTK_IS_WIDGET (child));
668
669   priv = dialog->priv;
670
671   ad = get_response_data (child, TRUE);
672
673   ad->response_id = response_id;
674
675   if (GTK_IS_BUTTON (child))
676     signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
677   else
678     signal_id = GTK_WIDGET_GET_CLASS (child)->activate_signal;
679
680   if (signal_id)
681     {
682       GClosure *closure;
683
684       closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
685                                        G_OBJECT (dialog));
686       g_signal_connect_closure_by_id (child,
687                                       signal_id,
688                                       0,
689                                       closure,
690                                       FALSE);
691     }
692   else
693     g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkDialog");
694
695   gtk_box_pack_end (GTK_BOX (priv->action_area),
696                     child,
697                     FALSE, TRUE, 0);
698   
699   if (response_id == GTK_RESPONSE_HELP)
700     gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (priv->action_area), child, TRUE);
701 }
702
703 /**
704  * gtk_dialog_add_button:
705  * @dialog: a #GtkDialog
706  * @button_text: text of button, or stock ID
707  * @response_id: response ID for the button
708  * 
709  * Adds a button with the given text (or a stock button, if @button_text is a
710  * stock ID) and sets things up so that clicking the button will emit the
711  * #GtkDialog::response signal with the given @response_id. The button is 
712  * appended to the end of the dialog's action area. The button widget is 
713  * returned, but usually you don't need it.
714  *
715  * Return value: the button widget that was added
716  **/
717 GtkWidget*
718 gtk_dialog_add_button (GtkDialog   *dialog,
719                        const gchar *button_text,
720                        gint         response_id)
721 {
722   GtkWidget *button;
723   
724   g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
725   g_return_val_if_fail (button_text != NULL, NULL);
726
727   button = gtk_button_new_from_stock (button_text);
728
729   gtk_widget_set_can_default (button, TRUE);
730   
731   gtk_widget_show (button);
732   
733   gtk_dialog_add_action_widget (dialog,
734                                 button,
735                                 response_id);
736
737   return button;
738 }
739
740 static void
741 gtk_dialog_add_buttons_valist (GtkDialog      *dialog,
742                                const gchar    *first_button_text,
743                                va_list         args)
744 {
745   const gchar* text;
746   gint response_id;
747
748   g_return_if_fail (GTK_IS_DIALOG (dialog));
749   
750   if (first_button_text == NULL)
751     return;
752   
753   text = first_button_text;
754   response_id = va_arg (args, gint);
755
756   while (text != NULL)
757     {
758       gtk_dialog_add_button (dialog, text, response_id);
759
760       text = va_arg (args, gchar*);
761       if (text == NULL)
762         break;
763       response_id = va_arg (args, int);
764     }
765 }
766
767 /**
768  * gtk_dialog_add_buttons:
769  * @dialog: a #GtkDialog
770  * @first_button_text: button text or stock ID
771  * @Varargs: response ID for first button, then more text-response_id pairs
772  * 
773  * Adds more buttons, same as calling gtk_dialog_add_button()
774  * repeatedly.  The variable argument list should be %NULL-terminated
775  * as with gtk_dialog_new_with_buttons(). Each button must have both
776  * text and response ID.
777  **/
778 void
779 gtk_dialog_add_buttons (GtkDialog   *dialog,
780                         const gchar *first_button_text,
781                         ...)
782 {  
783   va_list args;
784
785   va_start (args, first_button_text);
786
787   gtk_dialog_add_buttons_valist (dialog,
788                                  first_button_text,
789                                  args);
790   
791   va_end (args);
792 }
793
794 /**
795  * gtk_dialog_set_response_sensitive:
796  * @dialog: a #GtkDialog
797  * @response_id: a response ID
798  * @setting: %TRUE for sensitive
799  *
800  * Calls <literal>gtk_widget_set_sensitive (widget, @setting)</literal> 
801  * for each widget in the dialog's action area with the given @response_id.
802  * A convenient way to sensitize/desensitize dialog buttons.
803  **/
804 void
805 gtk_dialog_set_response_sensitive (GtkDialog *dialog,
806                                    gint       response_id,
807                                    gboolean   setting)
808 {
809   GtkDialogPriv *priv;
810   GList *children;
811   GList *tmp_list;
812
813   g_return_if_fail (GTK_IS_DIALOG (dialog));
814
815   priv = dialog->priv;
816
817   children = gtk_container_get_children (GTK_CONTAINER (priv->action_area));
818
819   tmp_list = children;
820   while (tmp_list != NULL)
821     {
822       GtkWidget *widget = tmp_list->data;
823       ResponseData *rd = get_response_data (widget, FALSE);
824
825       if (rd && rd->response_id == response_id)
826         gtk_widget_set_sensitive (widget, setting);
827
828       tmp_list = g_list_next (tmp_list);
829     }
830
831   g_list_free (children);
832 }
833
834 /**
835  * gtk_dialog_set_default_response:
836  * @dialog: a #GtkDialog
837  * @response_id: a response ID
838  * 
839  * Sets the last widget in the dialog's action area with the given @response_id
840  * as the default widget for the dialog. Pressing "Enter" normally activates
841  * the default widget.
842  **/
843 void
844 gtk_dialog_set_default_response (GtkDialog *dialog,
845                                  gint       response_id)
846 {
847   GtkDialogPriv *priv;
848   GList *children;
849   GList *tmp_list;
850
851   g_return_if_fail (GTK_IS_DIALOG (dialog));
852
853   priv = dialog->priv;
854
855   children = gtk_container_get_children (GTK_CONTAINER (priv->action_area));
856
857   tmp_list = children;
858   while (tmp_list != NULL)
859     {
860       GtkWidget *widget = tmp_list->data;
861       ResponseData *rd = get_response_data (widget, FALSE);
862
863       if (rd && rd->response_id == response_id)
864         gtk_widget_grab_default (widget);
865             
866       tmp_list = g_list_next (tmp_list);
867     }
868
869   g_list_free (children);
870 }
871
872 /**
873  * gtk_dialog_set_has_separator:
874  * @dialog: a #GtkDialog
875  * @setting: %TRUE to have a separator
876  *
877  * Sets whether the dialog has a separator above the buttons.
878  * %TRUE by default.
879  **/
880 void
881 gtk_dialog_set_has_separator (GtkDialog *dialog,
882                               gboolean   setting)
883 {
884   GtkDialogPriv *priv;
885
886   g_return_if_fail (GTK_IS_DIALOG (dialog));
887
888   priv = dialog->priv;
889
890   /* this might fail if we get called before _init() somehow */
891   g_assert (priv->vbox != NULL);
892
893   if (priv->ignore_separator)
894     {
895       g_warning ("Ignoring the separator setting");
896       return;
897     }
898   
899   if (setting && priv->separator == NULL)
900     {
901       priv->separator = gtk_hseparator_new ();
902       gtk_box_pack_end (GTK_BOX (priv->vbox), priv->separator, FALSE, TRUE, 0);
903
904       /* The app programmer could screw this up, but, their own fault.
905        * Moves the separator just above the action area.
906        */
907       gtk_box_reorder_child (GTK_BOX (priv->vbox), priv->separator, 1);
908       gtk_widget_show (priv->separator);
909     }
910   else if (!setting && priv->separator != NULL)
911     {
912       gtk_widget_destroy (priv->separator);
913       priv->separator = NULL;
914     }
915
916   g_object_notify (G_OBJECT (dialog), "has-separator");
917 }
918
919 /**
920  * gtk_dialog_get_has_separator:
921  * @dialog: a #GtkDialog
922  * 
923  * Accessor for whether the dialog has a separator.
924  * 
925  * Return value: %TRUE if the dialog has a separator
926  **/
927 gboolean
928 gtk_dialog_get_has_separator (GtkDialog *dialog)
929 {
930   g_return_val_if_fail (GTK_IS_DIALOG (dialog), FALSE);
931
932   return dialog->priv->separator != NULL;
933 }
934
935 /**
936  * gtk_dialog_response:
937  * @dialog: a #GtkDialog
938  * @response_id: response ID 
939  * 
940  * Emits the #GtkDialog::response signal with the given response ID. 
941  * Used to indicate that the user has responded to the dialog in some way;
942  * typically either you or gtk_dialog_run() will be monitoring the
943  * ::response signal and take appropriate action.
944  **/
945 void
946 gtk_dialog_response (GtkDialog *dialog,
947                      gint       response_id)
948 {
949   g_return_if_fail (GTK_IS_DIALOG (dialog));
950
951   g_signal_emit (dialog,
952                  dialog_signals[RESPONSE],
953                  0,
954                  response_id);
955 }
956
957 typedef struct
958 {
959   GtkDialog *dialog;
960   gint response_id;
961   GMainLoop *loop;
962   gboolean destroyed;
963 } RunInfo;
964
965 static void
966 shutdown_loop (RunInfo *ri)
967 {
968   if (g_main_loop_is_running (ri->loop))
969     g_main_loop_quit (ri->loop);
970 }
971
972 static void
973 run_unmap_handler (GtkDialog *dialog, gpointer data)
974 {
975   RunInfo *ri = data;
976
977   shutdown_loop (ri);
978 }
979
980 static void
981 run_response_handler (GtkDialog *dialog,
982                       gint response_id,
983                       gpointer data)
984 {
985   RunInfo *ri;
986
987   ri = data;
988
989   ri->response_id = response_id;
990
991   shutdown_loop (ri);
992 }
993
994 static gint
995 run_delete_handler (GtkDialog *dialog,
996                     GdkEventAny *event,
997                     gpointer data)
998 {
999   RunInfo *ri = data;
1000     
1001   shutdown_loop (ri);
1002   
1003   return TRUE; /* Do not destroy */
1004 }
1005
1006 static void
1007 run_destroy_handler (GtkDialog *dialog, gpointer data)
1008 {
1009   RunInfo *ri = data;
1010
1011   /* shutdown_loop will be called by run_unmap_handler */
1012   
1013   ri->destroyed = TRUE;
1014 }
1015
1016 /**
1017  * gtk_dialog_run:
1018  * @dialog: a #GtkDialog
1019  * 
1020  * Blocks in a recursive main loop until the @dialog either emits the
1021  * #GtkDialog::response signal, or is destroyed. If the dialog is 
1022  * destroyed during the call to gtk_dialog_run(), gtk_dialog_run() returns 
1023  * #GTK_RESPONSE_NONE. Otherwise, it returns the response ID from the 
1024  * ::response signal emission.
1025  *
1026  * Before entering the recursive main loop, gtk_dialog_run() calls
1027  * gtk_widget_show() on the dialog for you. Note that you still
1028  * need to show any children of the dialog yourself.
1029  *
1030  * During gtk_dialog_run(), the default behavior of #GtkWidget::delete-event 
1031  * is disabled; if the dialog receives ::delete_event, it will not be
1032  * destroyed as windows usually are, and gtk_dialog_run() will return
1033  * #GTK_RESPONSE_DELETE_EVENT. Also, during gtk_dialog_run() the dialog 
1034  * will be modal. You can force gtk_dialog_run() to return at any time by
1035  * calling gtk_dialog_response() to emit the ::response signal. Destroying 
1036  * the dialog during gtk_dialog_run() is a very bad idea, because your 
1037  * post-run code won't know whether the dialog was destroyed or not.
1038  *
1039  * After gtk_dialog_run() returns, you are responsible for hiding or
1040  * destroying the dialog if you wish to do so.
1041  *
1042  * Typical usage of this function might be:
1043  * |[
1044  *   gint result = gtk_dialog_run (GTK_DIALOG (dialog));
1045  *   switch (result)
1046  *     {
1047  *       case GTK_RESPONSE_ACCEPT:
1048  *          do_application_specific_something ();
1049  *          break;
1050  *       default:
1051  *          do_nothing_since_dialog_was_cancelled ();
1052  *          break;
1053  *     }
1054  *   gtk_widget_destroy (dialog);
1055  * ]|
1056  * 
1057  * Note that even though the recursive main loop gives the effect of a
1058  * modal dialog (it prevents the user from interacting with other 
1059  * windows in the same window group while the dialog is run), callbacks 
1060  * such as timeouts, IO channel watches, DND drops, etc, <emphasis>will</emphasis> 
1061  * be triggered during a gtk_dialog_run() call.
1062  * 
1063  * Return value: response ID
1064  **/
1065 gint
1066 gtk_dialog_run (GtkDialog *dialog)
1067 {
1068   RunInfo ri = { NULL, GTK_RESPONSE_NONE, NULL, FALSE };
1069   gboolean was_modal;
1070   gulong response_handler;
1071   gulong unmap_handler;
1072   gulong destroy_handler;
1073   gulong delete_handler;
1074   
1075   g_return_val_if_fail (GTK_IS_DIALOG (dialog), -1);
1076
1077   g_object_ref (dialog);
1078
1079   was_modal = gtk_window_get_modal (GTK_WINDOW (dialog));
1080   if (!was_modal)
1081     gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
1082
1083   if (!gtk_widget_get_visible (GTK_WIDGET (dialog)))
1084     gtk_widget_show (GTK_WIDGET (dialog));
1085   
1086   response_handler =
1087     g_signal_connect (dialog,
1088                       "response",
1089                       G_CALLBACK (run_response_handler),
1090                       &ri);
1091   
1092   unmap_handler =
1093     g_signal_connect (dialog,
1094                       "unmap",
1095                       G_CALLBACK (run_unmap_handler),
1096                       &ri);
1097   
1098   delete_handler =
1099     g_signal_connect (dialog,
1100                       "delete-event",
1101                       G_CALLBACK (run_delete_handler),
1102                       &ri);
1103   
1104   destroy_handler =
1105     g_signal_connect (dialog,
1106                       "destroy",
1107                       G_CALLBACK (run_destroy_handler),
1108                       &ri);
1109   
1110   ri.loop = g_main_loop_new (NULL, FALSE);
1111
1112   GDK_THREADS_LEAVE ();  
1113   g_main_loop_run (ri.loop);
1114   GDK_THREADS_ENTER ();  
1115
1116   g_main_loop_unref (ri.loop);
1117
1118   ri.loop = NULL;
1119   
1120   if (!ri.destroyed)
1121     {
1122       if (!was_modal)
1123         gtk_window_set_modal (GTK_WINDOW(dialog), FALSE);
1124       
1125       g_signal_handler_disconnect (dialog, response_handler);
1126       g_signal_handler_disconnect (dialog, unmap_handler);
1127       g_signal_handler_disconnect (dialog, delete_handler);
1128       g_signal_handler_disconnect (dialog, destroy_handler);
1129     }
1130
1131   g_object_unref (dialog);
1132
1133   return ri.response_id;
1134 }
1135
1136 void
1137 _gtk_dialog_set_ignore_separator (GtkDialog *dialog,
1138                                   gboolean   ignore_separator)
1139 {
1140   GtkDialogPriv *priv = dialog->priv;
1141
1142   priv->ignore_separator = ignore_separator;
1143 }
1144
1145 /**
1146  * gtk_dialog_get_widget_for_response:
1147  * @dialog: a #GtkDialog
1148  * @response_id: the response ID used by the @dialog widget
1149  *
1150  * Gets the widget button that uses the given response ID in the action area
1151  * of a dialog.
1152  *
1153  * Returns: the @widget button that uses the given @response_id, or %NULL.
1154  *
1155  * Since: 2.20
1156  */
1157 GtkWidget*
1158 gtk_dialog_get_widget_for_response (GtkDialog *dialog,
1159                                     gint       response_id)
1160 {
1161   GtkDialogPriv *priv;
1162   GList *children;
1163   GList *tmp_list;
1164
1165   g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
1166
1167   priv = dialog->priv;
1168
1169   children = gtk_container_get_children (GTK_CONTAINER (priv->action_area));
1170
1171   tmp_list = children;
1172   while (tmp_list != NULL)
1173     {
1174       GtkWidget *widget = tmp_list->data;
1175       ResponseData *rd = get_response_data (widget, FALSE);
1176
1177       if (rd && rd->response_id == response_id)
1178         {
1179           g_list_free (children);
1180           return widget;
1181         }
1182
1183       tmp_list = g_list_next (tmp_list);
1184     }
1185
1186   g_list_free (children);
1187
1188   return NULL;
1189 }
1190
1191 /**
1192  * gtk_dialog_get_response_for_widget:
1193  * @dialog: a #GtkDialog
1194  * @widget: a widget in the action area of @dialog
1195  *
1196  * Gets the response id of a widget in the action area
1197  * of a dialog.
1198  *
1199  * Returns: the response id of @widget, or %GTK_RESPONSE_NONE
1200  *  if @widget doesn't have a response id set.
1201  *
1202  * Since: 2.8
1203  */
1204 gint
1205 gtk_dialog_get_response_for_widget (GtkDialog *dialog,
1206                                     GtkWidget *widget)
1207 {
1208   ResponseData *rd;
1209
1210   rd = get_response_data (widget, FALSE);
1211   if (!rd)
1212     return GTK_RESPONSE_NONE;
1213   else
1214     return rd->response_id;
1215 }
1216
1217 /**
1218  * gtk_alternative_dialog_button_order:
1219  * @screen: (allow-none): a #GdkScreen, or %NULL to use the default screen
1220  *
1221  * Returns %TRUE if dialogs are expected to use an alternative
1222  * button order on the screen @screen. See
1223  * gtk_dialog_set_alternative_button_order() for more details
1224  * about alternative button order. 
1225  *
1226  * If you need to use this function, you should probably connect
1227  * to the ::notify:gtk-alternative-button-order signal on the
1228  * #GtkSettings object associated to @screen, in order to be 
1229  * notified if the button order setting changes.
1230  *
1231  * Returns: Whether the alternative button order should be used
1232  *
1233  * Since: 2.6
1234  */
1235 gboolean 
1236 gtk_alternative_dialog_button_order (GdkScreen *screen)
1237 {
1238   GtkSettings *settings;
1239   gboolean result;
1240
1241   if (screen)
1242     settings = gtk_settings_get_for_screen (screen);
1243   else
1244     settings = gtk_settings_get_default ();
1245   
1246   g_object_get (settings,
1247                 "gtk-alternative-button-order", &result, NULL);
1248
1249   return result;
1250 }
1251
1252 static void
1253 gtk_dialog_set_alternative_button_order_valist (GtkDialog *dialog,
1254                                                 gint       first_response_id,
1255                                                 va_list    args)
1256 {
1257   GtkDialogPriv *priv = dialog->priv;
1258   GtkWidget *child;
1259   gint response_id;
1260   gint position;
1261
1262   response_id = first_response_id;
1263   position = 0;
1264   while (response_id != -1)
1265     {
1266       /* reorder child with response_id to position */
1267       child = dialog_find_button (dialog, response_id);
1268       gtk_box_reorder_child (GTK_BOX (priv->action_area), child, position);
1269
1270       response_id = va_arg (args, gint);
1271       position++;
1272     }
1273 }
1274
1275 /**
1276  * gtk_dialog_set_alternative_button_order:
1277  * @dialog: a #GtkDialog
1278  * @first_response_id: a response id used by one @dialog's buttons
1279  * @Varargs: a list of more response ids of @dialog's buttons, terminated by -1
1280  *
1281  * Sets an alternative button order. If the 
1282  * #GtkSettings:gtk-alternative-button-order setting is set to %TRUE, 
1283  * the dialog buttons are reordered according to the order of the 
1284  * response ids passed to this function.
1285  *
1286  * By default, GTK+ dialogs use the button order advocated by the Gnome 
1287  * <ulink url="http://developer.gnome.org/projects/gup/hig/2.0/">Human 
1288  * Interface Guidelines</ulink> with the affirmative button at the far 
1289  * right, and the cancel button left of it. But the builtin GTK+ dialogs
1290  * and #GtkMessageDialog<!-- -->s do provide an alternative button order,
1291  * which is more suitable on some platforms, e.g. Windows.
1292  *
1293  * Use this function after adding all the buttons to your dialog, as the 
1294  * following example shows:
1295  * |[
1296  * cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
1297  *                                        GTK_STOCK_CANCEL,
1298  *                                        GTK_RESPONSE_CANCEL);
1299  *  
1300  * ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
1301  *                                    GTK_STOCK_OK,
1302  *                                    GTK_RESPONSE_OK);
1303  *   
1304  * gtk_widget_grab_default (ok_button);
1305  *   
1306  * help_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
1307  *                                      GTK_STOCK_HELP,
1308  *                                      GTK_RESPONSE_HELP);
1309  *  
1310  * gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
1311  *                                          GTK_RESPONSE_OK,
1312  *                                          GTK_RESPONSE_CANCEL,
1313  *                                          GTK_RESPONSE_HELP,
1314  *                                          -1);
1315  * ]|
1316  * 
1317  * Since: 2.6
1318  */
1319 void 
1320 gtk_dialog_set_alternative_button_order (GtkDialog *dialog,
1321                                          gint       first_response_id,
1322                                          ...)
1323 {
1324   GdkScreen *screen;
1325   va_list args;
1326   
1327   g_return_if_fail (GTK_IS_DIALOG (dialog));
1328
1329   screen = gtk_widget_get_screen (GTK_WIDGET (dialog));
1330   if (!gtk_alternative_dialog_button_order (screen))
1331       return;
1332
1333   va_start (args, first_response_id);
1334
1335   gtk_dialog_set_alternative_button_order_valist (dialog,
1336                                                   first_response_id,
1337                                                   args);
1338   va_end (args);
1339 }
1340 /**
1341  * gtk_dialog_set_alternative_button_order_from_array:
1342  * @dialog: a #GtkDialog
1343  * @n_params: the number of response ids in @new_order
1344  * @new_order: an array of response ids of @dialog's buttons
1345  *
1346  * Sets an alternative button order. If the 
1347  * #GtkSettings:gtk-alternative-button-order setting is set to %TRUE, 
1348  * the dialog buttons are reordered according to the order of the 
1349  * response ids in @new_order.
1350  *
1351  * See gtk_dialog_set_alternative_button_order() for more information.
1352  *
1353  * This function is for use by language bindings.
1354  * 
1355  * Since: 2.6
1356  */
1357 void 
1358 gtk_dialog_set_alternative_button_order_from_array (GtkDialog *dialog,
1359                                                     gint       n_params,
1360                                                     gint      *new_order)
1361 {
1362   GtkDialogPriv *priv = dialog->priv;
1363   GdkScreen *screen;
1364   GtkWidget *child;
1365   gint position;
1366
1367   g_return_if_fail (GTK_IS_DIALOG (dialog));
1368   g_return_if_fail (new_order != NULL);
1369
1370   screen = gtk_widget_get_screen (GTK_WIDGET (dialog));
1371   if (!gtk_alternative_dialog_button_order (screen))
1372       return;
1373
1374   for (position = 0; position < n_params; position++)
1375   {
1376       /* reorder child with response_id to position */
1377       child = dialog_find_button (dialog, new_order[position]);
1378       gtk_box_reorder_child (GTK_BOX (priv->action_area), child, position);
1379     }
1380 }
1381
1382 typedef struct {
1383   gchar *widget_name;
1384   gchar *response_id;
1385 } ActionWidgetInfo;
1386
1387 typedef struct {
1388   GtkDialog *dialog;
1389   GtkBuilder *builder;
1390   GSList *items;
1391   gchar *response;
1392 } ActionWidgetsSubParserData;
1393
1394 static void
1395 attributes_start_element (GMarkupParseContext *context,
1396                           const gchar         *element_name,
1397                           const gchar        **names,
1398                           const gchar        **values,
1399                           gpointer             user_data,
1400                           GError             **error)
1401 {
1402   ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
1403   guint i;
1404
1405   if (strcmp (element_name, "action-widget") == 0)
1406     {
1407       for (i = 0; names[i]; i++)
1408         if (strcmp (names[i], "response") == 0)
1409           parser_data->response = g_strdup (values[i]);
1410     }
1411   else if (strcmp (element_name, "action-widgets") == 0)
1412     return;
1413   else
1414     g_warning ("Unsupported tag for GtkDialog: %s\n", element_name);
1415 }
1416
1417 static void
1418 attributes_text_element (GMarkupParseContext *context,
1419                          const gchar         *text,
1420                          gsize                text_len,
1421                          gpointer             user_data,
1422                          GError             **error)
1423 {
1424   ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
1425   ActionWidgetInfo *item;
1426
1427   if (!parser_data->response)
1428     return;
1429
1430   item = g_new (ActionWidgetInfo, 1);
1431   item->widget_name = g_strndup (text, text_len);
1432   item->response_id = parser_data->response;
1433   parser_data->items = g_slist_prepend (parser_data->items, item);
1434   parser_data->response = NULL;
1435 }
1436
1437 static const GMarkupParser attributes_parser =
1438   {
1439     attributes_start_element,
1440     NULL,
1441     attributes_text_element,
1442   };
1443
1444 static gboolean
1445 gtk_dialog_buildable_custom_tag_start (GtkBuildable  *buildable,
1446                                        GtkBuilder    *builder,
1447                                        GObject       *child,
1448                                        const gchar   *tagname,
1449                                        GMarkupParser *parser,
1450                                        gpointer      *data)
1451 {
1452   ActionWidgetsSubParserData *parser_data;
1453
1454   if (child)
1455     return FALSE;
1456
1457   if (strcmp (tagname, "action-widgets") == 0)
1458     {
1459       parser_data = g_slice_new0 (ActionWidgetsSubParserData);
1460       parser_data->dialog = GTK_DIALOG (buildable);
1461       parser_data->items = NULL;
1462
1463       *parser = attributes_parser;
1464       *data = parser_data;
1465       return TRUE;
1466     }
1467
1468   return parent_buildable_iface->custom_tag_start (buildable, builder, child,
1469                                                    tagname, parser, data);
1470 }
1471
1472 static void
1473 gtk_dialog_buildable_custom_finished (GtkBuildable *buildable,
1474                                       GtkBuilder   *builder,
1475                                       GObject      *child,
1476                                       const gchar  *tagname,
1477                                       gpointer      user_data)
1478 {
1479   GtkDialog *dialog = GTK_DIALOG (buildable);
1480   GtkDialogPriv *priv = dialog->priv;
1481   GSList *l;
1482   ActionWidgetsSubParserData *parser_data;
1483   GObject *object;
1484   ResponseData *ad;
1485   guint signal_id;
1486   
1487   if (strcmp (tagname, "action-widgets"))
1488     {
1489     parent_buildable_iface->custom_finished (buildable, builder, child,
1490                                              tagname, user_data);
1491     return;
1492     }
1493
1494   parser_data = (ActionWidgetsSubParserData*)user_data;
1495   parser_data->items = g_slist_reverse (parser_data->items);
1496
1497   for (l = parser_data->items; l; l = l->next)
1498     {
1499       ActionWidgetInfo *item = l->data;
1500
1501       object = gtk_builder_get_object (builder, item->widget_name);
1502       if (!object)
1503         {
1504           g_warning ("Unknown object %s specified in action-widgets of %s",
1505                      item->widget_name,
1506                      gtk_buildable_get_name (GTK_BUILDABLE (buildable)));
1507           continue;
1508         }
1509
1510       ad = get_response_data (GTK_WIDGET (object), TRUE);
1511       ad->response_id = atoi (item->response_id);
1512
1513       if (GTK_IS_BUTTON (object))
1514         signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
1515       else
1516         signal_id = GTK_WIDGET_GET_CLASS (object)->activate_signal;
1517       
1518       if (signal_id)
1519         {
1520           GClosure *closure;
1521           
1522           closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
1523                                            G_OBJECT (dialog));
1524           g_signal_connect_closure_by_id (object,
1525                                           signal_id,
1526                                           0,
1527                                           closure,
1528                                           FALSE);
1529         }
1530
1531       if (ad->response_id == GTK_RESPONSE_HELP)
1532         gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (priv->action_area),
1533                                             GTK_WIDGET (object), TRUE);
1534
1535       g_free (item->widget_name);
1536       g_free (item->response_id);
1537       g_free (item);
1538     }
1539   g_slist_free (parser_data->items);
1540   g_slice_free (ActionWidgetsSubParserData, parser_data);
1541 }
1542
1543 /**
1544  * gtk_dialog_get_action_area:
1545  * @dialog: a #GtkDialog
1546  *
1547  * Returns the action area of @dialog.
1548  *
1549  * Returns: (transfer none): the action area.
1550  *
1551  * Since: 2.14
1552  **/
1553 GtkWidget *
1554 gtk_dialog_get_action_area (GtkDialog *dialog)
1555 {
1556   g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
1557
1558   return dialog->priv->action_area;
1559 }
1560
1561 /**
1562  * gtk_dialog_get_content_area:
1563  * @dialog: a #GtkDialog
1564  *
1565  * Returns the content area of @dialog.
1566  *
1567  * Returns: (transfer none): the content area #GtkVBox.
1568  *
1569  * Since: 2.14
1570  **/
1571 GtkWidget *
1572 gtk_dialog_get_content_area (GtkDialog *dialog)
1573 {
1574   g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
1575
1576   return dialog->priv->vbox;
1577 }