blob: 3d1bd43cb3f7005b763d998da6e6faa07f6b4009 [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};
41
42typedef int (*menu_function)(void);
Jonathan Gordondaf66942007-03-17 12:33:34 +000043struct menu_func {
44 union {
45 int (*function_w_param)(void* param); /* intptr_t instead of void*
46 for 64bit systems */
47 int (*function)(void);
48 };
49 void *param; /* passed to function_w_param */
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 Gordon3a7760c2007-04-30 13:41:33 +000056#define MENU_EXITAFTERTHISMENU 0x40
Jonathan Gordondaf66942007-03-17 12:33:34 +000057
58/* Flags for MT_FUNCTION_CALL */
Jonathan Gordon3a7760c2007-04-30 13:41:33 +000059#define MENU_FUNC_USEPARAM 0x80
60#define MENU_FUNC_CHECK_RETVAL 0x100
Jonathan Gordondaf66942007-03-17 12:33:34 +000061
62#define MENU_COUNT_MASK 0xFFF
Jonathan Gordon3a7760c2007-04-30 13:41:33 +000063#define MENU_COUNT_SHIFT 12
Jonathan Gordondaf66942007-03-17 12:33:34 +000064#define MENU_ITEM_COUNT(c) ((c&MENU_COUNT_MASK)<<MENU_COUNT_SHIFT)
Jonathan Gordonb5e587c2007-03-18 06:31:33 +000065#define MENU_GET_COUNT(flags) ((flags>>MENU_COUNT_SHIFT)&MENU_COUNT_MASK)
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000066
67struct menu_item_ex {
Jonathan Gordondaf66942007-03-17 12:33:34 +000068 unsigned int flags; /* above defines */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000069 union {
70 const struct menu_item_ex **submenus; /* used with MT_MENU */
71 void *variable; /* used with MT_SETTING,
72 must be in the settings_list.c list */
Jonathan Gordondaf66942007-03-17 12:33:34 +000073 const struct menu_func *function; /* MT_FUNCTION_* */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000074 const char **strings; /* used with MT_RETURN_ID */
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000075 int value; /* MT_RETURN_VALUE */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000076 };
77 union {
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000078 /* For settings */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000079 int (*menu_callback)(int action, const struct menu_item_ex *this_item);
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000080 /* For everything else, except if the text is dynamic */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000081 const struct menu_callback_with_desc {
82 int (*menu_callback)(int action,
83 const struct menu_item_ex *this_item);
84 unsigned char *desc; /* string or ID */
Jonathan Gordon02a87172007-03-03 13:52:14 +000085 int icon_id; /* from icons_6x8 in icons.h */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000086 } *callback_and_desc;
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000087 /* For when the item text is dynamic */
88 const struct menu_get_name_and_icon {
89 int (*menu_callback)(int action,
Jonathan Gordon2801a872007-02-19 02:14:51 +000090 const struct menu_item_ex *this_item);
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000091 char *(*list_get_name)(int selected_item, void * data, char *buffer);
92 void *list_get_name_data;
Jonathan Gordon02a87172007-03-03 13:52:14 +000093 int icon_id;
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000094 } *menu_get_name_and_icon;
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000095 };
96};
97
98typedef int (*menu_callback_type)(int action,
99 const struct menu_item_ex *this_item);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000100int do_menu(const struct menu_item_ex *menu, int *start_selected);
Jonathan Gordon2801a872007-02-19 02:14:51 +0000101bool do_setting_from_menu(const struct menu_item_ex *temp);
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000102
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000103/* In all the following macros the argument names are as follows:
104 - name: The name for the variable (so it can be used in a MAKE_MENU()
105 - str: the string to display for this menu item. use ID2P() for LANG_* id's
106 - callback: The callback function to call for this menu item.
107*/
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000108
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000109/* Use this to put a setting into a menu.
110 The setting must appear in settings_list.c.
111 If the setting is not configured properly, the menu will display "Not Done yet!"
112 When the user selects this item the setting select screen will load,
113 when that screen exits the user wll be back in the menu */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000114#define MENUITEM_SETTING(name,var,callback) \
115 static const struct menu_item_ex name = \
116 {MT_SETTING, {.variable = (void*)var},{callback}};
117
Jonathan Gordon97090862007-03-03 14:23:03 +0000118/* Use this for settings which have a differnt title in their
119 setting screen than in the menu (e.g scroll options */
120#define MENUITEM_SETTING_W_TEXT(name, var, str, callback ) \
121 static const struct menu_callback_with_desc name##__ = {callback,str, Icon_NOICON};\
122 static const struct menu_item_ex name = \
123 {MT_SETTING_W_TEXT|MENU_HAS_DESC, {.variable = (void*)var }, \
124 {.callback_and_desc = & name##__}};
125
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000126/* Use this To create a list of NON-XLATABLE (for the time being) Strings
127 When the user enters this list and selects one, the menu will exits
128 and its return value will be the index of the chosen item */
129#define MENUITEM_STRINGLIST(name, str, callback, ... ) \
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000130 static const char *name##_[] = {__VA_ARGS__}; \
Jonathan Gordon02a87172007-03-03 13:52:14 +0000131 static const struct menu_callback_with_desc name##__ = {callback,str, Icon_NOICON};\
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000132 static const struct menu_item_ex name = \
133 {MT_RETURN_ID|MENU_HAS_DESC| \
134 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
Jonathan Gordon1f5ee2a2007-03-25 14:31:56 +0000135 { .strings = name##_},{.callback_and_desc = & name##__}};
Jonathan Gordon5599d682007-02-14 06:58:30 +0000136
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000137
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000138/* returns a value associated with the item */
139#define MENUITEM_RETURNVALUE(name, str, val, cb, icon) \
140 static const struct menu_callback_with_desc name##_ = {cb,str,icon}; \
141 static const struct menu_item_ex name = \
142 { MT_RETURN_VALUE|MENU_HAS_DESC, { .value = val}, \
143 {.callback_and_desc = & name##_}};
144
145/* same as above, except the item name is dynamic */
146#define MENUITEM_RETURNVALUE_DYNTEXT(name, val, cb, text_callback, text_cb_data, icon) \
147 static const struct menu_get_name_and_icon name##_ \
148 = {cb,text_callback,text_cb_data,icon}; \
149 static const struct menu_item_ex name = \
150 { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \
151 {.menu_get_name_and_icon = & name##_}};
152
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000153/* Use this to put a function call into the menu.
154 When the user selects this item the function will be run,
Jonathan Gordone54d8e12007-03-18 07:03:43 +0000155 unless MENU_FUNC_IGNORE_RETVAL is set, the return value
156 will be checked, returning 1 will exit do_menu(); */
Jonathan Gordondaf66942007-03-17 12:33:34 +0000157#define MENUITEM_FUNCTION(name, flags, str, func, param, \
Jonathan Gordone54d8e12007-03-18 07:03:43 +0000158 callback, icon) \
Jonathan Gordon5599d682007-02-14 06:58:30 +0000159 static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \
Jonathan Gordone54d8e12007-03-18 07:03:43 +0000160 static const struct menu_func name##__ = {{(void*)func}, param}; \
Jonathan Gordondaf66942007-03-17 12:33:34 +0000161 /* 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 Gordone54d8e12007-03-18 07:03:43 +0000167#define MENUITEM_FUNCTION_DYNTEXT(name, flags, func, param, \
Jonathan Gordondaf66942007-03-17 12:33:34 +0000168 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}; \
Jonathan Gordone54d8e12007-03-18 07:03:43 +0000171 static const struct menu_func name##__ = {{(void*)func}, param}; \
Jonathan Gordondaf66942007-03-17 12:33:34 +0000172 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
Jonathan Gordon21b415d2007-04-08 05:52:47 +0000193/* if button2 == button3 == NULL, button1 is the menu title */
Jonathan Gordon34521462007-03-07 13:00:46 +0000194int menu_init(const struct menu_item* mitems, int count,
195 int (*callback)(int, int),
196 const char *button1, const char *button2, const char *button3);
197void menu_exit(int menu);
198
Jonathan Gordon91e726a2007-03-27 06:38:11 +0000199 /* Returns MENU_* define from root_menu.h, or number of selected menu item*/
Jonathan Gordon34521462007-03-07 13:00:46 +0000200int menu_show(int m);
Jonathan Gordon34521462007-03-07 13:00:46 +0000201
202bool menu_run(int menu);
203int menu_count(int menu);
Jonathan Gordon02a87172007-03-03 13:52:14 +0000204
Daniel Stenberg1c0c8612002-05-17 12:22:24 +0000205#endif /* End __MENU_H__ */