diff --git a/src/widget.c b/src/widget.c index cfa485f6d..679792e0b 100644 --- a/src/widget.c +++ b/src/widget.c @@ -785,6 +785,66 @@ label_new (int y, int x, const char *text) return l; } +static cb_ret_t +hline_callback (Widget *w, widget_msg_t msg, int parm) +{ + WHLine *l = (WHLine *) w; + Dlg_head *h = l->widget.parent; + + switch (msg) { + case WIDGET_INIT: + case WIDGET_RESIZED: + if (l->auto_adjust_cols) { + if (((w->parent->flags & DLG_COMPACT) != 0)) { + w->x = w->parent->x; + w->cols = w->parent->cols; + } else { + w->x = w->parent->x + 1; + w->cols = w->parent->cols - 2; + } + } + + case WIDGET_FOCUS: + /* We don't want to get the focus */ + return MSG_NOT_HANDLED; + + case WIDGET_DRAW: + if (l->transparent) + tty_setcolor (DEFAULT_COLOR); + else + tty_setcolor (DLG_NORMALC (h)); + + tty_draw_hline (w->y, w->x + 1, ACS_HLINE, w->cols - 2); + + if (l->auto_adjust_cols) { + widget_move (w, 0, 0); + tty_print_alt_char (ACS_LTEE); + widget_move (w, 0, w->cols - 1); + tty_print_alt_char (ACS_RTEE); + } + return MSG_HANDLED; + + default: + return default_proc (msg, parm); + } +} + + +WHLine * +hline_new (int y, int x, int width) +{ + WHLine *l; + int cols = width; + int lines = 1; + + l = g_new (WHLine, 1); + init_widget (&l->widget, y, x, lines, cols, hline_callback, NULL); + l->auto_adjust_cols = (width < 0); + l->transparent = FALSE; + widget_want_cursor (l->widget, 0); + return l; +} + /* Gauge widget (progress indicator) */ /* Currently width is hardcoded here for text mode */ diff --git a/src/widget.h b/src/widget.h index a7590935f..28691892f 100644 --- a/src/widget.h +++ b/src/widget.h @@ -128,6 +128,12 @@ typedef struct { int transparent; /* Paint in the default color fg/bg */ } WLabel; +typedef struct { + Widget widget; + gboolean auto_adjust_cols; /* Compute widget.cols from parent width? */ + gboolean transparent; /* Paint in the default color fg/bg */ +} WHLine; + typedef struct WLEntry { char *text; /* Text to display */ int hotkey; @@ -187,6 +193,8 @@ WRadio *radio_new (int y, int x, int count, const char **text); WCheck *check_new (int y, int x, int state, const char *text); WInput *input_new (int y, int x, int color, int len, const char *text, const char *histname, INPUT_COMPLETE_FLAGS completion_flags); WLabel *label_new (int y, int x, const char *text); +WHLine *hline_new (int y, int x, int width); + WGauge *gauge_new (int y, int x, int shown, int max, int current); WListbox *listbox_new (int y, int x, int height, int width, gboolean deletable, lcback callback); WButtonBar *buttonbar_new (gboolean visible);