2002-09-30 19:05:03 +00:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
2003-07-24 09:47:46 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Gilles Roux, 2003 Garrett Derner
|
2002-09-30 19:05:03 +00:00
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2003-06-29 16:33:04 +00:00
|
|
|
#include "plugin.h"
|
2003-07-24 09:47:46 +00:00
|
|
|
#include <ctype.h>
|
2006-04-04 12:04:15 +00:00
|
|
|
#include "playback_control.h"
|
2007-05-08 11:55:43 +00:00
|
|
|
#include "oldmenuapi.h"
|
2003-07-24 12:22:10 +00:00
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
PLUGIN_HEADER
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2007-08-21 21:15:32 +00:00
|
|
|
#define SETTINGS_FILE VIEWERS_DIR "/viewer.dat" /* binary file, so dont use .cfg */
|
|
|
|
#define BOOKMARKS_FILE VIEWERS_DIR "/viewer_bookmarks.dat"
|
2005-05-17 13:14:09 +00:00
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
#define WRAP_TRIM 44 /* Max number of spaces to trim (arbitrary) */
|
|
|
|
#define MAX_COLUMNS 64 /* Max displayable string len (over-estimate) */
|
|
|
|
#define MAX_WIDTH 910 /* Max line length in WIDE mode */
|
|
|
|
#define READ_PREV_ZONE 910 /* Arbitrary number less than SMALL_BLOCK_SIZE */
|
|
|
|
#define SMALL_BLOCK_SIZE 0x1000 /* 4k: Smallest file chunk we will read */
|
|
|
|
#define LARGE_BLOCK_SIZE 0x2000 /* 8k: Preferable size of file chunk to read */
|
|
|
|
#define BUFFER_SIZE 0x3000 /* 12k: Mem reserved for buffered file data */
|
|
|
|
#define TOP_SECTOR buffer
|
|
|
|
#define MID_SECTOR (buffer + SMALL_BLOCK_SIZE)
|
|
|
|
#define BOTTOM_SECTOR (buffer + 2*(SMALL_BLOCK_SIZE))
|
2006-05-11 20:34:37 +00:00
|
|
|
#define SCROLLBAR_WIDTH 6
|
2003-07-24 09:47:46 +00:00
|
|
|
|
2006-09-18 15:31:51 +00:00
|
|
|
#define MAX_BOOKMARKED_FILES (((signed)BUFFER_SIZE/(signed)sizeof(struct bookmarked_file_info))-1)
|
2006-09-17 10:32:49 +00:00
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
/* Out-Of-Bounds test for any pointer to data in the buffer */
|
|
|
|
#define BUFFER_OOB(p) ((p) < buffer || (p) >= buffer_end)
|
|
|
|
|
|
|
|
/* Does the buffer contain the beginning of the file? */
|
|
|
|
#define BUFFER_BOF() (file_pos==0)
|
|
|
|
|
|
|
|
/* Does the buffer contain the end of the file? */
|
|
|
|
#define BUFFER_EOF() (file_size-file_pos <= BUFFER_SIZE)
|
|
|
|
|
|
|
|
/* Formula for the endpoint address outside of buffer data */
|
|
|
|
#define BUFFER_END() \
|
|
|
|
((BUFFER_EOF()) ? (file_size-file_pos+buffer) : (buffer+BUFFER_SIZE))
|
|
|
|
|
|
|
|
/* Is the entire file being shown in one screen? */
|
|
|
|
#define ONE_SCREEN_FITS_ALL() \
|
|
|
|
(next_screen_ptr==NULL && screen_top_ptr==buffer && BUFFER_BOF())
|
|
|
|
|
|
|
|
/* Is a scrollbar called for on the current screen? */
|
2005-05-17 13:14:09 +00:00
|
|
|
#define NEED_SCROLLBAR() \
|
2006-05-01 05:45:18 +00:00
|
|
|
((!(ONE_SCREEN_FITS_ALL())) && (prefs.scrollbar_mode==SB_ON))
|
2003-07-24 09:47:46 +00:00
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
/* variable button definitions */
|
2005-05-17 13:14:09 +00:00
|
|
|
|
|
|
|
/* Recorder keys */
|
2004-10-16 00:07:43 +00:00
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_QUIT BUTTON_OFF
|
2004-10-16 00:07:43 +00:00
|
|
|
#define VIEWER_PAGE_UP BUTTON_UP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_MENU BUTTON_F1
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_PLAY
|
2004-10-16 00:07:43 +00:00
|
|
|
#define VIEWER_LINE_UP (BUTTON_ON | BUTTON_UP)
|
|
|
|
#define VIEWER_LINE_DOWN (BUTTON_ON | BUTTON_DOWN)
|
|
|
|
#define VIEWER_COLUMN_LEFT (BUTTON_ON | BUTTON_LEFT)
|
2007-01-14 13:48:09 +00:00
|
|
|
#define VIEWER_COLUMN_RIGHT (BUTTON_ON | BUTTON_RIGHT)
|
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_OFF
|
|
|
|
#define VIEWER_PAGE_UP BUTTON_UP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
|
|
|
#define VIEWER_MENU BUTTON_F1
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_SELECT
|
|
|
|
#define VIEWER_LINE_UP (BUTTON_ON | BUTTON_UP)
|
|
|
|
#define VIEWER_LINE_DOWN (BUTTON_ON | BUTTON_DOWN)
|
|
|
|
#define VIEWER_COLUMN_LEFT (BUTTON_ON | BUTTON_LEFT)
|
2004-10-16 00:07:43 +00:00
|
|
|
#define VIEWER_COLUMN_RIGHT (BUTTON_ON | BUTTON_RIGHT)
|
|
|
|
|
2005-05-17 13:14:09 +00:00
|
|
|
/* Ondio keys */
|
2004-10-16 00:07:43 +00:00
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
2006-05-03 23:16:53 +00:00
|
|
|
#define VIEWER_QUIT BUTTON_OFF
|
2004-10-16 00:07:43 +00:00
|
|
|
#define VIEWER_PAGE_UP BUTTON_UP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
2006-05-03 23:16:53 +00:00
|
|
|
#define VIEWER_MENU (BUTTON_MENU|BUTTON_REPEAT)
|
|
|
|
#define VIEWER_AUTOSCROLL_PRE BUTTON_MENU
|
|
|
|
#define VIEWER_AUTOSCROLL (BUTTON_MENU|BUTTON_REL)
|
2004-10-16 00:07:43 +00:00
|
|
|
|
2005-05-17 13:14:09 +00:00
|
|
|
/* Player keys */
|
2004-10-16 00:07:43 +00:00
|
|
|
#elif CONFIG_KEYPAD == PLAYER_PAD
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_QUIT BUTTON_STOP
|
2004-10-16 00:07:43 +00:00
|
|
|
#define VIEWER_PAGE_UP BUTTON_LEFT
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_RIGHT
|
2006-05-03 23:16:53 +00:00
|
|
|
#define VIEWER_SCREEN_LEFT (BUTTON_ON|BUTTON_LEFT)
|
|
|
|
#define VIEWER_SCREEN_RIGHT (BUTTON_ON|BUTTON_RIGHT)
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_MENU BUTTON_MENU
|
2006-05-03 23:16:53 +00:00
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_PLAY
|
2004-10-16 00:07:43 +00:00
|
|
|
|
2005-06-29 12:47:24 +00:00
|
|
|
/* iRiver H1x0 && H3x0 keys */
|
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IRIVER_H300_PAD)
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_QUIT BUTTON_OFF
|
2005-02-04 12:41:09 +00:00
|
|
|
#define VIEWER_PAGE_UP BUTTON_UP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_MENU BUTTON_MODE
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_SELECT
|
2005-02-12 02:02:20 +00:00
|
|
|
#define VIEWER_LINE_UP (BUTTON_ON | BUTTON_UP)
|
|
|
|
#define VIEWER_LINE_DOWN (BUTTON_ON | BUTTON_DOWN)
|
2006-05-03 23:16:53 +00:00
|
|
|
#define VIEWER_COLUMN_LEFT (BUTTON_ON | BUTTON_LEFT)
|
|
|
|
#define VIEWER_COLUMN_RIGHT (BUTTON_ON | BUTTON_RIGHT)
|
2005-02-04 12:41:09 +00:00
|
|
|
|
2006-06-30 16:43:47 +00:00
|
|
|
#define VIEWER_RC_QUIT BUTTON_RC_STOP
|
|
|
|
|
2007-07-27 09:57:27 +00:00
|
|
|
/* iPods */
|
2006-02-24 20:54:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
|
2007-07-27 09:57:27 +00:00
|
|
|
(CONFIG_KEYPAD == IPOD_3G_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IPOD_1G2G_PAD)
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_QUIT_PRE BUTTON_SELECT
|
|
|
|
#define VIEWER_QUIT (BUTTON_SELECT | BUTTON_MENU)
|
2006-02-16 01:18:21 +00:00
|
|
|
#define VIEWER_PAGE_UP BUTTON_SCROLL_BACK
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_SCROLL_FWD
|
2005-12-14 01:31:37 +00:00
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
2006-05-03 23:16:53 +00:00
|
|
|
#define VIEWER_MENU BUTTON_MENU
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_PLAY
|
2005-12-14 01:31:37 +00:00
|
|
|
|
2006-01-12 00:35:50 +00:00
|
|
|
/* iFP7xx keys */
|
|
|
|
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_QUIT BUTTON_PLAY
|
2006-01-12 00:35:50 +00:00
|
|
|
#define VIEWER_PAGE_UP BUTTON_UP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_MENU BUTTON_MODE
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_SELECT
|
2006-01-12 00:35:50 +00:00
|
|
|
|
2006-01-18 11:09:06 +00:00
|
|
|
/* iAudio X5 keys */
|
2007-03-16 23:02:39 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_QUIT BUTTON_POWER
|
2006-01-18 11:09:06 +00:00
|
|
|
#define VIEWER_PAGE_UP BUTTON_UP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_MENU BUTTON_SELECT
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_PLAY
|
2006-01-18 11:09:06 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
/* GIGABEAT keys */
|
2006-02-24 15:42:52 +00:00
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_PAD
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_QUIT BUTTON_POWER
|
2006-02-24 15:42:52 +00:00
|
|
|
#define VIEWER_PAGE_UP BUTTON_UP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
2006-05-01 05:45:18 +00:00
|
|
|
#define VIEWER_MENU BUTTON_MENU
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_A
|
2006-02-24 15:42:52 +00:00
|
|
|
|
2006-10-26 13:38:09 +00:00
|
|
|
/* Sansa E200 keys */
|
|
|
|
#elif CONFIG_KEYPAD == SANSA_E200_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_POWER
|
|
|
|
#define VIEWER_PAGE_UP BUTTON_UP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
|
|
|
#define VIEWER_MENU BUTTON_SELECT
|
2007-05-06 15:41:10 +00:00
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_REC
|
|
|
|
#define VIEWER_LINE_UP BUTTON_SCROLL_UP
|
|
|
|
#define VIEWER_LINE_DOWN BUTTON_SCROLL_DOWN
|
2006-10-26 13:38:09 +00:00
|
|
|
|
2007-09-20 10:49:48 +00:00
|
|
|
/* Sansa C200 keys */
|
|
|
|
#elif CONFIG_KEYPAD == SANSA_C200_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_POWER
|
|
|
|
#define VIEWER_PAGE_UP BUTTON_VOL_UP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_VOL_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
|
|
|
#define VIEWER_MENU BUTTON_SELECT
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_REC
|
|
|
|
#define VIEWER_LINE_UP BUTTON_UP
|
|
|
|
#define VIEWER_LINE_DOWN BUTTON_DOWN
|
|
|
|
|
2006-08-03 20:17:25 +00:00
|
|
|
/* iriver H10 keys */
|
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H10_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_POWER
|
|
|
|
#define VIEWER_PAGE_UP BUTTON_SCROLL_UP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_SCROLL_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
|
|
|
#define VIEWER_MENU BUTTON_REW
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_PLAY
|
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
#endif
|
|
|
|
|
2006-09-18 15:31:51 +00:00
|
|
|
/* stuff for the bookmarking */
|
2006-09-17 10:32:49 +00:00
|
|
|
struct bookmarked_file_info {
|
|
|
|
long file_position;
|
|
|
|
int top_ptr_pos;
|
|
|
|
char filename[MAX_PATH];
|
|
|
|
};
|
2006-09-18 15:31:51 +00:00
|
|
|
|
|
|
|
struct bookmark_file_data {
|
|
|
|
signed int bookmarked_files_count;
|
|
|
|
struct bookmarked_file_info bookmarks[];
|
|
|
|
};
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
struct preferences {
|
|
|
|
enum {
|
|
|
|
WRAP=0,
|
|
|
|
CHOP,
|
|
|
|
} word_mode;
|
2003-07-24 09:47:46 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
enum {
|
|
|
|
NORMAL=0,
|
|
|
|
JOIN,
|
|
|
|
EXPAND,
|
2006-05-03 23:16:53 +00:00
|
|
|
REFLOW, /* won't be set on charcell LCD, must be last */
|
2006-05-01 05:45:18 +00:00
|
|
|
} line_mode;
|
2003-07-24 09:47:46 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
enum {
|
|
|
|
NARROW=0,
|
|
|
|
WIDE,
|
|
|
|
} view_mode;
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2006-05-11 20:34:37 +00:00
|
|
|
enum {
|
|
|
|
ISO_8859_1=0,
|
|
|
|
ISO_8859_7,
|
|
|
|
ISO_8859_8,
|
|
|
|
CP1251,
|
|
|
|
ISO_8859_11,
|
|
|
|
ISO_8859_6,
|
|
|
|
ISO_8859_9,
|
|
|
|
ISO_8859_2,
|
2007-10-01 17:16:31 +00:00
|
|
|
CP1250,
|
2006-05-11 20:34:37 +00:00
|
|
|
SJIS,
|
|
|
|
GB2312,
|
|
|
|
KSX1001,
|
|
|
|
BIG5,
|
|
|
|
UTF8,
|
|
|
|
ENCODINGS
|
|
|
|
} encoding; /* FIXME: What should default encoding be? */
|
|
|
|
|
2002-09-30 19:05:03 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-05-01 05:45:18 +00:00
|
|
|
enum {
|
|
|
|
SB_OFF=0,
|
|
|
|
SB_ON,
|
|
|
|
} scrollbar_mode;
|
|
|
|
bool need_scrollbar;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
NO_OVERLAP=0,
|
|
|
|
OVERLAP,
|
|
|
|
} page_mode;
|
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PAGE=0,
|
|
|
|
LINE,
|
|
|
|
} scroll_mode;
|
|
|
|
|
|
|
|
int autoscroll_speed;
|
2006-09-18 15:31:51 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
} prefs;
|
2006-01-27 13:30:57 +00:00
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
static unsigned char buffer[BUFFER_SIZE + 1];
|
2006-05-11 20:34:37 +00:00
|
|
|
static unsigned char line_break[] = {0,0x20,9,0xB,0xC,'-'};
|
2005-05-13 13:32:57 +00:00
|
|
|
static int display_columns; /* number of (pixel) columns on the display */
|
2003-07-24 09:47:46 +00:00
|
|
|
static int display_lines; /* number of lines on the display */
|
2005-05-13 13:32:57 +00:00
|
|
|
static int draw_columns; /* number of (pixel) columns available for text */
|
|
|
|
static int par_indent_spaces; /* number of spaces to indent first paragraph */
|
2003-07-24 09:47:46 +00:00
|
|
|
static int fd;
|
2005-05-17 13:14:09 +00:00
|
|
|
static char *file_name;
|
2003-07-24 09:47:46 +00:00
|
|
|
static long file_size;
|
|
|
|
static bool mac_text;
|
|
|
|
static long file_pos; /* Position of the top of the buffer in the file */
|
|
|
|
static unsigned char *buffer_end; /*Set to BUFFER_END() when file_pos changes*/
|
|
|
|
static int max_line_len;
|
|
|
|
static unsigned char *screen_top_ptr;
|
|
|
|
static unsigned char *next_screen_ptr;
|
|
|
|
static unsigned char *next_screen_to_draw_ptr;
|
|
|
|
static unsigned char *next_line_ptr;
|
|
|
|
static struct plugin_api* rb;
|
2006-05-11 20:34:37 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static struct font *pf;
|
|
|
|
#endif
|
|
|
|
|
2006-09-17 10:32:49 +00:00
|
|
|
|
2006-05-11 20:34:37 +00:00
|
|
|
int glyph_width(int ch)
|
|
|
|
{
|
|
|
|
if (ch == 0)
|
|
|
|
ch = ' ';
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
return rb->font_get_width(pf, ch);
|
|
|
|
#else
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char* get_ucs(const unsigned char* str, unsigned short* ch)
|
|
|
|
{
|
|
|
|
unsigned char utf8_tmp[6];
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (prefs.encoding == UTF8)
|
|
|
|
return (unsigned char*)rb->utf8decode(str, ch);
|
|
|
|
|
|
|
|
count = BUFFER_OOB(str+2)? 1:2;
|
|
|
|
rb->iso_decode(str, utf8_tmp, prefs.encoding, count);
|
|
|
|
rb->utf8decode(utf8_tmp, ch);
|
2003-07-24 09:47:46 +00:00
|
|
|
|
2006-05-11 20:34:37 +00:00
|
|
|
if ((prefs.encoding == SJIS && *str > 0xA0 && *str < 0xE0) || prefs.encoding < SJIS)
|
|
|
|
return (unsigned char*)str+1;
|
|
|
|
else
|
|
|
|
return (unsigned char*)str+2;
|
|
|
|
}
|
2005-05-13 13:32:57 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
bool done = false;
|
|
|
|
int col = 0;
|
|
|
|
|
2006-06-03 07:04:02 +00:00
|
|
|
#define ADVANCE_COUNTERS(c) { width += glyph_width(c); k++; }
|
2006-08-01 17:48:38 +00:00
|
|
|
#define LINE_IS_FULL ((k>=MAX_COLUMNS-1) ||( width >= draw_columns))
|
2006-06-03 07:04:02 +00:00
|
|
|
#define LINE_IS_NOT_FULL ((k<MAX_COLUMNS-1) &&( width < draw_columns))
|
2005-05-13 13:32:57 +00:00
|
|
|
static unsigned char* crop_at_width(const unsigned char* p)
|
|
|
|
{
|
|
|
|
int k,width;
|
2006-05-11 20:34:37 +00:00
|
|
|
unsigned short ch;
|
|
|
|
const unsigned char *oldp = p;
|
2005-05-13 13:32:57 +00:00
|
|
|
|
|
|
|
k=width=0;
|
|
|
|
|
2006-06-03 07:04:02 +00:00
|
|
|
while (LINE_IS_NOT_FULL) {
|
2006-05-11 20:34:37 +00:00
|
|
|
oldp = p;
|
|
|
|
p = get_ucs(p, &ch);
|
|
|
|
ADVANCE_COUNTERS(ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (unsigned char*)oldp;
|
2005-05-13 13:32:57 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
static unsigned char* find_first_feed(const unsigned char* p, int size)
|
2002-09-30 19:05:03 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
for (i=0; i < size; i++)
|
|
|
|
if (p[i] == 0)
|
|
|
|
return (unsigned char*) p+i;
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
return NULL;
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
static unsigned char* find_last_feed(const unsigned char* p, int size)
|
2002-09-30 19:05:03 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
for (i=size-1; i>=0; i--)
|
|
|
|
if (p[i] == 0)
|
|
|
|
return (unsigned char*) p+i;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char* find_last_space(const unsigned char* p, int size)
|
|
|
|
{
|
|
|
|
int i, j, k;
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
k = (prefs.line_mode==JOIN) || (prefs.line_mode==REFLOW) ? 0:1;
|
2003-07-24 09:47:46 +00:00
|
|
|
|
2006-05-11 20:34:37 +00:00
|
|
|
if (!BUFFER_OOB(&p[size]))
|
|
|
|
for (j=k; j < ((int) sizeof(line_break)) - 1; j++)
|
|
|
|
if (p[size] == line_break[j])
|
|
|
|
return (unsigned char*) p+size;
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
for (i=size-1; i>=0; i--)
|
|
|
|
for (j=k; j < (int) sizeof(line_break); j++)
|
2007-08-05 04:16:21 +00:00
|
|
|
{
|
2007-08-13 13:53:33 +00:00
|
|
|
if (!((p[i] == '-') && (prefs.word_mode == WRAP)))
|
2007-08-05 04:16:21 +00:00
|
|
|
if (p[i] == line_break[j])
|
|
|
|
return (unsigned char*) p+i;
|
|
|
|
}
|
2003-07-24 09:47:46 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2005-05-13 13:32:57 +00:00
|
|
|
static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_short)
|
2003-07-24 09:47:46 +00:00
|
|
|
{
|
|
|
|
const unsigned char *next_line = NULL;
|
2005-05-13 13:32:57 +00:00
|
|
|
int size, i, j, k, width, search_len, spaces, newlines;
|
|
|
|
bool first_chars;
|
2003-07-24 09:47:46 +00:00
|
|
|
unsigned char c;
|
|
|
|
|
2006-02-16 01:18:21 +00:00
|
|
|
if (is_short != NULL)
|
2005-05-13 13:32:57 +00:00
|
|
|
*is_short = true;
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
if BUFFER_OOB(cur_line)
|
|
|
|
return NULL;
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.view_mode == WIDE) {
|
2005-05-13 13:32:57 +00:00
|
|
|
search_len = MAX_WIDTH;
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
2006-05-01 05:45:18 +00:00
|
|
|
else { /* prefs.view_mode == NARROW */
|
2006-02-16 01:18:21 +00:00
|
|
|
search_len = crop_at_width(cur_line) - cur_line;
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size = BUFFER_OOB(cur_line+search_len) ? buffer_end-cur_line : search_len;
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
if ((prefs.line_mode == JOIN) || (prefs.line_mode == REFLOW)) {
|
2003-07-24 09:47:46 +00:00
|
|
|
/* Need to scan ahead and possibly increase search_len and size,
|
|
|
|
or possibly set next_line at second hard return in a row. */
|
|
|
|
next_line = NULL;
|
2005-05-13 13:32:57 +00:00
|
|
|
first_chars=true;
|
|
|
|
for (j=k=width=spaces=newlines=0; ; j++) {
|
2005-05-14 16:46:31 +00:00
|
|
|
if (BUFFER_OOB(cur_line+j))
|
|
|
|
return NULL;
|
2005-05-13 13:32:57 +00:00
|
|
|
if (LINE_IS_FULL) {
|
|
|
|
size = search_len = j;
|
2003-07-24 09:47:46 +00:00
|
|
|
break;
|
2005-05-13 13:32:57 +00:00
|
|
|
}
|
2003-07-24 09:47:46 +00:00
|
|
|
|
|
|
|
c = cur_line[j];
|
|
|
|
switch (c) {
|
|
|
|
case ' ':
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.line_mode == REFLOW) {
|
2005-05-13 13:32:57 +00:00
|
|
|
if (newlines > 0) {
|
|
|
|
size = j;
|
|
|
|
next_line = cur_line + size;
|
|
|
|
return (unsigned char*) next_line;
|
|
|
|
}
|
|
|
|
if (j==0) /* i=1 is intentional */
|
|
|
|
for (i=0; i<par_indent_spaces; i++)
|
2006-02-16 01:18:21 +00:00
|
|
|
ADVANCE_COUNTERS(' ');
|
2005-05-13 13:32:57 +00:00
|
|
|
}
|
|
|
|
if (!first_chars) spaces++;
|
2003-07-24 09:47:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
if (newlines > 0) {
|
|
|
|
size = j;
|
2005-05-13 13:32:57 +00:00
|
|
|
next_line = cur_line + size - spaces;
|
2003-07-24 09:47:46 +00:00
|
|
|
if (next_line != cur_line)
|
|
|
|
return (unsigned char*) next_line;
|
|
|
|
break;
|
|
|
|
}
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
newlines++;
|
2005-05-13 13:32:57 +00:00
|
|
|
size += spaces -1;
|
2003-07-24 09:47:46 +00:00
|
|
|
if (BUFFER_OOB(cur_line+size) || size > 2*search_len)
|
|
|
|
return NULL;
|
|
|
|
search_len = size;
|
2005-05-13 13:32:57 +00:00
|
|
|
spaces = first_chars? 0:1;
|
2003-07-24 09:47:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.line_mode==JOIN || newlines>0) {
|
2005-05-14 16:46:31 +00:00
|
|
|
while (spaces) {
|
|
|
|
spaces--;
|
2005-05-13 13:32:57 +00:00
|
|
|
ADVANCE_COUNTERS(' ');
|
|
|
|
if (LINE_IS_FULL) {
|
|
|
|
size = search_len = j;
|
2005-05-14 16:46:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-05-13 13:32:57 +00:00
|
|
|
}
|
|
|
|
newlines=0;
|
2005-05-14 16:46:31 +00:00
|
|
|
} else if (spaces) {
|
2006-02-16 01:18:21 +00:00
|
|
|
/* REFLOW, multiple spaces between words: count only
|
2005-05-13 13:32:57 +00:00
|
|
|
* one. If more are needed, they will be added
|
2006-02-16 01:18:21 +00:00
|
|
|
* while drawing. */
|
2005-05-13 13:32:57 +00:00
|
|
|
search_len = size;
|
|
|
|
spaces=0;
|
|
|
|
ADVANCE_COUNTERS(' ');
|
|
|
|
if (LINE_IS_FULL) {
|
|
|
|
size = search_len = j;
|
|
|
|
break;
|
|
|
|
}
|
2006-02-16 01:18:21 +00:00
|
|
|
}
|
2005-05-13 13:32:57 +00:00
|
|
|
first_chars = false;
|
|
|
|
ADVANCE_COUNTERS(c);
|
2003-07-24 09:47:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-24 09:47:46 +00:00
|
|
|
else {
|
|
|
|
/* find first hard return */
|
|
|
|
next_line = find_first_feed(cur_line, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next_line == NULL)
|
|
|
|
if (size == search_len) {
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.word_mode == WRAP) /* Find last space */
|
2003-07-24 09:47:46 +00:00
|
|
|
next_line = find_last_space(cur_line, size);
|
|
|
|
|
|
|
|
if (next_line == NULL)
|
2005-05-13 13:32:57 +00:00
|
|
|
next_line = crop_at_width(cur_line);
|
2003-07-24 09:47:46 +00:00
|
|
|
else
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.word_mode == WRAP)
|
2003-07-24 09:47:46 +00:00
|
|
|
for (i=0;
|
|
|
|
i<WRAP_TRIM && isspace(next_line[0]) && !BUFFER_OOB(next_line);
|
|
|
|
i++)
|
|
|
|
next_line++;
|
|
|
|
}
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.line_mode == EXPAND)
|
2003-07-24 09:47:46 +00:00
|
|
|
if (!BUFFER_OOB(next_line)) /* Not Null & not out of bounds */
|
|
|
|
if (next_line[0] == 0)
|
|
|
|
if (next_line != cur_line)
|
|
|
|
return (unsigned char*) next_line;
|
|
|
|
|
|
|
|
/* If next_line is pointing to a zero, increment it; i.e.,
|
|
|
|
leave the terminator at the end of cur_line. If pointing
|
|
|
|
to a hyphen, increment only if there is room to display
|
|
|
|
the hyphen on current line (won't apply in WIDE mode,
|
|
|
|
since it's guarenteed there won't be room). */
|
|
|
|
if (!BUFFER_OOB(next_line)) /* Not Null & not out of bounds */
|
2006-05-11 20:34:37 +00:00
|
|
|
if (next_line[0] == 0)/* ||
|
|
|
|
(next_line[0] == '-' && next_line-cur_line < draw_columns)) */
|
2003-07-24 09:47:46 +00:00
|
|
|
next_line++;
|
|
|
|
|
|
|
|
if (BUFFER_OOB(next_line))
|
|
|
|
return NULL;
|
|
|
|
|
2005-05-13 13:32:57 +00:00
|
|
|
if (is_short)
|
|
|
|
*is_short = false;
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
return (unsigned char*) next_line;
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
static unsigned char* find_prev_line(const unsigned char* cur_line)
|
2002-09-30 19:05:03 +00:00
|
|
|
{
|
2003-07-24 09:47:46 +00:00
|
|
|
const unsigned char *prev_line = NULL;
|
|
|
|
const unsigned char *p;
|
|
|
|
|
|
|
|
if BUFFER_OOB(cur_line)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* To wrap consistently at the same places, we must
|
|
|
|
start with a known hard return, then work downwards.
|
|
|
|
We can either search backwards for a hard return,
|
|
|
|
or simply start wrapping downwards from top of buffer.
|
|
|
|
If current line is not near top of buffer, this is
|
|
|
|
a file with long lines (paragraphs). We would need to
|
|
|
|
read earlier sectors before we could decide how to
|
|
|
|
properly wrap the lines above the current line, but
|
|
|
|
it probably is not worth the disk access. Instead,
|
|
|
|
start with top of buffer and wrap down from there.
|
|
|
|
This may result in some lines wrapping at different
|
|
|
|
points from where they wrap when scrolling down.
|
|
|
|
If buffer is at top of file, start at top of buffer. */
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
if ((prefs.line_mode == JOIN) || (prefs.line_mode == REFLOW))
|
2003-07-24 09:47:46 +00:00
|
|
|
prev_line = p = NULL;
|
|
|
|
else
|
|
|
|
prev_line = p = find_last_feed(buffer, cur_line-buffer-1);
|
|
|
|
/* Null means no line feeds in buffer above current line. */
|
|
|
|
|
|
|
|
if (prev_line == NULL)
|
|
|
|
if (BUFFER_BOF() || cur_line - buffer > READ_PREV_ZONE)
|
|
|
|
prev_line = p = buffer;
|
|
|
|
/* (else return NULL and read previous block) */
|
|
|
|
|
|
|
|
/* Wrap downwards until too far, then use the one before. */
|
|
|
|
while (p < cur_line && p != NULL) {
|
|
|
|
prev_line = p;
|
2005-05-13 13:32:57 +00:00
|
|
|
p = find_next_line(prev_line, NULL);
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
2003-07-24 09:47:46 +00:00
|
|
|
|
|
|
|
if (BUFFER_OOB(prev_line))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (unsigned char*) prev_line;
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
static void fill_buffer(long pos, unsigned char* buf, unsigned size)
|
2002-09-30 19:05:03 +00:00
|
|
|
{
|
2003-07-24 09:47:46 +00:00
|
|
|
/* Read from file and preprocess the data */
|
|
|
|
/* To minimize disk access, always read on sector boundaries */
|
|
|
|
unsigned numread, i;
|
|
|
|
bool found_CR = false;
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
rb->lseek(fd, pos, SEEK_SET);
|
2003-07-24 09:47:46 +00:00
|
|
|
numread = rb->read(fd, buf, size);
|
2005-01-26 22:48:25 +00:00
|
|
|
rb->button_clear_queue(); /* clear button queue */
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
for(i = 0; i < numread; i++) {
|
|
|
|
switch(buf[i]) {
|
2002-09-30 19:05:03 +00:00
|
|
|
case '\r':
|
2003-07-24 09:47:46 +00:00
|
|
|
if (mac_text) {
|
|
|
|
buf[i] = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buf[i] = ' ';
|
|
|
|
found_CR = true;
|
|
|
|
}
|
2002-09-30 19:05:03 +00:00
|
|
|
break;
|
2003-07-24 09:47:46 +00:00
|
|
|
|
2002-09-30 19:05:03 +00:00
|
|
|
case '\n':
|
2003-07-24 09:47:46 +00:00
|
|
|
buf[i] = 0;
|
|
|
|
found_CR = false;
|
2002-09-30 19:05:03 +00:00
|
|
|
break;
|
2003-07-24 09:47:46 +00:00
|
|
|
|
|
|
|
case 0: /* No break between case 0 and default, intentionally */
|
|
|
|
buf[i] = ' ';
|
2002-09-30 19:05:03 +00:00
|
|
|
default:
|
2003-07-24 09:47:46 +00:00
|
|
|
if (found_CR) {
|
|
|
|
buf[i - 1] = 0;
|
|
|
|
found_CR = false;
|
|
|
|
mac_text = true;
|
|
|
|
}
|
2002-09-30 19:05:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
static int read_and_synch(int direction)
|
|
|
|
{
|
|
|
|
/* Read next (or prev) block, and reposition global pointers. */
|
|
|
|
/* direction: 1 for down (i.e., further into file), -1 for up */
|
|
|
|
int move_size, move_vector, offset;
|
|
|
|
unsigned char *fill_buf;
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
if (direction == -1) /* up */ {
|
|
|
|
move_size = SMALL_BLOCK_SIZE;
|
|
|
|
offset = 0;
|
|
|
|
fill_buf = TOP_SECTOR;
|
|
|
|
rb->memcpy(BOTTOM_SECTOR, MID_SECTOR, SMALL_BLOCK_SIZE);
|
|
|
|
rb->memcpy(MID_SECTOR, TOP_SECTOR, SMALL_BLOCK_SIZE);
|
|
|
|
}
|
|
|
|
else /* down */ {
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.view_mode == WIDE) {
|
2003-07-24 09:47:46 +00:00
|
|
|
/* WIDE mode needs more buffer so we have to read smaller blocks */
|
|
|
|
move_size = SMALL_BLOCK_SIZE;
|
|
|
|
offset = LARGE_BLOCK_SIZE;
|
|
|
|
fill_buf = BOTTOM_SECTOR;
|
|
|
|
rb->memcpy(TOP_SECTOR, MID_SECTOR, SMALL_BLOCK_SIZE);
|
|
|
|
rb->memcpy(MID_SECTOR, BOTTOM_SECTOR, SMALL_BLOCK_SIZE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
move_size = LARGE_BLOCK_SIZE;
|
|
|
|
offset = SMALL_BLOCK_SIZE;
|
|
|
|
fill_buf = MID_SECTOR;
|
|
|
|
rb->memcpy(TOP_SECTOR, BOTTOM_SECTOR, SMALL_BLOCK_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
move_vector = direction * move_size;
|
|
|
|
screen_top_ptr -= move_vector;
|
|
|
|
file_pos += move_vector;
|
|
|
|
buffer_end = BUFFER_END(); /* Update whenever file_pos changes */
|
|
|
|
fill_buffer(file_pos + offset, fill_buf, move_size);
|
|
|
|
return move_vector;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void viewer_scroll_up(void)
|
|
|
|
{
|
|
|
|
unsigned char *p;
|
|
|
|
|
|
|
|
p = find_prev_line(screen_top_ptr);
|
|
|
|
if (p == NULL && !BUFFER_BOF()) {
|
|
|
|
read_and_synch(-1);
|
|
|
|
p = find_prev_line(screen_top_ptr);
|
|
|
|
}
|
|
|
|
if (p != NULL)
|
|
|
|
screen_top_ptr = p;
|
|
|
|
}
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
static void viewer_scroll_down(void)
|
|
|
|
{
|
|
|
|
if (next_screen_ptr != NULL)
|
|
|
|
screen_top_ptr = next_line_ptr;
|
|
|
|
}
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static void viewer_scrollbar(void) {
|
2006-05-11 20:34:37 +00:00
|
|
|
int items, min_shown, max_shown;
|
2003-07-24 09:47:46 +00:00
|
|
|
|
|
|
|
items = (int) file_size; /* (SH1 int is same as long) */
|
|
|
|
min_shown = (int) file_pos + (screen_top_ptr - buffer);
|
|
|
|
|
|
|
|
if (next_screen_ptr == NULL)
|
|
|
|
max_shown = items;
|
|
|
|
else
|
|
|
|
max_shown = min_shown + (next_screen_ptr - screen_top_ptr);
|
|
|
|
|
2006-11-19 14:11:42 +00:00
|
|
|
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],0, 0, SCROLLBAR_WIDTH-1,
|
|
|
|
LCD_HEIGHT, items, min_shown, max_shown, VERTICAL);
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void viewer_draw(int col)
|
|
|
|
{
|
2006-05-11 20:34:37 +00:00
|
|
|
int i, j, k, line_len, line_width, resynch_move, spaces, left_col=0;
|
2005-05-13 13:32:57 +00:00
|
|
|
int width, extra_spaces, indent_spaces, spaces_per_word;
|
|
|
|
bool multiple_spacing, line_is_short;
|
2006-05-11 20:34:37 +00:00
|
|
|
unsigned short ch;
|
|
|
|
unsigned char *str, *oldstr;
|
2003-07-24 09:47:46 +00:00
|
|
|
unsigned char *line_begin;
|
|
|
|
unsigned char *line_end;
|
|
|
|
unsigned char c;
|
|
|
|
unsigned char scratch_buffer[MAX_COLUMNS + 1];
|
2006-03-01 13:31:36 +00:00
|
|
|
unsigned char utf8_buffer[MAX_COLUMNS*4 + 1];
|
|
|
|
unsigned char *endptr;
|
2003-07-24 09:47:46 +00:00
|
|
|
|
|
|
|
/* If col==-1 do all calculations but don't display */
|
|
|
|
if (col != -1) {
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-05-11 20:34:37 +00:00
|
|
|
left_col = prefs.need_scrollbar? SCROLLBAR_WIDTH:0;
|
2003-07-24 09:47:46 +00:00
|
|
|
#else
|
|
|
|
left_col = 0;
|
|
|
|
#endif
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
}
|
|
|
|
max_line_len = 0;
|
|
|
|
line_begin = line_end = screen_top_ptr;
|
|
|
|
|
|
|
|
for (i = 0; i < display_lines; i++) {
|
|
|
|
if (BUFFER_OOB(line_end))
|
|
|
|
break; /* Happens after display last line at BUFFER_EOF() */
|
|
|
|
|
|
|
|
line_begin = line_end;
|
2005-05-13 13:32:57 +00:00
|
|
|
line_end = find_next_line(line_begin, &line_is_short);
|
2003-07-24 09:47:46 +00:00
|
|
|
|
|
|
|
if (line_end == NULL) {
|
|
|
|
if (BUFFER_EOF()) {
|
|
|
|
if (i < display_lines - 1 && !BUFFER_BOF()) {
|
|
|
|
if (col != -1)
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
|
|
|
|
for (; i < display_lines - 1; i++)
|
|
|
|
viewer_scroll_up();
|
|
|
|
|
|
|
|
line_begin = line_end = screen_top_ptr;
|
|
|
|
i = -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
line_end = buffer_end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
resynch_move = read_and_synch(1); /* Read block & move ptrs */
|
|
|
|
line_begin -= resynch_move;
|
|
|
|
if (i > 0)
|
|
|
|
next_line_ptr -= resynch_move;
|
|
|
|
|
2005-05-13 13:32:57 +00:00
|
|
|
line_end = find_next_line(line_begin, NULL);
|
2003-07-24 09:47:46 +00:00
|
|
|
if (line_end == NULL) /* Should not really happen */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line_len = line_end - line_begin;
|
|
|
|
|
2006-05-11 20:34:37 +00:00
|
|
|
/* calculate line_len */
|
|
|
|
str = oldstr = line_begin;
|
|
|
|
j = -1;
|
|
|
|
while (str < line_end) {
|
|
|
|
oldstr = str;
|
|
|
|
str = crop_at_width(str);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
line_width = j*draw_columns;
|
|
|
|
while (oldstr < line_end) {
|
|
|
|
oldstr = get_ucs(oldstr, &ch);
|
|
|
|
line_width += glyph_width(ch);
|
|
|
|
}
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.line_mode == JOIN) {
|
2003-07-24 09:47:46 +00:00
|
|
|
if (line_begin[0] == 0) {
|
|
|
|
line_begin++;
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.word_mode == CHOP)
|
2003-07-24 09:47:46 +00:00
|
|
|
line_end++;
|
2005-05-13 13:32:57 +00:00
|
|
|
else
|
|
|
|
line_len--;
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
|
|
|
for (j=k=spaces=0; j < line_len; j++) {
|
|
|
|
if (k == MAX_COLUMNS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
c = line_begin[j];
|
|
|
|
switch (c) {
|
|
|
|
case ' ':
|
|
|
|
spaces++;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
spaces = 0;
|
|
|
|
scratch_buffer[k++] = ' ';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
while (spaces) {
|
|
|
|
spaces--;
|
|
|
|
scratch_buffer[k++] = ' ';
|
|
|
|
if (k == MAX_COLUMNS - 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
scratch_buffer[k++] = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-05-11 20:34:37 +00:00
|
|
|
if (col != -1) {
|
|
|
|
scratch_buffer[k] = 0;
|
|
|
|
endptr = rb->iso_decode(scratch_buffer + col, utf8_buffer,
|
2006-08-01 17:48:38 +00:00
|
|
|
prefs.encoding, draw_columns/glyph_width('i'));
|
2006-05-11 20:34:37 +00:00
|
|
|
*endptr = 0;
|
|
|
|
}
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
2006-05-01 05:45:18 +00:00
|
|
|
else if (prefs.line_mode == REFLOW) {
|
2005-05-13 13:32:57 +00:00
|
|
|
if (line_begin[0] == 0) {
|
|
|
|
line_begin++;
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.word_mode == CHOP)
|
2005-05-13 13:32:57 +00:00
|
|
|
line_end++;
|
|
|
|
else
|
|
|
|
line_len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
indent_spaces = 0;
|
|
|
|
if (!line_is_short) {
|
|
|
|
multiple_spacing = false;
|
2006-05-11 20:34:37 +00:00
|
|
|
width=spaces=0;
|
|
|
|
for (str = line_begin; str < line_end; ) {
|
|
|
|
str = get_ucs(str, &ch);
|
|
|
|
switch (ch) {
|
2005-05-13 13:32:57 +00:00
|
|
|
case ' ':
|
|
|
|
case 0:
|
2006-05-11 20:34:37 +00:00
|
|
|
if ((str == line_begin) && (prefs.word_mode==WRAP))
|
2006-02-16 01:18:21 +00:00
|
|
|
/* special case: indent the paragraph,
|
2005-05-13 13:32:57 +00:00
|
|
|
* don't count spaces */
|
|
|
|
indent_spaces = par_indent_spaces;
|
2006-02-16 01:18:21 +00:00
|
|
|
else if (!multiple_spacing)
|
2005-05-13 13:32:57 +00:00
|
|
|
spaces++;
|
|
|
|
multiple_spacing = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
multiple_spacing = false;
|
2006-05-11 20:34:37 +00:00
|
|
|
width += glyph_width(ch);
|
2005-05-13 13:32:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (multiple_spacing) spaces--;
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2005-05-13 13:32:57 +00:00
|
|
|
if (spaces) {
|
|
|
|
/* total number of spaces to insert between words */
|
2006-05-11 20:34:37 +00:00
|
|
|
extra_spaces = (draw_columns-width)/glyph_width(' ')
|
2005-05-13 13:32:57 +00:00
|
|
|
- indent_spaces;
|
|
|
|
/* number of spaces between each word*/
|
|
|
|
spaces_per_word = extra_spaces / spaces;
|
|
|
|
/* number of words with n+1 spaces (to fill up) */
|
|
|
|
extra_spaces = extra_spaces % spaces;
|
|
|
|
if (spaces_per_word > 2) { /* too much spacing is awful */
|
|
|
|
spaces_per_word = 3;
|
|
|
|
extra_spaces = 0;
|
2006-02-16 01:18:21 +00:00
|
|
|
}
|
2005-05-13 13:32:57 +00:00
|
|
|
} else { /* this doesn't matter much... no spaces anyway */
|
|
|
|
spaces_per_word = extra_spaces = 0;
|
|
|
|
}
|
|
|
|
} else { /* end of a paragraph: don't fill line */
|
|
|
|
spaces_per_word = 1;
|
|
|
|
extra_spaces = 0;
|
|
|
|
}
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2005-05-13 13:32:57 +00:00
|
|
|
multiple_spacing = false;
|
|
|
|
for (j=k=spaces=0; j < line_len; j++) {
|
|
|
|
if (k == MAX_COLUMNS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
c = line_begin[j];
|
|
|
|
switch (c) {
|
|
|
|
case ' ':
|
|
|
|
case 0:
|
2006-05-01 05:45:18 +00:00
|
|
|
if (j==0 && prefs.word_mode==WRAP) { /* indent paragraph */
|
2005-05-13 13:32:57 +00:00
|
|
|
for (j=0; j<par_indent_spaces; j++)
|
|
|
|
scratch_buffer[k++] = ' ';
|
|
|
|
j=0;
|
2006-02-16 01:18:21 +00:00
|
|
|
}
|
2005-05-13 13:32:57 +00:00
|
|
|
else if (!multiple_spacing) {
|
|
|
|
for (width = spaces<extra_spaces ? -1:0; width < spaces_per_word; width++)
|
|
|
|
scratch_buffer[k++] = ' ';
|
|
|
|
spaces++;
|
|
|
|
}
|
|
|
|
multiple_spacing = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
scratch_buffer[k++] = c;
|
|
|
|
multiple_spacing = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2006-05-11 20:34:37 +00:00
|
|
|
if (col != -1) {
|
|
|
|
scratch_buffer[k] = 0;
|
|
|
|
endptr = rb->iso_decode(scratch_buffer + col, utf8_buffer,
|
|
|
|
prefs.encoding, k-col);
|
|
|
|
*endptr = 0;
|
|
|
|
}
|
2006-02-16 01:18:21 +00:00
|
|
|
}
|
2006-05-01 05:45:18 +00:00
|
|
|
else { /* prefs.line_mode != JOIN && prefs.line_mode != REFLOW */
|
2003-07-24 09:47:46 +00:00
|
|
|
if (col != -1)
|
2006-05-11 20:34:37 +00:00
|
|
|
if (line_width > col) {
|
|
|
|
str = oldstr = line_begin;
|
|
|
|
k = col;
|
|
|
|
width = 0;
|
2006-06-03 07:04:02 +00:00
|
|
|
while( (width<draw_columns) && (oldstr<line_end) )
|
|
|
|
{
|
|
|
|
oldstr = get_ucs(oldstr, &ch);
|
2006-07-25 20:49:53 +00:00
|
|
|
if (k > 0) {
|
|
|
|
k -= glyph_width(ch);
|
|
|
|
line_begin = oldstr;
|
|
|
|
} else {
|
|
|
|
width += glyph_width(ch);
|
|
|
|
}
|
2006-05-11 20:34:37 +00:00
|
|
|
}
|
2006-06-03 07:04:02 +00:00
|
|
|
|
|
|
|
if(prefs.view_mode==WIDE)
|
|
|
|
endptr = rb->iso_decode(line_begin, utf8_buffer,
|
|
|
|
prefs.encoding, oldstr-line_begin);
|
|
|
|
else
|
|
|
|
endptr = rb->iso_decode(line_begin, utf8_buffer,
|
|
|
|
prefs.encoding, line_end-line_begin);
|
2006-03-01 13:31:36 +00:00
|
|
|
*endptr = 0;
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-11 20:34:37 +00:00
|
|
|
if (col != -1 && line_width > col)
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
rb->lcd_putsxy(left_col, i*pf->height, utf8_buffer);
|
|
|
|
#else
|
|
|
|
rb->lcd_puts(left_col, i, utf8_buffer);
|
|
|
|
#endif
|
|
|
|
if (line_width > max_line_len)
|
|
|
|
max_line_len = line_width;
|
2003-07-24 09:47:46 +00:00
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
next_line_ptr = line_end;
|
|
|
|
}
|
|
|
|
next_screen_ptr = line_end;
|
|
|
|
if (BUFFER_OOB(next_screen_ptr))
|
|
|
|
next_screen_ptr = NULL;
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-05-01 05:45:18 +00:00
|
|
|
next_screen_to_draw_ptr = prefs.page_mode==OVERLAP? line_begin: next_screen_ptr;
|
2003-07-24 09:47:46 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.need_scrollbar)
|
2003-07-24 09:47:46 +00:00
|
|
|
viewer_scrollbar();
|
|
|
|
#else
|
|
|
|
next_screen_to_draw_ptr = next_screen_ptr;
|
|
|
|
#endif
|
2007-04-06 22:55:00 +00:00
|
|
|
|
|
|
|
if (col != -1)
|
|
|
|
rb->lcd_update();
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void viewer_top(void)
|
|
|
|
{
|
|
|
|
/* Read top of file into buffer
|
|
|
|
and point screen pointer to top */
|
|
|
|
file_pos = 0;
|
|
|
|
buffer_end = BUFFER_END(); /* Update whenever file_pos changes */
|
|
|
|
screen_top_ptr = buffer;
|
|
|
|
fill_buffer(0, buffer, BUFFER_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void viewer_bottom(void)
|
|
|
|
{
|
|
|
|
/* Read bottom of file into buffer
|
|
|
|
and point screen pointer to bottom */
|
|
|
|
long last_sectors;
|
|
|
|
|
|
|
|
if (file_size > BUFFER_SIZE) {
|
|
|
|
/* Find last buffer in file, round up to next sector boundary */
|
|
|
|
last_sectors = file_size - BUFFER_SIZE + SMALL_BLOCK_SIZE;
|
|
|
|
last_sectors /= SMALL_BLOCK_SIZE;
|
|
|
|
last_sectors *= SMALL_BLOCK_SIZE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
last_sectors = 0;
|
|
|
|
}
|
|
|
|
file_pos = last_sectors;
|
|
|
|
buffer_end = BUFFER_END(); /* Update whenever file_pos changes */
|
|
|
|
screen_top_ptr = buffer_end-1;
|
|
|
|
fill_buffer(last_sectors, buffer, BUFFER_SIZE);
|
|
|
|
}
|
|
|
|
|
2006-05-03 23:16:53 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2003-07-24 09:47:46 +00:00
|
|
|
static void init_need_scrollbar(void) {
|
|
|
|
/* Call viewer_draw in quiet mode to initialize next_screen_ptr,
|
|
|
|
and thus ONE_SCREEN_FITS_ALL(), and thus NEED_SCROLLBAR() */
|
|
|
|
viewer_draw(-1);
|
2006-05-01 05:45:18 +00:00
|
|
|
prefs.need_scrollbar = NEED_SCROLLBAR();
|
2006-05-11 20:34:37 +00:00
|
|
|
draw_columns = prefs.need_scrollbar? display_columns-SCROLLBAR_WIDTH : display_columns;
|
|
|
|
par_indent_spaces = draw_columns/(5*glyph_width(' '));
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
2006-01-18 11:30:46 +00:00
|
|
|
#else
|
|
|
|
#define init_need_scrollbar()
|
2003-07-24 09:47:46 +00:00
|
|
|
#endif
|
|
|
|
|
2005-05-17 13:14:09 +00:00
|
|
|
static bool viewer_init(void)
|
2002-09-30 19:05:03 +00:00
|
|
|
{
|
2003-07-24 09:47:46 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-05-13 13:32:57 +00:00
|
|
|
|
|
|
|
pf = rb->font_get(FONT_UI);
|
2006-05-01 05:45:18 +00:00
|
|
|
|
2005-05-13 13:32:57 +00:00
|
|
|
display_lines = LCD_HEIGHT / pf->height;
|
2006-07-15 13:53:18 +00:00
|
|
|
draw_columns = display_columns = LCD_WIDTH;
|
2003-07-24 09:47:46 +00:00
|
|
|
#else
|
2005-05-13 13:32:57 +00:00
|
|
|
/* REAL fixed pitch :) all chars use up 1 cell */
|
2003-07-24 09:47:46 +00:00
|
|
|
display_lines = 2;
|
2005-05-13 13:32:57 +00:00
|
|
|
draw_columns = display_columns = 11;
|
|
|
|
par_indent_spaces = 2;
|
2003-07-24 09:47:46 +00:00
|
|
|
#endif
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2005-05-17 13:14:09 +00:00
|
|
|
fd = rb->open(file_name, O_RDONLY);
|
2002-09-30 19:05:03 +00:00
|
|
|
if (fd==-1)
|
|
|
|
return false;
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
file_size = rb->filesize(fd);
|
|
|
|
if (file_size==-1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Init mac_text value used in processing buffer */
|
|
|
|
mac_text = false;
|
|
|
|
|
2006-05-11 20:34:37 +00:00
|
|
|
/* Set codepage to system default */
|
|
|
|
prefs.encoding = rb->global_settings->default_codepage;
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
/* Read top of file into buffer;
|
|
|
|
init file_pos, buffer_end, screen_top_ptr */
|
|
|
|
viewer_top();
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
/* Init prefs.need_scrollbar value */
|
2003-07-24 09:47:46 +00:00
|
|
|
init_need_scrollbar();
|
2002-09-30 19:05:03 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
static void viewer_reset_settings(void)
|
|
|
|
{
|
|
|
|
prefs.word_mode = WRAP;
|
|
|
|
prefs.line_mode = NORMAL;
|
|
|
|
prefs.view_mode = NARROW;
|
|
|
|
prefs.scroll_mode = PAGE;
|
2005-05-17 13:14:09 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-05-01 05:45:18 +00:00
|
|
|
prefs.page_mode = NO_OVERLAP;
|
|
|
|
prefs.scrollbar_mode = SB_OFF;
|
2005-05-17 13:14:09 +00:00
|
|
|
#endif
|
2006-05-03 23:16:53 +00:00
|
|
|
prefs.autoscroll_speed = 1;
|
2006-05-01 05:45:18 +00:00
|
|
|
}
|
2005-05-17 13:14:09 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
static void viewer_load_settings(void) /* same name as global, but not the same file.. */
|
2005-05-17 13:14:09 +00:00
|
|
|
{
|
2007-09-13 00:18:28 +00:00
|
|
|
int settings_fd, i;
|
|
|
|
struct bookmark_file_data *data;
|
|
|
|
|
|
|
|
/* read settings file */
|
2005-05-17 13:14:09 +00:00
|
|
|
settings_fd=rb->open(SETTINGS_FILE, O_RDONLY);
|
2007-09-13 00:18:28 +00:00
|
|
|
if ((settings_fd < 0) || (rb->filesize(settings_fd) != sizeof(struct preferences)))
|
2006-05-01 05:45:18 +00:00
|
|
|
{
|
2007-09-13 00:18:28 +00:00
|
|
|
rb->splash(HZ*2, "No Valid Settings File");
|
|
|
|
}
|
|
|
|
else
|
2006-05-01 05:45:18 +00:00
|
|
|
{
|
2007-09-13 00:18:28 +00:00
|
|
|
rb->read(settings_fd, &prefs, sizeof(struct preferences));
|
|
|
|
rb->close(settings_fd);
|
|
|
|
}
|
2005-05-17 13:14:09 +00:00
|
|
|
|
2007-09-13 00:18:28 +00:00
|
|
|
data = (struct bookmark_file_data*)buffer; /* grab the text buffer */
|
|
|
|
data->bookmarked_files_count = 0;
|
|
|
|
|
|
|
|
/* read bookmarks if file exists */
|
2006-09-18 15:31:51 +00:00
|
|
|
settings_fd = rb->open(BOOKMARKS_FILE, O_RDONLY);
|
|
|
|
if (settings_fd >= 0)
|
|
|
|
{
|
2007-09-13 00:18:28 +00:00
|
|
|
/* figure out how many items to read */
|
|
|
|
rb->read(settings_fd, &data->bookmarked_files_count, sizeof(signed int));
|
2006-09-18 15:31:51 +00:00
|
|
|
if (data->bookmarked_files_count > MAX_BOOKMARKED_FILES)
|
2007-09-13 00:18:28 +00:00
|
|
|
data->bookmarked_files_count = MAX_BOOKMARKED_FILES;
|
2006-09-18 15:31:51 +00:00
|
|
|
rb->read(settings_fd, data->bookmarks,
|
|
|
|
sizeof(struct bookmarked_file_info) * data->bookmarked_files_count);
|
|
|
|
rb->close(settings_fd);
|
2007-09-13 00:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check if current file is in list */
|
|
|
|
for (i=0; i < data->bookmarked_files_count; i++)
|
|
|
|
{
|
|
|
|
if (!rb->strcmp(file_name, data->bookmarks[i].filename))
|
2006-09-18 15:31:51 +00:00
|
|
|
{
|
|
|
|
file_pos = data->bookmarks[i].file_position;
|
|
|
|
screen_top_ptr = buffer + data->bookmarks[i].top_ptr_pos;
|
2007-09-13 00:18:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* prevent potential slot overflow */
|
|
|
|
if (i >= data->bookmarked_files_count)
|
|
|
|
{
|
|
|
|
if (i < MAX_BOOKMARKED_FILES)
|
|
|
|
data->bookmarked_files_count++;
|
|
|
|
else
|
|
|
|
i = MAX_BOOKMARKED_FILES-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write bookmark file with spare slot in first position
|
|
|
|
to be filled in by viewer_save_settings */
|
|
|
|
settings_fd = rb->open(BOOKMARKS_FILE, O_WRONLY|O_CREAT);
|
|
|
|
if (settings_fd >=0 )
|
|
|
|
{
|
|
|
|
/* write count and skip first slot */
|
|
|
|
rb->write (settings_fd, &data->bookmarked_files_count, sizeof(signed int));
|
|
|
|
rb->PREFIX(lseek)(settings_fd,sizeof(struct bookmarked_file_info),SEEK_CUR);
|
|
|
|
|
|
|
|
/* shuffle up bookmarks */
|
|
|
|
rb->write (settings_fd, data->bookmarks, sizeof(struct bookmarked_file_info)*i);
|
|
|
|
rb->close(settings_fd);
|
|
|
|
}
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
init_need_scrollbar();
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
buffer_end = BUFFER_END(); /* Update whenever file_pos changes */
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2007-09-13 00:18:28 +00:00
|
|
|
if (BUFFER_OOB(screen_top_ptr))
|
|
|
|
{
|
2006-05-01 05:45:18 +00:00
|
|
|
screen_top_ptr = buffer;
|
2005-05-17 13:14:09 +00:00
|
|
|
}
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2005-05-17 13:14:09 +00:00
|
|
|
fill_buffer(file_pos, buffer, BUFFER_SIZE);
|
|
|
|
}
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
static void viewer_save_settings(void)/* same name as global, but not the same file.. */
|
2005-05-17 13:14:09 +00:00
|
|
|
{
|
2006-05-01 05:45:18 +00:00
|
|
|
int settings_fd;
|
2007-08-13 13:53:33 +00:00
|
|
|
|
2007-02-01 23:08:15 +00:00
|
|
|
settings_fd = rb->creat(SETTINGS_FILE); /* create the settings file */
|
2006-09-17 10:32:49 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
rb->write (settings_fd, &prefs, sizeof(struct preferences));
|
2005-05-17 13:14:09 +00:00
|
|
|
rb->close(settings_fd);
|
2006-09-18 15:31:51 +00:00
|
|
|
|
|
|
|
settings_fd = rb->open(BOOKMARKS_FILE, O_WRONLY|O_CREAT);
|
|
|
|
if (settings_fd >= 0 )
|
|
|
|
{
|
2006-09-18 15:46:06 +00:00
|
|
|
struct bookmarked_file_info b;
|
2006-09-18 15:31:51 +00:00
|
|
|
b.file_position = file_pos;
|
|
|
|
b.top_ptr_pos = screen_top_ptr - buffer;
|
2006-09-18 15:46:06 +00:00
|
|
|
rb->memset(&b.filename[0],0,MAX_PATH);
|
2006-09-18 15:31:51 +00:00
|
|
|
rb->strcpy(b.filename,file_name);
|
|
|
|
rb->PREFIX(lseek)(settings_fd,sizeof(signed int),SEEK_SET);
|
|
|
|
rb->write (settings_fd, &b, sizeof(struct bookmarked_file_info));
|
|
|
|
rb->close(settings_fd);
|
|
|
|
}
|
2006-02-16 01:18:21 +00:00
|
|
|
}
|
2005-05-17 13:14:09 +00:00
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
static void viewer_exit(void *parameter)
|
2002-09-30 19:05:03 +00:00
|
|
|
{
|
2004-10-16 00:07:43 +00:00
|
|
|
(void)parameter;
|
|
|
|
|
2005-05-17 13:14:09 +00:00
|
|
|
viewer_save_settings();
|
2003-06-29 16:33:04 +00:00
|
|
|
rb->close(fd);
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
static int col_limit(int col)
|
2002-09-30 19:05:03 +00:00
|
|
|
{
|
2003-07-24 09:47:46 +00:00
|
|
|
if (col < 0)
|
|
|
|
col = 0;
|
|
|
|
else
|
2006-05-11 20:34:37 +00:00
|
|
|
if (col > max_line_len - 2*glyph_width('o'))
|
|
|
|
col = max_line_len - 2*glyph_width('o');
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
return col;
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
|
|
|
|
2006-05-03 23:16:53 +00:00
|
|
|
/* settings helper functions */
|
2006-05-01 05:45:18 +00:00
|
|
|
|
2006-05-11 20:34:37 +00:00
|
|
|
static bool encoding_setting(void)
|
|
|
|
{
|
|
|
|
static const struct opt_items names[] = {
|
|
|
|
{"ISO-8859-1", -1},
|
|
|
|
{"ISO-8859-7", -1},
|
|
|
|
{"ISO-8859-8", -1},
|
|
|
|
{"CP1251", -1},
|
|
|
|
{"ISO-8859-11", -1},
|
|
|
|
{"ISO-8859-6", -1},
|
|
|
|
{"ISO-8859-9", -1},
|
|
|
|
{"ISO-8859-2", -1},
|
2007-10-01 17:16:31 +00:00
|
|
|
{"CP1250", -1},
|
2006-05-11 20:34:37 +00:00
|
|
|
{"SJIS", -1},
|
|
|
|
{"GB-2312", -1},
|
|
|
|
{"KSX-1001", -1},
|
|
|
|
{"BIG5", -1},
|
|
|
|
{"UTF-8", -1},
|
|
|
|
};
|
|
|
|
|
|
|
|
return rb->set_option("Encoding", &prefs.encoding, INT, names,
|
|
|
|
sizeof(names) / sizeof(names[0]), NULL);
|
|
|
|
}
|
|
|
|
|
2006-05-03 23:16:53 +00:00
|
|
|
static bool word_wrap_setting(void)
|
|
|
|
{
|
|
|
|
static const struct opt_items names[] = {
|
2006-05-05 17:49:27 +00:00
|
|
|
{"On", -1},
|
|
|
|
{"Off (Chop Words)", -1},
|
2006-05-01 05:45:18 +00:00
|
|
|
};
|
2006-05-03 23:16:53 +00:00
|
|
|
|
|
|
|
return rb->set_option("Word Wrap", &prefs.word_mode, INT,
|
|
|
|
names, 2, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool line_mode_setting(void)
|
|
|
|
{
|
|
|
|
static const struct opt_items names[] = {
|
2006-05-05 17:49:27 +00:00
|
|
|
{"Normal", -1},
|
|
|
|
{"Join Lines", -1},
|
|
|
|
{"Expand Lines", -1},
|
2006-05-01 05:45:18 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-05-05 17:49:27 +00:00
|
|
|
{"Reflow Lines", -1},
|
2006-05-01 05:45:18 +00:00
|
|
|
#endif
|
|
|
|
};
|
2006-05-03 23:16:53 +00:00
|
|
|
|
|
|
|
return rb->set_option("Line Mode", &prefs.line_mode, INT, names,
|
|
|
|
sizeof(names) / sizeof(names[0]), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool view_mode_setting(void)
|
|
|
|
{
|
|
|
|
static const struct opt_items names[] = {
|
2006-05-05 17:49:27 +00:00
|
|
|
{"No (Narrow)", -1},
|
|
|
|
{"Yes", -1},
|
2006-05-01 05:45:18 +00:00
|
|
|
};
|
2006-09-17 14:04:58 +00:00
|
|
|
bool ret;
|
|
|
|
ret = rb->set_option("Wide View", &prefs.view_mode, INT,
|
2006-05-03 23:16:53 +00:00
|
|
|
names , 2, NULL);
|
2006-09-17 14:04:58 +00:00
|
|
|
if (prefs.view_mode == NARROW)
|
|
|
|
col = 0;
|
|
|
|
return ret;
|
2006-05-03 23:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool scroll_mode_setting(void)
|
|
|
|
{
|
|
|
|
static const struct opt_items names[] = {
|
2006-05-05 17:49:27 +00:00
|
|
|
{"Scroll by Page", -1},
|
|
|
|
{"Scroll by Line", -1},
|
2006-05-01 05:45:18 +00:00
|
|
|
};
|
2006-05-03 23:16:53 +00:00
|
|
|
|
|
|
|
return rb->set_option("Scroll Mode", &prefs.scroll_mode, INT,
|
|
|
|
names, 2, NULL);
|
|
|
|
}
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-05-03 23:16:53 +00:00
|
|
|
static bool page_mode_setting(void)
|
|
|
|
{
|
|
|
|
static const struct opt_items names[] = {
|
2006-05-05 17:49:27 +00:00
|
|
|
{"No", -1},
|
|
|
|
{"Yes", -1},
|
2006-05-01 05:45:18 +00:00
|
|
|
};
|
2006-05-03 23:16:53 +00:00
|
|
|
|
|
|
|
return rb->set_option("Overlap Pages", &prefs.page_mode, INT,
|
|
|
|
names, 2, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool scrollbar_setting(void)
|
|
|
|
{
|
|
|
|
static const struct opt_items names[] = {
|
2006-05-05 17:49:27 +00:00
|
|
|
{"Off", -1},
|
|
|
|
{"On", -1}
|
2006-05-01 05:45:18 +00:00
|
|
|
};
|
2006-05-03 23:16:53 +00:00
|
|
|
|
|
|
|
return rb->set_option("Show Scrollbar", &prefs.scrollbar_mode, INT,
|
|
|
|
names, 2, NULL);
|
|
|
|
}
|
2006-05-01 05:45:18 +00:00
|
|
|
#endif
|
|
|
|
|
2006-05-03 23:16:53 +00:00
|
|
|
static bool autoscroll_speed_setting(void)
|
|
|
|
{
|
|
|
|
return rb->set_int("Auto-scroll Speed", "", UNIT_INT,
|
|
|
|
&prefs.autoscroll_speed, NULL, 1, 1, 10, NULL);
|
|
|
|
}
|
2006-04-04 12:04:15 +00:00
|
|
|
|
2006-05-03 23:16:53 +00:00
|
|
|
static bool viewer_options_menu(void)
|
|
|
|
{
|
|
|
|
int m;
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
static const struct menu_item items[] = {
|
2006-05-11 20:34:37 +00:00
|
|
|
{"Encoding", encoding_setting },
|
2006-05-03 23:16:53 +00:00
|
|
|
{"Word Wrap", word_wrap_setting },
|
|
|
|
{"Line Mode", line_mode_setting },
|
|
|
|
{"Wide View", view_mode_setting },
|
2006-05-01 05:45:18 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-05-03 23:16:53 +00:00
|
|
|
{"Show Scrollbar", scrollbar_setting },
|
|
|
|
{"Overlap Pages", page_mode_setting },
|
2006-05-01 05:45:18 +00:00
|
|
|
#endif
|
2006-05-03 23:16:53 +00:00
|
|
|
{"Scroll Mode", scroll_mode_setting},
|
|
|
|
{"Auto-Scroll Speed", autoscroll_speed_setting },
|
|
|
|
};
|
2007-05-08 11:55:43 +00:00
|
|
|
m = menu_init(rb, items, sizeof(items) / sizeof(*items),
|
2006-05-03 23:16:53 +00:00
|
|
|
NULL, NULL, NULL, NULL);
|
|
|
|
|
2007-05-08 11:55:43 +00:00
|
|
|
result = menu_run(m);
|
|
|
|
menu_exit(m);
|
2006-05-01 05:45:18 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-03-11 08:05:05 +00:00
|
|
|
rb->lcd_setmargins(0,0);
|
|
|
|
|
2006-05-03 23:16:53 +00:00
|
|
|
/* Show-scrollbar mode for current view-width mode */
|
|
|
|
if (!ONE_SCREEN_FITS_ALL())
|
|
|
|
if (prefs.scrollbar_mode == true)
|
|
|
|
init_need_scrollbar();
|
2006-05-01 05:45:18 +00:00
|
|
|
#endif
|
2006-05-03 23:16:53 +00:00
|
|
|
return result;
|
2006-05-01 05:45:18 +00:00
|
|
|
}
|
2006-04-04 12:04:15 +00:00
|
|
|
|
2006-05-03 23:16:53 +00:00
|
|
|
static void viewer_menu(void)
|
2006-05-01 05:45:18 +00:00
|
|
|
{
|
|
|
|
int m;
|
|
|
|
int result;
|
|
|
|
static const struct menu_item items[] = {
|
|
|
|
{"Quit", NULL },
|
|
|
|
{"Viewer Options", NULL },
|
|
|
|
{"Show Playback Menu", NULL },
|
|
|
|
{"Return", NULL },
|
|
|
|
};
|
|
|
|
|
2007-05-08 11:55:43 +00:00
|
|
|
m = menu_init(rb, items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL);
|
|
|
|
result=menu_show(m);
|
2006-05-01 05:45:18 +00:00
|
|
|
switch (result)
|
|
|
|
{
|
|
|
|
case 0: /* quit */
|
2007-05-08 11:55:43 +00:00
|
|
|
menu_exit(m);
|
2006-05-01 05:45:18 +00:00
|
|
|
viewer_exit(NULL);
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
case 1: /* change settings */
|
2006-05-03 23:16:53 +00:00
|
|
|
done = viewer_options_menu();
|
2006-05-01 05:45:18 +00:00
|
|
|
break;
|
|
|
|
case 2: /* playback control */
|
|
|
|
playback_control(rb);
|
|
|
|
break;
|
|
|
|
case 3: /* return */
|
|
|
|
break;
|
|
|
|
}
|
2007-05-08 11:55:43 +00:00
|
|
|
menu_exit(m);
|
2007-03-11 08:05:05 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
rb->lcd_setmargins(0,0);
|
|
|
|
#endif
|
2006-05-01 05:45:18 +00:00
|
|
|
viewer_draw(col);
|
|
|
|
}
|
2006-04-04 12:04:15 +00:00
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
enum plugin_status plugin_start(struct plugin_api* api, void* file)
|
2002-09-30 19:05:03 +00:00
|
|
|
{
|
2006-05-01 05:45:18 +00:00
|
|
|
int button, i, ok;
|
2006-05-03 23:16:53 +00:00
|
|
|
int lastbutton = BUTTON_NONE;
|
2006-05-01 05:45:18 +00:00
|
|
|
bool autoscroll = false;
|
2006-05-04 19:53:26 +00:00
|
|
|
long old_tick;
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
rb = api;
|
2006-05-04 19:53:26 +00:00
|
|
|
old_tick = *rb->current_tick;
|
2003-06-29 16:33:04 +00:00
|
|
|
|
|
|
|
if (!file)
|
|
|
|
return PLUGIN_ERROR;
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2005-05-17 13:14:09 +00:00
|
|
|
file_name = file;
|
|
|
|
ok = viewer_init();
|
2002-09-30 19:05:03 +00:00
|
|
|
if (!ok) {
|
2007-08-13 13:53:33 +00:00
|
|
|
rb->splash(HZ, "Error opening file.");
|
|
|
|
return PLUGIN_ERROR;
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
viewer_reset_settings(); /* load defaults first */
|
|
|
|
viewer_load_settings(); /* .. then try to load from disk */
|
2006-09-17 10:32:49 +00:00
|
|
|
|
2007-09-23 19:15:56 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_backdrop(NULL);
|
|
|
|
#endif
|
|
|
|
|
2002-09-30 19:05:03 +00:00
|
|
|
viewer_draw(col);
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
while (!done) {
|
2006-01-18 11:30:46 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
if(autoscroll)
|
|
|
|
{
|
|
|
|
if(old_tick <= *rb->current_tick - (110-prefs.autoscroll_speed*10))
|
|
|
|
{
|
|
|
|
viewer_scroll_down();
|
2003-07-24 09:47:46 +00:00
|
|
|
viewer_draw(col);
|
2006-05-01 05:45:18 +00:00
|
|
|
old_tick = *rb->current_tick;
|
|
|
|
}
|
|
|
|
}
|
2006-09-17 10:32:49 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
button = rb->button_get_w_tmo(HZ/10);
|
|
|
|
switch (button) {
|
|
|
|
case VIEWER_MENU:
|
2006-05-03 23:16:53 +00:00
|
|
|
viewer_menu();
|
2003-07-24 09:47:46 +00:00
|
|
|
break;
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
case VIEWER_AUTOSCROLL:
|
2006-05-03 23:16:53 +00:00
|
|
|
#ifdef VIEWER_AUTOSCROLL_PRE
|
|
|
|
if (lastbutton != VIEWER_AUTOSCROLL_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2006-05-01 05:45:18 +00:00
|
|
|
autoscroll = !autoscroll;
|
2003-07-24 09:47:46 +00:00
|
|
|
break;
|
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
case VIEWER_PAGE_UP:
|
|
|
|
case VIEWER_PAGE_UP | BUTTON_REPEAT:
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.scroll_mode == PAGE)
|
|
|
|
{
|
|
|
|
/* Page up */
|
2003-07-24 09:47:46 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-05-01 05:45:18 +00:00
|
|
|
for (i = prefs.page_mode==OVERLAP? 1:0; i < display_lines; i++)
|
2003-07-24 09:47:46 +00:00
|
|
|
#else
|
2006-05-01 05:45:18 +00:00
|
|
|
for (i = 0; i < display_lines; i++)
|
2003-07-24 09:47:46 +00:00
|
|
|
#endif
|
2006-05-01 05:45:18 +00:00
|
|
|
viewer_scroll_up();
|
|
|
|
}
|
|
|
|
else
|
2003-07-24 09:47:46 +00:00
|
|
|
viewer_scroll_up();
|
2006-05-01 05:45:18 +00:00
|
|
|
old_tick = *rb->current_tick;
|
2002-09-30 19:05:03 +00:00
|
|
|
viewer_draw(col);
|
|
|
|
break;
|
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
case VIEWER_PAGE_DOWN:
|
|
|
|
case VIEWER_PAGE_DOWN | BUTTON_REPEAT:
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.scroll_mode == PAGE)
|
|
|
|
{
|
|
|
|
/* Page down */
|
|
|
|
if (next_screen_ptr != NULL)
|
|
|
|
screen_top_ptr = next_screen_to_draw_ptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
viewer_scroll_down();
|
|
|
|
old_tick = *rb->current_tick;
|
2002-09-30 19:05:03 +00:00
|
|
|
viewer_draw(col);
|
|
|
|
break;
|
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
case VIEWER_SCREEN_LEFT:
|
|
|
|
case VIEWER_SCREEN_LEFT | BUTTON_REPEAT:
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.view_mode == WIDE) {
|
2003-07-24 09:47:46 +00:00
|
|
|
/* Screen left */
|
2006-05-11 20:34:37 +00:00
|
|
|
col -= draw_columns;
|
2003-07-24 09:47:46 +00:00
|
|
|
col = col_limit(col);
|
|
|
|
}
|
2006-05-01 05:45:18 +00:00
|
|
|
else { /* prefs.view_mode == NARROW */
|
2003-07-24 09:47:46 +00:00
|
|
|
/* Top of file */
|
|
|
|
viewer_top();
|
|
|
|
}
|
|
|
|
|
2002-09-30 19:05:03 +00:00
|
|
|
viewer_draw(col);
|
|
|
|
break;
|
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
case VIEWER_SCREEN_RIGHT:
|
|
|
|
case VIEWER_SCREEN_RIGHT | BUTTON_REPEAT:
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.view_mode == WIDE) {
|
2003-07-24 09:47:46 +00:00
|
|
|
/* Screen right */
|
2006-05-11 20:34:37 +00:00
|
|
|
col += draw_columns;
|
2003-07-24 09:47:46 +00:00
|
|
|
col = col_limit(col);
|
|
|
|
}
|
2006-05-01 05:45:18 +00:00
|
|
|
else { /* prefs.view_mode == NARROW */
|
2003-07-24 09:47:46 +00:00
|
|
|
/* Bottom of file */
|
|
|
|
viewer_bottom();
|
|
|
|
}
|
|
|
|
|
2002-09-30 19:05:03 +00:00
|
|
|
viewer_draw(col);
|
|
|
|
break;
|
2004-10-16 00:07:43 +00:00
|
|
|
|
2006-01-27 13:30:57 +00:00
|
|
|
#ifdef VIEWER_LINE_UP
|
2004-10-16 00:07:43 +00:00
|
|
|
case VIEWER_LINE_UP:
|
|
|
|
case VIEWER_LINE_UP | BUTTON_REPEAT:
|
|
|
|
/* Scroll up one line */
|
|
|
|
viewer_scroll_up();
|
2006-05-01 05:45:18 +00:00
|
|
|
old_tick = *rb->current_tick;
|
2004-10-16 00:07:43 +00:00
|
|
|
viewer_draw(col);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_LINE_DOWN:
|
|
|
|
case VIEWER_LINE_DOWN | BUTTON_REPEAT:
|
|
|
|
/* Scroll down one line */
|
|
|
|
if (next_screen_ptr != NULL)
|
|
|
|
screen_top_ptr = next_line_ptr;
|
2006-05-01 05:45:18 +00:00
|
|
|
old_tick = *rb->current_tick;
|
2004-10-16 00:07:43 +00:00
|
|
|
viewer_draw(col);
|
|
|
|
break;
|
2006-01-27 13:30:57 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VIEWER_COLUMN_LEFT
|
2004-10-16 00:07:43 +00:00
|
|
|
case VIEWER_COLUMN_LEFT:
|
|
|
|
case VIEWER_COLUMN_LEFT | BUTTON_REPEAT:
|
2006-07-25 20:49:53 +00:00
|
|
|
if (prefs.view_mode == WIDE) {
|
|
|
|
/* Scroll left one column */
|
|
|
|
col -= glyph_width('o');
|
|
|
|
col = col_limit(col);
|
|
|
|
viewer_draw(col);
|
|
|
|
}
|
2004-10-16 00:07:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_COLUMN_RIGHT:
|
|
|
|
case VIEWER_COLUMN_RIGHT | BUTTON_REPEAT:
|
2006-07-25 20:49:53 +00:00
|
|
|
if (prefs.view_mode == WIDE) {
|
|
|
|
/* Scroll right one column */
|
|
|
|
col += glyph_width('o');
|
|
|
|
col = col_limit(col);
|
|
|
|
viewer_draw(col);
|
|
|
|
}
|
2002-10-02 11:37:37 +00:00
|
|
|
break;
|
2003-07-24 09:47:46 +00:00
|
|
|
#endif
|
2006-05-01 06:01:17 +00:00
|
|
|
|
2006-06-30 16:43:47 +00:00
|
|
|
#ifdef VIEWER_RC_QUIT
|
|
|
|
case VIEWER_RC_QUIT:
|
|
|
|
#endif
|
2006-05-01 05:45:18 +00:00
|
|
|
case VIEWER_QUIT:
|
|
|
|
viewer_exit(NULL);
|
|
|
|
done = true;
|
|
|
|
break;
|
2002-10-02 11:37:37 +00:00
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
default:
|
|
|
|
if (rb->default_event_handler_ex(button, viewer_exit, NULL)
|
|
|
|
== SYS_USB_CONNECTED)
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
break;
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
2006-05-03 23:16:53 +00:00
|
|
|
if (button != BUTTON_NONE)
|
2006-09-17 14:37:59 +00:00
|
|
|
{
|
2006-05-03 23:16:53 +00:00
|
|
|
lastbutton = button;
|
2006-09-17 14:37:59 +00:00
|
|
|
rb->yield();
|
|
|
|
}
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
2003-06-29 16:33:04 +00:00
|
|
|
return PLUGIN_OK;
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
2006-04-04 12:04:15 +00:00
|
|
|
|