Fix improper shift and mask order causing FS#6842
Set start_selected if exiting do_menu() early from more places


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12826 a1c6a512-1295-4272-9138-f99709370657
diff --git a/apps/menu.c b/apps/menu.c
index 4686289..412aca7 100644
--- a/apps/menu.c
+++ b/apps/menu.c
@@ -176,7 +176,7 @@
 static void init_menu_lists(const struct menu_item_ex *menu,
                      struct gui_synclist *lists, int selected, bool callback)
 {
-    int i, count = (menu->flags&MENU_COUNT_MASK)>>MENU_COUNT_SHIFT;
+    int i, count = MENU_GET_COUNT(menu->flags);
     menu_callback_type menu_callback = NULL;
     ICON icon = NOICON;
     current_subitems_count = 0;
@@ -557,7 +557,10 @@
                     if (temp->flags&MENU_FUNC_CHECK_RETVAL)
                     {
                         if (return_value == temp->function->exit_value)
-                            return return_value;
+                        {
+                            done = true;
+                            ret =  return_value;
+                        }
                     }
                     break;
                 }
@@ -572,7 +575,8 @@
                     if (in_stringlist)
                     {
                         action_signalscreenchange();
-                        return selected;
+                        done = true;
+                        ret =  selected;
                     }
                     else if (stack_top < MAX_MENUS)
                     {
@@ -689,8 +693,7 @@
     (void)callback;
     gui_synclist_init(lists, oldmenuwrapper_getname, 
                         (void*)(intptr_t)menu->value, false, 1);
-    gui_synclist_set_nb_items(lists,
-        (menu->flags&MENU_COUNT_MASK)>>MENU_COUNT_SHIFT);
+    gui_synclist_set_nb_items(lists, MENU_GET_COUNT(menu->flags));
     gui_synclist_limit_scroll(lists, true);
     gui_synclist_select_item(lists, selected);
 }
diff --git a/apps/menu.h b/apps/menu.h
index 6d7d113..ded2550 100644
--- a/apps/menu.h
+++ b/apps/menu.h
@@ -61,6 +61,7 @@
 #define MENU_COUNT_MASK 0xFFF
 #define MENU_COUNT_SHIFT 8
 #define MENU_ITEM_COUNT(c) ((c&MENU_COUNT_MASK)<<MENU_COUNT_SHIFT)
+#define MENU_GET_COUNT(flags) ((flags>>MENU_COUNT_SHIFT)&MENU_COUNT_MASK)
 
 struct menu_item_ex {
     unsigned int flags; /* above defines */