2005-10-28 00:00:00 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2005-10-30 01:24:35 +00:00
|
|
|
* Copyright (C) 2005 by Kevin Ferrare
|
2005-10-28 00:00:00 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "sprintf.h"
|
2006-08-15 08:14:46 +00:00
|
|
|
#include "string.h"
|
2005-10-28 00:00:00 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "kernel.h"
|
2007-06-05 02:57:43 +00:00
|
|
|
#include "system.h"
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
#include "action.h"
|
2005-10-28 00:00:00 +00:00
|
|
|
#include "screen_access.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "scrollbar.h"
|
|
|
|
#include "statusbar.h"
|
2005-11-01 23:56:03 +00:00
|
|
|
#include "textarea.h"
|
2007-03-05 00:32:33 +00:00
|
|
|
#include "lang.h"
|
2007-04-08 01:33:01 +00:00
|
|
|
#include "sound.h"
|
2007-05-30 18:08:29 +00:00
|
|
|
#include "misc.h"
|
2007-10-21 00:20:10 +00:00
|
|
|
#include "talk.h"
|
2008-03-05 09:58:30 +00:00
|
|
|
#include "viewport.h"
|
2005-10-28 00:00:00 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
|
|
|
#define SCROLL_LIMIT 1
|
|
|
|
#else
|
2007-06-05 02:57:43 +00:00
|
|
|
#define SCROLL_LIMIT (nb_lines<3?1:2)
|
2005-10-28 00:00:00 +00:00
|
|
|
#endif
|
|
|
|
|
2007-03-11 10:52:36 +00:00
|
|
|
/* The minimum number of pending button events in queue before starting
|
|
|
|
* to limit list drawing interval.
|
|
|
|
*/
|
|
|
|
#define FRAMEDROP_TRIGGER 6
|
|
|
|
|
2006-01-22 04:24:26 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static int offset_step = 16; /* pixels per screen scroll step */
|
|
|
|
/* should lines scroll out of the screen */
|
|
|
|
static bool offset_out_of_view = false;
|
|
|
|
#endif
|
2008-03-09 09:37:39 +00:00
|
|
|
static int force_list_reinit = false;
|
2006-01-22 04:24:26 +00:00
|
|
|
|
2007-12-17 02:37:21 +00:00
|
|
|
static void gui_list_select_at_offset(struct gui_synclist * gui_list,
|
|
|
|
int offset);
|
2008-03-05 09:58:30 +00:00
|
|
|
void list_draw(struct screen *display, struct viewport *parent, struct gui_synclist *list);
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static struct viewport parent[NB_SCREENS];
|
2008-03-26 09:05:42 +00:00
|
|
|
void list_init_viewports(struct gui_synclist *list)
|
2008-03-05 09:58:30 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct viewport *vp;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
vp = &parent[i];
|
2008-03-26 09:05:42 +00:00
|
|
|
if (!list)
|
|
|
|
viewport_set_defaults(vp, i);
|
|
|
|
else if (list->parent[i] == vp)
|
|
|
|
{
|
|
|
|
viewport_set_defaults(vp, i);
|
|
|
|
list->parent[i]->y = global_settings.statusbar?STATUSBAR_HEIGHT:0;
|
|
|
|
list->parent[i]->height = screens[i].height - list->parent[i]->y;
|
|
|
|
}
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
2008-03-26 09:05:42 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
if (list && (list->parent[0] == &parent[0]) && global_settings.buttonbar)
|
|
|
|
list->parent[0]->height -= BUTTONBAR_HEIGHT;
|
|
|
|
#endif
|
2008-03-09 09:37:39 +00:00
|
|
|
force_list_reinit = false;
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static struct viewport parent[NB_SCREENS] =
|
|
|
|
{
|
|
|
|
[SCREEN_MAIN] =
|
|
|
|
{
|
|
|
|
.x = 0,
|
|
|
|
.y = 0,
|
|
|
|
.width = LCD_WIDTH,
|
|
|
|
.height = LCD_HEIGHT
|
|
|
|
},
|
|
|
|
};
|
2008-03-26 09:05:42 +00:00
|
|
|
void list_init_viewports(struct gui_synclist *list)
|
2008-03-05 09:58:30 +00:00
|
|
|
{
|
2008-03-26 09:05:42 +00:00
|
|
|
(void)list;
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
bool list_display_title(struct gui_synclist *list, struct viewport *vp)
|
|
|
|
{
|
|
|
|
return list->title != NULL && viewport_get_nb_lines(vp)>2;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define list_display_title(l,v) false
|
|
|
|
#endif
|
2007-02-23 21:52:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes a scrolling list
|
|
|
|
* - gui_list : the list structure to initialize
|
|
|
|
* - callback_get_item_name : pointer to a function that associates a label
|
|
|
|
* to a given item number
|
|
|
|
* - data : extra data passed to the list callback
|
2007-06-17 21:16:34 +00:00
|
|
|
* - scroll_all :
|
|
|
|
* - selected_size :
|
2008-03-26 03:35:24 +00:00
|
|
|
* - parent : the parent viewports to use. NULL means the full screen minus
|
|
|
|
* statusbar if enabled. NOTE: new screens should NOT set this to NULL.
|
2007-02-23 21:52:45 +00:00
|
|
|
*/
|
2007-12-17 02:37:21 +00:00
|
|
|
void gui_synclist_init(struct gui_synclist * gui_list,
|
2005-11-16 02:12:25 +00:00
|
|
|
list_get_name callback_get_item_name,
|
2006-07-02 12:28:27 +00:00
|
|
|
void * data,
|
|
|
|
bool scroll_all,
|
2008-03-26 03:35:24 +00:00
|
|
|
int selected_size, struct viewport list_parent[NB_SCREENS]
|
2005-10-29 02:33:19 +00:00
|
|
|
)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
int i;
|
2005-11-16 17:23:49 +00:00
|
|
|
gui_list->callback_get_item_icon = NULL;
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_list->callback_get_item_name = callback_get_item_name;
|
2007-10-21 00:20:10 +00:00
|
|
|
gui_list->callback_speak_item = NULL;
|
2008-03-05 09:58:30 +00:00
|
|
|
gui_list->nb_items = 0;
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_list->selected_item = 0;
|
2007-12-17 02:37:21 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
gui_list->start_item[i] = 0;
|
|
|
|
gui_list->last_displayed_start_item[i] = -1 ;
|
2006-01-22 04:24:26 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-12-17 02:37:21 +00:00
|
|
|
gui_list->offset_position[i] = 0;
|
2006-01-22 04:24:26 +00:00
|
|
|
#endif
|
2008-03-26 03:35:24 +00:00
|
|
|
if (list_parent)
|
|
|
|
gui_list->parent[i] = &list_parent[i];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gui_list->parent[i] = &parent[i];
|
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
}
|
2008-03-26 09:05:42 +00:00
|
|
|
list_init_viewports(gui_list);
|
2007-12-17 02:37:21 +00:00
|
|
|
gui_list->limit_scroll = false;
|
|
|
|
gui_list->data=data;
|
2006-07-02 12:28:27 +00:00
|
|
|
gui_list->scroll_all=scroll_all;
|
|
|
|
gui_list->selected_size=selected_size;
|
2006-08-15 08:14:46 +00:00
|
|
|
gui_list->title = NULL;
|
2006-08-15 12:23:55 +00:00
|
|
|
gui_list->title_width = 0;
|
2007-04-16 09:14:36 +00:00
|
|
|
gui_list->title_icon = Icon_NOICON;
|
2007-03-11 10:52:36 +00:00
|
|
|
|
2007-10-21 00:20:10 +00:00
|
|
|
gui_list->scheduled_talk_tick = gui_list->last_talked_tick = 0;
|
2007-06-07 12:14:31 +00:00
|
|
|
gui_list->show_selection_marker = true;
|
2007-12-17 02:37:21 +00:00
|
|
|
gui_list->last_displayed_selected_item = -1 ;
|
2007-06-17 21:16:34 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
gui_list->title_color = -1;
|
|
|
|
gui_list->callback_get_item_color = NULL;
|
|
|
|
#endif
|
2008-03-09 09:37:39 +00:00
|
|
|
force_list_reinit = true;
|
2007-06-07 12:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this toggles the selection bar or cursor */
|
|
|
|
void gui_synclist_hide_selection_marker(struct gui_synclist * lists, bool hide)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
lists->show_selection_marker = !hide;
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-23 20:02:06 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2008-03-05 09:58:30 +00:00
|
|
|
int list_title_height(struct gui_synclist *list, struct viewport *vp);
|
|
|
|
|
|
|
|
int gui_list_get_item_offset(struct gui_synclist * gui_list, int item_width,
|
|
|
|
int text_pos, struct screen * display, struct viewport *vp)
|
2006-08-23 20:02:06 +00:00
|
|
|
{
|
|
|
|
int item_offset;
|
2007-03-11 10:52:36 +00:00
|
|
|
|
2006-08-23 20:02:06 +00:00
|
|
|
if (offset_out_of_view)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
item_offset = gui_list->offset_position[display->screen_type];
|
2006-08-23 20:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* if text is smaller then view */
|
2008-03-05 09:58:30 +00:00
|
|
|
if (item_width <= vp->width - text_pos)
|
2006-08-23 20:02:06 +00:00
|
|
|
{
|
|
|
|
item_offset = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* if text got out of view */
|
2007-12-17 02:37:21 +00:00
|
|
|
if (gui_list->offset_position[display->screen_type] >
|
2008-03-05 09:58:30 +00:00
|
|
|
item_width - (vp->width - text_pos))
|
|
|
|
item_offset = item_width - (vp->width - text_pos);
|
2006-08-23 20:02:06 +00:00
|
|
|
else
|
2007-12-17 02:37:21 +00:00
|
|
|
item_offset = gui_list->offset_position[display->screen_type];
|
2006-08-23 20:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return item_offset;
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-11 10:52:36 +00:00
|
|
|
/*
|
|
|
|
* Force a full screen update.
|
|
|
|
*/
|
2008-03-05 09:58:30 +00:00
|
|
|
|
2007-12-17 02:37:21 +00:00
|
|
|
void gui_synclist_draw(struct gui_synclist *gui_list)
|
2007-03-11 10:52:36 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
int i;
|
2008-03-09 09:37:39 +00:00
|
|
|
static struct gui_synclist *last_list = NULL;
|
|
|
|
static int last_count = -1;
|
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
static bool last_buttonbar = false;
|
|
|
|
#endif
|
|
|
|
if (force_list_reinit ||
|
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
last_buttonbar != screens[SCREEN_MAIN].has_buttonbar ||
|
|
|
|
#endif
|
|
|
|
last_list != gui_list ||
|
|
|
|
gui_list->nb_items != last_count)
|
2007-12-17 02:37:21 +00:00
|
|
|
{
|
2008-03-26 09:05:42 +00:00
|
|
|
list_init_viewports(gui_list);
|
2008-03-09 09:37:39 +00:00
|
|
|
force_list_reinit = false;
|
|
|
|
}
|
2008-03-09 02:00:31 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
2008-03-09 09:37:39 +00:00
|
|
|
last_buttonbar = screens[SCREEN_MAIN].has_buttonbar;
|
2008-03-09 02:00:31 +00:00
|
|
|
#endif
|
2008-03-09 09:37:39 +00:00
|
|
|
last_count = gui_list->nb_items;
|
|
|
|
last_list = gui_list;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
2008-03-05 09:58:30 +00:00
|
|
|
list_draw(&screens[i], gui_list->parent[i], gui_list);
|
2007-12-17 02:37:21 +00:00
|
|
|
}
|
2007-03-11 10:52:36 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 02:37:21 +00:00
|
|
|
/* sets up the list so the selection is shown correctly on the screen */
|
|
|
|
static void gui_list_put_selection_on_screen(struct gui_synclist * gui_list,
|
|
|
|
enum screen_type screen)
|
2007-03-11 10:52:36 +00:00
|
|
|
{
|
2008-03-05 09:58:30 +00:00
|
|
|
int nb_lines;
|
2007-12-17 02:37:21 +00:00
|
|
|
int difference = gui_list->selected_item - gui_list->start_item[screen];
|
2008-03-05 09:58:30 +00:00
|
|
|
struct viewport vp = *gui_list->parent[screen];
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
if (list_display_title(gui_list, gui_list->parent[screen]))
|
|
|
|
vp.height -= list_title_height(gui_list,gui_list->parent[screen]);
|
|
|
|
#endif
|
|
|
|
nb_lines = viewport_get_nb_lines(&vp);
|
2007-06-07 12:14:31 +00:00
|
|
|
|
2007-12-17 02:37:21 +00:00
|
|
|
/* edge case,, selected last item */
|
|
|
|
if (gui_list->selected_item == gui_list->nb_items -1)
|
2007-06-07 12:14:31 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
gui_list->start_item[screen] = MAX(0, gui_list->nb_items - nb_lines);
|
2007-06-07 12:14:31 +00:00
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
/* selected first item */
|
|
|
|
else if (gui_list->selected_item == 0)
|
2007-03-11 10:52:36 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
gui_list->start_item[screen] = 0;
|
2007-06-05 02:57:43 +00:00
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
else if (difference < SCROLL_LIMIT) /* list moved up */
|
2007-06-05 02:57:43 +00:00
|
|
|
{
|
2007-05-27 15:08:56 +00:00
|
|
|
if (global_settings.scroll_paginated)
|
2007-03-11 10:52:36 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
if (gui_list->start_item[screen] > gui_list->selected_item)
|
2008-01-08 08:12:32 +00:00
|
|
|
gui_list->start_item[screen] = (gui_list->selected_item/nb_lines)*nb_lines;
|
2007-06-05 02:57:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int top_of_screen = gui_list->selected_item - SCROLL_LIMIT;
|
|
|
|
int temp = MIN(top_of_screen, gui_list->nb_items - nb_lines);
|
2007-12-17 02:37:21 +00:00
|
|
|
gui_list->start_item[screen] = MAX(0, temp);
|
2007-03-11 10:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
else if (difference > nb_lines - SCROLL_LIMIT) /* list moved down */
|
2007-06-07 12:14:31 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
int bottom = gui_list->nb_items - nb_lines;
|
|
|
|
/* always move the screen if selection isnt "visible" */
|
2007-06-07 12:14:31 +00:00
|
|
|
if (gui_list->show_selection_marker == false)
|
|
|
|
{
|
|
|
|
if (bottom < 0)
|
|
|
|
bottom = 0;
|
2007-12-17 02:37:21 +00:00
|
|
|
gui_list->start_item[screen] = MIN(bottom, gui_list->start_item[screen] +
|
|
|
|
2*gui_list->selected_size);
|
2007-05-27 15:08:56 +00:00
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
else if (global_settings.scroll_paginated)
|
2007-05-27 15:08:56 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
if (gui_list->start_item[screen] + nb_lines <= gui_list->selected_item)
|
|
|
|
gui_list->start_item[screen] = MIN(bottom, gui_list->selected_item);
|
2007-06-05 02:57:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int top_of_screen = gui_list->selected_item + SCROLL_LIMIT - nb_lines;
|
|
|
|
int temp = MAX(0, top_of_screen);
|
2007-12-17 02:37:21 +00:00
|
|
|
gui_list->start_item[screen] = MIN(bottom, temp);
|
2007-05-27 15:08:56 +00:00
|
|
|
}
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Selects an item in the list
|
|
|
|
* - gui_list : the list structure
|
|
|
|
* - item_number : the number of the item which will be selected
|
|
|
|
*/
|
|
|
|
void gui_synclist_select_item(struct gui_synclist * gui_list, int item_number)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if( item_number > gui_list->nb_items-1 || item_number < 0 )
|
|
|
|
return;
|
|
|
|
gui_list->selected_item = item_number;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
gui_list_put_selection_on_screen(gui_list, i);
|
2007-06-05 02:57:43 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 02:37:21 +00:00
|
|
|
static void gui_list_select_at_offset(struct gui_synclist * gui_list,
|
|
|
|
int offset)
|
2007-06-05 02:57:43 +00:00
|
|
|
{
|
2008-01-21 22:28:25 +00:00
|
|
|
int new_selection;
|
2007-06-05 02:57:43 +00:00
|
|
|
if (gui_list->selected_size > 1)
|
|
|
|
{
|
|
|
|
offset *= gui_list->selected_size;
|
|
|
|
/* always select the first item of multi-line lists */
|
|
|
|
offset -= offset%gui_list->selected_size;
|
|
|
|
}
|
2008-01-21 22:28:25 +00:00
|
|
|
new_selection = gui_list->selected_item + offset;
|
2007-12-17 02:37:21 +00:00
|
|
|
if (new_selection >= gui_list->nb_items)
|
2007-06-09 09:41:13 +00:00
|
|
|
{
|
2008-01-21 22:28:25 +00:00
|
|
|
gui_list->selected_item = gui_list->limit_scroll ?
|
|
|
|
gui_list->nb_items - gui_list->selected_size : 0;
|
2007-06-09 09:41:13 +00:00
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
else if (new_selection < 0)
|
|
|
|
{
|
2008-01-21 22:28:25 +00:00
|
|
|
gui_list->selected_item = gui_list->limit_scroll ?
|
|
|
|
0 : gui_list->nb_items - gui_list->selected_size;
|
2007-12-17 02:37:21 +00:00
|
|
|
}
|
|
|
|
else if (gui_list->show_selection_marker == false)
|
|
|
|
{
|
|
|
|
/* NOTE: this part doesnt work as well as it used to, the problem is
|
|
|
|
we want to scroll the lists seperatly but we only have one
|
|
|
|
selected item now, I dont think this is such a big deal though */
|
|
|
|
int i, nb_lines, screen_top;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
2008-03-05 09:58:30 +00:00
|
|
|
struct viewport vp = *gui_list->parent[i];
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
if (list_display_title(gui_list, gui_list->parent[i]))
|
|
|
|
vp.height -= list_title_height(gui_list,gui_list->parent[i]);
|
|
|
|
#endif
|
|
|
|
nb_lines = viewport_get_nb_lines(&vp);
|
2007-12-17 02:37:21 +00:00
|
|
|
if (offset > 0)
|
|
|
|
{
|
|
|
|
screen_top = gui_list->nb_items-nb_lines;
|
|
|
|
if (screen_top < 0)
|
|
|
|
screen_top = 0;
|
|
|
|
gui_list->start_item[i] = MIN(screen_top, gui_list->start_item[i] +
|
|
|
|
gui_list->selected_size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gui_list->start_item[i] = MAX(0, gui_list->start_item[i] -
|
|
|
|
gui_list->selected_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else gui_list->selected_item += offset;
|
|
|
|
gui_synclist_select_item(gui_list, gui_list->selected_item);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2007-02-23 21:52:45 +00:00
|
|
|
/*
|
|
|
|
* Adds an item to the list (the callback will be asked for one more item)
|
|
|
|
* - gui_list : the list structure
|
|
|
|
*/
|
2007-12-17 02:37:21 +00:00
|
|
|
void gui_synclist_add_item(struct gui_synclist * gui_list)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2005-10-29 02:33:19 +00:00
|
|
|
gui_list->nb_items++;
|
2005-10-28 00:00:00 +00:00
|
|
|
/* if only one item in the list, select it */
|
|
|
|
if(gui_list->nb_items == 1)
|
|
|
|
gui_list->selected_item = 0;
|
|
|
|
}
|
|
|
|
|
2007-02-23 21:52:45 +00:00
|
|
|
/*
|
|
|
|
* Removes an item to the list (the callback will be asked for one less item)
|
|
|
|
* - gui_list : the list structure
|
|
|
|
*/
|
2007-12-17 02:37:21 +00:00
|
|
|
void gui_synclist_del_item(struct gui_synclist * gui_list)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
|
|
|
if(gui_list->nb_items > 0)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
if (gui_list->selected_item == gui_list->nb_items-1)
|
2005-10-29 02:33:19 +00:00
|
|
|
gui_list->selected_item--;
|
|
|
|
gui_list->nb_items--;
|
2008-03-05 09:58:30 +00:00
|
|
|
gui_synclist_select_item(gui_list, gui_list->selected_item);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-22 04:24:26 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
void gui_list_screen_scroll_step(int ofs)
|
|
|
|
{
|
|
|
|
offset_step = ofs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_list_screen_scroll_out_of_view(bool enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
offset_out_of_view = true;
|
|
|
|
else
|
|
|
|
offset_out_of_view = false;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
2006-08-15 12:23:55 +00:00
|
|
|
|
2007-02-23 21:52:45 +00:00
|
|
|
/*
|
|
|
|
* Set the title and title icon of the list. Setting title to NULL disables
|
|
|
|
* both the title and icon. Use NOICON if there is no icon.
|
|
|
|
*/
|
2007-12-17 02:37:21 +00:00
|
|
|
void gui_synclist_set_title(struct gui_synclist * gui_list,
|
2007-04-16 09:14:36 +00:00
|
|
|
char * title, enum themable_icons icon)
|
2006-08-15 08:14:46 +00:00
|
|
|
{
|
|
|
|
gui_list->title = title;
|
2006-08-23 20:02:06 +00:00
|
|
|
gui_list->title_icon = icon;
|
2006-08-15 22:14:35 +00:00
|
|
|
if (title) {
|
2006-08-15 12:23:55 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-12-17 02:37:21 +00:00
|
|
|
int i;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].getstringsize(title, &gui_list->title_width, NULL);
|
2006-08-15 12:23:55 +00:00
|
|
|
#else
|
2006-08-15 22:14:35 +00:00
|
|
|
gui_list->title_width = strlen(title);
|
2006-08-15 12:23:55 +00:00
|
|
|
#endif
|
2006-08-15 22:14:35 +00:00
|
|
|
} else {
|
|
|
|
gui_list->title_width = 0;
|
|
|
|
}
|
2008-03-09 09:37:39 +00:00
|
|
|
force_list_reinit = true;
|
2006-08-15 08:14:46 +00:00
|
|
|
}
|
2006-08-15 12:23:55 +00:00
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
|
|
|
|
void gui_synclist_set_nb_items(struct gui_synclist * lists, int nb_items)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-10-28 00:00:00 +00:00
|
|
|
int i;
|
2007-12-17 02:37:21 +00:00
|
|
|
#endif
|
|
|
|
lists->nb_items = nb_items;
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-11-09 22:47:15 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
lists->offset_position[i] = 0;
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
#endif
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
2006-04-03 08:51:08 +00:00
|
|
|
int gui_synclist_get_nb_items(struct gui_synclist * lists)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
return lists->nb_items;
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
|
|
|
int gui_synclist_get_sel_pos(struct gui_synclist * lists)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
return lists->selected_item;
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
2006-12-09 10:02:09 +00:00
|
|
|
void gui_synclist_set_icon_callback(struct gui_synclist * lists,
|
|
|
|
list_get_icon icon_callback)
|
2005-11-16 17:23:49 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
lists->callback_get_item_icon = icon_callback;
|
2005-11-16 17:23:49 +00:00
|
|
|
}
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2007-10-21 00:20:10 +00:00
|
|
|
void gui_synclist_set_voice_callback(struct gui_synclist * lists,
|
|
|
|
list_speak_item voice_callback)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
lists->callback_speak_item = voice_callback;
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 09:58:30 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
void gui_synclist_set_color_callback(struct gui_synclist * lists,
|
|
|
|
list_get_color color_callback)
|
|
|
|
{
|
|
|
|
lists->callback_get_item_color = color_callback;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-02-23 21:52:45 +00:00
|
|
|
static void gui_synclist_select_next_page(struct gui_synclist * lists,
|
2005-10-28 00:00:00 +00:00
|
|
|
enum screen_type screen)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
gui_list_select_at_offset(lists, screens[screen].nb_lines);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2007-02-23 21:52:45 +00:00
|
|
|
static void gui_synclist_select_previous_page(struct gui_synclist * lists,
|
2005-10-28 00:00:00 +00:00
|
|
|
enum screen_type screen)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
gui_list_select_at_offset(lists, -screens[screen].nb_lines);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2005-10-28 23:52:49 +00:00
|
|
|
void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
lists->limit_scroll = scroll;
|
2006-08-15 08:14:46 +00:00
|
|
|
}
|
|
|
|
|
2006-01-22 04:24:26 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-12-17 02:37:21 +00:00
|
|
|
/*
|
|
|
|
* Makes all the item in the list scroll by one step to the right.
|
|
|
|
* Should stop increasing the value when reaching the widest item value
|
|
|
|
* in the list.
|
|
|
|
*/
|
2007-02-23 21:52:45 +00:00
|
|
|
static void gui_synclist_scroll_right(struct gui_synclist * lists)
|
2006-01-22 04:24:26 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FOR_NB_SCREENS(i)
|
2007-12-17 02:37:21 +00:00
|
|
|
{
|
|
|
|
/* FIXME: This is a fake right boundry limiter. there should be some
|
|
|
|
* callback function to find the longest item on the list in pixels,
|
|
|
|
* to stop the list from scrolling past that point */
|
|
|
|
lists->offset_position[i]+=offset_step;
|
|
|
|
if (lists->offset_position[i] > 1000)
|
|
|
|
lists->offset_position[i] = 1000;
|
|
|
|
}
|
2006-01-22 04:24:26 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 02:37:21 +00:00
|
|
|
/*
|
|
|
|
* Makes all the item in the list scroll by one step to the left.
|
|
|
|
* stops at starting position.
|
|
|
|
*/
|
2007-02-23 21:52:45 +00:00
|
|
|
static void gui_synclist_scroll_left(struct gui_synclist * lists)
|
2006-01-22 04:24:26 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FOR_NB_SCREENS(i)
|
2007-12-17 02:37:21 +00:00
|
|
|
{
|
|
|
|
lists->offset_position[i]-=offset_step;
|
|
|
|
if (lists->offset_position[i] < 0)
|
|
|
|
lists->offset_position[i] = 0;
|
|
|
|
}
|
2006-01-22 04:24:26 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
|
|
|
|
2007-10-21 00:20:10 +00:00
|
|
|
static void _gui_synclist_speak_item(struct gui_synclist *lists, bool repeating)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
list_speak_item *cb = lists->callback_speak_item;
|
2007-10-21 00:20:10 +00:00
|
|
|
if(cb && gui_synclist_get_nb_items(lists) != 0)
|
|
|
|
{
|
|
|
|
int sel = gui_synclist_get_sel_pos(lists);
|
|
|
|
talk_shutup();
|
|
|
|
/* If we got a repeating key action, or we have just very
|
|
|
|
recently started talking, then we want to stay silent for a
|
|
|
|
while until things settle. Likewise if we already had a
|
|
|
|
pending scheduled announcement not yet due: we need to
|
|
|
|
reschedule it. */
|
|
|
|
if(repeating
|
2007-12-17 02:37:21 +00:00
|
|
|
|| (lists->scheduled_talk_tick
|
|
|
|
&& TIME_BEFORE(current_tick, lists->scheduled_talk_tick))
|
|
|
|
|| (lists->last_talked_tick
|
|
|
|
&& TIME_BEFORE(current_tick, lists->last_talked_tick +HZ/4)))
|
2007-10-21 00:20:10 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
lists->scheduled_talk_tick = current_tick +HZ/4;
|
2007-10-21 00:20:10 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2007-12-17 02:37:21 +00:00
|
|
|
lists->scheduled_talk_tick = 0; /* work done */
|
|
|
|
cb(sel, lists->data);
|
|
|
|
lists->last_talked_tick = current_tick;
|
2007-10-21 00:20:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void gui_synclist_speak_item(struct gui_synclist * lists)
|
|
|
|
/* The list user should call this to speak the first item on entering
|
|
|
|
the list, and whenever the list is updated. */
|
|
|
|
{
|
|
|
|
if(gui_synclist_get_nb_items(lists) == 0 && global_settings.talk_menu)
|
|
|
|
talk_id(VOICE_EMPTY_LIST, true);
|
|
|
|
else _gui_synclist_speak_item(lists, false);
|
|
|
|
}
|
|
|
|
|
2007-07-22 21:02:24 +00:00
|
|
|
extern intptr_t get_action_data(void);
|
2007-10-22 12:26:53 +00:00
|
|
|
#if defined(HAVE_TOUCHPAD)
|
2007-12-17 04:23:34 +00:00
|
|
|
/* this needs to be fixed if we ever get more than 1 touchscreen on a target */
|
2008-03-05 10:38:10 +00:00
|
|
|
unsigned gui_synclist_do_touchpad(struct gui_synclist * gui_list, struct viewport *parent);
|
2007-10-22 12:26:53 +00:00
|
|
|
#endif
|
|
|
|
|
2007-09-17 10:08:50 +00:00
|
|
|
bool gui_synclist_do_button(struct gui_synclist * lists,
|
|
|
|
unsigned *actionptr, enum list_wrap wrap)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2007-09-17 10:08:50 +00:00
|
|
|
int action = *actionptr;
|
2006-09-25 11:06:54 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-09-25 10:56:38 +00:00
|
|
|
static bool scrolling_left = false;
|
2006-09-25 11:06:54 +00:00
|
|
|
#endif
|
2007-07-22 21:02:24 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_SCROLLWHEEL
|
2007-11-19 11:05:54 +00:00
|
|
|
int next_item_modifier = button_apply_acceleration(get_action_data());
|
2007-07-22 21:02:24 +00:00
|
|
|
#else
|
2007-05-27 15:08:56 +00:00
|
|
|
static int next_item_modifier = 1;
|
|
|
|
static int last_accel_tick = 0;
|
|
|
|
|
|
|
|
if (global_settings.list_accel_start_delay)
|
|
|
|
{
|
|
|
|
int start_delay = global_settings.list_accel_start_delay * (HZ/2);
|
|
|
|
int accel_wait = global_settings.list_accel_wait * HZ/2;
|
|
|
|
|
|
|
|
if (get_action_statuscode(NULL)&ACTION_REPEAT)
|
|
|
|
{
|
|
|
|
if (!last_accel_tick)
|
|
|
|
last_accel_tick = current_tick + start_delay;
|
|
|
|
else if (current_tick >=
|
|
|
|
last_accel_tick + accel_wait)
|
|
|
|
{
|
|
|
|
last_accel_tick = current_tick;
|
|
|
|
next_item_modifier++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (last_accel_tick)
|
|
|
|
{
|
|
|
|
next_item_modifier = 1;
|
|
|
|
last_accel_tick = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-07-22 21:02:24 +00:00
|
|
|
#endif
|
2007-10-22 12:26:53 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_TOUCHPAD)
|
|
|
|
if (action == ACTION_TOUCHPAD)
|
2008-03-05 10:38:10 +00:00
|
|
|
action = *actionptr = gui_synclist_do_touchpad(lists, &parent[SCREEN_MAIN]);
|
2007-10-22 12:26:53 +00:00
|
|
|
#endif
|
2006-09-25 10:56:38 +00:00
|
|
|
|
2006-11-06 10:11:51 +00:00
|
|
|
switch (wrap)
|
|
|
|
{
|
|
|
|
case LIST_WRAP_ON:
|
|
|
|
gui_synclist_limit_scroll(lists, false);
|
|
|
|
break;
|
|
|
|
case LIST_WRAP_OFF:
|
|
|
|
gui_synclist_limit_scroll(lists, true);
|
|
|
|
break;
|
|
|
|
case LIST_WRAP_UNLESS_HELD:
|
2007-09-17 10:08:50 +00:00
|
|
|
if (action == ACTION_STD_PREVREPEAT ||
|
|
|
|
action == ACTION_STD_NEXTREPEAT ||
|
|
|
|
action == ACTION_LISTTREE_PGUP ||
|
|
|
|
action == ACTION_LISTTREE_PGDOWN)
|
2006-11-06 10:11:51 +00:00
|
|
|
gui_synclist_limit_scroll(lists, true);
|
|
|
|
else gui_synclist_limit_scroll(lists, false);
|
|
|
|
break;
|
|
|
|
};
|
2007-03-11 10:52:36 +00:00
|
|
|
|
2007-09-17 10:08:50 +00:00
|
|
|
switch (action)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2007-10-22 12:26:53 +00:00
|
|
|
case ACTION_REDRAW:
|
|
|
|
gui_synclist_draw(lists);
|
|
|
|
return true;
|
|
|
|
|
2007-04-08 01:33:01 +00:00
|
|
|
#ifdef HAVE_VOLUME_IN_LIST
|
|
|
|
case ACTION_LIST_VOLUP:
|
|
|
|
global_settings.volume += 2;
|
|
|
|
/* up two because the falthrough brings it down one */
|
|
|
|
case ACTION_LIST_VOLDOWN:
|
|
|
|
global_settings.volume--;
|
2007-05-30 17:57:32 +00:00
|
|
|
setvol();
|
2007-09-17 10:08:50 +00:00
|
|
|
return true;
|
2007-04-08 01:33:01 +00:00
|
|
|
#endif
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_STD_PREV:
|
|
|
|
case ACTION_STD_PREVREPEAT:
|
2007-12-17 02:37:21 +00:00
|
|
|
gui_list_select_at_offset(lists, -next_item_modifier);
|
2007-07-22 21:02:24 +00:00
|
|
|
#ifndef HAVE_SCROLLWHEEL
|
2007-03-11 10:52:36 +00:00
|
|
|
if (queue_count(&button_queue) < FRAMEDROP_TRIGGER)
|
2007-07-22 21:02:24 +00:00
|
|
|
#endif
|
2007-03-11 10:52:36 +00:00
|
|
|
gui_synclist_draw(lists);
|
2007-10-21 00:20:10 +00:00
|
|
|
_gui_synclist_speak_item(lists,
|
|
|
|
action == ACTION_STD_PREVREPEAT
|
|
|
|
|| next_item_modifier >1);
|
2006-02-19 13:34:12 +00:00
|
|
|
yield();
|
2007-09-17 10:08:50 +00:00
|
|
|
*actionptr = ACTION_STD_PREV;
|
|
|
|
return true;
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_STD_NEXT:
|
|
|
|
case ACTION_STD_NEXTREPEAT:
|
2007-12-17 02:37:21 +00:00
|
|
|
gui_list_select_at_offset(lists, next_item_modifier);
|
2007-07-22 21:02:24 +00:00
|
|
|
#ifndef HAVE_SCROLLWHEEL
|
2007-03-11 10:52:36 +00:00
|
|
|
if (queue_count(&button_queue) < FRAMEDROP_TRIGGER)
|
2007-07-22 21:02:24 +00:00
|
|
|
#endif
|
2007-03-11 10:52:36 +00:00
|
|
|
gui_synclist_draw(lists);
|
2007-10-21 00:20:10 +00:00
|
|
|
_gui_synclist_speak_item(lists,
|
|
|
|
action == ACTION_STD_NEXTREPEAT
|
|
|
|
|| next_item_modifier >1);
|
2006-02-19 13:34:12 +00:00
|
|
|
yield();
|
2007-09-17 10:08:50 +00:00
|
|
|
*actionptr = ACTION_STD_NEXT;
|
|
|
|
return true;
|
2006-01-22 04:24:26 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-07-25 12:37:09 +00:00
|
|
|
case ACTION_TREE_PGRIGHT:
|
|
|
|
gui_synclist_scroll_right(lists);
|
|
|
|
gui_synclist_draw(lists);
|
2007-09-17 10:08:50 +00:00
|
|
|
return true;
|
2006-09-25 10:56:38 +00:00
|
|
|
case ACTION_TREE_ROOT_INIT:
|
2006-12-09 10:02:09 +00:00
|
|
|
/* After this button press ACTION_TREE_PGLEFT is allowed
|
|
|
|
to skip to root. ACTION_TREE_ROOT_INIT must be defined in the
|
|
|
|
keymaps as a repeated button press (the same as the repeated
|
|
|
|
ACTION_TREE_PGLEFT) with the pre condition being the non-repeated
|
|
|
|
button press */
|
2007-12-17 02:37:21 +00:00
|
|
|
if (lists->offset_position[0] == 0)
|
2006-09-25 10:56:38 +00:00
|
|
|
{
|
|
|
|
scrolling_left = false;
|
2007-09-17 10:08:50 +00:00
|
|
|
*actionptr = ACTION_STD_CANCEL;
|
|
|
|
return true;
|
2006-09-25 10:56:38 +00:00
|
|
|
}
|
2007-09-17 10:08:50 +00:00
|
|
|
*actionptr = ACTION_TREE_PGLEFT;
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_TREE_PGLEFT:
|
2007-12-17 02:37:21 +00:00
|
|
|
if(!scrolling_left && (lists->offset_position[0] == 0))
|
2007-09-17 10:08:50 +00:00
|
|
|
{
|
|
|
|
*actionptr = ACTION_STD_CANCEL;
|
|
|
|
return false;
|
|
|
|
}
|
2006-07-02 12:28:27 +00:00
|
|
|
gui_synclist_scroll_left(lists);
|
|
|
|
gui_synclist_draw(lists);
|
2006-12-09 10:02:09 +00:00
|
|
|
scrolling_left = true; /* stop ACTION_TREE_PAGE_LEFT
|
|
|
|
skipping to root */
|
2007-09-17 10:08:50 +00:00
|
|
|
return true;
|
2006-01-22 01:42:05 +00:00
|
|
|
#endif
|
2006-12-09 10:02:09 +00:00
|
|
|
/* for pgup / pgdown, we are obliged to have a different behaviour depending
|
|
|
|
* on the screen for which the user pressed the key since for example, remote
|
|
|
|
* and main screen doesn't have the same number of lines */
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_LISTTREE_PGUP:
|
2007-03-04 07:45:12 +00:00
|
|
|
{
|
|
|
|
int screen =
|
2007-03-04 08:35:20 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2007-03-04 07:45:12 +00:00
|
|
|
get_action_statuscode(NULL)&ACTION_REMOTE ?
|
|
|
|
SCREEN_REMOTE :
|
|
|
|
#endif
|
|
|
|
SCREEN_MAIN;
|
|
|
|
gui_synclist_select_previous_page(lists, screen);
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_synclist_draw(lists);
|
2007-10-21 00:20:10 +00:00
|
|
|
_gui_synclist_speak_item(lists, false);
|
2006-06-04 17:14:17 +00:00
|
|
|
yield();
|
2007-09-17 10:08:50 +00:00
|
|
|
*actionptr = ACTION_STD_NEXT;
|
2007-03-04 07:45:12 +00:00
|
|
|
}
|
2007-09-17 10:08:50 +00:00
|
|
|
return true;
|
2007-03-04 07:45:12 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_LISTTREE_PGDOWN:
|
2007-03-04 07:45:12 +00:00
|
|
|
{
|
|
|
|
int screen =
|
2007-03-04 08:35:20 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2007-03-04 07:45:12 +00:00
|
|
|
get_action_statuscode(NULL)&ACTION_REMOTE ?
|
|
|
|
SCREEN_REMOTE :
|
|
|
|
#endif
|
|
|
|
SCREEN_MAIN;
|
|
|
|
gui_synclist_select_next_page(lists, screen);
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_synclist_draw(lists);
|
2007-10-21 00:20:10 +00:00
|
|
|
_gui_synclist_speak_item(lists, false);
|
2006-06-04 17:14:17 +00:00
|
|
|
yield();
|
2007-09-17 10:08:50 +00:00
|
|
|
*actionptr = ACTION_STD_PREV;
|
2007-03-04 07:45:12 +00:00
|
|
|
}
|
2007-09-17 10:08:50 +00:00
|
|
|
return true;
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
if(lists->scheduled_talk_tick
|
|
|
|
&& TIME_AFTER(current_tick, lists->scheduled_talk_tick))
|
2007-10-21 00:20:10 +00:00
|
|
|
/* scheduled postponed item announcement is due */
|
|
|
|
_gui_synclist_speak_item(lists, false);
|
2007-09-17 10:08:50 +00:00
|
|
|
return false;
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
2007-10-20 12:32:55 +00:00
|
|
|
|
2007-10-21 00:20:10 +00:00
|
|
|
int list_do_action_timeout(struct gui_synclist *lists, int timeout)
|
|
|
|
/* Returns the lowest of timeout or the delay until a postponed
|
|
|
|
scheduled announcement is due (if any). */
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
if(lists->scheduled_talk_tick)
|
2007-10-21 00:20:10 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
long delay = lists->scheduled_talk_tick -current_tick +1;
|
2007-10-21 00:20:10 +00:00
|
|
|
/* +1 because the trigger condition uses TIME_AFTER(), which
|
|
|
|
is implemented as strictly greater than. */
|
|
|
|
if(delay < 0)
|
|
|
|
delay = 0;
|
|
|
|
if(timeout > delay || timeout == TIMEOUT_BLOCK)
|
|
|
|
timeout = delay;
|
|
|
|
}
|
|
|
|
return timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool list_do_action(int context, int timeout,
|
|
|
|
struct gui_synclist *lists, int *action,
|
|
|
|
enum list_wrap wrap)
|
|
|
|
/* Combines the get_action() (with possibly overridden timeout) and
|
|
|
|
gui_synclist_do_button() calls. Returns the list action from
|
|
|
|
do_button, and places the action from get_action in *action. */
|
|
|
|
{
|
|
|
|
timeout = list_do_action_timeout(lists, timeout);
|
|
|
|
*action = get_action(context, timeout);
|
|
|
|
return gui_synclist_do_button(lists, action, wrap);
|
|
|
|
}
|
|
|
|
|
2007-10-20 12:32:55 +00:00
|
|
|
/* Simple use list implementation */
|
|
|
|
static int simplelist_line_count = 0;
|
|
|
|
static char simplelist_text[SIMPLELIST_MAX_LINES][SIMPLELIST_MAX_LINELENGTH];
|
|
|
|
/* set the amount of lines shown in the list */
|
|
|
|
void simplelist_set_line_count(int lines)
|
|
|
|
{
|
|
|
|
if (lines < 0)
|
|
|
|
lines = 0;
|
|
|
|
else if (lines > SIMPLELIST_MAX_LINES)
|
|
|
|
lines = SIMPLELIST_MAX_LINES;
|
|
|
|
simplelist_line_count = 0;
|
|
|
|
}
|
|
|
|
/* get the current amount of lines shown */
|
|
|
|
int simplelist_get_line_count(void)
|
|
|
|
{
|
|
|
|
return simplelist_line_count;
|
|
|
|
}
|
|
|
|
/* add/edit a line in the list.
|
|
|
|
if line_number > number of lines shown it adds the line, else it edits the line */
|
|
|
|
void simplelist_addline(int line_number, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (line_number > simplelist_line_count)
|
|
|
|
{
|
|
|
|
if (simplelist_line_count < SIMPLELIST_MAX_LINES)
|
|
|
|
line_number = simplelist_line_count++;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(simplelist_text[line_number], SIMPLELIST_MAX_LINELENGTH, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* simplelist_static_getname(int item, void * data, char *buffer)
|
|
|
|
{
|
|
|
|
(void)data; (void)buffer;
|
|
|
|
return simplelist_text[item];
|
|
|
|
}
|
|
|
|
bool simplelist_show_list(struct simplelist_info *info)
|
|
|
|
{
|
|
|
|
struct gui_synclist lists;
|
2008-03-26 09:05:42 +00:00
|
|
|
struct viewport vp[NB_SCREENS];
|
|
|
|
int action, old_line_count = simplelist_line_count,i;
|
2007-10-20 12:32:55 +00:00
|
|
|
char* (*getname)(int item, void * data, char *buffer);
|
|
|
|
if (info->get_name)
|
|
|
|
getname = info->get_name;
|
|
|
|
else
|
|
|
|
getname = simplelist_static_getname;
|
2008-03-26 09:05:42 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
viewport_set_defaults(&vp[i], i);
|
|
|
|
}
|
2007-10-20 12:32:55 +00:00
|
|
|
gui_synclist_init(&lists, getname, info->callback_data,
|
2008-03-26 09:05:42 +00:00
|
|
|
info->scroll_all, info->selection_size, vp);
|
|
|
|
|
2007-10-20 12:32:55 +00:00
|
|
|
if (info->title)
|
|
|
|
gui_synclist_set_title(&lists, info->title, NOICON);
|
|
|
|
if (info->get_icon)
|
|
|
|
gui_synclist_set_icon_callback(&lists, info->get_icon);
|
2007-10-21 01:27:17 +00:00
|
|
|
if (info->get_talk)
|
|
|
|
gui_synclist_set_voice_callback(&lists, info->get_talk);
|
2007-10-20 12:32:55 +00:00
|
|
|
|
|
|
|
gui_synclist_hide_selection_marker(&lists, info->hide_selection);
|
|
|
|
|
|
|
|
if (info->action_callback)
|
|
|
|
info->action_callback(ACTION_REDRAW, &lists);
|
|
|
|
|
|
|
|
if (info->get_name == NULL)
|
|
|
|
gui_synclist_set_nb_items(&lists, simplelist_line_count*info->selection_size);
|
|
|
|
else
|
|
|
|
gui_synclist_set_nb_items(&lists, info->count*info->selection_size);
|
2007-10-21 13:47:43 +00:00
|
|
|
|
|
|
|
gui_synclist_select_item(&lists, info->start_selection);
|
|
|
|
|
2007-10-20 12:32:55 +00:00
|
|
|
gui_synclist_draw(&lists);
|
2007-10-23 05:19:03 +00:00
|
|
|
gui_synclist_speak_item(&lists);
|
2007-10-20 12:32:55 +00:00
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
gui_syncstatusbar_draw(&statusbars, true);
|
2007-10-24 12:32:12 +00:00
|
|
|
list_do_action(CONTEXT_STD, info->timeout,
|
|
|
|
&lists, &action, LIST_WRAP_UNLESS_HELD);
|
2007-10-26 23:11:18 +00:00
|
|
|
|
|
|
|
/* We must yield in this case or no other thread can run */
|
2007-10-26 18:04:42 +00:00
|
|
|
if (info->timeout == TIMEOUT_NOBLOCK)
|
2007-10-26 23:11:18 +00:00
|
|
|
yield();
|
|
|
|
|
2007-10-20 12:32:55 +00:00
|
|
|
if (info->action_callback)
|
|
|
|
{
|
|
|
|
action = info->action_callback(action, &lists);
|
|
|
|
if (info->get_name == NULL)
|
|
|
|
gui_synclist_set_nb_items(&lists, simplelist_line_count*info->selection_size);
|
|
|
|
}
|
|
|
|
if (action == ACTION_STD_CANCEL)
|
|
|
|
break;
|
2008-02-25 07:41:30 +00:00
|
|
|
else if ((action == ACTION_REDRAW) ||
|
2007-11-04 01:04:10 +00:00
|
|
|
(old_line_count != simplelist_line_count))
|
2007-10-20 12:32:55 +00:00
|
|
|
{
|
|
|
|
if (info->get_name == NULL)
|
|
|
|
gui_synclist_set_nb_items(&lists, simplelist_line_count*info->selection_size);
|
|
|
|
gui_synclist_draw(&lists);
|
2007-11-04 12:52:32 +00:00
|
|
|
if (action != ACTION_NONE)
|
|
|
|
gui_synclist_speak_item(&lists);
|
2007-10-21 11:06:30 +00:00
|
|
|
old_line_count = simplelist_line_count;
|
2007-10-20 12:32:55 +00:00
|
|
|
}
|
|
|
|
else if(default_event_handler(action) == SYS_USB_CONNECTED)
|
|
|
|
return true;
|
|
|
|
}
|
2007-10-23 05:19:03 +00:00
|
|
|
talk_shutup();
|
2007-10-20 12:32:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-10-21 01:27:17 +00:00
|
|
|
void simplelist_info_init(struct simplelist_info *info, char* title,
|
2007-10-21 06:42:52 +00:00
|
|
|
int count, void* data)
|
2007-10-21 01:27:17 +00:00
|
|
|
{
|
|
|
|
info->title = title;
|
|
|
|
info->count = count;
|
2007-10-21 06:42:52 +00:00
|
|
|
info->selection_size = 1;
|
2007-10-21 01:27:17 +00:00
|
|
|
info->hide_selection = false;
|
|
|
|
info->scroll_all = false;
|
2007-10-21 13:47:43 +00:00
|
|
|
info->timeout = HZ/10;
|
|
|
|
info->start_selection = 0;
|
2007-10-21 01:27:17 +00:00
|
|
|
info->action_callback = NULL;
|
|
|
|
info->get_icon = NULL;
|
|
|
|
info->get_name = NULL;
|
|
|
|
info->get_talk = NULL;
|
|
|
|
info->callback_data = data;
|
|
|
|
}
|
2007-10-20 12:32:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|