clean up some debugging output.
[kugel-rb.git] / apps / menu.h
blob6dec5e0bd3b8f5e0cb6ef7199b6171deb58a9e2e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Robert E. Hak
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef __MENU_H__
23 #define __MENU_H__
25 #include <stdbool.h>
26 #include "icon.h"
27 #include "icons.h"
28 #include "root_menu.h" /* needed for MENU_* return codes */
31 enum menu_item_type {
32 MT_MENU = 0,
33 MT_SETTING,
34 MT_SETTING_W_TEXT, /* same as setting, but uses different
35 text for the setting title,
36 ID2P() or "literal" for the str param */
37 MT_FUNCTION_CALL, /* call a function from the menus */
38 MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/
39 MT_RETURN_VALUE, /* returns a value associated with an item */
41 #define MENU_TYPE_MASK 0xF /* MT_* type */
43 typedef int (*menu_function)(void);
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);
50 void *param; /* passed to function_w_param */
53 /* these next two are mutually exclusive */
54 #define MENU_HAS_DESC 0x10
55 #define MENU_DYNAMIC_DESC 0x20 /* the name of this menu item is set by the \
56 list_get_name callback */
58 #define MENU_EXITAFTERTHISMENU 0x40 /* do_menu() will exiting out of any \
59 menu item with this flag set */
61 /* Flags for MT_FUNCTION_CALL */
62 #define MENU_FUNC_USEPARAM 0x80
63 #define MENU_FUNC_CHECK_RETVAL 0x100
65 #define MENU_COUNT_MASK 0xFFF
66 #define MENU_COUNT_SHIFT 12
67 #define MENU_ITEM_COUNT(c) ((c&MENU_COUNT_MASK)<<MENU_COUNT_SHIFT)
68 #define MENU_GET_COUNT(flags) ((flags>>MENU_COUNT_SHIFT)&MENU_COUNT_MASK)
70 struct menu_item_ex {
71 unsigned int flags; /* above defines */
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 */
76 const struct menu_func *function; /* MT_FUNCTION_* */
77 const char **strings; /* used with MT_RETURN_ID */
78 int value; /* MT_RETURN_VALUE */
80 union {
81 /* For settings */
82 int (*menu_callback)(int action, const struct menu_item_ex *this_item);
83 /* For everything else, except if the text is dynamic */
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 */
88 int icon_id; /* from icons_6x8 in icons.h */
89 } *callback_and_desc;
90 /* For when the item text is dynamic */
91 const struct menu_get_name_and_icon {
92 int (*menu_callback)(int action,
93 const struct menu_item_ex *this_item);
94 char *(*list_get_name)(int selected_item, void * data, char *buffer);
95 int (*list_speak_item)(int selected_item, void * data);
96 void *list_get_name_data;
97 int icon_id;
98 } *menu_get_name_and_icon;
102 typedef int (*menu_callback_type)(int action,
103 const struct menu_item_ex *this_item);
104 bool do_setting_from_menu(const struct menu_item_ex *temp,
105 struct viewport parent[NB_SCREENS]);
108 int do_menu(const struct menu_item_ex *menu, int *start_selected)
110 Return value - usually one of the GO_TO_* values from root_menu.h,
111 however, some of the following defines can cause this to
112 return a different value.
114 *menu - The menu to run, can be a pointer to a MAKE_MENU() variable,
115 MENUITEM_STRINGLIST() or MENUITEM_RETURNVALUE() variable.
117 *start_selected - the item to select when the menu is first run.
118 When do_menu() returns, this will be set to the
119 index of the selected item at the time of the exit.
120 This is always set, even if the menu was cancelled.
121 If NULL it is ignored and the firs item starts selected
123 int do_menu(const struct menu_item_ex *menu, int *start_selected,
124 struct viewport parent[NB_SCREENS], bool hide_bars);
126 /* In all the following macros the argument names are as follows:
127 - name: The name for the variable (so it can be used in a MAKE_MENU()
128 - str: the string to display for this menu item. use ID2P() for LANG_* id's
129 - callback: The callback function to call for this menu item.
132 /* Use this to put a setting into a menu.
133 The setting must appear in settings_list.c.
134 If the setting is not configured properly, the menu will display "Not Done yet!"
135 When the user selects this item the setting select screen will load,
136 when that screen exits the user wll be back in the menu */
137 #define MENUITEM_SETTING(name,var,callback) \
138 static const struct menu_item_ex name = \
139 {MT_SETTING, {.variable = (void*)var},{callback}};
141 /* Use this for settings which have a differnt title in their
142 setting screen than in the menu (e.g scroll options */
143 #define MENUITEM_SETTING_W_TEXT(name, var, str, callback ) \
144 static const struct menu_callback_with_desc name##__ = \
145 {callback,str, Icon_NOICON}; \
146 static const struct menu_item_ex name = \
147 {MT_SETTING_W_TEXT|MENU_HAS_DESC, {.variable = (void*)var }, \
148 {.callback_and_desc = & name##__}};
150 /* Use this To create a list of Strings (or ID2P()'s )
151 When the user enters this list and selects one, the menu will exit
152 and do_menu() will return value the index of the chosen item.
153 if the user cancels, GO_TO_PREVIOUS will be returned */
154 #define MENUITEM_STRINGLIST(name, str, callback, ... ) \
155 static const char *name##_[] = {__VA_ARGS__}; \
156 static const struct menu_callback_with_desc name##__ = \
157 {callback,str, Icon_NOICON}; \
158 static const struct menu_item_ex name = \
159 {MT_RETURN_ID|MENU_HAS_DESC| \
160 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
161 { .strings = name##_},{.callback_and_desc = & name##__}};
164 /* causes do_menu() to return a value associated with the item */
165 #define MENUITEM_RETURNVALUE(name, str, val, cb, icon) \
166 static const struct menu_callback_with_desc name##_ = {cb,str,icon}; \
167 static const struct menu_item_ex name = \
168 { MT_RETURN_VALUE|MENU_HAS_DESC, { .value = val}, \
169 {.callback_and_desc = & name##_}};
171 /* same as above, except the item name is dynamic */
172 #define MENUITEM_RETURNVALUE_DYNTEXT(name, val, cb, text_callback, \
173 voice_callback, text_cb_data, icon) \
174 static const struct menu_get_name_and_icon name##_ \
175 = {cb,text_callback,voice_callback,text_cb_data,icon}; \
176 static const struct menu_item_ex name = \
177 { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \
178 {.menu_get_name_and_icon = & name##_}};
180 /* Use this to put a function call into the menu.
181 When the user selects this item the function will be run,
182 if MENU_FUNC_CHECK_RETVAL is set, the return value
183 will be checked, returning 1 will exit do_menu();
184 if MENU_FUNC_USEPARAM is set, param will be passed to the function */
185 #define MENUITEM_FUNCTION(name, flags, str, func, param, \
186 callback, icon) \
187 static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \
188 static const struct menu_func name##__ = {{(void*)func}, param}; \
189 /* should be const, but recording_settings wont let us do that */ \
190 const struct menu_item_ex name = \
191 { MT_FUNCTION_CALL|MENU_HAS_DESC|flags, \
192 { .function = & name##__}, {.callback_and_desc = & name##_}};
194 /* As above, except the text is dynamic */
195 #define MENUITEM_FUNCTION_DYNTEXT(name, flags, func, param, \
196 text_callback, voice_callback, \
197 text_cb_data, callback, icon) \
198 static const struct menu_get_name_and_icon name##_ \
199 = {callback,text_callback,voice_callback,text_cb_data,icon}; \
200 static const struct menu_func name##__ = {{(void*)func}, param}; \
201 static const struct menu_item_ex name = \
202 { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \
203 { .function = & name##__}, {.menu_get_name_and_icon = & name##_}};
205 /* Use this to actually create a menu. the ... argument is a list of pointers
206 to any of the above macro'd variables.
207 (It can also have other menus in the list.) */
208 #define MAKE_MENU( name, str, callback, icon, ... ) \
209 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
210 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
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##__}};
217 #endif /* End __MENU_H__ */