1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
28 #include "gtkbutton.h"
29 #include "gtkdialog.h"
32 #include "gtkhseparator.h"
33 #include "gtkmarshalers.h"
35 #include "gdkkeysyms.h"
38 #include "gtkbindings.h"
39 #include "gtkprivate.h"
42 #define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_DIALOG, GtkDialogPrivate))
45 guint ignore_separator : 1;
48 typedef struct _ResponseData ResponseData;
55 static void gtk_dialog_class_init (GtkDialogClass *klass);
56 static void gtk_dialog_init (GtkDialog *dialog);
58 static void gtk_dialog_add_buttons_valist (GtkDialog *dialog,
59 const gchar *first_button_text,
62 static gint gtk_dialog_delete_event_handler (GtkWidget *widget,
66 static void gtk_dialog_set_property (GObject *object,
70 static void gtk_dialog_get_property (GObject *object,
74 static void gtk_dialog_style_set (GtkWidget *widget,
75 GtkStyle *prev_style);
76 static void gtk_dialog_map (GtkWidget *widget);
78 static void gtk_dialog_close (GtkDialog *dialog);
80 static ResponseData* get_response_data (GtkWidget *widget,
94 static gpointer parent_class;
95 static guint dialog_signals[LAST_SIGNAL];
98 gtk_dialog_get_type (void)
100 static GType dialog_type = 0;
104 static const GTypeInfo dialog_info =
106 sizeof (GtkDialogClass),
107 NULL, /* base_init */
108 NULL, /* base_finalize */
109 (GClassInitFunc) gtk_dialog_class_init,
110 NULL, /* class_finalize */
111 NULL, /* class_data */
114 (GInstanceInitFunc) gtk_dialog_init,
117 dialog_type = g_type_register_static (GTK_TYPE_WINDOW, I_("GtkDialog"),
125 gtk_dialog_class_init (GtkDialogClass *class)
127 GObjectClass *gobject_class;
128 GtkWidgetClass *widget_class;
129 GtkBindingSet *binding_set;
131 gobject_class = G_OBJECT_CLASS (class);
132 widget_class = GTK_WIDGET_CLASS (class);
134 parent_class = g_type_class_peek_parent (class);
136 gobject_class->set_property = gtk_dialog_set_property;
137 gobject_class->get_property = gtk_dialog_get_property;
139 widget_class->map = gtk_dialog_map;
140 widget_class->style_set = gtk_dialog_style_set;
142 class->close = gtk_dialog_close;
144 g_type_class_add_private (gobject_class, sizeof (GtkDialogPrivate));
146 g_object_class_install_property (gobject_class,
148 g_param_spec_boolean ("has-separator",
150 P_("The dialog has a separator bar above its buttons"),
152 GTK_PARAM_READWRITE));
154 dialog_signals[RESPONSE] =
155 g_signal_new (I_("response"),
156 G_OBJECT_CLASS_TYPE (class),
158 G_STRUCT_OFFSET (GtkDialogClass, response),
160 _gtk_marshal_NONE__INT,
164 dialog_signals[CLOSE] =
165 g_signal_new (I_("close"),
166 G_OBJECT_CLASS_TYPE (class),
167 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
168 G_STRUCT_OFFSET (GtkDialogClass, close),
170 _gtk_marshal_NONE__NONE,
173 gtk_widget_class_install_style_property (widget_class,
174 g_param_spec_int ("content-area-border",
175 P_("Content area border"),
176 P_("Width of border around the main dialog area"),
180 GTK_PARAM_READABLE));
181 gtk_widget_class_install_style_property (widget_class,
182 g_param_spec_int ("button-spacing",
183 P_("Button spacing"),
184 P_("Spacing between buttons"),
188 GTK_PARAM_READABLE));
190 gtk_widget_class_install_style_property (widget_class,
191 g_param_spec_int ("action-area-border",
192 P_("Action area border"),
193 P_("Width of border around the button area at the bottom of the dialog"),
197 GTK_PARAM_READABLE));
199 binding_set = gtk_binding_set_by_class (class);
201 gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
206 update_spacings (GtkDialog *dialog)
209 gint content_area_border;
211 gint action_area_border;
213 widget = GTK_WIDGET (dialog);
215 gtk_widget_style_get (widget,
216 "content-area-border", &content_area_border,
217 "button-spacing", &button_spacing,
218 "action-area-border", &action_area_border,
221 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox),
222 content_area_border);
223 gtk_box_set_spacing (GTK_BOX (dialog->action_area),
225 gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area),
230 gtk_dialog_init (GtkDialog *dialog)
232 GtkDialogPrivate *priv;
234 priv = GET_PRIVATE (dialog);
235 priv->ignore_separator = FALSE;
237 /* To avoid breaking old code that prevents destroy on delete event
238 * by connecting a handler, we have to have the FIRST signal
239 * connection on the dialog.
241 g_signal_connect (dialog,
243 G_CALLBACK (gtk_dialog_delete_event_handler),
246 dialog->vbox = gtk_vbox_new (FALSE, 0);
248 gtk_container_add (GTK_CONTAINER (dialog), dialog->vbox);
249 gtk_widget_show (dialog->vbox);
251 dialog->action_area = gtk_hbutton_box_new ();
253 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog->action_area),
256 gtk_box_pack_end (GTK_BOX (dialog->vbox), dialog->action_area,
258 gtk_widget_show (dialog->action_area);
260 dialog->separator = gtk_hseparator_new ();
261 gtk_box_pack_end (GTK_BOX (dialog->vbox), dialog->separator, FALSE, TRUE, 0);
262 gtk_widget_show (dialog->separator);
264 gtk_window_set_type_hint (GTK_WINDOW (dialog),
265 GDK_WINDOW_TYPE_HINT_DIALOG);
266 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ON_PARENT);
271 gtk_dialog_set_property (GObject *object,
278 dialog = GTK_DIALOG (object);
282 case PROP_HAS_SEPARATOR:
283 gtk_dialog_set_has_separator (dialog, g_value_get_boolean (value));
287 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
293 gtk_dialog_get_property (GObject *object,
300 dialog = GTK_DIALOG (object);
304 case PROP_HAS_SEPARATOR:
305 g_value_set_boolean (value, dialog->separator != NULL);
309 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
315 gtk_dialog_delete_event_handler (GtkWidget *widget,
319 /* emit response signal */
320 gtk_dialog_response (GTK_DIALOG (widget), GTK_RESPONSE_DELETE_EVENT);
322 /* Do the destroy by default */
326 /* A far too tricky heuristic for getting the right initial
327 * focus widget if none was set. What we do is we focus the first
328 * widget in the tab chain, but if this results in the focus
329 * ending up on one of the response widgets _other_ than the
330 * default response, we focus the default response instead.
332 * Additionally, skip selectable labels when looking for the
333 * right initial focus widget.
336 gtk_dialog_map (GtkWidget *widget)
338 GtkWindow *window = GTK_WINDOW (widget);
339 GtkDialog *dialog = GTK_DIALOG (widget);
341 GTK_WIDGET_CLASS (parent_class)->map (widget);
343 if (!window->focus_widget)
345 GList *children, *tmp_list;
346 GtkWidget *first_focus = NULL;
350 g_signal_emit_by_name (window, "move_focus", GTK_DIR_TAB_FORWARD);
352 if (first_focus == NULL)
353 first_focus = window->focus_widget;
354 else if (first_focus == window->focus_widget)
357 if (!GTK_IS_LABEL (window->focus_widget))
360 gtk_label_select_region (GTK_LABEL (window->focus_widget), 0, 0);
364 tmp_list = children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area));
368 GtkWidget *child = tmp_list->data;
370 if ((window->focus_widget == NULL ||
371 child == window->focus_widget) &&
372 child != window->default_widget &&
373 window->default_widget)
375 gtk_widget_grab_focus (window->default_widget);
379 tmp_list = tmp_list->next;
382 g_list_free (children);
387 gtk_dialog_style_set (GtkWidget *widget,
388 GtkStyle *prev_style)
390 update_spacings (GTK_DIALOG (widget));
394 dialog_find_button (GtkDialog *dialog,
397 GList *children, *tmp_list;
398 GtkWidget *child = NULL;
400 children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area));
402 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
404 ResponseData *rd = get_response_data (tmp_list->data, FALSE);
406 if (rd && rd->response_id == response_id)
408 child = tmp_list->data;
413 g_list_free (children);
419 gtk_dialog_close (GtkDialog *dialog)
421 /* Synthesize delete_event to close dialog. */
423 GtkWidget *widget = GTK_WIDGET (dialog);
426 if (!dialog_find_button (dialog, GTK_RESPONSE_CANCEL))
429 event = gdk_event_new (GDK_DELETE);
431 event->any.window = g_object_ref (widget->window);
432 event->any.send_event = TRUE;
434 gtk_main_do_event (event);
435 gdk_event_free (event);
439 gtk_dialog_new (void)
441 return g_object_new (GTK_TYPE_DIALOG, NULL);
445 gtk_dialog_new_empty (const gchar *title,
447 GtkDialogFlags flags)
451 dialog = g_object_new (GTK_TYPE_DIALOG, NULL);
454 gtk_window_set_title (GTK_WINDOW (dialog), title);
457 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
459 if (flags & GTK_DIALOG_MODAL)
460 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
462 if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
463 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
465 if (flags & GTK_DIALOG_NO_SEPARATOR)
466 gtk_dialog_set_has_separator (dialog, FALSE);
468 return GTK_WIDGET (dialog);
472 * gtk_dialog_new_with_buttons:
473 * @title: Title of the dialog, or %NULL
474 * @parent: Transient parent of the dialog, or %NULL
475 * @flags: from #GtkDialogFlags
476 * @first_button_text: stock ID or text to go in first button, or %NULL
477 * @Varargs: response ID for first button, then additional buttons, ending with %NULL
479 * Creates a new #GtkDialog with title @title (or %NULL for the default
480 * title; see gtk_window_set_title()) and transient parent @parent (or
481 * %NULL for none; see gtk_window_set_transient_for()). The @flags
482 * argument can be used to make the dialog modal (#GTK_DIALOG_MODAL)
483 * and/or to have it destroyed along with its transient parent
484 * (#GTK_DIALOG_DESTROY_WITH_PARENT). After @flags, button
485 * text/response ID pairs should be listed, with a %NULL pointer ending
486 * the list. Button text can be either a stock ID such as
487 * #GTK_STOCK_OK, or some arbitrary text. A response ID can be
488 * any positive number, or one of the values in the #GtkResponseType
489 * enumeration. If the user clicks one of these dialog buttons,
490 * #GtkDialog will emit the "response" signal with the corresponding
491 * response ID. If a #GtkDialog receives the "delete_event" signal, it
492 * will emit "response" with a response ID of #GTK_RESPONSE_DELETE_EVENT.
493 * However, destroying a dialog does not emit the "response" signal;
494 * so be careful relying on "response" when using
495 * the #GTK_DIALOG_DESTROY_WITH_PARENT flag. Buttons are from left to right,
496 * so the first button in the list will be the leftmost button in the dialog.
498 * Here's a simple example:
499 * <informalexample><programlisting>
500 * GtkWidget *dialog = gtk_dialog_new_with_buttons ("My dialog",
502 * GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
504 * GTK_RESPONSE_ACCEPT,
506 * GTK_RESPONSE_REJECT,
508 * </programlisting></informalexample>
510 * Return value: a new #GtkDialog
513 gtk_dialog_new_with_buttons (const gchar *title,
515 GtkDialogFlags flags,
516 const gchar *first_button_text,
522 dialog = GTK_DIALOG (gtk_dialog_new_empty (title, parent, flags));
524 va_start (args, first_button_text);
526 gtk_dialog_add_buttons_valist (dialog,
532 return GTK_WIDGET (dialog);
536 get_response_data (GtkWidget *widget,
539 ResponseData *ad = g_object_get_data (G_OBJECT (widget),
540 "gtk-dialog-response-data");
542 if (ad == NULL && create)
544 ad = g_new (ResponseData, 1);
546 g_object_set_data_full (G_OBJECT (widget),
547 I_("gtk-dialog-response-data"),
556 action_widget_activated (GtkWidget *widget, GtkDialog *dialog)
560 response_id = gtk_dialog_get_response_for_widget (dialog, widget);
562 gtk_dialog_response (dialog, response_id);
566 * gtk_dialog_add_action_widget:
567 * @dialog: a #GtkDialog
568 * @child: an activatable widget
569 * @response_id: response ID for @child
571 * Adds an activatable widget to the action area of a #GtkDialog,
572 * connecting a signal handler that will emit the "response" signal on
573 * the dialog when the widget is activated. The widget is appended to
574 * the end of the dialog's action area. If you want to add a
575 * non-activatable widget, simply pack it into the
576 * <literal>action_area</literal> field of the #GtkDialog struct.
579 gtk_dialog_add_action_widget (GtkDialog *dialog,
586 g_return_if_fail (GTK_IS_DIALOG (dialog));
587 g_return_if_fail (GTK_IS_WIDGET (child));
589 ad = get_response_data (child, TRUE);
591 ad->response_id = response_id;
593 if (GTK_IS_BUTTON (child))
594 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
596 signal_id = GTK_WIDGET_GET_CLASS (child)->activate_signal;
602 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
604 g_signal_connect_closure_by_id (child,
611 g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkDialog");
613 gtk_box_pack_end (GTK_BOX (dialog->action_area),
617 if (response_id == GTK_RESPONSE_HELP)
618 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (dialog->action_area), child, TRUE);
622 * gtk_dialog_add_button:
623 * @dialog: a #GtkDialog
624 * @button_text: text of button, or stock ID
625 * @response_id: response ID for the button
627 * Adds a button with the given text (or a stock button, if @button_text is a
628 * stock ID) and sets things up so that clicking the button will emit the
629 * "response" signal with the given @response_id. The button is appended to the
630 * end of the dialog's action area. The button widget is returned, but usually
633 * Return value: the button widget that was added
636 gtk_dialog_add_button (GtkDialog *dialog,
637 const gchar *button_text,
642 g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
643 g_return_val_if_fail (button_text != NULL, NULL);
645 button = gtk_button_new_from_stock (button_text);
647 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
649 gtk_widget_show (button);
651 gtk_dialog_add_action_widget (dialog,
659 gtk_dialog_add_buttons_valist (GtkDialog *dialog,
660 const gchar *first_button_text,
666 g_return_if_fail (GTK_IS_DIALOG (dialog));
668 if (first_button_text == NULL)
671 text = first_button_text;
672 response_id = va_arg (args, gint);
676 gtk_dialog_add_button (dialog, text, response_id);
678 text = va_arg (args, gchar*);
681 response_id = va_arg (args, int);
686 * gtk_dialog_add_buttons:
687 * @dialog: a #GtkDialog
688 * @first_button_text: button text or stock ID
689 * @Varargs: response ID for first button, then more text-response_id pairs
691 * Adds more buttons, same as calling gtk_dialog_add_button()
692 * repeatedly. The variable argument list should be %NULL-terminated
693 * as with gtk_dialog_new_with_buttons(). Each button must have both
694 * text and response ID.
697 gtk_dialog_add_buttons (GtkDialog *dialog,
698 const gchar *first_button_text,
703 va_start (args, first_button_text);
705 gtk_dialog_add_buttons_valist (dialog,
713 * gtk_dialog_set_response_sensitive:
714 * @dialog: a #GtkDialog
715 * @response_id: a response ID
716 * @setting: %TRUE for sensitive
718 * Calls <literal>gtk_widget_set_sensitive (widget, @setting)</literal>
719 * for each widget in the dialog's action area with the given @response_id.
720 * A convenient way to sensitize/desensitize dialog buttons.
723 gtk_dialog_set_response_sensitive (GtkDialog *dialog,
730 g_return_if_fail (GTK_IS_DIALOG (dialog));
732 children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area));
735 while (tmp_list != NULL)
737 GtkWidget *widget = tmp_list->data;
738 ResponseData *rd = get_response_data (widget, FALSE);
740 if (rd && rd->response_id == response_id)
741 gtk_widget_set_sensitive (widget, setting);
743 tmp_list = g_list_next (tmp_list);
746 g_list_free (children);
750 * gtk_dialog_set_default_response:
751 * @dialog: a #GtkDialog
752 * @response_id: a response ID
754 * Sets the last widget in the dialog's action area with the given @response_id
755 * as the default widget for the dialog. Pressing "Enter" normally activates
756 * the default widget.
759 gtk_dialog_set_default_response (GtkDialog *dialog,
765 g_return_if_fail (GTK_IS_DIALOG (dialog));
767 children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area));
770 while (tmp_list != NULL)
772 GtkWidget *widget = tmp_list->data;
773 ResponseData *rd = get_response_data (widget, FALSE);
775 if (rd && rd->response_id == response_id)
776 gtk_widget_grab_default (widget);
778 tmp_list = g_list_next (tmp_list);
781 g_list_free (children);
785 * gtk_dialog_set_has_separator:
786 * @dialog: a #GtkDialog
787 * @setting: %TRUE to have a separator
789 * Sets whether the dialog has a separator above the buttons.
793 gtk_dialog_set_has_separator (GtkDialog *dialog,
796 GtkDialogPrivate *priv;
798 g_return_if_fail (GTK_IS_DIALOG (dialog));
800 priv = GET_PRIVATE (dialog);
802 /* this might fail if we get called before _init() somehow */
803 g_assert (dialog->vbox != NULL);
805 if (priv->ignore_separator)
807 g_warning ("Ignoring the separator setting");
811 if (setting && dialog->separator == NULL)
813 dialog->separator = gtk_hseparator_new ();
814 gtk_box_pack_end (GTK_BOX (dialog->vbox), dialog->separator, FALSE, TRUE, 0);
816 /* The app programmer could screw this up, but, their own fault.
817 * Moves the separator just above the action area.
819 gtk_box_reorder_child (GTK_BOX (dialog->vbox), dialog->separator, 1);
820 gtk_widget_show (dialog->separator);
822 else if (!setting && dialog->separator != NULL)
824 gtk_widget_destroy (dialog->separator);
825 dialog->separator = NULL;
828 g_object_notify (G_OBJECT (dialog), "has-separator");
832 * gtk_dialog_get_has_separator:
833 * @dialog: a #GtkDialog
835 * Accessor for whether the dialog has a separator.
837 * Return value: %TRUE if the dialog has a separator
840 gtk_dialog_get_has_separator (GtkDialog *dialog)
842 g_return_val_if_fail (GTK_IS_DIALOG (dialog), FALSE);
844 return dialog->separator != NULL;
848 * gtk_dialog_response:
849 * @dialog: a #GtkDialog
850 * @response_id: response ID
852 * Emits the "response" signal with the given response ID. Used to
853 * indicate that the user has responded to the dialog in some way;
854 * typically either you or gtk_dialog_run() will be monitoring the
855 * "response" signal and take appropriate action.
858 gtk_dialog_response (GtkDialog *dialog,
861 g_return_if_fail (GTK_IS_DIALOG (dialog));
863 g_signal_emit (dialog,
864 dialog_signals[RESPONSE],
878 shutdown_loop (RunInfo *ri)
880 if (g_main_loop_is_running (ri->loop))
881 g_main_loop_quit (ri->loop);
885 run_unmap_handler (GtkDialog *dialog, gpointer data)
893 run_response_handler (GtkDialog *dialog,
901 ri->response_id = response_id;
907 run_delete_handler (GtkDialog *dialog,
915 return TRUE; /* Do not destroy */
919 run_destroy_handler (GtkDialog *dialog, gpointer data)
923 /* shutdown_loop will be called by run_unmap_handler */
925 ri->destroyed = TRUE;
930 * @dialog: a #GtkDialog
932 * Blocks in a recursive main loop until the @dialog either emits the
933 * response signal, or is destroyed. If the dialog is destroyed during the call
934 * to gtk_dialog_run(), gtk_dialog_returns #GTK_RESPONSE_NONE.
935 * Otherwise, it returns the response ID from the "response" signal emission.
936 * Before entering the recursive main loop, gtk_dialog_run() calls
937 * gtk_widget_show() on the dialog for you. Note that you still
938 * need to show any children of the dialog yourself.
940 * During gtk_dialog_run(), the default behavior of "delete_event" is
941 * disabled; if the dialog receives "delete_event", it will not be
942 * destroyed as windows usually are, and gtk_dialog_run() will return
943 * #GTK_RESPONSE_DELETE_EVENT. Also, during gtk_dialog_run() the dialog will be
944 * modal. You can force gtk_dialog_run() to return at any time by
945 * calling gtk_dialog_response() to emit the "response"
946 * signal. Destroying the dialog during gtk_dialog_run() is a very bad
947 * idea, because your post-run code won't know whether the dialog was
950 * After gtk_dialog_run() returns, you are responsible for hiding or
951 * destroying the dialog if you wish to do so.
953 * Typical usage of this function might be:
954 * <informalexample><programlisting>
955 * gint result = gtk_dialog_run (GTK_DIALOG (dialog));
958 * case GTK_RESPONSE_ACCEPT:
959 * do_application_specific_something (<!-- -->);
962 * do_nothing_since_dialog_was_cancelled (<!-- -->);
965 * gtk_widget_destroy (dialog);
966 * </programlisting></informalexample>
968 * Note that even though the recursive main loop gives the effect of a
969 * modal dialog (it prevents the user from interacting with other
970 * windows in the same window group while the dialog is run), callbacks
971 * such as timeouts, IO channel watches, DND drops, etc, <emphasis>will</emphasis>
972 * be triggered during a gtk_dialog_run() call.
974 * Return value: response ID
977 gtk_dialog_run (GtkDialog *dialog)
979 RunInfo ri = { NULL, GTK_RESPONSE_NONE, NULL, FALSE };
981 gulong response_handler;
982 gulong unmap_handler;
983 gulong destroy_handler;
984 gulong delete_handler;
986 g_return_val_if_fail (GTK_IS_DIALOG (dialog), -1);
988 g_object_ref (dialog);
990 was_modal = GTK_WINDOW (dialog)->modal;
992 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
994 if (!GTK_WIDGET_VISIBLE (dialog))
995 gtk_widget_show (GTK_WIDGET (dialog));
998 g_signal_connect (dialog,
1000 G_CALLBACK (run_response_handler),
1004 g_signal_connect (dialog,
1006 G_CALLBACK (run_unmap_handler),
1010 g_signal_connect (dialog,
1012 G_CALLBACK (run_delete_handler),
1016 g_signal_connect (dialog,
1018 G_CALLBACK (run_destroy_handler),
1021 ri.loop = g_main_loop_new (NULL, FALSE);
1023 GDK_THREADS_LEAVE ();
1024 g_main_loop_run (ri.loop);
1025 GDK_THREADS_ENTER ();
1027 g_main_loop_unref (ri.loop);
1034 gtk_window_set_modal (GTK_WINDOW(dialog), FALSE);
1036 g_signal_handler_disconnect (dialog, response_handler);
1037 g_signal_handler_disconnect (dialog, unmap_handler);
1038 g_signal_handler_disconnect (dialog, delete_handler);
1039 g_signal_handler_disconnect (dialog, destroy_handler);
1042 g_object_unref (dialog);
1044 return ri.response_id;
1048 _gtk_dialog_set_ignore_separator (GtkDialog *dialog,
1049 gboolean ignore_separator)
1051 GtkDialogPrivate *priv;
1053 priv = GET_PRIVATE (dialog);
1054 priv->ignore_separator = ignore_separator;
1058 * gtk_dialog_get_response_for_widget:
1059 * @dialog: a #GtkDialog
1060 * @widget: a widget in the action area of @dialog
1062 * Gets the response id of a widget in the action area
1065 * Returns: the response id of @widget, or %GTK_RESPONSE_NONE
1066 * if @widget doesn't have a response id set.
1071 gtk_dialog_get_response_for_widget (GtkDialog *dialog,
1076 rd = get_response_data (widget, FALSE);
1078 return GTK_RESPONSE_NONE;
1080 return rd->response_id;
1084 * gtk_alternative_dialog_button_order:
1085 * @screen: a #GdkScreen, or %NULL to use the default screen
1087 * Returns %TRUE if dialogs are expected to use an alternative
1088 * button order on the screen @screen. See
1089 * gtk_dialog_set_alternative_button_order() for more details
1090 * about alternative button order.
1092 * If you need to use this function, you should probably connect
1093 * to the ::notify:gtk-alternative-button-order signal on the
1094 * #GtkSettings object associated to @screen, in order to be
1095 * notified if the button order setting changes.
1097 * Returns: Whether the alternative button order should be used
1102 gtk_alternative_dialog_button_order (GdkScreen *screen)
1104 GtkSettings *settings;
1108 settings = gtk_settings_get_for_screen (screen);
1110 settings = gtk_settings_get_default ();
1112 g_object_get (settings,
1113 "gtk-alternative-button-order", &result, NULL);
1119 gtk_dialog_set_alternative_button_order_valist (GtkDialog *dialog,
1120 gint first_response_id,
1127 response_id = first_response_id;
1129 while (response_id != -1)
1131 /* reorder child with response_id to position */
1132 child = dialog_find_button (dialog, response_id);
1133 gtk_box_reorder_child (GTK_BOX (dialog->action_area), child, position);
1135 response_id = va_arg (args, gint);
1141 * gtk_dialog_set_alternative_button_order:
1142 * @dialog: a #GtkDialog
1143 * @first_response_id: a response id used by one @dialog's buttons
1144 * @Varargs: a list of more response ids of @dialog's buttons, terminated by -1
1146 * Sets an alternative button order. If the gtk-alternative-button-order
1147 * setting is set to %TRUE, the dialog buttons are reordered according to
1148 * the order of the response ids passed to this function.
1150 * By default, GTK+ dialogs use the button order advocated by the Gnome
1151 * <ulink url="http://developer.gnome.org/projects/gup/hig/2.0/">Human
1152 * Interface Guidelines</ulink> with the affirmative button at the far
1153 * right, and the cancel button left of it. But the builtin GTK+ dialogs
1154 * and #GtkMessageDialog<!-- -->s do provide an alternative button order,
1155 * which is more suitable on some platforms, e.g. Windows.
1157 * Use this function after adding all the buttons to your dialog, as the
1158 * following example shows:
1159 * <informalexample><programlisting>
1160 * cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
1162 * GTK_RESPONSE_CANCEL);
1164 * ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
1168 * gtk_widget_grab_default (ok_button);
1170 * help_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
1172 * GTK_RESPONSE_HELP);
1174 * gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
1176 * GTK_RESPONSE_CANCEL,
1177 * GTK_RESPONSE_HELP,
1179 * </programlisting></informalexample>
1184 gtk_dialog_set_alternative_button_order (GtkDialog *dialog,
1185 gint first_response_id,
1191 g_return_if_fail (GTK_IS_DIALOG (dialog));
1193 screen = gtk_widget_get_screen (GTK_WIDGET (dialog));
1194 if (!gtk_alternative_dialog_button_order (screen))
1197 va_start (args, first_response_id);
1199 gtk_dialog_set_alternative_button_order_valist (dialog,
1205 * gtk_dialog_set_alternative_button_order_from_array:
1206 * @dialog: a #GtkDialog
1207 * @n_params: the number of response ids in @new_order
1208 * @new_order: an array of response ids of @dialog's buttons
1210 * Sets an alternative button order. If the gtk-alternative-button-order
1211 * setting is set to %TRUE, the dialog buttons are reordered according to
1212 * the order of the response ids in @new_order.
1214 * See gtk_dialog_set_alternative_button_order() for more information.
1216 * This function is for use by language bindings.
1221 gtk_dialog_set_alternative_button_order_from_array (GtkDialog *dialog,
1229 g_return_if_fail (GTK_IS_DIALOG (dialog));
1230 g_return_if_fail (new_order != NULL);
1232 screen = gtk_widget_get_screen (GTK_WIDGET (dialog));
1233 if (!gtk_alternative_dialog_button_order (screen))
1236 for (position = 0; position < n_params; position++)
1238 /* reorder child with response_id to position */
1239 child = dialog_find_button (dialog, new_order[position]);
1240 gtk_box_reorder_child (GTK_BOX (dialog->action_area), child, position);
1244 #define __GTK_DIALOG_C__
1245 #include "gtkaliasdef.c"