Optimization of walking in dialog widgets.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2011-07-18 13:27:01 +04:00 committed by Slava Zanko
parent 05385e1586
commit ba86de945c

View File

@ -80,6 +80,33 @@ typedef enum
/*** file scope variables ************************************************************************/ /*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/ /*** file scope functions ************************************************************************/
static GList *
dlg_widget_next (Dlg_head *h, GList *l)
{
GList *next;
next = g_list_next (l);
if (next == NULL)
next = h->widgets;
return next;
}
/* --------------------------------------------------------------------------------------------- */
static GList *
dlg_widget_prev (Dlg_head *h, GList *l)
{
GList *prev;
prev = g_list_previous (l);
if (prev == NULL)
prev = g_list_last (h->widgets);
return prev;
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/** /**
* broadcast a message to all the widgets in a dialog that have * broadcast a message to all the widgets in a dialog that have
@ -99,19 +126,9 @@ dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t msg, gboolean reverse, int flag
h->current = h->widgets; h->current = h->widgets;
if (reverse) if (reverse)
{ p = dlg_widget_prev (h, h->current);
p = g_list_previous (h->current);
if (p == NULL)
p = g_list_last (h->widgets);
}
else else
{ p = dlg_widget_next (h, h->current);
p = g_list_next (h->current);
if (p == NULL)
p = h->widgets;
}
first = p; first = p;
@ -120,19 +137,9 @@ dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t msg, gboolean reverse, int flag
Widget *w = (Widget *) p->data; Widget *w = (Widget *) p->data;
if (reverse) if (reverse)
{ p = dlg_widget_prev (h, p);
p = g_list_previous (p);
if (p == NULL)
p = g_list_last (h->widgets);
}
else else
{ p = dlg_widget_next (h, p);
p = g_list_next (p);
if (p == NULL)
p = h->widgets;
}
if ((flags == 0) || ((flags & w->options) != 0)) if ((flags == 0) || ((flags & w->options) != 0))
send_message (w, msg, 0); send_message (w, msg, 0);
@ -228,14 +235,10 @@ do_select_widget (Dlg_head * h, GList * w, select_dir_t dir)
dir = SELECT_NEXT; dir = SELECT_NEXT;
/* fallthrough */ /* fallthrough */
case SELECT_NEXT: case SELECT_NEXT:
h->current = g_list_next (h->current); h->current = dlg_widget_next (h, h->current);
if (h->current == NULL)
h->current = h->widgets;
break; break;
case SELECT_PREV: case SELECT_PREV:
h->current = g_list_previous (h->current); h->current = dlg_widget_prev (h, h->current);
if (h->current == NULL)
h->current = g_list_last (h->widgets);
break; break;
} }
} }
@ -370,9 +373,7 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
Widget *widget; Widget *widget;
widget = (Widget *) item->data; widget = (Widget *) item->data;
item = g_list_next (item); item = dlg_widget_next (h, item);
if (item == NULL)
item = h->widgets;
if (((widget->options & W_DISABLED) == 0) if (((widget->options & W_DISABLED) == 0)
&& (x > widget->x) && (x <= widget->x + widget->cols) && (x > widget->x) && (x <= widget->x + widget->cols)
@ -438,9 +439,7 @@ dlg_try_hotkey (Dlg_head * h, int d_key)
if (handled == MSG_HANDLED) if (handled == MSG_HANDLED)
return MSG_HANDLED; return MSG_HANDLED;
hot_cur = g_list_next (h->current); hot_cur = dlg_widget_next (h, h->current);
if (hot_cur == NULL)
hot_cur = h->widgets;
/* send it to all widgets */ /* send it to all widgets */
while (h->current != hot_cur && handled == MSG_NOT_HANDLED) while (h->current != hot_cur && handled == MSG_NOT_HANDLED)
@ -451,11 +450,7 @@ dlg_try_hotkey (Dlg_head * h, int d_key)
handled = send_message (current, WIDGET_HOTKEY, d_key); handled = send_message (current, WIDGET_HOTKEY, d_key);
if (handled == MSG_NOT_HANDLED) if (handled == MSG_NOT_HANDLED)
{ hot_cur = dlg_widget_next (h, hot_cur);
hot_cur = g_list_next (hot_cur);
if (hot_cur == NULL)
hot_cur = h->widgets;
}
} }
if (handled == MSG_HANDLED) if (handled == MSG_HANDLED)
@ -993,15 +988,7 @@ void
dlg_one_up (Dlg_head * h) dlg_one_up (Dlg_head * h)
{ {
if (h->widgets != NULL) if (h->widgets != NULL)
{ do_select_widget (h, dlg_widget_prev (h, h->current), SELECT_PREV);
GList *prev;
prev = g_list_previous (h->current);
if (prev == NULL)
prev = g_list_last (h->widgets);
do_select_widget (h, prev, SELECT_PREV);
}
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -1011,14 +998,7 @@ void
dlg_one_down (Dlg_head * h) dlg_one_down (Dlg_head * h)
{ {
if (h->widgets != NULL) if (h->widgets != NULL)
{ do_select_widget (h, dlg_widget_next (h, h->current), SELECT_NEXT);
GList *next;
next = g_list_next (h->current);
if (next == NULL)
next = h->widgets;
do_select_widget (h, next, SELECT_NEXT);
}
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -1039,10 +1019,7 @@ update_cursor (Dlg_head * h)
else else
do do
{ {
p = g_list_next (p); p = dlg_widget_next (h, p);
if (p == NULL)
p = h->widgets;
if (p == h->current) if (p == h->current)
break; break;
@ -1116,11 +1093,7 @@ init_dlg (Dlg_head * h)
/* Select the first widget that takes focus */ /* Select the first widget that takes focus */
while (h->current != NULL && !dlg_focus (h)) while (h->current != NULL && !dlg_focus (h))
{ h->current = dlg_widget_next (h, h->current);
h->current = g_list_next (h->current);
if (h->current == NULL)
h->current = h->widgets;
}
h->ret_value = 0; h->ret_value = 0;
} }