mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 08:30:59 +00:00
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:
parent
4250e4a439
commit
1c6e5aa062
1 changed files with 32 additions and 20 deletions
|
@ -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
|
||||
{
|
||||
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
|
||||
|
||||
// If no context then remove from dictionary
|
||||
if (!focusView)
|
||||
if (focusView)
|
||||
{
|
||||
[dict removeObjectForKey: nsview_thread_key];
|
||||
}
|
||||
else
|
||||
{
|
||||
[dict setObject: focusView forKey: nsview_thread_key];
|
||||
}
|
||||
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
|
||||
NSMutableArray *stack = [dict objectForKey: nsview_thread_key];
|
||||
|
||||
if (stack == nil)
|
||||
{
|
||||
stack = [[NSMutableDictionary alloc] initWithCapacity: 4];
|
||||
[dict setObject: stack forKey: nsview_thread_key];
|
||||
[stack release];
|
||||
}
|
||||
[stack addObject: focusView];
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSView *)popFocusView
|
||||
{
|
||||
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
|
||||
id v;
|
||||
NSMutableArray *stack = [dict objectForKey: nsview_thread_key];
|
||||
NSView *v = nil;
|
||||
|
||||
// Remove from dictionary
|
||||
v = [dict objectForKey: nsview_thread_key];
|
||||
[dict removeObjectForKey: nsview_thread_key];
|
||||
if (stack)
|
||||
{
|
||||
unsigned count = [stack count];
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
v = [stack objectAtIndex: --count];
|
||||
[stack removeObjectAtIndex: count];
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
+ (NSView *)focusView
|
||||
{
|
||||
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
|
||||
NSMutableArray *stack = [dict objectForKey: nsview_thread_key];
|
||||
NSView *current_view = nil;
|
||||
|
||||
// current_view is nil if no focused view
|
||||
current_view = [dict objectForKey: nsview_thread_key];
|
||||
if (stack)
|
||||
{
|
||||
unsigned count = [stack count];
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
current_view = [stack objectAtIndex: --count];
|
||||
}
|
||||
}
|
||||
return current_view;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue