Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 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 Stenberg | 91f743f | 2002-06-14 10:39:11 +0000 | [diff] [blame] | 23 | #include <stdbool.h> |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 24 | #include "icon.h" |
| 25 | #include "icons.h" |
| 26 | |
Daniel Stenberg | 91f743f | 2002-06-14 10:39:11 +0000 | [diff] [blame] | 27 | |
Linus Nielsen Feltzing | 77936e6 | 2004-03-16 13:44:56 +0000 | [diff] [blame] | 28 | struct menu_item { |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 29 | unsigned char *desc; /* string or ID */ |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 30 | bool (*function) (void); /* return true if USB was connected */ |
Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 33 | int 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 Stenberg | 2ac0572 | 2002-05-26 17:03:17 +0000 | [diff] [blame] | 36 | void menu_exit(int menu); |
Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 37 | |
Daniel Stenberg | 91f743f | 2002-06-14 10:39:11 +0000 | [diff] [blame] | 38 | void put_cursorxy(int x, int y, bool on); |
| 39 | |
Kjell Ericson | 5cd393c | 2003-01-29 08:26:11 +0000 | [diff] [blame] | 40 | /* Returns below define, or number of selected menu item*/ |
| 41 | int menu_show(int m); |
| 42 | #define MENU_ATTACHED_USB -1 |
| 43 | #define MENU_SELECTED_EXIT -2 |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 44 | #define MENU_EXIT_ALL -3 |
| 45 | #define MENU_RETURN_TO_WPS -4 |
Kjell Ericson | 5cd393c | 2003-01-29 08:26:11 +0000 | [diff] [blame] | 46 | |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 47 | bool menu_run(int menu); |
Linus Nielsen Feltzing | 10b92c4 | 2004-03-12 10:20:33 +0000 | [diff] [blame] | 48 | int menu_cursor(int menu); |
| 49 | char* menu_description(int menu, int position); |
| 50 | void menu_delete(int menu, int position); |
| 51 | int menu_count(int menu); |
| 52 | bool menu_moveup(int menu); |
| 53 | bool menu_movedown(int menu); |
| 54 | void menu_draw(int menu); |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 55 | void menu_insert(int menu, int position, char *desc, bool (*function) (void)); |
Jens Arnold | cef15c6 | 2005-04-10 17:36:55 +0000 | [diff] [blame] | 56 | void menu_set_cursor(int menu, int position); |
Kevin Ferrare | c43822d | 2005-11-03 11:56:21 +0000 | [diff] [blame] | 57 | void menu_talk_selected(int m); |
Daniel Stenberg | b285076 | 2002-08-23 12:32:52 +0000 | [diff] [blame] | 58 | |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 59 | |
| 60 | enum menu_item_type { |
| 61 | MT_MENU = 0, |
| 62 | MT_SETTING, |
Jonathan Gordon | 9709086 | 2007-03-03 14:23:03 +0000 | [diff] [blame^] | 63 | MT_SETTING_W_TEXT, /* same as setting, but uses different |
| 64 | text for the setting title, |
| 65 | ID2P() or "literal" for the str param */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 66 | MT_FUNCTION_CALL, /* used when the standard code wont work */ |
| 67 | MT_FUNCTION_WITH_PARAM, |
| 68 | MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/ |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 69 | MT_RETURN_VALUE, /* returns a value associated with an item */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | typedef int (*menu_function)(void); |
| 73 | struct menu_func_with_param { |
| 74 | int (*function)(void* param); |
| 75 | void *param; |
| 76 | }; |
| 77 | |
| 78 | #define MENU_TYPE_MASK 0xF /* MT_* type */ |
Jonathan Gordon | 2801a87 | 2007-02-19 02:14:51 +0000 | [diff] [blame] | 79 | /* these next two are mutually exclusive */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 80 | #define MENU_HAS_DESC 0x10 |
Jonathan Gordon | 2801a87 | 2007-02-19 02:14:51 +0000 | [diff] [blame] | 81 | #define MENU_DYNAMIC_DESC 0x20 |
| 82 | /* unless we need more flags*/ |
| 83 | #define MENU_COUNT_MASK (~(MENU_TYPE_MASK|MENU_HAS_DESC|MENU_DYNAMIC_DESC)) |
| 84 | #define MENU_COUNT_SHIFT 6 |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 85 | |
| 86 | struct menu_item_ex { |
| 87 | int flags; /* above defines */ |
| 88 | union { |
| 89 | const struct menu_item_ex **submenus; /* used with MT_MENU */ |
| 90 | void *variable; /* used with MT_SETTING, |
| 91 | must be in the settings_list.c list */ |
| 92 | int (*function)(void); /* used with MT_FUNCTION_CALL */ |
| 93 | const struct menu_func_with_param |
| 94 | *func_with_param; /* MT_FUNCTION_WITH_PARAM */ |
| 95 | const char **strings; /* used with MT_RETURN_ID */ |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 96 | int value; /* MT_RETURN_VALUE */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 97 | }; |
| 98 | union { |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 99 | /* For settings */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 100 | int (*menu_callback)(int action, const struct menu_item_ex *this_item); |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 101 | /* For everything else, except if the text is dynamic */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 102 | const struct menu_callback_with_desc { |
| 103 | int (*menu_callback)(int action, |
| 104 | const struct menu_item_ex *this_item); |
| 105 | unsigned char *desc; /* string or ID */ |
Jonathan Gordon | 02a8717 | 2007-03-03 13:52:14 +0000 | [diff] [blame] | 106 | int icon_id; /* from icons_6x8 in icons.h */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 107 | } *callback_and_desc; |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 108 | /* For when the item text is dynamic */ |
| 109 | const struct menu_get_name_and_icon { |
| 110 | int (*menu_callback)(int action, |
Jonathan Gordon | 2801a87 | 2007-02-19 02:14:51 +0000 | [diff] [blame] | 111 | const struct menu_item_ex *this_item); |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 112 | char *(*list_get_name)(int selected_item, void * data, char *buffer); |
| 113 | void *list_get_name_data; |
Jonathan Gordon | 02a8717 | 2007-03-03 13:52:14 +0000 | [diff] [blame] | 114 | int icon_id; |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 115 | } *menu_get_name_and_icon; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 116 | }; |
| 117 | }; |
| 118 | |
| 119 | typedef int (*menu_callback_type)(int action, |
| 120 | const struct menu_item_ex *this_item); |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 121 | int do_menu(const struct menu_item_ex *menu, int *start_selected); |
Jonathan Gordon | 2801a87 | 2007-02-19 02:14:51 +0000 | [diff] [blame] | 122 | bool do_setting_from_menu(const struct menu_item_ex *temp); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 123 | |
| 124 | #define MENU_ITEM_COUNT(c) (c<<MENU_COUNT_SHIFT) |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 125 | /* In all the following macros the argument names are as follows: |
| 126 | - name: The name for the variable (so it can be used in a MAKE_MENU() |
| 127 | - str: the string to display for this menu item. use ID2P() for LANG_* id's |
| 128 | - callback: The callback function to call for this menu item. |
| 129 | */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 130 | |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 131 | /* Use this to put a setting into a menu. |
| 132 | The setting must appear in settings_list.c. |
| 133 | If the setting is not configured properly, the menu will display "Not Done yet!" |
| 134 | When the user selects this item the setting select screen will load, |
| 135 | when that screen exits the user wll be back in the menu */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 136 | #define MENUITEM_SETTING(name,var,callback) \ |
| 137 | static const struct menu_item_ex name = \ |
| 138 | {MT_SETTING, {.variable = (void*)var},{callback}}; |
| 139 | |
Jonathan Gordon | 9709086 | 2007-03-03 14:23:03 +0000 | [diff] [blame^] | 140 | /* Use this for settings which have a differnt title in their |
| 141 | setting screen than in the menu (e.g scroll options */ |
| 142 | #define MENUITEM_SETTING_W_TEXT(name, var, str, callback ) \ |
| 143 | static const struct menu_callback_with_desc name##__ = {callback,str, Icon_NOICON};\ |
| 144 | static const struct menu_item_ex name = \ |
| 145 | {MT_SETTING_W_TEXT|MENU_HAS_DESC, {.variable = (void*)var }, \ |
| 146 | {.callback_and_desc = & name##__}}; |
| 147 | |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 148 | /* Use this To create a list of NON-XLATABLE (for the time being) Strings |
| 149 | When the user enters this list and selects one, the menu will exits |
| 150 | and its return value will be the index of the chosen item */ |
| 151 | #define MENUITEM_STRINGLIST(name, str, callback, ... ) \ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 152 | static const char *name##_[] = {__VA_ARGS__}; \ |
Jonathan Gordon | 02a8717 | 2007-03-03 13:52:14 +0000 | [diff] [blame] | 153 | static const struct menu_callback_with_desc name##__ = {callback,str, Icon_NOICON};\ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 154 | static const struct menu_item_ex name = \ |
| 155 | {MT_RETURN_ID|MENU_HAS_DESC| \ |
| 156 | MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ |
| 157 | { .submenus = name##_},{.callback_and_desc = & name##__}}; |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 158 | |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 159 | |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 160 | /* returns a value associated with the item */ |
| 161 | #define MENUITEM_RETURNVALUE(name, str, val, cb, icon) \ |
| 162 | static const struct menu_callback_with_desc name##_ = {cb,str,icon}; \ |
| 163 | static const struct menu_item_ex name = \ |
| 164 | { MT_RETURN_VALUE|MENU_HAS_DESC, { .value = val}, \ |
| 165 | {.callback_and_desc = & name##_}}; |
| 166 | |
| 167 | /* same as above, except the item name is dynamic */ |
| 168 | #define MENUITEM_RETURNVALUE_DYNTEXT(name, val, cb, text_callback, text_cb_data, icon) \ |
| 169 | static const struct menu_get_name_and_icon name##_ \ |
| 170 | = {cb,text_callback,text_cb_data,icon}; \ |
| 171 | static const struct menu_item_ex name = \ |
| 172 | { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \ |
| 173 | {.menu_get_name_and_icon = & name##_}}; |
| 174 | |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 175 | /* Use this to put a function call into the menu. |
| 176 | When the user selects this item the function will be run, |
| 177 | when it exits the user will be back in the menu. return value is ignored */ |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 178 | #define MENUITEM_FUNCTION(name, str, func, callback, icon) \ |
| 179 | static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \ |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 180 | static const struct menu_item_ex name = \ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 181 | { MT_FUNCTION_CALL|MENU_HAS_DESC, { .function = func}, \ |
| 182 | {.callback_and_desc = & name##_}}; |
| 183 | |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 184 | /* This one should be static'ed also, |
| 185 | but cannot be done untill recording menu is done */ |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 186 | /* Same as above, except the function will be called with a (void*)param. */ |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 187 | #define MENUITEM_FUNCTION_WPARAM(name, str, func, param, callback, icon) \ |
| 188 | static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 189 | static const struct menu_func_with_param name##__ = {func, param}; \ |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 190 | const struct menu_item_ex name = \ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 191 | { MT_FUNCTION_WITH_PARAM|MENU_HAS_DESC, \ |
| 192 | { .func_with_param = &name##__}, \ |
| 193 | {.callback_and_desc = & name##_}}; |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 194 | |
Jonathan Gordon | 2801a87 | 2007-02-19 02:14:51 +0000 | [diff] [blame] | 195 | /* As above, except the text is dynamic */ |
| 196 | #define MENUITEM_FUNCTION_WPARAM_DYNTEXT(name, func, param, callback, \ |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 197 | text_callback, text_cb_data, icon) \ |
| 198 | static const struct menu_get_name_and_icon name##_ \ |
| 199 | = {callback,text_callback,text_cb_data,icon};\ |
Jonathan Gordon | 2801a87 | 2007-02-19 02:14:51 +0000 | [diff] [blame] | 200 | static const struct menu_func_with_param name##__ = {func, param}; \ |
| 201 | static const struct menu_item_ex name = \ |
| 202 | { MT_FUNCTION_WITH_PARAM|MENU_DYNAMIC_DESC, \ |
| 203 | { .func_with_param = &name##__}, \ |
| 204 | {.menu_get_name_and_icon = & name##_}}; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 205 | |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 206 | /* Use this to actually create a menu. the ... argument is a list of pointers |
| 207 | to any of the above macro'd variables. (It can also have other menus in the list. */ |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 208 | #define MAKE_MENU( name, str, callback, icon, ... ) \ |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 209 | static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \ |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 210 | static const struct menu_callback_with_desc name##__ = {callback,str,icon};\ |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 211 | const struct menu_item_ex name = \ |
| 212 | {MT_MENU|MENU_HAS_DESC| \ |
| 213 | MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ |
| 214 | { (void*)name##_},{.callback_and_desc = & name##__}}; |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 215 | |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 216 | |
Jonathan Gordon | 02a8717 | 2007-03-03 13:52:14 +0000 | [diff] [blame] | 217 | |
Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 218 | #endif /* End __MENU_H__ */ |