Add a public setting for button ordering (#74669, Owen Taylor)

2004-10-25  Matthias Clasen  <mclasen@redhat.com>

	Add a public setting for button ordering (#74669, Owen Taylor)

	* gtk/gtksettings.c (gtk_settings_class_init): Add a
	gtk-alternative-button-order setting.

	* gtk/gtkdialog.h:
	* gtk/gtkdialog.c (gtk_alternative_dialog_button_order): A
	getter for the alternative button order setting.
	* gtk/gtkdialog.c (gtk_dialog_set_alternative_button_order):
	New function to install an alternative button order for a
	dialog.

	* gtk/gtkfilesel.c (gtk_file_selection_init):
	* gtk/gtkfontsel.c (gtk_font_selection_dialog_init):
	* gtk/gtkmessagedialog.c (gtk_message_dialog_add_buttons):
	* gtk/gtkcolorseldialog.c (gtk_color_selection_dialog_init):
	* gtk/gtkfilechooserdefault.c (location_popup_handler):
	Set up an alternative button order.
This commit is contained in:
Matthias Clasen 2004-10-25 05:43:29 +00:00 committed by Matthias Clasen
parent b63431c82a
commit 8ab4fd4526
14 changed files with 267 additions and 9 deletions

View File

@ -1,3 +1,24 @@
2004-10-25 Matthias Clasen <mclasen@redhat.com>
Add a public setting for button ordering (#74669, Owen Taylor)
* gtk/gtksettings.c (gtk_settings_class_init): Add a
gtk-alternative-button-order setting.
* gtk/gtkdialog.h:
* gtk/gtkdialog.c (gtk_alternative_dialog_button_order): A
getter for the alternative button order setting.
* gtk/gtkdialog.c (gtk_dialog_set_alternative_button_order):
New function to install an alternative button order for a
dialog.
* gtk/gtkfilesel.c (gtk_file_selection_init):
* gtk/gtkfontsel.c (gtk_font_selection_dialog_init):
* gtk/gtkmessagedialog.c (gtk_message_dialog_add_buttons):
* gtk/gtkcolorseldialog.c (gtk_color_selection_dialog_init):
* gtk/gtkfilechooserdefault.c (location_popup_handler):
Set up an alternative button order.
2004-10-25 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkimage.h:

View File

@ -1,3 +1,24 @@
2004-10-25 Matthias Clasen <mclasen@redhat.com>
Add a public setting for button ordering (#74669, Owen Taylor)
* gtk/gtksettings.c (gtk_settings_class_init): Add a
gtk-alternative-button-order setting.
* gtk/gtkdialog.h:
* gtk/gtkdialog.c (gtk_alternative_dialog_button_order): A
getter for the alternative button order setting.
* gtk/gtkdialog.c (gtk_dialog_set_alternative_button_order):
New function to install an alternative button order for a
dialog.
* gtk/gtkfilesel.c (gtk_file_selection_init):
* gtk/gtkfontsel.c (gtk_font_selection_dialog_init):
* gtk/gtkmessagedialog.c (gtk_message_dialog_add_buttons):
* gtk/gtkcolorseldialog.c (gtk_color_selection_dialog_init):
* gtk/gtkfilechooserdefault.c (location_popup_handler):
Set up an alternative button order.
2004-10-25 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkimage.h:

View File

@ -1,3 +1,24 @@
2004-10-25 Matthias Clasen <mclasen@redhat.com>
Add a public setting for button ordering (#74669, Owen Taylor)
* gtk/gtksettings.c (gtk_settings_class_init): Add a
gtk-alternative-button-order setting.
* gtk/gtkdialog.h:
* gtk/gtkdialog.c (gtk_alternative_dialog_button_order): A
getter for the alternative button order setting.
* gtk/gtkdialog.c (gtk_dialog_set_alternative_button_order):
New function to install an alternative button order for a
dialog.
* gtk/gtkfilesel.c (gtk_file_selection_init):
* gtk/gtkfontsel.c (gtk_font_selection_dialog_init):
* gtk/gtkmessagedialog.c (gtk_message_dialog_add_buttons):
* gtk/gtkcolorseldialog.c (gtk_color_selection_dialog_init):
* gtk/gtkfilechooserdefault.c (location_popup_handler):
Set up an alternative button order.
2004-10-25 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkimage.h:

View File

@ -1,3 +1,24 @@
2004-10-25 Matthias Clasen <mclasen@redhat.com>
Add a public setting for button ordering (#74669, Owen Taylor)
* gtk/gtksettings.c (gtk_settings_class_init): Add a
gtk-alternative-button-order setting.
* gtk/gtkdialog.h:
* gtk/gtkdialog.c (gtk_alternative_dialog_button_order): A
getter for the alternative button order setting.
* gtk/gtkdialog.c (gtk_dialog_set_alternative_button_order):
New function to install an alternative button order for a
dialog.
* gtk/gtkfilesel.c (gtk_file_selection_init):
* gtk/gtkfontsel.c (gtk_font_selection_dialog_init):
* gtk/gtkmessagedialog.c (gtk_message_dialog_add_buttons):
* gtk/gtkcolorseldialog.c (gtk_color_selection_dialog_init):
* gtk/gtkfilechooserdefault.c (location_popup_handler):
Set up an alternative button order.
2004-10-25 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkimage.h:

View File

@ -1,6 +1,7 @@
2004-10-25 Matthias Clasen <mclasen@redhat.com>
* gtk/gtk-sections.txt: Add new named icon api in GtkImage.
Add new button order api.
Sun Oct 24 02:54:36 2004 Jonathan Blandford <jrb@redhat.com>

View File

@ -968,6 +968,10 @@ gtk_dialog_get_has_separator
gtk_dialog_set_default_response
gtk_dialog_set_has_separator
gtk_dialog_set_response_sensitive
<SUBSECTION>
gtk_alternative_dialog_button_order
gtk_dialog_set_alternative_button_order
<SUBSECTION Standard>
GTK_DIALOG
GTK_IS_DIALOG

View File

@ -113,6 +113,12 @@ gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag)
gtk_widget_hide (colorseldiag->help_button);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (colorseldiag),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
GTK_RESPONSE_HELP,
-1);
gtk_window_set_title (GTK_WINDOW (colorseldiag),
_("Color Selection"));
}

View File

@ -381,11 +381,12 @@ gtk_dialog_style_set (GtkWidget *widget,
update_spacings (GTK_DIALOG (widget));
}
static gboolean
dialog_has_cancel (GtkDialog *dialog)
static GtkWidget *
dialog_find_button (GtkDialog *dialog,
gint response_id)
{
GList *children, *tmp_list;
gboolean ret = FALSE;
GtkWidget *child = NULL;
children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area));
@ -393,16 +394,16 @@ dialog_has_cancel (GtkDialog *dialog)
{
ResponseData *rd = get_response_data (tmp_list->data, FALSE);
if (rd && rd->response_id == GTK_RESPONSE_CANCEL)
if (rd && rd->response_id == response_id)
{
ret = TRUE;
child = tmp_list->data;
break;
}
}
g_list_free (children);
return ret;
return child;
}
static void
@ -413,7 +414,7 @@ gtk_dialog_close (GtkDialog *dialog)
GtkWidget *widget = GTK_WIDGET (dialog);
GdkEvent *event;
if (!dialog_has_cancel (dialog))
if (!dialog_find_button (dialog, GTK_RESPONSE_CANCEL))
return;
event = gdk_event_new (GDK_DELETE);
@ -1062,3 +1063,126 @@ _gtk_dialog_get_response_for_widget (GtkDialog *dialog,
else
return rd->response_id;
}
/**
* gtk_alternative_dialog_button_order:
* @screen: a #GdkScreen, or %NULL to use the default screen
*
* Returns %TRUE if dialogs are expected to use an alternative
* button order on the screen @screen. See
* gtk_dialog_set_alternative_button_order() for more details
* about alternative button order.
*
* If you need to use this function, you should probably connect
* to the ::notify:gtk-alternative-button-order signal on the
* #GtkSettings object associated to @screen, in order to be
* notified if the button order setting changes.
*
* Returns: Whether the alternative button order should be used
*
* Since: 2.6
*/
gboolean
gtk_alternative_dialog_button_order (GdkScreen *screen)
{
GtkSettings *settings;
gboolean result;
if (screen)
settings = gtk_settings_get_for_screen (screen);
else
settings = gtk_settings_get_default ();
g_object_get (settings,
"gtk-alternative-button-order", &result, NULL);
return result;
}
static void
gtk_dialog_set_alternative_button_order_valist (GtkDialog *dialog,
gint first_response_id,
va_list args)
{
GtkWidget *child;
gint response_id;
gint position;
response_id = first_response_id;
position = 0;
while (response_id != -1)
{
/* reorder child with response_id to position */
child = dialog_find_button (dialog, response_id);
gtk_box_reorder_child (GTK_BOX (dialog->action_area), child, position);
response_id = va_arg (args, gint);
position++;
}
}
/**
* gtk_dialog_set_alternative_button_order:
* @dialog: a #GtkDialog
* @first_response_id: a response id used by one @dialog's buttons
* @Varargs: a list of more response ids of @dialog's buttons, terminated by -1
*
* Sets an alternative button order. If the gtk-alternative-button-order
* setting is set to %TRUE, the dialog buttons are reordered according to
* the order of the response ids passed to this function.
*
* By default, GTK+ dialogs use the button order advocated by the Gnome
* <ulink url="http://developer.gnome.org/projects/gup/hig/2.0/">Human
* Interface Guidelines</ulink> with the affirmative button at the far
* right, and the cancel button left of it. But the builtin GTK+ dialogs
* and #GtkMessageDialog<!-- -->s do provide an alternative button order,
* which is more suitable on some platforms, e.g. Windows.
*
* Use this function after adding all the buttons to your dialog, as the
* following example shows:
* <informalexample><programlisting>
* cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
* GTK_STOCK_CANCEL,
* GTK_RESPONSE_CANCEL);
*
* ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
* GTK_STOCK_OK,
* GTK_RESPONSE_OK);
*
* gtk_widget_grab_default (ok_button);
*
* help_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
* GTK_STOCK_HELP,
* GTK_RESPONSE_HELP);
*
* gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
* GTK_RESPONSE_OK,
* GTK_RESPONSE_CANCEL,
* GTK_RESPONSE_HELP,
* -1);
* </programlisting></informalexample>
*
* Since: 2.6
*/
void
gtk_dialog_set_alternative_button_order (GtkDialog *dialog,
gint first_response_id,
...)
{
GdkScreen *screen;
va_list args;
g_return_if_fail (GTK_IS_DIALOG (dialog));
screen = gtk_widget_get_screen (GTK_WIDGET (dialog));
if (!gtk_alternative_dialog_button_order (screen))
return;
va_start (args, first_response_id);
gtk_dialog_set_alternative_button_order_valist (dialog,
first_response_id,
args);
va_end (args);
}

View File

@ -152,6 +152,11 @@ void gtk_dialog_set_has_separator (GtkDialog *dialog,
gboolean setting);
gboolean gtk_dialog_get_has_separator (GtkDialog *dialog);
gboolean gtk_alternative_dialog_button_order (GdkScreen *screen);
void gtk_dialog_set_alternative_button_order (GtkDialog *dialog,
gint first_response_id,
...);
/* Emit response signal */
void gtk_dialog_response (GtkDialog *dialog,
gint response_id);

View File

@ -5787,6 +5787,11 @@ location_popup_handler (GtkFileChooserDefault *impl,
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_ACCEPT,
GTK_RESPONSE_CANCEL,
-1);
hbox = gtk_hbox_new (FALSE, 12);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);

View File

@ -811,7 +811,12 @@ gtk_file_selection_init (GtkFileSelection *filesel)
filesel->ok_button = gtk_dialog_add_button (dialog,
GTK_STOCK_OK,
GTK_RESPONSE_OK);
gtk_dialog_set_alternative_button_order (dialog,
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
gtk_widget_grab_default (filesel->ok_button);
/* The selection entry widget */

View File

@ -1371,6 +1371,13 @@ gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag)
GTK_RESPONSE_OK);
gtk_widget_grab_default (fontseldiag->ok_button);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontseldiag),
GTK_RESPONSE_OK,
GTK_RESPONSE_APPLY,
GTK_RESPONSE_CANCEL,
-1);
gtk_window_set_title (GTK_WINDOW (fontseldiag),
_("Font Selection"));

View File

@ -494,6 +494,10 @@ gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
gtk_dialog_add_button (dialog,
GTK_STOCK_YES,
GTK_RESPONSE_YES);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_YES,
GTK_RESPONSE_NO,
-1);
break;
case GTK_BUTTONS_OK_CANCEL:
@ -503,6 +507,10 @@ gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
gtk_dialog_add_button (dialog,
GTK_STOCK_OK,
GTK_RESPONSE_OK);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
break;
default:

View File

@ -69,7 +69,8 @@ enum {
PROP_XFT_HINTING,
PROP_XFT_HINTSTYLE,
PROP_XFT_RGBA,
PROP_XFT_DPI
PROP_XFT_DPI,
PROP_ALTERNATIVE_BUTTON_ORDER
};
@ -424,6 +425,14 @@ gtk_settings_class_init (GtkSettingsClass *class)
g_assert (result == PROP_XFT_DPI);
#endif /* GDK_WINDOWING_X11 */
result = settings_install_property_parser (class,
g_param_spec_boolean ("gtk-alternative-button-order",
P_("Alternative button order"),
P_("Whether buttons in dialogs should use the alternative button order"),
FALSE,
G_PARAM_READWRITE),
NULL);
g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
}
static void