From 77a458a464450c4e9d6977ac3f27b0e56217443c Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Tue, 8 May 2007 11:55:43 +0000 Subject: Move the old api out of the core and into the plugin lib. ew plugins shuold use the new api and not this one. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13358 a1c6a512-1295-4272-9138-f99709370657 --- apps/menu.c | 202 +---------------------- apps/menu.h | 20 --- apps/plugin.c | 10 +- apps/plugin.h | 18 +-- apps/plugins/clock.c | 49 +++--- apps/plugins/doom/rockdoom.c | 25 +-- apps/plugins/fireworks.c | 7 +- apps/plugins/jpeg.c | 15 +- apps/plugins/lib/SOURCES | 1 + apps/plugins/lib/oldmenuapi.c | 241 ++++++++++++++++++++++++++++ apps/plugins/lib/oldmenuapi.h | 56 +++++++ apps/plugins/mpegplayer/mpeg_settings.c | 7 +- apps/plugins/pacbox/pacbox.c | 7 +- apps/plugins/random_folder_advance_config.c | 21 +-- apps/plugins/rockboy/menu.c | 19 +-- apps/plugins/solitaire.c | 7 +- apps/plugins/sudoku/sudoku.c | 15 +- apps/plugins/test_disk.c | 7 +- apps/plugins/test_sampr.c | 7 +- apps/plugins/text_editor.c | 13 +- apps/plugins/viewer.c | 15 +- apps/plugins/zxbox/spmain.c | 25 +-- 22 files changed, 438 insertions(+), 349 deletions(-) create mode 100644 apps/plugins/lib/oldmenuapi.c create mode 100644 apps/plugins/lib/oldmenuapi.h diff --git a/apps/menu.c b/apps/menu.c index 000206182d..04ccaf4366 100644 --- a/apps/menu.c +++ b/apps/menu.c @@ -57,21 +57,8 @@ #include "list.h" #include "statusbar.h" #include "buttonbar.h" -/* needed for the old menu system */ -struct menu { - struct menu_item* items; - char *title; - int count; - int (*callback)(int, int); - int current_selection; -}; -#define MAX_MENUS 6 -static struct menu menus[MAX_MENUS]; -static bool inuse[MAX_MENUS] = { false }; -static void init_oldmenu(const struct menu_item_ex *menu, - struct gui_synclist *lists, int selected, bool callback); -static void menu_talk_selected(int m); +#define MAX_MENUS 8 /* used to allow for dynamic menus */ #define MAX_MENU_SUBITEMS 64 static struct menu_item_ex *current_submenus_menu; @@ -182,11 +169,6 @@ static void init_menu_lists(const struct menu_item_ex *menu, int icon; current_subitems_count = 0; - if (type == MT_OLD_MENU) - { - init_oldmenu(menu, lists, selected, callback); - return; - } if (type == MT_RETURN_ID) get_menu_callback(menu, &menu_callback); @@ -244,13 +226,6 @@ static void talk_menu_item(const struct menu_item_ex *menu, if (global_settings.talk_menu) { - if ((menu->flags&MENU_TYPE_MASK) == MT_OLD_MENU) - { - menus[menu->value].current_selection = - gui_synclist_get_sel_pos(lists); - menu_talk_selected(menu->value); - return; - } sel = get_menu_selection(gui_synclist_get_sel_pos(lists),menu); if ((menu->flags&MENU_TYPE_MASK) == MT_MENU) { @@ -480,8 +455,6 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected) } else if (action == ACTION_STD_MENU) { - if ((menu->flags&MENU_TYPE_MASK) == MT_OLD_MENU) - return MENU_SELECTED_EXIT; if (menu != &root_menu_) ret = GO_TO_ROOT; else @@ -521,13 +494,6 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected) gui_buttonbar_unset(&buttonbar); gui_buttonbar_draw(&buttonbar); #endif - if ((menu->flags&MENU_TYPE_MASK) == MT_OLD_MENU) - { - selected = gui_synclist_get_sel_pos(&lists); - menus[menu->value].current_selection = selected; - action_signalscreenchange(); - return selected; - } selected = get_menu_selection(gui_synclist_get_sel_pos(&lists), menu); temp = menu->submenus[selected]; if (in_stringlist) @@ -643,169 +609,3 @@ int main_menu(void) return do_menu(NULL, 0) == MENU_ATTACHED_USB; } -/* wrappers for the old menu system to work with the new system */ - - -static int menu_find_free(void) -{ - int i; - /* Tries to find an unused slot to put the new menu */ - for ( i=0; ivalue].callback) - { - int val = menus[this_item->value].callback(action, this_item->value); - switch (val) - { - case MENU_SELECTED_EXIT: - return ACTION_EXIT_MENUITEM; - } - return val; - } - return action; -} - -static char* oldmenuwrapper_getname(int selected_item, - void * data, char *buffer) -{ - (void)buffer; - unsigned char* desc = menus[(intptr_t)data].items[selected_item].desc; - return P2STR(desc); -} - -#ifdef HAVE_LCD_BITMAP -static int oldmenu_get_icon(int selected_item, void * data) -{ - (void)data; (void)selected_item; - return Icon_Menu_functioncall; -} -#endif - -static void init_oldmenu(const struct menu_item_ex *menu, - struct gui_synclist *lists, int selected, bool callback) -{ - (void)callback; - gui_synclist_init(lists, oldmenuwrapper_getname, - (void*)(intptr_t)menu->value, false, 1); - gui_synclist_set_nb_items(lists, MENU_GET_COUNT(menu->flags)); - gui_synclist_limit_scroll(lists, true); -#ifdef HAVE_LCD_BITMAP - gui_synclist_set_title(lists, menus[menu->value].title, - Icon_Submenu_Entered); - gui_synclist_set_icon_callback(lists, oldmenu_get_icon); -#endif - gui_synclist_select_item(lists, selected); -} - -static void menu_talk_selected(int m) -{ - int selected = menus[m].current_selection; - int voice_id = P2ID(menus[m].items[selected].desc); - if (voice_id >= 0) /* valid ID given? */ - talk_id(voice_id, false); /* say it */ -} - -int menu_show(int m) -{ - int value; - struct menu_item_ex menu; - struct menu_get_name_and_icon menu_info = - { - oldmenuwrapper_callback, - oldmenuwrapper_getname, - (void*)(intptr_t)m, Icon_Submenu - }; - - menu.flags = (MENU_TYPE_MASK&MT_OLD_MENU) | MENU_DYNAMIC_DESC | - MENU_ITEM_COUNT(menus[m].count); - menu.value = m; - menu.menu_get_name_and_icon = &menu_info; - value = do_menu(&menu, &menus[m].current_selection); - switch (value) - { - case MENU_ATTACHED_USB: - case GO_TO_ROOT: - return MENU_ATTACHED_USB; - case GO_TO_PREVIOUS: - return MENU_SELECTED_EXIT; - default: - if (value >= 0) - return menus[m].current_selection; - else return value; - } -} - - -bool menu_run(int m) -{ - int selected; - while (1) { - switch (selected=menu_show(m)) - { - case MENU_SELECTED_EXIT: - return false; - - case MENU_ATTACHED_USB: - return true; - - default: - { - if (selected >= 0 && selected < menus[m].count) - { - if (menus[m].items[selected].function && - menus[m].items[selected].function()) - return true; - } - gui_syncstatusbar_draw(&statusbars, true); - } - } - } - return false; -} - -/* - * Property function - return the "count" of menu items in "menu" - */ - -int menu_count(int menu) -{ - return menus[menu].count; -} - diff --git a/apps/menu.h b/apps/menu.h index 7e08ef5aac..7b26bbc90c 100644 --- a/apps/menu.h +++ b/apps/menu.h @@ -35,8 +35,6 @@ enum menu_item_type { MT_FUNCTION_CALL, /* call a function from the menus */ MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/ MT_RETURN_VALUE, /* returns a value associated with an item */ - MT_OLD_MENU, /* used so we can wrap the old menu api - around the new api. Noone else should use this */ }; #define MENU_TYPE_MASK 0xF /* MT_* type */ @@ -192,22 +190,4 @@ bool do_setting_from_menu(const struct menu_item_ex *temp); { (void*)name##_},{.callback_and_desc = & name##__}}; -/* OLD API - This is only here for plugin compatability now, will be dropped ASAP */ -struct menu_item { - unsigned char *desc; /* string or ID */ - bool (*function) (void); /* return true if USB was connected */ -}; - -/* if button2 == button3 == NULL, button1 is the menu title */ -int menu_init(const struct menu_item* mitems, int count, - int (*callback)(int, int), - const char *button1, const char *button2, const char *button3); -void menu_exit(int menu); - - /* Returns MENU_* define from root_menu.h, or number of selected menu item*/ -int menu_show(int m); - -bool menu_run(int menu); -int menu_count(int menu); - #endif /* End __MENU_H__ */ diff --git a/apps/plugin.c b/apps/plugin.c index 1478805e2c..379c154bad 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -397,12 +397,10 @@ static const struct plugin_api rockbox_api = { /* menu */ do_menu, - /* OLD API - dont use unless you have to */ - menu_init, - menu_exit, - menu_show, - menu_run, - menu_count, + /* statusbars */ + &statusbars, + gui_syncstatusbar_draw, + /* options */ set_option, set_int, set_bool, diff --git a/apps/plugin.h b/apps/plugin.h index e04b0e20d5..08d320ed57 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -74,6 +74,7 @@ #ifdef HAVE_LCD_BITMAP #include "scrollbar.h" #endif +#include "statusbar.h" #include "menu.h" #include "rbunicode.h" #include "list.h" @@ -113,12 +114,12 @@ #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 55 +#define PLUGIN_API_VERSION 56 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 54 +#define PLUGIN_MIN_API_VERSION 56 /* plugin return codes */ enum plugin_status { @@ -495,15 +496,12 @@ struct plugin_api { /* menu */ int (*do_menu)(const struct menu_item_ex *menu, int *start_selected); - /* OLD API - dont use unless you have to */ - int (*menu_init)(const struct menu_item* mitems, int count, - int (*callback)(int, int), - const char *button1, const char *button2, const char *button3); - void (*menu_exit)(int menu); - int (*menu_show)(int m); - bool (*menu_run)(int menu); - int (*menu_count)(int menu); + /* scroll bar */ + struct gui_syncstatusbar *statusbars; + void (*gui_syncstatusbar_draw)(struct gui_syncstatusbar * bars, bool force_redraw); + + /* options */ bool (*set_option)(const char* string, void* variable, enum optiontype type, const struct opt_items* options, int numoptions, void (*function)(int)); diff --git a/apps/plugins/clock.c b/apps/plugins/clock.c index 59b98247b8..3c70759da6 100644 --- a/apps/plugins/clock.c +++ b/apps/plugins/clock.c @@ -92,6 +92,7 @@ Original release, featuring analog/digital modes and a few options. #include "time.h" #include "checkbox.h" #include "xlcd.h" +#include "oldmenuapi.h" PLUGIN_HEADER @@ -1177,12 +1178,12 @@ void analog_settings_menu(void) rb->lcd_set_foreground(LCD_BLACK); #endif - m = rb->menu_init(analog_items, sizeof(analog_items) / sizeof(*analog_items), + m = menu_init(rb, analog_items, sizeof(analog_items) / sizeof(*analog_items), NULL, NULL, NULL, NULL); while(!done) { - result = rb->menu_show(m); + result = menu_show(m); switch(result) { @@ -1204,7 +1205,7 @@ void analog_settings_menu(void) break; } - rb->menu_exit(m); + menu_exit(m); } } @@ -1222,12 +1223,12 @@ void digital_settings_menu(void) rb->lcd_set_foreground(LCD_BLACK); #endif - m = rb->menu_init(digital_items, sizeof(digital_items) / sizeof(*digital_items), + m = menu_init(rb, digital_items, sizeof(digital_items) / sizeof(*digital_items), NULL, NULL, NULL, NULL); while(!done) { - result = rb->menu_show(m); + result = menu_show(m); switch(result) { @@ -1253,7 +1254,7 @@ void digital_settings_menu(void) break; } - rb->menu_exit(m); + menu_exit(m); } } @@ -1271,12 +1272,12 @@ void fullscreen_settings_menu(void) rb->lcd_set_foreground(LCD_BLACK); #endif - m = rb->menu_init(fullscreen_items, sizeof(fullscreen_items) / sizeof(*fullscreen_items), + m = menu_init(rb, fullscreen_items, sizeof(fullscreen_items) / sizeof(*fullscreen_items), NULL, NULL, NULL, NULL); while(!done) { - result = rb->menu_show(m); + result = menu_show(m); switch(result) { @@ -1294,7 +1295,7 @@ void fullscreen_settings_menu(void) break; } - rb->menu_exit(m); + menu_exit(m); } } @@ -1312,12 +1313,12 @@ void binary_settings_menu(void) rb->lcd_set_foreground(LCD_BLACK); #endif - m = rb->menu_init(binary_items, sizeof(binary_items) / sizeof(*binary_items), + m = menu_init(rb,binary_items, sizeof(binary_items) / sizeof(*binary_items), NULL, NULL, NULL, NULL); while(!done) { - result = rb->menu_show(m); + result = menu_show(m); switch(result) { @@ -1331,7 +1332,7 @@ void binary_settings_menu(void) break; } - rb->menu_exit(m); + menu_exit(m); } } @@ -1349,12 +1350,12 @@ void plain_settings_menu(void) rb->lcd_set_foreground(LCD_BLACK); #endif - m = rb->menu_init(plain_items, sizeof(plain_items) / sizeof(*plain_items), + m = menu_init(rb,plain_items, sizeof(plain_items) / sizeof(*plain_items), NULL, NULL, NULL, NULL); while(!done) { - result = rb->menu_show(m); + result = menu_show(m); switch(result) { @@ -1380,7 +1381,7 @@ void plain_settings_menu(void) break; } - rb->menu_exit(m); + menu_exit(m); } } @@ -1434,12 +1435,12 @@ void general_settings(void) set_standard_colors(); - m = rb->menu_init(general_settings_items, sizeof(general_settings_items) / sizeof(*general_settings_items), + m = menu_init(rb,general_settings_items, sizeof(general_settings_items) / sizeof(*general_settings_items), NULL, NULL, NULL, NULL); while(!done) { - result = rb->menu_show(m); + result = menu_show(m); switch(result) { @@ -1481,7 +1482,7 @@ void general_settings(void) break; } - rb->menu_exit(m); + menu_exit(m); } set_digital_colors(); @@ -1700,12 +1701,12 @@ void mode_selector(void) set_standard_colors(); - m = rb->menu_init(mode_selector_items, sizeof(mode_selector_items) / sizeof(*mode_selector_items), + m = menu_init(rb,mode_selector_items, sizeof(mode_selector_items) / sizeof(*mode_selector_items), NULL, NULL, NULL, NULL); while(!done) { - result = rb->menu_show(m); + result = menu_show(m); /* check for this, so if the user exits the menu without * making a selection, it won't change to some weird value. */ @@ -1714,7 +1715,7 @@ void mode_selector(void) done = true; - rb->menu_exit(m); + menu_exit(m); } set_digital_colors(); @@ -1830,12 +1831,12 @@ void main_menu(void) set_standard_colors(); - m = rb->menu_init(main_menu_items, sizeof(main_menu_items) / sizeof(*main_menu_items), + m = menu_init(rb,main_menu_items, sizeof(main_menu_items) / sizeof(*main_menu_items), NULL, NULL, NULL, NULL); while(!done) { - result = rb->menu_show(m); + result = menu_show(m); switch(result) { @@ -1866,7 +1867,7 @@ void main_menu(void) break; } - rb->menu_exit(m); + menu_exit(m); } rb->lcd_setfont(FONT_SYSFIXED); diff --git a/apps/plugins/doom/rockdoom.c b/apps/plugins/doom/rockdoom.c index 1081324974..82daadb24e 100644 --- a/apps/plugins/doom/rockdoom.c +++ b/apps/plugins/doom/rockdoom.c @@ -37,6 +37,7 @@ #include "i_system.h" #include "hu_stuff.h" #include "st_stuff.h" +#include "lib/oldmenuapi.h" PLUGIN_HEADER PLUGIN_IRAM_DECLARE @@ -490,12 +491,12 @@ int Oset_keys() { "Game Automap", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); while(!menuquit) { - result=rb->menu_show(m); + result=menu_show(m); if(result<0) menuquit=1; else @@ -506,7 +507,7 @@ int Oset_keys() } } - rb->menu_exit(m); + menu_exit(m); return (1); } @@ -554,12 +555,12 @@ static bool Doptions() #endif }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); while(!menuquit) { - result=rb->menu_show(m); + result=menu_show(m); if(result==0) Oset_keys(); else if (result > 0) @@ -568,7 +569,7 @@ static bool Doptions() menuquit=1; } - rb->menu_exit(m); + menu_exit(m); return (1); } @@ -577,10 +578,10 @@ int menuchoice(struct menu_item *menu, int items) { int m, result; - m = rb->menu_init(menu, items,NULL, NULL, NULL, NULL); + m = menu_init(rb, menu, items,NULL, NULL, NULL, NULL); - result= rb->menu_show(m); - rb->menu_exit(m); + result= menu_show(m); + menu_exit(m); if(result=0) return result; return 0; @@ -627,12 +628,12 @@ int doom_menu() while (rb->button_get(false) != BUTTON_NONE) rb->yield(); - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); while(!menuquit) { - result=rb->menu_show(m); + result=menu_show(m); switch (result) { case 0: /* Game picker */ rb->set_option("Game WAD", &gamever, INT, names, status, NULL ); @@ -664,7 +665,7 @@ int doom_menu() } } - rb->menu_exit(m); + menu_exit(m); return (gamever); } diff --git a/apps/plugins/fireworks.c b/apps/plugins/fireworks.c index f564b68b85..08d4e00d68 100644 --- a/apps/plugins/fireworks.c +++ b/apps/plugins/fireworks.c @@ -17,6 +17,7 @@ * ****************************************************************************/ #include "plugin.h" +#include "oldmenuapi.h" PLUGIN_HEADER @@ -303,14 +304,14 @@ void fireworks_menu(void) rb->lcd_clear_display(); rb->lcd_update(); - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); rb->button_clear_queue(); while(!menu_quit) { - result = rb->menu_show(m); + result = menu_show(m); switch(result) { @@ -360,7 +361,7 @@ void fireworks_menu(void) } } - rb->menu_exit(m); + menu_exit(m); } /* this is the plugin entry point */ diff --git a/apps/plugins/jpeg.c b/apps/plugins/jpeg.c index f04d704b2e..55eade1228 100644 --- a/apps/plugins/jpeg.c +++ b/apps/plugins/jpeg.c @@ -26,6 +26,7 @@ #include "plugin.h" #include "playback_control.h" +#include "oldmenuapi.h" #ifdef HAVE_LCD_BITMAP #include "gray.h" @@ -2415,10 +2416,10 @@ static void display_options(void) { "Dithering", set_option_dithering }, }; - int m = rb->menu_init(items, ARRAYLEN(items), + int m = menu_init(rb, items, ARRAYLEN(items), NULL, NULL, NULL, NULL); - rb->menu_run(m); - rb->menu_exit(m); + menu_run(m); + menu_exit(m); } #endif /* HAVE_LCD_COLOR */ @@ -2490,14 +2491,14 @@ int show_menu(void) /* return 1 to quit */ { "20 seconds", -1 }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - result=rb->menu_show(m); + result=menu_show(m); switch (result) { case MIID_QUIT: - rb->menu_exit(m); + menu_exit(m); return 1; break; case MIID_TOGGLE_SS_MODE: @@ -2561,7 +2562,7 @@ int show_menu(void) /* return 1 to quit */ rb->lcd_set_background(LCD_BLACK); #endif rb->lcd_clear_display(); - rb->menu_exit(m); + menu_exit(m); return 0; } /* interactively scroll around the image */ diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES index adb3d68260..03a990acda 100644 --- a/apps/plugins/lib/SOURCES +++ b/apps/plugins/lib/SOURCES @@ -1,3 +1,4 @@ +oldmenuapi.c configfile.c fixedpoint.c playback_control.c diff --git a/apps/plugins/lib/oldmenuapi.c b/apps/plugins/lib/oldmenuapi.c new file mode 100644 index 0000000000..e804a64d62 --- /dev/null +++ b/apps/plugins/lib/oldmenuapi.c @@ -0,0 +1,241 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 Robert E. Hak + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +/* +2005 Kevin Ferrare : + - Multi screen support + - Rewrote/removed a lot of code now useless with the new gui API +*/ +#include +#include + +#include "plugin.h" +#include "oldmenuapi.h" + +struct plugin_api *rb = NULL; + +struct menu { + struct menu_item* items; + int (*callback)(int, int); + struct gui_synclist synclist; +}; + +#define MAX_MENUS 6 + +static struct menu menus[MAX_MENUS]; +static bool inuse[MAX_MENUS] = { false }; + +static char * menu_get_itemname(int selected_item, void * data, char *buffer) +{ + struct menu *local_menus=(struct menu *)data; + (void)buffer; + return(local_menus->items[selected_item].desc); +} + +static int menu_find_free(void) +{ + int i; + /* Tries to find an unused slot to put the new menu */ + for ( i=0; igui_synclist_init(&(menus[menu].synclist), + &menu_get_itemname, &menus[menu], false, 1); + rb->gui_synclist_set_icon_callback(&(menus[menu].synclist), NULL); + rb->gui_synclist_set_nb_items(&(menus[menu].synclist), count); + menus[menu].callback = callback; + (void)button1; + (void)button2; + (void)button3; + return menu; +} + +void menu_exit(int m) +{ + inuse[m] = false; +} + +int menu_show(int m) +{ + bool exit = false; + int key; + + rb->gui_synclist_draw(&(menus[m].synclist)); + rb->action_signalscreenchange(); + rb->gui_syncstatusbar_draw(rb->statusbars, true); + while (!exit) { + key = rb->get_action(CONTEXT_MAINMENU,HZ/2); + /* + * "short-circuit" the default keypresses by running the + * callback function + * The callback may return a new key value, often this will be + * BUTTON_NONE or the same key value, but it's perfectly legal + * to "simulate" key presses by returning another value. + */ + if( menus[m].callback != NULL ) + key = menus[m].callback(key, m); + rb->gui_synclist_do_button(&(menus[m].synclist), key,LIST_WRAP_UNLESS_HELD); + switch( key ) { + case ACTION_STD_OK: + rb->action_signalscreenchange(); + return rb->gui_synclist_get_sel_pos(&(menus[m].synclist)); + + + case ACTION_STD_CANCEL: + case ACTION_STD_MENU: + exit = true; + break; + + default: + if(rb->default_event_handler(key) == SYS_USB_CONNECTED) + return MENU_ATTACHED_USB; + break; + } + rb->gui_syncstatusbar_draw(rb->statusbars, false); + } + rb->action_signalscreenchange(); + return MENU_SELECTED_EXIT; +} + + +bool menu_run(int m) +{ + int selected; + while (1) { + switch (selected=menu_show(m)) + { + case MENU_SELECTED_EXIT: + return false; + + case MENU_ATTACHED_USB: + return true; + + default: + { + if (menus[m].items[selected].function && + menus[m].items[selected].function()) + return true; + rb->gui_syncstatusbar_draw(rb->statusbars, true); + } + } + } + return false; +} + +/* + * Property function - return the current cursor for "menu" + */ + +int menu_cursor(int menu) +{ + return rb->gui_synclist_get_sel_pos(&(menus[menu].synclist)); +} + +/* + * Property function - return the "menu" description at "position" + */ + +char* menu_description(int menu, int position) +{ + return menus[menu].items[position].desc; +} + +/* + * Delete the element "position" from the menu items in "menu" + */ + +void menu_delete(int menu, int position) +{ + int i; + int nb_items=rb->gui_synclist_get_nb_items(&(menus[menu].synclist)); + /* copy the menu item from the one below */ + for( i = position; i < nb_items - 1; i++) + menus[menu].items[i] = menus[menu].items[i + 1]; + + rb->gui_synclist_del_item(&(menus[menu].synclist)); +} + +void menu_insert(int menu, int position, char *desc, bool (*function) (void)) +{ + int i; + int nb_items=rb->gui_synclist_get_nb_items(&(menus[menu].synclist)); + if(position < 0) + position = nb_items; + + /* Move the items below one position forward */ + for( i = nb_items; i > position; i--) + menus[menu].items[i] = menus[menu].items[i - 1]; + + /* Update the current item */ + menus[menu].items[position].desc = (unsigned char *)desc; + menus[menu].items[position].function = function; + rb->gui_synclist_add_item(&(menus[menu].synclist)); +} + +/* + * Property function - return the "count" of menu items in "menu" + */ + +int menu_count(int menu) +{ + return rb->gui_synclist_get_nb_items(&(menus[menu].synclist)); +} + +/* + * Allows to set the cursor position. Doesn't redraw by itself. + */ + +void menu_set_cursor(int menu, int position) +{ + rb->gui_synclist_select_item(&(menus[menu].synclist), position); +} +#if 0 +void menu_talk_selected(int m) +{ + if(rb->global_settings->talk_menu) + { + int selected=rb->gui_synclist_get_sel_pos(&(menus[m].synclist)); + int voice_id = P2ID(menus[m].items[selected].desc); + if (voice_id >= 0) /* valid ID given? */ + talk_id(voice_id, false); /* say it */ + } +} +#endif +void menu_draw(int m) +{ + rb->gui_synclist_draw(&(menus[m].synclist)); +} diff --git a/apps/plugins/lib/oldmenuapi.h b/apps/plugins/lib/oldmenuapi.h new file mode 100644 index 0000000000..34f6226d59 --- /dev/null +++ b/apps/plugins/lib/oldmenuapi.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 Robert E. Hak + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + + +/* This API is for existing plugins and shouldn't be used by new ones. + This provides a simpler menu system for plugins, but does not allow for + translatable or talkable strings in the menus. */ +#ifndef __OLDMENUAPI_H__ +#define __OLDMENUAPI_H__ + +#include + +struct menu_item { + unsigned char *desc; /* string or ID */ + bool (*function) (void); /* return true if USB was connected */ +}; + +int menu_init(struct plugin_api *api, const struct menu_item* mitems, + int count, int (*callback)(int, int), + const char *button1, const char *button2, const char *button3); +void menu_exit(int menu); + +void put_cursorxy(int x, int y, bool on); + + /* Returns below define, or number of selected menu item*/ +int menu_show(int m); + +bool menu_run(int menu); +int menu_cursor(int menu); +char* menu_description(int menu, int position); +void menu_delete(int menu, int position); +int menu_count(int menu); +bool menu_moveup(int menu); +bool menu_movedown(int menu); +void menu_draw(int menu); +void menu_insert(int menu, int position, char *desc, bool (*function) (void)); +void menu_set_cursor(int menu, int position); +void menu_talk_selected(int m); + +#endif /* End __OLDMENUAPI_H__ */ diff --git a/apps/plugins/mpegplayer/mpeg_settings.c b/apps/plugins/mpegplayer/mpeg_settings.c index c692edf861..964bad08bd 100644 --- a/apps/plugins/mpegplayer/mpeg_settings.c +++ b/apps/plugins/mpegplayer/mpeg_settings.c @@ -1,5 +1,6 @@ #include "plugin.h" #include "lib/configfile.h" +#include "lib/oldmenuapi.h" #include "mpeg_settings.h" @@ -41,13 +42,13 @@ bool mpeg_menu(void) { "Quit mpegplayer", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); rb->button_clear_queue(); while (!menu_quit) { - result=rb->menu_show(m); + result=menu_show(m); switch(result) { @@ -71,7 +72,7 @@ bool mpeg_menu(void) } } - rb->menu_exit(m); + menu_exit(m); rb->lcd_clear_display(); rb->lcd_update(); diff --git a/apps/plugins/pacbox/pacbox.c b/apps/plugins/pacbox/pacbox.c index 3a56430106..712c3aff77 100644 --- a/apps/plugins/pacbox/pacbox.c +++ b/apps/plugins/pacbox/pacbox.c @@ -27,6 +27,7 @@ #include "pacbox.h" #include "pacbox_lcd.h" #include "lib/configfile.h" +#include "lib/oldmenuapi.h" PLUGIN_HEADER PLUGIN_IRAM_DECLARE @@ -178,13 +179,13 @@ static bool pacbox_menu(void) { "Quit", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); rb->button_clear_queue(); while (!menu_quit) { - result=rb->menu_show(m); + result=menu_show(m); switch(result) { @@ -238,7 +239,7 @@ static bool pacbox_menu(void) } } - rb->menu_exit(m); + menu_exit(m); if (need_restart) { init_PacmanMachine(settings_to_dip(settings)); diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c index 7f498f7532..abe7bfdfbf 100644 --- a/apps/plugins/random_folder_advance_config.c +++ b/apps/plugins/random_folder_advance_config.c @@ -17,6 +17,7 @@ * ****************************************************************************/ #include "plugin.h" +#include "oldmenuapi.h" PLUGIN_HEADER @@ -194,10 +195,10 @@ void edit_list(void) { "Remove Folder", NULL }, { "Remove Folder Tree", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - switch (rb->menu_show(m)) + switch (menu_show(m)) { case 0: list->folder[selection][0] = ' '; @@ -219,7 +220,7 @@ void edit_list(void) } break; } - rb->menu_exit(m); + menu_exit(m); } break; case ACTION_STD_CANCEL: @@ -229,10 +230,10 @@ void edit_list(void) { "Save and Exit", NULL }, { "Ignore Changes and Exit", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - switch (rb->menu_show(m)) + switch (menu_show(m)) { case 0: exit = true; @@ -259,7 +260,7 @@ void edit_list(void) case 1: exit = true; } - rb->menu_exit(m); + menu_exit(m); } break; } @@ -273,10 +274,10 @@ int main_menu(void) { "Edit Folder List", NULL }, { "Quit", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - switch (rb->menu_show(m)) + switch (menu_show(m)) { case 0: /* generate */ #ifdef HAVE_ADJUSTABLE_CPU_FREQ @@ -305,10 +306,10 @@ int main_menu(void) rb->backlight_on(); break; case 2: - rb->menu_exit(m); + menu_exit(m); return 1; } - rb->menu_exit(m); + menu_exit(m); return 0; } diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c index a3d64d60d0..ca15cba7b9 100644 --- a/apps/plugins/rockboy/menu.c +++ b/apps/plugins/rockboy/menu.c @@ -7,6 +7,7 @@ #include "button.h" #include "rockmacros.h" #include "mem.h" +#include "lib/oldmenuapi.h" #if (CONFIG_KEYPAD == IPOD_4G_PAD) #define MENU_BUTTON_UP BUTTON_SCROLL_BACK @@ -101,11 +102,11 @@ int do_user_menu(void) { pcm_init(); - m = rb->menu_init(items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); + m = menu_init(rb,items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); while(!done) { - result=rb->menu_show(m); + result=menu_show(m); switch (result) { @@ -128,7 +129,7 @@ int do_user_menu(void) { } } - rb->menu_exit(m); + menu_exit(m); rb->lcd_setfont(0); /* Reset the font */ rb->lcd_clear_display(); /* Clear display for screen size changes */ @@ -303,18 +304,18 @@ static void do_slot_menu(bool is_load) { for (i = 0; i < num_items; i++) slot_info(buf[i], 20, i); - m = rb->menu_init(items, num_items, NULL, NULL, NULL, NULL); + m = menu_init(rb,items, num_items, NULL, NULL, NULL, NULL); while(!done) { - result=rb->menu_show(m); + result=menu_show(m); if (result= 0 ) done = do_slot(result, is_load); else done = true; } - rb->menu_exit(m); + menu_exit(m); } static void do_opt_menu(void) @@ -374,12 +375,12 @@ static void do_opt_menu(void) #endif }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); + m = menu_init(rb,items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); while(!done) { - result=rb->menu_show(m); + result=menu_show(m); switch (result) { @@ -414,5 +415,5 @@ static void do_opt_menu(void) break; } } - rb->menu_exit(m); + menu_exit(m); } diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c index a73e2c02ed..85d4efd3a9 100644 --- a/apps/plugins/solitaire.c +++ b/apps/plugins/solitaire.c @@ -36,6 +36,7 @@ use F3 to put card on top of the remains' stack on one of the 4 final stacks #include "configfile.h" #include "button.h" #include "lcd.h" +#include "oldmenuapi.h" #ifdef HAVE_LCD_BITMAP @@ -612,10 +613,10 @@ int solitaire_menu(bool in_game) create_draw_option_string(); create_unhide_option_string(); - m = rb->menu_init(items, i, NULL, NULL, NULL, NULL); + m = menu_init(rb, items, i, NULL, NULL, NULL, NULL); while (result < 0) { - switch (rb->menu_show(m)) + switch (menu_show(m)) { case MENU_SELECTED_EXIT: result = MENU_RESUME; @@ -662,7 +663,7 @@ int solitaire_menu(bool in_game) break; } } - rb->menu_exit(m); + menu_exit(m); rb->lcd_setmargins(0, 0); return result; } diff --git a/apps/plugins/sudoku/sudoku.c b/apps/plugins/sudoku/sudoku.c index 59adb77fa9..fcf1566d65 100644 --- a/apps/plugins/sudoku/sudoku.c +++ b/apps/plugins/sudoku/sudoku.c @@ -57,6 +57,7 @@ Example ".ss" file, and one with a saved state: */ #include "plugin.h" +#include "lib/oldmenuapi.h" #ifdef HAVE_LCD_BITMAP @@ -1007,10 +1008,10 @@ bool sudoku_menu(struct sudoku_state_t* state) { "Quit", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb,items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - result=rb->menu_show(m); + result=menu_show(m); switch (result) { case 0: /* Audio playback */ @@ -1044,7 +1045,7 @@ bool sudoku_menu(struct sudoku_state_t* state) case 7: /* Quit */ save_sudoku(state); - rb->menu_exit(m); + menu_exit(m); return true; break; @@ -1052,7 +1053,7 @@ bool sudoku_menu(struct sudoku_state_t* state) break; } - rb->menu_exit(m); + menu_exit(m); return (result==MENU_ATTACHED_USB); } @@ -1068,10 +1069,10 @@ int sudoku_edit_menu(struct sudoku_state_t* state) { "Quit", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb,items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - result=rb->menu_show(m); + result=menu_show(m); switch (result) { case 0: /* Save new game */ @@ -1090,7 +1091,7 @@ int sudoku_edit_menu(struct sudoku_state_t* state) break; } - rb->menu_exit(m); + menu_exit(m); return result; } diff --git a/apps/plugins/test_disk.c b/apps/plugins/test_disk.c index cda1d614c0..c46774d8a0 100644 --- a/apps/plugins/test_disk.c +++ b/apps/plugins/test_disk.c @@ -18,6 +18,7 @@ ****************************************************************************/ #include "plugin.h" +#include "oldmenuapi.h" PLUGIN_HEADER @@ -314,10 +315,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) if (rb->global_settings->backlight_timeout > 0) rb->backlight_set_timeout(1); /* keep the light on */ - m = rb->menu_init(items, sizeof(items) / sizeof(*items), NULL, + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - rb->menu_run(m); - rb->menu_exit(m); + menu_run(m); + menu_exit(m); /* restore normal backlight setting */ rb->backlight_set_timeout(rb->global_settings->backlight_timeout); diff --git a/apps/plugins/test_sampr.c b/apps/plugins/test_sampr.c index 891e68ffda..253c592eaa 100644 --- a/apps/plugins/test_sampr.c +++ b/apps/plugins/test_sampr.c @@ -17,6 +17,7 @@ * ****************************************************************************/ #include "plugin.h" +#include "oldmenuapi.h" PLUGIN_HEADER @@ -271,12 +272,12 @@ enum plugin_status plugin_start(struct plugin_api *api, void *parameter) talk_menu = rb->global_settings->talk_menu; rb->global_settings->talk_menu = false; - m = rb->menu_init(items, ARRAYLEN(items), + m = menu_init(rb, items, ARRAYLEN(items), NULL, NULL, NULL, NULL); while (!exit) { - int result = rb->menu_show(m); + int result = menu_show(m); switch (result) { @@ -292,7 +293,7 @@ enum plugin_status plugin_start(struct plugin_api *api, void *parameter) } } - rb->menu_exit(m); + menu_exit(m); rb->global_settings->talk_menu = talk_menu; diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c index d95bdb9b81..523cbad30c 100644 --- a/apps/plugins/text_editor.c +++ b/apps/plugins/text_editor.c @@ -18,6 +18,7 @@ ****************************************************************************/ #include "plugin.h" #include "action.h" +#include "oldmenuapi.h" #if PLUGIN_BUFFER_SIZE > 0x45000 #define MAX_CHARS 0x40000 /* 128 kiB */ @@ -228,10 +229,10 @@ int do_item_menu(int cur_sel, char* copy_buffer) { "", NULL }, { "Save", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - switch (rb->menu_show(m)) + switch (menu_show(m)) { case 0: /* cut */ rb->strcpy(copy_buffer,&buffer[do_action(ACTION_GET,0,cur_sel)]); @@ -279,7 +280,7 @@ int do_item_menu(int cur_sel, char* copy_buffer) ret = MENU_RET_NO_UPDATE; break; } - rb->menu_exit(m); + menu_exit(m); return ret; } /* this is the plugin entry point */ @@ -409,10 +410,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { "Ignore Changes and Exit", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - result=rb->menu_show(m); + result=menu_show(m); switch (result) { @@ -435,7 +436,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) exit=1; break; } - rb->menu_exit(m); + menu_exit(m); } else exit=1; break; diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c index 07392d49c3..d3f74e6514 100644 --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c @@ -20,6 +20,7 @@ #include "plugin.h" #include #include "playback_control.h" +#include "oldmenuapi.h" PLUGIN_HEADER @@ -1283,11 +1284,11 @@ static bool viewer_options_menu(void) {"Scroll Mode", scroll_mode_setting}, {"Auto-Scroll Speed", autoscroll_speed_setting }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - result = rb->menu_run(m); - rb->menu_exit(m); + result = menu_run(m); + menu_exit(m); #ifdef HAVE_LCD_BITMAP rb->lcd_setmargins(0,0); @@ -1310,13 +1311,13 @@ static void viewer_menu(void) {"Return", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - result=rb->menu_show(m); + m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); + result=menu_show(m); switch (result) { case 0: /* quit */ rb->splash(1, "Saving Settings"); - rb->menu_exit(m); + menu_exit(m); viewer_exit(NULL); done = true; break; @@ -1329,7 +1330,7 @@ static void viewer_menu(void) case 3: /* return */ break; } - rb->menu_exit(m); + menu_exit(m); #ifdef HAVE_LCD_BITMAP rb->lcd_setmargins(0,0); #endif diff --git a/apps/plugins/zxbox/spmain.c b/apps/plugins/zxbox/spmain.c index 036e28a240..b153b4191f 100644 --- a/apps/plugins/zxbox/spmain.c +++ b/apps/plugins/zxbox/spmain.c @@ -20,6 +20,7 @@ #include "misc.h" #include "zxconfig.h" #include "lib/configfile.h" +#include "lib/oldmenuapi.h" #include "spperif.h" #include "z80.h" @@ -142,13 +143,13 @@ static void set_keys(void){ { "Map Fire/Jump key", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb,items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); rb->button_clear_queue(); while (!menu_quit) { - result=rb->menu_show(m); + result=menu_show(m); switch(result) { @@ -188,7 +189,7 @@ static void set_keys(void){ } } - rb->menu_exit(m); + menu_exit(m); } /* select predefined keymap */ @@ -202,13 +203,13 @@ static void select_keymap(void){ { "7658S", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb,items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); rb->button_clear_queue(); while (!menu_quit) { - result=rb->menu_show(m); + result=menu_show(m); switch(result) { @@ -230,7 +231,7 @@ static void select_keymap(void){ } } - rb->menu_exit(m); + menu_exit(m); } /* options menu */ @@ -267,13 +268,13 @@ static void options_menu(void){ }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb,items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); rb->button_clear_queue(); while (!menu_quit) { - result=rb->menu_show(m); + result=menu_show(m); switch(result) { @@ -336,7 +337,7 @@ static void options_menu(void){ } } - rb->menu_exit(m); + menu_exit(m); } /* menu */ @@ -361,13 +362,13 @@ static bool zxbox_menu(void) { "Quit", NULL }, }; - m = rb->menu_init(items, sizeof(items) / sizeof(*items), + m = menu_init(rb,items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); rb->button_clear_queue(); while (!menu_quit) { - result=rb->menu_show(m); + result=menu_show(m); switch(result) { @@ -411,7 +412,7 @@ static bool zxbox_menu(void) } } - rb->menu_exit(m); + menu_exit(m); #if defined(HAVE_ADJUSTABLE_CPU_FREQ) rb->cpu_boost(true); #endif -- cgit v1.2.3