summaryrefslogtreecommitdiff
path: root/apps/plugins/lib
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2009-06-16 04:25:21 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2009-06-16 04:25:21 +0000
commitaf9f4056510f248c4c9c1335167853bb455e8cc0 (patch)
treeeff7ad7726083ee605d753bd9aa9e22213b1acf0 /apps/plugins/lib
parentcb57a568e8dc9def607dc9ab27f515309bd13841 (diff)
downloadrockbox-af9f4056510f248c4c9c1335167853bb455e8cc0.tar.gz
rockbox-af9f4056510f248c4c9c1335167853bb455e8cc0.zip
Accept FS#10094 by Teruaki Kawashima:
Replace the old menu API with the "new" one (a very long time overdue so huge thanks for the work.) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21306 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r--apps/plugins/lib/SOURCES1
-rw-r--r--apps/plugins/lib/oldmenuapi.c237
-rw-r--r--apps/plugins/lib/oldmenuapi.h58
3 files changed, 0 insertions, 296 deletions
diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES
index 5a6abc7848..7211109271 100644
--- a/apps/plugins/lib/SOURCES
+++ b/apps/plugins/lib/SOURCES
@@ -1,6 +1,5 @@
1gcc-support.c 1gcc-support.c
2jhash.c 2jhash.c
3oldmenuapi.c
4configfile.c 3configfile.c
5fixedpoint.c 4fixedpoint.c
6playback_control.c 5playback_control.c
diff --git a/apps/plugins/lib/oldmenuapi.c b/apps/plugins/lib/oldmenuapi.c
deleted file mode 100644
index f14edabd38..0000000000
--- a/apps/plugins/lib/oldmenuapi.c
+++ /dev/null
@@ -1,237 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Robert E. Hak
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21/*
222005 Kevin Ferrare :
23 - Multi screen support
24 - Rewrote/removed a lot of code now useless with the new gui API
25*/
26#include <stdbool.h>
27#include <stdlib.h>
28
29#include "plugin.h"
30#include "oldmenuapi.h"
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,
44 char *buffer, size_t buffer_len)
45{
46 (void)buffer; (void)buffer_len;
47 struct menu *local_menus=(struct menu *)data;
48 return(local_menus->items[selected_item].desc);
49}
50
51static int menu_find_free(void)
52{
53 int i;
54 /* Tries to find an unused slot to put the new menu */
55 for ( i=0; i<MAX_MENUS; i++ ) {
56 if ( !inuse[i] ) {
57 inuse[i] = true;
58 break;
59 }
60 }
61 if ( i == MAX_MENUS ) {
62 DEBUGF("Out of menus!\n");
63 return -1;
64 }
65 return(i);
66}
67
68int menu_init(const struct menu_item* mitems,
69 int count, int (*callback)(int, int),
70 const char *button1, const char *button2, const char *button3)
71{
72 int menu=menu_find_free();
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, NULL);
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 int bars = rb->viewportmanager_set_statusbar(VP_SB_ALLSCREENS);
98 rb->gui_synclist_draw(&(menus[m].synclist));
99 while (!exit) {
100 key = rb->get_action(CONTEXT_MAINMENU,HZ/2);
101 /*
102 * "short-circuit" the default keypresses by running the
103 * callback function
104 * The callback may return a new key value, often this will be
105 * BUTTON_NONE or the same key value, but it's perfectly legal
106 * to "simulate" key presses by returning another value.
107 */
108 if( menus[m].callback != NULL )
109 key = menus[m].callback(key, m);
110 rb->gui_synclist_do_button(&(menus[m].synclist), &key,LIST_WRAP_UNLESS_HELD);
111 switch( key ) {
112 case ACTION_STD_OK:
113 return rb->gui_synclist_get_sel_pos(&(menus[m].synclist));
114
115 case ACTION_STD_CANCEL:
116 case ACTION_STD_MENU:
117 case SYS_POWEROFF:
118 exit = true;
119 break;
120
121 default:
122 if(rb->default_event_handler(key) == SYS_USB_CONNECTED)
123 return MENU_ATTACHED_USB;
124 break;
125 }
126 }
127 rb->viewportmanager_set_statusbar(bars);
128 return MENU_SELECTED_EXIT;
129}
130
131
132bool menu_run(int m)
133{
134 int selected;
135 while (1) {
136 switch (selected=menu_show(m))
137 {
138 case MENU_SELECTED_EXIT:
139 return false;
140
141 case MENU_ATTACHED_USB:
142 return true;
143
144 default:
145 {
146 if (menus[m].items[selected].function &&
147 menus[m].items[selected].function())
148 return true;
149 }
150 }
151 }
152 return false;
153}
154
155/*
156 * Property function - return the current cursor for "menu"
157 */
158
159int menu_cursor(int menu)
160{
161 return rb->gui_synclist_get_sel_pos(&(menus[menu].synclist));
162}
163
164/*
165 * Property function - return the "menu" description at "position"
166 */
167
168char* menu_description(int menu, int position)
169{
170 return menus[menu].items[position].desc;
171}
172
173/*
174 * Delete the element "position" from the menu items in "menu"
175 */
176
177void menu_delete(int menu, int position)
178{
179 int i;
180 int nb_items=rb->gui_synclist_get_nb_items(&(menus[menu].synclist));
181 /* copy the menu item from the one below */
182 for( i = position; i < nb_items - 1; i++)
183 menus[menu].items[i] = menus[menu].items[i + 1];
184
185 rb->gui_synclist_del_item(&(menus[menu].synclist));
186}
187
188void menu_insert(int menu, int position, char *desc, bool (*function) (void))
189{
190 int i;
191 int nb_items=rb->gui_synclist_get_nb_items(&(menus[menu].synclist));
192 if(position < 0)
193 position = nb_items;
194
195 /* Move the items below one position forward */
196 for( i = nb_items; i > position; i--)
197 menus[menu].items[i] = menus[menu].items[i - 1];
198
199 /* Update the current item */
200 menus[menu].items[position].desc = (unsigned char *)desc;
201 menus[menu].items[position].function = function;
202 rb->gui_synclist_add_item(&(menus[menu].synclist));
203}
204
205/*
206 * Property function - return the "count" of menu items in "menu"
207 */
208
209int menu_count(int menu)
210{
211 return rb->gui_synclist_get_nb_items(&(menus[menu].synclist));
212}
213
214/*
215 * Allows to set the cursor position. Doesn't redraw by itself.
216 */
217
218void menu_set_cursor(int menu, int position)
219{
220 rb->gui_synclist_select_item(&(menus[menu].synclist), position);
221}
222#if 0
223void menu_talk_selected(int m)
224{
225 if(rb->global_settings->talk_menu)
226 {
227 int selected=rb->gui_synclist_get_sel_pos(&(menus[m].synclist));
228 int voice_id = P2ID(menus[m].items[selected].desc);
229 if (voice_id >= 0) /* valid ID given? */
230 talk_id(voice_id, false); /* say it */
231 }
232}
233#endif
234void menu_draw(int m)
235{
236 rb->gui_synclist_draw(&(menus[m].synclist));
237}
diff --git a/apps/plugins/lib/oldmenuapi.h b/apps/plugins/lib/oldmenuapi.h
deleted file mode 100644
index 7f877997cf..0000000000
--- a/apps/plugins/lib/oldmenuapi.h
+++ /dev/null
@@ -1,58 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Robert E. Hak
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23/* This API is for existing plugins and shouldn't be used by new ones.
24 This provides a simpler menu system for plugins, but does not allow for
25 translatable or talkable strings in the menus. */
26#ifndef __OLDMENUAPI_H__
27#define __OLDMENUAPI_H__
28
29#include <stdbool.h>
30
31struct menu_item {
32 unsigned char *desc; /* string or ID */
33 bool (*function) (void); /* return true if USB was connected */
34};
35
36int menu_init(const struct menu_item* mitems,
37 int count, int (*callback)(int, int),
38 const char *button1, const char *button2, const char *button3);
39void menu_exit(int menu);
40
41void put_cursorxy(int x, int y, bool on);
42
43 /* Returns below define, or number of selected menu item*/
44int menu_show(int m);
45
46bool menu_run(int menu);
47int menu_cursor(int menu);
48char* menu_description(int menu, int position);
49void menu_delete(int menu, int position);
50int menu_count(int menu);
51bool menu_moveup(int menu);
52bool menu_movedown(int menu);
53void menu_draw(int menu);
54void menu_insert(int menu, int position, char *desc, bool (*function) (void));
55void menu_set_cursor(int menu, int position);
56void menu_talk_selected(int m);
57
58#endif /* End __OLDMENUAPI_H__ */