summaryrefslogtreecommitdiff
path: root/apps/menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/menu.c')
-rw-r--r--apps/menu.c71
1 files changed, 53 insertions, 18 deletions
diff --git a/apps/menu.c b/apps/menu.c
index 0081d4964d..8656c903c7 100644
--- a/apps/menu.c
+++ b/apps/menu.c
@@ -23,6 +23,7 @@
23*/ 23*/
24#include <stdbool.h> 24#include <stdbool.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include "config.h"
26 27
27#include "hwcompat.h" 28#include "hwcompat.h"
28#include "lcd.h" 29#include "lcd.h"
@@ -44,6 +45,10 @@
44#include "action.h" 45#include "action.h"
45#include "menus/exported_menus.h" 46#include "menus/exported_menus.h"
46#include "string.h" 47#include "string.h"
48#include "root_menu.h"
49#include "bookmark.h"
50#include "gwps-common.h" /* for fade() */
51#include "audio.h"
47 52
48#ifdef HAVE_LCD_BITMAP 53#ifdef HAVE_LCD_BITMAP
49#include "icons.h" 54#include "icons.h"
@@ -303,7 +308,14 @@ static int get_menu_selection(int selected_item, const struct menu_item_ex *menu
303 return current_subitems[selected_item]; 308 return current_subitems[selected_item];
304 return selected_item; 309 return selected_item;
305} 310}
306 311static int find_menu_selection(int selected)
312{
313 int i;
314 for (i=0; i< current_subitems_count; i++)
315 if (current_subitems[i] == selected)
316 return i;
317 return 0;
318}
307static char * get_menu_item_name(int selected_item,void * data, char *buffer) 319static char * get_menu_item_name(int selected_item,void * data, char *buffer)
308{ 320{
309 const struct menu_item_ex *menu = (const struct menu_item_ex *)data; 321 const struct menu_item_ex *menu = (const struct menu_item_ex *)data;
@@ -363,6 +375,7 @@ static void menu_get_icon(int selected_item, void * data, ICON * icon)
363 break; 375 break;
364 case MT_FUNCTION_CALL: 376 case MT_FUNCTION_CALL:
365 case MT_FUNCTION_WITH_PARAM: 377 case MT_FUNCTION_WITH_PARAM:
378 case MT_RETURN_VALUE:
366 if (menu_icon == NOICON) 379 if (menu_icon == NOICON)
367 *icon = bitmap_icons_6x8[Icon_Menu_functioncall]; 380 *icon = bitmap_icons_6x8[Icon_Menu_functioncall];
368 else 381 else
@@ -418,7 +431,7 @@ static void init_menu_lists(const struct menu_item_ex *menu,
418 gui_synclist_set_icon_callback(lists, NULL); 431 gui_synclist_set_icon_callback(lists, NULL);
419 gui_synclist_set_nb_items(lists,current_subitems_count); 432 gui_synclist_set_nb_items(lists,current_subitems_count);
420 gui_synclist_limit_scroll(lists,true); 433 gui_synclist_limit_scroll(lists,true);
421 gui_synclist_select_item(lists, selected); 434 gui_synclist_select_item(lists, find_menu_selection(selected));
422 435
423 get_menu_callback(menu,&menu_callback); 436 get_menu_callback(menu,&menu_callback);
424 if (callback && menu_callback) 437 if (callback && menu_callback)
@@ -434,14 +447,14 @@ static void talk_menu_item(const struct menu_item_ex *menu,
434 int sel = get_menu_selection(gui_synclist_get_sel_pos(lists),menu); 447 int sel = get_menu_selection(gui_synclist_get_sel_pos(lists),menu);
435 if ((menu->flags&MENU_TYPE_MASK) == MT_MENU) 448 if ((menu->flags&MENU_TYPE_MASK) == MT_MENU)
436 { 449 {
437 if ((menu->submenus[sel]->flags&MENU_TYPE_MASK) == MT_SETTING) 450 if ((menu->submenus[sel]->flags&MENU_TYPE_MASK) == MT_SETTING)
438 talk_setting(menu->submenus[sel]->variable); 451 talk_setting(menu->submenus[sel]->variable);
439 else 452 else
440 { 453 {
441 id = P2ID(menu->submenus[sel]->callback_and_desc->desc); 454 id = P2ID(menu->submenus[sel]->callback_and_desc->desc);
442 if (id != -1) 455 if (id != -1)
443 talk_id(id,false); 456 talk_id(id,false);
444 } 457 }
445 } 458 }
446 } 459 }
447} 460}
@@ -564,10 +577,10 @@ bool do_setting_from_menu(const struct menu_item_ex *temp)
564 return ret_val; 577 return ret_val;
565} 578}
566 579
567int do_menu(const struct menu_item_ex *start_menu) 580int do_menu(const struct menu_item_ex *start_menu, int *start_selected)
568{ 581{
582 int selected = start_selected? *start_selected : 0;
569 int action; 583 int action;
570 int selected = 0;
571 struct gui_synclist lists; 584 struct gui_synclist lists;
572 const struct menu_item_ex *temp, *menu; 585 const struct menu_item_ex *temp, *menu;
573 int ret = 0; 586 int ret = 0;
@@ -630,10 +643,24 @@ int do_menu(const struct menu_item_ex *start_menu)
630 } 643 }
631 else if (action == ACTION_MENU_WPS) 644 else if (action == ACTION_MENU_WPS)
632 { 645 {
633 ret = MENU_RETURN_TO_WPS; 646 ret = GO_TO_PREVIOUS_MUSIC;
634 } 647 }
635 else if ((action == ACTION_STD_CANCEL) || 648 else if (action == ACTION_MENU_STOP)
636 (action == ACTION_STD_MENU)) 649 {
650 if (audio_status() && !global_settings.party_mode)
651 {
652 if (global_settings.fade_on_stop)
653 fade(0);
654 bookmark_autobookmark();
655 audio_stop();
656 }
657 }
658 else if (action == ACTION_STD_MENU)
659 {
660 if (menu != &root_menu_)
661 ret = GO_TO_ROOT;
662 }
663 else if (action == ACTION_STD_CANCEL)
637 { 664 {
638 in_stringlist = false; 665 in_stringlist = false;
639 if (menu_callback) 666 if (menu_callback)
@@ -649,8 +676,11 @@ int do_menu(const struct menu_item_ex *start_menu)
649 /* new menu, so reload the callback */ 676 /* new menu, so reload the callback */
650 get_menu_callback(menu, &menu_callback); 677 get_menu_callback(menu, &menu_callback);
651 } 678 }
652 else 679 else if (menu != &root_menu_)
680 {
681 ret = GO_TO_PREVIOUS;
653 break; 682 break;
683 }
654 } 684 }
655 else if (action == ACTION_STD_OK) 685 else if (action == ACTION_STD_OK)
656 { 686 {
@@ -678,8 +708,7 @@ int do_menu(const struct menu_item_ex *start_menu)
678 if (stack_top < MAX_MENUS) 708 if (stack_top < MAX_MENUS)
679 { 709 {
680 menu_stack[stack_top] = menu; 710 menu_stack[stack_top] = menu;
681 menu_stack_selected_item[stack_top] 711 menu_stack_selected_item[stack_top] = selected;
682 = gui_synclist_get_sel_pos(&lists);
683 stack_top++; 712 stack_top++;
684 init_menu_lists(temp, &lists, 0, true); 713 init_menu_lists(temp, &lists, 0, true);
685 menu = temp; 714 menu = temp;
@@ -717,6 +746,10 @@ int do_menu(const struct menu_item_ex *start_menu)
717 in_stringlist = true; 746 in_stringlist = true;
718 } 747 }
719 break; 748 break;
749 case MT_RETURN_VALUE:
750 if (start_selected)
751 *start_selected = selected;
752 return temp->value;
720 } 753 }
721 if (type != MT_MENU && menu_callback) 754 if (type != MT_MENU && menu_callback)
722 menu_callback(ACTION_EXIT_MENUITEM,temp); 755 menu_callback(ACTION_EXIT_MENUITEM,temp);
@@ -733,10 +766,12 @@ int do_menu(const struct menu_item_ex *start_menu)
733 gui_synclist_draw(&lists); 766 gui_synclist_draw(&lists);
734 } 767 }
735 action_signalscreenchange(); 768 action_signalscreenchange();
769 if (start_selected)
770 *start_selected = selected;
736 return ret; 771 return ret;
737} 772}
738 773
739int main_menu(void) 774int main_menu(void)
740{ 775{
741 return do_menu(NULL); 776 return do_menu(NULL, 0);
742} 777}