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.h | 73 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) (limited to 'apps/menu.h') diff --git a/apps/menu.h b/apps/menu.h index eed15d2..6d7d113 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)<