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 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
Kevin Ferrare | db8415c | 2005-10-30 22:34:51 +0000 | [diff] [blame] | 21 | /* |
| 22 | 2005 Kevin Ferrare : |
| 23 | - Multi screen support |
| 24 | - Rewrote/removed a lot of code now useless with the new gui API |
| 25 | */ |
Björn Stenberg | 2ac0572 | 2002-05-26 17:03:17 +0000 | [diff] [blame] | 26 | #include <stdbool.h> |
Linus Nielsen Feltzing | 10b92c4 | 2004-03-12 10:20:33 +0000 | [diff] [blame] | 27 | #include <stdlib.h> |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 28 | #include "config.h" |
Linus Nielsen Feltzing | 34d08b2 | 2007-11-16 08:18:08 +0000 | [diff] [blame] | 29 | #include "system.h" |
Justin Heiner | b5025a8 | 2002-08-31 04:58:35 +0000 | [diff] [blame] | 30 | |
Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 31 | #include "lcd.h" |
Daniel Stenberg | 93b231c | 2002-09-12 13:33:59 +0000 | [diff] [blame] | 32 | #include "font.h" |
Justin Heiner | b5025a8 | 2002-08-31 04:58:35 +0000 | [diff] [blame] | 33 | #include "backlight.h" |
Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame] | 34 | #include "menu.h" |
Björn Stenberg | b21a3bd | 2002-05-21 14:25:45 +0000 | [diff] [blame] | 35 | #include "button.h" |
| 36 | #include "kernel.h" |
| 37 | #include "debug.h" |
Justin Heiner | 2630245 | 2002-08-23 02:17:00 +0000 | [diff] [blame] | 38 | #include "usb.h" |
Björn Stenberg | cd22573 | 2002-08-11 09:17:47 +0000 | [diff] [blame] | 39 | #include "panic.h" |
Markus Braun | 5e4c1d2 | 2002-08-20 19:37:00 +0000 | [diff] [blame] | 40 | #include "settings.h" |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 41 | #include "settings_list.h" |
Jonathan Gordon | a5278fa | 2007-07-11 05:41:23 +0000 | [diff] [blame] | 42 | #include "option_select.h" |
Markus Braun | 5e4c1d2 | 2002-08-20 19:37:00 +0000 | [diff] [blame] | 43 | #include "status.h" |
Björn Stenberg | a4c3b03 | 2002-09-24 18:04:15 +0000 | [diff] [blame] | 44 | #include "screens.h" |
Jörg Hohensohn | 4f36ea8 | 2004-03-14 21:33:53 +0000 | [diff] [blame] | 45 | #include "talk.h" |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 46 | #include "lang.h" |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 47 | #include "misc.h" |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 48 | #include "action.h" |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 49 | #include "menus/exported_menus.h" |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 50 | #include "string.h" |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 51 | #include "root_menu.h" |
| 52 | #include "bookmark.h" |
| 53 | #include "gwps-common.h" /* for fade() */ |
| 54 | #include "audio.h" |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 55 | #include "viewport.h" |
Jonathan Gordon | ea664e0 | 2008-05-03 12:30:40 +0000 | [diff] [blame] | 56 | #include "quickscreen.h" |
Markus Braun | 000c2db | 2002-08-30 13:49:32 +0000 | [diff] [blame] | 57 | |
Daniel Stenberg | bf603f9 | 2002-06-14 08:47:44 +0000 | [diff] [blame] | 58 | #ifdef HAVE_LCD_BITMAP |
| 59 | #include "icons.h" |
| 60 | #endif |
Markus Braun | 000c2db | 2002-08-30 13:49:32 +0000 | [diff] [blame] | 61 | |
Kevin Ferrare | db8415c | 2005-10-30 22:34:51 +0000 | [diff] [blame] | 62 | /* gui api */ |
| 63 | #include "list.h" |
| 64 | #include "statusbar.h" |
| 65 | #include "buttonbar.h" |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 66 | |
Jonathan Gordon | 77a458a | 2007-05-08 11:55:43 +0000 | [diff] [blame] | 67 | #define MAX_MENUS 8 |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 68 | /* used to allow for dynamic menus */ |
| 69 | #define MAX_MENU_SUBITEMS 64 |
Jonathan Gordon | 208136d | 2007-03-17 14:10:51 +0000 | [diff] [blame] | 70 | static struct menu_item_ex *current_submenus_menu; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 71 | static int current_subitems[MAX_MENU_SUBITEMS]; |
| 72 | static int current_subitems_count = 0; |
Stéphane Doyon | 4e09b78 | 2007-10-21 00:23:23 +0000 | [diff] [blame] | 73 | static int talk_menu_item(int selected_item, void *data); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 74 | |
Nils Wallménius | f31e123 | 2007-05-19 19:54:11 +0000 | [diff] [blame] | 75 | static void get_menu_callback(const struct menu_item_ex *m, |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 76 | menu_callback_type *menu_callback) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 77 | { |
Jonathan Gordon | 2801a87 | 2007-02-19 02:14:51 +0000 | [diff] [blame] | 78 | if (m->flags&(MENU_HAS_DESC|MENU_DYNAMIC_DESC)) |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 79 | *menu_callback= m->callback_and_desc->menu_callback; |
| 80 | else |
| 81 | *menu_callback = m->menu_callback; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static int get_menu_selection(int selected_item, const struct menu_item_ex *menu) |
| 85 | { |
| 86 | int type = (menu->flags&MENU_TYPE_MASK); |
| 87 | if (type == MT_MENU && (selected_item<current_subitems_count)) |
| 88 | return current_subitems[selected_item]; |
| 89 | return selected_item; |
| 90 | } |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 91 | static int find_menu_selection(int selected) |
| 92 | { |
| 93 | int i; |
| 94 | for (i=0; i< current_subitems_count; i++) |
| 95 | if (current_subitems[i] == selected) |
| 96 | return i; |
| 97 | return 0; |
| 98 | } |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 99 | static char * get_menu_item_name(int selected_item, |
| 100 | void * data, |
| 101 | char *buffer, |
| 102 | size_t buffer_len) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 103 | { |
| 104 | const struct menu_item_ex *menu = (const struct menu_item_ex *)data; |
| 105 | int type = (menu->flags&MENU_TYPE_MASK); |
| 106 | selected_item = get_menu_selection(selected_item, menu); |
| 107 | |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 108 | (void)buffer_len; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 109 | /* only MT_MENU or MT_RETURN_ID is allowed in here */ |
| 110 | if (type == MT_RETURN_ID) |
| 111 | { |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 112 | if (menu->flags&MENU_DYNAMIC_DESC) |
| 113 | return menu->menu_get_name_and_icon->list_get_name(selected_item, |
| 114 | menu->menu_get_name_and_icon->list_get_name_data, buffer); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 115 | return (char*)menu->strings[selected_item]; |
| 116 | } |
| 117 | |
| 118 | menu = menu->submenus[selected_item]; |
Jonathan Gordon | 1ba493e | 2007-02-26 08:17:07 +0000 | [diff] [blame] | 119 | |
Jonathan Gordon | 9709086 | 2007-03-03 14:23:03 +0000 | [diff] [blame] | 120 | if ((menu->flags&MENU_DYNAMIC_DESC) && (type != MT_SETTING_W_TEXT)) |
Jonathan Gordon | 1ba493e | 2007-02-26 08:17:07 +0000 | [diff] [blame] | 121 | return menu->menu_get_name_and_icon->list_get_name(selected_item, |
| 122 | menu->menu_get_name_and_icon->list_get_name_data, buffer); |
| 123 | |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 124 | type = (menu->flags&MENU_TYPE_MASK); |
Jonathan Gordon | 9709086 | 2007-03-03 14:23:03 +0000 | [diff] [blame] | 125 | if ((type == MT_SETTING) || (type == MT_SETTING_W_TEXT)) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 126 | { |
| 127 | const struct settings_list *v |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 128 | = find_setting(menu->variable, NULL); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 129 | if (v) |
| 130 | return str(v->lang_id); |
| 131 | else return "Not Done yet!"; |
| 132 | } |
| 133 | return P2STR(menu->callback_and_desc->desc); |
| 134 | } |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 135 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 136 | static int menu_get_icon(int selected_item, void * data) |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 137 | { |
| 138 | const struct menu_item_ex *menu = (const struct menu_item_ex *)data; |
Jonathan Gordon | 9709086 | 2007-03-03 14:23:03 +0000 | [diff] [blame] | 139 | int menu_icon = Icon_NOICON; |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 140 | selected_item = get_menu_selection(selected_item, menu); |
| 141 | |
Jonathan Gordon | 1f5ee2a | 2007-03-25 14:31:56 +0000 | [diff] [blame] | 142 | if ((menu->flags&MENU_TYPE_MASK) == MT_RETURN_ID) |
| 143 | { |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 144 | return Icon_Menu_functioncall; |
Jonathan Gordon | 1f5ee2a | 2007-03-25 14:31:56 +0000 | [diff] [blame] | 145 | } |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 146 | menu = menu->submenus[selected_item]; |
Jonathan Gordon | 1ba493e | 2007-02-26 08:17:07 +0000 | [diff] [blame] | 147 | if (menu->flags&MENU_HAS_DESC) |
Jonathan Gordon | 02a8717 | 2007-03-03 13:52:14 +0000 | [diff] [blame] | 148 | menu_icon = menu->callback_and_desc->icon_id; |
Jonathan Gordon | 1ba493e | 2007-02-26 08:17:07 +0000 | [diff] [blame] | 149 | else if (menu->flags&MENU_DYNAMIC_DESC) |
Jonathan Gordon | 02a8717 | 2007-03-03 13:52:14 +0000 | [diff] [blame] | 150 | menu_icon = menu->menu_get_name_and_icon->icon_id; |
Jonathan Gordon | 1ba493e | 2007-02-26 08:17:07 +0000 | [diff] [blame] | 151 | |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 152 | if (menu_icon == Icon_NOICON) |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 153 | { |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 154 | switch (menu->flags&MENU_TYPE_MASK) |
| 155 | { |
| 156 | case MT_SETTING: |
| 157 | case MT_SETTING_W_TEXT: |
| 158 | menu_icon = Icon_Menu_setting; |
| 159 | break; |
| 160 | case MT_MENU: |
| 161 | menu_icon = Icon_Submenu; |
| 162 | break; |
| 163 | case MT_FUNCTION_CALL: |
| 164 | case MT_RETURN_VALUE: |
| 165 | menu_icon = Icon_Menu_functioncall; |
| 166 | break; |
| 167 | } |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 168 | } |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 169 | return menu_icon; |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 170 | } |
| 171 | #endif |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 172 | |
| 173 | static void init_menu_lists(const struct menu_item_ex *menu, |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 174 | struct gui_synclist *lists, int selected, bool callback, |
| 175 | struct viewport parent[NB_SCREENS]) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 176 | { |
Jonathan Gordon | b5e587c | 2007-03-18 06:31:33 +0000 | [diff] [blame] | 177 | int i, count = MENU_GET_COUNT(menu->flags); |
Jonathan Gordon | 1f5ee2a | 2007-03-25 14:31:56 +0000 | [diff] [blame] | 178 | int type = (menu->flags&MENU_TYPE_MASK); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 179 | menu_callback_type menu_callback = NULL; |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 180 | int icon; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 181 | current_subitems_count = 0; |
Jonathan Gordon | 3452146 | 2007-03-07 13:00:46 +0000 | [diff] [blame] | 182 | |
Jonathan Gordon | 1f5ee2a | 2007-03-25 14:31:56 +0000 | [diff] [blame] | 183 | if (type == MT_RETURN_ID) |
| 184 | get_menu_callback(menu, &menu_callback); |
| 185 | |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 186 | for (i=0; i<count; i++) |
| 187 | { |
Jonathan Gordon | 1f5ee2a | 2007-03-25 14:31:56 +0000 | [diff] [blame] | 188 | if (type != MT_RETURN_ID) |
| 189 | get_menu_callback(menu->submenus[i],&menu_callback); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 190 | if (menu_callback) |
| 191 | { |
Jonathan Gordon | 1f5ee2a | 2007-03-25 14:31:56 +0000 | [diff] [blame] | 192 | if (menu_callback(ACTION_REQUEST_MENUITEM, |
| 193 | type==MT_RETURN_ID ? (void*)(intptr_t)i: menu->submenus[i]) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 194 | != ACTION_EXIT_MENUITEM) |
| 195 | { |
| 196 | current_subitems[current_subitems_count] = i; |
| 197 | current_subitems_count++; |
| 198 | } |
| 199 | } |
| 200 | else |
| 201 | { |
| 202 | current_subitems[current_subitems_count] = i; |
| 203 | current_subitems_count++; |
| 204 | } |
| 205 | } |
Jonathan Gordon | 3d39c4d | 2007-03-17 14:16:11 +0000 | [diff] [blame] | 206 | current_submenus_menu = (struct menu_item_ex *)menu; |
Jonathan Gordon | 208136d | 2007-03-17 14:10:51 +0000 | [diff] [blame] | 207 | |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 208 | gui_synclist_init(lists,get_menu_item_name,(void*)menu,false,1, parent); |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 209 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | 02a8717 | 2007-03-03 13:52:14 +0000 | [diff] [blame] | 210 | if (menu->callback_and_desc->icon_id == Icon_NOICON) |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 211 | icon = Icon_Submenu_Entered; |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 212 | else |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 213 | icon = menu->callback_and_desc->icon_id; |
Jonathan Gordon | f8e08f0 | 2007-02-15 23:27:57 +0000 | [diff] [blame] | 214 | gui_synclist_set_title(lists, P2STR(menu->callback_and_desc->desc), icon); |
Steve Bavin | 361a60c | 2007-03-01 18:25:13 +0000 | [diff] [blame] | 215 | gui_synclist_set_icon_callback(lists, menu_get_icon); |
Jonathan Gordon | f8e08f0 | 2007-02-15 23:27:57 +0000 | [diff] [blame] | 216 | #else |
| 217 | (void)icon; |
Steve Bavin | 361a60c | 2007-03-01 18:25:13 +0000 | [diff] [blame] | 218 | gui_synclist_set_icon_callback(lists, NULL); |
Jonathan Gordon | 5599d68 | 2007-02-14 06:58:30 +0000 | [diff] [blame] | 219 | #endif |
Stéphane Doyon | 4e09b78 | 2007-10-21 00:23:23 +0000 | [diff] [blame] | 220 | if(global_settings.talk_menu) |
| 221 | gui_synclist_set_voice_callback(lists, talk_menu_item); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 222 | gui_synclist_set_nb_items(lists,current_subitems_count); |
| 223 | gui_synclist_limit_scroll(lists,true); |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 224 | gui_synclist_select_item(lists, find_menu_selection(selected)); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 225 | |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 226 | get_menu_callback(menu,&menu_callback); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 227 | if (callback && menu_callback) |
| 228 | menu_callback(ACTION_ENTER_MENUITEM,menu); |
Jonathan Gordon | baf9cf6 | 2007-05-07 08:50:47 +0000 | [diff] [blame] | 229 | gui_synclist_draw(lists); |
Stéphane Doyon | 4e09b78 | 2007-10-21 00:23:23 +0000 | [diff] [blame] | 230 | gui_synclist_speak_item(lists); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Stéphane Doyon | 4e09b78 | 2007-10-21 00:23:23 +0000 | [diff] [blame] | 233 | static int talk_menu_item(int selected_item, void *data) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 234 | { |
Stéphane Doyon | 4e09b78 | 2007-10-21 00:23:23 +0000 | [diff] [blame] | 235 | const struct menu_item_ex *menu = (const struct menu_item_ex *)data; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 236 | int id = -1; |
Jonathan Gordon | 9709086 | 2007-03-03 14:23:03 +0000 | [diff] [blame] | 237 | int type; |
Linus Nielsen Feltzing | 298c2bb | 2007-03-05 00:32:33 +0000 | [diff] [blame] | 238 | unsigned char *str; |
Stéphane Doyon | 4e09b78 | 2007-10-21 00:23:23 +0000 | [diff] [blame] | 239 | int sel = get_menu_selection(selected_item, menu); |
Linus Nielsen Feltzing | 298c2bb | 2007-03-05 00:32:33 +0000 | [diff] [blame] | 240 | |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 241 | if ((menu->flags&MENU_TYPE_MASK) == MT_MENU) |
| 242 | { |
Jonathan Gordon | 9709086 | 2007-03-03 14:23:03 +0000 | [diff] [blame] | 243 | type = menu->submenus[sel]->flags&MENU_TYPE_MASK; |
| 244 | if ((type == MT_SETTING) || (type == MT_SETTING_W_TEXT)) |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 245 | talk_setting(menu->submenus[sel]->variable); |
| 246 | else |
| 247 | { |
Linus Nielsen Feltzing | 298c2bb | 2007-03-05 00:32:33 +0000 | [diff] [blame] | 248 | if (menu->submenus[sel]->flags&(MENU_DYNAMIC_DESC)) |
| 249 | { |
Stéphane Doyon | 5acf091 | 2007-10-09 03:48:56 +0000 | [diff] [blame] | 250 | int (*list_speak_item)(int selected_item, void * data) |
| 251 | = menu->submenus[sel]->menu_get_name_and_icon-> |
| 252 | list_speak_item; |
| 253 | if(list_speak_item) |
| 254 | list_speak_item(sel, menu->submenus[sel]-> |
| 255 | menu_get_name_and_icon-> |
| 256 | list_get_name_data); |
| 257 | else |
| 258 | { |
| 259 | char buffer[80]; |
| 260 | str = menu->submenus[sel]->menu_get_name_and_icon-> |
| 261 | list_get_name(sel, menu->submenus[sel]-> |
| 262 | menu_get_name_and_icon-> |
| 263 | list_get_name_data, buffer); |
| 264 | id = P2ID(str); |
| 265 | } |
Linus Nielsen Feltzing | 298c2bb | 2007-03-05 00:32:33 +0000 | [diff] [blame] | 266 | } |
| 267 | else |
| 268 | id = P2ID(menu->submenus[sel]->callback_and_desc->desc); |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 269 | if (id != -1) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 270 | talk_id(id,false); |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 271 | } |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 272 | } |
Jonathan Gordon | 94b9804 | 2007-08-20 09:11:05 +0000 | [diff] [blame] | 273 | else if(((menu->flags&MENU_TYPE_MASK) == MT_RETURN_ID)) |
| 274 | { |
| 275 | if ((menu->flags&MENU_DYNAMIC_DESC) == 0) |
| 276 | { |
| 277 | unsigned char *s = (unsigned char *)menu->strings[sel]; |
| 278 | /* string list, try to talk it if ID2P was used */ |
| 279 | id = P2ID(s); |
| 280 | if (id != -1) |
| 281 | talk_id(id,false); |
| 282 | } |
| 283 | } |
Stéphane Doyon | 4e09b78 | 2007-10-21 00:23:23 +0000 | [diff] [blame] | 284 | return 0; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 285 | } |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 286 | /* this is used to reload the default menu viewports when the |
| 287 | theme changes. nothing happens if the menu is using a supplied parent vp */ |
Bertrik Sikken | e15f8a2 | 2008-05-03 08:35:14 +0000 | [diff] [blame] | 288 | static void init_default_menu_viewports(struct viewport parent[NB_SCREENS], bool hide_bars) |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 289 | { |
| 290 | int i; |
| 291 | FOR_NB_SCREENS(i) |
| 292 | { |
| 293 | viewport_set_defaults(&parent[i], i); |
| 294 | /* viewport_set_defaults() fixes the vp for the bars, so resize */ |
| 295 | if (hide_bars) |
| 296 | { |
| 297 | if (global_settings.statusbar) |
| 298 | { |
| 299 | parent[i].y -= STATUSBAR_HEIGHT; |
| 300 | parent[i].height += STATUSBAR_HEIGHT; |
| 301 | } |
| 302 | } |
| 303 | } |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 304 | #ifdef HAVE_BUTTONBAR |
Jonathan Gordon | be185a1 | 2008-03-26 09:05:42 +0000 | [diff] [blame] | 305 | if (!hide_bars && global_settings.buttonbar) |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 306 | parent[0].height -= BUTTONBAR_HEIGHT; |
| 307 | #endif |
| 308 | } |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 309 | |
Jonathan Gordon | fe9dca3 | 2008-04-23 11:07:40 +0000 | [diff] [blame] | 310 | bool do_setting_from_menu(const struct menu_item_ex *temp, |
| 311 | struct viewport parent[NB_SCREENS]) |
Jonathan Gordon | 2801a87 | 2007-02-19 02:14:51 +0000 | [diff] [blame] | 312 | { |
Jonathan Gordon | be185a1 | 2008-03-26 09:05:42 +0000 | [diff] [blame] | 313 | int setting_id, oldval; |
Jonathan Gordon | 1ba493e | 2007-02-26 08:17:07 +0000 | [diff] [blame] | 314 | const struct settings_list *setting = find_setting( |
| 315 | temp->variable, |
| 316 | &setting_id); |
Jonathan Gordon | fe2b376 | 2007-07-23 05:40:45 +0000 | [diff] [blame] | 317 | char *title; |
Jonathan Gordon | 91ccc01 | 2007-11-05 13:15:35 +0000 | [diff] [blame] | 318 | char padded_title[MAX_PATH]; |
Jonathan Gordon | be185a1 | 2008-03-26 09:05:42 +0000 | [diff] [blame] | 319 | int var_type = setting->flags&F_T_MASK; |
| 320 | if (var_type == F_T_INT || var_type == F_T_UINT) |
| 321 | { |
| 322 | oldval = *(int*)setting->setting; |
| 323 | } |
| 324 | else if (var_type == F_T_BOOL) |
| 325 | { |
| 326 | oldval = *(bool*)setting->setting; |
| 327 | } |
| 328 | else |
| 329 | oldval = 0; |
Jonathan Gordon | fe2b376 | 2007-07-23 05:40:45 +0000 | [diff] [blame] | 330 | if ((temp->flags&MENU_TYPE_MASK) == MT_SETTING_W_TEXT) |
| 331 | title = temp->callback_and_desc->desc; |
| 332 | else |
| 333 | title = ID2P(setting->lang_id); |
Jonathan Gordon | 91ccc01 | 2007-11-05 13:15:35 +0000 | [diff] [blame] | 334 | |
Linus Nielsen Feltzing | 34d08b2 | 2007-11-16 08:18:08 +0000 | [diff] [blame] | 335 | /* Pad the title string by repeating it. This is needed |
| 336 | so the scroll settings title can actually be used to |
| 337 | test the setting */ |
Jonathan Gordon | 91ccc01 | 2007-11-05 13:15:35 +0000 | [diff] [blame] | 338 | if (setting->flags&F_PADTITLE) |
| 339 | { |
| 340 | int i = 0, len; |
| 341 | if (setting->lang_id == -1) |
| 342 | title = (char*)setting->cfg_vals; |
| 343 | else |
| 344 | title = P2STR((unsigned char*)title); |
| 345 | len = strlen(title); |
Linus Nielsen Feltzing | 34d08b2 | 2007-11-16 08:18:08 +0000 | [diff] [blame] | 346 | while (i < MAX_PATH-1) |
Jonathan Gordon | 91ccc01 | 2007-11-05 13:15:35 +0000 | [diff] [blame] | 347 | { |
Linus Nielsen Feltzing | 34d08b2 | 2007-11-16 08:18:08 +0000 | [diff] [blame] | 348 | int padlen = MIN(len, MAX_PATH-1-i); |
| 349 | strncpy(&padded_title[i], title, padlen); |
| 350 | i += padlen; |
Jonathan Gordon | 91ccc01 | 2007-11-05 13:15:35 +0000 | [diff] [blame] | 351 | if (i<MAX_PATH-1) |
| 352 | padded_title[i++] = ' '; |
| 353 | } |
| 354 | padded_title[i] = '\0'; |
| 355 | title = padded_title; |
| 356 | } |
| 357 | |
Jonathan Gordon | fe9dca3 | 2008-04-23 11:07:40 +0000 | [diff] [blame] | 358 | option_screen((struct settings_list *)setting, parent, |
Jonathan Gordon | fe2b376 | 2007-07-23 05:40:45 +0000 | [diff] [blame] | 359 | setting->flags&F_TEMPVAR, title); |
Jonathan Gordon | be185a1 | 2008-03-26 09:05:42 +0000 | [diff] [blame] | 360 | if (var_type == F_T_INT || var_type == F_T_UINT) |
| 361 | { |
| 362 | return oldval != *(int*)setting->setting; |
| 363 | } |
| 364 | else if (var_type == F_T_BOOL) |
| 365 | { |
| 366 | return oldval != *(bool*)setting->setting; |
| 367 | } |
Jonathan Gordon | a5278fa | 2007-07-11 05:41:23 +0000 | [diff] [blame] | 368 | return false; |
Jonathan Gordon | 2801a87 | 2007-02-19 02:14:51 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Jonathan Gordon | 62decc4 | 2007-11-04 12:10:41 +0000 | [diff] [blame] | 371 | /* display a menu */ |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 372 | int do_menu(const struct menu_item_ex *start_menu, int *start_selected, |
| 373 | struct viewport parent[NB_SCREENS], bool hide_bars) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 374 | { |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 375 | int selected = start_selected? *start_selected : 0; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 376 | int action; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 377 | struct gui_synclist lists; |
| 378 | const struct menu_item_ex *temp, *menu; |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 379 | int ret = 0, i; |
Jonathan Gordon | 411f3e2 | 2007-07-11 02:22:03 +0000 | [diff] [blame] | 380 | bool redraw_lists; |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 381 | |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 382 | const struct menu_item_ex *menu_stack[MAX_MENUS]; |
| 383 | int menu_stack_selected_item[MAX_MENUS]; |
| 384 | int stack_top = 0; |
Jonathan Gordon | 43b2d09 | 2007-03-07 10:13:07 +0000 | [diff] [blame] | 385 | bool in_stringlist, done = false; |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 386 | |
| 387 | struct viewport *vps, menu_vp[NB_SCREENS]; /* menu_vp will hopefully be phased out */ |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 388 | #ifdef HAVE_BUTTONBAR |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 389 | struct gui_buttonbar buttonbar; |
| 390 | gui_buttonbar_init(&buttonbar); |
| 391 | gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) ); |
| 392 | gui_buttonbar_set(&buttonbar, "<<<", "", ""); |
| 393 | #endif |
| 394 | |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 395 | menu_callback_type menu_callback = NULL; |
| 396 | if (start_menu == NULL) |
| 397 | menu = &main_menu_; |
| 398 | else menu = start_menu; |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 399 | |
| 400 | if (parent) |
| 401 | { |
| 402 | vps = parent; |
| 403 | /* if hide_bars == true we assume the viewport is correctly sized */ |
| 404 | } |
| 405 | else |
| 406 | { |
| 407 | vps = menu_vp; |
| 408 | init_default_menu_viewports(vps, hide_bars); |
| 409 | } |
| 410 | FOR_NB_SCREENS(i) |
| 411 | { |
| 412 | screens[i].set_viewport(&vps[i]); |
| 413 | screens[i].clear_viewport(); |
| 414 | screens[i].set_viewport(NULL); |
| 415 | } |
| 416 | init_menu_lists(menu, &lists, selected, true, vps); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 417 | in_stringlist = ((menu->flags&MENU_TYPE_MASK) == MT_RETURN_ID); |
| 418 | |
Jonathan Gordon | d563cb2 | 2007-02-21 12:22:07 +0000 | [diff] [blame] | 419 | /* load the callback, and only reload it if menu changes */ |
| 420 | get_menu_callback(menu, &menu_callback); |
| 421 | |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 422 | |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 423 | #ifdef HAVE_BUTTONBAR |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 424 | if (!hide_bars) |
| 425 | { |
| 426 | gui_buttonbar_set(&buttonbar, "<<<", "", ""); |
| 427 | gui_buttonbar_draw(&buttonbar); |
| 428 | } |
| 429 | #endif |
Jonathan Gordon | 43b2d09 | 2007-03-07 10:13:07 +0000 | [diff] [blame] | 430 | while (!done) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 431 | { |
Jonathan Gordon | 411f3e2 | 2007-07-11 02:22:03 +0000 | [diff] [blame] | 432 | redraw_lists = false; |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 433 | if (!hide_bars) |
| 434 | { |
| 435 | gui_syncstatusbar_draw(&statusbars, true); |
| 436 | } |
Stéphane Doyon | 4e09b78 | 2007-10-21 00:23:23 +0000 | [diff] [blame] | 437 | action = get_action(CONTEXT_MAINMENU, |
| 438 | list_do_action_timeout(&lists, HZ)); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 439 | /* HZ so the status bar redraws corectly */ |
Jonathan Gordon | d563cb2 | 2007-02-21 12:22:07 +0000 | [diff] [blame] | 440 | |
Stéphane Doyon | 4e09b78 | 2007-10-21 00:23:23 +0000 | [diff] [blame] | 441 | if (action != ACTION_NONE && menu_callback) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 442 | { |
Jonathan Gordon | 9144be5 | 2007-02-27 09:16:47 +0000 | [diff] [blame] | 443 | int old_action = action; |
Jonathan Gordon | d563cb2 | 2007-02-21 12:22:07 +0000 | [diff] [blame] | 444 | action = menu_callback(action, menu); |
Jonathan Gordon | 9144be5 | 2007-02-27 09:16:47 +0000 | [diff] [blame] | 445 | if (action == ACTION_EXIT_AFTER_THIS_MENUITEM) |
| 446 | { |
| 447 | action = old_action; |
| 448 | ret = MENU_SELECTED_EXIT; /* will exit after returning |
| 449 | from selection */ |
| 450 | } |
Jonathan Gordon | 411f3e2 | 2007-07-11 02:22:03 +0000 | [diff] [blame] | 451 | else if (action == ACTION_REDRAW) |
| 452 | { |
| 453 | action = old_action; |
| 454 | redraw_lists = true; |
| 455 | } |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 458 | if (gui_synclist_do_button(&lists, &action, LIST_WRAP_UNLESS_HELD)) |
Jonathan Gordon | b9f22af | 2007-07-11 01:23:57 +0000 | [diff] [blame] | 459 | continue; |
Stéphane Doyon | 4e09b78 | 2007-10-21 00:23:23 +0000 | [diff] [blame] | 460 | if (action == ACTION_NONE) |
| 461 | continue; |
Jonathan Gordon | 286d48f | 2008-04-23 10:33:46 +0000 | [diff] [blame] | 462 | #ifdef HAVE_QUICKSCREEN |
| 463 | else if (action == ACTION_STD_QUICKSCREEN) |
| 464 | { |
| 465 | quick_screen_quick(action); |
| 466 | redraw_lists = true; |
| 467 | } |
| 468 | #endif |
Jonathan Gordon | 73336e9 | 2007-08-02 12:13:20 +0000 | [diff] [blame] | 469 | #ifdef HAVE_RECORDING |
Jonathan Gordon | 286d48f | 2008-04-23 10:33:46 +0000 | [diff] [blame] | 470 | else if (action == ACTION_STD_REC) |
Jonathan Gordon | 73336e9 | 2007-08-02 12:13:20 +0000 | [diff] [blame] | 471 | { |
| 472 | ret = GO_TO_RECSCREEN; |
| 473 | done = true; |
| 474 | } |
Jonathan Gordon | 73336e9 | 2007-08-02 12:13:20 +0000 | [diff] [blame] | 475 | #endif |
Jonathan Gordon | 286d48f | 2008-04-23 10:33:46 +0000 | [diff] [blame] | 476 | else if (action == ACTION_TREE_WPS) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 477 | { |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 478 | ret = GO_TO_PREVIOUS_MUSIC; |
Jonathan Gordon | 43b2d09 | 2007-03-07 10:13:07 +0000 | [diff] [blame] | 479 | done = true; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 480 | } |
Jonathan Gordon | a053e58 | 2007-04-08 01:33:01 +0000 | [diff] [blame] | 481 | else if (action == ACTION_TREE_STOP) |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 482 | { |
Magnus Holmgren | 1d9f693 | 2007-08-05 15:21:47 +0000 | [diff] [blame] | 483 | redraw_lists = list_stop_handler(); |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 484 | } |
Jonathan Gordon | f9fb492 | 2007-04-12 15:28:51 +0000 | [diff] [blame] | 485 | else if (action == ACTION_STD_CONTEXT && |
| 486 | menu == &root_menu_) |
| 487 | { |
| 488 | ret = GO_TO_ROOTITEM_CONTEXT; |
| 489 | done = true; |
| 490 | } |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 491 | else if (action == ACTION_STD_MENU) |
| 492 | { |
| 493 | if (menu != &root_menu_) |
| 494 | ret = GO_TO_ROOT; |
Jonathan Gordon | a74eefe | 2007-03-06 13:35:15 +0000 | [diff] [blame] | 495 | else |
| 496 | ret = GO_TO_PREVIOUS; |
Jonathan Gordon | 43b2d09 | 2007-03-07 10:13:07 +0000 | [diff] [blame] | 497 | done = true; |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 498 | } |
| 499 | else if (action == ACTION_STD_CANCEL) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 500 | { |
Jonathan Gordon | 5cab5da | 2007-11-07 10:06:21 +0000 | [diff] [blame] | 501 | bool exiting_menu = false; |
Linus Nielsen Feltzing | 6ffd804 | 2007-02-16 10:40:59 +0000 | [diff] [blame] | 502 | in_stringlist = false; |
Jonathan Gordon | d563cb2 | 2007-02-21 12:22:07 +0000 | [diff] [blame] | 503 | if (menu_callback) |
| 504 | menu_callback(ACTION_EXIT_MENUITEM, menu); |
Linus Nielsen Feltzing | 6ffd804 | 2007-02-16 10:40:59 +0000 | [diff] [blame] | 505 | |
Jonathan Gordon | 3a7760c | 2007-04-30 13:41:33 +0000 | [diff] [blame] | 506 | if (menu->flags&MENU_EXITAFTERTHISMENU) |
| 507 | done = true; |
Jonathan Gordon | 5cab5da | 2007-11-07 10:06:21 +0000 | [diff] [blame] | 508 | else if ((menu->flags&MENU_TYPE_MASK) == MT_MENU) |
| 509 | exiting_menu = true; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 510 | if (stack_top > 0) |
| 511 | { |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 512 | stack_top--; |
| 513 | menu = menu_stack[stack_top]; |
Jonathan Gordon | 5cab5da | 2007-11-07 10:06:21 +0000 | [diff] [blame] | 514 | if (!exiting_menu && (menu->flags&MENU_EXITAFTERTHISMENU)) |
Jonathan Gordon | 3a7760c | 2007-04-30 13:41:33 +0000 | [diff] [blame] | 515 | done = true; |
Jonathan Gordon | 75e2f19 | 2007-08-04 09:47:17 +0000 | [diff] [blame] | 516 | else |
| 517 | init_menu_lists(menu, &lists, |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 518 | menu_stack_selected_item[stack_top], false, vps); |
Jonathan Gordon | d563cb2 | 2007-02-21 12:22:07 +0000 | [diff] [blame] | 519 | /* new menu, so reload the callback */ |
Jonathan Gordon | 1ea4f0d | 2007-02-16 00:55:52 +0000 | [diff] [blame] | 520 | get_menu_callback(menu, &menu_callback); |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 521 | } |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 522 | else if (menu != &root_menu_) |
| 523 | { |
| 524 | ret = GO_TO_PREVIOUS; |
Jonathan Gordon | 43b2d09 | 2007-03-07 10:13:07 +0000 | [diff] [blame] | 525 | done = true; |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 526 | } |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 527 | } |
| 528 | else if (action == ACTION_STD_OK) |
| 529 | { |
| 530 | int type; |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 531 | #ifdef HAVE_BUTTONBAR |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 532 | if (!hide_bars) |
| 533 | { |
| 534 | gui_buttonbar_unset(&buttonbar); |
| 535 | gui_buttonbar_draw(&buttonbar); |
| 536 | } |
Jonathan Gordon | 1ba493e | 2007-02-26 08:17:07 +0000 | [diff] [blame] | 537 | #endif |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 538 | selected = get_menu_selection(gui_synclist_get_sel_pos(&lists), menu); |
| 539 | temp = menu->submenus[selected]; |
Jonathan Gordon | 50dc0ca | 2007-07-11 04:17:43 +0000 | [diff] [blame] | 540 | redraw_lists = true; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 541 | if (in_stringlist) |
| 542 | type = (menu->flags&MENU_TYPE_MASK); |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 543 | else |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 544 | { |
Jonathan Gordon | 1f5ee2a | 2007-03-25 14:31:56 +0000 | [diff] [blame] | 545 | type = (temp->flags&MENU_TYPE_MASK); |
| 546 | get_menu_callback(temp, &menu_callback); |
| 547 | if (menu_callback) |
| 548 | { |
| 549 | action = menu_callback(ACTION_ENTER_MENUITEM,temp); |
| 550 | if (action == ACTION_EXIT_MENUITEM) |
| 551 | break; |
| 552 | } |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 553 | } |
| 554 | switch (type) |
| 555 | { |
| 556 | case MT_MENU: |
| 557 | if (stack_top < MAX_MENUS) |
| 558 | { |
| 559 | menu_stack[stack_top] = menu; |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 560 | menu_stack_selected_item[stack_top] = selected; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 561 | stack_top++; |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 562 | init_menu_lists(temp, &lists, 0, true, vps); |
Jonathan Gordon | 50dc0ca | 2007-07-11 04:17:43 +0000 | [diff] [blame] | 563 | redraw_lists = false; /* above does the redraw */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 564 | menu = temp; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 565 | } |
| 566 | break; |
| 567 | case MT_FUNCTION_CALL: |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 568 | { |
| 569 | int return_value; |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 570 | if (temp->flags&MENU_FUNC_USEPARAM) |
| 571 | return_value = temp->function->function_w_param( |
| 572 | temp->function->param); |
| 573 | else |
| 574 | return_value = temp->function->function(); |
Jonathan Gordon | 6d20795 | 2008-04-30 10:22:39 +0000 | [diff] [blame] | 575 | if (!(menu->flags&MENU_EXITAFTERTHISMENU) || (temp->flags&MENU_EXITAFTERTHISMENU)) |
| 576 | { |
| 577 | init_default_menu_viewports(menu_vp, hide_bars); |
| 578 | init_menu_lists(menu, &lists, selected, true, vps); |
| 579 | } |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 580 | if (temp->flags&MENU_FUNC_CHECK_RETVAL) |
| 581 | { |
Jonathan Gordon | e54d8e1 | 2007-03-18 07:03:43 +0000 | [diff] [blame] | 582 | if (return_value == 1) |
Jonathan Gordon | b5e587c | 2007-03-18 06:31:33 +0000 | [diff] [blame] | 583 | { |
| 584 | done = true; |
| 585 | ret = return_value; |
| 586 | } |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 587 | } |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 588 | break; |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 589 | } |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 590 | case MT_SETTING: |
Jonathan Gordon | 9709086 | 2007-03-03 14:23:03 +0000 | [diff] [blame] | 591 | case MT_SETTING_W_TEXT: |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 592 | { |
Jonathan Gordon | fe9dca3 | 2008-04-23 11:07:40 +0000 | [diff] [blame] | 593 | if (do_setting_from_menu(temp, menu_vp)) |
Jonathan Gordon | 50dc0ca | 2007-07-11 04:17:43 +0000 | [diff] [blame] | 594 | { |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 595 | init_default_menu_viewports(menu_vp, hide_bars); |
| 596 | init_menu_lists(menu, &lists, selected, true,vps); |
Jonathan Gordon | 50dc0ca | 2007-07-11 04:17:43 +0000 | [diff] [blame] | 597 | redraw_lists = false; /* above does the redraw */ |
| 598 | } |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 599 | break; |
| 600 | } |
| 601 | case MT_RETURN_ID: |
| 602 | if (in_stringlist) |
| 603 | { |
Jonathan Gordon | b5e587c | 2007-03-18 06:31:33 +0000 | [diff] [blame] | 604 | done = true; |
| 605 | ret = selected; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 606 | } |
| 607 | else if (stack_top < MAX_MENUS) |
| 608 | { |
| 609 | menu_stack[stack_top] = menu; |
| 610 | menu_stack_selected_item[stack_top] = selected; |
| 611 | stack_top++; |
| 612 | menu = temp; |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 613 | init_menu_lists(menu,&lists,0,false, vps); |
Jonathan Gordon | 50dc0ca | 2007-07-11 04:17:43 +0000 | [diff] [blame] | 614 | redraw_lists = false; /* above does the redraw */ |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 615 | in_stringlist = true; |
| 616 | } |
| 617 | break; |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 618 | case MT_RETURN_VALUE: |
Jonathan Gordon | 43b2d09 | 2007-03-07 10:13:07 +0000 | [diff] [blame] | 619 | ret = temp->value; |
| 620 | done = true; |
| 621 | break; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 622 | } |
Jonathan Gordon | 3a7760c | 2007-04-30 13:41:33 +0000 | [diff] [blame] | 623 | if (type != MT_MENU) |
| 624 | { |
| 625 | if (menu_callback) |
| 626 | menu_callback(ACTION_EXIT_MENUITEM,temp); |
| 627 | } |
Jonathan Gordon | 208136d | 2007-03-17 14:10:51 +0000 | [diff] [blame] | 628 | if (current_submenus_menu != menu) |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 629 | init_menu_lists(menu,&lists,selected,true,vps); |
Jonathan Gordon | d563cb2 | 2007-02-21 12:22:07 +0000 | [diff] [blame] | 630 | /* callback was changed, so reload the menu's callback */ |
| 631 | get_menu_callback(menu, &menu_callback); |
Jonathan Gordon | 3a7760c | 2007-04-30 13:41:33 +0000 | [diff] [blame] | 632 | if ((menu->flags&MENU_EXITAFTERTHISMENU) && |
| 633 | !(temp->flags&MENU_EXITAFTERTHISMENU)) |
| 634 | { |
| 635 | done = true; |
| 636 | break; |
| 637 | } |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 638 | #ifdef HAVE_BUTTONBAR |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 639 | if (!hide_bars) |
| 640 | { |
| 641 | gui_buttonbar_set(&buttonbar, "<<<", "", ""); |
| 642 | gui_buttonbar_draw(&buttonbar); |
| 643 | } |
Jonathan Gordon | 1ba493e | 2007-02-26 08:17:07 +0000 | [diff] [blame] | 644 | #endif |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 645 | } |
| 646 | else if(default_event_handler(action) == SYS_USB_CONNECTED) |
Peter D'Hoye | d2b3055 | 2007-03-30 21:54:48 +0000 | [diff] [blame] | 647 | { |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 648 | ret = MENU_ATTACHED_USB; |
Peter D'Hoye | d2b3055 | 2007-03-30 21:54:48 +0000 | [diff] [blame] | 649 | done = true; |
| 650 | } |
Jonathan Gordon | 411f3e2 | 2007-07-11 02:22:03 +0000 | [diff] [blame] | 651 | |
Stéphane Doyon | 4e09b78 | 2007-10-21 00:23:23 +0000 | [diff] [blame] | 652 | if (redraw_lists && !done) |
| 653 | { |
Jonathan Gordon | 411f3e2 | 2007-07-11 02:22:03 +0000 | [diff] [blame] | 654 | gui_synclist_draw(&lists); |
Stéphane Doyon | 4e09b78 | 2007-10-21 00:23:23 +0000 | [diff] [blame] | 655 | gui_synclist_speak_item(&lists); |
| 656 | } |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 657 | } |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 658 | if (start_selected) |
Jonathan Gordon | fd9d140 | 2007-05-20 14:24:02 +0000 | [diff] [blame] | 659 | { |
| 660 | /* make sure the start_selected variable is set to |
| 661 | the selected item from the menu do_menu() was called from */ |
| 662 | if (stack_top > 0) |
| 663 | { |
| 664 | menu = menu_stack[0]; |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 665 | init_menu_lists(menu,&lists,menu_stack_selected_item[0],true, vps); |
Jonathan Gordon | fd9d140 | 2007-05-20 14:24:02 +0000 | [diff] [blame] | 666 | } |
Jonathan Gordon | 43b2d09 | 2007-03-07 10:13:07 +0000 | [diff] [blame] | 667 | *start_selected = get_menu_selection( |
| 668 | gui_synclist_get_sel_pos(&lists), menu); |
Jonathan Gordon | fd9d140 | 2007-05-20 14:24:02 +0000 | [diff] [blame] | 669 | } |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 670 | return ret; |
| 671 | } |
| 672 | |