A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Kevin Ferrare
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _GUI_LIST_H_
23#define _GUI_LIST_H_
24
25#include "config.h"
26#include "icon.h"
27#include "screen_access.h"
28#include "skin_engine/skin_engine.h"
29#include "line.h"
30
31#define SCROLLBAR_WIDTH global_settings.scrollbar_width
32
33enum synclist_cursor
34{
35 SYNCLIST_CURSOR_NOSTYLE = 0,
36 SYNCLIST_CURSOR_INVERT,
37 SYNCLIST_CURSOR_COLOR,
38 SYNCLIST_CURSOR_GRADIENT,
39};
40
41/*
42 * The gui_list is based on callback functions, if you want the list
43 * to display something you have to provide it a function that
44 * tells it what to display.
45 * There are three callback function :
46 * one to get the text, one to get the icon and one to get the color
47 */
48
49/*
50 * Icon callback
51 * - selected_item : an integer that tells the number of the item to display
52 * - data : a void pointer to the data you gave to the list when you
53 * initialized it
54 * Returns a pointer to the icon, the value inside it is used to display the
55 * icon after the function returns.
56 * Note : we use the ICON type because the real type depends of the plateform
57 */
58typedef enum themable_icons list_get_icon(int selected_item, void * data);
59/*
60 * Text callback
61 * - selected_item : an integer that tells the number of the item to display
62 * - data : a void pointer to the data you gave to the list when you
63 * initialized it
64 * - buffer : a buffer to put the resulting text on it
65 * (The content of the buffer may not be used by the list, we use
66 * the return value of the function in all cases to avoid filling
67 * a buffer when it's not necessary)
68 * - buffer_len : length of the buffer
69 * Returns a pointer to a string that contains the text to display
70 */
71typedef const char * list_get_name(int selected_item, void * data,
72 char * buffer, size_t buffer_len);
73/*
74 * Draw callback
75 * - display : functions supplied depends on the screen call originated from (typ: MAIN)
76 * - list_info : a pointer to an internal struct containing item display information
77 */
78/* owner drawn lists need to know this info */
79struct list_putlineinfo_t {
80 int x;
81 int y;
82 int item_indent;
83 int item_offset;
84 int line;
85
86 int icon;
87 int icon_width;
88
89 struct screen *display;
90 struct viewport *vp;
91 struct line_desc *linedes;
92 struct gui_synclist * list;
93 const char *dsp_text;
94
95 bool is_selected;
96 bool is_title;
97 bool show_cursor;
98 bool have_icons;
99};
100
101typedef void list_draw_item(struct list_putlineinfo_t *list_info);
102/*
103 * Voice callback
104 * - selected_item : an integer that tells the number of the item to speak
105 * - data : a void pointer to the data you gave to the list when you
106 * initialized it
107 * Returns an integer, 0 means success, ignored really...
108 */
109typedef int list_speak_item(int selected_item, void * data);
110#ifdef HAVE_LCD_COLOR
111/*
112 * Color callback
113 * - selected_item : an integer that tells the number of the item to display
114 * - data : a void pointer to the data you gave to the list when you
115 * initialized it
116 * Returns an int with the lower 16 bits representing the color to display the
117 * selected item, negative value for default coloring.
118 */
119typedef int list_get_color(int selected_item, void * data);
120
121struct list_selection_color
122{
123 /* text color, in native lcd format
124 * (convert with LCD_RGBPACK() if necessary) */
125 unsigned text_color;
126 /* only STYLE_GRADIENT supported set line_color & line_end_color the same
127 * for solid color, in native
128 * lcd format (convert with LCD_RGBPACK() if necessary) */
129 unsigned line_color;
130 unsigned line_end_color;
131 /* viewport foreground and background, in native
132 * lcd format (convert with LCD_RGBPACK() if necessary) */
133 unsigned fg_color;
134 unsigned bg_color;
135 /* To enable:
136 * call gui_synclist_set_sel_color(gui_synclist*, list_selection_color*)
137 * If using the default viewport you should call
138 * gui_synclist_set_sel_color(gui_synclist*, NULL) when finished */
139};
140#endif
141
142struct gui_synclist
143{
144 /*flags to hold settings show: icons, scrollbar etc..*/
145 int scrollbar;
146 int cursor_style;
147 bool show_icons;
148 bool keyclick;
149 bool talk_menu;
150 bool wraparound;
151 bool scroll_paginated;
152 /* whether the text of the whole items of the list have to be
153 * scrolled or only for the selected item */
154 bool scroll_all;
155 int nb_items;
156 int selected_item;
157
158#ifdef HAVE_TOUCHSCREEN
159 /* absolute Y coordinate, used for smooth scrolling */
160 int y_pos;
161#endif
162 int start_item[NB_SCREENS]; /* the item that is displayed at the top of the screen */
163 /* the number of lines that are selected at the same time */
164 int selected_size;
165 /* the number of pixels each line occupies (including optional padding on touchscreen */
166 int line_height[NB_SCREENS];
167 int offset_position[NB_SCREENS]; /* the list's screen scroll placement in pixels */
168 long scheduled_talk_tick, last_talked_tick, dirty_tick;
169
170 list_get_icon *callback_get_item_icon;
171 list_get_name *callback_get_item_name;
172 list_speak_item *callback_speak_item;
173 list_draw_item *callback_draw_item;
174
175 /* The data that will be passed to the callback function YOU implement */
176 void * data;
177 /* The optional title, set to NULL for none */
178 const char * title;
179 /* Optional title icon */
180 enum themable_icons title_icon;
181
182#ifdef HAVE_LCD_COLOR
183 int title_color;
184 list_get_color *callback_get_item_color;
185 struct list_selection_color *selection_color;
186#endif
187 struct viewport *parent[NB_SCREENS];
188};
189
190
191extern void list_init(void);
192
193extern void gui_synclist_init(
194 struct gui_synclist * lists,
195 list_get_name callback_get_item_name,
196 void * data,
197 bool scroll_all,
198 int selected_size,
199 struct viewport parent[NB_SCREENS] /* NOTE: new screens should NOT set this to NULL */
200 );
201extern void gui_synclist_set_nb_items(struct gui_synclist * lists, int nb_items);
202extern void gui_synclist_set_icon_callback(struct gui_synclist * lists, list_get_icon icon_callback);
203extern void gui_synclist_set_voice_callback(struct gui_synclist * lists, list_speak_item voice_callback);
204extern void gui_synclist_set_viewport_defaults(struct viewport *vp, enum screen_type screen);
205#ifdef HAVE_LCD_COLOR
206extern void gui_synclist_set_color_callback(struct gui_synclist * lists, list_get_color color_callback);
207extern void gui_synclist_set_sel_color(struct gui_synclist * lists, struct list_selection_color *list_sel_color);
208#endif
209extern void gui_synclist_speak_item(struct gui_synclist * lists);
210extern int gui_synclist_get_nb_items(struct gui_synclist * lists);
211
212extern int gui_synclist_get_sel_pos(struct gui_synclist * lists);
213
214extern void gui_synclist_draw(struct gui_synclist * lists);
215extern void gui_synclist_scroll_stop(struct gui_synclist *lists);
216extern void gui_synclist_select_item(struct gui_synclist * lists,
217 int item_number);
218extern void gui_synclist_add_item(struct gui_synclist * lists);
219extern void gui_synclist_del_item(struct gui_synclist * lists);
220extern void gui_synclist_set_title(struct gui_synclist * lists, const char * title,
221 enum themable_icons icon);
222
223extern bool gui_synclist_keyclick_callback(int action, void* data);
224/*
225 * Do the action implied by the given button,
226 * returns true if the action was handled.
227 * NOTE: *action may be changed regardless of return value
228 */
229extern bool gui_synclist_do_button(struct gui_synclist * lists, int *action);
230#if !defined(PLUGIN)
231struct listitem_viewport_cfg;
232
233bool skinlist_get_item(struct screen *display, struct gui_synclist *list, int x, int y, int *item);
234bool skinlist_draw(struct screen *display, struct gui_synclist *list);
235bool skinlist_is_selected_item(void);
236void skinlist_set_cfg(enum screen_type screen,
237 struct listitem_viewport_cfg *cfg);
238const char* skinlist_get_item_text(int offset, bool wrap, char* buf, size_t buf_size);
239int skinlist_get_item_number(void);
240int skinlist_get_item_row(void);
241int skinlist_get_item_column(void);
242enum themable_icons skinlist_get_item_icon(int offset, bool wrap);
243bool skinlist_needs_scrollbar(enum screen_type screen);
244void skinlist_get_scrollbar(int* nb_item, int* first_shown, int* last_shown);
245int skinlist_get_line_count(enum screen_type screen, struct gui_synclist *list);
246#endif /* !PLUGIN) */
247
248#if defined(HAVE_TOUCHSCREEN)
249/* this needs to be fixed if we ever get more than 1 touchscreen on a target */
250extern unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list);
251/* only for private use in gui/list.c */
252extern void _gui_synclist_stop_kinetic_scrolling(struct gui_synclist * gui_list);
253#endif
254
255/* If the list has a pending postponed scheduled announcement, that
256 may become due before the next get_action tmieout. This function
257 adjusts the get_action timeout appropriately. */
258extern int list_do_action_timeout(struct gui_synclist *lists, int timeout);
259/* This one combines a get_action call (with timeout overridden by
260 list_do_action_timeout) with the gui_synclist_do_button call, for
261 convenience. */
262extern bool list_do_action(int context, int timeout,
263 struct gui_synclist *lists, int *action);
264
265
266/** Simplelist implementation.
267 USe this if you dont need to reimplement the list code,
268 and just need to show a list
269 **/
270
271struct simplelist_info {
272 const char *title; /* title to show on the list */
273 int count; /* number of items in the list, each item is selection_size high */
274 int selection_size; /* list selection size, usually 1 */
275 bool scroll_all;
276 bool hide_theme;
277 bool speak_onshow; /* list speaks first item or 'empty list' */
278 int timeout;
279 int selection; /* the item to select when the list is first displayed */
280 /* when the list is exited, this will be set to the
281 index of the last item selected, or -1 if the list
282 was exited with ACTION_STD_CANCEL */
283 int (*action_callback)(int action, struct gui_synclist *lists); /* can be NULL */
284 /* action_callback notes:
285 action == the action pressed by the user
286 _after_ gui_synclist_do_button returns.
287 lists == the lists struct so the callback can get selection and count etc. */
288 enum themable_icons title_icon;
289 list_get_icon *get_icon; /* can be NULL */
290 list_get_name *get_name; /* NULL if you're using simplelist_addline() */
291 list_speak_item *get_talk; /* can be NULL to not speak */
292#ifdef HAVE_LCD_COLOR
293 list_get_color *get_color;
294 struct list_selection_color *selection_color;
295#endif
296 void *callback_data; /* data for callbacks */
297};
298
299#define SIMPLELIST_MAX_LINES 32
300#ifdef HAVE_ATA_SMART
301#define SIMPLELIST_MAX_LINELENGTH 48
302#else
303#define SIMPLELIST_MAX_LINELENGTH 32
304#endif
305
306/** The next three functions are used if the text is mostly static.
307 These should be called in the action callback for the list.
308 **/
309/* reset the amount of lines shown in the list to 0
310 Only needed if simplelist_info.get_name == NULL */
311void simplelist_reset_lines(void);
312/* get the current amount of lines shown */
313int simplelist_get_line_count(void);
314/* add a line in the list. */
315void simplelist_addline(const char *fmt, ...) ATTRIBUTE_PRINTF(1,2);
316void simplelist_setline(const char *text);
317/* setup the info struct. members not setup in this function need to be assigned manually
318 members set in this function:
319 info.selection_size = 1;
320 info.scroll_all = false;
321 info.hide_theme = false;
322 info.speak_onshow = true;
323 info.action_callback = NULL;
324 info.title_icon = Icon_NOICON;
325 info.get_icon = NULL;
326 info.get_name = NULL;
327 info.get_voice = NULL;
328 info.get_color = NULL;
329 info.list_selection_color = NULL;
330 info.timeout = HZ/10;
331 info.selection = 0;
332*/
333void simplelist_info_init(struct simplelist_info *info, char* title,
334 int count, void* data);
335
336/* show a list.
337 if list->action_callback != NULL it is called with the action ACTION_REDRAW
338 before the list is dislplayed for the first time */
339bool simplelist_show_list(struct simplelist_info *info);
340
341#endif /* _GUI_LIST_H_ */