Source/NSWindow.m: (_lossOfKeyOrMainWindow): Add sanity checks. Optimize.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@24679 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Sergii Stoian 2007-02-21 23:18:01 +00:00
parent bf41e31a34
commit 91c57aed58

View file

@ -237,19 +237,27 @@ has blocked and waited for events.
NSArray *windowList = GSOrderedWindows();
unsigned pos = [windowList indexOfObjectIdenticalTo: self];
unsigned c = [windowList count];
unsigned i;
unsigned i,ti;
NSWindow *w;
if (!c)
return;
i = pos + 1;
if (pos >= c || pos + 1 == c)
{
pos = c - 1;
i = 0;
}
ti = i;
if ([self isKeyWindow])
{
NSWindow *menu_window= [[NSApp mainMenu] window];
NSWindow *menu_window = [[NSApp mainMenu] window];
[self resignKeyWindow];
i = pos + 1;
if (i == c)
{
i = 0;
}
while (i != pos)
for (; i != pos && i < c; i++)
{
w = [windowList objectAtIndex: i];
if ([w isVisible] && [w canBecomeKeyWindow] && w != menu_window)
@ -257,17 +265,11 @@ has blocked and waited for events.
[w makeKeyWindow];
break;
}
i++;
if (i == c)
{
i = 0;
}
}
/*
* if we didn't find a possible key window - use the main menu window
*/
if (i == pos)
if (i == c)
{
if (menu_window != nil)
{
@ -287,12 +289,7 @@ has blocked and waited for events.
}
else
{
i = pos + 1;
if (i == c)
{
i = 0;
}
while (i != pos)
for (i = ti; i != pos && i < c; i++)
{
w = [windowList objectAtIndex: i];
if ([w isVisible] && [w canBecomeMainWindow])
@ -300,12 +297,6 @@ has blocked and waited for events.
[w makeMainWindow];
break;
}
i++;
if (i == c)
{
i = 0;
}
}
}
}