39aeccd55a6894647d55dac6579a35eaa3cfb941
[midnight-commander.git] / lib / widget / groupbox.c
blob39aeccd55a6894647d55dac6579a35eaa3cfb941
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 * sender, widget_msg_t msg, int parm, void *data)
58 WGroupbox *g = GROUPBOX (w);
60 switch (msg)
62 case MSG_INIT:
63 return MSG_HANDLED;
65 case MSG_FOCUS:
66 return MSG_NOT_HANDLED;
68 case MSG_DRAW:
70 Widget *wo = WIDGET (w->owner);
72 gboolean disabled = (w->options & W_DISABLED) != 0;
73 tty_setcolor (disabled ? DISABLED_COLOR : COLOR_NORMAL);
74 draw_box (w->owner, w->y - wo->y, w->x - wo->x, w->lines, w->cols, TRUE);
76 if (g->title != NULL)
78 tty_setcolor (disabled ? DISABLED_COLOR : COLOR_TITLE);
79 widget_move (w->owner, w->y - wo->y, w->x - wo->x + 1);
80 tty_print_string (g->title);
82 return MSG_HANDLED;
85 case MSG_DESTROY:
86 g_free (g->title);
87 return MSG_HANDLED;
89 default:
90 return widget_default_callback (w, sender, msg, parm, data);
94 /* --------------------------------------------------------------------------------------------- */
95 /*** public functions ****************************************************************************/
96 /* --------------------------------------------------------------------------------------------- */
98 WGroupbox *
99 groupbox_new (int y, int x, int height, int width, const char *title)
101 WGroupbox *g;
102 Widget *w;
104 g = g_new (WGroupbox, 1);
105 w = WIDGET (g);
106 init_widget (w, y, x, height, width, groupbox_callback, NULL);
108 widget_want_cursor (w, FALSE);
109 widget_want_hotkey (w, FALSE);
111 g->title = NULL;
112 groupbox_set_title (g, title);
114 return g;
117 /* --------------------------------------------------------------------------------------------- */
119 void
120 groupbox_set_title (WGroupbox *g, const char *title)
122 Widget *w = WIDGET (g);
124 g_free (g->title);
125 g->title = NULL;
127 /* Strip existing spaces, add one space before and after the title */
128 if (title != NULL && *title != '\0')
130 char *t;
132 t = g_strstrip (g_strdup (title));
133 g->title = g_strconcat (" ", t, " ", (char *) NULL);
134 g_free (t);
137 if (w->owner != NULL)
138 send_message (w, NULL, MSG_DRAW, 0, NULL);
141 /* --------------------------------------------------------------------------------------------- */