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;
69 static void get_menu_callback(const struct menu_item_ex
*m
,
70 menu_callback_type
*menu_callback
)
72 if (m
->flags
&(MENU_HAS_DESC
|MENU_DYNAMIC_DESC
))
73 *menu_callback
= m
->callback_and_desc
->menu_callback
;
75 *menu_callback
= m
->menu_callback
;
78 static int get_menu_selection(int selected_item
, const struct menu_item_ex
*menu
)
80 int type
= (menu
->flags
&MENU_TYPE_MASK
);
81 if (type
== MT_MENU
&& (selected_item
<current_subitems_count
))
82 return current_subitems
[selected_item
];
85 static int find_menu_selection(int selected
)
88 for (i
=0; i
< current_subitems_count
; i
++)
89 if (current_subitems
[i
] == selected
)
93 static char * get_menu_item_name(int selected_item
,void * data
, char *buffer
)
95 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
96 int type
= (menu
->flags
&MENU_TYPE_MASK
);
97 selected_item
= get_menu_selection(selected_item
, menu
);
100 /* only MT_MENU or MT_RETURN_ID is allowed in here */
101 if (type
== MT_RETURN_ID
)
103 if (menu
->flags
&MENU_DYNAMIC_DESC
)
104 return menu
->menu_get_name_and_icon
->list_get_name(selected_item
,
105 menu
->menu_get_name_and_icon
->list_get_name_data
, buffer
);
106 return (char*)menu
->strings
[selected_item
];
109 menu
= menu
->submenus
[selected_item
];
111 if ((menu
->flags
&MENU_DYNAMIC_DESC
) && (type
!= MT_SETTING_W_TEXT
))
112 return menu
->menu_get_name_and_icon
->list_get_name(selected_item
,
113 menu
->menu_get_name_and_icon
->list_get_name_data
, buffer
);
115 type
= (menu
->flags
&MENU_TYPE_MASK
);
116 if ((type
== MT_SETTING
) || (type
== MT_SETTING_W_TEXT
))
118 const struct settings_list
*v
119 = find_setting(menu
->variable
, NULL
);
121 return str(v
->lang_id
);
122 else return "Not Done yet!";
124 return P2STR(menu
->callback_and_desc
->desc
);
126 #ifdef HAVE_LCD_BITMAP
127 static int menu_get_icon(int selected_item
, void * data
)
129 const struct menu_item_ex
*menu
= (const struct menu_item_ex
*)data
;
130 int menu_icon
= Icon_NOICON
;
131 selected_item
= get_menu_selection(selected_item
, menu
);
133 if ((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
)
135 return Icon_Menu_functioncall
;
137 menu
= menu
->submenus
[selected_item
];
138 if (menu
->flags
&MENU_HAS_DESC
)
139 menu_icon
= menu
->callback_and_desc
->icon_id
;
140 else if (menu
->flags
&MENU_DYNAMIC_DESC
)
141 menu_icon
= menu
->menu_get_name_and_icon
->icon_id
;
143 if (menu_icon
== Icon_NOICON
)
145 switch (menu
->flags
&MENU_TYPE_MASK
)
148 case MT_SETTING_W_TEXT
:
149 menu_icon
= Icon_Menu_setting
;
152 menu_icon
= Icon_Submenu
;
154 case MT_FUNCTION_CALL
:
155 case MT_RETURN_VALUE
:
156 menu_icon
= Icon_Menu_functioncall
;
164 static void init_menu_lists(const struct menu_item_ex
*menu
,
165 struct gui_synclist
*lists
, int selected
, bool callback
)
167 int i
, count
= MENU_GET_COUNT(menu
->flags
);
168 int type
= (menu
->flags
&MENU_TYPE_MASK
);
169 menu_callback_type menu_callback
= NULL
;
171 current_subitems_count
= 0;
173 if (type
== MT_RETURN_ID
)
174 get_menu_callback(menu
, &menu_callback
);
176 for (i
=0; i
<count
; i
++)
178 if (type
!= MT_RETURN_ID
)
179 get_menu_callback(menu
->submenus
[i
],&menu_callback
);
182 if (menu_callback(ACTION_REQUEST_MENUITEM
,
183 type
==MT_RETURN_ID
? (void*)(intptr_t)i
: menu
->submenus
[i
])
184 != ACTION_EXIT_MENUITEM
)
186 current_subitems
[current_subitems_count
] = i
;
187 current_subitems_count
++;
192 current_subitems
[current_subitems_count
] = i
;
193 current_subitems_count
++;
196 current_submenus_menu
= (struct menu_item_ex
*)menu
;
198 gui_synclist_init(lists
,get_menu_item_name
,(void*)menu
,false,1);
199 #ifdef HAVE_LCD_BITMAP
200 if (menu
->callback_and_desc
->icon_id
== Icon_NOICON
)
201 icon
= Icon_Submenu_Entered
;
203 icon
= menu
->callback_and_desc
->icon_id
;
204 gui_synclist_set_title(lists
, P2STR(menu
->callback_and_desc
->desc
), icon
);
205 gui_synclist_set_icon_callback(lists
, menu_get_icon
);
208 gui_synclist_set_icon_callback(lists
, NULL
);
210 gui_synclist_set_nb_items(lists
,current_subitems_count
);
211 gui_synclist_limit_scroll(lists
,true);
212 gui_synclist_select_item(lists
, find_menu_selection(selected
));
214 get_menu_callback(menu
,&menu_callback
);
215 if (callback
&& menu_callback
)
216 menu_callback(ACTION_ENTER_MENUITEM
,menu
);
217 gui_synclist_draw(lists
);
220 static void talk_menu_item(const struct menu_item_ex
*menu
,
221 struct gui_synclist
*lists
)
228 if (global_settings
.talk_menu
)
230 sel
= get_menu_selection(gui_synclist_get_sel_pos(lists
),menu
);
231 if ((menu
->flags
&MENU_TYPE_MASK
) == MT_MENU
)
233 type
= menu
->submenus
[sel
]->flags
&MENU_TYPE_MASK
;
234 if ((type
== MT_SETTING
) || (type
== MT_SETTING_W_TEXT
))
235 talk_setting(menu
->submenus
[sel
]->variable
);
238 if (menu
->submenus
[sel
]->flags
&(MENU_DYNAMIC_DESC
))
240 int (*list_speak_item
)(int selected_item
, void * data
)
241 = menu
->submenus
[sel
]->menu_get_name_and_icon
->
244 list_speak_item(sel
, menu
->submenus
[sel
]->
245 menu_get_name_and_icon
->
250 str
= menu
->submenus
[sel
]->menu_get_name_and_icon
->
251 list_get_name(sel
, menu
->submenus
[sel
]->
252 menu_get_name_and_icon
->
253 list_get_name_data
, buffer
);
258 id
= P2ID(menu
->submenus
[sel
]->callback_and_desc
->desc
);
263 else if(((menu
->flags
&MENU_TYPE_MASK
) == MT_RETURN_ID
))
265 if ((menu
->flags
&MENU_DYNAMIC_DESC
) == 0)
267 unsigned char *s
= (unsigned char *)menu
->strings
[sel
];
268 /* string list, try to talk it if ID2P was used */
276 #define MAX_OPTIONS 32
277 bool do_setting_from_menu(const struct menu_item_ex
*temp
)
280 const struct settings_list
*setting
= find_setting(
284 if ((temp
->flags
&MENU_TYPE_MASK
) == MT_SETTING_W_TEXT
)
285 title
= temp
->callback_and_desc
->desc
;
287 title
= ID2P(setting
->lang_id
);
288 option_screen((struct settings_list
*)setting
,
289 setting
->flags
&F_TEMPVAR
, title
);
293 int do_menu(const struct menu_item_ex
*start_menu
, int *start_selected
)
295 int selected
= start_selected
? *start_selected
: 0;
297 struct gui_synclist lists
;
298 const struct menu_item_ex
*temp
, *menu
;
302 struct gui_buttonbar buttonbar
;
305 const struct menu_item_ex
*menu_stack
[MAX_MENUS
];
306 int menu_stack_selected_item
[MAX_MENUS
];
308 bool in_stringlist
, done
= false;
309 menu_callback_type menu_callback
= NULL
;
310 bool talk_item
= false;
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 talk_menu_item(menu
, &lists
);
325 /* load the callback, and only reload it if menu changes */
326 get_menu_callback(menu
, &menu_callback
);
327 gui_synclist_draw(&lists
);
332 redraw_lists
= false;
333 gui_syncstatusbar_draw(&statusbars
, true);
334 action
= get_action(CONTEXT_MAINMENU
,HZ
);
335 /* HZ so the status bar redraws corectly */
336 if (action
== ACTION_NONE
)
343 int old_action
= action
;
344 action
= menu_callback(action
, menu
);
345 if (action
== ACTION_EXIT_AFTER_THIS_MENUITEM
)
348 ret
= MENU_SELECTED_EXIT
; /* will exit after returning
351 else if (action
== ACTION_REDRAW
)
358 if (gui_synclist_do_button(&lists
, &action
, LIST_WRAP_UNLESS_HELD
))
360 talk_menu_item(menu
, &lists
);
364 #ifdef HAVE_RECORDING
365 if (action
== ACTION_STD_REC
)
367 ret
= GO_TO_RECSCREEN
;
372 if (action
== ACTION_TREE_WPS
)
374 ret
= GO_TO_PREVIOUS_MUSIC
;
377 else if (action
== ACTION_TREE_STOP
)
379 redraw_lists
= list_stop_handler();
381 else if (action
== ACTION_STD_CONTEXT
&&
384 ret
= GO_TO_ROOTITEM_CONTEXT
;
387 else if (action
== ACTION_STD_MENU
)
389 if (menu
!= &root_menu_
)
392 ret
= GO_TO_PREVIOUS
;
395 else if (action
== ACTION_STD_CANCEL
)
397 in_stringlist
= false;
399 menu_callback(ACTION_EXIT_MENUITEM
, menu
);
401 if (menu
->flags
&MENU_EXITAFTERTHISMENU
)
406 menu
= menu_stack
[stack_top
];
407 if (menu
->flags
&MENU_EXITAFTERTHISMENU
)
410 init_menu_lists(menu
, &lists
,
411 menu_stack_selected_item
[stack_top
], false);
412 /* new menu, so reload the callback */
413 get_menu_callback(menu
, &menu_callback
);
416 else if (menu
!= &root_menu_
)
418 ret
= GO_TO_PREVIOUS
;
422 else if (action
== ACTION_STD_OK
)
426 gui_buttonbar_unset(&buttonbar
);
427 gui_buttonbar_draw(&buttonbar
);
429 selected
= get_menu_selection(gui_synclist_get_sel_pos(&lists
), menu
);
430 temp
= menu
->submenus
[selected
];
433 type
= (menu
->flags
&MENU_TYPE_MASK
);
436 type
= (temp
->flags
&MENU_TYPE_MASK
);
437 get_menu_callback(temp
, &menu_callback
);
440 action
= menu_callback(ACTION_ENTER_MENUITEM
,temp
);
441 if (action
== ACTION_EXIT_MENUITEM
)
448 if (stack_top
< MAX_MENUS
)
450 menu_stack
[stack_top
] = menu
;
451 menu_stack_selected_item
[stack_top
] = selected
;
453 init_menu_lists(temp
, &lists
, 0, true);
454 redraw_lists
= false; /* above does the redraw */
459 case MT_FUNCTION_CALL
:
463 if (temp
->flags
&MENU_FUNC_USEPARAM
)
464 return_value
= temp
->function
->function_w_param(
465 temp
->function
->param
);
467 return_value
= temp
->function
->function();
468 if (temp
->flags
&MENU_FUNC_CHECK_RETVAL
)
470 if (return_value
== 1)
479 case MT_SETTING_W_TEXT
:
481 if (do_setting_from_menu(temp
))
483 init_menu_lists(menu
, &lists
, selected
, true);
484 redraw_lists
= false; /* above does the redraw */
495 else if (stack_top
< MAX_MENUS
)
497 menu_stack
[stack_top
] = menu
;
498 menu_stack_selected_item
[stack_top
] = selected
;
501 init_menu_lists(menu
,&lists
,0,false);
502 redraw_lists
= false; /* above does the redraw */
504 in_stringlist
= true;
507 case MT_RETURN_VALUE
:
515 menu_callback(ACTION_EXIT_MENUITEM
,temp
);
517 if (current_submenus_menu
!= menu
)
518 init_menu_lists(menu
,&lists
,selected
,true);
519 /* callback was changed, so reload the menu's callback */
520 get_menu_callback(menu
, &menu_callback
);
521 if ((menu
->flags
&MENU_EXITAFTERTHISMENU
) &&
522 !(temp
->flags
&MENU_EXITAFTERTHISMENU
))
528 gui_buttonbar_set(&buttonbar
, "<<<", "", "");
529 gui_buttonbar_draw(&buttonbar
);
532 else if(default_event_handler(action
) == SYS_USB_CONNECTED
)
534 ret
= MENU_ATTACHED_USB
;
537 if (talk_item
&& !done
)
538 talk_menu_item(menu
, &lists
);
541 gui_synclist_draw(&lists
);
545 /* make sure the start_selected variable is set to
546 the selected item from the menu do_menu() was called from */
549 menu
= menu_stack
[0];
550 init_menu_lists(menu
,&lists
,menu_stack_selected_item
[0],true);
552 *start_selected
= get_menu_selection(
553 gui_synclist_get_sel_pos(&lists
), menu
);