summaryrefslogtreecommitdiff
path: root/apps/menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/menu.c')
-rw-r--r--apps/menu.c114
1 files changed, 88 insertions, 26 deletions
diff --git a/apps/menu.c b/apps/menu.c
index 2c2e4ab0d0..d970ac8861 100644
--- a/apps/menu.c
+++ b/apps/menu.c
@@ -50,6 +50,7 @@
50#include "bookmark.h" 50#include "bookmark.h"
51#include "gwps-common.h" /* for fade() */ 51#include "gwps-common.h" /* for fade() */
52#include "audio.h" 52#include "audio.h"
53#include "viewport.h"
53 54
54#ifdef HAVE_LCD_BITMAP 55#ifdef HAVE_LCD_BITMAP
55#include "icons.h" 56#include "icons.h"
@@ -164,7 +165,8 @@ static int menu_get_icon(int selected_item, void * data)
164#endif 165#endif
165 166
166static void init_menu_lists(const struct menu_item_ex *menu, 167static void init_menu_lists(const struct menu_item_ex *menu,
167 struct gui_synclist *lists, int selected, bool callback) 168 struct gui_synclist *lists, int selected, bool callback,
169 struct viewport parent[NB_SCREENS])
168{ 170{
169 int i, count = MENU_GET_COUNT(menu->flags); 171 int i, count = MENU_GET_COUNT(menu->flags);
170 int type = (menu->flags&MENU_TYPE_MASK); 172 int type = (menu->flags&MENU_TYPE_MASK);
@@ -197,7 +199,7 @@ static void init_menu_lists(const struct menu_item_ex *menu,
197 } 199 }
198 current_submenus_menu = (struct menu_item_ex *)menu; 200 current_submenus_menu = (struct menu_item_ex *)menu;
199 201
200 gui_synclist_init(lists,get_menu_item_name,(void*)menu,false,1); 202 gui_synclist_init(lists,get_menu_item_name,(void*)menu,false,1, parent);
201#ifdef HAVE_LCD_BITMAP 203#ifdef HAVE_LCD_BITMAP
202 if (menu->callback_and_desc->icon_id == Icon_NOICON) 204 if (menu->callback_and_desc->icon_id == Icon_NOICON)
203 icon = Icon_Submenu_Entered; 205 icon = Icon_Submenu_Entered;
@@ -275,6 +277,29 @@ static int talk_menu_item(int selected_item, void *data)
275 } 277 }
276 return 0; 278 return 0;
277} 279}
280/* this is used to reload the default menu viewports when the
281 theme changes. nothing happens if the menu is using a supplied parent vp */
282void init_default_menu_viewports(struct viewport parent[NB_SCREENS], bool hide_bars)
283{
284 int i;
285 FOR_NB_SCREENS(i)
286 {
287 viewport_set_defaults(&parent[i], i);
288 /* viewport_set_defaults() fixes the vp for the bars, so resize */
289 if (hide_bars)
290 {
291 if (global_settings.statusbar)
292 {
293 parent[i].y -= STATUSBAR_HEIGHT;
294 parent[i].height += STATUSBAR_HEIGHT;
295 }
296 }
297 }
298#ifdef HAS_BUTTONBAR
299 if (!hide_bars)
300 parent[0].height -= BUTTONBAR_HEIGHT;
301#endif
302}
278 303
279bool do_setting_from_menu(const struct menu_item_ex *temp) 304bool do_setting_from_menu(const struct menu_item_ex *temp)
280{ 305{
@@ -318,42 +343,71 @@ bool do_setting_from_menu(const struct menu_item_ex *temp)
318} 343}
319 344
320/* display a menu */ 345/* display a menu */
321int do_menu(const struct menu_item_ex *start_menu, int *start_selected) 346int do_menu(const struct menu_item_ex *start_menu, int *start_selected,
347 struct viewport parent[NB_SCREENS], bool hide_bars)
322{ 348{
323 int selected = start_selected? *start_selected : 0; 349 int selected = start_selected? *start_selected : 0;
324 int action; 350 int action;
325 struct gui_synclist lists; 351 struct gui_synclist lists;
326 const struct menu_item_ex *temp, *menu; 352 const struct menu_item_ex *temp, *menu;
327 int ret = 0; 353 int ret = 0, i;
328 bool redraw_lists; 354 bool redraw_lists;
329#ifdef HAS_BUTTONBAR 355
330 struct gui_buttonbar buttonbar;
331#endif
332
333 const struct menu_item_ex *menu_stack[MAX_MENUS]; 356 const struct menu_item_ex *menu_stack[MAX_MENUS];
334 int menu_stack_selected_item[MAX_MENUS]; 357 int menu_stack_selected_item[MAX_MENUS];
335 int stack_top = 0; 358 int stack_top = 0;
336 bool in_stringlist, done = false; 359 bool in_stringlist, done = false;
337 menu_callback_type menu_callback = NULL; 360
338 if (start_menu == NULL) 361 struct viewport *vps, menu_vp[NB_SCREENS]; /* menu_vp will hopefully be phased out */
339 menu = &main_menu_;
340 else menu = start_menu;
341#ifdef HAS_BUTTONBAR 362#ifdef HAS_BUTTONBAR
363 struct gui_buttonbar buttonbar;
342 gui_buttonbar_init(&buttonbar); 364 gui_buttonbar_init(&buttonbar);
343 gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) ); 365 gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) );
344 gui_buttonbar_set(&buttonbar, "<<<", "", ""); 366 gui_buttonbar_set(&buttonbar, "<<<", "", "");
345 gui_buttonbar_draw(&buttonbar);
346#endif 367#endif
347 init_menu_lists(menu,&lists,selected,true); 368
369 menu_callback_type menu_callback = NULL;
370 if (start_menu == NULL)
371 menu = &main_menu_;
372 else menu = start_menu;
373
374 if (parent)
375 {
376 vps = parent;
377 /* if hide_bars == true we assume the viewport is correctly sized */
378 }
379 else
380 {
381 vps = menu_vp;
382 init_default_menu_viewports(vps, hide_bars);
383 }
384 FOR_NB_SCREENS(i)
385 {
386 screens[i].set_viewport(&vps[i]);
387 screens[i].clear_viewport();
388 screens[i].set_viewport(NULL);
389 }
390 init_menu_lists(menu, &lists, selected, true, vps);
348 in_stringlist = ((menu->flags&MENU_TYPE_MASK) == MT_RETURN_ID); 391 in_stringlist = ((menu->flags&MENU_TYPE_MASK) == MT_RETURN_ID);
349 392
350 /* load the callback, and only reload it if menu changes */ 393 /* load the callback, and only reload it if menu changes */
351 get_menu_callback(menu, &menu_callback); 394 get_menu_callback(menu, &menu_callback);
352 395
396
397#ifdef HAS_BUTTONBAR
398 if (!hide_bars)
399 {
400 gui_buttonbar_set(&buttonbar, "<<<", "", "");
401 gui_buttonbar_draw(&buttonbar);
402 }
403#endif
353 while (!done) 404 while (!done)
354 { 405 {
355 redraw_lists = false; 406 redraw_lists = false;
356 gui_syncstatusbar_draw(&statusbars, true); 407 if (!hide_bars)
408 {
409 gui_syncstatusbar_draw(&statusbars, true);
410 }
357 action = get_action(CONTEXT_MAINMENU, 411 action = get_action(CONTEXT_MAINMENU,
358 list_do_action_timeout(&lists, HZ)); 412 list_do_action_timeout(&lists, HZ));
359 /* HZ so the status bar redraws corectly */ 413 /* HZ so the status bar redraws corectly */
@@ -430,7 +484,7 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected)
430 done = true; 484 done = true;
431 else 485 else
432 init_menu_lists(menu, &lists, 486 init_menu_lists(menu, &lists,
433 menu_stack_selected_item[stack_top], false); 487 menu_stack_selected_item[stack_top], false, vps);
434 /* new menu, so reload the callback */ 488 /* new menu, so reload the callback */
435 get_menu_callback(menu, &menu_callback); 489 get_menu_callback(menu, &menu_callback);
436 } 490 }
@@ -444,8 +498,11 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected)
444 { 498 {
445 int type; 499 int type;
446#ifdef HAS_BUTTONBAR 500#ifdef HAS_BUTTONBAR
447 gui_buttonbar_unset(&buttonbar); 501 if (!hide_bars)
448 gui_buttonbar_draw(&buttonbar); 502 {
503 gui_buttonbar_unset(&buttonbar);
504 gui_buttonbar_draw(&buttonbar);
505 }
449#endif 506#endif
450 selected = get_menu_selection(gui_synclist_get_sel_pos(&lists), menu); 507 selected = get_menu_selection(gui_synclist_get_sel_pos(&lists), menu);
451 temp = menu->submenus[selected]; 508 temp = menu->submenus[selected];
@@ -471,7 +528,7 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected)
471 menu_stack[stack_top] = menu; 528 menu_stack[stack_top] = menu;
472 menu_stack_selected_item[stack_top] = selected; 529 menu_stack_selected_item[stack_top] = selected;
473 stack_top++; 530 stack_top++;
474 init_menu_lists(temp, &lists, 0, true); 531 init_menu_lists(temp, &lists, 0, true, vps);
475 redraw_lists = false; /* above does the redraw */ 532 redraw_lists = false; /* above does the redraw */
476 menu = temp; 533 menu = temp;
477 } 534 }
@@ -491,8 +548,9 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected)
491 if (temp->flags&MENU_HAS_DESC && 548 if (temp->flags&MENU_HAS_DESC &&
492 temp->callback_and_desc->desc == ID2P(LANG_LANGUAGE)) 549 temp->callback_and_desc->desc == ID2P(LANG_LANGUAGE))
493 { 550 {
494 init_menu_lists(menu, &lists, selected, true); 551 init_menu_lists(menu, &lists, selected, true, vps);
495 } 552 }
553 init_default_menu_viewports(menu_vp, hide_bars);
496 554
497 if (temp->flags&MENU_FUNC_CHECK_RETVAL) 555 if (temp->flags&MENU_FUNC_CHECK_RETVAL)
498 { 556 {
@@ -509,7 +567,8 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected)
509 { 567 {
510 if (do_setting_from_menu(temp)) 568 if (do_setting_from_menu(temp))
511 { 569 {
512 init_menu_lists(menu, &lists, selected, true); 570 init_default_menu_viewports(menu_vp, hide_bars);
571 init_menu_lists(menu, &lists, selected, true,vps);
513 redraw_lists = false; /* above does the redraw */ 572 redraw_lists = false; /* above does the redraw */
514 } 573 }
515 break; 574 break;
@@ -526,7 +585,7 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected)
526 menu_stack_selected_item[stack_top] = selected; 585 menu_stack_selected_item[stack_top] = selected;
527 stack_top++; 586 stack_top++;
528 menu = temp; 587 menu = temp;
529 init_menu_lists(menu,&lists,0,false); 588 init_menu_lists(menu,&lists,0,false, vps);
530 redraw_lists = false; /* above does the redraw */ 589 redraw_lists = false; /* above does the redraw */
531 in_stringlist = true; 590 in_stringlist = true;
532 } 591 }
@@ -542,7 +601,7 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected)
542 menu_callback(ACTION_EXIT_MENUITEM,temp); 601 menu_callback(ACTION_EXIT_MENUITEM,temp);
543 } 602 }
544 if (current_submenus_menu != menu) 603 if (current_submenus_menu != menu)
545 init_menu_lists(menu,&lists,selected,true); 604 init_menu_lists(menu,&lists,selected,true,vps);
546 /* callback was changed, so reload the menu's callback */ 605 /* callback was changed, so reload the menu's callback */
547 get_menu_callback(menu, &menu_callback); 606 get_menu_callback(menu, &menu_callback);
548 if ((menu->flags&MENU_EXITAFTERTHISMENU) && 607 if ((menu->flags&MENU_EXITAFTERTHISMENU) &&
@@ -552,8 +611,11 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected)
552 break; 611 break;
553 } 612 }
554#ifdef HAS_BUTTONBAR 613#ifdef HAS_BUTTONBAR
555 gui_buttonbar_set(&buttonbar, "<<<", "", ""); 614 if (!hide_bars)
556 gui_buttonbar_draw(&buttonbar); 615 {
616 gui_buttonbar_set(&buttonbar, "<<<", "", "");
617 gui_buttonbar_draw(&buttonbar);
618 }
557#endif 619#endif
558 } 620 }
559 else if(default_event_handler(action) == SYS_USB_CONNECTED) 621 else if(default_event_handler(action) == SYS_USB_CONNECTED)
@@ -575,7 +637,7 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected)
575 if (stack_top > 0) 637 if (stack_top > 0)
576 { 638 {
577 menu = menu_stack[0]; 639 menu = menu_stack[0];
578 init_menu_lists(menu,&lists,menu_stack_selected_item[0],true); 640 init_menu_lists(menu,&lists,menu_stack_selected_item[0],true, vps);
579 } 641 }
580 *start_selected = get_menu_selection( 642 *start_selected = get_menu_selection(
581 gui_synclist_get_sel_pos(&lists), menu); 643 gui_synclist_get_sel_pos(&lists), menu);