2 Widgets for the Midnight Commander
4 Copyright (C) 1994-2017
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, 2010, 2013
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)
39 #include "lib/global.h"
40 #include "lib/tty/tty.h"
41 #include "lib/tty/color.h"
43 #include "lib/strutil.h"
44 #include "lib/widget.h"
46 /*** global variables ****************************************************************************/
48 /*** file scope macro definitions ****************************************************************/
50 /*** file scope type declarations ****************************************************************/
52 /*** file scope variables ************************************************************************/
54 /*** file scope functions ************************************************************************/
57 hline_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
59 WHLine
*l
= HLINE (w
);
60 WDialog
*h
= w
->owner
;
66 if (l
->auto_adjust_cols
)
68 Widget
*wo
= WIDGET (h
);
78 w
->cols
= wo
->cols
- 2;
85 tty_setcolor (DEFAULT_COLOR
);
87 tty_setcolor (h
->color
[DLG_COLOR_NORMAL
]);
89 tty_draw_hline (w
->y
, w
->x
+ 1, ACS_HLINE
, w
->cols
- 2);
91 if (l
->auto_adjust_cols
)
93 widget_move (w
, 0, 0);
94 tty_print_alt_char (ACS_LTEE
, FALSE
);
95 widget_move (w
, 0, w
->cols
- 1);
96 tty_print_alt_char (ACS_RTEE
, FALSE
);
103 text_width
= str_term_width1 (l
->text
);
104 widget_move (w
, 0, (w
->cols
- text_width
) / 2);
105 tty_print_string (l
->text
);
114 return widget_default_callback (w
, sender
, msg
, parm
, data
);
118 /* --------------------------------------------------------------------------------------------- */
119 /*** public functions ****************************************************************************/
120 /* --------------------------------------------------------------------------------------------- */
123 hline_new (int y
, int x
, int width
)
129 l
= g_new (WHLine
, 1);
131 widget_init (w
, y
, x
, lines
, width
< 0 ? 1 : width
, hline_callback
, NULL
);
133 l
->auto_adjust_cols
= (width
< 0);
134 l
->transparent
= FALSE
;
139 /* --------------------------------------------------------------------------------------------- */
142 hline_set_text (WHLine
* l
, const char *text
)
146 if (text
== NULL
|| *text
== '\0')
149 l
->text
= g_strdup (text
);
151 widget_redraw (WIDGET (l
));
154 /* --------------------------------------------------------------------------------------------- */