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 ****************************************************************************/
32 #include "appevents.h"
34 #include "screen_access.h"
36 #include "scrollbar.h"
42 #include "appevents.h"
44 #ifdef HAVE_LCD_CHARCELLS
45 #define SCROLL_LIMIT 1
47 #define SCROLL_LIMIT (nb_lines<3?1:2)
50 /* The minimum number of pending button events in queue before starting
51 * to limit list drawing interval.
53 #define FRAMEDROP_TRIGGER 6
55 #ifdef HAVE_LCD_BITMAP
56 static int offset_step
= 16; /* pixels per screen scroll step */
57 /* should lines scroll out of the screen */
58 static bool offset_out_of_view
= false;
61 static void gui_list_select_at_offset(struct gui_synclist
* gui_list
,
63 void list_draw(struct screen
*display
, struct gui_synclist
*list
);
65 #ifdef HAVE_LCD_BITMAP
66 static int list_need_reinit
= false;
67 static struct viewport parent
[NB_SCREENS
];
69 static void list_force_reinit(void *param
)
72 list_need_reinit
= true;
77 add_event(GUI_EVENT_THEME_CHANGED
, false, list_force_reinit
);
80 static void list_init_viewports(struct gui_synclist
*list
)
87 parent_used
= (*list
->parent
!= &parent
[SCREEN_MAIN
]);
93 list
->parent
[i
] = &parent
[i
];
94 viewport_set_defaults(&parent
[i
], i
);
96 if (screens
[i
].has_buttonbar
&& !viewport_ui_vp_get_state(i
))
97 list
->parent
[i
]->height
-= BUTTONBAR_HEIGHT
;
101 list_need_reinit
= false;
104 #define list_init_viewports(a)
107 #ifdef HAVE_LCD_BITMAP
108 bool list_display_title(struct gui_synclist
*list
, enum screen_type screen
)
110 return list
->title
!= NULL
&&
111 viewport_get_nb_lines(list
->parent
[screen
])>2;
114 static struct viewport parent
[NB_SCREENS
] =
124 #define list_display_title(l, i) false
128 * Initializes a scrolling list
129 * - gui_list : the list structure to initialize
130 * - callback_get_item_name : pointer to a function that associates a label
131 * to a given item number
132 * - data : extra data passed to the list callback
135 * - parent : the parent viewports to use. NULL means the full screen minus
136 * statusbar if enabled. NOTE: new screens should NOT set this to NULL.
138 void gui_synclist_init(struct gui_synclist
* gui_list
,
139 list_get_name callback_get_item_name
,
142 int selected_size
, struct viewport list_parent
[NB_SCREENS
]
146 gui_list
->callback_get_item_icon
= NULL
;
147 gui_list
->callback_get_item_name
= callback_get_item_name
;
148 gui_list
->callback_speak_item
= NULL
;
149 gui_list
->nb_items
= 0;
150 gui_list
->selected_item
= 0;
153 gui_list
->start_item
[i
] = 0;
154 gui_list
->last_displayed_start_item
[i
] = -1 ;
155 #ifdef HAVE_LCD_BITMAP
156 gui_list
->offset_position
[i
] = 0;
159 gui_list
->parent
[i
] = &list_parent
[i
];
161 gui_list
->parent
[i
] = &parent
[i
];
163 list_init_viewports(gui_list
);
164 gui_list
->limit_scroll
= false;
166 gui_list
->scroll_all
=scroll_all
;
167 gui_list
->selected_size
=selected_size
;
168 gui_list
->title
= NULL
;
169 gui_list
->title_width
= 0;
170 gui_list
->title_icon
= Icon_NOICON
;
172 gui_list
->scheduled_talk_tick
= gui_list
->last_talked_tick
= 0;
173 gui_list
->show_selection_marker
= true;
174 gui_list
->last_displayed_selected_item
= -1 ;
176 #ifdef HAVE_LCD_COLOR
177 gui_list
->title_color
= -1;
178 gui_list
->callback_get_item_color
= NULL
;
182 /* this toggles the selection bar or cursor */
183 void gui_synclist_hide_selection_marker(struct gui_synclist
* lists
, bool hide
)
185 lists
->show_selection_marker
= !hide
;
189 #ifdef HAVE_LCD_BITMAP
190 int gui_list_get_item_offset(struct gui_synclist
* gui_list
,
193 struct screen
* display
,
198 if (offset_out_of_view
)
200 item_offset
= gui_list
->offset_position
[display
->screen_type
];
204 /* if text is smaller then view */
205 if (item_width
<= vp
->width
- text_pos
)
211 /* if text got out of view */
212 if (gui_list
->offset_position
[display
->screen_type
] >
213 item_width
- (vp
->width
- text_pos
))
214 item_offset
= item_width
- (vp
->width
- text_pos
);
216 item_offset
= gui_list
->offset_position
[display
->screen_type
];
224 * Force a full screen update.
227 void gui_synclist_draw(struct gui_synclist
*gui_list
)
230 #ifdef HAVE_LCD_BITMAP
231 if (list_need_reinit
)
233 list_init_viewports(gui_list
);
234 gui_synclist_select_item(gui_list
, gui_list
->selected_item
);
239 list_draw(&screens
[i
], gui_list
);
243 /* sets up the list so the selection is shown correctly on the screen */
244 static void gui_list_put_selection_on_screen(struct gui_synclist
* gui_list
,
245 enum screen_type screen
)
248 int difference
= gui_list
->selected_item
- gui_list
->start_item
[screen
];
249 struct viewport vp
= *gui_list
->parent
[screen
];
250 #ifdef HAVE_LCD_BITMAP
251 if (list_display_title(gui_list
, screen
))
252 vp
.height
-= font_get(gui_list
->parent
[screen
]->font
)->height
;
254 nb_lines
= viewport_get_nb_lines(&vp
);
256 /* edge case,, selected last item */
257 if (gui_list
->selected_item
== gui_list
->nb_items
-1)
259 gui_list
->start_item
[screen
] = MAX(0, gui_list
->nb_items
- nb_lines
);
261 /* selected first item */
262 else if (gui_list
->selected_item
== 0)
264 gui_list
->start_item
[screen
] = 0;
266 else if (difference
< SCROLL_LIMIT
) /* list moved up */
268 if (global_settings
.scroll_paginated
)
270 if (gui_list
->start_item
[screen
] > gui_list
->selected_item
)
272 gui_list
->start_item
[screen
] = (gui_list
->selected_item
/nb_lines
)
275 if (gui_list
->nb_items
<= nb_lines
)
276 gui_list
->start_item
[screen
] = 0;
280 int top_of_screen
= gui_list
->selected_item
- SCROLL_LIMIT
+ 1;
281 int temp
= MIN(top_of_screen
, gui_list
->nb_items
- nb_lines
);
282 gui_list
->start_item
[screen
] = MAX(0, temp
);
285 else if (difference
> nb_lines
- SCROLL_LIMIT
) /* list moved down */
287 int bottom
= gui_list
->nb_items
- nb_lines
;
288 /* always move the screen if selection isnt "visible" */
289 if (gui_list
->show_selection_marker
== false)
293 gui_list
->start_item
[screen
] = MIN(bottom
, gui_list
->start_item
[screen
] +
294 2*gui_list
->selected_size
);
296 else if (global_settings
.scroll_paginated
)
298 if (gui_list
->start_item
[screen
] + nb_lines
<= gui_list
->selected_item
)
299 gui_list
->start_item
[screen
] = MIN(bottom
, gui_list
->selected_item
);
303 int top_of_screen
= gui_list
->selected_item
+ SCROLL_LIMIT
- nb_lines
;
304 int temp
= MAX(0, top_of_screen
);
305 gui_list
->start_item
[screen
] = MIN(bottom
, temp
);
310 * Selects an item in the list
311 * - gui_list : the list structure
312 * - item_number : the number of the item which will be selected
314 void gui_synclist_select_item(struct gui_synclist
* gui_list
, int item_number
)
317 if( item_number
> gui_list
->nb_items
-1 || item_number
< 0 )
319 gui_list
->selected_item
= item_number
;
321 gui_list_put_selection_on_screen(gui_list
, i
);
324 static void gui_list_select_at_offset(struct gui_synclist
* gui_list
,
328 if (gui_list
->selected_size
> 1)
330 offset
*= gui_list
->selected_size
;
331 /* always select the first item of multi-line lists */
332 offset
-= offset
%gui_list
->selected_size
;
334 new_selection
= gui_list
->selected_item
+ offset
;
335 if (new_selection
>= gui_list
->nb_items
)
337 gui_list
->selected_item
= gui_list
->limit_scroll
?
338 gui_list
->nb_items
- gui_list
->selected_size
: 0;
340 else if (new_selection
< 0)
342 gui_list
->selected_item
= gui_list
->limit_scroll
?
343 0 : gui_list
->nb_items
- gui_list
->selected_size
;
345 else if (gui_list
->show_selection_marker
== false)
347 int i
, nb_lines
, screen_top
;
350 struct viewport vp
= *gui_list
->parent
[i
];
351 #ifdef HAVE_LCD_BITMAP
352 if (list_display_title(gui_list
, i
))
353 vp
.height
-= font_get(gui_list
->parent
[i
]->font
)->height
;
355 nb_lines
= viewport_get_nb_lines(&vp
);
358 screen_top
= gui_list
->nb_items
-nb_lines
;
361 gui_list
->start_item
[i
] = MIN(screen_top
, gui_list
->start_item
[i
] +
362 gui_list
->selected_size
);
363 gui_list
->selected_item
= gui_list
->start_item
[i
];
367 gui_list
->start_item
[i
] = MAX(0, gui_list
->start_item
[i
] -
368 gui_list
->selected_size
);
369 gui_list
->selected_item
= gui_list
->start_item
[i
] + nb_lines
;
374 else gui_list
->selected_item
+= offset
;
375 gui_synclist_select_item(gui_list
, gui_list
->selected_item
);
379 * Adds an item to the list (the callback will be asked for one more item)
380 * - gui_list : the list structure
382 void gui_synclist_add_item(struct gui_synclist
* gui_list
)
384 gui_list
->nb_items
++;
385 /* if only one item in the list, select it */
386 if(gui_list
->nb_items
== 1)
387 gui_list
->selected_item
= 0;
391 * Removes an item to the list (the callback will be asked for one less item)
392 * - gui_list : the list structure
394 void gui_synclist_del_item(struct gui_synclist
* gui_list
)
396 if(gui_list
->nb_items
> 0)
398 if (gui_list
->selected_item
== gui_list
->nb_items
-1)
399 gui_list
->selected_item
--;
400 gui_list
->nb_items
--;
401 gui_synclist_select_item(gui_list
, gui_list
->selected_item
);
405 #ifdef HAVE_LCD_BITMAP
406 void gui_list_screen_scroll_step(int ofs
)
411 void gui_list_screen_scroll_out_of_view(bool enable
)
413 offset_out_of_view
= enable
;
415 #endif /* HAVE_LCD_BITMAP */
418 * Set the title and title icon of the list. Setting title to NULL disables
419 * both the title and icon. Use NOICON if there is no icon.
421 void gui_synclist_set_title(struct gui_synclist
* gui_list
,
422 char * title
, enum themable_icons icon
)
424 gui_list
->title
= title
;
425 gui_list
->title_icon
= icon
;
427 #ifdef HAVE_LCD_BITMAP
430 screens
[i
].getstringsize(title
, &gui_list
->title_width
, NULL
);
432 gui_list
->title_width
= strlen(title
);
435 gui_list
->title_width
= 0;
440 void gui_synclist_set_nb_items(struct gui_synclist
* lists
, int nb_items
)
442 #ifdef HAVE_LCD_BITMAP
445 lists
->nb_items
= nb_items
;
446 #ifdef HAVE_LCD_BITMAP
449 lists
->offset_position
[i
] = 0;
453 int gui_synclist_get_nb_items(struct gui_synclist
* lists
)
455 return lists
->nb_items
;
457 int gui_synclist_get_sel_pos(struct gui_synclist
* lists
)
459 return lists
->selected_item
;
461 void gui_synclist_set_icon_callback(struct gui_synclist
* lists
,
462 list_get_icon icon_callback
)
464 lists
->callback_get_item_icon
= icon_callback
;
467 void gui_synclist_set_voice_callback(struct gui_synclist
* lists
,
468 list_speak_item voice_callback
)
470 lists
->callback_speak_item
= voice_callback
;
473 #ifdef HAVE_LCD_COLOR
474 void gui_synclist_set_color_callback(struct gui_synclist
* lists
,
475 list_get_color color_callback
)
477 lists
->callback_get_item_color
= color_callback
;
481 static void gui_synclist_select_next_page(struct gui_synclist
* lists
,
482 enum screen_type screen
)
484 int nb_lines
= viewport_get_nb_lines(lists
->parent
[screen
]);
485 #ifdef HAVE_LCD_BITMAP
486 if(list_display_title(lists
, screen
))
489 gui_list_select_at_offset(lists
, nb_lines
);
492 static void gui_synclist_select_previous_page(struct gui_synclist
* lists
,
493 enum screen_type screen
)
495 int nb_lines
= viewport_get_nb_lines(lists
->parent
[screen
]);
496 #ifdef HAVE_LCD_BITMAP
497 if(list_display_title(lists
, screen
))
500 gui_list_select_at_offset(lists
, -nb_lines
);
503 void gui_synclist_limit_scroll(struct gui_synclist
* lists
, bool scroll
)
505 lists
->limit_scroll
= scroll
;
508 #ifdef HAVE_LCD_BITMAP
510 * Makes all the item in the list scroll by one step to the right.
511 * Should stop increasing the value when reaching the widest item value
514 static void gui_synclist_scroll_right(struct gui_synclist
* lists
)
519 /* FIXME: This is a fake right boundry limiter. there should be some
520 * callback function to find the longest item on the list in pixels,
521 * to stop the list from scrolling past that point */
522 lists
->offset_position
[i
]+=offset_step
;
523 if (lists
->offset_position
[i
] > 1000)
524 lists
->offset_position
[i
] = 1000;
529 * Makes all the item in the list scroll by one step to the left.
530 * stops at starting position.
532 static void gui_synclist_scroll_left(struct gui_synclist
* lists
)
537 lists
->offset_position
[i
]-=offset_step
;
538 if (lists
->offset_position
[i
] < 0)
539 lists
->offset_position
[i
] = 0;
542 #endif /* HAVE_LCD_BITMAP */
544 static void _gui_synclist_speak_item(struct gui_synclist
*lists
, bool repeating
)
546 list_speak_item
*cb
= lists
->callback_speak_item
;
547 if(cb
&& gui_synclist_get_nb_items(lists
) != 0)
549 int sel
= gui_synclist_get_sel_pos(lists
);
551 /* If we got a repeating key action, or we have just very
552 recently started talking, then we want to stay silent for a
553 while until things settle. Likewise if we already had a
554 pending scheduled announcement not yet due: we need to
557 || (lists
->scheduled_talk_tick
558 && TIME_BEFORE(current_tick
, lists
->scheduled_talk_tick
))
559 || (lists
->last_talked_tick
560 && TIME_BEFORE(current_tick
, lists
->last_talked_tick
+HZ
/4)))
562 lists
->scheduled_talk_tick
= current_tick
+HZ
/4;
565 lists
->scheduled_talk_tick
= 0; /* work done */
566 cb(sel
, lists
->data
);
567 lists
->last_talked_tick
= current_tick
;
571 void gui_synclist_speak_item(struct gui_synclist
* lists
)
572 /* The list user should call this to speak the first item on entering
573 the list, and whenever the list is updated. */
575 if(gui_synclist_get_nb_items(lists
) == 0 && global_settings
.talk_menu
)
576 talk_id(VOICE_EMPTY_LIST
, true);
577 else _gui_synclist_speak_item(lists
, false);
580 bool gui_synclist_do_button(struct gui_synclist
* lists
,
581 int *actionptr
, enum list_wrap wrap
)
583 int action
= *actionptr
;
584 #ifdef HAVE_LCD_BITMAP
585 static bool scrolling_left
= false;
588 #ifdef HAVE_WHEEL_ACCELERATION
589 int next_item_modifier
= button_apply_acceleration(get_action_data());
591 static int next_item_modifier
= 1;
592 static int last_accel_tick
= 0;
594 if (global_settings
.list_accel_start_delay
)
596 int start_delay
= global_settings
.list_accel_start_delay
* (HZ
/2);
597 int accel_wait
= global_settings
.list_accel_wait
* HZ
/2;
599 if (get_action_statuscode(NULL
)&ACTION_REPEAT
)
601 if (!last_accel_tick
)
602 last_accel_tick
= current_tick
+ start_delay
;
603 else if (current_tick
>=
604 last_accel_tick
+ accel_wait
)
606 last_accel_tick
= current_tick
;
607 next_item_modifier
++;
610 else if (last_accel_tick
)
612 next_item_modifier
= 1;
618 #if defined(HAVE_TOUCHSCREEN)
619 if (action
== ACTION_TOUCHSCREEN
)
620 action
= *actionptr
= gui_synclist_do_touchscreen(lists
);
626 gui_synclist_limit_scroll(lists
, false);
629 gui_synclist_limit_scroll(lists
, true);
631 case LIST_WRAP_UNLESS_HELD
:
632 if (action
== ACTION_STD_PREVREPEAT
||
633 action
== ACTION_STD_NEXTREPEAT
||
634 action
== ACTION_LISTTREE_PGUP
||
635 action
== ACTION_LISTTREE_PGDOWN
)
636 gui_synclist_limit_scroll(lists
, true);
637 else gui_synclist_limit_scroll(lists
, false);
644 gui_synclist_draw(lists
);
647 #ifdef HAVE_VOLUME_IN_LIST
648 case ACTION_LIST_VOLUP
:
649 global_settings
.volume
+= 2;
650 /* up two because the falthrough brings it down one */
651 case ACTION_LIST_VOLDOWN
:
652 global_settings
.volume
--;
656 case ACTION_STD_PREV
:
657 case ACTION_STD_PREVREPEAT
:
658 gui_list_select_at_offset(lists
, -next_item_modifier
);
659 #ifndef HAVE_WHEEL_ACCELERATION
660 if (button_queue_count() < FRAMEDROP_TRIGGER
)
662 gui_synclist_draw(lists
);
663 _gui_synclist_speak_item(lists
,
664 action
== ACTION_STD_PREVREPEAT
665 || next_item_modifier
>1);
667 *actionptr
= ACTION_STD_PREV
;
670 case ACTION_STD_NEXT
:
671 case ACTION_STD_NEXTREPEAT
:
672 gui_list_select_at_offset(lists
, next_item_modifier
);
673 #ifndef HAVE_WHEEL_ACCELERATION
674 if (button_queue_count() < FRAMEDROP_TRIGGER
)
676 gui_synclist_draw(lists
);
677 _gui_synclist_speak_item(lists
,
678 action
== ACTION_STD_NEXTREPEAT
679 || next_item_modifier
>1);
681 *actionptr
= ACTION_STD_NEXT
;
684 #ifdef HAVE_LCD_BITMAP
685 case ACTION_TREE_PGRIGHT
:
686 gui_synclist_scroll_right(lists
);
687 gui_synclist_draw(lists
);
689 case ACTION_TREE_ROOT_INIT
:
690 /* After this button press ACTION_TREE_PGLEFT is allowed
691 to skip to root. ACTION_TREE_ROOT_INIT must be defined in the
692 keymaps as a repeated button press (the same as the repeated
693 ACTION_TREE_PGLEFT) with the pre condition being the non-repeated
695 if (lists
->offset_position
[0] == 0)
697 scrolling_left
= false;
698 *actionptr
= ACTION_STD_CANCEL
;
701 *actionptr
= ACTION_TREE_PGLEFT
;
702 case ACTION_TREE_PGLEFT
:
703 if(!scrolling_left
&& (lists
->offset_position
[0] == 0))
705 *actionptr
= ACTION_STD_CANCEL
;
708 gui_synclist_scroll_left(lists
);
709 gui_synclist_draw(lists
);
710 scrolling_left
= true; /* stop ACTION_TREE_PAGE_LEFT
714 /* for pgup / pgdown, we are obliged to have a different behaviour depending
715 * on the screen for which the user pressed the key since for example, remote
716 * and main screen doesn't have the same number of lines */
717 case ACTION_LISTTREE_PGUP
:
720 #ifdef HAVE_REMOTE_LCD
721 get_action_statuscode(NULL
)&ACTION_REMOTE
?
725 gui_synclist_select_previous_page(lists
, screen
);
726 gui_synclist_draw(lists
);
727 _gui_synclist_speak_item(lists
, false);
729 *actionptr
= ACTION_STD_NEXT
;
733 case ACTION_LISTTREE_PGDOWN
:
736 #ifdef HAVE_REMOTE_LCD
737 get_action_statuscode(NULL
)&ACTION_REMOTE
?
741 gui_synclist_select_next_page(lists
, screen
);
742 gui_synclist_draw(lists
);
743 _gui_synclist_speak_item(lists
, false);
745 *actionptr
= ACTION_STD_PREV
;
749 if(lists
->scheduled_talk_tick
750 && TIME_AFTER(current_tick
, lists
->scheduled_talk_tick
))
751 /* scheduled postponed item announcement is due */
752 _gui_synclist_speak_item(lists
, false);
756 int list_do_action_timeout(struct gui_synclist
*lists
, int timeout
)
757 /* Returns the lowest of timeout or the delay until a postponed
758 scheduled announcement is due (if any). */
760 if(lists
->scheduled_talk_tick
)
762 long delay
= lists
->scheduled_talk_tick
-current_tick
+1;
763 /* +1 because the trigger condition uses TIME_AFTER(), which
764 is implemented as strictly greater than. */
767 if(timeout
> delay
|| timeout
== TIMEOUT_BLOCK
)
773 bool list_do_action(int context
, int timeout
,
774 struct gui_synclist
*lists
, int *action
,
776 /* Combines the get_action() (with possibly overridden timeout) and
777 gui_synclist_do_button() calls. Returns the list action from
778 do_button, and places the action from get_action in *action. */
780 timeout
= list_do_action_timeout(lists
, timeout
);
781 *action
= get_action(context
, timeout
);
782 return gui_synclist_do_button(lists
, action
, wrap
);
785 bool gui_synclist_item_is_onscreen(struct gui_synclist
*lists
,
786 enum screen_type screen
, int item
)
788 struct viewport vp
= *lists
->parent
[screen
];
789 #ifdef HAVE_LCD_BITMAP
790 if (list_display_title(lists
, screen
))
791 vp
.height
-= font_get(lists
->parent
[screen
]->font
)->height
;
793 return item
<= (lists
->start_item
[screen
] + viewport_get_nb_lines(&vp
));
796 /* Simple use list implementation */
797 static int simplelist_line_count
= 0;
798 static char simplelist_text
[SIMPLELIST_MAX_LINES
][SIMPLELIST_MAX_LINELENGTH
];
799 /* set the amount of lines shown in the list */
800 void simplelist_set_line_count(int lines
)
803 simplelist_line_count
= 0;
804 else if (lines
>= SIMPLELIST_MAX_LINES
)
805 simplelist_line_count
= SIMPLELIST_MAX_LINES
;
807 simplelist_line_count
= lines
;
809 /* get the current amount of lines shown */
810 int simplelist_get_line_count(void)
812 return simplelist_line_count
;
814 /* add/edit a line in the list.
815 if line_number > number of lines shown it adds the line, else it edits the line */
816 void simplelist_addline(int line_number
, const char *fmt
, ...)
820 if (line_number
> simplelist_line_count
)
822 if (simplelist_line_count
< SIMPLELIST_MAX_LINES
)
823 line_number
= simplelist_line_count
++;
828 vsnprintf(simplelist_text
[line_number
], SIMPLELIST_MAX_LINELENGTH
, fmt
, ap
);
832 static const char* simplelist_static_getname(int item
,
837 (void)data
; (void)buffer
; (void)buffer_len
;
838 return simplelist_text
[item
];
841 bool simplelist_show_list(struct simplelist_info
*info
)
843 struct gui_synclist lists
;
844 int action
, old_line_count
= simplelist_line_count
;
845 int oldbars
= viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
846 const char* (*getname
)(int item
, void * data
, char *buffer
, size_t buffer_len
);
847 int wrap
= LIST_WRAP_UNLESS_HELD
;
849 getname
= info
->get_name
;
851 getname
= simplelist_static_getname
;
852 gui_synclist_init(&lists
, getname
, info
->callback_data
,
853 info
->scroll_all
, info
->selection_size
, NULL
);
856 gui_synclist_set_title(&lists
, info
->title
, NOICON
);
858 gui_synclist_set_icon_callback(&lists
, info
->get_icon
);
860 gui_synclist_set_voice_callback(&lists
, info
->get_talk
);
862 if (info
->hide_selection
)
864 gui_synclist_hide_selection_marker(&lists
, true);
865 wrap
= LIST_WRAP_OFF
;
868 if (info
->action_callback
)
869 info
->action_callback(ACTION_REDRAW
, &lists
);
871 if (info
->get_name
== NULL
)
872 gui_synclist_set_nb_items(&lists
, simplelist_line_count
*info
->selection_size
);
874 gui_synclist_set_nb_items(&lists
, info
->count
*info
->selection_size
);
876 gui_synclist_select_item(&lists
, info
->selection
);
878 gui_synclist_draw(&lists
);
879 gui_synclist_speak_item(&lists
);
883 list_do_action(CONTEXT_STD
, info
->timeout
,
884 &lists
, &action
, wrap
);
886 /* We must yield in this case or no other thread can run */
887 if (info
->timeout
== TIMEOUT_NOBLOCK
)
890 if (info
->action_callback
)
892 bool stdok
= action
==ACTION_STD_OK
;
893 action
= info
->action_callback(action
, &lists
);
894 if (stdok
&& action
== ACTION_STD_CANCEL
)
896 /* callback asked us to exit */
897 info
->selection
= gui_synclist_get_sel_pos(&lists
);
901 if (info
->get_name
== NULL
)
902 gui_synclist_set_nb_items(&lists
,
903 simplelist_line_count
*info
->selection_size
);
905 if (action
== ACTION_STD_CANCEL
)
907 info
->selection
= -1;
910 else if ((action
== ACTION_REDRAW
) ||
911 (old_line_count
!= simplelist_line_count
))
913 if (info
->get_name
== NULL
)
915 gui_synclist_set_nb_items(&lists
,
916 simplelist_line_count
*info
->selection_size
);
918 gui_synclist_draw(&lists
);
919 old_line_count
= simplelist_line_count
;
921 else if(default_event_handler(action
) == SYS_USB_CONNECTED
)
925 viewportmanager_set_statusbar(oldbars
);
929 void simplelist_info_init(struct simplelist_info
*info
, char* title
,
930 int count
, void* data
)
934 info
->selection_size
= 1;
935 info
->hide_selection
= false;
936 info
->scroll_all
= false;
937 info
->timeout
= HZ
/10;
939 info
->action_callback
= NULL
;
940 info
->get_icon
= NULL
;
941 info
->get_name
= NULL
;
942 info
->get_talk
= NULL
;
943 info
->callback_data
= data
;