diff options
Diffstat (limited to 'apps/gui/list.c')
-rw-r--r-- | apps/gui/list.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/apps/gui/list.c b/apps/gui/list.c index 41bde5802b..52c1e4a3b9 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c | |||
@@ -1028,3 +1028,106 @@ bool gui_synclist_do_button(struct gui_synclist * lists, | |||
1028 | } | 1028 | } |
1029 | return false; | 1029 | return false; |
1030 | } | 1030 | } |
1031 | |||
1032 | /* Simple use list implementation */ | ||
1033 | static int simplelist_line_count = 0; | ||
1034 | static char simplelist_text[SIMPLELIST_MAX_LINES][SIMPLELIST_MAX_LINELENGTH]; | ||
1035 | /* set the amount of lines shown in the list */ | ||
1036 | void simplelist_set_line_count(int lines) | ||
1037 | { | ||
1038 | if (lines < 0) | ||
1039 | lines = 0; | ||
1040 | else if (lines > SIMPLELIST_MAX_LINES) | ||
1041 | lines = SIMPLELIST_MAX_LINES; | ||
1042 | simplelist_line_count = 0; | ||
1043 | } | ||
1044 | /* get the current amount of lines shown */ | ||
1045 | int simplelist_get_line_count(void) | ||
1046 | { | ||
1047 | return simplelist_line_count; | ||
1048 | } | ||
1049 | /* add/edit a line in the list. | ||
1050 | if line_number > number of lines shown it adds the line, else it edits the line */ | ||
1051 | void simplelist_addline(int line_number, const char *fmt, ...) | ||
1052 | { | ||
1053 | va_list ap; | ||
1054 | |||
1055 | if (line_number > simplelist_line_count) | ||
1056 | { | ||
1057 | if (simplelist_line_count < SIMPLELIST_MAX_LINES) | ||
1058 | line_number = simplelist_line_count++; | ||
1059 | else | ||
1060 | return; | ||
1061 | } | ||
1062 | va_start(ap, fmt); | ||
1063 | vsnprintf(simplelist_text[line_number], SIMPLELIST_MAX_LINELENGTH, fmt, ap); | ||
1064 | va_end(ap); | ||
1065 | } | ||
1066 | |||
1067 | static char* simplelist_static_getname(int item, void * data, char *buffer) | ||
1068 | { | ||
1069 | (void)data; (void)buffer; | ||
1070 | return simplelist_text[item]; | ||
1071 | } | ||
1072 | bool simplelist_show_list(struct simplelist_info *info) | ||
1073 | { | ||
1074 | struct gui_synclist lists; | ||
1075 | int action, old_line_count = simplelist_line_count; | ||
1076 | char* (*getname)(int item, void * data, char *buffer); | ||
1077 | if (info->get_name) | ||
1078 | getname = info->get_name; | ||
1079 | else | ||
1080 | getname = simplelist_static_getname; | ||
1081 | gui_synclist_init(&lists, getname, info->callback_data, | ||
1082 | info->scroll_all, info->selection_size); | ||
1083 | if (info->title) | ||
1084 | gui_synclist_set_title(&lists, info->title, NOICON); | ||
1085 | if (info->get_icon) | ||
1086 | gui_synclist_set_icon_callback(&lists, info->get_icon); | ||
1087 | |||
1088 | gui_synclist_hide_selection_marker(&lists, info->hide_selection); | ||
1089 | |||
1090 | if (info->action_callback) | ||
1091 | info->action_callback(ACTION_REDRAW, &lists); | ||
1092 | |||
1093 | if (info->get_name == NULL) | ||
1094 | gui_synclist_set_nb_items(&lists, simplelist_line_count*info->selection_size); | ||
1095 | else | ||
1096 | gui_synclist_set_nb_items(&lists, info->count*info->selection_size); | ||
1097 | |||
1098 | gui_synclist_draw(&lists); | ||
1099 | |||
1100 | while(1) | ||
1101 | { | ||
1102 | gui_syncstatusbar_draw(&statusbars, true); | ||
1103 | action = get_action(CONTEXT_STD, HZ/5); | ||
1104 | if (gui_synclist_do_button(&lists, &action, LIST_WRAP_UNLESS_HELD)) | ||
1105 | continue; | ||
1106 | if (info->action_callback) | ||
1107 | { | ||
1108 | action = info->action_callback(action, &lists); | ||
1109 | if (info->get_name == NULL) | ||
1110 | gui_synclist_set_nb_items(&lists, simplelist_line_count*info->selection_size); | ||
1111 | } | ||
1112 | if (action == ACTION_STD_CANCEL) | ||
1113 | break; | ||
1114 | else if ((action == ACTION_REDRAW) || (old_line_count == simplelist_line_count)) | ||
1115 | { | ||
1116 | if (info->get_name == NULL) | ||
1117 | gui_synclist_set_nb_items(&lists, simplelist_line_count*info->selection_size); | ||
1118 | gui_synclist_draw(&lists); | ||
1119 | } | ||
1120 | else if(default_event_handler(action) == SYS_USB_CONNECTED) | ||
1121 | return true; | ||
1122 | } | ||
1123 | return false; | ||
1124 | } | ||
1125 | |||
1126 | |||
1127 | |||
1128 | |||
1129 | |||
1130 | |||
1131 | |||
1132 | |||
1133 | |||