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
33 #include "backlight.h"
41 #include "settings_list.h"
42 #include "option_select.h"
49 #include "menus/exported_menus.h"
51 #include "root_menu.h"
53 #include "gwps-common.h" /* for fade() */
56 #include "quickscreen.h"
58 #ifdef HAVE_LCD_BITMAP
64 #include "statusbar.h"
65 #include "buttonbar.h"
68 /* used to allow for dynamic menus */
69 #define MAX_MENU_SUBITEMS 64
70 static struct menu_item_ex
*current_submenus_menu
;
71 static int current_subitems
[MAX_MENU_SUBITEMS
];
72 static int current_subitems_count
= 0;
73 static int talk_menu_item(int selected_item
, void *data
);
75 static void get_menu_callback(const struct menu_item_ex
*m
,
76 menu_callback_type
*menu_callback
)
78 if (m
->flags
&(MENU_HAS_DESC
|MENU_DYNAMIC_DESC
))
79 *menu_callback
= m
->callback_and_desc
->menu_callback
;
81 *menu_callback
= m
->menu_callback
;
84 static int get_menu_selection(int selected_item
, const struct menu_item_ex
*menu
)
86 int type
= (menu
->flags
&MENU_TYPE_MASK
);
87 if (type
== MT_MENU
&& (selected_item
<current_subitems_count
))
88 return current_subitems
[selected_item
];
91 static int find_menu_selection(int selected
)
94 for (i
=0; i
< current_subitems_count
; i
++)
95 if (current_subitems
[i
] == selected
)
99 static char * get_menu_item_name(int selected_item
,
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
);
109 /* only MT_MENU or MT_RETURN_ID is allowed in here */
110 if (type
== MT_RETURN_ID
)
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
);
115 return (char*)menu
->strings
[selected_item
];
118 menu
= menu
->submenus
[selected_item
];
120 if ((menu
->flags
&MENU_DYNAMIC_DESC
) && (type
!= MT_SETTING_W_TEXT
))
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
);
124 type
= (menu
->flags
&MENU_TYPE_MASK
);
125 if ((type
== MT_SETTING
) || (type
== MT_SETTING_W_TEXT
))
127 const struct settings_list
*v
128 = find_setting(menu
->variable
, NULL
);
130 return str(v
->lang_id
);
131 else return "Not Done yet!";
133 return P2STR(menu
->callback_and_desc
->desc
);
135 #ifdef HAVE_LCD_BITMAP
136 static int menu_get_icon(int selected_item
, void * data
)
138 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
139 int menu_icon
= Icon_NOICON
;
140 selected_item
= get_menu_selection(selected_item
, menu
);
142 if ((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
)
144 return Icon_Menu_functioncall
;
146 menu
= menu
->submenus
[selected_item
];
147 if (menu
->flags
&MENU_HAS_DESC
)
148 menu_icon
= menu
->callback_and_desc
->icon_id
;
149 else if (menu
->flags
&MENU_DYNAMIC_DESC
)
150 menu_icon
= menu
->menu_get_name_and_icon
->icon_id
;
152 if (menu_icon
== Icon_NOICON
)
154 switch (menu
->flags
&MENU_TYPE_MASK
)
157 case MT_SETTING_W_TEXT
:
158 menu_icon
= Icon_Menu_setting
;
161 menu_icon
= Icon_Submenu
;
163 case MT_FUNCTION_CALL
:
164 case MT_RETURN_VALUE
:
165 menu_icon
= Icon_Menu_functioncall
;
173 static void init_menu_lists(const struct menu_item_ex
*menu
,
174 struct gui_synclist
*lists
, int selected
, bool callback
,
175 struct viewport parent
[NB_SCREENS
])
177 int i
, count
= MENU_GET_COUNT(menu
->flags
);
178 int type
= (menu
->flags
&MENU_TYPE_MASK
);
179 menu_callback_type menu_callback
= NULL
;
181 current_subitems_count
= 0;
183 if (type
== MT_RETURN_ID
)
184 get_menu_callback(menu
, &menu_callback
);
186 for (i
=0; i
<count
; i
++)
188 if (type
!= MT_RETURN_ID
)
189 get_menu_callback(menu
->submenus
[i
],&menu_callback
);
192 if (menu_callback(ACTION_REQUEST_MENUITEM
,
193 type
==MT_RETURN_ID
? (void*)(intptr_t)i
: menu
->submenus
[i
])
194 != ACTION_EXIT_MENUITEM
)
196 current_subitems
[current_subitems_count
] = i
;
197 current_subitems_count
++;
202 current_subitems
[current_subitems_count
] = i
;
203 current_subitems_count
++;
206 current_submenus_menu
= (struct menu_item_ex
*)menu
;
208 gui_synclist_init(lists
,get_menu_item_name
,(void*)menu
,false,1, parent
);
209 #ifdef HAVE_LCD_BITMAP
210 if (menu
->callback_and_desc
->icon_id
== Icon_NOICON
)
211 icon
= Icon_Submenu_Entered
;
213 icon
= menu
->callback_and_desc
->icon_id
;
214 gui_synclist_set_title(lists
, P2STR(menu
->callback_and_desc
->desc
), icon
);
215 gui_synclist_set_icon_callback(lists
, menu_get_icon
);
218 gui_synclist_set_icon_callback(lists
, NULL
);
220 if(global_settings
.talk_menu
)
221 gui_synclist_set_voice_callback(lists
, talk_menu_item
);
222 gui_synclist_set_nb_items(lists
,current_subitems_count
);
223 gui_synclist_limit_scroll(lists
,true);
224 gui_synclist_select_item(lists
, find_menu_selection(selected
));
226 get_menu_callback(menu
,&menu_callback
);
227 if (callback
&& menu_callback
)
228 menu_callback(ACTION_ENTER_MENUITEM
,menu
);
229 gui_synclist_draw(lists
);
230 gui_synclist_speak_item(lists
);
233 static int talk_menu_item(int selected_item
, void *data
)
235 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
239 int sel
= get_menu_selection(selected_item
, menu
);
241 if ((menu
->flags
&MENU_TYPE_MASK
) == MT_MENU
)
243 type
= menu
->submenus
[sel
]->flags
&MENU_TYPE_MASK
;
244 if ((type
== MT_SETTING
) || (type
== MT_SETTING_W_TEXT
))
245 talk_setting(menu
->submenus
[sel
]->variable
);
248 if (menu
->submenus
[sel
]->flags
&(MENU_DYNAMIC_DESC
))
250 int (*list_speak_item
)(int selected_item
, void * data
)
251 = menu
->submenus
[sel
]->menu_get_name_and_icon
->
254 list_speak_item(sel
, menu
->submenus
[sel
]->
255 menu_get_name_and_icon
->
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
);
268 id
= P2ID(menu
->submenus
[sel
]->callback_and_desc
->desc
);
273 else if(((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
))
275 if ((menu
->flags
&MENU_DYNAMIC_DESC
) == 0)
277 unsigned char *s
= (unsigned char *)menu
->strings
[sel
];
278 /* string list, try to talk it if ID2P was used */
287 bool do_setting_from_menu(const struct menu_item_ex
*temp
,
288 struct viewport parent
[NB_SCREENS
])
290 int setting_id
, oldval
;
291 const struct settings_list
*setting
= find_setting(
295 char padded_title
[MAX_PATH
];
296 int var_type
= setting
->flags
&F_T_MASK
;
297 if (var_type
== F_T_INT
|| var_type
== F_T_UINT
)
299 oldval
= *(int*)setting
->setting
;
301 else if (var_type
== F_T_BOOL
)
303 oldval
= *(bool*)setting
->setting
;
307 if ((temp
->flags
&MENU_TYPE_MASK
) == MT_SETTING_W_TEXT
)
308 title
= temp
->callback_and_desc
->desc
;
310 title
= ID2P(setting
->lang_id
);
312 /* Pad the title string by repeating it. This is needed
313 so the scroll settings title can actually be used to
315 if (setting
->flags
&F_PADTITLE
)
318 if (setting
->lang_id
== -1)
319 title
= (char*)setting
->cfg_vals
;
321 title
= P2STR((unsigned char*)title
);
323 while (i
< MAX_PATH
-1)
325 int padlen
= MIN(len
, MAX_PATH
-1-i
);
326 strncpy(&padded_title
[i
], title
, padlen
);
329 padded_title
[i
++] = ' ';
331 padded_title
[i
] = '\0';
332 title
= padded_title
;
335 option_screen((struct settings_list
*)setting
, parent
,
336 setting
->flags
&F_TEMPVAR
, title
);
337 if (var_type
== F_T_INT
|| var_type
== F_T_UINT
)
339 return oldval
!= *(int*)setting
->setting
;
341 else if (var_type
== F_T_BOOL
)
343 return oldval
!= *(bool*)setting
->setting
;
349 int do_menu(const struct menu_item_ex
*start_menu
, int *start_selected
,
350 struct viewport parent
[NB_SCREENS
], bool hide_bars
)
352 int selected
= start_selected
? *start_selected
: 0;
354 struct gui_synclist lists
;
355 const struct menu_item_ex
*temp
, *menu
;
358 bool oldbars
= viewportmanager_set_statusbar(!hide_bars
);
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_bars is true, assume parent has been fixed before passed into
378 * this function, e.g. with viewport_set_defaults(parent, screen, true) */
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
);
386 #ifdef HAVE_BUTTONBAR
389 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
390 gui_buttonbar_draw(&buttonbar
);
395 redraw_lists
= false;
398 #ifdef HAVE_BUTTONBAR
399 gui_buttonbar_draw(&buttonbar
);
402 action
= get_action(CONTEXT_MAINMENU
,
403 list_do_action_timeout(&lists
, HZ
));
404 /* HZ so the status bar redraws corectly */
408 int old_action
= action
;
409 action
= menu_callback(action
, menu
);
410 if (action
== ACTION_EXIT_AFTER_THIS_MENUITEM
)
413 ret
= MENU_SELECTED_EXIT
; /* will exit after returning
416 else if (action
== ACTION_REDRAW
)
423 if (gui_synclist_do_button(&lists
, &action
, LIST_WRAP_UNLESS_HELD
))
425 if (action
== ACTION_NONE
)
427 #ifdef HAVE_QUICKSCREEN
428 else if (action
== ACTION_STD_QUICKSCREEN
)
430 quick_screen_quick(action
);
434 #ifdef HAVE_RECORDING
435 else if (action
== ACTION_STD_REC
)
437 ret
= GO_TO_RECSCREEN
;
441 else if (action
== ACTION_TREE_WPS
)
443 ret
= GO_TO_PREVIOUS_MUSIC
;
446 else if (action
== ACTION_TREE_STOP
)
448 redraw_lists
= list_stop_handler();
450 else if (action
== ACTION_STD_CONTEXT
)
452 if (menu
== &root_menu_
)
454 ret
= GO_TO_ROOTITEM_CONTEXT
;
457 else if (!in_stringlist
)
460 selected
= get_menu_selection(gui_synclist_get_sel_pos(&lists
),menu
);
461 temp
= menu
->submenus
[selected
];
462 type
= (temp
->flags
&MENU_TYPE_MASK
);
463 if ((type
== MT_SETTING_W_TEXT
|| type
== MT_SETTING
))
465 #ifdef HAVE_QUICKSCREEN
466 MENUITEM_STRINGLIST(quickscreen_able_option
,
467 ID2P(LANG_ONPLAY_MENU_TITLE
), NULL
,
468 ID2P(LANG_RESET_SETTING
),
469 ID2P(LANG_LEFT_QS_ITEM
),
470 ID2P(LANG_BOTTOM_QS_ITEM
),
471 ID2P(LANG_RIGHT_QS_ITEM
));
473 MENUITEM_STRINGLIST(notquickscreen_able_option
,
474 ID2P(LANG_ONPLAY_MENU_TITLE
), NULL
,
475 ID2P(LANG_RESET_SETTING
));
476 const struct menu_item_ex
*menu
;
477 int menu_selection
= 0;
478 const struct settings_list
*setting
=
479 find_setting(temp
->variable
, NULL
);
480 #ifdef HAVE_QUICKSCREEN
481 if (is_setting_quickscreenable(setting
))
482 menu
= &quickscreen_able_option
;
485 menu
= ¬quickscreen_able_option
;
486 switch (do_menu(menu
, &menu_selection
, NULL
, false))
490 case 0: /* reset setting */
491 reset_setting(setting
, setting
->setting
);
493 #ifdef HAVE_QUICKSCREEN
495 case 1: /* set as left QS item */
496 set_as_qs_item(setting
, QUICKSCREEN_LEFT
);
498 case 2: /* set as bottom QS item */
499 set_as_qs_item(setting
, QUICKSCREEN_BOTTOM
);
501 case 3: /* set as right QS item */
502 set_as_qs_item(setting
, QUICKSCREEN_RIGHT
);
505 } /* swicth(do_menu()) */
508 } /* else if (!in_stringlist) */
510 else if (action
== ACTION_STD_MENU
)
512 if (menu
!= &root_menu_
)
515 ret
= GO_TO_PREVIOUS
;
518 else if (action
== ACTION_STD_CANCEL
)
520 bool exiting_menu
= false;
521 in_stringlist
= false;
522 /* might be leaving list, so stop scrolling */
525 screens
[i
].stop_scroll();
528 menu_callback(ACTION_EXIT_MENUITEM
, menu
);
530 if (menu
->flags
&MENU_EXITAFTERTHISMENU
)
532 else if ((menu
->flags
&MENU_TYPE_MASK
) == MT_MENU
)
537 menu
= menu_stack
[stack_top
];
538 if (!exiting_menu
&& (menu
->flags
&MENU_EXITAFTERTHISMENU
))
541 init_menu_lists(menu
, &lists
,
542 menu_stack_selected_item
[stack_top
], false, vps
);
543 /* new menu, so reload the callback */
544 get_menu_callback(menu
, &menu_callback
);
546 else if (menu
!= &root_menu_
)
548 ret
= GO_TO_PREVIOUS
;
552 else if (action
== ACTION_STD_OK
)
555 /* entering an item that may not be a list, so stop scrolling */
558 screens
[i
].stop_scroll();
560 #ifdef HAVE_BUTTONBAR
563 gui_buttonbar_unset(&buttonbar
);
564 gui_buttonbar_draw(&buttonbar
);
567 selected
= get_menu_selection(gui_synclist_get_sel_pos(&lists
), menu
);
568 temp
= menu
->submenus
[selected
];
571 type
= (menu
->flags
&MENU_TYPE_MASK
);
574 type
= (temp
->flags
&MENU_TYPE_MASK
);
575 get_menu_callback(temp
, &menu_callback
);
578 action
= menu_callback(ACTION_ENTER_MENUITEM
,temp
);
579 if (action
== ACTION_EXIT_MENUITEM
)
586 if (stack_top
< MAX_MENUS
)
588 menu_stack
[stack_top
] = menu
;
589 menu_stack_selected_item
[stack_top
] = selected
;
591 init_menu_lists(temp
, &lists
, 0, true, vps
);
592 redraw_lists
= false; /* above does the redraw */
596 case MT_FUNCTION_CALL
:
599 if (temp
->flags
&MENU_FUNC_USEPARAM
)
600 return_value
= temp
->function
->function_w_param(
601 temp
->function
->param
);
603 return_value
= temp
->function
->function();
604 if (!(menu
->flags
&MENU_EXITAFTERTHISMENU
) ||
605 (temp
->flags
&MENU_EXITAFTERTHISMENU
))
607 init_menu_lists(menu
, &lists
, selected
, true, vps
);
609 if (temp
->flags
&MENU_FUNC_CHECK_RETVAL
)
611 if (return_value
!= 0)
620 case MT_SETTING_W_TEXT
:
622 if (do_setting_from_menu(temp
, vps
))
624 init_menu_lists(menu
, &lists
, selected
, true,vps
);
625 redraw_lists
= false; /* above does the redraw */
635 else if (stack_top
< MAX_MENUS
)
637 menu_stack
[stack_top
] = menu
;
638 menu_stack_selected_item
[stack_top
] = selected
;
641 init_menu_lists(menu
,&lists
,0,false, vps
);
642 redraw_lists
= false; /* above does the redraw */
643 in_stringlist
= true;
646 case MT_RETURN_VALUE
:
654 menu_callback(ACTION_EXIT_MENUITEM
,temp
);
656 if (current_submenus_menu
!= menu
)
657 init_menu_lists(menu
,&lists
,selected
,true,vps
);
658 /* callback was changed, so reload the menu's callback */
659 get_menu_callback(menu
, &menu_callback
);
660 if ((menu
->flags
&MENU_EXITAFTERTHISMENU
) &&
661 !(temp
->flags
&MENU_EXITAFTERTHISMENU
))
666 #ifdef HAVE_BUTTONBAR
669 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
670 gui_buttonbar_draw(&buttonbar
);
674 else if(default_event_handler(action
) == SYS_USB_CONNECTED
)
676 ret
= MENU_ATTACHED_USB
;
680 if (redraw_lists
&& !done
)
683 menu_callback(ACTION_REDRAW
, menu
);
684 gui_synclist_draw(&lists
);
685 gui_synclist_speak_item(&lists
);
690 /* make sure the start_selected variable is set to
691 the selected item from the menu do_menu() was called from */
694 menu
= menu_stack
[0];
695 init_menu_lists(menu
,&lists
,menu_stack_selected_item
[0],true, vps
);
697 *start_selected
= get_menu_selection(
698 gui_synclist_get_sel_pos(&lists
), menu
);
700 viewportmanager_set_statusbar(oldbars
);