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
);
64 for (i
= 0; i
< r
->count
; i
++)
66 if (r
->texts
[i
].hotkey
!= NULL
)
68 int c
= g_ascii_tolower ((gchar
) r
->texts
[i
].hotkey
[0]);
75 send_message (w
, sender
, MSG_KEY
, ' ', data
);
80 return MSG_NOT_HANDLED
;
87 send_message (w
, sender
, MSG_FOCUS
, ' ', data
);
88 send_message (w
->owner
, w
, MSG_NOTIFY
, 0, NULL
);
98 return MSG_NOT_HANDLED
;
102 if (r
->count
- 1 > r
->pos
)
108 return MSG_NOT_HANDLED
;
112 send_message (w
, sender
, MSG_FOCUS
, ' ', data
);
113 widget_move (r
, r
->pos
, 1);
114 send_message (w
->owner
, w
, MSG_NOTIFY
, 0, NULL
);
120 for (i
= 0; i
< r
->count
; i
++)
122 const gboolean focused
= (i
== r
->pos
&& msg
== MSG_FOCUS
);
124 widget_selectcolor (w
, focused
, FALSE
);
125 widget_move (r
, i
, 0);
126 tty_draw_hline (w
->y
+ i
, w
->x
, ' ', w
->cols
);
127 tty_print_string ((r
->sel
== i
) ? "(*) " : "( ) ");
128 hotkey_draw (w
, r
->texts
[i
], focused
);
133 for (i
= 0; i
< r
->count
; i
++)
134 release_hotkey (r
->texts
[i
]);
139 return widget_default_callback (w
, sender
, msg
, parm
, data
);
143 /* --------------------------------------------------------------------------------------------- */
146 radio_mouse_callback (Widget
* w
, mouse_msg_t msg
, mouse_event_t
* event
)
151 RADIO (w
)->pos
= event
->y
;
152 dlg_select_widget (w
);
155 case MSG_MOUSE_CLICK
:
156 RADIO (w
)->pos
= event
->y
;
157 send_message (w
, NULL
, MSG_KEY
, ' ', NULL
);
158 send_message (w
->owner
, w
, MSG_POST_KEY
, ' ', NULL
);
166 /* --------------------------------------------------------------------------------------------- */
167 /*** public functions ****************************************************************************/
168 /* --------------------------------------------------------------------------------------------- */
171 radio_new (int y
, int x
, int count
, const char **texts
)
177 r
= g_new (WRadio
, 1);
180 /* Compute the longest string */
181 r
->texts
= g_new (hotkey_t
, count
);
183 for (i
= 0; i
< count
; i
++)
187 r
->texts
[i
] = parse_hotkey (texts
[i
]);
188 width
= hotkey_width (r
->texts
[i
]);
189 wmax
= max (width
, wmax
);
192 /* 4 is width of "(*) " */
193 widget_init (w
, y
, x
, count
, 4 + wmax
, radio_callback
, radio_mouse_callback
);
198 widget_want_hotkey (w
, TRUE
);
203 /* --------------------------------------------------------------------------------------------- */