blob: f9443548f6d66e5357db00bec3a1ba433fa415de [file] [log] [blame]
Daniel Stenberg1c0c8612002-05-17 12:22:24 +00001/***************************************************************************
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 ****************************************************************************/
Björn Stenberg2ac05722002-05-26 17:03:17 +000019#include <stdbool.h>
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +000020#include <stdlib.h>
Justin Heinerb5025a82002-08-31 04:58:35 +000021
Linus Nielsen Feltzing0a4b2472002-10-15 12:25:57 +000022#include "hwcompat.h"
Daniel Stenberg1c0c8612002-05-17 12:22:24 +000023#include "lcd.h"
Daniel Stenberg93b231c2002-09-12 13:33:59 +000024#include "font.h"
Justin Heinerb5025a82002-08-31 04:58:35 +000025#include "backlight.h"
Daniel Stenberg1c0c8612002-05-17 12:22:24 +000026#include "menu.h"
Björn Stenbergb21a3bd2002-05-21 14:25:45 +000027#include "button.h"
28#include "kernel.h"
29#include "debug.h"
Justin Heiner26302452002-08-23 02:17:00 +000030#include "usb.h"
Björn Stenbergcd225732002-08-11 09:17:47 +000031#include "panic.h"
Markus Braun5e4c1d22002-08-20 19:37:00 +000032#include "settings.h"
33#include "status.h"
Björn Stenberga4c3b032002-09-24 18:04:15 +000034#include "screens.h"
Jörg Hohensohn4f36ea82004-03-14 21:33:53 +000035#include "talk.h"
Markus Braun000c2db2002-08-30 13:49:32 +000036
Daniel Stenbergbf603f92002-06-14 08:47:44 +000037#ifdef HAVE_LCD_BITMAP
38#include "icons.h"
Markus Braun000c2db2002-08-30 13:49:32 +000039#include "widgets.h"
Daniel Stenbergbf603f92002-06-14 08:47:44 +000040#endif
Markus Braun000c2db2002-08-30 13:49:32 +000041
Björn Stenberg2ac05722002-05-26 17:03:17 +000042struct menu {
Björn Stenbergf76cee72002-05-28 15:35:33 +000043 int top;
Björn Stenberg2ac05722002-05-26 17:03:17 +000044 int cursor;
45 struct menu_items* items;
46 int itemcount;
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +000047 int (*callback)(int, int);
Björn Stenberg2ac05722002-05-26 17:03:17 +000048};
49
Hardeep Sidhu107ebc52004-01-26 17:05:21 +000050#define MAX_MENUS 5
Björn Stenberg2ac05722002-05-26 17:03:17 +000051
Björn Stenbergf76cee72002-05-28 15:35:33 +000052#ifdef HAVE_LCD_BITMAP
Markus Braun000c2db2002-08-30 13:49:32 +000053
Björn Stenberg8fb73122002-09-24 19:41:23 +000054/* pixel margins */
55#define MARGIN_X (global_settings.scrollbar && \
56 menu_lines < menus[m].itemcount ? SCROLLBAR_WIDTH : 0) +\
57 CURSOR_WIDTH
58#define MARGIN_Y (global_settings.statusbar ? STATUSBAR_HEIGHT : 0)
Markus Braun000c2db2002-08-30 13:49:32 +000059
Björn Stenberg8fb73122002-09-24 19:41:23 +000060/* position the entry-list starts at */
61#define LINE_X 0
62#define LINE_Y (global_settings.statusbar ? 1 : 0)
Markus Braun000c2db2002-08-30 13:49:32 +000063
Björn Stenberg8fb73122002-09-24 19:41:23 +000064#define CURSOR_X (global_settings.scrollbar && \
65 menu_lines < menus[m].itemcount ? 1 : 0)
66#define CURSOR_Y 0 /* the cursor is not positioned in regard to
67 the margins, so this is the amount of lines
68 we add to the cursor Y position to position
69 it on a line */
Linus Nielsen Feltzinge43b78a2003-04-16 00:12:31 +000070#define CURSOR_WIDTH (global_settings.invert_cursor ? 0 : 4)
Markus Braun000c2db2002-08-30 13:49:32 +000071
72#define SCROLLBAR_X 0
73#define SCROLLBAR_Y lcd_getymargin()
74#define SCROLLBAR_WIDTH 6
75
76#else /* HAVE_LCD_BITMAP */
77
Justin Heinerb5025a82002-08-31 04:58:35 +000078#define LINE_X 1 /* X position the entry-list starts at */
Markus Braun000c2db2002-08-30 13:49:32 +000079
Björn Stenbergf76cee72002-05-28 15:35:33 +000080#define MENU_LINES 2
Markus Braun000c2db2002-08-30 13:49:32 +000081
82#define CURSOR_X 0
83#define CURSOR_Y 0 /* not really used for players */
84
85#endif /* HAVE_LCD_BITMAP */
Björn Stenbergf76cee72002-05-28 15:35:33 +000086
Kjell Ericsonc11b90f2003-01-10 09:55:50 +000087#define CURSOR_CHAR 0x92
Björn Stenberg9314a682002-05-31 09:04:51 +000088
Björn Stenberg2ac05722002-05-26 17:03:17 +000089static struct menu menus[MAX_MENUS];
90static bool inuse[MAX_MENUS] = { false };
Daniel Stenberg1c0c8612002-05-17 12:22:24 +000091
Daniel Stenberg93b231c2002-09-12 13:33:59 +000092/* count in letter positions, NOT pixels */
Daniel Stenbergbf603f92002-06-14 08:47:44 +000093void put_cursorxy(int x, int y, bool on)
94{
Björn Stenberg71f71ef2002-08-11 09:20:53 +000095#ifdef HAVE_LCD_BITMAP
Daniel Stenberg93b231c2002-09-12 13:33:59 +000096 int fh, fw;
Björn Stenbergbed3d3f2002-09-20 08:07:51 +000097 int xpos, ypos;
Björn Stenbergd1a6fa12003-06-05 09:38:26 +000098
99 /* check here instead of at every call (ugly, but cheap) */
Linus Nielsen Feltzinge43b78a2003-04-16 00:12:31 +0000100 if (global_settings.invert_cursor)
101 return;
Björn Stenbergd1a6fa12003-06-05 09:38:26 +0000102
Björn Stenberga4c3b032002-09-24 18:04:15 +0000103 lcd_getstringsize("A", &fw, &fh);
Björn Stenbergbed3d3f2002-09-20 08:07:51 +0000104 xpos = x*6;
105 ypos = y*fh + lcd_getymargin();
106 if ( fh > 8 )
107 ypos += (fh - 8) / 2;
Björn Stenberg71f71ef2002-08-11 09:20:53 +0000108#endif
Björn Stenbergcd225732002-08-11 09:17:47 +0000109
Daniel Stenbergbf603f92002-06-14 08:47:44 +0000110 /* place the cursor */
111 if(on) {
112#ifdef HAVE_LCD_BITMAP
113 lcd_bitmap ( bitmap_icons_6x8[Cursor],
Björn Stenbergbed3d3f2002-09-20 08:07:51 +0000114 xpos, ypos, 4, 8, true);
Daniel Stenbergbf603f92002-06-14 08:47:44 +0000115#else
Kjell Ericsonc11b90f2003-01-10 09:55:50 +0000116 lcd_putc(x, y, CURSOR_CHAR);
Daniel Stenbergbf603f92002-06-14 08:47:44 +0000117#endif
118 }
119 else {
Daniel Stenbergc4be1ee2002-06-19 13:00:14 +0000120#if defined(HAVE_LCD_BITMAP)
Daniel Stenbergbf603f92002-06-14 08:47:44 +0000121 /* I use xy here since it needs to disregard the margins */
Björn Stenbergbed3d3f2002-09-20 08:07:51 +0000122 lcd_clearrect (xpos, ypos, 4, 8);
Daniel Stenbergbf603f92002-06-14 08:47:44 +0000123#else
Björn Stenberg3b974742002-09-09 23:57:00 +0000124 lcd_putc(x, y, ' ');
Daniel Stenbergbf603f92002-06-14 08:47:44 +0000125#endif
126 }
127}
128
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +0000129void menu_draw(int m)
Björn Stenbergf76cee72002-05-28 15:35:33 +0000130{
131 int i = 0;
Eric Linenberg038df5c2002-09-16 03:18:49 +0000132#ifdef HAVE_LCD_BITMAP
Daniel Stenberg93b231c2002-09-12 13:33:59 +0000133 int fw, fh;
Björn Stenbergcd225732002-08-11 09:17:47 +0000134 int menu_lines;
Björn Stenberga4c3b032002-09-24 18:04:15 +0000135 lcd_setfont(FONT_UI);
136 lcd_getstringsize("A", &fw, &fh);
Markus Braun5e4c1d22002-08-20 19:37:00 +0000137 if (global_settings.statusbar)
138 menu_lines = (LCD_HEIGHT - STATUSBAR_HEIGHT) / fh;
139 else
140 menu_lines = LCD_HEIGHT/fh;
Björn Stenbergcd225732002-08-11 09:17:47 +0000141#else
142 int menu_lines = MENU_LINES;
143#endif
Björn Stenbergf76cee72002-05-28 15:35:33 +0000144
Daniel Stenberga8e89fd2002-08-22 21:45:22 +0000145 lcd_clear_display(); /* ...then clean the screen */
Björn Stenbergf76cee72002-05-28 15:35:33 +0000146#ifdef HAVE_LCD_BITMAP
Markus Braun000c2db2002-08-30 13:49:32 +0000147 lcd_setmargins(MARGIN_X,MARGIN_Y); /* leave room for cursor and icon */
Björn Stenbergf76cee72002-05-28 15:35:33 +0000148#endif
Markus Braun5e4c1d22002-08-20 19:37:00 +0000149 /* correct cursor pos if out of screen */
150 if (menus[m].cursor - menus[m].top >= menu_lines)
151 menus[m].top++;
152
Björn Stenbergf76cee72002-05-28 15:35:33 +0000153 for (i = menus[m].top;
Björn Stenbergcd225732002-08-11 09:17:47 +0000154 (i < menus[m].itemcount) && (i<menus[m].top+menu_lines);
Björn Stenbergf76cee72002-05-28 15:35:33 +0000155 i++) {
Linus Nielsen Feltzing8fa02172002-08-02 07:59:25 +0000156 if((menus[m].cursor - menus[m].top)==(i-menus[m].top))
Linus Nielsen Feltzinge43b78a2003-04-16 00:12:31 +0000157#ifdef HAVE_LCD_BITMAP
158 if (global_settings.invert_cursor)
159 lcd_puts_scroll_style(LINE_X, i-menus[m].top,
160 menus[m].items[i].desc, STYLE_INVERT);
161 else
162#endif
163 lcd_puts_scroll(LINE_X, i-menus[m].top, menus[m].items[i].desc);
Linus Nielsen Feltzing8fa02172002-08-02 07:59:25 +0000164 else
Markus Braun000c2db2002-08-30 13:49:32 +0000165 lcd_puts(LINE_X, i-menus[m].top, menus[m].items[i].desc);
Björn Stenbergf76cee72002-05-28 15:35:33 +0000166 }
Robert Hakc501ac72002-05-30 08:06:42 +0000167
Daniel Stenbergbf603f92002-06-14 08:47:44 +0000168 /* place the cursor */
Markus Braun000c2db2002-08-30 13:49:32 +0000169 put_cursorxy(CURSOR_X, menus[m].cursor - menus[m].top, true);
Markus Braun5e4c1d22002-08-20 19:37:00 +0000170#ifdef HAVE_LCD_BITMAP
Björn Stenberg8fb73122002-09-24 19:41:23 +0000171 if (global_settings.scrollbar && menus[m].itemcount > menu_lines)
Markus Braun000c2db2002-08-30 13:49:32 +0000172 scrollbar(SCROLLBAR_X, SCROLLBAR_Y, SCROLLBAR_WIDTH - 1,
173 LCD_HEIGHT - SCROLLBAR_Y, menus[m].itemcount, menus[m].top,
174 menus[m].top + menu_lines, VERTICAL);
Markus Braun5e4c1d22002-08-20 19:37:00 +0000175#endif
Björn Stenberg942bc942003-04-23 11:26:25 +0000176 status_draw(true);
Björn Stenbergf76cee72002-05-28 15:35:33 +0000177 lcd_update();
178}
179
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000180/*
181 * Move the cursor to a particular id,
182 * target: where you want it to be
183 */
Björn Stenberg2ac05722002-05-26 17:03:17 +0000184static void put_cursor(int m, int target)
Daniel Stenberg1c0c8612002-05-17 12:22:24 +0000185{
Robert Hakc501ac72002-05-30 08:06:42 +0000186 bool do_update = true;
Eric Linenberg038df5c2002-09-16 03:18:49 +0000187#ifdef HAVE_LCD_BITMAP
Daniel Stenberg93b231c2002-09-12 13:33:59 +0000188 int fw, fh;
Björn Stenbergcd225732002-08-11 09:17:47 +0000189 int menu_lines;
Linus Nielsen Feltzingf1659a32003-11-20 01:51:15 +0000190 lcd_setfont(FONT_UI);
Björn Stenberga4c3b032002-09-24 18:04:15 +0000191 lcd_getstringsize("A", &fw, &fh);
Markus Braun5e4c1d22002-08-20 19:37:00 +0000192 if (global_settings.statusbar)
Daniel Stenberg93b231c2002-09-12 13:33:59 +0000193 menu_lines = (LCD_HEIGHT - STATUSBAR_HEIGHT) / fh;
Markus Braun5e4c1d22002-08-20 19:37:00 +0000194 else
195 menu_lines = LCD_HEIGHT/fh;
Björn Stenbergcd225732002-08-11 09:17:47 +0000196#else
197 int menu_lines = MENU_LINES;
198#endif
Daniel Stenberg93b231c2002-09-12 13:33:59 +0000199
Markus Braun000c2db2002-08-30 13:49:32 +0000200 put_cursorxy(CURSOR_X, menus[m].cursor - menus[m].top, false);
Robert Hakc501ac72002-05-30 08:06:42 +0000201 menus[m].cursor = target;
Linus Nielsen Feltzing8fa02172002-08-02 07:59:25 +0000202 menu_draw(m);
Björn Stenbergf76cee72002-05-28 15:35:33 +0000203
204 if ( target < menus[m].top ) {
205 menus[m].top--;
206 menu_draw(m);
Robert Hakc501ac72002-05-30 08:06:42 +0000207 do_update = false;
Björn Stenbergf76cee72002-05-28 15:35:33 +0000208 }
Björn Stenbergcd225732002-08-11 09:17:47 +0000209 else if ( target-menus[m].top > menu_lines-1 ) {
Björn Stenbergf76cee72002-05-28 15:35:33 +0000210 menus[m].top++;
211 menu_draw(m);
Robert Hakc501ac72002-05-30 08:06:42 +0000212 do_update = false;
Björn Stenbergf76cee72002-05-28 15:35:33 +0000213 }
Robert Hakc501ac72002-05-30 08:06:42 +0000214
Linus Nielsen Feltzinge43b78a2003-04-16 00:12:31 +0000215 if (do_update && !global_settings.invert_cursor) {
216 put_cursorxy(CURSOR_X, menus[m].cursor - menus[m].top, true);
Robert Hakc501ac72002-05-30 08:06:42 +0000217 lcd_update();
218 }
219
Jörg Hohensohn4f36ea82004-03-14 21:33:53 +0000220 if (do_update)
221 { /* "say" the entry under the cursor */
222 int voice_id = menus[m].items[menus[m].cursor].voice_id;
223 if (voice_id >= 0) /* valid ID given? */
224 talk_id(voice_id, false); /* say it */
225 }
226
Daniel Stenberg1c0c8612002-05-17 12:22:24 +0000227}
228
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +0000229int menu_init(struct menu_items* mitems, int count, int (*callback)(int, int))
Daniel Stenberg1c0c8612002-05-17 12:22:24 +0000230{
Björn Stenberg2ac05722002-05-26 17:03:17 +0000231 int i;
232
233 for ( i=0; i<MAX_MENUS; i++ ) {
234 if ( !inuse[i] ) {
235 inuse[i] = true;
236 break;
237 }
238 }
239 if ( i == MAX_MENUS ) {
240 DEBUGF("Out of menus!\n");
241 return -1;
242 }
243 menus[i].items = mitems;
244 menus[i].itemcount = count;
Björn Stenbergf76cee72002-05-28 15:35:33 +0000245 menus[i].top = 0;
Björn Stenberg2ac05722002-05-26 17:03:17 +0000246 menus[i].cursor = 0;
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +0000247 menus[i].callback = callback;
Björn Stenberg2ac05722002-05-26 17:03:17 +0000248
249 return i;
Daniel Stenberg1c0c8612002-05-17 12:22:24 +0000250}
251
Björn Stenberg2ac05722002-05-26 17:03:17 +0000252void menu_exit(int m)
Daniel Stenberg1c0c8612002-05-17 12:22:24 +0000253{
Björn Stenberg2ac05722002-05-26 17:03:17 +0000254 inuse[m] = false;
Daniel Stenberg1c0c8612002-05-17 12:22:24 +0000255}
256
Kjell Ericson5cd393c2003-01-29 08:26:11 +0000257int menu_show(int m)
Robert Hak7ec9aa32002-05-18 11:41:37 +0000258{
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000259 bool exit = false;
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +0000260 int key;
Jörg Hohensohn4f36ea82004-03-14 21:33:53 +0000261 int voice_id;
Linus Nielsen Feltzingf1659a32003-11-20 01:51:15 +0000262#ifdef HAVE_LCD_BITMAP
263 int fw, fh;
264 int menu_lines;
265 lcd_setfont(FONT_UI);
266 lcd_getstringsize("A", &fw, &fh);
267 if (global_settings.statusbar)
268 menu_lines = (LCD_HEIGHT - STATUSBAR_HEIGHT) / fh;
269 else
270 menu_lines = LCD_HEIGHT/fh;
Linus Nielsen Feltzingf1659a32003-11-20 01:51:15 +0000271#endif
Justin Heiner26302452002-08-23 02:17:00 +0000272
Björn Stenberg2ac05722002-05-26 17:03:17 +0000273 menu_draw(m);
Justin Heiner26302452002-08-23 02:17:00 +0000274
Jörg Hohensohn4f36ea82004-03-14 21:33:53 +0000275 /* say current entry */
276 voice_id = menus[m].items[menus[m].cursor].voice_id;
277 if (voice_id >= 0) /* valid ID given? */
278 talk_id(voice_id, false); /* say it */
279
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000280 while (!exit) {
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +0000281 key = button_get_w_tmo(HZ/2);
Jörg Hohensohn4f36ea82004-03-14 21:33:53 +0000282
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +0000283
Jörg Hohensohn4f36ea82004-03-14 21:33:53 +0000284
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +0000285 /*
286 * "short-circuit" the default keypresses by running the callback function
287 */
288
289 if( menus[m].callback != NULL )
290 key = menus[m].callback(key, m); /* make sure there's no match in the switch */
291
292 switch( key ) {
Jörg Hohensohn4f36ea82004-03-14 21:33:53 +0000293
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000294#ifdef HAVE_RECORDER_KEYPAD
295 case BUTTON_UP:
Björn Stenbergcbc71792002-08-10 09:04:55 +0000296 case BUTTON_UP | BUTTON_REPEAT:
Robert Hak7ec9aa32002-05-18 11:41:37 +0000297#else
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000298 case BUTTON_LEFT:
Linus Nielsen Feltzing8fa02172002-08-02 07:59:25 +0000299 case BUTTON_LEFT | BUTTON_REPEAT:
Robert Hak7ec9aa32002-05-18 11:41:37 +0000300#endif
Björn Stenberg4caebab2002-05-29 14:25:06 +0000301 if (menus[m].cursor) {
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000302 /* move up */
Björn Stenberg2ac05722002-05-26 17:03:17 +0000303 put_cursor(m, menus[m].cursor-1);
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000304 }
Eric Linenbergc076b272002-09-04 04:21:10 +0000305 else {
306 /* move to bottom */
307#ifdef HAVE_RECORDER_KEYPAD
Linus Nielsen Feltzingf1659a32003-11-20 01:51:15 +0000308 menus[m].top = menus[m].itemcount-(menu_lines+1);
Eric Linenbergc076b272002-09-04 04:21:10 +0000309#else
310 menus[m].top = menus[m].itemcount-3;
311#endif
312 if (menus[m].top < 0)
313 menus[m].top = 0;
314 menus[m].cursor = menus[m].itemcount-1;
315 put_cursor(m, menus[m].itemcount-1);
316 }
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000317 break;
Robert Hakdfba2102002-05-21 08:47:34 +0000318
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000319#ifdef HAVE_RECORDER_KEYPAD
320 case BUTTON_DOWN:
Björn Stenbergcbc71792002-08-10 09:04:55 +0000321 case BUTTON_DOWN | BUTTON_REPEAT:
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000322#else
323 case BUTTON_RIGHT:
Linus Nielsen Feltzing8fa02172002-08-02 07:59:25 +0000324 case BUTTON_RIGHT | BUTTON_REPEAT:
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000325#endif
Björn Stenberg4caebab2002-05-29 14:25:06 +0000326 if (menus[m].cursor < menus[m].itemcount-1) {
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000327 /* move down */
Björn Stenberg2ac05722002-05-26 17:03:17 +0000328 put_cursor(m, menus[m].cursor+1);
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000329 }
Eric Linenbergc076b272002-09-04 04:21:10 +0000330 else {
331 /* move to top */
332 menus[m].top = 0;
333 menus[m].cursor = 0;
334 put_cursor(m, 0);
335 }
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000336 break;
337
338#ifdef HAVE_RECORDER_KEYPAD
339 case BUTTON_RIGHT:
340#endif
341 case BUTTON_PLAY:
342 /* Erase current display state */
343 lcd_clear_display();
Kjell Ericson5cd393c2003-01-29 08:26:11 +0000344 return menus[m].cursor;
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000345
346#ifdef HAVE_RECORDER_KEYPAD
347 case BUTTON_LEFT:
Linus Nielsen Feltzinga552f4c2002-07-27 19:53:26 +0000348 case BUTTON_F1:
Björn Stenberg461d6e32003-12-04 00:08:25 +0000349 case BUTTON_OFF | BUTTON_REPEAT:
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000350#else
351 case BUTTON_STOP:
Björn Stenberg60fad542002-05-29 12:28:08 +0000352 case BUTTON_MENU:
Björn Stenberg461d6e32003-12-04 00:08:25 +0000353 case BUTTON_STOP | BUTTON_REPEAT:
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000354#endif
Kjell Ericson767d6042003-01-23 14:28:16 +0000355 lcd_stop_scroll();
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000356 exit = true;
357 break;
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000358
Justin Heiner26302452002-08-23 02:17:00 +0000359 case SYS_USB_CONNECTED:
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000360 usb_screen();
Björn Stenberg40d866b2002-09-01 20:08:08 +0000361#ifdef HAVE_LCD_CHARCELLS
Mats Lidell18739872002-10-15 12:56:05 +0000362 status_set_param(false);
Justin Heiner26302452002-08-23 02:17:00 +0000363#endif
Kjell Ericson5cd393c2003-01-29 08:26:11 +0000364 return MENU_ATTACHED_USB;
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000365 }
366
Björn Stenberg942bc942003-04-23 11:26:25 +0000367 status_draw(false);
Björn Stenbergb21a3bd2002-05-21 14:25:45 +0000368 }
Kjell Ericson5cd393c2003-01-29 08:26:11 +0000369 return MENU_SELECTED_EXIT;
370}
Daniel Stenbergb2850762002-08-23 12:32:52 +0000371
Kjell Ericson5cd393c2003-01-29 08:26:11 +0000372
373bool menu_run(int m)
374{
375 bool stop=false;
376 while (!stop) {
377 int result=menu_show(m);
378 if (result == MENU_SELECTED_EXIT)
379 return false;
380 else if (result == MENU_ATTACHED_USB)
381 return true;
382 if (menus[m].items[menus[m].cursor].function()) {
383 return true;
384 }
385 }
386 return false;
Robert Hak7ec9aa32002-05-18 11:41:37 +0000387}
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +0000388
389/*
390 * Property function - return the current cursor for "menu"
391 */
392
393int menu_cursor(int menu)
394{
395 return menus[menu].cursor;
396}
397
398/*
399 * Property function - return the "menu" description at "position"
400 */
401
402char* menu_description(int menu, int position)
403{
404 return menus[menu].items[position].desc;
405}
406
407/*
408 * Delete the element "position" from the menu items in "menu"
409 */
410
411void menu_delete(int menu, int position)
412{
413 int i;
414
415 /* copy the menu item from the one below */
416 for( i = position; i < (menus[menu].itemcount - 1); i++)
417 menus[menu].items[i] = menus[menu].items[i + 1];
418
419 /* reduce the count */
420 menus[menu].itemcount--;
421
422 /* adjust if this was the last menu item and the cursor was on it */
423 if( menus[menu].itemcount <= menus[menu].cursor)
424 menus[menu].cursor = menus[menu].itemcount - 1;
425}
426
427/*
428 * Property function - return the "count" of menu items in "menu"
429 */
430
431int menu_count(int menu)
432{
433 return menus[menu].itemcount;
434}
435
436/*
437 * Allows a menu item at the current cursor position in "menu" to be moved up the list
438 */
439
440bool menu_moveup(int menu)
441{
442 struct menu_items swap;
443
444 /* can't be the first item ! */
445 if( menus[menu].cursor == 0)
446 return false;
447
448 /* use a temporary variable to do the swap */
449 swap = menus[menu].items[menus[menu].cursor - 1];
450 menus[menu].items[menus[menu].cursor - 1] = menus[menu].items[menus[menu].cursor];
451 menus[menu].items[menus[menu].cursor] = swap;
452 menus[menu].cursor--;
453
454 return true;
455}
456
457/*
458 * Allows a menu item at the current cursor position in "menu" to be moved down the list
459 */
460
461bool menu_movedown(int menu)
462{
463 struct menu_items swap;
464
465 /* can't be the last item ! */
466 if( menus[menu].cursor == menus[menu].itemcount - 1)
467 return false;
468
469 /* use a temporary variable to do the swap */
470 swap = menus[menu].items[menus[menu].cursor + 1];
471 menus[menu].items[menus[menu].cursor + 1] = menus[menu].items[menus[menu].cursor];
472 menus[menu].items[menus[menu].cursor] = swap;
473 menus[menu].cursor++;
474
475 return true;
476}