summaryrefslogtreecommitdiff
path: root/apps/plugins/text_viewer/tv_window.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/text_viewer/tv_window.c')
-rw-r--r--apps/plugins/text_viewer/tv_window.c111
1 files changed, 43 insertions, 68 deletions
diff --git a/apps/plugins/text_viewer/tv_window.c b/apps/plugins/text_viewer/tv_window.c
index 1ffc921a85..c733d5a088 100644
--- a/apps/plugins/text_viewer/tv_window.c
+++ b/apps/plugins/text_viewer/tv_window.c
@@ -50,8 +50,6 @@ static int col_width;
50static int cur_window; 50static int cur_window;
51static int cur_column; 51static int cur_column;
52 52
53static const struct tv_preferences *prefs = NULL;
54
55#ifdef HAVE_LCD_BITMAP 53#ifdef HAVE_LCD_BITMAP
56static bool tv_set_font(const unsigned char *font) 54static bool tv_set_font(const unsigned char *font)
57{ 55{
@@ -69,46 +67,25 @@ static bool tv_set_font(const unsigned char *font)
69 return true; 67 return true;
70} 68}
71 69
72static void tv_check_header_and_footer(void)
73{
74 struct tv_preferences new_prefs;
75
76 tv_copy_preferences(&new_prefs);
77
78 if (rb->global_settings->statusbar != STATUSBAR_TOP)
79 {
80 if (new_prefs.header_mode == HD_SBAR)
81 new_prefs.header_mode = HD_NONE;
82 else if (new_prefs.header_mode == HD_BOTH)
83 new_prefs.header_mode = HD_PATH;
84 }
85 if (rb->global_settings->statusbar != STATUSBAR_BOTTOM)
86 {
87 if (new_prefs.footer_mode == FT_SBAR)
88 new_prefs.footer_mode = FT_NONE;
89 else if (new_prefs.footer_mode == FT_BOTH)
90 new_prefs.footer_mode = FT_PAGE;
91 }
92 tv_set_preferences(&new_prefs);
93}
94
95static void tv_show_header(void) 70static void tv_show_header(void)
96{ 71{
97 if (prefs->header_mode == HD_SBAR || prefs->header_mode == HD_BOTH) 72 unsigned header_mode = header_mode;
73 if (header_mode == HD_SBAR || header_mode == HD_BOTH)
98 rb->gui_syncstatusbar_draw(rb->statusbars, true); 74 rb->gui_syncstatusbar_draw(rb->statusbars, true);
99 75
100 if (prefs->header_mode == HD_PATH || prefs->header_mode == HD_BOTH) 76 if (header_mode == HD_PATH || header_mode == HD_BOTH)
101 rb->lcd_putsxy(0, header_height - prefs->font->height, prefs->file_name); 77 rb->lcd_putsxy(0, header_height - preferences->font->height, preferences->file_name);
102} 78}
103 79
104static void tv_show_footer(const struct tv_screen_pos *pos) 80static void tv_show_footer(const struct tv_screen_pos *pos)
105{ 81{
106 unsigned char buf[12]; 82 unsigned char buf[12];
83 unsigned footer_mode = preferences->footer_mode;
107 84
108 if (prefs->footer_mode == FT_SBAR || prefs->footer_mode == FT_BOTH) 85 if (footer_mode == FT_SBAR || footer_mode == FT_BOTH)
109 rb->gui_syncstatusbar_draw(rb->statusbars, true); 86 rb->gui_syncstatusbar_draw(rb->statusbars, true);
110 87
111 if (prefs->footer_mode == FT_PAGE || prefs->footer_mode == FT_BOTH) 88 if (footer_mode == FT_PAGE || footer_mode == FT_BOTH)
112 { 89 {
113 if (pos->line == 0) 90 if (pos->line == 0)
114 rb->snprintf(buf, sizeof(buf), "%d", pos->page + 1); 91 rb->snprintf(buf, sizeof(buf), "%d", pos->page + 1);
@@ -128,9 +105,9 @@ static void tv_show_scrollbar(off_t cur_pos, int size)
128 int sb_height; 105 int sb_height;
129 106
130 sb_height = LCD_HEIGHT - header_height - footer_height; 107 sb_height = LCD_HEIGHT - header_height - footer_height;
131 if (prefs->horizontal_scrollbar) 108 if (preferences->horizontal_scrollbar)
132 { 109 {
133 items = prefs->windows * window_columns; 110 items = preferences->windows * window_columns;
134 min_shown = cur_window * window_columns + cur_column; 111 min_shown = cur_window * window_columns + cur_column;
135 max_shown = min_shown + window_columns; 112 max_shown = min_shown + window_columns;
136 sb_width = (need_vertical_scrollbar)? TV_SCROLLBAR_WIDTH : 0; 113 sb_width = (need_vertical_scrollbar)? TV_SCROLLBAR_WIDTH : 0;
@@ -157,25 +134,27 @@ static void tv_show_scrollbar(off_t cur_pos, int size)
157 134
158static int tv_calc_display_lines(void) 135static int tv_calc_display_lines(void)
159{ 136{
160 int scrollbar_height = (prefs->horizontal_scrollbar)? TV_SCROLLBAR_HEIGHT : 0; 137 int scrollbar_height = preferences->horizontal_scrollbar ? TV_SCROLLBAR_HEIGHT : 0;
138 unsigned header_mode = preferences->header_mode;
139 unsigned footer_mode = preferences->footer_mode;
161 140
162 header_height = (prefs->header_mode == HD_SBAR || prefs->header_mode == HD_BOTH)? 141 header_height = (header_mode == HD_SBAR || header_mode == HD_BOTH)?
163 STATUSBAR_HEIGHT : 0; 142 STATUSBAR_HEIGHT : 0;
164 143
165 footer_height = (prefs->footer_mode == FT_SBAR || prefs->footer_mode == FT_BOTH)? 144 footer_height = (footer_mode == FT_SBAR || footer_mode == FT_BOTH)?
166 STATUSBAR_HEIGHT : 0; 145 STATUSBAR_HEIGHT : 0;
167 146
168 if (prefs->header_mode == HD_NONE || prefs->header_mode == HD_PATH || 147 if (header_mode == HD_NONE || header_mode == HD_PATH ||
169 prefs->footer_mode == FT_NONE || prefs->footer_mode == FT_PAGE) 148 footer_mode == FT_NONE || footer_mode == FT_PAGE)
170 rb->gui_syncstatusbar_draw(rb->statusbars, false); 149 rb->gui_syncstatusbar_draw(rb->statusbars, false);
171 150
172 if (prefs->header_mode == HD_PATH || prefs->header_mode == HD_BOTH) 151 if (header_mode == HD_PATH || header_mode == HD_BOTH)
173 header_height += prefs->font->height; 152 header_height += preferences->font->height;
174 153
175 if (prefs->footer_mode == FT_PAGE || prefs->footer_mode == FT_BOTH) 154 if (footer_mode == FT_PAGE || footer_mode == FT_BOTH)
176 footer_height += prefs->font->height; 155 footer_height += preferences->font->height;
177 156
178 return (LCD_HEIGHT - header_height - footer_height - scrollbar_height) / prefs->font->height; 157 return (LCD_HEIGHT - header_height - footer_height - scrollbar_height) / preferences->font->height;
179} 158}
180#endif 159#endif
181 160
@@ -195,8 +174,8 @@ static void tv_show_bookmarks(const struct tv_screen_pos *top_pos)
195 if (line >= 0 && line < display_lines) 174 if (line >= 0 && line < display_lines)
196 { 175 {
197#ifdef HAVE_LCD_BITMAP 176#ifdef HAVE_LCD_BITMAP
198 rb->lcd_fillrect(start_width, header_height + line * prefs->font->height, 177 rb->lcd_fillrect(start_width, header_height + line * preferences->font->height,
199 window_width, prefs->font->height); 178 window_width, preferences->font->height);
200#else 179#else
201 rb->lcd_putc(start_width - 1, line, TV_BOOKMARK_ICON); 180 rb->lcd_putc(start_width - 1, line, TV_BOOKMARK_ICON);
202#endif 181#endif
@@ -215,30 +194,30 @@ void tv_draw_window(void)
215 int offset = cur_column * col_width; 194 int offset = cur_column * col_width;
216 int size = 0; 195 int size = 0;
217 int line_width; 196 int line_width;
218 int draw_width = (prefs->windows - cur_window) * LCD_WIDTH - offset; 197 int draw_width = (preferences->windows - cur_window) * LCD_WIDTH - offset;
219 int dx = start_width - offset; 198 int dx = start_width - offset;
220 199
221 tv_copy_screen_pos(&pos); 200 tv_copy_screen_pos(&pos);
222 rb->lcd_clear_display(); 201 rb->lcd_clear_display();
223 202
224 if (prefs->alignment == LEFT) 203 if (preferences->alignment == LEFT)
225 tv_read_start(cur_window, (cur_column > 0)); 204 tv_read_start(cur_window, (cur_column > 0));
226 else 205 else
227 tv_read_start(0, prefs->windows > 1); 206 tv_read_start(0, preferences->windows > 1);
228 207
229 for (line = 0; line < display_lines; line++) 208 for (line = 0; line < display_lines; line++)
230 { 209 {
231 if (!tv_get_next_line(&line_buf)) 210 if (!tv_get_next_line(&line_buf))
232 break; 211 break;
233 212
234 if (prefs->alignment == RIGHT) 213 if (preferences->alignment == RIGHT)
235 { 214 {
236 rb->lcd_getstringsize(line_buf, &line_width, NULL); 215 rb->lcd_getstringsize(line_buf, &line_width, NULL);
237 dx = draw_width - line_width; 216 dx = draw_width - line_width;
238 } 217 }
239 218
240#ifdef HAVE_LCD_BITMAP 219#ifdef HAVE_LCD_BITMAP
241 rb->lcd_putsxy(dx, header_height + line * prefs->font->height, line_buf); 220 rb->lcd_putsxy(dx, header_height + line * preferences->font->height, line_buf);
242#else 221#else
243 rb->lcd_puts(dx, line, line_buf); 222 rb->lcd_puts(dx, line, line_buf);
244#endif 223#endif
@@ -284,12 +263,13 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
284 font_str = (oldp && !font_changing)? oldp->font_name : rb->global_settings->font_file; 263 font_str = (oldp && !font_changing)? oldp->font_name : rb->global_settings->font_file;
285 264
286 /* change font */ 265 /* change font */
287 if (font_changing || rb->strcmp(font_str, prefs->font_name)) 266 if (font_changing || rb->strcmp(font_str, preferences->font_name))
288 { 267 {
289 font_changing = true; 268 font_changing = true;
290 if (!tv_set_font(prefs->font_name)) 269 if (!tv_set_font(preferences->font_name))
291 { 270 {
292 struct tv_preferences new_prefs = *prefs; 271 struct tv_preferences new_prefs;
272 tv_copy_preferences(&new_prefs);
293 273
294 rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH); 274 rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
295 tv_set_preferences(&new_prefs); 275 tv_set_preferences(&new_prefs);
@@ -299,7 +279,6 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
299 font_changing = false; 279 font_changing = false;
300 280
301 /* calculates display lines */ 281 /* calculates display lines */
302 tv_check_header_and_footer();
303 display_lines = tv_calc_display_lines(); 282 display_lines = tv_calc_display_lines();
304#else 283#else
305 (void)oldp; 284 (void)oldp;
@@ -309,12 +288,12 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
309#endif 288#endif
310 289
311#ifdef HAVE_LCD_BITMAP 290#ifdef HAVE_LCD_BITMAP
312 col_width = 2 * rb->font_get_width(prefs->font, ' '); 291 col_width = 2 * rb->font_get_width(preferences->font, ' ');
313#else 292#else
314 col_width = 1; 293 col_width = 1;
315#endif 294#endif
316 295
317 if (cur_window >= prefs->windows) 296 if (cur_window >= preferences->windows)
318 cur_window = 0; 297 cur_window = 0;
319 298
320 window_width = LCD_WIDTH; 299 window_width = LCD_WIDTH;
@@ -322,8 +301,8 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
322 need_vertical_scrollbar = false; 301 need_vertical_scrollbar = false;
323 start_width = 0; 302 start_width = 0;
324 tv_seek_top(); 303 tv_seek_top();
325 tv_set_read_conditions(prefs->windows, window_width); 304 tv_set_read_conditions(preferences->windows, window_width);
326 if (tv_traverse_lines() && prefs->vertical_scrollbar) 305 if (tv_traverse_lines() && preferences->vertical_scrollbar)
327 { 306 {
328 need_vertical_scrollbar = true; 307 need_vertical_scrollbar = true;
329 start_width = TV_SCROLLBAR_WIDTH; 308 start_width = TV_SCROLLBAR_WIDTH;
@@ -337,17 +316,13 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
337 316
338 cur_column = 0; 317 cur_column = 0;
339 318
340 tv_set_read_conditions(prefs->windows, window_width); 319 tv_set_read_conditions(preferences->windows, window_width);
341} 320}
342 321
343bool tv_init_window(unsigned char *buf, size_t bufsize, size_t *used_size) 322bool tv_init_window(void)
344{ 323{
345 tv_add_preferences_change_listner(tv_change_preferences); 324 tv_add_preferences_change_listner(tv_change_preferences);
346 if (!tv_init_text_reader(buf, bufsize, used_size)) 325 return tv_init_text_reader();
347 return false;
348
349 prefs = tv_get_preferences();
350 return true;
351} 326}
352 327
353void tv_finalize_window(void) 328void tv_finalize_window(void)
@@ -356,7 +331,7 @@ void tv_finalize_window(void)
356 331
357#ifdef HAVE_LCD_BITMAP 332#ifdef HAVE_LCD_BITMAP
358 /* restore font */ 333 /* restore font */
359 if (rb->strcmp(rb->global_settings->font_file, prefs->font_name)) 334 if (rb->strcmp(rb->global_settings->font_file, preferences->font_name))
360 { 335 {
361 tv_set_font(rb->global_settings->font_file); 336 tv_set_font(rb->global_settings->font_file);
362 } 337 }
@@ -373,9 +348,9 @@ void tv_move_window(int window_delta, int column_delta)
373 cur_window = 0; 348 cur_window = 0;
374 cur_column = 0; 349 cur_column = 0;
375 } 350 }
376 else if (cur_window >= prefs->windows) 351 else if (cur_window >= preferences->windows)
377 { 352 {
378 cur_window = prefs->windows - 1; 353 cur_window = preferences->windows - 1;
379 cur_column = 0; 354 cur_column = 0;
380 } 355 }
381 356
@@ -391,7 +366,7 @@ void tv_move_window(int window_delta, int column_delta)
391 } 366 }
392 else 367 else
393 { 368 {
394 if (cur_window == prefs->windows - 1) 369 if (cur_window == preferences->windows - 1)
395 cur_column = 0; 370 cur_column = 0;
396 else if (cur_column >= window_columns) 371 else if (cur_column >= window_columns)
397 { 372 {