summaryrefslogtreecommitdiff
path: root/apps/plugins/text_viewer/tv_action.c
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2010-06-20 21:53:47 +0000
committerRafaël Carré <rafael.carre@gmail.com>2010-06-20 21:53:47 +0000
commit298316d19297eea82869b63235b535e5904fc0dd (patch)
tree0426e9c8cecac7532a88888e78e5e54ea9bb6145 /apps/plugins/text_viewer/tv_action.c
parent17a2f9d8d2dfddd8d2d81ff638e21302efef1c8e (diff)
downloadrockbox-298316d19297eea82869b63235b535e5904fc0dd.tar.gz
rockbox-298316d19297eea82869b63235b535e5904fc0dd.zip
text_viewer: cleanup & bugfix
cleanup: - don't use enum in struct / return values - don't use a getter for preferences but a global pointer - explicitely make enums start at 0 - use static tables for header/footer settings - remove unneeded memset before strlcpy - use static buffer allocation, not dynamic - check header/footer preferences before using the callbacks - don't include font filename in archos player preferences (break file format) bugfix: - statically allocate old preferences in tv_set_preferences() Sometimes I can read a file on Clipv2, but it still aborts quite often refs: FS#11399 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26998 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/text_viewer/tv_action.c')
-rw-r--r--apps/plugins/text_viewer/tv_action.c45
1 files changed, 15 insertions, 30 deletions
diff --git a/apps/plugins/text_viewer/tv_action.c b/apps/plugins/text_viewer/tv_action.c
index 53a29ef021..546ee99842 100644
--- a/apps/plugins/text_viewer/tv_action.c
+++ b/apps/plugins/text_viewer/tv_action.c
@@ -28,27 +28,12 @@
28#include "tv_settings.h" 28#include "tv_settings.h"
29#include "tv_window.h" 29#include "tv_window.h"
30 30
31static const struct tv_preferences *prefs;
32
33bool tv_init(const unsigned char *file) 31bool tv_init(const unsigned char *file)
34{ 32{
35 size_t req_size = 0;
36 size_t size;
37 size_t used_size;
38 unsigned char *buffer;
39
40 /* get the plugin buffer */
41 buffer = rb->plugin_get_buffer(&req_size);
42 size = req_size;
43 if (buffer == NULL || size == 0)
44 return false;
45
46 prefs = tv_get_preferences();
47
48 tv_init_bookmark(); 33 tv_init_bookmark();
49 34
50 /* initialize modules */ 35 /* initialize modules */
51 if (!tv_init_window(buffer, size, &used_size)) 36 if (!tv_init_window())
52 return false; 37 return false;
53 38
54 /* load the preferences and bookmark */ 39 /* load the preferences and bookmark */
@@ -83,45 +68,45 @@ void tv_draw(void)
83 tv_move_screen(pos.page, pos.line, SEEK_SET); 68 tv_move_screen(pos.page, pos.line, SEEK_SET);
84} 69}
85 70
86void tv_scroll_up(enum tv_vertical_scroll_mode mode) 71void tv_scroll_up(unsigned mode)
87{ 72{
88 int offset_page = 0; 73 int offset_page = 0;
89 int offset_line = -1; 74 int offset_line = -1;
90 75
91 if ((mode == TV_VERTICAL_SCROLL_PAGE) || 76 if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
92 (mode == TV_VERTICAL_SCROLL_PREFS && prefs->vertical_scroll_mode == PAGE)) 77 (mode == TV_VERTICAL_SCROLL_PREFS && preferences->vertical_scroll_mode == PAGE))
93 { 78 {
94 offset_page--; 79 offset_page--;
95#ifdef HAVE_LCD_BITMAP 80#ifdef HAVE_LCD_BITMAP
96 offset_line = (prefs->page_mode == OVERLAP)? 1:0; 81 offset_line = (preferences->page_mode == OVERLAP)? 1:0;
97#endif 82#endif
98 } 83 }
99 tv_move_screen(offset_page, offset_line, SEEK_CUR); 84 tv_move_screen(offset_page, offset_line, SEEK_CUR);
100} 85}
101 86
102void tv_scroll_down(enum tv_vertical_scroll_mode mode) 87void tv_scroll_down(unsigned mode)
103{ 88{
104 int offset_page = 0; 89 int offset_page = 0;
105 int offset_line = 1; 90 int offset_line = 1;
106 91
107 if ((mode == TV_VERTICAL_SCROLL_PAGE) || 92 if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
108 (mode == TV_VERTICAL_SCROLL_PREFS && prefs->vertical_scroll_mode == PAGE)) 93 (mode == TV_VERTICAL_SCROLL_PREFS && preferences->vertical_scroll_mode == PAGE))
109 { 94 {
110 offset_page++; 95 offset_page++;
111#ifdef HAVE_LCD_BITMAP 96#ifdef HAVE_LCD_BITMAP
112 offset_line = (prefs->page_mode == OVERLAP)? -1:0; 97 offset_line = (preferences->page_mode == OVERLAP)? -1:0;
113#endif 98#endif
114 } 99 }
115 tv_move_screen(offset_page, offset_line, SEEK_CUR); 100 tv_move_screen(offset_page, offset_line, SEEK_CUR);
116} 101}
117 102
118void tv_scroll_left(enum tv_horizontal_scroll_mode mode) 103void tv_scroll_left(unsigned mode)
119{ 104{
120 int offset_window = 0; 105 int offset_window = 0;
121 int offset_column = 0; 106 int offset_column = 0;
122 107
123 if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) || 108 if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) ||
124 (mode == TV_HORIZONTAL_SCROLL_PREFS && prefs->horizontal_scroll_mode == COLUMN)) 109 (mode == TV_HORIZONTAL_SCROLL_PREFS && preferences->horizontal_scroll_mode == COLUMN))
125 { 110 {
126 /* Scroll left one column */ 111 /* Scroll left one column */
127 offset_column--; 112 offset_column--;
@@ -134,13 +119,13 @@ void tv_scroll_left(enum tv_horizontal_scroll_mode mode)
134 tv_move_window(offset_window, offset_column); 119 tv_move_window(offset_window, offset_column);
135} 120}
136 121
137void tv_scroll_right(enum tv_horizontal_scroll_mode mode) 122void tv_scroll_right(unsigned mode)
138{ 123{
139 int offset_window = 0; 124 int offset_window = 0;
140 int offset_column = 0; 125 int offset_column = 0;
141 126
142 if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) || 127 if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) ||
143 (mode == TV_HORIZONTAL_SCROLL_PREFS && prefs->horizontal_scroll_mode == COLUMN)) 128 (mode == TV_HORIZONTAL_SCROLL_PREFS && preferences->horizontal_scroll_mode == COLUMN))
144 { 129 {
145 /* Scroll right one column */ 130 /* Scroll right one column */
146 offset_column++; 131 offset_column++;
@@ -161,13 +146,13 @@ void tv_top(void)
161void tv_bottom(void) 146void tv_bottom(void)
162{ 147{
163 tv_move_screen(0, 0, SEEK_END); 148 tv_move_screen(0, 0, SEEK_END);
164 if (prefs->vertical_scroll_mode == PAGE) 149 if (preferences->vertical_scroll_mode == PAGE)
165 tv_move_screen(0, -tv_get_screen_pos()->line, SEEK_CUR); 150 tv_move_screen(0, -tv_get_screen_pos()->line, SEEK_CUR);
166} 151}
167 152
168enum tv_menu_result tv_menu(void) 153unsigned tv_menu(void)
169{ 154{
170 enum tv_menu_result res; 155 unsigned res;
171 struct tv_screen_pos cur_pos; 156 struct tv_screen_pos cur_pos;
172 off_t cur_file_pos = tv_get_screen_pos()->file_pos; 157 off_t cur_file_pos = tv_get_screen_pos()->file_pos;
173 158
@@ -176,7 +161,7 @@ enum tv_menu_result tv_menu(void)
176 if (res == TV_MENU_RESULT_EXIT_MENU) 161 if (res == TV_MENU_RESULT_EXIT_MENU)
177 { 162 {
178 tv_convert_fpos(cur_file_pos, &cur_pos); 163 tv_convert_fpos(cur_file_pos, &cur_pos);
179 if (prefs->vertical_scroll_mode == PAGE) 164 if (preferences->vertical_scroll_mode == PAGE)
180 cur_pos.line = 0; 165 cur_pos.line = 0;
181 166
182 tv_move_screen(cur_pos.page, cur_pos.line, SEEK_SET); 167 tv_move_screen(cur_pos.page, cur_pos.line, SEEK_SET);