1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Kevin Ferrare
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
25 #include "screen_access.h"
27 #define SCROLLBAR_WIDTH 6
32 LIST_WRAP_UNLESS_HELD
,
36 * The gui_list is based on callback functions, if you want the list
37 * to display something you have to provide it a function that
38 * tells it what to display.
39 * There are three callback function :
40 * one to get the text, one to get the icon and one to get the color
45 * - selected_item : an integer that tells the number of the item to display
46 * - data : a void pointer to the data you gave to the list when you
48 * Returns a pointer to the icon, the value inside it is used to display the
49 * icon after the function returns.
50 * Note : we use the ICON type because the real type depends of the plateform
52 typedef enum themable_icons
list_get_icon(int selected_item
, void * data
);
55 * - selected_item : an integer that tells the number of the item to display
56 * - data : a void pointer to the data you gave to the list when you
58 * - buffer : a buffer to put the resulting text on it
59 * (The content of the buffer may not be used by the list, we use
60 * the return value of the function in all cases to avoid filling
61 * a buffer when it's not necessary)
62 * Returns a pointer to a string that contains the text to display
64 typedef char * list_get_name(int selected_item
, void * data
, char * buffer
);
67 * - selected_item : an integer that tells the number of the item to speak
68 * - data : a void pointer to the data you gave to the list when you
70 * Returns an integer, 0 means success, ignored really...
72 typedef int list_speak_item(int selected_item
, void * data
);
76 * - selected_item : an integer that tells the number of the item to display
77 * - data : a void pointer to the data you gave to the list when you
79 * Returns an int with the lower 16 bits representing the color to display the
80 * selected item, negative value for default coloring.
82 typedef int list_get_color(int selected_item
, void * data
);
87 /* defines wether the list should stop when reaching the top/bottom
88 * or should continue (by going to bottom/top) */
90 /* wether the text of the whole items of the list have to be
91 * scrolled or only for the selected item */
96 int start_item
[NB_SCREENS
]; /* the item that is displayed at the top of the screen */
97 /* the number of lines that are selected at the same time */
99 /* These are used to calculate how much of the screen content we need
101 int last_displayed_selected_item
;
102 int last_displayed_start_item
[NB_SCREENS
];
103 #ifdef HAVE_LCD_BITMAP
104 int offset_position
[NB_SCREENS
]; /* the list's screen scroll placement in pixels */
106 /* Cache the width of the title string in pixels/characters */
108 long scheduled_talk_tick
, last_talked_tick
;
110 list_get_icon
*callback_get_item_icon
;
111 list_get_name
*callback_get_item_name
;
112 list_speak_item
*callback_speak_item
;
114 /* The data that will be passed to the callback function YOU implement */
116 /* The optional title, set to NULL for none */
118 /* Optional title icon */
119 enum themable_icons title_icon
;
120 bool show_selection_marker
; /* set to true by default */
122 #ifdef HAVE_LCD_COLOR
124 list_get_color
*callback_get_item_color
;
129 * Sets the numbers of items the list can currently display
130 * note that the list's context like the currently pointed item is resetted
131 * - gui_list : the list structure
132 * - nb_items : the numbers of items you want
134 #define gui_list_set_nb_items(gui_list, nb) \
135 (gui_list)->nb_items = nb
138 * Returns the numbers of items currently in the list
139 * - gui_list : the list structure
141 #define gui_list_get_nb_items(gui_list) \
145 * Sets the icon callback function
146 * - gui_list : the list structure
147 * - _callback : the callback function
149 #define gui_list_set_icon_callback(gui_list, _callback) \
150 (gui_list)->callback_get_item_icon=_callback
153 * Sets the voice callback function
154 * - gui_list : the list structure
155 * - _callback : the callback function
157 #define gui_list_set_voice_callback(gui_list, _callback) \
158 (gui_list)->callback_speak_item=_callback
160 #ifdef HAVE_LCD_COLOR
162 * Sets the color callback function
163 * - gui_list : the list structure
164 * - _callback : the callback function
166 #define gui_list_set_color_callback(gui_list, _callback) \
167 (gui_list)->callback_get_item_color=_callback
171 * Gives the position of the selected item
172 * - gui_list : the list structure
173 * Returns the position
175 #define gui_list_get_sel_pos(gui_list) \
176 (gui_list)->selected_item
179 #ifdef HAVE_LCD_BITMAP
180 /* parse global setting to static int */
181 extern void gui_list_screen_scroll_step(int ofs
);
183 /* parse global setting to static bool */
184 extern void gui_list_screen_scroll_out_of_view(bool enable
);
185 #endif /* HAVE_LCD_BITMAP */
187 * Tells the list wether it should stop when reaching the top/bottom
188 * or should continue (by going to bottom/top)
189 * - gui_list : the list structure
191 * - true : stops when reaching top/bottom
192 * - false : continues to go to bottom/top when reaching top/bottom
194 #define gui_list_limit_scroll(gui_list, scroll) \
195 (gui_list)->limit_scroll=scroll
198 extern void gui_synclist_init(
199 struct gui_synclist
* lists
,
200 list_get_name callback_get_item_name
,
205 extern void gui_synclist_set_nb_items(struct gui_synclist
* lists
, int nb_items
);
206 extern void gui_synclist_set_icon_callback(struct gui_synclist
* lists
, list_get_icon icon_callback
);
207 extern void gui_synclist_set_voice_callback(struct gui_synclist
* lists
, list_speak_item voice_callback
);
208 extern void gui_synclist_speak_item(struct gui_synclist
* lists
);
209 extern int gui_synclist_get_nb_items(struct gui_synclist
* lists
);
211 extern int gui_synclist_get_sel_pos(struct gui_synclist
* lists
);
213 extern void gui_synclist_draw(struct gui_synclist
* lists
);
214 extern void gui_synclist_select_item(struct gui_synclist
* lists
,
216 extern void gui_synclist_add_item(struct gui_synclist
* lists
);
217 extern void gui_synclist_del_item(struct gui_synclist
* lists
);
218 extern void gui_synclist_limit_scroll(struct gui_synclist
* lists
, bool scroll
);
219 extern void gui_synclist_flash(struct gui_synclist
* lists
);
220 extern void gui_synclist_set_title(struct gui_synclist
* lists
, char * title
,
222 extern void gui_synclist_hide_selection_marker(struct gui_synclist
*lists
,
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
229 extern bool gui_synclist_do_button(struct gui_synclist
* lists
,
233 /* If the list has a pending postponed scheduled announcement, that
234 may become due before the next get_action tmieout. This function
235 adjusts the get_action timeout appropriately. */
236 extern int list_do_action_timeout(struct gui_synclist
*lists
, int timeout
);
237 /* This one combines a get_action call (with timeout overridden by
238 list_do_action_timeout) with the gui_synclist_do_button call, for
240 extern bool list_do_action(int context
, int timeout
,
241 struct gui_synclist
*lists
, int *action
,
242 enum list_wrap wrap
);
245 /** Simplelist implementation.
246 USe this if you dont need to reimplement the list code,
247 and just need to show a list
250 struct simplelist_info
{
251 char *title
; /* title to show on the list */
252 int count
; /* number of items in the list, each item is selection_size high */
253 char selection_size
; /* list selection size, usually 1 */
257 int start_selection
; /* the item to select when the list is first displayed */
258 int (*action_callback
)(int action
, struct gui_synclist
*lists
); /* can be NULL */
259 /* action_callback notes:
260 action == the action pressed by the user
261 _after_ gui_synclist_do_button returns.
262 lists == the lists sturct so the callack can get selection and count etc. */
263 list_get_icon
*get_icon
; /* can be NULL */
264 list_get_name
*get_name
; /* NULL if you're using simplelist_addline() */
265 list_speak_item
*get_talk
; /* can be NULL to not speak */
266 void *callback_data
; /* data for callbacks */
269 #define SIMPLELIST_MAX_LINES 32
270 #define SIMPLELIST_MAX_LINELENGTH 32
272 /** The next three functions are used if the text is mostly static.
273 These should be called in the action callback for the list.
275 /* set the amount of lines shown in the list
276 Only needed if simplelist_info.get_name == NULL */
277 void simplelist_set_line_count(int lines
);
278 /* get the current amount of lines shown */
279 int simplelist_get_line_count(void);
280 /* add/edit a line in the list.
281 if line_number > number of lines shown it adds the line, else it edits the line */
282 #define SIMPLELIST_ADD_LINE (SIMPLELIST_MAX_LINES+1)
283 void simplelist_addline(int line_number
, const char *fmt
, ...);
285 /* setup the info struct. members not setup in this function need to be assigned manually
286 members set in this function:
287 info.selection_size = 1;
288 info.hide_selection = false;
289 info.scroll_all = false;
290 info.action_callback = NULL;
291 info.get_icon = NULL;
292 info.get_name = NULL;
293 info.get_voice = NULL;
294 info.timeout = HZ/10;
295 info.start_selection = 0;
297 void simplelist_info_init(struct simplelist_info
*info
, char* title
,
298 int count
, void* data
);
301 if list->action_callback != NULL it is called with the action ACTION_REDRAW
302 before the list is dislplayed for the first time */
303 bool simplelist_show_list(struct simplelist_info
*info
);
305 #endif /* _GUI_LIST_H_ */