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_add_buttons_valist (GtkDialog *dialog,
56 const gchar *first_button_text,
59 static gint gtk_dialog_delete_event_handler (GtkWidget *widget,
63 static void gtk_dialog_set_property (GObject *object,
67 static void gtk_dialog_get_property (GObject *object,
71 static void gtk_dialog_style_set (GtkWidget *widget,
72 GtkStyle *prev_style);
73 static void gtk_dialog_map (GtkWidget *widget);
75 static void gtk_dialog_close (GtkDialog *dialog);
77 static ResponseData* get_response_data (GtkWidget *widget,
91 static guint dialog_signals[LAST_SIGNAL];
93 G_DEFINE_TYPE (GtkDialog, gtk_dialog, GTK_TYPE_WINDOW)
96 gtk_dialog_class_init (GtkDialogClass *class)
98 GObjectClass *gobject_class;
99 GtkWidgetClass *widget_class;
100 GtkBindingSet *binding_set;
102 gobject_class = G_OBJECT_CLASS (class);
103 widget_class = GTK_WIDGET_CLASS (class);
105 gobject_class->set_property = gtk_dialog_set_property;
106 gobject_class->get_property = gtk_dialog_get_property;
108 widget_class->map = gtk_dialog_map;
109 widget_class->style_set = gtk_dialog_style_set;
111 class->close = gtk_dialog_close;
113 g_type_class_add_private (gobject_class, sizeof (GtkDialogPrivate));
115 g_object_class_install_property (gobject_class,
117 g_param_spec_boolean ("has-separator",
119 P_("The dialog has a separator bar above its buttons"),
121 GTK_PARAM_READWRITE));
123 dialog_signals[RESPONSE] =
124 g_signal_new (I_("response"),
125 G_OBJECT_CLASS_TYPE (class),
127 G_STRUCT_OFFSET (GtkDialogClass, response),
129 _gtk_marshal_NONE__INT,
133 dialog_signals[CLOSE] =
134 g_signal_new (I_("close"),
135 G_OBJECT_CLASS_TYPE (class),
136 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
137 G_STRUCT_OFFSET (GtkDialogClass, close),
139 _gtk_marshal_NONE__NONE,
142 gtk_widget_class_install_style_property (widget_class,
143 g_param_spec_int ("content-area-border",
144 P_("Content area border"),
145 P_("Width of border around the main dialog area"),
149 GTK_PARAM_READABLE));
150 gtk_widget_class_install_style_property (widget_class,
151 g_param_spec_int ("button-spacing",
152 P_("Button spacing"),
153 P_("Spacing between buttons"),
157 GTK_PARAM_READABLE));
159 gtk_widget_class_install_style_property (widget_class,
160 g_param_spec_int ("action-area-border",
161 P_("Action area border"),
162 P_("Width of border around the button area at the bottom of the dialog"),
166 GTK_PARAM_READABLE));
168 binding_set = gtk_binding_set_by_class (class);
170 gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
175 update_spacings (GtkDialog *dialog)
178 gint content_area_border;
180 gint action_area_border;
182 widget = GTK_WIDGET (dialog);
184 gtk_widget_style_get (widget,
185 "content-area-border", &content_area_border,
186 "button-spacing", &button_spacing,
187 "action-area-border", &action_area_border,
190 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox),
191 content_area_border);
192 gtk_box_set_spacing (GTK_BOX (dialog->action_area),
194 gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area),
199 gtk_dialog_init (GtkDialog *dialog)
201 GtkDialogPrivate *priv;
203 priv = GET_PRIVATE (dialog);
204 priv->ignore_separator = FALSE;
206 /* To avoid breaking old code that prevents destroy on delete event
207 * by connecting a handler, we have to have the FIRST signal
208 * connection on the dialog.
210 g_signal_connect (dialog,
212 G_CALLBACK (gtk_dialog_delete_event_handler),
215 dialog->vbox = gtk_vbox_new (FALSE, 0);
217 gtk_container_add (GTK_CONTAINER (dialog), dialog->vbox);
218 gtk_widget_show (dialog->vbox);
220 dialog->action_area = gtk_hbutton_box_new ();
222 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog->action_area),
225 gtk_box_pack_end (GTK_BOX (dialog->vbox), dialog->action_area,
227 gtk_widget_show (dialog->action_area);
229 dialog->separator = gtk_hseparator_new ();
230 gtk_box_pack_end (GTK_BOX (dialog->vbox), dialog->separator, FALSE, TRUE, 0);
231 gtk_widget_show (dialog->separator);
233 gtk_window_set_type_hint (GTK_WINDOW (dialog),
234 GDK_WINDOW_TYPE_HINT_DIALOG);
235 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ON_PARENT);
240 gtk_dialog_set_property (GObject *object,
247 dialog = GTK_DIALOG (object);
251 case PROP_HAS_SEPARATOR:
252 gtk_dialog_set_has_separator (dialog, g_value_get_boolean (value));
256 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
262 gtk_dialog_get_property (GObject *object,
269 dialog = GTK_DIALOG (object);
273 case PROP_HAS_SEPARATOR:
274 g_value_set_boolean (value, dialog->separator != NULL);
278 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
284 gtk_dialog_delete_event_handler (GtkWidget *widget,
288 /* emit response signal */
289 gtk_dialog_response (GTK_DIALOG (widget), GTK_RESPONSE_DELETE_EVENT);
291 /* Do the destroy by default */
295 /* A far too tricky heuristic for getting the right initial
296 * focus widget if none was set. What we do is we focus the first
297 * widget in the tab chain, but if this results in the focus
298 * ending up on one of the response widgets _other_ than the
299 * default response, we focus the default response instead.
301 * Additionally, skip selectable labels when looking for the
302 * right initial focus widget.
305 gtk_dialog_map (GtkWidget *widget)
307 GtkWindow *window = GTK_WINDOW (widget);
308 GtkDialog *dialog = GTK_DIALOG (widget);
310 GTK_WIDGET_CLASS (gtk_dialog_parent_class)->map (widget);
312 if (!window->focus_widget)
314 GList *children, *tmp_list;
315 GtkWidget *first_focus = NULL;
319 g_signal_emit_by_name (window, "move_focus", GTK_DIR_TAB_FORWARD);
321 if (first_focus == NULL)
322 first_focus = window->focus_widget;
323 else if (first_focus == window->focus_widget)
326 if (!GTK_IS_LABEL (window->focus_widget))
329 gtk_label_select_region (GTK_LABEL (window->focus_widget), 0, 0);
333 tmp_list = children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area));
337 GtkWidget *child = tmp_list->data;
339 if ((window->focus_widget == NULL ||
340 child == window->focus_widget) &&
341 child != window->default_widget &&
342 window->default_widget)
344 gtk_widget_grab_focus (window->default_widget);
348 tmp_list = tmp_list->next;
351 g_list_free (children);
356 gtk_dialog_style_set (GtkWidget *widget,
357 GtkStyle *prev_style)
359 update_spacings (GTK_DIALOG (widget));
363 dialog_find_button (GtkDialog *dialog,
366 GList *children, *tmp_list;
367 GtkWidget *child = NULL;
369 children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area));
371 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
373 ResponseData *rd = get_response_data (tmp_list->data, FALSE);
375 if (rd && rd->response_id == response_id)
377 child = tmp_list->data;
382 g_list_free (children);
388 gtk_dialog_close (GtkDialog *dialog)
390 /* Synthesize delete_event to close dialog. */
392 GtkWidget *widget = GTK_WIDGET (dialog);
395 event = gdk_event_new (GDK_DELETE);
397 event->any.window = g_object_ref (widget->window);
398 event->any.send_event = TRUE;
400 gtk_main_do_event (event);
401 gdk_event_free (event);
405 gtk_dialog_new (void)
407 return g_object_new (GTK_TYPE_DIALOG, NULL);
411 gtk_dialog_new_empty (const gchar *title,
413 GtkDialogFlags flags)
417 dialog = g_object_new (GTK_TYPE_DIALOG, NULL);
420 gtk_window_set_title (GTK_WINDOW (dialog), title);
423 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
425 if (flags & GTK_DIALOG_MODAL)
426 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
428 if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
429 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
431 if (flags & GTK_DIALOG_NO_SEPARATOR)
432 gtk_dialog_set_has_separator (dialog, FALSE);
434 return GTK_WIDGET (dialog);
438 * gtk_dialog_new_with_buttons:
439 * @title: Title of the dialog, or %NULL
440 * @parent: Transient parent of the dialog, or %NULL
441 * @flags: from #GtkDialogFlags
442 * @first_button_text: stock ID or text to go in first button, or %NULL
443 * @Varargs: response ID for first button, then additional buttons, ending with %NULL
445 * Creates a new #GtkDialog with title @title (or %NULL for the default
446 * title; see gtk_window_set_title()) and transient parent @parent (or
447 * %NULL for none; see gtk_window_set_transient_for()). The @flags
448 * argument can be used to make the dialog modal (#GTK_DIALOG_MODAL)
449 * and/or to have it destroyed along with its transient parent
450 * (#GTK_DIALOG_DESTROY_WITH_PARENT). After @flags, button
451 * text/response ID pairs should be listed, with a %NULL pointer ending
452 * the list. Button text can be either a stock ID such as
453 * #GTK_STOCK_OK, or some arbitrary text. A response ID can be
454 * any positive number, or one of the values in the #GtkResponseType
455 * enumeration. If the user clicks one of these dialog buttons,
456 * #GtkDialog will emit the "response" signal with the corresponding
457 * response ID. If a #GtkDialog receives the "delete_event" signal, it
458 * will emit "response" with a response ID of #GTK_RESPONSE_DELETE_EVENT.
459 * However, destroying a dialog does not emit the "response" signal;
460 * so be careful relying on "response" when using
461 * the #GTK_DIALOG_DESTROY_WITH_PARENT flag. Buttons are from left to right,
462 * so the first button in the list will be the leftmost button in the dialog.
464 * Here's a simple example:
465 * <informalexample><programlisting>
466 * GtkWidget *dialog = gtk_dialog_new_with_buttons ("My dialog",
468 * GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
470 * GTK_RESPONSE_ACCEPT,
472 * GTK_RESPONSE_REJECT,
474 * </programlisting></informalexample>
476 * Return value: a new #GtkDialog
479 gtk_dialog_new_with_buttons (const gchar *title,
481 GtkDialogFlags flags,
482 const gchar *first_button_text,
488 dialog = GTK_DIALOG (gtk_dialog_new_empty (title, parent, flags));
490 va_start (args, first_button_text);
492 gtk_dialog_add_buttons_valist (dialog,
498 return GTK_WIDGET (dialog);
502 response_data_free (gpointer data)
504 g_slice_free (ResponseData, data);
508 get_response_data (GtkWidget *widget,
511 ResponseData *ad = g_object_get_data (G_OBJECT (widget),
512 "gtk-dialog-response-data");
514 if (ad == NULL && create)
516 ad = g_slice_new (ResponseData);
518 g_object_set_data_full (G_OBJECT (widget),
519 I_("gtk-dialog-response-data"),
528 action_widget_activated (GtkWidget *widget, GtkDialog *dialog)
532 response_id = gtk_dialog_get_response_for_widget (dialog, widget);
534 gtk_dialog_response (dialog, response_id);
538 * gtk_dialog_add_action_widget:
539 * @dialog: a #GtkDialog
540 * @child: an activatable widget
541 * @response_id: response ID for @child
543 * Adds an activatable widget to the action area of a #GtkDialog,
544 * connecting a signal handler that will emit the "response" signal on
545 * the dialog when the widget is activated. The widget is appended to
546 * the end of the dialog's action area. If you want to add a
547 * non-activatable widget, simply pack it into the
548 * <literal>action_area</literal> field of the #GtkDialog struct.
551 gtk_dialog_add_action_widget (GtkDialog *dialog,
558 g_return_if_fail (GTK_IS_DIALOG (dialog));
559 g_return_if_fail (GTK_IS_WIDGET (child));
561 ad = get_response_data (child, TRUE);
563 ad->response_id = response_id;
565 if (GTK_IS_BUTTON (child))
566 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
568 signal_id = GTK_WIDGET_GET_CLASS (child)->activate_signal;
574 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
576 g_signal_connect_closure_by_id (child,
583 g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkDialog");
585 gtk_box_pack_end (GTK_BOX (dialog->action_area),
589 if (response_id == GTK_RESPONSE_HELP)
590 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (dialog->action_area), child, TRUE);
594 * gtk_dialog_add_button:
595 * @dialog: a #GtkDialog
596 * @button_text: text of button, or stock ID
597 * @response_id: response ID for the button
599 * Adds a button with the given text (or a stock button, if @button_text is a
600 * stock ID) and sets things up so that clicking the button will emit the
601 * "response" signal with the given @response_id. The button is appended to the
602 * end of the dialog's action area. The button widget is returned, but usually
605 * Return value: the button widget that was added
608 gtk_dialog_add_button (GtkDialog *dialog,
609 const gchar *button_text,
614 g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
615 g_return_val_if_fail (button_text != NULL, NULL);
617 button = gtk_button_new_from_stock (button_text);
619 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
621 gtk_widget_show (button);
623 gtk_dialog_add_action_widget (dialog,
631 gtk_dialog_add_buttons_valist (GtkDialog *dialog,
632 const gchar *first_button_text,
638 g_return_if_fail (GTK_IS_DIALOG (dialog));
640 if (first_button_text == NULL)
643 text = first_button_text;
644 response_id = va_arg (args, gint);
648 gtk_dialog_add_button (dialog, text, response_id);
650 text = va_arg (args, gchar*);
653 response_id = va_arg (args, int);
658 * gtk_dialog_add_buttons:
659 * @dialog: a #GtkDialog
660 * @first_button_text: button text or stock ID
661 * @Varargs: response ID for first button, then more text-response_id pairs
663 * Adds more buttons, same as calling gtk_dialog_add_button()
664 * repeatedly. The variable argument list should be %NULL-terminated
665 * as with gtk_dialog_new_with_buttons(). Each button must have both
666 * text and response ID.
669 gtk_dialog_add_buttons (GtkDialog *dialog,
670 const gchar *first_button_text,
675 va_start (args, first_button_text);
677 gtk_dialog_add_buttons_valist (dialog,
685 * gtk_dialog_set_response_sensitive:
686 * @dialog: a #GtkDialog
687 * @response_id: a response ID
688 * @setting: %TRUE for sensitive
690 * Calls <literal>gtk_widget_set_sensitive (widget, @setting)</literal>
691 * for each widget in the dialog's action area with the given @response_id.
692 * A convenient way to sensitize/desensitize dialog buttons.
695 gtk_dialog_set_response_sensitive (GtkDialog *dialog,
702 g_return_if_fail (GTK_IS_DIALOG (dialog));
704 children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area));
707 while (tmp_list != NULL)
709 GtkWidget *widget = tmp_list->data;
710 ResponseData *rd = get_response_data (widget, FALSE);
712 if (rd && rd->response_id == response_id)
713 gtk_widget_set_sensitive (widget, setting);
715 tmp_list = g_list_next (tmp_list);
718 g_list_free (children);
722 * gtk_dialog_set_default_response:
723 * @dialog: a #GtkDialog
724 * @response_id: a response ID
726 * Sets the last widget in the dialog's action area with the given @response_id
727 * as the default widget for the dialog. Pressing "Enter" normally activates
728 * the default widget.
731 gtk_dialog_set_default_response (GtkDialog *dialog,
737 g_return_if_fail (GTK_IS_DIALOG (dialog));
739 children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area));
742 while (tmp_list != NULL)
744 GtkWidget *widget = tmp_list->data;
745 ResponseData *rd = get_response_data (widget, FALSE);
747 if (rd && rd->response_id == response_id)
748 gtk_widget_grab_default (widget);
750 tmp_list = g_list_next (tmp_list);
753 g_list_free (children);
757 * gtk_dialog_set_has_separator:
758 * @dialog: a #GtkDialog
759 * @setting: %TRUE to have a separator
761 * Sets whether the dialog has a separator above the buttons.
765 gtk_dialog_set_has_separator (GtkDialog *dialog,
768 GtkDialogPrivate *priv;
770 g_return_if_fail (GTK_IS_DIALOG (dialog));
772 priv = GET_PRIVATE (dialog);
774 /* this might fail if we get called before _init() somehow */
775 g_assert (dialog->vbox != NULL);
777 if (priv->ignore_separator)
779 g_warning ("Ignoring the separator setting");
783 if (setting && dialog->separator == NULL)
785 dialog->separator = gtk_hseparator_new ();
786 gtk_box_pack_end (GTK_BOX (dialog->vbox), dialog->separator, FALSE, TRUE, 0);
788 /* The app programmer could screw this up, but, their own fault.
789 * Moves the separator just above the action area.
791 gtk_box_reorder_child (GTK_BOX (dialog->vbox), dialog->separator, 1);
792 gtk_widget_show (dialog->separator);
794 else if (!setting && dialog->separator != NULL)
796 gtk_widget_destroy (dialog->separator);
797 dialog->separator = NULL;
800 g_object_notify (G_OBJECT (dialog), "has-separator");
804 * gtk_dialog_get_has_separator:
805 * @dialog: a #GtkDialog
807 * Accessor for whether the dialog has a separator.
809 * Return value: %TRUE if the dialog has a separator
812 gtk_dialog_get_has_separator (GtkDialog *dialog)
814 g_return_val_if_fail (GTK_IS_DIALOG (dialog), FALSE);
816 return dialog->separator != NULL;
820 * gtk_dialog_response:
821 * @dialog: a #GtkDialog
822 * @response_id: response ID
824 * Emits the "response" signal with the given response ID. Used to
825 * indicate that the user has responded to the dialog in some way;
826 * typically either you or gtk_dialog_run() will be monitoring the
827 * "response" signal and take appropriate action.
830 gtk_dialog_response (GtkDialog *dialog,
833 g_return_if_fail (GTK_IS_DIALOG (dialog));
835 g_signal_emit (dialog,
836 dialog_signals[RESPONSE],
850 shutdown_loop (RunInfo *ri)
852 if (g_main_loop_is_running (ri->loop))
853 g_main_loop_quit (ri->loop);
857 run_unmap_handler (GtkDialog *dialog, gpointer data)
865 run_response_handler (GtkDialog *dialog,
873 ri->response_id = response_id;
879 run_delete_handler (GtkDialog *dialog,
887 return TRUE; /* Do not destroy */
891 run_destroy_handler (GtkDialog *dialog, gpointer data)
895 /* shutdown_loop will be called by run_unmap_handler */
897 ri->destroyed = TRUE;
902 * @dialog: a #GtkDialog
904 * Blocks in a recursive main loop until the @dialog either emits the
905 * response signal, or is destroyed. If the dialog is destroyed during the call
906 * to gtk_dialog_run(), gtk_dialog_returns #GTK_RESPONSE_NONE.
907 * Otherwise, it returns the response ID from the "response" signal emission.
908 * Before entering the recursive main loop, gtk_dialog_run() calls
909 * gtk_widget_show() on the dialog for you. Note that you still
910 * need to show any children of the dialog yourself.
912 * During gtk_dialog_run(), the default behavior of "delete_event" is
913 * disabled; if the dialog receives "delete_event", it will not be
914 * destroyed as windows usually are, and gtk_dialog_run() will return
915 * #GTK_RESPONSE_DELETE_EVENT. Also, during gtk_dialog_run() the dialog will be
916 * modal. You can force gtk_dialog_run() to return at any time by
917 * calling gtk_dialog_response() to emit the "response"
918 * signal. Destroying the dialog during gtk_dialog_run() is a very bad
919 * idea, because your post-run code won't know whether the dialog was
922 * After gtk_dialog_run() returns, you are responsible for hiding or
923 * destroying the dialog if you wish to do so.
925 * Typical usage of this function might be:
926 * <informalexample><programlisting>
927 * gint result = gtk_dialog_run (GTK_DIALOG (dialog));
930 * case GTK_RESPONSE_ACCEPT:
931 * do_application_specific_something (<!-- -->);
934 * do_nothing_since_dialog_was_cancelled (<!-- -->);
937 * gtk_widget_destroy (dialog);
938 * </programlisting></informalexample>
940 * Note that even though the recursive main loop gives the effect of a
941 * modal dialog (it prevents the user from interacting with other
942 * windows in the same window group while the dialog is run), callbacks
943 * such as timeouts, IO channel watches, DND drops, etc, <emphasis>will</emphasis>
944 * be triggered during a gtk_dialog_run() call.
946 * Return value: response ID
949 gtk_dialog_run (GtkDialog *dialog)
951 RunInfo ri = { NULL, GTK_RESPONSE_NONE, NULL, FALSE };
953 gulong response_handler;
954 gulong unmap_handler;
955 gulong destroy_handler;
956 gulong delete_handler;
958 g_return_val_if_fail (GTK_IS_DIALOG (dialog), -1);
960 g_object_ref (dialog);
962 was_modal = GTK_WINDOW (dialog)->modal;
964 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
966 if (!GTK_WIDGET_VISIBLE (dialog))
967 gtk_widget_show (GTK_WIDGET (dialog));
970 g_signal_connect (dialog,
972 G_CALLBACK (run_response_handler),
976 g_signal_connect (dialog,
978 G_CALLBACK (run_unmap_handler),
982 g_signal_connect (dialog,
984 G_CALLBACK (run_delete_handler),
988 g_signal_connect (dialog,
990 G_CALLBACK (run_destroy_handler),
993 ri.loop = g_main_loop_new (NULL, FALSE);
995 GDK_THREADS_LEAVE ();
996 g_main_loop_run (ri.loop);
997 GDK_THREADS_ENTER ();
999 g_main_loop_unref (ri.loop);
1006 gtk_window_set_modal (GTK_WINDOW(dialog), FALSE);
1008 g_signal_handler_disconnect (dialog, response_handler);
1009 g_signal_handler_disconnect (dialog, unmap_handler);
1010 g_signal_handler_disconnect (dialog, delete_handler);
1011 g_signal_handler_disconnect (dialog, destroy_handler);
1014 g_object_unref (dialog);
1016 return ri.response_id;
1020 _gtk_dialog_set_ignore_separator (GtkDialog *dialog,
1021 gboolean ignore_separator)
1023 GtkDialogPrivate *priv;
1025 priv = GET_PRIVATE (dialog);
1026 priv->ignore_separator = ignore_separator;
1030 * gtk_dialog_get_response_for_widget:
1031 * @dialog: a #GtkDialog
1032 * @widget: a widget in the action area of @dialog
1034 * Gets the response id of a widget in the action area
1037 * Returns: the response id of @widget, or %GTK_RESPONSE_NONE
1038 * if @widget doesn't have a response id set.
1043 gtk_dialog_get_response_for_widget (GtkDialog *dialog,
1048 rd = get_response_data (widget, FALSE);
1050 return GTK_RESPONSE_NONE;
1052 return rd->response_id;
1056 * gtk_alternative_dialog_button_order:
1057 * @screen: a #GdkScreen, or %NULL to use the default screen
1059 * Returns %TRUE if dialogs are expected to use an alternative
1060 * button order on the screen @screen. See
1061 * gtk_dialog_set_alternative_button_order() for more details
1062 * about alternative button order.
1064 * If you need to use this function, you should probably connect
1065 * to the ::notify:gtk-alternative-button-order signal on the
1066 * #GtkSettings object associated to @screen, in order to be
1067 * notified if the button order setting changes.
1069 * Returns: Whether the alternative button order should be used
1074 gtk_alternative_dialog_button_order (GdkScreen *screen)
1076 GtkSettings *settings;
1080 settings = gtk_settings_get_for_screen (screen);
1082 settings = gtk_settings_get_default ();
1084 g_object_get (settings,
1085 "gtk-alternative-button-order", &result, NULL);
1091 gtk_dialog_set_alternative_button_order_valist (GtkDialog *dialog,
1092 gint first_response_id,
1099 response_id = first_response_id;
1101 while (response_id != -1)
1103 /* reorder child with response_id to position */
1104 child = dialog_find_button (dialog, response_id);
1105 gtk_box_reorder_child (GTK_BOX (dialog->action_area), child, position);
1107 response_id = va_arg (args, gint);
1113 * gtk_dialog_set_alternative_button_order:
1114 * @dialog: a #GtkDialog
1115 * @first_response_id: a response id used by one @dialog's buttons
1116 * @Varargs: a list of more response ids of @dialog's buttons, terminated by -1
1118 * Sets an alternative button order. If the gtk-alternative-button-order
1119 * setting is set to %TRUE, the dialog buttons are reordered according to
1120 * the order of the response ids passed to this function.
1122 * By default, GTK+ dialogs use the button order advocated by the Gnome
1123 * <ulink url="http://developer.gnome.org/projects/gup/hig/2.0/">Human
1124 * Interface Guidelines</ulink> with the affirmative button at the far
1125 * right, and the cancel button left of it. But the builtin GTK+ dialogs
1126 * and #GtkMessageDialog<!-- -->s do provide an alternative button order,
1127 * which is more suitable on some platforms, e.g. Windows.
1129 * Use this function after adding all the buttons to your dialog, as the
1130 * following example shows:
1131 * <informalexample><programlisting>
1132 * cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
1134 * GTK_RESPONSE_CANCEL);
1136 * ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
1140 * gtk_widget_grab_default (ok_button);
1142 * help_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
1144 * GTK_RESPONSE_HELP);
1146 * gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
1148 * GTK_RESPONSE_CANCEL,
1149 * GTK_RESPONSE_HELP,
1151 * </programlisting></informalexample>
1156 gtk_dialog_set_alternative_button_order (GtkDialog *dialog,
1157 gint first_response_id,
1163 g_return_if_fail (GTK_IS_DIALOG (dialog));
1165 screen = gtk_widget_get_screen (GTK_WIDGET (dialog));
1166 if (!gtk_alternative_dialog_button_order (screen))
1169 va_start (args, first_response_id);
1171 gtk_dialog_set_alternative_button_order_valist (dialog,
1177 * gtk_dialog_set_alternative_button_order_from_array:
1178 * @dialog: a #GtkDialog
1179 * @n_params: the number of response ids in @new_order
1180 * @new_order: an array of response ids of @dialog's buttons
1182 * Sets an alternative button order. If the gtk-alternative-button-order
1183 * setting is set to %TRUE, the dialog buttons are reordered according to
1184 * the order of the response ids in @new_order.
1186 * See gtk_dialog_set_alternative_button_order() for more information.
1188 * This function is for use by language bindings.
1193 gtk_dialog_set_alternative_button_order_from_array (GtkDialog *dialog,
1201 g_return_if_fail (GTK_IS_DIALOG (dialog));
1202 g_return_if_fail (new_order != NULL);
1204 screen = gtk_widget_get_screen (GTK_WIDGET (dialog));
1205 if (!gtk_alternative_dialog_button_order (screen))
1208 for (position = 0; position < n_params; position++)
1210 /* reorder child with response_id to position */
1211 child = dialog_find_button (dialog, new_order[position]);
1212 gtk_box_reorder_child (GTK_BOX (dialog->action_area), child, position);
1216 #define __GTK_DIALOG_C__
1217 #include "gtkaliasdef.c"