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
40 #include "settings_list.h"
41 #include "option_select.h"
47 #include "menus/exported_menus.h"
49 #include "root_menu.h"
51 #include "gwps-common.h" /* for fade() */
54 #include "quickscreen.h"
56 #ifdef HAVE_LCD_BITMAP
62 #include "buttonbar.h"
65 /* used to allow for dynamic menus */
66 #define MAX_MENU_SUBITEMS 64
67 static struct menu_item_ex
*current_submenus_menu
;
68 static int current_subitems
[MAX_MENU_SUBITEMS
];
69 static int current_subitems_count
= 0;
70 static int talk_menu_item(int selected_item
, void *data
);
72 static void get_menu_callback(const struct menu_item_ex
*m
,
73 menu_callback_type
*menu_callback
)
75 if (m
->flags
&(MENU_HAS_DESC
|MENU_DYNAMIC_DESC
))
76 *menu_callback
= m
->callback_and_desc
->menu_callback
;
78 *menu_callback
= m
->menu_callback
;
81 static int get_menu_selection(int selected_item
, const struct menu_item_ex
*menu
)
83 int type
= (menu
->flags
&MENU_TYPE_MASK
);
84 if ((type
== MT_MENU
|| type
== MT_RETURN_ID
)
85 && (selected_item
<current_subitems_count
))
86 return current_subitems
[selected_item
];
89 static int find_menu_selection(int selected
)
92 for (i
=0; i
< current_subitems_count
; i
++)
93 if (current_subitems
[i
] == selected
)
97 static char * get_menu_item_name(int selected_item
,
102 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
103 int type
= (menu
->flags
&MENU_TYPE_MASK
);
104 selected_item
= get_menu_selection(selected_item
, menu
);
107 /* only MT_MENU or MT_RETURN_ID is allowed in here */
108 if (type
== MT_RETURN_ID
)
110 if (menu
->flags
&MENU_DYNAMIC_DESC
)
111 return menu
->menu_get_name_and_icon
->list_get_name(selected_item
,
112 menu
->menu_get_name_and_icon
->list_get_name_data
, buffer
);
113 return (char*)menu
->strings
[selected_item
];
116 menu
= menu
->submenus
[selected_item
];
118 if ((menu
->flags
&MENU_DYNAMIC_DESC
) && (type
!= MT_SETTING_W_TEXT
))
119 return menu
->menu_get_name_and_icon
->list_get_name(selected_item
,
120 menu
->menu_get_name_and_icon
->list_get_name_data
, buffer
);
122 type
= (menu
->flags
&MENU_TYPE_MASK
);
123 if ((type
== MT_SETTING
) || (type
== MT_SETTING_W_TEXT
))
125 const struct settings_list
*v
126 = find_setting(menu
->variable
, NULL
);
128 return str(v
->lang_id
);
129 else return "Not Done yet!";
131 return P2STR(menu
->callback_and_desc
->desc
);
133 #ifdef HAVE_LCD_BITMAP
134 static enum themable_icons
menu_get_icon(int selected_item
, void * data
)
136 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
137 int menu_icon
= Icon_NOICON
;
138 selected_item
= get_menu_selection(selected_item
, menu
);
140 if ((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
)
142 return Icon_Menu_functioncall
;
144 menu
= menu
->submenus
[selected_item
];
145 if (menu
->flags
&MENU_HAS_DESC
)
146 menu_icon
= menu
->callback_and_desc
->icon_id
;
147 else if (menu
->flags
&MENU_DYNAMIC_DESC
)
148 menu_icon
= menu
->menu_get_name_and_icon
->icon_id
;
150 if (menu_icon
== Icon_NOICON
)
152 switch (menu
->flags
&MENU_TYPE_MASK
)
155 case MT_SETTING_W_TEXT
:
156 menu_icon
= Icon_Menu_setting
;
159 menu_icon
= Icon_Submenu
;
161 case MT_FUNCTION_CALL
:
162 case MT_RETURN_VALUE
:
163 menu_icon
= Icon_Menu_functioncall
;
171 static void init_menu_lists(const struct menu_item_ex
*menu
,
172 struct gui_synclist
*lists
, int selected
, bool callback
,
173 struct viewport parent
[NB_SCREENS
])
175 int i
, count
= MENU_GET_COUNT(menu
->flags
);
176 int type
= (menu
->flags
&MENU_TYPE_MASK
);
177 menu_callback_type menu_callback
= NULL
;
179 current_subitems_count
= 0;
181 if (type
== MT_RETURN_ID
)
182 get_menu_callback(menu
, &menu_callback
);
184 for (i
=0; i
<count
; i
++)
186 if (type
!= MT_RETURN_ID
)
187 get_menu_callback(menu
->submenus
[i
],&menu_callback
);
190 if (menu_callback(ACTION_REQUEST_MENUITEM
,
191 type
==MT_RETURN_ID
? (void*)(intptr_t)i
: menu
->submenus
[i
])
192 != ACTION_EXIT_MENUITEM
)
194 current_subitems
[current_subitems_count
] = i
;
195 current_subitems_count
++;
200 current_subitems
[current_subitems_count
] = i
;
201 current_subitems_count
++;
204 current_submenus_menu
= (struct menu_item_ex
*)menu
;
206 gui_synclist_init(lists
,get_menu_item_name
,(void*)menu
,false,1, parent
);
207 #ifdef HAVE_LCD_BITMAP
208 if (menu
->callback_and_desc
->icon_id
== Icon_NOICON
)
209 icon
= Icon_Submenu_Entered
;
211 icon
= menu
->callback_and_desc
->icon_id
;
212 gui_synclist_set_title(lists
, P2STR(menu
->callback_and_desc
->desc
), icon
);
213 gui_synclist_set_icon_callback(lists
, menu_get_icon
);
216 gui_synclist_set_icon_callback(lists
, NULL
);
218 if(global_settings
.talk_menu
)
219 gui_synclist_set_voice_callback(lists
, talk_menu_item
);
220 gui_synclist_set_nb_items(lists
,current_subitems_count
);
221 gui_synclist_limit_scroll(lists
,true);
222 gui_synclist_select_item(lists
, find_menu_selection(selected
));
224 get_menu_callback(menu
,&menu_callback
);
225 if (callback
&& menu_callback
)
226 menu_callback(ACTION_ENTER_MENUITEM
,menu
);
227 gui_synclist_draw(lists
);
228 gui_synclist_speak_item(lists
);
231 static int talk_menu_item(int selected_item
, void *data
)
233 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
237 int sel
= get_menu_selection(selected_item
, menu
);
239 if ((menu
->flags
&MENU_TYPE_MASK
) == MT_MENU
)
241 type
= menu
->submenus
[sel
]->flags
&MENU_TYPE_MASK
;
242 if ((type
== MT_SETTING
) || (type
== MT_SETTING_W_TEXT
))
243 talk_setting(menu
->submenus
[sel
]->variable
);
246 if (menu
->submenus
[sel
]->flags
&(MENU_DYNAMIC_DESC
))
248 int (*list_speak_item
)(int selected_item
, void * data
)
249 = menu
->submenus
[sel
]->menu_get_name_and_icon
->
252 list_speak_item(sel
, menu
->submenus
[sel
]->
253 menu_get_name_and_icon
->
258 str
= menu
->submenus
[sel
]->menu_get_name_and_icon
->
259 list_get_name(sel
, menu
->submenus
[sel
]->
260 menu_get_name_and_icon
->
261 list_get_name_data
, buffer
);
266 id
= P2ID(menu
->submenus
[sel
]->callback_and_desc
->desc
);
271 else if(((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
))
273 if ((menu
->flags
&MENU_DYNAMIC_DESC
) == 0)
275 unsigned char *s
= (unsigned char *)menu
->strings
[sel
];
276 /* string list, try to talk it if ID2P was used */
285 void do_setting_from_menu(const struct menu_item_ex
*temp
,
286 struct viewport parent
[NB_SCREENS
])
288 int setting_id
, oldval
;
289 const struct settings_list
*setting
= find_setting(
293 char padded_title
[MAX_PATH
];
294 int var_type
= setting
->flags
&F_T_MASK
;
295 if (var_type
== F_T_INT
|| var_type
== F_T_UINT
)
297 oldval
= *(int*)setting
->setting
;
299 else if (var_type
== F_T_BOOL
)
301 oldval
= *(bool*)setting
->setting
;
305 if ((temp
->flags
&MENU_TYPE_MASK
) == MT_SETTING_W_TEXT
)
306 title
= temp
->callback_and_desc
->desc
;
308 title
= ID2P(setting
->lang_id
);
310 /* Pad the title string by repeating it. This is needed
311 so the scroll settings title can actually be used to
313 if (setting
->flags
&F_PADTITLE
)
316 if (setting
->lang_id
== -1)
317 title
= (char*)setting
->cfg_vals
;
319 title
= P2STR((unsigned char*)title
);
321 while (i
< MAX_PATH
-1)
323 int padlen
= MIN(len
, MAX_PATH
-1-i
);
324 strncpy(&padded_title
[i
], title
, padlen
);
327 padded_title
[i
++] = ' ';
329 padded_title
[i
] = '\0';
330 title
= padded_title
;
333 option_screen((struct settings_list
*)setting
, parent
,
334 setting
->flags
&F_TEMPVAR
, title
);
338 int do_menu(const struct menu_item_ex
*start_menu
, int *start_selected
,
339 struct viewport parent
[NB_SCREENS
], bool hide_bars
)
341 int selected
= start_selected
? *start_selected
: 0;
343 struct gui_synclist lists
;
344 const struct menu_item_ex
*temp
, *menu
;
347 int oldbars
= viewportmanager_set_statusbar(
348 hide_bars
? VP_SB_HIDE_ALL
: VP_SB_ALLSCREENS
);
350 const struct menu_item_ex
*menu_stack
[MAX_MENUS
];
351 int menu_stack_selected_item
[MAX_MENUS
];
353 bool in_stringlist
, done
= false;
354 struct viewport
*vps
= NULL
;
355 #ifdef HAVE_BUTTONBAR
356 struct gui_buttonbar buttonbar
;
357 gui_buttonbar_init(&buttonbar
);
358 gui_buttonbar_set_display(&buttonbar
, &(screens
[SCREEN_MAIN
]) );
359 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
362 menu_callback_type menu_callback
= NULL
;
363 if (start_menu
== NULL
)
365 else menu
= start_menu
;
367 /* if hide_bars is true, assume parent has been fixed before passed into
368 * this function, e.g. with viewport_set_defaults(parent, screen) */
369 init_menu_lists(menu
, &lists
, selected
, true, parent
);
370 vps
= *(lists
.parent
);
371 in_stringlist
= ((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
);
372 /* load the callback, and only reload it if menu changes */
373 get_menu_callback(menu
, &menu_callback
);
376 #ifdef HAVE_BUTTONBAR
379 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
380 gui_buttonbar_draw(&buttonbar
);
385 redraw_lists
= false;
388 #ifdef HAVE_BUTTONBAR
389 gui_buttonbar_draw(&buttonbar
);
392 action
= get_action(CONTEXT_MAINMENU
,
393 list_do_action_timeout(&lists
, HZ
));
394 /* HZ so the status bar redraws corectly */
398 int old_action
= action
;
399 action
= menu_callback(action
, menu
);
400 if (action
== ACTION_EXIT_AFTER_THIS_MENUITEM
)
403 ret
= MENU_SELECTED_EXIT
; /* will exit after returning
406 else if (action
== ACTION_REDRAW
)
413 if (gui_synclist_do_button(&lists
, &action
, LIST_WRAP_UNLESS_HELD
))
415 if (action
== ACTION_NONE
)
417 #ifdef HAVE_QUICKSCREEN
418 else if (action
== ACTION_STD_QUICKSCREEN
)
420 quick_screen_quick(action
);
424 #ifdef HAVE_RECORDING
425 else if (action
== ACTION_STD_REC
)
427 ret
= GO_TO_RECSCREEN
;
431 else if (action
== ACTION_TREE_WPS
)
433 ret
= GO_TO_PREVIOUS_MUSIC
;
436 else if (action
== ACTION_TREE_STOP
)
438 redraw_lists
= list_stop_handler();
440 else if (action
== ACTION_STD_CONTEXT
)
442 if (menu
== &root_menu_
)
444 ret
= GO_TO_ROOTITEM_CONTEXT
;
447 else if (!in_stringlist
)
450 selected
= get_menu_selection(gui_synclist_get_sel_pos(&lists
),menu
);
451 temp
= menu
->submenus
[selected
];
452 type
= (temp
->flags
&MENU_TYPE_MASK
);
453 if ((type
== MT_SETTING_W_TEXT
|| type
== MT_SETTING
))
455 #ifdef HAVE_QUICKSCREEN
456 MENUITEM_STRINGLIST(quickscreen_able_option
,
457 ID2P(LANG_ONPLAY_MENU_TITLE
), NULL
,
458 ID2P(LANG_RESET_SETTING
),
459 ID2P(LANG_LEFT_QS_ITEM
),
460 ID2P(LANG_BOTTOM_QS_ITEM
),
461 ID2P(LANG_RIGHT_QS_ITEM
));
463 MENUITEM_STRINGLIST(notquickscreen_able_option
,
464 ID2P(LANG_ONPLAY_MENU_TITLE
), NULL
,
465 ID2P(LANG_RESET_SETTING
));
466 const struct menu_item_ex
*menu
;
467 int menu_selection
= 0;
468 const struct settings_list
*setting
=
469 find_setting(temp
->variable
, NULL
);
470 #ifdef HAVE_QUICKSCREEN
471 if (is_setting_quickscreenable(setting
))
472 menu
= &quickscreen_able_option
;
475 menu
= ¬quickscreen_able_option
;
476 switch (do_menu(menu
, &menu_selection
, NULL
, false))
480 case 0: /* reset setting */
481 reset_setting(setting
, setting
->setting
);
483 #ifdef HAVE_QUICKSCREEN
485 case 1: /* set as left QS item */
486 set_as_qs_item(setting
, QUICKSCREEN_LEFT
);
488 case 2: /* set as bottom QS item */
489 set_as_qs_item(setting
, QUICKSCREEN_BOTTOM
);
491 case 3: /* set as right QS item */
492 set_as_qs_item(setting
, QUICKSCREEN_RIGHT
);
495 } /* swicth(do_menu()) */
498 } /* else if (!in_stringlist) */
500 else if (action
== ACTION_STD_MENU
)
502 if (menu
!= &root_menu_
)
505 ret
= GO_TO_PREVIOUS
;
508 else if (action
== ACTION_STD_CANCEL
)
510 bool exiting_menu
= false;
511 in_stringlist
= false;
512 /* might be leaving list, so stop scrolling */
515 screens
[i
].stop_scroll();
518 menu_callback(ACTION_EXIT_MENUITEM
, menu
);
520 if (menu
->flags
&MENU_EXITAFTERTHISMENU
)
522 else if ((menu
->flags
&MENU_TYPE_MASK
) == MT_MENU
)
527 menu
= menu_stack
[stack_top
];
528 if (!exiting_menu
&& (menu
->flags
&MENU_EXITAFTERTHISMENU
))
531 init_menu_lists(menu
, &lists
,
532 menu_stack_selected_item
[stack_top
], false, vps
);
533 /* new menu, so reload the callback */
534 get_menu_callback(menu
, &menu_callback
);
536 else if (menu
!= &root_menu_
)
538 ret
= GO_TO_PREVIOUS
;
542 else if (action
== ACTION_STD_OK
)
545 /* entering an item that may not be a list, so stop scrolling */
548 screens
[i
].stop_scroll();
550 #ifdef HAVE_BUTTONBAR
553 gui_buttonbar_unset(&buttonbar
);
554 gui_buttonbar_draw(&buttonbar
);
557 selected
= get_menu_selection(gui_synclist_get_sel_pos(&lists
), menu
);
558 temp
= menu
->submenus
[selected
];
561 type
= (menu
->flags
&MENU_TYPE_MASK
);
564 type
= (temp
->flags
&MENU_TYPE_MASK
);
565 get_menu_callback(temp
, &menu_callback
);
568 action
= menu_callback(ACTION_ENTER_MENUITEM
,temp
);
569 if (action
== ACTION_EXIT_MENUITEM
)
576 if (stack_top
< MAX_MENUS
)
578 menu_stack
[stack_top
] = menu
;
579 menu_stack_selected_item
[stack_top
] = selected
;
581 init_menu_lists(temp
, &lists
, 0, true, vps
);
582 redraw_lists
= false; /* above does the redraw */
586 case MT_FUNCTION_CALL
:
589 if (temp
->flags
&MENU_FUNC_USEPARAM
)
590 return_value
= temp
->function
->function_w_param(
591 temp
->function
->param
);
593 return_value
= temp
->function
->function();
594 if (!(menu
->flags
&MENU_EXITAFTERTHISMENU
) ||
595 (temp
->flags
&MENU_EXITAFTERTHISMENU
))
597 init_menu_lists(menu
, &lists
, selected
, true, vps
);
599 if (temp
->flags
&MENU_FUNC_CHECK_RETVAL
)
601 if (return_value
!= 0)
610 case MT_SETTING_W_TEXT
:
612 do_setting_from_menu(temp
, vps
);
621 else if (stack_top
< MAX_MENUS
)
623 menu_stack
[stack_top
] = menu
;
624 menu_stack_selected_item
[stack_top
] = selected
;
627 init_menu_lists(menu
,&lists
,0,false, vps
);
628 redraw_lists
= false; /* above does the redraw */
629 in_stringlist
= true;
632 case MT_RETURN_VALUE
:
640 menu_callback(ACTION_EXIT_MENUITEM
,temp
);
642 if (current_submenus_menu
!= menu
)
643 init_menu_lists(menu
,&lists
,selected
,true,vps
);
644 /* callback was changed, so reload the menu's callback */
645 get_menu_callback(menu
, &menu_callback
);
646 if ((menu
->flags
&MENU_EXITAFTERTHISMENU
) &&
647 !(temp
->flags
&MENU_EXITAFTERTHISMENU
))
652 #ifdef HAVE_BUTTONBAR
655 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
656 gui_buttonbar_draw(&buttonbar
);
660 else if(default_event_handler(action
) == SYS_USB_CONNECTED
)
662 ret
= MENU_ATTACHED_USB
;
666 if (redraw_lists
&& !done
)
669 menu_callback(ACTION_REDRAW
, menu
);
670 gui_synclist_draw(&lists
);
671 gui_synclist_speak_item(&lists
);
676 /* make sure the start_selected variable is set to
677 the selected item from the menu do_menu() was called from */
680 menu
= menu_stack
[0];
681 init_menu_lists(menu
,&lists
,menu_stack_selected_item
[0],true, vps
);
683 *start_selected
= get_menu_selection(
684 gui_synclist_get_sel_pos(&lists
), menu
);
686 viewportmanager_set_statusbar(oldbars
);