From daf66940b1a06de2681c91dcb8cf72d95a234e86 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Sat, 17 Mar 2007 12:33:34 +0000 Subject: Unify the way functions are called from menus. Optionally, the functions return value can be checked for a value to tell the menu to quit. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12821 a1c6a512-1295-4272-9138-f99709370657 --- apps/menu.c | 20 ++++++++----- apps/menu.h | 73 ++++++++++++++++++++++----------------------- apps/menus/display_menu.c | 44 ++++++++++++++------------- apps/menus/eq_menu.c | 57 ++++++++++++++++++----------------- apps/menus/main_menu.c | 49 ++++++++++++++++-------------- apps/menus/playlist_menu.c | 18 ++++++----- apps/menus/recording_menu.c | 41 ++++++++++++------------- apps/menus/settings_menu.c | 35 ++++++++++++---------- apps/recorder/radio.c | 52 +++++++++++++++++--------------- apps/root_menu.c | 3 +- 10 files changed, 209 insertions(+), 183 deletions(-) diff --git a/apps/menu.c b/apps/menu.c index 29dad82851..dd5a23b933 100644 --- a/apps/menu.c +++ b/apps/menu.c @@ -160,7 +160,6 @@ static void menu_get_icon(int selected_item, void * data, ICON * icon) *icon = bitmap_icons_6x8[menu_icon]; break; case MT_FUNCTION_CALL: - case MT_FUNCTION_WITH_PARAM: case MT_RETURN_VALUE: if (menu_icon == Icon_NOICON) *icon = bitmap_icons_6x8[Icon_Menu_functioncall]; @@ -545,14 +544,21 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected) } break; case MT_FUNCTION_CALL: + { + int return_value; action_signalscreenchange(); - temp->function(); - break; - case MT_FUNCTION_WITH_PARAM: - action_signalscreenchange(); - temp->func_with_param->function( - temp->func_with_param->param); + if (temp->flags&MENU_FUNC_USEPARAM) + return_value = temp->function->function_w_param( + temp->function->param); + else + return_value = temp->function->function(); + if (temp->flags&MENU_FUNC_CHECK_RETVAL) + { + if (return_value == temp->function->exit_value) + return return_value; + } break; + } case MT_SETTING: case MT_SETTING_W_TEXT: { diff --git a/apps/menu.h b/apps/menu.h index eed15d2396..6d7d113c8c 100644 --- a/apps/menu.h +++ b/apps/menu.h @@ -31,8 +31,7 @@ enum menu_item_type { MT_SETTING_W_TEXT, /* same as setting, but uses different text for the setting title, ID2P() or "literal" for the str param */ - MT_FUNCTION_CALL, /* used when the standard code wont work */ - MT_FUNCTION_WITH_PARAM, + MT_FUNCTION_CALL, /* call a function from the menus */ MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/ MT_RETURN_VALUE, /* returns a value associated with an item */ MT_OLD_MENU, /* used so we can wrap the old menu api @@ -40,28 +39,36 @@ enum menu_item_type { }; typedef int (*menu_function)(void); -struct menu_func_with_param { - int (*function)(void* param); - void *param; +struct menu_func { + union { + int (*function_w_param)(void* param); /* intptr_t instead of void* + for 64bit systems */ + int (*function)(void); + }; + void *param; /* passed to function_w_param */ + int exit_value; /* exit do_menu() if function returns this value */ }; #define MENU_TYPE_MASK 0xF /* MT_* type */ /* these next two are mutually exclusive */ #define MENU_HAS_DESC 0x10 #define MENU_DYNAMIC_DESC 0x20 -/* unless we need more flags*/ -#define MENU_COUNT_MASK (~(MENU_TYPE_MASK|MENU_HAS_DESC|MENU_DYNAMIC_DESC)) -#define MENU_COUNT_SHIFT 6 + +/* Flags for MT_FUNCTION_CALL */ +#define MENU_FUNC_USEPARAM 0x40 +#define MENU_FUNC_CHECK_RETVAL 0x80 + +#define MENU_COUNT_MASK 0xFFF +#define MENU_COUNT_SHIFT 8 +#define MENU_ITEM_COUNT(c) ((c&MENU_COUNT_MASK)<