diff --git a/src/ChangeLog b/src/ChangeLog index b5451e6eb..878f6cffa 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2003-11-26 Pavel Roskin + * dialog.h (dlg_widget_active): New function - check if the + widget is active. + * boxes.c (display_callback): Use it. + * layout.c (swap_panels): Likewise. + * screen.c (do_panel_event): Likewise. + * dialog.c: Eliminate callback macro. * dialog.c (dlg_replace_widget): Use dlg_select_widget(). diff --git a/src/boxes.c b/src/boxes.c index 4cb7cbc38..b4abca3db 100644 --- a/src/boxes.c +++ b/src/boxes.c @@ -88,7 +88,7 @@ display_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) { switch (msg) { case DLG_UNFOCUS: - if ((WRadio *) h->current == my_radio) { + if (dlg_widget_active (my_radio)) { assign_text (status, displays_status[my_radio->sel]); input_set_point (status, 0); } @@ -96,28 +96,27 @@ display_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) case DLG_KEY: if (parm == '\n') { - if ((WRadio *) h->current == my_radio) { + if (dlg_widget_active (my_radio)) { assign_text (status, displays_status[my_radio->sel]); dlg_stop (h); return MSG_HANDLED; } - if ((WInput *) h->current == user) { + if (dlg_widget_active (user)) { h->ret_value = B_USER + 6; dlg_stop (h); return MSG_HANDLED; } - if ((WInput *) h->current == status) { + if (dlg_widget_active (status)) { h->ret_value = B_USER + 7; dlg_stop (h); return MSG_HANDLED; } } - if (tolower (parm) == user_hotkey - && h->current != (Widget *) user - && h->current != (Widget *) status) { + if (tolower (parm) == user_hotkey && dlg_widget_active (user) + && dlg_widget_active (status)) { my_radio->sel = 3; dlg_select_widget (h, my_radio); /* force redraw */ dlg_select_widget (h, user); diff --git a/src/dialog.h b/src/dialog.h index 0d24774e8..01e1c3b89 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -202,6 +202,14 @@ send_message (Widget *w, widget_msg_t msg, int parm) return (*(w->callback)) (w, msg, parm); } +/* Return 1 if the widget is active, 0 otherwise */ +static inline int +dlg_widget_active (void *w) +{ + Widget *w1 = (Widget *) w; + return (w1->parent->current == w1); +} + void dlg_replace_widget (Dlg_head *h, Widget *old, Widget *new); int dlg_overlap (Widget *a, Widget *b); void widget_erase (Widget *); diff --git a/src/layout.c b/src/layout.c index d9380b00f..ef8006cc1 100644 --- a/src/layout.c +++ b/src/layout.c @@ -1037,9 +1037,10 @@ void swap_panels () current_panel = panel2; else current_panel = panel1; - if (midnight_dlg->current == panels[0].widget) + + if (dlg_widget_active (panels[0].widget)) dlg_select_widget (midnight_dlg, (void *) panels [1].widget); - else if (midnight_dlg->current == panels[1].widget) + else if (dlg_widget_active (panels[1].widget)) dlg_select_widget (midnight_dlg, (void *) panels [0].widget); } else { WPanel *tmp_panel; diff --git a/src/screen.c b/src/screen.c index 6a869c198..07cf0cf08 100644 --- a/src/screen.c +++ b/src/screen.c @@ -2309,7 +2309,7 @@ do_panel_event (Gpm_Event *event, WPanel *panel, int *redir) event->y -= 2; if ((event->type & (GPM_DOWN | GPM_DRAG))) { - if (&panel->widget != current_dlg->current) + if (!dlg_widget_active (panel)) change_panel (); if (event->y <= 0) {