|
@@ -43,13 +43,79 @@
|
|
|
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
+const global_keymap_t *radio_map = NULL;
|
|
|
+
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
+/* --------------------------------------------------------------------------------------------- */
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
+/* --------------------------------------------------------------------------------------------- */
|
|
|
+
|
|
|
+static cb_ret_t
|
|
|
+radio_execute_cmd (WRadio * r, long command)
|
|
|
+{
|
|
|
+ cb_ret_t ret = MSG_HANDLED;
|
|
|
+ Widget *w = WIDGET (r);
|
|
|
+
|
|
|
+ switch (command)
|
|
|
+ {
|
|
|
+ case CK_Up:
|
|
|
+ case CK_Top:
|
|
|
+ if (r->pos == 0)
|
|
|
+ return MSG_NOT_HANDLED;
|
|
|
+
|
|
|
+ if (command == CK_Top)
|
|
|
+ r->pos = 0;
|
|
|
+ else
|
|
|
+ r->pos--;
|
|
|
+ widget_draw (w);
|
|
|
+ return MSG_HANDLED;
|
|
|
+
|
|
|
+ case CK_Down:
|
|
|
+ case CK_Bottom:
|
|
|
+ if (r->pos == r->count - 1)
|
|
|
+ return MSG_NOT_HANDLED;
|
|
|
+
|
|
|
+ if (command == CK_Bottom)
|
|
|
+ r->pos = r->count - 1;
|
|
|
+ else
|
|
|
+ r->pos++;
|
|
|
+ widget_draw (w);
|
|
|
+ return MSG_HANDLED;
|
|
|
+
|
|
|
+ case CK_Select:
|
|
|
+ r->sel = r->pos;
|
|
|
+ widget_set_state (w, WST_FOCUSED, TRUE); /* Also draws the widget */
|
|
|
+ send_message (w->owner, w, MSG_NOTIFY, 0, NULL);
|
|
|
+ return MSG_HANDLED;
|
|
|
+
|
|
|
+ default:
|
|
|
+ ret = MSG_NOT_HANDLED;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+/* --------------------------------------------------------------------------------------------- */
|
|
|
+
|
|
|
+/* Return MSG_HANDLED if we want a redraw */
|
|
|
+static cb_ret_t
|
|
|
+radio_key (WRadio * r, int key)
|
|
|
+{
|
|
|
+ long command;
|
|
|
+
|
|
|
+ command = widget_lookup_key (WIDGET (r), key);
|
|
|
+ if (command == CK_IgnoreKey)
|
|
|
+ return MSG_NOT_HANDLED;
|
|
|
+ return radio_execute_cmd (r, command);
|
|
|
+}
|
|
|
+
|
|
|
+/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
static cb_ret_t
|
|
|
radio_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
|
@@ -72,44 +138,17 @@ radio_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
|
|
|
r->pos = i;
|
|
|
|
|
|
/* Take action */
|
|
|
- send_message (w, sender, MSG_KEY, ' ', data);
|
|
|
+ send_message (w, sender, MSG_ACTION, CK_Select, data);
|
|
|
return MSG_HANDLED;
|
|
|
}
|
|
|
}
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
|
case MSG_KEY:
|
|
|
- switch (parm)
|
|
|
- {
|
|
|
- case ' ':
|
|
|
- r->sel = r->pos;
|
|
|
- widget_set_state (w, WST_FOCUSED, TRUE); /* Also draws the widget. */
|
|
|
- send_message (w->owner, w, MSG_NOTIFY, 0, NULL);
|
|
|
- return MSG_HANDLED;
|
|
|
-
|
|
|
- case KEY_UP:
|
|
|
- case KEY_LEFT:
|
|
|
- if (r->pos > 0)
|
|
|
- {
|
|
|
- r->pos--;
|
|
|
- widget_draw (w);
|
|
|
- return MSG_HANDLED;
|
|
|
- }
|
|
|
- return MSG_NOT_HANDLED;
|
|
|
-
|
|
|
- case KEY_DOWN:
|
|
|
- case KEY_RIGHT:
|
|
|
- if (r->count - 1 > r->pos)
|
|
|
- {
|
|
|
- r->pos++;
|
|
|
- widget_draw (w);
|
|
|
- return MSG_HANDLED;
|
|
|
- }
|
|
|
- return MSG_NOT_HANDLED;
|
|
|
+ return radio_key (r, parm);
|
|
|
|
|
|
- default:
|
|
|
- return MSG_NOT_HANDLED;
|
|
|
- }
|
|
|
+ case MSG_ACTION:
|
|
|
+ return radio_execute_cmd (r, parm);
|
|
|
|
|
|
case MSG_CURSOR:
|
|
|
widget_gotoyx (r, r->pos, 1);
|
|
@@ -158,7 +197,7 @@ radio_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
|
|
|
|
|
|
case MSG_MOUSE_CLICK:
|
|
|
RADIO (w)->pos = event->y;
|
|
|
- send_message (w, NULL, MSG_KEY, ' ', NULL);
|
|
|
+ send_message (w, NULL, MSG_ACTION, CK_Select, NULL);
|
|
|
send_message (w->owner, w, MSG_POST_KEY, ' ', NULL);
|
|
|
break;
|
|
|
|
|
@@ -196,6 +235,8 @@ radio_new (int y, int x, int count, const char **texts)
|
|
|
/* 4 is width of "(*) " */
|
|
|
widget_init (w, y, x, count, 4 + wmax, radio_callback, radio_mouse_callback);
|
|
|
w->options |= WOP_SELECTABLE | WOP_WANT_CURSOR | WOP_WANT_HOTKEY;
|
|
|
+ w->keymap = radio_map;
|
|
|
+
|
|
|
r->pos = 0;
|
|
|
r->sel = 0;
|
|
|
r->count = count;
|