diff options
Diffstat (limited to 'apps/gui/list.h')
-rw-r--r-- | apps/gui/list.h | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/apps/gui/list.h b/apps/gui/list.h new file mode 100644 index 0000000000..fd553f381c --- /dev/null +++ b/apps/gui/list.h | |||
@@ -0,0 +1,232 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 by Kévin FERRARE | ||
11 | * | ||
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. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef _GUI_LIST_H_ | ||
21 | #define _GUI_LIST_H_ | ||
22 | |||
23 | #include "config.h" | ||
24 | #include "icon.h" | ||
25 | #include "screen_access.h" | ||
26 | |||
27 | #define SCROLLBAR_WIDTH 6 | ||
28 | |||
29 | /* Key assignement */ | ||
30 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ | ||
31 | (CONFIG_KEYPAD == IRIVER_H300_PAD) | ||
32 | #define LIST_NEXT BUTTON_DOWN | ||
33 | #define LIST_PREV BUTTON_UP | ||
34 | #define LIST_PGUP (BUTTON_ON | BUTTON_UP) | ||
35 | #define LIST_PGDN (BUTTON_ON | BUTTON_DOWN) | ||
36 | #define LIST_RC_NEXT BUTTON_RC_FF | ||
37 | #define LIST_RC_PREV BUTTON_RC_REW | ||
38 | #define LIST_RC_PGUP BUTTON_RC_SOURCE | ||
39 | #define LIST_RC_PGDN BUTTON_RC_BITRATE | ||
40 | |||
41 | #elif CONFIG_KEYPAD == RECORDER_PAD | ||
42 | #define LIST_NEXT BUTTON_DOWN | ||
43 | #define LIST_PREV BUTTON_UP | ||
44 | #define LIST_PGUP (BUTTON_ON | BUTTON_UP) | ||
45 | #define LIST_PGDN (BUTTON_ON | BUTTON_DOWN) | ||
46 | #define LIST_RC_NEXT BUTTON_RC_RIGHT | ||
47 | #define LIST_RC_PREV BUTTON_RC_LEFT | ||
48 | |||
49 | #elif CONFIG_KEYPAD == PLAYER_PAD | ||
50 | #define LIST_NEXT BUTTON_RIGHT | ||
51 | #define LIST_PREV BUTTON_LEFT | ||
52 | #define LIST_RC_NEXT BUTTON_RC_RIGHT | ||
53 | #define LIST_RC_PREV BUTTON_RC_LEFT | ||
54 | |||
55 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
56 | #define LIST_NEXT BUTTON_DOWN | ||
57 | #define LIST_PREV BUTTON_UP | ||
58 | |||
59 | #elif CONFIG_KEYPAD == GMINI100_PAD | ||
60 | #define LIST_NEXT BUTTON_DOWN | ||
61 | #define LIST_PREV BUTTON_UP | ||
62 | #define LIST_PGUP (BUTTON_ON | BUTTON_UP) | ||
63 | #define LIST_PGDN (BUTTON_ON | BUTTON_DOWN) | ||
64 | #endif | ||
65 | |||
66 | |||
67 | struct gui_list | ||
68 | { | ||
69 | int nb_items; | ||
70 | int selected_item; | ||
71 | int start_item; /* the item that is displayed at the top of the screen */ | ||
72 | |||
73 | void (*callback_get_item_icon)(int selected_item, ICON * icon); | ||
74 | char * (*callback_get_item_name)(int selected_item, char *buffer); | ||
75 | |||
76 | struct screen * display; | ||
77 | int line_scroll_limit; | ||
78 | }; | ||
79 | |||
80 | /* | ||
81 | * Initializes a scrolling list | ||
82 | * - gui_list : the list structure to initialize | ||
83 | * - callback_get_item_icon : pointer to a function that associates an icon | ||
84 | * to a given item number | ||
85 | * - callback_get_item_name : pointer to a function that associates a label | ||
86 | * to a given item number | ||
87 | */ | ||
88 | extern void gui_list_init(struct gui_list * gui_list, | ||
89 | void (*callback_get_item_icon)(int selected_item, ICON * icon), | ||
90 | char * (*callback_get_item_name)(int selected_item, char *buffer) | ||
91 | ); | ||
92 | |||
93 | /* | ||
94 | * Sets the numburs of items the list can currently display | ||
95 | * note that the list's context like the currently pointed item is resetted | ||
96 | * - gui_list : the list structure to initialize | ||
97 | * - nb_items : the numbers of items you want | ||
98 | */ | ||
99 | extern void gui_list_set_nb_items(struct gui_list * gui_list, int nb_items); | ||
100 | |||
101 | /* | ||
102 | * Puts the selection in the screen | ||
103 | * - gui_list : the list structure | ||
104 | * - put_from_end : if true, selection will be put as close from | ||
105 | * the end of the list as possible, else, it's | ||
106 | * from the beginning | ||
107 | */ | ||
108 | extern void gui_list_put_selection_in_screen(struct gui_list * gui_list, | ||
109 | bool put_from_end); | ||
110 | |||
111 | /* | ||
112 | * Attach the scrolling list to a screen | ||
113 | * (The previous screen attachement is lost) | ||
114 | * - gui_list : the list structure | ||
115 | * - display : the screen to attach | ||
116 | */ | ||
117 | extern void gui_list_set_display(struct gui_list * gui_list, | ||
118 | struct screen * display); | ||
119 | |||
120 | /* | ||
121 | * Gives the name of the selected object | ||
122 | * - gui_list : the list structure | ||
123 | * - buffer : a buffer which is filled with the name | ||
124 | */ | ||
125 | extern void gui_list_get_selected_item_name(struct gui_list * gui_list, | ||
126 | char *buffer); | ||
127 | |||
128 | /* | ||
129 | * Gives the position of the selected item | ||
130 | * - gui_list : the list structure | ||
131 | * Returns the position | ||
132 | */ | ||
133 | extern int gui_list_get_selected_item_position(struct gui_list * gui_list); | ||
134 | |||
135 | /* | ||
136 | * Selects an item in the list | ||
137 | * - gui_list : the list structure | ||
138 | * - item_number : the number of the item which will be selected | ||
139 | */ | ||
140 | extern void gui_list_select_item(struct gui_list * gui_list, int item_number); | ||
141 | |||
142 | /* | ||
143 | * Draws the list on the attached screen | ||
144 | * - gui_list : the list structure | ||
145 | */ | ||
146 | extern void gui_list_draw(struct gui_list * gui_list); | ||
147 | |||
148 | /* | ||
149 | * Selects the next item in the list | ||
150 | * (Item 0 gets selected if the end of the list is reached) | ||
151 | * - gui_list : the list structure | ||
152 | */ | ||
153 | extern void gui_list_select_next(struct gui_list * gui_list); | ||
154 | |||
155 | /* | ||
156 | * Selects the previous item in the list | ||
157 | * (Last item in the list gets selected if the list beginning is reached) | ||
158 | * - gui_list : the list structure | ||
159 | */ | ||
160 | extern void gui_list_select_previous(struct gui_list * gui_list); | ||
161 | |||
162 | /* | ||
163 | * Go to next page if any, else selects the last item in the list | ||
164 | * - gui_list : the list structure | ||
165 | * - nb_lines : the number of lines to try to move the cursor | ||
166 | */ | ||
167 | extern void gui_list_select_next_page(struct gui_list * gui_list, | ||
168 | int nb_lines); | ||
169 | |||
170 | /* | ||
171 | * Go to previous page if any, else selects the first item in the list | ||
172 | * - gui_list : the list structure | ||
173 | * - nb_lines : the number of lines to try to move the cursor | ||
174 | */ | ||
175 | extern void gui_list_select_previous_page(struct gui_list * gui_list, | ||
176 | int nb_lines); | ||
177 | |||
178 | /* | ||
179 | * Adds an item to the list (the callback will be asked for one more item) | ||
180 | * - gui_list : the list structure | ||
181 | */ | ||
182 | extern void gui_list_add_item(struct gui_list * gui_list); | ||
183 | |||
184 | /* | ||
185 | * Removes an item to the list (the callback will be asked for one less item) | ||
186 | * - gui_list : the list structure | ||
187 | */ | ||
188 | extern void gui_list_del_item(struct gui_list * gui_list); | ||
189 | |||
190 | |||
191 | /* | ||
192 | * This part handles as many lists as there are connected screens | ||
193 | * (the api is similar to the ones above) | ||
194 | * The lists on the screens are synchronized ; | ||
195 | * theirs items and selected items are the same, but of course, | ||
196 | * they can be displayed on screens with different sizes | ||
197 | * The final aim is to let the programmer handle many lists in one | ||
198 | * function call and make its code independant from the number of screens | ||
199 | */ | ||
200 | struct gui_synclist | ||
201 | { | ||
202 | struct gui_list gui_list[NB_SCREENS]; | ||
203 | }; | ||
204 | |||
205 | extern void gui_synclist_init(struct gui_synclist * lists, | ||
206 | void (*callback_get_item_icon)(int selected_item, ICON * icon), | ||
207 | char * (*callback_get_item_name)(int selected_item, char *buffer) | ||
208 | ); | ||
209 | extern void gui_synclist_set_nb_items(struct gui_synclist * lists, int nb_items); | ||
210 | extern void gui_synclist_get_selected_item_name(struct gui_synclist * lists, | ||
211 | char *buffer); | ||
212 | extern int gui_synclist_get_selected_item_position(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, | ||
215 | int item_number); | ||
216 | extern void gui_synclist_select_next(struct gui_synclist * lists); | ||
217 | extern void gui_synclist_select_previous(struct gui_synclist * lists); | ||
218 | extern void gui_synclist_select_next_page(struct gui_synclist * lists, | ||
219 | enum screen_type screen); | ||
220 | extern void gui_synclist_select_previous_page(struct gui_synclist * lists, | ||
221 | enum screen_type screen); | ||
222 | extern void gui_synclist_add_item(struct gui_synclist * lists); | ||
223 | extern void gui_synclist_del_item(struct gui_synclist * lists); | ||
224 | /* | ||
225 | * Do the action implied by the given button, | ||
226 | * returns true if something has been done, false otherwise | ||
227 | * - lists : the synchronized lists | ||
228 | * - button : the keycode of a pressed button | ||
229 | */ | ||
230 | extern bool gui_synclist_do_button(struct gui_synclist * lists, unsigned button); | ||
231 | |||
232 | #endif /* _GUI_LIST_H_ */ | ||