A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 254 lines 13 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2002 Robert E. Hak 11 * 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. 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 25#include <stdbool.h> 26#include "icon.h" 27#include "icons.h" 28#include "root_menu.h" /* needed for MENU_* return codes */ 29#include "settings_list.h" 30#include "gui/list.h" 31 32 33enum menu_item_type { 34 MT_MENU = 0, 35 MT_SETTING, 36 MT_SETTING_W_TEXT, /* same as setting, but uses different 37 text for the setting title, 38 ID2P() or "literal" for the str param */ 39 MT_FUNCTION_CALL, /* call a function from the menus */ 40 MT_FUNCTION_CALL_W_PARAM, /* call a function from the menus */ 41 MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/ 42 MT_RETURN_VALUE, /* returns a value associated with an item */ 43}; 44#define MENU_TYPE_MASK 0xF /* MT_* type */ 45 46struct menu_func_param { 47 union { 48 int (*function_w_param)(void* param); /* intptr_t instead of void* 49 for 64bit systems */ 50 int (*function)(void); 51 }; 52 void *param; /* passed to function_w_param */ 53}; 54 55struct menu_func { 56 int (*function)(void); 57}; 58 59/* these next two are mutually exclusive */ 60#define MENU_HAS_DESC 0x10 61#define MENU_DYNAMIC_DESC 0x20 /* the name of this menu item is set by the \ 62 list_get_name callback */ 63 64#define MENU_EXITAFTERTHISMENU 0x40 /* do_menu() will exiting out of any \ 65 menu item with this flag set */ 66 67/* Flags for MT_FUNCTION_CALL */ 68#define MENU_FUNC_USEPARAM 0x80 69#define MENU_FUNC_CHECK_RETVAL 0x100 70 71#define MENU_COUNT_MASK 0xFFF 72#define MENU_COUNT_SHIFT 12 73#define MENU_ITEM_COUNT(c) ((c&MENU_COUNT_MASK)<<MENU_COUNT_SHIFT) 74#define MENU_GET_COUNT(flags) ((flags>>MENU_COUNT_SHIFT)&MENU_COUNT_MASK) 75 76struct menu_item_ex { 77 unsigned int flags; /* above defines */ 78 union { 79 const struct menu_item_ex **submenus; /* used with MT_MENU */ 80 void *variable; /* used with MT_SETTING, 81 must be in the settings_list.c list */ 82 const struct menu_func *function; /* MT_FUNCTION_* */ 83 const struct menu_func_param *function_param; /* MT_FUNCTION_*_W_PARAM */ 84 const char **strings; /* used with MT_RETURN_ID */ 85 int value; /* MT_RETURN_VALUE */ 86 }; 87 union { 88 /* For settings */ 89 int (*menu_callback)(int action, const struct menu_item_ex *this_item, 90 struct gui_synclist *this_list); 91 /* For everything else, except if the text is dynamic */ 92 const struct menu_callback_with_desc { 93 int (*menu_callback)(int action, 94 const struct menu_item_ex *this_item, 95 struct gui_synclist *this_list); 96 unsigned char *desc; /* string or ID */ 97 int icon_id; /* from icons_6x8 in icons.h */ 98 } *callback_and_desc; 99 /* For when the item text is dynamic */ 100 const struct menu_get_name_and_icon { 101 int (*menu_callback)(int action, 102 const struct menu_item_ex *this_item, 103 struct gui_synclist *this_list); 104 char *(*list_get_name)(int selected_item, void * data, 105 char *buffer, size_t buffer_len); 106 int (*list_speak_item)(int selected_item, void * data); 107 void *list_get_name_data; 108 int icon_id; 109 } *menu_get_name_and_icon; 110 }; 111}; 112 113typedef int (*menu_callback_type)(int action, 114 const struct menu_item_ex *this_item, 115 struct gui_synclist *this_list); 116void do_setting_from_menu(const struct menu_item_ex *temp, 117 struct viewport parent[NB_SCREENS]); 118void do_setting_screen(const struct settings_list *setting, const char * title, 119 struct viewport parent[NB_SCREENS]); 120 121/* 122 int do_menu(const struct menu_item_ex *menu, int *start_selected) 123 124 Return value - usually one of the GO_TO_* values from root_menu.h, 125 however, some of the following defines can cause this to 126 return a different value. 127 128 *menu - The menu to run, can be a pointer to a MAKE_MENU() variable, 129 MENUITEM_STRINGLIST() or MENUITEM_RETURNVALUE() variable. 130 131 *start_selected - the item to select when the menu is first run. 132 When do_menu() returns, this will be set to the 133 index of the selected item at the time of the exit. 134 This is always set, even if the menu was cancelled. 135 If NULL it is ignored and the firs item starts selected 136*/ 137int do_menu(const struct menu_item_ex *menu, int *start_selected, 138 struct viewport parent[NB_SCREENS], bool hide_theme); 139 140/* In all the following macros the argument names are as follows: 141 - name: The name for the variable (so it can be used in a MAKE_MENU() 142 - str: the string to display for this menu item. use ID2P() for LANG_* id's 143 - callback: The callback function to call for this menu item. 144*/ 145 146/* Use this to put a setting into a menu. 147 The setting must appear in settings_list.c. 148 If the setting is not configured properly, the menu will display "Not Done yet!" 149 When the user selects this item the setting select screen will load, 150 when that screen exits the user wll be back in the menu */ 151#define MENUITEM_SETTING(name,var,callback) \ 152 static const struct menu_item_ex name = \ 153 {MT_SETTING, {.variable = (void*)var},{callback}}; 154 155/* Use this for settings which have a differnt title in their 156 setting screen than in the menu (e.g scroll options */ 157#define MENUITEM_SETTING_W_TEXT(name, var, str, callback ) \ 158 static const struct menu_callback_with_desc name##__ = \ 159 {callback,str, Icon_NOICON}; \ 160 static const struct menu_item_ex name = \ 161 {MT_SETTING_W_TEXT|MENU_HAS_DESC, {.variable = (void*)var }, \ 162 {.callback_and_desc = & name##__}}; 163 164/* Use this To create a list of Strings (or ID2P()'s ) 165 When the user enters this list and selects one, the menu will exit 166 and do_menu() will return value the index of the chosen item. 167 if the user cancels, GO_TO_PREVIOUS will be returned */ 168#define MENUITEM_STRINGLIST(name, str, callback, ... ) \ 169 static const char *name##_[] = {__VA_ARGS__}; \ 170 static const struct menu_callback_with_desc name##__ = \ 171 {callback,str, Icon_NOICON}; \ 172 static const struct menu_item_ex name = \ 173 {MT_RETURN_ID|MENU_HAS_DESC| \ 174 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ 175 { .strings = name##_},{.callback_and_desc = & name##__}}; 176 177 178/* causes do_menu() to return a value associated with the item */ 179#define MENUITEM_RETURNVALUE(name, str, val, cb, icon) \ 180 static const struct menu_callback_with_desc name##_ = {cb,str,icon}; \ 181 static const struct menu_item_ex name = \ 182 { MT_RETURN_VALUE|MENU_HAS_DESC, { .value = val}, \ 183 {.callback_and_desc = & name##_}}; 184 185/* same as above, except the item name is dynamic */ 186#define MENUITEM_RETURNVALUE_DYNTEXT(name, val, cb, text_callback, \ 187 voice_callback, text_cb_data, icon) \ 188 static const struct menu_get_name_and_icon name##_ \ 189 = {cb,text_callback,voice_callback,text_cb_data,icon}; \ 190 static const struct menu_item_ex name = \ 191 { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \ 192 {.menu_get_name_and_icon = & name##_}}; 193 194/* Use this to put a function call expecting no arguments into the menu. 195 When the user selects this item the function will be run, 196 if MENU_FUNC_CHECK_RETVAL is set, the return value 197 will be checked, returning 1 will exit do_menu(); */ 198#define MENUITEM_FUNCTION(name, flags, str, func, callback, icon) \ 199 static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \ 200 static const struct menu_func name##__ = {(void*)func}; \ 201 /* should be const, but recording_settings wont let us do that */ \ 202 const struct menu_item_ex name = \ 203 { MT_FUNCTION_CALL|MENU_HAS_DESC|flags, \ 204 { .function = & name##__}, {.callback_and_desc = & name##_}}; 205 206/* As above, except the text is dynamic */ 207#define MENUITEM_FUNCTION_DYNTEXT(name, flags, func, \ 208 text_callback, voice_callback, \ 209 text_cb_data, callback, icon) \ 210 static const struct menu_get_name_and_icon name##_ \ 211 = {callback,text_callback,voice_callback,text_cb_data,icon}; \ 212 static const struct menu_func name##__ = {(void*)func}; \ 213 const struct menu_item_ex name = \ 214 { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \ 215 { .function = & name##__}, {.menu_get_name_and_icon = & name##_}}; 216 217/* Use this to put a function call into the menu. 218 When the user selects this item the function will be run, 219 if MENU_FUNC_CHECK_RETVAL is set, the return value 220 will be checked, returning 1 will exit do_menu(); 221 param will be passed to the function */ 222#define MENUITEM_FUNCTION_W_PARAM(name, flags, str, func, param, \ 223 callback, icon) \ 224 static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \ 225 static const struct menu_func_param name##__ = {{(void*)func}, param}; \ 226 /* should be const, but recording_settings wont let us do that */ \ 227 const struct menu_item_ex name = \ 228 { MT_FUNCTION_CALL_W_PARAM|MENU_HAS_DESC|MENU_FUNC_USEPARAM|flags, \ 229 { .function_param = & name##__}, {.callback_and_desc = & name##_}}; 230 231/* As above, except the text is dynamic */ 232#define MENUITEM_FUNCTION_DYNTEXT_W_PARAM(name, flags, func, param, \ 233 text_callback, voice_callback, \ 234 text_cb_data, callback, icon) \ 235 static const struct menu_get_name_and_icon name##_ \ 236 = {callback,text_callback,voice_callback,text_cb_data,icon}; \ 237 static const struct menu_func_param name##__ = {{(void*)func}, param}; \ 238 const struct menu_item_ex name = \ 239 { MT_FUNCTION_CALL_W_PARAM|MENU_DYNAMIC_DESC|flags, \ 240 { .function_param = & name##__}, {.menu_get_name_and_icon = & name##_}}; 241 242/* Use this to actually create a menu. the ... argument is a list of pointers 243 to any of the above macro'd variables. 244 (It can also have other menus in the list.) */ 245#define MAKE_MENU( name, str, callback, icon, ... ) \ 246 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \ 247 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\ 248 const struct menu_item_ex name = \ 249 {MT_MENU|MENU_HAS_DESC| \ 250 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ 251 { (void*)name##_},{.callback_and_desc = & name##__}}; 252 253 254#endif /* End __MENU_H__ */