summaryrefslogtreecommitdiff
path: root/apps/plugins/text_viewer
diff options
context:
space:
mode:
authorYoshihisa Uchida <uchida@rockbox.org>2010-07-01 11:31:28 +0000
committerYoshihisa Uchida <uchida@rockbox.org>2010-07-01 11:31:28 +0000
commitea0960801264cc78407dbdfaa64018a76ba5d61f (patch)
tree58df28ee9f0fd20d8303382975b6c7a19dca2450 /apps/plugins/text_viewer
parentaa1a126772609033ee6f16c11bafcf2f3890fa41 (diff)
downloadrockbox-ea0960801264cc78407dbdfaa64018a76ba5d61f.zip
rockbox-ea0960801264cc78407dbdfaa64018a76ba5d61f.tar.gz
rockbox-ea0960801264cc78407dbdfaa64018a76ba5d61f.tar.bz2
rockbox-ea0960801264cc78407dbdfaa64018a76ba5d61f.tar.xz
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
Diffstat (limited to 'apps/plugins/text_viewer')
-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 7c6fdcb..8cf7e11 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;
#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;
diff --git a/apps/plugins/text_viewer/tv_reader.c b/apps/plugins/text_viewer/tv_reader.c
index b94dc17..cdfb01d 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)
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 (preferences->encoding == UTF_8)
+ if (change_file || oldp->encoding != preferences->encoding)
{
- 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;
+ 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;
+ }
+
+ 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;
}
diff --git a/apps/plugins/text_viewer/tv_window.c b/apps/plugins/text_viewer/tv_window.c
index 05214fa..15db752 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)
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)