diff --git a/src/ChangeLog b/src/ChangeLog index 9ecc4c365..ee87aa8f9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-11-26 Pavel Roskin + + * dialog.c (dlg_replace_widget): Use dlg_select_widget(). + (select_a_widget): Rename to select_other_widget(), factorize + most code from dlg_one_up() and dlg_one_down(). + 2003-11-24 Pavel Roskin * complete.c (check_is_cd): Simplify logic, use isspace(). diff --git a/src/dialog.c b/src/dialog.c index f8ad47013..6e6e7a3d6 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -346,19 +346,6 @@ dlg_unfocus (Dlg_head *h) return 0; } -static void -select_a_widget (Dlg_head *h, int down) -{ - if (!h->current) - return; - - do { - if (down) - h->current = h->current->next; - else - h->current = h->current->prev; - } while (!dlg_focus (h)); -} /* Return true if the windows overlap */ int dlg_overlap (Widget *a, Widget *b) @@ -372,6 +359,52 @@ int dlg_overlap (Widget *a, Widget *b) } +/* + * Try to select another widget. If forward is set, follow tab order. + * Otherwise go to the previous widget. + */ +static void +select_other_widget (Dlg_head *h, int forward) +{ + Widget *old; + + old = h->current; + if (!old) + return; + + if (!dlg_unfocus (h)) + return; + + do { + if (forward) + h->current = h->current->next; + else + h->current = h->current->prev; + } while (!dlg_focus (h)); + + if (dlg_overlap (old, h->current)) { + send_message (h->current, WIDGET_DRAW, 0); + send_message (h->current, WIDGET_FOCUS, 0); + } +} + + +/* Try to select previous widget in the tab order */ +void +dlg_one_up (Dlg_head *h) +{ + select_other_widget (h, 0); +} + + +/* Try to select next widget in the tab order */ +void +dlg_one_down (Dlg_head *h) +{ + select_other_widget (h, 1); +} + + /* Find the widget with the given callback in the dialog h */ Widget * find_widget_type (Dlg_head *h, void *callback) @@ -419,44 +452,6 @@ dlg_select_by_id (Dlg_head *h, int id) dlg_select_widget(h, w_found); } -void dlg_one_up (Dlg_head *h) -{ - Widget *old; - - old = h->current; - - if (!old) - return; - - /* If it accepts unFOCUSion */ - if (!dlg_unfocus(h)) - return; - - select_a_widget (h, 0); - if (dlg_overlap (old, h->current)){ - send_message (h->current, WIDGET_DRAW, 0); - send_message (h->current, WIDGET_FOCUS, 0); - } -} - -void dlg_one_down (Dlg_head *h) -{ - Widget *old; - - old = h->current; - if (!old) - return; - - if (!dlg_unfocus (h)) - return; - - select_a_widget (h, 1); - if (dlg_overlap (old, h->current)){ - send_message (h->current, WIDGET_DRAW, 0); - send_message (h->current, WIDGET_FOCUS, 0); - } -} - int dlg_select_widget (Dlg_head *h, void *w) { if (!h->current) @@ -859,11 +854,8 @@ dlg_replace_widget (Dlg_head *h, Widget *old_w, Widget *new_w) send_message (old_w, WIDGET_DESTROY, 0); send_message (new_w, WIDGET_INIT, 0); - if (should_focus) { - if (!dlg_focus (h)) { - select_a_widget (h, 1); - } - } + if (should_focus) + dlg_select_widget (h, new_w); send_message (new_w, WIDGET_DRAW, 0); }