summaryrefslogtreecommitdiffstats
path: root/lib/widget/background.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 17:44:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 17:44:12 +0000
commit8ccb487c21368a7fdc8c7c72315325bf0aa06147 (patch)
treeb2056fae01d325924508a41731edfbd4c3cddd23 /lib/widget/background.c
parentInitial commit. (diff)
downloadmc-8ccb487c21368a7fdc8c7c72315325bf0aa06147.tar.xz
mc-8ccb487c21368a7fdc8c7c72315325bf0aa06147.zip
Adding upstream version 3:4.8.29.upstream/3%4.8.29upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/widget/background.c')
-rw-r--r--lib/widget/background.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/lib/widget/background.c b/lib/widget/background.c
new file mode 100644
index 0000000..f085312
--- /dev/null
+++ b/lib/widget/background.c
@@ -0,0 +1,124 @@
+/*
+ Widgets for the Midnight Commander
+
+ Copyright (C) 2020-2022
+ The Free Software Foundation, Inc.
+
+ Authors:
+ Andrew Borodin <aborodin@vmail.ru>, 2020-2022
+
+ 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 background.c
+ * \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 ****************************************************************/
+
+/*** file scope variables ************************************************************************/
+
+/* --------------------------------------------------------------------------------------------- */
+/*** file scope functions ************************************************************************/
+/* --------------------------------------------------------------------------------------------- */
+
+static const int *
+background_get_colors (const Widget * w)
+{
+ return &(CONST_BACKGROUND (w)->color);
+}
+
+/* --------------------------------------------------------------------------------------------- */
+
+static void
+background_adjust (WBackground * b)
+{
+ Widget *w = WIDGET (b);
+
+ w->rect = WIDGET (w->owner)->rect;
+ w->pos_flags |= WPOS_KEEP_ALL;
+}
+
+/* --------------------------------------------------------------------------------------------- */
+
+static void
+background_draw (const WBackground * b)
+{
+ const Widget *w = CONST_WIDGET (b);
+
+ tty_setcolor (b->color);
+ tty_fill_region (w->rect.y, w->rect.x, w->rect.lines, w->rect.cols, b->pattern);
+}
+
+/* --------------------------------------------------------------------------------------------- */
+/*** public functions ****************************************************************************/
+/* --------------------------------------------------------------------------------------------- */
+
+cb_ret_t
+background_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
+{
+ 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)
+{
+ WRect r = { y, x, lines, cols };
+ WBackground *b;
+ Widget *w;
+
+ b = g_new (WBackground, 1);
+ w = WIDGET (b);
+ widget_init (w, &r, callback != NULL ? callback : background_callback, NULL);
+ w->get_colors = background_get_colors;
+
+ b->color = color;
+ b->pattern = pattern;
+
+ return b;
+}
+
+/* --------------------------------------------------------------------------------------------- */