* Applied patch by G. Zachrisson to fix the endless loop in _FindNextNavigable().

* Rewrote broken _FindPreviousNavigable() - it now does the exact opposite of
  _FindNextNavigable().
* Both methods did not ignore hidden views - they now do.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17287 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-05-01 14:57:49 +00:00
parent e1fcb5e4b8
commit 9991d2b1ac
+49 -37
View File
@@ -2979,84 +2979,96 @@ BWindow::_FindView(BView *view, BPoint point) const
BView * BView *
BWindow::_FindNextNavigable(BView *focus, uint32 flags) BWindow::_FindNextNavigable(BView* focus, uint32 flags)
{ {
if (focus == NULL) if (focus == NULL)
focus = fTopView; focus = fTopView;
BView *nextFocus = focus; BView* nextFocus = focus;
// Search the tree for views that accept focus // Search the tree for views that accept focus (depth search)
while (true) { while (true) {
if (nextFocus->fFirstChild) if (nextFocus->fFirstChild)
nextFocus = nextFocus->fFirstChild; nextFocus = nextFocus->fFirstChild;
else if (nextFocus->fNextSibling) else if (nextFocus->fNextSibling)
nextFocus = nextFocus->fNextSibling; nextFocus = nextFocus->fNextSibling;
else { else {
while (!nextFocus->fNextSibling && nextFocus->fParent) // go to the nearest parent with a next sibling
while (!nextFocus->fNextSibling && nextFocus->fParent) {
nextFocus = nextFocus->fParent; nextFocus = nextFocus->fParent;
}
if (nextFocus == fTopView) {
// if we started with the top view, we traversed the whole tree already
if (nextFocus == focus)
return NULL;
if (nextFocus == fTopView)
nextFocus = nextFocus->fFirstChild; nextFocus = nextFocus->fFirstChild;
else } else
nextFocus = nextFocus->fNextSibling; nextFocus = nextFocus->fNextSibling;
} }
// It means that the hole tree has been searched and there is no if (nextFocus == focus || nextFocus == NULL) {
// view with B_NAVIGABLE_JUMP flag set! // When we get here it means that the hole tree has been
if (nextFocus == focus) // searched and there is no view with B_NAVIGABLE(_JUMP) flag set!
return NULL; return NULL;
}
if (nextFocus->Flags() & flags) if (!nextFocus->IsHidden() && (nextFocus->Flags() & flags) != 0)
return nextFocus; return nextFocus;
} }
} }
BView * BView *
BWindow::_FindPreviousNavigable(BView *focus, uint32 flags) BWindow::_FindPreviousNavigable(BView* focus, uint32 flags)
{ {
BView *prevFocus = focus; if (focus == NULL)
focus = fTopView;
// Search the tree for views that accept focus BView* previousFocus = focus;
// Search the tree for the previous view that accept focus
while (true) { while (true) {
BView *view; if (previousFocus->fPreviousSibling) {
if ((view = _LastViewChild(prevFocus)) != NULL) // find the last child in the previous sibling
prevFocus = view; previousFocus = _LastViewChild(previousFocus->fPreviousSibling);
else if (prevFocus->fPreviousSibling) } else {
prevFocus = prevFocus->fPreviousSibling; previousFocus = previousFocus->fParent;
else { if (previousFocus == fTopView)
while (!prevFocus->fPreviousSibling && prevFocus->fParent) previousFocus = _LastViewChild(fTopView);
prevFocus = prevFocus->fParent;
if (prevFocus == fTopView)
prevFocus = _LastViewChild(prevFocus);
else
prevFocus = prevFocus->fPreviousSibling;
} }
// It means that the hole tree has been searched and there is no if (previousFocus == focus || previousFocus == NULL) {
// view with B_NAVIGABLE_JUMP flag set! // When we get here it means that the hole tree has been
if (prevFocus == focus) // searched and there is no view with B_NAVIGABLE(_JUMP) flag set!
return NULL; return NULL;
}
if (prevFocus->Flags() & flags) if (!previousFocus->IsHidden() && (previousFocus->Flags() & flags) != 0)
return prevFocus; return previousFocus;
} }
} }
/*!
Returns the last child in a view hierarchy.
Needed only by _FindPreviousNavigable().
*/
BView * BView *
BWindow::_LastViewChild(BView *parent) BWindow::_LastViewChild(BView *parent)
{ {
BView *last = parent->fFirstChild; while (true) {
if (last == NULL) BView *last = parent->fFirstChild;
return NULL; if (last == NULL)
return parent;
while (last->fNextSibling) while (last->fNextSibling) {
last = last->fNextSibling; last = last->fNextSibling;
}
return last; parent = last;
}
} }