changed type of checking: used -n operator instead of -z
[midnight-commander.git] / lib / widget / groupbox.c
blob46cc48eef7c30cd41d3acee07e3ee7ac0ade7788
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 groupbox.c
33 * \brief Source: WGroupbox widget
36 #include <config.h>
38 #include "lib/global.h"
40 #include "lib/tty/tty.h"
41 #include "lib/tty/color.h"
42 #include "lib/skin.h"
43 #include "lib/widget.h"
45 /*** global variables ****************************************************************************/
47 /*** file scope macro definitions ****************************************************************/
49 /*** file scope type declarations ****************************************************************/
51 /*** file scope variables ************************************************************************/
53 /*** file scope functions ************************************************************************/
55 static cb_ret_t
56 groupbox_callback (Widget * w, widget_msg_t msg, int parm)
58 WGroupbox *g = (WGroupbox *) w;
60 switch (msg)
62 case WIDGET_INIT:
63 return MSG_HANDLED;
65 case WIDGET_FOCUS:
66 return MSG_NOT_HANDLED;
68 case WIDGET_DRAW:
70 gboolean disabled = (w->options & W_DISABLED) != 0;
71 tty_setcolor (disabled ? DISABLED_COLOR : COLOR_NORMAL);
72 draw_box (g->widget.owner, g->widget.y - g->widget.owner->y,
73 g->widget.x - g->widget.owner->x, g->widget.lines, g->widget.cols, TRUE);
75 if (g->title != NULL)
77 tty_setcolor (disabled ? DISABLED_COLOR : COLOR_TITLE);
78 dlg_move (g->widget.owner, g->widget.y - g->widget.owner->y,
79 g->widget.x - g->widget.owner->x + 1);
80 tty_print_string (g->title);
82 return MSG_HANDLED;
85 case WIDGET_DESTROY:
86 g_free (g->title);
87 return MSG_HANDLED;
89 default:
90 return default_proc (msg, parm);
94 /* --------------------------------------------------------------------------------------------- */
95 /*** public functions ****************************************************************************/
96 /* --------------------------------------------------------------------------------------------- */
98 WGroupbox *
99 groupbox_new (int y, int x, int height, int width, const char *title)
101 WGroupbox *g;
103 g = g_new (WGroupbox, 1);
104 init_widget (&g->widget, y, x, height, width, groupbox_callback, NULL);
106 widget_want_cursor (g->widget, FALSE);
107 widget_want_hotkey (g->widget, FALSE);
109 /* Strip existing spaces, add one space before and after the title */
110 if (title != NULL)
112 char *t;
114 t = g_strstrip (g_strdup (title));
115 g->title = g_strconcat (" ", t, " ", (char *) NULL);
116 g_free (t);
119 return g;
122 /* --------------------------------------------------------------------------------------------- */