text viewer:

- if the file fits on one screen, there is no horizontal scrollbar.
- the callback function in tv_reader doesn't do useless processing when the preferences changes.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27212 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Yoshihisa Uchida 2010-07-01 11:31:28 +00:00
parent aa1a126772
commit ea09608012
3 changed files with 42 additions and 25 deletions

View file

@ -100,6 +100,7 @@ static struct tv_rect bookmark;
#endif #endif
static struct tv_rect drawarea; static struct tv_rect drawarea;
static bool show_horizontal_scrollbar;
static bool show_vertical_scrollbar; static bool show_vertical_scrollbar;
static int display_columns; static int display_columns;
@ -138,7 +139,7 @@ static void tv_show_scrollbar(int window, int col, off_t cur_pos, int size)
int min_shown; int min_shown;
int max_shown; int max_shown;
if (preferences->horizontal_scrollbar) if (show_horizontal_scrollbar)
{ {
items = preferences->windows * display_columns; items = preferences->windows * display_columns;
min_shown = window * display_columns + col; 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)
void tv_init_scrollbar(off_t total, bool show_scrollbar) void tv_init_scrollbar(off_t total, bool show_scrollbar)
{ {
totalsize = total; totalsize = total;
show_vertical_scrollbar = show_scrollbar; show_horizontal_scrollbar = (show_scrollbar && preferences->horizontal_scrollbar);
show_vertical_scrollbar = (show_scrollbar && preferences->vertical_scrollbar);
} }
void tv_show_bookmarks(const int *rows, int count) void tv_show_bookmarks(const int *rows, int count)
@ -251,8 +253,10 @@ void tv_end_display(void)
void tv_set_layout(bool show_scrollbar) void tv_set_layout(bool show_scrollbar)
{ {
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
int scrollbar_width = (show_scrollbar)? TV_SCROLLBAR_WIDTH + 1 : 0; int scrollbar_width = (show_scrollbar && preferences->vertical_scrollbar)?
int scrollbar_height = (preferences->horizontal_scrollbar)? TV_SCROLLBAR_HEIGHT + 1 : 0; TV_SCROLLBAR_WIDTH + 1 : 0;
int scrollbar_height = (show_scrollbar && preferences->horizontal_scrollbar)?
TV_SCROLLBAR_HEIGHT + 1 : 0;
row_height = preferences->font->height; row_height = preferences->font->height;

View file

@ -134,14 +134,7 @@ void tv_seek(off_t offset, int whence)
static int tv_change_preferences(const struct tv_preferences *oldp) static int tv_change_preferences(const struct tv_preferences *oldp)
{ {
unsigned char bom[BOM_SIZE]; bool change_file = false;
int cur_start_file_pos = start_file_pos;
off_t cur_file_pos = file_pos + buf_pos;
file_pos = 0;
buf_pos = 0;
read_size = 0;
start_file_pos = 0;
/* open the new file */ /* open the new file */
if (oldp == NULL || rb->strcmp(oldp->file_name, preferences->file_name)) 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)
fd = rb->open(preferences->file_name, O_RDONLY); fd = rb->open(preferences->file_name, O_RDONLY);
if (fd < 0) if (fd < 0)
return TV_CALLBACK_ERROR; return TV_CALLBACK_ERROR;
file_size = rb->filesize(fd);
change_file = true;
} }
/* /*
* When a file is UTF-8 file with BOM, if encoding is UTF-8, * When a file is UTF-8 file with BOM, if encoding is UTF-8,
* then file size decreases only BOM_SIZE. * then file size decreases only BOM_SIZE.
*/ */
if (preferences->encoding == UTF_8) if (change_file || oldp->encoding != preferences->encoding)
{ {
rb->lseek(fd, 0, SEEK_SET); int old_start_file_pos = start_file_pos;
rb->read(fd, bom, BOM_SIZE); int delta_start_file_pos;
if (rb->memcmp(bom, BOM, BOM_SIZE) == 0) off_t cur_file_pos = file_pos + buf_pos;
start_file_pos = BOM_SIZE;
file_pos = 0;
buf_pos = 0;
read_size = 0;
start_file_pos = 0;
if (preferences->encoding == UTF_8)
{
unsigned char bom[BOM_SIZE];
rb->lseek(fd, 0, SEEK_SET);
rb->read(fd, bom, BOM_SIZE);
if (rb->memcmp(bom, BOM, BOM_SIZE) == 0)
start_file_pos = BOM_SIZE;
}
delta_start_file_pos = old_start_file_pos - start_file_pos;
file_size += delta_start_file_pos;
tv_seek(cur_file_pos + delta_start_file_pos, SEEK_SET);
} }
file_size = rb->filesize(fd) - start_file_pos;
tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET);
return TV_CALLBACK_OK; return TV_CALLBACK_OK;
} }

View file

@ -104,25 +104,26 @@ bool tv_traverse_lines(void)
static int tv_change_preferences(const struct tv_preferences *oldp) static int tv_change_preferences(const struct tv_preferences *oldp)
{ {
bool need_vertical_scrollbar = false; bool need_scrollbar = false;
(void)oldp; (void)oldp;
tv_set_layout(need_vertical_scrollbar); tv_set_layout(need_scrollbar);
tv_get_drawarea_info(&window_width, &window_columns, &display_lines); tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
if (tv_exist_scrollbar()) if (tv_exist_scrollbar())
{ {
tv_seek_top(); tv_seek_top();
tv_set_read_conditions(preferences->windows, window_width); tv_set_read_conditions(preferences->windows, window_width);
if (tv_traverse_lines() && preferences->vertical_scrollbar) if (tv_traverse_lines() &&
(preferences->vertical_scrollbar || preferences->horizontal_scrollbar))
{ {
need_vertical_scrollbar = true; need_scrollbar = true;
tv_set_layout(need_vertical_scrollbar); tv_set_layout(need_scrollbar);
tv_get_drawarea_info(&window_width, &window_columns, &display_lines); tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
} }
tv_seek_top(); tv_seek_top();
tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar); tv_init_scrollbar(tv_get_total_text_size(), need_scrollbar);
} }
if (cur_window >= preferences->windows) if (cur_window >= preferences->windows)