2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
Widgets for the Midnight Commander
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2023-01-03 11:30:57 +03:00
|
|
|
Copyright (C) 1994-2023
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
Authors:
|
|
|
|
Radek Doulik, 1994, 1995
|
|
|
|
Miguel de Icaza, 1994, 1995
|
|
|
|
Jakub Jelinek, 1995
|
|
|
|
Andrej Borsenkow, 1996
|
|
|
|
Norbert Warmuth, 1997
|
2022-05-01 10:43:33 +03:00
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2009-2022
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
This file is part of the Midnight Commander.
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is free software: you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
2010-11-12 11:03:57 +03:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-11-12 11:03:57 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file groupbox.c
|
|
|
|
* \brief Source: WGroupbox widget
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "lib/global.h"
|
|
|
|
|
|
|
|
#include "lib/tty/tty.h"
|
|
|
|
#include "lib/tty/color.h"
|
|
|
|
#include "lib/skin.h"
|
2014-08-05 11:18:30 +04:00
|
|
|
#include "lib/util.h"
|
2010-11-12 11:03:57 +03:00
|
|
|
#include "lib/widget.h"
|
|
|
|
|
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
|
|
|
|
static cb_ret_t
|
2012-06-26 11:52:21 +04:00
|
|
|
groupbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
2012-10-11 12:25:07 +04:00
|
|
|
WGroupbox *g = GROUPBOX (w);
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_DRAW:
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
2013-04-23 14:10:20 +04:00
|
|
|
gboolean disabled;
|
2019-11-17 17:58:52 +03:00
|
|
|
const int *colors;
|
|
|
|
|
|
|
|
colors = widget_get_colors (w);
|
2012-06-20 12:05:13 +04:00
|
|
|
|
2016-04-10 12:26:48 +03:00
|
|
|
disabled = widget_get_state (w, WST_DISABLED);
|
2019-11-17 17:58:52 +03:00
|
|
|
tty_setcolor (disabled ? DISABLED_COLOR : colors[DLG_COLOR_NORMAL]);
|
2022-05-01 10:43:33 +03:00
|
|
|
tty_draw_box (w->rect.y, w->rect.x, w->rect.lines, w->rect.cols, TRUE);
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
if (g->title != NULL)
|
|
|
|
{
|
2019-11-17 17:58:52 +03:00
|
|
|
tty_setcolor (disabled ? DISABLED_COLOR : colors[DLG_COLOR_TITLE]);
|
2019-10-16 13:07:24 +03:00
|
|
|
widget_gotoyx (w, 0, 1);
|
2010-11-12 11:03:57 +03:00
|
|
|
tty_print_string (g->title);
|
|
|
|
}
|
|
|
|
return MSG_HANDLED;
|
|
|
|
}
|
|
|
|
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_DESTROY:
|
2010-11-12 11:03:57 +03:00
|
|
|
g_free (g->title);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
|
|
default:
|
2012-09-28 15:05:43 +04:00
|
|
|
return widget_default_callback (w, sender, msg, parm, data);
|
2010-11-12 11:03:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
WGroupbox *
|
|
|
|
groupbox_new (int y, int x, int height, int width, const char *title)
|
|
|
|
{
|
2022-05-21 16:11:06 +03:00
|
|
|
WRect r = { y, x, height, width };
|
2010-11-12 11:03:57 +03:00
|
|
|
WGroupbox *g;
|
2012-06-20 15:09:44 +04:00
|
|
|
Widget *w;
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
g = g_new (WGroupbox, 1);
|
2012-06-20 15:09:44 +04:00
|
|
|
w = WIDGET (g);
|
2022-05-21 16:11:06 +03:00
|
|
|
widget_init (w, &r, groupbox_callback, NULL);
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2012-09-20 12:48:43 +04:00
|
|
|
g->title = NULL;
|
2012-09-21 11:55:57 +04:00
|
|
|
groupbox_set_title (g, title);
|
|
|
|
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
2012-11-20 13:27:10 +04:00
|
|
|
groupbox_set_title (WGroupbox * g, const char *title)
|
2012-09-21 11:55:57 +04:00
|
|
|
{
|
2014-08-05 11:18:30 +04:00
|
|
|
MC_PTR_FREE (g->title);
|
2012-09-21 11:55:57 +04:00
|
|
|
|
2010-11-12 11:03:57 +03:00
|
|
|
/* Strip existing spaces, add one space before and after the title */
|
2012-09-20 12:48:43 +04:00
|
|
|
if (title != NULL && *title != '\0')
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
t = g_strstrip (g_strdup (title));
|
|
|
|
g->title = g_strconcat (" ", t, " ", (char *) NULL);
|
|
|
|
g_free (t);
|
|
|
|
}
|
|
|
|
|
2019-10-18 15:44:57 +03:00
|
|
|
widget_draw (WIDGET (g));
|
2010-11-12 11:03:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|