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 ****************************************************************************/
33 #include "screen_access.h"
35 #include "scrollbar.h"
42 #ifdef HAVE_LCD_CHARCELLS
43 #define SCROLL_LIMIT 1
45 #define SCROLL_LIMIT (nb_lines<3?1:2)
48 /* The minimum number of pending button events in queue before starting
49 * to limit list drawing interval.
51 #define FRAMEDROP_TRIGGER 6
53 #ifdef HAVE_LCD_BITMAP
54 static int offset_step
= 16; /* pixels per screen scroll step */
55 /* should lines scroll out of the screen */
56 static bool offset_out_of_view
= false;
59 static void gui_list_select_at_offset(struct gui_synclist
* gui_list
,
61 void list_draw(struct screen
*display
, struct gui_synclist
*list
);
63 #ifdef HAVE_LCD_BITMAP
64 static void list_init_viewports(struct gui_synclist
*list
)
68 bool parent_used
= (*list
->parent
!= NULL
);
71 vp
= viewport_get_current_vp();
73 list
->parent
[i
] = &vp
[i
];
76 if (list
&& !parent_used
&& global_settings
.buttonbar
)
77 list
->parent
[0]->height
-= BUTTONBAR_HEIGHT
;
81 #define list_init_viewports(a)
84 #ifdef HAVE_LCD_BITMAP
85 bool list_display_title(struct gui_synclist
*list
, enum screen_type screen
)
87 return list
->title
!= NULL
&&
88 viewport_get_nb_lines(list
->parent
[screen
])>2;
91 static struct viewport parent
[NB_SCREENS
] =
101 #define list_display_title(l, i) false
105 * Initializes a scrolling list
106 * - gui_list : the list structure to initialize
107 * - callback_get_item_name : pointer to a function that associates a label
108 * to a given item number
109 * - data : extra data passed to the list callback
112 * - parent : the parent viewports to use. NULL means the full screen minus
113 * statusbar if enabled. NOTE: new screens should NOT set this to NULL.
115 void gui_synclist_init(struct gui_synclist
* gui_list
,
116 list_get_name callback_get_item_name
,
119 int selected_size
, struct viewport list_parent
[NB_SCREENS
]
123 gui_list
->callback_get_item_icon
= NULL
;
124 gui_list
->callback_get_item_name
= callback_get_item_name
;
125 gui_list
->callback_speak_item
= NULL
;
126 gui_list
->nb_items
= 0;
127 gui_list
->selected_item
= 0;
130 gui_list
->start_item
[i
] = 0;
131 gui_list
->last_displayed_start_item
[i
] = -1 ;
132 #ifdef HAVE_LCD_BITMAP
133 gui_list
->offset_position
[i
] = 0;
136 gui_list
->parent
[i
] = &list_parent
[i
];
138 gui_list
->parent
[i
] =
139 #ifdef HAVE_LCD_BITMAP
145 list_init_viewports(gui_list
);
146 gui_list
->limit_scroll
= false;
148 gui_list
->scroll_all
=scroll_all
;
149 gui_list
->selected_size
=selected_size
;
150 gui_list
->title
= NULL
;
151 gui_list
->title_width
= 0;
152 gui_list
->title_icon
= Icon_NOICON
;
154 gui_list
->scheduled_talk_tick
= gui_list
->last_talked_tick
= 0;
155 gui_list
->show_selection_marker
= true;
156 gui_list
->last_displayed_selected_item
= -1 ;
158 #ifdef HAVE_LCD_COLOR
159 gui_list
->title_color
= -1;
160 gui_list
->callback_get_item_color
= NULL
;
164 /* this toggles the selection bar or cursor */
165 void gui_synclist_hide_selection_marker(struct gui_synclist
* lists
, bool hide
)
167 lists
->show_selection_marker
= !hide
;
171 #ifdef HAVE_LCD_BITMAP
172 int gui_list_get_item_offset(struct gui_synclist
* gui_list
,
175 struct screen
* display
,
180 if (offset_out_of_view
)
182 item_offset
= gui_list
->offset_position
[display
->screen_type
];
186 /* if text is smaller then view */
187 if (item_width
<= vp
->width
- text_pos
)
193 /* if text got out of view */
194 if (gui_list
->offset_position
[display
->screen_type
] >
195 item_width
- (vp
->width
- text_pos
))
196 item_offset
= item_width
- (vp
->width
- text_pos
);
198 item_offset
= gui_list
->offset_position
[display
->screen_type
];
206 * Force a full screen update.
209 void gui_synclist_draw(struct gui_synclist
*gui_list
)
212 static struct gui_synclist
*last_list
= NULL
;
213 static int last_count
= -1;
214 #ifdef HAVE_BUTTONBAR
215 static bool last_buttonbar
= false;
218 #ifdef HAVE_BUTTONBAR
219 last_buttonbar
!= screens
[SCREEN_MAIN
].has_buttonbar
||
221 last_list
!= gui_list
||
222 gui_list
->nb_items
!= last_count
)
224 list_init_viewports(gui_list
);
225 gui_synclist_select_item(gui_list
, gui_list
->selected_item
);
227 #ifdef HAVE_BUTTONBAR
228 last_buttonbar
= screens
[SCREEN_MAIN
].has_buttonbar
;
230 last_count
= gui_list
->nb_items
;
231 last_list
= gui_list
;
234 list_draw(&screens
[i
], gui_list
);
238 /* sets up the list so the selection is shown correctly on the screen */
239 static void gui_list_put_selection_on_screen(struct gui_synclist
* gui_list
,
240 enum screen_type screen
)
243 int difference
= gui_list
->selected_item
- gui_list
->start_item
[screen
];
244 struct viewport vp
= *gui_list
->parent
[screen
];
245 #ifdef HAVE_LCD_BITMAP
246 if (list_display_title(gui_list
, screen
))
247 vp
.height
-= font_get(gui_list
->parent
[screen
]->font
)->height
;
249 nb_lines
= viewport_get_nb_lines(&vp
);
251 /* edge case,, selected last item */
252 if (gui_list
->selected_item
== gui_list
->nb_items
-1)
254 gui_list
->start_item
[screen
] = MAX(0, gui_list
->nb_items
- nb_lines
);
256 /* selected first item */
257 else if (gui_list
->selected_item
== 0)
259 gui_list
->start_item
[screen
] = 0;
261 else if (difference
< SCROLL_LIMIT
) /* list moved up */
263 if (global_settings
.scroll_paginated
)
265 if (gui_list
->start_item
[screen
] > gui_list
->selected_item
)
267 gui_list
->start_item
[screen
] = (gui_list
->selected_item
/nb_lines
)
270 if (gui_list
->nb_items
<= nb_lines
)
271 gui_list
->start_item
[screen
] = 0;
275 int top_of_screen
= gui_list
->selected_item
- SCROLL_LIMIT
+ 1;
276 int temp
= MIN(top_of_screen
, gui_list
->nb_items
- nb_lines
);
277 gui_list
->start_item
[screen
] = MAX(0, temp
);
280 else if (difference
> nb_lines
- SCROLL_LIMIT
) /* list moved down */
282 int bottom
= gui_list
->nb_items
- nb_lines
;
283 /* always move the screen if selection isnt "visible" */
284 if (gui_list
->show_selection_marker
== false)
288 gui_list
->start_item
[screen
] = MIN(bottom
, gui_list
->start_item
[screen
] +
289 2*gui_list
->selected_size
);
291 else if (global_settings
.scroll_paginated
)
293 if (gui_list
->start_item
[screen
] + nb_lines
<= gui_list
->selected_item
)
294 gui_list
->start_item
[screen
] = MIN(bottom
, gui_list
->selected_item
);
298 int top_of_screen
= gui_list
->selected_item
+ SCROLL_LIMIT
- nb_lines
;
299 int temp
= MAX(0, top_of_screen
);
300 gui_list
->start_item
[screen
] = MIN(bottom
, temp
);
305 * Selects an item in the list
306 * - gui_list : the list structure
307 * - item_number : the number of the item which will be selected
309 void gui_synclist_select_item(struct gui_synclist
* gui_list
, int item_number
)
312 if( item_number
> gui_list
->nb_items
-1 || item_number
< 0 )
314 gui_list
->selected_item
= item_number
;
316 gui_list_put_selection_on_screen(gui_list
, i
);
319 static void gui_list_select_at_offset(struct gui_synclist
* gui_list
,
323 if (gui_list
->selected_size
> 1)
325 offset
*= gui_list
->selected_size
;
326 /* always select the first item of multi-line lists */
327 offset
-= offset
%gui_list
->selected_size
;
329 new_selection
= gui_list
->selected_item
+ offset
;
330 if (new_selection
>= gui_list
->nb_items
)
332 gui_list
->selected_item
= gui_list
->limit_scroll
?
333 gui_list
->nb_items
- gui_list
->selected_size
: 0;
335 else if (new_selection
< 0)
337 gui_list
->selected_item
= gui_list
->limit_scroll
?
338 0 : gui_list
->nb_items
- gui_list
->selected_size
;
340 else if (gui_list
->show_selection_marker
== false)
342 int i
, nb_lines
, screen_top
;
345 struct viewport vp
= *gui_list
->parent
[i
];
346 #ifdef HAVE_LCD_BITMAP
347 if (list_display_title(gui_list
, i
))
348 vp
.height
-= font_get(gui_list
->parent
[i
]->font
)->height
;
350 nb_lines
= viewport_get_nb_lines(&vp
);
353 screen_top
= gui_list
->nb_items
-nb_lines
;
356 gui_list
->start_item
[i
] = MIN(screen_top
, gui_list
->start_item
[i
] +
357 gui_list
->selected_size
);
358 gui_list
->selected_item
= gui_list
->start_item
[i
];
362 gui_list
->start_item
[i
] = MAX(0, gui_list
->start_item
[i
] -
363 gui_list
->selected_size
);
364 gui_list
->selected_item
= gui_list
->start_item
[i
] + nb_lines
;
369 else gui_list
->selected_item
+= offset
;
370 gui_synclist_select_item(gui_list
, gui_list
->selected_item
);
374 * Adds an item to the list (the callback will be asked for one more item)
375 * - gui_list : the list structure
377 void gui_synclist_add_item(struct gui_synclist
* gui_list
)
379 gui_list
->nb_items
++;
380 /* if only one item in the list, select it */
381 if(gui_list
->nb_items
== 1)
382 gui_list
->selected_item
= 0;
386 * Removes an item to the list (the callback will be asked for one less item)
387 * - gui_list : the list structure
389 void gui_synclist_del_item(struct gui_synclist
* gui_list
)
391 if(gui_list
->nb_items
> 0)
393 if (gui_list
->selected_item
== gui_list
->nb_items
-1)
394 gui_list
->selected_item
--;
395 gui_list
->nb_items
--;
396 gui_synclist_select_item(gui_list
, gui_list
->selected_item
);
400 #ifdef HAVE_LCD_BITMAP
401 void gui_list_screen_scroll_step(int ofs
)
406 void gui_list_screen_scroll_out_of_view(bool enable
)
409 offset_out_of_view
= true;
411 offset_out_of_view
= false;
413 #endif /* HAVE_LCD_BITMAP */
416 * Set the title and title icon of the list. Setting title to NULL disables
417 * both the title and icon. Use NOICON if there is no icon.
419 void gui_synclist_set_title(struct gui_synclist
* gui_list
,
420 char * title
, enum themable_icons icon
)
422 gui_list
->title
= title
;
423 gui_list
->title_icon
= icon
;
425 #ifdef HAVE_LCD_BITMAP
428 screens
[i
].getstringsize(title
, &gui_list
->title_width
, NULL
);
430 gui_list
->title_width
= strlen(title
);
433 gui_list
->title_width
= 0;
438 void gui_synclist_set_nb_items(struct gui_synclist
* lists
, int nb_items
)
440 #ifdef HAVE_LCD_BITMAP
443 lists
->nb_items
= nb_items
;
444 #ifdef HAVE_LCD_BITMAP
447 lists
->offset_position
[i
] = 0;
451 int gui_synclist_get_nb_items(struct gui_synclist
* lists
)
453 return lists
->nb_items
;
455 int gui_synclist_get_sel_pos(struct gui_synclist
* lists
)
457 return lists
->selected_item
;
459 void gui_synclist_set_icon_callback(struct gui_synclist
* lists
,
460 list_get_icon icon_callback
)
462 lists
->callback_get_item_icon
= icon_callback
;
465 void gui_synclist_set_voice_callback(struct gui_synclist
* lists
,
466 list_speak_item voice_callback
)
468 lists
->callback_speak_item
= voice_callback
;
471 #ifdef HAVE_LCD_COLOR
472 void gui_synclist_set_color_callback(struct gui_synclist
* lists
,
473 list_get_color color_callback
)
475 lists
->callback_get_item_color
= color_callback
;
479 static void gui_synclist_select_next_page(struct gui_synclist
* lists
,
480 enum screen_type screen
)
482 int nb_lines
= viewport_get_nb_lines(lists
->parent
[screen
]);
483 #ifdef HAVE_LCD_BITMAP
484 if(list_display_title(lists
, screen
))
487 gui_list_select_at_offset(lists
, nb_lines
);
490 static void gui_synclist_select_previous_page(struct gui_synclist
* lists
,
491 enum screen_type screen
)
493 int nb_lines
= viewport_get_nb_lines(lists
->parent
[screen
]);
494 #ifdef HAVE_LCD_BITMAP
495 if(list_display_title(lists
, screen
))
498 gui_list_select_at_offset(lists
, -nb_lines
);
501 void gui_synclist_limit_scroll(struct gui_synclist
* lists
, bool scroll
)
503 lists
->limit_scroll
= scroll
;
506 #ifdef HAVE_LCD_BITMAP
508 * Makes all the item in the list scroll by one step to the right.
509 * Should stop increasing the value when reaching the widest item value
512 static void gui_synclist_scroll_right(struct gui_synclist
* lists
)
517 /* FIXME: This is a fake right boundry limiter. there should be some
518 * callback function to find the longest item on the list in pixels,
519 * to stop the list from scrolling past that point */
520 lists
->offset_position
[i
]+=offset_step
;
521 if (lists
->offset_position
[i
] > 1000)
522 lists
->offset_position
[i
] = 1000;
527 * Makes all the item in the list scroll by one step to the left.
528 * stops at starting position.
530 static void gui_synclist_scroll_left(struct gui_synclist
* lists
)
535 lists
->offset_position
[i
]-=offset_step
;
536 if (lists
->offset_position
[i
] < 0)
537 lists
->offset_position
[i
] = 0;
540 #endif /* HAVE_LCD_BITMAP */
542 static void _gui_synclist_speak_item(struct gui_synclist
*lists
, bool repeating
)
544 list_speak_item
*cb
= lists
->callback_speak_item
;
545 if(cb
&& gui_synclist_get_nb_items(lists
) != 0)
547 int sel
= gui_synclist_get_sel_pos(lists
);
549 /* If we got a repeating key action, or we have just very
550 recently started talking, then we want to stay silent for a
551 while until things settle. Likewise if we already had a
552 pending scheduled announcement not yet due: we need to
555 || (lists
->scheduled_talk_tick
556 && TIME_BEFORE(current_tick
, lists
->scheduled_talk_tick
))
557 || (lists
->last_talked_tick
558 && TIME_BEFORE(current_tick
, lists
->last_talked_tick
+HZ
/4)))
560 lists
->scheduled_talk_tick
= current_tick
+HZ
/4;
563 lists
->scheduled_talk_tick
= 0; /* work done */
564 cb(sel
, lists
->data
);
565 lists
->last_talked_tick
= current_tick
;
569 void gui_synclist_speak_item(struct gui_synclist
* lists
)
570 /* The list user should call this to speak the first item on entering
571 the list, and whenever the list is updated. */
573 if(gui_synclist_get_nb_items(lists
) == 0 && global_settings
.talk_menu
)
574 talk_id(VOICE_EMPTY_LIST
, true);
575 else _gui_synclist_speak_item(lists
, false);
578 bool gui_synclist_do_button(struct gui_synclist
* lists
,
579 int *actionptr
, enum list_wrap wrap
)
581 int action
= *actionptr
;
582 #ifdef HAVE_LCD_BITMAP
583 static bool scrolling_left
= false;
586 #ifdef HAVE_WHEEL_ACCELERATION
587 int next_item_modifier
= button_apply_acceleration(get_action_data());
589 static int next_item_modifier
= 1;
590 static int last_accel_tick
= 0;
592 if (global_settings
.list_accel_start_delay
)
594 int start_delay
= global_settings
.list_accel_start_delay
* (HZ
/2);
595 int accel_wait
= global_settings
.list_accel_wait
* HZ
/2;
597 if (get_action_statuscode(NULL
)&ACTION_REPEAT
)
599 if (!last_accel_tick
)
600 last_accel_tick
= current_tick
+ start_delay
;
601 else if (current_tick
>=
602 last_accel_tick
+ accel_wait
)
604 last_accel_tick
= current_tick
;
605 next_item_modifier
++;
608 else if (last_accel_tick
)
610 next_item_modifier
= 1;
616 #if defined(HAVE_TOUCHSCREEN)
617 if (action
== ACTION_TOUCHSCREEN
)
618 action
= *actionptr
= gui_synclist_do_touchscreen(lists
);
624 gui_synclist_limit_scroll(lists
, false);
627 gui_synclist_limit_scroll(lists
, true);
629 case LIST_WRAP_UNLESS_HELD
:
630 if (action
== ACTION_STD_PREVREPEAT
||
631 action
== ACTION_STD_NEXTREPEAT
||
632 action
== ACTION_LISTTREE_PGUP
||
633 action
== ACTION_LISTTREE_PGDOWN
)
634 gui_synclist_limit_scroll(lists
, true);
635 else gui_synclist_limit_scroll(lists
, false);
642 gui_synclist_draw(lists
);
645 #ifdef HAVE_VOLUME_IN_LIST
646 case ACTION_LIST_VOLUP
:
647 global_settings
.volume
+= 2;
648 /* up two because the falthrough brings it down one */
649 case ACTION_LIST_VOLDOWN
:
650 global_settings
.volume
--;
654 case ACTION_STD_PREV
:
655 case ACTION_STD_PREVREPEAT
:
656 gui_list_select_at_offset(lists
, -next_item_modifier
);
657 #ifndef HAVE_WHEEL_ACCELERATION
658 if (button_queue_count() < FRAMEDROP_TRIGGER
)
660 gui_synclist_draw(lists
);
661 _gui_synclist_speak_item(lists
,
662 action
== ACTION_STD_PREVREPEAT
663 || next_item_modifier
>1);
665 *actionptr
= ACTION_STD_PREV
;
668 case ACTION_STD_NEXT
:
669 case ACTION_STD_NEXTREPEAT
:
670 gui_list_select_at_offset(lists
, next_item_modifier
);
671 #ifndef HAVE_WHEEL_ACCELERATION
672 if (button_queue_count() < FRAMEDROP_TRIGGER
)
674 gui_synclist_draw(lists
);
675 _gui_synclist_speak_item(lists
,
676 action
== ACTION_STD_NEXTREPEAT
677 || next_item_modifier
>1);
679 *actionptr
= ACTION_STD_NEXT
;
682 #ifdef HAVE_LCD_BITMAP
683 case ACTION_TREE_PGRIGHT
:
684 gui_synclist_scroll_right(lists
);
685 gui_synclist_draw(lists
);
687 case ACTION_TREE_ROOT_INIT
:
688 /* After this button press ACTION_TREE_PGLEFT is allowed
689 to skip to root. ACTION_TREE_ROOT_INIT must be defined in the
690 keymaps as a repeated button press (the same as the repeated
691 ACTION_TREE_PGLEFT) with the pre condition being the non-repeated
693 if (lists
->offset_position
[0] == 0)
695 scrolling_left
= false;
696 *actionptr
= ACTION_STD_CANCEL
;
699 *actionptr
= ACTION_TREE_PGLEFT
;
700 case ACTION_TREE_PGLEFT
:
701 if(!scrolling_left
&& (lists
->offset_position
[0] == 0))
703 *actionptr
= ACTION_STD_CANCEL
;
706 gui_synclist_scroll_left(lists
);
707 gui_synclist_draw(lists
);
708 scrolling_left
= true; /* stop ACTION_TREE_PAGE_LEFT
712 /* for pgup / pgdown, we are obliged to have a different behaviour depending
713 * on the screen for which the user pressed the key since for example, remote
714 * and main screen doesn't have the same number of lines */
715 case ACTION_LISTTREE_PGUP
:
718 #ifdef HAVE_REMOTE_LCD
719 get_action_statuscode(NULL
)&ACTION_REMOTE
?
723 gui_synclist_select_previous_page(lists
, screen
);
724 gui_synclist_draw(lists
);
725 _gui_synclist_speak_item(lists
, false);
727 *actionptr
= ACTION_STD_NEXT
;
731 case ACTION_LISTTREE_PGDOWN
:
734 #ifdef HAVE_REMOTE_LCD
735 get_action_statuscode(NULL
)&ACTION_REMOTE
?
739 gui_synclist_select_next_page(lists
, screen
);
740 gui_synclist_draw(lists
);
741 _gui_synclist_speak_item(lists
, false);
743 *actionptr
= ACTION_STD_PREV
;
747 if(lists
->scheduled_talk_tick
748 && TIME_AFTER(current_tick
, lists
->scheduled_talk_tick
))
749 /* scheduled postponed item announcement is due */
750 _gui_synclist_speak_item(lists
, false);
754 int list_do_action_timeout(struct gui_synclist
*lists
, int timeout
)
755 /* Returns the lowest of timeout or the delay until a postponed
756 scheduled announcement is due (if any). */
758 if(lists
->scheduled_talk_tick
)
760 long delay
= lists
->scheduled_talk_tick
-current_tick
+1;
761 /* +1 because the trigger condition uses TIME_AFTER(), which
762 is implemented as strictly greater than. */
765 if(timeout
> delay
|| timeout
== TIMEOUT_BLOCK
)
771 bool list_do_action(int context
, int timeout
,
772 struct gui_synclist
*lists
, int *action
,
774 /* Combines the get_action() (with possibly overridden timeout) and
775 gui_synclist_do_button() calls. Returns the list action from
776 do_button, and places the action from get_action in *action. */
778 timeout
= list_do_action_timeout(lists
, timeout
);
779 *action
= get_action(context
, timeout
);
780 return gui_synclist_do_button(lists
, action
, wrap
);
783 bool gui_synclist_item_is_onscreen(struct gui_synclist
*lists
,
784 enum screen_type screen
, int item
)
786 struct viewport vp
= *lists
->parent
[screen
];
787 #ifdef HAVE_LCD_BITMAP
788 if (list_display_title(lists
, screen
))
789 vp
.height
-= font_get(lists
->parent
[screen
]->font
)->height
;
791 return item
<= (lists
->start_item
[screen
] + viewport_get_nb_lines(&vp
));
794 /* Simple use list implementation */
795 static int simplelist_line_count
= 0;
796 static char simplelist_text
[SIMPLELIST_MAX_LINES
][SIMPLELIST_MAX_LINELENGTH
];
797 /* set the amount of lines shown in the list */
798 void simplelist_set_line_count(int lines
)
801 simplelist_line_count
= 0;
802 else if (lines
>= SIMPLELIST_MAX_LINES
)
803 simplelist_line_count
= SIMPLELIST_MAX_LINES
;
805 simplelist_line_count
= lines
;
807 /* get the current amount of lines shown */
808 int simplelist_get_line_count(void)
810 return simplelist_line_count
;
812 /* add/edit a line in the list.
813 if line_number > number of lines shown it adds the line, else it edits the line */
814 void simplelist_addline(int line_number
, const char *fmt
, ...)
818 if (line_number
> simplelist_line_count
)
820 if (simplelist_line_count
< SIMPLELIST_MAX_LINES
)
821 line_number
= simplelist_line_count
++;
826 vsnprintf(simplelist_text
[line_number
], SIMPLELIST_MAX_LINELENGTH
, fmt
, ap
);
830 static const char* simplelist_static_getname(int item
,
835 (void)data
; (void)buffer
; (void)buffer_len
;
836 return simplelist_text
[item
];
839 bool simplelist_show_list(struct simplelist_info
*info
)
841 struct gui_synclist lists
;
842 int action
, old_line_count
= simplelist_line_count
;
843 int oldbars
= viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
844 const char* (*getname
)(int item
, void * data
, char *buffer
, size_t buffer_len
);
845 int wrap
= LIST_WRAP_UNLESS_HELD
;
847 getname
= info
->get_name
;
849 getname
= simplelist_static_getname
;
850 gui_synclist_init(&lists
, getname
, info
->callback_data
,
851 info
->scroll_all
, info
->selection_size
, NULL
);
854 gui_synclist_set_title(&lists
, info
->title
, NOICON
);
856 gui_synclist_set_icon_callback(&lists
, info
->get_icon
);
858 gui_synclist_set_voice_callback(&lists
, info
->get_talk
);
860 if (info
->hide_selection
)
862 gui_synclist_hide_selection_marker(&lists
, true);
863 wrap
= LIST_WRAP_OFF
;
866 if (info
->action_callback
)
867 info
->action_callback(ACTION_REDRAW
, &lists
);
869 if (info
->get_name
== NULL
)
870 gui_synclist_set_nb_items(&lists
, simplelist_line_count
*info
->selection_size
);
872 gui_synclist_set_nb_items(&lists
, info
->count
*info
->selection_size
);
874 gui_synclist_select_item(&lists
, info
->selection
);
876 gui_synclist_draw(&lists
);
877 gui_synclist_speak_item(&lists
);
881 list_do_action(CONTEXT_STD
, info
->timeout
,
882 &lists
, &action
, wrap
);
884 /* We must yield in this case or no other thread can run */
885 if (info
->timeout
== TIMEOUT_NOBLOCK
)
888 if (info
->action_callback
)
890 bool stdok
= action
==ACTION_STD_OK
;
891 action
= info
->action_callback(action
, &lists
);
892 if (stdok
&& action
== ACTION_STD_CANCEL
)
894 /* callback asked us to exit */
895 info
->selection
= gui_synclist_get_sel_pos(&lists
);
899 if (info
->get_name
== NULL
)
900 gui_synclist_set_nb_items(&lists
,
901 simplelist_line_count
*info
->selection_size
);
903 if (action
== ACTION_STD_CANCEL
)
905 info
->selection
= -1;
908 else if ((action
== ACTION_REDRAW
) ||
909 (old_line_count
!= simplelist_line_count
))
911 if (info
->get_name
== NULL
)
913 gui_synclist_set_nb_items(&lists
,
914 simplelist_line_count
*info
->selection_size
);
916 gui_synclist_draw(&lists
);
917 old_line_count
= simplelist_line_count
;
919 else if(default_event_handler(action
) == SYS_USB_CONNECTED
)
923 viewportmanager_set_statusbar(oldbars
);
927 void simplelist_info_init(struct simplelist_info
*info
, char* title
,
928 int count
, void* data
)
932 info
->selection_size
= 1;
933 info
->hide_selection
= false;
934 info
->scroll_all
= false;
935 info
->timeout
= HZ
/10;
937 info
->action_callback
= NULL
;
938 info
->get_icon
= NULL
;
939 info
->get_name
= NULL
;
940 info
->get_talk
= NULL
;
941 info
->callback_data
= data
;