a few more clean-ups

This commit is contained in:
marschap
2007-10-11 15:34:31 +00:00
parent d079440691
commit b3c5f1803e
+24 -23
View File
@@ -48,7 +48,7 @@ extern Menu *custom_main_menu;
/** /**
* Search a menu for an entry by index, ignoring hidden entries. * Search a menu for an entry by index, ignoring hidden entries.
* \param menu Pointer to menu to search in. * \param menu Pointer to menu to search in.
* \param index ID to search for. * \param index Index to search for.
* \return Pointer to entry found, 0 otherwise. * \return Pointer to entry found, 0 otherwise.
*/ */
static void * static void *
@@ -621,9 +621,9 @@ MenuResult menu_process_input(Menu *menu, MenuToken token, const char *key, unsi
return MENURESULT_ERROR; return MENURESULT_ERROR;
case MENUTOKEN_UP: case MENUTOKEN_UP:
if (menu->data.menu.selector_pos > 0) { if (menu->data.menu.selector_pos > 0) {
menu->data.menu.selector_pos --; if (menu->data.menu.selector_pos < menu->data.menu.scroll)
if (menu->data.menu.selector_pos + 1 < menu->data.menu.scroll)
menu->data.menu.scroll--; menu->data.menu.scroll--;
menu->data.menu.selector_pos--;
} }
else if (menu->data.menu.selector_pos == 0) { else if (menu->data.menu.selector_pos == 0) {
// wrap around to last menu entry // wrap around to last menu entry
@@ -652,22 +652,19 @@ MenuResult menu_process_input(Menu *menu, MenuToken token, const char *key, unsi
break; break;
switch (subitem->type) { switch (subitem->type) {
case MENUITEM_CHECKBOX: case MENUITEM_CHECKBOX:
/* note: this dangerous looking code works since /* Note: this works as CheckboxValue is an enum >= 0. */
* CheckboxValue is an enum >= 0. */ subitem->data.checkbox.value--;
if (subitem->data.checkbox.allow_gray) { subitem->data.checkbox.value %= (subitem->data.checkbox.allow_gray) ? 3 : 2;
subitem->data.checkbox.value = (subitem->data.checkbox.value - 1) % 3;
}
else {
subitem->data.checkbox.value = (subitem->data.checkbox.value - 1) % 2;
}
if (subitem->event_func) if (subitem->event_func)
subitem->event_func(subitem, MENUEVENT_UPDATE); subitem->event_func(subitem, MENUEVENT_UPDATE);
return MENURESULT_NONE; return MENURESULT_NONE;
case MENUITEM_RING: case MENUITEM_RING:
/* ring: jump to the end if beginning is reached */ /* ring: jump to the end if beginning is reached */
subitem->data.ring.value = (subitem->data.ring.value < 1) /* Note: this works as data.ring.value is a short >= 0 */
? LL_Length(subitem->data.ring.strings) - 1 subitem->data.ring.value--;
: (subitem->data.ring.value - 1) % LL_Length(subitem->data.ring.strings); subitem->data.ring.value %= LL_Length(subitem->data.ring.strings);
if (subitem->event_func) if (subitem->event_func)
subitem->event_func(subitem, MENUEVENT_UPDATE); subitem->event_func(subitem, MENUEVENT_UPDATE);
return MENURESULT_NONE; return MENURESULT_NONE;
@@ -684,17 +681,16 @@ MenuResult menu_process_input(Menu *menu, MenuToken token, const char *key, unsi
break; break;
switch (subitem->type) { switch (subitem->type) {
case MENUITEM_CHECKBOX: case MENUITEM_CHECKBOX:
if (subitem->data.checkbox.allow_gray) { subitem->data.checkbox.value++;
subitem->data.checkbox.value = (subitem->data.checkbox.value + 1) % 3; subitem->data.checkbox.value %= (subitem->data.checkbox.allow_gray) ? 3 : 2;
}
else {
subitem->data.checkbox.value = (subitem->data.checkbox.value + 1) % 2;
}
if (subitem->event_func) if (subitem->event_func)
subitem->event_func(subitem, MENUEVENT_UPDATE); subitem->event_func(subitem, MENUEVENT_UPDATE);
return MENURESULT_NONE; return MENURESULT_NONE;
case MENUITEM_RING: case MENUITEM_RING:
subitem->data.ring.value = (subitem->data.ring.value + 1) % LL_Length(subitem->data.ring.strings); subitem->data.ring.value++;
subitem->data.ring.value %= LL_Length(subitem->data.ring.strings);
if (subitem->event_func) if (subitem->event_func)
subitem->event_func(subitem, MENUEVENT_UPDATE); subitem->event_func(subitem, MENUEVENT_UPDATE);
return MENURESULT_NONE; return MENURESULT_NONE;
@@ -713,8 +709,12 @@ MenuResult menu_process_input(Menu *menu, MenuToken token, const char *key, unsi
} }
/** positions current item pointer on subitem subitem_id. If subitem_id is /**
* hidden or not valid subitem of menu this function does nothing. */ * Position current item pointer on entry subitem_id.
* If subitem_id is hidden or no valid subitem of menu do nothing.
* \param menu Pointer to menu to search in.
* \param item_id ID to search for.
*/
void menu_select_subitem(Menu *menu, char *subitem_id) void menu_select_subitem(Menu *menu, char *subitem_id)
{ {
int position; int position;
@@ -723,6 +723,7 @@ void menu_select_subitem(Menu *menu, char *subitem_id)
position = menu_get_index_of(menu, subitem_id); position = menu_get_index_of(menu, subitem_id);
debug(RPT_DEBUG, "%s(menu=[%s], subitem_id=\"%s\")", __FUNCTION__, debug(RPT_DEBUG, "%s(menu=[%s], subitem_id=\"%s\")", __FUNCTION__,
menu->id, subitem_id); menu->id, subitem_id);
if (position < 0) { if (position < 0) {
debug(RPT_DEBUG, "%s: subitem \"%s\" not found" debug(RPT_DEBUG, "%s: subitem \"%s\" not found"
" or hidden in \"%s\", ignored", " or hidden in \"%s\", ignored",