blob: 1be9da496ab1b60300bae9038ec2276299d7ba60 [file] [log] [blame]
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
Kevin Ferrarea3ed62b2005-10-30 01:24:35 +000010 * Copyright (C) 2005 by Kevin Ferrare
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +000011 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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 Feltzing7da94772005-10-28 00:00:00 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _GUI_LIST_H_
23#define _GUI_LIST_H_
24
25#include "config.h"
26#include "icon.h"
27#include "screen_access.h"
Jonathan Gordon9b6ac012011-09-06 13:49:41 +000028#include "skin_engine/skin_engine.h"
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +000029
Maurus Cuelenaere567d83e2009-08-17 22:41:22 +000030#define SCROLLBAR_WIDTH global_settings.scrollbar_width
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +000031
Jonathan Gordon6a1161b2006-11-06 10:11:51 +000032enum list_wrap {
33 LIST_WRAP_ON = 0,
34 LIST_WRAP_OFF,
35 LIST_WRAP_UNLESS_HELD,
36};
37
Kevin Ferraree75cbdd2005-10-29 02:33:19 +000038/*
39 * The gui_list is based on callback functions, if you want the list
40 * to display something you have to provide it a function that
41 * tells it what to display.
Brandon Low74cbb0a2007-06-17 21:16:34 +000042 * There are three callback function :
43 * one to get the text, one to get the icon and one to get the color
Kevin Ferrare8517ed82005-11-16 02:12:25 +000044 */
45
46/*
47 * Icon callback
48 * - selected_item : an integer that tells the number of the item to display
Brandon Low74cbb0a2007-06-17 21:16:34 +000049 * - data : a void pointer to the data you gave to the list when you
50 * initialized it
51 * Returns a pointer to the icon, the value inside it is used to display the
52 * icon after the function returns.
Kevin Ferrare8517ed82005-11-16 02:12:25 +000053 * Note : we use the ICON type because the real type depends of the plateform
54 */
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +000055typedef enum themable_icons list_get_icon(int selected_item, void * data);
Kevin Ferrare8517ed82005-11-16 02:12:25 +000056/*
Kevin Ferraree75cbdd2005-10-29 02:33:19 +000057 * Text callback
58 * - selected_item : an integer that tells the number of the item to display
Brandon Low74cbb0a2007-06-17 21:16:34 +000059 * - data : a void pointer to the data you gave to the list when you
60 * initialized it
Kevin Ferraree75cbdd2005-10-29 02:33:19 +000061 * - buffer : a buffer to put the resulting text on it
62 * (The content of the buffer may not be used by the list, we use
63 * the return value of the function in all cases to avoid filling
64 * a buffer when it's not necessary)
Nils Wallménius68489612008-04-09 15:25:17 +000065 * - buffer_len : length of the buffer
Kevin Ferraree75cbdd2005-10-29 02:33:19 +000066 * Returns a pointer to a string that contains the text to display
Kevin Ferraree75cbdd2005-10-29 02:33:19 +000067 */
Nils Wallménius3200d042009-08-20 16:47:44 +000068typedef const char * list_get_name(int selected_item, void * data,
69 char * buffer, size_t buffer_len);
Stéphane Doyon8486c042007-10-21 00:20:10 +000070/*
71 * Voice callback
72 * - selected_item : an integer that tells the number of the item to speak
73 * - data : a void pointer to the data you gave to the list when you
74 * initialized it
75 * Returns an integer, 0 means success, ignored really...
76 */
77typedef int list_speak_item(int selected_item, void * data);
Brandon Low74cbb0a2007-06-17 21:16:34 +000078#ifdef HAVE_LCD_COLOR
79/*
80 * Color callback
81 * - selected_item : an integer that tells the number of the item to display
82 * - data : a void pointer to the data you gave to the list when you
83 * initialized it
84 * Returns an int with the lower 16 bits representing the color to display the
85 * selected item, negative value for default coloring.
86 */
87typedef int list_get_color(int selected_item, void * data);
88#endif
Kevin Ferrare8517ed82005-11-16 02:12:25 +000089
Jonathan Gordonf5ec3e42007-12-17 02:37:21 +000090struct gui_synclist
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +000091{
Kevin Ferrared452d262005-10-28 23:52:49 +000092 /* defines wether the list should stop when reaching the top/bottom
93 * or should continue (by going to bottom/top) */
94 bool limit_scroll;
Kevin Ferraref77ac7a2006-07-02 12:28:27 +000095 /* wether the text of the whole items of the list have to be
96 * scrolled or only for the selected item */
97 bool scroll_all;
Jens Arnoldc05ee022007-04-12 23:53:17 +000098 int nb_items;
99 int selected_item;
Jonathan Gordonf5ec3e42007-12-17 02:37:21 +0000100 int start_item[NB_SCREENS]; /* the item that is displayed at the top of the screen */
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000101 /* the number of lines that are selected at the same time */
102 int selected_size;
Thomas Martitzeec89a92013-12-20 23:34:28 +0100103 /* the number of pixels each line occupies (including optional padding on touchscreen */
104 int line_height[NB_SCREENS];
Jens Arnoldc05ee022007-04-12 23:53:17 +0000105#ifdef HAVE_LCD_BITMAP
Jonathan Gordonf5ec3e42007-12-17 02:37:21 +0000106 int offset_position[NB_SCREENS]; /* the list's screen scroll placement in pixels */
Jens Arnoldc05ee022007-04-12 23:53:17 +0000107#endif
Thomas Martitz0acdc872011-10-07 17:22:49 +0000108 long scheduled_talk_tick, last_talked_tick, dirty_tick;
Jens Arnoldc05ee022007-04-12 23:53:17 +0000109
110 list_get_icon *callback_get_item_icon;
111 list_get_name *callback_get_item_name;
Stéphane Doyon8486c042007-10-21 00:20:10 +0000112 list_speak_item *callback_speak_item;
Jens Arnoldc05ee022007-04-12 23:53:17 +0000113
Jens Arnoldc05ee022007-04-12 23:53:17 +0000114 /* The data that will be passed to the callback function YOU implement */
115 void * data;
116 /* The optional title, set to NULL for none */
Nils Wallménius8e33c2f2009-10-11 09:40:47 +0000117 char * title;
Mark Arigo34301bb2006-08-23 20:02:06 +0000118 /* Optional title icon */
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000119 enum themable_icons title_icon;
Jonathan Gordon38234862007-06-07 12:14:31 +0000120 bool show_selection_marker; /* set to true by default */
Brandon Low74cbb0a2007-06-17 21:16:34 +0000121
122#ifdef HAVE_LCD_COLOR
123 int title_color;
124 list_get_color *callback_get_item_color;
125#endif
Jonathan Gordon0e5cec22008-03-05 09:58:30 +0000126 struct viewport *parent[NB_SCREENS];
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000127};
128
Kevin Ferraredb8415c2005-10-30 22:34:51 +0000129
Brandon Lowd3a03b62006-01-22 04:24:26 +0000130#ifdef HAVE_LCD_BITMAP
Thomas Martitz2eb1cb62009-09-07 17:37:06 +0000131extern void list_init(void);
Brandon Lowd3a03b62006-01-22 04:24:26 +0000132/* parse global setting to static int */
133extern void gui_list_screen_scroll_step(int ofs);
134
135/* parse global setting to static bool */
136extern void gui_list_screen_scroll_out_of_view(bool enable);
137#endif /* HAVE_LCD_BITMAP */
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000138
Kevin Ferraree75cbdd2005-10-29 02:33:19 +0000139extern void gui_synclist_init(
140 struct gui_synclist * lists,
Kevin Ferrare8517ed82005-11-16 02:12:25 +0000141 list_get_name callback_get_item_name,
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000142 void * data,
143 bool scroll_all,
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000144 int selected_size,
145 struct viewport parent[NB_SCREENS] /* NOTE: new screens should NOT set this to NULL */
Kevin Ferraree75cbdd2005-10-29 02:33:19 +0000146 );
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000147extern void gui_synclist_set_nb_items(struct gui_synclist * lists, int nb_items);
Kevin Ferrare15046f92005-11-16 17:23:49 +0000148extern void gui_synclist_set_icon_callback(struct gui_synclist * lists, list_get_icon icon_callback);
Stéphane Doyon8486c042007-10-21 00:20:10 +0000149extern void gui_synclist_set_voice_callback(struct gui_synclist * lists, list_speak_item voice_callback);
Thomas Martitz5c509d12011-10-22 10:09:23 +0000150extern void gui_synclist_set_viewport_defaults(struct viewport *vp, enum screen_type screen);
Jonathan Gordon0e5cec22008-03-05 09:58:30 +0000151#ifdef HAVE_LCD_COLOR
152extern void gui_synclist_set_color_callback(struct gui_synclist * lists, list_get_color color_callback);
153#endif
Stéphane Doyon8486c042007-10-21 00:20:10 +0000154extern void gui_synclist_speak_item(struct gui_synclist * lists);
Hristo Kovachev38deb8f2006-04-03 08:51:08 +0000155extern int gui_synclist_get_nb_items(struct gui_synclist * lists);
Kevin Ferrare15046f92005-11-16 17:23:49 +0000156
Kevin Ferrared452d262005-10-28 23:52:49 +0000157extern int gui_synclist_get_sel_pos(struct gui_synclist * lists);
Kevin Ferraree75cbdd2005-10-29 02:33:19 +0000158
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000159extern void gui_synclist_draw(struct gui_synclist * lists);
Teruaki Kawashima93f9e7c2010-02-11 10:41:06 +0000160extern void gui_synclist_scroll_stop(struct gui_synclist *lists);
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000161extern void gui_synclist_select_item(struct gui_synclist * lists,
162 int item_number);
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000163extern void gui_synclist_add_item(struct gui_synclist * lists);
164extern void gui_synclist_del_item(struct gui_synclist * lists);
Kevin Ferrared452d262005-10-28 23:52:49 +0000165extern void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll);
Nils Wallménius8e33c2f2009-10-11 09:40:47 +0000166extern void gui_synclist_set_title(struct gui_synclist * lists, char * title,
Andrew Mahone1bc67c82009-07-11 00:22:26 +0000167 enum themable_icons icon);
Jonathan Gordon38234862007-06-07 12:14:31 +0000168extern void gui_synclist_hide_selection_marker(struct gui_synclist *lists,
169 bool hide);
Solomon Peachy4beafe12019-02-08 19:59:57 -0500170extern bool gui_synclist_item_is_onscreen(struct gui_synclist *lists,
171 enum screen_type screen, int item);
Jonathan Gordoneb2ea7f2012-01-12 22:28:36 +1100172
173#if CONFIG_CODEC == SWCODEC
174extern bool gui_synclist_keyclick_callback(int action, void* data);
175#endif
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000176/*
177 * Do the action implied by the given button,
Jonathan Gordoncf1cef52007-09-17 10:08:50 +0000178 * returns true if the action was handled.
179 * NOTE: *action may be changed regardless of return value
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000180 */
Jonathan Gordoncf1cef52007-09-17 10:08:50 +0000181extern bool gui_synclist_do_button(struct gui_synclist * lists,
Jonathan Gordone385ee12008-12-31 05:59:26 +0000182 int *action,
Jonathan Gordon6a1161b2006-11-06 10:11:51 +0000183 enum list_wrap);
Jonathan Gordon9b6ac012011-09-06 13:49:41 +0000184#if defined(HAVE_LCD_BITMAP) && !defined(PLUGIN)
185struct listitem_viewport_cfg {
186 struct wps_data *data;
Frank Gevaerts680c6fc2012-02-21 14:33:42 +0100187 OFFSETTYPE(char *) label;
Jonathan Gordon9b6ac012011-09-06 13:49:41 +0000188 int width;
189 int height;
190 int xmargin;
191 int ymargin;
192 bool tile;
193 struct skin_viewport selected_item_vp;
194};
Frank Gevaerts71511112012-06-13 23:07:49 +0200195
196bool skinlist_get_item(struct screen *display, struct gui_synclist *list, int x, int y, int *item);
Jonathan Gordon9b6ac012011-09-06 13:49:41 +0000197bool skinlist_draw(struct screen *display, struct gui_synclist *list);
198bool skinlist_is_selected_item(void);
199void skinlist_set_cfg(enum screen_type screen,
200 struct listitem_viewport_cfg *cfg);
Jonathan Gordon3d0317a2011-09-11 10:44:17 +0000201const char* skinlist_get_item_text(int offset, bool wrap, char* buf, size_t buf_size);
Frank Gevaerts28d5f2a2011-09-18 12:35:32 +0000202int skinlist_get_item_number(void);
Frank Gevaertsb5cd5ce2012-02-25 02:34:23 +0100203int skinlist_get_item_row(void);
204int skinlist_get_item_column(void);
Jonathan Gordon3d0317a2011-09-11 10:44:17 +0000205enum themable_icons skinlist_get_item_icon(int offset, bool wrap);
Jonathan Gordon9b6ac012011-09-06 13:49:41 +0000206bool skinlist_needs_scrollbar(enum screen_type screen);
207void skinlist_get_scrollbar(int* nb_item, int* first_shown, int* last_shown);
208int skinlist_get_line_count(enum screen_type screen, struct gui_synclist *list);
209#endif
Jonathan Gordon5eac0102007-10-21 01:27:17 +0000210
Bertrik Sikkend7678832009-08-06 09:28:25 +0000211#if defined(HAVE_TOUCHSCREEN)
212/* this needs to be fixed if we ever get more than 1 touchscreen on a target */
Thomas Martitzb673ae22010-10-31 11:11:46 +0000213extern unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list);
214/* only for private use in gui/list.c */
215extern void _gui_synclist_stop_kinetic_scrolling(void);
Bertrik Sikkend7678832009-08-06 09:28:25 +0000216#endif
217
Jonathan Gordon5eac0102007-10-21 01:27:17 +0000218/* If the list has a pending postponed scheduled announcement, that
219 may become due before the next get_action tmieout. This function
220 adjusts the get_action timeout appropriately. */
221extern int list_do_action_timeout(struct gui_synclist *lists, int timeout);
222/* This one combines a get_action call (with timeout overridden by
223 list_do_action_timeout) with the gui_synclist_do_button call, for
224 convenience. */
225extern bool list_do_action(int context, int timeout,
226 struct gui_synclist *lists, int *action,
227 enum list_wrap wrap);
228
229
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000230/** Simplelist implementation.
231 USe this if you dont need to reimplement the list code,
232 and just need to show a list
233 **/
234
235struct simplelist_info {
236 char *title; /* title to show on the list */
237 int count; /* number of items in the list, each item is selection_size high */
Bertrik Sikken44fa0252010-01-05 21:15:20 +0000238 int selection_size; /* list selection size, usually 1 */
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000239 bool hide_selection;
240 bool scroll_all;
Jonathan Gordon04651012007-10-21 13:47:43 +0000241 int timeout;
Jonathan Gordon67df5f22008-09-25 07:56:34 +0000242 int selection; /* the item to select when the list is first displayed */
243 /* when the list is exited, this will be set to the
Jonathan Gordon2438d782008-09-25 08:12:25 +0000244 index of the last item selected, or -1 if the list
245 was exited with ACTION_STD_CANCEL */
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000246 int (*action_callback)(int action, struct gui_synclist *lists); /* can be NULL */
247 /* action_callback notes:
248 action == the action pressed by the user
249 _after_ gui_synclist_do_button returns.
Jonathan Gordon573f2202011-09-03 13:24:56 +0000250 lists == the lists struct so the callback can get selection and count etc. */
251 enum themable_icons title_icon;
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000252 list_get_icon *get_icon; /* can be NULL */
253 list_get_name *get_name; /* NULL if you're using simplelist_addline() */
Jonathan Gordon5eac0102007-10-21 01:27:17 +0000254 list_speak_item *get_talk; /* can be NULL to not speak */
Jonathan Gordon573f2202011-09-03 13:24:56 +0000255#ifdef HAVE_LCD_COLOR
256 list_get_color *get_color;
257#endif
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000258 void *callback_data; /* data for callbacks */
259};
260
261#define SIMPLELIST_MAX_LINES 32
Cástor Muñozd20185a2014-12-09 19:38:47 +0100262#ifdef HAVE_ATA_SMART
263#define SIMPLELIST_MAX_LINELENGTH 48
264#else
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000265#define SIMPLELIST_MAX_LINELENGTH 32
Cástor Muñozd20185a2014-12-09 19:38:47 +0100266#endif
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000267
268/** The next three functions are used if the text is mostly static.
269 These should be called in the action callback for the list.
270 **/
271/* set the amount of lines shown in the list
272 Only needed if simplelist_info.get_name == NULL */
273void simplelist_set_line_count(int lines);
274/* get the current amount of lines shown */
275int simplelist_get_line_count(void);
Jonathan Gordon69228f92013-02-12 20:35:11 +1100276/* add a line in the list. */
277void simplelist_addline(const char *fmt, ...);
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000278
Jonathan Gordon5eac0102007-10-21 01:27:17 +0000279/* setup the info struct. members not setup in this function need to be assigned manually
280 members set in this function:
Jonathan Gordon616971c2007-10-21 06:42:52 +0000281 info.selection_size = 1;
Jonathan Gordon5eac0102007-10-21 01:27:17 +0000282 info.hide_selection = false;
283 info.scroll_all = false;
284 info.action_callback = NULL;
Jonathan Gordon573f2202011-09-03 13:24:56 +0000285 info.title_icon = Icon_NOICON;
Jonathan Gordon5eac0102007-10-21 01:27:17 +0000286 info.get_icon = NULL;
287 info.get_name = NULL;
288 info.get_voice = NULL;
Jonathan Gordon573f2202011-09-03 13:24:56 +0000289 info.get_color = NULL;
Jonathan Gordon04651012007-10-21 13:47:43 +0000290 info.timeout = HZ/10;
Jonathan Gordon67df5f22008-09-25 07:56:34 +0000291 info.selection = 0;
Jonathan Gordon5eac0102007-10-21 01:27:17 +0000292*/
293void simplelist_info_init(struct simplelist_info *info, char* title,
Jonathan Gordon616971c2007-10-21 06:42:52 +0000294 int count, void* data);
Teruaki Kawashimad50c78c2010-02-16 11:59:37 +0000295
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000296/* show a list.
297 if list->action_callback != NULL it is called with the action ACTION_REDRAW
298 before the list is dislplayed for the first time */
299bool simplelist_show_list(struct simplelist_info *info);
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000300
Linus Nielsen Feltzing7da94772005-10-28 00:00:00 +0000301#endif /* _GUI_LIST_H_ */