2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
Widgets for the Midnight Commander
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 1994-2024
|
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 hline.c
|
|
|
|
* \brief Source: WHLine widget (horizontal line)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2020-05-10 14:00:04 +03:00
|
|
|
#include <stdarg.h>
|
2010-11-12 11:03:57 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "lib/global.h"
|
|
|
|
#include "lib/tty/tty.h"
|
|
|
|
#include "lib/tty/color.h"
|
|
|
|
#include "lib/skin.h"
|
2012-12-24 14:54:10 +04:00
|
|
|
#include "lib/strutil.h"
|
2010-11-12 11:03:57 +03:00
|
|
|
#include "lib/widget.h"
|
|
|
|
|
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/*** forward declarations (file scope functions) *************************************************/
|
|
|
|
|
2010-11-12 11:03:57 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
2016-10-13 10:15:03 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-12 11:03:57 +03:00
|
|
|
/*** file scope functions ************************************************************************/
|
2016-10-13 10:15:03 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2024-06-01 21:12:14 +03:00
|
|
|
hline_adjust_cols (WHLine *l)
|
2016-10-13 10:15:03 +03:00
|
|
|
{
|
|
|
|
if (l->auto_adjust_cols)
|
|
|
|
{
|
2022-05-01 10:43:33 +03:00
|
|
|
Widget *wl = WIDGET (l);
|
|
|
|
const Widget *o = CONST_WIDGET (wl->owner);
|
|
|
|
WRect *w = &wl->rect;
|
|
|
|
const WRect *wo = &o->rect;
|
2016-10-13 10:15:03 +03:00
|
|
|
|
2022-05-01 10:43:33 +03:00
|
|
|
if (CONST_DIALOG (o)->compact)
|
2016-10-13 10:15:03 +03:00
|
|
|
{
|
|
|
|
w->x = wo->x;
|
|
|
|
w->cols = wo->cols;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w->x = wo->x + 1;
|
|
|
|
w->cols = wo->cols - 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
static cb_ret_t
|
2024-06-01 21:12:14 +03:00
|
|
|
hline_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
|
|
|
WHLine *l = HLINE (w);
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_INIT:
|
2016-10-13 10:15:03 +03:00
|
|
|
hline_adjust_cols (l);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_RESIZE:
|
2016-10-13 10:15:03 +03:00
|
|
|
hline_adjust_cols (l);
|
2022-05-01 10:43:33 +03:00
|
|
|
w->rect.y = RECT (data)->y;
|
2013-07-31 10:38:48 +04:00
|
|
|
return MSG_HANDLED;
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_DRAW:
|
2010-11-12 11:03:57 +03:00
|
|
|
if (l->transparent)
|
|
|
|
tty_setcolor (DEFAULT_COLOR);
|
|
|
|
else
|
2019-11-17 17:58:52 +03:00
|
|
|
{
|
|
|
|
const int *colors;
|
|
|
|
|
|
|
|
colors = widget_get_colors (w);
|
|
|
|
tty_setcolor (colors[DLG_COLOR_NORMAL]);
|
|
|
|
}
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2022-05-01 10:43:33 +03:00
|
|
|
tty_draw_hline (w->rect.y, w->rect.x + 1, ACS_HLINE, w->rect.cols - 2);
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
if (l->auto_adjust_cols)
|
|
|
|
{
|
2019-10-16 13:07:24 +03:00
|
|
|
widget_gotoyx (w, 0, 0);
|
2010-11-12 11:03:57 +03:00
|
|
|
tty_print_alt_char (ACS_LTEE, FALSE);
|
2022-05-01 10:43:33 +03:00
|
|
|
widget_gotoyx (w, 0, w->rect.cols - 1);
|
2010-11-12 11:03:57 +03:00
|
|
|
tty_print_alt_char (ACS_RTEE, FALSE);
|
|
|
|
}
|
2012-12-24 14:54:10 +04:00
|
|
|
|
|
|
|
if (l->text != NULL)
|
|
|
|
{
|
|
|
|
int text_width;
|
|
|
|
|
|
|
|
text_width = str_term_width1 (l->text);
|
2022-05-01 10:43:33 +03:00
|
|
|
widget_gotoyx (w, 0, (w->rect.cols - text_width) / 2);
|
2012-12-24 14:54:10 +04:00
|
|
|
tty_print_string (l->text);
|
|
|
|
}
|
2010-11-12 11:03:57 +03:00
|
|
|
return MSG_HANDLED;
|
|
|
|
|
2015-05-09 16:26:40 +03:00
|
|
|
case MSG_DESTROY:
|
|
|
|
g_free (l->text);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
2010-11-12 11:03:57 +03:00
|
|
|
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 ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
WHLine *
|
|
|
|
hline_new (int y, int x, int width)
|
|
|
|
{
|
2022-05-21 16:11:06 +03:00
|
|
|
WRect r = { y, x, 1, width };
|
2010-11-12 11:03:57 +03:00
|
|
|
WHLine *l;
|
2012-06-20 15:09:44 +04:00
|
|
|
Widget *w;
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
l = g_new (WHLine, 1);
|
2012-06-20 15:09:44 +04:00
|
|
|
w = WIDGET (l);
|
2022-05-21 16:11:06 +03:00
|
|
|
r.cols = width < 0 ? 1 : width;
|
|
|
|
widget_init (w, &r, hline_callback, NULL);
|
2012-12-24 14:54:10 +04:00
|
|
|
l->text = NULL;
|
2010-11-12 11:03:57 +03:00
|
|
|
l->auto_adjust_cols = (width < 0);
|
|
|
|
l->transparent = FALSE;
|
|
|
|
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2012-12-24 14:54:10 +04:00
|
|
|
|
|
|
|
void
|
2024-06-01 21:12:14 +03:00
|
|
|
hline_set_text (WHLine *l, const char *text)
|
2012-12-24 14:54:10 +04:00
|
|
|
{
|
|
|
|
g_free (l->text);
|
|
|
|
|
|
|
|
if (text == NULL || *text == '\0')
|
|
|
|
l->text = NULL;
|
|
|
|
else
|
|
|
|
l->text = g_strdup (text);
|
|
|
|
|
2019-10-18 15:44:57 +03:00
|
|
|
widget_draw (WIDGET (l));
|
2012-12-24 14:54:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2020-05-10 14:00:04 +03:00
|
|
|
|
|
|
|
void
|
2024-06-01 21:12:14 +03:00
|
|
|
hline_set_textv (WHLine *l, const char *format, ...)
|
2020-05-10 14:00:04 +03:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char buf[BUF_1K]; /* FIXME: is it enough? */
|
|
|
|
|
|
|
|
va_start (args, format);
|
|
|
|
g_vsnprintf (buf, sizeof (buf), format, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
hline_set_text (l, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|