1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Gilles Roux
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 ****************************************************************************/
24 #include "tv_bookmark.h"
25 #include "tv_display.h"
26 #include "tv_preferences.h"
27 #include "tv_screen_pos.h"
28 #include "tv_text_reader.h"
29 #include "tv_window.h"
31 static int window_width
;
32 static int window_columns
;
33 static int display_lines
;
35 static int cur_window
;
36 static int cur_column
;
38 static void tv_draw_bookmarks(const struct tv_screen_pos
*top_pos
)
40 struct tv_screen_pos bookmarks
[TV_MAX_BOOKMARKS
];
41 int disp_bookmarks
[TV_MAX_BOOKMARKS
];
42 int count
= tv_get_bookmark_positions(bookmarks
);
48 line
= (bookmarks
[count
].page
- top_pos
->page
) * display_lines
49 + (bookmarks
[count
].line
- top_pos
->line
);
50 if (line
>= 0 && line
< display_lines
)
51 disp_bookmarks
[disp_count
++] = line
;
54 tv_show_bookmarks(disp_bookmarks
, disp_count
);
57 void tv_draw_window(void)
59 struct tv_screen_pos pos
;
60 const unsigned char *text_buf
;
64 tv_copy_screen_pos(&pos
);
68 tv_read_start(cur_window
, (cur_column
> 0));
70 for (line
= 0; line
< display_lines
; line
++)
72 if (!tv_get_next_line(&text_buf
))
75 tv_draw_text(line
, text_buf
, cur_column
);
80 tv_draw_bookmarks(&pos
);
82 tv_update_extra(cur_window
, cur_column
, &pos
, size
);
87 bool tv_traverse_lines(void)
92 tv_read_start(0, false);
93 for (i
= 0; i
< display_lines
; i
++)
95 if (!tv_get_next_line(NULL
))
105 static int tv_change_preferences(const struct tv_preferences
*oldp
)
107 bool need_scrollbar
= false;
111 tv_set_layout(need_scrollbar
);
112 tv_get_drawarea_info(&window_width
, &window_columns
, &display_lines
);
114 if (tv_exist_scrollbar())
117 tv_set_read_conditions(preferences
->windows
, window_width
);
118 if (tv_traverse_lines() &&
119 (preferences
->vertical_scrollbar
|| preferences
->horizontal_scrollbar
))
121 need_scrollbar
= true;
122 tv_set_layout(need_scrollbar
);
123 tv_get_drawarea_info(&window_width
, &window_columns
, &display_lines
);
126 tv_init_scrollbar(tv_get_total_text_size(), need_scrollbar
);
129 if (cur_window
>= preferences
->windows
)
134 tv_set_read_conditions(preferences
->windows
, window_width
);
135 return TV_CALLBACK_OK
;
138 bool tv_init_window(unsigned char **buf
, size_t *size
)
140 tv_add_preferences_change_listner(tv_change_preferences
);
141 return tv_init_display(buf
, size
) && tv_init_text_reader(buf
, size
);
144 void tv_finalize_window(void)
146 tv_finalize_text_reader();
147 tv_finalize_display();
150 void tv_move_window(int window_delta
, int column_delta
)
152 cur_window
+= window_delta
;
153 cur_column
+= column_delta
;
160 else if (cur_window
>= preferences
->windows
)
162 cur_window
= preferences
->windows
- 1;
173 cur_column
= window_columns
- 1;
178 if (cur_window
== preferences
->windows
- 1)
180 else if (cur_column
>= window_columns
)