Browse Source

Viewer: use WRect to hold position and size of various areas.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 2 years ago
parent
commit
2759d080cf
8 changed files with 115 additions and 140 deletions
  1. 4 4
      src/viewer/actions_cmd.c
  2. 24 30
      src/viewer/ascii.c
  3. 42 47
      src/viewer/display.c
  4. 21 23
      src/viewer/hex.c
  5. 6 15
      src/viewer/internal.h
  6. 2 4
      src/viewer/lib.c
  7. 9 8
      src/viewer/mcviewer.c
  8. 7 9
      src/viewer/move.c

+ 4 - 4
src/viewer/actions_cmd.c

@@ -510,16 +510,16 @@ mcview_execute_cmd (WView * view, long command)
         mcview_move_down (view, 1);
         break;
     case CK_HalfPageUp:
-        mcview_move_up (view, (view->data_area.height + 1) / 2);
+        mcview_move_up (view, (view->data_area.lines + 1) / 2);
         break;
     case CK_HalfPageDown:
-        mcview_move_down (view, (view->data_area.height + 1) / 2);
+        mcview_move_down (view, (view->data_area.lines + 1) / 2);
         break;
     case CK_PageUp:
-        mcview_move_up (view, view->data_area.height);
+        mcview_move_up (view, view->data_area.lines);
         break;
     case CK_PageDown:
-        mcview_move_down (view, view->data_area.height);
+        mcview_move_down (view, view->data_area.lines);
         break;
     case CK_Top:
         mcview_moveto_top (view);

+ 24 - 30
src/viewer/ascii.c

@@ -14,7 +14,7 @@
    Pavel Machek, 1998
    Roland Illig <roland.illig@gmx.de>, 2004, 2005
    Slava Zanko <slavazanko@google.com>, 2009
-   Andrew Borodin <aborodin@vmail.ru>, 2009-2014
+   Andrew Borodin <aborodin@vmail.ru>, 2009-2022
    Ilia Maslakov <il.smind@gmail.com>, 2009
    Rewritten almost from scratch by:
    Egmont Koblinger <egmont@gmail.com>, 2014
@@ -573,12 +573,9 @@ static int
 mcview_display_line (WView * view, mcview_state_machine_t * state, int row,
                      gboolean * paragraph_ended, off_t * linewidth)
 {
-    const screen_dimen left = view->data_area.left;
-    const screen_dimen top = view->data_area.top;
-    const screen_dimen width = view->data_area.width;
-    const screen_dimen height = view->data_area.height;
+    const WRect *r = &view->data_area;
     off_t dpy_text_column = view->mode_flags.wrap ? 0 : view->dpy_text_column;
-    screen_dimen col = 0;
+    int col = 0;
     int cs[1 + MAX_COMBINING_CHARS];
     char str[(1 + MAX_COMBINING_CHARS) * UTF8_CHAR_LEN + 1];
     int i, j;
@@ -586,7 +583,7 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row,
     if (paragraph_ended != NULL)
         *paragraph_ended = TRUE;
 
-    if (!view->mode_flags.wrap && (row < 0 || row >= (int) height) && linewidth == NULL)
+    if (!view->mode_flags.wrap && (row < 0 || row >= r->lines) && linewidth == NULL)
     {
         /* Optimization: Fast forward to the end of the line, rather than carefully
          * parsing and then not actually displaying it. */
@@ -655,7 +652,7 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row,
         /* In wrap mode only: We're done with this row if the character sequence wouldn't fit.
          * Except if at the first column, because then it wouldn't fit in the next row either.
          * In this extreme case let the unwrapped code below do its best to display it. */
-        if (view->mode_flags.wrap && (off_t) col + charwidth > dpy_text_column + (off_t) width
+        if (view->mode_flags.wrap && (off_t) col + charwidth > dpy_text_column + (off_t) r->cols
             && col > 0)
         {
             *state = state_saved;
@@ -667,14 +664,14 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row,
         }
 
         /* Display, unless outside of the viewport. */
-        if (row >= 0 && row < (int) height)
+        if (row >= 0 && row < r->lines)
         {
             if ((off_t) col >= dpy_text_column &&
-                (off_t) col + charwidth <= dpy_text_column + (off_t) width)
+                (off_t) col + charwidth <= dpy_text_column + (off_t) r->cols)
             {
                 /* The combining character sequence fits entirely in the viewport. Print it. */
                 tty_setcolor (color);
-                widget_gotoyx (view, top + row, left + ((off_t) col - dpy_text_column));
+                widget_gotoyx (view, r->y + row, r->x + ((off_t) col - dpy_text_column));
                 if (cs[0] == '\t')
                 {
                     for (i = 0; i < charwidth; i++)
@@ -700,22 +697,22 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row,
                  * or spaces with the correct attributes for partial Tabs. */
                 tty_setcolor (color);
                 for (i = dpy_text_column;
-                     i < (off_t) col + charwidth && i < dpy_text_column + (off_t) width; i++)
+                     i < (off_t) col + charwidth && i < dpy_text_column + (off_t) r->cols; i++)
                 {
-                    widget_gotoyx (view, top + row, left + (i - dpy_text_column));
+                    widget_gotoyx (view, r->y + row, r->x + (i - dpy_text_column));
                     tty_print_anychar ((cs[0] == '\t') ? ' ' : PARTIAL_CJK_AT_LEFT_MARGIN);
                 }
             }
-            else if ((off_t) col < dpy_text_column + (off_t) width &&
-                     (off_t) col + charwidth > dpy_text_column + (off_t) width)
+            else if ((off_t) col < dpy_text_column + (off_t) r->cols &&
+                     (off_t) col + charwidth > dpy_text_column + (off_t) r->cols)
             {
                 /* The combining character sequence would cross the right edge of the viewport
                  * and we're not wrapping. Print replacement character(s),
                  * or spaces with the correct attributes for partial Tabs. */
                 tty_setcolor (color);
-                for (i = col; i < dpy_text_column + (off_t) width; i++)
+                for (i = col; i < dpy_text_column + (off_t) r->cols; i++)
                 {
-                    widget_gotoyx (view, top + row, left + (i - dpy_text_column));
+                    widget_gotoyx (view, r->y + row, r->x + (i - dpy_text_column));
                     tty_print_anychar ((cs[0] == '\t') ? ' ' : PARTIAL_CJK_AT_RIGHT_MARGIN);
                 }
             }
@@ -724,7 +721,7 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row,
         col += charwidth;
         state->unwrapped_column += charwidth;
 
-        if (!view->mode_flags.wrap && (off_t) col >= dpy_text_column + (off_t) width
+        if (!view->mode_flags.wrap && (off_t) col >= dpy_text_column + (off_t) r->cols
             && linewidth == NULL)
         {
             /* Optimization: Fast forward to the end of the line, rather than carefully
@@ -767,7 +764,6 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row,
 static int
 mcview_display_paragraph (WView * view, mcview_state_machine_t * state, int row)
 {
-    const screen_dimen height = view->data_area.height;
     int lines = 0;
 
     while (TRUE)
@@ -778,11 +774,11 @@ mcview_display_paragraph (WView * view, mcview_state_machine_t * state, int row)
         if (paragraph_ended)
             return lines;
 
-        if (row < (int) height)
+        if (row < view->data_area.lines)
         {
             row++;
             /* stop if bottom of screen reached */
-            if (row >= (int) height)
+            if (row >= view->data_area.lines)
                 return lines;
         }
     }
@@ -848,9 +844,7 @@ mcview_wrap_fixup (WView * view)
 void
 mcview_display_text (WView * view)
 {
-    const screen_dimen left = view->data_area.left;
-    const screen_dimen top = view->data_area.top;
-    const screen_dimen height = view->data_area.height;
+    const WRect *r = &view->data_area;
     int row;
     mcview_state_machine_t state;
     gboolean again;
@@ -872,7 +866,7 @@ mcview_display_text (WView * view)
             state = view->dpy_state_top;
         }
 
-        for (row = 0; row < (int) height; row += n)
+        for (row = 0; row < r->lines; row += n)
         {
             n = mcview_display_paragraph (view, &state, row);
             if (n == 0)
@@ -884,7 +878,7 @@ mcview_display_text (WView * view)
                  * charset change or enabling nroff. */
                 if ((view->mode_flags.wrap ? view->dpy_state_top.offset : view->dpy_start) > 0)
                 {
-                    mcview_ascii_move_up (view, height - row);
+                    mcview_ascii_move_up (view, r->lines - row);
                     again = TRUE;
                 }
                 break;
@@ -898,9 +892,9 @@ mcview_display_text (WView * view)
 
     tty_setcolor (VIEW_NORMAL_COLOR);
     if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0')
-        while (row < (int) height)
+        while (row < r->lines)
         {
-            widget_gotoyx (view, top + row, left);
+            widget_gotoyx (view, r->y + row, r->x);
             /* TODO: should make it no wider than the viewport */
             tty_print_string (mcview_show_eof);
             row++;
@@ -1002,7 +996,7 @@ mcview_ascii_move_up (WView * view, off_t lines)
              * Normally we'd jump to the next paragraph and reset paragraph_skip_lines. But for
              * walking backwards this is exactly what we need. */
             view->dpy_paragraph_skip_lines =
-                mcview_display_paragraph (view, &view->dpy_state_top, view->data_area.height);
+                mcview_display_paragraph (view, &view->dpy_state_top, view->data_area.lines);
             view->force_max = -1;
         }
 
@@ -1038,7 +1032,7 @@ mcview_ascii_moveto_eol (WView * view)
         /* Get the width of the topmost paragraph. */
         mcview_state_machine_init (&state, view->dpy_start);
         mcview_display_line (view, &state, -1, NULL, &linewidth);
-        view->dpy_text_column = DOZ (linewidth, (off_t) view->data_area.width);
+        view->dpy_text_column = DOZ (linewidth, (off_t) view->data_area.cols);
     }
 }
 

+ 42 - 47
src/viewer/display.c

@@ -132,9 +132,10 @@ mcview_display_percent (WView * view, off_t p)
     percent = mcview_calc_percent (view, p);
     if (percent >= 0)
     {
-        const screen_dimen top = view->status_area.top;
-        const screen_dimen right = view->status_area.left + view->status_area.width;
+        int top = view->status_area.y;
+        int right;
 
+        right = view->status_area.x + view->status_area.cols;
         widget_gotoyx (view, top, right - 4);
         tty_printf ("%3d%%", percent);
         /* avoid cursor wrapping in NCurses-base MC */
@@ -147,26 +148,23 @@ mcview_display_percent (WView * view, off_t p)
 static void
 mcview_display_status (WView * view)
 {
-    const screen_dimen top = view->status_area.top;
-    const screen_dimen left = view->status_area.left;
-    const screen_dimen width = view->status_area.width;
-    const screen_dimen height = view->status_area.height;
+    const WRect *r = &view->status_area;
     const char *file_label;
 
-    if (height < 1)
+    if (r->lines < 1)
         return;
 
     tty_setcolor (STATUSBAR_COLOR);
-    tty_draw_hline (WIDGET (view)->rect.y + top, WIDGET (view)->rect.x + left, ' ', width);
+    tty_draw_hline (WIDGET (view)->rect.y + r->y, WIDGET (view)->rect.x + r->x, ' ', r->cols);
 
     file_label =
         view->filename_vpath != NULL ?
         vfs_path_get_last_path_str (view->filename_vpath) : view->command != NULL ?
         view->command : "";
 
-    if (width > 40)
+    if (r->cols > 40)
     {
-        widget_gotoyx (view, top, width - 32);
+        widget_gotoyx (view, r->y, r->cols - 32);
         if (view->mode_flags.hex)
             tty_printf ("0x%08" PRIxMAX, (uintmax_t) view->hex_cursor);
         else
@@ -184,12 +182,12 @@ mcview_display_status (WView * view)
                         "");
         }
     }
-    widget_gotoyx (view, top, left);
-    if (width > 40)
-        tty_print_string (str_fit_to_term (file_label, width - 34, J_LEFT_FIT));
+    widget_gotoyx (view, r->y, r->x);
+    if (r->cols > 40)
+        tty_print_string (str_fit_to_term (file_label, r->cols - 34, J_LEFT_FIT));
     else
-        tty_print_string (str_fit_to_term (file_label, width - 5, J_LEFT_FIT));
-    if (width > 26)
+        tty_print_string (str_fit_to_term (file_label, r->cols - 5, J_LEFT_FIT));
+    if (r->cols > 26)
         mcview_display_percent (view, view->mode_flags.hex ? view->hex_cursor : view->dpy_end);
 }
 
@@ -258,18 +256,18 @@ mcview_display (WView * view)
 void
 mcview_compute_areas (WView * view)
 {
-    struct area view_area;
-    screen_dimen height, rest, y;
+    WRect view_area;
+    int height, rest, y;
 
     /* The viewer is surrounded by a frame of size view->dpy_frame_size.
      * Inside that frame, there are: The status line (at the top),
      * the data area and an optional ruler, which is shown above or
      * below the data area. */
 
-    view_area.top = view->dpy_frame_size;
-    view_area.left = view->dpy_frame_size;
-    view_area.height = DOZ ((screen_dimen) WIDGET (view)->rect.lines, 2 * view->dpy_frame_size);
-    view_area.width = DOZ ((screen_dimen) WIDGET (view)->rect.cols, 2 * view->dpy_frame_size);
+    view_area.y = view->dpy_frame_size;
+    view_area.x = view->dpy_frame_size;
+    view_area.lines = DOZ (WIDGET (view)->rect.lines, 2 * view->dpy_frame_size);
+    view_area.cols = DOZ (WIDGET (view)->rect.cols, 2 * view->dpy_frame_size);
 
     /* Most coordinates of the areas equal those of the whole viewer */
     view->status_area = view_area;
@@ -277,36 +275,36 @@ mcview_compute_areas (WView * view)
     view->data_area = view_area;
 
     /* Compute the heights of the areas */
-    rest = view_area.height;
+    rest = view_area.lines;
 
     height = MIN (rest, 1);
-    view->status_area.height = height;
+    view->status_area.lines = height;
     rest -= height;
 
     height = (ruler == RULER_NONE || view->mode_flags.hex) ? 0 : 2;
     height = MIN (rest, height);
-    view->ruler_area.height = height;
+    view->ruler_area.lines = height;
     rest -= height;
 
-    view->data_area.height = rest;
+    view->data_area.lines = rest;
 
     /* Compute the position of the areas */
-    y = view_area.top;
+    y = view_area.y;
 
-    view->status_area.top = y;
-    y += view->status_area.height;
+    view->status_area.y = y;
+    y += view->status_area.lines;
 
     if (ruler == RULER_TOP)
     {
-        view->ruler_area.top = y;
-        y += view->ruler_area.height;
+        view->ruler_area.y = y;
+        y += view->ruler_area.lines;
     }
 
-    view->data_area.top = y;
-    y += view->data_area.height;
+    view->data_area.y = y;
+    y += view->data_area.lines;
 
     if (ruler == RULER_BOTTOM)
-        view->ruler_area.top = y;
+        view->ruler_area.y = y;
 }
 
 /* --------------------------------------------------------------------------------------------- */
@@ -314,7 +312,7 @@ mcview_compute_areas (WView * view)
 void
 mcview_update_bytes_per_line (WView * view)
 {
-    const screen_dimen cols = view->data_area.width;
+    int cols = view->data_area.cols;
     int bytes;
 
     if (cols < 9 + 17)
@@ -366,36 +364,33 @@ void
 mcview_display_ruler (WView * view)
 {
     static const char ruler_chars[] = "|----*----";
-    const screen_dimen top = view->ruler_area.top;
-    const screen_dimen left = view->ruler_area.left;
-    const screen_dimen width = view->ruler_area.width;
-    const screen_dimen height = view->ruler_area.height;
-    const screen_dimen line_row = (ruler == RULER_TOP) ? 0 : 1;
-    const screen_dimen nums_row = (ruler == RULER_TOP) ? 1 : 0;
+    const WRect *r = &view->ruler_area;
+    const int line_row = (ruler == RULER_TOP) ? 0 : 1;
+    const int nums_row = (ruler == RULER_TOP) ? 1 : 0;
 
     char r_buff[10];
     off_t cl;
-    screen_dimen c;
+    int c;
 
-    if (ruler == RULER_NONE || height < 1)
+    if (ruler == RULER_NONE || r->lines < 1)
         return;
 
     tty_setcolor (VIEW_BOLD_COLOR);
-    for (c = 0; c < width; c++)
+    for (c = 0; c < r->cols; c++)
     {
         cl = view->dpy_text_column + c;
-        if (line_row < height)
+        if (line_row < r->lines)
         {
-            widget_gotoyx (view, top + line_row, left + c);
+            widget_gotoyx (view, r->y + line_row, r->x + c);
             tty_print_char (ruler_chars[cl % 10]);
         }
 
         if ((cl != 0) && (cl % 10) == 0)
         {
             g_snprintf (r_buff, sizeof (r_buff), "%" PRIuMAX, (uintmax_t) cl);
-            if (nums_row < height)
+            if (nums_row < r->lines)
             {
-                widget_gotoyx (view, top + nums_row, left + c - 1);
+                widget_gotoyx (view, r->y + nums_row, r->x + c - 1);
                 tty_print_string (r_buff);
             }
         }

+ 21 - 23
src/viewer/hex.c

@@ -14,7 +14,7 @@
    Pavel Machek, 1998
    Roland Illig <roland.illig@gmx.de>, 2004, 2005
    Slava Zanko <slavazanko@google.com>, 2009, 2013
-   Andrew Borodin <aborodin@vmail.ru>, 2009
+   Andrew Borodin <aborodin@vmail.ru>, 2009-2022
    Ilia Maslakov <il.smind@gmail.com>, 2009
 
    This file is part of the Midnight Commander.
@@ -96,21 +96,17 @@ mcview_hex_calculate_boldflag (WView * view, off_t from, struct hexedit_change_n
 void
 mcview_display_hex (WView * view)
 {
-    const screen_dimen top = view->data_area.top;
-    const screen_dimen left = view->data_area.left;
-    const screen_dimen height = view->data_area.height;
-    const screen_dimen width = view->data_area.width;
-    const int ngroups = view->bytes_per_line / 4;
+    const WRect *r = &view->data_area;
+    int ngroups = view->bytes_per_line / 4;
     /* 8 characters are used for the file offset, and every hex group
      * takes 13 characters. Starting at width of 80 columns, the groups
      * are separated by an extra vertical line. Starting at width of 81,
      * there is an extra space before the text column. There is always a
      * mostly empty column on the right, to allow overflowing CJKs.
      */
-    const screen_dimen text_start = 8 + 13 * ngroups +
-        ((width < 80) ? 0 : (width == 80) ? (ngroups - 1) : (ngroups - 1 + 1));
+    int text_start;
 
-    int row;
+    int row = 0;
     off_t from;
     mark_t boldflag_byte = MARK_NORMAL;
     mark_t boldflag_char = MARK_NORMAL;
@@ -123,12 +119,14 @@ mcview_display_hex (WView * view)
 
     char hex_buff[10];          /* A temporary buffer for sprintf and mvwaddstr */
 
+    text_start = 8 + 13 * ngroups +
+        ((r->cols < 80) ? 0 : (r->cols == 80) ? (ngroups - 1) : (ngroups - 1 + 1));
+
     mcview_display_clean (view);
 
     /* Find the first displayable changed byte */
     /* In UTF-8 mode, go back by 1 or maybe 2 lines to handle continuation bytes properly. */
     from = view->dpy_start;
-    row = 0;
 #ifdef HAVE_CHARSET
     if (view->utf8)
     {
@@ -149,20 +147,20 @@ mcview_display_hex (WView * view)
         curr = curr->next;
     }
 
-    for (; mcview_get_byte (view, from, NULL) && row < (int) height; row++)
+    for (; mcview_get_byte (view, from, NULL) && row < r->lines; row++)
     {
-        screen_dimen col = 0;
+        int col = 0;
         int bytes;              /* Number of bytes already printed on the line */
 
         /* Print the hex offset */
         if (row >= 0)
         {
-            size_t i;
+            int i;
 
             g_snprintf (hex_buff, sizeof (hex_buff), "%08" PRIXMAX " ", (uintmax_t) from);
-            widget_gotoyx (view, top + row, left);
+            widget_gotoyx (view, r->y + row, r->x);
             tty_setcolor (VIEW_BOLD_COLOR);
-            for (i = 0; col < width && hex_buff[i] != '\0'; col++, i++)
+            for (i = 0; col < r->cols && hex_buff[i] != '\0'; col++, i++)
                 tty_print_char (hex_buff[i]);
             tty_setcolor (VIEW_NORMAL_COLOR);
         }
@@ -276,13 +274,13 @@ mcview_display_hex (WView * view)
                           view->hexview_in_text ? VIEW_SELECTED_COLOR : VIEW_UNDERLINED_COLOR);
 
             /* Print the hex number */
-            widget_gotoyx (view, top + row, left + col);
-            if (col < width)
+            widget_gotoyx (view, r->y + row, r->x + col);
+            if (col < r->cols)
             {
                 tty_print_char (hex_char[c / 16]);
                 col += 1;
             }
-            if (col < width)
+            if (col < r->cols)
             {
                 tty_print_char (hex_char[c % 16]);
                 col += 1;
@@ -292,7 +290,7 @@ mcview_display_hex (WView * view)
             tty_setcolor (VIEW_NORMAL_COLOR);
             if (bytes != view->bytes_per_line - 1)
             {
-                if (col < width)
+                if (col < r->cols)
                 {
                     tty_print_char (' ');
                     col += 1;
@@ -301,12 +299,12 @@ mcview_display_hex (WView * view)
                 /* After every four bytes, print a group separator */
                 if (bytes % 4 == 3)
                 {
-                    if (view->data_area.width >= 80 && col < width)
+                    if (view->data_area.cols >= 80 && col < r->cols)
                     {
                         tty_print_one_vline (TRUE);
                         col += 1;
                     }
-                    if (col < width)
+                    if (col < r->cols)
                     {
                         tty_print_char (' ');
                         col += 1;
@@ -347,9 +345,9 @@ mcview_display_hex (WView * view)
             }
 
             /* Print corresponding character on the text side */
-            if (text_start + bytes < width)
+            if (text_start + bytes < r->cols)
             {
-                widget_gotoyx (view, top + row, left + text_start + bytes);
+                widget_gotoyx (view, r->y + row, r->x + text_start + bytes);
 #ifdef HAVE_CHARSET
                 if (view->utf8)
                     tty_print_anychar (ch);

+ 6 - 15
src/viewer/internal.h

@@ -24,9 +24,6 @@
 
 typedef unsigned char byte;
 
-/* A width or height on the screen */
-typedef unsigned int screen_dimen;
-
 /*** enums ***************************************************************************************/
 
 /* data sources of the view */
@@ -62,12 +59,6 @@ struct hexedit_change_node
     byte value;
 };
 
-struct area
-{
-    screen_dimen top, left;
-    screen_dimen height, width;
-};
-
 /* A cache entry for mapping offsets into line/column pairs and vice versa.
  * cc_offset, cc_line, and cc_column are the 0-based values of the offset,
  * line and column of that cache entry. cc_nroff_column is the column
@@ -149,7 +140,7 @@ struct WView
     GPtrArray *coord_cache;     /* Cache for mapping offsets to cursor positions */
 
     /* Display information */
-    screen_dimen dpy_frame_size;        /* Size of the frame surrounding the real viewer */
+    int dpy_frame_size;         /* Size of the frame surrounding the real viewer */
     off_t dpy_start;            /* Offset of the displayed data (start of the paragraph in non-hex mode) */
     off_t dpy_end;              /* Offset after the displayed data */
     off_t dpy_paragraph_skip_lines;     /* Extra lines to skip in wrap mode */
@@ -158,12 +149,12 @@ struct WView
     gboolean dpy_wrap_dirty;    /* dpy_state_top needs to be recomputed */
     off_t dpy_text_column;      /* Number of skipped columns in non-wrap
                                  * text mode */
-    screen_dimen cursor_col;    /* Cursor column */
-    screen_dimen cursor_row;    /* Cursor row */
+    int cursor_col;             /* Cursor column */
+    int cursor_row;             /* Cursor row */
     struct hexedit_change_node *change_list;    /* Linked list of changes */
-    struct area status_area;    /* Where the status line is displayed */
-    struct area ruler_area;     /* Where the ruler is displayed */
-    struct area data_area;      /* Where the data is displayed */
+    WRect status_area;          /* Where the status line is displayed */
+    WRect ruler_area;           /* Where the ruler is displayed */
+    WRect data_area;            /* Where the data is displayed */
 
     ssize_t force_max;          /* Force a max offset, or -1 */
 

+ 2 - 4
src/viewer/lib.c

@@ -14,7 +14,7 @@
    Pavel Machek, 1998
    Roland Illig <roland.illig@gmx.de>, 2004, 2005
    Slava Zanko <slavazanko@google.com>, 2009, 2013
-   Andrew Borodin <aborodin@vmail.ru>, 2009, 2013, 2014
+   Andrew Borodin <aborodin@vmail.ru>, 2009-2022
    Ilia Maslakov <il.smind@gmail.com>, 2009
 
    This file is part of the Midnight Commander.
@@ -398,12 +398,10 @@ mcview_get_title (const WDialog * h, size_t len)
 int
 mcview_calc_percent (WView * view, off_t p)
 {
-    const screen_dimen right = view->status_area.left + view->status_area.width;
-    const screen_dimen height = view->status_area.height;
     off_t filesize;
     int percent;
 
-    if (height < 1 || right < 4)
+    if (view->status_area.cols < 1 || (view->status_area.x + view->status_area.cols) < 4)
         return (-1);
     if (mcview_may_still_grow (view))
         return (-1);

+ 9 - 8
src/viewer/mcviewer.c

@@ -89,6 +89,7 @@ static void
 mcview_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
 {
     WView *view = (WView *) w;
+    const WRect *r = &view->data_area;
     gboolean ok = TRUE;
 
     switch (msg)
@@ -117,16 +118,16 @@ mcview_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
         if (!view->mode_flags.wrap)
         {
             /* Scrolling left and right */
-            screen_dimen x;
+            int x;
 
             x = event->x + 1;   /* FIXME */
 
-            if (x < view->data_area.width * 1 / 4)
+            if (x < r->cols * 1 / 4)
             {
                 mcview_move_left (view, 1);
                 event->result.repeat = msg == MSG_MOUSE_DOWN;
             }
-            else if (x < view->data_area.width * 3 / 4)
+            else if (x < r->cols * 3 / 4)
             {
                 /* ignore the click */
                 ok = FALSE;
@@ -140,20 +141,20 @@ mcview_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
         else
         {
             /* Scrolling up and down */
-            screen_dimen y;
+            int y;
 
             y = event->y + 1;   /* FIXME */
 
-            if (y < view->data_area.top + view->data_area.height * 1 / 3)
+            if (y < r->y + r->lines * 1 / 3)
             {
                 if (mcview_mouse_move_pages)
-                    mcview_move_up (view, view->data_area.height / 2);
+                    mcview_move_up (view, r->lines / 2);
                 else
                     mcview_move_up (view, 1);
 
                 event->result.repeat = msg == MSG_MOUSE_DOWN;
             }
-            else if (y < view->data_area.top + view->data_area.height * 2 / 3)
+            else if (y < r->y + r->lines * 2 / 3)
             {
                 /* ignore the click */
                 ok = FALSE;
@@ -161,7 +162,7 @@ mcview_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
             else
             {
                 if (mcview_mouse_move_pages)
-                    mcview_move_down (view, view->data_area.height / 2);
+                    mcview_move_down (view, r->lines / 2);
                 else
                     mcview_move_down (view, 1);
 

+ 7 - 9
src/viewer/move.c

@@ -14,7 +14,7 @@
    Pavel Machek, 1998
    Roland Illig <roland.illig@gmx.de>, 2004, 2005
    Slava Zanko <slavazanko@google.com>, 2009
-   Andrew Borodin <aborodin@vmail.ru>, 2009, 2013
+   Andrew Borodin <aborodin@vmail.ru>, 2009-2022
    Ilia Maslakov <il.smind@gmail.com>, 2009, 2010
 
    This file is part of the Midnight Commander.
@@ -77,7 +77,7 @@ mcview_scroll_to_cursor (WView * view)
         off_t topleft = view->dpy_start;
         off_t displaysize;
 
-        displaysize = view->data_area.height * bytes;
+        displaysize = view->data_area.lines * bytes;
         if (topleft + displaysize <= cursor)
             topleft = mcview_offset_rounddown (cursor, bytes) - (displaysize - bytes);
         if (cursor < topleft)
@@ -258,12 +258,10 @@ mcview_moveto_bottom (WView * view)
     }
     else
     {
-        const off_t datalines = view->data_area.height;
-
         view->dpy_start = filesize;
         view->dpy_paragraph_skip_lines = 0;
         view->dpy_wrap_dirty = TRUE;
-        mcview_move_up (view, datalines);
+        mcview_move_up (view, view->data_area.lines);
     }
 }
 
@@ -378,12 +376,12 @@ mcview_offset_to_coord (WView * view, off_t * ret_line, off_t * ret_column, off_
 void
 mcview_place_cursor (WView * view)
 {
-    const screen_dimen top = view->data_area.top;
-    const screen_dimen left = view->data_area.left;
-    screen_dimen col = view->cursor_col;
+    const WRect *r = &view->data_area;
+    int col = view->cursor_col;
+
     if (!view->hexview_in_text && view->hexedit_lownibble)
         col++;
-    widget_gotoyx (view, top + view->cursor_row, left + col);
+    widget_gotoyx (view, r->y + view->cursor_row, r->x + col);
 }
 
 /* --------------------------------------------------------------------------------------------- */