diff options
author | William Wilgus <wilgus.william@gmail.com> | 2022-12-17 02:43:41 -0500 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2022-12-17 02:51:43 -0500 |
commit | ccf1aaa5bede11c95d219adbf6267426b57613d2 (patch) | |
tree | a2670a79c42b743d19631055385004706369b5d2 /apps/menu.h | |
parent | 6f54bb63fc1f0da06330806321fbba50b1364907 (diff) | |
download | rockbox-ccf1aaa5bede11c95d219adbf6267426b57613d2.tar.gz rockbox-ccf1aaa5bede11c95d219adbf6267426b57613d2.zip |
menus move functions with parameters to their own type
left the union with function(void) and function_w_param(param)
as a few areas might still need to use both (onplay.c)
there might be a few I missed yet..
Change-Id: I593a6875301923e19ba04ad1b0f3173dc9ebdf1f
Diffstat (limited to 'apps/menu.h')
-rw-r--r-- | apps/menu.h | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/apps/menu.h b/apps/menu.h index e56a4a149b..acdc8e987f 100644 --- a/apps/menu.h +++ b/apps/menu.h | |||
@@ -37,12 +37,13 @@ enum menu_item_type { | |||
37 | text for the setting title, | 37 | text for the setting title, |
38 | ID2P() or "literal" for the str param */ | 38 | ID2P() or "literal" for the str param */ |
39 | MT_FUNCTION_CALL, /* call a function from the menus */ | 39 | MT_FUNCTION_CALL, /* call a function from the menus */ |
40 | MT_FUNCTION_CALL_W_PARAM, /* call a function from the menus */ | ||
40 | MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/ | 41 | MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/ |
41 | MT_RETURN_VALUE, /* returns a value associated with an item */ | 42 | MT_RETURN_VALUE, /* returns a value associated with an item */ |
42 | }; | 43 | }; |
43 | #define MENU_TYPE_MASK 0xF /* MT_* type */ | 44 | #define MENU_TYPE_MASK 0xF /* MT_* type */ |
44 | 45 | ||
45 | struct menu_func { | 46 | struct menu_func_param { |
46 | union { | 47 | union { |
47 | int (*function_w_param)(void* param); /* intptr_t instead of void* | 48 | int (*function_w_param)(void* param); /* intptr_t instead of void* |
48 | for 64bit systems */ | 49 | for 64bit systems */ |
@@ -51,6 +52,10 @@ struct menu_func { | |||
51 | void *param; /* passed to function_w_param */ | 52 | void *param; /* passed to function_w_param */ |
52 | }; | 53 | }; |
53 | 54 | ||
55 | struct menu_func { | ||
56 | int (*function)(void); | ||
57 | }; | ||
58 | |||
54 | /* these next two are mutually exclusive */ | 59 | /* these next two are mutually exclusive */ |
55 | #define MENU_HAS_DESC 0x10 | 60 | #define MENU_HAS_DESC 0x10 |
56 | #define MENU_DYNAMIC_DESC 0x20 /* the name of this menu item is set by the \ | 61 | #define MENU_DYNAMIC_DESC 0x20 /* the name of this menu item is set by the \ |
@@ -75,6 +80,7 @@ struct menu_item_ex { | |||
75 | void *variable; /* used with MT_SETTING, | 80 | void *variable; /* used with MT_SETTING, |
76 | must be in the settings_list.c list */ | 81 | must be in the settings_list.c list */ |
77 | const struct menu_func *function; /* MT_FUNCTION_* */ | 82 | const struct menu_func *function; /* MT_FUNCTION_* */ |
83 | const struct menu_func_param *function_param; /* MT_FUNCTION_*_W_PARAM */ | ||
78 | const char **strings; /* used with MT_RETURN_ID */ | 84 | const char **strings; /* used with MT_RETURN_ID */ |
79 | int value; /* MT_RETURN_VALUE */ | 85 | int value; /* MT_RETURN_VALUE */ |
80 | }; | 86 | }; |
@@ -185,31 +191,55 @@ int do_menu(const struct menu_item_ex *menu, int *start_selected, | |||
185 | { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \ | 191 | { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \ |
186 | {.menu_get_name_and_icon = & name##_}}; | 192 | {.menu_get_name_and_icon = & name##_}}; |
187 | 193 | ||
188 | /* Use this to put a function call into the menu. | 194 | /* Use this to put a function call expecting no arguments into the menu. |
189 | When the user selects this item the function will be run, | 195 | When the user selects this item the function will be run, |
190 | if MENU_FUNC_CHECK_RETVAL is set, the return value | 196 | if MENU_FUNC_CHECK_RETVAL is set, the return value |
191 | will be checked, returning 1 will exit do_menu(); | 197 | will be checked, returning 1 will exit do_menu(); */ |
192 | if MENU_FUNC_USEPARAM is set, param will be passed to the function */ | 198 | #define MENUITEM_FUNCTION(name, flags, str, func, reserved, \ |
193 | #define MENUITEM_FUNCTION(name, flags, str, func, param, \ | ||
194 | callback, icon) \ | 199 | callback, icon) \ |
195 | static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \ | 200 | static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \ |
196 | static const struct menu_func name##__ = {{(void*)func}, param}; \ | 201 | static const struct menu_func name##__ = {(void*)func}; \ |
197 | /* should be const, but recording_settings wont let us do that */ \ | 202 | /* should be const, but recording_settings wont let us do that */ \ |
198 | const struct menu_item_ex name = \ | 203 | const struct menu_item_ex name = \ |
199 | { MT_FUNCTION_CALL|MENU_HAS_DESC|flags, \ | 204 | { MT_FUNCTION_CALL|MENU_HAS_DESC|flags, \ |
200 | { .function = & name##__}, {.callback_and_desc = & name##_}}; | 205 | { .function = & name##__}, {.callback_and_desc = & name##_}}; |
201 | 206 | ||
202 | /* As above, except the text is dynamic */ | 207 | /* As above, except the text is dynamic */ |
203 | #define MENUITEM_FUNCTION_DYNTEXT(name, flags, func, param, \ | 208 | #define MENUITEM_FUNCTION_DYNTEXT(name, flags, func, reserved, \ |
204 | text_callback, voice_callback, \ | 209 | text_callback, voice_callback, \ |
205 | text_cb_data, callback, icon) \ | 210 | text_cb_data, callback, icon) \ |
206 | static const struct menu_get_name_and_icon name##_ \ | 211 | static const struct menu_get_name_and_icon name##_ \ |
207 | = {callback,text_callback,voice_callback,text_cb_data,icon}; \ | 212 | = {callback,text_callback,voice_callback,text_cb_data,icon}; \ |
208 | static const struct menu_func name##__ = {{(void*)func}, param}; \ | 213 | static const struct menu_func name##__ = {(void*)func}; \ |
209 | const struct menu_item_ex name = \ | 214 | const struct menu_item_ex name = \ |
210 | { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \ | 215 | { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \ |
211 | { .function = & name##__}, {.menu_get_name_and_icon = & name##_}}; | 216 | { .function = & name##__}, {.menu_get_name_and_icon = & name##_}}; |
212 | 217 | ||
218 | /* Use this to put a function call into the menu. | ||
219 | When the user selects this item the function will be run, | ||
220 | if MENU_FUNC_CHECK_RETVAL is set, the return value | ||
221 | will be checked, returning 1 will exit do_menu(); | ||
222 | param will be passed to the function */ | ||
223 | #define MENUITEM_FUNCTION_W_PARAM(name, flags, str, func, param, \ | ||
224 | callback, icon) \ | ||
225 | static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \ | ||
226 | static const struct menu_func_param name##__ = {{(void*)func}, param}; \ | ||
227 | /* should be const, but recording_settings wont let us do that */ \ | ||
228 | const struct menu_item_ex name = \ | ||
229 | { MT_FUNCTION_CALL_W_PARAM|MENU_HAS_DESC|MENU_FUNC_USEPARAM|flags, \ | ||
230 | { .function_param = & name##__}, {.callback_and_desc = & name##_}}; | ||
231 | |||
232 | /* As above, except the text is dynamic */ | ||
233 | #define MENUITEM_FUNCTION_DYNTEXT_W_PARAM(name, flags, func, param, \ | ||
234 | text_callback, voice_callback, \ | ||
235 | text_cb_data, callback, icon) \ | ||
236 | static const struct menu_get_name_and_icon name##_ \ | ||
237 | = {callback,text_callback,voice_callback,text_cb_data,icon}; \ | ||
238 | static const struct menu_func_param name##__ = {{(void*)func}, param}; \ | ||
239 | const struct menu_item_ex name = \ | ||
240 | { MT_FUNCTION_CALL_W_PARAM|MENU_DYNAMIC_DESC|flags, \ | ||
241 | { .function_param = & name##__}, {.menu_get_name_and_icon = & name##_}}; | ||
242 | |||
213 | /* Use this to actually create a menu. the ... argument is a list of pointers | 243 | /* Use this to actually create a menu. the ... argument is a list of pointers |
214 | to any of the above macro'd variables. | 244 | to any of the above macro'd variables. |
215 | (It can also have other menus in the list.) */ | 245 | (It can also have other menus in the list.) */ |