text_viewer: cleanup & bugfix
[kugel-rb.git] / apps / plugins / text_viewer / tv_action.c
blob546ee99842c030aeb64e92bb4848b39edcf34b52
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 tv_init_bookmark();
35 /* initialize modules */
36 if (!tv_init_window())
37 return false;
39 /* load the preferences and bookmark */
40 tv_load_settings(file);
42 /* select to read the page */
43 tv_select_bookmark();
44 return true;
47 void tv_exit(void *parameter)
49 (void)parameter;
51 /* save preference and bookmarks */
52 if (!tv_save_settings())
53 rb->splash(HZ, "Can't save preferences and bookmarks");
55 /* finalize modules */
56 tv_finalize_window();
59 void tv_draw(void)
61 struct tv_screen_pos pos;
63 tv_copy_screen_pos(&pos);
64 tv_draw_window();
65 if (pos.line == 0)
66 tv_new_page();
68 tv_move_screen(pos.page, pos.line, SEEK_SET);
71 void tv_scroll_up(unsigned mode)
73 int offset_page = 0;
74 int offset_line = -1;
76 if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
77 (mode == TV_VERTICAL_SCROLL_PREFS && preferences->vertical_scroll_mode == PAGE))
79 offset_page--;
80 #ifdef HAVE_LCD_BITMAP
81 offset_line = (preferences->page_mode == OVERLAP)? 1:0;
82 #endif
84 tv_move_screen(offset_page, offset_line, SEEK_CUR);
87 void tv_scroll_down(unsigned mode)
89 int offset_page = 0;
90 int offset_line = 1;
92 if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
93 (mode == TV_VERTICAL_SCROLL_PREFS && preferences->vertical_scroll_mode == PAGE))
95 offset_page++;
96 #ifdef HAVE_LCD_BITMAP
97 offset_line = (preferences->page_mode == OVERLAP)? -1:0;
98 #endif
100 tv_move_screen(offset_page, offset_line, SEEK_CUR);
103 void tv_scroll_left(unsigned mode)
105 int offset_window = 0;
106 int offset_column = 0;
108 if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) ||
109 (mode == TV_HORIZONTAL_SCROLL_PREFS && preferences->horizontal_scroll_mode == COLUMN))
111 /* Scroll left one column */
112 offset_column--;
114 else
116 /* Scroll left one window */
117 offset_window--;
119 tv_move_window(offset_window, offset_column);
122 void tv_scroll_right(unsigned mode)
124 int offset_window = 0;
125 int offset_column = 0;
127 if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) ||
128 (mode == TV_HORIZONTAL_SCROLL_PREFS && preferences->horizontal_scroll_mode == COLUMN))
130 /* Scroll right one column */
131 offset_column++;
133 else
135 /* Scroll right one window */
136 offset_window++;
138 tv_move_window(offset_window, offset_column);
141 void tv_top(void)
143 tv_move_screen(0, 0, SEEK_SET);
146 void tv_bottom(void)
148 tv_move_screen(0, 0, SEEK_END);
149 if (preferences->vertical_scroll_mode == PAGE)
150 tv_move_screen(0, -tv_get_screen_pos()->line, SEEK_CUR);
153 unsigned tv_menu(void)
155 unsigned res;
156 struct tv_screen_pos cur_pos;
157 off_t cur_file_pos = tv_get_screen_pos()->file_pos;
159 res = tv_display_menu();
161 if (res == TV_MENU_RESULT_EXIT_MENU)
163 tv_convert_fpos(cur_file_pos, &cur_pos);
164 if (preferences->vertical_scroll_mode == PAGE)
165 cur_pos.line = 0;
167 tv_move_screen(cur_pos.page, cur_pos.line, SEEK_SET);
169 else if (res == TV_MENU_RESULT_MOVE_PAGE)
170 res = TV_MENU_RESULT_EXIT_MENU;
172 return res;
175 void tv_add_or_remove_bookmark(void)
177 tv_toggle_bookmark();