2016-10-16 11:01:30 +03:00
|
|
|
/*
|
|
|
|
Widgets for the Midnight Commander
|
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 2020-2024
|
2016-10-16 11:01:30 +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 11:01:30 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file frame.c
|
|
|
|
* \brief Source: WFrame widget (frame of dialogs)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "lib/global.h"
|
|
|
|
#include "lib/tty/tty.h"
|
|
|
|
#include "lib/tty/color.h"
|
|
|
|
#include "lib/skin.h"
|
|
|
|
#include "lib/strutil.h"
|
|
|
|
#include "lib/util.h" /* MC_PTR_FREE */
|
|
|
|
#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 11:01:30 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2024-06-01 21:12:14 +03:00
|
|
|
frame_adjust (WFrame *f)
|
2016-10-16 11:01:30 +03:00
|
|
|
{
|
|
|
|
Widget *w = WIDGET (f);
|
|
|
|
|
2022-05-01 10:43:33 +03:00
|
|
|
w->rect = WIDGET (w->owner)->rect;
|
2016-10-16 11:01:30 +03:00
|
|
|
w->pos_flags |= WPOS_KEEP_ALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2024-06-01 21:12:14 +03:00
|
|
|
frame_draw (const WFrame *f)
|
2016-10-16 11:01:30 +03:00
|
|
|
{
|
2022-05-01 10:43:33 +03:00
|
|
|
const Widget *wf = CONST_WIDGET (f);
|
|
|
|
const WRect *w = &wf->rect;
|
2016-10-16 11:01:30 +03:00
|
|
|
int d = f->compact ? 0 : 1;
|
2019-11-17 17:58:52 +03:00
|
|
|
const int *colors;
|
2016-10-16 11:01:30 +03:00
|
|
|
|
2022-05-01 10:43:33 +03:00
|
|
|
colors = widget_get_colors (wf);
|
2019-11-17 17:58:52 +03:00
|
|
|
|
2020-07-19 19:47:15 +03:00
|
|
|
if (mc_global.tty.shadows)
|
|
|
|
tty_draw_box_shadow (w->y, w->x, w->lines, w->cols, SHADOW_COLOR);
|
|
|
|
|
2019-11-17 17:58:52 +03:00
|
|
|
tty_setcolor (colors[FRAME_COLOR_NORMAL]);
|
2016-10-16 11:01:30 +03:00
|
|
|
tty_fill_region (w->y, w->x, w->lines, w->cols, ' ');
|
|
|
|
tty_draw_box (w->y + d, w->x + d, w->lines - 2 * d, w->cols - 2 * d, f->single);
|
|
|
|
|
|
|
|
if (f->title != NULL)
|
|
|
|
{
|
|
|
|
/* TODO: truncate long title */
|
2019-11-17 17:58:52 +03:00
|
|
|
tty_setcolor (colors[FRAME_COLOR_TITLE]);
|
2022-05-01 10:43:33 +03:00
|
|
|
widget_gotoyx (f, d, (w->cols - str_term_width1 (f->title)) / 2);
|
2016-10-16 11:01:30 +03:00
|
|
|
tty_print_string (f->title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
WFrame *
|
2019-11-17 17:58:52 +03:00
|
|
|
frame_new (int y, int x, int lines, int cols, const char *title, gboolean single, gboolean compact)
|
2016-10-16 11:01:30 +03:00
|
|
|
{
|
2022-05-21 16:11:06 +03:00
|
|
|
WRect r = { y, x, lines, cols };
|
2016-10-16 11:01:30 +03:00
|
|
|
WFrame *f;
|
|
|
|
Widget *w;
|
|
|
|
|
|
|
|
f = g_new (WFrame, 1);
|
|
|
|
w = WIDGET (f);
|
2022-05-21 16:11:06 +03:00
|
|
|
widget_init (w, &r, frame_callback, NULL);
|
2016-10-16 11:01:30 +03:00
|
|
|
|
|
|
|
f->single = single;
|
|
|
|
f->compact = compact;
|
|
|
|
|
|
|
|
f->title = NULL;
|
|
|
|
frame_set_title (f, title);
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
cb_ret_t
|
2024-06-01 21:12:14 +03:00
|
|
|
frame_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data)
|
2016-10-16 11:01:30 +03:00
|
|
|
{
|
|
|
|
WFrame *f = FRAME (w);
|
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case MSG_INIT:
|
|
|
|
frame_adjust (f);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
|
|
case MSG_DRAW:
|
|
|
|
frame_draw (f);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
|
|
case MSG_DESTROY:
|
|
|
|
g_free (f->title);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return widget_default_callback (w, sender, msg, parm, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
2024-06-01 21:12:14 +03:00
|
|
|
frame_set_title (WFrame *f, const char *title)
|
2016-10-16 11:01:30 +03:00
|
|
|
{
|
|
|
|
MC_PTR_FREE (f->title);
|
|
|
|
|
|
|
|
/* Strip existing spaces, add one space before and after the title */
|
|
|
|
if (title != NULL && *title != '\0')
|
|
|
|
{
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
t = g_strstrip (g_strdup (title));
|
|
|
|
if (*t != '\0')
|
|
|
|
f->title = g_strdup_printf (" %s ", t);
|
|
|
|
g_free (t);
|
|
|
|
}
|
|
|
|
|
|
|
|
widget_draw (WIDGET (f));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|