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.
29 /** \file widget-common.c
30 * \brief Source: shared stuff of widgets
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 ************************************************************************/
56 /* --------------------------------------------------------------------------------------------- */
57 /*** public functions ****************************************************************************/
58 /* --------------------------------------------------------------------------------------------- */
61 parse_hotkey (const char *text
)
69 /* search for '&', that is not on the of text */
70 cp
= strchr (text
, '&');
71 if (cp
!= NULL
&& cp
[1] != '\0')
73 result
.start
= g_strndup (text
, cp
- text
);
77 p
= str_cget_next_char (cp
);
78 result
.hotkey
= g_strndup (cp
, p
- cp
);
81 result
.end
= g_strdup (cp
);
85 result
.start
= g_strdup (text
);
93 /* --------------------------------------------------------------------------------------------- */
96 release_hotkey (const hotkey_t hotkey
)
98 g_free (hotkey
.start
);
99 g_free (hotkey
.hotkey
);
103 /* --------------------------------------------------------------------------------------------- */
106 hotkey_width (const hotkey_t hotkey
)
110 result
= str_term_width1 (hotkey
.start
);
111 result
+= (hotkey
.hotkey
!= NULL
) ? str_term_width1 (hotkey
.hotkey
) : 0;
112 result
+= (hotkey
.end
!= NULL
) ? str_term_width1 (hotkey
.end
) : 0;
116 /* --------------------------------------------------------------------------------------------- */
119 hotkey_draw (Widget
* w
, const hotkey_t hotkey
, gboolean focused
)
121 widget_selectcolor (w
, focused
, FALSE
);
122 tty_print_string (hotkey
.start
);
124 if (hotkey
.hotkey
!= NULL
)
126 widget_selectcolor (w
, focused
, TRUE
);
127 tty_print_string (hotkey
.hotkey
);
128 widget_selectcolor (w
, focused
, FALSE
);
131 if (hotkey
.end
!= NULL
)
132 tty_print_string (hotkey
.end
);
135 /* --------------------------------------------------------------------------------------------- */
138 init_widget (Widget
* w
, int y
, int x
, int lines
, int cols
,
139 callback_fn callback
, mouse_h mouse_handler
)
145 w
->callback
= callback
;
146 w
->mouse
= mouse_handler
;
149 /* Almost all widgets want to put the cursor in a suitable place */
150 w
->options
= W_WANT_CURSOR
;
153 /* --------------------------------------------------------------------------------------------- */
155 /* Default callback for widgets */
157 default_proc (widget_msg_t msg
, int parm
)
173 return MSG_NOT_HANDLED
;
177 /* --------------------------------------------------------------------------------------------- */
180 widget_set_size (Widget
* widget
, int y
, int x
, int lines
, int cols
)
185 widget
->lines
= lines
;
186 send_message (widget
, WIDGET_RESIZED
, 0 /* unused */ );
189 /* --------------------------------------------------------------------------------------------- */
192 widget_selectcolor (Widget
* w
, gboolean focused
, gboolean hotkey
)
194 Dlg_head
*h
= w
->owner
;
197 if ((w
->options
& W_DISABLED
) != 0)
198 color
= DISABLED_COLOR
;
202 color
= h
->color
[DLG_COLOR_HOT_FOCUS
];
204 color
= h
->color
[DLG_COLOR_HOT_NORMAL
];
209 color
= h
->color
[DLG_COLOR_FOCUS
];
211 color
= h
->color
[DLG_COLOR_NORMAL
];
214 tty_setcolor (color
);
217 /* --------------------------------------------------------------------------------------------- */
220 widget_erase (Widget
* w
)
223 tty_fill_region (w
->y
, w
->x
, w
->lines
, w
->cols
, ' ');
226 /* --------------------------------------------------------------------------------------------- */