root/lib/widget/hline.c

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

DEFINITIONS

This source file includes following definitions.
  1. hline_callback
  2. hline_new
  3. hline_set_text

   1 /*
   2    Widgets for the Midnight Commander
   3 
   4    Copyright (C) 1994-2019
   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 hline.c
  32  *  \brief Source: WHLine widget (horizontal line)
  33  */
  34 
  35 #include <config.h>
  36 
  37 #include <stdlib.h>
  38 
  39 #include "lib/global.h"
  40 #include "lib/tty/tty.h"
  41 #include "lib/tty/color.h"
  42 #include "lib/skin.h"
  43 #include "lib/strutil.h"
  44 #include "lib/widget.h"
  45 
  46 /*** global variables ****************************************************************************/
  47 
  48 /*** file scope macro definitions ****************************************************************/
  49 
  50 /*** file scope type declarations ****************************************************************/
  51 
  52 /*** file scope variables ************************************************************************/
  53 
  54 /*** file scope functions ************************************************************************/
  55 
  56 static cb_ret_t
  57 hline_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
  58 {
  59     WHLine *l = HLINE (w);
  60     WDialog *h = w->owner;
  61 
  62     switch (msg)
  63     {
  64     case MSG_INIT:
  65     case MSG_RESIZE:
  66         if (l->auto_adjust_cols)
  67         {
  68             Widget *wo = WIDGET (h);
  69 
  70             if (h->compact)
  71             {
  72                 w->x = wo->x;
  73                 w->cols = wo->cols;
  74             }
  75             else
  76             {
  77                 w->x = wo->x + 1;
  78                 w->cols = wo->cols - 2;
  79             }
  80         }
  81         return MSG_HANDLED;
  82 
  83     case MSG_DRAW:
  84         if (l->transparent)
  85             tty_setcolor (DEFAULT_COLOR);
  86         else
  87             tty_setcolor (h->color[DLG_COLOR_NORMAL]);
  88 
  89         tty_draw_hline (w->y, w->x + 1, ACS_HLINE, w->cols - 2);
  90 
  91         if (l->auto_adjust_cols)
  92         {
  93             widget_move (w, 0, 0);
  94             tty_print_alt_char (ACS_LTEE, FALSE);
  95             widget_move (w, 0, w->cols - 1);
  96             tty_print_alt_char (ACS_RTEE, FALSE);
  97         }
  98 
  99         if (l->text != NULL)
 100         {
 101             int text_width;
 102 
 103             text_width = str_term_width1 (l->text);
 104             widget_move (w, 0, (w->cols - text_width) / 2);
 105             tty_print_string (l->text);
 106         }
 107         return MSG_HANDLED;
 108 
 109     case MSG_DESTROY:
 110         g_free (l->text);
 111         return MSG_HANDLED;
 112 
 113     default:
 114         return widget_default_callback (w, sender, msg, parm, data);
 115     }
 116 }
 117 
 118 /* --------------------------------------------------------------------------------------------- */
 119 /*** public functions ****************************************************************************/
 120 /* --------------------------------------------------------------------------------------------- */
 121 
 122 WHLine *
 123 hline_new (int y, int x, int width)
     /* [previous][next][first][last][top][bottom][index][help]  */
 124 {
 125     WHLine *l;
 126     Widget *w;
 127     int lines = 1;
 128 
 129     l = g_new (WHLine, 1);
 130     w = WIDGET (l);
 131     widget_init (w, y, x, lines, width < 0 ? 1 : width, hline_callback, NULL);
 132     l->text = NULL;
 133     l->auto_adjust_cols = (width < 0);
 134     l->transparent = FALSE;
 135 
 136     return l;
 137 }
 138 
 139 /* --------------------------------------------------------------------------------------------- */
 140 
 141 void
 142 hline_set_text (WHLine * l, const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 143 {
 144     g_free (l->text);
 145 
 146     if (text == NULL || *text == '\0')
 147         l->text = NULL;
 148     else
 149         l->text = g_strdup (text);
 150 
 151     widget_redraw (WIDGET (l));
 152 }
 153 
 154 /* --------------------------------------------------------------------------------------------- */

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