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
* sender
, widget_msg_t msg
, int parm
, void *data
)
59 WRadio
*r
= (WRadio
*) w
;
61 Dlg_head
*h
= w
->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 send_message (w
, sender
, WIDGET_KEY
, ' ', data
);
83 return MSG_NOT_HANDLED
;
90 h
->callback (h
, w
, DLG_ACTION
, 0, NULL
);
91 send_message (w
, sender
, WIDGET_FOCUS
, ' ', data
);
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 send_message (w
, sender
, WIDGET_FOCUS
, ' ', data
);
116 widget_move (r
, 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
, 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
], focused
);
135 for (i
= 0; i
< r
->count
; i
++)
136 release_hotkey (r
->texts
[i
]);
141 return default_widget_callback (sender
, msg
, parm
, data
);
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
, NULL
, WIDGET_KEY
, ' ', NULL
);
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
)
185 r
= g_new (WRadio
, 1);
188 /* Compute the longest string */
189 r
->texts
= g_new (hotkey_t
, count
);
191 for (i
= 0; i
< count
; i
++)
195 r
->texts
[i
] = parse_hotkey (texts
[i
]);
196 width
= hotkey_width (r
->texts
[i
]);
197 wmax
= max (width
, wmax
);
200 init_widget (w
, y
, x
, count
, 4 + wmax
, radio_callback
, radio_event
);
201 /* 4 is width of "(*) " */
206 widget_want_hotkey (w
, TRUE
);
211 /* --------------------------------------------------------------------------------------------- */