FS#11399 by me: fix r26998 for text_viewer
[kugel-rb.git] / apps / plugins / text_viewer / tv_action.c
blob88338feb1eda7dbac40c8da3ff84e2f6b0207eaf
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Gilles Roux
11 * 2003 Garrett Derner
12 * 2010 Yoshihisa Uchida
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.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
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"
31 bool tv_init(const unsigned char *file)
33 size_t size;
35 /* get the plugin buffer */
36 unsigned char *buf = rb->plugin_get_buffer(&size);
38 tv_init_bookmark();
40 /* initialize modules */
41 if (!tv_init_window(&buf, &size))
42 return false;
44 /* load the preferences and bookmark */
45 tv_load_settings(file);
47 /* select to read the page */
48 tv_select_bookmark();
49 return true;
52 void tv_exit(void *parameter)
54 (void)parameter;
56 /* save preference and bookmarks */
57 if (!tv_save_settings())
58 rb->splash(HZ, "Can't save preferences and bookmarks");
60 /* finalize modules */
61 tv_finalize_window();
64 void tv_draw(void)
66 struct tv_screen_pos pos;
68 tv_copy_screen_pos(&pos);
69 tv_draw_window();
70 if (pos.line == 0)
71 tv_new_page();
73 tv_move_screen(pos.page, pos.line, SEEK_SET);
76 void tv_scroll_up(unsigned mode)
78 int offset_page = 0;
79 int offset_line = -1;
81 if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
82 (mode == TV_VERTICAL_SCROLL_PREFS && preferences->vertical_scroll_mode == PAGE))
84 offset_page--;
85 #ifdef HAVE_LCD_BITMAP
86 offset_line = (preferences->page_mode == OVERLAP)? 1:0;
87 #endif
89 tv_move_screen(offset_page, offset_line, SEEK_CUR);
92 void tv_scroll_down(unsigned mode)
94 int offset_page = 0;
95 int offset_line = 1;
97 if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
98 (mode == TV_VERTICAL_SCROLL_PREFS && preferences->vertical_scroll_mode == PAGE))
100 offset_page++;
101 #ifdef HAVE_LCD_BITMAP
102 offset_line = (preferences->page_mode == OVERLAP)? -1:0;
103 #endif
105 tv_move_screen(offset_page, offset_line, SEEK_CUR);
108 void tv_scroll_left(unsigned mode)
110 int offset_window = 0;
111 int offset_column = 0;
113 if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) ||
114 (mode == TV_HORIZONTAL_SCROLL_PREFS && preferences->horizontal_scroll_mode == COLUMN))
116 /* Scroll left one column */
117 offset_column--;
119 else
121 /* Scroll left one window */
122 offset_window--;
124 tv_move_window(offset_window, offset_column);
127 void tv_scroll_right(unsigned mode)
129 int offset_window = 0;
130 int offset_column = 0;
132 if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) ||
133 (mode == TV_HORIZONTAL_SCROLL_PREFS && preferences->horizontal_scroll_mode == COLUMN))
135 /* Scroll right one column */
136 offset_column++;
138 else
140 /* Scroll right one window */
141 offset_window++;
143 tv_move_window(offset_window, offset_column);
146 void tv_top(void)
148 tv_move_screen(0, 0, SEEK_SET);
151 void tv_bottom(void)
153 tv_move_screen(0, 0, SEEK_END);
154 if (preferences->vertical_scroll_mode == PAGE)
155 tv_move_screen(0, -tv_get_screen_pos()->line, SEEK_CUR);
158 unsigned tv_menu(void)
160 unsigned res;
161 struct tv_screen_pos cur_pos;
162 off_t cur_file_pos = tv_get_screen_pos()->file_pos;
164 res = tv_display_menu();
166 if (res == TV_MENU_RESULT_EXIT_MENU)
168 tv_convert_fpos(cur_file_pos, &cur_pos);
169 if (preferences->vertical_scroll_mode == PAGE)
170 cur_pos.line = 0;
172 tv_move_screen(cur_pos.page, cur_pos.line, SEEK_SET);
174 else if (res == TV_MENU_RESULT_MOVE_PAGE)
175 res = TV_MENU_RESULT_EXIT_MENU;
177 return res;
180 void tv_add_or_remove_bookmark(void)
182 tv_toggle_bookmark();