blob: ded25500bf2eee6028a4b182e35c7adc623e539c [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 Gordonb5e587c2007-03-18 06:31:33 +000064#define MENU_GET_COUNT(flags) ((flags>>MENU_COUNT_SHIFT)&MENU_COUNT_MASK)
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000065
66struct menu_item_ex {
Jonathan Gordondaf66942007-03-17 12:33:34 +000067 unsigned int flags; /* above defines */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000068 union {
69 const struct menu_item_ex **submenus; /* used with MT_MENU */
70 void *variable; /* used with MT_SETTING,
71 must be in the settings_list.c list */
Jonathan Gordondaf66942007-03-17 12:33:34 +000072 const struct menu_func *function; /* MT_FUNCTION_* */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000073 const char **strings; /* used with MT_RETURN_ID */
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000074 int value; /* MT_RETURN_VALUE */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000075 };
76 union {
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000077 /* For settings */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000078 int (*menu_callback)(int action, const struct menu_item_ex *this_item);
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000079 /* For everything else, except if the text is dynamic */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000080 const struct menu_callback_with_desc {
81 int (*menu_callback)(int action,
82 const struct menu_item_ex *this_item);
83 unsigned char *desc; /* string or ID */
Jonathan Gordon02a87172007-03-03 13:52:14 +000084 int icon_id; /* from icons_6x8 in icons.h */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000085 } *callback_and_desc;
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000086 /* For when the item text is dynamic */
87 const struct menu_get_name_and_icon {
88 int (*menu_callback)(int action,
Jonathan Gordon2801a872007-02-19 02:14:51 +000089 const struct menu_item_ex *this_item);
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000090 char *(*list_get_name)(int selected_item, void * data, char *buffer);
91 void *list_get_name_data;
Jonathan Gordon02a87172007-03-03 13:52:14 +000092 int icon_id;
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000093 } *menu_get_name_and_icon;
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000094 };
95};
96
97typedef int (*menu_callback_type)(int action,
98 const struct menu_item_ex *this_item);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000099int do_menu(const struct menu_item_ex *menu, int *start_selected);
Jonathan Gordon2801a872007-02-19 02:14:51 +0000100bool do_setting_from_menu(const struct menu_item_ex *temp);
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000101
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000102/* In all the following macros the argument names are as follows:
103 - name: The name for the variable (so it can be used in a MAKE_MENU()
104 - str: the string to display for this menu item. use ID2P() for LANG_* id's
105 - callback: The callback function to call for this menu item.
106*/
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000107
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000108/* Use this to put a setting into a menu.
109 The setting must appear in settings_list.c.
110 If the setting is not configured properly, the menu will display "Not Done yet!"
111 When the user selects this item the setting select screen will load,
112 when that screen exits the user wll be back in the menu */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000113#define MENUITEM_SETTING(name,var,callback) \
114 static const struct menu_item_ex name = \
115 {MT_SETTING, {.variable = (void*)var},{callback}};
116
Jonathan Gordon97090862007-03-03 14:23:03 +0000117/* Use this for settings which have a differnt title in their
118 setting screen than in the menu (e.g scroll options */
119#define MENUITEM_SETTING_W_TEXT(name, var, str, callback ) \
120 static const struct menu_callback_with_desc name##__ = {callback,str, Icon_NOICON};\
121 static const struct menu_item_ex name = \
122 {MT_SETTING_W_TEXT|MENU_HAS_DESC, {.variable = (void*)var }, \
123 {.callback_and_desc = & name##__}};
124
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000125/* Use this To create a list of NON-XLATABLE (for the time being) Strings
126 When the user enters this list and selects one, the menu will exits
127 and its return value will be the index of the chosen item */
128#define MENUITEM_STRINGLIST(name, str, callback, ... ) \
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000129 static const char *name##_[] = {__VA_ARGS__}; \
Jonathan Gordon02a87172007-03-03 13:52:14 +0000130 static const struct menu_callback_with_desc name##__ = {callback,str, Icon_NOICON};\
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000131 static const struct menu_item_ex name = \
132 {MT_RETURN_ID|MENU_HAS_DESC| \
133 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
134 { .submenus = name##_},{.callback_and_desc = & name##__}};
Jonathan Gordon5599d682007-02-14 06:58:30 +0000135
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000136
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000137/* returns a value associated with the item */
138#define MENUITEM_RETURNVALUE(name, str, val, cb, icon) \
139 static const struct menu_callback_with_desc name##_ = {cb,str,icon}; \
140 static const struct menu_item_ex name = \
141 { MT_RETURN_VALUE|MENU_HAS_DESC, { .value = val}, \
142 {.callback_and_desc = & name##_}};
143
144/* same as above, except the item name is dynamic */
145#define MENUITEM_RETURNVALUE_DYNTEXT(name, val, cb, text_callback, text_cb_data, icon) \
146 static const struct menu_get_name_and_icon name##_ \
147 = {cb,text_callback,text_cb_data,icon}; \
148 static const struct menu_item_ex name = \
149 { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \
150 {.menu_get_name_and_icon = & name##_}};
151
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000152/* Use this to put a function call into the menu.
153 When the user selects this item the function will be run,
Jonathan Gordondaf66942007-03-17 12:33:34 +0000154 unless MENU_FUNC_IGNORE_RETVAL is set, when it exits the user
155 will be back in the menu and return value is ignored,
156 else if it returns exit_if do_mneu() will exit */
157#define MENUITEM_FUNCTION(name, flags, str, func, param, \
158 exit_if, callback, icon) \
Jonathan Gordon5599d682007-02-14 06:58:30 +0000159 static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \
Jonathan Gordondaf66942007-03-17 12:33:34 +0000160 static const struct menu_func name##__ = {{(void*)func}, param, exit_if}; \
161 /* should be const, but recording_settings wont let us do that */ \
162 const struct menu_item_ex name = \
163 { MT_FUNCTION_CALL|MENU_HAS_DESC|flags, \
164 { .function = & name##__}, {.callback_and_desc = & name##_}};
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000165
Jonathan Gordon2801a872007-02-19 02:14:51 +0000166/* As above, except the text is dynamic */
Jonathan Gordondaf66942007-03-17 12:33:34 +0000167#define MENUITEM_FUNCTION_DYNTEXT(name, flags, func, param, exit_if, \
168 text_callback, text_cb_data, callback, icon) \
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000169 static const struct menu_get_name_and_icon name##_ \
Jonathan Gordondaf66942007-03-17 12:33:34 +0000170 = {callback,text_callback,text_cb_data,icon}; \
171 static const struct menu_func name##__ = {{(void*)func}, param, exit_if}; \
172 static const struct menu_item_ex name = \
173 { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \
174 { .function = & name##__}, {.menu_get_name_and_icon = & name##_}};
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000175
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000176/* Use this to actually create a menu. the ... argument is a list of pointers
177 to any of the above macro'd variables. (It can also have other menus in the list. */
Jonathan Gordon5599d682007-02-14 06:58:30 +0000178#define MAKE_MENU( name, str, callback, icon, ... ) \
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000179 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
Jonathan Gordon5599d682007-02-14 06:58:30 +0000180 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000181 const struct menu_item_ex name = \
182 {MT_MENU|MENU_HAS_DESC| \
183 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
184 { (void*)name##_},{.callback_and_desc = & name##__}};
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000185
Jonathan Gordon5599d682007-02-14 06:58:30 +0000186
Jonathan Gordon34521462007-03-07 13:00:46 +0000187/* OLD API - only use if you really have to.. Ideally this will be dropped */
188struct menu_item {
189 unsigned char *desc; /* string or ID */
190 bool (*function) (void); /* return true if USB was connected */
191};
192
193int menu_init(const struct menu_item* mitems, int count,
194 int (*callback)(int, int),
195 const char *button1, const char *button2, const char *button3);
196void menu_exit(int menu);
197
198 /* Returns below define, or number of selected menu item*/
199int menu_show(int m);
200#define MENU_ATTACHED_USB -1
201#define MENU_SELECTED_EXIT -2
202#define MENU_EXIT_ALL -3
203#define MENU_RETURN_TO_WPS -4
204
205bool menu_run(int menu);
206int menu_count(int menu);
Jonathan Gordon02a87172007-03-03 13:52:14 +0000207
Daniel Stenberg1c0c8612002-05-17 12:22:24 +0000208#endif /* End __MENU_H__ */