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: WRadui widget (radiobuttons)
40 #include "lib/global.h"
42 #include "lib/tty/tty.h"
43 #include "lib/tty/mouse.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 ************************************************************************/
57 radio_callback (Widget
* w
, widget_msg_t msg
, int parm
)
59 WRadio
*r
= (WRadio
*) w
;
61 Dlg_head
*h
= r
->widget
.owner
;
67 for (i
= 0; i
< r
->count
; i
++)
69 if (r
->texts
[i
].hotkey
!= NULL
)
71 int c
= g_ascii_tolower ((gchar
) r
->texts
[i
].hotkey
[0]);
78 radio_callback (w
, WIDGET_KEY
, ' ');
83 return MSG_NOT_HANDLED
;
90 h
->callback (h
, w
, DLG_ACTION
, 0, NULL
);
91 radio_callback (w
, WIDGET_FOCUS
, ' ');
101 return MSG_NOT_HANDLED
;
105 if (r
->count
- 1 > r
->pos
)
111 return MSG_NOT_HANDLED
;
114 h
->callback (h
, w
, DLG_ACTION
, 0, NULL
);
115 radio_callback (w
, WIDGET_FOCUS
, ' ');
116 widget_move (&r
->widget
, r
->pos
, 1);
122 for (i
= 0; i
< r
->count
; i
++)
124 const gboolean focused
= (i
== r
->pos
&& msg
== WIDGET_FOCUS
);
126 widget_selectcolor (w
, focused
, FALSE
);
127 widget_move (&r
->widget
, i
, 0);
128 tty_draw_hline (r
->widget
.y
+ i
, r
->widget
.x
, ' ', r
->widget
.cols
);
129 tty_print_string ((r
->sel
== i
) ? "(*) " : "( ) ");
130 hotkey_draw (w
, r
->texts
[i
], focused
);
135 for (i
= 0; i
< r
->count
; i
++)
136 release_hotkey (r
->texts
[i
]);
141 return default_proc (msg
, parm
);
145 /* --------------------------------------------------------------------------------------------- */
148 radio_event (Gpm_Event
* event
, void *data
)
150 Widget
*w
= (Widget
*) data
;
152 if (!mouse_global_in_widget (event
, w
))
153 return MOU_UNHANDLED
;
155 if ((event
->type
& (GPM_DOWN
| GPM_UP
)) != 0)
157 WRadio
*r
= (WRadio
*) data
;
160 local
= mouse_get_local (event
, w
);
162 r
->pos
= local
.y
- 1;
163 dlg_select_widget (w
);
164 if ((event
->type
& GPM_UP
) != 0)
166 radio_callback (w
, WIDGET_KEY
, ' ');
167 w
->owner
->callback (w
->owner
, w
, DLG_POST_KEY
, ' ', NULL
);
174 /* --------------------------------------------------------------------------------------------- */
175 /*** public functions ****************************************************************************/
176 /* --------------------------------------------------------------------------------------------- */
179 radio_new (int y
, int x
, int count
, const char **texts
)
184 r
= g_new (WRadio
, 1);
185 /* Compute the longest string */
186 r
->texts
= g_new (hotkey_t
, count
);
188 for (i
= 0; i
< count
; i
++)
192 r
->texts
[i
] = parse_hotkey (texts
[i
]);
193 w
= hotkey_width (r
->texts
[i
]);
194 wmax
= max (w
, wmax
);
197 init_widget (&r
->widget
, y
, x
, count
, 4 + wmax
, radio_callback
, radio_event
);
198 /* 4 is width of "(*) " */
203 widget_want_hotkey (r
->widget
, TRUE
);
208 /* --------------------------------------------------------------------------------------------- */