blob: f5bc2dd1798eedd035ed49df463f0630e6ac58cc [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
Linus Nielsen Feltzing77936e62004-03-16 13:44:56 +000028struct menu_item {
Jörg Hohensohnb1403ee2004-07-23 23:01:20 +000029 unsigned char *desc; /* string or ID */
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000030 bool (*function) (void); /* return true if USB was connected */
Daniel Stenberg1c0c8612002-05-17 12:22:24 +000031};
32
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000033int menu_init(const struct menu_item* mitems, int count,
34 int (*callback)(int, int),
35 const char *button1, const char *button2, const char *button3);
Björn Stenberg2ac05722002-05-26 17:03:17 +000036void menu_exit(int menu);
Daniel Stenberg1c0c8612002-05-17 12:22:24 +000037
Daniel Stenberg91f743f2002-06-14 10:39:11 +000038void put_cursorxy(int x, int y, bool on);
39
Kjell Ericson5cd393c2003-01-29 08:26:11 +000040 /* Returns below define, or number of selected menu item*/
41int menu_show(int m);
42#define MENU_ATTACHED_USB -1
43#define MENU_SELECTED_EXIT -2
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000044#define MENU_EXIT_ALL -3
45#define MENU_RETURN_TO_WPS -4
Kjell Ericson5cd393c2003-01-29 08:26:11 +000046
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000047bool menu_run(int menu);
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +000048int menu_cursor(int menu);
49char* menu_description(int menu, int position);
50void menu_delete(int menu, int position);
51int menu_count(int menu);
52bool menu_moveup(int menu);
53bool menu_movedown(int menu);
54void menu_draw(int menu);
Jörg Hohensohnb1403ee2004-07-23 23:01:20 +000055void menu_insert(int menu, int position, char *desc, bool (*function) (void));
Jens Arnoldcef15c62005-04-10 17:36:55 +000056void menu_set_cursor(int menu, int position);
Kevin Ferrarec43822d2005-11-03 11:56:21 +000057void menu_talk_selected(int m);
Daniel Stenbergb2850762002-08-23 12:32:52 +000058
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000059
60enum menu_item_type {
61 MT_MENU = 0,
62 MT_SETTING,
63 MT_FUNCTION_CALL, /* used when the standard code wont work */
64 MT_FUNCTION_WITH_PARAM,
65 MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000066 MT_RETURN_VALUE, /* returns a value associated with an item */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000067};
68
69typedef int (*menu_function)(void);
70struct menu_func_with_param {
71 int (*function)(void* param);
72 void *param;
73};
74
75#define MENU_TYPE_MASK 0xF /* MT_* type */
Jonathan Gordon2801a872007-02-19 02:14:51 +000076/* these next two are mutually exclusive */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000077#define MENU_HAS_DESC 0x10
Jonathan Gordon2801a872007-02-19 02:14:51 +000078#define MENU_DYNAMIC_DESC 0x20
79/* unless we need more flags*/
80#define MENU_COUNT_MASK (~(MENU_TYPE_MASK|MENU_HAS_DESC|MENU_DYNAMIC_DESC))
81#define MENU_COUNT_SHIFT 6
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000082
83struct menu_item_ex {
84 int flags; /* above defines */
85 union {
86 const struct menu_item_ex **submenus; /* used with MT_MENU */
87 void *variable; /* used with MT_SETTING,
88 must be in the settings_list.c list */
89 int (*function)(void); /* used with MT_FUNCTION_CALL */
90 const struct menu_func_with_param
91 *func_with_param; /* MT_FUNCTION_WITH_PARAM */
92 const char **strings; /* used with MT_RETURN_ID */
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000093 int value; /* MT_RETURN_VALUE */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000094 };
95 union {
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000096 /* For settings */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000097 int (*menu_callback)(int action, const struct menu_item_ex *this_item);
Jonathan Gordon8ca99d32007-02-27 11:09:09 +000098 /* For everything else, except if the text is dynamic */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000099 const struct menu_callback_with_desc {
100 int (*menu_callback)(int action,
101 const struct menu_item_ex *this_item);
102 unsigned char *desc; /* string or ID */
Jonathan Gordon02a87172007-03-03 13:52:14 +0000103 int icon_id; /* from icons_6x8 in icons.h */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000104 } *callback_and_desc;
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000105 /* For when the item text is dynamic */
106 const struct menu_get_name_and_icon {
107 int (*menu_callback)(int action,
Jonathan Gordon2801a872007-02-19 02:14:51 +0000108 const struct menu_item_ex *this_item);
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000109 char *(*list_get_name)(int selected_item, void * data, char *buffer);
110 void *list_get_name_data;
Jonathan Gordon02a87172007-03-03 13:52:14 +0000111 int icon_id;
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000112 } *menu_get_name_and_icon;
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000113 };
114};
115
116typedef int (*menu_callback_type)(int action,
117 const struct menu_item_ex *this_item);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000118int do_menu(const struct menu_item_ex *menu, int *start_selected);
Jonathan Gordon2801a872007-02-19 02:14:51 +0000119bool do_setting_from_menu(const struct menu_item_ex *temp);
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000120
121#define MENU_ITEM_COUNT(c) (c<<MENU_COUNT_SHIFT)
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000122/* In all the following macros the argument names are as follows:
123 - name: The name for the variable (so it can be used in a MAKE_MENU()
124 - str: the string to display for this menu item. use ID2P() for LANG_* id's
125 - callback: The callback function to call for this menu item.
126*/
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000127
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000128/* Use this to put a setting into a menu.
129 The setting must appear in settings_list.c.
130 If the setting is not configured properly, the menu will display "Not Done yet!"
131 When the user selects this item the setting select screen will load,
132 when that screen exits the user wll be back in the menu */
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000133#define MENUITEM_SETTING(name,var,callback) \
134 static const struct menu_item_ex name = \
135 {MT_SETTING, {.variable = (void*)var},{callback}};
136
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000137/* Use this To create a list of NON-XLATABLE (for the time being) Strings
138 When the user enters this list and selects one, the menu will exits
139 and its return value will be the index of the chosen item */
140#define MENUITEM_STRINGLIST(name, str, callback, ... ) \
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000141 static const char *name##_[] = {__VA_ARGS__}; \
Jonathan Gordon02a87172007-03-03 13:52:14 +0000142 static const struct menu_callback_with_desc name##__ = {callback,str, Icon_NOICON};\
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000143 static const struct menu_item_ex name = \
144 {MT_RETURN_ID|MENU_HAS_DESC| \
145 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
146 { .submenus = name##_},{.callback_and_desc = & name##__}};
Jonathan Gordon5599d682007-02-14 06:58:30 +0000147
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000148
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000149/* returns a value associated with the item */
150#define MENUITEM_RETURNVALUE(name, str, val, cb, icon) \
151 static const struct menu_callback_with_desc name##_ = {cb,str,icon}; \
152 static const struct menu_item_ex name = \
153 { MT_RETURN_VALUE|MENU_HAS_DESC, { .value = val}, \
154 {.callback_and_desc = & name##_}};
155
156/* same as above, except the item name is dynamic */
157#define MENUITEM_RETURNVALUE_DYNTEXT(name, val, cb, text_callback, text_cb_data, icon) \
158 static const struct menu_get_name_and_icon name##_ \
159 = {cb,text_callback,text_cb_data,icon}; \
160 static const struct menu_item_ex name = \
161 { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \
162 {.menu_get_name_and_icon = & name##_}};
163
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000164/* Use this to put a function call into the menu.
165 When the user selects this item the function will be run,
166 when it exits the user will be back in the menu. return value is ignored */
Jonathan Gordon5599d682007-02-14 06:58:30 +0000167#define MENUITEM_FUNCTION(name, str, func, callback, icon) \
168 static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000169 static const struct menu_item_ex name = \
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000170 { MT_FUNCTION_CALL|MENU_HAS_DESC, { .function = func}, \
171 {.callback_and_desc = & name##_}};
172
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000173/* This one should be static'ed also,
174 but cannot be done untill recording menu is done */
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000175/* Same as above, except the function will be called with a (void*)param. */
Jonathan Gordon5599d682007-02-14 06:58:30 +0000176#define MENUITEM_FUNCTION_WPARAM(name, str, func, param, callback, icon) \
177 static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000178 static const struct menu_func_with_param name##__ = {func, param}; \
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000179 const struct menu_item_ex name = \
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000180 { MT_FUNCTION_WITH_PARAM|MENU_HAS_DESC, \
181 { .func_with_param = &name##__}, \
182 {.callback_and_desc = & name##_}};
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000183
Jonathan Gordon2801a872007-02-19 02:14:51 +0000184/* As above, except the text is dynamic */
185#define MENUITEM_FUNCTION_WPARAM_DYNTEXT(name, func, param, callback, \
Jonathan Gordon8ca99d32007-02-27 11:09:09 +0000186 text_callback, text_cb_data, icon) \
187 static const struct menu_get_name_and_icon name##_ \
188 = {callback,text_callback,text_cb_data,icon};\
Jonathan Gordon2801a872007-02-19 02:14:51 +0000189 static const struct menu_func_with_param name##__ = {func, param}; \
190 static const struct menu_item_ex name = \
191 { MT_FUNCTION_WITH_PARAM|MENU_DYNAMIC_DESC, \
192 { .func_with_param = &name##__}, \
193 {.menu_get_name_and_icon = & name##_}};
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000194
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000195/* Use this to actually create a menu. the ... argument is a list of pointers
196 to any of the above macro'd variables. (It can also have other menus in the list. */
Jonathan Gordon5599d682007-02-14 06:58:30 +0000197#define MAKE_MENU( name, str, callback, icon, ... ) \
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000198 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
Jonathan Gordon5599d682007-02-14 06:58:30 +0000199 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
Jonathan Gordon37d246a2007-02-11 10:31:50 +0000200 const struct menu_item_ex name = \
201 {MT_MENU|MENU_HAS_DESC| \
202 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
203 { (void*)name##_},{.callback_and_desc = & name##__}};
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000204
Jonathan Gordon5599d682007-02-14 06:58:30 +0000205
Jonathan Gordon02a87172007-03-03 13:52:14 +0000206
Daniel Stenberg1c0c8612002-05-17 12:22:24 +0000207#endif /* End __MENU_H__ */