root/lib/widget/groupbox.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. groupbox_callback
  2. groupbox_new
  3. groupbox_set_title

   1 /*
   2    Widgets for the Midnight Commander
   3 
   4    Copyright (C) 1994-2024
   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-2022
  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 /*** forward declarations (file scope functions) *************************************************/
  52 
  53 /*** file scope variables ************************************************************************/
  54 
  55 /* --------------------------------------------------------------------------------------------- */
  56 /*** file scope functions ************************************************************************/
  57 /* --------------------------------------------------------------------------------------------- */
  58 
  59 static cb_ret_t
  60 groupbox_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
  61 {
  62     WGroupbox *g = GROUPBOX (w);
  63 
  64     switch (msg)
  65     {
  66     case MSG_DRAW:
  67         {
  68             gboolean disabled;
  69             const int *colors;
  70 
  71             colors = widget_get_colors (w);
  72 
  73             disabled = widget_get_state (w, WST_DISABLED);
  74             tty_setcolor (disabled ? DISABLED_COLOR : colors[DLG_COLOR_NORMAL]);
  75             tty_draw_box (w->rect.y, w->rect.x, w->rect.lines, w->rect.cols, TRUE);
  76 
  77             if (g->title != NULL)
  78             {
  79                 tty_setcolor (disabled ? DISABLED_COLOR : colors[DLG_COLOR_TITLE]);
  80                 widget_gotoyx (w, 0, 1);
  81                 tty_print_string (g->title);
  82             }
  83             return MSG_HANDLED;
  84         }
  85 
  86     case MSG_DESTROY:
  87         g_free (g->title);
  88         return MSG_HANDLED;
  89 
  90     default:
  91         return widget_default_callback (w, sender, msg, parm, data);
  92     }
  93 }
  94 
  95 /* --------------------------------------------------------------------------------------------- */
  96 /*** public functions ****************************************************************************/
  97 /* --------------------------------------------------------------------------------------------- */
  98 
  99 WGroupbox *
 100 groupbox_new (int y, int x, int height, int width, const char *title)
     /* [previous][next][first][last][top][bottom][index][help]  */
 101 {
 102     WRect r = { y, x, height, width };
 103     WGroupbox *g;
 104     Widget *w;
 105 
 106     g = g_new (WGroupbox, 1);
 107     w = WIDGET (g);
 108     widget_init (w, &r, groupbox_callback, NULL);
 109 
 110     g->title = NULL;
 111     groupbox_set_title (g, title);
 112 
 113     return g;
 114 }
 115 
 116 /* --------------------------------------------------------------------------------------------- */
 117 
 118 void
 119 groupbox_set_title (WGroupbox *g, const char *title)
     /* [previous][next][first][last][top][bottom][index][help]  */
 120 {
 121     MC_PTR_FREE (g->title);
 122 
 123     /* Strip existing spaces, add one space before and after the title */
 124     if (title != NULL && *title != '\0')
 125     {
 126         char *t;
 127 
 128         t = g_strstrip (g_strdup (title));
 129         g->title = g_strconcat (" ", t, " ", (char *) NULL);
 130         g_free (t);
 131     }
 132 
 133     widget_draw (WIDGET (g));
 134 }
 135 
 136 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */