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"
36 #include "statusbar.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;
60 static int force_list_reinit
= false;
62 static void gui_list_select_at_offset(struct gui_synclist
* gui_list
,
64 void list_draw(struct screen
*display
, struct gui_synclist
*list
);
66 #ifdef HAVE_LCD_BITMAP
67 static struct viewport parent
[NB_SCREENS
];
68 void list_init_viewports(struct gui_synclist
*list
)
75 if (!list
|| list
->parent
[i
] == vp
)
76 viewport_set_defaults(vp
, i
);
79 if (list
&& (list
->parent
[0] == &parent
[0]) && global_settings
.buttonbar
)
80 list
->parent
[0]->height
-= BUTTONBAR_HEIGHT
;
82 force_list_reinit
= false;
85 static struct viewport parent
[NB_SCREENS
] =
95 void list_init_viewports(struct gui_synclist
*list
)
98 force_list_reinit
= false;
102 #ifdef HAVE_LCD_BITMAP
103 bool list_display_title(struct gui_synclist
*list
, enum screen_type screen
)
105 return list
->title
!= NULL
&&
106 viewport_get_nb_lines(list
->parent
[screen
])>2;
109 #define list_display_title(l, i) false
113 * Initializes a scrolling list
114 * - gui_list : the list structure to initialize
115 * - callback_get_item_name : pointer to a function that associates a label
116 * to a given item number
117 * - data : extra data passed to the list callback
120 * - parent : the parent viewports to use. NULL means the full screen minus
121 * statusbar if enabled. NOTE: new screens should NOT set this to NULL.
123 void gui_synclist_init(struct gui_synclist
* gui_list
,
124 list_get_name callback_get_item_name
,
127 int selected_size
, struct viewport list_parent
[NB_SCREENS
]
131 gui_list
->callback_get_item_icon
= NULL
;
132 gui_list
->callback_get_item_name
= callback_get_item_name
;
133 gui_list
->callback_speak_item
= NULL
;
134 gui_list
->nb_items
= 0;
135 gui_list
->selected_item
= 0;
138 gui_list
->start_item
[i
] = 0;
139 gui_list
->last_displayed_start_item
[i
] = -1 ;
140 #ifdef HAVE_LCD_BITMAP
141 gui_list
->offset_position
[i
] = 0;
144 gui_list
->parent
[i
] = &list_parent
[i
];
147 gui_list
->parent
[i
] = &parent
[i
];
150 list_init_viewports(gui_list
);
151 gui_list
->limit_scroll
= false;
153 gui_list
->scroll_all
=scroll_all
;
154 gui_list
->selected_size
=selected_size
;
155 gui_list
->title
= NULL
;
156 gui_list
->title_width
= 0;
157 gui_list
->title_icon
= Icon_NOICON
;
159 gui_list
->scheduled_talk_tick
= gui_list
->last_talked_tick
= 0;
160 gui_list
->show_selection_marker
= true;
161 gui_list
->last_displayed_selected_item
= -1 ;
163 #ifdef HAVE_LCD_COLOR
164 gui_list
->title_color
= -1;
165 gui_list
->callback_get_item_color
= NULL
;
167 force_list_reinit
= true;
170 /* this toggles the selection bar or cursor */
171 void gui_synclist_hide_selection_marker(struct gui_synclist
* lists
, bool hide
)
173 lists
->show_selection_marker
= !hide
;
177 #ifdef HAVE_LCD_BITMAP
178 int gui_list_get_item_offset(struct gui_synclist
* gui_list
,
181 struct screen
* display
,
186 if (offset_out_of_view
)
188 item_offset
= gui_list
->offset_position
[display
->screen_type
];
192 /* if text is smaller then view */
193 if (item_width
<= vp
->width
- text_pos
)
199 /* if text got out of view */
200 if (gui_list
->offset_position
[display
->screen_type
] >
201 item_width
- (vp
->width
- text_pos
))
202 item_offset
= item_width
- (vp
->width
- text_pos
);
204 item_offset
= gui_list
->offset_position
[display
->screen_type
];
212 * Force a full screen update.
215 void gui_synclist_draw(struct gui_synclist
*gui_list
)
218 static struct gui_synclist
*last_list
= NULL
;
219 static int last_count
= -1;
220 #ifdef HAVE_BUTTONBAR
221 static bool last_buttonbar
= false;
223 if (force_list_reinit
||
224 #ifdef HAVE_BUTTONBAR
225 last_buttonbar
!= screens
[SCREEN_MAIN
].has_buttonbar
||
227 last_list
!= gui_list
||
228 gui_list
->nb_items
!= last_count
)
230 list_init_viewports(gui_list
);
231 gui_synclist_select_item(gui_list
, gui_list
->selected_item
);
233 #ifdef HAVE_BUTTONBAR
234 last_buttonbar
= screens
[SCREEN_MAIN
].has_buttonbar
;
236 last_count
= gui_list
->nb_items
;
237 last_list
= gui_list
;
240 list_draw(&screens
[i
], gui_list
);
244 /* sets up the list so the selection is shown correctly on the screen */
245 static void gui_list_put_selection_on_screen(struct gui_synclist
* gui_list
,
246 enum screen_type screen
)
249 int difference
= gui_list
->selected_item
- gui_list
->start_item
[screen
];
250 struct viewport vp
= *gui_list
->parent
[screen
];
251 #ifdef HAVE_LCD_BITMAP
252 if (list_display_title(gui_list
, screen
))
253 vp
.height
-= font_get(gui_list
->parent
[screen
]->font
)->height
;
255 nb_lines
= viewport_get_nb_lines(&vp
);
257 /* edge case,, selected last item */
258 if (gui_list
->selected_item
== gui_list
->nb_items
-1)
260 gui_list
->start_item
[screen
] = MAX(0, gui_list
->nb_items
- nb_lines
);
262 /* selected first item */
263 else if (gui_list
->selected_item
== 0)
265 gui_list
->start_item
[screen
] = 0;
267 else if (difference
< SCROLL_LIMIT
) /* list moved up */
269 if (global_settings
.scroll_paginated
)
271 if (gui_list
->start_item
[screen
] > gui_list
->selected_item
)
273 gui_list
->start_item
[screen
] = (gui_list
->selected_item
/nb_lines
)
276 if (gui_list
->nb_items
<= nb_lines
)
277 gui_list
->start_item
[screen
] = 0;
281 int top_of_screen
= gui_list
->selected_item
- SCROLL_LIMIT
+ 1;
282 int temp
= MIN(top_of_screen
, gui_list
->nb_items
- nb_lines
);
283 gui_list
->start_item
[screen
] = MAX(0, temp
);
286 else if (difference
> nb_lines
- SCROLL_LIMIT
) /* list moved down */
288 int bottom
= gui_list
->nb_items
- nb_lines
;
289 /* always move the screen if selection isnt "visible" */
290 if (gui_list
->show_selection_marker
== false)
294 gui_list
->start_item
[screen
] = MIN(bottom
, gui_list
->start_item
[screen
] +
295 2*gui_list
->selected_size
);
297 else if (global_settings
.scroll_paginated
)
299 if (gui_list
->start_item
[screen
] + nb_lines
<= gui_list
->selected_item
)
300 gui_list
->start_item
[screen
] = MIN(bottom
, gui_list
->selected_item
);
304 int top_of_screen
= gui_list
->selected_item
+ SCROLL_LIMIT
- nb_lines
;
305 int temp
= MAX(0, top_of_screen
);
306 gui_list
->start_item
[screen
] = MIN(bottom
, temp
);
311 * Selects an item in the list
312 * - gui_list : the list structure
313 * - item_number : the number of the item which will be selected
315 void gui_synclist_select_item(struct gui_synclist
* gui_list
, int item_number
)
318 if( item_number
> gui_list
->nb_items
-1 || item_number
< 0 )
320 gui_list
->selected_item
= item_number
;
322 gui_list_put_selection_on_screen(gui_list
, i
);
325 static void gui_list_select_at_offset(struct gui_synclist
* gui_list
,
329 if (gui_list
->selected_size
> 1)
331 offset
*= gui_list
->selected_size
;
332 /* always select the first item of multi-line lists */
333 offset
-= offset
%gui_list
->selected_size
;
335 new_selection
= gui_list
->selected_item
+ offset
;
336 if (new_selection
>= gui_list
->nb_items
)
338 gui_list
->selected_item
= gui_list
->limit_scroll
?
339 gui_list
->nb_items
- gui_list
->selected_size
: 0;
341 else if (new_selection
< 0)
343 gui_list
->selected_item
= gui_list
->limit_scroll
?
344 0 : gui_list
->nb_items
- gui_list
->selected_size
;
346 else if (gui_list
->show_selection_marker
== false)
348 int i
, nb_lines
, screen_top
;
351 struct viewport vp
= *gui_list
->parent
[i
];
352 #ifdef HAVE_LCD_BITMAP
353 if (list_display_title(gui_list
, i
))
354 vp
.height
-= font_get(gui_list
->parent
[i
]->font
)->height
;
356 nb_lines
= viewport_get_nb_lines(&vp
);
359 screen_top
= gui_list
->nb_items
-nb_lines
;
362 gui_list
->start_item
[i
] = MIN(screen_top
, gui_list
->start_item
[i
] +
363 gui_list
->selected_size
);
364 gui_list
->selected_item
= gui_list
->start_item
[i
];
368 gui_list
->start_item
[i
] = MAX(0, gui_list
->start_item
[i
] -
369 gui_list
->selected_size
);
370 gui_list
->selected_item
= gui_list
->start_item
[i
] + nb_lines
;
375 else gui_list
->selected_item
+= offset
;
376 gui_synclist_select_item(gui_list
, gui_list
->selected_item
);
380 * Adds an item to the list (the callback will be asked for one more item)
381 * - gui_list : the list structure
383 void gui_synclist_add_item(struct gui_synclist
* gui_list
)
385 gui_list
->nb_items
++;
386 /* if only one item in the list, select it */
387 if(gui_list
->nb_items
== 1)
388 gui_list
->selected_item
= 0;
392 * Removes an item to the list (the callback will be asked for one less item)
393 * - gui_list : the list structure
395 void gui_synclist_del_item(struct gui_synclist
* gui_list
)
397 if(gui_list
->nb_items
> 0)
399 if (gui_list
->selected_item
== gui_list
->nb_items
-1)
400 gui_list
->selected_item
--;
401 gui_list
->nb_items
--;
402 gui_synclist_select_item(gui_list
, gui_list
->selected_item
);
406 #ifdef HAVE_LCD_BITMAP
407 void gui_list_screen_scroll_step(int ofs
)
412 void gui_list_screen_scroll_out_of_view(bool enable
)
415 offset_out_of_view
= true;
417 offset_out_of_view
= false;
419 #endif /* HAVE_LCD_BITMAP */
422 * Set the title and title icon of the list. Setting title to NULL disables
423 * both the title and icon. Use NOICON if there is no icon.
425 void gui_synclist_set_title(struct gui_synclist
* gui_list
,
426 char * title
, enum themable_icons icon
)
428 gui_list
->title
= title
;
429 gui_list
->title_icon
= icon
;
431 #ifdef HAVE_LCD_BITMAP
434 screens
[i
].getstringsize(title
, &gui_list
->title_width
, NULL
);
436 gui_list
->title_width
= strlen(title
);
439 gui_list
->title_width
= 0;
441 force_list_reinit
= true;
445 void gui_synclist_set_nb_items(struct gui_synclist
* lists
, int nb_items
)
447 #ifdef HAVE_LCD_BITMAP
450 lists
->nb_items
= nb_items
;
451 #ifdef HAVE_LCD_BITMAP
454 lists
->offset_position
[i
] = 0;
458 int gui_synclist_get_nb_items(struct gui_synclist
* lists
)
460 return lists
->nb_items
;
462 int gui_synclist_get_sel_pos(struct gui_synclist
* lists
)
464 return lists
->selected_item
;
466 void gui_synclist_set_icon_callback(struct gui_synclist
* lists
,
467 list_get_icon icon_callback
)
469 lists
->callback_get_item_icon
= icon_callback
;
472 void gui_synclist_set_voice_callback(struct gui_synclist
* lists
,
473 list_speak_item voice_callback
)
475 lists
->callback_speak_item
= voice_callback
;
478 #ifdef HAVE_LCD_COLOR
479 void gui_synclist_set_color_callback(struct gui_synclist
* lists
,
480 list_get_color color_callback
)
482 lists
->callback_get_item_color
= color_callback
;
486 static void gui_synclist_select_next_page(struct gui_synclist
* lists
,
487 enum screen_type screen
)
489 int nb_lines
= viewport_get_nb_lines(lists
->parent
[screen
]);
490 gui_list_select_at_offset(lists
, nb_lines
);
493 static void gui_synclist_select_previous_page(struct gui_synclist
* lists
,
494 enum screen_type screen
)
496 int nb_lines
= viewport_get_nb_lines(lists
->parent
[screen
]);
497 gui_list_select_at_offset(lists
, -nb_lines
);
500 void gui_synclist_limit_scroll(struct gui_synclist
* lists
, bool scroll
)
502 lists
->limit_scroll
= scroll
;
505 #ifdef HAVE_LCD_BITMAP
507 * Makes all the item in the list scroll by one step to the right.
508 * Should stop increasing the value when reaching the widest item value
511 static void gui_synclist_scroll_right(struct gui_synclist
* lists
)
516 /* FIXME: This is a fake right boundry limiter. there should be some
517 * callback function to find the longest item on the list in pixels,
518 * to stop the list from scrolling past that point */
519 lists
->offset_position
[i
]+=offset_step
;
520 if (lists
->offset_position
[i
] > 1000)
521 lists
->offset_position
[i
] = 1000;
526 * Makes all the item in the list scroll by one step to the left.
527 * stops at starting position.
529 static void gui_synclist_scroll_left(struct gui_synclist
* lists
)
534 lists
->offset_position
[i
]-=offset_step
;
535 if (lists
->offset_position
[i
] < 0)
536 lists
->offset_position
[i
] = 0;
539 #endif /* HAVE_LCD_BITMAP */
541 static void _gui_synclist_speak_item(struct gui_synclist
*lists
, bool repeating
)
543 list_speak_item
*cb
= lists
->callback_speak_item
;
544 if(cb
&& gui_synclist_get_nb_items(lists
) != 0)
546 int sel
= gui_synclist_get_sel_pos(lists
);
548 /* If we got a repeating key action, or we have just very
549 recently started talking, then we want to stay silent for a
550 while until things settle. Likewise if we already had a
551 pending scheduled announcement not yet due: we need to
554 || (lists
->scheduled_talk_tick
555 && TIME_BEFORE(current_tick
, lists
->scheduled_talk_tick
))
556 || (lists
->last_talked_tick
557 && TIME_BEFORE(current_tick
, lists
->last_talked_tick
+HZ
/4)))
559 lists
->scheduled_talk_tick
= current_tick
+HZ
/4;
562 lists
->scheduled_talk_tick
= 0; /* work done */
563 cb(sel
, lists
->data
);
564 lists
->last_talked_tick
= current_tick
;
568 void gui_synclist_speak_item(struct gui_synclist
* lists
)
569 /* The list user should call this to speak the first item on entering
570 the list, and whenever the list is updated. */
572 if(gui_synclist_get_nb_items(lists
) == 0 && global_settings
.talk_menu
)
573 talk_id(VOICE_EMPTY_LIST
, true);
574 else _gui_synclist_speak_item(lists
, false);
577 extern intptr_t get_action_data(void);
578 #if defined(HAVE_TOUCHSCREEN)
579 /* this needs to be fixed if we ever get more than 1 touchscreen on a target */
580 unsigned gui_synclist_do_touchscreen(struct gui_synclist
* gui_list
);
583 bool gui_synclist_do_button(struct gui_synclist
* lists
,
584 int *actionptr
, enum list_wrap wrap
)
586 int action
= *actionptr
;
587 #ifdef HAVE_LCD_BITMAP
588 static bool scrolling_left
= false;
591 #ifdef HAVE_SCROLLWHEEL
592 int next_item_modifier
= button_apply_acceleration(get_action_data());
594 static int next_item_modifier
= 1;
595 static int last_accel_tick
= 0;
597 if (global_settings
.list_accel_start_delay
)
599 int start_delay
= global_settings
.list_accel_start_delay
* (HZ
/2);
600 int accel_wait
= global_settings
.list_accel_wait
* HZ
/2;
602 if (get_action_statuscode(NULL
)&ACTION_REPEAT
)
604 if (!last_accel_tick
)
605 last_accel_tick
= current_tick
+ start_delay
;
606 else if (current_tick
>=
607 last_accel_tick
+ accel_wait
)
609 last_accel_tick
= current_tick
;
610 next_item_modifier
++;
613 else if (last_accel_tick
)
615 next_item_modifier
= 1;
621 #if defined(HAVE_TOUCHSCREEN)
622 if (action
== ACTION_TOUCHSCREEN
)
623 action
= *actionptr
= gui_synclist_do_touchscreen(lists
);
629 gui_synclist_limit_scroll(lists
, false);
632 gui_synclist_limit_scroll(lists
, true);
634 case LIST_WRAP_UNLESS_HELD
:
635 if (action
== ACTION_STD_PREVREPEAT
||
636 action
== ACTION_STD_NEXTREPEAT
||
637 action
== ACTION_LISTTREE_PGUP
||
638 action
== ACTION_LISTTREE_PGDOWN
)
639 gui_synclist_limit_scroll(lists
, true);
640 else gui_synclist_limit_scroll(lists
, false);
647 gui_synclist_draw(lists
);
650 #ifdef HAVE_VOLUME_IN_LIST
651 case ACTION_LIST_VOLUP
:
652 global_settings
.volume
+= 2;
653 /* up two because the falthrough brings it down one */
654 case ACTION_LIST_VOLDOWN
:
655 global_settings
.volume
--;
659 case ACTION_STD_PREV
:
660 case ACTION_STD_PREVREPEAT
:
661 gui_list_select_at_offset(lists
, -next_item_modifier
);
662 #ifndef HAVE_SCROLLWHEEL
663 if (button_queue_count() < FRAMEDROP_TRIGGER
)
665 gui_synclist_draw(lists
);
666 _gui_synclist_speak_item(lists
,
667 action
== ACTION_STD_PREVREPEAT
668 || next_item_modifier
>1);
670 *actionptr
= ACTION_STD_PREV
;
673 case ACTION_STD_NEXT
:
674 case ACTION_STD_NEXTREPEAT
:
675 gui_list_select_at_offset(lists
, next_item_modifier
);
676 #ifndef HAVE_SCROLLWHEEL
677 if (button_queue_count() < FRAMEDROP_TRIGGER
)
679 gui_synclist_draw(lists
);
680 _gui_synclist_speak_item(lists
,
681 action
== ACTION_STD_NEXTREPEAT
682 || next_item_modifier
>1);
684 *actionptr
= ACTION_STD_NEXT
;
687 #ifdef HAVE_LCD_BITMAP
688 case ACTION_TREE_PGRIGHT
:
689 gui_synclist_scroll_right(lists
);
690 gui_synclist_draw(lists
);
692 case ACTION_TREE_ROOT_INIT
:
693 /* After this button press ACTION_TREE_PGLEFT is allowed
694 to skip to root. ACTION_TREE_ROOT_INIT must be defined in the
695 keymaps as a repeated button press (the same as the repeated
696 ACTION_TREE_PGLEFT) with the pre condition being the non-repeated
698 if (lists
->offset_position
[0] == 0)
700 scrolling_left
= false;
701 *actionptr
= ACTION_STD_CANCEL
;
704 *actionptr
= ACTION_TREE_PGLEFT
;
705 case ACTION_TREE_PGLEFT
:
706 if(!scrolling_left
&& (lists
->offset_position
[0] == 0))
708 *actionptr
= ACTION_STD_CANCEL
;
711 gui_synclist_scroll_left(lists
);
712 gui_synclist_draw(lists
);
713 scrolling_left
= true; /* stop ACTION_TREE_PAGE_LEFT
717 /* for pgup / pgdown, we are obliged to have a different behaviour depending
718 * on the screen for which the user pressed the key since for example, remote
719 * and main screen doesn't have the same number of lines */
720 case ACTION_LISTTREE_PGUP
:
723 #ifdef HAVE_REMOTE_LCD
724 get_action_statuscode(NULL
)&ACTION_REMOTE
?
728 gui_synclist_select_previous_page(lists
, screen
);
729 gui_synclist_draw(lists
);
730 _gui_synclist_speak_item(lists
, false);
732 *actionptr
= ACTION_STD_NEXT
;
736 case ACTION_LISTTREE_PGDOWN
:
739 #ifdef HAVE_REMOTE_LCD
740 get_action_statuscode(NULL
)&ACTION_REMOTE
?
744 gui_synclist_select_next_page(lists
, screen
);
745 gui_synclist_draw(lists
);
746 _gui_synclist_speak_item(lists
, false);
748 *actionptr
= ACTION_STD_PREV
;
752 if(lists
->scheduled_talk_tick
753 && TIME_AFTER(current_tick
, lists
->scheduled_talk_tick
))
754 /* scheduled postponed item announcement is due */
755 _gui_synclist_speak_item(lists
, false);
759 int list_do_action_timeout(struct gui_synclist
*lists
, int timeout
)
760 /* Returns the lowest of timeout or the delay until a postponed
761 scheduled announcement is due (if any). */
763 if(lists
->scheduled_talk_tick
)
765 long delay
= lists
->scheduled_talk_tick
-current_tick
+1;
766 /* +1 because the trigger condition uses TIME_AFTER(), which
767 is implemented as strictly greater than. */
770 if(timeout
> delay
|| timeout
== TIMEOUT_BLOCK
)
776 bool list_do_action(int context
, int timeout
,
777 struct gui_synclist
*lists
, int *action
,
779 /* Combines the get_action() (with possibly overridden timeout) and
780 gui_synclist_do_button() calls. Returns the list action from
781 do_button, and places the action from get_action in *action. */
783 timeout
= list_do_action_timeout(lists
, timeout
);
784 *action
= get_action(context
, timeout
);
785 return gui_synclist_do_button(lists
, action
, wrap
);
788 bool gui_synclist_item_is_onscreen(struct gui_synclist
*lists
,
789 enum screen_type screen
, int item
)
791 struct viewport vp
= *lists
->parent
[screen
];
792 #ifdef HAVE_LCD_BITMAP
793 if (list_display_title(lists
, screen
))
794 vp
.height
-= font_get(lists
->parent
[screen
]->font
)->height
;
796 return item
<= (lists
->start_item
[screen
] + viewport_get_nb_lines(&vp
));
799 /* Simple use list implementation */
800 static int simplelist_line_count
= 0;
801 static char simplelist_text
[SIMPLELIST_MAX_LINES
][SIMPLELIST_MAX_LINELENGTH
];
802 /* set the amount of lines shown in the list */
803 void simplelist_set_line_count(int lines
)
806 simplelist_line_count
= 0;
807 else if (lines
>= SIMPLELIST_MAX_LINES
)
808 simplelist_line_count
= SIMPLELIST_MAX_LINES
;
810 simplelist_line_count
= lines
;
812 /* get the current amount of lines shown */
813 int simplelist_get_line_count(void)
815 return simplelist_line_count
;
817 /* add/edit a line in the list.
818 if line_number > number of lines shown it adds the line, else it edits the line */
819 void simplelist_addline(int line_number
, const char *fmt
, ...)
823 if (line_number
> simplelist_line_count
)
825 if (simplelist_line_count
< SIMPLELIST_MAX_LINES
)
826 line_number
= simplelist_line_count
++;
831 vsnprintf(simplelist_text
[line_number
], SIMPLELIST_MAX_LINELENGTH
, fmt
, ap
);
835 static char* simplelist_static_getname(int item
,
840 (void)data
; (void)buffer
; (void)buffer_len
;
841 return simplelist_text
[item
];
844 bool simplelist_show_list(struct simplelist_info
*info
)
846 struct gui_synclist lists
;
847 int action
, old_line_count
= simplelist_line_count
;
848 int oldbars
= viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
849 char* (*getname
)(int item
, void * data
, char *buffer
, size_t buffer_len
);
850 int wrap
= LIST_WRAP_UNLESS_HELD
;
852 getname
= info
->get_name
;
854 getname
= simplelist_static_getname
;
855 gui_synclist_init(&lists
, getname
, info
->callback_data
,
856 info
->scroll_all
, info
->selection_size
, NULL
);
859 gui_synclist_set_title(&lists
, info
->title
, NOICON
);
861 gui_synclist_set_icon_callback(&lists
, info
->get_icon
);
863 gui_synclist_set_voice_callback(&lists
, info
->get_talk
);
865 if (info
->hide_selection
)
867 gui_synclist_hide_selection_marker(&lists
, true);
868 wrap
= LIST_WRAP_OFF
;
871 if (info
->action_callback
)
872 info
->action_callback(ACTION_REDRAW
, &lists
);
874 if (info
->get_name
== NULL
)
875 gui_synclist_set_nb_items(&lists
, simplelist_line_count
*info
->selection_size
);
877 gui_synclist_set_nb_items(&lists
, info
->count
*info
->selection_size
);
879 gui_synclist_select_item(&lists
, info
->selection
);
881 gui_synclist_draw(&lists
);
882 gui_synclist_speak_item(&lists
);
886 list_do_action(CONTEXT_STD
, info
->timeout
,
887 &lists
, &action
, wrap
);
889 /* We must yield in this case or no other thread can run */
890 if (info
->timeout
== TIMEOUT_NOBLOCK
)
893 if (info
->action_callback
)
895 bool stdok
= action
==ACTION_STD_OK
;
896 action
= info
->action_callback(action
, &lists
);
897 if (stdok
&& action
== ACTION_STD_CANCEL
)
899 /* callback asked us to exit */
900 info
->selection
= gui_synclist_get_sel_pos(&lists
);
904 if (info
->get_name
== NULL
)
905 gui_synclist_set_nb_items(&lists
,
906 simplelist_line_count
*info
->selection_size
);
908 if (action
== ACTION_STD_CANCEL
)
910 info
->selection
= -1;
913 else if ((action
== ACTION_REDRAW
) ||
914 (old_line_count
!= simplelist_line_count
))
916 if (info
->get_name
== NULL
)
918 gui_synclist_set_nb_items(&lists
,
919 simplelist_line_count
*info
->selection_size
);
921 gui_synclist_draw(&lists
);
922 old_line_count
= simplelist_line_count
;
924 else if(default_event_handler(action
) == SYS_USB_CONNECTED
)
928 viewportmanager_set_statusbar(oldbars
);
932 void simplelist_info_init(struct simplelist_info
*info
, char* title
,
933 int count
, void* data
)
937 info
->selection_size
= 1;
938 info
->hide_selection
= false;
939 info
->scroll_all
= false;
940 info
->timeout
= HZ
/10;
942 info
->action_callback
= NULL
;
943 info
->get_icon
= NULL
;
944 info
->get_name
= NULL
;
945 info
->get_talk
= NULL
;
946 info
->callback_data
= data
;