1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Kevin Ferrare
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
27 #include "screen_access.h"
29 #define SCROLLBAR_WIDTH global_settings.scrollbar_width
34 LIST_WRAP_UNLESS_HELD
,
38 * The gui_list is based on callback functions, if you want the list
39 * to display something you have to provide it a function that
40 * tells it what to display.
41 * There are three callback function :
42 * one to get the text, one to get the icon and one to get the color
47 * - selected_item : an integer that tells the number of the item to display
48 * - data : a void pointer to the data you gave to the list when you
50 * Returns a pointer to the icon, the value inside it is used to display the
51 * icon after the function returns.
52 * Note : we use the ICON type because the real type depends of the plateform
54 typedef enum themable_icons
list_get_icon(int selected_item
, void * data
);
57 * - selected_item : an integer that tells the number of the item to display
58 * - data : a void pointer to the data you gave to the list when you
60 * - buffer : a buffer to put the resulting text on it
61 * (The content of the buffer may not be used by the list, we use
62 * the return value of the function in all cases to avoid filling
63 * a buffer when it's not necessary)
64 * - buffer_len : length of the buffer
65 * Returns a pointer to a string that contains the text to display
67 typedef const char * list_get_name(int selected_item
, void * data
,
68 char * buffer
, size_t buffer_len
);
71 * - selected_item : an integer that tells the number of the item to speak
72 * - data : a void pointer to the data you gave to the list when you
74 * Returns an integer, 0 means success, ignored really...
76 typedef int list_speak_item(int selected_item
, void * data
);
80 * - selected_item : an integer that tells the number of the item to display
81 * - data : a void pointer to the data you gave to the list when you
83 * Returns an int with the lower 16 bits representing the color to display the
84 * selected item, negative value for default coloring.
86 typedef int list_get_color(int selected_item
, void * data
);
91 /* defines wether the list should stop when reaching the top/bottom
92 * or should continue (by going to bottom/top) */
94 /* wether the text of the whole items of the list have to be
95 * scrolled or only for the selected item */
99 int start_item
[NB_SCREENS
]; /* the item that is displayed at the top of the screen */
100 /* the number of lines that are selected at the same time */
102 #ifdef HAVE_LCD_BITMAP
103 int offset_position
[NB_SCREENS
]; /* the list's screen scroll placement in pixels */
105 long scheduled_talk_tick
, last_talked_tick
;
107 list_get_icon
*callback_get_item_icon
;
108 list_get_name
*callback_get_item_name
;
109 list_speak_item
*callback_speak_item
;
111 /* The data that will be passed to the callback function YOU implement */
113 /* The optional title, set to NULL for none */
115 /* Optional title icon */
116 enum themable_icons title_icon
;
117 bool show_selection_marker
; /* set to true by default */
119 #ifdef HAVE_LCD_COLOR
121 list_get_color
*callback_get_item_color
;
123 struct viewport
*parent
[NB_SCREENS
];
127 #ifdef HAVE_LCD_BITMAP
128 extern void list_init(void);
129 /* parse global setting to static int */
130 extern void gui_list_screen_scroll_step(int ofs
);
132 /* parse global setting to static bool */
133 extern void gui_list_screen_scroll_out_of_view(bool enable
);
134 #endif /* HAVE_LCD_BITMAP */
136 extern void gui_synclist_init(
137 struct gui_synclist
* lists
,
138 list_get_name callback_get_item_name
,
142 struct viewport parent
[NB_SCREENS
] /* NOTE: new screens should NOT set this to NULL */
144 extern void gui_synclist_set_nb_items(struct gui_synclist
* lists
, int nb_items
);
145 extern void gui_synclist_set_icon_callback(struct gui_synclist
* lists
, list_get_icon icon_callback
);
146 extern void gui_synclist_set_voice_callback(struct gui_synclist
* lists
, list_speak_item voice_callback
);
147 #ifdef HAVE_LCD_COLOR
148 extern void gui_synclist_set_color_callback(struct gui_synclist
* lists
, list_get_color color_callback
);
150 extern void gui_synclist_speak_item(struct gui_synclist
* lists
);
151 extern int gui_synclist_get_nb_items(struct gui_synclist
* lists
);
153 extern int gui_synclist_get_sel_pos(struct gui_synclist
* lists
);
155 extern void gui_synclist_draw(struct gui_synclist
* lists
);
156 extern void gui_synclist_scroll_stop(struct gui_synclist
*lists
);
157 extern void gui_synclist_select_item(struct gui_synclist
* lists
,
159 extern void gui_synclist_add_item(struct gui_synclist
* lists
);
160 extern void gui_synclist_del_item(struct gui_synclist
* lists
);
161 extern void gui_synclist_limit_scroll(struct gui_synclist
* lists
, bool scroll
);
162 extern void gui_synclist_set_title(struct gui_synclist
* lists
, char * title
,
163 enum themable_icons icon
);
164 extern void gui_synclist_hide_selection_marker(struct gui_synclist
*lists
,
166 extern bool gui_synclist_item_is_onscreen(struct gui_synclist
*lists
,
167 enum screen_type screen
, int item
);
169 * Do the action implied by the given button,
170 * returns true if the action was handled.
171 * NOTE: *action may be changed regardless of return value
173 extern bool gui_synclist_do_button(struct gui_synclist
* lists
,
177 #if defined(HAVE_TOUCHSCREEN)
178 /* this needs to be fixed if we ever get more than 1 touchscreen on a target */
179 extern unsigned gui_synclist_do_touchscreen(struct gui_synclist
* gui_list
);
180 /* only for private use in gui/list.c */
181 extern void _gui_synclist_stop_kinetic_scrolling(void);
184 /* If the list has a pending postponed scheduled announcement, that
185 may become due before the next get_action tmieout. This function
186 adjusts the get_action timeout appropriately. */
187 extern int list_do_action_timeout(struct gui_synclist
*lists
, int timeout
);
188 /* This one combines a get_action call (with timeout overridden by
189 list_do_action_timeout) with the gui_synclist_do_button call, for
191 extern bool list_do_action(int context
, int timeout
,
192 struct gui_synclist
*lists
, int *action
,
193 enum list_wrap wrap
);
196 /** Simplelist implementation.
197 USe this if you dont need to reimplement the list code,
198 and just need to show a list
201 struct simplelist_info
{
202 char *title
; /* title to show on the list */
203 int count
; /* number of items in the list, each item is selection_size high */
204 int selection_size
; /* list selection size, usually 1 */
208 int selection
; /* the item to select when the list is first displayed */
209 /* when the list is exited, this will be set to the
210 index of the last item selected, or -1 if the list
211 was exited with ACTION_STD_CANCEL */
212 int (*action_callback
)(int action
, struct gui_synclist
*lists
); /* can be NULL */
213 /* action_callback notes:
214 action == the action pressed by the user
215 _after_ gui_synclist_do_button returns.
216 lists == the lists sturct so the callack can get selection and count etc. */
217 list_get_icon
*get_icon
; /* can be NULL */
218 list_get_name
*get_name
; /* NULL if you're using simplelist_addline() */
219 list_speak_item
*get_talk
; /* can be NULL to not speak */
220 void *callback_data
; /* data for callbacks */
223 #define SIMPLELIST_MAX_LINES 32
224 #define SIMPLELIST_MAX_LINELENGTH 32
226 /** The next three functions are used if the text is mostly static.
227 These should be called in the action callback for the list.
229 /* set the amount of lines shown in the list
230 Only needed if simplelist_info.get_name == NULL */
231 void simplelist_set_line_count(int lines
);
232 /* get the current amount of lines shown */
233 int simplelist_get_line_count(void);
234 /* add/edit a line in the list.
235 if line_number > number of lines shown it adds the line, else it edits the line */
236 #define SIMPLELIST_ADD_LINE (SIMPLELIST_MAX_LINES+1)
237 void simplelist_addline(int line_number
, const char *fmt
, ...);
239 /* setup the info struct. members not setup in this function need to be assigned manually
240 members set in this function:
241 info.selection_size = 1;
242 info.hide_selection = false;
243 info.scroll_all = false;
244 info.action_callback = NULL;
245 info.get_icon = NULL;
246 info.get_name = NULL;
247 info.get_voice = NULL;
248 info.timeout = HZ/10;
251 void simplelist_info_init(struct simplelist_info
*info
, char* title
,
252 int count
, void* data
);
255 if list->action_callback != NULL it is called with the action ACTION_REDRAW
256 before the list is dislplayed for the first time */
257 bool simplelist_show_list(struct simplelist_info
*info
);
259 #endif /* _GUI_LIST_H_ */