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
);
295 int do_menu(const struct menu_item_ex
*start_menu
, int *start_selected
)
297 int selected
= start_selected
? *start_selected
: 0;
299 struct gui_synclist lists
;
300 const struct menu_item_ex
*temp
, *menu
;
304 struct gui_buttonbar buttonbar
;
307 const struct menu_item_ex
*menu_stack
[MAX_MENUS
];
308 int menu_stack_selected_item
[MAX_MENUS
];
310 bool in_stringlist
, done
= false;
311 menu_callback_type menu_callback
= NULL
;
312 if (start_menu
== NULL
)
314 else menu
= start_menu
;
316 gui_buttonbar_init(&buttonbar
);
317 gui_buttonbar_set_display(&buttonbar
, &(screens
[SCREEN_MAIN
]) );
318 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
319 gui_buttonbar_draw(&buttonbar
);
321 init_menu_lists(menu
,&lists
,selected
,true);
322 in_stringlist
= ((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
);
324 /* load the callback, and only reload it if menu changes */
325 get_menu_callback(menu
, &menu_callback
);
329 redraw_lists
= false;
330 gui_syncstatusbar_draw(&statusbars
, true);
331 action
= get_action(CONTEXT_MAINMENU
,
332 list_do_action_timeout(&lists
, HZ
));
333 /* HZ so the status bar redraws corectly */
335 if (action
!= ACTION_NONE
&& menu_callback
)
337 int old_action
= action
;
338 action
= menu_callback(action
, menu
);
339 if (action
== ACTION_EXIT_AFTER_THIS_MENUITEM
)
342 ret
= MENU_SELECTED_EXIT
; /* will exit after returning
345 else if (action
== ACTION_REDRAW
)
352 if (gui_synclist_do_button(&lists
, &action
, LIST_WRAP_UNLESS_HELD
))
354 if (action
== ACTION_NONE
)
357 #ifdef HAVE_RECORDING
358 if (action
== ACTION_STD_REC
)
360 ret
= GO_TO_RECSCREEN
;
365 if (action
== ACTION_TREE_WPS
)
367 ret
= GO_TO_PREVIOUS_MUSIC
;
370 else if (action
== ACTION_TREE_STOP
)
372 redraw_lists
= list_stop_handler();
374 else if (action
== ACTION_STD_CONTEXT
&&
377 ret
= GO_TO_ROOTITEM_CONTEXT
;
380 else if (action
== ACTION_STD_MENU
)
382 if (menu
!= &root_menu_
)
385 ret
= GO_TO_PREVIOUS
;
388 else if (action
== ACTION_STD_CANCEL
)
390 in_stringlist
= false;
392 menu_callback(ACTION_EXIT_MENUITEM
, menu
);
394 if (menu
->flags
&MENU_EXITAFTERTHISMENU
)
399 menu
= menu_stack
[stack_top
];
400 if (menu
->flags
&MENU_EXITAFTERTHISMENU
)
403 init_menu_lists(menu
, &lists
,
404 menu_stack_selected_item
[stack_top
], false);
405 /* new menu, so reload the callback */
406 get_menu_callback(menu
, &menu_callback
);
408 else if (menu
!= &root_menu_
)
410 ret
= GO_TO_PREVIOUS
;
414 else if (action
== ACTION_STD_OK
)
418 gui_buttonbar_unset(&buttonbar
);
419 gui_buttonbar_draw(&buttonbar
);
421 selected
= get_menu_selection(gui_synclist_get_sel_pos(&lists
), menu
);
422 temp
= menu
->submenus
[selected
];
425 type
= (menu
->flags
&MENU_TYPE_MASK
);
428 type
= (temp
->flags
&MENU_TYPE_MASK
);
429 get_menu_callback(temp
, &menu_callback
);
432 action
= menu_callback(ACTION_ENTER_MENUITEM
,temp
);
433 if (action
== ACTION_EXIT_MENUITEM
)
440 if (stack_top
< MAX_MENUS
)
442 menu_stack
[stack_top
] = menu
;
443 menu_stack_selected_item
[stack_top
] = selected
;
445 init_menu_lists(temp
, &lists
, 0, true);
446 redraw_lists
= false; /* above does the redraw */
450 case MT_FUNCTION_CALL
:
453 if (temp
->flags
&MENU_FUNC_USEPARAM
)
454 return_value
= temp
->function
->function_w_param(
455 temp
->function
->param
);
457 return_value
= temp
->function
->function();
458 if (temp
->flags
&MENU_FUNC_CHECK_RETVAL
)
460 if (return_value
== 1)
469 case MT_SETTING_W_TEXT
:
471 if (do_setting_from_menu(temp
))
473 init_menu_lists(menu
, &lists
, selected
, true);
474 redraw_lists
= false; /* above does the redraw */
484 else if (stack_top
< MAX_MENUS
)
486 menu_stack
[stack_top
] = menu
;
487 menu_stack_selected_item
[stack_top
] = selected
;
490 init_menu_lists(menu
,&lists
,0,false);
491 redraw_lists
= false; /* above does the redraw */
492 in_stringlist
= true;
495 case MT_RETURN_VALUE
:
503 menu_callback(ACTION_EXIT_MENUITEM
,temp
);
505 if (current_submenus_menu
!= menu
)
506 init_menu_lists(menu
,&lists
,selected
,true);
507 /* callback was changed, so reload the menu's callback */
508 get_menu_callback(menu
, &menu_callback
);
509 if ((menu
->flags
&MENU_EXITAFTERTHISMENU
) &&
510 !(temp
->flags
&MENU_EXITAFTERTHISMENU
))
516 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
517 gui_buttonbar_draw(&buttonbar
);
520 else if(default_event_handler(action
) == SYS_USB_CONNECTED
)
522 ret
= MENU_ATTACHED_USB
;
526 if (redraw_lists
&& !done
)
528 gui_synclist_draw(&lists
);
529 gui_synclist_speak_item(&lists
);
534 /* make sure the start_selected variable is set to
535 the selected item from the menu do_menu() was called from */
538 menu
= menu_stack
[0];
539 init_menu_lists(menu
,&lists
,menu_stack_selected_item
[0],true);
541 *start_selected
= get_menu_selection(
542 gui_synclist_get_sel_pos(&lists
), menu
);