summaryrefslogtreecommitdiff
path: root/apps/plugins/text_viewer/tv_action.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/text_viewer/tv_action.c')
-rw-r--r--apps/plugins/text_viewer/tv_action.c186
1 files changed, 186 insertions, 0 deletions
diff --git a/apps/plugins/text_viewer/tv_action.c b/apps/plugins/text_viewer/tv_action.c
new file mode 100644
index 0000000000..fb7fdb40e6
--- /dev/null
+++ b/apps/plugins/text_viewer/tv_action.c
@@ -0,0 +1,186 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Gilles Roux
11 * 2003 Garrett Derner
12 * 2010 Yoshihisa Uchida
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23#include "plugin.h"
24#include "tv_action.h"
25#include "tv_bookmark.h"
26#include "tv_pager.h"
27#include "tv_screen_pos.h"
28#include "tv_settings.h"
29#include "tv_window.h"
30
31static const struct tv_preferences *prefs;
32
33bool tv_init(const unsigned char *file)
34{
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();
49
50 /* initialize modules */
51 if (!tv_init_window(buffer, size, &used_size))
52 return false;
53
54 /* load the preferences and bookmark */
55 tv_load_settings(file);
56
57 /* select to read the page */
58 tv_select_bookmark();
59 return true;
60}
61
62void tv_exit(void *parameter)
63{
64 (void)parameter;
65
66 /* save preference and bookmarks */
67 if (!tv_save_settings())
68 rb->splash(HZ, "Can't save preferences and bookmarks");
69
70 /* finalize modules */
71 tv_finalize_window();
72}
73
74void tv_draw(void)
75{
76 struct tv_screen_pos pos;
77
78 tv_copy_screen_pos(&pos);
79 tv_draw_window();
80 if (pos.line == 0)
81 tv_new_page();
82
83 tv_move_screen(pos.page, pos.line, SEEK_SET);
84}
85
86void tv_scroll_up(enum tv_vertical_scroll_mode mode)
87{
88 int offset_page = 0;
89 int offset_line = -1;
90
91 if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
92 (mode == TV_VERTICAL_SCROLL_PREFS && prefs->scroll_mode == PAGE))
93 {
94 offset_page--;
95#ifdef HAVE_LCD_BITMAP
96 offset_line = (prefs->page_mode == OVERLAP)? 1:0;
97#endif
98 }
99 tv_move_screen(offset_page, offset_line, SEEK_CUR);
100}
101
102void tv_scroll_down(enum tv_vertical_scroll_mode mode)
103{
104 int offset_page = 0;
105 int offset_line = 1;
106
107 if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
108 (mode == TV_VERTICAL_SCROLL_PREFS && prefs->scroll_mode == PAGE))
109 {
110 offset_page++;
111#ifdef HAVE_LCD_BITMAP
112 offset_line = (prefs->page_mode == OVERLAP)? -1:0;
113#endif
114 }
115 tv_move_screen(offset_page, offset_line, SEEK_CUR);
116}
117
118void tv_scroll_left(enum tv_horizontal_scroll_mode mode)
119{
120 int offset_window = 0;
121 int offset_column = 0;
122
123 if (mode == TV_HORIZONTAL_SCROLL_COLUMN)
124 {
125 /* Scroll left one column */
126 offset_column--;
127 }
128 else
129 {
130 /* Scroll left one window */
131 offset_window--;
132 }
133 tv_move_window(offset_window, offset_column);
134}
135
136void tv_scroll_right(enum tv_horizontal_scroll_mode mode)
137{
138 int offset_window = 0;
139 int offset_column = 0;
140
141 if (mode == TV_HORIZONTAL_SCROLL_COLUMN)
142 {
143 /* Scroll right one column */
144 offset_column++;
145 }
146 else
147 {
148 /* Scroll right one window */
149 offset_window++;
150 }
151 tv_move_window(offset_window, offset_column);
152}
153
154void tv_top(void)
155{
156 tv_move_screen(0, 0, SEEK_SET);
157}
158
159void tv_bottom(void)
160{
161 tv_move_screen(0, 0, SEEK_END);
162 if (prefs->scroll_mode == PAGE)
163 tv_move_screen(0, -tv_get_screen_pos()->line, SEEK_CUR);
164}
165
166enum tv_menu_result tv_menu(void)
167{
168 enum tv_menu_result res;
169 struct tv_screen_pos cur_pos;
170 off_t cur_file_pos = tv_get_screen_pos()->file_pos;
171
172 res = tv_display_menu();
173
174 tv_convert_fpos(cur_file_pos, &cur_pos);
175 if (prefs->scroll_mode == PAGE)
176 cur_pos.line = 0;
177
178 tv_move_screen(cur_pos.page, cur_pos.line, SEEK_SET);
179
180 return res;
181}
182
183void tv_add_or_remove_bookmark(void)
184{
185 tv_toggle_bookmark();
186}