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
30 #include "backlight.h"
38 #include "settings_list.h"
39 #include "option_select.h"
46 #include "menus/exported_menus.h"
48 #include "root_menu.h"
50 #include "gwps-common.h" /* for fade() */
53 #ifdef HAVE_LCD_BITMAP
59 #include "statusbar.h"
60 #include "buttonbar.h"
63 /* used to allow for dynamic menus */
64 #define MAX_MENU_SUBITEMS 64
65 static struct menu_item_ex
*current_submenus_menu
;
66 static int current_subitems
[MAX_MENU_SUBITEMS
];
67 static int current_subitems_count
= 0;
68 static int talk_menu_item(int selected_item
, void *data
);
70 static void get_menu_callback(const struct menu_item_ex
*m
,
71 menu_callback_type
*menu_callback
)
73 if (m
->flags
&(MENU_HAS_DESC
|MENU_DYNAMIC_DESC
))
74 *menu_callback
= m
->callback_and_desc
->menu_callback
;
76 *menu_callback
= m
->menu_callback
;
79 static int get_menu_selection(int selected_item
, const struct menu_item_ex
*menu
)
81 int type
= (menu
->flags
&MENU_TYPE_MASK
);
82 if (type
== MT_MENU
&& (selected_item
<current_subitems_count
))
83 return current_subitems
[selected_item
];
86 static int find_menu_selection(int selected
)
89 for (i
=0; i
< current_subitems_count
; i
++)
90 if (current_subitems
[i
] == selected
)
94 static char * get_menu_item_name(int selected_item
,void * data
, char *buffer
)
96 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
97 int type
= (menu
->flags
&MENU_TYPE_MASK
);
98 selected_item
= get_menu_selection(selected_item
, menu
);
101 /* only MT_MENU or MT_RETURN_ID is allowed in here */
102 if (type
== MT_RETURN_ID
)
104 if (menu
->flags
&MENU_DYNAMIC_DESC
)
105 return menu
->menu_get_name_and_icon
->list_get_name(selected_item
,
106 menu
->menu_get_name_and_icon
->list_get_name_data
, buffer
);
107 return (char*)menu
->strings
[selected_item
];
110 menu
= menu
->submenus
[selected_item
];
112 if ((menu
->flags
&MENU_DYNAMIC_DESC
) && (type
!= MT_SETTING_W_TEXT
))
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
);
116 type
= (menu
->flags
&MENU_TYPE_MASK
);
117 if ((type
== MT_SETTING
) || (type
== MT_SETTING_W_TEXT
))
119 const struct settings_list
*v
120 = find_setting(menu
->variable
, NULL
);
122 return str(v
->lang_id
);
123 else return "Not Done yet!";
125 return P2STR(menu
->callback_and_desc
->desc
);
127 #ifdef HAVE_LCD_BITMAP
128 static int menu_get_icon(int selected_item
, void * data
)
130 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
131 int menu_icon
= Icon_NOICON
;
132 selected_item
= get_menu_selection(selected_item
, menu
);
134 if ((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
)
136 return Icon_Menu_functioncall
;
138 menu
= menu
->submenus
[selected_item
];
139 if (menu
->flags
&MENU_HAS_DESC
)
140 menu_icon
= menu
->callback_and_desc
->icon_id
;
141 else if (menu
->flags
&MENU_DYNAMIC_DESC
)
142 menu_icon
= menu
->menu_get_name_and_icon
->icon_id
;
144 if (menu_icon
== Icon_NOICON
)
146 switch (menu
->flags
&MENU_TYPE_MASK
)
149 case MT_SETTING_W_TEXT
:
150 menu_icon
= Icon_Menu_setting
;
153 menu_icon
= Icon_Submenu
;
155 case MT_FUNCTION_CALL
:
156 case MT_RETURN_VALUE
:
157 menu_icon
= Icon_Menu_functioncall
;
165 static void init_menu_lists(const struct menu_item_ex
*menu
,
166 struct gui_synclist
*lists
, int selected
, bool callback
)
168 int i
, count
= MENU_GET_COUNT(menu
->flags
);
169 int type
= (menu
->flags
&MENU_TYPE_MASK
);
170 menu_callback_type menu_callback
= NULL
;
172 current_subitems_count
= 0;
174 if (type
== MT_RETURN_ID
)
175 get_menu_callback(menu
, &menu_callback
);
177 for (i
=0; i
<count
; i
++)
179 if (type
!= MT_RETURN_ID
)
180 get_menu_callback(menu
->submenus
[i
],&menu_callback
);
183 if (menu_callback(ACTION_REQUEST_MENUITEM
,
184 type
==MT_RETURN_ID
? (void*)(intptr_t)i
: menu
->submenus
[i
])
185 != ACTION_EXIT_MENUITEM
)
187 current_subitems
[current_subitems_count
] = i
;
188 current_subitems_count
++;
193 current_subitems
[current_subitems_count
] = i
;
194 current_subitems_count
++;
197 current_submenus_menu
= (struct menu_item_ex
*)menu
;
199 gui_synclist_init(lists
,get_menu_item_name
,(void*)menu
,false,1);
200 #ifdef HAVE_LCD_BITMAP
201 if (menu
->callback_and_desc
->icon_id
== Icon_NOICON
)
202 icon
= Icon_Submenu_Entered
;
204 icon
= menu
->callback_and_desc
->icon_id
;
205 gui_synclist_set_title(lists
, P2STR(menu
->callback_and_desc
->desc
), icon
);
206 gui_synclist_set_icon_callback(lists
, menu_get_icon
);
209 gui_synclist_set_icon_callback(lists
, NULL
);
211 if(global_settings
.talk_menu
)
212 gui_synclist_set_voice_callback(lists
, talk_menu_item
);
213 gui_synclist_set_nb_items(lists
,current_subitems_count
);
214 gui_synclist_limit_scroll(lists
,true);
215 gui_synclist_select_item(lists
, find_menu_selection(selected
));
217 get_menu_callback(menu
,&menu_callback
);
218 if (callback
&& menu_callback
)
219 menu_callback(ACTION_ENTER_MENUITEM
,menu
);
220 gui_synclist_draw(lists
);
221 gui_synclist_speak_item(lists
);
224 static int talk_menu_item(int selected_item
, void *data
)
226 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
230 int sel
= get_menu_selection(selected_item
, menu
);
232 if ((menu
->flags
&MENU_TYPE_MASK
) == MT_MENU
)
234 type
= menu
->submenus
[sel
]->flags
&MENU_TYPE_MASK
;
235 if ((type
== MT_SETTING
) || (type
== MT_SETTING_W_TEXT
))
236 talk_setting(menu
->submenus
[sel
]->variable
);
239 if (menu
->submenus
[sel
]->flags
&(MENU_DYNAMIC_DESC
))
241 int (*list_speak_item
)(int selected_item
, void * data
)
242 = menu
->submenus
[sel
]->menu_get_name_and_icon
->
245 list_speak_item(sel
, menu
->submenus
[sel
]->
246 menu_get_name_and_icon
->
251 str
= menu
->submenus
[sel
]->menu_get_name_and_icon
->
252 list_get_name(sel
, menu
->submenus
[sel
]->
253 menu_get_name_and_icon
->
254 list_get_name_data
, buffer
);
259 id
= P2ID(menu
->submenus
[sel
]->callback_and_desc
->desc
);
264 else if(((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
))
266 if ((menu
->flags
&MENU_DYNAMIC_DESC
) == 0)
268 unsigned char *s
= (unsigned char *)menu
->strings
[sel
];
269 /* string list, try to talk it if ID2P was used */
277 #define MAX_OPTIONS 32
278 bool do_setting_from_menu(const struct menu_item_ex
*temp
)
281 const struct settings_list
*setting
= find_setting(
285 if ((temp
->flags
&MENU_TYPE_MASK
) == MT_SETTING_W_TEXT
)
286 title
= temp
->callback_and_desc
->desc
;
288 title
= ID2P(setting
->lang_id
);
289 option_screen((struct settings_list
*)setting
,
290 setting
->flags
&F_TEMPVAR
, title
);
294 int do_menu(const struct menu_item_ex
*start_menu
, int *start_selected
)
296 int selected
= start_selected
? *start_selected
: 0;
298 struct gui_synclist lists
;
299 const struct menu_item_ex
*temp
, *menu
;
303 struct gui_buttonbar buttonbar
;
306 const struct menu_item_ex
*menu_stack
[MAX_MENUS
];
307 int menu_stack_selected_item
[MAX_MENUS
];
309 bool in_stringlist
, done
= false;
310 menu_callback_type menu_callback
= NULL
;
311 if (start_menu
== NULL
)
313 else menu
= start_menu
;
315 gui_buttonbar_init(&buttonbar
);
316 gui_buttonbar_set_display(&buttonbar
, &(screens
[SCREEN_MAIN
]) );
317 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
318 gui_buttonbar_draw(&buttonbar
);
320 init_menu_lists(menu
,&lists
,selected
,true);
321 in_stringlist
= ((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
);
323 /* load the callback, and only reload it if menu changes */
324 get_menu_callback(menu
, &menu_callback
);
328 redraw_lists
= false;
329 gui_syncstatusbar_draw(&statusbars
, true);
330 action
= get_action(CONTEXT_MAINMENU
,
331 list_do_action_timeout(&lists
, HZ
));
332 /* HZ so the status bar redraws corectly */
334 if (action
!= ACTION_NONE
&& menu_callback
)
336 int old_action
= action
;
337 action
= menu_callback(action
, menu
);
338 if (action
== ACTION_EXIT_AFTER_THIS_MENUITEM
)
341 ret
= MENU_SELECTED_EXIT
; /* will exit after returning
344 else if (action
== ACTION_REDRAW
)
351 if (gui_synclist_do_button(&lists
, &action
, LIST_WRAP_UNLESS_HELD
))
353 if (action
== ACTION_NONE
)
356 #ifdef HAVE_RECORDING
357 if (action
== ACTION_STD_REC
)
359 ret
= GO_TO_RECSCREEN
;
364 if (action
== ACTION_TREE_WPS
)
366 ret
= GO_TO_PREVIOUS_MUSIC
;
369 else if (action
== ACTION_TREE_STOP
)
371 redraw_lists
= list_stop_handler();
373 else if (action
== ACTION_STD_CONTEXT
&&
376 ret
= GO_TO_ROOTITEM_CONTEXT
;
379 else if (action
== ACTION_STD_MENU
)
381 if (menu
!= &root_menu_
)
384 ret
= GO_TO_PREVIOUS
;
387 else if (action
== ACTION_STD_CANCEL
)
389 in_stringlist
= false;
391 menu_callback(ACTION_EXIT_MENUITEM
, menu
);
393 if (menu
->flags
&MENU_EXITAFTERTHISMENU
)
398 menu
= menu_stack
[stack_top
];
399 if (menu
->flags
&MENU_EXITAFTERTHISMENU
)
402 init_menu_lists(menu
, &lists
,
403 menu_stack_selected_item
[stack_top
], false);
404 /* new menu, so reload the callback */
405 get_menu_callback(menu
, &menu_callback
);
407 else if (menu
!= &root_menu_
)
409 ret
= GO_TO_PREVIOUS
;
413 else if (action
== ACTION_STD_OK
)
417 gui_buttonbar_unset(&buttonbar
);
418 gui_buttonbar_draw(&buttonbar
);
420 selected
= get_menu_selection(gui_synclist_get_sel_pos(&lists
), menu
);
421 temp
= menu
->submenus
[selected
];
424 type
= (menu
->flags
&MENU_TYPE_MASK
);
427 type
= (temp
->flags
&MENU_TYPE_MASK
);
428 get_menu_callback(temp
, &menu_callback
);
431 action
= menu_callback(ACTION_ENTER_MENUITEM
,temp
);
432 if (action
== ACTION_EXIT_MENUITEM
)
439 if (stack_top
< MAX_MENUS
)
441 menu_stack
[stack_top
] = menu
;
442 menu_stack_selected_item
[stack_top
] = selected
;
444 init_menu_lists(temp
, &lists
, 0, true);
445 redraw_lists
= false; /* above does the redraw */
449 case MT_FUNCTION_CALL
:
452 if (temp
->flags
&MENU_FUNC_USEPARAM
)
453 return_value
= temp
->function
->function_w_param(
454 temp
->function
->param
);
456 return_value
= temp
->function
->function();
457 if (temp
->flags
&MENU_FUNC_CHECK_RETVAL
)
459 if (return_value
== 1)
468 case MT_SETTING_W_TEXT
:
470 if (do_setting_from_menu(temp
))
472 init_menu_lists(menu
, &lists
, selected
, true);
473 redraw_lists
= false; /* above does the redraw */
483 else if (stack_top
< MAX_MENUS
)
485 menu_stack
[stack_top
] = menu
;
486 menu_stack_selected_item
[stack_top
] = selected
;
489 init_menu_lists(menu
,&lists
,0,false);
490 redraw_lists
= false; /* above does the redraw */
491 in_stringlist
= true;
494 case MT_RETURN_VALUE
:
502 menu_callback(ACTION_EXIT_MENUITEM
,temp
);
504 if (current_submenus_menu
!= menu
)
505 init_menu_lists(menu
,&lists
,selected
,true);
506 /* callback was changed, so reload the menu's callback */
507 get_menu_callback(menu
, &menu_callback
);
508 if ((menu
->flags
&MENU_EXITAFTERTHISMENU
) &&
509 !(temp
->flags
&MENU_EXITAFTERTHISMENU
))
515 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
516 gui_buttonbar_draw(&buttonbar
);
519 else if(default_event_handler(action
) == SYS_USB_CONNECTED
)
521 ret
= MENU_ATTACHED_USB
;
525 if (redraw_lists
&& !done
)
527 gui_synclist_draw(&lists
);
528 gui_synclist_speak_item(&lists
);
533 /* make sure the start_selected variable is set to
534 the selected item from the menu do_menu() was called from */
537 menu
= menu_stack
[0];
538 init_menu_lists(menu
,&lists
,menu_stack_selected_item
[0],true);
540 *start_selected
= get_menu_selection(
541 gui_synclist_get_sel_pos(&lists
), menu
);