text viewer: some modify text viewer's layout and preferences.
authoruchida <uchida@a1c6a512-1295-4272-9138-f99709370657>
Sat, 26 Jun 2010 12:17:01 +0000 (26 12:17 +0000)
committeruchida <uchida@a1c6a512-1295-4272-9138-f99709370657>
Sat, 26 Jun 2010 12:17:01 +0000 (26 12:17 +0000)
- layout: hader, footer and horizontal_scrollbar add padding.
- add member 'statusbar' in tv_preferences.
- delete HD_SBAR/HD_BOTH/FT_SBAR/FT_BOTH.
- deletes the function to check header_mode/footer_mode.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27142 a1c6a512-1295-4272-9138-f99709370657

apps/plugins/text_viewer/tv_display.c
apps/plugins/text_viewer/tv_menu.c
apps/plugins/text_viewer/tv_preferences.c
apps/plugins/text_viewer/tv_preferences.h
apps/plugins/text_viewer/tv_settings.c
apps/plugins/text_viewer/tv_window.c

index 78b5b4b..253bb0b 100644 (file)
  * |statusbar (6)            |
  * +-------------------------+
  *
- * (1) displays when rb->global_settings->statusbar == STATUSBAR_TOP
- *              and  preferences->header_mode is HD_SBAR or HD_BOTH.
- * (2) displays when preferences->header_mode is HD_PATH or HD_BOTH.
+ * (1) displays when rb->global_settings->statusbar == STATUSBAR_TOP.
+ * (2) displays when preferences->header_mode is HD_PATH.
  * (3) displays when preferences->vertical_scrollbar is SB_ON.
  * (4) displays when preferences->horizontal_scrollbar is SB_ON.
- * (5) displays when preferences->footer_mode is FT_PAGE or FT_BOTH.
- * (6) displays when rb->global_settings->statusbar == STATUSBAR_BOTTOM
- *              and  preferences->footer_mode is FT_SBAR or FT_BOTH.
+ * (5) displays when preferences->footer_mode is FT_PAGE.
+ * (6) displays when rb->global_settings->statusbar == STATUSBAR_BOTTOM.
  *
  *
  * when isn't defined HAVE_LCD_BITMAP
@@ -115,7 +113,7 @@ void tv_show_header(void)
 {
     unsigned header_mode = header_mode;
 
-    if (preferences->header_mode == HD_PATH || preferences->header_mode == HD_BOTH)
+    if (preferences->header_mode == HD_PATH)
         display->putsxy(header.x, header.y, preferences->file_name);
 }
 
@@ -124,13 +122,13 @@ void tv_show_footer(const struct tv_screen_pos *pos)
     unsigned char buf[12];
     unsigned footer_mode = preferences->footer_mode;
 
-    if (footer_mode == FT_PAGE || footer_mode == FT_BOTH)
+    if (footer_mode == FT_PAGE)
     {
         if (pos->line == 0)
             rb->snprintf(buf, sizeof(buf), "%d", pos->page + 1);
         else
             rb->snprintf(buf, sizeof(buf), "%d - %d", pos->page + 1, pos->page + 2);
-        display->putsxy(footer.x, footer.y, buf);
+        display->putsxy(footer.x, footer.y + 1, buf);
     }
 }
 
@@ -153,7 +151,7 @@ void tv_show_scrollbar(int window, int col, off_t cur_pos, int size)
         max_shown = min_shown + display_columns;
 
         rb->gui_scrollbar_draw(display,
-                               horizontal_scrollbar.x, horizontal_scrollbar.y,
+                               horizontal_scrollbar.x, horizontal_scrollbar.y + 1,
                                horizontal_scrollbar.w, TV_SCROLLBAR_HEIGHT,
                                items, min_shown, max_shown, HORIZONTAL);
     }
@@ -166,7 +164,7 @@ void tv_show_scrollbar(int window, int col, off_t cur_pos, int size)
 
         rb->gui_scrollbar_draw(display,
                                vertical_scrollbar.x, vertical_scrollbar.y,
-                               TV_SCROLLBAR_WIDTH-1, vertical_scrollbar.h,
+                               TV_SCROLLBAR_WIDTH, vertical_scrollbar.h,
                                items, min_shown, max_shown, VERTICAL);
     }
 }
@@ -236,6 +234,7 @@ void tv_end_display(void)
 
 void tv_clear_display(void)
 {
+    rb->lcd_set_backdrop(NULL);
     display->clear_viewport();
 }
 
@@ -251,22 +250,20 @@ void tv_set_layout(int col_w)
 #endif
 {
 #ifdef HAVE_LCD_BITMAP
-    int scrollbar_width  = (show_scrollbar)?                    TV_SCROLLBAR_WIDTH  : 0;
-    int scrollbar_height = (preferences->horizontal_scrollbar)? TV_SCROLLBAR_HEIGHT : 0;
-    unsigned header_mode = preferences->header_mode;
-    unsigned footer_mode = preferences->footer_mode;
+    int scrollbar_width  = (show_scrollbar)?                    TV_SCROLLBAR_WIDTH  + 1 : 0;
+    int scrollbar_height = (preferences->horizontal_scrollbar)? TV_SCROLLBAR_HEIGHT + 1 : 0;
 
     row_height = preferences->font->height;
 
     header.x = 0;
-    header.y = 0;
+    header.y = 1;
     header.w = vp_info.width;
-    header.h = (header_mode == HD_PATH || header_mode == HD_BOTH)? row_height : 0;
+    header.h = (preferences->header_mode == HD_PATH)? row_height + 1 : 0;
 
     footer.x = 0;
     footer.w = vp_info.width;
-    footer.h = (footer_mode == FT_PAGE || footer_mode == FT_BOTH)? row_height : 0;
-    footer.y = vp_info.height - footer.h;
+    footer.h = (preferences->footer_mode == FT_PAGE)? row_height + 1 : 0;
+    footer.y = vp_info.height - 1 - footer.h;
 
     drawarea.x = scrollbar_width;
     drawarea.y = header.y + header.h;
@@ -312,17 +309,13 @@ void tv_change_viewport(void)
 {
 #ifdef HAVE_LCD_BITMAP
     struct viewport vp;
-    bool show_statusbar = (preferences->header_mode == HD_SBAR ||
-                           preferences->header_mode == HD_BOTH ||
-                           preferences->footer_mode == FT_SBAR ||
-                           preferences->footer_mode == FT_BOTH);
 
     if (is_initialized_vp)
         tv_undo_viewport();
     else
         is_initialized_vp = true;
 
-    rb->viewportmanager_theme_enable(SCREEN_MAIN, show_statusbar, &vp);
+    rb->viewportmanager_theme_enable(SCREEN_MAIN, preferences->statusbar, &vp);
     vp_info = vp;
     vp_info.flags &= ~VP_FLAG_ALIGNMENT_MASK;
 
index c90386a..2e3a26d 100644 (file)
@@ -223,13 +223,10 @@ static bool tv_header_setting(void)
     {
         {"None",       -1},
         {"File path",  -1},
-        {"Status bar", -1},
-        {"Both",       -1},
     };
 
-    int len = (rb->global_settings->statusbar == STATUSBAR_TOP)? 4 : 2;
     return rb->set_option("Show Header", &new_prefs.header_mode, INT,
-                         names, len, NULL);
+                         names, 2, NULL);
 }
 
 static bool tv_footer_setting(void)
@@ -238,13 +235,21 @@ static bool tv_footer_setting(void)
     {
         {"None",       -1},
         {"Page Num",   -1},
-        {"Status bar", -1},
-        {"Both",       -1},
     };
 
-    int len = (rb->global_settings->statusbar == STATUSBAR_BOTTOM)? 4 : 2;
     return rb->set_option("Show Footer", &new_prefs.footer_mode, INT,
-                           names, len, NULL);
+                           names, 2, NULL);
+}
+
+static bool tv_statusbar_setting(void)
+{
+    static const struct opt_items names[] = {
+        {"No",  -1},
+        {"Yes", -1},
+    };
+
+    return rb->set_option("Show Statusbar", &new_prefs.statusbar, BOOL,
+                           names, 2, NULL);
 }
 
 static bool tv_font_setting(void)
@@ -319,6 +324,8 @@ MENUITEM_FUNCTION(header_item, 0, "Show Header", tv_header_setting,
                   NULL, NULL, Icon_NOICON);
 MENUITEM_FUNCTION(footer_item, 0, "Show Footer", tv_footer_setting,
                   NULL, NULL, Icon_NOICON);
+MENUITEM_FUNCTION(statusbar_item, 0, "Show Statusbar", tv_statusbar_setting,
+                  NULL, NULL, Icon_NOICON);
 MENUITEM_FUNCTION(font_item, 0, "Font", tv_font_setting,
                   NULL, NULL, Icon_NOICON);
 #endif
@@ -329,7 +336,7 @@ MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON,
             &encoding_item, &word_wrap_item, &line_mode_item, &windows_item,
             &alignment_item,
 #ifdef HAVE_LCD_BITMAP
-            &header_item, &footer_item, &font_item,
+            &header_item, &footer_item, &font_item, &statusbar_item,
 #endif
             &scroll_menu, &indent_spaces_item);
 
index 72cda9d..a90c72d 100644 (file)
@@ -58,6 +58,7 @@ static void tv_notify_change_preferences(const struct tv_preferences *oldp)
 #ifdef HAVE_LCD_BITMAP
         (oldp->header_mode          != preferences->header_mode)          ||
         (oldp->footer_mode          != preferences->footer_mode)          ||
+        (oldp->statusbar            != preferences->statusbar)            ||
         (rb->strcmp(oldp->font_name, preferences->font_name))             ||
 #endif
         (rb->strcmp(oldp->file_name, preferences->file_name)))
@@ -99,13 +100,15 @@ void tv_set_default_preferences(struct tv_preferences *p)
     p->horizontal_scrollbar = SB_OFF;
     p->vertical_scrollbar = SB_OFF;
 #ifdef HAVE_LCD_BITMAP
-    p->header_mode = HD_BOTH;
-    p->footer_mode = FT_BOTH;
+    p->header_mode = HD_PATH;
+    p->footer_mode = FT_PAGE;
+    p->statusbar   = true;
     rb->strlcpy(p->font_name, rb->global_settings->font_file, MAX_PATH);
     p->font = rb->font_get(FONT_UI);
 #else
     p->header_mode = HD_NONE;
     p->footer_mode = FT_NONE;
+    p->statusbar   = false;
 #endif
     p->autoscroll_speed = 1;
     p->narrow_mode = NM_PAGE;
index ee861ee..d1ba7f2 100644 (file)
@@ -59,8 +59,6 @@ enum {
 enum {
     HD_NONE = 0,
     HD_PATH,
-    HD_SBAR,
-    HD_BOTH,
 };
 
 /* footer_mode */
@@ -68,8 +66,6 @@ enum {
 
     FT_NONE = 0,
     FT_PAGE,
-    FT_SBAR,
-    FT_BOTH,
 };
 
 /* horizontal_scroll_mode */
@@ -114,6 +110,8 @@ struct tv_preferences {
 
     unsigned indent_spaces;
 
+    bool statusbar;
+
 #ifdef HAVE_LCD_BITMAP
     unsigned char font_name[MAX_PATH];
     struct font *font;
index 93f16b5..56c0bbe 100644 (file)
  * vertical_scrollbar     1
  * (unused)               1 (for compatibility)
  * page_mode              1
- * page_number_mode       1
- * title_mode             1
+ * header_mode            1
+ * footer_mode            1
  * scroll_mode            1
  * autoscroll_speed       1
  * horizontal_scrollbar   1
  * horizontal_scroll_mode 1
  * narrow_mode            1
  * indent_spaces          1
- * (reserved)             12
+ * statusbar              1
+ * (reserved)             11
  * font name              MAX_PATH
  */
 
@@ -58,7 +59,7 @@
 #define TV_GLOBAL_SETTINGS_FILE          VIEWERS_DIR "/tv_global.dat"
 
 #define TV_GLOBAL_SETTINGS_HEADER        "\x54\x56\x47\x53" /* "TVGS" */
-#define TV_GLOBAL_SETTINGS_VERSION       0x37
+#define TV_GLOBAL_SETTINGS_VERSION       0x38
 #define TV_GLOBAL_SETTINGS_HEADER_SIZE   5
 #define TV_GLOBAL_SETTINGS_FIRST_VERSION 0x31
 
@@ -92,7 +93,8 @@
  *     horizontal_scroll_mode 1
  *     narrow_mode            1
  *     indent_spaces          1
- *     (reserved)             12
+ *     statusbar              1
+ *     (reserved)             11
  *     font name              MAX_PATH
  *   bookmark count           1
  *   [1st bookmark]
 #define TV_SETTINGS_TMP_FILE      VIEWERS_DIR "/tv_file.tmp"
 
 #define TV_SETTINGS_HEADER        "\x54\x56\x53" /* "TVS" */
-#define TV_SETTINGS_VERSION       0x38
+#define TV_SETTINGS_VERSION       0x39
 #define TV_SETTINGS_HEADER_SIZE   4
 #define TV_SETTINGS_FIRST_VERSION 0x32
 
@@ -156,8 +158,34 @@ static bool tv_read_preferences(int pfd, int version, struct tv_preferences *pre
     /* skip need_scrollbar */
     p++;
     prefs->page_mode            = *p++;
-    prefs->header_mode          = *p++;
-    prefs->footer_mode          = *p++;
+
+    if (version < 7)
+    {
+        prefs->statusbar   = false;
+        if (*p > 1)
+        {
+            prefs->header_mode = (*p & 1);
+            prefs->statusbar   = true;
+        }
+        else
+            prefs->header_mode = *p;
+
+        if (*(++p) > 1)
+        {
+            prefs->footer_mode = (*p & 1);
+            prefs->statusbar   = true;
+        }
+        else
+            prefs->footer_mode = *p;
+
+        p++;
+    }
+    else
+    {
+        prefs->header_mode = *p++;
+        prefs->footer_mode = *p++;
+    }
+
     prefs->vertical_scroll_mode = *p++;
     prefs->autoscroll_speed     = *p++;
 
@@ -181,6 +209,9 @@ static bool tv_read_preferences(int pfd, int version, struct tv_preferences *pre
     else
         prefs->indent_spaces = 2;
 
+    if (version > 6)
+        prefs->statusbar = (*p++ != 0);
+
 #ifdef HAVE_LCD_BITMAP
     rb->memcpy(prefs->font_name, buf + read_size - MAX_PATH, MAX_PATH);
 
@@ -212,6 +243,7 @@ static bool tv_write_preferences(int pfd, const struct tv_preferences *prefs)
     *p++ = prefs->horizontal_scroll_mode;
     *p++ = prefs->narrow_mode;
     *p++ = prefs->indent_spaces;
+    *p++ = prefs->statusbar;
 
 #ifdef HAVE_LCD_BITMAP
     rb->memcpy(buf + 28, prefs->font_name, MAX_PATH);
index df3951a..16be884 100644 (file)
@@ -52,40 +52,6 @@ static bool tv_set_font(const unsigned char *font)
     }
     return true;
 }
-
-static bool tv_check_header_and_footer(struct tv_preferences *new_prefs)
-{
-    bool change_prefs = false;
-
-    if (rb->global_settings->statusbar != STATUSBAR_TOP)
-    {
-        if (new_prefs->header_mode == HD_SBAR)
-        {
-            new_prefs->header_mode = HD_NONE;
-            change_prefs = true;
-        }
-        else if (new_prefs->header_mode == HD_BOTH)
-        {
-            new_prefs->header_mode = HD_PATH;
-            change_prefs = true;
-        }
-    }
-    if (rb->global_settings->statusbar != STATUSBAR_BOTTOM)
-    {
-        if (new_prefs->footer_mode == FT_SBAR)
-        {
-            new_prefs->footer_mode = FT_NONE;
-            change_prefs = true;
-        }
-        else if (new_prefs->footer_mode == FT_BOTH)
-        {
-            new_prefs->footer_mode = FT_PAGE;
-            change_prefs = true;
-        }
-    }
-
-    return change_prefs;
-}
 #endif
 
 static void tv_show_bookmarks(const struct tv_screen_pos *top_pos)
@@ -177,7 +143,6 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
 #else
     static bool font_changing = false;
     const unsigned char *font_str;
-    bool change_prefs = false;
     bool need_vertical_scrollbar;
     struct tv_preferences new_prefs;
     tv_copy_preferences(&new_prefs);
@@ -191,16 +156,11 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
         if (!tv_set_font(preferences->font_name))
         {
             rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
-            change_prefs = true;
+            tv_set_preferences(&new_prefs);
+            return;
         }
     }
 
-    if (tv_check_header_and_footer(&new_prefs) || change_prefs)
-    {
-        tv_set_preferences(&new_prefs);
-        return;
-    }
-
     font_changing = false;
 #endif