Improve keyboard navigation by automatically computing a key view loop

for a window (and tab view item). This implicit key view is created
when a window is made key and does not have an explicit key view loop,
which is detected by checking the initial first responder of the
window.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@35632 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
wlux 2012-10-04 09:20:08 +00:00
parent e9a1c95079
commit 4bc8763f12
7 changed files with 227 additions and 6 deletions

View file

@ -77,6 +77,7 @@
#import "GSToolTips.h"
#import "GSBindingHelpers.h"
#import "GSGuiPrivate.h"
#import "NSViewPrivate.h"
/*
* We need a fast array that can store objects without retain/release ...
@ -422,10 +423,18 @@ GSSetDragTypes(NSView* obj, NSArray *types)
if (_window != nil)
{
[GSDisplayServer removeDragTypes: t fromWindow: _window];
if ([_window autorecalculatesKeyViewLoop])
{
[_window recalculateKeyViewLoop];
}
}
if (newWindow != nil)
{
[GSDisplayServer addDragTypes: t toWindow: newWindow];
if ([newWindow autorecalculatesKeyViewLoop])
{
[newWindow recalculateKeyViewLoop];
}
}
}
@ -5057,3 +5066,54 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
@end
@implementation NSView(KeyViewLoop)
static int
cmpFrame(id view1, id view2, void *context)
{
BOOL flippedSuperView = [(NSView *)context isFlipped];
NSRect frame1 = [view1 frame];
NSRect frame2 = [view2 frame];
if (NSMinY(frame1) < NSMinY(frame2))
return flippedSuperView ? NSOrderedAscending : NSOrderedDescending;
if (NSMaxY(frame1) > NSMaxY(frame2))
return flippedSuperView ? NSOrderedDescending : NSOrderedAscending;
// FIXME Should use NSMaxX in a Hebrew or Arabic locale
if (NSMinX(frame1) < NSMinX(frame2))
return NSOrderedAscending;
if (NSMinX(frame1) > NSMinX(frame2))
return NSOrderedDescending;
return NSOrderedSame;
}
- (void) _setUpKeyViewLoopWithNextKeyView: (NSView *)nextKeyView
{
if (_rFlags.has_subviews)
{
[self _recursiveSetUpKeyViewLoopWithNextKeyView: nextKeyView];
}
else
{
[self setNextKeyView: nextKeyView];
}
}
- (void) _recursiveSetUpKeyViewLoopWithNextKeyView: (NSView *)nextKeyView
{
NSArray *sortedViews;
NSView *aView;
NSEnumerator *e;
sortedViews = [_sub_views sortedArrayUsingFunction: cmpFrame context: self];
e = [sortedViews reverseObjectEnumerator];
while ((aView = [e nextObject]) != nil)
{
[aView _setUpKeyViewLoopWithNextKeyView: nextKeyView];
nextKeyView = aView;
}
[self setNextKeyView: nextKeyView];
}
@end