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