Implement view stack.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3133 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1998-10-27 15:24:42 +00:00
parent 84112aa3fb
commit 79758f2570

View file

@ -61,45 +61,57 @@ static NSString *nsview_thread_key = @"NSViewThreadKey";
} }
} }
//
// +++ Really each thread should have a stack!
//
+ (void) pushFocusView:(NSView *)focusView + (void) pushFocusView:(NSView *)focusView
{
if (focusView)
{ {
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary]; NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
NSMutableArray *stack = [dict objectForKey: nsview_thread_key];
// If no context then remove from dictionary if (stack == nil)
if (!focusView)
{ {
[dict removeObjectForKey: nsview_thread_key]; stack = [[NSMutableDictionary alloc] initWithCapacity: 4];
[dict setObject: stack forKey: nsview_thread_key];
[stack release];
} }
else [stack addObject: focusView];
{
[dict setObject: focusView forKey: nsview_thread_key];
} }
} }
+ (NSView *)popFocusView + (NSView *)popFocusView
{ {
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary]; NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
id v; NSMutableArray *stack = [dict objectForKey: nsview_thread_key];
NSView *v = nil;
// Remove from dictionary if (stack)
v = [dict objectForKey: nsview_thread_key]; {
[dict removeObjectForKey: nsview_thread_key]; unsigned count = [stack count];
if (count > 0)
{
v = [stack objectAtIndex: --count];
[stack removeObjectAtIndex: count];
}
}
return v; return v;
} }
+ (NSView *)focusView + (NSView *)focusView
{ {
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary]; NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
NSMutableArray *stack = [dict objectForKey: nsview_thread_key];
NSView *current_view = nil; NSView *current_view = nil;
// current_view is nil if no focused view if (stack)
current_view = [dict objectForKey: nsview_thread_key]; {
unsigned count = [stack count];
if (count > 0)
{
current_view = [stack objectAtIndex: --count];
}
}
return current_view; return current_view;
} }