1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Robert E. Hak
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 - Multi screen support
22 - Rewrote/removed a lot of code now useless with the new gui API
31 #include "backlight.h"
39 #include "settings_list.h"
40 #include "option_select.h"
47 #include "menus/exported_menus.h"
49 #include "root_menu.h"
51 #include "gwps-common.h" /* for fade() */
55 #ifdef HAVE_LCD_BITMAP
61 #include "statusbar.h"
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
&& (selected_item
<current_subitems_count
))
85 return current_subitems
[selected_item
];
88 static int find_menu_selection(int selected
)
91 for (i
=0; i
< current_subitems_count
; i
++)
92 if (current_subitems
[i
] == selected
)
96 static char * get_menu_item_name(int selected_item
,
101 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
102 int type
= (menu
->flags
&MENU_TYPE_MASK
);
103 selected_item
= get_menu_selection(selected_item
, menu
);
106 /* only MT_MENU or MT_RETURN_ID is allowed in here */
107 if (type
== MT_RETURN_ID
)
109 if (menu
->flags
&MENU_DYNAMIC_DESC
)
110 return menu
->menu_get_name_and_icon
->list_get_name(selected_item
,
111 menu
->menu_get_name_and_icon
->list_get_name_data
, buffer
);
112 return (char*)menu
->strings
[selected_item
];
115 menu
= menu
->submenus
[selected_item
];
117 if ((menu
->flags
&MENU_DYNAMIC_DESC
) && (type
!= MT_SETTING_W_TEXT
))
118 return menu
->menu_get_name_and_icon
->list_get_name(selected_item
,
119 menu
->menu_get_name_and_icon
->list_get_name_data
, buffer
);
121 type
= (menu
->flags
&MENU_TYPE_MASK
);
122 if ((type
== MT_SETTING
) || (type
== MT_SETTING_W_TEXT
))
124 const struct settings_list
*v
125 = find_setting(menu
->variable
, NULL
);
127 return str(v
->lang_id
);
128 else return "Not Done yet!";
130 return P2STR(menu
->callback_and_desc
->desc
);
132 #ifdef HAVE_LCD_BITMAP
133 static int menu_get_icon(int selected_item
, void * data
)
135 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
136 int menu_icon
= Icon_NOICON
;
137 selected_item
= get_menu_selection(selected_item
, menu
);
139 if ((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
)
141 return Icon_Menu_functioncall
;
143 menu
= menu
->submenus
[selected_item
];
144 if (menu
->flags
&MENU_HAS_DESC
)
145 menu_icon
= menu
->callback_and_desc
->icon_id
;
146 else if (menu
->flags
&MENU_DYNAMIC_DESC
)
147 menu_icon
= menu
->menu_get_name_and_icon
->icon_id
;
149 if (menu_icon
== Icon_NOICON
)
151 switch (menu
->flags
&MENU_TYPE_MASK
)
154 case MT_SETTING_W_TEXT
:
155 menu_icon
= Icon_Menu_setting
;
158 menu_icon
= Icon_Submenu
;
160 case MT_FUNCTION_CALL
:
161 case MT_RETURN_VALUE
:
162 menu_icon
= Icon_Menu_functioncall
;
170 static void init_menu_lists(const struct menu_item_ex
*menu
,
171 struct gui_synclist
*lists
, int selected
, bool callback
,
172 struct viewport parent
[NB_SCREENS
])
174 int i
, count
= MENU_GET_COUNT(menu
->flags
);
175 int type
= (menu
->flags
&MENU_TYPE_MASK
);
176 menu_callback_type menu_callback
= NULL
;
178 current_subitems_count
= 0;
180 if (type
== MT_RETURN_ID
)
181 get_menu_callback(menu
, &menu_callback
);
183 for (i
=0; i
<count
; i
++)
185 if (type
!= MT_RETURN_ID
)
186 get_menu_callback(menu
->submenus
[i
],&menu_callback
);
189 if (menu_callback(ACTION_REQUEST_MENUITEM
,
190 type
==MT_RETURN_ID
? (void*)(intptr_t)i
: menu
->submenus
[i
])
191 != ACTION_EXIT_MENUITEM
)
193 current_subitems
[current_subitems_count
] = i
;
194 current_subitems_count
++;
199 current_subitems
[current_subitems_count
] = i
;
200 current_subitems_count
++;
203 current_submenus_menu
= (struct menu_item_ex
*)menu
;
205 gui_synclist_init(lists
,get_menu_item_name
,(void*)menu
,false,1, parent
);
206 #ifdef HAVE_LCD_BITMAP
207 if (menu
->callback_and_desc
->icon_id
== Icon_NOICON
)
208 icon
= Icon_Submenu_Entered
;
210 icon
= menu
->callback_and_desc
->icon_id
;
211 gui_synclist_set_title(lists
, P2STR(menu
->callback_and_desc
->desc
), icon
);
212 gui_synclist_set_icon_callback(lists
, menu_get_icon
);
215 gui_synclist_set_icon_callback(lists
, NULL
);
217 if(global_settings
.talk_menu
)
218 gui_synclist_set_voice_callback(lists
, talk_menu_item
);
219 gui_synclist_set_nb_items(lists
,current_subitems_count
);
220 gui_synclist_limit_scroll(lists
,true);
221 gui_synclist_select_item(lists
, find_menu_selection(selected
));
223 get_menu_callback(menu
,&menu_callback
);
224 if (callback
&& menu_callback
)
225 menu_callback(ACTION_ENTER_MENUITEM
,menu
);
226 gui_synclist_draw(lists
);
227 gui_synclist_speak_item(lists
);
230 static int talk_menu_item(int selected_item
, void *data
)
232 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
236 int sel
= get_menu_selection(selected_item
, menu
);
238 if ((menu
->flags
&MENU_TYPE_MASK
) == MT_MENU
)
240 type
= menu
->submenus
[sel
]->flags
&MENU_TYPE_MASK
;
241 if ((type
== MT_SETTING
) || (type
== MT_SETTING_W_TEXT
))
242 talk_setting(menu
->submenus
[sel
]->variable
);
245 if (menu
->submenus
[sel
]->flags
&(MENU_DYNAMIC_DESC
))
247 int (*list_speak_item
)(int selected_item
, void * data
)
248 = menu
->submenus
[sel
]->menu_get_name_and_icon
->
251 list_speak_item(sel
, menu
->submenus
[sel
]->
252 menu_get_name_and_icon
->
257 str
= menu
->submenus
[sel
]->menu_get_name_and_icon
->
258 list_get_name(sel
, menu
->submenus
[sel
]->
259 menu_get_name_and_icon
->
260 list_get_name_data
, buffer
);
265 id
= P2ID(menu
->submenus
[sel
]->callback_and_desc
->desc
);
270 else if(((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
))
272 if ((menu
->flags
&MENU_DYNAMIC_DESC
) == 0)
274 unsigned char *s
= (unsigned char *)menu
->strings
[sel
];
275 /* string list, try to talk it if ID2P was used */
283 /* this is used to reload the default menu viewports when the
284 theme changes. nothing happens if the menu is using a supplied parent vp */
285 void init_default_menu_viewports(struct viewport parent
[NB_SCREENS
], bool hide_bars
)
290 viewport_set_defaults(&parent
[i
], i
);
291 /* viewport_set_defaults() fixes the vp for the bars, so resize */
294 if (global_settings
.statusbar
)
296 parent
[i
].y
-= STATUSBAR_HEIGHT
;
297 parent
[i
].height
+= STATUSBAR_HEIGHT
;
302 if (!hide_bars
&& global_settings
.buttonbar
)
303 parent
[0].height
-= BUTTONBAR_HEIGHT
;
307 bool do_setting_from_menu(const struct menu_item_ex
*temp
)
309 int setting_id
, oldval
;
310 const struct settings_list
*setting
= find_setting(
314 char padded_title
[MAX_PATH
];
315 int var_type
= setting
->flags
&F_T_MASK
;
316 if (var_type
== F_T_INT
|| var_type
== F_T_UINT
)
318 oldval
= *(int*)setting
->setting
;
320 else if (var_type
== F_T_BOOL
)
322 oldval
= *(bool*)setting
->setting
;
326 if ((temp
->flags
&MENU_TYPE_MASK
) == MT_SETTING_W_TEXT
)
327 title
= temp
->callback_and_desc
->desc
;
329 title
= ID2P(setting
->lang_id
);
331 /* Pad the title string by repeating it. This is needed
332 so the scroll settings title can actually be used to
334 if (setting
->flags
&F_PADTITLE
)
337 if (setting
->lang_id
== -1)
338 title
= (char*)setting
->cfg_vals
;
340 title
= P2STR((unsigned char*)title
);
342 while (i
< MAX_PATH
-1)
344 int padlen
= MIN(len
, MAX_PATH
-1-i
);
345 strncpy(&padded_title
[i
], title
, padlen
);
348 padded_title
[i
++] = ' ';
350 padded_title
[i
] = '\0';
351 title
= padded_title
;
354 option_screen((struct settings_list
*)setting
,
355 setting
->flags
&F_TEMPVAR
, title
);
356 if (var_type
== F_T_INT
|| var_type
== F_T_UINT
)
358 return oldval
!= *(int*)setting
->setting
;
360 else if (var_type
== F_T_BOOL
)
362 return oldval
!= *(bool*)setting
->setting
;
368 int do_menu(const struct menu_item_ex
*start_menu
, int *start_selected
,
369 struct viewport parent
[NB_SCREENS
], bool hide_bars
)
371 int selected
= start_selected
? *start_selected
: 0;
373 struct gui_synclist lists
;
374 const struct menu_item_ex
*temp
, *menu
;
378 const struct menu_item_ex
*menu_stack
[MAX_MENUS
];
379 int menu_stack_selected_item
[MAX_MENUS
];
381 bool in_stringlist
, done
= false;
383 struct viewport
*vps
, menu_vp
[NB_SCREENS
]; /* menu_vp will hopefully be phased out */
385 struct gui_buttonbar buttonbar
;
386 gui_buttonbar_init(&buttonbar
);
387 gui_buttonbar_set_display(&buttonbar
, &(screens
[SCREEN_MAIN
]) );
388 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
391 menu_callback_type menu_callback
= NULL
;
392 if (start_menu
== NULL
)
394 else menu
= start_menu
;
399 /* if hide_bars == true we assume the viewport is correctly sized */
404 init_default_menu_viewports(vps
, hide_bars
);
408 screens
[i
].set_viewport(&vps
[i
]);
409 screens
[i
].clear_viewport();
410 screens
[i
].set_viewport(NULL
);
412 init_menu_lists(menu
, &lists
, selected
, true, vps
);
413 in_stringlist
= ((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
);
415 /* load the callback, and only reload it if menu changes */
416 get_menu_callback(menu
, &menu_callback
);
422 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
423 gui_buttonbar_draw(&buttonbar
);
428 redraw_lists
= false;
431 gui_syncstatusbar_draw(&statusbars
, true);
433 action
= get_action(CONTEXT_MAINMENU
,
434 list_do_action_timeout(&lists
, HZ
));
435 /* HZ so the status bar redraws corectly */
437 if (action
!= ACTION_NONE
&& menu_callback
)
439 int old_action
= action
;
440 action
= menu_callback(action
, menu
);
441 if (action
== ACTION_EXIT_AFTER_THIS_MENUITEM
)
444 ret
= MENU_SELECTED_EXIT
; /* will exit after returning
447 else if (action
== ACTION_REDRAW
)
454 if (gui_synclist_do_button(&lists
, &action
, LIST_WRAP_UNLESS_HELD
))
456 if (action
== ACTION_NONE
)
459 #ifdef HAVE_RECORDING
460 if (action
== ACTION_STD_REC
)
462 ret
= GO_TO_RECSCREEN
;
467 if (action
== ACTION_TREE_WPS
)
469 ret
= GO_TO_PREVIOUS_MUSIC
;
472 else if (action
== ACTION_TREE_STOP
)
474 redraw_lists
= list_stop_handler();
476 else if (action
== ACTION_STD_CONTEXT
&&
479 ret
= GO_TO_ROOTITEM_CONTEXT
;
482 else if (action
== ACTION_STD_MENU
)
484 if (menu
!= &root_menu_
)
487 ret
= GO_TO_PREVIOUS
;
490 else if (action
== ACTION_STD_CANCEL
)
492 bool exiting_menu
= false;
493 in_stringlist
= false;
495 menu_callback(ACTION_EXIT_MENUITEM
, menu
);
497 if (menu
->flags
&MENU_EXITAFTERTHISMENU
)
499 else if ((menu
->flags
&MENU_TYPE_MASK
) == MT_MENU
)
504 menu
= menu_stack
[stack_top
];
505 if (!exiting_menu
&& (menu
->flags
&MENU_EXITAFTERTHISMENU
))
508 init_menu_lists(menu
, &lists
,
509 menu_stack_selected_item
[stack_top
], false, vps
);
510 /* new menu, so reload the callback */
511 get_menu_callback(menu
, &menu_callback
);
513 else if (menu
!= &root_menu_
)
515 ret
= GO_TO_PREVIOUS
;
519 else if (action
== ACTION_STD_OK
)
525 gui_buttonbar_unset(&buttonbar
);
526 gui_buttonbar_draw(&buttonbar
);
529 selected
= get_menu_selection(gui_synclist_get_sel_pos(&lists
), menu
);
530 temp
= menu
->submenus
[selected
];
533 type
= (menu
->flags
&MENU_TYPE_MASK
);
536 type
= (temp
->flags
&MENU_TYPE_MASK
);
537 get_menu_callback(temp
, &menu_callback
);
540 action
= menu_callback(ACTION_ENTER_MENUITEM
,temp
);
541 if (action
== ACTION_EXIT_MENUITEM
)
548 if (stack_top
< MAX_MENUS
)
550 menu_stack
[stack_top
] = menu
;
551 menu_stack_selected_item
[stack_top
] = selected
;
553 init_menu_lists(temp
, &lists
, 0, true, vps
);
554 redraw_lists
= false; /* above does the redraw */
558 case MT_FUNCTION_CALL
:
561 if (temp
->flags
&MENU_FUNC_USEPARAM
)
562 return_value
= temp
->function
->function_w_param(
563 temp
->function
->param
);
565 return_value
= temp
->function
->function();
567 init_default_menu_viewports(menu_vp
, hide_bars
);
568 init_menu_lists(menu
, &lists
, selected
, true, vps
);
570 if (temp
->flags
&MENU_FUNC_CHECK_RETVAL
)
572 if (return_value
== 1)
581 case MT_SETTING_W_TEXT
:
583 if (do_setting_from_menu(temp
))
585 init_default_menu_viewports(menu_vp
, hide_bars
);
586 init_menu_lists(menu
, &lists
, selected
, true,vps
);
587 redraw_lists
= false; /* above does the redraw */
597 else if (stack_top
< MAX_MENUS
)
599 menu_stack
[stack_top
] = menu
;
600 menu_stack_selected_item
[stack_top
] = selected
;
603 init_menu_lists(menu
,&lists
,0,false, vps
);
604 redraw_lists
= false; /* above does the redraw */
605 in_stringlist
= true;
608 case MT_RETURN_VALUE
:
616 menu_callback(ACTION_EXIT_MENUITEM
,temp
);
618 if (current_submenus_menu
!= menu
)
619 init_menu_lists(menu
,&lists
,selected
,true,vps
);
620 /* callback was changed, so reload the menu's callback */
621 get_menu_callback(menu
, &menu_callback
);
622 if ((menu
->flags
&MENU_EXITAFTERTHISMENU
) &&
623 !(temp
->flags
&MENU_EXITAFTERTHISMENU
))
631 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
632 gui_buttonbar_draw(&buttonbar
);
636 else if(default_event_handler(action
) == SYS_USB_CONNECTED
)
638 ret
= MENU_ATTACHED_USB
;
642 if (redraw_lists
&& !done
)
644 gui_synclist_draw(&lists
);
645 gui_synclist_speak_item(&lists
);
650 /* make sure the start_selected variable is set to
651 the selected item from the menu do_menu() was called from */
654 menu
= menu_stack
[0];
655 init_menu_lists(menu
,&lists
,menu_stack_selected_item
[0],true, vps
);
657 *start_selected
= get_menu_selection(
658 gui_synclist_get_sel_pos(&lists
), menu
);