1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Kevin Ferrare
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
31 #include "screen_access.h"
33 #include "scrollbar.h"
34 #include "statusbar.h"
41 #ifdef HAVE_LCD_CHARCELLS
42 #define SCROLL_LIMIT 1
44 #define SCROLL_LIMIT (nb_lines<3?1:2)
47 /* The minimum number of pending button events in queue before starting
48 * to limit list drawing interval.
50 #define FRAMEDROP_TRIGGER 6
52 #ifdef HAVE_LCD_BITMAP
53 static int offset_step
= 16; /* pixels per screen scroll step */
54 /* should lines scroll out of the screen */
55 static bool offset_out_of_view
= false;
57 static struct gui_synclist
* last_list_displayed
;
59 #define SHOW_LIST_TITLE ((gui_list->title != NULL) && \
60 (display->nb_lines > 2))
62 static void gui_list_select_at_offset(struct gui_synclist
* gui_list
,
66 * Initializes a scrolling list
67 * - gui_list : the list structure to initialize
68 * - callback_get_item_name : pointer to a function that associates a label
69 * to a given item number
70 * - data : extra data passed to the list callback
74 void gui_synclist_init(struct gui_synclist
* gui_list
,
75 list_get_name callback_get_item_name
,
82 gui_list
->callback_get_item_icon
= NULL
;
83 gui_list
->callback_get_item_name
= callback_get_item_name
;
84 gui_list
->callback_speak_item
= NULL
;
85 gui_list_set_nb_items(gui_list
, 0);
86 gui_list
->selected_item
= 0;
89 gui_list
->start_item
[i
] = 0;
90 gui_list
->last_displayed_start_item
[i
] = -1 ;
91 #ifdef HAVE_LCD_BITMAP
92 gui_list
->offset_position
[i
] = 0;
95 gui_list
->limit_scroll
= false;
97 gui_list
->scroll_all
=scroll_all
;
98 gui_list
->selected_size
=selected_size
;
99 gui_list
->title
= NULL
;
100 gui_list
->title_width
= 0;
101 gui_list
->title_icon
= Icon_NOICON
;
103 gui_list
->scheduled_talk_tick
= gui_list
->last_talked_tick
= 0;
104 gui_list
->show_selection_marker
= true;
105 gui_list
->last_displayed_selected_item
= -1 ;
107 #ifdef HAVE_LCD_COLOR
108 gui_list
->title_color
= -1;
109 gui_list
->callback_get_item_color
= NULL
;
113 /* this toggles the selection bar or cursor */
114 void gui_synclist_hide_selection_marker(struct gui_synclist
* lists
, bool hide
)
116 lists
->show_selection_marker
= !hide
;
120 #ifdef HAVE_LCD_BITMAP
121 static int gui_list_get_item_offset(struct gui_synclist
* gui_list
, int item_width
,
122 int text_pos
, struct screen
* display
)
126 if (offset_out_of_view
)
128 item_offset
= gui_list
->offset_position
[display
->screen_type
];
132 /* if text is smaller then view */
133 if (item_width
<= display
->width
- text_pos
)
139 /* if text got out of view */
140 if (gui_list
->offset_position
[display
->screen_type
] >
141 item_width
- (display
->width
- text_pos
))
142 item_offset
= item_width
- (display
->width
- text_pos
);
144 item_offset
= gui_list
->offset_position
[display
->screen_type
];
153 * Draws the list on the attached screen
154 * - gui_list : the list structure
156 static void gui_list_draw_smart(struct gui_synclist
*gui_list
, struct screen
* display
)
159 bool draw_icons
= (gui_list
->callback_get_item_icon
!= NULL
&& global_settings
.show_icons
);
163 static int last_lines
[NB_SCREENS
] = {0};
164 #ifdef HAVE_LCD_BITMAP
166 int old_margin
= display
->getxmargin();
169 bool partial_draw
= false;
171 #ifdef HAVE_LCD_BITMAP
172 display
->setfont(FONT_UI
);
173 gui_textarea_update_nblines(display
);
175 /* Speed up UI by drawing the changed contents only. */
176 if (gui_list
== last_list_displayed
177 && gui_list
->last_displayed_start_item
[display
->screen_type
] == gui_list
->start_item
[display
->screen_type
]
178 && gui_list
->selected_size
== 1)
183 lines
= display
->nb_lines
- SHOW_LIST_TITLE
;
184 if (last_lines
[display
->screen_type
] != lines
)
186 gui_list_select_at_offset(gui_list
, 0);
187 last_lines
[display
->screen_type
] = lines
;
192 end
= gui_list
->last_displayed_selected_item
- gui_list
->start_item
[display
->screen_type
];
193 i
= gui_list
->selected_item
- gui_list
->start_item
[display
->screen_type
];
207 gui_textarea_clear(display
);
209 end
= display
->nb_lines
;
210 gui_list
->last_displayed_start_item
[display
->screen_type
] = gui_list
->start_item
[display
->screen_type
];
211 last_list_displayed
= gui_list
;
214 gui_list
->last_displayed_selected_item
= gui_list
->selected_item
;
216 /* position and draw the list title & icon */
217 if (SHOW_LIST_TITLE
&& !partial_draw
)
219 if (gui_list
->title_icon
!= NOICON
&& draw_icons
)
221 screen_put_icon(display
, 0, 0, gui_list
->title_icon
);
222 #ifdef HAVE_LCD_BITMAP
223 text_pos
= get_icon_width(display
->screen_type
)+2; /* pixels */
225 text_pos
= 1; /* chars */
233 #ifdef HAVE_LCD_BITMAP
234 int title_style
= STYLE_DEFAULT
;
235 #ifdef HAVE_LCD_COLOR
236 if (gui_list
->title_color
>= 0)
238 title_style
|= STYLE_COLORED
;
239 title_style
|= gui_list
->title_color
;
242 screen_set_xmargin(display
, text_pos
); /* margin for title */
243 item_offset
= gui_list_get_item_offset(gui_list
, gui_list
->title_width
,
245 if (item_offset
> gui_list
->title_width
- (display
->width
- text_pos
))
246 display
->puts_style_offset(0, 0, gui_list
->title
,
247 title_style
, item_offset
);
249 display
->puts_scroll_style_offset(0, 0, gui_list
->title
,
250 title_style
, item_offset
);
252 display
->puts_scroll(text_pos
, 0, gui_list
->title
);
256 /* Adjust the position of icon, cursor, text for the list */
257 #ifdef HAVE_LCD_BITMAP
258 gui_textarea_update_nblines(display
);
261 draw_scrollbar
= (global_settings
.scrollbar
&&
262 lines
< gui_list
->nb_items
);
264 draw_cursor
= !global_settings
.cursor_style
&&
265 gui_list
->show_selection_marker
;
266 text_pos
= 0; /* here it's in pixels */
267 if(draw_scrollbar
|| SHOW_LIST_TITLE
) /* indent if there's
270 text_pos
+= SCROLLBAR_WIDTH
;
273 text_pos
+= get_icon_width(display
->screen_type
) + 2;
276 text_pos
+= get_icon_width(display
->screen_type
) + 2;
280 text_pos
= 2; /* here it's in chars */
285 #ifdef HAVE_LCD_BITMAP
286 screen_set_xmargin(display
, text_pos
); /* margin for list */
292 if (end
< display
->nb_lines
)
296 #ifdef HAVE_LCD_COLOR
297 unsigned char cur_line
= 0;
299 for (i
= start
; i
< end
; i
++)
302 char entry_buffer
[MAX_PATH
];
303 unsigned char *entry_name
;
304 int current_item
= gui_list
->start_item
[display
->screen_type
] +
305 (SHOW_LIST_TITLE
? i
-1 : i
);
307 /* When there are less items to display than the
308 * current available space on the screen, we stop*/
309 if(current_item
>= gui_list
->nb_items
)
311 s
= gui_list
->callback_get_item_name(current_item
,
314 entry_name
= P2STR(s
);
316 #ifdef HAVE_LCD_BITMAP
317 int style
= STYLE_DEFAULT
;
318 /* position the string at the correct offset place */
320 display
->getstringsize(entry_name
, &item_width
, &h
);
321 item_offset
= gui_list_get_item_offset(gui_list
, item_width
,
325 #ifdef HAVE_LCD_COLOR
326 /* if the list has a color callback */
327 if (gui_list
->callback_get_item_color
)
329 int color
= gui_list
->callback_get_item_color(current_item
,
331 /* if color selected */
334 style
|= STYLE_COLORED
;
340 if(gui_list
->show_selection_marker
&&
341 current_item
>= gui_list
->selected_item
&&
342 current_item
< gui_list
->selected_item
+ gui_list
->selected_size
)
343 {/* The selected item must be displayed scrolling */
344 #ifdef HAVE_LCD_BITMAP
345 if (global_settings
.cursor_style
== 1
346 #ifdef HAVE_REMOTE_LCD
347 || display
->screen_type
== SCREEN_REMOTE
351 /* Display inverted-line-style */
352 style
|= STYLE_INVERT
;
354 #ifdef HAVE_LCD_COLOR
355 else if (global_settings
.cursor_style
== 2)
357 /* Display colour line selector */
358 style
|= STYLE_COLORBAR
;
360 else if (global_settings
.cursor_style
== 3)
362 /* Display gradient line selector */
363 style
= STYLE_GRADIENT
;
365 /* Make the lcd driver know how many lines the gradient should
366 cover and current line number */
367 /* number of selected lines */
368 style
|= NUMLN_PACK(gui_list
->selected_size
);
369 /* current line number, zero based */
370 style
|= CURLN_PACK(cur_line
);
374 else /* if (!global_settings.cursor_style) */
376 if (current_item
% gui_list
->selected_size
!= 0)
379 /* if the text is smaller than the viewport size */
380 if (item_offset
> item_width
- (display
->width
- text_pos
))
383 display
->puts_style_offset(0, i
, entry_name
,
388 display
->puts_scroll_style_offset(0, i
, entry_name
,
392 display
->puts_scroll(text_pos
, i
, entry_name
);
397 screen_put_icon_with_offset(display
, 0, i
,
398 (draw_scrollbar
|| SHOW_LIST_TITLE
)?
405 if(gui_list
->scroll_all
)
407 #ifdef HAVE_LCD_BITMAP
408 display
->puts_scroll_style_offset(0, i
, entry_name
,
411 display
->puts_scroll(text_pos
, i
, entry_name
);
416 #ifdef HAVE_LCD_BITMAP
417 display
->puts_style_offset(0, i
, entry_name
,
420 display
->puts(text_pos
, i
, entry_name
);
427 enum themable_icons icon
;
428 icon
= gui_list
->callback_get_item_icon(current_item
, gui_list
->data
);
429 if(icon
> Icon_NOICON
)
431 #ifdef HAVE_LCD_BITMAP
432 int x
= draw_cursor
?1:0;
433 int x_off
= (draw_scrollbar
|| SHOW_LIST_TITLE
) ? SCROLLBAR_WIDTH
: 0;
434 screen_put_icon_with_offset(display
, x
, i
,
437 screen_put_icon(display
, 1, i
, icon
);
443 #ifdef HAVE_LCD_BITMAP
444 /* Draw the scrollbar if needed*/
447 int y_start
= gui_textarea_get_ystart(display
);
449 y_start
+= display
->char_height
;
450 int scrollbar_y_end
= display
->char_height
*
452 gui_scrollbar_draw(display
, 0, y_start
, SCROLLBAR_WIDTH
-1,
453 scrollbar_y_end
- y_start
, gui_list
->nb_items
,
454 gui_list
->start_item
[display
->screen_type
],
455 gui_list
->start_item
[display
->screen_type
] + lines
, VERTICAL
);
458 screen_set_xmargin(display
, old_margin
);
461 gui_textarea_update(display
);
465 * Force a full screen update.
467 void gui_synclist_draw(struct gui_synclist
*gui_list
)
472 last_list_displayed
= NULL
;
473 gui_list_draw_smart(gui_list
, &screens
[i
]);
479 /* sets up the list so the selection is shown correctly on the screen */
480 static void gui_list_put_selection_on_screen(struct gui_synclist
* gui_list
,
481 enum screen_type screen
)
483 struct screen
*display
= &screens
[screen
];
484 int nb_lines
= display
->nb_lines
- SHOW_LIST_TITLE
;
485 int difference
= gui_list
->selected_item
- gui_list
->start_item
[screen
];
487 /* edge case,, selected last item */
488 if (gui_list
->selected_item
== gui_list
->nb_items
-1)
490 gui_list
->start_item
[screen
] = MAX(0, gui_list
->nb_items
- nb_lines
);
492 /* selected first item */
493 else if (gui_list
->selected_item
== 0)
495 gui_list
->start_item
[screen
] = 0;
497 else if (difference
< SCROLL_LIMIT
) /* list moved up */
499 if (global_settings
.scroll_paginated
)
501 if (gui_list
->start_item
[screen
] > gui_list
->selected_item
)
502 gui_list
->start_item
[screen
] = (gui_list
->selected_item
/nb_lines
)*nb_lines
;
506 int top_of_screen
= gui_list
->selected_item
- SCROLL_LIMIT
;
507 int temp
= MIN(top_of_screen
, gui_list
->nb_items
- nb_lines
);
508 gui_list
->start_item
[screen
] = MAX(0, temp
);
511 else if (difference
> nb_lines
- SCROLL_LIMIT
) /* list moved down */
513 int bottom
= gui_list
->nb_items
- nb_lines
;
514 /* always move the screen if selection isnt "visible" */
515 if (gui_list
->show_selection_marker
== false)
519 gui_list
->start_item
[screen
] = MIN(bottom
, gui_list
->start_item
[screen
] +
520 2*gui_list
->selected_size
);
522 else if (global_settings
.scroll_paginated
)
524 if (gui_list
->start_item
[screen
] + nb_lines
<= gui_list
->selected_item
)
525 gui_list
->start_item
[screen
] = MIN(bottom
, gui_list
->selected_item
);
529 int top_of_screen
= gui_list
->selected_item
+ SCROLL_LIMIT
- nb_lines
;
530 int temp
= MAX(0, top_of_screen
);
531 gui_list
->start_item
[screen
] = MIN(bottom
, temp
);
536 * Selects an item in the list
537 * - gui_list : the list structure
538 * - item_number : the number of the item which will be selected
540 void gui_synclist_select_item(struct gui_synclist
* gui_list
, int item_number
)
543 if( item_number
> gui_list
->nb_items
-1 || item_number
< 0 )
545 gui_list
->selected_item
= item_number
;
547 gui_list_put_selection_on_screen(gui_list
, i
);
550 static void gui_list_select_at_offset(struct gui_synclist
* gui_list
,
554 if (gui_list
->selected_size
> 1)
556 offset
*= gui_list
->selected_size
;
557 /* always select the first item of multi-line lists */
558 offset
-= offset
%gui_list
->selected_size
;
560 new_selection
= gui_list
->selected_item
+ offset
;
561 if (new_selection
>= gui_list
->nb_items
)
563 gui_list
->selected_item
= gui_list
->limit_scroll
?
564 gui_list
->nb_items
- gui_list
->selected_size
: 0;
566 else if (new_selection
< 0)
568 gui_list
->selected_item
= gui_list
->limit_scroll
?
569 0 : gui_list
->nb_items
- gui_list
->selected_size
;
571 else if (gui_list
->show_selection_marker
== false)
573 /* NOTE: this part doesnt work as well as it used to, the problem is
574 we want to scroll the lists seperatly but we only have one
575 selected item now, I dont think this is such a big deal though */
576 int i
, nb_lines
, screen_top
;
579 struct screen
*display
= &screens
[i
];
580 nb_lines
= display
->nb_lines
- SHOW_LIST_TITLE
;
583 screen_top
= gui_list
->nb_items
-nb_lines
;
586 gui_list
->start_item
[i
] = MIN(screen_top
, gui_list
->start_item
[i
] +
587 gui_list
->selected_size
);
591 gui_list
->start_item
[i
] = MAX(0, gui_list
->start_item
[i
] -
592 gui_list
->selected_size
);
597 else gui_list
->selected_item
+= offset
;
598 gui_synclist_select_item(gui_list
, gui_list
->selected_item
);
602 * Adds an item to the list (the callback will be asked for one more item)
603 * - gui_list : the list structure
605 void gui_synclist_add_item(struct gui_synclist
* gui_list
)
607 gui_list
->nb_items
++;
608 /* if only one item in the list, select it */
609 if(gui_list
->nb_items
== 1)
610 gui_list
->selected_item
= 0;
614 * Removes an item to the list (the callback will be asked for one less item)
615 * - gui_list : the list structure
617 void gui_synclist_del_item(struct gui_synclist
* gui_list
)
620 if(gui_list
->nb_items
> 0)
622 if (gui_list
->selected_item
== gui_list
->nb_items
-1)
623 gui_list
->selected_item
--;
626 gui_textarea_update_nblines(&screens
[i
]);
627 int nb_lines
= screens
[i
].nb_lines
;
628 int dist_start_from_end
= gui_list
->nb_items
629 - gui_list
->start_item
[i
] - 1;
631 /* scroll the list if needed */
632 if( (dist_start_from_end
< nb_lines
) && (gui_list
->start_item
[i
] != 0) )
633 gui_list
->start_item
[i
]--;
635 gui_list
->nb_items
--;
639 #ifdef HAVE_LCD_BITMAP
640 void gui_list_screen_scroll_step(int ofs
)
645 void gui_list_screen_scroll_out_of_view(bool enable
)
648 offset_out_of_view
= true;
650 offset_out_of_view
= false;
652 #endif /* HAVE_LCD_BITMAP */
655 * Set the title and title icon of the list. Setting title to NULL disables
656 * both the title and icon. Use NOICON if there is no icon.
658 void gui_synclist_set_title(struct gui_synclist
* gui_list
,
659 char * title
, enum themable_icons icon
)
661 gui_list
->title
= title
;
662 gui_list
->title_icon
= icon
;
664 #ifdef HAVE_LCD_BITMAP
667 screens
[i
].getstringsize(title
, &gui_list
->title_width
, NULL
);
669 gui_list
->title_width
= strlen(title
);
672 gui_list
->title_width
= 0;
677 void gui_synclist_set_nb_items(struct gui_synclist
* lists
, int nb_items
)
679 #ifdef HAVE_LCD_BITMAP
682 lists
->nb_items
= nb_items
;
683 #ifdef HAVE_LCD_BITMAP
686 lists
->offset_position
[i
] = 0;
690 int gui_synclist_get_nb_items(struct gui_synclist
* lists
)
692 return lists
->nb_items
;
694 int gui_synclist_get_sel_pos(struct gui_synclist
* lists
)
696 return lists
->selected_item
;
698 void gui_synclist_set_icon_callback(struct gui_synclist
* lists
,
699 list_get_icon icon_callback
)
701 lists
->callback_get_item_icon
= icon_callback
;
704 void gui_synclist_set_voice_callback(struct gui_synclist
* lists
,
705 list_speak_item voice_callback
)
707 lists
->callback_speak_item
= voice_callback
;
710 static void gui_synclist_select_next_page(struct gui_synclist
* lists
,
711 enum screen_type screen
)
713 gui_list_select_at_offset(lists
, screens
[screen
].nb_lines
);
716 static void gui_synclist_select_previous_page(struct gui_synclist
* lists
,
717 enum screen_type screen
)
719 gui_list_select_at_offset(lists
, -screens
[screen
].nb_lines
);
722 void gui_synclist_limit_scroll(struct gui_synclist
* lists
, bool scroll
)
724 lists
->limit_scroll
= scroll
;
727 #ifdef HAVE_LCD_BITMAP
729 * Makes all the item in the list scroll by one step to the right.
730 * Should stop increasing the value when reaching the widest item value
733 static void gui_synclist_scroll_right(struct gui_synclist
* lists
)
738 /* FIXME: This is a fake right boundry limiter. there should be some
739 * callback function to find the longest item on the list in pixels,
740 * to stop the list from scrolling past that point */
741 lists
->offset_position
[i
]+=offset_step
;
742 if (lists
->offset_position
[i
] > 1000)
743 lists
->offset_position
[i
] = 1000;
748 * Makes all the item in the list scroll by one step to the left.
749 * stops at starting position.
751 static void gui_synclist_scroll_left(struct gui_synclist
* lists
)
756 lists
->offset_position
[i
]-=offset_step
;
757 if (lists
->offset_position
[i
] < 0)
758 lists
->offset_position
[i
] = 0;
761 #endif /* HAVE_LCD_BITMAP */
763 static void _gui_synclist_speak_item(struct gui_synclist
*lists
, bool repeating
)
765 list_speak_item
*cb
= lists
->callback_speak_item
;
766 if(cb
&& gui_synclist_get_nb_items(lists
) != 0)
768 int sel
= gui_synclist_get_sel_pos(lists
);
770 /* If we got a repeating key action, or we have just very
771 recently started talking, then we want to stay silent for a
772 while until things settle. Likewise if we already had a
773 pending scheduled announcement not yet due: we need to
776 || (lists
->scheduled_talk_tick
777 && TIME_BEFORE(current_tick
, lists
->scheduled_talk_tick
))
778 || (lists
->last_talked_tick
779 && TIME_BEFORE(current_tick
, lists
->last_talked_tick
+HZ
/4)))
781 lists
->scheduled_talk_tick
= current_tick
+HZ
/4;
784 lists
->scheduled_talk_tick
= 0; /* work done */
785 cb(sel
, lists
->data
);
786 lists
->last_talked_tick
= current_tick
;
790 void gui_synclist_speak_item(struct gui_synclist
* lists
)
791 /* The list user should call this to speak the first item on entering
792 the list, and whenever the list is updated. */
794 if(gui_synclist_get_nb_items(lists
) == 0 && global_settings
.talk_menu
)
795 talk_id(VOICE_EMPTY_LIST
, true);
796 else _gui_synclist_speak_item(lists
, false);
799 extern intptr_t get_action_data(void);
801 #if defined(HAVE_TOUCHPAD)
802 /* this needs to be fixed if we ever get more than 1 touchscreen on a target */
803 unsigned gui_synclist_do_touchpad(struct gui_synclist
* gui_list
)
806 unsigned button
= action_get_touchpad_press(&x
, &y
);
808 struct screen
*display
= &screens
[SCREEN_MAIN
];
809 if (button
== BUTTON_NONE
)
811 if (x
<SCROLLBAR_WIDTH
)
813 /* top left corner is hopefully GO_TO_ROOT */
814 if (y
<STATUSBAR_HEIGHT
)
816 if (button
== BUTTON_REL
)
817 return ACTION_STD_MENU
;
818 else if (button
== BUTTON_REPEAT
)
819 return ACTION_STD_CONTEXT
;
826 int new_selection
, nb_lines
;
828 nb_lines
= display
->nb_lines
- SHOW_LIST_TITLE
;
829 if (nb_lines
< gui_list
->nb_items
)
831 height
= nb_lines
* display
->char_height
;
832 size
= height
*nb_lines
/ gui_list
->nb_items
;
833 new_selection
= (y
*(gui_list
->nb_items
-nb_lines
))/(height
-size
);
834 gui_synclist_select_item(gui_list
, new_selection
);
836 if (new_selection
- gui_list
->start_item
[SCREEN_MAIN
] > nb_lines
)
838 new_selection
= gui_list
->start_item
[SCREEN_MAIN
]+nb_lines
;
840 gui_list
->start_item
[SCREEN_MAIN
] = new_selection
;
841 return ACTION_REDRAW
;
847 if (button
!= BUTTON_REL
&& button
!= BUTTON_REPEAT
)
849 if (global_settings
.statusbar
)
850 y
-= STATUSBAR_HEIGHT
;
852 y
-= display
->char_height
;
853 line
= y
/ display
->char_height
;
854 if (line
!= gui_list
->selected_item
- gui_list
->start_item
[SCREEN_MAIN
])
855 gui_synclist_select_item(gui_list
, gui_list
->start_item
[SCREEN_MAIN
]+line
);
856 return ACTION_REDRAW
;
858 /* title or statusbar is cancel */
859 if (global_settings
.statusbar
)
861 if (y
< STATUSBAR_HEIGHT
&& !SHOW_LIST_TITLE
)
862 return ACTION_STD_CANCEL
;
863 y
-= STATUSBAR_HEIGHT
;
865 /* title goes up one level */
868 if (y
< display
->char_height
)
869 return ACTION_STD_CANCEL
;
870 y
-= display
->char_height
;
872 /* pressing an item will select it.
873 pressing the selected item will "enter" it */
874 line
= y
/ display
->char_height
;
875 if (line
!= gui_list
->selected_item
- gui_list
->start_item
[SCREEN_MAIN
])
877 if (gui_list
->start_item
[SCREEN_MAIN
]+line
> gui_list
->nb_items
)
879 gui_synclist_select_item(gui_list
, gui_list
->start_item
[SCREEN_MAIN
]+line
);
882 if (button
== BUTTON_REPEAT
)
883 return ACTION_STD_CONTEXT
;
885 return ACTION_STD_OK
;
891 bool gui_synclist_do_button(struct gui_synclist
* lists
,
892 unsigned *actionptr
, enum list_wrap wrap
)
894 int action
= *actionptr
;
895 #ifdef HAVE_LCD_BITMAP
896 static bool scrolling_left
= false;
899 #ifdef HAVE_SCROLLWHEEL
900 int next_item_modifier
= button_apply_acceleration(get_action_data());
902 static int next_item_modifier
= 1;
903 static int last_accel_tick
= 0;
905 if (global_settings
.list_accel_start_delay
)
907 int start_delay
= global_settings
.list_accel_start_delay
* (HZ
/2);
908 int accel_wait
= global_settings
.list_accel_wait
* HZ
/2;
910 if (get_action_statuscode(NULL
)&ACTION_REPEAT
)
912 if (!last_accel_tick
)
913 last_accel_tick
= current_tick
+ start_delay
;
914 else if (current_tick
>=
915 last_accel_tick
+ accel_wait
)
917 last_accel_tick
= current_tick
;
918 next_item_modifier
++;
921 else if (last_accel_tick
)
923 next_item_modifier
= 1;
929 #if defined(HAVE_TOUCHPAD)
930 if (action
== ACTION_TOUCHPAD
)
931 action
= *actionptr
= gui_synclist_do_touchpad(lists
);
937 gui_synclist_limit_scroll(lists
, false);
940 gui_synclist_limit_scroll(lists
, true);
942 case LIST_WRAP_UNLESS_HELD
:
943 if (action
== ACTION_STD_PREVREPEAT
||
944 action
== ACTION_STD_NEXTREPEAT
||
945 action
== ACTION_LISTTREE_PGUP
||
946 action
== ACTION_LISTTREE_PGDOWN
)
947 gui_synclist_limit_scroll(lists
, true);
948 else gui_synclist_limit_scroll(lists
, false);
955 gui_synclist_draw(lists
);
958 #ifdef HAVE_VOLUME_IN_LIST
959 case ACTION_LIST_VOLUP
:
960 global_settings
.volume
+= 2;
961 /* up two because the falthrough brings it down one */
962 case ACTION_LIST_VOLDOWN
:
963 global_settings
.volume
--;
967 case ACTION_STD_PREV
:
968 case ACTION_STD_PREVREPEAT
:
969 gui_list_select_at_offset(lists
, -next_item_modifier
);
970 #ifndef HAVE_SCROLLWHEEL
971 if (queue_count(&button_queue
) < FRAMEDROP_TRIGGER
)
973 gui_synclist_draw(lists
);
974 _gui_synclist_speak_item(lists
,
975 action
== ACTION_STD_PREVREPEAT
976 || next_item_modifier
>1);
978 *actionptr
= ACTION_STD_PREV
;
981 case ACTION_STD_NEXT
:
982 case ACTION_STD_NEXTREPEAT
:
983 gui_list_select_at_offset(lists
, next_item_modifier
);
984 #ifndef HAVE_SCROLLWHEEL
985 if (queue_count(&button_queue
) < FRAMEDROP_TRIGGER
)
987 gui_synclist_draw(lists
);
988 _gui_synclist_speak_item(lists
,
989 action
== ACTION_STD_NEXTREPEAT
990 || next_item_modifier
>1);
992 *actionptr
= ACTION_STD_NEXT
;
995 #ifdef HAVE_LCD_BITMAP
996 case ACTION_TREE_PGRIGHT
:
997 gui_synclist_scroll_right(lists
);
998 gui_synclist_draw(lists
);
1000 case ACTION_TREE_ROOT_INIT
:
1001 /* After this button press ACTION_TREE_PGLEFT is allowed
1002 to skip to root. ACTION_TREE_ROOT_INIT must be defined in the
1003 keymaps as a repeated button press (the same as the repeated
1004 ACTION_TREE_PGLEFT) with the pre condition being the non-repeated
1006 if (lists
->offset_position
[0] == 0)
1008 scrolling_left
= false;
1009 *actionptr
= ACTION_STD_CANCEL
;
1012 *actionptr
= ACTION_TREE_PGLEFT
;
1013 case ACTION_TREE_PGLEFT
:
1014 if(!scrolling_left
&& (lists
->offset_position
[0] == 0))
1016 *actionptr
= ACTION_STD_CANCEL
;
1019 gui_synclist_scroll_left(lists
);
1020 gui_synclist_draw(lists
);
1021 scrolling_left
= true; /* stop ACTION_TREE_PAGE_LEFT
1025 /* for pgup / pgdown, we are obliged to have a different behaviour depending
1026 * on the screen for which the user pressed the key since for example, remote
1027 * and main screen doesn't have the same number of lines */
1028 case ACTION_LISTTREE_PGUP
:
1031 #ifdef HAVE_REMOTE_LCD
1032 get_action_statuscode(NULL
)&ACTION_REMOTE
?
1036 gui_synclist_select_previous_page(lists
, screen
);
1037 gui_synclist_draw(lists
);
1038 _gui_synclist_speak_item(lists
, false);
1040 *actionptr
= ACTION_STD_NEXT
;
1044 case ACTION_LISTTREE_PGDOWN
:
1047 #ifdef HAVE_REMOTE_LCD
1048 get_action_statuscode(NULL
)&ACTION_REMOTE
?
1052 gui_synclist_select_next_page(lists
, screen
);
1053 gui_synclist_draw(lists
);
1054 _gui_synclist_speak_item(lists
, false);
1056 *actionptr
= ACTION_STD_PREV
;
1060 if(lists
->scheduled_talk_tick
1061 && TIME_AFTER(current_tick
, lists
->scheduled_talk_tick
))
1062 /* scheduled postponed item announcement is due */
1063 _gui_synclist_speak_item(lists
, false);
1067 int list_do_action_timeout(struct gui_synclist
*lists
, int timeout
)
1068 /* Returns the lowest of timeout or the delay until a postponed
1069 scheduled announcement is due (if any). */
1071 if(lists
->scheduled_talk_tick
)
1073 long delay
= lists
->scheduled_talk_tick
-current_tick
+1;
1074 /* +1 because the trigger condition uses TIME_AFTER(), which
1075 is implemented as strictly greater than. */
1078 if(timeout
> delay
|| timeout
== TIMEOUT_BLOCK
)
1084 bool list_do_action(int context
, int timeout
,
1085 struct gui_synclist
*lists
, int *action
,
1086 enum list_wrap wrap
)
1087 /* Combines the get_action() (with possibly overridden timeout) and
1088 gui_synclist_do_button() calls. Returns the list action from
1089 do_button, and places the action from get_action in *action. */
1091 timeout
= list_do_action_timeout(lists
, timeout
);
1092 *action
= get_action(context
, timeout
);
1093 return gui_synclist_do_button(lists
, action
, wrap
);
1096 /* Simple use list implementation */
1097 static int simplelist_line_count
= 0;
1098 static char simplelist_text
[SIMPLELIST_MAX_LINES
][SIMPLELIST_MAX_LINELENGTH
];
1099 /* set the amount of lines shown in the list */
1100 void simplelist_set_line_count(int lines
)
1104 else if (lines
> SIMPLELIST_MAX_LINES
)
1105 lines
= SIMPLELIST_MAX_LINES
;
1106 simplelist_line_count
= 0;
1108 /* get the current amount of lines shown */
1109 int simplelist_get_line_count(void)
1111 return simplelist_line_count
;
1113 /* add/edit a line in the list.
1114 if line_number > number of lines shown it adds the line, else it edits the line */
1115 void simplelist_addline(int line_number
, const char *fmt
, ...)
1119 if (line_number
> simplelist_line_count
)
1121 if (simplelist_line_count
< SIMPLELIST_MAX_LINES
)
1122 line_number
= simplelist_line_count
++;
1127 vsnprintf(simplelist_text
[line_number
], SIMPLELIST_MAX_LINELENGTH
, fmt
, ap
);
1131 static char* simplelist_static_getname(int item
, void * data
, char *buffer
)
1133 (void)data
; (void)buffer
;
1134 return simplelist_text
[item
];
1136 bool simplelist_show_list(struct simplelist_info
*info
)
1138 struct gui_synclist lists
;
1139 int action
, old_line_count
= simplelist_line_count
;
1140 char* (*getname
)(int item
, void * data
, char *buffer
);
1142 getname
= info
->get_name
;
1144 getname
= simplelist_static_getname
;
1145 gui_synclist_init(&lists
, getname
, info
->callback_data
,
1146 info
->scroll_all
, info
->selection_size
);
1148 gui_synclist_set_title(&lists
, info
->title
, NOICON
);
1150 gui_synclist_set_icon_callback(&lists
, info
->get_icon
);
1152 gui_synclist_set_voice_callback(&lists
, info
->get_talk
);
1154 gui_synclist_hide_selection_marker(&lists
, info
->hide_selection
);
1156 if (info
->action_callback
)
1157 info
->action_callback(ACTION_REDRAW
, &lists
);
1159 if (info
->get_name
== NULL
)
1160 gui_synclist_set_nb_items(&lists
, simplelist_line_count
*info
->selection_size
);
1162 gui_synclist_set_nb_items(&lists
, info
->count
*info
->selection_size
);
1164 gui_synclist_select_item(&lists
, info
->start_selection
);
1166 gui_synclist_draw(&lists
);
1167 gui_synclist_speak_item(&lists
);
1171 gui_syncstatusbar_draw(&statusbars
, true);
1172 list_do_action(CONTEXT_STD
, info
->timeout
,
1173 &lists
, &action
, LIST_WRAP_UNLESS_HELD
);
1175 /* We must yield in this case or no other thread can run */
1176 if (info
->timeout
== TIMEOUT_NOBLOCK
)
1179 if (info
->action_callback
)
1181 action
= info
->action_callback(action
, &lists
);
1182 if (info
->get_name
== NULL
)
1183 gui_synclist_set_nb_items(&lists
, simplelist_line_count
*info
->selection_size
);
1185 if (action
== ACTION_STD_CANCEL
)
1187 else if ((action
== ACTION_REDRAW
) ||
1188 (old_line_count
!= simplelist_line_count
))
1190 if (info
->get_name
== NULL
)
1191 gui_synclist_set_nb_items(&lists
, simplelist_line_count
*info
->selection_size
);
1192 gui_synclist_draw(&lists
);
1193 if (action
!= ACTION_NONE
)
1194 gui_synclist_speak_item(&lists
);
1195 old_line_count
= simplelist_line_count
;
1197 else if(default_event_handler(action
) == SYS_USB_CONNECTED
)
1204 void simplelist_info_init(struct simplelist_info
*info
, char* title
,
1205 int count
, void* data
)
1207 info
->title
= title
;
1208 info
->count
= count
;
1209 info
->selection_size
= 1;
1210 info
->hide_selection
= false;
1211 info
->scroll_all
= false;
1212 info
->timeout
= HZ
/10;
1213 info
->start_selection
= 0;
1214 info
->action_callback
= NULL
;
1215 info
->get_icon
= NULL
;
1216 info
->get_name
= NULL
;
1217 info
->get_talk
= NULL
;
1218 info
->callback_data
= data
;