22ea767256f278d5c3f258a1a023f58ac94ccd75
[midnight-commander.git] / lib / widget / hline.c
blob22ea767256f278d5c3f258a1a023f58ac94ccd75
1 /*
2 Widgets for the Midnight Commander
4 Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
5 2004, 2005, 2006, 2007, 2009, 2010, 2011
6 The Free Software Foundation, Inc.
8 Authors:
9 Radek Doulik, 1994, 1995
10 Miguel de Icaza, 1994, 1995
11 Jakub Jelinek, 1995
12 Andrej Borsenkow, 1996
13 Norbert Warmuth, 1997
14 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010
16 This file is part of the Midnight Commander.
18 The Midnight Commander is free software: you can redistribute it
19 and/or modify it under the terms of the GNU General Public License as
20 published by the Free Software Foundation, either version 3 of the License,
21 or (at your option) any later version.
23 The Midnight Commander is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
28 You should have received a copy of the GNU General Public License
29 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 /** \file hline.c
33 * \brief Source: WHLine widget (horizontal line)
36 #include <config.h>
38 #include <stdlib.h>
40 #include "lib/global.h"
41 #include "lib/tty/tty.h"
42 #include "lib/tty/color.h"
43 #include "lib/skin.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;
82 case MSG_FOCUS:
83 /* We don't want to get the focus */
84 return MSG_NOT_HANDLED;
86 case MSG_DRAW:
87 if (l->transparent)
88 tty_setcolor (DEFAULT_COLOR);
89 else
90 tty_setcolor (h->color[DLG_COLOR_NORMAL]);
92 tty_draw_hline (w->y, w->x + 1, ACS_HLINE, w->cols - 2);
94 if (l->auto_adjust_cols)
96 widget_move (w, 0, 0);
97 tty_print_alt_char (ACS_LTEE, FALSE);
98 widget_move (w, 0, w->cols - 1);
99 tty_print_alt_char (ACS_RTEE, FALSE);
101 return MSG_HANDLED;
103 default:
104 return widget_default_callback (w, sender, msg, parm, data);
108 /* --------------------------------------------------------------------------------------------- */
109 /*** public functions ****************************************************************************/
110 /* --------------------------------------------------------------------------------------------- */
112 WHLine *
113 hline_new (int y, int x, int width)
115 WHLine *l;
116 Widget *w;
117 int lines = 1;
119 l = g_new (WHLine, 1);
120 w = WIDGET (l);
121 init_widget (w, y, x, lines, width < 0 ? 1 : width, hline_callback, NULL);
122 l->auto_adjust_cols = (width < 0);
123 l->transparent = FALSE;
124 widget_want_cursor (w, FALSE);
125 widget_want_hotkey (w, FALSE);
127 return l;
130 /* --------------------------------------------------------------------------------------------- */