2016-10-16 15:52:33 +03:00
|
|
|
/*
|
|
|
|
Widgets for the Midnight Commander
|
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 2020-2024
|
2016-10-16 15:52:33 +03:00
|
|
|
The Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Authors:
|
2022-05-01 10:43:33 +03:00
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2020-2022
|
2016-10-16 15:52:33 +03:00
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
|
|
|
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,
|
|
|
|
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
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-04-25 12:35:32 +03:00
|
|
|
/** \file background.c
|
2016-10-16 15:52:33 +03:00
|
|
|
* \brief Source: WBackground widget (background area of dialog)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "lib/global.h"
|
|
|
|
#include "lib/tty/tty.h"
|
|
|
|
#include "lib/tty/color.h"
|
|
|
|
#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) *************************************************/
|
|
|
|
|
2016-10-16 15:52:33 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2019-11-17 17:58:52 +03:00
|
|
|
static const int *
|
2024-06-01 21:12:14 +03:00
|
|
|
background_get_colors (const Widget *w)
|
2019-11-17 17:58:52 +03:00
|
|
|
{
|
|
|
|
return &(CONST_BACKGROUND (w)->color);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2016-10-16 15:52:33 +03:00
|
|
|
static void
|
2024-06-01 21:12:14 +03:00
|
|
|
background_adjust (WBackground *b)
|
2016-10-16 15:52:33 +03:00
|
|
|
{
|
|
|
|
Widget *w = WIDGET (b);
|
|
|
|
|
2022-05-01 10:43:33 +03:00
|
|
|
w->rect = WIDGET (w->owner)->rect;
|
2016-10-16 15:52:33 +03:00
|
|
|
w->pos_flags |= WPOS_KEEP_ALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2024-06-01 21:12:14 +03:00
|
|
|
background_draw (const WBackground *b)
|
2016-10-16 15:52:33 +03:00
|
|
|
{
|
|
|
|
const Widget *w = CONST_WIDGET (b);
|
|
|
|
|
|
|
|
tty_setcolor (b->color);
|
2022-05-01 10:43:33 +03:00
|
|
|
tty_fill_region (w->rect.y, w->rect.x, w->rect.lines, w->rect.cols, b->pattern);
|
2016-10-16 15:52:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
cb_ret_t
|
2024-06-01 21:12:14 +03:00
|
|
|
background_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data)
|
2016-10-16 15:52:33 +03:00
|
|
|
{
|
|
|
|
WBackground *b = BACKGROUND (w);
|
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case MSG_INIT:
|
|
|
|
background_adjust (b);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
|
|
case MSG_DRAW:
|
|
|
|
background_draw (b);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return widget_default_callback (w, sender, msg, parm, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
WBackground *
|
|
|
|
background_new (int y, int x, int lines, int cols, int color, unsigned char pattern,
|
|
|
|
widget_cb_fn callback)
|
|
|
|
{
|
2022-05-21 16:11:06 +03:00
|
|
|
WRect r = { y, x, lines, cols };
|
2016-10-16 15:52:33 +03:00
|
|
|
WBackground *b;
|
|
|
|
Widget *w;
|
|
|
|
|
|
|
|
b = g_new (WBackground, 1);
|
|
|
|
w = WIDGET (b);
|
2022-05-21 16:11:06 +03:00
|
|
|
widget_init (w, &r, callback != NULL ? callback : background_callback, NULL);
|
2019-11-17 17:58:52 +03:00
|
|
|
w->get_colors = background_get_colors;
|
2016-10-16 15:52:33 +03:00
|
|
|
|
|
|
|
b->color = color;
|
|
|
|
b->pattern = pattern;
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|