1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Rafaël Carré 2010-06-20 21:53:47 +00:00
parent 17a2f9d8d2
commit 298316d192
19 changed files with 272 additions and 380 deletions

View file

@ -35,7 +35,6 @@ enum plugin_status plugin_start(const void* file)
long old_tick; long old_tick;
bool done = false; bool done = false;
bool display_update = true; bool display_update = true;
const struct tv_preferences *prefs = tv_get_preferences();
old_tick = *rb->current_tick; old_tick = *rb->current_tick;
@ -66,7 +65,7 @@ enum plugin_status plugin_start(const void* file)
case TV_MENU2: case TV_MENU2:
#endif #endif
{ {
enum tv_menu_result res = tv_menu(); unsigned res = tv_menu();
if (res != TV_MENU_RESULT_EXIT_MENU) if (res != TV_MENU_RESULT_EXIT_MENU)
{ {
@ -108,13 +107,13 @@ enum plugin_status plugin_start(const void* file)
case TV_SCREEN_LEFT: case TV_SCREEN_LEFT:
case TV_SCREEN_LEFT | BUTTON_REPEAT: case TV_SCREEN_LEFT | BUTTON_REPEAT:
if (prefs->windows > 1) if (preferences->windows > 1)
{ {
/* Screen left */ /* Screen left */
tv_scroll_left(TV_HORIZONTAL_SCROLL_PREFS); tv_scroll_left(TV_HORIZONTAL_SCROLL_PREFS);
} }
else { /* prefs->windows == 1 */ else { /* prefs->windows == 1 */
if (prefs->narrow_mode == NM_PAGE) if (preferences->narrow_mode == NM_PAGE)
{ {
/* scroll to previous page */ /* scroll to previous page */
tv_scroll_up(TV_VERTICAL_SCROLL_PAGE); tv_scroll_up(TV_VERTICAL_SCROLL_PAGE);
@ -129,13 +128,13 @@ enum plugin_status plugin_start(const void* file)
case TV_SCREEN_RIGHT: case TV_SCREEN_RIGHT:
case TV_SCREEN_RIGHT | BUTTON_REPEAT: case TV_SCREEN_RIGHT | BUTTON_REPEAT:
if (prefs->windows > 1) if (preferences->windows > 1)
{ {
/* Screen right */ /* Screen right */
tv_scroll_right(TV_HORIZONTAL_SCROLL_PREFS); tv_scroll_right(TV_HORIZONTAL_SCROLL_PREFS);
} }
else { /* prefs->windows == 1 */ else { /* prefs->windows == 1 */
if (prefs->narrow_mode == NM_PAGE) if (preferences->narrow_mode == NM_PAGE)
{ {
/* scroll to next page */ /* scroll to next page */
tv_scroll_down(TV_VERTICAL_SCROLL_PAGE); tv_scroll_down(TV_VERTICAL_SCROLL_PAGE);
@ -206,7 +205,7 @@ enum plugin_status plugin_start(const void* file)
} }
if (autoscroll) if (autoscroll)
{ {
if(old_tick <= *rb->current_tick - (110 - prefs->autoscroll_speed * 10)) if(old_tick <= *rb->current_tick - (110 - preferences->autoscroll_speed * 10))
{ {
tv_scroll_down(TV_VERTICAL_SCROLL_PREFS); tv_scroll_down(TV_VERTICAL_SCROLL_PREFS);
old_tick = *rb->current_tick; old_tick = *rb->current_tick;

View file

@ -28,27 +28,12 @@
#include "tv_settings.h" #include "tv_settings.h"
#include "tv_window.h" #include "tv_window.h"
static const struct tv_preferences *prefs;
bool tv_init(const unsigned char *file) bool tv_init(const unsigned char *file)
{ {
size_t req_size = 0;
size_t size;
size_t used_size;
unsigned char *buffer;
/* get the plugin buffer */
buffer = rb->plugin_get_buffer(&req_size);
size = req_size;
if (buffer == NULL || size == 0)
return false;
prefs = tv_get_preferences();
tv_init_bookmark(); tv_init_bookmark();
/* initialize modules */ /* initialize modules */
if (!tv_init_window(buffer, size, &used_size)) if (!tv_init_window())
return false; return false;
/* load the preferences and bookmark */ /* load the preferences and bookmark */
@ -83,45 +68,45 @@ void tv_draw(void)
tv_move_screen(pos.page, pos.line, SEEK_SET); tv_move_screen(pos.page, pos.line, SEEK_SET);
} }
void tv_scroll_up(enum tv_vertical_scroll_mode mode) void tv_scroll_up(unsigned mode)
{ {
int offset_page = 0; int offset_page = 0;
int offset_line = -1; int offset_line = -1;
if ((mode == TV_VERTICAL_SCROLL_PAGE) || if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
(mode == TV_VERTICAL_SCROLL_PREFS && prefs->vertical_scroll_mode == PAGE)) (mode == TV_VERTICAL_SCROLL_PREFS && preferences->vertical_scroll_mode == PAGE))
{ {
offset_page--; offset_page--;
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
offset_line = (prefs->page_mode == OVERLAP)? 1:0; offset_line = (preferences->page_mode == OVERLAP)? 1:0;
#endif #endif
} }
tv_move_screen(offset_page, offset_line, SEEK_CUR); tv_move_screen(offset_page, offset_line, SEEK_CUR);
} }
void tv_scroll_down(enum tv_vertical_scroll_mode mode) void tv_scroll_down(unsigned mode)
{ {
int offset_page = 0; int offset_page = 0;
int offset_line = 1; int offset_line = 1;
if ((mode == TV_VERTICAL_SCROLL_PAGE) || if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
(mode == TV_VERTICAL_SCROLL_PREFS && prefs->vertical_scroll_mode == PAGE)) (mode == TV_VERTICAL_SCROLL_PREFS && preferences->vertical_scroll_mode == PAGE))
{ {
offset_page++; offset_page++;
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
offset_line = (prefs->page_mode == OVERLAP)? -1:0; offset_line = (preferences->page_mode == OVERLAP)? -1:0;
#endif #endif
} }
tv_move_screen(offset_page, offset_line, SEEK_CUR); tv_move_screen(offset_page, offset_line, SEEK_CUR);
} }
void tv_scroll_left(enum tv_horizontal_scroll_mode mode) void tv_scroll_left(unsigned mode)
{ {
int offset_window = 0; int offset_window = 0;
int offset_column = 0; int offset_column = 0;
if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) || if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) ||
(mode == TV_HORIZONTAL_SCROLL_PREFS && prefs->horizontal_scroll_mode == COLUMN)) (mode == TV_HORIZONTAL_SCROLL_PREFS && preferences->horizontal_scroll_mode == COLUMN))
{ {
/* Scroll left one column */ /* Scroll left one column */
offset_column--; offset_column--;
@ -134,13 +119,13 @@ void tv_scroll_left(enum tv_horizontal_scroll_mode mode)
tv_move_window(offset_window, offset_column); tv_move_window(offset_window, offset_column);
} }
void tv_scroll_right(enum tv_horizontal_scroll_mode mode) void tv_scroll_right(unsigned mode)
{ {
int offset_window = 0; int offset_window = 0;
int offset_column = 0; int offset_column = 0;
if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) || if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) ||
(mode == TV_HORIZONTAL_SCROLL_PREFS && prefs->horizontal_scroll_mode == COLUMN)) (mode == TV_HORIZONTAL_SCROLL_PREFS && preferences->horizontal_scroll_mode == COLUMN))
{ {
/* Scroll right one column */ /* Scroll right one column */
offset_column++; offset_column++;
@ -161,13 +146,13 @@ void tv_top(void)
void tv_bottom(void) void tv_bottom(void)
{ {
tv_move_screen(0, 0, SEEK_END); tv_move_screen(0, 0, SEEK_END);
if (prefs->vertical_scroll_mode == PAGE) if (preferences->vertical_scroll_mode == PAGE)
tv_move_screen(0, -tv_get_screen_pos()->line, SEEK_CUR); tv_move_screen(0, -tv_get_screen_pos()->line, SEEK_CUR);
} }
enum tv_menu_result tv_menu(void) unsigned tv_menu(void)
{ {
enum tv_menu_result res; unsigned res;
struct tv_screen_pos cur_pos; struct tv_screen_pos cur_pos;
off_t cur_file_pos = tv_get_screen_pos()->file_pos; off_t cur_file_pos = tv_get_screen_pos()->file_pos;
@ -176,7 +161,7 @@ enum tv_menu_result tv_menu(void)
if (res == TV_MENU_RESULT_EXIT_MENU) if (res == TV_MENU_RESULT_EXIT_MENU)
{ {
tv_convert_fpos(cur_file_pos, &cur_pos); tv_convert_fpos(cur_file_pos, &cur_pos);
if (prefs->vertical_scroll_mode == PAGE) if (preferences->vertical_scroll_mode == PAGE)
cur_pos.line = 0; cur_pos.line = 0;
tv_move_screen(cur_pos.page, cur_pos.line, SEEK_SET); tv_move_screen(cur_pos.page, cur_pos.line, SEEK_SET);

View file

@ -26,17 +26,17 @@
#include "tv_menu.h" #include "tv_menu.h"
/* horizontal scroll mode */ /* horizontal scroll mode */
enum tv_horizontal_scroll_mode enum
{ {
TV_HORIZONTAL_SCROLL_COLUMN, /* left/right one column */ TV_HORIZONTAL_SCROLL_COLUMN = 0, /* left/right one column */
TV_HORIZONTAL_SCROLL_SCREEN, /* left/right one screen */ TV_HORIZONTAL_SCROLL_SCREEN, /* left/right one screen */
TV_HORIZONTAL_SCROLL_PREFS, /* left/right follows the settings */ TV_HORIZONTAL_SCROLL_PREFS, /* left/right follows the settings */
}; };
/*vertical scroll mode */ /*vertical scroll mode */
enum tv_vertical_scroll_mode enum
{ {
TV_VERTICAL_SCROLL_LINE, /* up/down one line */ TV_VERTICAL_SCROLL_LINE = 0, /* up/down one line */
TV_VERTICAL_SCROLL_PAGE, /* up/down one page */ TV_VERTICAL_SCROLL_PAGE, /* up/down one page */
TV_VERTICAL_SCROLL_PREFS, /* up/down follows the settings */ TV_VERTICAL_SCROLL_PREFS, /* up/down follows the settings */
}; };
@ -70,7 +70,7 @@ void tv_draw(void);
* [In] mode * [In] mode
* scroll mode * scroll mode
*/ */
void tv_scroll_up(enum tv_vertical_scroll_mode mode); void tv_scroll_up(unsigned mode);
/* /*
* scroll down * scroll down
@ -78,7 +78,7 @@ void tv_scroll_up(enum tv_vertical_scroll_mode mode);
* [In] mode * [In] mode
* scroll mode * scroll mode
*/ */
void tv_scroll_down(enum tv_vertical_scroll_mode mode); void tv_scroll_down(unsigned mode);
/* /*
* scroll left * scroll left
@ -86,7 +86,7 @@ void tv_scroll_down(enum tv_vertical_scroll_mode mode);
* [In] mode * [In] mode
* scroll mode * scroll mode
*/ */
void tv_scroll_left(enum tv_horizontal_scroll_mode mode); void tv_scroll_left(unsigned mode);
/* /*
* scroll right * scroll right
@ -94,7 +94,7 @@ void tv_scroll_left(enum tv_horizontal_scroll_mode mode);
* [In] mode * [In] mode
* scroll mode * scroll mode
*/ */
void tv_scroll_right(enum tv_horizontal_scroll_mode mode); void tv_scroll_right(unsigned mode);
/* jump to the top */ /* jump to the top */
void tv_top(void); void tv_top(void);
@ -111,7 +111,7 @@ void tv_bottom(void);
* TV_MENU_RESULT_EXIT_PLUGIN request to exit this plugin * TV_MENU_RESULT_EXIT_PLUGIN request to exit this plugin
* TV_MENU_RESULT_ATTACHED_USB connect USB cable * TV_MENU_RESULT_ATTACHED_USB connect USB cable
*/ */
enum tv_menu_result tv_menu(void); unsigned tv_menu(void);
/* add or remove the bookmark to the current position */ /* add or remove the bookmark to the current position */
void tv_add_or_remove_bookmark(void); void tv_add_or_remove_bookmark(void);

View file

@ -224,7 +224,7 @@ void tv_select_bookmark(void)
} }
/* move to the select position */ /* move to the select position */
if (tv_get_preferences()->vertical_scroll_mode == PAGE) if (preferences->vertical_scroll_mode == PAGE)
select_pos.line = 0; select_pos.line = 0;
tv_move_screen(select_pos.page, select_pos.line, SEEK_SET); tv_move_screen(select_pos.page, select_pos.line, SEEK_SET);

View file

@ -219,44 +219,30 @@ static bool tv_alignment_setting(void)
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
static bool tv_header_setting(void) static bool tv_header_setting(void)
{ {
int len = (rb->global_settings->statusbar == STATUSBAR_TOP)? 4 : 2; static const struct opt_items names[4] =
struct opt_items names[len];
names[0].string = "None";
names[0].voice_id = -1;
names[1].string = "File path";
names[1].voice_id = -1;
if (rb->global_settings->statusbar == STATUSBAR_TOP)
{ {
names[2].string = "Status bar"; {"None", -1},
names[2].voice_id = -1; {"File path", -1},
names[3].string = "Both"; {"Status bar", -1},
names[3].voice_id = -1; {"Both", -1},
} };
int len = (rb->global_settings->statusbar == STATUSBAR_TOP)? 4 : 2;
return rb->set_option("Show Header", &new_prefs.header_mode, INT, return rb->set_option("Show Header", &new_prefs.header_mode, INT,
names, len, NULL); names, len, NULL);
} }
static bool tv_footer_setting(void) static bool tv_footer_setting(void)
{ {
int len = (rb->global_settings->statusbar == STATUSBAR_BOTTOM)? 4 : 2; static const struct opt_items names[4] =
struct opt_items names[len];
names[0].string = "None";
names[0].voice_id = -1;
names[1].string = "Page Num";
names[1].voice_id = -1;
if (rb->global_settings->statusbar == STATUSBAR_BOTTOM)
{ {
names[2].string = "Status bar"; {"None", -1},
names[2].voice_id = -1; {"Page Num", -1},
names[3].string = "Both"; {"Status bar", -1},
names[3].voice_id = -1; {"Both", -1},
} };
int len = (rb->global_settings->statusbar == STATUSBAR_BOTTOM)? 4 : 2;
return rb->set_option("Show Footer", &new_prefs.footer_mode, INT, return rb->set_option("Show Footer", &new_prefs.footer_mode, INT,
names, len, NULL); names, len, NULL);
} }
@ -304,10 +290,7 @@ static bool tv_font_setting(void)
names, count, NULL); names, count, NULL);
if (new_font != old_font) if (new_font != old_font)
{
rb->memset(new_prefs.font_name, 0, MAX_PATH);
rb->strlcpy(new_prefs.font_name, names[new_font].string, MAX_PATH); rb->strlcpy(new_prefs.font_name, names[new_font].string, MAX_PATH);
}
*tree = backup; *tree = backup;
rb->set_current_file(backup.currdir); rb->set_current_file(backup.currdir);
@ -350,9 +333,9 @@ MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON,
#endif #endif
&scroll_menu, &indent_spaces_item); &scroll_menu, &indent_spaces_item);
static enum tv_menu_result tv_options_menu(void) static unsigned tv_options_menu(void)
{ {
enum tv_menu_result result = TV_MENU_RESULT_EXIT_MENU; unsigned result = TV_MENU_RESULT_EXIT_MENU;
if (rb->do_menu(&option_menu, NULL, NULL, false) == MENU_ATTACHED_USB) if (rb->do_menu(&option_menu, NULL, NULL, false) == MENU_ATTACHED_USB)
result = TV_MENU_RESULT_ATTACHED_USB; result = TV_MENU_RESULT_ATTACHED_USB;
@ -360,9 +343,9 @@ static enum tv_menu_result tv_options_menu(void)
return result; return result;
} }
enum tv_menu_result tv_display_menu(void) unsigned tv_display_menu(void)
{ {
enum tv_menu_result result = TV_MENU_RESULT_EXIT_MENU; unsigned result = TV_MENU_RESULT_EXIT_MENU;
MENUITEM_STRINGLIST(menu, "Viewer Menu", NULL, MENUITEM_STRINGLIST(menu, "Viewer Menu", NULL,
"Return", "Viewer Options", "Return", "Viewer Options",

View file

@ -23,8 +23,8 @@
#ifndef PLUGIN_TEXT_VIEWER_MENU_H #ifndef PLUGIN_TEXT_VIEWER_MENU_H
#define PLUGIN_TEXT_VIEWER_MENU_H #define PLUGIN_TEXT_VIEWER_MENU_H
enum tv_menu_result { enum {
TV_MENU_RESULT_MOVE_PAGE, TV_MENU_RESULT_MOVE_PAGE = 0,
TV_MENU_RESULT_EXIT_MENU, TV_MENU_RESULT_EXIT_MENU,
TV_MENU_RESULT_EXIT_PLUGIN, TV_MENU_RESULT_EXIT_PLUGIN,
TV_MENU_RESULT_ATTACHED_USB, TV_MENU_RESULT_ATTACHED_USB,
@ -40,6 +40,6 @@ enum tv_menu_result {
* TV_MENU_RESULT_EXIT_PLUGIN request to exit this plugin * TV_MENU_RESULT_EXIT_PLUGIN request to exit this plugin
* TV_MENU_RESULT_ATTACHED_USB connect USB cable * TV_MENU_RESULT_ATTACHED_USB connect USB cable
*/ */
enum tv_menu_result tv_display_menu(void); unsigned tv_display_menu(void);
#endif #endif

View file

@ -32,9 +32,7 @@
#define TV_MAX_PAGE 9999 #define TV_MAX_PAGE 9999
#endif #endif
#define TV_PAGER_MEMSIZE (4 * TV_MAX_PAGE) static unsigned char pager_buffer[4 * TV_MAX_PAGE];
static unsigned char *pager_buffer;
static struct tv_screen_pos cur_pos; static struct tv_screen_pos cur_pos;
@ -87,12 +85,8 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
tv_seek(0, SEEK_SET); tv_seek(0, SEEK_SET);
} }
bool tv_init_pager(unsigned char *buf, size_t bufsize, size_t *used_size) bool tv_init_pager(void)
{ {
if (bufsize < TV_PAGER_MEMSIZE)
return false;
pager_buffer = buf;
tv_set_screen_pos(&cur_pos); tv_set_screen_pos(&cur_pos);
tv_add_preferences_change_listner(tv_change_preferences); tv_add_preferences_change_listner(tv_change_preferences);
@ -101,14 +95,7 @@ bool tv_init_pager(unsigned char *buf, size_t bufsize, size_t *used_size)
line_pos[0] = 0; line_pos[0] = 0;
buf += TV_PAGER_MEMSIZE; return tv_init_reader();
bufsize -= TV_PAGER_MEMSIZE;
if (!tv_init_reader(buf, bufsize, used_size))
return false;
*used_size += TV_PAGER_MEMSIZE;
return true;
} }
void tv_finalize_pager(void) void tv_finalize_pager(void)

View file

@ -30,20 +30,11 @@
/* /*
* initialize the pager module * initialize the pager module
* *
* [In] buf
* the start pointer of the buffer
*
* [In] size
* enabled buffer size
*
* [Out] used_size
* the size of the buffer which the pager uses
*
* return * return
* true initialize success * true initialize success
* false initialize failure * false initialize failure
*/ */
bool tv_init_pager(unsigned char *buf, size_t bufsize, size_t *used_size); bool tv_init_pager(void);
/* finalize the pager module */ /* finalize the pager module */
void tv_finalize_pager(void); void tv_finalize_pager(void);

View file

@ -23,15 +23,16 @@
#include "plugin.h" #include "plugin.h"
#include "tv_preferences.h" #include "tv_preferences.h"
/* global preferences */
static struct tv_preferences prefs; static struct tv_preferences prefs;
static bool is_initialized = false; struct tv_preferences *preferences = &prefs;
static int listner_count = 0; static int listner_count = 0;
#define TV_MAX_LISTNERS 4 #define TV_MAX_LISTNERS 4
static void (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp); static void (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp);
static void tv_notify_change_preferences(const struct tv_preferences *oldp, static void tv_notify_change_preferences(const struct tv_preferences *oldp)
const struct tv_preferences *newp)
{ {
int i; int i;
@ -46,49 +47,61 @@ static void tv_notify_change_preferences(const struct tv_preferences *oldp,
* - narrow_mode * - narrow_mode
*/ */
if ((oldp == NULL) || if ((oldp == NULL) ||
(oldp->word_mode != newp->word_mode) || (oldp->word_mode != preferences->word_mode) ||
(oldp->line_mode != newp->line_mode) || (oldp->line_mode != preferences->line_mode) ||
(oldp->windows != newp->windows) || (oldp->windows != preferences->windows) ||
(oldp->horizontal_scrollbar != newp->horizontal_scrollbar) || (oldp->horizontal_scrollbar != preferences->horizontal_scrollbar) ||
(oldp->vertical_scrollbar != newp->vertical_scrollbar) || (oldp->vertical_scrollbar != preferences->vertical_scrollbar) ||
(oldp->encoding != newp->encoding) || (oldp->encoding != preferences->encoding) ||
(oldp->indent_spaces != newp->indent_spaces) || (oldp->indent_spaces != preferences->indent_spaces) ||
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
(oldp->header_mode != newp->header_mode) || (oldp->header_mode != preferences->header_mode) ||
(oldp->footer_mode != newp->footer_mode) || (oldp->footer_mode != preferences->footer_mode) ||
(rb->strcmp(oldp->font_name, newp->font_name)) || (rb->strcmp(oldp->font_name, preferences->font_name)) ||
#endif #endif
(rb->strcmp(oldp->file_name, newp->file_name))) (rb->strcmp(oldp->file_name, preferences->file_name)))
{ {
for (i = listner_count - 1; i >= 0; i--) for (i = 0; i < listner_count; i++)
listners[i](oldp); listners[i](oldp);
} }
} }
const struct tv_preferences *tv_get_preferences(void) static void tv_check_header_and_footer(void)
{ {
return &prefs; if (rb->global_settings->statusbar != STATUSBAR_TOP)
{
if (preferences->header_mode == HD_SBAR)
preferences->header_mode = HD_NONE;
else if (preferences->header_mode == HD_BOTH)
preferences->header_mode = HD_PATH;
}
if (rb->global_settings->statusbar != STATUSBAR_BOTTOM)
{
if (preferences->footer_mode == FT_SBAR)
preferences->footer_mode = FT_NONE;
else if (preferences->footer_mode == FT_BOTH)
preferences->footer_mode = FT_PAGE;
}
} }
void tv_set_preferences(const struct tv_preferences *new_prefs) void tv_set_preferences(const struct tv_preferences *new_prefs)
{ {
static struct tv_preferences old_prefs;
struct tv_preferences *oldp = NULL; struct tv_preferences *oldp = NULL;
struct tv_preferences old_prefs; static bool is_initialized = false;
if (!is_initialized) if (is_initialized)
tv_copy_preferences((oldp = &old_prefs));
is_initialized = true; is_initialized = true;
else
{ rb->memcpy(preferences, new_prefs, sizeof(struct tv_preferences));
old_prefs = prefs; tv_check_header_and_footer();
oldp = &old_prefs; tv_notify_change_preferences(oldp);
}
rb->memcpy(&prefs, new_prefs, sizeof(struct tv_preferences));
tv_notify_change_preferences(oldp, &prefs);
} }
void tv_copy_preferences(struct tv_preferences *copy_prefs) void tv_copy_preferences(struct tv_preferences *copy_prefs)
{ {
rb->memcpy(copy_prefs, &prefs, sizeof(struct tv_preferences)); rb->memcpy(copy_prefs, preferences, sizeof(struct tv_preferences));
} }
void tv_set_default_preferences(struct tv_preferences *p) void tv_set_default_preferences(struct tv_preferences *p)
@ -102,7 +115,6 @@ void tv_set_default_preferences(struct tv_preferences *p)
p->page_mode = NO_OVERLAP; p->page_mode = NO_OVERLAP;
p->horizontal_scrollbar = SB_OFF; p->horizontal_scrollbar = SB_OFF;
p->vertical_scrollbar = SB_OFF; p->vertical_scrollbar = SB_OFF;
rb->memset(p->font_name, 0, MAX_PATH);
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
p->header_mode = HD_BOTH; p->header_mode = HD_BOTH;
p->footer_mode = FT_BOTH; p->footer_mode = FT_BOTH;

View file

@ -23,88 +23,108 @@
#ifndef PLUGIN_TEXT_VIEWER_PREFERENCES_H #ifndef PLUGIN_TEXT_VIEWER_PREFERENCES_H
#define PLUGIN_TEXT_VIEWER_PREFERENCES_H #define PLUGIN_TEXT_VIEWER_PREFERENCES_H
enum scrollbar_mode { /* scrollbar_mode */
enum {
SB_OFF = 0, SB_OFF = 0,
SB_ON, SB_ON,
}; };
struct tv_preferences { /* word_mode */
enum { enum {
WRAP = 0, WRAP = 0,
CHOP, CHOP,
} word_mode; };
/* line_mode */
enum { enum {
NORMAL = 0, NORMAL = 0,
JOIN, JOIN,
EXPAND, EXPAND,
REFLOW, REFLOW,
} line_mode; };
/* alignment */
enum { enum {
LEFT = 0, LEFT = 0,
RIGHT, RIGHT,
} alignment; };
enum codepages encoding;
enum scrollbar_mode horizontal_scrollbar;
enum scrollbar_mode vertical_scrollbar;
/* page_mode */
enum { enum {
NO_OVERLAP = 0, NO_OVERLAP = 0,
OVERLAP, OVERLAP,
} page_mode; };
/* header_mode */
enum { enum {
HD_NONE = 0, HD_NONE = 0,
HD_PATH, HD_PATH,
HD_SBAR, HD_SBAR,
HD_BOTH, HD_BOTH,
} header_mode; };
/* footer_mode */
enum { enum {
FT_NONE = 0, FT_NONE = 0,
FT_PAGE, FT_PAGE,
FT_SBAR, FT_SBAR,
FT_BOTH, FT_BOTH,
} footer_mode; };
/* horizontal_scroll_mode */
enum { enum {
SCREEN = 0, SCREEN = 0,
COLUMN, COLUMN,
} horizontal_scroll_mode; };
/* vertical_scroll_mode */
enum { enum {
PAGE = 0, PAGE = 0,
LINE, LINE,
} vertical_scroll_mode; };
/* narrow_mode */
enum {
NM_PAGE = 0,
NM_TOP_BOTTOM,
};
struct tv_preferences {
unsigned word_mode;
unsigned line_mode;
unsigned alignment;
unsigned encoding;
unsigned horizontal_scrollbar;
unsigned vertical_scrollbar;
unsigned page_mode;
unsigned header_mode;
unsigned footer_mode;
unsigned horizontal_scroll_mode;
unsigned vertical_scroll_mode;
int autoscroll_speed; int autoscroll_speed;
int windows; int windows;
enum { unsigned narrow_mode;
NM_PAGE = 0,
NM_TOP_BOTTOM,
} narrow_mode;
int indent_spaces; unsigned indent_spaces;
unsigned char font_name[MAX_PATH];
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
unsigned char font_name[MAX_PATH];
struct font *font; struct font *font;
#endif #endif
unsigned char file_name[MAX_PATH]; unsigned char file_name[MAX_PATH];
}; };
/* /*
* return the preferences * global pointer to the preferences
*
* return
* the pointer the preferences
*/ */
const struct tv_preferences *tv_get_preferences(void); extern struct tv_preferences *preferences;
/* /*
* change the preferences * change the preferences

View file

@ -135,7 +135,6 @@ void tv_seek(off_t offset, int whence)
static void tv_change_preferences(const struct tv_preferences *oldp) static void tv_change_preferences(const struct tv_preferences *oldp)
{ {
unsigned char bom[BOM_SIZE]; unsigned char bom[BOM_SIZE];
const struct tv_preferences *prefs = tv_get_preferences();
int cur_start_file_pos = start_file_pos; int cur_start_file_pos = start_file_pos;
off_t cur_file_pos = file_pos + buf_pos; off_t cur_file_pos = file_pos + buf_pos;
@ -145,21 +144,21 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
start_file_pos = 0; start_file_pos = 0;
/* open the new file */ /* open the new file */
if (oldp == NULL || rb->strcmp(oldp->file_name, prefs->file_name)) if (oldp == NULL || rb->strcmp(oldp->file_name, preferences->file_name))
{ {
if (fd >= 0) if (fd >= 0)
rb->close(fd); rb->close(fd);
fd = rb->open(prefs->file_name, O_RDONLY); fd = rb->open(preferences->file_name, O_RDONLY);
if (fd < 0) if (fd < 0)
return; return;
} }
/* /*
* When a file is UTF-8 file with BOM, if prefs.encoding is UTF-8, * When a file is UTF-8 file with BOM, if encoding is UTF-8,
* then file size decreases only BOM_SIZE. * then file size decreases only BOM_SIZE.
*/ */
if (prefs->encoding == UTF_8) if (preferences->encoding == UTF_8)
{ {
rb->lseek(fd, 0, SEEK_SET); rb->lseek(fd, 0, SEEK_SET);
rb->read(fd, bom, BOM_SIZE); rb->read(fd, bom, BOM_SIZE);
@ -171,16 +170,20 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET); tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET);
} }
bool tv_init_reader(unsigned char *buf, size_t bufsize, size_t *used_size) bool tv_init_reader(void)
{ {
if (bufsize < 2 * TV_MIN_BLOCK_SIZE) size_t size;
/* get the plugin buffer */
reader_buffer = rb->plugin_get_buffer(&size);
if (size < 2 * TV_MIN_BLOCK_SIZE)
return false; return false;
reader_buffer = buf; block_size = size / 2;
block_size = bufsize / 2;
buffer_size = 2 * block_size; buffer_size = 2 * block_size;
*used_size = buffer_size;
tv_add_preferences_change_listner(tv_change_preferences); tv_add_preferences_change_listner(tv_change_preferences);
return true; return true;
} }

View file

@ -28,20 +28,11 @@
/* /*
* initialize the reader module * initialize the reader module
* *
* [In] buf
* the start pointer of the buffer
*
* [In] size
* enabled buffer size
*
* [Out] used_size
* the size of the buffer which the pager uses
*
* return * return
* true initialize success * true initialize success
* false initialize failure * false initialize failure
*/ */
bool tv_init_reader(unsigned char *buf, size_t bufsize, size_t *used_size); bool tv_init_reader(void);
/* finalize the reader module */ /* finalize the reader module */
void tv_finalize_reader(void); void tv_finalize_reader(void);

View file

@ -181,9 +181,9 @@ static bool tv_read_preferences(int pfd, int version, struct tv_preferences *pre
else else
prefs->indent_spaces = 2; prefs->indent_spaces = 2;
#ifdef HAVE_LCD_BITMAP
rb->memcpy(prefs->font_name, buf + read_size - MAX_PATH, MAX_PATH); rb->memcpy(prefs->font_name, buf + read_size - MAX_PATH, MAX_PATH);
#ifdef HAVE_LCD_BITMAP
prefs->font = rb->font_get(FONT_UI); prefs->font = rb->font_get(FONT_UI);
#endif #endif
@ -213,7 +213,9 @@ static bool tv_write_preferences(int pfd, const struct tv_preferences *prefs)
*p++ = prefs->narrow_mode; *p++ = prefs->narrow_mode;
*p++ = prefs->indent_spaces; *p++ = prefs->indent_spaces;
#ifdef HAVE_LCD_BITMAP
rb->memcpy(buf + 28, prefs->font_name, MAX_PATH); rb->memcpy(buf + 28, prefs->font_name, MAX_PATH);
#endif
return (rb->write(pfd, buf, TV_PREFERENCES_SIZE) >= 0); return (rb->write(pfd, buf, TV_PREFERENCES_SIZE) >= 0);
} }
@ -457,7 +459,6 @@ static bool tv_copy_settings(int sfd, int dfd, int size)
bool tv_save_settings(void) bool tv_save_settings(void)
{ {
const struct tv_preferences *prefs = tv_get_preferences();
unsigned char buf[MAX_PATH+2]; unsigned char buf[MAX_PATH+2];
unsigned int fcount = 0; unsigned int fcount = 0;
unsigned int i; unsigned int i;
@ -502,7 +503,7 @@ bool tv_save_settings(void)
} }
size = (buf[MAX_PATH] << 8) | buf[MAX_PATH + 1]; size = (buf[MAX_PATH] << 8) | buf[MAX_PATH + 1];
if (rb->strcmp(buf, prefs->file_name) == 0) if (rb->strcmp(buf, preferences->file_name) == 0)
rb->lseek(ofd, size, SEEK_CUR); rb->lseek(ofd, size, SEEK_CUR);
else else
{ {
@ -522,12 +523,11 @@ bool tv_save_settings(void)
{ {
/* save to current read file's preferences and bookmarks */ /* save to current read file's preferences and bookmarks */
res = false; res = false;
rb->memset(buf, 0, MAX_PATH); rb->strlcpy(buf, preferences->file_name, MAX_PATH);
rb->strlcpy(buf, prefs->file_name, MAX_PATH);
if (rb->write(tfd, buf, MAX_PATH + 2) >= 0) if (rb->write(tfd, buf, MAX_PATH + 2) >= 0)
{ {
if (tv_write_preferences(tfd, prefs)) if (tv_write_preferences(tfd, preferences))
{ {
size = tv_serialize_bookmarks(tfd); size = tv_serialize_bookmarks(tfd);
if (size > 0) if (size > 0)

View file

@ -25,7 +25,7 @@
#include "tv_preferences.h" #include "tv_preferences.h"
#include "tv_text_processor.h" #include "tv_text_processor.h"
enum tv_text_type { enum{
TV_TEXT_UNKNOWN, TV_TEXT_UNKNOWN,
TV_TEXT_MAC, TV_TEXT_MAC,
TV_TEXT_UNIX, TV_TEXT_UNIX,
@ -41,13 +41,12 @@ enum tv_text_type {
#define TV_MAX_BLOCKS 5 #define TV_MAX_BLOCKS 5
static const struct tv_preferences *prefs; static unsigned text_type = TV_TEXT_UNKNOWN;
static enum tv_text_type text_type = TV_TEXT_UNKNOWN;
static const unsigned char *end_ptr; static const unsigned char *end_ptr;
static unsigned short *ucsbuf[TV_MAX_BLOCKS]; static unsigned short ucsbuf[TV_MAX_BLOCKS][TV_MAX_CHARS_PER_BLOCK];
static unsigned char *utf8buf; static unsigned char utf8buf[TV_MAX_CHARS_PER_BLOCK * (2 * 3)];
static unsigned char *outbuf; static unsigned char *outbuf;
static int block_count; static int block_count;
@ -96,7 +95,7 @@ static int tv_glyph_width(int ch)
if (rb->is_diacritic(ch, NULL)) if (rb->is_diacritic(ch, NULL))
return 0; return 0;
return rb->font_get_width(prefs->font, ch); return rb->font_get_width(preferences->font, ch);
#else #else
return 1; return 1;
#endif #endif
@ -136,13 +135,13 @@ static unsigned char *tv_get_ucs(const unsigned char *str, unsigned short *ch)
return (unsigned char *)str + 1; return (unsigned char *)str + 1;
} }
if (prefs->encoding == UTF_8) if (preferences->encoding == UTF_8)
return (unsigned char*)rb->utf8decode(str, ch); return (unsigned char*)rb->utf8decode(str, ch);
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
if ((*str >= 0x80) && if ((*str >= 0x80) &&
((prefs->encoding > SJIS) || ((preferences->encoding > SJIS) ||
(prefs->encoding == SJIS && (*str <= 0xa0 || *str >= 0xe0)))) (preferences->encoding == SJIS && (*str <= 0xa0 || *str >= 0xe0))))
{ {
if (str + 1 >= end_ptr) if (str + 1 >= end_ptr)
{ {
@ -153,7 +152,7 @@ static unsigned char *tv_get_ucs(const unsigned char *str, unsigned short *ch)
count = 2; count = 2;
} }
#endif #endif
rb->iso_decode(str, utf8_tmp, prefs->encoding, count); rb->iso_decode(str, utf8_tmp, preferences->encoding, count);
rb->utf8decode(utf8_tmp, ch); rb->utf8decode(utf8_tmp, ch);
return (unsigned char *)str + count; return (unsigned char *)str + count;
} }
@ -173,7 +172,7 @@ static bool tv_is_line_break_char(unsigned short ch)
size_t i; size_t i;
/* when the word mode is CHOP, all characters does not break line. */ /* when the word mode is CHOP, all characters does not break line. */
if (prefs->word_mode == CHOP) if (preferences->word_mode == CHOP)
return false; return false;
for (i = 0; i < sizeof(break_chars); i++) for (i = 0; i < sizeof(break_chars); i++)
@ -222,7 +221,7 @@ static int tv_form_reflow_line(unsigned short *ucs, int chars)
int spaces = 0; int spaces = 0;
int words_spaces; int words_spaces;
if (prefs->alignment == LEFT) if (preferences->alignment == LEFT)
{ {
while (chars > 0 && ucs[chars-1] == ' ') while (chars > 0 && ucs[chars-1] == ' ')
chars--; chars--;
@ -368,7 +367,6 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
unsigned short prev_ch; unsigned short prev_ch;
int chars = 0; int chars = 0;
int gw; int gw;
int i;
int line_break_width = 0; int line_break_width = 0;
int line_end_chars = 0; int line_end_chars = 0;
int width = 0; int width = 0;
@ -388,7 +386,7 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
next = tv_get_ucs(cur, &ch); next = tv_get_ucs(cur, &ch);
if (ch == '\n') if (ch == '\n')
{ {
if (prefs->line_mode != JOIN || tv_is_break_line_join_mode(next)) if (preferences->line_mode != JOIN || tv_is_break_line_join_mode(next))
{ {
line_end_ptr = next; line_end_ptr = next;
line_end_chars = chars; line_end_chars = chars;
@ -396,7 +394,7 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
break; break;
} }
if (prefs->word_mode == CHOP || tv_isspace(prev_ch)) if (preferences->word_mode == CHOP || tv_isspace(prev_ch))
continue; continue;
/* /*
@ -413,7 +411,7 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
* (1) spacelike character convert to ' ' * (1) spacelike character convert to ' '
* (2) plural spaces are collected to one * (2) plural spaces are collected to one
*/ */
if (prefs->line_mode == REFLOW) if (preferences->line_mode == REFLOW)
{ {
ch = ' '; ch = ' ';
if (prev_ch == ch) if (prev_ch == ch)
@ -421,14 +419,14 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
} }
/* when the alignment is RIGHT, ignores indent spaces. */ /* when the alignment is RIGHT, ignores indent spaces. */
if (prefs->alignment == RIGHT && is_indent) if (preferences->alignment == RIGHT && is_indent)
continue; continue;
} }
else else
is_indent = false; is_indent = false;
if (prefs->line_mode == REFLOW && is_indent) if (preferences->line_mode == REFLOW && is_indent)
gw = tv_glyph_width(ch) * prefs->indent_spaces; gw = tv_glyph_width(ch) * preferences->indent_spaces;
else else
gw = tv_glyph_width(ch); gw = tv_glyph_width(ch);
@ -445,11 +443,12 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
break; break;
} }
if (prefs->line_mode != REFLOW || !is_indent) if (preferences->line_mode != REFLOW || !is_indent)
ucs[chars++] = ch; ucs[chars++] = ch;
else else
{ {
for (i = 0; i < prefs->indent_spaces; i++) unsigned char i;
for (i = 0; i < preferences->indent_spaces; i++)
ucs[chars++] = ch; ucs[chars++] = ch;
} }
@ -473,7 +472,7 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
* when the last line break position is too short (line length < 0.75 * block width), * when the last line break position is too short (line length < 0.75 * block width),
* the line is cut off at the position where it is closest to the displayed width. * the line is cut off at the position where it is closest to the displayed width.
*/ */
if ((prefs->line_mode == REFLOW && line_break_ptr == NULL) || if ((preferences->line_mode == REFLOW && line_break_ptr == NULL) ||
(4 * line_break_width < 3 * block_width)) (4 * line_break_width < 3 * block_width))
{ {
line_end_ptr = cur; line_end_ptr = cur;
@ -505,7 +504,7 @@ int tv_create_formed_text(const unsigned char *src, ssize_t bufsize,
if (dst != NULL) if (dst != NULL)
*dst = utf8buf; *dst = utf8buf;
if (prefs->line_mode == EXPAND && (expand_extra_line = !expand_extra_line) == true) if (preferences->line_mode == EXPAND && (expand_extra_line = !expand_extra_line) == true)
return 0; return 0;
end_ptr = src + bufsize; end_ptr = src + bufsize;
@ -513,7 +512,7 @@ int tv_create_formed_text(const unsigned char *src, ssize_t bufsize,
tv_get_ucs(src, &ch); tv_get_ucs(src, &ch);
is_indent = (tv_isspace(ch) && !is_break_line); is_indent = (tv_isspace(ch) && !is_break_line);
if (is_indent && prefs->indent_spaces == 0 && (expand_extra_line = !expand_extra_line) == true) if (is_indent && preferences->indent_spaces == 0 && (expand_extra_line = !expand_extra_line) == true)
return 0; return 0;
for (i = 0; i < block_count; i++) for (i = 0; i < block_count; i++)
@ -527,14 +526,14 @@ int tv_create_formed_text(const unsigned char *src, ssize_t bufsize,
if (dst != NULL) if (dst != NULL)
{ {
if (prefs->alignment == RIGHT) if (preferences->alignment == RIGHT)
tv_align_right(chars); tv_align_right(chars);
for (i = 0; i < block_count; i++) for (i = 0; i < block_count; i++)
{ {
if (i == block || (is_multi && i == block + 1)) if (i == block || (is_multi && i == block + 1))
{ {
if (is_break_line && prefs->line_mode == REFLOW) if (is_break_line && preferences->line_mode == REFLOW)
chars[i] = tv_form_reflow_line(ucsbuf[i], chars[i]); chars[i] = tv_form_reflow_line(ucsbuf[i], chars[i]);
tv_decode2utf8(ucsbuf[i], chars[i]); tv_decode2utf8(ucsbuf[i], chars[i]);
@ -545,26 +544,11 @@ int tv_create_formed_text(const unsigned char *src, ssize_t bufsize,
return size; return size;
} }
bool tv_init_text_processor(unsigned char *buf, size_t bufsize, size_t *used_size) void tv_init_text_processor(void)
{ {
int i;
*used_size = TV_MAX_CHARS_PER_BLOCK * (2 * 3 + TV_MAX_BLOCKS * sizeof(unsigned short));
if (bufsize < *used_size)
return false;
prefs = tv_get_preferences();
text_type = TV_TEXT_UNKNOWN; text_type = TV_TEXT_UNKNOWN;
expand_extra_line = false; expand_extra_line = false;
is_break_line = false; is_break_line = false;
ucsbuf[0] = (unsigned short*)buf;
for (i = 1; i < TV_MAX_BLOCKS; i++)
ucsbuf[i] = ucsbuf[i - 1] + TV_MAX_CHARS_PER_BLOCK;
utf8buf = buf + TV_MAX_CHARS_PER_BLOCK * TV_MAX_BLOCKS * sizeof(unsigned short);
return true;
} }
void tv_set_creation_conditions(int blocks, int width) void tv_set_creation_conditions(int blocks, int width)

View file

@ -26,20 +26,8 @@
/* /*
* initialize the text processor module * initialize the text processor module
* *
* [In] buf
* the start pointer of the buffer
*
* [In] size
* enabled buffer size
*
* [Out] used_size
* the size of the buffer which the pager uses
*
* return
* true initialize success
* false initialize failure
*/ */
bool tv_init_text_processor(unsigned char *buf, size_t bufsize, size_t *used_size); void tv_init_text_processor(void);
/* /*
* set the processing conditions * set the processing conditions

View file

@ -29,19 +29,11 @@
static int get_block; static int get_block;
static bool get_double_blocks; static bool get_double_blocks;
bool tv_init_text_reader(unsigned char *buf, size_t bufsize, size_t *used_size) bool tv_init_text_reader(void)
{ {
size_t size; tv_init_text_processor();
if (!tv_init_text_processor(buf, bufsize, used_size)) return tv_init_pager();
return false;
size = *used_size;
if (!tv_init_pager(buf + size, bufsize - size, used_size))
return false;
*used_size += size;
return true;
} }
void tv_finalize_text_reader(void) void tv_finalize_text_reader(void)

View file

@ -26,20 +26,11 @@
/* /*
* initialize the text reader module * initialize the text reader module
* *
* [In] buf
* the start pointer of the buffer
*
* [In] size
* enabled buffer size
*
* [Out] used_size
* the size of the buffer which the pager uses
*
* return * return
* true initialize success * true initialize success
* false initialize failure * false initialize failure
*/ */
bool tv_init_text_reader(unsigned char *buf, size_t bufsize, size_t *used_size); bool tv_init_text_reader(void);
/* finalize the text reader module */ /* finalize the text reader module */
void tv_finalize_text_reader(void); void tv_finalize_text_reader(void);

View file

@ -50,8 +50,6 @@ static int col_width;
static int cur_window; static int cur_window;
static int cur_column; static int cur_column;
static const struct tv_preferences *prefs = NULL;
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
static bool tv_set_font(const unsigned char *font) static bool tv_set_font(const unsigned char *font)
{ {
@ -69,46 +67,25 @@ static bool tv_set_font(const unsigned char *font)
return true; return true;
} }
static void tv_check_header_and_footer(void)
{
struct tv_preferences new_prefs;
tv_copy_preferences(&new_prefs);
if (rb->global_settings->statusbar != STATUSBAR_TOP)
{
if (new_prefs.header_mode == HD_SBAR)
new_prefs.header_mode = HD_NONE;
else if (new_prefs.header_mode == HD_BOTH)
new_prefs.header_mode = HD_PATH;
}
if (rb->global_settings->statusbar != STATUSBAR_BOTTOM)
{
if (new_prefs.footer_mode == FT_SBAR)
new_prefs.footer_mode = FT_NONE;
else if (new_prefs.footer_mode == FT_BOTH)
new_prefs.footer_mode = FT_PAGE;
}
tv_set_preferences(&new_prefs);
}
static void tv_show_header(void) static void tv_show_header(void)
{ {
if (prefs->header_mode == HD_SBAR || prefs->header_mode == HD_BOTH) unsigned header_mode = header_mode;
if (header_mode == HD_SBAR || header_mode == HD_BOTH)
rb->gui_syncstatusbar_draw(rb->statusbars, true); rb->gui_syncstatusbar_draw(rb->statusbars, true);
if (prefs->header_mode == HD_PATH || prefs->header_mode == HD_BOTH) if (header_mode == HD_PATH || header_mode == HD_BOTH)
rb->lcd_putsxy(0, header_height - prefs->font->height, prefs->file_name); rb->lcd_putsxy(0, header_height - preferences->font->height, preferences->file_name);
} }
static void tv_show_footer(const struct tv_screen_pos *pos) static void tv_show_footer(const struct tv_screen_pos *pos)
{ {
unsigned char buf[12]; unsigned char buf[12];
unsigned footer_mode = preferences->footer_mode;
if (prefs->footer_mode == FT_SBAR || prefs->footer_mode == FT_BOTH) if (footer_mode == FT_SBAR || footer_mode == FT_BOTH)
rb->gui_syncstatusbar_draw(rb->statusbars, true); rb->gui_syncstatusbar_draw(rb->statusbars, true);
if (prefs->footer_mode == FT_PAGE || prefs->footer_mode == FT_BOTH) if (footer_mode == FT_PAGE || footer_mode == FT_BOTH)
{ {
if (pos->line == 0) if (pos->line == 0)
rb->snprintf(buf, sizeof(buf), "%d", pos->page + 1); rb->snprintf(buf, sizeof(buf), "%d", pos->page + 1);
@ -128,9 +105,9 @@ static void tv_show_scrollbar(off_t cur_pos, int size)
int sb_height; int sb_height;
sb_height = LCD_HEIGHT - header_height - footer_height; sb_height = LCD_HEIGHT - header_height - footer_height;
if (prefs->horizontal_scrollbar) if (preferences->horizontal_scrollbar)
{ {
items = prefs->windows * window_columns; items = preferences->windows * window_columns;
min_shown = cur_window * window_columns + cur_column; min_shown = cur_window * window_columns + cur_column;
max_shown = min_shown + window_columns; max_shown = min_shown + window_columns;
sb_width = (need_vertical_scrollbar)? TV_SCROLLBAR_WIDTH : 0; sb_width = (need_vertical_scrollbar)? TV_SCROLLBAR_WIDTH : 0;
@ -157,25 +134,27 @@ static void tv_show_scrollbar(off_t cur_pos, int size)
static int tv_calc_display_lines(void) static int tv_calc_display_lines(void)
{ {
int scrollbar_height = (prefs->horizontal_scrollbar)? TV_SCROLLBAR_HEIGHT : 0; int scrollbar_height = preferences->horizontal_scrollbar ? TV_SCROLLBAR_HEIGHT : 0;
unsigned header_mode = preferences->header_mode;
unsigned footer_mode = preferences->footer_mode;
header_height = (prefs->header_mode == HD_SBAR || prefs->header_mode == HD_BOTH)? header_height = (header_mode == HD_SBAR || header_mode == HD_BOTH)?
STATUSBAR_HEIGHT : 0; STATUSBAR_HEIGHT : 0;
footer_height = (prefs->footer_mode == FT_SBAR || prefs->footer_mode == FT_BOTH)? footer_height = (footer_mode == FT_SBAR || footer_mode == FT_BOTH)?
STATUSBAR_HEIGHT : 0; STATUSBAR_HEIGHT : 0;
if (prefs->header_mode == HD_NONE || prefs->header_mode == HD_PATH || if (header_mode == HD_NONE || header_mode == HD_PATH ||
prefs->footer_mode == FT_NONE || prefs->footer_mode == FT_PAGE) footer_mode == FT_NONE || footer_mode == FT_PAGE)
rb->gui_syncstatusbar_draw(rb->statusbars, false); rb->gui_syncstatusbar_draw(rb->statusbars, false);
if (prefs->header_mode == HD_PATH || prefs->header_mode == HD_BOTH) if (header_mode == HD_PATH || header_mode == HD_BOTH)
header_height += prefs->font->height; header_height += preferences->font->height;
if (prefs->footer_mode == FT_PAGE || prefs->footer_mode == FT_BOTH) if (footer_mode == FT_PAGE || footer_mode == FT_BOTH)
footer_height += prefs->font->height; footer_height += preferences->font->height;
return (LCD_HEIGHT - header_height - footer_height - scrollbar_height) / prefs->font->height; return (LCD_HEIGHT - header_height - footer_height - scrollbar_height) / preferences->font->height;
} }
#endif #endif
@ -195,8 +174,8 @@ static void tv_show_bookmarks(const struct tv_screen_pos *top_pos)
if (line >= 0 && line < display_lines) if (line >= 0 && line < display_lines)
{ {
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
rb->lcd_fillrect(start_width, header_height + line * prefs->font->height, rb->lcd_fillrect(start_width, header_height + line * preferences->font->height,
window_width, prefs->font->height); window_width, preferences->font->height);
#else #else
rb->lcd_putc(start_width - 1, line, TV_BOOKMARK_ICON); rb->lcd_putc(start_width - 1, line, TV_BOOKMARK_ICON);
#endif #endif
@ -215,30 +194,30 @@ void tv_draw_window(void)
int offset = cur_column * col_width; int offset = cur_column * col_width;
int size = 0; int size = 0;
int line_width; int line_width;
int draw_width = (prefs->windows - cur_window) * LCD_WIDTH - offset; int draw_width = (preferences->windows - cur_window) * LCD_WIDTH - offset;
int dx = start_width - offset; int dx = start_width - offset;
tv_copy_screen_pos(&pos); tv_copy_screen_pos(&pos);
rb->lcd_clear_display(); rb->lcd_clear_display();
if (prefs->alignment == LEFT) if (preferences->alignment == LEFT)
tv_read_start(cur_window, (cur_column > 0)); tv_read_start(cur_window, (cur_column > 0));
else else
tv_read_start(0, prefs->windows > 1); tv_read_start(0, preferences->windows > 1);
for (line = 0; line < display_lines; line++) for (line = 0; line < display_lines; line++)
{ {
if (!tv_get_next_line(&line_buf)) if (!tv_get_next_line(&line_buf))
break; break;
if (prefs->alignment == RIGHT) if (preferences->alignment == RIGHT)
{ {
rb->lcd_getstringsize(line_buf, &line_width, NULL); rb->lcd_getstringsize(line_buf, &line_width, NULL);
dx = draw_width - line_width; dx = draw_width - line_width;
} }
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
rb->lcd_putsxy(dx, header_height + line * prefs->font->height, line_buf); rb->lcd_putsxy(dx, header_height + line * preferences->font->height, line_buf);
#else #else
rb->lcd_puts(dx, line, line_buf); rb->lcd_puts(dx, line, line_buf);
#endif #endif
@ -284,12 +263,13 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
font_str = (oldp && !font_changing)? oldp->font_name : rb->global_settings->font_file; font_str = (oldp && !font_changing)? oldp->font_name : rb->global_settings->font_file;
/* change font */ /* change font */
if (font_changing || rb->strcmp(font_str, prefs->font_name)) if (font_changing || rb->strcmp(font_str, preferences->font_name))
{ {
font_changing = true; font_changing = true;
if (!tv_set_font(prefs->font_name)) if (!tv_set_font(preferences->font_name))
{ {
struct tv_preferences new_prefs = *prefs; struct tv_preferences new_prefs;
tv_copy_preferences(&new_prefs);
rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH); rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
tv_set_preferences(&new_prefs); tv_set_preferences(&new_prefs);
@ -299,7 +279,6 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
font_changing = false; font_changing = false;
/* calculates display lines */ /* calculates display lines */
tv_check_header_and_footer();
display_lines = tv_calc_display_lines(); display_lines = tv_calc_display_lines();
#else #else
(void)oldp; (void)oldp;
@ -309,12 +288,12 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
#endif #endif
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
col_width = 2 * rb->font_get_width(prefs->font, ' '); col_width = 2 * rb->font_get_width(preferences->font, ' ');
#else #else
col_width = 1; col_width = 1;
#endif #endif
if (cur_window >= prefs->windows) if (cur_window >= preferences->windows)
cur_window = 0; cur_window = 0;
window_width = LCD_WIDTH; window_width = LCD_WIDTH;
@ -322,8 +301,8 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
need_vertical_scrollbar = false; need_vertical_scrollbar = false;
start_width = 0; start_width = 0;
tv_seek_top(); tv_seek_top();
tv_set_read_conditions(prefs->windows, window_width); tv_set_read_conditions(preferences->windows, window_width);
if (tv_traverse_lines() && prefs->vertical_scrollbar) if (tv_traverse_lines() && preferences->vertical_scrollbar)
{ {
need_vertical_scrollbar = true; need_vertical_scrollbar = true;
start_width = TV_SCROLLBAR_WIDTH; start_width = TV_SCROLLBAR_WIDTH;
@ -337,17 +316,13 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
cur_column = 0; cur_column = 0;
tv_set_read_conditions(prefs->windows, window_width); tv_set_read_conditions(preferences->windows, window_width);
} }
bool tv_init_window(unsigned char *buf, size_t bufsize, size_t *used_size) bool tv_init_window(void)
{ {
tv_add_preferences_change_listner(tv_change_preferences); tv_add_preferences_change_listner(tv_change_preferences);
if (!tv_init_text_reader(buf, bufsize, used_size)) return tv_init_text_reader();
return false;
prefs = tv_get_preferences();
return true;
} }
void tv_finalize_window(void) void tv_finalize_window(void)
@ -356,7 +331,7 @@ void tv_finalize_window(void)
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
/* restore font */ /* restore font */
if (rb->strcmp(rb->global_settings->font_file, prefs->font_name)) if (rb->strcmp(rb->global_settings->font_file, preferences->font_name))
{ {
tv_set_font(rb->global_settings->font_file); tv_set_font(rb->global_settings->font_file);
} }
@ -373,9 +348,9 @@ void tv_move_window(int window_delta, int column_delta)
cur_window = 0; cur_window = 0;
cur_column = 0; cur_column = 0;
} }
else if (cur_window >= prefs->windows) else if (cur_window >= preferences->windows)
{ {
cur_window = prefs->windows - 1; cur_window = preferences->windows - 1;
cur_column = 0; cur_column = 0;
} }
@ -391,7 +366,7 @@ void tv_move_window(int window_delta, int column_delta)
} }
else else
{ {
if (cur_window == prefs->windows - 1) if (cur_window == preferences->windows - 1)
cur_column = 0; cur_column = 0;
else if (cur_column >= window_columns) else if (cur_column >= window_columns)
{ {

View file

@ -26,20 +26,11 @@
/* /*
* initialize the window module * initialize the window module
* *
* [In] buf
* the start pointer of the buffer
*
* [In] size
* enabled buffer size
*
* [Out] used_size
* the size of the buffer which the pager uses
*
* return * return
* true initialize success * true initialize success
* false initialize failure * false initialize failure
*/ */
bool tv_init_window(unsigned char *buf, size_t bufsize, size_t *used_size); bool tv_init_window(void);
/* finalize the window module */ /* finalize the window module */
void tv_finalize_window(void); void tv_finalize_window(void);