+
+ObMenuEntry *menu_control_keyboard_nav(ObMenuEntry *over, ObKey key)
+{
+ GList *it = NULL;
+
+ switch (key) {
+ case OB_KEY_DOWN: {
+ if (over != NULL) {
+ if (over->parent->mouseover)
+ over->parent->mouseover(over, FALSE);
+ else
+ menu_control_mouseover(over, FALSE);
+ menu_entry_render(over);
+
+ it = over->parent->entries;
+ while (it != NULL && it->data != over)
+ it = it->next;
+ }
+
+ if (it && it->next)
+ over = (ObMenuEntry *)it->next->data;
+ else if (over == NULL) {
+ if (menu_visible && ((ObMenu *)menu_visible->data)->entries)
+ over = (ObMenuEntry *)
+ (((ObMenu *)menu_visible->data)->entries)->data;
+ else
+ over = NULL;
+ } else {
+ over = (over->parent->entries != NULL ?
+ over->parent->entries->data : NULL);
+ }
+
+ if (over) {
+ if (over->parent->mouseover)
+ over->parent->mouseover(over, TRUE);
+ else
+ menu_control_mouseover(over, TRUE);
+ menu_entry_render(over);
+ }
+
+ break;
+ }
+ case OB_KEY_UP: {
+ if (over != NULL) {
+ if (over->parent->mouseover)
+ over->parent->mouseover(over, FALSE);
+ else
+ menu_control_mouseover(over, FALSE);
+ menu_entry_render(over);
+
+ it = g_list_last(over->parent->entries);
+ while (it != NULL && it->data != over)
+ it = it->prev;
+ }
+
+ if (it && it->prev)
+ over = (ObMenuEntry *)it->prev->data;
+ else if (over == NULL) {
+ it = g_list_last(menu_visible);
+ if (it != NULL) {
+ it = g_list_last(((ObMenu *)it->data)->entries);
+ over = (ObMenuEntry *)(it != NULL ? it->data : NULL);
+ }
+ } else
+ over = (over->parent->entries != NULL ?
+ g_list_last(over->parent->entries)->data :
+ NULL);
+
+ if (over->parent->mouseover)
+ over->parent->mouseover(over, TRUE);
+ else
+ menu_control_mouseover(over, TRUE);
+ menu_entry_render(over);
+ break;
+ }
+ case OB_KEY_RETURN: {
+ if (over == NULL)
+ return over;
+
+ if (over->submenu) {
+ if (over->parent->mouseover)
+ over->parent->mouseover(over, FALSE);
+ else
+ menu_control_mouseover(over, FALSE);
+ menu_entry_render(over);
+
+ if (over->submenu->entries)
+ over = over->submenu->entries->data;
+
+ if (over->parent->mouseover)
+ over->parent->mouseover(over, TRUE);
+ else
+ menu_control_mouseover(over, TRUE);
+ menu_entry_render(over);
+ }
+ else {
+ if (over->parent->mouseover)
+ over->parent->mouseover(over, FALSE);
+ else
+ menu_control_mouseover(over, FALSE);
+ menu_entry_render(over);
+
+ menu_entry_fire(over);
+ }
+ break;
+ }
+ case OB_KEY_ESCAPE: {
+ if (over != NULL) {
+ if (over->parent->mouseover)
+ over->parent->mouseover(over, FALSE);
+ else
+ menu_control_mouseover(over, FALSE);
+ menu_entry_render(over);
+
+ menu_hide(over->parent);
+ } else {
+ it = g_list_last(menu_visible);
+ if (it) {
+ menu_hide((ObMenu *)it->data);
+ }
+ }
+
+ over = NULL;
+ break;
+ }
+ default:
+ g_error("Unknown key");
+ }
+
+ return over;
+}