Bump version numbers for 3.13
[maemo-rb.git] / apps / menu.h
blobee2d9e7f40ce5fa88924bc9257412af194b37b33
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 */
29 #include "settings_list.h"
32 enum menu_item_type {
33 MT_MENU = 0,
34 MT_SETTING,
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 */
38 MT_FUNCTION_CALL, /* call a function from the menus */
39 MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/
40 MT_RETURN_VALUE, /* returns a value associated with an item */
42 #define MENU_TYPE_MASK 0xF /* MT_* type */
44 typedef int (*menu_function)(void);
45 struct menu_func {
46 union {
47 int (*function_w_param)(void* param); /* intptr_t instead of void*
48 for 64bit systems */
49 int (*function)(void);
51 void *param; /* passed to function_w_param */
54 /* these next two are mutually exclusive */
55 #define MENU_HAS_DESC 0x10
56 #define MENU_DYNAMIC_DESC 0x20 /* the name of this menu item is set by the \
57 list_get_name callback */
59 #define MENU_EXITAFTERTHISMENU 0x40 /* do_menu() will exiting out of any \
60 menu item with this flag set */
62 /* Flags for MT_FUNCTION_CALL */
63 #define MENU_FUNC_USEPARAM 0x80
64 #define MENU_FUNC_CHECK_RETVAL 0x100
66 #define MENU_COUNT_MASK 0xFFF
67 #define MENU_COUNT_SHIFT 12
68 #define MENU_ITEM_COUNT(c) ((c&MENU_COUNT_MASK)<<MENU_COUNT_SHIFT)
69 #define MENU_GET_COUNT(flags) ((flags>>MENU_COUNT_SHIFT)&MENU_COUNT_MASK)
71 struct menu_item_ex {
72 unsigned int flags; /* above defines */
73 union {
74 const struct menu_item_ex **submenus; /* used with MT_MENU */
75 void *variable; /* used with MT_SETTING,
76 must be in the settings_list.c list */
77 const struct menu_func *function; /* MT_FUNCTION_* */
78 const char **strings; /* used with MT_RETURN_ID */
79 int value; /* MT_RETURN_VALUE */
81 union {
82 /* For settings */
83 int (*menu_callback)(int action, const struct menu_item_ex *this_item);
84 /* For everything else, except if the text is dynamic */
85 const struct menu_callback_with_desc {
86 int (*menu_callback)(int action,
87 const struct menu_item_ex *this_item);
88 unsigned char *desc; /* string or ID */
89 int icon_id; /* from icons_6x8 in icons.h */
90 } *callback_and_desc;
91 /* For when the item text is dynamic */
92 const struct menu_get_name_and_icon {
93 int (*menu_callback)(int action,
94 const struct menu_item_ex *this_item);
95 char *(*list_get_name)(int selected_item, void * data, char *buffer);
96 int (*list_speak_item)(int selected_item, void * data);
97 void *list_get_name_data;
98 int icon_id;
99 } *menu_get_name_and_icon;
103 typedef int (*menu_callback_type)(int action,
104 const struct menu_item_ex *this_item);
105 void do_setting_from_menu(const struct menu_item_ex *temp,
106 struct viewport parent[NB_SCREENS]);
107 void do_setting_screen(const struct settings_list *setting, const char * title,
108 struct viewport parent[NB_SCREENS]);
111 int do_menu(const struct menu_item_ex *menu, int *start_selected)
113 Return value - usually one of the GO_TO_* values from root_menu.h,
114 however, some of the following defines can cause this to
115 return a different value.
117 *menu - The menu to run, can be a pointer to a MAKE_MENU() variable,
118 MENUITEM_STRINGLIST() or MENUITEM_RETURNVALUE() variable.
120 *start_selected - the item to select when the menu is first run.
121 When do_menu() returns, this will be set to the
122 index of the selected item at the time of the exit.
123 This is always set, even if the menu was cancelled.
124 If NULL it is ignored and the firs item starts selected
126 int do_menu(const struct menu_item_ex *menu, int *start_selected,
127 struct viewport parent[NB_SCREENS], bool hide_theme);
129 /* In all the following macros the argument names are as follows:
130 - name: The name for the variable (so it can be used in a MAKE_MENU()
131 - str: the string to display for this menu item. use ID2P() for LANG_* id's
132 - callback: The callback function to call for this menu item.
135 /* Use this to put a setting into a menu.
136 The setting must appear in settings_list.c.
137 If the setting is not configured properly, the menu will display "Not Done yet!"
138 When the user selects this item the setting select screen will load,
139 when that screen exits the user wll be back in the menu */
140 #define MENUITEM_SETTING(name,var,callback) \
141 static const struct menu_item_ex name = \
142 {MT_SETTING, {.variable = (void*)var},{callback}};
144 /* Use this for settings which have a differnt title in their
145 setting screen than in the menu (e.g scroll options */
146 #define MENUITEM_SETTING_W_TEXT(name, var, str, callback ) \
147 static const struct menu_callback_with_desc name##__ = \
148 {callback,str, Icon_NOICON}; \
149 static const struct menu_item_ex name = \
150 {MT_SETTING_W_TEXT|MENU_HAS_DESC, {.variable = (void*)var }, \
151 {.callback_and_desc = & name##__}};
153 /* Use this To create a list of Strings (or ID2P()'s )
154 When the user enters this list and selects one, the menu will exit
155 and do_menu() will return value the index of the chosen item.
156 if the user cancels, GO_TO_PREVIOUS will be returned */
157 #define MENUITEM_STRINGLIST(name, str, callback, ... ) \
158 static const char *name##_[] = {__VA_ARGS__}; \
159 static const struct menu_callback_with_desc name##__ = \
160 {callback,str, Icon_NOICON}; \
161 static const struct menu_item_ex name = \
162 {MT_RETURN_ID|MENU_HAS_DESC| \
163 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
164 { .strings = name##_},{.callback_and_desc = & name##__}};
167 /* causes do_menu() to return a value associated with the item */
168 #define MENUITEM_RETURNVALUE(name, str, val, cb, icon) \
169 static const struct menu_callback_with_desc name##_ = {cb,str,icon}; \
170 static const struct menu_item_ex name = \
171 { MT_RETURN_VALUE|MENU_HAS_DESC, { .value = val}, \
172 {.callback_and_desc = & name##_}};
174 /* same as above, except the item name is dynamic */
175 #define MENUITEM_RETURNVALUE_DYNTEXT(name, val, cb, text_callback, \
176 voice_callback, text_cb_data, icon) \
177 static const struct menu_get_name_and_icon name##_ \
178 = {cb,text_callback,voice_callback,text_cb_data,icon}; \
179 static const struct menu_item_ex name = \
180 { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \
181 {.menu_get_name_and_icon = & name##_}};
183 /* Use this to put a function call into the menu.
184 When the user selects this item the function will be run,
185 if MENU_FUNC_CHECK_RETVAL is set, the return value
186 will be checked, returning 1 will exit do_menu();
187 if MENU_FUNC_USEPARAM is set, param will be passed to the function */
188 #define MENUITEM_FUNCTION(name, flags, str, func, param, \
189 callback, icon) \
190 static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \
191 static const struct menu_func name##__ = {{(void*)func}, param}; \
192 /* should be const, but recording_settings wont let us do that */ \
193 const struct menu_item_ex name = \
194 { MT_FUNCTION_CALL|MENU_HAS_DESC|flags, \
195 { .function = & name##__}, {.callback_and_desc = & name##_}};
197 /* As above, except the text is dynamic */
198 #define MENUITEM_FUNCTION_DYNTEXT(name, flags, func, param, \
199 text_callback, voice_callback, \
200 text_cb_data, callback, icon) \
201 static const struct menu_get_name_and_icon name##_ \
202 = {callback,text_callback,voice_callback,text_cb_data,icon}; \
203 static const struct menu_func name##__ = {{(void*)func}, param}; \
204 const struct menu_item_ex name = \
205 { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \
206 { .function = & name##__}, {.menu_get_name_and_icon = & name##_}};
208 /* Use this to actually create a menu. the ... argument is a list of pointers
209 to any of the above macro'd variables.
210 (It can also have other menus in the list.) */
211 #define MAKE_MENU( name, str, callback, icon, ... ) \
212 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
213 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
214 const struct menu_item_ex name = \
215 {MT_MENU|MENU_HAS_DESC| \
216 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
217 { (void*)name##_},{.callback_and_desc = & name##__}};
220 #endif /* End __MENU_H__ */