summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2010-06-20 21:53:47 +0000
committerRafaël Carré <rafael.carre@gmail.com>2010-06-20 21:53:47 +0000
commit298316d19297eea82869b63235b535e5904fc0dd (patch)
tree0426e9c8cecac7532a88888e78e5e54ea9bb6145 /apps
parent17a2f9d8d2dfddd8d2d81ff638e21302efef1c8e (diff)
downloadrockbox-298316d19297eea82869b63235b535e5904fc0dd.tar.gz
rockbox-298316d19297eea82869b63235b535e5904fc0dd.zip
text_viewer: cleanup & bugfix
cleanup: - don't use enum in struct / return values - don't use a getter for preferences but a global pointer - explicitely make enums start at 0 - use static tables for header/footer settings - remove unneeded memset before strlcpy - use static buffer allocation, not dynamic - check header/footer preferences before using the callbacks - don't include font filename in archos player preferences (break file format) bugfix: - statically allocate old preferences in tv_set_preferences() Sometimes I can read a file on Clipv2, but it still aborts quite often refs: FS#11399 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26998 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/text_viewer/text_viewer.c13
-rw-r--r--apps/plugins/text_viewer/tv_action.c45
-rw-r--r--apps/plugins/text_viewer/tv_action.h18
-rw-r--r--apps/plugins/text_viewer/tv_bookmark.c2
-rw-r--r--apps/plugins/text_viewer/tv_menu.c53
-rw-r--r--apps/plugins/text_viewer/tv_menu.h6
-rw-r--r--apps/plugins/text_viewer/tv_pager.c19
-rw-r--r--apps/plugins/text_viewer/tv_pager.h11
-rw-r--r--apps/plugins/text_viewer/tv_preferences.c72
-rw-r--r--apps/plugins/text_viewer/tv_preferences.h144
-rw-r--r--apps/plugins/text_viewer/tv_reader.c23
-rw-r--r--apps/plugins/text_viewer/tv_reader.h11
-rw-r--r--apps/plugins/text_viewer/tv_settings.c12
-rw-r--r--apps/plugins/text_viewer/tv_text_processor.c68
-rw-r--r--apps/plugins/text_viewer/tv_text_processor.h14
-rw-r--r--apps/plugins/text_viewer/tv_text_reader.c14
-rw-r--r--apps/plugins/text_viewer/tv_text_reader.h11
-rw-r--r--apps/plugins/text_viewer/tv_window.c111
-rw-r--r--apps/plugins/text_viewer/tv_window.h11
19 files changed, 275 insertions, 383 deletions
diff --git a/apps/plugins/text_viewer/text_viewer.c b/apps/plugins/text_viewer/text_viewer.c
index fae2f071aa..4817710cb3 100644
--- a/apps/plugins/text_viewer/text_viewer.c
+++ b/apps/plugins/text_viewer/text_viewer.c
@@ -35,7 +35,6 @@ enum plugin_status plugin_start(const void* file)
35 long old_tick; 35 long old_tick;
36 bool done = false; 36 bool done = false;
37 bool display_update = true; 37 bool display_update = true;
38 const struct tv_preferences *prefs = tv_get_preferences();
39 38
40 old_tick = *rb->current_tick; 39 old_tick = *rb->current_tick;
41 40
@@ -66,7 +65,7 @@ enum plugin_status plugin_start(const void* file)
66 case TV_MENU2: 65 case TV_MENU2:
67#endif 66#endif
68 { 67 {
69 enum tv_menu_result res = tv_menu(); 68 unsigned res = tv_menu();
70 69
71 if (res != TV_MENU_RESULT_EXIT_MENU) 70 if (res != TV_MENU_RESULT_EXIT_MENU)
72 { 71 {
@@ -108,13 +107,13 @@ enum plugin_status plugin_start(const void* file)
108 107
109 case TV_SCREEN_LEFT: 108 case TV_SCREEN_LEFT:
110 case TV_SCREEN_LEFT | BUTTON_REPEAT: 109 case TV_SCREEN_LEFT | BUTTON_REPEAT:
111 if (prefs->windows > 1) 110 if (preferences->windows > 1)
112 { 111 {
113 /* Screen left */ 112 /* Screen left */
114 tv_scroll_left(TV_HORIZONTAL_SCROLL_PREFS); 113 tv_scroll_left(TV_HORIZONTAL_SCROLL_PREFS);
115 } 114 }
116 else { /* prefs->windows == 1 */ 115 else { /* prefs->windows == 1 */
117 if (prefs->narrow_mode == NM_PAGE) 116 if (preferences->narrow_mode == NM_PAGE)
118 { 117 {
119 /* scroll to previous page */ 118 /* scroll to previous page */
120 tv_scroll_up(TV_VERTICAL_SCROLL_PAGE); 119 tv_scroll_up(TV_VERTICAL_SCROLL_PAGE);
@@ -129,13 +128,13 @@ enum plugin_status plugin_start(const void* file)
129 128
130 case TV_SCREEN_RIGHT: 129 case TV_SCREEN_RIGHT:
131 case TV_SCREEN_RIGHT | BUTTON_REPEAT: 130 case TV_SCREEN_RIGHT | BUTTON_REPEAT:
132 if (prefs->windows > 1) 131 if (preferences->windows > 1)
133 { 132 {
134 /* Screen right */ 133 /* Screen right */
135 tv_scroll_right(TV_HORIZONTAL_SCROLL_PREFS); 134 tv_scroll_right(TV_HORIZONTAL_SCROLL_PREFS);
136 } 135 }
137 else { /* prefs->windows == 1 */ 136 else { /* prefs->windows == 1 */
138 if (prefs->narrow_mode == NM_PAGE) 137 if (preferences->narrow_mode == NM_PAGE)
139 { 138 {
140 /* scroll to next page */ 139 /* scroll to next page */
141 tv_scroll_down(TV_VERTICAL_SCROLL_PAGE); 140 tv_scroll_down(TV_VERTICAL_SCROLL_PAGE);
@@ -206,7 +205,7 @@ enum plugin_status plugin_start(const void* file)
206 } 205 }
207 if (autoscroll) 206 if (autoscroll)
208 { 207 {
209 if(old_tick <= *rb->current_tick - (110 - prefs->autoscroll_speed * 10)) 208 if(old_tick <= *rb->current_tick - (110 - preferences->autoscroll_speed * 10))
210 { 209 {
211 tv_scroll_down(TV_VERTICAL_SCROLL_PREFS); 210 tv_scroll_down(TV_VERTICAL_SCROLL_PREFS);
212 old_tick = *rb->current_tick; 211 old_tick = *rb->current_tick;
diff --git a/apps/plugins/text_viewer/tv_action.c b/apps/plugins/text_viewer/tv_action.c
index 53a29ef021..546ee99842 100644
--- a/apps/plugins/text_viewer/tv_action.c
+++ b/apps/plugins/text_viewer/tv_action.c
@@ -28,27 +28,12 @@
28#include "tv_settings.h" 28#include "tv_settings.h"
29#include "tv_window.h" 29#include "tv_window.h"
30 30
31static const struct tv_preferences *prefs;
32
33bool tv_init(const unsigned char *file) 31bool tv_init(const unsigned char *file)
34{ 32{
35 size_t req_size = 0;
36 size_t size;
37 size_t used_size;
38 unsigned char *buffer;
39
40 /* get the plugin buffer */
41 buffer = rb->plugin_get_buffer(&req_size);
42 size = req_size;
43 if (buffer == NULL || size == 0)
44 return false;
45
46 prefs = tv_get_preferences();
47
48 tv_init_bookmark(); 33 tv_init_bookmark();
49 34
50 /* initialize modules */ 35 /* initialize modules */
51 if (!tv_init_window(buffer, size, &used_size)) 36 if (!tv_init_window())
52 return false; 37 return false;
53 38
54 /* load the preferences and bookmark */ 39 /* load the preferences and bookmark */
@@ -83,45 +68,45 @@ void tv_draw(void)
83 tv_move_screen(pos.page, pos.line, SEEK_SET); 68 tv_move_screen(pos.page, pos.line, SEEK_SET);
84} 69}
85 70
86void tv_scroll_up(enum tv_vertical_scroll_mode mode) 71void tv_scroll_up(unsigned mode)
87{ 72{
88 int offset_page = 0; 73 int offset_page = 0;
89 int offset_line = -1; 74 int offset_line = -1;
90 75
91 if ((mode == TV_VERTICAL_SCROLL_PAGE) || 76 if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
92 (mode == TV_VERTICAL_SCROLL_PREFS && prefs->vertical_scroll_mode == PAGE)) 77 (mode == TV_VERTICAL_SCROLL_PREFS && preferences->vertical_scroll_mode == PAGE))
93 { 78 {
94 offset_page--; 79 offset_page--;
95#ifdef HAVE_LCD_BITMAP 80#ifdef HAVE_LCD_BITMAP
96 offset_line = (prefs->page_mode == OVERLAP)? 1:0; 81 offset_line = (preferences->page_mode == OVERLAP)? 1:0;
97#endif 82#endif
98 } 83 }
99 tv_move_screen(offset_page, offset_line, SEEK_CUR); 84 tv_move_screen(offset_page, offset_line, SEEK_CUR);
100} 85}
101 86
102void tv_scroll_down(enum tv_vertical_scroll_mode mode) 87void tv_scroll_down(unsigned mode)
103{ 88{
104 int offset_page = 0; 89 int offset_page = 0;
105 int offset_line = 1; 90 int offset_line = 1;
106 91
107 if ((mode == TV_VERTICAL_SCROLL_PAGE) || 92 if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
108 (mode == TV_VERTICAL_SCROLL_PREFS && prefs->vertical_scroll_mode == PAGE)) 93 (mode == TV_VERTICAL_SCROLL_PREFS && preferences->vertical_scroll_mode == PAGE))
109 { 94 {
110 offset_page++; 95 offset_page++;
111#ifdef HAVE_LCD_BITMAP 96#ifdef HAVE_LCD_BITMAP
112 offset_line = (prefs->page_mode == OVERLAP)? -1:0; 97 offset_line = (preferences->page_mode == OVERLAP)? -1:0;
113#endif 98#endif
114 } 99 }
115 tv_move_screen(offset_page, offset_line, SEEK_CUR); 100 tv_move_screen(offset_page, offset_line, SEEK_CUR);
116} 101}
117 102
118void tv_scroll_left(enum tv_horizontal_scroll_mode mode) 103void tv_scroll_left(unsigned mode)
119{ 104{
120 int offset_window = 0; 105 int offset_window = 0;
121 int offset_column = 0; 106 int offset_column = 0;
122 107
123 if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) || 108 if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) ||
124 (mode == TV_HORIZONTAL_SCROLL_PREFS && prefs->horizontal_scroll_mode == COLUMN)) 109 (mode == TV_HORIZONTAL_SCROLL_PREFS && preferences->horizontal_scroll_mode == COLUMN))
125 { 110 {
126 /* Scroll left one column */ 111 /* Scroll left one column */
127 offset_column--; 112 offset_column--;
@@ -134,13 +119,13 @@ void tv_scroll_left(enum tv_horizontal_scroll_mode mode)
134 tv_move_window(offset_window, offset_column); 119 tv_move_window(offset_window, offset_column);
135} 120}
136 121
137void tv_scroll_right(enum tv_horizontal_scroll_mode mode) 122void tv_scroll_right(unsigned mode)
138{ 123{
139 int offset_window = 0; 124 int offset_window = 0;
140 int offset_column = 0; 125 int offset_column = 0;
141 126
142 if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) || 127 if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) ||
143 (mode == TV_HORIZONTAL_SCROLL_PREFS && prefs->horizontal_scroll_mode == COLUMN)) 128 (mode == TV_HORIZONTAL_SCROLL_PREFS && preferences->horizontal_scroll_mode == COLUMN))
144 { 129 {
145 /* Scroll right one column */ 130 /* Scroll right one column */
146 offset_column++; 131 offset_column++;
@@ -161,13 +146,13 @@ void tv_top(void)
161void tv_bottom(void) 146void tv_bottom(void)
162{ 147{
163 tv_move_screen(0, 0, SEEK_END); 148 tv_move_screen(0, 0, SEEK_END);
164 if (prefs->vertical_scroll_mode == PAGE) 149 if (preferences->vertical_scroll_mode == PAGE)
165 tv_move_screen(0, -tv_get_screen_pos()->line, SEEK_CUR); 150 tv_move_screen(0, -tv_get_screen_pos()->line, SEEK_CUR);
166} 151}
167 152
168enum tv_menu_result tv_menu(void) 153unsigned tv_menu(void)
169{ 154{
170 enum tv_menu_result res; 155 unsigned res;
171 struct tv_screen_pos cur_pos; 156 struct tv_screen_pos cur_pos;
172 off_t cur_file_pos = tv_get_screen_pos()->file_pos; 157 off_t cur_file_pos = tv_get_screen_pos()->file_pos;
173 158
@@ -176,7 +161,7 @@ enum tv_menu_result tv_menu(void)
176 if (res == TV_MENU_RESULT_EXIT_MENU) 161 if (res == TV_MENU_RESULT_EXIT_MENU)
177 { 162 {
178 tv_convert_fpos(cur_file_pos, &cur_pos); 163 tv_convert_fpos(cur_file_pos, &cur_pos);
179 if (prefs->vertical_scroll_mode == PAGE) 164 if (preferences->vertical_scroll_mode == PAGE)
180 cur_pos.line = 0; 165 cur_pos.line = 0;
181 166
182 tv_move_screen(cur_pos.page, cur_pos.line, SEEK_SET); 167 tv_move_screen(cur_pos.page, cur_pos.line, SEEK_SET);
diff --git a/apps/plugins/text_viewer/tv_action.h b/apps/plugins/text_viewer/tv_action.h
index b01079cbd1..f774f07422 100644
--- a/apps/plugins/text_viewer/tv_action.h
+++ b/apps/plugins/text_viewer/tv_action.h
@@ -26,17 +26,17 @@
26#include "tv_menu.h" 26#include "tv_menu.h"
27 27
28/* horizontal scroll mode */ 28/* horizontal scroll mode */
29enum tv_horizontal_scroll_mode 29enum
30{ 30{
31 TV_HORIZONTAL_SCROLL_COLUMN, /* left/right one column */ 31 TV_HORIZONTAL_SCROLL_COLUMN = 0, /* left/right one column */
32 TV_HORIZONTAL_SCROLL_SCREEN, /* left/right one screen */ 32 TV_HORIZONTAL_SCROLL_SCREEN, /* left/right one screen */
33 TV_HORIZONTAL_SCROLL_PREFS, /* left/right follows the settings */ 33 TV_HORIZONTAL_SCROLL_PREFS, /* left/right follows the settings */
34}; 34};
35 35
36/*vertical scroll mode */ 36/*vertical scroll mode */
37enum tv_vertical_scroll_mode 37enum
38{ 38{
39 TV_VERTICAL_SCROLL_LINE, /* up/down one line */ 39 TV_VERTICAL_SCROLL_LINE = 0, /* up/down one line */
40 TV_VERTICAL_SCROLL_PAGE, /* up/down one page */ 40 TV_VERTICAL_SCROLL_PAGE, /* up/down one page */
41 TV_VERTICAL_SCROLL_PREFS, /* up/down follows the settings */ 41 TV_VERTICAL_SCROLL_PREFS, /* up/down follows the settings */
42}; 42};
@@ -70,7 +70,7 @@ void tv_draw(void);
70 * [In] mode 70 * [In] mode
71 * scroll mode 71 * scroll mode
72 */ 72 */
73void tv_scroll_up(enum tv_vertical_scroll_mode mode); 73void tv_scroll_up(unsigned mode);
74 74
75/* 75/*
76 * scroll down 76 * scroll down
@@ -78,7 +78,7 @@ void tv_scroll_up(enum tv_vertical_scroll_mode mode);
78 * [In] mode 78 * [In] mode
79 * scroll mode 79 * scroll mode
80 */ 80 */
81void tv_scroll_down(enum tv_vertical_scroll_mode mode); 81void tv_scroll_down(unsigned mode);
82 82
83/* 83/*
84 * scroll left 84 * scroll left
@@ -86,7 +86,7 @@ void tv_scroll_down(enum tv_vertical_scroll_mode mode);
86 * [In] mode 86 * [In] mode
87 * scroll mode 87 * scroll mode
88 */ 88 */
89void tv_scroll_left(enum tv_horizontal_scroll_mode mode); 89void tv_scroll_left(unsigned mode);
90 90
91/* 91/*
92 * scroll right 92 * scroll right
@@ -94,7 +94,7 @@ void tv_scroll_left(enum tv_horizontal_scroll_mode mode);
94 * [In] mode 94 * [In] mode
95 * scroll mode 95 * scroll mode
96 */ 96 */
97void tv_scroll_right(enum tv_horizontal_scroll_mode mode); 97void tv_scroll_right(unsigned mode);
98 98
99/* jump to the top */ 99/* jump to the top */
100void tv_top(void); 100void tv_top(void);
@@ -111,7 +111,7 @@ void tv_bottom(void);
111 * TV_MENU_RESULT_EXIT_PLUGIN request to exit this plugin 111 * TV_MENU_RESULT_EXIT_PLUGIN request to exit this plugin
112 * TV_MENU_RESULT_ATTACHED_USB connect USB cable 112 * TV_MENU_RESULT_ATTACHED_USB connect USB cable
113 */ 113 */
114enum tv_menu_result tv_menu(void); 114unsigned tv_menu(void);
115 115
116/* add or remove the bookmark to the current position */ 116/* add or remove the bookmark to the current position */
117void tv_add_or_remove_bookmark(void); 117void tv_add_or_remove_bookmark(void);
diff --git a/apps/plugins/text_viewer/tv_bookmark.c b/apps/plugins/text_viewer/tv_bookmark.c
index 78e4c60a83..d379c924c4 100644
--- a/apps/plugins/text_viewer/tv_bookmark.c
+++ b/apps/plugins/text_viewer/tv_bookmark.c
@@ -224,7 +224,7 @@ void tv_select_bookmark(void)
224 } 224 }
225 225
226 /* move to the select position */ 226 /* move to the select position */
227 if (tv_get_preferences()->vertical_scroll_mode == PAGE) 227 if (preferences->vertical_scroll_mode == PAGE)
228 select_pos.line = 0; 228 select_pos.line = 0;
229 229
230 tv_move_screen(select_pos.page, select_pos.line, SEEK_SET); 230 tv_move_screen(select_pos.page, select_pos.line, SEEK_SET);
diff --git a/apps/plugins/text_viewer/tv_menu.c b/apps/plugins/text_viewer/tv_menu.c
index ce85dc9325..c90386aabc 100644
--- a/apps/plugins/text_viewer/tv_menu.c
+++ b/apps/plugins/text_viewer/tv_menu.c
@@ -219,44 +219,30 @@ static bool tv_alignment_setting(void)
219#ifdef HAVE_LCD_BITMAP 219#ifdef HAVE_LCD_BITMAP
220static bool tv_header_setting(void) 220static bool tv_header_setting(void)
221{ 221{
222 int len = (rb->global_settings->statusbar == STATUSBAR_TOP)? 4 : 2; 222 static const struct opt_items names[4] =
223 struct opt_items names[len];
224
225 names[0].string = "None";
226 names[0].voice_id = -1;
227 names[1].string = "File path";
228 names[1].voice_id = -1;
229
230 if (rb->global_settings->statusbar == STATUSBAR_TOP)
231 { 223 {
232 names[2].string = "Status bar"; 224 {"None", -1},
233 names[2].voice_id = -1; 225 {"File path", -1},
234 names[3].string = "Both"; 226 {"Status bar", -1},
235 names[3].voice_id = -1; 227 {"Both", -1},
236 } 228 };
237 229
230 int len = (rb->global_settings->statusbar == STATUSBAR_TOP)? 4 : 2;
238 return rb->set_option("Show Header", &new_prefs.header_mode, INT, 231 return rb->set_option("Show Header", &new_prefs.header_mode, INT,
239 names, len, NULL); 232 names, len, NULL);
240} 233}
241 234
242static bool tv_footer_setting(void) 235static bool tv_footer_setting(void)
243{ 236{
244 int len = (rb->global_settings->statusbar == STATUSBAR_BOTTOM)? 4 : 2; 237 static const struct opt_items names[4] =
245 struct opt_items names[len];
246
247 names[0].string = "None";
248 names[0].voice_id = -1;
249 names[1].string = "Page Num";
250 names[1].voice_id = -1;
251
252 if (rb->global_settings->statusbar == STATUSBAR_BOTTOM)
253 { 238 {
254 names[2].string = "Status bar"; 239 {"None", -1},
255 names[2].voice_id = -1; 240 {"Page Num", -1},
256 names[3].string = "Both"; 241 {"Status bar", -1},
257 names[3].voice_id = -1; 242 {"Both", -1},
258 } 243 };
259 244
245 int len = (rb->global_settings->statusbar == STATUSBAR_BOTTOM)? 4 : 2;
260 return rb->set_option("Show Footer", &new_prefs.footer_mode, INT, 246 return rb->set_option("Show Footer", &new_prefs.footer_mode, INT,
261 names, len, NULL); 247 names, len, NULL);
262} 248}
@@ -304,10 +290,7 @@ static bool tv_font_setting(void)
304 names, count, NULL); 290 names, count, NULL);
305 291
306 if (new_font != old_font) 292 if (new_font != old_font)
307 {
308 rb->memset(new_prefs.font_name, 0, MAX_PATH);
309 rb->strlcpy(new_prefs.font_name, names[new_font].string, MAX_PATH); 293 rb->strlcpy(new_prefs.font_name, names[new_font].string, MAX_PATH);
310 }
311 294
312 *tree = backup; 295 *tree = backup;
313 rb->set_current_file(backup.currdir); 296 rb->set_current_file(backup.currdir);
@@ -350,9 +333,9 @@ MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON,
350#endif 333#endif
351 &scroll_menu, &indent_spaces_item); 334 &scroll_menu, &indent_spaces_item);
352 335
353static enum tv_menu_result tv_options_menu(void) 336static unsigned tv_options_menu(void)
354{ 337{
355 enum tv_menu_result result = TV_MENU_RESULT_EXIT_MENU; 338 unsigned result = TV_MENU_RESULT_EXIT_MENU;
356 339
357 if (rb->do_menu(&option_menu, NULL, NULL, false) == MENU_ATTACHED_USB) 340 if (rb->do_menu(&option_menu, NULL, NULL, false) == MENU_ATTACHED_USB)
358 result = TV_MENU_RESULT_ATTACHED_USB; 341 result = TV_MENU_RESULT_ATTACHED_USB;
@@ -360,9 +343,9 @@ static enum tv_menu_result tv_options_menu(void)
360 return result; 343 return result;
361} 344}
362 345
363enum tv_menu_result tv_display_menu(void) 346unsigned tv_display_menu(void)
364{ 347{
365 enum tv_menu_result result = TV_MENU_RESULT_EXIT_MENU; 348 unsigned result = TV_MENU_RESULT_EXIT_MENU;
366 349
367 MENUITEM_STRINGLIST(menu, "Viewer Menu", NULL, 350 MENUITEM_STRINGLIST(menu, "Viewer Menu", NULL,
368 "Return", "Viewer Options", 351 "Return", "Viewer Options",
diff --git a/apps/plugins/text_viewer/tv_menu.h b/apps/plugins/text_viewer/tv_menu.h
index 9f28723b87..0db5051192 100644
--- a/apps/plugins/text_viewer/tv_menu.h
+++ b/apps/plugins/text_viewer/tv_menu.h
@@ -23,8 +23,8 @@
23#ifndef PLUGIN_TEXT_VIEWER_MENU_H 23#ifndef PLUGIN_TEXT_VIEWER_MENU_H
24#define PLUGIN_TEXT_VIEWER_MENU_H 24#define PLUGIN_TEXT_VIEWER_MENU_H
25 25
26enum tv_menu_result { 26enum {
27 TV_MENU_RESULT_MOVE_PAGE, 27 TV_MENU_RESULT_MOVE_PAGE = 0,
28 TV_MENU_RESULT_EXIT_MENU, 28 TV_MENU_RESULT_EXIT_MENU,
29 TV_MENU_RESULT_EXIT_PLUGIN, 29 TV_MENU_RESULT_EXIT_PLUGIN,
30 TV_MENU_RESULT_ATTACHED_USB, 30 TV_MENU_RESULT_ATTACHED_USB,
@@ -40,6 +40,6 @@ enum tv_menu_result {
40 * TV_MENU_RESULT_EXIT_PLUGIN request to exit this plugin 40 * TV_MENU_RESULT_EXIT_PLUGIN request to exit this plugin
41 * TV_MENU_RESULT_ATTACHED_USB connect USB cable 41 * TV_MENU_RESULT_ATTACHED_USB connect USB cable
42 */ 42 */
43enum tv_menu_result tv_display_menu(void); 43unsigned tv_display_menu(void);
44 44
45#endif 45#endif
diff --git a/apps/plugins/text_viewer/tv_pager.c b/apps/plugins/text_viewer/tv_pager.c
index d98fe4627d..0c109530f8 100644
--- a/apps/plugins/text_viewer/tv_pager.c
+++ b/apps/plugins/text_viewer/tv_pager.c
@@ -32,9 +32,7 @@
32#define TV_MAX_PAGE 9999 32#define TV_MAX_PAGE 9999
33#endif 33#endif
34 34
35#define TV_PAGER_MEMSIZE (4 * TV_MAX_PAGE) 35static unsigned char pager_buffer[4 * TV_MAX_PAGE];
36
37static unsigned char *pager_buffer;
38 36
39static struct tv_screen_pos cur_pos; 37static struct tv_screen_pos cur_pos;
40 38
@@ -87,12 +85,8 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
87 tv_seek(0, SEEK_SET); 85 tv_seek(0, SEEK_SET);
88} 86}
89 87
90bool tv_init_pager(unsigned char *buf, size_t bufsize, size_t *used_size) 88bool tv_init_pager(void)
91{ 89{
92 if (bufsize < TV_PAGER_MEMSIZE)
93 return false;
94
95 pager_buffer = buf;
96 tv_set_screen_pos(&cur_pos); 90 tv_set_screen_pos(&cur_pos);
97 tv_add_preferences_change_listner(tv_change_preferences); 91 tv_add_preferences_change_listner(tv_change_preferences);
98 92
@@ -101,14 +95,7 @@ bool tv_init_pager(unsigned char *buf, size_t bufsize, size_t *used_size)
101 95
102 line_pos[0] = 0; 96 line_pos[0] = 0;
103 97
104 buf += TV_PAGER_MEMSIZE; 98 return tv_init_reader();
105 bufsize -= TV_PAGER_MEMSIZE;
106 if (!tv_init_reader(buf, bufsize, used_size))
107 return false;
108
109 *used_size += TV_PAGER_MEMSIZE;
110
111 return true;
112} 99}
113 100
114void tv_finalize_pager(void) 101void tv_finalize_pager(void)
diff --git a/apps/plugins/text_viewer/tv_pager.h b/apps/plugins/text_viewer/tv_pager.h
index 798d694ce5..ec1de24b5a 100644
--- a/apps/plugins/text_viewer/tv_pager.h
+++ b/apps/plugins/text_viewer/tv_pager.h
@@ -30,20 +30,11 @@
30/* 30/*
31 * initialize the pager module 31 * initialize the pager module
32 * 32 *
33 * [In] buf
34 * the start pointer of the buffer
35 *
36 * [In] size
37 * enabled buffer size
38 *
39 * [Out] used_size
40 * the size of the buffer which the pager uses
41 *
42 * return 33 * return
43 * true initialize success 34 * true initialize success
44 * false initialize failure 35 * false initialize failure
45 */ 36 */
46bool tv_init_pager(unsigned char *buf, size_t bufsize, size_t *used_size); 37bool tv_init_pager(void);
47 38
48/* finalize the pager module */ 39/* finalize the pager module */
49void tv_finalize_pager(void); 40void tv_finalize_pager(void);
diff --git a/apps/plugins/text_viewer/tv_preferences.c b/apps/plugins/text_viewer/tv_preferences.c
index d317508936..b1045fba7d 100644
--- a/apps/plugins/text_viewer/tv_preferences.c
+++ b/apps/plugins/text_viewer/tv_preferences.c
@@ -23,15 +23,16 @@
23#include "plugin.h" 23#include "plugin.h"
24#include "tv_preferences.h" 24#include "tv_preferences.h"
25 25
26/* global preferences */
26static struct tv_preferences prefs; 27static struct tv_preferences prefs;
27static bool is_initialized = false; 28struct tv_preferences *preferences = &prefs;
29
28static int listner_count = 0; 30static int listner_count = 0;
29 31
30#define TV_MAX_LISTNERS 4 32#define TV_MAX_LISTNERS 4
31static void (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp); 33static void (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp);
32 34
33static void tv_notify_change_preferences(const struct tv_preferences *oldp, 35static void tv_notify_change_preferences(const struct tv_preferences *oldp)
34 const struct tv_preferences *newp)
35{ 36{
36 int i; 37 int i;
37 38
@@ -45,50 +46,62 @@ static void tv_notify_change_preferences(const struct tv_preferences *oldp,
45 * - autoscroll_speed 46 * - autoscroll_speed
46 * - narrow_mode 47 * - narrow_mode
47 */ 48 */
48 if ((oldp == NULL) || 49 if ((oldp == NULL) ||
49 (oldp->word_mode != newp->word_mode) || 50 (oldp->word_mode != preferences->word_mode) ||
50 (oldp->line_mode != newp->line_mode) || 51 (oldp->line_mode != preferences->line_mode) ||
51 (oldp->windows != newp->windows) || 52 (oldp->windows != preferences->windows) ||
52 (oldp->horizontal_scrollbar != newp->horizontal_scrollbar) || 53 (oldp->horizontal_scrollbar != preferences->horizontal_scrollbar) ||
53 (oldp->vertical_scrollbar != newp->vertical_scrollbar) || 54 (oldp->vertical_scrollbar != preferences->vertical_scrollbar) ||
54 (oldp->encoding != newp->encoding) || 55 (oldp->encoding != preferences->encoding) ||
55 (oldp->indent_spaces != newp->indent_spaces) || 56 (oldp->indent_spaces != preferences->indent_spaces) ||
56#ifdef HAVE_LCD_BITMAP 57#ifdef HAVE_LCD_BITMAP
57 (oldp->header_mode != newp->header_mode) || 58 (oldp->header_mode != preferences->header_mode) ||
58 (oldp->footer_mode != newp->footer_mode) || 59 (oldp->footer_mode != preferences->footer_mode) ||
59 (rb->strcmp(oldp->font_name, newp->font_name)) || 60 (rb->strcmp(oldp->font_name, preferences->font_name)) ||
60#endif 61#endif
61 (rb->strcmp(oldp->file_name, newp->file_name))) 62 (rb->strcmp(oldp->file_name, preferences->file_name)))
62 { 63 {
63 for (i = listner_count - 1; i >= 0; i--) 64 for (i = 0; i < listner_count; i++)
64 listners[i](oldp); 65 listners[i](oldp);
65 } 66 }
66} 67}
67 68
68const struct tv_preferences *tv_get_preferences(void) 69static void tv_check_header_and_footer(void)
69{ 70{
70 return &prefs; 71 if (rb->global_settings->statusbar != STATUSBAR_TOP)
72 {
73 if (preferences->header_mode == HD_SBAR)
74 preferences->header_mode = HD_NONE;
75 else if (preferences->header_mode == HD_BOTH)
76 preferences->header_mode = HD_PATH;
77 }
78 if (rb->global_settings->statusbar != STATUSBAR_BOTTOM)
79 {
80 if (preferences->footer_mode == FT_SBAR)
81 preferences->footer_mode = FT_NONE;
82 else if (preferences->footer_mode == FT_BOTH)
83 preferences->footer_mode = FT_PAGE;
84 }
71} 85}
72 86
73void tv_set_preferences(const struct tv_preferences *new_prefs) 87void tv_set_preferences(const struct tv_preferences *new_prefs)
74{ 88{
89 static struct tv_preferences old_prefs;
75 struct tv_preferences *oldp = NULL; 90 struct tv_preferences *oldp = NULL;
76 struct tv_preferences old_prefs; 91 static bool is_initialized = false;
77 92
78 if (!is_initialized) 93 if (is_initialized)
79 is_initialized = true; 94 tv_copy_preferences((oldp = &old_prefs));
80 else 95 is_initialized = true;
81 { 96
82 old_prefs = prefs; 97 rb->memcpy(preferences, new_prefs, sizeof(struct tv_preferences));
83 oldp = &old_prefs; 98 tv_check_header_and_footer();
84 } 99 tv_notify_change_preferences(oldp);
85 rb->memcpy(&prefs, new_prefs, sizeof(struct tv_preferences));
86 tv_notify_change_preferences(oldp, &prefs);
87} 100}
88 101
89void tv_copy_preferences(struct tv_preferences *copy_prefs) 102void tv_copy_preferences(struct tv_preferences *copy_prefs)
90{ 103{
91 rb->memcpy(copy_prefs, &prefs, sizeof(struct tv_preferences)); 104 rb->memcpy(copy_prefs, preferences, sizeof(struct tv_preferences));
92} 105}
93 106
94void tv_set_default_preferences(struct tv_preferences *p) 107void tv_set_default_preferences(struct tv_preferences *p)
@@ -102,7 +115,6 @@ void tv_set_default_preferences(struct tv_preferences *p)
102 p->page_mode = NO_OVERLAP; 115 p->page_mode = NO_OVERLAP;
103 p->horizontal_scrollbar = SB_OFF; 116 p->horizontal_scrollbar = SB_OFF;
104 p->vertical_scrollbar = SB_OFF; 117 p->vertical_scrollbar = SB_OFF;
105 rb->memset(p->font_name, 0, MAX_PATH);
106#ifdef HAVE_LCD_BITMAP 118#ifdef HAVE_LCD_BITMAP
107 p->header_mode = HD_BOTH; 119 p->header_mode = HD_BOTH;
108 p->footer_mode = FT_BOTH; 120 p->footer_mode = FT_BOTH;
diff --git a/apps/plugins/text_viewer/tv_preferences.h b/apps/plugins/text_viewer/tv_preferences.h
index 1e5c45309a..906f5c5f16 100644
--- a/apps/plugins/text_viewer/tv_preferences.h
+++ b/apps/plugins/text_viewer/tv_preferences.h
@@ -23,88 +23,108 @@
23#ifndef PLUGIN_TEXT_VIEWER_PREFERENCES_H 23#ifndef PLUGIN_TEXT_VIEWER_PREFERENCES_H
24#define PLUGIN_TEXT_VIEWER_PREFERENCES_H 24#define PLUGIN_TEXT_VIEWER_PREFERENCES_H
25 25
26enum scrollbar_mode { 26/* scrollbar_mode */
27enum {
27 SB_OFF = 0, 28 SB_OFF = 0,
28 SB_ON, 29 SB_ON,
29}; 30};
30 31
32/* word_mode */
33enum {
34 WRAP = 0,
35 CHOP,
36};
37
38/* line_mode */
39enum {
40 NORMAL = 0,
41 JOIN,
42 EXPAND,
43 REFLOW,
44};
45
46/* alignment */
47enum {
48 LEFT = 0,
49 RIGHT,
50};
51
52/* page_mode */
53enum {
54 NO_OVERLAP = 0,
55 OVERLAP,
56};
57
58/* header_mode */
59enum {
60 HD_NONE = 0,
61 HD_PATH,
62 HD_SBAR,
63 HD_BOTH,
64};
65
66/* footer_mode */
67enum {
68
69 FT_NONE = 0,
70 FT_PAGE,
71 FT_SBAR,
72 FT_BOTH,
73};
74
75/* horizontal_scroll_mode */
76enum {
77 SCREEN = 0,
78 COLUMN,
79};
80
81/* vertical_scroll_mode */
82enum {
83 PAGE = 0,
84 LINE,
85};
86
87/* narrow_mode */
88enum {
89 NM_PAGE = 0,
90 NM_TOP_BOTTOM,
91};
92
31struct tv_preferences { 93struct tv_preferences {
32 enum { 94 unsigned word_mode;
33 WRAP = 0, 95 unsigned line_mode;
34 CHOP, 96 unsigned alignment;
35 } word_mode; 97
36 98 unsigned encoding;
37 enum { 99
38 NORMAL = 0, 100 unsigned horizontal_scrollbar;
39 JOIN, 101 unsigned vertical_scrollbar;
40 EXPAND, 102
41 REFLOW, 103 unsigned page_mode;
42 } line_mode; 104 unsigned header_mode;
43 105 unsigned footer_mode;
44 enum { 106 unsigned horizontal_scroll_mode;
45 LEFT = 0, 107 unsigned vertical_scroll_mode;
46 RIGHT,
47 } alignment;
48
49 enum codepages encoding;
50
51 enum scrollbar_mode horizontal_scrollbar;
52 enum scrollbar_mode vertical_scrollbar;
53
54 enum {
55 NO_OVERLAP = 0,
56 OVERLAP,
57 } page_mode;
58
59 enum {
60 HD_NONE = 0,
61 HD_PATH,
62 HD_SBAR,
63 HD_BOTH,
64 } header_mode;
65
66 enum {
67 FT_NONE = 0,
68 FT_PAGE,
69 FT_SBAR,
70 FT_BOTH,
71 } footer_mode;
72
73 enum {
74 SCREEN = 0,
75 COLUMN,
76 } horizontal_scroll_mode;
77
78 enum {
79 PAGE = 0,
80 LINE,
81 } vertical_scroll_mode;
82 108
83 int autoscroll_speed; 109 int autoscroll_speed;
84 110
85 int windows; 111 int windows;
86 112
87 enum { 113 unsigned narrow_mode;
88 NM_PAGE = 0,
89 NM_TOP_BOTTOM,
90 } narrow_mode;
91 114
92 int indent_spaces; 115 unsigned indent_spaces;
93 116
94 unsigned char font_name[MAX_PATH];
95#ifdef HAVE_LCD_BITMAP 117#ifdef HAVE_LCD_BITMAP
118 unsigned char font_name[MAX_PATH];
96 struct font *font; 119 struct font *font;
97#endif 120#endif
98 unsigned char file_name[MAX_PATH]; 121 unsigned char file_name[MAX_PATH];
99}; 122};
100 123
101/* 124/*
102 * return the preferences 125 * global pointer to the preferences
103 *
104 * return
105 * the pointer the preferences
106 */ 126 */
107const struct tv_preferences *tv_get_preferences(void); 127extern struct tv_preferences *preferences;
108 128
109/* 129/*
110 * change the preferences 130 * change the preferences
diff --git a/apps/plugins/text_viewer/tv_reader.c b/apps/plugins/text_viewer/tv_reader.c
index 6dc66ef567..4e91af9f98 100644
--- a/apps/plugins/text_viewer/tv_reader.c
+++ b/apps/plugins/text_viewer/tv_reader.c
@@ -135,7 +135,6 @@ void tv_seek(off_t offset, int whence)
135static void tv_change_preferences(const struct tv_preferences *oldp) 135static void tv_change_preferences(const struct tv_preferences *oldp)
136{ 136{
137 unsigned char bom[BOM_SIZE]; 137 unsigned char bom[BOM_SIZE];
138 const struct tv_preferences *prefs = tv_get_preferences();
139 int cur_start_file_pos = start_file_pos; 138 int cur_start_file_pos = start_file_pos;
140 off_t cur_file_pos = file_pos + buf_pos; 139 off_t cur_file_pos = file_pos + buf_pos;
141 140
@@ -145,21 +144,21 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
145 start_file_pos = 0; 144 start_file_pos = 0;
146 145
147 /* open the new file */ 146 /* open the new file */
148 if (oldp == NULL || rb->strcmp(oldp->file_name, prefs->file_name)) 147 if (oldp == NULL || rb->strcmp(oldp->file_name, preferences->file_name))
149 { 148 {
150 if (fd >= 0) 149 if (fd >= 0)
151 rb->close(fd); 150 rb->close(fd);
152 151
153 fd = rb->open(prefs->file_name, O_RDONLY); 152 fd = rb->open(preferences->file_name, O_RDONLY);
154 if (fd < 0) 153 if (fd < 0)
155 return; 154 return;
156 } 155 }
157 156
158 /* 157 /*
159 * When a file is UTF-8 file with BOM, if prefs.encoding is UTF-8, 158 * When a file is UTF-8 file with BOM, if encoding is UTF-8,
160 * then file size decreases only BOM_SIZE. 159 * then file size decreases only BOM_SIZE.
161 */ 160 */
162 if (prefs->encoding == UTF_8) 161 if (preferences->encoding == UTF_8)
163 { 162 {
164 rb->lseek(fd, 0, SEEK_SET); 163 rb->lseek(fd, 0, SEEK_SET);
165 rb->read(fd, bom, BOM_SIZE); 164 rb->read(fd, bom, BOM_SIZE);
@@ -171,16 +170,20 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
171 tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET); 170 tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET);
172} 171}
173 172
174bool tv_init_reader(unsigned char *buf, size_t bufsize, size_t *used_size) 173bool tv_init_reader(void)
175{ 174{
176 if (bufsize < 2 * TV_MIN_BLOCK_SIZE) 175 size_t size;
176
177 /* get the plugin buffer */
178 reader_buffer = rb->plugin_get_buffer(&size);
179
180 if (size < 2 * TV_MIN_BLOCK_SIZE)
177 return false; 181 return false;
178 182
179 reader_buffer = buf; 183 block_size = size / 2;
180 block_size = bufsize / 2;
181 buffer_size = 2 * block_size; 184 buffer_size = 2 * block_size;
182 *used_size = buffer_size;
183 tv_add_preferences_change_listner(tv_change_preferences); 185 tv_add_preferences_change_listner(tv_change_preferences);
186
184 return true; 187 return true;
185} 188}
186 189
diff --git a/apps/plugins/text_viewer/tv_reader.h b/apps/plugins/text_viewer/tv_reader.h
index 464af1027a..2ee0b828ab 100644
--- a/apps/plugins/text_viewer/tv_reader.h
+++ b/apps/plugins/text_viewer/tv_reader.h
@@ -28,20 +28,11 @@
28/* 28/*
29 * initialize the reader module 29 * initialize the reader module
30 * 30 *
31 * [In] buf
32 * the start pointer of the buffer
33 *
34 * [In] size
35 * enabled buffer size
36 *
37 * [Out] used_size
38 * the size of the buffer which the pager uses
39 *
40 * return 31 * return
41 * true initialize success 32 * true initialize success
42 * false initialize failure 33 * false initialize failure
43 */ 34 */
44bool tv_init_reader(unsigned char *buf, size_t bufsize, size_t *used_size); 35bool tv_init_reader(void);
45 36
46/* finalize the reader module */ 37/* finalize the reader module */
47void tv_finalize_reader(void); 38void tv_finalize_reader(void);
diff --git a/apps/plugins/text_viewer/tv_settings.c b/apps/plugins/text_viewer/tv_settings.c
index 6b16218523..428666de24 100644
--- a/apps/plugins/text_viewer/tv_settings.c
+++ b/apps/plugins/text_viewer/tv_settings.c
@@ -181,9 +181,9 @@ static bool tv_read_preferences(int pfd, int version, struct tv_preferences *pre
181 else 181 else
182 prefs->indent_spaces = 2; 182 prefs->indent_spaces = 2;
183 183
184#ifdef HAVE_LCD_BITMAP
184 rb->memcpy(prefs->font_name, buf + read_size - MAX_PATH, MAX_PATH); 185 rb->memcpy(prefs->font_name, buf + read_size - MAX_PATH, MAX_PATH);
185 186
186#ifdef HAVE_LCD_BITMAP
187 prefs->font = rb->font_get(FONT_UI); 187 prefs->font = rb->font_get(FONT_UI);
188#endif 188#endif
189 189
@@ -213,7 +213,9 @@ static bool tv_write_preferences(int pfd, const struct tv_preferences *prefs)
213 *p++ = prefs->narrow_mode; 213 *p++ = prefs->narrow_mode;
214 *p++ = prefs->indent_spaces; 214 *p++ = prefs->indent_spaces;
215 215
216#ifdef HAVE_LCD_BITMAP
216 rb->memcpy(buf + 28, prefs->font_name, MAX_PATH); 217 rb->memcpy(buf + 28, prefs->font_name, MAX_PATH);
218#endif
217 219
218 return (rb->write(pfd, buf, TV_PREFERENCES_SIZE) >= 0); 220 return (rb->write(pfd, buf, TV_PREFERENCES_SIZE) >= 0);
219} 221}
@@ -457,7 +459,6 @@ static bool tv_copy_settings(int sfd, int dfd, int size)
457 459
458bool tv_save_settings(void) 460bool tv_save_settings(void)
459{ 461{
460 const struct tv_preferences *prefs = tv_get_preferences();
461 unsigned char buf[MAX_PATH+2]; 462 unsigned char buf[MAX_PATH+2];
462 unsigned int fcount = 0; 463 unsigned int fcount = 0;
463 unsigned int i; 464 unsigned int i;
@@ -502,7 +503,7 @@ bool tv_save_settings(void)
502 } 503 }
503 504
504 size = (buf[MAX_PATH] << 8) | buf[MAX_PATH + 1]; 505 size = (buf[MAX_PATH] << 8) | buf[MAX_PATH + 1];
505 if (rb->strcmp(buf, prefs->file_name) == 0) 506 if (rb->strcmp(buf, preferences->file_name) == 0)
506 rb->lseek(ofd, size, SEEK_CUR); 507 rb->lseek(ofd, size, SEEK_CUR);
507 else 508 else
508 { 509 {
@@ -522,12 +523,11 @@ bool tv_save_settings(void)
522 { 523 {
523 /* save to current read file's preferences and bookmarks */ 524 /* save to current read file's preferences and bookmarks */
524 res = false; 525 res = false;
525 rb->memset(buf, 0, MAX_PATH); 526 rb->strlcpy(buf, preferences->file_name, MAX_PATH);
526 rb->strlcpy(buf, prefs->file_name, MAX_PATH);
527 527
528 if (rb->write(tfd, buf, MAX_PATH + 2) >= 0) 528 if (rb->write(tfd, buf, MAX_PATH + 2) >= 0)
529 { 529 {
530 if (tv_write_preferences(tfd, prefs)) 530 if (tv_write_preferences(tfd, preferences))
531 { 531 {
532 size = tv_serialize_bookmarks(tfd); 532 size = tv_serialize_bookmarks(tfd);
533 if (size > 0) 533 if (size > 0)
diff --git a/apps/plugins/text_viewer/tv_text_processor.c b/apps/plugins/text_viewer/tv_text_processor.c
index 5e30f0b078..f9a2fad1f2 100644
--- a/apps/plugins/text_viewer/tv_text_processor.c
+++ b/apps/plugins/text_viewer/tv_text_processor.c
@@ -25,7 +25,7 @@
25#include "tv_preferences.h" 25#include "tv_preferences.h"
26#include "tv_text_processor.h" 26#include "tv_text_processor.h"
27 27
28enum tv_text_type { 28enum{
29 TV_TEXT_UNKNOWN, 29 TV_TEXT_UNKNOWN,
30 TV_TEXT_MAC, 30 TV_TEXT_MAC,
31 TV_TEXT_UNIX, 31 TV_TEXT_UNIX,
@@ -41,13 +41,12 @@ enum tv_text_type {
41 41
42#define TV_MAX_BLOCKS 5 42#define TV_MAX_BLOCKS 5
43 43
44static const struct tv_preferences *prefs; 44static unsigned text_type = TV_TEXT_UNKNOWN;
45static enum tv_text_type text_type = TV_TEXT_UNKNOWN;
46 45
47static const unsigned char *end_ptr; 46static const unsigned char *end_ptr;
48 47
49static unsigned short *ucsbuf[TV_MAX_BLOCKS]; 48static unsigned short ucsbuf[TV_MAX_BLOCKS][TV_MAX_CHARS_PER_BLOCK];
50static unsigned char *utf8buf; 49static unsigned char utf8buf[TV_MAX_CHARS_PER_BLOCK * (2 * 3)];
51static unsigned char *outbuf; 50static unsigned char *outbuf;
52 51
53static int block_count; 52static int block_count;
@@ -96,7 +95,7 @@ static int tv_glyph_width(int ch)
96 if (rb->is_diacritic(ch, NULL)) 95 if (rb->is_diacritic(ch, NULL))
97 return 0; 96 return 0;
98 97
99 return rb->font_get_width(prefs->font, ch); 98 return rb->font_get_width(preferences->font, ch);
100#else 99#else
101 return 1; 100 return 1;
102#endif 101#endif
@@ -136,13 +135,13 @@ static unsigned char *tv_get_ucs(const unsigned char *str, unsigned short *ch)
136 return (unsigned char *)str + 1; 135 return (unsigned char *)str + 1;
137 } 136 }
138 137
139 if (prefs->encoding == UTF_8) 138 if (preferences->encoding == UTF_8)
140 return (unsigned char*)rb->utf8decode(str, ch); 139 return (unsigned char*)rb->utf8decode(str, ch);
141 140
142#ifdef HAVE_LCD_BITMAP 141#ifdef HAVE_LCD_BITMAP
143 if ((*str >= 0x80) && 142 if ((*str >= 0x80) &&
144 ((prefs->encoding > SJIS) || 143 ((preferences->encoding > SJIS) ||
145 (prefs->encoding == SJIS && (*str <= 0xa0 || *str >= 0xe0)))) 144 (preferences->encoding == SJIS && (*str <= 0xa0 || *str >= 0xe0))))
146 { 145 {
147 if (str + 1 >= end_ptr) 146 if (str + 1 >= end_ptr)
148 { 147 {
@@ -153,7 +152,7 @@ static unsigned char *tv_get_ucs(const unsigned char *str, unsigned short *ch)
153 count = 2; 152 count = 2;
154 } 153 }
155#endif 154#endif
156 rb->iso_decode(str, utf8_tmp, prefs->encoding, count); 155 rb->iso_decode(str, utf8_tmp, preferences->encoding, count);
157 rb->utf8decode(utf8_tmp, ch); 156 rb->utf8decode(utf8_tmp, ch);
158 return (unsigned char *)str + count; 157 return (unsigned char *)str + count;
159} 158}
@@ -173,7 +172,7 @@ static bool tv_is_line_break_char(unsigned short ch)
173 size_t i; 172 size_t i;
174 173
175 /* when the word mode is CHOP, all characters does not break line. */ 174 /* when the word mode is CHOP, all characters does not break line. */
176 if (prefs->word_mode == CHOP) 175 if (preferences->word_mode == CHOP)
177 return false; 176 return false;
178 177
179 for (i = 0; i < sizeof(break_chars); i++) 178 for (i = 0; i < sizeof(break_chars); i++)
@@ -222,7 +221,7 @@ static int tv_form_reflow_line(unsigned short *ucs, int chars)
222 int spaces = 0; 221 int spaces = 0;
223 int words_spaces; 222 int words_spaces;
224 223
225 if (prefs->alignment == LEFT) 224 if (preferences->alignment == LEFT)
226 { 225 {
227 while (chars > 0 && ucs[chars-1] == ' ') 226 while (chars > 0 && ucs[chars-1] == ' ')
228 chars--; 227 chars--;
@@ -368,7 +367,6 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
368 unsigned short prev_ch; 367 unsigned short prev_ch;
369 int chars = 0; 368 int chars = 0;
370 int gw; 369 int gw;
371 int i;
372 int line_break_width = 0; 370 int line_break_width = 0;
373 int line_end_chars = 0; 371 int line_end_chars = 0;
374 int width = 0; 372 int width = 0;
@@ -388,7 +386,7 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
388 next = tv_get_ucs(cur, &ch); 386 next = tv_get_ucs(cur, &ch);
389 if (ch == '\n') 387 if (ch == '\n')
390 { 388 {
391 if (prefs->line_mode != JOIN || tv_is_break_line_join_mode(next)) 389 if (preferences->line_mode != JOIN || tv_is_break_line_join_mode(next))
392 { 390 {
393 line_end_ptr = next; 391 line_end_ptr = next;
394 line_end_chars = chars; 392 line_end_chars = chars;
@@ -396,7 +394,7 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
396 break; 394 break;
397 } 395 }
398 396
399 if (prefs->word_mode == CHOP || tv_isspace(prev_ch)) 397 if (preferences->word_mode == CHOP || tv_isspace(prev_ch))
400 continue; 398 continue;
401 399
402 /* 400 /*
@@ -413,7 +411,7 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
413 * (1) spacelike character convert to ' ' 411 * (1) spacelike character convert to ' '
414 * (2) plural spaces are collected to one 412 * (2) plural spaces are collected to one
415 */ 413 */
416 if (prefs->line_mode == REFLOW) 414 if (preferences->line_mode == REFLOW)
417 { 415 {
418 ch = ' '; 416 ch = ' ';
419 if (prev_ch == ch) 417 if (prev_ch == ch)
@@ -421,14 +419,14 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
421 } 419 }
422 420
423 /* when the alignment is RIGHT, ignores indent spaces. */ 421 /* when the alignment is RIGHT, ignores indent spaces. */
424 if (prefs->alignment == RIGHT && is_indent) 422 if (preferences->alignment == RIGHT && is_indent)
425 continue; 423 continue;
426 } 424 }
427 else 425 else
428 is_indent = false; 426 is_indent = false;
429 427
430 if (prefs->line_mode == REFLOW && is_indent) 428 if (preferences->line_mode == REFLOW && is_indent)
431 gw = tv_glyph_width(ch) * prefs->indent_spaces; 429 gw = tv_glyph_width(ch) * preferences->indent_spaces;
432 else 430 else
433 gw = tv_glyph_width(ch); 431 gw = tv_glyph_width(ch);
434 432
@@ -445,11 +443,12 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
445 break; 443 break;
446 } 444 }
447 445
448 if (prefs->line_mode != REFLOW || !is_indent) 446 if (preferences->line_mode != REFLOW || !is_indent)
449 ucs[chars++] = ch; 447 ucs[chars++] = ch;
450 else 448 else
451 { 449 {
452 for (i = 0; i < prefs->indent_spaces; i++) 450 unsigned char i;
451 for (i = 0; i < preferences->indent_spaces; i++)
453 ucs[chars++] = ch; 452 ucs[chars++] = ch;
454 } 453 }
455 454
@@ -473,7 +472,7 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
473 * when the last line break position is too short (line length < 0.75 * block width), 472 * when the last line break position is too short (line length < 0.75 * block width),
474 * the line is cut off at the position where it is closest to the displayed width. 473 * the line is cut off at the position where it is closest to the displayed width.
475 */ 474 */
476 if ((prefs->line_mode == REFLOW && line_break_ptr == NULL) || 475 if ((preferences->line_mode == REFLOW && line_break_ptr == NULL) ||
477 (4 * line_break_width < 3 * block_width)) 476 (4 * line_break_width < 3 * block_width))
478 { 477 {
479 line_end_ptr = cur; 478 line_end_ptr = cur;
@@ -505,7 +504,7 @@ int tv_create_formed_text(const unsigned char *src, ssize_t bufsize,
505 if (dst != NULL) 504 if (dst != NULL)
506 *dst = utf8buf; 505 *dst = utf8buf;
507 506
508 if (prefs->line_mode == EXPAND && (expand_extra_line = !expand_extra_line) == true) 507 if (preferences->line_mode == EXPAND && (expand_extra_line = !expand_extra_line) == true)
509 return 0; 508 return 0;
510 509
511 end_ptr = src + bufsize; 510 end_ptr = src + bufsize;
@@ -513,7 +512,7 @@ int tv_create_formed_text(const unsigned char *src, ssize_t bufsize,
513 tv_get_ucs(src, &ch); 512 tv_get_ucs(src, &ch);
514 is_indent = (tv_isspace(ch) && !is_break_line); 513 is_indent = (tv_isspace(ch) && !is_break_line);
515 514
516 if (is_indent && prefs->indent_spaces == 0 && (expand_extra_line = !expand_extra_line) == true) 515 if (is_indent && preferences->indent_spaces == 0 && (expand_extra_line = !expand_extra_line) == true)
517 return 0; 516 return 0;
518 517
519 for (i = 0; i < block_count; i++) 518 for (i = 0; i < block_count; i++)
@@ -527,14 +526,14 @@ int tv_create_formed_text(const unsigned char *src, ssize_t bufsize,
527 526
528 if (dst != NULL) 527 if (dst != NULL)
529 { 528 {
530 if (prefs->alignment == RIGHT) 529 if (preferences->alignment == RIGHT)
531 tv_align_right(chars); 530 tv_align_right(chars);
532 531
533 for (i = 0; i < block_count; i++) 532 for (i = 0; i < block_count; i++)
534 { 533 {
535 if (i == block || (is_multi && i == block + 1)) 534 if (i == block || (is_multi && i == block + 1))
536 { 535 {
537 if (is_break_line && prefs->line_mode == REFLOW) 536 if (is_break_line && preferences->line_mode == REFLOW)
538 chars[i] = tv_form_reflow_line(ucsbuf[i], chars[i]); 537 chars[i] = tv_form_reflow_line(ucsbuf[i], chars[i]);
539 538
540 tv_decode2utf8(ucsbuf[i], chars[i]); 539 tv_decode2utf8(ucsbuf[i], chars[i]);
@@ -545,26 +544,11 @@ int tv_create_formed_text(const unsigned char *src, ssize_t bufsize,
545 return size; 544 return size;
546} 545}
547 546
548bool tv_init_text_processor(unsigned char *buf, size_t bufsize, size_t *used_size) 547void tv_init_text_processor(void)
549{ 548{
550 int i;
551
552 *used_size = TV_MAX_CHARS_PER_BLOCK * (2 * 3 + TV_MAX_BLOCKS * sizeof(unsigned short));
553 if (bufsize < *used_size)
554 return false;
555
556 prefs = tv_get_preferences();
557 text_type = TV_TEXT_UNKNOWN; 549 text_type = TV_TEXT_UNKNOWN;
558 expand_extra_line = false; 550 expand_extra_line = false;
559 is_break_line = false; 551 is_break_line = false;
560
561 ucsbuf[0] = (unsigned short*)buf;
562 for (i = 1; i < TV_MAX_BLOCKS; i++)
563 ucsbuf[i] = ucsbuf[i - 1] + TV_MAX_CHARS_PER_BLOCK;
564
565 utf8buf = buf + TV_MAX_CHARS_PER_BLOCK * TV_MAX_BLOCKS * sizeof(unsigned short);
566
567 return true;
568} 552}
569 553
570void tv_set_creation_conditions(int blocks, int width) 554void tv_set_creation_conditions(int blocks, int width)
diff --git a/apps/plugins/text_viewer/tv_text_processor.h b/apps/plugins/text_viewer/tv_text_processor.h
index 3cb2a96448..8a9de9075b 100644
--- a/apps/plugins/text_viewer/tv_text_processor.h
+++ b/apps/plugins/text_viewer/tv_text_processor.h
@@ -26,20 +26,8 @@
26/* 26/*
27 * initialize the text processor module 27 * initialize the text processor module
28 * 28 *
29 * [In] buf
30 * the start pointer of the buffer
31 *
32 * [In] size
33 * enabled buffer size
34 *
35 * [Out] used_size
36 * the size of the buffer which the pager uses
37 *
38 * return
39 * true initialize success
40 * false initialize failure
41 */ 29 */
42bool tv_init_text_processor(unsigned char *buf, size_t bufsize, size_t *used_size); 30void tv_init_text_processor(void);
43 31
44/* 32/*
45 * set the processing conditions 33 * set the processing conditions
diff --git a/apps/plugins/text_viewer/tv_text_reader.c b/apps/plugins/text_viewer/tv_text_reader.c
index 28cfa565c3..53c8f6738f 100644
--- a/apps/plugins/text_viewer/tv_text_reader.c
+++ b/apps/plugins/text_viewer/tv_text_reader.c
@@ -29,19 +29,11 @@
29static int get_block; 29static int get_block;
30static bool get_double_blocks; 30static bool get_double_blocks;
31 31
32bool tv_init_text_reader(unsigned char *buf, size_t bufsize, size_t *used_size) 32bool tv_init_text_reader(void)
33{ 33{
34 size_t size; 34 tv_init_text_processor();
35 35
36 if (!tv_init_text_processor(buf, bufsize, used_size)) 36 return tv_init_pager();
37 return false;
38
39 size = *used_size;
40 if (!tv_init_pager(buf + size, bufsize - size, used_size))
41 return false;
42
43 *used_size += size;
44 return true;
45} 37}
46 38
47void tv_finalize_text_reader(void) 39void tv_finalize_text_reader(void)
diff --git a/apps/plugins/text_viewer/tv_text_reader.h b/apps/plugins/text_viewer/tv_text_reader.h
index e8c712c76f..50059c8b3c 100644
--- a/apps/plugins/text_viewer/tv_text_reader.h
+++ b/apps/plugins/text_viewer/tv_text_reader.h
@@ -26,20 +26,11 @@
26/* 26/*
27 * initialize the text reader module 27 * initialize the text reader module
28 * 28 *
29 * [In] buf
30 * the start pointer of the buffer
31 *
32 * [In] size
33 * enabled buffer size
34 *
35 * [Out] used_size
36 * the size of the buffer which the pager uses
37 *
38 * return 29 * return
39 * true initialize success 30 * true initialize success
40 * false initialize failure 31 * false initialize failure
41 */ 32 */
42bool tv_init_text_reader(unsigned char *buf, size_t bufsize, size_t *used_size); 33bool tv_init_text_reader(void);
43 34
44/* finalize the text reader module */ 35/* finalize the text reader module */
45void tv_finalize_text_reader(void); 36void tv_finalize_text_reader(void);
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 {
diff --git a/apps/plugins/text_viewer/tv_window.h b/apps/plugins/text_viewer/tv_window.h
index fe87ec6569..abf475ae2d 100644
--- a/apps/plugins/text_viewer/tv_window.h
+++ b/apps/plugins/text_viewer/tv_window.h
@@ -26,20 +26,11 @@
26/* 26/*
27 * initialize the window module 27 * initialize the window module
28 * 28 *
29 * [In] buf
30 * the start pointer of the buffer
31 *
32 * [In] size
33 * enabled buffer size
34 *
35 * [Out] used_size
36 * the size of the buffer which the pager uses
37 *
38 * return 29 * return
39 * true initialize success 30 * true initialize success
40 * false initialize failure 31 * false initialize failure
41 */ 32 */
42bool tv_init_window(unsigned char *buf, size_t bufsize, size_t *used_size); 33bool tv_init_window(void);
43 34
44/* finalize the window module */ 35/* finalize the window module */
45void tv_finalize_window(void); 36void tv_finalize_window(void);