src/filemanager/filegui.c: fix coding style.
[midnight-commander.git] / lib / widget / groupbox.c
blobf3a377d5cf375a8be2452fcb9f1e712a066edf51
1 /*
2 Widgets for the Midnight Commander
4 Copyright (C) 1994-2019
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 groupbox.c
32 * \brief Source: WGroupbox widget
35 #include <config.h>
37 #include "lib/global.h"
39 #include "lib/tty/tty.h"
40 #include "lib/tty/color.h"
41 #include "lib/skin.h"
42 #include "lib/util.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_DRAW:
64 WDialog *h = w->owner;
66 gboolean disabled;
68 disabled = widget_get_state (w, WST_DISABLED);
69 tty_setcolor (disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]);
70 tty_draw_box (w->y, w->x, w->lines, w->cols, TRUE);
72 if (g->title != NULL)
74 tty_setcolor (disabled ? DISABLED_COLOR : h->color[DLG_COLOR_TITLE]);
75 widget_move (w, 0, 1);
76 tty_print_string (g->title);
78 return MSG_HANDLED;
81 case MSG_DESTROY:
82 g_free (g->title);
83 return MSG_HANDLED;
85 default:
86 return widget_default_callback (w, sender, msg, parm, data);
90 /* --------------------------------------------------------------------------------------------- */
91 /*** public functions ****************************************************************************/
92 /* --------------------------------------------------------------------------------------------- */
94 WGroupbox *
95 groupbox_new (int y, int x, int height, int width, const char *title)
97 WGroupbox *g;
98 Widget *w;
100 g = g_new (WGroupbox, 1);
101 w = WIDGET (g);
102 widget_init (w, y, x, height, width, groupbox_callback, NULL);
104 g->title = NULL;
105 groupbox_set_title (g, title);
107 return g;
110 /* --------------------------------------------------------------------------------------------- */
112 void
113 groupbox_set_title (WGroupbox * g, const char *title)
115 MC_PTR_FREE (g->title);
117 /* Strip existing spaces, add one space before and after the title */
118 if (title != NULL && *title != '\0')
120 char *t;
122 t = g_strstrip (g_strdup (title));
123 g->title = g_strconcat (" ", t, " ", (char *) NULL);
124 g_free (t);
127 widget_redraw (WIDGET (g));
130 /* --------------------------------------------------------------------------------------------- */