2 Widgets for the Midnight Commander
4 Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
5 2004, 2005, 2006, 2007, 2009, 2010, 2011
6 The Free Software Foundation, Inc.
9 Radek Doulik, 1994, 1995
10 Miguel de Icaza, 1994, 1995
12 Andrej Borsenkow, 1996
14 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010
16 This file is part of the Midnight Commander.
18 The Midnight Commander is free software: you can redistribute it
19 and/or modify it under the terms of the GNU General Public License as
20 published by the Free Software Foundation, either version 3 of the License,
21 or (at your option) any later version.
23 The Midnight Commander is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
28 You should have received a copy of the GNU General Public License
29 along with this program. If not, see <http://www.gnu.org/licenses/>.
33 * \brief Source: WLabel widget
41 #include "lib/global.h"
43 #include "lib/tty/tty.h"
44 #include "lib/tty/color.h"
46 #include "lib/strutil.h"
47 #include "lib/widget.h"
49 /*** global variables ****************************************************************************/
51 /*** file scope macro definitions ****************************************************************/
53 /*** file scope type declarations ****************************************************************/
55 /*** file scope variables ************************************************************************/
57 /*** file scope functions ************************************************************************/
60 label_callback (Widget
* w
, widget_msg_t msg
, int parm
)
62 WLabel
*l
= (WLabel
*) w
;
63 Dlg_head
*h
= w
->owner
;
70 /* We don't want to get the focus */
72 return MSG_NOT_HANDLED
;
78 gboolean disabled
= (w
->options
& W_DISABLED
) != 0;
84 tty_setcolor (disabled
? DISABLED_COLOR
: DEFAULT_COLOR
);
86 tty_setcolor (disabled
? DISABLED_COLOR
: h
->color
[DLG_COLOR_NORMAL
]);
100 widget_move (w
, y
, 0);
101 tty_print_string (str_fit_to_term (p
, w
->cols
, J_LEFT
));
118 return default_proc (msg
, parm
);
122 /* --------------------------------------------------------------------------------------------- */
123 /*** public functions ****************************************************************************/
124 /* --------------------------------------------------------------------------------------------- */
127 label_new (int y
, int x
, const char *text
)
135 str_msg_term_size (text
, &lines
, &cols
);
137 l
= g_new (WLabel
, 1);
139 init_widget (w
, y
, x
, lines
, cols
, label_callback
, NULL
);
141 l
->text
= g_strdup (text
);
142 l
->auto_adjust_cols
= TRUE
;
143 l
->transparent
= FALSE
;
144 widget_want_cursor (w
, FALSE
);
145 widget_want_hotkey (w
, FALSE
);
150 /* --------------------------------------------------------------------------------------------- */
153 label_set_text (WLabel
* label
, const char *text
)
155 Widget
*w
= WIDGET (label
);
156 int newcols
= w
->cols
;
159 if (label
->text
!= NULL
&& text
!= NULL
&& strcmp (label
->text
, text
) == 0)
160 return; /* Flickering is not nice */
162 g_free (label
->text
);
168 label
->text
= g_strdup (text
);
169 if (label
->auto_adjust_cols
)
171 str_msg_term_size (text
, &newlines
, &newcols
);
172 if (newcols
> w
->cols
)
174 if (newlines
> w
->lines
)
179 if (w
->owner
!= NULL
)
180 label_callback (w
, WIDGET_DRAW
, 0);
182 if (newcols
< w
->cols
)
186 /* --------------------------------------------------------------------------------------------- */