diff options
Diffstat (limited to 'apps/gui/list.c')
-rw-r--r-- | apps/gui/list.c | 91 |
1 files changed, 59 insertions, 32 deletions
diff --git a/apps/gui/list.c b/apps/gui/list.c index bb3eb7caaa..1a83a65e64 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * \/ \/ \/ \/ \/ | 7 | * \/ \/ \/ \/ \/ |
8 | * $Id$ | 8 | * $Id$ |
9 | * | 9 | * |
10 | * Copyright (C) 2005 by Kévin FERRARE | 10 | * Copyright (C) 2005 by Kevin FERRARE |
11 | * | 11 | * |
12 | * All files in this archive are subject to the GNU General Public License. | 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. | 13 | * See the file COPYING in the source tree root for full license agreement. |
@@ -48,9 +48,10 @@ void gui_list_init(struct gui_list * gui_list, | |||
48 | gui_list_set_nb_items(gui_list, 0); | 48 | gui_list_set_nb_items(gui_list, 0); |
49 | gui_list->selected_item = 0; | 49 | gui_list->selected_item = 0; |
50 | gui_list->start_item = 0; | 50 | gui_list->start_item = 0; |
51 | gui_list->limit_scroll=false; | ||
51 | } | 52 | } |
52 | 53 | ||
53 | void gui_list_set_nb_items(struct gui_list * gui_list, int nb_items) | 54 | inline void gui_list_set_nb_items(struct gui_list * gui_list, int nb_items) |
54 | { | 55 | { |
55 | gui_list->nb_items = nb_items; | 56 | gui_list->nb_items = nb_items; |
56 | } | 57 | } |
@@ -88,12 +89,7 @@ void gui_list_put_selection_in_screen(struct gui_list * gui_list, | |||
88 | gui_list->start_item = 0; | 89 | gui_list->start_item = 0; |
89 | } | 90 | } |
90 | 91 | ||
91 | void gui_list_get_selected_item_name(struct gui_list * gui_list, char *buffer) | 92 | inline int gui_list_get_sel_pos(struct gui_list * gui_list) |
92 | { | ||
93 | gui_list->callback_get_item_name(gui_list->selected_item, buffer); | ||
94 | } | ||
95 | |||
96 | int gui_list_get_selected_item_position(struct gui_list * gui_list) | ||
97 | { | 93 | { |
98 | return gui_list->selected_item; | 94 | return gui_list->selected_item; |
99 | } | 95 | } |
@@ -108,7 +104,7 @@ void gui_list_draw(struct gui_list * gui_list) | |||
108 | global_settings.show_icons) ; | 104 | global_settings.show_icons) ; |
109 | bool draw_cursor; | 105 | bool draw_cursor; |
110 | int i; | 106 | int i; |
111 | 107 | ||
112 | /* Adjust the position of icon, cursor, text */ | 108 | /* Adjust the position of icon, cursor, text */ |
113 | #ifdef HAVE_LCD_BITMAP | 109 | #ifdef HAVE_LCD_BITMAP |
114 | bool draw_scrollbar = (global_settings.scrollbar && | 110 | bool draw_scrollbar = (global_settings.scrollbar && |
@@ -116,7 +112,7 @@ void gui_list_draw(struct gui_list * gui_list) | |||
116 | 112 | ||
117 | int list_y_start = screen_get_text_y_start(gui_list->display); | 113 | int list_y_start = screen_get_text_y_start(gui_list->display); |
118 | int list_y_end = screen_get_text_y_end(gui_list->display); | 114 | int list_y_end = screen_get_text_y_end(gui_list->display); |
119 | 115 | ||
120 | draw_cursor = !global_settings.invert_cursor; | 116 | draw_cursor = !global_settings.invert_cursor; |
121 | text_pos = 0; /* here it's in pixels */ | 117 | text_pos = 0; /* here it's in pixels */ |
122 | if(draw_scrollbar) | 118 | if(draw_scrollbar) |
@@ -131,7 +127,7 @@ void gui_list_draw(struct gui_list * gui_list) | |||
131 | } | 127 | } |
132 | else | 128 | else |
133 | text_pos += CURSOR_WIDTH; | 129 | text_pos += CURSOR_WIDTH; |
134 | 130 | ||
135 | if(draw_icons) | 131 | if(draw_icons) |
136 | text_pos += 8; | 132 | text_pos += 8; |
137 | #else | 133 | #else |
@@ -149,8 +145,7 @@ void gui_list_draw(struct gui_list * gui_list) | |||
149 | display->width, list_y_end - list_y_start); | 145 | display->width, list_y_end - list_y_start); |
150 | display->set_drawmode(DRMODE_SOLID); | 146 | display->set_drawmode(DRMODE_SOLID); |
151 | 147 | ||
152 | /* FIXME: should not be handled here, but rather in the | 148 | display->setfont(FONT_UI); |
153 | * code that changes fonts */ | ||
154 | screen_update_nblines(display); | 149 | screen_update_nblines(display); |
155 | 150 | ||
156 | display->stop_scroll(); | 151 | display->stop_scroll(); |
@@ -159,12 +154,12 @@ void gui_list_draw(struct gui_list * gui_list) | |||
159 | display->clear_display(); | 154 | display->clear_display(); |
160 | #endif | 155 | #endif |
161 | 156 | ||
162 | for(i = 0;i < display->nb_lines;++i) | 157 | for(i = 0;i < display->nb_lines;i++) |
163 | { | 158 | { |
164 | char entry_buffer[MAX_PATH]; | 159 | char entry_buffer[MAX_PATH]; |
165 | char * entry_name; | 160 | char * entry_name; |
166 | int current_item = gui_list->start_item + i; | 161 | int current_item = gui_list->start_item + i; |
167 | 162 | ||
168 | /* When there are less items to display than the | 163 | /* When there are less items to display than the |
169 | * current available space on the screen, we stop*/ | 164 | * current available space on the screen, we stop*/ |
170 | if(current_item >= gui_list->nb_items) | 165 | if(current_item >= gui_list->nb_items) |
@@ -234,18 +229,20 @@ void gui_list_select_next(struct gui_list * gui_list) | |||
234 | { | 229 | { |
235 | int item_pos; | 230 | int item_pos; |
236 | int end_item; | 231 | int end_item; |
237 | int nb_lines = gui_list->display->nb_lines; | ||
238 | |||
239 | ++gui_list->selected_item; | ||
240 | 232 | ||
241 | if( gui_list->selected_item >= gui_list->nb_items ) | 233 | if( gui_list->selected_item == gui_list->nb_items-1 ) |
242 | { | 234 | { |
235 | if(gui_list->limit_scroll) | ||
236 | return; | ||
237 | ++gui_list->selected_item; | ||
243 | /* we have already reached the bottom of the list */ | 238 | /* we have already reached the bottom of the list */ |
244 | gui_list->selected_item = 0; | 239 | gui_list->selected_item = 0; |
245 | gui_list->start_item = 0; | 240 | gui_list->start_item = 0; |
246 | } | 241 | } |
247 | else | 242 | else |
248 | { | 243 | { |
244 | int nb_lines = gui_list->display->nb_lines; | ||
245 | ++gui_list->selected_item; | ||
249 | item_pos = gui_list->selected_item - gui_list->start_item; | 246 | item_pos = gui_list->selected_item - gui_list->start_item; |
250 | end_item = gui_list->start_item + nb_lines; | 247 | end_item = gui_list->start_item + nb_lines; |
251 | /* we start scrolling vertically when reaching the line | 248 | /* we start scrolling vertically when reaching the line |
@@ -261,9 +258,11 @@ void gui_list_select_previous(struct gui_list * gui_list) | |||
261 | int item_pos; | 258 | int item_pos; |
262 | int nb_lines = gui_list->display->nb_lines; | 259 | int nb_lines = gui_list->display->nb_lines; |
263 | 260 | ||
264 | --gui_list->selected_item; | 261 | if( gui_list->selected_item == 0 ) |
265 | if( gui_list->selected_item < 0 ) | ||
266 | { | 262 | { |
263 | if(gui_list->limit_scroll) | ||
264 | return; | ||
265 | --gui_list->selected_item; | ||
267 | /* we have aleady reached the top of the list */ | 266 | /* we have aleady reached the top of the list */ |
268 | int start; | 267 | int start; |
269 | gui_list->selected_item = gui_list->nb_items-1; | 268 | gui_list->selected_item = gui_list->nb_items-1; |
@@ -275,6 +274,7 @@ void gui_list_select_previous(struct gui_list * gui_list) | |||
275 | } | 274 | } |
276 | else | 275 | else |
277 | { | 276 | { |
277 | --gui_list->selected_item; | ||
278 | item_pos = gui_list->selected_item - gui_list->start_item; | 278 | item_pos = gui_list->selected_item - gui_list->start_item; |
279 | if( item_pos < SCROLL_LIMIT-1 && gui_list->start_item > 0 ) | 279 | if( item_pos < SCROLL_LIMIT-1 && gui_list->start_item > 0 ) |
280 | --gui_list->start_item; | 280 | --gui_list->start_item; |
@@ -284,7 +284,11 @@ void gui_list_select_previous(struct gui_list * gui_list) | |||
284 | void gui_list_select_next_page(struct gui_list * gui_list, int nb_lines) | 284 | void gui_list_select_next_page(struct gui_list * gui_list, int nb_lines) |
285 | { | 285 | { |
286 | if(gui_list->selected_item == gui_list->nb_items-1) | 286 | if(gui_list->selected_item == gui_list->nb_items-1) |
287 | { | ||
288 | if(gui_list->limit_scroll) | ||
289 | return; | ||
287 | gui_list->selected_item = 0; | 290 | gui_list->selected_item = 0; |
291 | } | ||
288 | else | 292 | else |
289 | { | 293 | { |
290 | gui_list->selected_item += nb_lines; | 294 | gui_list->selected_item += nb_lines; |
@@ -297,7 +301,11 @@ void gui_list_select_next_page(struct gui_list * gui_list, int nb_lines) | |||
297 | void gui_list_select_previous_page(struct gui_list * gui_list, int nb_lines) | 301 | void gui_list_select_previous_page(struct gui_list * gui_list, int nb_lines) |
298 | { | 302 | { |
299 | if(gui_list->selected_item == 0) | 303 | if(gui_list->selected_item == 0) |
304 | { | ||
305 | if(gui_list->limit_scroll) | ||
306 | return; | ||
300 | gui_list->selected_item = gui_list->nb_items - 1; | 307 | gui_list->selected_item = gui_list->nb_items - 1; |
308 | } | ||
301 | else | 309 | else |
302 | { | 310 | { |
303 | gui_list->selected_item -= nb_lines; | 311 | gui_list->selected_item -= nb_lines; |
@@ -332,13 +340,17 @@ void gui_list_del_item(struct gui_list * gui_list) | |||
332 | --gui_list->selected_item; | 340 | --gui_list->selected_item; |
333 | } | 341 | } |
334 | --gui_list->nb_items; | 342 | --gui_list->nb_items; |
335 | 343 | ||
336 | /* scroll the list if needed */ | 344 | /* scroll the list if needed */ |
337 | if( (dist_start_from_end < nb_lines) && (gui_list->start_item != 0) ) | 345 | if( (dist_start_from_end < nb_lines) && (gui_list->start_item != 0) ) |
338 | --gui_list->start_item; | 346 | --gui_list->start_item; |
339 | } | 347 | } |
340 | } | 348 | } |
341 | 349 | ||
350 | inline void gui_list_limit_scroll(struct gui_list * gui_list, bool scroll) | ||
351 | { | ||
352 | gui_list->limit_scroll=scroll; | ||
353 | } | ||
342 | /* | 354 | /* |
343 | * Synchronized lists stuffs | 355 | * Synchronized lists stuffs |
344 | */ | 356 | */ |
@@ -366,15 +378,9 @@ void gui_synclist_set_nb_items(struct gui_synclist * lists, int nb_items) | |||
366 | } | 378 | } |
367 | } | 379 | } |
368 | 380 | ||
369 | void gui_synclist_get_selected_item_name(struct gui_synclist * lists, | 381 | int gui_synclist_get_sel_pos(struct gui_synclist * lists) |
370 | char *buffer) | ||
371 | { | ||
372 | gui_list_get_selected_item_name(&(lists->gui_list[0]), buffer); | ||
373 | } | ||
374 | |||
375 | int gui_synclist_get_selected_item_position(struct gui_synclist * lists) | ||
376 | { | 382 | { |
377 | return gui_list_get_selected_item_position(&(lists->gui_list[0])); | 383 | return gui_list_get_sel_pos(&(lists->gui_list[0])); |
378 | } | 384 | } |
379 | 385 | ||
380 | void gui_synclist_draw(struct gui_synclist * lists) | 386 | void gui_synclist_draw(struct gui_synclist * lists) |
@@ -437,14 +443,26 @@ void gui_synclist_del_item(struct gui_synclist * lists) | |||
437 | gui_list_del_item(&(lists->gui_list[i])); | 443 | gui_list_del_item(&(lists->gui_list[i])); |
438 | } | 444 | } |
439 | 445 | ||
446 | void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll) | ||
447 | { | ||
448 | int i; | ||
449 | for(i = 0;i < NB_SCREENS;i++) | ||
450 | gui_list_limit_scroll(&(lists->gui_list[i]), scroll); | ||
451 | } | ||
452 | |||
440 | bool gui_synclist_do_button(struct gui_synclist * lists, unsigned button) | 453 | bool gui_synclist_do_button(struct gui_synclist * lists, unsigned button) |
441 | { | 454 | { |
455 | gui_synclist_limit_scroll(lists, true); | ||
442 | switch(button) | 456 | switch(button) |
443 | { | 457 | { |
444 | case LIST_PREV: | 458 | case LIST_PREV: |
445 | case LIST_PREV | BUTTON_REPEAT: | ||
446 | #ifdef LIST_RC_PREV | 459 | #ifdef LIST_RC_PREV |
447 | case LIST_RC_PREV: | 460 | case LIST_RC_PREV: |
461 | #endif | ||
462 | gui_synclist_limit_scroll(lists, false); | ||
463 | |||
464 | case LIST_PREV | BUTTON_REPEAT: | ||
465 | #ifdef LIST_RC_PREV | ||
448 | case LIST_RC_PREV | BUTTON_REPEAT: | 466 | case LIST_RC_PREV | BUTTON_REPEAT: |
449 | #endif | 467 | #endif |
450 | gui_synclist_select_previous(lists); | 468 | gui_synclist_select_previous(lists); |
@@ -452,9 +470,14 @@ bool gui_synclist_do_button(struct gui_synclist * lists, unsigned button) | |||
452 | return true; | 470 | return true; |
453 | 471 | ||
454 | case LIST_NEXT: | 472 | case LIST_NEXT: |
455 | case LIST_NEXT | BUTTON_REPEAT: | ||
456 | #ifdef LIST_RC_NEXT | 473 | #ifdef LIST_RC_NEXT |
457 | case LIST_RC_NEXT: | 474 | case LIST_RC_NEXT: |
475 | #endif | ||
476 | gui_synclist_limit_scroll(lists, false); | ||
477 | |||
478 | case LIST_NEXT | BUTTON_REPEAT: | ||
479 | #ifdef LIST_RC_NEXT | ||
480 | |||
458 | case LIST_RC_NEXT | BUTTON_REPEAT: | 481 | case LIST_RC_NEXT | BUTTON_REPEAT: |
459 | #endif | 482 | #endif |
460 | gui_synclist_select_next(lists); | 483 | gui_synclist_select_next(lists); |
@@ -465,6 +488,7 @@ bool gui_synclist_do_button(struct gui_synclist * lists, unsigned button) | |||
465 | * have the same number of lines*/ | 488 | * have the same number of lines*/ |
466 | #ifdef LIST_PGUP | 489 | #ifdef LIST_PGUP |
467 | case LIST_PGUP: | 490 | case LIST_PGUP: |
491 | gui_synclist_limit_scroll(lists, false); | ||
468 | case LIST_PGUP | BUTTON_REPEAT: | 492 | case LIST_PGUP | BUTTON_REPEAT: |
469 | gui_synclist_select_previous_page(lists, SCREEN_MAIN); | 493 | gui_synclist_select_previous_page(lists, SCREEN_MAIN); |
470 | gui_synclist_draw(lists); | 494 | gui_synclist_draw(lists); |
@@ -473,6 +497,7 @@ bool gui_synclist_do_button(struct gui_synclist * lists, unsigned button) | |||
473 | 497 | ||
474 | #ifdef LIST_RC_PGUP | 498 | #ifdef LIST_RC_PGUP |
475 | case LIST_RC_PGUP: | 499 | case LIST_RC_PGUP: |
500 | gui_synclist_limit_scroll(lists, false); | ||
476 | case LIST_RC_PGUP | BUTTON_REPEAT: | 501 | case LIST_RC_PGUP | BUTTON_REPEAT: |
477 | gui_synclist_select_previous_page(lists, SCREEN_REMOTE); | 502 | gui_synclist_select_previous_page(lists, SCREEN_REMOTE); |
478 | gui_synclist_draw(lists); | 503 | gui_synclist_draw(lists); |
@@ -481,6 +506,7 @@ bool gui_synclist_do_button(struct gui_synclist * lists, unsigned button) | |||
481 | 506 | ||
482 | #ifdef LIST_PGDN | 507 | #ifdef LIST_PGDN |
483 | case LIST_PGDN: | 508 | case LIST_PGDN: |
509 | gui_synclist_limit_scroll(lists, false); | ||
484 | case LIST_PGDN | BUTTON_REPEAT: | 510 | case LIST_PGDN | BUTTON_REPEAT: |
485 | gui_synclist_select_next_page(lists, SCREEN_MAIN); | 511 | gui_synclist_select_next_page(lists, SCREEN_MAIN); |
486 | gui_synclist_draw(lists); | 512 | gui_synclist_draw(lists); |
@@ -489,6 +515,7 @@ bool gui_synclist_do_button(struct gui_synclist * lists, unsigned button) | |||
489 | 515 | ||
490 | #ifdef LIST_RC_PGDN | 516 | #ifdef LIST_RC_PGDN |
491 | case LIST_RC_PGDN: | 517 | case LIST_RC_PGDN: |
518 | gui_synclist_limit_scroll(lists, false); | ||
492 | case LIST_RC_PGDN | BUTTON_REPEAT: | 519 | case LIST_RC_PGDN | BUTTON_REPEAT: |
493 | gui_synclist_select_next_page(lists, SCREEN_REMOTE); | 520 | gui_synclist_select_next_page(lists, SCREEN_REMOTE); |
494 | gui_synclist_draw(lists); | 521 | gui_synclist_draw(lists); |