2002-05-17 12:22:24 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Robert E. Hak
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2005-10-30 22:34:51 +00:00
|
|
|
/*
|
|
|
|
2005 Kevin Ferrare :
|
|
|
|
- Multi screen support
|
|
|
|
- Rewrote/removed a lot of code now useless with the new gui API
|
|
|
|
*/
|
2002-05-26 17:03:17 +00:00
|
|
|
#include <stdbool.h>
|
2004-03-12 10:20:33 +00:00
|
|
|
#include <stdlib.h>
|
2007-03-01 11:14:46 +00:00
|
|
|
#include "config.h"
|
2002-08-31 04:58:35 +00:00
|
|
|
|
2002-05-17 12:22:24 +00:00
|
|
|
#include "lcd.h"
|
2002-09-12 13:33:59 +00:00
|
|
|
#include "font.h"
|
2002-08-31 04:58:35 +00:00
|
|
|
#include "backlight.h"
|
2002-05-17 12:22:24 +00:00
|
|
|
#include "menu.h"
|
2002-05-21 14:25:45 +00:00
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "debug.h"
|
2002-08-23 02:17:00 +00:00
|
|
|
#include "usb.h"
|
2002-08-11 09:17:47 +00:00
|
|
|
#include "panic.h"
|
2002-08-20 19:37:00 +00:00
|
|
|
#include "settings.h"
|
2007-02-08 04:33:41 +00:00
|
|
|
#include "settings_list.h"
|
2002-08-20 19:37:00 +00:00
|
|
|
#include "status.h"
|
2002-09-24 18:04:15 +00:00
|
|
|
#include "screens.h"
|
2004-03-14 21:33:53 +00:00
|
|
|
#include "talk.h"
|
2004-07-23 23:01:20 +00:00
|
|
|
#include "lang.h"
|
2004-07-26 16:06:59 +00:00
|
|
|
#include "misc.h"
|
2006-08-15 12:27:07 +00:00
|
|
|
#include "action.h"
|
2007-02-08 04:33:41 +00:00
|
|
|
#include "menus/exported_menus.h"
|
2007-02-08 10:28:42 +00:00
|
|
|
#include "string.h"
|
2007-03-01 11:14:46 +00:00
|
|
|
#include "root_menu.h"
|
|
|
|
#include "bookmark.h"
|
|
|
|
#include "gwps-common.h" /* for fade() */
|
|
|
|
#include "audio.h"
|
2002-08-30 13:49:32 +00:00
|
|
|
|
2002-06-14 08:47:44 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#include "icons.h"
|
|
|
|
#endif
|
2002-08-30 13:49:32 +00:00
|
|
|
|
2005-10-30 22:34:51 +00:00
|
|
|
/* gui api */
|
|
|
|
#include "list.h"
|
|
|
|
#include "statusbar.h"
|
|
|
|
#include "buttonbar.h"
|
2007-03-07 13:00:46 +00:00
|
|
|
/* needed for the old menu system */
|
2002-05-26 17:03:17 +00:00
|
|
|
struct menu {
|
2004-03-16 13:44:56 +00:00
|
|
|
struct menu_item* items;
|
2007-04-08 05:52:47 +00:00
|
|
|
char *title;
|
2007-03-07 13:00:46 +00:00
|
|
|
int count;
|
2004-03-12 10:20:33 +00:00
|
|
|
int (*callback)(int, int);
|
2007-03-07 13:00:46 +00:00
|
|
|
int current_selection;
|
2002-05-26 17:03:17 +00:00
|
|
|
};
|
2006-09-16 19:51:46 +00:00
|
|
|
#define MAX_MENUS 6
|
2002-05-26 17:03:17 +00:00
|
|
|
static struct menu menus[MAX_MENUS];
|
|
|
|
static bool inuse[MAX_MENUS] = { false };
|
2007-03-07 13:00:46 +00:00
|
|
|
static void init_oldmenu(const struct menu_item_ex *menu,
|
|
|
|
struct gui_synclist *lists, int selected, bool callback);
|
|
|
|
static void menu_talk_selected(int m);
|
2007-02-08 04:33:41 +00:00
|
|
|
|
|
|
|
/* used to allow for dynamic menus */
|
|
|
|
#define MAX_MENU_SUBITEMS 64
|
2007-03-17 14:10:51 +00:00
|
|
|
static struct menu_item_ex *current_submenus_menu;
|
2007-02-08 04:33:41 +00:00
|
|
|
static int current_subitems[MAX_MENU_SUBITEMS];
|
|
|
|
static int current_subitems_count = 0;
|
|
|
|
|
|
|
|
void get_menu_callback(const struct menu_item_ex *m,
|
2007-02-08 10:28:42 +00:00
|
|
|
menu_callback_type *menu_callback)
|
2007-02-08 04:33:41 +00:00
|
|
|
{
|
2007-02-19 02:14:51 +00:00
|
|
|
if (m->flags&(MENU_HAS_DESC|MENU_DYNAMIC_DESC))
|
2007-02-08 10:28:42 +00:00
|
|
|
*menu_callback= m->callback_and_desc->menu_callback;
|
|
|
|
else
|
|
|
|
*menu_callback = m->menu_callback;
|
2007-02-08 04:33:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_menu_selection(int selected_item, const struct menu_item_ex *menu)
|
|
|
|
{
|
|
|
|
int type = (menu->flags&MENU_TYPE_MASK);
|
|
|
|
if (type == MT_MENU && (selected_item<current_subitems_count))
|
|
|
|
return current_subitems[selected_item];
|
|
|
|
return selected_item;
|
|
|
|
}
|
2007-03-01 11:14:46 +00:00
|
|
|
static int find_menu_selection(int selected)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i< current_subitems_count; i++)
|
|
|
|
if (current_subitems[i] == selected)
|
|
|
|
return i;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-02-08 04:33:41 +00:00
|
|
|
static char * get_menu_item_name(int selected_item,void * data, char *buffer)
|
|
|
|
{
|
|
|
|
const struct menu_item_ex *menu = (const struct menu_item_ex *)data;
|
|
|
|
int type = (menu->flags&MENU_TYPE_MASK);
|
|
|
|
selected_item = get_menu_selection(selected_item, menu);
|
|
|
|
|
|
|
|
(void)buffer;
|
|
|
|
/* only MT_MENU or MT_RETURN_ID is allowed in here */
|
|
|
|
if (type == MT_RETURN_ID)
|
|
|
|
{
|
2007-02-27 09:06:30 +00:00
|
|
|
if (menu->flags&MENU_DYNAMIC_DESC)
|
|
|
|
return menu->menu_get_name_and_icon->list_get_name(selected_item,
|
|
|
|
menu->menu_get_name_and_icon->list_get_name_data, buffer);
|
2007-02-08 04:33:41 +00:00
|
|
|
return (char*)menu->strings[selected_item];
|
|
|
|
}
|
|
|
|
|
|
|
|
menu = menu->submenus[selected_item];
|
2007-02-26 08:17:07 +00:00
|
|
|
|
2007-03-03 14:23:03 +00:00
|
|
|
if ((menu->flags&MENU_DYNAMIC_DESC) && (type != MT_SETTING_W_TEXT))
|
2007-02-26 08:17:07 +00:00
|
|
|
return menu->menu_get_name_and_icon->list_get_name(selected_item,
|
|
|
|
menu->menu_get_name_and_icon->list_get_name_data, buffer);
|
|
|
|
|
2007-02-08 04:33:41 +00:00
|
|
|
type = (menu->flags&MENU_TYPE_MASK);
|
2007-03-03 14:23:03 +00:00
|
|
|
if ((type == MT_SETTING) || (type == MT_SETTING_W_TEXT))
|
2007-02-08 04:33:41 +00:00
|
|
|
{
|
|
|
|
const struct settings_list *v
|
2007-02-08 10:28:42 +00:00
|
|
|
= find_setting(menu->variable, NULL);
|
2007-02-08 04:33:41 +00:00
|
|
|
if (v)
|
|
|
|
return str(v->lang_id);
|
|
|
|
else return "Not Done yet!";
|
|
|
|
}
|
|
|
|
return P2STR(menu->callback_and_desc->desc);
|
|
|
|
}
|
2007-02-14 06:58:30 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-04-16 09:14:36 +00:00
|
|
|
static int menu_get_icon(int selected_item, void * data)
|
2007-02-14 06:58:30 +00:00
|
|
|
{
|
|
|
|
const struct menu_item_ex *menu = (const struct menu_item_ex *)data;
|
2007-03-03 14:23:03 +00:00
|
|
|
int menu_icon = Icon_NOICON;
|
2007-02-14 06:58:30 +00:00
|
|
|
selected_item = get_menu_selection(selected_item, menu);
|
|
|
|
|
2007-03-25 14:31:56 +00:00
|
|
|
if ((menu->flags&MENU_TYPE_MASK) == MT_RETURN_ID)
|
|
|
|
{
|
2007-04-16 09:14:36 +00:00
|
|
|
return Icon_Menu_functioncall;
|
2007-03-25 14:31:56 +00:00
|
|
|
}
|
2007-02-14 06:58:30 +00:00
|
|
|
menu = menu->submenus[selected_item];
|
2007-02-26 08:17:07 +00:00
|
|
|
if (menu->flags&MENU_HAS_DESC)
|
2007-03-03 13:52:14 +00:00
|
|
|
menu_icon = menu->callback_and_desc->icon_id;
|
2007-02-26 08:17:07 +00:00
|
|
|
else if (menu->flags&MENU_DYNAMIC_DESC)
|
2007-03-03 13:52:14 +00:00
|
|
|
menu_icon = menu->menu_get_name_and_icon->icon_id;
|
2007-02-26 08:17:07 +00:00
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
if (menu_icon == Icon_NOICON)
|
2007-02-14 06:58:30 +00:00
|
|
|
{
|
2007-04-16 09:14:36 +00:00
|
|
|
switch (menu->flags&MENU_TYPE_MASK)
|
|
|
|
{
|
|
|
|
case MT_SETTING:
|
|
|
|
case MT_SETTING_W_TEXT:
|
|
|
|
menu_icon = Icon_Menu_setting;
|
|
|
|
break;
|
|
|
|
case MT_MENU:
|
|
|
|
menu_icon = Icon_Submenu;
|
|
|
|
break;
|
|
|
|
case MT_FUNCTION_CALL:
|
|
|
|
case MT_RETURN_VALUE:
|
|
|
|
menu_icon = Icon_Menu_functioncall;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-14 06:58:30 +00:00
|
|
|
}
|
2007-04-16 09:14:36 +00:00
|
|
|
return menu_icon;
|
2007-02-14 06:58:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
2007-02-08 04:33:41 +00:00
|
|
|
|
|
|
|
static void init_menu_lists(const struct menu_item_ex *menu,
|
|
|
|
struct gui_synclist *lists, int selected, bool callback)
|
|
|
|
{
|
2007-03-18 06:31:33 +00:00
|
|
|
int i, count = MENU_GET_COUNT(menu->flags);
|
2007-03-25 14:31:56 +00:00
|
|
|
int type = (menu->flags&MENU_TYPE_MASK);
|
2007-02-08 04:33:41 +00:00
|
|
|
menu_callback_type menu_callback = NULL;
|
2007-04-16 09:14:36 +00:00
|
|
|
int icon;
|
2007-02-08 04:33:41 +00:00
|
|
|
current_subitems_count = 0;
|
2007-03-07 13:00:46 +00:00
|
|
|
|
2007-03-25 14:31:56 +00:00
|
|
|
if (type == MT_OLD_MENU)
|
2007-03-07 13:00:46 +00:00
|
|
|
{
|
|
|
|
init_oldmenu(menu, lists, selected, callback);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-25 14:31:56 +00:00
|
|
|
if (type == MT_RETURN_ID)
|
|
|
|
get_menu_callback(menu, &menu_callback);
|
|
|
|
|
2007-02-08 04:33:41 +00:00
|
|
|
for (i=0; i<count; i++)
|
|
|
|
{
|
2007-03-25 14:31:56 +00:00
|
|
|
if (type != MT_RETURN_ID)
|
|
|
|
get_menu_callback(menu->submenus[i],&menu_callback);
|
2007-02-08 04:33:41 +00:00
|
|
|
if (menu_callback)
|
|
|
|
{
|
2007-03-25 14:31:56 +00:00
|
|
|
if (menu_callback(ACTION_REQUEST_MENUITEM,
|
|
|
|
type==MT_RETURN_ID ? (void*)(intptr_t)i: menu->submenus[i])
|
2007-02-08 04:33:41 +00:00
|
|
|
!= ACTION_EXIT_MENUITEM)
|
|
|
|
{
|
|
|
|
current_subitems[current_subitems_count] = i;
|
|
|
|
current_subitems_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
current_subitems[current_subitems_count] = i;
|
|
|
|
current_subitems_count++;
|
|
|
|
}
|
|
|
|
}
|
2007-03-17 14:16:11 +00:00
|
|
|
current_submenus_menu = (struct menu_item_ex *)menu;
|
2007-03-17 14:10:51 +00:00
|
|
|
|
2007-02-08 04:33:41 +00:00
|
|
|
gui_synclist_init(lists,get_menu_item_name,(void*)menu,false,1);
|
2007-02-14 06:58:30 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-03-03 13:52:14 +00:00
|
|
|
if (menu->callback_and_desc->icon_id == Icon_NOICON)
|
2007-04-16 09:14:36 +00:00
|
|
|
icon = Icon_Submenu_Entered;
|
2007-02-14 06:58:30 +00:00
|
|
|
else
|
2007-04-16 09:14:36 +00:00
|
|
|
icon = menu->callback_and_desc->icon_id;
|
2007-02-15 23:27:57 +00:00
|
|
|
gui_synclist_set_title(lists, P2STR(menu->callback_and_desc->desc), icon);
|
2007-03-01 18:25:13 +00:00
|
|
|
gui_synclist_set_icon_callback(lists, menu_get_icon);
|
2007-02-15 23:27:57 +00:00
|
|
|
#else
|
|
|
|
(void)icon;
|
2007-03-01 18:25:13 +00:00
|
|
|
gui_synclist_set_icon_callback(lists, NULL);
|
2007-02-14 06:58:30 +00:00
|
|
|
#endif
|
2007-02-08 04:33:41 +00:00
|
|
|
gui_synclist_set_nb_items(lists,current_subitems_count);
|
|
|
|
gui_synclist_limit_scroll(lists,true);
|
2007-03-01 11:14:46 +00:00
|
|
|
gui_synclist_select_item(lists, find_menu_selection(selected));
|
2007-02-08 04:33:41 +00:00
|
|
|
|
2007-02-08 10:28:42 +00:00
|
|
|
get_menu_callback(menu,&menu_callback);
|
2007-02-08 04:33:41 +00:00
|
|
|
if (callback && menu_callback)
|
|
|
|
menu_callback(ACTION_ENTER_MENUITEM,menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void talk_menu_item(const struct menu_item_ex *menu,
|
|
|
|
struct gui_synclist *lists)
|
|
|
|
{
|
|
|
|
int id = -1;
|
2007-03-03 14:23:03 +00:00
|
|
|
int type;
|
2007-03-05 00:32:33 +00:00
|
|
|
unsigned char *str;
|
2007-03-07 13:00:46 +00:00
|
|
|
int sel;
|
2007-03-05 00:32:33 +00:00
|
|
|
|
2007-02-08 04:33:41 +00:00
|
|
|
if (global_settings.talk_menu)
|
|
|
|
{
|
2007-03-07 13:00:46 +00:00
|
|
|
if ((menu->flags&MENU_TYPE_MASK) == MT_OLD_MENU)
|
|
|
|
{
|
|
|
|
menus[menu->value].current_selection =
|
|
|
|
gui_synclist_get_sel_pos(lists);
|
|
|
|
menu_talk_selected(menu->value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sel = get_menu_selection(gui_synclist_get_sel_pos(lists),menu);
|
2007-02-08 04:33:41 +00:00
|
|
|
if ((menu->flags&MENU_TYPE_MASK) == MT_MENU)
|
|
|
|
{
|
2007-03-03 14:23:03 +00:00
|
|
|
type = menu->submenus[sel]->flags&MENU_TYPE_MASK;
|
|
|
|
if ((type == MT_SETTING) || (type == MT_SETTING_W_TEXT))
|
2007-03-01 11:14:46 +00:00
|
|
|
talk_setting(menu->submenus[sel]->variable);
|
|
|
|
else
|
|
|
|
{
|
2007-03-05 00:32:33 +00:00
|
|
|
if (menu->submenus[sel]->flags&(MENU_DYNAMIC_DESC))
|
|
|
|
{
|
|
|
|
char buffer[80];
|
|
|
|
str = menu->submenus[sel]->menu_get_name_and_icon->
|
|
|
|
list_get_name(sel, menu->submenus[sel]->
|
|
|
|
menu_get_name_and_icon->
|
|
|
|
list_get_name_data, buffer);
|
|
|
|
id = P2ID(str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
id = P2ID(menu->submenus[sel]->callback_and_desc->desc);
|
2007-03-01 11:14:46 +00:00
|
|
|
if (id != -1)
|
2007-02-08 04:33:41 +00:00
|
|
|
talk_id(id,false);
|
2007-03-01 11:14:46 +00:00
|
|
|
}
|
2007-02-08 04:33:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#define MAX_OPTIONS 32
|
2007-02-19 02:14:51 +00:00
|
|
|
/* returns true if the menu needs to be redrwan */
|
|
|
|
bool do_setting_from_menu(const struct menu_item_ex *temp)
|
|
|
|
{
|
2007-02-26 08:17:07 +00:00
|
|
|
int setting_id;
|
|
|
|
const struct settings_list *setting = find_setting(
|
|
|
|
temp->variable,
|
|
|
|
&setting_id);
|
|
|
|
bool ret_val = false;
|
2007-03-03 14:23:03 +00:00
|
|
|
unsigned char *title;
|
2007-02-26 08:17:07 +00:00
|
|
|
if (setting)
|
|
|
|
{
|
2007-03-03 14:23:03 +00:00
|
|
|
if ((temp->flags&MENU_TYPE_MASK) == MT_SETTING_W_TEXT)
|
|
|
|
title = temp->callback_and_desc->desc;
|
|
|
|
else
|
|
|
|
title = ID2P(setting->lang_id);
|
|
|
|
|
2007-02-26 08:17:07 +00:00
|
|
|
if ((setting->flags&F_BOOL_SETTING) == F_BOOL_SETTING)
|
|
|
|
{
|
|
|
|
bool temp_var, *var;
|
|
|
|
bool show_icons = global_settings.show_icons;
|
|
|
|
if (setting->flags&F_TEMPVAR)
|
|
|
|
{
|
|
|
|
temp_var = *(bool*)setting->setting;
|
|
|
|
var = &temp_var;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var = (bool*)setting->setting;
|
|
|
|
}
|
2007-03-03 14:23:03 +00:00
|
|
|
set_bool_options(P2STR(title), var,
|
2007-02-26 08:17:07 +00:00
|
|
|
STR(setting->bool_setting->lang_yes),
|
|
|
|
STR(setting->bool_setting->lang_no),
|
|
|
|
setting->bool_setting->option_callback);
|
|
|
|
if (setting->flags&F_TEMPVAR)
|
|
|
|
*(bool*)setting->setting = temp_var;
|
|
|
|
if (show_icons != global_settings.show_icons)
|
|
|
|
ret_val = true;
|
|
|
|
}
|
|
|
|
else if (setting->flags&F_T_SOUND)
|
|
|
|
{
|
2007-03-03 14:23:03 +00:00
|
|
|
set_sound(P2STR(title), setting->setting,
|
2007-02-26 08:17:07 +00:00
|
|
|
setting->sound_setting->setting);
|
|
|
|
}
|
|
|
|
else /* other setting, must be an INT type */
|
|
|
|
{
|
|
|
|
int temp_var, *var;
|
|
|
|
if (setting->flags&F_TEMPVAR)
|
|
|
|
{
|
|
|
|
temp_var = *(int*)setting->setting;
|
|
|
|
var = &temp_var;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var = (int*)setting->setting;
|
|
|
|
}
|
|
|
|
if (setting->flags&F_INT_SETTING)
|
|
|
|
{
|
|
|
|
int min, max, step;
|
|
|
|
if (setting->flags&F_FLIPLIST)
|
|
|
|
{
|
|
|
|
min = setting->int_setting->max;
|
|
|
|
max = setting->int_setting->min;
|
|
|
|
step = -setting->int_setting->step;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
max = setting->int_setting->max;
|
|
|
|
min = setting->int_setting->min;
|
|
|
|
step = setting->int_setting->step;
|
|
|
|
}
|
2007-03-03 14:23:03 +00:00
|
|
|
set_int_ex(P2STR(title), NULL,
|
2007-02-26 08:17:07 +00:00
|
|
|
setting->int_setting->unit,var,
|
|
|
|
setting->int_setting->option_callback,
|
|
|
|
step, min, max,
|
|
|
|
setting->int_setting->formatter,
|
|
|
|
setting->int_setting->get_talk_id);
|
|
|
|
}
|
|
|
|
else if (setting->flags&F_CHOICE_SETTING)
|
|
|
|
{
|
|
|
|
static struct opt_items options[MAX_OPTIONS];
|
|
|
|
char buffer[256];
|
|
|
|
char *buf_start = buffer;
|
|
|
|
int buf_free = 256;
|
|
|
|
int i,j, count = setting->choice_setting->count;
|
|
|
|
for (i=0, j=0; i<count && i<MAX_OPTIONS; i++)
|
|
|
|
{
|
|
|
|
if (setting->flags&F_CHOICETALKS)
|
|
|
|
{
|
|
|
|
if (cfg_int_to_string(setting_id, i,
|
|
|
|
buf_start, buf_free))
|
|
|
|
{
|
|
|
|
int len = strlen(buf_start) +1;
|
|
|
|
options[j].string = buf_start;
|
|
|
|
buf_start += len;
|
|
|
|
buf_free -= len;
|
|
|
|
options[j].voice_id =
|
|
|
|
setting->choice_setting->talks[i];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
options[j].string =
|
|
|
|
P2STR(setting->
|
|
|
|
choice_setting->desc[i]);
|
|
|
|
options[j].voice_id =
|
|
|
|
P2ID(setting->
|
|
|
|
choice_setting->desc[i]);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
2007-03-03 14:23:03 +00:00
|
|
|
set_option(P2STR(title), var, INT,
|
2007-02-26 08:17:07 +00:00
|
|
|
options,j,
|
|
|
|
setting->
|
|
|
|
choice_setting->option_callback);
|
|
|
|
}
|
|
|
|
if (setting->flags&F_TEMPVAR)
|
|
|
|
*(int*)setting->setting = temp_var;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret_val;
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
|
|
|
|
2007-03-01 11:14:46 +00:00
|
|
|
int do_menu(const struct menu_item_ex *start_menu, int *start_selected)
|
2007-02-08 04:33:41 +00:00
|
|
|
{
|
2007-03-01 11:14:46 +00:00
|
|
|
int selected = start_selected? *start_selected : 0;
|
2007-02-08 04:33:41 +00:00
|
|
|
int action;
|
|
|
|
struct gui_synclist lists;
|
|
|
|
const struct menu_item_ex *temp, *menu;
|
|
|
|
int ret = 0;
|
2007-02-26 08:17:07 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
struct gui_buttonbar buttonbar;
|
|
|
|
#endif
|
|
|
|
|
2007-02-08 04:33:41 +00:00
|
|
|
const struct menu_item_ex *menu_stack[MAX_MENUS];
|
|
|
|
int menu_stack_selected_item[MAX_MENUS];
|
|
|
|
int stack_top = 0;
|
2007-03-07 10:13:07 +00:00
|
|
|
bool in_stringlist, done = false;
|
2007-02-08 04:33:41 +00:00
|
|
|
menu_callback_type menu_callback = NULL;
|
|
|
|
if (start_menu == NULL)
|
|
|
|
menu = &main_menu_;
|
|
|
|
else menu = start_menu;
|
2007-02-26 08:17:07 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
gui_buttonbar_init(&buttonbar);
|
|
|
|
gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) );
|
|
|
|
gui_buttonbar_set(&buttonbar, "<<<", "", "");
|
|
|
|
gui_buttonbar_draw(&buttonbar);
|
|
|
|
#endif
|
2007-02-08 04:33:41 +00:00
|
|
|
init_menu_lists(menu,&lists,selected,true);
|
|
|
|
in_stringlist = ((menu->flags&MENU_TYPE_MASK) == MT_RETURN_ID);
|
|
|
|
|
|
|
|
talk_menu_item(menu, &lists);
|
|
|
|
|
|
|
|
gui_synclist_draw(&lists);
|
|
|
|
gui_syncstatusbar_draw(&statusbars, true);
|
|
|
|
action_signalscreenchange();
|
|
|
|
|
2007-02-21 12:22:07 +00:00
|
|
|
/* load the callback, and only reload it if menu changes */
|
|
|
|
get_menu_callback(menu, &menu_callback);
|
|
|
|
|
2007-03-07 10:13:07 +00:00
|
|
|
while (!done)
|
2007-02-08 04:33:41 +00:00
|
|
|
{
|
|
|
|
action = get_action(CONTEXT_MAINMENU,HZ);
|
|
|
|
/* HZ so the status bar redraws corectly */
|
|
|
|
if (action == ACTION_NONE)
|
|
|
|
{
|
|
|
|
gui_syncstatusbar_draw(&statusbars, true);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-02-21 12:22:07 +00:00
|
|
|
|
2007-02-08 04:33:41 +00:00
|
|
|
if (menu_callback)
|
|
|
|
{
|
2007-02-27 09:16:47 +00:00
|
|
|
int old_action = action;
|
2007-02-21 12:22:07 +00:00
|
|
|
action = menu_callback(action, menu);
|
2007-02-27 09:16:47 +00:00
|
|
|
if (action == ACTION_EXIT_AFTER_THIS_MENUITEM)
|
|
|
|
{
|
|
|
|
action = old_action;
|
|
|
|
ret = MENU_SELECTED_EXIT; /* will exit after returning
|
|
|
|
from selection */
|
|
|
|
}
|
2007-02-08 04:33:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gui_synclist_do_button(&lists,action,LIST_WRAP_UNLESS_HELD))
|
|
|
|
{
|
|
|
|
talk_menu_item(menu, &lists);
|
|
|
|
}
|
2007-04-08 01:33:01 +00:00
|
|
|
else if (action == ACTION_TREE_WPS)
|
2007-02-08 04:33:41 +00:00
|
|
|
{
|
2007-03-01 11:14:46 +00:00
|
|
|
ret = GO_TO_PREVIOUS_MUSIC;
|
2007-03-07 10:13:07 +00:00
|
|
|
done = true;
|
2007-02-08 04:33:41 +00:00
|
|
|
}
|
2007-04-08 01:33:01 +00:00
|
|
|
else if (action == ACTION_TREE_STOP)
|
2007-03-01 11:14:46 +00:00
|
|
|
{
|
2007-04-09 13:39:37 +00:00
|
|
|
list_stop_handler();
|
2007-03-01 11:14:46 +00:00
|
|
|
}
|
2007-04-12 15:28:51 +00:00
|
|
|
else if (action == ACTION_STD_CONTEXT &&
|
|
|
|
menu == &root_menu_)
|
|
|
|
{
|
|
|
|
ret = GO_TO_ROOTITEM_CONTEXT;
|
|
|
|
done = true;
|
|
|
|
}
|
2007-03-01 11:14:46 +00:00
|
|
|
else if (action == ACTION_STD_MENU)
|
|
|
|
{
|
2007-03-07 13:00:46 +00:00
|
|
|
if ((menu->flags&MENU_TYPE_MASK) == MT_OLD_MENU)
|
|
|
|
return MENU_SELECTED_EXIT;
|
2007-03-01 11:14:46 +00:00
|
|
|
if (menu != &root_menu_)
|
|
|
|
ret = GO_TO_ROOT;
|
2007-03-06 13:35:15 +00:00
|
|
|
else
|
|
|
|
ret = GO_TO_PREVIOUS;
|
2007-03-07 10:13:07 +00:00
|
|
|
done = true;
|
2007-03-01 11:14:46 +00:00
|
|
|
}
|
|
|
|
else if (action == ACTION_STD_CANCEL)
|
2007-02-08 04:33:41 +00:00
|
|
|
{
|
2007-02-16 10:40:59 +00:00
|
|
|
in_stringlist = false;
|
2007-02-21 12:22:07 +00:00
|
|
|
if (menu_callback)
|
|
|
|
menu_callback(ACTION_EXIT_MENUITEM, menu);
|
2007-02-16 10:40:59 +00:00
|
|
|
|
2007-02-08 04:33:41 +00:00
|
|
|
if (stack_top > 0)
|
|
|
|
{
|
|
|
|
stack_top--;
|
|
|
|
menu = menu_stack[stack_top];
|
|
|
|
init_menu_lists(menu, &lists,
|
|
|
|
menu_stack_selected_item[stack_top], false);
|
|
|
|
talk_menu_item(menu, &lists);
|
2007-02-21 12:22:07 +00:00
|
|
|
/* new menu, so reload the callback */
|
2007-02-16 00:55:52 +00:00
|
|
|
get_menu_callback(menu, &menu_callback);
|
2007-02-08 04:33:41 +00:00
|
|
|
}
|
2007-03-01 11:14:46 +00:00
|
|
|
else if (menu != &root_menu_)
|
|
|
|
{
|
|
|
|
ret = GO_TO_PREVIOUS;
|
2007-03-07 10:13:07 +00:00
|
|
|
done = true;
|
2007-03-01 11:14:46 +00:00
|
|
|
}
|
2007-02-08 04:33:41 +00:00
|
|
|
}
|
|
|
|
else if (action == ACTION_STD_OK)
|
|
|
|
{
|
|
|
|
int type;
|
2007-02-26 08:17:07 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
gui_buttonbar_unset(&buttonbar);
|
|
|
|
gui_buttonbar_draw(&buttonbar);
|
|
|
|
#endif
|
2007-03-07 13:00:46 +00:00
|
|
|
if ((menu->flags&MENU_TYPE_MASK) == MT_OLD_MENU)
|
|
|
|
{
|
|
|
|
selected = gui_synclist_get_sel_pos(&lists);
|
|
|
|
menus[menu->value].current_selection = selected;
|
2007-03-15 05:40:18 +00:00
|
|
|
action_signalscreenchange();
|
2007-03-07 13:00:46 +00:00
|
|
|
return selected;
|
|
|
|
}
|
2007-02-08 04:33:41 +00:00
|
|
|
selected = get_menu_selection(gui_synclist_get_sel_pos(&lists), menu);
|
|
|
|
temp = menu->submenus[selected];
|
|
|
|
if (in_stringlist)
|
|
|
|
type = (menu->flags&MENU_TYPE_MASK);
|
2007-02-08 10:28:42 +00:00
|
|
|
else
|
2007-02-08 04:33:41 +00:00
|
|
|
{
|
2007-03-25 14:31:56 +00:00
|
|
|
type = (temp->flags&MENU_TYPE_MASK);
|
|
|
|
get_menu_callback(temp, &menu_callback);
|
|
|
|
if (menu_callback)
|
|
|
|
{
|
|
|
|
action = menu_callback(ACTION_ENTER_MENUITEM,temp);
|
|
|
|
if (action == ACTION_EXIT_MENUITEM)
|
|
|
|
break;
|
|
|
|
}
|
2007-02-08 04:33:41 +00:00
|
|
|
}
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case MT_MENU:
|
|
|
|
if (stack_top < MAX_MENUS)
|
|
|
|
{
|
|
|
|
menu_stack[stack_top] = menu;
|
2007-03-01 11:14:46 +00:00
|
|
|
menu_stack_selected_item[stack_top] = selected;
|
2007-02-08 04:33:41 +00:00
|
|
|
stack_top++;
|
|
|
|
init_menu_lists(temp, &lists, 0, true);
|
|
|
|
menu = temp;
|
|
|
|
talk_menu_item(menu, &lists);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MT_FUNCTION_CALL:
|
2007-03-17 12:33:34 +00:00
|
|
|
{
|
|
|
|
int return_value;
|
2007-02-08 04:33:41 +00:00
|
|
|
action_signalscreenchange();
|
2007-03-17 12:33:34 +00:00
|
|
|
if (temp->flags&MENU_FUNC_USEPARAM)
|
|
|
|
return_value = temp->function->function_w_param(
|
|
|
|
temp->function->param);
|
|
|
|
else
|
|
|
|
return_value = temp->function->function();
|
|
|
|
if (temp->flags&MENU_FUNC_CHECK_RETVAL)
|
|
|
|
{
|
2007-03-18 07:03:43 +00:00
|
|
|
if (return_value == 1)
|
2007-03-18 06:31:33 +00:00
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
ret = return_value;
|
|
|
|
}
|
2007-03-17 12:33:34 +00:00
|
|
|
}
|
2007-02-08 04:33:41 +00:00
|
|
|
break;
|
2007-03-17 12:33:34 +00:00
|
|
|
}
|
2007-02-08 04:33:41 +00:00
|
|
|
case MT_SETTING:
|
2007-03-03 14:23:03 +00:00
|
|
|
case MT_SETTING_W_TEXT:
|
2007-02-08 04:33:41 +00:00
|
|
|
{
|
2007-02-19 02:14:51 +00:00
|
|
|
if (do_setting_from_menu(temp))
|
2007-02-26 08:17:07 +00:00
|
|
|
init_menu_lists(menu, &lists, 0, true);
|
2007-02-08 04:33:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MT_RETURN_ID:
|
|
|
|
if (in_stringlist)
|
|
|
|
{
|
|
|
|
action_signalscreenchange();
|
2007-03-18 06:31:33 +00:00
|
|
|
done = true;
|
|
|
|
ret = selected;
|
2007-02-08 04:33:41 +00:00
|
|
|
}
|
|
|
|
else if (stack_top < MAX_MENUS)
|
|
|
|
{
|
|
|
|
menu_stack[stack_top] = menu;
|
|
|
|
menu_stack_selected_item[stack_top] = selected;
|
|
|
|
stack_top++;
|
|
|
|
menu = temp;
|
|
|
|
init_menu_lists(menu,&lists,0,false);
|
|
|
|
in_stringlist = true;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-01 11:14:46 +00:00
|
|
|
case MT_RETURN_VALUE:
|
2007-03-07 10:13:07 +00:00
|
|
|
ret = temp->value;
|
|
|
|
done = true;
|
|
|
|
break;
|
2007-02-08 04:33:41 +00:00
|
|
|
}
|
|
|
|
if (type != MT_MENU && menu_callback)
|
|
|
|
menu_callback(ACTION_EXIT_MENUITEM,temp);
|
2007-03-17 14:10:51 +00:00
|
|
|
if (current_submenus_menu != menu)
|
|
|
|
init_menu_lists(menu,&lists,selected,true);
|
2007-02-21 12:22:07 +00:00
|
|
|
/* callback was changed, so reload the menu's callback */
|
|
|
|
get_menu_callback(menu, &menu_callback);
|
2007-02-26 08:17:07 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
gui_buttonbar_set(&buttonbar, "<<<", "", "");
|
|
|
|
gui_buttonbar_draw(&buttonbar);
|
|
|
|
#endif
|
2007-02-08 04:33:41 +00:00
|
|
|
}
|
|
|
|
else if(default_event_handler(action) == SYS_USB_CONNECTED)
|
2007-03-30 21:54:48 +00:00
|
|
|
{
|
2007-02-08 04:33:41 +00:00
|
|
|
ret = MENU_ATTACHED_USB;
|
2007-03-30 21:54:48 +00:00
|
|
|
done = true;
|
|
|
|
}
|
2007-02-08 04:33:41 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars, true);
|
|
|
|
gui_synclist_draw(&lists);
|
|
|
|
}
|
|
|
|
action_signalscreenchange();
|
2007-03-01 11:14:46 +00:00
|
|
|
if (start_selected)
|
2007-03-07 10:13:07 +00:00
|
|
|
*start_selected = get_menu_selection(
|
|
|
|
gui_synclist_get_sel_pos(&lists), menu);
|
2007-02-08 04:33:41 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main_menu(void)
|
|
|
|
{
|
2007-03-15 04:42:10 +00:00
|
|
|
return do_menu(NULL, 0) == MENU_ATTACHED_USB;
|
2007-02-08 04:33:41 +00:00
|
|
|
}
|
2007-03-07 13:00:46 +00:00
|
|
|
|
|
|
|
/* wrappers for the old menu system to work with the new system */
|
|
|
|
|
|
|
|
|
|
|
|
static int menu_find_free(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* Tries to find an unused slot to put the new menu */
|
|
|
|
for ( i=0; i<MAX_MENUS; i++ ) {
|
|
|
|
if ( !inuse[i] ) {
|
|
|
|
inuse[i] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( i == MAX_MENUS ) {
|
|
|
|
DEBUGF("Out of menus!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
int menu_init(const struct menu_item* mitems, int count, int (*callback)(int, int),
|
|
|
|
const char *button1, const char *button2, const char *button3)
|
|
|
|
{
|
|
|
|
int menu=menu_find_free();
|
|
|
|
if(menu==-1)/* Out of menus */
|
|
|
|
return -1;
|
|
|
|
menus[menu].items = (struct menu_item*)mitems; /* de-const */
|
|
|
|
menus[menu].count = count;
|
|
|
|
menus[menu].callback = callback;
|
|
|
|
menus[menu].current_selection = 0;
|
2007-04-08 05:52:47 +00:00
|
|
|
if ((button2 == NULL) && (button3 == NULL))
|
2007-04-08 06:15:34 +00:00
|
|
|
menus[menu].title = (char*)button1;
|
2007-04-08 05:52:47 +00:00
|
|
|
else menus[menu].title = NULL;
|
2007-03-07 13:00:46 +00:00
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_exit(int m)
|
|
|
|
{
|
|
|
|
inuse[m] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int oldmenuwrapper_callback(int action,
|
|
|
|
const struct menu_item_ex *this_item)
|
|
|
|
{
|
|
|
|
if (menus[this_item->value].callback)
|
|
|
|
{
|
|
|
|
int val = menus[this_item->value].callback(action, this_item->value);
|
|
|
|
switch (val)
|
|
|
|
{
|
|
|
|
case MENU_SELECTED_EXIT:
|
|
|
|
return ACTION_EXIT_MENUITEM;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* oldmenuwrapper_getname(int selected_item,
|
|
|
|
void * data, char *buffer)
|
|
|
|
{
|
|
|
|
(void)buffer;
|
|
|
|
unsigned char* desc = menus[(intptr_t)data].items[selected_item].desc;
|
|
|
|
return P2STR(desc);
|
|
|
|
}
|
2007-04-08 05:52:47 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-04-16 09:14:36 +00:00
|
|
|
static int oldmenu_get_icon(int selected_item, void * data)
|
2007-04-08 05:52:47 +00:00
|
|
|
{
|
2007-04-08 06:15:34 +00:00
|
|
|
(void)data; (void)selected_item;
|
2007-04-16 09:14:36 +00:00
|
|
|
return Icon_Menu_functioncall;
|
2007-04-08 05:52:47 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-07 13:00:46 +00:00
|
|
|
static void init_oldmenu(const struct menu_item_ex *menu,
|
|
|
|
struct gui_synclist *lists, int selected, bool callback)
|
|
|
|
{
|
|
|
|
(void)callback;
|
|
|
|
gui_synclist_init(lists, oldmenuwrapper_getname,
|
2007-03-08 06:30:15 +00:00
|
|
|
(void*)(intptr_t)menu->value, false, 1);
|
2007-03-18 06:31:33 +00:00
|
|
|
gui_synclist_set_nb_items(lists, MENU_GET_COUNT(menu->flags));
|
2007-03-07 13:00:46 +00:00
|
|
|
gui_synclist_limit_scroll(lists, true);
|
2007-04-08 05:52:47 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
gui_synclist_set_title(lists, menus[menu->value].title,
|
2007-04-16 09:14:36 +00:00
|
|
|
Icon_Submenu_Entered);
|
2007-04-08 05:52:47 +00:00
|
|
|
gui_synclist_set_icon_callback(lists, oldmenu_get_icon);
|
|
|
|
#endif
|
2007-04-14 00:03:09 +00:00
|
|
|
gui_synclist_select_item(lists, selected);
|
2007-03-07 13:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_talk_selected(int m)
|
|
|
|
{
|
|
|
|
int selected = menus[m].current_selection;
|
|
|
|
int voice_id = P2ID(menus[m].items[selected].desc);
|
|
|
|
if (voice_id >= 0) /* valid ID given? */
|
|
|
|
talk_id(voice_id, false); /* say it */
|
|
|
|
}
|
|
|
|
|
|
|
|
int menu_show(int m)
|
|
|
|
{
|
2007-03-18 11:01:23 +00:00
|
|
|
int value;
|
2007-03-07 13:00:46 +00:00
|
|
|
struct menu_item_ex menu;
|
|
|
|
struct menu_get_name_and_icon menu_info =
|
|
|
|
{
|
|
|
|
oldmenuwrapper_callback,
|
|
|
|
oldmenuwrapper_getname,
|
2007-04-08 05:52:47 +00:00
|
|
|
(void*)(intptr_t)m, Icon_Submenu
|
2007-03-07 13:00:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
menu.flags = (MENU_TYPE_MASK&MT_OLD_MENU) | MENU_DYNAMIC_DESC |
|
|
|
|
MENU_ITEM_COUNT(menus[m].count);
|
|
|
|
menu.value = m;
|
|
|
|
menu.menu_get_name_and_icon = &menu_info;
|
2007-03-18 11:01:23 +00:00
|
|
|
value = do_menu(&menu, &menus[m].current_selection);
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case MENU_ATTACHED_USB:
|
2007-03-27 06:38:11 +00:00
|
|
|
case GO_TO_ROOT:
|
2007-03-18 11:01:23 +00:00
|
|
|
return MENU_ATTACHED_USB;
|
|
|
|
case GO_TO_PREVIOUS:
|
|
|
|
return MENU_SELECTED_EXIT;
|
|
|
|
default:
|
2007-04-22 14:24:32 +00:00
|
|
|
if (value >= 0)
|
2007-03-18 11:01:23 +00:00
|
|
|
return menus[m].current_selection;
|
|
|
|
else return value;
|
|
|
|
}
|
2007-03-07 13:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool menu_run(int m)
|
|
|
|
{
|
|
|
|
int selected;
|
|
|
|
while (1) {
|
|
|
|
switch (selected=menu_show(m))
|
|
|
|
{
|
|
|
|
case MENU_SELECTED_EXIT:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case MENU_ATTACHED_USB:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2007-03-07 13:24:29 +00:00
|
|
|
if (selected >= 0 && selected < menus[m].count)
|
|
|
|
{
|
|
|
|
if (menus[m].items[selected].function &&
|
|
|
|
menus[m].items[selected].function())
|
|
|
|
return true;
|
|
|
|
}
|
2007-03-07 13:00:46 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Property function - return the "count" of menu items in "menu"
|
|
|
|
*/
|
|
|
|
|
|
|
|
int menu_count(int menu)
|
|
|
|
{
|
|
|
|
return menus[menu].count;
|
|
|
|
}
|
|
|
|
|