Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 Robert E. Hak |
| 11 | * |
| 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. |
| 14 | * |
| 15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 16 | * KIND, either express or implied. |
| 17 | * |
| 18 | ****************************************************************************/ |
| 19 | |
| 20 | #ifndef __MENU_H__ |
| 21 | #define __MENU_H__ |
| 22 | |
Daniel Stenberg | 91f743f | 2002-06-14 10:39:11 +0000 | [diff] [blame] | 23 | #include <stdbool.h> |
| 24 | |
Linus Nielsen Feltzing | 77936e6 | 2004-03-16 13:44:56 +0000 | [diff] [blame] | 25 | struct menu_item { |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 26 | unsigned char *desc; /* string or ID */ |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 27 | bool (*function) (void); /* return true if USB was connected */ |
Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 28 | }; |
| 29 | |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame^] | 30 | int menu_init(const struct menu_item* mitems, int count, |
| 31 | int (*callback)(int, int), |
| 32 | const char *button1, const char *button2, const char *button3); |
Björn Stenberg | 2ac0572 | 2002-05-26 17:03:17 +0000 | [diff] [blame] | 33 | void menu_exit(int menu); |
Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 34 | |
Daniel Stenberg | 91f743f | 2002-06-14 10:39:11 +0000 | [diff] [blame] | 35 | void put_cursorxy(int x, int y, bool on); |
| 36 | |
Kjell Ericson | 5cd393c | 2003-01-29 08:26:11 +0000 | [diff] [blame] | 37 | /* Returns below define, or number of selected menu item*/ |
| 38 | int menu_show(int m); |
| 39 | #define MENU_ATTACHED_USB -1 |
| 40 | #define MENU_SELECTED_EXIT -2 |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame^] | 41 | #define MENU_EXIT_ALL -3 |
| 42 | #define MENU_RETURN_TO_WPS -4 |
Kjell Ericson | 5cd393c | 2003-01-29 08:26:11 +0000 | [diff] [blame] | 43 | |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 44 | bool menu_run(int menu); |
Linus Nielsen Feltzing | 10b92c4 | 2004-03-12 10:20:33 +0000 | [diff] [blame] | 45 | int menu_cursor(int menu); |
| 46 | char* menu_description(int menu, int position); |
| 47 | void menu_delete(int menu, int position); |
| 48 | int menu_count(int menu); |
| 49 | bool menu_moveup(int menu); |
| 50 | bool menu_movedown(int menu); |
| 51 | void menu_draw(int menu); |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 52 | void menu_insert(int menu, int position, char *desc, bool (*function) (void)); |
Jens Arnold | cef15c6 | 2005-04-10 17:36:55 +0000 | [diff] [blame] | 53 | void menu_set_cursor(int menu, int position); |
Kevin Ferrare | c43822d | 2005-11-03 11:56:21 +0000 | [diff] [blame] | 54 | void menu_talk_selected(int m); |
Daniel Stenberg | b285076 | 2002-08-23 12:32:52 +0000 | [diff] [blame] | 55 | |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame^] | 56 | |
| 57 | enum menu_item_type { |
| 58 | MT_MENU = 0, |
| 59 | MT_SETTING, |
| 60 | MT_FUNCTION_CALL, /* used when the standard code wont work */ |
| 61 | MT_FUNCTION_WITH_PARAM, |
| 62 | MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/ |
| 63 | }; |
| 64 | |
| 65 | typedef int (*menu_function)(void); |
| 66 | struct menu_func_with_param { |
| 67 | int (*function)(void* param); |
| 68 | void *param; |
| 69 | }; |
| 70 | |
| 71 | #define MENU_TYPE_MASK 0xF /* MT_* type */ |
| 72 | #define MENU_HAS_DESC 0x10 |
| 73 | #define MENU_COUNT_MASK (~(MENU_TYPE_MASK|MENU_HAS_DESC)) /* unless we need more flags*/ |
| 74 | #define MENU_COUNT_SHIFT 5 |
| 75 | |
| 76 | struct menu_item_ex { |
| 77 | 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 | int (*function)(void); /* used with MT_FUNCTION_CALL */ |
| 83 | const struct menu_func_with_param |
| 84 | *func_with_param; /* MT_FUNCTION_WITH_PARAM */ |
| 85 | const char **strings; /* used with MT_RETURN_ID */ |
| 86 | }; |
| 87 | union { |
| 88 | int (*menu_callback)(int action, const struct menu_item_ex *this_item); |
| 89 | const struct menu_callback_with_desc { |
| 90 | int (*menu_callback)(int action, |
| 91 | const struct menu_item_ex *this_item); |
| 92 | unsigned char *desc; /* string or ID */ |
| 93 | } *callback_and_desc; |
| 94 | }; |
| 95 | }; |
| 96 | |
| 97 | typedef int (*menu_callback_type)(int action, |
| 98 | const struct menu_item_ex *this_item); |
| 99 | int do_menu(const struct menu_item_ex *menu); |
| 100 | |
| 101 | #define MENU_ITEM_COUNT(c) (c<<MENU_COUNT_SHIFT) |
| 102 | |
| 103 | #define MENUITEM_SETTING(name,var,callback) \ |
| 104 | static const struct menu_item_ex name = \ |
| 105 | {MT_SETTING, {.variable = (void*)var},{callback}}; |
| 106 | |
| 107 | #define MAKE_MENU( name, str, cb, ... ) \ |
| 108 | static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \ |
| 109 | static const struct menu_callback_with_desc name##__ = {cb,str}; \ |
| 110 | const struct menu_item_ex name = \ |
| 111 | {MT_MENU|MENU_HAS_DESC| \ |
| 112 | MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ |
| 113 | { (void*)name##_},{.callback_and_desc = & name##__}}; |
| 114 | |
| 115 | #define MENUITEM_STRINGLIST(name, str, callback, ... ) \ |
| 116 | static const char *name##_[] = {__VA_ARGS__}; \ |
| 117 | static const struct menu_callback_with_desc name##__ = {cb,str}; \ |
| 118 | static const struct menu_item_ex name = \ |
| 119 | {MT_RETURN_ID|MENU_HAS_DESC| \ |
| 120 | MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ |
| 121 | { .submenus = name##_},{.callback_and_desc = & name##__}}; |
| 122 | /* This one should be static'ed also, |
| 123 | but cannot be done untill sound and playlist menus are done */ |
| 124 | #define MENUITEM_FUNCTION(name, str, func, cb) \ |
| 125 | static const struct menu_callback_with_desc name##_ = {cb,str}; \ |
| 126 | const struct menu_item_ex name = \ |
| 127 | { MT_FUNCTION_CALL|MENU_HAS_DESC, { .function = func}, \ |
| 128 | {.callback_and_desc = & name##_}}; |
| 129 | |
| 130 | #define MENUITEM_FUNCTION_WPARAM(name, str, func, param, callback) \ |
| 131 | static const struct menu_callback_with_desc name##_ = {callback,str}; \ |
| 132 | static const struct menu_func_with_param name##__ = {func, param}; \ |
| 133 | static const struct menu_item_ex name = \ |
| 134 | { MT_FUNCTION_WITH_PARAM|MENU_HAS_DESC, \ |
| 135 | { .func_with_param = &name##__}, \ |
| 136 | {.callback_and_desc = & name##_}}; |
| 137 | |
| 138 | |
Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 139 | #endif /* End __MENU_H__ */ |