blob: 6d7d113c8c57384cdab6ab0b7551901089dd9b84 [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"
26
Daniel Stenberg91f743f2002-06-14 10:39:11 +000027
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000028enum menu_item_type {
29 MT_MENU = 0,
30 MT_SETTING,
Jonathan Gordon97090862007-03-03 14:23:03 +000031 MT_SETTING_W_TEXT, /* same as setting, but uses different
32 text for the setting title,
33 ID2P() or "literal" for the str param */
Jonathan Gordondaf66942007-03-17 12:33:34 +000034 MT_FUNCTION_CALL, /* call a function from the menus */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000035 MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000036 MT_RETURN_VALUE, /* returns a value associated with an item */
Jonathan Gordon34521462007-03-07 13:00:46 +000037 MT_OLD_MENU, /* used so we can wrap the old menu api
38 around the new api. Noone else should use this */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000039};
40
41typedef int (*menu_function)(void);
Jonathan Gordondaf66942007-03-17 12:33:34 +000042struct menu_func {
43 union {
44 int (*function_w_param)(void* param); /* intptr_t instead of void*
45 for 64bit systems */
46 int (*function)(void);
47 };
48 void *param; /* passed to function_w_param */
49 int exit_value; /* exit do_menu() if function returns this value */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000050};
51
52#define MENU_TYPE_MASK 0xF /* MT_* type */
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 Gordon2801a872007-02-19 02:14:51 +000055#define MENU_DYNAMIC_DESC 0x20
Jonathan Gordondaf66942007-03-17 12:33:34 +000056
57/* Flags for MT_FUNCTION_CALL */
58#define MENU_FUNC_USEPARAM 0x40
59#define MENU_FUNC_CHECK_RETVAL 0x80
60
61#define MENU_COUNT_MASK 0xFFF
62#define MENU_COUNT_SHIFT 8
63#define MENU_ITEM_COUNT(c) ((c&MENU_COUNT_MASK)<<MENU_COUNT_SHIFT)
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000064
65struct menu_item_ex {
Jonathan Gordondaf66942007-03-17 12:33:34 +000066 unsigned int flags; /* above defines */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000067 union {
68 const struct menu_item_ex **submenus; /* used with MT_MENU */
69 void *variable; /* used with MT_SETTING,
70 must be in the settings_list.c list */
Jonathan Gordondaf66942007-03-17 12:33:34 +000071 const struct menu_func *function; /* MT_FUNCTION_* */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000072 const char **strings; /* used with MT_RETURN_ID */
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000073 int value; /* MT_RETURN_VALUE */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000074 };
75 union {
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000076 /* For settings */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000077 int (*menu_callback)(int action, const struct menu_item_ex *this_item);
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000078 /* For everything else, except if the text is dynamic */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000079 const struct menu_callback_with_desc {
80 int (*menu_callback)(int action,
81 const struct menu_item_ex *this_item);
82 unsigned char *desc; /* string or ID */
Jonathan Gordon02a87172007-03-03 13:52:14 +000083 int icon_id; /* from icons_6x8 in icons.h */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000084 } *callback_and_desc;
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000085 /* For when the item text is dynamic */
86 const struct menu_get_name_and_icon {
87 int (*menu_callback)(int action,
Jonathan Gordon2801a872007-02-19 02:14:51 +000088 const struct menu_item_ex *this_item);
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000089 char *(*list_get_name)(int selected_item, void * data, char *buffer);
90 void *list_get_name_data;
Jonathan Gordon02a87172007-03-03 13:52:14 +000091 int icon_id;
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000092 } *menu_get_name_and_icon;
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000093 };
94};
95
96typedef int (*menu_callback_type)(int action,
97 const struct menu_item_ex *this_item);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000098int do_menu(const struct menu_item_ex *menu, int *start_selected);
Jonathan Gordon2801a872007-02-19 02:14:51 +000099bool do_setting_from_menu(const struct menu_item_ex *temp);
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000100
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000101/* In all the following macros the argument names are as follows:
102 - name: The name for the variable (so it can be used in a MAKE_MENU()
103 - str: the string to display for this menu item. use ID2P() for LANG_* id's
104 - callback: The callback function to call for this menu item.
105*/
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000106
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000107/* Use this to put a setting into a menu.
108 The setting must appear in settings_list.c.
109 If the setting is not configured properly, the menu will display "Not Done yet!"
110 When the user selects this item the setting select screen will load,
111 when that screen exits the user wll be back in the menu */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000112#define MENUITEM_SETTING(name,var,callback) \
113 static const struct menu_item_ex name = \
114 {MT_SETTING, {.variable = (void*)var},{callback}};
115
Jonathan Gordon97090862007-03-03 14:23:03 +0000116/* Use this for settings which have a differnt title in their
117 setting screen than in the menu (e.g scroll options */
118#define MENUITEM_SETTING_W_TEXT(name, var, str, callback ) \
119 static const struct menu_callback_with_desc name##__ = {callback,str, Icon_NOICON};\
120 static const struct menu_item_ex name = \
121 {MT_SETTING_W_TEXT|MENU_HAS_DESC, {.variable = (void*)var }, \
122 {.callback_and_desc = & name##__}};
123
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000124/* Use this To create a list of NON-XLATABLE (for the time being) Strings
125 When the user enters this list and selects one, the menu will exits
126 and its return value will be the index of the chosen item */
127#define MENUITEM_STRINGLIST(name, str, callback, ... ) \
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000128 static const char *name##_[] = {__VA_ARGS__}; \
Jonathan Gordon02a87172007-03-03 13:52:14 +0000129 static const struct menu_callback_with_desc name##__ = {callback,str, Icon_NOICON};\
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000130 static const struct menu_item_ex name = \
131 {MT_RETURN_ID|MENU_HAS_DESC| \
132 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
133 { .submenus = name##_},{.callback_and_desc = & name##__}};
Jonathan Gordon5599d682007-02-14 06:58:30 +0000134
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000135
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000136/* returns a value associated with the item */
137#define MENUITEM_RETURNVALUE(name, str, val, cb, icon) \
138 static const struct menu_callback_with_desc name##_ = {cb,str,icon}; \
139 static const struct menu_item_ex name = \
140 { MT_RETURN_VALUE|MENU_HAS_DESC, { .value = val}, \
141 {.callback_and_desc = & name##_}};
142
143/* same as above, except the item name is dynamic */
144#define MENUITEM_RETURNVALUE_DYNTEXT(name, val, cb, text_callback, text_cb_data, icon) \
145 static const struct menu_get_name_and_icon name##_ \
146 = {cb,text_callback,text_cb_data,icon}; \
147 static const struct menu_item_ex name = \
148 { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \
149 {.menu_get_name_and_icon = & name##_}};
150
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000151/* Use this to put a function call into the menu.
152 When the user selects this item the function will be run,
Jonathan Gordondaf66942007-03-17 12:33:34 +0000153 unless MENU_FUNC_IGNORE_RETVAL is set, when it exits the user
154 will be back in the menu and return value is ignored,
155 else if it returns exit_if do_mneu() will exit */
156#define MENUITEM_FUNCTION(name, flags, str, func, param, \
157 exit_if, callback, icon) \
Jonathan Gordon5599d682007-02-14 06:58:30 +0000158 static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \
Jonathan Gordondaf66942007-03-17 12:33:34 +0000159 static const struct menu_func name##__ = {{(void*)func}, param, exit_if}; \
160 /* should be const, but recording_settings wont let us do that */ \
161 const struct menu_item_ex name = \
162 { MT_FUNCTION_CALL|MENU_HAS_DESC|flags, \
163 { .function = & name##__}, {.callback_and_desc = & name##_}};
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000164
Jonathan Gordon2801a872007-02-19 02:14:51 +0000165/* As above, except the text is dynamic */
Jonathan Gordondaf66942007-03-17 12:33:34 +0000166#define MENUITEM_FUNCTION_DYNTEXT(name, flags, func, param, exit_if, \
167 text_callback, text_cb_data, callback, icon) \
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000168 static const struct menu_get_name_and_icon name##_ \
Jonathan Gordondaf66942007-03-17 12:33:34 +0000169 = {callback,text_callback,text_cb_data,icon}; \
170 static const struct menu_func name##__ = {{(void*)func}, param, exit_if}; \
171 static const struct menu_item_ex name = \
172 { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \
173 { .function = & name##__}, {.menu_get_name_and_icon = & name##_}};
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000174
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000175/* Use this to actually create a menu. the ... argument is a list of pointers
176 to any of the above macro'd variables. (It can also have other menus in the list. */
Jonathan Gordon5599d682007-02-14 06:58:30 +0000177#define MAKE_MENU( name, str, callback, icon, ... ) \
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000178 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
Jonathan Gordon5599d682007-02-14 06:58:30 +0000179 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000180 const struct menu_item_ex name = \
181 {MT_MENU|MENU_HAS_DESC| \
182 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
183 { (void*)name##_},{.callback_and_desc = & name##__}};
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000184
Jonathan Gordon5599d682007-02-14 06:58:30 +0000185
Jonathan Gordon34521462007-03-07 13:00:46 +0000186/* OLD API - only use if you really have to.. Ideally this will be dropped */
187struct menu_item {
188 unsigned char *desc; /* string or ID */
189 bool (*function) (void); /* return true if USB was connected */
190};
191
192int menu_init(const struct menu_item* mitems, int count,
193 int (*callback)(int, int),
194 const char *button1, const char *button2, const char *button3);
195void menu_exit(int menu);
196
197 /* Returns below define, or number of selected menu item*/
198int menu_show(int m);
199#define MENU_ATTACHED_USB -1
200#define MENU_SELECTED_EXIT -2
201#define MENU_EXIT_ALL -3
202#define MENU_RETURN_TO_WPS -4
203
204bool menu_run(int menu);
205int menu_count(int menu);
Jonathan Gordon02a87172007-03-03 13:52:14 +0000206
Daniel Stenberg1c0c8612002-05-17 12:22:24 +0000207#endif /* End __MENU_H__ */