summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/text_viewer/tv_display.c12
-rw-r--r--apps/plugins/text_viewer/tv_reader.c42
-rw-r--r--apps/plugins/text_viewer/tv_window.c13
3 files changed, 42 insertions, 25 deletions
diff --git a/apps/plugins/text_viewer/tv_display.c b/apps/plugins/text_viewer/tv_display.c
index 7c6fdcb760..8cf7e11419 100644
--- a/apps/plugins/text_viewer/tv_display.c
+++ b/apps/plugins/text_viewer/tv_display.c
@@ -100,6 +100,7 @@ static struct tv_rect bookmark;
100#endif 100#endif
101static struct tv_rect drawarea; 101static struct tv_rect drawarea;
102 102
103static bool show_horizontal_scrollbar;
103static bool show_vertical_scrollbar; 104static bool show_vertical_scrollbar;
104 105
105static int display_columns; 106static int display_columns;
@@ -138,7 +139,7 @@ static void tv_show_scrollbar(int window, int col, off_t cur_pos, int size)
138 int min_shown; 139 int min_shown;
139 int max_shown; 140 int max_shown;
140 141
141 if (preferences->horizontal_scrollbar) 142 if (show_horizontal_scrollbar)
142 { 143 {
143 items = preferences->windows * display_columns; 144 items = preferences->windows * display_columns;
144 min_shown = window * display_columns + col; 145 min_shown = window * display_columns + col;
@@ -168,7 +169,8 @@ static void tv_show_scrollbar(int window, int col, off_t cur_pos, int size)
168void tv_init_scrollbar(off_t total, bool show_scrollbar) 169void tv_init_scrollbar(off_t total, bool show_scrollbar)
169{ 170{
170 totalsize = total; 171 totalsize = total;
171 show_vertical_scrollbar = show_scrollbar; 172 show_horizontal_scrollbar = (show_scrollbar && preferences->horizontal_scrollbar);
173 show_vertical_scrollbar = (show_scrollbar && preferences->vertical_scrollbar);
172} 174}
173 175
174void tv_show_bookmarks(const int *rows, int count) 176void tv_show_bookmarks(const int *rows, int count)
@@ -251,8 +253,10 @@ void tv_end_display(void)
251void tv_set_layout(bool show_scrollbar) 253void tv_set_layout(bool show_scrollbar)
252{ 254{
253#ifdef HAVE_LCD_BITMAP 255#ifdef HAVE_LCD_BITMAP
254 int scrollbar_width = (show_scrollbar)? TV_SCROLLBAR_WIDTH + 1 : 0; 256 int scrollbar_width = (show_scrollbar && preferences->vertical_scrollbar)?
255 int scrollbar_height = (preferences->horizontal_scrollbar)? TV_SCROLLBAR_HEIGHT + 1 : 0; 257 TV_SCROLLBAR_WIDTH + 1 : 0;
258 int scrollbar_height = (show_scrollbar && preferences->horizontal_scrollbar)?
259 TV_SCROLLBAR_HEIGHT + 1 : 0;
256 260
257 row_height = preferences->font->height; 261 row_height = preferences->font->height;
258 262
diff --git a/apps/plugins/text_viewer/tv_reader.c b/apps/plugins/text_viewer/tv_reader.c
index b94dc17f65..cdfb01d462 100644
--- a/apps/plugins/text_viewer/tv_reader.c
+++ b/apps/plugins/text_viewer/tv_reader.c
@@ -134,14 +134,7 @@ void tv_seek(off_t offset, int whence)
134 134
135static int tv_change_preferences(const struct tv_preferences *oldp) 135static int tv_change_preferences(const struct tv_preferences *oldp)
136{ 136{
137 unsigned char bom[BOM_SIZE]; 137 bool change_file = false;
138 int cur_start_file_pos = start_file_pos;
139 off_t cur_file_pos = file_pos + buf_pos;
140
141 file_pos = 0;
142 buf_pos = 0;
143 read_size = 0;
144 start_file_pos = 0;
145 138
146 /* open the new file */ 139 /* open the new file */
147 if (oldp == NULL || rb->strcmp(oldp->file_name, preferences->file_name)) 140 if (oldp == NULL || rb->strcmp(oldp->file_name, preferences->file_name))
@@ -152,22 +145,41 @@ static int tv_change_preferences(const struct tv_preferences *oldp)
152 fd = rb->open(preferences->file_name, O_RDONLY); 145 fd = rb->open(preferences->file_name, O_RDONLY);
153 if (fd < 0) 146 if (fd < 0)
154 return TV_CALLBACK_ERROR; 147 return TV_CALLBACK_ERROR;
148
149 file_size = rb->filesize(fd);
150 change_file = true;
155 } 151 }
156 152
157 /* 153 /*
158 * When a file is UTF-8 file with BOM, if encoding is UTF-8, 154 * When a file is UTF-8 file with BOM, if encoding is UTF-8,
159 * then file size decreases only BOM_SIZE. 155 * then file size decreases only BOM_SIZE.
160 */ 156 */
161 if (preferences->encoding == UTF_8) 157 if (change_file || oldp->encoding != preferences->encoding)
162 { 158 {
163 rb->lseek(fd, 0, SEEK_SET); 159 int old_start_file_pos = start_file_pos;
164 rb->read(fd, bom, BOM_SIZE); 160 int delta_start_file_pos;
165 if (rb->memcmp(bom, BOM, BOM_SIZE) == 0) 161 off_t cur_file_pos = file_pos + buf_pos;
166 start_file_pos = BOM_SIZE; 162
163 file_pos = 0;
164 buf_pos = 0;
165 read_size = 0;
166 start_file_pos = 0;
167
168 if (preferences->encoding == UTF_8)
169 {
170 unsigned char bom[BOM_SIZE];
171
172 rb->lseek(fd, 0, SEEK_SET);
173 rb->read(fd, bom, BOM_SIZE);
174 if (rb->memcmp(bom, BOM, BOM_SIZE) == 0)
175 start_file_pos = BOM_SIZE;
176 }
177
178 delta_start_file_pos = old_start_file_pos - start_file_pos;
179 file_size += delta_start_file_pos;
180 tv_seek(cur_file_pos + delta_start_file_pos, SEEK_SET);
167 } 181 }
168 182
169 file_size = rb->filesize(fd) - start_file_pos;
170 tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET);
171 return TV_CALLBACK_OK; 183 return TV_CALLBACK_OK;
172} 184}
173 185
diff --git a/apps/plugins/text_viewer/tv_window.c b/apps/plugins/text_viewer/tv_window.c
index 05214fab13..15db75260e 100644
--- a/apps/plugins/text_viewer/tv_window.c
+++ b/apps/plugins/text_viewer/tv_window.c
@@ -104,25 +104,26 @@ bool tv_traverse_lines(void)
104 104
105static int tv_change_preferences(const struct tv_preferences *oldp) 105static int tv_change_preferences(const struct tv_preferences *oldp)
106{ 106{
107 bool need_vertical_scrollbar = false; 107 bool need_scrollbar = false;
108 108
109 (void)oldp; 109 (void)oldp;
110 110
111 tv_set_layout(need_vertical_scrollbar); 111 tv_set_layout(need_scrollbar);
112 tv_get_drawarea_info(&window_width, &window_columns, &display_lines); 112 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
113 113
114 if (tv_exist_scrollbar()) 114 if (tv_exist_scrollbar())
115 { 115 {
116 tv_seek_top(); 116 tv_seek_top();
117 tv_set_read_conditions(preferences->windows, window_width); 117 tv_set_read_conditions(preferences->windows, window_width);
118 if (tv_traverse_lines() && preferences->vertical_scrollbar) 118 if (tv_traverse_lines() &&
119 (preferences->vertical_scrollbar || preferences->horizontal_scrollbar))
119 { 120 {
120 need_vertical_scrollbar = true; 121 need_scrollbar = true;
121 tv_set_layout(need_vertical_scrollbar); 122 tv_set_layout(need_scrollbar);
122 tv_get_drawarea_info(&window_width, &window_columns, &display_lines); 123 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
123 } 124 }
124 tv_seek_top(); 125 tv_seek_top();
125 tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar); 126 tv_init_scrollbar(tv_get_total_text_size(), need_scrollbar);
126 } 127 }
127 128
128 if (cur_window >= preferences->windows) 129 if (cur_window >= preferences->windows)