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: WRadui widget (radiobuttons)
37 #include "lib/global.h"
39 #include "lib/tty/tty.h"
40 #include "lib/tty/mouse.h"
41 #include "lib/widget.h"
43 /*** global variables ****************************************************************************/
45 /*** file scope macro definitions ****************************************************************/
47 /*** file scope type declarations ****************************************************************/
49 /*** file scope variables ************************************************************************/
51 /*** file scope functions ************************************************************************/
54 radio_callback (Widget
* w
, widget_msg_t msg
, int parm
)
56 WRadio
*r
= (WRadio
*) w
;
58 Dlg_head
*h
= r
->widget
.owner
;
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 radio_callback (w
, WIDGET_KEY
, ' ');
80 return MSG_NOT_HANDLED
;
87 h
->callback (h
, w
, DLG_ACTION
, 0, NULL
);
88 radio_callback (w
, WIDGET_FOCUS
, ' ');
98 return MSG_NOT_HANDLED
;
102 if (r
->count
- 1 > r
->pos
)
108 return MSG_NOT_HANDLED
;
111 h
->callback (h
, w
, DLG_ACTION
, 0, NULL
);
112 radio_callback (w
, WIDGET_FOCUS
, ' ');
113 widget_move (&r
->widget
, r
->pos
, 1);
119 for (i
= 0; i
< r
->count
; i
++)
121 const gboolean focused
= (i
== r
->pos
&& msg
== WIDGET_FOCUS
);
123 widget_selectcolor (w
, focused
, FALSE
);
124 widget_move (&r
->widget
, i
, 0);
125 tty_draw_hline (r
->widget
.y
+ i
, r
->widget
.x
, ' ', r
->widget
.cols
);
126 tty_print_string ((r
->sel
== i
) ? "(*) " : "( ) ");
127 hotkey_draw (w
, r
->texts
[i
], focused
);
132 for (i
= 0; i
< r
->count
; i
++)
133 release_hotkey (r
->texts
[i
]);
138 return default_proc (msg
, parm
);
142 /* --------------------------------------------------------------------------------------------- */
145 radio_event (Gpm_Event
* event
, void *data
)
150 if ((event
->type
& (GPM_DOWN
| GPM_UP
)) != 0)
152 Dlg_head
*h
= r
->widget
.owner
;
154 r
->pos
= event
->y
- 1;
155 dlg_select_widget (r
);
156 if ((event
->type
& GPM_UP
) != 0)
158 radio_callback (w
, WIDGET_KEY
, ' ');
159 h
->callback (h
, w
, DLG_POST_KEY
, ' ', NULL
);
166 /* --------------------------------------------------------------------------------------------- */
167 /*** public functions ****************************************************************************/
168 /* --------------------------------------------------------------------------------------------- */
171 radio_new (int y
, int x
, int count
, const char **texts
)
176 r
= g_new (WRadio
, 1);
177 /* Compute the longest string */
178 r
->texts
= g_new (hotkey_t
, count
);
180 for (i
= 0; i
< count
; i
++)
184 r
->texts
[i
] = parse_hotkey (texts
[i
]);
185 w
= hotkey_width (r
->texts
[i
]);
186 wmax
= max (w
, wmax
);
189 init_widget (&r
->widget
, y
, x
, count
, 4 + wmax
, radio_callback
, radio_event
);
190 /* 4 is width of "(*) " */
195 widget_want_hotkey (r
->widget
, TRUE
);
200 /* --------------------------------------------------------------------------------------------- */