2 Widgets for the Midnight Commander
4 Copyright (C) 1994-2024
5 Free Software Foundation, Inc.
8 Radek Doulik, 1994, 1995
9 Miguel de Icaza, 1994, 1995
11 Andrej Borsenkow, 1996
13 Andrew Borodin <aborodin@vmail.ru>, 2009-2022
15 This file is part of the Midnight Commander.
17 The Midnight Commander is free software: you can redistribute it
18 and/or modify it under the terms of the GNU General Public License as
19 published by the Free Software Foundation, either version 3 of the License,
20 or (at your option) any later version.
22 The Midnight Commander is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 * \brief Source: WHLine widget (horizontal line)
40 #include "lib/global.h"
41 #include "lib/tty/tty.h"
42 #include "lib/tty/color.h"
44 #include "lib/strutil.h"
45 #include "lib/widget.h"
47 /*** global variables ****************************************************************************/
49 /*** file scope macro definitions ****************************************************************/
51 /*** file scope type declarations ****************************************************************/
53 /*** forward declarations (file scope functions) *************************************************/
55 /*** file scope variables ************************************************************************/
57 /* --------------------------------------------------------------------------------------------- */
58 /*** file scope functions ************************************************************************/
59 /* --------------------------------------------------------------------------------------------- */
62 hline_adjust_cols (WHLine
*l
)
64 if (l
->auto_adjust_cols
)
66 Widget
*wl
= WIDGET (l
);
67 const Widget
*o
= CONST_WIDGET (wl
->owner
);
69 const WRect
*wo
= &o
->rect
;
71 if (CONST_DIALOG (o
)->compact
)
79 w
->cols
= wo
->cols
- 2;
84 /* --------------------------------------------------------------------------------------------- */
87 hline_callback (Widget
*w
, Widget
*sender
, widget_msg_t msg
, int parm
, void *data
)
89 WHLine
*l
= HLINE (w
);
94 hline_adjust_cols (l
);
98 hline_adjust_cols (l
);
99 w
->rect
.y
= RECT (data
)->y
;
104 tty_setcolor (DEFAULT_COLOR
);
109 colors
= widget_get_colors (w
);
110 tty_setcolor (colors
[DLG_COLOR_NORMAL
]);
113 tty_draw_hline (w
->rect
.y
, w
->rect
.x
+ 1, ACS_HLINE
, w
->rect
.cols
- 2);
115 if (l
->auto_adjust_cols
)
117 widget_gotoyx (w
, 0, 0);
118 tty_print_alt_char (ACS_LTEE
, FALSE
);
119 widget_gotoyx (w
, 0, w
->rect
.cols
- 1);
120 tty_print_alt_char (ACS_RTEE
, FALSE
);
127 text_width
= str_term_width1 (l
->text
);
128 widget_gotoyx (w
, 0, (w
->rect
.cols
- text_width
) / 2);
129 tty_print_string (l
->text
);
138 return widget_default_callback (w
, sender
, msg
, parm
, data
);
142 /* --------------------------------------------------------------------------------------------- */
143 /*** public functions ****************************************************************************/
144 /* --------------------------------------------------------------------------------------------- */
147 hline_new (int y
, int x
, int width
)
149 WRect r
= { y
, x
, 1, width
};
153 l
= g_new (WHLine
, 1);
155 r
.cols
= width
< 0 ? 1 : width
;
156 widget_init (w
, &r
, hline_callback
, NULL
);
158 l
->auto_adjust_cols
= (width
< 0);
159 l
->transparent
= FALSE
;
164 /* --------------------------------------------------------------------------------------------- */
167 hline_set_text (WHLine
*l
, const char *text
)
171 if (text
== NULL
|| *text
== '\0')
174 l
->text
= g_strdup (text
);
176 widget_draw (WIDGET (l
));
179 /* --------------------------------------------------------------------------------------------- */
182 hline_set_textv (WHLine
*l
, const char *format
, ...)
185 char buf
[BUF_1K
]; /* FIXME: is it enough? */
187 va_start (args
, format
);
188 g_vsnprintf (buf
, sizeof (buf
), format
, args
);
191 hline_set_text (l
, buf
);
194 /* --------------------------------------------------------------------------------------------- */