diff --git a/src/osgWidget/Window.cpp b/src/osgWidget/Window.cpp index 4181d7074..b004fadd4 100644 --- a/src/osgWidget/Window.cpp +++ b/src/osgWidget/Window.cpp @@ -758,25 +758,28 @@ bool Window::setFirstFocusable() { return false; } -bool Window::setNextFocusable() { +bool Window::setNextFocusable() +{ WidgetList focusList; if(!getFocusList(focusList)) return false; - WidgetList::iterator w = focusList.begin(); - // TODO: This needs to be a more complicated object, since the focus may be // in a child Window instead of a Widget. - unsigned int focusedIndex = 0; - - for(unsigned int i = 0; w != focusList.end(); w++, i++) if(*w == _focused) { - focusedIndex = i; - - break; + WidgetList::iterator witr; + for(witr = focusList.begin(); + witr != focusList.end(); + ++witr) + { + if (*witr==_focused) + { + // found current focused widget, move to next widget the one we want to focus on + ++witr; + break; + } } - if(focusedIndex < focusList.size() - 1) _setFocused((++w)->get()); - + if (witr!=focusList.end()) _setFocused(witr->get()); else _setFocused(focusList.front().get()); return true;