Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
Kevin Ferrare | a3ed62b | 2005-10-30 01:24:35 +0000 | [diff] [blame] | 10 | * Copyright (C) 2005 by Kevin Ferrare |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 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. |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
Thomas Martitz | 50a6ca3 | 2010-05-06 21:04:40 +0000 | [diff] [blame] | 22 | #include <stdarg.h> |
Thomas Martitz | 55e4fe7 | 2010-05-06 22:33:57 +0000 | [diff] [blame] | 23 | #include <stdio.h> |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 24 | #include "config.h" |
| 25 | #include "lcd.h" |
| 26 | #include "font.h" |
| 27 | #include "button.h" |
Dave Chapman | 079ad11 | 2006-08-15 08:14:46 +0000 | [diff] [blame] | 28 | #include "string.h" |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 29 | #include "settings.h" |
| 30 | #include "kernel.h" |
Jonathan Gordon | fea8888 | 2007-06-05 02:57:43 +0000 | [diff] [blame] | 31 | #include "system.h" |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 32 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 33 | #include "action.h" |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 34 | #include "screen_access.h" |
| 35 | #include "list.h" |
| 36 | #include "scrollbar.h" |
Linus Nielsen Feltzing | 298c2bb | 2007-03-05 00:32:33 +0000 | [diff] [blame] | 37 | #include "lang.h" |
Jonathan Gordon | a053e58 | 2007-04-08 01:33:01 +0000 | [diff] [blame] | 38 | #include "sound.h" |
Nils Wallménius | fbdbd21 | 2007-05-30 18:08:29 +0000 | [diff] [blame] | 39 | #include "misc.h" |
Stéphane Doyon | 8486c04 | 2007-10-21 00:20:10 +0000 | [diff] [blame] | 40 | #include "talk.h" |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 41 | #include "viewport.h" |
Thomas Martitz | 2eb1cb6 | 2009-09-07 17:37:06 +0000 | [diff] [blame] | 42 | #include "appevents.h" |
Jonathan Gordon | 466e5d9 | 2010-02-26 03:45:41 +0000 | [diff] [blame] | 43 | #include "statusbar-skinned.h" |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 44 | |
Miika Pekkarinen | 2eefb5a | 2007-03-11 10:52:36 +0000 | [diff] [blame] | 45 | /* The minimum number of pending button events in queue before starting |
| 46 | * to limit list drawing interval. |
| 47 | */ |
| 48 | #define FRAMEDROP_TRIGGER 6 |
| 49 | |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 50 | #ifdef HAVE_LCD_BITMAP |
| 51 | static int offset_step = 16; /* pixels per screen scroll step */ |
| 52 | /* should lines scroll out of the screen */ |
| 53 | static bool offset_out_of_view = false; |
| 54 | #endif |
| 55 | |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 56 | static void gui_list_select_at_offset(struct gui_synclist * gui_list, |
| 57 | int offset); |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 58 | void list_draw(struct screen *display, struct gui_synclist *list); |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 59 | |
| 60 | #ifdef HAVE_LCD_BITMAP |
Thomas Martitz | 0acdc87 | 2011-10-07 17:22:49 +0000 | [diff] [blame] | 61 | static long last_dirty_tick; |
Thomas Martitz | 2eb1cb6 | 2009-09-07 17:37:06 +0000 | [diff] [blame] | 62 | static struct viewport parent[NB_SCREENS]; |
| 63 | |
Thomas Martitz | f865066 | 2011-10-07 17:28:27 +0000 | [diff] [blame] | 64 | static bool list_is_dirty(struct gui_synclist *list) |
| 65 | { |
| 66 | return TIME_BEFORE(list->dirty_tick, last_dirty_tick); |
| 67 | } |
| 68 | |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 69 | static void list_force_reinit(unsigned short id, void *param, void *last_dirty_tick) |
Thomas Martitz | 2eb1cb6 | 2009-09-07 17:37:06 +0000 | [diff] [blame] | 70 | { |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 71 | (void)id; |
Thomas Martitz | 2eb1cb6 | 2009-09-07 17:37:06 +0000 | [diff] [blame] | 72 | (void)param; |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 73 | *(int *)last_dirty_tick = current_tick; |
Thomas Martitz | 2eb1cb6 | 2009-09-07 17:37:06 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void list_init(void) |
| 77 | { |
Thomas Martitz | 0acdc87 | 2011-10-07 17:22:49 +0000 | [diff] [blame] | 78 | last_dirty_tick = current_tick; |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 79 | add_event_ex(GUI_EVENT_THEME_CHANGED, false, list_force_reinit, &last_dirty_tick); |
Thomas Martitz | 2eb1cb6 | 2009-09-07 17:37:06 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 82 | static void list_init_viewports(struct gui_synclist *list) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 83 | { |
Thomas Martitz | 09d0b6f | 2011-10-22 10:06:48 +0000 | [diff] [blame] | 84 | bool parent_used = (*list->parent == &parent[SCREEN_MAIN]); |
Thomas Martitz | 2eb1cb6 | 2009-09-07 17:37:06 +0000 | [diff] [blame] | 85 | |
Thomas Martitz | 09d0b6f | 2011-10-22 10:06:48 +0000 | [diff] [blame] | 86 | if (parent_used) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 87 | { |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 88 | FOR_NB_SCREENS(i) |
Thomas Martitz | 2eb1cb6 | 2009-09-07 17:37:06 +0000 | [diff] [blame] | 89 | { |
Thomas Martitz | 5c509d1 | 2011-10-22 10:09:23 +0000 | [diff] [blame] | 90 | gui_synclist_set_viewport_defaults(list->parent[i], i); |
Thomas Martitz | 2eb1cb6 | 2009-09-07 17:37:06 +0000 | [diff] [blame] | 91 | } |
| 92 | } |
Thomas Martitz | 42a33a7 | 2011-10-07 17:31:15 +0000 | [diff] [blame] | 93 | list->dirty_tick = current_tick; |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 94 | } |
| 95 | #else |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 96 | static struct viewport parent[NB_SCREENS] = |
| 97 | { |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 98 | [SCREEN_MAIN] = |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 99 | { |
| 100 | .x = 0, |
| 101 | .y = 0, |
| 102 | .width = LCD_WIDTH, |
| 103 | .height = LCD_HEIGHT |
| 104 | }, |
| 105 | }; |
| 106 | |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 107 | #define list_init_viewports(a) |
Thomas Martitz | f865066 | 2011-10-07 17:28:27 +0000 | [diff] [blame] | 108 | #define list_is_dirty(a) false |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 109 | #endif |
| 110 | |
| 111 | #ifdef HAVE_LCD_BITMAP |
Thomas Martitz | eec89a9 | 2013-12-20 23:34:28 +0100 | [diff] [blame] | 112 | static int list_nb_lines(struct gui_synclist *list, enum screen_type screen) |
| 113 | { |
| 114 | struct viewport *vp = list->parent[screen]; |
| 115 | return vp->height / list->line_height[screen]; |
| 116 | } |
| 117 | |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 118 | bool list_display_title(struct gui_synclist *list, enum screen_type screen) |
| 119 | { |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 120 | return list->title != NULL && |
Jonathan Gordon | 3211481 | 2010-02-26 06:45:50 +0000 | [diff] [blame] | 121 | !sb_set_title_text(list->title, list->title_icon, screen) && |
Thomas Martitz | eec89a9 | 2013-12-20 23:34:28 +0100 | [diff] [blame] | 122 | list_nb_lines(list, screen) > 2; |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Thomas Martitz | eec89a9 | 2013-12-20 23:34:28 +0100 | [diff] [blame] | 125 | int list_get_nb_lines(struct gui_synclist *list, enum screen_type screen) |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 126 | { |
Thomas Martitz | 3b12634 | 2011-10-17 17:38:10 +0000 | [diff] [blame] | 127 | int lines = skinlist_get_line_count(screen, list); |
| 128 | if (lines < 0) |
| 129 | { |
Thomas Martitz | eec89a9 | 2013-12-20 23:34:28 +0100 | [diff] [blame] | 130 | lines = list_nb_lines(list, screen); |
Thomas Martitz | 3b12634 | 2011-10-17 17:38:10 +0000 | [diff] [blame] | 131 | if (list_display_title(list, screen)) |
| 132 | lines -= 1; |
| 133 | } |
| 134 | return lines; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 135 | } |
Thomas Martitz | eec89a9 | 2013-12-20 23:34:28 +0100 | [diff] [blame] | 136 | |
| 137 | void list_init_item_height(struct gui_synclist *list, enum screen_type screen) |
| 138 | { |
| 139 | struct viewport *vp = list->parent[screen]; |
| 140 | #ifdef HAVE_TOUCHSCREEN |
| 141 | /* the 4/12 factor is designed for reasonable item size on a 160dpi screen */ |
| 142 | if (global_settings.list_line_padding == -1) |
| 143 | list->line_height[screen] = MAX(lcd_get_dpi()*4/12, (int)font_get(vp->font)->height); |
| 144 | else |
| 145 | list->line_height[screen] = font_get(vp->font)->height + global_settings.list_line_padding; |
| 146 | #else |
| 147 | list->line_height[screen] = font_get(vp->font)->height; |
| 148 | #endif |
| 149 | } |
| 150 | |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 151 | #else |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 152 | #define list_display_title(l, i) false |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 153 | #define list_get_nb_lines(list, screen) \ |
| 154 | viewport_get_nb_lines((list)->parent[(screen)]); |
Thomas Martitz | eec89a9 | 2013-12-20 23:34:28 +0100 | [diff] [blame] | 155 | #define list_init_item_height(l, i) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 156 | #endif |
Nils Wallménius | 7fdee10 | 2007-02-23 21:52:45 +0000 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | * Initializes a scrolling list |
| 160 | * - gui_list : the list structure to initialize |
Nils Wallménius | 7fdee10 | 2007-02-23 21:52:45 +0000 | [diff] [blame] | 161 | * - callback_get_item_name : pointer to a function that associates a label |
| 162 | * to a given item number |
| 163 | * - data : extra data passed to the list callback |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 164 | * - scroll_all : |
| 165 | * - selected_size : |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 166 | * - parent : the parent viewports to use. NULL means the full screen minus |
| 167 | * statusbar if enabled. NOTE: new screens should NOT set this to NULL. |
Nils Wallménius | 7fdee10 | 2007-02-23 21:52:45 +0000 | [diff] [blame] | 168 | */ |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 169 | void gui_synclist_init(struct gui_synclist * gui_list, |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 170 | list_get_name callback_get_item_name, |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 171 | void * data, |
| 172 | bool scroll_all, |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 173 | int selected_size, struct viewport list_parent[NB_SCREENS] |
Kevin Ferrare | e75cbdd | 2005-10-29 02:33:19 +0000 | [diff] [blame] | 174 | ) |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 175 | { |
Kevin Ferrare | 15046f9 | 2005-11-16 17:23:49 +0000 | [diff] [blame] | 176 | gui_list->callback_get_item_icon = NULL; |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 177 | gui_list->callback_get_item_name = callback_get_item_name; |
Stéphane Doyon | 8486c04 | 2007-10-21 00:20:10 +0000 | [diff] [blame] | 178 | gui_list->callback_speak_item = NULL; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 179 | gui_list->nb_items = 0; |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 180 | gui_list->selected_item = 0; |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 181 | FOR_NB_SCREENS(i) |
| 182 | { |
| 183 | gui_list->start_item[i] = 0; |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 184 | #ifdef HAVE_LCD_BITMAP |
| 185 | gui_list->offset_position[i] = 0; |
| 186 | #endif |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 187 | if (list_parent) |
| 188 | gui_list->parent[i] = &list_parent[i]; |
| 189 | else |
Thomas Martitz | 2eb1cb6 | 2009-09-07 17:37:06 +0000 | [diff] [blame] | 190 | gui_list->parent[i] = &parent[i]; |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 191 | } |
Jonathan Gordon | be185a1 | 2008-03-26 09:05:42 +0000 | [diff] [blame] | 192 | list_init_viewports(gui_list); |
Thomas Martitz | eec89a9 | 2013-12-20 23:34:28 +0100 | [diff] [blame] | 193 | FOR_NB_SCREENS(i) |
| 194 | list_init_item_height(gui_list, i); |
Kevin Ferrare | e75cbdd | 2005-10-29 02:33:19 +0000 | [diff] [blame] | 195 | gui_list->limit_scroll = false; |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 196 | gui_list->data = data; |
| 197 | gui_list->scroll_all = scroll_all; |
| 198 | gui_list->selected_size = selected_size; |
Dave Chapman | 079ad11 | 2006-08-15 08:14:46 +0000 | [diff] [blame] | 199 | gui_list->title = NULL; |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 200 | gui_list->title_icon = Icon_NOICON; |
Miika Pekkarinen | 2eefb5a | 2007-03-11 10:52:36 +0000 | [diff] [blame] | 201 | |
Stéphane Doyon | 8486c04 | 2007-10-21 00:20:10 +0000 | [diff] [blame] | 202 | gui_list->scheduled_talk_tick = gui_list->last_talked_tick = 0; |
Thomas Martitz | 0acdc87 | 2011-10-07 17:22:49 +0000 | [diff] [blame] | 203 | gui_list->dirty_tick = current_tick; |
Jonathan Gordon | 3823486 | 2007-06-07 12:14:31 +0000 | [diff] [blame] | 204 | gui_list->show_selection_marker = true; |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 205 | |
| 206 | #ifdef HAVE_LCD_COLOR |
| 207 | gui_list->title_color = -1; |
| 208 | gui_list->callback_get_item_color = NULL; |
| 209 | #endif |
Jonathan Gordon | 3823486 | 2007-06-07 12:14:31 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /* this toggles the selection bar or cursor */ |
| 213 | void gui_synclist_hide_selection_marker(struct gui_synclist * lists, bool hide) |
| 214 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 215 | lists->show_selection_marker = !hide; |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 218 | |
Mark Arigo | 34301bb | 2006-08-23 20:02:06 +0000 | [diff] [blame] | 219 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 220 | int gui_list_get_item_offset(struct gui_synclist * gui_list, |
| 221 | int item_width, |
| 222 | int text_pos, |
| 223 | struct screen * display, |
| 224 | struct viewport *vp) |
Mark Arigo | 34301bb | 2006-08-23 20:02:06 +0000 | [diff] [blame] | 225 | { |
Mark Arigo | 34301bb | 2006-08-23 20:02:06 +0000 | [diff] [blame] | 226 | int item_offset; |
Miika Pekkarinen | 2eefb5a | 2007-03-11 10:52:36 +0000 | [diff] [blame] | 227 | |
Mark Arigo | 34301bb | 2006-08-23 20:02:06 +0000 | [diff] [blame] | 228 | if (offset_out_of_view) |
| 229 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 230 | item_offset = gui_list->offset_position[display->screen_type]; |
Mark Arigo | 34301bb | 2006-08-23 20:02:06 +0000 | [diff] [blame] | 231 | } |
| 232 | else |
| 233 | { |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 234 | /* if text is smaller than view */ |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 235 | if (item_width <= vp->width - text_pos) |
Mark Arigo | 34301bb | 2006-08-23 20:02:06 +0000 | [diff] [blame] | 236 | { |
| 237 | item_offset = 0; |
| 238 | } |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 239 | /* if text got out of view */ |
| 240 | else if (gui_list->offset_position[display->screen_type] > |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 241 | item_width - (vp->width - text_pos)) |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 242 | { |
| 243 | item_offset = item_width - (vp->width - text_pos); |
Mark Arigo | 34301bb | 2006-08-23 20:02:06 +0000 | [diff] [blame] | 244 | } |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 245 | else |
| 246 | item_offset = gui_list->offset_position[display->screen_type]; |
Mark Arigo | 34301bb | 2006-08-23 20:02:06 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | return item_offset; |
| 250 | } |
| 251 | #endif |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 252 | |
Nils Wallménius | 7fdee10 | 2007-02-23 21:52:45 +0000 | [diff] [blame] | 253 | /* |
Miika Pekkarinen | 2eefb5a | 2007-03-11 10:52:36 +0000 | [diff] [blame] | 254 | * Force a full screen update. |
| 255 | */ |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 256 | void gui_synclist_draw(struct gui_synclist *gui_list) |
Miika Pekkarinen | 2eefb5a | 2007-03-11 10:52:36 +0000 | [diff] [blame] | 257 | { |
Thomas Martitz | f865066 | 2011-10-07 17:28:27 +0000 | [diff] [blame] | 258 | if (list_is_dirty(gui_list)) |
Jonathan Gordon | 885283c | 2008-03-09 09:37:39 +0000 | [diff] [blame] | 259 | { |
Jonathan Gordon | be185a1 | 2008-03-26 09:05:42 +0000 | [diff] [blame] | 260 | list_init_viewports(gui_list); |
Thomas Martitz | eec89a9 | 2013-12-20 23:34:28 +0100 | [diff] [blame] | 261 | FOR_NB_SCREENS(i) |
| 262 | list_init_item_height(gui_list, i); |
Nils Wallménius | 68f6e83 | 2008-10-13 12:16:06 +0000 | [diff] [blame] | 263 | gui_synclist_select_item(gui_list, gui_list->selected_item); |
Jonathan Gordon | 885283c | 2008-03-09 09:37:39 +0000 | [diff] [blame] | 264 | } |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 265 | FOR_NB_SCREENS(i) |
| 266 | { |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 267 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | 9b6ac01 | 2011-09-06 13:49:41 +0000 | [diff] [blame] | 268 | if (!skinlist_draw(&screens[i], gui_list)) |
| 269 | #endif |
| 270 | list_draw(&screens[i], gui_list); |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 271 | } |
Miika Pekkarinen | 2eefb5a | 2007-03-11 10:52:36 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 274 | /* sets up the list so the selection is shown correctly on the screen */ |
| 275 | static void gui_list_put_selection_on_screen(struct gui_synclist * gui_list, |
| 276 | enum screen_type screen) |
Miika Pekkarinen | 2eefb5a | 2007-03-11 10:52:36 +0000 | [diff] [blame] | 277 | { |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 278 | int nb_lines = list_get_nb_lines(gui_list, screen); |
| 279 | int bottom = MAX(0, gui_list->nb_items - nb_lines); |
| 280 | int new_start_item = gui_list->start_item[screen]; |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 281 | int difference = gui_list->selected_item - gui_list->start_item[screen]; |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 282 | #ifdef HAVE_LCD_CHARCELLS |
| 283 | const int scroll_limit_up = 0; |
| 284 | const int scroll_limit_down = 1; |
| 285 | #else |
| 286 | const int scroll_limit_up = (nb_lines < gui_list->selected_size+2 ? 0:1); |
| 287 | const int scroll_limit_down = (scroll_limit_up+gui_list->selected_size); |
| 288 | #endif |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 289 | |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 290 | if (gui_list->show_selection_marker == false) |
Jonathan Gordon | 3823486 | 2007-06-07 12:14:31 +0000 | [diff] [blame] | 291 | { |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 292 | new_start_item = gui_list->selected_item; |
Jonathan Gordon | 3823486 | 2007-06-07 12:14:31 +0000 | [diff] [blame] | 293 | } |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 294 | else if (gui_list->selected_size >= nb_lines) |
Jonathan Gordon | fea8888 | 2007-06-05 02:57:43 +0000 | [diff] [blame] | 295 | { |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 296 | new_start_item = gui_list->selected_item; |
Jonathan Gordon | fea8888 | 2007-06-05 02:57:43 +0000 | [diff] [blame] | 297 | } |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 298 | else if (global_settings.scroll_paginated) |
Jonathan Gordon | fea8888 | 2007-06-05 02:57:43 +0000 | [diff] [blame] | 299 | { |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 300 | nb_lines -= nb_lines%gui_list->selected_size; |
| 301 | if (difference < 0 || difference >= nb_lines) |
Jonathan Gordon | fea8888 | 2007-06-05 02:57:43 +0000 | [diff] [blame] | 302 | { |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 303 | new_start_item = gui_list->selected_item - |
| 304 | (gui_list->selected_item%nb_lines); |
Jonathan Gordon | fea8888 | 2007-06-05 02:57:43 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 307 | else if (difference <= scroll_limit_up) /* list moved up */ |
Jonathan Gordon | fea8888 | 2007-06-05 02:57:43 +0000 | [diff] [blame] | 308 | { |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 309 | new_start_item = gui_list->selected_item - scroll_limit_up; |
| 310 | } |
| 311 | else if (difference > nb_lines - scroll_limit_down) /* list moved down */ |
| 312 | { |
| 313 | new_start_item = gui_list->selected_item + scroll_limit_down - nb_lines; |
Jonathan Gordon | fea8888 | 2007-06-05 02:57:43 +0000 | [diff] [blame] | 314 | } |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 315 | if (new_start_item < 0) |
| 316 | gui_list->start_item[screen] = 0; |
| 317 | else if (new_start_item > bottom) |
| 318 | gui_list->start_item[screen] = bottom; |
| 319 | else |
| 320 | gui_list->start_item[screen] = new_start_item; |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 321 | } |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 322 | |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 323 | static void edge_beep(struct gui_synclist * gui_list, bool wrap) |
| 324 | { |
| 325 | #if CONFIG_CODEC != SWCODEC |
| 326 | (void)gui_list; |
| 327 | (void)wrap; |
| 328 | #else |
| 329 | if (global_settings.keyclick) |
| 330 | { |
| 331 | list_speak_item *cb = gui_list->callback_speak_item; |
| 332 | if (!wrap) /* a bounce */ |
| 333 | { |
| 334 | static long last_bounce_tick = 0; |
| 335 | if(TIME_BEFORE(current_tick, last_bounce_tick+HZ/4)) |
| 336 | return; |
| 337 | last_bounce_tick = current_tick; |
| 338 | } |
| 339 | /* Next thing the list code will do is go speak the item, doing |
| 340 | a talk_shutup() first. Shutup now so the beep is clearer, and |
| 341 | make sure the subsequent shutup is skipped because otherwise |
| 342 | it'd kill the pcm buffer. */ |
| 343 | if (cb) { |
| 344 | talk_shutup(); |
| 345 | talk_force_enqueue_next(); |
| 346 | } |
| 347 | system_sound_play(wrap ? SOUND_LIST_EDGE_BEEP_WRAP : SOUND_LIST_EDGE_BEEP_NOWRAP); |
| 348 | if (cb) { |
| 349 | /* On at least x5: if, instead of the above shutup, I insert a |
| 350 | sleep just after the beep_play() call, to delay the subsequent |
| 351 | shutup and talk, then in some cases the beep is not played: if |
| 352 | the end of a previous utterance is still playing from the pcm buf, |
| 353 | the beep fails, even if there would seem to remain enough time |
| 354 | to the utterance to mix in the beep. */ |
| 355 | |
| 356 | /* Somehow, the following voice utterance is suppressed on e200, |
| 357 | but not on x5. Work around... */ |
| 358 | sleep((40*HZ +999)/1000); // FIXME: Is this really needed? |
| 359 | talk_force_shutup(); |
| 360 | } |
| 361 | } |
| 362 | #endif |
| 363 | } |
| 364 | |
Steve Bavin | dddd157 | 2010-06-15 07:08:35 +0000 | [diff] [blame] | 365 | static void _gui_synclist_speak_item(struct gui_synclist *lists) |
| 366 | { |
| 367 | list_speak_item *cb = lists->callback_speak_item; |
| 368 | if (cb && lists->nb_items != 0) |
| 369 | { |
| 370 | talk_shutup(); |
| 371 | /* If we have just very recently started talking, then we want |
| 372 | to stay silent for a while until things settle. Likewise if |
| 373 | we already had a pending scheduled announcement not yet due |
| 374 | we need to reschedule it. */ |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 375 | if ((lists->scheduled_talk_tick && |
Steve Bavin | dddd157 | 2010-06-15 07:08:35 +0000 | [diff] [blame] | 376 | TIME_BEFORE(current_tick, lists->scheduled_talk_tick)) || |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 377 | (lists->last_talked_tick && |
Steve Bavin | dddd157 | 2010-06-15 07:08:35 +0000 | [diff] [blame] | 378 | TIME_BEFORE(current_tick, lists->last_talked_tick + HZ/5))) |
| 379 | { |
| 380 | lists->scheduled_talk_tick = current_tick + HZ/5; |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 381 | } |
Steve Bavin | dddd157 | 2010-06-15 07:08:35 +0000 | [diff] [blame] | 382 | else |
| 383 | { |
| 384 | lists->scheduled_talk_tick = 0; /* work done */ |
| 385 | cb(lists->selected_item, lists->data); |
| 386 | lists->last_talked_tick = current_tick; |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | void gui_synclist_speak_item(struct gui_synclist *lists) |
| 392 | { |
| 393 | if (global_settings.talk_menu) |
| 394 | { |
| 395 | if (lists->nb_items == 0) |
| 396 | talk_id(VOICE_EMPTY_LIST, true); |
| 397 | else |
| 398 | _gui_synclist_speak_item(lists); |
| 399 | } |
| 400 | } |
| 401 | |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 402 | /* |
| 403 | * Selects an item in the list |
| 404 | * - gui_list : the list structure |
| 405 | * - item_number : the number of the item which will be selected |
| 406 | */ |
| 407 | void gui_synclist_select_item(struct gui_synclist * gui_list, int item_number) |
| 408 | { |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 409 | if (item_number >= gui_list->nb_items || item_number < 0) |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 410 | return; |
Steve Bavin | dddd157 | 2010-06-15 07:08:35 +0000 | [diff] [blame] | 411 | if (item_number != gui_list->selected_item) |
| 412 | { |
| 413 | gui_list->selected_item = item_number; |
| 414 | _gui_synclist_speak_item(gui_list); |
| 415 | } |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 416 | FOR_NB_SCREENS(i) |
| 417 | gui_list_put_selection_on_screen(gui_list, i); |
Jonathan Gordon | fea8888 | 2007-06-05 02:57:43 +0000 | [diff] [blame] | 418 | } |
Miika Pekkarinen | 2eefb5a | 2007-03-11 10:52:36 +0000 | [diff] [blame] | 419 | |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 420 | static void gui_list_select_at_offset(struct gui_synclist * gui_list, |
| 421 | int offset) |
Jonathan Gordon | fea8888 | 2007-06-05 02:57:43 +0000 | [diff] [blame] | 422 | { |
Peter D'Hoye | c4c678f | 2008-01-21 22:28:25 +0000 | [diff] [blame] | 423 | int new_selection; |
Jonathan Gordon | 195ac12 | 2007-05-29 12:16:31 +0000 | [diff] [blame] | 424 | if (gui_list->selected_size > 1) |
| 425 | { |
| 426 | offset *= gui_list->selected_size; |
Jonathan Gordon | 195ac12 | 2007-05-29 12:16:31 +0000 | [diff] [blame] | 427 | } |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 428 | |
Peter D'Hoye | c4c678f | 2008-01-21 22:28:25 +0000 | [diff] [blame] | 429 | new_selection = gui_list->selected_item + offset; |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 430 | |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 431 | if (new_selection >= gui_list->nb_items) |
Jonathan Gordon | f3145ba | 2007-06-09 09:41:13 +0000 | [diff] [blame] | 432 | { |
Steve Bavin | dddd157 | 2010-06-15 07:08:35 +0000 | [diff] [blame] | 433 | new_selection = gui_list->limit_scroll ? |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 434 | gui_list->nb_items - gui_list->selected_size : 0; |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 435 | edge_beep(gui_list, !gui_list->limit_scroll); |
Jonathan Gordon | f3145ba | 2007-06-09 09:41:13 +0000 | [diff] [blame] | 436 | } |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 437 | else if (new_selection < 0) |
| 438 | { |
Steve Bavin | dddd157 | 2010-06-15 07:08:35 +0000 | [diff] [blame] | 439 | new_selection = gui_list->limit_scroll ? |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 440 | 0 : gui_list->nb_items - gui_list->selected_size; |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 441 | edge_beep(gui_list, !gui_list->limit_scroll); |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 442 | } |
| 443 | else if (gui_list->show_selection_marker == false) |
| 444 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 445 | FOR_NB_SCREENS(i) |
| 446 | { |
Björn Stenberg | 0942e2a | 2011-10-15 19:35:02 +0000 | [diff] [blame] | 447 | int nb_lines = list_get_nb_lines(gui_list, i); |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 448 | if (offset > 0) |
| 449 | { |
Björn Stenberg | 0942e2a | 2011-10-15 19:35:02 +0000 | [diff] [blame] | 450 | int screen_top = MAX(0, gui_list->nb_items - nb_lines); |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 451 | gui_list->start_item[i] = MIN(screen_top, gui_list->start_item[i] + |
Jonathan Gordon | 8703cca | 2008-10-12 10:21:44 +0000 | [diff] [blame] | 452 | gui_list->selected_size); |
| 453 | gui_list->selected_item = gui_list->start_item[i]; |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 454 | } |
| 455 | else |
| 456 | { |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 457 | gui_list->start_item[i] = MAX(0, gui_list->start_item[i] - |
Jonathan Gordon | 8703cca | 2008-10-12 10:21:44 +0000 | [diff] [blame] | 458 | gui_list->selected_size); |
| 459 | gui_list->selected_item = gui_list->start_item[i] + nb_lines; |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | return; |
| 463 | } |
Steve Bavin | dddd157 | 2010-06-15 07:08:35 +0000 | [diff] [blame] | 464 | gui_synclist_select_item(gui_list, new_selection); |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Nils Wallménius | 7fdee10 | 2007-02-23 21:52:45 +0000 | [diff] [blame] | 467 | /* |
| 468 | * Adds an item to the list (the callback will be asked for one more item) |
| 469 | * - gui_list : the list structure |
| 470 | */ |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 471 | void gui_synclist_add_item(struct gui_synclist * gui_list) |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 472 | { |
Kevin Ferrare | e75cbdd | 2005-10-29 02:33:19 +0000 | [diff] [blame] | 473 | gui_list->nb_items++; |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 474 | /* if only one item in the list, select it */ |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 475 | if (gui_list->nb_items == 1) |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 476 | gui_list->selected_item = 0; |
| 477 | } |
| 478 | |
Nils Wallménius | 7fdee10 | 2007-02-23 21:52:45 +0000 | [diff] [blame] | 479 | /* |
| 480 | * Removes an item to the list (the callback will be asked for one less item) |
| 481 | * - gui_list : the list structure |
| 482 | */ |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 483 | void gui_synclist_del_item(struct gui_synclist * gui_list) |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 484 | { |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 485 | if (gui_list->nb_items > 0) |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 486 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 487 | if (gui_list->selected_item == gui_list->nb_items-1) |
Kevin Ferrare | e75cbdd | 2005-10-29 02:33:19 +0000 | [diff] [blame] | 488 | gui_list->selected_item--; |
Kevin Ferrare | e75cbdd | 2005-10-29 02:33:19 +0000 | [diff] [blame] | 489 | gui_list->nb_items--; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 490 | gui_synclist_select_item(gui_list, gui_list->selected_item); |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 494 | #ifdef HAVE_LCD_BITMAP |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 495 | void gui_list_screen_scroll_step(int ofs) |
| 496 | { |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 497 | offset_step = ofs; |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | void gui_list_screen_scroll_out_of_view(bool enable) |
| 501 | { |
Nils Wallménius | 8598b57 | 2009-10-09 06:52:20 +0000 | [diff] [blame] | 502 | offset_out_of_view = enable; |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 503 | } |
| 504 | #endif /* HAVE_LCD_BITMAP */ |
Dan Everton | c0f8b18 | 2006-08-15 12:23:55 +0000 | [diff] [blame] | 505 | |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 506 | /* |
Nils Wallménius | 7fdee10 | 2007-02-23 21:52:45 +0000 | [diff] [blame] | 507 | * Set the title and title icon of the list. Setting title to NULL disables |
| 508 | * both the title and icon. Use NOICON if there is no icon. |
| 509 | */ |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 510 | void gui_synclist_set_title(struct gui_synclist * gui_list, |
Nils Wallménius | 8e33c2f | 2009-10-11 09:40:47 +0000 | [diff] [blame] | 511 | char * title, enum themable_icons icon) |
Dave Chapman | 079ad11 | 2006-08-15 08:14:46 +0000 | [diff] [blame] | 512 | { |
| 513 | gui_list->title = title; |
Mark Arigo | 34301bb | 2006-08-23 20:02:06 +0000 | [diff] [blame] | 514 | gui_list->title_icon = icon; |
Jonathan Gordon | 466e5d9 | 2010-02-26 03:45:41 +0000 | [diff] [blame] | 515 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | 466e5d9 | 2010-02-26 03:45:41 +0000 | [diff] [blame] | 516 | FOR_NB_SCREENS(i) |
| 517 | sb_set_title_text(title, icon, i); |
| 518 | #endif |
| 519 | send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); |
Dave Chapman | 079ad11 | 2006-08-15 08:14:46 +0000 | [diff] [blame] | 520 | } |
Dan Everton | c0f8b18 | 2006-08-15 12:23:55 +0000 | [diff] [blame] | 521 | |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 522 | void gui_synclist_set_nb_items(struct gui_synclist * lists, int nb_items) |
| 523 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 524 | lists->nb_items = nb_items; |
| 525 | #ifdef HAVE_LCD_BITMAP |
Jens Arnold | edf5a70 | 2005-11-09 22:47:15 +0000 | [diff] [blame] | 526 | FOR_NB_SCREENS(i) |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 527 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 528 | lists->offset_position[i] = 0; |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 529 | } |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 530 | #endif |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 531 | } |
Hristo Kovachev | 38deb8f | 2006-04-03 08:51:08 +0000 | [diff] [blame] | 532 | int gui_synclist_get_nb_items(struct gui_synclist * lists) |
| 533 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 534 | return lists->nb_items; |
Hristo Kovachev | 38deb8f | 2006-04-03 08:51:08 +0000 | [diff] [blame] | 535 | } |
| 536 | int gui_synclist_get_sel_pos(struct gui_synclist * lists) |
| 537 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 538 | return lists->selected_item; |
Hristo Kovachev | 38deb8f | 2006-04-03 08:51:08 +0000 | [diff] [blame] | 539 | } |
Peter D'Hoye | 552ac5a | 2006-12-09 10:02:09 +0000 | [diff] [blame] | 540 | void gui_synclist_set_icon_callback(struct gui_synclist * lists, |
| 541 | list_get_icon icon_callback) |
Kevin Ferrare | 15046f9 | 2005-11-16 17:23:49 +0000 | [diff] [blame] | 542 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 543 | lists->callback_get_item_icon = icon_callback; |
Kevin Ferrare | 15046f9 | 2005-11-16 17:23:49 +0000 | [diff] [blame] | 544 | } |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 545 | |
Stéphane Doyon | 8486c04 | 2007-10-21 00:20:10 +0000 | [diff] [blame] | 546 | void gui_synclist_set_voice_callback(struct gui_synclist * lists, |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 547 | list_speak_item voice_callback) |
Stéphane Doyon | 8486c04 | 2007-10-21 00:20:10 +0000 | [diff] [blame] | 548 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 549 | lists->callback_speak_item = voice_callback; |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Thomas Martitz | 5c509d1 | 2011-10-22 10:09:23 +0000 | [diff] [blame] | 552 | void gui_synclist_set_viewport_defaults(struct viewport *vp, |
| 553 | enum screen_type screen) |
| 554 | { |
Thomas Martitz | 155a9f8 | 2011-10-23 11:05:27 +0000 | [diff] [blame] | 555 | viewport_set_defaults(vp, screen); |
Thomas Martitz | 5c509d1 | 2011-10-22 10:09:23 +0000 | [diff] [blame] | 556 | #ifdef HAVE_BUTTONBAR |
| 557 | if (screens[screen].has_buttonbar) |
| 558 | vp->height -= BUTTONBAR_HEIGHT; |
| 559 | #endif |
| 560 | } |
| 561 | |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 562 | #ifdef HAVE_LCD_COLOR |
| 563 | void gui_synclist_set_color_callback(struct gui_synclist * lists, |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 564 | list_get_color color_callback) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 565 | { |
| 566 | lists->callback_get_item_color = color_callback; |
| 567 | } |
| 568 | #endif |
| 569 | |
Nils Wallménius | 7fdee10 | 2007-02-23 21:52:45 +0000 | [diff] [blame] | 570 | static void gui_synclist_select_next_page(struct gui_synclist * lists, |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 571 | enum screen_type screen) |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 572 | { |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 573 | int nb_lines = list_get_nb_lines(lists, screen); |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 574 | if (lists->selected_size > 1) |
| 575 | nb_lines = MAX(1, nb_lines/lists->selected_size); |
Jonathan Gordon | 95be4fe | 2008-05-11 14:08:46 +0000 | [diff] [blame] | 576 | gui_list_select_at_offset(lists, nb_lines); |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Nils Wallménius | 7fdee10 | 2007-02-23 21:52:45 +0000 | [diff] [blame] | 579 | static void gui_synclist_select_previous_page(struct gui_synclist * lists, |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 580 | enum screen_type screen) |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 581 | { |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 582 | int nb_lines = list_get_nb_lines(lists, screen); |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 583 | if (lists->selected_size > 1) |
| 584 | nb_lines = MAX(1, nb_lines/lists->selected_size); |
Jonathan Gordon | 95be4fe | 2008-05-11 14:08:46 +0000 | [diff] [blame] | 585 | gui_list_select_at_offset(lists, -nb_lines); |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Kevin Ferrare | d452d26 | 2005-10-28 23:52:49 +0000 | [diff] [blame] | 588 | void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll) |
| 589 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 590 | lists->limit_scroll = scroll; |
Dave Chapman | 079ad11 | 2006-08-15 08:14:46 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 593 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 594 | /* |
| 595 | * Makes all the item in the list scroll by one step to the right. |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 596 | * Should stop increasing the value when reaching the widest item value |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 597 | * in the list. |
| 598 | */ |
Nils Wallménius | 7fdee10 | 2007-02-23 21:52:45 +0000 | [diff] [blame] | 599 | static void gui_synclist_scroll_right(struct gui_synclist * lists) |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 600 | { |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 601 | FOR_NB_SCREENS(i) |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 602 | { |
| 603 | /* FIXME: This is a fake right boundry limiter. there should be some |
| 604 | * callback function to find the longest item on the list in pixels, |
| 605 | * to stop the list from scrolling past that point */ |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 606 | lists->offset_position[i] += offset_step; |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 607 | if (lists->offset_position[i] > 1000) |
| 608 | lists->offset_position[i] = 1000; |
| 609 | } |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 612 | /* |
| 613 | * Makes all the item in the list scroll by one step to the left. |
| 614 | * stops at starting position. |
| 615 | */ |
Nils Wallménius | 7fdee10 | 2007-02-23 21:52:45 +0000 | [diff] [blame] | 616 | static void gui_synclist_scroll_left(struct gui_synclist * lists) |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 617 | { |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 618 | FOR_NB_SCREENS(i) |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 619 | { |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 620 | lists->offset_position[i] -= offset_step; |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 621 | if (lists->offset_position[i] < 0) |
| 622 | lists->offset_position[i] = 0; |
| 623 | } |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 624 | } |
| 625 | #endif /* HAVE_LCD_BITMAP */ |
| 626 | |
Jonathan Gordon | eb2ea7f | 2012-01-12 22:28:36 +1100 | [diff] [blame] | 627 | #if CONFIG_CODEC == SWCODEC |
| 628 | bool gui_synclist_keyclick_callback(int action, void* data) |
| 629 | { |
| 630 | struct gui_synclist *lists = (struct gui_synclist *)data; |
| 631 | |
| 632 | /* block the beep if we are at the end of the list and we are not wrapping. |
| 633 | * CAVEAT: mosts lists don't set limit_scroll untill it sees a repeat |
| 634 | * press at the end of the list so this can cause an extra beep. |
| 635 | */ |
| 636 | if (lists->limit_scroll == false) |
| 637 | return true; |
| 638 | if (lists->selected_item == 0) |
| 639 | return (action != ACTION_STD_PREV && action != ACTION_STD_PREVREPEAT); |
| 640 | if (lists->selected_item == lists->nb_items - lists->selected_size) |
| 641 | return (action != ACTION_STD_NEXT && action != ACTION_STD_NEXTREPEAT); |
| 642 | |
| 643 | return action != ACTION_NONE; |
| 644 | } |
| 645 | #endif |
Thomas Martitz | b673ae2 | 2010-10-31 11:11:46 +0000 | [diff] [blame] | 646 | |
Jonathan Gordon | 94139ac | 2012-03-20 21:27:33 +1100 | [diff] [blame] | 647 | /* |
| 648 | * Magic to make sure the list gets updated correctly if the skin does |
| 649 | * something naughty like a full screen update when we are in a button |
| 650 | * loop. |
| 651 | * |
| 652 | * The GUI_EVENT_NEED_UI_UPDATE event is registered for in list_do_action_timeout() |
| 653 | * and unregistered in gui_synclict_do_button(). This is done because |
| 654 | * if something is using the list UI they *must* be calling those |
| 655 | * two functions in the correct order or the list wont work. |
| 656 | */ |
| 657 | static struct gui_synclist *current_lists; |
| 658 | static bool ui_update_event_registered = false; |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 659 | static void _lists_uiviewport_update_callback(unsigned short id, void *data) |
Jonathan Gordon | 94139ac | 2012-03-20 21:27:33 +1100 | [diff] [blame] | 660 | { |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 661 | (void)id; |
Jonathan Gordon | 94139ac | 2012-03-20 21:27:33 +1100 | [diff] [blame] | 662 | (void)data; |
| 663 | if (current_lists) |
| 664 | gui_synclist_draw(current_lists); |
| 665 | } |
| 666 | |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 667 | bool gui_synclist_do_button(struct gui_synclist * lists, |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 668 | int *actionptr, enum list_wrap wrap) |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 669 | { |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 670 | int action = *actionptr; |
Martin Scarratt | 4a1d8d2 | 2006-09-25 11:06:54 +0000 | [diff] [blame] | 671 | #ifdef HAVE_LCD_BITMAP |
Sebastian Leonhardt | a8758c9 | 2015-10-21 00:11:44 +0200 | [diff] [blame] | 672 | static bool pgleft_allow_cancel = false; |
Martin Scarratt | 4a1d8d2 | 2006-09-25 11:06:54 +0000 | [diff] [blame] | 673 | #endif |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 674 | |
Thomas Martitz | fd14cac | 2009-03-02 19:25:50 +0000 | [diff] [blame] | 675 | #ifdef HAVE_WHEEL_ACCELERATION |
Linus Nielsen Feltzing | e75327b | 2007-11-19 11:05:54 +0000 | [diff] [blame] | 676 | int next_item_modifier = button_apply_acceleration(get_action_data()); |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 677 | #else |
Jonathan Gordon | 42698e4 | 2007-05-27 15:08:56 +0000 | [diff] [blame] | 678 | static int next_item_modifier = 1; |
| 679 | static int last_accel_tick = 0; |
Jonathan Gordon | 42698e4 | 2007-05-27 15:08:56 +0000 | [diff] [blame] | 680 | |
Thomas Martitz | b673ae2 | 2010-10-31 11:11:46 +0000 | [diff] [blame] | 681 | if (action != ACTION_TOUCHSCREEN) |
| 682 | { |
| 683 | if (global_settings.list_accel_start_delay) |
Jonathan Gordon | 42698e4 | 2007-05-27 15:08:56 +0000 | [diff] [blame] | 684 | { |
Andree Buschmann | 04bd51f | 2011-03-22 21:29:05 +0000 | [diff] [blame] | 685 | int start_delay = global_settings.list_accel_start_delay * HZ; |
| 686 | int accel_wait = global_settings.list_accel_wait * HZ; |
Thomas Martitz | b673ae2 | 2010-10-31 11:11:46 +0000 | [diff] [blame] | 687 | |
| 688 | if (get_action_statuscode(NULL)&ACTION_REPEAT) |
Jonathan Gordon | 42698e4 | 2007-05-27 15:08:56 +0000 | [diff] [blame] | 689 | { |
Thomas Martitz | b673ae2 | 2010-10-31 11:11:46 +0000 | [diff] [blame] | 690 | if (!last_accel_tick) |
| 691 | last_accel_tick = current_tick + start_delay; |
| 692 | else if (TIME_AFTER(current_tick, last_accel_tick + accel_wait)) |
| 693 | { |
| 694 | last_accel_tick = current_tick; |
| 695 | next_item_modifier++; |
| 696 | } |
Jonathan Gordon | 42698e4 | 2007-05-27 15:08:56 +0000 | [diff] [blame] | 697 | } |
Thomas Martitz | b673ae2 | 2010-10-31 11:11:46 +0000 | [diff] [blame] | 698 | else if (last_accel_tick) |
| 699 | { |
| 700 | next_item_modifier = 1; |
| 701 | last_accel_tick = 0; |
| 702 | } |
Jonathan Gordon | 42698e4 | 2007-05-27 15:08:56 +0000 | [diff] [blame] | 703 | } |
| 704 | } |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 705 | #endif |
Maurus Cuelenaere | 1392dc2 | 2008-08-23 09:46:38 +0000 | [diff] [blame] | 706 | #if defined(HAVE_TOUCHSCREEN) |
| 707 | if (action == ACTION_TOUCHSCREEN) |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 708 | action = *actionptr = gui_synclist_do_touchscreen(lists); |
Thomas Martitz | b673ae2 | 2010-10-31 11:11:46 +0000 | [diff] [blame] | 709 | else if (action > ACTION_TOUCHSCREEN_MODE) |
| 710 | /* cancel kinetic if we got a normal button event */ |
| 711 | _gui_synclist_stop_kinetic_scrolling(); |
Jonathan Gordon | fa13cbe | 2007-10-22 12:26:53 +0000 | [diff] [blame] | 712 | #endif |
Martin Scarratt | 1ab1f02 | 2006-09-25 10:56:38 +0000 | [diff] [blame] | 713 | |
Jonathan Gordon | 94139ac | 2012-03-20 21:27:33 +1100 | [diff] [blame] | 714 | /* Disable the skin redraw callback */ |
| 715 | current_lists = NULL; |
| 716 | |
Jonathan Gordon | 6a1161b | 2006-11-06 10:11:51 +0000 | [diff] [blame] | 717 | switch (wrap) |
| 718 | { |
| 719 | case LIST_WRAP_ON: |
| 720 | gui_synclist_limit_scroll(lists, false); |
| 721 | break; |
| 722 | case LIST_WRAP_OFF: |
| 723 | gui_synclist_limit_scroll(lists, true); |
| 724 | break; |
| 725 | case LIST_WRAP_UNLESS_HELD: |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 726 | if (action == ACTION_STD_PREVREPEAT || |
| 727 | action == ACTION_STD_NEXTREPEAT || |
| 728 | action == ACTION_LISTTREE_PGUP || |
| 729 | action == ACTION_LISTTREE_PGDOWN) |
Jonathan Gordon | 6a1161b | 2006-11-06 10:11:51 +0000 | [diff] [blame] | 730 | gui_synclist_limit_scroll(lists, true); |
| 731 | else gui_synclist_limit_scroll(lists, false); |
| 732 | break; |
| 733 | }; |
Miika Pekkarinen | 2eefb5a | 2007-03-11 10:52:36 +0000 | [diff] [blame] | 734 | |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 735 | switch (action) |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 736 | { |
Jonathan Gordon | fa13cbe | 2007-10-22 12:26:53 +0000 | [diff] [blame] | 737 | case ACTION_REDRAW: |
| 738 | gui_synclist_draw(lists); |
| 739 | return true; |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 740 | |
Jonathan Gordon | a053e58 | 2007-04-08 01:33:01 +0000 | [diff] [blame] | 741 | #ifdef HAVE_VOLUME_IN_LIST |
| 742 | case ACTION_LIST_VOLUP: |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 743 | global_settings.volume += 2; |
Jonathan Gordon | a053e58 | 2007-04-08 01:33:01 +0000 | [diff] [blame] | 744 | /* up two because the falthrough brings it down one */ |
| 745 | case ACTION_LIST_VOLDOWN: |
| 746 | global_settings.volume--; |
Nils Wallménius | f46657e | 2007-05-30 17:57:32 +0000 | [diff] [blame] | 747 | setvol(); |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 748 | return true; |
Jonathan Gordon | a053e58 | 2007-04-08 01:33:01 +0000 | [diff] [blame] | 749 | #endif |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 750 | case ACTION_STD_PREV: |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 751 | case ACTION_STD_PREVREPEAT: |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 752 | gui_list_select_at_offset(lists, -next_item_modifier); |
Thomas Martitz | fd14cac | 2009-03-02 19:25:50 +0000 | [diff] [blame] | 753 | #ifndef HAVE_WHEEL_ACCELERATION |
Bertrik Sikken | 9244259 | 2008-05-20 19:41:48 +0000 | [diff] [blame] | 754 | if (button_queue_count() < FRAMEDROP_TRIGGER) |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 755 | #endif |
Miika Pekkarinen | 2eefb5a | 2007-03-11 10:52:36 +0000 | [diff] [blame] | 756 | gui_synclist_draw(lists); |
Jens Arnold | 237d3c4 | 2006-02-19 13:34:12 +0000 | [diff] [blame] | 757 | yield(); |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 758 | *actionptr = ACTION_STD_PREV; |
| 759 | return true; |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 760 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 761 | case ACTION_STD_NEXT: |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 762 | case ACTION_STD_NEXTREPEAT: |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 763 | gui_list_select_at_offset(lists, next_item_modifier); |
Thomas Martitz | fd14cac | 2009-03-02 19:25:50 +0000 | [diff] [blame] | 764 | #ifndef HAVE_WHEEL_ACCELERATION |
Bertrik Sikken | 9244259 | 2008-05-20 19:41:48 +0000 | [diff] [blame] | 765 | if (button_queue_count() < FRAMEDROP_TRIGGER) |
Michael Sevakis | 873e0fd | 2007-07-22 21:02:24 +0000 | [diff] [blame] | 766 | #endif |
Miika Pekkarinen | 2eefb5a | 2007-03-11 10:52:36 +0000 | [diff] [blame] | 767 | gui_synclist_draw(lists); |
Jens Arnold | 237d3c4 | 2006-02-19 13:34:12 +0000 | [diff] [blame] | 768 | yield(); |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 769 | *actionptr = ACTION_STD_NEXT; |
| 770 | return true; |
Brandon Low | d3a03b6 | 2006-01-22 04:24:26 +0000 | [diff] [blame] | 771 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 772 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | ffeccda | 2007-07-25 12:37:09 +0000 | [diff] [blame] | 773 | case ACTION_TREE_PGRIGHT: |
| 774 | gui_synclist_scroll_right(lists); |
| 775 | gui_synclist_draw(lists); |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 776 | return true; |
Martin Scarratt | 1ab1f02 | 2006-09-25 10:56:38 +0000 | [diff] [blame] | 777 | case ACTION_TREE_ROOT_INIT: |
Peter D'Hoye | 552ac5a | 2006-12-09 10:02:09 +0000 | [diff] [blame] | 778 | /* After this button press ACTION_TREE_PGLEFT is allowed |
| 779 | to skip to root. ACTION_TREE_ROOT_INIT must be defined in the |
| 780 | keymaps as a repeated button press (the same as the repeated |
| 781 | ACTION_TREE_PGLEFT) with the pre condition being the non-repeated |
Sebastian Leonhardt | a8758c9 | 2015-10-21 00:11:44 +0200 | [diff] [blame] | 782 | button press. Leave out ACTION_TREE_ROOT_INIT in your keymaps to |
| 783 | disable cancel action by PGLEFT key (e.g. if PGLEFT and CANCEL |
| 784 | are mapped to different keys) */ |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 785 | if (lists->offset_position[0] == 0) |
Martin Scarratt | 1ab1f02 | 2006-09-25 10:56:38 +0000 | [diff] [blame] | 786 | { |
Sebastian Leonhardt | a8758c9 | 2015-10-21 00:11:44 +0200 | [diff] [blame] | 787 | pgleft_allow_cancel = true; |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 788 | *actionptr = ACTION_STD_CANCEL; |
| 789 | return true; |
Martin Scarratt | 1ab1f02 | 2006-09-25 10:56:38 +0000 | [diff] [blame] | 790 | } |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 791 | *actionptr = ACTION_TREE_PGLEFT; |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 792 | case ACTION_TREE_PGLEFT: |
Sebastian Leonhardt | a8758c9 | 2015-10-21 00:11:44 +0200 | [diff] [blame] | 793 | if(pgleft_allow_cancel && (lists->offset_position[0] == 0)) |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 794 | { |
| 795 | *actionptr = ACTION_STD_CANCEL; |
| 796 | return false; |
| 797 | } |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 798 | gui_synclist_scroll_left(lists); |
| 799 | gui_synclist_draw(lists); |
Sebastian Leonhardt | a8758c9 | 2015-10-21 00:11:44 +0200 | [diff] [blame] | 800 | pgleft_allow_cancel = false; /* stop ACTION_TREE_PAGE_LEFT |
| 801 | skipping to root */ |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 802 | return true; |
Tomas Salfischberger | 7fa39df | 2006-01-22 01:42:05 +0000 | [diff] [blame] | 803 | #endif |
Peter D'Hoye | 552ac5a | 2006-12-09 10:02:09 +0000 | [diff] [blame] | 804 | /* for pgup / pgdown, we are obliged to have a different behaviour depending |
| 805 | * on the screen for which the user pressed the key since for example, remote |
| 806 | * and main screen doesn't have the same number of lines */ |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 807 | case ACTION_LISTTREE_PGUP: |
Jonathan Gordon | ca701bf | 2007-03-04 07:45:12 +0000 | [diff] [blame] | 808 | { |
| 809 | int screen = |
Jonathan Gordon | 5ea43ce | 2007-03-04 08:35:20 +0000 | [diff] [blame] | 810 | #ifdef HAVE_REMOTE_LCD |
Jonathan Gordon | ca701bf | 2007-03-04 07:45:12 +0000 | [diff] [blame] | 811 | get_action_statuscode(NULL)&ACTION_REMOTE ? |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 812 | SCREEN_REMOTE : |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 813 | #endif |
Jonathan Gordon | ca701bf | 2007-03-04 07:45:12 +0000 | [diff] [blame] | 814 | SCREEN_MAIN; |
| 815 | gui_synclist_select_previous_page(lists, screen); |
| 816 | gui_synclist_draw(lists); |
| 817 | yield(); |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 818 | *actionptr = ACTION_STD_NEXT; |
Jonathan Gordon | ca701bf | 2007-03-04 07:45:12 +0000 | [diff] [blame] | 819 | } |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 820 | return true; |
Jonathan Gordon | ca701bf | 2007-03-04 07:45:12 +0000 | [diff] [blame] | 821 | |
| 822 | case ACTION_LISTTREE_PGDOWN: |
| 823 | { |
| 824 | int screen = |
Jonathan Gordon | 5ea43ce | 2007-03-04 08:35:20 +0000 | [diff] [blame] | 825 | #ifdef HAVE_REMOTE_LCD |
Jonathan Gordon | ca701bf | 2007-03-04 07:45:12 +0000 | [diff] [blame] | 826 | get_action_statuscode(NULL)&ACTION_REMOTE ? |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 827 | SCREEN_REMOTE : |
Jonathan Gordon | ca701bf | 2007-03-04 07:45:12 +0000 | [diff] [blame] | 828 | #endif |
| 829 | SCREEN_MAIN; |
| 830 | gui_synclist_select_next_page(lists, screen); |
| 831 | gui_synclist_draw(lists); |
| 832 | yield(); |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 833 | *actionptr = ACTION_STD_PREV; |
Jonathan Gordon | ca701bf | 2007-03-04 07:45:12 +0000 | [diff] [blame] | 834 | } |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 835 | return true; |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 836 | } |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 837 | if(lists->scheduled_talk_tick |
| 838 | && TIME_AFTER(current_tick, lists->scheduled_talk_tick)) |
Stéphane Doyon | 8486c04 | 2007-10-21 00:20:10 +0000 | [diff] [blame] | 839 | /* scheduled postponed item announcement is due */ |
Steve Bavin | dddd157 | 2010-06-15 07:08:35 +0000 | [diff] [blame] | 840 | _gui_synclist_speak_item(lists); |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 841 | return false; |
Linus Nielsen Feltzing | 7da9477 | 2005-10-28 00:00:00 +0000 | [diff] [blame] | 842 | } |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 843 | |
Stéphane Doyon | 8486c04 | 2007-10-21 00:20:10 +0000 | [diff] [blame] | 844 | int list_do_action_timeout(struct gui_synclist *lists, int timeout) |
| 845 | /* Returns the lowest of timeout or the delay until a postponed |
| 846 | scheduled announcement is due (if any). */ |
| 847 | { |
Jonathan Gordon | 94139ac | 2012-03-20 21:27:33 +1100 | [diff] [blame] | 848 | if (lists != current_lists) |
| 849 | { |
| 850 | if (!ui_update_event_registered) |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 851 | ui_update_event_registered = |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 852 | add_event(GUI_EVENT_NEED_UI_UPDATE, _lists_uiviewport_update_callback); |
Jonathan Gordon | 94139ac | 2012-03-20 21:27:33 +1100 | [diff] [blame] | 853 | current_lists = lists; |
| 854 | } |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 855 | if(lists->scheduled_talk_tick) |
Stéphane Doyon | 8486c04 | 2007-10-21 00:20:10 +0000 | [diff] [blame] | 856 | { |
Jonathan Gordon | f5ec3e4 | 2007-12-17 02:37:21 +0000 | [diff] [blame] | 857 | long delay = lists->scheduled_talk_tick -current_tick +1; |
Stéphane Doyon | 8486c04 | 2007-10-21 00:20:10 +0000 | [diff] [blame] | 858 | /* +1 because the trigger condition uses TIME_AFTER(), which |
| 859 | is implemented as strictly greater than. */ |
| 860 | if(delay < 0) |
| 861 | delay = 0; |
| 862 | if(timeout > delay || timeout == TIMEOUT_BLOCK) |
| 863 | timeout = delay; |
| 864 | } |
| 865 | return timeout; |
| 866 | } |
| 867 | |
| 868 | bool list_do_action(int context, int timeout, |
| 869 | struct gui_synclist *lists, int *action, |
| 870 | enum list_wrap wrap) |
| 871 | /* Combines the get_action() (with possibly overridden timeout) and |
| 872 | gui_synclist_do_button() calls. Returns the list action from |
| 873 | do_button, and places the action from get_action in *action. */ |
| 874 | { |
| 875 | timeout = list_do_action_timeout(lists, timeout); |
Jonathan Gordon | eb2ea7f | 2012-01-12 22:28:36 +1100 | [diff] [blame] | 876 | #if CONFIG_CODEC == SWCODEC |
| 877 | keyclick_set_callback(gui_synclist_keyclick_callback, lists); |
| 878 | #endif |
Stéphane Doyon | 8486c04 | 2007-10-21 00:20:10 +0000 | [diff] [blame] | 879 | *action = get_action(context, timeout); |
| 880 | return gui_synclist_do_button(lists, action, wrap); |
| 881 | } |
| 882 | |
Solomon Peachy | 4beafe1 | 2019-02-08 19:59:57 -0500 | [diff] [blame^] | 883 | bool gui_synclist_item_is_onscreen(struct gui_synclist *lists, |
| 884 | enum screen_type screen, int item) |
| 885 | { |
| 886 | int nb_lines = list_get_nb_lines(lists, screen); |
| 887 | return (unsigned)(item - lists->start_item[screen]) < (unsigned) nb_lines; |
| 888 | } |
| 889 | |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 890 | /* Simple use list implementation */ |
Jonathan Gordon | 69228f9 | 2013-02-12 20:35:11 +1100 | [diff] [blame] | 891 | static int simplelist_line_count = 0, simplelist_line_remaining; |
| 892 | static int simplelist_line_pos; |
| 893 | static char simplelist_buffer[SIMPLELIST_MAX_LINES * SIMPLELIST_MAX_LINELENGTH]; |
| 894 | static char *simplelist_text[SIMPLELIST_MAX_LINES]; |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 895 | /* set the amount of lines shown in the list */ |
| 896 | void simplelist_set_line_count(int lines) |
| 897 | { |
Jonathan Gordon | 69228f9 | 2013-02-12 20:35:11 +1100 | [diff] [blame] | 898 | if (lines <= 0) { |
| 899 | simplelist_line_pos = 0; |
| 900 | simplelist_line_remaining = sizeof(simplelist_buffer); |
Jonathan Gordon | fa64dbb | 2008-04-21 13:32:10 +0000 | [diff] [blame] | 901 | simplelist_line_count = 0; |
Jonathan Gordon | 69228f9 | 2013-02-12 20:35:11 +1100 | [diff] [blame] | 902 | } |
Jonathan Gordon | 83d3f1d | 2013-03-27 22:43:40 +1100 | [diff] [blame] | 903 | else if (lines < simplelist_line_count) { |
| 904 | char *end = simplelist_text[lines]; |
| 905 | simplelist_line_pos = end - simplelist_buffer; |
| 906 | simplelist_line_remaining = sizeof(simplelist_buffer) - simplelist_line_pos; |
| 907 | simplelist_line_count = lines; |
| 908 | } |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 909 | } |
| 910 | /* get the current amount of lines shown */ |
| 911 | int simplelist_get_line_count(void) |
| 912 | { |
| 913 | return simplelist_line_count; |
| 914 | } |
| 915 | /* add/edit a line in the list. |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 916 | if line_number > number of lines shown it adds the line, |
| 917 | else it edits the line */ |
Jonathan Gordon | 69228f9 | 2013-02-12 20:35:11 +1100 | [diff] [blame] | 918 | void simplelist_addline(const char *fmt, ...) |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 919 | { |
| 920 | va_list ap; |
Jonathan Gordon | 69228f9 | 2013-02-12 20:35:11 +1100 | [diff] [blame] | 921 | size_t len = simplelist_line_remaining; |
| 922 | int line_number = simplelist_line_count++; |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 923 | |
Jonathan Gordon | 69228f9 | 2013-02-12 20:35:11 +1100 | [diff] [blame] | 924 | simplelist_text[line_number] = &simplelist_buffer[simplelist_line_pos]; |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 925 | va_start(ap, fmt); |
Jonathan Gordon | 69228f9 | 2013-02-12 20:35:11 +1100 | [diff] [blame] | 926 | len = vsnprintf(simplelist_text[line_number], simplelist_line_remaining, fmt, ap); |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 927 | va_end(ap); |
Jonathan Gordon | 69228f9 | 2013-02-12 20:35:11 +1100 | [diff] [blame] | 928 | len++; |
| 929 | simplelist_line_remaining -= len; |
| 930 | simplelist_line_pos += len; |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 931 | } |
| 932 | |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 933 | static const char* simplelist_static_getname(int item, |
| 934 | void * data, |
| 935 | char *buffer, |
| 936 | size_t buffer_len) |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 937 | { |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 938 | (void)data; (void)buffer; (void)buffer_len; |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 939 | return simplelist_text[item]; |
| 940 | } |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 941 | |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 942 | bool simplelist_show_list(struct simplelist_info *info) |
| 943 | { |
| 944 | struct gui_synclist lists; |
Björn Stenberg | 0942e2a | 2011-10-15 19:35:02 +0000 | [diff] [blame] | 945 | int action, old_line_count = simplelist_line_count; |
Alexander Levin | 4702770 | 2010-04-10 21:11:19 +0000 | [diff] [blame] | 946 | list_get_name *getname; |
Jonathan Gordon | 8703cca | 2008-10-12 10:21:44 +0000 | [diff] [blame] | 947 | int wrap = LIST_WRAP_UNLESS_HELD; |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 948 | if (info->get_name) |
| 949 | getname = info->get_name; |
| 950 | else |
| 951 | getname = simplelist_static_getname; |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 952 | |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 953 | FOR_NB_SCREENS(i) |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 954 | viewportmanager_theme_enable(i, true, NULL); |
| 955 | |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 956 | gui_synclist_init(&lists, getname, info->callback_data, |
Jonathan Gordon | f9329e4 | 2009-01-07 07:52:32 +0000 | [diff] [blame] | 957 | info->scroll_all, info->selection_size, NULL); |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 958 | |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 959 | if (info->title) |
Jonathan Gordon | 573f220 | 2011-09-03 13:24:56 +0000 | [diff] [blame] | 960 | gui_synclist_set_title(&lists, info->title, info->title_icon); |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 961 | if (info->get_icon) |
| 962 | gui_synclist_set_icon_callback(&lists, info->get_icon); |
Jonathan Gordon | 5eac010 | 2007-10-21 01:27:17 +0000 | [diff] [blame] | 963 | if (info->get_talk) |
| 964 | gui_synclist_set_voice_callback(&lists, info->get_talk); |
Jonathan Gordon | 573f220 | 2011-09-03 13:24:56 +0000 | [diff] [blame] | 965 | #ifdef HAVE_LCD_COLOR |
| 966 | if (info->get_color) |
| 967 | gui_synclist_set_color_callback(&lists, info->get_color); |
| 968 | #endif |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 969 | |
Jonathan Gordon | 8703cca | 2008-10-12 10:21:44 +0000 | [diff] [blame] | 970 | if (info->hide_selection) |
| 971 | { |
| 972 | gui_synclist_hide_selection_marker(&lists, true); |
| 973 | wrap = LIST_WRAP_OFF; |
| 974 | } |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 975 | |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 976 | if (info->action_callback) |
| 977 | info->action_callback(ACTION_REDRAW, &lists); |
| 978 | |
| 979 | if (info->get_name == NULL) |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 980 | gui_synclist_set_nb_items(&lists, |
| 981 | simplelist_line_count*info->selection_size); |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 982 | else |
| 983 | gui_synclist_set_nb_items(&lists, info->count*info->selection_size); |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 984 | |
Jonathan Gordon | 67df5f2 | 2008-09-25 07:56:34 +0000 | [diff] [blame] | 985 | gui_synclist_select_item(&lists, info->selection); |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 986 | |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 987 | gui_synclist_draw(&lists); |
Stéphane Doyon | a82a860 | 2007-10-23 05:19:03 +0000 | [diff] [blame] | 988 | gui_synclist_speak_item(&lists); |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 989 | |
| 990 | while(1) |
| 991 | { |
Teruaki Kawashima | 2d86417 | 2010-10-07 12:27:26 +0000 | [diff] [blame] | 992 | list_do_action(CONTEXT_LIST, info->timeout, |
Jonathan Gordon | 8703cca | 2008-10-12 10:21:44 +0000 | [diff] [blame] | 993 | &lists, &action, wrap); |
Michael Sevakis | d6af287 | 2007-10-26 23:11:18 +0000 | [diff] [blame] | 994 | |
| 995 | /* We must yield in this case or no other thread can run */ |
Steve Bavin | ab78464 | 2007-10-26 18:04:42 +0000 | [diff] [blame] | 996 | if (info->timeout == TIMEOUT_NOBLOCK) |
Michael Sevakis | d6af287 | 2007-10-26 23:11:18 +0000 | [diff] [blame] | 997 | yield(); |
| 998 | |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 999 | if (info->action_callback) |
| 1000 | { |
Jonathan Gordon | 2438d78 | 2008-09-25 08:12:25 +0000 | [diff] [blame] | 1001 | bool stdok = action==ACTION_STD_OK; |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 1002 | action = info->action_callback(action, &lists); |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 1003 | if (stdok && action == ACTION_STD_CANCEL) |
Jonathan Gordon | 2438d78 | 2008-09-25 08:12:25 +0000 | [diff] [blame] | 1004 | { |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 1005 | /* callback asked us to exit */ |
Jonathan Gordon | 2438d78 | 2008-09-25 08:12:25 +0000 | [diff] [blame] | 1006 | info->selection = gui_synclist_get_sel_pos(&lists); |
| 1007 | break; |
| 1008 | } |
Teruaki Kawashima | 478afc3 | 2009-10-27 13:18:54 +0000 | [diff] [blame] | 1009 | |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 1010 | if (info->get_name == NULL) |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 1011 | gui_synclist_set_nb_items(&lists, |
| 1012 | simplelist_line_count*info->selection_size); |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 1013 | } |
| 1014 | if (action == ACTION_STD_CANCEL) |
Jonathan Gordon | 2438d78 | 2008-09-25 08:12:25 +0000 | [diff] [blame] | 1015 | { |
| 1016 | info->selection = -1; |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 1017 | break; |
Jonathan Gordon | 2438d78 | 2008-09-25 08:12:25 +0000 | [diff] [blame] | 1018 | } |
Jens Arnold | bf9ae1f | 2008-02-25 07:41:30 +0000 | [diff] [blame] | 1019 | else if ((action == ACTION_REDRAW) || |
Thomas Martitz | 6e6f0c6 | 2012-03-22 20:59:01 +0100 | [diff] [blame] | 1020 | (list_is_dirty(&lists)) || |
Jonathan Gordon | e247230 | 2007-11-04 01:04:10 +0000 | [diff] [blame] | 1021 | (old_line_count != simplelist_line_count)) |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 1022 | { |
| 1023 | if (info->get_name == NULL) |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 1024 | { |
| 1025 | gui_synclist_set_nb_items(&lists, |
| 1026 | simplelist_line_count*info->selection_size); |
| 1027 | } |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 1028 | gui_synclist_draw(&lists); |
Miika Pekkarinen | caff835 | 2007-10-21 11:06:30 +0000 | [diff] [blame] | 1029 | old_line_count = simplelist_line_count; |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 1030 | } |
| 1031 | else if(default_event_handler(action) == SYS_USB_CONNECTED) |
| 1032 | return true; |
| 1033 | } |
Stéphane Doyon | a82a860 | 2007-10-23 05:19:03 +0000 | [diff] [blame] | 1034 | talk_shutup(); |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 1035 | FOR_NB_SCREENS(i) |
Teruaki Kawashima | 67470c8 | 2010-01-07 12:51:57 +0000 | [diff] [blame] | 1036 | viewportmanager_theme_undo(i, false); |
Jonathan Gordon | 5f893be | 2007-10-20 12:32:55 +0000 | [diff] [blame] | 1037 | return false; |
| 1038 | } |
| 1039 | |
Jonathan Gordon | 5eac010 | 2007-10-21 01:27:17 +0000 | [diff] [blame] | 1040 | void simplelist_info_init(struct simplelist_info *info, char* title, |
Jonathan Gordon | 616971c | 2007-10-21 06:42:52 +0000 | [diff] [blame] | 1041 | int count, void* data) |
Jonathan Gordon | 5eac010 | 2007-10-21 01:27:17 +0000 | [diff] [blame] | 1042 | { |
| 1043 | info->title = title; |
| 1044 | info->count = count; |
Jonathan Gordon | 616971c | 2007-10-21 06:42:52 +0000 | [diff] [blame] | 1045 | info->selection_size = 1; |
Jonathan Gordon | 5eac010 | 2007-10-21 01:27:17 +0000 | [diff] [blame] | 1046 | info->hide_selection = false; |
| 1047 | info->scroll_all = false; |
Jonathan Gordon | 0465101 | 2007-10-21 13:47:43 +0000 | [diff] [blame] | 1048 | info->timeout = HZ/10; |
Jonathan Gordon | 67df5f2 | 2008-09-25 07:56:34 +0000 | [diff] [blame] | 1049 | info->selection = 0; |
Jonathan Gordon | 5eac010 | 2007-10-21 01:27:17 +0000 | [diff] [blame] | 1050 | info->action_callback = NULL; |
Jonathan Gordon | 573f220 | 2011-09-03 13:24:56 +0000 | [diff] [blame] | 1051 | info->title_icon = Icon_NOICON; |
Jonathan Gordon | 5eac010 | 2007-10-21 01:27:17 +0000 | [diff] [blame] | 1052 | info->get_icon = NULL; |
| 1053 | info->get_name = NULL; |
| 1054 | info->get_talk = NULL; |
Jonathan Gordon | 573f220 | 2011-09-03 13:24:56 +0000 | [diff] [blame] | 1055 | #ifdef HAVE_LCD_COLOR |
| 1056 | info->get_color = NULL; |
| 1057 | #endif |
Jonathan Gordon | 5eac010 | 2007-10-21 01:27:17 +0000 | [diff] [blame] | 1058 | info->callback_data = data; |
Alexander Levin | f232519 | 2010-04-10 20:25:23 +0000 | [diff] [blame] | 1059 | simplelist_line_count = 0; |
Jonathan Gordon | 5eac010 | 2007-10-21 01:27:17 +0000 | [diff] [blame] | 1060 | } |