add option "Ask new file name" in the Configuration box
[midnight-commander.git] / lib / widget / hline.c
blobb094e01c3b9b662437dda0839f352079e467fb43
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/strutil.h"
45 #include "lib/widget.h"
47 /*** global variables ****************************************************************************/
49 /*** file scope macro definitions ****************************************************************/
51 /*** file scope type declarations ****************************************************************/
53 /*** file scope variables ************************************************************************/
55 /*** file scope functions ************************************************************************/
57 static cb_ret_t
58 hline_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
60 WHLine *l = HLINE (w);
61 WDialog *h = w->owner;
63 switch (msg)
65 case MSG_INIT:
66 case MSG_RESIZE:
67 if (l->auto_adjust_cols)
69 Widget *wo = WIDGET (h);
71 if (((h->flags & DLG_COMPACT) != 0))
73 w->x = wo->x;
74 w->cols = wo->cols;
76 else
78 w->x = wo->x + 1;
79 w->cols = wo->cols - 2;
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 default:
114 return widget_default_callback (w, sender, msg, parm, data);
118 /* --------------------------------------------------------------------------------------------- */
119 /*** public functions ****************************************************************************/
120 /* --------------------------------------------------------------------------------------------- */
122 WHLine *
123 hline_new (int y, int x, int width)
125 WHLine *l;
126 Widget *w;
127 int lines = 1;
129 l = g_new (WHLine, 1);
130 w = WIDGET (l);
131 init_widget (w, y, x, lines, width < 0 ? 1 : width, hline_callback, NULL);
132 l->text = NULL;
133 l->auto_adjust_cols = (width < 0);
134 l->transparent = FALSE;
135 widget_want_cursor (w, FALSE);
136 widget_want_hotkey (w, FALSE);
138 return l;
141 /* --------------------------------------------------------------------------------------------- */
143 void
144 hline_set_text (WHLine * l, const char *text)
146 g_free (l->text);
148 if (text == NULL || *text == '\0')
149 l->text = NULL;
150 else
151 l->text = g_strdup (text);
153 if (WIDGET (l)->owner != NULL)
154 send_message (l, NULL, MSG_DRAW, 0, NULL);
157 /* --------------------------------------------------------------------------------------------- */