From: Andrew Borodin Date: Mon, 24 Dec 2012 09:36:29 +0000 (+0400) Subject: Ticket #2076: make copy/move/delete progress dialog wider. X-Git-Tag: 4.8.8~30^2~2 X-Git-Url: https://repo.or.cz/w/midnight-commander.git/commitdiff_plain/2176e5f283cf3853e7aef0b486e92f4f36b09416 Ticket #2076: make copy/move/delete progress dialog wider. Initial step: get rid of hardcoded width of progress bar. Signed-off-by: Andrew Borodin --- diff --git a/lib/widget/gauge.c b/lib/widget/gauge.c index 1c7355c2b..317aed689 100644 --- a/lib/widget/gauge.c +++ b/lib/widget/gauge.c @@ -49,9 +49,6 @@ /*** file scope macro definitions ****************************************************************/ -/* Currently width is hardcoded here for text mode */ -#define gauge_len 47 - /*** file scope type declarations ****************************************************************/ /*** file scope variables ************************************************************************/ @@ -64,21 +61,25 @@ gauge_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d WGauge *g = GAUGE (w); WDialog *h = w->owner; - if (msg == MSG_INIT) + switch (msg) + { + case MSG_INIT: return MSG_HANDLED; - /* We don't want to get the focus */ - if (msg == MSG_FOCUS) + /* We don't want to get the focus */ + case MSG_FOCUS: return MSG_NOT_HANDLED; - if (msg == MSG_DRAW) - { + case MSG_DRAW: widget_move (w, 0, 0); - tty_setcolor (h->color[DLG_COLOR_NORMAL]); if (!g->shown) - tty_printf ("%*s", gauge_len, ""); + { + tty_setcolor (h->color[DLG_COLOR_NORMAL]); + tty_printf ("%*s", w->cols, ""); + } else { + int gauge_len; int percentage, columns; long total = g->max; long done = g->current; @@ -95,30 +96,34 @@ gauge_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d total /= 256; done /= 256; } + + gauge_len = w->cols - 7; /* 7 positions for percentage */ + percentage = (200 * done / total + 1) / 2; - columns = (2 * (gauge_len - 7) * done / total + 1) / 2; + columns = (2 * gauge_len * done / total + 1) / 2; tty_print_char ('['); if (g->from_left_to_right) { tty_setcolor (GAUGE_COLOR); tty_printf ("%*s", (int) columns, ""); tty_setcolor (h->color[DLG_COLOR_NORMAL]); - tty_printf ("%*s] %3d%%", (int) (gauge_len - 7 - columns), "", (int) percentage); + tty_printf ("%*s] %3d%%", gauge_len - columns, "", percentage); } else { tty_setcolor (h->color[DLG_COLOR_NORMAL]); - tty_printf ("%*s", gauge_len - columns - 7, ""); + tty_printf ("%*s", gauge_len - columns, ""); tty_setcolor (GAUGE_COLOR); tty_printf ("%*s", columns, ""); tty_setcolor (h->color[DLG_COLOR_NORMAL]); - tty_printf ("] %3d%%", 100 * columns / (gauge_len - 7), percentage); + tty_printf ("] %3d%%", 100 * columns / gauge_len, percentage); } } return MSG_HANDLED; - } - return widget_default_callback (w, sender, msg, parm, data); + default: + return widget_default_callback (w, sender, msg, parm, data); + } } /* --------------------------------------------------------------------------------------------- */ @@ -126,14 +131,16 @@ gauge_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d /* --------------------------------------------------------------------------------------------- */ WGauge * -gauge_new (int y, int x, gboolean shown, int max, int current) +gauge_new (int y, int x, int cols, gboolean shown, int max, int current) { WGauge *g; Widget *w; g = g_new (WGauge, 1); w = WIDGET (g); - init_widget (w, y, x, 1, gauge_len, gauge_callback, NULL); + init_widget (w, y, x, 1, cols, gauge_callback, NULL); + widget_want_cursor (w, FALSE); + widget_want_hotkey (w, FALSE); g->shown = shown; if (max == 0) @@ -142,9 +149,6 @@ gauge_new (int y, int x, gboolean shown, int max, int current) g->current = current; g->from_left_to_right = TRUE; - widget_want_cursor (w, FALSE); - widget_want_hotkey (w, FALSE); - return g; } diff --git a/lib/widget/gauge.h b/lib/widget/gauge.h index 9b149a763..e1f5d2c54 100644 --- a/lib/widget/gauge.h +++ b/lib/widget/gauge.h @@ -27,7 +27,7 @@ typedef struct WGauge /*** declarations of public functions ************************************************************/ -WGauge *gauge_new (int y, int x, gboolean shown, int max, int current); +WGauge *gauge_new (int y, int x, int cols, gboolean shown, int max, int current); void gauge_set_value (WGauge * g, int max, int current); void gauge_show (WGauge * g, gboolean shown); diff --git a/src/filemanager/filegui.c b/src/filemanager/filegui.c index 63284d3c4..5c984c63e 100644 --- a/src/filemanager/filegui.c +++ b/src/filemanager/filegui.c @@ -735,7 +735,7 @@ file_op_context_create_ui (FileOpContext * ctx, gboolean with_eta, ui->file_string[1] = label_new (y++, x, ""); add_widget (ui->op_dlg, ui->file_string[1]); - ui->progress_file_gauge = gauge_new (y++, x + 3, 0, 100, 0); + ui->progress_file_gauge = gauge_new (y++, x + 3, dlg_width - (x + 3) * 2, FALSE, 100, 0); if (!classic_progressbar && (current_panel == right_panel)) ui->progress_file_gauge->from_left_to_right = FALSE; add_widget (ui->op_dlg, ui->progress_file_gauge); @@ -752,7 +752,8 @@ file_op_context_create_ui (FileOpContext * ctx, gboolean with_eta, if (file_op_compute_totals) { - ui->progress_total_gauge = gauge_new (y++, x + 3, 0, 100, 0); + ui->progress_total_gauge = + gauge_new (y++, x + 3, dlg_width - (x + 3) * 2, FALSE, 100, 0); if (!classic_progressbar && (current_panel == right_panel)) ui->progress_total_gauge->from_left_to_right = FALSE; add_widget (ui->op_dlg, ui->progress_total_gauge);