blob: 7e08ef5aacb1281c5e54db8310d00ccddfac7cd1 [file] [log] [blame]
Daniel Stenberg1c0c8612002-05-17 12:22:24 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Robert E. Hak
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef __MENU_H__
21#define __MENU_H__
22
Daniel Stenberg91f743f2002-06-14 10:39:11 +000023#include <stdbool.h>
Jonathan Gordon5599d682007-02-14 06:58:30 +000024#include "icon.h"
25#include "icons.h"
Jonathan Gordon91e726a2007-03-27 06:38:11 +000026#include "root_menu.h" /* needed for MENU_* return codes */
Jonathan Gordon5599d682007-02-14 06:58:30 +000027
Daniel Stenberg91f743f2002-06-14 10:39:11 +000028
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000029enum menu_item_type {
30 MT_MENU = 0,
31 MT_SETTING,
Jonathan Gordon97090862007-03-03 14:23:03 +000032 MT_SETTING_W_TEXT, /* same as setting, but uses different
33 text for the setting title,
34 ID2P() or "literal" for the str param */
Jonathan Gordondaf66942007-03-17 12:33:34 +000035 MT_FUNCTION_CALL, /* call a function from the menus */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000036 MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000037 MT_RETURN_VALUE, /* returns a value associated with an item */
Jonathan Gordon34521462007-03-07 13:00:46 +000038 MT_OLD_MENU, /* used so we can wrap the old menu api
39 around the new api. Noone else should use this */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000040};
Jonathan Gordon26ff6972007-05-01 11:01:53 +000041#define MENU_TYPE_MASK 0xF /* MT_* type */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000042
43typedef int (*menu_function)(void);
Jonathan Gordondaf66942007-03-17 12:33:34 +000044struct menu_func {
45 union {
46 int (*function_w_param)(void* param); /* intptr_t instead of void*
47 for 64bit systems */
48 int (*function)(void);
49 };
50 void *param; /* passed to function_w_param */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000051};
52
Jonathan Gordon2801a872007-02-19 02:14:51 +000053/* these next two are mutually exclusive */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000054#define MENU_HAS_DESC 0x10
Jonathan Gordon26ff6972007-05-01 11:01:53 +000055#define MENU_DYNAMIC_DESC 0x20 /* the name of this menu item is set by the \
56 list_get_name callback */
57
58#define MENU_EXITAFTERTHISMENU 0x40 /* do_menu() will exiting out of any \
59 menu item with this flag set */
Jonathan Gordondaf66942007-03-17 12:33:34 +000060
61/* Flags for MT_FUNCTION_CALL */
Jonathan Gordon3a7760c2007-04-30 13:41:33 +000062#define MENU_FUNC_USEPARAM 0x80
63#define MENU_FUNC_CHECK_RETVAL 0x100
Jonathan Gordondaf66942007-03-17 12:33:34 +000064
65#define MENU_COUNT_MASK 0xFFF
Jonathan Gordon3a7760c2007-04-30 13:41:33 +000066#define MENU_COUNT_SHIFT 12
Jonathan Gordondaf66942007-03-17 12:33:34 +000067#define MENU_ITEM_COUNT(c) ((c&MENU_COUNT_MASK)<<MENU_COUNT_SHIFT)
Jonathan Gordonb5e587c2007-03-18 06:31:33 +000068#define MENU_GET_COUNT(flags) ((flags>>MENU_COUNT_SHIFT)&MENU_COUNT_MASK)
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000069
70struct menu_item_ex {
Jonathan Gordondaf66942007-03-17 12:33:34 +000071 unsigned int flags; /* above defines */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000072 union {
73 const struct menu_item_ex **submenus; /* used with MT_MENU */
74 void *variable; /* used with MT_SETTING,
75 must be in the settings_list.c list */
Jonathan Gordondaf66942007-03-17 12:33:34 +000076 const struct menu_func *function; /* MT_FUNCTION_* */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000077 const char **strings; /* used with MT_RETURN_ID */
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000078 int value; /* MT_RETURN_VALUE */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000079 };
80 union {
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000081 /* For settings */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000082 int (*menu_callback)(int action, const struct menu_item_ex *this_item);
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000083 /* For everything else, except if the text is dynamic */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000084 const struct menu_callback_with_desc {
85 int (*menu_callback)(int action,
86 const struct menu_item_ex *this_item);
87 unsigned char *desc; /* string or ID */
Jonathan Gordon02a87172007-03-03 13:52:14 +000088 int icon_id; /* from icons_6x8 in icons.h */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000089 } *callback_and_desc;
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000090 /* For when the item text is dynamic */
91 const struct menu_get_name_and_icon {
92 int (*menu_callback)(int action,
Jonathan Gordon2801a872007-02-19 02:14:51 +000093 const struct menu_item_ex *this_item);
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000094 char *(*list_get_name)(int selected_item, void * data, char *buffer);
95 void *list_get_name_data;
Jonathan Gordon02a87172007-03-03 13:52:14 +000096 int icon_id;
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000097 } *menu_get_name_and_icon;
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000098 };
99};
100
101typedef int (*menu_callback_type)(int action,
102 const struct menu_item_ex *this_item);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000103int do_menu(const struct menu_item_ex *menu, int *start_selected);
Jonathan Gordon2801a872007-02-19 02:14:51 +0000104bool do_setting_from_menu(const struct menu_item_ex *temp);
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000105
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000106/* In all the following macros the argument names are as follows:
107 - name: The name for the variable (so it can be used in a MAKE_MENU()
108 - str: the string to display for this menu item. use ID2P() for LANG_* id's
109 - callback: The callback function to call for this menu item.
110*/
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000111
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000112/* Use this to put a setting into a menu.
113 The setting must appear in settings_list.c.
114 If the setting is not configured properly, the menu will display "Not Done yet!"
115 When the user selects this item the setting select screen will load,
116 when that screen exits the user wll be back in the menu */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000117#define MENUITEM_SETTING(name,var,callback) \
118 static const struct menu_item_ex name = \
119 {MT_SETTING, {.variable = (void*)var},{callback}};
120
Jonathan Gordon97090862007-03-03 14:23:03 +0000121/* Use this for settings which have a differnt title in their
122 setting screen than in the menu (e.g scroll options */
123#define MENUITEM_SETTING_W_TEXT(name, var, str, callback ) \
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000124 static const struct menu_callback_with_desc name##__ = \
125 {callback,str, Icon_NOICON}; \
Jonathan Gordon97090862007-03-03 14:23:03 +0000126 static const struct menu_item_ex name = \
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000127 {MT_SETTING_W_TEXT|MENU_HAS_DESC, {.variable = (void*)var }, \
Jonathan Gordon97090862007-03-03 14:23:03 +0000128 {.callback_and_desc = & name##__}};
129
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000130/* Use this To create a list of Strings (or ID2P()'s )
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000131 When the user enters this list and selects one, the menu will exits
132 and its return value will be the index of the chosen item */
133#define MENUITEM_STRINGLIST(name, str, callback, ... ) \
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000134 static const char *name##_[] = {__VA_ARGS__}; \
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000135 static const struct menu_callback_with_desc name##__ = \
136 {callback,str, Icon_NOICON}; \
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000137 static const struct menu_item_ex name = \
138 {MT_RETURN_ID|MENU_HAS_DESC| \
139 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
Jonathan Gordon1f5ee2a2007-03-25 14:31:56 +0000140 { .strings = name##_},{.callback_and_desc = & name##__}};
Jonathan Gordon5599d682007-02-14 06:58:30 +0000141
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000142
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000143/* returns a value associated with the item */
144#define MENUITEM_RETURNVALUE(name, str, val, cb, icon) \
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000145 static const struct menu_callback_with_desc name##_ = {cb,str,icon}; \
146 static const struct menu_item_ex name = \
147 { MT_RETURN_VALUE|MENU_HAS_DESC, { .value = val}, \
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000148 {.callback_and_desc = & name##_}};
149
150/* same as above, except the item name is dynamic */
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000151#define MENUITEM_RETURNVALUE_DYNTEXT(name, val, cb, text_callback, \
152 text_cb_data, icon) \
153 static const struct menu_get_name_and_icon name##_ \
154 = {cb,text_callback,text_cb_data,icon}; \
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000155 static const struct menu_item_ex name = \
156 { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \
157 {.menu_get_name_and_icon = & name##_}};
158
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000159/* Use this to put a function call into the menu.
160 When the user selects this item the function will be run,
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000161 if MENU_FUNC_CHECK_RETVAL is set, the return value
162 will be checked, returning 1 will exit do_menu();
163 if MENU_FUNC_USEPARAM is set, param will be passed to the function */
164#define MENUITEM_FUNCTION(name, flags, str, func, param, \
165 callback, icon) \
Jonathan Gordon5599d682007-02-14 06:58:30 +0000166 static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000167 static const struct menu_func name##__ = {{(void*)func}, param}; \
168 /* should be const, but recording_settings wont let us do that */ \
169 const struct menu_item_ex name = \
Jonathan Gordondaf66942007-03-17 12:33:34 +0000170 { MT_FUNCTION_CALL|MENU_HAS_DESC|flags, \
171 { .function = & name##__}, {.callback_and_desc = & name##_}};
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000172
Jonathan Gordon2801a872007-02-19 02:14:51 +0000173/* As above, except the text is dynamic */
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000174#define MENUITEM_FUNCTION_DYNTEXT(name, flags, func, param, \
175 text_callback, text_cb_data, callback, icon) \
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000176 static const struct menu_get_name_and_icon name##_ \
Jonathan Gordondaf66942007-03-17 12:33:34 +0000177 = {callback,text_callback,text_cb_data,icon}; \
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000178 static const struct menu_func name##__ = {{(void*)func}, param}; \
Jonathan Gordondaf66942007-03-17 12:33:34 +0000179 static const struct menu_item_ex name = \
180 { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \
181 { .function = & name##__}, {.menu_get_name_and_icon = & name##_}};
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000182
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000183/* Use this to actually create a menu. the ... argument is a list of pointers
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000184 to any of the above macro'd variables.
185 (It can also have other menus in the list.) */
186#define MAKE_MENU( name, str, callback, icon, ... ) \
187 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
Jonathan Gordon5599d682007-02-14 06:58:30 +0000188 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000189 const struct menu_item_ex name = \
190 {MT_MENU|MENU_HAS_DESC| \
191 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000192 { (void*)name##_},{.callback_and_desc = & name##__}};
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000193
Jonathan Gordon5599d682007-02-14 06:58:30 +0000194
Jonathan Gordon26ff6972007-05-01 11:01:53 +0000195/* OLD API - This is only here for plugin compatability now, will be dropped ASAP */
Jonathan Gordon34521462007-03-07 13:00:46 +0000196struct menu_item {
197 unsigned char *desc; /* string or ID */
198 bool (*function) (void); /* return true if USB was connected */
199};
200
Jonathan Gordon21b415d2007-04-08 05:52:47 +0000201/* if button2 == button3 == NULL, button1 is the menu title */
Jonathan Gordon34521462007-03-07 13:00:46 +0000202int menu_init(const struct menu_item* mitems, int count,
203 int (*callback)(int, int),
204 const char *button1, const char *button2, const char *button3);
205void menu_exit(int menu);
206
Jonathan Gordon91e726a2007-03-27 06:38:11 +0000207 /* Returns MENU_* define from root_menu.h, or number of selected menu item*/
Jonathan Gordon34521462007-03-07 13:00:46 +0000208int menu_show(int m);
Jonathan Gordon34521462007-03-07 13:00:46 +0000209
210bool menu_run(int menu);
211int menu_count(int menu);
Jonathan Gordon02a87172007-03-03 13:52:14 +0000212
Daniel Stenberg1c0c8612002-05-17 12:22:24 +0000213#endif /* End __MENU_H__ */