2002-09-30 19:05:03 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2009-12-18 14:17:28 +00:00
|
|
|
* $Id$
|
2003-07-24 09:47:46 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Gilles Roux, 2003 Garrett Derner
|
2002-09-30 19:05:03 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-09-30 19:05:03 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2008-11-20 11:27:31 +00:00
|
|
|
#include "lib/playback_control.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
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
/* global settings file
|
|
|
|
* binary file, so dont use .cfg
|
|
|
|
*
|
|
|
|
* setting file format
|
|
|
|
*
|
|
|
|
* part byte count
|
|
|
|
* --------------------------------
|
|
|
|
* 'TVGS' 4
|
|
|
|
* version 1
|
|
|
|
* word_mode 1
|
|
|
|
* line_mode 1
|
|
|
|
* view_mode 1
|
2010-03-30 17:09:04 +00:00
|
|
|
* alignment 1
|
2010-03-17 11:17:56 +00:00
|
|
|
* encoding 1
|
|
|
|
* scrollbar_mode 1
|
|
|
|
* need_scrollbar 1
|
|
|
|
* page_mode 1
|
|
|
|
* page_number_mode 1
|
|
|
|
* title_mode 1
|
|
|
|
* scroll_mode 1
|
|
|
|
* autoscroll_speed 1
|
|
|
|
* font name MAX_PATH
|
|
|
|
*/
|
|
|
|
#define GLOBAL_SETTINGS_FILE VIEWERS_DIR "/viewer.dat"
|
|
|
|
|
|
|
|
/* temporary file */
|
|
|
|
#define GLOBAL_SETTINGS_TMP_FILE VIEWERS_DIR "/viewer_file.tmp"
|
|
|
|
|
2010-04-10 08:58:37 +00:00
|
|
|
#define GLOBAL_SETTINGS_HEADER "\x54\x56\x47\x53" /* header="TVGS" */
|
2010-03-17 11:17:56 +00:00
|
|
|
#define GLOBAL_SETTINGS_H_SIZE 5
|
2010-04-10 08:58:37 +00:00
|
|
|
#define GLOBAL_SETTINGS_VERSION 0x32 /* version=2 */
|
|
|
|
#define GLOBAL_SETTINGS_FIRST_VERSION 0x31
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
/* preferences and bookmarks at each file
|
|
|
|
* binary file, so dont use .cfg
|
|
|
|
*
|
|
|
|
* setting file format
|
|
|
|
*
|
|
|
|
* part byte count
|
|
|
|
* --------------------------------
|
|
|
|
* 'TVS' 3
|
|
|
|
* version 1
|
|
|
|
* file count 2
|
|
|
|
* [1st file]
|
|
|
|
* file path MAX_PATH
|
|
|
|
* next file pos 2
|
|
|
|
* [preferences]
|
|
|
|
* word_mode 1
|
|
|
|
* line_mode 1
|
|
|
|
* view_mode 1
|
2010-03-30 17:09:04 +00:00
|
|
|
* alignment 1
|
2010-03-17 11:17:56 +00:00
|
|
|
* encoding 1
|
|
|
|
* scrollbar_mode 1
|
|
|
|
* need_scrollbar 1
|
|
|
|
* page_mode 1
|
|
|
|
* header_mode 1
|
|
|
|
* footer_mode 1
|
|
|
|
* scroll_mode 1
|
|
|
|
* autoscroll_speed 1
|
|
|
|
* font name MAX_PATH
|
|
|
|
* bookmark count 1
|
|
|
|
* [1st bookmark]
|
|
|
|
* file_position 4
|
|
|
|
* page 2
|
|
|
|
* line 1
|
|
|
|
* flag 1
|
|
|
|
* [2nd bookmark]
|
|
|
|
* ...
|
|
|
|
* [last bookmark]
|
|
|
|
* [2nd file]
|
|
|
|
* ...
|
|
|
|
* [last file]
|
|
|
|
*/
|
|
|
|
#define SETTINGS_FILE VIEWERS_DIR "/viewer_file.dat"
|
|
|
|
|
|
|
|
/* temporary file */
|
|
|
|
#define SETTINGS_TMP_FILE VIEWERS_DIR "/viewer_file.tmp"
|
|
|
|
|
2010-04-10 08:58:37 +00:00
|
|
|
#define SETTINGS_HEADER "\x54\x56\x53" /* header="TVS" */
|
|
|
|
#define SETTINGS_H_SIZE 4
|
|
|
|
#define SETTINGS_VERSION 0x33 /* version=3 */
|
|
|
|
#define SETTINGS_FIRST_VERSION 0x32
|
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) */
|
2010-03-17 11:17:56 +00:00
|
|
|
#define NARROW_MAX_COLUMNS 64 /* Max displayable string len [narrow] (over-estimate) */
|
|
|
|
#define WIDE_MAX_COLUMNS 128 /* Max displayable string len [wide] (over-estimate) */
|
2003-07-24 09:47:46 +00:00
|
|
|
#define MAX_WIDTH 910 /* Max line length in WIDE mode */
|
2010-03-17 11:17:56 +00:00
|
|
|
#define READ_PREV_ZONE (block_size*9/10) /* Arbitrary number less than SMALL_BLOCK_SIZE */
|
|
|
|
#define SMALL_BLOCK_SIZE block_size /* Smallest file chunk we will read */
|
|
|
|
#define LARGE_BLOCK_SIZE (block_size << 1) /* Preferable size of file chunk to read */
|
2003-07-24 09:47:46 +00:00
|
|
|
#define TOP_SECTOR buffer
|
|
|
|
#define MID_SECTOR (buffer + SMALL_BLOCK_SIZE)
|
2010-03-17 11:17:56 +00:00
|
|
|
#define BOTTOM_SECTOR (buffer + (SMALL_BLOCK_SIZE << 1))
|
2009-08-17 23:05:45 +00:00
|
|
|
#undef SCROLLBAR_WIDTH
|
|
|
|
#define SCROLLBAR_WIDTH rb->global_settings->scrollbar_width
|
2010-03-17 11:17:56 +00:00
|
|
|
#define MAX_PAGE 9999
|
|
|
|
|
|
|
|
#define BOOKMARK_SIZE 8
|
|
|
|
#define MAX_BOOKMARKS 10 /* user setting bookmarks + last read page */
|
|
|
|
|
|
|
|
#define BOOKMARK_LAST 1
|
|
|
|
#define BOOKMARK_USER 2
|
|
|
|
|
|
|
|
#ifndef HAVE_LCD_BITMAP
|
|
|
|
#define BOOKMARK_ICON "\xee\x84\x81\x00"
|
|
|
|
#endif
|
2003-07-24 09:47:46 +00:00
|
|
|
|
2010-04-10 08:58:37 +00:00
|
|
|
#define PREFERENCES_SIZE (12 + MAX_PATH)
|
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? */
|
2007-11-23 09:11:11 +00:00
|
|
|
#define BUFFER_EOF() (file_size-file_pos <= buffer_size)
|
2003-07-24 09:47:46 +00:00
|
|
|
|
|
|
|
/* Formula for the endpoint address outside of buffer data */
|
|
|
|
#define BUFFER_END() \
|
2007-11-23 09:11:11 +00:00
|
|
|
((BUFFER_EOF()) ? (file_size-file_pos+buffer) : (buffer+buffer_size))
|
2003-07-24 09:47:46 +00:00
|
|
|
|
|
|
|
/* 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)
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_F2
|
2007-01-14 13:48:09 +00:00
|
|
|
|
|
|
|
#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)
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_F2
|
2004-10-16 00:07:43 +00:00
|
|
|
|
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)
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK (BUTTON_MENU|BUTTON_OFF)
|
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
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_ON
|
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)
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK (BUTTON_ON | BUTTON_SELECT)
|
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
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_SELECT
|
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
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK (BUTTON_LEFT|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
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_REC
|
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
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_SELECT
|
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
|
2008-01-17 11:29:14 +00:00
|
|
|
#define VIEWER_LINE_UP BUTTON_SCROLL_BACK
|
|
|
|
#define VIEWER_LINE_DOWN BUTTON_SCROLL_FWD
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK (BUTTON_DOWN|BUTTON_SELECT)
|
2006-10-26 13:38:09 +00:00
|
|
|
|
2009-01-04 23:33:15 +00:00
|
|
|
/* Sansa Fuze keys */
|
|
|
|
#elif CONFIG_KEYPAD == SANSA_FUZE_PAD
|
2009-04-10 17:28:26 +00:00
|
|
|
#define VIEWER_QUIT (BUTTON_HOME|BUTTON_REPEAT)
|
2009-01-04 23:33:15 +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
|
|
|
|
#define VIEWER_MENU BUTTON_SELECT|BUTTON_REPEAT
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_SELECT|BUTTON_DOWN
|
|
|
|
#define VIEWER_LINE_UP BUTTON_SCROLL_BACK
|
|
|
|
#define VIEWER_LINE_DOWN BUTTON_SCROLL_FWD
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_SELECT
|
2009-01-04 23:33:15 +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
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK (BUTTON_DOWN | BUTTON_SELECT)
|
2007-09-20 10:49:48 +00:00
|
|
|
|
2008-11-28 00:37:28 +00:00
|
|
|
/* Sansa Clip keys */
|
|
|
|
#elif CONFIG_KEYPAD == SANSA_CLIP_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_HOME
|
|
|
|
#define VIEWER_LINE_UP BUTTON_UP
|
|
|
|
#define VIEWER_LINE_DOWN BUTTON_DOWN
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK (BUTTON_DOWN|BUTTON_SELECT)
|
2008-11-28 00:37:28 +00:00
|
|
|
|
2008-12-12 19:50:49 +00:00
|
|
|
/* Sansa M200 keys */
|
|
|
|
#elif CONFIG_KEYPAD == SANSA_M200_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 | BUTTON_UP)
|
|
|
|
#define VIEWER_AUTOSCROLL (BUTTON_SELECT | BUTTON_REL)
|
|
|
|
#define VIEWER_LINE_UP BUTTON_UP
|
|
|
|
#define VIEWER_LINE_DOWN BUTTON_DOWN
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK (BUTTON_DOWN|BUTTON_SELECT)
|
2008-12-12 19:50:49 +00:00
|
|
|
|
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
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_FF
|
2006-08-03 20:17:25 +00:00
|
|
|
|
2008-05-18 14:09:33 +00:00
|
|
|
/*M-Robe 500 keys */
|
2007-10-23 15:40:51 +00:00
|
|
|
#elif CONFIG_KEYPAD == MROBE500_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_POWER
|
|
|
|
#define VIEWER_PAGE_UP BUTTON_RC_PLAY
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_RC_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
|
|
|
#define VIEWER_MENU BUTTON_RC_HEART
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_RC_MODE
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_CENTER
|
2007-10-23 15:40:51 +00:00
|
|
|
|
2008-05-18 14:09:33 +00:00
|
|
|
/*Gigabeat S keys */
|
2008-02-17 12:23:02 +00:00
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_S_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_BACK
|
2008-05-18 14:09:33 +00:00
|
|
|
#define VIEWER_PAGE_UP BUTTON_PREV
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_NEXT
|
|
|
|
#define VIEWER_SCREEN_LEFT (BUTTON_PLAY | BUTTON_LEFT)
|
|
|
|
#define VIEWER_SCREEN_RIGHT (BUTTON_PLAY | BUTTON_RIGHT)
|
2008-02-17 12:23:02 +00:00
|
|
|
#define VIEWER_MENU BUTTON_MENU
|
2008-05-18 14:09:33 +00:00
|
|
|
#define VIEWER_AUTOSCROLL_PRE BUTTON_PLAY
|
|
|
|
#define VIEWER_AUTOSCROLL (BUTTON_PLAY|BUTTON_REL)
|
|
|
|
#define VIEWER_LINE_UP BUTTON_UP
|
|
|
|
#define VIEWER_LINE_DOWN BUTTON_DOWN
|
|
|
|
#define VIEWER_COLUMN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_COLUMN_RIGHT BUTTON_RIGHT
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_SELECT
|
2008-02-17 12:23:02 +00:00
|
|
|
|
2008-05-18 14:09:33 +00:00
|
|
|
/*M-Robe 100 keys */
|
2008-03-01 22:55:09 +00:00
|
|
|
#elif CONFIG_KEYPAD == MROBE100_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_MENU
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_DISPLAY
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_SELECT
|
2008-03-01 22:55:09 +00:00
|
|
|
|
2008-03-22 10:24:28 +00:00
|
|
|
/* iAUdio M3 keys */
|
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_QUIT BUTTON_REC
|
2008-03-22 10:24:28 +00:00
|
|
|
#define VIEWER_PAGE_UP BUTTON_RC_VOL_UP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_RC_VOL_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_RC_REW
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RC_FF
|
|
|
|
#define VIEWER_MENU BUTTON_RC_MENU
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_RC_MODE
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_RC_QUIT BUTTON_RC_REC
|
|
|
|
#define VIEWER_BOOKMARK BUTTON_RC_PLAY
|
2008-03-22 10:24:28 +00:00
|
|
|
|
2008-05-18 14:09:33 +00:00
|
|
|
/* Cowon D2 keys */
|
2009-12-15 20:51:41 +00:00
|
|
|
#elif CONFIG_KEYPAD == COWON_D2_PAD
|
2008-03-22 22:03:34 +00:00
|
|
|
#define VIEWER_QUIT BUTTON_POWER
|
|
|
|
#define VIEWER_MENU BUTTON_MENU
|
2010-02-24 21:38:15 +00:00
|
|
|
#define VIEWER_PAGE_UP BUTTON_MINUS
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_PLUS
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK (BUTTON_MENU|BUTTON_PLUS)
|
2008-03-22 22:03:34 +00:00
|
|
|
|
2008-10-07 16:38:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO67_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_POWER
|
|
|
|
#define VIEWER_PAGE_UP BUTTON_VOLUP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_VOLDOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
|
|
|
#define VIEWER_MENU BUTTON_MENU
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_PLAY
|
|
|
|
#define VIEWER_RC_QUIT BUTTON_STOP
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK (BUTTON_LEFT|BUTTON_PLAY)
|
2008-10-07 16:38:28 +00:00
|
|
|
|
2008-12-04 21:28:56 +00:00
|
|
|
/* Creative Zen Vision:M keys */
|
|
|
|
#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_BACK
|
|
|
|
#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_MENU
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_SELECT
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_PLAY
|
2008-12-04 21:28:56 +00:00
|
|
|
|
2009-01-24 22:41:55 +00:00
|
|
|
/* Philips HDD1630 keys */
|
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_HDD1630_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_MENU
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_VIEW
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_SELECT
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2009-12-03 23:13:45 +00:00
|
|
|
/* Philips SA9200 keys */
|
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_POWER
|
|
|
|
#define VIEWER_PAGE_UP BUTTON_UP
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_PREV
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_NEXT
|
|
|
|
#define VIEWER_MENU BUTTON_MENU
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_PLAY
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_RIGHT
|
2009-12-03 23:13:45 +00:00
|
|
|
|
2009-04-07 23:41:44 +00:00
|
|
|
/* Onda VX747 keys */
|
|
|
|
#elif CONFIG_KEYPAD == ONDAVX747_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_POWER
|
|
|
|
#define VIEWER_MENU BUTTON_MENU
|
2010-03-17 11:42:35 +00:00
|
|
|
#define VIEWER_BOOKMARK (BUTTON_RIGHT|BUTTON_POWER)
|
2009-04-07 23:41:44 +00:00
|
|
|
|
2009-08-31 21:11:32 +00:00
|
|
|
/* Onda VX777 keys */
|
|
|
|
#elif CONFIG_KEYPAD == ONDAVX777_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_POWER
|
2010-03-17 11:42:35 +00:00
|
|
|
#define VIEWER_BOOKMARK (BUTTON_RIGHT|BUTTON_POWER)
|
2009-08-31 21:11:32 +00:00
|
|
|
|
2009-08-04 03:08:32 +00:00
|
|
|
/* SAMSUNG YH-820 / YH-920 / YH-925 keys */
|
|
|
|
#elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_REC
|
|
|
|
#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_PLAY
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_REW
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_FFWD
|
2009-08-04 03:08:32 +00:00
|
|
|
|
2010-02-11 22:40:17 +00:00
|
|
|
/* Packard Bell Vibe 500 keys */
|
|
|
|
#elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
|
|
|
|
#define VIEWER_QUIT BUTTON_REC
|
|
|
|
#define VIEWER_PAGE_UP BUTTON_OK
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_CANCEL
|
|
|
|
#define VIEWER_LINE_UP BUTTON_UP
|
|
|
|
#define VIEWER_LINE_DOWN BUTTON_DOWN
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_PREV
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_NEXT
|
|
|
|
#define VIEWER_MENU BUTTON_MENU
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_PLAY
|
2010-03-17 11:17:56 +00:00
|
|
|
#define VIEWER_BOOKMARK BUTTON_POWER
|
2010-02-11 22:40:17 +00:00
|
|
|
|
2010-04-26 21:40:00 +00:00
|
|
|
#elif CONFIG_KEYPAD == MPIO_HD200_PAD
|
|
|
|
#define VIEWER_QUIT (BUTTON_REC | BUTTON_PLAY)
|
|
|
|
#define VIEWER_PAGE_UP BUTTON_PREV
|
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_NEXT
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_VOL_DOWN
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_VOL_UP
|
|
|
|
#define VIEWER_MENU BUTTON_SELECT
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_PLAY
|
|
|
|
#define VIEWER_BOOKMARK BUTTON_REC
|
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#else
|
|
|
|
#error No keymap defined!
|
2004-10-16 00:07:43 +00:00
|
|
|
#endif
|
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2010-02-24 21:38:15 +00:00
|
|
|
#ifdef VIEWER_QUIT
|
|
|
|
#define VIEWER_QUIT2 BUTTON_TOPLEFT
|
|
|
|
#else
|
2008-04-27 15:30:19 +00:00
|
|
|
#define VIEWER_QUIT BUTTON_TOPLEFT
|
|
|
|
#endif
|
2010-02-24 21:38:15 +00:00
|
|
|
#ifdef VIEWER_PAGE_UP
|
|
|
|
#define VIEWER_PAGE_UP2 BUTTON_TOPMIDDLE
|
|
|
|
#else
|
2008-04-27 15:30:19 +00:00
|
|
|
#define VIEWER_PAGE_UP BUTTON_TOPMIDDLE
|
|
|
|
#endif
|
2010-02-24 21:38:15 +00:00
|
|
|
#ifdef VIEWER_PAGE_DOWN
|
|
|
|
#define VIEWER_PAGE_DOWN2 BUTTON_BOTTOMMIDDLE
|
|
|
|
#else
|
2008-04-27 15:30:19 +00:00
|
|
|
#define VIEWER_PAGE_DOWN BUTTON_BOTTOMMIDDLE
|
|
|
|
#endif
|
|
|
|
#ifndef VIEWER_SCREEN_LEFT
|
|
|
|
#define VIEWER_SCREEN_LEFT BUTTON_MIDLEFT
|
|
|
|
#endif
|
|
|
|
#ifndef VIEWER_SCREEN_RIGHT
|
|
|
|
#define VIEWER_SCREEN_RIGHT BUTTON_MIDRIGHT
|
|
|
|
#endif
|
2010-02-24 21:38:15 +00:00
|
|
|
#ifdef VIEWER_MENU
|
|
|
|
#define VIEWER_MENU2 BUTTON_TOPRIGHT
|
|
|
|
#else
|
2008-04-27 15:30:19 +00:00
|
|
|
#define VIEWER_MENU BUTTON_TOPRIGHT
|
|
|
|
#endif
|
|
|
|
#ifndef VIEWER_AUTOSCROLL
|
|
|
|
#define VIEWER_AUTOSCROLL BUTTON_CENTER
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2006-09-18 15:31:51 +00:00
|
|
|
/* stuff for the bookmarking */
|
2010-03-17 11:17:56 +00:00
|
|
|
struct bookmark_info {
|
2006-09-17 10:32:49 +00:00
|
|
|
long file_position;
|
2010-03-17 11:17:56 +00:00
|
|
|
int page;
|
|
|
|
int line;
|
|
|
|
unsigned char flag;
|
2006-09-18 15:31:51 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2010-03-30 17:09:04 +00:00
|
|
|
enum {
|
|
|
|
LEFT=0,
|
|
|
|
RIGHT,
|
|
|
|
} alignment;
|
|
|
|
|
2008-12-04 22:00:12 +00:00
|
|
|
enum codepages encoding;
|
2006-05-11 20:34:37 +00:00
|
|
|
|
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;
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
HD_NONE = 0,
|
|
|
|
HD_PATH,
|
|
|
|
HD_SBAR,
|
|
|
|
HD_BOTH,
|
|
|
|
} header_mode;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FT_NONE = 0,
|
|
|
|
FT_PAGE,
|
|
|
|
FT_SBAR,
|
|
|
|
FT_BOTH,
|
|
|
|
} footer_mode;
|
2006-05-01 05:45:18 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
PAGE=0,
|
|
|
|
LINE,
|
|
|
|
} scroll_mode;
|
|
|
|
|
|
|
|
int autoscroll_speed;
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
unsigned char font[MAX_PATH];
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
VIEWER_FONT_MENU = 0,
|
|
|
|
VIEWER_FONT_TEXT,
|
2007-11-19 20:51:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct preferences prefs;
|
|
|
|
struct preferences old_prefs;
|
2006-01-27 13:30:57 +00:00
|
|
|
|
2007-11-23 09:11:11 +00:00
|
|
|
static unsigned char *buffer;
|
|
|
|
static long buffer_size;
|
2010-03-17 11:17:56 +00:00
|
|
|
static long block_size = 0x1000;
|
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;
|
2008-05-13 09:57:56 +00:00
|
|
|
static const char *file_name;
|
2003-07-24 09:47:46 +00:00
|
|
|
static long file_size;
|
2007-11-19 16:02:45 +00:00
|
|
|
static long start_position; /* position in the file after the viewer is started */
|
2003-07-24 09:47:46 +00:00
|
|
|
static bool mac_text;
|
|
|
|
static long file_pos; /* Position of the top of the buffer in the file */
|
2010-03-17 11:17:56 +00:00
|
|
|
static long last_file_pos;
|
2003-07-24 09:47:46 +00:00
|
|
|
static unsigned char *buffer_end; /*Set to BUFFER_END() when file_pos changes*/
|
2010-03-17 11:17:56 +00:00
|
|
|
static int max_width;
|
|
|
|
static int max_columns;
|
|
|
|
static int cline = 1;
|
|
|
|
static int cpage = 1;
|
|
|
|
static int lpage = 0;
|
2003-07-24 09:47:46 +00:00
|
|
|
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;
|
2010-03-17 11:17:56 +00:00
|
|
|
static unsigned char *last_screen_top_ptr = NULL;
|
2006-05-11 20:34:37 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static struct font *pf;
|
2010-03-17 11:17:56 +00:00
|
|
|
static int header_height = 0;
|
|
|
|
static int footer_height = 0;
|
2006-05-11 20:34:37 +00:00
|
|
|
#endif
|
2010-03-17 11:17:56 +00:00
|
|
|
struct bookmark_info bookmarks[MAX_BOOKMARKS];
|
|
|
|
static int bookmark_count;
|
2006-05-11 20:34:37 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
/* UTF-8 BOM */
|
|
|
|
#define BOM "\xef\xbb\xbf"
|
|
|
|
#define BOM_SIZE 3
|
2006-09-17 10:32:49 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
static bool is_bom = false;
|
|
|
|
|
2010-04-12 12:02:05 +00:00
|
|
|
/* We draw a diacritic char over a non-diacritic one. Therefore, such chars are
|
|
|
|
* not considered to occupy space, therefore buffers might have more than
|
|
|
|
* max_columns characters. The DIACRITIC_FACTOR is the max ratio between all
|
|
|
|
* characters and non-diacritic characters in the buffer
|
|
|
|
*/
|
|
|
|
#define DIACRITIC_FACTOR 2
|
|
|
|
|
2010-04-07 17:04:30 +00:00
|
|
|
/* calculate the width of a UCS character (zero width for diacritics) */
|
2010-04-07 17:22:16 +00:00
|
|
|
static int glyph_width(unsigned short ch)
|
2006-05-11 20:34:37 +00:00
|
|
|
{
|
|
|
|
if (ch == 0)
|
|
|
|
ch = ' ';
|
|
|
|
|
2010-04-07 17:27:19 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-04-07 17:22:16 +00:00
|
|
|
if (rb->is_diacritic(ch, NULL))
|
|
|
|
return 0;
|
|
|
|
|
2006-05-11 20:34:37 +00:00
|
|
|
return rb->font_get_width(pf, ch);
|
|
|
|
#else
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-04-07 17:04:30 +00:00
|
|
|
/* get UCS character from string */
|
2010-03-17 11:17:56 +00:00
|
|
|
static unsigned char* get_ucs(const unsigned char* str, unsigned short* ch)
|
2006-05-11 20:34:37 +00:00
|
|
|
{
|
|
|
|
unsigned char utf8_tmp[6];
|
2010-04-12 12:02:05 +00:00
|
|
|
int count = 2;
|
2006-05-11 20:34:37 +00:00
|
|
|
|
2008-12-04 22:00:12 +00:00
|
|
|
if (prefs.encoding == UTF_8)
|
2006-05-11 20:34:37 +00:00
|
|
|
return (unsigned char*)rb->utf8decode(str, ch);
|
|
|
|
|
|
|
|
rb->iso_decode(str, utf8_tmp, prefs.encoding, count);
|
|
|
|
rb->utf8decode(utf8_tmp, ch);
|
2003-07-24 09:47:46 +00:00
|
|
|
|
2010-04-07 17:04:30 +00:00
|
|
|
/* return a pointer after the parsed section of the string */
|
2008-12-04 22:00:12 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2009-07-10 14:06:34 +00:00
|
|
|
if (prefs.encoding >= SJIS && *str >= 0x80
|
|
|
|
&& !(prefs.encoding == SJIS && *str > 0xA0 && *str < 0xE0))
|
|
|
|
return (unsigned char*)str+2;
|
2006-05-11 20:34:37 +00:00
|
|
|
else
|
2008-12-04 22:00:12 +00:00
|
|
|
#endif
|
2009-07-10 14:06:34 +00:00
|
|
|
return (unsigned char*)str+1;
|
2006-05-11 20:34:37 +00:00
|
|
|
}
|
2005-05-13 13:32:57 +00:00
|
|
|
|
2010-04-12 12:02:05 +00:00
|
|
|
/* decode iso string into UTF-8 string */
|
2010-03-17 11:17:56 +00:00
|
|
|
static unsigned char *decode2utf8(const unsigned char *src, unsigned char *dst,
|
|
|
|
int skip_width, int disp_width)
|
|
|
|
{
|
2010-04-12 12:02:05 +00:00
|
|
|
unsigned short ucs[max_columns * DIACRITIC_FACTOR + 1];
|
2010-03-17 11:17:56 +00:00
|
|
|
unsigned short ch;
|
2010-04-12 12:15:35 +00:00
|
|
|
const unsigned char *oldstr = src;
|
2010-03-17 11:17:56 +00:00
|
|
|
const unsigned char *str = src;
|
|
|
|
unsigned char *utf8 = dst;
|
2010-04-12 12:02:05 +00:00
|
|
|
int chars = 0;
|
|
|
|
int idx = 0;
|
|
|
|
int width = max_width;
|
2010-03-17 11:17:56 +00:00
|
|
|
|
2010-04-12 12:02:05 +00:00
|
|
|
if (prefs.alignment == LEFT)
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
2010-04-12 12:02:05 +00:00
|
|
|
/* skip the skip_width */
|
|
|
|
if (skip_width > 0)
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
2010-04-12 12:02:05 +00:00
|
|
|
while (skip_width > 0 && *str != '\0')
|
|
|
|
{
|
|
|
|
oldstr = str;
|
|
|
|
str = get_ucs(oldstr, &ch);
|
|
|
|
skip_width -= glyph_width(ch);
|
|
|
|
}
|
|
|
|
if (skip_width < 0)
|
|
|
|
str = oldstr;
|
2010-03-17 11:17:56 +00:00
|
|
|
}
|
2010-04-07 17:04:30 +00:00
|
|
|
|
2010-04-12 12:02:05 +00:00
|
|
|
/* decode until string end or disp_width reached */
|
|
|
|
while(*str != '\0')
|
|
|
|
{
|
|
|
|
str = get_ucs(str, &ch);
|
|
|
|
disp_width -= glyph_width(ch);
|
|
|
|
if (disp_width < 0)
|
|
|
|
break;
|
|
|
|
utf8 = rb->utf8encode(ch, utf8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
2010-04-12 12:02:05 +00:00
|
|
|
while (width > 0 && *str != '\0')
|
|
|
|
{
|
|
|
|
str = get_ucs(str, &ch);
|
|
|
|
ucs[chars++] = ch;
|
|
|
|
}
|
|
|
|
ucs[chars] = 0;
|
|
|
|
|
|
|
|
skip_width = max_width - skip_width - disp_width;
|
|
|
|
if (skip_width > 0)
|
|
|
|
{
|
|
|
|
while (skip_width > 0 && chars-- > 0)
|
|
|
|
skip_width -= glyph_width(ucs[chars]);
|
|
|
|
|
|
|
|
if (skip_width < 0)
|
|
|
|
chars++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idx = chars;
|
|
|
|
while (disp_width > 0 && idx-- > 0)
|
|
|
|
disp_width -= glyph_width(ucs[idx]);
|
2010-03-17 11:17:56 +00:00
|
|
|
|
2010-04-12 12:02:05 +00:00
|
|
|
if (disp_width < 0 || idx < 0)
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( ; idx < chars; idx++)
|
|
|
|
utf8 = rb->utf8encode(ucs[idx], utf8);
|
2010-03-17 11:17:56 +00:00
|
|
|
}
|
|
|
|
|
2010-04-12 12:02:05 +00:00
|
|
|
*utf8 = '\0';
|
|
|
|
|
2010-04-07 17:04:30 +00:00
|
|
|
/* return a pointer after the dst string ends */
|
2010-03-17 11:17:56 +00:00
|
|
|
return utf8;
|
|
|
|
}
|
|
|
|
|
2010-04-07 17:04:30 +00:00
|
|
|
/* set max_columns and max_width */
|
2010-03-17 11:17:56 +00:00
|
|
|
static void calc_max_width(void)
|
|
|
|
{
|
|
|
|
if (prefs.view_mode == NARROW)
|
|
|
|
{
|
|
|
|
max_columns = NARROW_MAX_COLUMNS;
|
|
|
|
max_width = draw_columns;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
max_columns = WIDE_MAX_COLUMNS;
|
|
|
|
max_width = 2 * draw_columns;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-07 17:12:20 +00:00
|
|
|
static bool done = false;
|
|
|
|
static int col = 0;
|
2006-05-01 05:45:18 +00:00
|
|
|
|
2010-04-07 17:19:55 +00:00
|
|
|
static inline void advance_conters(unsigned short ch, int* k, int* width)
|
|
|
|
{
|
2010-04-07 17:27:19 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-04-07 17:22:16 +00:00
|
|
|
/* diacritics do not count */
|
|
|
|
if (rb->is_diacritic(ch, NULL))
|
|
|
|
return;
|
2010-04-07 17:27:19 +00:00
|
|
|
#endif
|
2010-04-07 17:22:16 +00:00
|
|
|
|
2010-04-07 17:19:55 +00:00
|
|
|
*width += glyph_width(ch);
|
|
|
|
(*k)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool line_is_full(int k, int width)
|
|
|
|
{
|
|
|
|
return ((k >= max_columns - 1) || (width >= max_width));
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2010-04-07 17:19:55 +00:00
|
|
|
while (!line_is_full(k, width)) {
|
2006-05-11 20:34:37 +00:00
|
|
|
oldp = p;
|
2010-03-17 11:17:56 +00:00
|
|
|
if (BUFFER_OOB(p))
|
|
|
|
break;
|
2006-05-11 20:34:37 +00:00
|
|
|
p = get_ucs(p, &ch);
|
2010-04-07 17:19:55 +00:00
|
|
|
advance_conters(ch, &k, &width);
|
2006-05-11 20:34:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-04-07 17:22:16 +00:00
|
|
|
int s = 0;
|
|
|
|
unsigned short ch;
|
|
|
|
const unsigned char *oldp = p;
|
2010-04-12 12:02:05 +00:00
|
|
|
const unsigned char *lbrkp = NULL;
|
|
|
|
int j;
|
|
|
|
int width = 0;
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2010-04-07 17:22:16 +00:00
|
|
|
while(s <= size)
|
|
|
|
{
|
|
|
|
if (*p == 0)
|
|
|
|
return (unsigned char*)p;
|
|
|
|
oldp = p;
|
|
|
|
p = get_ucs(p, &ch);
|
2010-04-12 12:02:05 +00:00
|
|
|
|
|
|
|
if (prefs.word_mode == WRAP)
|
|
|
|
{
|
|
|
|
for (j = 0; j < ((int) sizeof(line_break)); j++)
|
|
|
|
{
|
|
|
|
if (ch == line_break[j])
|
|
|
|
{
|
|
|
|
lbrkp = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
width += glyph_width(ch);
|
|
|
|
if (width > max_width)
|
|
|
|
return (lbrkp == NULL)? (unsigned char*)oldp : (unsigned char*)lbrkp;
|
|
|
|
|
2010-04-07 17:22:16 +00:00
|
|
|
s += (p - oldp);
|
|
|
|
}
|
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
|
|
|
|
2010-04-07 17:22:16 +00:00
|
|
|
i = size;
|
|
|
|
if (!BUFFER_OOB(&p[i]))
|
|
|
|
for (j=k; j < ((int) sizeof(line_break)) - 1; j++) {
|
|
|
|
if (p[i] == line_break[j])
|
|
|
|
return (unsigned char*) p+i;
|
|
|
|
}
|
2006-05-11 20:34:37 +00:00
|
|
|
|
2010-04-07 17:22:16 +00:00
|
|
|
if (prefs.word_mode == WRAP) {
|
|
|
|
for (i=size-1; i>=0; i--) {
|
|
|
|
for (j=k; j < (int) sizeof(line_break) - 1; j++) {
|
2007-08-05 04:16:21 +00:00
|
|
|
if (p[i] == line_break[j])
|
|
|
|
return (unsigned char*) p+i;
|
2010-04-07 17:22:16 +00:00
|
|
|
}
|
2007-08-05 04:16:21 +00:00
|
|
|
}
|
2010-04-07 17:22:16 +00:00
|
|
|
}
|
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;
|
2010-04-07 17:22:16 +00:00
|
|
|
int size, i, j, j_next, j_prev, k, width, search_len, spaces, newlines;
|
2005-05-13 13:32:57 +00:00
|
|
|
bool first_chars;
|
2010-04-07 17:22:16 +00:00
|
|
|
unsigned short ch;
|
2003-07-24 09:47:46 +00:00
|
|
|
|
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;
|
2010-04-07 17:22:16 +00:00
|
|
|
j_next=j=k=width=spaces=newlines=0;
|
|
|
|
while (1) {
|
|
|
|
const unsigned char *p, *oldp;
|
|
|
|
|
|
|
|
j_prev = j;
|
|
|
|
j = j_next;
|
|
|
|
|
2005-05-14 16:46:31 +00:00
|
|
|
if (BUFFER_OOB(cur_line+j))
|
|
|
|
return NULL;
|
2010-04-07 17:19:55 +00:00
|
|
|
if (line_is_full(k, width)) {
|
2010-04-07 17:22:16 +00:00
|
|
|
size = search_len = j_prev;
|
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
|
|
|
|
2010-04-07 17:22:16 +00:00
|
|
|
oldp = p = &cur_line[j];
|
|
|
|
p = get_ucs(p, &ch);
|
|
|
|
j_next = j + (p - oldp);
|
|
|
|
|
|
|
|
switch (ch) {
|
2003-07-24 09:47:46 +00:00
|
|
|
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++)
|
2010-04-07 17:19:55 +00:00
|
|
|
advance_conters(' ', &k, &width);
|
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--;
|
2010-04-07 17:19:55 +00:00
|
|
|
advance_conters(' ', &k, &width);
|
|
|
|
if (line_is_full(k, width)) {
|
2005-05-13 13:32:57 +00:00
|
|
|
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;
|
2010-04-07 17:19:55 +00:00
|
|
|
advance_conters(' ', &k, &width);
|
|
|
|
if (line_is_full(k, width)) {
|
2005-05-13 13:32:57 +00:00
|
|
|
size = search_len = j;
|
|
|
|
break;
|
|
|
|
}
|
2006-02-16 01:18:21 +00:00
|
|
|
}
|
2005-05-13 13:32:57 +00:00
|
|
|
first_chars = false;
|
2010-04-07 17:19:55 +00:00
|
|
|
advance_conters(ch, &k, &width);
|
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);
|
|
|
|
|
2010-04-07 17:22:16 +00:00
|
|
|
if (next_line == NULL) {
|
2005-05-13 13:32:57 +00:00
|
|
|
next_line = crop_at_width(cur_line);
|
2010-04-07 17:22:16 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (prefs.word_mode == WRAP) {
|
|
|
|
for (i=0;i<WRAP_TRIM;i++) {
|
|
|
|
if (!(isspace(next_line[0]) && !BUFFER_OOB(next_line)))
|
|
|
|
break;
|
2003-07-24 09:47:46 +00:00
|
|
|
next_line++;
|
2010-04-07 17:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
|
|
|
|
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))
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
|
|
|
if (BUFFER_EOF() && next_line != cur_line)
|
|
|
|
return (unsigned char*) next_line;
|
2003-07-24 09:47:46 +00:00
|
|
|
return NULL;
|
2010-03-17 11:17:56 +00:00
|
|
|
}
|
2003-07-24 09:47:46 +00:00
|
|
|
|
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. */
|
2010-03-17 11:17:56 +00:00
|
|
|
while (p != NULL && p < cur_line) {
|
2003-07-24 09:47:46 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
static void check_bom(void)
|
|
|
|
{
|
|
|
|
unsigned char bom[BOM_SIZE];
|
|
|
|
off_t orig = rb->lseek(fd, 0, SEEK_CUR);
|
|
|
|
|
|
|
|
is_bom = false;
|
|
|
|
|
|
|
|
rb->lseek(fd, 0, SEEK_SET);
|
|
|
|
|
|
|
|
if (rb->read(fd, bom, BOM_SIZE) == BOM_SIZE)
|
|
|
|
is_bom = !memcmp(bom, BOM, BOM_SIZE);
|
|
|
|
|
|
|
|
rb->lseek(fd, orig, SEEK_SET);
|
|
|
|
}
|
|
|
|
|
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;
|
2010-03-17 11:17:56 +00:00
|
|
|
off_t offset = rb->lseek(fd, pos, SEEK_SET);
|
|
|
|
|
|
|
|
if (offset == 0 && prefs.encoding == UTF_8 && is_bom)
|
|
|
|
rb->lseek(fd, BOM_SIZE, SEEK_SET);
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2010-04-07 17:06:32 +00:00
|
|
|
numread = rb->read(fd, buf, size - 1);
|
2010-03-17 11:17:56 +00:00
|
|
|
buf[numread] = 0;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
static int viewer_find_bookmark(int page, int line)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < bookmark_count; i++)
|
|
|
|
{
|
|
|
|
if (bookmarks[i].page == page && bookmarks[i].line == line)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
static void get_next_line_position(unsigned char **line_begin,
|
|
|
|
unsigned char **line_end,
|
|
|
|
bool *is_short)
|
|
|
|
{
|
|
|
|
int resynch_move;
|
|
|
|
|
|
|
|
*line_begin = *line_end;
|
|
|
|
*line_end = find_next_line(*line_begin, is_short);
|
|
|
|
|
|
|
|
if (*line_end == NULL && !BUFFER_EOF())
|
|
|
|
{
|
|
|
|
resynch_move = read_and_synch(1); /* Read block & move ptrs */
|
|
|
|
*line_begin -= resynch_move;
|
|
|
|
if (next_line_ptr > buffer)
|
|
|
|
next_line_ptr -= resynch_move;
|
|
|
|
|
|
|
|
*line_end = find_next_line(*line_begin, is_short);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void increment_current_line(void)
|
|
|
|
{
|
|
|
|
if (cline < display_lines)
|
|
|
|
cline++;
|
|
|
|
else if (cpage < MAX_PAGE)
|
|
|
|
{
|
|
|
|
cpage++;
|
|
|
|
cline = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void decrement_current_line(void)
|
|
|
|
{
|
|
|
|
if (cline > 1)
|
|
|
|
cline--;
|
|
|
|
else if (cpage > 1)
|
|
|
|
{
|
|
|
|
cpage--;
|
|
|
|
cline = display_lines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
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;
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
decrement_current_line();
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
static void viewer_scroll_down(bool autoscroll)
|
2006-05-01 05:45:18 +00:00
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
if (cpage == lpage)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (next_line_ptr != NULL)
|
2006-05-01 05:45:18 +00:00
|
|
|
screen_top_ptr = next_line_ptr;
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
if (prefs.scroll_mode == LINE || autoscroll)
|
|
|
|
increment_current_line();
|
2010-04-12 19:28:41 +00:00
|
|
|
cline++;
|
|
|
|
if (cline > display_lines) {
|
|
|
|
cline = 1;
|
|
|
|
cpage++;
|
|
|
|
}
|
2010-03-17 11:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void viewer_scroll_to_top_line(void)
|
|
|
|
{
|
|
|
|
int line;
|
|
|
|
|
|
|
|
for (line = cline; line > 1; line--)
|
|
|
|
viewer_scroll_up();
|
2006-05-01 05:45:18 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static void viewer_scrollbar(void) {
|
2010-03-17 11:17:56 +00:00
|
|
|
int items, min_shown, max_shown, sb_begin_y, sb_height;
|
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);
|
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
sb_begin_y = header_height;
|
|
|
|
sb_height = LCD_HEIGHT - header_height - footer_height;
|
|
|
|
|
|
|
|
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],0, sb_begin_y,
|
|
|
|
SCROLLBAR_WIDTH-1, sb_height,
|
|
|
|
items, min_shown, max_shown, VERTICAL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static void viewer_show_header(void)
|
|
|
|
{
|
|
|
|
if (prefs.header_mode == HD_SBAR || prefs.header_mode == HD_BOTH)
|
|
|
|
rb->gui_syncstatusbar_draw(rb->statusbars, true);
|
|
|
|
|
|
|
|
if (prefs.header_mode == HD_PATH || prefs.header_mode == HD_BOTH)
|
|
|
|
rb->lcd_putsxy(0, header_height - pf->height, file_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void viewer_show_footer(void)
|
|
|
|
{
|
|
|
|
if (prefs.footer_mode == FT_SBAR || prefs.footer_mode == FT_BOTH)
|
|
|
|
rb->gui_syncstatusbar_draw(rb->statusbars, true);
|
|
|
|
|
|
|
|
if (prefs.footer_mode == FT_PAGE || prefs.footer_mode == FT_BOTH)
|
|
|
|
{
|
|
|
|
unsigned char buf[12];
|
|
|
|
|
|
|
|
if (cline == 1)
|
|
|
|
rb->snprintf(buf, sizeof(buf), "%d", cpage);
|
|
|
|
else
|
|
|
|
rb->snprintf(buf, sizeof(buf), "%d - %d", cpage, cpage+1);
|
|
|
|
|
|
|
|
rb->lcd_putsxy(0, LCD_HEIGHT - footer_height, buf);
|
|
|
|
}
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void viewer_draw(int col)
|
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
int i, j, k, line_len, line_width, spaces, left_col=0;
|
2010-04-12 12:02:05 +00:00
|
|
|
int width, extra_spaces, indent_spaces, spaces_per_word, spaces_width, disp_width = 0;
|
2005-05-13 13:32:57 +00:00
|
|
|
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;
|
2010-04-07 17:22:16 +00:00
|
|
|
int max_chars = max_columns * DIACRITIC_FACTOR;
|
2010-04-12 12:02:05 +00:00
|
|
|
unsigned char scratch_buffer[max_chars * 4 + 1];
|
2010-04-07 17:22:16 +00:00
|
|
|
unsigned char utf8_buffer[max_chars * 4 + 1];
|
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();
|
|
|
|
}
|
|
|
|
line_begin = line_end = screen_top_ptr;
|
|
|
|
|
|
|
|
for (i = 0; i < display_lines; i++) {
|
|
|
|
if (BUFFER_OOB(line_end))
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
|
|
|
if (lpage == cpage)
|
|
|
|
break; /* Happens after display last line at BUFFER_EOF() */
|
2003-07-24 09:47:46 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
if (lpage == 0 && cline == 1)
|
|
|
|
{
|
|
|
|
lpage = cpage;
|
|
|
|
last_screen_top_ptr = screen_top_ptr;
|
|
|
|
last_file_pos = file_pos;
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
get_next_line_position(&line_begin, &line_end, &line_is_short);
|
|
|
|
if (line_end == NULL)
|
|
|
|
{
|
|
|
|
if (BUFFER_OOB(line_begin))
|
|
|
|
break;
|
|
|
|
line_end = buffer_end + 1;
|
|
|
|
}
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
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++;
|
2010-04-07 17:22:16 +00:00
|
|
|
if (oldstr == str)
|
|
|
|
{
|
|
|
|
oldstr = line_end;
|
|
|
|
break;
|
|
|
|
}
|
2006-05-11 20:34:37 +00:00
|
|
|
}
|
2010-04-07 17:22:16 +00:00
|
|
|
/* width of un-displayed part of the line */
|
2006-05-11 20:34:37 +00:00
|
|
|
line_width = j*draw_columns;
|
2010-04-07 17:22:16 +00:00
|
|
|
spaces_width = 0;
|
2006-05-11 20:34:37 +00:00
|
|
|
while (oldstr < line_end) {
|
|
|
|
oldstr = get_ucs(oldstr, &ch);
|
2010-04-07 17:22:16 +00:00
|
|
|
/* add width of displayed part of the line */
|
|
|
|
if (ch)
|
|
|
|
{
|
|
|
|
int dw = glyph_width(ch);
|
|
|
|
|
|
|
|
/* avoid counting spaces at the end of the line */
|
|
|
|
if (ch == ' ')
|
|
|
|
{
|
|
|
|
spaces_width += dw;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line_width += dw + spaces_width;
|
|
|
|
spaces_width = 0;
|
|
|
|
}
|
|
|
|
}
|
2006-05-11 20:34:37 +00:00
|
|
|
}
|
|
|
|
|
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++) {
|
2010-04-07 17:22:16 +00:00
|
|
|
if (k == max_chars)
|
2003-07-24 09:47:46 +00:00
|
|
|
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++] = ' ';
|
2010-04-07 17:22:16 +00:00
|
|
|
if (k == max_chars - 1)
|
2003-07-24 09:47:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
scratch_buffer[k++] = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-04-12 12:02:05 +00:00
|
|
|
scratch_buffer[k] = 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 0:
|
2010-04-12 12:02:05 +00:00
|
|
|
case ' ':
|
|
|
|
if (str == line_begin)
|
|
|
|
{
|
|
|
|
if (prefs.word_mode == WRAP && prefs.alignment == LEFT)
|
|
|
|
{
|
|
|
|
/* special case: indent the paragraph,
|
|
|
|
* 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 */
|
2010-03-17 11:17:56 +00:00
|
|
|
extra_spaces = (max_width-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;
|
|
|
|
}
|
|
|
|
multiple_spacing = false;
|
|
|
|
for (j=k=spaces=0; j < line_len; j++) {
|
2010-04-07 17:22:16 +00:00
|
|
|
if (k == max_chars)
|
2005-05-13 13:32:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
c = line_begin[j];
|
|
|
|
switch (c) {
|
|
|
|
case 0:
|
2010-04-12 12:02:05 +00:00
|
|
|
if (j == line_len - 1)
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
if (j==0) {
|
|
|
|
/* indent paragraph */
|
|
|
|
if (prefs.word_mode == WRAP && prefs.alignment == LEFT)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2010-04-12 12:02:05 +00:00
|
|
|
while (scratch_buffer[k-1] == ' ')
|
|
|
|
k--;
|
|
|
|
scratch_buffer[k] = 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 */
|
2010-04-12 12:02:05 +00:00
|
|
|
if (col != -1)
|
|
|
|
{
|
|
|
|
rb->memcpy(scratch_buffer, line_begin, line_len);
|
|
|
|
scratch_buffer[line_len] = '\0';
|
2010-04-07 17:22:16 +00:00
|
|
|
}
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
2010-04-07 17:22:16 +00:00
|
|
|
|
2010-04-12 12:02:05 +00:00
|
|
|
/* create displayed line */
|
|
|
|
if (col != -1)
|
|
|
|
{
|
|
|
|
decode2utf8(scratch_buffer, utf8_buffer, col, draw_columns);
|
|
|
|
rb->lcd_getstringsize(utf8_buffer, &disp_width, NULL);
|
|
|
|
}
|
|
|
|
|
2010-04-07 17:22:16 +00:00
|
|
|
/* display on screen the displayed part of the line */
|
2010-04-12 12:02:05 +00:00
|
|
|
if (col != -1)
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
2010-04-12 21:15:10 +00:00
|
|
|
bool in_page = (cline+i <= display_lines);
|
2010-04-12 19:25:28 +00:00
|
|
|
int dpage = cpage + (in_page ? 0 : 1);
|
|
|
|
int dline = cline + i - (in_page ? 0 : display_lines);
|
2010-03-17 11:17:56 +00:00
|
|
|
bool bflag = (viewer_find_bookmark(dpage, dline) >= 0);
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
int dy = i * pf->height + header_height;
|
2010-04-12 12:02:05 +00:00
|
|
|
int dx = (prefs.alignment == LEFT)? left_col : LCD_WIDTH - disp_width;
|
2010-03-17 11:17:56 +00:00
|
|
|
#endif
|
|
|
|
if (bflag)
|
2006-05-11 20:34:37 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
|
|
|
rb->lcd_set_drawmode(DRMODE_BG|DRMODE_FG);
|
2010-04-07 17:15:24 +00:00
|
|
|
rb->lcd_fillrect(left_col, dy, LCD_WIDTH - left_col, pf->height);
|
2010-03-17 11:17:56 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
|
|
|
|
}
|
2010-03-30 17:09:04 +00:00
|
|
|
rb->lcd_putsxy(dx, dy, utf8_buffer);
|
2010-03-17 11:17:56 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2006-05-11 20:34:37 +00:00
|
|
|
#else
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
|
|
|
rb->lcd_puts(left_col, i, BOOKMARK_ICON);
|
|
|
|
}
|
|
|
|
rb->lcd_puts(left_col+1, i, utf8_buffer);
|
2006-05-11 20:34:37 +00:00
|
|
|
#endif
|
2010-03-17 11:17:56 +00:00
|
|
|
}
|
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
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
/* show header */
|
|
|
|
viewer_show_header();
|
2010-04-07 17:04:30 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
/* show footer */
|
|
|
|
viewer_show_footer();
|
|
|
|
#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 */
|
2007-11-19 16:46:39 +00:00
|
|
|
if (file_pos != 0)
|
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
rb->splash(0, "Loading...");
|
|
|
|
|
2007-11-19 16:46:39 +00:00
|
|
|
file_pos = 0;
|
|
|
|
buffer_end = BUFFER_END(); /* Update whenever file_pos changes */
|
2007-11-23 09:11:11 +00:00
|
|
|
fill_buffer(0, buffer, buffer_size);
|
2007-11-19 16:46:39 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
screen_top_ptr = buffer;
|
2010-03-17 11:17:56 +00:00
|
|
|
cpage = 1;
|
|
|
|
cline = 1;
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void viewer_bottom(void)
|
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
unsigned char *line_begin;
|
|
|
|
unsigned char *line_end;
|
2003-07-24 09:47:46 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
rb->splash(0, "Loading...");
|
2007-11-19 16:46:39 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
if (last_screen_top_ptr)
|
2007-11-19 16:46:39 +00:00
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
cpage = lpage;
|
|
|
|
cline = 1;
|
|
|
|
screen_top_ptr = last_screen_top_ptr;
|
|
|
|
file_pos = last_file_pos;
|
|
|
|
fill_buffer(file_pos, buffer, buffer_size);
|
|
|
|
buffer_end = BUFFER_END();
|
|
|
|
return;
|
2007-11-19 16:46:39 +00:00
|
|
|
}
|
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
line_end = screen_top_ptr;
|
|
|
|
|
|
|
|
while (!BUFFER_EOF() || !BUFFER_OOB(line_end))
|
|
|
|
{
|
|
|
|
get_next_line_position(&line_begin, &line_end, NULL);
|
|
|
|
if (line_end == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
increment_current_line();
|
|
|
|
if (cline == 1)
|
|
|
|
screen_top_ptr = line_end;
|
|
|
|
}
|
|
|
|
lpage = cpage;
|
|
|
|
cline = 1;
|
|
|
|
last_screen_top_ptr = screen_top_ptr;
|
|
|
|
last_file_pos = file_pos;
|
|
|
|
buffer_end = BUFFER_END();
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
|
|
|
|
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(' '));
|
2010-03-17 11:17:56 +00:00
|
|
|
calc_max_width();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_header_and_footer(void)
|
|
|
|
{
|
|
|
|
header_height = 0;
|
|
|
|
footer_height = 0;
|
|
|
|
if (rb->global_settings->statusbar == STATUSBAR_TOP)
|
|
|
|
{
|
|
|
|
if (prefs.header_mode == HD_SBAR || prefs.header_mode == HD_BOTH)
|
|
|
|
header_height = STATUSBAR_HEIGHT;
|
|
|
|
|
|
|
|
if (prefs.footer_mode == FT_SBAR)
|
|
|
|
prefs.footer_mode = FT_NONE;
|
|
|
|
else if (prefs.footer_mode == FT_BOTH)
|
|
|
|
prefs.footer_mode = FT_PAGE;
|
|
|
|
}
|
|
|
|
else if (rb->global_settings->statusbar == STATUSBAR_BOTTOM)
|
|
|
|
{
|
|
|
|
if (prefs.footer_mode == FT_SBAR || prefs.footer_mode == FT_BOTH)
|
|
|
|
footer_height = STATUSBAR_HEIGHT;
|
|
|
|
|
|
|
|
if (prefs.header_mode == HD_SBAR)
|
|
|
|
prefs.header_mode = HD_NONE;
|
|
|
|
else if (prefs.header_mode == HD_BOTH)
|
|
|
|
prefs.header_mode = HD_PATH;
|
|
|
|
}
|
|
|
|
else /* STATUSBAR_OFF || STATUSBAR_CUSTOM */
|
|
|
|
{
|
|
|
|
if (prefs.header_mode == HD_SBAR)
|
|
|
|
prefs.header_mode = HD_NONE;
|
|
|
|
else if (prefs.header_mode == HD_BOTH)
|
|
|
|
prefs.header_mode = HD_PATH;
|
|
|
|
|
|
|
|
if (prefs.footer_mode == FT_SBAR)
|
|
|
|
prefs.footer_mode = FT_NONE;
|
|
|
|
else if (prefs.footer_mode == FT_BOTH)
|
|
|
|
prefs.footer_mode = FT_PAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prefs.header_mode == HD_NONE || prefs.header_mode == HD_PATH ||
|
|
|
|
prefs.footer_mode == FT_NONE || prefs.footer_mode == FT_PAGE)
|
|
|
|
rb->gui_syncstatusbar_draw(rb->statusbars, false);
|
|
|
|
|
|
|
|
if (prefs.header_mode == HD_PATH || prefs.header_mode == HD_BOTH)
|
|
|
|
header_height += pf->height;
|
|
|
|
if (prefs.footer_mode == FT_PAGE || prefs.footer_mode == FT_BOTH)
|
|
|
|
footer_height += pf->height;
|
|
|
|
|
|
|
|
display_lines = (LCD_HEIGHT - header_height - footer_height) / pf->height;
|
|
|
|
|
|
|
|
lpage = 0;
|
|
|
|
last_file_pos = 0;
|
|
|
|
last_screen_top_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
2010-04-07 18:06:47 +00:00
|
|
|
static bool change_font(unsigned char *font)
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
|
|
|
unsigned char buf[MAX_PATH];
|
|
|
|
|
|
|
|
if (font == NULL || *font == '\0')
|
2010-04-07 18:14:02 +00:00
|
|
|
return false;
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
rb->snprintf(buf, MAX_PATH, "%s/%s.fnt", FONT_DIR, font);
|
2010-04-07 18:06:47 +00:00
|
|
|
if (rb->font_load(NULL, buf) < 0) {
|
|
|
|
rb->splash(HZ/2, "Font load failed.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
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
|
2010-03-17 11:17:56 +00:00
|
|
|
/* initialize fonts */
|
2005-05-13 13:32:57 +00:00
|
|
|
pf = rb->font_get(FONT_UI);
|
2010-04-07 18:06:47 +00:00
|
|
|
if (pf == NULL)
|
|
|
|
return false;
|
|
|
|
|
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);
|
2009-12-06 13:52:28 +00:00
|
|
|
if (fd < 0)
|
2002-09-30 19:05:03 +00:00
|
|
|
return false;
|
|
|
|
|
2003-07-24 09:47:46 +00:00
|
|
|
/* Init mac_text value used in processing buffer */
|
|
|
|
mac_text = false;
|
|
|
|
|
2002-09-30 19:05:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
/* When a file is UTF-8 file with BOM, if prefs.encoding is UTF-8,
|
|
|
|
* then file size decreases only BOM_SIZE.
|
|
|
|
*/
|
|
|
|
static void get_filesize(void)
|
2006-05-01 05:45:18 +00:00
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
file_size = rb->filesize(fd);
|
|
|
|
if (file_size == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (prefs.encoding == UTF_8 && is_bom)
|
|
|
|
file_size -= BOM_SIZE;
|
2006-05-01 05:45:18 +00:00
|
|
|
}
|
2005-05-17 13:14:09 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
static int bm_comp(const void *a, const void *b)
|
2005-05-17 13:14:09 +00:00
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
struct bookmark_info *pa;
|
|
|
|
struct bookmark_info *pb;
|
2009-12-18 14:17:28 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
pa = (struct bookmark_info*)a;
|
|
|
|
pb = (struct bookmark_info*)b;
|
|
|
|
|
|
|
|
if (pa->page != pb->page)
|
|
|
|
return pa->page - pb->page;
|
|
|
|
|
|
|
|
return pa->line - pb->line;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void viewer_add_bookmark(void)
|
|
|
|
{
|
|
|
|
if (bookmark_count >= MAX_BOOKMARKS-1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bookmarks[bookmark_count].file_position
|
|
|
|
= file_pos + screen_top_ptr - buffer;
|
|
|
|
bookmarks[bookmark_count].page = cpage;
|
|
|
|
bookmarks[bookmark_count].line = cline;
|
|
|
|
bookmarks[bookmark_count].flag = BOOKMARK_USER;
|
|
|
|
bookmark_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int viewer_add_last_read_bookmark(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = viewer_find_bookmark(cpage, cline);
|
|
|
|
if (i >= 0)
|
|
|
|
bookmarks[i].flag |= BOOKMARK_LAST;
|
2007-11-23 09:11:09 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
viewer_add_bookmark();
|
|
|
|
i = bookmark_count-1;
|
|
|
|
bookmarks[i].flag = BOOKMARK_LAST;
|
2007-11-23 09:11:09 +00:00
|
|
|
}
|
2010-03-17 11:17:56 +00:00
|
|
|
return i;
|
|
|
|
}
|
2007-11-23 09:11:09 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
static void viewer_remove_bookmark(int i)
|
|
|
|
{
|
|
|
|
int j;
|
2005-05-17 13:14:09 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
if (i < 0 || i >= bookmark_count)
|
|
|
|
return;
|
2007-09-13 00:18:28 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
for (j = i+1; j < bookmark_count; j++)
|
|
|
|
rb->memcpy(&bookmarks[j-1], &bookmarks[j],
|
|
|
|
sizeof(struct bookmark_info));
|
2007-11-19 20:51:38 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
bookmark_count--;
|
|
|
|
}
|
2007-09-13 00:18:28 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
static void viewer_remove_last_read_bookmark(void)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < bookmark_count; i++)
|
2007-09-13 00:18:28 +00:00
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
if (bookmarks[i].flag & BOOKMARK_LAST)
|
2006-09-18 15:31:51 +00:00
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
if (bookmarks[i].flag == BOOKMARK_LAST)
|
|
|
|
{
|
|
|
|
for (j = i+1; j < bookmark_count; j++)
|
|
|
|
rb->memcpy(&bookmarks[j-1], &bookmarks[j],
|
|
|
|
sizeof(struct bookmark_info));
|
|
|
|
|
|
|
|
bookmark_count--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bookmarks[i].flag = BOOKMARK_USER;
|
2007-09-13 00:18:28 +00:00
|
|
|
break;
|
2009-12-18 14:17:28 +00:00
|
|
|
}
|
2007-09-13 00:18:28 +00:00
|
|
|
}
|
2010-03-17 11:17:56 +00:00
|
|
|
}
|
2007-09-13 00:18:28 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
static int viewer_get_last_read_bookmark(void)
|
|
|
|
{
|
|
|
|
int i;
|
2007-11-19 20:51:38 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
for (i = 0; i < bookmark_count; i++)
|
2007-09-13 00:18:28 +00:00
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
if (bookmarks[i].flag & BOOKMARK_LAST)
|
|
|
|
return i;
|
2009-12-18 14:17:28 +00:00
|
|
|
}
|
2010-03-17 11:17:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-09-13 00:18:28 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
static void viewer_select_bookmark(int initval)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int ipage = 0;
|
|
|
|
int iline = 0;
|
|
|
|
int screen_pos;
|
|
|
|
int screen_top;
|
|
|
|
int selected = -1;
|
2007-11-19 20:51:38 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
struct opt_items items[bookmark_count];
|
|
|
|
unsigned char names[bookmark_count][38];
|
2007-11-19 20:51:38 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
if (initval >= 0 && initval < bookmark_count)
|
|
|
|
{
|
|
|
|
ipage = bookmarks[initval].page;
|
|
|
|
iline = bookmarks[initval].line;
|
2007-09-13 00:18:28 +00:00
|
|
|
}
|
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
rb->qsort(bookmarks, bookmark_count, sizeof(struct bookmark_info),
|
|
|
|
bm_comp);
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
for (i = 0; i < bookmark_count; i++)
|
2007-09-13 00:18:28 +00:00
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
rb->snprintf(names[i], sizeof(names[0]),
|
|
|
|
#if CONFIG_KEYPAD != PLAYER_PAD
|
|
|
|
"%sPage: %d Line: %d",
|
|
|
|
#else
|
|
|
|
"%sP:%d L:%d",
|
|
|
|
#endif
|
|
|
|
(bookmarks[i].flag&BOOKMARK_LAST)? "*":" ",
|
|
|
|
bookmarks[i].page,
|
|
|
|
bookmarks[i].line);
|
|
|
|
items[i].string = names[i];
|
|
|
|
items[i].voice_id = -1;
|
|
|
|
if (selected < 0 && bookmarks[i].page == ipage && bookmarks[i].line == iline)
|
|
|
|
selected = i;
|
2005-05-17 13:14:09 +00:00
|
|
|
}
|
2006-02-16 01:18:21 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
rb->set_option("Select bookmark", &selected, INT, items,
|
|
|
|
sizeof(items) / sizeof(items[0]), NULL);
|
2007-08-13 13:53:33 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
if (selected < 0 || selected >= bookmark_count)
|
2007-11-19 20:51:42 +00:00
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
if (initval < 0 || (selected = viewer_get_last_read_bookmark()) < 0)
|
2007-11-19 20:51:42 +00:00
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
if (initval < 0)
|
|
|
|
rb->splash(HZ, "Start the first page.");
|
|
|
|
file_pos = 0;
|
|
|
|
screen_top_ptr = buffer;
|
|
|
|
cpage = 1;
|
|
|
|
cline = 1;
|
|
|
|
buffer_end = BUFFER_END();
|
|
|
|
return;
|
2007-11-19 20:51:42 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-18 14:17:28 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
screen_pos = bookmarks[selected].file_position;
|
|
|
|
screen_top = screen_pos % buffer_size;
|
|
|
|
file_pos = screen_pos - screen_top;
|
|
|
|
screen_top_ptr = buffer + screen_top;
|
|
|
|
cpage = bookmarks[selected].page;
|
|
|
|
cline = bookmarks[selected].line;
|
|
|
|
buffer_end = BUFFER_END();
|
2006-02-16 01:18:21 +00:00
|
|
|
}
|
2005-05-17 13:14:09 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
static void viewer_default_preferences(void)
|
2002-09-30 19:05:03 +00:00
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
prefs.word_mode = WRAP;
|
|
|
|
prefs.line_mode = NORMAL;
|
|
|
|
prefs.view_mode = NARROW;
|
2010-03-30 17:09:04 +00:00
|
|
|
prefs.alignment = LEFT;
|
2010-03-17 11:17:56 +00:00
|
|
|
prefs.scroll_mode = PAGE;
|
|
|
|
prefs.page_mode = NO_OVERLAP;
|
|
|
|
prefs.scrollbar_mode = SB_OFF;
|
|
|
|
rb->memset(prefs.font, 0, MAX_PATH);
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
prefs.header_mode = HD_BOTH;
|
|
|
|
prefs.footer_mode = FT_BOTH;
|
|
|
|
rb->snprintf(prefs.font, MAX_PATH, "%s", rb->global_settings->font_file);
|
|
|
|
#else
|
|
|
|
prefs.header_mode = HD_NONE;
|
|
|
|
prefs.footer_mode = FT_NONE;
|
|
|
|
#endif
|
|
|
|
prefs.autoscroll_speed = 1;
|
|
|
|
/* Set codepage to system default */
|
|
|
|
prefs.encoding = rb->global_settings->default_codepage;
|
2002-09-30 19:05:03 +00:00
|
|
|
}
|
|
|
|
|
2010-04-11 06:39:37 +00:00
|
|
|
static bool viewer_read_preferences(int pfd, int version, struct preferences *prf)
|
2002-09-30 19:05:03 +00:00
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
unsigned char buf[PREFERENCES_SIZE];
|
|
|
|
unsigned char *p = buf;
|
2010-04-11 06:39:37 +00:00
|
|
|
int read_size = PREFERENCES_SIZE;
|
2010-03-17 11:17:56 +00:00
|
|
|
|
2010-04-11 06:39:37 +00:00
|
|
|
if (version == 0)
|
|
|
|
read_size--;
|
|
|
|
|
|
|
|
if (rb->read(pfd, buf, read_size) != read_size)
|
2010-03-17 11:17:56 +00:00
|
|
|
return false;
|
|
|
|
|
2010-04-11 06:39:37 +00:00
|
|
|
prf->word_mode = *p++;
|
|
|
|
prf->line_mode = *p++;
|
|
|
|
prf->view_mode = *p++;
|
2010-04-10 08:58:37 +00:00
|
|
|
if (version > 0)
|
2010-04-11 06:39:37 +00:00
|
|
|
prf->alignment = *p++;
|
2010-04-10 08:58:37 +00:00
|
|
|
else
|
2010-04-11 06:39:37 +00:00
|
|
|
prf->alignment = LEFT;
|
|
|
|
prf->encoding = *p++;
|
|
|
|
prf->scrollbar_mode = *p++;
|
|
|
|
prf->need_scrollbar = *p++;
|
|
|
|
prf->page_mode = *p++;
|
|
|
|
prf->header_mode = *p++;
|
|
|
|
prf->footer_mode = *p++;
|
|
|
|
prf->scroll_mode = *p++;
|
|
|
|
prf->autoscroll_speed = *p++;
|
|
|
|
rb->memcpy(prf->font, p, MAX_PATH);
|
2010-03-17 11:17:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-11 06:39:37 +00:00
|
|
|
static bool viewer_write_preferences(int pfd, const struct preferences *prf)
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
|
|
|
unsigned char buf[PREFERENCES_SIZE];
|
|
|
|
unsigned char *p = buf;
|
|
|
|
|
2010-04-11 06:39:37 +00:00
|
|
|
*p++ = prf->word_mode;
|
|
|
|
*p++ = prf->line_mode;
|
|
|
|
*p++ = prf->view_mode;
|
|
|
|
*p++ = prf->alignment;
|
|
|
|
*p++ = prf->encoding;
|
|
|
|
*p++ = prf->scrollbar_mode;
|
|
|
|
*p++ = prf->need_scrollbar;
|
|
|
|
*p++ = prf->page_mode;
|
|
|
|
*p++ = prf->header_mode;
|
|
|
|
*p++ = prf->footer_mode;
|
|
|
|
*p++ = prf->scroll_mode;
|
|
|
|
*p++ = prf->autoscroll_speed;
|
|
|
|
rb->memcpy(p, prf->font, MAX_PATH);
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
return (rb->write(pfd, buf, sizeof(buf)) == sizeof(buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool viewer_read_bookmark_info(int bfd, struct bookmark_info *b)
|
|
|
|
{
|
|
|
|
unsigned char buf[BOOKMARK_SIZE];
|
|
|
|
|
|
|
|
if (rb->read(bfd, buf, sizeof(buf)) != sizeof(buf))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
b->file_position = (buf[0] << 24)|(buf[1] << 16)|(buf[2] << 8)|buf[3];
|
|
|
|
b->page = (buf[4] << 8)|buf[5];
|
|
|
|
b->line = buf[6];
|
|
|
|
b->flag = buf[7];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool viewer_read_bookmark_infos(int bfd)
|
|
|
|
{
|
|
|
|
unsigned char c;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (rb->read(bfd, &c, 1) != 1)
|
|
|
|
{
|
|
|
|
bookmark_count = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bookmark_count = c;
|
|
|
|
if (bookmark_count > MAX_BOOKMARKS)
|
|
|
|
bookmark_count = MAX_BOOKMARKS;
|
|
|
|
|
|
|
|
for (i = 0; i < bookmark_count; i++)
|
|
|
|
{
|
|
|
|
if (!viewer_read_bookmark_info(bfd, &bookmarks[i]))
|
|
|
|
{
|
|
|
|
bookmark_count = i;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool viewer_write_bookmark_info(int bfd, struct bookmark_info *b)
|
|
|
|
{
|
|
|
|
unsigned char buf[BOOKMARK_SIZE];
|
|
|
|
unsigned char *p = buf;
|
|
|
|
unsigned long ul;
|
|
|
|
|
|
|
|
ul = b->file_position;
|
|
|
|
*p++ = ul >> 24;
|
|
|
|
*p++ = ul >> 16;
|
|
|
|
*p++ = ul >> 8;
|
|
|
|
*p++ = ul;
|
|
|
|
|
|
|
|
ul = b->page;
|
|
|
|
*p++ = ul >> 8;
|
|
|
|
*p++ = ul;
|
|
|
|
|
|
|
|
*p++ = b->line;
|
|
|
|
*p = b->flag;
|
|
|
|
|
|
|
|
return (rb->write(bfd, buf, sizeof(buf)) == sizeof(buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool viewer_write_bookmark_infos(int bfd)
|
|
|
|
{
|
|
|
|
unsigned char c = bookmark_count;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (rb->write(bfd, &c, 1) != 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (i = 0; i < bookmark_count; i++)
|
|
|
|
{
|
|
|
|
if (!viewer_write_bookmark_info(bfd, &bookmarks[i]))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool viewer_load_global_settings(void)
|
|
|
|
{
|
|
|
|
unsigned buf[GLOBAL_SETTINGS_H_SIZE];
|
|
|
|
int sfd = rb->open(GLOBAL_SETTINGS_FILE, O_RDONLY);
|
2010-04-10 08:58:37 +00:00
|
|
|
int version;
|
|
|
|
bool res = false;
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
if (sfd < 0)
|
|
|
|
return false;
|
|
|
|
|
2010-04-10 08:58:37 +00:00
|
|
|
if ((rb->read(sfd, buf, GLOBAL_SETTINGS_H_SIZE) == GLOBAL_SETTINGS_H_SIZE) ||
|
|
|
|
(rb->memcmp(buf, GLOBAL_SETTINGS_HEADER, GLOBAL_SETTINGS_H_SIZE - 1) == 0))
|
|
|
|
{
|
|
|
|
version = buf[GLOBAL_SETTINGS_H_SIZE - 1] - GLOBAL_SETTINGS_FIRST_VERSION;
|
2010-04-11 06:39:37 +00:00
|
|
|
res = viewer_read_preferences(sfd, version, &prefs);
|
2010-03-17 11:17:56 +00:00
|
|
|
}
|
|
|
|
rb->close(sfd);
|
2010-04-10 08:58:37 +00:00
|
|
|
return res;
|
2010-03-17 11:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool viewer_save_global_settings(void)
|
|
|
|
{
|
2010-05-06 17:35:13 +00:00
|
|
|
int sfd = rb->open(GLOBAL_SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
2010-04-11 06:39:37 +00:00
|
|
|
unsigned char buf[GLOBAL_SETTINGS_H_SIZE];
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
if (sfd < 0)
|
|
|
|
return false;
|
|
|
|
|
2010-04-11 06:39:37 +00:00
|
|
|
rb->memcpy(buf, GLOBAL_SETTINGS_HEADER, GLOBAL_SETTINGS_H_SIZE - 1);
|
|
|
|
buf[GLOBAL_SETTINGS_H_SIZE - 1] = GLOBAL_SETTINGS_VERSION;
|
|
|
|
|
|
|
|
if (rb->write(sfd, buf, GLOBAL_SETTINGS_H_SIZE) != GLOBAL_SETTINGS_H_SIZE ||
|
|
|
|
!viewer_write_preferences(sfd, &prefs))
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
|
|
|
rb->close(sfd);
|
|
|
|
rb->remove(GLOBAL_SETTINGS_TMP_FILE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
rb->close(sfd);
|
|
|
|
rb->remove(GLOBAL_SETTINGS_FILE);
|
|
|
|
rb->rename(GLOBAL_SETTINGS_TMP_FILE, GLOBAL_SETTINGS_FILE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-11 06:39:37 +00:00
|
|
|
static bool viewer_convert_settings(int sfd, int dfd, int old_ver)
|
|
|
|
{
|
|
|
|
struct preferences new_prefs;
|
|
|
|
off_t old_pos;
|
|
|
|
off_t new_pos;
|
|
|
|
unsigned char buf[MAX_PATH + 2];
|
|
|
|
int settings_size;
|
|
|
|
|
|
|
|
rb->read(sfd, buf, MAX_PATH + 2);
|
|
|
|
rb->write(dfd, buf, MAX_PATH + 2);
|
|
|
|
|
|
|
|
settings_size = (buf[MAX_PATH] << 8) | buf[MAX_PATH + 1];
|
|
|
|
|
|
|
|
old_pos = rb->lseek(sfd, 0, SEEK_CUR);
|
|
|
|
new_pos = rb->lseek(dfd, 0, SEEK_CUR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* when the settings size != preferences size + bookmarks size,
|
|
|
|
* settings data are considered to be old version.
|
|
|
|
*/
|
|
|
|
if (old_ver > 0 && ((settings_size - PREFERENCES_SIZE) % 8) == 0)
|
|
|
|
old_ver = 0;
|
|
|
|
|
|
|
|
if (!viewer_read_preferences(sfd, old_ver, &new_prefs))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!viewer_write_preferences(dfd, &new_prefs))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
settings_size -= (rb->lseek(sfd, 0, SEEK_CUR) - old_pos);
|
|
|
|
|
|
|
|
if (settings_size > 0)
|
|
|
|
{
|
|
|
|
rb->read(sfd, buf, settings_size);
|
|
|
|
rb->write(dfd, buf, settings_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
settings_size = rb->lseek(dfd, 0, SEEK_CUR) - new_pos;
|
|
|
|
buf[0] = settings_size >> 8;
|
|
|
|
buf[1] = settings_size;
|
|
|
|
rb->lseek(dfd, new_pos - 2, SEEK_SET);
|
|
|
|
rb->write(dfd, buf, 2);
|
|
|
|
rb->lseek(dfd, settings_size, SEEK_CUR);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool viewer_convert_settings_file(void)
|
|
|
|
{
|
|
|
|
unsigned char buf[SETTINGS_H_SIZE+2];
|
|
|
|
int sfd;
|
|
|
|
int tfd;
|
|
|
|
int i;
|
|
|
|
int fcount;
|
|
|
|
int version;
|
|
|
|
bool res = true;
|
|
|
|
|
|
|
|
if ((sfd = rb->open(SETTINGS_FILE, O_RDONLY)) < 0)
|
|
|
|
return false;
|
|
|
|
|
2010-05-06 17:35:13 +00:00
|
|
|
if ((tfd = rb->open(SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
|
2010-04-11 06:39:37 +00:00
|
|
|
{
|
|
|
|
rb->close(sfd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->read(sfd, buf, SETTINGS_H_SIZE + 2);
|
|
|
|
|
|
|
|
version = buf[SETTINGS_H_SIZE - 1] - SETTINGS_FIRST_VERSION;
|
|
|
|
fcount = (buf[SETTINGS_H_SIZE] << 8) | buf[SETTINGS_H_SIZE + 1];
|
|
|
|
buf[SETTINGS_H_SIZE - 1] = SETTINGS_VERSION;
|
|
|
|
|
|
|
|
rb->write(tfd, buf, SETTINGS_H_SIZE + 2);
|
|
|
|
|
|
|
|
for (i = 0; i < fcount; i++)
|
|
|
|
{
|
|
|
|
if (!viewer_convert_settings(sfd, tfd, version))
|
|
|
|
{
|
|
|
|
res = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->close(sfd);
|
|
|
|
rb->close(tfd);
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
rb->remove(SETTINGS_TMP_FILE);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->remove(SETTINGS_FILE);
|
|
|
|
rb->rename(SETTINGS_TMP_FILE, SETTINGS_FILE);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-04-07 18:06:47 +00:00
|
|
|
static bool viewer_load_settings(void)
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
|
|
|
unsigned char buf[MAX_PATH+2];
|
|
|
|
unsigned int fcount;
|
|
|
|
unsigned int i;
|
|
|
|
bool res = false;
|
|
|
|
int sfd;
|
|
|
|
unsigned int size;
|
2010-04-10 08:58:37 +00:00
|
|
|
int version;
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
sfd = rb->open(SETTINGS_FILE, O_RDONLY);
|
|
|
|
if (sfd < 0)
|
|
|
|
goto read_end;
|
|
|
|
|
|
|
|
if ((rb->read(sfd, buf, SETTINGS_H_SIZE+2) != SETTINGS_H_SIZE+2) ||
|
2010-04-10 08:58:37 +00:00
|
|
|
rb->memcmp(buf, SETTINGS_HEADER, SETTINGS_H_SIZE - 1))
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
|
|
|
/* illegal setting file */
|
|
|
|
rb->close(sfd);
|
|
|
|
|
|
|
|
if (rb->file_exists(SETTINGS_FILE))
|
|
|
|
rb->remove(SETTINGS_FILE);
|
|
|
|
|
|
|
|
goto read_end;
|
|
|
|
}
|
|
|
|
|
2010-04-11 06:39:37 +00:00
|
|
|
if (buf[SETTINGS_H_SIZE - 1] != SETTINGS_VERSION)
|
|
|
|
{
|
|
|
|
rb->close(sfd);
|
|
|
|
if (!viewer_convert_settings_file())
|
|
|
|
goto read_end;
|
|
|
|
|
|
|
|
return viewer_load_settings();
|
|
|
|
}
|
|
|
|
|
2010-04-10 08:58:37 +00:00
|
|
|
version = buf[SETTINGS_H_SIZE - 1] - SETTINGS_FIRST_VERSION;
|
2010-03-17 11:17:56 +00:00
|
|
|
fcount = (buf[SETTINGS_H_SIZE] << 8) | buf[SETTINGS_H_SIZE+1];
|
|
|
|
for (i = 0; i < fcount; i++)
|
|
|
|
{
|
|
|
|
if (rb->read(sfd, buf, MAX_PATH+2) != MAX_PATH+2)
|
|
|
|
break;
|
|
|
|
|
|
|
|
size = (buf[MAX_PATH] << 8) | buf[MAX_PATH+1];
|
2010-04-11 06:39:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* when the settings size != preferences size + bookmarks size,
|
|
|
|
* the settings file converts to the newer.
|
|
|
|
*/
|
|
|
|
if (version > 0 && ((size - PREFERENCES_SIZE) % 8) == 0)
|
|
|
|
{
|
|
|
|
rb->close(sfd);
|
|
|
|
if (!viewer_convert_settings_file())
|
|
|
|
break;
|
|
|
|
|
|
|
|
return viewer_load_settings();
|
|
|
|
}
|
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
if (rb->strcmp(buf, file_name))
|
|
|
|
{
|
|
|
|
if (rb->lseek(sfd, size, SEEK_CUR) < 0)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
2010-04-11 06:39:37 +00:00
|
|
|
if (!viewer_read_preferences(sfd, version, &prefs))
|
2010-03-17 11:17:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
res = viewer_read_bookmark_infos(sfd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->close(sfd);
|
|
|
|
|
|
|
|
read_end:
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
/* load global settings */
|
|
|
|
if (!viewer_load_global_settings())
|
|
|
|
viewer_default_preferences();
|
|
|
|
|
|
|
|
file_pos = 0;
|
|
|
|
screen_top_ptr = buffer;
|
|
|
|
cpage = 1;
|
|
|
|
cline = 1;
|
|
|
|
bookmark_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->memcpy(&old_prefs, &prefs, sizeof(struct preferences));
|
|
|
|
calc_max_width();
|
|
|
|
|
|
|
|
if (bookmark_count > 1)
|
|
|
|
viewer_select_bookmark(-1);
|
|
|
|
else if (bookmark_count == 1)
|
|
|
|
{
|
|
|
|
int screen_pos;
|
|
|
|
int screen_top;
|
|
|
|
|
|
|
|
screen_pos = bookmarks[0].file_position;
|
|
|
|
screen_top = screen_pos % buffer_size;
|
|
|
|
file_pos = screen_pos - screen_top;
|
|
|
|
screen_top_ptr = buffer + screen_top;
|
|
|
|
cpage = bookmarks[0].page;
|
|
|
|
cline = bookmarks[0].line;
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer_remove_last_read_bookmark();
|
|
|
|
|
|
|
|
check_bom();
|
|
|
|
get_filesize();
|
|
|
|
|
|
|
|
buffer_end = BUFFER_END(); /* Update whenever file_pos changes */
|
|
|
|
|
|
|
|
if (BUFFER_OOB(screen_top_ptr))
|
|
|
|
screen_top_ptr = buffer;
|
|
|
|
|
|
|
|
fill_buffer(file_pos, buffer, buffer_size);
|
|
|
|
if (prefs.scroll_mode == PAGE && cline > 1)
|
|
|
|
viewer_scroll_to_top_line();
|
|
|
|
|
|
|
|
/* remember the current position */
|
|
|
|
start_position = file_pos + screen_top_ptr - buffer;
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-04-08 21:56:03 +00:00
|
|
|
/* load prefs font if it is different than the global settings font */
|
2010-04-07 18:06:47 +00:00
|
|
|
if (rb->strcmp(prefs.font, rb->global_settings->font_file)) {
|
|
|
|
if (!change_font(prefs.font)) {
|
2010-04-09 06:26:33 +00:00
|
|
|
/* fallback by resetting prefs font to the global settings font */
|
|
|
|
rb->memset(prefs.font, 0, MAX_PATH);
|
|
|
|
rb->snprintf(prefs.font, MAX_PATH, "%s",
|
|
|
|
rb->global_settings->font_file);
|
|
|
|
|
|
|
|
if (!change_font(prefs.font))
|
2010-04-08 21:56:03 +00:00
|
|
|
return false;
|
2010-04-07 18:06:47 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
init_need_scrollbar();
|
|
|
|
init_header_and_footer();
|
|
|
|
#endif
|
2010-04-07 18:06:47 +00:00
|
|
|
|
|
|
|
return true;
|
2010-03-17 11:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool copy_bookmark_file(int sfd, int dfd, off_t start, off_t size)
|
|
|
|
{
|
|
|
|
off_t rsize;
|
|
|
|
|
|
|
|
if (rb->lseek(sfd, start, SEEK_SET) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
while (size > 0)
|
|
|
|
{
|
|
|
|
if (size > buffer_size)
|
|
|
|
rsize = buffer_size;
|
|
|
|
else
|
|
|
|
rsize = size;
|
|
|
|
size -= rsize;
|
|
|
|
|
|
|
|
if (rb->read(sfd, buffer, rsize) != rsize ||
|
|
|
|
rb->write(dfd, buffer, rsize) != rsize)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool viewer_save_settings(void)
|
|
|
|
{
|
|
|
|
unsigned char buf[MAX_PATH+2];
|
|
|
|
unsigned int fcount = 0;
|
|
|
|
unsigned int i;
|
|
|
|
int idx;
|
|
|
|
int ofd;
|
|
|
|
int tfd;
|
|
|
|
off_t first_copy_size = 0;
|
|
|
|
off_t second_copy_start_pos = 0;
|
|
|
|
off_t size;
|
|
|
|
|
|
|
|
/* add reading page to bookmarks */
|
|
|
|
idx = viewer_find_bookmark(cpage, cline);
|
|
|
|
if (idx >= 0)
|
|
|
|
bookmarks[idx].flag |= BOOKMARK_LAST;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
viewer_add_bookmark();
|
|
|
|
bookmarks[bookmark_count-1].flag = BOOKMARK_LAST;
|
|
|
|
}
|
2010-04-07 17:04:30 +00:00
|
|
|
|
2010-05-06 17:35:13 +00:00
|
|
|
tfd = rb->open(SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
2010-03-17 11:17:56 +00:00
|
|
|
if (tfd < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ofd = rb->open(SETTINGS_FILE, O_RDWR);
|
|
|
|
if (ofd >= 0)
|
|
|
|
{
|
|
|
|
if ((rb->read(ofd, buf, SETTINGS_H_SIZE+2) != SETTINGS_H_SIZE+2) ||
|
2010-04-11 06:39:37 +00:00
|
|
|
rb->memcmp(buf, SETTINGS_HEADER, SETTINGS_H_SIZE - 1))
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
|
|
|
rb->close(ofd);
|
|
|
|
goto save_err;
|
|
|
|
}
|
2010-04-11 06:39:37 +00:00
|
|
|
|
|
|
|
if (buf[SETTINGS_H_SIZE - 1] != SETTINGS_VERSION)
|
|
|
|
{
|
|
|
|
rb->close(ofd);
|
|
|
|
if (!viewer_convert_settings_file())
|
|
|
|
goto save_err;
|
|
|
|
|
|
|
|
viewer_save_settings();
|
|
|
|
}
|
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
fcount = (buf[SETTINGS_H_SIZE] << 8) | buf[SETTINGS_H_SIZE+1];
|
|
|
|
|
|
|
|
for (i = 0; i < fcount; i++)
|
|
|
|
{
|
|
|
|
if (rb->read(ofd, buf, MAX_PATH+2) != MAX_PATH+2)
|
|
|
|
{
|
|
|
|
rb->close(ofd);
|
|
|
|
goto save_err;
|
|
|
|
}
|
|
|
|
size = (buf[MAX_PATH] << 8) | buf[MAX_PATH+1];
|
|
|
|
if (rb->strcmp(buf, file_name))
|
|
|
|
{
|
|
|
|
if (rb->lseek(ofd, size, SEEK_CUR) < 0)
|
|
|
|
{
|
|
|
|
rb->close(ofd);
|
|
|
|
goto save_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
first_copy_size = rb->lseek(ofd, 0, SEEK_CUR);
|
|
|
|
if (first_copy_size < 0)
|
|
|
|
{
|
|
|
|
rb->close(ofd);
|
|
|
|
goto save_err;
|
|
|
|
}
|
|
|
|
second_copy_start_pos = first_copy_size + size;
|
|
|
|
first_copy_size -= MAX_PATH+2;
|
|
|
|
fcount--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (first_copy_size == 0)
|
|
|
|
first_copy_size = rb->filesize(ofd);
|
|
|
|
|
|
|
|
if (!copy_bookmark_file(ofd, tfd, 0, first_copy_size))
|
|
|
|
{
|
|
|
|
rb->close(ofd);
|
|
|
|
goto save_err;
|
|
|
|
}
|
|
|
|
if (second_copy_start_pos > 0)
|
|
|
|
{
|
|
|
|
if (!copy_bookmark_file(ofd, tfd, second_copy_start_pos,
|
|
|
|
rb->filesize(ofd) - second_copy_start_pos))
|
|
|
|
{
|
|
|
|
rb->close(ofd);
|
|
|
|
goto save_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->close(ofd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-11 06:39:37 +00:00
|
|
|
rb->memcpy(buf, SETTINGS_HEADER, SETTINGS_H_SIZE - 1);
|
|
|
|
buf[SETTINGS_H_SIZE-1] = SETTINGS_VERSION;
|
|
|
|
buf[SETTINGS_H_SIZE ] = 0;
|
2010-03-17 11:17:56 +00:00
|
|
|
buf[SETTINGS_H_SIZE+1] = 0;
|
|
|
|
if (rb->write(tfd, buf, SETTINGS_H_SIZE+2) != SETTINGS_H_SIZE+2)
|
|
|
|
goto save_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy to current read file's bookmarks */
|
|
|
|
rb->memset(buf, 0, MAX_PATH);
|
|
|
|
rb->snprintf(buf, MAX_PATH, "%s", file_name);
|
|
|
|
|
|
|
|
size = PREFERENCES_SIZE + bookmark_count * BOOKMARK_SIZE + 1;
|
|
|
|
buf[MAX_PATH] = size >> 8;
|
|
|
|
buf[MAX_PATH+1] = size;
|
|
|
|
|
|
|
|
if (rb->write(tfd, buf, MAX_PATH+2) != MAX_PATH+2)
|
|
|
|
goto save_err;
|
|
|
|
|
2010-04-11 06:39:37 +00:00
|
|
|
if (!viewer_write_preferences(tfd, &prefs))
|
2010-03-17 11:17:56 +00:00
|
|
|
goto save_err;
|
|
|
|
|
|
|
|
if (!viewer_write_bookmark_infos(tfd))
|
|
|
|
goto save_err;
|
|
|
|
|
|
|
|
if (rb->lseek(tfd, SETTINGS_H_SIZE, SEEK_SET) < 0)
|
|
|
|
goto save_err;
|
|
|
|
|
|
|
|
fcount++;
|
|
|
|
buf[0] = fcount >> 8;
|
|
|
|
buf[1] = fcount;
|
|
|
|
|
|
|
|
if (rb->write(tfd, buf, 2) != 2)
|
|
|
|
goto save_err;
|
|
|
|
|
|
|
|
rb->close(tfd);
|
|
|
|
|
|
|
|
rb->remove(SETTINGS_FILE);
|
|
|
|
rb->rename(SETTINGS_TMP_FILE, SETTINGS_FILE);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
save_err:
|
|
|
|
rb->close(tfd);
|
|
|
|
rb->remove(SETTINGS_TMP_FILE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void viewer_exit(void *parameter)
|
|
|
|
{
|
|
|
|
(void)parameter;
|
|
|
|
|
|
|
|
/* save preference and bookmarks */
|
|
|
|
if (!viewer_save_settings())
|
|
|
|
rb->splash(HZ, "Can't save preference and bookmarks.");
|
|
|
|
|
|
|
|
rb->close(fd);
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-03-17 11:27:29 +00:00
|
|
|
if (rb->strcmp(prefs.font, rb->global_settings->font_file))
|
2010-03-17 11:17:56 +00:00
|
|
|
change_font(rb->global_settings->font_file);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void calc_page(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char *line_begin;
|
|
|
|
unsigned char *line_end;
|
|
|
|
off_t sfp;
|
|
|
|
unsigned char *sstp;
|
|
|
|
|
|
|
|
rb->splash(0, "Calculating page/line number...");
|
|
|
|
|
|
|
|
/* add reading page to bookmarks */
|
|
|
|
viewer_add_last_read_bookmark();
|
|
|
|
|
|
|
|
rb->qsort(bookmarks, bookmark_count, sizeof(struct bookmark_info),
|
|
|
|
bm_comp);
|
|
|
|
|
|
|
|
cpage = 1;
|
|
|
|
cline = 1;
|
|
|
|
file_pos = 0;
|
|
|
|
screen_top_ptr = buffer;
|
|
|
|
buffer_end = BUFFER_END();
|
|
|
|
|
|
|
|
fill_buffer(file_pos, buffer, buffer_size);
|
|
|
|
line_end = line_begin = buffer;
|
|
|
|
|
2010-04-12 21:15:10 +00:00
|
|
|
/* update page and line of all bookmark */
|
2010-03-17 11:17:56 +00:00
|
|
|
for (i = 0; i < bookmark_count; i++)
|
|
|
|
{
|
|
|
|
sfp = bookmarks[i].file_position;
|
|
|
|
sstp = buffer;
|
|
|
|
|
|
|
|
while ((line_begin > sstp || sstp >= line_end) ||
|
|
|
|
(file_pos > sfp || sfp >= file_pos + BUFFER_END() - buffer))
|
|
|
|
{
|
|
|
|
get_next_line_position(&line_begin, &line_end, NULL);
|
|
|
|
if (line_end == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
next_line_ptr = line_end;
|
|
|
|
|
|
|
|
if (sstp == buffer &&
|
|
|
|
file_pos <= sfp && sfp < file_pos + BUFFER_END() - buffer)
|
|
|
|
sstp = sfp - file_pos + buffer;
|
|
|
|
|
|
|
|
increment_current_line();
|
|
|
|
}
|
|
|
|
|
|
|
|
decrement_current_line();
|
|
|
|
bookmarks[i].page = cpage;
|
|
|
|
bookmarks[i].line = cline;
|
|
|
|
bookmarks[i].file_position = file_pos + (line_begin - buffer);
|
|
|
|
increment_current_line();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove reading page's bookmark */
|
|
|
|
for (i = 0; i < bookmark_count; i++)
|
|
|
|
{
|
|
|
|
if (bookmarks[i].flag & BOOKMARK_LAST)
|
|
|
|
{
|
|
|
|
int screen_pos;
|
|
|
|
int screen_top;
|
|
|
|
|
|
|
|
screen_pos = bookmarks[i].file_position;
|
|
|
|
screen_top = screen_pos % buffer_size;
|
|
|
|
file_pos = screen_pos - screen_top;
|
|
|
|
screen_top_ptr = buffer + screen_top;
|
|
|
|
|
|
|
|
cpage = bookmarks[i].page;
|
|
|
|
cline = bookmarks[i].line;
|
|
|
|
bookmarks[i].flag ^= BOOKMARK_LAST;
|
|
|
|
buffer_end = BUFFER_END();
|
|
|
|
|
|
|
|
fill_buffer(file_pos, buffer, buffer_size);
|
|
|
|
|
|
|
|
if (bookmarks[i].flag == 0)
|
|
|
|
viewer_remove_bookmark(i);
|
|
|
|
|
|
|
|
if (prefs.scroll_mode == PAGE && cline > 1)
|
|
|
|
viewer_scroll_to_top_line();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int col_limit(int col)
|
|
|
|
{
|
|
|
|
if (col < 0)
|
2003-07-24 09:47:46 +00:00
|
|
|
col = 0;
|
|
|
|
else
|
2010-04-07 17:11:09 +00:00
|
|
|
if (col >= max_width - draw_columns)
|
2010-03-17 11:17:56 +00:00
|
|
|
col = max_width - draw_columns;
|
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)
|
|
|
|
{
|
2008-12-04 22:00:12 +00:00
|
|
|
static struct opt_items names[NUM_CODEPAGES];
|
|
|
|
int idx;
|
2010-03-17 11:17:56 +00:00
|
|
|
bool res;
|
|
|
|
enum codepages oldenc = prefs.encoding;
|
2008-12-04 22:00:12 +00:00
|
|
|
|
|
|
|
for (idx = 0; idx < NUM_CODEPAGES; idx++)
|
|
|
|
{
|
|
|
|
names[idx].string = rb->get_codepage_name(idx);
|
|
|
|
names[idx].voice_id = -1;
|
|
|
|
}
|
2006-05-11 20:34:37 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
res = rb->set_option("Encoding", &prefs.encoding, INT, names,
|
2006-05-11 20:34:37 +00:00
|
|
|
sizeof(names) / sizeof(names[0]), NULL);
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
/* When prefs.encoding changes into UTF-8 or changes from UTF-8,
|
|
|
|
* filesize (file_size) might change.
|
|
|
|
* In addition, if prefs.encoding is UTF-8, then BOM does not read.
|
|
|
|
*/
|
|
|
|
if (oldenc != prefs.encoding && (oldenc == UTF_8 || prefs.encoding == UTF_8))
|
|
|
|
{
|
|
|
|
check_bom();
|
|
|
|
get_filesize();
|
|
|
|
fill_buffer(file_pos, buffer, buffer_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2006-05-11 20:34:37 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2010-03-17 11:17:56 +00:00
|
|
|
calc_max_width();
|
2006-09-17 14:04:58 +00:00
|
|
|
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);
|
|
|
|
}
|
2010-03-17 11:17:56 +00:00
|
|
|
|
|
|
|
static bool header_setting(void)
|
|
|
|
{
|
|
|
|
int len = (rb->global_settings->statusbar == STATUSBAR_TOP)? 4 : 2;
|
|
|
|
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";
|
|
|
|
names[2].voice_id = -1;
|
|
|
|
names[3].string = "Both";
|
|
|
|
names[3].voice_id = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rb->set_option("Show Header", &prefs.header_mode, INT,
|
|
|
|
names, len, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool footer_setting(void)
|
|
|
|
{
|
|
|
|
int len = (rb->global_settings->statusbar == STATUSBAR_BOTTOM)? 4 : 2;
|
|
|
|
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";
|
|
|
|
names[2].voice_id = -1;
|
|
|
|
names[3].string = "Both";
|
|
|
|
names[3].voice_id = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rb->set_option("Show Footer", &prefs.footer_mode, INT,
|
|
|
|
names, len, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int font_comp(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
struct opt_items *pa;
|
|
|
|
struct opt_items *pb;
|
|
|
|
|
|
|
|
pa = (struct opt_items *)a;
|
|
|
|
pb = (struct opt_items *)b;
|
|
|
|
|
|
|
|
return rb->strcmp(pa->string, pb->string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool font_setting(void)
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *entry;
|
|
|
|
int i = 0;
|
|
|
|
int len;
|
|
|
|
int new_font = 0;
|
|
|
|
int old_font;
|
|
|
|
bool res;
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
dir = rb->opendir(FONT_DIR);
|
|
|
|
if (!dir)
|
|
|
|
{
|
2010-04-07 18:06:47 +00:00
|
|
|
rb->splash(HZ/2, "Font dir is not accessible");
|
2010-03-17 11:17:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
entry = rb->readdir(dir);
|
|
|
|
|
|
|
|
if (entry == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
len = rb->strlen(entry->d_name);
|
|
|
|
if (len < 4 || rb->strcmp(entry->d_name + len-4, ".fnt"))
|
|
|
|
continue;
|
|
|
|
size += len-3;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
|
|
|
|
struct opt_items names[count];
|
|
|
|
unsigned char font_names[size];
|
|
|
|
unsigned char *p = font_names;
|
|
|
|
|
|
|
|
dir = rb->opendir(FONT_DIR);
|
|
|
|
if (!dir)
|
|
|
|
{
|
2010-04-07 18:06:47 +00:00
|
|
|
rb->splash(HZ/2, "Font dir is not accessible");
|
2010-03-17 11:17:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
entry = rb->readdir(dir);
|
|
|
|
|
|
|
|
if (entry == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
len = rb->strlen(entry->d_name);
|
|
|
|
if (len < 4 || rb->strcmp(entry->d_name + len-4, ".fnt"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rb->snprintf(p, len-3, "%s", entry->d_name);
|
|
|
|
names[i].string = p;
|
|
|
|
names[i].voice_id = -1;
|
|
|
|
p += len-3;
|
|
|
|
i++;
|
|
|
|
if (i >= count)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
|
|
|
|
rb->qsort(names, count, sizeof(struct opt_items), font_comp);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (!rb->strcmp(names[i].string, prefs.font))
|
|
|
|
{
|
|
|
|
new_font = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
old_font = new_font;
|
|
|
|
|
|
|
|
res = rb->set_option("Select Font", &new_font, INT,
|
|
|
|
names, count, NULL);
|
|
|
|
|
|
|
|
if (new_font != old_font)
|
|
|
|
{
|
2010-04-08 21:56:03 +00:00
|
|
|
/* load selected font */
|
|
|
|
if (!change_font((unsigned char *)names[new_font].string)) {
|
|
|
|
/* revert by re-loading the preferences font */
|
|
|
|
change_font(prefs.font);
|
2010-04-07 18:06:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-03-17 11:17:56 +00:00
|
|
|
rb->memset(prefs.font, 0, MAX_PATH);
|
|
|
|
rb->snprintf(prefs.font, MAX_PATH, "%s", names[new_font].string);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2010-03-30 17:09:04 +00:00
|
|
|
|
|
|
|
static bool alignment_setting(void)
|
|
|
|
{
|
|
|
|
static const struct opt_items names[] = {
|
|
|
|
{"Left", -1},
|
|
|
|
{"Right", -1},
|
|
|
|
};
|
|
|
|
|
|
|
|
return rb->set_option("Alignment", &prefs.alignment, 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)
|
|
|
|
{
|
2010-04-07 17:04:30 +00:00
|
|
|
return rb->set_int("Auto-scroll Speed", "", UNIT_INT,
|
2006-05-03 23:16:53 +00:00
|
|
|
&prefs.autoscroll_speed, NULL, 1, 1, 10, NULL);
|
|
|
|
}
|
2006-04-04 12:04:15 +00:00
|
|
|
|
2009-06-16 04:25:21 +00:00
|
|
|
MENUITEM_FUNCTION(encoding_item, 0, "Encoding", encoding_setting,
|
|
|
|
NULL, NULL, Icon_NOICON);
|
|
|
|
MENUITEM_FUNCTION(word_wrap_item, 0, "Word Wrap", word_wrap_setting,
|
|
|
|
NULL, NULL, Icon_NOICON);
|
|
|
|
MENUITEM_FUNCTION(line_mode_item, 0, "Line Mode", line_mode_setting,
|
|
|
|
NULL, NULL, Icon_NOICON);
|
|
|
|
MENUITEM_FUNCTION(view_mode_item, 0, "Wide View", view_mode_setting,
|
|
|
|
NULL, NULL, Icon_NOICON);
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-03-30 17:09:04 +00:00
|
|
|
MENUITEM_FUNCTION(alignment_item, 0, "Alignment", alignment_setting,
|
|
|
|
NULL, NULL, Icon_NOICON);
|
2009-06-16 04:25:21 +00:00
|
|
|
MENUITEM_FUNCTION(scrollbar_item, 0, "Show Scrollbar", scrollbar_setting,
|
|
|
|
NULL, NULL, Icon_NOICON);
|
|
|
|
MENUITEM_FUNCTION(page_mode_item, 0, "Overlap Pages", page_mode_setting,
|
|
|
|
NULL, NULL, Icon_NOICON);
|
2010-03-17 11:17:56 +00:00
|
|
|
MENUITEM_FUNCTION(header_item, 0, "Show Header", header_setting,
|
|
|
|
NULL, NULL, Icon_NOICON);
|
|
|
|
MENUITEM_FUNCTION(footer_item, 0, "Show Footer", footer_setting,
|
|
|
|
NULL, NULL, Icon_NOICON);
|
|
|
|
MENUITEM_FUNCTION(font_item, 0, "Font", font_setting,
|
|
|
|
NULL, NULL, Icon_NOICON);
|
2009-06-16 04:25:21 +00:00
|
|
|
#endif
|
|
|
|
MENUITEM_FUNCTION(scroll_mode_item, 0, "Scroll Mode", scroll_mode_setting,
|
|
|
|
NULL, NULL, Icon_NOICON);
|
|
|
|
MENUITEM_FUNCTION(autoscroll_speed_item, 0, "Auto-Scroll Speed",
|
|
|
|
autoscroll_speed_setting, NULL, NULL, Icon_NOICON);
|
|
|
|
MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON,
|
|
|
|
&encoding_item, &word_wrap_item, &line_mode_item, &view_mode_item,
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-03-30 17:09:04 +00:00
|
|
|
&alignment_item, &scrollbar_item, &page_mode_item, &header_item,
|
|
|
|
&footer_item, &font_item,
|
2009-06-16 04:25:21 +00:00
|
|
|
#endif
|
|
|
|
&scroll_mode_item, &autoscroll_speed_item);
|
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
static bool viewer_options_menu(bool is_global)
|
2006-05-03 23:16:53 +00:00
|
|
|
{
|
|
|
|
bool result;
|
2010-03-17 11:17:56 +00:00
|
|
|
struct preferences tmp_prefs;
|
|
|
|
|
|
|
|
rb->memcpy(&tmp_prefs, &prefs, sizeof(struct preferences));
|
|
|
|
|
2009-06-16 04:25:21 +00:00
|
|
|
result = (rb->do_menu(&option_menu, NULL, NULL, false) == MENU_ATTACHED_USB);
|
2006-05-03 23:16:53 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
if (!is_global && rb->memcmp(&tmp_prefs, &prefs, sizeof(struct preferences)))
|
|
|
|
{
|
|
|
|
/* Show-scrollbar mode for current view-width mode */
|
2006-05-01 05:45:18 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-03-17 11:17:56 +00:00
|
|
|
init_need_scrollbar();
|
|
|
|
init_header_and_footer();
|
2006-05-01 05:45:18 +00:00
|
|
|
#endif
|
2010-03-17 11:17:56 +00:00
|
|
|
calc_page();
|
|
|
|
}
|
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 result;
|
2010-03-17 11:17:56 +00:00
|
|
|
|
2009-06-16 04:25:21 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Viewer Menu", NULL,
|
|
|
|
"Return", "Viewer Options",
|
2010-03-17 11:17:56 +00:00
|
|
|
"Show Playback Menu", "Select Bookmark",
|
|
|
|
"Global Settings", "Quit");
|
2006-05-01 05:45:18 +00:00
|
|
|
|
2009-06-16 04:25:21 +00:00
|
|
|
result = rb->do_menu(&menu, NULL, NULL, false);
|
2006-05-01 05:45:18 +00:00
|
|
|
switch (result)
|
|
|
|
{
|
2009-06-16 04:25:21 +00:00
|
|
|
case 0: /* return */
|
2006-05-01 05:45:18 +00:00
|
|
|
break;
|
|
|
|
case 1: /* change settings */
|
2010-03-17 11:17:56 +00:00
|
|
|
done = viewer_options_menu(false);
|
2006-05-01 05:45:18 +00:00
|
|
|
break;
|
|
|
|
case 2: /* playback control */
|
2009-01-16 10:34:40 +00:00
|
|
|
playback_control(NULL);
|
2006-05-01 05:45:18 +00:00
|
|
|
break;
|
2010-03-17 11:17:56 +00:00
|
|
|
case 3: /* select bookmark */
|
|
|
|
viewer_select_bookmark(viewer_add_last_read_bookmark());
|
|
|
|
viewer_remove_last_read_bookmark();
|
|
|
|
fill_buffer(file_pos, buffer, buffer_size);
|
|
|
|
if (prefs.scroll_mode == PAGE && cline > 1)
|
|
|
|
viewer_scroll_to_top_line();
|
|
|
|
break;
|
|
|
|
case 4: /* change global settings */
|
|
|
|
{
|
|
|
|
struct preferences orig_prefs;
|
|
|
|
|
|
|
|
rb->memcpy(&orig_prefs, &prefs, sizeof(struct preferences));
|
|
|
|
if (!viewer_load_global_settings())
|
|
|
|
viewer_default_preferences();
|
|
|
|
done = viewer_options_menu(true);
|
|
|
|
viewer_save_global_settings();
|
|
|
|
rb->memcpy(&prefs, &orig_prefs, sizeof(struct preferences));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5: /* quit */
|
2009-06-16 04:25:21 +00:00
|
|
|
viewer_exit(NULL);
|
|
|
|
done = true;
|
2006-05-01 05:45:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
viewer_draw(col);
|
|
|
|
}
|
2006-04-04 12:04:15 +00:00
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const 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;
|
2010-05-07 19:27:42 +00:00
|
|
|
size_t buf_size;
|
2002-09-30 19:05:03 +00:00
|
|
|
|
2006-05-04 19:53:26 +00:00
|
|
|
old_tick = *rb->current_tick;
|
2003-06-29 16:33:04 +00:00
|
|
|
|
2007-11-23 09:11:11 +00:00
|
|
|
/* get the plugin buffer */
|
2010-05-07 19:27:42 +00:00
|
|
|
buffer = rb->plugin_get_buffer(&buf_size);
|
|
|
|
buffer_size = buf_size;
|
2010-03-17 11:17:56 +00:00
|
|
|
if (buffer_size == 0)
|
|
|
|
{
|
|
|
|
rb->splash(HZ, "buffer does not allocate !!");
|
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
block_size = buffer_size / 3;
|
|
|
|
buffer_size = 3 * block_size;
|
2007-11-23 09:11:11 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-04-07 18:06:47 +00:00
|
|
|
if (!viewer_load_settings()) /* load the preferences and bookmark */
|
|
|
|
return PLUGIN_ERROR;
|
2009-12-18 14:17:28 +00:00
|
|
|
|
2007-09-23 19:15:56 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_backdrop(NULL);
|
|
|
|
#endif
|
2009-12-18 14:17:28 +00:00
|
|
|
|
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))
|
|
|
|
{
|
2010-03-17 11:17:56 +00:00
|
|
|
viewer_scroll_down(true);
|
2003-07-24 09:47:46 +00:00
|
|
|
viewer_draw(col);
|
2006-05-01 05:45:18 +00:00
|
|
|
old_tick = *rb->current_tick;
|
|
|
|
}
|
|
|
|
}
|
2009-12-18 14:17:28 +00:00
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
button = rb->button_get_w_tmo(HZ/10);
|
2010-03-17 11:17:56 +00:00
|
|
|
|
2010-03-20 21:09:01 +00:00
|
|
|
if (prefs.view_mode != WIDE) {
|
|
|
|
/* when not in wide view mode, the SCREEN_LEFT and SCREEN_RIGHT
|
|
|
|
buttons jump to the beginning and end of the file. To stop
|
|
|
|
users doing this by accident, replace non-held occurrences
|
|
|
|
with page up/down instead. */
|
|
|
|
if (button == VIEWER_SCREEN_LEFT)
|
|
|
|
button = VIEWER_PAGE_UP;
|
|
|
|
else if (button == VIEWER_SCREEN_RIGHT)
|
|
|
|
button = VIEWER_PAGE_DOWN;
|
|
|
|
}
|
|
|
|
|
2006-05-01 05:45:18 +00:00
|
|
|
switch (button) {
|
|
|
|
case VIEWER_MENU:
|
2010-02-24 21:47:15 +00:00
|
|
|
#ifdef VIEWER_MENU2
|
2010-02-24 21:38:15 +00:00
|
|
|
case VIEWER_MENU2:
|
2010-02-24 21:47:15 +00:00
|
|
|
#endif
|
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:
|
2010-02-24 21:47:15 +00:00
|
|
|
#ifdef VIEWER_PAGE_UP2
|
|
|
|
case VIEWER_PAGE_UP2:
|
2010-02-24 21:38:15 +00:00
|
|
|
case VIEWER_PAGE_UP2 | BUTTON_REPEAT:
|
2010-02-24 21:47:15 +00:00
|
|
|
#endif
|
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:
|
2010-02-24 21:47:15 +00:00
|
|
|
#ifdef VIEWER_PAGE_DOWN2
|
|
|
|
case VIEWER_PAGE_DOWN2:
|
2010-02-24 21:38:15 +00:00
|
|
|
case VIEWER_PAGE_DOWN2 | BUTTON_REPEAT:
|
2010-02-24 21:47:15 +00:00
|
|
|
#endif
|
2006-05-01 05:45:18 +00:00
|
|
|
if (prefs.scroll_mode == PAGE)
|
|
|
|
{
|
|
|
|
/* Page down */
|
|
|
|
if (next_screen_ptr != NULL)
|
2010-03-17 11:17:56 +00:00
|
|
|
{
|
2006-05-01 05:45:18 +00:00
|
|
|
screen_top_ptr = next_screen_to_draw_ptr;
|
2010-03-17 11:17:56 +00:00
|
|
|
if (cpage < MAX_PAGE)
|
|
|
|
cpage++;
|
|
|
|
}
|
2006-05-01 05:45:18 +00:00
|
|
|
}
|
|
|
|
else
|
2010-03-17 11:17:56 +00:00
|
|
|
viewer_scroll_down(autoscroll);
|
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_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 */
|
2010-04-07 17:04:30 +00:00
|
|
|
col = col_limit(col - draw_columns);
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
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 */
|
2010-04-07 17:04:30 +00:00
|
|
|
col = col_limit(col + draw_columns);
|
2003-07-24 09:47:46 +00:00
|
|
|
}
|
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 */
|
2010-03-17 11:17:56 +00:00
|
|
|
viewer_scroll_down(autoscroll);
|
|
|
|
increment_current_line();
|
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 */
|
2010-04-07 17:04:30 +00:00
|
|
|
col = col_limit(col - glyph_width('o'));
|
2006-07-25 20:49:53 +00:00
|
|
|
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 */
|
2010-04-07 17:04:30 +00:00
|
|
|
col = col_limit(col + glyph_width('o'));
|
2006-07-25 20:49:53 +00:00
|
|
|
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:
|
2010-02-24 21:47:15 +00:00
|
|
|
#ifdef VIEWER_QUIT2
|
2010-02-24 21:38:15 +00:00
|
|
|
case VIEWER_QUIT2:
|
2010-02-24 21:47:15 +00:00
|
|
|
#endif
|
2006-05-01 05:45:18 +00:00
|
|
|
viewer_exit(NULL);
|
|
|
|
done = true;
|
|
|
|
break;
|
2002-10-02 11:37:37 +00:00
|
|
|
|
2010-03-17 11:17:56 +00:00
|
|
|
case VIEWER_BOOKMARK:
|
|
|
|
{
|
|
|
|
int idx = viewer_find_bookmark(cpage, cline);
|
|
|
|
|
|
|
|
if (idx < 0)
|
|
|
|
{
|
|
|
|
if (bookmark_count >= MAX_BOOKMARKS-1)
|
2010-04-12 21:15:10 +00:00
|
|
|
rb->splash(HZ/2, "No more bookmarks");
|
2010-03-17 11:17:56 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
viewer_add_bookmark();
|
2010-04-12 21:15:10 +00:00
|
|
|
rb->splash(HZ/2, "Bookmark added");
|
2010-03-17 11:17:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
viewer_remove_bookmark(idx);
|
2010-04-12 21:15:10 +00:00
|
|
|
rb->splash(HZ/2, "Bookmark removed");
|
2010-03-17 11:17:56 +00:00
|
|
|
}
|
|
|
|
viewer_draw(col);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
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
|
|
|
}
|