mirror of
https://github.com/MidnightCommander/mc
synced 2025-04-14 02:52:51 +03:00
patches by Rostislav Beneš: mc-04-radio
all options of radio box are stored in an array of hotkey_t, so radio box has own copy of options now (in original mc has only a reference to options), changed drawing and handling hotkey
This commit is contained in:
parent
9810380e9a
commit
8d6efd4cd0
53
src/widget.c
53
src/widget.c
@ -348,13 +348,11 @@ radio_callback (Widget *w, widget_msg_t msg, int parm)
|
|||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WIDGET_HOTKEY:
|
case WIDGET_HOTKEY:
|
||||||
{
|
{
|
||||||
int i, lp = tolower (parm);
|
int i, lp = g_ascii_tolower ((gchar)parm);
|
||||||
const char *cp;
|
|
||||||
|
|
||||||
for (i = 0; i < r->count; i++) {
|
for (i = 0; i < r->count; i++) {
|
||||||
cp = strchr (r->texts[i], '&');
|
if (r->texts[i].hotkey != NULL) {
|
||||||
if (cp != NULL && cp[1] != '\0') {
|
int c = g_ascii_tolower ((gchar)r->texts[i].hotkey[0]);
|
||||||
int c = tolower ((unsigned char) cp[1]);
|
|
||||||
|
|
||||||
if (c != lp)
|
if (c != lp)
|
||||||
continue;
|
continue;
|
||||||
@ -403,23 +401,32 @@ radio_callback (Widget *w, widget_msg_t msg, int parm)
|
|||||||
case WIDGET_FOCUS:
|
case WIDGET_FOCUS:
|
||||||
case WIDGET_DRAW:
|
case WIDGET_DRAW:
|
||||||
for (i = 0; i < r->count; i++) {
|
for (i = 0; i < r->count; i++) {
|
||||||
register const char *cp;
|
|
||||||
const gboolean focused = (i == r->pos && msg == WIDGET_FOCUS);
|
const gboolean focused = (i == r->pos && msg == WIDGET_FOCUS);
|
||||||
widget_selectcolor (w, focused, FALSE);
|
widget_selectcolor (w, focused, FALSE);
|
||||||
widget_move (&r->widget, i, 0);
|
widget_move (&r->widget, i, 0);
|
||||||
|
|
||||||
tty_printf ("(%c) ", (r->sel == i) ? '*' : ' ');
|
addstr ((r->sel == i) ? "(*) " : "( ) ");
|
||||||
for (cp = r->texts[i]; *cp; cp++) {
|
|
||||||
if (*cp == '&') {
|
addstr (str_term_form (r->texts[i].start));
|
||||||
|
|
||||||
|
if (r->texts[i].hotkey != NULL) {
|
||||||
widget_selectcolor (w, focused, TRUE);
|
widget_selectcolor (w, focused, TRUE);
|
||||||
addch (*++cp);
|
addstr (str_term_form (r->texts[i].hotkey));
|
||||||
widget_selectcolor (w, focused, FALSE);
|
widget_selectcolor (w, focused, FALSE);
|
||||||
} else
|
}
|
||||||
addch (*cp);
|
if (r->texts[i].end != NULL) {
|
||||||
|
addstr (str_term_form (r->texts[i].end));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return MSG_HANDLED;
|
return MSG_HANDLED;
|
||||||
|
|
||||||
|
case WIDGET_DESTROY:
|
||||||
|
for (i = 0; i < r->count; i++) {
|
||||||
|
release_hotkey (r->texts[i]);
|
||||||
|
}
|
||||||
|
g_free (r->texts);
|
||||||
|
return MSG_HANDLED;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return default_proc (msg, parm);
|
return default_proc (msg, parm);
|
||||||
}
|
}
|
||||||
@ -449,26 +456,28 @@ radio_event (Gpm_Event *event, void *data)
|
|||||||
WRadio *
|
WRadio *
|
||||||
radio_new (int y, int x, int count, const char **texts)
|
radio_new (int y, int x, int count, const char **texts)
|
||||||
{
|
{
|
||||||
WRadio *r = g_new (WRadio, 1);
|
WRadio *result = g_new (WRadio, 1);
|
||||||
int i, max, m;
|
int i, max, m;
|
||||||
|
|
||||||
/* Compute the longest string */
|
/* Compute the longest string */
|
||||||
|
result->texts = g_new (struct hotkey_t, count);
|
||||||
|
|
||||||
max = 0;
|
max = 0;
|
||||||
for (i = 0; i < count; i++){
|
for (i = 0; i < count; i++){
|
||||||
m = strlen (texts [i]);
|
result->texts[i] = parse_hotkey (texts[i]);
|
||||||
|
m = hotkey_width (result->texts[i]);
|
||||||
if (m > max)
|
if (m > max)
|
||||||
max = m;
|
max = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
init_widget (&r->widget, y, x, count, max, radio_callback, radio_event);
|
init_widget (&result->widget, y, x, count, max, radio_callback, radio_event);
|
||||||
r->state = 1;
|
result->state = 1;
|
||||||
r->pos = 0;
|
result->pos = 0;
|
||||||
r->sel = 0;
|
result->sel = 0;
|
||||||
r->count = count;
|
result->count = count;
|
||||||
r->texts = texts;
|
widget_want_hotkey (result->widget, 1);
|
||||||
widget_want_hotkey (r->widget, 1);
|
|
||||||
|
|
||||||
return r;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ typedef struct WRadio {
|
|||||||
unsigned int state; /* radio button state */
|
unsigned int state; /* radio button state */
|
||||||
int pos, sel;
|
int pos, sel;
|
||||||
int count; /* number of members */
|
int count; /* number of members */
|
||||||
const char **texts; /* texts of labels */
|
struct hotkey_t *texts; /* texts of labels */
|
||||||
} WRadio;
|
} WRadio;
|
||||||
|
|
||||||
typedef struct WCheck {
|
typedef struct WCheck {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user