Remove unneeded `struct` keyword for typedef'd structs
[midnight-commander.git] / lib / widget / hline.c
blobe2f91ff8342cd2e7aa2c68d5d720def4d6dd27b0
1 /*
2 Widgets for the Midnight Commander
4 Copyright (C) 1994-2016
5 Free Software Foundation, Inc.
7 Authors:
8 Radek Doulik, 1994, 1995
9 Miguel de Icaza, 1994, 1995
10 Jakub Jelinek, 1995
11 Andrej Borsenkow, 1996
12 Norbert Warmuth, 1997
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/>.
31 /** \file hline.c
32 * \brief Source: WHLine widget (horizontal line)
35 #include <config.h>
37 #include <stdlib.h>
39 #include "lib/global.h"
40 #include "lib/tty/tty.h"
41 #include "lib/tty/color.h"
42 #include "lib/skin.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 ************************************************************************/
56 static cb_ret_t
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;
62 switch (msg)
64 case MSG_INIT:
65 case MSG_RESIZE:
66 if (l->auto_adjust_cols)
68 Widget *wo = WIDGET (h);
70 if (((h->flags & DLG_COMPACT) != 0))
72 w->x = wo->x;
73 w->cols = wo->cols;
75 else
77 w->x = wo->x + 1;
78 w->cols = wo->cols - 2;
81 return MSG_HANDLED;
83 case MSG_FOCUS:
84 /* We don't want to get the focus */
85 return MSG_NOT_HANDLED;
87 case MSG_DRAW:
88 if (l->transparent)
89 tty_setcolor (DEFAULT_COLOR);
90 else
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);
103 if (l->text != NULL)
105 int text_width;
107 text_width = str_term_width1 (l->text);
108 widget_move (w, 0, (w->cols - text_width) / 2);
109 tty_print_string (l->text);
111 return MSG_HANDLED;
113 case MSG_DESTROY:
114 g_free (l->text);
115 return MSG_HANDLED;
117 default:
118 return widget_default_callback (w, sender, msg, parm, data);
122 /* --------------------------------------------------------------------------------------------- */
123 /*** public functions ****************************************************************************/
124 /* --------------------------------------------------------------------------------------------- */
126 WHLine *
127 hline_new (int y, int x, int width)
129 WHLine *l;
130 Widget *w;
131 int lines = 1;
133 l = g_new (WHLine, 1);
134 w = WIDGET (l);
135 widget_init (w, y, x, lines, width < 0 ? 1 : width, hline_callback, NULL);
136 l->text = NULL;
137 l->auto_adjust_cols = (width < 0);
138 l->transparent = FALSE;
139 widget_want_cursor (w, FALSE);
140 widget_want_hotkey (w, FALSE);
142 return l;
145 /* --------------------------------------------------------------------------------------------- */
147 void
148 hline_set_text (WHLine * l, const char *text)
150 g_free (l->text);
152 if (text == NULL || *text == '\0')
153 l->text = NULL;
154 else
155 l->text = g_strdup (text);
157 widget_redraw (WIDGET (l));
160 /* --------------------------------------------------------------------------------------------- */