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:
parent
aa1a126772
commit
ea09608012
3 changed files with 42 additions and 25 deletions
|
@ -100,6 +100,7 @@ static struct tv_rect bookmark;
|
|||
#endif
|
||||
static struct tv_rect drawarea;
|
||||
|
||||
static bool show_horizontal_scrollbar;
|
||||
static bool show_vertical_scrollbar;
|
||||
|
||||
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 max_shown;
|
||||
|
||||
if (preferences->horizontal_scrollbar)
|
||||
if (show_horizontal_scrollbar)
|
||||
{
|
||||
items = preferences->windows * display_columns;
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
@ -251,8 +253,10 @@ void tv_end_display(void)
|
|||
void tv_set_layout(bool show_scrollbar)
|
||||
{
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
int scrollbar_width = (show_scrollbar)? TV_SCROLLBAR_WIDTH + 1 : 0;
|
||||
int scrollbar_height = (preferences->horizontal_scrollbar)? TV_SCROLLBAR_HEIGHT + 1 : 0;
|
||||
int scrollbar_width = (show_scrollbar && preferences->vertical_scrollbar)?
|
||||
TV_SCROLLBAR_WIDTH + 1 : 0;
|
||||
int scrollbar_height = (show_scrollbar && preferences->horizontal_scrollbar)?
|
||||
TV_SCROLLBAR_HEIGHT + 1 : 0;
|
||||
|
||||
row_height = preferences->font->height;
|
||||
|
||||
|
|
|
@ -134,14 +134,7 @@ void tv_seek(off_t offset, int whence)
|
|||
|
||||
static int tv_change_preferences(const struct tv_preferences *oldp)
|
||||
{
|
||||
unsigned char bom[BOM_SIZE];
|
||||
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;
|
||||
bool change_file = false;
|
||||
|
||||
/* open the new file */
|
||||
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);
|
||||
if (fd < 0)
|
||||
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,
|
||||
* then file size decreases only BOM_SIZE.
|
||||
*/
|
||||
if (change_file || oldp->encoding != preferences->encoding)
|
||||
{
|
||||
int old_start_file_pos = start_file_pos;
|
||||
int delta_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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
file_size = rb->filesize(fd) - start_file_pos;
|
||||
tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET);
|
||||
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);
|
||||
}
|
||||
|
||||
return TV_CALLBACK_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -104,25 +104,26 @@ bool tv_traverse_lines(void)
|
|||
|
||||
static int tv_change_preferences(const struct tv_preferences *oldp)
|
||||
{
|
||||
bool need_vertical_scrollbar = false;
|
||||
bool need_scrollbar = false;
|
||||
|
||||
(void)oldp;
|
||||
|
||||
tv_set_layout(need_vertical_scrollbar);
|
||||
tv_set_layout(need_scrollbar);
|
||||
tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
|
||||
|
||||
if (tv_exist_scrollbar())
|
||||
{
|
||||
tv_seek_top();
|
||||
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;
|
||||
tv_set_layout(need_vertical_scrollbar);
|
||||
need_scrollbar = true;
|
||||
tv_set_layout(need_scrollbar);
|
||||
tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
|
||||
}
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue