From c776fab903ee179da2ad7cb6f1f31d94a9cad960 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Sun, 12 Feb 2006 17:11:57 +0000 Subject: [PATCH] Initially place cursor on the current listbox item Introduce the macros before_widgets and foreach_widget_back. Use the latter in update_all_widgets instead of foreach_widget so that the widgets are printed in reverse order, which means that any listbox is drawn last, which allows it to grab the cursor from the selected button when the dialogue box is initialised or redrawn. Requested by Kirk Reiser for great usability with screen readers. --- src/bfu/dialog.c | 4 +++- src/bfu/dialog.h | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bfu/dialog.c b/src/bfu/dialog.c index 8671c8179..042a172cc 100644 --- a/src/bfu/dialog.c +++ b/src/bfu/dialog.c @@ -57,7 +57,9 @@ update_all_widgets(struct dialog_data *dlg_data) { struct widget_data *widget_data; - foreach_widget(dlg_data, widget_data) { + /* Iterate backwards rather than forwards so that listboxes are drawn + * last, which means that they can grab the cursor. Yes, 'tis hacky. */ + foreach_widget_back(dlg_data, widget_data) { display_widget(dlg_data, widget_data); } } diff --git a/src/bfu/dialog.h b/src/bfu/dialog.h index 376ef701d..b0cde3bc9 100644 --- a/src/bfu/dialog.h +++ b/src/bfu/dialog.h @@ -131,6 +131,7 @@ void refresh_dialog(struct dialog_data *, dialog_refresh_handler_T handler, void void select_widget(struct dialog_data *dlg_data, struct widget_data *widget_data); struct widget_data *select_widget_by_id(struct dialog_data *dlg_data, int i); +#define before_widgets(dlg_data) (&(dlg_data)->widgets_data[-1]) #define end_of_widgets(dlg_data) (&(dlg_data)->widgets_data[(dlg_data)->number_of_widgets]) #define first_widget(dlg_data) (&(dlg_data)->widgets_data[0]) #define last_widget(dlg_data) (&(dlg_data)->widgets_data[(dlg_data)->number_of_widgets - 1]) @@ -140,6 +141,11 @@ struct widget_data *select_widget_by_id(struct dialog_data *dlg_data, int i); (widget_data) != end_of_widgets(dlg_data); \ (widget_data)++) +#define foreach_widget_back(dlg_data, widget_data) \ + for ((widget_data) = last_widget(dlg_data); \ + (widget_data) != before_widgets(dlg_data); \ + (widget_data)--) + #define is_selected_widget(dlg_data, widget_data) ((widget_data) == selected_widget(dlg_data)) #define add_dlg_end(dlg, n) \