diff options
author | Yoshihisa Uchida <uchida@rockbox.org> | 2010-07-01 11:31:28 +0000 |
---|---|---|
committer | Yoshihisa Uchida <uchida@rockbox.org> | 2010-07-01 11:31:28 +0000 |
commit | ea0960801264cc78407dbdfaa64018a76ba5d61f (patch) | |
tree | 58df28ee9f0fd20d8303382975b6c7a19dca2450 /apps/plugins/text_viewer | |
parent | aa1a126772609033ee6f16c11bafcf2f3890fa41 (diff) | |
download | rockbox-ea0960801264cc78407dbdfaa64018a76ba5d61f.tar.gz rockbox-ea0960801264cc78407dbdfaa64018a76ba5d61f.zip |
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.c | 12 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_reader.c | 42 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_window.c | 13 |
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 |
101 | static struct tv_rect drawarea; | 101 | static struct tv_rect drawarea; |
102 | 102 | ||
103 | static bool show_horizontal_scrollbar; | ||
103 | static bool show_vertical_scrollbar; | 104 | static bool show_vertical_scrollbar; |
104 | 105 | ||
105 | static int display_columns; | 106 | static 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) | |||
168 | void tv_init_scrollbar(off_t total, bool show_scrollbar) | 169 | void 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 | ||
174 | void tv_show_bookmarks(const int *rows, int count) | 176 | void tv_show_bookmarks(const int *rows, int count) |
@@ -251,8 +253,10 @@ void tv_end_display(void) | |||
251 | void tv_set_layout(bool show_scrollbar) | 253 | void 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 | ||
135 | static int tv_change_preferences(const struct tv_preferences *oldp) | 135 | static 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 | ||
105 | static int tv_change_preferences(const struct tv_preferences *oldp) | 105 | static 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) |