2 Widgets for the Midnight Commander
4 Copyright (C) 1994-2016
5 Free Software Foundation, Inc.
8 Radek Doulik, 1994, 1995
9 Miguel de Icaza, 1994, 1995
11 Andrej Borsenkow, 1996
13 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2013, 2016
15 This file is part of the Midnight Commander.
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.
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.
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/>.
32 * \brief Source: WRadui widget (radiobuttons)
39 #include "lib/global.h"
41 #include "lib/tty/tty.h"
42 #include "lib/widget.h"
44 /*** global variables ****************************************************************************/
46 /*** file scope macro definitions ****************************************************************/
48 /*** file scope type declarations ****************************************************************/
50 /*** file scope variables ************************************************************************/
52 /*** file scope functions ************************************************************************/
55 radio_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
57 WRadio
*r
= RADIO (w
);
63 for (i
= 0; i
< r
->count
; i
++)
65 if (r
->texts
[i
].hotkey
!= NULL
)
69 c
= g_ascii_tolower ((gchar
) r
->texts
[i
].hotkey
[0]);
75 send_message (w
, sender
, MSG_KEY
, ' ', data
);
79 return MSG_NOT_HANDLED
;
86 widget_set_state (w
, WST_FOCUSED
, TRUE
); /* Also draws the widget. */
87 send_message (w
->owner
, w
, MSG_NOTIFY
, (int) MSG_KEY
, NULL
);
98 return MSG_NOT_HANDLED
;
102 if (r
->count
- 1 > r
->pos
)
108 return MSG_NOT_HANDLED
;
111 return MSG_NOT_HANDLED
;
115 widget_move (r
, r
->pos
, 1);
122 focused
= widget_get_state (w
, WST_FOCUSED
);
124 for (i
= 0; i
< r
->count
; i
++)
126 widget_selectcolor (w
, i
== r
->pos
&& focused
, FALSE
);
127 widget_move (w
, i
, 0);
128 tty_draw_hline (w
->y
+ i
, w
->x
, ' ', w
->cols
);
129 tty_print_string ((r
->sel
== i
) ? "(*) " : "( ) ");
130 hotkey_draw (w
, r
->texts
[i
], i
== r
->pos
&& focused
);
137 for (i
= 0; i
< r
->count
; i
++)
138 release_hotkey (r
->texts
[i
]);
143 return widget_default_callback (w
, sender
, msg
, parm
, data
);
147 /* --------------------------------------------------------------------------------------------- */
150 radio_mouse_callback (Widget
* w
, mouse_msg_t msg
, mouse_event_t
* event
)
155 RADIO (w
)->pos
= event
->y
;
159 case MSG_MOUSE_CLICK
:
160 RADIO (w
)->pos
= event
->y
;
161 send_message (w
, NULL
, MSG_KEY
, ' ', NULL
);
162 send_message (w
->owner
, w
, MSG_POST_KEY
, ' ', NULL
);
170 /* --------------------------------------------------------------------------------------------- */
171 /*** public functions ****************************************************************************/
172 /* --------------------------------------------------------------------------------------------- */
175 radio_new (int y
, int x
, int count
, const char **texts
)
181 r
= g_new (WRadio
, 1);
184 /* Compute the longest string */
185 r
->texts
= g_new (hotkey_t
, count
);
187 for (i
= 0; i
< count
; i
++)
191 r
->texts
[i
] = parse_hotkey (texts
[i
]);
192 width
= hotkey_width (r
->texts
[i
]);
193 wmax
= MAX (width
, wmax
);
196 /* 4 is width of "(*) " */
197 widget_init (w
, y
, x
, count
, 4 + wmax
, radio_callback
, radio_mouse_callback
);
198 w
->options
|= WOP_SELECTABLE
| WOP_WANT_CURSOR
| WOP_WANT_HOTKEY
;
206 /* --------------------------------------------------------------------------------------------- */