2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
Widgets for the Midnight Commander
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2014-01-05 12:37:43 +04:00
|
|
|
Copyright (C) 1994-2014
|
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
|
2013-06-24 11:40:53 +04:00
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2013
|
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>
|
|
|
|
|
|
|
|
#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 ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
|
|
|
|
static cb_ret_t
|
2012-06-26 11:52:21 +04: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);
|
2012-09-28 11:18:45 +04:00
|
|
|
WDialog *h = w->owner;
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_INIT:
|
|
|
|
case MSG_RESIZE:
|
2010-11-12 11:03:57 +03:00
|
|
|
if (l->auto_adjust_cols)
|
|
|
|
{
|
2012-06-20 15:09:44 +04:00
|
|
|
Widget *wo = WIDGET (h);
|
2012-06-20 12:05:13 +04:00
|
|
|
|
2012-06-20 15:09:44 +04:00
|
|
|
if (((h->flags & DLG_COMPACT) != 0))
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
2012-06-20 12:05:13 +04:00
|
|
|
w->x = wo->x;
|
|
|
|
w->cols = wo->cols;
|
2010-11-12 11:03:57 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-20 12:05:13 +04:00
|
|
|
w->x = wo->x + 1;
|
|
|
|
w->cols = wo->cols - 2;
|
2010-11-12 11:03:57 +03:00
|
|
|
}
|
|
|
|
}
|
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_FOCUS:
|
2010-11-12 11:03:57 +03:00
|
|
|
/* We don't want to get the focus */
|
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
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
|
|
|
|
tty_setcolor (h->color[DLG_COLOR_NORMAL]);
|
|
|
|
|
|
|
|
tty_draw_hline (w->y, w->x + 1, ACS_HLINE, w->cols - 2);
|
|
|
|
|
|
|
|
if (l->auto_adjust_cols)
|
|
|
|
{
|
|
|
|
widget_move (w, 0, 0);
|
|
|
|
tty_print_alt_char (ACS_LTEE, FALSE);
|
|
|
|
widget_move (w, 0, w->cols - 1);
|
|
|
|
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);
|
|
|
|
widget_move (w, 0, (w->cols - text_width) / 2);
|
|
|
|
tty_print_string (l->text);
|
|
|
|
}
|
2010-11-12 11:03:57 +03:00
|
|
|
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 ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
WHLine *
|
|
|
|
hline_new (int y, int x, int width)
|
|
|
|
{
|
|
|
|
WHLine *l;
|
2012-06-20 15:09:44 +04:00
|
|
|
Widget *w;
|
2010-11-12 11:03:57 +03:00
|
|
|
int lines = 1;
|
|
|
|
|
|
|
|
l = g_new (WHLine, 1);
|
2012-06-20 15:09:44 +04:00
|
|
|
w = WIDGET (l);
|
2013-06-24 11:40:53 +04:00
|
|
|
widget_init (w, y, x, lines, width < 0 ? 1 : width, 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;
|
2012-06-20 15:09:44 +04:00
|
|
|
widget_want_cursor (w, FALSE);
|
|
|
|
widget_want_hotkey (w, FALSE);
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2012-12-24 14:54:10 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
hline_set_text (WHLine * l, const char *text)
|
|
|
|
{
|
|
|
|
g_free (l->text);
|
|
|
|
|
|
|
|
if (text == NULL || *text == '\0')
|
|
|
|
l->text = NULL;
|
|
|
|
else
|
|
|
|
l->text = g_strdup (text);
|
|
|
|
|
2013-02-11 15:35:00 +04:00
|
|
|
widget_redraw (WIDGET (l));
|
2012-12-24 14:54:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|