FS#11399 by me: fix r26998 for text_viewer

Restore the old behaviour:

- preferences must be read-write for tv_preferences.c , read-only for
  all other modules -> use pointer to const struct
- init functions must get the plugin buffer + its size as arguments for
  easily adding new functions -> use pointer to buffer pointer and size
  to make allocation easier
- preferences meaning is private to each file and must not be known by
  tv_preferences.c -> move tv_check_header_and_footer() back in
  tv_window.c; also avoid chaining 3 times the callbacks by calling
  tv_set_preferences() only once if more than one preference needs
  changing

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27089 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Rafaël Carré 2010-06-23 13:56:08 +00:00
parent cf9bba7102
commit 59fd2b24bd
13 changed files with 115 additions and 52 deletions

View file

@ -30,10 +30,15 @@
bool tv_init(const unsigned char *file)
{
size_t size;
/* get the plugin buffer */
unsigned char *buf = rb->plugin_get_buffer(&size);
tv_init_bookmark();
/* initialize modules */
if (!tv_init_window())
if (!tv_init_window(&buf, &size))
return false;
/* load the preferences and bookmark */

View file

@ -85,7 +85,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
tv_seek(0, SEEK_SET);
}
bool tv_init_pager(void)
bool tv_init_pager(unsigned char **buf, size_t *size)
{
tv_set_screen_pos(&cur_pos);
tv_add_preferences_change_listner(tv_change_preferences);
@ -95,7 +95,7 @@ bool tv_init_pager(void)
line_pos[0] = 0;
return tv_init_reader();
return tv_init_reader(buf, size);
}
void tv_finalize_pager(void)

View file

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

View file

@ -23,9 +23,10 @@
#include "plugin.h"
#include "tv_preferences.h"
/* global preferences */
static struct tv_preferences prefs;
struct tv_preferences *preferences = &prefs;
/* read-only preferences pointer, for access by other files */
const struct tv_preferences * const preferences = &prefs;
static int listner_count = 0;
@ -66,24 +67,6 @@ static void tv_notify_change_preferences(const struct tv_preferences *oldp)
}
}
static void tv_check_header_and_footer(void)
{
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)
{
static struct tv_preferences old_prefs;
@ -94,8 +77,7 @@ void tv_set_preferences(const struct tv_preferences *new_prefs)
tv_copy_preferences((oldp = &old_prefs));
is_initialized = true;
rb->memcpy(preferences, new_prefs, sizeof(struct tv_preferences));
tv_check_header_and_footer();
rb->memcpy(&prefs, new_prefs, sizeof(struct tv_preferences));
tv_notify_change_preferences(oldp);
}

View file

@ -122,9 +122,9 @@ struct tv_preferences {
};
/*
* global pointer to the preferences
* global pointer to the preferences (read-only)
*/
extern struct tv_preferences *preferences;
extern const struct tv_preferences * const preferences;
/*
* change the preferences

View file

@ -170,18 +170,18 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET);
}
bool tv_init_reader(void)
bool tv_init_reader(unsigned char **buf, size_t *size)
{
size_t size;
/* get the plugin buffer */
reader_buffer = rb->plugin_get_buffer(&size);
if (size < 2 * TV_MIN_BLOCK_SIZE)
if (*size < 2 * TV_MIN_BLOCK_SIZE)
return false;
block_size = size / 2;
block_size = *size / 2;
buffer_size = 2 * block_size;
reader_buffer = *buf;
*buf += buffer_size;
*size -= buffer_size;
tv_add_preferences_change_listner(tv_change_preferences);
return true;

View file

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

View file

@ -544,11 +544,16 @@ int tv_create_formed_text(const unsigned char *src, ssize_t bufsize,
return size;
}
void tv_init_text_processor(void)
bool tv_init_text_processor(unsigned char **buf, size_t *size)
{
/* unused : no need for dynamic buffer yet */
(void)buf;
(void)size;
text_type = TV_TEXT_UNKNOWN;
expand_extra_line = false;
is_break_line = false;
return true;
}
void tv_set_creation_conditions(int blocks, int width)

View file

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

View file

@ -29,11 +29,9 @@
static int get_block;
static bool get_double_blocks;
bool tv_init_text_reader(void)
bool tv_init_text_reader(unsigned char **buf, size_t *size)
{
tv_init_text_processor();
return tv_init_pager();
return tv_init_text_processor(buf, size) && tv_init_pager(buf, size);
}
void tv_finalize_text_reader(void)

View file

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

View file

@ -67,6 +67,40 @@ static bool tv_set_font(const unsigned char *font)
return true;
}
static bool tv_check_header_and_footer(struct tv_preferences *new_prefs)
{
bool change_prefs = false;
if (rb->global_settings->statusbar != STATUSBAR_TOP)
{
if (new_prefs->header_mode == HD_SBAR)
{
new_prefs->header_mode = HD_NONE;
change_prefs = true;
}
else if (new_prefs->header_mode == HD_BOTH)
{
new_prefs->header_mode = HD_PATH;
change_prefs = true;
}
}
if (rb->global_settings->statusbar != STATUSBAR_BOTTOM)
{
if (new_prefs->footer_mode == FT_SBAR)
{
new_prefs->footer_mode = FT_NONE;
change_prefs = true;
}
else if (new_prefs->footer_mode == FT_BOTH)
{
new_prefs->footer_mode = FT_PAGE;
change_prefs = true;
}
}
return change_prefs;
}
static void tv_show_header(void)
{
unsigned header_mode = header_mode;
@ -259,6 +293,9 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
#ifdef HAVE_LCD_BITMAP
static bool font_changing = false;
const unsigned char *font_str;
bool change_prefs = false;
struct tv_preferences new_prefs;
tv_copy_preferences(&new_prefs);
font_str = (oldp && !font_changing)? oldp->font_name : rb->global_settings->font_file;
@ -268,14 +305,17 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
font_changing = true;
if (!tv_set_font(preferences->font_name))
{
struct tv_preferences new_prefs;
tv_copy_preferences(&new_prefs);
rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
tv_set_preferences(&new_prefs);
return;
change_prefs = true;
}
}
if (tv_check_header_and_footer(&new_prefs) || change_prefs)
{
tv_set_preferences(&new_prefs);
return;
}
font_changing = false;
/* calculates display lines */
@ -319,10 +359,10 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
tv_set_read_conditions(preferences->windows, window_width);
}
bool tv_init_window(void)
bool tv_init_window(unsigned char **buf, size_t *size)
{
tv_add_preferences_change_listner(tv_change_preferences);
return tv_init_text_reader();
return tv_init_text_reader(buf, size);
}
void tv_finalize_window(void)

View file

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