1 /* 2 Widgets for the Midnight Commander 3 4 Copyright (C) 1994-2020 5 Free Software Foundation, Inc. 6 7 Authors: 8 Radek Doulik, 1994, 1995 9 Miguel de Icaza, 1994, 1995 10 Jakub Jelinek, 1995 11 Andrej Borsenkow, 1996 12 Norbert Warmuth, 1997 13 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2013 14 15 This file is part of the Midnight Commander. 16 17 The Midnight Commander is free software: you can redistribute it 18 and/or modify it under the terms of the GNU General Public License as 19 published by the Free Software Foundation, either version 3 of the License, 20 or (at your option) any later version. 21 22 The Midnight Commander is distributed in the hope that it will be useful, 23 but WITHOUT ANY WARRANTY; without even the implied warranty of 24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 GNU General Public License for more details. 26 27 You should have received a copy of the GNU General Public License 28 along with this program. If not, see <http://www.gnu.org/licenses/>. 29 */ 30 31 /** \file groupbox.c 32 * \brief Source: WGroupbox widget 33 */ 34 35 #include <config.h> 36 37 #include "lib/global.h" 38 39 #include "lib/tty/tty.h" 40 #include "lib/tty/color.h" 41 #include "lib/skin.h" 42 #include "lib/util.h" 43 #include "lib/widget.h" 44 45 /*** global variables ****************************************************************************/ 46 47 /*** file scope macro definitions ****************************************************************/ 48 49 /*** file scope type declarations ****************************************************************/ 50 51 /*** file scope variables ************************************************************************/ 52 53 /*** file scope functions ************************************************************************/ 54 55 static cb_ret_t 56 groupbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) /**/ 57 { 58 WGroupbox *g = GROUPBOX (w); 59 60 switch (msg) 61 { 62 case MSG_DRAW: 63 { 64 gboolean disabled; 65 const int *colors; 66 67 colors = widget_get_colors (w); 68 69 disabled = widget_get_state (w, WST_DISABLED); 70 tty_setcolor (disabled ? DISABLED_COLOR : colors[DLG_COLOR_NORMAL]); 71 tty_draw_box (w->y, w->x, w->lines, w->cols, TRUE); 72 73 if (g->title != NULL) 74 { 75 tty_setcolor (disabled ? DISABLED_COLOR : colors[DLG_COLOR_TITLE]); 76 widget_gotoyx (w, 0, 1); 77 tty_print_string (g->title); 78 } 79 return MSG_HANDLED; 80 } 81 82 case MSG_DESTROY: 83 g_free (g->title); 84 return MSG_HANDLED; 85 86 default: 87 return widget_default_callback (w, sender, msg, parm, data); 88 } 89 } 90 91 /* --------------------------------------------------------------------------------------------- */ 92 /*** public functions ****************************************************************************/ 93 /* --------------------------------------------------------------------------------------------- */ 94 95 WGroupbox * 96 groupbox_new (int y, int x, int height, int width, const char *title) /*
*/ 97 { 98 WGroupbox *g; 99 Widget *w; 100 101 g = g_new (WGroupbox, 1); 102 w = WIDGET (g); 103 widget_init (w, y, x, height, width, groupbox_callback, NULL); 104 105 g->title = NULL; 106 groupbox_set_title (g, title); 107 108 return g; 109 } 110 111 /* --------------------------------------------------------------------------------------------- */ 112 113 void 114 groupbox_set_title (WGroupbox * g, const char *title) /*
*/ 115 { 116 MC_PTR_FREE (g->title); 117 118 /* Strip existing spaces, add one space before and after the title */ 119 if (title != NULL && *title != '\0') 120 { 121 char *t; 122 123 t = g_strstrip (g_strdup (title)); 124 g->title = g_strconcat (" ", t, " ", (char *) NULL); 125 g_free (t); 126 } 127 128 widget_draw (WIDGET (g)); 129 } 130 131 /* --------------------------------------------------------------------------------------------- */