Ticket #4256: scrollbars_improvements.patch
File scrollbars_improvements.patch, 20.8 KB (added by kybl, 2 years ago) |
---|
-
lib/widget/listbox.c
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c
a b 85 85 86 86 /* --------------------------------------------------------------------------------------------- */ 87 87 88 static void89 listbox_drawscroll (WListbox * l)90 {91 Widget *w = WIDGET (l);92 int max_line = w->lines - 1;93 int line = 0;94 int i;95 int length;96 97 /* Are we at the top? */98 widget_gotoyx (w, 0, w->cols);99 if (l->top == 0)100 tty_print_one_vline (TRUE);101 else102 tty_print_char ('^');103 104 length = g_queue_get_length (l->list);105 106 /* Are we at the bottom? */107 widget_gotoyx (w, max_line, w->cols);108 if (l->top + w->lines == length || w->lines >= length)109 tty_print_one_vline (TRUE);110 else111 tty_print_char ('v');112 113 /* Now draw the nice relative pointer */114 if (!g_queue_is_empty (l->list))115 line = 1 + ((l->pos * (w->lines - 2)) / length);116 117 for (i = 1; i < max_line; i++)118 {119 widget_gotoyx (w, i, w->cols);120 if (i != line)121 tty_print_one_vline (TRUE);122 else123 tty_print_char ('*');124 }125 }126 127 /* --------------------------------------------------------------------------------------------- */128 129 88 static void 130 89 listbox_draw (WListbox * l, gboolean focused) 131 90 { … … 183 142 184 143 l->cursor_y = sel_line; 185 144 186 if (l-> scrollbar && length > w->lines)145 if (l->draw_scrollbar) 187 146 { 188 147 tty_setcolor (normalc); 189 listbox_drawscroll (l); 148 scrollbar_set_state (l->scrollbar, w->y - 1, w->x + w->cols - 1, w->lines + 2, g_queue_get_length (l->list), w->lines, l->top); 149 WIDGET (l->scrollbar)->callback (WIDGET (l->scrollbar), NULL, MSG_DRAW, 0, NULL); 190 150 } 191 151 } 192 152 … … 440 400 static inline void 441 401 listbox_destroy (WListbox * l) 442 402 { 403 widget_destroy (WIDGET (l->scrollbar)); 443 404 listbox_remove_list (l); 444 405 } 445 406 … … 564 525 l->deletable = deletable; 565 526 l->callback = callback; 566 527 l->allow_duplicates = TRUE; 567 l->scrollbar = !mc_global.tty.slow_terminal; 528 l->draw_scrollbar = !mc_global.tty.slow_terminal; 529 l->scrollbar = scrollbar_new (y, x + width - 1, height, TRUE); 568 530 569 531 return l; 570 532 } -
lib/widget/Makefile.am
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/lib/widget/Makefile.am b/lib/widget/Makefile.am
a b 24 24 quick.c quick.h \ 25 25 radio.c radio.h \ 26 26 rect.c rect.h \ 27 scrollbar.c scrollbar.h \ 27 28 widget-common.c widget-common.h \ 28 29 wtools.c wtools.h 29 30 -
doc/man/mc.1.in
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/doc/man/mc.1.in b/doc/man/mc.1.in
a b 1989 1989 .I Show free space. 1990 1990 If enabled, free space and total space of current file system is shown 1991 1991 at the bottom frame of panel. Enabled by default. 1992 .PP 1993 .I Panel scrollbars. 1994 Show scrollbars in main panels (on the right side). Enabled by default. 1992 1995 .\"NODE " Panel options" 1993 1996 .SH " Panel options" 1994 1997 .B Main panel options -
lib/widget/listbox.h
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/lib/widget/listbox.h b/lib/widget/listbox.h
a b 48 48 int pos; /* The current element displayed */ 49 49 int top; /* The first element displayed */ 50 50 gboolean allow_duplicates; /* Do we allow duplicates on the list? */ 51 gboolean scrollbar; /* Draw a scrollbar? */ 51 gboolean draw_scrollbar; /* Draw a scrollbar? */ 52 WScrollbar *scrollbar; /* Scrollbar widget */ 52 53 gboolean deletable; /* Can list entries be deleted? */ 53 54 lcback_fn callback; /* The callback function */ 54 55 int cursor_x, cursor_y; /* Cache the values */ -
src/filemanager/panel.h
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/filemanager/panel.h b/src/filemanager/panel.h
a b 105 105 106 106 dir_list dir; /* Directory contents */ 107 107 struct stat dir_stat; /* Stat of current dir: used by execute () */ 108 WScrollbar *scrollbar; /* scrollbar of panel */ 108 109 109 110 vfs_path_t *cwd_vpath; /* Current Working Directory */ 110 111 vfs_path_t *lwd_vpath; /* Last Working Directory */ -
src/filemanager/layout.h
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/filemanager/layout.h b/src/filemanager/layout.h
a b 46 46 extern int output_start_y; 47 47 extern gboolean xterm_title; 48 48 extern gboolean free_space; 49 extern gboolean panel_scrollbars; 49 50 extern gboolean nice_rotating_dash; 50 51 51 52 extern int ok_to_refresh; -
src/setup.c
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/setup.c b/src/setup.c
a b 274 274 { "command_prompt", &command_prompt }, 275 275 { "menubar_visible", &menubar_visible }, 276 276 { "free_space", &free_space }, 277 { "panel_scrollbars", &panel_scrollbars }, 277 278 { "horizontal_split", &panels_layout.horizontal_split }, 278 279 { "vertical_equal", &panels_layout.vertical_equal }, 279 280 { "horizontal_equal", &panels_layout.horizontal_equal }, -
lib/widget.h
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/lib/widget.h b/lib/widget.h
a b 29 29 #include "lib/widget/gauge.h" 30 30 #include "lib/widget/groupbox.h" 31 31 #include "lib/widget/label.h" 32 #include "lib/widget/scrollbar.h" 32 33 #include "lib/widget/listbox.h" 33 34 #include "lib/widget/menu.h" 34 35 #include "lib/widget/radio.h" -
src/filemanager/layout.c
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c
a b 100 100 /* Set to show free space on device assigned to current directory */ 101 101 gboolean free_space = TRUE; 102 102 103 /* Set to show scrollbars on main panels */ 104 gboolean panel_scrollbars = TRUE; 105 103 106 /* The starting line for the output of the subprogram */ 104 107 int output_start_y = 0; 105 108 … … 133 136 gboolean message_visible; 134 137 gboolean xterm_title; 135 138 gboolean free_space; 139 gboolean panel_scrollbars; 136 140 int output_lines; 137 141 } layout_t; 138 142 … … 176 180 { N_("&Keybar visible"), &mc_global.keybar_visible, NULL }, 177 181 { N_("H&intbar visible"), &mc_global.message_visible, NULL }, 178 182 { N_("&XTerm window title"), &xterm_title, NULL }, 179 { N_("&Show free space"), &free_space, NULL } 183 { N_("&Show free space"), &free_space, NULL }, 184 { N_("&Panel scrollbars"), &panel_scrollbars, NULL } 180 185 /* *INDENT-ON* */ 181 186 }; 182 187 … … 466 471 xterm_title = check_options[5].widget->state; 467 472 else if (sender == WIDGET (check_options[6].widget)) 468 473 free_space = check_options[6].widget->state; 474 else if (sender == WIDGET (check_options[7].widget)) 475 panel_scrollbars = check_options[7].widget->state; 469 476 else 470 477 ok = FALSE; 471 478 … … 678 685 old_layout.message_visible = mc_global.message_visible; 679 686 old_layout.xterm_title = xterm_title; 680 687 old_layout.free_space = free_space; 688 old_layout.panel_scrollbars = panel_scrollbars; 681 689 old_layout.output_lines = -1; 682 690 683 691 _output_lines = output_lines; … … 696 704 mc_global.message_visible = old_layout.message_visible; 697 705 xterm_title = old_layout.xterm_title; 698 706 free_space = old_layout.free_space; 707 panel_scrollbars = old_layout.panel_scrollbars; 699 708 output_lines = old_layout.output_lines; 700 709 701 710 panels_layout = old_panels_layout; -
src/filemanager/panel.c
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c
a b 1258 1258 { 1259 1259 const Widget *w = CONST_WIDGET (panel); 1260 1260 gchar *tmp; 1261 int lines; 1261 1262 1262 1263 set_colors (panel); 1263 1264 tty_draw_box (w->y, w->x, w->lines, w->cols, FALSE); 1265 lines = panel_lines (panel); 1264 1266 1265 1267 if (panels_options.show_mini_info) 1266 1268 { 1267 1269 int y; 1268 1270 1269 y = panel_lines (panel)+ 2;1271 y = lines + 2; 1270 1272 1271 1273 widget_gotoyx (w, y, 0); 1272 1274 tty_print_alt_char (ACS_LTEE, FALSE); … … 1274 1276 tty_print_alt_char (ACS_RTEE, FALSE); 1275 1277 } 1276 1278 1279 if (panel_scrollbars) { 1280 scrollbar_set_state (panel->scrollbar, w->y + 1, w->x + w->cols - 1, lines + 2, panel->dir.len, 1281 lines * panel->list_cols, panel->top_file); 1282 } 1283 1277 1284 widget_gotoyx (w, 0, 1); 1278 1285 tty_print_string (panel_history_prev_item_char); 1279 1286 … … 1314 1321 { 1315 1322 if (panel->marked == 0) 1316 1323 { 1317 /* Show size of curre t file in the bottom of panel */1324 /* Show size of current file in the bottom of panel */ 1318 1325 if (S_ISREG (panel->dir.list[panel->selected].st.st_mode)) 1319 1326 { 1320 1327 char buffer[BUF_SMALL]; … … 3648 3655 mc_event_add (h->event_group, MCEVENT_HISTORY_LOAD, panel_load_history, w, NULL); 3649 3656 /* subscribe to "history_save" event */ 3650 3657 mc_event_add (h->event_group, MCEVENT_HISTORY_SAVE, panel_save_history, w, NULL); 3658 panel->scrollbar = scrollbar_new (w->y + 1, w->x + w->cols - 1, w->lines, FALSE); 3659 return MSG_HANDLED; 3660 3661 case MSG_RESIZE: 3662 widget_default_callback (w, NULL, MSG_RESIZE, 0, data); 3663 if (panel->scrollbar != NULL) 3664 WIDGET (panel->scrollbar)->callback (WIDGET (panel->scrollbar), NULL, MSG_RESIZE, 0, NULL); 3651 3665 return MSG_HANDLED; 3652 3666 3653 3667 case MSG_DRAW: 3654 3668 /* Repaint everything, including frame and separator */ 3655 3669 widget_erase (w); 3656 3670 show_dir (panel); 3671 mini_info_separator (panel); 3657 3672 panel_print_header (panel); 3658 3673 adjust_top_file (panel); 3659 3674 paint_dir (panel); 3660 mini_info_separator (panel);3661 3675 display_mini_info (panel); 3676 3677 if (panel_scrollbars) 3678 WIDGET (panel->scrollbar)->callback (WIDGET (panel->scrollbar), NULL, MSG_DRAW, 0, NULL); 3679 3662 3680 panel->dirty = FALSE; 3663 3681 return MSG_HANDLED; 3664 3682 … … 3706 3724 mc_event_del (h->event_group, MCEVENT_HISTORY_LOAD, panel_load_history, w); 3707 3725 /* unsubscribe from "history_save" event */ 3708 3726 mc_event_del (h->event_group, MCEVENT_HISTORY_SAVE, panel_save_history, w); 3727 widget_destroy (WIDGET (panel->scrollbar)); 3709 3728 panel_destroy (panel); 3710 3729 free_my_statfs (); 3711 3730 return MSG_HANDLED; -
new file lib/widget/scrollbar.c
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/lib/widget/scrollbar.c b/lib/widget/scrollbar.c new file mode 100644
- + 1 /* 2 Widgets for the Midnight Commander 3 4 Copyright (C) 2021 5 Free Software Foundation, Inc. 6 7 This file is part of the Midnight Commander. 8 9 The Midnight Commander is free software: you can redistribute it 10 and/or modify it under the terms of the GNU General Public License as 11 published by the Free Software Foundation, either version 3 of the License, 12 or (at your option) any later version. 13 14 The Midnight Commander is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 /** \file scrollbar.c 24 * \brief Source: WScrollbar widget 25 */ 26 27 #include <config.h> 28 29 #include <stdarg.h> 30 #include <stdlib.h> 31 #include <string.h> 32 33 #include "lib/global.h" 34 35 #include "lib/tty/tty.h" 36 #include "lib/tty/color.h" 37 #include "lib/skin.h" 38 #include "lib/strutil.h" 39 #include "lib/widget.h" 40 41 /*** global variables ****************************************************************************/ 42 43 /*** file scope macro definitions ****************************************************************/ 44 45 /*** file scope type declarations ****************************************************************/ 46 47 /*** file scope variables ************************************************************************/ 48 49 /*** file scope functions ************************************************************************/ 50 51 static cb_ret_t 52 scrollbar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) 53 { 54 WScrollbar *s = SCROLLBAR (w); 55 56 switch (msg) 57 { 58 case MSG_RESIZE: 59 { 60 widget_default_callback (w, NULL, MSG_RESIZE, 0, data); 61 return MSG_HANDLED; 62 } 63 64 case MSG_DRAW: 65 { 66 int scrollbar_values_per_char; 67 int scrollbar_values_total; 68 int scrollbox_length; 69 int top_possibilities; 70 int scrollbox_pos_start; 71 int i; 72 int scrollbar_position; 73 74 if (s->data_items <= s->data_visible_items) 75 return MSG_HANDLED; 76 77 /* Are we at the top? */ 78 widget_gotoyx (w, 0, 0); 79 if (s->data_visible_start_position == 0) 80 tty_print_string (mc_global.tty.ugly_line_drawing ? "" : "△"); 81 else 82 tty_print_string (mc_global.tty.ugly_line_drawing ? "^" : "▲"); 83 84 /* Are we at the bottom? */ 85 widget_gotoyx (w, w->lines - 1, 0); 86 if (s->data_visible_start_position + s->data_visible_items >= s->data_items) 87 tty_print_string (mc_global.tty.ugly_line_drawing ? "" : "▽"); 88 else 89 tty_print_string (mc_global.tty.ugly_line_drawing ? "v" : "▼"); 90 91 if (w->lines <= 2) /* there is no enough space for actual scrollbar */ 92 return MSG_HANDLED; 93 94 /* Now draw the nice relative pointer */ 95 scrollbar_values_per_char = (s->has_subchars && !mc_global.tty.ugly_line_drawing ? 2 : 1); 96 scrollbar_values_total = (w->lines - 2) * scrollbar_values_per_char; 97 scrollbox_length = MAX (1, scrollbar_values_total * s->data_visible_items / s->data_items); 98 top_possibilities = s->data_items - s->data_visible_items + 1; 99 scrollbox_pos_start = (2 * s->data_visible_start_position * (scrollbar_values_total - scrollbox_length) 100 / (top_possibilities - 1) + 1) / 2; 101 102 for (i = 0; i < w->lines - 2; i++) 103 { 104 widget_gotoyx (w, i + 1, 0); 105 scrollbar_position = i * scrollbar_values_per_char; 106 107 if (scrollbar_values_per_char == 2 108 && scrollbar_position + 1 == scrollbox_pos_start) 109 tty_print_string ("▄"); 110 else if (scrollbar_values_per_char == 2 111 && scrollbar_position >= scrollbox_pos_start 112 && scrollbar_position + 1 == scrollbox_pos_start + scrollbox_length) 113 tty_print_string ("▀"); 114 else if (scrollbar_position >= scrollbox_pos_start 115 && scrollbar_position + scrollbar_values_per_char <= scrollbox_pos_start + scrollbox_length) 116 tty_print_string (mc_global.tty.ugly_line_drawing ? "#" : (s->has_subchars ? "█" : "▓")); 117 else 118 tty_print_string (s->has_subchars || mc_global.tty.ugly_line_drawing ? " " : "░"); 119 } 120 121 return MSG_HANDLED; 122 } 123 124 default: 125 return widget_default_callback (w, sender, msg, parm, data); 126 } 127 } 128 129 /* --------------------------------------------------------------------------------------------- */ 130 /*** public functions ****************************************************************************/ 131 /* --------------------------------------------------------------------------------------------- */ 132 133 WScrollbar * 134 scrollbar_new (int y, int x, int lines, gboolean has_subchars) 135 { 136 WScrollbar *scrollbar; 137 Widget *w; 138 139 scrollbar = g_new (WScrollbar, 1); 140 w = WIDGET (scrollbar); 141 widget_init (w, y, x, lines, 1, scrollbar_callback, NULL); 142 143 scrollbar->has_subchars = has_subchars; 144 scrollbar->data_items = 0; 145 scrollbar->data_visible_items = 0; 146 scrollbar->data_visible_start_position = 0; 147 148 return scrollbar; 149 } 150 151 /* --------------------------------------------------------------------------------------------- */ 152 153 void 154 scrollbar_set_state(WScrollbar * scrollbar, int y, int x, int lines, int data_length, 155 int data_visible_length, int data_position) 156 { 157 Widget *w = WIDGET (scrollbar); 158 159 w->y = y; 160 w->x = x; 161 w->lines = lines; 162 scrollbar->data_items = data_length; 163 scrollbar->data_visible_items = data_visible_length; 164 scrollbar->data_visible_start_position = data_position; 165 166 widget_draw (w); 167 } 168 169 /* --------------------------------------------------------------------------------------------- */ -
new file lib/widget/scrollbar.h
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/lib/widget/scrollbar.h b/lib/widget/scrollbar.h new file mode 100644
- + 1 2 /** \file scrollbar.h 3 * \brief Header: WScrollbar widget 4 */ 5 6 #ifndef MC__WIDGET_SCROLLBAR_H 7 #define MC__WIDGET_SCROLLBAR_H 8 9 /*** typedefs(not structures) and defined constants **********************************************/ 10 11 #define SCROLLBAR(x) ((WScrollbar *)(x)) 12 13 /*** enums ***************************************************************************************/ 14 15 /*** structures declarations (and typedefs of structures)*****************************************/ 16 17 typedef struct 18 { 19 Widget widget; 20 gboolean has_subchars; /* if uses sub-characters (2 states per character). Also, this 21 turns off scrollbar background */ 22 int data_items; /* how many items are in the background data */ 23 int data_visible_items; /* how many items from data are actually visible */ 24 int data_visible_start_position; /* position of first visible item in data */ 25 } WScrollbar; 26 27 /*** global variables defined in .c file *********************************************************/ 28 29 /*** declarations of public functions ************************************************************/ 30 31 WScrollbar *scrollbar_new (int y, int x, int height, gboolean has_subchars); 32 void scrollbar_set_state (WScrollbar * scrollbar, int y, int x, int lines, int data_length, 33 int data_visible_length, int data_position); 34 35 /*** inline functions ****************************************************************************/ 36 37 #endif /* MC__WIDGET_SCROLLBAR_H */