summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/oldmenuapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lib/oldmenuapi.c')
-rw-r--r--apps/plugins/lib/oldmenuapi.c241
1 files changed, 241 insertions, 0 deletions
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Robert E. Hak
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19/*
202005 Kevin Ferrare :
21 - Multi screen support
22 - Rewrote/removed a lot of code now useless with the new gui API
23*/
24#include <stdbool.h>
25#include <stdlib.h>
26
27#include "plugin.h"
28#include "oldmenuapi.h"
29
30struct plugin_api *rb = NULL;
31
32struct menu {
33 struct menu_item* items;
34 int (*callback)(int, int);
35 struct gui_synclist synclist;
36};
37
38#define MAX_MENUS 6
39
40static struct menu menus[MAX_MENUS];
41static bool inuse[MAX_MENUS] = { false };
42
43static char * menu_get_itemname(int selected_item, void * data, char *buffer)
44{
45 struct menu *local_menus=(struct menu *)data;
46 (void)buffer;
47 return(local_menus->items[selected_item].desc);
48}
49
50static int menu_find_free(void)
51{
52 int i;
53 /* Tries to find an unused slot to put the new menu */
54 for ( i=0; i<MAX_MENUS; i++ ) {
55 if ( !inuse[i] ) {
56 inuse[i] = true;
57 break;
58 }
59 }
60 if ( i == MAX_MENUS ) {
61 DEBUGF("Out of menus!\n");
62 return -1;
63 }
64 return(i);
65}
66
67int menu_init(struct plugin_api *api, const struct menu_item* mitems,
68 int count, int (*callback)(int, int),
69 const char *button1, const char *button2, const char *button3)
70{
71 int menu=menu_find_free();
72 rb = api;
73 if(menu==-1)/* Out of menus */
74 return -1;
75 menus[menu].items = (struct menu_item*)mitems; /* de-const */
76 rb->gui_synclist_init(&(menus[menu].synclist),
77 &menu_get_itemname, &menus[menu], false, 1);
78 rb->gui_synclist_set_icon_callback(&(menus[menu].synclist), NULL);
79 rb->gui_synclist_set_nb_items(&(menus[menu].synclist), count);
80 menus[menu].callback = callback;
81 (void)button1;
82 (void)button2;
83 (void)button3;
84 return menu;
85}
86
87void menu_exit(int m)
88{
89 inuse[m] = false;
90}
91
92int menu_show(int m)
93{
94 bool exit = false;
95 int key;
96
97 rb->gui_synclist_draw(&(menus[m].synclist));
98 rb->action_signalscreenchange();
99 rb->gui_syncstatusbar_draw(rb->statusbars, true);
100 while (!exit) {
101 key = rb->get_action(CONTEXT_MAINMENU,HZ/2);
102 /*
103 * "short-circuit" the default keypresses by running the
104 * callback function
105 * The callback may return a new key value, often this will be
106 * BUTTON_NONE or the same key value, but it's perfectly legal
107 * to "simulate" key presses by returning another value.
108 */
109 if( menus[m].callback != NULL )
110 key = menus[m].callback(key, m);
111 rb->gui_synclist_do_button(&(menus[m].synclist), key,LIST_WRAP_UNLESS_HELD);
112 switch( key ) {
113 case ACTION_STD_OK:
114 rb->action_signalscreenchange();
115 return rb->gui_synclist_get_sel_pos(&(menus[m].synclist));
116
117
118 case ACTION_STD_CANCEL:
119 case ACTION_STD_MENU:
120 exit = true;
121 break;
122
123 default:
124 if(rb->default_event_handler(key) == SYS_USB_CONNECTED)
125 return MENU_ATTACHED_USB;
126 break;
127 }
128 rb->gui_syncstatusbar_draw(rb->statusbars, false);
129 }
130 rb->action_signalscreenchange();
131 return MENU_SELECTED_EXIT;
132}
133
134
135bool menu_run(int m)
136{
137 int selected;
138 while (1) {
139 switch (selected=menu_show(m))
140 {
141 case MENU_SELECTED_EXIT:
142 return false;
143
144 case MENU_ATTACHED_USB:
145 return true;
146
147 default:
148 {
149 if (menus[m].items[selected].function &&
150 menus[m].items[selected].function())
151 return true;
152 rb->gui_syncstatusbar_draw(rb->statusbars, true);
153 }
154 }
155 }
156 return false;
157}
158
159/*
160 * Property function - return the current cursor for "menu"
161 */
162
163int menu_cursor(int menu)
164{
165 return rb->gui_synclist_get_sel_pos(&(menus[menu].synclist));
166}
167
168/*
169 * Property function - return the "menu" description at "position"
170 */
171
172char* menu_description(int menu, int position)
173{
174 return menus[menu].items[position].desc;
175}
176
177/*
178 * Delete the element "position" from the menu items in "menu"
179 */
180
181void menu_delete(int menu, int position)
182{
183 int i;
184 int nb_items=rb->gui_synclist_get_nb_items(&(menus[menu].synclist));
185 /* copy the menu item from the one below */
186 for( i = position; i < nb_items - 1; i++)
187 menus[menu].items[i] = menus[menu].items[i + 1];
188
189 rb->gui_synclist_del_item(&(menus[menu].synclist));
190}
191
192void menu_insert(int menu, int position, char *desc, bool (*function) (void))
193{
194 int i;
195 int nb_items=rb->gui_synclist_get_nb_items(&(menus[menu].synclist));
196 if(position < 0)
197 position = nb_items;
198
199 /* Move the items below one position forward */
200 for( i = nb_items; i > position; i--)
201 menus[menu].items[i] = menus[menu].items[i - 1];
202
203 /* Update the current item */
204 menus[menu].items[position].desc = (unsigned char *)desc;
205 menus[menu].items[position].function = function;
206 rb->gui_synclist_add_item(&(menus[menu].synclist));
207}
208
209/*
210 * Property function - return the "count" of menu items in "menu"
211 */
212
213int menu_count(int menu)
214{
215 return rb->gui_synclist_get_nb_items(&(menus[menu].synclist));
216}
217
218/*
219 * Allows to set the cursor position. Doesn't redraw by itself.
220 */
221
222void menu_set_cursor(int menu, int position)
223{
224 rb->gui_synclist_select_item(&(menus[menu].synclist), position);
225}
226#if 0
227void menu_talk_selected(int m)
228{
229 if(rb->global_settings->talk_menu)
230 {
231 int selected=rb->gui_synclist_get_sel_pos(&(menus[m].synclist));
232 int voice_id = P2ID(menus[m].items[selected].desc);
233 if (voice_id >= 0) /* valid ID given? */
234 talk_id(voice_id, false); /* say it */
235 }
236}
237#endif
238void menu_draw(int m)
239{
240 rb->gui_synclist_draw(&(menus[m].synclist));
241}