2 Widgets for the Midnight Commander
4 Copyright (C) 1994-2016
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
);
70 if (((h
->flags
& DLG_COMPACT
) != 0))
78 w
->cols
= wo
->cols
- 2;
84 /* We don't want to get the focus */
85 return MSG_NOT_HANDLED
;
89 tty_setcolor (DEFAULT_COLOR
);
91 tty_setcolor (h
->color
[DLG_COLOR_NORMAL
]);
93 tty_draw_hline (w
->y
, w
->x
+ 1, ACS_HLINE
, w
->cols
- 2);
95 if (l
->auto_adjust_cols
)
97 widget_move (w
, 0, 0);
98 tty_print_alt_char (ACS_LTEE
, FALSE
);
99 widget_move (w
, 0, w
->cols
- 1);
100 tty_print_alt_char (ACS_RTEE
, FALSE
);
107 text_width
= str_term_width1 (l
->text
);
108 widget_move (w
, 0, (w
->cols
- text_width
) / 2);
109 tty_print_string (l
->text
);
118 return widget_default_callback (w
, sender
, msg
, parm
, data
);
122 /* --------------------------------------------------------------------------------------------- */
123 /*** public functions ****************************************************************************/
124 /* --------------------------------------------------------------------------------------------- */
127 hline_new (int y
, int x
, int width
)
133 l
= g_new (WHLine
, 1);
135 widget_init (w
, y
, x
, lines
, width
< 0 ? 1 : width
, hline_callback
, NULL
);
137 l
->auto_adjust_cols
= (width
< 0);
138 l
->transparent
= FALSE
;
143 /* --------------------------------------------------------------------------------------------- */
146 hline_set_text (WHLine
* l
, const char *text
)
150 if (text
== NULL
|| *text
== '\0')
153 l
->text
= g_strdup (text
);
155 widget_redraw (WIDGET (l
));
158 /* --------------------------------------------------------------------------------------------- */