1 /* Widgets for the Midnight Commander
3 Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
6 Authors: 1994, 1995 Radek Doulik
7 1994, 1995 Miguel de Icaza
11 2009, 2010 Andrew Borodin
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 * \brief Source: WLabel widget
38 #include "lib/global.h"
40 #include "lib/tty/tty.h"
41 #include "lib/tty/color.h"
43 #include "lib/strutil.h"
44 #include "lib/widget.h"
46 /*** global variables ****************************************************************************/
48 /*** file scope macro definitions ****************************************************************/
50 /*** file scope type declarations ****************************************************************/
52 /*** file scope variables ************************************************************************/
54 /*** file scope functions ************************************************************************/
57 label_callback (Widget
* w
, widget_msg_t msg
, int parm
)
59 WLabel
*l
= (WLabel
*) w
;
60 Dlg_head
*h
= l
->widget
.owner
;
67 /* We don't want to get the focus */
69 return MSG_NOT_HANDLED
;
75 gboolean disabled
= (w
->options
& W_DISABLED
) != 0;
81 tty_setcolor (disabled
? DISABLED_COLOR
: DEFAULT_COLOR
);
83 tty_setcolor (disabled
? DISABLED_COLOR
: h
->color
[DLG_COLOR_NORMAL
]);
97 widget_move (&l
->widget
, y
, 0);
98 tty_print_string (str_fit_to_term (p
, l
->widget
.cols
, J_LEFT
));
115 return default_proc (msg
, parm
);
119 /* --------------------------------------------------------------------------------------------- */
120 /*** public functions ****************************************************************************/
121 /* --------------------------------------------------------------------------------------------- */
124 label_new (int y
, int x
, const char *text
)
131 str_msg_term_size (text
, &lines
, &cols
);
133 l
= g_new (WLabel
, 1);
134 init_widget (&l
->widget
, y
, x
, lines
, cols
, label_callback
, NULL
);
135 l
->text
= g_strdup (text
);
136 l
->auto_adjust_cols
= TRUE
;
137 l
->transparent
= FALSE
;
138 widget_want_cursor (l
->widget
, FALSE
);
139 widget_want_hotkey (l
->widget
, FALSE
);
144 /* --------------------------------------------------------------------------------------------- */
147 label_set_text (WLabel
* label
, const char *text
)
149 int newcols
= label
->widget
.cols
;
152 if (label
->text
!= NULL
&& text
!= NULL
&& strcmp (label
->text
, text
) == 0)
153 return; /* Flickering is not nice */
155 g_free (label
->text
);
161 label
->text
= g_strdup (text
);
162 if (label
->auto_adjust_cols
)
164 str_msg_term_size (text
, &newlines
, &newcols
);
165 if (newcols
> label
->widget
.cols
)
166 label
->widget
.cols
= newcols
;
167 if (newlines
> label
->widget
.lines
)
168 label
->widget
.lines
= newlines
;
172 if (label
->widget
.owner
!= NULL
)
173 label_callback ((Widget
*) label
, WIDGET_DRAW
, 0);
175 if (newcols
< label
->widget
.cols
)
176 label
->widget
.cols
= newcols
;
179 /* --------------------------------------------------------------------------------------------- */