1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 by Kevin Ferrare
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef _GUI_LIST_H_
#define _GUI_LIST_H_
#include "config.h"
#include "icon.h"
#include "screen_access.h"
#define SCROLLBAR_WIDTH 6
enum list_wrap {
LIST_WRAP_ON = 0,
LIST_WRAP_OFF,
LIST_WRAP_UNLESS_HELD,
};
/*
* The gui_list is based on callback functions, if you want the list
* to display something you have to provide it a function that
* tells it what to display.
* There are two callback function :
* one to get the text and one to get the icon
*/
/*
* Icon callback
* - selected_item : an integer that tells the number of the item to display
* - data : a void pointer to the data you gave to the list when
* you initialized it
* - icon : a pointer to the icon, the value inside it is used to display
* the icon after the function returns.
* Note : we use the ICON type because the real type depends of the plateform
*/
typedef void list_get_icon(int selected_item,
void * data,
ICON * icon);
/*
* Text callback
* - selected_item : an integer that tells the number of the item to display
* - data : a void pointer to the data you gave to the list when
* you initialized it
* - buffer : a buffer to put the resulting text on it
* (The content of the buffer may not be used by the list, we use
* the return value of the function in all cases to avoid filling
* a buffer when it's not necessary)
* Returns a pointer to a string that contains the text to display
*/
typedef char * list_get_name(int selected_item,
void * data,
char *buffer);
struct gui_list
{
int nb_items;
int selected_item;
bool cursor_flash_state;
int start_item; /* the item that is displayed at the top of the screen */
#ifdef HAVE_LCD_BITMAP
int offset_position; /* the list's screen scroll placement in pixels */
#endif
list_get_icon *callback_get_item_icon;
list_get_name *callback_get_item_name;
struct screen * display;
/* defines wether the list should stop when reaching the top/bottom
* or should continue (by going to bottom/top) */
bool limit_scroll;
/* wether the text of the whole items of the list have to be
* scrolled or only for the selected item */
bool scroll_all;
/* the number of lines that are selected at the same time */
int selected_size;
/* The data that will be passed to the callback function YOU implement */
void * data;
/* These are used to calculate how much of the screen content we need
to redraw. */
int last_displayed_selected_item;
int last_displayed_start_item;
/* The optional title, set to NULL for none */
char *title;
/* Cache the width of the title string in pixels/characters */
int title_width;
/* Optional title icon */
ICON title_icon;
};
/*
* Sets the numbers of items the list can currently display
* note that the list's context like the currently pointed item is resetted
* - gui_list : the list structure
* - nb_items : the numbers of items you want
*/
#define gui_list_set_nb_items(gui_list, nb) \
(gui_list)->nb_items = nb
/*
* Returns the numbers of items currently in the list
* - gui_list : the list structure
*/
#define gui_list_get_nb_items(gui_list) \
(gui_list)->nb_items
/*
* Sets the icon callback function
* - gui_list : the list structure
* - _callback : the callback function
*/
#define gui_list_set_icon_callback(gui_list, _callback) \
(gui_list)->callback_get_item_icon=_callback
/*
* Gives the position of the selected item
* - gui_list : the list structure
* Returns the position
*/
#define gui_list_get_sel_pos(gui_list) \
(gui_list)->selected_item
#ifdef HAVE_LCD_BITMAP
/* parse global setting to static int */
extern void gui_list_screen_scroll_step(int ofs);
/* parse global setting to static bool */
extern void gui_list_screen_scroll_out_of_view(bool enable);
#endif /* HAVE_LCD_BITMAP */
/*
* Tells the list wether it should stop when reaching the top/bottom
* or should continue (by going to bottom/top)
* - gui_list : the list structure
* - scroll :
* - true : stops when reaching top/bottom
* - false : continues to go to bottom/top when reaching top/bottom
*/
#define gui_list_limit_scroll(gui_list, scroll) \
(gui_list)->limit_scroll=scroll
/*
* This part handles as many lists as there are connected screens
* (the api is similar to the ones above)
* The lists on the screens are synchronized ;
* theirs items and selected items are the same, but of course,
* they can be displayed on screens with different sizes
* The final aim is to let the programmer handle many lists in one
* function call and make its code independant from the number of screens
*/
struct gui_synclist
{
struct gui_list gui_list[NB_SCREENS];
struct gui_list *last_displayed[NB_SCREENS];
};
extern void gui_synclist_init(
struct gui_synclist * lists,
list_get_name callback_get_item_name,
void * data,
bool scroll_all,
int selected_size
);
extern void gui_synclist_set_nb_items(struct gui_synclist * lists, int nb_items);
extern void gui_synclist_set_icon_callback(struct gui_synclist * lists, list_get_icon icon_callback);
extern int gui_synclist_get_nb_items(struct gui_synclist * lists);
extern int gui_synclist_get_sel_pos(struct gui_synclist * lists);
extern void gui_synclist_draw(struct gui_synclist * lists);
extern void gui_synclist_select_item(struct gui_synclist * lists,
int item_number);
extern void gui_synclist_add_item(struct gui_synclist * lists);
extern void gui_synclist_del_item(struct gui_synclist * lists);
extern void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll);
extern void gui_synclist_flash(struct gui_synclist * lists);
extern void gui_synclist_set_title(struct gui_synclist * lists, char * title,
ICON icon);
/*
* Do the action implied by the given button,
* returns the action taken if any, 0 else
* - lists : the synchronized lists
* - button : the keycode of a pressed button
* - specifies weather to allow the list to wrap or not, values at top of page
* returned value :
* - ACTION_STD_NEXT when moving forward (next item or pgup)
* - ACTION_STD_PREV when moving backward (previous item or pgdown)
*/
extern unsigned gui_synclist_do_button(struct gui_synclist * lists,
unsigned button,
enum list_wrap);
#endif /* _GUI_LIST_H_ */
|