1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
23 - Multi screen support
24 - Rewrote/removed a lot of code now useless with the new gui API
31 #include "appevents.h"
42 #include "settings_list.h"
43 #include "option_select.h"
49 #include "menus/exported_menus.h"
51 #include "root_menu.h"
54 #include "quickscreen.h"
56 #ifdef HAVE_LCD_BITMAP
62 #include "buttonbar.h"
66 const struct menu_item_ex
*selected_menu_item
;
67 bool hotkey_settable_menu
= false;
71 /* used to allow for dynamic menus */
72 #define MAX_MENU_SUBITEMS 64
73 static struct menu_item_ex
*current_submenus_menu
;
74 static int current_subitems
[MAX_MENU_SUBITEMS
];
75 static int current_subitems_count
= 0;
76 static int talk_menu_item(int selected_item
, void *data
);
78 static void get_menu_callback(const struct menu_item_ex
*m
,
79 menu_callback_type
*menu_callback
)
81 if (m
->flags
&(MENU_HAS_DESC
|MENU_DYNAMIC_DESC
))
82 *menu_callback
= m
->callback_and_desc
->menu_callback
;
84 *menu_callback
= m
->menu_callback
;
87 static int get_menu_selection(int selected_item
, const struct menu_item_ex
*menu
)
89 int type
= (menu
->flags
&MENU_TYPE_MASK
);
90 if ((type
== MT_MENU
|| type
== MT_RETURN_ID
)
91 && (selected_item
<current_subitems_count
))
92 return current_subitems
[selected_item
];
95 static int find_menu_selection(int selected
)
98 for (i
=0; i
< current_subitems_count
; i
++)
99 if (current_subitems
[i
] == selected
)
103 static const char* get_menu_item_name(int selected_item
,
108 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
109 int type
= (menu
->flags
&MENU_TYPE_MASK
);
110 selected_item
= get_menu_selection(selected_item
, menu
);
113 /* only MT_MENU or MT_RETURN_ID is allowed in here */
114 if (type
== MT_RETURN_ID
)
116 if (menu
->flags
&MENU_DYNAMIC_DESC
)
117 return menu
->menu_get_name_and_icon
->list_get_name(selected_item
,
118 menu
->menu_get_name_and_icon
->list_get_name_data
, buffer
);
119 return menu
->strings
[selected_item
];
122 menu
= menu
->submenus
[selected_item
];
124 if ((menu
->flags
&MENU_DYNAMIC_DESC
) && (type
!= MT_SETTING_W_TEXT
))
125 return menu
->menu_get_name_and_icon
->list_get_name(selected_item
,
126 menu
->menu_get_name_and_icon
->list_get_name_data
, buffer
);
128 type
= (menu
->flags
&MENU_TYPE_MASK
);
129 if ((type
== MT_SETTING
) || (type
== MT_SETTING_W_TEXT
))
131 const struct settings_list
*v
132 = find_setting(menu
->variable
, NULL
);
134 return str(v
->lang_id
);
135 else return "Not Done yet!";
137 return P2STR(menu
->callback_and_desc
->desc
);
139 #ifdef HAVE_LCD_BITMAP
140 static enum themable_icons
menu_get_icon(int selected_item
, void * data
)
142 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
143 int menu_icon
= Icon_NOICON
;
144 selected_item
= get_menu_selection(selected_item
, menu
);
146 if ((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
)
148 return Icon_Menu_functioncall
;
150 menu
= menu
->submenus
[selected_item
];
151 if (menu
->flags
&MENU_HAS_DESC
)
152 menu_icon
= menu
->callback_and_desc
->icon_id
;
153 else if (menu
->flags
&MENU_DYNAMIC_DESC
)
154 menu_icon
= menu
->menu_get_name_and_icon
->icon_id
;
157 if (hotkey_settable_menu
&& (menu
->flags
&MENU_FUNC_HOTKEYABLE
))
158 menu_icon
= Icon_Hotkey
;
161 if (menu_icon
== Icon_NOICON
)
163 switch (menu
->flags
&MENU_TYPE_MASK
)
166 case MT_SETTING_W_TEXT
:
167 menu_icon
= Icon_Menu_setting
;
170 menu_icon
= Icon_Submenu
;
172 case MT_FUNCTION_CALL
:
173 case MT_RETURN_VALUE
:
174 menu_icon
= Icon_Menu_functioncall
;
182 static void init_menu_lists(const struct menu_item_ex
*menu
,
183 struct gui_synclist
*lists
, int selected
, bool callback
,
184 struct viewport parent
[NB_SCREENS
])
186 int i
, count
= MENU_GET_COUNT(menu
->flags
);
187 int type
= (menu
->flags
&MENU_TYPE_MASK
);
188 menu_callback_type menu_callback
= NULL
;
190 current_subitems_count
= 0;
192 if (type
== MT_RETURN_ID
)
193 get_menu_callback(menu
, &menu_callback
);
195 for (i
=0; i
<count
; i
++)
197 if (type
!= MT_RETURN_ID
)
198 get_menu_callback(menu
->submenus
[i
],&menu_callback
);
201 if (menu_callback(ACTION_REQUEST_MENUITEM
,
202 type
==MT_RETURN_ID
? (void*)(intptr_t)i
: menu
->submenus
[i
])
203 != ACTION_EXIT_MENUITEM
)
205 current_subitems
[current_subitems_count
] = i
;
206 current_subitems_count
++;
211 current_subitems
[current_subitems_count
] = i
;
212 current_subitems_count
++;
215 current_submenus_menu
= (struct menu_item_ex
*)menu
;
217 gui_synclist_init(lists
,get_menu_item_name
,(void*)menu
,false,1, parent
);
218 #ifdef HAVE_LCD_BITMAP
219 if (menu
->callback_and_desc
->icon_id
== Icon_NOICON
)
220 icon
= Icon_Submenu_Entered
;
222 icon
= menu
->callback_and_desc
->icon_id
;
223 gui_synclist_set_title(lists
, P2STR(menu
->callback_and_desc
->desc
), icon
);
224 gui_synclist_set_icon_callback(lists
, global_settings
.show_icons
?menu_get_icon
:NULL
);
227 gui_synclist_set_icon_callback(lists
, NULL
);
229 if(global_settings
.talk_menu
)
230 gui_synclist_set_voice_callback(lists
, talk_menu_item
);
231 gui_synclist_set_nb_items(lists
,current_subitems_count
);
232 gui_synclist_limit_scroll(lists
,true);
233 gui_synclist_select_item(lists
, find_menu_selection(selected
));
235 get_menu_callback(menu
,&menu_callback
);
236 if (callback
&& menu_callback
)
237 menu_callback(ACTION_ENTER_MENUITEM
,menu
);
238 gui_synclist_draw(lists
);
239 gui_synclist_speak_item(lists
);
242 static int talk_menu_item(int selected_item
, void *data
)
244 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
248 int sel
= get_menu_selection(selected_item
, menu
);
250 if ((menu
->flags
&MENU_TYPE_MASK
) == MT_MENU
)
252 type
= menu
->submenus
[sel
]->flags
&MENU_TYPE_MASK
;
253 if ((type
== MT_SETTING
) || (type
== MT_SETTING_W_TEXT
))
254 talk_setting(menu
->submenus
[sel
]->variable
);
257 if (menu
->submenus
[sel
]->flags
&(MENU_DYNAMIC_DESC
))
259 int (*list_speak_item
)(int selected_item
, void * data
)
260 = menu
->submenus
[sel
]->menu_get_name_and_icon
->
263 list_speak_item(sel
, menu
->submenus
[sel
]->
264 menu_get_name_and_icon
->
269 str
= menu
->submenus
[sel
]->menu_get_name_and_icon
->
270 list_get_name(sel
, menu
->submenus
[sel
]->
271 menu_get_name_and_icon
->
272 list_get_name_data
, buffer
);
277 id
= P2ID(menu
->submenus
[sel
]->callback_and_desc
->desc
);
282 else if(((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
))
284 if ((menu
->flags
&MENU_DYNAMIC_DESC
) == 0)
286 unsigned char *s
= (unsigned char *)menu
->strings
[sel
];
287 /* string list, try to talk it if ID2P was used */
296 void do_setting_from_menu(const struct menu_item_ex
*temp
,
297 struct viewport parent
[NB_SCREENS
])
299 int setting_id
, oldval
;
300 const struct settings_list
*setting
=
301 find_setting(temp
->variable
, &setting_id
);
303 char padded_title
[MAX_PATH
];
304 int var_type
= setting
->flags
&F_T_MASK
;
305 if (var_type
== F_T_INT
|| var_type
== F_T_UINT
)
307 oldval
= *(int*)setting
->setting
;
309 else if (var_type
== F_T_BOOL
)
311 oldval
= *(bool*)setting
->setting
;
315 if ((temp
->flags
&MENU_TYPE_MASK
) == MT_SETTING_W_TEXT
)
316 title
= temp
->callback_and_desc
->desc
;
318 title
= ID2P(setting
->lang_id
);
320 /* Pad the title string by repeating it. This is needed
321 so the scroll settings title can actually be used to
323 if (setting
->flags
&F_PADTITLE
)
326 if (setting
->lang_id
== -1)
327 title
= (char*)setting
->cfg_vals
;
329 title
= P2STR((unsigned char*)title
);
331 while (i
< MAX_PATH
-1)
333 int padlen
= MIN(len
, MAX_PATH
-1-i
);
334 memcpy(&padded_title
[i
], title
, padlen
);
337 padded_title
[i
++] = ' ';
339 padded_title
[i
] = '\0';
340 title
= padded_title
;
343 option_screen((struct settings_list
*)setting
, parent
,
344 setting
->flags
&F_TEMPVAR
, title
);
348 int do_menu(const struct menu_item_ex
*start_menu
, int *start_selected
,
349 struct viewport parent
[NB_SCREENS
], bool hide_theme
)
351 int selected
= start_selected
? *start_selected
: 0;
353 struct gui_synclist lists
;
354 const struct menu_item_ex
*temp
, *menu
;
358 viewportmanager_theme_enable(i
, !hide_theme
, NULL
);
360 const struct menu_item_ex
*menu_stack
[MAX_MENUS
];
361 int menu_stack_selected_item
[MAX_MENUS
];
363 bool in_stringlist
, done
= false;
364 struct viewport
*vps
= NULL
;
365 #ifdef HAVE_BUTTONBAR
366 struct gui_buttonbar buttonbar
;
367 gui_buttonbar_init(&buttonbar
);
368 gui_buttonbar_set_display(&buttonbar
, &(screens
[SCREEN_MAIN
]) );
369 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
372 menu_callback_type menu_callback
= NULL
;
373 if (start_menu
== NULL
)
375 else menu
= start_menu
;
377 /* if hide_theme is true, assume parent has been fixed before passed into
378 * this function, e.g. with viewport_set_defaults(parent, screen) */
379 init_menu_lists(menu
, &lists
, selected
, true, parent
);
380 vps
= *(lists
.parent
);
381 in_stringlist
= ((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
);
382 /* load the callback, and only reload it if menu changes */
383 get_menu_callback(menu
, &menu_callback
);
385 #ifdef HAVE_BUTTONBAR
388 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
389 gui_buttonbar_draw(&buttonbar
);
394 redraw_lists
= false;
397 #ifdef HAVE_BUTTONBAR
398 gui_buttonbar_draw(&buttonbar
);
401 action
= get_action(CONTEXT_MAINMENU
,
402 list_do_action_timeout(&lists
, HZ
));
403 /* HZ so the status bar redraws corectly */
407 int old_action
= action
;
408 action
= menu_callback(action
, menu
);
409 if (action
== ACTION_EXIT_AFTER_THIS_MENUITEM
)
412 ret
= MENU_SELECTED_EXIT
; /* will exit after returning
415 else if (action
== ACTION_REDRAW
)
422 if (gui_synclist_do_button(&lists
, &action
, LIST_WRAP_UNLESS_HELD
))
424 if (action
== ACTION_NONE
)
426 #ifdef HAVE_QUICKSCREEN
427 else if (action
== ACTION_STD_QUICKSCREEN
)
429 quick_screen_quick(action
);
433 #ifdef HAVE_RECORDING
434 else if (action
== ACTION_STD_REC
)
436 ret
= GO_TO_RECSCREEN
;
441 else if (hotkey_settable_menu
&&
442 ((action
== ACTION_WPS_HOTKEY
) ||
443 (action
== ACTION_TREE_HOTKEY
)))
445 ret
= MENU_SELECTED_HOTKEY
;
447 selected
= get_menu_selection(gui_synclist_get_sel_pos(&lists
),menu
);
448 selected_menu_item
= menu
->submenus
[selected
];
451 else if (action
== ACTION_TREE_WPS
)
453 ret
= GO_TO_PREVIOUS_MUSIC
;
456 else if (action
== ACTION_TREE_STOP
)
458 redraw_lists
= list_stop_handler();
460 else if (action
== ACTION_STD_CONTEXT
)
462 if (menu
== &root_menu_
)
464 ret
= GO_TO_ROOTITEM_CONTEXT
;
467 else if (!in_stringlist
)
470 selected
= get_menu_selection(gui_synclist_get_sel_pos(&lists
),menu
);
471 temp
= menu
->submenus
[selected
];
472 type
= (temp
->flags
&MENU_TYPE_MASK
);
473 if ((type
== MT_SETTING_W_TEXT
|| type
== MT_SETTING
))
475 #ifdef HAVE_QUICKSCREEN
476 MENUITEM_STRINGLIST(quickscreen_able_option
,
477 ID2P(LANG_ONPLAY_MENU_TITLE
), NULL
,
478 ID2P(LANG_RESET_SETTING
),
479 ID2P(LANG_TOP_QS_ITEM
),
480 ID2P(LANG_LEFT_QS_ITEM
),
481 ID2P(LANG_BOTTOM_QS_ITEM
),
482 ID2P(LANG_RIGHT_QS_ITEM
));
484 MENUITEM_STRINGLIST(notquickscreen_able_option
,
485 ID2P(LANG_ONPLAY_MENU_TITLE
), NULL
,
486 ID2P(LANG_RESET_SETTING
));
487 const struct menu_item_ex
*menu
;
488 int menu_selection
= 0;
489 const struct settings_list
*setting
=
490 find_setting(temp
->variable
, NULL
);
491 #ifdef HAVE_QUICKSCREEN
492 if (is_setting_quickscreenable(setting
))
493 menu
= &quickscreen_able_option
;
496 menu
= ¬quickscreen_able_option
;
497 switch (do_menu(menu
, &menu_selection
, NULL
, false))
501 case 0: /* reset setting */
502 reset_setting(setting
, setting
->setting
);
504 #ifdef HAVE_QUICKSCREEN
505 case 1: /* set as top QS item */
506 set_as_qs_item(setting
, QUICKSCREEN_TOP
);
508 case 2: /* set as left QS item */
509 set_as_qs_item(setting
, QUICKSCREEN_LEFT
);
511 case 3: /* set as bottom QS item */
512 set_as_qs_item(setting
, QUICKSCREEN_BOTTOM
);
514 case 4: /* set as right QS item */
515 set_as_qs_item(setting
, QUICKSCREEN_RIGHT
);
518 } /* swicth(do_menu()) */
521 } /* else if (!in_stringlist) */
523 else if (action
== ACTION_STD_MENU
)
525 if (menu
!= &root_menu_
)
528 ret
= GO_TO_PREVIOUS
;
531 else if (action
== ACTION_STD_CANCEL
)
533 bool exiting_menu
= false;
534 in_stringlist
= false;
535 /* might be leaving list, so stop scrolling */
536 gui_synclist_scroll_stop(&lists
);
538 menu_callback(ACTION_EXIT_MENUITEM
, menu
);
540 if (menu
->flags
&MENU_EXITAFTERTHISMENU
)
542 else if ((menu
->flags
&MENU_TYPE_MASK
) == MT_MENU
)
547 menu
= menu_stack
[stack_top
];
548 if (!exiting_menu
&& (menu
->flags
&MENU_EXITAFTERTHISMENU
))
551 init_menu_lists(menu
, &lists
,
552 menu_stack_selected_item
[stack_top
], false, vps
);
553 /* new menu, so reload the callback */
554 get_menu_callback(menu
, &menu_callback
);
556 else if (menu
!= &root_menu_
)
558 ret
= GO_TO_PREVIOUS
;
562 else if (action
== ACTION_STD_OK
)
565 /* entering an item that may not be a list, so stop scrolling */
566 gui_synclist_scroll_stop(&lists
);
567 #ifdef HAVE_BUTTONBAR
570 gui_buttonbar_unset(&buttonbar
);
571 gui_buttonbar_draw(&buttonbar
);
574 selected
= get_menu_selection(gui_synclist_get_sel_pos(&lists
), menu
);
575 temp
= menu
->submenus
[selected
];
578 type
= (menu
->flags
&MENU_TYPE_MASK
);
581 type
= (temp
->flags
&MENU_TYPE_MASK
);
582 get_menu_callback(temp
, &menu_callback
);
585 action
= menu_callback(ACTION_ENTER_MENUITEM
,temp
);
586 if (action
== ACTION_EXIT_MENUITEM
)
593 if (stack_top
< MAX_MENUS
)
595 menu_stack
[stack_top
] = menu
;
596 menu_stack_selected_item
[stack_top
] = selected
;
598 init_menu_lists(temp
, &lists
, 0, true, vps
);
599 redraw_lists
= false; /* above does the redraw */
603 case MT_FUNCTION_CALL
:
606 if (temp
->flags
&MENU_FUNC_USEPARAM
)
607 return_value
= temp
->function
->function_w_param(
608 temp
->function
->param
);
610 return_value
= temp
->function
->function();
611 if (!(menu
->flags
&MENU_EXITAFTERTHISMENU
) ||
612 (temp
->flags
&MENU_EXITAFTERTHISMENU
))
614 init_menu_lists(menu
, &lists
, selected
, true, vps
);
616 if (temp
->flags
&MENU_FUNC_CHECK_RETVAL
)
618 if (return_value
!= 0)
627 case MT_SETTING_W_TEXT
:
629 do_setting_from_menu(temp
, vps
);
630 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)1); /* force a redraw */
639 else if (stack_top
< MAX_MENUS
)
641 menu_stack
[stack_top
] = menu
;
642 menu_stack_selected_item
[stack_top
] = selected
;
645 init_menu_lists(menu
,&lists
,0,false, vps
);
646 redraw_lists
= false; /* above does the redraw */
647 in_stringlist
= true;
650 case MT_RETURN_VALUE
:
658 menu_callback(ACTION_EXIT_MENUITEM
,temp
);
660 if (current_submenus_menu
!= menu
)
661 init_menu_lists(menu
,&lists
,selected
,true,vps
);
662 /* callback was changed, so reload the menu's callback */
663 get_menu_callback(menu
, &menu_callback
);
664 if ((menu
->flags
&MENU_EXITAFTERTHISMENU
) &&
665 !(temp
->flags
&MENU_EXITAFTERTHISMENU
))
670 #ifdef HAVE_BUTTONBAR
673 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
674 gui_buttonbar_draw(&buttonbar
);
678 else if(default_event_handler(action
) == SYS_USB_CONNECTED
)
680 ret
= MENU_ATTACHED_USB
;
684 if (redraw_lists
&& !done
)
687 menu_callback(ACTION_REDRAW
, menu
);
688 gui_synclist_draw(&lists
);
689 gui_synclist_speak_item(&lists
);
694 /* make sure the start_selected variable is set to
695 the selected item from the menu do_menu() was called from */
698 menu
= menu_stack
[0];
699 init_menu_lists(menu
,&lists
,menu_stack_selected_item
[0],true, vps
);
701 *start_selected
= get_menu_selection(
702 gui_synclist_get_sel_pos(&lists
), menu
);
705 viewportmanager_theme_undo(i
, false);