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 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #ifndef __MENU_H__ |
| 23 | #define __MENU_H__ |
| 24 | |
Daniel Stenberg | 91f743f | 2002-06-14 10:39:11 +0000 | [diff] [blame] | 25 | #include <stdbool.h> |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 26 | #include "icon.h" |
| 27 | #include "icons.h" |
Jonathan Gordon | 91e726a | 2007-03-27 06:38:11 +0000 | [diff] [blame] | 28 | #include "root_menu.h" /* needed for MENU_* return codes */ |
Jonathan Gordon | 101693f | 2011-11-15 13:22:02 +0000 | [diff] [blame] | 29 | #include "settings_list.h" |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 30 | |
Daniel Stenberg | 91f743f | 2002-06-14 10:39:11 +0000 | [diff] [blame] | 31 | |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 32 | enum menu_item_type { |
| 33 | MT_MENU = 0, |
| 34 | MT_SETTING, |
Jonathan Gordon | 9709086 | 2007-03-03 14:23:03 +0000 | [diff] [blame] | 35 | MT_SETTING_W_TEXT, /* same as setting, but uses different |
| 36 | text for the setting title, |
| 37 | ID2P() or "literal" for the str param */ |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 38 | MT_FUNCTION_CALL, /* call a function from the menus */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 39 | 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] | 40 | MT_RETURN_VALUE, /* returns a value associated with an item */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 41 | }; |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 42 | #define MENU_TYPE_MASK 0xF /* MT_* type */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 43 | |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 44 | struct menu_func { |
| 45 | union { |
| 46 | int (*function_w_param)(void* param); /* intptr_t instead of void* |
| 47 | for 64bit systems */ |
| 48 | int (*function)(void); |
| 49 | }; |
| 50 | void *param; /* passed to function_w_param */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
Jonathan Gordon | 2801a87 | 2007-02-19 02:14:51 +0000 | [diff] [blame] | 53 | /* these next two are mutually exclusive */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 54 | #define MENU_HAS_DESC 0x10 |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 55 | #define MENU_DYNAMIC_DESC 0x20 /* the name of this menu item is set by the \ |
| 56 | list_get_name callback */ |
| 57 | |
| 58 | #define MENU_EXITAFTERTHISMENU 0x40 /* do_menu() will exiting out of any \ |
| 59 | menu item with this flag set */ |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 60 | |
| 61 | /* Flags for MT_FUNCTION_CALL */ |
Jonathan Gordon | 3a7760c | 2007-04-30 13:41:33 +0000 | [diff] [blame] | 62 | #define MENU_FUNC_USEPARAM 0x80 |
| 63 | #define MENU_FUNC_CHECK_RETVAL 0x100 |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 64 | |
| 65 | #define MENU_COUNT_MASK 0xFFF |
Jonathan Gordon | 3a7760c | 2007-04-30 13:41:33 +0000 | [diff] [blame] | 66 | #define MENU_COUNT_SHIFT 12 |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 67 | #define MENU_ITEM_COUNT(c) ((c&MENU_COUNT_MASK)<<MENU_COUNT_SHIFT) |
Jonathan Gordon | b5e587c | 2007-03-18 06:31:33 +0000 | [diff] [blame] | 68 | #define MENU_GET_COUNT(flags) ((flags>>MENU_COUNT_SHIFT)&MENU_COUNT_MASK) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 69 | |
| 70 | struct menu_item_ex { |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 71 | unsigned int flags; /* above defines */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 72 | union { |
| 73 | const struct menu_item_ex **submenus; /* used with MT_MENU */ |
| 74 | void *variable; /* used with MT_SETTING, |
| 75 | must be in the settings_list.c list */ |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 76 | const struct menu_func *function; /* MT_FUNCTION_* */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 77 | const char **strings; /* used with MT_RETURN_ID */ |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 78 | int value; /* MT_RETURN_VALUE */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 79 | }; |
| 80 | union { |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 81 | /* For settings */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 82 | int (*menu_callback)(int action, const struct menu_item_ex *this_item); |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 83 | /* For everything else, except if the text is dynamic */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 84 | const struct menu_callback_with_desc { |
| 85 | int (*menu_callback)(int action, |
| 86 | const struct menu_item_ex *this_item); |
| 87 | unsigned char *desc; /* string or ID */ |
Jonathan Gordon | 02a8717 | 2007-03-03 13:52:14 +0000 | [diff] [blame] | 88 | int icon_id; /* from icons_6x8 in icons.h */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 89 | } *callback_and_desc; |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 90 | /* For when the item text is dynamic */ |
| 91 | const struct menu_get_name_and_icon { |
| 92 | int (*menu_callback)(int action, |
Jonathan Gordon | 2801a87 | 2007-02-19 02:14:51 +0000 | [diff] [blame] | 93 | const struct menu_item_ex *this_item); |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 94 | char *(*list_get_name)(int selected_item, void * data, char *buffer); |
Stéphane Doyon | 5acf091 | 2007-10-09 03:48:56 +0000 | [diff] [blame] | 95 | int (*list_speak_item)(int selected_item, void * data); |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 96 | void *list_get_name_data; |
Jonathan Gordon | 02a8717 | 2007-03-03 13:52:14 +0000 | [diff] [blame] | 97 | int icon_id; |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 98 | } *menu_get_name_and_icon; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 99 | }; |
| 100 | }; |
| 101 | |
| 102 | typedef int (*menu_callback_type)(int action, |
| 103 | const struct menu_item_ex *this_item); |
Steve Bavin | f14999e | 2009-03-10 07:27:13 +0000 | [diff] [blame] | 104 | void do_setting_from_menu(const struct menu_item_ex *temp, |
Jonathan Gordon | fe9dca3 | 2008-04-23 11:07:40 +0000 | [diff] [blame] | 105 | struct viewport parent[NB_SCREENS]); |
Jonathan Gordon | 101693f | 2011-11-15 13:22:02 +0000 | [diff] [blame] | 106 | void do_setting_screen(const struct settings_list *setting, const char * title, |
| 107 | struct viewport parent[NB_SCREENS]); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 108 | |
Jonathan Gordon | b85817a | 2007-05-20 08:26:27 +0000 | [diff] [blame] | 109 | /* |
| 110 | int do_menu(const struct menu_item_ex *menu, int *start_selected) |
| 111 | |
| 112 | Return value - usually one of the GO_TO_* values from root_menu.h, |
| 113 | however, some of the following defines can cause this to |
| 114 | return a different value. |
| 115 | |
| 116 | *menu - The menu to run, can be a pointer to a MAKE_MENU() variable, |
| 117 | MENUITEM_STRINGLIST() or MENUITEM_RETURNVALUE() variable. |
| 118 | |
| 119 | *start_selected - the item to select when the menu is first run. |
| 120 | When do_menu() returns, this will be set to the |
| 121 | index of the selected item at the time of the exit. |
| 122 | This is always set, even if the menu was cancelled. |
| 123 | If NULL it is ignored and the firs item starts selected |
| 124 | */ |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 125 | int do_menu(const struct menu_item_ex *menu, int *start_selected, |
Thomas Martitz | 5629d55 | 2010-01-26 20:14:42 +0000 | [diff] [blame] | 126 | struct viewport parent[NB_SCREENS], bool hide_theme); |
Jonathan Gordon | b85817a | 2007-05-20 08:26:27 +0000 | [diff] [blame] | 127 | |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 128 | /* In all the following macros the argument names are as follows: |
| 129 | - name: The name for the variable (so it can be used in a MAKE_MENU() |
| 130 | - str: the string to display for this menu item. use ID2P() for LANG_* id's |
| 131 | - callback: The callback function to call for this menu item. |
| 132 | */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 133 | |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 134 | /* Use this to put a setting into a menu. |
| 135 | The setting must appear in settings_list.c. |
| 136 | If the setting is not configured properly, the menu will display "Not Done yet!" |
| 137 | When the user selects this item the setting select screen will load, |
| 138 | when that screen exits the user wll be back in the menu */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 139 | #define MENUITEM_SETTING(name,var,callback) \ |
| 140 | static const struct menu_item_ex name = \ |
| 141 | {MT_SETTING, {.variable = (void*)var},{callback}}; |
| 142 | |
Jonathan Gordon | 9709086 | 2007-03-03 14:23:03 +0000 | [diff] [blame] | 143 | /* Use this for settings which have a differnt title in their |
| 144 | setting screen than in the menu (e.g scroll options */ |
| 145 | #define MENUITEM_SETTING_W_TEXT(name, var, str, callback ) \ |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 146 | static const struct menu_callback_with_desc name##__ = \ |
| 147 | {callback,str, Icon_NOICON}; \ |
Jonathan Gordon | 9709086 | 2007-03-03 14:23:03 +0000 | [diff] [blame] | 148 | static const struct menu_item_ex name = \ |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 149 | {MT_SETTING_W_TEXT|MENU_HAS_DESC, {.variable = (void*)var }, \ |
Jonathan Gordon | 9709086 | 2007-03-03 14:23:03 +0000 | [diff] [blame] | 150 | {.callback_and_desc = & name##__}}; |
| 151 | |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 152 | /* Use this To create a list of Strings (or ID2P()'s ) |
Jonathan Gordon | b85817a | 2007-05-20 08:26:27 +0000 | [diff] [blame] | 153 | When the user enters this list and selects one, the menu will exit |
| 154 | and do_menu() will return value the index of the chosen item. |
| 155 | if the user cancels, GO_TO_PREVIOUS will be returned */ |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 156 | #define MENUITEM_STRINGLIST(name, str, callback, ... ) \ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 157 | static const char *name##_[] = {__VA_ARGS__}; \ |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 158 | static const struct menu_callback_with_desc name##__ = \ |
| 159 | {callback,str, Icon_NOICON}; \ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 160 | static const struct menu_item_ex name = \ |
| 161 | {MT_RETURN_ID|MENU_HAS_DESC| \ |
| 162 | MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ |
Jonathan Gordon | 1f5ee2a | 2007-03-25 14:31:56 +0000 | [diff] [blame] | 163 | { .strings = name##_},{.callback_and_desc = & name##__}}; |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 164 | |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 165 | |
Jonathan Gordon | b85817a | 2007-05-20 08:26:27 +0000 | [diff] [blame] | 166 | /* causes do_menu() to return a value associated with the item */ |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 167 | #define MENUITEM_RETURNVALUE(name, str, val, cb, icon) \ |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 168 | static const struct menu_callback_with_desc name##_ = {cb,str,icon}; \ |
| 169 | static const struct menu_item_ex name = \ |
| 170 | { MT_RETURN_VALUE|MENU_HAS_DESC, { .value = val}, \ |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 171 | {.callback_and_desc = & name##_}}; |
| 172 | |
| 173 | /* same as above, except the item name is dynamic */ |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 174 | #define MENUITEM_RETURNVALUE_DYNTEXT(name, val, cb, text_callback, \ |
Stéphane Doyon | 5acf091 | 2007-10-09 03:48:56 +0000 | [diff] [blame] | 175 | voice_callback, text_cb_data, icon) \ |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 176 | static const struct menu_get_name_and_icon name##_ \ |
Stéphane Doyon | 5acf091 | 2007-10-09 03:48:56 +0000 | [diff] [blame] | 177 | = {cb,text_callback,voice_callback,text_cb_data,icon}; \ |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 178 | static const struct menu_item_ex name = \ |
| 179 | { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \ |
| 180 | {.menu_get_name_and_icon = & name##_}}; |
| 181 | |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 182 | /* Use this to put a function call into the menu. |
| 183 | When the user selects this item the function will be run, |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 184 | if MENU_FUNC_CHECK_RETVAL is set, the return value |
| 185 | will be checked, returning 1 will exit do_menu(); |
| 186 | if MENU_FUNC_USEPARAM is set, param will be passed to the function */ |
| 187 | #define MENUITEM_FUNCTION(name, flags, str, func, param, \ |
| 188 | callback, icon) \ |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 189 | static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \ |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 190 | static const struct menu_func name##__ = {{(void*)func}, param}; \ |
| 191 | /* should be const, but recording_settings wont let us do that */ \ |
| 192 | const struct menu_item_ex name = \ |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 193 | { MT_FUNCTION_CALL|MENU_HAS_DESC|flags, \ |
| 194 | { .function = & name##__}, {.callback_and_desc = & name##_}}; |
Jonathan Gordon | 8ca99d3 | 2007-02-27 11:09:09 +0000 | [diff] [blame] | 195 | |
Jonathan Gordon | 2801a87 | 2007-02-19 02:14:51 +0000 | [diff] [blame] | 196 | /* As above, except the text is dynamic */ |
Stéphane Doyon | 5acf091 | 2007-10-09 03:48:56 +0000 | [diff] [blame] | 197 | #define MENUITEM_FUNCTION_DYNTEXT(name, flags, func, param, \ |
| 198 | text_callback, voice_callback, \ |
| 199 | text_cb_data, callback, icon) \ |
| 200 | static const struct menu_get_name_and_icon name##_ \ |
| 201 | = {callback,text_callback,voice_callback,text_cb_data,icon}; \ |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 202 | static const struct menu_func name##__ = {{(void*)func}, param}; \ |
Thomas Martitz | a453bee | 2011-10-17 18:57:44 +0000 | [diff] [blame] | 203 | const struct menu_item_ex name = \ |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 204 | { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \ |
| 205 | { .function = & name##__}, {.menu_get_name_and_icon = & name##_}}; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 206 | |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 207 | /* Use this to actually create a menu. the ... argument is a list of pointers |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 208 | to any of the above macro'd variables. |
| 209 | (It can also have other menus in the list.) */ |
| 210 | #define MAKE_MENU( name, str, callback, icon, ... ) \ |
| 211 | static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \ |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 212 | static const struct menu_callback_with_desc name##__ = {callback,str,icon};\ |
Jonathan Gordon | 26ff697 | 2007-05-01 11:01:53 +0000 | [diff] [blame] | 213 | const struct menu_item_ex name = \ |
| 214 | {MT_MENU|MENU_HAS_DESC| \ |
| 215 | MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ |
Jonathan Gordon | 37d246a | 2007-02-11 10:31:50 +0000 | [diff] [blame] | 216 | { (void*)name##_},{.callback_and_desc = & name##__}}; |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 217 | |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 218 | |
Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 219 | #endif /* End __MENU_H__ */ |